@sentientui/snippet 0.12.0 → 0.13.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
- "use strict";var SentientSnippet=(()=>{var we=Object.defineProperty;var en=Object.getOwnPropertyDescriptor;var tn=Object.getOwnPropertyNames,Ye=Object.getOwnPropertySymbols;var Xe=Object.prototype.hasOwnProperty,nn=Object.prototype.propertyIsEnumerable;var Ze=(e,t,n)=>t in e?we(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))Xe.call(t,n)&&Ze(e,n,t[n]);if(Ye)for(var n of Ye(t))nn.call(t,n)&&Ze(e,n,t[n]);return e};var Qe=(e,t)=>()=>(e&&(t=e(e=0)),t);var et=(e,t)=>{for(var n in t)we(e,n,{get:t[n],enumerable:!0})},rn=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of tn(t))!Xe.call(e,o)&&o!==n&&we(e,o,{get:()=>t[o],enumerable:!(r=en(t,o))||r.enumerable});return e};var on=e=>rn(we({},"__esModule",{value:!0}),e);var sn,an,ln,tt,cn,un,nt,I,me,Se=Qe(()=>{"use strict";sn=Object.defineProperty,an=Object.defineProperties,ln=Object.getOwnPropertyDescriptors,tt=Object.getOwnPropertySymbols,cn=Object.prototype.hasOwnProperty,un=Object.prototype.propertyIsEnumerable,nt=(e,t,n)=>t in e?sn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,I=(e,t)=>{for(var n in t||(t={}))cn.call(t,n)&&nt(e,n,t[n]);if(tt)for(var n of tt(t))un.call(t,n)&&nt(e,n,t[n]);return e},me=(e,t)=>an(e,ln(t))});var dt={};et(dt,{LOCAL_ENGINE_AVAILABLE:()=>fn,createLocalEngine:()=>gn});function gn(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var fn,pt=Qe(()=>{"use strict";fn=!1});var ur={};et(ur,{applyPersonaAttributes:()=>_e,applyRegistrySlots:()=>Pe,applySlotArms:()=>Te,applySlotAttributes:()=>Re,parseEditorToken:()=>Ft,parsePersonaPreview:()=>Yt,parsePreview:()=>Ht,parseSnippetConfig:()=>Ce,reapply:()=>Fe,run:()=>Xt,version:()=>ze});Se();function xe(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function rt(e){if(e.length===0)return null;let t={};for(let n of e.split("|")){let r=n.indexOf("=");if(r<=0||r!==n.lastIndexOf("=")||r===n.length-1)return null;let o=n.slice(0,r);if(o in t)return null;t[o]=n.slice(r+1)}return t}function Ne(e){var t,n,r;if(e.arms)return typeof e.baseline=="string"?e.baseline:(t=e.arms[0])!=null?t:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return xe(e.baseline);if(typeof e.baseline=="string")return e.baseline;let o={};for(let[s,a]of Object.entries((n=e.dims)!=null?n:{}))o[s]=(r=a[0])!=null?r:"";return xe(o)}function ot(e,t){var n,r;return e.dims!=null?(r=(n=rt(t))!=null?n:rt(Ne(e)))!=null?r:{}:t}function se(e){return e>=.3?e<.7?"medium":"high":"low"}var dn=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function it(e){return pn(e)!==null}function pn(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=dn.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function st(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function at(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(o){}let r=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(n){return"direct"}}function lt(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function ct(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function $e(e){return I(I(I({id:e.id},e.arms?{arms:[...e.arms]}:{}),e.dims?{dims:Object.fromEntries(Object.entries(e.dims).map(([t,n])=>[t,[...n]]))}:{}),e.baseline!==void 0?{baseline:e.baseline}:{})}function Ke(e){let t=$e(e);return ot(t,Ne(t))}function ut(e){return typeof e=="string"?e:xe(e)}Se();function gt(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}try{if(typeof crypto!="undefined"&&typeof crypto.getRandomValues=="function"){let e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t="";for(let n=0;n<16;n++)t+=e[n].toString(16).padStart(2,"0"),(n===3||n===5||n===7||n===9)&&(t+="-");return t}}catch(e){}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function mt(e){return e?`_${e.slice(0,12)}`:""}var mn="_snt_uid",hn=365,yn="_snt_uid";function vn(){return gt()}function bn(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function wn(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function Sn(e){try{return localStorage.getItem(e)}catch(t){return null}}function xn(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function An(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function kn(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function En(e){try{sessionStorage.removeItem(e)}catch(t){}}function In(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function On(e){try{localStorage.removeItem(e)}catch(t){}}function Cn(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var _n={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ht(e){var t,n,r,o,s,a;if(typeof window=="undefined")return _n;let c=mt(e==null?void 0:e.apiKey),i=(t=e==null?void 0:e.cookieName)!=null?t:`${mn}${c}`,l=`${yn}${c}`,u=((n=e==null?void 0:e.cookieTTLDays)!=null?n:hn)*24*60*60,d=C=>C&&C.length>0?C:null,m=(a=(s=(o=(r=d(bn(i)))!=null?r:d(Sn(l)))!=null?o:d(An(l)))!=null?s:d(e==null?void 0:e.ssrSessionId))!=null?a:vn();wn(i,m,u);let g=xn(l,m),b=In(i),w=g?!1:kn(l,m),A=!g&&!b&&!w;return{getSessionId:()=>m,isEphemeral:()=>A,destroy:()=>{m=null,Cn(i),On(l),En(l)}}}function yt(e){return`_snt_retry_${e.slice(0,12)}`}var Rn={push:()=>{},flush:()=>{},destroy:()=>{}};function Tn(e,t){try{let n=localStorage.getItem(t);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?(localStorage.removeItem(t),r.slice(-e)):[]}catch(n){return[]}}function Be(e,t,n){try{let r=(()=>{try{let a=localStorage.getItem(n);if(!a)return[];let c=JSON.parse(a);return Array.isArray(c)?c:[]}catch(a){return[]}})(),o=new Map;for(let a of r)o.set(a.id,a);for(let a of e)o.set(a.id,a);let s=[...o.values()].slice(-t);localStorage.setItem(n,JSON.stringify(s))}catch(r){}}function Pn(e,t){try{let n=localStorage.getItem(t);if(!n)return;let r=JSON.parse(n);if(!Array.isArray(r))return;let o=new Set(e),s=r.filter(a=>!o.has(a.id));if(s.length===r.length)return;s.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(s))}catch(n){}}function Ln(e){var t,n,r;if(typeof window=="undefined")return Rn;let o=(t=e.flushIntervalMs)!=null?t:5e3,s=(n=e.maxBatchSize)!=null?n:20,a=(r=e.maxRetrySize)!=null?r:100,c=e.ingestUrl,i=e.apiKey,l=yt(i),u=[],d=new Set,m=[],g=f=>{for(let x of f)b.delete(x),!d.has(x)&&(d.add(x),m.push(x));for(;m.length>500;){let x=m.shift();x&&d.delete(x)}Pn(f,l)},b=new Set,w=f=>{d.has(f.id)||b.has(f.id)||(b.add(f.id),u.push(f))},A=f=>{for(let x of f)d.has(x.id)||(b.add(x.id),u.push(x))},C=Tn(a,l);for(let f of C)w(f);let S=0,E=0,j=f=>{if(f.length===0)return;let x=JSON.stringify(f),M=f.map(p=>p.id),z;try{z=fetch(c,{method:"POST",keepalive:!0,body:x,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}})}catch(p){Be(f,a,l),A(f),E++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6));return}let G=p=>{if(p.ok||p.status>=400&&p.status<500&&p.status!==429){g(M),E=0,S=0;return}Be(f,a,l),A(f),E++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))};z instanceof Promise?z.then(G).catch(()=>{Be(f,a,l),A(f),E++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))}):G(z)},H=typeof TextEncoder!="undefined"?new TextEncoder:null,le=f=>H?H.encode(f).length:f.length,ne=f=>{let x=[],M=2;for(let z of f){let G=le(JSON.stringify(z))+1;if(x.length>0&&M+G>57344||x.length>=s)break;x.push(z),M+=G}return x},_=()=>{try{if(Date.now()<S)return;for(;u.length>0&&!(Date.now()<S);){let f=u.filter(M=>!d.has(M.id));if(u.length=0,f.length===0)break;let x=ne(f);if(x.length===0)break;x.length<f.length&&u.push(...f.slice(x.length)),j(x)}}catch(f){}},Y=!0,y=null;y=setInterval(()=>{Y&&_()},o);let h=()=>{document.visibilityState==="hidden"&&_()},k=()=>{_()};return document.addEventListener("visibilitychange",h),window.addEventListener("pagehide",k),{push(f){w(f),u.length>=s&&_()},flush:_,destroy(){Y=!1,y!==null&&(clearInterval(y),y=null),document.removeEventListener("visibilitychange",h),window.removeEventListener("pagehide",k),_()}}}var Dn=1800*1e3;function Ae(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Mn(e=Dn,t){let n=new Map,r=`_snt_asgn${mt(t)}_`,o=(i,l)=>`${r}${encodeURIComponent(i)}:${encodeURIComponent(l)}`,s=i=>{let l=i.slice(r.length),u=l.indexOf(":");if(u<0)return null;try{return{componentId:decodeURIComponent(l.slice(0,u)),segment:decodeURIComponent(l.slice(u+1))}}catch(d){return null}},a=()=>{try{let i=[];for(let l=0;l<localStorage.length;l++){let u=localStorage.key(l);u!=null&&u.startsWith(r)&&i.push(u)}return i}catch(i){return[]}},c=i=>i.assignedAt+(i.ttlMs&&i.ttlMs>0?i.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let i of a())try{let l=localStorage.getItem(i);if(!l)continue;let u=JSON.parse(l);if(c(u)){localStorage.removeItem(i);continue}let d=s(i);if(!d)continue;n.set(Ae(d.componentId,d.segment),u)}catch(l){}})(),{get(i,l){let u=n.get(Ae(i,l));return u?c(u)?(n.delete(Ae(i,l)),null):u:null},set(i,l,u){let d=Ae(i,l);n.set(d,u);try{localStorage.setItem(o(i,l),JSON.stringify(u))}catch(m){}},invalidate(i){let l=`${encodeURIComponent(i)}:`;for(let u of[...n.keys()])u.startsWith(l)&&n.delete(u);for(let u of a()){let d=s(u);if((d==null?void 0:d.componentId)===i)try{localStorage.removeItem(u)}catch(m){}}},clear(){n.clear();for(let i of a())try{localStorage.removeItem(i)}catch(l){}}}}var Ee="_snt_snap:",jn=["low","medium","high"];function Ie(e){try{let t=localStorage.getItem(Ee+e);if(!t)return null;let n=JSON.parse(t);return!n||typeof n!="object"||n.v!==1||typeof n.persona!="string"||typeof n.band!="string"||!jn.includes(n.band)||typeof n.slots!="object"||n.slots===null||Array.isArray(n.slots)||!(n.layoutOrder===null||Array.isArray(n.layoutOrder))||typeof n.savedAt!="number"||!(n.slotConfig===void 0||typeof n.slotConfig=="object"&&n.slotConfig!==null&&!Array.isArray(n.slotConfig))?null:n}catch(t){return null}}function he(e,t){try{localStorage.setItem(Ee+e,JSON.stringify(t))}catch(n){}}var Ge="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",vt="[sentient] Local mode \u2014 decisions are simulated on-device and nothing is sent over the network. Add an API key to learn from real traffic.",ft=!1,ke=!1;function Nn(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function $n(e){var t;let n=ht({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),r=(t=n.getSessionId())!=null?t:"local",o=Nn(),s=Promise.resolve().then(()=>(pt(),dt)).then(i=>{let l=i;return l.LOCAL_ENGINE_AVAILABLE?(ft||(ft=!0,console.info(vt)),l):(ke||(ke=!0,console.error(Ge)),null)}).catch(()=>(ke||(ke=!0,console.error(Ge)),null)),a=null;function c(i){let l=document.documentElement;l.dataset.sentientPersona===void 0&&(l.dataset.sentientPersona=i.persona,l.dataset.sentientConfidence=se(i.confidence))}return{isLocal:!0,async decide(i){var l,u,d;let m=await s;if(!m)return null;let g=m.createLocalEngine({sessionId:r,forcedPersona:o}).decide(i);return a=me(I({},g),{layoutOrder:(u=(l=g.layoutOrder)!=null?l:a==null?void 0:a.layoutOrder)!=null?u:null,slots:I(I({},(d=a==null?void 0:a.slots)!=null?d:{}),g.slots)}),he(e.apiKey||"local",{v:1,persona:a.persona,band:se(a.confidence),slots:a.slots,layoutOrder:a.layoutOrder,savedAt:Date.now()}),c(g),g},getSlotResult(i){var l,u,d;return(d=(u=a==null?void 0:a.slots[i])!=null?u:(l=e.initialSlots)==null?void 0:l[i])!=null?d:null},getPersona(){return a?{persona:a.persona,confidence:a.confidence,band:se(a.confidence)}:null},async assign(i,l){var u;let d=await s;return!d||!l||l.length===0?l!=null&&l[0]?{variantId:l[0],assignmentTtlMs:0}:null:{variantId:(u=d.createLocalEngine({sessionId:r,forcedPersona:o}).decide({components:[{id:i,variantIds:l}]}).assignments[i])!=null?u:l[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function ye(e,t,n,r){let o=[];{let s=!1,a=[],c=()=>{if(s)return;let i=Date.now();for(a.push(i);a.length>0&&i-a[0]>500;)a.shift();a.length>=3&&(s=!0,e("rage_click"))};t.addEventListener("click",c),o.push(()=>t.removeEventListener("click",c))}{let s=!1,a=c=>{if(s||!(c.target instanceof Node)||!t.contains(c.target)&&t!==c.target)return;s=!0;let i=typeof window!="undefined"?window.getSelection():null,l=i?i.toString().length:0;e("text_copy",{selectionLength:l})};document.addEventListener("copy",a),o.push(()=>document.removeEventListener("copy",a))}{let s=!1,a=!1,c=null,i=()=>{c!==null&&(clearTimeout(c),c=null)},l=()=>{s||!a||(i(),c=setTimeout(()=>{!s&&a&&(s=!0,e("scroll_hesitation"))},3e3))},u=()=>{i(),l()},d=g=>{for(let b of g)a=b.intersectionRatio>.3,a?l():i()},m=new IntersectionObserver(d,{threshold:[.3]});m.observe(t),window.addEventListener("scroll",u,{passive:!0}),o.push(()=>{m.disconnect(),window.removeEventListener("scroll",u),i()})}if((r==null?void 0:r.tabLoss)!==!1){let s=!1,a=n!=null?n:Date.now(),c=()=>{if(s||document.visibilityState!=="hidden")return;let i=Date.now()-a;i<15e3&&(s=!0,e("tab_loss",{timeOnPage:i}))};document.addEventListener("visibilitychange",c),o.push(()=>document.removeEventListener("visibilitychange",c))}return()=>{for(let s of o)s()}}var bt="https://api.sentient-ui.com/v1/events",N=new Map,wt=null;function Ue(){return gt()}var ce={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}};function Kn(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,r]of t)n.startsWith("utm_")&&(e[n]=r);return e}catch(e){return{}}}function St(e){return e.replace(/\/events\/?$/,"")}function ae(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(e=>e==="1"||e==="yes")}function qe(e){var t;if(typeof window=="undefined")return;let n=e!=null?e:wt;if(!n){console.warn("[sentient] grantConsent() called before init()");return}let r=N.get(n);if(!r){console.warn("[sentient] grantConsent() called before init()");return}let{config:o,upgrade:s}=r;if(!s||o.respectDoNotTrack!==!1&&ae())return;let a=Oe(me(I({},o),{consent:!0}));s(a);let c=(t=N.get(n))==null?void 0:t.dispose;N.set(n,{config:me(I({},o),{consent:!0}),upgrade:null,dispose:c})}function Bn(e){var t;let n=St((t=e.ingestUrl)!=null?t:bt),r={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(c,i,l){try{let u=new URLSearchParams({componentId:c});for(let m of i!=null?i:[])u.append("variantIds[]",m);let d=await fetch(`${n}/winner?${u.toString()}`,{headers:r});return d.ok?{variantId:(await d.json()).variantId,assignmentTtlMs:0}:i!=null&&i[0]?{variantId:i[0],assignmentTtlMs:0}:null}catch(u){return i!=null&&i[0]?{variantId:i[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},s={track:c=>o.track(c),goal:(c,i,l,u)=>o.goal(c,i,l,u),componentGoal:(c,i,l)=>o.componentGoal(c,i,l),identify:c=>o.identify(c),getAssignment:(c,i)=>o.getAssignment(c,i),assign:(c,i,l,u)=>o.assign(c,i,l,u),decide:c=>o.decide(c),getSlotResult:c=>o.getSlotResult(c),getPersona:()=>o.getPersona(),fetchWeights:()=>o.fetchWeights(),getGraph:()=>o.getGraph(),dispose:()=>o.dispose(),destroy:()=>o.destroy()};function a(c){o=c}return{proxy:s,setInner:a}}function Oe(e){var t,n,r,o,s,a,c,i,l;if(typeof window=="undefined")return ce;wt=e.apiKey;let u=N.get(e.apiKey||"local");if(u!=null&&u.dispose)try{u.dispose()}catch(p){}let d=e.respectDoNotTrack!==!1&&ae(),m=e.consent===!1||d,g=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!g&&e.localMode!==!1)return m?(N.set(e.apiKey||"local",{config:e,upgrade:null}),ce):(N.set(e.apiKey||"local",{config:e,upgrade:null}),$n(e));if(m){if(e.preConsentBehavior==="statistical_winner"){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),ce;let{proxy:p,setInner:v}=Bn(e);return N.set(e.apiKey,{config:e,upgrade:d?null:v}),p}return N.set(e.apiKey,{config:e,upgrade:null}),ce}if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),ce;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),ce;let b=(t=e.ingestUrl)!=null?t:bt,w=Date.now(),A=ht({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),C=Mn(void 0,e.apiKey),S=Ln({ingestUrl:b,apiKey:e.apiKey}),E=St(b),j={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},H=st((n=navigator.userAgent)!=null?n:""),le=typeof window!="undefined"?window.location.origin:void 0,ne=at((r=document.referrer)!=null?r:"",le),_=(o=e.sessionSegment)!=null?o:`${H}:${ne}`,Y=new Map,y=new Map,h=null,k=p=>{for(let v of p)y.has(v.id)||y.set(v.id,Ke(v))};if(e.initialSlots)for(let[p,v]of Object.entries(e.initialSlots))y.set(p,v);let f=Ie(e.apiKey);if(f)for(let[p,v]of Object.entries(f.slots))y.has(p)||y.set(p,v);let x={low:.15,medium:.5,high:.85};if(e.initialPersona)h=I({},e.initialPersona);else{let p=document.documentElement.dataset;p.sentientPersona?h={persona:p.sentientPersona,confidence:(a=x[(s=p.sentientConfidence)!=null?s:"low"])!=null?a:.15}:f&&(h={persona:f.persona,confidence:(c=x[f.band])!=null?c:.15})}if(e.initialAssignments)for(let[p,v]of Object.entries(e.initialAssignments))C.set(p,_,{variantId:v,assignedAt:Date.now(),segment:_,confidence:1});let M=Promise.resolve(),z=A.getSessionId();if(z){let p=lt((i=document.referrer)!=null?i:""),v=I(I({sessionId:z,deviceClass:H,trafficSource:ne,referrerDomain:p,utmParams:Kn(),timeOfDay:ct(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:A.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||it((l=navigator.userAgent)!=null?l:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{M=fetch(`${E}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(v),headers:j}).then(T=>{T.status===402&&console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing")}).catch(()=>{})}catch(T){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:S});let G={goal(p,v={},T=1,J=0){let q=A.getSessionId();if(!q)return;let D=Ue();M.then(()=>{fetch(`${E}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:q,name:p,metadata:v,weight:T,stepIndex:J,goalId:D}),headers:j}).catch(()=>{})})},componentGoal(p,v,T){var J,q,D;let X=A.getSessionId();if(!X)return;let V=C.get(p,_),K=V?null:(J=y.get(p))!=null?J:null;if(!V&&K===null){e.debug&&console.warn(`[sentient] componentGoal("${p}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let re=V?V.variantId:ut(K),B={id:Ue(),sessionId:X,projectId:e.apiKey,componentId:p,variantId:re,eventType:"goal_achieved",goalType:v,payload:I({reward:(q=T==null?void 0:T.reward)!=null?q:1},(D=T==null?void 0:T.metadata)!=null?D:{}),timestamp:Date.now(),timeInSession:Date.now()-w};e.debug&&console.log("[sentient] componentGoal",B),M.then(()=>S.push(B))},identify(p){let v=A.getSessionId();v&&M.then(()=>{fetch(`${E}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:v,userId:p,ephemeral:A.isEphemeral()}),headers:j}).catch(()=>{})})},track(p){let v=A.getSessionId();if(!v)return;let T=me(I({},p),{id:Ue(),sessionId:v,timestamp:Date.now(),timeInSession:Date.now()-w});e.debug&&console.log("[sentient] track",T),M.then(()=>S.push(T))},getAssignment(p,v){return C.get(p,v)},async assign(p,v,T,J){let q=A.getSessionId();if(!q)return null;let D=C.get(p,_);if(D&&(v!=null&&v.length||D.content!==void 0)){let K=D.ttlMs&&D.ttlMs>0?Math.max(0,D.assignedAt+D.ttlMs-Date.now()):0;return{variantId:D.variantId,assignmentTtlMs:K,content:D.content}}let X=Y.get(p);if(X)return X;let V=(async()=>{await M;try{let K={sessionId:q,componentId:p,variantIds:v};J!==void 0?K.agentDataByVariant=J:T!==void 0&&(K.agentData=T);let re=await fetch(`${E}/assign`,{method:"POST",body:JSON.stringify(K),headers:j});if(!re.ok)return null;let B=await re.json();return C.set(p,_,I({variantId:B.variantId,assignedAt:Date.now(),segment:_,confidence:1,content:B.content},B.assignmentTtlMs&&B.assignmentTtlMs>0?{ttlMs:B.assignmentTtlMs}:{})),B}catch(K){return null}finally{Y.delete(p)}})();return Y.set(p,V),V},async decide(p){var v,T,J,q,D,X,V,K,re;let B=A.getSessionId();if(!B)return null;let pe=(v=p.slots)!=null?v:[];await M;try{let oe={sessionId:B};p.sections&&p.sections.length>0&&(oe.sections=p.sections.map(U=>({id:U}))),oe.components=(T=p.components)!=null?T:[],pe.length>0&&(oe.slots=pe.map($e)),p.slotsFrom==="registry"&&(oe.slotsFrom="registry"),p.v&&(oe.v=p.v);let He=await fetch(`${E}/decide`,{method:"POST",body:JSON.stringify(oe),headers:j});if(!He.ok)return k(pe),null;let R=await He.json(),fe={};for(let U of pe)fe[U.id]=(q=(J=R.slots)==null?void 0:J[U.id])!=null?q:Ke(U);if(R.slots)for(let[U,ge]of Object.entries(R.slots))U in fe||(fe[U]=ge);for(let[U,ge]of Object.entries(fe))y.set(U,ge);let Qt=h!=null&&h.persona!=="unknown";R.persona&&!(R.persona==="unknown"&&Qt)?h={persona:R.persona,confidence:(D=R.confidence)!=null?D:0}:h||(h={persona:"unknown",confidence:0});for(let[U,ge]of Object.entries((X=R.assignments)!=null?X:{}))C.set(U,_,{variantId:ge,assignedAt:Date.now(),segment:_,confidence:1});return he(e.apiKey,I({v:1,persona:h.persona,band:se(h.confidence),slots:Object.fromEntries(y),layoutOrder:(V=R.layoutOrder)!=null?V:null,savedAt:Date.now()},R.slotConfig?{slotConfig:R.slotConfig}:{})),I(I(I({layoutOrder:(K=R.layoutOrder)!=null?K:null,assignments:(re=R.assignments)!=null?re:{},slots:fe,persona:h.persona,confidence:h.confidence},R.slotConfig?{slotConfig:R.slotConfig}:{}),R.goals?{goals:R.goals}:{}),R.sectionMap?{sectionMap:R.sectionMap}:{})}catch(oe){return k(pe),null}},getSlotResult(p){var v;return(v=y.get(p))!=null?v:null},getPersona(){return h?{persona:h.persona,confidence:h.confidence,band:se(h.confidence)}:null},async fetchWeights(){var p;try{let v=await fetch(`${E}/weights`,{headers:j});return v.ok?(p=(await v.json()).components)!=null?p:[]:[]}catch(v){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var p;S.destroy(),((p=N.get(e.apiKey))==null?void 0:p.dispose)===G.dispose&&N.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var p;S.destroy(),A.destroy(),((p=N.get(e.apiKey))==null?void 0:p.dispose)===G.dispose&&N.delete(e.apiKey);try{localStorage.removeItem(Ee+e.apiKey),localStorage.removeItem(yt(e.apiKey))}catch(v){}e.debug&&console.log("[sentient] destroyed")}};if(N.set(e.apiKey,{config:e,upgrade:null,dispose:G.dispose}),e.debug){let p=window;p.__sentient&&(p.__sentient.client=G)}return G}var xt=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Un=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],Gn=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function qn(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function At(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,r]of Un)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of Gn)if(r.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function kt(e){var t,n;let r=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:qn(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function Et(e){return At(kt(e)).type}Se();var Ot="section, header, footer, nav, main > div, [data-sentient-section]";function Wn(e){var t;return((t=e.parentElement)==null?void 0:t.closest(Ot))!=null}function zn(e,t,n,r){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:r})}).catch(()=>{})}catch(o){}}var It=()=>{};function Ct(e,t){var n,r,o,s,a,c,i,l,u;let d=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!d||typeof IntersectionObserver=="undefined"||ae()||!t.apiKey)return It;let m=((r=t.apiBase)!=null?r:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),g=Array.from(d.querySelectorAll(Ot)).filter(y=>!Wn(y));if(g.length===0)return It;let b=new Map,w=new Map,A=new Map;for(let y of g){let h=y.getAttribute("data-sentient-type"),k=h&&xt.includes(h)?h:null,f=(s=k!=null?k:(o=t.typeOf)==null?void 0:o.call(t,y))!=null?s:Et(y),x=`nc-${f}`;b.set(y,x),w.set(x,f),k?A.set(x,"markup"):A.has(x)||A.set(x,"auto")}let C=(l=(i=(c=(a=d.defaultView)!=null?a:typeof window!="undefined"?window:void 0)==null?void 0:c.location)==null?void 0:i.pathname)!=null?l:"/";zn(t.apiKey,m,C,[...w.entries()].map(([y,h])=>{var k;return{componentId:y,semanticType:h,source:(k=A.get(y))!=null?k:"auto"}}));let S=new Map,E=y=>{let h=S.get(y);return h||(h={ms:0,scroll:0,enterAt:null,intersecting:!1},S.set(y,h)),h},j=new IntersectionObserver(y=>{for(let h of y){let k=b.get(h.target);if(!k)continue;let f=E(k);h.isIntersecting?(f.intersecting=!0,f.enterAt=Date.now(),h.intersectionRatio>f.scroll&&(f.scroll=h.intersectionRatio)):(f.intersecting=!1,f.enterAt!=null&&(f.ms+=Date.now()-f.enterAt,f.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let y of b.keys())j.observe(y);let H=()=>{let y=Date.now();for(let[h,k]of S)if(k.enterAt!=null&&(k.ms+=y-k.enterAt,k.enterAt=null),!(k.ms<=0)){try{e.track({projectId:t.apiKey,componentId:h,eventType:"dwell",payload:{dwell_time:Math.round(k.ms),scroll_depth:Number(k.scroll.toFixed(2))}})}catch(f){}k.ms=0}},le=()=>{if(d.hidden)H();else{let y=Date.now();for(let h of S.values())h.intersecting&&(h.enterAt=y)}},ne=()=>{H();try{j.disconnect()}catch(y){}};d.addEventListener("visibilitychange",le);let _=(u=d.defaultView)!=null?u:typeof window!="undefined"?window:void 0;_==null||_.addEventListener("pagehide",ne);let Y=[];return t.microSignals&&[...b.entries()].forEach(([y,h],k)=>{Y.push(ye((f,x={})=>{try{e.track({projectId:t.apiKey,componentId:h,eventType:"micro_signal",payload:I({signalType:f},x)})}catch(M){}},y,void 0,{tabLoss:k===0}))}),()=>{H(),d.removeEventListener("visibilitychange",le),_==null||_.removeEventListener("pagehide",ne);for(let y of Y)y();try{j.disconnect()}catch(y){}}}var Jn=["landing","ecommerce","saas","marketplace"];function Vn(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t=Object.entries(e);if(t.length<1||t.length>4)return null;let n={};for(let[r,o]of t){if(!Array.isArray(o)||o.length<2||o.length>6||!o.every(s=>typeof s=="string"))return null;n[r]=o}return n}function Fn(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function Ce(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.apiKey!="string"||!t.apiKey.startsWith("pk_"))return null;let n=Jn.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[s,a]of Object.entries(t.slots)){if(typeof a!="object"||a===null)continue;let c=a,i=Vn(c.dims);if(!i||c.target!==void 0&&typeof c.target!="string")continue;let l=c.arms!==void 0?Fn(c.arms):null,u={dims:i};typeof c.target=="string"&&(u.target=c.target),l&&(u.arms=l),r[s]=u}let o={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};return typeof t.consent=="boolean"&&(o.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(o.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(o.debug=!0),typeof t.registry=="boolean"&&(o.registry=t.registry),typeof t.editorSrc=="string"&&(o.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(o.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(o.sectionCapture=t.sectionCapture),o}function _t(e){var n,r,o;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(o=t==null?void 0:t.pathname)!=null?o:""}function Hn(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let r=((n=e.textContent)!=null?n:"").trim().toLowerCase(),o=t.text.trim().toLowerCase();if(!(r===o||r.startsWith(o)||o.startsWith(r)))return!1}return!0}function Rt(e,t){return!!(e!=null&&e.urlMatch)&&!_t(t).includes(e.urlMatch)}var Yn=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function Q(e,t){var o;if(e.urlMatch&&!_t(t).includes(e.urlMatch))return null;let n=[];if(e.id){let s=t.getElementById(e.id);n=s?[s]:[]}if(n.length===0&&((o=e.dataAttr)!=null&&o.name)&&Yn.test(e.dataAttr.name))try{let s=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${s}"]`))}catch(s){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(s){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!Hn(r,e.fingerprint)?null:r}var Tt={color:"color",background:"background",fontSize:"font-size",fontWeight:"font-weight",textAlign:"text-align",padding:"padding",margin:"margin",borderRadius:"border-radius",width:"width",height:"height",maxWidth:"max-width",border:"border",boxShadow:"box-shadow",opacity:"opacity",lineHeight:"line-height",letterSpacing:"letter-spacing",textTransform:"text-transform",gap:"gap",fontFamily:"font-family"},Zn=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function Pt(e){var t;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;for(let n of e.matchAll(/([A-Za-z-]*)\(/g))if(!Zn.test((t=n[1])!=null?t:""))return!1;return!0}var Lt=/^https:\/\//i,Dt=new Map,ee=null;function Xn(e){return e.replace(/["\\]/g,"\\$&")}function Qn(e){var t;(!ee||!ee.isConnected)&&(ee=e.querySelector("style[data-sentient-ops]"),ee||(ee=e.createElement("style"),ee.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(ee))),ee.textContent=[...Dt.entries()].map(([n,r])=>`[data-snt-e="${Xn(n)}"]{${r}}`).join(`
2
- `)}function Mt(e,t,n,r){var c;let o=!1,s=(c=t.moveBefore)!=null?c:t.moveAfter;if(s){let i=Q(s,r);!i||i===e||i.parentElement!==e.parentElement||!e.parentElement?o=!0:t.moveBefore?e.parentElement.insertBefore(e,i):e.parentElement.insertBefore(e,i.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&Lt.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&Lt.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let a=[];if(t.hidden&&a.push("display:none !important"),t.style)for(let[i,l]of Object.entries(t.style)){let u=Tt[i];u&&typeof l=="string"&&Pt(l)&&a.push(`${u}:${l.trim()} !important`)}return a.length>0&&(e.setAttribute("data-snt-e",n),Dt.set(n,a.join(";")),Qn(r)),{anchorMiss:o}}function _e(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function Re(e,t,n){var r;for(let[o,s]of Object.entries(t)){let a=e[o];if(!a||typeof a=="string")continue;let c=s.target?Array.from(n.querySelectorAll(s.target)):[n.documentElement];for(let i of c)for(let[l,u]of Object.entries(a))(r=s.dims[l])!=null&&r.includes(u)&&i.setAttribute(`data-${l}`,u)}}function Te(e,t,n){for(let[r,o]of Object.entries(t)){let s=e[r];if(typeof s!="string"||!o.arms||!o.arms.includes(s))continue;let a=o.target?Array.from(n.querySelectorAll(o.target)):[n.documentElement];for(let c of a)c.setAttribute("data-sentient-arm",s)}}function Pe(e,t,n,r){var a,c;let o=(a=r==null?void 0:r.contentAndOps)!=null?a:!0,s=[];for(let[i,l]of Object.entries(t)){if(Rt(l.locator,n))continue;let u;if(l.locator){let m=Q(l.locator,n);u=m?[m]:[]}else l.target?u=Array.from(n.querySelectorAll(l.target)):u=[n.documentElement];(l.locator||l.target)&&u.length===0&&s.push(i);let d=e[i];for(let m of u){if(d!==void 0)if(typeof d=="string")m.setAttribute("data-sentient-arm",d),o&&((c=r==null?void 0:r.onApplied)==null||c.call(r,i,d,m));else for(let[g,b]of Object.entries(d))m.setAttribute(`data-${g}`,b);o&&(typeof l.content=="string"&&(m.textContent=l.content),l.ops&&Mt(m,l.ops,i,n).anchorMiss&&!s.includes(i)&&s.push(i))}}return s}var er=800;function Le(e,t,n){let r=[];return n.forEach(({slotId:o,arm:s,el:a},c)=>{r.push(ye((m,g={})=>{try{e.track({projectId:t,componentId:o,variantId:s,eventType:"micro_signal",payload:ie({signalType:m},g)})}catch(b){}},a,void 0,{tabLoss:c===0}));let i=null,l=0,u=()=>{l=Date.now(),i=setTimeout(()=>{try{e.track({projectId:t,componentId:o,variantId:s,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-l}})}catch(m){}i=null},er)},d=()=>{i!==null&&(clearTimeout(i),i=null)};a.addEventListener("mouseenter",u),a.addEventListener("mouseleave",d),r.push(()=>{a.removeEventListener("mouseenter",u),a.removeEventListener("mouseleave",d),i!==null&&clearTimeout(i)})}),()=>{for(let o of r)o()}}function tr(e){var n,r,o;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(o=t==null?void 0:t.pathname)!=null?o:""}function nr(e,t){if(!e)return!1;if(e==="/")return t==="/";let n=e.endsWith("/")?e.slice(0,-1):e;return t===n||t.startsWith(`${n}/`)}function jt(e,t,n){var m;let r=new Set,o=g=>{if(!r.has(g.goalId)){r.add(g.goalId);try{g.slotId?t.componentGoal(g.slotId,g.goalId):t.goal(g.goalId)}catch(b){}}},s=e.filter(g=>g.event==="click"),a=e.filter(g=>g.event==="form_submit"),c=e.filter(g=>g.event==="url_reached"),i=(g,b)=>{if(!g.locator)return!1;let w=Q(g.locator,n);return!!w&&(w===b||w.contains(b))},l=g=>{let b=g.target;if(!(!b||typeof b.closest!="function"))for(let w of s)i(w,b)&&o(w)},u=g=>{let b=g.target;if(b)for(let w of a)i(w,b)&&o(w)},d=()=>{if(c.length===0)return;let g=tr(n);for(let b of c)b.urlPattern&&nr(b.urlPattern,g)&&o(b)};return n.addEventListener("click",l,!0),n.addEventListener("submit",u,!0),(m=n.defaultView)==null||m.addEventListener("popstate",d),d(),{checkUrl:d,teardown:()=>{var g;n.removeEventListener("click",l,!0),n.removeEventListener("submit",u,!0),(g=n.defaultView)==null||g.removeEventListener("popstate",d)}}}var Nt="__snt_editor_token";function $t(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(Nt):null}catch(e){return null}}function Kt(e){try{sessionStorage.setItem(Nt,e)}catch(t){}}var ze="0.12.0",Jt=5e3,rr=50,$=null,P=null,Z={},te=null,W=null,L=null,F=null,O=null,Bt=!1,We=null,De=null,Me=null,ve=!1,je=!1;function Vt(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function ue(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function de(e,t){return $?($.personaAttributes&&O&&_e(O.persona,O.band,e),Re(Z,$.slots,e),Te(Z,$.slots,e),te?Pe(Z,te,e,t):[]):[]}function or(e,t){var n;if(t.length!==0)try{let r=(n=e.apiBase)!=null?n:"https://api.sentient-ui.com";fetch(`${r}/v1/locator-miss`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify({slots:t})}).catch(()=>{})}catch(r){}}function be(){return!!($&&P&&$.sectionCapture!==!1&&($.consent!==!1||je)&&!ae())}function ir(){if(!P||!$||!be()||F)return;let e=[];de(document,{contentAndOps:ve,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),Ve();try{L==null||L(),L=Le(P,$.apiKey,e)}catch(t){}}function Ve(){if(typeof document=="undefined"||!be())return;let e;try{if(De&&De.length>0){let t=new Map;for(let n of De){if(n.urlMatch!==window.location.pathname)continue;let r=Q(n.locator,document);r&&t.set(r,n.type)}t.size>0&&(e=n=>{var r;return(r=t.get(n))!=null?r:null})}}catch(t){}try{F=Ct(P,ie({apiKey:$.apiKey,apiBase:$.apiBase,doc:document,microSignals:!0},e?{typeOf:e}:{})),Me=window.location.pathname}catch(t){}}function Fe(){try{let e=[];if(L==null||L(),L=null,de(document,{contentAndOps:ve,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),e.length>0&&be())try{L=Le(P,$.apiKey,e)}catch(t){}try{typeof window!="undefined"&&Me!==null&&window.location.pathname!==Me&&be()&&(F==null||F(),F=null,Ve())}catch(t){}}catch(e){}}function Ut(){We===null&&(We=setTimeout(()=>{We=null,Fe();try{W==null||W.checkUrl()}catch(e){}},rr))}function Gt(){if(!(Bt||typeof window=="undefined"||typeof history=="undefined")){Bt=!0;try{let e=t=>{let n=history[t];history[t]=function(r,o,s){let a=n.call(this,r,o,s!=null?s:null);return Ut(),a}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Ut)}catch(e){}}}function Je(e){let t={};for(let[n,r]of Object.entries(e.slots))t[n]=r.target?document.querySelectorAll(r.target).length:1;return t}function Ft(e){return new URLSearchParams(e).get("sentient_editor")}function sr(){try{let t=Array.from(document.getElementsByTagName("script")).find(n=>/snippet(\.global)?\.js/.test(n.src));if(t!=null&&t.src)return t.src.replace(/snippet(\.global)?\.js/,"editor.global.js")}catch(e){}return null}function ar(e,t){var n,r,o,s;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let i=document.createElement("meta");i.name="referrer",i.content="no-referrer",i.setAttribute("data-sentient-editor",""),((r=document.head)!=null?r:document.documentElement).appendChild(i)}catch(i){}let a=(o=e.editorSrc)!=null?o:sr();if(!a){Wt();return}let c=document.createElement("script");c.src=a,c.async=!0,c.onerror=()=>Wt(),((s=document.head)!=null?s:document.documentElement).appendChild(c)}catch(a){}}var qt="sentient-editor-load-notice";function Wt(){var e;try{if(typeof document=="undefined"||document.getElementById(qt))return;let t=document.createElement("div");t.id=qt,t.textContent="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.",Object.assign(t.style,{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",cursor:"pointer"}),t.addEventListener("click",()=>t.remove()),((e=document.body)!=null?e:document.documentElement).appendChild(t),setTimeout(()=>t.remove(),1e4)}catch(t){}}function Ht(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let o=r.indexOf(":"),s=o===-1?"":r.slice(0,o),a=o===-1?"":r.slice(o+1);if(!(!s||!a))if(a.includes("=")){let c={};for(let i of a.split(",")){let[l,u]=i.split("=");l&&u&&(c[l]=u)}Object.keys(c).length&&(n[s]=c)}else n[s]=a}return Object.keys(n).length?n:null}function Yt(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var zt="sentient-persona-preview-banner";function lr(e){var t;try{if(typeof document=="undefined"||document.getElementById(zt))return;let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),r=document.createElement("div");r.id=zt,r.setAttribute("role","status"),Object.assign(r.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",background:"#111827",color:"#fff",font:"13px/1 system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.14)"});let o=document.createElement("span");o.textContent=`Previewing as ${n}`;let s=document.createElement("button");s.type="button",s.textContent="Exit preview",Object.assign(s.style,{cursor:"pointer",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"inherit",padding:"4px 10px",borderRadius:"999px"}),s.addEventListener("click",()=>{try{let a=new URL(window.location.href);a.searchParams.delete("sentient_persona"),window.location.href=a.pathname+a.search+a.hash}catch(a){}}),r.appendChild(o),r.appendChild(s),((t=document.body)!=null?t:document.documentElement).appendChild(r)}catch(n){}}async function cr(e,t){var l,u,d,m,g,b,w,A,C;let n=(l=e.apiBase)!=null?l:"https://api.sentient-ui.com",o=((u=e.registry)!=null?u:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([S,E])=>({id:S,dims:E.dims}))},s=await Vt(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(o)}).then(S=>S.ok?S.json():null).catch(()=>null),Jt);if(!s){ue(e,"persona preview: explain unavailable \u2014 page left as-is");return}let a=s;Z=(d=a.slots)!=null?d:{},te=(m=a.slotConfig)!=null?m:null;let c=(w=(b=(g=a.personaAttributes)==null?void 0:g.persona)!=null?b:a.persona)!=null?w:t,i=(C=(A=a.personaAttributes)==null?void 0:A.confidence)!=null?C:"high";O={persona:c,band:i},de(document),ve=!0,Zt(e),lr(c)}function Zt(e){let t={goal(n,r){try{P==null||P.goal(n,r)}catch(o){}},componentGoal(n,r){try{P==null||P.componentGoal(n,r)}catch(o){}},grantConsent(){try{qe(e.apiKey)}catch(n){}je=!0;try{ir()}catch(n){}},revokeConsent(){try{F==null||F(),F=null,Me=null,L==null||L(),L=null,W==null||W.teardown(),W=null,je=!1,P==null||P.destroy()}catch(n){}},reapply:Fe,getState(){var n,r;return{apiKey:e.apiKey,persona:(n=O==null?void 0:O.persona)!=null?n:null,band:(r=O==null?void 0:O.band)!=null?r:null,slots:Z,matchCounts:Je(e),consent:e.consent!==!1}}};window.SentientSnippet=t}async function Xt(){var e,t,n,r,o;try{let s=Ce(window.sentient);if(!s)return;$=s,ve=!1,je=!1;let a=typeof window!="undefined"?Ft(window.location.search):null;if(a){Kt(a);try{let S=new URL(window.location.href);S.searchParams.delete("sentient_editor"),window.history.replaceState(null,"",S.pathname+S.search+S.hash)}catch(S){}}let c=a!=null?a:$t();if(c){ar(s,c),ue(s,"editor mode");return}let i=typeof window!="undefined"?Ht(window.location.search):null;if(i){Z=i,O=null,de(document),Gt(),ue(s,"preview mode",i);return}let l=typeof window!="undefined"?Yt(window.location.search):null;if(l){await cr(s,l),ue(s,"persona preview",l);return}let u=(e=s.registry)!=null?e:Object.keys(s.slots).length===0,d=Ie(s.apiKey);d&&(O={persona:d.persona,band:d.band},Z=d.slots,d.slotConfig&&(te=d.slotConfig),de(document,{contentAndOps:!1}));let m=Oe({apiKey:s.apiKey,context:s.context,consent:s.consent,preConsentBehavior:s.preConsentBehavior,debug:s.debug});P=m,Zt(s),Gt();let g=Object.entries(s.slots).map(([S,E])=>({id:S,dims:E.dims})),b=ze!=="0.0.0-dev"?{v:ze}:{},w=await Vt(m.decide(ie(ie({slots:g},b),u?{slotsFrom:"registry"}:{})),Jt);if(!w){ue(s,"decide timeout/null \u2014 snapshot state stands",Je(s));return}let A=m.getPersona();A?O={persona:A.persona,band:A.band}:w.persona&&(O={persona:w.persona,band:"low"}),Z=w.slots,u?te=(t=w.slotConfig)!=null?t:null:w.slotConfig&&(te=w.slotConfig);let C=[];if(or(s,de(document,{onApplied:(S,E,j)=>C.push({slotId:S,arm:E,el:j})})),ve=!0,w.goals&&w.goals.length>0&&s.consent!==!1&&P)try{W==null||W.teardown(),W=jt(w.goals,P,document)}catch(S){}if(De=(n=w.sectionMap)!=null?n:null,be()){Ve();try{L==null||L(),L=Le(P,s.apiKey,C)}catch(S){}}ue(s,"applied",{persona:O,slots:Z,matches:Je(s)}),he(s.apiKey,ie({v:1,persona:(r=O==null?void 0:O.persona)!=null?r:w.persona,band:(o=O==null?void 0:O.band)!=null?o:"low",slots:w.slots,layoutOrder:w.layoutOrder,savedAt:Date.now()},te?{slotConfig:te}:{}))}catch(s){}}if(typeof window!="undefined"&&window.sentient){let e=window;e.__sentientInitialized||(e.__sentientInitialized=!0,Xt())}return on(ur);})();
1
+ "use strict";var SentientSnippet=(()=>{var we=Object.defineProperty;var en=Object.getOwnPropertyDescriptor;var tn=Object.getOwnPropertyNames,Ye=Object.getOwnPropertySymbols;var Ze=Object.prototype.hasOwnProperty,nn=Object.prototype.propertyIsEnumerable;var Xe=(e,t,n)=>t in e?we(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))Ze.call(t,n)&&Xe(e,n,t[n]);if(Ye)for(var n of Ye(t))nn.call(t,n)&&Xe(e,n,t[n]);return e};var Qe=(e,t)=>()=>(e&&(t=e(e=0)),t);var et=(e,t)=>{for(var n in t)we(e,n,{get:t[n],enumerable:!0})},rn=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of tn(t))!Ze.call(e,l)&&l!==n&&we(e,l,{get:()=>t[l],enumerable:!(r=en(t,l))||r.enumerable});return e};var on=e=>rn(we({},"__esModule",{value:!0}),e);var sn,an,ln,tt,cn,un,nt,O,ge,Se=Qe(()=>{"use strict";sn=Object.defineProperty,an=Object.defineProperties,ln=Object.getOwnPropertyDescriptors,tt=Object.getOwnPropertySymbols,cn=Object.prototype.hasOwnProperty,un=Object.prototype.propertyIsEnumerable,nt=(e,t,n)=>t in e?sn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,O=(e,t)=>{for(var n in t||(t={}))cn.call(t,n)&&nt(e,n,t[n]);if(tt)for(var n of tt(t))un.call(t,n)&&nt(e,n,t[n]);return e},ge=(e,t)=>an(e,ln(t))});var dt={};et(dt,{LOCAL_ENGINE_AVAILABLE:()=>fn,createLocalEngine:()=>gn});function gn(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var fn,pt=Qe(()=>{"use strict";fn=!1});var pr={};et(pr,{applyPersonaAttributes:()=>_e,applyRegistrySlots:()=>Re,applySlotArms:()=>Pe,applySlotAttributes:()=>Te,parseEditorToken:()=>Ft,parsePersonaPreview:()=>Yt,parsePreview:()=>Ht,parseSnippetConfig:()=>Ce,reapply:()=>Fe,run:()=>Zt,version:()=>ze});Se();function xe(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function rt(e){if(e.length===0)return null;let t={};for(let n of e.split("|")){let r=n.indexOf("=");if(r<=0||r!==n.lastIndexOf("=")||r===n.length-1)return null;let l=n.slice(0,r);if(l in t)return null;t[l]=n.slice(r+1)}return t}function Ne(e){var t,n,r;if(e.arms)return typeof e.baseline=="string"?e.baseline:(t=e.arms[0])!=null?t:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return xe(e.baseline);if(typeof e.baseline=="string")return e.baseline;let l={};for(let[o,s]of Object.entries((n=e.dims)!=null?n:{}))l[o]=(r=s[0])!=null?r:"";return xe(l)}function ot(e,t){var n,r;return e.dims!=null?(r=(n=rt(t))!=null?n:rt(Ne(e)))!=null?r:{}:t}function se(e){return e>=.3?e<.7?"medium":"high":"low"}var dn=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function it(e){return pn(e)!==null}function pn(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=dn.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function st(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function at(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(l){}let r=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(n){return"direct"}}function lt(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function ct(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function $e(e){return O(O(O({id:e.id},e.arms?{arms:[...e.arms]}:{}),e.dims?{dims:Object.fromEntries(Object.entries(e.dims).map(([t,n])=>[t,[...n]]))}:{}),e.baseline!==void 0?{baseline:e.baseline}:{})}function Be(e){let t=$e(e);return ot(t,Ne(t))}function ut(e){return typeof e=="string"?e:xe(e)}Se();function gt(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}try{if(typeof crypto!="undefined"&&typeof crypto.getRandomValues=="function"){let e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t="";for(let n=0;n<16;n++)t+=e[n].toString(16).padStart(2,"0"),(n===3||n===5||n===7||n===9)&&(t+="-");return t}}catch(e){}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function mt(e){return e?`_${e.slice(0,12)}`:""}var mn="_snt_uid",hn=365,yn="_snt_uid";function vn(){return gt()}function bn(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function wn(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function Sn(e){try{return localStorage.getItem(e)}catch(t){return null}}function xn(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function An(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function kn(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function In(e){try{sessionStorage.removeItem(e)}catch(t){}}function En(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function On(e){try{localStorage.removeItem(e)}catch(t){}}function Cn(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var _n={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ht(e){var t,n,r,l,o,s;if(typeof window=="undefined")return _n;let u=mt(e==null?void 0:e.apiKey),i=(t=e==null?void 0:e.cookieName)!=null?t:`${mn}${u}`,a=`${yn}${u}`,c=((n=e==null?void 0:e.cookieTTLDays)!=null?n:hn)*24*60*60,d=_=>_&&_.length>0?_:null,m=(s=(o=(l=(r=d(bn(i)))!=null?r:d(Sn(a)))!=null?l:d(An(a)))!=null?o:d(e==null?void 0:e.ssrSessionId))!=null?s:vn();wn(i,m,c);let g=xn(a,m),b=En(i),w=g?!1:kn(a,m),A=!g&&!b&&!w;return{getSessionId:()=>m,isEphemeral:()=>A,destroy:()=>{m=null,Cn(i),On(a),In(a)}}}function yt(e){return`_snt_retry_${e.slice(0,12)}`}var Tn={push:()=>{},flush:()=>{},destroy:()=>{}};function Pn(e,t){try{let n=localStorage.getItem(t);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?(localStorage.removeItem(t),r.slice(-e)):[]}catch(n){return[]}}function Ke(e,t,n){try{let r=(()=>{try{let s=localStorage.getItem(n);if(!s)return[];let u=JSON.parse(s);return Array.isArray(u)?u:[]}catch(s){return[]}})(),l=new Map;for(let s of r)l.set(s.id,s);for(let s of e)l.set(s.id,s);let o=[...l.values()].slice(-t);localStorage.setItem(n,JSON.stringify(o))}catch(r){}}function Rn(e,t){try{let n=localStorage.getItem(t);if(!n)return;let r=JSON.parse(n);if(!Array.isArray(r))return;let l=new Set(e),o=r.filter(s=>!l.has(s.id));if(o.length===r.length)return;o.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(o))}catch(n){}}function Ln(e){var t,n,r;if(typeof window=="undefined")return Tn;let l=(t=e.flushIntervalMs)!=null?t:5e3,o=(n=e.maxBatchSize)!=null?n:20,s=(r=e.maxRetrySize)!=null?r:100,u=e.ingestUrl,i=e.apiKey,a=yt(i),c=[],d=new Set,m=[],g=f=>{for(let x of f)b.delete(x),!d.has(x)&&(d.add(x),m.push(x));for(;m.length>500;){let x=m.shift();x&&d.delete(x)}Rn(f,a)},b=new Set,w=f=>{d.has(f.id)||b.has(f.id)||(b.add(f.id),c.push(f))},A=f=>{for(let x of f)d.has(x.id)||(b.add(x.id),c.push(x))},_=Pn(s,a);for(let f of _)w(f);let S=0,I=0,N=f=>{if(f.length===0)return;let x=JSON.stringify(f),j=f.map(p=>p.id),J;try{J=fetch(u,{method:"POST",keepalive:!0,body:x,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}})}catch(p){Ke(f,s,a),A(f),I++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(I,6));return}let q=p=>{if(p.ok||p.status>=400&&p.status<500&&p.status!==429){g(j),I=0,S=0;return}Ke(f,s,a),A(f),I++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(I,6))};J instanceof Promise?J.then(q).catch(()=>{Ke(f,s,a),A(f),I++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(I,6))}):q(J)},Y=typeof TextEncoder!="undefined"?new TextEncoder:null,le=f=>Y?Y.encode(f).length:f.length,re=f=>{let x=[],j=2;for(let J of f){let q=le(JSON.stringify(J))+1;if(x.length>0&&j+q>57344||x.length>=o)break;x.push(J),j+=q}return x},T=()=>{try{if(Date.now()<S)return;for(;c.length>0&&!(Date.now()<S);){let f=c.filter(j=>!d.has(j.id));if(c.length=0,f.length===0)break;let x=re(f);if(x.length===0)break;x.length<f.length&&c.push(...f.slice(x.length)),N(x)}}catch(f){}},X=!0,v=null;v=setInterval(()=>{X&&T()},l);let h=()=>{document.visibilityState==="hidden"&&T()},k=()=>{T()};return document.addEventListener("visibilitychange",h),window.addEventListener("pagehide",k),{push(f){w(f),c.length>=o&&T()},flush:T,destroy(){X=!1,v!==null&&(clearInterval(v),v=null),document.removeEventListener("visibilitychange",h),window.removeEventListener("pagehide",k),T()}}}var Dn=1800*1e3;function Ae(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Mn(e=Dn,t){let n=new Map,r=`_snt_asgn${mt(t)}_`,l=(i,a)=>`${r}${encodeURIComponent(i)}:${encodeURIComponent(a)}`,o=i=>{let a=i.slice(r.length),c=a.indexOf(":");if(c<0)return null;try{return{componentId:decodeURIComponent(a.slice(0,c)),segment:decodeURIComponent(a.slice(c+1))}}catch(d){return null}},s=()=>{try{let i=[];for(let a=0;a<localStorage.length;a++){let c=localStorage.key(a);c!=null&&c.startsWith(r)&&i.push(c)}return i}catch(i){return[]}},u=i=>i.assignedAt+(i.ttlMs&&i.ttlMs>0?i.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let i of s())try{let a=localStorage.getItem(i);if(!a)continue;let c=JSON.parse(a);if(u(c)){localStorage.removeItem(i);continue}let d=o(i);if(!d)continue;n.set(Ae(d.componentId,d.segment),c)}catch(a){}})(),{get(i,a){let c=n.get(Ae(i,a));return c?u(c)?(n.delete(Ae(i,a)),null):c:null},set(i,a,c){let d=Ae(i,a);n.set(d,c);try{localStorage.setItem(l(i,a),JSON.stringify(c))}catch(m){}},invalidate(i){let a=`${encodeURIComponent(i)}:`;for(let c of[...n.keys()])c.startsWith(a)&&n.delete(c);for(let c of s()){let d=o(c);if((d==null?void 0:d.componentId)===i)try{localStorage.removeItem(c)}catch(m){}}},clear(){n.clear();for(let i of s())try{localStorage.removeItem(i)}catch(a){}}}}var Ie="_snt_snap:",jn=["low","medium","high"];function Ee(e){try{let t=localStorage.getItem(Ie+e);if(!t)return null;let n=JSON.parse(t);return!n||typeof n!="object"||n.v!==1||typeof n.persona!="string"||typeof n.band!="string"||!jn.includes(n.band)||typeof n.slots!="object"||n.slots===null||Array.isArray(n.slots)||!(n.layoutOrder===null||Array.isArray(n.layoutOrder))||typeof n.savedAt!="number"||!(n.slotConfig===void 0||typeof n.slotConfig=="object"&&n.slotConfig!==null&&!Array.isArray(n.slotConfig))?null:n}catch(t){return null}}function he(e,t){try{localStorage.setItem(Ie+e,JSON.stringify(t))}catch(n){}}var Ge="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",vt="[sentient] Local mode \u2014 decisions are simulated on-device and nothing is sent over the network. Add an API key to learn from real traffic.",ft=!1,ke=!1;function Nn(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function $n(e){var t;let n=ht({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),r=(t=n.getSessionId())!=null?t:"local",l=Nn(),o=Promise.resolve().then(()=>(pt(),dt)).then(i=>{let a=i;return a.LOCAL_ENGINE_AVAILABLE?(ft||(ft=!0,console.info(vt)),a):(ke||(ke=!0,console.error(Ge)),null)}).catch(()=>(ke||(ke=!0,console.error(Ge)),null)),s=null;function u(i){let a=document.documentElement;a.dataset.sentientPersona===void 0&&(a.dataset.sentientPersona=i.persona,a.dataset.sentientConfidence=se(i.confidence))}return{isLocal:!0,async decide(i){var a,c,d;let m=await o;if(!m)return null;let g=m.createLocalEngine({sessionId:r,forcedPersona:l}).decide(i);return s=ge(O({},g),{layoutOrder:(c=(a=g.layoutOrder)!=null?a:s==null?void 0:s.layoutOrder)!=null?c:null,slots:O(O({},(d=s==null?void 0:s.slots)!=null?d:{}),g.slots)}),he(e.apiKey||"local",{v:1,persona:s.persona,band:se(s.confidence),slots:s.slots,layoutOrder:s.layoutOrder,savedAt:Date.now()}),u(g),g},getSlotResult(i){var a,c,d;return(d=(c=s==null?void 0:s.slots[i])!=null?c:(a=e.initialSlots)==null?void 0:a[i])!=null?d:null},getPersona(){return s?{persona:s.persona,confidence:s.confidence,band:se(s.confidence)}:null},async assign(i,a){var c;let d=await o;return!d||!a||a.length===0?a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null:{variantId:(c=d.createLocalEngine({sessionId:r,forcedPersona:l}).decide({components:[{id:i,variantIds:a}]}).assignments[i])!=null?c:a[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function ye(e,t,n,r){let l=[];{let o=!1,s=[],u=()=>{if(o)return;let i=Date.now();for(s.push(i);s.length>0&&i-s[0]>500;)s.shift();s.length>=3&&(o=!0,e("rage_click"))};t.addEventListener("click",u),l.push(()=>t.removeEventListener("click",u))}{let o=!1,s=u=>{if(o||!(u.target instanceof Node)||!t.contains(u.target)&&t!==u.target)return;o=!0;let i=typeof window!="undefined"?window.getSelection():null,a=i?i.toString().length:0;e("text_copy",{selectionLength:a})};document.addEventListener("copy",s),l.push(()=>document.removeEventListener("copy",s))}{let o=!1,s=!1,u=null,i=()=>{u!==null&&(clearTimeout(u),u=null)},a=()=>{o||!s||(i(),u=setTimeout(()=>{!o&&s&&(o=!0,e("scroll_hesitation"))},3e3))},c=()=>{i(),a()},d=g=>{for(let b of g)s=b.intersectionRatio>.3,s?a():i()},m=new IntersectionObserver(d,{threshold:[.3]});m.observe(t),window.addEventListener("scroll",c,{passive:!0}),l.push(()=>{m.disconnect(),window.removeEventListener("scroll",c),i()})}if((r==null?void 0:r.tabLoss)!==!1){let o=!1,s=n!=null?n:Date.now(),u=()=>{if(o||document.visibilityState!=="hidden")return;let i=Date.now()-s;i<15e3&&(o=!0,e("tab_loss",{timeOnPage:i}))};document.addEventListener("visibilitychange",u),l.push(()=>document.removeEventListener("visibilitychange",u))}return()=>{for(let o of l)o()}}var bt="https://api.sentient-ui.com/v1/events",K=new Map,wt=null;function Bn(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}function Ue(){return gt()}var me={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}};function Kn(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,r]of t)n.startsWith("utm_")&&(e[n]=r);return e}catch(e){return{}}}function St(e){return e.replace(/\/events\/?$/,"")}function ae(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(e=>e==="1"||e==="yes")}function qe(e){var t;if(typeof window=="undefined")return;let n=e!=null?e:wt;if(!n){console.warn("[sentient] grantConsent() called before init()");return}let r=K.get(n);if(!r){console.warn("[sentient] grantConsent() called before init()");return}let{config:l,upgrade:o}=r;if(!o||l.respectDoNotTrack!==!1&&ae())return;let s=Oe(ge(O({},l),{consent:!0}));o(s);let u=(t=K.get(n))==null?void 0:t.dispose;K.set(n,{config:ge(O({},l),{consent:!0}),upgrade:null,dispose:u})}function Un(e){var t;let n=e.preConsentBehavior==="statistical_winner",r=St((t=e.ingestUrl)!=null?t:bt),l={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(i,a,c){if(!n)return null;try{let d=new URLSearchParams({componentId:i});for(let g of a!=null?a:[])d.append("variantIds[]",g);let m=await fetch(`${r}/winner?${d.toString()}`,{headers:l});return m.ok?{variantId:(await m.json()).variantId,assignmentTtlMs:0}:a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}catch(d){return a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},s={track:i=>o.track(i),goal:((i,a,c,d)=>o.goal(i,a,c,d)),componentGoal:(i,a,c)=>o.componentGoal(i,a,c),identify:i=>o.identify(i),getAssignment:(i,a)=>o.getAssignment(i,a),assign:(i,a,c,d)=>o.assign(i,a,c,d),decide:i=>o.decide(i),getSlotResult:i=>o.getSlotResult(i),getPersona:()=>o.getPersona(),fetchWeights:()=>o.fetchWeights(),getGraph:()=>o.getGraph(),dispose:()=>o.dispose(),destroy:()=>o.destroy()};function u(i){o=i}return{proxy:s,setInner:u}}function Oe(e){var t,n,r,l,o,s,u,i,a;if(typeof window=="undefined")return me;wt=e.apiKey;let c=K.get(e.apiKey||"local");if(c!=null&&c.dispose)try{c.dispose()}catch(p){}let d=e.respectDoNotTrack!==!1&&ae(),m=e.consent===!1||d,g=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!g&&e.localMode!==!1)return m?(K.set(e.apiKey||"local",{config:e,upgrade:null}),me):(K.set(e.apiKey||"local",{config:e,upgrade:null}),$n(e));if(m){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return e.preConsentBehavior==="statistical_winner"&&console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),K.set(e.apiKey,{config:e,upgrade:null}),me;let{proxy:p,setInner:y}=Un(e);return K.set(e.apiKey,{config:e,upgrade:d?null:y}),p}if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),me;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),me;let b=(t=e.ingestUrl)!=null?t:bt,w=Date.now(),A=ht({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),_=Mn(void 0,e.apiKey),S=Ln({ingestUrl:b,apiKey:e.apiKey}),I=St(b),N={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},Y=st((n=navigator.userAgent)!=null?n:""),le=typeof window!="undefined"?window.location.origin:void 0,re=at((r=document.referrer)!=null?r:"",le),T=(l=e.sessionSegment)!=null?l:`${Y}:${re}`,X=new Map,v=new Map,h=null,k=p=>{for(let y of p)v.has(y.id)||v.set(y.id,Be(y))};if(e.initialSlots)for(let[p,y]of Object.entries(e.initialSlots))v.set(p,y);let f=Ee(e.apiKey);if(f)for(let[p,y]of Object.entries(f.slots))v.has(p)||v.set(p,y);let x={low:.15,medium:.5,high:.85};if(e.initialPersona)h=O({},e.initialPersona);else{let p=document.documentElement.dataset;p.sentientPersona?h={persona:p.sentientPersona,confidence:(s=x[(o=p.sentientConfidence)!=null?o:"low"])!=null?s:.15}:f&&(h={persona:f.persona,confidence:(u=x[f.band])!=null?u:.15})}if(e.initialAssignments)for(let[p,y]of Object.entries(e.initialAssignments))_.set(p,T,{variantId:y,assignedAt:Date.now(),segment:T,confidence:1});let j=Promise.resolve(),J=A.getSessionId();if(J){let p=lt((i=document.referrer)!=null?i:""),y=O(O({sessionId:J,deviceClass:Y,trafficSource:re,referrerDomain:p,utmParams:Kn(),timeOfDay:ct(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:A.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||it((a=navigator.userAgent)!=null?a:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{j=fetch(`${I}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(y),headers:N}).then(E=>{E.status===402&&console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing")}).catch(()=>{})}catch(E){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:S});let q={goal(p,y={},E=1,F=0){var W,D,z;let B=A.getSessionId();if(!B)return;let P=Bn(y)?y:{metadata:y},Z=Ue(),$={sessionId:B,name:p,metadata:(W=P.metadata)!=null?W:{},weight:(D=P.weight)!=null?D:E,stepIndex:(z=P.stepIndex)!=null?z:F,goalId:Z,value:P.value,currency:P.currency,externalId:P.externalId};j.then(()=>{fetch(`${I}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify($),headers:N}).catch(()=>{})})},componentGoal(p,y,E){var F,W,D;let z=A.getSessionId();if(!z)return;let B=_.get(p,T),P=B?null:(F=v.get(p))!=null?F:null;if(!B&&P===null){e.debug&&console.warn(`[sentient] componentGoal("${p}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let Z=B?B.variantId:ut(P),$={id:Ue(),sessionId:z,projectId:e.apiKey,componentId:p,variantId:Z,eventType:"goal_achieved",goalType:y,payload:O({reward:(W=E==null?void 0:E.reward)!=null?W:1,goalValue:E==null?void 0:E.value,currency:E==null?void 0:E.currency},(D=E==null?void 0:E.metadata)!=null?D:{}),timestamp:Date.now(),timeInSession:Date.now()-w};e.debug&&console.log("[sentient] componentGoal",$),j.then(()=>S.push($))},identify(p){let y=A.getSessionId();y&&j.then(()=>{fetch(`${I}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:y,userId:p,ephemeral:A.isEphemeral()}),headers:N}).catch(()=>{})})},track(p){let y=A.getSessionId();if(!y)return;let E=ge(O({},p),{id:Ue(),sessionId:y,timestamp:Date.now(),timeInSession:Date.now()-w});e.debug&&console.log("[sentient] track",E),j.then(()=>S.push(E))},getAssignment(p,y){return _.get(p,y)},async assign(p,y,E,F){let W=A.getSessionId();if(!W)return null;let D=_.get(p,T);if(D&&(y!=null&&y.length||D.content!==void 0)){let P=D.ttlMs&&D.ttlMs>0?Math.max(0,D.assignedAt+D.ttlMs-Date.now()):0;return{variantId:D.variantId,assignmentTtlMs:P,content:D.content}}let z=X.get(p);if(z)return z;let B=(async()=>{await j;try{let P={sessionId:W,componentId:p,variantIds:y};F!==void 0?P.agentDataByVariant=F:E!==void 0&&(P.agentData=E);let Z=await fetch(`${I}/assign`,{method:"POST",body:JSON.stringify(P),headers:N});if(!Z.ok)return null;let $=await Z.json();return _.set(p,T,O({variantId:$.variantId,assignedAt:Date.now(),segment:T,confidence:1,content:$.content},$.assignmentTtlMs&&$.assignmentTtlMs>0?{ttlMs:$.assignmentTtlMs}:{})),$}catch(P){return null}finally{X.delete(p)}})();return X.set(p,B),B},async decide(p){var y,E,F,W,D,z,B,P,Z;let $=A.getSessionId();if(!$)return null;let de=(y=p.slots)!=null?y:[];await j;try{let oe={sessionId:$};p.sections&&p.sections.length>0&&(oe.sections=p.sections.map(G=>({id:G}))),oe.components=(E=p.components)!=null?E:[],de.length>0&&(oe.slots=de.map($e)),p.slotsFrom==="registry"&&(oe.slotsFrom="registry"),p.v&&(oe.v=p.v);let He=await fetch(`${I}/decide`,{method:"POST",body:JSON.stringify(oe),headers:N});if(!He.ok)return k(de),null;let R=await He.json(),pe={};for(let G of de)pe[G.id]=(W=(F=R.slots)==null?void 0:F[G.id])!=null?W:Be(G);if(R.slots)for(let[G,fe]of Object.entries(R.slots))G in pe||(pe[G]=fe);for(let[G,fe]of Object.entries(pe))v.set(G,fe);let Qt=h!=null&&h.persona!=="unknown";R.persona&&!(R.persona==="unknown"&&Qt)?h={persona:R.persona,confidence:(D=R.confidence)!=null?D:0}:h||(h={persona:"unknown",confidence:0});for(let[G,fe]of Object.entries((z=R.assignments)!=null?z:{}))_.set(G,T,{variantId:fe,assignedAt:Date.now(),segment:T,confidence:1});return he(e.apiKey,O({v:1,persona:h.persona,band:se(h.confidence),slots:Object.fromEntries(v),layoutOrder:(B=R.layoutOrder)!=null?B:null,savedAt:Date.now()},R.slotConfig?{slotConfig:R.slotConfig}:{})),O(O(O({layoutOrder:(P=R.layoutOrder)!=null?P:null,assignments:(Z=R.assignments)!=null?Z:{},slots:pe,persona:h.persona,confidence:h.confidence},R.slotConfig?{slotConfig:R.slotConfig}:{}),R.goals?{goals:R.goals}:{}),R.sectionMap?{sectionMap:R.sectionMap}:{})}catch(oe){return k(de),null}},getSlotResult(p){var y;return(y=v.get(p))!=null?y:null},getPersona(){return h?{persona:h.persona,confidence:h.confidence,band:se(h.confidence)}:null},async fetchWeights(){var p;try{let y=await fetch(`${I}/weights`,{headers:N});return y.ok?(p=(await y.json()).components)!=null?p:[]:[]}catch(y){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var p;S.destroy(),((p=K.get(e.apiKey))==null?void 0:p.dispose)===q.dispose&&K.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var p;S.destroy(),A.destroy(),((p=K.get(e.apiKey))==null?void 0:p.dispose)===q.dispose&&K.delete(e.apiKey);try{localStorage.removeItem(Ie+e.apiKey),localStorage.removeItem(yt(e.apiKey))}catch(y){}e.debug&&console.log("[sentient] destroyed")}};if(K.set(e.apiKey,{config:e,upgrade:null,dispose:q.dispose}),e.debug){let p=window;p.__sentient&&(p.__sentient.client=q)}return q}var xt=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Gn=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],qn=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function Wn(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function At(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,r]of Gn)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of qn)if(r.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function kt(e){var t,n;let r=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:Wn(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function It(e){return At(kt(e)).type}Se();var Ot="section, header, footer, nav, main > div, [data-sentient-section]";function zn(e){var t;return((t=e.parentElement)==null?void 0:t.closest(Ot))!=null}function Vn(e,t,n,r){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:r})}).catch(()=>{})}catch(l){}}var Et=()=>{};function Ct(e,t){var n,r,l,o,s,u,i,a,c;let d=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!d||typeof IntersectionObserver=="undefined"||ae()||!t.apiKey)return Et;let m=((r=t.apiBase)!=null?r:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),g=Array.from(d.querySelectorAll(Ot)).filter(v=>!zn(v));if(g.length===0)return Et;let b=new Map,w=new Map,A=new Map;for(let v of g){let h=v.getAttribute("data-sentient-type"),k=h&&xt.includes(h)?h:null,f=(o=k!=null?k:(l=t.typeOf)==null?void 0:l.call(t,v))!=null?o:It(v),x=`nc-${f}`;b.set(v,x),w.set(x,f),k?A.set(x,"markup"):A.has(x)||A.set(x,"auto")}let _=(a=(i=(u=(s=d.defaultView)!=null?s:typeof window!="undefined"?window:void 0)==null?void 0:u.location)==null?void 0:i.pathname)!=null?a:"/";Vn(t.apiKey,m,_,[...w.entries()].map(([v,h])=>{var k;return{componentId:v,semanticType:h,source:(k=A.get(v))!=null?k:"auto"}}));let S=new Map,I=v=>{let h=S.get(v);return h||(h={ms:0,scroll:0,enterAt:null,intersecting:!1},S.set(v,h)),h},N=new IntersectionObserver(v=>{for(let h of v){let k=b.get(h.target);if(!k)continue;let f=I(k);h.isIntersecting?(f.intersecting=!0,f.enterAt=Date.now(),h.intersectionRatio>f.scroll&&(f.scroll=h.intersectionRatio)):(f.intersecting=!1,f.enterAt!=null&&(f.ms+=Date.now()-f.enterAt,f.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let v of b.keys())N.observe(v);let Y=()=>{let v=Date.now();for(let[h,k]of S)if(k.enterAt!=null&&(k.ms+=v-k.enterAt,k.enterAt=null),!(k.ms<=0)){try{e.track({projectId:t.apiKey,componentId:h,eventType:"dwell",payload:{dwell_time:Math.round(k.ms),scroll_depth:Number(k.scroll.toFixed(2))}})}catch(f){}k.ms=0}},le=()=>{if(d.hidden)Y();else{let v=Date.now();for(let h of S.values())h.intersecting&&(h.enterAt=v)}},re=()=>{Y();try{N.disconnect()}catch(v){}};d.addEventListener("visibilitychange",le);let T=(c=d.defaultView)!=null?c:typeof window!="undefined"?window:void 0;T==null||T.addEventListener("pagehide",re);let X=[];return t.microSignals&&[...b.entries()].forEach(([v,h],k)=>{X.push(ye((f,x={})=>{try{e.track({projectId:t.apiKey,componentId:h,eventType:"micro_signal",payload:O({signalType:f},x)})}catch(j){}},v,void 0,{tabLoss:k===0}))}),()=>{Y(),d.removeEventListener("visibilitychange",le),T==null||T.removeEventListener("pagehide",re);for(let v of X)v();try{N.disconnect()}catch(v){}}}var Jn=["landing","ecommerce","saas","marketplace"];function Fn(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t=Object.entries(e);if(t.length<1||t.length>4)return null;let n={};for(let[r,l]of t){if(!Array.isArray(l)||l.length<2||l.length>6||!l.every(o=>typeof o=="string"))return null;n[r]=l}return n}function Hn(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function Ce(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.apiKey!="string"||!t.apiKey.startsWith("pk_"))return null;let n=Jn.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[o,s]of Object.entries(t.slots)){if(typeof s!="object"||s===null)continue;let u=s,i=Fn(u.dims);if(!i||u.target!==void 0&&typeof u.target!="string")continue;let a=u.arms!==void 0?Hn(u.arms):null,c={dims:i};typeof u.target=="string"&&(c.target=u.target),a&&(c.arms=a),r[o]=c}let l={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};return typeof t.consent=="boolean"&&(l.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(l.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(l.debug=!0),typeof t.registry=="boolean"&&(l.registry=t.registry),typeof t.editorSrc=="string"&&(l.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(l.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(l.sectionCapture=t.sectionCapture),l}function _t(e){var n,r,l;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(l=t==null?void 0:t.pathname)!=null?l:""}function Yn(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let r=((n=e.textContent)!=null?n:"").trim().toLowerCase(),l=t.text.trim().toLowerCase();if(!(r===l||r.startsWith(l)||l.startsWith(r)))return!1}return!0}function Tt(e,t){return!!(e!=null&&e.urlMatch)&&!_t(t).includes(e.urlMatch)}var Xn=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function ee(e,t){var l;if(e.urlMatch&&!_t(t).includes(e.urlMatch))return null;let n=[];if(e.id){let o=t.getElementById(e.id);n=o?[o]:[]}if(n.length===0&&((l=e.dataAttr)!=null&&l.name)&&Xn.test(e.dataAttr.name))try{let o=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${o}"]`))}catch(o){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(o){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!Yn(r,e.fingerprint)?null:r}var Pt={color:"color",background:"background",fontSize:"font-size",fontWeight:"font-weight",textAlign:"text-align",padding:"padding",margin:"margin",borderRadius:"border-radius",width:"width",height:"height",maxWidth:"max-width",border:"border",boxShadow:"box-shadow",opacity:"opacity",lineHeight:"line-height",letterSpacing:"letter-spacing",textTransform:"text-transform",gap:"gap",fontFamily:"font-family"},Zn=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function Rt(e){var t;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;for(let n of e.matchAll(/([A-Za-z-]*)\(/g))if(!Zn.test((t=n[1])!=null?t:""))return!1;return!0}var Lt=/^https:\/\//i,Dt=new Map,te=null;function Qn(e){return e.replace(/["\\]/g,"\\$&")}function er(e){var t;(!te||!te.isConnected)&&(te=e.querySelector("style[data-sentient-ops]"),te||(te=e.createElement("style"),te.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(te))),te.textContent=[...Dt.entries()].map(([n,r])=>`[data-snt-e="${Qn(n)}"]{${r}}`).join(`
2
+ `)}function Mt(e,t,n,r){var u;let l=!1,o=(u=t.moveBefore)!=null?u:t.moveAfter;if(o){let i=ee(o,r);!i||i===e||i.parentElement!==e.parentElement||!e.parentElement?l=!0:t.moveBefore?e.parentElement.insertBefore(e,i):e.parentElement.insertBefore(e,i.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&Lt.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&Lt.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let s=[];if(t.hidden&&s.push("display:none !important"),t.style)for(let[i,a]of Object.entries(t.style)){let c=Pt[i];c&&typeof a=="string"&&Rt(a)&&s.push(`${c}:${a.trim()} !important`)}return s.length>0&&(e.setAttribute("data-snt-e",n),Dt.set(n,s.join(";")),er(r)),{anchorMiss:l}}function _e(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function Te(e,t,n){var r;for(let[l,o]of Object.entries(t)){let s=e[l];if(!s||typeof s=="string")continue;let u=o.target?Array.from(n.querySelectorAll(o.target)):[n.documentElement];for(let i of u)for(let[a,c]of Object.entries(s))(r=o.dims[a])!=null&&r.includes(c)&&i.setAttribute(`data-${a}`,c)}}function Pe(e,t,n){for(let[r,l]of Object.entries(t)){let o=e[r];if(typeof o!="string"||!l.arms||!l.arms.includes(o))continue;let s=l.target?Array.from(n.querySelectorAll(l.target)):[n.documentElement];for(let u of s)u.setAttribute("data-sentient-arm",o)}}function Re(e,t,n,r){var s,u;let l=(s=r==null?void 0:r.contentAndOps)!=null?s:!0,o=[];for(let[i,a]of Object.entries(t)){if(Tt(a.locator,n))continue;let c;if(a.locator){let m=ee(a.locator,n);c=m?[m]:[]}else a.target?c=Array.from(n.querySelectorAll(a.target)):c=[n.documentElement];(a.locator||a.target)&&c.length===0&&o.push(i);let d=e[i];for(let m of c){if(d!==void 0)if(typeof d=="string")m.setAttribute("data-sentient-arm",d),l&&((u=r==null?void 0:r.onApplied)==null||u.call(r,i,d,m));else for(let[g,b]of Object.entries(d))m.setAttribute(`data-${g}`,b);l&&(typeof a.content=="string"&&(m.textContent=a.content),a.ops&&Mt(m,a.ops,i,n).anchorMiss&&!o.includes(i)&&o.push(i))}}return o}var tr=800;function Le(e,t,n){let r=[];return n.forEach(({slotId:l,arm:o,el:s},u)=>{r.push(ye((m,g={})=>{try{e.track({projectId:t,componentId:l,variantId:o,eventType:"micro_signal",payload:ie({signalType:m},g)})}catch(b){}},s,void 0,{tabLoss:u===0}));let i=null,a=0,c=()=>{a=Date.now(),i=setTimeout(()=>{try{e.track({projectId:t,componentId:l,variantId:o,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-a}})}catch(m){}i=null},tr)},d=()=>{i!==null&&(clearTimeout(i),i=null)};s.addEventListener("mouseenter",c),s.addEventListener("mouseleave",d),r.push(()=>{s.removeEventListener("mouseenter",c),s.removeEventListener("mouseleave",d),i!==null&&clearTimeout(i)})}),()=>{for(let l of r)l()}}function nr(e){var n,r,l;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(l=t==null?void 0:t.pathname)!=null?l:""}function rr(e,t){if(!e)return!1;if(e==="/")return t==="/";let n=e.endsWith("/")?e.slice(0,-1):e;return t===n||t.startsWith(`${n}/`)}function jt(e,t,n){var m;let r=new Set,l=g=>{if(!r.has(g.goalId)){r.add(g.goalId);try{g.slotId?t.componentGoal(g.slotId,g.goalId):t.goal(g.goalId)}catch(b){}}},o=e.filter(g=>g.event==="click"),s=e.filter(g=>g.event==="form_submit"),u=e.filter(g=>g.event==="url_reached"),i=(g,b)=>{if(!g.locator)return!1;let w=ee(g.locator,n);return!!w&&(w===b||w.contains(b))},a=g=>{let b=g.target;if(!(!b||typeof b.closest!="function"))for(let w of o)i(w,b)&&l(w)},c=g=>{let b=g.target;if(b)for(let w of s)i(w,b)&&l(w)},d=()=>{if(u.length===0)return;let g=nr(n);for(let b of u)b.urlPattern&&rr(b.urlPattern,g)&&l(b)};return n.addEventListener("click",a,!0),n.addEventListener("submit",c,!0),(m=n.defaultView)==null||m.addEventListener("popstate",d),d(),{checkUrl:d,teardown:()=>{var g;n.removeEventListener("click",a,!0),n.removeEventListener("submit",c,!0),(g=n.defaultView)==null||g.removeEventListener("popstate",d)}}}var Nt="__snt_editor_token";function $t(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(Nt):null}catch(e){return null}}function Bt(e){try{sessionStorage.setItem(Nt,e)}catch(t){}}var ze="0.13.0",Vt=5e3,or=50,ir=(()=>{try{if(typeof window=="undefined")return[];let e=window.SentientSnippet;return Array.isArray(e==null?void 0:e.q)?e.q:[]}catch(e){return[]}})(),U=null,L=null,Q={},ne=null,V=null,M=null,H=null,C=null,Kt=!1,We=null,De=null,Me=null,ve=!1,je=!1;function Jt(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function ce(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function ue(e,t){return U?(U.personaAttributes&&C&&_e(C.persona,C.band,e),Te(Q,U.slots,e),Pe(Q,U.slots,e),ne?Re(Q,ne,e,t):[]):[]}function sr(e,t){var n;if(t.length!==0)try{let r=(n=e.apiBase)!=null?n:"https://api.sentient-ui.com";fetch(`${r}/v1/locator-miss`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify({slots:t})}).catch(()=>{})}catch(r){}}function be(){return!!(U&&L&&U.sectionCapture!==!1&&(U.consent!==!1||je)&&!ae())}function ar(){if(!L||!U||!be()||H)return;let e=[];ue(document,{contentAndOps:ve,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),Je();try{M==null||M(),M=Le(L,U.apiKey,e)}catch(t){}}function Je(){if(typeof document=="undefined"||!be())return;let e;try{if(De&&De.length>0){let t=new Map;for(let n of De){if(n.urlMatch!==window.location.pathname)continue;let r=ee(n.locator,document);r&&t.set(r,n.type)}t.size>0&&(e=n=>{var r;return(r=t.get(n))!=null?r:null})}}catch(t){}try{H=Ct(L,ie({apiKey:U.apiKey,apiBase:U.apiBase,doc:document,microSignals:!0},e?{typeOf:e}:{})),Me=window.location.pathname}catch(t){}}function Fe(){try{let e=[];if(M==null||M(),M=null,ue(document,{contentAndOps:ve,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),e.length>0&&be())try{M=Le(L,U.apiKey,e)}catch(t){}try{typeof window!="undefined"&&Me!==null&&window.location.pathname!==Me&&be()&&(H==null||H(),H=null,Je())}catch(t){}}catch(e){}}function Ut(){We===null&&(We=setTimeout(()=>{We=null,Fe();try{V==null||V.checkUrl()}catch(e){}},or))}function Gt(){if(!(Kt||typeof window=="undefined"||typeof history=="undefined")){Kt=!0;try{let e=t=>{let n=history[t];history[t]=function(r,l,o){let s=n.call(this,r,l,o!=null?o:null);return Ut(),s}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Ut)}catch(e){}}}function Ve(e){let t={};for(let[n,r]of Object.entries(e.slots))t[n]=r.target?document.querySelectorAll(r.target).length:1;return t}function Ft(e){return new URLSearchParams(e).get("sentient_editor")}function lr(){try{let t=Array.from(document.getElementsByTagName("script")).find(n=>/snippet(\.global)?\.js/.test(n.src));if(t!=null&&t.src)return t.src.replace(/snippet(\.global)?\.js/,"editor.global.js")}catch(e){}return null}function cr(e,t){var n,r,l,o;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let i=document.createElement("meta");i.name="referrer",i.content="no-referrer",i.setAttribute("data-sentient-editor",""),((r=document.head)!=null?r:document.documentElement).appendChild(i)}catch(i){}let s=(l=e.editorSrc)!=null?l:lr();if(!s){Wt();return}let u=document.createElement("script");u.src=s,u.async=!0,u.onerror=()=>Wt(),((o=document.head)!=null?o:document.documentElement).appendChild(u)}catch(s){}}var qt="sentient-editor-load-notice";function Wt(){var e;try{if(typeof document=="undefined"||document.getElementById(qt))return;let t=document.createElement("div");t.id=qt,t.textContent="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.",Object.assign(t.style,{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",cursor:"pointer"}),t.addEventListener("click",()=>t.remove()),((e=document.body)!=null?e:document.documentElement).appendChild(t),setTimeout(()=>t.remove(),1e4)}catch(t){}}function Ht(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let l=r.indexOf(":"),o=l===-1?"":r.slice(0,l),s=l===-1?"":r.slice(l+1);if(!(!o||!s))if(s.includes("=")){let u={};for(let i of s.split(",")){let[a,c]=i.split("=");a&&c&&(u[a]=c)}Object.keys(u).length&&(n[o]=u)}else n[o]=s}return Object.keys(n).length?n:null}function Yt(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var zt="sentient-persona-preview-banner";function ur(e){var t;try{if(typeof document=="undefined"||document.getElementById(zt))return;let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),r=document.createElement("div");r.id=zt,r.setAttribute("role","status"),Object.assign(r.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",background:"#111827",color:"#fff",font:"13px/1 system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.14)"});let l=document.createElement("span");l.textContent=`Previewing as ${n}`;let o=document.createElement("button");o.type="button",o.textContent="Exit preview",Object.assign(o.style,{cursor:"pointer",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"inherit",padding:"4px 10px",borderRadius:"999px"}),o.addEventListener("click",()=>{try{let s=new URL(window.location.href);s.searchParams.delete("sentient_persona"),window.location.href=s.pathname+s.search+s.hash}catch(s){}}),r.appendChild(l),r.appendChild(o),((t=document.body)!=null?t:document.documentElement).appendChild(r)}catch(n){}}async function dr(e,t){var a,c,d,m,g,b,w,A,_;let n=(a=e.apiBase)!=null?a:"https://api.sentient-ui.com",l=((c=e.registry)!=null?c:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([S,I])=>({id:S,dims:I.dims}))},o=await Jt(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(l)}).then(S=>S.ok?S.json():null).catch(()=>null),Vt);if(!o){ce(e,"persona preview: explain unavailable \u2014 page left as-is");return}let s=o;Q=(d=s.slots)!=null?d:{},ne=(m=s.slotConfig)!=null?m:null;let u=(w=(b=(g=s.personaAttributes)==null?void 0:g.persona)!=null?b:s.persona)!=null?w:t,i=(_=(A=s.personaAttributes)==null?void 0:A.confidence)!=null?_:"high";C={persona:u,band:i},ue(document),ve=!0,Xt(e),ur(u)}function Xt(e){let t={goal(n,r){try{L==null||L.goal(n,r)}catch(l){}},componentGoal(n,r){try{L==null||L.componentGoal(n,r)}catch(l){}},grantConsent(){try{qe(e.apiKey)}catch(n){}je=!0;try{ar()}catch(n){}},revokeConsent(){try{H==null||H(),H=null,Me=null,M==null||M(),M=null,V==null||V.teardown(),V=null,je=!1,L==null||L.destroy()}catch(n){}},reapply:Fe,getState(){var n,r;return{apiKey:e.apiKey,persona:(n=C==null?void 0:C.persona)!=null?n:null,band:(r=C==null?void 0:C.band)!=null?r:null,slots:Q,matchCounts:Ve(e),consent:e.consent!==!1}}};window.SentientSnippet=t;for(let n of ir.splice(0))try{n[0]==="goal"&&t.goal(n[1],n[2])}catch(r){}}async function Zt(){var e,t,n,r,l;try{let o=Ce(window.sentient);if(!o)return;U=o,ve=!1,je=!1;let s=typeof window!="undefined"?Ft(window.location.search):null;if(s){Bt(s);try{let S=new URL(window.location.href);S.searchParams.delete("sentient_editor"),window.history.replaceState(null,"",S.pathname+S.search+S.hash)}catch(S){}}let u=s!=null?s:$t();if(u){cr(o,u),ce(o,"editor mode");return}let i=typeof window!="undefined"?Ht(window.location.search):null;if(i){Q=i,C=null,ue(document),Gt(),ce(o,"preview mode",i);return}let a=typeof window!="undefined"?Yt(window.location.search):null;if(a){await dr(o,a),ce(o,"persona preview",a);return}let c=(e=o.registry)!=null?e:Object.keys(o.slots).length===0,d=Ee(o.apiKey);d&&(C={persona:d.persona,band:d.band},Q=d.slots,d.slotConfig&&(ne=d.slotConfig),ue(document,{contentAndOps:!1}));let m=Oe({apiKey:o.apiKey,context:o.context,consent:o.consent,preConsentBehavior:o.preConsentBehavior,debug:o.debug});L=m,Xt(o),Gt();let g=Object.entries(o.slots).map(([S,I])=>({id:S,dims:I.dims})),b=ze!=="0.0.0-dev"?{v:ze}:{},w=await Jt(m.decide(ie(ie({slots:g},b),c?{slotsFrom:"registry"}:{})),Vt);if(!w){ce(o,"decide timeout/null \u2014 snapshot state stands",Ve(o));return}let A=m.getPersona();A?C={persona:A.persona,band:A.band}:w.persona&&(C={persona:w.persona,band:"low"}),Q=w.slots,c?ne=(t=w.slotConfig)!=null?t:null:w.slotConfig&&(ne=w.slotConfig);let _=[];if(sr(o,ue(document,{onApplied:(S,I,N)=>_.push({slotId:S,arm:I,el:N})})),ve=!0,w.goals&&w.goals.length>0&&o.consent!==!1&&L)try{V==null||V.teardown(),V=jt(w.goals,L,document)}catch(S){}if(De=(n=w.sectionMap)!=null?n:null,be()){Je();try{M==null||M(),M=Le(L,o.apiKey,_)}catch(S){}}ce(o,"applied",{persona:C,slots:Q,matches:Ve(o)}),he(o.apiKey,ie({v:1,persona:(r=C==null?void 0:C.persona)!=null?r:w.persona,band:(l=C==null?void 0:C.band)!=null?l:"low",slots:w.slots,layoutOrder:w.layoutOrder,savedAt:Date.now()},ne?{slotConfig:ne}:{}))}catch(o){}}if(typeof window!="undefined"&&window.sentient){let e=window;e.__sentientInitialized||(e.__sentientInitialized=!0,Zt())}return on(pr);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentientui/snippet",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "private": false,
5
5
  "description": "SentientUI Style-rung snippet for non-React sites — persona attributes and adaptive style tokens from one script tag",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  "tsx": "^4.19.2",
25
25
  "typescript": "^5.7.2",
26
26
  "vitest": "^2.1.8",
27
- "@sentientui/core": "0.16.9"
27
+ "@sentientui/core": "0.17.0"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "tsup",