@thg-agentic/hyper-personalisation-web 3.29.0 → 3.31.0

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.
@@ -1,4 +1,4 @@
1
- (()=>{async function Ue(i,o,a){let l=b=>Array.from(new Uint8Array(b),w=>w.toString(16).padStart(2,"0")).join(""),p=new TextEncoder,x=i.maxnumber??1e6;for(let b=0;b<=x;b+=256){let w=[];for(let C=b;C<b+256&&C<=x;C++)w.push(crypto.subtle.digest("SHA-256",p.encode(i.salt+C)));let h=(await Promise.all(w)).findIndex(C=>l(C)===i.challenge);if(h>=0)return b+h;if(o&&await o(),a?.aborted)return null}return null}var $t=()=>globalThis.scheduler?.postTask?.(()=>{},{priority:"user-visible"})??new Promise(i=>setTimeout(i,0)),De=(i,o)=>Ue(i,$t,o);function _t(i,o){let a=`onmessage=async(e)=>postMessage(await(${Ue})(e.data))`,l=URL.createObjectURL(new Blob([a],{type:"text/javascript"}));return new Promise((p,x)=>{let b;try{b=new Worker(l)}catch(h){URL.revokeObjectURL(l),x(h);return}let w=(h,C)=>{b.terminate(),URL.revokeObjectURL(l),h(C)};o.addEventListener("abort",()=>w(p,null),{once:!0}),b.onmessage=h=>w(p,h.data),b.onerror=h=>{h.preventDefault?.(),w(x,h)},b.postMessage({challenge:i.challenge,salt:i.salt,maxnumber:i.maxnumber})})}var zt=i=>i&&i.algorithm==="SHA-256"&&typeof i.challenge=="string"&&typeof i.salt=="string"&&typeof i.signature=="string";async function We(i){if(!zt(i)||typeof crypto?.subtle?.digest!="function")return null;let o=Date.now(),a=new AbortController,l,p=new Promise(w=>{l=setTimeout(()=>w(null),2e4)}),x=typeof Worker=="function"&&typeof Blob=="function"?_t(i,a.signal).catch(()=>De(i,a.signal)):De(i,a.signal),b=await Promise.race([x,p]);return clearTimeout(l),a.abort(),typeof b!="number"?null:btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:b,salt:i.salt,signature:i.signature,took:Date.now()-o}))}function V(i){if(typeof i!="string")return null;try{let o=new URL(i);return o.protocol==="https:"?o.href:null}catch{return null}}function X(i){if(typeof i!="string")return null;try{let o=new URL(i);return o.protocol==="https:"||o.protocol==="http:"&&o.hostname==="localhost"?o.href:null}catch{return null}}function me(i,o,a,l){if(typeof o=="string"){i.append(a.createTextNode(o));return}if(l>6||o===null)return;if(Array.isArray(o)){for(let w of o)me(i,w,a,l+1);return}if(typeof o!="object")return;let p="b"in o?"b":"i"in o?"i":"a"in o?"a":null;if(!p)return;let x=p==="a"?V(o.href):null,b=p==="a"&&!x?i:a.createElement(p);x&&(b.setAttribute("href",x),b.setAttribute("rel","noopener")),me(b,o[p],a,l+1),b!==i&&i.append(b)}function Fe(i,o=document){let a=o.createDocumentFragment();return me(a,i,o,0),a}var M=i=>i!==null&&typeof i=="object"&&!Array.isArray(i);function K(i,o,a){if(typeof a=="string"&&a)return a;let l=M(i?.next?.answers)?i.next.answers:{};for(let p of i?.blocks??[])for(let x of o[p?.question]??[]){let b=l[`${p.question}=${x}`];if(typeof b=="string")return b}return typeof i?.next?.default=="string"?i.next.default:null}var he={AT:"43",AU:"61",BE:"32",CA:"1",CH:"41",DE:"49",DK:"45",ES:"34",FI:"358",FR:"33",GB:"44",IE:"353",IT:"39",NL:"31",NO:"47",NZ:"64",PL:"48",PT:"351",SE:"46",US:"1"};function Ye(i,o){let a=String(i??"").replace(/[\s.()-]/g,"");a.startsWith("00")&&(a=`+${a.slice(2)}`);let l=he[String(o??"").toUpperCase()];return!a.startsWith("+")&&l&&(a=`+${l}${a.replace(/^0/,"")}`),/^\+[1-9]\d{7,14}$/.test(a)?a:null}var He=i=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i);function be(i,o,a,l,p){let x=i("select","i");x.setAttribute("aria-label",o);for(let[b,w]of[["",a],...l]){let h=i("option","",w);h.value=b,h.selected=b===p,x.append(h)}return x}var Be=i=>{let o=i.options.length;return o<=4?o:o%4?3:4};var xe={system:"system-ui,sans-serif","neo-grotesque":'Inter,Roboto,"Helvetica Neue",Arial,sans-serif',humanist:'Seravek,"Gill Sans Nova",Ubuntu,Calibri,sans-serif',"geometric-humanist":"Avenir,Montserrat,Corbel,sans-serif","rounded-sans":'ui-rounded,Quicksand,Comfortaa,"Arial Rounded MT Bold",sans-serif',industrial:'Bahnschrift,"DIN Alternate","Franklin Gothic Medium",sans-serif',transitional:'Charter,"Sitka Text",Cambria,serif',"old-style":'"Iowan Old Style","Palatino Linotype",P052,serif',didone:'Didot,"Bodoni MT","Noto Serif Display",serif',"slab-serif":'Rockwell,"Roboto Slab","DejaVu Serif",serif'},ge="cubic-bezier(.16,1,.3,1)",ye=`
1
+ (()=>{async function Be(o,r,a){let l=b=>Array.from(new Uint8Array(b),w=>w.toString(16).padStart(2,"0")).join(""),p=new TextEncoder,x=o.maxnumber??1e6;for(let b=0;b<=x;b+=256){let w=[];for(let C=b;C<b+256&&C<=x;C++)w.push(crypto.subtle.digest("SHA-256",p.encode(o.salt+C)));let h=(await Promise.all(w)).findIndex(C=>l(C)===o.challenge);if(h>=0)return b+h;if(r&&await r(),a?.aborted)return null}return null}var Ct=()=>globalThis.scheduler?.postTask?.(()=>{},{priority:"user-visible"})??new Promise(o=>setTimeout(o,0)),He=(o,r)=>Be(o,Ct,r);function Tt(o,r){let a=`onmessage=async(e)=>postMessage(await(${Be})(e.data))`,l=URL.createObjectURL(new Blob([a],{type:"text/javascript"}));return new Promise((p,x)=>{let b;try{b=new Worker(l)}catch(h){URL.revokeObjectURL(l),x(h);return}let w=(h,C)=>{b.terminate(),URL.revokeObjectURL(l),h(C)};r.addEventListener("abort",()=>w(p,null),{once:!0}),b.onmessage=h=>w(p,h.data),b.onerror=h=>{h.preventDefault?.(),w(x,h)},b.postMessage({challenge:o.challenge,salt:o.salt,maxnumber:o.maxnumber})})}var Lt=o=>o&&o.algorithm==="SHA-256"&&typeof o.challenge=="string"&&typeof o.salt=="string"&&typeof o.signature=="string";async function Ge(o){if(!Lt(o)||typeof crypto?.subtle?.digest!="function")return null;let r=Date.now(),a=new AbortController,l,p=new Promise(w=>{l=setTimeout(()=>w(null),2e4)}),x=typeof Worker=="function"&&typeof Blob=="function"?Tt(o,a.signal).catch(()=>He(o,a.signal)):He(o,a.signal),b=await Promise.race([x,p]);return clearTimeout(l),a.abort(),typeof b!="number"?null:btoa(JSON.stringify({algorithm:o.algorithm,challenge:o.challenge,number:b,salt:o.salt,signature:o.signature,took:Date.now()-r}))}function X(o){if(typeof o!="string")return null;try{let r=new URL(o);return r.protocol==="https:"?r.href:null}catch{return null}}function K(o){if(typeof o!="string")return null;try{let r=new URL(o);return r.protocol==="https:"||r.protocol==="http:"&&r.hostname==="localhost"?r.href:null}catch{return null}}function be(o,r,a,l){if(typeof r=="string"){o.append(a.createTextNode(r));return}if(l>6||r===null)return;if(Array.isArray(r)){for(let w of r)be(o,w,a,l+1);return}if(typeof r!="object")return;let p="b"in r?"b":"i"in r?"i":"a"in r?"a":null;if(!p)return;let x=p==="a"?X(r.href):null,b=p==="a"&&!x?o:a.createElement(p);x&&(b.setAttribute("href",x),b.setAttribute("rel","noopener")),be(b,r[p],a,l+1),b!==o&&o.append(b)}function Ve(o,r=document){let a=r.createDocumentFragment();return be(a,o,r,0),a}var M=o=>o!==null&&typeof o=="object"&&!Array.isArray(o);function ee(o,r,a){if(typeof a=="string"&&a)return a;let l=M(o?.next?.answers)?o.next.answers:{};for(let p of o?.blocks??[])for(let x of r[p?.question]??[]){let b=l[`${p.question}=${x}`];if(typeof b=="string")return b}return typeof o?.next?.default=="string"?o.next.default:null}var ge={AT:"43",AU:"61",BE:"32",CA:"1",CH:"41",DE:"49",DK:"45",ES:"34",FI:"358",FR:"33",GB:"44",IE:"353",IT:"39",NL:"31",NO:"47",NZ:"64",PL:"48",PT:"351",SE:"46",US:"1"};function Xe(o,r){let a=String(o??"").replace(/[\s.()-]/g,"");a.startsWith("00")&&(a=`+${a.slice(2)}`);let l=ge[String(r??"").toUpperCase()];return!a.startsWith("+")&&l&&(a=`+${l}${a.replace(/^0/,"")}`),/^\+[1-9]\d{7,14}$/.test(a)?a:null}var Ke=o=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o);function xe(o,r,a,l,p){let x=o("select","i");x.setAttribute("aria-label",r);for(let[b,w]of[["",a],...l]){let h=o("option","",w);h.value=b,h.selected=b===p,x.append(h)}return x}var Ze=o=>{let r=o.options.length;return r<=4?r:r%4?3:4};var ve={system:"system-ui,sans-serif","neo-grotesque":'Inter,Roboto,"Helvetica Neue",Arial,sans-serif',humanist:'Seravek,"Gill Sans Nova",Ubuntu,Calibri,sans-serif',"geometric-humanist":"Avenir,Montserrat,Corbel,sans-serif","rounded-sans":'ui-rounded,Quicksand,Comfortaa,"Arial Rounded MT Bold",sans-serif',industrial:'Bahnschrift,"DIN Alternate","Franklin Gothic Medium",sans-serif',transitional:'Charter,"Sitka Text",Cambria,serif',"old-style":'"Iowan Old Style","Palatino Linotype",P052,serif',didone:'Didot,"Bodoni MT","Noto Serif Display",serif',"slab-serif":'Rockwell,"Roboto Slab","DejaVu Serif",serif'},ye="cubic-bezier(.16,1,.3,1)",we=`
2
2
  :host{all:initial}
3
3
  :host([preview]){display:block;position:relative;width:100%;height:100%;overflow:hidden;contain:layout paint}
4
4
  .s{--a:var(--hp-accent,#111);--b:var(--hp-bg,#fff);--t:var(--hp-text,#111);--r:var(--hp-radius,16px);--oa:var(--hp-on-accent,#fff);--ot:var(--hp-on-accent-text,var(--oa));--fl:var(--hp-field,color-mix(in srgb,var(--t) 5%,var(--b)));--ft:var(--hp-field-text,var(--t));--mu:color-mix(in srgb,var(--t) 74%,var(--b));--ln:color-mix(in srgb,var(--t) 18%,var(--b));--br:min(12px,var(--r));--ir:min(var(--r),8px);font:16px/1.5 var(--hp-font,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif);color:var(--t);-webkit-font-smoothing:antialiased;box-sizing:border-box;margin:0;padding:0;border:0;background:none;max-width:none;max-height:none;overflow:visible}
@@ -13,7 +13,7 @@ dialog::backdrop{background:none}
13
13
  .mob.popup{padding:12px}
14
14
  .ov{display:none;position:absolute;inset:0;background:var(--hp-ov,rgb(10 10 14/.6));animation:hp-fade .3s ease both}
15
15
  .popup>.ov,.fullscreen>.ov{display:block}
16
- .w{position:relative;display:flex;flex-direction:column;width:min(100%,480px);max-height:100%;min-height:0;overflow:auto;overscroll-behavior:contain;background:var(--b);color:var(--t);border-radius:var(--r);box-shadow:0 24px 48px -24px rgb(0 0 0/.35),0 0 0 1px rgb(0 0 0/.05);animation:hp-pop .44s ${ge} both}
16
+ .w{position:relative;display:flex;flex-direction:column;width:min(100%,480px);max-height:100%;min-height:0;overflow:auto;overscroll-behavior:contain;background:var(--b);color:var(--t);border-radius:var(--r);box-shadow:0 24px 48px -24px rgb(0 0 0/.35),0 0 0 1px rgb(0 0 0/.05);animation:hp-pop .44s ${ye} both}
17
17
  .z-sm{width:min(100%,380px)}
18
18
  .z-lg{width:min(100%,880px)}
19
19
  .z-full,.fullscreen .w{width:100%;height:100%;max-height:none;border-radius:0;box-shadow:none}
@@ -105,7 +105,7 @@ legend{padding:0;margin-bottom:8px;font-size:13px;font-weight:600}
105
105
  .pg{display:flex;flex-direction:column;gap:8px}
106
106
  .pg p{font-weight:600}
107
107
  .tr{height:6px;border-radius:99px;background:color-mix(in srgb,var(--t) 18%,var(--b));overflow:hidden}
108
- .tr i{display:block;height:100%;border-radius:inherit;background:var(--a);transform:scaleX(0);transform-origin:left;transition:transform .6s ${ge}}
108
+ .tr i{display:block;height:100%;border-radius:inherit;background:var(--a);transform:scaleX(0);transform-origin:left;transition:transform .6s ${ye}}
109
109
  .bi{display:block;width:100%;height:auto}
110
110
  .bl{display:block;border-radius:var(--br)}
111
111
  hr{width:100%;margin:4px 0;border:0;border-top:1px solid var(--ln)}
@@ -169,7 +169,7 @@ hr{width:100%;margin:4px 0;border:0;border-top:1px solid var(--ln)}
169
169
  .inline .t-stack .m{max-height:none}
170
170
  .out .w{animation:hp-out .2s ease-in both}
171
171
  .out .ov{animation:hp-fade .2s ease-in reverse both}
172
- .f>*{animation:hp-rise .5s ${ge}}
172
+ .f>*{animation:hp-rise .5s ${ye}}
173
173
  .pv .w,.pv .ov,.pv .f>*,.inline .f>*{animation:none}
174
174
  @keyframes hp-pop{from{opacity:0;transform:translateY(24px) scale(.96)}}
175
175
  @keyframes hp-fade{from{opacity:0}}
@@ -178,4 +178,4 @@ hr{width:100%;margin:4px 0;border:0;border-top:1px solid var(--ln)}
178
178
  @keyframes hp-down{from{transform:translateY(-100%)}}
179
179
  @keyframes hp-out{to{opacity:0;transform:translateY(12px) scale(.98)}}
180
180
  @media (prefers-reduced-motion:reduce){.s .w,.s .ov,.f>*{animation:hp-fade .15s ease both!important}.btn{transition:none}}
181
- `;var Ct=/^#(?:[0-9a-f]{3}){1,2}$/i,Ge=["popup","fullscreen"],Tt=["ok","verify","already"],Lt=["stack","split","overlay","image-only"],Ve={bar:["bottom","top"],sheet:["bottom-right","bottom-left","bottom"],teaser:["bottom-left","bottom-right","left","right"]},Ot=["xs","sm","md","lg","xl","display"],Xe={xs:4,sm:8,md:16,lg:28,xl:44},Ke={sm:380,md:480,lg:880},Mt=["left","center","right"],Ze={secondary:" b2",link:" no"},It=220,Pt=["verify","already","held","fallback","success"],qt=[500,1500],Nt=600,jt=1800,S={email:"Enter a valid email address.",phone:"Enter a valid mobile number.",intl:"Enter a valid mobile number, starting with + and its country code.",consent:"Tick the box to sign up.",failed:"Something went wrong. Please try again.",busy:"Too many tries. Please wait a moment and try again.",spin:"Sign up first to spin.",yours:"Your code",held:"You\u2019re already on the list",resent:"We\u2019ve sent your code to your inbox again.",inbox:"Your code is in the email we sent when you first signed up.",shop:"Continue shopping",closeOffer:"Close offer",code:"We\u2019ll email your code to you.",claimed:"This email address has already claimed its code.",copied:"Copied",thanks:"Thanks, you\u2019re signed up",retry:"You\u2019re signed up, but we couldn\u2019t load your prize. Please try again.",unclaimed:"We couldn\u2019t load your prize right now.",unavailable:"Not available right now.",won:"You won"},H=(i,o,a)=>i.includes(o)?o:a,I=(i,o,a)=>Number.isFinite(i)?Math.min(Math.max(i,o),a):null,ve=i=>i.type==="date"||i.type==="number",we=()=>globalThis.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches===!0;function et(i){let o=M(i.layout)?i.layout:{},a=M(o.media)?o.media:null,l=H(Lt,o.template,"stack"),p=a?.side==="right"?"right":"left";return!a&&M(o.image)&&o.image.side!=="none"&&(a=o.image,o.image.side!=="top"&&(l="split",p=o.image.side==="right"?"right":"left")),(!a||!X(a.asset))&&(a=null,l="stack"),{template:l,media:a,side:p,scrim:I(o.scrim,0,.9)??.45,padding:H(["none","sm","md","lg"],o.padding,"md")}}var tt=(i,o)=>H(["sm","md","lg","full"],i.size,null)??(o.template==="split"||o.template==="overlay"?"lg":"md"),nt=(i,o,a=1,l="100vw")=>{if(i==="fullscreen"||o==="full")return l;let p=i==="teaser"?220:i==="sheet"?400:Ke[o]??Ke.md;return`(max-width: 639px) ${l}, ${Math.round(p*a)}px`},it=(i,o)=>i==="lg"?1/Be(o):.5,ot=(i,o,a)=>{if(!a||!Array.isArray(i.widths)||!o.endsWith(".webp"))return null;let l=i.widths.filter(p=>Number.isInteger(p)&&p>0&&p<a).sort((p,x)=>p-x);return l.length===0?null:[...l.map(p=>`${o.slice(0,-5)}-${p}w.webp ${p}w`),`${o} ${a}w`].join(",")},rt=(i,o)=>i.format==="inline"?"inline":o.format&&o.format!=="inline"?o.format:i.format,Ae=i=>i.kind==="video"||i.t==="video",Se={webm:"video/webm",mp4:"video/mp4",m4v:"video/mp4",mov:"video/quicktime",ogv:"video/ogg"},Ee=i=>Se[i.split(/[?#]/)[0].split(".").pop().toLowerCase()],Rt=(i,o)=>[...new Set([o,...Array.isArray(i.sources)?i.sources.map(X):[]])].filter(Boolean).sort((a,l)=>(Ee(l)===Se.webm)-(Ee(a)===Se.webm));function $e(i,o,a,l=new Set){let p=o.steps.find(v=>v.id===a);if(!p)return Promise.resolve();let x=rt(i,o),b=et(p),w=x==="teaser"&&p===o.steps[0],h=x==="teaser"&&!w?"popup":x,C=tt(o.theme,b),$=w?[]:p.blocks.flatMap(v=>{if(v?.t==="image"||v?.t==="video")return[[v]];let W=v?.display==="cards"&&i.questions.find(T=>T.key===v.question&&T.type==="one");return W?Object.values(v.pictures??{}).filter(M).map(T=>[T,it(C,W),"50vw"]):[]});return b.media&&!(w&&b.template!=="image-only")&&$.push([b.media,b.template==="split"?.46:1]),Promise.all($.map(([v,W,T])=>{let L=X(Ae(v)?v.poster:v.asset);if(!L)return null;let R=document.createElement("img"),y=!Ae(v)&&ot(v,L,I(v.width,1,8192));y&&(R.sizes=nt(h,C,W,T),R.srcset=y);let Z=`${R.sizes} ${y||L}`;return l.has(Z)?null:(l.add(Z),R.src=L,R.decode?.().catch(()=>{}))}))}var Je=i=>i?.call?i():clearInterval(i),Dt=0,ke=i=>`hp-${i}-${++Dt}`;function d(i,o,a){let l=document.createElement(i);return o&&(l.className=o),a!==void 0&&l.append(Fe(a)),l}var st=i=>{let o=i.length===4?[...i.slice(1)].map(a=>a+a).join(""):i.slice(1);return[0,2,4].map(a=>Number.parseInt(o.slice(a,a+2),16))},te=i=>{let[o,a,l]=st(i).map(p=>{let x=p/255;return x<=.04045?x/12.92:((x+.055)/1.055)**2.4});return .2126*o+.7152*a+.0722*l},Qe=(i,o=4.5)=>{let a=te(i)+.05,l=1.05/a;return l>=o?"#fff":a/(te("#111")+.05)>l?"#111":"#fff"};function Ut(i,o){let a=($,v)=>v&&i.style.setProperty($,v),l=$=>Ct.test($??"")?$:null;a("--hp-accent",l(o.accent)),a("--hp-bg",l(o.background)),a("--hp-text",l(o.text));let p=I(o.radius,0,48);p!==null&&a("--hp-radius",`${p}px`),a("--hp-font",o.font==="site"?i.ownerDocument.defaultView.getComputedStyle(i.parentElement??i.ownerDocument.body).fontFamily:Object.hasOwn(xe,o.font)?xe[o.font]:null),l(o.accent)&&(a("--hp-on-accent",Qe(o.accent,3)),a("--hp-on-accent-text",Qe(o.accent))),l(o.background)&&te(o.background)<.18&&(a("--hp-field","#fff"),a("--hp-field-text","#111"));let x=M(o.overlay)?o.overlay:{},b=[l(o.text),l(o.background)].filter(Boolean).sort(($,v)=>te($)-te(v))[0],[w,h,C]=st(l(x.colour)??b??"#0b0b0f");a("--hp-ov",`rgb(${w} ${h} ${C} / ${I(x.opacity,0,1)??.6})`)}function Wt(i){try{let o=new CSSStyleSheet;o.replaceSync(ye),i.adoptedStyleSheets=[o]}catch{let o=document.createElement("style");o.textContent=ye,i.append(o)}}function at(i){let{form:o,creative:a,decision:l,access:p,client:x,api:b,counters:w}=i,h=i.preview??null,C=e=>{let t=e.blocks.find(r=>r?.t==="email"||r?.t==="phone");return t?.t==="phone"||!t&&!o.consent_text?o.sms_consent_text:o.consent_text},$=rt(o,a),v=a.theme,W=H(Ve[$]??[],v.position,Ve[$]?.[0]),T=document.createElement("hp-onsite");h&&T.setAttribute("preview",""),Ut(T,v);let L=T.attachShadow({mode:"open"});Wt(L);let R=$!=="inline"&&!h,y=d(R?"dialog":$==="inline"?"section":"div"),Z=d("div","ov"),_=d("div","w"),F=d("div","m");h&&(F.dataset.hpMedia="");let _e=()=>{let e=d("form","f");return e.noValidate=!0,e.addEventListener("submit",wt),e.addEventListener("input",()=>{O.textContent&&E.getAttribute("aria-busy")!=="true"&&N(null)}),e},E=_e(),O=d("p","e");O.id=ke("err"),O.setAttribute("aria-live","assertive");let se=d("div","hd");se.setAttribute("aria-hidden","true"),_.append(se,F,E),y.append(Z,_);let B=$!=="inline"&&d("button","x");B&&(B.type="button",B.addEventListener("click",()=>j("close")),_.append(B),Z.addEventListener("click",()=>j("close"))),L.append(y);let n={step:null,mode:$,size:"md",modal:!1,mobile:h?.device==="mobile",answers:{},sent:new Set,seen:new Set,receipt:null,claim:i.coupon?{code:i.coupon}:h?{code:"WELCOME15"}:null,claiming:null,touched:!1,toWarm:new Set,warmed:i.warmed??new Set,warming:!1,owed:!1,unclaimed:!1,misses:0,submitted:!1,pow:null,wheel:null,timers:[],codes:[],videos:[],closed:!1},J=o.locale||document.documentElement.lang,ze=(o.questions.some(ve)||a.steps.some(e=>e.blocks.some(t=>t?.t==="countdown"||t?.display==="cards")))&&i.loadAnswers().catch(()=>null),Ce=new WeakMap,Te=()=>{let e=M(v.button)?v.button:{};y.className=`s ${n.mode}${W?` p-${W}`:""} b-${H(["pill","rounded","square"],e.shape,"rounded")}${n.mobile?" mob":""}${h?" pv":""}${e.style==="outline"?" bo":""}${v.caps===!0?" uc":""}`},Q=h?null:globalThis.matchMedia?.("(max-width: 639px)"),Le=()=>{n.mobile=Q?.matches===!0,de(),Te()};Q&&(n.mobile=Q.matches===!0,Q.addEventListener?.("change",Le));let ee=(e,t,r={})=>{h||!l.decision_id||!p.analytics()||x.slotEngaged({decision_id:l.decision_id,slot:l.slot,arm:l.arm??null,engagement:e,step:t??n.step?.id??null,...r})},N=(e,t)=>{O.className="e",O.textContent=e??"";for(let s of E.querySelectorAll("[aria-invalid]"))s.removeAttribute("aria-invalid");let r=t?.closest("label,fieldset");r&&E.contains(r)?r.after(O):E.append(O),t&&(t.setAttribute("aria-invalid","true"),t.setAttribute("aria-describedby",O.id),t.focus(),t.scrollIntoView?.({block:"nearest"}))},G=e=>{E.setAttribute("aria-busy",String(e));for(let t of E.querySelectorAll("button"))t.disabled=e},Oe=()=>h?Promise.resolve(null):(n.pow??(n.pow=b.challenge().then(e=>e.status===200?We(e.body):null).catch(()=>null)),n.pow),ae=()=>{for(let e of n.videos)try{document.hidden||we()?e.pause():e.play()?.catch?.(()=>{})}catch{}};document.addEventListener("visibilitychange",ae);function le(e,t,r,s,c){let u=X(e.asset);if(!u)return null;let g=typeof e.alt=="string"?e.alt:"",m;if(Ae(e)){m=d("video",t),m.muted=m.defaultMuted=m.loop=m.playsInline=!0;let A=X(e.poster);A&&(m.poster=A),g?m.setAttribute("aria-label",g):m.setAttribute("aria-hidden","true"),m.autoplay=!we()&&!h,m.preload=m.autoplay?"auto":A?"none":"metadata";let z=Rt(e,u);if(z.length>1)for(let P of z){let q=d("source");q.src=P;let Y=Ee(P);Y&&(q.type=Y),m.append(q)}else m.src=u;n.videos.push(m)}else{m=d("img",t),m.alt=g,m.decoding="async",m.loading=r?"eager":"lazy",r&&(m.fetchPriority="high");let A=ot(e,u,I(e.width,1,8192));A&&(m.sizes=nt(n.mode,n.size,s,c),m.srcset=A),m.src=u}let f=I(e.width,1,8192),k=I(e.height,1,8192);return f&&k&&(m.width=f,m.height=k),M(e.focal)&&(m.style.objectPosition=`${I(e.focal.x,0,100)??50}% ${I(e.focal.y,0,100)??50}%`),m}function Me(e,t){let r=d("label","l");r.append(d("span","lt",e.label??(t==="email"?"Email":"Mobile number")));let s=d("input","i");if(s.type=t,s.name=t==="email"?"email":"phone",s.autocomplete=s.inputMode=t,s.required=!0,typeof e.placeholder=="string"&&(s.placeholder=e.placeholder),s.setAttribute("aria-describedby",O.id),s.addEventListener("focus",Oe,{once:!0}),t!=="tel")return r.append(s),r;s.id=`${O.id}-p`,r.htmlFor=s.id;let c=be(d,"Country code","+",Object.entries(he).map(([g,m])=>[g,`${g} +${m}`]),(e.country||/-(\w\w)$/.exec(J)?.[1]||"").toUpperCase());c.classList.add("cc"),c.name="hp_cc";let u=d("span","ph");return u.append(c,s),r.append(u),r}function lt(e){let t=o.questions.find(f=>f.key===e.question);if(!t||!ve(t)&&!Array.isArray(t.options))return null;let r=d("fieldset");r.dataset.question=t.key,r.append(d("legend","",t.label??""));let s=n.answers[t.key]??[],c=e.display==="cards"&&t.type==="one";if(ve(t)||c)return ze.then(f=>{if(!f)return r.append(d("p","sm",S.unavailable));if(c)return f.answerCards(r,t,e,d,s,k=>le(k,"qi",!1,it(n.size,t),"50vw"),L);f.answerFields(r,t,d,s[0],J),Ce.set(r,()=>f.answerOf(r,t,void 0,J))}),r;let u=t.type==="many",g=H(["list","dropdown"],e.display,"buttons"),m=t.options.filter(f=>M(f)&&typeof f.value=="string");if(g==="dropdown"&&!u)return r.append(be(d,t.label??t.key,"\u2014",m.map(f=>[f.value,f.label??f.value]),s[0])),r;g!=="buttons"&&(r.className="ls");for(let f of m){let k=d("label",g==="buttons"?"ch":"c"),A=d("input");A.type=u?"checkbox":"radio",A.name=`q_${t.key}`,A.value=f.value,A.checked=s.includes(f.value),k.append(A,d("span","",f.label??f.value)),r.append(k)}return r}function ne(){for(let e of n.codes){if(e.replaceChildren(),!n.claim){n.unclaimed&&e.append(d("p","",S.unclaimed));continue}if(!n.claim.code){let s=n.claim.held?S.claimed:n.claim.fallback===!0?S.code:n.claim.prize?.label;s&&e.append(d("p","",s));continue}n.claim.prize?.label&&e.append(d("p","",n.claim.prize.label));let t=d("output");t.textContent=n.claim.code;let r=d("button","btn cp");r.type="button",r.textContent="Copy code",r.addEventListener("click",()=>{navigator.clipboard?.writeText(n.claim.code).then(()=>{r.textContent=S.copied}).catch(()=>{})}),e.append(t,r)}}function ct(e){if(n.claim&&!n.claim.code)return null;let t=d("div","cd");return t.hidden=!0,ze.then(r=>r&&t.isConnected&&n.timers.push(r.countdown(t,e,h,d))),t}function ce(e,t){return e.href=t,e.rel="noopener",e.addEventListener("click",r=>{h?r.preventDefault():ee("click")}),e}function dt(e){let t=e.label??"Continue";if(e.action==="link"){let s=V(e.href);return s?ce(d("a",`btn${Ze[e.variant]??""}`,t),s):null}let r=d("button",`btn${Ze[e.variant]??""}`,t);return r.type=e.action==="submit"?"submit":"button",r.type==="button"?r.addEventListener("click",()=>re(e)):r.dataset.submit="",r}let Ie=(e,t,r)=>(e.classList.add(`x-${H(Ot,t.size,r)}`),Mt.includes(t.align)&&e.classList.add(`a-${t.align}`),e);function Pe(e){let t=le(e,"bi",n.step===a.steps[0]);if(!t)return null;t.style.objectFit=e.fit==="contain"?"contain":"cover";let r=I(e.radius,0,48);r!==null&&(t.style.borderRadius=`${r}px`);let s=I(e.max_height,40,800);if(s!==null&&(t.style.maxHeight=`${s}px`),!t.width&&e.fit!=="contain"&&(t.style.aspectRatio="16 / 9"),e.t==="video"||!V(e.href))return t;let c=ce(d("a","bl"),V(e.href));return c.append(t),c}function pt(e){let t=I(e.threshold,.01,1e7);if(!t)return null;let r=d("div","pg"),s=d("p"),c=d("div","tr"),u=d("i");c.append(u),c.setAttribute("role","progressbar"),c.setAttribute("aria-valuemin","0"),c.setAttribute("aria-valuemax",String(t)),r.append(s,c);let g=f=>f.toFixed(2);try{let f=new Intl.NumberFormat(J||void 0,{style:"currency",currency:e.currency});g=k=>f.format(k)}catch{}let m=()=>{let f=Math.max(0,Number(i.basket?.())||0),k=t-f;s.textContent=k>0?String(e.text??"").replace("{amount}",g(k)):e.done??"",u.style.transform=`scaleX(${Math.min(1,f/t)})`,c.setAttribute("aria-valuenow",String(Math.min(f,t))),s.id||(s.id=ke("pg")),c.setAttribute("aria-labelledby",s.id)};return m(),n.timers.push(setInterval(m,2e3)),r}function ut(e){let t=d("div","pr");return i.loadProducts?.().then(r=>{t.isConnected&&n.timers.push(r.mountProducts(t,e,{el:d,lang:J,root:L,placement:o.slot,preview:h,client:!h&&p.analytics()&&x,engaged:ee,seen:n.seen}))}).catch(()=>{}),t}let qe={heading(e){let t=Ie(d("h2","",e.text),e,"xl");return t.id=ke("h"),t.tabIndex=-1,y.hasAttribute("aria-labelledby")||(y.setAttribute("aria-labelledby",t.id),n.step===a.steps[0]&&Ge.includes(n.mode)&&!h&&(t.autofocus=!0)),t},text:e=>Ie(d("p","",e.text),e,"md"),email:e=>Me(e,"email"),phone:e=>Me(e,"tel"),consent(e){let t=C(n.step)?.text;if(typeof t!="string")return null;if(e.required!==!0)return d("p","sm",t);let r=d("label","c"),s=d("input");return s.type="checkbox",s.name="hp_consent",s.required=!0,s.setAttribute("aria-describedby",O.id),r.append(s,d("span","",t)),r},question:lt,wheel(){let e=d("div","wh");return i.loadWheel().then(t=>{n.closed||(n.wheel=t.mountWheel(e,o.prizes))}).catch(()=>{}),e},code(){let e=d("div","k");return e.setAttribute("aria-live","polite"),n.codes.push(e),e},button:dt,decline(e){let t=d("button","btn no",e.label??"No thanks");return t.type="button",t.addEventListener("click",()=>j("decline")),t},countdown:ct,progress:pt,products:ut,image:Pe,video:Pe,spacer(e){let t=d("div","sp");return t.style.height=`${Xe[e.size]??Xe.md}px`,t.setAttribute("aria-hidden","true"),t},divider:()=>d("hr")};function ft(e,t){F.replaceChildren();let r=e.media,s=!r||t&&e.template!=="image-only";if(n.size=tt(v,e),_.className=`w t-${e.template} z-${n.size}${e.side==="right"?" right":""}${v.text_align==="center"?" ta-center":""}${s?" nm":""}`,_.style.setProperty("--sc",String(e.scrim)),E.className=`f pd-${e.padding}`,F.hidden=s,F.hidden)return;let c=le(r,"",n.step===a.steps[0],e.template==="split"?.46:1);if(!c)return;if(c.width?_.style.setProperty("--ar",`${c.width} / ${c.height}`):_.style.removeProperty("--ar"),e.template!=="image-only"){c.tagName==="IMG"&&e.template==="overlay"&&(c.alt=""),F.append(c);return}let u=V(r.href),g=u?ce(d("a","io"),u):d("button","io");u||(g.type="button",g.addEventListener("click",()=>re({action:"next"}))),g.append(c),F.append(g)}function mt(e){let t=e.blocks.find(c=>c?.t==="heading"),r=e.blocks.find(c=>c?.t==="button"&&c.action==="next"),s=d("button","tb");return s.textContent=t?d("b","",t.text).textContent:r?.label??"Open",s.type="button",s.addEventListener("click",()=>re(r??{action:"next"})),s}function D(e,t=new Set){let r=a.steps.find(z=>z.id===e);if(!r)return j("done");if(r.kind==="question"&&!h&&!p.analytics()&&!t.has(r.id))return D(K(r,n.answers),t.add(r.id));let s=n.step!==null,c=s&&(L.activeElement||document.activeElement===document.body),u=s&&!h?{mode:n.mode,w:_.offsetWidth,h:_.offsetHeight,top:_.offsetTop}:null;n.step=r,n.touched=!1;for(let z of n.timers.splice(0))Je(z);n.codes=[],n.videos=[],n.wheel=null;let g=$==="teaser"&&r===a.steps[0];if(n.mode=$==="teaser"&&!g?"popup":$,$==="teaser"&&w.tab?.(o.slot,g),B&&B.setAttribute("aria-label",g?S.closeOffer:"Close"),Te(),y.removeAttribute("aria-labelledby"),u){let z=_e();E.replaceWith(z),E=z}let m=et(r);ft(m,g);let f=u?.mode==="popup"&&n.mode==="popup";if(de(),u?.mode===n.mode&&u.h>0&&!f&&(_.style.setProperty("--lw",`${u.w}px`),_.style.setProperty("--lh",`${u.h}px`),_.classList.add("lk")),E.replaceChildren(),g&&m.template!=="image-only")E.append(mt(r));else for(let[z,P]of r.blocks.entries()){let q=M(P)&&Object.hasOwn(qe,P.t)?qe[P.t](P):null;q&&(h&&(q.dataset.hpBlock=String(z)),E.append(q))}let k=E.querySelector("[data-submit]"),A=E.querySelector("[name=hp_consent]")?.parentNode;k&&A&&k.before(A),E.hidden=E.childElementCount===0,N(null),ne(),y.hasAttribute("aria-labelledby")?y.removeAttribute("aria-label"):y.setAttribute("aria-label",m.media?.alt?.trim?.()||"Sign up"),f&&u.h>0&&ht(u),s&&Ne(),ae(),h||bt(r),c&&E.querySelector("h2")?.focus()}function de(){_.classList.remove("lk","an"),_.style.removeProperty("--tp")}function ht(e){let t=_.offsetHeight;_.classList.add("an");let r=_.offsetTop,s=Math.max(0,e.top-r);if(s+t>y.clientHeight-2*r)return de();_.style.setProperty("--tp",`${s}px`)}function bt(e){let t=e.next??{};for(let c of[t.default,...Object.values(M(t.answers)?t.answers:{}),...e.blocks.map(u=>u?.next),...Pt])typeof c=="string"&&n.toWarm.add(c);if(n.warming)return;n.warming=!0;let r=()=>{if(n.warming=!1,!n.closed&&T.isConnected)for(let c of n.toWarm)$e(o,a,c,n.warmed);n.toWarm.clear()},s=()=>globalThis.requestIdleCallback?requestIdleCallback(r,{timeout:2e3}):setTimeout(r,200);document.readyState==="complete"?s():window.addEventListener("load",s,{once:!0})}function Ne(){if(!R)return;let e=Ge.includes(n.mode);if(!(y.open&&n.modal===e)){try{y.open&&y.close()}catch{}if(n.modal=e,y.setAttribute("aria-modal",String(e)),e&&typeof y.showModal=="function")y.showModal();else if(typeof y.show=="function"){let t=document.activeElement;y.show(),t&&t!==document.body?t.focus?.({preventScroll:!0}):T.blur()}else y.setAttribute("open","");!e||typeof y.showModal!="function"?y.setAttribute("role","dialog"):y.removeAttribute("role")}}function gt(){for(let e of E.querySelectorAll("fieldset[data-question]")){let t=e.dataset.question,r=Ce.get(e)?.()??{};if(r.error)return r;let s=[r.value,...[...e.querySelectorAll("input:checked,select:not([name])")].map(c=>c.value)].filter(Boolean);s.length?n.answers[t]=s:delete n.answers[t]}}function xt(){let e=[];for(let[r,s]of Object.entries(n.answers)){let c=`${r}=${s.join(",")}`;n.sent.has(c)||(n.sent.add(c),e.push({question:r,values:s}))}let t=n.step.id;if(n.signedUp&&e.length)return void b.answers({anonymousId:p.anonymousId(),sessionId:p.sessionId()??void 0,slot:l.slot,arm:l.arm??void 0,decision_id:l.decision_id??void 0,step:t,...n.signedUp,answers:e,context:je()});if(p.analytics())for(let r of e)x.preferencesStated({...r,source:"onsite",slot:l.slot,arm:l.arm??null,decision_id:l.decision_id??null,step:t})}let je=()=>({page:{url:p.pageUrl()},locale:p.locale()??void 0,consent:p.consent()}),ie=e=>{n.receipt&&!h&&xt(),D(K(n.step,n.answers,e))};async function yt(e){let t=n.step,r=E.querySelector("input[name=email],input[name=phone]");if(!r)return ie(e.next);let s=r.name==="email"?"email":"sms",c=E.querySelector("select[name=hp_cc]")?.value,u=s==="email"?He(r.value.trim())?r.value.trim():null:Ye(r.value,c);if(!u)return N(s==="email"?S.email:c?S.phone:S.intl,r);let g=E.querySelector("input[name=hp_consent]");if(g&&!g.checked)return N(S.consent,g);N(null),G(!0);let m=await Oe();n.pow=null;let f=Object.entries(n.answers).map(([U,fe])=>({question:U,values:fe})),k=s==="sms"?o.sms_consent_text:o.consent_text,A=await b.capture({anonymousId:p.anonymousId(),sessionId:p.sessionId()??void 0,slot:l.slot,arm:l.arm??void 0,decision_id:l.decision_id??void 0,step:t.id,channel:s,[s==="email"?"email":"phone"]:u,...s==="sms"&&n.signedUp,consent_text:k?{id:k.id,version:k.version}:void 0,...f.length?{answers:f}:{},...m?{altcha:m}:{},context:je()}),z=A.body?.status,P=(A.status===202||A.status===200)&&Tt.includes(z);if(n.closed&&!P)return;P||G(!1);let q=A.status===400?A.body?.field:null;if(q==="email"||q==="phone")return N(S[q],r);if(!P)return N(A.status===429?S.busy:S.failed,r);r.value="";for(let[U,fe]of Object.entries(n.answers))n.sent.add(`${U}=${fe.join(",")}`);n.receipt=typeof A.body.receipt=="string"?A.body.receipt:null,s==="email"&&(n.signedUp={email:u,email_receipt:n.receipt}),n.submitted=!0,w.submitted(o.slot),ee("submit",t.id),n.owed=s==="email"&&o.prizes.length>0;let Y=n.owed?pe([]):null;Y||i.emit?.("submitted",{coupon:null});let At=Y&&await Promise.race([Y,new Promise(U=>setTimeout(U,Nt))]);if(n.closed)return;if(G(!1),At?.held)return D(oe("held"));let St=z!=="ok"&&a.steps.some(U=>U.id===z);D(St?z:K(t,n.answers,e.next));let Et=n.step;Y?.then(U=>{U?.held&&!n.closed&&n.step===Et&&!n.touched&&D(oe("held"))})}function oe(e){if(a.steps.some(s=>s.id===e))return e;let t={t:"button",label:S.shop,action:"close"},r=e==="unclaimed"?[{t:"heading",text:S.thanks},{t:"text",text:S.unclaimed},t]:e==="fallback"||n.claim?.code?[{t:"heading",text:e==="fallback"?S.thanks:S.yours},{t:"code"}]:[{t:"heading",text:S.held},{t:"text",text:o.code_relayed===!0?S.resent:S.inbox},t];return a.steps.push({id:e,blocks:r}),e}function Re(e){n.owed&&(n.owed=!1,i.emit?.("submitted",{coupon:e?{code:e.code??null,prize:e.prize?.key}:null}))}function pe(e=qt){let t=n.receipt;return n.claiming??(n.claiming=(async()=>{n.unclaimed=!1;let r;for(let g of[0,...e])if(g&&await new Promise(m=>setTimeout(m,g)),r=await b.claim({slot:l.slot,decision_id:l.decision_id??void 0,receipt:t}),r.status!==503)break;let s=r.body,c=s?.fallback===!0&&!s.code;if(r.status!==200||!(M(s?.prize)||c))return n.claiming=null,!e.length&&r.status===503?pe():(Re(null),n.unclaimed=!0,n.closed||ne(),null);let u=s.held&&!s.code?w.code?.():null;return u&&(s={...s,code:u}),n.claim=s,typeof s.code=="string"&&w.code?.(s.code),Re(s),n.closed||ne(),s})()),n.claiming}async function vt(e){if(!n.receipt)return N(S.spin);G(!0);let t=await pe();if(n.closed)return;if(!t)return G(!1),n.misses+=1,n.misses<2?N(S.retry):D(oe("unclaimed"));let r=t.fallback===!0&&!t.code,s=t.held?-1:o.prizes.findIndex(g=>g.key===t.prize?.key&&g.label===t.prize?.label);if(n.wheel&&s>=0&&!r){if(await n.wheel.spinTo(s),n.closed)return;O.className="e won",O.textContent=`${S.won} ${t.prize.label}`,await new Promise(g=>setTimeout(g,jt))}if(n.closed)return;G(!1);let c=r?"fallback":s<0?"held":null,u=c?oe(c):K(n.step,n.answers,e.next);u?D(u):ne()}function re(e){if(e.action==="close")return j("close");let t=gt();return h?ie(e.next):t?N(t.error,t.input):e.action==="apply"?(i.emit?.("apply",{coupon:n.claim?.code?{code:n.claim.code}:null}),ee("click"),K(n.step,n.answers,e.next)?ie(e.next):j("done")):e.action==="submit"?yt(e):e.action==="spin"?vt(e):ie(e.next)}function wt(e){if(e.preventDefault(),E.getAttribute("aria-busy")==="true")return;let t=n.step.blocks.find(r=>r?.t==="button"&&r.action==="submit");re(t??{action:"next"})}function ue(e=!1){n.closed=!0;for(let r of n.timers.splice(0))Je(r);document.removeEventListener("visibilitychange",ae),Q?.removeEventListener?.("change",Le);let t=()=>{try{y.open&&y.close()}catch{}T.remove()};if(e||!R||we())return t();y.classList.add("out"),setTimeout(t,It)}function j(e){n.closed||h||(!n.submitted&&e!=="done"&&ee("dismiss"),w.closed(o.slot),w.tab?.(o.slot,!1),ue(),i.onClose?.(e))}for(let e of["pointerdown","keydown","input"])y.addEventListener(e,()=>{n.touched=!0});y.addEventListener("cancel",e=>{e.preventDefault(),j("esc")}),y.addEventListener("keydown",e=>{e.key==="Escape"&&!n.modal&&$!=="inline"&&j("esc"),e.key==="Tab"&&n.modal&&kt(e)});function kt(e){let t=[...L.querySelectorAll("input[type=radio]:checked")],r=new Set,s=[...L.querySelectorAll("a[href],button,input,select,textarea")].filter(f=>{if(f.disabled||!f.getClientRects().length)return!1;if(f.type!=="radio")return!0;let k=t.find(A=>A.name===f.name);return(k?f!==k:r.has(f.name))?!1:(r.add(f.name),!0)});if(!s.length)return;let c=e.shiftKey,u=L.activeElement;u?.type==="radio"&&(u=s.find(f=>f.type==="radio"&&f.name===u.name)??u);let g=s.indexOf(u),m=null;if(g<0){let f=k=>u&&u.compareDocumentPosition(k)&4;m=c?s.findLast(k=>!f(k))??s.at(-1):s.find(f)??s[0]}else(c?g===0:g===s.length-1)&&(m=s.at(c?-1:0));m&&(e.preventDefault(),m.focus())}se.addEventListener("pointerdown",e=>{if(!n.mobile||n.mode!=="sheet")return;let t=e.clientY,r=0,s=u=>{r=Math.max(0,u.clientY-t),_.style.transform=`translateY(${r}px)`},c=()=>{document.removeEventListener("pointermove",s),document.removeEventListener("pointerup",c),_.style.transform="",r>80&&j("close")};document.addEventListener("pointermove",s),document.addEventListener("pointerup",c)});try{D(h?.step&&a.steps.some(e=>e.id===h.step)?h.step:a.steps[0].id),(i.container??document.body).append(T),Ne()}catch(e){throw ue(!0),e}return{close:j,root:L,host:T,show:D,step:()=>n.step?.id??null,modal:()=>!n.closed&&n.modal,destroy:()=>!n.closed&&ue()}}window[Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.render")]={mountForm:at,warm:$e};})();
181
+ `;var Ot=/^#(?:[0-9a-f]{3}){1,2}$/i,Je=["popup","fullscreen"],Mt=["ok","verify","already"],It=["stack","split","overlay","image-only"],Qe={bar:["bottom","top"],sheet:["bottom-right","bottom-left","bottom"],teaser:["bottom-left","bottom-right","left","right"]},Pt=["xs","sm","md","lg","xl","display"],et={xs:4,sm:8,md:16,lg:28,xl:44},tt={sm:380,md:480,lg:880},qt=["left","center","right"],nt={secondary:" b2",link:" no"},Nt=220,jt=["verify","already","held","fallback","success"],Rt=[500,1500],Dt=600,Ut=1800,S={email:"Enter a valid email address.",phone:"Enter a valid mobile number.",intl:"Enter a valid mobile number, starting with + and its country code.",consent:"Tick the box to sign up.",failed:"Something went wrong. Please try again.",busy:"Too many tries. Please wait a moment and try again.",spin:"Sign up first to spin.",yours:"Your code",held:"You\u2019re already on the list",resent:"We\u2019ve sent your code to your inbox again.",inbox:"Your code is in the email we sent when you first signed up.",shop:"Continue shopping",closeOffer:"Close offer",code:"We\u2019ll email your code to you.",claimed:"This email address has already claimed its code.",copied:"Copied",thanks:"Thanks, you\u2019re signed up",retry:"You\u2019re signed up, but we couldn\u2019t load your prize. Please try again.",unclaimed:"We couldn\u2019t load your prize right now.",unavailable:"Not available right now.",won:"You won"},H=(o,r,a)=>o.includes(r)?r:a,I=(o,r,a)=>Number.isFinite(o)?Math.min(Math.max(o,r),a):null,ke=o=>o.type==="date"||o.type==="number",Ae=()=>globalThis.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches===!0;function rt(o){let r=M(o.layout)?o.layout:{},a=M(r.media)?r.media:null,l=H(It,r.template,"stack"),p=a?.side==="right"?"right":"left";return!a&&M(r.image)&&r.image.side!=="none"&&(a=r.image,r.image.side!=="top"&&(l="split",p=r.image.side==="right"?"right":"left")),(!a||!K(a.asset))&&(a=null,l="stack"),{template:l,media:a,side:p,scrim:I(r.scrim,0,.9)??.45,padding:H(["none","sm","md","lg"],r.padding,"md")}}var st=(o,r)=>H(["sm","md","lg","full"],o.size,null)??(r.template==="split"||r.template==="overlay"?"lg":"md"),at=(o,r,a=1,l="100vw")=>{if(o==="fullscreen"||r==="full")return l;let p=o==="teaser"?220:o==="sheet"?400:tt[r]??tt.md;return`(max-width: 639px) ${l}, ${Math.round(p*a)}px`},lt=(o,r)=>o==="lg"?1/Ze(r):.5,ct=(o,r,a)=>{if(!a||!Array.isArray(o.widths)||!r.endsWith(".webp"))return null;let l=o.widths.filter(p=>Number.isInteger(p)&&p>0&&p<a).sort((p,x)=>p-x);return l.length===0?null:[...l.map(p=>`${r.slice(0,-5)}-${p}w.webp ${p}w`),`${r} ${a}w`].join(",")},dt=(o,r)=>o.format==="inline"?"inline":r.format&&r.format!=="inline"?r.format:o.format,Ee=o=>o.kind==="video"||o.t==="video",$e={webm:"video/webm",mp4:"video/mp4",m4v:"video/mp4",mov:"video/quicktime",ogv:"video/ogg"},_e=o=>$e[o.split(/[?#]/)[0].split(".").pop().toLowerCase()],Wt=(o,r)=>[...new Set([r,...Array.isArray(o.sources)?o.sources.map(K):[]])].filter(Boolean).sort((a,l)=>(_e(l)===$e.webm)-(_e(a)===$e.webm));function ze(o,r,a,l=new Set){let p=r.steps.find(v=>v.id===a);if(!p)return Promise.resolve();let x=dt(o,r),b=rt(p),w=x==="teaser"&&p===r.steps[0],h=x==="teaser"&&!w?"popup":x,C=st(r.theme,b),$=w?[]:p.blocks.flatMap(v=>{if(v?.t==="image"||v?.t==="video")return[[v]];let W=v?.display==="cards"&&o.questions.find(T=>T.key===v.question&&T.type==="one");return W?Object.values(v.pictures??{}).filter(M).map(T=>[T,lt(C,W),"50vw"]):[]});return b.media&&!(w&&b.template!=="image-only")&&$.push([b.media,b.template==="split"?.46:1]),Promise.all($.map(([v,W,T])=>{let L=K(Ee(v)?v.poster:v.asset);if(!L)return null;let j=document.createElement("img"),y=!Ee(v)&&ct(v,L,I(v.width,1,8192));y&&(j.sizes=at(h,C,W,T),j.srcset=y);let Z=`${j.sizes} ${y||L}`;return l.has(Z)?null:(l.add(Z),j.src=L,j.decode?.().catch(()=>{}))}))}var it=o=>o?.call?o():clearInterval(o),Ft=0,Se=o=>`hp-${o}-${++Ft}`;function d(o,r,a){let l=document.createElement(o);return r&&(l.className=r),a!==void 0&&l.append(Ve(a)),l}var pt=o=>{let r=o.length===4?[...o.slice(1)].map(a=>a+a).join(""):o.slice(1);return[0,2,4].map(a=>Number.parseInt(r.slice(a,a+2),16))},te=o=>{let[r,a,l]=pt(o).map(p=>{let x=p/255;return x<=.04045?x/12.92:((x+.055)/1.055)**2.4});return .2126*r+.7152*a+.0722*l},ot=(o,r=4.5)=>{let a=te(o)+.05,l=1.05/a;return l>=r?"#fff":a/(te("#111")+.05)>l?"#111":"#fff"};function Yt(o,r){let a=($,v)=>v&&o.style.setProperty($,v),l=$=>Ot.test($??"")?$:null;a("--hp-accent",l(r.accent)),a("--hp-bg",l(r.background)),a("--hp-text",l(r.text));let p=I(r.radius,0,48);p!==null&&a("--hp-radius",`${p}px`),a("--hp-font",r.font==="site"?o.ownerDocument.defaultView.getComputedStyle(o.parentElement??o.ownerDocument.body).fontFamily:Object.hasOwn(ve,r.font)?ve[r.font]:null),l(r.accent)&&(a("--hp-on-accent",ot(r.accent,3)),a("--hp-on-accent-text",ot(r.accent))),l(r.background)&&te(r.background)<.18&&(a("--hp-field","#fff"),a("--hp-field-text","#111"));let x=M(r.overlay)?r.overlay:{},b=[l(r.text),l(r.background)].filter(Boolean).sort(($,v)=>te($)-te(v))[0],[w,h,C]=pt(l(x.colour)??b??"#0b0b0f");a("--hp-ov",`rgb(${w} ${h} ${C} / ${I(x.opacity,0,1)??.6})`)}function Ht(o){try{let r=new CSSStyleSheet;r.replaceSync(we),o.adoptedStyleSheets=[r]}catch{let r=document.createElement("style");r.textContent=we,o.append(r)}}function ut(o){let{form:r,creative:a,decision:l,access:p,client:x,api:b,counters:w}=o,h=o.preview??null,C=e=>{let t=e.blocks.find(i=>i?.t==="email"||i?.t==="phone");return t?.t==="phone"||!t&&!r.consent_text?r.sms_consent_text:r.consent_text},$=dt(r,a),v=a.theme,W=H(Qe[$]??[],v.position,Qe[$]?.[0]),T=document.createElement("hp-onsite");h&&T.setAttribute("preview",""),Yt(T,v);let L=T.attachShadow({mode:"open"});Ht(L);let j=$!=="inline"&&!h,y=d(j?"dialog":$==="inline"?"section":"div"),Z=d("div","ov"),_=d("div","w"),F=d("div","m");h&&(F.dataset.hpMedia="");let Ce=()=>{let e=d("form","f");return e.noValidate=!0,e.addEventListener("submit",St),e.addEventListener("input",()=>{O.textContent&&E.getAttribute("aria-busy")!=="true"&&N(null)}),e},E=Ce(),O=d("p","e");O.id=Se("err"),O.setAttribute("aria-live","assertive");let se=d("div","hd");se.setAttribute("aria-hidden","true"),_.append(se,F,E),y.append(Z,_);let B=$!=="inline"&&d("button","x");B&&(B.type="button",B.addEventListener("click",()=>D("close")),_.append(B),Z.addEventListener("click",()=>D("close"))),L.append(y);let n={step:null,mode:$,size:"md",modal:!1,mobile:h?.device==="mobile",answers:{},answeredOn:{},sent:new Set,clicked:!1,seen:new Set,receipt:null,claim:o.coupon?{code:o.coupon}:h?{code:"WELCOME15"}:null,claiming:null,touched:!1,toWarm:new Set,warmed:o.warmed??new Set,warming:!1,owed:!1,unclaimed:!1,misses:0,submitted:!1,pow:null,wheel:null,timers:[],codes:[],videos:[],closed:!1},J=r.locale||document.documentElement.lang,Te=(r.questions.some(ke)||a.steps.some(e=>e.blocks.some(t=>t?.t==="countdown"||t?.display==="cards")))&&o.loadAnswers().catch(()=>null),Le=new WeakMap,Oe=()=>{let e=M(v.button)?v.button:{};y.className=`s ${n.mode}${W?` p-${W}`:""} b-${H(["pill","rounded","square"],e.shape,"rounded")}${n.mobile?" mob":""}${h?" pv":""}${e.style==="outline"?" bo":""}${v.caps===!0?" uc":""}`},Q=h?null:globalThis.matchMedia?.("(max-width: 639px)"),Me=()=>{n.mobile=Q?.matches===!0,pe(),Oe()};Q&&(n.mobile=Q.matches===!0,Q.addEventListener?.("change",Me));let ae=!r.channels?.length,G=(e,t,i={})=>{if(!(h||!l.decision_id||!p.analytics())){if(e==="click"){let s=n.clicked;if(n.clicked=!0,s&&!i.products)return}x.slotEngaged({decision_id:l.decision_id,slot:l.slot,arm:l.arm??null,engagement:e,step:t??n.step?.id??null,...i})}},N=(e,t)=>{O.className="e",O.textContent=e??"";for(let s of E.querySelectorAll("[aria-invalid]"))s.removeAttribute("aria-invalid");let i=t?.closest("label,fieldset");i&&E.contains(i)?i.after(O):E.append(O),t&&(t.setAttribute("aria-invalid","true"),t.setAttribute("aria-describedby",O.id),t.focus(),t.scrollIntoView?.({block:"nearest"}))},V=e=>{E.setAttribute("aria-busy",String(e));for(let t of E.querySelectorAll("button"))t.disabled=e},Ie=()=>h?Promise.resolve(null):(n.pow??(n.pow=b.challenge().then(e=>e.status===200?Ge(e.body):null).catch(()=>null)),n.pow),le=()=>{for(let e of n.videos)try{document.hidden||Ae()?e.pause():e.play()?.catch?.(()=>{})}catch{}};document.addEventListener("visibilitychange",le);function ce(e,t,i,s,c){let u=K(e.asset);if(!u)return null;let g=typeof e.alt=="string"?e.alt:"",m;if(Ee(e)){m=d("video",t),m.muted=m.defaultMuted=m.loop=m.playsInline=!0;let A=K(e.poster);A&&(m.poster=A),g?m.setAttribute("aria-label",g):m.setAttribute("aria-hidden","true"),m.autoplay=!Ae()&&!h,m.preload=m.autoplay?"auto":A?"none":"metadata";let z=Wt(e,u);if(z.length>1)for(let P of z){let q=d("source");q.src=P;let Y=_e(P);Y&&(q.type=Y),m.append(q)}else m.src=u;n.videos.push(m)}else{m=d("img",t),m.alt=g,m.decoding="async",m.loading=i?"eager":"lazy",i&&(m.fetchPriority="high");let A=ct(e,u,I(e.width,1,8192));A&&(m.sizes=at(n.mode,n.size,s,c),m.srcset=A),m.src=u}let f=I(e.width,1,8192),k=I(e.height,1,8192);return f&&k&&(m.width=f,m.height=k),M(e.focal)&&(m.style.objectPosition=`${I(e.focal.x,0,100)??50}% ${I(e.focal.y,0,100)??50}%`),m}function Pe(e,t){let i=d("label","l");i.append(d("span","lt",e.label??(t==="email"?"Email":"Mobile number")));let s=d("input","i");if(s.type=t,s.name=t==="email"?"email":"phone",s.autocomplete=s.inputMode=t,s.required=!0,typeof e.placeholder=="string"&&(s.placeholder=e.placeholder),s.setAttribute("aria-describedby",O.id),s.addEventListener("focus",Ie,{once:!0}),t!=="tel")return i.append(s),i;s.id=`${O.id}-p`,i.htmlFor=s.id;let c=xe(d,"Country code","+",Object.entries(ge).map(([g,m])=>[g,`${g} +${m}`]),(e.country||/-(\w\w)$/.exec(J)?.[1]||"").toUpperCase());c.classList.add("cc"),c.name="hp_cc";let u=d("span","ph");return u.append(c,s),i.append(u),i}function ft(e){let t=r.questions.find(f=>f.key===e.question);if(!t||!ke(t)&&!Array.isArray(t.options))return null;let i=d("fieldset");i.dataset.question=t.key,i.append(d("legend","",t.label??""));let s=n.answers[t.key]??[],c=e.display==="cards"&&t.type==="one";if(ke(t)||c)return Te.then(f=>{if(!f)return i.append(d("p","sm",S.unavailable));if(c)return f.answerCards(i,t,e,d,s,k=>ce(k,"qi",!1,lt(n.size,t),"50vw"),L);f.answerFields(i,t,d,s[0],J),Le.set(i,()=>f.answerOf(i,t,void 0,J))}),i;let u=t.type==="many",g=H(["list","dropdown"],e.display,"buttons"),m=t.options.filter(f=>M(f)&&typeof f.value=="string");if(g==="dropdown"&&!u)return i.append(xe(d,t.label??t.key,"\u2014",m.map(f=>[f.value,f.label??f.value]),s[0])),i;g!=="buttons"&&(i.className="ls");for(let f of m){let k=d("label",g==="buttons"?"ch":"c"),A=d("input");A.type=u?"checkbox":"radio",A.name=`q_${t.key}`,A.value=f.value,A.checked=s.includes(f.value),k.append(A,d("span","",f.label??f.value)),i.append(k)}return i}function ne(){for(let e of n.codes){if(e.replaceChildren(),!n.claim){n.unclaimed&&e.append(d("p","",S.unclaimed));continue}if(!n.claim.code){let s=n.claim.held?S.claimed:n.claim.fallback===!0?S.code:n.claim.prize?.label;s&&e.append(d("p","",s));continue}n.claim.prize?.label&&e.append(d("p","",n.claim.prize.label));let t=d("output");t.textContent=n.claim.code;let i=d("button","btn cp");i.type="button",i.textContent="Copy code",i.addEventListener("click",()=>{navigator.clipboard?.writeText(n.claim.code).then(()=>{i.textContent=S.copied}).catch(()=>{})}),e.append(t,i)}}function mt(e){if(n.claim&&!n.claim.code)return null;let t=d("div","cd");return t.hidden=!0,Te.then(i=>i&&t.isConnected&&n.timers.push(i.countdown(t,e,h,d))),t}function de(e,t){return e.href=t,e.rel="noopener",e.addEventListener("click",i=>{if(h)return i.preventDefault();G("click"),We()}),e}function ht(e){let t=e.label??"Continue";if(e.action==="link"){let s=X(e.href);return s?de(d("a",`btn${nt[e.variant]??""}`,t),s):null}let i=d("button",`btn${nt[e.variant]??""}`,t);return i.type=e.action==="submit"?"submit":"button",i.type==="button"?i.addEventListener("click",()=>re(e)):i.dataset.submit="",i}let qe=(e,t,i)=>(e.classList.add(`x-${H(Pt,t.size,i)}`),qt.includes(t.align)&&e.classList.add(`a-${t.align}`),e);function Ne(e){let t=ce(e,"bi",n.step===a.steps[0]);if(!t)return null;t.style.objectFit=e.fit==="contain"?"contain":"cover";let i=I(e.radius,0,48);i!==null&&(t.style.borderRadius=`${i}px`);let s=I(e.max_height,40,800);if(s!==null&&(t.style.maxHeight=`${s}px`),!t.width&&e.fit!=="contain"&&(t.style.aspectRatio="16 / 9"),e.t==="video"||!X(e.href))return t;let c=de(d("a","bl"),X(e.href));return c.append(t),c}function bt(e){let t=I(e.threshold,.01,1e7);if(!t)return null;let i=d("div","pg"),s=d("p"),c=d("div","tr"),u=d("i");c.append(u),c.setAttribute("role","progressbar"),c.setAttribute("aria-valuemin","0"),c.setAttribute("aria-valuemax",String(t)),i.append(s,c);let g=f=>f.toFixed(2);try{let f=new Intl.NumberFormat(J||void 0,{style:"currency",currency:e.currency});g=k=>f.format(k)}catch{}let m=()=>{let f=Math.max(0,Number(o.basket?.())||0),k=t-f;s.textContent=k>0?String(e.text??"").replace("{amount}",g(k)):e.done??"",u.style.transform=`scaleX(${Math.min(1,f/t)})`,c.setAttribute("aria-valuenow",String(Math.min(f,t))),s.id||(s.id=Se("pg")),c.setAttribute("aria-labelledby",s.id)};return m(),n.timers.push(setInterval(m,2e3)),i}function gt(e){let t=d("div","pr");return o.loadProducts?.().then(i=>{t.isConnected&&n.timers.push(i.mountProducts(t,e,{el:d,lang:J,root:L,placement:r.slot,preview:h,client:!h&&p.analytics()&&x,engaged:G,seen:n.seen}))}).catch(()=>{}),t}let je={heading(e){let t=qe(d("h2","",e.text),e,"xl");return t.id=Se("h"),t.tabIndex=-1,y.hasAttribute("aria-labelledby")||(y.setAttribute("aria-labelledby",t.id),n.step===a.steps[0]&&Je.includes(n.mode)&&!h&&(t.autofocus=!0)),t},text:e=>qe(d("p","",e.text),e,"md"),email:e=>Pe(e,"email"),phone:e=>Pe(e,"tel"),consent(e){let t=C(n.step)?.text;if(typeof t!="string")return null;if(e.required!==!0)return d("p","sm",t);let i=d("label","c"),s=d("input");return s.type="checkbox",s.name="hp_consent",s.required=!0,s.setAttribute("aria-describedby",O.id),i.append(s,d("span","",t)),i},question:ft,wheel(){let e=d("div","wh");return o.loadWheel().then(t=>{n.closed||(n.wheel=t.mountWheel(e,r.prizes))}).catch(()=>{}),e},code(){let e=d("div","k");return e.setAttribute("aria-live","polite"),n.codes.push(e),e},button:ht,decline(e){let t=d("button","btn no",e.label??"No thanks");return t.type="button",t.addEventListener("click",()=>D("decline")),t},countdown:mt,progress:bt,products:gt,image:Ne,video:Ne,spacer(e){let t=d("div","sp");return t.style.height=`${et[e.size]??et.md}px`,t.setAttribute("aria-hidden","true"),t},divider:()=>d("hr")};function xt(e,t){F.replaceChildren();let i=e.media,s=!i||t&&e.template!=="image-only";if(n.size=st(v,e),_.className=`w t-${e.template} z-${n.size}${e.side==="right"?" right":""}${v.text_align==="center"?" ta-center":""}${s?" nm":""}`,_.style.setProperty("--sc",String(e.scrim)),E.className=`f pd-${e.padding}`,F.hidden=s,F.hidden)return;let c=ce(i,"",n.step===a.steps[0],e.template==="split"?.46:1);if(!c)return;if(c.width?_.style.setProperty("--ar",`${c.width} / ${c.height}`):_.style.removeProperty("--ar"),e.template!=="image-only"){c.tagName==="IMG"&&e.template==="overlay"&&(c.alt=""),F.append(c);return}let u=X(i.href),g=u?de(d("a","io"),u):d("button","io");u||(g.type="button",g.addEventListener("click",()=>re({action:"next"}))),g.append(c),F.append(g)}function yt(e){let t=e.blocks.find(c=>c?.t==="heading"),i=e.blocks.find(c=>c?.t==="button"&&c.action==="next"),s=d("button","tb");return s.textContent=t?d("b","",t.text).textContent:i?.label??"Open",s.type="button",s.addEventListener("click",()=>re(i??{action:"next"})),s}function R(e,t=new Set){let i=a.steps.find(z=>z.id===e);if(!i)return D("done");if(i.kind==="question"&&!h&&!p.analytics()&&!t.has(i.id))return R(ee(i,n.answers),t.add(i.id));let s=n.step!==null,c=s&&(L.activeElement||document.activeElement===document.body),u=s&&!h?{mode:n.mode,w:_.offsetWidth,h:_.offsetHeight,top:_.offsetTop}:null;n.step=i,n.touched=!1;for(let z of n.timers.splice(0))it(z);n.codes=[],n.videos=[],n.wheel=null;let g=$==="teaser"&&i===a.steps[0];if(n.mode=$==="teaser"&&!g?"popup":$,$==="teaser"&&w.tab?.(r.slot,g),B&&B.setAttribute("aria-label",g?S.closeOffer:"Close"),Oe(),y.removeAttribute("aria-labelledby"),u){let z=Ce();E.replaceWith(z),E=z}let m=rt(i);xt(m,g);let f=u?.mode==="popup"&&n.mode==="popup";if(pe(),u?.mode===n.mode&&u.h>0&&!f&&(_.style.setProperty("--lw",`${u.w}px`),_.style.setProperty("--lh",`${u.h}px`),_.classList.add("lk")),E.replaceChildren(),g&&m.template!=="image-only")E.append(yt(i));else for(let[z,P]of i.blocks.entries()){let q=M(P)&&Object.hasOwn(je,P.t)?je[P.t](P):null;q&&(h&&(q.dataset.hpBlock=String(z)),E.append(q))}let k=E.querySelector("[data-submit]"),A=E.querySelector("[name=hp_consent]")?.parentNode;k&&A&&k.before(A),E.hidden=E.childElementCount===0,N(null),ne(),y.hasAttribute("aria-labelledby")?y.removeAttribute("aria-label"):y.setAttribute("aria-label",m.media?.alt?.trim?.()||"Sign up"),f&&u.h>0&&vt(u),s&&Re(),le(),h||wt(i),c&&E.querySelector("h2")?.focus()}function pe(){_.classList.remove("lk","an"),_.style.removeProperty("--tp")}function vt(e){let t=_.offsetHeight;_.classList.add("an");let i=_.offsetTop,s=Math.max(0,e.top-i);if(s+t>y.clientHeight-2*i)return pe();_.style.setProperty("--tp",`${s}px`)}function wt(e){let t=e.next??{};for(let c of[t.default,...Object.values(M(t.answers)?t.answers:{}),...e.blocks.map(u=>u?.next),...jt])typeof c=="string"&&n.toWarm.add(c);if(n.warming)return;n.warming=!0;let i=()=>{if(n.warming=!1,!n.closed&&T.isConnected)for(let c of n.toWarm)ze(r,a,c,n.warmed);n.toWarm.clear()},s=()=>globalThis.requestIdleCallback?requestIdleCallback(i,{timeout:2e3}):setTimeout(i,200);document.readyState==="complete"?s():window.addEventListener("load",s,{once:!0})}function Re(){if(!j)return;let e=Je.includes(n.mode);if(!(y.open&&n.modal===e)){try{y.open&&y.close()}catch{}if(n.modal=e,y.setAttribute("aria-modal",String(e)),e&&typeof y.showModal=="function")y.showModal();else if(typeof y.show=="function"){let t=document.activeElement;y.show(),t&&t!==document.body?t.focus?.({preventScroll:!0}):T.blur()}else y.setAttribute("open","");!e||typeof y.showModal!="function"?y.setAttribute("role","dialog"):y.removeAttribute("role")}}function De(){for(let e of E.querySelectorAll("fieldset[data-question]")){let t=e.dataset.question,i=Le.get(e)?.()??{};if(i.error)return i;let s=[i.value,...[...e.querySelectorAll("input:checked,select:not([name])")].map(c=>c.value)].filter(Boolean);s.length?(n.answers[t]=s,n.answeredOn[t]=n.step.id):delete n.answers[t]}}function Ue(){let e=Object.entries(n.answers).map(([i,s])=>({question:i,values:s})).filter(i=>!n.sent.has(ue(i))),t=({question:i})=>n.answeredOn[i];if(n.signedUp){for(let i of new Set(e.map(t))){let s=e.filter(c=>t(c)===i);for(let c of s)n.sent.add(ue(c));b.answers({anonymousId:p.anonymousId(),sessionId:p.sessionId()??void 0,slot:l.slot,arm:l.arm??void 0,decision_id:l.decision_id??void 0,step:i,...n.signedUp,answers:s,context:Fe()})}return}if(p.analytics())for(let i of e)n.sent.add(ue(i)),x.preferencesStated({...i,source:"onsite",slot:l.slot,arm:l.arm??null,decision_id:l.decision_id??null,step:t(i)})}let ue=({question:e,values:t})=>`${e}=${t.join(",")}`,We=()=>{ae&&(De(),Ue())},Fe=()=>({page:{url:p.pageUrl()},locale:p.locale()??void 0,consent:p.consent()}),ie=e=>{!h&&(n.receipt||ae)&&Ue(),R(ee(n.step,n.answers,e))};async function kt(e){let t=n.step,i=E.querySelector("input[name=email],input[name=phone]");if(!i)return ie(e.next);let s=i.name==="email"?"email":"sms",c=E.querySelector("select[name=hp_cc]")?.value,u=s==="email"?Ke(i.value.trim())?i.value.trim():null:Xe(i.value,c);if(!u)return N(s==="email"?S.email:c?S.phone:S.intl,i);let g=E.querySelector("input[name=hp_consent]");if(g&&!g.checked)return N(S.consent,g);N(null),V(!0);let m=await Ie();n.pow=null;let f=Object.entries(n.answers).map(([U,he])=>({question:U,values:he})),k=s==="sms"?r.sms_consent_text:r.consent_text,A=await b.capture({anonymousId:p.anonymousId(),sessionId:p.sessionId()??void 0,slot:l.slot,arm:l.arm??void 0,decision_id:l.decision_id??void 0,step:t.id,channel:s,[s==="email"?"email":"phone"]:u,...s==="sms"&&n.signedUp,consent_text:k?{id:k.id,version:k.version}:void 0,...f.length?{answers:f}:{},...m?{altcha:m}:{},context:Fe()}),z=A.body?.status,P=(A.status===202||A.status===200)&&Mt.includes(z);if(n.closed&&!P)return;P||V(!1);let q=A.status===400?A.body?.field:null;if(q==="email"||q==="phone")return N(S[q],i);if(!P)return N(A.status===429?S.busy:S.failed,i);i.value="";for(let[U,he]of Object.entries(n.answers))n.sent.add(`${U}=${he.join(",")}`);n.receipt=typeof A.body.receipt=="string"?A.body.receipt:null,s==="email"&&(n.signedUp={email:u,email_receipt:n.receipt}),n.submitted=!0,w.submitted(r.slot),G("submit",t.id),n.owed=s==="email"&&r.prizes.length>0;let Y=n.owed?fe([]):null;Y||o.emit?.("submitted",{coupon:null});let $t=Y&&await Promise.race([Y,new Promise(U=>setTimeout(U,Dt))]);if(n.closed)return;if(V(!1),$t?.held)return R(oe("held"));let _t=z!=="ok"&&a.steps.some(U=>U.id===z);R(_t?z:ee(t,n.answers,e.next));let zt=n.step;Y?.then(U=>{U?.held&&!n.closed&&n.step===zt&&!n.touched&&R(oe("held"))})}function oe(e){if(a.steps.some(s=>s.id===e))return e;let t={t:"button",label:S.shop,action:"close"},i=e==="unclaimed"?[{t:"heading",text:S.thanks},{t:"text",text:S.unclaimed},t]:e==="fallback"||n.claim?.code?[{t:"heading",text:e==="fallback"?S.thanks:S.yours},{t:"code"}]:[{t:"heading",text:S.held},{t:"text",text:r.code_relayed===!0?S.resent:S.inbox},t];return a.steps.push({id:e,blocks:i}),e}function Ye(e){n.owed&&(n.owed=!1,o.emit?.("submitted",{coupon:e?{code:e.code??null,prize:e.prize?.key}:null}))}function fe(e=Rt){let t=n.receipt;return n.claiming??(n.claiming=(async()=>{n.unclaimed=!1;let i;for(let g of[0,...e])if(g&&await new Promise(m=>setTimeout(m,g)),i=await b.claim({slot:l.slot,decision_id:l.decision_id??void 0,receipt:t}),i.status!==503)break;let s=i.body,c=s?.fallback===!0&&!s.code;if(i.status!==200||!(M(s?.prize)||c))return n.claiming=null,!e.length&&i.status===503?fe():(Ye(null),n.unclaimed=!0,n.closed||ne(),null);let u=s.held&&!s.code?w.code?.():null;return u&&(s={...s,code:u}),n.claim=s,typeof s.code=="string"&&w.code?.(s.code),Ye(s),n.closed||ne(),s})()),n.claiming}async function At(e){if(!n.receipt)return N(S.spin);V(!0);let t=await fe();if(n.closed)return;if(!t)return V(!1),n.misses+=1,n.misses<2?N(S.retry):R(oe("unclaimed"));let i=t.fallback===!0&&!t.code,s=t.held?-1:r.prizes.findIndex(g=>g.key===t.prize?.key&&g.label===t.prize?.label);if(n.wheel&&s>=0&&!i){if(await n.wheel.spinTo(s),n.closed)return;O.className="e won",O.textContent=`${S.won} ${t.prize.label}`,await new Promise(g=>setTimeout(g,Ut))}if(n.closed)return;V(!1);let c=i?"fallback":s<0?"held":null,u=c?oe(c):ee(n.step,n.answers,e.next);u?R(u):ne()}function re(e){if(e.action==="close")return D("close");let t=De();return h?ie(e.next):t?N(t.error,t.input):(ae&&n.step.blocks.some(i=>n.answers[i?.question])&&G("click"),e.action==="apply"?(o.emit?.("apply",{coupon:n.claim?.code?{code:n.claim.code}:null}),G("click"),ie(e.next)):e.action==="submit"?kt(e):e.action==="spin"?At(e):ie(e.next))}function St(e){if(e.preventDefault(),E.getAttribute("aria-busy")==="true")return;let t=n.step.blocks.find(i=>i?.t==="button"&&i.action==="submit");re(t??{action:"next"})}function me(e=!1){n.closed=!0;for(let i of n.timers.splice(0))it(i);document.removeEventListener("visibilitychange",le),Q?.removeEventListener?.("change",Me);let t=()=>{try{y.open&&y.close()}catch{}T.remove()};if(e||!j||Ae())return t();y.classList.add("out"),setTimeout(t,Nt)}function D(e){n.closed||h||(We(),!n.submitted&&e!=="done"&&G("dismiss"),w.closed(r.slot),w.tab?.(r.slot,!1),me(),o.onClose?.(e))}for(let e of["pointerdown","keydown","input"])y.addEventListener(e,()=>{n.touched=!0});y.addEventListener("cancel",e=>{e.preventDefault(),D("esc")}),y.addEventListener("keydown",e=>{e.key==="Escape"&&!n.modal&&$!=="inline"&&D("esc"),e.key==="Tab"&&n.modal&&Et(e)});function Et(e){let t=[...L.querySelectorAll("input[type=radio]:checked")],i=new Set,s=[...L.querySelectorAll("a[href],button,input,select,textarea")].filter(f=>{if(f.disabled||!f.getClientRects().length)return!1;if(f.type!=="radio")return!0;let k=t.find(A=>A.name===f.name);return(k?f!==k:i.has(f.name))?!1:(i.add(f.name),!0)});if(!s.length)return;let c=e.shiftKey,u=L.activeElement;u?.type==="radio"&&(u=s.find(f=>f.type==="radio"&&f.name===u.name)??u);let g=s.indexOf(u),m=null;if(g<0){let f=k=>u&&u.compareDocumentPosition(k)&4;m=c?s.findLast(k=>!f(k))??s.at(-1):s.find(f)??s[0]}else(c?g===0:g===s.length-1)&&(m=s.at(c?-1:0));m&&(e.preventDefault(),m.focus())}se.addEventListener("pointerdown",e=>{if(!n.mobile||n.mode!=="sheet")return;let t=e.clientY,i=0,s=u=>{i=Math.max(0,u.clientY-t),_.style.transform=`translateY(${i}px)`},c=()=>{document.removeEventListener("pointermove",s),document.removeEventListener("pointerup",c),_.style.transform="",i>80&&D("close")};document.addEventListener("pointermove",s),document.addEventListener("pointerup",c)});try{R(h?.step&&a.steps.some(e=>e.id===h.step)?h.step:a.steps[0].id),(o.container??document.body).append(T),Re()}catch(e){throw me(!0),e}return{close:D,root:L,host:T,show:R,step:()=>n.step?.id??null,modal:()=>!n.closed&&n.modal,destroy:()=>!n.closed&&me()}}window[Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.render")]={mountForm:ut,warm:ze};})();
@@ -1 +1 @@
1
- (()=>{function E(e){let s=typeof document>"u"?null:document.currentScript?.src;return s?new URL(e,s).href:null}var G=new Map;function x(e,s){return window[s]?Promise.resolve(window[s]):e?(G.has(s)||G.set(s,new Promise((n,i)=>{let u=document.createElement("script");u.src=e,u.async=!0,u.onload=()=>window[s]?n(window[s]):i(new Error(`${e} did not register`)),u.onerror=()=>i(new Error(`${e} did not load`)),document.head.append(u)}).finally(()=>G.delete(s))),G.get(s)):Promise.reject(new Error("the CDN script\u2019s own URL is unknown"))}var nt=E("onsite-answers.min.js"),ge=()=>x(nt,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.answers"));var st="/v1/capture/challenge",ot=e=>typeof e=="string"&&/^\/v1\/[\w/-]+$/.test(e)?e:st;function we(e,s={}){let n=s.fetch??globalThis.fetch?.bind(globalThis),i=s.servingHost??e.servingHost,u=s.gatewayHost??e.gatewayHost;async function r(p,{method:f="GET",body:o,consent:a=!1,timeoutMs:c}={}){if(!n)return{status:0,body:null};try{let y=await n(p,{method:f,credentials:"omit",signal:c&&AbortSignal.timeout?.(c),headers:{accept:"application/json",authorization:`Bearer ${e.writeKey}`,...o?{"content-type":"application/json"}:{},...a?e.headers():{}},...o?{body:JSON.stringify(o)}:{}}),_=null;try{_=await y.json()}catch{}return{status:y.status,body:_}}catch{return{status:0,body:null}}}return{decide:(p,f,{visitAudiences:o,visitCampaign:a,visitContext:c,timeoutMs:y=3e3}={})=>r(`${i}/v1/decisions`,{method:"POST",consent:!0,timeoutMs:Math.max(1,y),body:{slots:[f?{key:p,pin:{experiment:f[0],arm:f[1],split:f[2]}}:p],library:e.library,identifier_value:e.anonymousId()??void 0,session_id:e.sessionId()??void 0,identity_token:e.identityToken?.()??void 0,...e.preview?{preview:e.preview}:{},...o?{visit_audiences:o}:{},...a?{visit_campaign:a}:{},...c?{visit_context:c}:{}}}),datafile:()=>r(`${i}/v1/audiences/datafile`,{timeoutMs:1500}),challenge:()=>r(`${u}${ot(s.challenge)}`),capture:p=>r(`${u}/v1/capture`,{method:"POST",body:p}),answers:p=>r(`${u}/v1/capture/answers`,{method:"POST",body:p}),claim:p=>r(`${i}/v1/offers/claim`,{method:"POST",consent:!0,body:p,timeoutMs:8e3})}}var it=E("onsite-audiences.min.js"),ye=()=>x(it,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.audiences"));function be(e,s){let n={},i=()=>{try{let r=JSON.parse(e().getItem(s));r&&typeof r=="object"&&(n=r)}catch{}return n};return{read:i,write:r=>{let p=i();r(p),n=p;try{e().setItem(s,JSON.stringify(p))}catch{}}}}function Se(e,s=()=>!0){let n=be(()=>sessionStorage,e),i=be(()=>localStorage,e),u=()=>s()?i:n,r=()=>{let o=i.read();(o.sub!==void 0||o.k!==void 0)&&i.write(a=>{delete a.sub,delete a.k})},p=()=>s()?[n.read(),i.read()]:(r(),[n.read()]),f=(o,a)=>{var c;return o.f??(o.f={}),(c=o.f)[a]??(c[a]={}),o.f[a]};return{seen(o){let a=i.read().f?.[o]??{};return{session:n.read().f?.[o]?.n??0,lifetime:a.n??0,closedAt:a.c??null,submitted:a.s===1}},subscribed:()=>p().some(o=>o.sub===1),shown(o){n.write(a=>{let c=f(a,o);c.n=(c.n??0)+1}),i.write(a=>{let c=f(a,o);c.n=(c.n??0)+1})},closed(o,a=Date.now()){i.write(c=>{f(c,o).c=a})},tab(o,a){n.write(c=>{let y=f(c,o);a?y.t=1:delete y.t})},tabOut:o=>n.read().f?.[o]?.t===1,pin(o,a){if(a===void 0)return n.read().f?.[o]?.p??null;n.write(c=>{f(c,o).p=a})},coveredAt:()=>n.read().o??null,covered(o=Date.now()){n.write(a=>{a.o=o})},code(o,a=Date.now()){if(o===void 0){let[c]=p().flatMap(y=>y.k?[y.k]:[]).sort((y,_)=>_.at-y.at);return c&&a-c.at<14*864e5?c.c:null}return u().write(c=>{c.k={c:o,at:a}}),o},submitted(o){i.write(a=>{f(a,o).s=1}),u().write(a=>{a.sub=1})}}}var rt=E("onsite-products.min.js"),V=()=>x(rt,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.products"));var lt=E("onsite-render.min.js"),_e=()=>x(lt,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.render"));var at=["source","medium","campaign","content","term"];var Ae=e=>String(e).trim().toLowerCase();function ct(e,s,n){let i=Ae(e),u=Ae(n);return s==="is"?i===u:s==="contains"&&u!==""&&i.includes(u)}function ve(e,s){return(Array.isArray(e)?e:[]).every(n=>{let i=s?.[n?.field];return!at.includes(n?.field)||typeof i!="string"?!1:[].concat(n.values??[]).some(u=>ct(i,n.match,u))})}var Me=["popup","sheet","bar","teaser","inline","fullscreen"],ut=["entry","exit","scroll","time","idle","inline","manual"],oe=e=>e!=="inline",Ie=e=>e==="popup"||e==="sheet"||e==="fullscreen",v=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),j=e=>Array.isArray(e)?e.filter(s=>typeof s=="string"):[],Ee=e=>Number.isInteger(e)&&e>=0?e:null,dt={field:null,match:null,values:[]},pt=e=>e==null?[]:Array.isArray(e)&&e.every(v)?e:[dt];function Ce(e){if(!v(e)||typeof e.slot!="string"||e.slot==="")return null;let s=v(e.trigger)?e.trigger:{};if(!Me.includes(e.format)||!ut.includes(s.type))return null;let n=v(e.caps)?e.caps:{};return{...e,trigger:s,priority:Number.isFinite(e.priority)?e.priority:0,pages:v(e.pages)?e.pages:{},devices:j(e.devices),aliases:j(e.aliases),audiences:j(e.audiences),arrived_from:pt(e.arrived_from),caps:{per_session:Ee(n.per_session),lifetime:Ee(n.lifetime),after_close_days:Number.isFinite(n.after_close_days)?n.after_close_days:null},window:v(e.window)?e.window:{},questions:Array.isArray(e.questions)?e.questions.filter(v):[],prizes:Array.isArray(e.prizes)?e.prizes.filter(v):[]}}var ft=/^[a-z][a-z0-9_-]{0,31}$/;function Oe(e){if(!v(e)||e.v!==1||!Array.isArray(e.steps))return null;let s=e.steps.filter(n=>v(n)&&ft.test(n.id)&&Array.isArray(n.blocks));return s.length===0?null:{format:Me.includes(e.format)?e.format:null,theme:v(e.theme)?e.theme:{},steps:s}}function xe(e,s){let n=String(e).split("*").map(i=>i.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${n}$`,"i").test(s)}function ht(e,s){let n=j(e?.include);return(!n.length||n.some(i=>xe(i,s)))&&!j(e?.exclude).some(i=>xe(i,s))}function De(e){return e.matchMedia?.("(hover: none) and (pointer: coarse)")?.matches===!0||e.innerWidth<768?"mobile":"desktop"}var Te=e=>typeof e=="string"?Date.parse(e):Number.NaN,U=e=>e.trigger.type==="manual";function ie(e,s){let n=[];ht(e.pages,s.path)||n.push("page not included"),e.devices.length&&!e.devices.includes(s.device)&&n.push(`not on ${s.device}`),ve(e.arrived_from,s.campaign)||n.push("not from its campaign");let i=Te(e.window.starts_at),u=Te(e.window.ends_at);if((s.now<i||s.now>=u)&&n.push("outside its dates"),e.audiences.length&&!s.preview&&(s.personalisation?s.audiences&&!e.audiences.some(f=>s.audiences.includes(f))&&n.push("not in its audiences"):n.push("audiences need personalisation consent")),s.preview||s.asked||U(e))return n;let{seen:r}=s,{caps:p}=e;return r.submitted&&n.push("already submitted"),e.exclude_subscribed===!0&&s.subscribed&&n.push("already subscribed"),p.per_session!==null&&r.session>=p.per_session&&n.push("per_session cap"),p.lifetime!==null&&r.lifetime>=p.lifetime&&n.push("lifetime cap"),p.after_close_days!==null&&r.closedAt&&s.now-r.closedAt<p.after_close_days*864e5&&n.push("closed recently"),n}var $e=(e,s)=>s.priority-e.priority;var mt=["mousemove","pointerdown","keydown","scroll","touchstart","wheel"];function gt(){let e=[];return{on:(i,u,r,p={passive:!0})=>{i.addEventListener(u,r,p),e.push(()=>i.removeEventListener(u,r,p))},later:(i,u)=>{let r=setTimeout(i,u);e.push(()=>clearTimeout(r))},stop:()=>{for(let i of e.splice(0))i()}}}var Ne=(e,s)=>{let n=s.documentElement.scrollHeight||0;return n>0?(e.scrollY+e.innerHeight)/n:0},wt=e=>{let s=e.activeElement;return!!(s&&(/^(INPUT|TEXTAREA|SELECT)$/.test(s.tagName)||s.isContentEditable))};function yt({on:e,later:s},n,i,u,r){let p=!1,f=!1,o=null,a=0;s(()=>{p=!0},i.delay_ms??5e3),e(r,"mousemove",c=>{c.clientY>u.innerHeight*.1&&(f=!0),o!==null&&(a=c.clientY-o),o=c.clientY}),e(r,"mouseout",c=>{p&&f&&!c.relatedTarget&&c.clientY<=0&&a<0&&!wt(r)&&n("exit")})}function bt({on:e,later:s},n,i,u,r){let p=!1,f=0,o=u.scrollY,a=Date.now(),c=null,y=null;s(()=>{p=!0},i.delay_ms??5e3),e(u,"scroll",()=>{let _=u.scrollY,T=Date.now();if(f=Math.max(f,Ne(u,r)),_<o){(!c||T-c.t>300)&&(c={y:o,t:a});let M=c.y-_;p&&f>=.3&&M>=120&&M/Math.max(1,T-c.t)>=.5&&n("exit_scroll")}else c=null;o=_,a=T}),e(r,"visibilitychange",()=>{r.visibilityState==="hidden"?y=Date.now():y!==null&&Date.now()-y>=1e4&&n("return"),r.visibilityState!=="hidden"&&(y=null)})}function Pe(e,s,{device:n,win:i=window,doc:u=document}){let r=gt(),p=(e.seconds??30)*1e3;if(e.type==="entry"&&r.later(()=>s("entry"),e.delay_ms??0),e.type==="time"&&r.later(()=>s("time"),p),e.type==="exit"&&(n==="mobile"?bt:yt)(r,s,e,i,u),e.type==="scroll"){let f=e.depth??.5;r.on(i,"scroll",()=>Ne(i,u)>=f&&s("scroll"))}if(e.type==="idle"){let f=null,o=()=>{clearTimeout(f),f=setTimeout(()=>s("idle"),p)};o();for(let a of mt)r.on(a==="scroll"?i:u,a,o);return r.on(u,"visibilitychange",o),()=>{clearTimeout(f),r.stop()}}return r.stop}var St=E("onsite-wheel.min.js"),ke=()=>x(St,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.wheel"));var Le=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite-access"),W=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite"),_t=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.pending"),At=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.listeners"),Re=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.suppressed"),Fe={seen:()=>({session:0,lifetime:0,closedAt:null,submitted:!1}),subscribed:()=>!1,shown(){},closed(){},submitted(){},tab(){},tabOut:()=>!1,pin:()=>null,coveredAt:()=>null,covered(){},code:()=>null},vt=new Set(["decision-failed","no-creative","no-code","renderer-failed","products-failed","error"]),je=3e3,Ue={status:0,body:null},Et=1500,We=50,xt=300,Tt=()=>{try{return new URLSearchParams(location.search).get("hp_debug")==="onsite"}catch{return!1}},Mt=e=>Array.isArray(e?.steps)&&e.steps.some(s=>Array.isArray(s?.blocks)&&s.blocks.some(n=>n?.t==="products"));function Ke(e,s={}){if(typeof window>"u"||typeof document>"u")return null;if(window[W])return window[W];let n=typeof e?.[Le]=="function"?e[Le]():null;if(!n)return console.warn("[hp] onsite: startOnsite needs the client bootstrap or createAnalytics made"),null;let i=s.settings??n.settings??{},u=we(n,{...s,challenge:i.capture?.challenge}),r=n.preview?Fe:Se(n.storageKey,n.personalisation),p=()=>n.campaign?.()??null,f=new Map,o=()=>window[Re]?.size>0,a=(t,l)=>{for(let d of window[At]?.[t]??[])try{d(l)}catch(h){console.warn(`[hp] onsite ${t} listener failed:`,h)}},c=De(window),y=n.debug||s.debug===!0||Tt(),_=new Map,T=new Map,M=[];for(let t of Array.isArray(i.forms)?i.forms:[]){let l=Ce(t);l?M.push(l):_.set(String(t?.slot??`form ${_.size+1}`),{slot:String(t?.slot??""),state:"invalid",code:"invalid",reasons:["not a form this SDK can show"]})}let re=()=>ye().catch(t=>(console.warn("[hp] onsite audiences not loaded:",t?.message??t),null));n.personalisation()&&M.some(t=>t.audiences.length>0)&&re().then(t=>t?.prefetch(u));let N=new Map,K=new Map,I=null,le=!1,ae=new Set,He=t=>{for(let l of N.keys()){let d=f.get(l);if(!t||!d||d.modal?.())return l}return null},H=null,q=new Set,B=Number.isInteger(i.overlay_gap_minutes)?i.overlay_gap_minutes:0,Ye=()=>{let t=r.coveredAt();if(!(B>0)||typeof t!="number")return null;let l=Math.max(0,Math.floor((Date.now()-t)/6e4));return l<B?`a popup showed ${l} min ago; ${B} min between them`:null},P=new Set,Y=new Map,b=(t,l,d,h=[])=>(_.set(t.slot,{slot:t.slot,format:t.format,trigger:t.trigger.type,priority:t.priority,state:l,code:d,reasons:h}),y&&console.info(`[hp] onsite ${t.slot}: ${l}${h.length?` (${h.join("; ")})`:""}`),{state:l,code:d}),D=(t,l,d,h)=>(N.delete(t.slot),b(t,l,d,h)),k=(t,l,d)=>{let h;return Promise.race([t,new Promise(w=>{h=setTimeout(w,l-Date.now(),d)})]).then(w=>Date.now()>l?d:w).finally(()=>clearTimeout(h))},Xe=(t,l)=>{le||o()||(I??(I=t.slot),a("nothing",{slot:t.slot,format:t.format,code:l}))},ce=()=>{try{let t=s.audiences?.();return Array.isArray(t)?t:null}catch{return null}},ue=t=>({path:location.pathname,device:c,campaign:p(),now:Date.now(),seen:r.seen(t.slot),subscribed:r.subscribed()||s.subscribed?.()===!0,personalisation:n.personalisation(),preview:!!n.preview,audiences:ce()}),J=t=>{T.get(t.slot)?.(),T.delete(t.slot)};function L(t,l,d=!1,h=U(t),w=Date.now()+je){if(f.has(t.slot))return Promise.resolve({state:"shown",code:"shown",asked:h});let g=K.get(t.slot);return g?(g.asked||(g.asked=h),g.done):(g={asked:h},g.done=ze(t,l,d,h,w).catch(A=>f.has(t.slot)?{state:"shown",code:"shown"}:(console.warn("[hp] onsite form failed:",A?.message??A),D(t,"not shown","error",[`failed: ${A?.message??A}`]))).then(A=>(K.delete(t.slot),{...A,asked:g.asked||g.opened})),K.set(t.slot,g),g.done)}async function ze(t,l,d,h,w){if(o())return b(t,"not shown","suppressed",[`suppressed: ${[...window[Re]].join(", ")}`]);let g=ie(t,{...ue(t),...d?{seen:Fe.seen()}:{},asked:h});if(g.length)return b(t,"not eligible","not-eligible",g);let A=Ie(t.format)&&!d,C=A&&!h&&Ye();if(C)return b(t,"not shown","overlay-gap",[C]);if(A&&!n.preview&&n.consentAnswered?.()===!1)return Y.set(t,h),b(t,"not shown","awaiting-consent",["waiting for the consent banner"]);let O=oe(t.format),pe=O&&He(h);if(pe)return b(t,"not shown","another-showing",[`${pe} is showing`]);if(O&&I&&!h)return b(t,"not shown","allowance-spent",[`${I} already showed on this page view`]);let X=null;if(!O){try{X=document.querySelector(t.trigger.selector??"")}catch{X=null}if(!X)return b(t,"not shown","no-element",["no element matches its selector"])}O&&N.set(t.slot,t),J(t),b(t,"asking for a decision","deciding",[l]);let Be=_e().catch(m=>(console.warn("[hp] onsite renderer not loaded:",m?.message??m),null)),z=t.visit_context===!0?V().catch(()=>null):null,Q=ce()??[],fe=[...new Set([...t.audiences,...Q])].filter(m=>Q.includes(m)).slice(0,100),Je=t.audiences.length>0&&!n.preview&&n.personalisation()?await k(re().then(m=>m?m.visitAudiences(u,n.sessionSignals,t.audiences,Q):fe),Math.min(w,Date.now()+Et),fe):null,F=Date.now()<w?await k(u.decide(t.slot,r.pin(t.slot),{visitAudiences:Je,visitCampaign:t.arrived_from.length?p():null,visitContext:t.visit_context===!0?n.visitContext?.()??null:null,timeoutMs:w-Date.now()}),w,Ue):Ue,ee=F.status===200?F.body?.decisions:null,S=Array.isArray(ee)?ee.find(m=>m?.slot===t.slot):null;S?.experiment&&S.arm&&S.split&&r.pin(t.slot,[S.experiment,S.arm,S.split]);let $=S&&S.holdout!==!0?Oe(S.payload):null,he=$?.steps[0].blocks??[],me=S?.offer?.code??(n.preview?"PREVIEW":r.code()),Ze=n.basketValue?.()??null,te=he.some(m=>m?.t==="code")&&!me&&"no code to remind of"||he.some(m=>m?.t==="progress")&&!(Ze>0)&&"the basket is empty";if(te){let m=te==="the basket is empty";return m&&P.add(t),D(t,"not shown",m?"empty-basket":"no-code",[te])}if(P.delete(t),!$){let m=S?.holdout===!0;return m&&n.analytics()&&e.recordExposure(F.body),O&&m&&(I??(I=t.slot)),m&&!h&&a("held",{slot:t.slot,arm:S.arm??null,format:t.format}),m||Array.isArray(ee)?D(t,m?"held out":"no decision",m?"held-out":"no-creative",["no creative for this visitor"]):D(t,"no decision","decision-failed",[`decisions answered ${F.status}`])}let ne=await k(Be,w,null);if(!ne)return D(t,"not shown","renderer-failed",["the renderer did not load"]);if(Mt($)&&(z??(z=V().catch(()=>null)),!await k(z,w,null)))return D(t,"not shown","products-failed",["its products did not load"]);if(await k(ne.warm?.(t,$,$.steps[0].id,ae),Math.min(w,Date.now()+xt)),o())return D(t,"not shown","suppressed",["suppressed"]);let se=(m,tt={})=>a(m,{slot:t.slot,arm:S.arm??null,format:$.format??t.format,...tt}),Qe=ne.mountForm({form:t,creative:$,decision:S,access:n,client:e,api:u,counters:r,loadWheel:ke,loadAnswers:ge,loadProducts:()=>z??V(),container:X,warmed:ae,coupon:me,basket:()=>n.basketValue?.()??null,emit:se,onClose(m){f.delete(t.slot),N.delete(t.slot),b(t,"closed","closed",[m]),se("closed",{reason:m})}});f.set(t.slot,Qe),d||r.shown(t.slot),A&&r.covered(),O&&(I??(I=t.slot)),n.analytics()&&e.recordExposure(F.body);let et=b(t,"shown","shown",[l]);return se("shown"),et}function Z(t,l,d=U(t)){if(!oe(t.format))return L(t,l,!1,d);if(!H){let h={forms:[],taken:new Set,deadline:Date.now()+We+je};H=h,q.add(h),setTimeout(()=>{H=null,Ge(h)},We)}H.forms.push([t,l,d])}async function Ge(t){let l=t.forms.sort(([h],[w])=>$e(h,w)),d=null;for(let[h,[w,g,A]]of l.entries()){if(t.taken.has(w))continue;let C=await L(w,g,!1,A,t.deadline);if(!d&&vt.has(C.code)&&!C.asked&&(d=[w,C.code]),C.state==="shown"||C.state==="held out"){for(let[O]of l.slice(h+1))b(O,"not shown","lower-priority",[`${w.slot} has a higher priority`]);d=null;break}}q.delete(t),d&&Xe(...d)}for(let t of M){if(t.format==="teaser"&&r.tabOut(t.slot)){L(t,"tab kept from an earlier page",!0);continue}let l=ie(t,ue(t));if(l.length){b(t,"not eligible","not-eligible",l);continue}let d=t.trigger.type;d==="manual"?b(t,"waiting for hp.onsite.open","waiting-for-open"):d==="inline"||t.format==="inline"?L(t,"inline"):de(t)}function de(t){J(t),T.set(t.slot,Pe(t.trigger,l=>{J(t),Z(t,l)},{device:c})),b(t,"armed","armed",[`${t.trigger.type} on ${c}`])}let Ve=n.onConsentAnswered?.(()=>{let t=[...Y];Y.clear();for(let[l,d]of t)f.has(l.slot)||(d?Z(l,"manual",d):de(l))}),qe=n.onBasket?.(()=>{if(!((n.basketValue?.()??0)>0))return;let t=[...P];P.clear();for(let l of t)f.has(l.slot)||Z(l,"the basket changed")}),R=Object.freeze({open(t){let l=M.find(g=>g.slot===t),d=l??M.find(g=>g.aliases.includes(t));if(!d)return Promise.resolve(!1);if(f.has(d.slot))return Promise.resolve(!0);for(let g of q)g.taken.add(d);let h=L(d,"manual",!1,U(d)||!l),w=K.get(d.slot);return w&&(w.opened=!0),h.then(({state:g})=>g==="shown")},suppress(){for(let[t,l]of f){l.destroy(),f.delete(t),N.delete(t);let d=M.find(h=>h.slot===t);d&&b(d,"closed","suppressed",["suppressed"])}},debug:()=>[..._.values()].map(t=>({...t,reasons:[...t.reasons]})),stop(){le=!0;for(let t of T.values())t();T.clear(),qe?.(),Ve?.(),P.clear(),Y.clear(),window[W]===R&&delete window[W]}});window[W]=R;for(let{slot:t,resolve:l}of window[_t]?.splice(0)??[])l(R.open(t));return y&&console.table?.(R.debug()),R}window[Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.module")]={startOnsite:Ke};})();
1
+ (()=>{function x(e){let s=typeof document>"u"?null:document.currentScript?.src;return s?new URL(e,s).href:null}var G=new Map;function T(e,s){return window[s]?Promise.resolve(window[s]):e?(G.has(s)||G.set(s,new Promise((n,r)=>{let p=document.createElement("script");p.src=e,p.async=!0,p.onload=()=>window[s]?n(window[s]):r(new Error(`${e} did not register`)),p.onerror=()=>r(new Error(`${e} did not load`)),document.head.append(p)}).finally(()=>G.delete(s))),G.get(s)):Promise.reject(new Error("the CDN script\u2019s own URL is unknown"))}var nt=x("onsite-answers.min.js"),ge=()=>T(nt,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.answers"));var st="/v1/capture/challenge",ot=e=>typeof e=="string"&&/^\/v1\/[\w/-]+$/.test(e)?e:st;function me(e,s={}){let n=s.fetch??globalThis.fetch?.bind(globalThis),r=s.servingHost??e.servingHost,p=s.gatewayHost??e.gatewayHost;async function l(c,{method:o="GET",body:i,consent:u=!1,timeoutMs:y}={}){if(!n)return{status:0,body:null};try{let S=await n(c,{method:o,credentials:"omit",signal:y&&AbortSignal.timeout?.(y),headers:{accept:"application/json",authorization:`Bearer ${e.writeKey}`,...i?{"content-type":"application/json"}:{},...u?e.headers():{}},...i?{body:JSON.stringify(i)}:{}}),A=null;try{A=await S.json()}catch{}return{status:S.status,body:A}}catch{return{status:0,body:null}}}let h=(c,o)=>l(`${p}/v1/capture${c}`,{method:"POST",body:o}).then(i=>(i.status>=200&&i.status<300&&e.answered?.(o.answers,o.slot),i));return{decide:(c,o,{visitAudiences:i,visitCampaign:u,visitContext:y,timeoutMs:S=3e3}={})=>l(`${r}/v1/decisions`,{method:"POST",consent:!0,timeoutMs:Math.max(1,S),body:{slots:[o?{key:c,pin:{experiment:o[0],arm:o[1],split:o[2]}}:c],library:e.library,identifier_value:e.anonymousId()??void 0,session_id:e.sessionId()??void 0,identity_token:e.identityToken?.()??void 0,...e.preview?{preview:e.preview}:{},...i&&{visit_audiences:i.claims,...i.answered?.length&&{answered_audiences:i.answered}},...u?{visit_campaign:u}:{},...y?{visit_context:y}:{}}}),datafile:()=>l(`${r}/v1/audiences/datafile`,{timeoutMs:1500}),challenge:()=>l(`${p}${ot(s.challenge)}`),capture:c=>h("",c),answers:c=>h("/answers",c),claim:c=>l(`${r}/v1/offers/claim`,{method:"POST",consent:!0,body:c,timeoutMs:8e3})}}var it=x("onsite-audiences.min.js"),ye=()=>T(it,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.audiences"));function be(e,s){let n={},r=()=>{try{let l=JSON.parse(e().getItem(s));l&&typeof l=="object"&&(n=l)}catch{}return n};return{read:r,write:l=>{let h=r();l(h),n=h;try{e().setItem(s,JSON.stringify(h))}catch{}}}}function Se(e,s=()=>!0){let n=be(()=>sessionStorage,e),r=be(()=>localStorage,e),p=()=>s()?r:n,l=()=>{let o=r.read();(o.sub!==void 0||o.k!==void 0)&&r.write(i=>{delete i.sub,delete i.k})},h=()=>s()?[n.read(),r.read()]:(l(),[n.read()]),c=(o,i)=>{var u;return o.f??(o.f={}),(u=o.f)[i]??(u[i]={}),o.f[i]};return{seen(o){let i=r.read().f?.[o]??{};return{session:n.read().f?.[o]?.n??0,lifetime:i.n??0,closedAt:i.c??null,submitted:i.s===1}},subscribed:()=>h().some(o=>o.sub===1),shown(o){n.write(i=>{let u=c(i,o);u.n=(u.n??0)+1}),r.write(i=>{let u=c(i,o);u.n=(u.n??0)+1})},closed(o,i=Date.now()){r.write(u=>{c(u,o).c=i})},tab(o,i){n.write(u=>{let y=c(u,o);i?y.t=1:delete y.t})},tabOut:o=>n.read().f?.[o]?.t===1,pin(o,i){if(i===void 0)return n.read().f?.[o]?.p??null;n.write(u=>{c(u,o).p=i})},coveredAt:()=>n.read().o??null,covered(o=Date.now()){n.write(i=>{i.o=o})},code(o,i=Date.now()){if(o===void 0){let[u]=h().flatMap(y=>y.k?[y.k]:[]).sort((y,S)=>S.at-y.at);return u&&i-u.at<14*864e5?u.c:null}return p().write(u=>{u.k={c:o,at:i}}),o},submitted(o){r.write(i=>{c(i,o).s=1}),p().write(i=>{i.sub=1})}}}var rt=x("onsite-products.min.js"),V=()=>T(rt,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.products"));var lt=x("onsite-render.min.js"),_e=()=>T(lt,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.render"));var at=["source","medium","campaign","content","term"];var Ae=e=>String(e).trim().toLowerCase();function ct(e,s,n){let r=Ae(e),p=Ae(n);return s==="is"?r===p:s==="contains"&&p!==""&&r.includes(p)}function ve(e,s){return(Array.isArray(e)?e:[]).every(n=>{let r=s?.[n?.field];return!at.includes(n?.field)||typeof r!="string"?!1:[].concat(n.values??[]).some(p=>ct(r,n.match,p))})}var Me=["popup","sheet","bar","teaser","inline","fullscreen"],ut=["entry","exit","scroll","time","idle","inline","manual"],oe=e=>e!=="inline",Ie=e=>e==="popup"||e==="sheet"||e==="fullscreen",E=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),j=e=>Array.isArray(e)?e.filter(s=>typeof s=="string"):[],Ee=e=>Number.isInteger(e)&&e>=0?e:null,dt={field:null,match:null,values:[]},pt=e=>e==null?[]:Array.isArray(e)&&e.every(E)?e:[dt];function Ce(e){if(!E(e)||typeof e.slot!="string"||e.slot==="")return null;let s=E(e.trigger)?e.trigger:{};if(!Me.includes(e.format)||!ut.includes(s.type))return null;let n=E(e.caps)?e.caps:{};return{...e,trigger:s,priority:Number.isFinite(e.priority)?e.priority:0,pages:E(e.pages)?e.pages:{},devices:j(e.devices),aliases:j(e.aliases),audiences:j(e.audiences),arrived_from:pt(e.arrived_from),caps:{per_session:Ee(n.per_session),lifetime:Ee(n.lifetime),after_close_days:Number.isFinite(n.after_close_days)?n.after_close_days:null},window:E(e.window)?e.window:{},questions:Array.isArray(e.questions)?e.questions.filter(E):[],prizes:Array.isArray(e.prizes)?e.prizes.filter(E):[]}}var ft=/^[a-z][a-z0-9_-]{0,31}$/;function Oe(e){if(!E(e)||e.v!==1||!Array.isArray(e.steps))return null;let s=e.steps.filter(n=>E(n)&&ft.test(n.id)&&Array.isArray(n.blocks));return s.length===0?null:{format:Me.includes(e.format)?e.format:null,theme:E(e.theme)?e.theme:{},steps:s}}function xe(e,s){let n=String(e).split("*").map(r=>r.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${n}$`,"i").test(s)}function ht(e,s){let n=j(e?.include);return(!n.length||n.some(r=>xe(r,s)))&&!j(e?.exclude).some(r=>xe(r,s))}function De(e){return e.matchMedia?.("(hover: none) and (pointer: coarse)")?.matches===!0||e.innerWidth<768?"mobile":"desktop"}var Te=e=>typeof e=="string"?Date.parse(e):Number.NaN,U=e=>e.trigger.type==="manual";function ie(e,s){let n=[];ht(e.pages,s.path)||n.push("page not included"),e.devices.length&&!e.devices.includes(s.device)&&n.push(`not on ${s.device}`),ve(e.arrived_from,s.campaign)||n.push("not from its campaign");let r=Te(e.window.starts_at),p=Te(e.window.ends_at);if((s.now<r||s.now>=p)&&n.push("outside its dates"),e.audiences.length&&!s.preview&&(s.personalisation?s.audiences&&!e.audiences.some(c=>s.audiences.includes(c))&&n.push("not in its audiences"):n.push("audiences need personalisation consent")),s.preview||s.asked||U(e))return n;let{seen:l}=s,{caps:h}=e;return l.submitted&&n.push("already submitted"),e.exclude_subscribed===!0&&s.subscribed&&n.push("already subscribed"),h.per_session!==null&&l.session>=h.per_session&&n.push("per_session cap"),h.lifetime!==null&&l.lifetime>=h.lifetime&&n.push("lifetime cap"),h.after_close_days!==null&&l.closedAt&&s.now-l.closedAt<h.after_close_days*864e5&&n.push("closed recently"),n}var $e=(e,s)=>s.priority-e.priority;var wt=["mousemove","pointerdown","keydown","scroll","touchstart","wheel"];function gt(){let e=[];return{on:(r,p,l,h={passive:!0})=>{r.addEventListener(p,l,h),e.push(()=>r.removeEventListener(p,l,h))},later:(r,p)=>{let l=setTimeout(r,p);e.push(()=>clearTimeout(l))},stop:()=>{for(let r of e.splice(0))r()}}}var Ne=(e,s)=>{let n=s.documentElement.scrollHeight||0;return n>0?(e.scrollY+e.innerHeight)/n:0},mt=e=>{let s=e.activeElement;return!!(s&&(/^(INPUT|TEXTAREA|SELECT)$/.test(s.tagName)||s.isContentEditable))};function yt({on:e,later:s},n,r,p,l){let h=!1,c=!1,o=null,i=0;s(()=>{h=!0},r.delay_ms??5e3),e(l,"mousemove",u=>{u.clientY>p.innerHeight*.1&&(c=!0),o!==null&&(i=u.clientY-o),o=u.clientY}),e(l,"mouseout",u=>{h&&c&&!u.relatedTarget&&u.clientY<=0&&i<0&&!mt(l)&&n("exit")})}function bt({on:e,later:s},n,r,p,l){let h=!1,c=0,o=p.scrollY,i=Date.now(),u=null,y=null;s(()=>{h=!0},r.delay_ms??5e3),e(p,"scroll",()=>{let S=p.scrollY,A=Date.now();if(c=Math.max(c,Ne(p,l)),S<o){(!u||A-u.t>300)&&(u={y:o,t:i});let M=u.y-S;h&&c>=.3&&M>=120&&M/Math.max(1,A-u.t)>=.5&&n("exit_scroll")}else u=null;o=S,i=A}),e(l,"visibilitychange",()=>{l.visibilityState==="hidden"?y=Date.now():y!==null&&Date.now()-y>=1e4&&n("return"),l.visibilityState!=="hidden"&&(y=null)})}function Pe(e,s,{device:n,win:r=window,doc:p=document}){let l=gt(),h=(e.seconds??30)*1e3;if(e.type==="entry"&&l.later(()=>s("entry"),e.delay_ms??0),e.type==="time"&&l.later(()=>s("time"),h),e.type==="exit"&&(n==="mobile"?bt:yt)(l,s,e,r,p),e.type==="scroll"){let c=e.depth??.5;l.on(r,"scroll",()=>Ne(r,p)>=c&&s("scroll"))}if(e.type==="idle"){let c=null,o=()=>{clearTimeout(c),c=setTimeout(()=>s("idle"),h)};o();for(let i of wt)l.on(i==="scroll"?r:p,i,o);return l.on(p,"visibilitychange",o),()=>{clearTimeout(c),l.stop()}}return l.stop}var St=x("onsite-wheel.min.js"),ke=()=>T(St,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.wheel"));var Le=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite-access"),W=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite"),_t=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.pending"),At=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.listeners"),Re=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.suppressed"),Fe={seen:()=>({session:0,lifetime:0,closedAt:null,submitted:!1}),subscribed:()=>!1,shown(){},closed(){},submitted(){},tab(){},tabOut:()=>!1,pin:()=>null,coveredAt:()=>null,covered(){},code:()=>null},vt=new Set(["decision-failed","no-creative","no-code","renderer-failed","products-failed","error"]),je=3e3,Ue={status:0,body:null},Et=1500,We=50,xt=300,Tt=()=>{try{return new URLSearchParams(location.search).get("hp_debug")==="onsite"}catch{return!1}},Mt=e=>Array.isArray(e?.steps)&&e.steps.some(s=>Array.isArray(s?.blocks)&&s.blocks.some(n=>n?.t==="products"));function Ke(e,s={}){if(typeof window>"u"||typeof document>"u")return null;if(window[W])return window[W];let n=typeof e?.[Le]=="function"?e[Le]():null;if(!n)return console.warn("[hp] onsite: startOnsite needs the client bootstrap or createAnalytics made"),null;let r=s.settings??n.settings??{};n.started?.(r);let p=me(n,{...s,challenge:r.capture?.challenge}),l=n.preview?Fe:Se(n.storageKey,n.personalisation),h=()=>n.campaign?.()??null,c=new Map,o=()=>window[Re]?.size>0,i=(t,a)=>{for(let d of window[At]?.[t]??[])try{d(a)}catch(f){console.warn(`[hp] onsite ${t} listener failed:`,f)}},u=De(window),y=n.debug||s.debug===!0||Tt(),S=new Map,A=new Map,M=[];for(let t of Array.isArray(r.forms)?r.forms:[]){let a=Ce(t);a?M.push(a):S.set(String(t?.slot??`form ${S.size+1}`),{slot:String(t?.slot??""),state:"invalid",code:"invalid",reasons:["not a form this SDK can show"]})}let re=()=>ye().catch(t=>(console.warn("[hp] onsite audiences not loaded:",t?.message??t),null));n.personalisation()&&M.some(t=>t.audiences.length>0)&&re().then(t=>t?.prefetch(p));let N=new Map,K=new Map,I=null,le=!1,ae=new Set,He=t=>{for(let a of N.keys()){let d=c.get(a);if(!t||!d||d.modal?.())return a}return null},H=null,q=new Set,B=Number.isInteger(r.overlay_gap_minutes)?r.overlay_gap_minutes:0,Ye=()=>{let t=l.coveredAt();if(!(B>0)||typeof t!="number")return null;let a=Math.max(0,Math.floor((Date.now()-t)/6e4));return a<B?`a popup showed ${a} min ago; ${B} min between them`:null},P=new Set,Y=new Map,b=(t,a,d,f=[])=>(S.set(t.slot,{slot:t.slot,format:t.format,trigger:t.trigger.type,priority:t.priority,state:a,code:d,reasons:f}),y&&console.info(`[hp] onsite ${t.slot}: ${a}${f.length?` (${f.join("; ")})`:""}`),{state:a,code:d}),D=(t,a,d,f)=>(N.delete(t.slot),b(t,a,d,f)),k=(t,a,d)=>{let f;return Promise.race([t,new Promise(m=>{f=setTimeout(m,a-Date.now(),d)})]).then(m=>Date.now()>a?d:m).finally(()=>clearTimeout(f))},Xe=(t,a)=>{le||o()||(I??(I=t.slot),i("nothing",{slot:t.slot,format:t.format,code:a}))},ce=()=>{try{let t=s.audiences?.();return Array.isArray(t)?t:null}catch{return null}},ue=t=>({path:location.pathname,device:u,campaign:h(),now:Date.now(),seen:l.seen(t.slot),subscribed:l.subscribed()||s.subscribed?.()===!0,personalisation:n.personalisation(),preview:!!n.preview,audiences:ce()}),J=t=>{A.get(t.slot)?.(),A.delete(t.slot)};function L(t,a,d=!1,f=U(t),m=Date.now()+je){if(c.has(t.slot))return Promise.resolve({state:"shown",code:"shown",asked:f});let g=K.get(t.slot);return g?(g.asked||(g.asked=f),g.done):(g={asked:f},g.done=ze(t,a,d,f,m).catch(v=>c.has(t.slot)?{state:"shown",code:"shown"}:(console.warn("[hp] onsite form failed:",v?.message??v),D(t,"not shown","error",[`failed: ${v?.message??v}`]))).then(v=>(K.delete(t.slot),{...v,asked:g.asked||g.opened})),K.set(t.slot,g),g.done)}async function ze(t,a,d,f,m){if(o())return b(t,"not shown","suppressed",[`suppressed: ${[...window[Re]].join(", ")}`]);let g=ie(t,{...ue(t),...d?{seen:Fe.seen()}:{},asked:f});if(g.length)return b(t,"not eligible","not-eligible",g);let v=Ie(t.format)&&!d,C=v&&!f&&Ye();if(C)return b(t,"not shown","overlay-gap",[C]);if(v&&!n.preview&&n.consentAnswered?.()===!1)return Y.set(t,f),b(t,"not shown","awaiting-consent",["waiting for the consent banner"]);let O=oe(t.format),pe=O&&He(f);if(pe)return b(t,"not shown","another-showing",[`${pe} is showing`]);if(O&&I&&!f)return b(t,"not shown","allowance-spent",[`${I} already showed on this page view`]);let X=null;if(!O){try{X=document.querySelector(t.trigger.selector??"")}catch{X=null}if(!X)return b(t,"not shown","no-element",["no element matches its selector"])}O&&N.set(t.slot,t),J(t),b(t,"asking for a decision","deciding",[a]);let Be=_e().catch(w=>(console.warn("[hp] onsite renderer not loaded:",w?.message??w),null)),z=t.visit_context===!0?V().catch(()=>null):null,Q=ce()??[],fe={claims:[...new Set([...t.audiences,...Q])].filter(w=>Q.includes(w)).slice(0,100)},Je=t.audiences.length>0&&!n.preview&&n.personalisation()?await k(re().then(w=>w?w.visitAudiences(p,n.sessionSignals,t.audiences,Q):fe),Math.min(m,Date.now()+Et),fe):null,F=Date.now()<m?await k(p.decide(t.slot,l.pin(t.slot),{visitAudiences:Je,visitCampaign:t.arrived_from.length?h():null,visitContext:t.visit_context===!0?n.visitContext?.()??null:null,timeoutMs:m-Date.now()}),m,Ue):Ue,ee=F.status===200?F.body?.decisions:null,_=Array.isArray(ee)?ee.find(w=>w?.slot===t.slot):null;_?.experiment&&_.arm&&_.split&&l.pin(t.slot,[_.experiment,_.arm,_.split]);let $=_&&_.holdout!==!0?Oe(_.payload):null,he=$?.steps[0].blocks??[],we=_?.offer?.code??(n.preview?"PREVIEW":l.code()),Ze=n.basketValue?.()??null,te=he.some(w=>w?.t==="code")&&!we&&"no code to remind of"||he.some(w=>w?.t==="progress")&&!(Ze>0)&&"the basket is empty";if(te){let w=te==="the basket is empty";return w&&P.add(t),D(t,"not shown",w?"empty-basket":"no-code",[te])}if(P.delete(t),!$){let w=_?.holdout===!0;return w&&n.analytics()&&e.recordExposure(F.body),O&&w&&(I??(I=t.slot)),w&&!f&&i("held",{slot:t.slot,arm:_.arm??null,format:t.format}),w||Array.isArray(ee)?D(t,w?"held out":"no decision",w?"held-out":"no-creative",["no creative for this visitor"]):D(t,"no decision","decision-failed",[`decisions answered ${F.status}`])}let ne=await k(Be,m,null);if(!ne)return D(t,"not shown","renderer-failed",["the renderer did not load"]);if(Mt($)&&(z??(z=V().catch(()=>null)),!await k(z,m,null)))return D(t,"not shown","products-failed",["its products did not load"]);if(await k(ne.warm?.(t,$,$.steps[0].id,ae),Math.min(m,Date.now()+xt)),o())return D(t,"not shown","suppressed",["suppressed"]);let se=(w,tt={})=>i(w,{slot:t.slot,arm:_.arm??null,format:$.format??t.format,...tt}),Qe=ne.mountForm({form:t,creative:$,decision:_,access:n,client:e,api:p,counters:l,loadWheel:ke,loadAnswers:ge,loadProducts:()=>z??V(),container:X,warmed:ae,coupon:we,basket:()=>n.basketValue?.()??null,emit:se,onClose(w){c.delete(t.slot),N.delete(t.slot),b(t,"closed","closed",[w]),se("closed",{reason:w})}});c.set(t.slot,Qe),d||l.shown(t.slot),v&&l.covered(),O&&(I??(I=t.slot)),n.analytics()&&e.recordExposure(F.body);let et=b(t,"shown","shown",[a]);return se("shown"),et}function Z(t,a,d=U(t)){if(!oe(t.format))return L(t,a,!1,d);if(!H){let f={forms:[],taken:new Set,deadline:Date.now()+We+je};H=f,q.add(f),setTimeout(()=>{H=null,Ge(f)},We)}H.forms.push([t,a,d])}async function Ge(t){let a=t.forms.sort(([f],[m])=>$e(f,m)),d=null;for(let[f,[m,g,v]]of a.entries()){if(t.taken.has(m))continue;let C=await L(m,g,!1,v,t.deadline);if(!d&&vt.has(C.code)&&!C.asked&&(d=[m,C.code]),C.state==="shown"||C.state==="held out"){for(let[O]of a.slice(f+1))b(O,"not shown","lower-priority",[`${m.slot} has a higher priority`]);d=null;break}}q.delete(t),d&&Xe(...d)}for(let t of M){if(t.format==="teaser"&&l.tabOut(t.slot)){L(t,"tab kept from an earlier page",!0);continue}let a=ie(t,ue(t));if(a.length){b(t,"not eligible","not-eligible",a);continue}let d=t.trigger.type;d==="manual"?b(t,"waiting for hp.onsite.open","waiting-for-open"):d==="inline"||t.format==="inline"?L(t,"inline"):de(t)}function de(t){J(t),A.set(t.slot,Pe(t.trigger,a=>{J(t),Z(t,a)},{device:u})),b(t,"armed","armed",[`${t.trigger.type} on ${u}`])}let Ve=n.onConsentAnswered?.(()=>{let t=[...Y];Y.clear();for(let[a,d]of t)c.has(a.slot)||(d?Z(a,"manual",d):de(a))}),qe=n.onBasket?.(()=>{if(!((n.basketValue?.()??0)>0))return;let t=[...P];P.clear();for(let a of t)c.has(a.slot)||Z(a,"the basket changed")}),R=Object.freeze({open(t){let a=M.find(g=>g.slot===t),d=a??M.find(g=>g.aliases.includes(t));if(!d)return Promise.resolve(!1);if(c.has(d.slot))return Promise.resolve(!0);for(let g of q)g.taken.add(d);let f=L(d,"manual",!1,U(d)||!a),m=K.get(d.slot);return m&&(m.opened=!0),f.then(({state:g})=>g==="shown")},suppress(){for(let[t,a]of c){a.destroy(),c.delete(t),N.delete(t);let d=M.find(f=>f.slot===t);d&&b(d,"closed","suppressed",["suppressed"])}},debug:()=>[...S.values()].map(t=>({...t,reasons:[...t.reasons]})),stop(){le=!0;for(let t of A.values())t();A.clear(),qe?.(),Ve?.(),P.clear(),Y.clear(),window[W]===R&&delete window[W]}});window[W]=R;for(let{slot:t,resolve:a}of window[_t]?.splice(0)??[])a(R.open(t));return y&&console.table?.(R.debug()),R}window[Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.module")]={startOnsite:Ke};})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thg-agentic/hyper-personalisation-web",
3
- "version": "3.29.0",
3
+ "version": "3.31.0",
4
4
  "description": "Browser SDK for the THG Hyper-Personalisation event specification: event tracking from a write key and remote settings, strict CMP-agnostic consent, a GA4 dataLayer bridge and in-session audience evaluation. Dependency-free ESM on the Segment wire protocol, a CDN script (dist/hp.min.js), and an optional @segment/analytics-next plugin path.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -92,7 +92,7 @@
92
92
  "esbuild": "^0.28.2",
93
93
  "jsdom": "^30.1.1",
94
94
  "typescript": "^7.0.2",
95
- "@thg-agentic/hyper-personalisation-spec": "1.21.0"
95
+ "@thg-agentic/hyper-personalisation-spec": "1.22.0"
96
96
  },
97
97
  "scripts": {
98
98
  "test": "node --test tests/*.test.mjs",
@@ -0,0 +1,101 @@
1
+ /**
2
+ * The answers this shopper gave a property's onsite forms, kept on the device under personalisation
3
+ * consent only, so an early audience (ADR 0064) is decided as they answer, before the warehouse has
4
+ * the answer. The latest answer to each question counts, as in the warehouse, for 90 days from
5
+ * when it was given. Cleared with the visit: a refusal or withdrawal, a sign-out, another user
6
+ * signing in. Never contact data: a question's key and the option values chosen.
7
+ */
8
+
9
+ import { forgetEveryScope, storageKey, storageName } from './storage-scope.js';
10
+
11
+ const KEEP_MS = 90 * 24 * 60 * 60 * 1000;
12
+ const MAX_QUESTIONS = 50;
13
+ const MAX_VALUES = 20;
14
+ const MAX_TEXT = 128;
15
+
16
+ const keyOf = (propertyId) => storageKey(storageName('answers'), propertyId);
17
+ const text = (v) => typeof v === 'string' && v !== '' && v.length <= MAX_TEXT;
18
+
19
+ /** `[{ q, v, at }]`, newest last, without the lapsed or malformed. */
20
+ function kept(propertyId, now) {
21
+ try {
22
+ const list = JSON.parse(localStorage.getItem(keyOf(propertyId)));
23
+ return Array.isArray(list)
24
+ ? list.filter(
25
+ (a) =>
26
+ text(a?.q) &&
27
+ Array.isArray(a.v) &&
28
+ a.v.every(text) &&
29
+ now - a.at < KEEP_MS,
30
+ )
31
+ : [];
32
+ } catch {
33
+ return [];
34
+ }
35
+ }
36
+
37
+ /** The answers kept for this property, by question: `{ shopping_for: ['womens'] }`. */
38
+ export function readAnswers(propertyId, now = Date.now()) {
39
+ return Object.fromEntries(kept(propertyId, now).map((a) => [a.q, a.v]));
40
+ }
41
+
42
+ /**
43
+ * Only answers to a choice question of the form (`one` or `many`, from its settings' `questions`),
44
+ * and of those only its option values: never a date, a number or anything typed.
45
+ */
46
+ export function choiceAnswers(answers, questions) {
47
+ const asked = Array.isArray(questions) ? questions : [];
48
+ return (Array.isArray(answers) ? answers : []).flatMap((a) => {
49
+ const q = asked.find((x) => x?.key === a?.question);
50
+ if (!q || (q.type !== 'one' && q.type !== 'many')) return [];
51
+ const options = new Set((q.options ?? []).map((o) => o?.value));
52
+ const values = (Array.isArray(a.values) ? a.values : []).filter((v) =>
53
+ options.has(v),
54
+ );
55
+ return values.length ? [{ question: a.question, values }] : [];
56
+ });
57
+ }
58
+
59
+ /** Keep `answers` (`[{ question, values }]`), each replacing that question's earlier answer. */
60
+ export function rememberAnswers(propertyId, answers, now = Date.now()) {
61
+ const given = (Array.isArray(answers) ? answers : []).filter(
62
+ (a) => text(a?.question) && Array.isArray(a.values),
63
+ );
64
+ if (!given.length) return;
65
+ const asked = new Set(given.map((a) => a.question));
66
+ const next = [
67
+ ...kept(propertyId, now).filter((a) => !asked.has(a.q)),
68
+ ...given.map((a) => ({
69
+ q: a.question,
70
+ v: a.values.filter(text).slice(0, MAX_VALUES),
71
+ at: now,
72
+ })),
73
+ ].slice(-MAX_QUESTIONS);
74
+ try {
75
+ forgotten.delete(propertyId);
76
+ localStorage.setItem(keyOf(propertyId), JSON.stringify(next));
77
+ } catch {
78
+ // Quota or a disabled store: an early audience then waits for the warehouse.
79
+ }
80
+ }
81
+
82
+ /** The properties whose answers this page has removed, and written none since. */
83
+ const forgotten = new Set();
84
+
85
+ /**
86
+ * Forget the answers: `propertyId`'s, once a page while nothing new is kept (an event from a visitor
87
+ * without the grant); with none, every property's on the device (a consent change, a sign-out).
88
+ */
89
+ export function forgetAnswers(propertyId) {
90
+ if (propertyId === undefined) {
91
+ forgetEveryScope('answers');
92
+ forgotten.clear();
93
+ } else if (!forgotten.has(propertyId)) {
94
+ try {
95
+ localStorage.removeItem(keyOf(propertyId));
96
+ } catch {
97
+ // Nothing was stored.
98
+ }
99
+ forgotten.add(propertyId);
100
+ }
101
+ }
package/src/index.js CHANGED
@@ -42,6 +42,12 @@
42
42
  * trackRecommendationRails(analytics);
43
43
  */
44
44
 
45
+ import {
46
+ choiceAnswers,
47
+ forgetAnswers,
48
+ readAnswers,
49
+ rememberAnswers,
50
+ } from './answer-memory.js';
45
51
  import { assignmentSession, surfaceExposureToken } from './assignment.js';
46
52
  import { hostConsent, servingHeaders } from './consent.js';
47
53
  import { createConsentGate } from './consent-gate.js';
@@ -669,6 +675,8 @@ export function createAnalytics(options) {
669
675
  setSessionScope(perRequest(cfg.getSessionId, null), cfg.propertyId);
670
676
 
671
677
  let visitKept = false;
678
+ /** The settings the onsite runtime started on, once it has (`started`). */
679
+ let onsiteSettings = null;
672
680
 
673
681
  /** What `recommendationContext()` reads: the products and searches of the events sent. */
674
682
  function recordVisit(event) {
@@ -684,10 +692,17 @@ export function createAnalytics(options) {
684
692
  // A page view changes nothing a rail reads, so it does not extend what is kept for one.
685
693
  if (event.type === 'track')
686
694
  keepVisit(recommendationContextFrom(signals));
695
+ // What the shopper answered a form, for an early audience on the next page (ADR 0064). Kept as
696
+ // it is reported, as every other part of the visit is, not when the batch is delivered.
697
+ if (
698
+ event.event === 'Preferences Stated' &&
699
+ event.properties?.source === 'onsite'
700
+ )
701
+ keepAnswers([event.properties], event.properties.slot);
687
702
  visitKept = true;
688
703
  } else {
689
704
  // Not allowed, or withdrawn: what was kept under the permission goes with it.
690
- forgetKeptVisit();
705
+ forgetKeptVisit(false, cfg.propertyId ?? null);
691
706
  }
692
707
  } catch (err) {
693
708
  if (cfg.debug) console.warn('[hp] the visit was not recorded', err);
@@ -695,11 +710,25 @@ export function createAnalytics(options) {
695
710
  }
696
711
 
697
712
  /**
698
- * What the visit built up for recommendations, kept only under personalisation consent. The
699
- * session signals are cleared only when this SDK built them, unless `all`: a refusal or a sign-out.
713
+ * A form's choice answers, kept under personalisation consent, its questions read from the settings
714
+ * the onsite runtime started on (refreshed since the page's own), or the page's before it starts.
715
+ */
716
+ function keepAnswers(answers, slot) {
717
+ const form = (onsiteSettings ?? cfg.onsite)?.forms?.find?.(
718
+ (f) => f?.slot === slot,
719
+ );
720
+ rememberAnswers(cfg.propertyId, choiceAnswers(answers, form?.questions));
721
+ }
722
+
723
+ /**
724
+ * What the visit built up for recommendations, and the answers given to forms, kept only under
725
+ * personalisation consent. The session signals are cleared only when this SDK built them, unless
726
+ * `all`: a refusal or a sign-out. The answers are every property's, except on an event's path,
727
+ * which names its own (`answersOf`) so no event sweeps the device.
700
728
  */
701
- function forgetKeptVisit(all = false) {
729
+ function forgetKeptVisit(all = false, answersOf = undefined) {
702
730
  forgetVisit();
731
+ forgetAnswers(answersOf);
703
732
  if (all || visitKept) clearSessionSignals();
704
733
  visitKept = false;
705
734
  }
@@ -1197,6 +1226,14 @@ export function createAnalytics(options) {
1197
1226
  identityToken: () => (personalisationGranted() ? identityToken : null),
1198
1227
  analytics: granted,
1199
1228
  personalisation: personalisationGranted,
1229
+ /** A sign-up form's answers, once the gateway took them (`POST /v1/capture`, `/v1/capture/answers`). */
1230
+ answered: (answers, slot) => {
1231
+ if (personalisationGranted()) keepAnswers(answers, slot);
1232
+ },
1233
+ /** The settings the runtime started on, for the questions of the answers it reports. */
1234
+ started: (settings) => {
1235
+ onsiteSettings = settings;
1236
+ },
1200
1237
  consent: () => cfg.getConsent(),
1201
1238
  headers: () => servingHeaders(gate?.state ?? null),
1202
1239
  pageUrl: () =>
@@ -1229,6 +1266,7 @@ export function createAnalytics(options) {
1229
1266
  campaign: readVisitCampaign(cfg.propertyId, {
1230
1267
  sessionId: keptSession(),
1231
1268
  }),
1269
+ answers: readAnswers(cfg.propertyId),
1232
1270
  };
1233
1271
  },
1234
1272
  /**
package/src/onsite/api.js CHANGED
@@ -61,6 +61,19 @@ export function createApi(access, options = {}) {
61
61
  }
62
62
  }
63
63
 
64
+ /**
65
+ * A sign-up or its later answers, to the gateway. Once it takes them (2xx), the answers are kept
66
+ * on the device under personalisation consent, as a quiz's are (ADR 0064).
67
+ */
68
+ const taken = (path, body) =>
69
+ call(`${gateway}/v1/capture${path}`, { method: 'POST', body }).then(
70
+ (res) => {
71
+ if (res.status >= 200 && res.status < 300)
72
+ access.answered?.(body.answers, body.slot);
73
+ return res;
74
+ },
75
+ );
76
+
64
77
  return {
65
78
  /**
66
79
  * The decision for one slot, as the page's other serving calls ask for it, with its pin and
@@ -100,7 +113,12 @@ export function createApi(access, options = {}) {
100
113
  // What a promo reminder's code is answered for under a publishable key (ADR 0067).
101
114
  identity_token: access.identityToken?.() ?? undefined,
102
115
  ...(access.preview ? { preview: access.preview } : {}),
103
- ...(visitAudiences ? { visit_audiences: visitAudiences } : {}),
116
+ ...(visitAudiences && {
117
+ visit_audiences: visitAudiences.claims,
118
+ ...(visitAudiences.answered?.length && {
119
+ answered_audiences: visitAudiences.answered,
120
+ }),
121
+ }),
104
122
  ...(visitCampaign ? { visit_campaign: visitCampaign } : {}),
105
123
  ...(visitContext ? { visit_context: visitContext } : {}),
106
124
  },
@@ -111,10 +129,9 @@ export function createApi(access, options = {}) {
111
129
  timeoutMs: DATAFILE_TIMEOUT_MS,
112
130
  }),
113
131
  challenge: () => call(`${gateway}${challengePath(options.challenge)}`),
114
- capture: (body) => call(`${gateway}/v1/capture`, { method: 'POST', body }),
132
+ capture: (body) => taken('', body),
115
133
  // Answers given after the email step, with its address and receipt.
116
- answers: (body) =>
117
- call(`${gateway}/v1/capture/answers`, { method: 'POST', body }),
134
+ answers: (body) => taken('/answers', body),
118
135
  // Bounded, so the page's `submitted`, which waits for the claim, always comes.
119
136
  claim: (body) =>
120
137
  call(`${serving}/v1/offers/claim`, {
@@ -131,6 +131,7 @@ export function startOnsite(client, options = {}) {
131
131
  return null;
132
132
  }
133
133
  const settings = options.settings ?? access.settings ?? {};
134
+ access.started?.(settings);
134
135
  const api = createApi(access, {
135
136
  ...options,
136
137
  challenge: settings.capture?.challenge,
@@ -414,9 +415,11 @@ export function startOnsite(client, options = {}) {
414
415
  // The evaluator orders the page's own with the visit's (targets and what they require first);
415
416
  // a fallback sends the page's alone, the form's targets first and capped at the server's 100.
416
417
  const page = sessionAudiences() ?? [];
417
- const given = [...new Set([...form.audiences, ...page])]
418
- .filter((slug) => page.includes(slug))
419
- .slice(0, 100);
418
+ const given = {
419
+ claims: [...new Set([...form.audiences, ...page])]
420
+ .filter((slug) => page.includes(slug))
421
+ .slice(0, 100),
422
+ };
420
423
  const claimed =
421
424
  form.audiences.length > 0 && !access.preview && access.personalisation()
422
425
  ? await within(