@commerce-blocks/sdk 2.0.0-alpha.3 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,59 +1,45 @@
1
- import { effect as re, signal as P, computed as O } from "@preact/signals-core";
2
- import { batch as Wt, computed as Zt, effect as en, signal as tn } from "@preact/signals-core";
3
- const Se = "2.0.0-alpha.3", Re = {
4
- version: Se
5
- }, Te = "https://app.uselayers.com/api/storefront/v1", ke = 1e3, Oe = 100, Ne = 300 * ke, oe = Re.version, K = 1, J = 24, Z = 1, ee = 1, te = 100, Ce = 20, Le = 50, Pe = 300, De = 50, ve = "USD", Me = "en-US", qe = 1e3, pe = /* @__PURE__ */ new Map();
6
- function _e(e, t) {
7
- const r = `${e}:${t}`;
8
- let n = pe.get(r);
9
- return n || (n = new Intl.NumberFormat(Me, {
10
- style: "currency",
11
- currency: t
12
- }).format(e), pe.set(r, n)), n;
13
- }
14
- function L(e) {
1
+ import { effect as ie, signal as q, computed as L } from "@preact/signals-core";
2
+ import { batch as rr, computed as nr, effect as ar, signal as or } from "@preact/signals-core";
3
+ const Ne = "2.0.2", Le = {
4
+ version: Ne
5
+ }, Pe = "https://app.uselayers.com/api/storefront/v1", qe = 1e3, De = 100, Fe = 300 * qe, ce = Le.version, K = 1, X = 24, ne = 1, ae = 1, oe = 100, Ue = 10, Me = 200, Ve = 300, $e = 50, Be = 1e3;
6
+ function k(e) {
15
7
  return { data: e };
16
8
  }
17
- function b(e) {
9
+ function y(e) {
18
10
  return { error: e };
19
11
  }
20
- const Ue = ["TIMEOUT", "CONNECTION_FAILED", "DNS_FAILED"];
21
- function ae(e) {
22
- const t = Ue.includes(e.code);
12
+ function Q(e) {
23
13
  return {
24
14
  _tag: "NetworkError",
25
15
  code: e.code,
26
16
  message: e.message,
27
- cause: e.cause,
28
- retryable: t,
29
- retryAfterMs: t ? 1e3 : void 0
17
+ cause: e.cause
30
18
  };
31
19
  }
32
- function Fe(e) {
20
+ function Ge(e) {
33
21
  if (!e) return;
34
22
  const t = e["retry-after"] ?? e["Retry-After"];
35
23
  if (!t) return;
36
24
  const r = t.trim();
37
25
  if (/^\d+$/.test(r))
38
26
  return Number(r) * 1e3;
39
- const n = new Date(t);
40
- if (!isNaN(n.getTime()))
41
- return Math.max(0, n.getTime() - Date.now());
27
+ const a = new Date(t);
28
+ if (!isNaN(a.getTime()))
29
+ return Math.max(0, a.getTime() - Date.now());
42
30
  }
43
- function be(e) {
44
- const t = e.code === "RATE_LIMITED" || e.code === "SERVICE_UNAVAILABLE" || e.code === "NOT_READY" || e.status !== void 0 && e.status >= 500, r = e.retryAfterMs ?? Fe(e.responseHeaders) ?? (t ? 1e3 : void 0);
31
+ function Ie(e) {
45
32
  return {
46
33
  _tag: "ApiError",
47
34
  code: e.code,
48
35
  source: e.source,
49
36
  message: e.message,
50
37
  status: e.status,
51
- retryable: t,
52
- retryAfterMs: r,
38
+ retryAfterMs: e.retryAfterMs ?? Ge(e.responseHeaders),
53
39
  cause: e.cause
54
40
  };
55
41
  }
56
- function x(e) {
42
+ function B(e) {
57
43
  return {
58
44
  _tag: "ValidationError",
59
45
  code: "VALIDATION_FAILED",
@@ -63,15 +49,15 @@ function x(e) {
63
49
  input: e.input
64
50
  };
65
51
  }
66
- function F(e, t, r, n) {
52
+ function M(e, t, r, a) {
67
53
  return {
68
54
  field: e,
69
55
  code: t,
70
56
  message: r,
71
- ...n
57
+ ...a
72
58
  };
73
59
  }
74
- function Q(e) {
60
+ function H(e) {
75
61
  return {
76
62
  _tag: "ConfigError",
77
63
  code: e.code,
@@ -81,65 +67,62 @@ function Q(e) {
81
67
  expected: e.expected
82
68
  };
83
69
  }
84
- const $e = /* @__PURE__ */ new Set(["NetworkError", "ApiError", "ValidationError", "ConfigError"]);
85
- function Ct(e) {
86
- return typeof e == "object" && e !== null && $e.has(e._tag ?? "");
87
- }
88
- function Ve(e) {
89
- return "retryable" in e ? e.retryable : !1;
70
+ const xe = /* @__PURE__ */ new Set(["NetworkError", "ApiError", "ValidationError", "ConfigError"]);
71
+ function qt(e) {
72
+ return typeof e == "object" && e !== null && xe.has(e._tag ?? "");
90
73
  }
91
- function Be(e) {
92
- if ("retryAfterMs" in e) return e.retryAfterMs;
74
+ function Dt(e) {
75
+ return e._tag === "NetworkError" ? e.code === "TIMEOUT" || e.code === "CONNECTION_FAILED" || e.code === "DNS_FAILED" : e._tag === "ApiError" ? e.code === "RATE_LIMITED" || e.code === "SERVICE_UNAVAILABLE" || e.code === "NOT_READY" || e.status !== void 0 && e.status >= 500 : !1;
93
76
  }
94
- const xe = {
77
+ const je = {
95
78
  401: "UNAUTHORIZED",
96
79
  403: "FORBIDDEN",
97
80
  404: "NOT_FOUND",
98
81
  425: "NOT_READY",
99
82
  429: "RATE_LIMITED"
100
83
  };
101
- function Ge(e, t) {
102
- const { status: r } = e, n = xe[r] ?? (r >= 500 ? "SERVICE_UNAVAILABLE" : "UNKNOWN");
103
- let a;
84
+ function He(e, t) {
85
+ const { status: r } = e, a = je[r] ?? (r >= 500 ? "SERVICE_UNAVAILABLE" : "UNKNOWN");
86
+ let c;
104
87
  try {
105
- const o = JSON.parse(t);
106
- typeof o.retry_after_ms == "number" && (a = o.retry_after_ms);
88
+ const n = JSON.parse(t);
89
+ typeof n.retry_after_ms == "number" && (c = n.retry_after_ms);
107
90
  } catch {
108
91
  }
109
- return be({
110
- code: n,
92
+ return Ie({
93
+ code: a,
111
94
  source: "layers",
112
95
  message: t || `HTTP ${r}`,
113
96
  status: r,
114
- retryAfterMs: a,
97
+ retryAfterMs: c,
115
98
  responseHeaders: Object.fromEntries(e.headers.entries())
116
99
  });
117
100
  }
118
- function He(e) {
101
+ function Qe(e) {
119
102
  if (e instanceof Error && (e.name === "AbortError" || e.name === "TimeoutError")) {
120
103
  const t = e.name === "TimeoutError" || e.message.includes("timeout");
121
- return ae({
104
+ return Q({
122
105
  code: t ? "TIMEOUT" : "ABORTED",
123
106
  message: t ? "Request timed out" : "Request was aborted",
124
107
  cause: e
125
108
  });
126
109
  }
127
- return ae({
110
+ return Q({
128
111
  code: "CONNECTION_FAILED",
129
112
  message: e instanceof Error ? e.message : "Network request failed",
130
113
  cause: e
131
114
  });
132
115
  }
133
- async function je(e) {
116
+ async function Je(e) {
134
117
  if (!e.ok) {
135
118
  const t = await e.text().catch(() => "");
136
- return b(Ge(e, t));
119
+ return y(He(e, t));
137
120
  }
138
121
  try {
139
- return L(await e.json());
122
+ return k(await e.json());
140
123
  } catch (t) {
141
- return b(
142
- be({
124
+ return y(
125
+ Ie({
143
126
  code: "PARSE_ERROR",
144
127
  source: "layers",
145
128
  message: "Invalid JSON response",
@@ -148,99 +131,95 @@ async function je(e) {
148
131
  );
149
132
  }
150
133
  }
151
- function ie({
134
+ function de({
152
135
  token: e,
153
136
  json: t = !0
154
137
  }) {
155
138
  const r = {
156
139
  Accept: "application/json",
157
140
  "X-Storefront-Access-Token": e,
158
- "X-SDK-Client": `commerce-blocks-sdk/${oe}`
141
+ "X-SDK-Client": `commerce-blocks-sdk/${ce}`
159
142
  };
160
143
  return t && (r["Content-Type"] = "application/json"), r;
161
144
  }
162
- function ce({ config: e, endpoint: t }) {
163
- const { baseUrl: r = Te } = e;
145
+ function fe({ config: e, endpoint: t }) {
146
+ const { baseUrl: r = Pe } = e;
164
147
  return `${r}${t}`;
165
148
  }
166
- function ue(e) {
149
+ function me(e) {
167
150
  return e.fetch ?? ((t, r) => fetch(t, r));
168
151
  }
169
- async function le(e, t, r) {
152
+ async function ge(e, t, r) {
170
153
  try {
171
- const n = await e(t, r);
172
- return je(n);
173
- } catch (n) {
174
- return b(He(n));
154
+ const a = await e(t, r);
155
+ return Je(a);
156
+ } catch (a) {
157
+ return y(Qe(a));
175
158
  }
176
159
  }
177
- async function B(e) {
178
- return le(ue(e.config), ce(e), {
160
+ async function $(e) {
161
+ return ge(me(e.config), fe(e), {
179
162
  method: "POST",
180
- headers: ie({ token: e.config.token }),
163
+ headers: de({ token: e.config.token }),
181
164
  body: JSON.stringify(e.body),
182
165
  signal: e.signal
183
166
  });
184
167
  }
185
- async function Qe(e) {
168
+ async function Ke(e) {
186
169
  const t = new URLSearchParams();
187
- for (const [a, o] of Object.entries(e.params))
188
- o != null && t.append(a, typeof o == "object" ? JSON.stringify(o) : String(o));
189
- const r = t.toString(), n = r ? `${e.endpoint}?${r}` : e.endpoint;
190
- return le(
191
- ue(e.config),
192
- ce({ config: e.config, endpoint: n }),
170
+ for (const [c, n] of Object.entries(e.params))
171
+ n != null && t.append(c, typeof n == "object" ? JSON.stringify(n) : String(n));
172
+ const r = t.toString(), a = r ? `${e.endpoint}?${r}` : e.endpoint;
173
+ return ge(
174
+ me(e.config),
175
+ fe({ config: e.config, endpoint: a }),
193
176
  {
194
177
  method: "GET",
195
- headers: ie({ token: e.config.token }),
178
+ headers: de({ token: e.config.token }),
196
179
  signal: e.signal
197
180
  }
198
181
  );
199
182
  }
200
- async function Ke(e) {
201
- return le(ue(e.config), ce(e), {
183
+ async function Xe(e) {
184
+ return ge(me(e.config), fe(e), {
202
185
  method: "POST",
203
- headers: ie({ token: e.config.token, json: !1 }),
186
+ headers: de({ token: e.config.token, json: !1 }),
204
187
  body: e.formData,
205
188
  signal: e.signal
206
189
  });
207
190
  }
208
191
  function U(e, t, r) {
209
- return r ? null : x({
192
+ return r ? null : B({
210
193
  operation: e,
211
- fields: [F(t, "REQUIRED_FIELD", `${t} is required`)]
194
+ fields: [M(t, "REQUIRED_FIELD", `${t} is required`)]
212
195
  });
213
196
  }
214
197
  function j(e, t) {
215
198
  if (!e) return null;
216
199
  const r = [];
217
- return e.page !== void 0 && e.page < Z && r.push(
218
- F("page", "OUT_OF_RANGE", `page must be >= ${Z}`, {
200
+ return e.page !== void 0 && e.page < ne && r.push(
201
+ M("page", "OUT_OF_RANGE", `page must be >= ${ne}`, {
219
202
  value: e.page,
220
- constraints: { min: Z }
203
+ constraints: { min: ne }
221
204
  })
222
- ), e.limit !== void 0 && (e.limit < ee || e.limit > te) && r.push(
223
- F(
205
+ ), e.limit !== void 0 && (e.limit < ae || e.limit > oe) && r.push(
206
+ M(
224
207
  "limit",
225
208
  "OUT_OF_RANGE",
226
- `limit must be between ${ee} and ${te}`,
209
+ `limit must be between ${ae} and ${oe}`,
227
210
  {
228
211
  value: e.limit,
229
- constraints: { min: ee, max: te }
212
+ constraints: { min: ae, max: oe }
230
213
  }
231
214
  )
232
- ), r.length > 0 ? x({ operation: t, fields: r }) : null;
215
+ ), r.length > 0 ? B({ operation: t, fields: r }) : null;
233
216
  }
234
- const Je = [
217
+ const Ye = [
235
218
  "title",
236
219
  "handle",
237
220
  "available",
238
- "images",
239
- "options",
240
221
  "options_v2",
241
- "variants",
242
222
  "first_or_matched_variant",
243
- "price_range",
244
223
  "vendor",
245
224
  "product_type",
246
225
  "tags",
@@ -251,10 +230,10 @@ const Je = [
251
230
  "combined_listing_parent_product_id",
252
231
  "combined_listing_role"
253
232
  ];
254
- function Ye(e) {
233
+ function ze(e) {
255
234
  if (!e.token)
256
- return b(
257
- Q({
235
+ return y(
236
+ H({
258
237
  code: "MISSING_CONFIG",
259
238
  message: "token is required",
260
239
  field: "token",
@@ -262,136 +241,176 @@ function Ye(e) {
262
241
  })
263
242
  );
264
243
  if (!e.sorts || e.sorts.length === 0)
265
- return b(
266
- Q({
244
+ return y(
245
+ H({
267
246
  code: "MISSING_CONFIG",
268
247
  message: "At least one sort option is required",
269
248
  field: "sorts",
270
249
  expected: "non-empty array of Sort"
271
250
  })
272
251
  );
273
- function t(o) {
274
- return [.../* @__PURE__ */ new Set([...Je, ...e.attributes ?? [], ...o ?? []])];
275
- }
252
+ if (e.facets && !Array.isArray(e.facets))
253
+ return y(
254
+ H({
255
+ code: "INVALID_CONFIG",
256
+ message: "facets must be an array",
257
+ field: "facets",
258
+ expected: "array of Facet"
259
+ })
260
+ );
261
+ const t = [.../* @__PURE__ */ new Set([...Ye, ...e.attributes ?? []])];
276
262
  function r({
277
- attributes: o,
278
- transformBody: s,
279
- rest: u,
280
- includeFacets: c = !0
263
+ transformBody: n,
264
+ rest: i,
265
+ includeFacets: u = !0
281
266
  }) {
282
- let l = {
283
- attributes: t(o),
284
- ...u
267
+ let s = {
268
+ attributes: t,
269
+ ...i
285
270
  };
286
- return c && (l.facets = e.facets.map((i) => i.code), l.retrieveFacetCount = !0, l.includeFacetRanges = !0), s && (l = s(l)), l;
271
+ return u && (s.facets ?? (s.facets = e.facets?.map((d) => d.code) ?? []), s.retrieveFacetCount ?? (s.retrieveFacetCount = !0), s.includeFacetRanges ?? (s.includeFacetRanges = !0)), n && (s = n(s)), s;
287
272
  }
288
- const n = {
273
+ const a = {
289
274
  token: e.token,
290
275
  baseUrl: e.baseUrl,
291
276
  fetch: e.fetch
292
277
  };
293
- return L({
294
- browse: async (o, s) => {
295
- const u = U("browse", "collectionHandle", o.collectionHandle);
296
- if (u) return b(u);
297
- const c = U("browse", "sort_order_code", o.sort_order_code);
298
- if (c) return b(c);
299
- const l = j(o.pagination, "browse");
300
- if (l) return b(l);
301
- const { collectionHandle: i, attributes: f, transformBody: g, ...p } = o;
302
- return B({
303
- config: n,
304
- endpoint: `/browse/${i}`,
305
- body: r({ attributes: f, transformBody: g, rest: p }),
306
- signal: s
278
+ return k({
279
+ browse: async (n, i) => {
280
+ const u = U("browse", "collectionHandle", n.collectionHandle);
281
+ if (u) return y(u);
282
+ const s = U("browse", "sort_order_code", n.sort_order_code);
283
+ if (s) return y(s);
284
+ const d = j(n.pagination, "browse");
285
+ if (d) return y(d);
286
+ const { collectionHandle: o, transformBody: l, ...g } = n;
287
+ return $({
288
+ config: a,
289
+ endpoint: `/browse/${encodeURIComponent(o)}`,
290
+ body: r({ transformBody: l, rest: g }),
291
+ signal: i
307
292
  });
308
293
  },
309
- predictiveSearch: async (o, s) => {
310
- const u = U("predictiveSearch", "query", o);
311
- return u ? b(u) : Qe({
312
- config: n,
294
+ predictiveSearch: async (n, i) => {
295
+ const u = U("predictiveSearch", "query", n);
296
+ return u ? y(u) : Ke({
297
+ config: a,
313
298
  endpoint: "/search/complete",
314
- params: { query: o },
315
- signal: s
299
+ params: { query: n },
300
+ signal: i
316
301
  });
317
302
  },
318
- prepareSearch: async (o, s) => {
319
- const u = U("prepareSearch", "query", o.query);
320
- if (u) return b(u);
321
- const { query: c, transformBody: l, ...i } = o;
322
- let f = { ...i };
323
- return l && (f = l(f)), B({
324
- config: n,
325
- endpoint: `/search/${encodeURIComponent(c)}/prepare`,
326
- body: f,
327
- signal: s
303
+ prepareSearch: async (n, i) => {
304
+ const u = U("prepareSearch", "query", n.query);
305
+ if (u) return y(u);
306
+ const { query: s, transformBody: d, ...o } = n, l = r({ transformBody: d, rest: o, includeFacets: !1 });
307
+ return $({
308
+ config: a,
309
+ endpoint: `/search/${encodeURIComponent(s)}/prepare`,
310
+ body: l,
311
+ signal: i
328
312
  });
329
313
  },
330
- search: async (o, s) => {
331
- const u = U("search", "query", o.query);
332
- if (u) return b(u);
333
- const c = j(o.pagination, "search");
334
- if (c) return b(c);
335
- const { query: l, attributes: i, transformBody: f, ...g } = o;
336
- return B({
337
- config: n,
338
- endpoint: `/search/${encodeURIComponent(l)}/execute`,
339
- body: r({ attributes: i, transformBody: f, rest: g }),
340
- signal: s
314
+ search: async (n, i) => {
315
+ const u = U("search", "query", n.query);
316
+ if (u) return y(u);
317
+ const s = j(n.pagination, "search");
318
+ if (s) return y(s);
319
+ const { query: d, transformBody: o, ...l } = n;
320
+ return $({
321
+ config: a,
322
+ endpoint: `/search/${encodeURIComponent(d)}/execute`,
323
+ body: r({ transformBody: o, rest: l }),
324
+ signal: i
341
325
  });
342
326
  },
343
- imageSearch: async (o, s) => {
344
- if (!o.image_data && !o.image_id)
345
- return b(
346
- x({
327
+ imageSearch: async (n, i) => {
328
+ if (!n.image_data && !n.image_id)
329
+ return y(
330
+ B({
347
331
  operation: "imageSearch",
348
332
  fields: [
349
- F("image_data", "REQUIRED_FIELD", "image_data or image_id is required")
333
+ M("image_data", "REQUIRED_FIELD", "image_data or image_id is required")
350
334
  ]
351
335
  })
352
336
  );
353
- const u = j(o.pagination, "imageSearch");
354
- if (u) return b(u);
355
- const { attributes: c, transformBody: l, ...i } = o;
356
- return B({
357
- config: n,
337
+ const u = j(n.pagination, "imageSearch");
338
+ if (u) return y(u);
339
+ const { transformBody: s, ...d } = n;
340
+ return $({
341
+ config: a,
358
342
  endpoint: "/search/image",
359
- body: r({ attributes: c, transformBody: l, rest: i, includeFacets: !1 }),
360
- signal: s
343
+ body: r({ transformBody: s, rest: d, includeFacets: !1 }),
344
+ signal: i
361
345
  });
362
346
  },
363
- uploadImage: async (o, s) => {
347
+ uploadImage: async (n, i) => {
364
348
  const u = new FormData();
365
- return u.append("image", o), Ke({
366
- config: n,
349
+ return u.append("image", n), Xe({
350
+ config: a,
367
351
  endpoint: "/images/upload",
368
352
  formData: u,
369
- signal: s
353
+ signal: i
354
+ });
355
+ },
356
+ blocks: async (n, i) => {
357
+ const u = U("block", "blockId", n.blockId);
358
+ if (u) return y(u);
359
+ const s = j(n.pagination, "block");
360
+ if (s) return y(s);
361
+ const { blockId: d, transformBody: o, ...l } = n;
362
+ return $({
363
+ config: a,
364
+ endpoint: `/blocks/${encodeURIComponent(d)}/products`,
365
+ body: r({ transformBody: o, rest: l }),
366
+ signal: i
370
367
  });
371
368
  },
372
- blocks: async (o, s) => {
373
- const u = U("block", "blockId", o.blockId);
374
- if (u) return b(u);
375
- const c = j(o.pagination, "block");
376
- if (c) return b(c);
377
- const { blockId: l, attributes: i, transformBody: f, ...g } = o;
378
- return B({
379
- config: n,
380
- endpoint: `/blocks/${l}/products`,
381
- body: r({ attributes: i, transformBody: f, rest: g }),
382
- signal: s
369
+ searchContent: async (n, i) => {
370
+ const u = U("searchContent", "query", n.query);
371
+ if (u) return y(u);
372
+ const s = j(n.pagination, "searchContent");
373
+ if (s) return y(s);
374
+ const { query: d, transformBody: o, ...l } = n;
375
+ let g = { ...l };
376
+ return o && (g = o(g)), $({
377
+ config: a,
378
+ endpoint: `/search/content/${encodeURIComponent(d)}/execute`,
379
+ body: g,
380
+ signal: i
383
381
  });
384
382
  }
385
383
  });
386
384
  }
387
- function ze(e) {
388
- return typeof window > "u" || !window.localStorage ? null : {
389
- read: () => window.localStorage.getItem(e),
390
- write: (t) => window.localStorage.setItem(e, t),
391
- remove: () => window.localStorage.removeItem(e)
385
+ function We(e) {
386
+ try {
387
+ if (typeof window > "u" || !window.localStorage) return null;
388
+ } catch {
389
+ return null;
390
+ }
391
+ return {
392
+ read: () => {
393
+ try {
394
+ return window.localStorage.getItem(e);
395
+ } catch {
396
+ return null;
397
+ }
398
+ },
399
+ write: (t) => {
400
+ try {
401
+ window.localStorage.setItem(e, t);
402
+ } catch {
403
+ }
404
+ },
405
+ remove: () => {
406
+ try {
407
+ window.localStorage.removeItem(e);
408
+ } catch {
409
+ }
410
+ }
392
411
  };
393
412
  }
394
- function Lt(e, t) {
413
+ function Ft(e, t) {
395
414
  return {
396
415
  read() {
397
416
  try {
@@ -414,134 +433,145 @@ function Lt(e, t) {
414
433
  }
415
434
  };
416
435
  }
417
- const Xe = "cb-sdk-store";
418
- function We(e, t) {
436
+ const Ze = "cb-sdk-store";
437
+ function be(e, t) {
419
438
  if (e.size <= t) return;
420
- const n = [...e.entries()].sort((a, o) => a[1].timestamp - o[1].timestamp).slice(0, e.size - t);
421
- for (const [a] of n)
422
- e.delete(a);
439
+ const a = [...e.entries()].sort((c, n) => c[1].timestamp - n[1].timestamp).slice(0, e.size - t);
440
+ for (const [c] of a)
441
+ e.delete(c);
423
442
  }
424
- function Ze(e) {
425
- typeof requestIdleCallback == "function" ? requestIdleCallback(e, { timeout: qe }) : setTimeout(e, 0);
443
+ function et(e) {
444
+ typeof requestIdleCallback == "function" ? requestIdleCallback(e, { timeout: Be }) : setTimeout(e, 0);
426
445
  }
427
- function et(e = {}) {
446
+ function tt(e = {}) {
428
447
  const {
429
- ttl: t = Ne,
430
- maxEntries: r = Oe,
431
- storageKey: n = Xe,
432
- storageAdapter: a
433
- } = e, o = /* @__PURE__ */ new Map(), s = a ?? ze(n);
448
+ ttl: t = Fe,
449
+ maxEntries: r = De,
450
+ storageKey: a = Ze,
451
+ storageAdapter: c
452
+ } = e, n = /* @__PURE__ */ new Map(), i = c ?? We(a);
434
453
  let u = 0;
435
- function c(i) {
436
- return Date.now() - i > t;
454
+ function s(o) {
455
+ return Date.now() - o > t;
437
456
  }
438
- function l() {
439
- if (!s) return;
440
- const i = ++u;
441
- Ze(() => {
442
- if (i === u)
457
+ function d() {
458
+ if (!i) return;
459
+ const o = ++u;
460
+ et(() => {
461
+ if (o === u)
443
462
  try {
444
- const f = [];
445
- for (const [p, v] of o)
446
- c(v.timestamp) || f.push([p, v]);
463
+ const l = [];
464
+ for (const [p, h] of n)
465
+ s(h.createdAt) || l.push([p, h]);
447
466
  const g = {
448
- queries: f.slice(0, r),
449
- version: oe
467
+ queries: l.slice(0, r),
468
+ version: ce
450
469
  };
451
- s.write(JSON.stringify(g));
470
+ i.write(JSON.stringify(g));
452
471
  } catch {
453
472
  }
454
473
  });
455
474
  }
456
475
  return {
457
- get(i) {
458
- return o.get(i) ?? null;
476
+ get(o) {
477
+ const l = n.get(o);
478
+ return l ? s(l.createdAt) ? (n.delete(o), null) : (l.timestamp = Date.now(), l) : null;
459
479
  },
460
- set(i, f) {
461
- o.set(i, { data: f, timestamp: Date.now() }), We(o, r), l();
480
+ set(o, l) {
481
+ const g = Date.now();
482
+ n.set(o, { data: l, timestamp: g, createdAt: g }), be(n, r), d();
462
483
  },
463
- isExpired(i) {
464
- const f = o.get(i);
465
- return f ? c(f.timestamp) : !0;
484
+ isExpired(o) {
485
+ const l = n.get(o);
486
+ return l ? s(l.createdAt) : !0;
466
487
  },
467
- invalidate(i) {
468
- for (const f of o.keys())
469
- f.includes(i) && o.delete(f);
488
+ invalidate(o) {
489
+ for (const l of n.keys())
490
+ l.includes(o) && n.delete(l);
491
+ d();
470
492
  },
471
493
  persist() {
472
- l();
494
+ d();
473
495
  },
474
496
  restore() {
475
- if (s)
497
+ if (i)
476
498
  try {
477
- const i = s.read();
478
- if (!i) return;
479
- const f = JSON.parse(i);
480
- if (f.version !== oe) {
481
- s.remove();
499
+ const o = i.read();
500
+ if (!o) return;
501
+ const l = JSON.parse(o);
502
+ if (l.version !== ce) {
503
+ i.remove();
482
504
  return;
483
505
  }
484
- if (!Array.isArray(f.queries)) {
485
- s.remove();
506
+ if (!Array.isArray(l.queries)) {
507
+ i.remove();
486
508
  return;
487
509
  }
488
- for (const [g, p] of f.queries)
489
- c(p.timestamp) || o.set(g, p);
510
+ for (const [g, p] of l.queries) {
511
+ const h = p.createdAt ?? p.timestamp;
512
+ s(h) || (p.createdAt ?? (p.createdAt = p.timestamp), n.set(g, p));
513
+ }
514
+ be(n, r);
490
515
  } catch {
491
- s.remove();
516
+ i.remove();
492
517
  }
493
518
  },
494
519
  clear() {
495
- o.clear(), u++, s?.remove();
520
+ n.clear(), u++, i?.remove();
496
521
  },
497
522
  get stats() {
498
- return { entries: o.size };
523
+ return { entries: n.size };
499
524
  }
500
525
  };
501
526
  }
502
- function de({
527
+ function ue(e) {
528
+ return e === null || typeof e != "object" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map(ue).join(",")}]` : `{${Object.keys(e).sort().map(
529
+ (a) => `${JSON.stringify(a)}:${ue(e[a])}`
530
+ ).join(",")}}`;
531
+ }
532
+ function z({
503
533
  prefix: e,
504
534
  id: t,
505
535
  params: r = {}
506
536
  }) {
507
537
  if (!t?.trim()) return;
508
- const n = `${e}/${encodeURIComponent(t)}`, a = Object.entries(r).filter(([o, s]) => s != null && o !== "signal").sort(([o], [s]) => o.localeCompare(s)).map(
509
- ([o, s]) => `${encodeURIComponent(o)}=${encodeURIComponent(typeof s == "object" ? JSON.stringify(s) : String(s))}`
538
+ const a = `${e}/${encodeURIComponent(t)}`, c = Object.entries(r).filter(([n, i]) => i != null && n !== "signal").sort(([n], [i]) => n.localeCompare(i)).map(
539
+ ([n, i]) => `${encodeURIComponent(n)}=${encodeURIComponent(typeof i == "object" ? ue(i) : String(i))}`
510
540
  ).join("&");
511
- return a ? `${n}?${a}` : n;
541
+ return c ? `${a}?${c}` : a;
512
542
  }
513
- function ne() {
514
- return b(ae({ code: "ABORTED", message: "Request aborted" }));
543
+ function se() {
544
+ return y(Q({ code: "ABORTED", message: "Request aborted" }));
515
545
  }
516
- function tt() {
546
+ function rt() {
517
547
  const e = /* @__PURE__ */ new Map();
518
548
  return {
519
549
  async resolve(t) {
520
- const { key: r, cache: n, signal: a, onFetch: o, fn: s } = t;
550
+ const { key: r, cache: a, signal: c, onFetch: n, fn: i } = t;
521
551
  if (!r)
522
- return o?.(), s(a);
523
- const u = n.get(r);
524
- if (u && !n.isExpired(r))
552
+ return n?.(), i(c);
553
+ const u = a.get(r);
554
+ if (u)
525
555
  return { data: u.data };
526
- if (a.aborted) return ne();
527
- const c = e.get(r);
528
- if (c) {
529
- c.consumers++, o?.();
556
+ if (c.aborted) return se();
557
+ const s = e.get(r);
558
+ if (s) {
559
+ s.consumers++, n?.();
530
560
  const p = () => {
531
- c.consumers--, c.consumers <= 0 && (c.controller.abort(), e.delete(r));
561
+ s.consumers--, s.consumers <= 0 && (s.controller.abort(), e.get(r) === s && e.delete(r));
532
562
  };
533
- a.addEventListener("abort", p, { once: !0 });
534
- const v = await c.promise;
535
- return a.removeEventListener("abort", p), a.aborted ? ne() : v;
563
+ c.addEventListener("abort", p, { once: !0 });
564
+ const h = await s.promise;
565
+ return c.removeEventListener("abort", p), c.aborted ? se() : h;
536
566
  }
537
- const l = new AbortController(), i = { promise: null, controller: l, consumers: 1 }, f = () => {
538
- i.consumers--, i.consumers <= 0 && (l.abort(), e.delete(r));
567
+ const d = new AbortController(), o = { promise: null, controller: d, consumers: 1 }, l = () => {
568
+ o.consumers--, o.consumers <= 0 && (d.abort(), e.get(r) === o && e.delete(r));
539
569
  };
540
- a.addEventListener("abort", f, { once: !0 }), o?.(), i.promise = s(l.signal).finally(() => {
541
- e.delete(r);
542
- }), e.set(r, i);
543
- const g = await i.promise;
544
- return a.removeEventListener("abort", f), a.aborted ? ne() : g;
570
+ c.addEventListener("abort", l, { once: !0 }), n?.(), e.set(r, o), o.promise = i(d.signal).finally(() => {
571
+ e.get(r) === o && e.delete(r);
572
+ });
573
+ const g = await o.promise;
574
+ return c.removeEventListener("abort", l), c.aborted ? se() : g;
545
575
  },
546
576
  clear() {
547
577
  for (const t of e.values())
@@ -550,194 +580,214 @@ function tt() {
550
580
  }
551
581
  };
552
582
  }
553
- var se = /* @__PURE__ */ ((e) => (e.Equal = "eq", e.NotEqual = "not_eq", e.In = "in", e.NotIn = "not_in", e.GreaterThan = "gt", e.GreaterThanOrEqual = "gte", e.LessThan = "lt", e.LessThanOrEqual = "lte", e.Exists = "exists", e.NotExists = "not_exists", e))(se || {}), ye = /* @__PURE__ */ ((e) => (e.And = "AND", e.Or = "OR", e))(ye || {});
554
- function Pt(e, t) {
583
+ var le = /* @__PURE__ */ ((e) => (e.Equal = "eq", e.NotEqual = "not_eq", e.In = "in", e.NotIn = "not_in", e.GreaterThan = "gt", e.GreaterThanOrEqual = "gte", e.LessThan = "lt", e.LessThanOrEqual = "lte", e.Exists = "exists", e.NotExists = "not_exists", e))(le || {}), Ae = /* @__PURE__ */ ((e) => (e.And = "AND", e.Or = "OR", e))(Ae || {});
584
+ function Ut(e, t) {
555
585
  return { property: e, operator: "eq", values: [t] };
556
586
  }
557
- function Dt(e, t) {
587
+ function Mt(e, t) {
558
588
  return { property: e, operator: "not_eq", values: [t] };
559
589
  }
560
- function Mt(e, t) {
590
+ function Vt(e, t) {
561
591
  return { property: e, operator: "in", values: t };
562
592
  }
563
- function qt(e, t) {
593
+ function $t(e, t) {
564
594
  return { property: e, operator: "not_in", values: t };
565
595
  }
566
- function Ut(e, t) {
596
+ function Bt(e, t) {
567
597
  return { property: e, operator: "gt", values: [t] };
568
598
  }
569
- function Ft(e, t) {
599
+ function Gt(e, t) {
570
600
  return { property: e, operator: "gte", values: [t] };
571
601
  }
572
- function $t(e, t) {
602
+ function xt(e, t) {
573
603
  return { property: e, operator: "lt", values: [t] };
574
604
  }
575
- function Vt(e, t) {
605
+ function jt(e, t) {
576
606
  return { property: e, operator: "lte", values: [t] };
577
607
  }
578
- function Bt(e) {
608
+ function Ht(e) {
579
609
  return { property: e, operator: "exists", values: [] };
580
610
  }
581
- function xt(e) {
611
+ function Qt(e) {
582
612
  return { property: e, operator: "not_exists", values: [] };
583
613
  }
584
614
  function nt(...e) {
585
615
  return { conditional: "AND", expressions: e };
586
616
  }
587
- function Gt(...e) {
617
+ function Jt(...e) {
588
618
  return { conditional: "OR", expressions: e };
589
619
  }
590
- function rt(e) {
620
+ function at(e) {
591
621
  return "conditional" in e;
592
622
  }
593
- function Ht(e) {
594
- return rt(e) ? e : nt(e);
623
+ function Kt(e) {
624
+ return at(e) ? e : nt(e);
595
625
  }
596
- function Ee(e, t) {
626
+ function Se(e, t) {
597
627
  return `gid://shopify/${e}/${t}`;
598
628
  }
599
629
  function ot(e) {
600
- return Ee("Product", e);
630
+ return Se("Product", e);
601
631
  }
602
- function at(e) {
603
- return Ee("ProductVariant", e);
632
+ function st(e) {
633
+ return Se("ProductVariant", e);
604
634
  }
605
- const he = (e) => encodeURIComponent(e).replace(/-/g, "%2D");
606
- function we({
635
+ const Ee = (e) => encodeURIComponent(e).replace(/-/g, "%2D");
636
+ function Re({
607
637
  type: e,
608
638
  selectedOptions: t
609
639
  }) {
610
640
  if (t.length === 0)
611
641
  return `${e}-`;
612
- const r = t.map(({ name: n, value: a }) => `${he(n)}:${he(a)}`).join("-");
642
+ const r = t.map(({ name: a, value: c }) => `${Ee(a)}:${Ee(c)}`).join("-");
613
643
  return `${e}-${r}`;
614
644
  }
615
- function Ie(e) {
645
+ function Te(e) {
616
646
  return e.product_id ?? e.id;
617
647
  }
618
- function st(e) {
619
- return ot(Ie(e));
648
+ function it(e) {
649
+ return ot(Te(e));
650
+ }
651
+ const pe = "USD", ct = "en-US";
652
+ function G(e, t, r) {
653
+ return { amount: e, currencyCode: t, formatted: r(e, t) };
654
+ }
655
+ const we = /* @__PURE__ */ new Map();
656
+ function he(e, t) {
657
+ let r = we.get(t);
658
+ return r || (r = new Intl.NumberFormat(ct, {
659
+ style: "currency",
660
+ currency: t
661
+ }), we.set(t, r)), r.format(e);
662
+ }
663
+ function ut(e, t, r) {
664
+ const a = e?.["variants.price"];
665
+ if (a)
666
+ return {
667
+ min: G(a.min, t, r),
668
+ max: G(a.max, t, r)
669
+ };
620
670
  }
621
- function it({
671
+ function lt({
622
672
  layers: e,
623
- currencyCode: t = ve,
624
- formatPrice: r = _e,
625
- swatches: n = [],
626
- breakoutContext: a
673
+ currencyCode: t = pe,
674
+ formatPrice: r = he,
675
+ swatches: a = [],
676
+ breakoutContext: c
627
677
  }) {
628
- const o = Ie(e), s = st(e), u = e.title, c = e.handle, l = e.vendor ?? "", i = e.product_type ?? "", f = e.available, g = e.tags, p = ct(e), v = ut(e.price_range, t, r), I = dt(e, n), y = mt(e, t, r), R = y.map((h) => h.compareAtPrice).filter((h) => h !== null), T = R.length > 0 ? {
629
- min: R.reduce((h, A) => h.amount < A.amount ? h : A),
630
- max: R.reduce((h, A) => h.amount > A.amount ? h : A)
631
- } : void 0, N = e.first_or_matched_variant ? ft(e.first_or_matched_variant) : [], w = we({ type: "Product", selectedOptions: N }), k = e.metafields, d = e.calculated, m = e.category ? {
678
+ const n = e.first_or_matched_variant, i = Te(e), u = it(e), s = e.title, d = e.handle, o = e.vendor ?? "", l = e.product_type ?? "", g = e.tags, p = dt(e), h = ft(e, a), w = mt(n), S = Re({ type: "Product", selectedOptions: w }), I = e.metafields, C = e.calculated, O = G(parseFloat(n.price), t, r), b = n.compare_at_price ? G(parseFloat(n.compare_at_price), t, r) : null, T = n.available, f = n.featured_media ? {
679
+ mediaContentType: n.featured_media.media_type ?? null,
680
+ url: n.featured_media.src,
681
+ alt: n.featured_media.alt ?? "",
682
+ width: n.featured_media.width,
683
+ height: n.featured_media.height
684
+ } : null, m = e.category ? {
632
685
  id: e.category.id,
633
686
  name: e.category.name,
634
687
  fullName: e.category.full_name,
635
688
  isLeaf: e.category.is_leaf,
636
689
  isRoot: e.category.is_root
637
- } : null, E = e.featured_media ? {
638
- mediaContentType: e.featured_media.media_type ?? null,
639
- url: e.featured_media.src,
640
- alt: e.featured_media.alt ?? "",
641
- width: e.featured_media.width,
642
- height: e.featured_media.height
643
- } : null, _ = e.first_or_matched_variant ? y.find((h) => h.numericId === e.first_or_matched_variant.id) ?? null : null;
644
- let S = [], C = null;
645
- if (a?.isVariantTile) {
646
- C = a.variantId;
647
- const h = y.find((A) => A.numericId === C);
648
- if (h) {
649
- const A = new Set(a.optionCodes);
650
- S = h.selectedOptions.filter((V) => A.has(V.name));
651
- }
690
+ } : null;
691
+ let v, E;
692
+ if (e.variants?.length)
693
+ v = gt(e, t, r), E = v.find((_) => _.numericId === n.id) ?? null;
694
+ else {
695
+ const _ = Ce(n, t, r);
696
+ v = [_], E = _;
652
697
  }
698
+ let R = [], N = null;
699
+ if (c?.isVariantTile)
700
+ if (N = c.variantId, e.variants?.length) {
701
+ const _ = v.find((A) => A.numericId === N);
702
+ if (_) {
703
+ const A = new Set(c.optionCodes);
704
+ R = _.selectedOptions.filter((ee) => A.has(ee.name));
705
+ }
706
+ } else {
707
+ const _ = new Set(c.optionCodes);
708
+ R = w.filter((A) => _.has(A.name));
709
+ }
653
710
  return {
654
- id: w,
655
- gid: s,
656
- numericId: o,
657
- title: u,
658
- handle: c,
659
- type: i,
660
- vendor: l,
661
- availableForSale: f,
711
+ id: S,
712
+ gid: u,
713
+ numericId: i,
714
+ title: s,
715
+ handle: d,
716
+ type: l,
717
+ vendor: o,
718
+ availableForSale: T,
662
719
  images: p,
663
- priceRange: v,
664
- compareAtPriceRange: T,
665
- options: I,
720
+ price: O,
721
+ compareAtPrice: b,
722
+ options: h,
666
723
  tags: g,
667
- variants: y,
668
- selectedOptions: N,
669
- metafields: k,
670
- calculated: d,
724
+ variants: v,
725
+ selectedOptions: w,
726
+ metafields: I,
727
+ calculated: C,
671
728
  category: m,
672
- featuredMedia: E,
729
+ featuredMedia: f,
673
730
  combinedListingParentProductId: e.combined_listing_parent_product_id,
674
731
  combinedListingRole: e.combined_listing_role,
675
- selectedVariant: _,
676
- breakoutOptions: S,
677
- breakoutVariantId: C
732
+ selectedVariant: E,
733
+ breakoutOptions: R,
734
+ breakoutVariantId: N
678
735
  };
679
736
  }
680
- function ct(e) {
681
- return e.images.map((t, r) => ({
682
- url: t.src,
683
- alt: t.alt ?? "",
684
- width: t.width,
685
- height: t.height,
686
- position: t.position ?? r,
687
- variantIds: t.variant_ids ?? []
688
- }));
689
- }
690
- function ut(e, t, r) {
691
- const n = e.from, a = e.to;
692
- return {
693
- min: { amount: n, currencyCode: t, formatted: r(n, t) },
694
- max: { amount: a, currencyCode: t, formatted: r(a, t) }
695
- };
737
+ function dt(e) {
738
+ if (e.images?.length)
739
+ return e.images.map((r, a) => ({
740
+ url: r.src,
741
+ alt: r.alt ?? "",
742
+ width: r.width,
743
+ height: r.height,
744
+ position: r.position ?? a,
745
+ variantIds: r.variant_ids ?? []
746
+ }));
747
+ const t = e.first_or_matched_variant.featured_media;
748
+ return t ? [
749
+ {
750
+ url: t.src,
751
+ alt: t.alt ?? "",
752
+ width: t.width,
753
+ height: t.height,
754
+ position: 0,
755
+ variantIds: []
756
+ }
757
+ ] : [];
696
758
  }
697
- function lt(e) {
698
- if (e.length === 0) return;
699
- const t = /* @__PURE__ */ new Map();
700
- for (const r of e)
701
- for (const n of r.values)
702
- n.swatch && (!n.swatch.color && !n.swatch.image || t.set(`${r.name}:${n.value}`, {
703
- name: r.name,
704
- value: n.value,
705
- color: n.swatch.color,
706
- imageUrl: n.swatch.image?.url ?? null
707
- }));
708
- return t.size > 0 ? t : void 0;
709
- }
710
- function dt(e, t) {
711
- const r = [], n = e.options, a = lt(e.options_v2);
712
- for (const [o, s] of Object.entries(n))
713
- for (const u of s) {
714
- const c = a?.get(`${o}:${u}`) ?? t.find((l) => l.name === o && l.value === u);
715
- r.push({ name: o, value: u, swatch: c });
759
+ function ft(e, t) {
760
+ const r = [];
761
+ for (const a of e.options_v2)
762
+ for (const c of a.values) {
763
+ const n = c.swatch, u = n && (n.color || n.image) ? {
764
+ name: a.name,
765
+ value: c.value,
766
+ color: n.color,
767
+ imageUrl: n.image?.url ?? null
768
+ } : t.find((s) => s.name === a.name && s.value === c.value);
769
+ r.push({ name: a.name, code: a.code, value: c.value, swatch: u });
716
770
  }
717
771
  return r;
718
772
  }
719
- function ft(e) {
773
+ function mt(e) {
720
774
  return e.selected_options.map((t) => ({ name: t.name, value: t.value }));
721
775
  }
722
- function mt(e, t, r) {
723
- return e.variants.map((n) => gt(n, t, r));
724
- }
725
776
  function gt(e, t, r) {
726
- const n = parseFloat(e.price), a = e.compare_at_price ? parseFloat(e.compare_at_price) : null;
777
+ return (e.variants ?? []).map((a) => Ce(a, t, r));
778
+ }
779
+ function Ce(e, t, r) {
780
+ const a = parseFloat(e.price), c = e.compare_at_price ? parseFloat(e.compare_at_price) : null;
727
781
  return {
728
- id: we({ type: "ProductVariant", selectedOptions: e.selected_options }),
729
- gid: at(e.id),
782
+ id: Re({ type: "ProductVariant", selectedOptions: e.selected_options }),
783
+ gid: st(e.id),
730
784
  numericId: e.id,
731
785
  title: e.title,
732
786
  availableForSale: e.available,
733
787
  sku: e.sku,
734
788
  position: e.position,
735
- price: { amount: n, currencyCode: t, formatted: r(n, t) },
736
- compareAtPrice: a != null ? {
737
- amount: a,
738
- currencyCode: t,
739
- formatted: r(a, t)
740
- } : null,
789
+ price: G(a, t, r),
790
+ compareAtPrice: c != null ? G(c, t, r) : null,
741
791
  image: e.featured_media ? {
742
792
  url: e.featured_media.src,
743
793
  alt: e.featured_media.alt ?? "",
@@ -746,7 +796,7 @@ function gt(e, t, r) {
746
796
  position: 0,
747
797
  variantIds: [e.id]
748
798
  } : null,
749
- selectedOptions: e.selected_options.map((o) => ({ name: o.name, value: o.value })),
799
+ selectedOptions: e.selected_options.map((n) => ({ name: n.name, value: n.value })),
750
800
  inventoryLevels: e.inventory_levels ?? {},
751
801
  inventoryPolicy: e.inventory_policy ?? null,
752
802
  inStockLocationIds: e.in_stock_location_ids ?? [],
@@ -754,7 +804,35 @@ function gt(e, t, r) {
754
804
  hasSellingPlan: e.has_selling_plan ?? !1
755
805
  };
756
806
  }
757
- function G({
807
+ function W({
808
+ results: e,
809
+ meta: t,
810
+ currencyCode: r = pe,
811
+ formatPrice: a = he,
812
+ swatches: c,
813
+ extender: n
814
+ }) {
815
+ const i = t?.variantBreakouts?.map((u) => u.optionCode) ?? [];
816
+ return e.map((u) => {
817
+ const s = pt(u, i), d = lt({
818
+ layers: u,
819
+ currencyCode: r,
820
+ formatPrice: a,
821
+ swatches: c,
822
+ breakoutContext: s
823
+ });
824
+ return n ? { ...d, ...n({ base: d, raw: u }) } : d;
825
+ });
826
+ }
827
+ function pt(e, t) {
828
+ if (!(e.__typename !== "Variant" || t.length === 0))
829
+ return {
830
+ isVariantTile: !0,
831
+ variantId: e.variant_id,
832
+ optionCodes: t
833
+ };
834
+ }
835
+ function x({
758
836
  state: e,
759
837
  isFetching: t = !0
760
838
  }) {
@@ -766,69 +844,69 @@ function D({
766
844
  }) {
767
845
  return { data: e, error: null, isFetching: t };
768
846
  }
769
- function M({
847
+ function P({
770
848
  error: e,
771
849
  data: t = null,
772
850
  isFetching: r = !1
773
851
  }) {
774
852
  return { data: t, error: e, isFetching: r };
775
853
  }
776
- const fe = "__COMMERCE_BLOCKS__", me = typeof window < "u" && typeof window.document < "u";
777
- function pt(e) {
778
- me && (window[fe] = e);
854
+ const ye = "__COMMERCE_BLOCKS__", ve = typeof window < "u" && typeof window.document < "u";
855
+ function ht(e) {
856
+ ve && (window[ye] = e);
779
857
  }
780
- function jt() {
781
- if (!me)
782
- return b(
783
- Q({
858
+ function Xt() {
859
+ if (!ve)
860
+ return y(
861
+ H({
784
862
  code: "INVALID_CONFIG",
785
863
  message: "Client only available in browser",
786
864
  field: "environment",
787
865
  expected: "browser"
788
866
  })
789
867
  );
790
- const e = window[fe];
791
- return e ? L(e) : b(
792
- Q({
868
+ const e = window[ye];
869
+ return e ? k(e) : y(
870
+ H({
793
871
  code: "MISSING_CONFIG",
794
872
  message: "Client not initialized. Call createClient() first.",
795
873
  field: "client"
796
874
  })
797
875
  );
798
876
  }
799
- function Qt() {
800
- return me && !!window[fe];
877
+ function Yt() {
878
+ return ve && !!window[ye];
801
879
  }
802
880
  function Y(e) {
803
881
  let t = null;
804
882
  return {
805
883
  next(r) {
806
- return t?.abort(), t = ge(r, e), t.signal;
884
+ return t?.abort(), t = _e(r, e), t.signal;
807
885
  },
808
886
  abort() {
809
887
  t?.abort();
810
888
  }
811
889
  };
812
890
  }
813
- function ge(...e) {
891
+ function _e(...e) {
814
892
  const t = new AbortController(), r = [];
815
- for (const n of e) {
816
- if (!n) continue;
817
- if (n.aborted) {
818
- t.abort(n.reason);
893
+ for (const a of e) {
894
+ if (!a) continue;
895
+ if (a.aborted) {
896
+ t.abort(a.reason);
819
897
  break;
820
898
  }
821
- const a = () => t.abort(n.reason);
822
- n.addEventListener("abort", a, { once: !0 }), r.push(() => n.removeEventListener("abort", a));
899
+ const c = () => t.abort(a.reason);
900
+ a.addEventListener("abort", c, { once: !0 }), r.push(() => a.removeEventListener("abort", c));
823
901
  }
824
- return r.length && t.signal.addEventListener("abort", () => r.forEach((n) => n()), {
902
+ return r.length && t.signal.addEventListener("abort", () => r.forEach((a) => a()), {
825
903
  once: !0
826
904
  }), t;
827
905
  }
828
- function $(e, t) {
829
- return re(() => t(e.value));
906
+ function V(e, t) {
907
+ return ie(() => t(e.value));
830
908
  }
831
- function q() {
909
+ function F() {
832
910
  const e = /* @__PURE__ */ new Set();
833
911
  return {
834
912
  add(t) {
@@ -841,14 +919,14 @@ function q() {
841
919
  }
842
920
  };
843
921
  }
844
- function z({
922
+ function Z({
845
923
  products: e,
846
924
  raw: t,
847
925
  extender: r,
848
- currencyCode: n = ve,
849
- formatPrice: a = _e
926
+ currencyCode: a = pe,
927
+ formatPrice: c = he
850
928
  }) {
851
- const o = {
929
+ const n = {
852
930
  products: e,
853
931
  totalResults: t.totalResults,
854
932
  totalPages: t.totalPages,
@@ -856,149 +934,147 @@ function z({
856
934
  resultsPerPage: t.resultsPerPage,
857
935
  facets: t.facets ?? {},
858
936
  facetRanges: t.facetRanges,
859
- priceRange: ht(t.facetRanges, n, a),
937
+ priceRange: ut(t.facetRanges, a, c),
860
938
  attributionToken: t.attributionToken,
861
939
  _workflow: t._workflow
862
940
  };
863
- return r ? r(o, t) : o;
864
- }
865
- function ht(e, t, r) {
866
- const n = e?.["variants.price"];
867
- if (n)
868
- return {
869
- min: { amount: n.min, currencyCode: t, formatted: r(n.min, t) },
870
- max: { amount: n.max, currencyCode: t, formatted: r(n.max, t) }
871
- };
872
- }
873
- function vt(e, t) {
874
- if (!(e.__typename !== "Variant" || t.length === 0))
875
- return {
876
- isVariantTile: !0,
877
- variantId: e.variant_id,
878
- optionCodes: t
879
- };
880
- }
881
- function X(e, { results: t, meta: r }) {
882
- const n = r?.variantBreakouts?.map((a) => a.optionCode) ?? [];
883
- return t.map((a) => {
884
- const o = vt(a, n), s = it({
885
- layers: a,
886
- currencyCode: e.config.currency,
887
- formatPrice: e.config.formatPrice,
888
- swatches: e.config.swatches,
889
- breakoutContext: o
890
- });
891
- return e.config.transforms?.product ? { ...s, ...e.config.transforms.product({ base: s, raw: a }) } : s;
892
- });
941
+ return r ? r(n, t) : n;
893
942
  }
894
- function H(e, t) {
943
+ function J(e, t) {
895
944
  if (t) {
896
945
  if (e.config.transforms?.filters)
897
946
  return e.config.transforms.filters(t);
947
+ if (typeof t == "object" && !Array.isArray(t) && "conditional" in t && "expressions" in t)
948
+ return t;
898
949
  if (e.config.filterAliases && typeof t == "object" && !Array.isArray(t)) {
899
- const r = t, n = [];
900
- for (const [a, o] of Object.entries(r)) {
901
- if (o == null) continue;
902
- const s = e.config.filterAliases[a], u = typeof s == "string" ? s : s?.property ?? a, c = typeof s == "object" ? s.values : void 0, i = (Array.isArray(o) ? o : [o]).map((f) => {
903
- const g = String(f);
904
- return c?.[g] ?? g;
950
+ const r = t, a = [];
951
+ for (const [c, n] of Object.entries(r)) {
952
+ if (n == null) continue;
953
+ const i = e.config.filterAliases[c], u = typeof i == "string" ? i : i?.property ?? c, s = typeof i == "object" ? i.values : void 0, o = (Array.isArray(n) ? n : [n]).map((l) => {
954
+ const g = s?.[String(l)];
955
+ return g !== void 0 ? g : l;
905
956
  });
906
- n.push({
957
+ a.push({
907
958
  property: u,
908
- operator: i.length > 1 ? se.In : se.Equal,
909
- values: i
959
+ operator: o.length > 1 ? le.In : le.Equal,
960
+ values: o
910
961
  });
911
962
  }
912
- return n.length === 0 ? void 0 : {
913
- conditional: ye.And,
914
- expressions: n
963
+ return a.length === 0 ? void 0 : {
964
+ conditional: Ae.And,
965
+ expressions: a
915
966
  };
916
967
  }
917
968
  return t;
918
969
  }
919
970
  }
920
- function _t({ ctx: e }) {
971
+ function yt({ ctx: e }) {
921
972
  return ({ handle: t, defaultSort: r }) => {
922
- const n = P({
973
+ const a = q({
923
974
  data: null,
924
975
  error: null,
925
976
  isFetching: !1
926
- }), a = Y();
927
- let o = r ?? e.config.sorts[0]?.code;
928
- const s = q();
977
+ }), c = Y();
978
+ let n = r ?? e.config.sorts[0]?.code, i = 0;
979
+ const u = F();
929
980
  return {
930
- state: n,
931
- async execute(u = {}) {
981
+ state: a,
982
+ async execute(s = {}) {
932
983
  const {
933
- page: c = K,
934
- limit: l = J,
935
- filters: i,
936
- sort: f,
937
- signal: g,
938
- includeMeta: p = e.config.includeMeta ?? !1,
939
- linking: v,
940
- transformRequest: I
941
- } = u, y = f ?? o;
942
- o = y;
943
- const R = a.next(g), T = de({
984
+ page: d = K,
985
+ limit: o = X,
986
+ filters: l,
987
+ sort: g,
988
+ signal: p,
989
+ includeMeta: h = e.config.includeMeta ?? !1,
990
+ linking: w,
991
+ transformRequest: S
992
+ } = s, I = g ?? n;
993
+ n = I;
994
+ const C = ++i, O = c.next(p), b = z({
944
995
  prefix: "/browse",
945
996
  id: t,
946
- params: { sort: y, page: c, limit: l, filters: i }
947
- }), { data: N, error: w } = await e.coordinator.resolve({
948
- key: T,
997
+ params: { sort: I, page: d, limit: o, filters: l, linking: w }
998
+ }), { data: T, error: f } = await e.coordinator.resolve({
999
+ key: b,
949
1000
  cache: e.cache,
950
- signal: R,
1001
+ signal: O,
951
1002
  onFetch: () => {
952
- n.value = G({ state: n.value });
1003
+ a.value = x({ state: a.value });
953
1004
  },
954
- fn: async (k) => {
955
- const { data: d, error: m } = await e.layers.browse(
1005
+ fn: async (m) => {
1006
+ const { data: v, error: E } = await e.layers.browse(
956
1007
  {
957
1008
  collectionHandle: t,
958
- sort_order_code: y,
959
- pagination: { page: c, limit: l },
960
- filter_group: H(e, i),
961
- dynamicLinking: v,
962
- transformBody: I
1009
+ sort_order_code: I,
1010
+ pagination: { page: d, limit: o },
1011
+ filter_group: J(e, l),
1012
+ dynamicLinking: w,
1013
+ transformBody: S
963
1014
  },
964
- k
1015
+ m
965
1016
  );
966
- if (m) return b(m);
967
- const { results: E, _meta: _ } = d, S = X(e, { results: E, meta: _ }), C = z({
968
- products: S,
969
- raw: d,
1017
+ if (E) return y(E);
1018
+ const { results: R, _meta: N } = v, _ = W({
1019
+ results: R,
1020
+ meta: N,
1021
+ currencyCode: e.config.currency,
1022
+ formatPrice: e.config.formatPrice,
1023
+ swatches: e.config.swatches,
1024
+ extender: e.config.transforms?.product
1025
+ }), A = Z({
1026
+ products: _,
1027
+ raw: v,
970
1028
  extender: e.config.transforms?.collection,
971
1029
  currencyCode: e.config.currency,
972
1030
  formatPrice: e.config.formatPrice
973
1031
  });
974
- return p && d._meta && (C._meta = d._meta), T && e.cache.set(T, C), L(C);
1032
+ return h && v._meta && (A._meta = v._meta), b && e.cache.set(b, A), k(A);
975
1033
  }
976
1034
  });
977
- return w ? (n.value = M({ error: w, data: n.value.data }), b(w)) : (n.value = D({ data: N }), L(N));
1035
+ return C !== i ? f ? y(f) : k(T) : f ? (a.value = P({ error: f, data: a.value.data }), y(f)) : (a.value = D({ data: T }), k(T));
978
1036
  },
979
- subscribe(u) {
980
- return s.add($(n, u));
1037
+ subscribe(s) {
1038
+ return u.add(V(a, s));
981
1039
  },
982
1040
  dispose() {
983
- s.clear(), a.abort();
1041
+ u.clear(), c.abort();
984
1042
  }
985
1043
  };
986
1044
  };
987
1045
  }
988
- async function bt(e, { maxRetries: t = 3, defaultDelayMs: r = 1e3 } = {}) {
1046
+ function vt(e, t) {
1047
+ return t?.aborted ? Promise.resolve() : new Promise((r) => {
1048
+ const a = setTimeout(r, e);
1049
+ t?.addEventListener(
1050
+ "abort",
1051
+ () => {
1052
+ clearTimeout(a), r();
1053
+ },
1054
+ { once: !0 }
1055
+ );
1056
+ });
1057
+ }
1058
+ async function _t(e, { maxRetries: t = 3, defaultDelayMs: r = 1e3, signal: a, shouldRetry: c }) {
989
1059
  let n = await e();
990
- for (let a = 0; a < t && n.error && Ve(n.error); a++)
991
- await new Promise((o) => setTimeout(o, Be(n.error) ?? r)), n = await e();
1060
+ for (let i = 0; i < t && n.error && !(!c(n.error) || a?.aborted); i++) {
1061
+ const u = "retryAfterMs" in n.error ? n.error.retryAfterMs ?? r : r;
1062
+ if (await vt(u, a), a?.aborted) break;
1063
+ n = await e();
1064
+ }
992
1065
  return n;
993
1066
  }
994
- function yt({ ctx: e }) {
1067
+ function bt(e) {
1068
+ return e._tag === "ApiError" && e.status === 425;
1069
+ }
1070
+ function Et({ ctx: e }) {
995
1071
  return (t = {}) => {
996
- const r = P({
1072
+ const r = q({
997
1073
  data: null,
998
1074
  error: null,
999
1075
  isFetching: !1
1000
1076
  });
1001
- let n = {
1077
+ let a = {
1002
1078
  query: t.query,
1003
1079
  page: t.page,
1004
1080
  limit: t.limit,
@@ -1007,191 +1083,212 @@ function yt({ ctx: e }) {
1007
1083
  linking: t.linking,
1008
1084
  transformRequest: t.transformRequest
1009
1085
  };
1010
- const a = Y(t.signal);
1011
- let o;
1012
- const s = q();
1013
- function u(c = {}) {
1014
- const l = { ...n, ...c };
1015
- return c.temporary || (n = l), l;
1086
+ const c = Y(t.signal);
1087
+ let n, i = 0;
1088
+ const u = F();
1089
+ function s(d = {}) {
1090
+ const { signal: o, searchId: l, temporary: g, ...p } = d, h = { ...a, ...p };
1091
+ return g || (a = h), { ...h, signal: o, searchId: l };
1016
1092
  }
1017
1093
  return {
1018
1094
  state: r,
1019
- async prepare(c = {}) {
1020
- const l = u(c), { query: i, filters: f, tuning: g, linking: p, transformRequest: v } = l;
1021
- if (!i)
1022
- return b(
1023
- x({
1095
+ async prepare(d = {}) {
1096
+ const o = s(d), { query: l, filters: g, tuning: p, linking: h, transformRequest: w } = o;
1097
+ if (!l)
1098
+ return y(
1099
+ B({
1024
1100
  operation: "search.prepare",
1025
- fields: [F("query", "REQUIRED_FIELD", "query is required")]
1101
+ fields: [M("query", "REQUIRED_FIELD", "query is required")]
1026
1102
  })
1027
1103
  );
1028
- const I = H(e, f), y = await e.layers.prepareSearch(
1104
+ const S = J(e, g), I = await e.layers.prepareSearch(
1029
1105
  {
1030
- query: i,
1031
- filter_group: I,
1032
- tuning: g,
1033
- dynamicLinking: p,
1034
- transformBody: v
1106
+ query: l,
1107
+ filter_group: S,
1108
+ tuning: p,
1109
+ dynamicLinking: h,
1110
+ transformBody: w
1035
1111
  },
1036
- c.signal
1112
+ d.signal
1037
1113
  );
1038
- return y.error ? b(y.error) : (o = y.data.search_id, L({ searchId: y.data.search_id }));
1114
+ return I.error ? y(I.error) : (n = I.data.search_id, k({ searchId: I.data.search_id }));
1039
1115
  },
1040
- async execute(c = {}) {
1041
- const l = u(c), {
1042
- query: i,
1043
- page: f = K,
1044
- limit: g = J,
1045
- filters: p,
1046
- tuning: v,
1047
- linking: I,
1048
- transformRequest: y
1049
- } = l;
1050
- if (!i) {
1051
- const E = x({
1116
+ async execute(d = {}) {
1117
+ const o = s(d), {
1118
+ query: l,
1119
+ page: g = K,
1120
+ limit: p = X,
1121
+ filters: h,
1122
+ tuning: w,
1123
+ linking: S,
1124
+ transformRequest: I
1125
+ } = o;
1126
+ if (!l) {
1127
+ const R = B({
1052
1128
  operation: "search.execute",
1053
- fields: [F("query", "REQUIRED_FIELD", "query is required")]
1129
+ fields: [M("query", "REQUIRED_FIELD", "query is required")]
1054
1130
  });
1055
- return r.value = M({ error: E, data: r.value.data }), b(E);
1131
+ return r.value = P({ error: R, data: r.value.data }), y(R);
1056
1132
  }
1057
- const R = c.searchId, T = H(e, p), N = a.next(c.signal), w = R ?? o;
1058
- o = void 0;
1059
- const k = de({
1133
+ const C = d.searchId, O = J(e, h), b = ++i, T = c.next(d.signal), f = C ?? n;
1134
+ n = void 0;
1135
+ const m = z({
1060
1136
  prefix: "/search",
1061
- id: i,
1062
- params: { page: f, limit: g, filters: p }
1063
- }), { data: d, error: m } = await e.coordinator.resolve({
1064
- key: k,
1137
+ id: l,
1138
+ params: { page: g, limit: p, filters: h, tuning: w, linking: S }
1139
+ }), { data: v, error: E } = await e.coordinator.resolve({
1140
+ key: m,
1065
1141
  cache: e.cache,
1066
- signal: N,
1142
+ signal: T,
1067
1143
  onFetch: () => {
1068
- r.value = G({ state: r.value });
1144
+ r.value = x({ state: r.value });
1069
1145
  },
1070
- fn: async (E) => {
1071
- let _ = w;
1072
- if (!_) {
1073
- const W = await e.layers.prepareSearch(
1146
+ fn: async (R) => {
1147
+ let N = f;
1148
+ if (!N) {
1149
+ const re = await e.layers.prepareSearch(
1074
1150
  {
1075
- query: i,
1076
- filter_group: T,
1077
- tuning: v,
1078
- dynamicLinking: I,
1079
- transformBody: y
1151
+ query: l,
1152
+ filter_group: O,
1153
+ tuning: w,
1154
+ dynamicLinking: S,
1155
+ transformBody: I
1080
1156
  },
1081
- E
1157
+ R
1082
1158
  );
1083
- if (W.error) return b(W.error);
1084
- _ = W.data.search_id;
1159
+ if (re.error) return y(re.error);
1160
+ N = re.data.search_id;
1085
1161
  }
1086
- const S = await bt(
1162
+ const _ = await _t(
1087
1163
  () => e.layers.search(
1088
1164
  {
1089
- query: i,
1090
- search_id: _,
1091
- pagination: { page: f, limit: g },
1092
- filter_group: T,
1093
- tuning: v,
1094
- dynamicLinking: I,
1095
- transformBody: y
1165
+ query: l,
1166
+ search_id: N,
1167
+ pagination: { page: g, limit: p },
1168
+ filter_group: O,
1169
+ tuning: w,
1170
+ dynamicLinking: S,
1171
+ transformBody: I
1096
1172
  },
1097
- E
1173
+ R
1098
1174
  ),
1099
- { maxRetries: Ce, defaultDelayMs: Le }
1175
+ {
1176
+ maxRetries: Ue,
1177
+ defaultDelayMs: Me,
1178
+ signal: R,
1179
+ shouldRetry: bt
1180
+ }
1100
1181
  );
1101
- if (S.error) return b(S.error);
1102
- const { results: C, _meta: h } = S.data, A = X(e, { results: C, meta: h }), V = z({
1103
- products: A,
1104
- raw: S.data,
1182
+ if (_.error) return y(_.error);
1183
+ const { results: A, _meta: ee } = _.data, ke = W({
1184
+ results: A,
1185
+ meta: ee,
1186
+ currencyCode: e.config.currency,
1187
+ formatPrice: e.config.formatPrice,
1188
+ swatches: e.config.swatches,
1189
+ extender: e.config.transforms?.product
1190
+ }), te = Z({
1191
+ products: ke,
1192
+ raw: _.data,
1105
1193
  extender: e.config.transforms?.search,
1106
1194
  currencyCode: e.config.currency,
1107
1195
  formatPrice: e.config.formatPrice
1108
1196
  });
1109
- return e.config.includeMeta && S.data._meta && (V._meta = S.data._meta), k && e.cache.set(k, V), L(V);
1197
+ return e.config.includeMeta && _.data._meta && (te._meta = _.data._meta), m && e.cache.set(m, te), k(te);
1110
1198
  }
1111
1199
  });
1112
- return m ? (r.value = M({ error: m, data: r.value.data }), b(m)) : (r.value = D({ data: d }), L(d));
1200
+ return b !== i ? E ? y(E) : k(v) : E ? (r.value = P({ error: E, data: r.value.data }), y(E)) : (r.value = D({ data: v }), k(v));
1113
1201
  },
1114
- subscribe(c) {
1115
- return s.add($(r, c));
1202
+ subscribe(d) {
1203
+ return u.add(V(r, d));
1116
1204
  },
1117
1205
  dispose() {
1118
- s.clear(), a.abort();
1206
+ u.clear(), c.abort();
1119
1207
  }
1120
1208
  };
1121
1209
  };
1122
1210
  }
1123
- function Et({ ctx: e }) {
1211
+ function wt({ ctx: e }) {
1124
1212
  return ({ blockId: t, anchor: r }) => {
1125
- const n = P({
1213
+ const a = q({
1126
1214
  data: null,
1127
1215
  error: null,
1128
1216
  isFetching: !1
1129
- }), a = Y(), o = q();
1217
+ }), c = Y();
1218
+ let n = 0;
1219
+ const i = F();
1130
1220
  return {
1131
- state: n,
1132
- async execute(s = {}) {
1221
+ state: a,
1222
+ async execute(u = {}) {
1133
1223
  const {
1134
- page: u = K,
1135
- limit: c = J,
1136
- filters: l,
1137
- signal: i,
1138
- discounts: f,
1139
- context: g,
1140
- linking: p,
1141
- transformRequest: v
1142
- } = s, I = a.next(i), y = de({
1224
+ page: s = K,
1225
+ limit: d = X,
1226
+ filters: o,
1227
+ signal: l,
1228
+ discounts: g,
1229
+ context: p,
1230
+ linking: h,
1231
+ transformRequest: w
1232
+ } = u, S = ++n, I = c.next(l), C = z({
1143
1233
  prefix: "/blocks",
1144
1234
  id: t,
1145
- params: { anchor: r, page: u, limit: c, filters: l }
1146
- }), { data: R, error: T } = await e.coordinator.resolve({
1147
- key: y,
1235
+ params: { anchor: r, page: s, limit: d, filters: o, discounts: g, context: p, linking: h }
1236
+ }), { data: O, error: b } = await e.coordinator.resolve({
1237
+ key: C,
1148
1238
  cache: e.cache,
1149
1239
  signal: I,
1150
1240
  onFetch: () => {
1151
- n.value = G({ state: n.value });
1241
+ a.value = x({ state: a.value });
1152
1242
  },
1153
- fn: async (N) => {
1154
- const { data: w, error: k } = await e.layers.blocks(
1243
+ fn: async (T) => {
1244
+ const { data: f, error: m } = await e.layers.blocks(
1155
1245
  {
1156
1246
  blockId: t,
1157
1247
  anchor_id: r,
1158
- pagination: { page: u, limit: c },
1159
- filter_group: H(e, l),
1160
- discountEntitlements: f,
1161
- context: g,
1162
- dynamicLinking: p,
1163
- transformBody: v
1248
+ pagination: { page: s, limit: d },
1249
+ filter_group: J(e, o),
1250
+ discountEntitlements: g,
1251
+ context: p,
1252
+ dynamicLinking: h,
1253
+ transformBody: w
1164
1254
  },
1165
- N
1255
+ T
1166
1256
  );
1167
- if (k) return b(k);
1168
- const { results: d, _meta: m } = w, E = X(e, { results: d, meta: m }), _ = z({
1169
- products: E,
1170
- raw: w,
1257
+ if (m) return y(m);
1258
+ const { results: v, _meta: E } = f, R = W({
1259
+ results: v,
1260
+ meta: E,
1261
+ currencyCode: e.config.currency,
1262
+ formatPrice: e.config.formatPrice,
1263
+ swatches: e.config.swatches,
1264
+ extender: e.config.transforms?.product
1265
+ }), N = Z({
1266
+ products: R,
1267
+ raw: f,
1171
1268
  extender: e.config.transforms?.block,
1172
1269
  currencyCode: e.config.currency,
1173
1270
  formatPrice: e.config.formatPrice
1174
1271
  });
1175
- return e.config.includeMeta && w._meta && (_._meta = w._meta), w.block && (_.block = w.block), y && e.cache.set(y, _), L(_);
1272
+ return e.config.includeMeta && f._meta && (N._meta = f._meta), f.block && (N.block = f.block), C && e.cache.set(C, N), k(N);
1176
1273
  }
1177
1274
  });
1178
- return T ? (n.value = M({ error: T, data: n.value.data }), b(T)) : (n.value = D({ data: R }), L(R));
1275
+ return S !== n ? b ? y(b) : k(O) : b ? (a.value = P({ error: b, data: a.value.data }), y(b)) : (a.value = D({ data: O }), k(O));
1179
1276
  },
1180
- subscribe(s) {
1181
- return o.add($(n, s));
1277
+ subscribe(u) {
1278
+ return i.add(V(a, u));
1182
1279
  },
1183
1280
  dispose() {
1184
- o.clear(), a.abort();
1281
+ i.clear(), c.abort();
1185
1282
  }
1186
1283
  };
1187
1284
  };
1188
1285
  }
1189
- function wt(e, t) {
1286
+ function It(e, t) {
1190
1287
  let r = null;
1191
1288
  return {
1192
- call(...n) {
1289
+ call(...a) {
1193
1290
  r && clearTimeout(r), r = setTimeout(() => {
1194
- r = null, e(...n);
1291
+ r = null, e(...a);
1195
1292
  }, t);
1196
1293
  },
1197
1294
  cancel() {
@@ -1199,145 +1296,257 @@ function wt(e, t) {
1199
1296
  }
1200
1297
  };
1201
1298
  }
1202
- function It(e, t) {
1203
- const r = new Set(t.map((n) => n.toLowerCase()));
1204
- return e.filter((n) => !r.has(n.toLowerCase()));
1299
+ function At(e, t) {
1300
+ const r = new Set(t.map((a) => a.toLowerCase()));
1301
+ return e.filter((a) => !r.has(a.toLowerCase()));
1205
1302
  }
1206
- function At({ ctx: e }) {
1303
+ function St({ ctx: e }) {
1207
1304
  return (t = {}) => {
1208
1305
  const {
1209
- debounce: r = Pe,
1210
- excludeInputQuery: n = !1,
1211
- excludeQueries: a,
1212
- signal: o
1213
- } = t, s = P({
1306
+ debounce: r = Ve,
1307
+ excludeInputQuery: a = !1,
1308
+ excludeQueries: c,
1309
+ signal: n
1310
+ } = t, i = q({
1214
1311
  data: null,
1215
1312
  error: null,
1216
1313
  isFetching: !1
1217
- }), u = Y(o);
1218
- let c = 0;
1219
- const l = /* @__PURE__ */ new Map(), i = q();
1220
- function f() {
1221
- i.clear(), g.cancel(), u.abort(), l.clear(), o?.removeEventListener("abort", f);
1314
+ }), u = Y(n);
1315
+ let s = 0;
1316
+ const d = /* @__PURE__ */ new Map(), o = F();
1317
+ function l() {
1318
+ o.clear(), g.cancel(), u.abort(), d.clear(), n?.removeEventListener("abort", l);
1222
1319
  }
1223
- o?.addEventListener("abort", f, { once: !0 });
1224
- const g = wt(async (v) => {
1225
- const I = v.trim();
1226
- if (!I) {
1227
- s.value = { data: null, error: null, isFetching: !1 };
1320
+ n?.addEventListener("abort", l, { once: !0 });
1321
+ const g = It(async (h) => {
1322
+ const w = h.trim();
1323
+ if (!w) {
1324
+ i.value = { data: null, error: null, isFetching: !1 };
1228
1325
  return;
1229
1326
  }
1230
- const y = I.toLowerCase(), R = l.get(y);
1231
- if (R) {
1232
- s.value = D({ data: R });
1327
+ const S = w.toLowerCase(), I = d.get(S);
1328
+ if (I) {
1329
+ i.value = D({ data: I });
1233
1330
  return;
1234
1331
  }
1235
- const T = u.next(), N = ++c;
1236
- s.value = G({ state: s.value });
1237
- const w = await e.layers.predictiveSearch(I, T);
1238
- if (N === c)
1239
- if (w.error)
1240
- w.error._tag !== "NetworkError" || w.error.code !== "ABORTED" ? s.value = M({ error: w.error }) : s.value = G({ state: s.value, isFetching: !1 });
1332
+ const C = u.next(), O = ++s;
1333
+ i.value = x({ state: i.value });
1334
+ const b = await e.layers.predictiveSearch(w, C);
1335
+ if (O === s)
1336
+ if (b.error)
1337
+ b.error._tag !== "NetworkError" || b.error.code !== "ABORTED" ? i.value = P({ error: b.error }) : i.value = x({ state: i.value, isFetching: !1 });
1241
1338
  else {
1242
- const k = [
1243
- ...n ? [w.data.originalQuery, w.data.normalizedQuery] : [],
1244
- ...a ?? []
1245
- ], d = k.length ? {
1246
- ...w.data,
1247
- matchedQueries: It(w.data.matchedQueries, k)
1248
- } : w.data;
1249
- l.set(y, d), l.size > De && l.delete(l.keys().next().value), s.value = D({ data: d });
1339
+ const T = [
1340
+ ...a ? [b.data.originalQuery, b.data.normalizedQuery] : [],
1341
+ ...c ?? []
1342
+ ], f = T.length ? {
1343
+ ...b.data,
1344
+ matchedQueries: At(b.data.matchedQueries, T)
1345
+ } : b.data;
1346
+ d.set(S, f), d.size > $e && d.delete(d.keys().next().value), i.value = D({ data: f });
1250
1347
  }
1251
1348
  }, r);
1252
- function p(v) {
1253
- return i.add($(s, v));
1349
+ function p(h) {
1350
+ return o.add(V(i, h));
1254
1351
  }
1255
1352
  return {
1256
- state: s,
1257
- execute: (v) => g.call(v),
1353
+ state: i,
1354
+ execute: (h) => g.call(h),
1258
1355
  subscribe: p,
1259
- dispose: f
1356
+ dispose: l
1260
1357
  };
1261
1358
  };
1262
1359
  }
1263
- function St({ ctx: e }) {
1360
+ function Rt({ ctx: e }) {
1264
1361
  return ({ image: t, signal: r }) => {
1265
- const n = P({
1362
+ const a = q({
1266
1363
  data: null,
1267
1364
  error: null,
1268
1365
  isFetching: !0
1269
- }), a = q(), o = ge(r);
1366
+ }), c = F(), n = _e(r);
1270
1367
  return (async () => {
1271
- const s = await e.layers.uploadImage(t, o.signal);
1272
- if (s.error) {
1273
- n.value = M({ error: s.error });
1368
+ const i = await e.layers.uploadImage(t, n.signal);
1369
+ if (i.error) {
1370
+ a.value = P({ error: i.error });
1274
1371
  return;
1275
1372
  }
1276
- n.value = D({ data: { imageId: s.data.imageId } });
1277
- })(), {
1278
- state: n,
1279
- subscribe(s) {
1280
- return a.add($(n, s));
1373
+ a.value = D({ data: { imageId: i.data.imageId } });
1374
+ })().catch((i) => {
1375
+ a.value = P({
1376
+ error: Q({ code: "CONNECTION_FAILED", message: String(i) })
1377
+ });
1378
+ }), {
1379
+ state: a,
1380
+ subscribe(i) {
1381
+ return c.add(V(a, i));
1281
1382
  },
1282
1383
  dispose() {
1283
- a.clear(), o.abort();
1384
+ c.clear(), n.abort();
1284
1385
  }
1285
1386
  };
1286
1387
  };
1287
1388
  }
1288
- function Rt({ ctx: e }) {
1389
+ function Tt({ ctx: e }) {
1289
1390
  return (t) => {
1290
1391
  const {
1291
1392
  imageId: r,
1292
- page: n = K,
1293
- limit: a = J,
1294
- filters: o,
1295
- tuning: s,
1393
+ page: a = K,
1394
+ limit: c = X,
1395
+ filters: n,
1396
+ tuning: i,
1296
1397
  signal: u,
1297
- linking: c,
1298
- transformRequest: l
1299
- } = t, i = P({
1398
+ linking: s,
1399
+ transformRequest: d
1400
+ } = t, o = q({
1300
1401
  data: null,
1301
1402
  error: null,
1302
1403
  isFetching: !0
1303
- }), f = q(), g = ge(u);
1404
+ }), l = F(), g = _e(u);
1304
1405
  return (async () => {
1305
1406
  const p = await e.layers.imageSearch(
1306
1407
  {
1307
1408
  image_id: r,
1308
- pagination: { page: n, limit: a },
1309
- filter_group: H(e, o),
1310
- tuning: s,
1311
- dynamicLinking: c,
1312
- transformBody: l
1409
+ pagination: { page: a, limit: c },
1410
+ filter_group: J(e, n),
1411
+ tuning: i,
1412
+ dynamicLinking: s,
1413
+ transformBody: d
1313
1414
  },
1314
1415
  g.signal
1315
1416
  );
1316
1417
  if (p.error) {
1317
- i.value = M({ error: p.error });
1418
+ o.value = P({ error: p.error });
1318
1419
  return;
1319
1420
  }
1320
- const { results: v, _meta: I } = p.data, y = X(e, { results: v, meta: I }), R = z({
1321
- products: y,
1421
+ const { results: h, _meta: w } = p.data, S = W({
1422
+ results: h,
1423
+ meta: w,
1424
+ currencyCode: e.config.currency,
1425
+ formatPrice: e.config.formatPrice,
1426
+ swatches: e.config.swatches,
1427
+ extender: e.config.transforms?.product
1428
+ }), I = Z({
1429
+ products: S,
1322
1430
  raw: p.data,
1323
1431
  extender: e.config.transforms?.search,
1324
1432
  currencyCode: e.config.currency,
1325
1433
  formatPrice: e.config.formatPrice
1326
1434
  });
1327
- i.value = D({ data: R });
1328
- })(), {
1329
- state: i,
1435
+ o.value = D({ data: I });
1436
+ })().catch((p) => {
1437
+ o.value = P({
1438
+ error: Q({ code: "CONNECTION_FAILED", message: String(p) })
1439
+ });
1440
+ }), {
1441
+ state: o,
1330
1442
  subscribe(p) {
1331
- return f.add($(i, p));
1443
+ return l.add(V(o, p));
1332
1444
  },
1333
1445
  dispose() {
1334
- f.clear(), g.abort();
1446
+ l.clear(), g.abort();
1335
1447
  }
1336
1448
  };
1337
1449
  };
1338
1450
  }
1339
- function Kt(e) {
1340
- const t = Ye({
1451
+ function Ct(e) {
1452
+ return {
1453
+ title: e.title,
1454
+ handle: e.handle,
1455
+ summary: e.summary_text,
1456
+ author: e.author,
1457
+ tags: e.tags,
1458
+ image: e.image,
1459
+ publishedAt: e.published_at
1460
+ };
1461
+ }
1462
+ function Ot({ ctx: e }) {
1463
+ return (t = {}) => {
1464
+ const r = q({
1465
+ data: null,
1466
+ error: null,
1467
+ isFetching: !1
1468
+ });
1469
+ let a = {
1470
+ query: t.query,
1471
+ contentType: t.contentType,
1472
+ page: t.page,
1473
+ limit: t.limit,
1474
+ tuning: t.tuning,
1475
+ transformRequest: t.transformRequest
1476
+ };
1477
+ const c = Y(t.signal);
1478
+ let n = 0;
1479
+ const i = F();
1480
+ function u(s = {}) {
1481
+ const { signal: d, temporary: o, ...l } = s, g = { ...a, ...l };
1482
+ return o || (a = g), { ...g, signal: d };
1483
+ }
1484
+ return {
1485
+ state: r,
1486
+ async execute(s = {}) {
1487
+ const d = u(s), {
1488
+ query: o,
1489
+ contentType: l,
1490
+ page: g = K,
1491
+ limit: p = X,
1492
+ tuning: h,
1493
+ transformRequest: w
1494
+ } = d;
1495
+ if (!o) {
1496
+ const T = B({
1497
+ operation: "searchContent.execute",
1498
+ fields: [M("query", "REQUIRED_FIELD", "query is required")]
1499
+ });
1500
+ return r.value = P({ error: T, data: r.value.data }), y(T);
1501
+ }
1502
+ const S = c.next(s.signal), I = ++n, C = z({
1503
+ prefix: "/search-content",
1504
+ id: o,
1505
+ params: { contentType: l, page: g, limit: p, tuning: h }
1506
+ }), { data: O, error: b } = await e.coordinator.resolve({
1507
+ key: C,
1508
+ cache: e.cache,
1509
+ signal: S,
1510
+ onFetch: () => {
1511
+ r.value = x({ state: r.value });
1512
+ },
1513
+ fn: async (T) => {
1514
+ const f = await e.layers.searchContent(
1515
+ {
1516
+ query: o,
1517
+ content_type: l,
1518
+ pagination: { page: g, limit: p },
1519
+ tuning: h,
1520
+ transformBody: w
1521
+ },
1522
+ T
1523
+ );
1524
+ if (f.error) return y(f.error);
1525
+ const m = f.data;
1526
+ let v = {
1527
+ articles: m.results.map(Ct),
1528
+ query: m.query,
1529
+ contentType: m.contentType,
1530
+ totalResults: m.totalResults,
1531
+ page: m.page,
1532
+ resultsPerPage: m.resultsPerPage
1533
+ };
1534
+ return e.config.transforms?.searchContent && (v = e.config.transforms.searchContent(v, m)), C && e.cache.set(C, v), k(v);
1535
+ }
1536
+ });
1537
+ return I !== n ? b ? y(b) : k(O) : b ? (r.value = P({ error: b, data: r.value.data }), y(b)) : (r.value = D({ data: O }), k(O));
1538
+ },
1539
+ subscribe(s) {
1540
+ return i.add(V(r, s));
1541
+ },
1542
+ dispose() {
1543
+ i.clear(), c.abort();
1544
+ }
1545
+ };
1546
+ };
1547
+ }
1548
+ function zt(e) {
1549
+ const t = ze({
1341
1550
  token: e.token,
1342
1551
  baseUrl: e.baseUrl,
1343
1552
  sorts: e.sorts,
@@ -1345,151 +1554,149 @@ function Kt(e) {
1345
1554
  attributes: e.attributes,
1346
1555
  fetch: e.fetch
1347
1556
  });
1348
- if (t.error) return b(t.error);
1349
- const r = t.data, n = et({
1557
+ if (t.error) return y(t.error);
1558
+ const r = t.data, a = tt({
1350
1559
  maxEntries: e.cacheLimit,
1351
1560
  ttl: e.cacheLifetime,
1352
1561
  storageAdapter: e.storage
1353
1562
  });
1354
- if (e.restoreCache !== !1 && n.restore(), e.initialData)
1355
- for (const [u, c] of Object.entries(e.initialData))
1356
- n.set(u, c);
1357
- const a = tt(), o = {
1563
+ if (e.restoreCache !== !1 && a.restore(), e.initialData)
1564
+ for (const [u, s] of Object.entries(e.initialData))
1565
+ a.set(u, s);
1566
+ const c = rt(), n = {
1358
1567
  config: e,
1359
1568
  layers: r,
1360
- cache: n,
1361
- coordinator: a
1362
- }, s = {
1569
+ cache: a,
1570
+ coordinator: c
1571
+ }, i = {
1363
1572
  config: e,
1364
- cache: n,
1365
- collection: _t({ ctx: o }),
1366
- search: yt({ ctx: o }),
1367
- blocks: Et({ ctx: o }),
1368
- suggest: At({ ctx: o }),
1369
- uploadImage: St({ ctx: o }),
1370
- searchByImage: Rt({ ctx: o })
1573
+ cache: a,
1574
+ collection: yt({ ctx: n }),
1575
+ search: Et({ ctx: n }),
1576
+ blocks: wt({ ctx: n }),
1577
+ suggest: St({ ctx: n }),
1578
+ uploadImage: Rt({ ctx: n }),
1579
+ searchByImage: Tt({ ctx: n }),
1580
+ searchContent: Ot({ ctx: n })
1371
1581
  };
1372
- return pt(s), L(s);
1582
+ return ht(i), k(i);
1373
1583
  }
1374
- function Jt({
1584
+ function Wt({
1375
1585
  product: e,
1376
1586
  selectedOptions: t = [],
1377
1587
  breakoutOptions: r
1378
1588
  }) {
1379
- const n = r ?? e.breakoutOptions ?? [], a = new Set(n.map((d) => d.name)), o = P(t), s = P(null), u = q(), c = O(() => Tt(e.variants, n)), l = O(() => {
1380
- const d = o.value.filter((m) => !a.has(m.name));
1381
- return [...n, ...d];
1382
- }), i = O(
1383
- () => Ae(c.value, l.value)
1384
- ), f = O(
1385
- () => kt({
1386
- variants: c.value,
1589
+ const a = r ?? e.breakoutOptions ?? [], c = new Set(a.map((f) => f.name)), n = q(t), i = q(null), u = F(), s = L(() => kt(e.variants, a)), d = L(() => {
1590
+ const f = n.value.filter((m) => !c.has(m.name));
1591
+ return [...a, ...f];
1592
+ }), o = L(
1593
+ () => Oe(s.value, d.value)
1594
+ ), l = L(
1595
+ () => Nt({
1596
+ variants: s.value,
1387
1597
  productOptions: e.options,
1388
- selectedOptions: o.value,
1389
- breakoutOptions: n,
1390
- breakoutNames: a
1598
+ selectedOptions: n.value,
1599
+ breakoutOptions: a,
1600
+ breakoutNames: c
1391
1601
  })
1392
- ), g = O(() => e.options.find((m) => m.swatch)?.name ?? null), p = O(() => {
1393
- const d = g.value;
1394
- if (!d) return /* @__PURE__ */ new Map();
1602
+ ), g = L(() => e.options.find((m) => m.swatch)?.name ?? null), p = L(() => {
1603
+ const f = g.value;
1604
+ if (!f) return /* @__PURE__ */ new Map();
1395
1605
  const m = /* @__PURE__ */ new Map();
1396
- for (const E of c.value) {
1397
- const _ = E.selectedOptions.find((S) => S.name === d);
1398
- _ && m.set(E.numericId, _.value);
1606
+ for (const v of s.value) {
1607
+ const E = v.selectedOptions.find((R) => R.name === f);
1608
+ E && m.set(v.numericId, E.value);
1399
1609
  }
1400
1610
  return m;
1401
- }), v = O(() => {
1402
- const d = g.value;
1403
- return d ? e.options.filter((m) => m.name === d).map((m) => m.value) : [];
1404
- }), I = O(
1405
- () => Ot({
1611
+ }), h = L(() => {
1612
+ const f = g.value;
1613
+ return f ? e.options.filter((m) => m.name === f).map((m) => m.value) : [];
1614
+ }), w = L(
1615
+ () => Lt({
1406
1616
  images: e.images,
1407
- swatchValues: v.value,
1617
+ swatchValues: h.value,
1408
1618
  variantSwatchMap: p.value,
1409
- selectedVariantId: i.value?.numericId ?? null
1619
+ selectedVariantId: o.value?.numericId ?? null
1410
1620
  })
1411
- ), y = O(() => {
1412
- const d = i.value;
1413
- if (!d?.image) return I.value;
1414
- if (!g.value) return d.image ? [d.image] : I.value;
1415
- const E = p.value.get(d.numericId);
1416
- return E ? I.value.filter((_) => _.variantIds.length === 0 ? !0 : _.variantIds.some(
1417
- (S) => p.value.get(S) === E
1418
- )) : d.image ? [d.image] : I.value;
1419
- }), R = O(() => {
1420
- const d = i.value;
1421
- if (!d) return { price: null, compareAtPrice: null, isOnSale: !1 };
1422
- const m = d.compareAtPrice !== null && d.compareAtPrice.amount > d.price.amount;
1423
- return { price: d.price, compareAtPrice: d.compareAtPrice, isOnSale: m };
1424
- }), T = O(() => {
1425
- const d = c.value;
1426
- if (d.length === 0)
1427
- return { priceRange: e.priceRange, compareAtPriceRange: null };
1428
- const m = d.map((h) => h.price), E = m.reduce((h, A) => h.amount < A.amount ? h : A), _ = m.reduce((h, A) => h.amount > A.amount ? h : A), S = d.map((h) => h.compareAtPrice).filter((h) => h !== null), C = S.length > 0 ? {
1429
- min: S.reduce((h, A) => h.amount < A.amount ? h : A),
1430
- max: S.reduce((h, A) => h.amount > A.amount ? h : A)
1621
+ ), S = L(() => {
1622
+ const f = o.value;
1623
+ if (!f?.image) return w.value;
1624
+ if (!g.value) return f.image ? [f.image] : w.value;
1625
+ const v = p.value.get(f.numericId);
1626
+ return v ? w.value.filter((E) => E.variantIds.length === 0 ? !0 : E.variantIds.some(
1627
+ (R) => p.value.get(R) === v
1628
+ )) : f.image ? [f.image] : w.value;
1629
+ }), I = L(() => {
1630
+ const f = o.value;
1631
+ if (!f) return { price: null, compareAtPrice: null, isOnSale: !1 };
1632
+ const m = f.compareAtPrice !== null && f.compareAtPrice.amount > f.price.amount;
1633
+ return { price: f.price, compareAtPrice: f.compareAtPrice, isOnSale: m };
1634
+ }), C = L(() => {
1635
+ const f = s.value, m = f.map((_) => _.price), v = m.reduce((_, A) => _.amount < A.amount ? _ : A), E = m.reduce((_, A) => _.amount > A.amount ? _ : A), R = f.map((_) => _.compareAtPrice).filter((_) => _ !== null), N = R.length > 0 ? {
1636
+ min: R.reduce((_, A) => _.amount < A.amount ? _ : A),
1637
+ max: R.reduce((_, A) => _.amount > A.amount ? _ : A)
1431
1638
  } : null;
1432
- return { priceRange: { min: E, max: _ }, compareAtPriceRange: C };
1433
- }), N = O(() => {
1434
- const d = /* @__PURE__ */ new Set();
1435
- for (const m of f.value) d.add(m.name);
1436
- return d;
1437
- }), w = O(() => {
1438
- const d = new Set(l.value.map((m) => m.name));
1439
- return [...N.value].every((m) => d.has(m));
1440
- }), k = O(() => {
1441
- const d = s.value;
1442
- if (d !== null) return d;
1443
- const m = i.value;
1639
+ return { priceRange: { min: v, max: E }, compareAtPriceRange: N };
1640
+ }), O = L(() => {
1641
+ const f = /* @__PURE__ */ new Set();
1642
+ for (const m of l.value) f.add(m.name);
1643
+ return f;
1644
+ }), b = L(() => {
1645
+ const f = new Set(d.value.map((m) => m.name));
1646
+ return [...O.value].every((m) => f.has(m));
1647
+ }), T = L(() => {
1648
+ const f = i.value;
1649
+ if (f !== null) return f;
1650
+ const m = o.value;
1444
1651
  if (!m?.image) return 1;
1445
- const E = y.value.findIndex((_) => _.url === m.image?.url);
1446
- return E >= 0 ? E + 1 : 1;
1652
+ const v = S.value.findIndex((E) => E.url === m.image?.url);
1653
+ return v >= 0 ? v + 1 : 1;
1447
1654
  });
1448
1655
  return u.add(
1449
- re(() => {
1450
- o.value, s.value = null;
1656
+ ie(() => {
1657
+ n.value, i.value = null;
1451
1658
  })
1452
1659
  ), {
1453
1660
  product: e,
1454
1661
  // Reactive state
1455
- variants: c,
1456
- selectedVariant: i,
1457
- options: f,
1458
- images: y,
1459
- price: R,
1460
- priceRange: T,
1461
- carouselPosition: k,
1462
- isSelectionComplete: w,
1662
+ variants: s,
1663
+ selectedVariant: o,
1664
+ options: l,
1665
+ images: S,
1666
+ price: I,
1667
+ priceRange: C,
1668
+ carouselPosition: T,
1669
+ isSelectionComplete: b,
1463
1670
  // Actions
1464
- selectOption(d) {
1465
- const m = o.value;
1466
- o.value = m.filter((E) => E.name !== d.name).concat(d);
1671
+ selectOption(f) {
1672
+ const m = n.value;
1673
+ n.value = m.filter((v) => v.name !== f.name).concat(f);
1467
1674
  },
1468
- setSelectedOptions(d) {
1469
- const m = new Set(d.map((_) => _.name)), E = o.value.filter((_) => !m.has(_.name));
1470
- o.value = [...E, ...d];
1675
+ setSelectedOptions(f) {
1676
+ const m = new Set(f.map((E) => E.name)), v = n.value.filter((E) => !m.has(E.name));
1677
+ n.value = [...v, ...f];
1471
1678
  },
1472
- setSelectedVariant(d) {
1473
- const m = c.value.find((_) => _.numericId === d);
1679
+ setSelectedVariant(f) {
1680
+ const m = s.value.find((E) => E.numericId === f);
1474
1681
  if (!m) return;
1475
- const E = m.selectedOptions.filter((_) => !a.has(_.name));
1476
- o.value = E;
1682
+ const v = m.selectedOptions.filter((E) => !c.has(E.name));
1683
+ n.value = v;
1477
1684
  },
1478
- setCarouselPosition(d) {
1479
- s.value = d;
1685
+ setCarouselPosition(f) {
1686
+ i.value = f;
1480
1687
  },
1481
- subscribe(d) {
1688
+ subscribe(f) {
1482
1689
  return u.add(
1483
- re(() => {
1484
- d({
1485
- variants: c.value,
1486
- selectedVariant: i.value,
1487
- options: f.value,
1488
- images: y.value,
1489
- price: R.value,
1490
- priceRange: T.value,
1491
- carouselPosition: k.value,
1492
- isSelectionComplete: w.value
1690
+ ie(() => {
1691
+ f({
1692
+ variants: s.value,
1693
+ selectedVariant: o.value,
1694
+ options: l.value,
1695
+ images: S.value,
1696
+ price: I.value,
1697
+ priceRange: C.value,
1698
+ carouselPosition: T.value,
1699
+ isSelectionComplete: b.value
1493
1700
  });
1494
1701
  })
1495
1702
  );
@@ -1499,141 +1706,141 @@ function Jt({
1499
1706
  }
1500
1707
  };
1501
1708
  }
1502
- function Tt(e, t) {
1709
+ function kt(e, t) {
1503
1710
  return t.length === 0 ? e : e.filter(
1504
1711
  (r) => t.every(
1505
- (n) => r.selectedOptions.some((a) => a.name === n.name && a.value === n.value)
1712
+ (a) => r.selectedOptions.some((c) => c.name === a.name && c.value === a.value)
1506
1713
  )
1507
1714
  );
1508
1715
  }
1509
- function Ae(e, t) {
1716
+ function Oe(e, t) {
1510
1717
  return t.length === 0 ? e.length === 1 ? e[0] : null : e.find(
1511
1718
  (r) => t.every(
1512
- (n) => r.selectedOptions.some((a) => a.name === n.name && a.value === n.value)
1719
+ (a) => r.selectedOptions.some((c) => c.name === a.name && c.value === a.value)
1513
1720
  )
1514
1721
  ) ?? null;
1515
1722
  }
1516
- function kt({
1723
+ function Nt({
1517
1724
  variants: e,
1518
1725
  productOptions: t,
1519
1726
  selectedOptions: r,
1520
- breakoutOptions: n,
1521
- breakoutNames: a
1727
+ breakoutOptions: a,
1728
+ breakoutNames: c
1522
1729
  }) {
1523
- const o = /* @__PURE__ */ new Set();
1524
- for (const i of e)
1525
- for (const f of i.selectedOptions)
1526
- a.has(f.name) || o.add(`${f.name}:${f.value}`);
1527
- const s = /* @__PURE__ */ new Map();
1528
- for (const i of t)
1529
- i.swatch && s.set(`${i.name}:${i.value}`, i.swatch);
1730
+ const n = /* @__PURE__ */ new Set();
1731
+ for (const o of e)
1732
+ for (const l of o.selectedOptions)
1733
+ c.has(l.name) || n.add(`${l.name}:${l.value}`);
1734
+ const i = /* @__PURE__ */ new Map();
1735
+ for (const o of t)
1736
+ o.swatch && i.set(`${o.name}:${o.value}`, o.swatch);
1530
1737
  const u = /* @__PURE__ */ new Set();
1531
- for (const i of r) u.add(`${i.name}:${i.value}`);
1532
- const c = /* @__PURE__ */ new Map(), l = [...n, ...r];
1533
- for (const i of t) {
1534
- if (a.has(i.name) || !o.has(`${i.name}:${i.value}`)) continue;
1535
- c.has(i.name) || c.set(i.name, []);
1536
- const f = l.filter((I) => I.name !== i.name).concat({ name: i.name, value: i.value }), g = [...n, ...f.filter((I) => !a.has(I.name))], p = Ae(e, g);
1537
- let v;
1538
- p ? p.availableForSale ? v = "available" : p.inventoryPolicy === "CONTINUE" ? v = "backorderable" : v = "sold-out" : v = "unavailable", c.get(i.name).push({
1539
- value: i.value,
1540
- status: v,
1541
- selected: u.has(`${i.name}:${i.value}`),
1542
- swatch: s.get(`${i.name}:${i.value}`) ?? null
1738
+ for (const o of r) u.add(`${o.name}:${o.value}`);
1739
+ const s = /* @__PURE__ */ new Map(), d = [...a, ...r];
1740
+ for (const o of t) {
1741
+ if (c.has(o.name) || !n.has(`${o.name}:${o.value}`)) continue;
1742
+ s.has(o.name) || s.set(o.name, []);
1743
+ const l = d.filter((w) => w.name !== o.name).concat({ name: o.name, value: o.value }), g = [...a, ...l.filter((w) => !c.has(w.name))], p = Oe(e, g);
1744
+ let h;
1745
+ p ? p.availableForSale ? h = "available" : p.inventoryPolicy === "CONTINUE" ? h = "backorderable" : h = "sold-out" : h = "unavailable", s.get(o.name).push({
1746
+ value: o.value,
1747
+ status: h,
1748
+ selected: u.has(`${o.name}:${o.value}`),
1749
+ swatch: i.get(`${o.name}:${o.value}`) ?? null
1543
1750
  });
1544
1751
  }
1545
- return Array.from(c.entries()).map(([i, f]) => ({ name: i, values: f }));
1752
+ return Array.from(s.entries()).map(([o, l]) => ({ name: o, values: l }));
1546
1753
  }
1547
- function Ot({
1754
+ function Lt({
1548
1755
  images: e,
1549
1756
  swatchValues: t,
1550
1757
  variantSwatchMap: r,
1551
- selectedVariantId: n
1758
+ selectedVariantId: a
1552
1759
  }) {
1553
1760
  if (t.length === 0)
1554
- return [...e].sort((c, l) => c.position - l.position);
1555
- const a = n !== null ? r.get(n) ?? null : null, o = /* @__PURE__ */ new Map(), s = [];
1556
- for (const c of e) {
1557
- if (c.variantIds.length === 0) {
1558
- s.push(c);
1761
+ return [...e].sort((s, d) => s.position - d.position);
1762
+ const c = a !== null ? r.get(a) ?? null : null, n = /* @__PURE__ */ new Map(), i = [];
1763
+ for (const s of e) {
1764
+ if (s.variantIds.length === 0) {
1765
+ i.push(s);
1559
1766
  continue;
1560
1767
  }
1561
- let l = null;
1562
- for (const i of c.variantIds) {
1563
- const f = r.get(i);
1564
- if (f) {
1565
- l = f;
1768
+ let d = null;
1769
+ for (const o of s.variantIds) {
1770
+ const l = r.get(o);
1771
+ if (l) {
1772
+ d = l;
1566
1773
  break;
1567
1774
  }
1568
1775
  }
1569
- if (l) {
1570
- const i = o.get(l) ?? [];
1571
- i.push(c), o.set(l, i);
1776
+ if (d) {
1777
+ const o = n.get(d) ?? [];
1778
+ o.push(s), n.set(d, o);
1572
1779
  } else
1573
- s.push(c);
1780
+ i.push(s);
1574
1781
  }
1575
- for (const c of o.values())
1576
- c.sort((l, i) => l.position - i.position);
1577
- s.sort((c, l) => c.position - l.position);
1782
+ for (const s of n.values())
1783
+ s.sort((d, o) => d.position - o.position);
1784
+ i.sort((s, d) => s.position - d.position);
1578
1785
  const u = [];
1579
- a && o.has(a) && u.push(...o.get(a));
1580
- for (const c of t)
1581
- c !== a && o.has(c) && u.push(...o.get(c));
1582
- return u.push(...s), u;
1583
- }
1584
- function Yt(e, t = {}) {
1585
- return new Promise((r, n) => {
1586
- const a = new XMLHttpRequest();
1587
- if (a.open(t.method || "GET", e, !0), t.headers) {
1588
- const o = t.headers;
1589
- for (const s in o) a.setRequestHeader(s, o[s]);
1786
+ c && n.has(c) && u.push(...n.get(c));
1787
+ for (const s of t)
1788
+ s !== c && n.has(s) && u.push(...n.get(s));
1789
+ return u.push(...i), u;
1790
+ }
1791
+ function Zt(e, t = {}) {
1792
+ return new Promise((r, a) => {
1793
+ const c = new XMLHttpRequest();
1794
+ if (c.open(t.method || "GET", e, !0), t.headers) {
1795
+ const n = t.headers;
1796
+ for (const i in n) c.setRequestHeader(i, n[i]);
1590
1797
  }
1591
- if (t.signal && (t.signal.addEventListener("abort", () => a.abort()), t.signal.aborted)) {
1592
- n(new DOMException("Aborted", "AbortError"));
1798
+ if (t.signal && (t.signal.addEventListener("abort", () => c.abort()), t.signal.aborted)) {
1799
+ a(new DOMException("Aborted", "AbortError"));
1593
1800
  return;
1594
1801
  }
1595
- a.onload = () => {
1596
- const o = new Headers();
1597
- a.getAllResponseHeaders().trim().split(`\r
1598
- `).forEach((s) => {
1599
- const [u, ...c] = s.split(": ");
1600
- u && o.append(u, c.join(": "));
1802
+ c.onload = () => {
1803
+ const n = new Headers();
1804
+ c.getAllResponseHeaders().trim().split(`\r
1805
+ `).forEach((i) => {
1806
+ const [u, ...s] = i.split(": ");
1807
+ u && n.append(u, s.join(": "));
1601
1808
  }), r(
1602
- new Response(a.response, {
1603
- status: a.status,
1604
- statusText: a.statusText,
1605
- headers: o
1809
+ new Response(c.response, {
1810
+ status: c.status,
1811
+ statusText: c.statusText,
1812
+ headers: n
1606
1813
  })
1607
1814
  );
1608
- }, a.onerror = () => n(new TypeError("Network request failed")), a.ontimeout = () => n(new DOMException("Timeout", "TimeoutError")), a.onabort = () => n(new DOMException("Aborted", "AbortError")), a.send(t.body);
1815
+ }, c.onerror = () => a(new TypeError("Network request failed")), c.ontimeout = () => a(new DOMException("Timeout", "TimeoutError")), c.onabort = () => a(new DOMException("Aborted", "AbortError")), c.send(t.body);
1609
1816
  });
1610
1817
  }
1611
1818
  export {
1612
1819
  nt as and,
1613
- Wt as batch,
1614
- Zt as computed,
1615
- Kt as createClient,
1616
- Jt as createProductCard,
1617
- en as effect,
1618
- Pt as eq,
1619
- Bt as exists,
1620
- Lt as fileStorage,
1621
- Ht as filter,
1622
- jt as getClient,
1623
- Ut as gt,
1624
- Ft as gte,
1625
- Mt as inValues,
1626
- Ct as isClientError,
1627
- Qt as isInitialized,
1628
- Ve as isRetryable,
1629
- ze as localStorageAdapter,
1630
- $t as lt,
1631
- Vt as lte,
1632
- Dt as notEq,
1633
- xt as notExists,
1634
- qt as notIn,
1635
- Gt as or,
1636
- tn as signal,
1637
- $ as subscribe,
1638
- Yt as xhrFetch
1820
+ rr as batch,
1821
+ nr as computed,
1822
+ zt as createClient,
1823
+ Wt as createProductCard,
1824
+ ar as effect,
1825
+ Ut as eq,
1826
+ Ht as exists,
1827
+ Ft as fileStorage,
1828
+ Kt as filter,
1829
+ Xt as getClient,
1830
+ Bt as gt,
1831
+ Gt as gte,
1832
+ Vt as inValues,
1833
+ qt as isClientError,
1834
+ Yt as isInitialized,
1835
+ Dt as isRetryable,
1836
+ We as localStorageAdapter,
1837
+ xt as lt,
1838
+ jt as lte,
1839
+ Mt as notEq,
1840
+ Qt as notExists,
1841
+ $t as notIn,
1842
+ Jt as or,
1843
+ or as signal,
1844
+ V as subscribe,
1845
+ Zt as xhrFetch
1639
1846
  };