@aifeatures/react 0.2.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 +1 -67
- package/dist/index.d.cts +1243 -1
- package/dist/index.d.ts +1243 -1
- package/dist/index.js +1 -41
- package/package.json +11 -11
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,42 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
// src/AifeaturesCaptcha.tsx
|
|
4
|
-
import { useState, useEffect } from "react";
|
|
5
|
-
import { Turnstile } from "@marsidev/react-turnstile";
|
|
6
|
-
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
function AifeaturesCaptcha({
|
|
8
|
-
formId,
|
|
9
|
-
apiUrl = "https://aifeatures.dev",
|
|
10
|
-
onVerify,
|
|
11
|
-
onError,
|
|
12
|
-
className
|
|
13
|
-
}) {
|
|
14
|
-
const [sitekey, setSitekey] = useState(null);
|
|
15
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
setIsLoading(true);
|
|
18
|
-
fetch(`${apiUrl}/f/${formId}/config`).then((r) => r.json()).then((config) => {
|
|
19
|
-
setSitekey(config.turnstile_sitekey);
|
|
20
|
-
setIsLoading(false);
|
|
21
|
-
}).catch(() => {
|
|
22
|
-
setIsLoading(false);
|
|
23
|
-
});
|
|
24
|
-
}, [formId, apiUrl]);
|
|
25
|
-
if (isLoading || !sitekey) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(
|
|
29
|
-
Turnstile,
|
|
30
|
-
{
|
|
31
|
-
siteKey: sitekey,
|
|
32
|
-
onSuccess: onVerify,
|
|
33
|
-
onError,
|
|
34
|
-
onExpire: onError,
|
|
35
|
-
options: { theme: "light" }
|
|
36
|
-
}
|
|
37
|
-
) });
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
AifeaturesCaptcha
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=index.js.map
|
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aifeatures/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "React
|
|
3
|
+
"version": "0.3.1",
|
|
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",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -21,14 +21,6 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "tsup",
|
|
26
|
-
"dev": "tsup --watch",
|
|
27
|
-
"lint": "eslint src/",
|
|
28
|
-
"typecheck": "tsc --noEmit",
|
|
29
|
-
"storybook": "storybook dev -p 6007",
|
|
30
|
-
"build-storybook": "storybook build"
|
|
31
|
-
},
|
|
32
24
|
"peerDependencies": {
|
|
33
25
|
"react": ">=18",
|
|
34
26
|
"react-dom": ">=18"
|
|
@@ -58,5 +50,13 @@
|
|
|
58
50
|
"workerDirectory": [
|
|
59
51
|
".storybook/public"
|
|
60
52
|
]
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsup",
|
|
56
|
+
"dev": "tsup --watch",
|
|
57
|
+
"lint": "eslint src/",
|
|
58
|
+
"typecheck": "tsc --noEmit",
|
|
59
|
+
"storybook": "storybook dev -p 6007",
|
|
60
|
+
"build-storybook": "storybook build"
|
|
61
61
|
}
|
|
62
|
-
}
|
|
62
|
+
}
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/AifeaturesCaptcha.tsx"],"sourcesContent":["export { AifeaturesCaptcha } from './AifeaturesCaptcha';\nexport type { AifeaturesCaptchaProps } from './AifeaturesCaptcha';\n","import { useState, useEffect } from 'react';\nimport { Turnstile } from '@marsidev/react-turnstile';\n\nexport interface AifeaturesCaptchaProps {\n /** Form ID from aifeatures - used to fetch the Turnstile sitekey */\n formId: string;\n /** Base URL for the aifeatures API (defaults to https://aifeatures.dev) */\n apiUrl?: string;\n /** Called when CAPTCHA verification succeeds */\n onVerify?: (token: string) => void;\n /** Called when CAPTCHA verification fails or expires */\n onError?: () => void;\n /** Additional class name for the container */\n className?: string;\n}\n\ninterface FormConfig {\n id: string;\n name: string;\n endpoint_url: string;\n turnstile_sitekey: string | null;\n}\n\n/**\n * A CAPTCHA component that handles Turnstile verification for aifeatures forms.\n *\n * Drop this into any form to add CAPTCHA protection. The Turnstile widget\n * automatically adds a hidden `cf-turnstile-response` input to the form.\n *\n * @example\n * ```tsx\n * <form action={`https://aifeatures.dev/f/${formId}`} method=\"POST\">\n * <input name=\"email\" type=\"email\" required />\n * <textarea name=\"message\" />\n * <AifeaturesCaptcha formId={formId} />\n * <button type=\"submit\">Send</button>\n * </form>\n * ```\n */\nexport function AifeaturesCaptcha({\n formId,\n apiUrl = 'https://aifeatures.dev',\n onVerify,\n onError,\n className,\n}: AifeaturesCaptchaProps) {\n const [sitekey, setSitekey] = useState<string | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n setIsLoading(true);\n fetch(`${apiUrl}/f/${formId}/config`)\n .then((r) => r.json())\n .then((config: FormConfig) => {\n setSitekey(config.turnstile_sitekey);\n setIsLoading(false);\n })\n .catch(() => {\n setIsLoading(false);\n });\n }, [formId, apiUrl]);\n\n if (isLoading || !sitekey) {\n return null;\n }\n\n return (\n <div className={className}>\n <Turnstile\n siteKey={sitekey}\n onSuccess={onVerify}\n onError={onError}\n onExpire={onError}\n options={{ theme: 'light' }}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAoC;AACpC,6BAA0B;AAmEpB;AA7BC,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AACF,GAA2B;AACzB,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAwB,IAAI;AAC1D,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,IAAI;AAE/C,8BAAU,MAAM;AACd,iBAAa,IAAI;AACjB,UAAM,GAAG,MAAM,MAAM,MAAM,SAAS,EACjC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,EACpB,KAAK,CAAC,WAAuB;AAC5B,iBAAW,OAAO,iBAAiB;AACnC,mBAAa,KAAK;AAAA,IACpB,CAAC,EACA,MAAM,MAAM;AACX,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,QAAQ,MAAM,CAAC;AAEnB,MAAI,aAAa,CAAC,SAAS;AACzB,WAAO;AAAA,EACT;AAEA,SACE,4CAAC,SAAI,WACH;AAAA,IAAC;AAAA;AAAA,MACC,SAAS;AAAA,MACT,WAAW;AAAA,MACX;AAAA,MACA,UAAU;AAAA,MACV,SAAS,EAAE,OAAO,QAAQ;AAAA;AAAA,EAC5B,GACF;AAEJ;","names":[]}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/AifeaturesCaptcha.tsx"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { Turnstile } from '@marsidev/react-turnstile';\n\nexport interface AifeaturesCaptchaProps {\n /** Form ID from aifeatures - used to fetch the Turnstile sitekey */\n formId: string;\n /** Base URL for the aifeatures API (defaults to https://aifeatures.dev) */\n apiUrl?: string;\n /** Called when CAPTCHA verification succeeds */\n onVerify?: (token: string) => void;\n /** Called when CAPTCHA verification fails or expires */\n onError?: () => void;\n /** Additional class name for the container */\n className?: string;\n}\n\ninterface FormConfig {\n id: string;\n name: string;\n endpoint_url: string;\n turnstile_sitekey: string | null;\n}\n\n/**\n * A CAPTCHA component that handles Turnstile verification for aifeatures forms.\n *\n * Drop this into any form to add CAPTCHA protection. The Turnstile widget\n * automatically adds a hidden `cf-turnstile-response` input to the form.\n *\n * @example\n * ```tsx\n * <form action={`https://aifeatures.dev/f/${formId}`} method=\"POST\">\n * <input name=\"email\" type=\"email\" required />\n * <textarea name=\"message\" />\n * <AifeaturesCaptcha formId={formId} />\n * <button type=\"submit\">Send</button>\n * </form>\n * ```\n */\nexport function AifeaturesCaptcha({\n formId,\n apiUrl = 'https://aifeatures.dev',\n onVerify,\n onError,\n className,\n}: AifeaturesCaptchaProps) {\n const [sitekey, setSitekey] = useState<string | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n setIsLoading(true);\n fetch(`${apiUrl}/f/${formId}/config`)\n .then((r) => r.json())\n .then((config: FormConfig) => {\n setSitekey(config.turnstile_sitekey);\n setIsLoading(false);\n })\n .catch(() => {\n setIsLoading(false);\n });\n }, [formId, apiUrl]);\n\n if (isLoading || !sitekey) {\n return null;\n }\n\n return (\n <div className={className}>\n <Turnstile\n siteKey={sitekey}\n onSuccess={onVerify}\n onError={onError}\n onExpire={onError}\n options={{ theme: 'light' }}\n />\n </div>\n );\n}\n"],"mappings":";;;AAAA,SAAS,UAAU,iBAAiB;AACpC,SAAS,iBAAiB;AAmEpB;AA7BC,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AACF,GAA2B;AACzB,QAAM,CAAC,SAAS,UAAU,IAAI,SAAwB,IAAI;AAC1D,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,IAAI;AAE/C,YAAU,MAAM;AACd,iBAAa,IAAI;AACjB,UAAM,GAAG,MAAM,MAAM,MAAM,SAAS,EACjC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,EACpB,KAAK,CAAC,WAAuB;AAC5B,iBAAW,OAAO,iBAAiB;AACnC,mBAAa,KAAK;AAAA,IACpB,CAAC,EACA,MAAM,MAAM;AACX,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,QAAQ,MAAM,CAAC;AAEnB,MAAI,aAAa,CAAC,SAAS;AACzB,WAAO;AAAA,EACT;AAEA,SACE,oBAAC,SAAI,WACH;AAAA,IAAC;AAAA;AAAA,MACC,SAAS;AAAA,MACT,WAAW;AAAA,MACX;AAAA,MACA,UAAU;AAAA,MACV,SAAS,EAAE,OAAO,QAAQ;AAAA;AAAA,EAC5B,GACF;AAEJ;","names":[]}
|