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