@sentientui/react 0.29.0 → 0.30.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/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- var Tt=Object.defineProperty,Ft=Object.defineProperties;var Bt=Object.getOwnPropertyDescriptors;var Q=Object.getOwnPropertySymbols;var Be=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable;var Fe=(e,t,n)=>t in e?Tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,S=(e,t)=>{for(var n in t||(t={}))Be.call(t,n)&&Fe(e,n,t[n]);if(Q)for(var n of Q(t))Me.call(t,n)&&Fe(e,n,t[n]);return e},K=(e,t)=>Ft(e,Bt(t));var Ke=(e,t)=>{var n={};for(var i in e)Be.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(e!=null&&Q)for(var i of Q(e))t.indexOf(i)<0&&Me.call(e,i)&&(n[i]=e[i]);return n};import{createContext as Nt,useContext as L,useEffect as V,useMemo as tt,useRef as xe,useState as te,useSyncExternalStore as $t}from"react";import{deriveSessionSegment as Vt,init as Wt}from"@sentientui/core";var je=new Map,Y=new Map;function Ne(e,t){let n=Y.get(e);return n||(n=new Set,Y.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Y.delete(e)}}function $e(e,t){je.set(e,t);let n=Y.get(e);if(n)for(let i of n)try{i(t)}catch(s){}}function ve(e){var t;return(t=je.get(e))!=null?t:null}var Mt={on:!1,listeners:new Set};function Ve(){if(typeof window=="undefined")return Mt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function ye(){return Ve().on}function We(e){let t=Ve().listeners;return t.add(e),()=>{t.delete(e)}}function Ue(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,i,s)=>e.assign(t,n,i,s),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getSlotConfig:t=>e.getSlotConfig(t),getSitePalette:()=>e.getSitePalette(),reportSlots:t=>e.reportSlots(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Je="sentient:overrides-changed";function He(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function D(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Je,e),()=>window.removeEventListener(Je,e))}function Xe(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function _(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function P(e){return typeof e=="string"?{type:"click"}:e}function N(e){return typeof e=="string"?e:e.type}function T(e){if(typeof e!="string"&&(e.type==="click"||e.type==="form_submit"||e.type==="scroll_depth"))return e.value}var Se=new Set,he=!1;function ze(e){if(Se.has(e))return!0;if(Se.add(e),!he){he=!0;let t=()=>{he=!1,Se.clear()};if(typeof MessageChannel=="function"){let n=new MessageChannel;n.port1.onmessage=()=>{n.port1.close(),n.port2.close(),t()},n.port2.postMessage(0)}else setTimeout(t,0)}return!1}function Kt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function qe(e,t,n){if(n){try{let s=e;for(;s&&s!==t;){if(s.matches(n))return!0;s=s.parentElement}}catch(s){}return!1}let i=e;for(;i&&i!==t;){if(Kt(i))return!0;i=i.parentElement}return!1}function F(e,t,n,i){if(t.type==="weighted_composite"){let l=new Set,d=[];return t.steps.forEach(({goal:f,name:p,weight:h},b)=>{let y=(c=!1)=>{l.has(b)||c&&i!==void 0&&ze(`step\0${p}\0${h}\0${b}`)||(l.add(b),n.fireStep(p,h,b))};if(f.type==="click"){let c=u=>{let g=u.target;g instanceof Element&&qe(g,e,f.selector)&&y()};e.addEventListener("click",c),d.push(()=>e.removeEventListener("click",c));return}if(f.type==="form_submit"){let c=u=>{u.target instanceof HTMLFormElement&&e.contains(u.target)&&y()};e.addEventListener("submit",c),d.push(()=>e.removeEventListener("submit",c));return}if(f.type==="scroll_depth"){let c=Math.max(0,Math.min(1,f.threshold)),u=new IntersectionObserver(g=>{for(let v of g)if(v.intersectionRatio>=c){y(!0),u.disconnect();break}},{threshold:[c]});u.observe(e),d.push(()=>u.disconnect())}}),()=>{for(let f of d)f()}}let s=t.type==="composite"?t.all:[t],r=new Set(s.map((l,d)=>d)),m=()=>{i!==void 0&&ze(i)||n.fireGoal()},o=(l,d=!1)=>{r.delete(l),r.size===0&&(d?m():n.fireGoal())},a=[];return s.forEach((l,d)=>{if(l.type==="click"){let f=p=>{let h=p.target;h instanceof Element&&qe(h,e,l.selector)&&(t.type==="composite"?o(d):n.fireGoal())};e.addEventListener("click",f),a.push(()=>e.removeEventListener("click",f));return}if(l.type==="form_submit"){let f=p=>{p.target instanceof HTMLFormElement&&e.contains(p.target)&&(t.type==="composite"?o(d):n.fireGoal())};e.addEventListener("submit",f),a.push(()=>e.removeEventListener("submit",f));return}if(l.type==="scroll_depth"){let f=Math.max(0,Math.min(1,l.threshold)),p=new IntersectionObserver(h=>{for(let b of h)if(b.intersectionRatio>=f){t.type==="composite"?o(d,!0):m(),p.disconnect();break}},{threshold:[f]});p.observe(e),a.push(()=>p.disconnect());return}}),()=>{for(let l of a)l()}}var Ze=new Set,Qe=new Set;function $(e,t,n,i,s){let r=`${i}|${n}`;if(Qe.has(r))return;Qe.add(r);let m=s.type==="weighted_composite"&&!Ze.has(i);m&&Ze.add(i),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:m?{funnelId:i,steps:s.steps.map(o=>({goalId:o.name,weight:o.weight}))}:{funnelId:i}})}function j(e,t,n,i){e.track({projectId:t,componentId:n,variantId:i,eventType:"variant_assigned",payload:{}})}var jt={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function U(){if(typeof window=="undefined")return jt;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function q(){U().version+=1;for(let e of U().listeners)e()}var Ye=()=>{};function ee(e){return _()?(U().components.set(e.id,e),q(),()=>{U().components.delete(e.id),q()}):Ye}function X(e){return _()?(U().slots.set(e.id,e),q(),()=>{U().slots.delete(e.id),q()}):Ye}function be(e){_()&&(U().sections=[...e],q())}var et="0.29.0",we=et!=="0.0.0-dev"?{name:"react",version:et}:void 0;import{jsx as qt}from"react/jsx-runtime";function Ut(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return Vt({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var nt="https://api.sentient-ui.com/v1",I=Nt({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialPersona:null,apiBaseUrl:nt,debug:!1});function Jt(e){let[t,n]=te(!1),i=xe(e);i.current=e;let{cookie:s,value:r,event:m}=e!=null?e:{},o=typeof(e==null?void 0:e.check)=="function";return V(()=>{let a=()=>{var p;let d=i.current;if(!d)return!1;if(d.check)return d.check()===!0;if(!d.cookie||typeof document=="undefined")return!1;let f=`${d.cookie}=${(p=d.value)!=null?p:"accepted"}`;return document.cookie.split("; ").some(h=>h.trim()===f)};if(n(a()),!m)return;let l=()=>{n(a())};return window.addEventListener(m,l),()=>window.removeEventListener(m,l)},[s,r,m,o]),t}function Ht(e){var b,y;let[t,n]=te(null),[i]=te(()=>{var c;return(c=e.sessionSegment)!=null?c:Ut()}),[s,r]=te(ye());V(()=>We(()=>r(ye())),[]);let m=Jt(e.consentFrom),o=e.consentFrom?e.consent===!0||m:e.consent,a=xe(null);V(()=>{var k;if(o===!1&&!e.preConsentBehavior){(k=a.current)==null||k.destroy(),a.current=null,n(null);return}let c=S({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:i,consent:o,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,persona:e.persona,localMode:e.localMode,initialSlots:e.initialSlots,initialSlotConfig:e.initialSlotConfig,initialPalette:e.initialPalette,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0},we?{sdk:we}:{}),u=!1,g=null,v=null,C=R=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:x})=>{u||(v=x(R,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:R})=>{u||(g=R(K(S({},c),{graph:!0,captureDomText:e.captureDomText===!0})),a.current=g,n(g),C(g))}):(g=Wt(c),a.current=g,n(g),C(g)),()=>{u=!0,v==null||v(),g==null||g.dispose()}},[o]),V(()=>{if(!t)return;let c=!1,u=async()=>{if(c)return;let v;try{v=await t.fetchWeights()}catch(C){return}if(!c)for(let C of v){let k={componentId:C.componentId,updatedAt:C.updatedAt,variants:C.variants.map(R=>{var x;return{variantId:R.variantId,pulls:R.pulls,avgReward:(x=R.avgReward)!=null?x:0}})};$e(C.componentId,k)}};u();let g=setInterval(()=>{u()},6e4);return()=>{c=!0,clearInterval(g)}},[t]);let l=(b=e.ssrFallback)!=null?b:"first",d=((y=e.apiBaseUrl)!=null?y:nt).replace(/\/$/,""),f=xe(null);V(()=>{var g;if(typeof process!="undefined"&&((g=process.env)==null?void 0:g.NODE_ENV)==="production")return;let c={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:d},u=f.current;if(f.current=c,u!==null)for(let v of["apiKey","context","country","persona","apiBaseUrl"])Object.is(u[v],c[v])||console.warn(`[sentient] AdaptiveProvider: \`${v}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,d]),V(()=>{var c;typeof process!="undefined"&&((c=process.env)==null?void 0:c.NODE_ENV)==="production"||Xe({apiKey:e.apiKey,apiBaseUrl:d,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,d]),V(()=>{let c=e.initialLayoutOrder;if(c&&c.length>0){be(c);return}e.declaredSections&&e.declaredSections.length>0&&be(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),V(()=>{if(!_())return;let c=e.declaredSections;if(!c||c.length===0||typeof document=="undefined")return;let u=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),v=>v.getAttribute("data-sentient-id"))),g=c.filter(v=>!u.has(v));g.length>0&&console.warn(`[SentientUI] Declared section${g.length>1?"s":""} ${g.map(v=>`"${v}"`).join(", ")} ${g.length>1?"have":"has"} no matching data-sentient-id element, so the layout engine cannot learn what they are and will serve the same order to every persona. Add data-sentient-id="<sectionId>" (plus optional data-sentient-type) to each section's element.`)},[e.declaredSections]);let p=tt(()=>t&&s?Ue(t):t,[t,s]),h=tt(()=>{var c,u,g,v,C,k,R;return{client:p,apiKey:e.apiKey,initialAssignments:(c=e.initialAssignments)!=null?c:{},sessionSegment:i,ssrFallback:l,onAssignment:e.onAssignment,initialLayoutOrder:(u=e.initialLayoutOrder)!=null?u:null,initialSlots:(g=e.initialSlots)!=null?g:{},initialSlotConfig:(v=e.initialSlotConfig)!=null?v:{},initialPalette:(C=e.initialPalette)!=null?C:null,initialPersona:(k=e.initialPersona)!=null?k:null,apiBaseUrl:d,debug:(R=e.debug)!=null?R:!1}},[p,e.apiKey,e.initialAssignments,i,l,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialPersona,d,e.debug]);return qt(I.Provider,{value:h,children:e.children})}function G(){return L(I).client}function B(){return L(I).apiKey}function Ae(){return L(I).initialAssignments}function ne(){return L(I).sessionSegment}function rt(){return L(I).ssrFallback}function re(){return L(I).onAssignment}function it(){return L(I).debug}function Xt(){let e=L(I).initialLayoutOrder,t=$t(D,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function ie(){return L(I).initialSlots}function ot(){return L(I).initialPersona}function st(){return L(I).initialSlotConfig}function at(){return L(I).initialPalette}function zt(){return L(I).apiBaseUrl}import{memo as Yt,useEffect as W,useMemo as ut,useRef as se,useState as en}from"react";import{attachMicroSignalDetectors as tn}from"@sentientui/core";import{useEffect as oe,useRef as lt,useState as Zt,useSyncExternalStore as Qt}from"react";import{pickFromWeights as Ce}from"@sentientui/policy";function z(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;if(!window.location.search)return null;try{let i=new URLSearchParams(window.location.search);for(let s of i.getAll("sentient_variant")){let r=s.indexOf(":");if(r!==-1&&s.slice(0,r)===e)return s.slice(r+1)}}catch(i){}return null}function Z(e,t,n,i){let s=Ae(),r=rt(),m=G(),o=ne(),a=re(),l=it(),d=lt(null),f=Qt(D,()=>z(e),()=>null),p=f&&t.includes(f)?f:null,h=lt(null);oe(()=>{l&&p&&h.current!==p&&(h.current=p,console.info(`[sentient] override active: ${e} -> ${p}`))},[l,p,e]);let[b,y]=Zt(()=>{var v,C;if(p)return{variantId:p,content:null,isLoading:!1,settled:!0};if(!m){let k=s[e];return k&&t.includes(k)?{variantId:k,content:null,isLoading:!1,settled:!0}:r==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let u=m.getAssignment(e,o);if(u&&(t.includes(u.variantId)||u.content))return{variantId:u.variantId,content:(v=u.content)!=null?v:null,isLoading:!1,settled:!0};let g=ve(e);if(g){let k=Ce(g.variants,t);if(k)return{variantId:k,content:null,isLoading:!1,settled:!0}}return{variantId:(C=t[0])!=null?C:null,content:null,isLoading:!1,settled:!1}}),c=u=>{a&&d.current!==u&&(d.current=u,a(e,u))};return oe(()=>{var v;if(p||!m)return;let u=m.getAssignment(e,o);if(u&&(t.includes(u.variantId)||u.content)){y({variantId:u.variantId,content:(v=u.content)!=null?v:null,isLoading:!1,settled:!0}),c(u.variantId);return}let g=ve(e);if(g&&b.settled&&b.variantId&&b.variantId===Ce(g.variants,t)){c(b.variantId);return}y(C=>{var k;return C.variantId?C:{variantId:(k=t[0])!=null?k:null,content:null,isLoading:!1,settled:!1}})},[p,m,e,o]),oe(()=>{if(p||!m)return;let u=m.getAssignment(e,o);if(u&&t.includes(u.variantId))return;let g=!1;return m.assign(e,t,n,i).then(v=>{var C;g||v&&(!t.includes(v.variantId)&&!v.content||(y({variantId:v.variantId,content:(C=v.content)!=null?C:null,isLoading:!1,settled:!0}),c(v.variantId)))}),()=>{g=!0}},[p,m,e,o]),oe(()=>{if(!p&&m)return Ne(e,u=>{var C;let g=m.getAssignment(e,o);if(g&&(t.includes(g.variantId)||g.content)){y({variantId:g.variantId,content:(C=g.content)!=null?C:null,isLoading:!1,settled:!0}),c(g.variantId);return}let v=Ce(u.variants,t);v&&(y({variantId:v,content:null,isLoading:!1,settled:!0}),c(v))})},[p,m,e,o]),p?{variantId:p,content:null,isLoading:!1,settled:!0,isOverride:!0}:b}import{jsx as on}from"react/jsx-runtime";function nn(e){var C;let t=G(),n=B(),i=Object.keys(e.variants).join("\0"),s=ut(()=>Object.keys(e.variants),[i]),{variantId:r,content:m,isOverride:o,settled:a}=Z(e.id,s,e.agentData,e.agentDataByVariant),l=se(null),[d,f]=en(!1);W(()=>{f(!0)},[]);let p=se(!1),h=se(new Set),b=se(null),y=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),c=ut(()=>P(e.goal),[y]),u=typeof e.goal=="string"?e.goal:c.type;if(W(()=>ee({id:e.id,variantIds:s,goal:u}),[e.id,s,u]),W(()=>{o||a&&(!t||!r||!n||b.current!==r&&(b.current=r,j(t,n,e.id,r)))},[t,r,n,e.id,o,a]),W(()=>{p.current=!1,h.current=new Set},[r,c]),W(()=>{o||!a||!t||!e.funnel||$(t,n,e.id,e.funnel,c)},[t,n,e.id,e.funnel,c,o,a]),W(()=>{if(o||!a||!t||!r)return;let k=l.current;if(!k)return;let R=null,x=0,A=()=>{x=Date.now(),R=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-x}}),R=null},800)},w=()=>{R!==null&&(clearTimeout(R),R=null)};return k.addEventListener("mouseenter",A),k.addEventListener("mouseleave",w),()=>{k.removeEventListener("mouseenter",A),k.removeEventListener("mouseleave",w),R!==null&&clearTimeout(R)}},[t,r,n,e.id,o,a]),W(()=>{if(o||!a||!t||!r)return;let k=l.current;if(!k)return;let R=Date.now();return tn((x,A={})=>{var Le,De,Te;t.track({projectId:n,componentId:e.id,variantId:r,eventType:"micro_signal",payload:S({signalType:x},A)});let w=(Le=e.microSignalGoals)==null?void 0:Le[x];if(!w||h.current.has(x))return;h.current.add(x);let E=typeof w=="string"?w:w.name,M=typeof w=="string"?1:(De=w.weight)!=null?De:1,H=typeof w=="string"?0:(Te=w.stepIndex)!=null?Te:0;t.goal(E,{metadata:S({signalType:x},A),weight:M,stepIndex:H})},k,R)},[t,r,n,e.id,e.microSignalGoals,o,a]),W(()=>{if(o||!a||!t||!r)return;let k=l.current;if(!k)return;let R=T(c);return F(k,c,{fireGoal:()=>{p.current||(p.current=!0,t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:u,payload:S({reward:1},R!==void 0?{goalValue:R}:{})}),t.goal(u,S({metadata:{componentId:e.id,variantId:r},weight:1,stepIndex:0},R!==void 0?{value:R}:{})))},fireStep:(x,A,w)=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:x,payload:{reward:A}}),t.goal(x,{metadata:{},weight:A,stepIndex:w})}},u)},[t,r,n,e.id,c,u,o,a]),e.clientOnly&&(!d||!t)||!r)return null;let g=(C=e.variants[r])!=null?C:null,v=g===null?m:null;return _()&&g===null&&v===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${r}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),on("div",{ref:l,"data-sentient-id":e.id,"data-sentient-variant":r,children:g!=null?g:v})}var rn=Yt(nn,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.funnel!==t.funnel||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),i=Object.keys(t.variants);return n.length!==i.length?!1:n.every(s=>s in t.variants&&Object.is(e.variants[s],t.variants[s]))});import{useEffect as ae,useMemo as sn,useRef as ke,useState as ct,useSyncExternalStore as an}from"react";import{jsx as un}from"react/jsx-runtime";function ln({id:e,default:t,component:n="span",className:i,goal:s}){var R;let r=G(),m=B(),o=re(),a=ne(),l=ke(null),d=ke(null),f=an(D,()=>z(e),()=>null),[p,h]=ct(()=>{var x,A;return(A=(x=r==null?void 0:r.getAssignment(e,a))==null?void 0:x.content)!=null?A:null}),[b,y]=ct(()=>{var x,A;return(A=(x=r==null?void 0:r.getAssignment(e,a))==null?void 0:x.variantId)!=null?A:null});ae(()=>{if(f||!r)return;let x=r.getAssignment(e,a);if((x==null?void 0:x.content)!==void 0){y(x.variantId),h(x.content);return}let A=!1;return r.assign(e).then(w=>{if(!A){if(!w){_()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}y(w.variantId),w.content&&h(w.content)}}),()=>{A=!0}},[r,e,a,f]),ae(()=>{f||!r||!b||!m||l.current!==b&&(l.current=b,r.track({projectId:m,componentId:e,variantId:b,eventType:"variant_assigned",payload:{}}),o==null||o(e,b))},[r,b,m,e,o,f]);let c=s===void 0?"":typeof s=="string"?s:JSON.stringify(s),u=sn(()=>s===void 0?null:P(s),[c]),g=s===void 0?null:typeof s=="string"?s:u.type,v=ke(!1);ae(()=>{v.current=!1},[b,c]),ae(()=>{if(f||!r||!b||!m||!u||!g)return;let x=d.current;if(!x)return;let A=T(u);return F(x,u,{fireGoal:()=>{v.current||(v.current=!0,r.track({projectId:m,componentId:e,variantId:b,eventType:"goal_achieved",goalType:g,payload:S({reward:1},A!==void 0?{goalValue:A}:{})}),r.goal(g,S({metadata:{componentId:e,variantId:b},weight:1,stepIndex:0},A!==void 0?{value:A}:{})))},fireStep:(w,E,M)=>{r.track({projectId:m,componentId:e,variantId:b,eventType:"goal_achieved",goalType:w,payload:{reward:E}}),r.goal(w,{metadata:{},weight:E,stepIndex:M})}})},[r,b,m,e,u,g,f]);let C=p!=null?p:t;if(f){let x=r==null?void 0:r.getAssignment(e,a);C=x&&x.variantId===f&&(R=x.content)!=null?R:t}return un(n,{ref:x=>{d.current=x},className:i,children:C})}import{useCallback as cn,useRef as dn}from"react";function Re(e){let t=G(),n=dn(new Set);return cn((i,s)=>{var r,m;if(!z(e)){if(s!=null&&s.once){if(n.current.has(i))return;n.current.add(i)}t==null||t.componentGoal(e,i,s),t==null||t.goal(i,S(S(S({metadata:(r=s==null?void 0:s.metadata)!=null?r:{},weight:(m=s==null?void 0:s.reward)!=null?m:1,stepIndex:0},(s==null?void 0:s.value)!==void 0?{value:s.value}:{}),(s==null?void 0:s.currency)!==void 0?{currency:s.currency}:{}),(s==null?void 0:s.externalId)!==void 0?{externalId:s.externalId}:{}))}},[t,e])}import{useEffect as fn,useRef as dt}from"react";function gn(e,t={}){let a=t,{componentId:n}=a,i=Ke(a,["componentId"]),s=G(),r=Re(n!=null?n:""),m=dt(!1),o=dt(i);o.current=i,fn(()=>{if(!s||m.current)return;m.current=!0;let{metadata:l,reward:d,value:f,currency:p,externalId:h}=o.current;if(n){r(e,o.current);return}s.goal(e,S(S(S({metadata:l!=null?l:{},weight:d!=null?d:1,stepIndex:0},f!==void 0?{value:f}:{}),p!==void 0?{currency:p}:{}),h!==void 0?{externalId:h}:{}))},[s,n,e,r])}import{renderPrePaintScript as mn}from"@sentientui/core";import{confidenceBand as pn}from"@sentientui/policy";import{jsx as Sn}from"react/jsx-runtime";function ft(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function vn(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+ft(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+ft(pn(e.persona.confidence))+");}catch(e){}})();":mn(e.apiKey)}function yn(e){return Sn("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:vn(e)}})}import{useEffect as ce,useMemo as Ge,useRef as kn}from"react";import{validateSlotDecl as Rn}from"@sentientui/policy";import{useEffect as _e,useReducer as hn,useState as bn,useSyncExternalStore as mt}from"react";import{armOfResult as le,baselineResultFor as wn}from"@sentientui/core";import{confidenceBand as xn}from"@sentientui/policy";var gt=new Set;function ue(e,t){let n=G(),i=ie(),[,s]=hn(d=>d+1,0),r=mt(D,()=>{var d;return typeof window!="undefined"?(d=window.__sentient_slot_overrides)==null?void 0:d[e]:void 0},()=>{}),m=r===void 0?i[e]:void 0,o=r===void 0&&m===void 0&&n?n.getSlotResult(e):null,a=(n==null?void 0:n.isLocal)===!0&&r===void 0&&m===void 0&&o===null;_e(()=>{if(!a||!n)return;let d=!1;return n.decide({slots:[t]}).then(f=>{!d&&f&&s()}),()=>{d=!0}},[n,e,a]);let l=(()=>{if(r!==void 0)return{result:r,arm:le(r),source:"override"};if(m!==void 0)return{result:m,arm:le(m),source:"preloaded"};if(o!==null)return{result:o,arm:le(o),source:"client"};let d=wn(t);return{result:d,arm:le(d),source:"baseline"}})();return _e(()=>{_()&&(!n||n.isLocal===!0||l.source==="baseline"&&(gt.has(e)||(gt.add(e),console.warn(`[sentient] slot "${e}" resolved to its baseline \u2014 no SSR-preloaded or decided result. Keyed clients decide slots server-side, so this slot serves baseline for the whole session and records no exposure. Preload it via loadAdaptiveDecision()/initialSlots so it can serve a decided arm and learn.`))))},[n,l.source,e]),l}function An(){var t;if(typeof window=="undefined")return null;let e=window.__sentient_persona_override;if(e!=null&&e.persona)return{persona:e.persona,confidence:(t=e.confidence)!=null?t:1};try{let n=new URLSearchParams(window.location.search).get("sentient_persona");if(n)return{persona:n,confidence:1}}catch(n){}return null}function Cn(){let e=G(),t=ot();mt(D,He,()=>0);let[n,i]=bn(!1);_e(()=>i(!0),[]);let s=o=>({persona:o.persona,confidence:o.confidence,band:xn(o.confidence)});if(!n)return t?s(t):null;let r=An();if(r)return s(r);if(t)return s(t);let m=e?e.getPersona():null;return m?s(m):null}var pt=new Set;function _n(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function Gn(e,t,n){let i=G(),s=B(),r=JSON.stringify(t),m=Ge(()=>({id:e,dims:t}),[e,r]),{result:o,arm:a,source:l}=ue(e,m),d=Ge(()=>typeof o=="string"?{}:o,[a]);if(_()&&!pt.has(e)){pt.add(e);let y=Rn({id:e,dims:Object.fromEntries(Object.entries(t).map(([u,g])=>[u,[...g]]))}),c=Object.values(t).reduce((u,g)=>u*g.length,1);y.ok?c>4&&console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${c} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`):console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${y.reason}. Serving baseline.`)}let f=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);ce(()=>X({id:e,dims:t}),[e]);let p=kn(null);ce(()=>{!i||l==="baseline"||l==="override"||p.current===a||(p.current=a,j(i,s,e,a))},[i,s,e,a,l]);let h=n==null?void 0:n.funnel;ce(()=>{var y;!i||!h||l==="override"||$(i,s,e,h,P((y=n==null?void 0:n.goal)!=null?y:"click"))},[i,s,e,h,f,l]),ce(()=>{if(!i||!(n!=null&&n.goal)||l==="override"||l==="baseline")return;let y=document.querySelector(`[data-sentient-slot="${_n(e)}"]`);if(!y){_()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let c=N(n.goal),u=T(n.goal),g=!1;return F(y,P(n.goal),{fireGoal:()=>{g||(g=!0,u!==void 0?i.componentGoal(e,c,{value:u}):i.componentGoal(e,c),i.goal(c,S({metadata:{componentId:e,arm:a},weight:1,stepIndex:0},u!==void 0?{value:u}:{})))},fireStep:(v,C,k)=>{i.componentGoal(e,v,{reward:C}),i.goal(v,{metadata:{componentId:e,arm:a},weight:C,stepIndex:k})}},c)},[i,e,f,a,l]);let b=Ge(()=>{let y={"data-sentient-slot":e};for(let[c,u]of Object.entries(d))y[`data-${c}`]=u;return y},[e,d]);return{tokens:d,props:b}}import{useEffect as ge,useMemo as Tn,useRef as Rt}from"react";import{containsFormBlock as Fn}from"@sentientui/core";import{useEffect as Oe,useReducer as On,useSyncExternalStore as vt}from"react";import{armOfResult as En}from"@sentientui/core";var yt=new Set;function St(e){var b;let t=G(),n=ie(),i=st(),s=at(),[,r]=On(y=>y+1,0),m=vt(D,()=>{var y;return typeof window!="undefined"?(y=window.__sentient_slot_config_overrides)==null?void 0:y[e]:void 0},()=>{}),o=vt(D,()=>{var y;return typeof window!="undefined"?(y=window.__sentient_slot_overrides)==null?void 0:y[e]:void 0},()=>{}),a=m===void 0?i[e]:void 0,l=m===void 0&&a===void 0&&t?t.getSlotConfig(e):null,d=y=>y==null?"":En(y),f=(b=s!=null?s:t==null?void 0:t.getSitePalette())!=null?b:null,p=(t==null?void 0:t.isLocal)===!0&&m===void 0&&a===void 0&&l===null;Oe(()=>{if(!p||!t)return;let y=!1;return t.decide({slotsFrom:"registry"}).then(c=>{!y&&c&&r()}),()=>{y=!0}},[t,e,p]);let h=(()=>{var y,c;return m!==void 0?{config:m,arm:d(o),palette:f,source:"override"}:a!==void 0?{config:a,arm:d((y=n[e])!=null?y:t==null?void 0:t.getSlotResult(e)),palette:f,source:"preloaded"}:l!==null?{config:l,arm:d((c=t==null?void 0:t.getSlotResult(e))!=null?c:n[e]),palette:f,source:"client"}:{config:null,arm:"",palette:f,source:"none"}})();return Oe(()=>{!t||t.isLocal===!0||h.source!=="none"||t.reportSlots([e])},[t,h.source,e]),Oe(()=>{_()&&(!t||t.isLocal===!0||h.source==="none"&&(yt.has(e)||(yt.add(e),console.warn(`[sentient] AdaptiveSlot "${e}" has no server config \u2014 rendering its baseline children. Preload it via loadAdaptiveDecision({ slotsFrom: 'registry' }) and pass initialSlotConfig/initialSlots to <AdaptiveProvider> so it can serve a decided arm and learn.`))))},[t,h.source,e]),h}import{Fragment as ht}from"react";import{jsx as O,jsxs as At}from"react/jsx-runtime";var de={none:"0",sm:"8px",md:"16px",lg:"24px"},Ee={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch",between:"space-between"},Ct={sm:"0.875em",md:"1em",lg:"1.25em"},Pn={sm:"1.25em",md:"1.5em",lg:"2em"},bt={sm:"6px 14px",md:"10px 20px",lg:"14px 28px"},wt={sm:"8px",md:"16px",lg:"32px"},In={square:"1 / 1",landscape:"4 / 3",wide:"16 / 9"},Ln={normal:"400",medium:"500",bold:"700"};function xt(e){return S(S({},e==="muted"?{opacity:.7}:{}),e==="accent"?{fontWeight:600}:{})}function kt(e,t,n){var i,s,r,m;return K(S({display:"inline-block",padding:(i=bt[n!=null?n:"md"])!=null?i:bt.md,borderRadius:(s=t==null?void 0:t.radius)!=null?s:"8px",font:"inherit"},n?{fontSize:Ct[n]}:{}),{textDecoration:e==="ghost"?"underline":"none",cursor:"pointer",background:e==="primary"?(r=t==null?void 0:t.primaryBg)!=null?r:"#111827":"transparent",color:e==="primary"?(m=t==null?void 0:t.primaryText)!=null?m:"#ffffff":"inherit",border:e==="secondary"?"1px solid currentColor":"none"})}function Dn({node:e,opts:t}){var s,r,m;let n=(s=e.emphasis)!=null?s:"primary",i={padding:"8px 10px",font:"inherit",border:"1px solid currentColor",borderRadius:(m=(r=t.palette)==null?void 0:r.radius)!=null?m:"8px"};return At("form",{onSubmit:o=>{var d,f,p;o.preventDefault();let a=new FormData(o.currentTarget),l={};for(let h of e.fields)l[h.name]=String((d=a.get(h.name))!=null?d:"");(f=t.onFormGoal)==null||f.call(t,e.submitGoal);try{(p=t.onFormSubmit)==null||p.call(t,l)}catch(h){}},style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e.fields.map(o=>{var a,l;return At("label",{style:{display:"flex",flexDirection:"column",gap:"4px",font:"inherit"},children:[o.label,o.kind==="textarea"?O("textarea",{name:o.name,required:o.required,placeholder:o.placeholder,rows:3,style:i}):o.kind==="select"?O("select",{name:o.name,required:o.required,style:i,children:((a=o.options)!=null?a:[]).map(d=>O("option",{value:d,children:d},d))}):O("input",{name:o.name,type:(l=o.inputType)!=null?l:"text",required:o.required,placeholder:o.placeholder,style:i})]},o.name)}),O("button",{type:"submit",style:kt(n,t.palette),children:e.submitLabel})]})}function fe(e,t){var n,i,s,r,m,o,a,l,d;try{switch(e.type){case"stack":{let f=(i=de[(n=e.gap)!=null?n:"md"])!=null?i:de.md;return O("div",{style:S(S(S({display:"flex",flexDirection:e.direction,gap:f},e.align?{alignItems:Ee[e.align]}:{}),e.justify?{justifyContent:Ee[e.justify]}:{}),e.wrap?{flexWrap:"wrap"}:{}),children:((s=e.children)!=null?s:[]).map((p,h)=>{let b=fe(p,t);return b===null?null:O(ht,{children:b},h)})})}case"grid":{let f=(m=de[(r=e.gap)!=null?r:"md"])!=null?m:de.md;return O("div",{style:S({display:"grid",gridTemplateColumns:`repeat(auto-fit, minmax(max(200px, calc((100% - ${e.columns-1} * ${f}) / ${e.columns})), 1fr))`,gap:f},e.align?{alignItems:Ee[e.align]}:{}),children:((o=e.children)!=null?o:[]).map((p,h)=>{let b=fe(p,t);return b===null?null:O(ht,{children:b},h)})})}case"text":return O("p",{style:S(S(S(S({margin:0},e.size?{fontSize:Ct[e.size]}:{}),e.weight?{fontWeight:Ln[e.weight]}:{}),e.align?{textAlign:e.align}:{}),xt(e.tone)),children:e.value});case"heading":{let f=`h${e.level}`;return O(f,{style:S({margin:0,fontSize:Pn[(a=e.size)!=null?a:"md"]},e.align?{textAlign:e.align}:{}),children:e.value})}case"button":{let f=(l=e.emphasis)!=null?l:"primary";return O("a",K(S({href:e.href},e.tag?{"data-sentient-tag":e.tag}:{}),{style:kt(f,t.palette,e.size),children:e.label}))}case"link":return O("a",K(S({href:e.href},e.tag?{"data-sentient-tag":e.tag}:{}),{style:{color:"inherit",textDecoration:"underline"},children:e.label}));case"image":return O("img",{src:e.src,alt:e.alt,style:S(S({display:"block",maxWidth:"100%"},e.ratio&&e.ratio!=="auto"?{aspectRatio:In[e.ratio],width:"100%"}:{}),e.fit?{objectFit:e.fit}:{})});case"badge":return O("span",{style:S({display:"inline-block",padding:"2px 10px",borderRadius:"999px",fontSize:"0.75em",border:"1px solid currentColor"},xt(e.tone)),children:e.value});case"spacer":return O("div",{style:{height:(d=wt[e.size])!=null?d:wt.md}});case"form":return O(Dn,{node:e,opts:t});default:return null}}catch(f){return null}}import{jsx as Mn}from"react/jsx-runtime";var _t=new Set;function Bn({id:e,children:t,onFormSubmit:n,goal:i,className:s}){var C,k;let r=G(),m=B(),{config:o,arm:a,palette:l,source:d}=St(e),f=Rt(null),p=a!==""?(C=o==null?void 0:o.blocks)==null?void 0:C[a]:void 0,h=p!==void 0&&Fn(p)&&!n;ge(()=>{!h||!_()||_t.has(e)||(_t.add(e),console.warn(`[sentient] AdaptiveSlot "${e}" was served a form arm but has no onFormSubmit handler \u2014 rendering its baseline children instead. Pass onFormSubmit to render generated forms.`))},[h,e]);let b=R=>{!r||d==="override"||(r.componentGoal(e,R),r.goal(R,{metadata:{componentId:e,arm:a},weight:1,stepIndex:0}))},y=t;p!==void 0&&!h?y=(k=fe(p,{palette:l,onFormSubmit:n,onFormGoal:b}))!=null?k:t:(o==null?void 0:o.content)!==void 0&&d!=="none"&&(y=o.content);let c=o!=null&&o.blocks?Object.keys(o.blocks).sort().join("|"):"";ge(()=>X({id:e,arms:c===""?void 0:c.split("|")}),[e,c]);let u=Rt(null);ge(()=>{!r||d==="none"||d==="override"||a===""||u.current===a||(u.current=a,j(r,m,e,a))},[r,m,e,a,d]);let g=i===void 0?null:typeof i=="string"?i:JSON.stringify(i);ge(()=>{if(!r||!i||d==="override"||d==="none")return;let R=f.current;if(!R)return;let x=N(i),A=T(i),w=!1;return F(R,P(i),{fireGoal:()=>{w||(w=!0,A!==void 0?r.componentGoal(e,x,{value:A}):r.componentGoal(e,x),r.goal(x,S({metadata:{componentId:e,arm:a},weight:1,stepIndex:0},A!==void 0?{value:A}:{})))},fireStep:(E,M,H)=>{r.componentGoal(e,E,{reward:M}),r.goal(E,{metadata:{componentId:e,arm:a},weight:M,stepIndex:H})}},x)},[r,e,g,a,d]);let v=Tn(()=>S({"data-sentient-slot":e},a!==""?{"data-sentient-arm":a}:{}),[e,a]);return Mn("div",K(S({ref:f,className:s},v),{children:y}))}import{useCallback as Gt,useEffect as J,useMemo as Pe,useRef as Ie,useState as Kn}from"react";import{attachMicroSignalDetectors as jn}from"@sentientui/core";var Ot=new Set;function Nn(e,t){var x;if(_()&&!t.goal)throw new Error(`[sentient] useAdaptive("${e}"): a goal is required \u2014 without one the optimizer accumulates exposures with no rewards and cannot learn. Pass e.g. goal: 'buy_click'.`);let n=G(),i=B(),s=Object.keys(t.variants).join(" "),r=Pe(()=>Object.keys(t.variants),[s]),{variantId:m,isOverride:o,settled:a}=Z(e,r),l=(x=m!=null?m:r[0])!=null?x:"",d=t.variants[l],[f,p]=Kn(null),h=Ie(null),b=Gt(A=>{h.current=A,p(A)},[]),y=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),c=Pe(()=>t.goal?P(t.goal):null,[y]),u=t.goal?N(t.goal):"";J(()=>ee({id:e,variantIds:r,goal:u}),[e,r,u]);let g=Ie(null);J(()=>{o||a&&(!n||!l||!f||g.current!==l&&(g.current=l,j(n,i,e,l)))},[n,i,e,l,f,o,a]);let v=t.funnel;J(()=>{o||!a||!n||!v||!c||$(n,i,e,v,c)},[n,i,e,v,c,o,a]);let C=Ie(!1);J(()=>{C.current=!1},[l,y]),J(()=>{if(o||!a||!n||!l||!f||!c)return;let A=T(c);return F(f,c,{fireGoal:()=>{C.current||(C.current=!0,n.track({projectId:i,componentId:e,variantId:l,eventType:"goal_achieved",goalType:u,payload:S({reward:1},A!==void 0?{goalValue:A}:{})}),n.goal(u,S({metadata:{componentId:e,variantId:l},weight:1,stepIndex:0},A!==void 0?{value:A}:{})))},fireStep:(w,E,M)=>{n.track({projectId:i,componentId:e,variantId:l,eventType:"goal_achieved",goalType:w,payload:{reward:E}}),n.goal(w,{metadata:{},weight:E,stepIndex:M})}},u)},[n,f,l,i,e,c,u,o,a]),J(()=>{if(o||!n||!l||!f)return;let A=Date.now();return jn((w,E={})=>{n.track({projectId:i,componentId:e,variantId:l,eventType:"micro_signal",payload:S({signalType:w},E)})},f,A)},[n,f,l,i,e,o]),J(()=>{if(!_()||!n)return;let A=setTimeout(()=>{!h.current&&!Ot.has(e)&&(Ot.add(e),console.warn(`[sentient] useAdaptive("${e}"): bind was never attached \u2014 spread {...bind} on the rendered element, otherwise exposure and goal tracking cannot work and the optimizer learns nothing.`))},0);return()=>clearTimeout(A)},[n,e]);let k=Gt((A,w)=>{var M,H;if(o)return;let E=A!=null?A:u;E&&(n==null||n.componentGoal(e,E,w),n==null||n.goal(E,S(S(S({metadata:(M=w==null?void 0:w.metadata)!=null?M:{},weight:(H=w==null?void 0:w.reward)!=null?H:1,stepIndex:0},(w==null?void 0:w.value)!==void 0?{value:w.value}:{}),(w==null?void 0:w.currency)!==void 0?{currency:w.currency}:{}),(w==null?void 0:w.externalId)!==void 0?{externalId:w.externalId}:{})))},[n,e,u,o]),R=Pe(()=>({ref:b,"data-sentient-id":e,"data-sentient-variant":l}),[b,e,l]);return{variant:l,value:d,bind:R,fireGoal:k}}import{Children as $n,isValidElement as Vn,useEffect as me,useMemo as Et,useRef as Pt}from"react";import{jsx as Un}from"react/jsx-runtime";var pe=new Set;function Wn(e){var u;let t=G(),n=B(),i=Pt(null),s=Object.keys(e.arrangements).join(" "),r=Et(()=>Object.keys(e.arrangements),[s]),m=Et(()=>S({id:e.id,arms:r},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,r,e.baseline]),{arm:o,source:a}=ue(e.id,m);_()&&e.baseline!==void 0&&e.baseline!==r[0]&&!pe.has(e.id+":baseline")&&(pe.add(e.id+":baseline"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: baseline "${e.baseline}" is not the first-declared arrangement ("${r[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let l=$n.toArray(e.children).filter(Vn),d=new Map;for(let g of l)d.set(String((u=g.key)!=null?u:"").replace(/^\.\$/,""),g);let f=e.arrangements[o],p=f!==void 0&&f.length===l.length&&f.every(g=>d.has(g));_()&&f!==void 0&&!p&&!pe.has(e.id+":keys")&&(pe.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${o}" [${f.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let h=p?f.map(g=>d.get(g)):l;me(()=>X({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let b=Pt(null);me(()=>{!t||a==="baseline"||a==="override"||b.current===o||(b.current=o,j(t,n,e.id,o))},[t,n,e.id,o,a]);let y=e.funnel;me(()=>{var g;!t||!y||a==="override"||$(t,n,e.id,y,P((g=e.goal)!=null?g:"click"))},[t,n,e.id,y,a]);let c=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return me(()=>{if(!t||e.goal===void 0||a==="override"||a==="baseline")return;let g=i.current;if(!g)return;let v=N(e.goal),C=T(e.goal),k=!1;return F(g,P(e.goal),{fireGoal:()=>{k||(k=!0,C!==void 0?t.componentGoal(e.id,v,{value:C}):t.componentGoal(e.id,v),t.goal(v,S({metadata:{componentId:e.id,arm:o},weight:1,stepIndex:0},C!==void 0?{value:C}:{})))},fireStep:(R,x,A)=>{t.componentGoal(e.id,R,{reward:x}),t.goal(R,{metadata:{componentId:e.id,arm:o},weight:x,stepIndex:A})}},v)},[t,e.id,c,o,a]),Un("div",{ref:i,"data-sentient-id":e.id,"data-sentient-variant":o,children:h})}import{deriveSessionSegment as Jn}from"@sentientui/core";var Hn=["page","blocks","layoutOrder"],It=new Map;function Xn(e,t){It.set(e,t)}function Lt(e){return It.get(e)}function zn(e){var s,r;let t=(r=(s=e.content)!=null?s:Lt(e.page))!=null?r:{},n={};for(let[m,o]of Object.entries(t))Hn.includes(m)||(n[m]=o);let i=K(S({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(i.layoutOrder=e.layoutOrder),i}function qn(e){return`<script type="application/ld+json">${Dt(e)}</script>`}function Dt(e){return JSON.stringify(S({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function Zn(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,i]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(i,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
2
+ var Wt=Object.defineProperty,Ut=Object.defineProperties;var Jt=Object.getOwnPropertyDescriptors;var ne=Object.getOwnPropertySymbols;var je=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable;var Ke=(e,t,n)=>t in e?Wt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))je.call(t,n)&&Ke(e,n,t[n]);if(ne)for(var n of ne(t))Ve.call(t,n)&&Ke(e,n,t[n]);return e},N=(e,t)=>Ut(e,Jt(t));var We=(e,t)=>{var n={};for(var r in e)je.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ne)for(var r of ne(e))t.indexOf(r)<0&&Ve.call(e,r)&&(n[r]=e[r]);return n};import{createContext as Yt,useContext as L,useEffect as j,useMemo as ct,useRef as Oe,useState as se,useSyncExternalStore as Qt}from"react";import{deriveSessionSegment as en,init as tn}from"@sentientui/core";var Ue=new Map,re=new Map;function Je(e,t){let n=re.get(e);return n||(n=new Set,re.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&re.delete(e)}}function ze(e,t){Ue.set(e,t);let n=re.get(e);if(n)for(let r of n)try{r(t)}catch(i){}}function he(e){var t;return(t=Ue.get(e))!=null?t:null}var zt={on:!1,listeners:new Set};function Xe(){if(typeof window=="undefined")return zt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function be(){return Xe().on}function He(e){let t=Xe().listeners;return t.add(e),()=>{t.delete(e)}}function qe(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,r,i)=>e.assign(t,n,r,i),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getSlotConfig:t=>e.getSlotConfig(t),getSitePalette:()=>e.getSitePalette(),reportSlots:t=>e.reportSlots(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var we="sentient:overrides-changed";function Ze(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function Ye(){var t;if(typeof window=="undefined")return;let e=window;e.__sentient_overrides_version=((t=e.__sentient_overrides_version)!=null?t:0)+1,window.dispatchEvent(new Event(we))}function F(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(we,e),()=>window.removeEventListener(we,e))}function Qe(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function R(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function I(e){return typeof e=="string"?{type:"click"}:e}function V(e){return typeof e=="string"?e:e.type}function B(e){if(typeof e!="string"&&(e.type==="click"||e.type==="form_submit"||e.type==="scroll_depth"))return e.value}var xe=new Set,Ce=!1;function et(e){if(xe.has(e))return!0;if(xe.add(e),!Ce){Ce=!0;let t=()=>{Ce=!1,xe.clear()};if(typeof MessageChannel=="function"){let n=new MessageChannel;n.port1.onmessage=()=>{n.port1.close(),n.port2.close(),t()},n.port2.postMessage(0)}else setTimeout(t,0)}return!1}function Xt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function tt(e,t,n){if(n){try{let i=e;for(;i&&i!==t;){if(i.matches(n))return!0;i=i.parentElement}}catch(i){}return!1}let r=e;for(;r&&r!==t;){if(Xt(r))return!0;r=r.parentElement}return!1}function $(e,t,n,r){if(t.type==="weighted_composite"){let s=new Set,d=[];return t.steps.forEach(({goal:p,name:m,weight:C},w)=>{let S=(u=!1)=>{s.has(w)||u&&r!==void 0&&et(`step\0${m}\0${C}\0${w}`)||(s.add(w),n.fireStep(m,C,w))};if(p.type==="click"){let u=l=>{let f=l.target;f instanceof Element&&tt(f,e,p.selector)&&S()};e.addEventListener("click",u),d.push(()=>e.removeEventListener("click",u));return}if(p.type==="form_submit"){let u=l=>{l.target instanceof HTMLFormElement&&e.contains(l.target)&&S()};e.addEventListener("submit",u),d.push(()=>e.removeEventListener("submit",u));return}if(p.type==="scroll_depth"){let u=Math.max(0,Math.min(1,p.threshold)),l=new IntersectionObserver(f=>{for(let y of f)if(y.intersectionRatio>=u){S(!0),l.disconnect();break}},{threshold:[u]});l.observe(e),d.push(()=>l.disconnect())}}),()=>{for(let p of d)p()}}let i=t.type==="composite"?t.all:[t],o=new Set(i.map((s,d)=>d)),c=()=>{r!==void 0&&et(r)||n.fireGoal()},a=(s,d=!1)=>{o.delete(s),o.size===0&&(d?c():n.fireGoal())},g=[];return i.forEach((s,d)=>{if(s.type==="click"){let p=m=>{let C=m.target;C instanceof Element&&tt(C,e,s.selector)&&(t.type==="composite"?a(d):n.fireGoal())};e.addEventListener("click",p),g.push(()=>e.removeEventListener("click",p));return}if(s.type==="form_submit"){let p=m=>{m.target instanceof HTMLFormElement&&e.contains(m.target)&&(t.type==="composite"?a(d):n.fireGoal())};e.addEventListener("submit",p),g.push(()=>e.removeEventListener("submit",p));return}if(s.type==="scroll_depth"){let p=Math.max(0,Math.min(1,s.threshold)),m=new IntersectionObserver(C=>{for(let w of C)if(w.intersectionRatio>=p){t.type==="composite"?a(d,!0):c(),m.disconnect();break}},{threshold:[p]});m.observe(e),g.push(()=>m.disconnect());return}}),()=>{for(let s of g)s()}}var nt=new Set,rt=new Set;function W(e,t,n,r,i){let o=`${r}|${n}`;if(rt.has(o))return;rt.add(o);let c=i.type==="weighted_composite"&&!nt.has(r);c&&nt.add(r),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:c?{funnelId:r,steps:i.steps.map(a=>({goalId:a.name,weight:a.weight}))}:{funnelId:r}})}function K(e,t,n,r){e.track({projectId:t,componentId:n,variantId:r,eventType:"variant_assigned",payload:{}})}var Ht={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function z(){if(typeof window=="undefined")return Ht;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function Q(){z().version+=1;for(let e of z().listeners)e()}var it=()=>{};function ie(e){return R()?(z().components.set(e.id,e),Q(),()=>{z().components.delete(e.id),Q()}):it}function q(e){return R()?(z().slots.set(e.id,e),Q(),()=>{z().slots.delete(e.id),Q()}):it}function _e(e){R()&&(z().sections=[...e],Q())}var ot="0.30.0",Ae=ot!=="0.0.0-dev"?{name:"react",version:ot}:void 0;function qt(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function ke(e,t){qt()[e]=t}function Zt(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function Re(e,t){Zt()[e]=t}var st="sentient_editor",at="sentient_preview_cell",Ge="sentient-cell-preview-bar",Ee="__preview__";function lt(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(Ge))return;let t,n;try{let a=new URLSearchParams(window.location.search);t=a.get(st),n=a.get(at)}catch(a){return}if(!t||!n)return;let r=n.lastIndexOf("~");if(r<=0)return;let i=n.slice(0,r),o=n.slice(r+1),c=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");fetch(`${c}/editor/cell-preview?slotId=${encodeURIComponent(i)}&persona=${encodeURIComponent(o)}`,{headers:{authorization:`Bearer ${t}`}}).then(async a=>{if(!a.ok){oe(a.status===401?"This preview link has expired \u2014 reopen it from your dashboard.":"Couldn\u2019t load this preview \u2014 reopen it from your dashboard.");return}let g=await a.json();if(g.blocks!=null)ke(i,{kind:"arms",blocks:{[Ee]:g.blocks}}),Re(i,Ee);else if(g.content!=null)ke(i,{kind:"arms",content:g.content}),Re(i,Ee);else{oe("Nothing to preview in that square yet.");return}Ye(),oe(`Previewing \u201C${g.slotName}\u201D for ${g.personaDisplay}${g.status==="review"?" \u2014 waiting for your approval":""}. Nothing is being tracked.`),setTimeout(()=>{var s;try{(s=document.querySelector(`[data-sentient-slot="${i}"]`))==null||s.scrollIntoView({block:"center"})}catch(d){}},300)}).catch(()=>oe("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function oe(e){var i;if(document.getElementById(Ge))return;let t=document.createElement("div");t.id=Ge,Object.assign(t.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"10px",padding:"10px 14px",borderRadius:"12px",maxWidth:"90vw",background:"#111827",color:"#fff",font:"13px system-ui, sans-serif",border:"1px solid rgba(139,92,246,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});let n=document.createElement("span");n.textContent=e;let r=document.createElement("button");r.textContent="Exit preview",Object.assign(r.style,{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.35)",background:"transparent",color:"#fff",font:"12px system-ui, sans-serif",cursor:"pointer"}),r.onclick=()=>{let o=new URL(window.location.href);o.searchParams.delete(st),o.searchParams.delete(at),window.location.assign(o.toString())},t.append(n,r),((i=document.body)!=null?i:document.documentElement).append(t)}import{jsx as ln}from"react/jsx-runtime";function nn(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return en({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var ut="https://api.sentient-ui.com/v1",T=Yt({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialPersona:null,apiBaseUrl:ut,debug:!1});function rn(e){let[t,n]=se(!1),r=Oe(e);r.current=e;let{cookie:i,value:o,event:c}=e!=null?e:{},a=typeof(e==null?void 0:e.check)=="function";return j(()=>{let g=()=>{var m;let d=r.current;if(!d)return!1;if(d.check)return d.check()===!0;if(!d.cookie||typeof document=="undefined")return!1;let p=`${d.cookie}=${(m=d.value)!=null?m:"accepted"}`;return document.cookie.split("; ").some(C=>C.trim()===p)};if(n(g()),!c)return;let s=()=>{n(g())};return window.addEventListener(c,s),()=>window.removeEventListener(c,s)},[i,o,c,a]),t}function on(e){var w,S;let[t,n]=se(null),[r]=se(()=>{var u;return(u=e.sessionSegment)!=null?u:nn()}),[i,o]=se(be());j(()=>He(()=>o(be())),[]),j(()=>{lt(e.apiBaseUrl)},[]);let c=rn(e.consentFrom),a=e.consentFrom?e.consent===!0||c:e.consent,g=Oe(null);j(()=>{var A;if(a===!1&&!e.preConsentBehavior){(A=g.current)==null||A.destroy(),g.current=null,n(null);return}let u=v({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:r,consent:a,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,persona:e.persona,localMode:e.localMode,initialSlots:e.initialSlots,initialSlotConfig:e.initialSlotConfig,initialPalette:e.initialPalette,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0},Ae?{sdk:Ae}:{}),l=!1,f=null,y=null,_=k=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:b})=>{l||(y=b(k,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:k})=>{l||(f=k(N(v({},u),{graph:!0,captureDomText:e.captureDomText===!0})),g.current=f,n(f),_(f))}):(f=tn(u),g.current=f,n(f),_(f)),()=>{l=!0,y==null||y(),f==null||f.dispose()}},[a]),j(()=>{if(!t)return;let u=!1,l=async()=>{if(u)return;let y;try{y=await t.fetchWeights()}catch(_){return}if(!u)for(let _ of y){let A={componentId:_.componentId,updatedAt:_.updatedAt,variants:_.variants.map(k=>{var b;return{variantId:k.variantId,pulls:k.pulls,avgReward:(b=k.avgReward)!=null?b:0}})};ze(_.componentId,A)}};l();let f=setInterval(()=>{l()},6e4);return()=>{u=!0,clearInterval(f)}},[t]);let s=(w=e.ssrFallback)!=null?w:"first",d=((S=e.apiBaseUrl)!=null?S:ut).replace(/\/$/,""),p=Oe(null);j(()=>{var f;if(typeof process!="undefined"&&((f=process.env)==null?void 0:f.NODE_ENV)==="production")return;let u={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:d},l=p.current;if(p.current=u,l!==null)for(let y of["apiKey","context","country","persona","apiBaseUrl"])Object.is(l[y],u[y])||console.warn(`[sentient] AdaptiveProvider: \`${y}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,d]),j(()=>{var u;typeof process!="undefined"&&((u=process.env)==null?void 0:u.NODE_ENV)==="production"||Qe({apiKey:e.apiKey,apiBaseUrl:d,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,d]),j(()=>{let u=e.initialLayoutOrder;if(u&&u.length>0){_e(u);return}e.declaredSections&&e.declaredSections.length>0&&_e(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),j(()=>{if(!R())return;let u=e.declaredSections;if(!u||u.length===0||typeof document=="undefined")return;let l=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),y=>y.getAttribute("data-sentient-id"))),f=u.filter(y=>!l.has(y));f.length>0&&console.warn(`[SentientUI] Declared section${f.length>1?"s":""} ${f.map(y=>`"${y}"`).join(", ")} ${f.length>1?"have":"has"} no matching data-sentient-id element, so the layout engine cannot learn what they are and will serve the same order to every persona. Add data-sentient-id="<sectionId>" (plus optional data-sentient-type) to each section's element.`)},[e.declaredSections]);let m=ct(()=>t&&i?qe(t):t,[t,i]),C=ct(()=>{var u,l,f,y,_,A,k;return{client:m,apiKey:e.apiKey,initialAssignments:(u=e.initialAssignments)!=null?u:{},sessionSegment:r,ssrFallback:s,onAssignment:e.onAssignment,initialLayoutOrder:(l=e.initialLayoutOrder)!=null?l:null,initialSlots:(f=e.initialSlots)!=null?f:{},initialSlotConfig:(y=e.initialSlotConfig)!=null?y:{},initialPalette:(_=e.initialPalette)!=null?_:null,initialPersona:(A=e.initialPersona)!=null?A:null,apiBaseUrl:d,debug:(k=e.debug)!=null?k:!1}},[m,e.apiKey,e.initialAssignments,r,s,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialPersona,d,e.debug]);return ln(T.Provider,{value:C,children:e.children})}function E(){return L(T).client}function M(){return L(T).apiKey}function Pe(){return L(T).initialAssignments}function ae(){return L(T).sessionSegment}function dt(){return L(T).ssrFallback}function le(){return L(T).onAssignment}function ft(){return L(T).debug}function sn(){let e=L(T).initialLayoutOrder,t=Qt(F,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function ce(){return L(T).initialSlots}function gt(){return L(T).initialPersona}function mt(){return L(T).initialSlotConfig}function pt(){return L(T).initialPalette}function an(){return L(T).apiBaseUrl}import{memo as dn,useEffect as U,useMemo as yt,useRef as de,useState as fn}from"react";import{attachMicroSignalDetectors as gn}from"@sentientui/core";import{useEffect as ue,useRef as vt,useState as cn,useSyncExternalStore as un}from"react";import{pickFromWeights as Ie}from"@sentientui/policy";function Z(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;if(!window.location.search)return null;try{let r=new URLSearchParams(window.location.search);for(let i of r.getAll("sentient_variant")){let o=i.indexOf(":");if(o!==-1&&i.slice(0,o)===e)return i.slice(o+1)}}catch(r){}return null}function ee(e,t,n,r){let i=Pe(),o=dt(),c=E(),a=ae(),g=le(),s=ft(),d=vt(null),p=un(F,()=>Z(e),()=>null),m=p&&t.includes(p)?p:null,C=vt(null);ue(()=>{s&&m&&C.current!==m&&(C.current=m,console.info(`[sentient] override active: ${e} -> ${m}`))},[s,m,e]);let[w,S]=cn(()=>{var y,_;if(m)return{variantId:m,content:null,isLoading:!1,settled:!0};if(!c){let A=i[e];return A&&t.includes(A)?{variantId:A,content:null,isLoading:!1,settled:!0}:o==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let l=c.getAssignment(e,a);if(l&&(t.includes(l.variantId)||l.content))return{variantId:l.variantId,content:(y=l.content)!=null?y:null,isLoading:!1,settled:!0};let f=he(e);if(f){let A=Ie(f.variants,t);if(A)return{variantId:A,content:null,isLoading:!1,settled:!0}}return{variantId:(_=t[0])!=null?_:null,content:null,isLoading:!1,settled:!1}}),u=l=>{g&&d.current!==l&&(d.current=l,g(e,l))};return ue(()=>{var y;if(m||!c)return;let l=c.getAssignment(e,a);if(l&&(t.includes(l.variantId)||l.content)){S({variantId:l.variantId,content:(y=l.content)!=null?y:null,isLoading:!1,settled:!0}),u(l.variantId);return}let f=he(e);if(f&&w.settled&&w.variantId&&w.variantId===Ie(f.variants,t)){u(w.variantId);return}S(_=>{var A;return _.variantId?_:{variantId:(A=t[0])!=null?A:null,content:null,isLoading:!1,settled:!1}})},[m,c,e,a]),ue(()=>{if(m||!c)return;let l=c.getAssignment(e,a);if(l&&t.includes(l.variantId))return;let f=!1;return c.assign(e,t,n,r).then(y=>{var _;f||y&&(!t.includes(y.variantId)&&!y.content||(S({variantId:y.variantId,content:(_=y.content)!=null?_:null,isLoading:!1,settled:!0}),u(y.variantId)))}),()=>{f=!0}},[m,c,e,a]),ue(()=>{if(!m&&c)return Je(e,l=>{var _;let f=c.getAssignment(e,a);if(f&&(t.includes(f.variantId)||f.content)){S({variantId:f.variantId,content:(_=f.content)!=null?_:null,isLoading:!1,settled:!0}),u(f.variantId);return}let y=Ie(l.variants,t);y&&(S({variantId:y,content:null,isLoading:!1,settled:!0}),u(y))})},[m,c,e,a]),m?{variantId:m,content:null,isLoading:!1,settled:!0,isOverride:!0}:w}import{jsx as vn}from"react/jsx-runtime";function mn(e){var _;let t=E(),n=M(),r=Object.keys(e.variants).join("\0"),i=yt(()=>Object.keys(e.variants),[r]),{variantId:o,content:c,isOverride:a,settled:g}=ee(e.id,i,e.agentData,e.agentDataByVariant),s=de(null),[d,p]=fn(!1);U(()=>{p(!0)},[]);let m=de(!1),C=de(new Set),w=de(null),S=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),u=yt(()=>I(e.goal),[S]),l=typeof e.goal=="string"?e.goal:u.type;if(U(()=>ie({id:e.id,variantIds:i,goal:l}),[e.id,i,l]),U(()=>{a||g&&(!t||!o||!n||w.current!==o&&(w.current=o,K(t,n,e.id,o)))},[t,o,n,e.id,a,g]),U(()=>{m.current=!1,C.current=new Set},[o,u]),U(()=>{a||!g||!t||!e.funnel||W(t,n,e.id,e.funnel,u)},[t,n,e.id,e.funnel,u,a,g]),U(()=>{if(a||!g||!t||!o)return;let A=s.current;if(!A)return;let k=null,b=0,x=()=>{b=Date.now(),k=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:o,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-b}}),k=null},800)},h=()=>{k!==null&&(clearTimeout(k),k=null)};return A.addEventListener("mouseenter",x),A.addEventListener("mouseleave",h),()=>{A.removeEventListener("mouseenter",x),A.removeEventListener("mouseleave",h),k!==null&&clearTimeout(k)}},[t,o,n,e.id,a,g]),U(()=>{if(a||!g||!t||!o)return;let A=s.current;if(!A)return;let k=Date.now();return gn((b,x={})=>{var H,Y,Ne;t.track({projectId:n,componentId:e.id,variantId:o,eventType:"micro_signal",payload:v({signalType:b},x)});let h=(H=e.microSignalGoals)==null?void 0:H[b];if(!h||C.current.has(b))return;C.current.add(b);let G=typeof h=="string"?h:h.name,P=typeof h=="string"?1:(Y=h.weight)!=null?Y:1,D=typeof h=="string"?0:(Ne=h.stepIndex)!=null?Ne:0;t.goal(G,{metadata:v({signalType:b},x),weight:P,stepIndex:D})},A,k)},[t,o,n,e.id,e.microSignalGoals,a,g]),U(()=>{if(a||!g||!t||!o)return;let A=s.current;if(!A)return;let k=B(u);return $(A,u,{fireGoal:()=>{m.current||(m.current=!0,t.track({projectId:n,componentId:e.id,variantId:o,eventType:"goal_achieved",goalType:l,payload:v({reward:1},k!==void 0?{goalValue:k}:{})}),t.goal(l,v({metadata:{componentId:e.id,variantId:o},weight:1,stepIndex:0},k!==void 0?{value:k}:{})))},fireStep:(b,x,h)=>{t.track({projectId:n,componentId:e.id,variantId:o,eventType:"goal_achieved",goalType:b,payload:{reward:x}}),t.goal(b,{metadata:{},weight:x,stepIndex:h})}},l)},[t,o,n,e.id,u,l,a,g]),e.clientOnly&&(!d||!t)||!o)return null;let f=(_=e.variants[o])!=null?_:null,y=f===null?c:null;return R()&&f===null&&y===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${o}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),vn("div",{ref:s,"data-sentient-id":e.id,"data-sentient-variant":o,children:f!=null?f:y})}var pn=dn(mn,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.funnel!==t.funnel||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),r=Object.keys(t.variants);return n.length!==r.length?!1:n.every(i=>i in t.variants&&Object.is(e.variants[i],t.variants[i]))});import{useEffect as fe,useMemo as yn,useRef as Te,useState as St,useSyncExternalStore as Sn}from"react";import{jsx as bn}from"react/jsx-runtime";function hn({id:e,default:t,component:n="span",className:r,goal:i}){var k;let o=E(),c=M(),a=le(),g=ae(),s=Te(null),d=Te(null),p=Sn(F,()=>Z(e),()=>null),[m,C]=St(()=>{var b,x;return(x=(b=o==null?void 0:o.getAssignment(e,g))==null?void 0:b.content)!=null?x:null}),[w,S]=St(()=>{var b,x;return(x=(b=o==null?void 0:o.getAssignment(e,g))==null?void 0:b.variantId)!=null?x:null});fe(()=>{if(p||!o)return;let b=o.getAssignment(e,g);if((b==null?void 0:b.content)!==void 0){S(b.variantId),C(b.content);return}let x=!1;return o.assign(e).then(h=>{if(!x){if(!h){R()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}S(h.variantId),h.content&&C(h.content)}}),()=>{x=!0}},[o,e,g,p]),fe(()=>{p||!o||!w||!c||s.current!==w&&(s.current=w,o.track({projectId:c,componentId:e,variantId:w,eventType:"variant_assigned",payload:{}}),a==null||a(e,w))},[o,w,c,e,a,p]);let u=i===void 0?"":typeof i=="string"?i:JSON.stringify(i),l=yn(()=>i===void 0?null:I(i),[u]),f=i===void 0?null:typeof i=="string"?i:l.type,y=Te(!1);fe(()=>{y.current=!1},[w,u]),fe(()=>{if(p||!o||!w||!c||!l||!f)return;let b=d.current;if(!b)return;let x=B(l);return $(b,l,{fireGoal:()=>{y.current||(y.current=!0,o.track({projectId:c,componentId:e,variantId:w,eventType:"goal_achieved",goalType:f,payload:v({reward:1},x!==void 0?{goalValue:x}:{})}),o.goal(f,v({metadata:{componentId:e,variantId:w},weight:1,stepIndex:0},x!==void 0?{value:x}:{})))},fireStep:(h,G,P)=>{o.track({projectId:c,componentId:e,variantId:w,eventType:"goal_achieved",goalType:h,payload:{reward:G}}),o.goal(h,{metadata:{},weight:G,stepIndex:P})}})},[o,w,c,e,l,f,p]);let _=m!=null?m:t;if(p){let b=o==null?void 0:o.getAssignment(e,g);_=b&&b.variantId===p&&(k=b.content)!=null?k:t}return bn(n,{ref:b=>{d.current=b},className:r,children:_})}import{useCallback as wn,useRef as xn}from"react";function Le(e){let t=E(),n=xn(new Set);return wn((r,i)=>{var o,c;if(!Z(e)){if(i!=null&&i.once){if(n.current.has(r))return;n.current.add(r)}t==null||t.componentGoal(e,r,i),t==null||t.goal(r,v(v(v({metadata:(o=i==null?void 0:i.metadata)!=null?o:{},weight:(c=i==null?void 0:i.reward)!=null?c:1,stepIndex:0},(i==null?void 0:i.value)!==void 0?{value:i.value}:{}),(i==null?void 0:i.currency)!==void 0?{currency:i.currency}:{}),(i==null?void 0:i.externalId)!==void 0?{externalId:i.externalId}:{}))}},[t,e])}import{useEffect as Cn,useRef as ht}from"react";function _n(e,t={}){let g=t,{componentId:n}=g,r=We(g,["componentId"]),i=E(),o=Le(n!=null?n:""),c=ht(!1),a=ht(r);a.current=r,Cn(()=>{if(!i||c.current)return;c.current=!0;let{metadata:s,reward:d,value:p,currency:m,externalId:C}=a.current;if(n){o(e,a.current);return}i.goal(e,v(v(v({metadata:s!=null?s:{},weight:d!=null?d:1,stepIndex:0},p!==void 0?{value:p}:{}),m!==void 0?{currency:m}:{}),C!==void 0?{externalId:C}:{}))},[i,n,e,o])}import{renderPrePaintScript as An}from"@sentientui/core";import{confidenceBand as kn}from"@sentientui/policy";import{jsx as Gn}from"react/jsx-runtime";function bt(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Rn(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+bt(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+bt(kn(e.persona.confidence))+");}catch(e){}})();":An(e.apiKey)}function En(e){return Gn("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Rn(e)}})}import{useEffect as pe,useMemo as Fe,useRef as Fn}from"react";import{validateSlotDecl as Bn}from"@sentientui/policy";import{useEffect as De,useReducer as On,useState as Pn,useSyncExternalStore as xt}from"react";import{armOfResult as ge,baselineResultFor as In}from"@sentientui/core";import{confidenceBand as Tn}from"@sentientui/policy";var wt=new Set;function me(e,t){let n=E(),r=ce(),[,i]=On(d=>d+1,0),o=xt(F,()=>{var d;return typeof window!="undefined"?(d=window.__sentient_slot_overrides)==null?void 0:d[e]:void 0},()=>{}),c=o===void 0?r[e]:void 0,a=o===void 0&&c===void 0&&n?n.getSlotResult(e):null,g=(n==null?void 0:n.isLocal)===!0&&o===void 0&&c===void 0&&a===null;De(()=>{if(!g||!n)return;let d=!1;return n.decide({slots:[t]}).then(p=>{!d&&p&&i()}),()=>{d=!0}},[n,e,g]);let s=(()=>{if(o!==void 0)return{result:o,arm:ge(o),source:"override"};if(c!==void 0)return{result:c,arm:ge(c),source:"preloaded"};if(a!==null)return{result:a,arm:ge(a),source:"client"};let d=In(t);return{result:d,arm:ge(d),source:"baseline"}})();return De(()=>{R()&&(!n||n.isLocal===!0||s.source==="baseline"&&(wt.has(e)||(wt.add(e),console.warn(`[sentient] slot "${e}" resolved to its baseline \u2014 no SSR-preloaded or decided result. Keyed clients decide slots server-side, so this slot serves baseline for the whole session and records no exposure. Preload it via loadAdaptiveDecision()/initialSlots so it can serve a decided arm and learn.`))))},[n,s.source,e]),s}function Ln(){var t;if(typeof window=="undefined")return null;let e=window.__sentient_persona_override;if(e!=null&&e.persona)return{persona:e.persona,confidence:(t=e.confidence)!=null?t:1};try{let n=new URLSearchParams(window.location.search).get("sentient_persona");if(n)return{persona:n,confidence:1}}catch(n){}return null}function Dn(){let e=E(),t=gt();xt(F,Ze,()=>0);let[n,r]=Pn(!1);De(()=>r(!0),[]);let i=a=>({persona:a.persona,confidence:a.confidence,band:Tn(a.confidence)});if(!n)return t?i(t):null;let o=Ln();if(o)return i(o);if(t)return i(t);let c=e?e.getPersona():null;return c?i(c):null}var Ct=new Set;function $n(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function Mn(e,t,n){let r=E(),i=M(),o=JSON.stringify(t),c=Fe(()=>({id:e,dims:t}),[e,o]),{result:a,arm:g,source:s}=me(e,c),d=Fe(()=>typeof a=="string"?{}:a,[g]);if(R()&&!Ct.has(e)){Ct.add(e);let S=Bn({id:e,dims:Object.fromEntries(Object.entries(t).map(([l,f])=>[l,[...f]]))}),u=Object.values(t).reduce((l,f)=>l*f.length,1);S.ok?u>4&&console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${u} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`):console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${S.reason}. Serving baseline.`)}let p=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);pe(()=>q({id:e,dims:t}),[e]);let m=Fn(null);pe(()=>{!r||s==="baseline"||s==="override"||m.current===g||(m.current=g,K(r,i,e,g))},[r,i,e,g,s]);let C=n==null?void 0:n.funnel;pe(()=>{var S;!r||!C||s==="override"||W(r,i,e,C,I((S=n==null?void 0:n.goal)!=null?S:"click"))},[r,i,e,C,p,s]),pe(()=>{if(!r||!(n!=null&&n.goal)||s==="override"||s==="baseline")return;let S=document.querySelector(`[data-sentient-slot="${$n(e)}"]`);if(!S){R()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let u=V(n.goal),l=B(n.goal),f=!1;return $(S,I(n.goal),{fireGoal:()=>{f||(f=!0,l!==void 0?r.componentGoal(e,u,{value:l}):r.componentGoal(e,u),r.goal(u,v({metadata:{componentId:e,arm:g},weight:1,stepIndex:0},l!==void 0?{value:l}:{})))},fireStep:(y,_,A)=>{r.componentGoal(e,y,{reward:_}),r.goal(y,{metadata:{componentId:e,arm:g},weight:_,stepIndex:A})}},u)},[r,e,p,g,s]);let w=Fe(()=>{let S={"data-sentient-slot":e};for(let[u,l]of Object.entries(d))S[`data-${u}`]=l;return S},[e,d]);return{tokens:d,props:w}}import{useEffect as ve,useMemo as Jn,useRef as Dt}from"react";import{containsFormBlock as zn}from"@sentientui/core";import{useEffect as _t,useRef as Nn,useSyncExternalStore as At}from"react";import{armOfResult as Kn}from"@sentientui/core";var kt=new Set;function Rt(e,t){var w;let n=E(),r=Nn(t==null?void 0:t.baselineText);r.current=t==null?void 0:t.baselineText;let i=ce(),o=mt(),c=pt(),a=At(F,()=>{var S;return typeof window!="undefined"?(S=window.__sentient_slot_config_overrides)==null?void 0:S[e]:void 0},()=>{}),g=At(F,()=>{var S;return typeof window!="undefined"?(S=window.__sentient_slot_overrides)==null?void 0:S[e]:void 0},()=>{}),s=a===void 0?o[e]:void 0,d=a===void 0&&s===void 0&&n?n.getSlotConfig(e):null,p=S=>S==null?"":Kn(S),m=(w=c!=null?c:n==null?void 0:n.getSitePalette())!=null?w:null,C=(()=>{var S,u;return a!==void 0?{config:a,arm:p(g),palette:m,source:"override"}:s!==void 0?{config:s,arm:p((S=i[e])!=null?S:n==null?void 0:n.getSlotResult(e)),palette:m,source:"preloaded"}:d!==null?{config:d,arm:p((u=n==null?void 0:n.getSlotResult(e))!=null?u:i[e]),palette:m,source:"client"}:{config:null,arm:"",palette:m,source:"none"}})();return _t(()=>{var u,l;if(!n||n.isLocal===!0||C.source!=="none")return;let S=(l=(u=r.current)==null?void 0:u.call(r))!=null?l:null;S!=null&&S!==""?n.reportSlots([e],{[e]:S}):n.reportSlots([e])},[n,C.source,e]),_t(()=>{if(R()&&n&&C.source==="none"&&!kt.has(e)){if(kt.add(e),n.isLocal===!0){console.warn(`[sentient] AdaptiveSlot "${e}" is rendering its baseline children: in local/keyless mode AdaptiveSlot serves ONLY what you pass as \`initialSlotConfig\` (there is no registry to decide from). Pass initialSlotConfig/initialSlots to <AdaptiveProvider> to preview arms locally.`);return}console.warn(`[sentient] AdaptiveSlot "${e}" has no server config \u2014 rendering its baseline children. Keyed clients issue no client-side registry decide, so a production CSR-only app will NEVER serve this slot: preload the decision server-side via loadAdaptiveDecision({ slotsFrom: 'registry' }) and pass initialSlotConfig/initialSlots to <AdaptiveProvider> so it can serve a decided arm and learn.`)}},[n,C.source,e]),C}import{Fragment as Et}from"react";import{jsx as O,jsxs as It}from"react/jsx-runtime";var J={none:"0",sm:"8px",md:"16px",lg:"24px"},Be={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch",between:"space-between"},Tt={sm:"0.875em",md:"1em",lg:"1.25em"},jn={sm:"1.25em",md:"1.5em",lg:"2em"},Gt={sm:"6px 14px",md:"10px 20px",lg:"14px 28px"},Ot={sm:"8px",md:"16px",lg:"32px"},Vn={square:"1 / 1",landscape:"4 / 3",wide:"16 / 9"},Wn={normal:"400",medium:"500",bold:"700"};function Pt(e,t){return v(v({},e==="muted"?t!=null&&t.muted?{color:t.muted}:{opacity:.7}:{}),e==="accent"?v({fontWeight:600},t!=null&&t.accent?{color:t.accent}:{}):{})}function Lt(e,t,n){var i,o,c,a;let r=t==null?void 0:t.accent;return N(v({display:"inline-block",padding:(i=Gt[n!=null?n:"md"])!=null?i:Gt.md,borderRadius:(o=t==null?void 0:t.radius)!=null?o:"8px",font:"inherit"},n?{fontSize:Tt[n]}:{}),{textDecoration:e==="ghost"?"underline":"none",cursor:"pointer",background:e==="primary"?(c=t==null?void 0:t.primaryBg)!=null?c:"#111827":"transparent",color:e==="primary"?(a=t==null?void 0:t.primaryText)!=null?a:"#ffffff":r!=null?r:"inherit",border:e==="secondary"?`1px solid ${r!=null?r:"currentColor"}`:"none"})}function Un({node:e,opts:t}){var i,o,c,a,g;let n=(i=e.emphasis)!=null?i:"primary",r={padding:"8px 10px",font:"inherit",border:`1px solid ${(c=(o=t.palette)==null?void 0:o.border)!=null?c:"currentColor"}`,borderRadius:(g=(a=t.palette)==null?void 0:a.radius)!=null?g:"8px"};return It("form",{onSubmit:s=>{var m,C,w;s.preventDefault();let d=new FormData(s.currentTarget),p={};for(let S of e.fields)p[S.name]=String((m=d.get(S.name))!=null?m:"");(C=t.onFormGoal)==null||C.call(t,e.submitGoal);try{(w=t.onFormSubmit)==null||w.call(t,p)}catch(S){}},style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e.fields.map(s=>{var d,p;return It("label",{style:{display:"flex",flexDirection:"column",gap:"4px",font:"inherit"},children:[s.label,s.kind==="textarea"?O("textarea",{name:s.name,required:s.required,placeholder:s.placeholder,rows:3,style:r}):s.kind==="select"?O("select",{name:s.name,required:s.required,style:r,children:((d=s.options)!=null?d:[]).map(m=>O("option",{value:m,children:m},m))}):O("input",{name:s.name,type:(p=s.inputType)!=null?p:"text",required:s.required,placeholder:s.placeholder,style:r})]},s.name)}),O("button",{type:"submit",style:Lt(n,t.palette),children:e.submitLabel})]})}function te(e,t){var n,r,i,o,c,a,g,s,d,p,m,C,w,S,u,l,f,y,_,A,k,b,x;try{switch(e.type){case"stack":{let h=(r=J[(n=e.gap)!=null?n:"md"])!=null?r:J.md,G=e.surface==="raised",P=(i=e.pad)!=null?i:G?"md":void 0;return O("div",{style:v(v(v(v(v({display:"flex",flexDirection:e.direction,gap:h},e.align?{alignItems:Be[e.align]}:{}),e.justify?{justifyContent:Be[e.justify]}:{}),e.wrap?{flexWrap:"wrap"}:{}),P?{padding:(o=J[P])!=null?o:J.md}:{}),G?N(v(v({},(c=t.palette)!=null&&c.surface?{background:t.palette.surface}:{}),(a=t.palette)!=null&&a.surface&&((g=t.palette)!=null&&g.surfaceText)?{color:t.palette.surfaceText}:{}),{border:`1px solid ${(d=(s=t.palette)==null?void 0:s.border)!=null?d:"currentColor"}`,borderRadius:(m=(p=t.palette)==null?void 0:p.radius)!=null?m:"8px"}):{}),children:((C=e.children)!=null?C:[]).map((D,H)=>{let Y=te(D,t);return Y===null?null:O(Et,{children:Y},H)})})}case"grid":{let h=(S=J[(w=e.gap)!=null?w:"md"])!=null?S:J.md;return O("div",{style:v(v({display:"grid",gridTemplateColumns:`repeat(auto-fit, minmax(max(200px, calc((100% - ${e.columns-1} * ${h}) / ${e.columns})), 1fr))`,gap:h},e.align?{alignItems:Be[e.align]}:{}),e.pad?{padding:(u=J[e.pad])!=null?u:J.md}:{}),children:((l=e.children)!=null?l:[]).map((G,P)=>{let D=te(G,t);return D===null?null:O(Et,{children:D},P)})})}case"text":return O("p",{style:v(v(v(v(v({margin:0},e.size?{fontSize:Tt[e.size]}:{}),e.weight?{fontWeight:Wn[e.weight]}:{}),e.align?{textAlign:e.align}:{}),e.maxWidth==="measure"?{maxWidth:"65ch"}:{}),Pt(e.tone,t.palette)),children:e.value});case"heading":{let h=`h${e.level}`;return O(h,{style:v(v({margin:0,fontSize:jn[(f=e.size)!=null?f:"md"]},e.align?{textAlign:e.align}:{}),e.maxWidth==="measure"?{maxWidth:"65ch"}:{}),children:e.value})}case"button":{let h=(y=e.emphasis)!=null?y:"primary";return O("a",N(v({href:e.href},e.tag?{"data-sentient-tag":e.tag}:{}),{style:Lt(h,t.palette,e.size),children:e.label}))}case"link":return O("a",N(v({href:e.href},e.tag?{"data-sentient-tag":e.tag}:{}),{style:{color:"inherit",textDecoration:"underline"},children:e.label}));case"image":return O("img",{src:e.src,alt:e.alt,style:v(v({display:"block",maxWidth:"100%"},e.ratio&&e.ratio!=="auto"?{aspectRatio:Vn[e.ratio],width:"100%"}:{}),e.fit?{objectFit:e.fit}:{})});case"badge":return O("span",{style:v({display:"inline-block",padding:"2px 10px",borderRadius:"999px",fontSize:"0.75em",border:`1px solid ${(A=(_=t.palette)==null?void 0:_.border)!=null?A:"currentColor"}`},Pt(e.tone,t.palette)),children:e.value});case"spacer":return O("div",{style:{height:(k=Ot[e.size])!=null?k:Ot.md}});case"divider":return O("hr",{style:{border:"none",borderTop:`1px solid ${(x=(b=t.palette)==null?void 0:b.border)!=null?x:"currentColor"}`,margin:0,width:"100%"}});case"form":return O(Un,{node:e,opts:t});default:return null}}catch(h){return null}}import{jsx as Hn}from"react/jsx-runtime";var Ft=new Set;function Xn({id:e,children:t,onFormSubmit:n,goal:r,className:i,reportBaselineText:o=!0}){var k;let c=E(),a=M(),g=Dt(null),{config:s,arm:d,palette:p,source:m}=Rt(e,{baselineText:o?()=>{var b,x;return(x=(b=g.current)==null?void 0:b.textContent)!=null?x:null}:void 0}),C=d!==""?(k=s==null?void 0:s.blocks)==null?void 0:k[d]:void 0,w=C!==void 0&&zn(C)&&!n;ve(()=>{!w||!R()||Ft.has(e)||(Ft.add(e),console.warn(`[sentient] AdaptiveSlot "${e}" was served a form arm but has no onFormSubmit handler \u2014 rendering its baseline children instead. Pass onFormSubmit to render generated forms.`))},[w,e]);let S=b=>{!c||m==="override"||(c.componentGoal(e,b),c.goal(b,{metadata:{componentId:e,arm:d},weight:1,stepIndex:0}))},u=t,l=!1;if(C!==void 0){let b=w?null:te(C,{palette:p,onFormSubmit:n,onFormGoal:S});b===null?l=!0:u=b}else(s==null?void 0:s.content)!==void 0&&m!=="none"&&(u=s.content);let f=s!=null&&s.blocks?Object.keys(s.blocks).sort().join("|"):"";ve(()=>q({id:e,arms:f===""?void 0:f.split("|")}),[e,f]);let y=Dt(null);ve(()=>{!c||m==="none"||m==="override"||d===""||l||y.current!==d&&(y.current=d,K(c,a,e,d))},[c,a,e,d,m,l]);let _=r===void 0?null:typeof r=="string"?r:JSON.stringify(r);ve(()=>{if(!c||!r||m==="override"||m==="none"||l)return;let b=g.current;if(!b)return;let x=V(r),h=B(r),G=!1;return $(b,I(r),{fireGoal:()=>{G||(G=!0,h!==void 0?c.componentGoal(e,x,{value:h}):c.componentGoal(e,x),c.goal(x,v({metadata:{componentId:e,arm:d},weight:1,stepIndex:0},h!==void 0?{value:h}:{})))},fireStep:(P,D,H)=>{c.componentGoal(e,P,{reward:D}),c.goal(P,{metadata:{componentId:e,arm:d},weight:D,stepIndex:H})}},x)},[c,e,_,d,m,l]);let A=Jn(()=>v({"data-sentient-slot":e},d!==""?{"data-sentient-arm":d}:{}),[e,d]);return Hn("div",N(v({ref:g,className:i},A),{children:u}))}import{useCallback as Bt,useEffect as X,useMemo as $e,useRef as Me,useState as qn}from"react";import{attachMicroSignalDetectors as Zn}from"@sentientui/core";var $t=new Set;function Yn(e,t){var b;if(R()&&!t.goal)throw new Error(`[sentient] useAdaptive("${e}"): a goal is required \u2014 without one the optimizer accumulates exposures with no rewards and cannot learn. Pass e.g. goal: 'buy_click'.`);let n=E(),r=M(),i=Object.keys(t.variants).join(" "),o=$e(()=>Object.keys(t.variants),[i]),{variantId:c,isOverride:a,settled:g}=ee(e,o),s=(b=c!=null?c:o[0])!=null?b:"",d=t.variants[s],[p,m]=qn(null),C=Me(null),w=Bt(x=>{C.current=x,m(x)},[]),S=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),u=$e(()=>t.goal?I(t.goal):null,[S]),l=t.goal?V(t.goal):"";X(()=>ie({id:e,variantIds:o,goal:l}),[e,o,l]);let f=Me(null);X(()=>{a||g&&(!n||!s||!p||f.current!==s&&(f.current=s,K(n,r,e,s)))},[n,r,e,s,p,a,g]);let y=t.funnel;X(()=>{a||!g||!n||!y||!u||W(n,r,e,y,u)},[n,r,e,y,u,a,g]);let _=Me(!1);X(()=>{_.current=!1},[s,S]),X(()=>{if(a||!g||!n||!s||!p||!u)return;let x=B(u);return $(p,u,{fireGoal:()=>{_.current||(_.current=!0,n.track({projectId:r,componentId:e,variantId:s,eventType:"goal_achieved",goalType:l,payload:v({reward:1},x!==void 0?{goalValue:x}:{})}),n.goal(l,v({metadata:{componentId:e,variantId:s},weight:1,stepIndex:0},x!==void 0?{value:x}:{})))},fireStep:(h,G,P)=>{n.track({projectId:r,componentId:e,variantId:s,eventType:"goal_achieved",goalType:h,payload:{reward:G}}),n.goal(h,{metadata:{},weight:G,stepIndex:P})}},l)},[n,p,s,r,e,u,l,a,g]),X(()=>{if(a||!n||!s||!p)return;let x=Date.now();return Zn((h,G={})=>{n.track({projectId:r,componentId:e,variantId:s,eventType:"micro_signal",payload:v({signalType:h},G)})},p,x)},[n,p,s,r,e,a]),X(()=>{if(!R()||!n)return;let x=setTimeout(()=>{!C.current&&!$t.has(e)&&($t.add(e),console.warn(`[sentient] useAdaptive("${e}"): bind was never attached \u2014 spread {...bind} on the rendered element, otherwise exposure and goal tracking cannot work and the optimizer learns nothing.`))},0);return()=>clearTimeout(x)},[n,e]);let A=Bt((x,h)=>{var P,D;if(a)return;let G=x!=null?x:l;G&&(n==null||n.componentGoal(e,G,h),n==null||n.goal(G,v(v(v({metadata:(P=h==null?void 0:h.metadata)!=null?P:{},weight:(D=h==null?void 0:h.reward)!=null?D:1,stepIndex:0},(h==null?void 0:h.value)!==void 0?{value:h.value}:{}),(h==null?void 0:h.currency)!==void 0?{currency:h.currency}:{}),(h==null?void 0:h.externalId)!==void 0?{externalId:h.externalId}:{})))},[n,e,l,a]),k=$e(()=>({ref:w,"data-sentient-id":e,"data-sentient-variant":s}),[w,e,s]);return{variant:s,value:d,bind:k,fireGoal:A}}import{Children as Qn,isValidElement as er,useEffect as ye,useMemo as Mt,useRef as Nt}from"react";import{jsx as nr}from"react/jsx-runtime";var Se=new Set;function tr(e){var l;let t=E(),n=M(),r=Nt(null),i=Object.keys(e.arrangements).join(" "),o=Mt(()=>Object.keys(e.arrangements),[i]),c=Mt(()=>v({id:e.id,arms:o},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,o,e.baseline]),{arm:a,source:g}=me(e.id,c);R()&&e.baseline!==void 0&&e.baseline!==o[0]&&!Se.has(e.id+":baseline")&&(Se.add(e.id+":baseline"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: baseline "${e.baseline}" is not the first-declared arrangement ("${o[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let s=Qn.toArray(e.children).filter(er),d=new Map;for(let f of s)d.set(String((l=f.key)!=null?l:"").replace(/^\.\$/,""),f);let p=e.arrangements[a],m=p!==void 0&&p.length===s.length&&p.every(f=>d.has(f));R()&&p!==void 0&&!m&&!Se.has(e.id+":keys")&&(Se.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${a}" [${p.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let C=m?p.map(f=>d.get(f)):s;ye(()=>q({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let w=Nt(null);ye(()=>{!t||g==="baseline"||g==="override"||w.current===a||(w.current=a,K(t,n,e.id,a))},[t,n,e.id,a,g]);let S=e.funnel;ye(()=>{var f;!t||!S||g==="override"||W(t,n,e.id,S,I((f=e.goal)!=null?f:"click"))},[t,n,e.id,S,g]);let u=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return ye(()=>{if(!t||e.goal===void 0||g==="override"||g==="baseline")return;let f=r.current;if(!f)return;let y=V(e.goal),_=B(e.goal),A=!1;return $(f,I(e.goal),{fireGoal:()=>{A||(A=!0,_!==void 0?t.componentGoal(e.id,y,{value:_}):t.componentGoal(e.id,y),t.goal(y,v({metadata:{componentId:e.id,arm:a},weight:1,stepIndex:0},_!==void 0?{value:_}:{})))},fireStep:(k,b,x)=>{t.componentGoal(e.id,k,{reward:b}),t.goal(k,{metadata:{componentId:e.id,arm:a},weight:b,stepIndex:x})}},y)},[t,e.id,u,a,g]),nr("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":a,children:C})}import{deriveSessionSegment as rr}from"@sentientui/core";var ir=["page","blocks","layoutOrder"],Kt=new Map;function or(e,t){Kt.set(e,t)}function jt(e){return Kt.get(e)}function sr(e){var i,o;let t=(o=(i=e.content)!=null?i:jt(e.page))!=null?o:{},n={};for(let[c,a]of Object.entries(t))ir.includes(c)||(n[c]=a);let r=N(v({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(r.layoutOrder=e.layoutOrder),r}function ar(e){return`<script type="application/ld+json">${Vt(e)}</script>`}function Vt(e){return JSON.stringify(v({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function lr(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,r]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(r,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
3
3
  `).trimEnd()+`
4
- `}import{grantConsent as xo}from"@sentientui/core";export{rn as Adaptive,Wn as AdaptiveGroup,Ht as AdaptiveProvider,Bn as AdaptiveSlot,ln as AdaptiveText,yn as SentientPersonaScript,zn as buildAgentFeed,Xn as defineAgentContent,Jn as detectSegment,Lt as getAgentContent,xo as grantConsent,qn as renderAgentJsonLd,Dt as renderAgentJsonLdBody,Zn as renderAgentMarkdown,Nn as useAdaptive,zt as useAdaptiveApiBaseUrl,Re as useAdaptiveGoal,Cn as useAdaptivePersona,Gn as useAdaptiveTokens,Z as useAssignment,Ae as useInitialAssignments,Xt as useLayoutOrder,gn as usePageGoal,G as useSentient};
4
+ `}import{grantConsent as jo}from"@sentientui/core";export{pn as Adaptive,tr as AdaptiveGroup,on as AdaptiveProvider,Xn as AdaptiveSlot,hn as AdaptiveText,En as SentientPersonaScript,sr as buildAgentFeed,or as defineAgentContent,rr as detectSegment,jt as getAgentContent,jo as grantConsent,ar as renderAgentJsonLd,Vt as renderAgentJsonLdBody,lr as renderAgentMarkdown,te as renderBlocks,Yn as useAdaptive,an as useAdaptiveApiBaseUrl,Le as useAdaptiveGoal,Dn as useAdaptivePersona,Mn as useAdaptiveTokens,ee as useAssignment,Pe as useInitialAssignments,sn as useLayoutOrder,_n as usePageGoal,E as useSentient};
5
5
  //# sourceMappingURL=index.mjs.map