@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,128 @@
1
+ "use client";
2
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }"use client";
3
+
4
+
5
+ var _chunkXQHGFWLGcjs = require('./chunk-XQHGFWLG.cjs');
6
+
7
+
8
+ var _chunkVWXJO427cjs = require('./chunk-VWXJO427.cjs');
9
+
10
+ // src/shopper/storage.ts
11
+ var _react = require('react');
12
+ var NONE = Object.freeze([]);
13
+ function parse(text, max) {
14
+ if (text === null) return NONE;
15
+ try {
16
+ const value = JSON.parse(text);
17
+ if (!Array.isArray(value)) return NONE;
18
+ return clean(value, max);
19
+ } catch (e) {
20
+ return NONE;
21
+ }
22
+ }
23
+ function clean(values, max) {
24
+ const out = /* @__PURE__ */ new Set();
25
+ for (const v of values) if (typeof v === "string" && v.trim() !== "") out.add(v);
26
+ return out.size === 0 ? NONE : Object.freeze([...out].slice(0, max));
27
+ }
28
+ function createStoredList(key, max) {
29
+ const listeners = /* @__PURE__ */ new Set();
30
+ let seenText;
31
+ let snapshot = NONE;
32
+ let memory = null;
33
+ const read = () => {
34
+ if (memory) return memory;
35
+ let text;
36
+ try {
37
+ text = window.localStorage.getItem(key);
38
+ } catch (e2) {
39
+ return NONE;
40
+ }
41
+ if (text !== seenText) {
42
+ seenText = text;
43
+ snapshot = parse(text, max);
44
+ }
45
+ return snapshot;
46
+ };
47
+ const notify = () => listeners.forEach((l) => l());
48
+ const onStorage = (event) => {
49
+ if (event.key === key || event.key === null) notify();
50
+ };
51
+ const subscribe = (listener) => {
52
+ if (listeners.size === 0 && typeof window !== "undefined") window.addEventListener("storage", onStorage);
53
+ listeners.add(listener);
54
+ return () => {
55
+ listeners.delete(listener);
56
+ if (listeners.size === 0 && typeof window !== "undefined") window.removeEventListener("storage", onStorage);
57
+ };
58
+ };
59
+ return {
60
+ useIds: () => _react.useSyncExternalStore.call(void 0, subscribe, read, () => NONE),
61
+ read,
62
+ write(ids) {
63
+ const next = clean(ids, max);
64
+ const text = JSON.stringify(next);
65
+ try {
66
+ window.localStorage.setItem(key, text);
67
+ memory = null;
68
+ seenText = text;
69
+ snapshot = next;
70
+ } catch (e3) {
71
+ memory = next;
72
+ }
73
+ notify();
74
+ },
75
+ reset() {
76
+ seenText = void 0;
77
+ snapshot = NONE;
78
+ memory = null;
79
+ }
80
+ };
81
+ }
82
+
83
+ // src/shopper/CompareButton.tsx
84
+
85
+ var _jsxruntime = require('react/jsx-runtime');
86
+ var COMPARE_KEY = "throttle:sf:compare";
87
+ var COMPARE_MAX = 4;
88
+ var compareList = createStoredList(COMPARE_KEY, COMPARE_MAX);
89
+ function useCompare() {
90
+ const items = compareList.useIds();
91
+ const toggle = _react.useCallback.call(void 0, (handle) => {
92
+ const now = compareList.read();
93
+ if (now.includes(handle)) compareList.write(now.filter((h) => h !== handle));
94
+ else if (now.length < COMPARE_MAX) compareList.write([...now, handle]);
95
+ }, []);
96
+ const clear = _react.useCallback.call(void 0, () => compareList.write([]), []);
97
+ return _react.useMemo.call(void 0,
98
+ () => ({ items, toggle, clear, has: (handle) => items.includes(handle), full: items.length >= COMPARE_MAX }),
99
+ [items, toggle, clear]
100
+ );
101
+ }
102
+ function CompareButton({ product, ...local }) {
103
+ const { t } = _chunkXQHGFWLGcjs.useStrings.call(void 0, );
104
+ const { has, toggle, full } = useCompare();
105
+ const part = _chunkVWXJO427cjs.usePart.call(void 0, "compare-button", local);
106
+ const pressed = has(product.handle);
107
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
108
+ "button",
109
+ {
110
+ ...part,
111
+ type: "button",
112
+ "aria-pressed": pressed,
113
+ "aria-label": t("shopper.compare.buttonFor", { title: _nullishCoalesce(product.title, () => ( product.handle)) }),
114
+ disabled: full && !pressed,
115
+ title: full && !pressed ? t("shopper.compare.full", { max: COMPARE_MAX }) : void 0,
116
+ "data-compare-handle": product.handle,
117
+ onClick: () => toggle(product.handle),
118
+ children: t("shopper.compare.button")
119
+ }
120
+ );
121
+ }
122
+
123
+
124
+
125
+
126
+
127
+ exports.createStoredList = createStoredList; exports.useCompare = useCompare; exports.CompareButton = CompareButton;
128
+ //# sourceMappingURL=chunk-PNJOFFTL.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-PNJOFFTL.cjs","../src/shopper/storage.ts","../src/shopper/CompareButton.tsx"],"names":[],"mappings":"AAAA,yLAAY;AACZ;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACRA,8BAAqC;AAErC,IAAM,KAAA,EAA0B,MAAA,CAAO,MAAA,CAAO,CAAC,CAAC,CAAA;AAchD,SAAS,KAAA,CAAM,IAAA,EAAqB,GAAA,EAAgC;AAClE,EAAA,GAAA,CAAI,KAAA,IAAS,IAAA,EAAM,OAAO,IAAA;AAC1B,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,EAAiB,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA;AACtC,IAAA,GAAA,CAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG,OAAO,IAAA;AAClC,IAAA,OAAO,KAAA,CAAM,KAAA,EAAO,GAA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DA;AACA;AACE;AACA;AACA;AACF,oHAAC","file":"/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-PNJOFFTL.cjs","sourcesContent":[null,"import { useSyncExternalStore } from 'react';\n\nconst NONE: readonly string[] = Object.freeze([]);\n\n/** A short list of ids kept in `localStorage` (and readable by `useSyncExternalStore`). */\nexport type StoredList = {\n /** The ids now, or none on the server and while the browser's storage cannot be read. */\n useIds(): readonly string[];\n read(): readonly string[];\n /** Replaces the list: blanks and repeats dropped, at most `max` kept, in the order given. */\n write(ids: readonly string[]): void;\n /** Forgets what was read, so the next read asks the storage again. */\n reset(): void;\n};\n\n/** An array of non-empty strings, from JSON text; anything else is an empty list. */\nfunction parse(text: string | null, max: number): readonly string[] {\n if (text === null) return NONE;\n try {\n const value: unknown = JSON.parse(text);\n if (!Array.isArray(value)) return NONE;\n return clean(value, max);\n } catch {\n return NONE;\n }\n}\n\nfunction clean(values: readonly unknown[], max: number): readonly string[] {\n const out = new Set<string>();\n for (const v of values) if (typeof v === 'string' && v.trim() !== '') out.add(v);\n return out.size === 0 ? NONE : Object.freeze([...out].slice(0, max));\n}\n\n/**\n * A short list of ids kept in `localStorage` under `key`. Ids only (a product handle), never a name,\n * an email or an account. Every access is in try/catch: a blocked or full storage, or one that throws\n * (private windows, a disabled setting), reads as an empty list and the page keeps working. If a write\n * fails the list lives in memory for the rest of the visit.\n *\n * `useIds` is a `useSyncExternalStore`: the server snapshot is always empty, so the server markup and\n * the first client render agree, then the stored ids appear once hydrated. Other tabs are followed\n * through the `storage` event.\n */\nexport function createStoredList(key: string, max: number): StoredList {\n const listeners = new Set<() => void>();\n // What was last read: the text, and the list it parsed to (one array while the text is the same).\n let seenText: string | null | undefined;\n let snapshot: readonly string[] = NONE;\n // Set when a write failed: the list is then kept here and the storage is not asked again.\n let memory: readonly string[] | null = null;\n\n const read = (): readonly string[] => {\n if (memory) return memory;\n let text: string | null;\n try {\n text = window.localStorage.getItem(key);\n } catch {\n return NONE;\n }\n if (text !== seenText) {\n seenText = text;\n snapshot = parse(text, max);\n }\n return snapshot;\n };\n\n const notify = () => listeners.forEach((l) => l());\n const onStorage = (event: StorageEvent) => {\n if (event.key === key || event.key === null) notify();\n };\n\n const subscribe = (listener: () => void): (() => void) => {\n if (listeners.size === 0 && typeof window !== 'undefined') window.addEventListener('storage', onStorage);\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n if (listeners.size === 0 && typeof window !== 'undefined') window.removeEventListener('storage', onStorage);\n };\n };\n\n return {\n useIds: () => useSyncExternalStore(subscribe, read, () => NONE),\n read,\n write(ids) {\n const next = clean(ids, max);\n const text = JSON.stringify(next);\n try {\n window.localStorage.setItem(key, text);\n memory = null;\n seenText = text;\n snapshot = next;\n } catch {\n memory = next;\n }\n notify();\n },\n reset() {\n seenText = undefined;\n snapshot = NONE;\n memory = null;\n },\n };\n}\n","import type { ListProduct } from '@usethrottle/catalog';\nimport { useCallback, useMemo } from 'react';\nimport { usePart, type UsePartLocal } from '../parts';\nimport { useStrings } from '../strings';\nimport { createStoredList } from './storage';\n\n/** The browser key and the most products compared at once. */\nexport const COMPARE_KEY = 'throttle:sf:compare';\nexport const COMPARE_MAX = 4;\n\nexport const compareList = createStoredList(COMPARE_KEY, COMPARE_MAX);\n\n/** What `useCompare()` answers: the handles chosen and how to change them. */\nexport type CompareState = {\n /** The handles being compared, in the order they were added. Empty on the server and before hydration. */\n items: string[];\n /** Adds the handle, or removes it when it is there. A fifth product is not added. */\n toggle(handle: string): void;\n clear(): void;\n has(handle: string): boolean;\n /** Four are chosen: only a removal changes the list. */\n full: boolean;\n};\n\n/** The products to compare (2 to 4), kept in `localStorage` as handles only. */\nexport function useCompare(): CompareState {\n const items = compareList.useIds() as string[];\n const toggle = useCallback((handle: string) => {\n const now = compareList.read();\n if (now.includes(handle)) compareList.write(now.filter((h) => h !== handle));\n else if (now.length < COMPARE_MAX) compareList.write([...now, handle]);\n }, []);\n const clear = useCallback(() => compareList.write([]), []);\n return useMemo(\n () => ({ items, toggle, clear, has: (handle: string) => items.includes(handle), full: items.length >= COMPARE_MAX }),\n [items, toggle, clear],\n );\n}\n\n/** A toggle that adds a product to the comparison or removes it. */\nexport type CompareButtonProps = UsePartLocal & {\n /** The product to add or remove: its handle and its title (the button's accessible name). */\n product: Pick<ListProduct, 'handle' | 'title'>;\n};\n\n/**\n * Adds a product to the comparison, or takes it out. A toggle button: its name stays the same and\n * `aria-pressed` says whether the product is in. With four chosen it is disabled for the others.\n */\nexport function CompareButton({ product, ...local }: CompareButtonProps) {\n const { t } = useStrings();\n const { has, toggle, full } = useCompare();\n const part = usePart('compare-button', local);\n const pressed = has(product.handle);\n return (\n <button\n {...part}\n type=\"button\"\n aria-pressed={pressed}\n aria-label={t('shopper.compare.buttonFor', { title: product.title ?? product.handle })}\n disabled={full && !pressed}\n title={full && !pressed ? t('shopper.compare.full', { max: COMPARE_MAX }) : undefined}\n data-compare-handle={product.handle}\n onClick={() => toggle(product.handle)}\n >\n {t('shopper.compare.button')}\n </button>\n );\n}\n"]}
@@ -0,0 +1,127 @@
1
+ "use client";
2
+ import {
3
+ useStrings
4
+ } from "./chunk-Q3XFD5UI.js";
5
+ import {
6
+ usePart
7
+ } from "./chunk-NNE4FYRT.js";
8
+
9
+ // src/shopper/storage.ts
10
+ import { useSyncExternalStore } from "react";
11
+ var NONE = Object.freeze([]);
12
+ function parse(text, max) {
13
+ if (text === null) return NONE;
14
+ try {
15
+ const value = JSON.parse(text);
16
+ if (!Array.isArray(value)) return NONE;
17
+ return clean(value, max);
18
+ } catch {
19
+ return NONE;
20
+ }
21
+ }
22
+ function clean(values, max) {
23
+ const out = /* @__PURE__ */ new Set();
24
+ for (const v of values) if (typeof v === "string" && v.trim() !== "") out.add(v);
25
+ return out.size === 0 ? NONE : Object.freeze([...out].slice(0, max));
26
+ }
27
+ function createStoredList(key, max) {
28
+ const listeners = /* @__PURE__ */ new Set();
29
+ let seenText;
30
+ let snapshot = NONE;
31
+ let memory = null;
32
+ const read = () => {
33
+ if (memory) return memory;
34
+ let text;
35
+ try {
36
+ text = window.localStorage.getItem(key);
37
+ } catch {
38
+ return NONE;
39
+ }
40
+ if (text !== seenText) {
41
+ seenText = text;
42
+ snapshot = parse(text, max);
43
+ }
44
+ return snapshot;
45
+ };
46
+ const notify = () => listeners.forEach((l) => l());
47
+ const onStorage = (event) => {
48
+ if (event.key === key || event.key === null) notify();
49
+ };
50
+ const subscribe = (listener) => {
51
+ if (listeners.size === 0 && typeof window !== "undefined") window.addEventListener("storage", onStorage);
52
+ listeners.add(listener);
53
+ return () => {
54
+ listeners.delete(listener);
55
+ if (listeners.size === 0 && typeof window !== "undefined") window.removeEventListener("storage", onStorage);
56
+ };
57
+ };
58
+ return {
59
+ useIds: () => useSyncExternalStore(subscribe, read, () => NONE),
60
+ read,
61
+ write(ids) {
62
+ const next = clean(ids, max);
63
+ const text = JSON.stringify(next);
64
+ try {
65
+ window.localStorage.setItem(key, text);
66
+ memory = null;
67
+ seenText = text;
68
+ snapshot = next;
69
+ } catch {
70
+ memory = next;
71
+ }
72
+ notify();
73
+ },
74
+ reset() {
75
+ seenText = void 0;
76
+ snapshot = NONE;
77
+ memory = null;
78
+ }
79
+ };
80
+ }
81
+
82
+ // src/shopper/CompareButton.tsx
83
+ import { useCallback, useMemo } from "react";
84
+ import { jsx } from "react/jsx-runtime";
85
+ var COMPARE_KEY = "throttle:sf:compare";
86
+ var COMPARE_MAX = 4;
87
+ var compareList = createStoredList(COMPARE_KEY, COMPARE_MAX);
88
+ function useCompare() {
89
+ const items = compareList.useIds();
90
+ const toggle = useCallback((handle) => {
91
+ const now = compareList.read();
92
+ if (now.includes(handle)) compareList.write(now.filter((h) => h !== handle));
93
+ else if (now.length < COMPARE_MAX) compareList.write([...now, handle]);
94
+ }, []);
95
+ const clear = useCallback(() => compareList.write([]), []);
96
+ return useMemo(
97
+ () => ({ items, toggle, clear, has: (handle) => items.includes(handle), full: items.length >= COMPARE_MAX }),
98
+ [items, toggle, clear]
99
+ );
100
+ }
101
+ function CompareButton({ product, ...local }) {
102
+ const { t } = useStrings();
103
+ const { has, toggle, full } = useCompare();
104
+ const part = usePart("compare-button", local);
105
+ const pressed = has(product.handle);
106
+ return /* @__PURE__ */ jsx(
107
+ "button",
108
+ {
109
+ ...part,
110
+ type: "button",
111
+ "aria-pressed": pressed,
112
+ "aria-label": t("shopper.compare.buttonFor", { title: product.title ?? product.handle }),
113
+ disabled: full && !pressed,
114
+ title: full && !pressed ? t("shopper.compare.full", { max: COMPARE_MAX }) : void 0,
115
+ "data-compare-handle": product.handle,
116
+ onClick: () => toggle(product.handle),
117
+ children: t("shopper.compare.button")
118
+ }
119
+ );
120
+ }
121
+
122
+ export {
123
+ createStoredList,
124
+ useCompare,
125
+ CompareButton
126
+ };
127
+ //# sourceMappingURL=chunk-PXZQ4ONA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shopper/storage.ts","../src/shopper/CompareButton.tsx"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nconst NONE: readonly string[] = Object.freeze([]);\n\n/** A short list of ids kept in `localStorage` (and readable by `useSyncExternalStore`). */\nexport type StoredList = {\n /** The ids now, or none on the server and while the browser's storage cannot be read. */\n useIds(): readonly string[];\n read(): readonly string[];\n /** Replaces the list: blanks and repeats dropped, at most `max` kept, in the order given. */\n write(ids: readonly string[]): void;\n /** Forgets what was read, so the next read asks the storage again. */\n reset(): void;\n};\n\n/** An array of non-empty strings, from JSON text; anything else is an empty list. */\nfunction parse(text: string | null, max: number): readonly string[] {\n if (text === null) return NONE;\n try {\n const value: unknown = JSON.parse(text);\n if (!Array.isArray(value)) return NONE;\n return clean(value, max);\n } catch {\n return NONE;\n }\n}\n\nfunction clean(values: readonly unknown[], max: number): readonly string[] {\n const out = new Set<string>();\n for (const v of values) if (typeof v === 'string' && v.trim() !== '') out.add(v);\n return out.size === 0 ? NONE : Object.freeze([...out].slice(0, max));\n}\n\n/**\n * A short list of ids kept in `localStorage` under `key`. Ids only (a product handle), never a name,\n * an email or an account. Every access is in try/catch: a blocked or full storage, or one that throws\n * (private windows, a disabled setting), reads as an empty list and the page keeps working. If a write\n * fails the list lives in memory for the rest of the visit.\n *\n * `useIds` is a `useSyncExternalStore`: the server snapshot is always empty, so the server markup and\n * the first client render agree, then the stored ids appear once hydrated. Other tabs are followed\n * through the `storage` event.\n */\nexport function createStoredList(key: string, max: number): StoredList {\n const listeners = new Set<() => void>();\n // What was last read: the text, and the list it parsed to (one array while the text is the same).\n let seenText: string | null | undefined;\n let snapshot: readonly string[] = NONE;\n // Set when a write failed: the list is then kept here and the storage is not asked again.\n let memory: readonly string[] | null = null;\n\n const read = (): readonly string[] => {\n if (memory) return memory;\n let text: string | null;\n try {\n text = window.localStorage.getItem(key);\n } catch {\n return NONE;\n }\n if (text !== seenText) {\n seenText = text;\n snapshot = parse(text, max);\n }\n return snapshot;\n };\n\n const notify = () => listeners.forEach((l) => l());\n const onStorage = (event: StorageEvent) => {\n if (event.key === key || event.key === null) notify();\n };\n\n const subscribe = (listener: () => void): (() => void) => {\n if (listeners.size === 0 && typeof window !== 'undefined') window.addEventListener('storage', onStorage);\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n if (listeners.size === 0 && typeof window !== 'undefined') window.removeEventListener('storage', onStorage);\n };\n };\n\n return {\n useIds: () => useSyncExternalStore(subscribe, read, () => NONE),\n read,\n write(ids) {\n const next = clean(ids, max);\n const text = JSON.stringify(next);\n try {\n window.localStorage.setItem(key, text);\n memory = null;\n seenText = text;\n snapshot = next;\n } catch {\n memory = next;\n }\n notify();\n },\n reset() {\n seenText = undefined;\n snapshot = NONE;\n memory = null;\n },\n };\n}\n","import type { ListProduct } from '@usethrottle/catalog';\nimport { useCallback, useMemo } from 'react';\nimport { usePart, type UsePartLocal } from '../parts';\nimport { useStrings } from '../strings';\nimport { createStoredList } from './storage';\n\n/** The browser key and the most products compared at once. */\nexport const COMPARE_KEY = 'throttle:sf:compare';\nexport const COMPARE_MAX = 4;\n\nexport const compareList = createStoredList(COMPARE_KEY, COMPARE_MAX);\n\n/** What `useCompare()` answers: the handles chosen and how to change them. */\nexport type CompareState = {\n /** The handles being compared, in the order they were added. Empty on the server and before hydration. */\n items: string[];\n /** Adds the handle, or removes it when it is there. A fifth product is not added. */\n toggle(handle: string): void;\n clear(): void;\n has(handle: string): boolean;\n /** Four are chosen: only a removal changes the list. */\n full: boolean;\n};\n\n/** The products to compare (2 to 4), kept in `localStorage` as handles only. */\nexport function useCompare(): CompareState {\n const items = compareList.useIds() as string[];\n const toggle = useCallback((handle: string) => {\n const now = compareList.read();\n if (now.includes(handle)) compareList.write(now.filter((h) => h !== handle));\n else if (now.length < COMPARE_MAX) compareList.write([...now, handle]);\n }, []);\n const clear = useCallback(() => compareList.write([]), []);\n return useMemo(\n () => ({ items, toggle, clear, has: (handle: string) => items.includes(handle), full: items.length >= COMPARE_MAX }),\n [items, toggle, clear],\n );\n}\n\n/** A toggle that adds a product to the comparison or removes it. */\nexport type CompareButtonProps = UsePartLocal & {\n /** The product to add or remove: its handle and its title (the button's accessible name). */\n product: Pick<ListProduct, 'handle' | 'title'>;\n};\n\n/**\n * Adds a product to the comparison, or takes it out. A toggle button: its name stays the same and\n * `aria-pressed` says whether the product is in. With four chosen it is disabled for the others.\n */\nexport function CompareButton({ product, ...local }: CompareButtonProps) {\n const { t } = useStrings();\n const { has, toggle, full } = useCompare();\n const part = usePart('compare-button', local);\n const pressed = has(product.handle);\n return (\n <button\n {...part}\n type=\"button\"\n aria-pressed={pressed}\n aria-label={t('shopper.compare.buttonFor', { title: product.title ?? product.handle })}\n disabled={full && !pressed}\n title={full && !pressed ? t('shopper.compare.full', { max: COMPARE_MAX }) : undefined}\n data-compare-handle={product.handle}\n onClick={() => toggle(product.handle)}\n >\n {t('shopper.compare.button')}\n </button>\n );\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,4BAA4B;AAErC,IAAM,OAA0B,OAAO,OAAO,CAAC,CAAC;AAchD,SAAS,MAAM,MAAqB,KAA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AAQ,KAAK,IAAI,WAAW;AACzC,QAAM,OAAO,QAAQ,kBAAkB,KAAK;AAC5C,QAAM,UAAU,IAAI,QAAQ,MAAM;AAClC,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,MAAK;AAAA,MACL,gBAAc;AAAA,MACd,cAAY,EAAE,6BAA6B,EAAE,OAAO,QAAQ,SAAS,QAAQ,OAAO,CAAC;AAAA,MACrF,UAAU,QAAQ,CAAC;AAAA,MACnB,OAAO,QAAQ,CAAC,UAAU,EAAE,wBAAwB,EAAE,KAAK,YAAY,CAAC,IAAI;AAAA,MAC5E,uBAAqB,QAAQ;AAAA,MAC7B,SAAS,MAAM,OAAO,QAAQ,MAAM;AAAA,MAEnC,YAAE,wBAAwB;AAAA;AAAA,EAC7B;AAEJ;","names":[]}
@@ -0,0 +1,82 @@
1
+ "use client";
2
+ import {
3
+ BuyBox,
4
+ Gallery,
5
+ ProductPage,
6
+ QuietRouter,
7
+ useProductPage
8
+ } from "./chunk-D76CRI4X.js";
9
+ import "./chunk-A3IFWQUV.js";
10
+ import "./chunk-66HDJVPS.js";
11
+ import {
12
+ routeHref
13
+ } from "./chunk-LW2A6USV.js";
14
+ import "./chunk-IJOTLGPT.js";
15
+ import "./chunk-HSUUDZWS.js";
16
+ import {
17
+ useStrings
18
+ } from "./chunk-Q3XFD5UI.js";
19
+ import {
20
+ usePart,
21
+ useStorefront
22
+ } from "./chunk-NNE4FYRT.js";
23
+
24
+ // src/shopper/QuickViewBody.tsx
25
+ import { useProduct } from "@usethrottle/catalog/react";
26
+ import { Modal } from "@usethrottle/ui";
27
+ import { useId, useLayoutEffect, useRef, useState } from "react";
28
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
29
+ function Content({ onNavigate, ...local }) {
30
+ const { product } = useProductPage();
31
+ const { settings, Link: Anchor } = useStorefront();
32
+ const { t } = useStrings();
33
+ const body = usePart("quick-view-body", local);
34
+ const gallery = usePart("quick-view-gallery", local);
35
+ const details = usePart("quick-view-details", local);
36
+ const link = usePart("quick-view-link", local);
37
+ return /* @__PURE__ */ jsxs("div", { ...body, "data-quick-view": product.handle, children: [
38
+ /* @__PURE__ */ jsx("div", { ...gallery, children: /* @__PURE__ */ jsx(Gallery, { ...local }) }),
39
+ /* @__PURE__ */ jsxs("div", { ...details, children: [
40
+ /* @__PURE__ */ jsx(BuyBox, { ...local, headingLevel: 2 }),
41
+ /* @__PURE__ */ jsx(Anchor, { ...link, href: routeHref(settings, "product", product.handle), onClick: onNavigate, children: t("shopper.quickView.viewDetails") })
42
+ ] })
43
+ ] });
44
+ }
45
+ function QuickViewBody({ handle, onOpenChange, openerRef, classNames, unstyled, className }) {
46
+ const local = { classNames, unstyled };
47
+ const { settings } = useStorefront();
48
+ const { t } = useStrings();
49
+ const titleId = useId();
50
+ const sentinel = useRef(null);
51
+ const [host, setHost] = useState(void 0);
52
+ useLayoutEffect(() => setHost(sentinel.current?.closest(".tsf-root") ?? null), []);
53
+ const read = useProduct(handle);
54
+ const found = read.data && "product" in read.data ? read.data.product : null;
55
+ const name = found ? found.title ?? found.handle : null;
56
+ const title = usePart("quick-view-title", local);
57
+ const root = usePart("quick-view", { ...local, className });
58
+ const message = usePart("quick-view-message", local);
59
+ const close = () => onOpenChange(false);
60
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
61
+ /* @__PURE__ */ jsx("span", { ref: sentinel, hidden: true }),
62
+ host === void 0 ? null : /* @__PURE__ */ jsxs(
63
+ Modal,
64
+ {
65
+ open: true,
66
+ onClose: close,
67
+ labelledBy: titleId,
68
+ container: host,
69
+ closeLabel: t("shopper.quickView.closeLabel"),
70
+ restoreFocusTo: openerRef.current,
71
+ children: [
72
+ /* @__PURE__ */ jsx("h2", { ...title, id: titleId, children: name ? t("shopper.quickView.title", { title: name }) : t("shopper.quickView.loadingTitle") }),
73
+ /* @__PURE__ */ jsx("div", { ...root, children: read.error && !read.data ? /* @__PURE__ */ jsx("p", { ...message, role: "alert", children: t("shopper.quickView.notFound") }) : /* @__PURE__ */ jsx(QuietRouter, { pathname: routeHref(settings, "product", handle), children: /* @__PURE__ */ jsx(ProductPage.Root, { handle, ...local, children: /* @__PURE__ */ jsx(Content, { onNavigate: close, ...local }) }) }) })
74
+ ]
75
+ }
76
+ )
77
+ ] });
78
+ }
79
+ export {
80
+ QuickViewBody
81
+ };
82
+ //# sourceMappingURL=chunk-Q3VTUBPP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shopper/QuickViewBody.tsx"],"sourcesContent":["import { useProduct } from '@usethrottle/catalog/react';\nimport { Modal } from '@usethrottle/ui';\nimport { useId, useLayoutEffect, useRef, useState } from 'react';\nimport type { RefObject } from 'react';\nimport { usePart } from '../parts';\nimport { BuyBox, Gallery, ProductPage, useProductPage } from '../product';\nimport { useStorefront } from '../provider/context';\nimport { useStrings } from '../strings';\nimport { routeHref } from '../url/routes';\nimport { QuietRouter } from './quiet-router';\nimport type { QuickViewProps } from './QuickView';\n\ntype BodyProps = Omit<QuickViewProps, 'open' | 'handle'> & { handle: string; openerRef: RefObject<Element | null> };\n\nfunction Content({ onNavigate, ...local }: { onNavigate(): void } & Pick<QuickViewProps, 'classNames' | 'unstyled'>) {\n const { product } = useProductPage();\n const { settings, Link: Anchor } = useStorefront();\n const { t } = useStrings();\n const body = usePart('quick-view-body', local);\n const gallery = usePart('quick-view-gallery', local);\n const details = usePart('quick-view-details', local);\n const link = usePart('quick-view-link', local);\n return (\n <div {...body} data-quick-view={product.handle}>\n <div {...gallery}>\n <Gallery {...local} />\n </div>\n <div {...details}>\n <BuyBox {...local} headingLevel={2} />\n <Anchor {...link} href={routeHref(settings, 'product', product.handle)} onClick={onNavigate}>\n {t('shopper.quickView.viewDetails')}\n </Anchor>\n </div>\n </div>\n );\n}\n\n/** The modal itself. `QuickView` loads this file when a quick view first opens. */\nexport function QuickViewBody({ handle, onOpenChange, openerRef, classNames, unstyled, className }: BodyProps) {\n const local = { classNames, unstyled };\n const { settings } = useStorefront();\n const { t } = useStrings();\n const titleId = useId();\n const sentinel = useRef<HTMLSpanElement>(null);\n // The modal goes into the storefront root, so the preset, theme variables and direction apply to it.\n const [host, setHost] = useState<HTMLElement | null | undefined>(undefined);\n useLayoutEffect(() => setHost(sentinel.current?.closest<HTMLElement>('.tsf-root') ?? null), []);\n\n // The same read the product inside makes, so the name is known without a second request.\n const read = useProduct(handle);\n const found = read.data && 'product' in read.data ? read.data.product : null;\n const name = found ? (found.title ?? found.handle) : null;\n const title = usePart('quick-view-title', local);\n const root = usePart('quick-view', { ...local, className });\n const message = usePart('quick-view-message', local);\n const close = () => onOpenChange(false);\n\n return (\n <>\n <span ref={sentinel} hidden />\n {host === undefined ? null : (\n <Modal\n open\n onClose={close}\n labelledBy={titleId}\n container={host}\n closeLabel={t('shopper.quickView.closeLabel')}\n restoreFocusTo={openerRef.current}\n >\n <h2 {...title} id={titleId}>\n {name ? t('shopper.quickView.title', { title: name }) : t('shopper.quickView.loadingTitle')}\n </h2>\n <div {...root}>\n {read.error && !read.data ? (\n <p {...message} role=\"alert\">{t('shopper.quickView.notFound')}</p>\n ) : (\n <QuietRouter pathname={routeHref(settings, 'product', handle)}>\n <ProductPage.Root handle={handle} {...local}>\n <Content onNavigate={close} {...local} />\n </ProductPage.Root>\n </QuietRouter>\n )}\n </div>\n </Modal>\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,OAAO,iBAAiB,QAAQ,gBAAgB;AAuBjD,SAiCJ,UAjCI,KAEF,YAFE;AAXR,SAAS,QAAQ,EAAE,YAAY,GAAG,MAAM,GAA6E;AACnH,QAAM,EAAE,QAAQ,IAAI,eAAe;AACnC,QAAM,EAAE,UAAU,MAAM,OAAO,IAAI,cAAc;AACjD,QAAM,EAAE,EAAE,IAAI,WAAW;AACzB,QAAM,OAAO,QAAQ,mBAAmB,KAAK;AAC7C,QAAM,UAAU,QAAQ,sB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,MAAC;AAAA;AAAA,QACC,MAAI;AAAA,QACJ,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,YAAY,EAAE,8BAA8B;AAAA,QAC5C,gBAAgB,UAAU;AAAA,QAE1B;AAAA,8BAAC,QAAI,GAAG,OAAO,IAAI,SAChB,iBAAO,EAAE,2BAA2B,EAAE,OAAO,KAAK,CAAC,IAAI,EAAE,gCAAgC,GAC5F;AAAA,UACA,oBAAC,SAAK,GAAG,MACN,eAAK,SAAS,CAAC,KAAK,OACnB,oBAAC,OAAG,GAAG,SAAS,MAAK,SAAS,YAAE,4BAA4B,GAAE,IAE9D,oBAAC,eAAY,UAAU,UAAU,UAAU,WAAW,MAAM,GAC1D,8BAAC,YAAY,MAAZ,EAAiB,QAAiB,GAAG,OACpC,8BAAC,WAAQ,YAAY,OAAQ,GAAG,OAAO,GACzC,GACF,GAEJ;AAAA;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;","names":[]}
@@ -0,0 +1,45 @@
1
+ "use client";
2
+ import {
3
+ useSfCopy,
4
+ useStorefront
5
+ } from "./chunk-NNE4FYRT.js";
6
+
7
+ // src/strings/use-strings.ts
8
+ import { DEFAULT_STRINGS } from "@usethrottle/catalog";
9
+ import { useCallback, useMemo } from "react";
10
+ var isCatalogKey = (key) => Object.hasOwn(DEFAULT_STRINGS, key);
11
+ function lookup(table, key) {
12
+ let at = table;
13
+ for (const part of key.split(".")) {
14
+ if (typeof at !== "object" || at === null || !Object.hasOwn(at, part)) return void 0;
15
+ at = at[part];
16
+ }
17
+ return typeof at === "string" && at !== "" ? at : void 0;
18
+ }
19
+ function interpolate(text, vars) {
20
+ if (!vars) return text;
21
+ return text.replace(/\{(\w+)\}/g, (whole, name) => name in vars ? String(vars[name]) : whole);
22
+ }
23
+ function useStrings() {
24
+ const { settings, site } = useStorefront();
25
+ const copy = useSfCopy();
26
+ const t = useCallback(
27
+ (key, vars) => {
28
+ const fromSite = Object.hasOwn(site.builderStrings, key) ? site.builderStrings[key] : void 0;
29
+ if (typeof fromSite === "string" && fromSite !== "") return interpolate(fromSite, vars);
30
+ const local = lookup(copy, key);
31
+ if (isCatalogKey(key)) {
32
+ return interpolate(local ?? (settings.strings[key] || DEFAULT_STRINGS[key]), vars);
33
+ }
34
+ return interpolate(local ?? key, vars);
35
+ },
36
+ [site.builderStrings, settings.strings, copy]
37
+ );
38
+ const keyAttr = useCallback((key) => ({ "data-string-key": key }), []);
39
+ return useMemo(() => ({ t, keyAttr }), [t, keyAttr]);
40
+ }
41
+
42
+ export {
43
+ useStrings
44
+ };
45
+ //# sourceMappingURL=chunk-Q3XFD5UI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/strings/use-strings.ts"],"sourcesContent":["import { DEFAULT_STRINGS } from '@usethrottle/catalog';\nimport { useCallback, useMemo } from 'react';\nimport { useStorefront } from '../provider/context';\nimport { useSfCopy } from './localization';\nimport type { SfStringKey } from './en';\n\nconst isCatalogKey = (key: string): key is keyof typeof DEFAULT_STRINGS => Object.hasOwn(DEFAULT_STRINGS, key);\n\nfunction lookup(table: unknown, key: string): string | undefined {\n let at: unknown = table;\n for (const part of key.split('.')) {\n if (typeof at !== 'object' || at === null || !Object.hasOwn(at, part)) return undefined;\n at = (at as Record<string, unknown>)[part];\n }\n return typeof at === 'string' && at !== '' ? at : undefined;\n}\n\nfunction interpolate(text: string, vars?: Record<string, string | number>): string {\n if (!vars) return text;\n return text.replace(/\\{(\\w+)\\}/g, (whole, name: string) => (name in vars ? String(vars[name]) : whole));\n}\n\n/**\n * Text lookup. A key resolves, first match wins, through:\n * 1. the Builder's strings (`site.builderStrings[key]`); the catalog adapter's site strings are catalog text and rank with step 3;\n * 2. the `localization` prop (a package key by `<area>.<name>`, a catalog key by\n * its dotted path, such as `{ cart: { title: 'Basket' } }`): the developer's\n * own text beats what the catalog sends;\n * 3. for a catalog key, the catalog settings' `strings`;\n * 4. the package's English (`SF_STRINGS_EN`), or for a catalog key the SDK's `DEFAULT_STRINGS`.\n *\n * `{name}` placeholders fill from `vars`; one with no value stays as written.\n * `keyAttr(key)` is the `data-string-key` attribute the sync tests read.\n */\nexport function useStrings(): {\n t(key: SfStringKey, vars?: Record<string, string | number>): string;\n keyAttr(key: SfStringKey): { 'data-string-key': string };\n} {\n const { settings, site } = useStorefront();\n const copy = useSfCopy();\n\n const t = useCallback(\n (key: SfStringKey, vars?: Record<string, string | number>): string => {\n const fromSite = Object.hasOwn(site.builderStrings, key) ? site.builderStrings[key] : undefined;\n if (typeof fromSite === 'string' && fromSite !== '') return interpolate(fromSite, vars);\n // `copy` is English merged under the prop, so a catalog key (absent from English) is found only if the prop gave it.\n const local = lookup(copy, key);\n if (isCatalogKey(key)) {\n return interpolate(local ?? (settings.strings[key] || DEFAULT_STRINGS[key]), vars);\n }\n return interpolate(local ?? key, vars);\n },\n [site.builderStrings, settings.strings, copy],\n );\n const keyAttr = useCallback((key: SfStringKey) => ({ 'data-string-key': key as string }), []);\n return useMemo(() => ({ t, keyAttr }), [t, keyAttr]);\n}\n"],"mappings":";;;;;;;AAAA,SAAS,uBAAuB;AAChC,SAAS,aAAa,eAAe;AAKrC,IAAM,eAAe,CAAC,QAAqD,OAAO,OAAO,iBAAiB,GAAG;AAE7G,SAAS,OAAO,OAAgB,KAAiC;AAC/D,MAAI,KAAc;AAClB,aAAW,QAAQ,IAAI,MAAM,GAAG,GAAG;AACjC,QAAI,OAAO,OAAO,YAAY,OAAO,QAAQ,CAAC,OAAO,OAAO,IAAI,IAAI,EAAG,QAAO;AAC9E,SAAM,GAA+B,IAAI;AAAA,EAC3C;AACA,SAAO,OAAO,OAAO,YAAY,OAAO,KAAK,KAAK;AACpD;AAEA,SAAS,YAAY,MAAc,MAAgD;AACjF,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,KAAK,QAAQ,cAAc,CAAC,OAAO,SAAkB,QAAQ,OAAO,OAAO,KAAK,IAAI,CAAC,IAAI,KAAM;AACxG;AAcO,SAAS,aAGd;AACA,QAAM,EAAE,UAAU,KAAK,IAAI,cAAc;AACzC,QAAM,OAAO,UAAU;AAEvB,QAAM,IAAI;AAAA,IACR,CAAC,KAAkB,SAAmD;AACpE,YAAM,WAAW,OAAO,OAAO,KAAK,gBAAgB,GAAG,IAAI,KAAK,eAAe,GAAG,IAAI;AACtF,UAAI,OAAO,aAAa,YAAY,aAAa,GAAI,QAAO,YAAY,UAAU,IAAI;AAEtF,YAAM,QAAQ,OAAO,MAAM,GAAG;AAC9B,UAAI,aAAa,GAAG,GAAG;AACrB,eAAO,YAAY,UAAU,SAAS,QAAQ,GAAG,KAAK,gBAAgB,GAAG,IAAI,IAAI;AAAA,MACnF;AACA,aAAO,YAAY,SAAS,KAAK,IAAI;AAAA,IACvC;AAAA,IACA,CAAC,KAAK,gBAAgB,SAAS,SAAS,IAAI;AAAA,EAC9C;AACA,QAAM,UAAU,YAAY,CAAC,SAAsB,EAAE,mBAAmB,IAAc,IAAI,CAAC,CAAC;AAC5F,SAAO,QAAQ,OAAO,EAAE,GAAG,QAAQ,IAAI,CAAC,GAAG,OAAO,CAAC;AACrD;","names":[]}
@@ -0,0 +1,94 @@
1
+ "use client";
2
+ import {
3
+ Image
4
+ } from "./chunk-HSUUDZWS.js";
5
+ import {
6
+ useStrings
7
+ } from "./chunk-Q3XFD5UI.js";
8
+ import {
9
+ usePart
10
+ } from "./chunk-NNE4FYRT.js";
11
+
12
+ // src/shopper/CartLine.tsx
13
+ import { toDecimalString } from "@usethrottle/money";
14
+ import { Icon } from "@usethrottle/ui";
15
+ import { jsx, jsxs } from "react/jsx-runtime";
16
+ var decimal = (minor, currency) => Number(toDecimalString(minor, currency));
17
+ function lineToGa4Item(line, currency, quantity = line.quantity) {
18
+ return {
19
+ item_id: line.referenceId ?? line.id,
20
+ item_name: line.name,
21
+ price: decimal(line.unitPrice, currency),
22
+ quantity
23
+ };
24
+ }
25
+ function CartLine({ line, format, busy, onQuantity, onRemove, ...local }) {
26
+ const { t } = useStrings();
27
+ const root = usePart("cart-line", local);
28
+ const media = usePart("cart-line-media", local);
29
+ const body = usePart("cart-line-body", local);
30
+ const name = usePart("cart-line-name", local);
31
+ const price = usePart("cart-line-price", local);
32
+ const note = usePart("cart-line-note", local);
33
+ const quantity = usePart("cart-line-quantity", local);
34
+ const decrease = usePart("cart-line-decrease", local);
35
+ const count = usePart("cart-line-count", local);
36
+ const increase = usePart("cart-line-increase", local);
37
+ const total = usePart("cart-line-total", local);
38
+ const remove = usePart("cart-line-remove", local);
39
+ const max = line.resolution?.maxQuantity;
40
+ const atMax = typeof max === "number" && line.quantity >= max;
41
+ const refused = line.resolution?.status === "refused" || line.resolution?.status === "stale";
42
+ const noteText = refused ? typeof max === "number" && max > 0 ? t("shopper.cart.onlyLeft", { count: max }) : t("shopper.cart.unavailable") : null;
43
+ return /* @__PURE__ */ jsxs("li", { ...root, "data-line-id": line.id, "data-sku": line.referenceId ?? void 0, "data-busy": busy ? "" : void 0, children: [
44
+ line.imageUrl ? /* @__PURE__ */ jsx("div", { ...media, children: /* @__PURE__ */ jsx(Image, { src: line.imageUrl, alt: "", aspectRatio: 1, ...local }) }) : null,
45
+ /* @__PURE__ */ jsxs("div", { ...body, children: [
46
+ /* @__PURE__ */ jsx("p", { ...name, children: line.name }),
47
+ /* @__PURE__ */ jsx("p", { ...price, children: format(line.unitPrice) }),
48
+ noteText ? /* @__PURE__ */ jsx("p", { ...note, role: "status", children: noteText }) : null,
49
+ /* @__PURE__ */ jsxs("div", { ...quantity, role: "group", "aria-label": t("shopper.cart.quantity", { name: line.name }), children: [
50
+ /* @__PURE__ */ jsx(
51
+ "button",
52
+ {
53
+ type: "button",
54
+ ...decrease,
55
+ "aria-label": t("shopper.cart.decrease", { name: line.name }),
56
+ disabled: busy || line.quantity <= 1,
57
+ onClick: () => onQuantity(line.quantity - 1),
58
+ children: /* @__PURE__ */ jsx(Icon, { name: "minus", size: 16 })
59
+ }
60
+ ),
61
+ /* @__PURE__ */ jsx("span", { ...count, "data-quantity": line.quantity, children: line.quantity }),
62
+ /* @__PURE__ */ jsx(
63
+ "button",
64
+ {
65
+ type: "button",
66
+ ...increase,
67
+ "aria-label": t("shopper.cart.increase", { name: line.name }),
68
+ disabled: busy || atMax,
69
+ onClick: () => onQuantity(line.quantity + 1),
70
+ children: /* @__PURE__ */ jsx(Icon, { name: "plus", size: 16 })
71
+ }
72
+ )
73
+ ] })
74
+ ] }),
75
+ /* @__PURE__ */ jsx("p", { ...total, children: format(line.unitPrice * line.quantity) }),
76
+ /* @__PURE__ */ jsx(
77
+ "button",
78
+ {
79
+ type: "button",
80
+ ...remove,
81
+ "aria-label": t("shopper.cart.remove", { name: line.name }),
82
+ disabled: busy,
83
+ onClick: onRemove,
84
+ children: t("shopper.cart.removeText")
85
+ }
86
+ )
87
+ ] });
88
+ }
89
+
90
+ export {
91
+ lineToGa4Item,
92
+ CartLine
93
+ };
94
+ //# sourceMappingURL=chunk-QM7KTT7F.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shopper/CartLine.tsx"],"sourcesContent":["import type { ThrottleCart } from '@usethrottle/catalog';\nimport { toDecimalString } from '@usethrottle/money';\nimport { Icon } from '@usethrottle/ui';\nimport type { Ga4Item } from '../analytics/types';\nimport { usePart, type UsePartLocal } from '../parts';\nimport { Image } from '../pieces/Image';\nimport { useStrings } from '../strings';\n\n/** One line of the shared cart (`useCart().cart.lineItems`). */\nexport type CartLineData = NonNullable<ThrottleCart['lineItems']>[number];\n\nconst decimal = (minor: number, currency: string): number => Number(toDecimalString(minor, currency));\n\n/** A cart line as a GA4 item: the price is a decimal amount through `@usethrottle/money`. */\nexport function lineToGa4Item(line: CartLineData, currency: string, quantity: number = line.quantity): Ga4Item {\n return {\n item_id: line.referenceId ?? line.id,\n item_name: line.name,\n price: decimal(line.unitPrice, currency),\n quantity,\n };\n}\n\n/** One cart line and what it needs to change itself. */\nexport type CartLineProps = UsePartLocal & {\n /** The cart line to draw. */\n line: CartLineData;\n /** `useCart().format`: minor units in the cart's currency. */\n format(minor: number): string;\n /** A change is running: the buttons wait. */\n busy: boolean;\n /** Called with the new quantity when the stepper changes. */\n onQuantity(quantity: number): void;\n /** Called when the shopper removes the line. */\n onRemove(): void;\n};\n\n/** One line of the cart: the picture, the name, the price, a quantity stepper, the line total and Remove. */\nexport function CartLine({ line, format, busy, onQuantity, onRemove, ...local }: CartLineProps) {\n const { t } = useStrings();\n const root = usePart('cart-line', local);\n const media = usePart('cart-line-media', local);\n const body = usePart('cart-line-body', local);\n const name = usePart('cart-line-name', local);\n const price = usePart('cart-line-price', local);\n const note = usePart('cart-line-note', local);\n const quantity = usePart('cart-line-quantity', local);\n const decrease = usePart('cart-line-decrease', local);\n const count = usePart('cart-line-count', local);\n const increase = usePart('cart-line-increase', local);\n const total = usePart('cart-line-total', local);\n const remove = usePart('cart-line-remove', local);\n\n const max = line.resolution?.maxQuantity;\n const atMax = typeof max === 'number' && line.quantity >= max;\n const refused = line.resolution?.status === 'refused' || line.resolution?.status === 'stale';\n const noteText = refused\n ? typeof max === 'number' && max > 0\n ? t('shopper.cart.onlyLeft', { count: max })\n : t('shopper.cart.unavailable')\n : null;\n\n return (\n <li {...root} data-line-id={line.id} data-sku={line.referenceId ?? undefined} data-busy={busy ? '' : undefined}>\n {line.imageUrl ? (\n <div {...media}>\n <Image src={line.imageUrl} alt=\"\" aspectRatio={1} {...local} />\n </div>\n ) : null}\n <div {...body}>\n <p {...name}>{line.name}</p>\n <p {...price}>{format(line.unitPrice)}</p>\n {noteText ? (\n <p {...note} role=\"status\">{noteText}</p>\n ) : null}\n <div {...quantity} role=\"group\" aria-label={t('shopper.cart.quantity', { name: line.name })}>\n <button\n type=\"button\"\n {...decrease}\n aria-label={t('shopper.cart.decrease', { name: line.name })}\n disabled={busy || line.quantity <= 1}\n onClick={() => onQuantity(line.quantity - 1)}\n >\n <Icon name=\"minus\" size={16} />\n </button>\n <span {...count} data-quantity={line.quantity}>{line.quantity}</span>\n <button\n type=\"button\"\n {...increase}\n aria-label={t('shopper.cart.increase', { name: line.name })}\n disabled={busy || atMax}\n onClick={() => onQuantity(line.quantity + 1)}\n >\n <Icon name=\"plus\" size={16} />\n </button>\n </div>\n </div>\n <p {...total}>{format(line.unitPrice * line.quantity)}</p>\n <button\n type=\"button\"\n {...remove}\n aria-label={t('shopper.cart.remove', { name: line.name })}\n disabled={busy}\n onClick={onRemove}\n >\n {t('shopper.cart.removeText')}\n </button>\n </li>\n );\n}\n"],"mappings":";;;;;;;;;;;;AACA,SAAS,uBAAuB;AAChC,SAAS,YAAY;AAgEX,cASF,YATE;AAvDV,IAAM,UAAU,CAAC,OAAe,aAA6B,OAAO,gBAAgB,OAAO,QAAQ,CAAC;AAG7F,SAAS,cAAc,MAAoB,UAAkB,WAAmB,KAAK,UAAmB;AAC7G,SAAO;AAAA,IACL,SAAS,KAAK,eAAe,KAAK;AAAA,IAClC,WAAW,KAAK;AAAA,IAChB,OAAO,QAAQ,KAAK,WAAW,QAAQ;AAAA,IACvC;AAAA,EACF;AACF;AAiBO,SAAS,SAAS,EAAE,MAAM,QAAQ,MAAM,YAAY,UAAU,GAAG,MAAM,GAAkB;AAC9F,QAAM,EAAE,EAAE,IAAI,WAAW;AACzB,QAAM,OAAO,QAAQ,aAAa,KAAK;AACvC,QAAM,QAAQ,QAAQ,mBAAmB,KAAK;AAC9C,QAAM,OAAO,QAAQ,kBAAkB,KAAK;AAC5C,QAAM,OAAO,QAAQ,kBAAkB,KAAK;AAC5C,QAAM,QAAQ,QAAQ,mBAAmB,KAAK;AAC9C,QAAM,OAAO,QAAQ,kBAAkB,KAAK;AAC5C,QAAM,WAAW,QAAQ,sBAAsB,KAAK;AACpD,QAAM,WAAW,QAAQ,sBAAsB,KAAK;AACpD,QAAM,QAAQ,QAAQ,mBAAmB,KAAK;AAC9C,QAAM,WAAW,QAAQ,sBAAsB,KAAK;AACpD,QAAM,QAAQ,QAAQ,mBAAmB,KAAK;AAC9C,QAAM,SAAS,QAAQ,oBAAoB,KAAK;AAEhD,QA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AAE,yBAAyB,EAAE,MAAM,KAAK,KAAK,CAAC;AAAA,YAC1D,UAAU,QAAQ;AAAA,YAClB,SAAS,MAAM,WAAW,KAAK,WAAW,CAAC;AAAA,YAE3C,8BAAC,QAAK,MAAK,QAAO,MAAM,IAAI;AAAA;AAAA,QAC9B;AAAA,SACF;AAAA,OACF;AAAA,IACA,oBAAC,OAAG,GAAG,OAAQ,iBAAO,KAAK,YAAY,KAAK,QAAQ,GAAE;AAAA,IACtD;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACJ,GAAG;AAAA,QACJ,cAAY,EAAE,uBAAuB,EAAE,MAAM,KAAK,KAAK,CAAC;AAAA,QACxD,UAAU;AAAA,QACV,SAAS;AAAA,QAER,YAAE,yBAAyB;AAAA;AAAA,IAC9B;AAAA,KACF;AAEJ;","names":[]}
@@ -0,0 +1,70 @@
1
+ "use client";
2
+ import {
3
+ isVideo,
4
+ ratioOf
5
+ } from "./chunk-66HDJVPS.js";
6
+ import {
7
+ Image
8
+ } from "./chunk-HSUUDZWS.js";
9
+ import {
10
+ useStrings
11
+ } from "./chunk-Q3XFD5UI.js";
12
+ import {
13
+ usePart,
14
+ useStorefront
15
+ } from "./chunk-NNE4FYRT.js";
16
+
17
+ // src/product/Lightbox.tsx
18
+ import { Icon, Modal } from "@usethrottle/ui";
19
+ import { useEffect, useId } from "react";
20
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
21
+ function Lightbox({ open, items, index, title, onIndexChange, onClose, classNames, unstyled }) {
22
+ const local = { classNames, unstyled };
23
+ const { dir } = useStorefront();
24
+ const { t } = useStrings();
25
+ const titleId = useId();
26
+ const content = usePart("lightbox", local);
27
+ const heading = usePart("lightbox-title", local);
28
+ const stage = usePart("lightbox-stage", local);
29
+ const previous = usePart("lightbox-previous", local);
30
+ const next = usePart("lightbox-next", local);
31
+ const counter = usePart("lightbox-counter", local);
32
+ const count = items.length;
33
+ const item = items[index];
34
+ useEffect(() => {
35
+ if (!open) return;
36
+ const onKey = (e) => {
37
+ const forward = dir === "rtl" ? "ArrowLeft" : "ArrowRight";
38
+ const backward = dir === "rtl" ? "ArrowRight" : "ArrowLeft";
39
+ if (e.key === forward) onIndexChange((index + 1) % count);
40
+ else if (e.key === backward) onIndexChange((index - 1 + count) % count);
41
+ };
42
+ document.addEventListener("keydown", onKey);
43
+ return () => document.removeEventListener("keydown", onKey);
44
+ }, [open, dir, index, count, onIndexChange]);
45
+ if (!item) return null;
46
+ return /* @__PURE__ */ jsx(Modal, { open, onClose, labelledBy: titleId, closeLabel: t("product.gallery.close"), children: /* @__PURE__ */ jsxs("div", { ...content, children: [
47
+ /* @__PURE__ */ jsx("h2", { ...heading, id: titleId, children: t("product.gallery.lightboxTitle", { title }) }),
48
+ /* @__PURE__ */ jsx("div", { ...stage, children: isVideo(item) ? /* @__PURE__ */ jsx("video", { src: item.url, controls: true, playsInline: true, preload: "metadata", "aria-label": t("product.gallery.video", { title }) }) : /* @__PURE__ */ jsx(
49
+ Image,
50
+ {
51
+ ...local,
52
+ src: item.sizes?.["2048"] ?? item.url,
53
+ alt: item.altText ?? t("product.gallery.photoAlt", { title, n: index + 1 }),
54
+ aspectRatio: ratioOf(item),
55
+ priority: true
56
+ }
57
+ ) }),
58
+ count > 1 ? /* @__PURE__ */ jsxs(Fragment, { children: [
59
+ /* @__PURE__ */ jsx("button", { ...previous, type: "button", "aria-label": t("product.gallery.previous"), onClick: () => onIndexChange((index - 1 + count) % count), children: /* @__PURE__ */ jsx(Icon, { name: "chevron-left", size: 20 }) }),
60
+ /* @__PURE__ */ jsx("button", { ...next, type: "button", "aria-label": t("product.gallery.next"), onClick: () => onIndexChange((index + 1) % count), children: /* @__PURE__ */ jsx(Icon, { name: "chevron-right", size: 20 }) }),
61
+ /* @__PURE__ */ jsx("p", { ...counter, "aria-live": "polite", children: /* @__PURE__ */ jsx("bdi", { dir: "ltr", children: t("product.gallery.counter", { n: index + 1, count }) }) })
62
+ ] }) : null
63
+ ] }) });
64
+ }
65
+ var Lightbox_default = Lightbox;
66
+ export {
67
+ Lightbox,
68
+ Lightbox_default as default
69
+ };
70
+ //# sourceMappingURL=chunk-RLWZOLXL.js.map