@elevateab/sdk 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/next.cjs CHANGED
@@ -43,5 +43,5 @@
43
43
  if(window.__eab_reveal)window.__eab_reveal();
44
44
  };
45
45
  document.head.appendChild(script);
46
- })();`}function xr(e){if(!e?.trim())return"";try{let n=`https://${e.trim().replace(/^https?:\/\//,"")}`,o=new URL(n.replace(/\/+$/,""));return o.hostname.startsWith("www.")&&(o.hostname=o.hostname.substring(4)),o.toString().replace(/\/+$/,"")}catch{return e.trim().replace(/\/+$/,"")}}function Ot(e,t){let n=xr(e.split("?")[0]);for(let o of t){let r=xr(o.split("?")[0]);if(n===r)return!0;try{let c=new URL(e).pathname,u=new URL(o,e).pathname;if(c===u)return!0}catch{}}return!1}function gn(e){return e.data?.redirectBehavior||"redirectAll"}function Tr(e){return!!(V("eabRedirectedTests")||{})[e]}function Pr(e){let t=V("eabRedirectedTests")||{};t[e]=!0,L("eabRedirectedTests",JSON.stringify(t))}function wn(e,t){for(let n of e.tests)if(!(n.type!=="SPLIT_URL"||!n.enabled))for(let o of n.variations){let r=o.splitUrlTestLinks||[];if(r.length!==0&&Ot(t,r))return{test:n,matchedVariation:o,isControlUrl:!!o.isControl}}return null}function bn(e){if(typeof window>"u")return;let t=new URL(e,window.location.origin);t.searchParams.set("abtr","true");let n=t.toString(),o=window.__remixRouter?.navigate??window.next?.router?.push??window.$nuxt?.$router?.push??window.__navigate;if(o&&typeof o=="function")try{let r=t.pathname+t.search;o(r);return}catch{}window.location.href=n}function We(e,t){if(typeof window>"u")return!1;let n=window.location.href;if(new URLSearchParams(window.location.search).get("abtr")==="true")return!1;let r=wn(e,n);if(!r)return!1;let{test:c,matchedVariation:u,isControlUrl:f}=r,l=c.testId,m=gn(c),i=z(l);if(!i)return!1;let d=c.variations.find(p=>p.id===i);if(!d)return!1;let a=d.splitUrlTestLinks||[];if(a.length===0||Ot(n,a))return!1;switch(m){case"redirectOnlyControlUrl":if(!f||d.isControl)return!1;break;case"redirectOnce":if(Tr(l))return!1;Pr(l);break;case"redirectOnceControlUrlOnly":if(!f||Tr(l)||d.isControl)return!1;Pr(l);break;default:break}let s=a[0];return bn(s),!0}var Lt={type:"SPLIT_URL",shouldActivate(e,t){for(let n of e.variations){let o=n.splitUrlTestLinks||[];if(Ot(t.currentUrl,o))return!0}return!1},getVariantData(){return{handlerActivated:!0}}};G();var Er="elv-el-",Ar={ELEMENT_NODE:1,TEXT_NODE:3},Ge=new Map,Je=new Map,Ye=new Map,Qe=new Map,ce=!1;function j(e,t){if(t==="*")return!0;if(t.startsWith("*")&&t.endsWith("*")){let n=t.slice(1,-1);return e.includes(n)}if(t.startsWith("*")){let n=t.slice(1);return e.endsWith(n)}return t===e}function Mt(){return typeof window>"u"?!1:window.innerWidth<768}function hn(e){let t="";for(let n=0;n<e.length;n++){let o=e[n];o>="A"&&o<="Z"?(n!==0&&(t+="-"),t+=o.toLowerCase()):t+=o}return t}function yn(e){return e.nodeType===Ar.TEXT_NODE}function Bt(e){return e.nodeType===Ar.ELEMENT_NODE}function Dt(e,t){Ge.has(e)||Ge.set(e,t.cloneNode(!0))}function Sr(e){let t=e;t=t.replace(/&#96;/g,"`").replace(/&#36;/g,"$");try{t=JSON.parse('"'+t+'"')}catch{}return t}function Ir(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname,n=e.filter(r=>r.pathnames?.length?r.pathnames.some(c=>j(t,c)):!0);ce=Mt();let o=n.map(r=>({...r,style:r.style?{...r.style.lg,...ce&&r.style.sm}:void 0,content:r.content&&ce&&r.content.sm?r.content.sm:r.content?.lg}));o.filter(r=>r.content!==void 0).forEach(r=>{(r.applyAll?Array.from(document.querySelectorAll(r.selector)):[document.querySelector(r.selector)].filter(Boolean)).forEach((u,f)=>{if(!u)return;let l=r.applyAll?`${r.selector}-${f}-${u.id||Math.random().toString(36).substr(2,9)}`:r.selector;Dt(l,u),yn(u)?u.nodeValue=r.content:Bt(u)&&(u.innerHTML=r.content)})}),o.filter(r=>r.style!==void 0).forEach(r=>{let c=document.querySelector(r.selector);!c||!Bt(c)||(Dt(r.selector,c),Object.entries(r.style).forEach(([u,f])=>{let l=hn(u),m=f.toString().includes("!important"),i=f.toString().replace(/\s*!important\s*$/,"");c.style.setProperty(l,i,m?"important":void 0)}))}),o.filter(r=>r.attributes!==void 0).forEach(r=>{let c=document.querySelector(r.selector);!c||!Bt(c)||(Dt(r.selector,c),Object.entries(r.attributes).forEach(([u,f])=>{c.setAttribute(u,f)}))})}function Ur(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname;e.filter(o=>o.selector?.pathnames?.length?o.selector.pathnames.some(r=>j(t,r)):!0).forEach(o=>{let r=`${Er}${o.id}`;if(Qe.has(r))return;let c=document.querySelector(o.selector.target);if(!c||c.parentElement?.querySelector(`#${r}`))return;let u=Rr(o);o.selector.placement==="after"?c.after(u):o.selector.placement==="before"&&c.before(u),Qe.set(r,u)})}function Rr(e){let t=document.createElement(e.tagName);return t.id=`${Er}${e.id}`,e.style&&Object.assign(t.style,e.style),e.attributes&&Object.entries(e.attributes).forEach(([n,o])=>{t.setAttribute(n,o)}),e.kind==="text"&&e.content&&(t.innerText=e.content),e.kind==="container"&&e.childrens&&e.childrens.forEach(n=>{let o=Rr(n);t.appendChild(o)}),t}function Xe(e,t){if(typeof window>"u"||e.length===0)return;let n=window.location.pathname;e.filter(r=>r.pathnames?.length?r.excludePathnames?.length&&r.excludePathnames.some(u=>j(n,u))?!1:r.pathnames.some(c=>j(n,c)):!0).forEach(r=>{r.id&&(r.css&&vn(r.id,r.css),r.js&&_n(r.id,r.js,t))})}function vn(e,t){let n=`css-${e}`;if(Je.has(n)||document.getElementById(n))return;let o=document.createElement("style");o.id=n,o.textContent=Sr(t),document.head.appendChild(o),Je.set(n,o)}function _n(e,t,n){let o=`js-${e}`;if(Ye.has(o)||document.getElementById(o))return;let r=document.createElement("script");r.id=o,n&&r.setAttribute("nonce",n);let c=Sr(t);r.textContent="(function(){try{"+c+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(r),Ye.set(o,r)}function Vr(){Ge.forEach((e,t)=>{let n=document.querySelector(t);n&&n.replaceWith(e.cloneNode(!0))})}function Or(){Je.forEach(e=>e.remove()),Je.clear(),Ye.forEach(e=>e.remove()),Ye.clear(),Qe.forEach(e=>e.remove()),Qe.clear(),Ge.clear()}function kn(e,t){let n=[],o=[],r=[];return e.tests.filter(u=>u.type==="CONTENT"&&u.enabled).forEach(u=>{let f=z(u.testId);if(!f)return;let l=u.variations.find(m=>m.id===f);l?.content&&(l.content.changes?.length&&n.push(...l.content.changes),l.content.elements?.length&&o.push(...l.content.elements),l.content.customCodes?.length&&r.push(...l.content.customCodes))}),{changes:n,elements:o,blocks:[],customCodes:r}}function Ke(e){return e.tests.some(t=>t.type==="CONTENT"&&t.enabled)}function Ze(e,t,n){if(typeof window>"u"||!Ke(e))return;let o=kn(e,t);(o.changes.length>0||o.elements.length>0||o.customCodes.length>0)&&(Ir(o.changes),Ur(o.elements),Xe(o.customCodes,n))}function Nt(e,t,n){if(typeof window>"u")return;let o=Mt();o!==ce&&(Vr(),ce=o),Ze(e,t,n)}function Ht(e,t,n){if(typeof window>"u")return()=>{};let o=()=>{Mt()!==ce&&Nt(e,t,n)},r=()=>{Nt(e,t,n)};return window.addEventListener("resize",o),window.addEventListener("popstate",r),()=>{window.removeEventListener("resize",o),window.removeEventListener("popstate",r),Or()}}G();function zt(e){return e.tests.some(t=>t.type==="CUSTOM_CODE"&&t.enabled)}function qt(e,t,n){if(typeof window>"u")return;if(console.log("[ElevateAB Custom Code] All tests:",e.tests.map(c=>({id:c.testId,type:c.type,enabled:c.enabled}))),!zt(e)){console.log("[ElevateAB Custom Code] No CUSTOM_CODE tests found");return}let o=e.tests.filter(c=>c.type==="CUSTOM_CODE"&&c.enabled);console.log("[ElevateAB Custom Code] Found",o.length,"CUSTOM_CODE tests");let r=[];o.forEach(c=>{let u=z(c.testId);if(console.log("[ElevateAB Custom Code] Test",c.testId,"assigned variant:",u),!u)return;let f=c.variations.find(l=>l.id===u);if(console.log("[ElevateAB Custom Code] Variation data:",f),!f?.customCode){console.log("[ElevateAB Custom Code] No customCode on variation");return}(f.customCode.js||f.customCode.css)&&(console.log("[ElevateAB Custom Code] Adding custom code:",f.customCode),r.push(f.customCode))}),r.length>0?(console.log("[ElevateAB Custom Code] Applying",r.length,"custom code blocks"),Xe(r,n)):console.log("[ElevateAB Custom Code] No custom code to apply")}function Cn(e,t,n){typeof window>"u"||qt(e,t,n)}function Lr(e,t,n){if(typeof window>"u")return()=>{};let o=()=>{Cn(e,t,n)};return window.addEventListener("popstate",o),()=>{window.removeEventListener("popstate",o)}}G();var et=require("react/jsx-runtime"),xn="https://d19dz5bxptjmv5.cloudfront.net/headless";function Tn(e){return e.replace(/^https?:\/\//,"").replace(".myshopify.com","")}function Br(e){return`${xn}/${Tn(e)}.js`}function Ft({storeId:e,storefrontAccessToken:t,preventFlickering:n=!1,flickerTimeout:o=3e3,nonce:r,children:c}){let[u,f]=U.default.useState(null),[l,m]=U.default.useState(null),[i,d]=U.default.useState(null);U.default.useEffect(()=>{if(typeof window>"u")return;ye({storeId:e,storefrontAccessToken:t});let g=F();m(g);let w=X();d(w)},[e,t]);let a=(0,U.useCallback)(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);U.default.useEffect(()=>{async function g(){try{let w=typeof window<"u"?F():null,y=null;if(typeof window<"u"&&window.eab_data)y=window.eab_data;else{let $=Br(e);y=await new Promise((Z,W)=>{let N=document.createElement("script");N.src=$,N.async=!0,N.onload=()=>{let ue=window.eab_data;N.remove(),ue?Z(ue):W(new Error("Failed to load config: window.eab_data is undefined"))},N.onerror=()=>{N.remove(),Z({allTests:{},selectors:{selectorsV2:[]}})},document.head.appendChild(N)})}if(!y||!y.allTests||Object.keys(y.allTests).length===0){f({tests:[],selectors:void 0}),a();return}if(y.subscriptionPaused){console.error(`[ElevateAB] Subscription is paused or stopped for store: ${e}. `+(y.subscriptionMessage||"A/B tests will not run. Please reactivate your subscription.")),f({tests:[],selectors:void 0}),a();return}if(!(Object.keys(y.allTests||{}).length>0)){f({tests:[],selectors:void 0}),a();return}let D=ur(y);if(_t(D,w),D.tests.some($=>$.type==="SPLIT_URL")&&We(D,w))return;f(D),a()}catch(w){console.error("[ElevateAB] Failed to load config:",w),f({tests:[],selectors:void 0}),a()}}g()},[e,a]),U.default.useEffect(()=>!u||typeof window>"u"||!Ke(u)?void 0:(Ze(u,l,r),Ht(u,l,r)),[u,l,r]),U.default.useEffect(()=>!u||typeof window>"u"||!zt(u)?void 0:(qt(u,l,r),Lr(u,l,r)),[u,l,r]);let s=U.default.useMemo(()=>({config:u,storeId:e,storefrontAccessToken:t,isPreviewMode:l?.isPreview??!1,previewTestId:l?.previewTestId??null,previewState:l,selectors:u?.selectors,countryCode:i}),[u,e,t,l,i]),p=(0,U.useRef)(!1);U.default.useEffect(()=>{!t&&!p.current&&(p.current=!0,console.warn("[ElevateAB] No storefrontAccessToken provided. Orders won't be attributed to test variants."))},[t]);let _=U.default.useMemo(()=>Br(e),[e]),k=U.default.useMemo(()=>Vt({configUrl:_,timeout:n?o:2e3}),[_,n,o]);return(0,et.jsxs)(Ve.Provider,{value:s,children:[(0,et.jsx)("script",{nonce:r,dangerouslySetInnerHTML:{__html:k}}),c]})}var tt=require("next/navigation");var ke=require("react/jsx-runtime");function Pn({currency:e}){let t=(0,tt.usePathname)(),n=(0,tt.useSearchParams)();return(0,Ce.useEffect)(()=>{n.get("eabUserPreview")!=="true"&&ve({currency:e})},[t,n,e]),null}function Dr({storeId:e,storefrontAccessToken:t,preventFlickering:n=!1,flickerTimeout:o=3e3,currency:r,children:c}){return(0,Ce.useEffect)(()=>{ye({storeId:e,storefrontAccessToken:t})},[e,t]),(0,ke.jsxs)(Ft,{storeId:e,storefrontAccessToken:t,preventFlickering:n,flickerTimeout:o,children:[(0,ke.jsx)(Ce.Suspense,{fallback:null,children:(0,ke.jsx)(Pn,{currency:r})}),c]})}var Nr=require("react");function Mr({productId:e,productVendor:t,productPrice:n,productSku:o,currency:r}){return(0,Nr.useEffect)(()=>{e&&_e({productId:e,productVendor:t,productPrice:n,productSku:o,currency:r})},[e,t,n,o,r]),null}Oe();B();G();B();function Hr(e){let t=V("ABAU")||{};t[e]||(t[e]=!0,L("ABAU",JSON.stringify(t)))}function zr(e){let t=bt("ABAV")||{};t[e]||(t[e]=!0,ae("ABAV",t))}function jt(e){Hr(e),zr(e)}he();je();kt();var K=Re(require("react"),1);G();he();var qr=new Map;function re(e){qr.set(e.type,e)}function rt(e){return qr.get(e)}function En(e){try{let o=new URL(e,"https://example.com").pathname.match(/\/products\/([^\/\?]+)/);return o?o[1]:null}catch{return null}}function An(e,t,n,o){if(typeof window>"u"||!e.prices||!t)return;let r=e.prices[t];if(!r)return;let c=r.price?.[n],u=r.compare?.[n],f=o;if(f?.selectorsV2?.length)for(let l of f.selectorsV2){if(l.price&&c){let m=l.price.replace("{{variant}}",t);document.querySelectorAll(m).forEach(d=>{let a=new Intl.NumberFormat("en-US",{style:"currency",currency:n}).format(parseFloat(c));d.textContent=a})}if(l.compareAt&&u){let m=l.compareAt.replace("{{variant}}",t);document.querySelectorAll(m).forEach(d=>{let a=new Intl.NumberFormat("en-US",{style:"currency",currency:n}).format(parseFloat(u));d.textContent=a})}if(l.saving&&c&&u)for(let m of l.saving){let i=m.selector.replace("{{variant}}",t);document.querySelectorAll(i).forEach(a=>{let s=parseFloat(c),p=parseFloat(u),_=p-s;if(m.isPercentage){let k=Math.round(_/p*100);a.textContent=`${k}%`}else{let k=new Intl.NumberFormat("en-US",{style:"currency",currency:n}).format(_);a.textContent=k}})}}}var $t={type:"PRICE_PLUS",shouldActivate(e,t){let n=e.data;if(!n)return!1;let{productId:o,productHandle:r}=t,c=r||En(t.currentUrl),u=o&&n.productIds?.includes(o),f=c&&n.handles?.includes(c);return u||f},applyEffect(e,t,n){An(t,n.variantId,n.currencyCode||"USD",n.selectors)},getVariantData(e,t,n){let o=e.data;return{prices:t.prices,matchedProductId:n.productId,productIds:o?.productIds,handles:o?.handles,handlerActivated:!0}}};function Sn(e,t){let o=e.data?.pathnames||[];if(!o.length)return!0;try{let c=new URL(t,"https://example.com").pathname;return o.some(u=>j(c,u))}catch{return!1}}var nt={type:"CONTENT",shouldActivate(e,t){return Sn(e,t.currentUrl)},getVariantData(e,t,n){let o=e.data;return{content:t.content,pathnames:o?.pathnames,handlerActivated:!0}}};function In(e,t){let o=e.data?.pathnames||[];if(!o.length)return!0;try{let c=new URL(t,"https://example.com").pathname;return o.some(u=>j(c,u))}catch{return!1}}var Wt={type:"CUSTOM_CODE",shouldActivate(e,t){return In(e,t.currentUrl)},getVariantData(e,t,n){let o=e.data;return{customCode:t.customCode,pathnames:o?.pathnames,excludePathnames:o?.excludePathnames,handlerActivated:!0}}};re($t);re(Lt);re(nt);re(Wt);function Vn(e){if(typeof window>"u")return{currentUrl:"",selectors:e};let t=window.location.href,n=window.location.pathname,o,r=n.match(/\/products\/([^\/\?]+)/);r&&(o=r[1]);let c,f=new URLSearchParams(window.location.search).get("variant");return f&&(c=f),{currentUrl:t,productHandle:o,variantId:c,selectors:e,currencyCode:"USD"}}function Gt(e){let{config:t,previewState:n,selectors:o}=we(),[r,c]=K.default.useState(null),[u,f]=K.default.useState(!0),l=K.default.useMemo(()=>t&&t.tests.find(a=>a.testId===e)||null,[t,e]),m=K.default.useMemo(()=>n||F(),[n]),i=K.default.useRef(null),d=K.default.useRef(null);return K.default.useEffect(()=>{let a=!0;if(t===null)return;if(!l){i.current!==e&&(i.current=e,console.warn(`[ElevateAB] Test not found: ${e}`)),a&&f(!1);return}if(!l.enabled&&!m?.isPreview){i.current!==`${e}-disabled`&&(i.current=`${e}-disabled`,console.warn(`[ElevateAB] Test disabled: ${e}`)),a&&f(!1);return}let s=z(e);if(!s){a&&f(!1);return}let p=l.variations.find(w=>w.id===s);if(!p){a&&f(!1);return}let _=rt(l.type),k=Vn(o),g={...p};if(_?.shouldActivate(l,k)){let w=`${e}-${p.id}`;_.applyEffect&&d.current!==w&&(d.current=w,_.applyEffect(l,p,k));let y=_.getVariantData(l,p,k);g={...g,...y}}return a&&c(g),m?.isPreview||jt(e),a&&f(!1),()=>{a=!1}},[t,l,e,m,o]),{variant:r,isLoading:u,isControl:r?.isControl??!1,isA:r?.isA??!1,isB:r?.isB??!1,isC:r?.isC??!1,isD:r?.isD??!1}}var Jt=require("react");B();B();je();0&&(module.exports={ElevateNextProvider,ProductViewTracker,clearPreviewMode,extractShopifyId,extractShopifyType,getCountryCode,getPreviewState,isInPreviewMode,isShopifyGid,matchesGeoTargeting,trackAddToCart,trackCartView,trackCheckoutCompleted,trackCheckoutStarted,trackPageView,trackProductView,trackRemoveFromCart,trackSearchSubmitted,useElevateConfig,useExperiment});
46
+ })();`}function xr(e){if(!e?.trim())return"";try{let n=`https://${e.trim().replace(/^https?:\/\//,"")}`,o=new URL(n.replace(/\/+$/,""));return o.hostname.startsWith("www.")&&(o.hostname=o.hostname.substring(4)),o.toString().replace(/\/+$/,"")}catch{return e.trim().replace(/\/+$/,"")}}function Ot(e,t){let n=xr(e.split("?")[0]);for(let o of t){let r=xr(o.split("?")[0]);if(n===r)return!0;try{let c=new URL(e).pathname,u=new URL(o,e).pathname;if(c===u)return!0}catch{}}return!1}function gn(e){return e.data?.redirectBehavior||"redirectAll"}function Tr(e){return!!(V("eabRedirectedTests")||{})[e]}function Pr(e){let t=V("eabRedirectedTests")||{};t[e]=!0,L("eabRedirectedTests",JSON.stringify(t))}function wn(e,t){for(let n of e.tests)if(!(n.type!=="SPLIT_URL"||!n.enabled))for(let o of n.variations){let r=o.splitUrlTestLinks||[];if(r.length!==0&&Ot(t,r))return{test:n,matchedVariation:o,isControlUrl:!!o.isControl}}return null}function bn(e){if(typeof window>"u")return;let t=new URL(e,window.location.origin);t.searchParams.set("abtr","true");let n=t.toString(),o=window.__remixRouter?.navigate??window.next?.router?.push??window.$nuxt?.$router?.push??window.__navigate;if(o&&typeof o=="function")try{let r=t.pathname+t.search;o(r);return}catch{}window.location.href=n}function We(e,t){if(typeof window>"u")return!1;let n=window.location.href;if(new URLSearchParams(window.location.search).get("abtr")==="true")return!1;let r=wn(e,n);if(!r)return!1;let{test:c,matchedVariation:u,isControlUrl:f}=r,l=c.testId,m=gn(c),i=z(l);if(!i)return!1;let d=c.variations.find(p=>p.id===i);if(!d)return!1;let a=d.splitUrlTestLinks||[];if(a.length===0||Ot(n,a))return!1;switch(m){case"redirectOnlyControlUrl":if(!f||d.isControl)return!1;break;case"redirectOnce":if(Tr(l))return!1;Pr(l);break;case"redirectOnceControlUrlOnly":if(!f||Tr(l)||d.isControl)return!1;Pr(l);break;default:break}let s=a[0];return bn(s),!0}var Lt={type:"SPLIT_URL",shouldActivate(e,t){for(let n of e.variations){let o=n.splitUrlTestLinks||[];if(Ot(t.currentUrl,o))return!0}return!1},getVariantData(){return{handlerActivated:!0}}};G();var Er="elv-el-",Ar={ELEMENT_NODE:1,TEXT_NODE:3},Ge=new Map,Je=new Map,Ye=new Map,Qe=new Map,ce=!1;function j(e,t){if(t==="*")return!0;if(t.startsWith("*")&&t.endsWith("*")){let n=t.slice(1,-1);return e.includes(n)}if(t.startsWith("*")){let n=t.slice(1);return e.endsWith(n)}return t===e}function Mt(){return typeof window>"u"?!1:window.innerWidth<768}function hn(e){let t="";for(let n=0;n<e.length;n++){let o=e[n];o>="A"&&o<="Z"?(n!==0&&(t+="-"),t+=o.toLowerCase()):t+=o}return t}function yn(e){return e.nodeType===Ar.TEXT_NODE}function Bt(e){return e.nodeType===Ar.ELEMENT_NODE}function Dt(e,t){Ge.has(e)||Ge.set(e,t.cloneNode(!0))}function Sr(e){let t=e;t=t.replace(/&#96;/g,"`").replace(/&#36;/g,"$");try{t=JSON.parse('"'+t+'"')}catch{}return t}function Ir(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname,n=e.filter(r=>r.pathnames?.length?r.pathnames.some(c=>j(t,c)):!0);ce=Mt();let o=n.map(r=>({...r,style:r.style?{...r.style.lg,...ce&&r.style.sm}:void 0,content:r.content&&ce&&r.content.sm?r.content.sm:r.content?.lg}));o.filter(r=>r.content!==void 0).forEach(r=>{(r.applyAll?Array.from(document.querySelectorAll(r.selector)):[document.querySelector(r.selector)].filter(Boolean)).forEach((u,f)=>{if(!u)return;let l=r.applyAll?`${r.selector}-${f}-${u.id||Math.random().toString(36).substr(2,9)}`:r.selector;Dt(l,u),yn(u)?u.nodeValue=r.content:Bt(u)&&(u.innerHTML=r.content)})}),o.filter(r=>r.style!==void 0).forEach(r=>{let c=document.querySelector(r.selector);!c||!Bt(c)||(Dt(r.selector,c),Object.entries(r.style).forEach(([u,f])=>{let l=hn(u),m=f.toString().includes("!important"),i=f.toString().replace(/\s*!important\s*$/,"");c.style.setProperty(l,i,m?"important":void 0)}))}),o.filter(r=>r.attributes!==void 0).forEach(r=>{let c=document.querySelector(r.selector);!c||!Bt(c)||(Dt(r.selector,c),Object.entries(r.attributes).forEach(([u,f])=>{c.setAttribute(u,f)}))})}function Ur(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname;e.filter(o=>o.selector?.pathnames?.length?o.selector.pathnames.some(r=>j(t,r)):!0).forEach(o=>{let r=`${Er}${o.id}`;if(Qe.has(r))return;let c=document.querySelector(o.selector.target);if(!c||c.parentElement?.querySelector(`#${r}`))return;let u=Rr(o);o.selector.placement==="after"?c.after(u):o.selector.placement==="before"&&c.before(u),Qe.set(r,u)})}function Rr(e){let t=document.createElement(e.tagName);return t.id=`${Er}${e.id}`,e.style&&Object.assign(t.style,e.style),e.attributes&&Object.entries(e.attributes).forEach(([n,o])=>{t.setAttribute(n,o)}),e.kind==="text"&&e.content&&(t.innerText=e.content),e.kind==="container"&&e.childrens&&e.childrens.forEach(n=>{let o=Rr(n);t.appendChild(o)}),t}function Xe(e,t){if(typeof window>"u"||e.length===0)return;let n=window.location.pathname;e.filter(r=>r.pathnames?.length?r.excludePathnames?.length&&r.excludePathnames.some(u=>j(n,u))?!1:r.pathnames.some(c=>j(n,c)):!0).forEach(r=>{r.id&&(r.css&&vn(r.id,r.css),r.js&&_n(r.id,r.js,t))})}function vn(e,t){let n=`css-${e}`;if(Je.has(n)||document.getElementById(n))return;let o=document.createElement("style");o.id=n,o.textContent=Sr(t),document.head.appendChild(o),Je.set(n,o)}function _n(e,t,n){let o=`js-${e}`;if(Ye.has(o)||document.getElementById(o))return;let r=document.createElement("script");r.id=o,n&&r.setAttribute("nonce",n);let c=Sr(t);r.textContent="(function(){try{"+c+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(r),Ye.set(o,r)}function Vr(){Ge.forEach((e,t)=>{let n=document.querySelector(t);n&&n.replaceWith(e.cloneNode(!0))})}function Or(){Je.forEach(e=>e.remove()),Je.clear(),Ye.forEach(e=>e.remove()),Ye.clear(),Qe.forEach(e=>e.remove()),Qe.clear(),Ge.clear()}function kn(e,t){let n=[],o=[],r=[];return e.tests.filter(u=>u.type==="CONTENT"&&u.enabled).forEach(u=>{let f=z(u.testId);if(!f)return;let l=u.variations.find(m=>m.id===f);l?.content&&(l.content.changes?.length&&n.push(...l.content.changes),l.content.elements?.length&&o.push(...l.content.elements),l.content.customCodes?.length&&r.push(...l.content.customCodes))}),{changes:n,elements:o,blocks:[],customCodes:r}}function Ke(e){return e.tests.some(t=>t.type==="CONTENT"&&t.enabled)}function Ze(e,t,n){if(typeof window>"u"||!Ke(e))return;let o=kn(e,t);(o.changes.length>0||o.elements.length>0||o.customCodes.length>0)&&(Ir(o.changes),Ur(o.elements),Xe(o.customCodes,n))}function Nt(e,t,n){if(typeof window>"u")return;let o=Mt();o!==ce&&(Vr(),ce=o),Ze(e,t,n)}function Ht(e,t,n){if(typeof window>"u")return()=>{};let o=()=>{Mt()!==ce&&Nt(e,t,n)},r=()=>{Nt(e,t,n)};return window.addEventListener("resize",o),window.addEventListener("popstate",r),()=>{window.removeEventListener("resize",o),window.removeEventListener("popstate",r),Or()}}G();function zt(e){return e.tests.some(t=>t.type==="CUSTOM_CODE"&&t.enabled)}function qt(e,t,n){if(typeof window>"u")return;if(console.log("[ElevateAB Custom Code] All tests:",e.tests.map(c=>({id:c.testId,type:c.type,enabled:c.enabled}))),!zt(e)){console.log("[ElevateAB Custom Code] No CUSTOM_CODE tests found");return}let o=e.tests.filter(c=>c.type==="CUSTOM_CODE"&&c.enabled);console.log("[ElevateAB Custom Code] Found",o.length,"CUSTOM_CODE tests");let r=[];o.forEach(c=>{let u=z(c.testId);if(console.log("[ElevateAB Custom Code] Test",c.testId,"assigned variant:",u),!u)return;let f=c.variations.find(l=>l.id===u);if(console.log("[ElevateAB Custom Code] Variation data:",f),!f?.customCode){console.log("[ElevateAB Custom Code] No customCode on variation");return}(f.customCode.js||f.customCode.css)&&(console.log("[ElevateAB Custom Code] Adding custom code:",f.customCode),r.push(f.customCode))}),r.length>0?(console.log("[ElevateAB Custom Code] Applying",r.length,"custom code blocks"),Xe(r,n)):console.log("[ElevateAB Custom Code] No custom code to apply")}function Cn(e,t,n){typeof window>"u"||qt(e,t,n)}function Lr(e,t,n){if(typeof window>"u")return()=>{};let o=()=>{Cn(e,t,n)};return window.addEventListener("popstate",o),()=>{window.removeEventListener("popstate",o)}}G();var et=require("react/jsx-runtime"),xn="https://ds0wlyksfn0sb.cloudfront.net/headless";function Tn(e){return e.replace(/^https?:\/\//,"").replace(".myshopify.com","")}function Br(e){return`${xn}/${Tn(e)}.js`}function Ft({storeId:e,storefrontAccessToken:t,preventFlickering:n=!1,flickerTimeout:o=3e3,nonce:r,children:c}){let[u,f]=U.default.useState(null),[l,m]=U.default.useState(null),[i,d]=U.default.useState(null);U.default.useEffect(()=>{if(typeof window>"u")return;ye({storeId:e,storefrontAccessToken:t});let g=F();m(g);let w=X();d(w)},[e,t]);let a=(0,U.useCallback)(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);U.default.useEffect(()=>{async function g(){try{let w=typeof window<"u"?F():null,y=null;if(typeof window<"u"&&window.eab_data)y=window.eab_data;else{let $=Br(e);y=await new Promise((Z,W)=>{let N=document.createElement("script");N.src=$,N.async=!0,N.onload=()=>{let ue=window.eab_data;N.remove(),ue?Z(ue):W(new Error("Failed to load config: window.eab_data is undefined"))},N.onerror=()=>{N.remove(),Z({allTests:{},selectors:{selectorsV2:[]}})},document.head.appendChild(N)})}if(!y||!y.allTests||Object.keys(y.allTests).length===0){f({tests:[],selectors:void 0}),a();return}if(y.subscriptionPaused){console.error(`[ElevateAB] Subscription is paused or stopped for store: ${e}. `+(y.subscriptionMessage||"A/B tests will not run. Please reactivate your subscription.")),f({tests:[],selectors:void 0}),a();return}if(!(Object.keys(y.allTests||{}).length>0)){f({tests:[],selectors:void 0}),a();return}let D=ur(y);if(_t(D,w),D.tests.some($=>$.type==="SPLIT_URL")&&We(D,w))return;f(D),a()}catch(w){console.error("[ElevateAB] Failed to load config:",w),f({tests:[],selectors:void 0}),a()}}g()},[e,a]),U.default.useEffect(()=>!u||typeof window>"u"||!Ke(u)?void 0:(Ze(u,l,r),Ht(u,l,r)),[u,l,r]),U.default.useEffect(()=>!u||typeof window>"u"||!zt(u)?void 0:(qt(u,l,r),Lr(u,l,r)),[u,l,r]);let s=U.default.useMemo(()=>({config:u,storeId:e,storefrontAccessToken:t,isPreviewMode:l?.isPreview??!1,previewTestId:l?.previewTestId??null,previewState:l,selectors:u?.selectors,countryCode:i}),[u,e,t,l,i]),p=(0,U.useRef)(!1);U.default.useEffect(()=>{!t&&!p.current&&(p.current=!0,console.warn("[ElevateAB] No storefrontAccessToken provided. Orders won't be attributed to test variants."))},[t]);let _=U.default.useMemo(()=>Br(e),[e]),k=U.default.useMemo(()=>Vt({configUrl:_,timeout:n?o:2e3}),[_,n,o]);return(0,et.jsxs)(Ve.Provider,{value:s,children:[(0,et.jsx)("script",{nonce:r,dangerouslySetInnerHTML:{__html:k}}),c]})}var tt=require("next/navigation");var ke=require("react/jsx-runtime");function Pn({currency:e}){let t=(0,tt.usePathname)(),n=(0,tt.useSearchParams)();return(0,Ce.useEffect)(()=>{n.get("eabUserPreview")!=="true"&&ve({currency:e})},[t,n,e]),null}function Dr({storeId:e,storefrontAccessToken:t,preventFlickering:n=!1,flickerTimeout:o=3e3,currency:r,children:c}){return(0,Ce.useEffect)(()=>{ye({storeId:e,storefrontAccessToken:t})},[e,t]),(0,ke.jsxs)(Ft,{storeId:e,storefrontAccessToken:t,preventFlickering:n,flickerTimeout:o,children:[(0,ke.jsx)(Ce.Suspense,{fallback:null,children:(0,ke.jsx)(Pn,{currency:r})}),c]})}var Nr=require("react");function Mr({productId:e,productVendor:t,productPrice:n,productSku:o,currency:r}){return(0,Nr.useEffect)(()=>{e&&_e({productId:e,productVendor:t,productPrice:n,productSku:o,currency:r})},[e,t,n,o,r]),null}Oe();B();G();B();function Hr(e){let t=V("ABAU")||{};t[e]||(t[e]=!0,L("ABAU",JSON.stringify(t)))}function zr(e){let t=bt("ABAV")||{};t[e]||(t[e]=!0,ae("ABAV",t))}function jt(e){Hr(e),zr(e)}he();je();kt();var K=Re(require("react"),1);G();he();var qr=new Map;function re(e){qr.set(e.type,e)}function rt(e){return qr.get(e)}function En(e){try{let o=new URL(e,"https://example.com").pathname.match(/\/products\/([^\/\?]+)/);return o?o[1]:null}catch{return null}}function An(e,t,n,o){if(typeof window>"u"||!e.prices||!t)return;let r=e.prices[t];if(!r)return;let c=r.price?.[n],u=r.compare?.[n],f=o;if(f?.selectorsV2?.length)for(let l of f.selectorsV2){if(l.price&&c){let m=l.price.replace("{{variant}}",t);document.querySelectorAll(m).forEach(d=>{let a=new Intl.NumberFormat("en-US",{style:"currency",currency:n}).format(parseFloat(c));d.textContent=a})}if(l.compareAt&&u){let m=l.compareAt.replace("{{variant}}",t);document.querySelectorAll(m).forEach(d=>{let a=new Intl.NumberFormat("en-US",{style:"currency",currency:n}).format(parseFloat(u));d.textContent=a})}if(l.saving&&c&&u)for(let m of l.saving){let i=m.selector.replace("{{variant}}",t);document.querySelectorAll(i).forEach(a=>{let s=parseFloat(c),p=parseFloat(u),_=p-s;if(m.isPercentage){let k=Math.round(_/p*100);a.textContent=`${k}%`}else{let k=new Intl.NumberFormat("en-US",{style:"currency",currency:n}).format(_);a.textContent=k}})}}}var $t={type:"PRICE_PLUS",shouldActivate(e,t){let n=e.data;if(!n)return!1;let{productId:o,productHandle:r}=t,c=r||En(t.currentUrl),u=o&&n.productIds?.includes(o),f=c&&n.handles?.includes(c);return u||f},applyEffect(e,t,n){An(t,n.variantId,n.currencyCode||"USD",n.selectors)},getVariantData(e,t,n){let o=e.data;return{prices:t.prices,matchedProductId:n.productId,productIds:o?.productIds,handles:o?.handles,handlerActivated:!0}}};function Sn(e,t){let o=e.data?.pathnames||[];if(!o.length)return!0;try{let c=new URL(t,"https://example.com").pathname;return o.some(u=>j(c,u))}catch{return!1}}var nt={type:"CONTENT",shouldActivate(e,t){return Sn(e,t.currentUrl)},getVariantData(e,t,n){let o=e.data;return{content:t.content,pathnames:o?.pathnames,handlerActivated:!0}}};function In(e,t){let o=e.data?.pathnames||[];if(!o.length)return!0;try{let c=new URL(t,"https://example.com").pathname;return o.some(u=>j(c,u))}catch{return!1}}var Wt={type:"CUSTOM_CODE",shouldActivate(e,t){return In(e,t.currentUrl)},getVariantData(e,t,n){let o=e.data;return{customCode:t.customCode,pathnames:o?.pathnames,excludePathnames:o?.excludePathnames,handlerActivated:!0}}};re($t);re(Lt);re(nt);re(Wt);function Vn(e){if(typeof window>"u")return{currentUrl:"",selectors:e};let t=window.location.href,n=window.location.pathname,o,r=n.match(/\/products\/([^\/\?]+)/);r&&(o=r[1]);let c,f=new URLSearchParams(window.location.search).get("variant");return f&&(c=f),{currentUrl:t,productHandle:o,variantId:c,selectors:e,currencyCode:"USD"}}function Gt(e){let{config:t,previewState:n,selectors:o}=we(),[r,c]=K.default.useState(null),[u,f]=K.default.useState(!0),l=K.default.useMemo(()=>t&&t.tests.find(a=>a.testId===e)||null,[t,e]),m=K.default.useMemo(()=>n||F(),[n]),i=K.default.useRef(null),d=K.default.useRef(null);return K.default.useEffect(()=>{let a=!0;if(t===null)return;if(!l){i.current!==e&&(i.current=e,console.warn(`[ElevateAB] Test not found: ${e}`)),a&&f(!1);return}if(!l.enabled&&!m?.isPreview){i.current!==`${e}-disabled`&&(i.current=`${e}-disabled`,console.warn(`[ElevateAB] Test disabled: ${e}`)),a&&f(!1);return}let s=z(e);if(!s){a&&f(!1);return}let p=l.variations.find(w=>w.id===s);if(!p){a&&f(!1);return}let _=rt(l.type),k=Vn(o),g={...p};if(_?.shouldActivate(l,k)){let w=`${e}-${p.id}`;_.applyEffect&&d.current!==w&&(d.current=w,_.applyEffect(l,p,k));let y=_.getVariantData(l,p,k);g={...g,...y}}return a&&c(g),m?.isPreview||jt(e),a&&f(!1),()=>{a=!1}},[t,l,e,m,o]),{variant:r,isLoading:u,isControl:r?.isControl??!1,isA:r?.isA??!1,isB:r?.isB??!1,isC:r?.isC??!1,isD:r?.isD??!1}}var Jt=require("react");B();B();je();0&&(module.exports={ElevateNextProvider,ProductViewTracker,clearPreviewMode,extractShopifyId,extractShopifyType,getCountryCode,getPreviewState,isInPreviewMode,isShopifyGid,matchesGeoTargeting,trackAddToCart,trackCartView,trackCheckoutCompleted,trackCheckoutStarted,trackPageView,trackProductView,trackRemoveFromCart,trackSearchSubmitted,useElevateConfig,useExperiment});
47
47
  //# sourceMappingURL=next.cjs.map