@svelte-atoms/core 1.0.0-alpha.44 → 1.0.0-alpha.46
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 +13 -0
- package/dist/components/accordion/item/accordion-item-body.svelte +5 -8
- package/dist/components/accordion/item/accordion-item-header.svelte +0 -13
- package/dist/components/accordion/item/accordion-item-indicator.svelte +0 -12
- package/dist/components/accordion/item/accordion-item-root.svelte +0 -12
- package/dist/components/alert/alert-actions.svelte +0 -12
- package/dist/components/alert/alert-close-button.svelte +0 -12
- package/dist/components/alert/alert-content.svelte +0 -12
- package/dist/components/alert/alert-description.svelte +0 -12
- package/dist/components/alert/alert-icon.svelte +0 -12
- package/dist/components/alert/alert-root.svelte +1 -13
- package/dist/components/alert/alert-title.svelte +0 -12
- package/dist/components/atom/html-atom.svelte +31 -17
- package/dist/components/atom/types.d.ts +9 -0
- package/dist/components/atom/utils/base.d.ts +6 -0
- package/dist/components/atom/utils/base.js +8 -0
- package/dist/components/atom/utils/cache.d.ts +17 -0
- package/dist/components/atom/utils/cache.js +134 -0
- package/dist/components/atom/utils/classes.d.ts +14 -0
- package/dist/components/atom/utils/classes.js +42 -0
- package/dist/components/atom/utils/constants.d.ts +9 -0
- package/dist/components/atom/utils/constants.js +9 -0
- package/dist/components/atom/utils/index.d.ts +6 -0
- package/dist/components/atom/utils/index.js +5 -0
- package/dist/components/atom/utils/preset.d.ts +22 -0
- package/dist/components/atom/utils/preset.js +94 -0
- package/dist/components/atom/utils/props.d.ts +13 -0
- package/dist/components/atom/utils/props.js +60 -0
- package/dist/components/atom/utils/variants.d.ts +31 -0
- package/dist/components/atom/utils/variants.js +270 -0
- package/dist/components/card/card-body.svelte +0 -12
- package/dist/components/card/card-description.svelte +0 -12
- package/dist/components/card/card-footer.svelte +0 -12
- package/dist/components/card/card-header.svelte +0 -12
- package/dist/components/card/card-media.svelte +0 -12
- package/dist/components/card/card-root.svelte +0 -12
- package/dist/components/card/card-subtitle.svelte +0 -12
- package/dist/components/card/card-title.svelte +0 -12
- package/dist/components/collapsible/collapsible-body.svelte +5 -12
- package/dist/components/collapsible/collapsible-header.svelte +0 -12
- package/dist/components/collapsible/collapsible-indicator.svelte +0 -12
- package/dist/components/collapsible/collapsible-root.svelte +0 -12
- package/dist/components/combobox/combobox-control.svelte +0 -12
- package/dist/components/combobox/combobox-item.svelte +0 -12
- package/dist/components/combobox/combobox-item.svelte.d.ts +0 -6
- package/dist/components/combobox/index.d.ts +1 -1
- package/dist/components/container/container.svelte +0 -12
- package/dist/components/datagrid/column/datagrid-column-sort-icon.svelte +3 -12
- package/dist/components/datagrid/column/datagrid-column-sort-icon.svelte.d.ts +0 -6
- package/dist/components/datagrid/datagrid-body.svelte +17 -1
- package/dist/components/dialog/dialog-body.svelte +0 -12
- package/dist/components/dialog/dialog-close-button.svelte +0 -12
- package/dist/components/dialog/dialog-close.svelte +0 -12
- package/dist/components/dialog/dialog-content.svelte +4 -12
- package/dist/components/dialog/dialog-description.svelte +0 -12
- package/dist/components/dialog/dialog-footer.svelte +0 -12
- package/dist/components/dialog/dialog-header.svelte +0 -12
- package/dist/components/dialog/dialog-title.svelte +0 -12
- package/dist/components/dialog/index.d.ts +3 -0
- package/dist/components/dialog/index.js +3 -0
- package/dist/components/drawer/drawer-backdrop.svelte +0 -12
- package/dist/components/drawer/drawer-body.svelte +0 -12
- package/dist/components/drawer/drawer-content.svelte +5 -12
- package/dist/components/drawer/drawer-description.svelte +0 -12
- package/dist/components/drawer/drawer-footer.svelte +0 -12
- package/dist/components/drawer/drawer-header.svelte +0 -12
- package/dist/components/drawer/drawer-root.svelte +5 -4
- package/dist/components/drawer/drawer-title.svelte +0 -12
- package/dist/components/dropdown/dropdown-placeholder.svelte +0 -6
- package/dist/components/dropdown/dropdown-placeholder.svelte.d.ts +0 -6
- package/dist/components/dropdown/dropdown-query.svelte +0 -12
- package/dist/components/dropdown-menu/bond.svelte.d.ts +0 -4
- package/dist/components/dropdown-menu/dropdown-menu-content.svelte +0 -12
- package/dist/components/dropdown-menu/dropdown-menu-content.svelte.d.ts +0 -6
- package/dist/components/dropdown-menu/index.d.ts +1 -1
- package/dist/components/form/field/bond.svelte.d.ts +29 -17
- package/dist/components/form/field/bond.svelte.js +73 -49
- package/dist/components/form/field/field-control.svelte +21 -18
- package/dist/components/form/field/field-label.svelte +2 -2
- package/dist/components/form/field/field-root.svelte +2 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/input/input-file-control.svelte +0 -12
- package/dist/components/input/input-icon.svelte +3 -3
- package/dist/components/input/input-number-control.svelte +28 -35
- package/dist/components/input/input-text-control.svelte +8 -3
- package/dist/components/input/input-url-control.svelte +2 -2
- package/dist/components/input/types.d.ts +4 -4
- package/dist/components/kbd/index.d.ts +3 -0
- package/dist/components/kbd/index.js +3 -0
- package/dist/components/kbd/kbd.svelte +19 -0
- package/dist/components/kbd/kbd.svelte.d.ts +4 -0
- package/dist/components/kbd/shortcut.svelte +38 -0
- package/dist/components/kbd/shortcut.svelte.d.ts +4 -0
- package/dist/components/kbd/types.d.ts +20 -0
- package/dist/components/kbd/types.js +1 -0
- package/dist/components/layer/layer-inner.svelte +0 -12
- package/dist/components/layer/layer-root.svelte +0 -12
- package/dist/components/menu/menu-content.svelte +0 -12
- package/dist/components/menu/menu-content.svelte.d.ts +0 -6
- package/dist/components/popover/bond.svelte.d.ts +29 -1
- package/dist/components/popover/bond.svelte.js +55 -2
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover/index.js +1 -0
- package/dist/components/popover/popover-arrow.svelte +4 -2
- package/dist/components/popover/popover-content.svelte +17 -90
- package/dist/components/popover/popover-overlay.svelte +98 -0
- package/dist/components/popover/popover-overlay.svelte.d.ts +4 -0
- package/dist/components/popover/popover-trigger.svelte +9 -0
- package/dist/components/popover/strategies/floating.svelte +10 -10
- package/dist/components/popover/types.d.ts +7 -2
- package/dist/components/portal/portal-inner.svelte +0 -12
- package/dist/components/portal/portal-root.svelte +0 -12
- package/dist/components/portal/types.d.ts +1 -1
- package/dist/components/progress/index.d.ts +3 -0
- package/dist/components/progress/index.js +3 -0
- package/dist/components/progress/progress-circular.svelte +99 -0
- package/dist/components/progress/progress-circular.svelte.d.ts +6 -0
- package/dist/components/progress/progress-linear.svelte +66 -0
- package/dist/components/progress/progress-linear.svelte.d.ts +6 -0
- package/dist/components/progress/types.d.ts +18 -0
- package/dist/components/progress/types.js +1 -0
- package/dist/components/scrollable/scrollable-container.svelte +0 -12
- package/dist/components/scrollable/scrollable-content.svelte +0 -12
- package/dist/components/scrollable/scrollable-root.svelte +0 -12
- package/dist/components/scrollable/scrollable-thumb.svelte +1 -12
- package/dist/components/scrollable/scrollable-track.svelte +0 -12
- package/dist/components/select/bond.svelte.d.ts +0 -4
- package/dist/components/select/index.d.ts +1 -1
- package/dist/components/select/select-placeholder.svelte +0 -6
- package/dist/components/select/select-placeholder.svelte.d.ts +0 -6
- package/dist/components/sidebar/sidebar-content.svelte +5 -12
- package/dist/components/stack/bond.svelte.js +6 -0
- package/dist/components/stack/stack-item.svelte +4 -0
- package/dist/components/switch/switch.svelte +2 -0
- package/dist/components/tabs/tab/tab-header.svelte +4 -4
- package/dist/components/tabs/tabs-body.svelte +0 -2
- package/dist/components/tabs/tabs-root.svelte +11 -3
- package/dist/components/toast/atoms.d.ts +1 -1
- package/dist/components/toast/atoms.js +1 -1
- package/dist/components/toast/attachments.svelte.d.ts +10 -2
- package/dist/components/toast/attachments.svelte.js +9 -1
- package/dist/components/toast/bond.svelte.d.ts +73 -0
- package/dist/components/toast/bond.svelte.js +132 -0
- package/dist/components/toast/index.d.ts +1 -1
- package/dist/components/toast/index.js +1 -1
- package/dist/components/toast/toast-close.svelte +47 -0
- package/dist/components/toast/toast-close.svelte.d.ts +26 -0
- package/dist/components/toast/toast-description.svelte +16 -24
- package/dist/components/toast/toast-description.svelte.d.ts +15 -19
- package/dist/components/toast/toast-root.svelte +36 -26
- package/dist/components/toast/toast-root.svelte.d.ts +16 -15
- package/dist/components/toast/toast-title.svelte +17 -22
- package/dist/components/toast/toast-title.svelte.d.ts +13 -13
- package/dist/components/toast/toaster.svelte.d.ts +38 -0
- package/dist/components/toast/toaster.svelte.js +107 -0
- package/dist/components/toast/types.d.ts +13 -21
- package/dist/components/tree/tree-body.svelte +5 -12
- package/dist/components/tree/tree-header.svelte +0 -12
- package/dist/components/tree/tree-indicator.svelte +0 -12
- package/dist/components/tree/tree-root.svelte +0 -12
- package/dist/context/preset.svelte.d.ts +53 -37
- package/dist/context/preset.svelte.js +29 -3
- package/package.json +1 -1
- package/dist/components/atom/utils.d.ts +0 -44
- package/dist/components/atom/utils.js +0 -275
- package/dist/components/popover/popover-engine.svelte +0 -118
- package/dist/components/popover/popover-engine.svelte.d.ts +0 -3
- package/dist/components/toast/bond.d.ts +0 -35
- package/dist/components/toast/bond.js +0 -59
- package/dist/components/toast/manager.svelte.d.ts +0 -38
- package/dist/components/toast/manager.svelte.js +0 -82
- package/dist/components/toast/toast-root-managed.svelte +0 -64
- package/dist/components/toast/toast-root-managed.svelte.d.ts +0 -7
- package/dist/components/toast/toast-toaster.svelte +0 -42
- package/dist/components/toast/toast-toaster.svelte.d.ts +0 -4
- /package/dist/components/popover/{motion.d.ts → motion.svelte.d.ts} +0 -0
- /package/dist/components/popover/{motion.js → motion.svelte.js} +0 -0
|
@@ -12,7 +12,17 @@ export interface PresetEntryRecord {
|
|
|
12
12
|
defaults?: Record<string, any>;
|
|
13
13
|
attachments?: Attachment[];
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
/** A single preset entry value — either a record or a deferred factory returning one. */
|
|
16
|
+
export type PresetEntryValue = PresetEntryRecord | (() => PresetEntryRecord);
|
|
17
|
+
/**
|
|
18
|
+
* A preset entry — invoked with a bond and returns either a single
|
|
19
|
+
* {@link PresetEntryValue} or an array of them.
|
|
20
|
+
*
|
|
21
|
+
* Returning an array makes it easy to layer/merge preset configurations
|
|
22
|
+
* (e.g. base preset + per-route override + per-component override). Entries
|
|
23
|
+
* are merged in order, with later entries taking precedence.
|
|
24
|
+
*/
|
|
25
|
+
export type PresetEntry = (bond: Bond | undefined | null, ...args: any[]) => PresetEntryValue | Array<PresetEntryValue>;
|
|
16
26
|
/**
|
|
17
27
|
* Registry of all preset slot names → their PresetEntry type.
|
|
18
28
|
*
|
|
@@ -31,7 +41,7 @@ export type PresetEntry = (bond: Bond | undefined | null, ...args: any[]) => Pre
|
|
|
31
41
|
* ```
|
|
32
42
|
*/
|
|
33
43
|
export interface PresetModuleMap {
|
|
34
|
-
|
|
44
|
+
accordion: PresetEntry;
|
|
35
45
|
'accordion.item.body': PresetEntry;
|
|
36
46
|
'accordion.item.header': PresetEntry;
|
|
37
47
|
'accordion.item.indicator': PresetEntry;
|
|
@@ -41,7 +51,7 @@ export interface PresetModuleMap {
|
|
|
41
51
|
'alert.content': PresetEntry;
|
|
42
52
|
'alert.description': PresetEntry;
|
|
43
53
|
'alert.icon': PresetEntry;
|
|
44
|
-
|
|
54
|
+
alert: PresetEntry;
|
|
45
55
|
'alert.title': PresetEntry;
|
|
46
56
|
'card.content': PresetEntry;
|
|
47
57
|
'card.description': PresetEntry;
|
|
@@ -49,13 +59,13 @@ export interface PresetModuleMap {
|
|
|
49
59
|
'card.header': PresetEntry;
|
|
50
60
|
'card.body': PresetEntry;
|
|
51
61
|
'card.media': PresetEntry;
|
|
52
|
-
|
|
62
|
+
card: PresetEntry;
|
|
53
63
|
'card.subtitle': PresetEntry;
|
|
54
64
|
'card.title': PresetEntry;
|
|
55
65
|
'collapsible.body': PresetEntry;
|
|
56
66
|
'collapsible.header': PresetEntry;
|
|
57
67
|
'collapsible.indicator': PresetEntry;
|
|
58
|
-
|
|
68
|
+
collapsible: PresetEntry;
|
|
59
69
|
'combobox.control': PresetEntry;
|
|
60
70
|
'combobox.trigger': PresetEntry;
|
|
61
71
|
'combobox.item': PresetEntry;
|
|
@@ -65,30 +75,30 @@ export interface PresetModuleMap {
|
|
|
65
75
|
'dialog.description': PresetEntry;
|
|
66
76
|
'dialog.footer': PresetEntry;
|
|
67
77
|
'dialog.header': PresetEntry;
|
|
68
|
-
|
|
78
|
+
dialog: PresetEntry;
|
|
69
79
|
'dialog.title': PresetEntry;
|
|
70
|
-
|
|
80
|
+
divider: PresetEntry;
|
|
71
81
|
'dropdown.placeholder': PresetEntry;
|
|
72
82
|
'dropdown.query': PresetEntry;
|
|
73
83
|
'dropdown.trigger': PresetEntry;
|
|
74
84
|
'dropdown.selections': PresetEntry;
|
|
75
85
|
'dropdown.selection': PresetEntry;
|
|
76
|
-
|
|
86
|
+
dropdown: PresetEntry;
|
|
77
87
|
'dropdown.item': PresetEntry;
|
|
78
88
|
'field.control': PresetEntry;
|
|
79
89
|
'field.label': PresetEntry;
|
|
80
90
|
'field.helper-text': PresetEntry;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
91
|
+
field: PresetEntry;
|
|
92
|
+
form: PresetEntry;
|
|
93
|
+
icon: PresetEntry;
|
|
94
|
+
input: PresetEntry;
|
|
85
95
|
'input.control': PresetEntry;
|
|
86
96
|
'input.password': PresetEntry;
|
|
87
97
|
'input.placeholder': PresetEntry;
|
|
88
|
-
|
|
98
|
+
label: PresetEntry;
|
|
89
99
|
'layer.inner': PresetEntry;
|
|
90
|
-
|
|
91
|
-
|
|
100
|
+
layer: PresetEntry;
|
|
101
|
+
link: PresetEntry;
|
|
92
102
|
'list.divider': PresetEntry;
|
|
93
103
|
'list.group': PresetEntry;
|
|
94
104
|
'list.item': PresetEntry;
|
|
@@ -98,11 +108,11 @@ export interface PresetModuleMap {
|
|
|
98
108
|
'popover.content': PresetEntry;
|
|
99
109
|
'popover.trigger': PresetEntry;
|
|
100
110
|
'portal.inner': PresetEntry;
|
|
101
|
-
|
|
102
|
-
|
|
111
|
+
portal: PresetEntry;
|
|
112
|
+
root: PresetEntry;
|
|
103
113
|
'root.portals': PresetEntry;
|
|
104
114
|
'sidebar.content': PresetEntry;
|
|
105
|
-
|
|
115
|
+
sidebar: PresetEntry;
|
|
106
116
|
'drawer.backdrop': PresetEntry;
|
|
107
117
|
'drawer.body': PresetEntry;
|
|
108
118
|
'drawer.content': PresetEntry;
|
|
@@ -110,10 +120,10 @@ export interface PresetModuleMap {
|
|
|
110
120
|
'drawer.title': PresetEntry;
|
|
111
121
|
'drawer.footer': PresetEntry;
|
|
112
122
|
'drawer.header': PresetEntry;
|
|
113
|
-
|
|
123
|
+
drawer: PresetEntry;
|
|
114
124
|
'stack.root': PresetEntry;
|
|
115
125
|
'stack.item': PresetEntry;
|
|
116
|
-
|
|
126
|
+
stepper: PresetEntry;
|
|
117
127
|
'stepper.header': PresetEntry;
|
|
118
128
|
'stepper.body': PresetEntry;
|
|
119
129
|
'stepper.footer': PresetEntry;
|
|
@@ -124,16 +134,16 @@ export interface PresetModuleMap {
|
|
|
124
134
|
'stepper.step.separator': PresetEntry;
|
|
125
135
|
'tabs.body': PresetEntry;
|
|
126
136
|
'tabs.header': PresetEntry;
|
|
127
|
-
|
|
137
|
+
tabs: PresetEntry;
|
|
128
138
|
'tab.header': PresetEntry;
|
|
129
139
|
'tab.body': PresetEntry;
|
|
130
140
|
'tab.description': PresetEntry;
|
|
131
|
-
|
|
141
|
+
tab: PresetEntry;
|
|
132
142
|
'tree.body': PresetEntry;
|
|
133
143
|
'tree.header': PresetEntry;
|
|
134
144
|
'tree.indicator': PresetEntry;
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
tree: PresetEntry;
|
|
146
|
+
datagrid: PresetEntry;
|
|
137
147
|
'datagrid.header': PresetEntry;
|
|
138
148
|
'datagrid.column': PresetEntry;
|
|
139
149
|
'datagrid.body': PresetEntry;
|
|
@@ -142,31 +152,29 @@ export interface PresetModuleMap {
|
|
|
142
152
|
'datagrid.footer': PresetEntry;
|
|
143
153
|
'datagrid.checkbox': PresetEntry;
|
|
144
154
|
'datagrid.sort-icon': PresetEntry;
|
|
145
|
-
|
|
155
|
+
scrollable: PresetEntry;
|
|
146
156
|
'scrollable.container': PresetEntry;
|
|
147
157
|
'scrollable.content': PresetEntry;
|
|
148
158
|
'scrollable.track': PresetEntry;
|
|
149
159
|
'scrollable.thumb': PresetEntry;
|
|
150
|
-
|
|
151
|
-
'toast.toaster': PresetEntry;
|
|
152
|
-
'toast.item': PresetEntry;
|
|
160
|
+
toast: PresetEntry;
|
|
153
161
|
'toast.title': PresetEntry;
|
|
154
162
|
'toast.description': PresetEntry;
|
|
155
|
-
'toast.close
|
|
156
|
-
|
|
163
|
+
'toast.close': PresetEntry;
|
|
164
|
+
breadcrumb: PresetEntry;
|
|
157
165
|
'breadcrumb.item': PresetEntry;
|
|
158
166
|
'breadcrumb.separator': PresetEntry;
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
badge: PresetEntry;
|
|
168
|
+
chip: PresetEntry;
|
|
161
169
|
'chip.close-button': PresetEntry;
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
button: PresetEntry;
|
|
171
|
+
checkbox: PresetEntry;
|
|
164
172
|
'checkbox.checkmark': PresetEntry;
|
|
165
173
|
'checkbox.indeterminate': PresetEntry;
|
|
166
|
-
|
|
174
|
+
radio: PresetEntry;
|
|
167
175
|
'radio.group': PresetEntry;
|
|
168
|
-
|
|
169
|
-
|
|
176
|
+
container: PresetEntry;
|
|
177
|
+
calendar: PresetEntry;
|
|
170
178
|
'calendar.day': PresetEntry;
|
|
171
179
|
'calendar.header': PresetEntry;
|
|
172
180
|
'calendar.weekday': PresetEntry;
|
|
@@ -176,6 +184,13 @@ export interface PresetModuleMap {
|
|
|
176
184
|
'datepicker.years': PresetEntry;
|
|
177
185
|
'datepicker.months': PresetEntry;
|
|
178
186
|
'datepicker.header': PresetEntry;
|
|
187
|
+
progress: PresetEntry;
|
|
188
|
+
'progress.linear': PresetEntry;
|
|
189
|
+
'progress.linear.track': PresetEntry;
|
|
190
|
+
'progress.linear.fill': PresetEntry;
|
|
191
|
+
'progress.circular': PresetEntry;
|
|
192
|
+
'progress.circular.track': PresetEntry;
|
|
193
|
+
'progress.circular.fill': PresetEntry;
|
|
179
194
|
}
|
|
180
195
|
/** All valid preset slot names — derived from PresetModuleMap for extensibility. */
|
|
181
196
|
export type PresetModuleName = keyof PresetModuleMap;
|
|
@@ -185,3 +200,4 @@ export type Preset = {
|
|
|
185
200
|
export declare function getPreset<K extends PresetModuleName>(key: K): PresetEntry | undefined;
|
|
186
201
|
export declare function getPreset(): Partial<Preset> | undefined;
|
|
187
202
|
export declare function setPreset(preset: Partial<Preset>): Partial<Preset>;
|
|
203
|
+
export declare function mergePreset(callback: (currentPreset: Partial<Preset> | undefined) => Partial<Preset>): Partial<Preset>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getContext, setContext } from 'svelte';
|
|
2
|
-
import {
|
|
2
|
+
import { mergePresetRecords, resolvePreset } from '../components/atom/utils/preset';
|
|
3
3
|
const CONTEXT_KEY = '@svelte-atoms/context/preset';
|
|
4
4
|
export function getPreset(...args) {
|
|
5
5
|
const context = getContext(CONTEXT_KEY);
|
|
@@ -10,6 +10,32 @@ export function getPreset(...args) {
|
|
|
10
10
|
return context;
|
|
11
11
|
}
|
|
12
12
|
export function setPreset(preset) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
return mergePreset(() => preset);
|
|
14
|
+
}
|
|
15
|
+
export function mergePreset(callback) {
|
|
16
|
+
const currentPreset = getPreset();
|
|
17
|
+
const override = callback(currentPreset);
|
|
18
|
+
const result = { ...currentPreset };
|
|
19
|
+
const keys = Object.keys(override);
|
|
20
|
+
for (let i = 0; i < keys.length; i++) {
|
|
21
|
+
const k = keys[i];
|
|
22
|
+
const next = override[k];
|
|
23
|
+
if (!next)
|
|
24
|
+
continue;
|
|
25
|
+
const existing = currentPreset?.[k];
|
|
26
|
+
if (existing) {
|
|
27
|
+
const e = existing, n = next;
|
|
28
|
+
result[k] = ((bond, ...args) => {
|
|
29
|
+
const a = resolvePreset(e(bond, ...args));
|
|
30
|
+
const b = resolvePreset(n(bond, ...args));
|
|
31
|
+
if (a && b)
|
|
32
|
+
return mergePresetRecords([a, b]);
|
|
33
|
+
return a ?? b;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
result[k] = next;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return setContext(CONTEXT_KEY, result);
|
|
15
41
|
}
|
package/package.json
CHANGED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Bond } from '../../shared';
|
|
2
|
-
import { type ClassValue, type VariantDefinition } from '../../utils';
|
|
3
|
-
type ResolvedProps = Record<string, unknown>;
|
|
4
|
-
type AnyVariantDefinition = VariantDefinition<any>;
|
|
5
|
-
/**
|
|
6
|
-
* Resolves preset to its final value, handling both direct values and factory functions
|
|
7
|
-
*/
|
|
8
|
-
export declare function resolvePreset<T>(preset: T | (() => T) | undefined): T | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Pure function to resolve variant definition to props
|
|
11
|
-
* Caches results to avoid recomputation with same inputs
|
|
12
|
-
*/
|
|
13
|
-
export declare function resolveVariants(def: AnyVariantDefinition, bond: Bond | null | undefined, props: Record<string, unknown>): ResolvedProps;
|
|
14
|
-
/**
|
|
15
|
-
* Pure function to merge preset and local variant definitions
|
|
16
|
-
* Returns merged variant props with local overriding preset
|
|
17
|
-
*/
|
|
18
|
-
export declare function mergeVariants(presetVariants: Record<string, any> | undefined, presetClass: ClassValue | undefined, presetCompounds: Array<Record<string, any>> | undefined, presetDefaults: Record<string, any> | undefined, localVariants: ResolvedProps | undefined, bond: Bond | null | undefined, props: Record<string, unknown>): ResolvedProps | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Pure function to merge classes with $preset placeholder support
|
|
21
|
-
* Handles the special $preset placeholder for precise positioning of preset classes
|
|
22
|
-
*/
|
|
23
|
-
export declare function mergeClassesWithPreset(userClass: string | ClassValue | undefined, presetClass: ClassValue | undefined, variantClass: ClassValue | undefined): string;
|
|
24
|
-
/**
|
|
25
|
-
* Pure function to resolve local variants.
|
|
26
|
-
* Handles both function-based and VariantDefinition-based variants.
|
|
27
|
-
*
|
|
28
|
-
* If the function was created by `defineVariants`, it carries a VARIANT_DEF_TAG
|
|
29
|
-
* symbol with the original config. We detect this and route through the cached
|
|
30
|
-
* resolveVariants engine so defineVariants-based variants benefit from the same
|
|
31
|
-
* two-level WeakMap cache as raw VariantDefinition objects.
|
|
32
|
-
*/
|
|
33
|
-
export declare function resolveLocalVariants(variants: any, bond: Bond | null | undefined, props: Record<string, unknown>): ResolvedProps | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Pure function to extract rest props by filtering out preset and variant-specific props
|
|
36
|
-
*/
|
|
37
|
-
export declare function extractRestProps(preset: Record<string, any> | undefined, mergedVariants: ResolvedProps | undefined, restProps: Record<string, unknown>): Record<string, unknown>;
|
|
38
|
-
/**
|
|
39
|
-
* Pure function to check if a base is a snippet.
|
|
40
|
-
* Svelte 5 snippets compile to arrow functions (no prototype),
|
|
41
|
-
* while components compile to named functions (with prototype).
|
|
42
|
-
*/
|
|
43
|
-
export declare function isSnippetBase(base: unknown): boolean;
|
|
44
|
-
export {};
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import { cn, VARIANT_DEF_TAG } from '../../utils';
|
|
2
|
-
import { call } from '../../utils/function';
|
|
3
|
-
/**
|
|
4
|
-
* Two-level cache for resolved variants.
|
|
5
|
-
* Outer key: bond instance identity (WeakMap for automatic GC when bond is destroyed).
|
|
6
|
-
* Inner key: JSON stringified variant-relevant props.
|
|
7
|
-
* Bond-less calls share a single flat Map.
|
|
8
|
-
*/
|
|
9
|
-
const variantCacheByBond = new WeakMap();
|
|
10
|
-
const variantCacheNoBond = new Map();
|
|
11
|
-
const MAX_CACHE_SIZE = 100;
|
|
12
|
-
function getCacheMap(bond) {
|
|
13
|
-
if (!bond)
|
|
14
|
-
return variantCacheNoBond;
|
|
15
|
-
let map = variantCacheByBond.get(bond);
|
|
16
|
-
if (!map) {
|
|
17
|
-
map = new Map();
|
|
18
|
-
variantCacheByBond.set(bond, map);
|
|
19
|
-
}
|
|
20
|
-
return map;
|
|
21
|
-
}
|
|
22
|
-
function hasOwnKeys(obj) {
|
|
23
|
-
for (const k in obj)
|
|
24
|
-
if (Object.hasOwn(obj, k))
|
|
25
|
-
return true;
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
const PRESET_SKIP = new Set(['class', 'base', 'as', 'variants', 'compounds', 'defaults']);
|
|
29
|
-
const VARIANTS_SKIP = new Set(['class', 'variants', 'compounds', 'defaults']);
|
|
30
|
-
/**
|
|
31
|
-
* Resolves preset to its final value, handling both direct values and factory functions
|
|
32
|
-
*/
|
|
33
|
-
export function resolvePreset(preset) {
|
|
34
|
-
if (!preset)
|
|
35
|
-
return undefined;
|
|
36
|
-
const result = call(preset);
|
|
37
|
-
// If call returns a function, call it again (handle deferred preset)
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
-
return typeof result === 'function' ? result() : result;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Pure function to resolve variant definition to props
|
|
43
|
-
* Caches results to avoid recomputation with same inputs
|
|
44
|
-
*/
|
|
45
|
-
export function resolveVariants(def, bond, props) {
|
|
46
|
-
const { variants: variantMap, compounds, defaults, class: baseClass } = def;
|
|
47
|
-
// Merge props with defaults
|
|
48
|
-
const finalProps = defaults && hasOwnKeys(defaults) ? { ...defaults, ...props } : props;
|
|
49
|
-
const variantKeys = variantMap ? Object.keys(variantMap) : [];
|
|
50
|
-
// Fast path: no variants or compounds — skip cache entirely
|
|
51
|
-
if (variantKeys.length === 0 && !compounds?.length) {
|
|
52
|
-
return { class: baseClass ? [baseClass] : [] };
|
|
53
|
-
}
|
|
54
|
-
// Build cache key only when variants are present
|
|
55
|
-
const relevantProps = {};
|
|
56
|
-
for (const key of variantKeys)
|
|
57
|
-
if (key in finalProps)
|
|
58
|
-
relevantProps[key] = finalProps[key];
|
|
59
|
-
const cacheKey = JSON.stringify({ relevantProps, baseClass, compounds });
|
|
60
|
-
const cacheMap = getCacheMap(bond);
|
|
61
|
-
if (cacheMap.has(cacheKey)) {
|
|
62
|
-
return cacheMap.get(cacheKey);
|
|
63
|
-
}
|
|
64
|
-
const classes = [];
|
|
65
|
-
const attributes = {};
|
|
66
|
-
// Add base class
|
|
67
|
-
if (baseClass)
|
|
68
|
-
classes.push(baseClass);
|
|
69
|
-
// Add variant classes
|
|
70
|
-
if (variantMap) {
|
|
71
|
-
for (const key of variantKeys) {
|
|
72
|
-
const value = finalProps[key];
|
|
73
|
-
if (value === undefined)
|
|
74
|
-
continue;
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
-
const variantValue = variantMap[key]?.[value];
|
|
77
|
-
if (variantValue !== undefined) {
|
|
78
|
-
const resolved = typeof variantValue === 'function' ? variantValue(bond) : variantValue;
|
|
79
|
-
if (typeof resolved === 'string') {
|
|
80
|
-
classes.push(resolved);
|
|
81
|
-
}
|
|
82
|
-
else if (typeof resolved === 'object' && resolved !== null) {
|
|
83
|
-
if ('class' in resolved) {
|
|
84
|
-
classes.push(resolved.class);
|
|
85
|
-
}
|
|
86
|
-
// Add other attributes (including Symbol-based attachment keys)
|
|
87
|
-
Object.getOwnPropertySymbols(resolved).forEach((sym) => {
|
|
88
|
-
attributes[sym] = resolved[sym];
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// Add compound variants
|
|
95
|
-
if (compounds?.length) {
|
|
96
|
-
for (const compound of compounds) {
|
|
97
|
-
const compoundClass = compound.class;
|
|
98
|
-
const compoundPropKeys = new Set(Object.keys(compound).filter((k) => k !== 'class'));
|
|
99
|
-
let matches = true;
|
|
100
|
-
for (const key of compoundPropKeys) {
|
|
101
|
-
if (finalProps[key] !== compound[key]) {
|
|
102
|
-
matches = false;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (matches) {
|
|
107
|
-
if (compoundClass)
|
|
108
|
-
classes.push(compoundClass);
|
|
109
|
-
// Add compound attributes (string keys that are not condition keys or 'class')
|
|
110
|
-
for (const [k, v] of Object.entries(compound)) {
|
|
111
|
-
if (k !== 'class' && !compoundPropKeys.has(k))
|
|
112
|
-
attributes[k] = v;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const result = {
|
|
118
|
-
class: classes,
|
|
119
|
-
...attributes
|
|
120
|
-
};
|
|
121
|
-
// Store in cache (limit per-bond cache size to prevent memory leaks)
|
|
122
|
-
if (cacheMap.size >= MAX_CACHE_SIZE) {
|
|
123
|
-
const firstKey = cacheMap.keys().next().value;
|
|
124
|
-
if (firstKey)
|
|
125
|
-
cacheMap.delete(firstKey);
|
|
126
|
-
}
|
|
127
|
-
cacheMap.set(cacheKey, result);
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Pure function to merge preset and local variant definitions
|
|
132
|
-
* Returns merged variant props with local overriding preset
|
|
133
|
-
*/
|
|
134
|
-
export function mergeVariants(
|
|
135
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
|
-
presetVariants, presetClass,
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
138
|
-
presetCompounds,
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
-
presetDefaults, localVariants, bond, props) {
|
|
141
|
-
// No variants at all
|
|
142
|
-
if (!presetVariants && !localVariants)
|
|
143
|
-
return undefined;
|
|
144
|
-
// Only preset variants (raw object from preset)
|
|
145
|
-
if (presetVariants && !localVariants) {
|
|
146
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
147
|
-
const variantDef = {
|
|
148
|
-
class: presetClass ?? '',
|
|
149
|
-
variants: presetVariants,
|
|
150
|
-
compounds: presetCompounds ?? [],
|
|
151
|
-
defaults: presetDefaults ?? {}
|
|
152
|
-
};
|
|
153
|
-
return resolveVariants(variantDef, bond, props);
|
|
154
|
-
}
|
|
155
|
-
// Only local variants
|
|
156
|
-
if (!presetVariants && localVariants) {
|
|
157
|
-
return localVariants;
|
|
158
|
-
}
|
|
159
|
-
// Both exist - merge them
|
|
160
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
161
|
-
const presetVariantDef = {
|
|
162
|
-
class: presetClass ?? '',
|
|
163
|
-
variants: presetVariants ?? {},
|
|
164
|
-
compounds: presetCompounds ?? [],
|
|
165
|
-
defaults: presetDefaults ?? {}
|
|
166
|
-
};
|
|
167
|
-
const presetResolved = resolveVariants(presetVariantDef, bond, props);
|
|
168
|
-
// Merge the resolved variant props
|
|
169
|
-
// Local variant classes and attributes override preset
|
|
170
|
-
const presetClasses = Array.isArray(presetResolved.class)
|
|
171
|
-
? presetResolved.class
|
|
172
|
-
: [presetResolved.class];
|
|
173
|
-
const localClasses = Array.isArray(localVariants?.class)
|
|
174
|
-
? localVariants.class
|
|
175
|
-
: [localVariants?.class];
|
|
176
|
-
return {
|
|
177
|
-
...presetResolved,
|
|
178
|
-
...localVariants,
|
|
179
|
-
class: [...presetClasses, ...localClasses].filter(Boolean)
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Pure function to merge classes with $preset placeholder support
|
|
184
|
-
* Handles the special $preset placeholder for precise positioning of preset classes
|
|
185
|
-
*/
|
|
186
|
-
export function mergeClassesWithPreset(userClass, presetClass, variantClass) {
|
|
187
|
-
const klassStr = cn(userClass ?? '');
|
|
188
|
-
// Check for $preset placeholder first
|
|
189
|
-
if (!klassStr.includes('$preset')) {
|
|
190
|
-
// No placeholder - normal merge: variants override direct class
|
|
191
|
-
return cn(userClass, variantClass ?? '');
|
|
192
|
-
}
|
|
193
|
-
// Has placeholder - calculate position and inject preset classes
|
|
194
|
-
const parts = klassStr.split('$preset');
|
|
195
|
-
// Only keep the last $preset placeholder
|
|
196
|
-
const beforeLastPlaceholder = parts.slice(0, -1).join('');
|
|
197
|
-
const afterLastPlaceholder = parts[parts.length - 1];
|
|
198
|
-
const presetClassString = cn(presetClass);
|
|
199
|
-
// Merge: before + preset + variants + after
|
|
200
|
-
return cn(beforeLastPlaceholder, presetClassString, variantClass ?? '', afterLastPlaceholder);
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Pure function to resolve local variants.
|
|
204
|
-
* Handles both function-based and VariantDefinition-based variants.
|
|
205
|
-
*
|
|
206
|
-
* If the function was created by `defineVariants`, it carries a VARIANT_DEF_TAG
|
|
207
|
-
* symbol with the original config. We detect this and route through the cached
|
|
208
|
-
* resolveVariants engine so defineVariants-based variants benefit from the same
|
|
209
|
-
* two-level WeakMap cache as raw VariantDefinition objects.
|
|
210
|
-
*/
|
|
211
|
-
export function resolveLocalVariants(
|
|
212
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
213
|
-
variants, bond, props) {
|
|
214
|
-
if (!variants)
|
|
215
|
-
return undefined;
|
|
216
|
-
// Detect functions tagged by defineVariants — route through the cache
|
|
217
|
-
if (typeof variants === 'function' && VARIANT_DEF_TAG in variants) {
|
|
218
|
-
const config = variants[VARIANT_DEF_TAG];
|
|
219
|
-
// If config is a function (dynamic/bond-based), resolve it to a VariantDefinition first
|
|
220
|
-
const resolvedConfig = typeof config === 'function' ? config(bond) : config;
|
|
221
|
-
return resolveVariants(resolvedConfig, bond, props);
|
|
222
|
-
}
|
|
223
|
-
// Plain function (legacy / manual variants fn) — call directly, no cache
|
|
224
|
-
if (typeof variants === 'function') {
|
|
225
|
-
return variants(bond, props);
|
|
226
|
-
}
|
|
227
|
-
// Raw VariantDefinition object — resolve through cache
|
|
228
|
-
return resolveVariants(variants, bond, props);
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Internal keys that are never valid DOM attributes — stripped before spreading onto element
|
|
232
|
-
*/
|
|
233
|
-
const INTERNAL_PROPS = new Set(['class', 'base', 'as', 'variants', 'compounds', 'defaults']);
|
|
234
|
-
/**
|
|
235
|
-
* Pure function to extract rest props by filtering out preset and variant-specific props
|
|
236
|
-
*/
|
|
237
|
-
export function extractRestProps(
|
|
238
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
239
|
-
preset, mergedVariants, restProps) {
|
|
240
|
-
const result = {};
|
|
241
|
-
if (preset) {
|
|
242
|
-
for (const k in preset)
|
|
243
|
-
if (Object.hasOwn(preset, k) && !PRESET_SKIP.has(k))
|
|
244
|
-
result[k] = preset[k];
|
|
245
|
-
// Preserve Symbol-keyed attachment props (e.g. from createAttachmentKey())
|
|
246
|
-
const symPreset = preset;
|
|
247
|
-
for (const s of Object.getOwnPropertySymbols(preset))
|
|
248
|
-
result[s] = symPreset[s];
|
|
249
|
-
}
|
|
250
|
-
if (mergedVariants) {
|
|
251
|
-
for (const k in mergedVariants)
|
|
252
|
-
if (Object.hasOwn(mergedVariants, k) && !VARIANTS_SKIP.has(k))
|
|
253
|
-
result[k] = mergedVariants[k];
|
|
254
|
-
// Preserve Symbol-keyed attachment props (e.g. from variant definitions)
|
|
255
|
-
const symProps = mergedVariants;
|
|
256
|
-
for (const s of Object.getOwnPropertySymbols(mergedVariants))
|
|
257
|
-
result[s] = symProps[s];
|
|
258
|
-
}
|
|
259
|
-
for (const k in restProps)
|
|
260
|
-
if (Object.hasOwn(restProps, k))
|
|
261
|
-
result[k] = restProps[k];
|
|
262
|
-
// Preserve Symbol-keyed attachment props from restProps (e.g. {@attach} directives)
|
|
263
|
-
const symRestProps = restProps;
|
|
264
|
-
for (const s of Object.getOwnPropertySymbols(restProps))
|
|
265
|
-
result[s] = symRestProps[s];
|
|
266
|
-
return result;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Pure function to check if a base is a snippet.
|
|
270
|
-
* Svelte 5 snippets compile to arrow functions (no prototype),
|
|
271
|
-
* while components compile to named functions (with prototype).
|
|
272
|
-
*/
|
|
273
|
-
export function isSnippetBase(base) {
|
|
274
|
-
return typeof base === 'function' && !base.prototype;
|
|
275
|
-
}
|