@sentientui/react 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -46
- package/dist/devtools.js +1 -1
- package/dist/devtools.js.map +1 -1
- package/dist/devtools.mjs +1 -1
- package/dist/devtools.mjs.map +1 -1
- package/dist/index.d.cts +76 -45
- package/dist/index.d.ts +76 -45
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/next/adaptive-root.d.ts +41 -5
- package/dist/next/adaptive-root.js +2 -2
- package/dist/next/adaptive-root.js.map +1 -1
- package/dist/server.d.cts +10 -2
- package/dist/server.d.ts +10 -2
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +1 -1
- package/dist/server.mjs.map +1 -1
- package/dist/testing/msw.d.cts +1 -1
- package/dist/testing/msw.d.ts +1 -1
- package/dist/testing/msw.js.map +1 -1
- package/dist/testing/msw.mjs.map +1 -1
- package/dist/testing/node.d.cts +1 -1
- package/dist/testing/node.d.ts +1 -1
- package/dist/testing/node.js.map +1 -1
- package/dist/testing/node.mjs.map +1 -1
- package/dist/testing/react.d.cts +1 -1
- package/dist/testing/react.d.ts +1 -1
- package/dist/testing/react.js +1 -1
- package/dist/testing/react.js.map +1 -1
- package/dist/testing/react.mjs +1 -1
- package/dist/testing/react.mjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs.map +1 -1
- package/llms.txt +5 -5
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
var Wt=Object.defineProperty,Ut=Object.defineProperties;var Jt=Object.getOwnPropertyDescriptors;var re=Object.getOwnPropertySymbols;var Ve=Object.prototype.hasOwnProperty,We=Object.prototype.propertyIsEnumerable;var je=(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={}))Ve.call(t,n)&&je(e,n,t[n]);if(re)for(var n of re(t))We.call(t,n)&&je(e,n,t[n]);return e},N=(e,t)=>Ut(e,Jt(t));var Ue=(e,t)=>{var n={};for(var r in e)Ve.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&re)for(var r of re(e))t.indexOf(r)<0&&We.call(e,r)&&(n[r]=e[r]);return n};import{createContext as Yt,useContext as L,useEffect as j,useMemo as ut,useRef as Oe,useState as ae,useSyncExternalStore as Qt}from"react";import{deriveSessionSegment as en,init as tn}from"@sentientui/core";var Je=new Map,ie=new Map;function ze(e,t){let n=ie.get(e);return n||(n=new Set,ie.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&ie.delete(e)}}function Xe(e,t){Je.set(e,t);let n=ie.get(e);if(n)for(let r of n)try{r(t)}catch(i){}}function he(e){var t;return(t=Je.get(e))!=null?t:null}var zt={on:!1,listeners:new Set};function He(){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 He().on}function qe(e){let t=He().listeners;return t.add(e),()=>{t.delete(e)}}function Ze(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 Ye(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function Qe(){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 et(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 tt(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 nt(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,u=[];return t.steps.forEach(({goal:p,name:m,weight:x},w)=>{let h=(d=!1)=>{s.has(w)||d&&r!==void 0&&tt(`step\0${m}\0${x}\0${w}`)||(s.add(w),n.fireStep(m,x,w))};if(p.type==="click"){let d=l=>{let f=l.target;f instanceof Element&&nt(f,e,p.selector)&&h()};e.addEventListener("click",d),u.push(()=>e.removeEventListener("click",d));return}if(p.type==="form_submit"){let d=l=>{l.target instanceof HTMLFormElement&&e.contains(l.target)&&h()};e.addEventListener("submit",d),u.push(()=>e.removeEventListener("submit",d));return}if(p.type==="scroll_depth"){let d=Math.max(0,Math.min(1,p.threshold)),l=new IntersectionObserver(f=>{for(let y of f)if(y.intersectionRatio>=d){h(!0),l.disconnect();break}},{threshold:[d]});l.observe(e),u.push(()=>l.disconnect())}}),()=>{for(let p of u)p()}}let i=t.type==="composite"?t.all:[t],o=new Set(i.map((s,u)=>u)),c=()=>{r!==void 0&&tt(r)||n.fireGoal()},a=(s,u=!1)=>{o.delete(s),o.size===0&&(u?c():n.fireGoal())},g=[];return i.forEach((s,u)=>{if(s.type==="click"){let p=m=>{let x=m.target;x instanceof Element&&nt(x,e,s.selector)&&(t.type==="composite"?a(u):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(u):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(x=>{for(let w of x)if(w.intersectionRatio>=p){t.type==="composite"?a(u,!0):c(),m.disconnect();break}},{threshold:[p]});m.observe(e),g.push(()=>m.disconnect());return}}),()=>{for(let s of g)s()}}var rt=new Set,it=new Set;function W(e,t,n,r,i){let o=`${r}|${n}`;if(it.has(o))return;it.add(o);let c=i.type==="weighted_composite"&&!rt.has(r);c&&rt.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 H(){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(){H().version+=1;for(let e of H().listeners)e()}var ot=()=>{};function oe(e){return R()?(H().components.set(e.id,e),Q(),()=>{H().components.delete(e.id),Q()}):ot}function Z(e){return R()?(H().slots.set(e.id,e),Q(),()=>{H().slots.delete(e.id),Q()}):ot}function Ae(e){R()&&(H().sections=[...e],Q())}var st="0.32.0",_e=st!=="0.0.0-dev"?{name:"react",version:st}: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 at="sentient_editor",lt="sentient_preview_cell",Ge="sentient-cell-preview-bar",Ee="__preview__";function ct(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(at),n=a.get(lt)}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){se(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{se("Nothing to preview in that square yet.");return}Qe(),se(`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(u){}},300)}).catch(()=>se("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function se(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(at),o.searchParams.delete(lt),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 dt="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:dt,debug:!1});function rn(e){let[t,n]=ae(!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 u=r.current;if(!u)return!1;if(u.check)return u.check()===!0;if(!u.cookie||typeof document=="undefined")return!1;let p=`${u.cookie}=${(m=u.value)!=null?m:"accepted"}`;return document.cookie.split("; ").some(x=>x.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,h;let[t,n]=ae(null),[r]=ae(()=>{var d;return(d=e.sessionSegment)!=null?d:nn()}),[i,o]=ae(be());j(()=>qe(()=>o(be())),[]),j(()=>{ct(e.apiBaseUrl)},[]);let c=rn(e.consentFrom),a=e.consentFrom?e.consent===!0||c:e.consent,g=Oe(null);j(()=>{var _;if(a===!1&&!e.preConsentBehavior){(_=g.current)==null||_.destroy(),g.current=null,n(null);return}let d=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},_e?{sdk:_e}:{}),l=!1,f=null,y=null,A=k=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:C})=>{l||(y=C(k,{apiKey:e.apiKey,sectionTypes:e.sectionTypes,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:k})=>{l||(f=k(N(v({},d),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),g.current=f,n(f),A(f))}):(f=tn(d),g.current=f,n(f),A(f)),()=>{l=!0,y==null||y(),f==null||f.dispose()}},[a]),j(()=>{if(!t)return;let d=!1,l=async()=>{if(d)return;let y;try{y=await t.fetchWeights()}catch(A){return}if(!d)for(let A of y){let _={componentId:A.componentId,updatedAt:A.updatedAt,variants:A.variants.map(k=>{var C;return{variantId:k.variantId,pulls:k.pulls,avgReward:(C=k.avgReward)!=null?C:0}})};Xe(A.componentId,_)}};l();let f=setInterval(()=>{l()},6e4);return()=>{d=!0,clearInterval(f)}},[t]);let s=(w=e.ssrFallback)!=null?w:"first",u=((h=e.apiBaseUrl)!=null?h:dt).replace(/\/$/,""),p=Oe(null);j(()=>{var f;if(typeof process!="undefined"&&((f=process.env)==null?void 0:f.NODE_ENV)==="production")return;let d={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:u},l=p.current;if(p.current=d,l!==null)for(let y of["apiKey","context","country","persona","apiBaseUrl"])Object.is(l[y],d[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,u]),j(()=>{var d;typeof process!="undefined"&&((d=process.env)==null?void 0:d.NODE_ENV)==="production"||et({apiKey:e.apiKey,apiBaseUrl:u,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,u]),j(()=>{let d=e.initialLayoutOrder;if(d&&d.length>0){Ae(d);return}e.declaredSections&&e.declaredSections.length>0&&Ae(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),j(()=>{if(!R())return;let d=e.declaredSections;if(!d||d.length===0||typeof document=="undefined")return;let l=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),y=>y.getAttribute("data-sentient-id"))),f=d.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>" to each section's element.`)},[e.declaredSections]);let m=ut(()=>t&&i?Ze(t):t,[t,i]),x=ut(()=>{var d,l,f,y,A,_,k;return{client:m,apiKey:e.apiKey,initialAssignments:(d=e.initialAssignments)!=null?d:{},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:(A=e.initialPalette)!=null?A:null,initialPersona:(_=e.initialPersona)!=null?_:null,apiBaseUrl:u,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,u,e.debug]);return ln(T.Provider,{value:x,children:e.children})}function E(){return L(T).client}function M(){return L(T).apiKey}function Pe(){return L(T).initialAssignments}function le(){return L(T).sessionSegment}function ft(){return L(T).ssrFallback}function ce(){return L(T).onAssignment}function gt(){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 ue(){return L(T).initialSlots}function mt(){return L(T).initialPersona}function pt(){return L(T).initialSlotConfig}function vt(){return L(T).initialPalette}function an(){return L(T).apiBaseUrl}import{memo as dn,useEffect as U,useMemo as St,useRef as fe,useState as fn}from"react";import{attachMicroSignalDetectors as gn}from"@sentientui/core";import{useEffect as de,useRef as yt,useState as cn,useSyncExternalStore as un}from"react";import{pickFromWeights as Ie}from"@sentientui/policy";function Y(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=ft(),c=E(),a=le(),g=ce(),s=gt(),u=yt(null),p=un(F,()=>Y(e),()=>null),m=p&&t.includes(p)?p:null,x=yt(null);de(()=>{s&&m&&x.current!==m&&(x.current=m,console.info(`[sentient] override active: ${e} -> ${m}`))},[s,m,e]);let[w,h]=cn(()=>{var y,A;if(m)return{variantId:m,content:null,isLoading:!1,settled:!0};if(!c){let _=i[e];return _&&t.includes(_)?{variantId:_,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 _=Ie(f.variants,t);if(_)return{variantId:_,content:null,isLoading:!1,settled:!0}}return{variantId:(A=t[0])!=null?A:null,content:null,isLoading:!1,settled:!1}}),d=l=>{g&&u.current!==l&&(u.current=l,g(e,l))};return de(()=>{var y;if(m||!c)return;let l=c.getAssignment(e,a);if(l&&(t.includes(l.variantId)||l.content)){h({variantId:l.variantId,content:(y=l.content)!=null?y:null,isLoading:!1,settled:!0}),d(l.variantId);return}let f=he(e);if(f&&w.settled&&w.variantId&&w.variantId===Ie(f.variants,t)){d(w.variantId);return}h(A=>{var _;return A.variantId?A:{variantId:(_=t[0])!=null?_:null,content:null,isLoading:!1,settled:!1}})},[m,c,e,a]),de(()=>{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 A;f||y&&(!t.includes(y.variantId)&&!y.content||(h({variantId:y.variantId,content:(A=y.content)!=null?A:null,isLoading:!1,settled:!0}),d(y.variantId)))}),()=>{f=!0}},[m,c,e,a]),de(()=>{if(!m&&c)return ze(e,l=>{var A;let f=c.getAssignment(e,a);if(f&&(t.includes(f.variantId)||f.content)){h({variantId:f.variantId,content:(A=f.content)!=null?A:null,isLoading:!1,settled:!0}),d(f.variantId);return}let y=Ie(l.variants,t);y&&(h({variantId:y,content:null,isLoading:!1,settled:!0}),d(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 A;let t=E(),n=M(),r=Object.keys(e.variants).join("\0"),i=St(()=>Object.keys(e.variants),[r]),{variantId:o,content:c,isOverride:a,settled:g}=ee(e.id,i,e.agentData,e.agentDataByVariant),s=fe(null),[u,p]=fn(!1);U(()=>{p(!0)},[]);let m=fe(!1),x=fe(new Set),w=fe(null),h=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),d=St(()=>I(e.goal),[h]),l=typeof e.goal=="string"?e.goal:d.type;if(U(()=>oe({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,x.current=new Set},[o,d]),U(()=>{a||!g||!t||!e.funnel||W(t,n,e.id,e.funnel,d)},[t,n,e.id,e.funnel,d,a,g]),U(()=>{if(a||!g||!t||!o)return;let _=s.current;if(!_)return;let k=null,C=0,b=()=>{C=Date.now(),k=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:o,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-C}}),k=null},800)},S=()=>{k!==null&&(clearTimeout(k),k=null)};return _.addEventListener("mouseenter",b),_.addEventListener("mouseleave",S),()=>{_.removeEventListener("mouseenter",b),_.removeEventListener("mouseleave",S),k!==null&&clearTimeout(k)}},[t,o,n,e.id,a,g]),U(()=>{if(a||!g||!t||!o)return;let _=s.current;if(!_)return;let k=Date.now();return gn((C,b={})=>{var z,X,Ke;t.track({projectId:n,componentId:e.id,variantId:o,eventType:"micro_signal",payload:v({signalType:C},b)});let S=(z=e.microSignalGoals)==null?void 0:z[C];if(!S||x.current.has(C))return;x.current.add(C);let G=typeof S=="string"?S:S.name,P=typeof S=="string"?1:(X=S.weight)!=null?X:1,D=typeof S=="string"?0:(Ke=S.stepIndex)!=null?Ke:0;t.goal(G,{metadata:v({signalType:C},b),weight:P,stepIndex:D})},_,k)},[t,o,n,e.id,e.microSignalGoals,a,g]),U(()=>{if(a||!g||!t||!o)return;let _=s.current;if(!_)return;let k=B(d);return $(_,d,{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:(C,b,S)=>{t.track({projectId:n,componentId:e.id,variantId:o,eventType:"goal_achieved",goalType:C,payload:{reward:b}}),t.goal(C,{metadata:{},weight:b,stepIndex:S})}},l)},[t,o,n,e.id,d,l,a,g]),e.clientOnly&&(!u||!t)||!o)return null;let f=(A=e.variants[o])!=null?A: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 ge,useMemo as yn,useRef as Te,useState as ht,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=ce(),g=le(),s=Te(null),u=Te(null),p=Sn(F,()=>Y(e),()=>null),[m,x]=ht(()=>{var C,b;return(b=(C=o==null?void 0:o.getAssignment(e,g))==null?void 0:C.content)!=null?b:null}),[w,h]=ht(()=>{var C,b;return(b=(C=o==null?void 0:o.getAssignment(e,g))==null?void 0:C.variantId)!=null?b:null});ge(()=>{if(p||!o)return;let C=o.getAssignment(e,g);if((C==null?void 0:C.content)!==void 0){h(C.variantId),x(C.content);return}let b=!1;return o.assign(e).then(S=>{if(!b){if(!S){R()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}h(S.variantId),S.content&&x(S.content)}}),()=>{b=!0}},[o,e,g,p]),ge(()=>{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 d=i===void 0?"":typeof i=="string"?i:JSON.stringify(i),l=yn(()=>i===void 0?null:I(i),[d]),f=i===void 0?null:typeof i=="string"?i:l.type,y=Te(!1);ge(()=>{y.current=!1},[w,d]),ge(()=>{if(p||!o||!w||!c||!l||!f)return;let C=u.current;if(!C)return;let b=B(l);return $(C,l,{fireGoal:()=>{y.current||(y.current=!0,o.track({projectId:c,componentId:e,variantId:w,eventType:"goal_achieved",goalType:f,payload:v({reward:1},b!==void 0?{goalValue:b}:{})}),o.goal(f,v({metadata:{componentId:e,variantId:w},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(S,G,P)=>{o.track({projectId:c,componentId:e,variantId:w,eventType:"goal_achieved",goalType:S,payload:{reward:G}}),o.goal(S,{metadata:{},weight:G,stepIndex:P})}})},[o,w,c,e,l,f,p]);let A=m!=null?m:t;if(p){let C=o==null?void 0:o.getAssignment(e,g);A=C&&C.variantId===p&&(k=C.content)!=null?k:t}return bn(n,{ref:C=>{u.current=C},className:r,children:A})}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(!Y(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 bt}from"react";function An(e,t={}){let g=t,{componentId:n}=g,r=Ue(g,["componentId"]),i=E(),o=Le(n!=null?n:""),c=bt(!1),a=bt(r);a.current=r,Cn(()=>{if(!i||c.current)return;c.current=!0;let{metadata:s,reward:u,value:p,currency:m,externalId:x}=a.current;if(n){o(e,a.current);return}i.goal(e,v(v(v({metadata:s!=null?s:{},weight:u!=null?u:1,stepIndex:0},p!==void 0?{value:p}:{}),m!==void 0?{currency:m}:{}),x!==void 0?{externalId:x}:{}))},[i,n,e,o])}import{renderPrePaintScript as _n}from"@sentientui/core";import{confidenceBand as kn}from"@sentientui/policy";import{jsx as Gn}from"react/jsx-runtime";function wt(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",'+wt(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+wt(kn(e.persona.confidence))+");}catch(e){}})();":_n(e.apiKey)}function En(e){return Gn("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Rn(e)}})}import{useEffect as ve,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 Ct}from"react";import{armOfResult as me,baselineResultFor as In}from"@sentientui/core";import{confidenceBand as Tn}from"@sentientui/policy";var xt=new Set;function pe(e,t){let n=E(),r=ue(),[,i]=On(u=>u+1,0),o=Ct(F,()=>{var u;return typeof window!="undefined"?(u=window.__sentient_slot_overrides)==null?void 0:u[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 u=!1;return n.decide({slots:[t]}).then(p=>{!u&&p&&i()}),()=>{u=!0}},[n,e,g]);let s=(()=>{if(o!==void 0)return{result:o,arm:me(o),source:"override"};if(c!==void 0)return{result:c,arm:me(c),source:"preloaded"};if(a!==null)return{result:a,arm:me(a),source:"client"};let u=In(t);return{result:u,arm:me(u),source:"baseline"}})();return De(()=>{R()&&(!n||n.isLocal===!0||s.source==="baseline"&&(xt.has(e)||(xt.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=mt();Ct(F,Ye,()=>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 At=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}=pe(e,c),u=Fe(()=>typeof a=="string"?{}:a,[g]);if(R()&&!At.has(e)){At.add(e);let h=Bn({id:e,dims:Object.fromEntries(Object.entries(t).map(([l,f])=>[l,[...f]]))}),d=Object.values(t).reduce((l,f)=>l*f.length,1);h.ok?d>4&&console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${d} 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 ${h.reason}. Serving baseline.`)}let p=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);ve(()=>Z({id:e,dims:t}),[e]);let m=Fn(null);ve(()=>{!r||s==="baseline"||s==="override"||m.current===g||(m.current=g,K(r,i,e,g))},[r,i,e,g,s]);let x=n==null?void 0:n.funnel;ve(()=>{var h;!r||!x||s==="override"||W(r,i,e,x,I((h=n==null?void 0:n.goal)!=null?h:"click"))},[r,i,e,x,p,s]),ve(()=>{if(!r||!(n!=null&&n.goal)||s==="override"||s==="baseline")return;let h=document.querySelector(`[data-sentient-slot="${$n(e)}"]`);if(!h){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 d=V(n.goal),l=B(n.goal),f=!1;return $(h,I(n.goal),{fireGoal:()=>{f||(f=!0,l!==void 0?r.componentGoal(e,d,{value:l}):r.componentGoal(e,d),r.goal(d,v({metadata:{componentId:e,arm:g},weight:1,stepIndex:0},l!==void 0?{value:l}:{})))},fireStep:(y,A,_)=>{r.componentGoal(e,y,{reward:A}),r.goal(y,{metadata:{componentId:e,arm:g},weight:A,stepIndex:_})}},d)},[r,e,p,g,s]);let w=Fe(()=>{let h={"data-sentient-slot":e};for(let[d,l]of Object.entries(u))h[`data-${d}`]=l;return h},[e,u]);return{tokens:u,props:w}}import{useEffect as ne,useMemo as Jn,useRef as $e}from"react";import{containsFormBlock as zn,reveal as Xn}from"@sentientui/core";import{useEffect as _t,useRef as Nn,useSyncExternalStore as kt}from"react";import{armOfResult as Kn}from"@sentientui/core";var Rt=new Set;function Et(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=ue(),o=pt(),c=vt(),a=kt(F,()=>{var h;return typeof window!="undefined"?(h=window.__sentient_slot_config_overrides)==null?void 0:h[e]:void 0},()=>{}),g=kt(F,()=>{var h;return typeof window!="undefined"?(h=window.__sentient_slot_overrides)==null?void 0:h[e]:void 0},()=>{}),s=a===void 0?o[e]:void 0,u=a===void 0&&s===void 0&&n?n.getSlotConfig(e):null,p=h=>h==null?"":Kn(h),m=(w=c!=null?c:n==null?void 0:n.getSitePalette())!=null?w:null,x=(()=>{var h,d;return a!==void 0?{config:a,arm:p(g),palette:m,source:"override"}:s!==void 0?{config:s,arm:p((h=i[e])!=null?h:n==null?void 0:n.getSlotResult(e)),palette:m,source:"preloaded"}:u!==null?{config:u,arm:p((d=n==null?void 0:n.getSlotResult(e))!=null?d:i[e]),palette:m,source:"client"}:{config:null,arm:"",palette:m,source:"none"}})();return _t(()=>{var d,l;if(!n||n.isLocal===!0||x.source!=="none")return;let h=(l=(d=r.current)==null?void 0:d.call(r))!=null?l:null;h!=null&&h!==""?n.reportSlots([e],{[e]:h}):n.reportSlots([e])},[n,x.source,e]),_t(()=>{if(R()&&n&&x.source==="none"&&!Rt.has(e)){if(Rt.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,x.source,e]),x}import{Fragment as Gt}from"react";import{jsx as O,jsxs as Tt}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"},Lt={sm:"0.875em",md:"1em",lg:"1.25em"},jn={sm:"1.25em",md:"1.5em",lg:"2em"},Ot={sm:"6px 14px",md:"10px 20px",lg:"14px 28px"},Pt={sm:"8px",md:"16px",lg:"32px"},Vn={square:"1 / 1",landscape:"4 / 3",wide:"16 / 9"},Wn={normal:"400",medium:"500",bold:"700"};function It(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 Dt(e,t,n){var i,o,c,a;let r=t==null?void 0:t.accent;return N(v({display:"inline-block",padding:(i=Ot[n!=null?n:"md"])!=null?i:Ot.md,borderRadius:(o=t==null?void 0:t.radius)!=null?o:"8px",font:"inherit"},n?{fontSize:Lt[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 Tt("form",{onSubmit:s=>{var m,x,w;s.preventDefault();let u=new FormData(s.currentTarget),p={};for(let h of e.fields)p[h.name]=String((m=u.get(h.name))!=null?m:"");(x=t.onFormGoal)==null||x.call(t,e.submitGoal);try{(w=t.onFormSubmit)==null||w.call(t,p)}catch(h){}},style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e.fields.map(s=>{var u,p;return Tt("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:((u=s.options)!=null?u:[]).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:Dt(n,t.palette),children:e.submitLabel})]})}function te(e,t){var n,r,i,o,c,a,g,s,u,p,m,x,w,h,d,l,f,y,A,_,k,C,b;try{switch(e.type){case"stack":{let S=(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:S},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 ${(u=(s=t.palette)==null?void 0:s.border)!=null?u:"currentColor"}`,borderRadius:(m=(p=t.palette)==null?void 0:p.radius)!=null?m:"8px"}):{}),children:((x=e.children)!=null?x:[]).map((D,z)=>{let X=te(D,t);return X===null?null:O(Gt,{children:X},z)})})}case"grid":{let S=(h=J[(w=e.gap)!=null?w:"md"])!=null?h:J.md;return O("div",{style:v(v({display:"grid",gridTemplateColumns:`repeat(auto-fit, minmax(max(200px, calc((100% - ${e.columns-1} * ${S}) / ${e.columns})), 1fr))`,gap:S},e.align?{alignItems:Be[e.align]}:{}),e.pad?{padding:(d=J[e.pad])!=null?d:J.md}:{}),children:((l=e.children)!=null?l:[]).map((G,P)=>{let D=te(G,t);return D===null?null:O(Gt,{children:D},P)})})}case"text":return O("p",{style:v(v(v(v(v({margin:0},e.size?{fontSize:Lt[e.size]}:{}),e.weight?{fontWeight:Wn[e.weight]}:{}),e.align?{textAlign:e.align}:{}),e.maxWidth==="measure"?{maxWidth:"65ch"}:{}),It(e.tone,t.palette)),children:e.value});case"heading":{let S=`h${e.level}`;return O(S,{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 S=(y=e.emphasis)!=null?y:"primary";return O("a",N(v({href:e.href},e.tag?{"data-sentient-tag":e.tag}:{}),{style:Dt(S,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:A.border)!=null?_:"currentColor"}`},It(e.tone,t.palette)),children:e.value});case"spacer":return O("div",{style:{height:(k=Pt[e.size])!=null?k:Pt.md}});case"divider":return O("hr",{style:{border:"none",borderTop:`1px solid ${(b=(C=t.palette)==null?void 0:C.border)!=null?b:"currentColor"}`,margin:0,width:"100%"}});case"form":return O(Un,{node:e,opts:t});default:return null}}catch(S){return null}}import{jsx as qn}from"react/jsx-runtime";var Ft=new Set;function Hn({id:e,children:t,onFormSubmit:n,goal:r,className:i,reportBaselineText:o=!0}){var C;let c=E(),a=M(),g=$e(null),{config:s,arm:u,palette:p,source:m}=Et(e,{baselineText:o?()=>{var b,S;return(S=(b=g.current)==null?void 0:b.textContent)!=null?S:null}:void 0}),x=u!==""?(C=s==null?void 0:s.blocks)==null?void 0:C[u]:void 0,w=x!==void 0&&zn(x)&&!n;ne(()=>{!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 h=b=>{!c||m==="override"||(c.componentGoal(e,b),c.goal(b,{metadata:{componentId:e,arm:u},weight:1,stepIndex:0}))},d=t,l=!1;if(x!==void 0){let b=w?null:te(x,{palette:p,onFormSubmit:n,onFormGoal:h});b===null?l=!0:d=b}else(s==null?void 0:s.content)!==void 0&&m!=="none"&&(d=s.content);let f=s!=null&&s.blocks?Object.keys(s.blocks).sort().join("|"):"";ne(()=>Z({id:e,arms:f===""?void 0:f.split("|")}),[e,f]);let y=$e(null);ne(()=>{!c||m==="none"||m==="override"||u===""||l||y.current!==u&&(y.current=u,K(c,a,e,u))},[c,a,e,u,m,l]);let A=r===void 0?null:typeof r=="string"?r:JSON.stringify(r);ne(()=>{if(!c||!r||m==="override"||m==="none"||l)return;let b=g.current;if(!b)return;let S=V(r),G=B(r),P=!1;return $(b,I(r),{fireGoal:()=>{P||(P=!0,G!==void 0?c.componentGoal(e,S,{value:G}):c.componentGoal(e,S),c.goal(S,v({metadata:{componentId:e,arm:u},weight:1,stepIndex:0},G!==void 0?{value:G}:{})))},fireStep:(D,z,X)=>{c.componentGoal(e,D,{reward:z}),c.goal(D,{metadata:{componentId:e,arm:u},weight:z,stepIndex:X})}},S)},[c,e,A,u,m,l]);let _=$e(null);ne(()=>{let b=g.current;if(b){if(_.current===null){_.current=u;return}_.current!==u&&(_.current=u,Xn(b))}},[u]);let k=Jn(()=>v({"data-sentient-slot":e},u!==""?{"data-sentient-arm":u}:{}),[e,u]);return qn("div",N(v({ref:g,className:i},k),{children:d}))}import{useCallback as Bt,useEffect as q,useMemo as Me,useRef as Ne,useState as Zn}from"react";import{attachMicroSignalDetectors as Yn}from"@sentientui/core";var $t=new Set;function Qn(e,t){var C;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=Me(()=>Object.keys(t.variants),[i]),{variantId:c,isOverride:a,settled:g}=ee(e,o),s=(C=c!=null?c:o[0])!=null?C:"",u=t.variants[s],[p,m]=Zn(null),x=Ne(null),w=Bt(b=>{x.current=b,m(b)},[]),h=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),d=Me(()=>t.goal?I(t.goal):null,[h]),l=t.goal?V(t.goal):"";q(()=>oe({id:e,variantIds:o,goal:l}),[e,o,l]);let f=Ne(null);q(()=>{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;q(()=>{a||!g||!n||!y||!d||W(n,r,e,y,d)},[n,r,e,y,d,a,g]);let A=Ne(!1);q(()=>{A.current=!1},[s,h]),q(()=>{if(a||!g||!n||!s||!p||!d)return;let b=B(d);return $(p,d,{fireGoal:()=>{A.current||(A.current=!0,n.track({projectId:r,componentId:e,variantId:s,eventType:"goal_achieved",goalType:l,payload:v({reward:1},b!==void 0?{goalValue:b}:{})}),n.goal(l,v({metadata:{componentId:e,variantId:s},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(S,G,P)=>{n.track({projectId:r,componentId:e,variantId:s,eventType:"goal_achieved",goalType:S,payload:{reward:G}}),n.goal(S,{metadata:{},weight:G,stepIndex:P})}},l)},[n,p,s,r,e,d,l,a,g]),q(()=>{if(a||!n||!s||!p)return;let b=Date.now();return Yn((S,G={})=>{n.track({projectId:r,componentId:e,variantId:s,eventType:"micro_signal",payload:v({signalType:S},G)})},p,b)},[n,p,s,r,e,a]),q(()=>{if(!R()||!n)return;let b=setTimeout(()=>{!x.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(b)},[n,e]);let _=Bt((b,S)=>{var P,D;if(a)return;let G=b!=null?b:l;G&&(n==null||n.componentGoal(e,G,S),n==null||n.goal(G,v(v(v({metadata:(P=S==null?void 0:S.metadata)!=null?P:{},weight:(D=S==null?void 0:S.reward)!=null?D: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}:{})))},[n,e,l,a]),k=Me(()=>({ref:w,"data-sentient-id":e,"data-sentient-variant":s}),[w,e,s]);return{variant:s,value:u,bind:k,fireGoal:_}}import{Children as er,isValidElement as tr,useEffect as ye,useMemo as Mt,useRef as Nt}from"react";import{jsx as rr}from"react/jsx-runtime";var Se=new Set;function nr(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}=pe(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=er.toArray(e.children).filter(tr),u=new Map;for(let f of s)u.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=>u.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 x=m?p.map(f=>u.get(f)):s;ye(()=>Z({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 h=e.funnel;ye(()=>{var f;!t||!h||g==="override"||W(t,n,e.id,h,I((f=e.goal)!=null?f:"click"))},[t,n,e.id,h,g]);let d=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),A=B(e.goal),_=!1;return $(f,I(e.goal),{fireGoal:()=>{_||(_=!0,A!==void 0?t.componentGoal(e.id,y,{value:A}):t.componentGoal(e.id,y),t.goal(y,v({metadata:{componentId:e.id,arm:a},weight:1,stepIndex:0},A!==void 0?{value:A}:{})))},fireStep:(k,C,b)=>{t.componentGoal(e.id,k,{reward:C}),t.goal(k,{metadata:{componentId:e.id,arm:a},weight:C,stepIndex:b})}},y)},[t,e.id,d,a,g]),rr("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":a,children:x})}import{deriveSessionSegment as ir}from"@sentientui/core";var or=["page","blocks","layoutOrder"],Kt=new Map;function sr(e,t){Kt.set(e,t)}function jt(e){return Kt.get(e)}function ar(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))or.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 lr(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 cr(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(`
|
|
2
|
+
var Jt=Object.defineProperty,Xt=Object.defineProperties;var Ht=Object.getOwnPropertyDescriptors;var ne=Object.getOwnPropertySymbols;var Ue=Object.prototype.hasOwnProperty,Je=Object.prototype.propertyIsEnumerable;var We=(e,t,n)=>t in e?Jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,S=(e,t)=>{for(var n in t||(t={}))Ue.call(t,n)&&We(e,n,t[n]);if(ne)for(var n of ne(t))Je.call(t,n)&&We(e,n,t[n]);return e},M=(e,t)=>Xt(e,Ht(t));var Xe=(e,t)=>{var n={};for(var r in e)Ue.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&&Je.call(e,r)&&(n[r]=e[r]);return n};import{createContext as en,useContext as I,useEffect as j,useMemo as gt,useRef as Oe,useState as oe,useSyncExternalStore as tn}from"react";import{deriveSessionSegment as nn,init as rn}from"@sentientui/core";var He=new Map,re=new Map;function ze(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 qe(e,t){He.set(e,t);let n=re.get(e);if(n)for(let r of n)try{r(t)}catch(i){}}function Se(e){var t;return(t=He.get(e))!=null?t:null}var zt={on:!1,listeners:new Set};function Ze(){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 he(){return Ze().on}function Ye(e){let t=Ze().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 be="sentient:overrides-changed";function et(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function tt(){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(be))}function F(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(be,e),()=>window.removeEventListener(be,e))}function nt(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function G(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function B(e){return typeof e=="string"?{type:"click"}:e}function K(e){return typeof e=="string"?e:e.type}function $(e){if(typeof e!="string"&&(e.type==="click"||e.type==="form_submit"||e.type==="scroll_depth"))return e.value}var xe=new Set,we=!1;function rt(e){if(xe.has(e))return!0;if(xe.add(e),!we){we=!0;let t=()=>{we=!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 qt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function it(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(qt(r))return!0;r=r.parentElement}return!1}function V(e,t,n,r){if(t.type==="weighted_composite"){let o=new Set,d=[];return t.steps.forEach(({goal:u,name:g,weight:b},h)=>{let v=(p=!1)=>{o.has(h)||p&&r!==void 0&&rt(`step\0${g}\0${b}\0${h}`)||(o.add(h),n.fireStep(g,b,h))};if(u.type==="click"){let p=a=>{let l=a.target;l instanceof Element&&it(l,e,u.selector)&&v()};e.addEventListener("click",p),d.push(()=>e.removeEventListener("click",p));return}if(u.type==="form_submit"){let p=a=>{a.target instanceof HTMLFormElement&&e.contains(a.target)&&v()};e.addEventListener("submit",p),d.push(()=>e.removeEventListener("submit",p));return}if(u.type==="scroll_depth"){let p=Math.max(0,Math.min(1,u.threshold)),a=new IntersectionObserver(l=>{for(let y of l)if(y.intersectionRatio>=p){v(!0),a.disconnect();break}},{threshold:[p]});a.observe(e),d.push(()=>a.disconnect())}}),()=>{for(let u of d)u()}}let i=t.type==="composite"?t.all:[t],f=new Set(i.map((o,d)=>d)),c=()=>{r!==void 0&&rt(r)||n.fireGoal()},s=(o,d=!1)=>{f.delete(o),f.size===0&&(d?c():n.fireGoal())},m=[];return i.forEach((o,d)=>{if(o.type==="click"){let u=g=>{let b=g.target;b instanceof Element&&it(b,e,o.selector)&&(t.type==="composite"?s(d):n.fireGoal())};e.addEventListener("click",u),m.push(()=>e.removeEventListener("click",u));return}if(o.type==="form_submit"){let u=g=>{g.target instanceof HTMLFormElement&&e.contains(g.target)&&(t.type==="composite"?s(d):n.fireGoal())};e.addEventListener("submit",u),m.push(()=>e.removeEventListener("submit",u));return}if(o.type==="scroll_depth"){let u=Math.max(0,Math.min(1,o.threshold)),g=new IntersectionObserver(b=>{for(let h of b)if(h.intersectionRatio>=u){t.type==="composite"?s(d,!0):c(),g.disconnect();break}},{threshold:[u]});g.observe(e),m.push(()=>g.disconnect());return}}),()=>{for(let o of m)o()}}var ot=new Set,st=new Set;function z(e,t,n,r,i){let f=`${r}|${n}`;if(st.has(f))return;st.add(f);let c=i.type==="weighted_composite"&&!ot.has(r);c&&ot.add(r),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:c?{funnelId:r,steps:i.steps.map(s=>({goalId:s.name,weight:s.weight}))}:{funnelId:r}})}function W(e,t,n,r){e.track({projectId:t,componentId:n,variantId:r,eventType:"variant_assigned",payload:{}})}var Zt={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function J(){if(typeof window=="undefined")return Zt;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 Y(){J().version+=1;for(let e of J().listeners)e()}var at=()=>{};function lt(e){return G()?(J().components.set(e.id,e),Y(),()=>{J().components.delete(e.id),Y()}):at}function q(e){return G()?(J().slots.set(e.id,e),Y(),()=>{J().slots.delete(e.id),Y()}):at}function Ce(e){G()&&(J().sections=[...e],Y())}var ct="0.34.0",Ae=ct!=="0.0.0-dev"?{name:"react",version:ct}:void 0;function Yt(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function _e(e,t){Yt()[e]=t}function Qt(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function Re(e,t){Qt()[e]=t}var ut="sentient_editor",dt="sentient_preview_cell",Ge="sentient-cell-preview-bar",ke="__preview__";function ft(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(Ge))return;let t,n;try{let s=new URLSearchParams(window.location.search);t=s.get(ut),n=s.get(dt)}catch(s){return}if(!t||!n)return;let r=n.lastIndexOf("~");if(r<=0)return;let i=n.slice(0,r),f=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(f)}`,{headers:{authorization:`Bearer ${t}`}}).then(async s=>{if(!s.ok){ie(s.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 m=await s.json();if(m.blocks!=null)_e(i,{kind:"arms",blocks:{[ke]:m.blocks}}),Re(i,ke);else if(m.content!=null)_e(i,{kind:"arms",content:m.content}),Re(i,ke);else{ie("Nothing to preview in that square yet.");return}tt(),ie(`Previewing \u201C${m.slotName}\u201D for ${m.personaDisplay}${m.status==="review"?" \u2014 waiting for your approval":""}. Nothing is being tracked.`),setTimeout(()=>{var o;try{(o=document.querySelector(`[data-sentient-slot="${i}"]`))==null||o.scrollIntoView({block:"center"})}catch(d){}},300)}).catch(()=>ie("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function ie(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 f=new URL(window.location.href);f.searchParams.delete(ut),f.searchParams.delete(dt),window.location.assign(f.toString())},t.append(n,r),((i=document.body)!=null?i:document.documentElement).append(t)}import{jsx as un}from"react/jsx-runtime";function on(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return nn({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var mt="https://api.sentient-ui.com/v1",L=en({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialPersona:null,apiBaseUrl:mt,debug:!1});function sn(e){let[t,n]=oe(!1),r=Oe(e);r.current=e;let{cookie:i,value:f,event:c}=e!=null?e:{},s=typeof(e==null?void 0:e.check)=="function";return j(()=>{let m=()=>{var g;let d=r.current;if(!d)return!1;if(d.check)return d.check()===!0;if(!d.cookie||typeof document=="undefined")return!1;let u=`${d.cookie}=${(g=d.value)!=null?g:"accepted"}`;return document.cookie.split("; ").some(b=>b.trim()===u)};if(n(m()),!c)return;let o=()=>{n(m())};return window.addEventListener(c,o),()=>window.removeEventListener(c,o)},[i,f,c,s]),t}function an(e){var h,v;let[t,n]=oe(null),[r]=oe(()=>{var p;return(p=e.sessionSegment)!=null?p:on()}),[i,f]=oe(he());j(()=>Ye(()=>f(he())),[]),j(()=>{ft(e.apiBaseUrl)},[]);let c=sn(e.consentFrom),s=e.consentFrom?e.consent===!0||c:e.consent,m=Oe(null);j(()=>{var w;if(s===!1&&!e.preConsentBehavior){(w=m.current)==null||w.destroy(),m.current=null,n(null);return}let p=S({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:r,consent:s,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}:{}),a=!1,l=null,y=null,x=k=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:C})=>{a||(y=C(k,{apiKey:e.apiKey,sectionTypes:e.sectionTypes,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:k})=>{a||(l=k(M(S({},p),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),m.current=l,n(l),x(l))}):(l=rn(p),m.current=l,n(l),x(l)),()=>{a=!0,y==null||y(),l==null||l.dispose()}},[s]),j(()=>{if(!t)return;let p=!1,a=async()=>{if(p)return;let y;try{y=await t.fetchWeights()}catch(x){return}if(!p)for(let x of y){let w={componentId:x.componentId,updatedAt:x.updatedAt,variants:x.variants.map(k=>{var C;return{variantId:k.variantId,pulls:k.pulls,avgReward:(C=k.avgReward)!=null?C:0}})};qe(x.componentId,w)}};a();let l=setInterval(()=>{a()},6e4);return()=>{p=!0,clearInterval(l)}},[t]);let o=(h=e.ssrFallback)!=null?h:"first",d=((v=e.apiBaseUrl)!=null?v:mt).replace(/\/$/,""),u=Oe(null);j(()=>{var l;if(typeof process!="undefined"&&((l=process.env)==null?void 0:l.NODE_ENV)==="production")return;let p={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:d},a=u.current;if(u.current=p,a!==null)for(let y of["apiKey","context","country","persona","apiBaseUrl"])Object.is(a[y],p[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 p;typeof process!="undefined"&&((p=process.env)==null?void 0:p.NODE_ENV)==="production"||nt({apiKey:e.apiKey,apiBaseUrl:d,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,d]),j(()=>{let p=e.initialLayoutOrder;if(p&&p.length>0){Ce(p);return}e.declaredSections&&e.declaredSections.length>0&&Ce(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),j(()=>{if(!G())return;let p=e.declaredSections;if(!p||p.length===0||typeof document=="undefined")return;let a=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),y=>y.getAttribute("data-sentient-id"))),l=p.filter(y=>!a.has(y));l.length>0&&console.warn(`[SentientUI] Declared section${l.length>1?"s":""} ${l.map(y=>`"${y}"`).join(", ")} ${l.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>" to each section's element.`)},[e.declaredSections]);let g=gt(()=>t&&i?Qe(t):t,[t,i]),b=gt(()=>{var p,a,l,y,x,w,k;return{client:g,apiKey:e.apiKey,initialAssignments:(p=e.initialAssignments)!=null?p:{},sessionSegment:r,ssrFallback:o,onAssignment:e.onAssignment,initialLayoutOrder:(a=e.initialLayoutOrder)!=null?a:null,initialSlots:(l=e.initialSlots)!=null?l:{},initialSlotConfig:(y=e.initialSlotConfig)!=null?y:{},initialPalette:(x=e.initialPalette)!=null?x:null,initialPersona:(w=e.initialPersona)!=null?w:null,apiBaseUrl:d,debug:(k=e.debug)!=null?k:!1}},[g,e.apiKey,e.initialAssignments,r,o,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialPersona,d,e.debug]);return un(L.Provider,{value:b,children:e.children})}function O(){return I(L).client}function N(){return I(L).apiKey}function Ee(){return I(L).initialAssignments}function se(){return I(L).sessionSegment}function pt(){return I(L).ssrFallback}function ae(){return I(L).onAssignment}function vt(){return I(L).debug}function ln(){let e=I(L).initialLayoutOrder,t=tn(F,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function le(){return I(L).initialSlots}function yt(){return I(L).initialPersona}function St(){return I(L).initialSlotConfig}function ht(){return I(L).initialPalette}function cn(){return I(L).apiBaseUrl}import{memo as kn,useEffect as Gn,useState as On}from"react";import{useCallback as gn,useEffect as X,useMemo as xt,useRef as Q,useState as mn}from"react";import{attachMicroSignalDetectors as pn}from"@sentientui/core";import{useEffect as ce,useRef as bt,useState as dn,useSyncExternalStore as fn}from"react";import{pickFromWeights as Pe}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 f=i.indexOf(":");if(f!==-1&&i.slice(0,f)===e)return i.slice(f+1)}}catch(r){}return null}function Te(e,t,n,r){let i=Ee(),f=pt(),c=O(),s=se(),m=ae(),o=vt(),d=bt(null),u=fn(F,()=>Z(e),()=>null),g=u&&t.includes(u)?u:null,b=bt(null);ce(()=>{o&&g&&b.current!==g&&(b.current=g,console.info(`[sentient] override active: ${e} -> ${g}`))},[o,g,e]);let[h,v]=dn(()=>{var y,x;if(g)return{variantId:g,content:null,isLoading:!1,settled:!0};if(!c){let w=i[e];return w&&t.includes(w)?{variantId:w,content:null,isLoading:!1,settled:!0}:f==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let a=c.getAssignment(e,s);if(a&&(t.includes(a.variantId)||a.content))return{variantId:a.variantId,content:(y=a.content)!=null?y:null,isLoading:!1,settled:!0};let l=Se(e);if(l){let w=Pe(l.variants,t);if(w)return{variantId:w,content:null,isLoading:!1,settled:!0}}return{variantId:(x=t[0])!=null?x:null,content:null,isLoading:!1,settled:!1}}),p=a=>{m&&d.current!==a&&(d.current=a,m(e,a))};return ce(()=>{var y;if(g||!c)return;let a=c.getAssignment(e,s);if(a&&(t.includes(a.variantId)||a.content)){v({variantId:a.variantId,content:(y=a.content)!=null?y:null,isLoading:!1,settled:!0}),p(a.variantId);return}let l=Se(e);if(l&&h.settled&&h.variantId&&h.variantId===Pe(l.variants,t)){p(h.variantId);return}v(x=>{var w;return x.variantId?x:{variantId:(w=t[0])!=null?w:null,content:null,isLoading:!1,settled:!1}})},[g,c,e,s]),ce(()=>{if(g||!c)return;let a=c.getAssignment(e,s);if(a&&t.includes(a.variantId))return;let l=!1;return c.assign(e,t,n,r).then(y=>{var x;l||y&&(!t.includes(y.variantId)&&!y.content||(v({variantId:y.variantId,content:(x=y.content)!=null?x:null,isLoading:!1,settled:!0}),p(y.variantId)))}),()=>{l=!0}},[g,c,e,s]),ce(()=>{if(!g&&c)return ze(e,a=>{var x;let l=c.getAssignment(e,s);if(l&&(t.includes(l.variantId)||l.content)){v({variantId:l.variantId,content:(x=l.content)!=null?x:null,isLoading:!1,settled:!0}),p(l.variantId);return}let y=Pe(a.variants,t);y&&(v({variantId:y,content:null,isLoading:!1,settled:!0}),p(y))})},[g,c,e,s]),g?{variantId:g,content:null,isLoading:!1,settled:!0,isOverride:!0}:h}function ue(e,t,n){let r=O(),i=N(),f=Object.keys(t).join("\0"),c=xt(()=>Object.keys(t),[f]),{variantId:s,content:m,isOverride:o=!1,settled:d}=Te(e,c,n.agentData,n.agentDataByVariant),[u,g]=mn(null),b=Q(null),h=gn(_=>{b.current=_,g(_)},[]),v=n.goal,p=typeof v=="string"?v:JSON.stringify(v),a=xt(()=>v?B(v):null,[p]),l=v?K(v):"";X(()=>lt({id:e,variantIds:c,goal:l}),[e,c,l]);let y=Q(null);X(()=>{o||d&&(!r||!s||!i||!u||y.current!==s&&(y.current=s,W(r,i,e,s)))},[r,s,i,e,u,o,d]);let x=Q(!1),w=Q(new Set);X(()=>{x.current=!1,w.current=new Set},[s,a]);let k=n.funnel;X(()=>{o||!d||!r||!k||!a||z(r,i,e,k,a)},[r,i,e,k,a,o,d]);let C=n.cursorSignal===!0;X(()=>{if(!C||o||!d||!r||!s||!u)return;let _=null,E=0,D=()=>{E=Date.now(),_=setTimeout(()=>{r.track({projectId:i,componentId:e,variantId:s,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-E}}),_=null},800)},P=()=>{_!==null&&(clearTimeout(_),_=null)};return u.addEventListener("mouseenter",D),u.addEventListener("mouseleave",P),()=>{u.removeEventListener("mouseenter",D),u.removeEventListener("mouseleave",P),_!==null&&clearTimeout(_)}},[C,r,s,i,e,u,o,d]);let A=Q(n.microSignalGoals);A.current=n.microSignalGoals;let R=n.microSignalGoals?JSON.stringify(n.microSignalGoals):"";return X(()=>{if(o||!d||!r||!s||!u)return;let _=Date.now();return pn((E,D={})=>{var Ne,je,Ke;r.track({projectId:i,componentId:e,variantId:s,eventType:"micro_signal",payload:S({signalType:E},D)});let P=(Ne=A.current)==null?void 0:Ne[E];if(!P||w.current.has(E))return;w.current.add(E);let H=typeof P=="string"?P:P.name,Wt=typeof P=="string"?1:(je=P.weight)!=null?je:1,Ut=typeof P=="string"?0:(Ke=P.stepIndex)!=null?Ke:0;r.goal(H,{metadata:S({signalType:E},D),weight:Wt,stepIndex:Ut})},u,_)},[r,s,i,e,u,R,o,d]),X(()=>{if(o||!d||!r||!s||!u||!a)return;let _=$(a);return V(u,a,{fireGoal:()=>{x.current||(x.current=!0,r.track({projectId:i,componentId:e,variantId:s,eventType:"goal_achieved",goalType:l,payload:S({reward:1},_!==void 0?{goalValue:_}:{})}),r.goal(l,S({metadata:{componentId:e,variantId:s},weight:1,stepIndex:0},_!==void 0?{value:_}:{})))},fireStep:(E,D,P)=>{r.track({projectId:i,componentId:e,variantId:s,eventType:"goal_achieved",goalType:E,payload:{reward:D}}),r.goal(E,{metadata:{},weight:D,stepIndex:P})}},l)},[r,s,i,e,u,a,l,o,d]),{client:r,variantIds:c,variantId:s,content:m,settled:d,isOverride:o,goalLabel:l,ref:h,nodeRef:b}}import{useEffect as te,useMemo as Cn,useRef as Le}from"react";import{containsFormBlock as An,reveal as _n}from"@sentientui/core";import{useCallback as vn,useEffect as wt,useRef as yn,useSyncExternalStore as de}from"react";import{armOfResult as Sn}from"@sentientui/core";var Ct=new Set;function At(e,t){var p;let n=O(),r=yn(t==null?void 0:t.baselineText);r.current=t==null?void 0:t.baselineText;let i=le(),f=St(),c=ht(),s=de(F,()=>{var a;return typeof window!="undefined"?(a=window.__sentient_slot_config_overrides)==null?void 0:a[e]:void 0},()=>{}),m=de(F,()=>{var a;return typeof window!="undefined"?(a=window.__sentient_slot_overrides)==null?void 0:a[e]:void 0},()=>{}),o=a=>a==null?"":Sn(a),d=vn(a=>{var l,y;return(y=(l=n==null?void 0:n.onSlotsChanged)==null?void 0:l.call(n,a))!=null?y:(()=>{})},[n]);de(d,()=>{var a;return(a=n==null?void 0:n.getSlotConfig(e))!=null?a:null},()=>null),de(d,()=>o(n==null?void 0:n.getSlotResult(e)),()=>"");let u=s===void 0?f[e]:void 0,g=s===void 0&&u===void 0&&n?n.getSlotConfig(e):null,b=(p=c!=null?c:n==null?void 0:n.getSitePalette())!=null?p:null,h=(()=>{var a,l;if(s!==void 0)return{config:s,arm:o(m),palette:b,source:"override"};if(u!==void 0)return{config:u,arm:o((a=i[e])!=null?a:n==null?void 0:n.getSlotResult(e)),palette:b,source:"preloaded"};if(g!==null){let y=n!=null&&n.isSlotDecided?n.isSlotDecided(e):!0;return{config:g,arm:o((l=n==null?void 0:n.getSlotResult(e))!=null?l:i[e]),palette:b,source:y?"client":"seeded"}}return{config:null,arm:"",palette:b,source:"none"}})(),v=h.source==="preloaded"||h.source==="override";return wt(()=>{var y,x;if(!n||n.isLocal===!0||v)return;let a=h.source==="none"&&(x=(y=r.current)==null?void 0:y.call(r))!=null?x:null,l=a!=null&&a!==""?[[e],{[e]:a}]:[[e]];return n.requestSlots?n.requestSlots(...l):h.source==="none"&&n.reportSlots(...l),()=>{var w;return(w=n.cancelSlots)==null?void 0:w.call(n,[e])}},[n,v,h.source,e]),wt(()=>{!G()||(n==null?void 0:n.isLocal)!==!0||h.source!=="none"||Ct.has(e)||(Ct.add(e),console.warn(`[sentient] <Adaptive id="${e}"> is rendering its baseline children: in local/keyless mode <Adaptive> serves ONLY what you pass as \`initialSlotConfig\` (there is no registry to decide from). Pass initialSlotConfig/initialSlots to <AdaptiveProvider> to preview arms locally.`))},[n,h.source,e]),h}import{Fragment as _t}from"react";import{jsx as T,jsxs as Ot}from"react/jsx-runtime";var U={none:"0",sm:"8px",md:"16px",lg:"24px"},De={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch",between:"space-between"},Et={sm:"0.875em",md:"1em",lg:"1.25em"},hn={sm:"1.25em",md:"1.5em",lg:"2em"},Rt={sm:"6px 14px",md:"10px 20px",lg:"14px 28px"},kt={sm:"8px",md:"16px",lg:"32px"},bn={square:"1 / 1",landscape:"4 / 3",wide:"16 / 9"},xn={normal:"400",medium:"500",bold:"700"};function Gt(e,t){return S(S({},e==="muted"?t!=null&&t.muted?{color:t.muted}:{opacity:.7}:{}),e==="accent"?S({fontWeight:600},t!=null&&t.accent?{color:t.accent}:{}):{})}function Pt(e,t,n){var i,f,c,s;let r=t==null?void 0:t.accent;return M(S({display:"inline-block",padding:(i=Rt[n!=null?n:"md"])!=null?i:Rt.md,borderRadius:(f=t==null?void 0:t.radius)!=null?f:"8px",font:"inherit"},n?{fontSize:Et[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"?(s=t==null?void 0:t.primaryText)!=null?s:"#ffffff":r!=null?r:"inherit",border:e==="secondary"?`1px solid ${r!=null?r:"currentColor"}`:"none"})}function wn({node:e,opts:t}){var i,f,c,s,m;let n=(i=e.emphasis)!=null?i:"primary",r={padding:"8px 10px",font:"inherit",border:`1px solid ${(c=(f=t.palette)==null?void 0:f.border)!=null?c:"currentColor"}`,borderRadius:(m=(s=t.palette)==null?void 0:s.radius)!=null?m:"8px"};return Ot("form",{onSubmit:o=>{var g,b,h;o.preventDefault();let d=new FormData(o.currentTarget),u={};for(let v of e.fields)u[v.name]=String((g=d.get(v.name))!=null?g:"");(b=t.onFormGoal)==null||b.call(t,e.submitGoal);try{(h=t.onFormSubmit)==null||h.call(t,u)}catch(v){}},style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e.fields.map(o=>{var d,u;return Ot("label",{style:{display:"flex",flexDirection:"column",gap:"4px",font:"inherit"},children:[o.label,o.kind==="textarea"?T("textarea",{name:o.name,required:o.required,placeholder:o.placeholder,rows:3,style:r}):o.kind==="select"?T("select",{name:o.name,required:o.required,style:r,children:((d=o.options)!=null?d:[]).map(g=>T("option",{value:g,children:g},g))}):T("input",{name:o.name,type:(u=o.inputType)!=null?u:"text",required:o.required,placeholder:o.placeholder,style:r})]},o.name)}),T("button",{type:"submit",style:Pt(n,t.palette),children:e.submitLabel})]})}function ee(e,t){var n,r,i,f,c,s,m,o,d,u,g,b,h,v,p,a,l,y,x,w,k,C,A;try{switch(e.type){case"stack":{let R=(r=U[(n=e.gap)!=null?n:"md"])!=null?r:U.md,_=e.surface==="raised",E=(i=e.pad)!=null?i:_?"md":void 0;return T("div",{style:S(S(S(S(S({display:"flex",flexDirection:e.direction,gap:R},e.align?{alignItems:De[e.align]}:{}),e.justify?{justifyContent:De[e.justify]}:{}),e.wrap?{flexWrap:"wrap"}:{}),E?{padding:(f=U[E])!=null?f:U.md}:{}),_?M(S(S({},(c=t.palette)!=null&&c.surface?{background:t.palette.surface}:{}),(s=t.palette)!=null&&s.surface&&((m=t.palette)!=null&&m.surfaceText)?{color:t.palette.surfaceText}:{}),{border:`1px solid ${(d=(o=t.palette)==null?void 0:o.border)!=null?d:"currentColor"}`,borderRadius:(g=(u=t.palette)==null?void 0:u.radius)!=null?g:"8px"}):{}),children:((b=e.children)!=null?b:[]).map((D,P)=>{let H=ee(D,t);return H===null?null:T(_t,{children:H},P)})})}case"grid":{let R=(v=U[(h=e.gap)!=null?h:"md"])!=null?v:U.md;return T("div",{style:S(S({display:"grid",gridTemplateColumns:`repeat(auto-fit, minmax(max(200px, calc((100% - ${e.columns-1} * ${R}) / ${e.columns})), 1fr))`,gap:R},e.align?{alignItems:De[e.align]}:{}),e.pad?{padding:(p=U[e.pad])!=null?p:U.md}:{}),children:((a=e.children)!=null?a:[]).map((_,E)=>{let D=ee(_,t);return D===null?null:T(_t,{children:D},E)})})}case"text":return T("p",{style:S(S(S(S(S({margin:0},e.size?{fontSize:Et[e.size]}:{}),e.weight?{fontWeight:xn[e.weight]}:{}),e.align?{textAlign:e.align}:{}),e.maxWidth==="measure"?{maxWidth:"65ch"}:{}),Gt(e.tone,t.palette)),children:e.value});case"heading":{let R=`h${e.level}`;return T(R,{style:S(S({margin:0,fontSize:hn[(l=e.size)!=null?l:"md"]},e.align?{textAlign:e.align}:{}),e.maxWidth==="measure"?{maxWidth:"65ch"}:{}),children:e.value})}case"button":{let R=(y=e.emphasis)!=null?y:"primary";return T("a",M(S({href:e.href},e.tag?{"data-sentient-tag":e.tag}:{}),{style:Pt(R,t.palette,e.size),children:e.label}))}case"link":return T("a",M(S({href:e.href},e.tag?{"data-sentient-tag":e.tag}:{}),{style:{color:"inherit",textDecoration:"underline"},children:e.label}));case"image":return T("img",{src:e.src,alt:e.alt,style:S(S({display:"block",maxWidth:"100%"},e.ratio&&e.ratio!=="auto"?{aspectRatio:bn[e.ratio],width:"100%"}:{}),e.fit?{objectFit:e.fit}:{})});case"badge":return T("span",{style:S({display:"inline-block",padding:"2px 10px",borderRadius:"999px",fontSize:"0.75em",border:`1px solid ${(w=(x=t.palette)==null?void 0:x.border)!=null?w:"currentColor"}`},Gt(e.tone,t.palette)),children:e.value});case"spacer":return T("div",{style:{height:(k=kt[e.size])!=null?k:kt.md}});case"divider":return T("hr",{style:{border:"none",borderTop:`1px solid ${(A=(C=t.palette)==null?void 0:C.border)!=null?A:"currentColor"}`,margin:0,width:"100%"}});case"form":return T(wn,{node:e,opts:t});default:return null}}catch(R){return null}}import{jsx as Rn}from"react/jsx-runtime";var Tt=new Set;function Ie({id:e,children:t,onFormSubmit:n,goal:r,className:i,reportBaselineText:f=!0}){var C;let c=O(),s=N(),m=Le(null),{config:o,arm:d,palette:u,source:g}=At(e,{baselineText:f?()=>{var A,R;return(R=(A=m.current)==null?void 0:A.textContent)!=null?R:null}:void 0}),b=d!==""?(C=o==null?void 0:o.blocks)==null?void 0:C[d]:void 0,h=b!==void 0&&An(b)&&!n;te(()=>{!h||!G()||Tt.has(e)||(Tt.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 v=A=>{!c||g==="override"||(g!=="seeded"&&c.componentGoal(e,A),c.goal(A,{metadata:{componentId:e,arm:d},weight:1,stepIndex:0}))},p=t,a=!1;if(b!==void 0){let A=h?null:ee(b,{palette:u,onFormSubmit:n,onFormGoal:v});A===null?a=!0:p=A}else(o==null?void 0:o.content)!==void 0&&g!=="none"&&(p=o.content);let l=o!=null&&o.blocks?Object.keys(o.blocks).sort().join("|"):"";te(()=>q({id:e,arms:l===""?void 0:l.split("|")}),[e,l]);let y=Le(null);te(()=>{!c||g==="none"||g==="seeded"||g==="override"||d===""||a||y.current!==d&&(y.current=d,W(c,s,e,d))},[c,s,e,d,g,a]);let x=r===void 0?null:typeof r=="string"?r:JSON.stringify(r);te(()=>{if(!c||!r||g==="override"||g==="none"||g==="seeded"||a)return;let A=m.current;if(!A)return;let R=K(r),_=$(r),E=!1;return V(A,B(r),{fireGoal:()=>{E||(E=!0,_!==void 0?c.componentGoal(e,R,{value:_}):c.componentGoal(e,R),c.goal(R,S({metadata:{componentId:e,arm:d},weight:1,stepIndex:0},_!==void 0?{value:_}:{})))},fireStep:(D,P,H)=>{c.componentGoal(e,D,{reward:P}),c.goal(D,{metadata:{componentId:e,arm:d},weight:P,stepIndex:H})}},R)},[c,e,x,d,g,a]);let w=Le(null);te(()=>{let A=m.current;if(A){if(w.current===null){w.current=d;return}w.current!==d&&(w.current=d,_n(A))}},[d]);let k=Cn(()=>S({"data-sentient-slot":e},d!==""?{"data-sentient-arm":d}:{}),[e,d]);return Rn("div",M(S({ref:m,className:i},k),{children:p}))}import{jsx as Fe}from"react/jsx-runtime";function En(e){var o;let{client:t,variantId:n,content:r,ref:i}=ue(e.id,e.variants,{goal:e.goal,funnel:e.funnel,microSignalGoals:e.microSignalGoals,agentData:e.agentData,agentDataByVariant:e.agentDataByVariant,cursorSignal:!0}),[f,c]=On(!1);if(Gn(()=>{c(!0)},[]),e.clientOnly&&(!f||!t)||!n)return null;let s=(o=e.variants[n])!=null?o:null,m=s===null?r:null;return G()&&s===null&&m===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${n}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),Fe("div",{ref:i,"data-sentient-id":e.id,"data-sentient-variant":n,children:s!=null?s:m})}var Pn=kn(En,(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]))});function Tn(e){return e.variants===void 0?Fe(Ie,S({},e)):(G()&&e.children!=null&&console.warn(`[sentient] <Adaptive id="${e.id}"> got both variants and children \u2014 rendering variants; children are ignored.`),Fe(Pn,S({},e)))}import{useEffect as fe,useMemo as Dn,useRef as Be,useState as Dt,useSyncExternalStore as Ln}from"react";import{jsx as Fn}from"react/jsx-runtime";function In({id:e,default:t,component:n="span",className:r,goal:i}){var k;let f=O(),c=N(),s=ae(),m=se(),o=Be(null),d=Be(null),u=Ln(F,()=>Z(e),()=>null),[g,b]=Dt(()=>{var C,A;return(A=(C=f==null?void 0:f.getAssignment(e,m))==null?void 0:C.content)!=null?A:null}),[h,v]=Dt(()=>{var C,A;return(A=(C=f==null?void 0:f.getAssignment(e,m))==null?void 0:C.variantId)!=null?A:null});fe(()=>{if(u||!f)return;let C=f.getAssignment(e,m);if((C==null?void 0:C.content)!==void 0){v(C.variantId),b(C.content);return}let A=!1;return f.assign(e).then(R=>{if(!A){if(!R){G()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}v(R.variantId),R.content&&b(R.content)}}),()=>{A=!0}},[f,e,m,u]),fe(()=>{u||!f||!h||!c||o.current!==h&&(o.current=h,f.track({projectId:c,componentId:e,variantId:h,eventType:"variant_assigned",payload:{}}),s==null||s(e,h))},[f,h,c,e,s,u]);let p=i===void 0?"":typeof i=="string"?i:JSON.stringify(i),a=Dn(()=>i===void 0?null:B(i),[p]),l=i===void 0?null:typeof i=="string"?i:a.type,y=Be(!1);fe(()=>{y.current=!1},[h,p]),fe(()=>{if(u||!f||!h||!c||!a||!l)return;let C=d.current;if(!C)return;let A=$(a);return V(C,a,{fireGoal:()=>{y.current||(y.current=!0,f.track({projectId:c,componentId:e,variantId:h,eventType:"goal_achieved",goalType:l,payload:S({reward:1},A!==void 0?{goalValue:A}:{})}),f.goal(l,S({metadata:{componentId:e,variantId:h},weight:1,stepIndex:0},A!==void 0?{value:A}:{})))},fireStep:(R,_,E)=>{f.track({projectId:c,componentId:e,variantId:h,eventType:"goal_achieved",goalType:R,payload:{reward:_}}),f.goal(R,{metadata:{},weight:_,stepIndex:E})}})},[f,h,c,e,a,l,u]);let x=g!=null?g:t;if(u){let C=f==null?void 0:f.getAssignment(e,m);x=C&&C.variantId===u&&(k=C.content)!=null?k:t}return Fn(n,{ref:C=>{d.current=C},className:r,children:x})}import{useCallback as Bn,useRef as Mn}from"react";function Me(e){let t=O(),n=Mn(new Set);return Bn((r,i)=>{var f,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,S(S(S({metadata:(f=i==null?void 0:i.metadata)!=null?f:{},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 $n,useRef as Lt}from"react";function Vn(e,t={}){let m=t,{componentId:n}=m,r=Xe(m,["componentId"]),i=O(),f=Me(n!=null?n:""),c=Lt(!1),s=Lt(r);s.current=r,$n(()=>{if(!i||c.current)return;c.current=!0;let{metadata:o,reward:d,value:u,currency:g,externalId:b}=s.current;if(n){f(e,s.current);return}i.goal(e,S(S(S({metadata:o!=null?o:{},weight:d!=null?d:1,stepIndex:0},u!==void 0?{value:u}:{}),g!==void 0?{currency:g}:{}),b!==void 0?{externalId:b}:{}))},[i,n,e,f])}import{renderPrePaintScript as Nn}from"@sentientui/core";import{confidenceBand as jn}from"@sentientui/policy";import{jsx as Un}from"react/jsx-runtime";function It(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Kn(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+It(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+It(jn(e.persona.confidence))+");}catch(e){}})();":Nn(e.apiKey)}function Wn(e){return Un("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Kn(e)}})}import{useEffect as pe,useMemo as Ve,useRef as Yn}from"react";import{validateSlotDecl as Qn}from"@sentientui/policy";import{useEffect as $e,useReducer as Jn,useState as Xn,useSyncExternalStore as Ft}from"react";import{armOfResult as ge,baselineResultFor as Hn}from"@sentientui/core";import{confidenceBand as zn}from"@sentientui/policy";function me(e,t){let n=O(),r=le(),[,i]=Jn(u=>u+1,0),f=Ft(F,()=>{var u;return typeof window!="undefined"?(u=window.__sentient_slot_overrides)==null?void 0:u[e]:void 0},()=>{}),c=f===void 0?r[e]:void 0,s=f===void 0&&c===void 0&&n?n.getSlotResult(e):null,m=(n==null?void 0:n.isLocal)===!0&&f===void 0&&c===void 0&&s===null;$e(()=>{if(!m||!n)return;let u=!1;return n.decide({slots:[t]}).then(g=>{!u&&g&&i()}),()=>{u=!0}},[n,e,m]);let o=(()=>{if(f!==void 0)return{result:f,arm:ge(f),source:"override"};if(c!==void 0)return{result:c,arm:ge(c),source:"preloaded"};if(s!==null){let g=n!=null&&n.isSlotDecided?n.isSlotDecided(e):!0;return{result:s,arm:ge(s),source:g?"client":"seeded"}}let u=Hn(t);return{result:u,arm:ge(u),source:"baseline"}})(),d=o.source==="preloaded"||o.source==="override";return $e(()=>{var g;if(!n||n.isLocal===!0||d||!n.decideSlots)return;let u=(g=n.onSlotsChanged)==null?void 0:g.call(n,i);return n.decideSlots([t]),()=>{var b;(b=n.cancelSlots)==null||b.call(n,[e]),u==null||u()}},[n,e,d]),o}function qn(){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 Zn(){let e=O(),t=yt();Ft(F,et,()=>0);let[n,r]=Xn(!1);$e(()=>r(!0),[]);let i=s=>({persona:s.persona,confidence:s.confidence,band:zn(s.confidence)});if(!n)return t?i(t):null;let f=qn();if(f)return i(f);if(t)return i(t);let c=e?e.getPersona():null;return c?i(c):null}var Bt=new Set;function er(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function tr(e,t,n){let r=O(),i=N(),f=JSON.stringify(t),c=Ve(()=>({id:e,dims:t}),[e,f]),{result:s,arm:m,source:o}=me(e,c),d=Ve(()=>typeof s=="string"?{}:s,[m]);if(G()&&!Bt.has(e)){Bt.add(e);let v=Qn({id:e,dims:Object.fromEntries(Object.entries(t).map(([a,l])=>[a,[...l]]))}),p=Object.values(t).reduce((a,l)=>a*l.length,1);v.ok?p>4&&console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${p} 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 ${v.reason}. Serving baseline.`)}let u=(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 g=Yn(null);pe(()=>{!r||o==="baseline"||o==="seeded"||o==="override"||g.current===m||(g.current=m,W(r,i,e,m))},[r,i,e,m,o]);let b=n==null?void 0:n.funnel;pe(()=>{var v;!r||!b||o==="override"||z(r,i,e,b,B((v=n==null?void 0:n.goal)!=null?v:"click"))},[r,i,e,b,u,o]),pe(()=>{if(!r||!(n!=null&&n.goal)||o==="override"||o==="baseline"||o==="seeded")return;let v=document.querySelector(`[data-sentient-slot="${er(e)}"]`);if(!v){G()&&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 p=K(n.goal),a=$(n.goal),l=!1;return V(v,B(n.goal),{fireGoal:()=>{l||(l=!0,a!==void 0?r.componentGoal(e,p,{value:a}):r.componentGoal(e,p),r.goal(p,S({metadata:{componentId:e,arm:m},weight:1,stepIndex:0},a!==void 0?{value:a}:{})))},fireStep:(y,x,w)=>{r.componentGoal(e,y,{reward:x}),r.goal(y,{metadata:{componentId:e,arm:m},weight:x,stepIndex:w})}},p)},[r,e,u,m,o]);let h=Ve(()=>{let v={"data-sentient-slot":e};for(let[p,a]of Object.entries(d))v[`data-${p}`]=a;return v},[e,d]);return{tokens:d,props:h}}import{useCallback as nr,useEffect as rr,useMemo as ir}from"react";var Mt=new Set;function or(e,t){var b;if(G()&&!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{client:n,variantIds:r,variantId:i,isOverride:f,goalLabel:c,ref:s,nodeRef:m}=ue(e,t.variants,{goal:t.goal,funnel:t.funnel,microSignalGoals:t.microSignalGoals}),o=(b=i!=null?i:r[0])!=null?b:"",d=t.variants[o];rr(()=>{if(!G()||!n)return;let h=setTimeout(()=>{!m.current&&!Mt.has(e)&&(Mt.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(h)},[n,e]);let u=nr((h,v)=>{var a,l;if(f)return;let p=h!=null?h:c;p&&(n==null||n.componentGoal(e,p,v),n==null||n.goal(p,S(S(S({metadata:(a=v==null?void 0:v.metadata)!=null?a:{},weight:(l=v==null?void 0:v.reward)!=null?l:1,stepIndex:0},(v==null?void 0:v.value)!==void 0?{value:v.value}:{}),(v==null?void 0:v.currency)!==void 0?{currency:v.currency}:{}),(v==null?void 0:v.externalId)!==void 0?{externalId:v.externalId}:{})))},[n,e,c,f]),g=ir(()=>({ref:s,"data-sentient-id":e,"data-sentient-variant":o}),[s,e,o]);return{variant:o,value:d,bind:g,fireGoal:u}}import{Children as sr,isValidElement as ar,useEffect as ve,useMemo as $t,useRef as Vt}from"react";import{jsx as cr}from"react/jsx-runtime";var ye=new Set;function lr(e){var a;let t=O(),n=N(),r=Vt(null),i=Object.keys(e.arrangements).join(" "),f=$t(()=>Object.keys(e.arrangements),[i]),c=$t(()=>S({id:e.id,arms:f},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,f,e.baseline]),{arm:s,source:m}=me(e.id,c);G()&&e.baseline!==void 0&&e.baseline!==f[0]&&!ye.has(e.id+":baseline")&&(ye.add(e.id+":baseline"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: baseline "${e.baseline}" is not the first-declared arrangement ("${f[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let o=sr.toArray(e.children).filter(ar),d=new Map;for(let l of o)d.set(String((a=l.key)!=null?a:"").replace(/^\.\$/,""),l);let u=e.arrangements[s],g=u!==void 0&&u.length===o.length&&u.every(l=>d.has(l));G()&&u!==void 0&&!g&&!ye.has(e.id+":keys")&&(ye.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${s}" [${u.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let b=g?u.map(l=>d.get(l)):o;ve(()=>q({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let h=Vt(null);ve(()=>{!t||m==="baseline"||m==="seeded"||m==="override"||h.current===s||(h.current=s,W(t,n,e.id,s))},[t,n,e.id,s,m]);let v=e.funnel;ve(()=>{var l;!t||!v||m==="override"||z(t,n,e.id,v,B((l=e.goal)!=null?l:"click"))},[t,n,e.id,v,m]);let p=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return ve(()=>{if(!t||e.goal===void 0||m==="override"||m==="baseline"||m==="seeded")return;let l=r.current;if(!l)return;let y=K(e.goal),x=$(e.goal),w=!1;return V(l,B(e.goal),{fireGoal:()=>{w||(w=!0,x!==void 0?t.componentGoal(e.id,y,{value:x}):t.componentGoal(e.id,y),t.goal(y,S({metadata:{componentId:e.id,arm:s},weight:1,stepIndex:0},x!==void 0?{value:x}:{})))},fireStep:(k,C,A)=>{t.componentGoal(e.id,k,{reward:C}),t.goal(k,{metadata:{componentId:e.id,arm:s},weight:C,stepIndex:A})}},y)},[t,e.id,p,s,m]),cr("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":s,children:b})}import{deriveSessionSegment as ur}from"@sentientui/core";var dr=["page","blocks","layoutOrder"],Nt=new Map;function fr(e,t){Nt.set(e,t)}function jt(e){return Nt.get(e)}function gr(e){var i,f;let t=(f=(i=e.content)!=null?i:jt(e.page))!=null?f:{},n={};for(let[c,s]of Object.entries(t))dr.includes(c)||(n[c]=s);let r=M(S({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(r.layoutOrder=e.layoutOrder),r}function mr(e){return`<script type="application/ld+json">${Kt(e)}</script>`}function Kt(e){return JSON.stringify(S({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function pr(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
|
|
4
|
+
`}import{grantConsent as Zo}from"@sentientui/core";export{Tn as Adaptive,lr as AdaptiveGroup,an as AdaptiveProvider,Ie as AdaptiveSlot,In as AdaptiveText,Wn as SentientPersonaScript,gr as buildAgentFeed,fr as defineAgentContent,ur as detectSegment,jt as getAgentContent,Zo as grantConsent,mr as renderAgentJsonLd,Kt as renderAgentJsonLdBody,pr as renderAgentMarkdown,ee as renderBlocks,or as useAdaptive,cn as useAdaptiveApiBaseUrl,Me as useAdaptiveGoal,Zn as useAdaptivePersona,tr as useAdaptiveTokens,Te as useAssignment,Ee as useInitialAssignments,ln as useLayoutOrder,Vn as usePageGoal,O as useSentient};
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|