UNPKG

@shopify/hydrogen-react

Version:

React components, hooks, and utilities for creating custom Shopify storefronts

239 lines (227 loc) • 57.3 kB
(function(U,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],g):(U=typeof globalThis<"u"?globalThis:U||self,g(U.hydrogenreact={},U.React))})(this,function(U,g){"use strict";const fr=e=>e&&typeof e=="object"&&"default"in e?e:{default:e};function yr(e){if(e&&e.__esModule)return e;const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const w=fr(g),Se=yr(g);/*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */function ve(e,r){var t=typeof Symbol=="function"&&e[Symbol.iterator];if(!t)return e;var a,o,i=t.call(e),u=[];try{for(;(r===void 0||r-- >0)&&!(a=i.next()).done;)u.push(a.value)}catch(n){o={error:n}}finally{try{a&&!a.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return u}var Y;(function(e){e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped"})(Y||(Y={}));var be={type:"xstate.init"};function se(e){return e===void 0?[]:[].concat(e)}function Q(e){return{type:"xstate.assign",assignment:e}}function Te(e,r){return typeof(e=typeof e=="string"&&r&&r[e]?r[e]:e)=="string"?{type:e}:typeof e=="function"?{type:e.name,exec:e}:e}function ae(e){return function(r){return e===r}}function Ce(e){return typeof e=="string"?{type:e}:e}function Ae(e,r){return{value:e,context:r,actions:[],changed:!1,matches:ae(e)}}function Ne(e,r,t){var a=r,o=!1;return[e.filter(function(i){if(i.type==="xstate.assign"){o=!0;var u=Object.assign({},a);return typeof i.assignment=="function"?u=i.assignment(a,t):Object.keys(i.assignment).forEach(function(n){u[n]=typeof i.assignment[n]=="function"?i.assignment[n](a,t):i.assignment[n]}),a=u,!1}return!0}),a,o]}function we(e,r){r===void 0&&(r={});var t=ve(Ne(se(e.states[e.initial].entry).map(function(u){return Te(u,r.actions)}),e.context,be),2),a=t[0],o=t[1],i={config:e,_options:r,initialState:{value:e.initial,actions:a,context:o,matches:ae(e.initial)},transition:function(u,n){var l,d,h=typeof u=="string"?{value:u,context:e.context}:u,s=h.value,m=h.context,_=Ce(n),p=e.states[s];if(p.on){var A=se(p.on[_.type]);try{for(var f=function(D){var G=typeof Symbol=="function"&&Symbol.iterator,P=G&&D[G],ue=0;if(P)return P.call(D);if(D&&typeof D.length=="number")return{next:function(){return D&&ue>=D.length&&(D=void 0),{value:D&&D[ue++],done:!D}}};throw new TypeError(G?"Object is not iterable.":"Symbol.iterator is not defined.")}(A),S=f.next();!S.done;S=f.next()){var v=S.value;if(v===void 0)return Ae(s,m);var b=typeof v=="string"?{target:v}:v,c=b.target,y=b.actions,E=y===void 0?[]:y,N=b.cond,I=N===void 0?function(){return!0}:N,C=c===void 0,O=c!=null?c:s,R=e.states[O];if(I(m,_)){var V=ve(Ne((C?se(E):[].concat(p.exit,E,R.entry).filter(function(D){return D})).map(function(D){return Te(D,i._options.actions)}),m,_),3),F=V[0],W=V[1],K=V[2],q=c!=null?c:s;return{value:q,context:W,actions:F,changed:c!==s||F.length>0||K,matches:ae(q)}}}}catch(D){l={error:D}}finally{try{S&&!S.done&&(d=f.return)&&d.call(f)}finally{if(l)throw l.error}}}return Ae(s,m)}};return i}var Ie=function(e,r){return e.actions.forEach(function(t){var a=t.exec;return a&&a(e.context,r)})};function mr(e){var r=e.initialState,t=Y.NotStarted,a=new Set,o={_machine:e,send:function(i){t===Y.Running&&(r=e.transition(r,i),Ie(r,Ce(i)),a.forEach(function(u){return u(r)}))},subscribe:function(i){return a.add(i),i(r),{unsubscribe:function(){return a.delete(i)}}},start:function(i){if(i){var u=typeof i=="object"?i:{context:e.config.context,value:i};r={value:u.value,actions:[],context:u.context,matches:ae(u.value)}}else r=e.initialState;return t=Y.Running,Ie(r,be),o},stop:function(){return t=Y.Stopped,a.clear(),o},get state(){return r},get status(){return t}};return o}var _r=g.useLayoutEffect,Oe={exports:{}},le={},de={exports:{}},fe={};/** * @license React * use-sync-external-store-shim.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var De;function hr(){if(De)return fe;De=1;var e=w.default;function r(s,m){return s===m&&(s!==0||1/s===1/m)||s!==s&&m!==m}var t=typeof Object.is=="function"?Object.is:r,a=e.useState,o=e.useEffect,i=e.useLayoutEffect,u=e.useDebugValue;function n(s,m){var _=m(),p=a({inst:{value:_,getSnapshot:m}}),A=p[0].inst,f=p[1];return i(function(){A.value=_,A.getSnapshot=m,l(A)&&f({inst:A})},[s,_,m]),o(function(){return l(A)&&f({inst:A}),s(function(){l(A)&&f({inst:A})})},[s]),u(_),_}function l(s){var m=s.getSnapshot;s=s.value;try{var _=m();return!t(s,_)}catch{return!0}}function d(s,m){return m()}var h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?d:n;return fe.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:h,fe}var ye={};/** * @license React * use-sync-external-store-shim.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Le;function gr(){return Le||(Le=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=w.default,r=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function t(b){{for(var c=arguments.length,y=new Array(c>1?c-1:0),E=1;E<c;E++)y[E-1]=arguments[E];a("error",b,y)}}function a(b,c,y){{var E=r.ReactDebugCurrentFrame,N=E.getStackAddendum();N!==""&&(c+="%s",y=y.concat([N]));var I=y.map(function(C){return String(C)});I.unshift("Warning: "+c),Function.prototype.apply.call(console[b],console,I)}}function o(b,c){return b===c&&(b!==0||1/b===1/c)||b!==b&&c!==c}var i=typeof Object.is=="function"?Object.is:o,u=e.useState,n=e.useEffect,l=e.useLayoutEffect,d=e.useDebugValue,h=!1,s=!1;function m(b,c,y){h||e.startTransition!==void 0&&(h=!0,t("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var E=c();if(!s){var N=c();i(E,N)||(t("The result of getSnapshot should be cached to avoid an infinite loop"),s=!0)}var I=u({inst:{value:E,getSnapshot:c}}),C=I[0].inst,O=I[1];return l(function(){C.value=E,C.getSnapshot=c,_(C)&&O({inst:C})},[b,E,c]),n(function(){_(C)&&O({inst:C});var R=function(){_(C)&&O({inst:C})};return b(R)},[b]),d(E),E}function _(b){var c=b.getSnapshot,y=b.value;try{var E=c();return!i(y,E)}catch{return!0}}function p(b,c,y){return c()}var A=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",f=!A,S=f?p:m,v=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:S;ye.useSyncExternalStore=v,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),ye}var Ue;function Pe(){return Ue||(Ue=1,function(e){process.env.NODE_ENV==="production"?e.exports=hr():e.exports=gr()}(de)),de.exports}/** * @license React * use-sync-external-store-shim/with-selector.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Re;function Er(){if(Re)return le;Re=1;var e=w.default,r=Pe();function t(d,h){return d===h&&(d!==0||1/d===1/h)||d!==d&&h!==h}var a=typeof Object.is=="function"?Object.is:t,o=r.useSyncExternalStore,i=e.useRef,u=e.useEffect,n=e.useMemo,l=e.useDebugValue;return le.useSyncExternalStoreWithSelector=function(d,h,s,m,_){var p=i(null);if(p.current===null){var A={hasValue:!1,value:null};p.current=A}else A=p.current;p=n(function(){function S(E){if(!v){if(v=!0,b=E,E=m(E),_!==void 0&&A.hasValue){var N=A.value;if(_(N,E))return c=N}return c=E}if(N=c,a(b,E))return N;var I=m(E);return _!==void 0&&_(N,I)?N:(b=E,c=I)}var v=!1,b,c,y=s===void 0?null:s;return[function(){return S(h())},y===null?void 0:function(){return S(y())}]},[h,s,m,_]);var f=o(d,p[0],p[1]);return u(function(){A.hasValue=!0,A.value=f},[f]),l(f),f},le}var me={};/** * @license React * use-sync-external-store-shim/with-selector.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Me;function pr(){return Me||(Me=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=w.default,r=Pe();function t(h,s){return h===s&&(h!==0||1/h===1/s)||h!==h&&s!==s}var a=typeof Object.is=="function"?Object.is:t,o=r.useSyncExternalStore,i=e.useRef,u=e.useEffect,n=e.useMemo,l=e.useDebugValue;function d(h,s,m,_,p){var A=i(null),f;A.current===null?(f={hasValue:!1,value:null},A.current=f):f=A.current;var S=n(function(){var y=!1,E,N,I=function(V){if(!y){y=!0,E=V;var F=_(V);if(p!==void 0&&f.hasValue){var W=f.value;if(p(W,F))return N=W,W}return N=F,F}var K=E,q=N;if(a(K,V))return q;var D=_(V);return p!==void 0&&p(q,D)?q:(E=V,N=D,D)},C=m===void 0?null:m,O=function(){return I(s())},R=C===null?void 0:function(){return I(C())};return[O,R]},[s,m,_,p]),v=S[0],b=S[1],c=o(h,v,b);return u(function(){f.hasValue=!0,f.value=c},[c]),l(c),c}me.useSyncExternalStoreWithSelector=d,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),me}(function(e){process.env.NODE_ENV==="production"?e.exports=Er():e.exports=pr()})(Oe);function Sr(e){var r=Se.useRef();return r.current||(r.current={v:e()}),r.current.v}var $e=globalThis&&globalThis.__read||function(e,r){var t=typeof Symbol=="function"&&e[Symbol.iterator];if(!t)return e;var a=t.call(e),o,i=[],u;try{for(;(r===void 0||r-- >0)&&!(o=a.next()).done;)i.push(o.value)}catch(n){u={error:n}}finally{try{o&&!o.done&&(t=a.return)&&t.call(a)}finally{if(u)throw u.error}}return i};function vr(e){return e}var br=function(e){var r;return e.subscribe(function(t){r=t}).unsubscribe(),r};function Tr(e,r){var t=g.useRef();if(process.env.NODE_ENV!=="production"){var a=$e(g.useState(e),1),o=a[0];e!==o&&console.warn("Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.\nPlease make sure that you pass the same Machine as argument each time.")}var i=$e(Sr(function(){var d=[],h=mr(we(e.config,r||e._options)),s=h.send;return h.send=function(m){if(h.status===Y.NotStarted){d.push(m);return}s(m),t.current=h.state},[h,d]}),2),u=i[0],n=i[1];_r(function(){r&&(u._machine._options=r)});var l=Ar(u);return g.useEffect(function(){return u.start(t.current),n.forEach(u.send),t.current=u.state,function(){u.stop()}},[]),l}var Cr=function(e,r){return r.changed===!1};function Ar(e){var r=g.useCallback(function(){return br(e)},[e]),t=g.useCallback(function(o){var i=e.subscribe(o).unsubscribe;return i},[e]),a=Oe.exports.useSyncExternalStoreWithSelector(t,r,r,vr,Cr);return[a,e.send,e]}function B(e){if(!e){const r=`flattenConnection(): needs a 'connection' to flatten, but received '${e}' instead`;return console.error(r),[]}return e.nodes?e.nodes:e.edges?e.edges.map(r=>{if(!(r!=null&&r.node))throw new Error("Connection edges must contain nodes");return r.node}):[]}const Nr=e=>` mutation CartLineAdd($cartId: ID!, $lines: [CartLineInput!]!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) { cartLinesAdd(cartId: $cartId, lines: $lines) { cart { ...CartFragment } } } ${e} `,wr=e=>` mutation CartCreate($input: CartInput!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) { cartCreate(input: $input) { cart { ...CartFragment } } } ${e} `,Ir=e=>` mutation CartLineRemove($cartId: ID!, $lines: [ID!]!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) { cartLinesRemove(cartId: $cartId, lineIds: $lines) { cart { ...CartFragment } } } ${e} `,Or=e=>` mutation CartLineUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) { cartLinesUpdate(cartId: $cartId, lines: $lines) { cart { ...CartFragment } } } ${e} `,Dr=e=>` mutation CartNoteUpdate($cartId: ID!, $note: String, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) { cartNoteUpdate(cartId: $cartId, note: $note) { cart { ...CartFragment } } } ${e} `,Lr=e=>` mutation CartBuyerIdentityUpdate( $cartId: ID! $buyerIdentity: CartBuyerIdentityInput! $numCartLines: Int = 250 $country: CountryCode = ZZ ) @inContext(country: $country) { cartBuyerIdentityUpdate(cartId: $cartId, buyerIdentity: $buyerIdentity) { cart { ...CartFragment } } } ${e} `,Ur=e=>` mutation CartAttributesUpdate($attributes: [AttributeInput!]!, $cartId: ID!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) { cartAttributesUpdate(attributes: $attributes, cartId: $cartId) { cart { ...CartFragment } } } ${e} `,Pr=e=>` mutation CartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!], $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) { cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) { cart { ...CartFragment } } } ${e} `,Rr=e=>` query CartQuery($id: ID!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) { cart(id: $id) { ...CartFragment } } ${e} `,X="2022-10";var Mr="/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopifyProvider.tsx";const Ve=g.createContext({storeDomain:"test.myshopify.com",storefrontToken:"abc123",storefrontApiVersion:X,country:{isoCode:"US"},language:{isoCode:"EN"},locale:"EN-US"});function $r({children:e,shopifyConfig:r}){if(!r)throw new Error("The 'shopifyConfig' prop must be passed to '<ShopifyProvider/>'");r.storefrontApiVersion!==X&&console.warn(`This version of Hydrogen-UI is built for Shopify's Storefront API version ${X}, but it looks like you're using version ${r.storefrontApiVersion}. There may be issues or bugs if you use a mismatched version of Hydrogen-UI and the Storefront API.`);const t=g.useMemo(()=>({...r,storeDomain:r.storeDomain.replace(/^https?:\/\//,"")}),[r]);return w.default.createElement(Ve.Provider,{value:t,__self:this,__source:{fileName:Mr,lineNumber:49,columnNumber:5}},e)}function J(){const e=g.useContext(Ve);if(!e)throw new Error("'useShop()' must be a descendent of <ShopifyProvider/>");return e}const _e="shopifyCartId",Vr="X-Shopify-Storefront-Access-Token",kr="Shopify-Storefront-Id",Fr="Shopify-Storefront-Y",xr="Shopify-Storefront-S",ke="_shopify_y",Fe="_shopify_s";var jr=new Set(["domain","path","max-age","expires","samesite","secure","httponly"]);function qr(e){let r={},t,a,o=0,i=e.split(/;\s*/g),u,n;for(;o<i.length;o++)if(a=i[o],t=a.indexOf("="),~t){if(u=a.substring(0,t++).trim(),n=a.substring(t).trim(),n[0]==='"'&&(n=n.substring(1,n.length-1)),~n.indexOf("%"))try{n=decodeURIComponent(n)}catch{}jr.has(a=u.toLowerCase())?a==="expires"?r.expires=new Date(n):a==="max-age"?r.maxage=+n:r[a]=n:r[u]=n}else(u=a.trim().toLowerCase())&&(u==="httponly"||u==="secure")&&(r[u]=!0);return r}function Hr(){const{storeDomain:e,storefrontApiVersion:r,storefrontToken:t,storefrontId:a}=J();return g.useCallback(({query:o,variables:i})=>{const u={"Content-Type":"application/json","X-SDK-Variant":"hydrogen","X-SDK-Version":r,[Vr]:t};a&&(u[kr]=a);const n=qr(document.cookie);return n[ke]&&n[Fe]&&(u[Fr]=n[ke],u[xr]=n[Fe]),fetch(`https://${e}/api/${r}/graphql.json`,{method:"POST",headers:u,body:JSON.stringify({query:o.toString(),variables:i})}).then(l=>l.json()).catch(l=>({data:void 0,errors:l.toString()}))},[e,r,t,a])}function Br({numCartLines:e,cartFragment:r,countryCode:t="US"}){const a=Hr(),o=g.useCallback(_=>a({query:Rr(r),variables:{id:_,numCartLines:e,country:t}}),[a,r,e,t]),i=g.useCallback(_=>a({query:wr(r),variables:{input:_,numCartLines:e,country:t}}),[r,t,a,e]),u=g.useCallback((_,p)=>a({query:Nr(r),variables:{cartId:_,lines:p,numCartLines:e,country:t}}),[r,t,a,e]),n=g.useCallback((_,p)=>a({query:Or(r),variables:{cartId:_,lines:p,numCartLines:e,country:t}}),[r,t,a,e]),l=g.useCallback((_,p)=>a({query:Ir(r),variables:{cartId:_,lines:p,numCartLines:e,country:t}}),[r,t,a,e]),d=g.useCallback((_,p)=>a({query:Dr(r),variables:{cartId:_,note:p,numCartLines:e,country:t}}),[a,r,e,t]),h=g.useCallback((_,p)=>a({query:Lr(r),variables:{cartId:_,buyerIdentity:p,numCartLines:e,country:t}}),[r,t,a,e]),s=g.useCallback((_,p)=>a({query:Ur(r),variables:{cartId:_,attributes:p,numCartLines:e,country:t}}),[r,t,a,e]),m=g.useCallback((_,p)=>a({query:Pr(r),variables:{cartId:_,discountCodes:p,numCartLines:e,country:t}}),[r,t,a,e]);return g.useMemo(()=>({cartFetch:o,cartCreate:i,cartLineAdd:u,cartLineUpdate:n,cartLineRemove:l,noteUpdate:d,buyerIdentityUpdate:h,cartAttributesUpdate:s,discountCodesUpdate:m,cartFragment:r}),[o,i,u,n,l,d,h,s,m,r])}function x(e,r){return{entry:[...(r==null?void 0:r.entryActions)||[],"onCartActionEntry","onCartActionOptimisticUI",e],on:{RESOLVE:{target:(r==null?void 0:r.resolveTarget)||"idle",actions:[Q({prevCart:t=>t==null?void 0:t.cart,cart:(t,a)=>{var o;return(o=a==null?void 0:a.payload)==null?void 0:o.cart},rawCartResult:(t,a)=>{var o;return(o=a==null?void 0:a.payload)==null?void 0:o.rawCartResult},errors:t=>{}})]},ERROR:{target:(r==null?void 0:r.errorTarget)||"error",actions:[Q({prevCart:t=>t==null?void 0:t.cart,cart:t=>t==null?void 0:t.lastValidCart,errors:(t,a)=>{var o;return(o=a==null?void 0:a.payload)==null?void 0:o.errors}})]},CART_COMPLETED:{target:"cartCompleted",actions:Q({prevCart:t=>{},cart:t=>{},lastValidCart:t=>{},errors:t=>{}})}},exit:["onCartActionComplete",...(r==null?void 0:r.exitActions)||[]]}}const ee={CART_FETCH:{target:"cartFetching"},CART_CREATE:{target:"cartCreating"},CART_SET:{target:"idle",actions:[Q({rawCartResult:(e,r)=>r.payload.cart,cart:(e,r)=>he(r.payload.cart)})]}},xe={CARTLINE_ADD:{target:"cartLineAdding"},CARTLINE_UPDATE:{target:"cartLineUpdating"},CARTLINE_REMOVE:{target:"cartLineRemoving"},NOTE_UPDATE:{target:"noteUpdating"},BUYER_IDENTITY_UPDATE:{target:"buyerIdentityUpdating"},CART_ATTRIBUTES_UPDATE:{target:"cartAttributesUpdating"},DISCOUNT_CODES_UPDATE:{target:"discountCodesUpdating"}};function Wr(e){return we({id:"Cart",initial:e?"idle":"uninitialized",context:{cart:e&&he(e)},states:{uninitialized:{on:ee},cartCompleted:{on:ee},initializationError:{on:ee},idle:{on:{...ee,...xe}},error:{on:{...ee,...xe}},cartFetching:x("cartFetchAction",{errorTarget:"initializationError"}),cartCreating:x("cartCreateAction",{errorTarget:"initializationError"}),cartLineRemoving:x("cartLineRemoveAction"),cartLineUpdating:x("cartLineUpdateAction"),cartLineAdding:x("cartLineAddAction"),noteUpdating:x("noteUpdateAction"),buyerIdentityUpdating:x("buyerIdentityUpdateAction"),cartAttributesUpdating:x("cartAttributesUpdateAction"),discountCodesUpdating:x("discountCodesUpdateAction")}})}function Yr({numCartLines:e,onCartActionEntry:r,onCartActionOptimisticUI:t,onCartActionComplete:a,data:o,cartFragment:i,countryCode:u}){const{cartFetch:n,cartCreate:l,cartLineAdd:d,cartLineUpdate:h,cartLineRemove:s,noteUpdate:m,buyerIdentityUpdate:_,cartAttributesUpdate:p,discountCodesUpdate:A}=Br({numCartLines:e,cartFragment:i,countryCode:u}),f=g.useMemo(()=>Wr(o),[o]),[S,v,b]=Tr(f,{actions:{cartFetchAction:async(c,y)=>{var C;if(y.type!=="CART_FETCH")return;const{data:E,errors:N}=await n((C=y==null?void 0:y.payload)==null?void 0:C.cartId),I=j(y,E==null?void 0:E.cart,N);v(I)},cartCreateAction:async(c,y)=>{var C;if(y.type!=="CART_CREATE")return;const{data:E,errors:N}=await l(y==null?void 0:y.payload),I=j(y,(C=E==null?void 0:E.cartCreate)==null?void 0:C.cart,N);v(I)},cartLineAddAction:async(c,y)=>{var C,O;if(y.type!=="CARTLINE_ADD"||!((C=c==null?void 0:c.cart)!=null&&C.id))return;const{data:E,errors:N}=await d(c.cart.id,y.payload.lines),I=j(y,(O=E==null?void 0:E.cartLinesAdd)==null?void 0:O.cart,N);v(I)},cartLineUpdateAction:async(c,y)=>{var C,O;if(y.type!=="CARTLINE_UPDATE"||!((C=c==null?void 0:c.cart)!=null&&C.id))return;const{data:E,errors:N}=await h(c.cart.id,y.payload.lines),I=j(y,(O=E==null?void 0:E.cartLinesUpdate)==null?void 0:O.cart,N);v(I)},cartLineRemoveAction:async(c,y)=>{var C,O;if(y.type!=="CARTLINE_REMOVE"||!((C=c==null?void 0:c.cart)!=null&&C.id))return;const{data:E,errors:N}=await s(c.cart.id,y.payload.lines),I=j(y,(O=E==null?void 0:E.cartLinesRemove)==null?void 0:O.cart,N);v(I)},noteUpdateAction:async(c,y)=>{var C,O;if(y.type!=="NOTE_UPDATE"||!((C=c==null?void 0:c.cart)!=null&&C.id))return;const{data:E,errors:N}=await m(c.cart.id,y.payload.note),I=j(y,(O=E==null?void 0:E.cartNoteUpdate)==null?void 0:O.cart,N);v(I)},buyerIdentityUpdateAction:async(c,y)=>{var C,O;if(y.type!=="BUYER_IDENTITY_UPDATE"||!((C=c==null?void 0:c.cart)!=null&&C.id))return;const{data:E,errors:N}=await _(c.cart.id,y.payload.buyerIdentity),I=j(y,(O=E==null?void 0:E.cartBuyerIdentityUpdate)==null?void 0:O.cart,N);v(I)},cartAttributesUpdateAction:async(c,y)=>{var C,O;if(y.type!=="CART_ATTRIBUTES_UPDATE"||!((C=c==null?void 0:c.cart)!=null&&C.id))return;const{data:E,errors:N}=await p(c.cart.id,y.payload.attributes),I=j(y,(O=E==null?void 0:E.cartAttributesUpdate)==null?void 0:O.cart,N);v(I)},discountCodesUpdateAction:async(c,y)=>{var C,O;if(y.type!=="DISCOUNT_CODES_UPDATE"||!((C=c==null?void 0:c.cart)!=null&&C.id))return;const{data:E,errors:N}=await A(c.cart.id,y.payload.discountCodes),I=j(y,(O=E==null?void 0:E.cartDiscountCodesUpdate)==null?void 0:O.cart,N);v(I)},...r&&{onCartActionEntry:(c,y)=>{Gr(y)&&r(c,y)}},...t&&{onCartActionOptimisticUI:Q((c,y)=>t(c,y))},...a&&{onCartActionComplete:(c,y)=>{Zr(y)&&a(c,y)}}}});return g.useMemo(()=>[S,v,b],[S,v,b])}function he(e){var r;return{...e,lines:B(e==null?void 0:e.lines),note:(r=e.note)!=null?r:void 0}}function j(e,r,t){return t?{type:"ERROR",payload:{errors:t,cartActionEvent:e}}:r?{type:"RESOLVE",payload:{cart:he(r),rawCartResult:r,cartActionEvent:e}}:{type:"CART_COMPLETED",payload:{cartActionEvent:e}}}function Gr(e){return e.type==="CART_CREATE"||e.type==="CARTLINE_ADD"||e.type==="CARTLINE_UPDATE"||e.type==="CARTLINE_REMOVE"||e.type==="NOTE_UPDATE"||e.type==="BUYER_IDENTITY_UPDATE"||e.type==="CART_ATTRIBUTES_UPDATE"||e.type==="DISCOUNT_CODES_UPDATE"}function Zr(e){return e.type==="RESOLVE"||e.type==="ERROR"||e.type==="CART_COMPLETED"}var Kr="/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/CartProvider.tsx";const je=g.createContext(null);function zr(){const e=g.useContext(je);if(!e)throw new Error("Expected a Cart Context, but no Cart Context was found");return e}function Qr({children:e,numCartLines:r,onCreate:t,onLineAdd:a,onLineRemove:o,onLineUpdate:i,onNoteUpdate:u,onBuyerIdentityUpdate:n,onAttributesUpdate:l,onDiscountCodesUpdate:d,onCreateComplete:h,onLineAddComplete:s,onLineRemoveComplete:m,onLineUpdateComplete:_,onNoteUpdateComplete:p,onBuyerIdentityUpdateComplete:A,onAttributesUpdateComplete:f,onDiscountCodesUpdateComplete:S,data:v,cartFragment:b=rt,customerAccessToken:c,countryCode:y="US"}){var ir,or,ur,cr,sr,lr,dr;y&&(y=y.toUpperCase());const[E,N]=g.useState(y),[I,C]=g.useState(c),O=g.useRef(!1);(E!==y||I!==c)&&(N(y),C(c),O.current=!1);const[R,V]=Yr({numCartLines:r,data:v,cartFragment:b,countryCode:y,onCartActionEntry(T,M){try{switch(M.type){case"CART_CREATE":return t==null?void 0:t();case"CARTLINE_ADD":return a==null?void 0:a();case"CARTLINE_REMOVE":return o==null?void 0:o();case"CARTLINE_UPDATE":return i==null?void 0:i();case"NOTE_UPDATE":return u==null?void 0:u();case"BUYER_IDENTITY_UPDATE":return n==null?void 0:n();case"CART_ATTRIBUTES_UPDATE":return l==null?void 0:l();case"DISCOUNT_CODES_UPDATE":return d==null?void 0:d()}}catch(k){console.error("Cart entry action failed",k)}},onCartActionOptimisticUI(T,M){var k,H,te,ne;if(!(T!=null&&T.cart))return{cart:void 0};switch(M.type){case"CARTLINE_REMOVE":return{...T,lastValidCart:T.cart,cart:{...T.cart,lines:(H=(k=T==null?void 0:T.cart)==null?void 0:k.lines)==null?void 0:H.filter(L=>(L==null?void 0:L.id)&&!M.payload.lines.includes(L==null?void 0:L.id))}};case"CARTLINE_UPDATE":return{...T,lastValidCart:T.cart,cart:{...T.cart,lines:(ne=(te=T==null?void 0:T.cart)==null?void 0:te.lines)==null?void 0:ne.map(L=>{const z=M.payload.lines.find(({id:ce})=>ce===(L==null?void 0:L.id));return z&&z.quantity?{...L,quantity:z.quantity}:L})}}}return{cart:T.cart?{...T.cart}:void 0}},onCartActionComplete(T,M){const k=M.payload.cartActionEvent;try{switch(M.type){case"RESOLVE":switch(k.type){case"CART_CREATE":return h==null?void 0:h();case"CARTLINE_ADD":return s==null?void 0:s();case"CARTLINE_REMOVE":return m==null?void 0:m();case"CARTLINE_UPDATE":return _==null?void 0:_();case"NOTE_UPDATE":return p==null?void 0:p();case"BUYER_IDENTITY_UPDATE":return et(T,k)&&(O.current=!0),A==null?void 0:A();case"CART_ATTRIBUTES_UPDATE":return f==null?void 0:f();case"DISCOUNT_CODES_UPDATE":return S==null?void 0:S()}}}catch(H){console.error("onCartActionComplete failed",H)}}}),F=g.useRef(!1),W=R.matches("cartCompleted"),K=(R.value==="idle"||R.value==="error"||R.value==="cartCompleted")&&y!==((ur=(or=(ir=R==null?void 0:R.context)==null?void 0:ir.cart)==null?void 0:or.buyerIdentity)==null?void 0:ur.countryCode)&&!R.context.errors,q=g.useRef(!1);g.useEffect(()=>{if(!F.current&&!q.current){if(!v&&ge("localStorage")){q.current=!0;try{const T=window.localStorage.getItem(_e);T&&V({type:"CART_FETCH",payload:{cartId:T}})}catch(T){console.warn("error fetching cartId"),console.warn(T)}}F.current=!0}},[v,F,V]),g.useEffect(()=>{!K||O.current||V({type:"BUYER_IDENTITY_UPDATE",payload:{buyerIdentity:{countryCode:y,customerAccessToken:c}}})},[y,c,K,O,V]);const D=g.useCallback(T=>{if(!F.current)return console.warn("Cart isn't ready yet");V(T)},[V]);g.useEffect(()=>{var T,M,k;if(((M=(T=R==null?void 0:R.context)==null?void 0:T.cart)==null?void 0:M.id)&&ge("localStorage"))try{window.localStorage.setItem(_e,(k=R.context.cart)==null?void 0:k.id)}catch(H){console.warn("Failed to save cartId to localStorage",H)}},[(sr=(cr=R==null?void 0:R.context)==null?void 0:cr.cart)==null?void 0:sr.id]),g.useEffect(()=>{if(W&&ge("localStorage"))try{window.localStorage.removeItem(_e)}catch(T){console.warn("Failed to delete cartId from localStorage",T)}},[W]);const G=g.useCallback(T=>{var M,k;y&&!((M=T.buyerIdentity)!=null&&M.countryCode)&&(T.buyerIdentity==null&&(T.buyerIdentity={}),T.buyerIdentity.countryCode=y),c&&!((k=T.buyerIdentity)!=null&&k.customerAccessToken)&&(T.buyerIdentity==null&&(T.buyerIdentity={}),T.buyerIdentity.customerAccessToken=c),D({type:"CART_CREATE",payload:T})},[y,c,D]),P=Jr(R),ue=g.useMemo(()=>{var T,M,k,H,te,ne;return{...(M=(T=P==null?void 0:P.context)==null?void 0:T.cart)!=null?M:{lines:[],attributes:[]},status:Xr(P.value),error:(k=P==null?void 0:P.context)==null?void 0:k.errors,totalQuantity:(ne=(te=(H=P==null?void 0:P.context)==null?void 0:H.cart)==null?void 0:te.totalQuantity)!=null?ne:0,cartCreate:G,linesAdd(L){var z,ce;(ce=(z=P==null?void 0:P.context)==null?void 0:z.cart)!=null&&ce.id?D({type:"CARTLINE_ADD",payload:{lines:L}}):G({lines:L})},linesRemove(L){D({type:"CARTLINE_REMOVE",payload:{lines:L}})},linesUpdate(L){D({type:"CARTLINE_UPDATE",payload:{lines:L}})},noteUpdate(L){D({type:"NOTE_UPDATE",payload:{note:L}})},buyerIdentityUpdate(L){D({type:"BUYER_IDENTITY_UPDATE",payload:{buyerIdentity:L}})},cartAttributesUpdate(L){D({type:"CART_ATTRIBUTES_UPDATE",payload:{attributes:L}})},discountCodesUpdate(L){D({type:"DISCOUNT_CODES_UPDATE",payload:{discountCodes:L}})},cartFragment:b}},[G,(lr=P==null?void 0:P.context)==null?void 0:lr.cart,(dr=P==null?void 0:P.context)==null?void 0:dr.errors,P.value,b,D]);return w.default.createElement(je.Provider,{value:ue,__self:this,__source:{fileName:Kr,lineNumber:425,columnNumber:5}},e)}function Xr(e){switch(e){case"uninitialized":case"initializationError":return"uninitialized";case"idle":case"cartCompleted":case"error":return"idle";case"cartFetching":return"fetching";case"cartCreating":return"creating";case"cartLineAdding":case"cartLineRemoving":case"cartLineUpdating":case"noteUpdating":case"buyerIdentityUpdating":case"cartAttributesUpdating":case"discountCodesUpdating":return"updating"}}function Jr(e){const[r,t]=g.useTransition(),[a,o]=g.useState(e),i=g.useRef(!1);r&&(i.current=!0);const u=g.useRef(!1);return!r&&i.current&&(u.current=!0),g.useEffect(()=>{t(()=>{u.current||o(e)})},[e]),u.current?e:a}function ge(e){let r;try{r=window[e];const t="__storage_test__";return r.setItem(t,t),r.removeItem(t),!0}catch(t){return t instanceof DOMException&&(t.code===22||t.code===1014||t.name==="QuotaExceededError"||t.name==="NS_ERROR_DOM_QUOTA_REACHED")&&r&&r.length!==0}}function et(e,r){var t,a;return r.payload.buyerIdentity.countryCode&&((a=(t=e.cart)==null?void 0:t.buyerIdentity)==null?void 0:a.countryCode)!==r.payload.buyerIdentity.countryCode}const rt=` fragment CartFragment on Cart { id checkoutUrl totalQuantity buyerIdentity { countryCode customer { id email firstName lastName displayName } email phone } lines(first: $numCartLines) { edges { node { id quantity attributes { key value } cost { totalAmount { amount currencyCode } compareAtAmountPerQuantity { amount currencyCode } } merchandise { ... on ProductVariant { id availableForSale compareAtPriceV2 { ...MoneyFragment } priceV2 { ...MoneyFragment } requiresShipping title image { ...ImageFragment } product { handle title } selectedOptions { name value } } } } } } cost { subtotalAmount { ...MoneyFragment } totalAmount { ...MoneyFragment } totalDutyAmount { ...MoneyFragment } totalTaxAmount { ...MoneyFragment } } note attributes { key value } discountCodes { code } } fragment MoneyFragment on MoneyV2 { currencyCode amount } fragment ImageFragment on Image { id url altText width height } `;var tt="/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ExternalVideo.tsx";function qe(e){var h,s;const{data:r,options:t,id:a=r.id,frameBorder:o="0",allow:i="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:u=!0,loading:n="lazy",...l}=e;if(!r.embedUrl)throw new Error("<ExternalVideo/> requires the 'embedUrl' property");let d=r.embedUrl;if(t){const m=new URL(r.embedUrl);for(const _ of Object.keys(t))m.searchParams.set(_,t[_]);d=m.toString()}return w.default.createElement("iframe",{...l,id:a!=null?a:r.embedUrl,title:(s=(h=r.alt)!=null?h:r.id)!=null?s:"external video",frameBorder:o,allow:i,allowFullScreen:u,src:d,loading:n,__self:this,__source:{fileName:tt,lineNumber:56,columnNumber:5}})}const nt=["cdn.shopify.com","cdn.shopifycdn.net","shopify-assets.shopifycdn.com","shopify-assets.shopifycdn.net"],at=["spin.dev"],it=[...nt,...at],re=[352,832,1200,1920,2560];function He({src:e,width:r,height:t,crop:a,scale:o}){const i=new URL(e),u=o!=null?o:1;if(r){let n;typeof r=="string"?n=(re[0]*u).toString():n=(Number(r)*u).toString(),i.searchParams.append("width",n)}return t&&typeof t=="number"&&i.searchParams.append("height",(t*u).toString()),a&&i.searchParams.append("crop",a),i.toString()}function Be(e){const r=new URL(e.src);return!it.some(a=>r.hostname.endsWith(a))||!e.width&&!e.height&&!e.crop&&!e.scale?e.src:He(e)}function ot({data:e,loaderOptions:r,elementProps:t}){var o,i,u,n,l,d;let a=null;return(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&(a=(e==null?void 0:e.width)/(e==null?void 0:e.height)),(r==null?void 0:r.width)||(r==null?void 0:r.height)?{width:(o=r==null?void 0:r.width)!=null?o:a&&typeof r.height=="number"?Math.round(a*r.height):null,height:(i=r==null?void 0:r.height)!=null?i:a&&typeof r.width=="number"?Math.round(a*r.width):null}:(t==null?void 0:t.width)||(t==null?void 0:t.height)?{width:(u=t==null?void 0:t.width)!=null?u:a&&typeof t.height=="number"?Math.round(a*t.height):null,height:(n=t==null?void 0:t.height)!=null?n:a&&typeof t.width=="number"?Math.round(a*t.width):null}:(e==null?void 0:e.width)||(e==null?void 0:e.height)?{width:(l=e==null?void 0:e.width)!=null?l:null,height:(d=e==null?void 0:e.height)!=null?d:null}:{width:null,height:null}}var ut="/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Image.tsx";function ie({data:e,width:r,height:t,loading:a,loader:o=Be,loaderOptions:i,widths:u,decoding:n="async",...l}){var p,A,f,S,v,b;if(!e.url){const c=`<Image/>: the 'data' prop requires the 'url' property. Image: ${(p=e.id)!=null?p:"no ID provided"}`;return console.error(c),null}const{width:d,height:h}=ot({data:e,loaderOptions:i,elementProps:{width:r,height:t}});let s=e.url;if(o&&(s=o({...i,src:e.url,width:d,height:h}),typeof s!="string"||!s))throw new Error(`<Image/>: 'loader' did not return a valid string. Image: ${(A=e.id)!=null?A:e.url}`);const m=r&&d&&r<d?r:d,_=(f=l.srcSet)!=null?f:ct({...i,widths:u,src:e.url,width:m,height:h,loader:o});return Se.createElement("img",{id:(S=e.id)!=null?S:"",alt:(b=(v=e.altText)!=null?v:l.alt)!=null?b:"",loading:a!=null?a:"lazy",...l,src:s,width:d!=null?d:void 0,height:h!=null?h:void 0,srcSet:_,decoding:n,__self:this,__source:{fileName:ut,lineNumber:150,columnNumber:5}})}function ct({src:e,width:r,crop:t,scale:a,widths:o,loader:i,height:u}){const n=o&&Array.isArray(o);if(n&&o.some(s=>isNaN(s)))throw new Error(`<Image/>: the 'widths' must be an array of numbers. Image: ${e}`);let l=1;r&&u&&(l=Number(u)/Number(r));let d=n?o:re;!n&&r&&r<re[re.length-1]&&(d=re.filter(s=>s<=r));const h=i||He;return d.map(s=>`${h({src:e,width:s,height:t?Number(s)*l:void 0,crop:t,scale:a})} ${s}w`).join(", ")}var We="/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Video.tsx";function Ee(e){var d,h;const{data:r,previewImageOptions:t,id:a=r.id,playsInline:o=!0,controls:i=!0,sourceProps:u={},...n}=e,l=Be({src:(h=(d=r.previewImage)==null?void 0:d.url)!=null?h:"",...t});if(!r.sources)throw new Error("<Video/> requires a 'data.sources' array");return w.default.createElement("video",{...n,id:a,playsInline:o,controls:i,poster:l,__self:this,__source:{fileName:We,lineNumber:42,columnNumber:5}},r.sources.map(s=>{if(!((s==null?void 0:s.url)&&(s==null?void 0:s.mimeType)))throw new Error("<Video/> needs 'source.url' and 'source.mimeType'");return w.default.createElement("source",{...u,key:s.url,src:s.url,type:s.mimeType,__self:this,__source:{fileName:We,lineNumber:54,columnNumber:11}})}))}const Ye={};function st(e,r){const t=Ye[e];if(t)return t;const a=new Promise((o,i)=>{const u=document.createElement("script");r!=null&&r.module?u.type="module":u.type="text/javascript",u.src=e,u.onload=()=>{o(!0)},u.onerror=()=>{i(!1)},(r==null?void 0:r.in)==="head"?document.head.appendChild(u):document.body.appendChild(u)});return Ye[e]=a,a}function Ge(e,r){const[t,a]=g.useState("loading"),o=JSON.stringify(r);return g.useEffect(()=>{async function i(){try{a("loading"),await st(e,r),a("done")}catch{a("error")}}i()},[e,o,r]),t}var lt="/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ModelViewer.tsx";function Ze(e){var d,h,s,m,_,p,A,f,S,v,b;const[r,t]=g.useState(void 0),a=g.useCallback(c=>{t(c)},[]),{data:o,children:i,className:u,...n}=e,l=Ge("https://unpkg.com/@google/model-viewer@v1.12.1/dist/model-viewer.min.js",{module:!0});return g.useEffect(()=>{if(!!r)return n.onError&&r.addEventListener("error",n.onError),n.onLoad&&r.addEventListener("load",n.onLoad),n.onPreload&&r.addEventListener("preload",n.onPreload),n.onModelVisibility&&r.addEventListener("model-visibility",n.onModelVisibility),n.onProgress&&r.addEventListener("progress",n.onProgress),n.onArStatus&&r.addEventListener("ar-status",n.onArStatus),n.onArTracking&&r.addEventListener("ar-tracking",n.onArTracking),n.onQuickLookButtonTapped&&r.addEventListener("quick-look-button-tapped",n.onQuickLookButtonTapped),n.onCameraChange&&r.addEventListener("camera-change",n.onCameraChange),n.onEnvironmentChange&&r.addEventListener("environment-change",n.onEnvironmentChange),n.onPlay&&r.addEventListener("play",n.onPlay),n.onPause&&r.addEventListener("ar-status",n.onPause),n.onSceneGraphReady&&r.addEventListener("scene-graph-ready",n.onSceneGraphReady),()=>{r!=null&&(n.onError&&r.removeEventListener("error",n.onError),n.onLoad&&r.removeEventListener("load",n.onLoad),n.onPreload&&r.removeEventListener("preload",n.onPreload),n.onModelVisibility&&r.removeEventListener("model-visibility",n.onModelVisibility),n.onProgress&&r.removeEventListener("progress",n.onProgress),n.onArStatus&&r.removeEventListener("ar-status",n.onArStatus),n.onArTracking&&r.removeEventListener("ar-tracking",n.onArTracking),n.onQuickLookButtonTapped&&r.removeEventListener("quick-look-button-tapped",n.onQuickLookButtonTapped),n.onCameraChange&&r.removeEventListener("camera-change",n.onCameraChange),n.onEnvironmentChange&&r.removeEventListener("environment-change",n.onEnvironmentChange),n.onPlay&&r.removeEventListener("play",n.onPlay),n.onPause&&r.removeEventListener("ar-status",n.onPause),n.onSceneGraphReady&&r.removeEventListener("scene-graph-ready",n.onSceneGraphReady))}},[r,n.onArStatus,n.onArTracking,n.onCameraChange,n.onEnvironmentChange,n.onError,n.onLoad,n.onModelVisibility,n.onPause,n.onPlay,n.onPreload,n.onProgress,n.onQuickLookButtonTapped,n.onSceneGraphReady]),l!=="done"?null:(h=(d=o.sources)==null?void 0:d[0])!=null&&h.url?w.default.createElement("model-viewer",{ref:a,...n,className:u,id:(s=n.id)!=null?s:o.id,src:o.sources[0].url,alt:(m=o.alt)!=null?m:null,"camera-controls":(_=n.cameraControls)!=null?_:!0,poster:(A=n.poster||((p=o.previewImage)==null?void 0:p.url))!=null?A:null,autoplay:(f=n.autoplay)!=null?f:!0,loading:n.loading,reveal:n.reveal,ar:n.ar,"ar-modes":n.arModes,"ar-scale":n.arScale,"ar-placement":n.arPlacement,"ios-src":n.iosSrc,"touch-action":n.touchAction,"disable-zoom":n.disableZoom,"orbit-sensitivity":n.orbitSensitivity,"auto-rotate":n.autoRotate,"auto-rotate-delay":n.autoRotateDelay,"rotation-per-second":n.rotationPerSecond,"interaction-policy":n.interactionPolicy,"interaction-prompt":n.interactionPrompt,"interaction-prompt-style":n.interactionPromptStyle,"interaction-prompt-threshold":n.interactionPromptThreshold,"camera-orbit":n.cameraOrbit,"camera-target":n.cameraTarget,"field-of-view":n.fieldOfView,"max-camera-orbit":n.maxCameraOrbit,"min-camera-orbit":n.minCameraOrbit,"max-field-of-view":n.maxFieldOfView,"min-field-of-view":n.minFieldOfView,bounds:n.bounds,"interpolation-decay":(S=n.interpolationDecay)!=null?S:100,"skybox-image":n.skyboxImage,"environment-image":n.environmentImage,exposure:n.exposure,"shadow-intensity":(v=n.shadowIntensity)!=null?v:0,"shadow-softness":(b=n.shadowSoftness)!=null?b:0,"animation-name":n.animationName,"animation-crossfade-duration":n.animationCrossfadeDuration,"variant-name":n.variantName,orientation:n.orientation,scale:n.scale,__self:this,__source:{fileName:lt,lineNumber:222,columnNumber:5}},i):(console.error("<ModelViewer/> requires 'data.sources' prop to be an array, with an object that has a property 'url' on it. Rendering 'null'"),null)}var oe="/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/MediaFile.tsx";function dt({data:e,mediaOptions:r,...t}){switch(e.__typename){case"MediaImage":return e.image?w.default.createElement(ie,{...t,...r==null?void 0:r.image,data:e.image,__self:this,__source:{fileName:oe,lineNumber:50,columnNumber:9}}):(console.warn("<MediaFile/>: 'data.image' does not exist for __typename of 'MediaImage'; rendering 'null' by default."),null);case"Video":return w.default.createElement(Ee,{...t,...r==null?void 0:r.video,data:e,__self:this,__source:{fileName:oe,lineNumber:59,columnNumber:9}});case"ExternalVideo":return w.default.createElement(qe,{...t,...r==null?void 0:r.externalVideo,data:e,__self:this,__source:{fileName:oe,lineNumber:64,columnNumber:9}});case"Model3d":return w.default.createElement(Ze,{...t,...r==null?void 0:r.modelViewer,data:e,__self:this,__source:{fileName:oe,lineNumber:73,columnNumber:9}});default:return console.error("<MediaFile /> requires the '__typename' property to exist on the 'data' prop in order to correctly render the correct component for this media. Rendering 'null' by default"),null}}var $="/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Metafield.tsx";function ft(e){var n,l,d,h,s,m,_,p,A;const{data:r,as:t,...a}=e,{locale:o}=J(),i=g.useMemo(()=>Ke(r),[r]);if(!i)return console.warn("<Metafield/>: nothing was passed to the data prop 'data'. Rendering 'null'"),null;if(i.value===null||i.value===void 0){const f=`<Metafield/>: No metafield value for metafield ${(n=i.id)!=null?n:i.key}. Rendering 'null'`;return console.warn(f),null}switch(i.type){case"date":{const f=t!=null?t:"time";return w.default.createElement(f,{...a,__self:this,__source:{fileName:$,lineNumber:68,columnNumber:9}},i.value.toLocaleDateString(o))}case"date_time":{const f=t!=null?t:"time";return w.default.createElement(f,{...a,__self:this,__source:{fileName:$,lineNumber:76,columnNumber:9}},i.value.toLocaleString(o))}case"weight":case"dimension":case"volume":{const f=t!=null?t:"span";return w.default.createElement(f,{...a,__self:this,__source:{fileName:$,lineNumber:86,columnNumber:9}},_t(i.value,o))}case"rating":{const f=t!=null?t:"span";return w.default.createElement(f,{...a,__self:this,__source:{fileName:$,lineNumber:94,columnNumber:9}},i.value.value)}case"single_line_text_field":{const f=t!=null?t:"span";return w.default.createElement(f,{...a,dangerouslySetInnerHTML:{__html:i.value},__self:this,__source:{fileName:$,lineNumber:102,columnNumber:9}})}case"multi_line_text_field":{const f=t!=null?t:"div";return w.default.createElement(f,{...a,dangerouslySetInnerHTML:{__html:i.value.split(` `).join("<br/>")},__self:this,__source:{fileName:$,lineNumber:111,columnNumber:9}})}case"url":{const f=new URL(i.value);return w.default.createElement("a",{href:f.href.replace(f.protocol,""),...a,__self:this,__source:{fileName:$,lineNumber:122,columnNumber:9}},i.value)}case"json":{const f=t!=null?t:"span";return w.default.createElement(f,{...a,__self:this,__source:{fileName:$,lineNumber:133,columnNumber:9}},JSON.stringify(i.value))}case"product_reference":case"variant_reference":case"page_reference":{const f=t!=null?t:"span",S=i.reference;return w.default.createElement(f,{...a,__self:this,__source:{fileName:$,lineNumber:144,columnNumber:9}},(d=(l=S==null?void 0:S.title)!=null?l:S==null?void 0:S.id)!=null?d:"")}case"list.single_line_text_field":{const f=t!=null?t:"ul",S=i.references?B(i.references):[];return w.default.createElement(f,{...a,__self:this,__source:{fileName:$,lineNumber:154,columnNumber:9}},S.map((v,b)=>w.default.createElement("li",{key:`${v!=null?v:""}-${b}`,__self:this,__source:{fileName:$,lineNumber:158,columnNumber:13}},v)))}case"file_reference":if(((h=i.reference)==null?void 0:h.__typename)==="MediaImage"){const f=i.reference;return f.image?w.default.createElement(ie,{data:f.image,...a,__self:this,__source:{fileName:$,lineNumber:167,columnNumber:11}}):null}else if(((s=i.reference)==null?void 0:s.__typename)==="GenericFile"){const f=i.reference;return f.previewImage?w.default.createElement("a",{href:(_=(m=i.reference)==null?void 0:m.url)!=null?_:"",...a,__self:this,__source:{fileName:$,lineNumber:172,columnNumber:11}},w.default.createElement(ie,{data:f.previewImage,__self:this,__source:{fileName:$,lineNumber:173,columnNumber:13}})):null}else if(((p=i.reference)==null?void 0:p.__typename)==="Video"){const f=i.reference;return w.default.createElement(Ee,{...a,data:f,__self:this,__source:{fileName:$,lineNumber:178,columnNumber:16}})}}const u=t!=null?t:"span";return w.default.createElement(u,{...a,__self:this,__source:{fileName:$,lineNumber:185,columnNumber:5}},(A=i.value)==null?void 0:A.toString())}function Ke(e){return e?{...e,value:ze(e)}:null}function ze(e){if(!e)return null;if(e.value===null||e.value===void 0)return e.value;switch(e.type){case"boolean":return e.value==="true";case"number_integer":return parseInt(e.value);case"number_decimal":return parseFloat(e.value);case"date":case"date_time":return new Date(e.value);case"json":case"weight":case"dimension":case"volume":case"rating":return yt(e.value);case"color":case"single_line_text_field":case"multi_line_text_field":case"product_reference":case"page_reference":case"variant_reference":case"file_reference":case"url":default:return e.value}}function yt(e){return String(e).includes("__proto__")?JSON.parse(e,(r,t)=>{if(r!=="__proto__")return t}):JSON.parse(e)}const mt={mm:"millimeter",cm:"centimeter",m:"meter",in:"inch",ft:"foot",yd:"yard",ml:"milliliter",l:"liter",us_fl_oz:"fluid-ounce",us_gal:"gallon",kg:"kilogram",g:"gram",lb:"pound",oz:"ounce"};function _t(e,r="en-us",t={}){let a={value:e.value,unit:mt[e.unit]};return a.unit==null&&(a=ht(e.value,e.unit)),new Intl.NumberFormat(r,{...t,unit:a.unit,style:"unit"}).format(a.value)}function ht(e,r){switch(r){case"cl":return{value:e/1e3,unit:"liter"};case"m3":return{value:e*1e3,unit:"liter"};case"us_pt":return{value:e*.125,unit:"gallon"};case"us_qt":return{value:e*.5,unit:"gallon"};case"us_oz":return{value:e/128,unit:"gallon"};case"imp_pt":return{value:e/6.661,unit:"gallon"};case"imp_qt":return{value:e/3.331,unit:"gallon"};case"imp_gal":return{value:e/1.201,unit:"gallon"};case"imp_fl_oz":return{value:e*.96076,unit:"fluid-ounce"};default:throw new Error(`Unit not supported: ${r}`)}}function Qe(e){const{locale:r}=J();if(!r)throw new Error("useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work");const t=parseFloat(e.amount),a=g.useMemo(()=>({style:"currency",currency:e.currencyCode}),[e.currencyCode]),o=Z(r,a),i=Z(r,{...a,currencyDisplay:"name"}),u=Z(r,{...a,currencyDisplay:"narrowSymbol"}),n=Z(r,{...a,minimumFractionDigits:0,maximumFractionDigits:0}),l=Z(r),d=Z(r,{minimumFractionDigits:0,maximumFractionDigits:0}),h=m=>m.type==="currency",s=g.useMemo(()=>({original:()=>e,currencyCode:()=>e.currencyCode,localizedString:()=>o().format(t),parts:()=>o().formatToParts(t),withoutTrailingZeros:()=>t%1===0?n().format(t):o().format(t),withoutTrailingZerosAndCurrency:()=>t%1===0?d().format(t):l().format(t),currencyName:()=>{var m,_;return(_=(m=i().formatToParts(t).find(h))==null?void 0:m.value)!=null?_:e.currencyCode},currencySymbol:()=>{var m,_;return(_=(m=o().formatToParts(t).find(h))==null?void 0:m.value)!=null?_:e.currencyCode},currencyNarrowSymbol:()=>{var m,_;return(_=(m=u().formatToParts(t).find(h))==null?void 0:m.value)!=null?_:""},amount:()=>o().formatToParts(t).filter(m=>["decimal","fraction","group","integer","literal"].includes(m.type)).map(m=>m.value).join("")}),[e,t,i,o,u,l,n,d]);return g.useMemo(()=>new Proxy(s,{get:(m,_)=>{var p;return(p=Reflect.get(m,_))==null?void 0:p.call(null)}}),[s])}function Z(e,r){return g.useMemo(()=>{let t;return()=>t!=null?t:t=new Intl.NumberFormat(e,r)},[e,r])}var gt="/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Money.tsx";function pe({data:e,as:r,withoutCurrency:t,withoutTrailingZeros:a,measurement:o,measurementSeparator:i="/",...u}){if(!Et(e))throw new Error("<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'");const n=Qe(e),l=r!=null?r:"div";let d=n.localizedString;return(t||a)&&(t&&!a?d=n.amount:!t&&a?d=n.withoutTrailingZeros:d=n.withoutTrailingZerosAndCurrency),w.default.createElement(l,{...u,__self:this,__source:{fileName:gt,lineNumber:65,columnNumber:5}},d,o&&o.referenceUnit&&w.default.createElement(w.default.Fragment,null,i,o.referenceUnit))}function Et(e){return typeof e.amount=="string"&&!!e.amount&&typeof e.currencyCode=="string"&&!!e.currencyCode}var Xe="/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductPrice.tsx";function pt(e){var d,h,s,m,_,p,A,f;const{priceType:r="regular",variantId:t,valueType:a="min",data:o,...i}=e;if(o==null)throw new Error("<ProductPrice/> requires a product as the 'data' prop");let u,n;const l=t&&(h=B((d=o==null?void 0:o.variants)!=null?d:{}).find(S=>(S==null?void 0:S.id)===t))!=null?h:null;if(r==="compareAt")if(t&&l){if