@mrrocket/sdk 0.16.0 → 0.17.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,2 +1,2 @@
1
- (function(){'use strict';var pn=Object.defineProperty;var gn=(e,n,r)=>n in e?pn(e,n,{enumerable:true,configurable:true,writable:true,value:r}):e[n]=r;var ye=(e,n,r)=>gn(e,typeof n!="symbol"?n+"":n,r);var St=e=>{let n=0;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);s<128?n+=1:s<2048?n+=2:s>=55296&&s<=56319&&r+1<e.length&&(e.charCodeAt(r+1)&64512)===56320?(n+=4,r++):n+=3;}return n},mn=(e,n,r,s)=>{let a=`{"key":${JSON.stringify(e)},${s?`"userHash":${JSON.stringify(s)},`:""}"sdk":${JSON.stringify(r)},"events":[`,c=St(a)+2,p=[],R=[],S=[],h=c,O=()=>{R.length&&p.push({body:`${a}${R.join(",")}]}`,events:S}),R=[],S=[],h=c;};for(let m of n){let k=JSON.stringify(m),E=St(k)+1;c+E>6e4||((R.length===100||h+E>6e4)&&O(),R.push(k),S.push(m),h+=E);}return O(),p},Ot=(e,n,r,s)=>mn(e,n,r,s).map(a=>a.body);var _e=class{constructor(n=1e3,r=30,s=3){ye(this,"windowMs",n);ye(this,"radius",r);ye(this,"count",s);ye(this,"clicks",[]);ye(this,"fired",false);}push(n,r,s){let a=this.clicks.filter(c=>s-c.t<=this.windowMs&&Math.hypot(c.x-n,c.y-r)<=this.radius);return a.length!==this.clicks.length&&(this.fired=false),this.clicks=[...a,{x:n,y:r,t:s}],this.clicks.length>=this.count&&!this.fired?(this.fired=true,true):false}};var wn='a[href],button,input,select,textarea,label,summary,[role="button"],[role="link"],[role="tab"],[role="menuitem"],[role="checkbox"],[role="switch"],[onclick],[data-ck-goal]',hn="[data-ck-mask]",kn="[data-ck-block]",It=/\d{4,}|^[a-z]{1,3}-[a-z0-9]{5,}$|^_|__|css-|^sc-|^jsx-/i,yn=e=>{let n=e.tagName.toLowerCase();if(e.id&&!It.test(e.id)&&e.id.length<=40)return `${n}#${e.id}`;let r=typeof e.className=="string"?e.className.split(/\s+/).filter(c=>c&&!It.test(c)&&c.length<=30&&!c.includes(":")):[],s=r.length?`${n}.${r.slice(0,2).join(".")}`:n,a=e.parentElement?[...e.parentElement.children].filter(c=>c.tagName===e.tagName):[];return a.length>1?`${s}:nth-of-type(${a.indexOf(e)+1})`:s},bn=e=>{let n=[],r=e;for(;r&&n.length<3&&r.tagName&&r.tagName!=="BODY"&&r.tagName!=="HTML";){let s=yn(r);if(n.unshift(s),s.includes("#"))break;r=r.parentElement;}return n.join(" > ").slice(0,160)},Ae=e=>(e!=null?e:"").replace(/\s+/g," ").trim().slice(0,40),xn=e=>{var r,s,a,c,p;if(e.closest(`${hn},${kn}`))return "";let n=e.tagName.toLowerCase();if(n==="input"){let R=((r=e.getAttribute("type"))!=null?r:"text").toLowerCase();return Ae(R==="submit"||R==="button"?(s=e.getAttribute("aria-label"))!=null?s:e.value:e.getAttribute("aria-label"))}return Ae(n==="select"||n==="textarea"?e.getAttribute("aria-label"):(p=(c=(a=e.getAttribute("aria-label"))!=null?a:e.getAttribute("title"))!=null?c:e.innerText)!=null?p:e.textContent)},Ft=e=>{var c,p;let n=e.target instanceof Element?e.target:null;if(!n)return null;let r=n.closest(wn),s=r!=null?r:n,a=document.documentElement;return {x:Math.round(e.clientX),y:Math.round(e.clientY+window.scrollY),vw:window.innerWidth,vh:window.innerHeight,docH:Math.max(a.scrollHeight,(p=(c=document.body)==null?void 0:c.scrollHeight)!=null?p:0),selector:bn(s),label:r?xn(r):"",interactive:!!r}},$t=()=>{var r,s;let e=document.documentElement,n=Math.max(e.scrollHeight,(s=(r=document.body)==null?void 0:r.scrollHeight)!=null?s:0);return n?Math.min(100,Math.round((window.scrollY+window.innerHeight)/n*100)):0};var Le="0.16.0",Cn=(e,n)=>{let r=n.trim().toLowerCase();for(let[s,a]of Object.entries(e))if(s.toLowerCase()===r)return a},Rn=(e,n)=>{let r=e.trim().toLowerCase(),s=n.trim().toLowerCase();return s.startsWith("@")?r.endsWith(s):r===s},vn=(e,n)=>{if(e.op==="in cohort")return false;let r=Cn(n,e.property),s=r==null?"":String(r);if(e.op==="\u2265"){let c=Number(s),p=Number(e.values[0]);return s!==""&&Number.isFinite(c)&&Number.isFinite(p)&&c>=p}let a=s!==""&&e.values.some(c=>Rn(s,c));return e.op==="is"||e.op==="in"?a:!a},En=(e,n,r={})=>{var R;if(!e.on)return false;let s={id:n,...r},a=e.sets.length?e.sets.find(S=>S.conditions.every(h=>vn(h,s))):{rollout:100};if(!a||Pt(`${e.key}:rollout:${n}`)*100>=a.rollout)return false;if(!((R=e.variants)!=null&&R.length))return true;let c=Pt(`${e.key}:variant:${n}`)*100,p=0;for(let S of e.variants)if(p+=S.split,c<p)return S.key;return e.variants[e.variants.length-1].key},rt=(e,n,r,s={})=>{var c;let a=(c=n==null?void 0:n.flags)==null?void 0:c.find(p=>p.key===e);return a?En(a,r,s):false},_n=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],Mt="ck_preview",At="ck_embed",ue="ck_id",be="ck_sid";var Sn=e=>{var r;let n={};for(let s of _n){let a=(r=e(s))==null?void 0:r.trim();a&&(n[s]=a.slice(0,150));}return n},Nt=e=>{let n=new URLSearchParams(e);return Sn(r=>n.get(r))};var On=e=>{let n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619);return (n>>>0)/4294967296},Pt=e=>{let n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619);return n^=n>>>16,n=Math.imul(n,2246822507),n^=n>>>13,n=Math.imul(n,3266489909),n^=n>>>16,(n>>>0)/4294967296},In=(e,n)=>{var c,p,R,S;let r=(p=(c=e.variants[0])==null?void 0:c.id)!=null?p:"control";if(e.winner)return e.winner;if(e.status!=="running")return r;let s=On(`${e.key}:${n}`),a=0;for(let h of e.variants)if(a+=h.weight,s<a)return h.id;return (S=(R=e.variants[e.variants.length-1])==null?void 0:R.id)!=null?S:r},Lt=e=>{let n=Array.isArray(e)?e[0]:e;if(!n)return {};let r={};for(let s of n.split(",")){let[a,c]=s.split(":");a&&c&&(r[a.trim()]=c.trim());}return r};var Oe=(e,n,r,s)=>{if(s[e])return s[e];let a=n==null?void 0:n.experiments.find(c=>c.key===e);return a?In(a,r):"control"},Tt=(e,n,r)=>{var a,c,p,R,S,h;let s={...(a=e==null?void 0:e.texts)!=null?a:{}};for(let O of (c=e==null?void 0:e.experiments)!=null?c:[]){let m=Oe(O.key,e,n,r);m!==((R=(p=O.variants[0])==null?void 0:p.id)!=null?R:"control")&&Object.assign(s,(h=(S=O.variants.find(k=>k.id===m))==null?void 0:S.changes)!=null?h:{});}return s},Se="ck_x",Ne=e=>e.replace(/\/+$/,"")||"/",Ut=(e,n,r,s={})=>{var R,S;if(!e)return null;let a;try{a=new URL(n);}catch(h){return null}if(a.searchParams.has(Se))return null;let c=Ne(a.pathname),p=(h,O)=>{let m;try{m=new URL(h,a);}catch(k){return}if(!(!/^https?:$/.test(m.protocol)||m.origin===a.origin&&Ne(m.pathname)===c))return a.searchParams.forEach((k,E)=>{m.searchParams.has(E)||m.searchParams.set(E,k);}),O&&m.searchParams.set(Se,O),m.hash||(m.hash=a.hash),m.href};for(let h of (R=e.redirects)!=null?R:[]){let O=h.from&&Ne(h.from)===c?p(h.to):void 0;if(O)return {to:O}}for(let h of e.experiments){if(!h.path||Ne(h.path)!==c)continue;let O=h.status==="running"&&!h.winner;if(O&&r===null&&!s[h.key])return null;let m=Oe(h.key,e,r!=null?r:"",s),k=(S=h.variants.find(I=>I.id===m))==null?void 0:S.url,E=k?p(k,O?`${h.key}:${m}`:void 0):void 0;return O?{to:E,experiment:h.key,variant:m}:E?{to:E}:null}return null},Ht=(e,n)=>{let[r,s]=(n!=null?n:"").split(":"),a=e==null?void 0:e.experiments.find(c=>c.key===r);return a&&a.variants.some(c=>c.id===s)?{experiment:r,variant:s}:null};var ot=()=>typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID():`ck_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;var Fn="401: sign the user id on your server with userHash(id) from @mrrocket/sdk/next/server and pass identify(id, props, { hash }).",xe=(e,n=r=>console.warn(r))=>{let r=globalThis;e!==401||r.__mrrocketUnsigned||(r.__mrrocketUnsigned=true,n(`[MRRocket] ${Fn}`));},Dt=(e,n,r,s=a=>console.warn(a))=>{let a=typeof r=="string"?r.trim().toLowerCase():"";return /^[0-9a-f]{64}$/.test(a)?{id:n,hash:a}:(a&&s("[MRRocket] identify: that hash is no userHash(id); not sent."),e&&e.id===n?e:null)},jt=(e,n)=>e&&n&&e.id===n?e.hash:void 0,Wt=(e,n)=>e&&n.some(r=>r===e.id)&&n.every(r=>!r||r===e.id)?e.hash:void 0;var $n=8*1024,Pn=20,Mn=20,An=2e3,Ie=(e,n)=>e.length>n?`${e.slice(0,n-1)}\u2026`:e,Nn=e=>{var n;if(e instanceof Error)return {type:e.name||"Error",message:Ie(e.message||String(e),1e3),stack:e.stack?Ie(e.stack,$n):void 0};if(typeof e=="string")return {type:"Error",message:Ie(e,1e3)};try{return {type:"Error",message:Ie((n=JSON.stringify(e))!=null?n:String(e),1e3)}}catch(r){return {type:"Error",message:String(e)}}},Kt=e=>{let n=[],r=[],s=new Set,a=0,c=`${e.host}/api/sdk/errors`,p=(k=false)=>{for(;n.length;){let E=n.splice(0,4),I=e.context(),T=I.distinctId&&I.userHash?{id:I.distinctId,hash:I.userHash}:null,M=Wt(T,E.map(N=>N.distinctId)),K=JSON.stringify({key:e.apiKey,...M?{userHash:M}:{},errors:E});k&&typeof navigator!="undefined"&&"sendBeacon"in navigator&&navigator.sendBeacon(c,K)||fetch(c,{method:"POST",headers:{"content-type":"application/json"},body:K,keepalive:true}).then(N=>{N.status===401?xe(401):!N.ok&&N.status!==429&&e.warn(`Error reports were rejected with ${N.status}. Check the public key and NEXT_PUBLIC_MRROCKET_HOST.`);}).catch(()=>{});}},R=(k,E="manual")=>{let I=e.context();if(!I.send||a>=Pn)return;let T=Nn(k);if(/\/api\/sdk\/errors/.test(T.message))return;let M=`${T.type}:${T.message}`;s.has(M)||(s.add(M),a++,n.push({...T,mechanism:E,handled:E==="manual",url:window.location.href,ts:Date.now(),crumbs:r.slice(),...e.release?{release:e.release}:{},...I.distinctId?{distinctId:I.distinctId}:{},...I.sessionId?{sessionId:I.sessionId}:{}}));},S=k=>{var E;!k.error&&(!k.message||k.message==="Script error.")||R((E=k.error)!=null?E:new Error(k.message),"onerror");},h=k=>{var E;return R((E=k.reason)!=null?E:new Error("Unhandled promise rejection"),"onunhandledrejection")},O=()=>p(true);window.addEventListener("error",S),window.addEventListener("unhandledrejection",h),window.addEventListener("pagehide",O);let m=window.setInterval(()=>p(),An);return {capture:R,crumb:(k,E)=>{r.push({ts:Date.now(),type:k,message:Ie(E,120)}),r.length>Mn&&r.shift();},stop:()=>{window.removeEventListener("error",S),window.removeEventListener("unhandledrejection",h),window.removeEventListener("pagehide",O),window.clearInterval(m),p(true);}}};var Fe="$cancel_flow",ie="$onboarding",st="$inapp";var Ln={version:0,question:"",reasons:[],offers:{},confirm:{title:"Cancel your subscription?",body:"You keep access until the end of the billing period.",button:"Cancel subscription"},offersFor:"business"},Tn="Something went wrong. Please try again.",Vt="mrrocket:onboarding",Ue=e=>e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),Bt=new Set(["signed_up","signup","sign_up","registered","account_created","user_signed_up"]),it=(e,n)=>{let r=Ue(e),s=Ue(n);return !r||!s?false:r===s||Bt.has(r)&&Bt.has(s)},Un=e=>/^(first (launch|visit|open|session|login|sign ?in|app open)|app (opened|launched)|on load|every visit|always)?$/i.test(e.trim()),Hn=()=>`cf_${Math.random().toString(36).slice(2,10)}${Date.now().toString(36)}`;var Dn=e=>{let n=(e!=null?e:"").trim();return /^https?:\/\//i.test(n)||/^\/(?!\/)/.test(n)?n:void 0},fe=e=>{var n;return (n=e.nodes)!=null?n:e.steps},jn=e=>Math.max(0,e.amount)*(e.unit==="hours"?36e5:864e5),Wn=(e,n)=>{let r=e.trim(),s=(n.split(/[?#]/)[0]||"/").replace(/\/+$/,"")||"/";if(!r)return false;if(r.endsWith("*")){let a=r.slice(0,-1).replace(/\/+$/,"");return !a||s===a||s.startsWith(`${a}/`)}return s===(r.replace(/\/+$/,"")||"/")},at=e=>e.flatMap(n=>n.kind==="condition"?[...at(n.yes),...at(n.no)]:n.kind==="wait"?[]:[n]),Kn=(e,n=Date.now())=>e==null||e===""?NaN:Math.floor((n-new Date(e).getTime())/2630016e3),Te=e=>e==null?void 0:e.trim().toLowerCase(),Vn=({when:e={}},n)=>(e.answer==null||Te(e.answer)===Te(n.answer))&&(e.plan==null||[e.plan].flat().some(r=>Te(r)===Te(n.plan)))&&!(n.months>=e.tenureUnder)&&!(n.months<e.tenureOver)&&(e.tenureUnder==null||n.months>=0)&&(e.tenureOver==null||n.months>=0),qt=e=>{let n=null,r=null,s=null,a=[],c=false,p=null,R,S=null,h=new Map,O=new Set,m=new Set,k=new Set,E=e.auto!==false,I=new Set,T=()=>{var t,i;return (i=(t=e.now)==null?void 0:t.call(e))!=null?i:Date.now()},M=null,K=()=>{var t;return (t=n==null?void 0:n.onboarding)!=null?t:[]},Q=t=>t?K().find(i=>i.id===t):void 0,N=t=>{let i=h.get(t);return i||h.set(t,i={done:new Set,dismissed:false,answers:new Map,at:new Map,reached:new Map}),i},ee=false,V=t=>{e.track(ie,t),ee=true;},ae=(t,i)=>{t.done.add(i),t.at.set(i,T());},ze=t=>{var i,l,g;if((i=t.page)!=null&&i.trim()){let d=(l=e.path)==null?void 0:l.call(e);return d===void 0?false:Wn(t.page,d)}if((g=t.event)!=null&&g.trim()){if(!c)return;for(let d of I)if(it(t.event,d))return true;return false}return false},pe=(t,i,l,g,d=0,C)=>{var _,y;for(let b=0;b<i.length;b++){let x=i[b];if(x.kind==="wait"){if(l.done.has(x.id)){C=(_=l.at.get(x.id))!=null?_:C;continue}let F=l.reached.get(x.id);if(F===void 0){if(!g)return {at:"pending"};F=C!=null?C:T(),l.reached.set(x.id,F),V({flow:t.id,step:x.id,kind:"wait",action:"shown"});}let B=F+jn(x);if(T()<B)return {at:"wait",until:B};if(!g)return {at:"pending"};ae(l,x.id),V({flow:t.id,step:x.id,kind:"wait",action:"completed"}),C=B;continue}if(x.kind==="condition"){let F=l.answers.get(x.id);if(F===void 0){if(!g)return {at:"pending"};if(F=ze(x),F===void 0)return {at:"pending"};l.answers.set(x.id,F),V({flow:t.id,step:x.id,kind:"condition",action:"answered",answer:F?"yes":"no"});}return pe(t,F?x.yes:x.no,l,g,d,C)}if(!l.done.has(x.id))return {at:"step",step:x,line:i,index:b,before:d};C=(y=l.at.get(x.id))!=null?y:C,d++;}return {at:"end"}},ce=t=>{let i=h.get(t.id);return !!i&&(i.dismissed||pe(t,fe(t),i,false).at==="end")},ge=t=>`${Vt}:${t!=null?t:"visitor"}`,H=t=>`${Vt}:events:${t!=null?t:"visitor"}`,Y=()=>{var l;ee=false;let t=(l=e.storage)==null?void 0:l.call(e);if(!t)return;let i={};for(let[g,d]of h)i[g]={done:[...d.done],...d.dismissed?{dismissed:true}:{},...d.answers.size?{answers:Object.fromEntries([...d.answers].map(([C,_])=>[C,_?"yes":"no"]))}:{},...d.at.size?{at:Object.fromEntries(d.at)}:{},...d.reached.size?{reached:Object.fromEntries(d.reached)}:{}};try{t.set(ge(e.personId()),JSON.stringify(i)),I.size&&t.set(H(e.personId()),JSON.stringify([...I].slice(-200)));}catch(g){}},te=t=>{var i,l,g,d;for(let[C,_]of Object.entries(t!=null?t:{})){let y=N(C);for(let b of (i=_.done)!=null?i:[])y.done.add(b);_.dismissed&&(y.dismissed=true);for(let[b,x]of Object.entries((l=_.answers)!=null?l:{}))y.answers.has(b)||y.answers.set(b,x==="yes");for(let[b,x]of Object.entries((g=_.at)!=null?g:{}))typeof x=="number"&&!y.at.has(b)&&y.at.set(b,x);for(let[b,x]of Object.entries((d=_.reached)!=null?d:{}))typeof x=="number"&&(!y.reached.has(b)||x<y.reached.get(b))&&y.reached.set(b,x);}},P=t=>{var l;M&&clearTimeout(M),M=null;let i=t-T();i>0&&i<=864e5&&(M=setTimeout(()=>(M=null,A()),i+50),(l=M.unref)==null||l.call(M));},X=false,le=()=>{X=false;let t=Q(s);if(!t)return null;let i=N(t.id);if(i.dismissed)return null;let l=pe(t,fe(t),i,true);if(ee&&Y(),l.at==="wait"&&P(l.until),X=l.at==="wait"||l.at==="pending",l.at!=="step")return null;let{step:g,line:d,index:C}=l,_=F=>!!F&&F.kind!=="wait"&&F.kind!=="condition";if(g.kind==="checklist"){let F=C;for(;F>0&&_(d[F-1])&&d[F-1].kind==="checklist";)F--;let B=C;for(;B+1<d.length&&_(d[B+1])&&d[B+1].kind==="checklist";)B++;let ve=d.slice(F,B+1).filter(_);for(let J of ve)!i.done.has(J.id)&&!m.has(`s:${J.id}`)&&(m.add(`s:${J.id}`),e.track(ie,{flow:t.id,step:J.id,kind:"checklist",action:"shown"}));return {type:"checklist",flow:t,items:ve.map(J=>({step:J,done:i.done.has(J.id)}))}}m.has(`s:${g.id}`)||(m.add(`s:${g.id}`),e.track(ie,{flow:t.id,step:g.id,kind:g.kind,action:"shown"}));let y=d.slice(C+1),b=y.findIndex(F=>F.kind==="condition"),x=(b<0?y:y.slice(0,b)).filter(_).length;return {type:"step",flow:t,step:g,index:l.before,total:l.before+1+x,last:!x&&b<0}},de=()=>{var l,g;if(r){let d=r,C=(l=d.flow.followUps)==null?void 0:l[d.reason],_=C?1:0,y=d.plain?1:3+_+((g=d.flow.second)!=null&&g[d.reason]?1:0);return {type:"cancel",screen:d.screen,flow:d.flow,reason:d.reason,...d.screen==="followup"&&C?{followUp:C,answer:d.answer}:{},offer:d.screen==="offer"?d.offer:void 0,...d.screen==="offer"?{round:d.round}:{},price:d.options.price,busy:d.busy,error:d.error,step:d.screen==="survey"?1:d.screen==="followup"?2:d.screen==="offer"?1+_+d.round:y,steps:y}}let t=le();if(t)return t;s&&!X&&(s=null);let i=a.find(d=>!O.has(d.id));return i?{type:"message",message:i}:null},A=()=>{let t=de();(t==null?void 0:t.type)==="message"&&!m.has(`m:${t.message.id}`)&&(m.add(`m:${t.message.id}`),e.track(st,{message:t.message.id,journey:t.message.journey,action:"shown"}));for(let i of [...k])try{i();}catch(l){}},me=t=>s===t.id?true:s&&Q(s)&&!ce(Q(s))?false:(s=t.id,e.track(ie,{flow:t.id,action:"started"}),A(),true),ne=()=>{var i;if(!E||s||!c||!e.personId()&&!((i=e.storage)!=null&&i.call(e)))return;let t=K().find(l=>Un(l.trigger)&&fe(l).length&&!ce(l));t&&me(t);},Ce=()=>{let t=e.personId();S!==null&&S!==t&&(h.clear(),I.clear(),O.clear(),s=null,R=void 0),S=t;let i=(async()=>{var d,C,_;let l=(d=e.storage)==null?void 0:d.call(e);if(l)try{let y=await l.get(ge(t));y&&te(JSON.parse(y));let b=await l.get(H(t));if(b)for(let x of JSON.parse(b))typeof x=="string"&&I.add(x);}catch(y){}let g=K().length>0||!!(n!=null&&n.messages);if(t&&g&&R!==t){R=t;let y=await e.fetchInApp(t).catch(()=>null);if(y&&e.personId()===t){te(y.onboarding);for(let b of (C=y.events)!=null?C:[])typeof b=="string"&&I.add(Ue(b));a=((_=y.messages)!=null?_:[]).filter(b=>b&&b.id&&b.title);}}t||(a=[]),c=true,ne(),A();})();return p=i.finally(()=>{p===i&&(p=null);}),p},we=t=>t.round>1?{round:2}:t.rule>=0?{rule:t.rule}:{},D=t=>{var g,d,C,_;let i={answer:t.answer,plan:t.options.plan,months:Kn(t.options.customerSince,(g=e.now)==null?void 0:g.call(e))},l=(C=(d=t.flow.rules)==null?void 0:d[t.reason])!=null?C:[];t.rule=l.findIndex(y=>Vn(y,i)),t.offer=t.rule<0?t.flow.offers[t.reason]:(_=l[t.rule].offer)!=null?_:void 0,t.round=1,t.screen=t.offer?"offer":"confirm";},j=(t,i,l)=>{var d;let g=t.screen==="offer"?t.offer:void 0;return {outcome:i,run:t.run,...t.reason?{reason:t.reason,reasonLabel:(d=t.flow.reasons.find(C=>C.id===t.reason))==null?void 0:d.label}:{},...t.answer?{answer:t.answer}:{},...i==="saved"&&g?{offer:g}:{},...l!=null&&l.trim()?{comment:l.trim().slice(0,500)}:{}}},W=(t,i)=>{var l;e.track(Fe,{action:"finished",run:t.run,version:t.flow.version,outcome:i.outcome,customer:(l=t.options.customer)!=null?l:"consumer",...i.reason?{reason:i.reason}:{},...i.answer?{answer:i.answer}:{},...i.offer?{offer:i.offer.kind,...we(t)}:{},...i.comment?{comment:i.comment}:{}}),r===t&&(r=null),t.resolve(i),A();},z=(t,i,l)=>{if(t.busy)return;let g=j(t,i,l),d=i==="saved"?t.options.onSave:t.options.onCancel;t.busy=true,t.error=void 0,A(),Promise.resolve().then(()=>d==null?void 0:d(g)).then(()=>W(t,g),()=>{t.busy=false,t.error=Tn,A();});};return {setConfig:t=>{n=t,s&&!Q(s)&&(s=null),A();},refresh:Ce,onEvent:t=>{var _;if(!t||t.startsWith("$"))return;let i=Ue(t),l=!!i&&!I.has(i);l&&I.add(i);let g=Q(s),d=false;if(g){let y=N(g.id);for(let b of at(fe(g)))b.kind==="checklist"&&b.event&&!y.done.has(b.id)&&it(b.event,t)&&(ae(y,b.id),d=true,e.track(ie,{flow:g.id,step:b.id,kind:b.kind,action:"completed"}));}if(d||l&&g?(Y(),A()):l&&Y(),!E||!e.personId()&&!((_=e.storage)!=null&&_.call(e)))return;let C=K().find(y=>fe(y).length&&it(y.trigger,t)&&!ce(y));C&&me(C);},openCancelFlow:(t={})=>{var _,y;if(r)return r.promise;let i=(_=n==null?void 0:n.cancelFlow)!=null?_:Ln,l=t.customer!=="business"||i.reasons.length<2,g=()=>{},d=new Promise(b=>g=b),C={flow:i,options:t,plain:l,screen:l?"confirm":"survey",round:1,run:Hn(),busy:false,resolve:g,promise:d};return r=C,e.track(Fe,{action:"shown",run:C.run,version:i.version,customer:(y=t.customer)!=null?y:"consumer",plain:l}),A(),d},startOnboarding:t=>{let i=t?Q(t):K().find(g=>fe(g).length&&!ce(g));if(!i||!fe(i).length)return false;let l=N(i.id);return l.dismissed=false,me(i)},view:de,subscribe:t=>(k.add(t),()=>k.delete(t)),cancel:{pick:t=>{!r||r.busy||r.screen!=="survey"||!r.flow.reasons.some(i=>i.id===t)||(r.reason!==t&&(r.answer=void 0),r.reason=t,r.error=void 0,A());},answer:t=>{let i=r;if(!i||i.busy||i.screen!=="followup")return;let l=t.slice(0,500);i.answer=l.trim()?l:void 0,A();},next:()=>{var i,l;let t=r;if(!(!t||!t.reason)){if(t.screen==="survey")e.track(Fe,{action:"answered",run:t.run,version:t.flow.version,reason:t.reason}),(i=t.flow.followUps)!=null&&i[t.reason]?t.screen="followup":D(t);else if(t.screen==="followup")t.answer=(l=t.answer)==null?void 0:l.trim(),D(t);else return;A();}},accept:t=>{var l;let i=r;!i||i.screen!=="offer"||!i.reason||(i.busy||e.track(Fe,{action:"offer",run:i.run,version:i.flow.version,reason:i.reason,offer:(l=i.offer)==null?void 0:l.kind,...we(i),outcome:"accepted"}),z(i,"saved",t));},decline:()=>{var l,g;let t=r;if(!t||t.screen!=="offer"||t.busy)return;e.track(Fe,{action:"offer",run:t.run,version:t.flow.version,reason:t.reason,offer:(l=t.offer)==null?void 0:l.kind,...we(t),outcome:"declined"});let i=t.round===1&&t.reason?(g=t.flow.second)==null?void 0:g[t.reason]:void 0;i?(t.offer=i,t.rule=void 0,t.round=2):t.screen="confirm",t.error=void 0,A();},confirm:t=>{let i=r;!i||i.screen!=="confirm"||z(i,"cancelled",t);},close:()=>{var l,g;let t=r;if(!t||t.busy)return;let i=j(t,"kept");(g=(l=t.options).onClose)==null||g.call(l,i),W(t,i);}},onboarding:{next:()=>{let t=le();(t==null?void 0:t.type)==="step"&&(ae(N(t.flow.id),t.step.id),e.track(ie,{flow:t.flow.id,step:t.step.id,kind:t.step.kind,action:"completed"}),Y(),A());},check:t=>{let i=le();if((i==null?void 0:i.type)!=="checklist")return;let l=i.items.find(g=>g.step.id===t);!l||l.done||(ae(N(i.flow.id),t),e.track(ie,{flow:i.flow.id,step:t,kind:"checklist",action:"completed"}),Y(),A());},dismiss:()=>{let t=le();!t||t.type!=="step"&&t.type!=="checklist"||(N(t.flow.id).dismissed=true,e.track(ie,{flow:t.flow.id,...t.type==="step"?{step:t.step.id}:{},action:"dismissed"}),s=null,Y(),A());}},message:{click:()=>{var l;let t=de();if((t==null?void 0:t.type)!=="message")return;O.add(t.message.id),e.track(st,{message:t.message.id,journey:t.message.journey,action:"clicked"});let i=Dn(t.message.url);A(),i&&((l=e.openUrl)==null||l.call(e,i));},dismiss:()=>{let t=de();(t==null?void 0:t.type)==="message"&&(O.add(t.message.id),e.track(st,{message:t.message.id,journey:t.message.journey,action:"dismissed"}),A());}}}};var Bn="ck_pick",qn="ck_origin",He=e=>typeof CSS!="undefined"&&CSS.escape?CSS.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,n=>`\\${n}`),Yn=e=>[...e.classList].filter(n=>n.length<30&&!/\d{2,}|[_-][a-z0-9]{5,}$|^(is|has)-|hover|active|focus|open|selected|:|\[/.test(n)).slice(0,2),Yt=e=>{let n=e.ownerDocument,r=p=>{try{return n.querySelectorAll(p).length===1}catch(R){return false}},s=e.getAttribute("data-ck-target");if(s)return `[data-ck-target="${s.replace(/"/g,'\\"')}"]`;if(e.id&&!/\d{3,}/.test(e.id)&&r(`#${He(e.id)}`))return `#${He(e.id)}`;let a=[],c=e;for(;c&&c!==n.documentElement&&a.length<6;){if(c!==e&&c.id&&!/\d{3,}/.test(c.id)){a.unshift(`#${He(c.id)}`);break}let p=c.tagName.toLowerCase(),R=Yn(c).map(k=>`.${He(k)}`).join(""),S=c.parentElement,h=S?[...S.children].filter(k=>k.tagName===c.tagName):[],O=h.length>1?`:nth-of-type(${h.indexOf(c)+1})`:"";a.unshift(`${p}${R}${O}`);let m=a.join(" > ");if(r(m))return m;c=S;}return a.join(" > ")},Xt=()=>{var O;if(typeof window=="undefined"||window.top===window)return null;let e=new URLSearchParams(window.location.search);if(e.get(Bn)!=="1")return null;let n;try{n=new URL((O=e.get(qn))!=null?O:"").origin;}catch(m){return null}if(!/^https?:\/\//.test(n))return null;let r=m=>window.parent.postMessage(m,n),s=document.createElement("div");s.setAttribute("aria-hidden","true"),Object.assign(s.style,{position:"fixed",zIndex:"2147483647",pointerEvents:"none",border:"2px solid #0ea5e9",background:"rgba(14,165,233,.12)",borderRadius:"6px",transition:"all 60ms linear",display:"none"});let a=document.createElement("div");Object.assign(a.style,{position:"absolute",left:"-2px",bottom:"calc(100% + 4px)",font:"600 11px/1.4 system-ui, sans-serif",color:"#fff",background:"#0c4a6e",padding:"2px 6px",borderRadius:"4px",whiteSpace:"nowrap",maxWidth:"360px",overflow:"hidden",textOverflow:"ellipsis"}),s.appendChild(a),document.body.appendChild(s);let c=null,p=m=>{if(c=m&&m!==s&&!s.contains(m)?m:null,!c){s.style.display="none";return}let k=c.getBoundingClientRect();Object.assign(s.style,{display:"block",left:`${k.left-2}px`,top:`${k.top-2}px`,width:`${k.width+4}px`,height:`${k.height+4}px`}),a.textContent=Yt(c);},R=m=>p(document.elementFromPoint(m.clientX,m.clientY)),S=m=>{var E,I;m.preventDefault(),m.stopPropagation();let k=(E=document.elementFromPoint(m.clientX,m.clientY))!=null?E:c;!k||k===s||r({type:"mrrocket:picked",selector:Yt(k),text:((I=k.textContent)!=null?I:"").trim().replace(/\s+/g," ").slice(0,80)});},h=m=>{m.key==="Escape"&&r({type:"mrrocket:pick-cancel"});};return window.addEventListener("mousemove",R,true),window.addEventListener("click",S,true),window.addEventListener("keydown",h,true),r({type:"mrrocket:pick-ready"}),()=>{window.removeEventListener("mousemove",R,true),window.removeEventListener("click",S,true),window.removeEventListener("keydown",h,true),s.remove();}};var Xn={get:e=>{try{return window.localStorage.getItem(e)}catch(n){return null}},set:(e,n)=>{try{window.localStorage.setItem(e,n);}catch(r){}}},zt=()=>{try{for(let e=window.localStorage.length-1;e>=0;e--){let n=window.localStorage.key(e);n!=null&&n.startsWith("mrrocket:onboarding")&&window.localStorage.removeItem(n);}}catch(e){}},Jt=e=>({track:e.track,personId:e.personId,auto:e.auto,storage:()=>e.canStore()?Xn:null,openUrl:n=>window.location.assign(n),path:()=>window.location.pathname,fetchInApp:async n=>{var a;if(!e.apiKey)return null;let r=(a=e.userHash)==null?void 0:a.call(e,n),s=await fetch(`${e.host}/api/sdk/inapp?key=${encodeURIComponent(e.apiKey)}&distinctId=${encodeURIComponent(n)}${r?`&userHash=${r}`:""}`);return xe(s.status),s.ok?await s.json():null}});var We="mrr_ref",Ke="mrr_ref",zn="mrr_ref",Jn="mrr_click";var $e=/^[A-Za-z0-9_-]{1,64}$/;var Gn=(e,n="ref")=>{let r=new URLSearchParams(e);return Qn(s=>r.get(s),n)},Qn=(e,n="ref")=>{let r=e(zn);if(r&&$e.test(r)){let a=e(Jn);return {code:r,clickId:a&&$e.test(a)?a:null,direct:false}}let s=e(n);return s&&$e.test(s)?{code:s,clickId:null,direct:true}:null},Gt=e=>{var n;return `${e.code}.${(n=e.clickId)!=null?n:""}.${e.at}`},De=(e,n=60,r=Date.now())=>{if(!e)return null;let[s,a,c]=e.split("."),p=Number(c);return !s||!$e.test(s)||!Number.isFinite(p)||a&&!$e.test(a)||r-p>n*864e5||p>r+864e5?null:{code:s,clickId:a||null,at:p}};var U=null,Ve=()=>typeof document!="undefined",Qt=e=>{var r;if(!Ve())return;let n=(r=document.cookie.split("; ").find(s=>s.startsWith(`${e}=`)))==null?void 0:r.slice(e.length+1);try{return n?decodeURIComponent(n):void 0}catch(s){return n}},Be=()=>{try{return typeof localStorage=="undefined"?null:localStorage}catch(e){return null}},ct=()=>{var e,n;return U||(Ve()?(n=De(Qt(We),3650))!=null?n:De((e=Be())==null?void 0:e.getItem(Ke),3650):null)};var je=(e,n)=>{var a;if(!Ve())return;let r=Math.max(1,Math.round(n))*86400,s=typeof location!="undefined"&&location.protocol==="https:"?"; secure":"";document.cookie=`${We}=${encodeURIComponent(Gt(e))}; path=/; max-age=${r}; samesite=lax${s}`;try{(a=Be())==null||a.setItem(Ke,Gt(e));}catch(c){}},qe=()=>{var e;if(Ve()){document.cookie=`${We}=; path=/; max-age=0; samesite=lax`;try{(e=Be())==null||e.removeItem(Ke);}catch(n){}}},Zt=()=>{U=null;},en=async e=>{var s,a,c;let n=Gn(e.search,e.param),r=(s=e.now)!=null?s:Date.now();if(!n)return !U&&e.store&&(U=(c=De(Qt(We),e.days,r))!=null?c:De((a=Be())==null?void 0:a.getItem(Ke),e.days,r),U||qe()),U;if(U={code:n.code,clickId:n.clickId,at:r},e.store&&je(U,e.days),e.beacon)try{let p=await e.beacon({code:n.code,clickId:n.clickId});p&&U&&U.code===n.code&&!U.clickId&&(U={...U,clickId:p},e.store&&je(U,e.days));}catch(p){}return U},tn=e=>e==="$identify"||!e.startsWith("$");var lt=3600*24*365,on=e=>{var r;if(typeof document=="undefined")return;let n=(r=document.cookie.split("; ").find(s=>s.startsWith(`${e}=`)))==null?void 0:r.slice(e.length+1);if(n)try{return decodeURIComponent(n)}catch(s){return n}},Ye=(e,n,r)=>{let s=window.location.protocol==="https:"?"; secure":"";document.cookie=`${e}=${encodeURIComponent(n)}; path=/; max-age=${r}; samesite=lax${s}`;},Pe=e=>{document.cookie=`${e}=; path=/; max-age=0; samesite=lax`;},L={utm:{}},rn=()=>{var e;return (e=L.id)!=null?e:L.id=ot()},dt=(e,n)=>{if(e!=="cookies")return rn();let r=on(ue);if(r)return L.id=r;let s=rn();return Ye(ue,s,lt),s},ut=e=>{var a;let n=Date.now(),r=L.session,s=(a=e?on(be):void 0)!=null?a:r&&n-r.last<18e5?r.id:ot();return L.session={id:s,last:n},e&&Ye(be,s,18e5/1e3),s},ft=()=>{var r;let e=window.location.href;if(L.url===e)return;L.referrer=(r=L.url)!=null?r:document.referrer||void 0,L.url=e;let n=Nt(window.location.search);Object.keys(n).length&&(L.utm=n);},sn=()=>{let e=navigator,n=window;return e.doNotTrack==="1"||n.doNotTrack==="1"||e.globalPrivacyControl===true};var Xe=window,er=()=>{var e,n;return (n=(e=document.currentScript)!=null?e:document.querySelector('script[data-key][src*="sdk"]'))!=null?n:document.querySelector("script[data-key][src*='mrrocket']")},an=new Set,G=e=>{an.has(e)||(an.add(e),console.warn(`[MRRocket] ${e}`));},tr=()=>{var Ct,Rt,vt,Et;let e=er(),n=o=>{var u;return (u=e==null?void 0:e.getAttribute(`data-${o}`))!=null?u:void 0},r=(o,u)=>{let f=n(o);return f===void 0?u:!["false","0","off","no"].includes(f.trim().toLowerCase())},s=(Ct=e==null?void 0:e.src)!=null?Ct:"",a="";try{a=s?new URL(s,window.location.href).origin:"";}catch(o){a="";}let c=((Rt=n("key"))!=null?Rt:"").trim(),p=((vt=n("api-host"))!=null?vt:a).trim().replace(/\/+$/,""),R=n("consent"),S=r("respect-dnt",false),h=r("heatmaps",true),O=r("errors",true),m=n("release"),k=n("attribution"),E=k==="always"||k==="off"?k:"consent",I=n("referral-param")||"ref",T={},M=(o,u)=>{var f;return (f=T[o])!=null?f:T[o]=new Promise((w,v)=>{var _t;let $=()=>Xe[u];if($())return w($());let q=(_t=n(`${o}-src`))!=null?_t:s?s.replace(/(\.min)?\.js(\?[^#]*)?(#.*)?$/,`-${o}$1.js?v=${Le}`):"";if(!q)return v(new Error(o));let se=document.createElement("script");se.async=true,se.src=q,se.onload=()=>$()?w($()):v(new Error(o)),se.onerror=()=>v(new Error(o)),document.head.appendChild(se);}).catch(w=>{throw T[o]=void 0,w})},K=n("theme"),Q={theme:K==="light"||K==="dark"?K:"auto",accent:n("accent")},N=new URLSearchParams(window.location.search),ee=Lt(N.get(Mt)),V=N.get(At)==="1";V&&Xt();let ae=N.get(Se);if(ae!==null){N.delete(Se);let o=N.toString();history.replaceState(history.state,"",`${window.location.pathname}${o?`?${o}`:""}${window.location.hash}`);}let ze=sn(),pe=R==="cookies"||R==="off"?R:"cookieless",ce=r("replay",false),ge="",H,Y=null,te,P=null,X=false,le=false,de=null,A=null,me=window.location.pathname,ne=[],Ce=new Set,we=[],D=()=>S&&ze?"off":pe,j=()=>!V&&D()!=="off",W=()=>H!=null?H:ge,z=()=>D()==="cookies"?W():H,Z=o=>jt(Y,o);c||G('No public key. Add data-key="mrr_pub_\u2026" to the script tag; nothing is tracked until then.');let Re=(o=false)=>{if(!ne.length)return;if(!c){ne.length=0;return}let u=`${p}/api/sdk/events`;for(let f of Ot(c,ne.splice(0),{v:Le,errors:O,platform:"web"},Z(z())))o&&"sendBeacon"in navigator&&navigator.sendBeacon(u,f)||fetch(u,{method:"POST",headers:{"content-type":"application/json"},body:f,keepalive:true}).then(v=>{v.status===401?xe(401):v.ok||G(`Events were rejected with ${v.status}. Check data-key (MRRocket \u203A Settings \u203A Products).`);}).catch(()=>G(`Could not reach ${p||"this origin"} to send events. Check data-api-host.`));},t=null,i=null,l=(o,u,f=Date.now(),w)=>{if(!j())return;let v=tn(o)?ct():null;ne.push({event:o,props:v?{...u,$referral:{code:v.code,clickId:v.clickId}}:u,distinctId:z(),sessionId:ut(D()==="cookies"),ts:f,url:w!=null?w:window.location.href,referrer:L.referrer,...L.utm,screen:{w:window.screen.width,h:window.screen.height}});},g=(o,u)=>{typeof o!="string"||!o||(l(o,u),j()&&(t==null||t.event(o)),d.onEvent(o));},d=qt(Jt({host:p,apiKey:c,track:l,personId:()=>j()?H:void 0,userHash:Z,canStore:()=>D()==="cookies",auto:r("onboarding",true)})),C=false,_;d.subscribe(()=>{C||!d.view()||V||(C=true,M("flows","__mrrocketFlows").then(o=>o.mountFlows(d,Q)).catch(()=>{C=false,G("The cancel flow and onboarding dialogs did not load. Check that sdk-flows.js is served next to sdk.js.");}));});let y=(o,u)=>{if(!j())return;let f=`${window.location.pathname}|${o}`;Ce.has(f)||(Ce.add(f),g("$exposure",{experiment:o,variant:u}));},b=()=>{let o=Ut(P,window.location.href,W(),ee);return o!=null&&o.to?(Re(true),window.location.replace(o.to),true):(o!=null&&o.experiment&&y(o.experiment,o.variant),false)},x=()=>{if(!P)return;let o=document.querySelectorAll("[data-ck-text]");if(!o.length)return;let u=Tt(P,W(),ee),f=new Set;o.forEach(w=>{var q,se;let v=w.dataset.ckText;if(!v)return;f.add(v),w.dataset.ckDefault===void 0&&(w.dataset.ckDefault=(q=w.textContent)!=null?q:"");let $=(se=u[v])!=null?se:w.dataset.ckDefault;w.textContent!==$&&(w.textContent=$);});for(let w of P.experiments)w.variants.some(v=>{var $;return Object.keys(($=v.changes)!=null?$:{}).some(q=>f.has(q))})&&y(w.key,Oe(w.key,P,W(),ee));},F=()=>{var o,u;return (u=(o=P==null?void 0:P.referral)==null?void 0:o.cookieDays)!=null?u:60},B=()=>E==="always"?D()!=="off":E==="consent"&&D()==="cookies",ve=null,J=false,Je=()=>{if(!X||V)return;if(E==="off"||D()==="off"){Zt(),(E==="off"||J)&&qe();return}let o=window.location.href;ve!==o&&(ve=o,en({search:window.location.search,param:I,store:B(),days:F(),beacon:c?({code:u,clickId:f})=>fetch(`${p}/api/sdk/affiliate/click`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({key:c,code:u,clickId:f,url:o,referrer:document.referrer||void 0}),keepalive:true}).then(w=>w.ok?w.json():null).then(w=>{var v;return (v=w==null?void 0:w.clickId)!=null?v:null}):void 0}));},ln=()=>{let o=B(),u=ct();o&&u?je(u,F()):!o&&J&&qe(),J=o;},pt=0,gt=false,mt=()=>{var w,v;let o=j()&&ce&&!!(P!=null&&P.replay)&&!!c;if(o===gt)return;gt=o;let u=++pt;if(!o){t==null||t.stop(true),t=null;return}let f=(v=(w=P==null?void 0:P.replay)==null?void 0:w.sampleRate)!=null?v:.1;M("replay","__mrrocketReplay").then($=>$.startReplay({host:p,apiKey:c,sessionId:ut(D()==="cookies"),distinctId:z(),identified:!!H,userHash:Z(z()),sampleRate:f,warn:G})).then($=>{u!==pt?$==null||$.stop(true):t=$;}).catch(()=>G("Session recording could not start (the recorder did not load)."));},wt=r("messenger",false),re=null,he=o=>{V||c&&(re!=null||(re=M("messenger","__mrrocketMessenger").then(u=>{var $;let f=q=>n(`messenger-${q}`)===void 0?void 0:r(`messenger-${q}`,true),w=n("messenger-position"),v=($=n("messenger-theme"))!=null?$:K;return u.mountMessenger({host:p,apiKey:c,distinctId:W,user:()=>te,userHash:()=>Z(W()),launcher:wt,position:w,corners:n("messenger-corners"),header:n("messenger-header"),font:n("messenger-font"),title:n("messenger-title"),greeting:n("messenger-greeting"),label:n("messenger-label"),askEmail:f("ask-email"),help:f("help"),sound:f("sound"),preview:f("preview"),theme:v==="light"||v==="dark"||v==="auto"?v:void 0,accent:n("accent")})})),re.then(o).catch(()=>{re=null,G("sdk-messenger.js did not load.");}));},ht=n("forms")==="auto",Ge=false,Qe=()=>{Ge||!c||V||!document.querySelector(ht?"form":"form[data-mrrocket-form]")||(Ge=true,M("forms","__mrrocketForms").then(o=>o.watchForms({host:p,apiKey:c,auto:ht,distinctId:()=>j()?z():void 0,userHash:Z,identified:()=>!!H,identify:xt,tracking:j,referrer:()=>L.referrer,utm:()=>L.utm})).catch(()=>Ge=false));},Ze=()=>{!le||!j()||A===window.location.pathname||(A=window.location.pathname,g("$pageview",{path:window.location.pathname}));},oe=null,kt=()=>{let o=oe;h&&o&&o.max>0&&l("$scroll",{depth:o.max,docH:o.docH,vw:window.innerWidth,vh:window.innerHeight},Date.now(),o.url),oe=null;},Ee=()=>{var v,$;if(!h||!j()||V)return;let o=document.documentElement,u=Math.max(o.scrollHeight,($=(v=document.body)==null?void 0:v.scrollHeight)!=null?$:0),f=$t(),w=window.location.href;(oe==null?void 0:oe.url)!==w?oe={url:w,max:f,docH:u}:f>oe.max&&(oe={url:w,max:f,docH:u});},yt=()=>{let o=window.location.pathname;o!==me&&(me=o,!(X&&b())&&(kt(),ft(),t==null||t.page(o),i==null||i.crumb("navigation",o),Ze(),Je(),window.setTimeout(()=>{Ee(),x(),Qe();},0)));},bt=()=>{let o=D(),u=de;de=o,u==="cookies"&&o!=="cookies"&&(Pe(ue),Pe(be)),o==="off"&&(ne.length=0,L.session=void 0),u==="cookies"&&o!=="cookies"&&zt(),ge=dt(o),ln(),Je(),mt(),Ze(),Ee();},dn=o=>{let{analytics:u,replay:f}=typeof o=="string"?{analytics:o,replay:void 0}:o!=null?o:{};if(u!==void 0&&u!=="cookieless"&&u!=="cookies"&&u!=="off"){G(`setConsent: "${String(u)}" is not a consent mode. Use "cookieless", "cookies" or "off".`);return}u==="off"&&(ne.length=0),u&&(pe=u),typeof f=="boolean"&&(ce=f),bt(),X&&d.refresh();},xt=(o,u,f)=>{if(typeof o!="string"||!o)return;let w=z();Y=Dt(Y,o,f==null?void 0:f.hash),H=o,l("$identify",{...u,id:o,...w&&w!==o?{previousId:w}:{}}),t==null||t.identify(o,Z(o)),D()==="cookies"&&Ye(ue,o,lt),te={...u,id:o},x(),X&&d.refresh();},Me={track:g,identify:xt,reset:()=>{Re(),H=void 0,Y=null,te=void 0,Ce.clear(),D()==="cookies"&&(Pe(ue),Pe(be)),L.id=void 0,L.session=void 0,ge=dt(D()),x(),X&&d.refresh();},captureError:o=>i==null?void 0:i.capture(o,"manual"),setConsent:dn,getFlag:o=>rt(o,P,W(),{...te})!==false,getFlagVariant:o=>{let u=rt(o,P,W(),{...te});return typeof u=="string"?u:null},getVariant:o=>{let u=Oe(o,P,W(),ee);return (P||ee[o])&&y(o,u),u},ready:o=>{typeof o=="function"&&(X?window.setTimeout(()=>o(Me),0):we.push(o));},getDistinctId:W,cancelFlow:{open:o=>d.openCancelFlow(o)},onboarding:{start:o=>d.startOnboarding(o)},openCancelFlow:o=>d.openCancelFlow(o),startOnboarding:o=>d.startOnboarding(o),paywall:{open:(o,u)=>(_!=null?_:_=M("flows","__mrrocketFlows").then(f=>f.paywallHost({config:()=>P,distinctId:W,track:l},Q))).then(f=>f.open(o,u))},push:{subscribe:o=>{let u=j()?H:void 0;if(!u)return Promise.resolve({status:"not-signed-in"});let f=window.Notification,w=Promise.resolve(f&&f.permission==="default"&&(o==null?void 0:o.ask)!==false?f.requestPermission():f==null?void 0:f.permission);return M("push","__mrrocketPush").then(v=>v.subscribeWebPush({host:p,apiKey:c,distinctId:u,userHash:Z(u),permission:w},o))},unsubscribe:()=>M("push","__mrrocketPush").then(o=>o.unsubscribeWebPush({host:p,apiKey:c,distinctId:H,userHash:Z(H)}))},messenger:{open:o=>he(u=>u.open(o)),close:()=>{re==null?void 0:re.then(o=>o.close()).catch(()=>{});},toggle:()=>he(o=>o.toggle())},openMessenger:()=>he(o=>o.open()),version:Le};ft(),bt();let ke=Xe.mrrocket,un=(Et=ke==null?void 0:ke.q)!=null?Et:[],et=ke&&typeof ke=="object"?ke:{};Object.assign(et,Me,{__loaded:true}),delete et.q,Xe.mrrocket=et;for(let[o,u]of un){let f=Me[o];if(typeof f=="function")try{f(...Array.from(u!=null?u:[]));}catch(w){console.error(w);}}le=true,Ze(),O&&c&&!V&&(i=Kt({host:p,apiKey:c,release:m,context:()=>{var o;return {send:j(),distinctId:z(),sessionId:(o=L.session)==null?void 0:o.id,userHash:Z(z())}},warn:G}),i.crumb("navigation",window.location.pathname));for(let o of ["pushState","replaceState"]){let u=history[o];history[o]=function(...f){let w=u.apply(this,f);return yt(),w};}window.addEventListener("popstate",yt);let fn=new _e;document.addEventListener("click",o=>{var $;o.target instanceof Element&&o.target.closest("[data-ck-messenger]")&&(o.preventDefault(),he(q=>q.open()));let u=o.target instanceof Element?o.target.closest("[data-ck-goal]"):null;if(u!=null&&u.dataset.ckGoal&&g(u.dataset.ckGoal,{text:($=u.textContent)==null?void 0:$.trim().slice(0,80)}),!j())return;let f=Ft(o);if(!f)return;let w=fn.push(f.x,f.y,Date.now());if((f.label||f.selector)&&(i==null||i.crumb("click",f.label||f.selector)),t==null||t.click(f,w),!h)return;let v={x:f.x,y:f.y,vw:f.vw,vh:f.vh,docH:f.docH,selector:f.selector,label:f.label,dead:!f.interactive};l("$click",v),w&&l("$rageclick",v);});let tt=0;window.addEventListener("scroll",()=>{tt||(tt=window.requestAnimationFrame(()=>{tt=0,Ee();}));},{passive:true}),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>Ee()):Ee(),window.setInterval(()=>Re(),2e3),window.addEventListener("pagehide",()=>{kt(),Re(true);});let nt=()=>{if(X=true,b())return;let o=Ht(P,ae);o&&y(o.experiment,o.variant),document.documentElement.classList.remove("ck-hide"),Je(),mt(),d.setConfig(P),d.refresh(),wt&&(document.body?he():document.addEventListener("DOMContentLoaded",()=>he())),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{x(),Qe();}):(x(),Qe());for(let u of we.splice(0))try{u(Me);}catch(f){console.error(f);}};c?fetch(`${p}/api/sdk/config?key=${encodeURIComponent(c)}`).then(o=>(o.ok||G(`Config request to ${p||"this origin"} answered ${o.status}. Check data-key and data-api-host.`),o.ok?o.json():null)).then(o=>{o&&Array.isArray(o.experiments)&&(P=o),nt();}).catch(()=>{G(`Could not reach ${p||"this origin"}. Check data-api-host. The page keeps its own texts and flags stay off.`),nt();}):nt();},cn;typeof window!="undefined"&&typeof document!="undefined"&&!((cn=Xe.mrrocket)!=null&&cn.__loaded)&&tr();
1
+ (function(){'use strict';var wn=Object.defineProperty;var hn=(e,n,r)=>n in e?wn(e,n,{enumerable:true,configurable:true,writable:true,value:r}):e[n]=r;var _e=(e,n,r)=>hn(e,typeof n!="symbol"?n+"":n,r);var It=e=>{let n=0;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);s<128?n+=1:s<2048?n+=2:s>=55296&&s<=56319&&r+1<e.length&&(e.charCodeAt(r+1)&64512)===56320?(n+=4,r++):n+=3;}return n},kn=(e,n,r,s)=>{let c=`{"key":${JSON.stringify(e)},${s?`"userHash":${JSON.stringify(s)},`:""}"sdk":${JSON.stringify(r)},"events":[`,l=It(c)+2,g=[],v=[],S=[],b=l,O=()=>{v.length&&g.push({body:`${c}${v.join(",")}]}`,events:S}),v=[],S=[],b=l;};for(let w of n){let C=JSON.stringify(w),_=It(C)+1;l+_>6e4||((v.length===100||b+_>6e4)&&O(),v.push(C),S.push(w),b+=_);}return O(),g},Ft=(e,n,r,s)=>kn(e,n,r,s).map(c=>c.body);var Fe=class{constructor(n=1e3,r=30,s=3){_e(this,"windowMs",n);_e(this,"radius",r);_e(this,"count",s);_e(this,"clicks",[]);_e(this,"fired",false);}push(n,r,s){let c=this.clicks.filter(l=>s-l.t<=this.windowMs&&Math.hypot(l.x-n,l.y-r)<=this.radius);return c.length!==this.clicks.length&&(this.fired=false),this.clicks=[...c,{x:n,y:r,t:s}],this.clicks.length>=this.count&&!this.fired?(this.fired=true,true):false}};var yn='a[href],button,input,select,textarea,label,summary,[role="button"],[role="link"],[role="tab"],[role="menuitem"],[role="checkbox"],[role="switch"],[onclick],[data-ck-goal]',bn="[data-ck-mask]",xn="[data-ck-block]",$t=/\d{4,}|^[a-z]{1,3}-[a-z0-9]{5,}$|^_|__|css-|^sc-|^jsx-/i,Cn=e=>{let n=e.tagName.toLowerCase();if(e.id&&!$t.test(e.id)&&e.id.length<=40)return `${n}#${e.id}`;let r=typeof e.className=="string"?e.className.split(/\s+/).filter(l=>l&&!$t.test(l)&&l.length<=30&&!l.includes(":")):[],s=r.length?`${n}.${r.slice(0,2).join(".")}`:n,c=e.parentElement?[...e.parentElement.children].filter(l=>l.tagName===e.tagName):[];return c.length>1?`${s}:nth-of-type(${c.indexOf(e)+1})`:s},Rn=e=>{let n=[],r=e;for(;r&&n.length<3&&r.tagName&&r.tagName!=="BODY"&&r.tagName!=="HTML";){let s=Cn(r);if(n.unshift(s),s.includes("#"))break;r=r.parentElement;}return n.join(" > ").slice(0,160)},He=e=>(e!=null?e:"").replace(/\s+/g," ").trim().slice(0,40),vn=e=>{var r,s,c,l,g;if(e.closest(`${bn},${xn}`))return "";let n=e.tagName.toLowerCase();if(n==="input"){let v=((r=e.getAttribute("type"))!=null?r:"text").toLowerCase();return He(v==="submit"||v==="button"?(s=e.getAttribute("aria-label"))!=null?s:e.value:e.getAttribute("aria-label"))}return He(n==="select"||n==="textarea"?e.getAttribute("aria-label"):(g=(l=(c=e.getAttribute("aria-label"))!=null?c:e.getAttribute("title"))!=null?l:e.innerText)!=null?g:e.textContent)},Pt=e=>{var l,g;let n=e.target instanceof Element?e.target:null;if(!n)return null;let r=n.closest(yn),s=r!=null?r:n,c=document.documentElement;return {x:Math.round(e.clientX),y:Math.round(e.clientY+window.scrollY),vw:window.innerWidth,vh:window.innerHeight,docH:Math.max(c.scrollHeight,(g=(l=document.body)==null?void 0:l.scrollHeight)!=null?g:0),selector:Rn(s),label:r?vn(r):"",interactive:!!r}},Mt=()=>{var r,s;let e=document.documentElement,n=Math.max(e.scrollHeight,(s=(r=document.body)==null?void 0:r.scrollHeight)!=null?s:0);return n?Math.min(100,Math.round((window.scrollY+window.innerHeight)/n*100)):0};var je="0.17.0",En=(e,n)=>{let r=n.trim().toLowerCase();for(let[s,c]of Object.entries(e))if(s.toLowerCase()===r)return c},_n=(e,n)=>{let r=e.trim().toLowerCase(),s=n.trim().toLowerCase();return s.startsWith("@")?r.endsWith(s):r===s},Sn=(e,n)=>{if(e.op==="in cohort")return false;let r=En(n,e.property),s=r==null?"":String(r);if(e.op==="\u2265"){let l=Number(s),g=Number(e.values[0]);return s!==""&&Number.isFinite(l)&&Number.isFinite(g)&&l>=g}let c=s!==""&&e.values.some(l=>_n(s,l));return e.op==="is"||e.op==="in"?c:!c},On=(e,n,r={})=>{var v;if(!e.on)return false;let s={id:n,...r},c=e.sets.length?e.sets.find(S=>S.conditions.every(b=>Sn(b,s))):{rollout:100};if(!c||At(`${e.key}:rollout:${n}`)*100>=c.rollout)return false;if(!((v=e.variants)!=null&&v.length))return true;let l=At(`${e.key}:variant:${n}`)*100,g=0;for(let S of e.variants)if(g+=S.split,l<g)return S.key;return e.variants[e.variants.length-1].key},it=(e,n,r,s={})=>{var l;let c=(l=n==null?void 0:n.flags)==null?void 0:l.find(g=>g.key===e);return c?On(c,r,s):false},In=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],Nt="ck_preview",Lt="ck_embed",ke="ck_id",Se="ck_sid";var Fn=e=>{var r;let n={};for(let s of In){let c=(r=e(s))==null?void 0:r.trim();c&&(n[s]=c.slice(0,150));}return n},Tt=e=>{let n=new URLSearchParams(e);return Fn(r=>n.get(r))};var $n=e=>{let n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619);return (n>>>0)/4294967296},At=e=>{let n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619);return n^=n>>>16,n=Math.imul(n,2246822507),n^=n>>>13,n=Math.imul(n,3266489909),n^=n>>>16,(n>>>0)/4294967296},Pn=(e,n)=>{var l,g,v,S;let r=(g=(l=e.variants[0])==null?void 0:l.id)!=null?g:"control";if(e.winner)return e.winner;if(e.status!=="running")return r;let s=$n(`${e.key}:${n}`),c=0;for(let b of e.variants)if(c+=b.weight,s<c)return b.id;return (S=(v=e.variants[e.variants.length-1])==null?void 0:v.id)!=null?S:r},Ut=e=>{let n=Array.isArray(e)?e[0]:e;if(!n)return {};let r={};for(let s of n.split(",")){let[c,l]=s.split(":");c&&l&&(r[c.trim()]=l.trim());}return r};var Pe=(e,n,r,s)=>{if(s[e])return s[e];let c=n==null?void 0:n.experiments.find(l=>l.key===e);return c?Pn(c,r):"control"},Ht=(e,n,r)=>{var c,l,g,v,S,b;let s={...(c=e==null?void 0:e.texts)!=null?c:{}};for(let O of (l=e==null?void 0:e.experiments)!=null?l:[]){let w=Pe(O.key,e,n,r);w!==((v=(g=O.variants[0])==null?void 0:g.id)!=null?v:"control")&&Object.assign(s,(b=(S=O.variants.find(C=>C.id===w))==null?void 0:S.changes)!=null?b:{});}return s},$e="ck_x",De=e=>e.replace(/\/+$/,"")||"/",Dt=(e,n,r,s={})=>{var v,S;if(!e)return null;let c;try{c=new URL(n);}catch(b){return null}if(c.searchParams.has($e))return null;let l=De(c.pathname),g=(b,O)=>{let w;try{w=new URL(b,c);}catch(C){return}if(!(!/^https?:$/.test(w.protocol)||w.origin===c.origin&&De(w.pathname)===l))return c.searchParams.forEach((C,_)=>{w.searchParams.has(_)||w.searchParams.set(_,C);}),O&&w.searchParams.set($e,O),w.hash||(w.hash=c.hash),w.href};for(let b of (v=e.redirects)!=null?v:[]){let O=b.from&&De(b.from)===l?g(b.to):void 0;if(O)return {to:O}}for(let b of e.experiments){if(!b.path||De(b.path)!==l)continue;let O=b.status==="running"&&!b.winner;if(O&&r===null&&!s[b.key])return null;let w=Pe(b.key,e,r!=null?r:"",s),C=(S=b.variants.find(F=>F.id===w))==null?void 0:S.url,_=C?g(C,O?`${b.key}:${w}`:void 0):void 0;return O?{to:_,experiment:b.key,variant:w}:_?{to:_}:null}return null},jt=(e,n)=>{let[r,s]=(n!=null?n:"").split(":"),c=e==null?void 0:e.experiments.find(l=>l.key===r);return c&&c.variants.some(l=>l.id===s)?{experiment:r,variant:s}:null};var at=()=>typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID():`ck_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;var Mn="401: sign the user id on your server with userHash(id) from @mrrocket/sdk/next/server and pass identify(id, props, { hash }).",Oe=(e,n=r=>console.warn(r))=>{let r=globalThis;e!==401||r.__mrrocketUnsigned||(r.__mrrocketUnsigned=true,n(`[MRRocket] ${Mn}`));},Wt=(e,n,r,s=c=>console.warn(c))=>{let c=typeof r=="string"?r.trim().toLowerCase():"";return /^[0-9a-f]{64}$/.test(c)?{id:n,hash:c}:(c&&s("[MRRocket] identify: that hash is no userHash(id); not sent."),e&&e.id===n?e:null)},Kt=(e,n)=>e&&n&&e.id===n?e.hash:void 0,Vt=(e,n)=>e&&n.some(r=>r===e.id)&&n.every(r=>!r||r===e.id)?e.hash:void 0;var An=8*1024,Nn=20,Ln=20,Tn=2e3,Me=(e,n)=>e.length>n?`${e.slice(0,n-1)}\u2026`:e,Un=e=>{var n;if(e instanceof Error)return {type:e.name||"Error",message:Me(e.message||String(e),1e3),stack:e.stack?Me(e.stack,An):void 0};if(typeof e=="string")return {type:"Error",message:Me(e,1e3)};try{return {type:"Error",message:Me((n=JSON.stringify(e))!=null?n:String(e),1e3)}}catch(r){return {type:"Error",message:String(e)}}},Bt=e=>{let n=[],r=[],s=new Set,c=0,l=`${e.host}/api/sdk/errors`,g=(C=false)=>{for(;n.length;){let _=n.splice(0,4),F=e.context(),H=F.distinctId&&F.userHash?{id:F.distinctId,hash:F.userHash}:null,A=Vt(H,_.map(M=>M.distinctId)),U=JSON.stringify({key:e.apiKey,...A?{userHash:A}:{},errors:_});C&&typeof navigator!="undefined"&&"sendBeacon"in navigator&&navigator.sendBeacon(l,U)||fetch(l,{method:"POST",headers:{"content-type":"application/json"},body:U,keepalive:true}).then(M=>{M.status===401?Oe(401):!M.ok&&M.status!==429&&e.warn(`Error reports were rejected with ${M.status}. Check the public key and NEXT_PUBLIC_MRROCKET_HOST.`);}).catch(()=>{});}},v=(C,_="manual")=>{let F=e.context();if(!F.send||c>=Nn)return;let H=Un(C);if(/\/api\/sdk\/errors/.test(H.message))return;let A=`${H.type}:${H.message}`;s.has(A)||(s.add(A),c++,n.push({...H,mechanism:_,handled:_==="manual",url:window.location.href,ts:Date.now(),crumbs:r.slice(),...e.release?{release:e.release}:{},...F.distinctId?{distinctId:F.distinctId}:{},...F.sessionId?{sessionId:F.sessionId}:{}}));},S=C=>{var _;!C.error&&(!C.message||C.message==="Script error.")||v((_=C.error)!=null?_:new Error(C.message),"onerror");},b=C=>{var _;return v((_=C.reason)!=null?_:new Error("Unhandled promise rejection"),"onunhandledrejection")},O=()=>g(true);window.addEventListener("error",S),window.addEventListener("unhandledrejection",b),window.addEventListener("pagehide",O);let w=window.setInterval(()=>g(),Tn);return {capture:v,crumb:(C,_)=>{r.push({ts:Date.now(),type:C,message:Me(_,120)}),r.length>Ln&&r.shift();},stop:()=>{window.removeEventListener("error",S),window.removeEventListener("unhandledrejection",b),window.removeEventListener("pagehide",O),window.clearInterval(w),g(true);}}};var Ae="$cancel_flow",se="$onboarding",ct="$inapp";var Hn={version:0,question:"",reasons:[],offers:{},confirm:{title:"Cancel your subscription?",body:"You keep access until the end of the billing period.",button:"Cancel subscription"},offersFor:"business"},Dn="Something went wrong. Please try again.",qt="mrrocket:onboarding",ye=e=>e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),Yt=new Set(["signed_up","signup","sign_up","registered","account_created","user_signed_up"]),lt=(e,n)=>{let r=ye(e),s=ye(n);return !r||!s?false:r===s||Yt.has(r)&&Yt.has(s)},jn=e=>/^(first (launch|visit|open|session|login|sign ?in|app open)|app (opened|launched)|on load|every visit|always)?$/i.test(e.trim());var Wn=e=>e.trim().startsWith("/"),dt=e=>ye(e)==="from_a_checklist";var Kn=()=>`cf_${Math.random().toString(36).slice(2,10)}${Date.now().toString(36)}`;var Xt=e=>{let n=(e!=null?e:"").trim();return /^https?:\/\//i.test(n)||/^\/(?!\/)/.test(n)?n:void 0},ie=e=>{var n;return (n=e.nodes)!=null?n:e.steps},Vn=e=>Math.max(0,e.amount)*(e.unit==="hours"?36e5:864e5),zt=(e,n)=>{let r=e.trim(),s=(n.split(/[?#]/)[0]||"/").replace(/\/+$/,"")||"/";if(!r)return false;if(r.endsWith("*")){let c=r.slice(0,-1).replace(/\/+$/,"");return !c||s===c||s.startsWith(`${c}/`)}return s===(r.replace(/\/+$/,"")||"/")},Ke=e=>e.flatMap(n=>n.kind==="condition"?[...Ke(n.yes),...Ke(n.no)]:n.kind==="wait"?[]:[n]),Bn=(e,n=Date.now())=>e==null||e===""?NaN:Math.floor((n-new Date(e).getTime())/2630016e3),We=e=>e==null?void 0:e.trim().toLowerCase(),qn=({when:e={}},n)=>(e.answer==null||We(e.answer)===We(n.answer))&&(e.plan==null||[e.plan].flat().some(r=>We(r)===We(n.plan)))&&!(n.months>=e.tenureUnder)&&!(n.months<e.tenureOver)&&(e.tenureUnder==null||n.months>=0)&&(e.tenureOver==null||n.months>=0),Jt=e=>{let n=null,r=null,s=null,c=[],l=false,g=null,v,S=null,b=new Map,O=new Set,w=new Set,C=new Set,_=e.auto!==false,F=new Set,H=()=>{var t,i;return (i=(t=e.now)==null?void 0:t.call(e))!=null?i:Date.now()},A=null,U=null,ne=()=>{var t;return (t=n==null?void 0:n.onboarding)!=null?t:[]},M=t=>t?ne().find(i=>i.id===t):void 0,K=t=>{let i=b.get(t);return i||b.set(t,i={done:new Set,dismissed:false,answers:new Map,at:new Map,reached:new Map}),i},X=false,fe=t=>{e.track(se,t),X=true;},pe=(t,i)=>{t.done.add(i),t.at.set(i,H());},Te=t=>{var i,a,p;if((i=t.page)!=null&&i.trim()){let m=(a=e.path)==null?void 0:a.call(e);return m===void 0?false:zt(t.page,m)}if((p=t.event)!=null&&p.trim()){if(!l)return;for(let m of F)if(lt(t.event,m))return true;return false}return false},be=(t,i,a,p,m=0,R)=>{var f,h;for(let k=0;k<i.length;k++){let x=i[k];if(x.kind==="wait"){if(a.done.has(x.id)){R=(f=a.at.get(x.id))!=null?f:R;continue}let I=a.reached.get(x.id);if(I===void 0){if(!p)return {at:"pending"};I=R!=null?R:H(),a.reached.set(x.id,I),fe({flow:t.id,step:x.id,kind:"wait",action:"shown"});}let j=I+Vn(x);if(H()<j)return {at:"wait",until:j};if(!p)return {at:"pending"};pe(a,x.id),fe({flow:t.id,step:x.id,kind:"wait",action:"completed"}),R=j;continue}if(x.kind==="condition"){let I=a.answers.get(x.id);if(I===void 0){if(!p)return {at:"pending"};if(I=Te(x),I===void 0)return {at:"pending"};a.answers.set(x.id,I),fe({flow:t.id,step:x.id,kind:"condition",action:"answered",answer:I?"yes":"no"});}return be(t,I?x.yes:x.no,a,p,m,R)}if(!a.done.has(x.id))return {at:"step",step:x,line:i,index:k,before:m};R=(h=a.at.get(x.id))!=null?h:R,m++;}return {at:"end"}},ae=t=>{let i=b.get(t.id);return !!i&&(i.dismissed||be(t,ie(t),i,false).at==="end")},V=t=>`${qt}:${t!=null?t:"visitor"}`,ge=t=>`${qt}:events:${t!=null?t:"visitor"}`,Y=()=>{var a;X=false;let t=(a=e.storage)==null?void 0:a.call(e);if(!t)return;let i={};for(let[p,m]of b)i[p]={done:[...m.done],...m.dismissed?{dismissed:true}:{},...m.answers.size?{answers:Object.fromEntries([...m.answers].map(([R,f])=>[R,f?"yes":"no"]))}:{},...m.at.size?{at:Object.fromEntries(m.at)}:{},...m.reached.size?{reached:Object.fromEntries(m.reached)}:{}};try{t.set(V(e.personId()),JSON.stringify(i)),F.size&&t.set(ge(e.personId()),JSON.stringify([...F].slice(-200)));}catch(p){}},P=t=>{var i,a,p,m;for(let[R,f]of Object.entries(t!=null?t:{})){let h=K(R);for(let k of (i=f.done)!=null?i:[])h.done.add(k);f.dismissed&&(h.dismissed=true);for(let[k,x]of Object.entries((a=f.answers)!=null?a:{}))h.answers.has(k)||h.answers.set(k,x==="yes");for(let[k,x]of Object.entries((p=f.at)!=null?p:{}))typeof x=="number"&&!h.at.has(k)&&h.at.set(k,x);for(let[k,x]of Object.entries((m=f.reached)!=null?m:{}))typeof x=="number"&&(!h.reached.has(k)||x<h.reached.get(k))&&h.reached.set(k,x);}},re=t=>{var a;A&&clearTimeout(A),A=null;let i=t-H();i>0&&i<=864e5&&(A=setTimeout(()=>(A=null,N()),i+50),(a=A.unref)==null||a.call(A));},me=false,oe=()=>{me=false;let t=M(s);if(!t)return null;let i=K(t.id);if(i.dismissed)return null;let a=be(t,ie(t),i,true);if(X&&Y(),a.at==="wait"&&re(a.until),me=a.at==="wait"||a.at==="pending",a.at!=="step")return null;let{step:p,line:m,index:R}=a,f=I=>!!I&&I.kind!=="wait"&&I.kind!=="condition";if(p.kind==="checklist"){let I=R;for(;I>0&&f(m[I-1])&&m[I-1].kind==="checklist";)I--;let j=R;for(;j+1<m.length&&f(m[j+1])&&m[j+1].kind==="checklist";)j++;let ce=m.slice(I,j+1).filter(f);for(let G of ce)!i.done.has(G.id)&&!w.has(`s:${G.id}`)&&(w.add(`s:${G.id}`),e.track(se,{flow:t.id,step:G.id,kind:"checklist",action:"shown"}));return {type:"checklist",flow:t,items:ce.map(G=>{let Re=G.startsTour&&G.startsTour!==t.id?M(G.startsTour):void 0;return {step:G,done:i.done.has(G.id),...Re&&ie(Re).length?{tour:Re}:{}}})}}w.has(`s:${p.id}`)||(w.add(`s:${p.id}`),e.track(se,{flow:t.id,step:p.id,kind:p.kind,action:"shown"}));let h=m.slice(R+1),k=h.findIndex(I=>I.kind==="condition"),x=(k<0?h:h.slice(0,k)).filter(f).length;return {type:"step",flow:t,step:p,index:a.before,total:a.before+1+x,last:!x&&k<0}},we=()=>{var a,p,m,R;if(r){let f=r,h=(a=f.flow.followUps)==null?void 0:a[f.reason],k=h?1:0,x=f.plain?1:3+k+((p=f.flow.second)!=null&&p[f.reason]?1:0);return {type:"cancel",screen:f.screen,flow:f.flow,reason:f.reason,...f.screen==="followup"&&h?{followUp:h,answer:f.answer}:{},offer:f.screen==="offer"?f.offer:void 0,...f.screen==="offer"?{round:f.round}:{},price:f.options.price,busy:f.busy,error:f.error,step:f.screen==="survey"?1:f.screen==="followup"?2:f.screen==="offer"?1+k+f.round:x,steps:x}}let t=oe();if(t)return t;if(s&&!me){let f=U,h=s;U=null,s=null;let k=f?M(f.flow):void 0;if(f&&k){let x=Ke(ie(k)).find(ce=>ce.id===f.step),I=K(k.id);x&&!x.event&&!((m=b.get(h))!=null&&m.dismissed)&&!I.done.has(x.id)&&(pe(I,x.id),fe({flow:k.id,step:x.id,kind:"checklist",action:"completed"})),s=k.id;let j=oe();if(j)return j;me||(s=null);}else if(l){let x=(R=M(h))==null?void 0:R.trigger;Promise.resolve().then(()=>Ce(x));}}let i=c.find(f=>!O.has(f.id));return i?{type:"message",message:i}:null},N=()=>{let t=we();(t==null?void 0:t.type)==="message"&&!w.has(`m:${t.message.id}`)&&(w.add(`m:${t.message.id}`),e.track(ct,{message:t.message.id,journey:t.message.journey,action:"shown"}));for(let i of [...C])try{i();}catch(a){}},te=t=>s===t.id?true:s&&M(s)&&!ae(M(s))?false:(s=t.id,e.track(se,{flow:t.id,action:"started"}),N(),true),xe=t=>t.audience!=="signed_in"||!!e.personId(),Ce=t=>{var m,R;if(!_||s||!l||!e.personId()&&!((m=e.storage)!=null&&m.call(e)))return;let i=(R=e.path)==null?void 0:R.call(e),a=t&&!dt(t)?ye(t):"",p=ne().find(f=>(Wn(f.trigger)?i!==void 0&&zt(f.trigger,i):jn(f.trigger)||!!a&&ye(f.trigger)===a)&&xe(f)&&ie(f).length&&!ae(f));p&&te(p);},B=()=>{let t=e.personId();S!==null&&S!==t&&(b.clear(),F.clear(),O.clear(),s=null,U=null,v=void 0),S=t;let i=(async()=>{var m,R,f;let a=(m=e.storage)==null?void 0:m.call(e);if(a)try{let h=await a.get(V(t));h&&P(JSON.parse(h));let k=await a.get(ge(t));if(k)for(let x of JSON.parse(k))typeof x=="string"&&F.add(x);}catch(h){}let p=ne().length>0||!!(n!=null&&n.messages);if(t&&p&&v!==t){v=t;let h=await e.fetchInApp(t).catch(()=>null);if(h&&e.personId()===t){P(h.onboarding);for(let k of (R=h.events)!=null?R:[])typeof k=="string"&&F.add(ye(k));c=((f=h.messages)!=null?f:[]).filter(k=>k&&k.id&&k.title);}}t||(c=[]),l=true,Ce(),N();})();return g=i.finally(()=>{g===i&&(g=null);}),g},D=t=>t.round>1?{round:2}:t.rule>=0?{rule:t.rule}:{},q=t=>{var p,m,R,f;let i={answer:t.answer,plan:t.options.plan,months:Bn(t.options.customerSince,(p=e.now)==null?void 0:p.call(e))},a=(R=(m=t.flow.rules)==null?void 0:m[t.reason])!=null?R:[];t.rule=a.findIndex(h=>qn(h,i)),t.offer=t.rule<0?t.flow.offers[t.reason]:(f=a[t.rule].offer)!=null?f:void 0,t.round=1,t.screen=t.offer?"offer":"confirm";},Z=(t,i,a)=>{var m;let p=t.screen==="offer"?t.offer:void 0;return {outcome:i,run:t.run,...t.reason?{reason:t.reason,reasonLabel:(m=t.flow.reasons.find(R=>R.id===t.reason))==null?void 0:m.label}:{},...t.answer?{answer:t.answer}:{},...i==="saved"&&p?{offer:p}:{},...a!=null&&a.trim()?{comment:a.trim().slice(0,500)}:{}}},z=(t,i)=>{var a;e.track(Ae,{action:"finished",run:t.run,version:t.flow.version,outcome:i.outcome,customer:(a=t.options.customer)!=null?a:"consumer",...i.reason?{reason:i.reason}:{},...i.answer?{answer:i.answer}:{},...i.offer?{offer:i.offer.kind,...D(t)}:{},...i.comment?{comment:i.comment}:{}}),r===t&&(r=null),t.resolve(i),N();},he=(t,i,a)=>{if(t.busy)return;let p=Z(t,i,a),m=i==="saved"?t.options.onSave:t.options.onCancel;t.busy=true,t.error=void 0,N(),Promise.resolve().then(()=>m==null?void 0:m(p)).then(()=>z(t,p),()=>{t.busy=false,t.error=Dn,N();});};return {setConfig:t=>{n=t,s&&!M(s)&&(s=null),N();},refresh:B,onEvent:t=>{var f;if(t==="$pageview"&&Ce(),!t||t.startsWith("$"))return;let i=ye(t),a=!!i&&!F.has(i);a&&F.add(i);let p=M(s),m=false;if(p){let h=K(p.id);for(let k of Ke(ie(p)))k.kind==="checklist"&&k.event&&!h.done.has(k.id)&&lt(k.event,t)&&(pe(h,k.id),m=true,e.track(se,{flow:p.id,step:k.id,kind:k.kind,action:"completed"}));}if(m||a&&p?(Y(),N()):a&&Y(),!_||!e.personId()&&!((f=e.storage)!=null&&f.call(e)))return;let R=ne().find(h=>ie(h).length&&!dt(h.trigger)&&lt(h.trigger,t)&&xe(h)&&!ae(h));R&&te(R);},openCancelFlow:(t={})=>{var f,h;if(r)return r.promise;let i=(f=n==null?void 0:n.cancelFlow)!=null?f:Hn,a=t.customer!=="business"||i.reasons.length<2,p=()=>{},m=new Promise(k=>p=k),R={flow:i,options:t,plain:a,screen:a?"confirm":"survey",round:1,run:Kn(),busy:false,resolve:p,promise:m};return r=R,e.track(Ae,{action:"shown",run:R.run,version:i.version,customer:(h=t.customer)!=null?h:"consumer",plain:a}),N(),m},startOnboarding:t=>{let i=t?M(t):ne().find(p=>ie(p).length&&!dt(p.trigger)&&!ae(p));if(!i||!ie(i).length)return false;let a=K(i.id);return a.dismissed=false,te(i)},view:we,subscribe:t=>(C.add(t),()=>C.delete(t)),cancel:{pick:t=>{!r||r.busy||r.screen!=="survey"||!r.flow.reasons.some(i=>i.id===t)||(r.reason!==t&&(r.answer=void 0),r.reason=t,r.error=void 0,N());},answer:t=>{let i=r;if(!i||i.busy||i.screen!=="followup")return;let a=t.slice(0,500);i.answer=a.trim()?a:void 0,N();},next:()=>{var i,a;let t=r;if(!(!t||!t.reason)){if(t.screen==="survey")e.track(Ae,{action:"answered",run:t.run,version:t.flow.version,reason:t.reason}),(i=t.flow.followUps)!=null&&i[t.reason]?t.screen="followup":q(t);else if(t.screen==="followup")t.answer=(a=t.answer)==null?void 0:a.trim(),q(t);else return;N();}},accept:t=>{var a;let i=r;!i||i.screen!=="offer"||!i.reason||(i.busy||e.track(Ae,{action:"offer",run:i.run,version:i.flow.version,reason:i.reason,offer:(a=i.offer)==null?void 0:a.kind,...D(i),outcome:"accepted"}),he(i,"saved",t));},decline:()=>{var a,p;let t=r;if(!t||t.screen!=="offer"||t.busy)return;e.track(Ae,{action:"offer",run:t.run,version:t.flow.version,reason:t.reason,offer:(a=t.offer)==null?void 0:a.kind,...D(t),outcome:"declined"});let i=t.round===1&&t.reason?(p=t.flow.second)==null?void 0:p[t.reason]:void 0;i?(t.offer=i,t.rule=void 0,t.round=2):t.screen="confirm",t.error=void 0,N();},confirm:t=>{let i=r;!i||i.screen!=="confirm"||he(i,"cancelled",t);},close:()=>{var a,p;let t=r;if(!t||t.busy)return;let i=Z(t,"kept");(p=(a=t.options).onClose)==null||p.call(a,i),z(t,i);}},onboarding:{next:()=>{var a;let t=oe();if((t==null?void 0:t.type)!=="step")return;pe(K(t.flow.id),t.step.id),e.track(se,{flow:t.flow.id,step:t.step.id,kind:t.step.kind,action:"completed"}),Y(),N();let i=t.step.kind==="modal"?Xt(t.step.url):void 0;i&&((a=e.openUrl)==null||a.call(e,i));},check:t=>{let i=oe();if((i==null?void 0:i.type)!=="checklist")return;let a=i.items.find(p=>p.step.id===t);!a||a.done||(pe(K(i.flow.id),t),e.track(se,{flow:i.flow.id,step:t,kind:"checklist",action:"completed"}),Y(),N());},dismiss:()=>{let t=oe();!t||t.type!=="step"&&t.type!=="checklist"||(K(t.flow.id).dismissed=true,e.track(se,{flow:t.flow.id,...t.type==="step"?{step:t.step.id}:{},action:"dismissed"}),s=U&&U.flow!==t.flow.id&&M(U.flow)?U.flow:null,U=null,Y(),N());},startTour:t=>{var m;let i=oe();if((i==null?void 0:i.type)!=="checklist")return false;let a=(m=i.items.find(R=>R.step.id===t))==null?void 0:m.tour;if(!a)return false;let p=K(a.id);return p.done.clear(),p.at.clear(),p.dismissed=false,U={flow:i.flow.id,step:t},s=a.id,e.track(se,{flow:a.id,action:"started",from:i.flow.id}),Y(),N(),true}},message:{click:()=>{var a;let t=we();if((t==null?void 0:t.type)!=="message")return;O.add(t.message.id),e.track(ct,{message:t.message.id,journey:t.message.journey,action:"clicked"});let i=Xt(t.message.url);N(),i&&((a=e.openUrl)==null||a.call(e,i));},dismiss:()=>{let t=we();(t==null?void 0:t.type)==="message"&&(O.add(t.message.id),e.track(ct,{message:t.message.id,journey:t.message.journey,action:"dismissed"}),N());}}}};var Yn="ck_pick",Xn="ck_origin",Ve=e=>typeof CSS!="undefined"&&CSS.escape?CSS.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,n=>`\\${n}`),zn=e=>[...e.classList].filter(n=>n.length<30&&!/\d{2,}|[_-][a-z0-9]{5,}$|^(is|has)-|hover|active|focus|open|selected|:|\[/.test(n)).slice(0,2),Gt=e=>{let n=e.ownerDocument,r=g=>{try{return n.querySelectorAll(g).length===1}catch(v){return false}},s=e.getAttribute("data-ck-target");if(s)return `[data-ck-target="${s.replace(/"/g,'\\"')}"]`;if(e.id&&!/\d{3,}/.test(e.id)&&r(`#${Ve(e.id)}`))return `#${Ve(e.id)}`;let c=[],l=e;for(;l&&l!==n.documentElement&&c.length<6;){if(l!==e&&l.id&&!/\d{3,}/.test(l.id)){c.unshift(`#${Ve(l.id)}`);break}let g=l.tagName.toLowerCase(),v=zn(l).map(C=>`.${Ve(C)}`).join(""),S=l.parentElement,b=S?[...S.children].filter(C=>C.tagName===l.tagName):[],O=b.length>1?`:nth-of-type(${b.indexOf(l)+1})`:"";c.unshift(`${g}${v}${O}`);let w=c.join(" > ");if(r(w))return w;l=S;}return c.join(" > ")},Qt=()=>{var O;if(typeof window=="undefined"||window.top===window)return null;let e=new URLSearchParams(window.location.search);if(e.get(Yn)!=="1")return null;let n;try{n=new URL((O=e.get(Xn))!=null?O:"").origin;}catch(w){return null}if(!/^https?:\/\//.test(n))return null;let r=w=>window.parent.postMessage(w,n),s=document.createElement("div");s.setAttribute("aria-hidden","true"),Object.assign(s.style,{position:"fixed",zIndex:"2147483647",pointerEvents:"none",border:"2px solid #0ea5e9",background:"rgba(14,165,233,.12)",borderRadius:"6px",transition:"all 60ms linear",display:"none"});let c=document.createElement("div");Object.assign(c.style,{position:"absolute",left:"-2px",bottom:"calc(100% + 4px)",font:"600 11px/1.4 system-ui, sans-serif",color:"#fff",background:"#0c4a6e",padding:"2px 6px",borderRadius:"4px",whiteSpace:"nowrap",maxWidth:"360px",overflow:"hidden",textOverflow:"ellipsis"}),s.appendChild(c),document.body.appendChild(s);let l=null,g=w=>{if(l=w&&w!==s&&!s.contains(w)?w:null,!l){s.style.display="none";return}let C=l.getBoundingClientRect();Object.assign(s.style,{display:"block",left:`${C.left-2}px`,top:`${C.top-2}px`,width:`${C.width+4}px`,height:`${C.height+4}px`}),c.textContent=Gt(l);},v=w=>g(document.elementFromPoint(w.clientX,w.clientY)),S=w=>{var _,F;w.preventDefault(),w.stopPropagation();let C=(_=document.elementFromPoint(w.clientX,w.clientY))!=null?_:l;!C||C===s||r({type:"mrrocket:picked",selector:Gt(C),text:((F=C.textContent)!=null?F:"").trim().replace(/\s+/g," ").slice(0,80)});},b=w=>{w.key==="Escape"&&r({type:"mrrocket:pick-cancel"});};return window.addEventListener("mousemove",v,true),window.addEventListener("click",S,true),window.addEventListener("keydown",b,true),r({type:"mrrocket:pick-ready"}),()=>{window.removeEventListener("mousemove",v,true),window.removeEventListener("click",S,true),window.removeEventListener("keydown",b,true),s.remove();}};var Jn={get:e=>{try{return window.localStorage.getItem(e)}catch(n){return null}},set:(e,n)=>{try{window.localStorage.setItem(e,n);}catch(r){}}},Zt=()=>{try{for(let e=window.localStorage.length-1;e>=0;e--){let n=window.localStorage.key(e);n!=null&&n.startsWith("mrrocket:onboarding")&&window.localStorage.removeItem(n);}}catch(e){}},en=e=>({track:e.track,personId:e.personId,auto:e.auto,storage:()=>e.canStore()?Jn:null,openUrl:n=>window.location.assign(n),path:()=>window.location.pathname,fetchInApp:async n=>{var c;if(!e.apiKey)return null;let r=(c=e.userHash)==null?void 0:c.call(e,n),s=await fetch(`${e.host}/api/sdk/inapp?key=${encodeURIComponent(e.apiKey)}&distinctId=${encodeURIComponent(n)}${r?`&userHash=${r}`:""}`);return Oe(s.status),s.ok?await s.json():null}});var Ye="mrr_ref",Xe="mrr_ref",Gn="mrr_ref",Qn="mrr_click";var Ne=/^[A-Za-z0-9_-]{1,64}$/;var Zn=(e,n="ref")=>{let r=new URLSearchParams(e);return er(s=>r.get(s),n)},er=(e,n="ref")=>{let r=e(Gn);if(r&&Ne.test(r)){let c=e(Qn);return {code:r,clickId:c&&Ne.test(c)?c:null,direct:false}}let s=e(n);return s&&Ne.test(s)?{code:s,clickId:null,direct:true}:null},tn=e=>{var n;return `${e.code}.${(n=e.clickId)!=null?n:""}.${e.at}`},Be=(e,n=60,r=Date.now())=>{if(!e)return null;let[s,c,l]=e.split("."),g=Number(l);return !s||!Ne.test(s)||!Number.isFinite(g)||c&&!Ne.test(c)||r-g>n*864e5||g>r+864e5?null:{code:s,clickId:c||null,at:g}};var W=null,ze=()=>typeof document!="undefined",nn=e=>{var r;if(!ze())return;let n=(r=document.cookie.split("; ").find(s=>s.startsWith(`${e}=`)))==null?void 0:r.slice(e.length+1);try{return n?decodeURIComponent(n):void 0}catch(s){return n}},Je=()=>{try{return typeof localStorage=="undefined"?null:localStorage}catch(e){return null}},ut=()=>{var e,n;return W||(ze()?(n=Be(nn(Ye),3650))!=null?n:Be((e=Je())==null?void 0:e.getItem(Xe),3650):null)};var qe=(e,n)=>{var c;if(!ze())return;let r=Math.max(1,Math.round(n))*86400,s=typeof location!="undefined"&&location.protocol==="https:"?"; secure":"";document.cookie=`${Ye}=${encodeURIComponent(tn(e))}; path=/; max-age=${r}; samesite=lax${s}`;try{(c=Je())==null||c.setItem(Xe,tn(e));}catch(l){}},Ge=()=>{var e;if(ze()){document.cookie=`${Ye}=; path=/; max-age=0; samesite=lax`;try{(e=Je())==null||e.removeItem(Xe);}catch(n){}}},rn=()=>{W=null;},on=async e=>{var s,c,l;let n=Zn(e.search,e.param),r=(s=e.now)!=null?s:Date.now();if(!n)return !W&&e.store&&(W=(l=Be(nn(Ye),e.days,r))!=null?l:Be((c=Je())==null?void 0:c.getItem(Xe),e.days,r),W||Ge()),W;if(W={code:n.code,clickId:n.clickId,at:r},e.store&&qe(W,e.days),e.beacon)try{let g=await e.beacon({code:n.code,clickId:n.clickId});g&&W&&W.code===n.code&&!W.clickId&&(W={...W,clickId:g},e.store&&qe(W,e.days));}catch(g){}return W},sn=e=>e==="$identify"||!e.startsWith("$");var ft=3600*24*365,ln=e=>{var r;if(typeof document=="undefined")return;let n=(r=document.cookie.split("; ").find(s=>s.startsWith(`${e}=`)))==null?void 0:r.slice(e.length+1);if(n)try{return decodeURIComponent(n)}catch(s){return n}},Qe=(e,n,r)=>{let s=window.location.protocol==="https:"?"; secure":"";document.cookie=`${e}=${encodeURIComponent(n)}; path=/; max-age=${r}; samesite=lax${s}`;},Le=e=>{document.cookie=`${e}=; path=/; max-age=0; samesite=lax`;},L={utm:{}},cn=()=>{var e;return (e=L.id)!=null?e:L.id=at()},pt=(e,n)=>{if(e!=="cookies")return cn();let r=ln(ke);if(r)return L.id=r;let s=cn();return Qe(ke,s,ft),s},gt=e=>{var c;let n=Date.now(),r=L.session,s=(c=e?ln(Se):void 0)!=null?c:r&&n-r.last<18e5?r.id:at();return L.session={id:s,last:n},e&&Qe(Se,s,18e5/1e3),s},mt=()=>{var r;let e=window.location.href;if(L.url===e)return;L.referrer=(r=L.url)!=null?r:document.referrer||void 0,L.url=e;let n=Tt(window.location.search);Object.keys(n).length&&(L.utm=n);},dn=()=>{let e=navigator,n=window;return e.doNotTrack==="1"||n.doNotTrack==="1"||e.globalPrivacyControl===true};var Ze=window,nr=()=>{var e,n;return (n=(e=document.currentScript)!=null?e:document.querySelector('script[data-key][src*="sdk"]'))!=null?n:document.querySelector("script[data-key][src*='mrrocket']")},un=new Set,ee=e=>{un.has(e)||(un.add(e),console.warn(`[MRRocket] ${e}`));},rr=()=>{var vt,Et,_t,St;let e=nr(),n=o=>{var d;return (d=e==null?void 0:e.getAttribute(`data-${o}`))!=null?d:void 0},r=(o,d)=>{let u=n(o);return u===void 0?d:!["false","0","off","no"].includes(u.trim().toLowerCase())},s=(vt=e==null?void 0:e.src)!=null?vt:"",c="";try{c=s?new URL(s,window.location.href).origin:"";}catch(o){c="";}let l=((Et=n("key"))!=null?Et:"").trim(),g=((_t=n("api-host"))!=null?_t:c).trim().replace(/\/+$/,""),v=n("consent"),S=r("respect-dnt",false),b=r("heatmaps",true),O=r("errors",true),w=n("release"),C=n("attribution"),_=C==="always"||C==="off"?C:"consent",F=n("referral-param")||"ref",H={},A=(o,d)=>{var u;return (u=H[o])!=null?u:H[o]=new Promise((y,E)=>{var Ot;let $=()=>Ze[d];if($())return y($());let Q=(Ot=n(`${o}-src`))!=null?Ot:s?s.replace(/(\.min)?\.js(\?[^#]*)?(#.*)?$/,`-${o}$1.js?v=${je}`):"";if(!Q)return E(new Error(o));let ue=document.createElement("script");ue.async=true,ue.src=Q,ue.onload=()=>$()?y($()):E(new Error(o)),ue.onerror=()=>E(new Error(o)),document.head.appendChild(ue);}).catch(y=>{throw H[o]=void 0,y})},U=n("theme"),ne={theme:U==="light"||U==="dark"?U:"auto",accent:n("accent")},M=new URLSearchParams(window.location.search),K=Ut(M.get(Nt)),X=M.get(Lt)==="1";X&&Qt();let fe=M.get($e);if(fe!==null){M.delete($e);let o=M.toString();history.replaceState(history.state,"",`${window.location.pathname}${o?`?${o}`:""}${window.location.hash}`);}let pe=dn(),Te=v==="cookies"||v==="off"?v:"cookieless",be=r("replay",false),ae="",V,ge=null,Y,P=null,re=false,me=false,oe=null,we=null,N=window.location.pathname,te=[],xe=new Set,Ce=[],B=()=>S&&pe?"off":Te,D=()=>!X&&B()!=="off",q=()=>V!=null?V:ae,Z=()=>B()==="cookies"?q():V,z=o=>Kt(ge,o);l||ee('No public key. Add data-key="mrr_pub_\u2026" to the script tag; nothing is tracked until then.');let he=(o=false)=>{if(!te.length)return;if(!l){te.length=0;return}let d=`${g}/api/sdk/events`;for(let u of Ft(l,te.splice(0),{v:je,errors:O,platform:"web"},z(Z())))o&&"sendBeacon"in navigator&&navigator.sendBeacon(d,u)||fetch(d,{method:"POST",headers:{"content-type":"application/json"},body:u,keepalive:true}).then(E=>{E.status===401?Oe(401):E.ok||ee(`Events were rejected with ${E.status}. Check data-key (MRRocket \u203A Settings \u203A Products).`);}).catch(()=>ee(`Could not reach ${g||"this origin"} to send events. Check data-api-host.`));},T=null,J=null,t=(o,d,u=Date.now(),y)=>{if(!D())return;let E=sn(o)?ut():null;te.push({event:o,props:E?{...d,$referral:{code:E.code,clickId:E.clickId}}:d,distinctId:Z(),sessionId:gt(B()==="cookies"),ts:u,url:y!=null?y:window.location.href,referrer:L.referrer,...L.utm,screen:{w:window.screen.width,h:window.screen.height}});},i=(o,d)=>{typeof o!="string"||!o||(t(o,d),D()&&(T==null||T.event(o)),a.onEvent(o));},a=Jt(en({host:g,apiKey:l,track:t,personId:()=>D()?V:void 0,userHash:z,canStore:()=>B()==="cookies",auto:r("onboarding",true)})),p=false,m;a.subscribe(()=>{p||!a.view()||X||(p=true,A("flows","__mrrocketFlows").then(o=>o.mountFlows(a,ne)).catch(()=>{p=false,ee("The cancel flow and onboarding dialogs did not load. Check that sdk-flows.js is served next to sdk.js.");}));});let R=(o,d)=>{if(!D())return;let u=`${window.location.pathname}|${o}`;xe.has(u)||(xe.add(u),i("$exposure",{experiment:o,variant:d}));},f=()=>{let o=Dt(P,window.location.href,q(),K);return o!=null&&o.to?(he(true),window.location.replace(o.to),true):(o!=null&&o.experiment&&R(o.experiment,o.variant),false)},h=()=>{if(!P)return;let o=document.querySelectorAll("[data-ck-text]");if(!o.length)return;let d=Ht(P,q(),K),u=new Set;o.forEach(y=>{var Q,ue;let E=y.dataset.ckText;if(!E)return;u.add(E),y.dataset.ckDefault===void 0&&(y.dataset.ckDefault=(Q=y.textContent)!=null?Q:"");let $=(ue=d[E])!=null?ue:y.dataset.ckDefault;y.textContent!==$&&(y.textContent=$);});for(let y of P.experiments)y.variants.some(E=>{var $;return Object.keys(($=E.changes)!=null?$:{}).some(Q=>u.has(Q))})&&R(y.key,Pe(y.key,P,q(),K));},k=()=>{var o,d;return (d=(o=P==null?void 0:P.referral)==null?void 0:o.cookieDays)!=null?d:60},x=()=>_==="always"?B()!=="off":_==="consent"&&B()==="cookies",I=null,j=false,ce=()=>{if(!re||X)return;if(_==="off"||B()==="off"){rn(),(_==="off"||j)&&Ge();return}let o=window.location.href;I!==o&&(I=o,on({search:window.location.search,param:F,store:x(),days:k(),beacon:l?({code:d,clickId:u})=>fetch(`${g}/api/sdk/affiliate/click`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({key:l,code:d,clickId:u,url:o,referrer:document.referrer||void 0}),keepalive:true}).then(y=>y.ok?y.json():null).then(y=>{var E;return (E=y==null?void 0:y.clickId)!=null?E:null}):void 0}));},G=()=>{let o=x(),d=ut();o&&d?qe(d,k()):!o&&j&&Ge(),j=o;},Re=0,wt=false,ht=()=>{var y,E;let o=D()&&be&&!!(P!=null&&P.replay)&&!!l;if(o===wt)return;wt=o;let d=++Re;if(!o){T==null||T.stop(true),T=null;return}let u=(E=(y=P==null?void 0:P.replay)==null?void 0:y.sampleRate)!=null?E:.1;A("replay","__mrrocketReplay").then($=>$.startReplay({host:g,apiKey:l,sessionId:gt(B()==="cookies"),distinctId:Z(),identified:!!V,userHash:z(Z()),sampleRate:u,warn:ee})).then($=>{d!==Re?$==null||$.stop(true):T=$;}).catch(()=>ee("Session recording could not start (the recorder did not load)."));},kt=r("messenger",false),le=null,ve=o=>{X||l&&(le!=null||(le=A("messenger","__mrrocketMessenger").then(d=>{var $;let u=Q=>n(`messenger-${Q}`)===void 0?void 0:r(`messenger-${Q}`,true),y=n("messenger-position"),E=($=n("messenger-theme"))!=null?$:U;return d.mountMessenger({host:g,apiKey:l,distinctId:q,user:()=>Y,userHash:()=>z(q()),launcher:kt,position:y,corners:n("messenger-corners"),header:n("messenger-header"),font:n("messenger-font"),title:n("messenger-title"),greeting:n("messenger-greeting"),label:n("messenger-label"),askEmail:u("ask-email"),help:u("help"),sound:u("sound"),preview:u("preview"),theme:E==="light"||E==="dark"||E==="auto"?E:void 0,accent:n("accent")})})),le.then(o).catch(()=>{le=null,ee("sdk-messenger.js did not load.");}));},yt=n("forms")==="auto",et=false,tt=()=>{et||!l||X||!document.querySelector(yt?"form":"form[data-mrrocket-form]")||(et=true,A("forms","__mrrocketForms").then(o=>o.watchForms({host:g,apiKey:l,auto:yt,distinctId:()=>D()?Z():void 0,userHash:z,identified:()=>!!V,identify:Rt,tracking:D,referrer:()=>L.referrer,utm:()=>L.utm})).catch(()=>et=false));},nt=()=>{!me||!D()||we===window.location.pathname||(we=window.location.pathname,i("$pageview",{path:window.location.pathname}));},de=null,bt=()=>{let o=de;b&&o&&o.max>0&&t("$scroll",{depth:o.max,docH:o.docH,vw:window.innerWidth,vh:window.innerHeight},Date.now(),o.url),de=null;},Ie=()=>{var E,$;if(!b||!D()||X)return;let o=document.documentElement,d=Math.max(o.scrollHeight,($=(E=document.body)==null?void 0:E.scrollHeight)!=null?$:0),u=Mt(),y=window.location.href;(de==null?void 0:de.url)!==y?de={url:y,max:u,docH:d}:u>de.max&&(de={url:y,max:u,docH:d});},xt=()=>{let o=window.location.pathname;o!==N&&(N=o,!(re&&f())&&(bt(),mt(),T==null||T.page(o),J==null||J.crumb("navigation",o),nt(),ce(),window.setTimeout(()=>{Ie(),h(),tt();},0)));},Ct=()=>{let o=B(),d=oe;oe=o,d==="cookies"&&o!=="cookies"&&(Le(ke),Le(Se)),o==="off"&&(te.length=0,L.session=void 0),d==="cookies"&&o!=="cookies"&&Zt(),ae=pt(o),G(),ce(),ht(),nt(),Ie();},pn=o=>{let{analytics:d,replay:u}=typeof o=="string"?{analytics:o,replay:void 0}:o!=null?o:{};if(d!==void 0&&d!=="cookieless"&&d!=="cookies"&&d!=="off"){ee(`setConsent: "${String(d)}" is not a consent mode. Use "cookieless", "cookies" or "off".`);return}d==="off"&&(te.length=0),d&&(Te=d),typeof u=="boolean"&&(be=u),Ct(),re&&a.refresh();},Rt=(o,d,u)=>{if(typeof o!="string"||!o)return;let y=Z();ge=Wt(ge,o,u==null?void 0:u.hash),V=o,t("$identify",{...d,id:o,...y&&y!==o?{previousId:y}:{}}),T==null||T.identify(o,z(o)),B()==="cookies"&&Qe(ke,o,ft),Y={...d,id:o},h(),re&&a.refresh();},Ue={track:i,identify:Rt,reset:()=>{he(),V=void 0,ge=null,Y=void 0,xe.clear(),B()==="cookies"&&(Le(ke),Le(Se)),L.id=void 0,L.session=void 0,ae=pt(B()),h(),re&&a.refresh();},captureError:o=>J==null?void 0:J.capture(o,"manual"),setConsent:pn,getFlag:o=>it(o,P,q(),{...Y})!==false,getFlagVariant:o=>{let d=it(o,P,q(),{...Y});return typeof d=="string"?d:null},getVariant:o=>{let d=Pe(o,P,q(),K);return (P||K[o])&&R(o,d),d},ready:o=>{typeof o=="function"&&(re?window.setTimeout(()=>o(Ue),0):Ce.push(o));},getDistinctId:q,cancelFlow:{open:o=>a.openCancelFlow(o)},onboarding:{start:o=>a.startOnboarding(o)},openCancelFlow:o=>a.openCancelFlow(o),startOnboarding:o=>a.startOnboarding(o),paywall:{open:(o,d)=>(m!=null?m:m=A("flows","__mrrocketFlows").then(u=>u.paywallHost({config:()=>P,distinctId:q,track:t},ne))).then(u=>u.open(o,d))},push:{subscribe:o=>{let d=D()?V:void 0;if(!d)return Promise.resolve({status:"not-signed-in"});let u=window.Notification,y=Promise.resolve(u&&u.permission==="default"&&(o==null?void 0:o.ask)!==false?u.requestPermission():u==null?void 0:u.permission);return A("push","__mrrocketPush").then(E=>E.subscribeWebPush({host:g,apiKey:l,distinctId:d,userHash:z(d),permission:y},o))},unsubscribe:()=>A("push","__mrrocketPush").then(o=>o.unsubscribeWebPush({host:g,apiKey:l,distinctId:V,userHash:z(V)}))},messenger:{open:o=>ve(d=>d.open(o)),close:()=>{le==null?void 0:le.then(o=>o.close()).catch(()=>{});},toggle:()=>ve(o=>o.toggle())},openMessenger:()=>ve(o=>o.open()),version:je};mt(),Ct();let Ee=Ze.mrrocket,gn=(St=Ee==null?void 0:Ee.q)!=null?St:[],rt=Ee&&typeof Ee=="object"?Ee:{};Object.assign(rt,Ue,{__loaded:true}),delete rt.q,Ze.mrrocket=rt;for(let[o,d]of gn){let u=Ue[o];if(typeof u=="function")try{u(...Array.from(d!=null?d:[]));}catch(y){console.error(y);}}me=true,nt(),O&&l&&!X&&(J=Bt({host:g,apiKey:l,release:w,context:()=>{var o;return {send:D(),distinctId:Z(),sessionId:(o=L.session)==null?void 0:o.id,userHash:z(Z())}},warn:ee}),J.crumb("navigation",window.location.pathname));for(let o of ["pushState","replaceState"]){let d=history[o];history[o]=function(...u){let y=d.apply(this,u);return xt(),y};}window.addEventListener("popstate",xt);let mn=new Fe;document.addEventListener("click",o=>{var $;o.target instanceof Element&&o.target.closest("[data-ck-messenger]")&&(o.preventDefault(),ve(Q=>Q.open()));let d=o.target instanceof Element?o.target.closest("[data-ck-goal]"):null;if(d!=null&&d.dataset.ckGoal&&i(d.dataset.ckGoal,{text:($=d.textContent)==null?void 0:$.trim().slice(0,80)}),!D())return;let u=Pt(o);if(!u)return;let y=mn.push(u.x,u.y,Date.now());if((u.label||u.selector)&&(J==null||J.crumb("click",u.label||u.selector)),T==null||T.click(u,y),!b)return;let E={x:u.x,y:u.y,vw:u.vw,vh:u.vh,docH:u.docH,selector:u.selector,label:u.label,dead:!u.interactive};t("$click",E),y&&t("$rageclick",E);});let ot=0;window.addEventListener("scroll",()=>{ot||(ot=window.requestAnimationFrame(()=>{ot=0,Ie();}));},{passive:true}),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>Ie()):Ie(),window.setInterval(()=>he(),2e3),window.addEventListener("pagehide",()=>{bt(),he(true);});let st=()=>{if(re=true,f())return;let o=jt(P,fe);o&&R(o.experiment,o.variant),document.documentElement.classList.remove("ck-hide"),ce(),ht(),a.setConfig(P),a.refresh(),kt&&(document.body?ve():document.addEventListener("DOMContentLoaded",()=>ve())),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{h(),tt();}):(h(),tt());for(let d of Ce.splice(0))try{d(Ue);}catch(u){console.error(u);}};l?fetch(`${g}/api/sdk/config?key=${encodeURIComponent(l)}`).then(o=>(o.ok||ee(`Config request to ${g||"this origin"} answered ${o.status}. Check data-key and data-api-host.`),o.ok?o.json():null)).then(o=>{o&&Array.isArray(o.experiments)&&(P=o),st();}).catch(()=>{ee(`Could not reach ${g||"this origin"}. Check data-api-host. The page keeps its own texts and flags stay off.`),st();}):st();},fn;typeof window!="undefined"&&typeof document!="undefined"&&!((fn=Ze.mrrocket)!=null&&fn.__loaded)&&rr();
2
2
  })();
package/dist/core.d.ts CHANGED
@@ -6,7 +6,7 @@ import type { CancelFlowConfig, OnboardingFlow } from "./flows.js";
6
6
  import type { PaywallConfig } from "./paywall.js";
7
7
  export type VariantId = string;
8
8
  /** This build of the SDK. Sent with the config request so MRRocket knows what the site runs (error tracking, flags). */
9
- export declare const SDK_VERSION = "0.16.0";
9
+ export declare const SDK_VERSION = "0.17.0";
10
10
  /** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */
11
11
  export interface VariantConfig {
12
12
  id: VariantId;
package/dist/core.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/core.ts
2
- var SDK_VERSION = "0.16.0";
2
+ var SDK_VERSION = "0.17.0";
3
3
  var propOf = (person, name) => {
4
4
  const want = name.trim().toLowerCase();
5
5
  for (const [k, v] of Object.entries(person)) if (k.toLowerCase() === want) return v;
package/dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core.ts"],"sourcesContent":["/**\n * The part of the SDK that runs anywhere: experiment config, variant assignment, preview links and event shapes.\n * No React, no browser APIs, so the server helper, the proxy helper and the client share it.\n */\nimport type { CancelFlowConfig, OnboardingFlow } from \"./flows\";\nimport type { PaywallConfig } from \"./paywall\";\n\nexport type VariantId = string;\n\n/** This build of the SDK. Sent with the config request so MRRocket knows what the site runs (error tracking, flags). */\nexport const SDK_VERSION = \"0.16.0\";\n\n/** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */\nexport interface VariantConfig {\n id: VariantId;\n /** Share of traffic, 0 to 1. The weights of an experiment add up to 1. */\n weight: number;\n changes?: Record<string, string>;\n /**\n * A redirect test: where this variant sends the visitor instead of the test's page (a path like \"/pricing-b\" or a\n * full address). Control has none and stays. SDK 0.7.0+.\n */\n url?: string;\n}\n\nexport interface ExperimentConfig {\n /** The experiment's key, the same as in Cockpit. */\n key: string;\n status: \"running\" | \"draft\" | \"stopped\";\n /** Control first. */\n variants: VariantConfig[];\n /** A winner that shipped: everyone gets it, and nobody is assigned anymore. */\n winner?: VariantId;\n /** A redirect test: the path of the page it runs on (\"/pricing\"). Visitors there are sent to their variant's `url`. */\n path?: string;\n}\n\n/** A page redirect set in MRRocket (Conversion › Landing pages › Redirect): everyone on `from` goes to `to`. SDK 0.7.0+. */\nexport interface RedirectConfig {\n /** A path of the site, like \"/old-pricing\". */\n from: string;\n /** A path or a full address. */\n to: string;\n}\n\nexport interface CockpitConfig {\n /** The product the public key belongs to. */\n project: string;\n experiments: ExperimentConfig[];\n /** The product's affiliate program: how many days a partner's referral is kept. Missing without a program. */\n referral?: { cookieDays: number };\n /** Session recordings: present only while the product records (Cockpit › Sessions). See `ReplayConfig`. */\n replay?: ReplayConfig;\n /** Feature flags of the product in Production (MRRocket › Build › Feature flags), evaluated by `useFlag` and `getFlag`. */\n flags?: FlagConfig[];\n /**\n * Published copy for texts the site marks (`<Text id>`, `data-ck-text`): a landing page's headline, subheadline and\n * button (`pricing.headline` …) and a paywall's (`paywall.<placement>.headline` …) as published in MRRocket. A\n * running test's variant changes them on top. Missing when nothing is published. SDK 0.5.0+.\n */\n texts?: Record<string, string>;\n /** The product's live cancel flow (MRRocket › Churn › Cancel flow), for `cancelFlow.open()`. SDK 0.7.0+. */\n cancelFlow?: CancelFlowConfig;\n /** The in-app steps of live onboarding flows (tours, checklists, modals). SDK 0.7.0+. */\n onboarding?: OnboardingFlow[];\n /** A live Lifecycle journey has in-app messages: signed-in people ask `/api/sdk/inapp` for theirs. SDK 0.7.0+. */\n messages?: boolean;\n /** Page redirects set in MRRocket; the SDK sends visitors on before the page shows (`redirectFor`). SDK 0.7.0+. */\n redirects?: RedirectConfig[];\n /** Published paywalls with their pages, per placement (MRRocket › Conversion › Paywalls), for `paywall.open()`. SDK 0.14.0+. */\n paywalls?: PaywallConfig[];\n}\n\n/** One condition of a flag's audience, on a property of the person (`identify(id, props)`), the id or the page. */\nexport interface FlagCondition {\n /** \"Email\", \"Plan\", \"Country\", \"id\", \"path\" … Matched against the person's properties without regard to case. */\n property: string;\n op: \"is\" | \"is not\" | \"in\" | \"not in\" | \"≥\" | \"in cohort\";\n values: string[];\n}\n\n/** Users who match every condition, of whom `rollout` percent get the flag. No conditions: everyone. */\nexport interface FlagConditionSet {\n conditions: FlagCondition[];\n /** 0 to 100. */\n rollout: number;\n}\n\nexport interface FlagConfig {\n key: string;\n /** Off: everyone gets the off side. */\n on: boolean;\n /** The first set a person matches decides; none matched: off. */\n sets: FlagConditionSet[];\n /** Multivariate flags: the variants and their split in percent (control included). Missing for an on/off flag. */\n variants?: { key: string; split: number; payload?: string }[];\n}\n\n/** What a person is for flag conditions: their properties from identify(), their id and the page they are on. */\nexport type FlagPerson = Record<string, unknown>;\n\nconst propOf = (person: FlagPerson, name: string) => {\n const want = name.trim().toLowerCase();\n for (const [k, v] of Object.entries(person)) if (k.toLowerCase() === want) return v;\n return undefined;\n};\n\n/** `\"@acme.com\"` matches every address at that domain; anything else matches the whole value, without regard to case. */\nconst same = (actual: string, value: string) => {\n const a = actual.trim().toLowerCase();\n const v = value.trim().toLowerCase();\n return v.startsWith(\"@\") ? a.endsWith(v) : a === v;\n};\n\nconst matchesCondition = (c: FlagCondition, person: FlagPerson) => {\n // Cohorts live in MRRocket; a browser cannot know them, so a cohort condition never matches here.\n if (c.op === \"in cohort\") return false;\n const raw = propOf(person, c.property);\n const actual = raw === undefined || raw === null ? \"\" : String(raw);\n if (c.op === \"≥\") {\n const a = Number(actual);\n const b = Number(c.values[0]);\n return actual !== \"\" && Number.isFinite(a) && Number.isFinite(b) && a >= b;\n }\n const hit = actual !== \"\" && c.values.some((v) => same(actual, v));\n return c.op === \"is\" || c.op === \"in\" ? hit : !hit;\n};\n\n/**\n * The flag for one person: `false` (off), `true` (on, an on/off flag) or the variant's key (a multivariate flag). The\n * bucket is a stable hash of flag and person, so a person keeps their side as the rollout grows.\n */\nexport const evaluateFlag = (flag: FlagConfig, distinctId: string, person: FlagPerson = {}): boolean | string => {\n if (!flag.on) return false;\n const subject = { id: distinctId, ...person };\n const set = flag.sets.length ? flag.sets.find((s) => s.conditions.every((c) => matchesCondition(c, subject))) : { conditions: [], rollout: 100 };\n if (!set) return false;\n if (flagUnit(`${flag.key}:rollout:${distinctId}`) * 100 >= set.rollout) return false;\n if (!flag.variants?.length) return true;\n const u = flagUnit(`${flag.key}:variant:${distinctId}`) * 100;\n let acc = 0;\n for (const v of flag.variants) {\n acc += v.split;\n if (u < acc) return v.key;\n }\n return flag.variants[flag.variants.length - 1].key;\n};\n\n/** A flag of the config for this person; an unknown flag (or no config) is off. */\nexport const flagFor = (key: string, config: CockpitConfig | null, distinctId: string, person: FlagPerson = {}) => {\n const flag = config?.flags?.find((f) => f.key === key);\n return flag ? evaluateFlag(flag, distinctId, person) : false;\n};\n\n/** One JavaScript error as it goes over the wire to `POST /api/sdk/errors`. */\nexport interface ErrorReport {\n /** \"TypeError\", \"Error\" … */\n type: string;\n message: string;\n /** The raw stack, at most 8 KB. MRRocket parses it into frames. */\n stack?: string;\n /** \"onerror\" (uncaught), \"onunhandledrejection\" (a rejected promise nobody caught) or \"manual\" (captureError). */\n mechanism: \"onerror\" | \"onunhandledrejection\" | \"manual\";\n handled: boolean;\n url: string;\n ts: number;\n /** What happened just before: pages and clicks, newest last, at most 20. */\n crumbs?: { ts: number; type: \"navigation\" | \"click\" | \"lifecycle\"; message: string }[];\n /** Your release (a version or commit), from the provider's `release` prop. */\n release?: string;\n distinctId?: string;\n sessionId?: string;\n}\n\n/**\n * Session recordings of a product, from the config. Recording also needs the visitor's own replay consent\n * (`<CockpitProvider replay>` or `setConsent({ replay: true })`); without it nothing is recorded or buffered.\n */\nexport interface ReplayConfig {\n /**\n * Share of sessions uploaded from their start, 0 to 1 (default 0.1). The others keep only the last minute in\n * memory and upload it when something goes wrong: a JS error, a rage click, a `purchase…` or `checkout…` event.\n */\n sampleRate: number;\n}\n\n/**\n * What the SDK may send and store.\n * - \"cookieless\" (default): no cookie, no localStorage. Events go without a visitor id; the server counts visitors\n * with a hash of key, date, IP and user agent that changes every day.\n * - \"cookies\": a persistent `ck_id` cookie identifies the visitor across visits, `ck_sid` holds the session.\n * - \"off\": nothing is sent and nothing is stored.\n */\nexport type ConsentMode = \"cookieless\" | \"cookies\" | \"off\";\n\n/**\n * What `setConsent` takes: a mode as before, or the parts to change. `replay` is the separate consent for session\n * recordings (default false); it applies only while analytics is not \"off\".\n *\n * setConsent(\"cookies\");\n * setConsent({ replay: true });\n * setConsent({ analytics: \"cookieless\", replay: false });\n */\nexport type ConsentChoice = ConsentMode | { analytics?: ConsentMode; replay?: boolean };\n\n/** The campaign parameters the SDK reads from the landing URL. */\nexport const UTM_KEYS = [\"utm_source\", \"utm_medium\", \"utm_campaign\", \"utm_term\", \"utm_content\"] as const;\nexport type UtmKey = (typeof UTM_KEYS)[number];\n\n/** One event as it goes over the wire to `POST /api/sdk/events`. */\nexport interface CockpitEvent {\n event: string;\n /** The visitor. Missing in \"cookieless\" mode until identify(): the server then uses its daily visitor hash. */\n distinctId?: string;\n /** Ends after 30 minutes without an event. */\n sessionId?: string;\n props?: Record<string, unknown>;\n /** Milliseconds since the epoch. */\n ts: number;\n url?: string;\n /** `document.referrer` on the first page of a page load, the previous in-app URL after client-side navigation. */\n referrer?: string;\n utm_source?: string;\n utm_medium?: string;\n utm_campaign?: string;\n utm_term?: string;\n utm_content?: string;\n /** The screen size in CSS pixels (points on a phone). */\n screen?: { w: number; h: number };\n /** The app that sent it (React Native only): MRRocket stores it with the event and fills OS and device from it. */\n app?: AppContext;\n}\n\n/** Where a React Native event comes from. Every field is optional except the platform; nothing identifies the person. */\nexport interface AppContext {\n /** \"ios\" or \"android\" (React Native's `Platform.OS`). */\n platform: string;\n /** The app's version, like \"1.4.0\" (`expo-application`'s `nativeApplicationVersion`). */\n appVersion?: string;\n /** The build number, like \"42\". */\n build?: string;\n /** The OS version, like \"17.4\". */\n osVersion?: string;\n /** The device model, like \"iPhone 15 Pro\" (`expo-device`). */\n deviceModel?: string;\n /** \"phone\", \"tablet\", \"desktop\" or \"tv\" when `expo-device` knows it. */\n deviceType?: string;\n /** The first preferred locale, like \"de-DE\". */\n locale?: string;\n}\n\n/** The query parameter that forces variants, for previews in Cockpit: `?ck_preview=pricing-annual:a,home-hero:control`. */\nexport const PREVIEW_PARAM = \"ck_preview\";\n/** Set when Cockpit embeds the page: nothing is tracked, so previews never count as visits. */\nexport const EMBED_PARAM = \"ck_embed\";\n/** The cookie that keeps a visitor in the same variant across visits. Only written in \"cookies\" mode. */\nexport const ID_COOKIE = \"ck_id\";\n/** The cookie that holds the session id in \"cookies\" mode. */\nexport const SESSION_COOKIE = \"ck_sid\";\n/** A session ends after this long without an event. */\nexport const SESSION_TIMEOUT_MS = 30 * 60 * 1000;\n\n/** The UTM parameters from a parameter lookup (`URLSearchParams.get` in a browser). Empty values are left out. */\nexport const utmFrom = (get: (name: string) => string | null | undefined): Partial<Record<UtmKey, string>> => {\n const out: Partial<Record<UtmKey, string>> = {};\n for (const key of UTM_KEYS) {\n const value = get(key)?.trim();\n if (value) out[key] = value.slice(0, 150);\n }\n return out;\n};\n\n/** The UTM parameters of a query string, like `\"?utm_source=x\"`. Empty values are left out. */\nexport const readUtm = (search: string): Partial<Record<UtmKey, string>> => {\n const params = new URLSearchParams(search);\n return utmFrom((k) => params.get(k));\n};\n\n/**\n * The query parameters of a URL or query string, without `URLSearchParams` (React Native's is incomplete): `+` is a\n * space, values are percent-decoded, the first of a repeated name wins.\n */\nexport const parseQuery = (url: string): Record<string, string> => {\n const out: Record<string, string> = {};\n const q = url.split(\"#\")[0];\n const at = q.indexOf(\"?\");\n if (at < 0) return out;\n const dec = (s: string) => {\n try {\n return decodeURIComponent(s.replace(/\\+/g, \" \"));\n } catch {\n return s;\n }\n };\n for (const pair of q.slice(at + 1).split(\"&\")) {\n if (!pair) continue;\n const eq = pair.indexOf(\"=\");\n const k = dec(eq < 0 ? pair : pair.slice(0, eq));\n if (k && !(k in out)) out[k] = eq < 0 ? \"\" : dec(pair.slice(eq + 1));\n }\n return out;\n};\n\n/** FNV-1a, 32 bit, mapped to [0, 1). Stable across server and browser. */\nexport const hashUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0) / 4294967296;\n};\n\n/**\n * FNV-1a with murmur3's finalizer, mapped to [0, 1): ids that differ only at the end (\"user-1\", \"user-2\") still spread\n * evenly, so a 30 % rollout reaches about 30 % of people. Flags only; experiments keep `hashUnit` so nobody switches.\n */\nexport const flagUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n h ^= h >>> 16;\n h = Math.imul(h, 0x85ebca6b);\n h ^= h >>> 13;\n h = Math.imul(h, 0xc2b2ae35);\n h ^= h >>> 16;\n return (h >>> 0) / 4294967296;\n};\n\n/** The variant a visitor sees: a shipped winner, control while the experiment does not run, else a stable bucket by visitor. */\nexport const assign = (experiment: ExperimentConfig, distinctId: string): VariantId => {\n const control = experiment.variants[0]?.id ?? \"control\";\n if (experiment.winner) return experiment.winner;\n if (experiment.status !== \"running\") return control;\n const u = hashUnit(`${experiment.key}:${distinctId}`);\n let acc = 0;\n for (const v of experiment.variants) {\n acc += v.weight;\n if (u < acc) return v.id;\n }\n return experiment.variants[experiment.variants.length - 1]?.id ?? control;\n};\n\n/** `\"a:b,c:d\"` → `{ a: \"b\", c: \"d\" }`. Ignores anything malformed. */\nexport const parsePreview = (value: string | string[] | null | undefined): Record<string, VariantId> => {\n const raw = Array.isArray(value) ? value[0] : value;\n if (!raw) return {};\n const out: Record<string, VariantId> = {};\n for (const pair of raw.split(\",\")) {\n const [key, variant] = pair.split(\":\");\n if (key && variant) out[key.trim()] = variant.trim();\n }\n return out;\n};\n\n/** A link that shows one variant of a page, for example in Cockpit's preview frames. */\nexport const previewHref = (url: string, forced: Record<string, VariantId>, embed = true) => {\n const [path, query = \"\"] = url.split(\"?\");\n const params = new URLSearchParams(query);\n const value = Object.entries(forced)\n .map(([k, v]) => `${k}:${v}`)\n .join(\",\");\n if (value) params.set(PREVIEW_PARAM, value);\n if (embed) params.set(EMBED_PARAM, \"1\");\n return `${path}?${params.toString()}`;\n};\n\n/** The variant for one experiment, from a forced preview first, then the config. Unknown experiments get control. */\n/** The experiments whose variants change the text `id`: showing that text is an exposure to them. */\nexport const experimentsOfText = (config: CockpitConfig | null, id: string) =>\n (config?.experiments ?? []).filter((e) => e.variants.some((v) => v.changes && id in v.changes)).map((e) => e.key);\n\nexport const resolveVariant = (key: string, config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>): VariantId => {\n if (preview[key]) return preview[key];\n const experiment = config?.experiments.find((e) => e.key === key);\n return experiment ? assign(experiment, distinctId) : \"control\";\n};\n\n/**\n * Every text change that applies to this visitor: the published texts first, then each experiment's in config order.\n * Control keeps the published (or the page's own) words, so only a non-control variant (assigned, forced in a preview,\n * or a shipped winner) changes them further.\n */\nexport const textChanges = (config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>) => {\n const out: Record<string, string> = { ...(config?.texts ?? {}) };\n for (const experiment of config?.experiments ?? []) {\n const id = resolveVariant(experiment.key, config, distinctId, preview);\n if (id === (experiment.variants[0]?.id ?? \"control\")) continue;\n Object.assign(out, experiment.variants.find((v) => v.id === id)?.changes ?? {});\n }\n return out;\n};\n\n/**\n * The query parameter a redirect test adds to the variant's address (`ck_x=<test>:<variant>`): the page there records\n * the exposure and takes it out of the address bar. It also keeps that page from redirecting again.\n */\nexport const EXPOSURE_PARAM = \"ck_x\";\n\n/** What `redirectFor` decided: go to `to`, and/or the redirect test this page belongs to and the visitor's variant. */\nexport interface RedirectDecision {\n /** Where to send the visitor now. Missing for control, which stays on the page. */\n to?: string;\n /** The redirect test, while it runs: record `$exposure` for it (on this page for control, on `to` otherwise). */\n experiment?: string;\n variant?: VariantId;\n}\n\nconst pathOf = (p: string) => p.replace(/\\/+$/, \"\") || \"/\";\n\n/**\n * Where a page sends the visitor, before it shows: a page redirect set in MRRocket first, else a redirect test that runs\n * on this path (the visitor's variant, by the same stable assignment as every test). Null when nothing applies.\n *\n * - The new address keeps the page's query (UTM parameters) and its hash; a running test adds `ck_x=<test>:<variant>`,\n * so the page it lands on records the exposure (and never redirects again).\n * - `distinctId` null (no stable id, as on a server without the `ck_id` cookie): running tests are left to the browser,\n * page redirects and shipped winners still apply.\n * - A redirect to the page itself is ignored.\n */\nexport const redirectFor = (config: CockpitConfig | null, href: string, distinctId: string | null, preview: Record<string, VariantId> = {}): RedirectDecision | null => {\n if (!config) return null;\n let here: URL;\n try {\n here = new URL(href);\n } catch {\n return null;\n }\n if (here.searchParams.has(EXPOSURE_PARAM)) return null;\n const path = pathOf(here.pathname);\n const go = (to: string, mark?: string) => {\n let t: URL;\n try {\n t = new URL(to, here);\n } catch {\n return undefined;\n }\n if (!/^https?:$/.test(t.protocol) || (t.origin === here.origin && pathOf(t.pathname) === path)) return undefined;\n here.searchParams.forEach((v, k) => {\n if (!t.searchParams.has(k)) t.searchParams.set(k, v);\n });\n if (mark) t.searchParams.set(EXPOSURE_PARAM, mark);\n if (!t.hash) t.hash = here.hash;\n return t.href;\n };\n for (const r of config.redirects ?? []) {\n const to = r.from && pathOf(r.from) === path ? go(r.to) : undefined;\n if (to) return { to };\n }\n for (const e of config.experiments) {\n if (!e.path || pathOf(e.path) !== path) continue;\n const running = e.status === \"running\" && !e.winner;\n if (running && distinctId === null && !preview[e.key]) return null;\n const variant = resolveVariant(e.key, config, distinctId ?? \"\", preview);\n const url = e.variants.find((v) => v.id === variant)?.url;\n const to = url ? go(url, running ? `${e.key}:${variant}` : undefined) : undefined;\n return running ? { to, experiment: e.key, variant } : to ? { to } : null;\n }\n return null;\n};\n\n/** The test and variant a redirect test's `ck_x` names, when the config has them; null otherwise. */\nexport const exposureFrom = (config: CockpitConfig | null, value: string | null | undefined) => {\n const [key, variant] = (value ?? \"\").split(\":\");\n const e = config?.experiments.find((x) => x.key === key);\n return e && e.variants.some((v) => v.id === variant) ? { experiment: key, variant } : null;\n};\n\n/**\n * The MRRocket API host from `NEXT_PUBLIC_MRROCKET_HOST`. Written as a literal property access on purpose: Next.js\n * inlines `process.env.NEXT_PUBLIC_*` at build time, in the browser bundle and in the server bundle (also on\n * Cloudflare Workers), and only replaces the literal form. Without a bundler (or a `process`) it is undefined.\n */\nexport const envHost = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_HOST || undefined;\n } catch {\n return undefined;\n }\n};\n\n/** The public key from `NEXT_PUBLIC_MRROCKET_KEY`, the default for the `apiKey` prop. Same literal-access rule as `envHost`. */\nexport const envKey = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_KEY || undefined;\n } catch {\n return undefined;\n }\n};\n\n/**\n * Where the API lives: the `host` prop, else `NEXT_PUBLIC_MRROCKET_HOST`, else \"\" (the page's own origin, which is how\n * MRRocket's own demo pages call it). Without a trailing slash.\n */\nexport const resolveHost = (host?: string) => (host ?? envHost() ?? \"\").trim().replace(/\\/+$/, \"\");\n\n/** A random visitor id. */\nexport const newDistinctId = () =>\n typeof crypto !== \"undefined\" && \"randomUUID\" in crypto ? crypto.randomUUID() : `ck_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;\n"],"mappings":";AAUO,IAAM,cAAc;AA2F3B,IAAM,SAAS,CAAC,QAAoB,SAAiB;AACjD,QAAM,OAAO,KAAK,KAAK,EAAE,YAAY;AACrC,aAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,MAAM,EAAG,KAAI,EAAE,YAAY,MAAM,KAAM,QAAO;AAClF,SAAO;AACX;AAGA,IAAM,OAAO,CAAC,QAAgB,UAAkB;AAC5C,QAAM,IAAI,OAAO,KAAK,EAAE,YAAY;AACpC,QAAM,IAAI,MAAM,KAAK,EAAE,YAAY;AACnC,SAAO,EAAE,WAAW,GAAG,IAAI,EAAE,SAAS,CAAC,IAAI,MAAM;AACrD;AAEA,IAAM,mBAAmB,CAAC,GAAkB,WAAuB;AAE/D,MAAI,EAAE,OAAO,YAAa,QAAO;AACjC,QAAM,MAAM,OAAO,QAAQ,EAAE,QAAQ;AACrC,QAAM,SAAS,QAAQ,UAAa,QAAQ,OAAO,KAAK,OAAO,GAAG;AAClE,MAAI,EAAE,OAAO,UAAK;AACd,UAAM,IAAI,OAAO,MAAM;AACvB,UAAM,I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AK,QAAQ,cAAc,IAAI,OAAO;AACvE,UAAM,MAAM,EAAE,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO,GAAG;AACtD,UAAM,KAAK,MAAM,GAAG,KAAK,UAAU,GAAG,EAAE,GAAG,IAAI,OAAO,KAAK,MAAS,IAAI;AACxE,WAAO,UAAU,EAAE,IAAI,YAAY,EAAE,KAAK,QAAQ,IAAI,KAAK,EAAE,GAAG,IAAI;AAAA,EACxE;AACA,SAAO;AACX;AAGO,IAAM,eAAe,CAAC,QAA8B,UAAqC;AAC5F,QAAM,CAAC,KAAK,OAAO,KAAK,SAAS,IAAI,MAAM,GAAG;AAC9C,QAAM,IAAI,QAAQ,YAAY,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG;AACvD,SAAO,KAAK,EAAE,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO,IAAI,EAAE,YAAY,KAAK,QAAQ,IAAI;AAC1F;AAOO,IAAM,UAAU,MAA0B;AAC7C,MAAI;AACA,WAAO,QAAQ,IAAI,6BAA6B;AAAA,EACpD,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAGO,IAAM,SAAS,MAA0B;AAC5C,MAAI;AACA,WAAO,QAAQ,IAAI,4BAA4B;AAAA,EACnD,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAMO,IAAM,cAAc,CAAC,UAAmB,QAAQ,QAAQ,KAAK,IAAI,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAG1F,IAAM,gBAAgB,MACzB,OAAO,WAAW,eAAe,gBAAgB,SAAS,OAAO,WAAW,IAAI,MAAM,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,KAAK,IAAI,EAAE,SAAS,EAAE,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/core.ts"],"sourcesContent":["/**\n * The part of the SDK that runs anywhere: experiment config, variant assignment, preview links and event shapes.\n * No React, no browser APIs, so the server helper, the proxy helper and the client share it.\n */\nimport type { CancelFlowConfig, OnboardingFlow } from \"./flows\";\nimport type { PaywallConfig } from \"./paywall\";\n\nexport type VariantId = string;\n\n/** This build of the SDK. Sent with the config request so MRRocket knows what the site runs (error tracking, flags). */\nexport const SDK_VERSION = \"0.17.0\";\n\n/** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */\nexport interface VariantConfig {\n id: VariantId;\n /** Share of traffic, 0 to 1. The weights of an experiment add up to 1. */\n weight: number;\n changes?: Record<string, string>;\n /**\n * A redirect test: where this variant sends the visitor instead of the test's page (a path like \"/pricing-b\" or a\n * full address). Control has none and stays. SDK 0.7.0+.\n */\n url?: string;\n}\n\nexport interface ExperimentConfig {\n /** The experiment's key, the same as in Cockpit. */\n key: string;\n status: \"running\" | \"draft\" | \"stopped\";\n /** Control first. */\n variants: VariantConfig[];\n /** A winner that shipped: everyone gets it, and nobody is assigned anymore. */\n winner?: VariantId;\n /** A redirect test: the path of the page it runs on (\"/pricing\"). Visitors there are sent to their variant's `url`. */\n path?: string;\n}\n\n/** A page redirect set in MRRocket (Conversion › Landing pages › Redirect): everyone on `from` goes to `to`. SDK 0.7.0+. */\nexport interface RedirectConfig {\n /** A path of the site, like \"/old-pricing\". */\n from: string;\n /** A path or a full address. */\n to: string;\n}\n\nexport interface CockpitConfig {\n /** The product the public key belongs to. */\n project: string;\n experiments: ExperimentConfig[];\n /** The product's affiliate program: how many days a partner's referral is kept. Missing without a program. */\n referral?: { cookieDays: number };\n /** Session recordings: present only while the product records (Cockpit › Sessions). See `ReplayConfig`. */\n replay?: ReplayConfig;\n /** Feature flags of the product in Production (MRRocket › Build › Feature flags), evaluated by `useFlag` and `getFlag`. */\n flags?: FlagConfig[];\n /**\n * Published copy for texts the site marks (`<Text id>`, `data-ck-text`): a landing page's headline, subheadline and\n * button (`pricing.headline` …) and a paywall's (`paywall.<placement>.headline` …) as published in MRRocket. A\n * running test's variant changes them on top. Missing when nothing is published. SDK 0.5.0+.\n */\n texts?: Record<string, string>;\n /** The product's live cancel flow (MRRocket › Churn › Cancel flow), for `cancelFlow.open()`. SDK 0.7.0+. */\n cancelFlow?: CancelFlowConfig;\n /** The in-app steps of live onboarding flows (tours, checklists, modals). SDK 0.7.0+. */\n onboarding?: OnboardingFlow[];\n /** A live Lifecycle journey has in-app messages: signed-in people ask `/api/sdk/inapp` for theirs. SDK 0.7.0+. */\n messages?: boolean;\n /** Page redirects set in MRRocket; the SDK sends visitors on before the page shows (`redirectFor`). SDK 0.7.0+. */\n redirects?: RedirectConfig[];\n /** Published paywalls with their pages, per placement (MRRocket › Conversion › Paywalls), for `paywall.open()`. SDK 0.14.0+. */\n paywalls?: PaywallConfig[];\n}\n\n/** One condition of a flag's audience, on a property of the person (`identify(id, props)`), the id or the page. */\nexport interface FlagCondition {\n /** \"Email\", \"Plan\", \"Country\", \"id\", \"path\" … Matched against the person's properties without regard to case. */\n property: string;\n op: \"is\" | \"is not\" | \"in\" | \"not in\" | \"≥\" | \"in cohort\";\n values: string[];\n}\n\n/** Users who match every condition, of whom `rollout` percent get the flag. No conditions: everyone. */\nexport interface FlagConditionSet {\n conditions: FlagCondition[];\n /** 0 to 100. */\n rollout: number;\n}\n\nexport interface FlagConfig {\n key: string;\n /** Off: everyone gets the off side. */\n on: boolean;\n /** The first set a person matches decides; none matched: off. */\n sets: FlagConditionSet[];\n /** Multivariate flags: the variants and their split in percent (control included). Missing for an on/off flag. */\n variants?: { key: string; split: number; payload?: string }[];\n}\n\n/** What a person is for flag conditions: their properties from identify(), their id and the page they are on. */\nexport type FlagPerson = Record<string, unknown>;\n\nconst propOf = (person: FlagPerson, name: string) => {\n const want = name.trim().toLowerCase();\n for (const [k, v] of Object.entries(person)) if (k.toLowerCase() === want) return v;\n return undefined;\n};\n\n/** `\"@acme.com\"` matches every address at that domain; anything else matches the whole value, without regard to case. */\nconst same = (actual: string, value: string) => {\n const a = actual.trim().toLowerCase();\n const v = value.trim().toLowerCase();\n return v.startsWith(\"@\") ? a.endsWith(v) : a === v;\n};\n\nconst matchesCondition = (c: FlagCondition, person: FlagPerson) => {\n // Cohorts live in MRRocket; a browser cannot know them, so a cohort condition never matches here.\n if (c.op === \"in cohort\") return false;\n const raw = propOf(person, c.property);\n const actual = raw === undefined || raw === null ? \"\" : String(raw);\n if (c.op === \"≥\") {\n const a = Number(actual);\n const b = Number(c.values[0]);\n return actual !== \"\" && Number.isFinite(a) && Number.isFinite(b) && a >= b;\n }\n const hit = actual !== \"\" && c.values.some((v) => same(actual, v));\n return c.op === \"is\" || c.op === \"in\" ? hit : !hit;\n};\n\n/**\n * The flag for one person: `false` (off), `true` (on, an on/off flag) or the variant's key (a multivariate flag). The\n * bucket is a stable hash of flag and person, so a person keeps their side as the rollout grows.\n */\nexport const evaluateFlag = (flag: FlagConfig, distinctId: string, person: FlagPerson = {}): boolean | string => {\n if (!flag.on) return false;\n const subject = { id: distinctId, ...person };\n const set = flag.sets.length ? flag.sets.find((s) => s.conditions.every((c) => matchesCondition(c, subject))) : { conditions: [], rollout: 100 };\n if (!set) return false;\n if (flagUnit(`${flag.key}:rollout:${distinctId}`) * 100 >= set.rollout) return false;\n if (!flag.variants?.length) return true;\n const u = flagUnit(`${flag.key}:variant:${distinctId}`) * 100;\n let acc = 0;\n for (const v of flag.variants) {\n acc += v.split;\n if (u < acc) return v.key;\n }\n return flag.variants[flag.variants.length - 1].key;\n};\n\n/** A flag of the config for this person; an unknown flag (or no config) is off. */\nexport const flagFor = (key: string, config: CockpitConfig | null, distinctId: string, person: FlagPerson = {}) => {\n const flag = config?.flags?.find((f) => f.key === key);\n return flag ? evaluateFlag(flag, distinctId, person) : false;\n};\n\n/** One JavaScript error as it goes over the wire to `POST /api/sdk/errors`. */\nexport interface ErrorReport {\n /** \"TypeError\", \"Error\" … */\n type: string;\n message: string;\n /** The raw stack, at most 8 KB. MRRocket parses it into frames. */\n stack?: string;\n /** \"onerror\" (uncaught), \"onunhandledrejection\" (a rejected promise nobody caught) or \"manual\" (captureError). */\n mechanism: \"onerror\" | \"onunhandledrejection\" | \"manual\";\n handled: boolean;\n url: string;\n ts: number;\n /** What happened just before: pages and clicks, newest last, at most 20. */\n crumbs?: { ts: number; type: \"navigation\" | \"click\" | \"lifecycle\"; message: string }[];\n /** Your release (a version or commit), from the provider's `release` prop. */\n release?: string;\n distinctId?: string;\n sessionId?: string;\n}\n\n/**\n * Session recordings of a product, from the config. Recording also needs the visitor's own replay consent\n * (`<CockpitProvider replay>` or `setConsent({ replay: true })`); without it nothing is recorded or buffered.\n */\nexport interface ReplayConfig {\n /**\n * Share of sessions uploaded from their start, 0 to 1 (default 0.1). The others keep only the last minute in\n * memory and upload it when something goes wrong: a JS error, a rage click, a `purchase…` or `checkout…` event.\n */\n sampleRate: number;\n}\n\n/**\n * What the SDK may send and store.\n * - \"cookieless\" (default): no cookie, no localStorage. Events go without a visitor id; the server counts visitors\n * with a hash of key, date, IP and user agent that changes every day.\n * - \"cookies\": a persistent `ck_id` cookie identifies the visitor across visits, `ck_sid` holds the session.\n * - \"off\": nothing is sent and nothing is stored.\n */\nexport type ConsentMode = \"cookieless\" | \"cookies\" | \"off\";\n\n/**\n * What `setConsent` takes: a mode as before, or the parts to change. `replay` is the separate consent for session\n * recordings (default false); it applies only while analytics is not \"off\".\n *\n * setConsent(\"cookies\");\n * setConsent({ replay: true });\n * setConsent({ analytics: \"cookieless\", replay: false });\n */\nexport type ConsentChoice = ConsentMode | { analytics?: ConsentMode; replay?: boolean };\n\n/** The campaign parameters the SDK reads from the landing URL. */\nexport const UTM_KEYS = [\"utm_source\", \"utm_medium\", \"utm_campaign\", \"utm_term\", \"utm_content\"] as const;\nexport type UtmKey = (typeof UTM_KEYS)[number];\n\n/** One event as it goes over the wire to `POST /api/sdk/events`. */\nexport interface CockpitEvent {\n event: string;\n /** The visitor. Missing in \"cookieless\" mode until identify(): the server then uses its daily visitor hash. */\n distinctId?: string;\n /** Ends after 30 minutes without an event. */\n sessionId?: string;\n props?: Record<string, unknown>;\n /** Milliseconds since the epoch. */\n ts: number;\n url?: string;\n /** `document.referrer` on the first page of a page load, the previous in-app URL after client-side navigation. */\n referrer?: string;\n utm_source?: string;\n utm_medium?: string;\n utm_campaign?: string;\n utm_term?: string;\n utm_content?: string;\n /** The screen size in CSS pixels (points on a phone). */\n screen?: { w: number; h: number };\n /** The app that sent it (React Native only): MRRocket stores it with the event and fills OS and device from it. */\n app?: AppContext;\n}\n\n/** Where a React Native event comes from. Every field is optional except the platform; nothing identifies the person. */\nexport interface AppContext {\n /** \"ios\" or \"android\" (React Native's `Platform.OS`). */\n platform: string;\n /** The app's version, like \"1.4.0\" (`expo-application`'s `nativeApplicationVersion`). */\n appVersion?: string;\n /** The build number, like \"42\". */\n build?: string;\n /** The OS version, like \"17.4\". */\n osVersion?: string;\n /** The device model, like \"iPhone 15 Pro\" (`expo-device`). */\n deviceModel?: string;\n /** \"phone\", \"tablet\", \"desktop\" or \"tv\" when `expo-device` knows it. */\n deviceType?: string;\n /** The first preferred locale, like \"de-DE\". */\n locale?: string;\n}\n\n/** The query parameter that forces variants, for previews in Cockpit: `?ck_preview=pricing-annual:a,home-hero:control`. */\nexport const PREVIEW_PARAM = \"ck_preview\";\n/** Set when Cockpit embeds the page: nothing is tracked, so previews never count as visits. */\nexport const EMBED_PARAM = \"ck_embed\";\n/** The cookie that keeps a visitor in the same variant across visits. Only written in \"cookies\" mode. */\nexport const ID_COOKIE = \"ck_id\";\n/** The cookie that holds the session id in \"cookies\" mode. */\nexport const SESSION_COOKIE = \"ck_sid\";\n/** A session ends after this long without an event. */\nexport const SESSION_TIMEOUT_MS = 30 * 60 * 1000;\n\n/** The UTM parameters from a parameter lookup (`URLSearchParams.get` in a browser). Empty values are left out. */\nexport const utmFrom = (get: (name: string) => string | null | undefined): Partial<Record<UtmKey, string>> => {\n const out: Partial<Record<UtmKey, string>> = {};\n for (const key of UTM_KEYS) {\n const value = get(key)?.trim();\n if (value) out[key] = value.slice(0, 150);\n }\n return out;\n};\n\n/** The UTM parameters of a query string, like `\"?utm_source=x\"`. Empty values are left out. */\nexport const readUtm = (search: string): Partial<Record<UtmKey, string>> => {\n const params = new URLSearchParams(search);\n return utmFrom((k) => params.get(k));\n};\n\n/**\n * The query parameters of a URL or query string, without `URLSearchParams` (React Native's is incomplete): `+` is a\n * space, values are percent-decoded, the first of a repeated name wins.\n */\nexport const parseQuery = (url: string): Record<string, string> => {\n const out: Record<string, string> = {};\n const q = url.split(\"#\")[0];\n const at = q.indexOf(\"?\");\n if (at < 0) return out;\n const dec = (s: string) => {\n try {\n return decodeURIComponent(s.replace(/\\+/g, \" \"));\n } catch {\n return s;\n }\n };\n for (const pair of q.slice(at + 1).split(\"&\")) {\n if (!pair) continue;\n const eq = pair.indexOf(\"=\");\n const k = dec(eq < 0 ? pair : pair.slice(0, eq));\n if (k && !(k in out)) out[k] = eq < 0 ? \"\" : dec(pair.slice(eq + 1));\n }\n return out;\n};\n\n/** FNV-1a, 32 bit, mapped to [0, 1). Stable across server and browser. */\nexport const hashUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0) / 4294967296;\n};\n\n/**\n * FNV-1a with murmur3's finalizer, mapped to [0, 1): ids that differ only at the end (\"user-1\", \"user-2\") still spread\n * evenly, so a 30 % rollout reaches about 30 % of people. Flags only; experiments keep `hashUnit` so nobody switches.\n */\nexport const flagUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n h ^= h >>> 16;\n h = Math.imul(h, 0x85ebca6b);\n h ^= h >>> 13;\n h = Math.imul(h, 0xc2b2ae35);\n h ^= h >>> 16;\n return (h >>> 0) / 4294967296;\n};\n\n/** The variant a visitor sees: a shipped winner, control while the experiment does not run, else a stable bucket by visitor. */\nexport const assign = (experiment: ExperimentConfig, distinctId: string): VariantId => {\n const control = experiment.variants[0]?.id ?? \"control\";\n if (experiment.winner) return experiment.winner;\n if (experiment.status !== \"running\") return control;\n const u = hashUnit(`${experiment.key}:${distinctId}`);\n let acc = 0;\n for (const v of experiment.variants) {\n acc += v.weight;\n if (u < acc) return v.id;\n }\n return experiment.variants[experiment.variants.length - 1]?.id ?? control;\n};\n\n/** `\"a:b,c:d\"` → `{ a: \"b\", c: \"d\" }`. Ignores anything malformed. */\nexport const parsePreview = (value: string | string[] | null | undefined): Record<string, VariantId> => {\n const raw = Array.isArray(value) ? value[0] : value;\n if (!raw) return {};\n const out: Record<string, VariantId> = {};\n for (const pair of raw.split(\",\")) {\n const [key, variant] = pair.split(\":\");\n if (key && variant) out[key.trim()] = variant.trim();\n }\n return out;\n};\n\n/** A link that shows one variant of a page, for example in Cockpit's preview frames. */\nexport const previewHref = (url: string, forced: Record<string, VariantId>, embed = true) => {\n const [path, query = \"\"] = url.split(\"?\");\n const params = new URLSearchParams(query);\n const value = Object.entries(forced)\n .map(([k, v]) => `${k}:${v}`)\n .join(\",\");\n if (value) params.set(PREVIEW_PARAM, value);\n if (embed) params.set(EMBED_PARAM, \"1\");\n return `${path}?${params.toString()}`;\n};\n\n/** The variant for one experiment, from a forced preview first, then the config. Unknown experiments get control. */\n/** The experiments whose variants change the text `id`: showing that text is an exposure to them. */\nexport const experimentsOfText = (config: CockpitConfig | null, id: string) =>\n (config?.experiments ?? []).filter((e) => e.variants.some((v) => v.changes && id in v.changes)).map((e) => e.key);\n\nexport const resolveVariant = (key: string, config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>): VariantId => {\n if (preview[key]) return preview[key];\n const experiment = config?.experiments.find((e) => e.key === key);\n return experiment ? assign(experiment, distinctId) : \"control\";\n};\n\n/**\n * Every text change that applies to this visitor: the published texts first, then each experiment's in config order.\n * Control keeps the published (or the page's own) words, so only a non-control variant (assigned, forced in a preview,\n * or a shipped winner) changes them further.\n */\nexport const textChanges = (config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>) => {\n const out: Record<string, string> = { ...(config?.texts ?? {}) };\n for (const experiment of config?.experiments ?? []) {\n const id = resolveVariant(experiment.key, config, distinctId, preview);\n if (id === (experiment.variants[0]?.id ?? \"control\")) continue;\n Object.assign(out, experiment.variants.find((v) => v.id === id)?.changes ?? {});\n }\n return out;\n};\n\n/**\n * The query parameter a redirect test adds to the variant's address (`ck_x=<test>:<variant>`): the page there records\n * the exposure and takes it out of the address bar. It also keeps that page from redirecting again.\n */\nexport const EXPOSURE_PARAM = \"ck_x\";\n\n/** What `redirectFor` decided: go to `to`, and/or the redirect test this page belongs to and the visitor's variant. */\nexport interface RedirectDecision {\n /** Where to send the visitor now. Missing for control, which stays on the page. */\n to?: string;\n /** The redirect test, while it runs: record `$exposure` for it (on this page for control, on `to` otherwise). */\n experiment?: string;\n variant?: VariantId;\n}\n\nconst pathOf = (p: string) => p.replace(/\\/+$/, \"\") || \"/\";\n\n/**\n * Where a page sends the visitor, before it shows: a page redirect set in MRRocket first, else a redirect test that runs\n * on this path (the visitor's variant, by the same stable assignment as every test). Null when nothing applies.\n *\n * - The new address keeps the page's query (UTM parameters) and its hash; a running test adds `ck_x=<test>:<variant>`,\n * so the page it lands on records the exposure (and never redirects again).\n * - `distinctId` null (no stable id, as on a server without the `ck_id` cookie): running tests are left to the browser,\n * page redirects and shipped winners still apply.\n * - A redirect to the page itself is ignored.\n */\nexport const redirectFor = (config: CockpitConfig | null, href: string, distinctId: string | null, preview: Record<string, VariantId> = {}): RedirectDecision | null => {\n if (!config) return null;\n let here: URL;\n try {\n here = new URL(href);\n } catch {\n return null;\n }\n if (here.searchParams.has(EXPOSURE_PARAM)) return null;\n const path = pathOf(here.pathname);\n const go = (to: string, mark?: string) => {\n let t: URL;\n try {\n t = new URL(to, here);\n } catch {\n return undefined;\n }\n if (!/^https?:$/.test(t.protocol) || (t.origin === here.origin && pathOf(t.pathname) === path)) return undefined;\n here.searchParams.forEach((v, k) => {\n if (!t.searchParams.has(k)) t.searchParams.set(k, v);\n });\n if (mark) t.searchParams.set(EXPOSURE_PARAM, mark);\n if (!t.hash) t.hash = here.hash;\n return t.href;\n };\n for (const r of config.redirects ?? []) {\n const to = r.from && pathOf(r.from) === path ? go(r.to) : undefined;\n if (to) return { to };\n }\n for (const e of config.experiments) {\n if (!e.path || pathOf(e.path) !== path) continue;\n const running = e.status === \"running\" && !e.winner;\n if (running && distinctId === null && !preview[e.key]) return null;\n const variant = resolveVariant(e.key, config, distinctId ?? \"\", preview);\n const url = e.variants.find((v) => v.id === variant)?.url;\n const to = url ? go(url, running ? `${e.key}:${variant}` : undefined) : undefined;\n return running ? { to, experiment: e.key, variant } : to ? { to } : null;\n }\n return null;\n};\n\n/** The test and variant a redirect test's `ck_x` names, when the config has them; null otherwise. */\nexport const exposureFrom = (config: CockpitConfig | null, value: string | null | undefined) => {\n const [key, variant] = (value ?? \"\").split(\":\");\n const e = config?.experiments.find((x) => x.key === key);\n return e && e.variants.some((v) => v.id === variant) ? { experiment: key, variant } : null;\n};\n\n/**\n * The MRRocket API host from `NEXT_PUBLIC_MRROCKET_HOST`. Written as a literal property access on purpose: Next.js\n * inlines `process.env.NEXT_PUBLIC_*` at build time, in the browser bundle and in the server bundle (also on\n * Cloudflare Workers), and only replaces the literal form. Without a bundler (or a `process`) it is undefined.\n */\nexport const envHost = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_HOST || undefined;\n } catch {\n return undefined;\n }\n};\n\n/** The public key from `NEXT_PUBLIC_MRROCKET_KEY`, the default for the `apiKey` prop. Same literal-access rule as `envHost`. */\nexport const envKey = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_KEY || undefined;\n } catch {\n return undefined;\n }\n};\n\n/**\n * Where the API lives: the `host` prop, else `NEXT_PUBLIC_MRROCKET_HOST`, else \"\" (the page's own origin, which is how\n * MRRocket's own demo pages call it). Without a trailing slash.\n */\nexport const resolveHost = (host?: string) => (host ?? envHost() ?? \"\").trim().replace(/\\/+$/, \"\");\n\n/** A random visitor id. */\nexport const newDistinctId = () =>\n typeof crypto !== \"undefined\" && \"randomUUID\" in crypto ? crypto.randomUUID() : `ck_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;\n"],"mappings":";AAUO,IAAM,cAAc;AA2F3B,IAAM,SAAS,CAAC,QAAoB,SAAiB;AACjD,QAAM,OAAO,KAAK,KAAK,EAAE,YAAY;AACrC,aAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,MAAM,EAAG,KAAI,EAAE,YAAY,MAAM,KAAM,QAAO;AAClF,SAAO;AACX;AAGA,IAAM,OAAO,CAAC,QAAgB,UAAkB;AAC5C,QAAM,IAAI,OAAO,KAAK,EAAE,YAAY;AACpC,QAAM,IAAI,MAAM,KAAK,EAAE,YAAY;AACnC,SAAO,EAAE,WAAW,GAAG,IAAI,EAAE,SAAS,CAAC,IAAI,MAAM;AACrD;AAEA,IAAM,mBAAmB,CAAC,GAAkB,WAAuB;AAE/D,MAAI,EAAE,OAAO,YAAa,QAAO;AACjC,QAAM,MAAM,OAAO,QAAQ,EAAE,QAAQ;AACrC,QAAM,SAAS,QAAQ,UAAa,QAAQ,OAAO,KAAK,OAAO,GAAG;AAClE,MAAI,EAAE,OAAO,UAAK;AACd,UAAM,IAAI,OAAO,MAAM;AACvB,UAAM,IAAI,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5B,WAAO,WAAW,MAAM,OAAO,SAAS,CAAC,KAAK,OAAO,SAAS,CAAC,KAAK,KAAK;AAAA,EAC7E;AACA,QAAM,MAAM,WAAW,MAAM,EAAE,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC;AACjE,SAAO,EAAE,OAAO,QAAQ,EAAE,OAAO,OAAO,MAAM,CAAC;AACnD;AAMO,IAAM,eAAe,CAAC,MAAkB,YAAoB,SAAqB,CAAC,MAAwB;AAC7G,MAAI,CAAC,KAAK,GAAI,QAAO;AACrB,QAAM,UAAU,EAAE,IAAI,YAAY,GAAG,OAAO;AAC5C,QAAM,MA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AK,CAAC,MAAM,EAAE,QAAQ,GAAG;AACvD,SAAO,KAAK,EAAE,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO,IAAI,EAAE,YAAY,KAAK,QAAQ,IAAI;AAC1F;AAOO,IAAM,UAAU,MAA0B;AAC7C,MAAI;AACA,WAAO,QAAQ,IAAI,6BAA6B;AAAA,EACpD,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAGO,IAAM,SAAS,MAA0B;AAC5C,MAAI;AACA,WAAO,QAAQ,IAAI,4BAA4B;AAAA,EACnD,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAMO,IAAM,cAAc,CAAC,UAAmB,QAAQ,QAAQ,KAAK,IAAI,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAG1F,IAAM,gBAAgB,MACzB,OAAO,WAAW,eAAe,gBAAgB,SAAS,OAAO,WAAW,IAAI,MAAM,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,KAAK,IAAI,EAAE,SAAS,EAAE,CAAC;","names":[]}
@@ -16,7 +16,7 @@ export interface FlowsTheme {
16
16
  /** An extra class on the root, for the site's own CSS. */
17
17
  className?: string;
18
18
  }
19
- export declare const FLOWS_CSS = "\n.ckf-root{--ckf-accent:#3f76ff;--ckf-accent-ink:#fff;--ckf-bg:#fff;--ckf-fg:#1c1d20;--ckf-muted:#5d6068;--ckf-soft:#f4f5f7;--ckf-line:#e4e5e8;--ckf-danger:#d92d20;--ckf-radius:14px;--ckf-font:inherit;--ckf-shadow:0 16px 40px -12px rgba(16,18,24,.28),0 0 0 1px rgba(16,18,24,.07)}\n.ckf-root[data-theme=dark]{--ckf-bg:#17181b;--ckf-fg:#f1f2f4;--ckf-muted:#a9acb3;--ckf-soft:#232428;--ckf-line:#2e2f35;--ckf-shadow:0 16px 40px -12px rgba(0,0,0,.6),0 0 0 1px rgba(255,255,255,.08)}\n@media (prefers-color-scheme:dark){.ckf-root[data-theme=auto]{--ckf-bg:#17181b;--ckf-fg:#f1f2f4;--ckf-muted:#a9acb3;--ckf-soft:#232428;--ckf-line:#2e2f35;--ckf-shadow:0 16px 40px -12px rgba(0,0,0,.6),0 0 0 1px rgba(255,255,255,.08)}}\n.ckf-root,.ckf-root *{box-sizing:border-box}\n.ckf-root{font-family:var(--ckf-font);font-size:14px;line-height:1.45;color:var(--ckf-fg);-webkit-font-smoothing:antialiased}\n.ckf-root :where(button,textarea){font:inherit;color:inherit;margin:0}\n.ckf-root :focus-visible{outline:2px solid var(--ckf-accent);outline-offset:2px}\n.ckf-scrim{position:fixed;inset:0;z-index:2147483002;background:rgba(0,0,0,.4);display:flex;align-items:center;justify-content:center;padding:16px;animation:ckf-fade .15s ease-out}\n.ckf-card{position:relative;width:100%;max-width:400px;max-height:calc(100dvh - 32px);overflow-y:auto;background:var(--ckf-bg);color:var(--ckf-fg);border-radius:var(--ckf-radius);box-shadow:var(--ckf-shadow);padding:18px 20px 20px;display:flex;flex-direction:column;gap:12px;animation:ckf-in .18s ease-out}\n.ckf-float{position:fixed;z-index:2147483001;right:20px;bottom:20px;width:340px;max-width:calc(100vw - 24px)}\n.ckf-top{display:flex;align-items:center;gap:8px;min-height:20px}\n.ckf-dots{display:flex;gap:4px}\n.ckf-dot{width:16px;height:4px;border-radius:4px;background:var(--ckf-line)}\n.ckf-dot[data-on]{background:var(--ckf-accent)}\n.ckf-x{margin-left:auto;width:28px;height:28px;border:0;border-radius:8px;background:none;color:var(--ckf-muted);cursor:pointer;display:inline-flex;align-items:center;justify-content:center;font-size:18px;line-height:1}\n.ckf-x:hover{background:var(--ckf-soft);color:var(--ckf-fg)}\n.ckf-h{margin:0;font-size:17px;font-weight:650;letter-spacing:-.01em;text-wrap:balance}\n.ckf-p{margin:0;color:var(--ckf-muted);text-wrap:pretty;white-space:pre-wrap}\n.ckf-small{margin:0;font-size:12px;color:var(--ckf-muted)}\n.ckf-opts{display:flex;flex-direction:column;gap:6px;margin:0;padding:0;list-style:none}\n.ckf-opt{display:flex;align-items:center;gap:10px;width:100%;min-height:40px;padding:8px 12px;border:1px solid var(--ckf-line);border-radius:10px;background:var(--ckf-bg);text-align:left;cursor:pointer;font-weight:500}\n.ckf-opt:hover{background:var(--ckf-soft)}\n.ckf-opt[aria-checked=true]{border-color:var(--ckf-accent);background:color-mix(in srgb,var(--ckf-accent) 8%,var(--ckf-bg))}\n.ckf-radio{width:16px;height:16px;flex:none;border-radius:50%;border:1.5px solid var(--ckf-line);display:inline-flex;align-items:center;justify-content:center}\n.ckf-opt[aria-checked=true] .ckf-radio{border-color:var(--ckf-accent)}\n.ckf-opt[aria-checked=true] .ckf-radio::after{content:\"\";width:8px;height:8px;border-radius:50%;background:var(--ckf-accent)}\n.ckf-box{border-radius:10px;background:var(--ckf-soft);padding:12px;display:flex;align-items:baseline;gap:8px;flex-wrap:wrap}\n.ckf-big{font-size:22px;font-weight:650;font-variant-numeric:tabular-nums}\n.ckf-strike{color:var(--ckf-muted);text-decoration:line-through;font-variant-numeric:tabular-nums}\n.ckf-text{width:100%;min-height:64px;resize:vertical;border:1px solid var(--ckf-line);border-radius:10px;background:var(--ckf-bg);padding:8px 10px}\n.ckf-text::placeholder{color:var(--ckf-muted)}\n.ckf-btns{display:flex;flex-direction:column;gap:6px}\n.ckf-btn{height:38px;padding:0 14px;border-radius:10px;border:1px solid var(--ckf-line);background:var(--ckf-bg);font-weight:600;cursor:pointer;transition:filter .1s linear,background-color .1s linear}\n.ckf-btn:hover{background:var(--ckf-soft)}\n.ckf-btn[disabled]{opacity:.55;cursor:not-allowed}\n.ckf-primary{background:var(--ckf-accent);border-color:var(--ckf-accent);color:var(--ckf-accent-ink)}\n.ckf-primary:hover{background:var(--ckf-accent);filter:brightness(1.07)}\n.ckf-danger{background:var(--ckf-danger);border-color:var(--ckf-danger);color:#fff}\n.ckf-danger:hover{background:var(--ckf-danger);filter:brightness(1.07)}\n.ckf-quiet{border-color:transparent;background:none;color:var(--ckf-muted);height:30px;font-weight:500}\n.ckf-quiet:hover{background:none;color:var(--ckf-fg)}\n.ckf-err{margin:0;color:var(--ckf-danger);font-size:13px;font-weight:500}\n.ckf-row{display:flex;justify-content:flex-end;gap:8px;align-items:center}\n.ckf-row .ckf-small{margin-right:auto}\n.ckf-ring{position:fixed;z-index:2147483000;pointer-events:none;border-radius:10px;box-shadow:0 0 0 2px var(--ckf-accent),0 0 0 6px color-mix(in srgb,var(--ckf-accent) 25%,transparent);transition:all .15s ease-out}\n.ckf-check{display:flex;align-items:flex-start;gap:10px;width:100%;padding:8px 6px;border:0;border-radius:8px;background:none;text-align:left}\n.ckf-check:where(button){cursor:pointer}\n.ckf-check:where(button):hover{background:var(--ckf-soft)}\n.ckf-tick{width:18px;height:18px;flex:none;margin-top:1px;border-radius:50%;border:1.5px solid var(--ckf-line);display:inline-flex;align-items:center;justify-content:center;color:var(--ckf-accent-ink);font-size:11px;font-weight:700}\n.ckf-check[data-done] .ckf-tick{background:var(--ckf-accent);border-color:var(--ckf-accent)}\n.ckf-check[data-done] b{color:var(--ckf-muted);text-decoration:line-through}\n.ckf-check span{display:flex;flex-direction:column;gap:2px;min-width:0}\n.ckf-bar{height:4px;border-radius:4px;background:var(--ckf-soft);overflow:hidden}\n.ckf-bar i{display:block;height:100%;background:var(--ckf-accent)}\n.ckf-banner{position:fixed;z-index:2147483001;left:50%;top:12px;transform:translateX(-50%);width:min(640px,calc(100vw - 24px));background:var(--ckf-bg);border-radius:12px;box-shadow:var(--ckf-shadow);padding:10px 10px 10px 16px;display:flex;align-items:center;gap:12px;animation:ckf-in .18s ease-out}\n.ckf-banner>span{flex:1;min-width:0;display:flex;flex-direction:column}\n.ckf-banner .ckf-btn{height:32px}\n.ckf-pw{max-width:420px;gap:14px}\n.ckf-root[data-still] :is(.ckf-scrim,.ckf-card){animation:none}\n.ckf-li{display:flex;gap:10px;align-items:flex-start;margin:0}\n.ckf-li::before{content:\"\u2713\";flex:none;width:20px;height:20px;border-radius:50%;background:color-mix(in srgb,var(--ckf-accent) 14%,var(--ckf-bg));color:var(--ckf-accent);font-size:12px;font-weight:700;display:inline-flex;align-items:center;justify-content:center}\n.ckf-quote{margin:0;padding:12px 14px;border-radius:12px;background:var(--ckf-soft)}\n.ckf-quote cite{display:block;margin-top:6px;font-style:normal;font-size:12px;color:var(--ckf-muted)}\n.ckf-plan{justify-content:space-between;min-height:52px}\n.ckf-plan span:nth-child(2){display:flex;flex-direction:column;margin-right:auto}\n.ckf-plan b{font-variant-numeric:tabular-nums}\n@keyframes ckf-fade{from{opacity:0}}\n@keyframes ckf-in{from{opacity:0;transform:translateY(6px)}}\n.ckf-banner{animation-name:ckf-fade}\n@media (max-width:520px){.ckf-scrim{align-items:flex-end;padding:0}.ckf-scrim .ckf-card{max-width:none;border-radius:var(--ckf-radius) var(--ckf-radius) 0 0;max-height:92dvh}.ckf-float{right:12px;bottom:12px}}\n@media (prefers-reduced-motion:reduce){.ckf-root *{animation:none!important;transition:none!important}}\n";
19
+ export declare const FLOWS_CSS = "\n.ckf-root{--ckf-accent:#3f76ff;--ckf-accent-ink:#fff;--ckf-bg:#fff;--ckf-fg:#1c1d20;--ckf-muted:#5d6068;--ckf-soft:#f4f5f7;--ckf-line:#e4e5e8;--ckf-danger:#d92d20;--ckf-radius:14px;--ckf-font:inherit;--ckf-shadow:0 16px 40px -12px rgba(16,18,24,.28),0 0 0 1px rgba(16,18,24,.07)}\n.ckf-root[data-theme=dark]{--ckf-bg:#17181b;--ckf-fg:#f1f2f4;--ckf-muted:#a9acb3;--ckf-soft:#232428;--ckf-line:#2e2f35;--ckf-shadow:0 16px 40px -12px rgba(0,0,0,.6),0 0 0 1px rgba(255,255,255,.08)}\n@media (prefers-color-scheme:dark){.ckf-root[data-theme=auto]{--ckf-bg:#17181b;--ckf-fg:#f1f2f4;--ckf-muted:#a9acb3;--ckf-soft:#232428;--ckf-line:#2e2f35;--ckf-shadow:0 16px 40px -12px rgba(0,0,0,.6),0 0 0 1px rgba(255,255,255,.08)}}\n.ckf-root,.ckf-root *{box-sizing:border-box}\n.ckf-root{font-family:var(--ckf-font);font-size:14px;line-height:1.45;color:var(--ckf-fg);-webkit-font-smoothing:antialiased}\n.ckf-root :where(button,textarea){font:inherit;color:inherit;margin:0}\n.ckf-root :focus-visible{outline:2px solid var(--ckf-accent);outline-offset:2px}\n.ckf-scrim{position:fixed;inset:0;z-index:2147483002;background:rgba(0,0,0,.4);display:flex;align-items:center;justify-content:center;padding:16px;animation:ckf-fade .15s ease-out}\n.ckf-card{position:relative;width:100%;max-width:400px;max-height:calc(100dvh - 32px);overflow-y:auto;background:var(--ckf-bg);color:var(--ckf-fg);border-radius:var(--ckf-radius);box-shadow:var(--ckf-shadow);padding:18px 20px 20px;display:flex;flex-direction:column;gap:12px;animation:ckf-in .18s ease-out}\n.ckf-float{position:fixed;z-index:2147483001;right:20px;bottom:20px;width:340px;max-width:calc(100vw - 24px)}\n.ckf-top{display:flex;align-items:center;gap:8px;min-height:20px}\n.ckf-dots{display:flex;gap:4px}\n.ckf-dot{width:16px;height:4px;border-radius:4px;background:var(--ckf-line)}\n.ckf-dot[data-on]{background:var(--ckf-accent)}\n.ckf-x{margin-left:auto;width:28px;height:28px;border:0;border-radius:8px;background:none;color:var(--ckf-muted);cursor:pointer;display:inline-flex;align-items:center;justify-content:center;font-size:18px;line-height:1}\n.ckf-x:hover{background:var(--ckf-soft);color:var(--ckf-fg)}\n.ckf-h{margin:0;font-size:17px;font-weight:650;letter-spacing:-.01em;text-wrap:balance}\n.ckf-p{margin:0;color:var(--ckf-muted);text-wrap:pretty;white-space:pre-wrap}\n.ckf-small{margin:0;font-size:12px;color:var(--ckf-muted)}\n.ckf-opts{display:flex;flex-direction:column;gap:6px;margin:0;padding:0;list-style:none}\n.ckf-opt{display:flex;align-items:center;gap:10px;width:100%;min-height:40px;padding:8px 12px;border:1px solid var(--ckf-line);border-radius:10px;background:var(--ckf-bg);text-align:left;cursor:pointer;font-weight:500}\n.ckf-opt:hover{background:var(--ckf-soft)}\n.ckf-opt[aria-checked=true]{border-color:var(--ckf-accent);background:color-mix(in srgb,var(--ckf-accent) 8%,var(--ckf-bg))}\n.ckf-radio{width:16px;height:16px;flex:none;border-radius:50%;border:1.5px solid var(--ckf-line);display:inline-flex;align-items:center;justify-content:center}\n.ckf-opt[aria-checked=true] .ckf-radio{border-color:var(--ckf-accent)}\n.ckf-opt[aria-checked=true] .ckf-radio::after{content:\"\";width:8px;height:8px;border-radius:50%;background:var(--ckf-accent)}\n.ckf-box{border-radius:10px;background:var(--ckf-soft);padding:12px;display:flex;align-items:baseline;gap:8px;flex-wrap:wrap}\n.ckf-big{font-size:22px;font-weight:650;font-variant-numeric:tabular-nums}\n.ckf-strike{color:var(--ckf-muted);text-decoration:line-through;font-variant-numeric:tabular-nums}\n.ckf-text{width:100%;min-height:64px;resize:vertical;border:1px solid var(--ckf-line);border-radius:10px;background:var(--ckf-bg);padding:8px 10px}\n.ckf-text::placeholder{color:var(--ckf-muted)}\n.ckf-btns{display:flex;flex-direction:column;gap:6px}\n.ckf-btn{height:38px;padding:0 14px;border-radius:10px;border:1px solid var(--ckf-line);background:var(--ckf-bg);font-weight:600;cursor:pointer;transition:filter .1s linear,background-color .1s linear}\n.ckf-btn:hover{background:var(--ckf-soft)}\n.ckf-btn[disabled]{opacity:.55;cursor:not-allowed}\n.ckf-primary{background:var(--ckf-accent);border-color:var(--ckf-accent);color:var(--ckf-accent-ink)}\n.ckf-primary:hover{background:var(--ckf-accent);filter:brightness(1.07)}\n.ckf-danger{background:var(--ckf-danger);border-color:var(--ckf-danger);color:#fff}\n.ckf-danger:hover{background:var(--ckf-danger);filter:brightness(1.07)}\n.ckf-quiet{border-color:transparent;background:none;color:var(--ckf-muted);height:30px;font-weight:500}\n.ckf-quiet:hover{background:none;color:var(--ckf-fg)}\n.ckf-err{margin:0;color:var(--ckf-danger);font-size:13px;font-weight:500}\n.ckf-row{display:flex;justify-content:flex-end;gap:8px;align-items:center}\n.ckf-row .ckf-small{margin-right:auto}\n.ckf-media{display:block;width:100%;max-height:240px;object-fit:cover;border-radius:10px;background:var(--ckf-soft)}\n.ckf-video{position:relative;width:100%;aspect-ratio:16/9;border-radius:10px;overflow:hidden;background:#000}\n.ckf-video iframe{position:absolute;inset:0;width:100%;height:100%;border:0}\n.ckf-arrow{position:absolute;width:12px;height:12px;margin:-6px;background:var(--ckf-bg);transform:rotate(45deg)}\n[data-side=bottom]>.ckf-arrow{top:0;left:var(--ckf-ap)}[data-side=top]>.ckf-arrow{top:100%;left:var(--ckf-ap)}\n[data-side=right]>.ckf-arrow{left:0;top:var(--ckf-ap)}[data-side=left]>.ckf-arrow{left:100%;top:var(--ckf-ap)}\n.ckf-check .ckf-go{margin-left:auto;align-self:center;color:var(--ckf-accent);font-weight:700}\n.ckf-ring{position:fixed;z-index:2147483000;pointer-events:none;border-radius:10px;box-shadow:0 0 0 2px var(--ckf-accent),0 0 0 6px color-mix(in srgb,var(--ckf-accent) 25%,transparent);transition:all .15s ease-out}\n.ckf-check{display:flex;align-items:flex-start;gap:10px;width:100%;padding:8px 6px;border:0;border-radius:8px;background:none;text-align:left}\n.ckf-check:where(button){cursor:pointer}\n.ckf-check:where(button):hover{background:var(--ckf-soft)}\n.ckf-tick{width:18px;height:18px;flex:none;margin-top:1px;border-radius:50%;border:1.5px solid var(--ckf-line);display:inline-flex;align-items:center;justify-content:center;color:var(--ckf-accent-ink);font-size:11px;font-weight:700}\n.ckf-check[data-done] .ckf-tick{background:var(--ckf-accent);border-color:var(--ckf-accent)}\n.ckf-check[data-done] b{color:var(--ckf-muted);text-decoration:line-through}\n.ckf-check span{display:flex;flex-direction:column;gap:2px;min-width:0}\n.ckf-bar{height:4px;border-radius:4px;background:var(--ckf-soft);overflow:hidden}\n.ckf-bar i{display:block;height:100%;background:var(--ckf-accent)}\n.ckf-banner{position:fixed;z-index:2147483001;left:50%;top:12px;transform:translateX(-50%);width:min(640px,calc(100vw - 24px));background:var(--ckf-bg);border-radius:12px;box-shadow:var(--ckf-shadow);padding:10px 10px 10px 16px;display:flex;align-items:center;gap:12px;animation:ckf-in .18s ease-out}\n.ckf-banner>span{flex:1;min-width:0;display:flex;flex-direction:column}\n.ckf-banner .ckf-btn{height:32px}\n.ckf-pw{max-width:420px;gap:14px}\n.ckf-root[data-still] :is(.ckf-scrim,.ckf-card){animation:none}\n.ckf-li{display:flex;gap:10px;align-items:flex-start;margin:0}\n.ckf-li::before{content:\"\u2713\";flex:none;width:20px;height:20px;border-radius:50%;background:color-mix(in srgb,var(--ckf-accent) 14%,var(--ckf-bg));color:var(--ckf-accent);font-size:12px;font-weight:700;display:inline-flex;align-items:center;justify-content:center}\n.ckf-quote{margin:0;padding:12px 14px;border-radius:12px;background:var(--ckf-soft)}\n.ckf-quote cite{display:block;margin-top:6px;font-style:normal;font-size:12px;color:var(--ckf-muted)}\n.ckf-plan{justify-content:space-between;min-height:52px}\n.ckf-plan span:nth-child(2){display:flex;flex-direction:column;margin-right:auto}\n.ckf-plan b{font-variant-numeric:tabular-nums}\n@keyframes ckf-fade{from{opacity:0}}\n@keyframes ckf-in{from{opacity:0;transform:translateY(6px)}}\n.ckf-banner{animation-name:ckf-fade}\n@media (max-width:520px){.ckf-scrim{align-items:flex-end;padding:0}.ckf-scrim .ckf-card{max-width:none;border-radius:var(--ckf-radius) var(--ckf-radius) 0 0;max-height:92dvh}.ckf-float{right:12px;bottom:12px}}\n@media (prefers-reduced-motion:reduce){.ckf-root *{animation:none!important;transition:none!important}}\n";
20
20
  export declare const mountFlows: (ctl: FlowsController, theme?: FlowsTheme) => (() => void);
21
21
  /**
22
22
  * Draws an open paywall (paywall.ts) page by page until the returned function is called: the dots, the page's title and
package/dist/flows-ui.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/flows-ui.ts
2
- import { discounted, money, offerButton } from "./flows.js";
2
+ import { discounted, mediaOf, money, offerButton, videoEmbed } from "./flows.js";
3
3
  var STYLE_ID = "ckf-styles";
4
4
  var FLOWS_CSS = `
5
5
  .ckf-root{--ckf-accent:#3f76ff;--ckf-accent-ink:#fff;--ckf-bg:#fff;--ckf-fg:#1c1d20;--ckf-muted:#5d6068;--ckf-soft:#f4f5f7;--ckf-line:#e4e5e8;--ckf-danger:#d92d20;--ckf-radius:14px;--ckf-font:inherit;--ckf-shadow:0 16px 40px -12px rgba(16,18,24,.28),0 0 0 1px rgba(16,18,24,.07)}
@@ -46,6 +46,13 @@ var FLOWS_CSS = `
46
46
  .ckf-err{margin:0;color:var(--ckf-danger);font-size:13px;font-weight:500}
47
47
  .ckf-row{display:flex;justify-content:flex-end;gap:8px;align-items:center}
48
48
  .ckf-row .ckf-small{margin-right:auto}
49
+ .ckf-media{display:block;width:100%;max-height:240px;object-fit:cover;border-radius:10px;background:var(--ckf-soft)}
50
+ .ckf-video{position:relative;width:100%;aspect-ratio:16/9;border-radius:10px;overflow:hidden;background:#000}
51
+ .ckf-video iframe{position:absolute;inset:0;width:100%;height:100%;border:0}
52
+ .ckf-arrow{position:absolute;width:12px;height:12px;margin:-6px;background:var(--ckf-bg);transform:rotate(45deg)}
53
+ [data-side=bottom]>.ckf-arrow{top:0;left:var(--ckf-ap)}[data-side=top]>.ckf-arrow{top:100%;left:var(--ckf-ap)}
54
+ [data-side=right]>.ckf-arrow{left:0;top:var(--ckf-ap)}[data-side=left]>.ckf-arrow{left:100%;top:var(--ckf-ap)}
55
+ .ckf-check .ckf-go{margin-left:auto;align-self:center;color:var(--ckf-accent);font-weight:700}
49
56
  .ckf-ring{position:fixed;z-index:2147483000;pointer-events:none;border-radius:10px;box-shadow:0 0 0 2px var(--ckf-accent),0 0 0 6px color-mix(in srgb,var(--ckf-accent) 25%,transparent);transition:all .15s ease-out}
50
57
  .ckf-check{display:flex;align-items:flex-start;gap:10px;width:100%;padding:8px 6px;border:0;border-radius:8px;background:none;text-align:left}
51
58
  .ckf-check:where(button){cursor:pointer}
@@ -287,6 +294,17 @@ var mountFlows = (ctl, theme = {}) => {
287
294
  )
288
295
  );
289
296
  };
297
+ const media = (s) => {
298
+ const m = mediaOf(s);
299
+ if (!m) return false;
300
+ if (m.kind === "image") return h("img", { className: "ckf-media", src: m.url, alt: m.alt ?? "", onLoad: () => follow() });
301
+ const v = videoEmbed(m.url);
302
+ return v.kind === "iframe" ? h(
303
+ "div",
304
+ { className: "ckf-video" },
305
+ h("iframe", { src: v.src, title: m.alt || "Video", allow: "fullscreen; picture-in-picture", allowfullscreen: true, loading: "lazy", referrerpolicy: "strict-origin-when-cross-origin" })
306
+ ) : h("video", { className: "ckf-media", src: v.src, controls: true, playsinline: true, preload: "metadata", "aria-label": m.alt || void 0, onLoadedmetadata: () => follow() });
307
+ };
290
308
  const stepCard = (v) => {
291
309
  const s = v.step;
292
310
  const card = h(
@@ -298,6 +316,7 @@ var mountFlows = (ctl, theme = {}) => {
298
316
  v.total > 1 ? h("p", { className: "ckf-small" }, `Step ${v.index + 1} of ${v.total}`) : h("span"),
299
317
  closeButton("Close the tour", ctl.onboarding.dismiss)
300
318
  ),
319
+ media(s),
301
320
  h("h2", { className: "ckf-h", id: "ckf-title" }, s.title),
302
321
  s.body ? h("p", { className: "ckf-p" }, s.body) : false,
303
322
  h("div", { className: "ckf-row" }, button(s.button || (v.last ? "Done" : "Next"), "primary", ctl.onboarding.next, { id: "go" }))
@@ -307,8 +326,9 @@ var mountFlows = (ctl, theme = {}) => {
307
326
  const float = h("div", { className: "ckf-float" }, card);
308
327
  if (target) {
309
328
  const ring = h("div", { className: "ckf-ring", "aria-hidden": "true" });
310
- placed = { float, ring, target };
311
- place(float, ring, target);
329
+ float.append(h("span", { className: "ckf-arrow", "aria-hidden": "true" }));
330
+ placed = { float, ring, target, side: s.placement };
331
+ place(float, ring, target, s.placement);
312
332
  return h("div", {}, ring, float);
313
333
  }
314
334
  return float;
@@ -325,15 +345,31 @@ var mountFlows = (ctl, theme = {}) => {
325
345
  return null;
326
346
  }
327
347
  };
328
- const place = (float, ring, target) => {
348
+ const place = (float, ring, target, side = "auto") => {
329
349
  const r = target.getBoundingClientRect();
330
350
  Object.assign(ring.style, { left: `${r.left - 4}px`, top: `${r.top - 4}px`, width: `${r.width + 8}px`, height: `${r.height + 8}px` });
331
- const w = Math.min(340, window.innerWidth - 24);
332
- const left = Math.max(12, Math.min(r.left, window.innerWidth - w - 12));
333
- const below = r.bottom + 12;
334
- Object.assign(float.style, { left: `${left}px`, right: "auto", width: `${w}px` });
335
- if (below + 200 < window.innerHeight) Object.assign(float.style, { top: `${below}px`, bottom: "auto" });
336
- else Object.assign(float.style, { top: "auto", bottom: `${Math.max(12, window.innerHeight - r.top + 12)}px` });
351
+ const vw = window.innerWidth;
352
+ const vh = window.innerHeight;
353
+ const w = Math.min(340, vw - 24);
354
+ const ht = float.offsetHeight || 200;
355
+ const gap = 14;
356
+ const room = {
357
+ bottom: vh - r.bottom - gap - 12 >= ht,
358
+ top: r.top - gap - 12 >= ht,
359
+ right: vw - r.right - gap - 12 >= w,
360
+ left: r.left - gap - 12 >= w
361
+ };
362
+ const flip = { top: "bottom", bottom: "top", left: "right", right: "left" };
363
+ const order = side === "auto" || !flip[side] ? ["bottom", "top"] : [side, flip[side], "bottom", "top", "right", "left"];
364
+ const s = order.find((x) => room[x]) ?? (side !== "auto" && flip[side] ? side : r.top > vh - r.bottom ? "top" : "bottom");
365
+ const clamp = (v, hi) => Math.max(12, Math.min(v, hi - 12));
366
+ const across = s === "top" || s === "bottom";
367
+ const left = across ? clamp(side === "auto" ? r.left : r.left + r.width / 2 - w / 2, vw - w) : s === "right" ? r.right + gap : r.left - gap - w;
368
+ const top = across ? s === "bottom" ? r.bottom + gap : r.top - gap - ht : clamp(r.top + r.height / 2 - ht / 2, vh - ht);
369
+ Object.assign(float.style, { left: `${left}px`, top: `${top}px`, right: "auto", bottom: "auto", width: `${w}px` });
370
+ float.setAttribute("data-side", s);
371
+ const at = across ? r.left + r.width / 2 - left : r.top + r.height / 2 - top;
372
+ float.style.setProperty("--ckf-ap", `${Math.max(18, Math.min(at, (across ? w : ht) - 18))}px`);
337
373
  };
338
374
  const checklist = (v) => {
339
375
  const done = v.items.filter((i) => i.done).length;
@@ -358,11 +394,24 @@ var mountFlows = (ctl, theme = {}) => {
358
394
  h(
359
395
  "div",
360
396
  { className: "ckf-opts" },
361
- ...v.items.map(({ step, done: d }) => {
397
+ ...v.items.map(({ step, done: d, tour }) => {
362
398
  const inner = [
363
399
  h("span", { className: "ckf-tick", "aria-hidden": "true" }, d ? "\u2713" : ""),
364
400
  h("span", {}, h("b", {}, step.title), step.body ? h("span", { className: "ckf-small" }, step.body) : false)
365
401
  ];
402
+ if (!d && tour)
403
+ return h(
404
+ "button",
405
+ {
406
+ type: "button",
407
+ className: "ckf-check",
408
+ "aria-label": `Start \u201C${step.title}\u201D`,
409
+ "data-ckf-id": `t:${step.id}`,
410
+ onClick: () => ctl.onboarding.startTour(step.id)
411
+ },
412
+ ...inner,
413
+ h("span", { className: "ckf-go", "aria-hidden": "true" }, "\u203A")
414
+ );
366
415
  return d || step.event ? h("div", { className: "ckf-check", "data-done": d, role: "listitem" }, ...inner) : h(
367
416
  "button",
368
417
  {
@@ -415,6 +464,7 @@ var mountFlows = (ctl, theme = {}) => {
415
464
  root.replaceChildren(
416
465
  ...v ? [v.type === "cancel" ? cancelCard(v) : v.type === "step" ? stepCard(v) : v.type === "checklist" ? checklist(v) : message(v)] : []
417
466
  );
467
+ follow();
418
468
  if (key !== lastKey) {
419
469
  const modal = root.querySelector("[aria-modal=true]");
420
470
  const first = modal?.querySelector("[role=radio], [data-ckf-id=go], textarea") ?? null;
@@ -433,9 +483,9 @@ var mountFlows = (ctl, theme = {}) => {
433
483
  else if (v?.type === "message") ctl.message.dismiss();
434
484
  else if (v?.type === "step" && v.step.kind === "modal") ctl.onboarding.dismiss();
435
485
  };
436
- const follow = () => {
437
- if (placed) place(placed.float, placed.ring, placed.target);
438
- };
486
+ function follow() {
487
+ if (placed) place(placed.float, placed.ring, placed.target, placed.side);
488
+ }
439
489
  document.addEventListener("keydown", onKey);
440
490
  window.addEventListener("resize", follow);
441
491
  window.addEventListener("scroll", follow, { passive: true, capture: true });