@sentientui/snippet 0.14.0 → 0.15.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.
package/README.md CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  Style-rung [SentientUI](https://sentient-ui.com) for sites that are not built with React.
4
4
  One script tag: visitor-type attributes on `<html>` plus learned `data-*` style tokens on the
5
- elements you declare. Plain CSS does the rest. No DOM reordering, ever; if anything fails, your
5
+ elements you declare. Plain CSS does the rest. No markup is ever injected text is written as
6
+ `textContent` and styles come from a bounded, validated set. The only structural change possible
7
+ is moving a declared element among its own siblings (a registry `moveBefore`/`moveAfter` op,
8
+ applied after the decision returns); a drifted anchor applies nothing. If anything fails, your
6
9
  page is left exactly as it was.
7
10
 
8
11
  ```html
@@ -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 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:()=>Pe,applySlotArms:()=>Re,applySlotAttributes:()=>Te,parseEditorToken:()=>Ft,parsePersonaPreview:()=>Yt,parsePreview:()=>Ht,parseSnippetConfig:()=>Oe,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 Cn(e){try{localStorage.removeItem(e)}catch(t){}}function On(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=A=>A&&A.length>0?A: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 x=xn(a,m),k=En(i),f=x?!1:kn(a,m),h=!x&&!k&&!f;return{getSessionId:()=>m,isEphemeral:()=>h,destroy:()=>{m=null,On(i),Cn(a),In(a)}}}function yt(e){return`_snt_retry_${e.slice(0,12)}`}var Tn={push:()=>{},flush:()=>{},destroy:()=>{}};function Rn(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 Pn(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=[],x=g=>{for(let S of g)k.delete(S),!d.has(S)&&(d.add(S),m.push(S));for(;m.length>500;){let S=m.shift();S&&d.delete(S)}Pn(g,a)},k=new Set,f=g=>{d.has(g.id)||k.has(g.id)||(k.add(g.id),c.push(g))},h=g=>{for(let S of g)d.has(S.id)||(k.add(S.id),c.push(S))},A=Rn(s,a);for(let g of A)f(g);let w=0,E=0,N=g=>{if(g.length===0)return;let S=JSON.stringify(g),j=g.map(p=>p.id),J;try{J=fetch(u,{method:"POST",keepalive:!0,body:S,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}})}catch(p){Ke(g,s,a),h(g),E++,w=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6));return}let q=p=>{if(p.ok||p.status>=400&&p.status<500&&p.status!==429){x(j),E=0,w=0;return}Ke(g,s,a),h(g),E++,w=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))};J instanceof Promise?J.then(q).catch(()=>{Ke(g,s,a),h(g),E++,w=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))}):q(J)},Y=typeof TextEncoder!="undefined"?new TextEncoder:null,le=g=>Y?Y.encode(g).length:g.length,re=g=>{let S=[],j=2;for(let J of g){let q=le(JSON.stringify(J))+1;if(S.length>0&&j+q>57344||S.length>=o)break;S.push(J),j+=q}return S},T=()=>{try{if(Date.now()<w)return;for(;c.length>0&&!(Date.now()<w);){let g=c.filter(j=>!d.has(j.id));if(c.length=0,g.length===0)break;let S=re(g);if(S.length===0)break;S.length<g.length&&c.push(...g.slice(S.length)),N(S)}}catch(g){}},X=!0,b=null;b=setInterval(()=>{X&&T()},l);let y=()=>{document.visibilityState==="hidden"&&T()},I=()=>{T()};return document.addEventListener("visibilitychange",y),window.addEventListener("pagehide",I),{push(g){f(g),c.length>=o&&T()},flush:T,destroy(){X=!1,b!==null&&(clearInterval(b),b=null),document.removeEventListener("visibilitychange",y),window.removeEventListener("pagehide",I),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 x=m.createLocalEngine({sessionId:r,forcedPersona:l}).decide(i);return s=ge(O({},x),{layoutOrder:(c=(a=x.layoutOrder)!=null?a:s==null?void 0:s.layoutOrder)!=null?c:null,slots:O(O({},(d=s==null?void 0:s.slots)!=null?d:{}),x.slots)}),he(e.apiKey||"local",{v:1,persona:s.persona,band:se(s.confidence),slots:s.slots,layoutOrder:s.layoutOrder,savedAt:Date.now()}),u(x),x},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=x=>{for(let k of x)s=k.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=Ce(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 x of a!=null?a:[])d.append("variantIds[]",x);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 Ce(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,x=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!x&&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:v}=Un(e);return K.set(e.apiKey,{config:e,upgrade:d?null:v}),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 k=(t=e.ingestUrl)!=null?t:bt,f=Date.now(),h=ht({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),A=Mn(void 0,e.apiKey),w=Ln({ingestUrl:k,apiKey:e.apiKey}),E=St(k),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,b=new Map,y=null,I=p=>{for(let v of p)b.has(v.id)||b.set(v.id,Be(v))};if(e.initialSlots)for(let[p,v]of Object.entries(e.initialSlots))b.set(p,v);let g=Ee(e.apiKey);if(g)for(let[p,v]of Object.entries(g.slots))b.has(p)||b.set(p,v);let S={low:.15,medium:.5,high:.85};if(e.initialPersona)y=O({},e.initialPersona);else{let p=document.documentElement.dataset;p.sentientPersona?y={persona:p.sentientPersona,confidence:(s=S[(o=p.sentientConfidence)!=null?o:"low"])!=null?s:.15}:g&&(y={persona:g.persona,confidence:(u=S[g.band])!=null?u:.15})}if(e.initialAssignments)for(let[p,v]of Object.entries(e.initialAssignments))A.set(p,T,{variantId:v,assignedAt:Date.now(),segment:T,confidence:1});let j=Promise.resolve(),J=h.getSessionId();if(J){let p=lt((i=document.referrer)!=null?i:""),v=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:h.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(`${E}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(v),headers:N}).then(C=>{C.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(C){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:w});let q={goal(p,v={},C=1,F=0){var W,D,z;let B=h.getSessionId();if(!B)return;let R=Bn(v)?v:{metadata:v},Z=Ue(),$={sessionId:B,name:p,metadata:(W=R.metadata)!=null?W:{},weight:(D=R.weight)!=null?D:C,stepIndex:(z=R.stepIndex)!=null?z:F,goalId:Z,value:R.value,currency:R.currency,externalId:R.externalId};j.then(()=>{fetch(`${E}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify($),headers:N}).catch(()=>{})})},componentGoal(p,v,C){var F,W,D;let z=h.getSessionId();if(!z)return;let B=A.get(p,T),R=B?null:(F=b.get(p))!=null?F:null;if(!B&&R===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(R),$={id:Ue(),sessionId:z,projectId:e.apiKey,componentId:p,variantId:Z,eventType:"goal_achieved",goalType:v,payload:O({reward:(W=C==null?void 0:C.reward)!=null?W:1,goalValue:C==null?void 0:C.value,currency:C==null?void 0:C.currency},(D=C==null?void 0:C.metadata)!=null?D:{}),timestamp:Date.now(),timeInSession:Date.now()-f};e.debug&&console.log("[sentient] componentGoal",$),j.then(()=>w.push($))},identify(p){let v=h.getSessionId();v&&j.then(()=>{fetch(`${E}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:v,userId:p,ephemeral:h.isEphemeral()}),headers:N}).catch(()=>{})})},track(p){let v=h.getSessionId();if(!v)return;let C=ge(O({},p),{id:Ue(),sessionId:v,timestamp:Date.now(),timeInSession:Date.now()-f});e.debug&&console.log("[sentient] track",C),j.then(()=>w.push(C))},getAssignment(p,v){return A.get(p,v)},async assign(p,v,C,F){let W=h.getSessionId();if(!W)return null;let D=A.get(p,T);if(D&&(v!=null&&v.length||D.content!==void 0)){let R=D.ttlMs&&D.ttlMs>0?Math.max(0,D.assignedAt+D.ttlMs-Date.now()):0;return{variantId:D.variantId,assignmentTtlMs:R,content:D.content}}let z=X.get(p);if(z)return z;let B=(async()=>{await j;try{let R={sessionId:W,componentId:p,variantIds:v};F!==void 0?R.agentDataByVariant=F:C!==void 0&&(R.agentData=C);let Z=await fetch(`${E}/assign`,{method:"POST",body:JSON.stringify(R),headers:N});if(!Z.ok)return null;let $=await Z.json();return A.set(p,T,O({variantId:$.variantId,assignedAt:Date.now(),segment:T,confidence:1,content:$.content},$.assignmentTtlMs&&$.assignmentTtlMs>0?{ttlMs:$.assignmentTtlMs}:{})),$}catch(R){return null}finally{X.delete(p)}})();return X.set(p,B),B},async decide(p){var v,C,F,W,D,z,B,R,Z;let $=h.getSessionId();if(!$)return null;let de=(v=p.slots)!=null?v:[];await j;try{let oe={sessionId:$};p.sections&&p.sections.length>0&&(oe.sections=p.sections.map(G=>({id:G}))),oe.components=(C=p.components)!=null?C:[],de.length>0&&(oe.slots=de.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:N});if(!He.ok)return I(de),null;let P=await He.json(),pe={};for(let G of de)pe[G.id]=(W=(F=P.slots)==null?void 0:F[G.id])!=null?W:Be(G);if(P.slots)for(let[G,fe]of Object.entries(P.slots))G in pe||(pe[G]=fe);for(let[G,fe]of Object.entries(pe))b.set(G,fe);let Qt=y!=null&&y.persona!=="unknown";P.persona&&!(P.persona==="unknown"&&Qt)?y={persona:P.persona,confidence:(D=P.confidence)!=null?D:0}:y||(y={persona:"unknown",confidence:0});for(let[G,fe]of Object.entries((z=P.assignments)!=null?z:{}))A.set(G,T,{variantId:fe,assignedAt:Date.now(),segment:T,confidence:1});return he(e.apiKey,O({v:1,persona:y.persona,band:se(y.confidence),slots:Object.fromEntries(b),layoutOrder:(B=P.layoutOrder)!=null?B:null,savedAt:Date.now()},P.slotConfig?{slotConfig:P.slotConfig}:{})),O(O(O({layoutOrder:(R=P.layoutOrder)!=null?R:null,assignments:(Z=P.assignments)!=null?Z:{},slots:pe,persona:y.persona,confidence:y.confidence},P.slotConfig?{slotConfig:P.slotConfig}:{}),P.goals?{goals:P.goals}:{}),P.sectionMap?{sectionMap:P.sectionMap}:{})}catch(oe){return I(de),null}},getSlotResult(p){var v;return(v=b.get(p))!=null?v:null},getPersona(){return y?{persona:y.persona,confidence:y.confidence,band:se(y.confidence)}:null},async fetchWeights(){var p;try{let v=await fetch(`${E}/weights`,{headers:N});return v.ok?(p=(await v.json()).components)!=null?p:[]:[]}catch(v){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var p;w.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;w.destroy(),h.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(v){}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 Ct="section, header, footer, nav, main > div, [data-sentient-section]";function zn(e){var t;return((t=e.parentElement)==null?void 0:t.closest(Ct))!=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 Ot(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$/,""),x=Array.from(d.querySelectorAll(Ct)).filter(b=>!zn(b));if(x.length===0)return Et;let k=new Map,f=new Map,h=new Map;for(let b of x){let y=b.getAttribute("data-sentient-type"),I=y&&xt.includes(y)?y:null,g=(o=I!=null?I:(l=t.typeOf)==null?void 0:l.call(t,b))!=null?o:It(b),S=`nc-${g}`;k.set(b,S),f.set(S,g),I?h.set(S,"markup"):h.has(S)||h.set(S,"auto")}let A=(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,A,[...f.entries()].map(([b,y])=>{var I;return{componentId:b,semanticType:y,source:(I=h.get(b))!=null?I:"auto"}}));let w=new Map,E=b=>{let y=w.get(b);return y||(y={ms:0,scroll:0,enterAt:null,intersecting:!1},w.set(b,y)),y},N=new IntersectionObserver(b=>{for(let y of b){let I=k.get(y.target);if(!I)continue;let g=E(I);y.isIntersecting?(g.intersecting=!0,g.enterAt=Date.now(),y.intersectionRatio>g.scroll&&(g.scroll=y.intersectionRatio)):(g.intersecting=!1,g.enterAt!=null&&(g.ms+=Date.now()-g.enterAt,g.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let b of k.keys())N.observe(b);let Y=()=>{let b=Date.now();for(let[y,I]of w)if(I.enterAt!=null&&(I.ms+=b-I.enterAt,I.enterAt=null),!(I.ms<=0)){try{e.track({projectId:t.apiKey,componentId:y,eventType:"dwell",payload:{dwell_time:Math.round(I.ms),scroll_depth:Number(I.scroll.toFixed(2))}})}catch(g){}I.ms=0}},le=()=>{if(d.hidden)Y();else{let b=Date.now();for(let y of w.values())y.intersecting&&(y.enterAt=b)}},re=()=>{Y();try{N.disconnect()}catch(b){}};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&&[...k.entries()].forEach(([b,y],I)=>{X.push(ye((g,S={})=>{try{e.track({projectId:t.apiKey,componentId:y,eventType:"micro_signal",payload:O({signalType:g},S)})}catch(j){}},b,void 0,{tabLoss:I===0}))}),()=>{Y(),d.removeEventListener("visibilitychange",le),T==null||T.removeEventListener("pagehide",re);for(let b of X)b();try{N.disconnect()}catch(b){}}}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 Oe(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 Rt={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,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=Rt[i];c&&typeof a=="string"&&Pt(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 Re(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 Pe(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[x,k]of Object.entries(d))m.setAttribute(`data-${x}`,k);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,x={})=>{try{e.track({projectId:t,componentId:l,variantId:o,eventType:"micro_signal",payload:ie({signalType:m},x)})}catch(k){}},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 k;let r=new Set,l=f=>{if(!r.has(f.goalId)){r.add(f.goalId);try{f.slotId?t.componentGoal(f.slotId,f.goalId):t.goal(f.goalId)}catch(h){}}},o=e.filter(f=>f.event==="click"),s=e.filter(f=>f.event==="form_submit"),u=e.filter(f=>f.event==="url_reached"),i=e.filter(f=>f.event==="scroll_depth"),a=(f,h)=>{if(!f.locator)return!1;let A=ee(f.locator,n);return!!A&&(A===h||A.contains(h))},c=f=>{let h=f.target;if(!(!h||typeof h.closest!="function"))for(let A of o)a(A,h)&&l(A)},d=f=>{let h=f.target;if(h)for(let A of s)a(A,h)&&l(A)},m=()=>{if(u.length===0)return;let f=nr(n);for(let h of u)h.urlPattern&&rr(h.urlPattern,f)&&l(h)},x=()=>{var A;let f=n.documentElement,h=f.scrollHeight>0?(f.scrollTop+f.clientHeight)/f.scrollHeight:0;for(let w of i)h>=((A=w.threshold)!=null?A:.75)&&l(w)};return n.addEventListener("click",c,!0),n.addEventListener("submit",d,!0),(k=n.defaultView)==null||k.addEventListener("popstate",m),m(),i.length>0&&(n.addEventListener("scroll",x,{passive:!0}),x()),{checkUrl:m,teardown:()=>{var f;n.removeEventListener("click",c,!0),n.removeEventListener("submit",d,!0),(f=n.defaultView)==null||f.removeEventListener("popstate",m),i.length>0&&n.removeEventListener("scroll",x)}}}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.14.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,_=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&&_&&_e(_.persona,_.band,e),Te(Q,U.slots,e),Re(Q,U.slots,e),ne?Pe(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=Ot(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,x,k,f,h,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(([w,E])=>({id:w,dims:E.dims}))},o=await Jt(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(l)}).then(w=>w.ok?w.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=(f=(k=(x=s.personaAttributes)==null?void 0:x.persona)!=null?k:s.persona)!=null?f:t,i=(A=(h=s.personaAttributes)==null?void 0:h.confidence)!=null?A:"high";_={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=_==null?void 0:_.persona)!=null?n:null,band:(r=_==null?void 0:_.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=Oe(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 w=new URL(window.location.href);w.searchParams.delete("sentient_editor"),window.history.replaceState(null,"",w.pathname+w.search+w.hash)}catch(w){}}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,_=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&&(_={persona:d.persona,band:d.band},Q=d.slots,d.slotConfig&&(ne=d.slotConfig),ue(document,{contentAndOps:!1}));let m=Ce({apiKey:o.apiKey,context:o.context,consent:o.consent,preConsentBehavior:o.preConsentBehavior,debug:o.debug});L=m,Xt(o),Gt();let x=Object.entries(o.slots).map(([w,E])=>({id:w,dims:E.dims})),k=ze!=="0.0.0-dev"?{v:ze}:{},f=await Jt(m.decide(ie(ie({slots:x},k),c?{slotsFrom:"registry"}:{})),Vt);if(!f){ce(o,"decide timeout/null \u2014 snapshot state stands",Ve(o));return}let h=m.getPersona();h?_={persona:h.persona,band:h.band}:f.persona&&(_={persona:f.persona,band:"low"}),Q=f.slots,c?ne=(t=f.slotConfig)!=null?t:null:f.slotConfig&&(ne=f.slotConfig);let A=[];if(sr(o,ue(document,{onApplied:(w,E,N)=>A.push({slotId:w,arm:E,el:N})})),ve=!0,f.goals&&f.goals.length>0&&o.consent!==!1&&L)try{V==null||V.teardown(),V=jt(f.goals,L,document)}catch(w){}if(De=(n=f.sectionMap)!=null?n:null,be()){Je();try{M==null||M(),M=Le(L,o.apiKey,A)}catch(w){}}ce(o,"applied",{persona:_,slots:Q,matches:Ve(o)}),he(o.apiKey,ie({v:1,persona:(r=_==null?void 0:_.persona)!=null?r:f.persona,band:(l=_==null?void 0:_.band)!=null?l:"low",slots:f.slots,layoutOrder:f.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);})();
1
+ "use strict";var SentientSnippet=(()=>{var xe=Object.defineProperty;var un=Object.getOwnPropertyDescriptor;var dn=Object.getOwnPropertyNames,et=Object.getOwnPropertySymbols;var nt=Object.prototype.hasOwnProperty,pn=Object.prototype.propertyIsEnumerable;var tt=(e,t,n)=>t in e?xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,le=(e,t)=>{for(var n in t||(t={}))nt.call(t,n)&&tt(e,n,t[n]);if(et)for(var n of et(t))pn.call(t,n)&&tt(e,n,t[n]);return e};var rt=(e,t)=>()=>(e&&(t=e(e=0)),t);var ot=(e,t)=>{for(var n in t)xe(e,n,{get:t[n],enumerable:!0})},fn=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of dn(t))!nt.call(e,a)&&a!==n&&xe(e,a,{get:()=>t[a],enumerable:!(r=un(t,a))||r.enumerable});return e};var gn=e=>fn(xe({},"__esModule",{value:!0}),e);var mn,hn,yn,it,vn,bn,st,T,he,Ie=rt(()=>{"use strict";mn=Object.defineProperty,hn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,it=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,bn=Object.prototype.propertyIsEnumerable,st=(e,t,n)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,T=(e,t)=>{for(var n in t||(t={}))vn.call(t,n)&&st(e,n,t[n]);if(it)for(var n of it(t))bn.call(t,n)&&st(e,n,t[n]);return e},he=(e,t)=>hn(e,yn(t))});var mt={};ot(mt,{LOCAL_ENGINE_AVAILABLE:()=>An,createLocalEngine:()=>xn});function xn(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var An,ht=rt(()=>{"use strict";An=!1});var Cr={};ot(Cr,{applyPersonaAttributes:()=>De,applyRegistrySlots:()=>Ne,applySlotArms:()=>$e,applySlotAttributes:()=>Me,parseEditorToken:()=>rn,parsePersonaPreview:()=>sn,parsePreview:()=>on,parseSnippetConfig:()=>Pe,reapply:()=>Qe,run:()=>ln,version:()=>Ye});Ie();function ke(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function at(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 a=n.slice(0,r);if(a in t)return null;t[a]=n.slice(r+1)}return t}function Ge(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 ke(e.baseline);if(typeof e.baseline=="string")return e.baseline;let a={};for(let[o,l]of Object.entries((n=e.dims)!=null?n:{}))a[o]=(r=l[0])!=null?r:"";return ke(a)}function lt(e,t){var n,r;return e.dims!=null?(r=(n=at(t))!=null?n:at(Ge(e)))!=null?r:{}:t}function ce(e){return e>=.3?e<.7?"medium":"high":"low"}var wn=["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 ct(e){return Sn(e)!==null}function Sn(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=wn.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function ut(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 dt(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(a){}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 pt(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function ft(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function qe(e){return T(T(T({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 We(e){let t=qe(e);return lt(t,Ge(t))}function gt(e){return typeof e=="string"?e:ke(e)}Ie();function vt(){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 bt(e){return e?`_${e.slice(0,12)}`:""}var In="_snt_uid",kn=365,En="_snt_uid";function Cn(){return vt()}function On(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function _n(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function Tn(e){try{return localStorage.getItem(e)}catch(t){return null}}function Ln(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function Rn(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function Pn(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function Dn(e){try{sessionStorage.removeItem(e)}catch(t){}}function Mn(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 $n(e){try{localStorage.removeItem(e)}catch(t){}}function Nn(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var jn={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function wt(e){var t,n,r,a,o,l;if(typeof window=="undefined")return jn;let u=bt(e==null?void 0:e.apiKey),i=(t=e==null?void 0:e.cookieName)!=null?t:`${In}${u}`,s=`${En}${u}`,c=((n=e==null?void 0:e.cookieTTLDays)!=null?n:kn)*24*60*60,d=g=>g&&g.length>0?g:null,m=(l=(o=(a=(r=d(On(i)))!=null?r:d(Tn(s)))!=null?a:d(Rn(s)))!=null?o:d(e==null?void 0:e.ssrSessionId))!=null?l:Cn();_n(i,m,c);let w=Ln(s,m),E=Mn(i),C=w?!1:Pn(s,m),k=!w&&!E&&!C;return{getSessionId:()=>m,isEphemeral:()=>k,destroy:()=>{m=null,Nn(i),$n(s),Dn(s)}}}function Oe(e){return Math.min(6e4,1e3*2**Math.min(e,6))}function St(e){if(e.ok===!0)return"delivered";let{status:t}=e;return typeof t!="number"?"retry":t>=200&&t<300?"delivered":t>=400&&t<500&&t!==429?"dropped":"retry"}function At(e,t){try{let n=localStorage.getItem(e);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?(localStorage.removeItem(e),r.slice(-t)):[]}catch(n){return[]}}function _e(e,t,n){try{let r=(()=>{try{let o=localStorage.getItem(n);if(!o)return[];let l=JSON.parse(o);return Array.isArray(l)?l:[]}catch(o){return[]}})(),a=new Map;for(let o of r)a.set(o.id,o);for(let o of e)a.set(o.id,o);localStorage.setItem(n,JSON.stringify([...a.values()].slice(-t)))}catch(r){}}function xt(e,t){try{let n=localStorage.getItem(t);if(!n)return;let r=JSON.parse(n);if(!Array.isArray(r))return;let a=new Set(e),o=r.filter(l=>!a.has(l.id));if(o.length===r.length)return;o.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(o))}catch(n){}}var Kn=500,Bn=56*1024;function It(e){return`_snt_retry_${e.slice(0,12)}`}var Un={push:()=>{},flush:()=>{},destroy:()=>{}};function Gn(e){var t,n,r;if(typeof window=="undefined")return Un;let a=(t=e.flushIntervalMs)!=null?t:5e3,o=(n=e.maxBatchSize)!=null?n:20,l=(r=e.maxRetrySize)!=null?r:100,u=e.ingestUrl,i=e.apiKey,s=It(i),c=[],d=new Set,m=[],w=h=>{for(let I of h)E.delete(I),!d.has(I)&&(d.add(I),m.push(I));for(;m.length>Kn;){let I=m.shift();I&&d.delete(I)}xt(h,s)},E=new Set,C=h=>{d.has(h.id)||E.has(h.id)||(E.add(h.id),c.push(h))},k=h=>{for(let I of h)d.has(I.id)||(E.add(I.id),c.push(I))},g=At(s,l);for(let h of g)C(h);let f=0,x=0,O=h=>{if(h.length===0)return;let I=JSON.stringify(h),X=h.map(te=>te.id),K;try{K=fetch(u,{method:"POST",keepalive:!0,body:I,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}})}catch(te){_e(h,l,s),k(h),x++,f=Date.now()+Oe(x);return}let re=te=>{if(St(te)!=="retry"){w(X),x=0,f=0;return}_e(h,l,s),k(h),x++,f=Date.now()+Oe(x)};K instanceof Promise?K.then(re).catch(()=>{_e(h,l,s),k(h),x++,f=Date.now()+Oe(x)}):re(K)},q=typeof TextEncoder!="undefined"?new TextEncoder:null,v=h=>q?q.encode(h).length:h.length,P=h=>{let I=[],X=2;for(let K of h){let re=v(JSON.stringify(K))+1;if(I.length>0&&X+re>Bn||I.length>=o)break;I.push(K),X+=re}return I},$=()=>{try{if(Date.now()<f)return;for(;c.length>0&&!(Date.now()<f);){let h=c.filter(X=>!d.has(X.id));if(c.length=0,h.length===0)break;let I=P(h);if(I.length===0)break;I.length<h.length&&c.push(...h.slice(I.length)),O(I)}}catch(h){}},D=!0,S=null;S=setInterval(()=>{D&&$()},a);let A=()=>{document.visibilityState==="hidden"&&$()},b=()=>{$()};return document.addEventListener("visibilitychange",A),window.addEventListener("pagehide",b),{push(h){C(h),c.length>=o&&$()},flush:$,destroy(){D=!1,S!==null&&(clearInterval(S),S=null),document.removeEventListener("visibilitychange",A),window.removeEventListener("pagehide",b),$()}}}var qn=200;function kt(e){return`_snt_goal_retry_${e.slice(0,12)}`}var Wn={send:()=>{},flush:()=>{},destroy:()=>{}};function zn(e){var t,n,r;if(typeof window=="undefined")return Wn;let a=(t=e.flushIntervalMs)!=null?t:5e3,o=(n=e.maxRetrySize)!=null?n:100,l=(r=e.maxPerFlush)!=null?r:5,u=kt(e.apiKey),i=[],s=new Set,c=new Set,d=[],m=0,w=0,E=!1,C=v=>{for(s.delete(v.id),c.has(v.id)||(c.add(v.id),d.push(v.id));d.length>qn;){let P=d.shift();P&&c.delete(P)}xt([v.id],u)},k=v=>{_e([v],o,u),!c.has(v.id)&&!s.has(v.id)&&(s.add(v.id),i.push(v)),w++,m=Date.now()+Oe(w)},g=v=>{let P;try{P=fetch(e.url,{method:"POST",keepalive:!0,body:v.body,headers:e.headers})}catch(D){k(v);return}let $=D=>{var S;let A=St(D);if(A==="retry"){k(v);return}A==="dropped"&&((S=e.onDrop)==null||S.call(e,v,D.status)),C(v),w=0,m=0};P instanceof Promise?P.then($).catch(()=>k(v)):$(P)},f=()=>{try{if(E||Date.now()<m)return;let v=0;for(;i.length>0&&v<l&&!(Date.now()<m);){let P=i.shift();s.delete(P.id),!c.has(P.id)&&(v++,g(P))}}catch(v){}};for(let v of At(u,o))s.has(v.id)||(s.add(v.id),i.push(v));let x=setInterval(f,a),O=()=>{document.visibilityState==="hidden"&&f()},q=()=>f();return document.addEventListener("visibilitychange",O),window.addEventListener("pagehide",q),{send(v){if(!E&&!(c.has(v.id)||s.has(v.id))){if(Date.now()<m){s.add(v.id),i.push(v);return}g(v)}},flush:f,destroy(){clearInterval(x),document.removeEventListener("visibilitychange",O),window.removeEventListener("pagehide",q),f(),E=!0}}}var Vn=1800*1e3;function Ee(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Jn(e=Vn,t){let n=new Map,r=`_snt_asgn${bt(t)}_`,a=(i,s)=>`${r}${encodeURIComponent(i)}:${encodeURIComponent(s)}`,o=i=>{let s=i.slice(r.length),c=s.indexOf(":");if(c<0)return null;try{return{componentId:decodeURIComponent(s.slice(0,c)),segment:decodeURIComponent(s.slice(c+1))}}catch(d){return null}},l=()=>{try{let i=[];for(let s=0;s<localStorage.length;s++){let c=localStorage.key(s);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 l())try{let s=localStorage.getItem(i);if(!s)continue;let c=JSON.parse(s);if(u(c)){localStorage.removeItem(i);continue}let d=o(i);if(!d)continue;n.set(Ee(d.componentId,d.segment),c)}catch(s){}})(),{get(i,s){let c=n.get(Ee(i,s));return c?u(c)?(n.delete(Ee(i,s)),null):c:null},set(i,s,c){let d=Ee(i,s);n.set(d,c);try{localStorage.setItem(a(i,s),JSON.stringify(c))}catch(m){}},invalidate(i){let s=`${encodeURIComponent(i)}:`;for(let c of[...n.keys()])c.startsWith(s)&&n.delete(c);for(let c of l()){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 l())try{localStorage.removeItem(i)}catch(s){}}}}var Te="_snt_snap:",Fn=["low","medium","high"];function Le(e){try{let t=localStorage.getItem(Te+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"||!Fn.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 ve(e,t){try{localStorage.setItem(Te+e,JSON.stringify(t))}catch(n){}}var Ve="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",Et="[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.",yt=!1,Ce=!1;function Hn(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function Yn(e){var t;let n=wt({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),r=(t=n.getSessionId())!=null?t:"local",a=Hn(),o=Promise.resolve().then(()=>(ht(),mt)).then(i=>{let s=i;return s.LOCAL_ENGINE_AVAILABLE?(yt||(yt=!0,console.info(Et)),s):(Ce||(Ce=!0,console.error(Ve)),null)}).catch(()=>(Ce||(Ce=!0,console.error(Ve)),null)),l=null;function u(i){let s=document.documentElement;s.dataset.sentientPersona===void 0&&(s.dataset.sentientPersona=i.persona,s.dataset.sentientConfidence=ce(i.confidence))}return{isLocal:!0,async decide(i){var s,c,d;let m=await o;if(!m)return null;let w=m.createLocalEngine({sessionId:r,forcedPersona:a}).decide(i);return l=he(T({},w),{layoutOrder:(c=(s=w.layoutOrder)!=null?s:l==null?void 0:l.layoutOrder)!=null?c:null,slots:T(T({},(d=l==null?void 0:l.slots)!=null?d:{}),w.slots)}),ve(e.apiKey||"local",{v:1,persona:l.persona,band:ce(l.confidence),slots:l.slots,layoutOrder:l.layoutOrder,savedAt:Date.now()}),u(w),w},getSlotResult(i){var s,c,d;return(d=(c=l==null?void 0:l.slots[i])!=null?c:(s=e.initialSlots)==null?void 0:s[i])!=null?d:null},getPersona(){return l?{persona:l.persona,confidence:l.confidence,band:ce(l.confidence)}:null},async assign(i,s){var c;let d=await o;return!d||!s||s.length===0?s!=null&&s[0]?{variantId:s[0],assignmentTtlMs:0}:null:{variantId:(c=d.createLocalEngine({sessionId:r,forcedPersona:a}).decide({components:[{id:i,variantIds:s}]}).assignments[i])!=null?c:s[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function be(e,t,n,r){let a=[];{let o=!1,l=[],u=()=>{if(o)return;let i=Date.now();for(l.push(i);l.length>0&&i-l[0]>500;)l.shift();l.length>=3&&(o=!0,e("rage_click"))};t.addEventListener("click",u),a.push(()=>t.removeEventListener("click",u))}{let o=!1,l=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,s=i?i.toString().length:0;e("text_copy",{selectionLength:s})};document.addEventListener("copy",l),a.push(()=>document.removeEventListener("copy",l))}{let o=!1,l=!1,u=null,i=()=>{u!==null&&(clearTimeout(u),u=null)},s=()=>{o||!l||(i(),u=setTimeout(()=>{!o&&l&&(o=!0,e("scroll_hesitation"))},3e3))},c=()=>{i(),s()},d=w=>{for(let E of w)l=E.intersectionRatio>.3,l?s():i()},m=new IntersectionObserver(d,{threshold:[.3]});m.observe(t),window.addEventListener("scroll",c,{passive:!0}),a.push(()=>{m.disconnect(),window.removeEventListener("scroll",c),i()})}if((r==null?void 0:r.tabLoss)!==!1){let o=!1,l=n!=null?n:Date.now(),u=()=>{if(o||document.visibilityState!=="hidden")return;let i=Date.now()-l;i<15e3&&(o=!0,e("tab_loss",{timeOnPage:i}))};document.addEventListener("visibilitychange",u),a.push(()=>document.removeEventListener("visibilitychange",u))}return()=>{for(let o of a)o()}}var Ct="https://api.sentient-ui.com/v1/events",z=new Map,Ot=null;function Xn(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}function ze(){return vt()}function Je(){var e;if(typeof window!="undefined")return((e=window.location)==null?void 0:e.pathname)||void 0}function Zn(e,t){let n=typeof window=="undefined"?null:window.history;if(!n)return;let r,a=()=>{let o=Je();!o||o===r||(r=o,e.track({projectId:t,componentId:"__page__",eventType:"pageview",payload:{}}))};for(let o of["pushState","replaceState"]){let l=n[o];n[o]=function(...u){let i=l.apply(this,u);return a(),i}}window.addEventListener("popstate",a),a()}var ye={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 Qn(){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 _t(e){return e.replace(/\/events\/?$/,"")}function ue(){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 Fe(e){var t;if(typeof window=="undefined")return;let n=e!=null?e:Ot;if(!n){console.warn("[sentient] grantConsent() called before init()");return}let r=z.get(n);if(!r){console.warn("[sentient] grantConsent() called before init()");return}let{config:a,upgrade:o}=r;if(!o||a.respectDoNotTrack!==!1&&ue())return;let l=Re(he(T({},a),{consent:!0}));o(l);let u=(t=z.get(n))==null?void 0:t.dispose;z.set(n,{config:he(T({},a),{consent:!0}),upgrade:null,dispose:u})}function er(e){var t;let n=e.preConsentBehavior==="statistical_winner",r=_t((t=e.ingestUrl)!=null?t:Ct),a={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(i,s,c){if(!n)return null;try{let d=new URLSearchParams({componentId:i});for(let w of s!=null?s:[])d.append("variantIds[]",w);let m=await fetch(`${r}/winner?${d.toString()}`,{headers:a});return m.ok?{variantId:(await m.json()).variantId,assignmentTtlMs:0}:s!=null&&s[0]?{variantId:s[0],assignmentTtlMs:0}:null}catch(d){return s!=null&&s[0]?{variantId:s[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},l={track:i=>o.track(i),goal:((i,s,c,d)=>o.goal(i,s,c,d)),componentGoal:(i,s,c)=>o.componentGoal(i,s,c),identify:i=>o.identify(i),getAssignment:(i,s)=>o.getAssignment(i,s),assign:(i,s,c,d)=>o.assign(i,s,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:l,setInner:u}}function Re(e){var t,n,r,a,o,l,u,i,s;if(typeof window=="undefined")return ye;Ot=e.apiKey;let c=z.get(e.apiKey||"local");if(c!=null&&c.dispose)try{c.dispose()}catch(p){}let d=e.respectDoNotTrack!==!1&&ue(),m=e.consent===!1||d,w=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!w&&e.localMode!==!1)return m?(z.set(e.apiKey||"local",{config:e,upgrade:null}),ye):(z.set(e.apiKey||"local",{config:e,upgrade:null}),Yn(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."),z.set(e.apiKey,{config:e,upgrade:null}),ye;let{proxy:p,setInner:y}=er(e);return z.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."),ye;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),ye;let E=(t=e.ingestUrl)!=null?t:Ct,C=Date.now(),k=wt({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),g=Jn(void 0,e.apiKey),f=Gn({ingestUrl:E,apiKey:e.apiKey}),x=_t(E),O={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},q=zn({url:`${x}/goals`,apiKey:e.apiKey,headers:O,onDrop:(p,y)=>{e.debug&&console.warn(`[sentient] goal dropped (HTTP ${y}) \u2014 this will not be retried. `+(y===400?"The session was not found: call init() and let the session upsert complete before firing goals.":y===401||y===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),p)}}),v=ut((n=navigator.userAgent)!=null?n:""),P=typeof window!="undefined"?window.location.origin:void 0,$=dt((r=document.referrer)!=null?r:"",P),D=(a=e.sessionSegment)!=null?a:`${v}:${$}`,S=new Map,A=new Map,b=null,h=p=>{for(let y of p)A.has(y.id)||A.set(y.id,We(y))};if(e.initialSlots)for(let[p,y]of Object.entries(e.initialSlots))A.set(p,y);let I=Le(e.apiKey);if(I)for(let[p,y]of Object.entries(I.slots))A.has(p)||A.set(p,y);let X={low:.15,medium:.5,high:.85};if(e.initialPersona)b=T({},e.initialPersona);else{let p=document.documentElement.dataset;p.sentientPersona?b={persona:p.sentientPersona,confidence:(l=X[(o=p.sentientConfidence)!=null?o:"low"])!=null?l:.15}:I&&(b={persona:I.persona,confidence:(u=X[I.band])!=null?u:.15})}if(e.initialAssignments)for(let[p,y]of Object.entries(e.initialAssignments))g.set(p,D,{variantId:y,assignedAt:Date.now(),segment:D,confidence:1});let K=Promise.resolve(),re=k.getSessionId();if(re){let p=pt((i=document.referrer)!=null?i:""),y=T(T({sessionId:re,deviceClass:v,trafficSource:$,referrerDomain:p,utmParams:Qn(),timeOfDay:ft(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:k.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||ct((s=navigator.userAgent)!=null?s:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{K=fetch(`${x}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(y),headers:O}).then(_=>{_.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.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:f});let te=new Set,de={goal(p,y={},_=1,Z=0){var F,N,H,W;let B=k.getSessionId();if(!B)return;let U=Xn(y)?y:{metadata:y},G=`${p}\0${(F=U.externalId)!=null?F:""}`;if(te.has(G)){e.debug&&console.log(`[sentient] goal("${p}") already recorded for this action \u2014 not sent twice`);return}te.add(G),te.size===1&&setTimeout(()=>te.clear(),0);let oe=ze(),Q={sessionId:B,name:p,metadata:(N=U.metadata)!=null?N:{},weight:(H=U.weight)!=null?H:_,stepIndex:(W=U.stepIndex)!=null?W:Z,goalId:oe,value:U.value,currency:U.currency,externalId:U.externalId};e.debug&&console.log("[sentient] goal",Q);let Ae={id:oe,body:JSON.stringify(Q)};K.then(()=>q.send(Ae))},componentGoal(p,y,_){var Z,F,N;let H=k.getSessionId();if(!H)return;let W=g.get(p,D),B=W?null:(Z=A.get(p))!=null?Z:null;if(!W&&B===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 U=W?W.variantId:gt(B),G={id:ze(),sessionId:H,projectId:e.apiKey,componentId:p,variantId:U,eventType:"goal_achieved",goalType:y,payload:T({reward:(F=_==null?void 0:_.reward)!=null?F:1,goalValue:_==null?void 0:_.value,currency:_==null?void 0:_.currency},(N=_==null?void 0:_.metadata)!=null?N:{}),timestamp:Date.now(),timeInSession:Date.now()-C,path:Je()};e.debug&&console.log("[sentient] componentGoal",G),K.then(()=>f.push(G))},identify(p){let y=k.getSessionId();y&&K.then(()=>{fetch(`${x}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:y,userId:p,ephemeral:k.isEphemeral()}),headers:O}).catch(()=>{})})},track(p){let y=k.getSessionId();if(!y)return;let _=he(T({path:Je()},p),{id:ze(),sessionId:y,timestamp:Date.now(),timeInSession:Date.now()-C});e.debug&&console.log("[sentient] track",_),K.then(()=>f.push(_))},getAssignment(p,y){return g.get(p,y)},async assign(p,y,_,Z){let F=k.getSessionId();if(!F)return null;let N=g.get(p,D);if(N&&(y!=null&&y.length||N.content!==void 0)){let B=N.ttlMs&&N.ttlMs>0?Math.max(0,N.assignedAt+N.ttlMs-Date.now()):0;return{variantId:N.variantId,assignmentTtlMs:B,content:N.content}}let H=S.get(p);if(H)return H;let W=(async()=>{await K;try{let B={sessionId:F,componentId:p,variantIds:y};Z!==void 0?B.agentDataByVariant=Z:_!==void 0&&(B.agentData=_);let U=await fetch(`${x}/assign`,{method:"POST",body:JSON.stringify(B),headers:O});if(!U.ok)return null;let G=await U.json();return g.set(p,D,T({variantId:G.variantId,assignedAt:Date.now(),segment:D,confidence:1,content:G.content},G.assignmentTtlMs&&G.assignmentTtlMs>0?{ttlMs:G.assignmentTtlMs}:{})),G}catch(B){return null}finally{S.delete(p)}})();return S.set(p,W),W},async decide(p){var y,_,Z,F,N,H,W,B,U;let G=k.getSessionId();if(!G)return null;let oe=(y=p.slots)!=null?y:[];await K;try{let Q={sessionId:G};p.sections&&p.sections.length>0&&(Q.sections=p.sections.map(J=>({id:J}))),Q.components=(_=p.components)!=null?_:[],oe.length>0&&(Q.slots=oe.map(qe)),p.slotsFrom==="registry"&&(Q.slotsFrom="registry"),p.v&&(Q.v=p.v);let Ae=await fetch(`${x}/decide`,{method:"POST",body:JSON.stringify(Q),headers:O});if(!Ae.ok)return h(oe),null;let R=await Ae.json(),ge={};for(let J of oe)ge[J.id]=(F=(Z=R.slots)==null?void 0:Z[J.id])!=null?F:We(J);if(R.slots)for(let[J,me]of Object.entries(R.slots))J in ge||(ge[J]=me);for(let[J,me]of Object.entries(ge))A.set(J,me);let cn=b!=null&&b.persona!=="unknown";R.persona&&!(R.persona==="unknown"&&cn)?b={persona:R.persona,confidence:(N=R.confidence)!=null?N:0}:b||(b={persona:"unknown",confidence:0});for(let[J,me]of Object.entries((H=R.assignments)!=null?H:{}))g.set(J,D,{variantId:me,assignedAt:Date.now(),segment:D,confidence:1});return ve(e.apiKey,T({v:1,persona:b.persona,band:ce(b.confidence),slots:Object.fromEntries(A),layoutOrder:(W=R.layoutOrder)!=null?W:null,savedAt:Date.now()},R.slotConfig?{slotConfig:R.slotConfig}:{})),T(T(T({layoutOrder:(B=R.layoutOrder)!=null?B:null,assignments:(U=R.assignments)!=null?U:{},slots:ge,persona:b.persona,confidence:b.confidence},R.slotConfig?{slotConfig:R.slotConfig}:{}),R.goals?{goals:R.goals}:{}),R.sectionMap?{sectionMap:R.sectionMap}:{})}catch(Q){return h(oe),null}},getSlotResult(p){var y;return(y=A.get(p))!=null?y:null},getPersona(){return b?{persona:b.persona,confidence:b.confidence,band:ce(b.confidence)}:null},async fetchWeights(){var p;try{let y=await fetch(`${x}/weights`,{headers:O});return y.ok?(p=(await y.json()).components)!=null?p:[]:[]}catch(y){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var p;f.destroy(),q.destroy(),((p=z.get(e.apiKey))==null?void 0:p.dispose)===de.dispose&&z.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var p;f.destroy(),q.destroy(),k.destroy(),((p=z.get(e.apiKey))==null?void 0:p.dispose)===de.dispose&&z.delete(e.apiKey);try{localStorage.removeItem(Te+e.apiKey),localStorage.removeItem(It(e.apiKey)),localStorage.removeItem(kt(e.apiKey))}catch(y){}e.debug&&console.log("[sentient] destroyed")}};if(z.set(e.apiKey,{config:e,upgrade:null,dispose:de.dispose}),Zn(de,e.apiKey),e.debug){let p=window;p.__sentient&&(p.__sentient.client=de)}return de}var Tt=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],tr=[["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]],nr=[["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 rr(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function Lt(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 tr)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of nr)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 Rt(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:rr(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function Pt(e){return Lt(Rt(e)).type}Ie();var Mt="section, header, footer, nav, main > div, [data-sentient-section]";function or(e){var t;return((t=e.parentElement)==null?void 0:t.closest(Mt))!=null}function ir(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(a){}}var Dt=()=>{};function $t(e,t){var n,r,a,o,l,u,i,s,c;let d=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!d||typeof IntersectionObserver=="undefined"||ue()||!t.apiKey)return Dt;let m=((r=t.apiBase)!=null?r:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),w=Array.from(d.querySelectorAll(Mt)).filter(S=>!or(S));if(w.length===0)return Dt;let E=new Map,C=new Map,k=new Map;for(let S of w){let A=S.getAttribute("data-sentient-type"),b=A&&Tt.includes(A)?A:null,h=(o=b!=null?b:(a=t.typeOf)==null?void 0:a.call(t,S))!=null?o:Pt(S),I=`nc-${h}`;E.set(S,I),C.set(I,h),b?k.set(I,"markup"):k.has(I)||k.set(I,"auto")}let g=(s=(i=(u=(l=d.defaultView)!=null?l:typeof window!="undefined"?window:void 0)==null?void 0:u.location)==null?void 0:i.pathname)!=null?s:"/";ir(t.apiKey,m,g,[...C.entries()].map(([S,A])=>{var b;return{componentId:S,semanticType:A,source:(b=k.get(S))!=null?b:"auto"}}));let f=new Map,x=S=>{let A=f.get(S);return A||(A={ms:0,scroll:0,enterAt:null,intersecting:!1},f.set(S,A)),A},O=new IntersectionObserver(S=>{for(let A of S){let b=E.get(A.target);if(!b)continue;let h=x(b);A.isIntersecting?(h.intersecting=!0,h.enterAt=Date.now(),A.intersectionRatio>h.scroll&&(h.scroll=A.intersectionRatio)):(h.intersecting=!1,h.enterAt!=null&&(h.ms+=Date.now()-h.enterAt,h.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let S of E.keys())O.observe(S);let q=()=>{let S=Date.now();for(let[A,b]of f)if(b.enterAt!=null&&(b.ms+=S-b.enterAt,b.enterAt=null),!(b.ms<=0)){try{e.track({projectId:t.apiKey,componentId:A,eventType:"dwell",payload:{dwell_time:Math.round(b.ms),scroll_depth:Number(b.scroll.toFixed(2))}})}catch(h){}b.ms=0}},v=()=>{if(d.hidden)q();else{let S=Date.now();for(let A of f.values())A.intersecting&&(A.enterAt=S)}},P=()=>{q();try{O.disconnect()}catch(S){}};d.addEventListener("visibilitychange",v);let $=(c=d.defaultView)!=null?c:typeof window!="undefined"?window:void 0;$==null||$.addEventListener("pagehide",P);let D=[];return t.microSignals&&[...E.entries()].forEach(([S,A],b)=>{D.push(be((h,I={})=>{try{e.track({projectId:t.apiKey,componentId:A,eventType:"micro_signal",payload:T({signalType:h},I)})}catch(X){}},S,void 0,{tabLoss:b===0}))}),()=>{q(),d.removeEventListener("visibilitychange",v),$==null||$.removeEventListener("pagehide",P);for(let S of D)S();try{O.disconnect()}catch(S){}}}var sr=["landing","ecommerce","saas","marketplace"];function ar(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,a]of t){if(!Array.isArray(a)||a.length<2||a.length>6||!a.every(o=>typeof o=="string"))return null;n[r]=a}return n}function lr(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function Pe(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=sr.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[o,l]of Object.entries(t.slots)){if(typeof l!="object"||l===null)continue;let u=l,i=ar(u.dims);if(!i||u.target!==void 0&&typeof u.target!="string")continue;let s=u.arms!==void 0?lr(u.arms):null,c={dims:i};typeof u.target=="string"&&(c.target=u.target),s&&(c.arms=s),r[o]=c}let a={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};return typeof t.consent=="boolean"&&(a.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(a.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(a.debug=!0),typeof t.registry=="boolean"&&(a.registry=t.registry),typeof t.editorSrc=="string"&&(a.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(a.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(a.sectionCapture=t.sectionCapture),a}function Nt(e){var n,r,a;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(a=t==null?void 0:t.pathname)!=null?a:""}function cr(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(),a=t.text.trim().toLowerCase();if(!(r===a||r.startsWith(a)||a.startsWith(r)))return!1}return!0}function jt(e,t){return!!(e!=null&&e.urlMatch)&&!Nt(t).includes(e.urlMatch)}var ur=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function ie(e,t){var a;if(e.urlMatch&&!Nt(t).includes(e.urlMatch))return null;let n=[];if(e.id){let o=t.getElementById(e.id);n=o?[o]:[]}if(n.length===0&&((a=e.dataAttr)!=null&&a.name)&&ur.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&&!cr(r,e.fingerprint)?null:r}var Kt={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"},dr=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function Bt(e){var t;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;for(let n of e.matchAll(/([A-Za-z-]*)\(/g))if(!dr.test((t=n[1])!=null?t:""))return!1;return!0}var Ut=/^https:\/\//i,Gt=new Map,se=null;function pr(e){return e.replace(/["\\]/g,"\\$&")}function fr(e){var t;(!se||!se.isConnected)&&(se=e.querySelector("style[data-sentient-ops]"),se||(se=e.createElement("style"),se.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(se))),se.textContent=[...Gt.entries()].map(([n,r])=>`[data-snt-e="${pr(n)}"]{${r}}`).join(`
2
+ `)}function qt(e,t,n,r){var u;let a=!1,o=(u=t.moveBefore)!=null?u:t.moveAfter;if(o){let i=ie(o,r);!i||i===e||i.parentElement!==e.parentElement||!e.parentElement?a=!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"&&Ut.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&Ut.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let l=[];if(t.hidden&&l.push("display:none !important"),t.style)for(let[i,s]of Object.entries(t.style)){let c=Kt[i];c&&typeof s=="string"&&Bt(s)&&l.push(`${c}:${s.trim()} !important`)}return l.length>0&&(e.setAttribute("data-snt-e",n),Gt.set(n,l.join(";")),fr(r)),{anchorMiss:a}}function De(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function Me(e,t,n){var r;for(let[a,o]of Object.entries(t)){let l=e[a];if(!l||typeof l=="string")continue;let u=o.target?Array.from(n.querySelectorAll(o.target)):[n.documentElement];for(let i of u)for(let[s,c]of Object.entries(l))(r=o.dims[s])!=null&&r.includes(c)&&i.setAttribute(`data-${s}`,c)}}function $e(e,t,n){for(let[r,a]of Object.entries(t)){let o=e[r];if(typeof o!="string"||!a.arms||!a.arms.includes(o))continue;let l=a.target?Array.from(n.querySelectorAll(a.target)):[n.documentElement];for(let u of l)u.setAttribute("data-sentient-arm",o)}}function Ne(e,t,n,r){var l,u;let a=(l=r==null?void 0:r.contentAndOps)!=null?l:!0,o=[];for(let[i,s]of Object.entries(t)){if(jt(s.locator,n))continue;let c;if(s.locator){let m=ie(s.locator,n);c=m?[m]:[]}else s.target?c=Array.from(n.querySelectorAll(s.target)):c=[n.documentElement];(s.locator||s.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),a&&((u=r==null?void 0:r.onApplied)==null||u.call(r,i,d,m));else for(let[w,E]of Object.entries(d))m.setAttribute(`data-${w}`,E);a&&(typeof s.content=="string"&&(m.textContent=s.content),s.ops&&qt(m,s.ops,i,n).anchorMiss&&!o.includes(i)&&o.push(i))}}return o}var gr=800;function je(e,t,n){let r=[];return n.forEach(({slotId:a,arm:o,el:l},u)=>{r.push(be((m,w={})=>{try{e.track({projectId:t,componentId:a,variantId:o,eventType:"micro_signal",payload:le({signalType:m},w)})}catch(E){}},l,void 0,{tabLoss:u===0}));let i=null,s=0,c=()=>{s=Date.now(),i=setTimeout(()=>{try{e.track({projectId:t,componentId:a,variantId:o,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-s}})}catch(m){}i=null},gr)},d=()=>{i!==null&&(clearTimeout(i),i=null)};l.addEventListener("mouseenter",c),l.addEventListener("mouseleave",d),r.push(()=>{l.removeEventListener("mouseenter",c),l.removeEventListener("mouseleave",d),i!==null&&clearTimeout(i)})}),()=>{for(let a of r)a()}}function mr(e){var n,r,a;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(a=t==null?void 0:t.pathname)!=null?a:""}function hr(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}/`)}var Wt="_snt_fired_goals";function yr(e){try{let t=e==null?void 0:e.sessionStorage.getItem(Wt);if(!t)return new Set;let n=JSON.parse(t);return Array.isArray(n)?new Set(n.filter(r=>typeof r=="string")):new Set}catch(t){return new Set}}function vr(e,t){try{e==null||e.sessionStorage.setItem(Wt,JSON.stringify([...t]))}catch(n){}}function zt(e,t,n){var C,k;let r=(C=n.defaultView)!=null?C:typeof window!="undefined"?window:null,a=yr(r),o=g=>{if(!a.has(g.goalId)){a.add(g.goalId),vr(r,a);try{g.slotId?t.componentGoal(g.slotId,g.goalId):t.goal(g.goalId)}catch(f){}}},l=e.filter(g=>g.event==="click"),u=e.filter(g=>g.event==="form_submit"),i=e.filter(g=>g.event==="url_reached"),s=e.filter(g=>g.event==="scroll_depth"),c=(g,f)=>{if(!g.locator)return!1;let x=ie(g.locator,n);return!!x&&(x===f||x.contains(f))},d=g=>{let f=g.target;if(!(!f||typeof f.closest!="function"))for(let x of l)c(x,f)&&o(x)},m=g=>{let f=g.target;if(f)for(let x of u)c(x,f)&&o(x)},w=()=>{if(i.length===0)return;let g=mr(n);for(let f of i)f.urlPattern&&hr(f.urlPattern,g)&&o(f)},E=()=>{var x;let g=n.documentElement,f=g.scrollHeight>0?(g.scrollTop+g.clientHeight)/g.scrollHeight:0;for(let O of s)f>=((x=O.threshold)!=null?x:.75)&&o(O);s.every(O=>a.has(O.goalId))&&n.removeEventListener("scroll",E)};return n.addEventListener("click",d,!0),n.addEventListener("submit",m,!0),(k=n.defaultView)==null||k.addEventListener("popstate",w),w(),s.length>0&&(n.addEventListener("scroll",E,{passive:!0}),E()),{checkUrl:w,teardown:()=>{var g;n.removeEventListener("click",d,!0),n.removeEventListener("submit",m,!0),(g=n.defaultView)==null||g.removeEventListener("popstate",w),s.length>0&&n.removeEventListener("scroll",E)}}}var Vt="__snt_editor_token";function Jt(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(Vt):null}catch(e){return null}}function Ft(e){try{sessionStorage.setItem(Vt,e)}catch(t){}}var Ye="0.15.0",tn=5e3,br=50,wr=(()=>{try{if(typeof window=="undefined")return[];let e=window.SentientSnippet;return Array.isArray(e==null?void 0:e.q)?e.q:[]}catch(e){return[]}})(),V=null,M=null,ne={},ae=null,Y=null,j=null,ee=null,L=null,Ht=!1,He=null,Ke=null,Be=null,we=!1,Ue=!1;function nn(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function pe(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function fe(e,t){return V?(V.personaAttributes&&L&&De(L.persona,L.band,e),Me(ne,V.slots,e),$e(ne,V.slots,e),ae?Ne(ne,ae,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 Se(){return!!(V&&M&&V.sectionCapture!==!1&&(V.consent!==!1||Ue)&&!ue())}function Ar(){if(!M||!V||!Se()||ee)return;let e=[];fe(document,{contentAndOps:we,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),Ze();try{j==null||j(),j=je(M,V.apiKey,e)}catch(t){}}function Ze(){if(typeof document=="undefined"||!Se())return;let e;try{if(Ke&&Ke.length>0){let t=new Map;for(let n of Ke){if(n.urlMatch!==window.location.pathname)continue;let r=ie(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{ee=$t(M,le({apiKey:V.apiKey,apiBase:V.apiBase,doc:document,microSignals:!0},e?{typeOf:e}:{})),Be=window.location.pathname}catch(t){}}function Qe(){try{let e=[];if(j==null||j(),j=null,fe(document,{contentAndOps:we,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),e.length>0&&Se())try{j=je(M,V.apiKey,e)}catch(t){}try{typeof window!="undefined"&&Be!==null&&window.location.pathname!==Be&&Se()&&(ee==null||ee(),ee=null,Ze())}catch(t){}}catch(e){}}function Yt(){He===null&&(He=setTimeout(()=>{He=null,Qe();try{Y==null||Y.checkUrl()}catch(e){}},br))}function Xt(){if(!(Ht||typeof window=="undefined"||typeof history=="undefined")){Ht=!0;try{let e=t=>{let n=history[t];history[t]=function(r,a,o){let l=n.call(this,r,a,o!=null?o:null);return Yt(),l}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Yt)}catch(e){}}}function Xe(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 rn(e){return new URLSearchParams(e).get("sentient_editor")}function xr(){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 Ir(e,t){var n,r,a,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 l=(a=e.editorSrc)!=null?a:xr();if(!l){Qt();return}let u=document.createElement("script");u.src=l,u.async=!0,u.onerror=()=>Qt(),((o=document.head)!=null?o:document.documentElement).appendChild(u)}catch(l){}}var Zt="sentient-editor-load-notice";function Qt(){var e;try{if(typeof document=="undefined"||document.getElementById(Zt))return;let t=document.createElement("div");t.id=Zt,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 on(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let a=r.indexOf(":"),o=a===-1?"":r.slice(0,a),l=a===-1?"":r.slice(a+1);if(!(!o||!l))if(l.includes("=")){let u={};for(let i of l.split(",")){let[s,c]=i.split("=");s&&c&&(u[s]=c)}Object.keys(u).length&&(n[o]=u)}else n[o]=l}return Object.keys(n).length?n:null}function sn(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var en="sentient-persona-preview-banner";function kr(e){var t;try{if(typeof document=="undefined"||document.getElementById(en))return;let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),r=document.createElement("div");r.id=en,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 a=document.createElement("span");a.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 l=new URL(window.location.href);l.searchParams.delete("sentient_persona"),window.location.href=l.pathname+l.search+l.hash}catch(l){}}),r.appendChild(a),r.appendChild(o),((t=document.body)!=null?t:document.documentElement).appendChild(r)}catch(n){}}async function Er(e,t){var s,c,d,m,w,E,C,k,g;let n=(s=e.apiBase)!=null?s:"https://api.sentient-ui.com",a=((c=e.registry)!=null?c:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([f,x])=>({id:f,dims:x.dims}))},o=await nn(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(a)}).then(f=>f.ok?f.json():null).catch(()=>null),tn);if(!o){pe(e,"persona preview: explain unavailable \u2014 page left as-is");return}let l=o;ne=(d=l.slots)!=null?d:{},ae=(m=l.slotConfig)!=null?m:null;let u=(C=(E=(w=l.personaAttributes)==null?void 0:w.persona)!=null?E:l.persona)!=null?C:t,i=(g=(k=l.personaAttributes)==null?void 0:k.confidence)!=null?g:"high";L={persona:u,band:i},fe(document),we=!0,an(e),kr(u)}function an(e){let t={goal(n,r){try{M==null||M.goal(n,r)}catch(a){}},componentGoal(n,r){try{M==null||M.componentGoal(n,r)}catch(a){}},grantConsent(){try{Fe(e.apiKey)}catch(n){}Ue=!0;try{Ar()}catch(n){}},revokeConsent(){try{ee==null||ee(),ee=null,Be=null,j==null||j(),j=null,Y==null||Y.teardown(),Y=null,Ue=!1,M==null||M.destroy()}catch(n){}},reapply:Qe,getState(){var n,r;return{apiKey:e.apiKey,persona:(n=L==null?void 0:L.persona)!=null?n:null,band:(r=L==null?void 0:L.band)!=null?r:null,slots:ne,matchCounts:Xe(e),consent:e.consent!==!1}}};window.SentientSnippet=t;for(let n of wr.splice(0))try{n[0]==="goal"&&t.goal(n[1],n[2])}catch(r){}}async function ln(){var e,t,n,r,a;try{let o=Pe(window.sentient);if(!o)return;V=o,we=!1,Ue=!1;let l=typeof window!="undefined"?rn(window.location.search):null;if(l){Ft(l);try{let f=new URL(window.location.href);f.searchParams.delete("sentient_editor"),window.history.replaceState(null,"",f.pathname+f.search+f.hash)}catch(f){}}let u=l!=null?l:Jt();if(u){Ir(o,u),pe(o,"editor mode");return}let i=typeof window!="undefined"?on(window.location.search):null;if(i){ne=i,L=null,fe(document),Xt(),pe(o,"preview mode",i);return}let s=typeof window!="undefined"?sn(window.location.search):null;if(s){await Er(o,s),pe(o,"persona preview",s);return}let c=(e=o.registry)!=null?e:Object.keys(o.slots).length===0,d=Le(o.apiKey);d&&(L={persona:d.persona,band:d.band},ne=d.slots,d.slotConfig&&(ae=d.slotConfig),fe(document,{contentAndOps:!1}));let m=Re({apiKey:o.apiKey,context:o.context,consent:o.consent,preConsentBehavior:o.preConsentBehavior,debug:o.debug});M=m,an(o),Xt();let w=Object.entries(o.slots).map(([f,x])=>({id:f,dims:x.dims})),E=Ye!=="0.0.0-dev"?{v:Ye}:{},C=await nn(m.decide(le(le({slots:w},E),c?{slotsFrom:"registry"}:{})),tn);if(!C){pe(o,"decide timeout/null \u2014 snapshot state stands",Xe(o));return}let k=m.getPersona();k?L={persona:k.persona,band:k.band}:C.persona&&(L={persona:C.persona,band:"low"}),ne=C.slots,c?ae=(t=C.slotConfig)!=null?t:null:C.slotConfig&&(ae=C.slotConfig);let g=[];if(Sr(o,fe(document,{onApplied:(f,x,O)=>g.push({slotId:f,arm:x,el:O})})),we=!0,C.goals&&C.goals.length>0&&o.consent!==!1&&M)try{Y==null||Y.teardown(),Y=zt(C.goals,M,document)}catch(f){}if(Ke=(n=C.sectionMap)!=null?n:null,Se()){Ze();try{j==null||j(),j=je(M,o.apiKey,g)}catch(f){}}pe(o,"applied",{persona:L,slots:ne,matches:Xe(o)}),ve(o.apiKey,le({v:1,persona:(r=L==null?void 0:L.persona)!=null?r:C.persona,band:(a=L==null?void 0:L.band)!=null?a:"low",slots:C.slots,layoutOrder:C.layoutOrder,savedAt:Date.now()},ae?{slotConfig:ae}:{}))}catch(o){}}if(typeof window!="undefined"&&window.sentient){let e=window;e.__sentientInitialized||(e.__sentientInitialized=!0,ln())}return gn(Cr);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentientui/snippet",
3
- "version": "0.14.0",
3
+ "version": "0.15.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.18.0"
27
+ "@sentientui/core": "0.19.0"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "tsup",