@shopify/hydrogen-react 2022.7.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 (172) hide show
  1. package/README.md +218 -0
  2. package/dist/dev/ExternalVideo.cjs +39 -0
  3. package/dist/dev/ExternalVideo.cjs.map +1 -0
  4. package/dist/dev/ExternalVideo.js +39 -0
  5. package/dist/dev/ExternalVideo.js.map +1 -0
  6. package/dist/dev/Image.cjs +104 -0
  7. package/dist/dev/Image.cjs.map +1 -0
  8. package/dist/dev/Image.js +104 -0
  9. package/dist/dev/Image.js.map +1 -0
  10. package/dist/dev/MediaFile.cjs +57 -0
  11. package/dist/dev/MediaFile.cjs.map +1 -0
  12. package/dist/dev/MediaFile.js +57 -0
  13. package/dist/dev/MediaFile.js.map +1 -0
  14. package/dist/dev/Metafield.cjs +295 -0
  15. package/dist/dev/Metafield.cjs.map +1 -0
  16. package/dist/dev/Metafield.js +295 -0
  17. package/dist/dev/Metafield.js.map +1 -0
  18. package/dist/dev/ModelViewer.cjs +145 -0
  19. package/dist/dev/ModelViewer.cjs.map +1 -0
  20. package/dist/dev/ModelViewer.js +145 -0
  21. package/dist/dev/ModelViewer.js.map +1 -0
  22. package/dist/dev/Money.cjs +40 -0
  23. package/dist/dev/Money.cjs.map +1 -0
  24. package/dist/dev/Money.js +40 -0
  25. package/dist/dev/Money.js.map +1 -0
  26. package/dist/dev/ProductPrice.cjs +61 -0
  27. package/dist/dev/ProductPrice.cjs.map +1 -0
  28. package/dist/dev/ProductPrice.js +61 -0
  29. package/dist/dev/ProductPrice.js.map +1 -0
  30. package/dist/dev/ProductProvider.cjs +161 -0
  31. package/dist/dev/ProductProvider.cjs.map +1 -0
  32. package/dist/dev/ProductProvider.js +161 -0
  33. package/dist/dev/ProductProvider.js.map +1 -0
  34. package/dist/dev/ShopPayButton.cjs +64 -0
  35. package/dist/dev/ShopPayButton.cjs.map +1 -0
  36. package/dist/dev/ShopPayButton.js +64 -0
  37. package/dist/dev/ShopPayButton.js.map +1 -0
  38. package/dist/dev/ShopifyProvider.cjs +46 -0
  39. package/dist/dev/ShopifyProvider.cjs.map +1 -0
  40. package/dist/dev/ShopifyProvider.js +46 -0
  41. package/dist/dev/ShopifyProvider.js.map +1 -0
  42. package/dist/dev/Video.cjs +44 -0
  43. package/dist/dev/Video.cjs.map +1 -0
  44. package/dist/dev/Video.js +44 -0
  45. package/dist/dev/Video.js.map +1 -0
  46. package/dist/dev/flatten-connection.cjs +23 -0
  47. package/dist/dev/flatten-connection.cjs.map +1 -0
  48. package/dist/dev/flatten-connection.js +23 -0
  49. package/dist/dev/flatten-connection.js.map +1 -0
  50. package/dist/dev/image-size.cjs +80 -0
  51. package/dist/dev/image-size.cjs.map +1 -0
  52. package/dist/dev/image-size.js +80 -0
  53. package/dist/dev/image-size.js.map +1 -0
  54. package/dist/dev/index.cjs +35 -0
  55. package/dist/dev/index.cjs.map +1 -0
  56. package/dist/dev/index.js +35 -0
  57. package/dist/dev/index.js.map +1 -0
  58. package/dist/dev/load-script.cjs +52 -0
  59. package/dist/dev/load-script.cjs.map +1 -0
  60. package/dist/dev/load-script.js +52 -0
  61. package/dist/dev/load-script.js.map +1 -0
  62. package/dist/dev/storefront-api-constants.cjs +5 -0
  63. package/dist/dev/storefront-api-constants.cjs.map +1 -0
  64. package/dist/dev/storefront-api-constants.js +5 -0
  65. package/dist/dev/storefront-api-constants.js.map +1 -0
  66. package/dist/dev/storefront-client.cjs +72 -0
  67. package/dist/dev/storefront-client.cjs.map +1 -0
  68. package/dist/dev/storefront-client.js +72 -0
  69. package/dist/dev/storefront-client.js.map +1 -0
  70. package/dist/dev/useMoney.cjs +72 -0
  71. package/dist/dev/useMoney.cjs.map +1 -0
  72. package/dist/dev/useMoney.js +72 -0
  73. package/dist/dev/useMoney.js.map +1 -0
  74. package/dist/prod/ExternalVideo.cjs +39 -0
  75. package/dist/prod/ExternalVideo.cjs.map +1 -0
  76. package/dist/prod/ExternalVideo.js +39 -0
  77. package/dist/prod/ExternalVideo.js.map +1 -0
  78. package/dist/prod/Image.cjs +99 -0
  79. package/dist/prod/Image.cjs.map +1 -0
  80. package/dist/prod/Image.js +99 -0
  81. package/dist/prod/Image.js.map +1 -0
  82. package/dist/prod/MediaFile.cjs +59 -0
  83. package/dist/prod/MediaFile.cjs.map +1 -0
  84. package/dist/prod/MediaFile.js +59 -0
  85. package/dist/prod/MediaFile.js.map +1 -0
  86. package/dist/prod/Metafield.cjs +288 -0
  87. package/dist/prod/Metafield.cjs.map +1 -0
  88. package/dist/prod/Metafield.js +288 -0
  89. package/dist/prod/Metafield.js.map +1 -0
  90. package/dist/prod/ModelViewer.cjs +143 -0
  91. package/dist/prod/ModelViewer.cjs.map +1 -0
  92. package/dist/prod/ModelViewer.js +143 -0
  93. package/dist/prod/ModelViewer.js.map +1 -0
  94. package/dist/prod/Money.cjs +40 -0
  95. package/dist/prod/Money.cjs.map +1 -0
  96. package/dist/prod/Money.js +40 -0
  97. package/dist/prod/Money.js.map +1 -0
  98. package/dist/prod/ProductPrice.cjs +61 -0
  99. package/dist/prod/ProductPrice.cjs.map +1 -0
  100. package/dist/prod/ProductPrice.js +61 -0
  101. package/dist/prod/ProductPrice.js.map +1 -0
  102. package/dist/prod/ProductProvider.cjs +161 -0
  103. package/dist/prod/ProductProvider.cjs.map +1 -0
  104. package/dist/prod/ProductProvider.js +161 -0
  105. package/dist/prod/ProductProvider.js.map +1 -0
  106. package/dist/prod/ShopPayButton.cjs +64 -0
  107. package/dist/prod/ShopPayButton.cjs.map +1 -0
  108. package/dist/prod/ShopPayButton.js +64 -0
  109. package/dist/prod/ShopPayButton.js.map +1 -0
  110. package/dist/prod/ShopifyProvider.cjs +46 -0
  111. package/dist/prod/ShopifyProvider.cjs.map +1 -0
  112. package/dist/prod/ShopifyProvider.js +46 -0
  113. package/dist/prod/ShopifyProvider.js.map +1 -0
  114. package/dist/prod/Video.cjs +44 -0
  115. package/dist/prod/Video.cjs.map +1 -0
  116. package/dist/prod/Video.js +44 -0
  117. package/dist/prod/Video.js.map +1 -0
  118. package/dist/prod/flatten-connection.cjs +18 -0
  119. package/dist/prod/flatten-connection.cjs.map +1 -0
  120. package/dist/prod/flatten-connection.js +18 -0
  121. package/dist/prod/flatten-connection.js.map +1 -0
  122. package/dist/prod/image-size.cjs +80 -0
  123. package/dist/prod/image-size.cjs.map +1 -0
  124. package/dist/prod/image-size.js +80 -0
  125. package/dist/prod/image-size.js.map +1 -0
  126. package/dist/prod/index.cjs +35 -0
  127. package/dist/prod/index.cjs.map +1 -0
  128. package/dist/prod/index.js +35 -0
  129. package/dist/prod/index.js.map +1 -0
  130. package/dist/prod/load-script.cjs +52 -0
  131. package/dist/prod/load-script.cjs.map +1 -0
  132. package/dist/prod/load-script.js +52 -0
  133. package/dist/prod/load-script.js.map +1 -0
  134. package/dist/prod/storefront-api-constants.cjs +5 -0
  135. package/dist/prod/storefront-api-constants.cjs.map +1 -0
  136. package/dist/prod/storefront-api-constants.js +5 -0
  137. package/dist/prod/storefront-api-constants.js.map +1 -0
  138. package/dist/prod/storefront-client.cjs +57 -0
  139. package/dist/prod/storefront-client.cjs.map +1 -0
  140. package/dist/prod/storefront-client.js +57 -0
  141. package/dist/prod/storefront-client.js.map +1 -0
  142. package/dist/prod/useMoney.cjs +72 -0
  143. package/dist/prod/useMoney.cjs.map +1 -0
  144. package/dist/prod/useMoney.js +72 -0
  145. package/dist/prod/useMoney.js.map +1 -0
  146. package/dist/types/ExternalVideo.d.ts +67 -0
  147. package/dist/types/Image.d.ts +54 -0
  148. package/dist/types/MediaFile.d.ts +31 -0
  149. package/dist/types/Metafield.d.ts +58 -0
  150. package/dist/types/ModelViewer.d.ts +57 -0
  151. package/dist/types/Money.d.ts +29 -0
  152. package/dist/types/ProductPrice.d.ts +22 -0
  153. package/dist/types/ProductProvider.d.ts +74 -0
  154. package/dist/types/ShopPayButton.d.ts +42 -0
  155. package/dist/types/ShopifyProvider.d.ts +42 -0
  156. package/dist/types/Video.d.ts +20 -0
  157. package/dist/types/flatten-connection.d.ts +17 -0
  158. package/dist/types/image-size.d.ts +36 -0
  159. package/dist/types/index.d.cts +15 -0
  160. package/dist/types/index.d.ts +15 -0
  161. package/dist/types/load-script.d.ts +11 -0
  162. package/dist/types/storefront-api-constants.d.ts +1 -0
  163. package/dist/types/storefront-api-response.types.d.ts +68 -0
  164. package/dist/types/storefront-api-types.d.ts +6537 -0
  165. package/dist/types/storefront-client.d.ts +63 -0
  166. package/dist/types/useMoney.d.ts +55 -0
  167. package/dist/umd/hydrogen-react.dev.js +1472 -0
  168. package/dist/umd/hydrogen-react.dev.js.map +1 -0
  169. package/dist/umd/hydrogen-react.prod.js +3 -0
  170. package/dist/umd/hydrogen-react.prod.js.map +1 -0
  171. package/package.json +106 -0
  172. package/storefront.schema.json +1 -0
@@ -0,0 +1,1472 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react")) : typeof define === "function" && define.amd ? define(["exports", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.hydrogenreact = {}, global.React));
3
+ })(this, function(exports2, React) {
4
+ "use strict";
5
+ const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
6
+ function _interopNamespace(e) {
7
+ if (e && e.__esModule)
8
+ return e;
9
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
10
+ if (e) {
11
+ for (const k in e) {
12
+ if (k !== "default") {
13
+ const d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: () => e[k]
17
+ });
18
+ }
19
+ }
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
24
+ const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
25
+ const React__namespace = /* @__PURE__ */ _interopNamespace(React);
26
+ var _jsxFileName$a = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ExternalVideo.tsx";
27
+ function ExternalVideo(props) {
28
+ var _a, _b;
29
+ const {
30
+ data,
31
+ options,
32
+ id = data.id,
33
+ frameBorder = "0",
34
+ allow = "accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture",
35
+ allowFullScreen = true,
36
+ loading = "lazy",
37
+ ...passthroughProps
38
+ } = props;
39
+ if (!data.embedUrl) {
40
+ throw new Error(`<ExternalVideo/> requires the 'embedUrl' property`);
41
+ }
42
+ let finalUrl = data.embedUrl;
43
+ if (options) {
44
+ const urlObject = new URL(data.embedUrl);
45
+ for (const key of Object.keys(options)) {
46
+ urlObject.searchParams.set(key, options[key]);
47
+ }
48
+ finalUrl = urlObject.toString();
49
+ }
50
+ return /* @__PURE__ */ React__default.default.createElement("iframe", {
51
+ ...passthroughProps,
52
+ id: id != null ? id : data.embedUrl,
53
+ title: (_b = (_a = data.alt) != null ? _a : data.id) != null ? _b : "external video",
54
+ frameBorder,
55
+ allow,
56
+ allowFullScreen,
57
+ src: finalUrl,
58
+ loading,
59
+ __self: this,
60
+ __source: {
61
+ fileName: _jsxFileName$a,
62
+ lineNumber: 56,
63
+ columnNumber: 5
64
+ }
65
+ });
66
+ }
67
+ function flattenConnection(connection) {
68
+ if (connection.nodes) {
69
+ return connection.nodes;
70
+ }
71
+ if (connection.edges) {
72
+ return connection.edges.map((edge) => {
73
+ if (!(edge == null ? void 0 : edge.node)) {
74
+ throw new Error("Connection edges must contain nodes");
75
+ }
76
+ return edge.node;
77
+ });
78
+ }
79
+ {
80
+ console.warn(
81
+ `The connection did not contain either "nodes" or "edges.node". A empty array will be returned in its place.`
82
+ );
83
+ }
84
+ return [];
85
+ }
86
+ const PRODUCTION_CDN_HOSTNAMES = [
87
+ "cdn.shopify.com",
88
+ "cdn.shopifycdn.net",
89
+ "shopify-assets.shopifycdn.com",
90
+ "shopify-assets.shopifycdn.net"
91
+ ];
92
+ const LOCAL_CDN_HOSTNAMES = ["spin.dev"];
93
+ const ALL_CDN_HOSTNAMES = [...PRODUCTION_CDN_HOSTNAMES, ...LOCAL_CDN_HOSTNAMES];
94
+ const IMG_SRC_SET_SIZES = [352, 832, 1200, 1920, 2560];
95
+ function addImageSizeParametersToUrl({
96
+ src,
97
+ width,
98
+ height,
99
+ crop,
100
+ scale
101
+ }) {
102
+ const newUrl = new URL(src);
103
+ const multipliedScale = scale != null ? scale : 1;
104
+ if (width) {
105
+ let finalWidth;
106
+ if (typeof width === "string") {
107
+ finalWidth = (IMG_SRC_SET_SIZES[0] * multipliedScale).toString();
108
+ } else {
109
+ finalWidth = (Number(width) * multipliedScale).toString();
110
+ }
111
+ newUrl.searchParams.append("width", finalWidth);
112
+ }
113
+ if (height && typeof height === "number") {
114
+ newUrl.searchParams.append("height", (height * multipliedScale).toString());
115
+ }
116
+ crop && newUrl.searchParams.append("crop", crop);
117
+ return newUrl.toString();
118
+ }
119
+ function shopifyImageLoader(params) {
120
+ const newSrc = new URL(params.src);
121
+ const isShopifyServedImage = ALL_CDN_HOSTNAMES.some(
122
+ (allowedHostname) => newSrc.hostname.endsWith(allowedHostname)
123
+ );
124
+ if (!isShopifyServedImage || !params.width && !params.height && !params.crop && !params.scale) {
125
+ return params.src;
126
+ }
127
+ return addImageSizeParametersToUrl(params);
128
+ }
129
+ function getShopifyImageDimensions({
130
+ data: sfapiImage,
131
+ loaderOptions,
132
+ elementProps
133
+ }) {
134
+ var _a, _b, _c, _d, _e, _f;
135
+ let aspectRatio = null;
136
+ if ((sfapiImage == null ? void 0 : sfapiImage.width) && (sfapiImage == null ? void 0 : sfapiImage.height)) {
137
+ aspectRatio = (sfapiImage == null ? void 0 : sfapiImage.width) / (sfapiImage == null ? void 0 : sfapiImage.height);
138
+ }
139
+ if ((loaderOptions == null ? void 0 : loaderOptions.width) || (loaderOptions == null ? void 0 : loaderOptions.height)) {
140
+ return {
141
+ width: (_a = loaderOptions == null ? void 0 : loaderOptions.width) != null ? _a : aspectRatio && typeof loaderOptions.height === "number" ? Math.round(aspectRatio * loaderOptions.height) : null,
142
+ height: (_b = loaderOptions == null ? void 0 : loaderOptions.height) != null ? _b : aspectRatio && typeof loaderOptions.width === "number" ? Math.round(aspectRatio * loaderOptions.width) : null
143
+ };
144
+ }
145
+ if ((elementProps == null ? void 0 : elementProps.width) || (elementProps == null ? void 0 : elementProps.height)) {
146
+ return {
147
+ width: (_c = elementProps == null ? void 0 : elementProps.width) != null ? _c : aspectRatio && typeof elementProps.height === "number" ? Math.round(aspectRatio * elementProps.height) : null,
148
+ height: (_d = elementProps == null ? void 0 : elementProps.height) != null ? _d : aspectRatio && typeof elementProps.width === "number" ? Math.round(aspectRatio * elementProps.width) : null
149
+ };
150
+ }
151
+ if ((sfapiImage == null ? void 0 : sfapiImage.width) || (sfapiImage == null ? void 0 : sfapiImage.height)) {
152
+ return {
153
+ width: (_e = sfapiImage == null ? void 0 : sfapiImage.width) != null ? _e : null,
154
+ height: (_f = sfapiImage == null ? void 0 : sfapiImage.height) != null ? _f : null
155
+ };
156
+ }
157
+ return { width: null, height: null };
158
+ }
159
+ var _jsxFileName$9 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Image.tsx";
160
+ function Image({
161
+ data,
162
+ width,
163
+ height,
164
+ loading,
165
+ loader = shopifyImageLoader,
166
+ loaderOptions,
167
+ widths,
168
+ decoding = "async",
169
+ ...rest
170
+ }) {
171
+ var _a, _b, _c, _d, _e, _f, _g, _h;
172
+ if (!data.url) {
173
+ const missingUrlError = `<Image/>: the 'data' prop requires the 'url' property. Image: ${(_a = data.id) != null ? _a : "no ID provided"}`;
174
+ {
175
+ throw new Error(missingUrlError);
176
+ }
177
+ }
178
+ if (!data.altText && !rest.alt) {
179
+ console.warn(`<Image/>: the 'data' prop should have the 'altText' property, or the 'alt' prop, and one of them should not be empty. Image: ${(_b = data.id) != null ? _b : data.url}`);
180
+ }
181
+ const {
182
+ width: imgElementWidth,
183
+ height: imgElementHeight
184
+ } = getShopifyImageDimensions({
185
+ data,
186
+ loaderOptions,
187
+ elementProps: {
188
+ width,
189
+ height
190
+ }
191
+ });
192
+ if (!imgElementWidth || !imgElementHeight) {
193
+ console.warn(`<Image/>: the 'data' prop requires either 'width' or 'data.width', and 'height' or 'data.height' properties. Image: ${(_c = data.id) != null ? _c : data.url}`);
194
+ }
195
+ let finalSrc = data.url;
196
+ if (loader) {
197
+ finalSrc = loader({
198
+ ...loaderOptions,
199
+ src: data.url,
200
+ width: imgElementWidth,
201
+ height: imgElementHeight
202
+ });
203
+ if (typeof finalSrc !== "string" || !finalSrc) {
204
+ throw new Error(`<Image/>: 'loader' did not return a valid string. Image: ${(_d = data.id) != null ? _d : data.url}`);
205
+ }
206
+ }
207
+ const maxWidth = width && imgElementWidth && width < imgElementWidth ? width : imgElementWidth;
208
+ const finalSrcset = (_e = rest.srcSet) != null ? _e : internalImageSrcSet({
209
+ ...loaderOptions,
210
+ widths,
211
+ src: data.url,
212
+ width: maxWidth,
213
+ height: imgElementHeight,
214
+ loader
215
+ });
216
+ return /* @__PURE__ */ React__namespace.createElement("img", {
217
+ id: (_f = data.id) != null ? _f : "",
218
+ alt: (_h = (_g = data.altText) != null ? _g : rest.alt) != null ? _h : "",
219
+ loading: loading != null ? loading : "lazy",
220
+ ...rest,
221
+ src: finalSrc,
222
+ width: imgElementWidth != null ? imgElementWidth : void 0,
223
+ height: imgElementHeight != null ? imgElementHeight : void 0,
224
+ srcSet: finalSrcset,
225
+ decoding,
226
+ __self: this,
227
+ __source: {
228
+ fileName: _jsxFileName$9,
229
+ lineNumber: 150,
230
+ columnNumber: 5
231
+ }
232
+ });
233
+ }
234
+ function internalImageSrcSet({
235
+ src,
236
+ width,
237
+ crop,
238
+ scale,
239
+ widths,
240
+ loader,
241
+ height
242
+ }) {
243
+ const hasCustomWidths = widths && Array.isArray(widths);
244
+ if (hasCustomWidths && widths.some((size) => isNaN(size))) {
245
+ throw new Error(`<Image/>: the 'widths' must be an array of numbers. Image: ${src}`);
246
+ }
247
+ let aspectRatio = 1;
248
+ if (width && height) {
249
+ aspectRatio = Number(height) / Number(width);
250
+ }
251
+ let setSizes = hasCustomWidths ? widths : IMG_SRC_SET_SIZES;
252
+ if (!hasCustomWidths && width && width < IMG_SRC_SET_SIZES[IMG_SRC_SET_SIZES.length - 1]) {
253
+ setSizes = IMG_SRC_SET_SIZES.filter((size) => size <= width);
254
+ }
255
+ const srcGenerator = loader ? loader : addImageSizeParametersToUrl;
256
+ return setSizes.map((size) => `${srcGenerator({
257
+ src,
258
+ width: size,
259
+ height: crop ? Number(size) * aspectRatio : void 0,
260
+ crop,
261
+ scale
262
+ })} ${size}w`).join(", ");
263
+ }
264
+ var _jsxFileName$8 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Video.tsx";
265
+ function Video(props) {
266
+ var _a, _b;
267
+ const {
268
+ data,
269
+ previewImageOptions,
270
+ id = data.id,
271
+ playsInline = true,
272
+ controls = true,
273
+ sourceProps = {},
274
+ ...passthroughProps
275
+ } = props;
276
+ const posterUrl = shopifyImageLoader({
277
+ src: (_b = (_a = data.previewImage) == null ? void 0 : _a.url) != null ? _b : "",
278
+ ...previewImageOptions
279
+ });
280
+ if (!data.sources) {
281
+ throw new Error(`<Video/> requires a 'data.sources' array`);
282
+ }
283
+ return /* @__PURE__ */ React__default.default.createElement("video", {
284
+ ...passthroughProps,
285
+ id,
286
+ playsInline,
287
+ controls,
288
+ poster: posterUrl,
289
+ __self: this,
290
+ __source: {
291
+ fileName: _jsxFileName$8,
292
+ lineNumber: 42,
293
+ columnNumber: 5
294
+ }
295
+ }, data.sources.map((source) => {
296
+ if (!((source == null ? void 0 : source.url) && (source == null ? void 0 : source.mimeType))) {
297
+ throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);
298
+ }
299
+ return /* @__PURE__ */ React__default.default.createElement("source", {
300
+ ...sourceProps,
301
+ key: source.url,
302
+ src: source.url,
303
+ type: source.mimeType,
304
+ __self: this,
305
+ __source: {
306
+ fileName: _jsxFileName$8,
307
+ lineNumber: 54,
308
+ columnNumber: 11
309
+ }
310
+ });
311
+ }));
312
+ }
313
+ const SCRIPTS_LOADED = {};
314
+ function loadScript(src, options) {
315
+ const isScriptLoaded = SCRIPTS_LOADED[src];
316
+ if (isScriptLoaded) {
317
+ return isScriptLoaded;
318
+ }
319
+ const promise = new Promise((resolve, reject) => {
320
+ const script = document.createElement("script");
321
+ if (options == null ? void 0 : options.module) {
322
+ script.type = "module";
323
+ } else {
324
+ script.type = "text/javascript";
325
+ }
326
+ script.src = src;
327
+ script.onload = () => {
328
+ resolve(true);
329
+ };
330
+ script.onerror = () => {
331
+ reject(false);
332
+ };
333
+ if ((options == null ? void 0 : options.in) === "head") {
334
+ document.head.appendChild(script);
335
+ } else {
336
+ document.body.appendChild(script);
337
+ }
338
+ });
339
+ SCRIPTS_LOADED[src] = promise;
340
+ return promise;
341
+ }
342
+ function useLoadScript(url, options) {
343
+ const [status, setStatus] = React.useState("loading");
344
+ const stringifiedOptions = JSON.stringify(options);
345
+ React.useEffect(() => {
346
+ async function loadScriptWrapper() {
347
+ try {
348
+ setStatus("loading");
349
+ await loadScript(url, options);
350
+ setStatus("done");
351
+ } catch (error) {
352
+ setStatus("error");
353
+ }
354
+ }
355
+ loadScriptWrapper();
356
+ }, [url, stringifiedOptions, options]);
357
+ return status;
358
+ }
359
+ var _jsxFileName$7 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ModelViewer.tsx";
360
+ function ModelViewer(props) {
361
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
362
+ const [modelViewer, setModelViewer] = React.useState(void 0);
363
+ const callbackRef = React.useCallback((node) => {
364
+ setModelViewer(node);
365
+ }, []);
366
+ const {
367
+ data,
368
+ children,
369
+ className,
370
+ ...passthroughProps
371
+ } = props;
372
+ const modelViewerLoadedStatus = useLoadScript("https://unpkg.com/@google/model-viewer@v1.12.1/dist/model-viewer.min.js", {
373
+ module: true
374
+ });
375
+ React.useEffect(() => {
376
+ if (!modelViewer) {
377
+ return;
378
+ }
379
+ if (passthroughProps.onError)
380
+ modelViewer.addEventListener("error", passthroughProps.onError);
381
+ if (passthroughProps.onLoad)
382
+ modelViewer.addEventListener("load", passthroughProps.onLoad);
383
+ if (passthroughProps.onPreload)
384
+ modelViewer.addEventListener("preload", passthroughProps.onPreload);
385
+ if (passthroughProps.onModelVisibility)
386
+ modelViewer.addEventListener("model-visibility", passthroughProps.onModelVisibility);
387
+ if (passthroughProps.onProgress)
388
+ modelViewer.addEventListener("progress", passthroughProps.onProgress);
389
+ if (passthroughProps.onArStatus)
390
+ modelViewer.addEventListener("ar-status", passthroughProps.onArStatus);
391
+ if (passthroughProps.onArTracking)
392
+ modelViewer.addEventListener("ar-tracking", passthroughProps.onArTracking);
393
+ if (passthroughProps.onQuickLookButtonTapped)
394
+ modelViewer.addEventListener("quick-look-button-tapped", passthroughProps.onQuickLookButtonTapped);
395
+ if (passthroughProps.onCameraChange)
396
+ modelViewer.addEventListener("camera-change", passthroughProps.onCameraChange);
397
+ if (passthroughProps.onEnvironmentChange)
398
+ modelViewer.addEventListener("environment-change", passthroughProps.onEnvironmentChange);
399
+ if (passthroughProps.onPlay)
400
+ modelViewer.addEventListener("play", passthroughProps.onPlay);
401
+ if (passthroughProps.onPause)
402
+ modelViewer.addEventListener("ar-status", passthroughProps.onPause);
403
+ if (passthroughProps.onSceneGraphReady)
404
+ modelViewer.addEventListener("scene-graph-ready", passthroughProps.onSceneGraphReady);
405
+ return () => {
406
+ if (modelViewer == null) {
407
+ return;
408
+ }
409
+ if (passthroughProps.onError)
410
+ modelViewer.removeEventListener("error", passthroughProps.onError);
411
+ if (passthroughProps.onLoad)
412
+ modelViewer.removeEventListener("load", passthroughProps.onLoad);
413
+ if (passthroughProps.onPreload)
414
+ modelViewer.removeEventListener("preload", passthroughProps.onPreload);
415
+ if (passthroughProps.onModelVisibility)
416
+ modelViewer.removeEventListener("model-visibility", passthroughProps.onModelVisibility);
417
+ if (passthroughProps.onProgress)
418
+ modelViewer.removeEventListener("progress", passthroughProps.onProgress);
419
+ if (passthroughProps.onArStatus)
420
+ modelViewer.removeEventListener("ar-status", passthroughProps.onArStatus);
421
+ if (passthroughProps.onArTracking)
422
+ modelViewer.removeEventListener("ar-tracking", passthroughProps.onArTracking);
423
+ if (passthroughProps.onQuickLookButtonTapped)
424
+ modelViewer.removeEventListener("quick-look-button-tapped", passthroughProps.onQuickLookButtonTapped);
425
+ if (passthroughProps.onCameraChange)
426
+ modelViewer.removeEventListener("camera-change", passthroughProps.onCameraChange);
427
+ if (passthroughProps.onEnvironmentChange)
428
+ modelViewer.removeEventListener("environment-change", passthroughProps.onEnvironmentChange);
429
+ if (passthroughProps.onPlay)
430
+ modelViewer.removeEventListener("play", passthroughProps.onPlay);
431
+ if (passthroughProps.onPause)
432
+ modelViewer.removeEventListener("ar-status", passthroughProps.onPause);
433
+ if (passthroughProps.onSceneGraphReady)
434
+ modelViewer.removeEventListener("scene-graph-ready", passthroughProps.onSceneGraphReady);
435
+ };
436
+ }, [modelViewer, passthroughProps.onArStatus, passthroughProps.onArTracking, passthroughProps.onCameraChange, passthroughProps.onEnvironmentChange, passthroughProps.onError, passthroughProps.onLoad, passthroughProps.onModelVisibility, passthroughProps.onPause, passthroughProps.onPlay, passthroughProps.onPreload, passthroughProps.onProgress, passthroughProps.onQuickLookButtonTapped, passthroughProps.onSceneGraphReady]);
437
+ if (modelViewerLoadedStatus !== "done") {
438
+ return null;
439
+ }
440
+ if (!((_b = (_a = data.sources) == null ? void 0 : _a[0]) == null ? void 0 : _b.url)) {
441
+ const sourcesUrlError = `<ModelViewer/> requires 'data.sources' prop to be an array, with an object that has a property 'url' on it. Rendering 'null'`;
442
+ {
443
+ throw new Error(sourcesUrlError);
444
+ }
445
+ }
446
+ if (!data.alt) {
447
+ console.warn(`<ModelViewer/> requires the 'data.alt' prop for accessibility`);
448
+ }
449
+ return /* @__PURE__ */ React__default.default.createElement("model-viewer", {
450
+ ref: callbackRef,
451
+ ...passthroughProps,
452
+ className,
453
+ id: (_c = passthroughProps.id) != null ? _c : data.id,
454
+ src: data.sources[0].url,
455
+ alt: (_d = data.alt) != null ? _d : null,
456
+ "camera-controls": (_e = passthroughProps.cameraControls) != null ? _e : true,
457
+ poster: (_g = passthroughProps.poster || ((_f = data.previewImage) == null ? void 0 : _f.url)) != null ? _g : null,
458
+ autoplay: (_h = passthroughProps.autoplay) != null ? _h : true,
459
+ loading: passthroughProps.loading,
460
+ reveal: passthroughProps.reveal,
461
+ ar: passthroughProps.ar,
462
+ "ar-modes": passthroughProps.arModes,
463
+ "ar-scale": passthroughProps.arScale,
464
+ "ar-placement": passthroughProps.arPlacement,
465
+ "ios-src": passthroughProps.iosSrc,
466
+ "touch-action": passthroughProps.touchAction,
467
+ "disable-zoom": passthroughProps.disableZoom,
468
+ "orbit-sensitivity": passthroughProps.orbitSensitivity,
469
+ "auto-rotate": passthroughProps.autoRotate,
470
+ "auto-rotate-delay": passthroughProps.autoRotateDelay,
471
+ "rotation-per-second": passthroughProps.rotationPerSecond,
472
+ "interaction-policy": passthroughProps.interactionPolicy,
473
+ "interaction-prompt": passthroughProps.interactionPrompt,
474
+ "interaction-prompt-style": passthroughProps.interactionPromptStyle,
475
+ "interaction-prompt-threshold": passthroughProps.interactionPromptThreshold,
476
+ "camera-orbit": passthroughProps.cameraOrbit,
477
+ "camera-target": passthroughProps.cameraTarget,
478
+ "field-of-view": passthroughProps.fieldOfView,
479
+ "max-camera-orbit": passthroughProps.maxCameraOrbit,
480
+ "min-camera-orbit": passthroughProps.minCameraOrbit,
481
+ "max-field-of-view": passthroughProps.maxFieldOfView,
482
+ "min-field-of-view": passthroughProps.minFieldOfView,
483
+ bounds: passthroughProps.bounds,
484
+ "interpolation-decay": (_i = passthroughProps.interpolationDecay) != null ? _i : 100,
485
+ "skybox-image": passthroughProps.skyboxImage,
486
+ "environment-image": passthroughProps.environmentImage,
487
+ exposure: passthroughProps.exposure,
488
+ "shadow-intensity": (_j = passthroughProps.shadowIntensity) != null ? _j : 0,
489
+ "shadow-softness": (_k = passthroughProps.shadowSoftness) != null ? _k : 0,
490
+ "animation-name": passthroughProps.animationName,
491
+ "animation-crossfade-duration": passthroughProps.animationCrossfadeDuration,
492
+ "variant-name": passthroughProps.variantName,
493
+ orientation: passthroughProps.orientation,
494
+ scale: passthroughProps.scale,
495
+ __self: this,
496
+ __source: {
497
+ fileName: _jsxFileName$7,
498
+ lineNumber: 222,
499
+ columnNumber: 5
500
+ }
501
+ }, children);
502
+ }
503
+ var _jsxFileName$6 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/MediaFile.tsx";
504
+ function MediaFile({
505
+ data,
506
+ mediaOptions,
507
+ ...passthroughProps
508
+ }) {
509
+ switch (data.__typename) {
510
+ case "MediaImage": {
511
+ if (!data.image) {
512
+ const noDataImage = `<MediaFile/>: 'data.image' does not exist for __typename of 'MediaImage'; rendering 'null' by default.`;
513
+ {
514
+ throw new Error(noDataImage);
515
+ }
516
+ }
517
+ return /* @__PURE__ */ React__default.default.createElement(Image, {
518
+ ...passthroughProps,
519
+ ...mediaOptions == null ? void 0 : mediaOptions.image,
520
+ data: data.image,
521
+ __self: this,
522
+ __source: {
523
+ fileName: _jsxFileName$6,
524
+ lineNumber: 51,
525
+ columnNumber: 9
526
+ }
527
+ });
528
+ }
529
+ case "Video": {
530
+ return /* @__PURE__ */ React__default.default.createElement(Video, {
531
+ ...passthroughProps,
532
+ ...mediaOptions == null ? void 0 : mediaOptions.video,
533
+ data,
534
+ __self: this,
535
+ __source: {
536
+ fileName: _jsxFileName$6,
537
+ lineNumber: 60,
538
+ columnNumber: 9
539
+ }
540
+ });
541
+ }
542
+ case "ExternalVideo": {
543
+ return /* @__PURE__ */ React__default.default.createElement(ExternalVideo, {
544
+ ...passthroughProps,
545
+ ...mediaOptions == null ? void 0 : mediaOptions.externalVideo,
546
+ data,
547
+ __self: this,
548
+ __source: {
549
+ fileName: _jsxFileName$6,
550
+ lineNumber: 65,
551
+ columnNumber: 9
552
+ }
553
+ });
554
+ }
555
+ case "Model3d": {
556
+ return /* @__PURE__ */ React__default.default.createElement(ModelViewer, {
557
+ ...passthroughProps,
558
+ ...mediaOptions == null ? void 0 : mediaOptions.modelViewer,
559
+ data,
560
+ __self: this,
561
+ __source: {
562
+ fileName: _jsxFileName$6,
563
+ lineNumber: 74,
564
+ columnNumber: 9
565
+ }
566
+ });
567
+ }
568
+ default: {
569
+ const typenameMissingMessage = `<MediaFile /> requires the '__typename' property to exist on the 'data' prop in order to correctly render the correct component for this media. Rendering 'null' by default`;
570
+ {
571
+ throw new Error(typenameMissingMessage);
572
+ }
573
+ }
574
+ }
575
+ }
576
+ const SFAPI_VERSION = "2022-07";
577
+ var _jsxFileName$5 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopifyProvider.tsx";
578
+ const ShopifyContext = React.createContext({
579
+ storeDomain: "test.myshopify.com",
580
+ storefrontToken: "abc123",
581
+ storefrontApiVersion: SFAPI_VERSION,
582
+ country: {
583
+ isoCode: "US"
584
+ },
585
+ language: {
586
+ isoCode: "EN"
587
+ },
588
+ locale: "EN-US"
589
+ });
590
+ function ShopifyProvider({
591
+ children,
592
+ shopifyConfig
593
+ }) {
594
+ if (!shopifyConfig) {
595
+ throw new Error(`The 'shopifyConfig' prop must be passed to '<ShopifyProvider/>'`);
596
+ }
597
+ if (shopifyConfig.storefrontApiVersion !== SFAPI_VERSION) {
598
+ console.warn(`This version of Hydrogen-UI is built for Shopify's Storefront API version ${SFAPI_VERSION}, but it looks like you're using version ${shopifyConfig.storefrontApiVersion}. There may be issues or bugs if you use a mismatched version of Hydrogen-UI and the Storefront API.`);
599
+ }
600
+ const finalConfig = React.useMemo(() => ({
601
+ ...shopifyConfig,
602
+ storeDomain: shopifyConfig.storeDomain.replace(/^https?:\/\//, "")
603
+ }), [shopifyConfig]);
604
+ return /* @__PURE__ */ React__default.default.createElement(ShopifyContext.Provider, {
605
+ value: finalConfig,
606
+ __self: this,
607
+ __source: {
608
+ fileName: _jsxFileName$5,
609
+ lineNumber: 49,
610
+ columnNumber: 5
611
+ }
612
+ }, children);
613
+ }
614
+ function useShop() {
615
+ const shopContext = React.useContext(ShopifyContext);
616
+ if (!shopContext) {
617
+ throw new Error(`'useShop()' must be a descendent of <ShopifyProvider/>`);
618
+ }
619
+ return shopContext;
620
+ }
621
+ var _jsxFileName$4 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Metafield.tsx";
622
+ function Metafield(props) {
623
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
624
+ const {
625
+ data,
626
+ as,
627
+ ...passthroughProps
628
+ } = props;
629
+ const {
630
+ locale
631
+ } = useShop();
632
+ const parsedMetafield = React.useMemo(() => parseMetafield(data), [data]);
633
+ if (!parsedMetafield) {
634
+ const noDataPropWarning = `<Metafield/>: nothing was passed to the data prop 'data'. Rendering 'null'`;
635
+ {
636
+ throw new Error(noDataPropWarning);
637
+ }
638
+ }
639
+ if (parsedMetafield.value === null || parsedMetafield.value === void 0) {
640
+ const noValueWarning = `<Metafield/>: No metafield value for metafield ${(_a = parsedMetafield.id) != null ? _a : parsedMetafield.key}. Rendering 'null'`;
641
+ {
642
+ throw new Error(noValueWarning);
643
+ }
644
+ }
645
+ switch (parsedMetafield.type) {
646
+ case "date": {
647
+ const Wrapper2 = as != null ? as : "time";
648
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper2, {
649
+ ...passthroughProps,
650
+ __self: this,
651
+ __source: {
652
+ fileName: _jsxFileName$4,
653
+ lineNumber: 68,
654
+ columnNumber: 9
655
+ }
656
+ }, parsedMetafield.value.toLocaleDateString(locale));
657
+ }
658
+ case "date_time": {
659
+ const Wrapper2 = as != null ? as : "time";
660
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper2, {
661
+ ...passthroughProps,
662
+ __self: this,
663
+ __source: {
664
+ fileName: _jsxFileName$4,
665
+ lineNumber: 76,
666
+ columnNumber: 9
667
+ }
668
+ }, parsedMetafield.value.toLocaleString(locale));
669
+ }
670
+ case "weight":
671
+ case "dimension":
672
+ case "volume": {
673
+ const Wrapper2 = as != null ? as : "span";
674
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper2, {
675
+ ...passthroughProps,
676
+ __self: this,
677
+ __source: {
678
+ fileName: _jsxFileName$4,
679
+ lineNumber: 86,
680
+ columnNumber: 9
681
+ }
682
+ }, getMeasurementAsString(parsedMetafield.value, locale));
683
+ }
684
+ case "rating": {
685
+ const Wrapper2 = as != null ? as : "span";
686
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper2, {
687
+ ...passthroughProps,
688
+ __self: this,
689
+ __source: {
690
+ fileName: _jsxFileName$4,
691
+ lineNumber: 94,
692
+ columnNumber: 9
693
+ }
694
+ }, parsedMetafield.value.value);
695
+ }
696
+ case "single_line_text_field": {
697
+ const Wrapper2 = as != null ? as : "span";
698
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper2, {
699
+ ...passthroughProps,
700
+ dangerouslySetInnerHTML: {
701
+ __html: parsedMetafield.value
702
+ },
703
+ __self: this,
704
+ __source: {
705
+ fileName: _jsxFileName$4,
706
+ lineNumber: 102,
707
+ columnNumber: 9
708
+ }
709
+ });
710
+ }
711
+ case "multi_line_text_field": {
712
+ const Wrapper2 = as != null ? as : "div";
713
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper2, {
714
+ ...passthroughProps,
715
+ dangerouslySetInnerHTML: {
716
+ __html: parsedMetafield.value.split("\n").join("<br/>")
717
+ },
718
+ __self: this,
719
+ __source: {
720
+ fileName: _jsxFileName$4,
721
+ lineNumber: 111,
722
+ columnNumber: 9
723
+ }
724
+ });
725
+ }
726
+ case "url": {
727
+ const protocolLessUrl = new URL(parsedMetafield.value);
728
+ return /* @__PURE__ */ React__default.default.createElement("a", {
729
+ href: protocolLessUrl.href.replace(protocolLessUrl.protocol, ""),
730
+ ...passthroughProps,
731
+ __self: this,
732
+ __source: {
733
+ fileName: _jsxFileName$4,
734
+ lineNumber: 122,
735
+ columnNumber: 9
736
+ }
737
+ }, parsedMetafield.value);
738
+ }
739
+ case "json": {
740
+ const Wrapper2 = as != null ? as : "span";
741
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper2, {
742
+ ...passthroughProps,
743
+ __self: this,
744
+ __source: {
745
+ fileName: _jsxFileName$4,
746
+ lineNumber: 133,
747
+ columnNumber: 9
748
+ }
749
+ }, JSON.stringify(parsedMetafield.value));
750
+ }
751
+ case "product_reference":
752
+ case "variant_reference":
753
+ case "page_reference": {
754
+ const Wrapper2 = as != null ? as : "span";
755
+ const ref = parsedMetafield.reference;
756
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper2, {
757
+ ...passthroughProps,
758
+ __self: this,
759
+ __source: {
760
+ fileName: _jsxFileName$4,
761
+ lineNumber: 144,
762
+ columnNumber: 9
763
+ }
764
+ }, (_c = (_b = ref == null ? void 0 : ref.title) != null ? _b : ref == null ? void 0 : ref.id) != null ? _c : "");
765
+ }
766
+ case "list.single_line_text_field": {
767
+ const Wrapper2 = as != null ? as : "ul";
768
+ const refArray = parsedMetafield.references ? flattenConnection(parsedMetafield.references) : [];
769
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper2, {
770
+ ...passthroughProps,
771
+ __self: this,
772
+ __source: {
773
+ fileName: _jsxFileName$4,
774
+ lineNumber: 155,
775
+ columnNumber: 9
776
+ }
777
+ }, refArray.map((ref, index) => /* @__PURE__ */ React__default.default.createElement("li", {
778
+ key: `${ref != null ? ref : ""}-${index}`,
779
+ __self: this,
780
+ __source: {
781
+ fileName: _jsxFileName$4,
782
+ lineNumber: 159,
783
+ columnNumber: 13
784
+ }
785
+ }, ref)));
786
+ }
787
+ case "file_reference": {
788
+ if (((_d = parsedMetafield.reference) == null ? void 0 : _d.__typename) === "MediaImage") {
789
+ const ref = parsedMetafield.reference;
790
+ return ref.image ? /* @__PURE__ */ React__default.default.createElement(Image, {
791
+ data: ref.image,
792
+ ...passthroughProps,
793
+ __self: this,
794
+ __source: {
795
+ fileName: _jsxFileName$4,
796
+ lineNumber: 168,
797
+ columnNumber: 11
798
+ }
799
+ }) : null;
800
+ } else if (((_e = parsedMetafield.reference) == null ? void 0 : _e.__typename) === "GenericFile") {
801
+ const ref = parsedMetafield.reference;
802
+ return ref.previewImage ? /* @__PURE__ */ React__default.default.createElement("a", {
803
+ href: (_g = (_f = parsedMetafield.reference) == null ? void 0 : _f.url) != null ? _g : "",
804
+ ...passthroughProps,
805
+ __self: this,
806
+ __source: {
807
+ fileName: _jsxFileName$4,
808
+ lineNumber: 173,
809
+ columnNumber: 11
810
+ }
811
+ }, /* @__PURE__ */ React__default.default.createElement(Image, {
812
+ data: ref.previewImage,
813
+ __self: this,
814
+ __source: {
815
+ fileName: _jsxFileName$4,
816
+ lineNumber: 174,
817
+ columnNumber: 13
818
+ }
819
+ })) : null;
820
+ } else if (((_h = parsedMetafield.reference) == null ? void 0 : _h.__typename) === "Video") {
821
+ const ref = parsedMetafield.reference;
822
+ return /* @__PURE__ */ React__default.default.createElement(Video, {
823
+ ...passthroughProps,
824
+ data: ref,
825
+ __self: this,
826
+ __source: {
827
+ fileName: _jsxFileName$4,
828
+ lineNumber: 179,
829
+ columnNumber: 16
830
+ }
831
+ });
832
+ }
833
+ }
834
+ }
835
+ const Wrapper = as != null ? as : "span";
836
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper, {
837
+ ...passthroughProps,
838
+ __self: this,
839
+ __source: {
840
+ fileName: _jsxFileName$4,
841
+ lineNumber: 186,
842
+ columnNumber: 5
843
+ }
844
+ }, (_i = parsedMetafield.value) == null ? void 0 : _i.toString());
845
+ }
846
+ function parseMetafield(metafield) {
847
+ if (!metafield) {
848
+ {
849
+ console.warn(`'parseMetafield' was not passed any value for the 'metafield' argument`);
850
+ }
851
+ return null;
852
+ }
853
+ if (metafield.value === null || metafield.value === void 0) {
854
+ console.warn(`'parseMetafield()' was passed ${metafield.value} for 'metafield.value'`);
855
+ }
856
+ return {
857
+ ...metafield,
858
+ value: parseMetafieldValue(metafield)
859
+ };
860
+ }
861
+ function parseMetafieldValue(metafield) {
862
+ if (!metafield) {
863
+ return null;
864
+ }
865
+ if (metafield.value === null || metafield.value === void 0) {
866
+ {
867
+ console.warn(`'parseMetafieldValue()' was passed ${metafield.value} for 'metafield.value'`);
868
+ }
869
+ return metafield.value;
870
+ }
871
+ switch (metafield.type) {
872
+ case "boolean":
873
+ return metafield.value === "true";
874
+ case "number_integer":
875
+ return parseInt(metafield.value);
876
+ case "number_decimal":
877
+ return parseFloat(metafield.value);
878
+ case "date":
879
+ case "date_time":
880
+ return new Date(metafield.value);
881
+ case "json":
882
+ case "weight":
883
+ case "dimension":
884
+ case "volume":
885
+ case "rating":
886
+ return parseJSON(metafield.value);
887
+ case "color":
888
+ case "single_line_text_field":
889
+ case "multi_line_text_field":
890
+ case "product_reference":
891
+ case "page_reference":
892
+ case "variant_reference":
893
+ case "file_reference":
894
+ case "url":
895
+ default:
896
+ return metafield.value;
897
+ }
898
+ }
899
+ function parseJSON(json) {
900
+ if (String(json).includes("__proto__")) {
901
+ return JSON.parse(json, (k, v) => {
902
+ if (k !== "__proto__")
903
+ return v;
904
+ });
905
+ }
906
+ return JSON.parse(json);
907
+ }
908
+ const UNIT_MAPPING = {
909
+ mm: "millimeter",
910
+ cm: "centimeter",
911
+ m: "meter",
912
+ in: "inch",
913
+ ft: "foot",
914
+ yd: "yard",
915
+ ml: "milliliter",
916
+ l: "liter",
917
+ us_fl_oz: "fluid-ounce",
918
+ us_gal: "gallon",
919
+ kg: "kilogram",
920
+ g: "gram",
921
+ lb: "pound",
922
+ oz: "ounce"
923
+ };
924
+ function getMeasurementAsString(measurement, locale = "en-us", options = {}) {
925
+ let measure = {
926
+ value: measurement.value,
927
+ unit: UNIT_MAPPING[measurement.unit]
928
+ };
929
+ if (measure.unit == null) {
930
+ measure = convertToSupportedUnit(measurement.value, measurement.unit);
931
+ }
932
+ return new Intl.NumberFormat(locale, {
933
+ ...options,
934
+ unit: measure.unit,
935
+ style: "unit"
936
+ }).format(measure.value);
937
+ }
938
+ function convertToSupportedUnit(value, unit) {
939
+ switch (unit) {
940
+ case "cl":
941
+ return {
942
+ value: value / 1e3,
943
+ unit: "liter"
944
+ };
945
+ case "m3":
946
+ return {
947
+ value: value * 1e3,
948
+ unit: "liter"
949
+ };
950
+ case "us_pt":
951
+ return {
952
+ value: value * 0.125,
953
+ unit: "gallon"
954
+ };
955
+ case "us_qt":
956
+ return {
957
+ value: value * 0.5,
958
+ unit: "gallon"
959
+ };
960
+ case "us_oz":
961
+ return {
962
+ value: value / 128,
963
+ unit: "gallon"
964
+ };
965
+ case "imp_pt":
966
+ return {
967
+ value: value / 6.661,
968
+ unit: "gallon"
969
+ };
970
+ case "imp_qt":
971
+ return {
972
+ value: value / 3.331,
973
+ unit: "gallon"
974
+ };
975
+ case "imp_gal":
976
+ return {
977
+ value: value / 1.201,
978
+ unit: "gallon"
979
+ };
980
+ case "imp_fl_oz":
981
+ return {
982
+ value: value * 0.96076,
983
+ unit: "fluid-ounce"
984
+ };
985
+ default:
986
+ throw new Error(`Unit not supported: ${unit}`);
987
+ }
988
+ }
989
+ function useMoney(money) {
990
+ const {
991
+ locale
992
+ } = useShop();
993
+ if (!locale) {
994
+ throw new Error(`useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`);
995
+ }
996
+ const amount = parseFloat(money.amount);
997
+ const options = React.useMemo(() => ({
998
+ style: "currency",
999
+ currency: money.currencyCode
1000
+ }), [money.currencyCode]);
1001
+ const defaultFormatter = useLazyFormatter(locale, options);
1002
+ const nameFormatter = useLazyFormatter(locale, {
1003
+ ...options,
1004
+ currencyDisplay: "name"
1005
+ });
1006
+ const narrowSymbolFormatter = useLazyFormatter(locale, {
1007
+ ...options,
1008
+ currencyDisplay: "narrowSymbol"
1009
+ });
1010
+ const withoutTrailingZerosFormatter = useLazyFormatter(locale, {
1011
+ ...options,
1012
+ minimumFractionDigits: 0,
1013
+ maximumFractionDigits: 0
1014
+ });
1015
+ const withoutCurrencyFormatter = useLazyFormatter(locale);
1016
+ const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {
1017
+ minimumFractionDigits: 0,
1018
+ maximumFractionDigits: 0
1019
+ });
1020
+ const isPartCurrency = (part) => part.type === "currency";
1021
+ const lazyFormatters = React.useMemo(() => ({
1022
+ original: () => money,
1023
+ currencyCode: () => money.currencyCode,
1024
+ localizedString: () => defaultFormatter().format(amount),
1025
+ parts: () => defaultFormatter().formatToParts(amount),
1026
+ withoutTrailingZeros: () => amount % 1 === 0 ? withoutTrailingZerosFormatter().format(amount) : defaultFormatter().format(amount),
1027
+ withoutTrailingZerosAndCurrency: () => amount % 1 === 0 ? withoutTrailingZerosOrCurrencyFormatter().format(amount) : withoutCurrencyFormatter().format(amount),
1028
+ currencyName: () => {
1029
+ var _a, _b;
1030
+ return (_b = (_a = nameFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : money.currencyCode;
1031
+ },
1032
+ currencySymbol: () => {
1033
+ var _a, _b;
1034
+ return (_b = (_a = defaultFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : money.currencyCode;
1035
+ },
1036
+ currencyNarrowSymbol: () => {
1037
+ var _a, _b;
1038
+ return (_b = (_a = narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : "";
1039
+ },
1040
+ amount: () => defaultFormatter().formatToParts(amount).filter((part) => ["decimal", "fraction", "group", "integer", "literal"].includes(part.type)).map((part) => part.value).join("")
1041
+ }), [money, amount, nameFormatter, defaultFormatter, narrowSymbolFormatter, withoutCurrencyFormatter, withoutTrailingZerosFormatter, withoutTrailingZerosOrCurrencyFormatter]);
1042
+ return React.useMemo(() => new Proxy(lazyFormatters, {
1043
+ get: (target, key) => {
1044
+ var _a;
1045
+ return (_a = Reflect.get(target, key)) == null ? void 0 : _a.call(null);
1046
+ }
1047
+ }), [lazyFormatters]);
1048
+ }
1049
+ function useLazyFormatter(locale, options) {
1050
+ return React.useMemo(() => {
1051
+ let memoized;
1052
+ return () => memoized != null ? memoized : memoized = new Intl.NumberFormat(locale, options);
1053
+ }, [locale, options]);
1054
+ }
1055
+ var _jsxFileName$3 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Money.tsx";
1056
+ function Money({
1057
+ data,
1058
+ as,
1059
+ withoutCurrency,
1060
+ withoutTrailingZeros,
1061
+ measurement,
1062
+ measurementSeparator = "/",
1063
+ ...passthroughProps
1064
+ }) {
1065
+ if (!isMoney(data)) {
1066
+ throw new Error(`<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`);
1067
+ }
1068
+ const moneyObject = useMoney(data);
1069
+ const Wrapper = as != null ? as : "div";
1070
+ let output = moneyObject.localizedString;
1071
+ if (withoutCurrency || withoutTrailingZeros) {
1072
+ if (withoutCurrency && !withoutTrailingZeros) {
1073
+ output = moneyObject.amount;
1074
+ } else if (!withoutCurrency && withoutTrailingZeros) {
1075
+ output = moneyObject.withoutTrailingZeros;
1076
+ } else {
1077
+ output = moneyObject.withoutTrailingZerosAndCurrency;
1078
+ }
1079
+ }
1080
+ return /* @__PURE__ */ React__default.default.createElement(Wrapper, {
1081
+ ...passthroughProps,
1082
+ __self: this,
1083
+ __source: {
1084
+ fileName: _jsxFileName$3,
1085
+ lineNumber: 65,
1086
+ columnNumber: 5
1087
+ }
1088
+ }, output, measurement && measurement.referenceUnit && /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, measurementSeparator, measurement.referenceUnit));
1089
+ }
1090
+ function isMoney(maybeMoney) {
1091
+ return typeof maybeMoney.amount === "string" && !!maybeMoney.amount && typeof maybeMoney.currencyCode === "string" && !!maybeMoney.currencyCode;
1092
+ }
1093
+ var _jsxFileName$2 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductPrice.tsx";
1094
+ function ProductPrice(props) {
1095
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1096
+ const {
1097
+ priceType = "regular",
1098
+ variantId,
1099
+ valueType = "min",
1100
+ data: product,
1101
+ ...passthroughProps
1102
+ } = props;
1103
+ if (product == null) {
1104
+ throw new Error(`<ProductPrice/> requires a product as the 'data' prop`);
1105
+ }
1106
+ let price;
1107
+ let measurement;
1108
+ const variant = variantId ? (_b = flattenConnection((_a = product == null ? void 0 : product.variants) != null ? _a : {}).find((variant2) => (variant2 == null ? void 0 : variant2.id) === variantId)) != null ? _b : null : null;
1109
+ if (priceType === "compareAt") {
1110
+ if (variantId && variant) {
1111
+ if (((_c = variant.compareAtPriceV2) == null ? void 0 : _c.amount) === ((_d = variant.priceV2) == null ? void 0 : _d.amount)) {
1112
+ return null;
1113
+ }
1114
+ price = variant.compareAtPriceV2;
1115
+ } else if (valueType === "max") {
1116
+ price = (_e = product == null ? void 0 : product.compareAtPriceRange) == null ? void 0 : _e.maxVariantPrice;
1117
+ } else {
1118
+ price = (_f = product == null ? void 0 : product.compareAtPriceRange) == null ? void 0 : _f.minVariantPrice;
1119
+ }
1120
+ } else {
1121
+ if (variantId && variant) {
1122
+ price = variant.priceV2;
1123
+ if (valueType === "unit") {
1124
+ price = variant.unitPrice;
1125
+ measurement = variant.unitPriceMeasurement;
1126
+ }
1127
+ } else if (valueType === "max") {
1128
+ price = (_g = product.priceRange) == null ? void 0 : _g.maxVariantPrice;
1129
+ } else {
1130
+ price = (_h = product.priceRange) == null ? void 0 : _h.minVariantPrice;
1131
+ }
1132
+ }
1133
+ if (!price) {
1134
+ return null;
1135
+ }
1136
+ if (measurement) {
1137
+ return /* @__PURE__ */ React__default.default.createElement(Money, {
1138
+ ...passthroughProps,
1139
+ data: price,
1140
+ measurement,
1141
+ __self: this,
1142
+ __source: {
1143
+ fileName: _jsxFileName$2,
1144
+ lineNumber: 82,
1145
+ columnNumber: 7
1146
+ }
1147
+ });
1148
+ }
1149
+ return /* @__PURE__ */ React__default.default.createElement(Money, {
1150
+ ...passthroughProps,
1151
+ data: price,
1152
+ __self: this,
1153
+ __source: {
1154
+ fileName: _jsxFileName$2,
1155
+ lineNumber: 86,
1156
+ columnNumber: 10
1157
+ }
1158
+ });
1159
+ }
1160
+ var _jsxFileName$1 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductProvider.tsx";
1161
+ const ProductOptionsContext = React.createContext(null);
1162
+ function ProductProvider({
1163
+ children,
1164
+ data: product,
1165
+ initialVariantId: explicitVariantId
1166
+ }) {
1167
+ const variants = React.useMemo(() => {
1168
+ var _a;
1169
+ return flattenConnection((_a = product.variants) != null ? _a : {});
1170
+ }, [product.variants]);
1171
+ if (!isProductVariantArray(variants)) {
1172
+ throw new Error(`<ProductProvider/> requires 'product.variants.nodes' or 'product.variants.edges'`);
1173
+ }
1174
+ const options = React.useMemo(() => getOptions(variants), [variants]);
1175
+ const [selectedVariant, setSelectedVariant] = React.useState(() => getVariantBasedOnIdProp(explicitVariantId, variants));
1176
+ const [selectedOptions, setSelectedOptions] = React.useState(() => getSelectedOptions(selectedVariant));
1177
+ React.useEffect(() => {
1178
+ const newSelectedVariant = getVariantBasedOnIdProp(explicitVariantId, variants);
1179
+ setSelectedVariant(newSelectedVariant);
1180
+ setSelectedOptions(getSelectedOptions(newSelectedVariant));
1181
+ }, [explicitVariantId, variants]);
1182
+ const setSelectedOption = React.useCallback((name, value2) => {
1183
+ setSelectedOptions((selectedOptions2) => {
1184
+ const opts = {
1185
+ ...selectedOptions2,
1186
+ [name]: value2
1187
+ };
1188
+ setSelectedVariant(getSelectedVariant(variants, opts));
1189
+ return opts;
1190
+ });
1191
+ }, [setSelectedOptions, variants]);
1192
+ const isOptionInStock = React.useCallback((option, value2) => {
1193
+ var _a;
1194
+ const proposedVariant = getSelectedVariant(variants, {
1195
+ ...selectedOptions,
1196
+ ...{
1197
+ [option]: value2
1198
+ }
1199
+ });
1200
+ return (_a = proposedVariant == null ? void 0 : proposedVariant.availableForSale) != null ? _a : true;
1201
+ }, [selectedOptions, variants]);
1202
+ const sellingPlanGroups = React.useMemo(() => {
1203
+ var _a;
1204
+ return flattenConnection((_a = product.sellingPlanGroups) != null ? _a : {}).map((sellingPlanGroup) => {
1205
+ var _a2;
1206
+ return {
1207
+ ...sellingPlanGroup,
1208
+ sellingPlans: flattenConnection((_a2 = sellingPlanGroup == null ? void 0 : sellingPlanGroup.sellingPlans) != null ? _a2 : {})
1209
+ };
1210
+ });
1211
+ }, [product.sellingPlanGroups]);
1212
+ const [selectedSellingPlan, setSelectedSellingPlan] = React.useState(void 0);
1213
+ const selectedSellingPlanAllocation = React.useMemo(() => {
1214
+ var _a, _b;
1215
+ if (!selectedVariant || !selectedSellingPlan) {
1216
+ return;
1217
+ }
1218
+ if (!((_a = selectedVariant.sellingPlanAllocations) == null ? void 0 : _a.nodes) && !((_b = selectedVariant.sellingPlanAllocations) == null ? void 0 : _b.edges)) {
1219
+ throw new Error(`<ProductProvider/>: You must include 'sellingPlanAllocations.nodes' or 'sellingPlanAllocations.edges' in your variants in order to calculate selectedSellingPlanAllocation`);
1220
+ }
1221
+ return flattenConnection(selectedVariant.sellingPlanAllocations).find((allocation) => {
1222
+ var _a2;
1223
+ return ((_a2 = allocation == null ? void 0 : allocation.sellingPlan) == null ? void 0 : _a2.id) === selectedSellingPlan.id;
1224
+ });
1225
+ }, [selectedVariant, selectedSellingPlan]);
1226
+ const value = React.useMemo(() => ({
1227
+ variants,
1228
+ variantsConnection: product.variants,
1229
+ options,
1230
+ selectedVariant,
1231
+ setSelectedVariant,
1232
+ selectedOptions,
1233
+ setSelectedOption,
1234
+ setSelectedOptions,
1235
+ isOptionInStock,
1236
+ selectedSellingPlan,
1237
+ setSelectedSellingPlan,
1238
+ selectedSellingPlanAllocation,
1239
+ sellingPlanGroups,
1240
+ sellingPlanGroupsConnection: product.sellingPlanGroups
1241
+ }), [isOptionInStock, options, product.sellingPlanGroups, product.variants, selectedOptions, selectedSellingPlan, selectedSellingPlanAllocation, selectedVariant, sellingPlanGroups, setSelectedOption, variants]);
1242
+ return /* @__PURE__ */ React__default.default.createElement(ProductOptionsContext.Provider, {
1243
+ value,
1244
+ __self: this,
1245
+ __source: {
1246
+ fileName: _jsxFileName$1,
1247
+ lineNumber: 201,
1248
+ columnNumber: 5
1249
+ }
1250
+ }, children);
1251
+ }
1252
+ function useProduct() {
1253
+ const context = React.useContext(ProductOptionsContext);
1254
+ if (!context) {
1255
+ throw new Error(`'useProduct' must be a child of <ProductProvider />`);
1256
+ }
1257
+ return context;
1258
+ }
1259
+ function getSelectedVariant(variants, choices) {
1260
+ var _a, _b;
1261
+ if (!variants.length || ((_b = (_a = variants == null ? void 0 : variants[0]) == null ? void 0 : _a.selectedOptions) == null ? void 0 : _b.length) !== Object.keys(choices).length) {
1262
+ return;
1263
+ }
1264
+ return variants == null ? void 0 : variants.find((variant) => {
1265
+ return Object.entries(choices).every(([name, value]) => {
1266
+ var _a2;
1267
+ return (_a2 = variant == null ? void 0 : variant.selectedOptions) == null ? void 0 : _a2.some((option) => (option == null ? void 0 : option.name) === name && (option == null ? void 0 : option.value) === value);
1268
+ });
1269
+ });
1270
+ }
1271
+ function getOptions(variants) {
1272
+ const map = variants.reduce((memo, variant) => {
1273
+ var _a;
1274
+ if (!variant.selectedOptions) {
1275
+ throw new Error(`'getOptions' requires 'variant.selectedOptions'`);
1276
+ }
1277
+ (_a = variant == null ? void 0 : variant.selectedOptions) == null ? void 0 : _a.forEach((opt) => {
1278
+ var _a2, _b, _c, _d;
1279
+ memo[(_a2 = opt == null ? void 0 : opt.name) != null ? _a2 : ""] = memo[(_b = opt == null ? void 0 : opt.name) != null ? _b : ""] || /* @__PURE__ */ new Set();
1280
+ memo[(_c = opt == null ? void 0 : opt.name) != null ? _c : ""].add((_d = opt == null ? void 0 : opt.value) != null ? _d : "");
1281
+ });
1282
+ return memo;
1283
+ }, {});
1284
+ return Object.keys(map).map((option) => {
1285
+ return {
1286
+ name: option,
1287
+ values: Array.from(map[option])
1288
+ };
1289
+ });
1290
+ }
1291
+ function getVariantBasedOnIdProp(explicitVariantId, variants) {
1292
+ if (explicitVariantId) {
1293
+ const foundVariant = variants.find((variant) => (variant == null ? void 0 : variant.id) === explicitVariantId);
1294
+ if (!foundVariant) {
1295
+ console.warn(`<ProductProvider/> received a 'initialVariantId' prop, but could not actually find a variant with that ID`);
1296
+ }
1297
+ return foundVariant;
1298
+ }
1299
+ if (explicitVariantId === null) {
1300
+ return null;
1301
+ }
1302
+ if (explicitVariantId === void 0) {
1303
+ return variants.find((variant) => variant == null ? void 0 : variant.availableForSale) || variants[0];
1304
+ }
1305
+ }
1306
+ function getSelectedOptions(selectedVariant) {
1307
+ return (selectedVariant == null ? void 0 : selectedVariant.selectedOptions) ? selectedVariant.selectedOptions.reduce((memo, optionSet) => {
1308
+ var _a, _b;
1309
+ memo[(_a = optionSet == null ? void 0 : optionSet.name) != null ? _a : ""] = (_b = optionSet == null ? void 0 : optionSet.value) != null ? _b : "";
1310
+ return memo;
1311
+ }, {}) : {};
1312
+ }
1313
+ function isProductVariantArray(maybeVariantArray) {
1314
+ if (!maybeVariantArray || !Array.isArray(maybeVariantArray)) {
1315
+ return false;
1316
+ }
1317
+ return true;
1318
+ }
1319
+ var _jsxFileName = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopPayButton.tsx";
1320
+ const SHOPJS_URL = "https://cdn.shopify.com/shopifycloud/shop-js/v1.0/client.js";
1321
+ function ShopPayButton({
1322
+ variantIds,
1323
+ className,
1324
+ variantIdsAndQuantities,
1325
+ width
1326
+ }) {
1327
+ const {
1328
+ storeDomain
1329
+ } = useShop();
1330
+ const shopPayLoadedStatus = useLoadScript(SHOPJS_URL);
1331
+ let ids;
1332
+ if (variantIds && variantIdsAndQuantities) {
1333
+ throw new Error(DoublePropsErrorMessage);
1334
+ }
1335
+ if (variantIds) {
1336
+ ids = variantIds.reduce((prev, curr) => {
1337
+ const bareId = getIdFromGid(curr);
1338
+ if (bareId) {
1339
+ prev.push(bareId);
1340
+ }
1341
+ return prev;
1342
+ }, []);
1343
+ } else if (variantIdsAndQuantities) {
1344
+ ids = variantIdsAndQuantities.reduce((prev, curr) => {
1345
+ var _a;
1346
+ const bareId = getIdFromGid(curr == null ? void 0 : curr.id);
1347
+ if (bareId) {
1348
+ prev.push(`${bareId}:${(_a = curr == null ? void 0 : curr.quantity) != null ? _a : 1}`);
1349
+ }
1350
+ return prev;
1351
+ }, []);
1352
+ } else {
1353
+ throw new Error(MissingPropsErrorMessage);
1354
+ }
1355
+ const style = width ? {
1356
+ "--shop-pay-button-width": width
1357
+ } : void 0;
1358
+ return /* @__PURE__ */ React__default.default.createElement("div", {
1359
+ className,
1360
+ style,
1361
+ __self: this,
1362
+ __source: {
1363
+ fileName: _jsxFileName,
1364
+ lineNumber: 91,
1365
+ columnNumber: 5
1366
+ }
1367
+ }, shopPayLoadedStatus === "done" && /* @__PURE__ */ React__default.default.createElement("shop-pay-button", {
1368
+ "store-url": `https://${storeDomain}`,
1369
+ variants: ids.join(","),
1370
+ __self: this,
1371
+ __source: {
1372
+ fileName: _jsxFileName,
1373
+ lineNumber: 93,
1374
+ columnNumber: 9
1375
+ }
1376
+ }));
1377
+ }
1378
+ function getIdFromGid(id) {
1379
+ if (!id)
1380
+ return;
1381
+ return id.split("/").pop();
1382
+ }
1383
+ const MissingPropsErrorMessage = `You must pass in either "variantIds" or "variantIdsAndQuantities" to ShopPayButton`;
1384
+ const DoublePropsErrorMessage = `You must provide either a variantIds or variantIdsAndQuantities prop, but not both in the ShopPayButton component`;
1385
+ function createStorefrontClient({
1386
+ storeDomain,
1387
+ privateStorefrontToken,
1388
+ publicStorefrontToken,
1389
+ storefrontApiVersion,
1390
+ contentType
1391
+ }) {
1392
+ if (storefrontApiVersion !== SFAPI_VERSION) {
1393
+ console.warn(
1394
+ `StorefrontClient: The Storefront API version that you're using is different than the version this build of Hydrogen-UI is targeting. You may run into unexpected errors if these versions don't match. Received verion: "${storefrontApiVersion}"; expected version ${SFAPI_VERSION}`
1395
+ );
1396
+ }
1397
+ if (!privateStorefrontToken && !globalThis.document) {
1398
+ console.warn(
1399
+ `StorefrontClient: Using a private storefront token is recommended for server environments. Refer to the authentication https://shopify.dev/api/storefront#authentication documentation for more details. `
1400
+ );
1401
+ }
1402
+ if (privateStorefrontToken && globalThis) {
1403
+ console.warn(
1404
+ `StorefrontClient: You are attempting to use a private token in an environment where it can be easily accessed by anyone. This is a security risk; please use the public token and the 'publicStorefrontToken' prop`
1405
+ );
1406
+ }
1407
+ return {
1408
+ getStorefrontApiUrl(overrideProps) {
1409
+ var _a, _b;
1410
+ return `https://${(_a = overrideProps == null ? void 0 : overrideProps.storeDomain) != null ? _a : storeDomain}.myshopify.com/api/${(_b = overrideProps == null ? void 0 : overrideProps.storefrontApiVersion) != null ? _b : storefrontApiVersion}/graphql.json`;
1411
+ },
1412
+ getPrivateTokenHeaders(overrideProps) {
1413
+ var _a, _b, _c;
1414
+ if (!privateStorefrontToken && !(overrideProps == null ? void 0 : overrideProps.privateStorefrontToken)) {
1415
+ throw new Error(
1416
+ `StorefrontClient: You did not pass in a 'privateStorefrontToken' while using 'getPrivateTokenHeaders()'`
1417
+ );
1418
+ }
1419
+ if (!(overrideProps == null ? void 0 : overrideProps.buyerIp)) {
1420
+ console.warn(
1421
+ `StorefrontClient: it is recommended to pass in the 'buyerIp' property which improves analytics and data in the admin.`
1422
+ );
1423
+ }
1424
+ const finalContentType = (_a = overrideProps == null ? void 0 : overrideProps.contentType) != null ? _a : contentType;
1425
+ return {
1426
+ "content-type": finalContentType === "graphql" ? "application/graphql" : "application/json",
1427
+ "X-SDK-Variant": "hydrogen-ui",
1428
+ "X-SDK-Variant-Source": "react",
1429
+ "X-SDK-Version": storefrontApiVersion,
1430
+ "Shopify-Storefront-Private-Token": (_c = (_b = overrideProps == null ? void 0 : overrideProps.privateStorefrontToken) != null ? _b : privateStorefrontToken) != null ? _c : "",
1431
+ ...(overrideProps == null ? void 0 : overrideProps.buyerIp) ? { "Shopify-Storefront-Buyer-IP": overrideProps.buyerIp } : {}
1432
+ };
1433
+ },
1434
+ getPublicTokenHeaders(overrideProps) {
1435
+ var _a, _b, _c;
1436
+ if (!publicStorefrontToken && !(overrideProps == null ? void 0 : overrideProps.publicStorefrontToken)) {
1437
+ throw new Error(
1438
+ `StorefrontClient: You did not pass in a 'publicStorefrontToken' while using 'getPublicTokenHeaders()'`
1439
+ );
1440
+ }
1441
+ const finalContentType = (_a = overrideProps == null ? void 0 : overrideProps.contentType) != null ? _a : contentType;
1442
+ return {
1443
+ "content-type": finalContentType === "graphql" ? "application/graphql" : "application/json",
1444
+ "X-SDK-Variant": "hydrogen-ui",
1445
+ "X-SDK-Variant-Source": "react",
1446
+ "X-SDK-Version": storefrontApiVersion,
1447
+ "X-Shopify-Storefront-Access-Token": (_c = (_b = overrideProps == null ? void 0 : overrideProps.publicStorefrontToken) != null ? _b : publicStorefrontToken) != null ? _c : ""
1448
+ };
1449
+ }
1450
+ };
1451
+ }
1452
+ exports2.ExternalVideo = ExternalVideo;
1453
+ exports2.Image = Image;
1454
+ exports2.MediaFile = MediaFile;
1455
+ exports2.Metafield = Metafield;
1456
+ exports2.ModelViewer = ModelViewer;
1457
+ exports2.Money = Money;
1458
+ exports2.ProductPrice = ProductPrice;
1459
+ exports2.ProductProvider = ProductProvider;
1460
+ exports2.ShopPayButton = ShopPayButton;
1461
+ exports2.ShopifyProvider = ShopifyProvider;
1462
+ exports2.Video = Video;
1463
+ exports2.createStorefrontClient = createStorefrontClient;
1464
+ exports2.flattenConnection = flattenConnection;
1465
+ exports2.parseMetafield = parseMetafield;
1466
+ exports2.parseMetafieldValue = parseMetafieldValue;
1467
+ exports2.useMoney = useMoney;
1468
+ exports2.useProduct = useProduct;
1469
+ exports2.useShop = useShop;
1470
+ Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
1471
+ });
1472
+ //# sourceMappingURL=hydrogen-react.dev.js.map