@usethrottle/storefront-react 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/CLAUDE.md +67 -0
  2. package/README.md +119 -2
  3. package/dist/StorefrontProvider-Br4wUHui.d.cts +559 -0
  4. package/dist/StorefrontProvider-DLEPEjg6.d.ts +559 -0
  5. package/dist/account/index.cjs +69 -0
  6. package/dist/account/index.cjs.map +1 -0
  7. package/dist/account/index.d.cts +23 -0
  8. package/dist/account/index.d.ts +23 -0
  9. package/dist/account/index.js +68 -0
  10. package/dist/account/index.js.map +1 -0
  11. package/dist/chunk-2LCPIY2P.cjs +16 -0
  12. package/dist/chunk-2LCPIY2P.cjs.map +1 -0
  13. package/dist/chunk-3A72UY6T.js +2126 -0
  14. package/dist/chunk-3A72UY6T.js.map +1 -0
  15. package/dist/chunk-3JMIVAHN.js +185 -0
  16. package/dist/chunk-3JMIVAHN.js.map +1 -0
  17. package/dist/chunk-4J6AGWNC.cjs +24 -0
  18. package/dist/chunk-4J6AGWNC.cjs.map +1 -0
  19. package/dist/chunk-4U6MYDZV.js +17 -0
  20. package/dist/chunk-4U6MYDZV.js.map +1 -0
  21. package/dist/chunk-66HDJVPS.js +22 -0
  22. package/dist/chunk-66HDJVPS.js.map +1 -0
  23. package/dist/chunk-6X2OZSNV.cjs +83 -0
  24. package/dist/chunk-6X2OZSNV.cjs.map +1 -0
  25. package/dist/chunk-6ZMMZ245.cjs +2127 -0
  26. package/dist/chunk-6ZMMZ245.cjs.map +1 -0
  27. package/dist/chunk-7R37CVAB.cjs +23 -0
  28. package/dist/chunk-7R37CVAB.cjs.map +1 -0
  29. package/dist/chunk-A3IFWQUV.js +368 -0
  30. package/dist/chunk-A3IFWQUV.js.map +1 -0
  31. package/dist/chunk-AYC2YK4E.cjs +95 -0
  32. package/dist/chunk-AYC2YK4E.cjs.map +1 -0
  33. package/dist/chunk-AZV5U7YB.cjs +18 -0
  34. package/dist/chunk-AZV5U7YB.cjs.map +1 -0
  35. package/dist/chunk-CE2SKNQP.cjs +71 -0
  36. package/dist/chunk-CE2SKNQP.cjs.map +1 -0
  37. package/dist/chunk-D76CRI4X.js +2175 -0
  38. package/dist/chunk-D76CRI4X.js.map +1 -0
  39. package/dist/chunk-DOAII637.cjs +186 -0
  40. package/dist/chunk-DOAII637.cjs.map +1 -0
  41. package/dist/chunk-DYHHAOMG.cjs +17 -0
  42. package/dist/chunk-DYHHAOMG.cjs.map +1 -0
  43. package/dist/chunk-EYSVU5SJ.js +196 -0
  44. package/dist/chunk-EYSVU5SJ.js.map +1 -0
  45. package/dist/chunk-HSUUDZWS.js +37 -0
  46. package/dist/chunk-HSUUDZWS.js.map +1 -0
  47. package/dist/chunk-HZ6VEN6Q.cjs +101 -0
  48. package/dist/chunk-HZ6VEN6Q.cjs.map +1 -0
  49. package/dist/chunk-IJOTLGPT.js +16 -0
  50. package/dist/chunk-IJOTLGPT.js.map +1 -0
  51. package/dist/chunk-ISDATHVC.js +219 -0
  52. package/dist/chunk-ISDATHVC.js.map +1 -0
  53. package/dist/chunk-LW2A6USV.js +100 -0
  54. package/dist/chunk-LW2A6USV.js.map +1 -0
  55. package/dist/chunk-M4YXSLRG.cjs +369 -0
  56. package/dist/chunk-M4YXSLRG.cjs.map +1 -0
  57. package/dist/chunk-NDUEJJLP.cjs +2176 -0
  58. package/dist/chunk-NDUEJJLP.cjs.map +1 -0
  59. package/dist/chunk-NNE4FYRT.js +820 -0
  60. package/dist/chunk-NNE4FYRT.js.map +1 -0
  61. package/dist/chunk-NW3EFHY2.js +15 -0
  62. package/dist/chunk-NW3EFHY2.js.map +1 -0
  63. package/dist/chunk-NZRUQUN5.js +167 -0
  64. package/dist/chunk-NZRUQUN5.js.map +1 -0
  65. package/dist/chunk-P6HHE57S.cjs +38 -0
  66. package/dist/chunk-P6HHE57S.cjs.map +1 -0
  67. package/dist/chunk-PHY7AY27.cjs +197 -0
  68. package/dist/chunk-PHY7AY27.cjs.map +1 -0
  69. package/dist/chunk-PNJOFFTL.cjs +128 -0
  70. package/dist/chunk-PNJOFFTL.cjs.map +1 -0
  71. package/dist/chunk-PXZQ4ONA.js +127 -0
  72. package/dist/chunk-PXZQ4ONA.js.map +1 -0
  73. package/dist/chunk-Q3VTUBPP.js +82 -0
  74. package/dist/chunk-Q3VTUBPP.js.map +1 -0
  75. package/dist/chunk-Q3XFD5UI.js +45 -0
  76. package/dist/chunk-Q3XFD5UI.js.map +1 -0
  77. package/dist/chunk-QM7KTT7F.js +94 -0
  78. package/dist/chunk-QM7KTT7F.js.map +1 -0
  79. package/dist/chunk-RLWZOLXL.js +70 -0
  80. package/dist/chunk-RLWZOLXL.js.map +1 -0
  81. package/dist/chunk-SV53BRP2.js +23 -0
  82. package/dist/chunk-SV53BRP2.js.map +1 -0
  83. package/dist/chunk-VWXJO427.cjs +821 -0
  84. package/dist/chunk-VWXJO427.cjs.map +1 -0
  85. package/dist/chunk-WIIOJDHR.cjs +220 -0
  86. package/dist/chunk-WIIOJDHR.cjs.map +1 -0
  87. package/dist/chunk-XQHGFWLG.cjs +46 -0
  88. package/dist/chunk-XQHGFWLG.cjs.map +1 -0
  89. package/dist/chunk-ZHCXI2ZZ.cjs +168 -0
  90. package/dist/chunk-ZHCXI2ZZ.cjs.map +1 -0
  91. package/dist/index-RSj2Rg62.d.cts +8 -0
  92. package/dist/index-RSj2Rg62.d.ts +8 -0
  93. package/dist/index.cjs +2829 -0
  94. package/dist/index.cjs.map +1 -0
  95. package/dist/index.d.cts +1718 -0
  96. package/dist/index.d.ts +1718 -0
  97. package/dist/index.js +2828 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/metadata-QhKw-tvz.d.cts +188 -0
  100. package/dist/metadata-QhKw-tvz.d.ts +188 -0
  101. package/dist/next/client.cjs +84 -0
  102. package/dist/next/client.cjs.map +1 -0
  103. package/dist/next/client.d.cts +40 -0
  104. package/dist/next/client.d.ts +40 -0
  105. package/dist/next/client.js +83 -0
  106. package/dist/next/client.js.map +1 -0
  107. package/dist/next/index.cjs +1090 -0
  108. package/dist/next/index.cjs.map +1 -0
  109. package/dist/next/index.d.cts +218 -0
  110. package/dist/next/index.d.ts +218 -0
  111. package/dist/next/index.js +1049 -0
  112. package/dist/next/index.js.map +1 -0
  113. package/dist/server/index.cjs +994 -0
  114. package/dist/server/index.cjs.map +1 -0
  115. package/dist/server/index.d.cts +229 -0
  116. package/dist/server/index.d.ts +229 -0
  117. package/dist/server/index.js +951 -0
  118. package/dist/server/index.js.map +1 -0
  119. package/dist/styles.css +2111 -0
  120. package/dist/use-part-DCfFk7kf.d.ts +24 -0
  121. package/dist/use-part-DgjPBL_O.d.cts +24 -0
  122. package/package.json +121 -3
package/dist/index.js ADDED
@@ -0,0 +1,2828 @@
1
+ "use client";
2
+ import {
3
+ DefaultLink,
4
+ STOREFRONT_LAYER_ORDER_ID,
5
+ STOREFRONT_STYLES,
6
+ STOREFRONT_STYLE_ID,
7
+ StorefrontProvider,
8
+ normalizeSettings,
9
+ themeToVariables,
10
+ useHistoryRouter
11
+ } from "./chunk-3A72UY6T.js";
12
+ import {
13
+ useMediaQuery
14
+ } from "./chunk-SV53BRP2.js";
15
+ import {
16
+ QuickAdd
17
+ } from "./chunk-EYSVU5SJ.js";
18
+ import {
19
+ CartLine
20
+ } from "./chunk-QM7KTT7F.js";
21
+ import {
22
+ useCartDrawer
23
+ } from "./chunk-NW3EFHY2.js";
24
+ import {
25
+ AddToCart,
26
+ BackInStock,
27
+ Badge,
28
+ Breadcrumbs,
29
+ BuyBox,
30
+ CategoryList,
31
+ FrequentlyBoughtTogether,
32
+ Gallery,
33
+ JsonLd,
34
+ ProductCard,
35
+ ProductPage,
36
+ ProductSections,
37
+ QuantityInput,
38
+ QuestionsAndAnswers,
39
+ RelatedProducts,
40
+ ReviewForm,
41
+ ReviewPhotos,
42
+ ReviewVotes,
43
+ Reviews,
44
+ RichText,
45
+ ShippingSection,
46
+ SlotOutlet,
47
+ StickyAddToCart,
48
+ StockStatus,
49
+ Swatch,
50
+ TagList,
51
+ VariantPicker,
52
+ WishlistButton,
53
+ breadcrumbJsonLd,
54
+ canonicalForShopQuery,
55
+ cardBadges,
56
+ itemListJsonLd,
57
+ pageWindow,
58
+ parseShopQuery,
59
+ pickerKind,
60
+ productCrumbs,
61
+ productJsonLd,
62
+ productMetadata,
63
+ robotsForShopQuery,
64
+ sanitizeHtml,
65
+ searchMetadata,
66
+ selectOption,
67
+ shopAllMetadata,
68
+ shopQueryToSearch,
69
+ stockWord,
70
+ useProductPage,
71
+ useRelatedProducts,
72
+ useShippingContent,
73
+ variantFromSearch
74
+ } from "./chunk-D76CRI4X.js";
75
+ import {
76
+ catalogSiteDesign,
77
+ menuHref,
78
+ menuItems,
79
+ resolveSiteDesign
80
+ } from "./chunk-A3IFWQUV.js";
81
+ import "./chunk-66HDJVPS.js";
82
+ import {
83
+ CompareButton,
84
+ createStoredList,
85
+ useCompare
86
+ } from "./chunk-PXZQ4ONA.js";
87
+ import {
88
+ MERCH_STALE_MS,
89
+ cardFields,
90
+ isEmptySource,
91
+ productSourceQuery,
92
+ shopListQuery,
93
+ useListAnalytics,
94
+ useMerchProducts
95
+ } from "./chunk-3JMIVAHN.js";
96
+ import {
97
+ Money,
98
+ Price,
99
+ StarRating,
100
+ routeHref,
101
+ toGa4Item
102
+ } from "./chunk-LW2A6USV.js";
103
+ import {
104
+ useTrack
105
+ } from "./chunk-IJOTLGPT.js";
106
+ import {
107
+ Image
108
+ } from "./chunk-HSUUDZWS.js";
109
+ import {
110
+ useStrings
111
+ } from "./chunk-Q3XFD5UI.js";
112
+ import {
113
+ SF_STRINGS_EN,
114
+ STOREFRONT_PART_KEYS,
115
+ SYNC_ATTRIBUTES,
116
+ Unstyled,
117
+ UnstyledContext,
118
+ usePart,
119
+ useStorefront,
120
+ useUnstyled
121
+ } from "./chunk-NNE4FYRT.js";
122
+
123
+ // src/analytics/ga.ts
124
+ var noopAnalytics = { track() {
125
+ } };
126
+ function gaAnalytics(o = {}) {
127
+ return {
128
+ track(event, payload) {
129
+ if (typeof window === "undefined") return;
130
+ const w = window;
131
+ if (o.target === "gtag") w.gtag?.("event", event, payload);
132
+ else {
133
+ const layer = w.dataLayer ??= [];
134
+ layer.push({ ecommerce: null });
135
+ layer.push({ event, ecommerce: payload });
136
+ }
137
+ }
138
+ };
139
+ }
140
+
141
+ // src/analytics/scripts.ts
142
+ var THROTTLE_EVENTS = {
143
+ view_item: "product.viewed",
144
+ view_item_list: "collection.viewed",
145
+ add_to_cart: "cart.item_added",
146
+ remove_from_cart: "cart.item_removed",
147
+ view_cart: "cart.viewed",
148
+ begin_checkout: "cart.checkout_started",
149
+ select_item: "custom.select_item"
150
+ };
151
+ function throttleScriptsAnalytics(scripts) {
152
+ return {
153
+ track(event, payload) {
154
+ if (typeof window === "undefined") return;
155
+ scripts.track(THROTTLE_EVENTS[event], payload);
156
+ }
157
+ };
158
+ }
159
+
160
+ // src/analytics/types.ts
161
+ var GA4_EVENTS = [
162
+ "view_item_list",
163
+ "select_item",
164
+ "view_item",
165
+ "add_to_cart",
166
+ "remove_from_cart",
167
+ "view_cart",
168
+ "begin_checkout"
169
+ ];
170
+
171
+ // src/pieces/Link.tsx
172
+ import { jsx } from "react/jsx-runtime";
173
+ function Link({ classNames, unstyled, className, ...anchor }) {
174
+ const { Link: Anchor } = useStorefront();
175
+ const part = usePart("link", { classNames, className, unstyled });
176
+ return /* @__PURE__ */ jsx(Anchor, { ...anchor, ...part });
177
+ }
178
+
179
+ // src/shop/ShopAll.tsx
180
+ import { useMemo as useMemo2 } from "react";
181
+
182
+ // src/shop/ActiveFilters.tsx
183
+ import { Icon } from "@usethrottle/ui";
184
+
185
+ // src/shop/use-shop-all.ts
186
+ import { useProducts } from "@usethrottle/catalog/react";
187
+ import {
188
+ createContext,
189
+ useCallback,
190
+ useContext,
191
+ useEffect as useEffect2,
192
+ useMemo,
193
+ useRef as useRef2,
194
+ useState
195
+ } from "react";
196
+
197
+ // src/shop/scroll-restore.ts
198
+ import { useEffect, useReducer, useRef } from "react";
199
+ var PREFIX = "tsf-shop-scroll:";
200
+ var TRAVERSAL_WINDOW_MS = 2e3;
201
+ var HISTORY_LOAD_WINDOW_MS = 1e4;
202
+ var lastTraversalAt = Number.NEGATIVE_INFINITY;
203
+ var historyLoad = null;
204
+ if (typeof window !== "undefined") {
205
+ window.addEventListener("popstate", () => {
206
+ lastTraversalAt = Date.now();
207
+ });
208
+ }
209
+ function takeHistoryLoad() {
210
+ if (historyLoad === null) {
211
+ const entry = typeof performance !== "undefined" ? performance.getEntriesByType?.("navigation")?.[0] : void 0;
212
+ historyLoad = entry?.type === "back_forward" && performance.now() < HISTORY_LOAD_WINDOW_MS;
213
+ }
214
+ const taken = historyLoad;
215
+ historyLoad = false;
216
+ return taken;
217
+ }
218
+ var read = (key) => {
219
+ try {
220
+ return window.sessionStorage.getItem(key);
221
+ } catch {
222
+ return null;
223
+ }
224
+ };
225
+ function rememberScroll() {
226
+ if (typeof window === "undefined") return;
227
+ try {
228
+ window.sessionStorage.setItem(PREFIX + window.location.href, String(Math.round(window.scrollY)));
229
+ } catch {
230
+ }
231
+ }
232
+ function useScrollRestore(ready) {
233
+ const pending = useRef(false);
234
+ const [wake, bump] = useReducer((n) => n + 1, 0);
235
+ useEffect(() => {
236
+ const byHistory = takeHistoryLoad();
237
+ if (byHistory || Date.now() - lastTraversalAt < TRAVERSAL_WINDOW_MS) {
238
+ pending.current = true;
239
+ bump();
240
+ }
241
+ const onPop = () => {
242
+ pending.current = true;
243
+ bump();
244
+ };
245
+ window.addEventListener("popstate", onPop);
246
+ return () => window.removeEventListener("popstate", onPop);
247
+ }, []);
248
+ useEffect(() => {
249
+ if (!ready || !pending.current) return;
250
+ const saved = read(PREFIX + window.location.href);
251
+ const y = saved === null ? Number.NaN : Number(saved);
252
+ if (!Number.isFinite(y)) {
253
+ pending.current = false;
254
+ return;
255
+ }
256
+ window.scrollTo(0, y);
257
+ const again = () => {
258
+ pending.current = false;
259
+ if (Math.abs(window.scrollY - y) > 1) window.scrollTo(0, y);
260
+ };
261
+ if (typeof requestAnimationFrame !== "function") {
262
+ const timer = window.setTimeout(again, 0);
263
+ return () => window.clearTimeout(timer);
264
+ }
265
+ const frame = requestAnimationFrame(again);
266
+ return () => cancelAnimationFrame(frame);
267
+ }, [ready, wake]);
268
+ }
269
+
270
+ // src/shop/use-shop-all.ts
271
+ var MAX_CHUNK_PAGES = 5;
272
+ var CATALOG_MAX_LIMIT = 100;
273
+ var ShopAllContext = createContext(null);
274
+ function useShopAll() {
275
+ const value = useContext(ShopAllContext);
276
+ if (!value) throw new Error("useShopAll() was called outside <ShopAll.Root>.");
277
+ return value;
278
+ }
279
+ var NO_CRUMBS = [];
280
+ var rangeKeysOf = (facets) => facets && facets.length > 0 ? facets.filter((f) => f.display === "range").map((f) => f.key) : void 0;
281
+ var withoutKey = (record, key) => {
282
+ const { [key]: _removed, ...rest } = record;
283
+ return rest;
284
+ };
285
+ var currencyOf = (answer) => answer.currency ?? answer.products.find((p) => p.priceRange)?.priceRange?.currency;
286
+ function listNameOf(source) {
287
+ if (source.kind === "all") return "shop";
288
+ if (source.kind === "search") return "search";
289
+ return `${source.kind}:${source.handle}`;
290
+ }
291
+ function useShopAllState({
292
+ source,
293
+ initialData,
294
+ pagination
295
+ }) {
296
+ const { router, settings } = useStorefront();
297
+ const { t } = useStrings();
298
+ const track = useTrack();
299
+ const topRef = useRef2(null);
300
+ const [mounted, setMounted] = useState(false);
301
+ useEffect2(() => setMounted(true), []);
302
+ const facetsRef = useRef2(initialData?.facets);
303
+ const rangeKeys = rangeKeysOf(facetsRef.current);
304
+ const search = router.searchParams.toString();
305
+ const sourceKey = JSON.stringify(source);
306
+ const query = useMemo(() => {
307
+ const parsed = !mounted && initialData ? initialData.query : parseShopQuery(new URLSearchParams(search), settings, rangeKeys);
308
+ return source.kind === "search" ? { ...parsed, q: source.q } : parsed;
309
+ }, [mounted, initialData, search, settings, rangeKeys?.join("\0"), sourceKey]);
310
+ const manualCollection = initialData?.collectionKind === "manual";
311
+ const fields = useMemo(() => cardFields(settings), [settings]);
312
+ const pageSize = settings.listing.pageSize;
313
+ const selectionKey = JSON.stringify([query.filters, query.ranges, query.sort, query.q ?? null]);
314
+ const loadMode = pagination !== "numbered";
315
+ const seedFor = (page) => initialData && initialData.query.page === page && selectionKey === JSON.stringify([initialData.query.filters, initialData.query.ranges, initialData.query.sort, initialData.query.q ?? null]) ? initialData.list : void 0;
316
+ const anchorKey = `${sourceKey}\0${selectionKey}`;
317
+ const chunkCap = Math.max(1, Math.min(MAX_CHUNK_PAGES, Math.floor(CATALOG_MAX_LIMIT / pageSize)));
318
+ const anchorRef = useRef2(null);
319
+ let anchor = anchorRef.current;
320
+ if (!anchor || anchor.key !== anchorKey || query.page < anchor.first + anchor.span - 1) {
321
+ const cold = loadMode && seedFor(query.page) === void 0 && query.page <= chunkCap;
322
+ anchor = { key: anchorKey, first: cold ? 1 : query.page, span: cold ? query.page : 1 };
323
+ anchorRef.current = anchor;
324
+ }
325
+ const segments = useMemo(() => {
326
+ const make = (from, to) => {
327
+ const base = shopListQuery({ ...query, page: from }, source, settings, { fields, manualCollection });
328
+ const listed = to > from ? { ...base, limit: (to - from + 1) * pageSize } : base;
329
+ const seed = to === from ? seedFor(from) : void 0;
330
+ return { key: JSON.stringify(listed), from, to, query: listed, ...seed ? { seed } : {} };
331
+ };
332
+ if (!loadMode) return [make(query.page, query.page)];
333
+ const end = anchor.first + anchor.span - 1;
334
+ const list = [];
335
+ if (loadMode && anchor.first > 1 && anchor.first - 1 <= chunkCap) list.push(make(1, anchor.first - 1));
336
+ list.push(make(anchor.first, end));
337
+ for (let page = end + 1; page <= query.page; page += 1) list.push(make(page, page));
338
+ return list;
339
+ }, [query, sourceKey, settings, fields, manualCollection, pageSize, loadMode, chunkCap, anchor.first, anchor.span, initialData, selectionKey]);
340
+ const primary = segments[segments.length - 1];
341
+ const earlier = useMemo(() => segments.slice(0, -1), [segments]);
342
+ const listQuery = primary.query;
343
+ const result = useProducts(listQuery, { initialData: primary.seed, keepPreviousData: true });
344
+ const data = result.data;
345
+ const isPrevious = result.isPreviousData;
346
+ const status = data && !isPrevious ? "ready" : result.error ? "error" : "loading";
347
+ const facets = data?.filters ?? initialData?.facets ?? [];
348
+ facetsRef.current = data?.filters ?? facetsRef.current;
349
+ const total = data?.page.total ?? void 0;
350
+ const pageCount = Math.max(1, total !== void 0 ? Math.ceil(total / pageSize) : data?.page.pageCount ?? 1);
351
+ const [readySegments, setReadySegments] = useState(() => /* @__PURE__ */ new Set());
352
+ const reportReady = useCallback(
353
+ (key) => setReadySegments((seen) => seen.has(key) ? seen : new Set(seen).add(key)),
354
+ []
355
+ );
356
+ const earlierReady = earlier.every((segment) => readySegments.has(segment.key));
357
+ const hrefFor = useCallback(
358
+ (next) => {
359
+ const queryString = shopQueryToSearch(next, settings);
360
+ return `${router.pathname}${queryString ? `?${queryString}` : ""}`;
361
+ },
362
+ [router.pathname, settings]
363
+ );
364
+ const go = useCallback(
365
+ (next, mode = "push") => router[mode](hrefFor(next), { scroll: false }),
366
+ [router, hrefFor]
367
+ );
368
+ const setValues = useCallback(
369
+ (key, values) => {
370
+ const filters = values.length > 0 ? { ...query.filters, [key]: values } : withoutKey(query.filters, key);
371
+ go({ ...query, filters, ranges: withoutKey(query.ranges, key), page: 1 });
372
+ },
373
+ [query, go]
374
+ );
375
+ const toggleValue = useCallback(
376
+ (key, value) => {
377
+ const current = query.filters[key] ?? [];
378
+ setValues(key, current.includes(value) ? current.filter((v) => v !== value) : [...current, value]);
379
+ },
380
+ [query, setValues]
381
+ );
382
+ const setRange = useCallback(
383
+ (key, range) => {
384
+ const set = range !== null && (range.min !== void 0 || range.max !== void 0);
385
+ go({
386
+ ...query,
387
+ filters: withoutKey(query.filters, key),
388
+ ranges: set ? { ...query.ranges, [key]: range } : withoutKey(query.ranges, key),
389
+ page: 1
390
+ });
391
+ },
392
+ [query, go]
393
+ );
394
+ const clear = useCallback(
395
+ (key) => go(
396
+ key === void 0 ? { ...query, filters: {}, ranges: {}, page: 1 } : { ...query, filters: withoutKey(query.filters, key), ranges: withoutKey(query.ranges, key), page: 1 }
397
+ ),
398
+ [query, go]
399
+ );
400
+ const setSort = useCallback((sort) => go({ ...query, sort, page: 1 }), [query, go]);
401
+ const setPage = useCallback(
402
+ (page) => {
403
+ go({ ...query, page });
404
+ topRef.current?.scrollIntoView?.({ block: "start" });
405
+ },
406
+ [query, go]
407
+ );
408
+ const loadMore = useCallback(() => go({ ...query, page: query.page + 1 }, "replace"), [query, go]);
409
+ const listName = listNameOf(source);
410
+ const selectProduct = useCallback(
411
+ (product, index) => {
412
+ rememberScroll();
413
+ const currency = data ? currencyOf(data) : void 0;
414
+ if (currency) {
415
+ track("select_item", { currency, item_list_name: listName, items: [toGa4Item(product, { index, listName })] });
416
+ }
417
+ },
418
+ [data, track, listName]
419
+ );
420
+ const listKey = `${sourceKey}\0${JSON.stringify(listQuery)}`;
421
+ const reported = useRef2(null);
422
+ useEffect2(() => {
423
+ if (status !== "ready" || !data || reported.current === listKey) return;
424
+ reported.current = listKey;
425
+ const currency = currencyOf(data);
426
+ if (!currency) return;
427
+ const offset = (data.page.number - 1) * data.page.limit;
428
+ track("view_item_list", {
429
+ currency,
430
+ item_list_name: listName,
431
+ items: data.products.map((p, i) => toGa4Item(p, { index: offset + i, listName }))
432
+ });
433
+ }, [status, data, listKey, listName, track]);
434
+ useScrollRestore(status === "ready" && earlierReady);
435
+ const fallbackTitle = source.kind === "all" ? t("shop.title") : source.kind === "search" ? t("search.results", { q: source.q }) : source.handle;
436
+ const [shownAt] = useState(() => (/* @__PURE__ */ new Date()).toISOString());
437
+ const refetch = useCallback(() => void result.refetch(), [result.refetch]);
438
+ const selectedCount = Object.values(query.filters).reduce((n, values) => n + values.length, 0) + Object.keys(query.ranges).length;
439
+ const title = initialData?.title ?? fallbackTitle;
440
+ const description = initialData?.description;
441
+ const breadcrumbs = initialData?.breadcrumbs ?? NO_CRUMBS;
442
+ const generatedAt = initialData?.generatedAt ?? shownAt;
443
+ const reviewsOnLists = initialData?.reviewsOnLists;
444
+ return useMemo(() => ({
445
+ source,
446
+ query,
447
+ data,
448
+ status,
449
+ isPrevious,
450
+ facets,
451
+ total,
452
+ pageCount,
453
+ listQuery,
454
+ earlier,
455
+ firstLoadedPage: segments[0].from,
456
+ reportReady,
457
+ hrefFor,
458
+ toggleValue,
459
+ setValues,
460
+ setRange,
461
+ clear,
462
+ setSort,
463
+ setPage,
464
+ loadMore,
465
+ refetch,
466
+ selectedCount,
467
+ announceKey: selectionKey,
468
+ title,
469
+ ...description ? { description } : {},
470
+ breadcrumbs,
471
+ listName,
472
+ generatedAt,
473
+ ...reviewsOnLists !== void 0 ? { reviewsOnLists } : {},
474
+ manualCollection,
475
+ selectProduct,
476
+ topRef
477
+ }), [
478
+ source,
479
+ query,
480
+ data,
481
+ status,
482
+ isPrevious,
483
+ facets,
484
+ total,
485
+ pageCount,
486
+ listQuery,
487
+ earlier,
488
+ segments,
489
+ reportReady,
490
+ hrefFor,
491
+ toggleValue,
492
+ setValues,
493
+ setRange,
494
+ clear,
495
+ setSort,
496
+ setPage,
497
+ loadMore,
498
+ refetch,
499
+ selectedCount,
500
+ selectionKey,
501
+ title,
502
+ description,
503
+ breadcrumbs,
504
+ listName,
505
+ generatedAt,
506
+ reviewsOnLists,
507
+ manualCollection,
508
+ selectProduct
509
+ ]);
510
+ }
511
+
512
+ // src/shop/ActiveFilters.tsx
513
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
514
+ function ActiveFilters(local) {
515
+ const root = usePart("active-filters", local);
516
+ const item = usePart("active-filter", local);
517
+ const remove = usePart("active-filter-remove", local);
518
+ const clearAll = usePart("active-filters-clear", local);
519
+ const { t } = useStrings();
520
+ const { query, facets, toggleValue, setRange, clear, selectedCount } = useShopAll();
521
+ if (selectedCount === 0) return null;
522
+ const rangeText = ({ min, max }) => min !== void 0 && max !== void 0 ? t("shop.rangeBetween", { min, max }) : min !== void 0 ? t("shop.rangeFrom", { min }) : t("shop.rangeUpTo", { max: max ?? "" });
523
+ const chips = [];
524
+ for (const [key, values] of Object.entries(query.filters)) {
525
+ const facet = facets.find((f) => f.key === key);
526
+ for (const value of values) {
527
+ const label = facet?.values.find((v) => v.value === value)?.label ?? value;
528
+ chips.push({ id: `${key}\0${value}`, label, name: `${facet?.label ?? key}: ${label}`, remove: () => toggleValue(key, value) });
529
+ }
530
+ }
531
+ for (const [key, range] of Object.entries(query.ranges)) {
532
+ const name = facets.find((f) => f.key === key)?.label ?? key;
533
+ chips.push({ id: `${key}\0range`, label: rangeText(range), name: `${name}: ${rangeText(range)}`, remove: () => setRange(key, null) });
534
+ }
535
+ return /* @__PURE__ */ jsxs("ul", { ...root, "aria-label": t("filters.title"), children: [
536
+ chips.map((chip) => /* @__PURE__ */ jsx2("li", { ...item, children: /* @__PURE__ */ jsxs("button", { ...remove, type: "button", "aria-label": t("shop.removeFilter", { label: chip.name }), onClick: chip.remove, children: [
537
+ /* @__PURE__ */ jsx2("span", { children: chip.label }),
538
+ /* @__PURE__ */ jsx2(Icon, { name: "close", size: 14 })
539
+ ] }) }, chip.id)),
540
+ /* @__PURE__ */ jsx2("li", { children: /* @__PURE__ */ jsx2("button", { ...clearAll, type: "button", onClick: () => clear(), children: t("filters.clearAll") }) })
541
+ ] });
542
+ }
543
+
544
+ // src/shop/FilterBar.tsx
545
+ import { useRef as useRef5, useState as useState4 } from "react";
546
+
547
+ // src/shop/FacetGroup.tsx
548
+ import { useFilterValues } from "@usethrottle/catalog/react";
549
+ import { Icon as Icon2, VisuallyHidden } from "@usethrottle/ui";
550
+ import { useEffect as useEffect3, useId, useRef as useRef3, useState as useState2 } from "react";
551
+ import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
552
+ var FACET_VALUE_LIMIT = 10;
553
+ function visibleFacets(facets, query) {
554
+ return facets.filter(
555
+ (f) => (f.display === "range" ? f.range !== void 0 : f.values.length > 0) || (query.filters[f.key]?.length ?? 0) > 0 || query.ranges[f.key] !== void 0
556
+ );
557
+ }
558
+ function withSelected(values, selected) {
559
+ const missing = selected.filter((s) => !values.some((v) => v.value === s));
560
+ return [...values, ...missing.map((value) => ({ value, label: value, count: 0, selected: true }))];
561
+ }
562
+ function OptionList({ facet, local }) {
563
+ const fieldset = usePart("facet-fieldset", local);
564
+ const legend = usePart("facet-legend", local);
565
+ const options = usePart("facet-options", local);
566
+ const option = usePart("facet-option", local);
567
+ const optionLabel = usePart("facet-option-label", local);
568
+ const input = usePart("facet-option-input", local);
569
+ const text = usePart("facet-option-text", local);
570
+ const count = usePart("facet-option-count", local);
571
+ const search = usePart("facet-search", local);
572
+ const showAll = usePart("facet-show-all", local);
573
+ const empty = usePart("facet-empty", local);
574
+ const { t } = useStrings();
575
+ const { query, toggleValue, listQuery } = useShopAll();
576
+ const selected = query.filters[facet.key] ?? [];
577
+ const [expanded, setExpanded] = useState2(false);
578
+ const [needle, setNeedle] = useState2("");
579
+ const full = useFilterValues(expanded && facet.more ? facet.key : null, listQuery);
580
+ const values = withSelected(full.data?.values ?? facet.values, selected);
581
+ const long = values.length > FACET_VALUE_LIMIT || facet.more;
582
+ const q = needle.trim().toLowerCase();
583
+ const shown = q ? values.filter((v) => v.label.toLowerCase().includes(q)) : expanded || !long ? values : [...values.slice(0, FACET_VALUE_LIMIT), ...values.slice(FACET_VALUE_LIMIT).filter((v) => selected.includes(v.value))];
584
+ return /* @__PURE__ */ jsxs2(Fragment, { children: [
585
+ long ? /* @__PURE__ */ jsx3(
586
+ "input",
587
+ {
588
+ ...search,
589
+ type: "search",
590
+ value: needle,
591
+ placeholder: t("shop.searchFacet", { name: facet.label }),
592
+ "aria-label": t("shop.searchFacet", { name: facet.label }),
593
+ onChange: (event) => setNeedle(event.target.value)
594
+ }
595
+ ) : null,
596
+ /* @__PURE__ */ jsxs2("fieldset", { ...fieldset, children: [
597
+ /* @__PURE__ */ jsx3("legend", { ...legend, children: facet.label }),
598
+ /* @__PURE__ */ jsx3("ul", { ...options, children: shown.map((v) => {
599
+ const checked = selected.includes(v.value);
600
+ const swatch = facet.display === "swatch" ? v.swatch : void 0;
601
+ return /* @__PURE__ */ jsx3("li", { ...option, "data-empty": v.count === 0 && !checked ? "" : void 0, children: /* @__PURE__ */ jsxs2("label", { ...optionLabel, children: [
602
+ /* @__PURE__ */ jsx3(
603
+ "input",
604
+ {
605
+ ...input,
606
+ type: "checkbox",
607
+ value: v.value,
608
+ checked,
609
+ disabled: v.count === 0 && !checked,
610
+ onChange: () => toggleValue(facet.key, v.value)
611
+ }
612
+ ),
613
+ swatch ? /* @__PURE__ */ jsx3(
614
+ Swatch,
615
+ {
616
+ ...local,
617
+ value: v.label,
618
+ hex: "color" in swatch ? swatch.color : void 0,
619
+ image: "url" in swatch ? swatch.url : void 0,
620
+ selected: checked
621
+ }
622
+ ) : null,
623
+ /* @__PURE__ */ jsx3("span", { ...text, children: v.label }),
624
+ /* @__PURE__ */ jsx3("span", { ...count, "aria-hidden": "true", children: v.count }),
625
+ /* @__PURE__ */ jsx3(VisuallyHidden, { children: t("shop.valueCount", { count: v.count }) })
626
+ ] }) }, v.value);
627
+ }) })
628
+ ] }),
629
+ q && shown.length === 0 ? /* @__PURE__ */ jsx3("p", { ...empty, children: t("shop.noFacetMatch") }) : null,
630
+ long && !q ? /* @__PURE__ */ jsx3("button", { ...showAll, type: "button", "aria-expanded": expanded, onClick: () => setExpanded(!expanded), children: expanded ? t("shop.showFewer") : t("shop.showAll", { count: values.length }) }) : null
631
+ ] });
632
+ }
633
+ function SelectControl({ facet, local }) {
634
+ const select = usePart("facet-select", local);
635
+ const { t } = useStrings();
636
+ const { query, setValues } = useShopAll();
637
+ const selected = query.filters[facet.key] ?? [];
638
+ const values = withSelected(facet.values, selected);
639
+ return /* @__PURE__ */ jsxs2(
640
+ "select",
641
+ {
642
+ ...select,
643
+ "aria-label": facet.label,
644
+ value: selected[0] ?? "",
645
+ onChange: (event) => setValues(facet.key, event.target.value ? [event.target.value] : []),
646
+ children: [
647
+ /* @__PURE__ */ jsx3("option", { value: "", children: t("shop.any") }),
648
+ values.map((v) => /* @__PURE__ */ jsxs2("option", { value: v.value, disabled: v.count === 0 && !selected.includes(v.value), children: [
649
+ v.label,
650
+ " (",
651
+ v.count,
652
+ ")"
653
+ ] }, v.value))
654
+ ]
655
+ }
656
+ );
657
+ }
658
+ function BooleanControl({ facet, local }) {
659
+ const group = usePart("facet-boolean", local);
660
+ const optionLabel = usePart("facet-option-label", local);
661
+ const input = usePart("facet-option-input", local);
662
+ const text = usePart("facet-option-text", local);
663
+ const count = usePart("facet-option-count", local);
664
+ const { t } = useStrings();
665
+ const { query, setValues } = useShopAll();
666
+ const name = useId();
667
+ const current = query.filters[facet.key]?.[0] ?? "";
668
+ const countOf = (value) => facet.values.find((v) => v.value === value)?.count;
669
+ const choices = [
670
+ { value: "", label: t("shop.any"), count: void 0 },
671
+ { value: "true", label: t("boolean.yes"), count: countOf("true") },
672
+ { value: "false", label: t("boolean.no"), count: countOf("false") }
673
+ ];
674
+ return /* @__PURE__ */ jsx3("div", { ...group, role: "radiogroup", "aria-label": facet.label, children: choices.map((c) => /* @__PURE__ */ jsxs2("label", { ...optionLabel, children: [
675
+ /* @__PURE__ */ jsx3(
676
+ "input",
677
+ {
678
+ ...input,
679
+ type: "radio",
680
+ name,
681
+ value: c.value,
682
+ checked: current === c.value,
683
+ disabled: c.count === 0 && current !== c.value,
684
+ onChange: () => setValues(facet.key, c.value ? [c.value] : [])
685
+ }
686
+ ),
687
+ /* @__PURE__ */ jsx3("span", { ...text, children: c.label }),
688
+ c.count !== void 0 ? /* @__PURE__ */ jsx3("span", { ...count, "aria-hidden": "true", children: c.count }) : null
689
+ ] }, c.value)) });
690
+ }
691
+ function RangeControl({ facet, local }) {
692
+ const form = usePart("facet-range", local);
693
+ const fields = usePart("facet-range-fields", local);
694
+ const field = usePart("facet-range-field", local);
695
+ const input = usePart("facet-range-input", local);
696
+ const error = usePart("facet-range-error", local);
697
+ const hint = usePart("facet-range-hint", local);
698
+ const actions = usePart("facet-range-actions", local);
699
+ const apply = usePart("facet-range-apply", local);
700
+ const clearPart = usePart("facet-range-clear", local);
701
+ const { t } = useStrings();
702
+ const { query, setRange } = useShopAll();
703
+ const id = useId();
704
+ const current = query.ranges[facet.key];
705
+ const [min, setMin] = useState2(current?.min?.toString() ?? "");
706
+ const [max, setMax] = useState2(current?.max?.toString() ?? "");
707
+ const [invalid, setInvalid] = useState2(false);
708
+ const minRef = useRef3(null);
709
+ const maxRef = useRef3(null);
710
+ useEffect3(() => {
711
+ setMin(current?.min?.toString() ?? "");
712
+ setMax(current?.max?.toString() ?? "");
713
+ }, [current?.min, current?.max]);
714
+ const submit = (event) => {
715
+ event.preventDefault();
716
+ if (minRef.current?.validity.badInput || maxRef.current?.validity.badInput) {
717
+ setInvalid(true);
718
+ return;
719
+ }
720
+ setInvalid(false);
721
+ const lo = min.trim() === "" ? void 0 : Number(min);
722
+ const hi = max.trim() === "" ? void 0 : Number(max);
723
+ if (lo !== void 0 && hi !== void 0 && lo > hi) setRange(facet.key, { min: hi, max: lo });
724
+ else setRange(facet.key, { ...lo !== void 0 ? { min: lo } : {}, ...hi !== void 0 ? { max: hi } : {} });
725
+ };
726
+ const bounds = facet.range;
727
+ return /* @__PURE__ */ jsxs2("form", { ...form, onSubmit: submit, noValidate: true, children: [
728
+ /* @__PURE__ */ jsx3("div", { ...fields, children: [
729
+ ["min", min, setMin, minRef, "shop.rangeMin", bounds?.min],
730
+ ["max", max, setMax, maxRef, "shop.rangeMax", bounds?.max]
731
+ ].map(([name, value, set, ref, key, placeholder]) => /* @__PURE__ */ jsxs2("label", { ...field, htmlFor: `${id}-${name}`, children: [
732
+ /* @__PURE__ */ jsx3("span", { children: t(key) }),
733
+ /* @__PURE__ */ jsx3(
734
+ "input",
735
+ {
736
+ ...input,
737
+ ref,
738
+ id: `${id}-${name}`,
739
+ "aria-label": `${facet.label}: ${t(key)}`,
740
+ type: "number",
741
+ inputMode: "numeric",
742
+ placeholder: placeholder === void 0 ? void 0 : String(placeholder),
743
+ value,
744
+ "aria-invalid": invalid || void 0,
745
+ "aria-describedby": invalid ? `${id}-error` : void 0,
746
+ onChange: (event) => set(event.target.value)
747
+ }
748
+ )
749
+ ] }, name)) }),
750
+ invalid ? /* @__PURE__ */ jsx3("p", { ...error, id: `${id}-error`, role: "alert", children: t("shop.rangeInvalid") }) : null,
751
+ bounds ? /* @__PURE__ */ jsx3("p", { ...hint, children: t("shop.rangeBetween", { min: bounds.min, max: bounds.max }) }) : null,
752
+ /* @__PURE__ */ jsxs2("div", { ...actions, children: [
753
+ /* @__PURE__ */ jsx3("button", { ...apply, type: "submit", children: t("filters.apply") }),
754
+ current ? /* @__PURE__ */ jsx3("button", { ...clearPart, type: "button", onClick: () => setRange(facet.key, null), children: t("shop.rangeClear") }) : null
755
+ ] })
756
+ ] });
757
+ }
758
+ function FacetBody({ facet, local }) {
759
+ switch (facet.display) {
760
+ case "range":
761
+ return /* @__PURE__ */ jsx3(RangeControl, { facet, local });
762
+ case "boolean":
763
+ return /* @__PURE__ */ jsx3(BooleanControl, { facet, local });
764
+ case "dropdown":
765
+ return /* @__PURE__ */ jsx3(SelectControl, { facet, local });
766
+ default:
767
+ return /* @__PURE__ */ jsx3(OptionList, { facet, local });
768
+ }
769
+ }
770
+ function DropdownFacet({ facet, local, name }) {
771
+ const root = usePart("facet", local);
772
+ const trigger = usePart("facet-trigger", local);
773
+ const panel = usePart("facet-panel", local);
774
+ const [open, setOpen] = useState2(false);
775
+ const rootRef = useRef3(null);
776
+ const triggerRef = useRef3(null);
777
+ const panelId = useId();
778
+ useEffect3(() => {
779
+ if (!open) return;
780
+ const onDown = (event) => {
781
+ if (rootRef.current && !rootRef.current.contains(event.target)) setOpen(false);
782
+ };
783
+ const onKey = (event) => {
784
+ if (event.key !== "Escape") return;
785
+ setOpen(false);
786
+ triggerRef.current?.focus();
787
+ };
788
+ document.addEventListener("mousedown", onDown);
789
+ document.addEventListener("keydown", onKey);
790
+ return () => {
791
+ document.removeEventListener("mousedown", onDown);
792
+ document.removeEventListener("keydown", onKey);
793
+ };
794
+ }, [open]);
795
+ return /* @__PURE__ */ jsxs2("div", { ...root, ref: rootRef, "data-filter-key": facet.key, "data-filter-display": facet.display, "data-presentation": "dropdown", children: [
796
+ /* @__PURE__ */ jsxs2(
797
+ "button",
798
+ {
799
+ ...trigger,
800
+ ref: triggerRef,
801
+ type: "button",
802
+ "aria-expanded": open,
803
+ "aria-controls": open ? panelId : void 0,
804
+ onClick: () => setOpen(!open),
805
+ children: [
806
+ name,
807
+ /* @__PURE__ */ jsx3(Icon2, { name: open ? "chevron-up" : "chevron-down", size: 16 })
808
+ ]
809
+ }
810
+ ),
811
+ open ? /* @__PURE__ */ jsx3("div", { ...panel, id: panelId, role: "group", "aria-label": facet.label, children: /* @__PURE__ */ jsx3(FacetBody, { facet, local }) }) : null
812
+ ] });
813
+ }
814
+ function FacetGroup({ facet, presentation = "section", classNames, unstyled }) {
815
+ const local = { classNames, unstyled };
816
+ const root = usePart("facet", local);
817
+ const heading = usePart("facet-heading", local);
818
+ const toggle = usePart("facet-toggle", local);
819
+ const label = usePart("facet-label", local);
820
+ const badge = usePart("facet-selected", local);
821
+ const body = usePart("facet-body", local);
822
+ const { t } = useStrings();
823
+ const { query } = useShopAll();
824
+ const [open, setOpen] = useState2(true);
825
+ const bodyId = useId();
826
+ const selectedCount = (query.filters[facet.key]?.length ?? 0) + (query.ranges[facet.key] ? 1 : 0);
827
+ const name = /* @__PURE__ */ jsxs2(Fragment, { children: [
828
+ /* @__PURE__ */ jsx3("span", { ...label, "data-filter-label": "", children: facet.label }),
829
+ selectedCount > 0 ? /* @__PURE__ */ jsxs2("span", { ...badge, children: [
830
+ /* @__PURE__ */ jsx3("span", { "aria-hidden": "true", children: selectedCount }),
831
+ /* @__PURE__ */ jsx3(VisuallyHidden, { children: t("shop.selectedCount", { count: selectedCount }) })
832
+ ] }) : null
833
+ ] });
834
+ if (presentation === "dropdown") {
835
+ return /* @__PURE__ */ jsx3(DropdownFacet, { facet, local, name });
836
+ }
837
+ return /* @__PURE__ */ jsxs2("section", { ...root, "data-filter-key": facet.key, "data-filter-display": facet.display, "data-presentation": "section", children: [
838
+ /* @__PURE__ */ jsx3("h3", { ...heading, children: /* @__PURE__ */ jsxs2("button", { ...toggle, type: "button", "aria-expanded": open, "aria-controls": bodyId, onClick: () => setOpen(!open), children: [
839
+ name,
840
+ /* @__PURE__ */ jsx3(Icon2, { name: open ? "chevron-up" : "chevron-down", size: 16 })
841
+ ] }) }),
842
+ /* @__PURE__ */ jsx3("div", { ...body, id: bodyId, hidden: !open, children: /* @__PURE__ */ jsx3(FacetBody, { facet, local }) })
843
+ ] });
844
+ }
845
+
846
+ // src/shop/FilterDrawer.tsx
847
+ import { Drawer, Icon as Icon3 } from "@usethrottle/ui";
848
+ import { useId as useId2, useRef as useRef4, useState as useState3 } from "react";
849
+ import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
850
+ function FilterPanel({
851
+ open,
852
+ onClose,
853
+ facets,
854
+ title,
855
+ restoreFocusTo,
856
+ container,
857
+ ...local
858
+ }) {
859
+ const head = usePart("filter-drawer-head", local);
860
+ const titlePart = usePart("filter-drawer-title", local);
861
+ const close = usePart("filter-drawer-close", local);
862
+ const body = usePart("filter-drawer-body", local);
863
+ const foot = usePart("filter-drawer-foot", local);
864
+ const apply = usePart("filter-drawer-apply", local);
865
+ const clearPart = usePart("filter-clear", local);
866
+ const { t } = useStrings();
867
+ const { status, total, selectedCount, clear } = useShopAll();
868
+ const titleId = useId2();
869
+ return /* @__PURE__ */ jsxs3(Drawer, { open, onClose, labelledBy: titleId, restoreFocusTo, container, children: [
870
+ /* @__PURE__ */ jsxs3("div", { ...head, children: [
871
+ /* @__PURE__ */ jsx4("h2", { ...titlePart, id: titleId, children: title }),
872
+ /* @__PURE__ */ jsx4("button", { ...close, type: "button", "aria-label": t("shop.closeFilters"), onClick: onClose, children: /* @__PURE__ */ jsx4(Icon3, { name: "close", size: 20 }) })
873
+ ] }),
874
+ /* @__PURE__ */ jsx4("div", { ...body, children: facets.map((facet) => /* @__PURE__ */ jsx4(FacetGroup, { facet, ...local }, facet.key)) }),
875
+ /* @__PURE__ */ jsxs3("div", { ...foot, children: [
876
+ selectedCount > 0 ? /* @__PURE__ */ jsx4("button", { ...clearPart, type: "button", onClick: () => clear(), children: t("filters.clearAll") }) : null,
877
+ /* @__PURE__ */ jsx4("button", { ...apply, type: "button", onClick: onClose, children: status === "ready" && total !== void 0 ? t("shop.showResults", { count: total }) : t("shop.showResultsLoading") })
878
+ ] })
879
+ ] });
880
+ }
881
+ function FilterDrawer(local) {
882
+ const trigger = usePart("filter-drawer-trigger", local);
883
+ const count = usePart("filter-drawer-count", local);
884
+ const { t } = useStrings();
885
+ const { facets, query, selectedCount, filterLayout } = useShopAll();
886
+ const [open, setOpen] = useState3(false);
887
+ const [container, setContainer] = useState3(null);
888
+ const opener = useRef4(null);
889
+ const shown = visibleFacets(facets, query);
890
+ if (shown.length === 0) return null;
891
+ return /* @__PURE__ */ jsxs3(Fragment2, { children: [
892
+ /* @__PURE__ */ jsxs3(
893
+ "button",
894
+ {
895
+ ...trigger,
896
+ ref: opener,
897
+ type: "button",
898
+ "aria-haspopup": "dialog",
899
+ "data-phone-only": filterLayout === "drawer" ? void 0 : "",
900
+ onClick: () => {
901
+ setContainer(opener.current?.closest(".tsf-root") ?? null);
902
+ setOpen(true);
903
+ },
904
+ children: [
905
+ /* @__PURE__ */ jsx4(Icon3, { name: "filter", size: 18 }),
906
+ /* @__PURE__ */ jsx4("span", { children: t("filters.title") }),
907
+ selectedCount > 0 ? /* @__PURE__ */ jsx4("span", { ...count, children: selectedCount }) : null
908
+ ]
909
+ }
910
+ ),
911
+ /* @__PURE__ */ jsx4(
912
+ FilterPanel,
913
+ {
914
+ open,
915
+ onClose: () => setOpen(false),
916
+ container,
917
+ restoreFocusTo: opener.current,
918
+ facets: shown,
919
+ title: t("filters.title"),
920
+ classNames: local.classNames,
921
+ unstyled: local.unstyled
922
+ }
923
+ )
924
+ ] });
925
+ }
926
+
927
+ // src/shop/FilterBar.tsx
928
+ import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
929
+ var FILTER_BAR_INLINE = 4;
930
+ function FilterBar(local) {
931
+ const root = usePart("filter-bar", local);
932
+ const more = usePart("filter-bar-more", local);
933
+ const { t } = useStrings();
934
+ const { facets, query } = useShopAll();
935
+ const [open, setOpen] = useState4(false);
936
+ const [container, setContainer] = useState4(null);
937
+ const opener = useRef5(null);
938
+ const shown = visibleFacets(facets, query);
939
+ if (shown.length === 0) return null;
940
+ const inline = shown.slice(0, FILTER_BAR_INLINE);
941
+ const rest = shown.slice(FILTER_BAR_INLINE);
942
+ return /* @__PURE__ */ jsxs4("div", { ...root, role: "group", "aria-label": t("filters.title"), children: [
943
+ inline.map((facet) => /* @__PURE__ */ jsx5(FacetGroup, { facet, presentation: "dropdown", classNames: local.classNames, unstyled: local.unstyled }, facet.key)),
944
+ rest.length > 0 ? /* @__PURE__ */ jsxs4(Fragment3, { children: [
945
+ /* @__PURE__ */ jsx5(
946
+ "button",
947
+ {
948
+ ...more,
949
+ ref: opener,
950
+ type: "button",
951
+ "aria-haspopup": "dialog",
952
+ onClick: () => {
953
+ setContainer(opener.current?.closest(".tsf-root") ?? null);
954
+ setOpen(true);
955
+ },
956
+ children: t("shop.moreFilters")
957
+ }
958
+ ),
959
+ /* @__PURE__ */ jsx5(
960
+ FilterPanel,
961
+ {
962
+ open,
963
+ onClose: () => setOpen(false),
964
+ container,
965
+ restoreFocusTo: opener.current,
966
+ facets: rest,
967
+ title: t("shop.moreFilters"),
968
+ classNames: local.classNames,
969
+ unstyled: local.unstyled
970
+ }
971
+ )
972
+ ] }) : null
973
+ ] });
974
+ }
975
+
976
+ // src/shop/FilterSidebar.tsx
977
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
978
+ function FilterSidebar(local) {
979
+ const root = usePart("filter-sidebar", local);
980
+ const head = usePart("filter-sidebar-head", local);
981
+ const title = usePart("filter-sidebar-title", local);
982
+ const clearPart = usePart("filter-clear", local);
983
+ const { t, keyAttr } = useStrings();
984
+ const { facets, query, selectedCount, clear } = useShopAll();
985
+ const shown = visibleFacets(facets, query);
986
+ if (shown.length === 0) return null;
987
+ return /* @__PURE__ */ jsxs5("aside", { ...root, "aria-label": t("filters.title"), children: [
988
+ /* @__PURE__ */ jsxs5("div", { ...head, children: [
989
+ /* @__PURE__ */ jsx6("h2", { ...title, ...keyAttr("filters.title"), children: t("filters.title") }),
990
+ selectedCount > 0 ? /* @__PURE__ */ jsx6("button", { ...clearPart, type: "button", onClick: () => clear(), children: t("filters.clearAll") }) : null
991
+ ] }),
992
+ shown.map((facet) => /* @__PURE__ */ jsx6(FacetGroup, { facet, classNames: local.classNames, unstyled: local.unstyled }, facet.key))
993
+ ] });
994
+ }
995
+
996
+ // src/shop/LiveRegion.tsx
997
+ import { useEffect as useEffect4, useRef as useRef6, useState as useState5 } from "react";
998
+ import { jsx as jsx7 } from "react/jsx-runtime";
999
+ function LiveRegion(local) {
1000
+ const part = usePart("live-region", local);
1001
+ const { status, total, data, announceKey } = useShopAll();
1002
+ const { t } = useStrings();
1003
+ const [message, setMessage] = useState5("");
1004
+ const seen = useRef6(null);
1005
+ const count = total ?? data?.products.length ?? 0;
1006
+ useEffect4(() => {
1007
+ if (status !== "ready" || seen.current === announceKey) return;
1008
+ const first = seen.current === null;
1009
+ seen.current = announceKey;
1010
+ if (!first) setMessage(t("shop.resultsAnnounce", { count }));
1011
+ }, [status, announceKey, count, t]);
1012
+ return /* @__PURE__ */ jsx7("div", { ...part, role: "status", "aria-live": "polite", "aria-atomic": "true", children: message });
1013
+ }
1014
+
1015
+ // src/shop/Pagination.tsx
1016
+ import { Icon as Icon4, VisuallyHidden as VisuallyHidden2 } from "@usethrottle/ui";
1017
+ import { useEffect as useEffect5, useRef as useRef7 } from "react";
1018
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
1019
+ var plainClick = (event) => !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0);
1020
+ function Numbered(local) {
1021
+ const nav = usePart("pagination", local);
1022
+ const list = usePart("pagination-list", local);
1023
+ const item = usePart("pagination-item", local);
1024
+ const link = usePart("pagination-link", local);
1025
+ const step = usePart("pagination-step", local);
1026
+ const gap = usePart("pagination-gap", local);
1027
+ const { t } = useStrings();
1028
+ const { query, pageCount, hrefFor, setPage } = useShopAll();
1029
+ if (pageCount <= 1) return null;
1030
+ const current = Math.min(query.page, pageCount);
1031
+ const follow = (page) => (event) => {
1032
+ if (!plainClick(event)) return;
1033
+ event.preventDefault();
1034
+ setPage(page);
1035
+ };
1036
+ const stepLink = (page, rel) => {
1037
+ const label = rel === "prev" ? t("listing.previous") : t("listing.next");
1038
+ const icon = /* @__PURE__ */ jsx8(Icon4, { name: rel === "prev" ? "chevron-left" : "chevron-right", size: 18 });
1039
+ return page >= 1 && page <= pageCount ? /* @__PURE__ */ jsx8("a", { ...step, href: hrefFor({ ...query, page }), rel, "aria-label": label, onClick: follow(page), children: icon }) : /* @__PURE__ */ jsx8("span", { ...step, "aria-hidden": "true", "data-disabled": "", children: icon });
1040
+ };
1041
+ return /* @__PURE__ */ jsx8("nav", { ...nav, "aria-label": t("shop.paginationLabel"), "data-style": "numbered", children: /* @__PURE__ */ jsxs6("ol", { ...list, children: [
1042
+ /* @__PURE__ */ jsx8("li", { ...item, children: stepLink(current - 1, "prev") }),
1043
+ pageWindow(current, pageCount).map(
1044
+ (page, index) => page === null ? /* @__PURE__ */ jsx8("li", { ...item, children: /* @__PURE__ */ jsx8("span", { ...gap, "aria-hidden": "true", children: "\u2026" }) }, `gap-${index}`) : /* @__PURE__ */ jsx8("li", { ...item, children: /* @__PURE__ */ jsx8(
1045
+ "a",
1046
+ {
1047
+ ...link,
1048
+ href: hrefFor({ ...query, page }),
1049
+ "aria-label": t("shop.pageLabel", { page }),
1050
+ "aria-current": page === current ? "page" : void 0,
1051
+ onClick: follow(page),
1052
+ children: page
1053
+ }
1054
+ ) }, page)
1055
+ ),
1056
+ /* @__PURE__ */ jsx8("li", { ...item, children: stepLink(current + 1, "next") })
1057
+ ] }) });
1058
+ }
1059
+ function More(local) {
1060
+ const nav = usePart("pagination", local);
1061
+ const link = usePart("pagination-link", local);
1062
+ const more = usePart("pagination-more", local);
1063
+ const crawl = usePart("pagination-crawl", local);
1064
+ const { t } = useStrings();
1065
+ const { query, pageCount, hrefFor, loadMore, status, pagination, firstLoadedPage: first } = useShopAll();
1066
+ const sentinel = useRef7(null);
1067
+ const asked = useRef7(null);
1068
+ const hasNext = query.page < pageCount;
1069
+ const infinite = pagination === "infinite";
1070
+ useEffect5(() => {
1071
+ const node = sentinel.current;
1072
+ if (!infinite || !hasNext || status !== "ready" || !node || typeof IntersectionObserver === "undefined") return;
1073
+ const observer = new IntersectionObserver(
1074
+ (entries) => {
1075
+ if (!entries.some((e) => e.isIntersecting) || asked.current === query.page) return;
1076
+ asked.current = query.page;
1077
+ loadMore();
1078
+ },
1079
+ { rootMargin: "400px" }
1080
+ );
1081
+ observer.observe(node);
1082
+ return () => observer.disconnect();
1083
+ }, [infinite, hasNext, status, query.page, loadMore]);
1084
+ if (!hasNext && first === 1) return null;
1085
+ return /* @__PURE__ */ jsxs6("nav", { ...nav, "aria-label": t("shop.paginationLabel"), "data-style": pagination, children: [
1086
+ first > 1 ? /* @__PURE__ */ jsx8("a", { ...link, rel: "prev", href: hrefFor({ ...query, page: first - 1 }), children: t("listing.previous") }) : null,
1087
+ hasNext && !infinite ? /* @__PURE__ */ jsx8("button", { ...more, type: "button", "aria-disabled": status !== "ready" || void 0, onClick: () => status === "ready" && loadMore(), children: status === "ready" ? t("listing.loadMore") : t("listing.loading") }) : null,
1088
+ hasNext && infinite ? /* @__PURE__ */ jsx8("div", { ref: sentinel, "aria-hidden": "true", "data-sentinel": "" }) : null,
1089
+ hasNext ? /* @__PURE__ */ jsx8("a", { ...crawl, rel: "next", href: hrefFor({ ...query, page: query.page + 1 }), tabIndex: -1, "aria-hidden": "true", children: /* @__PURE__ */ jsx8(VisuallyHidden2, { children: t("listing.next") }) }) : null
1090
+ ] });
1091
+ }
1092
+ function Pagination(local) {
1093
+ const { pagination } = useShopAll();
1094
+ return pagination === "numbered" ? /* @__PURE__ */ jsx8(Numbered, { ...local }) : /* @__PURE__ */ jsx8(More, { ...local });
1095
+ }
1096
+
1097
+ // src/shop/ProductGrid.tsx
1098
+ import { useProducts as useProducts2 } from "@usethrottle/catalog/react";
1099
+ import { VisuallyHidden as VisuallyHidden3 } from "@usethrottle/ui";
1100
+ import { useEffect as useEffect6 } from "react";
1101
+ import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1102
+ function useColumns() {
1103
+ const { columns } = useShopAll();
1104
+ return { "--tsf-cols-desktop": columns.desktop, "--tsf-cols-mobile": columns.mobile };
1105
+ }
1106
+ function Cards({ answer, previous, local }) {
1107
+ const grid = usePart("product-grid", local);
1108
+ const item = usePart("product-grid-item", local);
1109
+ const { cardVariant, cardMeta, listName, generatedAt, reviewsOnLists, selectProduct } = useShopAll();
1110
+ const style = useColumns();
1111
+ const offset = (answer.page.number - 1) * answer.page.limit;
1112
+ return /* @__PURE__ */ jsx9("ul", { ...grid, style, "data-page": answer.page.number, "data-previous": previous ? "" : void 0, "aria-busy": previous || void 0, children: answer.products.map((product, i) => /* @__PURE__ */ jsx9("li", { ...item, children: /* @__PURE__ */ jsx9(
1113
+ ProductCard,
1114
+ {
1115
+ ...local,
1116
+ product,
1117
+ variant: cardVariant,
1118
+ meta: cardMeta,
1119
+ position: offset + i,
1120
+ listName,
1121
+ generatedAt,
1122
+ priceContext: answer.priceContext,
1123
+ reviewsOnLists,
1124
+ onSelect: (p) => selectProduct(p, offset + i)
1125
+ }
1126
+ ) }, `${answer.page.number}:${product.handle}:${i}`)) });
1127
+ }
1128
+ function Skeleton({ count, local }) {
1129
+ const grid = usePart("product-grid-skeleton", local);
1130
+ const item = usePart("product-grid-skeleton-item", local);
1131
+ const { t } = useStrings();
1132
+ const style = useColumns();
1133
+ return /* @__PURE__ */ jsxs7(Fragment4, { children: [
1134
+ /* @__PURE__ */ jsx9("ul", { ...grid, style, "aria-hidden": "true", children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx9("li", { ...item }, i)) }),
1135
+ /* @__PURE__ */ jsx9(VisuallyHidden3, { children: t("shop.loadingProducts") })
1136
+ ] });
1137
+ }
1138
+ function EarlierSegment({ segment, local }) {
1139
+ const { settings } = useStorefront();
1140
+ const { reportReady } = useShopAll();
1141
+ const { t } = useStrings();
1142
+ const error = usePart("product-grid-error", local);
1143
+ const retry = usePart("product-grid-retry", local);
1144
+ const result = useProducts2(segment.query, { initialData: segment.seed });
1145
+ const settled = result.data !== void 0 || result.error !== void 0;
1146
+ useEffect6(() => {
1147
+ if (settled) reportReady(segment.key);
1148
+ }, [settled, reportReady, segment.key]);
1149
+ if (result.data) return /* @__PURE__ */ jsx9(Cards, { answer: result.data, local });
1150
+ if (result.error) {
1151
+ return /* @__PURE__ */ jsxs7("div", { ...error, role: "alert", children: [
1152
+ /* @__PURE__ */ jsx9("p", { children: t("shop.errorLoading") }),
1153
+ /* @__PURE__ */ jsx9("button", { ...retry, type: "button", onClick: () => void result.refetch(), children: t("shop.retry") })
1154
+ ] });
1155
+ }
1156
+ return /* @__PURE__ */ jsx9(Skeleton, { count: Math.min(settings.listing.pageSize, 8), local });
1157
+ }
1158
+ function ProductGrid(local) {
1159
+ const pages = usePart("product-grid-pages", local);
1160
+ const empty = usePart("product-grid-empty", local);
1161
+ const error = usePart("product-grid-error", local);
1162
+ const retry = usePart("product-grid-retry", local);
1163
+ const clearPart = usePart("filter-clear", local);
1164
+ const { settings } = useStorefront();
1165
+ const { t } = useStrings();
1166
+ const { status, data, isPrevious, pagination, source, selectedCount, total, clear, refetch, earlier } = useShopAll();
1167
+ const sub = { classNames: local.classNames, unstyled: local.unstyled };
1168
+ const loadMode = pagination !== "numbered";
1169
+ if (!data && status === "error") {
1170
+ return /* @__PURE__ */ jsxs7("div", { ...error, role: "alert", children: [
1171
+ /* @__PURE__ */ jsx9("p", { children: t("shop.errorLoading") }),
1172
+ /* @__PURE__ */ jsx9("button", { ...retry, type: "button", onClick: refetch, children: t("shop.retry") })
1173
+ ] });
1174
+ }
1175
+ const skeleton = Math.min(settings.listing.pageSize, 8);
1176
+ const current = data && !(loadMode && isPrevious) ? data : void 0;
1177
+ if (!current && earlier.length === 0) return /* @__PURE__ */ jsx9(Skeleton, { count: skeleton, local: sub });
1178
+ if (data && !isPrevious && data.products.length === 0 && earlier.length === 0) {
1179
+ const pastEnd = (total ?? 0) > 0;
1180
+ const message = pastEnd ? t("shop.pastEnd") : selectedCount > 0 ? t("empty.listing") : source.kind === "collection" ? t("empty.collection") : source.kind === "category" ? t("empty.category") : source.kind === "search" ? t("empty.search") : t("empty.listing");
1181
+ return /* @__PURE__ */ jsxs7("div", { ...empty, children: [
1182
+ /* @__PURE__ */ jsx9("p", { children: message }),
1183
+ selectedCount > 0 ? /* @__PURE__ */ jsx9("button", { ...clearPart, type: "button", onClick: () => clear(), children: t("filters.clearAll") }) : null
1184
+ ] });
1185
+ }
1186
+ return /* @__PURE__ */ jsxs7("div", { ...pages, "data-pagination": pagination, children: [
1187
+ earlier.map((segment) => /* @__PURE__ */ jsx9(EarlierSegment, { segment, local: sub }, segment.key)),
1188
+ current ? /* @__PURE__ */ jsx9(Cards, { answer: current, previous: isPrevious, local: sub }) : /* @__PURE__ */ jsx9(Skeleton, { count: skeleton, local: sub })
1189
+ ] });
1190
+ }
1191
+
1192
+ // src/shop/ResultCount.tsx
1193
+ import { jsx as jsx10 } from "react/jsx-runtime";
1194
+ function ResultCount(local) {
1195
+ const part = usePart("result-count", local);
1196
+ const { total } = useShopAll();
1197
+ const { t } = useStrings();
1198
+ if (total === void 0) return null;
1199
+ return /* @__PURE__ */ jsx10("p", { ...part, children: total === 1 ? t("shop.countOne", { count: total }) : t("listing.count", { count: total }) });
1200
+ }
1201
+
1202
+ // src/shop/SortSelect.tsx
1203
+ import { useId as useId3 } from "react";
1204
+ import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
1205
+ function SortSelect(local) {
1206
+ const root = usePart("sort-select", local);
1207
+ const label = usePart("sort-select-label", local);
1208
+ const input = usePart("sort-select-input", local);
1209
+ const id = useId3();
1210
+ const { settings } = useStorefront();
1211
+ const { t, keyAttr } = useStrings();
1212
+ const { query, data, isPrevious, setSort, manualCollection } = useShopAll();
1213
+ const options = settings.listing.sorts.filter(
1214
+ (s) => s.enabled && (s.key !== "relevance" || Boolean(query.q)) && (s.key !== "manual" || manualCollection)
1215
+ );
1216
+ if (options.length === 0) return null;
1217
+ const applied = query.sort !== settings.listing.defaultSort ? query.sort : !isPrevious && data ? data.sort : query.sort;
1218
+ const value = options.some((o) => o.key === applied) ? applied : options[0].key;
1219
+ return /* @__PURE__ */ jsxs8("div", { ...root, children: [
1220
+ /* @__PURE__ */ jsx11("label", { ...label, ...keyAttr("sort.label"), htmlFor: id, children: t("sort.label") }),
1221
+ /* @__PURE__ */ jsx11("select", { ...input, id, value, onChange: (event) => setSort(event.target.value), children: options.map((o) => /* @__PURE__ */ jsx11("option", { value: o.key, "data-sort-option": o.key, children: o.label || o.key }, o.key)) })
1222
+ ] });
1223
+ }
1224
+
1225
+ // src/shop/ShopAll.tsx
1226
+ import { Fragment as Fragment5, jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
1227
+ function Root({ children, className, classNames, unstyled, ...options }) {
1228
+ const { settings } = useStorefront();
1229
+ const filterLayout = options.filterLayout ?? settings.listing.filterLayout;
1230
+ const pagination = options.pagination ?? settings.listing.pagination;
1231
+ const columns = options.columns ?? settings.listing.columns;
1232
+ const state = useShopAllState({ source: options.source, initialData: options.initialData, pagination });
1233
+ const part = usePart("shop-all", { classNames, className, unstyled });
1234
+ const { cardVariant, cardMeta, baseUrl = "", jsonLd = true } = options;
1235
+ const value = useMemo2(
1236
+ () => ({
1237
+ ...state,
1238
+ filterLayout,
1239
+ pagination,
1240
+ columns: { desktop: columns.desktop, mobile: columns.mobile },
1241
+ ...cardVariant ? { cardVariant } : {},
1242
+ ...cardMeta ? { cardMeta } : {},
1243
+ baseUrl,
1244
+ jsonLd
1245
+ }),
1246
+ [state, filterLayout, pagination, columns.desktop, columns.mobile, cardVariant, cardMeta, baseUrl, jsonLd]
1247
+ );
1248
+ return /* @__PURE__ */ jsx12(ShopAllContext.Provider, { value, children: /* @__PURE__ */ jsxs9(
1249
+ "div",
1250
+ {
1251
+ ...part,
1252
+ ref: state.topRef,
1253
+ "data-listing": "",
1254
+ "data-listing-page-size": settings.listing.pageSize,
1255
+ "data-filter-layout": filterLayout,
1256
+ "data-pagination": pagination,
1257
+ "data-source": options.source.kind,
1258
+ children: [
1259
+ children,
1260
+ /* @__PURE__ */ jsx12(LiveRegion, { classNames, unstyled }),
1261
+ /* @__PURE__ */ jsx12(ShopJsonLd, {})
1262
+ ]
1263
+ }
1264
+ ) });
1265
+ }
1266
+ function useListingContext() {
1267
+ const { source, total, query } = useShopAll();
1268
+ return {
1269
+ kind: "listing",
1270
+ listing: { source, total: total ?? 0, filters: query.filters, sort: query.sort, page: query.page }
1271
+ };
1272
+ }
1273
+ function SlotAbove() {
1274
+ return /* @__PURE__ */ jsx12(SlotOutlet, { name: "shop.above", context: useListingContext() });
1275
+ }
1276
+ function SlotBelow() {
1277
+ return /* @__PURE__ */ jsx12(SlotOutlet, { name: "shop.below", context: useListingContext() });
1278
+ }
1279
+ function ShopJsonLd() {
1280
+ const { settings } = useStorefront();
1281
+ const { jsonLd, baseUrl, data, isPrevious, query, breadcrumbs } = useShopAll();
1282
+ if (!jsonLd) return null;
1283
+ const origin = baseUrl.replace(/\/+$/u, "");
1284
+ const products = data && !isPrevious ? data.products : [];
1285
+ const first = ((data?.page.number ?? query.page) - 1) * (data?.page.limit ?? settings.listing.pageSize) + 1;
1286
+ const list = itemListJsonLd(products, { baseUrl, settings });
1287
+ return /* @__PURE__ */ jsxs9(Fragment5, { children: [
1288
+ products.length > 0 ? /* @__PURE__ */ jsx12(JsonLd, { data: { ...list, itemListElement: list.itemListElement.map((e, i) => ({ ...e, position: first + i })) } }) : null,
1289
+ breadcrumbs.length > 0 ? /* @__PURE__ */ jsx12(JsonLd, { data: breadcrumbJsonLd(breadcrumbs.map((c) => ({ name: c.name, url: `${origin}${c.href}` }))) }) : null
1290
+ ] });
1291
+ }
1292
+ function Breadcrumbs2(local) {
1293
+ const root = usePart("shop-all-breadcrumbs", local);
1294
+ const list = usePart("shop-all-breadcrumb-list", local);
1295
+ const item = usePart("shop-all-breadcrumb", local);
1296
+ const link = usePart("shop-all-breadcrumb-link", local);
1297
+ const { Link: Link2 } = useStorefront();
1298
+ const { t } = useStrings();
1299
+ const { breadcrumbs } = useShopAll();
1300
+ if (breadcrumbs.length === 0) return null;
1301
+ return /* @__PURE__ */ jsx12("nav", { ...root, "aria-label": t("shop.breadcrumbs"), children: /* @__PURE__ */ jsx12("ol", { ...list, children: breadcrumbs.map((crumb, i) => /* @__PURE__ */ jsx12("li", { ...item, children: i === breadcrumbs.length - 1 ? /* @__PURE__ */ jsx12("span", { "aria-current": "page", children: crumb.name }) : /* @__PURE__ */ jsx12(Link2, { ...link, href: crumb.href, children: crumb.name }) }, crumb.href)) }) });
1302
+ }
1303
+ function Heading(local) {
1304
+ const heading = usePart("shop-all-heading", local);
1305
+ const description = usePart("shop-all-description", local);
1306
+ const { t, keyAttr } = useStrings();
1307
+ const { source, title, description: text } = useShopAll();
1308
+ return /* @__PURE__ */ jsxs9(Fragment5, { children: [
1309
+ source.kind === "all" ? /* @__PURE__ */ jsx12("h1", { ...heading, ...keyAttr("shop.title"), children: t("shop.title") }) : /* @__PURE__ */ jsx12("h1", { ...heading, "data-collection-title": source.kind === "collection" ? "" : void 0, children: title }),
1310
+ text ? /* @__PURE__ */ jsx12("p", { ...description, children: text }) : null
1311
+ ] });
1312
+ }
1313
+ function DefaultLayout(local) {
1314
+ const controls = usePart("shop-all-controls", local);
1315
+ const tools = usePart("shop-all-tools", local);
1316
+ const body = usePart("shop-all-body", local);
1317
+ const main = usePart("shop-all-main", local);
1318
+ const { filterLayout } = useShopAll();
1319
+ return /* @__PURE__ */ jsxs9(Fragment5, { children: [
1320
+ /* @__PURE__ */ jsx12(Breadcrumbs2, { ...local }),
1321
+ /* @__PURE__ */ jsx12(Heading, { ...local }),
1322
+ /* @__PURE__ */ jsx12(SlotAbove, {}),
1323
+ /* @__PURE__ */ jsxs9("div", { ...controls, children: [
1324
+ /* @__PURE__ */ jsx12(ResultCount, { ...local }),
1325
+ /* @__PURE__ */ jsxs9("div", { ...tools, children: [
1326
+ /* @__PURE__ */ jsx12(FilterDrawer, { ...local }),
1327
+ /* @__PURE__ */ jsx12(SortSelect, { ...local })
1328
+ ] })
1329
+ ] }),
1330
+ filterLayout === "topbar" ? /* @__PURE__ */ jsx12(FilterBar, { ...local }) : null,
1331
+ /* @__PURE__ */ jsx12(ActiveFilters, { ...local }),
1332
+ /* @__PURE__ */ jsxs9("div", { ...body, "data-layout": filterLayout, children: [
1333
+ filterLayout === "sidebar" ? /* @__PURE__ */ jsx12(FilterSidebar, { ...local }) : null,
1334
+ /* @__PURE__ */ jsxs9("div", { ...main, children: [
1335
+ /* @__PURE__ */ jsx12(ProductGrid, { ...local }),
1336
+ /* @__PURE__ */ jsx12(Pagination, { ...local })
1337
+ ] })
1338
+ ] }),
1339
+ /* @__PURE__ */ jsx12(SlotBelow, {})
1340
+ ] });
1341
+ }
1342
+ function ShopAllPage({ children, ...props }) {
1343
+ const local = { classNames: props.classNames, unstyled: props.unstyled };
1344
+ return /* @__PURE__ */ jsx12(Root, { ...props, children: children ?? /* @__PURE__ */ jsx12(DefaultLayout, { ...local }) });
1345
+ }
1346
+ var ShopAll = Object.assign(ShopAllPage, {
1347
+ Root,
1348
+ Heading,
1349
+ Breadcrumbs: Breadcrumbs2,
1350
+ FilterSidebar,
1351
+ FilterBar,
1352
+ FilterDrawer,
1353
+ ActiveFilters,
1354
+ SortSelect,
1355
+ ResultCount,
1356
+ ProductGrid,
1357
+ Pagination,
1358
+ SlotAbove,
1359
+ SlotBelow
1360
+ });
1361
+
1362
+ // src/shopper/CartDrawer.tsx
1363
+ import { lazy, Suspense, useState as useState6 } from "react";
1364
+ import { jsx as jsx13 } from "react/jsx-runtime";
1365
+ var CartPanel = lazy(() => import("./chunk-ISDATHVC.js").then((m) => ({ default: m.CartDrawerBody })));
1366
+ function CartDrawer({ inline, ...local }) {
1367
+ const { open } = useCartDrawer();
1368
+ const [wanted, setWanted] = useState6(false);
1369
+ if (open && !wanted) setWanted(true);
1370
+ if (!inline && !wanted) return null;
1371
+ return /* @__PURE__ */ jsx13(Suspense, { fallback: null, children: /* @__PURE__ */ jsx13(CartPanel, { inline, ...local }) });
1372
+ }
1373
+
1374
+ // src/frame/AnnouncementBar.tsx
1375
+ import { Icon as Icon5 } from "@usethrottle/ui";
1376
+ import { useSyncExternalStore } from "react";
1377
+
1378
+ // src/frame/menu.ts
1379
+ var KINDS = /* @__PURE__ */ new Set(["category", "collection", "product", "page", "search", "url"]);
1380
+ var SAFE_SCHEME = /^(https?|mailto|tel):/i;
1381
+ var ANY_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
1382
+ var MAX_DEPTH = 4;
1383
+ function safeHref(href) {
1384
+ if (typeof href !== "string") return null;
1385
+ const bare = href.replace(/[\p{Cc}\s]/gu, "");
1386
+ if (bare === "") return null;
1387
+ if (SAFE_SCHEME.test(bare)) return href.trim();
1388
+ if (ANY_SCHEME.test(bare)) return null;
1389
+ return href.trim();
1390
+ }
1391
+ function cleanMenuItems(items, depth = 0) {
1392
+ if (!Array.isArray(items) || depth >= MAX_DEPTH) return [];
1393
+ return items.flatMap((item) => {
1394
+ if (typeof item !== "object" || item === null) return [];
1395
+ const { label, href, kind, handle, children } = item;
1396
+ if (typeof label !== "string" || label.trim() === "") return [];
1397
+ const link = safeHref(href);
1398
+ if (link === null) return [];
1399
+ if (children !== void 0 && !Array.isArray(children)) return [];
1400
+ const out = { label, href: link };
1401
+ if (typeof kind === "string" && KINDS.has(kind)) out.kind = kind;
1402
+ if (typeof handle === "string") out.handle = handle;
1403
+ const nested = cleanMenuItems(children, depth + 1);
1404
+ if (nested.length > 0) out.children = nested;
1405
+ return [out];
1406
+ });
1407
+ }
1408
+
1409
+ // src/frame/AnnouncementBar.tsx
1410
+ import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
1411
+ var STORAGE_KEY = "throttle-storefront-announcement-dismissed";
1412
+ var listeners = /* @__PURE__ */ new Set();
1413
+ function hashOf(text) {
1414
+ let hash = 5381;
1415
+ for (let i = 0; i < text.length; i++) hash = (hash << 5) + hash + text.charCodeAt(i) | 0;
1416
+ return (hash >>> 0).toString(36);
1417
+ }
1418
+ function readDismissed() {
1419
+ try {
1420
+ return window.localStorage.getItem(STORAGE_KEY);
1421
+ } catch {
1422
+ return null;
1423
+ }
1424
+ }
1425
+ function subscribe(listener) {
1426
+ listeners.add(listener);
1427
+ window.addEventListener("storage", listener);
1428
+ return () => {
1429
+ listeners.delete(listener);
1430
+ window.removeEventListener("storage", listener);
1431
+ };
1432
+ }
1433
+ function moveFocusAway() {
1434
+ const target = document.querySelector('[data-throttle-part="header"], main');
1435
+ target?.focus();
1436
+ }
1437
+ function dismiss(hash) {
1438
+ moveFocusAway();
1439
+ try {
1440
+ window.localStorage.setItem(STORAGE_KEY, hash);
1441
+ } catch {
1442
+ }
1443
+ listeners.forEach((l) => l());
1444
+ }
1445
+ function AnnouncementBar(props) {
1446
+ const { site, Link: Anchor } = useStorefront();
1447
+ const { t } = useStrings();
1448
+ const root = usePart("announcement-bar", props);
1449
+ const text = usePart("announcement-bar-text", props);
1450
+ const close = usePart("announcement-bar-dismiss", props);
1451
+ const announcement = site.announcement;
1452
+ const hash = announcement ? hashOf(`${announcement.message}
1453
+ ${announcement.href ?? ""}`) : "";
1454
+ const dismissed = useSyncExternalStore(subscribe, readDismissed, () => null) === hash;
1455
+ if (!announcement || announcement.message.trim() === "" || dismissed) return null;
1456
+ const href = safeHref(announcement.href);
1457
+ return /* @__PURE__ */ jsxs10("div", { ...root, role: "region", "aria-label": t("frame.announcement.label"), children: [
1458
+ href ? /* @__PURE__ */ jsx14(Anchor, { ...text, href, "data-throttle-setting": "announcement", children: announcement.message }) : /* @__PURE__ */ jsx14("p", { ...text, "data-throttle-setting": "announcement", children: announcement.message }),
1459
+ /* @__PURE__ */ jsx14("button", { type: "button", ...close, "aria-label": t("frame.announcement.dismiss"), onClick: () => dismiss(hash), children: /* @__PURE__ */ jsx14(Icon5, { name: "close", size: 16 }) })
1460
+ ] });
1461
+ }
1462
+
1463
+ // src/frame/Footer.tsx
1464
+ import { jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
1465
+ function FooterList({ items, nested, local }) {
1466
+ const { Link: Anchor } = useStorefront();
1467
+ const list = usePart(nested ? "footer-sublist" : "footer-list", local);
1468
+ const item = usePart("footer-item", local);
1469
+ const link = usePart("footer-link", local);
1470
+ return /* @__PURE__ */ jsx15("ul", { ...list, children: items.map((entry) => /* @__PURE__ */ jsxs11("li", { ...item, children: [
1471
+ /* @__PURE__ */ jsx15(Anchor, { ...link, href: entry.href, children: entry.label }),
1472
+ entry.children ? /* @__PURE__ */ jsx15(FooterList, { items: entry.children, nested: true, local }) : null
1473
+ ] }, `${entry.href}|${entry.label}`)) });
1474
+ }
1475
+ function Footer({ year, brand, children, ...local }) {
1476
+ const { site } = useStorefront();
1477
+ const { t, keyAttr } = useStrings();
1478
+ const root = usePart("footer", local);
1479
+ const brandPart = usePart("footer-brand", local);
1480
+ const extra = usePart("footer-extra", local);
1481
+ const nav = usePart("footer-nav", local);
1482
+ const copyright = usePart("footer-copyright", local);
1483
+ const items = cleanMenuItems(site.menus.footer);
1484
+ return /* @__PURE__ */ jsxs11("footer", { ...root, children: [
1485
+ brand ? /* @__PURE__ */ jsx15("div", { ...brandPart, children: brand }) : null,
1486
+ items.length > 0 ? /* @__PURE__ */ jsx15("nav", { ...nav, "aria-label": t("frame.footer.label"), "data-menu": "footer", children: /* @__PURE__ */ jsx15(FooterList, { items, local }) }) : null,
1487
+ children ? /* @__PURE__ */ jsx15("div", { ...extra, children }) : null,
1488
+ /* @__PURE__ */ jsx15("p", { ...copyright, ...keyAttr("footer.copyright"), suppressHydrationWarning: true, children: t("footer.copyright", { year: year ?? (/* @__PURE__ */ new Date()).getFullYear(), store: site.brand.storeName }) })
1489
+ ] });
1490
+ }
1491
+
1492
+ // src/frame/Header.tsx
1493
+ import { useCategories } from "@usethrottle/catalog/react";
1494
+ import { Drawer as Drawer2, Icon as Icon10 } from "@usethrottle/ui";
1495
+ import { useId as useId8, useRef as useRef10, useState as useState10 } from "react";
1496
+
1497
+ // src/frame/AccountButton.tsx
1498
+ import { Icon as Icon6 } from "@usethrottle/ui";
1499
+ import { jsx as jsx16 } from "react/jsx-runtime";
1500
+ function AccountButton({ href = "/account", ...local }) {
1501
+ const { Link: Anchor } = useStorefront();
1502
+ const { t } = useStrings();
1503
+ const part = usePart("account-button", local);
1504
+ return /* @__PURE__ */ jsx16(Anchor, { ...part, href, "aria-label": t("nav.account"), children: /* @__PURE__ */ jsx16(Icon6, { name: "user", size: 22 }) });
1505
+ }
1506
+
1507
+ // src/frame/CartButton.tsx
1508
+ import { useCart } from "@usethrottle/catalog/react";
1509
+ import { Icon as Icon7 } from "@usethrottle/ui";
1510
+ import { jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
1511
+ function CartButton(props) {
1512
+ const { currency } = useStorefront();
1513
+ const { t } = useStrings();
1514
+ const drawer = useCartDrawer();
1515
+ const cart = useCart(currency ? { currency } : void 0);
1516
+ const count = cart.cart?.unitCount ?? 0;
1517
+ const part = usePart("cart-button", props);
1518
+ const badge = usePart("cart-button-count", props);
1519
+ const label = count === 1 ? t("frame.cart.labelOne") : t("frame.cart.label", { count });
1520
+ return /* @__PURE__ */ jsxs12(
1521
+ "button",
1522
+ {
1523
+ type: "button",
1524
+ ...part,
1525
+ "aria-label": label,
1526
+ "aria-haspopup": "dialog",
1527
+ "aria-expanded": drawer.open,
1528
+ onClick: () => drawer.setOpen(true),
1529
+ children: [
1530
+ /* @__PURE__ */ jsx17(Icon7, { name: "cart", size: 22 }),
1531
+ /* @__PURE__ */ jsx17("span", { ...badge, "aria-hidden": "true", "data-cart-count": count, "data-empty": count === 0 ? "" : void 0, children: count })
1532
+ ]
1533
+ }
1534
+ );
1535
+ }
1536
+
1537
+ // src/frame/CategoryNav.tsx
1538
+ import { Icon as Icon8 } from "@usethrottle/ui";
1539
+ import { useEffect as useEffect7, useId as useId4, useRef as useRef8, useState as useState7 } from "react";
1540
+ import { jsx as jsx18, jsxs as jsxs13 } from "react/jsx-runtime";
1541
+ function CategoryNav(props) {
1542
+ const { items, source, stacked = false } = props;
1543
+ const { dir } = useStorefront();
1544
+ const { t } = useStrings();
1545
+ const id = useId4();
1546
+ const [open, setOpen] = useState7(null);
1547
+ const enterList = useRef8(null);
1548
+ const root = usePart("category-nav", props);
1549
+ const list = usePart("category-nav-list", props);
1550
+ const item = usePart("category-nav-item", props);
1551
+ const link = usePart("category-nav-link", props);
1552
+ const toggle = usePart("category-nav-toggle", props);
1553
+ const panel = usePart("category-nav-panel", props);
1554
+ const child = usePart("category-nav-child", props);
1555
+ const listRef = useRef8(null);
1556
+ useEffect7(() => {
1557
+ if (enterList.current === null) return;
1558
+ const at = enterList.current;
1559
+ enterList.current = null;
1560
+ const entry = listRef.current?.querySelectorAll(":scope > li")[at];
1561
+ entry?.querySelector("[data-nav-panel] a")?.focus();
1562
+ }, [open]);
1563
+ const tops = () => [...listRef.current?.querySelectorAll(":scope > li > a") ?? []];
1564
+ const onKeyDown = (event) => {
1565
+ const target = event.target;
1566
+ const entry = target.closest("li[data-nav-top]");
1567
+ const index = entry ? [...listRef.current?.children ?? []].indexOf(entry) : -1;
1568
+ if (event.key === "Escape" && open !== null) {
1569
+ event.preventDefault();
1570
+ setOpen(null);
1571
+ tops()[open]?.focus();
1572
+ return;
1573
+ }
1574
+ const inPanel = target.closest("[data-nav-panel]");
1575
+ if (inPanel) {
1576
+ const links = [...inPanel.querySelectorAll("a")];
1577
+ const at2 = links.indexOf(target);
1578
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
1579
+ event.preventDefault();
1580
+ const step = event.key === "ArrowDown" ? 1 : -1;
1581
+ links[(at2 + step + links.length) % links.length]?.focus();
1582
+ }
1583
+ return;
1584
+ }
1585
+ const all = tops();
1586
+ const at = all.indexOf(target);
1587
+ if (at < 0) return;
1588
+ const forward = dir === "rtl" ? "ArrowLeft" : "ArrowRight";
1589
+ const back = dir === "rtl" ? "ArrowRight" : "ArrowLeft";
1590
+ if (event.key === forward || event.key === back) {
1591
+ event.preventDefault();
1592
+ const step = event.key === forward ? 1 : -1;
1593
+ all[(at + step + all.length) % all.length]?.focus();
1594
+ } else if (event.key === "Home" || event.key === "End") {
1595
+ event.preventDefault();
1596
+ all[event.key === "Home" ? 0 : all.length - 1]?.focus();
1597
+ } else if (event.key === "ArrowDown" && items[index]?.children) {
1598
+ event.preventDefault();
1599
+ if (stacked || open === index) {
1600
+ target.closest("li")?.querySelector("[data-nav-panel] a")?.focus();
1601
+ } else {
1602
+ enterList.current = index;
1603
+ setOpen(index);
1604
+ }
1605
+ }
1606
+ };
1607
+ const onBlur = (event, index) => {
1608
+ if (open === index && !event.currentTarget.contains(event.relatedTarget)) setOpen(null);
1609
+ };
1610
+ const label = props.label ?? t(source === "menu" ? "frame.header.mainNav" : "frame.header.categoriesNav");
1611
+ const parentOf = (entry, parent) => source === "categories" && entry.kind === "category" && entry.handle !== void 0 ? { "data-category-handle": entry.handle, "data-category-parent": parent } : entry.kind === "category" && entry.handle !== void 0 ? { "data-category-handle": entry.handle } : {};
1612
+ return /* @__PURE__ */ jsx18("nav", { ...root, "aria-label": label, "data-menu": source === "menu" ? "header" : void 0, onKeyDown, children: /* @__PURE__ */ jsx18("ul", { ...list, ref: listRef, "data-stacked": stacked ? "true" : void 0, children: items.map((entry, index) => {
1613
+ const children = entry.children;
1614
+ const shown = children !== void 0 && (stacked || open === index);
1615
+ const panelId = `${id}-${index}`;
1616
+ return /* @__PURE__ */ jsxs13(
1617
+ "li",
1618
+ {
1619
+ ...item,
1620
+ "data-nav-top": "",
1621
+ "data-stacked": stacked ? "true" : void 0,
1622
+ "data-open": shown ? "" : void 0,
1623
+ ...parentOf(entry, ""),
1624
+ onMouseEnter: children && !stacked ? () => setOpen(index) : void 0,
1625
+ onMouseLeave: children && !stacked ? () => setOpen((v) => v === index ? null : v) : void 0,
1626
+ onBlur: (event) => onBlur(event, index),
1627
+ children: [
1628
+ /* @__PURE__ */ jsx18(NavLink, { entry, part: link }),
1629
+ children && !stacked ? /* @__PURE__ */ jsx18(
1630
+ "button",
1631
+ {
1632
+ type: "button",
1633
+ ...toggle,
1634
+ "aria-expanded": shown,
1635
+ "aria-controls": panelId,
1636
+ "aria-label": t("frame.nav.submenu", { name: entry.label }),
1637
+ onClick: () => setOpen(shown ? null : index),
1638
+ children: /* @__PURE__ */ jsx18(Icon8, { name: "chevron-down", size: 14 })
1639
+ }
1640
+ ) : null,
1641
+ children ? /* @__PURE__ */ jsx18("ul", { ...panel, id: panelId, "data-nav-panel": "", "data-stacked": stacked ? "true" : void 0, hidden: !shown, children: children.map((sub) => /* @__PURE__ */ jsx18("li", { ...child, ...parentOf(sub, entry.handle ?? ""), children: /* @__PURE__ */ jsx18(NavLink, { entry: sub, part: link }) }, `${sub.href}|${sub.label}`)) }) : null
1642
+ ]
1643
+ },
1644
+ `${entry.href}|${entry.label}`
1645
+ );
1646
+ }) }) });
1647
+ }
1648
+ function NavLink({ entry, part }) {
1649
+ const { Link: Anchor } = useStorefront();
1650
+ return /* @__PURE__ */ jsx18(Anchor, { ...part, href: entry.href, children: entry.label });
1651
+ }
1652
+
1653
+ // src/frame/CurrencySwitch.tsx
1654
+ import { useConfig } from "@usethrottle/catalog/react";
1655
+ import { useId as useId5, useState as useState8 } from "react";
1656
+ import { jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
1657
+ function CurrencySwitch(props) {
1658
+ const { onChange } = props;
1659
+ const { currency } = useStorefront();
1660
+ const { t } = useStrings();
1661
+ const id = useId5();
1662
+ const [busy, setBusy] = useState8(false);
1663
+ const config = useConfig({ enabled: props.currencies === void 0 });
1664
+ const root = usePart("currency-switch", props);
1665
+ const label = usePart("currency-switch-label", props);
1666
+ const select = usePart("currency-switch-select", props);
1667
+ const offered = props.currencies ?? config.data?.currencies ?? [];
1668
+ if (!onChange || offered.length < 2) return null;
1669
+ return /* @__PURE__ */ jsxs14("div", { ...root, children: [
1670
+ /* @__PURE__ */ jsx19("label", { ...label, htmlFor: id, children: t("frame.currency.label") }),
1671
+ /* @__PURE__ */ jsx19(
1672
+ "select",
1673
+ {
1674
+ ...select,
1675
+ id,
1676
+ value: currency !== void 0 && offered.includes(currency) ? currency : offered[0],
1677
+ "aria-busy": busy || void 0,
1678
+ onChange: async (e) => {
1679
+ if (busy) return;
1680
+ setBusy(true);
1681
+ try {
1682
+ await onChange(e.target.value);
1683
+ } finally {
1684
+ setBusy(false);
1685
+ }
1686
+ },
1687
+ children: offered.map((code) => /* @__PURE__ */ jsx19("option", { value: code, "data-currency-option": code, children: code }, code))
1688
+ }
1689
+ )
1690
+ ] });
1691
+ }
1692
+
1693
+ // src/frame/LocaleSwitch.tsx
1694
+ import { useConfig as useConfig2 } from "@usethrottle/catalog/react";
1695
+ import { useId as useId6 } from "react";
1696
+ import { jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
1697
+ function nativeName(locale) {
1698
+ try {
1699
+ const name = new Intl.DisplayNames([locale], { type: "language" }).of(locale);
1700
+ return name ? name.charAt(0).toLocaleUpperCase(locale) + name.slice(1) : locale;
1701
+ } catch {
1702
+ return locale;
1703
+ }
1704
+ }
1705
+ function LocaleSwitch(props) {
1706
+ const { onChange } = props;
1707
+ const { locale } = useStorefront();
1708
+ const { t } = useStrings();
1709
+ const id = useId6();
1710
+ const config = useConfig2({ enabled: props.locales === void 0 });
1711
+ const root = usePart("locale-switch", props);
1712
+ const label = usePart("locale-switch-label", props);
1713
+ const select = usePart("locale-switch-select", props);
1714
+ const offered = props.locales ?? config.data?.locales ?? [];
1715
+ if (!onChange || offered.length < 2) return null;
1716
+ return /* @__PURE__ */ jsxs15("div", { ...root, children: [
1717
+ /* @__PURE__ */ jsx20("label", { ...label, htmlFor: id, children: t("frame.locale.label") }),
1718
+ /* @__PURE__ */ jsx20("select", { ...select, id, value: offered.includes(locale) ? locale : offered[0], onChange: (e) => onChange(e.target.value), children: offered.map((code) => /* @__PURE__ */ jsx20("option", { value: code, lang: code, "data-locale-option": code, children: nativeName(code) }, code)) })
1719
+ ] });
1720
+ }
1721
+
1722
+ // src/frame/SearchBox.tsx
1723
+ import { useSuggest } from "@usethrottle/catalog/react";
1724
+ import { Icon as Icon9 } from "@usethrottle/ui";
1725
+ import { useEffect as useEffect8, useId as useId7, useLayoutEffect, useRef as useRef9, useState as useState9 } from "react";
1726
+ import { Fragment as Fragment6, jsx as jsx21, jsxs as jsxs16 } from "react/jsx-runtime";
1727
+ var DEBOUNCE_MS = 150;
1728
+ var LIMIT = 8;
1729
+ var MIN_CHARS = 2;
1730
+ var END = Number.POSITIVE_INFINITY;
1731
+ function groupsOf(answer, href) {
1732
+ const groups = [
1733
+ {
1734
+ name: "products",
1735
+ options: answer.products.map((p) => ({
1736
+ kind: "product",
1737
+ key: p.handle,
1738
+ href: href("product", p.handle),
1739
+ label: p.title ?? p.handle,
1740
+ product: p
1741
+ }))
1742
+ },
1743
+ {
1744
+ name: "categories",
1745
+ options: answer.categories.map((c) => ({
1746
+ kind: "category",
1747
+ key: c.handle,
1748
+ href: href("category", c.handle),
1749
+ label: c.name,
1750
+ count: c.productCount
1751
+ }))
1752
+ },
1753
+ {
1754
+ name: "brands",
1755
+ options: answer.brands.map((b) => ({
1756
+ kind: "brand",
1757
+ key: b.name,
1758
+ href: href("search", b.name),
1759
+ label: b.name,
1760
+ count: b.productCount
1761
+ }))
1762
+ },
1763
+ {
1764
+ name: "tags",
1765
+ options: answer.tags.map((x) => ({
1766
+ kind: "tag",
1767
+ key: x.tag,
1768
+ href: href("tag", x.tag),
1769
+ label: x.tag,
1770
+ count: x.productCount
1771
+ }))
1772
+ },
1773
+ {
1774
+ name: "collections",
1775
+ options: answer.collections.map((c) => ({
1776
+ kind: "collection",
1777
+ key: c.handle,
1778
+ href: href("collection", c.handle),
1779
+ label: c.title,
1780
+ count: c.productCount
1781
+ }))
1782
+ }
1783
+ ];
1784
+ return groups.filter((g) => g.options.length > 0);
1785
+ }
1786
+ function searchForm(pattern) {
1787
+ const [path = "/search", query = ""] = pattern.split("?");
1788
+ const named = /(?:^|&)([^=&]+)=\{q\}/.exec(query);
1789
+ return { action: path.replace(/\/?\{q\}$/, "") || "/", name: named?.[1] ?? "q" };
1790
+ }
1791
+ function SearchBox(props) {
1792
+ const { settings, site, router, Link: Anchor } = useStorefront();
1793
+ const { t } = useStrings();
1794
+ const id = useId7();
1795
+ const listId = `${id}-list`;
1796
+ const root = usePart("search-box", props);
1797
+ const inputPart = usePart("search-box-input", props);
1798
+ const panel = usePart("search-box-panel", props);
1799
+ const listPart = usePart("search-box-list", props);
1800
+ const groupPart = usePart("search-box-group", props);
1801
+ const groupLabel = usePart("search-box-group-label", props);
1802
+ const optionPart = usePart("search-box-option", props);
1803
+ const thumb = usePart("search-box-thumb", props);
1804
+ const optionName = usePart("search-box-option-name", props);
1805
+ const optionMeta = usePart("search-box-option-meta", props);
1806
+ const allPart = usePart("search-box-all", props);
1807
+ const nonePart = usePart("search-box-none", props);
1808
+ const status = usePart("search-box-status", props);
1809
+ const form = searchForm(settings.routes.search);
1810
+ const href = (kind, value2) => routeHref(settings, kind, value2, site);
1811
+ const urlQuery = router.pathname === form.action ? router.searchParams.get(form.name) ?? "" : "";
1812
+ const [value, setValue] = useState9(urlQuery);
1813
+ const [open, setOpen] = useState9(false);
1814
+ const [active, setActive] = useState9(-1);
1815
+ const inputRef = useRef9(null);
1816
+ const write = (next) => {
1817
+ setValue(next);
1818
+ if (inputRef.current && inputRef.current.value !== next) inputRef.current.value = next;
1819
+ };
1820
+ useLayoutEffect(() => {
1821
+ const input = inputRef.current;
1822
+ if (!input || input.value === urlQuery) return;
1823
+ setValue(input.value);
1824
+ if (document.activeElement === input) setOpen(true);
1825
+ }, []);
1826
+ const seen = useRef9({ pathname: router.pathname, urlQuery });
1827
+ useEffect8(() => {
1828
+ const before = seen.current;
1829
+ if (before.pathname === router.pathname && before.urlQuery === urlQuery) return;
1830
+ seen.current = { pathname: router.pathname, urlQuery };
1831
+ if (before.urlQuery !== urlQuery) write(urlQuery);
1832
+ setOpen(false);
1833
+ setActive(-1);
1834
+ }, [router.pathname, urlQuery]);
1835
+ const term = value.trim();
1836
+ const { data, isLoading } = useSuggest(value, {
1837
+ debounceMs: DEBOUNCE_MS,
1838
+ limit: LIMIT,
1839
+ enabled: open,
1840
+ keepPreviousData: true
1841
+ });
1842
+ const lastAnswer = useRef9(void 0);
1843
+ useEffect8(() => {
1844
+ if (!data) return;
1845
+ if (data !== lastAnswer.current) setActive(-1);
1846
+ lastAnswer.current = data;
1847
+ }, [data]);
1848
+ const groups = data ? groupsOf(data, href) : [];
1849
+ const searchHref = href("search", term);
1850
+ const options = [...groups.flatMap((g) => g.options), { href: searchHref }];
1851
+ const visible = open && term.length >= MIN_CHARS && data !== void 0;
1852
+ const optionId = (index2) => `${id}-opt-${index2}`;
1853
+ const at = active === END ? options.length - 1 : active;
1854
+ const activeId = visible && at >= 0 && at < options.length ? optionId(at) : void 0;
1855
+ const total = groups.reduce((n, g) => n + g.options.length, 0);
1856
+ const close = () => {
1857
+ setOpen(false);
1858
+ setActive(-1);
1859
+ };
1860
+ const leave = () => {
1861
+ close();
1862
+ inputRef.current?.blur();
1863
+ };
1864
+ const onKeyDown = (event) => {
1865
+ if (event.nativeEvent.isComposing) return;
1866
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
1867
+ event.preventDefault();
1868
+ if (!visible) {
1869
+ setOpen(true);
1870
+ setActive(event.key === "ArrowDown" ? 0 : END);
1871
+ return;
1872
+ }
1873
+ const n = options.length;
1874
+ setActive(event.key === "ArrowDown" ? (at + 1) % n : at <= 0 ? n - 1 : at - 1);
1875
+ } else if (event.key === "Escape") {
1876
+ if (visible) {
1877
+ event.preventDefault();
1878
+ close();
1879
+ } else if (value) {
1880
+ event.preventDefault();
1881
+ write("");
1882
+ }
1883
+ } else if (event.key === "Enter") {
1884
+ if (activeId) {
1885
+ event.preventDefault();
1886
+ router.push(options[at].href);
1887
+ leave();
1888
+ } else {
1889
+ close();
1890
+ }
1891
+ }
1892
+ };
1893
+ const onSubmit = (event) => {
1894
+ const query = (inputRef.current?.value ?? value).trim();
1895
+ event.preventDefault();
1896
+ if (query === "") return;
1897
+ router.push(href("search", query));
1898
+ leave();
1899
+ };
1900
+ const announce = !visible || isLoading ? "" : total === 0 ? t("frame.search.announceNone") : total === 1 ? t("frame.search.announceOne") : t("frame.search.announceMany", { count: total });
1901
+ let index = -1;
1902
+ const optionLink = (o) => {
1903
+ index += 1;
1904
+ const i = index;
1905
+ return /* @__PURE__ */ jsx21(
1906
+ Anchor,
1907
+ {
1908
+ ...optionPart,
1909
+ id: optionId(i),
1910
+ href: o.href,
1911
+ role: "option",
1912
+ "aria-selected": i === at,
1913
+ tabIndex: -1,
1914
+ prefetch: false,
1915
+ "data-kind": o.kind,
1916
+ "data-handle": o.kind === "product" ? o.key : void 0,
1917
+ onClick: leave,
1918
+ onMouseMove: () => setActive(i),
1919
+ children: o.product ? /* @__PURE__ */ jsxs16(Fragment6, { children: [
1920
+ o.product.images[0] ? /* @__PURE__ */ jsx21("span", { ...thumb, "aria-hidden": "true", children: /* @__PURE__ */ jsx21(Image, { src: o.product.images[0].url, alt: "", aspectRatio: 1, sizes: "40px" }) }) : null,
1921
+ /* @__PURE__ */ jsx21("span", { ...optionName, children: o.label }),
1922
+ o.product.availability !== "out_of_stock" && o.product.priceRange ? /* @__PURE__ */ jsxs16("span", { ...optionMeta, children: [
1923
+ o.product.priceRange.minMinor !== o.product.priceRange.maxMinor ? `${t("pieces.price.from")} ` : null,
1924
+ /* @__PURE__ */ jsx21(
1925
+ Price,
1926
+ {
1927
+ minor: o.product.priceRange.minMinor,
1928
+ currency: o.product.priceRange.currency,
1929
+ priceContext: data?.priceContext
1930
+ }
1931
+ )
1932
+ ] }) : null
1933
+ ] }) : /* @__PURE__ */ jsxs16(Fragment6, { children: [
1934
+ /* @__PURE__ */ jsx21("span", { ...optionName, children: o.label }),
1935
+ o.count !== void 0 ? /* @__PURE__ */ jsx21("span", { ...optionMeta, children: o.count === 1 ? t("frame.search.productCountOne") : t("frame.search.productCount", { count: o.count }) }) : null
1936
+ ] })
1937
+ },
1938
+ `${o.kind}:${o.key}`
1939
+ );
1940
+ };
1941
+ return /* @__PURE__ */ jsxs16(
1942
+ "form",
1943
+ {
1944
+ ...root,
1945
+ role: "search",
1946
+ action: form.action,
1947
+ method: "get",
1948
+ onSubmit,
1949
+ onBlur: (event) => {
1950
+ if (!event.currentTarget.contains(event.relatedTarget)) close();
1951
+ },
1952
+ children: [
1953
+ /* @__PURE__ */ jsx21(Icon9, { name: "search", size: 18 }),
1954
+ /* @__PURE__ */ jsx21(
1955
+ "input",
1956
+ {
1957
+ ...inputPart,
1958
+ ref: inputRef,
1959
+ type: "search",
1960
+ name: form.name,
1961
+ defaultValue: urlQuery,
1962
+ placeholder: t("search.placeholder"),
1963
+ "aria-label": t("frame.search.label"),
1964
+ autoComplete: "off",
1965
+ enterKeyHint: "search",
1966
+ role: "combobox",
1967
+ "aria-autocomplete": "list",
1968
+ "aria-expanded": visible,
1969
+ "aria-controls": listId,
1970
+ "aria-activedescendant": activeId,
1971
+ onChange: (event) => {
1972
+ setValue(event.target.value);
1973
+ setOpen(true);
1974
+ setActive(-1);
1975
+ },
1976
+ onFocus: () => setOpen(true),
1977
+ onClick: () => setOpen(true),
1978
+ onKeyDown
1979
+ }
1980
+ ),
1981
+ /* @__PURE__ */ jsxs16(
1982
+ "div",
1983
+ {
1984
+ ...panel,
1985
+ hidden: !visible,
1986
+ onMouseDown: (event) => event.preventDefault(),
1987
+ children: [
1988
+ total === 0 ? /* @__PURE__ */ jsx21("p", { ...nonePart, children: t("frame.search.none", { q: term }) }) : null,
1989
+ /* @__PURE__ */ jsxs16("div", { id: listId, ...listPart, role: "listbox", "aria-label": t("frame.search.suggestions"), children: [
1990
+ groups.map((g) => /* @__PURE__ */ jsxs16("div", { ...groupPart, role: "group", "aria-labelledby": `${id}-${g.name}`, "data-group": g.name, children: [
1991
+ /* @__PURE__ */ jsx21("div", { id: `${id}-${g.name}`, ...groupLabel, role: "presentation", children: t(`frame.search.${g.name}`) }),
1992
+ g.options.map(optionLink)
1993
+ ] }, g.name)),
1994
+ /* @__PURE__ */ jsx21(
1995
+ Anchor,
1996
+ {
1997
+ ...allPart,
1998
+ id: optionId(options.length - 1),
1999
+ href: searchHref,
2000
+ role: "option",
2001
+ "aria-selected": at === options.length - 1,
2002
+ tabIndex: -1,
2003
+ prefetch: false,
2004
+ onClick: leave,
2005
+ onMouseMove: () => setActive(options.length - 1),
2006
+ children: t("frame.search.searchFor", { q: term })
2007
+ }
2008
+ )
2009
+ ] })
2010
+ ]
2011
+ }
2012
+ ),
2013
+ /* @__PURE__ */ jsx21("div", { ...status, role: "status", "aria-live": "polite", children: announce })
2014
+ ]
2015
+ }
2016
+ );
2017
+ }
2018
+
2019
+ // src/frame/Header.tsx
2020
+ import { jsx as jsx22, jsxs as jsxs17 } from "react/jsx-runtime";
2021
+ var DRAWER_QUERY = "(max-width: 959px)";
2022
+ var DEFAULT_SLOTS = { SearchBox, AccountButton, CartButton, CategoryNav, LocaleSwitch, CurrencySwitch };
2023
+ function useNavItems(enabled) {
2024
+ const { site, settings } = useStorefront();
2025
+ const { t } = useStrings();
2026
+ const menu = cleanMenuItems(site.menus.header);
2027
+ const tree = useCategories({ depth: 2, enabled: enabled && menu.length === 0 });
2028
+ if (menu.length > 0) return { items: menu, source: "menu" };
2029
+ const categories = (tree.data?.categories ?? []).map((root) => {
2030
+ const entry = {
2031
+ label: root.name,
2032
+ href: routeHref(settings, "category", root.handle, site),
2033
+ kind: "category",
2034
+ handle: root.handle
2035
+ };
2036
+ if (root.children.length > 0) {
2037
+ entry.children = root.children.map((c) => ({
2038
+ label: c.name,
2039
+ href: routeHref(settings, "category", c.handle, site),
2040
+ kind: "category",
2041
+ handle: c.handle
2042
+ }));
2043
+ }
2044
+ return entry;
2045
+ });
2046
+ const all = { label: t("home.shopAll"), href: settings.routes.shop };
2047
+ return { items: categories.length > 0 ? [all, ...categories] : [], source: "categories" };
2048
+ }
2049
+ function Header(props) {
2050
+ const { showCategoryNav = true, accountHref, onLocaleChange, onCurrencyChange } = props;
2051
+ const { site, Link: Anchor } = useStorefront();
2052
+ const { t } = useStrings();
2053
+ const slots = { ...DEFAULT_SLOTS, ...props.slots };
2054
+ const local = { classNames: props.classNames, unstyled: props.unstyled };
2055
+ const isDrawer = useMediaQuery(DRAWER_QUERY);
2056
+ const [open, setOpen] = useState10(false);
2057
+ const [container, setContainer] = useState10(null);
2058
+ const titleId = useId8();
2059
+ const opener = useRef10(null);
2060
+ if (!isDrawer && open) setOpen(false);
2061
+ const { items, source } = useNavItems(showCategoryNav);
2062
+ const hasNav = showCategoryNav && items.length > 0;
2063
+ const hasMenu = hasNav || onLocaleChange !== void 0 || onCurrencyChange !== void 0;
2064
+ const root = usePart("header", props);
2065
+ const bar = usePart("header-bar", local);
2066
+ const menuButton = usePart("header-menu-button", local);
2067
+ const brand = usePart("header-brand", local);
2068
+ const logoPart = usePart("header-logo", local);
2069
+ const namePart = usePart("header-store-name", local);
2070
+ const searchPart = usePart("header-search", local);
2071
+ const actions = usePart("header-actions", local);
2072
+ const navRow = usePart("header-nav-row", local);
2073
+ const prefs = usePart("header-prefs", local);
2074
+ const drawerTop = usePart("header-drawer-top", local);
2075
+ const drawerTitle = usePart("header-drawer-title", local);
2076
+ const drawerClose = usePart("header-drawer-close", local);
2077
+ const { storeName, logo } = site.brand;
2078
+ const logoLight = logo ? site.scheme === "dark" ? logo.dark ?? logo.light : logo.light ?? logo.dark : void 0;
2079
+ const logoDark = logo && site.scheme === "auto" ? logo.dark : void 0;
2080
+ const close = () => setOpen(false);
2081
+ const switchesIn = (drawer) => /* @__PURE__ */ jsxs17("div", { ...prefs, "data-in-drawer": drawer ? "" : void 0, children: [
2082
+ /* @__PURE__ */ jsx22(slots.CurrencySwitch, { onChange: onCurrencyChange, ...local }),
2083
+ /* @__PURE__ */ jsx22(slots.LocaleSwitch, { onChange: onLocaleChange, ...local })
2084
+ ] });
2085
+ const nav = hasNav ? /* @__PURE__ */ jsx22(slots.CategoryNav, { items, source, stacked: isDrawer, ...local }) : null;
2086
+ return /* @__PURE__ */ jsxs17("header", { ...root, tabIndex: -1, children: [
2087
+ /* @__PURE__ */ jsxs17("div", { ...bar, children: [
2088
+ hasMenu ? /* @__PURE__ */ jsx22(
2089
+ "button",
2090
+ {
2091
+ ref: opener,
2092
+ type: "button",
2093
+ ...menuButton,
2094
+ "aria-haspopup": "dialog",
2095
+ "aria-expanded": open && isDrawer,
2096
+ "aria-label": t("nav.menu"),
2097
+ onClick: () => {
2098
+ setContainer(opener.current?.closest(".tsf-root") ?? null);
2099
+ setOpen(true);
2100
+ },
2101
+ children: /* @__PURE__ */ jsx22(Icon10, { name: "menu", size: 22 })
2102
+ }
2103
+ ) : null,
2104
+ /* @__PURE__ */ jsxs17(
2105
+ Anchor,
2106
+ {
2107
+ ...brand,
2108
+ href: "/",
2109
+ "aria-label": storeName ? t("frame.header.home", { store: storeName }) : t("frame.header.homeNoName"),
2110
+ children: [
2111
+ logoLight ? /* @__PURE__ */ jsxs17("picture", { children: [
2112
+ logoDark ? /* @__PURE__ */ jsx22("source", { media: "(prefers-color-scheme: dark)", srcSet: logoDark }) : null,
2113
+ /* @__PURE__ */ jsx22("img", { ...logoPart, src: logoLight, alt: "" })
2114
+ ] }) : null,
2115
+ storeName || !logoLight ? /* @__PURE__ */ jsx22("span", { ...namePart, "data-has-logo": logoLight ? "" : void 0, "data-throttle-setting": "store-name", children: storeName }) : null
2116
+ ]
2117
+ }
2118
+ ),
2119
+ /* @__PURE__ */ jsx22("div", { ...searchPart, children: /* @__PURE__ */ jsx22(slots.SearchBox, { ...local }) }),
2120
+ /* @__PURE__ */ jsxs17("div", { ...actions, children: [
2121
+ /* @__PURE__ */ jsx22(slots.AccountButton, { href: accountHref, ...local }),
2122
+ /* @__PURE__ */ jsx22(slots.CartButton, { ...local })
2123
+ ] })
2124
+ ] }),
2125
+ !isDrawer && hasMenu ? /* @__PURE__ */ jsxs17("div", { ...navRow, children: [
2126
+ nav,
2127
+ switchesIn(false)
2128
+ ] }) : null,
2129
+ /* @__PURE__ */ jsxs17(Drawer2, { open: open && isDrawer, onClose: close, labelledBy: titleId, side: "start", restoreFocusTo: opener.current, container, children: [
2130
+ /* @__PURE__ */ jsxs17("div", { ...drawerTop, children: [
2131
+ /* @__PURE__ */ jsx22("h2", { id: titleId, ...drawerTitle, children: t("nav.menu") }),
2132
+ /* @__PURE__ */ jsx22("button", { type: "button", ...drawerClose, "aria-label": t("frame.header.closeMenu"), onClick: close, children: /* @__PURE__ */ jsx22(Icon10, { name: "close", size: 22 }) })
2133
+ ] }),
2134
+ /* @__PURE__ */ jsxs17("div", { onClick: (event) => event.target.closest("a") && close(), children: [
2135
+ nav,
2136
+ switchesIn(true)
2137
+ ] })
2138
+ ] })
2139
+ ] });
2140
+ }
2141
+
2142
+ // src/frame/in-frame.ts
2143
+ import { createContext as createContext2, useContext as useContext2 } from "react";
2144
+ var InFrameContext = createContext2(false);
2145
+ var useInFrame = () => useContext2(InFrameContext);
2146
+
2147
+ // src/frame/StoreFrame.tsx
2148
+ import { jsx as jsx23, jsxs as jsxs18 } from "react/jsx-runtime";
2149
+ function StoreFrame({ children, header, footer, mainId = "main-content", ...local }) {
2150
+ const { t } = useStrings();
2151
+ const root = usePart("store-frame", local);
2152
+ const skip = usePart("skip-link", local);
2153
+ const main = usePart("store-frame-main", local);
2154
+ const parts = { classNames: local.classNames, unstyled: local.unstyled };
2155
+ return /* @__PURE__ */ jsx23(InFrameContext.Provider, { value: true, children: /* @__PURE__ */ jsxs18("div", { ...root, children: [
2156
+ /* @__PURE__ */ jsx23("a", { ...skip, href: `#${mainId}`, children: t("frame.skipLink") }),
2157
+ /* @__PURE__ */ jsx23(AnnouncementBar, { ...parts }),
2158
+ /* @__PURE__ */ jsx23(Header, { ...parts, ...header }),
2159
+ /* @__PURE__ */ jsx23("main", { ...main, id: mainId, tabIndex: -1, children }),
2160
+ /* @__PURE__ */ jsx23(Footer, { ...parts, ...footer }),
2161
+ /* @__PURE__ */ jsx23(CartDrawer, { ...parts })
2162
+ ] }) });
2163
+ }
2164
+
2165
+ // src/merch/ProductCarousel.tsx
2166
+ import { Icon as Icon11 } from "@usethrottle/ui";
2167
+ import { useCallback as useCallback2, useEffect as useEffect9, useId as useId9, useRef as useRef11, useState as useState11 } from "react";
2168
+
2169
+ // src/merch/skeleton.tsx
2170
+ import { jsx as jsx24 } from "react/jsx-runtime";
2171
+ function MerchSkeleton({ count, classNames, unstyled }) {
2172
+ const list = usePart("merch-skeleton", { classNames, unstyled });
2173
+ const item = usePart("merch-skeleton-item", { classNames, unstyled });
2174
+ return /* @__PURE__ */ jsx24("div", { ...list, "aria-hidden": "true", children: Array.from({ length: Math.min(count, 8) }, (_, i) => /* @__PURE__ */ jsx24("div", { ...item }, i)) });
2175
+ }
2176
+
2177
+ // src/merch/ProductCarousel.tsx
2178
+ import { jsx as jsx25, jsxs as jsxs19 } from "react/jsx-runtime";
2179
+ var DEFAULT_LIMIT = 8;
2180
+ function stepOf(track) {
2181
+ const [a, b] = Array.from(track.children);
2182
+ if (a && b) return Math.abs(b.offsetLeft - a.offsetLeft);
2183
+ return a?.offsetWidth ?? track.clientWidth;
2184
+ }
2185
+ function Carousel(props) {
2186
+ const { products, label, heading, eyebrow, trailing, generatedAt, priceContext, cardVariant, cardMeta, embedded, classNames, unstyled, className } = props;
2187
+ const { dir } = useStorefront();
2188
+ const { t } = useStrings();
2189
+ const local = { classNames, unstyled };
2190
+ const root = usePart("product-carousel", { ...local, className });
2191
+ const header = usePart("product-carousel-header", local);
2192
+ const eyebrowPart = usePart("product-carousel-eyebrow", local);
2193
+ const titlePart = usePart("product-carousel-title", local);
2194
+ const controls = usePart("product-carousel-controls", local);
2195
+ const prevPart = usePart("product-carousel-prev", local);
2196
+ const nextPart = usePart("product-carousel-next", local);
2197
+ const trackPart = usePart("product-carousel-track", local);
2198
+ const itemPart = usePart("product-carousel-item", local);
2199
+ const trackId = useId9();
2200
+ const track = useRef11(null);
2201
+ const [edge, setEdge] = useState11({ start: true, end: false });
2202
+ const onSelect = useListAnalytics(label, products);
2203
+ const measure = useCallback2(() => {
2204
+ const el = track.current;
2205
+ if (!el) return;
2206
+ const offset = Math.abs(el.scrollLeft);
2207
+ const next = { start: offset <= 1, end: offset >= el.scrollWidth - el.clientWidth - 1 };
2208
+ setEdge((prev) => prev.start === next.start && prev.end === next.end ? prev : next);
2209
+ }, []);
2210
+ useEffect9(() => {
2211
+ measure();
2212
+ const el = track.current;
2213
+ if (!el || typeof ResizeObserver === "undefined") return;
2214
+ const observer = new ResizeObserver(measure);
2215
+ observer.observe(el);
2216
+ return () => observer.disconnect();
2217
+ }, [measure, products.length]);
2218
+ const move = (toward) => {
2219
+ const el = track.current;
2220
+ if (!el) return;
2221
+ const left = toward * (dir === "rtl" ? -1 : 1) * stepOf(el);
2222
+ const reduce = typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
2223
+ if (typeof el.scrollBy === "function") el.scrollBy({ left, behavior: reduce ? "auto" : "smooth" });
2224
+ else el.scrollLeft += left;
2225
+ };
2226
+ const onKeyDown = (event) => {
2227
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
2228
+ if (event.key !== "ArrowRight" && event.key !== "ArrowLeft") return;
2229
+ const target = event.target;
2230
+ if (target.closest('input, textarea, select, [contenteditable="true"]')) return;
2231
+ event.preventDefault();
2232
+ const toward = event.key === "ArrowRight" === (dir !== "rtl") ? 1 : -1;
2233
+ move(toward);
2234
+ const items = Array.from(track.current?.children ?? []);
2235
+ const from = items.findIndex((li) => li.contains(target));
2236
+ if (from >= 0) items[from + toward]?.querySelector('a:not([tabindex="-1"]), button')?.focus({ preventScroll: true });
2237
+ };
2238
+ return /* @__PURE__ */ jsxs19(
2239
+ "section",
2240
+ {
2241
+ ...root,
2242
+ role: "region",
2243
+ "aria-roledescription": "carousel",
2244
+ "aria-label": label,
2245
+ "data-section": embedded ? void 0 : "product-carousel",
2246
+ "data-section-title": embedded ? void 0 : label,
2247
+ onKeyDown,
2248
+ children: [
2249
+ /* @__PURE__ */ jsxs19("div", { ...header, children: [
2250
+ heading && eyebrow?.trim() ? /* @__PURE__ */ jsx25("p", { ...eyebrowPart, children: eyebrow }) : null,
2251
+ heading ? /* @__PURE__ */ jsx25("h2", { ...titlePart, children: heading }) : null,
2252
+ /* @__PURE__ */ jsxs19("div", { ...controls, children: [
2253
+ trailing,
2254
+ /* @__PURE__ */ jsx25(
2255
+ "button",
2256
+ {
2257
+ ...prevPart,
2258
+ type: "button",
2259
+ "aria-label": t("merch.carousel.previous"),
2260
+ "aria-controls": trackId,
2261
+ disabled: edge.start,
2262
+ onClick: () => move(-1),
2263
+ children: /* @__PURE__ */ jsx25(Icon11, { name: "chevron-left", size: 20 })
2264
+ }
2265
+ ),
2266
+ /* @__PURE__ */ jsx25(
2267
+ "button",
2268
+ {
2269
+ ...nextPart,
2270
+ type: "button",
2271
+ "aria-label": t("merch.carousel.next"),
2272
+ "aria-controls": trackId,
2273
+ disabled: edge.end,
2274
+ onClick: () => move(1),
2275
+ children: /* @__PURE__ */ jsx25(Icon11, { name: "chevron-right", size: 20 })
2276
+ }
2277
+ )
2278
+ ] })
2279
+ ] }),
2280
+ /* @__PURE__ */ jsx25("div", { ...trackPart, ref: track, id: trackId, onScroll: measure, children: products.map((product, position) => /* @__PURE__ */ jsx25(
2281
+ "div",
2282
+ {
2283
+ ...itemPart,
2284
+ role: "group",
2285
+ "aria-roledescription": "slide",
2286
+ "aria-label": t("merch.carousel.slide", { n: position + 1, total: products.length }),
2287
+ children: /* @__PURE__ */ jsx25(
2288
+ ProductCard,
2289
+ {
2290
+ product,
2291
+ variant: cardVariant,
2292
+ meta: cardMeta,
2293
+ position,
2294
+ listName: label,
2295
+ generatedAt,
2296
+ priceContext,
2297
+ onSelect,
2298
+ ...local
2299
+ }
2300
+ )
2301
+ },
2302
+ product.handle
2303
+ )) })
2304
+ ]
2305
+ }
2306
+ );
2307
+ }
2308
+ function ProductCarousel(props) {
2309
+ const { source, title, eyebrow, limit = DEFAULT_LIMIT, cardVariant, cardMeta, initialData, classNames, unstyled, className } = props;
2310
+ const { t } = useStrings();
2311
+ const data = useMerchProducts(source, { limit, initialData });
2312
+ const label = title?.trim() || t("merch.carousel.label");
2313
+ if (isEmptySource(source) || data.status === "error") return null;
2314
+ if (data.status === "loading") return /* @__PURE__ */ jsx25(MerchSkeleton, { count: 4, classNames, unstyled });
2315
+ if (data.products.length === 0) return null;
2316
+ return /* @__PURE__ */ jsx25(
2317
+ Carousel,
2318
+ {
2319
+ products: data.products,
2320
+ label,
2321
+ heading: title?.trim() || void 0,
2322
+ eyebrow,
2323
+ generatedAt: data.generatedAt,
2324
+ priceContext: data.priceContext,
2325
+ cardVariant,
2326
+ cardMeta,
2327
+ classNames,
2328
+ unstyled,
2329
+ className
2330
+ }
2331
+ );
2332
+ }
2333
+
2334
+ // src/merch/CollectionShelf.tsx
2335
+ import { jsx as jsx26, jsxs as jsxs20 } from "react/jsx-runtime";
2336
+ var DEFAULT_LIMIT2 = 4;
2337
+ function CollectionShelf(props) {
2338
+ const { handle, title, eyebrow, limit = DEFAULT_LIMIT2, layout = "grid", columns, showViewAll = true, cardVariant, cardMeta, initialData, classNames, unstyled, className } = props;
2339
+ const { settings } = useStorefront();
2340
+ const { t } = useStrings();
2341
+ const local = { classNames, unstyled };
2342
+ const root = usePart("collection-shelf", { ...local, className });
2343
+ const header = usePart("collection-shelf-header", local);
2344
+ const eyebrowPart = usePart("collection-shelf-eyebrow", local);
2345
+ const heading = usePart("collection-shelf-title", local);
2346
+ const viewAll = usePart("collection-shelf-link", local);
2347
+ const grid = usePart("collection-shelf-grid", local);
2348
+ const item = usePart("collection-shelf-item", local);
2349
+ const data = useMerchProducts({ kind: "collection", handle }, { limit, initialData, withTitle: !title?.trim() });
2350
+ const label = title?.trim() || data.title || "";
2351
+ const onSelect = useListAnalytics(label || handle, layout === "grid" ? data.products : []);
2352
+ const { Link: Anchor } = useStorefront();
2353
+ if (data.status === "error") return null;
2354
+ if (data.status === "loading") return /* @__PURE__ */ jsx26(MerchSkeleton, { count: limit, ...local });
2355
+ if (data.products.length === 0) return null;
2356
+ const cols = columns ?? settings.listing.columns;
2357
+ const style = { "--tsf-columns-desktop": cols.desktop, "--tsf-columns-mobile": cols.mobile };
2358
+ const link = showViewAll ? /* @__PURE__ */ jsx26(
2359
+ Anchor,
2360
+ {
2361
+ ...viewAll,
2362
+ href: routeHref(settings, "collection", handle),
2363
+ "aria-label": label ? t("merch.viewAllNamed", { title: label }) : void 0,
2364
+ children: t("merch.viewAll")
2365
+ }
2366
+ ) : null;
2367
+ return /* @__PURE__ */ jsxs20("section", { ...root, "data-section": "collection-shelf", "data-section-title": label || void 0, "data-collection-handle": handle, "data-layout": layout, children: [
2368
+ /* @__PURE__ */ jsxs20("div", { ...header, children: [
2369
+ eyebrow?.trim() ? /* @__PURE__ */ jsx26("p", { ...eyebrowPart, children: eyebrow }) : null,
2370
+ label ? /* @__PURE__ */ jsx26("h2", { ...heading, children: label }) : null,
2371
+ layout === "grid" ? link : null
2372
+ ] }),
2373
+ layout === "carousel" ? /* @__PURE__ */ jsx26(
2374
+ Carousel,
2375
+ {
2376
+ products: data.products,
2377
+ label: label || t("merch.carousel.label"),
2378
+ trailing: link,
2379
+ generatedAt: data.generatedAt,
2380
+ priceContext: data.priceContext,
2381
+ cardVariant,
2382
+ cardMeta,
2383
+ embedded: true,
2384
+ ...local
2385
+ }
2386
+ ) : /* @__PURE__ */ jsx26("ul", { ...grid, style, children: data.products.map((product, position) => /* @__PURE__ */ jsx26("li", { ...item, children: /* @__PURE__ */ jsx26(
2387
+ ProductCard,
2388
+ {
2389
+ product,
2390
+ variant: cardVariant,
2391
+ meta: cardMeta,
2392
+ position,
2393
+ listName: label || handle,
2394
+ generatedAt: data.generatedAt,
2395
+ priceContext: data.priceContext,
2396
+ onSelect,
2397
+ ...local
2398
+ }
2399
+ ) }, product.handle)) })
2400
+ ] });
2401
+ }
2402
+
2403
+ // src/merch/FeaturedProduct.tsx
2404
+ import { useProduct } from "@usethrottle/catalog/react";
2405
+ import { useMemo as useMemo3 } from "react";
2406
+ import { jsx as jsx27, jsxs as jsxs21 } from "react/jsx-runtime";
2407
+ function priceOf(product) {
2408
+ const range = product.priceRange;
2409
+ if (!range) return null;
2410
+ const priced = product.variants.filter((v) => v.priceMinor !== null && v.currency === range.currency);
2411
+ const cheapest = priced.reduce(
2412
+ (best, v) => !best || (v.salePriceMinor ?? v.priceMinor) < (best.salePriceMinor ?? best.priceMinor) ? v : best,
2413
+ void 0
2414
+ );
2415
+ const compare = cheapest?.compareAtPriceMinor ?? (cheapest?.salePriceMinor != null ? cheapest.priceMinor : null);
2416
+ return {
2417
+ minor: range.minMinor,
2418
+ currency: range.currency,
2419
+ ...compare != null && compare > range.minMinor ? { compareAtMinor: compare } : {},
2420
+ from: range.minMinor !== range.maxMinor
2421
+ };
2422
+ }
2423
+ var EXCERPT_LENGTH = 240;
2424
+ function excerptOf(text) {
2425
+ if (text.length <= EXCERPT_LENGTH) return text;
2426
+ const cut = text.slice(0, EXCERPT_LENGTH);
2427
+ const space = cut.lastIndexOf(" ");
2428
+ return `${(space > EXCERPT_LENGTH / 2 ? cut.slice(0, space) : cut).trimEnd()}\u2026`;
2429
+ }
2430
+ function FeaturedProduct(props) {
2431
+ const { handle, layout = "image-left", showDescription = true, initialData, classNames, unstyled, className } = props;
2432
+ const { settings, reviewsOnLists, Link: Anchor } = useStorefront();
2433
+ const { t } = useStrings();
2434
+ const local = { classNames, unstyled };
2435
+ const root = usePart("featured-product", { ...local, className });
2436
+ const media = usePart("featured-product-media", local);
2437
+ const mediaLink = usePart("featured-product-media-link", local);
2438
+ const placeholder = usePart("featured-product-placeholder", local);
2439
+ const body = usePart("featured-product-body", local);
2440
+ const titlePart = usePart("featured-product-title", local);
2441
+ const ratingPart = usePart("featured-product-rating", local);
2442
+ const pricePart = usePart("featured-product-price", local);
2443
+ const from = usePart("featured-product-from", local);
2444
+ const description = usePart("featured-product-description", local);
2445
+ const link = usePart("featured-product-link", local);
2446
+ const seed = useMemo3(() => initialData ? { product: initialData.product } : void 0, [initialData]);
2447
+ const query = useProduct(handle.trim() === "" ? null : handle, { initialData: seed, staleTimeMs: MERCH_STALE_MS });
2448
+ const answer = query.data && "product" in query.data ? query.data : void 0;
2449
+ if (!answer) return null;
2450
+ const { product } = answer;
2451
+ const priceContext = answer.priceContext;
2452
+ const title = product.title ?? product.handle;
2453
+ const href = routeHref(settings, "product", product.handle);
2454
+ const price = priceOf(product);
2455
+ const image = product.images[0];
2456
+ const rating = product.rating;
2457
+ const showRating = settings.card.showRating && reviewsOnLists && rating && rating.count > 0 && rating.average !== null;
2458
+ const plain = (product.shortDescription || product.description || "").trim();
2459
+ const html = plain ? "" : product.descriptionHtml ?? "";
2460
+ const ratio = image?.width && image.height ? image.width / image.height : 0.8;
2461
+ return /* @__PURE__ */ jsxs21("section", { ...root, "data-section": "featured-product", "data-section-title": title, "data-product-handle": product.handle, "data-layout": layout, children: [
2462
+ /* @__PURE__ */ jsx27("div", { ...media, "data-layout": layout, children: /* @__PURE__ */ jsx27(Anchor, { ...mediaLink, href, tabIndex: -1, "aria-hidden": "true", children: image ? /* @__PURE__ */ jsx27(Image, { src: image.url, alt: "", aspectRatio: ratio, sizes: "(min-width: 768px) 50vw, 100vw", ...local }) : /* @__PURE__ */ jsx27("div", { ...placeholder, style: { aspectRatio: 0.8 } }) }) }),
2463
+ /* @__PURE__ */ jsxs21("div", { ...body, children: [
2464
+ /* @__PURE__ */ jsx27("h2", { ...titlePart, children: title }),
2465
+ showRating ? /* @__PURE__ */ jsx27("div", { ...ratingPart, "data-card-rating": "", children: /* @__PURE__ */ jsx27(StarRating, { value: rating.average, count: rating.count, ...local }) }) : null,
2466
+ price ? /* @__PURE__ */ jsxs21("p", { ...pricePart, children: [
2467
+ price.from ? /* @__PURE__ */ jsxs21("span", { ...from, children: [
2468
+ t("pieces.price.from"),
2469
+ " "
2470
+ ] }) : null,
2471
+ /* @__PURE__ */ jsx27(Price, { minor: price.minor, currency: price.currency, compareAtMinor: settings.card.showCompareAt ? price.compareAtMinor : void 0, priceContext, ...local })
2472
+ ] }) : null,
2473
+ showDescription && (plain || html) ? /* @__PURE__ */ jsx27("div", { ...description, children: plain ? /* @__PURE__ */ jsx27("p", { children: excerptOf(plain) }) : /* @__PURE__ */ jsx27(RichText, { html, ...local }) }) : null,
2474
+ /* @__PURE__ */ jsx27(Anchor, { ...link, href, children: t("merch.viewProduct") })
2475
+ ] })
2476
+ ] });
2477
+ }
2478
+
2479
+ // src/merch/CategoryDirectory.tsx
2480
+ import { useCategories as useCategories2 } from "@usethrottle/catalog/react";
2481
+ import { jsx as jsx28, jsxs as jsxs22 } from "react/jsx-runtime";
2482
+ function find(nodes, handle) {
2483
+ for (const node of nodes) {
2484
+ if (node.handle === handle) return node;
2485
+ const inside = find(node.children, handle);
2486
+ if (inside) return inside;
2487
+ }
2488
+ return void 0;
2489
+ }
2490
+ function CategoryDirectory(props) {
2491
+ const { parent, depth = 1, layout = "grid", showImages = false, showCounts = false, initialData, classNames, unstyled, className } = props;
2492
+ const { settings, Link: Anchor } = useStorefront();
2493
+ const { t } = useStrings();
2494
+ const local = { classNames, unstyled };
2495
+ const root = usePart("category-directory", { ...local, className });
2496
+ const list = usePart("category-directory-list", local);
2497
+ const item = usePart("category-directory-item", local);
2498
+ const link = usePart("category-directory-link", local);
2499
+ const imagePart = usePart("category-directory-image", local);
2500
+ const name = usePart("category-directory-name", local);
2501
+ const count = usePart("category-directory-count", local);
2502
+ const children = usePart("category-directory-children", local);
2503
+ const tree = useCategories2({ depth: parent ? 10 : depth, initialData, staleTimeMs: MERCH_STALE_MS });
2504
+ if (!tree.data) return null;
2505
+ const top = parent ? find(tree.data.categories, parent)?.children : tree.data.categories;
2506
+ if (!top || top.length === 0) return null;
2507
+ const entry = (node, parentHandle, level) => {
2508
+ const image = showImages ? node.image : void 0;
2509
+ const productCount = node.productCount;
2510
+ return /* @__PURE__ */ jsxs22("li", { ...item, "data-category-handle": node.handle, "data-category-parent": parentHandle, children: [
2511
+ /* @__PURE__ */ jsxs22(Anchor, { ...link, href: routeHref(settings, "category", node.handle), children: [
2512
+ image?.url ? /* @__PURE__ */ jsx28(Image, { src: image.url, alt: "", aspectRatio: 4 / 3, className: imagePart.className, ...local }) : null,
2513
+ /* @__PURE__ */ jsx28("span", { ...name, children: node.name }),
2514
+ showCounts ? /* @__PURE__ */ jsx28("span", { ...count, children: t(productCount === 1 ? "merch.categories.countOne" : "merch.categories.count", { count: productCount }) }) : null
2515
+ ] }),
2516
+ level === 1 && depth === 2 && node.children.length > 0 ? /* @__PURE__ */ jsx28("ul", { ...children, children: node.children.map((child) => entry(child, node.handle, 2)) }) : null
2517
+ ] }, node.id);
2518
+ };
2519
+ return /* @__PURE__ */ jsx28("nav", { ...root, "aria-label": t("merch.categories.label"), "data-section": "category-directory", "data-layout": layout, children: /* @__PURE__ */ jsx28("ul", { ...list, "data-layout": layout, children: top.map((node) => entry(node, parent, 1)) }) });
2520
+ }
2521
+
2522
+ // src/merch/ReviewsList.tsx
2523
+ import { useReviews } from "@usethrottle/catalog/react";
2524
+ import { jsx as jsx29, jsxs as jsxs23 } from "react/jsx-runtime";
2525
+ var DEFAULT_LIMIT3 = 5;
2526
+ function dateOf(iso, locale) {
2527
+ const time = Date.parse(iso);
2528
+ if (Number.isNaN(time)) return null;
2529
+ try {
2530
+ return new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeZone: "UTC" }).format(time);
2531
+ } catch {
2532
+ return null;
2533
+ }
2534
+ }
2535
+ function ReviewsList(props) {
2536
+ const { productHandle, reviews, limit = DEFAULT_LIMIT3, showProduct = false, classNames, unstyled, className } = props;
2537
+ const { settings, locale, Link: Anchor } = useStorefront();
2538
+ const { t } = useStrings();
2539
+ const local = { classNames, unstyled };
2540
+ const root = usePart("reviews-list", { ...local, className });
2541
+ const items = usePart("reviews-list-items", local);
2542
+ const itemPart = usePart("reviews-list-item", local);
2543
+ const head = usePart("reviews-list-head", local);
2544
+ const titlePart = usePart("reviews-list-title", local);
2545
+ const bodyPart = usePart("reviews-list-body", local);
2546
+ const meta = usePart("reviews-list-meta", local);
2547
+ const author = usePart("reviews-list-author", local);
2548
+ const verified = usePart("reviews-list-verified", local);
2549
+ const datePart = usePart("reviews-list-date", local);
2550
+ const productPart = usePart("reviews-list-product", local);
2551
+ const reply = usePart("reviews-list-reply", local);
2552
+ const handle = !reviews && productHandle?.trim() ? productHandle : null;
2553
+ const query = useReviews(handle, { sort: "newest", limit, staleTimeMs: MERCH_STALE_MS });
2554
+ const given = reviews ?? (query.data && "reviews" in query.data ? query.data.reviews : void 0);
2555
+ const shown = given?.slice(0, Math.max(0, limit));
2556
+ if (!shown || shown.length === 0) return null;
2557
+ return /* @__PURE__ */ jsx29("section", { ...root, "aria-label": t("merch.reviews.label"), "data-section": "reviews-list", children: /* @__PURE__ */ jsx29("ul", { ...items, children: shown.map((review) => {
2558
+ const when = dateOf(review.createdAt, locale);
2559
+ const about = showProduct && review.productHandle ? review.productTitle ?? review.productHandle : null;
2560
+ return /* @__PURE__ */ jsxs23("li", { ...itemPart, "data-review-id": review.id, "data-rating": review.rating, children: [
2561
+ /* @__PURE__ */ jsxs23("div", { ...head, children: [
2562
+ /* @__PURE__ */ jsx29(StarRating, { value: review.rating, size: "sm", ...local }),
2563
+ review.title ? /* @__PURE__ */ jsx29("h3", { ...titlePart, children: review.title }) : null
2564
+ ] }),
2565
+ /* @__PURE__ */ jsx29("p", { ...bodyPart, children: review.body }),
2566
+ /* @__PURE__ */ jsxs23("p", { ...meta, children: [
2567
+ /* @__PURE__ */ jsx29("span", { ...author, children: review.displayName }),
2568
+ review.verified ? /* @__PURE__ */ jsx29("span", { ...verified, children: t("merch.reviews.verified") }) : null,
2569
+ when ? /* @__PURE__ */ jsx29("time", { ...datePart, dateTime: review.createdAt, children: when }) : null,
2570
+ about && review.productHandle ? /* @__PURE__ */ jsx29(Anchor, { ...productPart, href: routeHref(settings, "product", review.productHandle), children: t("merch.reviews.forProduct", { product: about }) }) : null
2571
+ ] }),
2572
+ review.reply ? /* @__PURE__ */ jsxs23("div", { ...reply, children: [
2573
+ /* @__PURE__ */ jsx29("strong", { children: t("merch.reviews.reply") }),
2574
+ " ",
2575
+ review.reply.body
2576
+ ] }) : null
2577
+ ] }, review.id);
2578
+ }) }) });
2579
+ }
2580
+
2581
+ // src/shopper/QuickView.tsx
2582
+ import { lazy as lazy2, Suspense as Suspense2, useEffect as useEffect10, useRef as useRef12 } from "react";
2583
+ import { jsx as jsx30 } from "react/jsx-runtime";
2584
+ var QuickViewBody = lazy2(() => import("./chunk-Q3VTUBPP.js").then((m) => ({ default: m.QuickViewBody })));
2585
+ function QuickView({ handle, open, onOpenChange, ...local }) {
2586
+ const opener = useRef12(null);
2587
+ useEffect10(() => {
2588
+ if (open) opener.current = document.activeElement;
2589
+ }, [open]);
2590
+ if (!open || !handle) return null;
2591
+ return /* @__PURE__ */ jsx30(Suspense2, { fallback: null, children: /* @__PURE__ */ jsx30(QuickViewBody, { handle, onOpenChange, openerRef: opener, ...local }) });
2592
+ }
2593
+
2594
+ // src/shopper/RecentlyViewed.tsx
2595
+ import { useCallback as useCallback3, useEffect as useEffect11 } from "react";
2596
+ import { jsx as jsx31, jsxs as jsxs24 } from "react/jsx-runtime";
2597
+ var RECENT_KEY = "throttle:sf:recent";
2598
+ var RECENT_MAX = 12;
2599
+ var recentList = createStoredList(RECENT_KEY, RECENT_MAX);
2600
+ function useRecentlyViewed() {
2601
+ const handles = recentList.useIds();
2602
+ const push = useCallback3((handle) => {
2603
+ const clean = handle.trim();
2604
+ if (clean === "") return;
2605
+ const now = recentList.read();
2606
+ if (now[0] === clean) return;
2607
+ recentList.write([clean, ...now.filter((h) => h !== clean)]);
2608
+ }, []);
2609
+ return { handles, push };
2610
+ }
2611
+ function RecentlyViewed(props) {
2612
+ const { limit = RECENT_MAX, current, cardVariant, cardMeta, title, classNames, unstyled, className } = props;
2613
+ const local = { classNames, unstyled };
2614
+ const { t } = useStrings();
2615
+ const { handles, push } = useRecentlyViewed();
2616
+ useEffect11(() => {
2617
+ if (current) push(current);
2618
+ }, [current, push]);
2619
+ const shown = handles.filter((h) => h !== current).slice(0, Math.min(Math.max(1, Math.floor(limit)), RECENT_MAX));
2620
+ const data = useMerchProducts({ kind: "manual", handles: shown }, { limit: Math.max(1, shown.length) });
2621
+ const label = title?.trim() || t("shopper.recent.title");
2622
+ const onSelect = useListAnalytics(label, data.products);
2623
+ const root = usePart("recently-viewed", { ...local, className });
2624
+ const heading = usePart("recently-viewed-title", local);
2625
+ const list = usePart("recently-viewed-list", local);
2626
+ const item = usePart("recently-viewed-item", local);
2627
+ if (shown.length === 0 || data.status === "error") return null;
2628
+ if (data.status === "loading") return /* @__PURE__ */ jsx31(MerchSkeleton, { count: Math.min(shown.length, 4), ...local });
2629
+ if (data.products.length === 0) return null;
2630
+ return /* @__PURE__ */ jsxs24("section", { ...root, "aria-label": label, "data-section": "recently-viewed", "data-section-title": label, children: [
2631
+ /* @__PURE__ */ jsx31("h2", { ...heading, children: label }),
2632
+ /* @__PURE__ */ jsx31("ul", { ...list, children: data.products.map((product, position) => /* @__PURE__ */ jsx31("li", { ...item, children: /* @__PURE__ */ jsx31(
2633
+ ProductCard,
2634
+ {
2635
+ product,
2636
+ variant: cardVariant,
2637
+ meta: cardMeta,
2638
+ position,
2639
+ listName: label,
2640
+ generatedAt: data.generatedAt,
2641
+ priceContext: data.priceContext,
2642
+ onSelect,
2643
+ ...local
2644
+ }
2645
+ ) }, product.handle)) })
2646
+ ] });
2647
+ }
2648
+
2649
+ // src/shopper/Compare.tsx
2650
+ import { lazy as lazy3, Suspense as Suspense3 } from "react";
2651
+ import { jsx as jsx32 } from "react/jsx-runtime";
2652
+ var CompareTable = lazy3(() => import("./chunk-NZRUQUN5.js").then((m) => ({ default: m.CompareTable })));
2653
+ function Compare(props) {
2654
+ return /* @__PURE__ */ jsx32(Suspense3, { fallback: null, children: /* @__PURE__ */ jsx32(CompareTable, { ...props }) });
2655
+ }
2656
+
2657
+ // src/pages/NotFound.tsx
2658
+ import { useId as useId10 } from "react";
2659
+ import { jsx as jsx33, jsxs as jsxs25 } from "react/jsx-runtime";
2660
+ function NotFound(props) {
2661
+ const { settings, Link: Anchor } = useStorefront();
2662
+ const { t, keyAttr } = useStrings();
2663
+ const inFrame = useInFrame();
2664
+ const titleId = useId10();
2665
+ const root = usePart("not-found", props);
2666
+ const code = usePart("not-found-code", props);
2667
+ const title = usePart("not-found-title", props);
2668
+ const body = usePart("not-found-body", props);
2669
+ const actions = usePart("not-found-actions", props);
2670
+ const link = usePart("not-found-link", props);
2671
+ const Wrapper = inFrame ? "section" : "main";
2672
+ return /* @__PURE__ */ jsxs25(Wrapper, { ...root, "aria-labelledby": titleId, children: [
2673
+ /* @__PURE__ */ jsx33("p", { ...code, "aria-hidden": "true", children: t("pages.notFound.code") }),
2674
+ /* @__PURE__ */ jsx33("h1", { ...title, id: titleId, ...keyAttr("error.notFound"), children: t("error.notFound") }),
2675
+ /* @__PURE__ */ jsx33("p", { ...body, children: t("pages.notFound.body") }),
2676
+ /* @__PURE__ */ jsxs25("p", { ...actions, children: [
2677
+ /* @__PURE__ */ jsx33(Anchor, { ...link, href: settings.routes.shop, children: t("pages.notFound.shop") }),
2678
+ /* @__PURE__ */ jsx33(Anchor, { ...link, href: "/", children: t("pages.notFound.home") })
2679
+ ] })
2680
+ ] });
2681
+ }
2682
+
2683
+ // src/pages/SearchResults.tsx
2684
+ import { Fragment as Fragment7, jsx as jsx34, jsxs as jsxs26 } from "react/jsx-runtime";
2685
+ function SearchResults(props) {
2686
+ const { q, initialData } = props;
2687
+ const { t, keyAttr } = useStrings();
2688
+ const root = usePart("search-results", props);
2689
+ const title = usePart("search-results-title", props);
2690
+ const prompt = usePart("search-results-prompt", props);
2691
+ const term = q.trim();
2692
+ return /* @__PURE__ */ jsx34("section", { ...root, children: term === "" ? /* @__PURE__ */ jsxs26(Fragment7, { children: [
2693
+ /* @__PURE__ */ jsx34("h1", { ...title, ...keyAttr("search.title"), children: t("search.title") }),
2694
+ /* @__PURE__ */ jsx34("p", { ...prompt, children: t("pages.search.prompt") })
2695
+ ] }) : (
2696
+ // `ShopAll` draws the `search.results` heading for a search source.
2697
+ /* @__PURE__ */ jsx34(ShopAll, { source: { kind: "search", q: term }, initialData })
2698
+ ) });
2699
+ }
2700
+ export {
2701
+ AccountButton,
2702
+ ActiveFilters,
2703
+ AddToCart,
2704
+ AnnouncementBar,
2705
+ BackInStock,
2706
+ Badge,
2707
+ Breadcrumbs,
2708
+ BuyBox,
2709
+ CartButton,
2710
+ CartDrawer,
2711
+ CartLine,
2712
+ CategoryDirectory,
2713
+ CategoryList,
2714
+ CategoryNav,
2715
+ CollectionShelf,
2716
+ Compare,
2717
+ CompareButton,
2718
+ CurrencySwitch,
2719
+ DefaultLink,
2720
+ FacetGroup,
2721
+ FeaturedProduct,
2722
+ FilterBar,
2723
+ FilterDrawer,
2724
+ FilterSidebar,
2725
+ Footer,
2726
+ FrequentlyBoughtTogether,
2727
+ GA4_EVENTS,
2728
+ Gallery,
2729
+ Header,
2730
+ Image,
2731
+ JsonLd,
2732
+ Link,
2733
+ LiveRegion,
2734
+ LocaleSwitch,
2735
+ Money,
2736
+ NotFound,
2737
+ Pagination,
2738
+ Price,
2739
+ ProductCard,
2740
+ ProductCarousel,
2741
+ ProductGrid,
2742
+ ProductPage,
2743
+ ProductSections,
2744
+ QuantityInput,
2745
+ QuestionsAndAnswers,
2746
+ QuickAdd,
2747
+ QuickView,
2748
+ RecentlyViewed,
2749
+ RelatedProducts,
2750
+ ResultCount,
2751
+ ReviewForm,
2752
+ ReviewPhotos,
2753
+ ReviewVotes,
2754
+ Reviews,
2755
+ ReviewsList,
2756
+ RichText,
2757
+ SF_STRINGS_EN,
2758
+ STOREFRONT_LAYER_ORDER_ID,
2759
+ STOREFRONT_PART_KEYS,
2760
+ STOREFRONT_STYLES,
2761
+ STOREFRONT_STYLE_ID,
2762
+ SYNC_ATTRIBUTES,
2763
+ SearchBox,
2764
+ SearchResults,
2765
+ ShippingSection,
2766
+ ShopAll,
2767
+ SlotOutlet,
2768
+ SortSelect,
2769
+ StarRating,
2770
+ StickyAddToCart,
2771
+ StockStatus,
2772
+ StoreFrame,
2773
+ StorefrontProvider,
2774
+ Swatch,
2775
+ TagList,
2776
+ Unstyled,
2777
+ UnstyledContext,
2778
+ VariantPicker,
2779
+ WishlistButton,
2780
+ breadcrumbJsonLd,
2781
+ canonicalForShopQuery,
2782
+ cardBadges,
2783
+ cardFields,
2784
+ catalogSiteDesign,
2785
+ createStoredList,
2786
+ gaAnalytics,
2787
+ itemListJsonLd,
2788
+ menuHref,
2789
+ menuItems,
2790
+ noopAnalytics,
2791
+ normalizeSettings,
2792
+ pageWindow,
2793
+ parseShopQuery,
2794
+ pickerKind,
2795
+ productCrumbs,
2796
+ productJsonLd,
2797
+ productMetadata,
2798
+ productSourceQuery,
2799
+ rememberScroll,
2800
+ resolveSiteDesign,
2801
+ robotsForShopQuery,
2802
+ sanitizeHtml,
2803
+ searchMetadata,
2804
+ selectOption,
2805
+ shopAllMetadata,
2806
+ shopListQuery,
2807
+ shopQueryToSearch,
2808
+ stockWord,
2809
+ themeToVariables,
2810
+ throttleScriptsAnalytics,
2811
+ toGa4Item,
2812
+ useCartDrawer,
2813
+ useCompare,
2814
+ useHistoryRouter,
2815
+ useMerchProducts,
2816
+ usePart,
2817
+ useProductPage,
2818
+ useRecentlyViewed,
2819
+ useRelatedProducts,
2820
+ useShippingContent,
2821
+ useShopAll,
2822
+ useStorefront,
2823
+ useStrings,
2824
+ useTrack,
2825
+ useUnstyled,
2826
+ variantFromSearch
2827
+ };
2828
+ //# sourceMappingURL=index.js.map