@a4ui/core 0.17.0 → 0.18.0

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.
@@ -390,9 +390,9 @@ export {
390
390
  Se as c,
391
391
  Fe as d,
392
392
  Le as e,
393
- Ee as f,
394
- De as g,
395
- Pe as h,
393
+ De as f,
394
+ Pe as g,
395
+ Ee as h,
396
396
  Me as i,
397
397
  V as j,
398
398
  H as k,
@@ -0,0 +1,53 @@
1
+ import { Accessor } from 'solid-js';
2
+ export interface CartProduct {
3
+ id: string | number;
4
+ price: number;
5
+ }
6
+ export interface CartEntry<T extends CartProduct> {
7
+ product: T;
8
+ qty: number;
9
+ }
10
+ export interface Cart<T extends CartProduct> {
11
+ /** Reactive list of cart entries. */
12
+ items: Accessor<CartEntry<T>[]>;
13
+ /** Add a product, or increment its `qty` if it's already in the cart. */
14
+ add: (product: T, qty?: number) => void;
15
+ /** Remove a product from the cart by id. */
16
+ remove: (id: T['id']) => void;
17
+ /** Set a product's quantity. `qty <= 0` removes the entry. */
18
+ setQty: (id: T['id'], qty: number) => void;
19
+ /** Empty the cart. */
20
+ clear: () => void;
21
+ /** Total number of units across all entries. */
22
+ count: () => number;
23
+ /** Sum of `price * qty` across all entries. */
24
+ subtotal: () => number;
25
+ /** Whether a product with this id is currently in the cart. */
26
+ has: (id: T['id']) => boolean;
27
+ }
28
+ /**
29
+ * Create a signal-backed shopping cart store, generic over the product type.
30
+ * `count()` and `subtotal()` are memoized and stay in sync with `items()`.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * interface Product extends CartProduct {
35
+ * id: string
36
+ * price: number
37
+ * title: string
38
+ * }
39
+ *
40
+ * const cart = createCart<Product>()
41
+ *
42
+ * cart.add({ id: 'sku-1', price: 29.99, title: 'Wireless Mouse' })
43
+ * cart.add({ id: 'sku-1', price: 29.99, title: 'Wireless Mouse' }) // qty -> 2
44
+ * cart.setQty('sku-1', 3)
45
+ *
46
+ * cart.count() // 3
47
+ * cart.subtotal() // 89.97
48
+ *
49
+ * cart.remove('sku-1')
50
+ * cart.has('sku-1') // false
51
+ * ```
52
+ */
53
+ export declare function createCart<T extends CartProduct>(initial?: CartEntry<T>[]): Cart<T>;
@@ -5,3 +5,4 @@ export { ProductGrid, type ProductGridProps } from './ProductGrid';
5
5
  export { CartLine, type CartLineProps } from './CartLine';
6
6
  export { CartSummary, type CartSummaryProps, type CartSummaryItem } from './CartSummary';
7
7
  export { FilterGroup, type FilterGroupProps, type FacetOption } from './FilterGroup';
8
+ export { createCart, type Cart, type CartProduct, type CartEntry } from './createCart';
package/dist/commerce.js CHANGED
@@ -1,78 +1,78 @@
1
- import { insert as n, createComponent as i, memo as A, effect as v, className as b, template as o, delegateEvents as y, setAttribute as x } from "solid-js/web";
2
- import { Show as s, For as C } from "solid-js";
3
- import { c as h } from "./cn-B6yFEsav.js";
4
- import { B as T, C as N, R as E, a as S, b as I } from "./Checkbox-DMx0y81E.js";
5
- import { Minus as R, Plus as F, Trash2 as U } from "lucide-solid";
6
- var j = /* @__PURE__ */ o('<span class="text-muted-foreground line-through">'), q = /* @__PURE__ */ o("<div><span>");
7
- const B = {
1
+ import { insert as l, createComponent as d, memo as I, effect as b, className as $, template as g, delegateEvents as S, setAttribute as y } from "solid-js/web";
2
+ import { Show as h, For as k, createSignal as N, createMemo as C } from "solid-js";
3
+ import { c as x } from "./cn-B6yFEsav.js";
4
+ import { B as q, C as E, R, a as A, b as F } from "./Checkbox-BZjX1GMG.js";
5
+ import { Minus as M, Plus as P, Trash2 as U } from "lucide-solid";
6
+ var j = /* @__PURE__ */ g('<span class="text-muted-foreground line-through">'), B = /* @__PURE__ */ g("<div><span>");
7
+ const D = {
8
8
  sm: "text-sm",
9
9
  md: "text-lg",
10
10
  lg: "text-2xl"
11
11
  };
12
- function k(e) {
13
- const r = (u) => new Intl.NumberFormat(e.locale ?? "en-US", {
12
+ function T(e) {
13
+ const n = (a) => new Intl.NumberFormat(e.locale ?? "en-US", {
14
14
  style: "currency",
15
15
  currency: e.currency ?? "USD"
16
- }).format(u), l = () => (e.compareAt ?? 0) > e.amount, t = () => Math.round((1 - e.amount / e.compareAt) * 100);
16
+ }).format(a), r = () => (e.compareAt ?? 0) > e.amount, t = () => Math.round((1 - e.amount / e.compareAt) * 100);
17
17
  return (() => {
18
- var u = q(), d = u.firstChild;
19
- return n(d, () => r(e.amount)), n(u, i(s, {
18
+ var a = B(), o = a.firstChild;
19
+ return l(o, () => n(e.amount)), l(a, d(h, {
20
20
  get when() {
21
- return l();
21
+ return r();
22
22
  },
23
23
  get children() {
24
24
  return [(() => {
25
- var c = j();
26
- return n(c, () => r(e.compareAt)), c;
27
- })(), i(T, {
25
+ var u = j();
26
+ return l(u, () => n(e.compareAt)), u;
27
+ })(), d(q, {
28
28
  tone: "danger",
29
29
  get children() {
30
- return ["-", A(() => t()), "%"];
30
+ return ["-", I(() => t()), "%"];
31
31
  }
32
32
  })];
33
33
  }
34
- }), null), v((c) => {
35
- var a = h("inline-flex items-center gap-2", e.class), m = h("font-bold text-foreground", B[e.size ?? "md"]);
36
- return a !== c.e && b(u, c.e = a), m !== c.t && b(d, c.t = m), c;
34
+ }), null), b((u) => {
35
+ var c = x("inline-flex items-center gap-2", e.class), s = x("font-bold text-foreground", D[e.size ?? "md"]);
36
+ return c !== u.e && $(a, u.e = c), s !== u.t && $(o, u.t = s), u;
37
37
  }, {
38
38
  e: void 0,
39
39
  t: void 0
40
- }), u;
40
+ }), a;
41
41
  })();
42
42
  }
43
- var M = /* @__PURE__ */ o('<div><button type=button aria-label="Decrease quantity"class="grid h-8 w-8 place-items-center hover:bg-muted disabled:opacity-40"></button><span class="grid min-w-[2.5rem] place-items-center tabular-nums"></span><button type=button aria-label="Increase quantity"class="grid h-8 w-8 place-items-center hover:bg-muted disabled:opacity-40">');
44
- function P(e) {
45
- const r = () => e.min ?? 0, l = () => e.max ?? Number.MAX_SAFE_INTEGER, t = (c) => Math.min(l(), Math.max(r(), c)), u = () => e.onChange(t(e.value - 1)), d = () => e.onChange(t(e.value + 1));
43
+ var L = /* @__PURE__ */ g('<div><button type=button aria-label="Decrease quantity"class="grid h-8 w-8 place-items-center hover:bg-muted disabled:opacity-40"></button><span class="grid min-w-[2.5rem] place-items-center tabular-nums"></span><button type=button aria-label="Increase quantity"class="grid h-8 w-8 place-items-center hover:bg-muted disabled:opacity-40">');
44
+ function z(e) {
45
+ const n = () => e.min ?? 0, r = () => e.max ?? Number.MAX_SAFE_INTEGER, t = (u) => Math.min(r(), Math.max(n(), u)), a = () => e.onChange(t(e.value - 1)), o = () => e.onChange(t(e.value + 1));
46
46
  return (() => {
47
- var c = M(), a = c.firstChild, m = a.nextSibling, f = m.nextSibling;
48
- return a.$$click = u, n(a, i(R, {
47
+ var u = L(), c = u.firstChild, s = c.nextSibling, f = s.nextSibling;
48
+ return c.$$click = a, l(c, d(M, {
49
49
  class: "h-4 w-4"
50
- })), n(m, () => e.value), f.$$click = d, n(f, i(F, {
50
+ })), l(s, () => e.value), f.$$click = o, l(f, d(P, {
51
51
  class: "h-4 w-4"
52
- })), v((g) => {
53
- var $ = h("inline-flex items-stretch rounded-md border border-input", e.class), _ = e.disabled || e.value <= r(), w = e.disabled || e.value >= l();
54
- return $ !== g.e && b(c, g.e = $), _ !== g.t && (a.disabled = g.t = _), w !== g.a && (f.disabled = g.a = w), g;
52
+ })), b((i) => {
53
+ var m = x("inline-flex items-stretch rounded-md border border-input", e.class), v = e.disabled || e.value <= n(), _ = e.disabled || e.value >= r();
54
+ return m !== i.e && $(u, i.e = m), v !== i.t && (c.disabled = i.t = v), _ !== i.a && (f.disabled = i.a = _), i;
55
55
  }, {
56
56
  e: void 0,
57
57
  t: void 0,
58
58
  a: void 0
59
- }), c;
59
+ }), u;
60
60
  })();
61
61
  }
62
- y(["click"]);
63
- var D = /* @__PURE__ */ o("<span>"), L = /* @__PURE__ */ o('<div class="relative aspect-square overflow-hidden rounded-lg bg-muted"><img loading=lazy class="h-full w-full object-cover">', !0, !1, !1), z = /* @__PURE__ */ o('<span class="text-[11px] font-medium uppercase tracking-wide text-muted-foreground">'), G = /* @__PURE__ */ o('<span class="w-fit rounded bg-muted px-1.5 py-0.5 text-[11px] text-muted-foreground">'), O = /* @__PURE__ */ o('<div class="mt-3 flex flex-1 flex-col gap-1.5"><p class="line-clamp-1 font-medium text-foreground">');
64
- const Q = {
62
+ S(["click"]);
63
+ var G = /* @__PURE__ */ g("<span>"), O = /* @__PURE__ */ g('<div class="relative aspect-square overflow-hidden rounded-lg bg-muted"><img loading=lazy class="h-full w-full object-cover">', !0, !1, !1), Q = /* @__PURE__ */ g('<span class="text-[11px] font-medium uppercase tracking-wide text-muted-foreground">'), X = /* @__PURE__ */ g('<span class="w-fit rounded bg-muted px-1.5 py-0.5 text-[11px] text-muted-foreground">'), Z = /* @__PURE__ */ g('<div class="mt-3 flex flex-1 flex-col gap-1.5"><p class="line-clamp-1 font-medium text-foreground">');
64
+ const H = {
65
65
  sale: "bg-destructive text-destructive-foreground",
66
66
  new: "bg-primary text-primary-foreground",
67
67
  featured: "bg-accent text-accent-foreground"
68
68
  };
69
- function X(e, r) {
70
- if (r) return r;
71
- const l = (e ?? "").toLowerCase();
72
- return /sale|off|%|deal/.test(l) ? "sale" : /new/.test(l) ? "new" : "featured";
69
+ function J(e, n) {
70
+ if (n) return n;
71
+ const r = (e ?? "").toLowerCase();
72
+ return /sale|off|%|deal/.test(r) ? "sale" : /new/.test(r) ? "new" : "featured";
73
73
  }
74
- function ue(e) {
75
- return i(N, {
74
+ function de(e) {
75
+ return d(E, {
76
76
  glass: !0,
77
77
  glow: !0,
78
78
  get tilt() {
@@ -82,50 +82,50 @@ function ue(e) {
82
82
  return e.spotlight;
83
83
  },
84
84
  get class() {
85
- return h("flex h-full flex-col overflow-hidden p-4", e.class);
85
+ return x("flex h-full flex-col overflow-hidden p-4", e.class);
86
86
  },
87
87
  get children() {
88
88
  return [(() => {
89
- var r = L(), l = r.firstChild;
90
- return n(r, i(s, {
89
+ var n = O(), r = n.firstChild;
90
+ return l(n, d(h, {
91
91
  get when() {
92
92
  return e.badge;
93
93
  },
94
94
  get children() {
95
- var t = D();
96
- return n(t, () => e.badge), v(() => b(t, h("absolute -right-9 top-3.5 w-32 rotate-45 py-1 text-center text-[11px] font-semibold uppercase tracking-wide shadow-md", Q[X(e.badge, e.badgeTone)]))), t;
95
+ var t = G();
96
+ return l(t, () => e.badge), b(() => $(t, x("absolute -right-9 top-3.5 w-32 rotate-45 py-1 text-center text-[11px] font-semibold uppercase tracking-wide shadow-md", H[J(e.badge, e.badgeTone)]))), t;
97
97
  }
98
- }), null), v((t) => {
99
- var u = e.image, d = e.title;
100
- return u !== t.e && x(l, "src", t.e = u), d !== t.t && x(l, "alt", t.t = d), t;
98
+ }), null), b((t) => {
99
+ var a = e.image, o = e.title;
100
+ return a !== t.e && y(r, "src", t.e = a), o !== t.t && y(r, "alt", t.t = o), t;
101
101
  }, {
102
102
  e: void 0,
103
103
  t: void 0
104
- }), r;
104
+ }), n;
105
105
  })(), (() => {
106
- var r = O(), l = r.firstChild;
107
- return n(r, i(s, {
106
+ var n = Z(), r = n.firstChild;
107
+ return l(n, d(h, {
108
108
  get when() {
109
109
  return e.brand;
110
110
  },
111
111
  get children() {
112
- var t = z();
113
- return n(t, () => e.brand), t;
112
+ var t = Q();
113
+ return l(t, () => e.brand), t;
114
114
  }
115
- }), l), n(l, () => e.title), n(r, i(s, {
115
+ }), r), l(r, () => e.title), l(n, d(h, {
116
116
  get when() {
117
117
  return e.category;
118
118
  },
119
119
  get children() {
120
- var t = G();
121
- return n(t, () => e.category), t;
120
+ var t = X();
121
+ return l(t, () => e.category), t;
122
122
  }
123
- }), null), n(r, i(s, {
123
+ }), null), l(n, d(h, {
124
124
  get when() {
125
125
  return e.rating !== void 0;
126
126
  },
127
127
  get children() {
128
- return i(E, {
128
+ return d(R, {
129
129
  get value() {
130
130
  return e.rating;
131
131
  },
@@ -133,7 +133,7 @@ function ue(e) {
133
133
  max: 5
134
134
  });
135
135
  }
136
- }), null), n(r, i(k, {
136
+ }), null), l(n, d(T, {
137
137
  get amount() {
138
138
  return e.price;
139
139
  },
@@ -146,55 +146,55 @@ function ue(e) {
146
146
  get locale() {
147
147
  return e.locale;
148
148
  }
149
- }), null), n(r, i(s, {
149
+ }), null), l(n, d(h, {
150
150
  get when() {
151
151
  return e.onAddToCart;
152
152
  },
153
153
  get children() {
154
- return i(S, {
154
+ return d(A, {
155
155
  class: "mt-auto w-full",
156
- onClick: () => {
157
- var t;
158
- return (t = e.onAddToCart) == null ? void 0 : t.call(e);
156
+ onClick: (t) => {
157
+ var a;
158
+ t.stopPropagation(), (a = e.onAddToCart) == null || a.call(e);
159
159
  },
160
160
  children: "Add to cart"
161
161
  });
162
162
  }
163
- }), null), r;
163
+ }), null), n;
164
164
  })()];
165
165
  }
166
166
  });
167
167
  }
168
- var Z = /* @__PURE__ */ o("<div>");
169
- function ie(e) {
168
+ var K = /* @__PURE__ */ g("<div>");
169
+ function oe(e) {
170
170
  return (() => {
171
- var r = Z();
172
- return n(r, () => e.children), v(() => b(r, h("grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-4", e.class))), r;
171
+ var n = K();
172
+ return l(n, () => e.children), b(() => $(n, x("grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-4", e.class))), n;
173
173
  })();
174
174
  }
175
- var H = /* @__PURE__ */ o('<img class="h-16 w-16 shrink-0 rounded-md bg-muted object-cover">'), J = /* @__PURE__ */ o('<button type=button aria-label="Remove item"class="text-muted-foreground hover:text-foreground">'), K = /* @__PURE__ */ o('<div><div class="min-w-[8rem] flex-1"><p class="line-clamp-1 font-medium text-foreground"></p></div><span class="min-w-[4rem] text-right font-medium tabular-nums text-foreground">');
176
- function ce(e) {
177
- const r = () => e.price * e.quantity, l = (t) => new Intl.NumberFormat(e.locale ?? "en-US", {
175
+ var V = /* @__PURE__ */ g('<img class="h-16 w-16 shrink-0 rounded-md bg-muted object-cover">'), W = /* @__PURE__ */ g('<button type=button aria-label="Remove item"class="text-muted-foreground hover:text-foreground">'), Y = /* @__PURE__ */ g('<div><div class="min-w-[8rem] flex-1"><p class="line-clamp-1 font-medium text-foreground"></p></div><span class="min-w-[4rem] text-right font-medium tabular-nums text-foreground">');
176
+ function se(e) {
177
+ const n = () => e.price * e.quantity, r = (t) => new Intl.NumberFormat(e.locale ?? "en-US", {
178
178
  style: "currency",
179
179
  currency: e.currency ?? "USD"
180
180
  }).format(t);
181
181
  return (() => {
182
- var t = K(), u = t.firstChild, d = u.firstChild, c = u.nextSibling;
183
- return n(t, i(s, {
182
+ var t = Y(), a = t.firstChild, o = a.firstChild, u = a.nextSibling;
183
+ return l(t, d(h, {
184
184
  get when() {
185
185
  return e.image;
186
186
  },
187
187
  get children() {
188
- var a = H();
189
- return v((m) => {
190
- var f = e.image, g = e.title;
191
- return f !== m.e && x(a, "src", m.e = f), g !== m.t && x(a, "alt", m.t = g), m;
188
+ var c = V();
189
+ return b((s) => {
190
+ var f = e.image, i = e.title;
191
+ return f !== s.e && y(c, "src", s.e = f), i !== s.t && y(c, "alt", s.t = i), s;
192
192
  }, {
193
193
  e: void 0,
194
194
  t: void 0
195
- }), a;
195
+ }), c;
196
196
  }
197
- }), u), n(d, () => e.title), n(u, i(k, {
197
+ }), a), l(o, () => e.title), l(a, d(T, {
198
198
  get amount() {
199
199
  return e.price;
200
200
  },
@@ -205,108 +205,129 @@ function ce(e) {
205
205
  return e.locale;
206
206
  },
207
207
  size: "sm"
208
- }), null), n(t, i(P, {
208
+ }), null), l(t, d(z, {
209
209
  get value() {
210
210
  return e.quantity;
211
211
  },
212
- onChange: (a) => {
213
- var m;
214
- return (m = e.onQuantityChange) == null ? void 0 : m.call(e, a);
212
+ onChange: (c) => {
213
+ var s;
214
+ return (s = e.onQuantityChange) == null ? void 0 : s.call(e, c);
215
215
  },
216
216
  min: 1
217
- }), c), n(c, () => l(r())), n(t, i(s, {
217
+ }), u), l(u, () => r(n())), l(t, d(h, {
218
218
  get when() {
219
219
  return e.onRemove;
220
220
  },
221
221
  get children() {
222
- var a = J();
223
- return a.$$click = () => {
224
- var m;
225
- return (m = e.onRemove) == null ? void 0 : m.call(e);
226
- }, n(a, i(U, {
222
+ var c = W();
223
+ return c.$$click = () => {
224
+ var s;
225
+ return (s = e.onRemove) == null ? void 0 : s.call(e);
226
+ }, l(c, d(U, {
227
227
  class: "h-4 w-4"
228
- })), a;
228
+ })), c;
229
229
  }
230
- }), null), v(() => b(t, h("flex flex-wrap items-center gap-4", e.class))), t;
230
+ }), null), b(() => $(t, x("flex flex-wrap items-center gap-4", e.class))), t;
231
231
  })();
232
232
  }
233
- y(["click"]);
234
- var V = /* @__PURE__ */ o('<div><div class="my-3 border-t border-border"></div><div class="flex items-center justify-between text-base font-bold text-foreground"><span>Total</span><span class=tabular-nums>'), W = /* @__PURE__ */ o('<div class="flex items-center justify-between py-1 text-sm"><span class=text-muted-foreground></span><span class="tabular-nums text-foreground">');
235
- function de(e) {
236
- const r = (l) => new Intl.NumberFormat(e.locale ?? "en-US", {
233
+ S(["click"]);
234
+ var p = /* @__PURE__ */ g('<div><div class="my-3 border-t border-border"></div><div class="flex items-center justify-between text-base font-bold text-foreground"><span>Total</span><span class=tabular-nums>'), ee = /* @__PURE__ */ g('<div class="flex items-center justify-between py-1 text-sm"><span class=text-muted-foreground></span><span class="tabular-nums text-foreground">');
235
+ function me(e) {
236
+ const n = (r) => new Intl.NumberFormat(e.locale ?? "en-US", {
237
237
  style: "currency",
238
238
  currency: e.currency ?? "USD"
239
- }).format(l);
239
+ }).format(r);
240
240
  return (() => {
241
- var l = V(), t = l.firstChild, u = t.nextSibling, d = u.firstChild, c = d.nextSibling;
242
- return n(l, i(C, {
241
+ var r = p(), t = r.firstChild, a = t.nextSibling, o = a.firstChild, u = o.nextSibling;
242
+ return l(r, d(k, {
243
243
  get each() {
244
244
  return e.lines;
245
245
  },
246
- children: (a) => (() => {
247
- var m = W(), f = m.firstChild, g = f.nextSibling;
248
- return n(f, () => a.label), n(g, () => r(a.amount)), m;
246
+ children: (c) => (() => {
247
+ var s = ee(), f = s.firstChild, i = f.nextSibling;
248
+ return l(f, () => c.label), l(i, () => n(c.amount)), s;
249
249
  })()
250
- }), t), n(c, () => r(e.total)), n(l, i(s, {
250
+ }), t), l(u, () => n(e.total)), l(r, d(h, {
251
251
  get when() {
252
252
  return e.onCheckout;
253
253
  },
254
254
  get children() {
255
- return i(S, {
255
+ return d(A, {
256
256
  class: "mt-4 w-full",
257
257
  onClick: () => {
258
- var a;
259
- return (a = e.onCheckout) == null ? void 0 : a.call(e);
258
+ var c;
259
+ return (c = e.onCheckout) == null ? void 0 : c.call(e);
260
260
  },
261
261
  get children() {
262
262
  return e.checkoutLabel ?? "Checkout";
263
263
  }
264
264
  });
265
265
  }
266
- }), null), v(() => b(l, h("card glow-edge rounded-xl p-5 text-card-foreground", e.class))), l;
266
+ }), null), b(() => $(r, x("card glow-edge rounded-xl p-5 text-card-foreground", e.class))), r;
267
267
  })();
268
268
  }
269
- var Y = /* @__PURE__ */ o('<div><p class="text-sm font-semibold text-foreground"></p><div class=space-y-1.5>'), p = /* @__PURE__ */ o('<span class="text-xs text-muted-foreground">'), ee = /* @__PURE__ */ o('<div class="flex items-center justify-between gap-2">');
270
- function me(e) {
271
- const r = (l, t) => {
272
- const u = e.selected.slice(), d = u.indexOf(l);
273
- t ? d === -1 && u.push(l) : d !== -1 && u.splice(d, 1), e.onChange(u);
269
+ var te = /* @__PURE__ */ g('<div><p class="text-sm font-semibold text-foreground"></p><div class=space-y-1.5>'), ne = /* @__PURE__ */ g('<span class="text-xs text-muted-foreground">'), re = /* @__PURE__ */ g('<div class="flex items-center justify-between gap-2">');
270
+ function ge(e) {
271
+ const n = (r, t) => {
272
+ const a = e.selected.slice(), o = a.indexOf(r);
273
+ t ? o === -1 && a.push(r) : o !== -1 && a.splice(o, 1), e.onChange(a);
274
274
  };
275
275
  return (() => {
276
- var l = Y(), t = l.firstChild, u = t.nextSibling;
277
- return n(t, () => e.title), n(u, i(C, {
276
+ var r = te(), t = r.firstChild, a = t.nextSibling;
277
+ return l(t, () => e.title), l(a, d(k, {
278
278
  get each() {
279
279
  return e.options;
280
280
  },
281
- children: (d) => (() => {
282
- var c = ee();
283
- return n(c, i(I, {
281
+ children: (o) => (() => {
282
+ var u = re();
283
+ return l(u, d(F, {
284
284
  get checked() {
285
- return e.selected.includes(d.value);
285
+ return e.selected.includes(o.value);
286
286
  },
287
- onChange: (a) => r(d.value, a),
287
+ onChange: (c) => n(o.value, c),
288
288
  get label() {
289
- return d.label;
289
+ return o.label;
290
290
  }
291
- }), null), n(c, i(s, {
291
+ }), null), l(u, d(h, {
292
292
  get when() {
293
- return d.count != null;
293
+ return o.count != null;
294
294
  },
295
295
  get children() {
296
- var a = p();
297
- return n(a, () => d.count), a;
296
+ var c = ne();
297
+ return l(c, () => o.count), c;
298
298
  }
299
- }), null), c;
299
+ }), null), u;
300
300
  })()
301
- })), v(() => b(l, h("space-y-2", e.class))), l;
301
+ })), b(() => $(r, x("space-y-2", e.class))), r;
302
302
  })();
303
303
  }
304
+ function fe(e = []) {
305
+ const [n, r] = N(e), t = (i, m = 1) => {
306
+ r((v) => v.find((w) => w.product.id === i.id) ? v.map(
307
+ (w) => w.product.id === i.id ? { ...w, qty: w.qty + m } : w
308
+ ) : [...v, { product: i, qty: m }]);
309
+ }, a = (i) => {
310
+ r((m) => m.filter((v) => v.product.id !== i));
311
+ }, o = (i, m) => {
312
+ if (m <= 0) {
313
+ a(i);
314
+ return;
315
+ }
316
+ r((v) => v.map((_) => _.product.id === i ? { ..._, qty: m } : _));
317
+ }, u = () => {
318
+ r([]);
319
+ }, c = C(() => n().reduce((i, m) => i + m.qty, 0)), s = C(
320
+ () => n().reduce((i, m) => i + m.product.price * m.qty, 0)
321
+ );
322
+ return { items: n, add: t, remove: a, setQty: o, clear: u, count: c, subtotal: s, has: (i) => n().some((m) => m.product.id === i) };
323
+ }
304
324
  export {
305
- ce as CartLine,
306
- de as CartSummary,
307
- me as FilterGroup,
308
- k as PriceTag,
309
- ue as ProductCard,
310
- ie as ProductGrid,
311
- P as QuantityStepper
325
+ se as CartLine,
326
+ me as CartSummary,
327
+ ge as FilterGroup,
328
+ T as PriceTag,
329
+ de as ProductCard,
330
+ oe as ProductGrid,
331
+ z as QuantityStepper,
332
+ fe as createCart
312
333
  };