@sentientui/snippet 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var SentientSnippet=(()=>{var he=Object.defineProperty;var Jt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames,We=Object.getOwnPropertySymbols;var Je=Object.prototype.hasOwnProperty,Ft=Object.prototype.propertyIsEnumerable;var ze=(e,t,n)=>t in e?he(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oe=(e,t)=>{for(var n in t||(t={}))Je.call(t,n)&&ze(e,n,t[n]);if(We)for(var n of We(t))Ft.call(t,n)&&ze(e,n,t[n]);return e};var Ve=(e,t)=>()=>(e&&(t=e(e=0)),t);var Fe=(e,t)=>{for(var n in t)he(e,n,{get:t[n],enumerable:!0})},Ht=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Vt(t))!Je.call(e,o)&&o!==n&&he(e,o,{get:()=>t[o],enumerable:!(r=Jt(t,o))||r.enumerable});return e};var Yt=e=>Ht(he({},"__esModule",{value:!0}),e);var Xt,Zt,Qt,He,en,tn,Ye,O,de,ye=Ve(()=>{"use strict";Xt=Object.defineProperty,Zt=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,He=Object.getOwnPropertySymbols,en=Object.prototype.hasOwnProperty,tn=Object.prototype.propertyIsEnumerable,Ye=(e,t,n)=>t in e?Xt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,O=(e,t)=>{for(var n in t||(t={}))en.call(t,n)&&Ye(e,n,t[n]);if(He)for(var n of He(t))tn.call(t,n)&&Ye(e,n,t[n]);return e},de=(e,t)=>Zt(e,Qt(t))});var it={};Fe(it,{LOCAL_ENGINE_AVAILABLE:()=>on,createLocalEngine:()=>sn});function sn(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var on,st=Ve(()=>{"use strict";on=!1});var Xn={};Fe(Xn,{applyPersonaAttributes:()=>Ie,applyRegistrySlots:()=>Ce,applySlotArms:()=>Oe,applySlotAttributes:()=>Ee,parseEditorToken:()=>Ut,parsePersonaPreview:()=>qt,parsePreview:()=>Gt,parseSnippetConfig:()=>Ae,reapply:()=>Ue,run:()=>zt,version:()=>$t});ye();function ve(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function Xe(e){if(e.length===0)return null;let t={};for(let n of e.split("|")){let r=n.indexOf("=");if(r<=0||r!==n.lastIndexOf("=")||r===n.length-1)return null;let o=n.slice(0,r);if(o in t)return null;t[o]=n.slice(r+1)}return t}function Re(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 ve(e.baseline);if(typeof e.baseline=="string")return e.baseline;let o={};for(let[i,s]of Object.entries((n=e.dims)!=null?n:{}))o[i]=(r=s[0])!=null?r:"";return ve(o)}function Ze(e,t){var n,r;return e.dims!=null?(r=(n=Xe(t))!=null?n:Xe(Re(e)))!=null?r:{}:t}function Q(e){return e>=.3?e<.7?"medium":"high":"low"}var nn=["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 Qe(e){return rn(e)!==null}function rn(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=nn.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function et(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 tt(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(o){}let r=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(n){return"direct"}}function nt(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function rt(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function Te(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 Pe(e){let t=Te(e);return Ze(t,Re(t))}function ot(e){return typeof e=="string"?e:ve(e)}ye();var an="_snt_uid",ie="_snt_uid";function ln(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function cn(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function un(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function dn(e){try{return localStorage.getItem(e)}catch(t){return null}}function pn(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function fn(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function gn(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function mn(e){try{sessionStorage.removeItem(e)}catch(t){}}function hn(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function yn(e){try{localStorage.removeItem(e)}catch(t){}}function vn(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var bn={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ct(e){var t,n,r,o,i,s;if(typeof window=="undefined")return bn;let a=(t=e==null?void 0:e.cookieName)!=null?t:an,c=((n=e==null?void 0:e.cookieTTLDays)!=null?n:365)*24*60*60,l=(s=(i=(o=(r=cn(a))!=null?r:dn(ie))!=null?o:fn(ie))!=null?i:e==null?void 0:e.ssrSessionId)!=null?s:ln();un(a,l,c);let u=pn(ie,l),g=hn(a),m=u?!1:gn(ie,l),f=!u&&!g&&!m;return{getSessionId:()=>l,isEphemeral:()=>f,destroy:()=>{l=null,vn(a),yn(ie),mn(ie)}}}function ut(e){return`_snt_retry_${e.slice(0,12)}`}var wn={push:()=>{},flush:()=>{},destroy:()=>{}};function Sn(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 Le(e,t,n){try{let r=[...(()=>{try{let o=localStorage.getItem(n);if(!o)return[];let i=JSON.parse(o);return Array.isArray(i)?i:[]}catch(o){return[]}})(),...e].slice(-t);localStorage.setItem(n,JSON.stringify(r))}catch(r){}}function xn(e){var t,n,r;if(typeof window=="undefined")return wn;let o=(t=e.flushIntervalMs)!=null?t:5e3,i=(n=e.maxBatchSize)!=null?n:20,s=(r=e.maxRetrySize)!=null?r:100,a=e.ingestUrl,c=e.apiKey,l=ut(c),u=[],g=new Set,m=[],f=p=>{for(let v of p)b.delete(v),!g.has(v)&&(g.add(v),m.push(v));for(;m.length>500;){let v=m.shift();v&&g.delete(v)}},b=new Set,S=p=>{g.has(p.id)||b.has(p.id)||(b.add(p.id),u.push(p))},w=Sn(s,l);for(let p of w)S(p);let A=0,x=0,C=p=>{if(p.length===0)return;let v=JSON.stringify(p),I=p.map(d=>d.id),$;try{$=fetch(a,{method:"POST",keepalive:!0,body:v,headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`}})}catch(d){Le(p,s,l);for(let h of I)b.delete(h);x++,A=Date.now()+Math.min(6e4,1e3*2**Math.min(x,6));return}let z=d=>{if(d.ok||d.status>=400&&d.status<500&&d.status!==429){f(I),x=0,A=0;return}Le(p,s,l);for(let h of I)b.delete(h);x++,A=Date.now()+Math.min(6e4,1e3*2**Math.min(x,6))};$ instanceof Promise?$.then(z).catch(()=>{Le(p,s,l);for(let d of I)b.delete(d);x++,A=Date.now()+Math.min(6e4,1e3*2**Math.min(x,6))}):z($)},G=typeof TextEncoder!="undefined"?new TextEncoder:null,H=p=>G?G.encode(p).length:p.length,Y=p=>{let v=[],I=2;for(let $ of p){let z=H(JSON.stringify($))+1;if(v.length>0&&I+z>57344||v.length>=i)break;v.push($),I+=z}return v},_=()=>{try{if(Date.now()<A)return;for(;u.length>0;){let p=u.filter(I=>!g.has(I.id));if(u.length=0,p.length===0)break;let v=Y(p);if(v.length===0)break;v.length<p.length&&u.push(...p.slice(v.length)),C(v)}}catch(p){}},M=!0,T=null;T=setInterval(()=>{M&&_()},o);let y=()=>{document.visibilityState==="hidden"&&_()},k=()=>{_()};return document.addEventListener("visibilitychange",y),window.addEventListener("pagehide",k),{push(p){S(p),u.length>=i&&_()},flush:_,destroy(){M=!1,T!==null&&(clearInterval(T),T=null),document.removeEventListener("visibilitychange",y),window.removeEventListener("pagehide",k),_()}}}var Ne="_snt_asgn_";function be(e,t){return`${e}:${t}`}function kn(e,t){return`${Ne}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function at(e){let t=e.slice(Ne.length),n=t.indexOf(":");if(n<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,n)),segment:decodeURIComponent(t.slice(n+1))}}catch(r){return null}}function De(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(Ne)&&e.push(n)}return e}catch(e){return[]}}function An(e=18e5){let t=new Map,n=r=>r.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let r of De())try{let o=localStorage.getItem(r);if(!o)continue;let i=JSON.parse(o);if(n(i)){localStorage.removeItem(r);continue}let s=at(r);if(!s)continue;t.set(be(s.componentId,s.segment),i)}catch(o){}})(),{get(r,o){let i=t.get(be(r,o));return i?n(i)?(t.delete(be(r,o)),null):i:null},set(r,o,i){let s=be(r,o);t.set(s,i);try{localStorage.setItem(kn(r,o),JSON.stringify(i))}catch(a){}},invalidate(r){let o=`${r}:`;for(let i of[...t.keys()])i.startsWith(o)&&t.delete(i);for(let i of De()){let s=at(i);if((s==null?void 0:s.componentId)===r)try{localStorage.removeItem(i)}catch(a){}}},clear(){t.clear();for(let r of De())try{localStorage.removeItem(r)}catch(o){}}}}var Se="_snt_snap:",In=["low","medium","high"];function xe(e){try{let t=localStorage.getItem(Se+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"||!In.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 pe(e,t){try{localStorage.setItem(Se+e,JSON.stringify(t))}catch(n){}}var Me="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",dt="[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.",lt=!1,we=!1;function En(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function On(e){var t;let n=ct({ssrSessionId:e.ssrSessionId}),r=(t=n.getSessionId())!=null?t:"local",o=En(),i=Promise.resolve().then(()=>(st(),it)).then(c=>{let l=c;return l.LOCAL_ENGINE_AVAILABLE?(lt||(lt=!0,console.info(dt)),l):(we||(we=!0,console.error(Me)),null)}).catch(()=>(we||(we=!0,console.error(Me)),null)),s=null;function a(c){let l=document.documentElement;l.dataset.sentientPersona===void 0&&(l.dataset.sentientPersona=c.persona,l.dataset.sentientConfidence=Q(c.confidence))}return{isLocal:!0,async decide(c){var l,u,g;let m=await i;if(!m)return null;let f=m.createLocalEngine({sessionId:r,forcedPersona:o}).decide(c);return s=de(O({},f),{layoutOrder:(u=(l=f.layoutOrder)!=null?l:s==null?void 0:s.layoutOrder)!=null?u:null,slots:O(O({},(g=s==null?void 0:s.slots)!=null?g:{}),f.slots)}),pe(e.apiKey||"local",{v:1,persona:s.persona,band:Q(s.confidence),slots:s.slots,layoutOrder:s.layoutOrder,savedAt:Date.now()}),a(f),f},getSlotResult(c){var l,u,g;return(g=(u=s==null?void 0:s.slots[c])!=null?u:(l=e.initialSlots)==null?void 0:l[c])!=null?g:null},getPersona(){return s?{persona:s.persona,confidence:s.confidence,band:Q(s.confidence)}:null},async assign(c,l){var u;let g=await i;return!g||!l||l.length===0?l!=null&&l[0]?{variantId:l[0],assignmentTtlMs:0}:null:{variantId:(u=g.createLocalEngine({sessionId:r,forcedPersona:o}).decide({components:[{id:c,variantIds:l}]}).assignments[c])!=null?u:l[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function fe(e,t,n){let r=[];{let o=!1,i=[],s=()=>{if(o)return;let a=Date.now();for(i.push(a);i.length>0&&a-i[0]>500;)i.shift();i.length>=3&&(o=!0,e("rage_click"))};t.addEventListener("click",s),r.push(()=>t.removeEventListener("click",s))}{let o=!1,i=s=>{if(o||!(s.target instanceof Node)||!t.contains(s.target)&&t!==s.target)return;o=!0;let a=typeof window!="undefined"?window.getSelection():null,c=a?a.toString().length:0;e("text_copy",{selectionLength:c})};document.addEventListener("copy",i),r.push(()=>document.removeEventListener("copy",i))}{let o=!1,i=!1,s=null,a=()=>{s!==null&&(clearTimeout(s),s=null)},c=()=>{o||!i||(a(),s=setTimeout(()=>{!o&&i&&(o=!0,e("scroll_hesitation"))},3e3))},l=()=>{a(),c()},u=m=>{for(let f of m)i=f.intersectionRatio>.3,i?c():a()},g=new IntersectionObserver(u,{threshold:[.3]});g.observe(t),window.addEventListener("scroll",l,{passive:!0}),r.push(()=>{g.disconnect(),window.removeEventListener("scroll",l),a()})}{let o=!1,i=n!=null?n:Date.now(),s=()=>{if(o||document.visibilityState!=="hidden")return;let a=Date.now()-i;a<15e3&&(o=!0,e("tab_loss",{timeOnPage:a}))};document.addEventListener("visibilitychange",s),r.push(()=>document.removeEventListener("visibilitychange",s))}return()=>{for(let o of r)o()}}var pt="https://api.sentient-ui.com/v1/events",ee=new Map,ft=null;function je(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}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)})}var se={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 Cn(){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 gt(e){return e.replace(/\/events\/?$/,"")}function te(){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 $e(e){if(typeof window=="undefined")return;let t=e!=null?e:ft;if(!t){console.warn("[sentient] grantConsent() called before init()");return}let n=ee.get(t);if(!n){console.warn("[sentient] grantConsent() called before init()");return}let{config:r,upgrade:o}=n;if(!o||r.respectDoNotTrack!==!1&&te())return;let i=ke(de(O({},r),{consent:!0}));o(i),ee.set(t,{config:de(O({},r),{consent:!0}),upgrade:null})}function _n(e){var t;let n=gt((t=e.ingestUrl)!=null?t:pt),r={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(a,c,l){try{let u=new URLSearchParams({componentId:a});for(let m of c!=null?c:[])u.append("variantIds[]",m);let g=await fetch(`${n}/winner?${u.toString()}`,{headers:r});return g.ok?{variantId:(await g.json()).variantId,assignmentTtlMs:0}:c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null}catch(u){return c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},i={track:a=>o.track(a),goal:(a,c,l,u)=>o.goal(a,c,l,u),componentGoal:(a,c,l)=>o.componentGoal(a,c,l),identify:a=>o.identify(a),getAssignment:(a,c)=>o.getAssignment(a,c),assign:(a,c,l,u)=>o.assign(a,c,l,u),decide:a=>o.decide(a),getSlotResult:a=>o.getSlotResult(a),getPersona:()=>o.getPersona(),fetchWeights:()=>o.fetchWeights(),getGraph:()=>o.getGraph(),dispose:()=>o.dispose(),destroy:()=>o.destroy()};function s(a){o=a}return{proxy:i,setInner:s}}function ke(e){var t,n,r,o,i,s,a,c,l;if(typeof window=="undefined")return se;ft=e.apiKey;let u=e.respectDoNotTrack!==!1&&te(),g=e.consent===!1||u,m=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!m&&e.localMode!==!1)return g?(ee.set(e.apiKey||"local",{config:e,upgrade:null}),se):(ee.set(e.apiKey||"local",{config:e,upgrade:null}),On(e));if(g){if(e.preConsentBehavior==="statistical_winner"){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),se;let{proxy:d,setInner:h}=_n(e);return ee.set(e.apiKey,{config:e,upgrade:u?null:h}),d}return ee.set(e.apiKey,{config:e,upgrade:null}),se}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."),se;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),se;let f=(t=e.ingestUrl)!=null?t:pt,b=Date.now(),S=ct({ssrSessionId:e.ssrSessionId}),w=An(),A=xn({ingestUrl:f,apiKey:e.apiKey}),x=gt(f),C={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},G=et((n=navigator.userAgent)!=null?n:""),H=typeof window!="undefined"?window.location.origin:void 0,Y=tt((r=document.referrer)!=null?r:"",H),_=(o=e.sessionSegment)!=null?o:`${G}:${Y}`,M=new Map,T=new Map,y=null,k=d=>{for(let h of d)T.has(h.id)||T.set(h.id,Pe(h))};if(e.initialSlots)for(let[d,h]of Object.entries(e.initialSlots))T.set(d,h);let p=xe(e.apiKey);if(p)for(let[d,h]of Object.entries(p.slots))T.has(d)||T.set(d,h);let v={low:.15,medium:.5,high:.85};if(e.initialPersona)y=O({},e.initialPersona);else{let d=document.documentElement.dataset;d.sentientPersona?y={persona:d.sentientPersona,confidence:(s=v[(i=d.sentientConfidence)!=null?i:"low"])!=null?s:.15}:p&&(y={persona:p.persona,confidence:(a=v[p.band])!=null?a:.15})}if(e.initialAssignments)for(let[d,h]of Object.entries(e.initialAssignments))w.set(d,_,{variantId:h,assignedAt:Date.now(),segment:_,confidence:1});let I=Promise.resolve(),$=S.getSessionId();if($){let d=nt((c=document.referrer)!=null?c:""),h=O(O({sessionId:$,deviceClass:G,trafficSource:Y,referrerDomain:d,utmParams:Cn(),timeOfDay:rt(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:S.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||Qe((l=navigator.userAgent)!=null?l:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{I=fetch(`${x}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(h),headers:C}).then(R=>{R.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(R){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:A});let z={goal(d,h={},R=1,B=0){let N=S.getSessionId();if(!N)return;let D=je();I.then(()=>{fetch(`${x}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:N,name:d,metadata:h,weight:R,stepIndex:B,goalId:D}),headers:C}).catch(()=>{})})},componentGoal(d,h,R){var B,N,D;let J=S.getSessionId();if(!J)return;let K=w.get(d,_),U=K?null:(B=T.get(d))!=null?B:null;if(!K&&U===null){e.debug&&console.warn(`[sentient] componentGoal("${d}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let X=K?K.variantId:ot(U),q={id:je(),sessionId:J,projectId:e.apiKey,componentId:d,variantId:X,eventType:"goal_achieved",goalType:h,payload:O({reward:(N=R==null?void 0:R.reward)!=null?N:1},(D=R==null?void 0:R.metadata)!=null?D:{}),timestamp:Date.now(),timeInSession:Date.now()-b};e.debug&&console.log("[sentient] componentGoal",q),I.then(()=>A.push(q))},identify(d){let h=S.getSessionId();h&&I.then(()=>{fetch(`${x}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:h,userId:d,ephemeral:S.isEphemeral()}),headers:C}).catch(()=>{})})},track(d){let h=S.getSessionId();if(!h)return;let R=de(O({},d),{id:je(),sessionId:h,timestamp:Date.now(),timeInSession:Date.now()-b});e.debug&&console.log("[sentient] track",R),I.then(()=>A.push(R))},getAssignment(d,h){return w.get(d,h)},async assign(d,h,R,B){let N=S.getSessionId();if(!N)return null;let D=w.get(d,_);if(D&&(h!=null&&h.length||D.content!==void 0))return{variantId:D.variantId,assignmentTtlMs:0,content:D.content};let J=M.get(d);if(J)return J;let K=(async()=>{await I;try{let U={sessionId:N,componentId:d,variantIds:h};B!==void 0?U.agentDataByVariant=B:R!==void 0&&(U.agentData=R);let X=await fetch(`${x}/assign`,{method:"POST",body:JSON.stringify(U),headers:C});if(!X.ok)return null;let q=await X.json();return w.set(d,_,{variantId:q.variantId,assignedAt:Date.now(),segment:_,confidence:1,content:q.content}),q}catch(U){return null}finally{M.delete(d)}})();return M.set(d,K),K},async decide(d){var h,R,B,N,D,J,K,U,X,q;let Ge=S.getSessionId();if(!Ge)return null;let le=(h=d.slots)!=null?h:[];await I;try{let Z={sessionId:Ge};d.sections&&d.sections.length>0&&(Z.sections=d.sections.map(j=>({id:j}))),Z.components=(R=d.components)!=null?R:[],le.length>0&&(Z.slots=le.map(Te)),d.slotsFrom==="registry"&&(Z.slotsFrom="registry"),d.v&&(Z.v=d.v);let qe=await fetch(`${x}/decide`,{method:"POST",body:JSON.stringify(Z),headers:C});if(!qe.ok)return k(le),null;let P=await qe.json(),ce={};for(let j of le)ce[j.id]=(N=(B=P.slots)==null?void 0:B[j.id])!=null?N:Pe(j);if(P.slots)for(let[j,ue]of Object.entries(P.slots))j in ce||(ce[j]=ue);for(let[j,ue]of Object.entries(ce))T.set(j,ue);y={persona:(D=P.persona)!=null?D:"unknown",confidence:(J=P.confidence)!=null?J:0};for(let[j,ue]of Object.entries((K=P.assignments)!=null?K:{}))w.set(j,_,{variantId:ue,assignedAt:Date.now(),segment:_,confidence:1});return pe(e.apiKey,O({v:1,persona:y.persona,band:Q(y.confidence),slots:Object.fromEntries(T),layoutOrder:(U=P.layoutOrder)!=null?U:null,savedAt:Date.now()},P.slotConfig?{slotConfig:P.slotConfig}:{})),O(O({layoutOrder:(X=P.layoutOrder)!=null?X:null,assignments:(q=P.assignments)!=null?q:{},slots:ce,persona:y.persona,confidence:y.confidence},P.slotConfig?{slotConfig:P.slotConfig}:{}),P.goals?{goals:P.goals}:{})}catch(Z){return k(le),null}},getSlotResult(d){var h;return(h=T.get(d))!=null?h:null},getPersona(){return y?{persona:y.persona,confidence:y.confidence,band:Q(y.confidence)}:null},async fetchWeights(){var d;try{let h=await fetch(`${x}/weights`,{headers:C});return h.ok?(d=(await h.json()).components)!=null?d:[]:[]}catch(h){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){A.destroy(),e.debug&&console.log("[sentient] disposed")},destroy(){A.destroy(),S.destroy();try{localStorage.removeItem(Se+e.apiKey),localStorage.removeItem(ut(e.apiKey))}catch(d){}e.debug&&console.log("[sentient] destroyed")}};if(ee.set(e.apiKey,{config:e,upgrade:null}),e.debug){let d=window;d.__sentient&&(d.__sentient.client=z)}return z}var mt=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Rn=[["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]],Tn=[["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 Pn(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function ht(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 Rn)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of Tn)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 yt(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:Pn(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function vt(e){return ht(yt(e)).type}ye();var wt="section, header, footer, nav, main > div, [data-sentient-section]";function Ln(e){var t;return((t=e.parentElement)==null?void 0:t.closest(wt))!=null}function Dn(e,t,n,r){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:r})}).catch(()=>{})}catch(o){}}var bt=()=>{};function St(e,t){var n,r,o,i,s,a,c,l,u;let g=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!g||typeof IntersectionObserver=="undefined"||te()||!t.apiKey)return bt;let m=(r=t.apiBase)!=null?r:"https://api.sentient-ui.com",f=Array.from(g.querySelectorAll(wt)).filter(y=>!Ln(y));if(f.length===0)return bt;let b=new Map,S=new Map,w=new Map;for(let y of f){let k=y.getAttribute("data-sentient-type"),p=k&&mt.includes(k)?k:null,v=(i=p!=null?p:(o=t.typeOf)==null?void 0:o.call(t,y))!=null?i:vt(y),I=`nc-${v}`;b.set(y,I),S.set(I,v),p?w.set(I,"markup"):w.has(I)||w.set(I,"auto")}let A=(l=(c=(a=(s=g.defaultView)!=null?s:typeof window!="undefined"?window:void 0)==null?void 0:a.location)==null?void 0:c.pathname)!=null?l:"/";Dn(t.apiKey,m,A,[...S.entries()].map(([y,k])=>{var p;return{componentId:y,semanticType:k,source:(p=w.get(y))!=null?p:"auto"}}));let x=new Map,C=y=>{let k=x.get(y);return k||(k={ms:0,scroll:0,enterAt:null,intersecting:!1},x.set(y,k)),k},G=new IntersectionObserver(y=>{for(let k of y){let p=b.get(k.target);if(!p)continue;let v=C(p);k.isIntersecting?(v.intersecting=!0,v.enterAt=Date.now(),k.intersectionRatio>v.scroll&&(v.scroll=k.intersectionRatio)):(v.intersecting=!1,v.enterAt!=null&&(v.ms+=Date.now()-v.enterAt,v.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let y of b.keys())G.observe(y);let H=()=>{let y=Date.now();for(let[k,p]of x)if(p.enterAt!=null&&(p.ms+=y-p.enterAt,p.enterAt=null),!(p.ms<=0)){try{e.track({projectId:t.apiKey,componentId:k,eventType:"dwell",payload:{dwell_time:Math.round(p.ms),scroll_depth:Number(p.scroll.toFixed(2))}})}catch(v){}p.ms=0}},Y=()=>{if(g.hidden)H();else{let y=Date.now();for(let k of x.values())k.intersecting&&(k.enterAt=y)}},_=()=>{H();try{G.disconnect()}catch(y){}};g.addEventListener("visibilitychange",Y);let M=(u=g.defaultView)!=null?u:typeof window!="undefined"?window:void 0;M==null||M.addEventListener("pagehide",_);let T=[];if(t.microSignals)for(let[y,k]of b)T.push(fe((p,v={})=>{try{e.track({projectId:t.apiKey,componentId:k,eventType:"micro_signal",payload:O({signalType:p},v)})}catch(I){}},y));return()=>{H(),g.removeEventListener("visibilitychange",Y),M==null||M.removeEventListener("pagehide",_);for(let y of T)y();try{G.disconnect()}catch(y){}}}var jn=["landing","ecommerce","saas","marketplace"];function Mn(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t=Object.entries(e);if(t.length<1||t.length>4)return null;let n={};for(let[r,o]of t){if(!Array.isArray(o)||o.length<2||o.length>6||!o.every(i=>typeof i=="string"))return null;n[r]=o}return n}function Nn(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function Ae(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[i,s]of Object.entries(t.slots)){if(typeof s!="object"||s===null)continue;let a=s,c=Mn(a.dims);if(!c||a.target!==void 0&&typeof a.target!="string")continue;let l=a.arms!==void 0?Nn(a.arms):null,u={dims:c};typeof a.target=="string"&&(u.target=a.target),l&&(u.arms=l),r[i]=u}let o={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};return typeof t.consent=="boolean"&&(o.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(o.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(o.debug=!0),typeof t.registry=="boolean"&&(o.registry=t.registry),typeof t.editorSrc=="string"&&(o.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(o.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(o.sectionCapture=t.sectionCapture),o}function xt(e){var n,r,o;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(o=t==null?void 0:t.pathname)!=null?o:""}function $n(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let r=((n=e.textContent)!=null?n:"").trim().toLowerCase(),o=t.text.trim().toLowerCase();if(!(r===o||r.startsWith(o)||o.startsWith(r)))return!1}return!0}function kt(e,t){return!!(e!=null&&e.urlMatch)&&!xt(t).includes(e.urlMatch)}function V(e,t){var o;if(e.urlMatch&&!xt(t).includes(e.urlMatch))return null;let n=[];if(e.id){let i=t.getElementById(e.id);n=i?[i]:[]}if(n.length===0&&((o=e.dataAttr)!=null&&o.name))try{let i=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${i}"]`))}catch(i){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(i){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!$n(r,e.fingerprint)?null:r}var At=/^https:\/\//i,Bn={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"};function Kn(e){return!/[;{}<>]/.test(e)}var It=new Map,F=null;function Un(e){return e.replace(/["\\]/g,"\\$&")}function Gn(e){var t;(!F||!F.isConnected)&&(F=e.querySelector("style[data-sentient-ops]"),F||(F=e.createElement("style"),F.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(F))),F.textContent=[...It.entries()].map(([n,r])=>`[data-snt-e="${Un(n)}"]{${r}}`).join(`
2
- `)}function Et(e,t,n,r){var a;let o=!1,i=(a=t.moveBefore)!=null?a:t.moveAfter;if(i){let c=V(i,r);!c||c===e||c.parentElement!==e.parentElement||!e.parentElement?o=!0:t.moveBefore?e.parentElement.insertBefore(e,c):e.parentElement.insertBefore(e,c.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&At.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&At.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[c,l]of Object.entries(t.style)){let u=Bn[c];u&&typeof l=="string"&&Kn(l)&&s.push(`${u}:${l.trim()} !important`)}return s.length>0&&(e.setAttribute("data-snt-e",n),It.set(n,s.join(";")),Gn(r)),{anchorMiss:o}}function Ie(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function Ee(e,t,n){var r;for(let[o,i]of Object.entries(t)){let s=e[o];if(!s||typeof s=="string")continue;let a=i.target?Array.from(n.querySelectorAll(i.target)):[n.documentElement];for(let c of a)for(let[l,u]of Object.entries(s))(r=i.dims[l])!=null&&r.includes(u)&&c.setAttribute(`data-${l}`,u)}}function Oe(e,t,n){for(let[r,o]of Object.entries(t)){let i=e[r];if(typeof i!="string"||!o.arms||!o.arms.includes(i))continue;let s=o.target?Array.from(n.querySelectorAll(o.target)):[n.documentElement];for(let a of s)a.setAttribute("data-sentient-arm",i)}}function Ce(e,t,n,r){var s,a;let o=(s=r==null?void 0:r.contentAndOps)!=null?s:!0,i=[];for(let[c,l]of Object.entries(t)){if(kt(l.locator,n))continue;let u;if(l.locator){let m=V(l.locator,n);u=m?[m]:[]}else l.target?u=Array.from(n.querySelectorAll(l.target)):u=[n.documentElement];(l.locator||l.target)&&u.length===0&&i.push(c);let g=e[c];for(let m of u){if(g!==void 0)if(typeof g=="string")m.setAttribute("data-sentient-arm",g),o&&((a=r==null?void 0:r.onApplied)==null||a.call(r,c,g,m));else for(let[f,b]of Object.entries(g))m.setAttribute(`data-${f}`,b);o&&(typeof l.content=="string"&&(m.textContent=l.content),l.ops&&Et(m,l.ops,c,n).anchorMiss&&!i.includes(c)&&i.push(c))}}return i}var qn=800;function Ot(e,t,n){let r=[];for(let{slotId:o,arm:i,el:s}of n){r.push(fe((g,m={})=>{try{e.track({projectId:t,componentId:o,variantId:i,eventType:"micro_signal",payload:oe({signalType:g},m)})}catch(f){}},s));let a=null,c=0,l=()=>{c=Date.now(),a=setTimeout(()=>{try{e.track({projectId:t,componentId:o,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-c}})}catch(g){}a=null},qn)},u=()=>{a!==null&&(clearTimeout(a),a=null)};s.addEventListener("mouseenter",l),s.addEventListener("mouseleave",u),r.push(()=>{s.removeEventListener("mouseenter",l),s.removeEventListener("mouseleave",u),a!==null&&clearTimeout(a)})}return()=>{for(let o of r)o()}}function Wn(e){var n,r,o;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(o=t==null?void 0:t.pathname)!=null?o:""}function Ct(e,t,n){var m;let r=new Set,o=f=>{if(!r.has(f.goalId)){r.add(f.goalId);try{f.slotId?t.componentGoal(f.slotId,f.goalId):t.goal(f.goalId)}catch(b){}}},i=e.filter(f=>f.event==="click"),s=e.filter(f=>f.event==="form_submit"),a=e.filter(f=>f.event==="url_reached"),c=(f,b)=>{if(!f.locator)return!1;let S=V(f.locator,n);return!!S&&(S===b||S.contains(b))},l=f=>{let b=f.target;if(!(!b||typeof b.closest!="function"))for(let S of i)c(S,b)&&o(S)},u=f=>{let b=f.target;if(b)for(let S of s)c(S,b)&&o(S)},g=()=>{if(a.length===0)return;let f=Wn(n);for(let b of a)b.urlPattern&&f.includes(b.urlPattern)&&o(b)};return n.addEventListener("click",l,!0),n.addEventListener("submit",u,!0),(m=n.defaultView)==null||m.addEventListener("popstate",g),g(),{checkUrl:g,teardown:()=>{var f;n.removeEventListener("click",l,!0),n.removeEventListener("submit",u,!0),(f=n.defaultView)==null||f.removeEventListener("popstate",g)}}}var _t="__snt_editor_token";function Rt(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(_t):null}catch(e){return null}}function Tt(e){try{sessionStorage.setItem(_t,e)}catch(t){}}var $t="0.11.0",Bt=5e3,zn=50,ge=null,L=null,W={},ne=null,re=null,_e=null,E=null,Pt=!1,Be=null;function Kt(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function ae(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function me(e,t){return ge?(ge.personaAttributes&&E&&Ie(E.persona,E.band,e),Ee(W,ge.slots,e),Oe(W,ge.slots,e),ne?Ce(W,ne,e,t):[]):[]}function Jn(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 Ue(){try{me(document)}catch(e){}}function Lt(){Be===null&&(Be=setTimeout(()=>{Be=null,Ue();try{re==null||re.checkUrl()}catch(e){}},zn))}function Dt(){if(!(Pt||typeof window=="undefined"||typeof history=="undefined")){Pt=!0;try{let e=t=>{let n=history[t];history[t]=function(r,o,i){let s=n.call(this,r,o,i!=null?i:null);return Lt(),s}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Lt)}catch(e){}}}function Ke(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 Ut(e){return new URLSearchParams(e).get("sentient_editor")}function Vn(){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 Fn(e,t){var n,r,o,i;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let c=document.createElement("meta");c.name="referrer",c.content="no-referrer",((r=document.head)!=null?r:document.documentElement).appendChild(c)}catch(c){}let s=(o=e.editorSrc)!=null?o:Vn();if(!s){Mt();return}let a=document.createElement("script");a.src=s,a.async=!0,a.onerror=()=>Mt(),((i=document.head)!=null?i:document.documentElement).appendChild(a)}catch(s){}}var jt="sentient-editor-load-notice";function Mt(){var e;try{if(typeof document=="undefined"||document.getElementById(jt))return;let t=document.createElement("div");t.id=jt,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 Gt(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let o=r.indexOf(":"),i=o===-1?"":r.slice(0,o),s=o===-1?"":r.slice(o+1);if(!(!i||!s))if(s.includes("=")){let a={};for(let c of s.split(",")){let[l,u]=c.split("=");l&&u&&(a[l]=u)}Object.keys(a).length&&(n[i]=a)}else n[i]=s}return Object.keys(n).length?n:null}function qt(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var Nt="sentient-persona-preview-banner";function Hn(e){var t;try{if(typeof document=="undefined"||document.getElementById(Nt))return;let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),r=document.createElement("div");r.id=Nt,r.setAttribute("role","status"),Object.assign(r.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",background:"#111827",color:"#fff",font:"13px/1 system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.14)"});let o=document.createElement("span");o.textContent=`Previewing as ${n}`;let i=document.createElement("button");i.type="button",i.textContent="Exit preview",Object.assign(i.style,{cursor:"pointer",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"inherit",padding:"4px 10px",borderRadius:"999px"}),i.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(o),r.appendChild(i),((t=document.body)!=null?t:document.documentElement).appendChild(r)}catch(n){}}async function Yn(e,t){var l,u,g,m,f,b,S,w,A;let n=(l=e.apiBase)!=null?l:"https://api.sentient-ui.com",o=((u=e.registry)!=null?u:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([x,C])=>({id:x,dims:C.dims}))},i=await Kt(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(o)}).then(x=>x.ok?x.json():null).catch(()=>null),Bt);if(!i){ae(e,"persona preview: explain unavailable \u2014 page left as-is");return}let s=i;W=(g=s.slots)!=null?g:{},ne=(m=s.slotConfig)!=null?m:null;let a=(S=(b=(f=s.personaAttributes)==null?void 0:f.persona)!=null?b:s.persona)!=null?S:t,c=(A=(w=s.personaAttributes)==null?void 0:w.confidence)!=null?A:"high";E={persona:a,band:c},me(document),Wt(e),Hn(a)}function Wt(e){let t={goal(n,r){try{L==null||L.goal(n,r)}catch(o){}},componentGoal(n,r){try{L==null||L.componentGoal(n,r)}catch(o){}},grantConsent(){try{$e(e.apiKey)}catch(n){}},revokeConsent(){try{L==null||L.destroy()}catch(n){}},reapply:Ue,getState(){var n,r;return{apiKey:e.apiKey,persona:(n=E==null?void 0:E.persona)!=null?n:null,band:(r=E==null?void 0:E.band)!=null?r:null,slots:W,matchCounts:Ke(e),consent:e.consent!==!1}}};window.SentientSnippet=t}async function zt(){var e,t,n;try{let r=Ae(window.sentient);if(!r)return;ge=r;let o=typeof window!="undefined"?Ut(window.location.search):null;if(o){Tt(o);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 i=o!=null?o:Rt();if(i){Fn(r,i),ae(r,"editor mode");return}let s=typeof window!="undefined"?Gt(window.location.search):null;if(s){W=s,E=null,me(document),Dt(),ae(r,"preview mode",s);return}let a=typeof window!="undefined"?qt(window.location.search):null;if(a){await Yn(r,a),ae(r,"persona preview",a);return}let c=(e=r.registry)!=null?e:Object.keys(r.slots).length===0,l=xe(r.apiKey);l&&(E={persona:l.persona,band:l.band},W=l.slots,l.slotConfig&&(ne=l.slotConfig),me(document,{contentAndOps:!1}));let u=ke({apiKey:r.apiKey,context:r.context,consent:r.consent,preConsentBehavior:r.preConsentBehavior,debug:r.debug});L=u,Wt(r),Dt();let g=Object.entries(r.slots).map(([w,A])=>({id:w,dims:A.dims})),m=await Kt(u.decide(oe({slots:g,v:$t},c?{slotsFrom:"registry"}:{})),Bt);if(!m){ae(r,"decide timeout/null \u2014 snapshot state stands",Ke(r));return}let f=u.getPersona();f?E={persona:f.persona,band:f.band}:m.persona&&(E={persona:m.persona,band:"low"}),W=m.slots,m.slotConfig&&(ne=m.slotConfig);let b=[];if(Jn(r,me(document,{onApplied:(w,A,x)=>b.push({slotId:w,arm:A,el:x})})),m.goals&&m.goals.length>0&&r.consent!==!1&&L)try{re==null||re.teardown(),re=Ct(m.goals,L,document)}catch(w){}let S;try{let w=m.sectionMap;if(w&&w.length>0){let A=new Map;for(let x of w){if(x.urlMatch!==window.location.pathname)continue;let C=V(x.locator,document);C&&A.set(C,x.type)}A.size>0&&(S=x=>{var C;return(C=A.get(x))!=null?C:null})}}catch(w){}if(r.sectionCapture!==!1&&r.consent!==!1&&L&&!te()){try{St(L,oe({apiKey:r.apiKey,apiBase:r.apiBase,doc:document,microSignals:!0},S?{typeOf:S}:{}))}catch(w){}try{_e==null||_e(),_e=Ot(L,r.apiKey,b)}catch(w){}}ae(r,"applied",{persona:E,slots:W,matches:Ke(r)}),pe(r.apiKey,oe({v:1,persona:(t=E==null?void 0:E.persona)!=null?t:m.persona,band:(n=E==null?void 0:E.band)!=null?n:"low",slots:m.slots,layoutOrder:m.layoutOrder,savedAt:Date.now()},ne?{slotConfig:ne}:{}))}catch(r){}}typeof window!="undefined"&&window.sentient&&zt();return Yt(Xn);})();
1
+ "use strict";var SentientSnippet=(()=>{var ye=Object.defineProperty;var Jt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames,Je=Object.getOwnPropertySymbols;var Fe=Object.prototype.hasOwnProperty,Ft=Object.prototype.propertyIsEnumerable;var Ve=(e,t,n)=>t in e?ye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ne=(e,t)=>{for(var n in t||(t={}))Fe.call(t,n)&&Ve(e,n,t[n]);if(Je)for(var n of Je(t))Ft.call(t,n)&&Ve(e,n,t[n]);return e};var He=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ye=(e,t)=>{for(var n in t)ye(e,n,{get:t[n],enumerable:!0})},Ht=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Vt(t))!Fe.call(e,o)&&o!==n&&ye(e,o,{get:()=>t[o],enumerable:!(r=Jt(t,o))||r.enumerable});return e};var Yt=e=>Ht(ye({},"__esModule",{value:!0}),e);var Xt,Zt,Qt,Xe,en,tn,Ze,C,fe,ve=He(()=>{"use strict";Xt=Object.defineProperty,Zt=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,Xe=Object.getOwnPropertySymbols,en=Object.prototype.hasOwnProperty,tn=Object.prototype.propertyIsEnumerable,Ze=(e,t,n)=>t in e?Xt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))en.call(t,n)&&Ze(e,n,t[n]);if(Xe)for(var n of Xe(t))tn.call(t,n)&&Ze(e,n,t[n]);return e},fe=(e,t)=>Zt(e,Qt(t))});var at={};Ye(at,{LOCAL_ENGINE_AVAILABLE:()=>on,createLocalEngine:()=>sn});function sn(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var on,lt=He(()=>{"use strict";on=!1});var Xn={};Ye(Xn,{applyPersonaAttributes:()=>Ee,applyRegistrySlots:()=>_e,applySlotArms:()=>Ce,applySlotAttributes:()=>Oe,parseEditorToken:()=>Ut,parsePersonaPreview:()=>qt,parsePreview:()=>Gt,parseSnippetConfig:()=>Ie,reapply:()=>qe,run:()=>zt,version:()=>Ue});ve();function be(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function Qe(e){if(e.length===0)return null;let t={};for(let n of e.split("|")){let r=n.indexOf("=");if(r<=0||r!==n.lastIndexOf("=")||r===n.length-1)return null;let o=n.slice(0,r);if(o in t)return null;t[o]=n.slice(r+1)}return t}function Re(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 be(e.baseline);if(typeof e.baseline=="string")return e.baseline;let o={};for(let[s,i]of Object.entries((n=e.dims)!=null?n:{}))o[s]=(r=i[0])!=null?r:"";return be(o)}function et(e,t){var n,r;return e.dims!=null?(r=(n=Qe(t))!=null?n:Qe(Re(e)))!=null?r:{}:t}function re(e){return e>=.3?e<.7?"medium":"high":"low"}var nn=["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 tt(e){return rn(e)!==null}function rn(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=nn.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function nt(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 rt(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(o){}let r=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(n){return"direct"}}function ot(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function it(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function Te(e){return C(C(C({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 Le(e){let t=Te(e);return et(t,Re(t))}function st(e){return typeof e=="string"?e:be(e)}ve();var an="_snt_uid",ae="_snt_uid";function ln(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function cn(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function un(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function dn(e){try{return localStorage.getItem(e)}catch(t){return null}}function pn(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function fn(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function gn(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function mn(e){try{sessionStorage.removeItem(e)}catch(t){}}function hn(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function yn(e){try{localStorage.removeItem(e)}catch(t){}}function vn(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var bn={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function dt(e){var t,n,r,o,s,i;if(typeof window=="undefined")return bn;let l=(t=e==null?void 0:e.cookieName)!=null?t:an,a=((n=e==null?void 0:e.cookieTTLDays)!=null?n:365)*24*60*60,c=(i=(s=(o=(r=cn(l))!=null?r:dn(ae))!=null?o:fn(ae))!=null?s:e==null?void 0:e.ssrSessionId)!=null?i:ln();un(l,c,a);let u=pn(ae,c),g=hn(l),b=u?!1:gn(ae,c),d=!u&&!g&&!b;return{getSessionId:()=>c,isEphemeral:()=>d,destroy:()=>{c=null,vn(l),yn(ae),mn(ae)}}}function pt(e){return`_snt_retry_${e.slice(0,12)}`}var wn={push:()=>{},flush:()=>{},destroy:()=>{}};function Sn(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 Pe(e,t,n){try{let r=[...(()=>{try{let o=localStorage.getItem(n);if(!o)return[];let s=JSON.parse(o);return Array.isArray(s)?s:[]}catch(o){return[]}})(),...e].slice(-t);localStorage.setItem(n,JSON.stringify(r))}catch(r){}}function xn(e){var t,n,r;if(typeof window=="undefined")return wn;let o=(t=e.flushIntervalMs)!=null?t:5e3,s=(n=e.maxBatchSize)!=null?n:20,i=(r=e.maxRetrySize)!=null?r:100,l=e.ingestUrl,a=e.apiKey,c=pt(a),u=[],g=new Set,b=[],d=f=>{for(let v of f)y.delete(v),!g.has(v)&&(g.add(v),b.push(v));for(;b.length>500;){let v=b.shift();v&&g.delete(v)}},y=new Set,S=f=>{g.has(f.id)||y.has(f.id)||(y.add(f.id),u.push(f))},E=Sn(i,c);for(let f of E)S(f);let w=0,x=0,O=f=>{if(f.length===0)return;let v=JSON.stringify(f),A=f.map(p=>p.id),B;try{B=fetch(l,{method:"POST",keepalive:!0,body:v,headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}})}catch(p){Pe(f,i,c);for(let m of A)y.delete(m);x++,w=Date.now()+Math.min(6e4,1e3*2**Math.min(x,6));return}let J=p=>{if(p.ok||p.status>=400&&p.status<500&&p.status!==429){d(A),x=0,w=0;return}Pe(f,i,c);for(let m of A)y.delete(m);x++,w=Date.now()+Math.min(6e4,1e3*2**Math.min(x,6))};B instanceof Promise?B.then(J).catch(()=>{Pe(f,i,c);for(let p of A)y.delete(p);x++,w=Date.now()+Math.min(6e4,1e3*2**Math.min(x,6))}):J(B)},P=typeof TextEncoder!="undefined"?new TextEncoder:null,Z=f=>P?P.encode(f).length:f.length,Q=f=>{let v=[],A=2;for(let B of f){let J=Z(JSON.stringify(B))+1;if(v.length>0&&A+J>57344||v.length>=s)break;v.push(B),A+=J}return v},_=()=>{try{if(Date.now()<w)return;for(;u.length>0;){let f=u.filter(A=>!g.has(A.id));if(u.length=0,f.length===0)break;let v=Q(f);if(v.length===0)break;v.length<f.length&&u.push(...f.slice(v.length)),O(v)}}catch(f){}},N=!0,T=null;T=setInterval(()=>{N&&_()},o);let h=()=>{document.visibilityState==="hidden"&&_()},k=()=>{_()};return document.addEventListener("visibilitychange",h),window.addEventListener("pagehide",k),{push(f){S(f),u.length>=s&&_()},flush:_,destroy(){N=!1,T!==null&&(clearInterval(T),T=null),document.removeEventListener("visibilitychange",h),window.removeEventListener("pagehide",k),_()}}}var Ne="_snt_asgn_";function we(e,t){return`${e}:${t}`}function kn(e,t){return`${Ne}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function ct(e){let t=e.slice(Ne.length),n=t.indexOf(":");if(n<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,n)),segment:decodeURIComponent(t.slice(n+1))}}catch(r){return null}}function De(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(Ne)&&e.push(n)}return e}catch(e){return[]}}function An(e=18e5){let t=new Map,n=r=>r.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let r of De())try{let o=localStorage.getItem(r);if(!o)continue;let s=JSON.parse(o);if(n(s)){localStorage.removeItem(r);continue}let i=ct(r);if(!i)continue;t.set(we(i.componentId,i.segment),s)}catch(o){}})(),{get(r,o){let s=t.get(we(r,o));return s?n(s)?(t.delete(we(r,o)),null):s:null},set(r,o,s){let i=we(r,o);t.set(i,s);try{localStorage.setItem(kn(r,o),JSON.stringify(s))}catch(l){}},invalidate(r){let o=`${r}:`;for(let s of[...t.keys()])s.startsWith(o)&&t.delete(s);for(let s of De()){let i=ct(s);if((i==null?void 0:i.componentId)===r)try{localStorage.removeItem(s)}catch(l){}}},clear(){t.clear();for(let r of De())try{localStorage.removeItem(r)}catch(o){}}}}var xe="_snt_snap:",In=["low","medium","high"];function ke(e){try{let t=localStorage.getItem(xe+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"||!In.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 ge(e,t){try{localStorage.setItem(xe+e,JSON.stringify(t))}catch(n){}}var Me="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",ft="[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.",ut=!1,Se=!1;function En(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function On(e){var t;let n=dt({ssrSessionId:e.ssrSessionId}),r=(t=n.getSessionId())!=null?t:"local",o=En(),s=Promise.resolve().then(()=>(lt(),at)).then(a=>{let c=a;return c.LOCAL_ENGINE_AVAILABLE?(ut||(ut=!0,console.info(ft)),c):(Se||(Se=!0,console.error(Me)),null)}).catch(()=>(Se||(Se=!0,console.error(Me)),null)),i=null;function l(a){let c=document.documentElement;c.dataset.sentientPersona===void 0&&(c.dataset.sentientPersona=a.persona,c.dataset.sentientConfidence=re(a.confidence))}return{isLocal:!0,async decide(a){var c,u,g;let b=await s;if(!b)return null;let d=b.createLocalEngine({sessionId:r,forcedPersona:o}).decide(a);return i=fe(C({},d),{layoutOrder:(u=(c=d.layoutOrder)!=null?c:i==null?void 0:i.layoutOrder)!=null?u:null,slots:C(C({},(g=i==null?void 0:i.slots)!=null?g:{}),d.slots)}),ge(e.apiKey||"local",{v:1,persona:i.persona,band:re(i.confidence),slots:i.slots,layoutOrder:i.layoutOrder,savedAt:Date.now()}),l(d),d},getSlotResult(a){var c,u,g;return(g=(u=i==null?void 0:i.slots[a])!=null?u:(c=e.initialSlots)==null?void 0:c[a])!=null?g:null},getPersona(){return i?{persona:i.persona,confidence:i.confidence,band:re(i.confidence)}:null},async assign(a,c){var u;let g=await s;return!g||!c||c.length===0?c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null:{variantId:(u=g.createLocalEngine({sessionId:r,forcedPersona:o}).decide({components:[{id:a,variantIds:c}]}).assignments[a])!=null?u:c[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function me(e,t,n,r){let o=[];{let s=!1,i=[],l=()=>{if(s)return;let a=Date.now();for(i.push(a);i.length>0&&a-i[0]>500;)i.shift();i.length>=3&&(s=!0,e("rage_click"))};t.addEventListener("click",l),o.push(()=>t.removeEventListener("click",l))}{let s=!1,i=l=>{if(s||!(l.target instanceof Node)||!t.contains(l.target)&&t!==l.target)return;s=!0;let a=typeof window!="undefined"?window.getSelection():null,c=a?a.toString().length:0;e("text_copy",{selectionLength:c})};document.addEventListener("copy",i),o.push(()=>document.removeEventListener("copy",i))}{let s=!1,i=!1,l=null,a=()=>{l!==null&&(clearTimeout(l),l=null)},c=()=>{s||!i||(a(),l=setTimeout(()=>{!s&&i&&(s=!0,e("scroll_hesitation"))},3e3))},u=()=>{a(),c()},g=d=>{for(let y of d)i=y.intersectionRatio>.3,i?c():a()},b=new IntersectionObserver(g,{threshold:[.3]});b.observe(t),window.addEventListener("scroll",u,{passive:!0}),o.push(()=>{b.disconnect(),window.removeEventListener("scroll",u),a()})}if((r==null?void 0:r.tabLoss)!==!1){let s=!1,i=n!=null?n:Date.now(),l=()=>{if(s||document.visibilityState!=="hidden")return;let a=Date.now()-i;a<15e3&&(s=!0,e("tab_loss",{timeOnPage:a}))};document.addEventListener("visibilitychange",l),o.push(()=>document.removeEventListener("visibilitychange",l))}return()=>{for(let s of o)s()}}var gt="https://api.sentient-ui.com/v1/events",oe=new Map,mt=null;function je(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}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)})}var le={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 Cn(){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 ht(e){return e.replace(/\/events\/?$/,"")}function F(){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 $e(e){if(typeof window=="undefined")return;let t=e!=null?e:mt;if(!t){console.warn("[sentient] grantConsent() called before init()");return}let n=oe.get(t);if(!n){console.warn("[sentient] grantConsent() called before init()");return}let{config:r,upgrade:o}=n;if(!o||r.respectDoNotTrack!==!1&&F())return;let s=Ae(fe(C({},r),{consent:!0}));o(s),oe.set(t,{config:fe(C({},r),{consent:!0}),upgrade:null})}function _n(e){var t;let n=ht((t=e.ingestUrl)!=null?t:gt),r={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(l,a,c){try{let u=new URLSearchParams({componentId:l});for(let b of a!=null?a:[])u.append("variantIds[]",b);let g=await fetch(`${n}/winner?${u.toString()}`,{headers:r});return g.ok?{variantId:(await g.json()).variantId,assignmentTtlMs:0}:a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}catch(u){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:l=>o.track(l),goal:(l,a,c,u)=>o.goal(l,a,c,u),componentGoal:(l,a,c)=>o.componentGoal(l,a,c),identify:l=>o.identify(l),getAssignment:(l,a)=>o.getAssignment(l,a),assign:(l,a,c,u)=>o.assign(l,a,c,u),decide:l=>o.decide(l),getSlotResult:l=>o.getSlotResult(l),getPersona:()=>o.getPersona(),fetchWeights:()=>o.fetchWeights(),getGraph:()=>o.getGraph(),dispose:()=>o.dispose(),destroy:()=>o.destroy()};function i(l){o=l}return{proxy:s,setInner:i}}function Ae(e){var t,n,r,o,s,i,l,a,c;if(typeof window=="undefined")return le;mt=e.apiKey;let u=e.respectDoNotTrack!==!1&&F(),g=e.consent===!1||u,b=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!b&&e.localMode!==!1)return g?(oe.set(e.apiKey||"local",{config:e,upgrade:null}),le):(oe.set(e.apiKey||"local",{config:e,upgrade:null}),On(e));if(g){if(e.preConsentBehavior==="statistical_winner"){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),le;let{proxy:p,setInner:m}=_n(e);return oe.set(e.apiKey,{config:e,upgrade:u?null:m}),p}return oe.set(e.apiKey,{config:e,upgrade:null}),le}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."),le;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),le;let d=(t=e.ingestUrl)!=null?t:gt,y=Date.now(),S=dt({ssrSessionId:e.ssrSessionId}),E=An(),w=xn({ingestUrl:d,apiKey:e.apiKey}),x=ht(d),O={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},P=nt((n=navigator.userAgent)!=null?n:""),Z=typeof window!="undefined"?window.location.origin:void 0,Q=rt((r=document.referrer)!=null?r:"",Z),_=(o=e.sessionSegment)!=null?o:`${P}:${Q}`,N=new Map,T=new Map,h=null,k=p=>{for(let m of p)T.has(m.id)||T.set(m.id,Le(m))};if(e.initialSlots)for(let[p,m]of Object.entries(e.initialSlots))T.set(p,m);let f=ke(e.apiKey);if(f)for(let[p,m]of Object.entries(f.slots))T.has(p)||T.set(p,m);let v={low:.15,medium:.5,high:.85};if(e.initialPersona)h=C({},e.initialPersona);else{let p=document.documentElement.dataset;p.sentientPersona?h={persona:p.sentientPersona,confidence:(i=v[(s=p.sentientConfidence)!=null?s:"low"])!=null?i:.15}:f&&(h={persona:f.persona,confidence:(l=v[f.band])!=null?l:.15})}if(e.initialAssignments)for(let[p,m]of Object.entries(e.initialAssignments))E.set(p,_,{variantId:m,assignedAt:Date.now(),segment:_,confidence:1});let A=Promise.resolve(),B=S.getSessionId();if(B){let p=ot((a=document.referrer)!=null?a:""),m=C(C({sessionId:B,deviceClass:P,trafficSource:Q,referrerDomain:p,utmParams:Cn(),timeOfDay:it(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:S.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||tt((c=navigator.userAgent)!=null?c:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{A=fetch(`${x}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(m),headers:O}).then(R=>{R.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(R){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:w});let J={goal(p,m={},R=1,K=0){let $=S.getSessionId();if(!$)return;let j=je();A.then(()=>{fetch(`${x}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:$,name:p,metadata:m,weight:R,stepIndex:K,goalId:j}),headers:O}).catch(()=>{})})},componentGoal(p,m,R){var K,$,j;let V=S.getSessionId();if(!V)return;let U=E.get(p,_),G=U?null:(K=T.get(p))!=null?K:null;if(!U&&G===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 ee=U?U.variantId:st(G),q={id:je(),sessionId:V,projectId:e.apiKey,componentId:p,variantId:ee,eventType:"goal_achieved",goalType:m,payload:C({reward:($=R==null?void 0:R.reward)!=null?$:1},(j=R==null?void 0:R.metadata)!=null?j:{}),timestamp:Date.now(),timeInSession:Date.now()-y};e.debug&&console.log("[sentient] componentGoal",q),A.then(()=>w.push(q))},identify(p){let m=S.getSessionId();m&&A.then(()=>{fetch(`${x}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:m,userId:p,ephemeral:S.isEphemeral()}),headers:O}).catch(()=>{})})},track(p){let m=S.getSessionId();if(!m)return;let R=fe(C({},p),{id:je(),sessionId:m,timestamp:Date.now(),timeInSession:Date.now()-y});e.debug&&console.log("[sentient] track",R),A.then(()=>w.push(R))},getAssignment(p,m){return E.get(p,m)},async assign(p,m,R,K){let $=S.getSessionId();if(!$)return null;let j=E.get(p,_);if(j&&(m!=null&&m.length||j.content!==void 0))return{variantId:j.variantId,assignmentTtlMs:0,content:j.content};let V=N.get(p);if(V)return V;let U=(async()=>{await A;try{let G={sessionId:$,componentId:p,variantIds:m};K!==void 0?G.agentDataByVariant=K:R!==void 0&&(G.agentData=R);let ee=await fetch(`${x}/assign`,{method:"POST",body:JSON.stringify(G),headers:O});if(!ee.ok)return null;let q=await ee.json();return E.set(p,_,{variantId:q.variantId,assignedAt:Date.now(),segment:_,confidence:1,content:q.content}),q}catch(G){return null}finally{N.delete(p)}})();return N.set(p,U),U},async decide(p){var m,R,K,$,j,V,U,G,ee,q;let We=S.getSessionId();if(!We)return null;let ue=(m=p.slots)!=null?m:[];await A;try{let te={sessionId:We};p.sections&&p.sections.length>0&&(te.sections=p.sections.map(M=>({id:M}))),te.components=(R=p.components)!=null?R:[],ue.length>0&&(te.slots=ue.map(Te)),p.slotsFrom==="registry"&&(te.slotsFrom="registry"),p.v&&(te.v=p.v);let ze=await fetch(`${x}/decide`,{method:"POST",body:JSON.stringify(te),headers:O});if(!ze.ok)return k(ue),null;let D=await ze.json(),de={};for(let M of ue)de[M.id]=($=(K=D.slots)==null?void 0:K[M.id])!=null?$:Le(M);if(D.slots)for(let[M,pe]of Object.entries(D.slots))M in de||(de[M]=pe);for(let[M,pe]of Object.entries(de))T.set(M,pe);h={persona:(j=D.persona)!=null?j:"unknown",confidence:(V=D.confidence)!=null?V:0};for(let[M,pe]of Object.entries((U=D.assignments)!=null?U:{}))E.set(M,_,{variantId:pe,assignedAt:Date.now(),segment:_,confidence:1});return ge(e.apiKey,C({v:1,persona:h.persona,band:re(h.confidence),slots:Object.fromEntries(T),layoutOrder:(G=D.layoutOrder)!=null?G:null,savedAt:Date.now()},D.slotConfig?{slotConfig:D.slotConfig}:{})),C(C({layoutOrder:(ee=D.layoutOrder)!=null?ee:null,assignments:(q=D.assignments)!=null?q:{},slots:de,persona:h.persona,confidence:h.confidence},D.slotConfig?{slotConfig:D.slotConfig}:{}),D.goals?{goals:D.goals}:{})}catch(te){return k(ue),null}},getSlotResult(p){var m;return(m=T.get(p))!=null?m:null},getPersona(){return h?{persona:h.persona,confidence:h.confidence,band:re(h.confidence)}:null},async fetchWeights(){var p;try{let m=await fetch(`${x}/weights`,{headers:O});return m.ok?(p=(await m.json()).components)!=null?p:[]:[]}catch(m){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){w.destroy(),e.debug&&console.log("[sentient] disposed")},destroy(){w.destroy(),S.destroy();try{localStorage.removeItem(xe+e.apiKey),localStorage.removeItem(pt(e.apiKey))}catch(p){}e.debug&&console.log("[sentient] destroyed")}};if(oe.set(e.apiKey,{config:e,upgrade:null}),e.debug){let p=window;p.__sentient&&(p.__sentient.client=J)}return J}var yt=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Rn=[["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]],Tn=[["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 Ln(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function vt(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 Rn)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of Tn)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 bt(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:Ln(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function wt(e){return vt(bt(e)).type}ve();var xt="section, header, footer, nav, main > div, [data-sentient-section]";function Pn(e){var t;return((t=e.parentElement)==null?void 0:t.closest(xt))!=null}function Dn(e,t,n,r){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:r})}).catch(()=>{})}catch(o){}}var St=()=>{};function kt(e,t){var n,r,o,s,i,l,a,c,u;let g=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!g||typeof IntersectionObserver=="undefined"||F()||!t.apiKey)return St;let b=(r=t.apiBase)!=null?r:"https://api.sentient-ui.com",d=Array.from(g.querySelectorAll(xt)).filter(h=>!Pn(h));if(d.length===0)return St;let y=new Map,S=new Map,E=new Map;for(let h of d){let k=h.getAttribute("data-sentient-type"),f=k&&yt.includes(k)?k:null,v=(s=f!=null?f:(o=t.typeOf)==null?void 0:o.call(t,h))!=null?s:wt(h),A=`nc-${v}`;y.set(h,A),S.set(A,v),f?E.set(A,"markup"):E.has(A)||E.set(A,"auto")}let w=(c=(a=(l=(i=g.defaultView)!=null?i:typeof window!="undefined"?window:void 0)==null?void 0:l.location)==null?void 0:a.pathname)!=null?c:"/";Dn(t.apiKey,b,w,[...S.entries()].map(([h,k])=>{var f;return{componentId:h,semanticType:k,source:(f=E.get(h))!=null?f:"auto"}}));let x=new Map,O=h=>{let k=x.get(h);return k||(k={ms:0,scroll:0,enterAt:null,intersecting:!1},x.set(h,k)),k},P=new IntersectionObserver(h=>{for(let k of h){let f=y.get(k.target);if(!f)continue;let v=O(f);k.isIntersecting?(v.intersecting=!0,v.enterAt=Date.now(),k.intersectionRatio>v.scroll&&(v.scroll=k.intersectionRatio)):(v.intersecting=!1,v.enterAt!=null&&(v.ms+=Date.now()-v.enterAt,v.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let h of y.keys())P.observe(h);let Z=()=>{let h=Date.now();for(let[k,f]of x)if(f.enterAt!=null&&(f.ms+=h-f.enterAt,f.enterAt=null),!(f.ms<=0)){try{e.track({projectId:t.apiKey,componentId:k,eventType:"dwell",payload:{dwell_time:Math.round(f.ms),scroll_depth:Number(f.scroll.toFixed(2))}})}catch(v){}f.ms=0}},Q=()=>{if(g.hidden)Z();else{let h=Date.now();for(let k of x.values())k.intersecting&&(k.enterAt=h)}},_=()=>{Z();try{P.disconnect()}catch(h){}};g.addEventListener("visibilitychange",Q);let N=(u=g.defaultView)!=null?u:typeof window!="undefined"?window:void 0;N==null||N.addEventListener("pagehide",_);let T=[];if(t.microSignals)for(let[h,k]of y)T.push(me((f,v={})=>{try{e.track({projectId:t.apiKey,componentId:k,eventType:"micro_signal",payload:C({signalType:f},v)})}catch(A){}},h));return()=>{Z(),g.removeEventListener("visibilitychange",Q),N==null||N.removeEventListener("pagehide",_);for(let h of T)h();try{P.disconnect()}catch(h){}}}var jn=["landing","ecommerce","saas","marketplace"];function Mn(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t=Object.entries(e);if(t.length<1||t.length>4)return null;let n={};for(let[r,o]of t){if(!Array.isArray(o)||o.length<2||o.length>6||!o.every(s=>typeof s=="string"))return null;n[r]=o}return n}function Nn(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function Ie(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.apiKey!="string"||!t.apiKey.startsWith("pk_"))return null;let n=jn.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[s,i]of Object.entries(t.slots)){if(typeof i!="object"||i===null)continue;let l=i,a=Mn(l.dims);if(!a||l.target!==void 0&&typeof l.target!="string")continue;let c=l.arms!==void 0?Nn(l.arms):null,u={dims:a};typeof l.target=="string"&&(u.target=l.target),c&&(u.arms=c),r[s]=u}let o={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};return typeof t.consent=="boolean"&&(o.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(o.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(o.debug=!0),typeof t.registry=="boolean"&&(o.registry=t.registry),typeof t.editorSrc=="string"&&(o.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(o.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(o.sectionCapture=t.sectionCapture),o}function At(e){var n,r,o;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(o=t==null?void 0:t.pathname)!=null?o:""}function $n(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let r=((n=e.textContent)!=null?n:"").trim().toLowerCase(),o=t.text.trim().toLowerCase();if(!(r===o||r.startsWith(o)||o.startsWith(r)))return!1}return!0}function It(e,t){return!!(e!=null&&e.urlMatch)&&!At(t).includes(e.urlMatch)}function H(e,t){var o;if(e.urlMatch&&!At(t).includes(e.urlMatch))return null;let n=[];if(e.id){let s=t.getElementById(e.id);n=s?[s]:[]}if(n.length===0&&((o=e.dataAttr)!=null&&o.name))try{let s=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${s}"]`))}catch(s){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(s){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!$n(r,e.fingerprint)?null:r}var Et=/^https:\/\//i,Bn={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"};function Kn(e){return!/[;{}<>]/.test(e)}var Ot=new Map,Y=null;function Un(e){return e.replace(/["\\]/g,"\\$&")}function Gn(e){var t;(!Y||!Y.isConnected)&&(Y=e.querySelector("style[data-sentient-ops]"),Y||(Y=e.createElement("style"),Y.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(Y))),Y.textContent=[...Ot.entries()].map(([n,r])=>`[data-snt-e="${Un(n)}"]{${r}}`).join(`
2
+ `)}function Ct(e,t,n,r){var l;let o=!1,s=(l=t.moveBefore)!=null?l:t.moveAfter;if(s){let a=H(s,r);!a||a===e||a.parentElement!==e.parentElement||!e.parentElement?o=!0:t.moveBefore?e.parentElement.insertBefore(e,a):e.parentElement.insertBefore(e,a.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&Et.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&Et.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let i=[];if(t.hidden&&i.push("display:none !important"),t.style)for(let[a,c]of Object.entries(t.style)){let u=Bn[a];u&&typeof c=="string"&&Kn(c)&&i.push(`${u}:${c.trim()} !important`)}return i.length>0&&(e.setAttribute("data-snt-e",n),Ot.set(n,i.join(";")),Gn(r)),{anchorMiss:o}}function Ee(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function Oe(e,t,n){var r;for(let[o,s]of Object.entries(t)){let i=e[o];if(!i||typeof i=="string")continue;let l=s.target?Array.from(n.querySelectorAll(s.target)):[n.documentElement];for(let a of l)for(let[c,u]of Object.entries(i))(r=s.dims[c])!=null&&r.includes(u)&&a.setAttribute(`data-${c}`,u)}}function Ce(e,t,n){for(let[r,o]of Object.entries(t)){let s=e[r];if(typeof s!="string"||!o.arms||!o.arms.includes(s))continue;let i=o.target?Array.from(n.querySelectorAll(o.target)):[n.documentElement];for(let l of i)l.setAttribute("data-sentient-arm",s)}}function _e(e,t,n,r){var i,l;let o=(i=r==null?void 0:r.contentAndOps)!=null?i:!0,s=[];for(let[a,c]of Object.entries(t)){if(It(c.locator,n))continue;let u;if(c.locator){let b=H(c.locator,n);u=b?[b]:[]}else c.target?u=Array.from(n.querySelectorAll(c.target)):u=[n.documentElement];(c.locator||c.target)&&u.length===0&&s.push(a);let g=e[a];for(let b of u){if(g!==void 0)if(typeof g=="string")b.setAttribute("data-sentient-arm",g),o&&((l=r==null?void 0:r.onApplied)==null||l.call(r,a,g,b));else for(let[d,y]of Object.entries(g))b.setAttribute(`data-${d}`,y);o&&(typeof c.content=="string"&&(b.textContent=c.content),c.ops&&Ct(b,c.ops,a,n).anchorMiss&&!s.includes(a)&&s.push(a))}}return s}var qn=800;function Be(e,t,n){let r=[];return n.forEach(({slotId:o,arm:s,el:i},l)=>{r.push(me((b,d={})=>{try{e.track({projectId:t,componentId:o,variantId:s,eventType:"micro_signal",payload:ne({signalType:b},d)})}catch(y){}},i,void 0,{tabLoss:l===0}));let a=null,c=0,u=()=>{c=Date.now(),a=setTimeout(()=>{try{e.track({projectId:t,componentId:o,variantId:s,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-c}})}catch(b){}a=null},qn)},g=()=>{a!==null&&(clearTimeout(a),a=null)};i.addEventListener("mouseenter",u),i.addEventListener("mouseleave",g),r.push(()=>{i.removeEventListener("mouseenter",u),i.removeEventListener("mouseleave",g),a!==null&&clearTimeout(a)})}),()=>{for(let o of r)o()}}function Wn(e){var n,r,o;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(o=t==null?void 0:t.pathname)!=null?o:""}function _t(e,t,n){var b;let r=new Set,o=d=>{if(!r.has(d.goalId)){r.add(d.goalId);try{d.slotId?t.componentGoal(d.slotId,d.goalId):t.goal(d.goalId)}catch(y){}}},s=e.filter(d=>d.event==="click"),i=e.filter(d=>d.event==="form_submit"),l=e.filter(d=>d.event==="url_reached"),a=(d,y)=>{if(!d.locator)return!1;let S=H(d.locator,n);return!!S&&(S===y||S.contains(y))},c=d=>{let y=d.target;if(!(!y||typeof y.closest!="function"))for(let S of s)a(S,y)&&o(S)},u=d=>{let y=d.target;if(y)for(let S of i)a(S,y)&&o(S)},g=()=>{if(l.length===0)return;let d=Wn(n);for(let y of l)y.urlPattern&&d.includes(y.urlPattern)&&o(y)};return n.addEventListener("click",c,!0),n.addEventListener("submit",u,!0),(b=n.defaultView)==null||b.addEventListener("popstate",g),g(),{checkUrl:g,teardown:()=>{var d;n.removeEventListener("click",c,!0),n.removeEventListener("submit",u,!0),(d=n.defaultView)==null||d.removeEventListener("popstate",g)}}}var Rt="__snt_editor_token";function Tt(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(Rt):null}catch(e){return null}}function Lt(e){try{sessionStorage.setItem(Rt,e)}catch(t){}}var Ue="0.11.1",Bt=5e3,zn=50,W=null,L=null,z={},ie=null,se=null,X=null,I=null,Pt=!1,Ke=null;function Kt(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 he(e,t){return W?(W.personaAttributes&&I&&Ee(I.persona,I.band,e),Oe(z,W.slots,e),Ce(z,W.slots,e),ie?_e(z,ie,e,t):[]):[]}function Jn(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 qe(){try{let e=[];if(he(document,{onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),e.length>0&&L&&W&&W.sectionCapture!==!1&&W.consent!==!1&&!F())try{X==null||X(),X=Be(L,W.apiKey,e)}catch(t){}}catch(e){}}function Dt(){Ke===null&&(Ke=setTimeout(()=>{Ke=null,qe();try{se==null||se.checkUrl()}catch(e){}},zn))}function jt(){if(!(Pt||typeof window=="undefined"||typeof history=="undefined")){Pt=!0;try{let e=t=>{let n=history[t];history[t]=function(r,o,s){let i=n.call(this,r,o,s!=null?s:null);return Dt(),i}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Dt)}catch(e){}}}function Ge(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 Ut(e){return new URLSearchParams(e).get("sentient_editor")}function Vn(){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 Fn(e,t){var n,r,o,s;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let a=document.createElement("meta");a.name="referrer",a.content="no-referrer",((r=document.head)!=null?r:document.documentElement).appendChild(a)}catch(a){}let i=(o=e.editorSrc)!=null?o:Vn();if(!i){Nt();return}let l=document.createElement("script");l.src=i,l.async=!0,l.onerror=()=>Nt(),((s=document.head)!=null?s:document.documentElement).appendChild(l)}catch(i){}}var Mt="sentient-editor-load-notice";function Nt(){var e;try{if(typeof document=="undefined"||document.getElementById(Mt))return;let t=document.createElement("div");t.id=Mt,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 Gt(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let o=r.indexOf(":"),s=o===-1?"":r.slice(0,o),i=o===-1?"":r.slice(o+1);if(!(!s||!i))if(i.includes("=")){let l={};for(let a of i.split(",")){let[c,u]=a.split("=");c&&u&&(l[c]=u)}Object.keys(l).length&&(n[s]=l)}else n[s]=i}return Object.keys(n).length?n:null}function qt(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var $t="sentient-persona-preview-banner";function Hn(e){var t;try{if(typeof document=="undefined"||document.getElementById($t))return;let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),r=document.createElement("div");r.id=$t,r.setAttribute("role","status"),Object.assign(r.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",background:"#111827",color:"#fff",font:"13px/1 system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.14)"});let o=document.createElement("span");o.textContent=`Previewing as ${n}`;let s=document.createElement("button");s.type="button",s.textContent="Exit preview",Object.assign(s.style,{cursor:"pointer",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"inherit",padding:"4px 10px",borderRadius:"999px"}),s.addEventListener("click",()=>{try{let i=new URL(window.location.href);i.searchParams.delete("sentient_persona"),window.location.href=i.pathname+i.search+i.hash}catch(i){}}),r.appendChild(o),r.appendChild(s),((t=document.body)!=null?t:document.documentElement).appendChild(r)}catch(n){}}async function Yn(e,t){var c,u,g,b,d,y,S,E,w;let n=(c=e.apiBase)!=null?c:"https://api.sentient-ui.com",o=((u=e.registry)!=null?u:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([x,O])=>({id:x,dims:O.dims}))},s=await Kt(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(o)}).then(x=>x.ok?x.json():null).catch(()=>null),Bt);if(!s){ce(e,"persona preview: explain unavailable \u2014 page left as-is");return}let i=s;z=(g=i.slots)!=null?g:{},ie=(b=i.slotConfig)!=null?b:null;let l=(S=(y=(d=i.personaAttributes)==null?void 0:d.persona)!=null?y:i.persona)!=null?S:t,a=(w=(E=i.personaAttributes)==null?void 0:E.confidence)!=null?w:"high";I={persona:l,band:a},he(document),Wt(e),Hn(l)}function Wt(e){let t={goal(n,r){try{L==null||L.goal(n,r)}catch(o){}},componentGoal(n,r){try{L==null||L.componentGoal(n,r)}catch(o){}},grantConsent(){try{$e(e.apiKey)}catch(n){}},revokeConsent(){try{L==null||L.destroy()}catch(n){}},reapply:qe,getState(){var n,r;return{apiKey:e.apiKey,persona:(n=I==null?void 0:I.persona)!=null?n:null,band:(r=I==null?void 0:I.band)!=null?r:null,slots:z,matchCounts:Ge(e),consent:e.consent!==!1}}};window.SentientSnippet=t}async function zt(){var e,t,n;try{let r=Ie(window.sentient);if(!r)return;W=r;let o=typeof window!="undefined"?Ut(window.location.search):null;if(o){Lt(o);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 s=o!=null?o:Tt();if(s){Fn(r,s),ce(r,"editor mode");return}let i=typeof window!="undefined"?Gt(window.location.search):null;if(i){z=i,I=null,he(document),jt(),ce(r,"preview mode",i);return}let l=typeof window!="undefined"?qt(window.location.search):null;if(l){await Yn(r,l),ce(r,"persona preview",l);return}let a=(e=r.registry)!=null?e:Object.keys(r.slots).length===0,c=ke(r.apiKey);c&&(I={persona:c.persona,band:c.band},z=c.slots,c.slotConfig&&(ie=c.slotConfig),he(document,{contentAndOps:!1}));let u=Ae({apiKey:r.apiKey,context:r.context,consent:r.consent,preConsentBehavior:r.preConsentBehavior,debug:r.debug});L=u,Wt(r),jt();let g=Object.entries(r.slots).map(([w,x])=>({id:w,dims:x.dims})),b=Ue!=="0.0.0-dev"?{v:Ue}:{},d=await Kt(u.decide(ne(ne({slots:g},b),a?{slotsFrom:"registry"}:{})),Bt);if(!d){ce(r,"decide timeout/null \u2014 snapshot state stands",Ge(r));return}let y=u.getPersona();y?I={persona:y.persona,band:y.band}:d.persona&&(I={persona:d.persona,band:"low"}),z=d.slots,d.slotConfig&&(ie=d.slotConfig);let S=[];if(Jn(r,he(document,{onApplied:(w,x,O)=>S.push({slotId:w,arm:x,el:O})})),d.goals&&d.goals.length>0&&r.consent!==!1&&L)try{se==null||se.teardown(),se=_t(d.goals,L,document)}catch(w){}let E;try{let w=d.sectionMap;if(w&&w.length>0){let x=new Map;for(let O of w){if(O.urlMatch!==window.location.pathname)continue;let P=H(O.locator,document);P&&x.set(P,O.type)}x.size>0&&(E=O=>{var P;return(P=x.get(O))!=null?P:null})}}catch(w){}if(r.sectionCapture!==!1&&r.consent!==!1&&L&&!F()){try{kt(L,ne({apiKey:r.apiKey,apiBase:r.apiBase,doc:document,microSignals:!0},E?{typeOf:E}:{}))}catch(w){}try{X==null||X(),X=Be(L,r.apiKey,S)}catch(w){}}ce(r,"applied",{persona:I,slots:z,matches:Ge(r)}),ge(r.apiKey,ne({v:1,persona:(t=I==null?void 0:I.persona)!=null?t:d.persona,band:(n=I==null?void 0:I.band)!=null?n:"low",slots:d.slots,layoutOrder:d.layoutOrder,savedAt:Date.now()},ie?{slotConfig:ie}:{}))}catch(r){}}if(typeof window!="undefined"&&window.sentient){let e=window;e.__sentientInitialized||(e.__sentientInitialized=!0,zt())}return Yt(Xn);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentientui/snippet",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
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",
@@ -22,7 +22,7 @@
22
22
  "tsx": "^4.19.2",
23
23
  "typescript": "^5.7.2",
24
24
  "vitest": "^2.1.8",
25
- "@sentientui/core": "0.16.2"
25
+ "@sentientui/core": "0.16.3"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsup",