@aifeatures/react 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";var Ue=Object.defineProperty;var bt=Object.getOwnPropertyDescriptor;var St=Object.getOwnPropertyNames;var vt=Object.prototype.hasOwnProperty;var kt=(e,t)=>{for(var r in t)Ue(e,r,{get:t[r],enumerable:!0})},_t=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of St(t))!vt.call(e,i)&&i!==r&&Ue(e,i,{get:()=>t[i],enumerable:!(n=bt(t,i))||n.enumerable});return e};var wt=e=>_t(Ue({},"__esModule",{value:!0}),e);var Yt={};kt(Yt,{AddToCartButton:()=>mt,AifeaturesCaptcha:()=>Qe,BuyButton:()=>ft,CartCheckoutButton:()=>ht,MARKET_COUNTRIES:()=>Ae,MAX_CART_LINES:()=>Ke,OrderConfirmation:()=>Ct,ProductPrice:()=>ut,VariantPicker:()=>ct,ZERO_DECIMAL_CURRENCIES:()=>Me,applySelectionToUrl:()=>Re,formatPrice:()=>F,getOptions:()=>le,getVariants:()=>ne,isMultiVariant:()=>pe,isValueAvailable:()=>ke,isValueInCatalog:()=>_e,reanchorSelection:()=>we,resolveVariant:()=>ae,searchFromSelection:()=>Ce,selectedImages:()=>fe,selectedValues:()=>Ne,selectionFromSearch:()=>xe,useCart:()=>ee,useCartCheckout:()=>Ee,useCartItems:()=>Le,useCartSummary:()=>it,useCheckout:()=>Oe,useMarket:()=>st,useProduct:()=>oe,valueSlug:()=>Z,variantPriceRange:()=>Pe});module.exports=wt(Yt);var he=require("react"),Ge=require("@marsidev/react-turnstile"),Ve=require("react/jsx-runtime");function Qe({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:i}){let[o,g]=(0,he.useState)(null),[p,y]=(0,he.useState)(!0);return(0,he.useEffect)(()=>{y(!0),fetch(`${t}/f/${e}/config`).then(l=>l.json()).then(l=>{g(l.turnstile_sitekey),y(!1)}).catch(()=>{y(!1)})},[e,t]),p||!o?null:(0,Ve.jsx)("div",{className:i,children:(0,Ve.jsx)(Ge.Turnstile,{siteKey:o,onSuccess:r,onError:n,onExpire:n,options:{theme:"light"}})})}var Q=require("react"),Se=[1e3,3e3];function oe(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[i,o]=(0,Q.useState)(null),[g,p]=(0,Q.useState)(!0),[y,l]=(0,Q.useState)(null),[f,a]=(0,Q.useState)(0),h=(0,Q.useRef)(e);(0,Q.useEffect)(()=>{let c=!1,v;p(!0),l(null),h.current!==e&&(h.current=e,o(null));let w=I=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async S=>{let O=await S.json().catch(()=>null);if(!c)if(!S.ok||!O){if(S.status>=500&&I<Se.length){v=setTimeout(()=>w(I+1),Se[I]);return}l(O?.error??`Request failed (${S.status})`),o(null),p(!1)}else o(O),p(!1)}).catch(S=>{if(!c){if(I<Se.length){v=setTimeout(()=>w(I+1),Se[I]);return}l(S instanceof Error?S.message:"Failed to load product"),p(!1)}})};return w(0),()=>{c=!0,v&&clearTimeout(v)}},[e,r,n,f]);let m=(0,Q.useCallback)(()=>a(c=>c+1),[]);return{product:i,loading:g,error:y,refresh:m}}var Me=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function F(e,t,r){let n=Me.has(t.toLowerCase())?e:e/100;try{return new Intl.NumberFormat(r,{style:"currency",currency:t.toUpperCase()}).format(n)}catch{return`${n} ${t.toUpperCase()}`}}function ne(e){return e.variants??[]}function le(e){return e.options??[]}function pe(e){return le(e).length>0}function ve(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function ae(e,t){let r=Object.keys(t);return e.find(n=>{let i=n.option_values;return i.length!==r.length?!1:i.every(o=>t[o.option_id]===o.value_id)})??null}function ke(e,t,r,n){return e.some(i=>{let o=ve(i);if(o[r]!==n)return!1;for(let[g,p]of Object.entries(t))if(g!==r&&o[g]!==p)return!1;return!0})}function _e(e,t,r){return e.some(n=>ve(n)[t]===r)}function we(e,t,r,n){let i={[r]:n};for(let[g,p]of Object.entries(t)){if(g===r)continue;e.some(l=>{let f=ve(l);return f[r]===n&&f[g]===p})&&(i[g]=p)}return e.some(g=>{let p=ve(g);return Object.entries(i).every(([y,l])=>p[y]===l)})?i:{[r]:n}}function Pe(e){let t=e.map(r=>r.unit_amount).filter(r=>r!==null);return t.length===0?null:{min:Math.min(...t),max:Math.max(...t)}}function Ne(e,t){let r={};for(let n of le(e)){let i=t[n.id];if(!i)continue;let o=n.values.find(g=>g.id===i);o&&(r[n.title]=o.value)}return r}function Z(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function xe(e,t){let r=t instanceof URLSearchParams?t:new URLSearchParams(t),n=new Map;r.forEach((o,g)=>{n.has(Z(g))||n.set(Z(g),o)});let i={};for(let o of le(e)){let g=Z(o.title);if(g.length===0)continue;let p=n.get(g);if(p===void 0)continue;let y=Z(p);if(y.length===0)continue;let l=o.values.find(f=>Z(f.value)===y);l&&(i[o.id]=l.id)}return i}function Ce(e,t){let r={};for(let[n,i]of Object.entries(Ne(e,t))){let o=Z(n),g=Z(i);o.length===0||g.length===0||(r[o]=g)}return r}function fe(e,t){let r=[];for(let n of le(e)){let i=t[n.id];if(!i)continue;let o=n.values.find(g=>g.id===i);o?.images?.length&&r.push(...o.images)}return r.length>0?r:e.images??[]}function Re(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of le(e)){let i=Z(n.title);i.length!==0&&r.searchParams.delete(i)}for(let[n,i]of Object.entries(Ce(e,t)))r.searchParams.set(n,i);window.history.replaceState(window.history.state,"",r.toString())}var Y=require("react");var Be="aifeatures_cart",De="aifeatures_market",Ze="aifeatures_cart_cleared";var qe="aifeatures:cart-storage",be=new Map;function $e(e){if(be.has(e))return be.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Fe(e,t){if(typeof window>"u"){be.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),be.delete(e)}catch{be.set(e,t)}Pt(e)}function Pt(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(qe,{detail:{key:e}}))}catch{}}function He(e,t){if(typeof window>"u")return()=>{};let r=i=>{(i.key===e||i.key===null)&&t()},n=i=>{i.detail?.key===e&&t()};return window.addEventListener("storage",r),window.addEventListener(qe,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(qe,n)}}function xt(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.productId!="string"||t.productId.length===0||typeof t.variantId!="string"||t.variantId.length===0)return null;let r=typeof t.quantity=="number"&&Number.isFinite(t.quantity)?Math.max(1,Math.floor(t.quantity)):1,n={};if(typeof t.selection=="object"&&t.selection!==null)for(let[g,p]of Object.entries(t.selection))typeof p=="string"&&(n[g]=p);let i=typeof t.display=="object"&&t.display!==null?t.display:{},o={name:typeof i.name=="string"?i.name:"",variantTitle:typeof i.variantTitle=="string"?i.variantTitle:null,image:typeof i.image=="string"?i.image:null};return{productId:t.productId,variantId:t.variantId,quantity:r,selection:n,display:o}}function se(){let e=$e(Be);if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let r=[],n=new Set;for(let i of t){let o=xt(i);o&&!n.has(o.variantId)&&(n.add(o.variantId),r.push(o))}return r}function H(e){Fe(Be,JSON.stringify(e))}function Xe(e){return He(Be,e)}function et(e){let t=new Map;for(let n of e)!n.variantId||!(n.quantity>0)||t.set(n.variantId,(t.get(n.variantId)??0)+n.quantity);if(t.size===0)return;let r=[];for(let n of se()){let i=t.get(n.variantId);if(i===void 0){r.push(n);continue}let o=n.quantity-i;o>0&&r.push({...n,quantity:o})}H(r)}function j(){let e=$e(De);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function tt(e){Fe(De,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function me(e){return He(De,e)}function nt(e){let t=[],r=$e(Ze);if(r)try{let i=JSON.parse(r);Array.isArray(i)&&(t=i.filter(o=>typeof o=="object"&&o!==null&&typeof o.id=="string"&&typeof o.ts=="number"))}catch{}let n=Date.now()-6048e5;return t=t.filter(i=>i.ts>n),t.some(i=>i.id===e)?!1:(t.push({id:e,ts:Date.now()}),t.length>200&&(t=t.slice(-200)),Fe(Ze,JSON.stringify(t)),!0)}var Rt=1500;function je(){try{if(typeof crypto<"u"&&"randomUUID"in crypto)return crypto.randomUUID()}catch{}return`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`}function Ie(e,t){return!("requestId"in e)||e.requestId===t}function ze(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,i=p=>{n||(n=!0,window.removeEventListener("message",o),clearTimeout(g),r(p))},o=p=>{if(p.source!==window.parent)return;let y=p.data;y?.type==="aifeatures:test-checkout-ack"&&Ie(y,t)&&i(y.status==="accepted")},g=setTimeout(()=>i(!1),Rt);window.addEventListener("message",o);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{i(!1)}})}function Oe(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(null),[g,p]=(0,Y.useState)(null),y=(0,Y.useRef)(!1),l=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{let a=h=>{h.persisted&&(y.current=!1,n(!1))};return window.addEventListener("pageshow",a),()=>window.removeEventListener("pageshow",a)},[]),(0,Y.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let a=h=>{if(h.source!==window.parent)return;let m=h.data;if(m?.type!=="aifeatures:test-checkout-ack"||m.status!=="failed")return;let c=l.current;c===null||!Ie(m,c)||(l.current=null,o(typeof m.error=="string"&&m.error?m.error:"The test purchase could not be created."),y.current=!1,n(!1))};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[]),{startCheckout:(0,Y.useCallback)(async({productId:a,variantId:h,quantity:m,amount:c,metadata:v,successUrl:w,cancelUrl:I,customerEmail:S,expectedUnitAmount:O,expectedCurrency:b})=>{if(!y.current){y.current=!0,n(!0),o(null),p(null);try{let s=j(),u=await fetch(`${t}/v1/p/${a}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...h!==void 0?{variant_id:h}:{},...m!==void 0?{quantity:m}:{},...c!==void 0?{amount:c}:{},...v!==void 0?{metadata:v}:{},...S!==void 0?{customer_email:S}:{},...O!==void 0&&b!==void 0?{expected_unit_amount:O,expected_currency:b}:{},...s!==null?{country:s}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:I??window.location.href})}),d=await u.json().catch(()=>null);if(!u.ok){if(d?.error==="price_changed"&&typeof d.current_unit_amount=="number"&&typeof d.currency=="string"){p({currentUnitAmount:d.current_unit_amount,currency:d.currency}),o(`The price has changed to ${F(d.current_unit_amount,d.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(d?.code==="preview_domain"){let C=je();if(l.current=C,await ze({productId:a,...h!==void 0?{variantId:h}:{},...m!==void 0?{quantity:m}:{},...c!==void 0?{amount:c}:{},...S!==void 0?{customerEmail:S}:{}},C))return;l.current=null}o(d?.error??`Checkout failed (${u.status})`),y.current=!1,n(!1);return}if(!d?.url){o("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=d.url;return}catch{if(window.open(d.url,"_blank")){y.current=!1,n(!1);return}}window.location.href=d.url}catch(s){o(s instanceof Error?s.message:"Checkout failed"),y.current=!1,n(!1)}}},[t]),loading:r,error:i,priceChange:g}}var X=require("react");var Ke=20;function rt(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function ee(){let[e,t]=(0,X.useState)([]),[r,n]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let l=()=>t(se());return l(),n(!0),Xe(l)},[]);let i=(0,X.useCallback)(l=>{let f=se(),a=rt(l.quantity);return f.find(m=>m.variantId===l.variantId)?(H(f.map(m=>m.variantId===l.variantId?{...m,quantity:m.quantity+a,selection:l.selection??m.selection,display:l.display}:m)),{ok:!0}):f.length>=Ke?{ok:!1,reason:"cart_full"}:(H([...f,{productId:l.productId,variantId:l.variantId,quantity:a,selection:l.selection??{},display:l.display}]),{ok:!0})},[]),o=(0,X.useCallback)(l=>{H(se().filter(f=>f.variantId!==l))},[]),g=(0,X.useCallback)((l,f)=>{let a=se();if(f<=0){H(a.filter(m=>m.variantId!==l));return}let h=rt(f);H(a.map(m=>m.variantId===l?{...m,quantity:h}:m))},[]),p=(0,X.useCallback)(()=>{H([])},[]),y=e.reduce((l,f)=>l+f.quantity,0);return{items:e,count:y,hydrated:r,add:i,remove:o,setQuantity:g,clear:p}}var M=require("react");var Te={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},It={...Te,inStock:!0,status:"error"};function Ot(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Le(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=ee(),[i,o]=(0,M.useState)({}),[g,p]=(0,M.useState)({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,l]=(0,M.useState)(!0),[f,a]=(0,M.useState)(null),[h,m]=(0,M.useState)(0),c=(0,M.useRef)(new Set),v=(0,M.useMemo)(()=>JSON.stringify(r.map(b=>[b.productId,b.variantId,b.selection])),[r]),w=(0,M.useCallback)(()=>m(b=>b+1),[]);(0,M.useEffect)(()=>me(w),[w]),(0,M.useEffect)(()=>{if(!n)return;if(r.length===0){o({}),p({shippingRates:null,freeShippingOver:null,shippingCountries:null}),a(null),l(!1);return}let b=!1;l(!0);let s=r,u=[...new Set(s.map(C=>C.productId))],d=async C=>{let R=new Map;return await Promise.all(u.map(async T=>{try{let P=await fetch(`${t}/v1/p/${encodeURIComponent(T)}${C?`?country=${encodeURIComponent(C)}`:""}`);if(P.status===404){R.set(T,{kind:"not_found"});return}if(!P.ok){R.set(T,{kind:"error",message:`Request failed (${P.status})`});return}let x=await P.json();R.set(T,{kind:"ok",product:x})}catch(P){R.set(T,{kind:"error",message:P instanceof Error?P.message:"Failed to load product"})}})),R};return(async()=>{let C=j(),R=await d(C);if(C){let k=[...R.values()].filter(A=>A.kind==="ok"),L=k.filter(A=>A.product.base_currency);L.length>0&&L.length<k.length&&(R=await d(null))}if(b)return;let T=null,P=null,x=null;for(let k of u){let L=R.get(k);!L||L.kind!=="ok"||(T===null&&L.product.shipping_rates&&(T=L.product.shipping_rates),P===null&&L.product.free_shipping_over!=null&&(P=L.product.free_shipping_over),x===null&&L.product.shipping_countries&&(x=L.product.shipping_countries))}let E={},B=new Map,ue=null;for(let k of s){let L=R.get(k.productId);if(!L||L.kind==="error"){E[k.variantId]=It,L&&ue===null&&(ue=L.message);continue}if(L.kind==="not_found"){E[k.variantId]=Te;continue}let{product:A}=L;if(!A.active||A.purchasable===!1){E[k.variantId]=Te;continue}let K=A.variants??[],G=K.find(ie=>ie.id===k.variantId)??null,W=k.variantId;if(!G){let ie=ae(K,k.selection);if(!ie){E[k.variantId]=Te;continue}let Je=B.get(k.variantId)??{};Je.reanchorTo={variantId:ie.id,selection:Ot(ie)},B.set(k.variantId,Je),c.current.add(ie.id),G=ie,W=ie.id}let D=fe(A,k.selection)[0]??null,ye={image:D,unitAmount:G.unit_amount,currency:G.currency,baseCurrency:A.base_currency??null,inStock:G.in_stock,available:G.available,maxQuantity:A.max_quantity,pdpSearch:Ce(A,k.selection),status:c.current.has(W)?"reanchored":"ok"};E[k.variantId]=ye,E[W]=ye;let Ye=B.get(k.variantId)??{};Ye.display={name:A.name,variantTitle:G.title,image:D},B.set(k.variantId,Ye)}let $=new Set(s.map(k=>k.variantId));for(let k of[...c.current])!$.has(k)&&!(k in E)&&c.current.delete(k);if(B.size>0){let k=se(),L=[],A=new Map,K=!1;for(let G of k){let W=B.get(G.variantId),D={...G};W?.reanchorTo&&(D.variantId=W.reanchorTo.variantId,D.selection=W.reanchorTo.selection,K=!0),W?.display&&(D.display.name!==W.display.name||D.display.variantTitle!==W.display.variantTitle||D.display.image!==W.display.image)&&(D.display=W.display,K=!0);let ye=A.get(D.variantId);if(ye){ye.quantity+=D.quantity,K=!0;continue}L.push(D),A.set(D.variantId,D)}K&&H(L)}b||(o(E),p({shippingRates:T,freeShippingOver:P,shippingCountries:x}),a(ue),l(!1))})(),()=>{b=!0}},[n,v,t,h]);let I=(0,M.useMemo)(()=>r.map(b=>{let s=i[b.variantId];return s?{...b,...s,image:s.image??b.display.image}:{...b,image:b.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,i]),{subtotal:S,currency:O}=(0,M.useMemo)(()=>{let b=0,s=null;for(let u of I)u.unitAmount===null||u.currency===null||(b+=u.unitAmount*u.quantity,s=s??u.currency);return{subtotal:b,currency:s}},[I]);return{lines:I,subtotal:S,currency:O,shippingRates:g.shippingRates,freeShippingOver:g.freeShippingOver,shippingCountries:g.shippingCountries,loading:y,error:f,refresh:w}}var N=require("react");var Tt=2e3;function it(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:i,hydrated:o}=ee(),[g,p]=(0,N.useState)(null),[y,l]=(0,N.useState)(!1),[f,a]=(0,N.useState)(null),[h,m]=(0,N.useState)(null),[c,v]=(0,N.useState)(0);(0,N.useEffect)(()=>(m(j()),me(()=>m(j()))),[]);let w=(0,N.useMemo)(()=>i.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[i]),I=(0,N.useCallback)(()=>v(s=>s+1),[]),S=(0,N.useRef)(0),O=(0,N.useRef)(!1),b=(0,N.useRef)("idle");return(0,N.useEffect)(()=>{if(!o)return;if(i.length===0){p(null),a(null),l(!1);return}let s=++S.current,u=new AbortController,d=!1,C,R=O.current?r:0;O.current=!0,b.current=b.current==="pending"?"spent":"idle";let T=setTimeout(async()=>{l(!0);try{let P=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:u.signal,body:JSON.stringify({items:i.map(E=>({variant_id:E.variantId,quantity:E.quantity})),...h?{country:h}:{},...n?{shipping_option:n}:{}})});if(d||s!==S.current)return;if(!P.ok){if(P.status===429){let E=b.current==="idle";E&&(C=setTimeout(()=>{d||s!==S.current||(b.current="pending",v(B=>B+1))},Tt)),a(E?"Too many updates \u2014 retrying shortly":"Too many updates \u2014 the total will refresh on the next cart change")}else a(`Could not price this cart (${P.status})`);return}let x=await P.json();if(d||s!==S.current)return;p({currency:x.currency,subtotal:x.subtotal,shipping:x.shipping?{options:x.shipping.options.map(E=>({label:E.label,amount:E.amount,undiscountedAmount:E.undiscounted_amount})),selectedAmount:x.shipping.selected_amount,selectedLabel:x.shipping.selected_label,freeShippingOver:x.shipping.free_shipping_over,freeShippingCurrency:x.shipping.free_shipping_currency,thresholdMet:x.shipping.threshold_met,collectsAddress:x.shipping.collects_address}:null,total:x.total,totalIsFinal:x.total_is_final,tax:x.tax??null,unavailableVariantIds:x.unavailable_variant_ids}),a(null)}catch(P){if(d||u.signal.aborted||s!==S.current)return;a(P instanceof Error?P.message:"Could not price this cart")}finally{!d&&s===S.current&&l(!1)}},R);return()=>{d=!0,clearTimeout(T),C!==void 0&&clearTimeout(C),u.abort()}},[o,w,h,t,r,n,c]),{summary:g,loading:y,error:f,refresh:I}}var z=require("react");function Ee(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,z.useState)(!1),[i,o]=(0,z.useState)(null),[g,p]=(0,z.useState)(null),[y,l]=(0,z.useState)(null),f=(0,z.useRef)(!1),a=(0,z.useRef)(null);return(0,z.useEffect)(()=>{let m=c=>{c.persisted&&(f.current=!1,n(!1))};return window.addEventListener("pageshow",m),()=>window.removeEventListener("pageshow",m)},[]),(0,z.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let m=c=>{if(c.source!==window.parent)return;let v=c.data;if(v?.type!=="aifeatures:test-checkout-ack"||v.status!=="failed")return;let w=a.current;w===null||!Ie(v,w)||(a.current=null,o(typeof v.error=="string"&&v.error?v.error:"The test purchase could not be created."),f.current=!1,n(!1))};return window.addEventListener("message",m),()=>window.removeEventListener("message",m)},[]),{startCheckout:(0,z.useCallback)(async(m,{successUrl:c,cancelUrl:v,customerEmail:w,metadata:I,shippingOption:S}={})=>{if(!f.current){f.current=!0,n(!0),o(null),p(null),l(null);try{let O=j(),b=await fetch(`${t}/v1/p/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:m.map(u=>({variant_id:u.variantId,quantity:u.quantity,...typeof u.unitAmount=="number"&&typeof u.currency=="string"?{expected_unit_amount:u.unitAmount,expected_currency:u.currency}:{}})),...O!==null?{country:O}:{},...S?{shipping_option:S}:{},...I!==void 0?{metadata:I}:{},...w!==void 0?{customer_email:w}:{},success_url:c??`${window.location.origin}/order/confirmation`,cancel_url:v??window.location.href})}),s=await b.json().catch(()=>null);if(!b.ok){if(s?.code==="shipping_option_unavailable"&&typeof s.requested=="string"&&Array.isArray(s.available)){l({requested:s.requested,available:s.available,currency:typeof s.currency=="string"?s.currency:""}),f.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let u={};for(let d of s.items)d&&typeof d.variant_id=="string"&&(u[d.variant_id]=d);p(u),f.current=!1,n(!1);return}if(s?.code==="preview_domain"){let u=je();if(a.current=u,await ze({items:m.map(C=>({productId:C.productId,variantId:C.variantId,quantity:C.quantity})),...w!==void 0?{customerEmail:w}:{}},u))return;a.current=null}o(s?.error??`Checkout failed (${b.status})`),f.current=!1,n(!1);return}if(!s?.url){o("Checkout failed: no redirect URL returned"),f.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=s.url;return}catch{if(window.open(s.url,"_blank")){f.current=!1,n(!1);return}}window.location.href=s.url}catch(O){o(O instanceof Error?O.message:"Checkout failed"),f.current=!1,n(!1)}}},[t]),loading:r,error:i,conflicts:g,shippingConflict:y}}var re=require("react");var Ae=[{country:"US",currency:"usd"},{country:"GB",currency:"gbp"},{country:"CA",currency:"cad"},{country:"AU",currency:"aud"},{country:"NZ",currency:"nzd"},{country:"JP",currency:"jpy"},{country:"CH",currency:"chf"},{country:"SE",currency:"sek"},{country:"NO",currency:"nok"},{country:"DK",currency:"dkk"},{country:"PL",currency:"pln"},{country:"CZ",currency:"czk"},{country:"SG",currency:"sgd"},{country:"HK",currency:"hkd"},{country:"MX",currency:"mxn"},{country:"BR",currency:"brl"},{country:"IN",currency:"inr"},{country:"ZA",currency:"zar"},{country:"AE",currency:"aed"},{country:"IL",currency:"ils"},{country:"AT",currency:"eur"},{country:"BE",currency:"eur"},{country:"HR",currency:"eur"},{country:"CY",currency:"eur"},{country:"EE",currency:"eur"},{country:"FI",currency:"eur"},{country:"FR",currency:"eur"},{country:"DE",currency:"eur"},{country:"GR",currency:"eur"},{country:"IE",currency:"eur"},{country:"IT",currency:"eur"},{country:"LV",currency:"eur"},{country:"LT",currency:"eur"},{country:"LU",currency:"eur"},{country:"MT",currency:"eur"},{country:"NL",currency:"eur"},{country:"PT",currency:"eur"},{country:"SK",currency:"eur"},{country:"SI",currency:"eur"},{country:"ES",currency:"eur"}];function ot(e){return e?Ae.find(t=>t.country===e.toUpperCase())?.currency??null:null}var at=new Map;function Lt(e){let t=at.get(e);return t||(t=fetch(`${e}/v1/geo`).then(async r=>{if(!r.ok)return null;let n=await r.json().catch(()=>null);return typeof n?.country=="string"&&/^[A-Za-z]{2}$/.test(n.country)?n.country.toUpperCase():null}).catch(()=>null),at.set(e,t)),t}function st(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,re.useState)(null),[i,o]=(0,re.useState)(!1),[g,p]=(0,re.useState)(null);(0,re.useEffect)(()=>{let a=()=>n(j());return a(),o(!0),me(a)},[]),(0,re.useEffect)(()=>{let a=!1;return Lt(t).then(h=>{a||p(h)}),()=>{a=!0}},[t]);let y=(0,re.useCallback)(a=>{tt(a)},[]),l=ot(g),f=i&&l!==null&&l!==ot(r);return{market:r,suggestedCountry:g,setMarket:y,markets:Ae,shouldPrompt:f}}var ge=require("react/jsx-runtime"),Et={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function ut({productId:e,variantId:t,apiUrl:r,locale:n,className:i,style:o,compareAtClassName:g}){let{product:p,loading:y}=oe(e,{apiUrl:r});if(y||!p)return null;let l=ne(p),f=t!==void 0?l.find(h=>h.id===t)??null:p.options.length===0?l[0]??null:null;if(f){if(f.unit_amount===null)return null;let h=f.compare_at_amount!==null&&f.compare_at_amount>f.unit_amount;return(0,ge.jsxs)("span",{className:i,style:o,children:[h&&(0,ge.jsx)("span",{className:g,style:g?void 0:Et,children:F(f.compare_at_amount,f.currency,n)}),F(f.unit_amount,f.currency,n)]})}let a=Pe(l);return a?(0,ge.jsx)("span",{className:i,style:o,children:a.min===a.max?F(a.min,p.currency,n):`${F(a.min,p.currency,n)} \u2013 ${F(a.max,p.currency,n)}`}):p.unit_amount===null?null:(0,ge.jsx)("span",{className:i,style:o,children:F(p.unit_amount,p.currency,n)})}var te=require("react");var ce=require("react/jsx-runtime"),At={marginBottom:"0.75rem"},Ut={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},Vt={display:"flex",flexWrap:"wrap",gap:"0.5rem"},Mt={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},Nt={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},lt={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},qt={...lt,cursor:"pointer"};function ct({options:e,variants:t,value:r,syncUrl:n=!0,onChange:i,onVariantChange:o,className:g,style:p,optionClassName:y,optionLabelClassName:l,valueClassName:f,selectedValueClassName:a,unavailableValueClassName:h}){let m=r!==void 0,[c,v]=(0,te.useState)(r??{}),w=m?r:c,I=(0,te.useRef)(!1);(0,te.useEffect)(()=>{if(!n||m||I.current||e.length===0||typeof window>"u"||(I.current=!0,Object.keys(c).length>0))return;let s=xe({options:e},window.location.search);Object.keys(s).length!==0&&(v(s),i?.(s))},[n,m,e]);let S=(0,te.useMemo)(()=>e.length>0?t.filter(s=>s.option_values.length===e.length):t,[t,e]),O=(0,te.useRef)(void 0);if((0,te.useEffect)(()=>{let s=ae(S,w),u=s?.id??null;O.current!==u&&(O.current=u,o?.(s))},[S,w]),e.length===0)return null;let b=(s,u)=>{let d=we(S,w,s,u);m||(v(d),n&&Re({options:e},d)),i?.(d)};return(0,ce.jsx)("div",{className:g,style:p,children:e.map(s=>(0,ce.jsxs)("div",{className:y,style:y?void 0:At,children:[(0,ce.jsx)("span",{className:l,style:l?void 0:Ut,children:s.title}),(0,ce.jsx)("div",{style:Vt,children:s.values.map(u=>{let d=w[s.id]===u.id,C=ke(S,w,s.id,u.id),R=C||_e(S,s.id,u.id),T=[f,d?a:void 0,C?void 0:h].filter(Boolean).join(" ")||void 0,P=f?void 0:{...Mt,...d?Nt:{},...C?{}:R?qt:lt};return(0,ce.jsx)("button",{type:"button",className:T,style:P,disabled:!R,"aria-pressed":d,"data-selected":d?"true":void 0,"data-available":C?"true":"false",onClick:()=>b(s.id,u.id),children:u.value},u.id)})})]},s.id))})}var pt=require("react");var U=require("react/jsx-runtime"),Bt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Dt={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function dt(){return(0,U.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,U.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,U.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,U.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function ft({productId:e,variantId:t,quantity:r,amount:n,metadata:i,successUrl:o,cancelUrl:g,customerEmail:p,apiUrl:y,disabled:l,className:f,style:a,errorClassName:h,spinner:m=!0,children:c}){let{product:v,loading:w,error:I,refresh:S}=oe(e,{apiUrl:y}),{startCheckout:O,loading:b,error:s,priceChange:u}=Oe({apiUrl:y});(0,pt.useEffect)(()=>{u&&S()},[u,S]);let d=v!==null&&!v.payments_ready,C=v!==null&&!v.active,R=v!==null&&v.purchasable===!1,T=v!==null&&pe(v),P=v!==null?ne(v):[],x=t!==void 0?P.find(A=>A.id===t)??null:!T&&P.length===1?P[0]:null,E=T&&!x,B=x!==null&&!x.in_stock,ue=!!l||w||!v||d||C||R||E||B||b,$;b?$=(0,U.jsxs)(U.Fragment,{children:[m&&(0,U.jsx)(dt,{}),"Processing\u2026"]}):w?$=(0,U.jsxs)(U.Fragment,{children:[m&&(0,U.jsx)(dt,{}),c??"Buy now"]}):d?$="Payments not set up":C||R?$="Unavailable":E?$="Select options":B?$="Out of stock":c!==void 0?$=c:$="Buy now";let k=s??I;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)("button",{type:"button",className:f,style:a,disabled:ue,onClick:()=>{let A=n===void 0&&j()===null&&x!==null&&!x.allow_custom_amount&&typeof x.unit_amount=="number"?{expectedUnitAmount:x.unit_amount,expectedCurrency:x.currency}:{};O({productId:e,variantId:t,quantity:r,amount:n,metadata:i,successUrl:o,cancelUrl:g,customerEmail:p,...A})},children:$}),k&&(0,U.jsxs)("div",{role:"alert",className:h,style:h?void 0:Bt,children:[k,v===null&&!w&&I!==null&&(0,U.jsx)("button",{type:"button",onClick:S,style:Dt,children:"Tap to retry"})]})]})}var de=require("react");var q=require("react/jsx-runtime"),$t={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Ft={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},jt=1500;function zt(){return(0,q.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,q.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,q.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,q.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Kt(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function mt({productId:e,variantId:t,selection:r,quantity:n,apiUrl:i,disabled:o,className:g,style:p,errorClassName:y,spinner:l=!0,children:f}){let{product:a,loading:h,error:m,refresh:c}=oe(e,{apiUrl:i}),{add:v}=ee(),[w,I]=(0,de.useState)(!1),[S,O]=(0,de.useState)(!1),b=(0,de.useRef)(void 0);(0,de.useEffect)(()=>()=>{b.current&&clearTimeout(b.current)},[]);let s=a!==null&&!a.payments_ready,u=a!==null&&!a.active,d=a!==null&&a.purchasable===!1,C=a!==null&&!h&&ne(a).length===0,R=a!==null&&a.allow_custom_amount,T=a!==null&&pe(a),P=a!==null?ne(a):[],x=t!==void 0?P.find(K=>K.id===t)??null:r!==void 0&&T?ae(P,r):!T&&P.length===1?P[0]:null,E=a!==null&&!C&&!x,B=x!==null&&!x.in_stock,ue=!!o||h||!a||s||u||d||C||R||E||B,$=()=>{if(!a||!x)return;let K=r??Kt(x);if(!v({productId:e,variantId:x.id,quantity:n,selection:K,display:{name:a.name,variantTitle:x.title,image:fe(a,K)[0]??null}}).ok){I(!0);return}I(!1),O(!0),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>O(!1),jt)},k;h?k=(0,q.jsxs)(q.Fragment,{children:[l&&(0,q.jsx)(zt,{}),f??"Add to cart"]}):s?k="Payments not set up":u||d||C||R?k="Unavailable":E?k="Select options":B?k="Out of stock":S?k="Added to cart":f!==void 0?k=f:k="Add to cart";let L=w?"Your cart is full \u2014 remove an item before adding another.":m;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)("button",{type:"button",className:g,style:p,disabled:ue,"data-added":S?"true":void 0,onClick:$,children:k}),L&&(0,q.jsxs)("div",{role:"alert",className:y,style:y?void 0:$t,children:[L,a===null&&!h&&m!==null&&!w&&(0,q.jsx)("button",{type:"button",onClick:c,style:Ft,children:"Tap to retry"})]})]})}var V=require("react/jsx-runtime"),gt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function yt(){return(0,V.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,V.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,V.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,V.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function ht({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:i,shippingOption:o,disabled:g,className:p,style:y,errorClassName:l,spinner:f=!0,children:a}){let{items:h,hydrated:m}=ee(),{lines:c}=Le({apiUrl:e}),{startCheckout:v,loading:w,error:I,conflicts:S}=Ee({apiUrl:e}),O=m&&h.length===0,b=c.some(C=>C.status==="unavailable"),s=!!g||!m||O||b||w,u;w?u=(0,V.jsxs)(V.Fragment,{children:[f&&(0,V.jsx)(yt,{}),"Processing\u2026"]}):m?O?u="Cart is empty":b?u="Remove unavailable items":a!==void 0?u=a:u="Checkout":u=(0,V.jsxs)(V.Fragment,{children:[f&&(0,V.jsx)(yt,{}),a??"Checkout"]});let d=S?Object.keys(S).length:0;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)("button",{type:"button",className:p,style:y,disabled:s,onClick:()=>v(c,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:i,shippingOption:o}),children:u}),d>0&&(0,V.jsx)("div",{role:"alert",className:l,style:l?void 0:gt,children:d===1?"An item in your cart changed \u2014 please review your cart and try again.":`${d} items in your cart changed \u2014 please review your cart and try again.`}),I&&(0,V.jsx)("div",{role:"alert",className:l,style:l?void 0:gt,children:I})]})}var J=require("react");var _=require("react/jsx-runtime"),We="af_order_confirmation_session",Wt=1800*1e3;function Ct({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:i=2e3,pollTimeoutMs:o=6e4,followRedirect:g=!0,redirectDelayMs:p=1500,renderNoSession:y,renderPending:l,renderPaid:f,renderFailed:a}){let[h,m]=(0,J.useState)(n),[c,v]=(0,J.useState)(null),[w,I]=(0,J.useState)(!1),S=(0,J.useRef)(void 0);(0,J.useEffect)(()=>{if(n!==void 0){m(n);return}if(S.current!==void 0){m(S.current);return}let u=new URL(window.location.href),d=u.searchParams.get("session_id");if(d){u.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",u.toString());try{sessionStorage.setItem(We,JSON.stringify({id:d,ts:Date.now()}))}catch{}}else try{let C=sessionStorage.getItem(We);if(C){let R=JSON.parse(C);typeof R.id=="string"&&typeof R.ts=="number"&&Date.now()-R.ts<=Wt?d=R.id:sessionStorage.removeItem(We)}}catch{}S.current=d,m(d)},[n]),(0,J.useEffect)(()=>{if(!h)return;let u=!1,d,C=Date.now(),R=async()=>{try{let T=await fetch(`${e}/v1/o/session/${encodeURIComponent(h)}`);if(T.ok){let P=await T.json();if(u||(v(P),P.status!=="pending"))return}}catch{}if(!u){if(Date.now()-C>=o){I(!0);return}d=setTimeout(R,i)}};return R(),()=>{u=!0,d&&clearTimeout(d)}},[h,e,i,o]);let O=c!==null&&(c.status==="paid"||c.status==="partially_refunded"),b=(0,J.useRef)(!1);(0,J.useEffect)(()=>{if(!h||c===null||b.current||!(c.status==="paid"||c.status==="partially_refunded"||c.is_test===!0)||(b.current=!0,!nt(h)))return;let d=(c.line_items??[]).filter(C=>typeof C.variant_id=="string"&&C.variant_id.length>0).map(C=>({variantId:C.variant_id,quantity:C.quantity}));d.length>0&&et(d)},[h,c]);let s=O&&c.fulfillment.type==="redirect"?c.fulfillment.redirect_url:void 0;if((0,J.useEffect)(()=>{if(!s||!g)return;let u=setTimeout(()=>{window.location.href=s},p);return()=>clearTimeout(u)},[s,g,p]),h===void 0)return null;if(h===null)return y?(0,_.jsx)(_.Fragment,{children:y()}):(0,_.jsxs)("div",{className:t,style:r,children:[(0,_.jsx)("h2",{children:"Thank you for your order!"}),(0,_.jsx)("p",{children:"If you completed a payment, a confirmation email with your receipt and any download links is on its way to you. This page can only show live order details right after checkout."})]});if(!c||c.status==="pending")return l?(0,_.jsx)(_.Fragment,{children:l({timedOut:w})}):(0,_.jsx)("div",{className:t,style:r,role:"status",children:(0,_.jsx)("p",{children:w?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(O){if(f)return(0,_.jsx)(_.Fragment,{children:f(c)});let{fulfillment:u}=c,d=c.amount_total!==void 0&&c.currency?F(c.amount_total,c.currency):null,C=u.files??[],R=C.length===0?u.download_url:void 0;return(0,_.jsxs)("div",{className:t,style:r,children:[(0,_.jsx)("h2",{children:"Thank you for your purchase!"}),c.is_test&&(0,_.jsxs)("p",{children:[(0,_.jsx)("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),c.line_items&&c.line_items.length>0&&(0,_.jsx)("ul",{children:c.line_items.map((T,P)=>(0,_.jsxs)("li",{children:[T.quantity>1?`${T.quantity} \xD7 `:"",T.name,T.refunded&&(0,_.jsx)("em",{children:T.refund_reason==="oversold"?" \u2014 sold out and refunded; check your email for details":" \u2014 refunded"})]},P))}),d&&(0,_.jsxs)("p",{children:["Total paid: ",d]}),C.length>0&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("p",{children:"Your downloads:"}),(0,_.jsx)("ul",{children:C.map((T,P)=>(0,_.jsx)("li",{children:(0,_.jsx)("a",{href:T.download_url,children:T.name})},P))})]}),R&&(0,_.jsx)("p",{children:(0,_.jsx)("a",{href:R,children:"Download your file"})}),s?(0,_.jsxs)("p",{children:["Taking you to your content\u2026"," ",(0,_.jsx)("a",{href:s,children:"Continue if you are not redirected"})]}):u.redirect_url?(0,_.jsx)("p",{children:(0,_.jsx)("a",{href:u.redirect_url,children:"Continue to your content"})}):null,C.length===0&&!R&&!u.redirect_url&&(0,_.jsx)("p",{children:"A confirmation email is on its way to you."}),c.order_id&&(0,_.jsxs)("p",{children:["Order reference: ",(0,_.jsx)("code",{children:c.order_id})," \u2014 keep this if you ever need help with your order."]})]})}return a?(0,_.jsx)(_.Fragment,{children:a(c)}):(0,_.jsx)("div",{className:t,style:r,children:(0,_.jsx)("p",{children:"We couldn't confirm your payment. If you were charged, you'll receive an email confirmation \u2014 otherwise you can safely try again."})})}0&&(module.exports={AddToCartButton,AifeaturesCaptcha,BuyButton,CartCheckoutButton,MARKET_COUNTRIES,MAX_CART_LINES,OrderConfirmation,ProductPrice,VariantPicker,ZERO_DECIMAL_CURRENCIES,applySelectionToUrl,formatPrice,getOptions,getVariants,isMultiVariant,isValueAvailable,isValueInCatalog,reanchorSelection,resolveVariant,searchFromSelection,selectedImages,selectedValues,selectionFromSearch,useCart,useCartCheckout,useCartItems,useCartSummary,useCheckout,useMarket,useProduct,valueSlug,variantPriceRange});
2
+ "use strict";var Ue=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var St=Object.getOwnPropertyNames;var vt=Object.prototype.hasOwnProperty;var kt=(e,t)=>{for(var r in t)Ue(e,r,{get:t[r],enumerable:!0})},wt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of St(t))!vt.call(e,i)&&i!==r&&Ue(e,i,{get:()=>t[i],enumerable:!(n=Ct(t,i))||n.enumerable});return e};var _t=e=>wt(Ue({},"__esModule",{value:!0}),e);var Zt={};kt(Zt,{AddToCartButton:()=>mt,AifeaturesCaptcha:()=>Ge,BuyButton:()=>pt,CartCheckoutButton:()=>ht,MARKET_COUNTRIES:()=>Ae,MAX_CART_LINES:()=>We,OrderConfirmation:()=>bt,ProductPrice:()=>ut,VariantPicker:()=>lt,ZERO_DECIMAL_CURRENCIES:()=>Me,applySelectionToUrl:()=>Re,formatPrice:()=>F,getOptions:()=>le,getVariants:()=>ie,isMultiVariant:()=>fe,isValueAvailable:()=>ke,isValueInCatalog:()=>we,reanchorSelection:()=>_e,resolveVariant:()=>ue,searchFromSelection:()=>be,selectedImages:()=>pe,selectedValues:()=>Ne,selectionFromSearch:()=>xe,useCart:()=>re,useCartCheckout:()=>Ee,useCartItems:()=>Le,useCartSummary:()=>it,useCheckout:()=>Oe,useMarket:()=>st,useProduct:()=>se,valueSlug:()=>ee,variantPriceRange:()=>Pe});module.exports=_t(Zt);var he=require("react"),Je=require("@marsidev/react-turnstile"),Ve=require("react/jsx-runtime");function Ge({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:i}){let[o,p]=(0,he.useState)(null),[l,h]=(0,he.useState)(!0);return(0,he.useEffect)(()=>{h(!0),fetch(`${t}/f/${e}/config`).then(s=>s.json()).then(s=>{p(s.turnstile_sitekey),h(!1)}).catch(()=>{h(!1)})},[e,t]),l||!o?null:(0,Ve.jsx)("div",{className:i,children:(0,Ve.jsx)(Je.Turnstile,{siteKey:o,onSuccess:r,onError:n,onExpire:n,options:{theme:"light"}})})}var X=require("react"),Se=[1e3,3e3];function se(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[i,o]=(0,X.useState)(null),[p,l]=(0,X.useState)(!0),[h,s]=(0,X.useState)(null),[d,a]=(0,X.useState)(0),b=(0,X.useRef)(e);(0,X.useEffect)(()=>{let u=!1,P;l(!0),s(null),b.current!==e&&(b.current=e,o(null));let I=O=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async R=>{let T=await R.json().catch(()=>null);if(!u)if(!R.ok||!T){if(R.status>=500&&O<Se.length){P=setTimeout(()=>I(O+1),Se[O]);return}s(T?.error??`Request failed (${R.status})`),o(null),l(!1)}else o(T),l(!1)}).catch(R=>{if(!u){if(O<Se.length){P=setTimeout(()=>I(O+1),Se[O]);return}s(R instanceof Error?R.message:"Failed to load product"),l(!1)}})};return I(0),()=>{u=!0,P&&clearTimeout(P)}},[e,r,n,d]);let m=(0,X.useCallback)(()=>a(u=>u+1),[]);return{product:i,loading:p,error:h,refresh:m}}var Me=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function F(e,t,r){let n=Me.has(t.toLowerCase())?e:e/100;try{return new Intl.NumberFormat(r,{style:"currency",currency:t.toUpperCase()}).format(n)}catch{return`${n} ${t.toUpperCase()}`}}function ie(e){return e.variants??[]}function le(e){return e.options??[]}function fe(e){return le(e).length>0}function ve(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function ue(e,t){let r=Object.keys(t);return e.find(n=>{let i=n.option_values;return i.length!==r.length?!1:i.every(o=>t[o.option_id]===o.value_id)})??null}function ke(e,t,r,n){return e.some(i=>{let o=ve(i);if(o[r]!==n)return!1;for(let[p,l]of Object.entries(t))if(p!==r&&o[p]!==l)return!1;return!0})}function we(e,t,r){return e.some(n=>ve(n)[t]===r)}function _e(e,t,r,n){let i={[r]:n};for(let[p,l]of Object.entries(t)){if(p===r)continue;e.some(s=>{let d=ve(s);return d[r]===n&&d[p]===l})&&(i[p]=l)}return e.some(p=>{let l=ve(p);return Object.entries(i).every(([h,s])=>l[h]===s)})?i:{[r]:n}}function Pe(e){let t=e.map(r=>r.unit_amount).filter(r=>r!==null);return t.length===0?null:{min:Math.min(...t),max:Math.max(...t)}}function Ne(e,t){let r={};for(let n of le(e)){let i=t[n.id];if(!i)continue;let o=n.values.find(p=>p.id===i);o&&(r[n.title]=o.value)}return r}function ee(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function xe(e,t){let r=t instanceof URLSearchParams?t:new URLSearchParams(t),n=new Map;r.forEach((o,p)=>{n.has(ee(p))||n.set(ee(p),o)});let i={};for(let o of le(e)){let p=ee(o.title);if(p.length===0)continue;let l=n.get(p);if(l===void 0)continue;let h=ee(l);if(h.length===0)continue;let s=o.values.find(d=>ee(d.value)===h);s&&(i[o.id]=s.id)}return i}function be(e,t){let r={};for(let[n,i]of Object.entries(Ne(e,t))){let o=ee(n),p=ee(i);o.length===0||p.length===0||(r[o]=p)}return r}function pe(e,t){let r=[];for(let n of le(e)){let i=t[n.id];if(!i)continue;let o=n.values.find(p=>p.id===i);o?.images?.length&&r.push(...o.images)}return r.length>0?r:e.images??[]}function Re(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of le(e)){let i=ee(n.title);i.length!==0&&r.searchParams.delete(i)}for(let[n,i]of Object.entries(be(e,t)))r.searchParams.set(n,i);window.history.replaceState(window.history.state,"",r.toString())}var H=require("react");var Be="aifeatures_cart",De="aifeatures_market",Qe="aifeatures_cart_cleared";var qe="aifeatures:cart-storage",Ce=new Map;function $e(e){if(Ce.has(e))return Ce.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Fe(e,t){if(typeof window>"u"){Ce.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),Ce.delete(e)}catch{Ce.set(e,t)}Pt(e)}function Pt(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(qe,{detail:{key:e}}))}catch{}}function Ze(e,t){if(typeof window>"u")return()=>{};let r=i=>{(i.key===e||i.key===null)&&t()},n=i=>{i.detail?.key===e&&t()};return window.addEventListener("storage",r),window.addEventListener(qe,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(qe,n)}}function xt(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.productId!="string"||t.productId.length===0||typeof t.variantId!="string"||t.variantId.length===0)return null;let r=typeof t.quantity=="number"&&Number.isFinite(t.quantity)?Math.max(1,Math.floor(t.quantity)):1,n={};if(typeof t.selection=="object"&&t.selection!==null)for(let[p,l]of Object.entries(t.selection))typeof l=="string"&&(n[p]=l);let i=typeof t.display=="object"&&t.display!==null?t.display:{},o={name:typeof i.name=="string"?i.name:"",variantTitle:typeof i.variantTitle=="string"?i.variantTitle:null,image:typeof i.image=="string"?i.image:null};return{productId:t.productId,variantId:t.variantId,quantity:r,selection:n,display:o}}function ce(){let e=$e(Be);if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let r=[],n=new Set;for(let i of t){let o=xt(i);o&&!n.has(o.variantId)&&(n.add(o.variantId),r.push(o))}return r}function te(e){Fe(Be,JSON.stringify(e))}function Xe(e){return Ze(Be,e)}function et(e){let t=new Map;for(let n of e)!n.variantId||!(n.quantity>0)||t.set(n.variantId,(t.get(n.variantId)??0)+n.quantity);if(t.size===0)return;let r=[];for(let n of ce()){let i=t.get(n.variantId);if(i===void 0){r.push(n);continue}let o=n.quantity-i;o>0&&r.push({...n,quantity:o})}te(r)}function j(){let e=$e(De);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function tt(e){Fe(De,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function me(e){return Ze(De,e)}function nt(e){let t=[],r=$e(Qe);if(r)try{let i=JSON.parse(r);Array.isArray(i)&&(t=i.filter(o=>typeof o=="object"&&o!==null&&typeof o.id=="string"&&typeof o.ts=="number"))}catch{}let n=Date.now()-6048e5;return t=t.filter(i=>i.ts>n),t.some(i=>i.id===e)?!1:(t.push({id:e,ts:Date.now()}),t.length>200&&(t=t.slice(-200)),Fe(Qe,JSON.stringify(t)),!0)}var Rt=1500;function je(){try{if(typeof crypto<"u"&&"randomUUID"in crypto)return crypto.randomUUID()}catch{}return`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`}function Ie(e,t){return!("requestId"in e)||e.requestId===t}function ze(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,i=l=>{n||(n=!0,window.removeEventListener("message",o),clearTimeout(p),r(l))},o=l=>{if(l.source!==window.parent)return;let h=l.data;h?.type==="aifeatures:test-checkout-ack"&&Ie(h,t)&&i(h.status==="accepted")},p=setTimeout(()=>i(!1),Rt);window.addEventListener("message",o);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{i(!1)}})}function Oe(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,H.useState)(!1),[i,o]=(0,H.useState)(null),[p,l]=(0,H.useState)(null),h=(0,H.useRef)(!1),s=(0,H.useRef)(null);return(0,H.useEffect)(()=>{let a=b=>{b.persisted&&(h.current=!1,n(!1))};return window.addEventListener("pageshow",a),()=>window.removeEventListener("pageshow",a)},[]),(0,H.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let a=b=>{if(b.source!==window.parent)return;let m=b.data;if(m?.type!=="aifeatures:test-checkout-ack"||m.status!=="failed")return;let u=s.current;u===null||!Ie(m,u)||(s.current=null,o(typeof m.error=="string"&&m.error?m.error:"The test purchase could not be created."),h.current=!1,n(!1))};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[]),{startCheckout:(0,H.useCallback)(async({productId:a,variantId:b,quantity:m,amount:u,metadata:P,successUrl:I,cancelUrl:O,customerEmail:R,expectedUnitAmount:T,expectedCurrency:v})=>{if(!h.current){h.current=!0,n(!0),o(null),l(null);try{let f=j(),c=await fetch(`${t}/v1/p/${a}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...b!==void 0?{variant_id:b}:{},...m!==void 0?{quantity:m}:{},...u!==void 0?{amount:u}:{},...P!==void 0?{metadata:P}:{},...R!==void 0?{customer_email:R}:{},...T!==void 0&&v!==void 0?{expected_unit_amount:T,expected_currency:v}:{},...f!==null?{country:f}:{},success_url:I??`${window.location.origin}/order/confirmation`,cancel_url:O??window.location.href})}),g=await c.json().catch(()=>null);if(!c.ok){if(g?.error==="price_changed"&&typeof g.current_unit_amount=="number"&&typeof g.currency=="string"){l({currentUnitAmount:g.current_unit_amount,currency:g.currency}),o(`The price has changed to ${F(g.current_unit_amount,g.currency)} \u2014 please review and try again.`),h.current=!1,n(!1);return}if(g?.code==="preview_domain"){let k=je();if(s.current=k,await ze({productId:a,...b!==void 0?{variantId:b}:{},...m!==void 0?{quantity:m}:{},...u!==void 0?{amount:u}:{},...R!==void 0?{customerEmail:R}:{}},k))return;s.current=null}o(g?.error??`Checkout failed (${c.status})`),h.current=!1,n(!1);return}if(!g?.url){o("Checkout failed: no redirect URL returned"),h.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=g.url;return}catch{if(window.open(g.url,"_blank")){h.current=!1,n(!1);return}}window.location.href=g.url}catch(f){o(f instanceof Error?f.message:"Checkout failed"),h.current=!1,n(!1)}}},[t]),loading:r,error:i,priceChange:p}}var ne=require("react");var We=20;function rt(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function re(){let[e,t]=(0,ne.useState)([]),[r,n]=(0,ne.useState)(!1);(0,ne.useEffect)(()=>{let s=()=>t(ce());return s(),n(!0),Xe(s)},[]);let i=(0,ne.useCallback)(s=>{let d=ce(),a=rt(s.quantity);return d.find(m=>m.variantId===s.variantId)?(te(d.map(m=>m.variantId===s.variantId?{...m,quantity:m.quantity+a,selection:s.selection??m.selection,display:s.display}:m)),{ok:!0}):d.length>=We?{ok:!1,reason:"cart_full"}:(te([...d,{productId:s.productId,variantId:s.variantId,quantity:a,selection:s.selection??{},display:s.display}]),{ok:!0})},[]),o=(0,ne.useCallback)(s=>{te(ce().filter(d=>d.variantId!==s))},[]),p=(0,ne.useCallback)((s,d)=>{let a=ce();if(d<=0){te(a.filter(m=>m.variantId!==s));return}let b=rt(d);te(a.map(m=>m.variantId===s?{...m,quantity:b}:m))},[]),l=(0,ne.useCallback)(()=>{te([])},[]),h=e.reduce((s,d)=>s+d.quantity,0);return{items:e,count:h,hydrated:r,add:i,remove:o,setQuantity:p,clear:l}}var N=require("react");var Te={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},It={...Te,inStock:!0,status:"error"};function Ot(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Le(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=re(),[i,o]=(0,N.useState)({}),[p,l]=(0,N.useState)({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[h,s]=(0,N.useState)(!0),[d,a]=(0,N.useState)(null),[b,m]=(0,N.useState)(0),u=(0,N.useRef)(new Set),P=(0,N.useMemo)(()=>JSON.stringify(r.map(v=>[v.productId,v.variantId,v.selection])),[r]),I=(0,N.useCallback)(()=>m(v=>v+1),[]);(0,N.useEffect)(()=>me(I),[I]),(0,N.useEffect)(()=>{if(!n)return;if(r.length===0){o({}),l({shippingRates:null,freeShippingOver:null,shippingCountries:null}),a(null),s(!1);return}let v=!1;s(!0);let f=r,c=[...new Set(f.map(k=>k.productId))],g=async k=>{let y=new Map;return await Promise.all(c.map(async C=>{try{let _=await fetch(`${t}/v1/p/${encodeURIComponent(C)}${k?`?country=${encodeURIComponent(k)}`:""}`);if(_.status===404){y.set(C,{kind:"not_found"});return}if(!_.ok){y.set(C,{kind:"error",message:`Request failed (${_.status})`});return}let w=await _.json();y.set(C,{kind:"ok",product:w})}catch(_){y.set(C,{kind:"error",message:_ instanceof Error?_.message:"Failed to load product"})}})),y};return(async()=>{let k=j(),y=await g(k);if(k){let S=[...y.values()].filter(U=>U.kind==="ok"),E=S.filter(U=>U.product.base_currency);E.length>0&&E.length<S.length&&(y=await g(null))}if(v)return;let C=null,_=null,w=null;for(let S of c){let E=y.get(S);!E||E.kind!=="ok"||(C===null&&E.product.shipping_rates&&(C=E.product.shipping_rates),_===null&&E.product.free_shipping_over!=null&&(_=E.product.free_shipping_over),w===null&&E.product.shipping_countries&&(w=E.product.shipping_countries))}let L={},B=new Map,Q=null;for(let S of f){let E=y.get(S.productId);if(!E||E.kind==="error"){L[S.variantId]=It,E&&Q===null&&(Q=E.message);continue}if(E.kind==="not_found"){L[S.variantId]=Te;continue}let{product:U}=E;if(!U.active||U.purchasable===!1){L[S.variantId]=Te;continue}let W=U.variants??[],Z=W.find(ae=>ae.id===S.variantId)??null,K=S.variantId;if(!Z){let ae=ue(W,S.selection);if(!ae){L[S.variantId]=Te;continue}let Ye=B.get(S.variantId)??{};Ye.reanchorTo={variantId:ae.id,selection:Ot(ae)},B.set(S.variantId,Ye),u.current.add(ae.id),Z=ae,K=ae.id}let $=pe(U,S.selection)[0]??null,ye={image:$,unitAmount:Z.unit_amount,currency:Z.currency,baseCurrency:U.base_currency??null,inStock:Z.in_stock,available:Z.available,maxQuantity:U.max_quantity,pdpSearch:be(U,S.selection),status:u.current.has(K)?"reanchored":"ok"};L[S.variantId]=ye,L[K]=ye;let He=B.get(S.variantId)??{};He.display={name:U.name,variantTitle:Z.title,image:$},B.set(S.variantId,He)}let A=new Set(f.map(S=>S.variantId));for(let S of[...u.current])!A.has(S)&&!(S in L)&&u.current.delete(S);if(B.size>0){let S=ce(),E=[],U=new Map,W=!1;for(let Z of S){let K=B.get(Z.variantId),$={...Z};K?.reanchorTo&&($.variantId=K.reanchorTo.variantId,$.selection=K.reanchorTo.selection,W=!0),K?.display&&($.display.name!==K.display.name||$.display.variantTitle!==K.display.variantTitle||$.display.image!==K.display.image)&&($.display=K.display,W=!0);let ye=U.get($.variantId);if(ye){ye.quantity+=$.quantity,W=!0;continue}E.push($),U.set($.variantId,$)}W&&te(E)}v||(o(L),l({shippingRates:C,freeShippingOver:_,shippingCountries:w}),a(Q),s(!1))})(),()=>{v=!0}},[n,P,t,b]);let O=(0,N.useMemo)(()=>r.map(v=>{let f=i[v.variantId];return f?{...v,...f,image:f.image??v.display.image}:{...v,image:v.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,i]),{subtotal:R,currency:T}=(0,N.useMemo)(()=>{let v=0,f=null;for(let c of O)c.unitAmount===null||c.currency===null||(v+=c.unitAmount*c.quantity,f=f??c.currency);return{subtotal:v,currency:f}},[O]);return{lines:O,subtotal:R,currency:T,shippingRates:p.shippingRates,freeShippingOver:p.freeShippingOver,shippingCountries:p.shippingCountries,loading:h,error:d,refresh:I}}var q=require("react");var Tt=2e3;function it(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:i,hydrated:o}=re(),[p,l]=(0,q.useState)(null),[h,s]=(0,q.useState)(!1),[d,a]=(0,q.useState)(null),[b,m]=(0,q.useState)(null),[u,P]=(0,q.useState)(0);(0,q.useEffect)(()=>(m(j()),me(()=>m(j()))),[]);let I=(0,q.useMemo)(()=>i.map(f=>`${f.variantId}:${f.quantity}`).sort().join(","),[i]),O=(0,q.useCallback)(()=>P(f=>f+1),[]),R=(0,q.useRef)(0),T=(0,q.useRef)(!1),v=(0,q.useRef)("idle");return(0,q.useEffect)(()=>{if(!o)return;if(i.length===0){l(null),a(null),s(!1);return}let f=++R.current,c=new AbortController,g=!1,k,y=T.current?r:0;T.current=!0,v.current=v.current==="pending"?"spent":"idle";let C=setTimeout(async()=>{s(!0);try{let _=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:c.signal,body:JSON.stringify({items:i.map(L=>({variant_id:L.variantId,quantity:L.quantity})),...b?{country:b}:{},...n?{shipping_option:n}:{}})});if(g||f!==R.current)return;if(!_.ok){if(_.status===429){let L=v.current==="idle";L&&(k=setTimeout(()=>{g||f!==R.current||(v.current="pending",P(B=>B+1))},Tt)),a(L?"Too many updates \u2014 retrying shortly":"Too many updates \u2014 the total will refresh on the next cart change")}else a(`Could not price this cart (${_.status})`);return}let w=await _.json();if(g||f!==R.current)return;l({currency:w.currency,subtotal:w.subtotal,shipping:w.shipping?{options:w.shipping.options.map(L=>({label:L.label,amount:L.amount,undiscountedAmount:L.undiscounted_amount})),selectedAmount:w.shipping.selected_amount,selectedLabel:w.shipping.selected_label,freeShippingOver:w.shipping.free_shipping_over,freeShippingCurrency:w.shipping.free_shipping_currency,thresholdMet:w.shipping.threshold_met,collectsAddress:w.shipping.collects_address}:null,total:w.total,totalIsFinal:w.total_is_final,tax:w.tax??null,unavailableVariantIds:w.unavailable_variant_ids}),a(null)}catch(_){if(g||c.signal.aborted||f!==R.current)return;a(_ instanceof Error?_.message:"Could not price this cart")}finally{!g&&f===R.current&&s(!1)}},y);return()=>{g=!0,clearTimeout(C),k!==void 0&&clearTimeout(k),c.abort()}},[o,I,b,t,r,n,u]),{summary:p,loading:h,error:d,refresh:O}}var z=require("react");function Ee(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,z.useState)(!1),[i,o]=(0,z.useState)(null),[p,l]=(0,z.useState)(null),[h,s]=(0,z.useState)(null),d=(0,z.useRef)(!1),a=(0,z.useRef)(null);return(0,z.useEffect)(()=>{let m=u=>{u.persisted&&(d.current=!1,n(!1))};return window.addEventListener("pageshow",m),()=>window.removeEventListener("pageshow",m)},[]),(0,z.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let m=u=>{if(u.source!==window.parent)return;let P=u.data;if(P?.type!=="aifeatures:test-checkout-ack"||P.status!=="failed")return;let I=a.current;I===null||!Ie(P,I)||(a.current=null,o(typeof P.error=="string"&&P.error?P.error:"The test purchase could not be created."),d.current=!1,n(!1))};return window.addEventListener("message",m),()=>window.removeEventListener("message",m)},[]),{startCheckout:(0,z.useCallback)(async(m,{successUrl:u,cancelUrl:P,customerEmail:I,metadata:O,shippingOption:R}={})=>{if(!d.current){d.current=!0,n(!0),o(null),l(null),s(null);try{let T=j(),v=await fetch(`${t}/v1/p/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:m.map(c=>({variant_id:c.variantId,quantity:c.quantity,...typeof c.unitAmount=="number"&&typeof c.currency=="string"?{expected_unit_amount:c.unitAmount,expected_currency:c.currency}:{}})),...T!==null?{country:T}:{},...R?{shipping_option:R}:{},...O!==void 0?{metadata:O}:{},...I!==void 0?{customer_email:I}:{},success_url:u??`${window.location.origin}/order/confirmation`,cancel_url:P??window.location.href})}),f=await v.json().catch(()=>null);if(!v.ok){if(f?.code==="shipping_option_unavailable"&&typeof f.requested=="string"&&Array.isArray(f.available)){s({requested:f.requested,available:f.available,currency:typeof f.currency=="string"?f.currency:""}),d.current=!1,n(!1);return}if(f?.error==="cart_conflict"&&Array.isArray(f.items)){let c={};for(let g of f.items)g&&typeof g.variant_id=="string"&&(c[g.variant_id]=g);l(c),d.current=!1,n(!1);return}if(f?.code==="preview_domain"){let c=je();if(a.current=c,await ze({items:m.map(k=>({productId:k.productId,variantId:k.variantId,quantity:k.quantity})),...I!==void 0?{customerEmail:I}:{}},c))return;a.current=null}o(f?.error??`Checkout failed (${v.status})`),d.current=!1,n(!1);return}if(!f?.url){o("Checkout failed: no redirect URL returned"),d.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=f.url;return}catch{if(window.open(f.url,"_blank")){d.current=!1,n(!1);return}}window.location.href=f.url}catch(T){o(T instanceof Error?T.message:"Checkout failed"),d.current=!1,n(!1)}}},[t]),loading:r,error:i,conflicts:p,shippingConflict:h}}var oe=require("react");var Ae=[{country:"US",currency:"usd"},{country:"GB",currency:"gbp"},{country:"CA",currency:"cad"},{country:"AU",currency:"aud"},{country:"NZ",currency:"nzd"},{country:"JP",currency:"jpy"},{country:"CH",currency:"chf"},{country:"SE",currency:"sek"},{country:"NO",currency:"nok"},{country:"DK",currency:"dkk"},{country:"PL",currency:"pln"},{country:"CZ",currency:"czk"},{country:"SG",currency:"sgd"},{country:"HK",currency:"hkd"},{country:"MX",currency:"mxn"},{country:"BR",currency:"brl"},{country:"IN",currency:"inr"},{country:"ZA",currency:"zar"},{country:"AE",currency:"aed"},{country:"IL",currency:"ils"},{country:"AT",currency:"eur"},{country:"BE",currency:"eur"},{country:"HR",currency:"eur"},{country:"CY",currency:"eur"},{country:"EE",currency:"eur"},{country:"FI",currency:"eur"},{country:"FR",currency:"eur"},{country:"DE",currency:"eur"},{country:"GR",currency:"eur"},{country:"IE",currency:"eur"},{country:"IT",currency:"eur"},{country:"LV",currency:"eur"},{country:"LT",currency:"eur"},{country:"LU",currency:"eur"},{country:"MT",currency:"eur"},{country:"NL",currency:"eur"},{country:"PT",currency:"eur"},{country:"SK",currency:"eur"},{country:"SI",currency:"eur"},{country:"ES",currency:"eur"}];function ot(e){return e?Ae.find(t=>t.country===e.toUpperCase())?.currency??null:null}var at=new Map;function Lt(e){let t=at.get(e);return t||(t=fetch(`${e}/v1/geo`).then(async r=>{if(!r.ok)return null;let n=await r.json().catch(()=>null);return typeof n?.country=="string"&&/^[A-Za-z]{2}$/.test(n.country)?n.country.toUpperCase():null}).catch(()=>null),at.set(e,t)),t}function st(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,oe.useState)(null),[i,o]=(0,oe.useState)(!1),[p,l]=(0,oe.useState)(null);(0,oe.useEffect)(()=>{let a=()=>n(j());return a(),o(!0),me(a)},[]),(0,oe.useEffect)(()=>{let a=!1;return Lt(t).then(b=>{a||l(b)}),()=>{a=!0}},[t]);let h=(0,oe.useCallback)(a=>{tt(a)},[]),s=ot(p),d=i&&s!==null&&s!==ot(r);return{market:r,suggestedCountry:p,setMarket:h,markets:Ae,shouldPrompt:d}}var ge=require("react/jsx-runtime"),Et={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function ut({productId:e,variantId:t,apiUrl:r,locale:n,className:i,style:o,compareAtClassName:p}){let{product:l,loading:h}=se(e,{apiUrl:r});if(h||!l)return null;let s=ie(l),d=t!==void 0?s.find(b=>b.id===t)??null:l.options.length===0?s[0]??null:null;if(d){if(d.unit_amount===null)return null;let b=d.compare_at_amount!==null&&d.compare_at_amount>d.unit_amount;return(0,ge.jsxs)("span",{className:i,style:o,children:[b&&(0,ge.jsx)("span",{className:p,style:p?void 0:Et,children:F(d.compare_at_amount,d.currency,n)}),F(d.unit_amount,d.currency,n)]})}let a=Pe(s);return a?(0,ge.jsx)("span",{className:i,style:o,children:a.min===a.max?F(a.min,l.currency,n):`${F(a.min,l.currency,n)} \u2013 ${F(a.max,l.currency,n)}`}):l.unit_amount===null?null:(0,ge.jsx)("span",{className:i,style:o,children:F(l.unit_amount,l.currency,n)})}var J=require("react");var Y=require("react/jsx-runtime"),At={marginBottom:"0.75rem"},Ut={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},Vt={display:"flex",flexWrap:"wrap",gap:"0.5rem"},Mt={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},Nt={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},ct={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},qt={...ct,cursor:"pointer"},Bt=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,Dt=e=>Bt.test(e),$t={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},Ft={display:"block",width:"1.5rem",height:"1.5rem",maxWidth:"100%",maxHeight:"100%",boxSizing:"border-box",borderRadius:3,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#f3f4f6",border:"1px solid rgba(0, 0, 0, 0.2)"},jt="linear-gradient(to top right, transparent calc(50% - 2px), rgba(0,0,0,0.55) calc(50% - 2px), rgba(255,255,255,0.95) calc(50% - 1px), rgba(255,255,255,0.95) calc(50% + 1px), rgba(0,0,0,0.55) calc(50% + 1px), transparent calc(50% + 2px))";function lt({options:e,variants:t,value:r,syncUrl:n=!0,onChange:i,onVariantChange:o,className:p,style:l,optionClassName:h,optionLabelClassName:s,valueClassName:d,selectedValueClassName:a,unavailableValueClassName:b,swatchClassName:m}){let u=r!==void 0,[P,I]=(0,J.useState)(r??{}),O=u?r:P,[R,T]=(0,J.useState)(()=>new Set),v=y=>T(C=>C.has(y)?C:new Set(C).add(y));(0,J.useEffect)(()=>{T(y=>y.size===0?y:new Set)},[e]);let f=(0,J.useRef)(!1);(0,J.useEffect)(()=>{if(!n||u||f.current||e.length===0||typeof window>"u"||(f.current=!0,Object.keys(P).length>0))return;let y=xe({options:e},window.location.search);Object.keys(y).length!==0&&(I(y),i?.(y))},[n,u,e]);let c=(0,J.useMemo)(()=>e.length>0?t.filter(y=>y.option_values.length===e.length):t,[t,e]),g=(0,J.useRef)(void 0);if((0,J.useEffect)(()=>{let y=ue(c,O),C=y?.id??null;g.current!==C&&(g.current=C,o?.(y))},[c,O]),e.length===0)return null;let k=(y,C)=>{let _=_e(c,O,y,C);u||(I(_),n&&Re({options:e},_)),i?.(_)};return(0,Y.jsx)("div",{className:p,style:l,children:e.map(y=>(0,Y.jsxs)("div",{className:h,style:h?void 0:At,children:[(0,Y.jsx)("span",{className:s,style:s?void 0:Ut,children:y.title}),(0,Y.jsx)("div",{style:Vt,children:y.values.map(C=>{let _=O[y.id]===C.id,w=ke(c,O,y.id,C.id),L=w||we(c,y.id,C.id),B=[d,_?a:void 0,w?void 0:b].filter(Boolean).join(" ")||void 0,Q=C.swatch??null,A=Q&&!R.has(Q)?Q:null,S=A?Dt(A):!1,E=d?void 0:{...Mt,..._?Nt:{},...w?{}:L?qt:ct,...A?{...$t,textDecoration:"none"}:{}},U=w?C.value:`${C.value} \u2014 unavailable with your current selection`;return(0,Y.jsx)("button",{type:"button",className:B,style:E,disabled:!L,"aria-pressed":_,"aria-label":A?U:void 0,title:A?U:void 0,"data-selected":_?"true":void 0,"data-available":w?"true":"false","data-swatch":A?S?"hex":"image":void 0,onClick:()=>k(y.id,C.id),children:A?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)("span",{"aria-hidden":"true",className:m,style:m?void 0:{...Ft,...S?{background:A}:{},...S&&w?{}:{backgroundImage:[...w?[]:[jt],...S?[]:[`url(${JSON.stringify(A)})`]].join(", ")}}}),S?null:(0,Y.jsx)("img",{src:A,alt:"","aria-hidden":"true",referrerPolicy:"no-referrer",style:{display:"none"},onError:()=>v(A)})]}):C.value},C.id)})})]},y.id))})}var ft=require("react");var V=require("react/jsx-runtime"),zt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Wt={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function dt(){return(0,V.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,V.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,V.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,V.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function pt({productId:e,variantId:t,quantity:r,amount:n,metadata:i,successUrl:o,cancelUrl:p,customerEmail:l,apiUrl:h,disabled:s,className:d,style:a,errorClassName:b,spinner:m=!0,children:u}){let{product:P,loading:I,error:O,refresh:R}=se(e,{apiUrl:h}),{startCheckout:T,loading:v,error:f,priceChange:c}=Oe({apiUrl:h});(0,ft.useEffect)(()=>{c&&R()},[c,R]);let g=P!==null&&!P.payments_ready,k=P!==null&&!P.active,y=P!==null&&P.purchasable===!1,C=P!==null&&fe(P),_=P!==null?ie(P):[],w=t!==void 0?_.find(U=>U.id===t)??null:!C&&_.length===1?_[0]:null,L=C&&!w,B=w!==null&&!w.in_stock,Q=!!s||I||!P||g||k||y||L||B||v,A;v?A=(0,V.jsxs)(V.Fragment,{children:[m&&(0,V.jsx)(dt,{}),"Processing\u2026"]}):I?A=(0,V.jsxs)(V.Fragment,{children:[m&&(0,V.jsx)(dt,{}),u??"Buy now"]}):g?A="Payments not set up":k||y?A="Unavailable":L?A="Select options":B?A="Out of stock":u!==void 0?A=u:A="Buy now";let S=f??O;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)("button",{type:"button",className:d,style:a,disabled:Q,onClick:()=>{let U=n===void 0&&j()===null&&w!==null&&!w.allow_custom_amount&&typeof w.unit_amount=="number"?{expectedUnitAmount:w.unit_amount,expectedCurrency:w.currency}:{};T({productId:e,variantId:t,quantity:r,amount:n,metadata:i,successUrl:o,cancelUrl:p,customerEmail:l,...U})},children:A}),S&&(0,V.jsxs)("div",{role:"alert",className:b,style:b?void 0:zt,children:[S,P===null&&!I&&O!==null&&(0,V.jsx)("button",{type:"button",onClick:R,style:Wt,children:"Tap to retry"})]})]})}var de=require("react");var D=require("react/jsx-runtime"),Kt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Ht={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Yt=1500;function Jt(){return(0,D.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,D.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,D.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,D.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Gt(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function mt({productId:e,variantId:t,selection:r,quantity:n,apiUrl:i,disabled:o,className:p,style:l,errorClassName:h,spinner:s=!0,children:d}){let{product:a,loading:b,error:m,refresh:u}=se(e,{apiUrl:i}),{add:P}=re(),[I,O]=(0,de.useState)(!1),[R,T]=(0,de.useState)(!1),v=(0,de.useRef)(void 0);(0,de.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);let f=a!==null&&!a.payments_ready,c=a!==null&&!a.active,g=a!==null&&a.purchasable===!1,k=a!==null&&!b&&ie(a).length===0,y=a!==null&&a.allow_custom_amount,C=a!==null&&fe(a),_=a!==null?ie(a):[],w=t!==void 0?_.find(W=>W.id===t)??null:r!==void 0&&C?ue(_,r):!C&&_.length===1?_[0]:null,L=a!==null&&!k&&!w,B=w!==null&&!w.in_stock,Q=!!o||b||!a||f||c||g||k||y||L||B,A=()=>{if(!a||!w)return;let W=r??Gt(w);if(!P({productId:e,variantId:w.id,quantity:n,selection:W,display:{name:a.name,variantTitle:w.title,image:pe(a,W)[0]??null}}).ok){O(!0);return}O(!1),T(!0),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>T(!1),Yt)},S;b?S=(0,D.jsxs)(D.Fragment,{children:[s&&(0,D.jsx)(Jt,{}),d??"Add to cart"]}):f?S="Payments not set up":c||g||k||y?S="Unavailable":L?S="Select options":B?S="Out of stock":R?S="Added to cart":d!==void 0?S=d:S="Add to cart";let E=I?"Your cart is full \u2014 remove an item before adding another.":m;return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)("button",{type:"button",className:p,style:l,disabled:Q,"data-added":R?"true":void 0,onClick:A,children:S}),E&&(0,D.jsxs)("div",{role:"alert",className:h,style:h?void 0:Kt,children:[E,a===null&&!b&&m!==null&&!I&&(0,D.jsx)("button",{type:"button",onClick:u,style:Ht,children:"Tap to retry"})]})]})}var M=require("react/jsx-runtime"),gt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function yt(){return(0,M.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,M.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,M.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,M.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function ht({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:i,shippingOption:o,disabled:p,className:l,style:h,errorClassName:s,spinner:d=!0,children:a}){let{items:b,hydrated:m}=re(),{lines:u}=Le({apiUrl:e}),{startCheckout:P,loading:I,error:O,conflicts:R}=Ee({apiUrl:e}),T=m&&b.length===0,v=u.some(k=>k.status==="unavailable"),f=!!p||!m||T||v||I,c;I?c=(0,M.jsxs)(M.Fragment,{children:[d&&(0,M.jsx)(yt,{}),"Processing\u2026"]}):m?T?c="Cart is empty":v?c="Remove unavailable items":a!==void 0?c=a:c="Checkout":c=(0,M.jsxs)(M.Fragment,{children:[d&&(0,M.jsx)(yt,{}),a??"Checkout"]});let g=R?Object.keys(R).length:0;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)("button",{type:"button",className:l,style:h,disabled:f,onClick:()=>P(u,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:i,shippingOption:o}),children:c}),g>0&&(0,M.jsx)("div",{role:"alert",className:s,style:s?void 0:gt,children:g===1?"An item in your cart changed \u2014 please review your cart and try again.":`${g} items in your cart changed \u2014 please review your cart and try again.`}),O&&(0,M.jsx)("div",{role:"alert",className:s,style:s?void 0:gt,children:O})]})}var G=require("react");var x=require("react/jsx-runtime"),Ke="af_order_confirmation_session",Qt=1800*1e3;function bt({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:i=2e3,pollTimeoutMs:o=6e4,followRedirect:p=!0,redirectDelayMs:l=1500,renderNoSession:h,renderPending:s,renderPaid:d,renderFailed:a}){let[b,m]=(0,G.useState)(n),[u,P]=(0,G.useState)(null),[I,O]=(0,G.useState)(!1),R=(0,G.useRef)(void 0);(0,G.useEffect)(()=>{if(n!==void 0){m(n);return}if(R.current!==void 0){m(R.current);return}let c=new URL(window.location.href),g=c.searchParams.get("session_id");if(g){c.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",c.toString());try{sessionStorage.setItem(Ke,JSON.stringify({id:g,ts:Date.now()}))}catch{}}else try{let k=sessionStorage.getItem(Ke);if(k){let y=JSON.parse(k);typeof y.id=="string"&&typeof y.ts=="number"&&Date.now()-y.ts<=Qt?g=y.id:sessionStorage.removeItem(Ke)}}catch{}R.current=g,m(g)},[n]),(0,G.useEffect)(()=>{if(!b)return;let c=!1,g,k=Date.now(),y=async()=>{try{let C=await fetch(`${e}/v1/o/session/${encodeURIComponent(b)}`);if(C.ok){let _=await C.json();if(c||(P(_),_.status!=="pending"))return}}catch{}if(!c){if(Date.now()-k>=o){O(!0);return}g=setTimeout(y,i)}};return y(),()=>{c=!0,g&&clearTimeout(g)}},[b,e,i,o]);let T=u!==null&&(u.status==="paid"||u.status==="partially_refunded"),v=(0,G.useRef)(!1);(0,G.useEffect)(()=>{if(!b||u===null||v.current||!(u.status==="paid"||u.status==="partially_refunded"||u.is_test===!0)||(v.current=!0,!nt(b)))return;let g=(u.line_items??[]).filter(k=>typeof k.variant_id=="string"&&k.variant_id.length>0).map(k=>({variantId:k.variant_id,quantity:k.quantity}));g.length>0&&et(g)},[b,u]);let f=T&&u.fulfillment.type==="redirect"?u.fulfillment.redirect_url:void 0;if((0,G.useEffect)(()=>{if(!f||!p)return;let c=setTimeout(()=>{window.location.href=f},l);return()=>clearTimeout(c)},[f,p,l]),b===void 0)return null;if(b===null)return h?(0,x.jsx)(x.Fragment,{children:h()}):(0,x.jsxs)("div",{className:t,style:r,children:[(0,x.jsx)("h2",{children:"Thank you for your order!"}),(0,x.jsx)("p",{children:"If you completed a payment, a confirmation email with your receipt and any download links is on its way to you. This page can only show live order details right after checkout."})]});if(!u||u.status==="pending")return s?(0,x.jsx)(x.Fragment,{children:s({timedOut:I})}):(0,x.jsx)("div",{className:t,style:r,role:"status",children:(0,x.jsx)("p",{children:I?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(T){if(d)return(0,x.jsx)(x.Fragment,{children:d(u)});let{fulfillment:c}=u,g=u.amount_total!==void 0&&u.currency?F(u.amount_total,u.currency):null,k=c.files??[],y=k.length===0?c.download_url:void 0;return(0,x.jsxs)("div",{className:t,style:r,children:[(0,x.jsx)("h2",{children:"Thank you for your purchase!"}),u.is_test&&(0,x.jsxs)("p",{children:[(0,x.jsx)("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),u.line_items&&u.line_items.length>0&&(0,x.jsx)("ul",{children:u.line_items.map((C,_)=>(0,x.jsxs)("li",{children:[C.quantity>1?`${C.quantity} \xD7 `:"",C.name,C.refunded&&(0,x.jsx)("em",{children:C.refund_reason==="oversold"?" \u2014 sold out and refunded; check your email for details":" \u2014 refunded"})]},_))}),g&&(0,x.jsxs)("p",{children:["Total paid: ",g]}),k.length>0&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("p",{children:"Your downloads:"}),(0,x.jsx)("ul",{children:k.map((C,_)=>(0,x.jsx)("li",{children:(0,x.jsx)("a",{href:C.download_url,children:C.name})},_))})]}),y&&(0,x.jsx)("p",{children:(0,x.jsx)("a",{href:y,children:"Download your file"})}),f?(0,x.jsxs)("p",{children:["Taking you to your content\u2026"," ",(0,x.jsx)("a",{href:f,children:"Continue if you are not redirected"})]}):c.redirect_url?(0,x.jsx)("p",{children:(0,x.jsx)("a",{href:c.redirect_url,children:"Continue to your content"})}):null,k.length===0&&!y&&!c.redirect_url&&(0,x.jsx)("p",{children:"A confirmation email is on its way to you."}),u.order_id&&(0,x.jsxs)("p",{children:["Order reference: ",(0,x.jsx)("code",{children:u.order_id})," \u2014 keep this if you ever need help with your order."]})]})}return a?(0,x.jsx)(x.Fragment,{children:a(u)}):(0,x.jsx)("div",{className:t,style:r,children:(0,x.jsx)("p",{children:"We couldn't confirm your payment. If you were charged, you'll receive an email confirmation \u2014 otherwise you can safely try again."})})}0&&(module.exports={AddToCartButton,AifeaturesCaptcha,BuyButton,CartCheckoutButton,MARKET_COUNTRIES,MAX_CART_LINES,OrderConfirmation,ProductPrice,VariantPicker,ZERO_DECIMAL_CURRENCIES,applySelectionToUrl,formatPrice,getOptions,getVariants,isMultiVariant,isValueAvailable,isValueInCatalog,reanchorSelection,resolveVariant,searchFromSelection,selectedImages,selectedValues,selectionFromSearch,useCart,useCartCheckout,useCartItems,useCartSummary,useCheckout,useMarket,useProduct,valueSlug,variantPriceRange});
package/dist/index.d.cts CHANGED
@@ -42,6 +42,22 @@ interface PublicOptionValue {
42
42
  * `selectedImages()`, which applies that rule for you).
43
43
  */
44
44
  images: string[];
45
+ /**
46
+ * Colour chip for this value: a hex colour ("#6B7A4F") or an image URL for
47
+ * a pattern/finish. null when the merchant hasn't set one — `VariantPicker`
48
+ * then renders the value's text label instead, so a half-swatched option
49
+ * shows which values still need one.
50
+ *
51
+ * Deliberately unrelated to `images` above: those are product photography
52
+ * shown when the value is SELECTED, and are never used as a chip.
53
+ *
54
+ * OPTIONAL on the type, though the API always sends it. This interface is
55
+ * exported, and `VariantPicker` takes `options` directly — so consumers
56
+ * hand-author these literals, and a required key would fail their build on
57
+ * what ships as a patch release. Readers must treat missing and null alike
58
+ * (`v.swatch ?? null`).
59
+ */
60
+ swatch?: string | null;
45
61
  }
46
62
  /** A product option axis (e.g. "Size", "Color") the buyer chooses from. */
47
63
  interface PublicOption {
@@ -949,6 +965,8 @@ interface VariantPickerProps {
949
965
  valueClassName?: string;
950
966
  /** Class added to the currently selected value button. */
951
967
  selectedValueClassName?: string;
968
+ /** Class for the swatch chip rendered in place of a swatched value's label. */
969
+ swatchClassName?: string;
952
970
  /**
953
971
  * Class added to values with no variant under the current other selections.
954
972
  * Most of these stay clickable (clicking re-anchors the selection around
@@ -976,7 +994,7 @@ interface VariantPickerProps {
976
994
  * Unstyled-first: pass the *ClassName props (or target the data-selected /
977
995
  * data-available attributes) to match the site's design.
978
996
  */
979
- declare function VariantPicker({ options, variants, value, syncUrl, onChange, onVariantChange, className, style, optionClassName, optionLabelClassName, valueClassName, selectedValueClassName, unavailableValueClassName, }: VariantPickerProps): react_jsx_runtime.JSX.Element | null;
997
+ declare function VariantPicker({ options, variants, value, syncUrl, onChange, onVariantChange, className, style, optionClassName, optionLabelClassName, valueClassName, selectedValueClassName, unavailableValueClassName, swatchClassName, }: VariantPickerProps): react_jsx_runtime.JSX.Element | null;
980
998
 
981
999
  interface BuyButtonProps {
982
1000
  /** Product ID from aifeatures */
package/dist/index.d.ts CHANGED
@@ -42,6 +42,22 @@ interface PublicOptionValue {
42
42
  * `selectedImages()`, which applies that rule for you).
43
43
  */
44
44
  images: string[];
45
+ /**
46
+ * Colour chip for this value: a hex colour ("#6B7A4F") or an image URL for
47
+ * a pattern/finish. null when the merchant hasn't set one — `VariantPicker`
48
+ * then renders the value's text label instead, so a half-swatched option
49
+ * shows which values still need one.
50
+ *
51
+ * Deliberately unrelated to `images` above: those are product photography
52
+ * shown when the value is SELECTED, and are never used as a chip.
53
+ *
54
+ * OPTIONAL on the type, though the API always sends it. This interface is
55
+ * exported, and `VariantPicker` takes `options` directly — so consumers
56
+ * hand-author these literals, and a required key would fail their build on
57
+ * what ships as a patch release. Readers must treat missing and null alike
58
+ * (`v.swatch ?? null`).
59
+ */
60
+ swatch?: string | null;
45
61
  }
46
62
  /** A product option axis (e.g. "Size", "Color") the buyer chooses from. */
47
63
  interface PublicOption {
@@ -949,6 +965,8 @@ interface VariantPickerProps {
949
965
  valueClassName?: string;
950
966
  /** Class added to the currently selected value button. */
951
967
  selectedValueClassName?: string;
968
+ /** Class for the swatch chip rendered in place of a swatched value's label. */
969
+ swatchClassName?: string;
952
970
  /**
953
971
  * Class added to values with no variant under the current other selections.
954
972
  * Most of these stay clickable (clicking re-anchors the selection around
@@ -976,7 +994,7 @@ interface VariantPickerProps {
976
994
  * Unstyled-first: pass the *ClassName props (or target the data-selected /
977
995
  * data-available attributes) to match the site's design.
978
996
  */
979
- declare function VariantPicker({ options, variants, value, syncUrl, onChange, onVariantChange, className, style, optionClassName, optionLabelClassName, valueClassName, selectedValueClassName, unavailableValueClassName, }: VariantPickerProps): react_jsx_runtime.JSX.Element | null;
997
+ declare function VariantPicker({ options, variants, value, syncUrl, onChange, onVariantChange, className, style, optionClassName, optionLabelClassName, valueClassName, selectedValueClassName, unavailableValueClassName, swatchClassName, }: VariantPickerProps): react_jsx_runtime.JSX.Element | null;
980
998
 
981
999
  interface BuyButtonProps {
982
1000
  /** Product ID from aifeatures */
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{useState as Ze,useEffect as It}from"react";import{Turnstile as Ot}from"@marsidev/react-turnstile";import{jsx as He}from"react/jsx-runtime";function Tt({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:i}){let[o,g]=Ze(null),[p,y]=Ze(!0);return It(()=>{y(!0),fetch(`${t}/f/${e}/config`).then(l=>l.json()).then(l=>{g(l.turnstile_sitekey),y(!1)}).catch(()=>{y(!1)})},[e,t]),p||!o?null:He("div",{className:i,children:He(Ot,{siteKey:o,onSuccess:r,onError:n,onExpire:n,options:{theme:"light"}})})}import{useCallback as Lt,useEffect as Et,useRef as At,useState as de}from"react";var pe=[1e3,3e3];function Z(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[i,o]=de(null),[g,p]=de(!0),[y,l]=de(null),[f,a]=de(0),h=At(e);Et(()=>{let c=!1,v;p(!0),l(null),h.current!==e&&(h.current=e,o(null));let _=R=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async S=>{let I=await S.json().catch(()=>null);if(!c)if(!S.ok||!I){if(S.status>=500&&R<pe.length){v=setTimeout(()=>_(R+1),pe[R]);return}l(I?.error??`Request failed (${S.status})`),o(null),p(!1)}else o(I),p(!1)}).catch(S=>{if(!c){if(R<pe.length){v=setTimeout(()=>_(R+1),pe[R]);return}l(S instanceof Error?S.message:"Failed to load product"),p(!1)}})};return _(0),()=>{c=!0,v&&clearTimeout(v)}},[e,r,n,f]);let m=Lt(()=>a(c=>c+1),[]);return{product:i,loading:g,error:y,refresh:m}}var Xe=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function D(e,t,r){let n=Xe.has(t.toLowerCase())?e:e/100;try{return new Intl.NumberFormat(r,{style:"currency",currency:t.toUpperCase()}).format(n)}catch{return`${n} ${t.toUpperCase()}`}}function W(e){return e.variants??[]}function ee(e){return e.options??[]}function ie(e){return ee(e).length>0}function fe(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function H(e,t){let r=Object.keys(t);return e.find(n=>{let i=n.option_values;return i.length!==r.length?!1:i.every(o=>t[o.option_id]===o.value_id)})??null}function _e(e,t,r,n){return e.some(i=>{let o=fe(i);if(o[r]!==n)return!1;for(let[g,p]of Object.entries(t))if(g!==r&&o[g]!==p)return!1;return!0})}function we(e,t,r){return e.some(n=>fe(n)[t]===r)}function Pe(e,t,r,n){let i={[r]:n};for(let[g,p]of Object.entries(t)){if(g===r)continue;e.some(l=>{let f=fe(l);return f[r]===n&&f[g]===p})&&(i[g]=p)}return e.some(g=>{let p=fe(g);return Object.entries(i).every(([y,l])=>p[y]===l)})?i:{[r]:n}}function xe(e){let t=e.map(r=>r.unit_amount).filter(r=>r!==null);return t.length===0?null:{min:Math.min(...t),max:Math.max(...t)}}function et(e,t){let r={};for(let n of ee(e)){let i=t[n.id];if(!i)continue;let o=n.values.find(g=>g.id===i);o&&(r[n.title]=o.value)}return r}function j(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Re(e,t){let r=t instanceof URLSearchParams?t:new URLSearchParams(t),n=new Map;r.forEach((o,g)=>{n.has(j(g))||n.set(j(g),o)});let i={};for(let o of ee(e)){let g=j(o.title);if(g.length===0)continue;let p=n.get(g);if(p===void 0)continue;let y=j(p);if(y.length===0)continue;let l=o.values.find(f=>j(f.value)===y);l&&(i[o.id]=l.id)}return i}function me(e,t){let r={};for(let[n,i]of Object.entries(et(e,t))){let o=j(n),g=j(i);o.length===0||g.length===0||(r[o]=g)}return r}function oe(e,t){let r=[];for(let n of ee(e)){let i=t[n.id];if(!i)continue;let o=n.values.find(g=>g.id===i);o?.images?.length&&r.push(...o.images)}return r.length>0?r:e.images??[]}function Ie(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of ee(e)){let i=j(n.title);i.length!==0&&r.searchParams.delete(i)}for(let[n,i]of Object.entries(me(e,t)))r.searchParams.set(n,i);window.history.replaceState(window.history.state,"",r.toString())}import{useCallback as Mt,useEffect as st,useRef as ut,useState as Ue}from"react";var Te="aifeatures_cart",Le="aifeatures_market",tt="aifeatures_cart_cleared";var Oe="aifeatures:cart-storage",ae=new Map;function Ee(e){if(ae.has(e))return ae.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Ae(e,t){if(typeof window>"u"){ae.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),ae.delete(e)}catch{ae.set(e,t)}Ut(e)}function Ut(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(Oe,{detail:{key:e}}))}catch{}}function nt(e,t){if(typeof window>"u")return()=>{};let r=i=>{(i.key===e||i.key===null)&&t()},n=i=>{i.detail?.key===e&&t()};return window.addEventListener("storage",r),window.addEventListener(Oe,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(Oe,n)}}function Vt(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.productId!="string"||t.productId.length===0||typeof t.variantId!="string"||t.variantId.length===0)return null;let r=typeof t.quantity=="number"&&Number.isFinite(t.quantity)?Math.max(1,Math.floor(t.quantity)):1,n={};if(typeof t.selection=="object"&&t.selection!==null)for(let[g,p]of Object.entries(t.selection))typeof p=="string"&&(n[g]=p);let i=typeof t.display=="object"&&t.display!==null?t.display:{},o={name:typeof i.name=="string"?i.name:"",variantTitle:typeof i.variantTitle=="string"?i.variantTitle:null,image:typeof i.image=="string"?i.image:null};return{productId:t.productId,variantId:t.variantId,quantity:r,selection:n,display:o}}function Y(){let e=Ee(Te);if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let r=[],n=new Set;for(let i of t){let o=Vt(i);o&&!n.has(o.variantId)&&(n.add(o.variantId),r.push(o))}return r}function F(e){Ae(Te,JSON.stringify(e))}function rt(e){return nt(Te,e)}function it(e){let t=new Map;for(let n of e)!n.variantId||!(n.quantity>0)||t.set(n.variantId,(t.get(n.variantId)??0)+n.quantity);if(t.size===0)return;let r=[];for(let n of Y()){let i=t.get(n.variantId);if(i===void 0){r.push(n);continue}let o=n.quantity-i;o>0&&r.push({...n,quantity:o})}F(r)}function N(){let e=Ee(Le);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function ot(e){Ae(Le,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function te(e){return nt(Le,e)}function at(e){let t=[],r=Ee(tt);if(r)try{let i=JSON.parse(r);Array.isArray(i)&&(t=i.filter(o=>typeof o=="object"&&o!==null&&typeof o.id=="string"&&typeof o.ts=="number"))}catch{}let n=Date.now()-6048e5;return t=t.filter(i=>i.ts>n),t.some(i=>i.id===e)?!1:(t.push({id:e,ts:Date.now()}),t.length>200&&(t=t.slice(-200)),Ae(tt,JSON.stringify(t)),!0)}var Nt=1500;function Ve(){try{if(typeof crypto<"u"&&"randomUUID"in crypto)return crypto.randomUUID()}catch{}return`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`}function ge(e,t){return!("requestId"in e)||e.requestId===t}function Me(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,i=p=>{n||(n=!0,window.removeEventListener("message",o),clearTimeout(g),r(p))},o=p=>{if(p.source!==window.parent)return;let y=p.data;y?.type==="aifeatures:test-checkout-ack"&&ge(y,t)&&i(y.status==="accepted")},g=setTimeout(()=>i(!1),Nt);window.addEventListener("message",o);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{i(!1)}})}function Ne(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Ue(!1),[i,o]=Ue(null),[g,p]=Ue(null),y=ut(!1),l=ut(null);return st(()=>{let a=h=>{h.persisted&&(y.current=!1,n(!1))};return window.addEventListener("pageshow",a),()=>window.removeEventListener("pageshow",a)},[]),st(()=>{if(typeof window>"u"||window.self===window.top)return;let a=h=>{if(h.source!==window.parent)return;let m=h.data;if(m?.type!=="aifeatures:test-checkout-ack"||m.status!=="failed")return;let c=l.current;c===null||!ge(m,c)||(l.current=null,o(typeof m.error=="string"&&m.error?m.error:"The test purchase could not be created."),y.current=!1,n(!1))};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[]),{startCheckout:Mt(async({productId:a,variantId:h,quantity:m,amount:c,metadata:v,successUrl:_,cancelUrl:R,customerEmail:S,expectedUnitAmount:I,expectedCurrency:b})=>{if(!y.current){y.current=!0,n(!0),o(null),p(null);try{let s=N(),u=await fetch(`${t}/v1/p/${a}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...h!==void 0?{variant_id:h}:{},...m!==void 0?{quantity:m}:{},...c!==void 0?{amount:c}:{},...v!==void 0?{metadata:v}:{},...S!==void 0?{customer_email:S}:{},...I!==void 0&&b!==void 0?{expected_unit_amount:I,expected_currency:b}:{},...s!==null?{country:s}:{},success_url:_??`${window.location.origin}/order/confirmation`,cancel_url:R??window.location.href})}),d=await u.json().catch(()=>null);if(!u.ok){if(d?.error==="price_changed"&&typeof d.current_unit_amount=="number"&&typeof d.currency=="string"){p({currentUnitAmount:d.current_unit_amount,currency:d.currency}),o(`The price has changed to ${D(d.current_unit_amount,d.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(d?.code==="preview_domain"){let C=Ve();if(l.current=C,await Me({productId:a,...h!==void 0?{variantId:h}:{},...m!==void 0?{quantity:m}:{},...c!==void 0?{amount:c}:{},...S!==void 0?{customerEmail:S}:{}},C))return;l.current=null}o(d?.error??`Checkout failed (${u.status})`),y.current=!1,n(!1);return}if(!d?.url){o("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=d.url;return}catch{if(window.open(d.url,"_blank")){y.current=!1,n(!1);return}}window.location.href=d.url}catch(s){o(s instanceof Error?s.message:"Checkout failed"),y.current=!1,n(!1)}}},[t]),loading:r,error:i,priceChange:g}}import{useCallback as ye,useEffect as qt,useState as lt}from"react";var dt=20;function ct(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function z(){let[e,t]=lt([]),[r,n]=lt(!1);qt(()=>{let l=()=>t(Y());return l(),n(!0),rt(l)},[]);let i=ye(l=>{let f=Y(),a=ct(l.quantity);return f.find(m=>m.variantId===l.variantId)?(F(f.map(m=>m.variantId===l.variantId?{...m,quantity:m.quantity+a,selection:l.selection??m.selection,display:l.display}:m)),{ok:!0}):f.length>=dt?{ok:!1,reason:"cart_full"}:(F([...f,{productId:l.productId,variantId:l.variantId,quantity:a,selection:l.selection??{},display:l.display}]),{ok:!0})},[]),o=ye(l=>{F(Y().filter(f=>f.variantId!==l))},[]),g=ye((l,f)=>{let a=Y();if(f<=0){F(a.filter(m=>m.variantId!==l));return}let h=ct(f);F(a.map(m=>m.variantId===l?{...m,quantity:h}:m))},[]),p=ye(()=>{F([])},[]),y=e.reduce((l,f)=>l+f.quantity,0);return{items:e,count:y,hydrated:r,add:i,remove:o,setQuantity:g,clear:p}}import{useCallback as Bt,useEffect as pt,useMemo as qe,useRef as Dt,useState as se}from"react";var he={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},$t={...he,inStock:!0,status:"error"};function Ft(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Be(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=z(),[i,o]=se({}),[g,p]=se({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,l]=se(!0),[f,a]=se(null),[h,m]=se(0),c=Dt(new Set),v=qe(()=>JSON.stringify(r.map(b=>[b.productId,b.variantId,b.selection])),[r]),_=Bt(()=>m(b=>b+1),[]);pt(()=>te(_),[_]),pt(()=>{if(!n)return;if(r.length===0){o({}),p({shippingRates:null,freeShippingOver:null,shippingCountries:null}),a(null),l(!1);return}let b=!1;l(!0);let s=r,u=[...new Set(s.map(C=>C.productId))],d=async C=>{let x=new Map;return await Promise.all(u.map(async O=>{try{let w=await fetch(`${t}/v1/p/${encodeURIComponent(O)}${C?`?country=${encodeURIComponent(C)}`:""}`);if(w.status===404){x.set(O,{kind:"not_found"});return}if(!w.ok){x.set(O,{kind:"error",message:`Request failed (${w.status})`});return}let P=await w.json();x.set(O,{kind:"ok",product:P})}catch(w){x.set(O,{kind:"error",message:w instanceof Error?w.message:"Failed to load product"})}})),x};return(async()=>{let C=N(),x=await d(C);if(C){let k=[...x.values()].filter(A=>A.kind==="ok"),T=k.filter(A=>A.product.base_currency);T.length>0&&T.length<k.length&&(x=await d(null))}if(b)return;let O=null,w=null,P=null;for(let k of u){let T=x.get(k);!T||T.kind!=="ok"||(O===null&&T.product.shipping_rates&&(O=T.product.shipping_rates),w===null&&T.product.free_shipping_over!=null&&(w=T.product.free_shipping_over),P===null&&T.product.shipping_countries&&(P=T.product.shipping_countries))}let E={},U=new Map,Q=null;for(let k of s){let T=x.get(k.productId);if(!T||T.kind==="error"){E[k.variantId]=$t,T&&Q===null&&(Q=T.message);continue}if(T.kind==="not_found"){E[k.variantId]=he;continue}let{product:A}=T;if(!A.active||A.purchasable===!1){E[k.variantId]=he;continue}let q=A.variants??[],$=q.find(K=>K.id===k.variantId)??null,B=k.variantId;if(!$){let K=H(q,k.selection);if(!K){E[k.variantId]=he;continue}let Qe=U.get(k.variantId)??{};Qe.reanchorTo={variantId:K.id,selection:Ft(K)},U.set(k.variantId,Qe),c.current.add(K.id),$=K,B=K.id}let V=oe(A,k.selection)[0]??null,re={image:V,unitAmount:$.unit_amount,currency:$.currency,baseCurrency:A.base_currency??null,inStock:$.in_stock,available:$.available,maxQuantity:A.max_quantity,pdpSearch:me(A,k.selection),status:c.current.has(B)?"reanchored":"ok"};E[k.variantId]=re,E[B]=re;let Ge=U.get(k.variantId)??{};Ge.display={name:A.name,variantTitle:$.title,image:V},U.set(k.variantId,Ge)}let M=new Set(s.map(k=>k.variantId));for(let k of[...c.current])!M.has(k)&&!(k in E)&&c.current.delete(k);if(U.size>0){let k=Y(),T=[],A=new Map,q=!1;for(let $ of k){let B=U.get($.variantId),V={...$};B?.reanchorTo&&(V.variantId=B.reanchorTo.variantId,V.selection=B.reanchorTo.selection,q=!0),B?.display&&(V.display.name!==B.display.name||V.display.variantTitle!==B.display.variantTitle||V.display.image!==B.display.image)&&(V.display=B.display,q=!0);let re=A.get(V.variantId);if(re){re.quantity+=V.quantity,q=!0;continue}T.push(V),A.set(V.variantId,V)}q&&F(T)}b||(o(E),p({shippingRates:O,freeShippingOver:w,shippingCountries:P}),a(Q),l(!1))})(),()=>{b=!0}},[n,v,t,h]);let R=qe(()=>r.map(b=>{let s=i[b.variantId];return s?{...b,...s,image:s.image??b.display.image}:{...b,image:b.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,i]),{subtotal:S,currency:I}=qe(()=>{let b=0,s=null;for(let u of R)u.unitAmount===null||u.currency===null||(b+=u.unitAmount*u.quantity,s=s??u.currency);return{subtotal:b,currency:s}},[R]);return{lines:R,subtotal:S,currency:I,shippingRates:g.shippingRates,freeShippingOver:g.freeShippingOver,shippingCountries:g.shippingCountries,loading:y,error:f,refresh:_}}import{useCallback as jt,useEffect as ft,useMemo as zt,useRef as De,useState as ue}from"react";var Kt=2e3;function Wt(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:i,hydrated:o}=z(),[g,p]=ue(null),[y,l]=ue(!1),[f,a]=ue(null),[h,m]=ue(null),[c,v]=ue(0);ft(()=>(m(N()),te(()=>m(N()))),[]);let _=zt(()=>i.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[i]),R=jt(()=>v(s=>s+1),[]),S=De(0),I=De(!1),b=De("idle");return ft(()=>{if(!o)return;if(i.length===0){p(null),a(null),l(!1);return}let s=++S.current,u=new AbortController,d=!1,C,x=I.current?r:0;I.current=!0,b.current=b.current==="pending"?"spent":"idle";let O=setTimeout(async()=>{l(!0);try{let w=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:u.signal,body:JSON.stringify({items:i.map(E=>({variant_id:E.variantId,quantity:E.quantity})),...h?{country:h}:{},...n?{shipping_option:n}:{}})});if(d||s!==S.current)return;if(!w.ok){if(w.status===429){let E=b.current==="idle";E&&(C=setTimeout(()=>{d||s!==S.current||(b.current="pending",v(U=>U+1))},Kt)),a(E?"Too many updates \u2014 retrying shortly":"Too many updates \u2014 the total will refresh on the next cart change")}else a(`Could not price this cart (${w.status})`);return}let P=await w.json();if(d||s!==S.current)return;p({currency:P.currency,subtotal:P.subtotal,shipping:P.shipping?{options:P.shipping.options.map(E=>({label:E.label,amount:E.amount,undiscountedAmount:E.undiscounted_amount})),selectedAmount:P.shipping.selected_amount,selectedLabel:P.shipping.selected_label,freeShippingOver:P.shipping.free_shipping_over,freeShippingCurrency:P.shipping.free_shipping_currency,thresholdMet:P.shipping.threshold_met,collectsAddress:P.shipping.collects_address}:null,total:P.total,totalIsFinal:P.total_is_final,tax:P.tax??null,unavailableVariantIds:P.unavailable_variant_ids}),a(null)}catch(w){if(d||u.signal.aborted||s!==S.current)return;a(w instanceof Error?w.message:"Could not price this cart")}finally{!d&&s===S.current&&l(!1)}},x);return()=>{d=!0,clearTimeout(O),C!==void 0&&clearTimeout(C),u.abort()}},[o,_,h,t,r,n,c]),{summary:g,loading:y,error:f,refresh:R}}import{useCallback as Yt,useEffect as mt,useRef as gt,useState as Ce}from"react";function $e(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Ce(!1),[i,o]=Ce(null),[g,p]=Ce(null),[y,l]=Ce(null),f=gt(!1),a=gt(null);return mt(()=>{let m=c=>{c.persisted&&(f.current=!1,n(!1))};return window.addEventListener("pageshow",m),()=>window.removeEventListener("pageshow",m)},[]),mt(()=>{if(typeof window>"u"||window.self===window.top)return;let m=c=>{if(c.source!==window.parent)return;let v=c.data;if(v?.type!=="aifeatures:test-checkout-ack"||v.status!=="failed")return;let _=a.current;_===null||!ge(v,_)||(a.current=null,o(typeof v.error=="string"&&v.error?v.error:"The test purchase could not be created."),f.current=!1,n(!1))};return window.addEventListener("message",m),()=>window.removeEventListener("message",m)},[]),{startCheckout:Yt(async(m,{successUrl:c,cancelUrl:v,customerEmail:_,metadata:R,shippingOption:S}={})=>{if(!f.current){f.current=!0,n(!0),o(null),p(null),l(null);try{let I=N(),b=await fetch(`${t}/v1/p/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:m.map(u=>({variant_id:u.variantId,quantity:u.quantity,...typeof u.unitAmount=="number"&&typeof u.currency=="string"?{expected_unit_amount:u.unitAmount,expected_currency:u.currency}:{}})),...I!==null?{country:I}:{},...S?{shipping_option:S}:{},...R!==void 0?{metadata:R}:{},..._!==void 0?{customer_email:_}:{},success_url:c??`${window.location.origin}/order/confirmation`,cancel_url:v??window.location.href})}),s=await b.json().catch(()=>null);if(!b.ok){if(s?.code==="shipping_option_unavailable"&&typeof s.requested=="string"&&Array.isArray(s.available)){l({requested:s.requested,available:s.available,currency:typeof s.currency=="string"?s.currency:""}),f.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let u={};for(let d of s.items)d&&typeof d.variant_id=="string"&&(u[d.variant_id]=d);p(u),f.current=!1,n(!1);return}if(s?.code==="preview_domain"){let u=Ve();if(a.current=u,await Me({items:m.map(C=>({productId:C.productId,variantId:C.variantId,quantity:C.quantity})),..._!==void 0?{customerEmail:_}:{}},u))return;a.current=null}o(s?.error??`Checkout failed (${b.status})`),f.current=!1,n(!1);return}if(!s?.url){o("Checkout failed: no redirect URL returned"),f.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=s.url;return}catch{if(window.open(s.url,"_blank")){f.current=!1,n(!1);return}}window.location.href=s.url}catch(I){o(I instanceof Error?I.message:"Checkout failed"),f.current=!1,n(!1)}}},[t]),loading:r,error:i,conflicts:g,shippingConflict:y}}import{useCallback as Jt,useEffect as yt,useState as Fe}from"react";var je=[{country:"US",currency:"usd"},{country:"GB",currency:"gbp"},{country:"CA",currency:"cad"},{country:"AU",currency:"aud"},{country:"NZ",currency:"nzd"},{country:"JP",currency:"jpy"},{country:"CH",currency:"chf"},{country:"SE",currency:"sek"},{country:"NO",currency:"nok"},{country:"DK",currency:"dkk"},{country:"PL",currency:"pln"},{country:"CZ",currency:"czk"},{country:"SG",currency:"sgd"},{country:"HK",currency:"hkd"},{country:"MX",currency:"mxn"},{country:"BR",currency:"brl"},{country:"IN",currency:"inr"},{country:"ZA",currency:"zar"},{country:"AE",currency:"aed"},{country:"IL",currency:"ils"},{country:"AT",currency:"eur"},{country:"BE",currency:"eur"},{country:"HR",currency:"eur"},{country:"CY",currency:"eur"},{country:"EE",currency:"eur"},{country:"FI",currency:"eur"},{country:"FR",currency:"eur"},{country:"DE",currency:"eur"},{country:"GR",currency:"eur"},{country:"IE",currency:"eur"},{country:"IT",currency:"eur"},{country:"LV",currency:"eur"},{country:"LT",currency:"eur"},{country:"LU",currency:"eur"},{country:"MT",currency:"eur"},{country:"NL",currency:"eur"},{country:"PT",currency:"eur"},{country:"SK",currency:"eur"},{country:"SI",currency:"eur"},{country:"ES",currency:"eur"}];function ht(e){return e?je.find(t=>t.country===e.toUpperCase())?.currency??null:null}var Ct=new Map;function Gt(e){let t=Ct.get(e);return t||(t=fetch(`${e}/v1/geo`).then(async r=>{if(!r.ok)return null;let n=await r.json().catch(()=>null);return typeof n?.country=="string"&&/^[A-Za-z]{2}$/.test(n.country)?n.country.toUpperCase():null}).catch(()=>null),Ct.set(e,t)),t}function Qt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Fe(null),[i,o]=Fe(!1),[g,p]=Fe(null);yt(()=>{let a=()=>n(N());return a(),o(!0),te(a)},[]),yt(()=>{let a=!1;return Gt(t).then(h=>{a||p(h)}),()=>{a=!0}},[t]);let y=Jt(a=>{ot(a)},[]),l=ht(g),f=i&&l!==null&&l!==ht(r);return{market:r,suggestedCountry:g,setMarket:y,markets:je,shouldPrompt:f}}import{jsx as ze,jsxs as Xt}from"react/jsx-runtime";var Zt={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function Ht({productId:e,variantId:t,apiUrl:r,locale:n,className:i,style:o,compareAtClassName:g}){let{product:p,loading:y}=Z(e,{apiUrl:r});if(y||!p)return null;let l=W(p),f=t!==void 0?l.find(h=>h.id===t)??null:p.options.length===0?l[0]??null:null;if(f){if(f.unit_amount===null)return null;let h=f.compare_at_amount!==null&&f.compare_at_amount>f.unit_amount;return Xt("span",{className:i,style:o,children:[h&&ze("span",{className:g,style:g?void 0:Zt,children:D(f.compare_at_amount,f.currency,n)}),D(f.unit_amount,f.currency,n)]})}let a=xe(l);return a?ze("span",{className:i,style:o,children:a.min===a.max?D(a.min,p.currency,n):`${D(a.min,p.currency,n)} \u2013 ${D(a.max,p.currency,n)}`}):p.unit_amount===null?null:ze("span",{className:i,style:o,children:D(p.unit_amount,p.currency,n)})}import{useEffect as bt,useMemo as en,useRef as St,useState as tn}from"react";import{jsx as be,jsxs as cn}from"react/jsx-runtime";var nn={marginBottom:"0.75rem"},rn={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},on={display:"flex",flexWrap:"wrap",gap:"0.5rem"},an={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},sn={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},vt={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},un={...vt,cursor:"pointer"};function ln({options:e,variants:t,value:r,syncUrl:n=!0,onChange:i,onVariantChange:o,className:g,style:p,optionClassName:y,optionLabelClassName:l,valueClassName:f,selectedValueClassName:a,unavailableValueClassName:h}){let m=r!==void 0,[c,v]=tn(r??{}),_=m?r:c,R=St(!1);bt(()=>{if(!n||m||R.current||e.length===0||typeof window>"u"||(R.current=!0,Object.keys(c).length>0))return;let s=Re({options:e},window.location.search);Object.keys(s).length!==0&&(v(s),i?.(s))},[n,m,e]);let S=en(()=>e.length>0?t.filter(s=>s.option_values.length===e.length):t,[t,e]),I=St(void 0);if(bt(()=>{let s=H(S,_),u=s?.id??null;I.current!==u&&(I.current=u,o?.(s))},[S,_]),e.length===0)return null;let b=(s,u)=>{let d=Pe(S,_,s,u);m||(v(d),n&&Ie({options:e},d)),i?.(d)};return be("div",{className:g,style:p,children:e.map(s=>cn("div",{className:y,style:y?void 0:nn,children:[be("span",{className:l,style:l?void 0:rn,children:s.title}),be("div",{style:on,children:s.values.map(u=>{let d=_[s.id]===u.id,C=_e(S,_,s.id,u.id),x=C||we(S,s.id,u.id),O=[f,d?a:void 0,C?void 0:h].filter(Boolean).join(" ")||void 0,w=f?void 0:{...an,...d?sn:{},...C?{}:x?un:vt};return be("button",{type:"button",className:O,style:w,disabled:!x,"aria-pressed":d,"data-selected":d?"true":void 0,"data-available":C?"true":"false",onClick:()=>b(s.id,u.id),children:u.value},u.id)})})]},s.id))})}import{useEffect as dn}from"react";import{Fragment as Ke,jsx as X,jsxs as le}from"react/jsx-runtime";var pn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},fn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function kt(){return le("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[X("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),X("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:X("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function mn({productId:e,variantId:t,quantity:r,amount:n,metadata:i,successUrl:o,cancelUrl:g,customerEmail:p,apiUrl:y,disabled:l,className:f,style:a,errorClassName:h,spinner:m=!0,children:c}){let{product:v,loading:_,error:R,refresh:S}=Z(e,{apiUrl:y}),{startCheckout:I,loading:b,error:s,priceChange:u}=Ne({apiUrl:y});dn(()=>{u&&S()},[u,S]);let d=v!==null&&!v.payments_ready,C=v!==null&&!v.active,x=v!==null&&v.purchasable===!1,O=v!==null&&ie(v),w=v!==null?W(v):[],P=t!==void 0?w.find(A=>A.id===t)??null:!O&&w.length===1?w[0]:null,E=O&&!P,U=P!==null&&!P.in_stock,Q=!!l||_||!v||d||C||x||E||U||b,M;b?M=le(Ke,{children:[m&&X(kt,{}),"Processing\u2026"]}):_?M=le(Ke,{children:[m&&X(kt,{}),c??"Buy now"]}):d?M="Payments not set up":C||x?M="Unavailable":E?M="Select options":U?M="Out of stock":c!==void 0?M=c:M="Buy now";let k=s??R;return le(Ke,{children:[X("button",{type:"button",className:f,style:a,disabled:Q,onClick:()=>{let A=n===void 0&&N()===null&&P!==null&&!P.allow_custom_amount&&typeof P.unit_amount=="number"?{expectedUnitAmount:P.unit_amount,expectedCurrency:P.currency}:{};I({productId:e,variantId:t,quantity:r,amount:n,metadata:i,successUrl:o,cancelUrl:g,customerEmail:p,...A})},children:M}),k&&le("div",{role:"alert",className:h,style:h?void 0:pn,children:[k,v===null&&!_&&R!==null&&X("button",{type:"button",onClick:S,style:fn,children:"Tap to retry"})]})]})}import{useEffect as gn,useRef as yn,useState as _t}from"react";import{Fragment as wt,jsx as ne,jsxs as Se}from"react/jsx-runtime";var hn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Cn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},bn=1500;function Sn(){return Se("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[ne("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),ne("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:ne("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function vn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function kn({productId:e,variantId:t,selection:r,quantity:n,apiUrl:i,disabled:o,className:g,style:p,errorClassName:y,spinner:l=!0,children:f}){let{product:a,loading:h,error:m,refresh:c}=Z(e,{apiUrl:i}),{add:v}=z(),[_,R]=_t(!1),[S,I]=_t(!1),b=yn(void 0);gn(()=>()=>{b.current&&clearTimeout(b.current)},[]);let s=a!==null&&!a.payments_ready,u=a!==null&&!a.active,d=a!==null&&a.purchasable===!1,C=a!==null&&!h&&W(a).length===0,x=a!==null&&a.allow_custom_amount,O=a!==null&&ie(a),w=a!==null?W(a):[],P=t!==void 0?w.find(q=>q.id===t)??null:r!==void 0&&O?H(w,r):!O&&w.length===1?w[0]:null,E=a!==null&&!C&&!P,U=P!==null&&!P.in_stock,Q=!!o||h||!a||s||u||d||C||x||E||U,M=()=>{if(!a||!P)return;let q=r??vn(P);if(!v({productId:e,variantId:P.id,quantity:n,selection:q,display:{name:a.name,variantTitle:P.title,image:oe(a,q)[0]??null}}).ok){R(!0);return}R(!1),I(!0),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>I(!1),bn)},k;h?k=Se(wt,{children:[l&&ne(Sn,{}),f??"Add to cart"]}):s?k="Payments not set up":u||d||C||x?k="Unavailable":E?k="Select options":U?k="Out of stock":S?k="Added to cart":f!==void 0?k=f:k="Add to cart";let T=_?"Your cart is full \u2014 remove an item before adding another.":m;return Se(wt,{children:[ne("button",{type:"button",className:g,style:p,disabled:Q,"data-added":S?"true":void 0,onClick:M,children:k}),T&&Se("div",{role:"alert",className:y,style:y?void 0:hn,children:[T,a===null&&!h&&m!==null&&!_&&ne("button",{type:"button",onClick:c,style:Cn,children:"Tap to retry"})]})]})}import{Fragment as We,jsx as J,jsxs as ve}from"react/jsx-runtime";var Pt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function xt(){return ve("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[J("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),J("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:J("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function _n({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:i,shippingOption:o,disabled:g,className:p,style:y,errorClassName:l,spinner:f=!0,children:a}){let{items:h,hydrated:m}=z(),{lines:c}=Be({apiUrl:e}),{startCheckout:v,loading:_,error:R,conflicts:S}=$e({apiUrl:e}),I=m&&h.length===0,b=c.some(C=>C.status==="unavailable"),s=!!g||!m||I||b||_,u;_?u=ve(We,{children:[f&&J(xt,{}),"Processing\u2026"]}):m?I?u="Cart is empty":b?u="Remove unavailable items":a!==void 0?u=a:u="Checkout":u=ve(We,{children:[f&&J(xt,{}),a??"Checkout"]});let d=S?Object.keys(S).length:0;return ve(We,{children:[J("button",{type:"button",className:p,style:y,disabled:s,onClick:()=>v(c,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:i,shippingOption:o}),children:u}),d>0&&J("div",{role:"alert",className:l,style:l?void 0:Pt,children:d===1?"An item in your cart changed \u2014 please review your cart and try again.":`${d} items in your cart changed \u2014 please review your cart and try again.`}),R&&J("div",{role:"alert",className:l,style:l?void 0:Pt,children:R})]})}import{useEffect as ke,useRef as Rt,useState as Ye}from"react";import{Fragment as ce,jsx as L,jsxs as G}from"react/jsx-runtime";var Je="af_order_confirmation_session",wn=1800*1e3;function Pn({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:i=2e3,pollTimeoutMs:o=6e4,followRedirect:g=!0,redirectDelayMs:p=1500,renderNoSession:y,renderPending:l,renderPaid:f,renderFailed:a}){let[h,m]=Ye(n),[c,v]=Ye(null),[_,R]=Ye(!1),S=Rt(void 0);ke(()=>{if(n!==void 0){m(n);return}if(S.current!==void 0){m(S.current);return}let u=new URL(window.location.href),d=u.searchParams.get("session_id");if(d){u.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",u.toString());try{sessionStorage.setItem(Je,JSON.stringify({id:d,ts:Date.now()}))}catch{}}else try{let C=sessionStorage.getItem(Je);if(C){let x=JSON.parse(C);typeof x.id=="string"&&typeof x.ts=="number"&&Date.now()-x.ts<=wn?d=x.id:sessionStorage.removeItem(Je)}}catch{}S.current=d,m(d)},[n]),ke(()=>{if(!h)return;let u=!1,d,C=Date.now(),x=async()=>{try{let O=await fetch(`${e}/v1/o/session/${encodeURIComponent(h)}`);if(O.ok){let w=await O.json();if(u||(v(w),w.status!=="pending"))return}}catch{}if(!u){if(Date.now()-C>=o){R(!0);return}d=setTimeout(x,i)}};return x(),()=>{u=!0,d&&clearTimeout(d)}},[h,e,i,o]);let I=c!==null&&(c.status==="paid"||c.status==="partially_refunded"),b=Rt(!1);ke(()=>{if(!h||c===null||b.current||!(c.status==="paid"||c.status==="partially_refunded"||c.is_test===!0)||(b.current=!0,!at(h)))return;let d=(c.line_items??[]).filter(C=>typeof C.variant_id=="string"&&C.variant_id.length>0).map(C=>({variantId:C.variant_id,quantity:C.quantity}));d.length>0&&it(d)},[h,c]);let s=I&&c.fulfillment.type==="redirect"?c.fulfillment.redirect_url:void 0;if(ke(()=>{if(!s||!g)return;let u=setTimeout(()=>{window.location.href=s},p);return()=>clearTimeout(u)},[s,g,p]),h===void 0)return null;if(h===null)return y?L(ce,{children:y()}):G("div",{className:t,style:r,children:[L("h2",{children:"Thank you for your order!"}),L("p",{children:"If you completed a payment, a confirmation email with your receipt and any download links is on its way to you. This page can only show live order details right after checkout."})]});if(!c||c.status==="pending")return l?L(ce,{children:l({timedOut:_})}):L("div",{className:t,style:r,role:"status",children:L("p",{children:_?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(I){if(f)return L(ce,{children:f(c)});let{fulfillment:u}=c,d=c.amount_total!==void 0&&c.currency?D(c.amount_total,c.currency):null,C=u.files??[],x=C.length===0?u.download_url:void 0;return G("div",{className:t,style:r,children:[L("h2",{children:"Thank you for your purchase!"}),c.is_test&&G("p",{children:[L("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),c.line_items&&c.line_items.length>0&&L("ul",{children:c.line_items.map((O,w)=>G("li",{children:[O.quantity>1?`${O.quantity} \xD7 `:"",O.name,O.refunded&&L("em",{children:O.refund_reason==="oversold"?" \u2014 sold out and refunded; check your email for details":" \u2014 refunded"})]},w))}),d&&G("p",{children:["Total paid: ",d]}),C.length>0&&G(ce,{children:[L("p",{children:"Your downloads:"}),L("ul",{children:C.map((O,w)=>L("li",{children:L("a",{href:O.download_url,children:O.name})},w))})]}),x&&L("p",{children:L("a",{href:x,children:"Download your file"})}),s?G("p",{children:["Taking you to your content\u2026"," ",L("a",{href:s,children:"Continue if you are not redirected"})]}):u.redirect_url?L("p",{children:L("a",{href:u.redirect_url,children:"Continue to your content"})}):null,C.length===0&&!x&&!u.redirect_url&&L("p",{children:"A confirmation email is on its way to you."}),c.order_id&&G("p",{children:["Order reference: ",L("code",{children:c.order_id})," \u2014 keep this if you ever need help with your order."]})]})}return a?L(ce,{children:a(c)}):L("div",{className:t,style:r,children:L("p",{children:"We couldn't confirm your payment. If you were charged, you'll receive an email confirmation \u2014 otherwise you can safely try again."})})}export{kn as AddToCartButton,Tt as AifeaturesCaptcha,mn as BuyButton,_n as CartCheckoutButton,je as MARKET_COUNTRIES,dt as MAX_CART_LINES,Pn as OrderConfirmation,Ht as ProductPrice,ln as VariantPicker,Xe as ZERO_DECIMAL_CURRENCIES,Ie as applySelectionToUrl,D as formatPrice,ee as getOptions,W as getVariants,ie as isMultiVariant,_e as isValueAvailable,we as isValueInCatalog,Pe as reanchorSelection,H as resolveVariant,me as searchFromSelection,oe as selectedImages,et as selectedValues,Re as selectionFromSearch,z as useCart,$e as useCartCheckout,Be as useCartItems,Wt as useCartSummary,Ne as useCheckout,Qt as useMarket,Z as useProduct,j as valueSlug,xe as variantPriceRange};
2
+ import{useState as Ze,useEffect as Tt}from"react";import{Turnstile as Lt}from"@marsidev/react-turnstile";import{jsx as Xe}from"react/jsx-runtime";function Et({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:i}){let[o,p]=Ze(null),[l,h]=Ze(!0);return Tt(()=>{h(!0),fetch(`${t}/f/${e}/config`).then(s=>s.json()).then(s=>{p(s.turnstile_sitekey),h(!1)}).catch(()=>{h(!1)})},[e,t]),l||!o?null:Xe("div",{className:i,children:Xe(Lt,{siteKey:o,onSuccess:r,onError:n,onExpire:n,options:{theme:"light"}})})}import{useCallback as At,useEffect as Ut,useRef as Vt,useState as fe}from"react";var pe=[1e3,3e3];function Q(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[i,o]=fe(null),[p,l]=fe(!0),[h,s]=fe(null),[d,a]=fe(0),b=Vt(e);Ut(()=>{let u=!1,P;l(!0),s(null),b.current!==e&&(b.current=e,o(null));let R=I=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async x=>{let O=await x.json().catch(()=>null);if(!u)if(!x.ok||!O){if(x.status>=500&&I<pe.length){P=setTimeout(()=>R(I+1),pe[I]);return}s(O?.error??`Request failed (${x.status})`),o(null),l(!1)}else o(O),l(!1)}).catch(x=>{if(!u){if(I<pe.length){P=setTimeout(()=>R(I+1),pe[I]);return}s(x instanceof Error?x.message:"Failed to load product"),l(!1)}})};return R(0),()=>{u=!0,P&&clearTimeout(P)}},[e,r,n,d]);let m=At(()=>a(u=>u+1),[]);return{product:i,loading:p,error:h,refresh:m}}var et=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function D(e,t,r){let n=et.has(t.toLowerCase())?e:e/100;try{return new Intl.NumberFormat(r,{style:"currency",currency:t.toUpperCase()}).format(n)}catch{return`${n} ${t.toUpperCase()}`}}function H(e){return e.variants??[]}function ee(e){return e.options??[]}function oe(e){return ee(e).length>0}function me(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Z(e,t){let r=Object.keys(t);return e.find(n=>{let i=n.option_values;return i.length!==r.length?!1:i.every(o=>t[o.option_id]===o.value_id)})??null}function we(e,t,r,n){return e.some(i=>{let o=me(i);if(o[r]!==n)return!1;for(let[p,l]of Object.entries(t))if(p!==r&&o[p]!==l)return!1;return!0})}function _e(e,t,r){return e.some(n=>me(n)[t]===r)}function Pe(e,t,r,n){let i={[r]:n};for(let[p,l]of Object.entries(t)){if(p===r)continue;e.some(s=>{let d=me(s);return d[r]===n&&d[p]===l})&&(i[p]=l)}return e.some(p=>{let l=me(p);return Object.entries(i).every(([h,s])=>l[h]===s)})?i:{[r]:n}}function xe(e){let t=e.map(r=>r.unit_amount).filter(r=>r!==null);return t.length===0?null:{min:Math.min(...t),max:Math.max(...t)}}function tt(e,t){let r={};for(let n of ee(e)){let i=t[n.id];if(!i)continue;let o=n.values.find(p=>p.id===i);o&&(r[n.title]=o.value)}return r}function z(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Re(e,t){let r=t instanceof URLSearchParams?t:new URLSearchParams(t),n=new Map;r.forEach((o,p)=>{n.has(z(p))||n.set(z(p),o)});let i={};for(let o of ee(e)){let p=z(o.title);if(p.length===0)continue;let l=n.get(p);if(l===void 0)continue;let h=z(l);if(h.length===0)continue;let s=o.values.find(d=>z(d.value)===h);s&&(i[o.id]=s.id)}return i}function ge(e,t){let r={};for(let[n,i]of Object.entries(tt(e,t))){let o=z(n),p=z(i);o.length===0||p.length===0||(r[o]=p)}return r}function ae(e,t){let r=[];for(let n of ee(e)){let i=t[n.id];if(!i)continue;let o=n.values.find(p=>p.id===i);o?.images?.length&&r.push(...o.images)}return r.length>0?r:e.images??[]}function Ie(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of ee(e)){let i=z(n.title);i.length!==0&&r.searchParams.delete(i)}for(let[n,i]of Object.entries(ge(e,t)))r.searchParams.set(n,i);window.history.replaceState(window.history.state,"",r.toString())}import{useCallback as qt,useEffect as ut,useRef as ct,useState as Ue}from"react";var Te="aifeatures_cart",Le="aifeatures_market",nt="aifeatures_cart_cleared";var Oe="aifeatures:cart-storage",se=new Map;function Ee(e){if(se.has(e))return se.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Ae(e,t){if(typeof window>"u"){se.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),se.delete(e)}catch{se.set(e,t)}Mt(e)}function Mt(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(Oe,{detail:{key:e}}))}catch{}}function rt(e,t){if(typeof window>"u")return()=>{};let r=i=>{(i.key===e||i.key===null)&&t()},n=i=>{i.detail?.key===e&&t()};return window.addEventListener("storage",r),window.addEventListener(Oe,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(Oe,n)}}function Nt(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.productId!="string"||t.productId.length===0||typeof t.variantId!="string"||t.variantId.length===0)return null;let r=typeof t.quantity=="number"&&Number.isFinite(t.quantity)?Math.max(1,Math.floor(t.quantity)):1,n={};if(typeof t.selection=="object"&&t.selection!==null)for(let[p,l]of Object.entries(t.selection))typeof l=="string"&&(n[p]=l);let i=typeof t.display=="object"&&t.display!==null?t.display:{},o={name:typeof i.name=="string"?i.name:"",variantTitle:typeof i.variantTitle=="string"?i.variantTitle:null,image:typeof i.image=="string"?i.image:null};return{productId:t.productId,variantId:t.variantId,quantity:r,selection:n,display:o}}function Y(){let e=Ee(Te);if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let r=[],n=new Set;for(let i of t){let o=Nt(i);o&&!n.has(o.variantId)&&(n.add(o.variantId),r.push(o))}return r}function j(e){Ae(Te,JSON.stringify(e))}function it(e){return rt(Te,e)}function ot(e){let t=new Map;for(let n of e)!n.variantId||!(n.quantity>0)||t.set(n.variantId,(t.get(n.variantId)??0)+n.quantity);if(t.size===0)return;let r=[];for(let n of Y()){let i=t.get(n.variantId);if(i===void 0){r.push(n);continue}let o=n.quantity-i;o>0&&r.push({...n,quantity:o})}j(r)}function N(){let e=Ee(Le);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function at(e){Ae(Le,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function te(e){return rt(Le,e)}function st(e){let t=[],r=Ee(nt);if(r)try{let i=JSON.parse(r);Array.isArray(i)&&(t=i.filter(o=>typeof o=="object"&&o!==null&&typeof o.id=="string"&&typeof o.ts=="number"))}catch{}let n=Date.now()-6048e5;return t=t.filter(i=>i.ts>n),t.some(i=>i.id===e)?!1:(t.push({id:e,ts:Date.now()}),t.length>200&&(t=t.slice(-200)),Ae(nt,JSON.stringify(t)),!0)}var Bt=1500;function Ve(){try{if(typeof crypto<"u"&&"randomUUID"in crypto)return crypto.randomUUID()}catch{}return`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`}function ye(e,t){return!("requestId"in e)||e.requestId===t}function Me(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,i=l=>{n||(n=!0,window.removeEventListener("message",o),clearTimeout(p),r(l))},o=l=>{if(l.source!==window.parent)return;let h=l.data;h?.type==="aifeatures:test-checkout-ack"&&ye(h,t)&&i(h.status==="accepted")},p=setTimeout(()=>i(!1),Bt);window.addEventListener("message",o);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{i(!1)}})}function Ne(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Ue(!1),[i,o]=Ue(null),[p,l]=Ue(null),h=ct(!1),s=ct(null);return ut(()=>{let a=b=>{b.persisted&&(h.current=!1,n(!1))};return window.addEventListener("pageshow",a),()=>window.removeEventListener("pageshow",a)},[]),ut(()=>{if(typeof window>"u"||window.self===window.top)return;let a=b=>{if(b.source!==window.parent)return;let m=b.data;if(m?.type!=="aifeatures:test-checkout-ack"||m.status!=="failed")return;let u=s.current;u===null||!ye(m,u)||(s.current=null,o(typeof m.error=="string"&&m.error?m.error:"The test purchase could not be created."),h.current=!1,n(!1))};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[]),{startCheckout:qt(async({productId:a,variantId:b,quantity:m,amount:u,metadata:P,successUrl:R,cancelUrl:I,customerEmail:x,expectedUnitAmount:O,expectedCurrency:v})=>{if(!h.current){h.current=!0,n(!0),o(null),l(null);try{let f=N(),c=await fetch(`${t}/v1/p/${a}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...b!==void 0?{variant_id:b}:{},...m!==void 0?{quantity:m}:{},...u!==void 0?{amount:u}:{},...P!==void 0?{metadata:P}:{},...x!==void 0?{customer_email:x}:{},...O!==void 0&&v!==void 0?{expected_unit_amount:O,expected_currency:v}:{},...f!==null?{country:f}:{},success_url:R??`${window.location.origin}/order/confirmation`,cancel_url:I??window.location.href})}),g=await c.json().catch(()=>null);if(!c.ok){if(g?.error==="price_changed"&&typeof g.current_unit_amount=="number"&&typeof g.currency=="string"){l({currentUnitAmount:g.current_unit_amount,currency:g.currency}),o(`The price has changed to ${D(g.current_unit_amount,g.currency)} \u2014 please review and try again.`),h.current=!1,n(!1);return}if(g?.code==="preview_domain"){let k=Ve();if(s.current=k,await Me({productId:a,...b!==void 0?{variantId:b}:{},...m!==void 0?{quantity:m}:{},...u!==void 0?{amount:u}:{},...x!==void 0?{customerEmail:x}:{}},k))return;s.current=null}o(g?.error??`Checkout failed (${c.status})`),h.current=!1,n(!1);return}if(!g?.url){o("Checkout failed: no redirect URL returned"),h.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=g.url;return}catch{if(window.open(g.url,"_blank")){h.current=!1,n(!1);return}}window.location.href=g.url}catch(f){o(f instanceof Error?f.message:"Checkout failed"),h.current=!1,n(!1)}}},[t]),loading:r,error:i,priceChange:p}}import{useCallback as he,useEffect as Dt,useState as lt}from"react";var ft=20;function dt(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function W(){let[e,t]=lt([]),[r,n]=lt(!1);Dt(()=>{let s=()=>t(Y());return s(),n(!0),it(s)},[]);let i=he(s=>{let d=Y(),a=dt(s.quantity);return d.find(m=>m.variantId===s.variantId)?(j(d.map(m=>m.variantId===s.variantId?{...m,quantity:m.quantity+a,selection:s.selection??m.selection,display:s.display}:m)),{ok:!0}):d.length>=ft?{ok:!1,reason:"cart_full"}:(j([...d,{productId:s.productId,variantId:s.variantId,quantity:a,selection:s.selection??{},display:s.display}]),{ok:!0})},[]),o=he(s=>{j(Y().filter(d=>d.variantId!==s))},[]),p=he((s,d)=>{let a=Y();if(d<=0){j(a.filter(m=>m.variantId!==s));return}let b=dt(d);j(a.map(m=>m.variantId===s?{...m,quantity:b}:m))},[]),l=he(()=>{j([])},[]),h=e.reduce((s,d)=>s+d.quantity,0);return{items:e,count:h,hydrated:r,add:i,remove:o,setQuantity:p,clear:l}}import{useCallback as $t,useEffect as pt,useMemo as qe,useRef as Ft,useState as ue}from"react";var be={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},jt={...be,inStock:!0,status:"error"};function zt(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Be(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=W(),[i,o]=ue({}),[p,l]=ue({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[h,s]=ue(!0),[d,a]=ue(null),[b,m]=ue(0),u=Ft(new Set),P=qe(()=>JSON.stringify(r.map(v=>[v.productId,v.variantId,v.selection])),[r]),R=$t(()=>m(v=>v+1),[]);pt(()=>te(R),[R]),pt(()=>{if(!n)return;if(r.length===0){o({}),l({shippingRates:null,freeShippingOver:null,shippingCountries:null}),a(null),s(!1);return}let v=!1;s(!0);let f=r,c=[...new Set(f.map(k=>k.productId))],g=async k=>{let y=new Map;return await Promise.all(c.map(async C=>{try{let _=await fetch(`${t}/v1/p/${encodeURIComponent(C)}${k?`?country=${encodeURIComponent(k)}`:""}`);if(_.status===404){y.set(C,{kind:"not_found"});return}if(!_.ok){y.set(C,{kind:"error",message:`Request failed (${_.status})`});return}let w=await _.json();y.set(C,{kind:"ok",product:w})}catch(_){y.set(C,{kind:"error",message:_ instanceof Error?_.message:"Failed to load product"})}})),y};return(async()=>{let k=N(),y=await g(k);if(k){let S=[...y.values()].filter(U=>U.kind==="ok"),L=S.filter(U=>U.product.base_currency);L.length>0&&L.length<S.length&&(y=await g(null))}if(v)return;let C=null,_=null,w=null;for(let S of c){let L=y.get(S);!L||L.kind!=="ok"||(C===null&&L.product.shipping_rates&&(C=L.product.shipping_rates),_===null&&L.product.free_shipping_over!=null&&(_=L.product.free_shipping_over),w===null&&L.product.shipping_countries&&(w=L.product.shipping_countries))}let T={},V=new Map,$=null;for(let S of f){let L=y.get(S.productId);if(!L||L.kind==="error"){T[S.variantId]=jt,L&&$===null&&($=L.message);continue}if(L.kind==="not_found"){T[S.variantId]=be;continue}let{product:U}=L;if(!U.active||U.purchasable===!1){T[S.variantId]=be;continue}let q=U.variants??[],F=q.find(K=>K.id===S.variantId)??null,B=S.variantId;if(!F){let K=Z(q,S.selection);if(!K){T[S.variantId]=be;continue}let Qe=V.get(S.variantId)??{};Qe.reanchorTo={variantId:K.id,selection:zt(K)},V.set(S.variantId,Qe),u.current.add(K.id),F=K,B=K.id}let M=ae(U,S.selection)[0]??null,ie={image:M,unitAmount:F.unit_amount,currency:F.currency,baseCurrency:U.base_currency??null,inStock:F.in_stock,available:F.available,maxQuantity:U.max_quantity,pdpSearch:ge(U,S.selection),status:u.current.has(B)?"reanchored":"ok"};T[S.variantId]=ie,T[B]=ie;let Ge=V.get(S.variantId)??{};Ge.display={name:U.name,variantTitle:F.title,image:M},V.set(S.variantId,Ge)}let E=new Set(f.map(S=>S.variantId));for(let S of[...u.current])!E.has(S)&&!(S in T)&&u.current.delete(S);if(V.size>0){let S=Y(),L=[],U=new Map,q=!1;for(let F of S){let B=V.get(F.variantId),M={...F};B?.reanchorTo&&(M.variantId=B.reanchorTo.variantId,M.selection=B.reanchorTo.selection,q=!0),B?.display&&(M.display.name!==B.display.name||M.display.variantTitle!==B.display.variantTitle||M.display.image!==B.display.image)&&(M.display=B.display,q=!0);let ie=U.get(M.variantId);if(ie){ie.quantity+=M.quantity,q=!0;continue}L.push(M),U.set(M.variantId,M)}q&&j(L)}v||(o(T),l({shippingRates:C,freeShippingOver:_,shippingCountries:w}),a($),s(!1))})(),()=>{v=!0}},[n,P,t,b]);let I=qe(()=>r.map(v=>{let f=i[v.variantId];return f?{...v,...f,image:f.image??v.display.image}:{...v,image:v.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,i]),{subtotal:x,currency:O}=qe(()=>{let v=0,f=null;for(let c of I)c.unitAmount===null||c.currency===null||(v+=c.unitAmount*c.quantity,f=f??c.currency);return{subtotal:v,currency:f}},[I]);return{lines:I,subtotal:x,currency:O,shippingRates:p.shippingRates,freeShippingOver:p.freeShippingOver,shippingCountries:p.shippingCountries,loading:h,error:d,refresh:R}}import{useCallback as Wt,useEffect as mt,useMemo as Kt,useRef as De,useState as ce}from"react";var Ht=2e3;function Yt(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:i,hydrated:o}=W(),[p,l]=ce(null),[h,s]=ce(!1),[d,a]=ce(null),[b,m]=ce(null),[u,P]=ce(0);mt(()=>(m(N()),te(()=>m(N()))),[]);let R=Kt(()=>i.map(f=>`${f.variantId}:${f.quantity}`).sort().join(","),[i]),I=Wt(()=>P(f=>f+1),[]),x=De(0),O=De(!1),v=De("idle");return mt(()=>{if(!o)return;if(i.length===0){l(null),a(null),s(!1);return}let f=++x.current,c=new AbortController,g=!1,k,y=O.current?r:0;O.current=!0,v.current=v.current==="pending"?"spent":"idle";let C=setTimeout(async()=>{s(!0);try{let _=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:c.signal,body:JSON.stringify({items:i.map(T=>({variant_id:T.variantId,quantity:T.quantity})),...b?{country:b}:{},...n?{shipping_option:n}:{}})});if(g||f!==x.current)return;if(!_.ok){if(_.status===429){let T=v.current==="idle";T&&(k=setTimeout(()=>{g||f!==x.current||(v.current="pending",P(V=>V+1))},Ht)),a(T?"Too many updates \u2014 retrying shortly":"Too many updates \u2014 the total will refresh on the next cart change")}else a(`Could not price this cart (${_.status})`);return}let w=await _.json();if(g||f!==x.current)return;l({currency:w.currency,subtotal:w.subtotal,shipping:w.shipping?{options:w.shipping.options.map(T=>({label:T.label,amount:T.amount,undiscountedAmount:T.undiscounted_amount})),selectedAmount:w.shipping.selected_amount,selectedLabel:w.shipping.selected_label,freeShippingOver:w.shipping.free_shipping_over,freeShippingCurrency:w.shipping.free_shipping_currency,thresholdMet:w.shipping.threshold_met,collectsAddress:w.shipping.collects_address}:null,total:w.total,totalIsFinal:w.total_is_final,tax:w.tax??null,unavailableVariantIds:w.unavailable_variant_ids}),a(null)}catch(_){if(g||c.signal.aborted||f!==x.current)return;a(_ instanceof Error?_.message:"Could not price this cart")}finally{!g&&f===x.current&&s(!1)}},y);return()=>{g=!0,clearTimeout(C),k!==void 0&&clearTimeout(k),c.abort()}},[o,R,b,t,r,n,u]),{summary:p,loading:h,error:d,refresh:I}}import{useCallback as Jt,useEffect as gt,useRef as yt,useState as Ce}from"react";function $e(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Ce(!1),[i,o]=Ce(null),[p,l]=Ce(null),[h,s]=Ce(null),d=yt(!1),a=yt(null);return gt(()=>{let m=u=>{u.persisted&&(d.current=!1,n(!1))};return window.addEventListener("pageshow",m),()=>window.removeEventListener("pageshow",m)},[]),gt(()=>{if(typeof window>"u"||window.self===window.top)return;let m=u=>{if(u.source!==window.parent)return;let P=u.data;if(P?.type!=="aifeatures:test-checkout-ack"||P.status!=="failed")return;let R=a.current;R===null||!ye(P,R)||(a.current=null,o(typeof P.error=="string"&&P.error?P.error:"The test purchase could not be created."),d.current=!1,n(!1))};return window.addEventListener("message",m),()=>window.removeEventListener("message",m)},[]),{startCheckout:Jt(async(m,{successUrl:u,cancelUrl:P,customerEmail:R,metadata:I,shippingOption:x}={})=>{if(!d.current){d.current=!0,n(!0),o(null),l(null),s(null);try{let O=N(),v=await fetch(`${t}/v1/p/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:m.map(c=>({variant_id:c.variantId,quantity:c.quantity,...typeof c.unitAmount=="number"&&typeof c.currency=="string"?{expected_unit_amount:c.unitAmount,expected_currency:c.currency}:{}})),...O!==null?{country:O}:{},...x?{shipping_option:x}:{},...I!==void 0?{metadata:I}:{},...R!==void 0?{customer_email:R}:{},success_url:u??`${window.location.origin}/order/confirmation`,cancel_url:P??window.location.href})}),f=await v.json().catch(()=>null);if(!v.ok){if(f?.code==="shipping_option_unavailable"&&typeof f.requested=="string"&&Array.isArray(f.available)){s({requested:f.requested,available:f.available,currency:typeof f.currency=="string"?f.currency:""}),d.current=!1,n(!1);return}if(f?.error==="cart_conflict"&&Array.isArray(f.items)){let c={};for(let g of f.items)g&&typeof g.variant_id=="string"&&(c[g.variant_id]=g);l(c),d.current=!1,n(!1);return}if(f?.code==="preview_domain"){let c=Ve();if(a.current=c,await Me({items:m.map(k=>({productId:k.productId,variantId:k.variantId,quantity:k.quantity})),...R!==void 0?{customerEmail:R}:{}},c))return;a.current=null}o(f?.error??`Checkout failed (${v.status})`),d.current=!1,n(!1);return}if(!f?.url){o("Checkout failed: no redirect URL returned"),d.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=f.url;return}catch{if(window.open(f.url,"_blank")){d.current=!1,n(!1);return}}window.location.href=f.url}catch(O){o(O instanceof Error?O.message:"Checkout failed"),d.current=!1,n(!1)}}},[t]),loading:r,error:i,conflicts:p,shippingConflict:h}}import{useCallback as Gt,useEffect as ht,useState as Fe}from"react";var je=[{country:"US",currency:"usd"},{country:"GB",currency:"gbp"},{country:"CA",currency:"cad"},{country:"AU",currency:"aud"},{country:"NZ",currency:"nzd"},{country:"JP",currency:"jpy"},{country:"CH",currency:"chf"},{country:"SE",currency:"sek"},{country:"NO",currency:"nok"},{country:"DK",currency:"dkk"},{country:"PL",currency:"pln"},{country:"CZ",currency:"czk"},{country:"SG",currency:"sgd"},{country:"HK",currency:"hkd"},{country:"MX",currency:"mxn"},{country:"BR",currency:"brl"},{country:"IN",currency:"inr"},{country:"ZA",currency:"zar"},{country:"AE",currency:"aed"},{country:"IL",currency:"ils"},{country:"AT",currency:"eur"},{country:"BE",currency:"eur"},{country:"HR",currency:"eur"},{country:"CY",currency:"eur"},{country:"EE",currency:"eur"},{country:"FI",currency:"eur"},{country:"FR",currency:"eur"},{country:"DE",currency:"eur"},{country:"GR",currency:"eur"},{country:"IE",currency:"eur"},{country:"IT",currency:"eur"},{country:"LV",currency:"eur"},{country:"LT",currency:"eur"},{country:"LU",currency:"eur"},{country:"MT",currency:"eur"},{country:"NL",currency:"eur"},{country:"PT",currency:"eur"},{country:"SK",currency:"eur"},{country:"SI",currency:"eur"},{country:"ES",currency:"eur"}];function bt(e){return e?je.find(t=>t.country===e.toUpperCase())?.currency??null:null}var Ct=new Map;function Qt(e){let t=Ct.get(e);return t||(t=fetch(`${e}/v1/geo`).then(async r=>{if(!r.ok)return null;let n=await r.json().catch(()=>null);return typeof n?.country=="string"&&/^[A-Za-z]{2}$/.test(n.country)?n.country.toUpperCase():null}).catch(()=>null),Ct.set(e,t)),t}function Zt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Fe(null),[i,o]=Fe(!1),[p,l]=Fe(null);ht(()=>{let a=()=>n(N());return a(),o(!0),te(a)},[]),ht(()=>{let a=!1;return Qt(t).then(b=>{a||l(b)}),()=>{a=!0}},[t]);let h=Gt(a=>{at(a)},[]),s=bt(p),d=i&&s!==null&&s!==bt(r);return{market:r,suggestedCountry:p,setMarket:h,markets:je,shouldPrompt:d}}import{jsx as ze,jsxs as tn}from"react/jsx-runtime";var Xt={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function en({productId:e,variantId:t,apiUrl:r,locale:n,className:i,style:o,compareAtClassName:p}){let{product:l,loading:h}=Q(e,{apiUrl:r});if(h||!l)return null;let s=H(l),d=t!==void 0?s.find(b=>b.id===t)??null:l.options.length===0?s[0]??null:null;if(d){if(d.unit_amount===null)return null;let b=d.compare_at_amount!==null&&d.compare_at_amount>d.unit_amount;return tn("span",{className:i,style:o,children:[b&&ze("span",{className:p,style:p?void 0:Xt,children:D(d.compare_at_amount,d.currency,n)}),D(d.unit_amount,d.currency,n)]})}let a=xe(s);return a?ze("span",{className:i,style:o,children:a.min===a.max?D(a.min,l.currency,n):`${D(a.min,l.currency,n)} \u2013 ${D(a.max,l.currency,n)}`}):l.unit_amount===null?null:ze("span",{className:i,style:o,children:D(l.unit_amount,l.currency,n)})}import{useEffect as We,useMemo as nn,useRef as St,useState as vt}from"react";import{Fragment as yn,jsx as ne,jsxs as kt}from"react/jsx-runtime";var rn={marginBottom:"0.75rem"},on={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},an={display:"flex",flexWrap:"wrap",gap:"0.5rem"},sn={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},un={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},wt={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},cn={...wt,cursor:"pointer"},ln=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,dn=e=>ln.test(e),fn={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},pn={display:"block",width:"1.5rem",height:"1.5rem",maxWidth:"100%",maxHeight:"100%",boxSizing:"border-box",borderRadius:3,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#f3f4f6",border:"1px solid rgba(0, 0, 0, 0.2)"},mn="linear-gradient(to top right, transparent calc(50% - 2px), rgba(0,0,0,0.55) calc(50% - 2px), rgba(255,255,255,0.95) calc(50% - 1px), rgba(255,255,255,0.95) calc(50% + 1px), rgba(0,0,0,0.55) calc(50% + 1px), transparent calc(50% + 2px))";function gn({options:e,variants:t,value:r,syncUrl:n=!0,onChange:i,onVariantChange:o,className:p,style:l,optionClassName:h,optionLabelClassName:s,valueClassName:d,selectedValueClassName:a,unavailableValueClassName:b,swatchClassName:m}){let u=r!==void 0,[P,R]=vt(r??{}),I=u?r:P,[x,O]=vt(()=>new Set),v=y=>O(C=>C.has(y)?C:new Set(C).add(y));We(()=>{O(y=>y.size===0?y:new Set)},[e]);let f=St(!1);We(()=>{if(!n||u||f.current||e.length===0||typeof window>"u"||(f.current=!0,Object.keys(P).length>0))return;let y=Re({options:e},window.location.search);Object.keys(y).length!==0&&(R(y),i?.(y))},[n,u,e]);let c=nn(()=>e.length>0?t.filter(y=>y.option_values.length===e.length):t,[t,e]),g=St(void 0);if(We(()=>{let y=Z(c,I),C=y?.id??null;g.current!==C&&(g.current=C,o?.(y))},[c,I]),e.length===0)return null;let k=(y,C)=>{let _=Pe(c,I,y,C);u||(R(_),n&&Ie({options:e},_)),i?.(_)};return ne("div",{className:p,style:l,children:e.map(y=>kt("div",{className:h,style:h?void 0:rn,children:[ne("span",{className:s,style:s?void 0:on,children:y.title}),ne("div",{style:an,children:y.values.map(C=>{let _=I[y.id]===C.id,w=we(c,I,y.id,C.id),T=w||_e(c,y.id,C.id),V=[d,_?a:void 0,w?void 0:b].filter(Boolean).join(" ")||void 0,$=C.swatch??null,E=$&&!x.has($)?$:null,S=E?dn(E):!1,L=d?void 0:{...sn,..._?un:{},...w?{}:T?cn:wt,...E?{...fn,textDecoration:"none"}:{}},U=w?C.value:`${C.value} \u2014 unavailable with your current selection`;return ne("button",{type:"button",className:V,style:L,disabled:!T,"aria-pressed":_,"aria-label":E?U:void 0,title:E?U:void 0,"data-selected":_?"true":void 0,"data-available":w?"true":"false","data-swatch":E?S?"hex":"image":void 0,onClick:()=>k(y.id,C.id),children:E?kt(yn,{children:[ne("span",{"aria-hidden":"true",className:m,style:m?void 0:{...pn,...S?{background:E}:{},...S&&w?{}:{backgroundImage:[...w?[]:[mn],...S?[]:[`url(${JSON.stringify(E)})`]].join(", ")}}}),S?null:ne("img",{src:E,alt:"","aria-hidden":"true",referrerPolicy:"no-referrer",style:{display:"none"},onError:()=>v(E)})]}):C.value},C.id)})})]},y.id))})}import{useEffect as hn}from"react";import{Fragment as Ke,jsx as X,jsxs as le}from"react/jsx-runtime";var bn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Cn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function _t(){return le("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[X("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),X("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:X("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Sn({productId:e,variantId:t,quantity:r,amount:n,metadata:i,successUrl:o,cancelUrl:p,customerEmail:l,apiUrl:h,disabled:s,className:d,style:a,errorClassName:b,spinner:m=!0,children:u}){let{product:P,loading:R,error:I,refresh:x}=Q(e,{apiUrl:h}),{startCheckout:O,loading:v,error:f,priceChange:c}=Ne({apiUrl:h});hn(()=>{c&&x()},[c,x]);let g=P!==null&&!P.payments_ready,k=P!==null&&!P.active,y=P!==null&&P.purchasable===!1,C=P!==null&&oe(P),_=P!==null?H(P):[],w=t!==void 0?_.find(U=>U.id===t)??null:!C&&_.length===1?_[0]:null,T=C&&!w,V=w!==null&&!w.in_stock,$=!!s||R||!P||g||k||y||T||V||v,E;v?E=le(Ke,{children:[m&&X(_t,{}),"Processing\u2026"]}):R?E=le(Ke,{children:[m&&X(_t,{}),u??"Buy now"]}):g?E="Payments not set up":k||y?E="Unavailable":T?E="Select options":V?E="Out of stock":u!==void 0?E=u:E="Buy now";let S=f??I;return le(Ke,{children:[X("button",{type:"button",className:d,style:a,disabled:$,onClick:()=>{let U=n===void 0&&N()===null&&w!==null&&!w.allow_custom_amount&&typeof w.unit_amount=="number"?{expectedUnitAmount:w.unit_amount,expectedCurrency:w.currency}:{};O({productId:e,variantId:t,quantity:r,amount:n,metadata:i,successUrl:o,cancelUrl:p,customerEmail:l,...U})},children:E}),S&&le("div",{role:"alert",className:b,style:b?void 0:bn,children:[S,P===null&&!R&&I!==null&&X("button",{type:"button",onClick:x,style:Cn,children:"Tap to retry"})]})]})}import{useEffect as vn,useRef as kn,useState as Pt}from"react";import{Fragment as xt,jsx as re,jsxs as Se}from"react/jsx-runtime";var wn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},_n={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Pn=1500;function xn(){return Se("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[re("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),re("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:re("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Rn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function In({productId:e,variantId:t,selection:r,quantity:n,apiUrl:i,disabled:o,className:p,style:l,errorClassName:h,spinner:s=!0,children:d}){let{product:a,loading:b,error:m,refresh:u}=Q(e,{apiUrl:i}),{add:P}=W(),[R,I]=Pt(!1),[x,O]=Pt(!1),v=kn(void 0);vn(()=>()=>{v.current&&clearTimeout(v.current)},[]);let f=a!==null&&!a.payments_ready,c=a!==null&&!a.active,g=a!==null&&a.purchasable===!1,k=a!==null&&!b&&H(a).length===0,y=a!==null&&a.allow_custom_amount,C=a!==null&&oe(a),_=a!==null?H(a):[],w=t!==void 0?_.find(q=>q.id===t)??null:r!==void 0&&C?Z(_,r):!C&&_.length===1?_[0]:null,T=a!==null&&!k&&!w,V=w!==null&&!w.in_stock,$=!!o||b||!a||f||c||g||k||y||T||V,E=()=>{if(!a||!w)return;let q=r??Rn(w);if(!P({productId:e,variantId:w.id,quantity:n,selection:q,display:{name:a.name,variantTitle:w.title,image:ae(a,q)[0]??null}}).ok){I(!0);return}I(!1),O(!0),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>O(!1),Pn)},S;b?S=Se(xt,{children:[s&&re(xn,{}),d??"Add to cart"]}):f?S="Payments not set up":c||g||k||y?S="Unavailable":T?S="Select options":V?S="Out of stock":x?S="Added to cart":d!==void 0?S=d:S="Add to cart";let L=R?"Your cart is full \u2014 remove an item before adding another.":m;return Se(xt,{children:[re("button",{type:"button",className:p,style:l,disabled:$,"data-added":x?"true":void 0,onClick:E,children:S}),L&&Se("div",{role:"alert",className:h,style:h?void 0:wn,children:[L,a===null&&!b&&m!==null&&!R&&re("button",{type:"button",onClick:u,style:_n,children:"Tap to retry"})]})]})}import{Fragment as He,jsx as J,jsxs as ve}from"react/jsx-runtime";var Rt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function It(){return ve("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[J("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),J("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:J("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function On({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:i,shippingOption:o,disabled:p,className:l,style:h,errorClassName:s,spinner:d=!0,children:a}){let{items:b,hydrated:m}=W(),{lines:u}=Be({apiUrl:e}),{startCheckout:P,loading:R,error:I,conflicts:x}=$e({apiUrl:e}),O=m&&b.length===0,v=u.some(k=>k.status==="unavailable"),f=!!p||!m||O||v||R,c;R?c=ve(He,{children:[d&&J(It,{}),"Processing\u2026"]}):m?O?c="Cart is empty":v?c="Remove unavailable items":a!==void 0?c=a:c="Checkout":c=ve(He,{children:[d&&J(It,{}),a??"Checkout"]});let g=x?Object.keys(x).length:0;return ve(He,{children:[J("button",{type:"button",className:l,style:h,disabled:f,onClick:()=>P(u,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:i,shippingOption:o}),children:c}),g>0&&J("div",{role:"alert",className:s,style:s?void 0:Rt,children:g===1?"An item in your cart changed \u2014 please review your cart and try again.":`${g} items in your cart changed \u2014 please review your cart and try again.`}),I&&J("div",{role:"alert",className:s,style:s?void 0:Rt,children:I})]})}import{useEffect as ke,useRef as Ot,useState as Ye}from"react";import{Fragment as de,jsx as A,jsxs as G}from"react/jsx-runtime";var Je="af_order_confirmation_session",Tn=1800*1e3;function Ln({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:i=2e3,pollTimeoutMs:o=6e4,followRedirect:p=!0,redirectDelayMs:l=1500,renderNoSession:h,renderPending:s,renderPaid:d,renderFailed:a}){let[b,m]=Ye(n),[u,P]=Ye(null),[R,I]=Ye(!1),x=Ot(void 0);ke(()=>{if(n!==void 0){m(n);return}if(x.current!==void 0){m(x.current);return}let c=new URL(window.location.href),g=c.searchParams.get("session_id");if(g){c.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",c.toString());try{sessionStorage.setItem(Je,JSON.stringify({id:g,ts:Date.now()}))}catch{}}else try{let k=sessionStorage.getItem(Je);if(k){let y=JSON.parse(k);typeof y.id=="string"&&typeof y.ts=="number"&&Date.now()-y.ts<=Tn?g=y.id:sessionStorage.removeItem(Je)}}catch{}x.current=g,m(g)},[n]),ke(()=>{if(!b)return;let c=!1,g,k=Date.now(),y=async()=>{try{let C=await fetch(`${e}/v1/o/session/${encodeURIComponent(b)}`);if(C.ok){let _=await C.json();if(c||(P(_),_.status!=="pending"))return}}catch{}if(!c){if(Date.now()-k>=o){I(!0);return}g=setTimeout(y,i)}};return y(),()=>{c=!0,g&&clearTimeout(g)}},[b,e,i,o]);let O=u!==null&&(u.status==="paid"||u.status==="partially_refunded"),v=Ot(!1);ke(()=>{if(!b||u===null||v.current||!(u.status==="paid"||u.status==="partially_refunded"||u.is_test===!0)||(v.current=!0,!st(b)))return;let g=(u.line_items??[]).filter(k=>typeof k.variant_id=="string"&&k.variant_id.length>0).map(k=>({variantId:k.variant_id,quantity:k.quantity}));g.length>0&&ot(g)},[b,u]);let f=O&&u.fulfillment.type==="redirect"?u.fulfillment.redirect_url:void 0;if(ke(()=>{if(!f||!p)return;let c=setTimeout(()=>{window.location.href=f},l);return()=>clearTimeout(c)},[f,p,l]),b===void 0)return null;if(b===null)return h?A(de,{children:h()}):G("div",{className:t,style:r,children:[A("h2",{children:"Thank you for your order!"}),A("p",{children:"If you completed a payment, a confirmation email with your receipt and any download links is on its way to you. This page can only show live order details right after checkout."})]});if(!u||u.status==="pending")return s?A(de,{children:s({timedOut:R})}):A("div",{className:t,style:r,role:"status",children:A("p",{children:R?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(O){if(d)return A(de,{children:d(u)});let{fulfillment:c}=u,g=u.amount_total!==void 0&&u.currency?D(u.amount_total,u.currency):null,k=c.files??[],y=k.length===0?c.download_url:void 0;return G("div",{className:t,style:r,children:[A("h2",{children:"Thank you for your purchase!"}),u.is_test&&G("p",{children:[A("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),u.line_items&&u.line_items.length>0&&A("ul",{children:u.line_items.map((C,_)=>G("li",{children:[C.quantity>1?`${C.quantity} \xD7 `:"",C.name,C.refunded&&A("em",{children:C.refund_reason==="oversold"?" \u2014 sold out and refunded; check your email for details":" \u2014 refunded"})]},_))}),g&&G("p",{children:["Total paid: ",g]}),k.length>0&&G(de,{children:[A("p",{children:"Your downloads:"}),A("ul",{children:k.map((C,_)=>A("li",{children:A("a",{href:C.download_url,children:C.name})},_))})]}),y&&A("p",{children:A("a",{href:y,children:"Download your file"})}),f?G("p",{children:["Taking you to your content\u2026"," ",A("a",{href:f,children:"Continue if you are not redirected"})]}):c.redirect_url?A("p",{children:A("a",{href:c.redirect_url,children:"Continue to your content"})}):null,k.length===0&&!y&&!c.redirect_url&&A("p",{children:"A confirmation email is on its way to you."}),u.order_id&&G("p",{children:["Order reference: ",A("code",{children:u.order_id})," \u2014 keep this if you ever need help with your order."]})]})}return a?A(de,{children:a(u)}):A("div",{className:t,style:r,children:A("p",{children:"We couldn't confirm your payment. If you were charged, you'll receive an email confirmation \u2014 otherwise you can safely try again."})})}export{In as AddToCartButton,Et as AifeaturesCaptcha,Sn as BuyButton,On as CartCheckoutButton,je as MARKET_COUNTRIES,ft as MAX_CART_LINES,Ln as OrderConfirmation,en as ProductPrice,gn as VariantPicker,et as ZERO_DECIMAL_CURRENCIES,Ie as applySelectionToUrl,D as formatPrice,ee as getOptions,H as getVariants,oe as isMultiVariant,we as isValueAvailable,_e as isValueInCatalog,Pe as reanchorSelection,Z as resolveVariant,ge as searchFromSelection,ae as selectedImages,tt as selectedValues,Re as selectionFromSearch,W as useCart,$e as useCartCheckout,Be as useCartItems,Yt as useCartSummary,Ne as useCheckout,Zt as useMarket,Q as useProduct,z as valueSlug,xe as variantPriceRange};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aifeatures/react",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "React components for aifeatures sites: form CAPTCHA (Cloudflare Turnstile) and headless payments (product price, buy button, order confirmation)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",