@shopify/hydrogen-react 2023.10.1 → 2024.1.1

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 (175) hide show
  1. package/customer-account.schema.json +1 -0
  2. package/dist/browser-dev/CartProvider.mjs.map +1 -1
  3. package/dist/browser-dev/ExternalVideo.mjs +41 -34
  4. package/dist/browser-dev/ExternalVideo.mjs.map +1 -1
  5. package/dist/browser-dev/Image.mjs.map +1 -1
  6. package/dist/browser-dev/MediaFile.mjs.map +1 -1
  7. package/dist/browser-dev/ModelViewer.mjs +29 -94
  8. package/dist/browser-dev/ModelViewer.mjs.map +1 -1
  9. package/dist/browser-dev/Money.mjs.map +1 -1
  10. package/dist/browser-dev/Video.mjs +4 -3
  11. package/dist/browser-dev/Video.mjs.map +1 -1
  12. package/dist/browser-dev/codegen.helpers.mjs +9 -0
  13. package/dist/browser-dev/codegen.helpers.mjs.map +1 -1
  14. package/dist/browser-dev/index.mjs +2 -1
  15. package/dist/browser-dev/load-script.mjs +8 -15
  16. package/dist/browser-dev/load-script.mjs.map +1 -1
  17. package/dist/browser-dev/node_modules/@xstate/react/es/fsm.mjs +1 -1
  18. package/dist/browser-dev/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
  19. package/dist/browser-dev/node_modules/use-sync-external-store/shim/index.mjs +1 -1
  20. package/dist/browser-dev/node_modules/use-sync-external-store/shim/index.mjs.map +1 -1
  21. package/dist/browser-dev/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
  22. package/dist/browser-dev/node_modules/use-sync-external-store/shim/with-selector.mjs.map +1 -1
  23. package/dist/browser-dev/storefront-api-constants.mjs +1 -1
  24. package/dist/browser-dev/storefront-api-constants.mjs.map +1 -1
  25. package/dist/browser-dev/storefront-client.mjs.map +1 -1
  26. package/dist/browser-dev/useCartAPIStateMachine.mjs.map +1 -1
  27. package/dist/browser-dev/useCartActions.mjs.map +1 -1
  28. package/dist/browser-prod/CartProvider.mjs.map +1 -1
  29. package/dist/browser-prod/ExternalVideo.mjs +41 -34
  30. package/dist/browser-prod/ExternalVideo.mjs.map +1 -1
  31. package/dist/browser-prod/Image.mjs.map +1 -1
  32. package/dist/browser-prod/MediaFile.mjs.map +1 -1
  33. package/dist/browser-prod/ModelViewer.mjs +29 -94
  34. package/dist/browser-prod/ModelViewer.mjs.map +1 -1
  35. package/dist/browser-prod/Money.mjs.map +1 -1
  36. package/dist/browser-prod/Video.mjs +4 -3
  37. package/dist/browser-prod/Video.mjs.map +1 -1
  38. package/dist/browser-prod/codegen.helpers.mjs +9 -0
  39. package/dist/browser-prod/codegen.helpers.mjs.map +1 -1
  40. package/dist/browser-prod/index.mjs +2 -1
  41. package/dist/browser-prod/load-script.mjs +8 -15
  42. package/dist/browser-prod/load-script.mjs.map +1 -1
  43. package/dist/browser-prod/node_modules/@xstate/react/es/fsm.mjs +1 -1
  44. package/dist/browser-prod/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
  45. package/dist/browser-prod/node_modules/use-sync-external-store/shim/index.mjs +1 -1
  46. package/dist/browser-prod/node_modules/use-sync-external-store/shim/index.mjs.map +1 -1
  47. package/dist/browser-prod/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
  48. package/dist/browser-prod/node_modules/use-sync-external-store/shim/with-selector.mjs.map +1 -1
  49. package/dist/browser-prod/storefront-api-constants.mjs +1 -1
  50. package/dist/browser-prod/storefront-api-constants.mjs.map +1 -1
  51. package/dist/browser-prod/useCartAPIStateMachine.mjs.map +1 -1
  52. package/dist/browser-prod/useCartActions.mjs.map +1 -1
  53. package/dist/node-dev/CartProvider.js.map +1 -1
  54. package/dist/node-dev/CartProvider.mjs.map +1 -1
  55. package/dist/node-dev/ExternalVideo.js +41 -34
  56. package/dist/node-dev/ExternalVideo.js.map +1 -1
  57. package/dist/node-dev/ExternalVideo.mjs +41 -34
  58. package/dist/node-dev/ExternalVideo.mjs.map +1 -1
  59. package/dist/node-dev/Image.js.map +1 -1
  60. package/dist/node-dev/Image.mjs.map +1 -1
  61. package/dist/node-dev/MediaFile.js.map +1 -1
  62. package/dist/node-dev/MediaFile.mjs.map +1 -1
  63. package/dist/node-dev/ModelViewer.js +29 -94
  64. package/dist/node-dev/ModelViewer.js.map +1 -1
  65. package/dist/node-dev/ModelViewer.mjs +29 -94
  66. package/dist/node-dev/ModelViewer.mjs.map +1 -1
  67. package/dist/node-dev/Money.js.map +1 -1
  68. package/dist/node-dev/Money.mjs.map +1 -1
  69. package/dist/node-dev/Video.js +3 -2
  70. package/dist/node-dev/Video.js.map +1 -1
  71. package/dist/node-dev/Video.mjs +4 -3
  72. package/dist/node-dev/Video.mjs.map +1 -1
  73. package/dist/node-dev/codegen.helpers.js +9 -0
  74. package/dist/node-dev/codegen.helpers.js.map +1 -1
  75. package/dist/node-dev/codegen.helpers.mjs +9 -0
  76. package/dist/node-dev/codegen.helpers.mjs.map +1 -1
  77. package/dist/node-dev/index.js +1 -0
  78. package/dist/node-dev/index.js.map +1 -1
  79. package/dist/node-dev/index.mjs +2 -1
  80. package/dist/node-dev/load-script.js +8 -15
  81. package/dist/node-dev/load-script.js.map +1 -1
  82. package/dist/node-dev/load-script.mjs +8 -15
  83. package/dist/node-dev/load-script.mjs.map +1 -1
  84. package/dist/node-dev/node_modules/@xstate/react/es/fsm.js +1 -1
  85. package/dist/node-dev/node_modules/@xstate/react/es/fsm.js.map +1 -1
  86. package/dist/node-dev/node_modules/@xstate/react/es/fsm.mjs +1 -1
  87. package/dist/node-dev/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
  88. package/dist/node-dev/node_modules/use-sync-external-store/shim/index.js +1 -1
  89. package/dist/node-dev/node_modules/use-sync-external-store/shim/index.js.map +1 -1
  90. package/dist/node-dev/node_modules/use-sync-external-store/shim/index.mjs +1 -1
  91. package/dist/node-dev/node_modules/use-sync-external-store/shim/index.mjs.map +1 -1
  92. package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.js +1 -1
  93. package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -1
  94. package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
  95. package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.mjs.map +1 -1
  96. package/dist/node-dev/storefront-api-constants.js +1 -1
  97. package/dist/node-dev/storefront-api-constants.js.map +1 -1
  98. package/dist/node-dev/storefront-api-constants.mjs +1 -1
  99. package/dist/node-dev/storefront-api-constants.mjs.map +1 -1
  100. package/dist/node-dev/storefront-client.js.map +1 -1
  101. package/dist/node-dev/storefront-client.mjs.map +1 -1
  102. package/dist/node-dev/useCartAPIStateMachine.js.map +1 -1
  103. package/dist/node-dev/useCartAPIStateMachine.mjs.map +1 -1
  104. package/dist/node-dev/useCartActions.js.map +1 -1
  105. package/dist/node-dev/useCartActions.mjs.map +1 -1
  106. package/dist/node-prod/CartProvider.js.map +1 -1
  107. package/dist/node-prod/CartProvider.mjs.map +1 -1
  108. package/dist/node-prod/ExternalVideo.js +41 -34
  109. package/dist/node-prod/ExternalVideo.js.map +1 -1
  110. package/dist/node-prod/ExternalVideo.mjs +41 -34
  111. package/dist/node-prod/ExternalVideo.mjs.map +1 -1
  112. package/dist/node-prod/Image.js.map +1 -1
  113. package/dist/node-prod/Image.mjs.map +1 -1
  114. package/dist/node-prod/MediaFile.js.map +1 -1
  115. package/dist/node-prod/MediaFile.mjs.map +1 -1
  116. package/dist/node-prod/ModelViewer.js +29 -94
  117. package/dist/node-prod/ModelViewer.js.map +1 -1
  118. package/dist/node-prod/ModelViewer.mjs +29 -94
  119. package/dist/node-prod/ModelViewer.mjs.map +1 -1
  120. package/dist/node-prod/Money.js.map +1 -1
  121. package/dist/node-prod/Money.mjs.map +1 -1
  122. package/dist/node-prod/Video.js +3 -2
  123. package/dist/node-prod/Video.js.map +1 -1
  124. package/dist/node-prod/Video.mjs +4 -3
  125. package/dist/node-prod/Video.mjs.map +1 -1
  126. package/dist/node-prod/codegen.helpers.js +9 -0
  127. package/dist/node-prod/codegen.helpers.js.map +1 -1
  128. package/dist/node-prod/codegen.helpers.mjs +9 -0
  129. package/dist/node-prod/codegen.helpers.mjs.map +1 -1
  130. package/dist/node-prod/index.js +1 -0
  131. package/dist/node-prod/index.js.map +1 -1
  132. package/dist/node-prod/index.mjs +2 -1
  133. package/dist/node-prod/load-script.js +8 -15
  134. package/dist/node-prod/load-script.js.map +1 -1
  135. package/dist/node-prod/load-script.mjs +8 -15
  136. package/dist/node-prod/load-script.mjs.map +1 -1
  137. package/dist/node-prod/node_modules/@xstate/react/es/fsm.js +1 -1
  138. package/dist/node-prod/node_modules/@xstate/react/es/fsm.js.map +1 -1
  139. package/dist/node-prod/node_modules/@xstate/react/es/fsm.mjs +1 -1
  140. package/dist/node-prod/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
  141. package/dist/node-prod/node_modules/use-sync-external-store/shim/index.js +1 -1
  142. package/dist/node-prod/node_modules/use-sync-external-store/shim/index.js.map +1 -1
  143. package/dist/node-prod/node_modules/use-sync-external-store/shim/index.mjs +1 -1
  144. package/dist/node-prod/node_modules/use-sync-external-store/shim/index.mjs.map +1 -1
  145. package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.js +1 -1
  146. package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -1
  147. package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
  148. package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.mjs.map +1 -1
  149. package/dist/node-prod/storefront-api-constants.js +1 -1
  150. package/dist/node-prod/storefront-api-constants.js.map +1 -1
  151. package/dist/node-prod/storefront-api-constants.mjs +1 -1
  152. package/dist/node-prod/storefront-api-constants.mjs.map +1 -1
  153. package/dist/node-prod/useCartAPIStateMachine.js.map +1 -1
  154. package/dist/node-prod/useCartAPIStateMachine.mjs.map +1 -1
  155. package/dist/node-prod/useCartActions.js.map +1 -1
  156. package/dist/node-prod/useCartActions.mjs.map +1 -1
  157. package/dist/types/CartProvider.d.ts +2 -2
  158. package/dist/types/ExternalVideo.d.ts +3 -2
  159. package/dist/types/Image.d.ts +1 -1
  160. package/dist/types/ModelViewer.d.ts +1 -1
  161. package/dist/types/Money.d.ts +1 -1
  162. package/dist/types/Video.d.ts +2 -2
  163. package/dist/types/codegen.helpers.d.ts +14 -1
  164. package/dist/types/index.d.cts +1 -1
  165. package/dist/types/index.d.ts +1 -1
  166. package/dist/types/storefront-api-constants.d.ts +1 -1
  167. package/dist/types/storefront-api-types.d.ts +69 -19
  168. package/dist/types/useCartAPIStateMachine.d.ts +2 -2
  169. package/dist/types/useCartActions.d.ts +2 -2
  170. package/dist/umd/hydrogen-react.dev.js +92 -148
  171. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  172. package/dist/umd/hydrogen-react.prod.js +9 -9
  173. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  174. package/package.json +13 -10
  175. package/storefront.schema.json +1 -1
@@ -16,108 +16,43 @@ function ModelViewer(props) {
16
16
  module: true
17
17
  }
18
18
  );
19
+ const hydrogenEventListener = {
20
+ error: passthroughProps.onError,
21
+ load: passthroughProps.onLoad,
22
+ preload: passthroughProps.onPreload,
23
+ "model-visibility": passthroughProps.onModelVisibility,
24
+ progress: passthroughProps.onProgress,
25
+ "ar-status": passthroughProps.onArStatus,
26
+ "ar-tracking": passthroughProps.onArTracking,
27
+ "quick-look-button-tapped": passthroughProps.onQuickLookButtonTapped,
28
+ "camera-change": passthroughProps.onCameraChange,
29
+ "environment-change": passthroughProps.onEnvironmentChange,
30
+ play: passthroughProps.onPlay,
31
+ pause: passthroughProps.onPause,
32
+ "scene-graph-ready": passthroughProps.onSceneGraphReady
33
+ };
19
34
  useEffect(() => {
20
35
  if (!modelViewer) {
21
36
  return;
22
37
  }
23
- if (passthroughProps.onError)
24
- modelViewer.addEventListener("error", passthroughProps.onError);
25
- if (passthroughProps.onLoad)
26
- modelViewer.addEventListener("load", passthroughProps.onLoad);
27
- if (passthroughProps.onPreload)
28
- modelViewer.addEventListener("preload", passthroughProps.onPreload);
29
- if (passthroughProps.onModelVisibility)
30
- modelViewer.addEventListener(
31
- "model-visibility",
32
- passthroughProps.onModelVisibility
33
- );
34
- if (passthroughProps.onProgress)
35
- modelViewer.addEventListener("progress", passthroughProps.onProgress);
36
- if (passthroughProps.onArStatus)
37
- modelViewer.addEventListener("ar-status", passthroughProps.onArStatus);
38
- if (passthroughProps.onArTracking)
39
- modelViewer.addEventListener(
40
- "ar-tracking",
41
- passthroughProps.onArTracking
42
- );
43
- if (passthroughProps.onQuickLookButtonTapped)
44
- modelViewer.addEventListener(
45
- "quick-look-button-tapped",
46
- passthroughProps.onQuickLookButtonTapped
47
- );
48
- if (passthroughProps.onCameraChange)
49
- modelViewer.addEventListener(
50
- "camera-change",
51
- passthroughProps.onCameraChange
52
- );
53
- if (passthroughProps.onEnvironmentChange)
54
- modelViewer.addEventListener(
55
- "environment-change",
56
- passthroughProps.onEnvironmentChange
57
- );
58
- if (passthroughProps.onPlay)
59
- modelViewer.addEventListener("play", passthroughProps.onPlay);
60
- if (passthroughProps.onPause)
61
- modelViewer.addEventListener("ar-status", passthroughProps.onPause);
62
- if (passthroughProps.onSceneGraphReady)
63
- modelViewer.addEventListener(
64
- "scene-graph-ready",
65
- passthroughProps.onSceneGraphReady
66
- );
38
+ Object.entries(hydrogenEventListener).forEach(
39
+ ([eventName, callbackFunc]) => {
40
+ if (callbackFunc) {
41
+ modelViewer.addEventListener(eventName, callbackFunc);
42
+ }
43
+ }
44
+ );
67
45
  return () => {
68
46
  if (modelViewer == null) {
69
47
  return;
70
48
  }
71
- if (passthroughProps.onError)
72
- modelViewer.removeEventListener("error", passthroughProps.onError);
73
- if (passthroughProps.onLoad)
74
- modelViewer.removeEventListener("load", passthroughProps.onLoad);
75
- if (passthroughProps.onPreload)
76
- modelViewer.removeEventListener("preload", passthroughProps.onPreload);
77
- if (passthroughProps.onModelVisibility)
78
- modelViewer.removeEventListener(
79
- "model-visibility",
80
- passthroughProps.onModelVisibility
81
- );
82
- if (passthroughProps.onProgress)
83
- modelViewer.removeEventListener(
84
- "progress",
85
- passthroughProps.onProgress
86
- );
87
- if (passthroughProps.onArStatus)
88
- modelViewer.removeEventListener(
89
- "ar-status",
90
- passthroughProps.onArStatus
91
- );
92
- if (passthroughProps.onArTracking)
93
- modelViewer.removeEventListener(
94
- "ar-tracking",
95
- passthroughProps.onArTracking
96
- );
97
- if (passthroughProps.onQuickLookButtonTapped)
98
- modelViewer.removeEventListener(
99
- "quick-look-button-tapped",
100
- passthroughProps.onQuickLookButtonTapped
101
- );
102
- if (passthroughProps.onCameraChange)
103
- modelViewer.removeEventListener(
104
- "camera-change",
105
- passthroughProps.onCameraChange
106
- );
107
- if (passthroughProps.onEnvironmentChange)
108
- modelViewer.removeEventListener(
109
- "environment-change",
110
- passthroughProps.onEnvironmentChange
111
- );
112
- if (passthroughProps.onPlay)
113
- modelViewer.removeEventListener("play", passthroughProps.onPlay);
114
- if (passthroughProps.onPause)
115
- modelViewer.removeEventListener("ar-status", passthroughProps.onPause);
116
- if (passthroughProps.onSceneGraphReady)
117
- modelViewer.removeEventListener(
118
- "scene-graph-ready",
119
- passthroughProps.onSceneGraphReady
120
- );
49
+ Object.entries(hydrogenEventListener).forEach(
50
+ ([eventName, callbackFunc]) => {
51
+ if (callbackFunc) {
52
+ modelViewer.removeEventListener(eventName, callbackFunc);
53
+ }
54
+ }
55
+ );
121
56
  };
122
57
  }, [
123
58
  modelViewer,
@@ -1 +1 @@
1
- {"version":3,"file":"ModelViewer.mjs","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\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 'src'\n> &\n ModelViewerBaseProps;\n\ntype ModelViewerBaseProps = {\n /** An object with fields that correspond to the Storefront API's [Model3D object](https://shopify.dev/api/storefront/2023-10/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): JSX.Element | null {\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 ref={callbackRef}\n {...passthroughProps}\n // @ts-expect-error src should exist\n // @eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n class={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 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\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 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\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":[],"mappings":";;;AA+DO,SAAS,YAAY,OAA6C;;AACjE,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC;AAAA,EAAA;AAEI,QAAA,cAAc,YAAY,CAAC,SAAsB;AACrD,mBAAe,IAAI;AAAA,EACrB,GAAG,CAAE,CAAA;AACL,QAAM,EAAC,MAAM,UAAU,WAAW,GAAG,iBAAoB,IAAA;AAEzD,QAAM,0BAA0B;AAAA,IAC9B;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,IACV;AAAA,EAAA;AAGF,YAAU,MAAM;AACd,QAAI,CAAC,aAAa;AAChB;AAAA,IACF;AACA,QAAI,iBAAiB;AACP,kBAAA,iBAAiB,SAAS,iBAAiB,OAAO;AAChE,QAAI,iBAAiB;AACP,kBAAA,iBAAiB,QAAQ,iBAAiB,MAAM;AAC9D,QAAI,iBAAiB;AACP,kBAAA,iBAAiB,WAAW,iBAAiB,SAAS;AACpE,QAAI,iBAAiB;AACP,kBAAA;AAAA,QACV;AAAA,QACA,iBAAiB;AAAA,MAAA;AAErB,QAAI,iBAAiB;AACP,kBAAA,iBAAiB,YAAY,iBAAiB,UAAU;AACtE,QAAI,iBAAiB;AACP,kBAAA,iBAAiB,aAAa,iBAAiB,UAAU;AACvE,QAAI,iBAAiB;AACP,kBAAA;AAAA,QACV;AAAA,QACA,iBAAiB;AAAA,MAAA;AAErB,QAAI,iBAAiB;AACP,kBAAA;AAAA,QACV;AAAA,QACA,iBAAiB;AAAA,MAAA;AAErB,QAAI,iBAAiB;AACP,kBAAA;AAAA,QACV;AAAA,QACA,iBAAiB;AAAA,MAAA;AAErB,QAAI,iBAAiB;AACP,kBAAA;AAAA,QACV;AAAA,QACA,iBAAiB;AAAA,MAAA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tC,sBAAoB,iBAAiB;AAAA,MACrC,sBAAoB,iBAAiB;AAAA,MACrC,4BAA0B,iBAAiB;AAAA,MAC3C,gCAA8B,iBAAiB;AAAA,MAC/C,gBAAc,iBAAiB;AAAA,MAC/B,iBAAe,iBAAiB;AAAA,MAChC,iBAAe,iBAAiB;AAAA,MAChC,oBAAkB,iBAAiB;AAAA,MACnC,oBAAkB,iBAAiB;AAAA,MACnC,qBAAmB,iBAAiB;AAAA,MACpC,qBAAmB,iBAAiB;AAAA,MACpC,QAAQ,iBAAiB;AAAA,MACzB,uBAAqB,iBAAiB,sBAAsB;AAAA,MAC5D,gBAAc,iBAAiB;AAAA,MAC/B,qBAAmB,iBAAiB;AAAA,MACpC,UAAU,iBAAiB;AAAA,MAC3B,oBAAkB,iBAAiB,mBAAmB;AAAA,MACtD,mBAAiB,iBAAiB,kBAAkB;AAAA,MACpD,kBAAgB,iBAAiB;AAAA,MACjC,gCAA8B,iBAAiB;AAAA,MAC/C,gBAAc,iBAAiB;AAAA,MAC/B,aAAa,iBAAiB;AAAA,MAC9B,OAAO,iBAAiB;AAAA,MAEvB;AAAA,IAAA;AAAA,EAAA;AAGP;"}
1
+ {"version":3,"file":"ModelViewer.mjs","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\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 'src'\n> &\n ModelViewerBaseProps;\n\ntype ModelViewerBaseProps = {\n /** An object with fields that correspond to the Storefront API's [Model3D object](https://shopify.dev/api/storefront/2024-01/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): JSX.Element | null {\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 const hydrogenEventListener = {\n error: passthroughProps.onError,\n load: passthroughProps.onLoad,\n preload: passthroughProps.onPreload,\n 'model-visibility': passthroughProps.onModelVisibility,\n progress: passthroughProps.onProgress,\n 'ar-status': passthroughProps.onArStatus,\n 'ar-tracking': passthroughProps.onArTracking,\n 'quick-look-button-tapped': passthroughProps.onQuickLookButtonTapped,\n 'camera-change': passthroughProps.onCameraChange,\n 'environment-change': passthroughProps.onEnvironmentChange,\n play: passthroughProps.onPlay,\n pause: passthroughProps.onPause,\n 'scene-graph-ready': passthroughProps.onSceneGraphReady,\n };\n\n useEffect(() => {\n if (!modelViewer) {\n return;\n }\n Object.entries(hydrogenEventListener).forEach(\n ([eventName, callbackFunc]) => {\n if (callbackFunc) {\n modelViewer.addEventListener(eventName, callbackFunc);\n }\n },\n );\n\n return () => {\n if (modelViewer == null) {\n return;\n }\n Object.entries(hydrogenEventListener).forEach(\n ([eventName, callbackFunc]) => {\n if (callbackFunc) {\n modelViewer.removeEventListener(eventName, callbackFunc);\n }\n },\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 ref={callbackRef}\n {...passthroughProps}\n // @ts-expect-error src should exist\n // @eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n class={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 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\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 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\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}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,MAGpC,uBAAqB,iBAAiB;AAAA,MACtC,sBAAoB,iBAAiB;AAAA,MACrC,sBAAoB,iBAAiB;AAAA,MACrC,4BAA0B,iBAAiB;AAAA,MAC3C,gCAA8B,iBAAiB;AAAA,MAC/C,gBAAc,iBAAiB;AAAA,MAC/B,iBAAe,iBAAiB;AAAA,MAChC,iBAAe,iBAAiB;AAAA,MAChC,oBAAkB,iBAAiB;AAAA,MACnC,oBAAkB,iBAAiB;AAAA,MACnC,qBAAmB,iBAAiB;AAAA,MACpC,qBAAmB,iBAAiB;AAAA,MACpC,QAAQ,iBAAiB;AAAA,MACzB,uBAAqB,iBAAiB,sBAAsB;AAAA,MAC5D,gBAAc,iBAAiB;AAAA,MAC/B,qBAAmB,iBAAiB;AAAA,MACpC,UAAU,iBAAiB;AAAA,MAC3B,oBAAkB,iBAAiB,mBAAmB;AAAA,MACtD,mBAAiB,iBAAiB,kBAAkB;AAAA,MACpD,kBAAgB,iBAAiB;AAAA,MACjC,gCAA8B,iBAAiB;AAAA,MAC/C,gBAAc,iBAAiB;AAAA,MAC/B,aAAa,iBAAiB;AAAA,MAC9B,OAAO,iBAAiB;AAAA,MAEvB;AAAA,IAAA;AAAA,EAAA;AAGP;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Money.js","sources":["../../src/Money.tsx"],"sourcesContent":["import {type ReactNode} from 'react';\nimport {useMoney} from './useMoney.js';\nimport type {MoneyV2, UnitPriceMeasurement} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nexport interface MoneyPropsBase<ComponentGeneric extends React.ElementType> {\n /** An HTML tag or React Component to be rendered as the base element wrapper. The default is `div`. */\n as?: ComponentGeneric;\n /** An object with fields that correspond to the Storefront API's [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2). */\n data: PartialDeep<MoneyV2, {recurseIntoArrays: true}>;\n /** Whether to remove the currency symbol from the output. */\n withoutCurrency?: boolean;\n /** Whether to remove trailing zeros (fractional money) from the output. */\n withoutTrailingZeros?: boolean;\n /** A [UnitPriceMeasurement object](https://shopify.dev/api/storefront/2023-10/objects/unitpricemeasurement). */\n measurement?: PartialDeep<UnitPriceMeasurement, {recurseIntoArrays: true}>;\n /** Customizes the separator between the money output and the measurement output. Used with the `measurement` prop. Defaults to `'/'`. */\n measurementSeparator?: ReactNode;\n}\n\n// This article helps understand the typing here https://www.benmvp.com/blog/polymorphic-react-components-typescript/ Ben is the best :)\nexport type MoneyProps<ComponentGeneric extends React.ElementType> =\n MoneyPropsBase<ComponentGeneric> &\n (ComponentGeneric extends keyof React.JSX.IntrinsicElements\n ? Omit<\n React.ComponentPropsWithoutRef<ComponentGeneric>,\n keyof MoneyPropsBase<ComponentGeneric>\n >\n : React.ComponentPropsWithoutRef<ComponentGeneric>);\n\n/**\n * The `Money` component renders a string of the Storefront API's\n * [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2)\n * according to the `locale` in the `ShopifyProvider` component.\n * &nbsp;\n * @see {@link https://shopify.dev/api/hydrogen/components/money}\n * @example basic usage, outputs: $100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} />\n * ```\n * &nbsp;\n *\n * @example without currency, outputs: 100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutCurrency />\n * ```\n * &nbsp;\n *\n * @example without trailing zeros, outputs: $100\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutTrailingZeros />\n * ```\n * &nbsp;\n *\n * @example with per-unit measurement, outputs: $100.00 per G\n * ```ts\n * <Money\n * data={{amount: '100.00', currencyCode: 'USD'}}\n * measurement={{referenceUnit: 'G'}}\n * measurementSeparator=\" per \"\n * />\n * ```\n */\nexport function Money<ComponentGeneric extends React.ElementType = 'div'>({\n data,\n as,\n withoutCurrency,\n withoutTrailingZeros,\n measurement,\n measurementSeparator = '/',\n ...passthroughProps\n}: MoneyProps<ComponentGeneric>): JSX.Element {\n if (!isMoney(data)) {\n throw new Error(\n `<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`,\n );\n }\n const moneyObject = useMoney(data);\n const Wrapper = as ?? 'div';\n\n let output = moneyObject.localizedString;\n\n if (withoutCurrency || withoutTrailingZeros) {\n if (withoutCurrency && !withoutTrailingZeros) {\n output = moneyObject.amount;\n } else if (!withoutCurrency && withoutTrailingZeros) {\n output = moneyObject.withoutTrailingZeros;\n } else {\n // both\n output = moneyObject.withoutTrailingZerosAndCurrency;\n }\n }\n\n return (\n <Wrapper {...passthroughProps}>\n {output}\n {measurement && measurement.referenceUnit && (\n <>\n {measurementSeparator}\n {measurement.referenceUnit}\n </>\n )}\n </Wrapper>\n );\n}\n\n// required in order to narrow the money object down and make TS happy\nfunction isMoney(\n maybeMoney: PartialDeep<MoneyV2, {recurseIntoArrays: true}>,\n): maybeMoney is MoneyV2 {\n return (\n typeof maybeMoney.amount === 'string' &&\n !!maybeMoney.amount &&\n typeof maybeMoney.currencyCode === 'string' &&\n !!maybeMoney.currencyCode\n );\n}\n"],"names":["useMoney","jsxs","Fragment"],"mappings":";;;;AA+DO,SAAS,MAA0D;AAAA,EACxE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,uBAAuB;AAAA,EACvB,GAAG;AACL,GAA8C;AACxC,MAAA,CAAC,QAAQ,IAAI,GAAG;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACM,QAAA,cAAcA,kBAAS,IAAI;AACjC,QAAM,UAAU,MAAM;AAEtB,MAAI,SAAS,YAAY;AAEzB,MAAI,mBAAmB,sBAAsB;AACvC,QAAA,mBAAmB,CAAC,sBAAsB;AAC5C,eAAS,YAAY;AAAA,IAAA,WACZ,CAAC,mBAAmB,sBAAsB;AACnD,eAAS,YAAY;AAAA,IAAA,OAChB;AAEL,eAAS,YAAY;AAAA,IACvB;AAAA,EACF;AAGE,SAAAC,2BAAA,KAAC,SAAS,EAAA,GAAG,kBACV,UAAA;AAAA,IAAA;AAAA,IACA,eAAe,YAAY,iBAEvBA,2BAAA,KAAAC,WAAA,UAAA,EAAA,UAAA;AAAA,MAAA;AAAA,MACA,YAAY;AAAA,IAAA,GACf;AAAA,EAEJ,EAAA,CAAA;AAEJ;AAGA,SAAS,QACP,YACuB;AACvB,SACE,OAAO,WAAW,WAAW,YAC7B,CAAC,CAAC,WAAW,UACb,OAAO,WAAW,iBAAiB,YACnC,CAAC,CAAC,WAAW;AAEjB;;"}
1
+ {"version":3,"file":"Money.js","sources":["../../src/Money.tsx"],"sourcesContent":["import {type ReactNode} from 'react';\nimport {useMoney} from './useMoney.js';\nimport type {MoneyV2, UnitPriceMeasurement} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nexport interface MoneyPropsBase<ComponentGeneric extends React.ElementType> {\n /** An HTML tag or React Component to be rendered as the base element wrapper. The default is `div`. */\n as?: ComponentGeneric;\n /** An object with fields that correspond to the Storefront API's [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2). */\n data: PartialDeep<MoneyV2, {recurseIntoArrays: true}>;\n /** Whether to remove the currency symbol from the output. */\n withoutCurrency?: boolean;\n /** Whether to remove trailing zeros (fractional money) from the output. */\n withoutTrailingZeros?: boolean;\n /** A [UnitPriceMeasurement object](https://shopify.dev/api/storefront/2024-01/objects/unitpricemeasurement). */\n measurement?: PartialDeep<UnitPriceMeasurement, {recurseIntoArrays: true}>;\n /** Customizes the separator between the money output and the measurement output. Used with the `measurement` prop. Defaults to `'/'`. */\n measurementSeparator?: ReactNode;\n}\n\n// This article helps understand the typing here https://www.benmvp.com/blog/polymorphic-react-components-typescript/ Ben is the best :)\nexport type MoneyProps<ComponentGeneric extends React.ElementType> =\n MoneyPropsBase<ComponentGeneric> &\n (ComponentGeneric extends keyof React.JSX.IntrinsicElements\n ? Omit<\n React.ComponentPropsWithoutRef<ComponentGeneric>,\n keyof MoneyPropsBase<ComponentGeneric>\n >\n : React.ComponentPropsWithoutRef<ComponentGeneric>);\n\n/**\n * The `Money` component renders a string of the Storefront API's\n * [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2)\n * according to the `locale` in the `ShopifyProvider` component.\n * &nbsp;\n * @see {@link https://shopify.dev/api/hydrogen/components/money}\n * @example basic usage, outputs: $100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} />\n * ```\n * &nbsp;\n *\n * @example without currency, outputs: 100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutCurrency />\n * ```\n * &nbsp;\n *\n * @example without trailing zeros, outputs: $100\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutTrailingZeros />\n * ```\n * &nbsp;\n *\n * @example with per-unit measurement, outputs: $100.00 per G\n * ```ts\n * <Money\n * data={{amount: '100.00', currencyCode: 'USD'}}\n * measurement={{referenceUnit: 'G'}}\n * measurementSeparator=\" per \"\n * />\n * ```\n */\nexport function Money<ComponentGeneric extends React.ElementType = 'div'>({\n data,\n as,\n withoutCurrency,\n withoutTrailingZeros,\n measurement,\n measurementSeparator = '/',\n ...passthroughProps\n}: MoneyProps<ComponentGeneric>): JSX.Element {\n if (!isMoney(data)) {\n throw new Error(\n `<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`,\n );\n }\n const moneyObject = useMoney(data);\n const Wrapper = as ?? 'div';\n\n let output = moneyObject.localizedString;\n\n if (withoutCurrency || withoutTrailingZeros) {\n if (withoutCurrency && !withoutTrailingZeros) {\n output = moneyObject.amount;\n } else if (!withoutCurrency && withoutTrailingZeros) {\n output = moneyObject.withoutTrailingZeros;\n } else {\n // both\n output = moneyObject.withoutTrailingZerosAndCurrency;\n }\n }\n\n return (\n <Wrapper {...passthroughProps}>\n {output}\n {measurement && measurement.referenceUnit && (\n <>\n {measurementSeparator}\n {measurement.referenceUnit}\n </>\n )}\n </Wrapper>\n );\n}\n\n// required in order to narrow the money object down and make TS happy\nfunction isMoney(\n maybeMoney: PartialDeep<MoneyV2, {recurseIntoArrays: true}>,\n): maybeMoney is MoneyV2 {\n return (\n typeof maybeMoney.amount === 'string' &&\n !!maybeMoney.amount &&\n typeof maybeMoney.currencyCode === 'string' &&\n !!maybeMoney.currencyCode\n );\n}\n"],"names":["useMoney","jsxs","Fragment"],"mappings":";;;;AA+DO,SAAS,MAA0D;AAAA,EACxE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,uBAAuB;AAAA,EACvB,GAAG;AACL,GAA8C;AACxC,MAAA,CAAC,QAAQ,IAAI,GAAG;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACM,QAAA,cAAcA,kBAAS,IAAI;AACjC,QAAM,UAAU,MAAM;AAEtB,MAAI,SAAS,YAAY;AAEzB,MAAI,mBAAmB,sBAAsB;AACvC,QAAA,mBAAmB,CAAC,sBAAsB;AAC5C,eAAS,YAAY;AAAA,IAAA,WACZ,CAAC,mBAAmB,sBAAsB;AACnD,eAAS,YAAY;AAAA,IAAA,OAChB;AAEL,eAAS,YAAY;AAAA,IACvB;AAAA,EACF;AAGE,SAAAC,2BAAA,KAAC,SAAS,EAAA,GAAG,kBACV,UAAA;AAAA,IAAA;AAAA,IACA,eAAe,YAAY,iBAEvBA,2BAAA,KAAAC,WAAA,UAAA,EAAA,UAAA;AAAA,MAAA;AAAA,MACA,YAAY;AAAA,IAAA,GACf;AAAA,EAEJ,EAAA,CAAA;AAEJ;AAGA,SAAS,QACP,YACuB;AACvB,SACE,OAAO,WAAW,WAAW,YAC7B,CAAC,CAAC,WAAW,UACb,OAAO,WAAW,iBAAiB,YACnC,CAAC,CAAC,WAAW;AAEjB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Money.mjs","sources":["../../src/Money.tsx"],"sourcesContent":["import {type ReactNode} from 'react';\nimport {useMoney} from './useMoney.js';\nimport type {MoneyV2, UnitPriceMeasurement} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nexport interface MoneyPropsBase<ComponentGeneric extends React.ElementType> {\n /** An HTML tag or React Component to be rendered as the base element wrapper. The default is `div`. */\n as?: ComponentGeneric;\n /** An object with fields that correspond to the Storefront API's [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2). */\n data: PartialDeep<MoneyV2, {recurseIntoArrays: true}>;\n /** Whether to remove the currency symbol from the output. */\n withoutCurrency?: boolean;\n /** Whether to remove trailing zeros (fractional money) from the output. */\n withoutTrailingZeros?: boolean;\n /** A [UnitPriceMeasurement object](https://shopify.dev/api/storefront/2023-10/objects/unitpricemeasurement). */\n measurement?: PartialDeep<UnitPriceMeasurement, {recurseIntoArrays: true}>;\n /** Customizes the separator between the money output and the measurement output. Used with the `measurement` prop. Defaults to `'/'`. */\n measurementSeparator?: ReactNode;\n}\n\n// This article helps understand the typing here https://www.benmvp.com/blog/polymorphic-react-components-typescript/ Ben is the best :)\nexport type MoneyProps<ComponentGeneric extends React.ElementType> =\n MoneyPropsBase<ComponentGeneric> &\n (ComponentGeneric extends keyof React.JSX.IntrinsicElements\n ? Omit<\n React.ComponentPropsWithoutRef<ComponentGeneric>,\n keyof MoneyPropsBase<ComponentGeneric>\n >\n : React.ComponentPropsWithoutRef<ComponentGeneric>);\n\n/**\n * The `Money` component renders a string of the Storefront API's\n * [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2)\n * according to the `locale` in the `ShopifyProvider` component.\n * &nbsp;\n * @see {@link https://shopify.dev/api/hydrogen/components/money}\n * @example basic usage, outputs: $100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} />\n * ```\n * &nbsp;\n *\n * @example without currency, outputs: 100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutCurrency />\n * ```\n * &nbsp;\n *\n * @example without trailing zeros, outputs: $100\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutTrailingZeros />\n * ```\n * &nbsp;\n *\n * @example with per-unit measurement, outputs: $100.00 per G\n * ```ts\n * <Money\n * data={{amount: '100.00', currencyCode: 'USD'}}\n * measurement={{referenceUnit: 'G'}}\n * measurementSeparator=\" per \"\n * />\n * ```\n */\nexport function Money<ComponentGeneric extends React.ElementType = 'div'>({\n data,\n as,\n withoutCurrency,\n withoutTrailingZeros,\n measurement,\n measurementSeparator = '/',\n ...passthroughProps\n}: MoneyProps<ComponentGeneric>): JSX.Element {\n if (!isMoney(data)) {\n throw new Error(\n `<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`,\n );\n }\n const moneyObject = useMoney(data);\n const Wrapper = as ?? 'div';\n\n let output = moneyObject.localizedString;\n\n if (withoutCurrency || withoutTrailingZeros) {\n if (withoutCurrency && !withoutTrailingZeros) {\n output = moneyObject.amount;\n } else if (!withoutCurrency && withoutTrailingZeros) {\n output = moneyObject.withoutTrailingZeros;\n } else {\n // both\n output = moneyObject.withoutTrailingZerosAndCurrency;\n }\n }\n\n return (\n <Wrapper {...passthroughProps}>\n {output}\n {measurement && measurement.referenceUnit && (\n <>\n {measurementSeparator}\n {measurement.referenceUnit}\n </>\n )}\n </Wrapper>\n );\n}\n\n// required in order to narrow the money object down and make TS happy\nfunction isMoney(\n maybeMoney: PartialDeep<MoneyV2, {recurseIntoArrays: true}>,\n): maybeMoney is MoneyV2 {\n return (\n typeof maybeMoney.amount === 'string' &&\n !!maybeMoney.amount &&\n typeof maybeMoney.currencyCode === 'string' &&\n !!maybeMoney.currencyCode\n );\n}\n"],"names":[],"mappings":";;AA+DO,SAAS,MAA0D;AAAA,EACxE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,uBAAuB;AAAA,EACvB,GAAG;AACL,GAA8C;AACxC,MAAA,CAAC,QAAQ,IAAI,GAAG;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACM,QAAA,cAAc,SAAS,IAAI;AACjC,QAAM,UAAU,MAAM;AAEtB,MAAI,SAAS,YAAY;AAEzB,MAAI,mBAAmB,sBAAsB;AACvC,QAAA,mBAAmB,CAAC,sBAAsB;AAC5C,eAAS,YAAY;AAAA,IAAA,WACZ,CAAC,mBAAmB,sBAAsB;AACnD,eAAS,YAAY;AAAA,IAAA,OAChB;AAEL,eAAS,YAAY;AAAA,IACvB;AAAA,EACF;AAGE,SAAA,qBAAC,SAAS,EAAA,GAAG,kBACV,UAAA;AAAA,IAAA;AAAA,IACA,eAAe,YAAY,iBAEvB,qBAAA,UAAA,EAAA,UAAA;AAAA,MAAA;AAAA,MACA,YAAY;AAAA,IAAA,GACf;AAAA,EAEJ,EAAA,CAAA;AAEJ;AAGA,SAAS,QACP,YACuB;AACvB,SACE,OAAO,WAAW,WAAW,YAC7B,CAAC,CAAC,WAAW,UACb,OAAO,WAAW,iBAAiB,YACnC,CAAC,CAAC,WAAW;AAEjB;"}
1
+ {"version":3,"file":"Money.mjs","sources":["../../src/Money.tsx"],"sourcesContent":["import {type ReactNode} from 'react';\nimport {useMoney} from './useMoney.js';\nimport type {MoneyV2, UnitPriceMeasurement} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nexport interface MoneyPropsBase<ComponentGeneric extends React.ElementType> {\n /** An HTML tag or React Component to be rendered as the base element wrapper. The default is `div`. */\n as?: ComponentGeneric;\n /** An object with fields that correspond to the Storefront API's [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2). */\n data: PartialDeep<MoneyV2, {recurseIntoArrays: true}>;\n /** Whether to remove the currency symbol from the output. */\n withoutCurrency?: boolean;\n /** Whether to remove trailing zeros (fractional money) from the output. */\n withoutTrailingZeros?: boolean;\n /** A [UnitPriceMeasurement object](https://shopify.dev/api/storefront/2024-01/objects/unitpricemeasurement). */\n measurement?: PartialDeep<UnitPriceMeasurement, {recurseIntoArrays: true}>;\n /** Customizes the separator between the money output and the measurement output. Used with the `measurement` prop. Defaults to `'/'`. */\n measurementSeparator?: ReactNode;\n}\n\n// This article helps understand the typing here https://www.benmvp.com/blog/polymorphic-react-components-typescript/ Ben is the best :)\nexport type MoneyProps<ComponentGeneric extends React.ElementType> =\n MoneyPropsBase<ComponentGeneric> &\n (ComponentGeneric extends keyof React.JSX.IntrinsicElements\n ? Omit<\n React.ComponentPropsWithoutRef<ComponentGeneric>,\n keyof MoneyPropsBase<ComponentGeneric>\n >\n : React.ComponentPropsWithoutRef<ComponentGeneric>);\n\n/**\n * The `Money` component renders a string of the Storefront API's\n * [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2)\n * according to the `locale` in the `ShopifyProvider` component.\n * &nbsp;\n * @see {@link https://shopify.dev/api/hydrogen/components/money}\n * @example basic usage, outputs: $100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} />\n * ```\n * &nbsp;\n *\n * @example without currency, outputs: 100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutCurrency />\n * ```\n * &nbsp;\n *\n * @example without trailing zeros, outputs: $100\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutTrailingZeros />\n * ```\n * &nbsp;\n *\n * @example with per-unit measurement, outputs: $100.00 per G\n * ```ts\n * <Money\n * data={{amount: '100.00', currencyCode: 'USD'}}\n * measurement={{referenceUnit: 'G'}}\n * measurementSeparator=\" per \"\n * />\n * ```\n */\nexport function Money<ComponentGeneric extends React.ElementType = 'div'>({\n data,\n as,\n withoutCurrency,\n withoutTrailingZeros,\n measurement,\n measurementSeparator = '/',\n ...passthroughProps\n}: MoneyProps<ComponentGeneric>): JSX.Element {\n if (!isMoney(data)) {\n throw new Error(\n `<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`,\n );\n }\n const moneyObject = useMoney(data);\n const Wrapper = as ?? 'div';\n\n let output = moneyObject.localizedString;\n\n if (withoutCurrency || withoutTrailingZeros) {\n if (withoutCurrency && !withoutTrailingZeros) {\n output = moneyObject.amount;\n } else if (!withoutCurrency && withoutTrailingZeros) {\n output = moneyObject.withoutTrailingZeros;\n } else {\n // both\n output = moneyObject.withoutTrailingZerosAndCurrency;\n }\n }\n\n return (\n <Wrapper {...passthroughProps}>\n {output}\n {measurement && measurement.referenceUnit && (\n <>\n {measurementSeparator}\n {measurement.referenceUnit}\n </>\n )}\n </Wrapper>\n );\n}\n\n// required in order to narrow the money object down and make TS happy\nfunction isMoney(\n maybeMoney: PartialDeep<MoneyV2, {recurseIntoArrays: true}>,\n): maybeMoney is MoneyV2 {\n return (\n typeof maybeMoney.amount === 'string' &&\n !!maybeMoney.amount &&\n typeof maybeMoney.currencyCode === 'string' &&\n !!maybeMoney.currencyCode\n );\n}\n"],"names":[],"mappings":";;AA+DO,SAAS,MAA0D;AAAA,EACxE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,uBAAuB;AAAA,EACvB,GAAG;AACL,GAA8C;AACxC,MAAA,CAAC,QAAQ,IAAI,GAAG;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACM,QAAA,cAAc,SAAS,IAAI;AACjC,QAAM,UAAU,MAAM;AAEtB,MAAI,SAAS,YAAY;AAEzB,MAAI,mBAAmB,sBAAsB;AACvC,QAAA,mBAAmB,CAAC,sBAAsB;AAC5C,eAAS,YAAY;AAAA,IAAA,WACZ,CAAC,mBAAmB,sBAAsB;AACnD,eAAS,YAAY;AAAA,IAAA,OAChB;AAEL,eAAS,YAAY;AAAA,IACvB;AAAA,EACF;AAGE,SAAA,qBAAC,SAAS,EAAA,GAAG,kBACV,UAAA;AAAA,IAAA;AAAA,IACA,eAAe,YAAY,iBAEvB,qBAAA,UAAA,EAAA,UAAA;AAAA,MAAA;AAAA,MACA,YAAY;AAAA,IAAA,GACf;AAAA,EAEJ,EAAA,CAAA;AAEJ;AAGA,SAAS,QACP,YACuB;AACvB,SACE,OAAO,WAAW,WAAW,YAC7B,CAAC,CAAC,WAAW,UACb,OAAO,WAAW,iBAAiB,YACnC,CAAC,CAAC,WAAW;AAEjB;"}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
5
  const Image = require("./Image.js");
6
- function Video(props) {
6
+ const Video = React.forwardRef((props, ref) => {
7
7
  var _a;
8
8
  const {
9
9
  data,
@@ -31,6 +31,7 @@ function Video(props) {
31
31
  playsInline,
32
32
  controls,
33
33
  poster: posterUrl,
34
+ ref,
34
35
  children: data.sources.map((source) => {
35
36
  if (!((source == null ? void 0 : source.url) && (source == null ? void 0 : source.mimeType))) {
36
37
  throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);
@@ -48,6 +49,6 @@ function Video(props) {
48
49
  }
49
50
  )
50
51
  );
51
- }
52
+ });
52
53
  exports.Video = Video;
53
54
  //# sourceMappingURL=Video.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Video.js","sources":["../../src/Video.tsx"],"sourcesContent":["import {type HTMLAttributes} from 'react';\nimport {shopifyLoader} from './Image.js';\nimport type {Video as VideoType} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nexport interface VideoProps {\n /** An object with fields that correspond to the Storefront API's [Video object](https://shopify.dev/api/storefront/2023-10/objects/video). */\n data: PartialDeep<VideoType, {recurseIntoArrays: true}>;\n /** An object of image size options for the video's `previewImage`. Uses `shopifyImageLoader` to generate the `poster` URL. */\n previewImageOptions?: Parameters<typeof shopifyLoader>[0];\n /** Props that will be passed to the `video` element's `source` children elements. */\n sourceProps?: HTMLAttributes<HTMLSourceElement> & {\n 'data-testid'?: string;\n };\n}\n\n/**\n * The `Video` component renders a `video` for the Storefront API's [Video object](https://shopify.dev/api/storefront/reference/products/video).\n */\nexport function Video(\n props: JSX.IntrinsicElements['video'] & VideoProps,\n): JSX.Element {\n const {\n data,\n previewImageOptions,\n id = data.id,\n playsInline = true,\n controls = true,\n sourceProps = {},\n ...passthroughProps\n } = props;\n\n const posterUrl = shopifyLoader({\n src: data.previewImage?.url ?? '',\n ...previewImageOptions,\n });\n\n if (!data.sources) {\n throw new Error(`<Video/> requires a 'data.sources' array`);\n }\n\n return (\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <video\n {...passthroughProps}\n id={id}\n playsInline={playsInline}\n controls={controls}\n poster={posterUrl}\n >\n {data.sources.map((source) => {\n if (!(source?.url && source?.mimeType)) {\n throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);\n }\n return (\n <source\n {...sourceProps}\n key={source.url}\n src={source.url}\n type={source.mimeType}\n />\n );\n })}\n </video>\n );\n}\n"],"names":["shopifyLoader","jsx","createElement"],"mappings":";;;;;AAmBO,SAAS,MACd,OACa;;AACP,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA,KAAK,KAAK;AAAA,IACV,cAAc;AAAA,IACd,WAAW;AAAA,IACX,cAAc,CAAC;AAAA,IACf,GAAG;AAAA,EACD,IAAA;AAEJ,QAAM,YAAYA,MAAAA,cAAc;AAAA,IAC9B,OAAK,UAAK,iBAAL,mBAAmB,QAAO;AAAA,IAC/B,GAAG;AAAA,EAAA,CACJ;AAEG,MAAA,CAAC,KAAK,SAAS;AACX,UAAA,IAAI,MAAM,0CAA0C;AAAA,EAC5D;AAEA;AAAA;AAAA,IAEEC,2BAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ;AAAA,QAEP,UAAK,KAAA,QAAQ,IAAI,CAAC,WAAW;AAC5B,cAAI,GAAE,iCAAQ,SAAO,iCAAQ,YAAW;AAChC,kBAAA,IAAI,MAAM,mDAAmD;AAAA,UACrE;AAEE,iBAAAC,sBAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACE,GAAG;AAAA,cACJ,KAAK,OAAO;AAAA,cACZ,KAAK,OAAO;AAAA,cACZ,MAAM,OAAO;AAAA,YAAA;AAAA,UAAA;AAAA,QACf,CAEH;AAAA,MAAA;AAAA,IACH;AAAA;AAEJ;;"}
1
+ {"version":3,"file":"Video.js","sources":["../../src/Video.tsx"],"sourcesContent":["import {forwardRef, type HTMLAttributes} from 'react';\nimport {shopifyLoader} from './Image.js';\nimport type {Video as VideoType} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nexport interface VideoProps {\n /** An object with fields that correspond to the Storefront API's [Video object](https://shopify.dev/api/storefront/2024-01/objects/video). */\n data: PartialDeep<VideoType, {recurseIntoArrays: true}>;\n /** An object of image size options for the video's `previewImage`. Uses `shopifyImageLoader` to generate the `poster` URL. */\n previewImageOptions?: Parameters<typeof shopifyLoader>[0];\n /** Props that will be passed to the `video` element's `source` children elements. */\n sourceProps?: HTMLAttributes<HTMLSourceElement> & {\n 'data-testid'?: string;\n };\n}\n\n/**\n * The `Video` component renders a `video` for the Storefront API's [Video object](https://shopify.dev/api/storefront/reference/products/video).\n */\nexport const Video = forwardRef<\n HTMLVideoElement,\n JSX.IntrinsicElements['video'] & VideoProps\n>((props, ref): JSX.Element => {\n const {\n data,\n previewImageOptions,\n id = data.id,\n playsInline = true,\n controls = true,\n sourceProps = {},\n ...passthroughProps\n } = props;\n\n const posterUrl = shopifyLoader({\n src: data.previewImage?.url ?? '',\n ...previewImageOptions,\n });\n\n if (!data.sources) {\n throw new Error(`<Video/> requires a 'data.sources' array`);\n }\n\n return (\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <video\n {...passthroughProps}\n id={id}\n playsInline={playsInline}\n controls={controls}\n poster={posterUrl}\n ref={ref}\n >\n {data.sources.map((source) => {\n if (!(source?.url && source?.mimeType)) {\n throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);\n }\n return (\n <source\n {...sourceProps}\n key={source.url}\n src={source.url}\n type={source.mimeType}\n />\n );\n })}\n </video>\n );\n});\n"],"names":["forwardRef","shopifyLoader","jsx","createElement"],"mappings":";;;;;AAmBO,MAAM,QAAQA,MAAA,WAGnB,CAAC,OAAO,QAAqB;;AACvB,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA,KAAK,KAAK;AAAA,IACV,cAAc;AAAA,IACd,WAAW;AAAA,IACX,cAAc,CAAC;AAAA,IACf,GAAG;AAAA,EACD,IAAA;AAEJ,QAAM,YAAYC,MAAAA,cAAc;AAAA,IAC9B,OAAK,UAAK,iBAAL,mBAAmB,QAAO;AAAA,IAC/B,GAAG;AAAA,EAAA,CACJ;AAEG,MAAA,CAAC,KAAK,SAAS;AACX,UAAA,IAAI,MAAM,0CAA0C;AAAA,EAC5D;AAEA;AAAA;AAAA,IAEEC,2BAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ;AAAA,QACR;AAAA,QAEC,UAAK,KAAA,QAAQ,IAAI,CAAC,WAAW;AAC5B,cAAI,GAAE,iCAAQ,SAAO,iCAAQ,YAAW;AAChC,kBAAA,IAAI,MAAM,mDAAmD;AAAA,UACrE;AAEE,iBAAAC,sBAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACE,GAAG;AAAA,cACJ,KAAK,OAAO;AAAA,cACZ,KAAK,OAAO;AAAA,cACZ,MAAM,OAAO;AAAA,YAAA;AAAA,UAAA;AAAA,QACf,CAEH;AAAA,MAAA;AAAA,IACH;AAAA;AAEJ,CAAC;;"}
@@ -1,7 +1,7 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { createElement } from "react";
2
+ import { forwardRef, createElement } from "react";
3
3
  import { shopifyLoader } from "./Image.mjs";
4
- function Video(props) {
4
+ const Video = forwardRef((props, ref) => {
5
5
  var _a;
6
6
  const {
7
7
  data,
@@ -29,6 +29,7 @@ function Video(props) {
29
29
  playsInline,
30
30
  controls,
31
31
  poster: posterUrl,
32
+ ref,
32
33
  children: data.sources.map((source) => {
33
34
  if (!((source == null ? void 0 : source.url) && (source == null ? void 0 : source.mimeType))) {
34
35
  throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);
@@ -46,7 +47,7 @@ function Video(props) {
46
47
  }
47
48
  )
48
49
  );
49
- }
50
+ });
50
51
  export {
51
52
  Video
52
53
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Video.mjs","sources":["../../src/Video.tsx"],"sourcesContent":["import {type HTMLAttributes} from 'react';\nimport {shopifyLoader} from './Image.js';\nimport type {Video as VideoType} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nexport interface VideoProps {\n /** An object with fields that correspond to the Storefront API's [Video object](https://shopify.dev/api/storefront/2023-10/objects/video). */\n data: PartialDeep<VideoType, {recurseIntoArrays: true}>;\n /** An object of image size options for the video's `previewImage`. Uses `shopifyImageLoader` to generate the `poster` URL. */\n previewImageOptions?: Parameters<typeof shopifyLoader>[0];\n /** Props that will be passed to the `video` element's `source` children elements. */\n sourceProps?: HTMLAttributes<HTMLSourceElement> & {\n 'data-testid'?: string;\n };\n}\n\n/**\n * The `Video` component renders a `video` for the Storefront API's [Video object](https://shopify.dev/api/storefront/reference/products/video).\n */\nexport function Video(\n props: JSX.IntrinsicElements['video'] & VideoProps,\n): JSX.Element {\n const {\n data,\n previewImageOptions,\n id = data.id,\n playsInline = true,\n controls = true,\n sourceProps = {},\n ...passthroughProps\n } = props;\n\n const posterUrl = shopifyLoader({\n src: data.previewImage?.url ?? '',\n ...previewImageOptions,\n });\n\n if (!data.sources) {\n throw new Error(`<Video/> requires a 'data.sources' array`);\n }\n\n return (\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <video\n {...passthroughProps}\n id={id}\n playsInline={playsInline}\n controls={controls}\n poster={posterUrl}\n >\n {data.sources.map((source) => {\n if (!(source?.url && source?.mimeType)) {\n throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);\n }\n return (\n <source\n {...sourceProps}\n key={source.url}\n src={source.url}\n type={source.mimeType}\n />\n );\n })}\n </video>\n );\n}\n"],"names":[],"mappings":";;;AAmBO,SAAS,MACd,OACa;;AACP,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA,KAAK,KAAK;AAAA,IACV,cAAc;AAAA,IACd,WAAW;AAAA,IACX,cAAc,CAAC;AAAA,IACf,GAAG;AAAA,EACD,IAAA;AAEJ,QAAM,YAAY,cAAc;AAAA,IAC9B,OAAK,UAAK,iBAAL,mBAAmB,QAAO;AAAA,IAC/B,GAAG;AAAA,EAAA,CACJ;AAEG,MAAA,CAAC,KAAK,SAAS;AACX,UAAA,IAAI,MAAM,0CAA0C;AAAA,EAC5D;AAEA;AAAA;AAAA,IAEE;AAAA,MAAC;AAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ;AAAA,QAEP,UAAK,KAAA,QAAQ,IAAI,CAAC,WAAW;AAC5B,cAAI,GAAE,iCAAQ,SAAO,iCAAQ,YAAW;AAChC,kBAAA,IAAI,MAAM,mDAAmD;AAAA,UACrE;AAEE,iBAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACE,GAAG;AAAA,cACJ,KAAK,OAAO;AAAA,cACZ,KAAK,OAAO;AAAA,cACZ,MAAM,OAAO;AAAA,YAAA;AAAA,UAAA;AAAA,QACf,CAEH;AAAA,MAAA;AAAA,IACH;AAAA;AAEJ;"}
1
+ {"version":3,"file":"Video.mjs","sources":["../../src/Video.tsx"],"sourcesContent":["import {forwardRef, type HTMLAttributes} from 'react';\nimport {shopifyLoader} from './Image.js';\nimport type {Video as VideoType} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nexport interface VideoProps {\n /** An object with fields that correspond to the Storefront API's [Video object](https://shopify.dev/api/storefront/2024-01/objects/video). */\n data: PartialDeep<VideoType, {recurseIntoArrays: true}>;\n /** An object of image size options for the video's `previewImage`. Uses `shopifyImageLoader` to generate the `poster` URL. */\n previewImageOptions?: Parameters<typeof shopifyLoader>[0];\n /** Props that will be passed to the `video` element's `source` children elements. */\n sourceProps?: HTMLAttributes<HTMLSourceElement> & {\n 'data-testid'?: string;\n };\n}\n\n/**\n * The `Video` component renders a `video` for the Storefront API's [Video object](https://shopify.dev/api/storefront/reference/products/video).\n */\nexport const Video = forwardRef<\n HTMLVideoElement,\n JSX.IntrinsicElements['video'] & VideoProps\n>((props, ref): JSX.Element => {\n const {\n data,\n previewImageOptions,\n id = data.id,\n playsInline = true,\n controls = true,\n sourceProps = {},\n ...passthroughProps\n } = props;\n\n const posterUrl = shopifyLoader({\n src: data.previewImage?.url ?? '',\n ...previewImageOptions,\n });\n\n if (!data.sources) {\n throw new Error(`<Video/> requires a 'data.sources' array`);\n }\n\n return (\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <video\n {...passthroughProps}\n id={id}\n playsInline={playsInline}\n controls={controls}\n poster={posterUrl}\n ref={ref}\n >\n {data.sources.map((source) => {\n if (!(source?.url && source?.mimeType)) {\n throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);\n }\n return (\n <source\n {...sourceProps}\n key={source.url}\n src={source.url}\n type={source.mimeType}\n />\n );\n })}\n </video>\n );\n});\n"],"names":[],"mappings":";;;AAmBO,MAAM,QAAQ,WAGnB,CAAC,OAAO,QAAqB;;AACvB,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA,KAAK,KAAK;AAAA,IACV,cAAc;AAAA,IACd,WAAW;AAAA,IACX,cAAc,CAAC;AAAA,IACf,GAAG;AAAA,EACD,IAAA;AAEJ,QAAM,YAAY,cAAc;AAAA,IAC9B,OAAK,UAAK,iBAAL,mBAAmB,QAAO;AAAA,IAC/B,GAAG;AAAA,EAAA,CACJ;AAEG,MAAA,CAAC,KAAK,SAAS;AACX,UAAA,IAAI,MAAM,0CAA0C;AAAA,EAC5D;AAEA;AAAA;AAAA,IAEE;AAAA,MAAC;AAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ;AAAA,QACR;AAAA,QAEC,UAAK,KAAA,QAAQ,IAAI,CAAC,WAAW;AAC5B,cAAI,GAAE,iCAAQ,SAAO,iCAAQ,YAAW;AAChC,kBAAA,IAAI,MAAM,mDAAmD;AAAA,UACrE;AAEE,iBAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACE,GAAG;AAAA,cACJ,KAAK,OAAO;AAAA,cACZ,KAAK,OAAO;AAAA,cACZ,MAAM,OAAO;AAAA,YAAA;AAAA,UAAA;AAAA,QACf,CAEH;AAAA,MAAA;AAAA,IACH;AAAA;AAEJ,CAAC;"}
@@ -9,5 +9,14 @@ const storefrontApiCustomScalars = {
9
9
  Color: "string",
10
10
  UnsignedInt64: "string"
11
11
  };
12
+ const customerAccountApiCustomScalars = {
13
+ DateTime: "string",
14
+ Decimal: "string",
15
+ HTML: "string",
16
+ ISO8601DateTime: "string",
17
+ URL: "string",
18
+ UnsignedInt64: "string"
19
+ };
20
+ exports.customerAccountApiCustomScalars = customerAccountApiCustomScalars;
12
21
  exports.storefrontApiCustomScalars = storefrontApiCustomScalars;
13
22
  //# sourceMappingURL=codegen.helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.helpers.js","sources":["../../src/codegen.helpers.ts"],"sourcesContent":["/**\n * Meant to be used with GraphQL CodeGen to type the Storefront API's custom scalars correctly.\n * Reference for the GraphQL types: https://shopify.dev/docs/api/storefront/current/scalars/HTML\n * Note: JSON is generated as 'unknown' by default.\n */\nexport const storefrontApiCustomScalars = {\n // Keep in sync with the definitions in the app/nextjs/codegen.ts!\n DateTime: 'string',\n Decimal: 'string',\n HTML: 'string',\n URL: 'string',\n Color: 'string',\n UnsignedInt64: 'string',\n};\n"],"names":[],"mappings":";;AAKO,MAAM,6BAA6B;AAAA;AAAA,EAExC,UAAU;AAAA,EACV,SAAS;AAAA,EACT,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,eAAe;AACjB;;"}
1
+ {"version":3,"file":"codegen.helpers.js","sources":["../../src/codegen.helpers.ts"],"sourcesContent":["/**\n * Meant to be used with GraphQL CodeGen to type the Storefront API's custom scalars correctly.\n * Reference for the GraphQL types: https://shopify.dev/docs/api/storefront/2024-01/scalars/HTML\n * Note: JSON is generated as 'unknown' by default.\n */\nexport const storefrontApiCustomScalars = {\n // Keep in sync with the definitions in the app/nextjs/codegen.ts!\n DateTime: 'string',\n Decimal: 'string',\n HTML: 'string',\n URL: 'string',\n Color: 'string',\n UnsignedInt64: 'string',\n};\n\n/**\n * Meant to be used with GraphQL CodeGen to type the Storefront API's custom scalars correctly.\n * Reference for the GraphQL types: https://shopify.dev/docs/api/customer/2024-01/scalars/HTML\n * Note: JSON is generated as 'unknown' by default.\n */\nexport const customerAccountApiCustomScalars = {\n DateTime: 'string',\n Decimal: 'string',\n HTML: 'string',\n ISO8601DateTime: 'string',\n URL: 'string',\n UnsignedInt64: 'string',\n};\n"],"names":[],"mappings":";;AAKO,MAAM,6BAA6B;AAAA;AAAA,EAExC,UAAU;AAAA,EACV,SAAS;AAAA,EACT,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,eAAe;AACjB;AAOO,MAAM,kCAAkC;AAAA,EAC7C,UAAU;AAAA,EACV,SAAS;AAAA,EACT,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,KAAK;AAAA,EACL,eAAe;AACjB;;;"}
@@ -7,7 +7,16 @@ const storefrontApiCustomScalars = {
7
7
  Color: "string",
8
8
  UnsignedInt64: "string"
9
9
  };
10
+ const customerAccountApiCustomScalars = {
11
+ DateTime: "string",
12
+ Decimal: "string",
13
+ HTML: "string",
14
+ ISO8601DateTime: "string",
15
+ URL: "string",
16
+ UnsignedInt64: "string"
17
+ };
10
18
  export {
19
+ customerAccountApiCustomScalars,
11
20
  storefrontApiCustomScalars
12
21
  };
13
22
  //# sourceMappingURL=codegen.helpers.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.helpers.mjs","sources":["../../src/codegen.helpers.ts"],"sourcesContent":["/**\n * Meant to be used with GraphQL CodeGen to type the Storefront API's custom scalars correctly.\n * Reference for the GraphQL types: https://shopify.dev/docs/api/storefront/current/scalars/HTML\n * Note: JSON is generated as 'unknown' by default.\n */\nexport const storefrontApiCustomScalars = {\n // Keep in sync with the definitions in the app/nextjs/codegen.ts!\n DateTime: 'string',\n Decimal: 'string',\n HTML: 'string',\n URL: 'string',\n Color: 'string',\n UnsignedInt64: 'string',\n};\n"],"names":[],"mappings":"AAKO,MAAM,6BAA6B;AAAA;AAAA,EAExC,UAAU;AAAA,EACV,SAAS;AAAA,EACT,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,eAAe;AACjB;"}
1
+ {"version":3,"file":"codegen.helpers.mjs","sources":["../../src/codegen.helpers.ts"],"sourcesContent":["/**\n * Meant to be used with GraphQL CodeGen to type the Storefront API's custom scalars correctly.\n * Reference for the GraphQL types: https://shopify.dev/docs/api/storefront/2024-01/scalars/HTML\n * Note: JSON is generated as 'unknown' by default.\n */\nexport const storefrontApiCustomScalars = {\n // Keep in sync with the definitions in the app/nextjs/codegen.ts!\n DateTime: 'string',\n Decimal: 'string',\n HTML: 'string',\n URL: 'string',\n Color: 'string',\n UnsignedInt64: 'string',\n};\n\n/**\n * Meant to be used with GraphQL CodeGen to type the Storefront API's custom scalars correctly.\n * Reference for the GraphQL types: https://shopify.dev/docs/api/customer/2024-01/scalars/HTML\n * Note: JSON is generated as 'unknown' by default.\n */\nexport const customerAccountApiCustomScalars = {\n DateTime: 'string',\n Decimal: 'string',\n HTML: 'string',\n ISO8601DateTime: 'string',\n URL: 'string',\n UnsignedInt64: 'string',\n};\n"],"names":[],"mappings":"AAKO,MAAM,6BAA6B;AAAA;AAAA,EAExC,UAAU;AAAA,EACV,SAAS;AAAA,EACT,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,eAAe;AACjB;AAOO,MAAM,kCAAkC;AAAA,EAC7C,UAAU;AAAA,EACV,SAAS;AAAA,EACT,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,KAAK;AAAA,EACL,eAAe;AACjB;"}
@@ -51,6 +51,7 @@ exports.CartLineQuantity = CartLineQuantity.CartLineQuantity;
51
51
  exports.CartLineQuantityAdjustButton = CartLineQuantityAdjustButton.CartLineQuantityAdjustButton;
52
52
  exports.CartProvider = CartProvider.CartProvider;
53
53
  exports.useCart = CartProvider.useCart;
54
+ exports.customerAccountApiCustomScalars = codegen_helpers.customerAccountApiCustomScalars;
54
55
  exports.storefrontApiCustomScalars = codegen_helpers.storefrontApiCustomScalars;
55
56
  exports.getShopifyCookies = cookiesUtils.getShopifyCookies;
56
57
  exports.ExternalVideo = ExternalVideo.ExternalVideo;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -10,7 +10,7 @@ import { CartLineProvider, useCartLine } from "./CartLineProvider.mjs";
10
10
  import { CartLineQuantity } from "./CartLineQuantity.mjs";
11
11
  import { CartLineQuantityAdjustButton } from "./CartLineQuantityAdjustButton.mjs";
12
12
  import { CartProvider, useCart } from "./CartProvider.mjs";
13
- import { storefrontApiCustomScalars } from "./codegen.helpers.mjs";
13
+ import { customerAccountApiCustomScalars, storefrontApiCustomScalars } from "./codegen.helpers.mjs";
14
14
  import { getShopifyCookies } from "./cookies-utils.mjs";
15
15
  import { ExternalVideo } from "./ExternalVideo.mjs";
16
16
  import { flattenConnection } from "./flatten-connection.mjs";
@@ -57,6 +57,7 @@ export {
57
57
  ShopifySalesChannel,
58
58
  Video,
59
59
  createStorefrontClient,
60
+ customerAccountApiCustomScalars,
60
61
  flattenConnection,
61
62
  getClientBrowserParameters,
62
63
  getShopifyCookies,
@@ -38,21 +38,14 @@ function loadScript(src, options) {
38
38
  }
39
39
  function useLoadScript(url, options) {
40
40
  const [status, setStatus] = React.useState("loading");
41
- const stringifiedOptions = JSON.stringify(options);
42
- React.useEffect(() => {
43
- async function loadScriptWrapper() {
44
- try {
45
- setStatus("loading");
46
- await loadScript(url, options);
47
- setStatus("done");
48
- } catch (error) {
49
- setStatus("error");
50
- }
51
- }
52
- loadScriptWrapper().catch(() => {
53
- setStatus("error");
54
- });
55
- }, [url, stringifiedOptions, options]);
41
+ React.useEffect(
42
+ () => {
43
+ loadScript(url, options).then(() => setStatus("done")).catch(() => setStatus("error"));
44
+ },
45
+ // Ignore options changes since it won't trigger a new load.
46
+ // eslint-disable-next-line react-hooks/exhaustive-deps
47
+ [url]
48
+ );
56
49
  return status;
57
50
  }
58
51
  exports.loadScript = loadScript;
@@ -1 +1 @@
1
- {"version":3,"file":"load-script.js","sources":["../../src/load-script.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\n\nconst SCRIPTS_LOADED: Record<string, Promise<boolean>> = {};\n\ntype LoadScriptOptions = {\n module?: boolean;\n in?: 'head' | 'body';\n attributes?: Record<string, string>;\n};\n\nexport function loadScript(\n src: string,\n options?: LoadScriptOptions,\n): Promise<boolean> {\n const isScriptLoaded = SCRIPTS_LOADED[src];\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (isScriptLoaded) {\n return isScriptLoaded;\n }\n\n const promise = new Promise<boolean>((resolve, reject) => {\n const script = document.createElement('script');\n if (options?.module) {\n script.type = 'module';\n } else {\n script.type = 'text/javascript';\n }\n script.src = src;\n script.onload = (): void => {\n resolve(true);\n };\n script.onerror = (): void => {\n reject(false);\n };\n if (options?.in === 'head') {\n document.head.appendChild(script);\n } else {\n document.body.appendChild(script);\n }\n\n const attributes = options?.attributes;\n if (attributes) {\n Object.keys(attributes).forEach((key) => {\n script.setAttribute(key, attributes[key]);\n });\n }\n });\n\n SCRIPTS_LOADED[src] = promise;\n\n return promise;\n}\n\ntype LoadScriptParams = Parameters<typeof loadScript>;\n\n/**\n * The `useLoadScript` hook loads an external script tag in the browser. It allows React components to lazy-load large third-party dependencies.\n */\nexport function useLoadScript(\n url: LoadScriptParams[0],\n options?: LoadScriptParams[1],\n): ScriptState {\n const [status, setStatus] = useState<ScriptState>('loading');\n const stringifiedOptions = JSON.stringify(options);\n\n useEffect(() => {\n async function loadScriptWrapper(): Promise<void> {\n try {\n setStatus('loading');\n await loadScript(url, options);\n setStatus('done');\n } catch (error) {\n setStatus('error');\n }\n }\n\n loadScriptWrapper().catch(() => {\n setStatus('error');\n });\n }, [url, stringifiedOptions, options]);\n\n return status;\n}\n\ntype ScriptState = 'loading' | 'done' | 'error';\n"],"names":["useState","useEffect"],"mappings":";;;AAEA,MAAM,iBAAmD,CAAA;AAQzC,SAAA,WACd,KACA,SACkB;AACZ,QAAA,iBAAiB,eAAe,GAAG;AAGzC,MAAI,gBAAgB;AACX,WAAA;AAAA,EACT;AAEA,QAAM,UAAU,IAAI,QAAiB,CAAC,SAAS,WAAW;AAClD,UAAA,SAAS,SAAS,cAAc,QAAQ;AAC9C,QAAI,mCAAS,QAAQ;AACnB,aAAO,OAAO;AAAA,IAAA,OACT;AACL,aAAO,OAAO;AAAA,IAChB;AACA,WAAO,MAAM;AACb,WAAO,SAAS,MAAY;AAC1B,cAAQ,IAAI;AAAA,IAAA;AAEd,WAAO,UAAU,MAAY;AAC3B,aAAO,KAAK;AAAA,IAAA;AAEV,SAAA,mCAAS,QAAO,QAAQ;AACjB,eAAA,KAAK,YAAY,MAAM;AAAA,IAAA,OAC3B;AACI,eAAA,KAAK,YAAY,MAAM;AAAA,IAClC;AAEA,UAAM,aAAa,mCAAS;AAC5B,QAAI,YAAY;AACd,aAAO,KAAK,UAAU,EAAE,QAAQ,CAAC,QAAQ;AACvC,eAAO,aAAa,KAAK,WAAW,GAAG,CAAC;AAAA,MAAA,CACzC;AAAA,IACH;AAAA,EAAA,CACD;AAED,iBAAe,GAAG,IAAI;AAEf,SAAA;AACT;AAOgB,SAAA,cACd,KACA,SACa;AACb,QAAM,CAAC,QAAQ,SAAS,IAAIA,eAAsB,SAAS;AACrD,QAAA,qBAAqB,KAAK,UAAU,OAAO;AAEjDC,QAAAA,UAAU,MAAM;AACd,mBAAe,oBAAmC;AAC5C,UAAA;AACF,kBAAU,SAAS;AACb,cAAA,WAAW,KAAK,OAAO;AAC7B,kBAAU,MAAM;AAAA,eACT,OAAO;AACd,kBAAU,OAAO;AAAA,MACnB;AAAA,IACF;AAEkB,sBAAA,EAAE,MAAM,MAAM;AAC9B,gBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EACA,GAAA,CAAC,KAAK,oBAAoB,OAAO,CAAC;AAE9B,SAAA;AACT;;;"}
1
+ {"version":3,"file":"load-script.js","sources":["../../src/load-script.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\n\nconst SCRIPTS_LOADED: Record<string, Promise<boolean>> = {};\n\ntype LoadScriptOptions = {\n module?: boolean;\n in?: 'head' | 'body';\n attributes?: Record<string, string>;\n};\n\nexport function loadScript(\n src: string,\n options?: LoadScriptOptions,\n): Promise<boolean> {\n const isScriptLoaded = SCRIPTS_LOADED[src];\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (isScriptLoaded) {\n return isScriptLoaded;\n }\n\n const promise = new Promise<boolean>((resolve, reject) => {\n const script = document.createElement('script');\n if (options?.module) {\n script.type = 'module';\n } else {\n script.type = 'text/javascript';\n }\n script.src = src;\n script.onload = (): void => {\n resolve(true);\n };\n script.onerror = (): void => {\n reject(false);\n };\n if (options?.in === 'head') {\n document.head.appendChild(script);\n } else {\n document.body.appendChild(script);\n }\n\n const attributes = options?.attributes;\n if (attributes) {\n Object.keys(attributes).forEach((key) => {\n script.setAttribute(key, attributes[key]);\n });\n }\n });\n\n SCRIPTS_LOADED[src] = promise;\n\n return promise;\n}\n\ntype LoadScriptParams = Parameters<typeof loadScript>;\n\n/**\n * The `useLoadScript` hook loads an external script tag in the browser. It allows React components to lazy-load large third-party dependencies.\n */\nexport function useLoadScript(\n url: LoadScriptParams[0],\n options?: LoadScriptParams[1],\n): ScriptState {\n const [status, setStatus] = useState<ScriptState>('loading');\n\n useEffect(\n () => {\n loadScript(url, options)\n .then(() => setStatus('done'))\n .catch(() => setStatus('error'));\n },\n // Ignore options changes since it won't trigger a new load.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [url],\n );\n\n return status;\n}\n\ntype ScriptState = 'loading' | 'done' | 'error';\n"],"names":["useState","useEffect"],"mappings":";;;AAEA,MAAM,iBAAmD,CAAA;AAQzC,SAAA,WACd,KACA,SACkB;AACZ,QAAA,iBAAiB,eAAe,GAAG;AAGzC,MAAI,gBAAgB;AACX,WAAA;AAAA,EACT;AAEA,QAAM,UAAU,IAAI,QAAiB,CAAC,SAAS,WAAW;AAClD,UAAA,SAAS,SAAS,cAAc,QAAQ;AAC9C,QAAI,mCAAS,QAAQ;AACnB,aAAO,OAAO;AAAA,IAAA,OACT;AACL,aAAO,OAAO;AAAA,IAChB;AACA,WAAO,MAAM;AACb,WAAO,SAAS,MAAY;AAC1B,cAAQ,IAAI;AAAA,IAAA;AAEd,WAAO,UAAU,MAAY;AAC3B,aAAO,KAAK;AAAA,IAAA;AAEV,SAAA,mCAAS,QAAO,QAAQ;AACjB,eAAA,KAAK,YAAY,MAAM;AAAA,IAAA,OAC3B;AACI,eAAA,KAAK,YAAY,MAAM;AAAA,IAClC;AAEA,UAAM,aAAa,mCAAS;AAC5B,QAAI,YAAY;AACd,aAAO,KAAK,UAAU,EAAE,QAAQ,CAAC,QAAQ;AACvC,eAAO,aAAa,KAAK,WAAW,GAAG,CAAC;AAAA,MAAA,CACzC;AAAA,IACH;AAAA,EAAA,CACD;AAED,iBAAe,GAAG,IAAI;AAEf,SAAA;AACT;AAOgB,SAAA,cACd,KACA,SACa;AACb,QAAM,CAAC,QAAQ,SAAS,IAAIA,eAAsB,SAAS;AAE3DC,QAAA;AAAA,IACE,MAAM;AACJ,iBAAW,KAAK,OAAO,EACpB,KAAK,MAAM,UAAU,MAAM,CAAC,EAC5B,MAAM,MAAM,UAAU,OAAO,CAAC;AAAA,IACnC;AAAA;AAAA;AAAA,IAGA,CAAC,GAAG;AAAA,EAAA;AAGC,SAAA;AACT;;;"}
@@ -36,21 +36,14 @@ function loadScript(src, options) {
36
36
  }
37
37
  function useLoadScript(url, options) {
38
38
  const [status, setStatus] = useState("loading");
39
- const stringifiedOptions = JSON.stringify(options);
40
- useEffect(() => {
41
- async function loadScriptWrapper() {
42
- try {
43
- setStatus("loading");
44
- await loadScript(url, options);
45
- setStatus("done");
46
- } catch (error) {
47
- setStatus("error");
48
- }
49
- }
50
- loadScriptWrapper().catch(() => {
51
- setStatus("error");
52
- });
53
- }, [url, stringifiedOptions, options]);
39
+ useEffect(
40
+ () => {
41
+ loadScript(url, options).then(() => setStatus("done")).catch(() => setStatus("error"));
42
+ },
43
+ // Ignore options changes since it won't trigger a new load.
44
+ // eslint-disable-next-line react-hooks/exhaustive-deps
45
+ [url]
46
+ );
54
47
  return status;
55
48
  }
56
49
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"load-script.mjs","sources":["../../src/load-script.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\n\nconst SCRIPTS_LOADED: Record<string, Promise<boolean>> = {};\n\ntype LoadScriptOptions = {\n module?: boolean;\n in?: 'head' | 'body';\n attributes?: Record<string, string>;\n};\n\nexport function loadScript(\n src: string,\n options?: LoadScriptOptions,\n): Promise<boolean> {\n const isScriptLoaded = SCRIPTS_LOADED[src];\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (isScriptLoaded) {\n return isScriptLoaded;\n }\n\n const promise = new Promise<boolean>((resolve, reject) => {\n const script = document.createElement('script');\n if (options?.module) {\n script.type = 'module';\n } else {\n script.type = 'text/javascript';\n }\n script.src = src;\n script.onload = (): void => {\n resolve(true);\n };\n script.onerror = (): void => {\n reject(false);\n };\n if (options?.in === 'head') {\n document.head.appendChild(script);\n } else {\n document.body.appendChild(script);\n }\n\n const attributes = options?.attributes;\n if (attributes) {\n Object.keys(attributes).forEach((key) => {\n script.setAttribute(key, attributes[key]);\n });\n }\n });\n\n SCRIPTS_LOADED[src] = promise;\n\n return promise;\n}\n\ntype LoadScriptParams = Parameters<typeof loadScript>;\n\n/**\n * The `useLoadScript` hook loads an external script tag in the browser. It allows React components to lazy-load large third-party dependencies.\n */\nexport function useLoadScript(\n url: LoadScriptParams[0],\n options?: LoadScriptParams[1],\n): ScriptState {\n const [status, setStatus] = useState<ScriptState>('loading');\n const stringifiedOptions = JSON.stringify(options);\n\n useEffect(() => {\n async function loadScriptWrapper(): Promise<void> {\n try {\n setStatus('loading');\n await loadScript(url, options);\n setStatus('done');\n } catch (error) {\n setStatus('error');\n }\n }\n\n loadScriptWrapper().catch(() => {\n setStatus('error');\n });\n }, [url, stringifiedOptions, options]);\n\n return status;\n}\n\ntype ScriptState = 'loading' | 'done' | 'error';\n"],"names":[],"mappings":";AAEA,MAAM,iBAAmD,CAAA;AAQzC,SAAA,WACd,KACA,SACkB;AACZ,QAAA,iBAAiB,eAAe,GAAG;AAGzC,MAAI,gBAAgB;AACX,WAAA;AAAA,EACT;AAEA,QAAM,UAAU,IAAI,QAAiB,CAAC,SAAS,WAAW;AAClD,UAAA,SAAS,SAAS,cAAc,QAAQ;AAC9C,QAAI,mCAAS,QAAQ;AACnB,aAAO,OAAO;AAAA,IAAA,OACT;AACL,aAAO,OAAO;AAAA,IAChB;AACA,WAAO,MAAM;AACb,WAAO,SAAS,MAAY;AAC1B,cAAQ,IAAI;AAAA,IAAA;AAEd,WAAO,UAAU,MAAY;AAC3B,aAAO,KAAK;AAAA,IAAA;AAEV,SAAA,mCAAS,QAAO,QAAQ;AACjB,eAAA,KAAK,YAAY,MAAM;AAAA,IAAA,OAC3B;AACI,eAAA,KAAK,YAAY,MAAM;AAAA,IAClC;AAEA,UAAM,aAAa,mCAAS;AAC5B,QAAI,YAAY;AACd,aAAO,KAAK,UAAU,EAAE,QAAQ,CAAC,QAAQ;AACvC,eAAO,aAAa,KAAK,WAAW,GAAG,CAAC;AAAA,MAAA,CACzC;AAAA,IACH;AAAA,EAAA,CACD;AAED,iBAAe,GAAG,IAAI;AAEf,SAAA;AACT;AAOgB,SAAA,cACd,KACA,SACa;AACb,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAsB,SAAS;AACrD,QAAA,qBAAqB,KAAK,UAAU,OAAO;AAEjD,YAAU,MAAM;AACd,mBAAe,oBAAmC;AAC5C,UAAA;AACF,kBAAU,SAAS;AACb,cAAA,WAAW,KAAK,OAAO;AAC7B,kBAAU,MAAM;AAAA,eACT,OAAO;AACd,kBAAU,OAAO;AAAA,MACnB;AAAA,IACF;AAEkB,sBAAA,EAAE,MAAM,MAAM;AAC9B,gBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EACA,GAAA,CAAC,KAAK,oBAAoB,OAAO,CAAC;AAE9B,SAAA;AACT;"}
1
+ {"version":3,"file":"load-script.mjs","sources":["../../src/load-script.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\n\nconst SCRIPTS_LOADED: Record<string, Promise<boolean>> = {};\n\ntype LoadScriptOptions = {\n module?: boolean;\n in?: 'head' | 'body';\n attributes?: Record<string, string>;\n};\n\nexport function loadScript(\n src: string,\n options?: LoadScriptOptions,\n): Promise<boolean> {\n const isScriptLoaded = SCRIPTS_LOADED[src];\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (isScriptLoaded) {\n return isScriptLoaded;\n }\n\n const promise = new Promise<boolean>((resolve, reject) => {\n const script = document.createElement('script');\n if (options?.module) {\n script.type = 'module';\n } else {\n script.type = 'text/javascript';\n }\n script.src = src;\n script.onload = (): void => {\n resolve(true);\n };\n script.onerror = (): void => {\n reject(false);\n };\n if (options?.in === 'head') {\n document.head.appendChild(script);\n } else {\n document.body.appendChild(script);\n }\n\n const attributes = options?.attributes;\n if (attributes) {\n Object.keys(attributes).forEach((key) => {\n script.setAttribute(key, attributes[key]);\n });\n }\n });\n\n SCRIPTS_LOADED[src] = promise;\n\n return promise;\n}\n\ntype LoadScriptParams = Parameters<typeof loadScript>;\n\n/**\n * The `useLoadScript` hook loads an external script tag in the browser. It allows React components to lazy-load large third-party dependencies.\n */\nexport function useLoadScript(\n url: LoadScriptParams[0],\n options?: LoadScriptParams[1],\n): ScriptState {\n const [status, setStatus] = useState<ScriptState>('loading');\n\n useEffect(\n () => {\n loadScript(url, options)\n .then(() => setStatus('done'))\n .catch(() => setStatus('error'));\n },\n // Ignore options changes since it won't trigger a new load.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [url],\n );\n\n return status;\n}\n\ntype ScriptState = 'loading' | 'done' | 'error';\n"],"names":[],"mappings":";AAEA,MAAM,iBAAmD,CAAA;AAQzC,SAAA,WACd,KACA,SACkB;AACZ,QAAA,iBAAiB,eAAe,GAAG;AAGzC,MAAI,gBAAgB;AACX,WAAA;AAAA,EACT;AAEA,QAAM,UAAU,IAAI,QAAiB,CAAC,SAAS,WAAW;AAClD,UAAA,SAAS,SAAS,cAAc,QAAQ;AAC9C,QAAI,mCAAS,QAAQ;AACnB,aAAO,OAAO;AAAA,IAAA,OACT;AACL,aAAO,OAAO;AAAA,IAChB;AACA,WAAO,MAAM;AACb,WAAO,SAAS,MAAY;AAC1B,cAAQ,IAAI;AAAA,IAAA;AAEd,WAAO,UAAU,MAAY;AAC3B,aAAO,KAAK;AAAA,IAAA;AAEV,SAAA,mCAAS,QAAO,QAAQ;AACjB,eAAA,KAAK,YAAY,MAAM;AAAA,IAAA,OAC3B;AACI,eAAA,KAAK,YAAY,MAAM;AAAA,IAClC;AAEA,UAAM,aAAa,mCAAS;AAC5B,QAAI,YAAY;AACd,aAAO,KAAK,UAAU,EAAE,QAAQ,CAAC,QAAQ;AACvC,eAAO,aAAa,KAAK,WAAW,GAAG,CAAC;AAAA,MAAA,CACzC;AAAA,IACH;AAAA,EAAA,CACD;AAED,iBAAe,GAAG,IAAI;AAEf,SAAA;AACT;AAOgB,SAAA,cACd,KACA,SACa;AACb,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAsB,SAAS;AAE3D;AAAA,IACE,MAAM;AACJ,iBAAW,KAAK,OAAO,EACpB,KAAK,MAAM,UAAU,MAAM,CAAC,EAC5B,MAAM,MAAM,UAAU,OAAO,CAAC;AAAA,IACnC;AAAA;AAAA;AAAA,IAGA,CAAC,GAAG;AAAA,EAAA;AAGC,SAAA;AACT;"}
@@ -5,7 +5,7 @@ const React = require("react");
5
5
  const useIsomorphicLayoutEffect_esm = require("../../../use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.esm.js");
6
6
  const withSelector = require("../../../use-sync-external-store/shim/with-selector.js");
7
7
  const useConstant = require("./useConstant.js");
8
- var __read = globalThis && globalThis.__read || function(o, n) {
8
+ var __read = function(o, n) {
9
9
  var m = typeof Symbol === "function" && o[Symbol.iterator];
10
10
  if (!m)
11
11
  return o;
@@ -1 +1 @@
1
- {"version":3,"file":"fsm.js","sources":["../../../../../../../../node_modules/@xstate/react/es/fsm.js"],"sourcesContent":["var __read = (this && this.__read) || function (o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n};\nimport { createMachine, interpret, InterpreterStatus } from '@xstate/fsm';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';\nimport useConstant from './useConstant';\nfunction identity(a) {\n return a;\n}\nvar getServiceState = function (service) {\n var currentValue;\n service\n .subscribe(function (state) {\n currentValue = state;\n })\n .unsubscribe();\n return currentValue;\n};\nexport function useMachine(stateMachine, options) {\n var persistedStateRef = useRef();\n if (process.env.NODE_ENV !== 'production') {\n var _a = __read(useState(stateMachine), 1), initialMachine = _a[0];\n if (stateMachine !== initialMachine) {\n console.warn('Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.\\n' +\n 'Please make sure that you pass the same Machine as argument each time.');\n }\n }\n var _b = __read(useConstant(function () {\n var queue = [];\n var service = interpret(createMachine(stateMachine.config, options ? options : stateMachine._options));\n var send = service.send;\n service.send = function (event) {\n if (service.status === InterpreterStatus.NotStarted) {\n queue.push(event);\n return;\n }\n send(event);\n persistedStateRef.current = service.state;\n };\n return [service, queue];\n }), 2), service = _b[0], queue = _b[1];\n useIsomorphicLayoutEffect(function () {\n if (options) {\n service._machine._options = options;\n }\n });\n var useServiceResult = useService(service);\n useEffect(function () {\n service.start(persistedStateRef.current);\n queue.forEach(service.send);\n persistedStateRef.current = service.state;\n return function () {\n service.stop();\n };\n }, []);\n return useServiceResult;\n}\nvar isEqual = function (_prevState, nextState) { return nextState.changed === false; };\nexport function useService(service) {\n var getSnapshot = useCallback(function () { return getServiceState(service); }, [service]);\n var subscribe = useCallback(function (handleStoreChange) {\n var unsubscribe = service.subscribe(handleStoreChange).unsubscribe;\n return unsubscribe;\n }, [service]);\n var storeSnapshot = useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);\n return [storeSnapshot, service.send, service];\n}\n"],"names":["this","useRef","useState","queue","service","interpret","createMachine","InterpreterStatus","useIsomorphicLayoutEffect","useEffect","useCallback","useSyncExternalStoreWithSelector"],"mappings":";;;;;;;AAAA,IAAI,SAAUA,cAAQA,WAAK,UAAW,SAAU,GAAG,GAAG;AAClD,MAAI,IAAI,OAAO,WAAW,cAAc,EAAE,OAAO,QAAQ;AACzD,MAAI,CAAC;AAAG,WAAO;AACf,MAAI,IAAI,EAAE,KAAK,CAAC,GAAG,GAAG,KAAK,CAAE,GAAE;AAC/B,MAAI;AACA,YAAQ,MAAM,UAAU,MAAM,MAAM,EAAE,IAAI,EAAE,KAAM,GAAE;AAAM,S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AAS,WAAW;AAAA,IAC/B;AAAA,EACT,CAAK;AACD,MAAI,mBAAmB,WAAW,OAAO;AACzCC,QAAAA,UAAU,WAAY;AAClB,YAAQ,MAAM,kBAAkB,OAAO;AACvC,UAAM,QAAQ,QAAQ,IAAI;AAC1B,sBAAkB,UAAU,QAAQ;AACpC,WAAO,WAAY;AACf,cAAQ,KAAI;AAAA,IACxB;AAAA,EACK,GAAE,CAAE,CAAA;AACL,SAAO;AACX;AACA,IAAI,UAAU,SAAU,YAAY,WAAW;AAAE,SAAO,UAAU,YAAY;;AACvE,SAAS,WAAW,SAAS;AAChC,MAAI,cAAcC,kBAAY,WAAY;AAAE,WAAO,gBAAgB,OAAO;AAAA,EAAI,GAAE,CAAC,OAAO,CAAC;AACzF,MAAI,YAAYA,kBAAY,SAAU,mBAAmB;AACrD,QAAI,cAAc,QAAQ,UAAU,iBAAiB,EAAE;AACvD,WAAO;AAAA,EACf,GAAO,CAAC,OAAO,CAAC;AACZ,MAAI,gBAAgBC,aAAAA,oBAAAA,iCAAiC,WAAW,aAAa,aAAa,UAAU,OAAO;AAC3G,SAAO,CAAC,eAAe,QAAQ,MAAM,OAAO;AAChD;;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"fsm.js","sources":["../../../../../../../../node_modules/@xstate/react/es/fsm.js"],"sourcesContent":["var __read = (this && this.__read) || function (o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n};\nimport { createMachine, interpret, InterpreterStatus } from '@xstate/fsm';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';\nimport useConstant from './useConstant';\nfunction identity(a) {\n return a;\n}\nvar getServiceState = function (service) {\n var currentValue;\n service\n .subscribe(function (state) {\n currentValue = state;\n })\n .unsubscribe();\n return currentValue;\n};\nexport function useMachine(stateMachine, options) {\n var persistedStateRef = useRef();\n if (process.env.NODE_ENV !== 'production') {\n var _a = __read(useState(stateMachine), 1), initialMachine = _a[0];\n if (stateMachine !== initialMachine) {\n console.warn('Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.\\n' +\n 'Please make sure that you pass the same Machine as argument each time.');\n }\n }\n var _b = __read(useConstant(function () {\n var queue = [];\n var service = interpret(createMachine(stateMachine.config, options ? options : stateMachine._options));\n var send = service.send;\n service.send = function (event) {\n if (service.status === InterpreterStatus.NotStarted) {\n queue.push(event);\n return;\n }\n send(event);\n persistedStateRef.current = service.state;\n };\n return [service, queue];\n }), 2), service = _b[0], queue = _b[1];\n useIsomorphicLayoutEffect(function () {\n if (options) {\n service._machine._options = options;\n }\n });\n var useServiceResult = useService(service);\n useEffect(function () {\n service.start(persistedStateRef.current);\n queue.forEach(service.send);\n persistedStateRef.current = service.state;\n return function () {\n service.stop();\n };\n }, []);\n return useServiceResult;\n}\nvar isEqual = function (_prevState, nextState) { return nextState.changed === false; };\nexport function useService(service) {\n var getSnapshot = useCallback(function () { return getServiceState(service); }, [service]);\n var subscribe = useCallback(function (handleStoreChange) {\n var unsubscribe = service.subscribe(handleStoreChange).unsubscribe;\n return unsubscribe;\n }, [service]);\n var storeSnapshot = useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);\n return [storeSnapshot, service.send, service];\n}\n"],"names":["useRef","useState","queue","service","interpret","createMachine","InterpreterStatus","useIsomorphicLayoutEffect","useEffect","useCallback","useSyncExternalStoreWithSelector"],"mappings":";;;;;;;AAAA,IAAI,SAAkC,SAAU,GAAG,GAAG;AAClD,MAAI,IAAI,OAAO,WAAW,cAAc,EAAE,OAAO,QAAQ;AACzD,MA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AA,IAChD;AACQ,WAAO,CAACA,UAASD,MAAK;AAAA,EAC9B,CAAK,GAAG,CAAC,GAAG,UAAU,GAAG,CAAC,GAAG,QAAQ,GAAG,CAAC;AACrCK,gCAA0B,WAAY;AAClC,QAAI,SAAS;AACT,cAAQ,SAAS,WAAW;AAAA,IAC/B;AAAA,EACT,CAAK;AACD,MAAI,mBAAmB,WAAW,OAAO;AACzCC,QAAAA,UAAU,WAAY;AAClB,YAAQ,MAAM,kBAAkB,OAAO;AACvC,UAAM,QAAQ,QAAQ,IAAI;AAC1B,sBAAkB,UAAU,QAAQ;AACpC,WAAO,WAAY;AACf,cAAQ,KAAI;AAAA,IACxB;AAAA,EACK,GAAE,CAAE,CAAA;AACL,SAAO;AACX;AACA,IAAI,UAAU,SAAU,YAAY,WAAW;AAAE,SAAO,UAAU,YAAY;;AACvE,SAAS,WAAW,SAAS;AAChC,MAAI,cAAcC,kBAAY,WAAY;AAAE,WAAO,gBAAgB,OAAO;AAAA,EAAI,GAAE,CAAC,OAAO,CAAC;AACzF,MAAI,YAAYA,kBAAY,SAAU,mBAAmB;AACrD,QAAI,cAAc,QAAQ,UAAU,iBAAiB,EAAE;AACvD,WAAO;AAAA,EACf,GAAO,CAAC,OAAO,CAAC;AACZ,MAAI,gBAAgBC,aAAAA,oBAAAA,iCAAiC,WAAW,aAAa,aAAa,UAAU,OAAO;AAC3G,SAAO,CAAC,eAAe,QAAQ,MAAM,OAAO;AAChD;;;","x_google_ignoreList":[0]}
@@ -3,7 +3,7 @@ import { useRef, useState, useEffect, useCallback } from "react";
3
3
  import index from "../../../use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.esm.mjs";
4
4
  import { w as withSelectorExports } from "../../../use-sync-external-store/shim/with-selector.mjs";
5
5
  import useConstant from "./useConstant.mjs";
6
- var __read = globalThis && globalThis.__read || function(o, n2) {
6
+ var __read = function(o, n2) {
7
7
  var m = typeof Symbol === "function" && o[Symbol.iterator];
8
8
  if (!m)
9
9
  return o;