efficient-storefront-blocks 0.134.0 → 0.134.2
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.
- package/CHANGELOG.md +23 -0
- package/dist/chunks/EditorPreviewCheckout-NAWXDKVA.js +4 -0
- package/dist/chunks/chunk-V7SYE7AE.js +1 -0
- package/dist/index.js +25 -25
- package/dist/render/app/globals.css +8 -3
- package/dist/render/components/CartContext.d.ts +1 -0
- package/dist/render/components/CartContext.js +1 -1
- package/dist/render/components/checkout/checkout-parts.js +1 -1
- package/dist/render/components/checkout/checkout-state.d.ts +1 -0
- package/dist/render/components/checkout/checkout-state.js +3 -3
- package/dist/render/components/product-hero/SpinLayer.js +1 -1
- package/dist/render/lib/sections/spin-sets.d.ts +0 -2
- package/dist/render/lib/sections/spin-sets.js +1 -1
- package/dist/routine-index.json +1 -1
- package/dist/value-index.json +1 -1
- package/package.json +1 -1
- package/dist/chunks/EditorPreviewCheckout-K5CYDY5Q.js +0 -4
- package/dist/chunks/chunk-K7S3C6QE.js +0 -1
|
@@ -4552,17 +4552,22 @@ em.text-accent {
|
|
|
4552
4552
|
top: 79.31cqw;
|
|
4553
4553
|
}
|
|
4554
4554
|
/* The 360° frames are white-ground renders: multiplied, their white is the
|
|
4555
|
-
ground and the floor shadows show under the wheel (SpinLayer).
|
|
4556
|
-
|
|
4555
|
+
ground and the floor shadows show under the wheel (SpinLayer). The frames'
|
|
4556
|
+
layer is multiplied as ONE picture: the two frames of a crossfade blend over
|
|
4557
|
+
each other first, as they are. Multiplied one by one, the next frame
|
|
4558
|
+
darkened the one under it and the wheel jumped bright at every step. */
|
|
4559
|
+
.sf-photo-ground-studio [data-spin-frames] {
|
|
4557
4560
|
mix-blend-mode: multiply;
|
|
4561
|
+
isolation: isolate;
|
|
4558
4562
|
}
|
|
4559
4563
|
/* The Flat ground on a light page (the well's `bg-bg`, ProductGallery
|
|
4560
4564
|
groundClass): multiplied too, so the frame's white is the page colour and no
|
|
4561
4565
|
white square shows on an off-white page. On a dark page the well has no
|
|
4562
4566
|
paint and the frame is drawn as it is: a white-ground render cannot sit on
|
|
4563
4567
|
a dark ground without its white. */
|
|
4564
|
-
.bg-bg > [data-spin-well] [data-spin-
|
|
4568
|
+
.bg-bg > [data-spin-well] [data-spin-frames] {
|
|
4565
4569
|
mix-blend-mode: multiply;
|
|
4570
|
+
isolation: isolate;
|
|
4566
4571
|
}
|
|
4567
4572
|
.sf-photo-ground-studio::after {
|
|
4568
4573
|
top: 78.75cqw;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as ce}from"react/jsx-runtime";import{createContext as ie,useCallback as a,useContext as ae,useEffect as p,useMemo as kt,useRef as g,useState as i}from"react";import{usePathname as le}from"next/navigation";import{products as C}from"../lib/api/index.js";import{couponDeferredToCheckout as de}from"../lib/cart/coupon-preview.js";import{snapshotCartLines as Ut}from"../lib/cart/snapshot-lines.js";import{restoreCartLines as fe}from"../lib/cart/restore-lines.js";import{safeLocalStorage as
|
|
1
|
+
"use client";import{jsx as ce}from"react/jsx-runtime";import{createContext as ie,useCallback as a,useContext as ae,useEffect as p,useMemo as kt,useRef as g,useState as i}from"react";import{usePathname as le}from"next/navigation";import{products as C}from"../lib/api/index.js";import{couponDeferredToCheckout as de}from"../lib/cart/coupon-preview.js";import{snapshotCartLines as Ut}from"../lib/cart/snapshot-lines.js";import{restoreCartLines as fe}from"../lib/cart/restore-lines.js";import{safeLocalStorage as G}from"efficient-web-builder/format/lib/safe-storage";import{MAX_QTY_PER_LINE as Lt,orderLinesForSets as me,setPrice as pe}from"../lib/commerce.js";import{UNPRICED_LABEL as he}from"../lib/wheels/price-display.js";import{isValidEmail as ye}from"../lib/email-shape.js";import{trackAddToCart as ge}from"../lib/google-tag.js";import{deliveryAfterCoupon as Ce,shippingStatus as Se}from"../lib/cart/shipping-status.js";import{useCurrency as Ee}from"./CurrencyContext.js";const be=400,Ne=400,Ie=1500,K="storefront-cart";function X(d){return(d.components?.length??0)>0}function Qt(d,r){return{code:d,valid:r.valid,deferred:de(r,r.askedAsShopper),message:r.message||void 0,effects:r.effects??void 0}}function wt(d,r){return pe(d.components,r)}function Z(d,r){const u=wt(d,r);return u===null?null:u*d.qty}function Wt(d){return d!=="tyre"}const Vt=ie(null);function Qe({children:d,preview:r=!1}){const{currency:u,country:$,formatMoney:Ft}=Ee(),[tt,W]=i(r),[s,R]=i([]),[et,Jt]=i([]),[nt,jt]=i([]),[ot,vt]=i(!1),rt=g(new Set),[st,Ht]=i([]),[Yt,zt]=i(!1),[f,ut]=i(null),[ct,it]=i(null),[at,lt]=i(null),[Gt,Kt]=i(0),dt=a(()=>Kt(t=>t+1),[]),[V,ft]=i(void 0),[N,Xt]=i(null),[l,S]=i(null),[mt,B]=i(!1),[h,pt]=i(null),D=g(void 0),I=a(()=>W(!0),[]),M=a(()=>W(!1),[]),ht=a(()=>W(t=>!t),[]);p(()=>{r||typeof window>"u"||new URLSearchParams(window.location.search).get("cart")==="open"&&I()},[I,r]);const _=le(),yt=g(_);p(()=>{yt.current!==_&&(yt.current=_,r||M())},[_,r,M]);const gt=a(t=>{Xt(n=>n?.country===t?.country&&n?.subdivision===t?.subdivision&&n?.postcode===t?.postcode?n:t)},[]),Ct=a((t,n)=>{zt(!0),!(!n||!Wt(t))&&Ht(e=>e.includes(n)?e:[...e,n])},[]),St=Yt||s.length>0,F=g(!0);p(()=>(F.current=!0,()=>{F.current=!1}),[]),p(()=>{if(r)return;const t=[...st,...s.filter(e=>Wt(e.kind)).map(e=>e.slug)],n=[...new Set(t)].filter(e=>e&&!rt.current.has(e));if(n.length!==0){for(const e of n)rt.current.add(e);C.listWheelsBySlug(n).then(e=>{if(!F.current||e.length===0)return;const o=new Set(e.map(c=>c.slug));Jt(c=>[...c.filter(b=>!o.has(b.slug)),...e])})}},[r,st,s]),p(()=>{if(r||!St||ot)return;let t=!0;return C.listBundles().then(n=>{t&&(jt(n),vt(!0))}),()=>{t=!1}},[r,St,ot]);const E=f?.deliveryOptions??[],Et=f?.courier??null;p(()=>{f&&pt(t=>t&&E.some(n=>n.id===t)?t:E[0]?.id??null)},[f]);const x=a(()=>s.filter(X).flatMap(t=>me(t.components,t.qty)),[s]),bt=a(async(t,n)=>{const e=t.trim().toUpperCase();if(!e)return;const o=x();if(o.length===0){S({code:e,valid:!1,message:"Add a wheel to the cart first."});return}B(!0),D.current=n;try{const c=await C.validateCoupon({code:e,items:o,currency:u,shippingMethodId:h??void 0,customerEmail:n});S(Qt(e,c))}catch{S({code:e,valid:!1,unchecked:!0,message:"Could not check that code. Please try again."})}finally{B(!1)}},[x,u,h]),Nt=a(()=>{S(null),D.current=void 0},[]),It=a(t=>{if(!l)return;const{code:n}=l;S(e=>e&&e.code===n?{code:n,valid:!1,refused:!0,message:t}:e)},[l]);p(()=>{if(!l||l.refused)return;const t=l.code,n=o=>o!==null&&o.code===t&&!o.refused,e=setTimeout(async()=>{const o=x();if(o.length===0){S(c=>n(c)?{code:t,valid:!1,message:"Add a wheel to the cart first."}:c);return}B(!0);try{const c=await C.validateCoupon({code:t,items:o,currency:u,shippingMethodId:h??void 0,customerEmail:D.current});S(b=>n(b)?Qt(t,c):b)}catch{}finally{B(!1)}},be);return()=>clearTimeout(e)},[s,u,h]);const q=l&&!l.refused?l.code:void 0;p(()=>{if(r)return;let t=!0;const n=s,e=setTimeout(async()=>{const o=x();if(o.length===0){ut(null),it(null),ft(void 0);return}try{const c=await C.quoteCart({items:o,currency:u,shippingMethodId:h??void 0,couponCode:q,customerEmail:D.current||void 0,country:N?.country||$||void 0,subdivision:N?.country&&N.subdivision||void 0,postcode:N?.country&&N.postcode||void 0});if(!t)return;ut(c),it(n),lt(null)}catch{if(!t)return;lt(n)}ft(q)},Ne);return()=>{t=!1,clearTimeout(e)}},[s,u,h,q,$,N,Gt]);const P=a(t=>{R(n=>{const e=n.findIndex(o=>o.id===t.id);return e===-1?[...n,t]:n.map((o,c)=>c===e?{...o,qty:Math.min(Lt,o.qty+t.qty)}:o)}),ge(t,u)},[u]),Tt=a(t=>{R(n=>n.filter(e=>e.id!==t))},[]),Ot=a((t,n)=>{const e=Math.max(1,Math.min(Lt,n));R(o=>o.map(c=>c.id===t?{...c,qty:e}:c))},[]),k=a(t=>{R(t)},[]),[U,J]=i(!1),[qt,Zt]=i([]),At=g(s);At.current=s,p(()=>{if(r)return;let t=[];try{const e=JSON.parse(G.getItem(K)??"[]");Array.isArray(e)&&(t=e)}catch{}if(t.length===0){J(!0);return}let n=!0;return fe(t,C).then(({lines:e,dropped:o})=>{n&&(At.current.length===0&&(k(e),Zt(o)),J(!0))},e=>{n&&(process.env.NODE_ENV!=="production"&&console.warn("stored cart could not be rebuilt",e),J(!0))}),()=>{n=!1}},[r,k]),p(()=>{if(r||!U)return;const t=s.filter(X);if(t.length===0){G.removeItem(K);return}G.setItem(K,JSON.stringify(Ut(t,()=>"")))},[s,r,U]);const[A,$t]=i(null),Rt=g(null);Rt.current=A;const y=g(null),j=g(""),Bt=a((t,n)=>{const e=t.trim().toLowerCase();ye(e)&&$t(o=>o&&o.email===e&&o.firstName===(n??"")?o:{email:e,firstName:n??""})},[]);p(()=>{if(r||!A)return;const t=Ut(s.filter(X),o=>Z(o,u)===null?he:Ft(Z(o,u),u)),n={email:A.email,firstName:A.firstName,currency:u,items:t},e=JSON.stringify(n);if(e!==j.current)return y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{y.current=null,j.current=e,C.captureCart(n).catch(o=>{process.env.NODE_ENV!=="production"&&console.warn("abandoned-cart capture failed",o)})},Ie),()=>{y.current&&(clearTimeout(y.current),y.current=null)}},[s,A,u,r]);const Dt=a(()=>{y.current&&(clearTimeout(y.current),y.current=null);const t=Rt.current;t&&(j.current="",C.captureCart({email:t.email,firstName:t.firstName,currency:u,items:[]}).catch(n=>{process.env.NODE_ENV!=="production"&&console.warn("abandoned-cart clear failed",n)}))},[u]),Mt=kt(()=>{const t=s.reduce((m,O)=>{const w=Z(O,u);return w===null?m:m+w},0),n=s.some(m=>wt(m,u)===null),e=s.reduce((m,O)=>m+O.qty,0),o=l?.valid?l.effects:void 0,c=o?Math.min(t,Number(o.discountAmount)):0,b=f?.bundleDiscount??0,ee=f?.appliedBundles??[],L=!!o?.freeShipping,T=E.find(m=>m.id===h),v=Number(o?.deliveryDiscountPercent??0),Q=!L&&v>0&&v<100?v:0,H=Q>0&&T?Ce(T.amount,Q):void 0,Y=L?0:H!==void 0&&V!==q?H:f?.shipping??H??T?.amount??0,ne=Q>0&&T?Math.max(0,T.amount-Y):0,oe=Se({quoted:f!==null,optionCount:E.length,chosenAmount:T?.amount,couponWaivesFreight:L}),z={};for(const m of o?.freeUnits??[])z[m.partNumber]=(z[m.partNumber]??0)+m.quantity;const re=f?.tax??null,se=f?f.grandTotal:t-c-b+Y;return{sets:e,units:s.reduce((m,O)=>m+(O.components??[]).reduce((w,ue)=>w+ue.wheels*O.qty,0),0),subtotal:t,hasUnpricedLine:n,discount:c,bundleDiscount:b,appliedBundles:ee,shipping:Y,freeShipping:L,deliveryDiscountPercent:Q,deliverySaving:ne,shippingStatus:oe,freeUnitsByPartNumber:z,tax:re,grand:se,repricing:!!l?.refused&&f!==null&&V===l?.code,quoted:f!==null&&ct===s,serverSubtotal:f?.subtotal??null,quoteFailed:at===s,currency:u}},[s,u,l,q,E,h,f,V,ct,at]),_t=g(!0),xt=a(t=>{_t.current=t},[]),Pt=a(t=>{P(t),_t.current&&I()},[P,I]),te=kt(()=>({isOpen:tt,preview:r,open:I,close:M,toggle:ht,items:s,basketRead:r||U,catalog:et,bundles:nt,warmCatalog:Ct,add:P,addAndOpen:Pt,setAutoOpen:xt,remove:Tt,setQty:Ot,replaceItems:k,restoreDropped:qt,identify:Bt,clearCapturedCart:Dt,coupon:l,applyCoupon:bt,removeCoupon:Nt,refuseCoupon:It,couponBusy:mt,deliveryOptions:E,setQuoteDestination:gt,courier:Et,requote:dt,shippingMethodId:h,setShippingMethodId:pt,totals:Mt}),[tt,r,I,M,ht,s,U,et,nt,Ct,P,Pt,xt,Tt,Ot,k,qt,Bt,Dt,l,bt,Nt,It,mt,E,gt,Et,dt,h,Mt]);return ce(Vt.Provider,{value:te,children:d})}function we(){const d=ae(Vt);if(!d)throw new Error("useCart() must be called inside <CartProvider>. Mount the provider in app/layout.tsx.");return d}export{K as CART_STORAGE_KEY,Qe as CartProvider,X as isOrderable,Z as lineTotal,we as useCart};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as e,Fragment as N,jsxs as a}from"react/jsx-runtime";import{useId as O}from"react";import X from"next/image";import Z from"next/link";import{lineTotal as J,useCart as ee}from"../CartContext.js";import{useCurrency as te}from"../CurrencyContext.js";import{Notice as _}from"../Notice.js";import{FREE_PRICE as A}from"../../lib/wheels/price-display.js";import ne from"../CouponField.js";import{COUPON_DEFERRED_TOTAL as ae}from"../../lib/cart/coupon-preview.js";import{orderReference as re}from"../../lib/checkout/pay-first.js";import{PRICES_REQUOTED as ie,PRICES_UNCHECKED as le}from"../../lib/checkout/checkout-memory.js";import{couponSaving as oe,deliveryAfterCoupon as ce,shippingWords as se,TAX_PENDING as de}from"../../lib/cart/shipping-status.js";import{DEFAULT_FINISH_COLOR as pe}from"../../lib/wheels/finish-defaults.js";import M from"../ThemedSelect.js";import x from"../WebFormField.js";import me from"../WheelSvg.js";import{NO_PAYMENT_METHOD_NOTE as ue,placedOrderLockNote as he,SHIPPING_RETRY_NOTE as ge,useCheckout as C}from"./checkout-state.js";import{FIELD_INPUT_CLASS as f}from"../../lib/field-input.js";import{FIGURE_UPDATING as T}from"../../lib/wheels/price-display.js";function Me(){const{email:t,setEmail:i,firstName:n,setFirstName:l,lastName:c,setLastName:d,company:m,setCompany:k,me:v,signInHref:u,checkoutSignOut:b,orderLocked:o,unpaidOrder:s}=C(),h=O();return a(L,{num:1,title:"Contact",children:[o&&s&&e(be,{orderNumber:s.orderNumber}),e(x,{label:"Email",htmlFor:h,hint:v?a(N,{children:["Signed in ·"," ",e("button",{type:"button",onClick:b,className:"underline transition-colors enabled:hover:text-accent",children:"Not you? Sign out"})]}):u?a(N,{children:["Have an account?"," ",e(R,{href:u,className:"underline transition-colors hover:text-accent",children:"Sign in"})]}):void 0,children:e("input",{id:h,type:"email",value:t,onChange:p=>i(p.target.value),placeholder:"you@example.com",readOnly:v!==null,className:f})}),a(q,{children:[e(x,{label:"First name",children:e("input",{type:"text",value:n,onChange:p=>l(p.target.value),className:f})}),e(x,{label:"Last name",children:e("input",{type:"text",value:c,onChange:p=>d(p.target.value),className:f})})]}),e(x,{label:"Company (optional)",children:e("input",{type:"text",value:m,onChange:p=>k(p.target.value),autoComplete:"organization",className:f})})]})}function Ue(){const{pickupLocation:t,servedCountries:i,address1:n,setAddress1:l,address2:c,setAddress2:d,city:m,setCity:k,postcode:v,setPostcode:u,phone:b,setPhone:o,country:s,setCountry:h,subdivision:p,setSubdivision:g,subdivisions:E,destination:P,postcodeLabel:S,subdivisionLabel:y,me:B,savedAddresses:D,selectedAddressId:F,setSelectedAddressId:$,saveAddress:Y,setSaveAddress:G,saveLabel:W,setSaveLabel:K,fillFromAddress:Q,orderLocked:V}=C(),H=O(),j=O();return a(L,{num:2,title:t?"Collection":"Shipping address",children:[t?a("div",{className:"grid gap-2 text-[14px] leading-[1.6]",children:[e("span",{className:"font-medium",children:t.name}),[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).length>0&&e("span",{className:"opacity-80",children:[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).join(", ")}),t.openingHours&&e("span",{className:"opacity-80",children:t.openingHours}),t.readyIn&&e("span",{className:"opacity-80",children:t.readyIn}),t.instructions&&e("span",{className:"opacity-80",children:t.instructions}),e("span",{className:"mt-1 font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"No delivery address needed"})]}):a(N,{children:[B!==null&&D.length>0&&a("div",{className:"grid gap-3",children:[D.map(r=>e(I,{active:F===r.id,onClick:()=>{$(r.id),Q(r)},title:r.label,body:r.formatted_address,price:null},r.id)),e(I,{active:F==="new",onClick:()=>$("new"),title:"New address",body:null,price:null})]}),e(x,{label:"Address line 1",children:e("input",{type:"text",value:n,onChange:r=>l(r.target.value),className:f})}),e(x,{label:"Address line 2",children:e("input",{type:"text",value:c,onChange:r=>d(r.target.value),placeholder:"Apartment, unit, garage bay…",className:f})}),a(q,{cols:"three",children:[e(x,{label:"City",children:e("input",{type:"text",value:m,onChange:r=>k(r.target.value),className:f})}),e(x,{label:S,children:e("input",{type:"text",value:v,onChange:r=>u(r.target.value),className:f})}),e(x,{label:"Country",separate:!0,htmlFor:H,children:e(M,{id:H,value:s,onChange:r=>h(r.target.value),className:f+" pr-10",style:U,children:i.map(r=>e("option",{value:r.code,children:r.name},r.code))})})]}),e(x,{label:y,separate:!0,htmlFor:j,children:E.length>0?a(M,{id:j,value:p,onChange:r=>g(r.target.value),className:f+" pr-10",style:U,children:[e("option",{value:"",children:"Select…"}),E.map(r=>e("option",{value:r.code||r.name,children:r.name},r.code||r.name))]}):e("input",{id:j,type:"text",value:p,onChange:r=>g(r.target.value),className:f})})]}),e(x,{label:"Phone",children:e("input",{type:"tel",value:b,onChange:r=>o(r.target.value),className:f})}),!t&&B!==null&&F==="new"&&!V&&a(N,{children:[e(ye,{checked:Y,onChange:G,label:"Save this address to my account"}),Y&&e(x,{label:"Address label",children:e("input",{type:"text",value:W,onChange:r=>K(r.target.value),placeholder:"Home",className:f})})]})]})}function qe(){const{totals:t,coupon:i,deliveryOptions:n,shippingMethodId:l,setShippingMethodId:c,pickupLocation:d,formatMoney:m,city:k,destination:v,courierUnavailable:u,retryCourier:b}=C();return e(L,{num:3,title:"Shipping",children:a("div",{className:"grid gap-3",children:[n.map(o=>{const s=o.pickupLocation,h=s?[s.address,s.city,s.state,s.zipCode].filter(Boolean).join(", "):null;return e(I,{active:l===o.id,onClick:()=>c(o.id),title:s?`${o.name} — ${s.name}`:o.name,body:s?[h,s.openingHours,s.readyIn,s.instructions,o.description].filter(Boolean).join(" · "):o.description||null,price:t.freeShipping||o.amount===0?A:t.deliveryDiscountPercent>0?a(N,{children:[e("s",{className:"text-fg-dim",children:m(o.amount,t.currency)})," ",m(ce(o.amount,t.deliveryDiscountPercent),t.currency)]}):m(o.amount,t.currency),tag:o.tag||void 0},o.id)}),u?a("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:[ge," ",e("button",{type:"button",onClick:b,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}):n.length===0&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Shipping is arranged after your order is reviewed."})]})})}function ze(){const{payChoice:t,setPayChoice:i,payment:n,payOptions:l,noPaymentMethod:c}=C();return a(L,{num:4,title:"Payment",children:[c&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:ue}),e("div",{className:"grid gap-3",children:l.map(d=>e(I,{active:t===d.key,onClick:()=>i(d.key),title:d.title,body:d.body,price:d.price,tag:d.tag},d.key))}),t==="card"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="paypal"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll approve the payment with PayPal on the payment step after placing the order."}):t==="afterpay"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Afterpay to approve four interest-free payments, then brought straight back."}):t==="square"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="gocardless"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll set up a bank direct debit with GoCardless, then be brought straight back. Direct debits clear in a few days."}):t==="zip"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Zip to approve four instalments, then brought straight back."}):t==="klarna"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Klarna to choose how to pay, then brought straight back."}):t==="worldpay"?e("p",{className:"font-mono text-xs uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter your card on Worldpay’s secure page, then be brought straight back."}):t==="bank"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Our team emails you the invoice and bank details after review."}):null]})}function Ge(){const{site:t,items:i,totals:n,coupon:l,formatMoney:c,payChoice:d,placing:m,email:k,orderError:v,payment:u,noPaymentMethod:b,unpaidOrder:o,formLocked:s,restoredPrices:h,quoteFailed:p,retryQuote:g,placeOrder:E}=C(),P=h==="waiting",S=h==="changed";return a("aside",{className:"sticky top-[var(--sf-checkout-header-h,88px)] border border-line max-view-desktop:static",style:{background:"linear-gradient(180deg, color-mix(in oklab, var(--site-surface) 70%, var(--bg)) 0%, var(--bg) 100%)"},children:[a("header",{className:"flex items-center justify-between border-b border-accent bg-accent px-6 py-4 font-mono text-[13px] font-bold uppercase tracking-[0.28em] text-bg",children:[e("span",{children:"Your order"}),e(R,{href:"/wheels",className:"text-bg/80 transition-colors hover:text-bg",children:"Edit ↗"})]}),e("div",{className:"flex flex-col px-6 py-2",children:i.length===0?a("div",{className:"py-8 text-center font-serif text-[16px] italic leading-[1.5] text-fg-dim",children:["Your cart is empty. ",e(R,{href:"/wheels",className:"text-accent underline-offset-4 hover:underline",children:"Browse the catalog →"})]}):i.map(y=>e(Ne,{slug:y.slug,name:y.name,qty:y.qty,config:y.config,configSummary:ve(y.config),price:S||P?null:J(y,n.currency)??0,currency:n.currency},y.id))}),e(xe,{locked:s,className:"border-t border-line px-6 pt-5",children:e(ne,{customerEmail:k,disabled:s})}),a("div",{className:"flex flex-col gap-2 border-t border-line mt-5 px-6 pt-5",children:[e(w,{label:"Subtotal",value:P?T:c(S?n.serverSubtotal??0:n.subtotal,n.currency)}),(n.discount>0||n.deliverySaving>0)&&l?.valid&&e(w,{label:`Coupon · ${l.code}`,value:e("span",{className:"font-semibold text-green",children:oe(n,y=>c(y,n.currency))})}),l?.deferred&&e(w,{label:`Coupon · ${l.code}`,value:ae}),l?.valid&&l.effects?.gift&&e(w,{label:`Free gift · ${l.effects.gift.partNumber}${l.effects.gift.quantity>1?` ×${l.effects.gift.quantity}`:""}`,value:e("span",{className:"font-semibold text-green",children:A})}),e(w,{label:"Shipping",value:n.shippingStatus==="free"?e("span",{className:"font-semibold text-green",children:A}):se(n.shippingStatus)??c(n.shipping,n.currency)}),n.tax&&(n.tax.charged?e(w,{label:n.tax.inclusive?`${n.tax.name} included · ${n.tax.rate}%`:n.tax.name,value:c(n.tax.amount,n.currency)}):n.tax.name?e(w,{label:n.tax.name,value:de}):null)]}),a("div",{className:"mt-4 flex items-end justify-between border-y-2 border-accent px-6 py-4",style:{background:"color-mix(in oklab, var(--accent) 10%, var(--bg))"},children:[e("span",{className:"font-display text-[20px] font-bold uppercase tracking-[0.04em] text-fg",children:"Total"}),e("span",{className:"text-right font-display text-[34px] font-bold leading-none tracking-[-0.025em] text-fg",children:n.repricing?T:c(n.grand,n.currency)})]}),a("div",{className:"flex flex-col gap-3 px-6 pt-5 pb-6",children:[S&&e(_,{tone:"quiet",children:ie}),p&&a(_,{role:"alert",children:[le," ",e("button",{type:"button",onClick:g,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}),v&&e(_,{role:"alert",children:v}),n.hasUnpricedLine&&a(_,{role:"status",children:["One or more items have no price in ",n.currency,". Remove them, or switch region, to continue."]}),e("button",{type:"button",onClick:E,disabled:m||!o&&(b||i.length===0||n.hasUnpricedLine||n.repricing),className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all max-[640px]:gap-3 max-[640px]:whitespace-nowrap max-[640px]:px-4 max-[640px]:text-xs max-[640px]:tracking-normal",m||!o&&(i.length===0||b||n.hasUnpricedLine||n.repricing)?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:m?a(N,{children:["Building order… ",e("span",{children:"·"})]}):b?a(N,{children:["No online payment ",e("span",{children:"·"})]}):o?a(N,{children:[a("span",{children:["Try payment again",a(z,{children:[" · ",re(o)]})]}),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]}):p?a(N,{children:["Total not confirmed ",e("span",{children:"·"})]}):n.repricing?a(N,{children:[T," ",e("span",{children:"·"})]}):a(N,{children:[a("span",{children:[d==="bank"?"Place order":"Continue to payment",a(z,{children:[" · ",c(n.grand,n.currency)]})]}),a("span",{className:"flex items-center gap-3",children:[e("span",{"aria-hidden":"true",className:"max-[359px]:hidden min-[641px]:hidden",children:c(n.grand,n.currency)}),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})]})})]})]})}const fe=" [&:disabled_:disabled]:cursor-not-allowed! [&:disabled_:disabled]:opacity-70! [&_input[readonly]]:cursor-not-allowed [&_input[readonly]]:opacity-70";function xe({locked:t,className:i="",children:n}){return e("fieldset",{disabled:t,className:"m-0 min-w-0 border-0 p-0 "+i+fe,children:n})}function R({href:t,className:i="",children:n,...l}){const{placing:c}=C();return c?e("span",{"aria-disabled":"true","aria-label":l["aria-label"],className:i+" pointer-events-none",children:n}):e(Z,{href:t,"aria-label":l["aria-label"],className:i,children:n})}function be({orderNumber:t}){return e(_,{tone:"quiet",role:"status",children:a("span",{className:"flex items-start gap-2",children:[a("svg",{"aria-hidden":!0,viewBox:"0 0 16 16",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"mt-[3px] shrink-0",children:[e("rect",{x:"3",y:"7",width:"10",height:"7",rx:"1"}),e("path",{d:"M5 7V5a3 3 0 0 1 6 0v2"})]}),e("span",{children:he(t)})]})})}const U={backgroundImage:"linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%)",backgroundPosition:"calc(100% - 18px) 50%, calc(100% - 12px) 50%",backgroundSize:"6px 6px",backgroundRepeat:"no-repeat"};function L({num:t,title:i,children:n}){const{capitalised:l}=C();return a("section",{className:"mb-6 border border-line bg-bg",children:[a("header",{className:"flex items-center gap-4 border-b border-line bg-surface px-6 py-4",children:[e("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:l?String(t):`N° ${String(t).padStart(2,"0")}`}),e("h2",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:i})]}),e("div",{className:"flex flex-col gap-4 px-6 py-6",children:n})]})}function q({cols:t="two",children:i}){return e("div",{className:["grid gap-3 max-[640px]:grid-cols-1",t==="two"?"grid-cols-2":"grid-cols-[1.2fr_1fr_1fr]"].join(" "),children:i})}function I({active:t,onClick:i,title:n,body:l,price:c,tag:d}){return a("button",{type:"button",onClick:i,"aria-pressed":t,className:["relative grid grid-cols-[auto_1fr_auto] items-center gap-5 border bg-bg px-6 py-5 text-left transition-colors",t?"border-accent outline outline-1 outline-accent -outline-offset-1":"border-line enabled:hover:border-[color-mix(in_oklab,var(--accent)_50%,var(--site-line))]"].join(" "),style:t?{background:"color-mix(in oklab, var(--accent) 14%, var(--bg))"}:void 0,children:[t&&e("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-0 w-[3px] bg-accent"}),e("span",{className:["flex h-[18px] w-[18px] items-center justify-center rounded-full border-2",t?"border-accent":"border-fg-dim"].join(" "),children:t&&e("span",{className:"block h-2.5 w-2.5 rounded-full bg-accent"})}),a("span",{className:"flex min-w-0 flex-col gap-1",children:[a("span",{className:"flex flex-wrap items-baseline gap-3 font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:[n,d&&e("span",{className:"border px-2 py-0.5 font-mono text-[11px] font-normal uppercase tracking-[0.24em] text-accent",style:{background:"color-mix(in oklab, var(--accent) 14%, transparent)",borderColor:"color-mix(in oklab, var(--accent) 45%, var(--site-line))"},children:d})]}),l&&e("span",{className:"font-mono text-[12px] uppercase tracking-[0.22em] text-fg-dim",children:l})]}),e("span",{className:"whitespace-nowrap font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:c})]})}function ye({checked:t,onChange:i,label:n,sub:l}){return a("div",{className:"flex items-start gap-3 border-t border-line py-4 first:border-t-0 first:pt-0",children:[e("button",{type:"button",onClick:()=>i(!t),"aria-pressed":t,"aria-label":n,className:["mt-px flex h-5 w-5 flex-shrink-0 items-center justify-center border transition-colors",t?"border-accent":"border-line"].join(" "),style:t?{background:"color-mix(in oklab, var(--accent) 18%, transparent)"}:void 0,children:t&&e("span",{className:"text-[13px] text-accent",children:"✓"})}),a("span",{className:"flex-1 font-display text-[16px] leading-[1.5] text-fg",children:[n,l&&e("small",{className:"mt-1 block font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim",children:l})]})]})}function Ne({slug:t,name:i,qty:n,config:l,configSummary:c,price:d,currency:m}){const{catalog:k}=ee(),{formatMoney:v}=te(),u=k.find(g=>g.slug===t),b=u?.spokes??5,o=u?.mesh??!1,s=l.find(g=>g.gold)?.label,h=u?.finishes.find(g=>g.name===s&&g.src)??u?.finishes.find(g=>g.src),p=u?.finishes[0]?.color??pe;return a("div",{className:"grid grid-cols-[60px_1fr_auto] items-center gap-4 border-b border-line py-4 last:border-b-0",children:[a("div",{className:"relative aspect-square",children:[e("div",{className:"flex h-full w-full items-center justify-center overflow-hidden border border-line bg-surface",children:h?.src?e(X,{src:h.src,alt:`${i.lead}${i.accent} — ${h.name}`,width:120,height:120,sizes:"60px",className:"block h-full w-full object-contain p-2"}):e("div",{className:"block w-[78%]",style:{color:p},children:e(me,{spokes:b,mesh:o,className:"block w-full"})})}),e("span",{className:"absolute -right-1.5 -top-1.5 z-[2] flex h-[18px] w-[18px] items-center justify-center rounded-full bg-accent font-mono text-[11px] font-bold text-bg",children:n})]}),a("div",{className:"flex min-w-0 flex-col gap-0.5",children:[a("span",{className:"font-display text-[17px] font-bold uppercase leading-none tracking-[-0.005em] text-fg",children:[i.lead,e("em",{className:"font-serif font-normal italic text-accent tracking-[-0.005em] normal-case",children:i.accent})]}),e("span",{className:"font-mono text-[12px] uppercase leading-[1.5] tracking-[0.18em] text-fg-dim",children:c})]}),e("span",{className:"text-right font-display text-[17px] font-bold tracking-[-0.005em] text-fg",children:d===null?null:v(d,m)})]})}function z({children:t}){return e("span",{className:"max-[640px]:sr-only",children:t})}function w({label:t,value:i}){return a("div",{className:"flex items-center justify-between font-mono text-[13px] font-medium uppercase tracking-[0.18em] text-fg",children:[e("span",{children:t}),e("strong",{className:"font-display text-[16px] font-medium tracking-[-0.005em] normal-case text-fg",children:i})]})}function ve(t){return t.map(i=>i.label).join(" · ")}export{Me as CheckoutContact,Ge as CheckoutOrderSummary,ze as CheckoutPayment,Ue as CheckoutShippingAddress,qe as CheckoutShippingMethod,xe as FormLock,R as LeaveLink};
|
|
1
|
+
"use client";import{jsx as e,Fragment as N,jsxs as a}from"react/jsx-runtime";import{useId as j}from"react";import Z from"next/image";import J from"next/link";import{lineTotal as ee,useCart as te}from"../CartContext.js";import{useCurrency as ne}from"../CurrencyContext.js";import{Notice as _}from"../Notice.js";import{FREE_PRICE as A}from"../../lib/wheels/price-display.js";import ae from"../CouponField.js";import{COUPON_DEFERRED_TOTAL as re}from"../../lib/cart/coupon-preview.js";import{orderReference as ie}from"../../lib/checkout/pay-first.js";import{PRICES_REQUOTED as le,PRICES_UNCHECKED as oe}from"../../lib/checkout/checkout-memory.js";import{couponSaving as ce,deliveryAfterCoupon as se,shippingWords as de,TAX_PENDING as pe}from"../../lib/cart/shipping-status.js";import{DEFAULT_FINISH_COLOR as me}from"../../lib/wheels/finish-defaults.js";import U from"../ThemedSelect.js";import b from"../WebFormField.js";import ue from"../WheelSvg.js";import{NO_PAYMENT_METHOD_NOTE as he,placedOrderLockNote as ge,SHIPPING_RETRY_NOTE as fe,useCheckout as C}from"./checkout-state.js";import{FIELD_INPUT_CLASS as f}from"../../lib/field-input.js";import{FIGURE_UPDATING as T}from"../../lib/wheels/price-display.js";const xe="Loading your order",H=["py-8","text-center","font-serif","text-[16px]","italic","leading-[1.5]","text-fg-dim"].join(" ");function qe(){const{email:t,setEmail:i,firstName:n,setFirstName:l,lastName:c,setLastName:d,company:u,setCompany:k,me:v,signInHref:h,checkoutSignOut:y,orderLocked:o,unpaidOrder:s}=C(),g=j();return a(I,{num:1,title:"Contact",children:[o&&s&&e(Ne,{orderNumber:s.orderNumber}),e(b,{label:"Email",htmlFor:g,hint:v?a(N,{children:["Signed in ·"," ",e("button",{type:"button",onClick:y,className:"underline transition-colors enabled:hover:text-accent",children:"Not you? Sign out"})]}):h?a(N,{children:["Have an account?"," ",e(R,{href:h,className:"underline transition-colors hover:text-accent",children:"Sign in"})]}):void 0,children:e("input",{id:g,type:"email",value:t,onChange:p=>i(p.target.value),placeholder:"you@example.com",readOnly:v!==null,className:f})}),a(z,{children:[e(b,{label:"First name",children:e("input",{type:"text",value:n,onChange:p=>l(p.target.value),className:f})}),e(b,{label:"Last name",children:e("input",{type:"text",value:c,onChange:p=>d(p.target.value),className:f})})]}),e(b,{label:"Company (optional)",children:e("input",{type:"text",value:u,onChange:p=>k(p.target.value),autoComplete:"organization",className:f})})]})}function ze(){const{pickupLocation:t,servedCountries:i,address1:n,setAddress1:l,address2:c,setAddress2:d,city:u,setCity:k,postcode:v,setPostcode:h,phone:y,setPhone:o,country:s,setCountry:g,subdivision:p,setSubdivision:m,subdivisions:E,destination:B,postcodeLabel:L,subdivisionLabel:S,me:x,savedAddresses:D,selectedAddressId:F,setSelectedAddressId:M,saveAddress:Y,setSaveAddress:W,saveLabel:K,setSaveLabel:Q,fillFromAddress:V,orderLocked:X}=C(),$=j(),O=j();return a(I,{num:2,title:t?"Collection":"Shipping address",children:[t?a("div",{className:"grid gap-2 text-[14px] leading-[1.6]",children:[e("span",{className:"font-medium",children:t.name}),[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).length>0&&e("span",{className:"opacity-80",children:[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).join(", ")}),t.openingHours&&e("span",{className:"opacity-80",children:t.openingHours}),t.readyIn&&e("span",{className:"opacity-80",children:t.readyIn}),t.instructions&&e("span",{className:"opacity-80",children:t.instructions}),e("span",{className:"mt-1 font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"No delivery address needed"})]}):a(N,{children:[x!==null&&D.length>0&&a("div",{className:"grid gap-3",children:[D.map(r=>e(P,{active:F===r.id,onClick:()=>{M(r.id),V(r)},title:r.label,body:r.formatted_address,price:null},r.id)),e(P,{active:F==="new",onClick:()=>M("new"),title:"New address",body:null,price:null})]}),e(b,{label:"Address line 1",children:e("input",{type:"text",value:n,onChange:r=>l(r.target.value),className:f})}),e(b,{label:"Address line 2",children:e("input",{type:"text",value:c,onChange:r=>d(r.target.value),placeholder:"Apartment, unit, garage bay…",className:f})}),a(z,{cols:"three",children:[e(b,{label:"City",children:e("input",{type:"text",value:u,onChange:r=>k(r.target.value),className:f})}),e(b,{label:L,children:e("input",{type:"text",value:v,onChange:r=>h(r.target.value),className:f})}),e(b,{label:"Country",separate:!0,htmlFor:$,children:e(U,{id:$,value:s,onChange:r=>g(r.target.value),className:f+" pr-10",style:q,children:i.map(r=>e("option",{value:r.code,children:r.name},r.code))})})]}),e(b,{label:S,separate:!0,htmlFor:O,children:E.length>0?a(U,{id:O,value:p,onChange:r=>m(r.target.value),className:f+" pr-10",style:q,children:[e("option",{value:"",children:"Select…"}),E.map(r=>e("option",{value:r.code||r.name,children:r.name},r.code||r.name))]}):e("input",{id:O,type:"text",value:p,onChange:r=>m(r.target.value),className:f})})]}),e(b,{label:"Phone",children:e("input",{type:"tel",value:y,onChange:r=>o(r.target.value),className:f})}),!t&&x!==null&&F==="new"&&!X&&a(N,{children:[e(ve,{checked:Y,onChange:W,label:"Save this address to my account"}),Y&&e(b,{label:"Address label",children:e("input",{type:"text",value:K,onChange:r=>Q(r.target.value),placeholder:"Home",className:f})})]})]})}function Ge(){const{totals:t,coupon:i,deliveryOptions:n,shippingMethodId:l,setShippingMethodId:c,pickupLocation:d,formatMoney:u,city:k,destination:v,courierUnavailable:h,retryCourier:y}=C();return e(I,{num:3,title:"Shipping",children:a("div",{className:"grid gap-3",children:[n.map(o=>{const s=o.pickupLocation,g=s?[s.address,s.city,s.state,s.zipCode].filter(Boolean).join(", "):null;return e(P,{active:l===o.id,onClick:()=>c(o.id),title:s?`${o.name} — ${s.name}`:o.name,body:s?[g,s.openingHours,s.readyIn,s.instructions,o.description].filter(Boolean).join(" · "):o.description||null,price:t.freeShipping||o.amount===0?A:t.deliveryDiscountPercent>0?a(N,{children:[e("s",{className:"text-fg-dim",children:u(o.amount,t.currency)})," ",u(se(o.amount,t.deliveryDiscountPercent),t.currency)]}):u(o.amount,t.currency),tag:o.tag||void 0},o.id)}),h?a("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:[fe," ",e("button",{type:"button",onClick:y,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}):n.length===0&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Shipping is arranged after your order is reviewed."})]})})}function We(){const{payChoice:t,setPayChoice:i,payment:n,payOptions:l,noPaymentMethod:c}=C();return a(I,{num:4,title:"Payment",children:[c&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:he}),e("div",{className:"grid gap-3",children:l.map(d=>e(P,{active:t===d.key,onClick:()=>i(d.key),title:d.title,body:d.body,price:d.price,tag:d.tag},d.key))}),t==="card"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="paypal"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll approve the payment with PayPal on the payment step after placing the order."}):t==="afterpay"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Afterpay to approve four interest-free payments, then brought straight back."}):t==="square"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="gocardless"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll set up a bank direct debit with GoCardless, then be brought straight back. Direct debits clear in a few days."}):t==="zip"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Zip to approve four instalments, then brought straight back."}):t==="klarna"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Klarna to choose how to pay, then brought straight back."}):t==="worldpay"?e("p",{className:"font-mono text-xs uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter your card on Worldpay’s secure page, then be brought straight back."}):t==="bank"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Our team emails you the invoice and bank details after review."}):null]})}function Ke(){const{site:t,items:i,totals:n,coupon:l,formatMoney:c,payChoice:d,placing:u,email:k,orderError:v,payment:h,noPaymentMethod:y,unpaidOrder:o,formLocked:s,restoredPrices:g,basketRead:p,quoteFailed:m,retryQuote:E,placeOrder:B}=C(),L=g==="waiting"||!p,S=g==="changed";return a("aside",{className:"sticky top-[var(--sf-checkout-header-h,88px)] border border-line max-view-desktop:static",style:{background:"linear-gradient(180deg, color-mix(in oklab, var(--site-surface) 70%, var(--bg)) 0%, var(--bg) 100%)"},children:[a("header",{className:"flex items-center justify-between border-b border-accent bg-accent px-6 py-4 font-mono text-[13px] font-bold uppercase tracking-[0.28em] text-bg",children:[e("span",{children:"Your order"}),e(R,{href:"/wheels",className:"text-bg/80 transition-colors hover:text-bg",children:"Edit ↗"})]}),e("div",{className:"flex flex-col px-6 py-2",children:p?i.length===0?a("div",{className:H,children:["Your cart is empty. ",e(R,{href:"/wheels",className:"text-accent underline-offset-4 hover:underline",children:"Browse the catalog →"})]}):i.map(x=>e(ke,{slug:x.slug,name:x.name,qty:x.qty,config:x.config,configSummary:Ce(x.config),price:S||L?null:ee(x,n.currency)??0,currency:n.currency},x.id)):e("div",{role:"status",className:H,children:xe})}),e(ye,{locked:s,className:"border-t border-line px-6 pt-5",children:e(ae,{customerEmail:k,disabled:s})}),a("div",{className:"flex flex-col gap-2 border-t border-line mt-5 px-6 pt-5",children:[e(w,{label:"Subtotal",value:L?T:c(S?n.serverSubtotal??0:n.subtotal,n.currency)}),(n.discount>0||n.deliverySaving>0)&&l?.valid&&e(w,{label:`Coupon · ${l.code}`,value:e("span",{className:"font-semibold text-green",children:ce(n,x=>c(x,n.currency))})}),l?.deferred&&e(w,{label:`Coupon · ${l.code}`,value:re}),l?.valid&&l.effects?.gift&&e(w,{label:`Free gift · ${l.effects.gift.partNumber}${l.effects.gift.quantity>1?` ×${l.effects.gift.quantity}`:""}`,value:e("span",{className:"font-semibold text-green",children:A})}),e(w,{label:"Shipping",value:n.shippingStatus==="free"?e("span",{className:"font-semibold text-green",children:A}):de(n.shippingStatus)??c(n.shipping,n.currency)}),n.tax&&(n.tax.charged?e(w,{label:n.tax.inclusive?`${n.tax.name} included · ${n.tax.rate}%`:n.tax.name,value:c(n.tax.amount,n.currency)}):n.tax.name?e(w,{label:n.tax.name,value:pe}):null)]}),a("div",{className:"mt-4 flex items-end justify-between border-y-2 border-accent px-6 py-4",style:{background:"color-mix(in oklab, var(--accent) 10%, var(--bg))"},children:[e("span",{className:"font-display text-[20px] font-bold uppercase tracking-[0.04em] text-fg",children:"Total"}),e("span",{className:"text-right font-display text-[34px] font-bold leading-none tracking-[-0.025em] text-fg",children:n.repricing||!p?T:c(n.grand,n.currency)})]}),a("div",{className:"flex flex-col gap-3 px-6 pt-5 pb-6",children:[S&&e(_,{tone:"quiet",children:le}),m&&a(_,{role:"alert",children:[oe," ",e("button",{type:"button",onClick:E,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}),v&&e(_,{role:"alert",children:v}),n.hasUnpricedLine&&a(_,{role:"status",children:["One or more items have no price in ",n.currency,". Remove them, or switch region, to continue."]}),e("button",{type:"button",onClick:B,disabled:u||!o&&(y||i.length===0||n.hasUnpricedLine||n.repricing),className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all max-[640px]:gap-3 max-[640px]:whitespace-nowrap max-[640px]:px-4 max-[640px]:text-xs max-[640px]:tracking-normal",u||!o&&(i.length===0||y||n.hasUnpricedLine||n.repricing)?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:u?a(N,{children:["Building order… ",e("span",{children:"·"})]}):y?a(N,{children:["No online payment ",e("span",{children:"·"})]}):o?a(N,{children:[a("span",{children:["Try payment again",a(G,{children:[" · ",ie(o)]})]}),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]}):m?a(N,{children:["Total not confirmed ",e("span",{children:"·"})]}):n.repricing||!p?a(N,{children:[T," ",e("span",{children:"·"})]}):a(N,{children:[a("span",{children:[d==="bank"?"Place order":"Continue to payment",a(G,{children:[" · ",c(n.grand,n.currency)]})]}),a("span",{className:"flex items-center gap-3",children:[e("span",{"aria-hidden":"true",className:"max-[359px]:hidden min-[641px]:hidden",children:c(n.grand,n.currency)}),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})]})})]})]})}const be=" [&:disabled_:disabled]:cursor-not-allowed! [&:disabled_:disabled]:opacity-70! [&_input[readonly]]:cursor-not-allowed [&_input[readonly]]:opacity-70";function ye({locked:t,className:i="",children:n}){return e("fieldset",{disabled:t,className:"m-0 min-w-0 border-0 p-0 "+i+be,children:n})}function R({href:t,className:i="",children:n,...l}){const{placing:c}=C();return c?e("span",{"aria-disabled":"true","aria-label":l["aria-label"],className:i+" pointer-events-none",children:n}):e(J,{href:t,"aria-label":l["aria-label"],className:i,children:n})}function Ne({orderNumber:t}){return e(_,{tone:"quiet",role:"status",children:a("span",{className:"flex items-start gap-2",children:[a("svg",{"aria-hidden":!0,viewBox:"0 0 16 16",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"mt-[3px] shrink-0",children:[e("rect",{x:"3",y:"7",width:"10",height:"7",rx:"1"}),e("path",{d:"M5 7V5a3 3 0 0 1 6 0v2"})]}),e("span",{children:ge(t)})]})})}const q={backgroundImage:"linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%)",backgroundPosition:"calc(100% - 18px) 50%, calc(100% - 12px) 50%",backgroundSize:"6px 6px",backgroundRepeat:"no-repeat"};function I({num:t,title:i,children:n}){const{capitalised:l}=C();return a("section",{className:"mb-6 border border-line bg-bg",children:[a("header",{className:"flex items-center gap-4 border-b border-line bg-surface px-6 py-4",children:[e("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:l?String(t):`N° ${String(t).padStart(2,"0")}`}),e("h2",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:i})]}),e("div",{className:"flex flex-col gap-4 px-6 py-6",children:n})]})}function z({cols:t="two",children:i}){return e("div",{className:["grid gap-3 max-[640px]:grid-cols-1",t==="two"?"grid-cols-2":"grid-cols-[1.2fr_1fr_1fr]"].join(" "),children:i})}function P({active:t,onClick:i,title:n,body:l,price:c,tag:d}){return a("button",{type:"button",onClick:i,"aria-pressed":t,className:["relative grid grid-cols-[auto_1fr_auto] items-center gap-5 border bg-bg px-6 py-5 text-left transition-colors",t?"border-accent outline outline-1 outline-accent -outline-offset-1":"border-line enabled:hover:border-[color-mix(in_oklab,var(--accent)_50%,var(--site-line))]"].join(" "),style:t?{background:"color-mix(in oklab, var(--accent) 14%, var(--bg))"}:void 0,children:[t&&e("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-0 w-[3px] bg-accent"}),e("span",{className:["flex h-[18px] w-[18px] items-center justify-center rounded-full border-2",t?"border-accent":"border-fg-dim"].join(" "),children:t&&e("span",{className:"block h-2.5 w-2.5 rounded-full bg-accent"})}),a("span",{className:"flex min-w-0 flex-col gap-1",children:[a("span",{className:"flex flex-wrap items-baseline gap-3 font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:[n,d&&e("span",{className:"border px-2 py-0.5 font-mono text-[11px] font-normal uppercase tracking-[0.24em] text-accent",style:{background:"color-mix(in oklab, var(--accent) 14%, transparent)",borderColor:"color-mix(in oklab, var(--accent) 45%, var(--site-line))"},children:d})]}),l&&e("span",{className:"font-mono text-[12px] uppercase tracking-[0.22em] text-fg-dim",children:l})]}),e("span",{className:"whitespace-nowrap font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:c})]})}function ve({checked:t,onChange:i,label:n,sub:l}){return a("div",{className:"flex items-start gap-3 border-t border-line py-4 first:border-t-0 first:pt-0",children:[e("button",{type:"button",onClick:()=>i(!t),"aria-pressed":t,"aria-label":n,className:["mt-px flex h-5 w-5 flex-shrink-0 items-center justify-center border transition-colors",t?"border-accent":"border-line"].join(" "),style:t?{background:"color-mix(in oklab, var(--accent) 18%, transparent)"}:void 0,children:t&&e("span",{className:"text-[13px] text-accent",children:"✓"})}),a("span",{className:"flex-1 font-display text-[16px] leading-[1.5] text-fg",children:[n,l&&e("small",{className:"mt-1 block font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim",children:l})]})]})}function ke({slug:t,name:i,qty:n,config:l,configSummary:c,price:d,currency:u}){const{catalog:k}=te(),{formatMoney:v}=ne(),h=k.find(m=>m.slug===t),y=h?.spokes??5,o=h?.mesh??!1,s=l.find(m=>m.gold)?.label,g=h?.finishes.find(m=>m.name===s&&m.src)??h?.finishes.find(m=>m.src),p=h?.finishes[0]?.color??me;return a("div",{className:"grid grid-cols-[60px_1fr_auto] items-center gap-4 border-b border-line py-4 last:border-b-0",children:[a("div",{className:"relative aspect-square",children:[e("div",{className:"flex h-full w-full items-center justify-center overflow-hidden border border-line bg-surface",children:g?.src?e(Z,{src:g.src,alt:`${i.lead}${i.accent} — ${g.name}`,width:120,height:120,sizes:"60px",className:"block h-full w-full object-contain p-2"}):e("div",{className:"block w-[78%]",style:{color:p},children:e(ue,{spokes:y,mesh:o,className:"block w-full"})})}),e("span",{className:"absolute -right-1.5 -top-1.5 z-[2] flex h-[18px] w-[18px] items-center justify-center rounded-full bg-accent font-mono text-[11px] font-bold text-bg",children:n})]}),a("div",{className:"flex min-w-0 flex-col gap-0.5",children:[a("span",{className:"font-display text-[17px] font-bold uppercase leading-none tracking-[-0.005em] text-fg",children:[i.lead,e("em",{className:"font-serif font-normal italic text-accent tracking-[-0.005em] normal-case",children:i.accent})]}),e("span",{className:"font-mono text-[12px] uppercase leading-[1.5] tracking-[0.18em] text-fg-dim",children:c})]}),e("span",{className:"text-right font-display text-[17px] font-bold tracking-[-0.005em] text-fg",children:d===null?null:v(d,u)})]})}function G({children:t}){return e("span",{className:"max-[640px]:sr-only",children:t})}function w({label:t,value:i}){return a("div",{className:"flex items-center justify-between font-mono text-[13px] font-medium uppercase tracking-[0.18em] text-fg",children:[e("span",{children:t}),e("strong",{className:"font-display text-[16px] font-medium tracking-[-0.005em] normal-case text-fg",children:i})]})}function Ce(t){return t.map(i=>i.label).join(" · ")}export{qe as CheckoutContact,Ke as CheckoutOrderSummary,We as CheckoutPayment,ze as CheckoutShippingAddress,Ge as CheckoutShippingMethod,ye as FormLock,R as LeaveLink};
|
|
@@ -195,6 +195,7 @@ declare function useCheckoutState({ site, logo, signInHref, preview, textCase }:
|
|
|
195
195
|
orderLocked: boolean;
|
|
196
196
|
formLocked: boolean;
|
|
197
197
|
restoredPrices: "waiting" | "changed" | "same" | null;
|
|
198
|
+
basketRead: boolean;
|
|
198
199
|
quoteFailed: boolean;
|
|
199
200
|
retryQuote: () => void;
|
|
200
201
|
payNote: PayNote | null;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use client";import{jsx as O}from"react/jsx-runtime";import{createContext as
|
|
2
|
-
`);return k===-1?[r,""]:[r.slice(0,k),r.slice(k+1)]}function gn(r,{canParkContext:k}={canParkContext:!0}){const g=r.paymentMethods,m=[];return g.includes("card")&&m.push({key:"card",title:"Card",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),g.includes("paypal")&&r.paypalClientId&&m.push({key:"paypal",title:"PayPal",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAYPAL · CARDS"})}),g.includes("afterpay")&&m.push({key:"afterpay",title:"Afterpay",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"4 × INTEREST-FREE"})}),g.includes("square")&&r.squareApplicationId&&r.squareLocationId&&m.push({key:"square",title:"Card (Square)",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),g.includes("gocardless")&&k&&m.push({key:"gocardless",title:"Bank Direct Debit",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY BY BANK"})}),g.includes("zip")&&m.push({key:"zip",title:"Zip",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY IN 4"})}),g.includes("klarna")&&k&&m.push({key:"klarna",title:"Klarna",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY LATER"})}),g.includes("worldpay")&&m.push({key:"worldpay",title:"Visa / Mastercard / American Express",body:null,price:O("span",{className:"font-mono text-xs uppercase tracking-[0.2em] text-accent",children:"VIA WORLDPAY"})}),g.includes("bank")&&m.push({key:"bank",title:"Bank transfer",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Invoiced"})}),m}const
|
|
3
|
-
${ve.trim()}`:te,cr=eo({email:F,firstName:L,lastName:H,company:Ae.trim(),phone:G,address:Te,city:q,subdivision:E,postcode:T,country:p,lines:f.map(e=>[e.id,e.qty]),shippingMethodId:Q,couponCode:mn(M),currency:b.currency,shopperId:ue?.id??null}),N=JSON.stringify([cr,P]),et=y(null),_e=y(!1),I=y(!1),Z=y(null),Ie=y(!1),v=y(N);v.current=N;const qt=y(x);qt.current=x;const Fe=y(null);h(()=>{const e=()=>{const t=Fe.current;t&&(Fe.current=null,A(t),He(!1))};return window.addEventListener("pageshow",e),()=>window.removeEventListener("pageshow",e)},[]);function de(e,t,o,c){const n={idempotencyKey:t,confirmation:o};Zt()&&(n.lostChange=!0),at.setItem(e,JSON.stringify(n)),window.location.assign(c),Fe.current=o}async function $t(e){He(!0);try{await e()}finally{Fe.current||He(!1)}}const Ut=y(!1),Bt=!!(je||le&&le.kind!=="processing");h(()=>{Bt&&(Ut.current=!0,fe())},[Bt]);const qe=y(null),pe=y(!1),tt=y(null);function fe(){tt.current=null,Br()}const $e=y(null),[j,ar]=s(!1);function nt(e){if(Ut.current||m||pe.current)return;const t={key:e,authed:Qe.current,parkedAt:tt.current??=Date.now(),press:Pn(co,a.current),lines:f.length>0?f:U.current,form:Hr({email:F,firstName:L,lastName:H,company:Ae,address1:te,address2:ve,city:q,postcode:T,phone:G,country:p,subdivision:E,selectedAddressId:Xe,shippingMethodId:Q,couponCode:M?.valid?M.code:null})};Yr(t.press)?Dr(t):fe()}const Yt=y(P);Yt.current=P;function rt(e){return{...Xr(e),...wn(),...e.payFirst?{checkoutFlow:dt}:{}}}function ir(e,t){let o=e.request.payFirst?"":null,c=e.plainPressed?null:"";const n=()=>Yt.current??"";return{key:e.key,send:()=>t(rt(e.request)),request:rt(e.request),lines:e.lines,shape:JSON.stringify([e.goods,null]),get method(){return o??n()},set method(i){o=i},get plainMethod(){return c??n()},set plainMethod(i){c=i},plainLines:e.plainLines,plainShape:JSON.stringify([e.plainGoods,null])}}const[ur,lr]=s(!1),Dt=ur?!b.quoted||b.serverSubtotal===null?"waiting":Math.abs(b.serverSubtotal-b.subtotal)<oo?"same":"changed":null,ot=!w&&Dt==="waiting",dr=ot?{...b,repricing:!0}:b,st=ot&&b.quoteFailed;h(()=>{if(!st)return;const e=setInterval(Ce,ro);return()=>clearInterval(e)},[st,Ce]);const pr=Ce;function Ht(e,t=!0){be(e.email),Ne(e.firstName),Se(e.lastName),Ge(e.company),ne(e.address1),re(e.address2),oe(e.city),se(e.postcode),ce(e.phone),e.country&&ae(e.country),W({country:e.country||null,state:e.subdivision}),Ee(e.selectedAddressId),e.shippingMethodId&&ft(e.shippingMethodId),t&&(qe.current=e.couponCode)}h(()=>{let e=m?null:Wr();const t=!!(e&&f.length>0);if(e&&t&&!zr(e.lines,f)&&(fe(),e=null),e){const o=e.authed?C.createOrderAuthed:C.createOrder;Ke(e.key),tt.current=e.parkedAt,Qe.current=e.authed;const c={lastPress:n=>n&&ir(n,o),keptCardKey:n=>n,placedShape:n=>n===null?null:JSON.stringify([n,null]),placedRequest:n=>{if(!n)return null;const i=rt(n);return{body:i,send:()=>o(i)}},unpaidOrder:n=>n};a.current=Pn(c,e.press),e.press.unpaidOrder&&A(e.press.unpaidOrder),e.lines.length>0&&!t&&(De(e.lines),U.current=e.lines,lr(!0)),e.form&&($e.current=e.form,Ht(e.form))}ar(!0)},[]),h(()=>{!j||f.length>0||a.current.unpaidOrder||x||(pe.current=!0,fe())},[j,f.length]),h(()=>{const e=qe.current;!j||!e||f.length===0||(qe.current=null,vn(e,F||void 0))},[j,f.length]),h(()=>{!j||x||nt($)},[j,x,$,w]);const B=y(null);h(()=>{qt.current||(N!==B.current&&(B.current=null),!(!I.current||!w||w.orderNumber)&&(N===a.current.placedShape||N===B.current||$t(()=>Gt(w))))},[N,w]);async function Gt(e){if(Ie.current)return null;Ie.current=!0;try{const t=Z.current?await Vr(Z.current):"none";if(t==="succeeded"||t==="processing")return I.current=!1,A(null),K("card"),t==="succeeded"?await Y(void 0,e):tn(e),null;if(t===void 0||!Zr.has(t))return B.current=v.current,A(e),S(t==="requires_action"?Jr:ut),null;const o=await fn($);if(o==="committed")return I.current=!1,A(null),K("card"),await Y(void 0,e),null;if(o!=="released")return B.current=v.current,A(e),S(ut),null;I.current=!1,Z.current=null,B.current=null,S(null),A(null);const c=Be();return Ke(c),c}finally{Ie.current=!1}}async function fr(){m||x||Ie.current||await $t(yr)}async function yr(){if(w){if((I.current?N!==a.current.placedShape:ye())&&!w.orderNumber){const c=await Gt(w);c&&v.current===N&&await Wt(c);return}S(null),_e.current=!1,await ct();const t=R(v.current)[1],o=w.orderNumber?t:"card";if(o&&Cn.has(o)&&ye()&&R(v.current)[0]!==et.current){zt(w);return}K(o),o!==P&&Pe(o),await nn(w,o,!w.orderNumber);return}await Wt($)}async function Wt(e){if(f.length===0||b.repricing||ot||!P||!J.some(l=>l.key===P))return;const t=f.filter(ln).flatMap(l=>Rr(l.components,l.qty));if(t.length===0){S("Pick a size on each wheel's product page before checking out.");return}S(null);let o,c=e,n=P,i=!1;try{const l=ue?C.createOrderAuthed:C.createOrder,u={customer:{email:F,name:`${L} ${H}`.trim(),phone:G.trim()||void 0,companyName:Ae.trim()||void 0,address:Te,city:q,state:E||void 0,zipCode:T,country:p},items:t,currency:b.currency,idempotencyKey:e,shippingMethodId:Q??void 0,couponCode:mn(M),...wn(),...jr(P)?{checkoutFlow:dt}:{}};a.current.placedRequest={body:u,send:()=>l(u)},Qe.current=!!ue,pe.current=!1,Ze(null),et.current=null,_e.current=!1,Z.current=null,I.current=!1,B.current=null,a.current.placedShape=N,U.current=f;const d=a.current.lastPress,V=d?.key===u.idempotencyKey&&(d.shape!==N&&(!!u.checkoutFlow||!!d.method||!!d.plainMethod)||!!u.checkoutFlow&&!!d.plainMethod);V&&(a.current.keptCardKey=u.idempotencyKey);const sn=Vt(u,l),cn=V||!u.checkoutFlow&&a.current.keptCardKey===u.idempotencyKey,an=!sn&&!cn&&!u.checkoutFlow&&!!d&&!d.method;an&&(d.plainMethod=P,d.plainLines=f,d.plainShape=N,nt(u.idempotencyKey));const D=await(cn?Jt(u,l):l(u).then(me=>({answer:me,request:u})).catch(me=>(sn?Xt(me,u.idempotencyKey):an&&yn(me)&&(d.plainMethod=""),mr(me,u,l))));if(!D)return;o=D.answer,c=D.request.idempotencyKey,n=D.method??n,K(n),i=ye()||n!==R(v.current)[1],D.method&&D.method!==P&&Pe(D.method),o.orderNumber&&(Qt(o),we()),await ct()}catch(l){const u=no(l);u?(Sn(u),S(`${u} Your order has not been placed. Place it again to continue without the code.`)):l instanceof Ye?S(ut):S(l instanceof Ue?l.message:"Could not place the order. Please try again.");return}if(n&&Cn.has(n)&&(i||ye())){zt(o);return}await nn(o,n,!1,c)}function zt(e){et.current=R(v.current)[0],S(`${kn(e,null)} ${lt}`),A(e)}function Xt(e,t){yn(e)&&!pn(e)&&a.current.lastPress?.key===t&&(a.current.lastPress=null)}async function mr(e,t,o){if(it(e))return jt(t,o);if(!pn(e))throw e;return a.current.keptCardKey=t.idempotencyKey,Jt(t,o,!0)}async function Jt(e,t,o=!1){const c=await fn(e.idempotencyKey);if(c==="released")return jt(e,t);if(c!=="committed")throw new Ye;const n=a.current.lastPress?.key===e.idempotencyKey?a.current.lastPress:null;if(U.current=n?.lines??f,n?.method&&!o){a.current.keptCardKey=null,a.current.placedRequest={body:n.request,send:n.send};const V=await n.send().catch(()=>{throw new Ye});return a.current.placedShape=n.shape,{answer:V,request:e,method:n.method}}const i={...e,checkoutFlow:dt},l=n&&!n.method?{body:n.request,send:n.send}:{body:i,send:()=>t(i)};a.current.placedRequest=l;const u=l.send,d=await u().catch(()=>null);if(!d&&n?.plainMethod)throw new Ye;return d?.orderNumber&&d.status!==Qr?(a.current.keptCardKey=null,n?.plainMethod&&(U.current=n.plainLines),n&&(a.current.placedShape=n.plainMethod?n.plainShape:n.shape),{answer:d,request:e,method:n?.plainMethod||void 0}):(n&&(a.current.placedShape=n.shape),K("card"),await en("",d?async()=>d:()=>Promise.reject(new Error("The order request did not answer."))),await ct(),null)}function ye(){const e=a.current.placedShape;return e!==null&&R(e)[0]!==R(v.current)[0]}function K(e){e!==R(v.current)[1]&&(_e.current=!0),Ze(Zt()?lt:null)}function Zt(){return _e.current||ye()}async function jt(e,t){const o={...e,idempotencyKey:Be()};a.current.keptCardKey=null,Ke(o.idempotencyKey),a.current.placedRequest={body:o,send:()=>t(o)},Vt(o,t);try{return{answer:await t(o),request:o}}catch(c){throw Xt(c,o.idempotencyKey),c}}function Vt(e,t){return a.current.lastPress?.key===e.idempotencyKey?!1:(a.current.lastPress={key:e.idempotencyKey,send:()=>t(e),request:e,lines:f,shape:N,method:e.checkoutFlow?"":P??"",plainMethod:"",plainLines:f,plainShape:N},pe.current=!1,nt(e.idempotencyKey),!0)}function Qt(e){vr({confirmation:e,lines:U.current,adsSendTo:r.googleAdsId&&r.googleAdsConversionLabel?`${r.googleAdsId}/${r.googleAdsConversionLabel}`:null}),Or({confirmation:e,lines:U.current})}async function Y(e,t=_){if(!t)return;const o=e?async()=>e:a.current.placedRequest?.send;if(t.orderNumber||!o){xe(!0),z(t);return}await en(t.checkoutNumber,o)}async function en(e,t){we(),await to({checkoutNumber:e,resend:t,page:{setConfirming:tr,land:z,markPaid:()=>xe(!0),track:Qt,unplaced:Lt}})}function tn(e=_){if(e){if(e.orderNumber){z(e);return}we(),Lt({kind:"processing",checkoutNumber:e.checkoutNumber})}}async function ct(){const e=JSON.stringify([Je.trim(),L,H,G.trim(),Te,q,E,T,p]);if(!(!ue||!St||Xe!=="new"||Ot.current===e))try{await he.createAddress({label:Je.trim()||"Home",contact_name:`${L} ${H}`.trim(),phone:G.trim(),address:Te,city:q,zip_code:T,state:E,country:p}),Ot.current=e,vt("Address saved to your account.")}catch{vt("We couldn't save the address to your account — you can add it under Account → Addresses.")}}async function nn(e,t=P,o=!1,c=$){A(null);try{if(t==="card"&&r.paymentMethods.includes("card")){const n=await C.createPaymentIntent({idempotencyKey:c});Z.current=n;let i=e;if(o){const l=await a.current.placedRequest?.send().catch(()=>null);if(l?.orderNumber){K("card"),await Y(l,e);return}i=rn(e,l)??{...e,expiresAt:null}}K("card"),X(i),Ve(!1),Me(n)}else if(t==="paypal"&&r.paymentMethods.includes("paypal"))X(e),$n(!0);else if(t==="afterpay"&&r.paymentMethods.includes("afterpay")){const n=window.location.origin,i=await C.createAfterpayCheckout({idempotencyKey:c,confirmUrl:`${n}/checkout?afterpay=confirm`,cancelUrl:`${n}/checkout?afterpay=cancel`});de(Kr,c,e,i.redirectCheckoutUrl);return}else if(t==="square"&&r.paymentMethods.includes("square"))X(e),Un(!0);else if(t==="gocardless"&&r.paymentMethods.includes("gocardless")){const n=window.location.origin,i=await C.createGocardlessBillingRequest({idempotencyKey:c,confirmUrl:`${n}/checkout?gocardless=confirm`,cancelUrl:`${n}/checkout?gocardless=cancel`});de(xr,c,e,i.authorisationUrl);return}else if(t==="zip"&&r.paymentMethods.includes("zip")){const n=window.location.origin,i=await C.createZipCheckout({idempotencyKey:c,redirectUrl:`${n}/checkout?zip=return`});de(qr,c,e,i.redirectUrl);return}else if(t==="klarna"&&r.paymentMethods.includes("klarna")){const n=window.location.origin,i=await C.createKlarnaCheckout({idempotencyKey:c,confirmUrl:`${n}/checkout?klarna=confirm`,cancelUrl:`${n}/checkout?klarna=cancel`});de(Tr,c,e,i.redirectUrl);return}else if(t==="worldpay"&&r.paymentMethods.includes("worldpay")){const n=window.location.origin,i=await C.createWorldpayCheckout({idempotencyKey:c,successUrl:`${n}/checkout?worldpay=return`,cancelUrl:`${n}/checkout?worldpay=cancel`});de(Ir,c,e,i.redirectUrl);return}else K(t),z(e)}catch(n){if((o||t==="card")&&n instanceof Ue&&n.status===409){K(t),await Y(void 0,e);return}on(e,n)}}function rn(e,t){return t&&!t.orderNumber&&t.status==="open"&&t.checkoutNumber===e.checkoutNumber?t:null}function on(e,t){S(kn(e,t)),!e.orderNumber&&it(t)?(I.current=!1,Ke(Be())):A(e)}async function hr(e){if(!_)return;const t=_;try{const o=await C.createPaymentIntent({idempotencyKey:$}),c=await a.current.placedRequest?.send().catch(()=>null);if(c?.orderNumber){await Y(c);return}const n=rn(t,c);X(n??{...t,expiresAt:null}),Ve(e&&n!==null),Z.current=o,Me(o)}catch(o){if(o instanceof Ue&&o.status===409){await Y();return}Me(null),X(null),on(t,o)}}function gr(){_&&(I.current=!0,A(_),Me(null),X(null),Ve(!1))}return{site:r,logo:k,signInHref:g,capitalised:br(Nn)==="capitalised",items:f,totals:dr,coupon:M,deliveryOptions:pt,courierUnavailable:xn,retryCourier:Ln,shippingMethodId:Q,setShippingMethodId:ft,pickupLocation:On,servedCountries:ee,formatMoney:Rn,payChoice:P,setPayChoice:Pe,placing:x,email:F,setEmail:be,firstName:L,setFirstName:Ne,lastName:H,setLastName:Se,company:Ae,setCompany:Ge,address1:te,setAddress1:ne,address2:ve,setAddress2:re,city:q,setCity:oe,postcode:T,setPostcode:se,phone:G,setPhone:ce,country:p,setCountry:ae,subdivision:E,setSubdivision:Oe,subdivisions:ie,destination:wt,postcodeLabel:Kn,subdivisionLabel:Mn,me:ue,savedAddresses:Tn,selectedAddressId:Xe,setSelectedAddressId:Ee,saveAddress:St,setSaveAddress:At,saveLabel:Je,setSaveLabel:_n,addressSaveNote:In,lostChangeNote:Fn,idemKey:$,confirmation:je,setConfirmation:z,orderError:qn,payment:Rt,paypalStep:Et,squareStep:Kt,pendingConf:_,paid:Bn,setPaid:xe,unpaidOrder:w,orderLocked:Mt,formLocked:Yn,restoredPrices:Dt,quoteFailed:st,retryQuote:pr,payNote:Dn,afterpayConfirming:Gn,gocardlessConfirming:zn,zipConfirming:Jn,klarnaConfirming:jn,worldpayConfirming:Qn,cardConfirming:xt,checkoutResult:le,confirmCardPayment:Y,cardStillProcessing:tn,renewCardPayment:hr,holdRenewed:nr,leaveCardPayment:gr,checkoutRootRef:It,setCheckoutHeaderEl:rr,fillFromAddress:Ft,checkoutSignOut:or,payOptions:J,noPaymentMethod:sr,placeOrder:fr}}const bn=kr(null);function Mo({children:r,...k}){const g=ao(k);return O(bn.Provider,{value:g,children:r})}function xo(){const r=Cr(bn);if(!r)throw new Error("useCheckout must be used inside CheckoutStateProvider");return r}export{Mo as CheckoutStateProvider,Ro as NO_PAYMENT_METHOD_NOTE,Eo as SHIPPING_RETRY_NOTE,gn as buildPayOptions,kn as paymentNotStartedMessage,Ko as placedOrderLockNote,xo as useCheckout};
|
|
1
|
+
"use client";import{jsx as O}from"react/jsx-runtime";import{createContext as Cr,useContext as wr,useEffect as h,useMemo as un,useRef as y,useState as s}from"react";import{isOrderable as ln,useCart as Pr}from"../CartContext.js";import{useCurrency as br}from"../CurrencyContext.js";import{resolveNavTextCase as Nr}from"../../lib/content/header-bar.js";import{getClickIds as Sr}from"../../lib/click-ids.js";import{adConsentForOrder as Ar}from"../../lib/consent/choice.js";import{trackBeginCheckout as vr,trackPurchase as Or}from"../../lib/google-tag.js";import{trackMetaPurchase as Rr}from"../../lib/meta-pixel.js";import{ApiError as Ue,api as he,products as C}from"../../lib/api/index.js";import{uuid as Be}from"../../lib/uuid.js";import{orderLinesForSets as Er}from"../../lib/commerce.js";import{canPersist as Kr,safeSessionStorage as at}from"efficient-web-builder/format/lib/safe-storage";import{AFTERPAY_CONTEXT_KEY as Mr,AFTERPAY_RETURN as xr,GOCARDLESS_CONTEXT_KEY as Lr,GOCARDLESS_RETURN as Tr,KLARNA_CONTEXT_KEY as _r,KLARNA_RETURN as Ir,WORLDPAY_CONTEXT_KEY as Fr,WORLDPAY_RETURN as qr,ZIP_CONTEXT_KEY as $r,ZIP_RETURN as Ur,runWalletReturn as ge}from"../../lib/checkout/wallet-return.js";import{matchSubdivision as Br}from"../../lib/checkout/match-subdivision.js";import{clearCheckoutMemory as Yr,holdsPress as Dr,parkCheckoutMemory as Hr,parkForm as Gr,parkOrder as Wr,parkRequest as dn,readCheckoutMemory as zr,sameGoods as Xr,sendableRequest as Jr}from"../../lib/checkout/checkout-memory.js";import{checkoutGone as it,checkoutWaiting as pn,BANK_WAITING as Zr,DROPPABLE_INTENT as jr,NOT_CHECKED as ut,LOST_CHANGE as lt,PAY_FIRST_FLOW as dt,paysFirst as Vr,readIntentStatus as Qr,releaseHeldCheckout as fn,CHECKOUT_COMMITTED as eo,goodsShapeOf as to,refusedForGood as yn,settlePayFirst as no}from"../../lib/checkout/pay-first.js";import{couponCodeForOrder as mn,couponRefusedByOrder as ro}from"../../lib/cart/coupon-preview.js";function hn(r){const k=r.indexOf(`
|
|
2
|
+
`);return k===-1?[r,""]:[r.slice(0,k),r.slice(k+1)]}function gn(r,{canParkContext:k}={canParkContext:!0}){const g=r.paymentMethods,m=[];return g.includes("card")&&m.push({key:"card",title:"Card",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),g.includes("paypal")&&r.paypalClientId&&m.push({key:"paypal",title:"PayPal",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAYPAL · CARDS"})}),g.includes("afterpay")&&m.push({key:"afterpay",title:"Afterpay",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"4 × INTEREST-FREE"})}),g.includes("square")&&r.squareApplicationId&&r.squareLocationId&&m.push({key:"square",title:"Card (Square)",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),g.includes("gocardless")&&k&&m.push({key:"gocardless",title:"Bank Direct Debit",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY BY BANK"})}),g.includes("zip")&&m.push({key:"zip",title:"Zip",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY IN 4"})}),g.includes("klarna")&&k&&m.push({key:"klarna",title:"Klarna",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY LATER"})}),g.includes("worldpay")&&m.push({key:"worldpay",title:"Visa / Mastercard / American Express",body:null,price:O("span",{className:"font-mono text-xs uppercase tracking-[0.2em] text-accent",children:"VIA WORLDPAY"})}),g.includes("bank")&&m.push({key:"bank",title:"Bank transfer",body:null,price:O("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Invoiced"})}),m}const Eo="This shop does not take payment online yet. Please contact the shop to order.";class Ye extends Error{}function kn(r,k){if(!r.orderNumber&&it(k))return k.message;const g=k instanceof Ue?` (${k.message})`:"";return r.orderNumber?`Your order ${r.orderNumber} is saved, but the payment did not start${g}. Try the payment again — your order will not be placed twice.`:`Your items are held under ${r.checkoutNumber}, but the payment did not start${g}. Try the payment again — you will not be charged twice.`}const oo=3e3,so=.005,Cn=new Set(["paypal","square","afterpay","gocardless","zip","klarna","worldpay"]);function wn(){const r=Ar();return{...r==="denied"?{}:Sr(),...r?{adConsent:r}:{}}}const R=r=>JSON.parse(r),co={lastPress:null,keptCardKey:null,placedShape:null,placedRequest:null,unpaidOrder:null},ao={lastPress:r=>r&&{key:r.key,request:dn(r.request),lines:r.lines,goods:R(r.shape)[0],plainPressed:!!r.plainMethod,plainLines:r.plainLines,plainGoods:R(r.plainShape)[0]},keptCardKey:r=>r,placedShape:r=>r===null?null:R(r)[0],placedRequest:r=>r&&dn(r.body),unpaidOrder:r=>r&&Wr(r)};function Pn(r,k){const g={};for(const m of Object.keys(r))g[m]=r[m](k[m]);return g}const Ko="Shipping cannot be calculated right now. Please try again.";function Mo(r){return`Your order is saved, so its contact, address, delivery and discount can't change here. To change any of them, contact the shop and quote ${r}.`}function io({site:r,logo:k,signInHref:g=null,preview:m=!1,textCase:Nn}){const{items:f,basketRead:Sn,totals:b,coupon:M,refuseCoupon:An,deliveryOptions:pt,shippingMethodId:Q,setShippingMethodId:ft,setQuoteDestination:ke,courier:vn,requote:Ce,identify:yt,clearCapturedCart:we,replaceItems:De,removeCoupon:mt,applyCoupon:On}=Pr(),Rn=pt.find(e=>e.id===Q)?.pickupLocation??null,{country:ht,countries:ee,activeCountry:gt,formatMoney:En}=br(),[P,Pe]=s(()=>gn(r)[0]?.key??null),[kt,Kn]=s(!0);h(()=>{Kn(Kr(at))},[]);const[x,He]=s(!1),[F,be]=s(""),[L,Ne]=s(""),[H,Se]=s(""),[Ae,Ge]=s(""),[te,ne]=s(""),[ve,re]=s(""),[q,oe]=s(""),[T,se]=s(""),[G,ce]=s(""),[p,ae]=s(()=>ht||ee[0]?.code||""),[E,Oe]=s(""),[ie,Ct]=s([]),[We,ze]=s(null),[Re,W]=s(null),wt=un(()=>ee.find(e=>e.code===p)??gt,[ee,p,gt]),Mn=wt?.postalLabel||"Postal Code",xn=ie[0]?.divisionType||"State / Province";h(()=>{if(!p){Ct([]),ze(p);return}ze(null);let e=!1;return C.listCountrySubdivisions(p).then(t=>{e||(Ct(t),ze(p),Oe(""))}),()=>{e=!0}},[p]);const Pt=te.trim()!==""&&q.trim()!==""&&T.trim()!==""&&We===p&&(ie.length===0||E!=="")?T.trim():"";h(()=>{ke(p?{country:p,subdivision:E,postcode:Pt}:null)},[p,E,Pt,ke]),h(()=>()=>ke(null),[ke]);const Ln=vn?.status==="unavailable",Tn=Ce,[ue,bt]=s(null),[_n,Nt]=s([]),[Xe,Ee]=s("new"),[St,At]=s(!1),[Je,In]=s("Home"),[Fn,vt]=s(null),[qn,Ze]=s(null),[$,Ke]=s(()=>Be()),Ot=y(null),[je,z]=s(null),[$n,S]=s(null),[Rt,Me]=s(null),[Et,Un]=s(!1),[Kt,Bn]=s(!1),[_,X]=s(null),[Yn,xe]=s(!1),[w,A]=s(null),Mt=!!w?.orderNumber,Dn=Mt||x,[Hn,Gn]=s(null),[Wn,zn]=s(!1),[Xn,Jn]=s(!1),[Zn,jn]=s(!1),[Vn,Qn]=s(!1),[er,tr]=s(!1),[xt,nr]=s(!1),[rr,Ve]=s(!1),[le,Lt]=s(null),a=y({...co});a.current.unpaidOrder=w;const Qe=y(!1),U=y(f),Tt=!!(je||le&&le.kind!=="processing"||xt||Et||Kt||Rt&&_?.orderNumber);h(()=>{Tt&&(De([]),mt())},[Tt,De,mt]);const _t=y(!1);h(()=>{m||_t.current||!f.some(ln)||(_t.current=!0,vr({lines:f,currency:b.currency,value:b.subtotal-b.discount,coupon:M?.valid?M.code:void 0}))},[f,b,M,m]),h(()=>{yt(F,L.trim()||void 0)},[F,L,yt]);const It=y(null),[Le,or]=s(null);h(()=>{const e=It.current;if(!Le||!e)return;const t=()=>e.style.setProperty("--sf-checkout-header-h",`${Le.offsetHeight}px`);t();const o=new ResizeObserver(t);return o.observe(Le),()=>o.disconnect()},[Le]),h(()=>{const e=o=>({setConfirming:o,land:z,markPaid:()=>xe(!0),note:(c,n)=>Gn({text:c,warning:n}),fail:S,clearCart:we,lostChange:()=>Ze(lt)}),t={search:window.location.search,storage:at,scrubQuery:()=>window.history.replaceState(null,"",window.location.pathname)};ge(xr,{...t,capture:C.captureAfterpayPayment,page:e(zn)}),ge(Ur,{...t,capture:C.captureZipPayment,page:e(jn)}),ge(Tr,{...t,capture:C.completeGocardlessPayment,page:e(Jn)}),ge(Ir,{...t,capture:C.captureKlarnaPayment,page:e(Qn)}),ge(qr,{...t,capture:C.confirmWorldpayPayment,page:e(tr)})},[]);function Ft(e){const[t,o]=hn(e.address);ne(t),re(o),oe(e.city),se(e.zip_code),e.country&&ae(e.country),e.phone&&ce(e.phone),W({country:e.country||null,state:e.state??""})}h(()=>{if(Re){if((Re.country||p)!==p){W(null);return}We===p&&(Oe(Br(p,Re.state,ie)),W(null))}},[Re,p,We,ie]),h(()=>{let e=!1;return(async()=>{try{const[t,o,c]=await Promise.all([he.me(),he.myProfile().catch(()=>null),he.myAddresses().catch(()=>[])]);if(e)return;bt(t);const n=c.filter(d=>d.is_active);Nt(n),be(t.email);const i=(o?.contact_name??"").split(/\s+/);Ne(t.first_name||i[0]||""),Se(t.last_name||i.slice(1).join(" "));const l=t.phone||o?.phone;l&&ce(l);const u=n.find(d=>d.id===t.default_delivery_location)??n[0];if(u)Ee(u.id),Ft(u);else if(o){const[d,V]=hn(o.address??"");ne(d),re(V),oe(o.city??""),se(o.zip_code??""),o.country&&ae(o.country),W({country:o.country||null,state:o.state??""})}$e.current&&Ht($e.current,!1)}catch{}})(),()=>{e=!0}},[]);function sr(){he.logout(),pe.current=!0,$e.current=null,qe.current=null,fe(),bt(null),Nt([]),Ee("new"),At(!1),be(""),Ne(""),Se(""),Ge(""),ne(""),re(""),oe(""),se(""),ce(""),ae(ht||ee[0]?.code||""),Oe(""),W(null)}const J=un(()=>gn(r,{canParkContext:kt}),[r,kt]);h(()=>{J.some(e=>e.key===P)||Pe(J[0]?.key??null)},[J,P]);const cr=J.length===0,Te=ve.trim()?`${te}
|
|
3
|
+
${ve.trim()}`:te,ar=to({email:F,firstName:L,lastName:H,company:Ae.trim(),phone:G,address:Te,city:q,subdivision:E,postcode:T,country:p,lines:f.map(e=>[e.id,e.qty]),shippingMethodId:Q,couponCode:mn(M),currency:b.currency,shopperId:ue?.id??null}),N=JSON.stringify([ar,P]),et=y(null),_e=y(!1),I=y(!1),Z=y(null),Ie=y(!1),v=y(N);v.current=N;const qt=y(x);qt.current=x;const Fe=y(null);h(()=>{const e=()=>{const t=Fe.current;t&&(Fe.current=null,A(t),He(!1))};return window.addEventListener("pageshow",e),()=>window.removeEventListener("pageshow",e)},[]);function de(e,t,o,c){const n={idempotencyKey:t,confirmation:o};Zt()&&(n.lostChange=!0),at.setItem(e,JSON.stringify(n)),window.location.assign(c),Fe.current=o}async function $t(e){He(!0);try{await e()}finally{Fe.current||He(!1)}}const Ut=y(!1),Bt=!!(je||le&&le.kind!=="processing");h(()=>{Bt&&(Ut.current=!0,fe())},[Bt]);const qe=y(null),pe=y(!1),tt=y(null);function fe(){tt.current=null,Yr()}const $e=y(null),[j,ir]=s(!1);function nt(e){if(Ut.current||m||pe.current)return;const t={key:e,authed:Qe.current,parkedAt:tt.current??=Date.now(),press:Pn(ao,a.current),lines:f.length>0?f:U.current,form:Gr({email:F,firstName:L,lastName:H,company:Ae,address1:te,address2:ve,city:q,postcode:T,phone:G,country:p,subdivision:E,selectedAddressId:Xe,shippingMethodId:Q,couponCode:M?.valid?M.code:null})};Dr(t.press)?Hr(t):fe()}const Yt=y(P);Yt.current=P;function rt(e){return{...Jr(e),...wn(),...e.payFirst?{checkoutFlow:dt}:{}}}function ur(e,t){let o=e.request.payFirst?"":null,c=e.plainPressed?null:"";const n=()=>Yt.current??"";return{key:e.key,send:()=>t(rt(e.request)),request:rt(e.request),lines:e.lines,shape:JSON.stringify([e.goods,null]),get method(){return o??n()},set method(i){o=i},get plainMethod(){return c??n()},set plainMethod(i){c=i},plainLines:e.plainLines,plainShape:JSON.stringify([e.plainGoods,null])}}const[lr,dr]=s(!1),Dt=lr?!b.quoted||b.serverSubtotal===null?"waiting":Math.abs(b.serverSubtotal-b.subtotal)<so?"same":"changed":null,ot=!w&&Dt==="waiting",pr=ot?{...b,repricing:!0}:b,st=ot&&b.quoteFailed;h(()=>{if(!st)return;const e=setInterval(Ce,oo);return()=>clearInterval(e)},[st,Ce]);const fr=Ce;function Ht(e,t=!0){be(e.email),Ne(e.firstName),Se(e.lastName),Ge(e.company),ne(e.address1),re(e.address2),oe(e.city),se(e.postcode),ce(e.phone),e.country&&ae(e.country),W({country:e.country||null,state:e.subdivision}),Ee(e.selectedAddressId),e.shippingMethodId&&ft(e.shippingMethodId),t&&(qe.current=e.couponCode)}h(()=>{let e=m?null:zr();const t=!!(e&&f.length>0);if(e&&t&&!Xr(e.lines,f)&&(fe(),e=null),e){const o=e.authed?C.createOrderAuthed:C.createOrder;Ke(e.key),tt.current=e.parkedAt,Qe.current=e.authed;const c={lastPress:n=>n&&ur(n,o),keptCardKey:n=>n,placedShape:n=>n===null?null:JSON.stringify([n,null]),placedRequest:n=>{if(!n)return null;const i=rt(n);return{body:i,send:()=>o(i)}},unpaidOrder:n=>n};a.current=Pn(c,e.press),e.press.unpaidOrder&&A(e.press.unpaidOrder),e.lines.length>0&&!t&&(De(e.lines),U.current=e.lines,dr(!0)),e.form&&($e.current=e.form,Ht(e.form))}ir(!0)},[]),h(()=>{!j||f.length>0||a.current.unpaidOrder||x||(pe.current=!0,fe())},[j,f.length]),h(()=>{const e=qe.current;!j||!e||f.length===0||(qe.current=null,On(e,F||void 0))},[j,f.length]),h(()=>{!j||x||nt($)},[j,x,$,w]);const B=y(null);h(()=>{qt.current||(N!==B.current&&(B.current=null),!(!I.current||!w||w.orderNumber)&&(N===a.current.placedShape||N===B.current||$t(()=>Gt(w))))},[N,w]);async function Gt(e){if(Ie.current)return null;Ie.current=!0;try{const t=Z.current?await Qr(Z.current):"none";if(t==="succeeded"||t==="processing")return I.current=!1,A(null),K("card"),t==="succeeded"?await Y(void 0,e):tn(e),null;if(t===void 0||!jr.has(t))return B.current=v.current,A(e),S(t==="requires_action"?Zr:ut),null;const o=await fn($);if(o==="committed")return I.current=!1,A(null),K("card"),await Y(void 0,e),null;if(o!=="released")return B.current=v.current,A(e),S(ut),null;I.current=!1,Z.current=null,B.current=null,S(null),A(null);const c=Be();return Ke(c),c}finally{Ie.current=!1}}async function yr(){m||x||Ie.current||await $t(mr)}async function mr(){if(w){if((I.current?N!==a.current.placedShape:ye())&&!w.orderNumber){const c=await Gt(w);c&&v.current===N&&await Wt(c);return}S(null),_e.current=!1,await ct();const t=R(v.current)[1],o=w.orderNumber?t:"card";if(o&&Cn.has(o)&&ye()&&R(v.current)[0]!==et.current){zt(w);return}K(o),o!==P&&Pe(o),await nn(w,o,!w.orderNumber);return}await Wt($)}async function Wt(e){if(f.length===0||b.repricing||ot||!P||!J.some(l=>l.key===P))return;const t=f.filter(ln).flatMap(l=>Er(l.components,l.qty));if(t.length===0){S("Pick a size on each wheel's product page before checking out.");return}S(null);let o,c=e,n=P,i=!1;try{const l=ue?C.createOrderAuthed:C.createOrder,u={customer:{email:F,name:`${L} ${H}`.trim(),phone:G.trim()||void 0,companyName:Ae.trim()||void 0,address:Te,city:q,state:E||void 0,zipCode:T,country:p},items:t,currency:b.currency,idempotencyKey:e,shippingMethodId:Q??void 0,couponCode:mn(M),...wn(),...Vr(P)?{checkoutFlow:dt}:{}};a.current.placedRequest={body:u,send:()=>l(u)},Qe.current=!!ue,pe.current=!1,Ze(null),et.current=null,_e.current=!1,Z.current=null,I.current=!1,B.current=null,a.current.placedShape=N,U.current=f;const d=a.current.lastPress,V=d?.key===u.idempotencyKey&&(d.shape!==N&&(!!u.checkoutFlow||!!d.method||!!d.plainMethod)||!!u.checkoutFlow&&!!d.plainMethod);V&&(a.current.keptCardKey=u.idempotencyKey);const sn=Vt(u,l),cn=V||!u.checkoutFlow&&a.current.keptCardKey===u.idempotencyKey,an=!sn&&!cn&&!u.checkoutFlow&&!!d&&!d.method;an&&(d.plainMethod=P,d.plainLines=f,d.plainShape=N,nt(u.idempotencyKey));const D=await(cn?Jt(u,l):l(u).then(me=>({answer:me,request:u})).catch(me=>(sn?Xt(me,u.idempotencyKey):an&&yn(me)&&(d.plainMethod=""),hr(me,u,l))));if(!D)return;o=D.answer,c=D.request.idempotencyKey,n=D.method??n,K(n),i=ye()||n!==R(v.current)[1],D.method&&D.method!==P&&Pe(D.method),o.orderNumber&&(Qt(o),we()),await ct()}catch(l){const u=ro(l);u?(An(u),S(`${u} Your order has not been placed. Place it again to continue without the code.`)):l instanceof Ye?S(ut):S(l instanceof Ue?l.message:"Could not place the order. Please try again.");return}if(n&&Cn.has(n)&&(i||ye())){zt(o);return}await nn(o,n,!1,c)}function zt(e){et.current=R(v.current)[0],S(`${kn(e,null)} ${lt}`),A(e)}function Xt(e,t){yn(e)&&!pn(e)&&a.current.lastPress?.key===t&&(a.current.lastPress=null)}async function hr(e,t,o){if(it(e))return jt(t,o);if(!pn(e))throw e;return a.current.keptCardKey=t.idempotencyKey,Jt(t,o,!0)}async function Jt(e,t,o=!1){const c=await fn(e.idempotencyKey);if(c==="released")return jt(e,t);if(c!=="committed")throw new Ye;const n=a.current.lastPress?.key===e.idempotencyKey?a.current.lastPress:null;if(U.current=n?.lines??f,n?.method&&!o){a.current.keptCardKey=null,a.current.placedRequest={body:n.request,send:n.send};const V=await n.send().catch(()=>{throw new Ye});return a.current.placedShape=n.shape,{answer:V,request:e,method:n.method}}const i={...e,checkoutFlow:dt},l=n&&!n.method?{body:n.request,send:n.send}:{body:i,send:()=>t(i)};a.current.placedRequest=l;const u=l.send,d=await u().catch(()=>null);if(!d&&n?.plainMethod)throw new Ye;return d?.orderNumber&&d.status!==eo?(a.current.keptCardKey=null,n?.plainMethod&&(U.current=n.plainLines),n&&(a.current.placedShape=n.plainMethod?n.plainShape:n.shape),{answer:d,request:e,method:n?.plainMethod||void 0}):(n&&(a.current.placedShape=n.shape),K("card"),await en("",d?async()=>d:()=>Promise.reject(new Error("The order request did not answer."))),await ct(),null)}function ye(){const e=a.current.placedShape;return e!==null&&R(e)[0]!==R(v.current)[0]}function K(e){e!==R(v.current)[1]&&(_e.current=!0),Ze(Zt()?lt:null)}function Zt(){return _e.current||ye()}async function jt(e,t){const o={...e,idempotencyKey:Be()};a.current.keptCardKey=null,Ke(o.idempotencyKey),a.current.placedRequest={body:o,send:()=>t(o)},Vt(o,t);try{return{answer:await t(o),request:o}}catch(c){throw Xt(c,o.idempotencyKey),c}}function Vt(e,t){return a.current.lastPress?.key===e.idempotencyKey?!1:(a.current.lastPress={key:e.idempotencyKey,send:()=>t(e),request:e,lines:f,shape:N,method:e.checkoutFlow?"":P??"",plainMethod:"",plainLines:f,plainShape:N},pe.current=!1,nt(e.idempotencyKey),!0)}function Qt(e){Or({confirmation:e,lines:U.current,adsSendTo:r.googleAdsId&&r.googleAdsConversionLabel?`${r.googleAdsId}/${r.googleAdsConversionLabel}`:null}),Rr({confirmation:e,lines:U.current})}async function Y(e,t=_){if(!t)return;const o=e?async()=>e:a.current.placedRequest?.send;if(t.orderNumber||!o){xe(!0),z(t);return}await en(t.checkoutNumber,o)}async function en(e,t){we(),await no({checkoutNumber:e,resend:t,page:{setConfirming:nr,land:z,markPaid:()=>xe(!0),track:Qt,unplaced:Lt}})}function tn(e=_){if(e){if(e.orderNumber){z(e);return}we(),Lt({kind:"processing",checkoutNumber:e.checkoutNumber})}}async function ct(){const e=JSON.stringify([Je.trim(),L,H,G.trim(),Te,q,E,T,p]);if(!(!ue||!St||Xe!=="new"||Ot.current===e))try{await he.createAddress({label:Je.trim()||"Home",contact_name:`${L} ${H}`.trim(),phone:G.trim(),address:Te,city:q,zip_code:T,state:E,country:p}),Ot.current=e,vt("Address saved to your account.")}catch{vt("We couldn't save the address to your account — you can add it under Account → Addresses.")}}async function nn(e,t=P,o=!1,c=$){A(null);try{if(t==="card"&&r.paymentMethods.includes("card")){const n=await C.createPaymentIntent({idempotencyKey:c});Z.current=n;let i=e;if(o){const l=await a.current.placedRequest?.send().catch(()=>null);if(l?.orderNumber){K("card"),await Y(l,e);return}i=rn(e,l)??{...e,expiresAt:null}}K("card"),X(i),Ve(!1),Me(n)}else if(t==="paypal"&&r.paymentMethods.includes("paypal"))X(e),Un(!0);else if(t==="afterpay"&&r.paymentMethods.includes("afterpay")){const n=window.location.origin,i=await C.createAfterpayCheckout({idempotencyKey:c,confirmUrl:`${n}/checkout?afterpay=confirm`,cancelUrl:`${n}/checkout?afterpay=cancel`});de(Mr,c,e,i.redirectCheckoutUrl);return}else if(t==="square"&&r.paymentMethods.includes("square"))X(e),Bn(!0);else if(t==="gocardless"&&r.paymentMethods.includes("gocardless")){const n=window.location.origin,i=await C.createGocardlessBillingRequest({idempotencyKey:c,confirmUrl:`${n}/checkout?gocardless=confirm`,cancelUrl:`${n}/checkout?gocardless=cancel`});de(Lr,c,e,i.authorisationUrl);return}else if(t==="zip"&&r.paymentMethods.includes("zip")){const n=window.location.origin,i=await C.createZipCheckout({idempotencyKey:c,redirectUrl:`${n}/checkout?zip=return`});de($r,c,e,i.redirectUrl);return}else if(t==="klarna"&&r.paymentMethods.includes("klarna")){const n=window.location.origin,i=await C.createKlarnaCheckout({idempotencyKey:c,confirmUrl:`${n}/checkout?klarna=confirm`,cancelUrl:`${n}/checkout?klarna=cancel`});de(_r,c,e,i.redirectUrl);return}else if(t==="worldpay"&&r.paymentMethods.includes("worldpay")){const n=window.location.origin,i=await C.createWorldpayCheckout({idempotencyKey:c,successUrl:`${n}/checkout?worldpay=return`,cancelUrl:`${n}/checkout?worldpay=cancel`});de(Fr,c,e,i.redirectUrl);return}else K(t),z(e)}catch(n){if((o||t==="card")&&n instanceof Ue&&n.status===409){K(t),await Y(void 0,e);return}on(e,n)}}function rn(e,t){return t&&!t.orderNumber&&t.status==="open"&&t.checkoutNumber===e.checkoutNumber?t:null}function on(e,t){S(kn(e,t)),!e.orderNumber&&it(t)?(I.current=!1,Ke(Be())):A(e)}async function gr(e){if(!_)return;const t=_;try{const o=await C.createPaymentIntent({idempotencyKey:$}),c=await a.current.placedRequest?.send().catch(()=>null);if(c?.orderNumber){await Y(c);return}const n=rn(t,c);X(n??{...t,expiresAt:null}),Ve(e&&n!==null),Z.current=o,Me(o)}catch(o){if(o instanceof Ue&&o.status===409){await Y();return}Me(null),X(null),on(t,o)}}function kr(){_&&(I.current=!0,A(_),Me(null),X(null),Ve(!1))}return{site:r,logo:k,signInHref:g,capitalised:Nr(Nn)==="capitalised",items:f,totals:pr,coupon:M,deliveryOptions:pt,courierUnavailable:Ln,retryCourier:Tn,shippingMethodId:Q,setShippingMethodId:ft,pickupLocation:Rn,servedCountries:ee,formatMoney:En,payChoice:P,setPayChoice:Pe,placing:x,email:F,setEmail:be,firstName:L,setFirstName:Ne,lastName:H,setLastName:Se,company:Ae,setCompany:Ge,address1:te,setAddress1:ne,address2:ve,setAddress2:re,city:q,setCity:oe,postcode:T,setPostcode:se,phone:G,setPhone:ce,country:p,setCountry:ae,subdivision:E,setSubdivision:Oe,subdivisions:ie,destination:wt,postcodeLabel:Mn,subdivisionLabel:xn,me:ue,savedAddresses:_n,selectedAddressId:Xe,setSelectedAddressId:Ee,saveAddress:St,setSaveAddress:At,saveLabel:Je,setSaveLabel:In,addressSaveNote:Fn,lostChangeNote:qn,idemKey:$,confirmation:je,setConfirmation:z,orderError:$n,payment:Rt,paypalStep:Et,squareStep:Kt,pendingConf:_,paid:Yn,setPaid:xe,unpaidOrder:w,orderLocked:Mt,formLocked:Dn,restoredPrices:Dt,basketRead:Sn,quoteFailed:st,retryQuote:fr,payNote:Hn,afterpayConfirming:Wn,gocardlessConfirming:Xn,zipConfirming:Zn,klarnaConfirming:Vn,worldpayConfirming:er,cardConfirming:xt,checkoutResult:le,confirmCardPayment:Y,cardStillProcessing:tn,renewCardPayment:gr,holdRenewed:rr,leaveCardPayment:kr,checkoutRootRef:It,setCheckoutHeaderEl:or,fillFromAddress:Ft,checkoutSignOut:sr,payOptions:J,noPaymentMethod:cr,placeOrder:yr}}const bn=Cr(null);function xo({children:r,...k}){const g=io(k);return O(bn.Provider,{value:g,children:r})}function Lo(){const r=wr(bn);if(!r)throw new Error("useCheckout must be used inside CheckoutStateProvider");return r}export{xo as CheckoutStateProvider,Eo as NO_PAYMENT_METHOD_NOTE,Ko as SHIPPING_RETRY_NOTE,gn as buildPayOptions,kn as paymentNotStartedMessage,Mo as placedOrderLockNote,Lo as useCheckout};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as p,Fragment as le,jsxs as $}from"react/jsx-runtime";import{createContext as Ne,useCallback as ue,useContext as $e,useEffect as h,useRef as g,useState as d}from"react";import{VIEW_TABLET_MIN as Re}from"efficient-easel/screen/lib/content/view-tiers";import{cssStringBody as Oe}from"efficient-web-builder/format/lib/document/style-text";import{HALF_SIZES as R,sizedImage as Ce}from"efficient-web-builder/format/lib/sized-image";import{prefersReducedMotion as z}from"efficient-web-builder/render/components/useReducedMotion";import{STAGE_PHOTO_BOX as He}from"../../lib/sections/hero-gallery.js";import{DEFAULT_SPIN_AUTO_TURN as We,DEFAULT_SPIN_HINT as Ue,SPIN_RESUME_MS as je,isFullTurn as de,spinAutoTurnStep as Xe,spinBlend as ze,spinClampPosition as Be,spinFrameIndex as O,spinPositionAfterDrag as fe,spinCell as B,spinStartPosition as q}from"../../lib/sections/spin-sets.js";const qe=.3,Ge=.85,me=24,pe=4,he=1e3,ge=77/72,we=`${(1-ge)/2*100}%`,be=`${ge*100}%`,G={left:we,top:we,width:be,height:be},Ke=`(max-width: ${Re-.02}px)`,K=new Map,ve=new Map;function Z(t,y){let w=K.get(t);return w||(w=new Promise(M=>{const l=new Image,F=()=>{K.delete(t),ve.delete(t),M(null)},S=()=>M({w:l.naturalWidth,h:l.naturalHeight});l.onload=()=>{if(typeof l.decode!="function")return S();l.decode().then(S,F)},l.onerror=F,y&&(l.sizes=R,l.srcset=y),l.src=t,ve.set(t,l)}),K.set(t,w)),w}const Ze=Ne({autoTurn:We,turnHint:Ue}),Qe="M3 4.5c3.2 3.6 18.8 3.6 22 0M5.6 2.6 3 4.5l3 1.2M22.4 2.6 25 4.5l-3 1.2",L=t=>Ce(t,{fallbackWidth:he,maxWidth:he}),ye=(t,y)=>!!t.frames&&y===t.frames[0],Se=t=>({...G,backgroundImage:`url("${Oe(t.url)}")`,backgroundSize:`${t.cols*100}% ${t.rows*100}%`,backgroundPosition:`${t.cols>1?t.col*100/(t.cols-1):0}% ${t.rows>1?t.row*100/(t.rows-1):0}%`});function Ve({set:t,name:y,poster:w}){const[M,l]=d(null),F=g(null),[S,Q]=d(()=>q(t)),T=g(null),C=g(0),b=g(S),D=g(null),E=g(null),{autoTurn:f,turnHint:Ee}=$e(Ze),[ke,V]=d(!1),[xe,Y]=d(!1),[H,J]=d(0),ee=g(0),[Ae,te]=d(!1),[Pe,Fe]=d(!0),[ne,_e]=d(null),a=t.count,[W,re]=d(null),U=g(null),[k,oe]=d(null),v=de(t),x=O(S,a,v),_=t.frames?t.frames[x]:t.startFrame??"";h(()=>{const e=F.current;e?.complete&&e.naturalWidth>0&&l(_)},[_]);const I=ue(e=>{const n=Be(e,a,v);return b.current=n,Q(n),n},[a,v]),N=ue(()=>cancelAnimationFrame(C.current),[]);h(()=>{const e=window.matchMedia?.(Ke);if(!e)return oe(!1);const n=()=>oe(e.matches);return n(),e.addEventListener?.("change",n),()=>e.removeEventListener?.("change",n)},[]),h(()=>{if(!t.sheets||!t.startFrame||k===null)return;const e=k?t.sheets.phone:t.sheets.desktop,n=`${t.startFrame} ${e.urls[0]}`;if(E.current===n)return;E.current=n,re({key:n,sheet:e,ready:new Set});const r=Math.floor(q(t)/(e.cols*e.rows)),u=e.urls.map((c,o)=>e.urls[(r+o)%e.urls.length]),i=L(t.startFrame);Z(i.src,i.srcSet).then(()=>{for(const c of u)Z(c).then(o=>{!o||o.w!==e.cols*e.frame||o.h!==e.rows*e.frame||E.current===n&&re(m=>m?.key===n?{...m,ready:new Set(m.ready).add(c)}:m)})})},[t,k]),h(()=>{if(!t.frames)return;const e=t.frames,n=e[0];if(E.current===n)return;E.current=n;const r=O(q(t),a,de(t)),u=[];for(let c=0;c<pe;c+=1)for(let o=c;o<a;o+=pe)u.push((r+o)%a);const i=c=>{const o=L(e[c]);return Z(o.src,o.srcSet)};i(u[0]).then(()=>Promise.all(u.slice(1).map(i))).then(c=>{E.current===n&&c.every(Boolean)&&_e(n)})},[a,t]),h(()=>N,[N]),h(()=>{const e=T.current;if(!f||!e)return;if(typeof IntersectionObserver>"u")return te(!0);const n=new IntersectionObserver(r=>te(r.some(u=>u.isIntersecting)));return n.observe(e),()=>n.disconnect()},[f]),h(()=>{if(!f)return;const e=()=>Fe(document.visibilityState!=="hidden");return e(),document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[f]);const Ie=e=>{N(),f&&Y(!0),V(!0),e.currentTarget.setPointerCapture?.(e.pointerId),D.current={x0:e.clientX,f0:b.current,last:e.clientX,speed:0}},Le=e=>{const n=D.current,r=T.current;!n||!r||(n.speed=e.clientX-n.last,n.last=e.clientX,I(fe(n.f0,e.clientX-n.x0,r.clientWidth,a)))},se=()=>{const e=D.current;D.current=null,V(!1),f&&e&&(Y(!1),J(i=>i+1));const n=T.current;if(!e||!n||z())return;let r=Math.max(-me,Math.min(me,e.speed));const u=()=>{if(Math.abs(r)<qe)return;const i=fe(b.current,r,n.clientWidth,a);I(i)===i&&(r*=Ge,C.current=requestAnimationFrame(u))};C.current=requestAnimationFrame(u)},Me=e=>{const n=e.key==="ArrowRight"||e.key==="ArrowUp"?1:e.key==="ArrowLeft"||e.key==="ArrowDown"?-1:0;if(e.key==="Home")I(0);else if(e.key==="End")I(a-1);else if(n)I(Math.round(b.current)+n);else return;N(),f&&J(r=>r+1),e.preventDefault()},s=t.sheets&&W&&W.key.startsWith(`${t.startFrame} `)?W:null;s&&s.ready.has(B(s.sheet,x).url)&&(U.current={key:s.key,frame:x});const j=s&&U.current?.key===s.key?U.current.frame:null,A=s&&j!==null?{...B(s.sheet,j),cols:s.sheet.cols,rows:s.sheet.rows}:null,P=ze(S,a,v,z()),X=s&&P.b!==null&&j===x?B(s.sheet,P.b):null,ae=A&&X&&s.ready.has(X.url)?{...X,cols:A.cols,rows:A.rows}:null,ie=!s&&t.frames&&P.b!==null&&ye(t,ne)?t.frames[P.b]:null,Te=t.frames?ye(t,ne):!!s&&s.ready.size===s.sheet.urls.length,ce=f&&Te&&Ae&&Pe&&!xe;return h(()=>{if(!ce)return;const e=ee.current!==H;let n=-1,r=-1,u=1,i=0;const c=o=>{if(i=requestAnimationFrame(c),n<0&&(n=o),e&&o-n<je)return;if(ee.current=H,r<0){r=o;return}const m=Xe(t,b.current,u,o-r);r=o,u=m.way;const De=O(b.current,a,v);b.current=m.position,(!z()||O(m.position,a,v)!==De)&&Q(m.position)};return i=requestAnimationFrame(c),()=>cancelAnimationFrame(i)},[ce,H,t,a,v]),$("div",{ref:T,"data-spin-well":!0,role:"slider",tabIndex:0,"aria-label":`${y}, 360° view: drag or use the arrow keys to turn`,"aria-valuemin":1,"aria-valuemax":a,"aria-valuenow":x+1,"aria-valuetext":`Angle ${x+1} of ${a}`,"data-spin-auto-turn":f?"":void 0,onKeyDown:Me,className:"absolute inset-0 select-none overflow-hidden cursor-grab active:cursor-grabbing focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-fg",style:{touchAction:"pan-y"},onPointerDown:Ie,onPointerMove:Le,onPointerUp:se,onPointerCancel:se,onTouchStart:e=>e.stopPropagation(),onTouchMove:e=>e.stopPropagation(),onTouchEnd:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:[p("div",{"data-spin-frames":!0,className:"pointer-events-none absolute inset-0",children:A?$(le,{children:[p("div",{"data-spin-frame":!0,className:"pointer-events-none absolute",style:Se(A)}),ae?p("div",{"data-spin-frame":!0,className:"pointer-events-none absolute",style:{...Se(ae),opacity:P.mix}}):null]}):$(le,{children:[p("img",{...L(_),ref:F,onLoad:()=>l(_),sizes:R,alt:"",draggable:!1,fetchPriority:"high","data-spin-frame":!0,className:"pointer-events-none absolute max-w-none object-contain",style:G}),ie?p("img",{...L(ie),sizes:R,alt:"",draggable:!1,"data-spin-frame":!0,className:"pointer-events-none absolute max-w-none object-contain",style:{...G,opacity:P.mix}}):null]})}),w&&!A&&M!==_?p("img",{...L(w),sizes:R,alt:"",draggable:!1,"data-spin-poster":!0,className:`pointer-events-none absolute inset-[6%] ${He} object-contain`}):null,Ee&&!ke?$("span",{"data-spin-hint":!0,className:`pointer-events-none absolute inset-x-0 flex flex-col items-center gap-1 text-xs text-fg ${k?"bottom-3":"bottom-5"}`,children:[k?null:p("svg",{viewBox:"0 0 28 12",width:"28",height:"12","aria-hidden":"true",children:p("path",{d:Qe,fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),k?"Swipe to turn":"Drag to turn"]}):null]})}export{Ze as SpinChoices,Ve as default};
|
|
@@ -21,8 +21,6 @@ export type SpinSets = Record<string, Record<string, SpinSet>>;
|
|
|
21
21
|
export declare const DEFAULT_SPIN_AUTO_TURN = false;
|
|
22
22
|
export declare const DEFAULT_SPIN_HINT = false;
|
|
23
23
|
export declare function parseSpinSwitch(v: unknown): boolean;
|
|
24
|
-
export declare const SPIN_HINT_SHOW_MS = 1000;
|
|
25
|
-
export declare const SPIN_HINT_HIDE_MS = 6000;
|
|
26
24
|
export declare const SPIN_TURN_MS = 14000;
|
|
27
25
|
export declare const SPIN_RESUME_MS = 5000;
|
|
28
26
|
export declare const DEFAULT_SPIN_AUTO_ARC = 160;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolveMedia as m}from"efficient-web-builder/render/lib/media";const
|
|
1
|
+
import{resolveMedia as m}from"efficient-web-builder/render/lib/media";const h=4096,c=360,y=.9,E=!1,U=!1;function F(n){return n===!0}const S=14e3,M=1e-6,j=5e3,g=160;function R(n,t,r,e){const o=n.autoArc??g;if(a(n)&&o<c)return d(n.count,o,t,r,e*n.count/S);const i=a(n)?c:n.arc,s=t+r*e*n.count*c/(S*i);if(a(n))return{position:(s%n.count+n.count)%n.count,way:r};const u=n.count-M;return s>=u?{position:u,way:-1}:s<=0?{position:0,way:1}:{position:s,way:r}}const _=n=>Array.isArray(n)&&n.length>0&&n.every(t=>typeof t=="string"&&t.length>0),x=n=>m(n)??n,p=n=>Number.isInteger(n)&&n>0;function A(n,t){if(!n||typeof n!="object")return null;const{frame:r,cols:e,rows:o,urls:i}=n;return!p(r)||!p(e)||!p(o)||!_(i)||r*e>h||r*o>h||i.length!==Math.ceil(t/(e*o))?null:{frame:r,cols:e,rows:o,urls:i.map(x)}}function T(n){const{frames:t,count:r,startFrame:e,sheets:o}=n,i=_(t)?{count:t.length,frames:t.map(x)}:null;if(o&&typeof o=="object"&&p(r)&&typeof e=="string"&&e){const s=A(o.desktop,r),u=A(o.phone,r);if(s&&u)return{count:r,startFrame:x(e),sheets:{desktop:s,phone:u}}}return i}function b(n){if(!n||typeof n!="object")return null;const{arc:t,start:r}=n,e=T(n);if(!e)return null;if(t!==void 0){if(typeof t!="number"||!(t>0&&t<=c))return null;e.arc=t}const{autoArc:o}=n;return typeof o=="number"&&o>0&&o<=c&&(e.autoArc=o),Number.isInteger(r)&&r>=0&&r<e.count&&(e.start=r),e}function L(n){if(!n||typeof n!="object"||Array.isArray(n))return{};const t={};for(const[r,e]of Object.entries(n)){if(!e||typeof e!="object"||Array.isArray(e))continue;const o={};for(const[i,s]of Object.entries(e)){const u=b(s);u&&(o[i]=u)}Object.keys(o).length>0&&(t[r]=o)}return t}function k(n,t,r){return r?n[t]?.[r]??null:null}function w(n,t){const r=Object.keys(n?.[t]??{});return r.length>0?{finish:r}:null}function a(n){return n.arc===void 0||n.arc>=c}function d(n,t,r,e,o){const i=n*t/(2*c),s=(r%n+n)%n,u=s>n/2?s-n:s;let f=u>i?-1:u<-i?1:e,l=u+f*o;return f===1&&u<=i&&l>=i?[l,f]=[i,-1]:f===-1&&u>=-i&&l<=-i&&([l,f]=[-i,1]),{position:(l%n+n)%n,way:f}}function N(n){return a(n)?0:Math.floor(n.count/2)}function D(n){return n.start??N(n)}function I(n,t,r=!0){return r?(Math.floor(n)%t+t)%t:Math.max(0,Math.min(t-1,Math.floor(n)))}function O(n,t,r,e){const o=I(n,t,r),i=n-Math.floor(n),s=r?(o+1)%t:o+1<t?o+1:null;return e||i===0||s===null?{a:o,b:null,mix:0}:{a:o,b:s,mix:i}}function C(n,t,r){return r?n:Math.max(0,Math.min(t-1,n))}function H(n,t,r,e){return r<=0?n:n-t/r*e*y}function B(n,t){const r=n.cols*n.rows,e=t%r;return{url:n.urls[Math.floor(t/r)],col:e%n.cols,row:Math.floor(e/n.cols)}}export{g as DEFAULT_SPIN_AUTO_ARC,E as DEFAULT_SPIN_AUTO_TURN,U as DEFAULT_SPIN_HINT,j as SPIN_RESUME_MS,h as SPIN_SHEET_MAX_SIDE,S as SPIN_TURN_MS,a as isFullTurn,L as parseSpinSets,F as parseSpinSwitch,R as spinAutoTurnStep,O as spinBlend,B as spinCell,C as spinClampPosition,I as spinFrameIndex,H as spinPositionAfterDrag,w as spinPreference,k as spinSetFor,D as spinStartPosition};
|