@shopify/hydrogen-react 0.0.0-next-022e862 → 0.0.0-next-c23a62a

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 (230) hide show
  1. package/dist/dev/CartProvider.js +20 -20
  2. package/dist/dev/CartProvider.js.map +1 -1
  3. package/dist/dev/Metafield.js +8 -2
  4. package/dist/dev/Metafield.js.map +1 -1
  5. package/dist/dev/Metafield.mjs +6 -0
  6. package/dist/dev/Metafield.mjs.map +1 -1
  7. package/dist/dev/ModelViewer.js +4 -4
  8. package/dist/dev/ModelViewer.js.map +1 -1
  9. package/dist/dev/ProductProvider.js +14 -14
  10. package/dist/dev/ProductProvider.js.map +1 -1
  11. package/dist/dev/ShopifyProvider.js +4 -4
  12. package/dist/dev/ShopifyProvider.js.map +1 -1
  13. package/dist/dev/Video.js +2 -2
  14. package/dist/dev/_virtual/index.js +5 -0
  15. package/dist/dev/_virtual/index.js.map +1 -0
  16. package/dist/dev/_virtual/index.mjs +5 -0
  17. package/dist/dev/_virtual/index.mjs.map +1 -0
  18. package/dist/dev/_virtual/index2.js +5 -0
  19. package/dist/dev/_virtual/index2.js.map +1 -0
  20. package/dist/dev/_virtual/index2.mjs +5 -0
  21. package/dist/dev/_virtual/index2.mjs.map +1 -0
  22. package/dist/dev/_virtual/use-sync-external-store-shim.development.js +5 -0
  23. package/dist/dev/_virtual/use-sync-external-store-shim.development.js.map +1 -0
  24. package/dist/dev/_virtual/use-sync-external-store-shim.development.mjs +5 -0
  25. package/dist/dev/_virtual/use-sync-external-store-shim.development.mjs.map +1 -0
  26. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.js +5 -0
  27. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.js.map +1 -0
  28. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.mjs +5 -0
  29. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.mjs.map +1 -0
  30. package/dist/dev/_virtual/with-selector.development.js +5 -0
  31. package/dist/dev/_virtual/with-selector.development.js.map +1 -0
  32. package/dist/dev/_virtual/with-selector.development.mjs +5 -0
  33. package/dist/dev/_virtual/with-selector.development.mjs.map +1 -0
  34. package/dist/dev/_virtual/with-selector.js +5 -0
  35. package/dist/dev/_virtual/with-selector.js.map +1 -0
  36. package/dist/dev/_virtual/with-selector.mjs +5 -0
  37. package/dist/dev/_virtual/with-selector.mjs.map +1 -0
  38. package/dist/dev/_virtual/with-selector.production.min.js +5 -0
  39. package/dist/dev/_virtual/with-selector.production.min.js.map +1 -0
  40. package/dist/dev/_virtual/with-selector.production.min.mjs +5 -0
  41. package/dist/dev/_virtual/with-selector.production.min.mjs.map +1 -0
  42. package/dist/dev/cart-hooks.js +4 -4
  43. package/dist/dev/cart-hooks.js.map +1 -1
  44. package/dist/dev/cart-hooks.mjs +3 -3
  45. package/dist/dev/cart-hooks.mjs.map +1 -1
  46. package/dist/dev/index.js +2 -0
  47. package/dist/dev/index.js.map +1 -1
  48. package/dist/dev/index.mjs +2 -0
  49. package/dist/dev/index.mjs.map +1 -1
  50. package/dist/dev/load-script.js +3 -3
  51. package/dist/dev/load-script.js.map +1 -1
  52. package/dist/dev/metafield-parser.js +105 -0
  53. package/dist/dev/metafield-parser.js.map +1 -0
  54. package/dist/dev/metafield-parser.mjs +105 -0
  55. package/dist/dev/metafield-parser.mjs.map +1 -0
  56. package/dist/dev/node_modules/@xstate/fsm/es/index.js +158 -0
  57. package/dist/dev/node_modules/@xstate/fsm/es/index.js.map +1 -0
  58. package/dist/dev/node_modules/@xstate/fsm/es/index.mjs +159 -0
  59. package/dist/dev/node_modules/@xstate/fsm/es/index.mjs.map +1 -0
  60. package/dist/dev/node_modules/@xstate/react/es/fsm.js +94 -0
  61. package/dist/dev/node_modules/@xstate/react/es/fsm.js.map +1 -0
  62. package/dist/dev/node_modules/@xstate/react/es/fsm.mjs +94 -0
  63. package/dist/dev/node_modules/@xstate/react/es/fsm.mjs.map +1 -0
  64. package/dist/dev/node_modules/@xstate/react/es/useConstant.js +30 -0
  65. package/dist/dev/node_modules/@xstate/react/es/useConstant.js.map +1 -0
  66. package/dist/dev/node_modules/@xstate/react/es/useConstant.mjs +12 -0
  67. package/dist/dev/node_modules/@xstate/react/es/useConstant.mjs.map +1 -0
  68. package/dist/dev/node_modules/ts-expect/dist/index.js +13 -0
  69. package/dist/dev/node_modules/ts-expect/dist/index.js.map +1 -0
  70. package/dist/dev/node_modules/ts-expect/dist/index.mjs +15 -0
  71. package/dist/dev/node_modules/ts-expect/dist/index.mjs.map +1 -0
  72. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js +5 -0
  73. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js.map +1 -0
  74. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.mjs +6 -0
  75. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.mjs.map +1 -0
  76. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +107 -0
  77. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
  78. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs +105 -0
  79. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -0
  80. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +74 -0
  81. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
  82. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs +72 -0
  83. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -0
  84. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +138 -0
  85. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -0
  86. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs +136 -0
  87. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -0
  88. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +60 -0
  89. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -0
  90. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs +58 -0
  91. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -0
  92. package/dist/dev/node_modules/use-sync-external-store/shim/index.js +21 -0
  93. package/dist/dev/node_modules/use-sync-external-store/shim/index.js.map +1 -0
  94. package/dist/dev/node_modules/use-sync-external-store/shim/index.mjs +21 -0
  95. package/dist/dev/node_modules/use-sync-external-store/shim/index.mjs.map +1 -0
  96. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.js +12 -0
  97. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
  98. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.mjs +11 -0
  99. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.mjs.map +1 -0
  100. package/dist/dev/node_modules/worktop/cookie/index.js +27 -0
  101. package/dist/dev/node_modules/worktop/cookie/index.js.map +1 -0
  102. package/dist/dev/node_modules/worktop/cookie/index.mjs +27 -0
  103. package/dist/dev/node_modules/worktop/cookie/index.mjs.map +1 -0
  104. package/dist/dev/useCartAPIStateMachine.js +12 -12
  105. package/dist/dev/useCartAPIStateMachine.js.map +1 -1
  106. package/dist/dev/useCartAPIStateMachine.mjs +8 -8
  107. package/dist/dev/useCartAPIStateMachine.mjs.map +1 -1
  108. package/dist/dev/useCartActions.js +11 -11
  109. package/dist/dev/useCartActions.js.map +1 -1
  110. package/dist/dev/useMoney.js +5 -5
  111. package/dist/dev/useMoney.js.map +1 -1
  112. package/dist/prod/CartProvider.js +20 -20
  113. package/dist/prod/CartProvider.js.map +1 -1
  114. package/dist/prod/Metafield.js +2 -2
  115. package/dist/prod/Metafield.js.map +1 -1
  116. package/dist/prod/Metafield.mjs.map +1 -1
  117. package/dist/prod/ModelViewer.js +4 -4
  118. package/dist/prod/ModelViewer.js.map +1 -1
  119. package/dist/prod/ProductProvider.js +14 -14
  120. package/dist/prod/ProductProvider.js.map +1 -1
  121. package/dist/prod/ShopifyProvider.js +4 -4
  122. package/dist/prod/ShopifyProvider.js.map +1 -1
  123. package/dist/prod/Video.js +2 -2
  124. package/dist/prod/_virtual/index.js +5 -0
  125. package/dist/prod/_virtual/index.js.map +1 -0
  126. package/dist/prod/_virtual/index.mjs +5 -0
  127. package/dist/prod/_virtual/index.mjs.map +1 -0
  128. package/dist/prod/_virtual/index2.js +5 -0
  129. package/dist/prod/_virtual/index2.js.map +1 -0
  130. package/dist/prod/_virtual/index2.mjs +5 -0
  131. package/dist/prod/_virtual/index2.mjs.map +1 -0
  132. package/dist/prod/_virtual/use-sync-external-store-shim.development.js +5 -0
  133. package/dist/prod/_virtual/use-sync-external-store-shim.development.js.map +1 -0
  134. package/dist/prod/_virtual/use-sync-external-store-shim.development.mjs +5 -0
  135. package/dist/prod/_virtual/use-sync-external-store-shim.development.mjs.map +1 -0
  136. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.js +5 -0
  137. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.js.map +1 -0
  138. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.mjs +5 -0
  139. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.mjs.map +1 -0
  140. package/dist/prod/_virtual/with-selector.development.js +5 -0
  141. package/dist/prod/_virtual/with-selector.development.js.map +1 -0
  142. package/dist/prod/_virtual/with-selector.development.mjs +5 -0
  143. package/dist/prod/_virtual/with-selector.development.mjs.map +1 -0
  144. package/dist/prod/_virtual/with-selector.js +5 -0
  145. package/dist/prod/_virtual/with-selector.js.map +1 -0
  146. package/dist/prod/_virtual/with-selector.mjs +5 -0
  147. package/dist/prod/_virtual/with-selector.mjs.map +1 -0
  148. package/dist/prod/_virtual/with-selector.production.min.js +5 -0
  149. package/dist/prod/_virtual/with-selector.production.min.js.map +1 -0
  150. package/dist/prod/_virtual/with-selector.production.min.mjs +5 -0
  151. package/dist/prod/_virtual/with-selector.production.min.mjs.map +1 -0
  152. package/dist/prod/cart-hooks.js +4 -4
  153. package/dist/prod/cart-hooks.js.map +1 -1
  154. package/dist/prod/cart-hooks.mjs +3 -3
  155. package/dist/prod/cart-hooks.mjs.map +1 -1
  156. package/dist/prod/index.js +2 -0
  157. package/dist/prod/index.js.map +1 -1
  158. package/dist/prod/index.mjs +2 -0
  159. package/dist/prod/index.mjs.map +1 -1
  160. package/dist/prod/load-script.js +3 -3
  161. package/dist/prod/load-script.js.map +1 -1
  162. package/dist/prod/metafield-parser.js +116 -0
  163. package/dist/prod/metafield-parser.js.map +1 -0
  164. package/dist/prod/metafield-parser.mjs +116 -0
  165. package/dist/prod/metafield-parser.mjs.map +1 -0
  166. package/dist/prod/node_modules/@xstate/fsm/es/index.js +158 -0
  167. package/dist/prod/node_modules/@xstate/fsm/es/index.js.map +1 -0
  168. package/dist/prod/node_modules/@xstate/fsm/es/index.mjs +159 -0
  169. package/dist/prod/node_modules/@xstate/fsm/es/index.mjs.map +1 -0
  170. package/dist/prod/node_modules/@xstate/react/es/fsm.js +94 -0
  171. package/dist/prod/node_modules/@xstate/react/es/fsm.js.map +1 -0
  172. package/dist/prod/node_modules/@xstate/react/es/fsm.mjs +94 -0
  173. package/dist/prod/node_modules/@xstate/react/es/fsm.mjs.map +1 -0
  174. package/dist/prod/node_modules/@xstate/react/es/useConstant.js +30 -0
  175. package/dist/prod/node_modules/@xstate/react/es/useConstant.js.map +1 -0
  176. package/dist/prod/node_modules/@xstate/react/es/useConstant.mjs +12 -0
  177. package/dist/prod/node_modules/@xstate/react/es/useConstant.mjs.map +1 -0
  178. package/dist/prod/node_modules/ts-expect/dist/index.js +13 -0
  179. package/dist/prod/node_modules/ts-expect/dist/index.js.map +1 -0
  180. package/dist/prod/node_modules/ts-expect/dist/index.mjs +15 -0
  181. package/dist/prod/node_modules/ts-expect/dist/index.mjs.map +1 -0
  182. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js +5 -0
  183. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js.map +1 -0
  184. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.mjs +6 -0
  185. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.mjs.map +1 -0
  186. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +107 -0
  187. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
  188. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs +105 -0
  189. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -0
  190. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +74 -0
  191. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
  192. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs +72 -0
  193. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -0
  194. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +138 -0
  195. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -0
  196. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs +136 -0
  197. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -0
  198. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +60 -0
  199. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -0
  200. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs +58 -0
  201. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -0
  202. package/dist/prod/node_modules/use-sync-external-store/shim/index.js +21 -0
  203. package/dist/prod/node_modules/use-sync-external-store/shim/index.js.map +1 -0
  204. package/dist/prod/node_modules/use-sync-external-store/shim/index.mjs +21 -0
  205. package/dist/prod/node_modules/use-sync-external-store/shim/index.mjs.map +1 -0
  206. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.js +12 -0
  207. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
  208. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.mjs +11 -0
  209. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.mjs.map +1 -0
  210. package/dist/prod/node_modules/worktop/cookie/index.js +27 -0
  211. package/dist/prod/node_modules/worktop/cookie/index.js.map +1 -0
  212. package/dist/prod/node_modules/worktop/cookie/index.mjs +27 -0
  213. package/dist/prod/node_modules/worktop/cookie/index.mjs.map +1 -0
  214. package/dist/prod/useCartAPIStateMachine.js +12 -12
  215. package/dist/prod/useCartAPIStateMachine.js.map +1 -1
  216. package/dist/prod/useCartAPIStateMachine.mjs +8 -8
  217. package/dist/prod/useCartAPIStateMachine.mjs.map +1 -1
  218. package/dist/prod/useCartActions.js +11 -11
  219. package/dist/prod/useCartActions.js.map +1 -1
  220. package/dist/prod/useMoney.js +5 -5
  221. package/dist/prod/useMoney.js.map +1 -1
  222. package/dist/types/Metafield.d.ts +3 -0
  223. package/dist/types/index.d.cts +1 -0
  224. package/dist/types/index.d.ts +1 -0
  225. package/dist/types/metafield-parser.d.ts +222 -0
  226. package/dist/umd/hydrogen-react.dev.js +114 -0
  227. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  228. package/dist/umd/hydrogen-react.prod.js +17 -17
  229. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  230. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ModelViewer.js","sources":["../../src/ModelViewer.tsx"],"sourcesContent":["import {useState, useEffect, useCallback} from 'react';\nimport {useLoadScript} from './load-script.js';\nimport type {Model3d} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\nimport type {ModelViewerElement} from '@google/model-viewer/lib/model-viewer.js';\n\ntype PropsWeControl = 'src';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'model-viewer': PartialDeep<\n ModelViewerElement,\n {recurseIntoArrays: true}\n >;\n }\n }\n}\n\ntype ModelViewerProps = Omit<\n PartialDeep<JSX.IntrinsicElements['model-viewer'], {recurseIntoArrays: true}>,\n PropsWeControl\n> & {\n /** An object with fields that correspond to the Storefront API's [Model3D object](https://shopify.dev/api/storefront/latest/objects/model3d). */\n data: PartialDeep<Model3d, {recurseIntoArrays: true}>;\n /** The callback to invoke when the 'error' event is triggered. Refer to [error in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-error). */\n onError?: (event: Event) => void;\n /** The callback to invoke when the `load` event is triggered. Refer to [load in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-load). */\n onLoad?: (event: Event) => void;\n /** The callback to invoke when the 'preload' event is triggered. Refer to [preload in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-preload). */\n onPreload?: (event: Event) => void;\n /** The callback to invoke when the 'model-visibility' event is triggered. Refer to [model-visibility in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-modelVisibility). */\n onModelVisibility?: (event: Event) => void;\n /** The callback to invoke when the 'progress' event is triggered. Refer to [progress in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-progress). */\n onProgress?: (event: Event) => void;\n /** The callback to invoke when the 'ar-status' event is triggered. Refer to [ar-status in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-arStatus). */\n onArStatus?: (event: Event) => void;\n /** The callback to invoke when the 'ar-tracking' event is triggered. Refer to [ar-tracking in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-arTracking). */\n onArTracking?: (event: Event) => void;\n /** The callback to invoke when the 'quick-look-button-tapped' event is triggered. Refer to [quick-look-button-tapped in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-quickLookButtonTapped). */\n onQuickLookButtonTapped?: (event: Event) => void;\n /** The callback to invoke when the 'camera-change' event is triggered. Refer to [camera-change in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-stagingandcameras-events-cameraChange). */\n onCameraChange?: (event: Event) => void;\n /** The callback to invoke when the 'environment-change' event is triggered. Refer to [environment-change in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-lightingandenv-events-environmentChange). */\n onEnvironmentChange?: (event: Event) => void;\n /** The callback to invoke when the 'play' event is triggered. Refer to [play in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-animation-events-play). */\n onPlay?: (event: Event) => void;\n /** The callback to invoke when the 'pause' event is triggered. Refer to [pause in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-animation-events-pause). */\n onPause?: (event: Event) => void;\n /** The callback to invoke when the 'scene-graph-ready' event is triggered. Refer to [scene-graph-ready in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-scenegraph-events-sceneGraphReady). */\n onSceneGraphReady?: (event: Event) => void;\n};\n\n/**\n * The `ModelViewer` component renders a 3D model (with the `model-viewer` custom element) for\n * the Storefront API's [Model3d object](https://shopify.dev/api/storefront/reference/products/model3d).\n *\n * The `model-viewer` custom element is lazily downloaded through a dynamically-injected `<script type=\"module\">` tag when the `<ModelViewer />` component is rendered\n *\n * ModelViewer is using version `1.21.1` of the `@google/model-viewer` library.\n */\nexport function ModelViewer(props: ModelViewerProps) {\n const [modelViewer, setModelViewer] = useState<undefined | HTMLElement>(\n undefined\n );\n const callbackRef = useCallback((node: HTMLElement) => {\n setModelViewer(node);\n }, []);\n const {data, children, className, ...passthroughProps} = props;\n\n const modelViewerLoadedStatus = useLoadScript(\n 'https://unpkg.com/@google/model-viewer@v1.12.1/dist/model-viewer.min.js',\n {\n module: true,\n }\n );\n\n useEffect(() => {\n if (!modelViewer) {\n return;\n }\n if (passthroughProps.onError)\n modelViewer.addEventListener('error', passthroughProps.onError);\n if (passthroughProps.onLoad)\n modelViewer.addEventListener('load', passthroughProps.onLoad);\n if (passthroughProps.onPreload)\n modelViewer.addEventListener('preload', passthroughProps.onPreload);\n if (passthroughProps.onModelVisibility)\n modelViewer.addEventListener(\n 'model-visibility',\n passthroughProps.onModelVisibility\n );\n if (passthroughProps.onProgress)\n modelViewer.addEventListener('progress', passthroughProps.onProgress);\n if (passthroughProps.onArStatus)\n modelViewer.addEventListener('ar-status', passthroughProps.onArStatus);\n if (passthroughProps.onArTracking)\n modelViewer.addEventListener(\n 'ar-tracking',\n passthroughProps.onArTracking\n );\n if (passthroughProps.onQuickLookButtonTapped)\n modelViewer.addEventListener(\n 'quick-look-button-tapped',\n passthroughProps.onQuickLookButtonTapped\n );\n if (passthroughProps.onCameraChange)\n modelViewer.addEventListener(\n 'camera-change',\n passthroughProps.onCameraChange\n );\n if (passthroughProps.onEnvironmentChange)\n modelViewer.addEventListener(\n 'environment-change',\n passthroughProps.onEnvironmentChange\n );\n if (passthroughProps.onPlay)\n modelViewer.addEventListener('play', passthroughProps.onPlay);\n if (passthroughProps.onPause)\n modelViewer.addEventListener('ar-status', passthroughProps.onPause);\n if (passthroughProps.onSceneGraphReady)\n modelViewer.addEventListener(\n 'scene-graph-ready',\n passthroughProps.onSceneGraphReady\n );\n\n return () => {\n if (modelViewer == null) {\n return;\n }\n if (passthroughProps.onError)\n modelViewer.removeEventListener('error', passthroughProps.onError);\n if (passthroughProps.onLoad)\n modelViewer.removeEventListener('load', passthroughProps.onLoad);\n if (passthroughProps.onPreload)\n modelViewer.removeEventListener('preload', passthroughProps.onPreload);\n if (passthroughProps.onModelVisibility)\n modelViewer.removeEventListener(\n 'model-visibility',\n passthroughProps.onModelVisibility\n );\n if (passthroughProps.onProgress)\n modelViewer.removeEventListener(\n 'progress',\n passthroughProps.onProgress\n );\n if (passthroughProps.onArStatus)\n modelViewer.removeEventListener(\n 'ar-status',\n passthroughProps.onArStatus\n );\n if (passthroughProps.onArTracking)\n modelViewer.removeEventListener(\n 'ar-tracking',\n passthroughProps.onArTracking\n );\n if (passthroughProps.onQuickLookButtonTapped)\n modelViewer.removeEventListener(\n 'quick-look-button-tapped',\n passthroughProps.onQuickLookButtonTapped\n );\n if (passthroughProps.onCameraChange)\n modelViewer.removeEventListener(\n 'camera-change',\n passthroughProps.onCameraChange\n );\n if (passthroughProps.onEnvironmentChange)\n modelViewer.removeEventListener(\n 'environment-change',\n passthroughProps.onEnvironmentChange\n );\n if (passthroughProps.onPlay)\n modelViewer.removeEventListener('play', passthroughProps.onPlay);\n if (passthroughProps.onPause)\n modelViewer.removeEventListener('ar-status', passthroughProps.onPause);\n if (passthroughProps.onSceneGraphReady)\n modelViewer.removeEventListener(\n 'scene-graph-ready',\n passthroughProps.onSceneGraphReady\n );\n };\n }, [\n modelViewer,\n passthroughProps.onArStatus,\n passthroughProps.onArTracking,\n passthroughProps.onCameraChange,\n passthroughProps.onEnvironmentChange,\n passthroughProps.onError,\n passthroughProps.onLoad,\n passthroughProps.onModelVisibility,\n passthroughProps.onPause,\n passthroughProps.onPlay,\n passthroughProps.onPreload,\n passthroughProps.onProgress,\n passthroughProps.onQuickLookButtonTapped,\n passthroughProps.onSceneGraphReady,\n ]);\n\n if (modelViewerLoadedStatus !== 'done') {\n // TODO: What do we want to display while the model-viewer library loads?\n return null;\n }\n\n if (!data.sources?.[0]?.url) {\n const sourcesUrlError = `<ModelViewer/> requires 'data.sources' prop to be an array, with an object that has a property 'url' on it. Rendering 'null'`;\n if (__HYDROGEN_DEV__) {\n throw new Error(sourcesUrlError);\n } else {\n console.error(sourcesUrlError);\n return null;\n }\n }\n\n if (__HYDROGEN_DEV__ && !data.alt) {\n console.warn(\n `<ModelViewer/> requires the 'data.alt' prop for accessibility`\n );\n }\n\n return (\n <model-viewer\n // @ts-expect-error ref should exist\n ref={callbackRef}\n {...passthroughProps}\n className={className}\n id={passthroughProps.id ?? data.id}\n src={data.sources[0].url}\n alt={data.alt ?? null}\n camera-controls={passthroughProps.cameraControls ?? true}\n poster={(passthroughProps.poster || data.previewImage?.url) ?? null}\n autoplay={passthroughProps.autoplay ?? true}\n loading={passthroughProps.loading}\n reveal={passthroughProps.reveal}\n ar={passthroughProps.ar}\n ar-modes={passthroughProps.arModes}\n ar-scale={passthroughProps.arScale}\n // @ts-expect-error arPlacement should exist as a type, not sure why it doesn't. https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-attributes-arPlacement\n ar-placement={passthroughProps.arPlacement}\n ios-src={passthroughProps.iosSrc}\n touch-action={passthroughProps.touchAction}\n disable-zoom={passthroughProps.disableZoom}\n orbit-sensitivity={passthroughProps.orbitSensitivity}\n auto-rotate={passthroughProps.autoRotate}\n auto-rotate-delay={passthroughProps.autoRotateDelay}\n // @ts-expect-error rotationPerSecond should exist as a type, not sure why it doesn't. https://modelviewer.dev/docs/index.html#entrydocs-stagingandcameras-attributes-rotationPerSecond\n rotation-per-second={passthroughProps.rotationPerSecond}\n interaction-policy={passthroughProps.interactionPolicy}\n interaction-prompt={passthroughProps.interactionPrompt}\n interaction-prompt-style={passthroughProps.interactionPromptStyle}\n interaction-prompt-threshold={passthroughProps.interactionPromptThreshold}\n camera-orbit={passthroughProps.cameraOrbit}\n camera-target={passthroughProps.cameraTarget}\n field-of-view={passthroughProps.fieldOfView}\n max-camera-orbit={passthroughProps.maxCameraOrbit}\n min-camera-orbit={passthroughProps.minCameraOrbit}\n max-field-of-view={passthroughProps.maxFieldOfView}\n min-field-of-view={passthroughProps.minFieldOfView}\n bounds={passthroughProps.bounds}\n interpolation-decay={passthroughProps.interpolationDecay ?? 100}\n skybox-image={passthroughProps.skyboxImage}\n environment-image={passthroughProps.environmentImage}\n exposure={passthroughProps.exposure}\n shadow-intensity={passthroughProps.shadowIntensity ?? 0}\n shadow-softness={passthroughProps.shadowSoftness ?? 0}\n animation-name={passthroughProps.animationName}\n animation-crossfade-duration={passthroughProps.animationCrossfadeDuration}\n variant-name={passthroughProps.variantName}\n orientation={passthroughProps.orientation}\n scale={passthroughProps.scale}\n >\n {children}\n </model-viewer>\n );\n}\n"],"names":["ModelViewer","props","modelViewer","setModelViewer","useState","undefined","callbackRef","useCallback","node","data","children","className","passthroughProps","modelViewerLoadedStatus","useLoadScript","module","useEffect","onError","addEventListener","onLoad","onPreload","onModelVisibility","onProgress","onArStatus","onArTracking","onQuickLookButtonTapped","onCameraChange","onEnvironmentChange","onPlay","onPause","onSceneGraphReady","removeEventListener","sources","url","sourcesUrlError","Error","__HYDROGEN_DEV__","alt","console","warn","id","cameraControls","poster","previewImage","autoplay","loading","reveal","ar","arModes","arScale","arPlacement","iosSrc","touchAction","disableZoom","orbitSensitivity","autoRotate","autoRotateDelay","rotationPerSecond","interactionPolicy","interactionPrompt","interactionPromptStyle","interactionPromptThreshold","cameraOrbit","cameraTarget","fieldOfView","maxCameraOrbit","minCameraOrbit","maxFieldOfView","minFieldOfView","bounds","interpolationDecay","skyboxImage","environmentImage","exposure","shadowIntensity","shadowSoftness","animationName","animationCrossfadeDuration","variantName","orientation","scale"],"mappings":";;;;;AA8DO,SAASA,YAAYC,OAAyB;;AACnD,QAAM,CAACC,aAAaC,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AiB+C;AAAAA,IACrC,4BAA0B/C,iBAAiBgD;AAAAA,IAC3C,gCAA8BhD,iBAAiBiD;AAAAA,IAC/C,gBAAcjD,iBAAiBkD;AAAAA,IAC/B,iBAAelD,iBAAiBmD;AAAAA,IAChC,iBAAenD,iBAAiBoD;AAAAA,IAChC,oBAAkBpD,iBAAiBqD;AAAAA,IACnC,oBAAkBrD,iBAAiBsD;AAAAA,IACnC,qBAAmBtD,iBAAiBuD;AAAAA,IACpC,qBAAmBvD,iBAAiBwD;AAAAA,IACpC,QAAQxD,iBAAiByD;AAAAA,IACzB,wBAAqBzD,sBAAiB0D,uBAAjB1D,YAAuC;AAAA,IAC5D,gBAAcA,iBAAiB2D;AAAAA,IAC/B,qBAAmB3D,iBAAiB4D;AAAAA,IACpC,UAAU5D,iBAAiB6D;AAAAA,IAC3B,qBAAkB7D,sBAAiB8D,oBAAjB9D,YAAoC;AAAA,IACtD,oBAAiBA,sBAAiB+D,mBAAjB/D,YAAmC;AAAA,IACpD,kBAAgBA,iBAAiBgE;AAAAA,IACjC,gCAA8BhE,iBAAiBiE;AAAAA,IAC/C,gBAAcjE,iBAAiBkE;AAAAA,IAC/B,aAAalE,iBAAiBmE;AAAAA,IAC9B,OAAOnE,iBAAiBoE;AAAAA,IAhD1B;AAAA,EAAA,CADF;AAsDD;;"}
1
+ {"version":3,"file":"ModelViewer.js","sources":["../../src/ModelViewer.tsx"],"sourcesContent":["import {useState, useEffect, useCallback} from 'react';\nimport {useLoadScript} from './load-script.js';\nimport type {Model3d} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\nimport type {ModelViewerElement} from '@google/model-viewer/lib/model-viewer.js';\n\ntype PropsWeControl = 'src';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'model-viewer': PartialDeep<\n ModelViewerElement,\n {recurseIntoArrays: true}\n >;\n }\n }\n}\n\ntype ModelViewerProps = Omit<\n PartialDeep<JSX.IntrinsicElements['model-viewer'], {recurseIntoArrays: true}>,\n PropsWeControl\n> & {\n /** An object with fields that correspond to the Storefront API's [Model3D object](https://shopify.dev/api/storefront/latest/objects/model3d). */\n data: PartialDeep<Model3d, {recurseIntoArrays: true}>;\n /** The callback to invoke when the 'error' event is triggered. Refer to [error in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-error). */\n onError?: (event: Event) => void;\n /** The callback to invoke when the `load` event is triggered. Refer to [load in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-load). */\n onLoad?: (event: Event) => void;\n /** The callback to invoke when the 'preload' event is triggered. Refer to [preload in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-preload). */\n onPreload?: (event: Event) => void;\n /** The callback to invoke when the 'model-visibility' event is triggered. Refer to [model-visibility in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-modelVisibility). */\n onModelVisibility?: (event: Event) => void;\n /** The callback to invoke when the 'progress' event is triggered. Refer to [progress in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-progress). */\n onProgress?: (event: Event) => void;\n /** The callback to invoke when the 'ar-status' event is triggered. Refer to [ar-status in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-arStatus). */\n onArStatus?: (event: Event) => void;\n /** The callback to invoke when the 'ar-tracking' event is triggered. Refer to [ar-tracking in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-arTracking). */\n onArTracking?: (event: Event) => void;\n /** The callback to invoke when the 'quick-look-button-tapped' event is triggered. Refer to [quick-look-button-tapped in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-quickLookButtonTapped). */\n onQuickLookButtonTapped?: (event: Event) => void;\n /** The callback to invoke when the 'camera-change' event is triggered. Refer to [camera-change in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-stagingandcameras-events-cameraChange). */\n onCameraChange?: (event: Event) => void;\n /** The callback to invoke when the 'environment-change' event is triggered. Refer to [environment-change in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-lightingandenv-events-environmentChange). */\n onEnvironmentChange?: (event: Event) => void;\n /** The callback to invoke when the 'play' event is triggered. Refer to [play in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-animation-events-play). */\n onPlay?: (event: Event) => void;\n /** The callback to invoke when the 'pause' event is triggered. Refer to [pause in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-animation-events-pause). */\n onPause?: (event: Event) => void;\n /** The callback to invoke when the 'scene-graph-ready' event is triggered. Refer to [scene-graph-ready in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-scenegraph-events-sceneGraphReady). */\n onSceneGraphReady?: (event: Event) => void;\n};\n\n/**\n * The `ModelViewer` component renders a 3D model (with the `model-viewer` custom element) for\n * the Storefront API's [Model3d object](https://shopify.dev/api/storefront/reference/products/model3d).\n *\n * The `model-viewer` custom element is lazily downloaded through a dynamically-injected `<script type=\"module\">` tag when the `<ModelViewer />` component is rendered\n *\n * ModelViewer is using version `1.21.1` of the `@google/model-viewer` library.\n */\nexport function ModelViewer(props: ModelViewerProps) {\n const [modelViewer, setModelViewer] = useState<undefined | HTMLElement>(\n undefined\n );\n const callbackRef = useCallback((node: HTMLElement) => {\n setModelViewer(node);\n }, []);\n const {data, children, className, ...passthroughProps} = props;\n\n const modelViewerLoadedStatus = useLoadScript(\n 'https://unpkg.com/@google/model-viewer@v1.12.1/dist/model-viewer.min.js',\n {\n module: true,\n }\n );\n\n useEffect(() => {\n if (!modelViewer) {\n return;\n }\n if (passthroughProps.onError)\n modelViewer.addEventListener('error', passthroughProps.onError);\n if (passthroughProps.onLoad)\n modelViewer.addEventListener('load', passthroughProps.onLoad);\n if (passthroughProps.onPreload)\n modelViewer.addEventListener('preload', passthroughProps.onPreload);\n if (passthroughProps.onModelVisibility)\n modelViewer.addEventListener(\n 'model-visibility',\n passthroughProps.onModelVisibility\n );\n if (passthroughProps.onProgress)\n modelViewer.addEventListener('progress', passthroughProps.onProgress);\n if (passthroughProps.onArStatus)\n modelViewer.addEventListener('ar-status', passthroughProps.onArStatus);\n if (passthroughProps.onArTracking)\n modelViewer.addEventListener(\n 'ar-tracking',\n passthroughProps.onArTracking\n );\n if (passthroughProps.onQuickLookButtonTapped)\n modelViewer.addEventListener(\n 'quick-look-button-tapped',\n passthroughProps.onQuickLookButtonTapped\n );\n if (passthroughProps.onCameraChange)\n modelViewer.addEventListener(\n 'camera-change',\n passthroughProps.onCameraChange\n );\n if (passthroughProps.onEnvironmentChange)\n modelViewer.addEventListener(\n 'environment-change',\n passthroughProps.onEnvironmentChange\n );\n if (passthroughProps.onPlay)\n modelViewer.addEventListener('play', passthroughProps.onPlay);\n if (passthroughProps.onPause)\n modelViewer.addEventListener('ar-status', passthroughProps.onPause);\n if (passthroughProps.onSceneGraphReady)\n modelViewer.addEventListener(\n 'scene-graph-ready',\n passthroughProps.onSceneGraphReady\n );\n\n return () => {\n if (modelViewer == null) {\n return;\n }\n if (passthroughProps.onError)\n modelViewer.removeEventListener('error', passthroughProps.onError);\n if (passthroughProps.onLoad)\n modelViewer.removeEventListener('load', passthroughProps.onLoad);\n if (passthroughProps.onPreload)\n modelViewer.removeEventListener('preload', passthroughProps.onPreload);\n if (passthroughProps.onModelVisibility)\n modelViewer.removeEventListener(\n 'model-visibility',\n passthroughProps.onModelVisibility\n );\n if (passthroughProps.onProgress)\n modelViewer.removeEventListener(\n 'progress',\n passthroughProps.onProgress\n );\n if (passthroughProps.onArStatus)\n modelViewer.removeEventListener(\n 'ar-status',\n passthroughProps.onArStatus\n );\n if (passthroughProps.onArTracking)\n modelViewer.removeEventListener(\n 'ar-tracking',\n passthroughProps.onArTracking\n );\n if (passthroughProps.onQuickLookButtonTapped)\n modelViewer.removeEventListener(\n 'quick-look-button-tapped',\n passthroughProps.onQuickLookButtonTapped\n );\n if (passthroughProps.onCameraChange)\n modelViewer.removeEventListener(\n 'camera-change',\n passthroughProps.onCameraChange\n );\n if (passthroughProps.onEnvironmentChange)\n modelViewer.removeEventListener(\n 'environment-change',\n passthroughProps.onEnvironmentChange\n );\n if (passthroughProps.onPlay)\n modelViewer.removeEventListener('play', passthroughProps.onPlay);\n if (passthroughProps.onPause)\n modelViewer.removeEventListener('ar-status', passthroughProps.onPause);\n if (passthroughProps.onSceneGraphReady)\n modelViewer.removeEventListener(\n 'scene-graph-ready',\n passthroughProps.onSceneGraphReady\n );\n };\n }, [\n modelViewer,\n passthroughProps.onArStatus,\n passthroughProps.onArTracking,\n passthroughProps.onCameraChange,\n passthroughProps.onEnvironmentChange,\n passthroughProps.onError,\n passthroughProps.onLoad,\n passthroughProps.onModelVisibility,\n passthroughProps.onPause,\n passthroughProps.onPlay,\n passthroughProps.onPreload,\n passthroughProps.onProgress,\n passthroughProps.onQuickLookButtonTapped,\n passthroughProps.onSceneGraphReady,\n ]);\n\n if (modelViewerLoadedStatus !== 'done') {\n // TODO: What do we want to display while the model-viewer library loads?\n return null;\n }\n\n if (!data.sources?.[0]?.url) {\n const sourcesUrlError = `<ModelViewer/> requires 'data.sources' prop to be an array, with an object that has a property 'url' on it. Rendering 'null'`;\n if (__HYDROGEN_DEV__) {\n throw new Error(sourcesUrlError);\n } else {\n console.error(sourcesUrlError);\n return null;\n }\n }\n\n if (__HYDROGEN_DEV__ && !data.alt) {\n console.warn(\n `<ModelViewer/> requires the 'data.alt' prop for accessibility`\n );\n }\n\n return (\n <model-viewer\n // @ts-expect-error ref should exist\n ref={callbackRef}\n {...passthroughProps}\n className={className}\n id={passthroughProps.id ?? data.id}\n src={data.sources[0].url}\n alt={data.alt ?? null}\n camera-controls={passthroughProps.cameraControls ?? true}\n poster={(passthroughProps.poster || data.previewImage?.url) ?? null}\n autoplay={passthroughProps.autoplay ?? true}\n loading={passthroughProps.loading}\n reveal={passthroughProps.reveal}\n ar={passthroughProps.ar}\n ar-modes={passthroughProps.arModes}\n ar-scale={passthroughProps.arScale}\n // @ts-expect-error arPlacement should exist as a type, not sure why it doesn't. https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-attributes-arPlacement\n ar-placement={passthroughProps.arPlacement}\n ios-src={passthroughProps.iosSrc}\n touch-action={passthroughProps.touchAction}\n disable-zoom={passthroughProps.disableZoom}\n orbit-sensitivity={passthroughProps.orbitSensitivity}\n auto-rotate={passthroughProps.autoRotate}\n auto-rotate-delay={passthroughProps.autoRotateDelay}\n // @ts-expect-error rotationPerSecond should exist as a type, not sure why it doesn't. https://modelviewer.dev/docs/index.html#entrydocs-stagingandcameras-attributes-rotationPerSecond\n rotation-per-second={passthroughProps.rotationPerSecond}\n interaction-policy={passthroughProps.interactionPolicy}\n interaction-prompt={passthroughProps.interactionPrompt}\n interaction-prompt-style={passthroughProps.interactionPromptStyle}\n interaction-prompt-threshold={passthroughProps.interactionPromptThreshold}\n camera-orbit={passthroughProps.cameraOrbit}\n camera-target={passthroughProps.cameraTarget}\n field-of-view={passthroughProps.fieldOfView}\n max-camera-orbit={passthroughProps.maxCameraOrbit}\n min-camera-orbit={passthroughProps.minCameraOrbit}\n max-field-of-view={passthroughProps.maxFieldOfView}\n min-field-of-view={passthroughProps.minFieldOfView}\n bounds={passthroughProps.bounds}\n interpolation-decay={passthroughProps.interpolationDecay ?? 100}\n skybox-image={passthroughProps.skyboxImage}\n environment-image={passthroughProps.environmentImage}\n exposure={passthroughProps.exposure}\n shadow-intensity={passthroughProps.shadowIntensity ?? 0}\n shadow-softness={passthroughProps.shadowSoftness ?? 0}\n animation-name={passthroughProps.animationName}\n animation-crossfade-duration={passthroughProps.animationCrossfadeDuration}\n variant-name={passthroughProps.variantName}\n orientation={passthroughProps.orientation}\n scale={passthroughProps.scale}\n >\n {children}\n </model-viewer>\n );\n}\n"],"names":["ModelViewer","props","modelViewer","setModelViewer","useState","undefined","callbackRef","useCallback","node","data","children","className","passthroughProps","modelViewerLoadedStatus","useLoadScript","module","useEffect","onError","addEventListener","onLoad","onPreload","onModelVisibility","onProgress","onArStatus","onArTracking","onQuickLookButtonTapped","onCameraChange","onEnvironmentChange","onPlay","onPause","onSceneGraphReady","removeEventListener","sources","url","sourcesUrlError","Error","__HYDROGEN_DEV__","alt","console","warn","id","cameraControls","poster","previewImage","autoplay","loading","reveal","ar","arModes","arScale","arPlacement","iosSrc","touchAction","disableZoom","orbitSensitivity","autoRotate","autoRotateDelay","rotationPerSecond","interactionPolicy","interactionPrompt","interactionPromptStyle","interactionPromptThreshold","cameraOrbit","cameraTarget","fieldOfView","maxCameraOrbit","minCameraOrbit","maxFieldOfView","minFieldOfView","bounds","interpolationDecay","skyboxImage","environmentImage","exposure","shadowIntensity","shadowSoftness","animationName","animationCrossfadeDuration","variantName","orientation","scale"],"mappings":";;;;;AA8DO,SAASA,YAAYC,OAAyB;;AACnD,QAAM,CAACC,aAAaC,cAAd,IAAgCC,WAAAA,SACpCC,MAD4C;AAGxCC,QAAAA,cAAcC,uBAAY,CAACC,SAAsB;AACrDL,mBAAeK,IAAD;AAAA,EACf,GAAE,CAF4B,CAAA;AAGzB,QAAA;AAAA,IAACC;AAAAA,IAAMC;AAAAA,IAAUC;AAAAA,OAAcC;AAAAA,EAAoBX,IAAAA;AAEnDY,QAAAA,0BAA0BC,yBAC9B,2EACA;AAAA,IACEC,QAAQ;AAAA,EAAA,CAHiC;AAO7CC,aAAAA,UAAU,MAAM;AACd,QAAI,CAACd,aAAa;AAChB;AAAA,IACD;AACD,QAAIU,iBAAiBK;AACPC,kBAAAA,iBAAiB,SAASN,iBAAiBK,OAAvD;AACF,QAAIL,iBAAiBO;AACPD,kBAAAA,iBAAiB,QAAQN,iBAAiBO,MAAtD;AACF,QAAIP,iBAAiBQ;AACPF,kBAAAA,iBAAiB,WAAWN,iBAAiBQ,SAAzD;AACF,QAAIR,iBAAiBS;AACPH,kBAAAA,iBACV,oBACAN,iBAAiBS,iBAFnB;AAIF,QAAIT,iBAAiBU;AACP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AiBiE;AAAAA,IAC/C,gBAAcjE,iBAAiBkE;AAAAA,IAC/B,aAAalE,iBAAiBmE;AAAAA,IAC9B,OAAOnE,iBAAiBoE;AAAAA,IAhD1B;AAAA,EAAA,CADF;AAsDD;;"}
@@ -1,30 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const react = require("react");
3
+ const require$$0 = require("react");
4
4
  const flattenConnection = require("./flatten-connection.js");
5
5
  const jsxRuntime = require("react/jsx-runtime");
6
- const ProductOptionsContext = react.createContext(null);
6
+ const ProductOptionsContext = require$$0.createContext(null);
7
7
  function ProductProvider({
8
8
  children,
9
9
  data: product,
10
10
  initialVariantId: explicitVariantId
11
11
  }) {
12
- const variants = react.useMemo(() => {
12
+ const variants = require$$0.useMemo(() => {
13
13
  var _a;
14
14
  return flattenConnection.flattenConnection((_a = product.variants) != null ? _a : {});
15
15
  }, [product.variants]);
16
16
  if (!isProductVariantArray(variants)) {
17
17
  throw new Error(`<ProductProvider/> requires 'product.variants.nodes' or 'product.variants.edges'`);
18
18
  }
19
- const options = react.useMemo(() => getOptions(variants), [variants]);
20
- const [selectedVariant, setSelectedVariant] = react.useState(() => getVariantBasedOnIdProp(explicitVariantId, variants));
21
- const [selectedOptions, setSelectedOptions] = react.useState(() => getSelectedOptions(selectedVariant));
22
- react.useEffect(() => {
19
+ const options = require$$0.useMemo(() => getOptions(variants), [variants]);
20
+ const [selectedVariant, setSelectedVariant] = require$$0.useState(() => getVariantBasedOnIdProp(explicitVariantId, variants));
21
+ const [selectedOptions, setSelectedOptions] = require$$0.useState(() => getSelectedOptions(selectedVariant));
22
+ require$$0.useEffect(() => {
23
23
  const newSelectedVariant = getVariantBasedOnIdProp(explicitVariantId, variants);
24
24
  setSelectedVariant(newSelectedVariant);
25
25
  setSelectedOptions(getSelectedOptions(newSelectedVariant));
26
26
  }, [explicitVariantId, variants]);
27
- const setSelectedOption = react.useCallback((name, value2) => {
27
+ const setSelectedOption = require$$0.useCallback((name, value2) => {
28
28
  setSelectedOptions((selectedOptions2) => {
29
29
  const opts = {
30
30
  ...selectedOptions2,
@@ -34,7 +34,7 @@ function ProductProvider({
34
34
  return opts;
35
35
  });
36
36
  }, [setSelectedOptions, variants]);
37
- const isOptionInStock = react.useCallback((option, value2) => {
37
+ const isOptionInStock = require$$0.useCallback((option, value2) => {
38
38
  var _a;
39
39
  const proposedVariant = getSelectedVariant(variants, {
40
40
  ...selectedOptions,
@@ -44,7 +44,7 @@ function ProductProvider({
44
44
  });
45
45
  return (_a = proposedVariant == null ? void 0 : proposedVariant.availableForSale) != null ? _a : true;
46
46
  }, [selectedOptions, variants]);
47
- const sellingPlanGroups = react.useMemo(() => {
47
+ const sellingPlanGroups = require$$0.useMemo(() => {
48
48
  var _a;
49
49
  return flattenConnection.flattenConnection((_a = product.sellingPlanGroups) != null ? _a : {}).map((sellingPlanGroup) => {
50
50
  var _a2;
@@ -54,8 +54,8 @@ function ProductProvider({
54
54
  };
55
55
  });
56
56
  }, [product.sellingPlanGroups]);
57
- const [selectedSellingPlan, setSelectedSellingPlan] = react.useState(void 0);
58
- const selectedSellingPlanAllocation = react.useMemo(() => {
57
+ const [selectedSellingPlan, setSelectedSellingPlan] = require$$0.useState(void 0);
58
+ const selectedSellingPlanAllocation = require$$0.useMemo(() => {
59
59
  var _a, _b;
60
60
  if (!selectedVariant || !selectedSellingPlan) {
61
61
  return;
@@ -68,7 +68,7 @@ function ProductProvider({
68
68
  return ((_a2 = allocation == null ? void 0 : allocation.sellingPlan) == null ? void 0 : _a2.id) === selectedSellingPlan.id;
69
69
  });
70
70
  }, [selectedVariant, selectedSellingPlan]);
71
- const value = react.useMemo(() => ({
71
+ const value = require$$0.useMemo(() => ({
72
72
  variants,
73
73
  variantsConnection: product.variants,
74
74
  options,
@@ -90,7 +90,7 @@ function ProductProvider({
90
90
  });
91
91
  }
92
92
  function useProduct() {
93
- const context = react.useContext(ProductOptionsContext);
93
+ const context = require$$0.useContext(ProductOptionsContext);
94
94
  if (!context) {
95
95
  throw new Error(`'useProduct' must be a child of <ProductProvider />`);
96
96
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ProductProvider.js","sources":["../../src/ProductProvider.tsx"],"sourcesContent":["import {\n useMemo,\n useState,\n useEffect,\n useCallback,\n createContext,\n useContext,\n} from 'react';\nimport type {\n SelectedOption as SelectedOptionType,\n SellingPlan,\n SellingPlanAllocation,\n Product,\n ProductVariant as ProductVariantType,\n ProductVariantConnection,\n SellingPlan as SellingPlanType,\n SellingPlanAllocation as SellingPlanAllocationType,\n SellingPlanGroup as SellingPlanGroupType,\n SellingPlanGroupConnection,\n} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\nimport {flattenConnection} from './flatten-connection.js';\n\nconst ProductOptionsContext = createContext<ProductHookValue | null>(null);\n\ntype InitialVariantId = ProductVariantType['id'] | null;\n\ninterface ProductProviderProps {\n /** A [Product object](https://shopify.dev/api/storefront/reference/products/product). */\n data: PartialDeep<Product, {recurseIntoArrays: true}>;\n /** A `ReactNode` element. */\n children: React.ReactNode;\n /**\n * The initially selected variant.\n * The following logic applies to `initialVariantId`:\n * 1. If `initialVariantId` is provided, then it's used even if it's out of stock.\n * 2. If `initialVariantId` is provided but is `null`, then no variant is used.\n * 3. If nothing is passed to `initialVariantId` then the first available / in-stock variant is used.\n * 4. If nothing is passed to `initialVariantId` and no variants are in stock, then the first variant is used.\n */\n initialVariantId?: InitialVariantId;\n}\n\n/**\n * `<ProductProvider />` is a context provider that enables use of the `useProduct()` hook.\n *\n * It helps manage selected options and variants for a product.\n */\nexport function ProductProvider({\n children,\n data: product,\n initialVariantId: explicitVariantId,\n}: ProductProviderProps) {\n // The flattened variants\n const variants = useMemo(\n () => flattenConnection(product.variants ?? {}),\n [product.variants]\n );\n\n if (!isProductVariantArray(variants)) {\n throw new Error(\n `<ProductProvider/> requires 'product.variants.nodes' or 'product.variants.edges'`\n );\n }\n\n // All the options available for a product, based on all the variants\n const options = useMemo(() => getOptions(variants), [variants]);\n\n /**\n * Track the selectedVariant within the provider.\n */\n const [selectedVariant, setSelectedVariant] = useState<\n | PartialDeep<ProductVariantType, {recurseIntoArrays: true}>\n | undefined\n | null\n >(() => getVariantBasedOnIdProp(explicitVariantId, variants));\n\n /**\n * Track the selectedOptions within the provider. If a `initialVariantId`\n * is passed, use that to select initial options.\n */\n const [selectedOptions, setSelectedOptions] = useState<SelectedOptions>(() =>\n getSelectedOptions(selectedVariant)\n );\n\n /**\n * When the initialVariantId changes, we need to make sure we\n * update the selected variant and selected options. If not,\n * then the selected variant and options will reference incorrect\n * values.\n */\n useEffect(() => {\n const newSelectedVariant = getVariantBasedOnIdProp(\n explicitVariantId,\n variants\n );\n setSelectedVariant(newSelectedVariant);\n setSelectedOptions(getSelectedOptions(newSelectedVariant));\n }, [explicitVariantId, variants]);\n\n /**\n * Allow the developer to select an option.\n */\n const setSelectedOption = useCallback(\n (name: string, value: string) => {\n setSelectedOptions((selectedOptions) => {\n const opts = {...selectedOptions, [name]: value};\n setSelectedVariant(getSelectedVariant(variants, opts));\n return opts;\n });\n },\n [setSelectedOptions, variants]\n );\n\n const isOptionInStock = useCallback(\n (option: string, value: string) => {\n const proposedVariant = getSelectedVariant(variants, {\n ...selectedOptions,\n ...{[option]: value},\n });\n\n return proposedVariant?.availableForSale ?? true;\n },\n [selectedOptions, variants]\n );\n\n const sellingPlanGroups = useMemo(\n () =>\n flattenConnection(product.sellingPlanGroups ?? {}).map(\n (sellingPlanGroup) => ({\n ...sellingPlanGroup,\n sellingPlans: flattenConnection(sellingPlanGroup?.sellingPlans ?? {}),\n })\n ),\n [product.sellingPlanGroups]\n );\n\n /**\n * Track the selectedSellingPlan within the hook. If `initialSellingPlanId`\n * is passed, use that as an initial value. Look it up from the `selectedVariant`, since\n * that is also a requirement.\n */\n const [selectedSellingPlan, setSelectedSellingPlan] = useState<\n PartialDeep<SellingPlan, {recurseIntoArrays: true}> | undefined\n >(undefined);\n\n const selectedSellingPlanAllocation = useMemo<\n PartialDeep<SellingPlanAllocation, {recurseIntoArrays: true}> | undefined\n >(() => {\n if (!selectedVariant || !selectedSellingPlan) {\n return;\n }\n\n if (\n !selectedVariant.sellingPlanAllocations?.nodes &&\n !selectedVariant.sellingPlanAllocations?.edges\n ) {\n throw new Error(\n `<ProductProvider/>: You must include 'sellingPlanAllocations.nodes' or 'sellingPlanAllocations.edges' in your variants in order to calculate selectedSellingPlanAllocation`\n );\n }\n\n return flattenConnection(selectedVariant.sellingPlanAllocations).find(\n (allocation) => allocation?.sellingPlan?.id === selectedSellingPlan.id\n );\n }, [selectedVariant, selectedSellingPlan]);\n\n const value = useMemo<ProductHookValue>(\n () => ({\n variants,\n variantsConnection: product.variants,\n options,\n selectedVariant,\n setSelectedVariant,\n selectedOptions,\n setSelectedOption,\n setSelectedOptions,\n isOptionInStock,\n selectedSellingPlan,\n setSelectedSellingPlan,\n selectedSellingPlanAllocation,\n sellingPlanGroups,\n sellingPlanGroupsConnection: product.sellingPlanGroups,\n }),\n [\n isOptionInStock,\n options,\n product.sellingPlanGroups,\n product.variants,\n selectedOptions,\n selectedSellingPlan,\n selectedSellingPlanAllocation,\n selectedVariant,\n sellingPlanGroups,\n setSelectedOption,\n variants,\n ]\n );\n\n return (\n <ProductOptionsContext.Provider value={value}>\n {children}\n </ProductOptionsContext.Provider>\n );\n}\n\n/**\n * Provides access to the context value provided by `<ProductProvider />`. Must be a descendent of `<ProductProvider />`.\n */\nexport function useProduct() {\n const context = useContext(ProductOptionsContext);\n\n if (!context) {\n throw new Error(`'useProduct' must be a child of <ProductProvider />`);\n }\n\n return context;\n}\n\nfunction getSelectedVariant(\n variants: PartialDeep<ProductVariantType, {recurseIntoArrays: true}>[],\n choices: SelectedOptions\n): PartialDeep<ProductVariantType, {recurseIntoArrays: true}> | undefined {\n /**\n * Ensure the user has selected all the required options, not just some.\n */\n if (\n !variants.length ||\n variants?.[0]?.selectedOptions?.length !== Object.keys(choices).length\n ) {\n return;\n }\n\n return variants?.find((variant) => {\n return Object.entries(choices).every(([name, value]) => {\n return variant?.selectedOptions?.some(\n (option) => option?.name === name && option?.value === value\n );\n });\n });\n}\n\nfunction getOptions(\n variants: PartialDeep<ProductVariantType, {recurseIntoArrays: true}>[]\n): OptionWithValues[] {\n const map = variants.reduce((memo, variant) => {\n if (!variant.selectedOptions) {\n throw new Error(`'getOptions' requires 'variant.selectedOptions'`);\n }\n variant?.selectedOptions?.forEach((opt) => {\n memo[opt?.name ?? ''] = memo[opt?.name ?? ''] || new Set();\n memo[opt?.name ?? ''].add(opt?.value ?? '');\n });\n\n return memo;\n }, {} as Record<string, Set<string>>);\n\n return Object.keys(map).map((option) => {\n return {\n name: option,\n values: Array.from(map[option]),\n };\n });\n}\n\nfunction getVariantBasedOnIdProp(\n explicitVariantId: InitialVariantId | undefined,\n variants: Array<\n PartialDeep<ProductVariantType, {recurseIntoArrays: true}> | undefined\n >\n) {\n // get the initial variant based on the logic outlined in the comments for 'initialVariantId' above\n // * 1. If `initialVariantId` is provided, then it's used even if it's out of stock.\n if (explicitVariantId) {\n const foundVariant = variants.find(\n (variant) => variant?.id === explicitVariantId\n );\n if (!foundVariant) {\n console.warn(\n `<ProductProvider/> received a 'initialVariantId' prop, but could not actually find a variant with that ID`\n );\n }\n return foundVariant;\n }\n // * 2. If `initialVariantId` is provided but is `null`, then no variant is used.\n if (explicitVariantId === null) {\n return null;\n }\n // * 3. If nothing is passed to `initialVariantId` then the first available / in-stock variant is used.\n // * 4. If nothing is passed to `initialVariantId` and no variants are in stock, then the first variant is used.\n if (explicitVariantId === undefined) {\n return variants.find((variant) => variant?.availableForSale) || variants[0];\n }\n}\n\nfunction getSelectedOptions(\n selectedVariant:\n | PartialDeep<ProductVariantType, {recurseIntoArrays: true}>\n | undefined\n | null\n): SelectedOptions {\n return selectedVariant?.selectedOptions\n ? selectedVariant.selectedOptions.reduce<SelectedOptions>(\n (memo, optionSet) => {\n memo[optionSet?.name ?? ''] = optionSet?.value ?? '';\n return memo;\n },\n {}\n )\n : {};\n}\n\nfunction isProductVariantArray(\n maybeVariantArray:\n | (PartialDeep<ProductVariantType, {recurseIntoArrays: true}> | undefined)[]\n | undefined\n): maybeVariantArray is PartialDeep<\n ProductVariantType,\n {recurseIntoArrays: true}\n>[] {\n if (!maybeVariantArray || !Array.isArray(maybeVariantArray)) {\n return false;\n }\n\n return true;\n}\n\nexport interface OptionWithValues {\n name: SelectedOptionType['name'];\n values: SelectedOptionType['value'][];\n}\n\ntype ProductHookValue = PartialDeep<\n {\n /** An array of the variant `nodes` from the `VariantConnection`. */\n variants: ProductVariantType[];\n variantsConnection?: ProductVariantConnection;\n /** An array of the product's options and values. */\n options: OptionWithValues[];\n /** The selected variant. */\n selectedVariant?: ProductVariantType | null;\n selectedOptions: SelectedOptions;\n /** The selected selling plan. */\n selectedSellingPlan?: SellingPlanType;\n /** The selected selling plan allocation. */\n selectedSellingPlanAllocation?: SellingPlanAllocationType;\n /** The selling plan groups. */\n sellingPlanGroups?: (Omit<SellingPlanGroupType, 'sellingPlans'> & {\n sellingPlans: SellingPlanType[];\n })[];\n sellingPlanGroupsConnection?: SellingPlanGroupConnection;\n },\n {recurseIntoArrays: true}\n> & {\n /** A callback to set the selected variant to the variant passed as an argument. */\n setSelectedVariant: (\n variant: PartialDeep<ProductVariantType, {recurseIntoArrays: true}> | null\n ) => void;\n /** A callback to set the selected option. */\n setSelectedOption: (\n name: SelectedOptionType['name'],\n value: SelectedOptionType['value']\n ) => void;\n /** A callback to set multiple selected options at once. */\n setSelectedOptions: (options: SelectedOptions) => void;\n /** A callback to set the selected selling plan to the one passed as an argument. */\n setSelectedSellingPlan: (\n sellingPlan: PartialDeep<SellingPlanType, {recurseIntoArrays: true}>\n ) => void;\n /** A callback that returns a boolean indicating if the option is in stock. */\n isOptionInStock: (\n name: SelectedOptionType['name'],\n value: SelectedOptionType['value']\n ) => boolean;\n};\n\nexport type SelectedOptions = {\n [key: string]: string;\n};\n"],"names":["ProductOptionsContext","createContext","ProductProvider","children","data","product","initialVariantId","explicitVariantId","variants","useMemo","flattenConnection","isProductVariantArray","Error","options","getOptions","selectedVariant","setSelectedVariant","useState","getVariantBasedOnIdProp","selectedOptions","setSelectedOptions","getSelectedOptions","useEffect","newSelectedVariant","setSelectedOption","useCallback","name","value","opts","getSelectedVariant","isOptionInStock","option","proposedVariant","availableForSale","sellingPlanGroups","map","sellingPlanGroup","sellingPlans","selectedSellingPlan","setSelectedSellingPlan","undefined","selectedSellingPlanAllocation","sellingPlanAllocations","nodes","edges","find","allocation","sellingPlan","id","variantsConnection","sellingPlanGroupsConnection","_jsx","useProduct","context","useContext","choices","length","Object","keys","variant","entries","every","some","reduce","memo","forEach","opt","Set","add","values","Array","from","foundVariant","console","warn","optionSet","maybeVariantArray","isArray"],"mappings":";;;;;AAuBA,MAAMA,wBAAwBC,MAAAA,cAAuC,IAA1B;AAyBpC,SAASC,gBAAgB;AAAA,EAC9BC;AAAAA,EACAC,MAAMC;AAAAA,EACNC,kBAAkBC;AAHY,GAIP;AAEvB,QAAMC,WAAWC,MAAAA,QACf,MAAMC;;AAAAA,6BAAAA,mBAAkBL,aAAQG,aAARH,YAAoB,CAAA,CAArB;AAAA,KACvB,CAACA,QAAQG,QAAT,CAFsB;AAKpB,MAAA,CAACG,sBAAsBH,QAAD,GAAY;AAC9B,UAAA,IAAII,MACP,kFADG;AAAA,EAGP;AAGKC,QAAAA,UAAUJ,MAAAA,QAAQ,MAAMK,WAAWN,QAAD,GAAY,CAACA,QAAD,CAA7B;AAKjB,QAAA,CAACO,iBAAiBC,kBAAlB,IAAwCC,MAAAA,SAI5C,MAAMC,wBAAwBX,mBAAmBC,QAApB,CAJuB;AAUhD,QAAA,CAACW,iBAAiBC,kBAAlB,IAAwCH,eAA0B,MACtEI,mBAAmBN,eAAD,CADkC;AAUtDO,QAAAA,UAAU,MAAM;AACRC,UAAAA,qBAAqBL,wBACzBX,mBACAC,QAFgD;AAIlDQ,uBAAmBO,kBAAD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A,mDAAiBI,mBACpBJ,gBAAgBI,gBAAgB4C,OAC9B,CAACC,MAAMW,cAAc;;AACnBX,UAAKW,4CAAWjD,SAAXiD,YAAmB,OAAMA,4CAAWhD,UAAXgD,YAAoB;AAC3CX,WAAAA;AAAAA,EAAAA,GAET,CAAA,CALF,IAOA;AACL;AAED,SAASrD,sBACPiE,mBAME;AACF,MAAI,CAACA,qBAAqB,CAACN,MAAMO,QAAQD,iBAAd,GAAkC;AACpD,WAAA;AAAA,EACR;AAEM,SAAA;AACR;;;"}
1
+ {"version":3,"file":"ProductProvider.js","sources":["../../src/ProductProvider.tsx"],"sourcesContent":["import {\n useMemo,\n useState,\n useEffect,\n useCallback,\n createContext,\n useContext,\n} from 'react';\nimport type {\n SelectedOption as SelectedOptionType,\n SellingPlan,\n SellingPlanAllocation,\n Product,\n ProductVariant as ProductVariantType,\n ProductVariantConnection,\n SellingPlan as SellingPlanType,\n SellingPlanAllocation as SellingPlanAllocationType,\n SellingPlanGroup as SellingPlanGroupType,\n SellingPlanGroupConnection,\n} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\nimport {flattenConnection} from './flatten-connection.js';\n\nconst ProductOptionsContext = createContext<ProductHookValue | null>(null);\n\ntype InitialVariantId = ProductVariantType['id'] | null;\n\ninterface ProductProviderProps {\n /** A [Product object](https://shopify.dev/api/storefront/reference/products/product). */\n data: PartialDeep<Product, {recurseIntoArrays: true}>;\n /** A `ReactNode` element. */\n children: React.ReactNode;\n /**\n * The initially selected variant.\n * The following logic applies to `initialVariantId`:\n * 1. If `initialVariantId` is provided, then it's used even if it's out of stock.\n * 2. If `initialVariantId` is provided but is `null`, then no variant is used.\n * 3. If nothing is passed to `initialVariantId` then the first available / in-stock variant is used.\n * 4. If nothing is passed to `initialVariantId` and no variants are in stock, then the first variant is used.\n */\n initialVariantId?: InitialVariantId;\n}\n\n/**\n * `<ProductProvider />` is a context provider that enables use of the `useProduct()` hook.\n *\n * It helps manage selected options and variants for a product.\n */\nexport function ProductProvider({\n children,\n data: product,\n initialVariantId: explicitVariantId,\n}: ProductProviderProps) {\n // The flattened variants\n const variants = useMemo(\n () => flattenConnection(product.variants ?? {}),\n [product.variants]\n );\n\n if (!isProductVariantArray(variants)) {\n throw new Error(\n `<ProductProvider/> requires 'product.variants.nodes' or 'product.variants.edges'`\n );\n }\n\n // All the options available for a product, based on all the variants\n const options = useMemo(() => getOptions(variants), [variants]);\n\n /**\n * Track the selectedVariant within the provider.\n */\n const [selectedVariant, setSelectedVariant] = useState<\n | PartialDeep<ProductVariantType, {recurseIntoArrays: true}>\n | undefined\n | null\n >(() => getVariantBasedOnIdProp(explicitVariantId, variants));\n\n /**\n * Track the selectedOptions within the provider. If a `initialVariantId`\n * is passed, use that to select initial options.\n */\n const [selectedOptions, setSelectedOptions] = useState<SelectedOptions>(() =>\n getSelectedOptions(selectedVariant)\n );\n\n /**\n * When the initialVariantId changes, we need to make sure we\n * update the selected variant and selected options. If not,\n * then the selected variant and options will reference incorrect\n * values.\n */\n useEffect(() => {\n const newSelectedVariant = getVariantBasedOnIdProp(\n explicitVariantId,\n variants\n );\n setSelectedVariant(newSelectedVariant);\n setSelectedOptions(getSelectedOptions(newSelectedVariant));\n }, [explicitVariantId, variants]);\n\n /**\n * Allow the developer to select an option.\n */\n const setSelectedOption = useCallback(\n (name: string, value: string) => {\n setSelectedOptions((selectedOptions) => {\n const opts = {...selectedOptions, [name]: value};\n setSelectedVariant(getSelectedVariant(variants, opts));\n return opts;\n });\n },\n [setSelectedOptions, variants]\n );\n\n const isOptionInStock = useCallback(\n (option: string, value: string) => {\n const proposedVariant = getSelectedVariant(variants, {\n ...selectedOptions,\n ...{[option]: value},\n });\n\n return proposedVariant?.availableForSale ?? true;\n },\n [selectedOptions, variants]\n );\n\n const sellingPlanGroups = useMemo(\n () =>\n flattenConnection(product.sellingPlanGroups ?? {}).map(\n (sellingPlanGroup) => ({\n ...sellingPlanGroup,\n sellingPlans: flattenConnection(sellingPlanGroup?.sellingPlans ?? {}),\n })\n ),\n [product.sellingPlanGroups]\n );\n\n /**\n * Track the selectedSellingPlan within the hook. If `initialSellingPlanId`\n * is passed, use that as an initial value. Look it up from the `selectedVariant`, since\n * that is also a requirement.\n */\n const [selectedSellingPlan, setSelectedSellingPlan] = useState<\n PartialDeep<SellingPlan, {recurseIntoArrays: true}> | undefined\n >(undefined);\n\n const selectedSellingPlanAllocation = useMemo<\n PartialDeep<SellingPlanAllocation, {recurseIntoArrays: true}> | undefined\n >(() => {\n if (!selectedVariant || !selectedSellingPlan) {\n return;\n }\n\n if (\n !selectedVariant.sellingPlanAllocations?.nodes &&\n !selectedVariant.sellingPlanAllocations?.edges\n ) {\n throw new Error(\n `<ProductProvider/>: You must include 'sellingPlanAllocations.nodes' or 'sellingPlanAllocations.edges' in your variants in order to calculate selectedSellingPlanAllocation`\n );\n }\n\n return flattenConnection(selectedVariant.sellingPlanAllocations).find(\n (allocation) => allocation?.sellingPlan?.id === selectedSellingPlan.id\n );\n }, [selectedVariant, selectedSellingPlan]);\n\n const value = useMemo<ProductHookValue>(\n () => ({\n variants,\n variantsConnection: product.variants,\n options,\n selectedVariant,\n setSelectedVariant,\n selectedOptions,\n setSelectedOption,\n setSelectedOptions,\n isOptionInStock,\n selectedSellingPlan,\n setSelectedSellingPlan,\n selectedSellingPlanAllocation,\n sellingPlanGroups,\n sellingPlanGroupsConnection: product.sellingPlanGroups,\n }),\n [\n isOptionInStock,\n options,\n product.sellingPlanGroups,\n product.variants,\n selectedOptions,\n selectedSellingPlan,\n selectedSellingPlanAllocation,\n selectedVariant,\n sellingPlanGroups,\n setSelectedOption,\n variants,\n ]\n );\n\n return (\n <ProductOptionsContext.Provider value={value}>\n {children}\n </ProductOptionsContext.Provider>\n );\n}\n\n/**\n * Provides access to the context value provided by `<ProductProvider />`. Must be a descendent of `<ProductProvider />`.\n */\nexport function useProduct() {\n const context = useContext(ProductOptionsContext);\n\n if (!context) {\n throw new Error(`'useProduct' must be a child of <ProductProvider />`);\n }\n\n return context;\n}\n\nfunction getSelectedVariant(\n variants: PartialDeep<ProductVariantType, {recurseIntoArrays: true}>[],\n choices: SelectedOptions\n): PartialDeep<ProductVariantType, {recurseIntoArrays: true}> | undefined {\n /**\n * Ensure the user has selected all the required options, not just some.\n */\n if (\n !variants.length ||\n variants?.[0]?.selectedOptions?.length !== Object.keys(choices).length\n ) {\n return;\n }\n\n return variants?.find((variant) => {\n return Object.entries(choices).every(([name, value]) => {\n return variant?.selectedOptions?.some(\n (option) => option?.name === name && option?.value === value\n );\n });\n });\n}\n\nfunction getOptions(\n variants: PartialDeep<ProductVariantType, {recurseIntoArrays: true}>[]\n): OptionWithValues[] {\n const map = variants.reduce((memo, variant) => {\n if (!variant.selectedOptions) {\n throw new Error(`'getOptions' requires 'variant.selectedOptions'`);\n }\n variant?.selectedOptions?.forEach((opt) => {\n memo[opt?.name ?? ''] = memo[opt?.name ?? ''] || new Set();\n memo[opt?.name ?? ''].add(opt?.value ?? '');\n });\n\n return memo;\n }, {} as Record<string, Set<string>>);\n\n return Object.keys(map).map((option) => {\n return {\n name: option,\n values: Array.from(map[option]),\n };\n });\n}\n\nfunction getVariantBasedOnIdProp(\n explicitVariantId: InitialVariantId | undefined,\n variants: Array<\n PartialDeep<ProductVariantType, {recurseIntoArrays: true}> | undefined\n >\n) {\n // get the initial variant based on the logic outlined in the comments for 'initialVariantId' above\n // * 1. If `initialVariantId` is provided, then it's used even if it's out of stock.\n if (explicitVariantId) {\n const foundVariant = variants.find(\n (variant) => variant?.id === explicitVariantId\n );\n if (!foundVariant) {\n console.warn(\n `<ProductProvider/> received a 'initialVariantId' prop, but could not actually find a variant with that ID`\n );\n }\n return foundVariant;\n }\n // * 2. If `initialVariantId` is provided but is `null`, then no variant is used.\n if (explicitVariantId === null) {\n return null;\n }\n // * 3. If nothing is passed to `initialVariantId` then the first available / in-stock variant is used.\n // * 4. If nothing is passed to `initialVariantId` and no variants are in stock, then the first variant is used.\n if (explicitVariantId === undefined) {\n return variants.find((variant) => variant?.availableForSale) || variants[0];\n }\n}\n\nfunction getSelectedOptions(\n selectedVariant:\n | PartialDeep<ProductVariantType, {recurseIntoArrays: true}>\n | undefined\n | null\n): SelectedOptions {\n return selectedVariant?.selectedOptions\n ? selectedVariant.selectedOptions.reduce<SelectedOptions>(\n (memo, optionSet) => {\n memo[optionSet?.name ?? ''] = optionSet?.value ?? '';\n return memo;\n },\n {}\n )\n : {};\n}\n\nfunction isProductVariantArray(\n maybeVariantArray:\n | (PartialDeep<ProductVariantType, {recurseIntoArrays: true}> | undefined)[]\n | undefined\n): maybeVariantArray is PartialDeep<\n ProductVariantType,\n {recurseIntoArrays: true}\n>[] {\n if (!maybeVariantArray || !Array.isArray(maybeVariantArray)) {\n return false;\n }\n\n return true;\n}\n\nexport interface OptionWithValues {\n name: SelectedOptionType['name'];\n values: SelectedOptionType['value'][];\n}\n\ntype ProductHookValue = PartialDeep<\n {\n /** An array of the variant `nodes` from the `VariantConnection`. */\n variants: ProductVariantType[];\n variantsConnection?: ProductVariantConnection;\n /** An array of the product's options and values. */\n options: OptionWithValues[];\n /** The selected variant. */\n selectedVariant?: ProductVariantType | null;\n selectedOptions: SelectedOptions;\n /** The selected selling plan. */\n selectedSellingPlan?: SellingPlanType;\n /** The selected selling plan allocation. */\n selectedSellingPlanAllocation?: SellingPlanAllocationType;\n /** The selling plan groups. */\n sellingPlanGroups?: (Omit<SellingPlanGroupType, 'sellingPlans'> & {\n sellingPlans: SellingPlanType[];\n })[];\n sellingPlanGroupsConnection?: SellingPlanGroupConnection;\n },\n {recurseIntoArrays: true}\n> & {\n /** A callback to set the selected variant to the variant passed as an argument. */\n setSelectedVariant: (\n variant: PartialDeep<ProductVariantType, {recurseIntoArrays: true}> | null\n ) => void;\n /** A callback to set the selected option. */\n setSelectedOption: (\n name: SelectedOptionType['name'],\n value: SelectedOptionType['value']\n ) => void;\n /** A callback to set multiple selected options at once. */\n setSelectedOptions: (options: SelectedOptions) => void;\n /** A callback to set the selected selling plan to the one passed as an argument. */\n setSelectedSellingPlan: (\n sellingPlan: PartialDeep<SellingPlanType, {recurseIntoArrays: true}>\n ) => void;\n /** A callback that returns a boolean indicating if the option is in stock. */\n isOptionInStock: (\n name: SelectedOptionType['name'],\n value: SelectedOptionType['value']\n ) => boolean;\n};\n\nexport type SelectedOptions = {\n [key: string]: string;\n};\n"],"names":["ProductOptionsContext","createContext","ProductProvider","children","data","product","initialVariantId","explicitVariantId","variants","useMemo","flattenConnection","isProductVariantArray","Error","options","getOptions","selectedVariant","setSelectedVariant","useState","getVariantBasedOnIdProp","selectedOptions","setSelectedOptions","getSelectedOptions","useEffect","newSelectedVariant","setSelectedOption","useCallback","name","value","opts","getSelectedVariant","isOptionInStock","option","proposedVariant","availableForSale","sellingPlanGroups","map","sellingPlanGroup","sellingPlans","selectedSellingPlan","setSelectedSellingPlan","undefined","selectedSellingPlanAllocation","sellingPlanAllocations","nodes","edges","find","allocation","sellingPlan","id","variantsConnection","sellingPlanGroupsConnection","_jsx","useProduct","context","useContext","choices","length","Object","keys","variant","entries","every","some","reduce","memo","forEach","opt","Set","add","values","Array","from","foundVariant","console","warn","optionSet","maybeVariantArray","isArray"],"mappings":";;;;;AAuBA,MAAMA,wBAAwBC,WAAAA,cAAuC,IAA1B;AAyBpC,SAASC,gBAAgB;AAAA,EAC9BC;AAAAA,EACAC,MAAMC;AAAAA,EACNC,kBAAkBC;AAHY,GAIP;AAEvB,QAAMC,WAAWC,WAAAA,QACf,MAAMC;;AAAAA,6BAAAA,mBAAkBL,aAAQG,aAARH,YAAoB,CAAA,CAArB;AAAA,KACvB,CAACA,QAAQG,QAAT,CAFsB;AAKpB,MAAA,CAACG,sBAAsBH,QAAD,GAAY;AAC9B,UAAA,IAAII,MACP,kFADG;AAAA,EAGP;AAGKC,QAAAA,UAAUJ,WAAAA,QAAQ,MAAMK,WAAWN,QAAD,GAAY,CAACA,QAAD,CAA7B;AAKjB,QAAA,CAACO,iBAAiBC,kBAAlB,IAAwCC,WAAAA,SAI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A;AAAAA,EACR;AAED,MAAIjE,sBAAsB,MAAM;AACvB,WAAA;AAAA,EACR;AAGD,MAAIA,sBAAsBiC,QAAW;AACnC,WAAOhC,SAASqC,KAAMc,CAAAA,YAAYA,mCAAS1B,gBAApC,KAAyDzB,SAAS;AAAA,EAC1E;AACF;AAED,SAASa,mBACPN,iBAIiB;AACjB,UAAOA,mDAAiBI,mBACpBJ,gBAAgBI,gBAAgB4C,OAC9B,CAACC,MAAMW,cAAc;;AACnBX,UAAKW,4CAAWjD,SAAXiD,YAAmB,OAAMA,4CAAWhD,UAAXgD,YAAoB;AAC3CX,WAAAA;AAAAA,EAAAA,GAET,CAAA,CALF,IAOA;AACL;AAED,SAASrD,sBACPiE,mBAME;AACF,MAAI,CAACA,qBAAqB,CAACN,MAAMO,QAAQD,iBAAd,GAAkC;AACpD,WAAA;AAAA,EACR;AAEM,SAAA;AACR;;;"}
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const react = require("react");
3
+ const require$$0 = require("react");
4
4
  const storefrontApiConstants = require("./storefront-api-constants.js");
5
5
  const jsxRuntime = require("react/jsx-runtime");
6
- const ShopifyContext = react.createContext({
6
+ const ShopifyContext = require$$0.createContext({
7
7
  storeDomain: "test.myshopify.com",
8
8
  storefrontToken: "abc123",
9
9
  storefrontApiVersion: storefrontApiConstants.SFAPI_VERSION,
@@ -25,7 +25,7 @@ function ShopifyProvider({
25
25
  if (shopifyConfig.storefrontApiVersion !== storefrontApiConstants.SFAPI_VERSION) {
26
26
  console.warn(`This version of Hydrogen-UI is built for Shopify's Storefront API version ${storefrontApiConstants.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.`);
27
27
  }
28
- const finalConfig = react.useMemo(() => ({
28
+ const finalConfig = require$$0.useMemo(() => ({
29
29
  ...shopifyConfig,
30
30
  storeDomain: shopifyConfig.storeDomain.replace(/^https?:\/\//, "")
31
31
  }), [shopifyConfig]);
@@ -35,7 +35,7 @@ function ShopifyProvider({
35
35
  });
36
36
  }
37
37
  function useShop() {
38
- const shopContext = react.useContext(ShopifyContext);
38
+ const shopContext = require$$0.useContext(ShopifyContext);
39
39
  if (!shopContext) {
40
40
  throw new Error(`'useShop()' must be a descendent of <ShopifyProvider/>`);
41
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyProvider.js","sources":["../../src/ShopifyProvider.tsx"],"sourcesContent":["import {createContext, useContext, useMemo, type ReactNode} from 'react';\nimport type {LanguageCode, CountryCode, Shop} from './storefront-api-types.js';\nimport {SFAPI_VERSION} from './storefront-api-constants.js';\n\nconst ShopifyContext = createContext<ShopifyContextValue>({\n storeDomain: 'test.myshopify.com',\n storefrontToken: 'abc123',\n storefrontApiVersion: SFAPI_VERSION,\n country: {\n isoCode: 'US',\n },\n language: {\n isoCode: 'EN',\n },\n locale: 'EN-US',\n});\n\n/**\n * The `<ShopifyProvider/>` component enables use of the `useShop()` hook. The component should wrap your app.\n */\nexport function ShopifyProvider({\n children,\n shopifyConfig,\n}: {\n children: ReactNode;\n shopifyConfig: ShopifyContextValue;\n}) {\n if (!shopifyConfig) {\n throw new Error(\n `The 'shopifyConfig' prop must be passed to '<ShopifyProvider/>'`\n );\n }\n\n if (shopifyConfig.storefrontApiVersion !== SFAPI_VERSION) {\n console.warn(\n `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.`\n );\n }\n\n const finalConfig = useMemo<ShopifyContextValue>(\n () => ({\n ...shopifyConfig,\n storeDomain: shopifyConfig.storeDomain.replace(/^https?:\\/\\//, ''),\n }),\n [shopifyConfig]\n );\n\n return (\n <ShopifyContext.Provider value={finalConfig}>\n {children}\n </ShopifyContext.Provider>\n );\n}\n\n/**\n * Provides access to the `shopifyConfig` prop of `<ShopifyProvider/>`. Must be a descendent of `<ShopifyProvider/>`.\n */\nexport function useShop() {\n const shopContext = useContext(ShopifyContext);\n if (!shopContext) {\n throw new Error(`'useShop()' must be a descendent of <ShopifyProvider/>`);\n }\n return shopContext;\n}\n\n/**\n * Shopify-specific values that are used in various Hydrogen-UI components and hooks.\n */\nexport type ShopifyContextValue = {\n /** The globally-unique identifier for the Shop */\n storefrontId?: string;\n /** The host name of the domain (eg: `{shop}.myshopify.com`). If a URL with a scheme (for example `https://`) is passed in, then the scheme is removed. */\n storeDomain: Shop['primaryDomain']['host'];\n /** The Storefront API public access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */\n storefrontToken: string;\n /** The Storefront API version. This should almost always be the same as the version Hydrogen-UI was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. */\n storefrontApiVersion: string;\n country?: {\n /**\n * The code designating a country, which generally follows ISO 3166-1 alpha-2 guidelines. If a territory doesn't have a country code value in the `CountryCode` enum, it might be considered a subdivision of another country. For example, the territories associated with Spain are represented by the country code `ES`, and the territories associated with the United States of America are represented by the country code `US`.\n */\n isoCode: CountryCode;\n };\n language?: {\n /**\n * `ISO 369` language codes supported by Shopify.\n */\n isoCode: LanguageCode;\n };\n /**\n * The locale string based on `country` and `language`.\n */\n locale?: string;\n};\n"],"names":["ShopifyContext","createContext","storeDomain","storefrontToken","storefrontApiVersion","SFAPI_VERSION","country","isoCode","language","locale","ShopifyProvider","children","shopifyConfig","Error","console","warn","finalConfig","useMemo","replace","_jsx","useShop","shopContext","useContext"],"mappings":";;;;;AAIA,MAAMA,iBAAiBC,MAAAA,cAAmC;AAAA,EACxDC,aAAa;AAAA,EACbC,iBAAiB;AAAA,EACjBC,sBAAsBC,uBAAAA;AAAAA,EACtBC,SAAS;AAAA,IACPC,SAAS;AAAA,EADF;AAAA,EAGTC,UAAU;AAAA,IACRD,SAAS;AAAA,EADD;AAAA,EAGVE,QAAQ;AAVgD,CAAtB;AAgB7B,SAASC,gBAAgB;AAAA,EAC9BC;AAAAA,EACAC;AAF8B,GAM7B;AACD,MAAI,CAACA,eAAe;AACZ,UAAA,IAAIC,MACP,iEADG;AAAA,EAGP;AAEGD,MAAAA,cAAcR,yBAAyBC,sCAAe;AACxDS,YAAQC,KACL,6EAA4EV,uBAAyDO,yDAAAA,cAAcR,0HADtJ;AAAA,EAGD;AAEKY,QAAAA,cAAcC,MAAAA,QAClB,OAAO;AAAA,IACL,GAAGL;AAAAA,IACHV,aAAaU,cAAcV,YAAYgB,QAAQ,gBAAgB,EAAlD;AAAA,EAAA,IAEf,CAACN,aAAD,CALyB;AASzB,SAAAO,2BAAA,IAAC,eAAe,UAAhB;AAAA,IAAyB,OAAOH;AAAAA,IAAhC;AAAA,EAAA,CADF;AAKD;AAKM,SAASI,UAAU;AAClBC,QAAAA,cAAcC,iBAAWtB,cAAD;AAC9B,MAAI,CAACqB,aAAa;AACV,UAAA,IAAIR,MAAO,wDAAX;AAAA,EACP;AACMQ,SAAAA;AACR;;;"}
1
+ {"version":3,"file":"ShopifyProvider.js","sources":["../../src/ShopifyProvider.tsx"],"sourcesContent":["import {createContext, useContext, useMemo, type ReactNode} from 'react';\nimport type {LanguageCode, CountryCode, Shop} from './storefront-api-types.js';\nimport {SFAPI_VERSION} from './storefront-api-constants.js';\n\nconst ShopifyContext = createContext<ShopifyContextValue>({\n storeDomain: 'test.myshopify.com',\n storefrontToken: 'abc123',\n storefrontApiVersion: SFAPI_VERSION,\n country: {\n isoCode: 'US',\n },\n language: {\n isoCode: 'EN',\n },\n locale: 'EN-US',\n});\n\n/**\n * The `<ShopifyProvider/>` component enables use of the `useShop()` hook. The component should wrap your app.\n */\nexport function ShopifyProvider({\n children,\n shopifyConfig,\n}: {\n children: ReactNode;\n shopifyConfig: ShopifyContextValue;\n}) {\n if (!shopifyConfig) {\n throw new Error(\n `The 'shopifyConfig' prop must be passed to '<ShopifyProvider/>'`\n );\n }\n\n if (shopifyConfig.storefrontApiVersion !== SFAPI_VERSION) {\n console.warn(\n `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.`\n );\n }\n\n const finalConfig = useMemo<ShopifyContextValue>(\n () => ({\n ...shopifyConfig,\n storeDomain: shopifyConfig.storeDomain.replace(/^https?:\\/\\//, ''),\n }),\n [shopifyConfig]\n );\n\n return (\n <ShopifyContext.Provider value={finalConfig}>\n {children}\n </ShopifyContext.Provider>\n );\n}\n\n/**\n * Provides access to the `shopifyConfig` prop of `<ShopifyProvider/>`. Must be a descendent of `<ShopifyProvider/>`.\n */\nexport function useShop() {\n const shopContext = useContext(ShopifyContext);\n if (!shopContext) {\n throw new Error(`'useShop()' must be a descendent of <ShopifyProvider/>`);\n }\n return shopContext;\n}\n\n/**\n * Shopify-specific values that are used in various Hydrogen-UI components and hooks.\n */\nexport type ShopifyContextValue = {\n /** The globally-unique identifier for the Shop */\n storefrontId?: string;\n /** The host name of the domain (eg: `{shop}.myshopify.com`). If a URL with a scheme (for example `https://`) is passed in, then the scheme is removed. */\n storeDomain: Shop['primaryDomain']['host'];\n /** The Storefront API public access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */\n storefrontToken: string;\n /** The Storefront API version. This should almost always be the same as the version Hydrogen-UI was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. */\n storefrontApiVersion: string;\n country?: {\n /**\n * The code designating a country, which generally follows ISO 3166-1 alpha-2 guidelines. If a territory doesn't have a country code value in the `CountryCode` enum, it might be considered a subdivision of another country. For example, the territories associated with Spain are represented by the country code `ES`, and the territories associated with the United States of America are represented by the country code `US`.\n */\n isoCode: CountryCode;\n };\n language?: {\n /**\n * `ISO 369` language codes supported by Shopify.\n */\n isoCode: LanguageCode;\n };\n /**\n * The locale string based on `country` and `language`.\n */\n locale?: string;\n};\n"],"names":["ShopifyContext","createContext","storeDomain","storefrontToken","storefrontApiVersion","SFAPI_VERSION","country","isoCode","language","locale","ShopifyProvider","children","shopifyConfig","Error","console","warn","finalConfig","useMemo","replace","_jsx","useShop","shopContext","useContext"],"mappings":";;;;;AAIA,MAAMA,iBAAiBC,WAAAA,cAAmC;AAAA,EACxDC,aAAa;AAAA,EACbC,iBAAiB;AAAA,EACjBC,sBAAsBC,uBAAAA;AAAAA,EACtBC,SAAS;AAAA,IACPC,SAAS;AAAA,EADF;AAAA,EAGTC,UAAU;AAAA,IACRD,SAAS;AAAA,EADD;AAAA,EAGVE,QAAQ;AAVgD,CAAtB;AAgB7B,SAASC,gBAAgB;AAAA,EAC9BC;AAAAA,EACAC;AAF8B,GAM7B;AACD,MAAI,CAACA,eAAe;AACZ,UAAA,IAAIC,MACP,iEADG;AAAA,EAGP;AAEGD,MAAAA,cAAcR,yBAAyBC,sCAAe;AACxDS,YAAQC,KACL,6EAA4EV,uBAAyDO,yDAAAA,cAAcR,0HADtJ;AAAA,EAGD;AAEKY,QAAAA,cAAcC,WAAAA,QAClB,OAAO;AAAA,IACL,GAAGL;AAAAA,IACHV,aAAaU,cAAcV,YAAYgB,QAAQ,gBAAgB,EAAlD;AAAA,EAAA,IAEf,CAACN,aAAD,CALyB;AASzB,SAAAO,2BAAA,IAAC,eAAe,UAAhB;AAAA,IAAyB,OAAOH;AAAAA,IAAhC;AAAA,EAAA,CADF;AAKD;AAKM,SAASI,UAAU;AAClBC,QAAAA,cAAcC,sBAAWtB,cAAD;AAC9B,MAAI,CAACqB,aAAa;AACV,UAAA,IAAIR,MAAO,wDAAX;AAAA,EACP;AACMQ,SAAAA;AACR;;;"}
package/dist/dev/Video.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
3
  const imageSize = require("./image-size.js");
4
- const react = require("react");
4
+ const require$$0 = require("react");
5
5
  const jsxRuntime = require("react/jsx-runtime");
6
6
  function Video(props) {
7
7
  var _a, _b;
@@ -31,7 +31,7 @@ function Video(props) {
31
31
  if (!((source == null ? void 0 : source.url) && (source == null ? void 0 : source.mimeType))) {
32
32
  throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);
33
33
  }
34
- return /* @__PURE__ */ react.createElement("source", {
34
+ return /* @__PURE__ */ require$$0.createElement("source", {
35
35
  ...sourceProps,
36
36
  key: source.url,
37
37
  src: source.url,
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ var dist = {};
4
+ exports.__exports = dist;
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,5 @@
1
+ var dist = {};
2
+ export {
3
+ dist as __exports
4
+ };
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ var shim = { exports: {} };
4
+ exports.shim = shim;
5
+ //# sourceMappingURL=index2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,5 @@
1
+ var shim = { exports: {} };
2
+ export {
3
+ shim as s
4
+ };
5
+ //# sourceMappingURL=index2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index2.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ var useSyncExternalStoreShim_development = {};
4
+ exports.__exports = useSyncExternalStoreShim_development;
5
+ //# sourceMappingURL=use-sync-external-store-shim.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sync-external-store-shim.development.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,5 @@
1
+ var useSyncExternalStoreShim_development = {};
2
+ export {
3
+ useSyncExternalStoreShim_development as __exports
4
+ };
5
+ //# sourceMappingURL=use-sync-external-store-shim.development.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sync-external-store-shim.development.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ var useSyncExternalStoreShim_production_min = {};
4
+ exports.__exports = useSyncExternalStoreShim_production_min;
5
+ //# sourceMappingURL=use-sync-external-store-shim.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sync-external-store-shim.production.min.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,5 @@
1
+ var useSyncExternalStoreShim_production_min = {};
2
+ export {
3
+ useSyncExternalStoreShim_production_min as __exports
4
+ };
5
+ //# sourceMappingURL=use-sync-external-store-shim.production.min.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sync-external-store-shim.production.min.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ var withSelector_development = {};
4
+ exports.__exports = withSelector_development;
5
+ //# sourceMappingURL=with-selector.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-selector.development.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,5 @@
1
+ var withSelector_development = {};
2
+ export {
3
+ withSelector_development as __exports
4
+ };
5
+ //# sourceMappingURL=with-selector.development.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-selector.development.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ var withSelector = { exports: {} };
4
+ exports.withSelector = withSelector;
5
+ //# sourceMappingURL=with-selector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-selector.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,5 @@
1
+ var withSelector = { exports: {} };
2
+ export {
3
+ withSelector as w
4
+ };
5
+ //# sourceMappingURL=with-selector.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-selector.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ var withSelector_production_min = {};
4
+ exports.__exports = withSelector_production_min;
5
+ //# sourceMappingURL=with-selector.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-selector.production.min.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,5 @@
1
+ var withSelector_production_min = {};
2
+ export {
3
+ withSelector_production_min as __exports
4
+ };
5
+ //# sourceMappingURL=with-selector.production.min.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-selector.production.min.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const react = require("react");
3
+ const require$$0 = require("react");
4
4
  const ShopifyProvider = require("./ShopifyProvider.js");
5
5
  const cartConstants = require("./cart-constants.js");
6
- const cookie = require("worktop/cookie");
6
+ const index = require("./node_modules/worktop/cookie/index.js");
7
7
  function useCartFetch() {
8
8
  const {
9
9
  storeDomain,
@@ -11,7 +11,7 @@ function useCartFetch() {
11
11
  storefrontToken,
12
12
  storefrontId
13
13
  } = ShopifyProvider.useShop();
14
- return react.useCallback(({
14
+ return require$$0.useCallback(({
15
15
  query,
16
16
  variables
17
17
  }) => {
@@ -24,7 +24,7 @@ function useCartFetch() {
24
24
  if (storefrontId) {
25
25
  headers[cartConstants.SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;
26
26
  }
27
- const cookieData = cookie.parse(document.cookie);
27
+ const cookieData = index.parse(document.cookie);
28
28
  if (cookieData[cartConstants.SHOPIFY_Y] && cookieData[cartConstants.SHOPIFY_S]) {
29
29
  headers[cartConstants.SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[cartConstants.SHOPIFY_Y];
30
30
  headers[cartConstants.SHOPIFY_STOREFRONT_S_HEADER] = cookieData[cartConstants.SHOPIFY_S];
@@ -1 +1 @@
1
- {"version":3,"file":"cart-hooks.js","sources":["../../src/cart-hooks.tsx"],"sourcesContent":["import {useState, useCallback} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {flattenConnection} from './flatten-connection.js';\nimport {CartInput, Cart as CartType} from './storefront-api-types.js';\nimport {CartCreate, defaultCartFragment} from './cart-queries.js';\nimport {Cart} from './cart-types.js';\nimport {\n SHOPIFY_STOREFRONT_ID_HEADER,\n STOREFRONT_API_PUBLIC_TOKEN_HEADER,\n SHOPIFY_STOREFRONT_Y_HEADER,\n SHOPIFY_STOREFRONT_S_HEADER,\n SHOPIFY_Y,\n SHOPIFY_S,\n} from './cart-constants.js';\nimport {parse} from 'worktop/cookie';\nimport type {StorefrontApiResponseOkPartial} from './storefront-api-response.types.js';\n\nexport function useCartFetch() {\n const {storeDomain, storefrontApiVersion, storefrontToken, storefrontId} =\n useShop();\n\n return useCallback(\n <ReturnDataGeneric,>({\n query,\n variables,\n }: {\n query: string;\n variables: Record<string, unknown>;\n }): Promise<StorefrontApiResponseOkPartial<ReturnDataGeneric>> => {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-SDK-Variant': 'hydrogen',\n 'X-SDK-Version': storefrontApiVersion,\n [STOREFRONT_API_PUBLIC_TOKEN_HEADER]: storefrontToken,\n };\n\n if (storefrontId) {\n headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;\n }\n\n // Find Shopify cookies\n const cookieData = parse(document.cookie);\n if (cookieData[SHOPIFY_Y] && cookieData[SHOPIFY_S]) {\n headers[SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[SHOPIFY_Y];\n headers[SHOPIFY_STOREFRONT_S_HEADER] = cookieData[SHOPIFY_S];\n }\n\n return fetch(\n `https://${storeDomain}/api/${storefrontApiVersion}/graphql.json`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify({\n query: query.toString(),\n variables,\n }),\n }\n )\n .then((res) => res.json())\n .catch((error) => {\n return {\n data: undefined,\n errors: error.toString(),\n };\n });\n },\n [storeDomain, storefrontApiVersion, storefrontToken, storefrontId]\n );\n}\n\nexport function useInstantCheckout() {\n const [cart, updateCart] = useState<Cart | undefined>();\n const [checkoutUrl, updateCheckoutUrl] = useState<Cart['checkoutUrl']>();\n const [error, updateError] = useState<string | undefined>();\n\n const fetch = useCartFetch();\n\n const createInstantCheckout = useCallback(\n async (cartInput: CartInput) => {\n const {data, errors} = await fetch<{\n cartCreate: {cart: CartType};\n }>({\n query: CartCreate(defaultCartFragment),\n variables: {\n input: cartInput,\n },\n });\n\n if (errors) {\n updateError(errors.toString());\n updateCart(undefined);\n updateCheckoutUrl(undefined);\n }\n\n if (data?.cartCreate?.cart) {\n const dataCart = data.cartCreate.cart;\n updateCart({\n ...dataCart,\n lines: flattenConnection(dataCart.lines),\n note: dataCart.note ?? undefined,\n });\n updateCheckoutUrl(dataCart.checkoutUrl);\n }\n },\n [fetch]\n );\n\n return {cart, checkoutUrl, error, createInstantCheckout};\n}\n"],"names":["useCartFetch","storeDomain","storefrontApiVersion","storefrontToken","storefrontId","useShop","useCallback","query","variables","headers","STOREFRONT_API_PUBLIC_TOKEN_HEADER","SHOPIFY_STOREFRONT_ID_HEADER","cookieData","parse","document","cookie","SHOPIFY_Y","SHOPIFY_S","SHOPIFY_STOREFRONT_Y_HEADER","SHOPIFY_STOREFRONT_S_HEADER","fetch","method","body","JSON","stringify","toString","then","res","json","catch","error","data","undefined","errors"],"mappings":";;;;;;AAiBO,SAASA,eAAe;AACvB,QAAA;AAAA,IAACC;AAAAA,IAAaC;AAAAA,IAAsBC;AAAAA,IAAiBC;AAAAA,MACzDC,gBADF,QAAA;AAGA,SAAOC,kBACL,CAAqB;AAAA,IACnBC;AAAAA,IACAC;AAAAA,EAAAA,MAIgE;AAChE,UAAMC,UAAkC;AAAA,MACtC,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,iBAAiBP;AAAAA,MACjB,CAACQ,cAAqCP,qCAAAA;AAAAA,IAAAA;AAGxC,QAAIC,cAAc;AAChBK,cAAQE,cAAAA,gCAAgCP;AAAAA,IACzC;AAGKQ,UAAAA,aAAaC,OAAAA,MAAMC,SAASC,MAAV;AACpBH,QAAAA,WAAWI,cAAcJ,cAAAA,WAAWK,cAAY,YAAA;AAClDR,cAAQS,6CAA+BN,WAAWI,cAAAA;AAClDP,cAAQU,6CAA+BP,WAAWK,cAAAA;AAAAA,IACnD;AAEMG,WAAAA,MACJ,WAAUnB,mBAAmBC,qCAC9B;AAAA,MACEmB,QAAQ;AAAA,MACRZ;AAAAA,MACAa,MAAMC,KAAKC,UAAU;AAAA,QACnBjB,OAAOA,MAAMkB,SADM;AAAA,QAEnBjB;AAAAA,MAAAA,CAFI;AAAA,IAAA,CALE,EAWTkB,KAAMC,CAAAA,QAAQA,IAAIC,MAXd,EAYJC,MAAOC,CAAU,UAAA;AACT,aAAA;AAAA,QACLC,MAAMC;AAAAA,QACNC,QAAQH,MAAML,SAAN;AAAA,MAAA;AAAA,IAFH,CAbJ;AAAA,KAmBT,CAACxB,aAAaC,sBAAsBC,iBAAiBC,YAArD,CA7CgB;AA+CnB;;"}
1
+ {"version":3,"file":"cart-hooks.js","sources":["../../src/cart-hooks.tsx"],"sourcesContent":["import {useState, useCallback} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {flattenConnection} from './flatten-connection.js';\nimport {CartInput, Cart as CartType} from './storefront-api-types.js';\nimport {CartCreate, defaultCartFragment} from './cart-queries.js';\nimport {Cart} from './cart-types.js';\nimport {\n SHOPIFY_STOREFRONT_ID_HEADER,\n STOREFRONT_API_PUBLIC_TOKEN_HEADER,\n SHOPIFY_STOREFRONT_Y_HEADER,\n SHOPIFY_STOREFRONT_S_HEADER,\n SHOPIFY_Y,\n SHOPIFY_S,\n} from './cart-constants.js';\nimport {parse} from 'worktop/cookie';\nimport type {StorefrontApiResponseOkPartial} from './storefront-api-response.types.js';\n\nexport function useCartFetch() {\n const {storeDomain, storefrontApiVersion, storefrontToken, storefrontId} =\n useShop();\n\n return useCallback(\n <ReturnDataGeneric,>({\n query,\n variables,\n }: {\n query: string;\n variables: Record<string, unknown>;\n }): Promise<StorefrontApiResponseOkPartial<ReturnDataGeneric>> => {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-SDK-Variant': 'hydrogen',\n 'X-SDK-Version': storefrontApiVersion,\n [STOREFRONT_API_PUBLIC_TOKEN_HEADER]: storefrontToken,\n };\n\n if (storefrontId) {\n headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;\n }\n\n // Find Shopify cookies\n const cookieData = parse(document.cookie);\n if (cookieData[SHOPIFY_Y] && cookieData[SHOPIFY_S]) {\n headers[SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[SHOPIFY_Y];\n headers[SHOPIFY_STOREFRONT_S_HEADER] = cookieData[SHOPIFY_S];\n }\n\n return fetch(\n `https://${storeDomain}/api/${storefrontApiVersion}/graphql.json`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify({\n query: query.toString(),\n variables,\n }),\n }\n )\n .then((res) => res.json())\n .catch((error) => {\n return {\n data: undefined,\n errors: error.toString(),\n };\n });\n },\n [storeDomain, storefrontApiVersion, storefrontToken, storefrontId]\n );\n}\n\nexport function useInstantCheckout() {\n const [cart, updateCart] = useState<Cart | undefined>();\n const [checkoutUrl, updateCheckoutUrl] = useState<Cart['checkoutUrl']>();\n const [error, updateError] = useState<string | undefined>();\n\n const fetch = useCartFetch();\n\n const createInstantCheckout = useCallback(\n async (cartInput: CartInput) => {\n const {data, errors} = await fetch<{\n cartCreate: {cart: CartType};\n }>({\n query: CartCreate(defaultCartFragment),\n variables: {\n input: cartInput,\n },\n });\n\n if (errors) {\n updateError(errors.toString());\n updateCart(undefined);\n updateCheckoutUrl(undefined);\n }\n\n if (data?.cartCreate?.cart) {\n const dataCart = data.cartCreate.cart;\n updateCart({\n ...dataCart,\n lines: flattenConnection(dataCart.lines),\n note: dataCart.note ?? undefined,\n });\n updateCheckoutUrl(dataCart.checkoutUrl);\n }\n },\n [fetch]\n );\n\n return {cart, checkoutUrl, error, createInstantCheckout};\n}\n"],"names":["useCartFetch","storeDomain","storefrontApiVersion","storefrontToken","storefrontId","useShop","useCallback","query","variables","headers","STOREFRONT_API_PUBLIC_TOKEN_HEADER","SHOPIFY_STOREFRONT_ID_HEADER","cookieData","parse","document","cookie","SHOPIFY_Y","SHOPIFY_S","SHOPIFY_STOREFRONT_Y_HEADER","SHOPIFY_STOREFRONT_S_HEADER","fetch","method","body","JSON","stringify","toString","then","res","json","catch","error","data","undefined","errors"],"mappings":";;;;;;AAiBO,SAASA,eAAe;AACvB,QAAA;AAAA,IAACC;AAAAA,IAAaC;AAAAA,IAAsBC;AAAAA,IAAiBC;AAAAA,MACzDC,gBADF,QAAA;AAGA,SAAOC,uBACL,CAAqB;AAAA,IACnBC;AAAAA,IACAC;AAAAA,EAAAA,MAIgE;AAChE,UAAMC,UAAkC;AAAA,MACtC,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,iBAAiBP;AAAAA,MACjB,CAACQ,cAAqCP,qCAAAA;AAAAA,IAAAA;AAGxC,QAAIC,cAAc;AAChBK,cAAQE,cAAAA,gCAAgCP;AAAAA,IACzC;AAGKQ,UAAAA,aAAaC,MAAAA,MAAMC,SAASC,MAAV;AACpBH,QAAAA,WAAWI,cAAcJ,cAAAA,WAAWK,cAAY,YAAA;AAClDR,cAAQS,6CAA+BN,WAAWI,cAAAA;AAClDP,cAAQU,6CAA+BP,WAAWK,cAAAA;AAAAA,IACnD;AAEMG,WAAAA,MACJ,WAAUnB,mBAAmBC,qCAC9B;AAAA,MACEmB,QAAQ;AAAA,MACRZ;AAAAA,MACAa,MAAMC,KAAKC,UAAU;AAAA,QACnBjB,OAAOA,MAAMkB,SADM;AAAA,QAEnBjB;AAAAA,MAAAA,CAFI;AAAA,IAAA,CALE,EAWTkB,KAAMC,CAAAA,QAAQA,IAAIC,MAXd,EAYJC,MAAOC,CAAU,UAAA;AACT,aAAA;AAAA,QACLC,MAAMC;AAAAA,QACNC,QAAQH,MAAML,SAAN;AAAA,MAAA;AAAA,IAFH,CAbJ;AAAA,KAmBT,CAACxB,aAAaC,sBAAsBC,iBAAiBC,YAArD,CA7CgB;AA+CnB;;"}
@@ -1,7 +1,7 @@
1
1
  import { useCallback } from "react";
2
2
  import { useShop } from "./ShopifyProvider.mjs";
3
- import { SHOPIFY_Y, SHOPIFY_S, STOREFRONT_API_PUBLIC_TOKEN_HEADER, SHOPIFY_STOREFRONT_ID_HEADER, SHOPIFY_STOREFRONT_Y_HEADER, SHOPIFY_STOREFRONT_S_HEADER } from "./cart-constants.mjs";
4
- import { parse } from "worktop/cookie";
3
+ import { STOREFRONT_API_PUBLIC_TOKEN_HEADER, SHOPIFY_STOREFRONT_ID_HEADER, SHOPIFY_Y, SHOPIFY_S, SHOPIFY_STOREFRONT_Y_HEADER, SHOPIFY_STOREFRONT_S_HEADER } from "./cart-constants.mjs";
4
+ import { parse as u } from "./node_modules/worktop/cookie/index.mjs";
5
5
  function useCartFetch() {
6
6
  const {
7
7
  storeDomain,
@@ -22,7 +22,7 @@ function useCartFetch() {
22
22
  if (storefrontId) {
23
23
  headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;
24
24
  }
25
- const cookieData = parse(document.cookie);
25
+ const cookieData = u(document.cookie);
26
26
  if (cookieData[SHOPIFY_Y] && cookieData[SHOPIFY_S]) {
27
27
  headers[SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[SHOPIFY_Y];
28
28
  headers[SHOPIFY_STOREFRONT_S_HEADER] = cookieData[SHOPIFY_S];