@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
@@ -0,0 +1,2175 @@
1
+ "use client";
2
+ import {
3
+ DEFAULT_SETTINGS,
4
+ isHexColor,
5
+ isUnsafeKey,
6
+ parseHex,
7
+ resolveSiteDesign
8
+ } from "./chunk-A3IFWQUV.js";
9
+ import {
10
+ galleryItems,
11
+ isVideo,
12
+ ratioOf,
13
+ srcSetOf
14
+ } from "./chunk-66HDJVPS.js";
15
+ import {
16
+ Price,
17
+ StarRating,
18
+ routeHref,
19
+ toGa4Item
20
+ } from "./chunk-LW2A6USV.js";
21
+ import {
22
+ useTrack
23
+ } from "./chunk-IJOTLGPT.js";
24
+ import {
25
+ Image
26
+ } from "./chunk-HSUUDZWS.js";
27
+ import {
28
+ useStrings
29
+ } from "./chunk-Q3XFD5UI.js";
30
+ import {
31
+ StorefrontContext,
32
+ usePart,
33
+ useStorefront,
34
+ useUnstyled
35
+ } from "./chunk-NNE4FYRT.js";
36
+
37
+ // src/site/SlotOutlet.tsx
38
+ import { useSlotOutlet } from "@usethrottle/ui";
39
+ import { jsx } from "react/jsx-runtime";
40
+ function SlotOutlet({ name, context }) {
41
+ const Renderer = useSlotOutlet(name);
42
+ const part = usePart("slot-outlet");
43
+ if (!Renderer) return null;
44
+ return /* @__PURE__ */ jsx("div", { ...part, "data-slot": name, children: /* @__PURE__ */ jsx(Renderer, { context }) });
45
+ }
46
+
47
+ // src/url/shop-query.ts
48
+ import {
49
+ formatRange,
50
+ parseRange,
51
+ parseShopQuery as parseCatalogQuery,
52
+ serializeShopQuery
53
+ } from "@usethrottle/catalog/url";
54
+ var enabledSorts = (settings) => new Set(settings.listing.sorts.filter((s) => s.enabled).map((s) => s.key));
55
+ function explicitSort(params, settings) {
56
+ const { sort } = parseCatalogQuery(params);
57
+ return sort !== void 0 && enabledSorts(settings).has(sort) ? sort : null;
58
+ }
59
+ function parseShopQuery(params, settings, rangeKeys) {
60
+ const ranged = rangeKeys === void 0 ? null : new Set(rangeKeys);
61
+ const raw = parseCatalogQuery(params);
62
+ const filters = {};
63
+ const ranges = {};
64
+ for (const key of Object.keys(raw.filters ?? {})) {
65
+ if (isUnsafeKey(key)) continue;
66
+ for (const value of raw.filters[key]) {
67
+ const range = ranged === null || ranged.has(key) ? parseRange(value) : null;
68
+ if (range) {
69
+ if (!Object.hasOwn(ranges, key)) ranges[key] = range;
70
+ } else (filters[key] ??= []).push(value);
71
+ }
72
+ }
73
+ for (const key of Object.keys(filters)) filters[key] = [...new Set(filters[key])].sort();
74
+ const query = {
75
+ filters,
76
+ ranges,
77
+ sort: explicitSort(params, settings) ?? settings.listing.defaultSort,
78
+ page: raw.page !== void 0 && raw.page >= 1 ? raw.page : 1
79
+ };
80
+ if (raw.q) query.q = raw.q;
81
+ return query;
82
+ }
83
+ function toCatalogQuery(q, settings) {
84
+ const filters = {};
85
+ for (const key of Object.keys(q.filters)) filters[key] = [...q.filters[key]];
86
+ for (const key of Object.keys(q.ranges)) (filters[key] ??= []).push(formatRange(q.ranges[key]));
87
+ for (const key of Object.keys(filters)) filters[key] = [...new Set(filters[key])].sort();
88
+ return {
89
+ ...q.q ? { q: q.q } : {},
90
+ ...Object.keys(filters).length > 0 ? { filters } : {},
91
+ ...q.sort !== settings.listing.defaultSort ? { sort: q.sort } : {},
92
+ ...q.page > 1 ? { page: q.page } : {}
93
+ };
94
+ }
95
+ function shopQueryToSearch(q, settings) {
96
+ return serializeShopQuery(toCatalogQuery(q, settings));
97
+ }
98
+ function pageWindow(current, count) {
99
+ const pages = [.../* @__PURE__ */ new Set([1, current - 1, current, current + 1, count])].filter((p) => p >= 1 && p <= count).sort((a, b) => a - b);
100
+ const out = [];
101
+ for (const [i, p] of pages.entries()) {
102
+ if (i > 0 && p - pages[i - 1] > 1) out.push(null);
103
+ out.push(p);
104
+ }
105
+ return out;
106
+ }
107
+ function variantFromSearch(params, product) {
108
+ const value = params instanceof URLSearchParams ? params.get("variant") : params.variant;
109
+ const sku = Array.isArray(value) ? value[0] : value;
110
+ return sku !== void 0 && product.variants.some((v) => v.sku === sku) ? sku : null;
111
+ }
112
+ var filterValueCount = (q) => Object.values(q.filters).reduce((n, values) => n + values.length, 0) + Object.keys(q.ranges).length;
113
+ function robotsForShopQuery(q, settings) {
114
+ return { index: filterValueCount(q) <= 1 && q.sort === settings.listing.defaultSort && !q.q, follow: true };
115
+ }
116
+ function canonicalForShopQuery(baseUrl, pathname, q, settings, source) {
117
+ const first = [
118
+ ...Object.entries(q.filters).flatMap(([key, values]) => values.map((value) => ({ key, value }))),
119
+ ...Object.entries(q.ranges).map(([key, range]) => ({ key, value: formatRange(range) }))
120
+ ].sort((a, b) => a.key === b.key ? a.value.localeCompare(b.value) : a.key.localeCompare(b.key))[0];
121
+ const kept = {
122
+ filters: {},
123
+ ranges: {},
124
+ sort: settings.listing.defaultSort,
125
+ page: q.page,
126
+ ...q.q && source?.kind === "search" ? { q: q.q } : {}
127
+ };
128
+ if (first) {
129
+ const range = parseRange(first.value);
130
+ if (range) kept.ranges[first.key] = range;
131
+ else kept.filters[first.key] = [first.value];
132
+ }
133
+ const search = shopQueryToSearch(kept, settings);
134
+ return `${baseUrl.replace(/\/+$/u, "")}${pathname}${search ? `?${search}` : ""}`;
135
+ }
136
+
137
+ // src/seo/JsonLd.tsx
138
+ import { jsx as jsx2 } from "react/jsx-runtime";
139
+ function JsonLd({ data }) {
140
+ return /* @__PURE__ */ jsx2(
141
+ "script",
142
+ {
143
+ type: "application/ld+json",
144
+ dangerouslySetInnerHTML: { __html: JSON.stringify(data).replace(/</gu, "\\u003c") }
145
+ }
146
+ );
147
+ }
148
+
149
+ // src/seo/json-ld.ts
150
+ import { toDecimalString } from "@usethrottle/money";
151
+ var SCHEMA = "https://schema.org";
152
+ var availabilityOf = (states) => {
153
+ if (states.includes("in_stock")) return `${SCHEMA}/InStock`;
154
+ if (states.includes("preorder")) return `${SCHEMA}/PreOrder`;
155
+ if (states.includes("backorder")) return `${SCHEMA}/BackOrder`;
156
+ return `${SCHEMA}/OutOfStock`;
157
+ };
158
+ function productJsonLd(product, o) {
159
+ const priced = product.variants.map((v) => ({ minor: v.salePriceMinor ?? v.priceMinor, currency: v.currency ?? o.currency })).filter((p) => p.minor !== null && p.currency === o.currency);
160
+ const lowest = priced.sort((a, b) => a.minor - b.minor)[0];
161
+ const price = lowest ?? (product.priceRange ? { minor: product.priceRange.minMinor, currency: product.priceRange.currency } : null);
162
+ const store = o.settings.brand.storeName.trim();
163
+ const description = product.shortDescription ?? product.description;
164
+ return {
165
+ "@context": SCHEMA,
166
+ "@type": "Product",
167
+ name: product.title ?? product.handle,
168
+ ...description ? { description } : {},
169
+ ...product.images.length > 0 ? { image: product.images.map((i) => i.url) } : {},
170
+ ...product.brand ? { brand: { "@type": "Brand", name: product.brand } } : {},
171
+ ...product.variants[0] ? { sku: product.variants[0].sku } : {},
172
+ url: o.url,
173
+ offers: {
174
+ "@type": "Offer",
175
+ url: o.url,
176
+ ...price ? { price: toDecimalString(price.minor, price.currency), priceCurrency: price.currency } : {},
177
+ availability: availabilityOf(
178
+ product.variants.length > 0 ? product.variants.map((v) => v.availability) : [product.availability]
179
+ ),
180
+ ...store ? { seller: { "@type": "Organization", name: store } } : {}
181
+ }
182
+ };
183
+ }
184
+ function breadcrumbJsonLd(crumbs) {
185
+ return {
186
+ "@context": SCHEMA,
187
+ "@type": "BreadcrumbList",
188
+ itemListElement: crumbs.map((c, i) => ({ "@type": "ListItem", position: i + 1, name: c.name, item: c.url }))
189
+ };
190
+ }
191
+ function itemListJsonLd(products, o) {
192
+ const base = o.baseUrl.replace(/\/+$/u, "");
193
+ return {
194
+ "@context": SCHEMA,
195
+ "@type": "ItemList",
196
+ itemListElement: products.map((p, i) => ({
197
+ "@type": "ListItem",
198
+ position: i + 1,
199
+ url: `${base}${routeHref(o.settings, "product", p.handle)}`,
200
+ ...p.title ? { name: p.title } : {}
201
+ }))
202
+ };
203
+ }
204
+
205
+ // src/seo/metadata.ts
206
+ var origin = (baseUrl) => baseUrl.replace(/\/+$/u, "");
207
+ var absolute = (baseUrl, path) => `${origin(baseUrl)}${path}`;
208
+ function pageTitle(template, store, page) {
209
+ const name = page.trim();
210
+ const shop = store.trim();
211
+ if (name === "") return shop;
212
+ if (shop === "") return name;
213
+ return template.split("{page}").join(name).split("{store}").join(shop);
214
+ }
215
+ function resolved(data, o) {
216
+ return resolveSiteDesign({ site: o.site ?? null, settings: data.settings });
217
+ }
218
+ var nonEmpty = (value) => value && value.trim() ? value : void 0;
219
+ function openGraph(title, description, images) {
220
+ const urls = images.filter((u) => Boolean(u));
221
+ return { title, ...description ? { description } : {}, ...urls.length > 0 ? { images: urls } : {} };
222
+ }
223
+ function listingPath(settings, source) {
224
+ switch (source.kind) {
225
+ case "all":
226
+ return settings.routes.shop;
227
+ case "search":
228
+ return settings.routes.search.split("?")[0];
229
+ default:
230
+ return routeHref(settings, source.kind, source.handle);
231
+ }
232
+ }
233
+ function shopAllMetadata(data, o) {
234
+ const site = resolved(data, o);
235
+ const title = pageTitle(site.seo.titleTemplate, site.brand.storeName, data.seoTitle ?? data.title);
236
+ const description = nonEmpty(data.description) ?? nonEmpty(site.seo.defaultDescription);
237
+ return {
238
+ title,
239
+ ...description ? { description } : {},
240
+ alternates: {
241
+ canonical: canonicalForShopQuery(o.baseUrl, listingPath(data.settings, data.source), data.query, data.settings, data.source)
242
+ },
243
+ robots: robotsForShopQuery(data.query, data.settings),
244
+ openGraph: openGraph(title, description, [site.seo.shareImage])
245
+ };
246
+ }
247
+ function searchMetadata(data, o) {
248
+ return { ...shopAllMetadata(data, o), robots: { index: false, follow: true } };
249
+ }
250
+ function productMetadata(data, o) {
251
+ const { product } = data;
252
+ const site = resolved(data, o);
253
+ const name = nonEmpty(product.seoTitle) ?? nonEmpty(product.seo?.title) ?? product.title ?? product.handle;
254
+ const title = pageTitle(site.seo.titleTemplate, site.brand.storeName, name);
255
+ const description = nonEmpty(product.seoDescription) ?? nonEmpty(product.seo?.description) ?? nonEmpty(product.shortDescription) ?? nonEmpty(product.description) ?? nonEmpty(site.seo.defaultDescription);
256
+ return {
257
+ title,
258
+ ...description ? { description } : {},
259
+ alternates: { canonical: absolute(o.baseUrl, routeHref(data.settings, "product", product.handle)) },
260
+ openGraph: openGraph(title, description, [product.images[0]?.url ?? site.seo.shareImage])
261
+ };
262
+ }
263
+
264
+ // src/pieces/Badge.tsx
265
+ import { jsx as jsx3 } from "react/jsx-runtime";
266
+ var KIND_BACKGROUND = {
267
+ sale: "var(--throttle-sf-sale)",
268
+ new: "var(--throttle-sf-accent)",
269
+ lowStock: "var(--throttle-sf-warning)"
270
+ };
271
+ function ink(hex) {
272
+ const [r, g, b] = parseHex(hex).map((c) => {
273
+ const v = c / 255;
274
+ return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
275
+ });
276
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b > 0.4 ? "#20150e" : "#ffffff";
277
+ }
278
+ function Badge({ kind, tone, children, classNames, className, unstyled }) {
279
+ const part = usePart("product-badge", { classNames, className, unstyled });
280
+ const style = {};
281
+ if (isHexColor(tone)) {
282
+ style["--tsf-badge-bg"] = tone;
283
+ style["--tsf-badge-fg"] = ink(tone);
284
+ } else if (kind && KIND_BACKGROUND[kind]) {
285
+ style["--tsf-badge-bg"] = KIND_BACKGROUND[kind];
286
+ }
287
+ return /* @__PURE__ */ jsx3("span", { ...part, "data-badge": kind, style: Object.keys(style).length > 0 ? style : void 0, children });
288
+ }
289
+
290
+ // src/pieces/badges.ts
291
+ var DAY_MS = 864e5;
292
+ function createdAtOf(product) {
293
+ const at = product.createdAt;
294
+ const time = typeof at === "string" ? Date.parse(at) : NaN;
295
+ return Number.isNaN(time) ? null : time;
296
+ }
297
+ function isNew(product, days, generatedAt) {
298
+ const created = createdAtOf(product);
299
+ const now = Date.parse(generatedAt);
300
+ if (created === null || Number.isNaN(now)) return product.badges?.new === true;
301
+ return now - created <= days * DAY_MS;
302
+ }
303
+ function isSale(product) {
304
+ const range = product.priceRange;
305
+ if (!range) return product.badges?.sale === true;
306
+ const compareAt = "compareAtMinMinor" in range ? range.compareAtMinMinor : null;
307
+ return typeof compareAt === "number" && compareAt > range.minMinor;
308
+ }
309
+ var toneOf = (colour, catalogDefault) => isHexColor(colour) && colour.toLowerCase() !== catalogDefault.toLowerCase() ? colour : void 0;
310
+ function cardBadges(settings, product, generatedAt) {
311
+ if (!settings.card.showBadges) return [];
312
+ const { badges } = settings;
313
+ const out = [];
314
+ const add = (kind, label, tone) => out.push(tone === void 0 ? { kind, label } : { kind, label, tone });
315
+ if (badges.new.enabled && isNew(product, badges.new.days, generatedAt))
316
+ add("new", badges.new.label, toneOf(badges.new.colour, DEFAULT_SETTINGS.badges.new.colour));
317
+ if (badges.sale.enabled && isSale(product))
318
+ add("sale", badges.sale.label, toneOf(badges.sale.colour, DEFAULT_SETTINGS.badges.sale.colour));
319
+ if (badges.lowStock.enabled && product.lowStock && product.availability !== "out_of_stock")
320
+ add("lowStock", badges.lowStock.label);
321
+ for (const custom of badges.custom)
322
+ if (product.tags?.includes(custom.tag)) add("custom", custom.label, isHexColor(custom.colour) ? custom.colour : void 0);
323
+ return out;
324
+ }
325
+
326
+ // src/pieces/reserved.tsx
327
+ function WishlistButton(_props) {
328
+ return null;
329
+ }
330
+ function BackInStock(_props) {
331
+ return null;
332
+ }
333
+ function FrequentlyBoughtTogether(_props) {
334
+ return null;
335
+ }
336
+ function ReviewPhotos(_props) {
337
+ return null;
338
+ }
339
+ function ReviewVotes(_props) {
340
+ return null;
341
+ }
342
+ function QuestionsAndAnswers(_props) {
343
+ return null;
344
+ }
345
+
346
+ // src/pieces/Swatch.tsx
347
+ import { jsx as jsx4 } from "react/jsx-runtime";
348
+ function Swatch({ value, hex, image, selected, disabled, classNames, className, unstyled }) {
349
+ const part = usePart("swatch", { classNames, className, unstyled });
350
+ return /* @__PURE__ */ jsx4(
351
+ "span",
352
+ {
353
+ ...part,
354
+ role: "img",
355
+ "aria-label": value,
356
+ "data-selected": selected ? "true" : void 0,
357
+ "data-disabled": disabled ? "true" : void 0,
358
+ style: image ? { backgroundImage: `url(${JSON.stringify(image)})` } : isHexColor(hex) ? { backgroundColor: hex } : void 0
359
+ }
360
+ );
361
+ }
362
+
363
+ // src/product/variant-logic.ts
364
+ var DROPDOWN_ABOVE = 8;
365
+ function pickerKind(option) {
366
+ const { values } = option;
367
+ if (values.length > 0 && values.every((v) => v.swatch !== void 0 && v.swatch !== null)) return "swatch";
368
+ return values.length > DROPDOWN_ABOVE ? "dropdown" : "buttons";
369
+ }
370
+ var optionsOf = (variant) => variant.options ?? {};
371
+ var matches = (variant, selection) => {
372
+ const own = optionsOf(variant);
373
+ return Object.entries(selection).every(([name, value]) => own[name] === value);
374
+ };
375
+ var isSoldOut = (variant) => variant.availability === "out_of_stock" || !variant.purchasable;
376
+ function variantForSelection(product, selection) {
377
+ return product.variants.find((v) => matches(v, selection));
378
+ }
379
+ function pickVariant(product, sku) {
380
+ const { variants } = product;
381
+ return variants.find((v) => v.sku === sku) ?? variants.find((v) => !isSoldOut(v)) ?? variants[0];
382
+ }
383
+ function selectOption(product, current, name, value) {
384
+ const selection = { ...current, [name]: value };
385
+ const variant = variantForSelection(product, selection);
386
+ return { selection, sku: variant?.sku ?? null, soldOut: variant ? isSoldOut(variant) : false };
387
+ }
388
+ function nearestVariant(product, current, name, value) {
389
+ const others = Object.entries(current).filter(([k]) => k !== name);
390
+ let best;
391
+ for (const variant of product.variants) {
392
+ const own = optionsOf(variant);
393
+ if (own[name] !== value) continue;
394
+ const kept = others.filter(([k, v]) => own[k] === v).length;
395
+ const better = !best || kept > best.kept || kept === best.kept && isSoldOut(best.variant) && !isSoldOut(variant);
396
+ if (better) best = { variant, kept };
397
+ }
398
+ return best?.variant;
399
+ }
400
+ function valueState(product, current, name, value) {
401
+ const result = selectOption(product, current, name, value);
402
+ if (result.sku === null) return "unavailable";
403
+ return result.soldOut ? "sold-out" : "available";
404
+ }
405
+ function stockOf(product, variant) {
406
+ if (product.availableInCurrency === false || variant.priceMinor === null) return "no_currency";
407
+ if (isSoldOut(variant)) return "out";
408
+ if (variant.availability === "preorder") return "preorder";
409
+ if (variant.availability === "backorder") return "backorder";
410
+ return variant.lowStock ? "low" : "in_stock";
411
+ }
412
+ function quantityBounds(variant) {
413
+ const max = variant?.maxOrderQuantity;
414
+ return { min: 1, max: typeof max === "number" && max >= 1 ? Math.floor(max) : void 0 };
415
+ }
416
+ function clampQuantity(value, max) {
417
+ const whole = Number.isFinite(value) ? Math.floor(value) : 1;
418
+ return Math.min(max ?? Number.POSITIVE_INFINITY, Math.max(1, whole));
419
+ }
420
+
421
+ // src/product/use-product-page.ts
422
+ import { isCatalogError } from "@usethrottle/catalog";
423
+ import { useCart } from "@usethrottle/catalog/react";
424
+ import { toDecimalString as toDecimalString2 } from "@usethrottle/money";
425
+ import { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
426
+ var ProductPageContext = createContext(null);
427
+ function useProductPage() {
428
+ const value = useContext(ProductPageContext);
429
+ if (!value) throw new Error("useProductPage() was called outside <ProductPage.Root>.");
430
+ return value;
431
+ }
432
+ var decimal = (minor, currency) => Number(toDecimalString2(minor, currency));
433
+ function refusedLine(error, sku) {
434
+ if (!isCatalogError(error)) return null;
435
+ const lines = error.lines;
436
+ if (!Array.isArray(lines)) return null;
437
+ return lines.find((l) => l.sku === sku) ?? lines[0] ?? null;
438
+ }
439
+ function useProductPageState(input) {
440
+ const { product, priceContext, initialSku } = input;
441
+ const { router, currency: storeCurrency } = useStorefront();
442
+ const { t } = useStrings();
443
+ const track = useTrack();
444
+ const cart = useCart(storeCurrency ? { currency: storeCurrency } : void 0);
445
+ const sectionsId = useId();
446
+ const addToCartRef = useRef(null);
447
+ const revealSectionRef = useRef(null);
448
+ const urlSku = variantFromSearch(router.searchParams, product);
449
+ const [chosen, setChosen] = useState(null);
450
+ useEffect(() => {
451
+ setChosen(null);
452
+ }, [urlSku, product.handle]);
453
+ const variant = pickVariant(product, chosen ?? urlSku ?? initialSku);
454
+ const sku = variant?.sku ?? null;
455
+ const selection = useMemo(() => ({ ...variant?.options ?? {} }), [variant]);
456
+ const stock = variant ? stockOf(product, variant) : null;
457
+ const selectOption2 = useCallback(
458
+ (name, value) => {
459
+ const result = selectOption(product, selection, name, value);
460
+ const next = result.sku ?? nearestVariant(product, selection, name, value)?.sku ?? null;
461
+ if (next === null) return;
462
+ setChosen(next);
463
+ const params = new URLSearchParams(router.searchParams.toString());
464
+ params.set("variant", next);
465
+ router.replace(`${router.pathname}?${params.toString()}`, { scroll: false });
466
+ },
467
+ [product, selection, router]
468
+ );
469
+ const maxQuantity = quantityBounds(variant).max;
470
+ const [wanted, setWanted] = useState(1);
471
+ const quantity = clampQuantity(wanted, maxQuantity);
472
+ const setQuantity = useCallback((n) => setWanted(clampQuantity(n, maxQuantity)), [maxQuantity]);
473
+ const eventCurrency = variant?.currency ?? product.priceRange?.currency ?? storeCurrency;
474
+ const unitMinor = variant ? variant.salePriceMinor ?? variant.priceMinor : null;
475
+ const seen = useRef(/* @__PURE__ */ new Set());
476
+ useEffect(() => {
477
+ if (!sku || !eventCurrency || seen.current.has(sku)) return;
478
+ seen.current.add(sku);
479
+ track("view_item", {
480
+ currency: eventCurrency,
481
+ ...unitMinor !== null ? { value: decimal(unitMinor, eventCurrency) } : {},
482
+ items: [toGa4Item(product, { variantSku: sku })]
483
+ });
484
+ }, [sku, eventCurrency, unitMinor, product, track]);
485
+ const [adding, setAdding] = useState(false);
486
+ const [message, setMessage] = useState(null);
487
+ const title = product.title ?? product.handle;
488
+ const add = useCallback(async () => {
489
+ if (!sku || adding) return;
490
+ setAdding(true);
491
+ setMessage(null);
492
+ try {
493
+ await cart.add(sku, quantity);
494
+ if (eventCurrency) {
495
+ track("add_to_cart", {
496
+ currency: eventCurrency,
497
+ ...unitMinor !== null ? { value: decimal(unitMinor * quantity, eventCurrency) } : {},
498
+ items: [toGa4Item(product, { variantSku: sku, quantity })]
499
+ });
500
+ }
501
+ setMessage({ tone: "ok", text: t("product.cartAdd.added", { quantity, title }) });
502
+ } catch (error) {
503
+ if (error instanceof DOMException && error.name === "AbortError") return;
504
+ const line = refusedLine(error, sku);
505
+ const left = line?.maxQuantity;
506
+ setMessage({
507
+ tone: "refused",
508
+ text: left === 0 ? t("product.cartAdd.outOfStock") : typeof left === "number" ? t("product.cartAdd.onlyLeft", { count: left }) : t("product.cartAdd.failed")
509
+ });
510
+ } finally {
511
+ setAdding(false);
512
+ }
513
+ }, [sku, adding, cart, quantity, eventCurrency, unitMinor, product, title, track, t]);
514
+ return {
515
+ product,
516
+ priceContext,
517
+ selection,
518
+ sku,
519
+ variant,
520
+ stock,
521
+ selectOption: selectOption2,
522
+ quantity,
523
+ setQuantity,
524
+ maxQuantity,
525
+ add,
526
+ adding,
527
+ message,
528
+ layout: input.layout,
529
+ sectionsStyle: input.sectionsStyle,
530
+ reviewsLayout: input.reviewsLayout ?? "stack",
531
+ related: input.related,
532
+ generatedAt: input.generatedAt,
533
+ baseUrl: input.baseUrl,
534
+ addToCartRef,
535
+ revealSectionRef,
536
+ initialReviews: input.reviews,
537
+ shippingPage: input.shippingPage,
538
+ sectionsId
539
+ };
540
+ }
541
+
542
+ // src/product/AddToCart.tsx
543
+ import { Spinner } from "@usethrottle/ui";
544
+ import { jsx as jsx5, jsxs } from "react/jsx-runtime";
545
+ function AddToCart({ classNames, className, unstyled }) {
546
+ const local = { classNames, unstyled };
547
+ const { add, adding, stock, sku, message, addToCartRef } = useProductPage();
548
+ const { t } = useStrings();
549
+ const root = usePart("add-to-cart", { ...local, className });
550
+ const button = usePart("add-to-cart-button", local);
551
+ const status = usePart("add-to-cart-message", local);
552
+ const cannot = !sku || stock === "out" || stock === "no_currency";
553
+ return /* @__PURE__ */ jsxs("div", { ...root, ref: (el) => {
554
+ addToCartRef.current = el;
555
+ }, children: [
556
+ /* @__PURE__ */ jsxs(
557
+ "button",
558
+ {
559
+ ...button,
560
+ type: "button",
561
+ disabled: cannot,
562
+ "aria-disabled": adding || void 0,
563
+ "aria-busy": adding || void 0,
564
+ "data-adding": adding ? "true" : void 0,
565
+ onClick: () => {
566
+ if (!adding) void add();
567
+ },
568
+ children: [
569
+ adding ? /* @__PURE__ */ jsx5(Spinner, {}) : null,
570
+ adding ? t("product.cartAdd.adding") : t("product.addToCart")
571
+ ]
572
+ }
573
+ ),
574
+ /* @__PURE__ */ jsx5("p", { ...status, role: "status", "aria-live": "polite", "data-tone": message?.tone, children: message?.text })
575
+ ] });
576
+ }
577
+
578
+ // src/product/Breadcrumbs.tsx
579
+ import { jsx as jsx6 } from "react/jsx-runtime";
580
+ import { createElement } from "react";
581
+ function productCrumbs(product, settings, homeLabel) {
582
+ return [
583
+ { name: settings.brand.storeName.trim() || homeLabel, href: "/" },
584
+ ...(product.breadcrumbs ?? []).map((c) => ({ name: c.name, href: routeHref(settings, "category", c.handle) })),
585
+ { name: product.title ?? product.handle, href: routeHref(settings, "product", product.handle) }
586
+ ];
587
+ }
588
+ function Breadcrumbs({ classNames, className, unstyled }) {
589
+ const local = { classNames, unstyled };
590
+ const { product } = useProductPage();
591
+ const { settings, Link: Anchor } = useStorefront();
592
+ const { t } = useStrings();
593
+ const root = usePart("product-breadcrumbs", { ...local, className });
594
+ const list = usePart("product-breadcrumbs-list", local);
595
+ const item = usePart("product-breadcrumbs-item", local);
596
+ const link = usePart("product-breadcrumbs-link", local);
597
+ const current = usePart("product-breadcrumbs-current", local);
598
+ const crumbs = productCrumbs(product, settings, t("product.crumbs.home"));
599
+ return /* @__PURE__ */ jsx6("nav", { ...root, "aria-label": t("product.crumbs.label"), children: /* @__PURE__ */ jsx6("ol", { ...list, children: crumbs.map((crumb, i) => /* @__PURE__ */ createElement("li", { ...item, key: `${crumb.href}-${i}` }, i === crumbs.length - 1 ? /* @__PURE__ */ jsx6("span", { ...current, "aria-current": "page", children: crumb.name }) : /* @__PURE__ */ jsx6(Anchor, { ...link, href: crumb.href, children: crumb.name }))) }) });
600
+ }
601
+
602
+ // src/product/QuantityInput.tsx
603
+ import { VisuallyHidden } from "@usethrottle/ui";
604
+ import { useEffect as useEffect2, useId as useId2, useState as useState2 } from "react";
605
+ import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
606
+ function QuantityInput({ classNames, className, unstyled }) {
607
+ const local = { classNames, unstyled };
608
+ const { quantity, setQuantity, maxQuantity, stock } = useProductPage();
609
+ const { t } = useStrings();
610
+ const id = useId2();
611
+ const root = usePart("quantity-input", { ...local, className });
612
+ const decrease = usePart("quantity-decrease", local);
613
+ const field = usePart("quantity-field", local);
614
+ const increase = usePart("quantity-increase", local);
615
+ const [text, setText] = useState2(String(quantity));
616
+ useEffect2(() => setText(String(quantity)), [quantity]);
617
+ const disabled = stock === "out" || stock === "no_currency";
618
+ return /* @__PURE__ */ jsxs2("div", { ...root, children: [
619
+ /* @__PURE__ */ jsx7("label", { htmlFor: id, children: /* @__PURE__ */ jsx7(VisuallyHidden, { children: t("product.quantity") }) }),
620
+ /* @__PURE__ */ jsx7(
621
+ "button",
622
+ {
623
+ ...decrease,
624
+ type: "button",
625
+ "aria-label": t("product.quantityInput.decrease"),
626
+ disabled,
627
+ "aria-disabled": quantity <= 1 || void 0,
628
+ onClick: () => quantity > 1 && setQuantity(quantity - 1),
629
+ children: "\u2212"
630
+ }
631
+ ),
632
+ /* @__PURE__ */ jsx7(
633
+ "input",
634
+ {
635
+ ...field,
636
+ id,
637
+ type: "number",
638
+ inputMode: "numeric",
639
+ min: 1,
640
+ max: maxQuantity,
641
+ value: text,
642
+ disabled,
643
+ onChange: (e) => {
644
+ const raw = e.target.value;
645
+ if (raw === "") return setText("");
646
+ const n = Number.parseInt(raw, 10);
647
+ if (Number.isNaN(n)) return;
648
+ const held = clampQuantity(n, maxQuantity);
649
+ setText(String(held));
650
+ setQuantity(held);
651
+ },
652
+ onBlur: () => setText(String(quantity))
653
+ }
654
+ ),
655
+ /* @__PURE__ */ jsx7(
656
+ "button",
657
+ {
658
+ ...increase,
659
+ type: "button",
660
+ "aria-label": t("product.quantityInput.increase"),
661
+ disabled,
662
+ "aria-disabled": maxQuantity !== void 0 && quantity >= maxQuantity || void 0,
663
+ onClick: () => (maxQuantity === void 0 || quantity < maxQuantity) && setQuantity(quantity + 1),
664
+ children: "+"
665
+ }
666
+ )
667
+ ] });
668
+ }
669
+
670
+ // src/product/StockStatus.tsx
671
+ import { jsx as jsx8 } from "react/jsx-runtime";
672
+ var WORD_KEY = {
673
+ in_stock: "inStock",
674
+ low: "lowStock",
675
+ preorder: "preorder",
676
+ backorder: "backorder",
677
+ out: "outOfStock"
678
+ };
679
+ var ENGLISH = {
680
+ inStock: "In stock",
681
+ lowStock: "Only a few left",
682
+ outOfStock: "Out of stock",
683
+ backorder: "Available on backorder",
684
+ preorder: "Pre-order"
685
+ };
686
+ function stockWord(settings, key, count) {
687
+ const word = settings.stock.words[key].trim() || ENGLISH[key];
688
+ if (!word.includes("{count}")) return word;
689
+ if (count !== void 0) return word.split("{count}").join(String(count));
690
+ return settings.badges.lowStock.label.trim() || ENGLISH.lowStock;
691
+ }
692
+ function StockStatus({ classNames, className, unstyled }) {
693
+ const { stock, variant } = useProductPage();
694
+ const { settings, currency } = useStorefront();
695
+ const { t } = useStrings();
696
+ const part = usePart("stock-status", { classNames, className, unstyled });
697
+ const state = stock ?? "out";
698
+ const shown = variant?.currency ?? currency;
699
+ const text = state === "no_currency" ? shown ? t("product.stockStatus.noCurrency", { currency: shown }) : t("product.stockStatus.noCurrencyAny") : stockWord(settings, WORD_KEY[state]);
700
+ return /* @__PURE__ */ jsx8("p", { ...part, "data-state": state, "data-stock-words": state === "no_currency" ? void 0 : WORD_KEY[state], children: text });
701
+ }
702
+
703
+ // src/product/VariantPicker.tsx
704
+ import { Select, VisuallyHidden as VisuallyHidden2 } from "@usethrottle/ui";
705
+ import { jsx as jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
706
+ import { createElement as createElement2 } from "react";
707
+ var swatchProps = (swatch) => !swatch ? {} : "color" in swatch ? { hex: swatch.color } : { image: swatch.url };
708
+ function OptionGroup({ option, kind, ...local }) {
709
+ const { product, selection, selectOption: selectOption2 } = useProductPage();
710
+ const { t } = useStrings();
711
+ const group = usePart("variant-option", local);
712
+ const legend = usePart("variant-option-legend", local);
713
+ const nameOf = usePart("variant-option-name", local);
714
+ const chosenOf = usePart("variant-option-chosen", local);
715
+ const values = usePart("variant-option-values", local);
716
+ const value = usePart("variant-value", local);
717
+ const label = usePart("variant-value-label", local);
718
+ const chosen = selection[option.name];
719
+ const others = Object.entries(selection).filter(([name]) => name !== option.name).map(([, v]) => v).join(" / ");
720
+ if (kind === "dropdown") {
721
+ return /* @__PURE__ */ jsx9("div", { ...group, "data-option-name": option.name, "data-picker": kind, children: /* @__PURE__ */ jsx9(
722
+ Select,
723
+ {
724
+ label: option.name,
725
+ value: chosen ?? "",
726
+ placeholder: chosen === void 0 ? t("product.options.chooseOne", { option: option.name }) : void 0,
727
+ options: option.values.map((v) => {
728
+ const state = valueState(product, selection, option.name, v.value);
729
+ return { value: v.value, label: state === "sold-out" ? `${v.value}${t("product.options.soldOut")}` : v.value };
730
+ }),
731
+ onChange: (next) => next !== "" && selectOption2(option.name, next)
732
+ }
733
+ ) });
734
+ }
735
+ return /* @__PURE__ */ jsxs3("fieldset", { ...group, "data-option-name": option.name, "data-picker": kind, children: [
736
+ /* @__PURE__ */ jsxs3("legend", { ...legend, children: [
737
+ /* @__PURE__ */ jsx9("span", { ...nameOf, children: option.name }),
738
+ chosen ? /* @__PURE__ */ jsx9("span", { ...chosenOf, children: chosen }) : null
739
+ ] }),
740
+ /* @__PURE__ */ jsx9("div", { ...values, children: option.values.map((v) => {
741
+ const state = valueState(product, selection, option.name, v.value);
742
+ const pressed = chosen === v.value;
743
+ return /* @__PURE__ */ createElement2(
744
+ "button",
745
+ {
746
+ ...value,
747
+ key: v.value,
748
+ type: "button",
749
+ "data-value": v.value,
750
+ "data-kind": kind,
751
+ "aria-pressed": pressed,
752
+ "aria-disabled": false,
753
+ "data-sold-out": state === "sold-out" ? "" : void 0,
754
+ "data-unavailable": state === "unavailable" ? "" : void 0,
755
+ onClick: () => selectOption2(option.name, v.value)
756
+ },
757
+ kind === "swatch" ? /* @__PURE__ */ jsx9(Swatch, { ...local, ...swatchProps(v.swatch), value: v.value, selected: pressed }) : /* @__PURE__ */ jsx9("span", { ...label, children: v.value }),
758
+ state === "sold-out" ? /* @__PURE__ */ jsx9(VisuallyHidden2, { children: t("product.options.soldOut") }) : null,
759
+ state === "unavailable" ? /* @__PURE__ */ jsx9(VisuallyHidden2, { children: t("product.options.unavailableWith", { others: others || option.name }) }) : null
760
+ );
761
+ }) })
762
+ ] });
763
+ }
764
+ function VariantPicker({ classNames, className, unstyled }) {
765
+ const { product } = useProductPage();
766
+ const root = usePart("variant-picker", { classNames, className, unstyled });
767
+ const options = product.options ?? [];
768
+ if (options.length === 0) return null;
769
+ return /* @__PURE__ */ jsx9("div", { ...root, children: options.map((option) => /* @__PURE__ */ jsx9(OptionGroup, { option, kind: pickerKind(option), classNames, unstyled }, option.name)) });
770
+ }
771
+
772
+ // src/product/BuyBox.tsx
773
+ import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
774
+ var DEFAULT_SLOTS = { Price, VariantPicker, StockStatus, QuantityInput, AddToCart, WishlistButton, BackInStock };
775
+ function BuyBox({ slots, classNames, className, unstyled, headingLevel = 1 }) {
776
+ const Heading = `h${headingLevel}`;
777
+ const local = { classNames, unstyled };
778
+ const s = { ...DEFAULT_SLOTS, ...slots };
779
+ const { product, variant, priceContext, revealSectionRef, sectionsId } = useProductPage();
780
+ const { settings, currency } = useStorefront();
781
+ const { t, keyAttr } = useStrings();
782
+ const root = usePart("buy-box", { ...local, className });
783
+ const kicker = usePart("buy-box-kicker", local);
784
+ const title = usePart("buy-box-title", local);
785
+ const ratingLink = usePart("buy-box-rating", local);
786
+ const summary = usePart("buy-box-summary", local);
787
+ const priceRow = usePart("buy-box-price", local);
788
+ const sku = usePart("buy-box-sku", local);
789
+ const actions = usePart("buy-box-actions", local);
790
+ const kickerText = [product.productType, product.brand].filter(Boolean).join(" \xB7 ");
791
+ const rating = product.rating;
792
+ const showRating = rating && rating.count > 0 && rating.average !== null && settings.product.sections.some((x) => x.key === "reviews" && x.enabled);
793
+ const now = variant ? variant.salePriceMinor ?? variant.priceMinor : null;
794
+ const was = variant ? variant.salePriceMinor !== null && variant.priceMinor !== null ? variant.priceMinor : variant.compareAtPriceMinor ?? void 0 : void 0;
795
+ const priced = variant?.currency ?? currency;
796
+ return /* @__PURE__ */ jsxs4("div", { ...root, children: [
797
+ kickerText ? /* @__PURE__ */ jsx10("p", { ...kicker, children: kickerText }) : null,
798
+ /* @__PURE__ */ jsx10(Heading, { ...title, children: product.title ?? product.handle }),
799
+ showRating ? /* @__PURE__ */ jsx10(
800
+ "a",
801
+ {
802
+ ...ratingLink,
803
+ href: `#${sectionsId}-panel-reviews`,
804
+ onClick: (e) => {
805
+ if (revealSectionRef.current?.("reviews")) {
806
+ e.preventDefault();
807
+ requestAnimationFrame(() => document.getElementById(`${sectionsId}-panel-reviews`)?.scrollIntoView({ block: "start" }));
808
+ }
809
+ },
810
+ children: /* @__PURE__ */ jsx10(StarRating, { ...local, value: rating.average, count: rating.count })
811
+ }
812
+ ) : null,
813
+ product.shortDescription ? /* @__PURE__ */ jsx10("p", { ...summary, children: product.shortDescription }) : null,
814
+ now !== null && priced ? /* @__PURE__ */ jsx10("p", { ...priceRow, children: /* @__PURE__ */ jsx10(s.Price, { ...local, minor: now, currency: priced, compareAtMinor: was ?? void 0, priceContext }) }) : null,
815
+ /* @__PURE__ */ jsx10(s.VariantPicker, { ...local }),
816
+ /* @__PURE__ */ jsx10(s.StockStatus, { ...local }),
817
+ variant ? /* @__PURE__ */ jsxs4("p", { ...sku, children: [
818
+ /* @__PURE__ */ jsx10("span", { ...keyAttr("product.sku"), children: t("product.sku") }),
819
+ " ",
820
+ variant.sku
821
+ ] }) : null,
822
+ /* @__PURE__ */ jsxs4("div", { ...actions, children: [
823
+ /* @__PURE__ */ jsx10(s.QuantityInput, { ...local }),
824
+ /* @__PURE__ */ jsx10(s.AddToCart, { ...local }),
825
+ /* @__PURE__ */ jsx10(s.WishlistButton, { ...local, product, variant }),
826
+ /* @__PURE__ */ jsx10(s.BackInStock, { ...local, product, variant })
827
+ ] })
828
+ ] });
829
+ }
830
+
831
+ // src/product/CategoryList.tsx
832
+ import { jsx as jsx11 } from "react/jsx-runtime";
833
+ import { createElement as createElement3 } from "react";
834
+ function CategoryList({ classNames, className, unstyled }) {
835
+ const local = { classNames, unstyled };
836
+ const { product } = useProductPage();
837
+ const { settings, Link: Anchor } = useStorefront();
838
+ const root = usePart("category-list", { ...local, className });
839
+ const item = usePart("category-list-item", local);
840
+ const link = usePart("category-list-link", local);
841
+ const categories = product.categories ?? [];
842
+ if (categories.length === 0) return null;
843
+ return /* @__PURE__ */ jsx11("ul", { ...root, children: categories.map((category) => /* @__PURE__ */ createElement3("li", { ...item, key: category.id, "data-category-handle": category.handle }, /* @__PURE__ */ jsx11(Anchor, { ...link, href: routeHref(settings, "category", category.handle), children: category.name }))) });
844
+ }
845
+
846
+ // src/product/Gallery.tsx
847
+ import { Icon } from "@usethrottle/ui";
848
+ import { lazy, Suspense, useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
849
+ import { Fragment, jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
850
+ import { createElement as createElement4 } from "react";
851
+ var Lightbox = lazy(() => import("./chunk-RLWZOLXL.js"));
852
+ var SWIPE_PX = 40;
853
+ var STAGE_SIZES = "(min-width: 1024px) 50vw, 100vw";
854
+ function Gallery({ classNames, className, unstyled }) {
855
+ const local = { classNames, unstyled };
856
+ const { product, variant } = useProductPage();
857
+ const { dir } = useStorefront();
858
+ const { t } = useStrings();
859
+ const items = galleryItems(product);
860
+ const count = items.length;
861
+ const title = product.title ?? product.handle;
862
+ const indexOfVariant = () => {
863
+ const url = variant?.image?.url ?? variant?.images[0]?.url;
864
+ const at = url ? items.findIndex((i) => i.url === url) : -1;
865
+ return at >= 0 ? at : 0;
866
+ };
867
+ const [active, setActive] = useState3(indexOfVariant);
868
+ const [open, setOpen] = useState3(false);
869
+ const [zoom, setZoom] = useState3(null);
870
+ const start = useRef2(null);
871
+ const zoomAt = useRef2(null);
872
+ const frame = useRef2(0);
873
+ const stopZoom = () => {
874
+ cancelAnimationFrame(frame.current);
875
+ frame.current = 0;
876
+ zoomAt.current = null;
877
+ setZoom(null);
878
+ };
879
+ useEffect3(() => () => cancelAnimationFrame(frame.current), []);
880
+ const first = useRef2(true);
881
+ const sku = variant?.sku;
882
+ useEffect3(() => {
883
+ if (first.current) {
884
+ first.current = false;
885
+ return;
886
+ }
887
+ setActive(indexOfVariant());
888
+ }, [sku]);
889
+ const root = usePart("gallery", { ...local, className });
890
+ const stage = usePart("gallery-stage", local);
891
+ const itemPart = usePart("gallery-item", local);
892
+ const video = usePart("gallery-video", local);
893
+ const placeholder = usePart("gallery-placeholder", local);
894
+ const previous = usePart("gallery-previous", local);
895
+ const next = usePart("gallery-next", local);
896
+ const enlarge = usePart("gallery-enlarge", local);
897
+ const counter = usePart("gallery-counter", local);
898
+ const thumbs = usePart("gallery-thumbs", local);
899
+ const thumbItem = usePart("gallery-thumbs-item", local);
900
+ const thumb = usePart("gallery-thumb", local);
901
+ const go = (delta) => count > 0 && setActive((a) => (a + delta + count) % count);
902
+ const current = items[active];
903
+ const onKeyDown = (e) => {
904
+ const forward = dir === "rtl" ? "ArrowLeft" : "ArrowRight";
905
+ const backward = dir === "rtl" ? "ArrowRight" : "ArrowLeft";
906
+ if (e.key === forward) go(1);
907
+ else if (e.key === backward) go(-1);
908
+ else if (e.key === "Home") setActive(0);
909
+ else if (e.key === "End") setActive(count - 1);
910
+ else return;
911
+ e.preventDefault();
912
+ };
913
+ const onPointerDown = (e) => {
914
+ start.current = { x: e.clientX, moved: false };
915
+ };
916
+ const onPointerMove = (e) => {
917
+ if (e.pointerType === "mouse" && current && !isVideo(current)) {
918
+ const box = e.currentTarget.getBoundingClientRect();
919
+ if (box.width > 0 && box.height > 0) {
920
+ zoomAt.current = { x: (e.clientX - box.left) / box.width * 100, y: (e.clientY - box.top) / box.height * 100 };
921
+ if (!frame.current) {
922
+ frame.current = requestAnimationFrame(() => {
923
+ frame.current = 0;
924
+ if (zoomAt.current) setZoom(zoomAt.current);
925
+ });
926
+ }
927
+ }
928
+ }
929
+ if (start.current && Math.abs(e.clientX - start.current.x) > 10) start.current.moved = true;
930
+ };
931
+ const onPointerUp = (e) => {
932
+ const from = start.current;
933
+ start.current = null;
934
+ if (!from) return;
935
+ const dx = e.clientX - from.x;
936
+ if (Math.abs(dx) >= SWIPE_PX) go((dir === "rtl" ? dx > 0 : dx < 0) ? 1 : -1);
937
+ };
938
+ const onClick = () => {
939
+ if (start.current?.moved) return;
940
+ if (current && !isVideo(current)) setOpen(true);
941
+ };
942
+ return /* @__PURE__ */ jsxs5("section", { ...root, "aria-label": t("product.gallery.label", { title }), children: [
943
+ /* @__PURE__ */ jsxs5(
944
+ "div",
945
+ {
946
+ ...stage,
947
+ tabIndex: 0,
948
+ role: "group",
949
+ "aria-roledescription": "carousel",
950
+ "aria-label": t("product.gallery.label", { title }),
951
+ onKeyDown,
952
+ onPointerDown,
953
+ onPointerMove,
954
+ onPointerUp,
955
+ onPointerLeave: () => {
956
+ stopZoom();
957
+ start.current = null;
958
+ },
959
+ onClick,
960
+ children: [
961
+ current ? /* @__PURE__ */ jsx12("div", { ...itemPart, "data-index": active, "data-zoomed": zoom ? "true" : void 0, style: zoom ? { transformOrigin: `${zoom.x}% ${zoom.y}%` } : void 0, children: isVideo(current) ? /* @__PURE__ */ jsx12("video", { ...video, src: current.url, controls: true, playsInline: true, preload: "metadata", "aria-label": t("product.gallery.video", { title }) }) : /* @__PURE__ */ jsx12(
962
+ Image,
963
+ {
964
+ ...local,
965
+ src: current.url,
966
+ alt: current.altText ?? t("product.gallery.photoAlt", { title, n: active + 1 }),
967
+ aspectRatio: ratioOf(current),
968
+ srcSet: srcSetOf(current),
969
+ sizes: STAGE_SIZES,
970
+ priority: active === 0
971
+ }
972
+ ) }) : /* @__PURE__ */ jsx12("div", { ...placeholder }),
973
+ count > 1 ? /* @__PURE__ */ jsxs5(Fragment, { children: [
974
+ /* @__PURE__ */ jsx12("button", { ...previous, type: "button", "aria-label": t("product.gallery.previous"), onClick: (e) => {
975
+ e.stopPropagation();
976
+ go(-1);
977
+ }, children: /* @__PURE__ */ jsx12(Icon, { name: "chevron-left", size: 20 }) }),
978
+ /* @__PURE__ */ jsx12("button", { ...next, type: "button", "aria-label": t("product.gallery.next"), onClick: (e) => {
979
+ e.stopPropagation();
980
+ go(1);
981
+ }, children: /* @__PURE__ */ jsx12(Icon, { name: "chevron-right", size: 20 }) }),
982
+ /* @__PURE__ */ jsx12("p", { ...counter, "aria-live": "polite", children: /* @__PURE__ */ jsx12("bdi", { dir: "ltr", children: t("product.gallery.counter", { n: active + 1, count }) }) })
983
+ ] }) : null,
984
+ current && !isVideo(current) ? /* @__PURE__ */ jsx12("button", { ...enlarge, type: "button", "aria-label": t("product.gallery.enlarge"), onClick: (e) => {
985
+ e.stopPropagation();
986
+ setOpen(true);
987
+ }, children: /* @__PURE__ */ jsx12(Icon, { name: "zoom", size: 18 }) }) : null
988
+ ]
989
+ }
990
+ ),
991
+ count > 1 ? /* @__PURE__ */ jsx12("ul", { ...thumbs, "aria-label": t("product.gallery.thumbs"), children: items.map((item, i) => /* @__PURE__ */ createElement4("li", { ...thumbItem, key: `${item.url}-${i}` }, /* @__PURE__ */ jsx12(
992
+ "button",
993
+ {
994
+ ...thumb,
995
+ type: "button",
996
+ "aria-label": t("product.gallery.showPhoto", { n: i + 1, count }),
997
+ "aria-current": i === active ? "true" : void 0,
998
+ onClick: () => setActive(i),
999
+ children: isVideo(item) && !item.posterUrl ? /* @__PURE__ */ jsx12(Icon, { name: "play", size: 20 }) : /* @__PURE__ */ jsx12(Image, { ...local, src: isVideo(item) ? item.posterUrl : item.sizes?.["400"] ?? item.url, alt: "", aspectRatio: ratioOf(item) })
1000
+ }
1001
+ ))) }) : null,
1002
+ open ? /* @__PURE__ */ jsx12(Suspense, { fallback: null, children: /* @__PURE__ */ jsx12(Lightbox, { ...local, open: true, items, index: active, title, onIndexChange: setActive, onClose: () => setOpen(false) }) }) : null
1003
+ ] });
1004
+ }
1005
+
1006
+ // src/pieces/RichText.tsx
1007
+ import { jsx as jsx13 } from "react/jsx-runtime";
1008
+ var ALLOWED_TAGS = /* @__PURE__ */ new Set([
1009
+ "p",
1010
+ "br",
1011
+ "hr",
1012
+ "div",
1013
+ "span",
1014
+ "strong",
1015
+ "b",
1016
+ "em",
1017
+ "i",
1018
+ "u",
1019
+ "s",
1020
+ "del",
1021
+ "ins",
1022
+ "mark",
1023
+ "small",
1024
+ "sub",
1025
+ "sup",
1026
+ "blockquote",
1027
+ "pre",
1028
+ "code",
1029
+ "ul",
1030
+ "ol",
1031
+ "li",
1032
+ "dl",
1033
+ "dt",
1034
+ "dd",
1035
+ "h1",
1036
+ "h2",
1037
+ "h3",
1038
+ "h4",
1039
+ "h5",
1040
+ "h6",
1041
+ "a",
1042
+ "img",
1043
+ "figure",
1044
+ "figcaption",
1045
+ "table",
1046
+ "caption",
1047
+ "thead",
1048
+ "tbody",
1049
+ "tfoot",
1050
+ "tr",
1051
+ "th",
1052
+ "td"
1053
+ ]);
1054
+ var VOID_TAGS = /* @__PURE__ */ new Set(["br", "hr", "img"]);
1055
+ var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
1056
+ "script",
1057
+ "style",
1058
+ "iframe",
1059
+ "object",
1060
+ "embed",
1061
+ "noscript",
1062
+ "template",
1063
+ "textarea",
1064
+ "title",
1065
+ "noembed",
1066
+ "noframes",
1067
+ "xmp",
1068
+ "svg",
1069
+ "math"
1070
+ ]);
1071
+ var ALLOWED_ATTRS = {
1072
+ "*": ["title", "lang", "dir"],
1073
+ a: ["href", "target", "rel"],
1074
+ img: ["src", "alt", "width", "height", "loading"],
1075
+ th: ["colspan", "rowspan", "scope"],
1076
+ td: ["colspan", "rowspan"]
1077
+ };
1078
+ var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src"]);
1079
+ var SAFE_SCHEME = /^(https?|mailto|tel):/i;
1080
+ var NAMED_ENTITIES = { colon: ":", tab: " ", newline: "\n", amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: " " };
1081
+ function decodeEntities(value) {
1082
+ return value.replace(/&(?:#x([0-9a-f]+)|#(\d+)|([a-z]+));?/gi, (whole, hex, dec, name) => {
1083
+ const code = hex ? Number.parseInt(hex, 16) : dec ? Number.parseInt(dec, 10) : NaN;
1084
+ if (!Number.isNaN(code)) return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : "";
1085
+ return NAMED_ENTITIES[name.toLowerCase()] ?? whole;
1086
+ });
1087
+ }
1088
+ function safeUrl(raw) {
1089
+ const plain = decodeEntities(raw).replace(/[\u0000- \u007f-\u009f]/g, "");
1090
+ if (plain === "") return null;
1091
+ if (SAFE_SCHEME.test(plain)) return plain;
1092
+ return /^[a-z][a-z0-9+.-]*:/i.test(plain) ? null : decodeEntities(raw).trim();
1093
+ }
1094
+ var escapeAttr = (value) => value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1095
+ var escapeText = (value) => value.replace(/</g, "&lt;").replace(/>/g, "&gt;");
1096
+ var TAG_NAME = /[a-z][a-z0-9-]*/iy;
1097
+ function readTag(html, start) {
1098
+ const attrs = [];
1099
+ let i = start;
1100
+ for (; ; ) {
1101
+ while (i < html.length && /[\s/]/.test(html[i])) i += 1;
1102
+ if (i >= html.length) return null;
1103
+ if (html[i] === ">") return { attrs, end: i + 1, selfClosing: /\/\s*$/.test(html.slice(start, i)) };
1104
+ let name = "";
1105
+ while (i < html.length && !/[\s=/>]/.test(html[i])) name += html[i++];
1106
+ while (i < html.length && /\s/.test(html[i])) i += 1;
1107
+ let value = "";
1108
+ if (html[i] === "=") {
1109
+ i += 1;
1110
+ while (i < html.length && /\s/.test(html[i])) i += 1;
1111
+ const quote = html[i];
1112
+ if (quote === '"' || quote === "'") {
1113
+ const close = html.indexOf(quote, i + 1);
1114
+ if (close === -1) return null;
1115
+ value = html.slice(i + 1, close);
1116
+ i = close + 1;
1117
+ } else {
1118
+ while (i < html.length && !/[\s>]/.test(html[i])) value += html[i++];
1119
+ }
1120
+ }
1121
+ if (name) attrs.push({ name: name.toLowerCase(), value });
1122
+ }
1123
+ }
1124
+ function sanitizeHtml(html, options = {}) {
1125
+ let out = "";
1126
+ const open = [];
1127
+ let i = 0;
1128
+ while (i < html.length) {
1129
+ const lt = html.indexOf("<", i);
1130
+ if (lt === -1) {
1131
+ out += escapeText(html.slice(i));
1132
+ break;
1133
+ }
1134
+ out += escapeText(html.slice(i, lt));
1135
+ i = lt;
1136
+ if (html.startsWith("<!--", i)) {
1137
+ const close = html.indexOf("-->", i + 4);
1138
+ i = close === -1 ? html.length : close + 3;
1139
+ continue;
1140
+ }
1141
+ const closing = html[i + 1] === "/";
1142
+ const nameStart = i + (closing ? 2 : 1);
1143
+ TAG_NAME.lastIndex = nameStart;
1144
+ const name = TAG_NAME.exec(html)?.[0]?.toLowerCase();
1145
+ if (!name) {
1146
+ if (html[i + 1] === "!" || html[i + 1] === "?") {
1147
+ const close = html.indexOf(">", i);
1148
+ i = close === -1 ? html.length : close + 1;
1149
+ } else {
1150
+ out += "&lt;";
1151
+ i += 1;
1152
+ }
1153
+ continue;
1154
+ }
1155
+ const tag = readTag(html, nameStart + name.length);
1156
+ if (!tag) break;
1157
+ i = tag.end;
1158
+ if (closing) {
1159
+ const at = open.lastIndexOf(name);
1160
+ if (at !== -1) {
1161
+ while (open.length > at) out += `</${open.pop()}>`;
1162
+ }
1163
+ continue;
1164
+ }
1165
+ if (DROP_WITH_CONTENT.has(name)) {
1166
+ if (!tag.selfClosing) {
1167
+ const close = new RegExp(`</${name}\\s*>`, "ig");
1168
+ close.lastIndex = i;
1169
+ const found = close.exec(html);
1170
+ i = found ? found.index + found[0].length : html.length;
1171
+ }
1172
+ continue;
1173
+ }
1174
+ if (!ALLOWED_TAGS.has(name)) continue;
1175
+ let attrs = "";
1176
+ const seen = /* @__PURE__ */ new Set();
1177
+ const blank = name === "a" && tag.attrs.some((a) => a.name === "target" && a.value.trim().toLowerCase() === "_blank");
1178
+ for (const { name: attr, value } of tag.attrs) {
1179
+ if (blank && attr === "rel") continue;
1180
+ if (seen.has(attr) || !(ALLOWED_ATTRS["*"].includes(attr) || ALLOWED_ATTRS[name]?.includes(attr))) continue;
1181
+ seen.add(attr);
1182
+ if (URL_ATTRS.has(attr)) {
1183
+ const url = safeUrl(value);
1184
+ if (url !== null) attrs += ` ${attr}="${escapeAttr(url)}"`;
1185
+ } else {
1186
+ attrs += ` ${attr}="${escapeAttr(decodeEntities(value))}"`;
1187
+ }
1188
+ }
1189
+ if (blank) attrs += ' rel="noopener noreferrer"';
1190
+ if (name === "a" && options.linkClass) attrs += ` class="${escapeAttr(options.linkClass)}"`;
1191
+ out += `<${name}${attrs}>`;
1192
+ if (!VOID_TAGS.has(name)) open.push(name);
1193
+ }
1194
+ while (open.length > 0) out += `</${open.pop()}>`;
1195
+ return out;
1196
+ }
1197
+ function RichText({ html, classNames, className, unstyled }) {
1198
+ const part = usePart("rich-text", { classNames, className, unstyled });
1199
+ const ambient = useUnstyled();
1200
+ const linkClass = unstyled ?? ambient ? void 0 : "tsf-rich-text-link";
1201
+ return /* @__PURE__ */ jsx13("div", { ...part, dangerouslySetInnerHTML: { __html: sanitizeHtml(html, { linkClass }) } });
1202
+ }
1203
+
1204
+ // src/product/RelatedProducts.tsx
1205
+ import { useRelated } from "@usethrottle/catalog/react";
1206
+ import { useMemo as useMemo2 } from "react";
1207
+
1208
+ // src/pieces/ProductCard.tsx
1209
+ import { VisuallyHidden as VisuallyHidden3 } from "@usethrottle/ui";
1210
+ import { lazy as lazy2, Suspense as Suspense2 } from "react";
1211
+ import { Fragment as Fragment2, jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
1212
+ var SIZES = "(min-width: 1280px) 300px, (min-width: 768px) 33vw, 50vw";
1213
+ var MAX_SWATCHES = 5;
1214
+ function srcSetOf2(image) {
1215
+ const entries = Object.entries(image.sizes ?? {}).filter(([, url]) => typeof url === "string" && url !== "");
1216
+ return entries.length > 0 ? entries.map(([width, url]) => `${url} ${width}w`).join(", ") : void 0;
1217
+ }
1218
+ function swatchesOf(product) {
1219
+ const seen = /* @__PURE__ */ new Set();
1220
+ const out = [];
1221
+ for (const option of product.optionSwatches ?? []) {
1222
+ for (const v of option.values) {
1223
+ const swatch = v.swatch;
1224
+ if (!swatch) continue;
1225
+ const key = "color" in swatch ? swatch.color.toLowerCase() : swatch.url;
1226
+ if (seen.has(key)) continue;
1227
+ if ("color" in swatch) {
1228
+ if (!isHexColor(swatch.color)) continue;
1229
+ out.push({ value: v.label, hex: swatch.color });
1230
+ } else {
1231
+ out.push({ value: v.label, image: swatch.url });
1232
+ }
1233
+ seen.add(key);
1234
+ }
1235
+ }
1236
+ return out;
1237
+ }
1238
+ function CardTitle({ product, title, href, onSelect, classNames, unstyled }) {
1239
+ const { Link: Anchor } = useStorefront();
1240
+ const heading = usePart("product-card-title", { classNames, unstyled });
1241
+ const link = usePart("product-card-title-link", { classNames, unstyled });
1242
+ return /* @__PURE__ */ jsx14("h3", { ...heading, children: /* @__PURE__ */ jsx14(Anchor, { ...link, href, onClick: onSelect, children: title || product.handle }) });
1243
+ }
1244
+ function CardBadges({ badges, soldOut, classNames, unstyled }) {
1245
+ const part = usePart("product-card-badges", { classNames, unstyled });
1246
+ const { settings } = useStorefront();
1247
+ if (badges.length === 0 && !soldOut) return null;
1248
+ return /* @__PURE__ */ jsxs6("div", { ...part, children: [
1249
+ badges.map((b, i) => /* @__PURE__ */ jsx14(Badge, { kind: b.kind, tone: b.tone, classNames, unstyled, children: b.label }, `${b.kind}-${i}`)),
1250
+ soldOut ? /* @__PURE__ */ jsx14(Badge, { kind: "soldOut", classNames, unstyled, children: settings.stock.words.outOfStock }) : null
1251
+ ] });
1252
+ }
1253
+ var NoQuickAdd = () => null;
1254
+ var LoadedQuickAdd = lazy2(() => import("./chunk-4U6MYDZV.js").then((m) => ({ default: m.QuickAdd })));
1255
+ var ShopperQuickAdd = (props) => /* @__PURE__ */ jsx14(Suspense2, { fallback: null, children: /* @__PURE__ */ jsx14(LoadedQuickAdd, { ...props }) });
1256
+ var DEFAULT_SLOTS2 = {
1257
+ Image,
1258
+ Title: CardTitle,
1259
+ Price,
1260
+ Rating: StarRating,
1261
+ Badges: CardBadges,
1262
+ QuickAdd: NoQuickAdd,
1263
+ WishlistButton
1264
+ };
1265
+ function CardMedia({ product, slots, badges, soldOut, aspectRatio, href, onSelect, classNames, unstyled }) {
1266
+ const { settings, Link: Anchor } = useStorefront();
1267
+ const local = { classNames, unstyled };
1268
+ const media = usePart("product-card-media", local);
1269
+ const link = usePart("product-card-media-link", local);
1270
+ const first = usePart("product-card-image", local);
1271
+ const alt = usePart("product-card-image-alt", local);
1272
+ const placeholder = usePart("product-card-placeholder", local);
1273
+ const actions = usePart("product-card-actions", local);
1274
+ const images = product.images ?? [];
1275
+ const primary = images[0];
1276
+ const second = settings.card.secondImageOnHover ? images[1] : void 0;
1277
+ const hasActions = slots.QuickAdd !== NoQuickAdd || slots.WishlistButton !== WishlistButton;
1278
+ const imageProps = (image) => ({
1279
+ src: image.url,
1280
+ // The title link already names the product; a second description would read twice.
1281
+ alt: "",
1282
+ aspectRatio,
1283
+ srcSet: srcSetOf2(image),
1284
+ sizes: SIZES,
1285
+ ...local
1286
+ });
1287
+ return /* @__PURE__ */ jsxs6("div", { ...media, children: [
1288
+ /* @__PURE__ */ jsxs6(Anchor, { ...link, href, tabIndex: -1, "aria-hidden": "true", onClick: onSelect, children: [
1289
+ primary ? /* @__PURE__ */ jsx14("div", { ...first, children: /* @__PURE__ */ jsx14(slots.Image, { ...imageProps(primary) }) }) : /* @__PURE__ */ jsx14("div", { ...placeholder, style: { aspectRatio } }),
1290
+ second ? /* @__PURE__ */ jsx14("div", { ...alt, children: /* @__PURE__ */ jsx14(slots.Image, { ...imageProps(second) }) }) : null
1291
+ ] }),
1292
+ /* @__PURE__ */ jsx14(slots.Badges, { badges, soldOut, ...local }),
1293
+ hasActions ? /* @__PURE__ */ jsxs6("div", { ...actions, children: [
1294
+ /* @__PURE__ */ jsx14(slots.QuickAdd, { product, ...local }),
1295
+ /* @__PURE__ */ jsx14(slots.WishlistButton, { product, ...local })
1296
+ ] }) : null
1297
+ ] });
1298
+ }
1299
+ function CardBody(props) {
1300
+ const { product, slots, href, title, priceContext, onSelect, classNames, unstyled } = props;
1301
+ const { settings, reviewsOnLists: providerReviewsOnLists } = useStorefront();
1302
+ const { t } = useStrings();
1303
+ const local = { classNames, unstyled };
1304
+ const body = usePart("product-card-body", local);
1305
+ const brand = usePart("product-card-brand", local);
1306
+ const swatchesPart = usePart("product-card-swatches", local);
1307
+ const more = usePart("product-card-swatch-more", local);
1308
+ const ratingPart = usePart("product-card-rating", local);
1309
+ const pricePart = usePart("product-card-price", local);
1310
+ const from = usePart("product-card-from", local);
1311
+ const unpriced = usePart("product-card-unpriced", local);
1312
+ const { card } = settings;
1313
+ const metaText = props.meta === "category" ? product.productType : card.showBrand ? product.brand : null;
1314
+ const swatches = card.showSwatches ? swatchesOf(product) : [];
1315
+ const rating = product.rating;
1316
+ const reviewsOnLists = props.reviewsOnLists ?? providerReviewsOnLists;
1317
+ const showRating = card.showRating && reviewsOnLists && rating && rating.count > 0 && rating.average !== null;
1318
+ const range = product.priceRange ?? null;
1319
+ const compareAt = range && "compareAtMinMinor" in range && typeof range.compareAtMinMinor === "number" ? range.compareAtMinMinor : void 0;
1320
+ return /* @__PURE__ */ jsxs6("div", { ...body, children: [
1321
+ metaText ? /* @__PURE__ */ jsx14("p", { ...brand, "data-meta": props.meta ?? "brand", children: metaText }) : null,
1322
+ /* @__PURE__ */ jsx14(slots.Title, { product, title, href, onSelect, ...local }),
1323
+ swatches.length > 0 ? /* @__PURE__ */ jsxs6("ul", { ...swatchesPart, "data-card-swatches": "", children: [
1324
+ swatches.slice(0, MAX_SWATCHES).map((s) => /* @__PURE__ */ jsx14("li", { children: /* @__PURE__ */ jsx14(Swatch, { ...local, ...s }) }, s.hex ?? s.image)),
1325
+ swatches.length > MAX_SWATCHES ? /* @__PURE__ */ jsxs6("li", { ...more, children: [
1326
+ /* @__PURE__ */ jsx14("span", { "aria-hidden": "true", children: t("pieces.card.moreSwatches", { count: swatches.length - MAX_SWATCHES }) }),
1327
+ /* @__PURE__ */ jsx14(VisuallyHidden3, { children: t("pieces.card.moreSwatchesLabel", { count: swatches.length - MAX_SWATCHES }) })
1328
+ ] }) : null
1329
+ ] }) : null,
1330
+ showRating ? /* @__PURE__ */ jsx14("div", { ...ratingPart, "data-card-rating": "", children: /* @__PURE__ */ jsx14(slots.Rating, { value: rating.average, count: rating.count, size: "sm", ...local }) }) : null,
1331
+ /* @__PURE__ */ jsx14("p", { ...pricePart, children: range ? /* @__PURE__ */ jsxs6(Fragment2, { children: [
1332
+ range.minMinor !== range.maxMinor ? /* @__PURE__ */ jsxs6("span", { ...from, children: [
1333
+ t("pieces.price.from"),
1334
+ " "
1335
+ ] }) : null,
1336
+ /* @__PURE__ */ jsx14(
1337
+ slots.Price,
1338
+ {
1339
+ minor: range.minMinor,
1340
+ currency: range.currency,
1341
+ compareAtMinor: card.showCompareAt ? compareAt : void 0,
1342
+ priceContext,
1343
+ ...local
1344
+ }
1345
+ )
1346
+ ] }) : /* @__PURE__ */ jsx14("span", { ...unpriced, children: t("pieces.price.unavailable") }) })
1347
+ ] });
1348
+ }
1349
+ function RowLayout({ children, classNames, unstyled }) {
1350
+ const row = usePart("product-card-row", { classNames, unstyled });
1351
+ return /* @__PURE__ */ jsx14("div", { ...row, children });
1352
+ }
1353
+ function ProductCard(props) {
1354
+ const { product, position, listName, generatedAt, priceContext, onSelect, classNames, unstyled } = props;
1355
+ const { settings } = useStorefront();
1356
+ const variant = props.variant ?? settings.card.style;
1357
+ const quickAdd = props.quickAdd ?? settings.card.quickAdd;
1358
+ const slots = { ...DEFAULT_SLOTS2, ...quickAdd ? { QuickAdd: ShopperQuickAdd } : {}, ...props.slots };
1359
+ const local = { classNames, unstyled };
1360
+ const root = usePart("product-card", local);
1361
+ const href = routeHref(settings, "product", product.handle);
1362
+ const select = onSelect ? () => onSelect(product) : void 0;
1363
+ const soldOut = product.availability === "out_of_stock";
1364
+ const inner = /* @__PURE__ */ jsxs6(Fragment2, { children: [
1365
+ /* @__PURE__ */ jsx14(
1366
+ CardMedia,
1367
+ {
1368
+ product,
1369
+ slots,
1370
+ badges: cardBadges(settings, product, generatedAt),
1371
+ soldOut: settings.card.showBadges && soldOut,
1372
+ aspectRatio: variant === "row" ? 1 : 0.8,
1373
+ href,
1374
+ onSelect: select,
1375
+ ...local
1376
+ }
1377
+ ),
1378
+ /* @__PURE__ */ jsx14(CardBody, { product, slots, href, title: product.title ?? product.handle, priceContext, reviewsOnLists: props.reviewsOnLists, meta: props.meta, onSelect: select, ...local })
1379
+ ] });
1380
+ return /* @__PURE__ */ jsx14(
1381
+ "article",
1382
+ {
1383
+ ...root,
1384
+ "data-product-card": "",
1385
+ "data-product-handle": product.handle,
1386
+ "data-variant": variant,
1387
+ "data-sold-out": soldOut ? "" : void 0,
1388
+ "data-position": position,
1389
+ "data-list-name": listName,
1390
+ children: variant === "row" ? /* @__PURE__ */ jsx14(RowLayout, { ...local, children: inner }) : inner
1391
+ }
1392
+ );
1393
+ }
1394
+
1395
+ // src/product/RelatedProducts.tsx
1396
+ import { jsx as jsx15 } from "react/jsx-runtime";
1397
+ import { createElement as createElement5 } from "react";
1398
+ var LIST_NAME = "related_products";
1399
+ function useRelatedProducts(active = true) {
1400
+ const { product, related } = useProductPage();
1401
+ const { settings } = useStorefront();
1402
+ const limit = settings.product.relatedLimit;
1403
+ const seeded = useMemo2(() => related ? { products: related } : void 0, [related]);
1404
+ const query = useRelated(product.handle, { limit, initialData: seeded, enabled: active || seeded !== void 0 });
1405
+ const products = (query.data?.products ?? related ?? []).slice(0, limit);
1406
+ return { products, priceContext: query.data?.priceContext };
1407
+ }
1408
+ function RelatedProducts({ active = true, card, classNames, className, unstyled }) {
1409
+ const local = { classNames, unstyled };
1410
+ const { generatedAt } = useProductPage();
1411
+ const { products, priceContext } = useRelatedProducts(active);
1412
+ const track = useTrack();
1413
+ const root = usePart("related-products", { ...local, className });
1414
+ const item = usePart("related-products-item", local);
1415
+ const at = useMemo2(() => generatedAt ?? (/* @__PURE__ */ new Date()).toISOString(), [generatedAt]);
1416
+ if (products.length === 0) return null;
1417
+ return /* @__PURE__ */ jsx15("ul", { ...root, children: products.map((p, position) => /* @__PURE__ */ createElement5("li", { ...item, key: p.handle }, /* @__PURE__ */ jsx15(
1418
+ ProductCard,
1419
+ {
1420
+ ...local,
1421
+ ...card,
1422
+ product: p,
1423
+ position,
1424
+ listName: LIST_NAME,
1425
+ generatedAt: at,
1426
+ priceContext,
1427
+ onSelect: () => {
1428
+ const currency = p.priceRange?.currency;
1429
+ if (currency) track("select_item", { currency, item_list_name: LIST_NAME, items: [toGa4Item(p, { index: position, listName: LIST_NAME })] });
1430
+ }
1431
+ }
1432
+ ))) });
1433
+ }
1434
+
1435
+ // src/product/ReviewForm.tsx
1436
+ import { useSubmitReview } from "@usethrottle/catalog/react";
1437
+ import { Field, VisuallyHidden as VisuallyHidden4 } from "@usethrottle/ui";
1438
+ import { useEffect as useEffect4, useId as useId3, useRef as useRef3, useState as useState4 } from "react";
1439
+ import { jsx as jsx16, jsxs as jsxs7 } from "react/jsx-runtime";
1440
+ import { createElement as createElement6 } from "react";
1441
+ function ReviewForm({ handle, classNames, className, unstyled }) {
1442
+ const local = { classNames, unstyled };
1443
+ const page = useProductPage();
1444
+ const submit = useSubmitReview(handle ?? page.product.handle);
1445
+ const { t, keyAttr } = useStrings();
1446
+ const id = useId3();
1447
+ const root = usePart("review-form", { ...local, className });
1448
+ const heading = usePart("review-form-title", local);
1449
+ const stars = usePart("review-form-stars", local);
1450
+ const star = usePart("review-form-star", local);
1451
+ const starInput = usePart("review-form-star-input", local);
1452
+ const textarea = usePart("review-form-textarea", local);
1453
+ const fieldPart = usePart("review-form-field", local);
1454
+ const errorPart = usePart("review-form-error", local);
1455
+ const submitPart = usePart("review-form-submit", local);
1456
+ const thanksPart = usePart("review-form-thanks", local);
1457
+ const [rating, setRating] = useState4(0);
1458
+ const [title, setTitle] = useState4("");
1459
+ const [body, setBody] = useState4("");
1460
+ const [displayName, setDisplayName] = useState4("");
1461
+ const [problems, setProblems] = useState4({});
1462
+ const formRef = useRef3(null);
1463
+ const thanks = useRef3(null);
1464
+ useEffect4(() => {
1465
+ if (submit.status === "done") thanks.current?.focus();
1466
+ }, [submit.status]);
1467
+ if (submit.status === "done") {
1468
+ return /* @__PURE__ */ jsx16("p", { ...thanksPart, ref: thanks, role: "status", tabIndex: -1, children: submit.result?.review.status === "approved" ? t("product.reviewForm.thanksLive") : t("product.reviewForm.thanksPending") });
1469
+ }
1470
+ const busy = submit.status === "submitting";
1471
+ const failure = (code) => {
1472
+ switch (code) {
1473
+ case "ALREADY_REVIEWED":
1474
+ return t("product.reviewForm.errorAlready");
1475
+ case "NOT_VERIFIED_BUYER":
1476
+ case "PURCHASE_REFUNDED":
1477
+ return t("product.reviewForm.errorNotBuyer");
1478
+ case "EMAIL_NOT_VERIFIED":
1479
+ return t("product.reviewForm.errorEmail");
1480
+ case "RATE_LIMITED":
1481
+ case "REVIEW_QUEUE_FULL":
1482
+ return t("product.reviewForm.errorBusy");
1483
+ default:
1484
+ return t("product.reviewForm.errorGeneric");
1485
+ }
1486
+ };
1487
+ const onSubmit = (event) => {
1488
+ event.preventDefault();
1489
+ if (busy) return;
1490
+ const found = {};
1491
+ if (rating < 1) found.rating = t("product.reviewForm.needRating");
1492
+ if (body.trim() === "") found.body = t("product.reviewForm.needBody");
1493
+ if (displayName.trim() === "") found.displayName = t("product.reviewForm.needName");
1494
+ setProblems(found);
1495
+ const first = ["rating", "body", "displayName"].find((f) => found[f]);
1496
+ if (first) {
1497
+ const selector = first === "rating" ? 'input[name="rating"]' : `[name="${first}"]`;
1498
+ formRef.current?.querySelector(selector)?.focus();
1499
+ return;
1500
+ }
1501
+ submit.submit({ rating, title: title.trim() || null, body: body.trim(), displayName: displayName.trim() }).catch(() => void 0);
1502
+ };
1503
+ return /* @__PURE__ */ jsxs7("form", { ...root, ref: formRef, noValidate: true, "aria-busy": busy || void 0, onSubmit, children: [
1504
+ /* @__PURE__ */ jsx16("p", { ...heading, ...keyAttr("product.writeReview"), children: t("product.writeReview") }),
1505
+ /* @__PURE__ */ jsxs7("fieldset", { ...stars, "aria-describedby": problems.rating ? `${id}-rating-error` : void 0, children: [
1506
+ /* @__PURE__ */ jsx16("legend", { children: t("product.reviewForm.rating") }),
1507
+ [1, 2, 3, 4, 5].map((n) => /* @__PURE__ */ createElement6("label", { ...star, key: n, "data-on": n <= rating ? "true" : void 0 }, /* @__PURE__ */ jsx16(
1508
+ "input",
1509
+ {
1510
+ ...starInput,
1511
+ type: "radio",
1512
+ name: "rating",
1513
+ value: n,
1514
+ checked: rating === n,
1515
+ "aria-invalid": problems.rating ? true : void 0,
1516
+ onChange: () => {
1517
+ setRating(n);
1518
+ setProblems((p) => ({ ...p, rating: void 0 }));
1519
+ }
1520
+ }
1521
+ ), /* @__PURE__ */ jsx16("span", { "aria-hidden": "true", children: "\u2605" }), /* @__PURE__ */ jsx16(VisuallyHidden4, { children: n === 1 ? t("product.reviewForm.starOne") : t("product.reviewForm.star", { n }) }))),
1522
+ problems.rating ? /* @__PURE__ */ jsx16("span", { ...errorPart, id: `${id}-rating-error`, role: "alert", children: problems.rating }) : null
1523
+ ] }),
1524
+ /* @__PURE__ */ jsx16(Field, { label: t("product.reviewForm.title"), name: "title", value: title, onChange: setTitle }),
1525
+ /* @__PURE__ */ jsxs7("div", { ...fieldPart, children: [
1526
+ /* @__PURE__ */ jsx16("label", { htmlFor: `${id}-body`, children: t("product.reviewForm.body") }),
1527
+ /* @__PURE__ */ jsx16(
1528
+ "textarea",
1529
+ {
1530
+ ...textarea,
1531
+ id: `${id}-body`,
1532
+ name: "body",
1533
+ rows: 4,
1534
+ maxLength: 4e3,
1535
+ value: body,
1536
+ "aria-invalid": problems.body ? true : void 0,
1537
+ "aria-describedby": problems.body ? `${id}-body-error` : void 0,
1538
+ onChange: (e) => {
1539
+ setBody(e.target.value);
1540
+ setProblems((p) => ({ ...p, body: void 0 }));
1541
+ }
1542
+ }
1543
+ ),
1544
+ problems.body ? /* @__PURE__ */ jsx16("span", { ...errorPart, id: `${id}-body-error`, role: "alert", children: problems.body }) : null
1545
+ ] }),
1546
+ /* @__PURE__ */ jsx16(
1547
+ Field,
1548
+ {
1549
+ label: t("product.reviewForm.name"),
1550
+ name: "displayName",
1551
+ value: displayName,
1552
+ autoComplete: "given-name",
1553
+ error: problems.displayName,
1554
+ onChange: (v) => {
1555
+ setDisplayName(v);
1556
+ setProblems((p) => ({ ...p, displayName: void 0 }));
1557
+ }
1558
+ }
1559
+ ),
1560
+ submit.status === "error" ? /* @__PURE__ */ jsx16("p", { ...errorPart, role: "alert", children: failure(submit.error?.code) }) : null,
1561
+ /* @__PURE__ */ jsx16("button", { ...submitPart, type: "submit", "aria-disabled": busy || void 0, children: busy ? t("product.reviewForm.sending") : t("product.reviewForm.submit") })
1562
+ ] });
1563
+ }
1564
+
1565
+ // src/product/Reviews.tsx
1566
+ import { useCatalog, useCustomerKey, useReviews } from "@usethrottle/catalog/react";
1567
+ import { useReviewEligibility } from "@usethrottle/catalog/react/extras";
1568
+ import { Icon as Icon2, Select as Select2, Skeleton } from "@usethrottle/ui";
1569
+ import { useRef as useRef4, useState as useState5 } from "react";
1570
+
1571
+ // src/server/reviews-page.ts
1572
+ var REVIEWS_PAGE_SIZE = 10;
1573
+
1574
+ // src/product/Reviews.tsx
1575
+ import { Fragment as Fragment3, jsx as jsx17, jsxs as jsxs8 } from "react/jsx-runtime";
1576
+ import { createElement as createElement7 } from "react";
1577
+ var SORTS = ["newest", "highest", "lowest"];
1578
+ var STARS = [5, 4, 3, 2, 1];
1579
+ var sortLabelKey = {
1580
+ newest: "product.reviewList.sortNewest",
1581
+ highest: "product.reviewList.sortHighest",
1582
+ lowest: "product.reviewList.sortLowest"
1583
+ };
1584
+ var gateKey = {
1585
+ reviews_disabled: "product.reviewList.gateReviewsDisabled",
1586
+ not_signed_in: "product.reviewList.gateSignIn",
1587
+ email_not_verified: "product.reviewList.gateEmailNotVerified",
1588
+ already_reviewed: "product.reviewList.gateAlreadyReviewed",
1589
+ not_verified_buyer: "product.reviewList.gateNotVerifiedBuyer"
1590
+ };
1591
+ function ReviewGate({ handle, ...local }) {
1592
+ const signedIn = useCustomerKey() !== null;
1593
+ const eligibility = useReviewEligibility(handle);
1594
+ const { t } = useStrings();
1595
+ const gate = usePart("product-reviews-gate", local);
1596
+ if (!signedIn) return /* @__PURE__ */ jsx17("p", { ...gate, children: t("product.reviewList.gateSignIn") });
1597
+ if (eligibility.error) {
1598
+ if (eligibility.error.code === "NOT_FOUND") return null;
1599
+ return /* @__PURE__ */ jsx17("p", { ...gate, children: t("product.reviewList.gateFailed") });
1600
+ }
1601
+ if (!eligibility.data) return /* @__PURE__ */ jsx17(Skeleton, {});
1602
+ if (eligibility.data.canReview) return /* @__PURE__ */ jsx17(ReviewForm, { ...local, handle });
1603
+ const reason = eligibility.data.reason;
1604
+ return /* @__PURE__ */ jsx17("p", { ...gate, "data-reason": reason, children: t(reason ? gateKey[reason] : "product.reviewList.gateUnknown") });
1605
+ }
1606
+ function ReviewItem({ review, ...local }) {
1607
+ const { locale } = useStorefront();
1608
+ const { t } = useStrings();
1609
+ const root = usePart("product-review", local);
1610
+ const head = usePart("product-review-header", local);
1611
+ const date = usePart("product-review-date", local);
1612
+ const title = usePart("product-review-title", local);
1613
+ const body = usePart("product-review-body", local);
1614
+ const author = usePart("product-review-author", local);
1615
+ const reply = usePart("product-review-reply", local);
1616
+ const when = new Date(review.createdAt);
1617
+ return /* @__PURE__ */ jsxs8("li", { ...root, "data-review-id": review.id, children: [
1618
+ /* @__PURE__ */ jsxs8("div", { ...head, children: [
1619
+ /* @__PURE__ */ jsx17(StarRating, { ...local, value: review.rating, size: "sm" }),
1620
+ /* @__PURE__ */ jsx17("time", { ...date, dateTime: review.createdAt, children: Number.isNaN(when.getTime()) ? "" : new Intl.DateTimeFormat(locale, { year: "numeric", month: "long", day: "numeric", timeZone: "UTC" }).format(when) })
1621
+ ] }),
1622
+ review.title ? /* @__PURE__ */ jsx17("h3", { ...title, children: review.title }) : null,
1623
+ /* @__PURE__ */ jsx17("p", { ...body, children: review.body }),
1624
+ /* @__PURE__ */ jsxs8("p", { ...author, children: [
1625
+ review.displayName,
1626
+ review.verified ? /* @__PURE__ */ jsx17(Badge, { ...local, kind: "verified", children: t("product.reviewList.verified") }) : null
1627
+ ] }),
1628
+ review.reply ? /* @__PURE__ */ jsxs8("div", { ...reply, children: [
1629
+ /* @__PURE__ */ jsx17("p", { children: t("product.reviewList.reply") }),
1630
+ /* @__PURE__ */ jsx17("p", { children: review.reply.body })
1631
+ ] }) : null
1632
+ ] });
1633
+ }
1634
+ function Reviews({ active = true, initialData, layout, classNames, className, unstyled }) {
1635
+ const local = { classNames, unstyled };
1636
+ const { product, initialReviews, reviewsLayout } = useProductPage();
1637
+ const arrangement = layout ?? reviewsLayout;
1638
+ const handle = product.handle;
1639
+ const seed = initialData ?? initialReviews ?? void 0;
1640
+ const client = useCatalog();
1641
+ const { t, keyAttr } = useStrings();
1642
+ const [sort, setSort] = useState5("newest");
1643
+ const [rating, setRating] = useState5(null);
1644
+ const [more, setMore] = useState5(null);
1645
+ const [loadingMore, setLoadingMore] = useState5(false);
1646
+ const [moreFailed, setMoreFailed] = useState5(false);
1647
+ const ask = useRef4(0);
1648
+ const first = useReviews(handle, {
1649
+ sort,
1650
+ ...rating ? { rating } : {},
1651
+ limit: REVIEWS_PAGE_SIZE,
1652
+ enabled: active,
1653
+ keepPreviousData: true,
1654
+ ...seed && sort === "newest" && rating === null ? { initialData: seed } : {}
1655
+ });
1656
+ const root = usePart("product-reviews", { ...local, className });
1657
+ const summaryPart = usePart("product-reviews-summary", local);
1658
+ const mainPart = usePart("product-reviews-main", local);
1659
+ const average = usePart("product-reviews-average", local);
1660
+ const histogram = usePart("product-reviews-histogram", local);
1661
+ const row = usePart("product-reviews-histogram-row", local);
1662
+ const bar = usePart("product-reviews-histogram-bar", local);
1663
+ const fill = usePart("product-reviews-histogram-fill", local);
1664
+ const count = usePart("product-reviews-histogram-count", local);
1665
+ const controls = usePart("product-reviews-controls", local);
1666
+ const clear = usePart("product-reviews-clear", local);
1667
+ const list = usePart("product-reviews-list", local);
1668
+ const empty = usePart("product-reviews-empty", local);
1669
+ const loadMore = usePart("product-reviews-load-more", local);
1670
+ const failed = usePart("product-reviews-error", local);
1671
+ const change = (next) => {
1672
+ ask.current += 1;
1673
+ setMore(null);
1674
+ setMoreFailed(false);
1675
+ if (next.sort !== void 0) setSort(next.sort);
1676
+ if (next.rating !== void 0) setRating(next.rating);
1677
+ };
1678
+ const data = first.data && !("redirectTo" in first.data) ? first.data : void 0;
1679
+ if (first.error && first.error.code === "NOT_FOUND") return null;
1680
+ if (!data) {
1681
+ return /* @__PURE__ */ jsx17("div", { ...root, "aria-busy": first.isLoading || void 0, children: first.error ? /* @__PURE__ */ jsx17("p", { ...failed, children: t("product.reviewList.loadFailed") }) : active ? /* @__PURE__ */ jsx17(Skeleton, { count: 2 }) : null });
1682
+ }
1683
+ const { summary } = data;
1684
+ const reviews = [...data.reviews, ...more?.reviews ?? []];
1685
+ const nextCursor = more ? more.nextCursor : data.nextCursor;
1686
+ const loadNext = async () => {
1687
+ if (!nextCursor || loadingMore) return;
1688
+ const mine = ask.current;
1689
+ setLoadingMore(true);
1690
+ setMoreFailed(false);
1691
+ try {
1692
+ const page = await client.reviews.list(handle, { sort, ...rating ? { rating } : {}, limit: REVIEWS_PAGE_SIZE, cursor: nextCursor });
1693
+ if (mine !== ask.current || "redirectTo" in page) return;
1694
+ setMore((prev) => ({ reviews: [...prev?.reviews ?? [], ...page.reviews], nextCursor: page.nextCursor }));
1695
+ } catch {
1696
+ if (mine === ask.current) setMoreFailed(true);
1697
+ } finally {
1698
+ if (mine === ask.current) setLoadingMore(false);
1699
+ }
1700
+ };
1701
+ const main = /* @__PURE__ */ jsxs8(Fragment3, { children: [
1702
+ /* @__PURE__ */ jsx17(ReviewGate, { ...local, handle }),
1703
+ summary.count > 0 ? /* @__PURE__ */ jsxs8("div", { ...controls, children: [
1704
+ /* @__PURE__ */ jsx17(
1705
+ Select2,
1706
+ {
1707
+ label: t("product.reviewList.sortLabel"),
1708
+ value: sort,
1709
+ options: SORTS.map((s) => ({ value: s, label: t(sortLabelKey[s]) })),
1710
+ onChange: (value) => change({ sort: value })
1711
+ }
1712
+ ),
1713
+ rating !== null ? /* @__PURE__ */ jsx17("button", { ...clear, type: "button", onClick: () => change({ rating: null }), children: t("product.reviewList.clearFilter") }) : null
1714
+ ] }) : null,
1715
+ reviews.length > 0 ? /* @__PURE__ */ jsx17("ul", { ...list, "aria-busy": first.isValidating || void 0, children: reviews.map((review) => /* @__PURE__ */ createElement7(ReviewItem, { ...local, key: review.id, review })) }) : summary.count > 0 ? /* @__PURE__ */ jsx17("p", { ...empty, children: t("product.reviewList.noneForRating") }) : null,
1716
+ moreFailed ? /* @__PURE__ */ jsx17("p", { ...failed, children: t("product.reviewList.loadFailed") }) : null,
1717
+ nextCursor ? /* @__PURE__ */ jsx17("button", { ...loadMore, type: "button", "aria-disabled": loadingMore || void 0, onClick: () => void loadNext(), children: loadingMore ? t("product.reviewList.loading") : t("product.reviewList.loadMore") }) : null
1718
+ ] });
1719
+ return /* @__PURE__ */ jsxs8("div", { ...root, "data-layout": arrangement, children: [
1720
+ /* @__PURE__ */ jsx17("div", { ...summaryPart, "data-layout": arrangement, children: summary.count > 0 && summary.average !== null ? /* @__PURE__ */ jsxs8(Fragment3, { children: [
1721
+ /* @__PURE__ */ jsxs8("p", { ...average, children: [
1722
+ /* @__PURE__ */ jsx17("span", { "aria-hidden": "true", children: summary.average.toFixed(1) }),
1723
+ /* @__PURE__ */ jsx17(StarRating, { ...local, value: summary.average, count: summary.count })
1724
+ ] }),
1725
+ /* @__PURE__ */ jsx17("ol", { ...histogram, "aria-label": t("product.reviewList.ratingsByStars"), children: STARS.map((stars) => {
1726
+ const n = summary.histogram[String(stars)];
1727
+ const pressed = rating === stars;
1728
+ return /* @__PURE__ */ jsx17("li", { children: /* @__PURE__ */ jsxs8(
1729
+ "button",
1730
+ {
1731
+ ...row,
1732
+ type: "button",
1733
+ "data-rating": stars,
1734
+ "aria-pressed": pressed,
1735
+ "aria-label": t("product.reviewList.filterRating", { rating: stars, count: n }),
1736
+ onClick: () => change({ rating: pressed ? null : stars }),
1737
+ children: [
1738
+ /* @__PURE__ */ jsxs8("span", { "aria-hidden": "true", children: [
1739
+ stars,
1740
+ " ",
1741
+ /* @__PURE__ */ jsx17(Icon2, { name: "star", size: 12 })
1742
+ ] }),
1743
+ /* @__PURE__ */ jsx17("span", { ...bar, "aria-hidden": "true", children: /* @__PURE__ */ jsx17("span", { ...fill, style: { inlineSize: `${summary.count ? n / summary.count * 100 : 0}%` } }) }),
1744
+ /* @__PURE__ */ jsx17("span", { ...count, "aria-hidden": "true", children: n })
1745
+ ]
1746
+ }
1747
+ ) }, stars);
1748
+ }) })
1749
+ ] }) : /* @__PURE__ */ jsx17("p", { ...empty, ...keyAttr("product.noReviews"), children: t("product.noReviews") }) }),
1750
+ arrangement === "columns" ? /* @__PURE__ */ jsx17("div", { ...mainPart, children: main }) : main
1751
+ ] });
1752
+ }
1753
+
1754
+ // src/product/ShippingSection.tsx
1755
+ import { usePage } from "@usethrottle/catalog/react/extras";
1756
+ import { useContext as useContext2, useMemo as useMemo3 } from "react";
1757
+ import { jsx as jsx18 } from "react/jsx-runtime";
1758
+ function useShippingContent(pageHandle) {
1759
+ const { site, settings } = useStorefront();
1760
+ const builder = site.source === "builder";
1761
+ const pageOutlet = site.pageOutlet;
1762
+ const Outlet = useMemo3(
1763
+ () => builder && pageHandle && pageOutlet ? pageOutlet(pageHandle) : null,
1764
+ [builder, pageHandle, pageOutlet]
1765
+ );
1766
+ const loaded = useContext2(ProductPageContext)?.shippingPage;
1767
+ const configured = settings.product.sections.find((s) => s.key === "shipping")?.pageHandle ?? null;
1768
+ const seeded = pageHandle !== null && pageHandle === configured ? loaded : void 0;
1769
+ const seed = useMemo3(
1770
+ () => typeof seeded === "string" ? { handle: pageHandle, title: "", bodyHtml: seeded, seo: { title: "", description: "" } } : void 0,
1771
+ [seeded, pageHandle]
1772
+ );
1773
+ const page = usePage(!builder && pageHandle && seeded !== null ? pageHandle : null, seed ? { initialData: seed } : void 0);
1774
+ if (builder) return Outlet ? { kind: "outlet", Outlet } : { kind: "hidden" };
1775
+ const html = page.data?.bodyHtml;
1776
+ return html ? { kind: "page", html } : { kind: "hidden" };
1777
+ }
1778
+ function ShippingSection({ pageHandle, classNames, className, unstyled }) {
1779
+ const local = { classNames, unstyled };
1780
+ const content = useShippingContent(pageHandle);
1781
+ const part = usePart("shipping-section", { ...local, className });
1782
+ if (content.kind === "hidden") return null;
1783
+ return /* @__PURE__ */ jsx18("div", { ...part, children: content.kind === "outlet" ? /* @__PURE__ */ jsx18(content.Outlet, {}) : /* @__PURE__ */ jsx18(RichText, { ...local, html: content.html }) });
1784
+ }
1785
+
1786
+ // src/product/TagList.tsx
1787
+ import { jsx as jsx19 } from "react/jsx-runtime";
1788
+ import { createElement as createElement8 } from "react";
1789
+ function TagList({ classNames, className, unstyled }) {
1790
+ const local = { classNames, unstyled };
1791
+ const { product } = useProductPage();
1792
+ const { settings, Link: Anchor } = useStorefront();
1793
+ const root = usePart("tag-list", { ...local, className });
1794
+ const item = usePart("tag-list-item", local);
1795
+ const link = usePart("tag-list-link", local);
1796
+ const tags = product.tags ?? [];
1797
+ if (tags.length === 0) return null;
1798
+ return /* @__PURE__ */ jsx19("ul", { ...root, children: tags.map((tag) => /* @__PURE__ */ createElement8("li", { ...item, key: tag }, /* @__PURE__ */ jsx19(Anchor, { ...link, href: routeHref(settings, "tag", tag), children: tag }))) });
1799
+ }
1800
+
1801
+ // src/product/ProductSections.tsx
1802
+ import { Icon as Icon3, Tabs } from "@usethrottle/ui";
1803
+ import { useEffect as useEffect5, useState as useState6 } from "react";
1804
+
1805
+ // src/product/use-media-query.ts
1806
+ import { useSyncExternalStore } from "react";
1807
+ function useMediaQuery(query) {
1808
+ return useSyncExternalStore(
1809
+ (onChange) => {
1810
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return () => {
1811
+ };
1812
+ const list = window.matchMedia(query);
1813
+ list.addEventListener("change", onChange);
1814
+ return () => list.removeEventListener("change", onChange);
1815
+ },
1816
+ () => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(query).matches,
1817
+ () => false
1818
+ );
1819
+ }
1820
+
1821
+ // src/product/ProductSections.tsx
1822
+ import { jsx as jsx20, jsxs as jsxs9 } from "react/jsx-runtime";
1823
+ import { createElement as createElement9 } from "react";
1824
+ var PHONE_QUERY = "(max-width: 767px)";
1825
+ function specRows(variants, yes, no) {
1826
+ const words = (v) => typeof v === "boolean" ? v ? yes : no : String(v);
1827
+ const rows = /* @__PURE__ */ new Map();
1828
+ for (const variant of variants) {
1829
+ for (const [key, value] of Object.entries(variant.attributes ?? {})) {
1830
+ const row = rows.get(key) ?? { key, label: variant.attributeLabels?.[key] ?? key.replace(/_/g, " "), values: [] };
1831
+ if (!row.values.includes(words(value))) row.values.push(words(value));
1832
+ rows.set(key, row);
1833
+ }
1834
+ }
1835
+ return [...rows.values()];
1836
+ }
1837
+ function Specs({ rows, ...local }) {
1838
+ const root = usePart("product-specs", local);
1839
+ const row = usePart("product-specs-row", local);
1840
+ const label = usePart("product-specs-label", local);
1841
+ const value = usePart("product-specs-value", local);
1842
+ return /* @__PURE__ */ jsx20("dl", { ...root, children: rows.map((r) => /* @__PURE__ */ createElement9("div", { ...row, key: r.key, "data-key": r.key }, /* @__PURE__ */ jsx20("dt", { ...label, children: r.label }), /* @__PURE__ */ jsx20("dd", { ...value, children: r.values.join(", ") }))) });
1843
+ }
1844
+ function ProductSections({ style, classNames, className, unstyled }) {
1845
+ const local = { classNames, unstyled };
1846
+ const page = useProductPage();
1847
+ const { product, revealSectionRef } = page;
1848
+ const { settings } = useStorefront();
1849
+ const { t } = useStrings();
1850
+ const phone = useMediaQuery(PHONE_QUERY);
1851
+ const base = page.sectionsId;
1852
+ const root = usePart("product-sections", { ...local, className });
1853
+ const sectionPart = usePart("product-section", local);
1854
+ const titlePart = usePart("product-section-title", local);
1855
+ const triggerPart = usePart("product-section-trigger", local);
1856
+ const bodyPart = usePart("product-section-body", local);
1857
+ const configured = settings.product.sections;
1858
+ const shipping = useShippingContent(configured.find((s) => s.key === "shipping")?.pageHandle ?? null);
1859
+ const requested = style ?? page.sectionsStyle;
1860
+ const resolved2 = requested === "auto" ? phone ? "accordion" : "tabs" : requested;
1861
+ const rows = specRows(product.variants, t("boolean.yes"), t("boolean.no"));
1862
+ const hasDescription = !!(product.descriptionHtml?.trim() || product.description?.trim());
1863
+ const present = {
1864
+ description: hasDescription,
1865
+ specs: rows.length > 0,
1866
+ shipping: shipping.kind !== "hidden",
1867
+ tags: (product.tags?.length ?? 0) > 0,
1868
+ categories: (product.categories?.length ?? 0) > 0,
1869
+ // Server data says; without it the request decides inside the section.
1870
+ related: page.related === void 0 || page.related.length > 0,
1871
+ // `null`: the server found the catalog has no reviews to show for this product.
1872
+ reviews: page.initialReviews !== null
1873
+ };
1874
+ const entries = configured.filter((s) => s.enabled && present[s.key]);
1875
+ const [active, setActive] = useState6(null);
1876
+ const [open, setOpen] = useState6(null);
1877
+ const firstKey = entries[0]?.key;
1878
+ const current = active && entries.some((e) => e.key === active) ? active : firstKey ?? "";
1879
+ const opened = open ?? (firstKey ? [firstKey] : []);
1880
+ useEffect5(() => {
1881
+ revealSectionRef.current = (key) => {
1882
+ if (!entries.some((e) => e.key === key)) return false;
1883
+ setActive(key);
1884
+ setOpen((prev) => [.../* @__PURE__ */ new Set([...prev ?? (firstKey ? [firstKey] : []), key])]);
1885
+ return true;
1886
+ };
1887
+ return () => {
1888
+ revealSectionRef.current = null;
1889
+ };
1890
+ });
1891
+ if (entries.length === 0) return null;
1892
+ const isShown = (key) => resolved2 === "tabs" ? current === key : resolved2 === "accordion" ? opened.includes(key) : true;
1893
+ const titleOf = (s) => (s.key === "related" ? settings.product.relatedTitle.trim() : "") || s.title.trim() || t(`product.${s.key}`);
1894
+ const bodyOf = (s) => {
1895
+ switch (s.key) {
1896
+ case "description":
1897
+ return product.descriptionHtml?.trim() ? /* @__PURE__ */ jsx20(RichText, { ...local, html: product.descriptionHtml }) : /* @__PURE__ */ jsx20("p", { children: product.description });
1898
+ case "specs":
1899
+ return /* @__PURE__ */ jsx20(Specs, { ...local, rows });
1900
+ case "shipping":
1901
+ return /* @__PURE__ */ jsx20(ShippingSection, { ...local, pageHandle: s.pageHandle });
1902
+ case "tags":
1903
+ return /* @__PURE__ */ jsx20(TagList, { ...local });
1904
+ case "categories":
1905
+ return /* @__PURE__ */ jsx20(CategoryList, { ...local });
1906
+ case "related":
1907
+ return /* @__PURE__ */ jsx20(RelatedProducts, { ...local, active: isShown("related") });
1908
+ case "reviews":
1909
+ return /* @__PURE__ */ jsx20(Reviews, { ...local, active: isShown("reviews"), initialData: page.initialReviews ?? void 0 });
1910
+ }
1911
+ };
1912
+ const list = entries.map((s) => ({ key: s.key, title: titleOf(s), body: bodyOf(s) }));
1913
+ const toggle = (key) => setOpen(opened.includes(key) ? opened.filter((k) => k !== key) : [...opened, key]);
1914
+ return /* @__PURE__ */ jsxs9("div", { ...root, "data-style": resolved2, children: [
1915
+ resolved2 === "tabs" ? /* @__PURE__ */ jsx20(
1916
+ Tabs,
1917
+ {
1918
+ tabs: list.map((e) => ({ id: e.key, label: e.title })),
1919
+ active: current,
1920
+ onChange: setActive,
1921
+ idBase: base
1922
+ }
1923
+ ) : null,
1924
+ list.map((e) => {
1925
+ const shown = isShown(e.key);
1926
+ const region = `${base}-region-${e.key}`;
1927
+ if (resolved2 === "tabs") {
1928
+ return /* @__PURE__ */ createElement9(
1929
+ "section",
1930
+ {
1931
+ ...sectionPart,
1932
+ key: e.key,
1933
+ id: `${base}-panel-${e.key}`,
1934
+ role: "tabpanel",
1935
+ "aria-labelledby": `${base}-tab-${e.key}`,
1936
+ hidden: !shown,
1937
+ "data-section": e.key
1938
+ },
1939
+ /* @__PURE__ */ jsx20("h2", { ...titlePart, "data-section-title": "", "data-in-tabs": "", children: e.title }),
1940
+ /* @__PURE__ */ jsx20("div", { ...bodyPart, children: e.body })
1941
+ );
1942
+ }
1943
+ if (resolved2 === "accordion") {
1944
+ return /* @__PURE__ */ createElement9("section", { ...sectionPart, key: e.key, id: `${base}-panel-${e.key}`, "data-section": e.key }, /* @__PURE__ */ jsx20("h2", { ...titlePart, "data-section-title": "", children: /* @__PURE__ */ jsxs9("button", { ...triggerPart, type: "button", "aria-expanded": shown, "aria-controls": region, onClick: () => toggle(e.key), children: [
1945
+ e.title,
1946
+ /* @__PURE__ */ jsx20(Icon3, { name: shown ? "chevron-up" : "chevron-down", size: 16 })
1947
+ ] }) }), /* @__PURE__ */ jsx20("div", { ...bodyPart, id: region, role: "region", hidden: !shown, children: e.body }));
1948
+ }
1949
+ return /* @__PURE__ */ createElement9("section", { ...sectionPart, key: e.key, id: `${base}-panel-${e.key}`, "data-section": e.key }, /* @__PURE__ */ jsx20("h2", { ...titlePart, "data-section-title": "", children: e.title }), /* @__PURE__ */ jsx20("div", { ...bodyPart, children: e.body }));
1950
+ })
1951
+ ] });
1952
+ }
1953
+
1954
+ // src/product/StickyAddToCart.tsx
1955
+ import { useEffect as useEffect6, useState as useState7 } from "react";
1956
+ import { jsx as jsx21, jsxs as jsxs10 } from "react/jsx-runtime";
1957
+ function StickyAddToCart({ classNames, className, unstyled }) {
1958
+ const local = { classNames, unstyled };
1959
+ const { product, variant, priceContext, add, adding, stock, sku, addToCartRef } = useProductPage();
1960
+ const { currency } = useStorefront();
1961
+ const { t } = useStrings();
1962
+ const [shown, setShown] = useState7(false);
1963
+ const root = usePart("sticky-add-to-cart", { ...local, className });
1964
+ const titlePart = usePart("sticky-add-to-cart-title", local);
1965
+ const pricePart = usePart("sticky-add-to-cart-price", local);
1966
+ const button = usePart("sticky-add-to-cart-button", local);
1967
+ useEffect6(() => {
1968
+ const target = addToCartRef.current;
1969
+ if (!target || typeof IntersectionObserver === "undefined") return;
1970
+ const observer = new IntersectionObserver(([entry]) => {
1971
+ setShown(!!entry && !entry.isIntersecting && entry.boundingClientRect.top < 0);
1972
+ });
1973
+ observer.observe(target);
1974
+ return () => observer.disconnect();
1975
+ }, [addToCartRef]);
1976
+ if (!shown) return null;
1977
+ const now = variant ? variant.salePriceMinor ?? variant.priceMinor : null;
1978
+ const priced = variant?.currency ?? currency;
1979
+ const cannot = !sku || stock === "out" || stock === "no_currency";
1980
+ return /* @__PURE__ */ jsxs10("div", { ...root, role: "region", "aria-label": t("product.sticky.label"), children: [
1981
+ /* @__PURE__ */ jsx21("p", { ...titlePart, children: product.title ?? product.handle }),
1982
+ now !== null && priced ? /* @__PURE__ */ jsx21("p", { ...pricePart, children: /* @__PURE__ */ jsx21(Price, { ...local, minor: now, currency: priced, priceContext }) }) : null,
1983
+ /* @__PURE__ */ jsx21("button", { ...button, type: "button", disabled: cannot, "aria-disabled": adding || void 0, onClick: () => !adding && void add(), children: adding ? t("product.cartAdd.adding") : t("product.addToCart") })
1984
+ ] });
1985
+ }
1986
+
1987
+ // src/product/ProductPage.tsx
1988
+ import { useProduct } from "@usethrottle/catalog/react";
1989
+ import { EmptyState, Skeleton as Skeleton2 } from "@usethrottle/ui";
1990
+ import { useEffect as useEffect7, useMemo as useMemo4 } from "react";
1991
+ import { Fragment as Fragment4, jsx as jsx22, jsxs as jsxs11 } from "react/jsx-runtime";
1992
+ function handleFromPath(pattern, pathname) {
1993
+ const [head, tail = ""] = pattern.split("{handle}");
1994
+ if (!pathname.startsWith(head) || !pathname.endsWith(tail) || pathname.length <= head.length + tail.length) return null;
1995
+ const raw = pathname.slice(head.length, pathname.length - tail.length);
1996
+ if (raw.includes("/")) return null;
1997
+ try {
1998
+ return decodeURIComponent(raw);
1999
+ } catch {
2000
+ return null;
2001
+ }
2002
+ }
2003
+ function Loaded(props) {
2004
+ const { product, priceContext, initialData, children, classNames, className, unstyled } = props;
2005
+ const { settings } = useStorefront();
2006
+ const value = useProductPageState({
2007
+ product,
2008
+ priceContext,
2009
+ initialSku: initialData?.variantSku ?? null,
2010
+ related: initialData?.related,
2011
+ generatedAt: initialData?.generatedAt,
2012
+ reviews: initialData?.reviews,
2013
+ shippingPage: initialData?.shippingPage,
2014
+ layout: props.layout ?? settings.product.layout,
2015
+ sectionsStyle: props.sectionsStyle ?? settings.product.sectionsStyle,
2016
+ reviewsLayout: props.reviewsLayout,
2017
+ baseUrl: (props.baseUrl ?? "").replace(/\/+$/u, "")
2018
+ });
2019
+ const root = usePart("product-page", { classNames, className, unstyled });
2020
+ return /* @__PURE__ */ jsx22(ProductPageContext.Provider, { value, children: /* @__PURE__ */ jsx22("div", { ...root, "data-layout": value.layout, "data-sections-style": value.sectionsStyle, "data-product-page": product.handle, children }) });
2021
+ }
2022
+ function Root(props) {
2023
+ const { settings, router } = useStorefront();
2024
+ const { t } = useStrings();
2025
+ const { classNames, className, unstyled } = props;
2026
+ const handle = props.handle ?? props.initialData?.product.handle ?? handleFromPath(settings.routes.product, router.pathname);
2027
+ const seeded = useMemo4(
2028
+ () => props.initialData ? { product: props.initialData.product } : void 0,
2029
+ [props.initialData]
2030
+ );
2031
+ const query = useProduct(handle, { initialData: seeded });
2032
+ const data = query.data;
2033
+ const redirectTo = data && "redirectTo" in data ? data.redirectTo : null;
2034
+ useEffect7(() => {
2035
+ if (redirectTo) router.replace(routeHref(settings, "product", redirectTo));
2036
+ }, [redirectTo, router, settings]);
2037
+ const root = usePart("product-page", { classNames, className, unstyled });
2038
+ if (data && "product" in data) {
2039
+ return /* @__PURE__ */ jsx22(Loaded, { ...props, product: data.product, priceContext: data.priceContext });
2040
+ }
2041
+ if (query.error || redirectTo) {
2042
+ return /* @__PURE__ */ jsx22("div", { ...root, "data-status": "empty", children: redirectTo ? null : /* @__PURE__ */ jsx22(EmptyState, { title: t("error.notFound") }) });
2043
+ }
2044
+ return /* @__PURE__ */ jsx22("div", { ...root, "data-status": "loading", "aria-busy": "true", children: /* @__PURE__ */ jsx22(Skeleton2, { count: 4 }) });
2045
+ }
2046
+ function ProductJsonLd() {
2047
+ const { product, baseUrl } = useProductPage();
2048
+ const { settings, currency } = useStorefront();
2049
+ const { t } = useStrings();
2050
+ const url = `${baseUrl}${routeHref(settings, "product", product.handle)}`;
2051
+ const priced = currency ?? product.variants.find((v) => v.currency)?.currency ?? product.priceRange?.currency;
2052
+ const crumbs = productCrumbs(product, settings, t("product.crumbs.home")).map((c) => ({ name: c.name, url: `${baseUrl}${c.href}` }));
2053
+ return /* @__PURE__ */ jsxs11(Fragment4, { children: [
2054
+ priced ? /* @__PURE__ */ jsx22(JsonLd, { data: productJsonLd(product, { url, settings, currency: priced }) }) : null,
2055
+ /* @__PURE__ */ jsx22(JsonLd, { data: breadcrumbJsonLd(crumbs) })
2056
+ ] });
2057
+ }
2058
+ function SlotAbove() {
2059
+ const { product, sku } = useProductPage();
2060
+ return /* @__PURE__ */ jsx22(SlotOutlet, { name: "product.above", context: { kind: "product", product, variantSku: sku } });
2061
+ }
2062
+ function SlotBelow() {
2063
+ const { product, sku } = useProductPage();
2064
+ return /* @__PURE__ */ jsx22(SlotOutlet, { name: "product.below", context: { kind: "product", product, variantSku: sku } });
2065
+ }
2066
+ function Main({ classNames, unstyled }) {
2067
+ const main = usePart("product-page-main", { classNames, unstyled });
2068
+ return /* @__PURE__ */ jsxs11("div", { ...main, children: [
2069
+ /* @__PURE__ */ jsx22(Gallery, { classNames, unstyled }),
2070
+ /* @__PURE__ */ jsx22(BuyBox, { classNames, unstyled })
2071
+ ] });
2072
+ }
2073
+ function ProductPageImpl(props) {
2074
+ const { children, classNames, unstyled } = props;
2075
+ const local = { classNames, unstyled };
2076
+ return /* @__PURE__ */ jsx22(Root, { ...props, children: children ?? /* @__PURE__ */ jsxs11(Fragment4, { children: [
2077
+ /* @__PURE__ */ jsx22(ProductJsonLd, {}),
2078
+ /* @__PURE__ */ jsx22(Breadcrumbs, { ...local }),
2079
+ /* @__PURE__ */ jsx22(SlotAbove, {}),
2080
+ /* @__PURE__ */ jsx22(Main, { ...local }),
2081
+ /* @__PURE__ */ jsx22(SlotBelow, {}),
2082
+ /* @__PURE__ */ jsx22(ProductSections, { ...local }),
2083
+ /* @__PURE__ */ jsx22(StickyAddToCart, { ...local })
2084
+ ] }) });
2085
+ }
2086
+ var ProductPage = Object.assign(ProductPageImpl, {
2087
+ Root,
2088
+ JsonLd: ProductJsonLd,
2089
+ Breadcrumbs,
2090
+ SlotAbove,
2091
+ Gallery,
2092
+ BuyBox,
2093
+ VariantPicker,
2094
+ Price,
2095
+ StockStatus,
2096
+ QuantityInput,
2097
+ AddToCart,
2098
+ StickyAddToCart,
2099
+ ProductSections,
2100
+ ShippingSection,
2101
+ TagList,
2102
+ CategoryList,
2103
+ RelatedProducts,
2104
+ Reviews,
2105
+ ReviewForm,
2106
+ SlotBelow
2107
+ });
2108
+
2109
+ // src/shopper/quiet-router.tsx
2110
+ import { useMemo as useMemo5 } from "react";
2111
+ import { jsx as jsx23 } from "react/jsx-runtime";
2112
+ var NOOP = () => {
2113
+ };
2114
+ function QuietRouter({ pathname, children }) {
2115
+ const outer = useStorefront();
2116
+ const value = useMemo5(
2117
+ () => ({ ...outer, router: { pathname, searchParams: new URLSearchParams(), push: NOOP, replace: NOOP } }),
2118
+ [outer, pathname]
2119
+ );
2120
+ return /* @__PURE__ */ jsx23(StorefrontContext.Provider, { value, children });
2121
+ }
2122
+
2123
+ export {
2124
+ SlotOutlet,
2125
+ parseShopQuery,
2126
+ shopQueryToSearch,
2127
+ pageWindow,
2128
+ variantFromSearch,
2129
+ robotsForShopQuery,
2130
+ canonicalForShopQuery,
2131
+ JsonLd,
2132
+ productJsonLd,
2133
+ breadcrumbJsonLd,
2134
+ itemListJsonLd,
2135
+ shopAllMetadata,
2136
+ searchMetadata,
2137
+ productMetadata,
2138
+ Badge,
2139
+ cardBadges,
2140
+ WishlistButton,
2141
+ BackInStock,
2142
+ FrequentlyBoughtTogether,
2143
+ ReviewPhotos,
2144
+ ReviewVotes,
2145
+ QuestionsAndAnswers,
2146
+ Swatch,
2147
+ pickerKind,
2148
+ selectOption,
2149
+ useProductPage,
2150
+ AddToCart,
2151
+ productCrumbs,
2152
+ Breadcrumbs,
2153
+ QuantityInput,
2154
+ stockWord,
2155
+ StockStatus,
2156
+ VariantPicker,
2157
+ BuyBox,
2158
+ CategoryList,
2159
+ Gallery,
2160
+ sanitizeHtml,
2161
+ RichText,
2162
+ useRelatedProducts,
2163
+ RelatedProducts,
2164
+ ReviewForm,
2165
+ Reviews,
2166
+ useShippingContent,
2167
+ ShippingSection,
2168
+ TagList,
2169
+ ProductSections,
2170
+ StickyAddToCart,
2171
+ ProductPage,
2172
+ QuietRouter,
2173
+ ProductCard
2174
+ };
2175
+ //# sourceMappingURL=chunk-D76CRI4X.js.map