@sentientui/snippet 0.16.1 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -5
- package/dist/editor.global.js +7 -7
- package/dist/snippet.global.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Style-rung [SentientUI](https://sentient-ui.com) for sites that are not built with React.
|
|
4
4
|
One script tag: visitor-type attributes on `<html>` plus learned `data-*` style tokens on the
|
|
5
|
-
elements you declare. Plain CSS does the rest. No
|
|
6
|
-
`textContent
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
elements you declare. Plain CSS does the rest. No HTML is ever accepted or injected — text is
|
|
6
|
+
written as `textContent`, styles come from a bounded validated set, and dashboard-authored
|
|
7
|
+
Composition Blocks are a typed, enumerated component tree rendered via `createElement` only
|
|
8
|
+
(there is no sanitizer because there is no HTML to sanitize). The structural changes possible
|
|
9
|
+
are: moving a declared element among its own siblings (a registry `moveBefore`/`moveAfter` op,
|
|
10
|
+
applied after the decision returns; a drifted anchor applies nothing), reordering the sections
|
|
11
|
+
you list in `sections` within their shared parent (never applied unless every selector still
|
|
12
|
+
resolves and the served order is exactly a permutation of them), and revealing one published
|
|
13
|
+
Composition-Block arm inside its slot (all arms render hidden up front; the served one is
|
|
14
|
+
shown, and removing the arm restores your original markup exactly). If anything fails, your
|
|
9
15
|
page is left exactly as it was.
|
|
10
16
|
|
|
11
17
|
```html
|
|
@@ -16,6 +22,8 @@ page is left exactly as it was.
|
|
|
16
22
|
personaAttributes: true, // sets data-sentient-persona / -confidence on <html>
|
|
17
23
|
persona: () => window.myApp?.role, // optional: declare the role your site already knows
|
|
18
24
|
// (string or function; must be a key from Settings → Personas)
|
|
25
|
+
sections: ['#hero', '#pricing', '#faq'], // optional: sections eligible for reordering,
|
|
26
|
+
// CSS selectors in your theme's natural order
|
|
19
27
|
slots: {
|
|
20
28
|
hero: { dims: { tone: ['calm', 'urgent'] }, target: '#hero' },
|
|
21
29
|
},
|
|
@@ -48,9 +56,15 @@ persona vocabulary (dashboard → Settings → Personas); unrecognized values ar
|
|
|
48
56
|
server-side and surfaced in the dashboard so you can add them. Keep it a low-cardinality
|
|
49
57
|
role label — never a user id or email.
|
|
50
58
|
|
|
59
|
+
`sections` lists the page sections the optimizer may reorder, as CSS selectors in the order
|
|
60
|
+
your theme renders them (the first learned baseline). Each selector must match exactly one
|
|
61
|
+
element and all of them must share one parent; anything else — a missing section, an ambiguous
|
|
62
|
+
selector, a served order that isn't a permutation of your list — applies nothing. Return visits
|
|
63
|
+
pre-paint the last served order from a local snapshot, so there is no natural-order flash.
|
|
64
|
+
|
|
51
65
|
The snippet also captures per-section attention (visible time + scroll depth) and behavioral
|
|
52
66
|
signals by default — that's what builds audience profiles with zero tagging. Add
|
|
53
67
|
`sectionCapture: false` to `window.sentient` to turn it off; it never runs for a Do-Not-Track,
|
|
54
68
|
Global Privacy Control, or consent-gated visitor.
|
|
55
69
|
|
|
56
|
-
Bundle ≤
|
|
70
|
+
Bundle ≤ 20 KiB gzip (CI-enforced). MIT.
|
package/dist/editor.global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var SentientSnippet=(()=>{var
|
|
2
|
-
`)}function
|
|
1
|
+
"use strict";var SentientSnippet=(()=>{var Lt=Object.defineProperty,Ee=Object.defineProperties,we=Object.getOwnPropertyDescriptor,Se=Object.getOwnPropertyDescriptors,Le=Object.getOwnPropertyNames,Jt=Object.getOwnPropertySymbols;var Zt=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable;var Xt=(e,t,n)=>t in e?Lt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,F=(e,t)=>{for(var n in t||(t={}))Zt.call(t,n)&&Xt(e,n,t[n]);if(Jt)for(var n of Jt(t))Ce.call(t,n)&&Xt(e,n,t[n]);return e},V=(e,t)=>Ee(e,Se(t));var Te=(e,t)=>{for(var n in t)Lt(e,n,{get:t[n],enumerable:!0})},Be=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Le(t))!Zt.call(e,s)&&s!==n&&Lt(e,s,{get:()=>t[s],enumerable:!(o=we(t,s))||o.enumerable});return e};var $e=e=>Be(Lt({},"__esModule",{value:!0}),e);var on={};Te(on,{buildStyleOps:()=>fe,clearTargetHighlights:()=>yt,computeMoveAnchors:()=>_t,deriveSlotId:()=>ht,drawTargetHighlights:()=>ce,mount:()=>ge,styleFieldError:()=>pe});function Ae(e){var n,o,s;let t=(o=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:o.location;return(s=t==null?void 0:t.pathname)!=null?s:""}function _e(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let o=((n=e.textContent)!=null?n:"").trim().toLowerCase(),s=t.text.trim().toLowerCase();if(!(o===s||o.startsWith(s)||s.startsWith(o)))return!1}return!0}var Re=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function et(e,t){var s;if(e.urlMatch&&!Ae(t).includes(e.urlMatch))return null;let n=[];if(e.id){let d=t.getElementById(e.id);n=d?[d]:[]}if(n.length===0&&((s=e.dataAttr)!=null&&s.name)&&Re.test(e.dataAttr.name))try{let d=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${d}"]`))}catch(d){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(d){n=[]}if(n.length!==1)return null;let o=n[0];return e.fingerprint&&!_e(o,e.fingerprint)?null:o}function Kt(e){let t=globalThis;if(t.CSS&&typeof t.CSS.escape=="function")return t.CSS.escape(e);let n="";for(let o=0;o<e.length;o++){let s=e[o],d=s>="0"&&s<="9";o===0&&d||o===1&&d&&e[0]==="-"?n+=`\\3${s} `:o===0&&s==="-"&&e.length===1?n+="\\-":/[a-zA-Z0-9_-]/.test(s)?n+=s:n+=`\\${s}`}return n}function Ie(e,t){if(e.id)return`#${Kt(e.id)}`;let n=[],o=e,s=0;for(;o&&o!==t.body&&o!==t.documentElement&&s<6;){if(o.id){n.unshift(`#${Kt(o.id)}`);break}let d=o.tagName.toLowerCase(),f=o.parentElement;if(f){let v=Array.from(f.children).filter(m=>m.tagName===o.tagName);v.length>1&&(d+=`:nth-of-type(${v.indexOf(o)+1})`)}n.unshift(d),o=o.parentElement,s++}return n.join(" > ")}function mt(e,t){var s;let n={v:1};e.id&&(n.id=e.id);for(let d of["data-framer-name","data-w-id","data-sentient-name"]){let f=e.getAttribute(d);if(f){n.dataAttr={name:d,value:f};break}}n.selector=Ie(e,t);let o=((s=e.textContent)!=null?s:"").trim().replace(/\s+/g," ").slice(0,80);return n.fingerprint=F({tag:e.tagName.toLowerCase()},o?{text:o}:{}),n}function Ct(e,t,n){return et(e,n)===t}var Me="__snt_editor_token";function Tt(){try{sessionStorage.removeItem(Me)}catch(e){}}var Pe=/rgba\([^)]*,\s*0\s*\)$/,He=/^\d+(\.\d+)?px$/;function Qt(e){var t,n;try{let o=e.defaultView;if(!o||!e.body)return null;let s=o.getComputedStyle(e.body).backgroundColor,d=e.querySelectorAll('button, [role="button"], input[type="submit"], a[class*="btn" i], a[class*="button" i]'),f=new Map;for(let I of Array.from(d).slice(0,300)){let _=I.getBoundingClientRect();if(_.width>0&&(_.width<48||_.height<24))continue;let M=o.getComputedStyle(I),L=M.backgroundColor;if(!L||L==="transparent"||L===s||Pe.test(L))continue;let P=(t=(M.borderRadius||"").split(" ")[0])!=null?t:"",H=`${L}|${M.color}|${He.test(P)?P:"8px"}`;f.set(H,((n=f.get(H))!=null?n:0)+1)}let v=null,m=0;for(let[I,_]of f)_>m&&(v=I,m=_);if(!v)return null;let[z,B,G]=v.split("|");return{primaryBg:z,primaryText:B,radius:G}}catch(o){return null}}var te={color:"color",background:"background",fontSize:"font-size",fontWeight:"font-weight",textAlign:"text-align",padding:"padding",margin:"margin",borderRadius:"border-radius",width:"width",height:"height",maxWidth:"max-width",border:"border",boxShadow:"box-shadow",opacity:"opacity",lineHeight:"line-height",letterSpacing:"letter-spacing",textTransform:"text-transform",gap:"gap",fontFamily:"font-family"},Oe=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function Bt(e){var t;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;for(let n of e.matchAll(/([A-Za-z-]*)\(/g))if(!Oe.test((t=n[1])!=null?t:""))return!1;return!0}var ee=/^https:\/\//i,ne=new Map,J=null;function ze(e){return e.replace(/["\\]/g,"\\$&")}function Ne(e){var t;(!J||!J.isConnected)&&(J=e.querySelector("style[data-sentient-ops]"),J||(J=e.createElement("style"),J.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(J))),J.textContent=[...ne.entries()].map(([n,o])=>`[data-snt-e="${ze(n)}"]{${o}}`).join(`
|
|
2
|
+
`)}function oe(e,t,n,o){var v;let s=!1,d=(v=t.moveBefore)!=null?v:t.moveAfter;if(d){let m=et(d,o);!m||m===e||m.parentElement!==e.parentElement||!e.parentElement?s=!0:t.moveBefore?e.parentElement.insertBefore(e,m):e.parentElement.insertBefore(e,m.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&ee.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&ee.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let f=[];if(t.hidden&&f.push("display:none !important"),t.style)for(let[m,z]of Object.entries(t.style)){let B=te[m];B&&typeof z=="string"&&Bt(z)&&f.push(`${B}:${z.trim()} !important`)}return f.length>0&&(e.setAttribute("data-snt-e",n),ne.set(n,f.join(";")),Ne(o)),{anchorMiss:s}}function Ht(e){let t=e.steps.length,n=e.status==="active"?"":` (${e.status})`;return`${e.display_name} \u2014 ${t} step${t===1?"":"s"}${n}`}function Ot(e,t){return e.steps.map(n=>{var o;return{value:n.step_index,label:`${n.step_index+1}. ${(o=t.get(n.goal_id))!=null?o:n.goal_id}`}})}function re(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function Fe(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"funnel"}function ie(e,t){let n=e.trim();return n?t.length<2?{ok:!1,error:"Pick at least 2 goals \u2014 a funnel is a sequence."}:t.length>12?{ok:!1,error:"A funnel can have at most 12 steps."}:{ok:!0,funnelId:Fe(n),body:{displayName:n.slice(0,128),steps:t.map(o=>({goalId:o}))}}:{ok:!1,error:"Give the funnel a name."}}function le(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)>>>0;return t.toString(36)}function At(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40)}function ht(e,t,n){var v,m;let o=t.id||((v=t.dataAttr)==null?void 0:v.value)||((m=n.textContent)!=null?m:"").trim()||n.tagName,s=At(o)||"el",d=le(JSON.stringify(t));return`${e}-${s}-${d}`.slice(0,128)}var De="sentient-editor-highlight",je="sentient-editor-selection",st="sentient-editor-panel",Rt="sentient-editor-toast",se="sentient-editor-styles",zt="sentient-editor-target-highlight",Ge=10,Ue="Editor session expired. Reopen it from your dashboard to keep editing \u2014 your saved changes are safe.",We="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.";function de(){var t;if(document.getElementById(se))return;let e=document.createElement("style");e.id=se,e.textContent=`
|
|
3
3
|
@keyframes sntedi-in {
|
|
4
4
|
from { opacity: 0; transform: translateY(28px) scale(0.94); }
|
|
5
5
|
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
0%, 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0.55); }
|
|
13
13
|
50% { box-shadow: 0 0 0 5px rgba(52,211,153,0); }
|
|
14
14
|
}
|
|
15
|
-
#${
|
|
15
|
+
#${st} {
|
|
16
16
|
animation: sntedi-in 0.42s cubic-bezier(0.2,0.9,0.25,1.15) both,
|
|
17
17
|
sntedi-attn 1.7s ease-in-out 0.42s 3;
|
|
18
18
|
}
|
|
19
|
-
#${
|
|
20
|
-
#${
|
|
19
|
+
#${st} .sntedi-dot { animation: sntedi-dot 1.4s ease-in-out infinite; }
|
|
20
|
+
#${Rt} { animation: sntedi-in 0.42s cubic-bezier(0.2,0.9,0.25,1.15) both; }
|
|
21
21
|
@media (prefers-reduced-motion: reduce) {
|
|
22
|
-
#${
|
|
22
|
+
#${st}, #${st} .sntedi-dot, #${Rt} { animation: none !important; }
|
|
23
23
|
}
|
|
24
|
-
`,((t=document.head)!=null?t:document.documentElement).appendChild(e)}function re(e){var o,s;se(),(o=document.getElementById(Bt))==null||o.remove();let t=a("div",{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",display:"flex",gap:"10px",alignItems:"flex-start",cursor:"pointer"});t.id=Bt;let n=a("span",{width:"9px",height:"9px",marginTop:"4px",borderRadius:"50%",background:"#f59e0b",flex:"0 0 auto"});t.append(n,a("div",{},e)),((s=document.body)!=null?s:document.documentElement).appendChild(t),t.addEventListener("click",()=>t.remove()),setTimeout(()=>t.remove(),1e4)}function Fe(){let e=window.__sentientEditor;return e&&typeof e.token=="string"&&typeof e.apiBase=="string"?e:null}async function De(e){try{let t=await fetch(`${e.apiBase}/v1/editor/verify`,{headers:{authorization:`Bearer ${e.token}`}});if(t.status===401)return{ok:!1,unauthorized:!0};if(!t.ok)return{ok:!1,unauthorized:!1};let n=(await t.json()).projectId;return n?{ok:!0,projectId:n}:{ok:!1,unauthorized:!1}}catch(t){return{ok:!1,unauthorized:!1}}}async function P(e,t,n){try{let o=await fetch(`${e.apiBase}${t}`,{method:"POST",headers:{authorization:`Bearer ${e.token}`,"content-type":"application/json"},body:JSON.stringify(n)});return o.ok?"ok":o.status===401?"expired":"error"}catch(o){return"error"}}var Ot=[];async function Ge(e){try{let t=await fetch(`${e.apiBase}/v1/editor/targets`,{headers:{authorization:`Bearer ${e.token}`}});if(!t.ok)return[];let n=await t.json();return Ot=Array.isArray(n.fonts)?n.fonts.filter(o=>typeof o=="string"):[],Array.isArray(n.targets)?n.targets:[]}catch(t){return[]}}async function Ht(e,t){try{let n=await fetch(`${e.apiBase}${t}`,{headers:{authorization:`Bearer ${e.token}`}});return n.ok?await n.json():null}catch(n){return null}}function ft(e=document){for(let t of Array.from(e.querySelectorAll(`.${Pt}`)))t.remove()}function ae(e,t=document){var o;ft(t);let n=0;for(let s of e){if(n>=Oe)break;let c=V(s.locator,t);if(!c)continue;let u=c.getBoundingClientRect(),E=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${u.left}px`,top:`${u.top}px`,width:`${u.width}px`,height:`${u.height}px`,border:"2px dashed #10b981",background:"rgba(16,185,129,0.08)"});E.className=Pt;let h=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${u.left}px`,top:`${Math.max(0,u.top-20)}px`,padding:"2px 6px",borderRadius:"4px",background:"#10b981",color:"#fff",font:"11px system-ui, sans-serif",whiteSpace:"nowrap"},s.label);h.className=Pt,((o=t.body)!=null?o:t.documentElement).append(E,h),n+=1}}function Tt(e,t){let n=e.previousElementSibling,o=e.nextElementSibling,s=n?pt(n,t):null,c=o?pt(o,t):null;return{prevEl:n,nextEl:o,prevLocator:n&&s&&Et(s,n,t)?s:null,nextLocator:o&&c&&Et(c,o,t)?c:null}}var le=["color","background","fontSize","fontWeight","borderRadius","textAlign","fontFamily"],je=/^(0|\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|pt))$/i,Ue=new Set(["left","center","right","justify","start","end"]),We=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,qe=/^(rgb|rgba|hsl|hsla)\(/i;function Ye(e){return We.test(e)||qe.test(e)}function ce(e,t){switch(e){case"fontSize":case"borderRadius":return je.test(t)?null:"Add a unit, e.g. 20px or 1.5rem.";case"fontWeight":return/^(normal|bold|bolder|lighter)$/i.test(t)||/^\d{1,4}$/.test(t)&&+t>=1&&+t<=1e3?null:"Use 100\u2013900, or normal/bold.";case"textAlign":return Ue.has(t.toLowerCase())?null:"Choose left, center, right, or justify.";case"color":case"background":return Ye(t)?null:"Enter a colour, e.g. #1a1a1a.";case"fontFamily":{let n=t.split(",").map(o=>o.trim().replace(/^['"]|['"]$/g,""));return t.length<=120&&n.length>=1&&n.length<=5&&n.every(o=>/^[A-Za-z0-9][A-Za-z0-9 -]*$/.test(o))?null:"Use a font name, e.g. Georgia, serif."}default:return null}}function de(e){let t={},n={};for(let o of le){let s=e[o];if(typeof s!="string")continue;let c=s.trim();if(c==="")continue;if(!St(c)){n[o]="That value isn\u2019t allowed.";continue}let u=ce(o,c);if(u){n[o]=u;continue}t[o]=c}return{style:t,errors:n}}function a(e,t,n){let o=document.createElement(e);return Object.assign(o.style,t),n!==void 0&&(o.textContent=n),o}function ue(e){var qt;let t=null,n=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #6366f1",background:"rgba(99,102,241,0.12)",display:"none"});n.id=He;let o=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #10b981",background:"rgba(16,185,129,0.10)",borderRadius:"4px",display:"none"});o.id=Pe;let s=()=>{if(!t||!t.isConnected){o.style.display="none";return}let r=t.getBoundingClientRect();Object.assign(o.style,{display:"block",left:`${r.left-2}px`,top:`${r.top-2}px`,width:`${r.width}px`,height:`${r.height}px`})},c=()=>s();se();let u=a("div",{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",width:"320px",padding:"16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.4 system-ui, sans-serif",border:"1px solid rgba(99,102,241,0.55)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});u.id=rt;let E=a("span",{width:"9px",height:"9px",borderRadius:"50%",background:"#34d399",display:"inline-block",flex:"0 0 auto"});E.className="sntedi-dot";let h=a("div",{display:"flex",alignItems:"center",gap:"8px",fontWeight:"700",fontSize:"14px",marginBottom:"6px"});h.append(E,a("span",{},"SentientUI editor"));let O=a("div",{opacity:"0.85",marginBottom:"8px"},"Click any element on the page to adapt it."),C=!1,Z=a("button",y("#374151"),"Pause selecting");Z.onclick=()=>{C=!C,Z.textContent=C?"Resume selecting":"Pause selecting",C?(n.style.display="none",ft(document),d("Selection paused \u2014 browse normally, then resume.")):d("Click any element on the page to adapt it.")};let J=a("div",{fontSize:"12px",marginBottom:"6px",padding:"5px 8px",borderRadius:"8px",background:"rgba(16,185,129,0.14)",border:"1px solid rgba(16,185,129,0.45)",display:"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),K=a("div",{fontSize:"12px",marginBottom:"8px",minHeight:"16px"}),j=r=>a("div",{fontSize:"10px",letterSpacing:"0.08em",textTransform:"uppercase",opacity:"0.55",marginTop:"10px",marginBottom:"2px"},r),I=a("button",y("#6366f1"),"Test different text here"),z=a("button",y("#374151"),"Change style"),N=a("button",y("#374151"),"Track clicks as a goal"),F=a("button",y("#374151"),"Track form submissions as a goal"),it=a("button",y("#374151"),"Track page visits as a goal"),st=a("button",y("#374151"),"Track reading this far as a goal"),w=a("button",y("#374151"),"Set up a funnel"),_=a("button",y("#374151"),"Attach this test to a funnel step"),L=a("button",y("#10b981"),"Turn the funnel on"),U=a("button",y("#374151"),"Move up"),W=a("button",y("#374151"),"Move down"),gt=a("button",y("#6366f1"),"Save this arrangement"),mt=a("button",y("#374151"),"Undo"),zt=a("button",ot(D({},y("transparent")),{opacity:"0.6"}),"Close editor"),q=a("button",y("#10b981"),"Publish now \u2014 go live"),Y=a("button",y("#10b981"),"Start tracking now");for(let r of[I,z,N,U,W])r.disabled=!0;let Nt=[I,z,N,F,U,W];for(let r of Nt)r.style.display="none";gt.style.display="none",mt.style.display="none",q.style.display="none",Y.style.display="none",_.style.display="none",L.style.display="none",u.append(h,O,Z,J,K,j("Content & style"),I,z,j("Track a goal"),N,F,it,st,j("Funnels"),w,_,L,j("Move"),U,W,gt,mt,q,Y,zt),((qt=document.body)!=null?qt:document.documentElement).append(n,o,u);let T=a("div",{marginTop:"10px"});u.append(T);let R=()=>{T.textContent=""},ht=(r,i,l)=>{var A;R();let p={},f={},k={display:"block",width:"100%",marginTop:"4px",padding:"7px 9px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.18)",background:"#1f2937",color:"#fff",font:"13px system-ui, sans-serif"};for(let g of r){let m=a("label",{display:"block",fontSize:"12px",opacity:"0.85",marginTop:"8px"},g.label);if(T.append(m),g.type==="select"){let v=a("select",k);v.setAttribute("data-field",g.key);let H=document.createElement("option");H.value="",H.textContent="\u2014 no change \u2014",v.append(H);for(let et of(A=g.options)!=null?A:[]){let nt=document.createElement("option");nt.value=et,nt.textContent=et,v.append(nt)}p[g.key]=()=>v.value,T.append(v)}else if(g.type==="color"){let v=a("input",ot(D({},k),{padding:"2px",height:"34px"}));v.type="color",v.setAttribute("data-field",g.key);let H=!1;v.addEventListener("input",()=>{H=!0}),p[g.key]=()=>H?v.value:"",T.append(v)}else{let v=a("input",k);v.setAttribute("data-field",g.key),g.value!==void 0&&(v.value=g.value),p[g.key]=()=>v.value,T.append(v)}let x=a("div",{fontSize:"11px",color:"#fca5a5",marginTop:"3px",display:"none"});x.setAttribute("data-feedback",g.key),f[g.key]=x,T.append(x)}let S=(g,m)=>{let x=f[g];x&&(x.textContent=m!=null?m:"",x.style.display=m?"block":"none")},b=a("button",y("#6366f1"),i),$=a("button",ot(D({},y("transparent")),{opacity:"0.6"}),"Cancel");b.onclick=()=>l(Object.fromEntries(Object.entries(p).map(([g,m])=>[g,m()])),S),$.onclick=R,T.append(b,$)},d=(r,i=!0)=>{K.textContent=r,K.style.color=i?"#a7f3d0":"#fca5a5"},X=(r,i)=>{r==="ok"?d(i,!0):d(r==="expired"?"Editor session expired \u2014 reopen it from your dashboard to save this. Your earlier changes are safe.":"\u26A0 Couldn\u2019t save \u2014 try again.",!1)},at=null,$t=r=>{at=r,q.style.display="block",_.style.display="block"};q.onclick=async()=>{if(!at)return;q.disabled=!0,d("Publishing\u2026");let r=await P(e,`/v1/editor/slots/${encodeURIComponent(at)}/publish`,{});q.disabled=!1,r==="ok"?(d("\u2713 Published \u2014 live for new visitors.",!0),q.style.display="none",at=null):d(r==="expired"?"Editor session expired \u2014 reopen it from your dashboard to publish. Your saved draft is safe.":"\u26A0 Couldn\u2019t publish \u2014 try again.",!1)};let B=null,lt=!1,ct=null,dt=null,M=null,Q=null,ut=null,yt=null,tt=!1,Ft=(r,i)=>lt?r?"":`Nothing to swap with ${i} \u2014 it\u2019s at the edge, or that neighbor can\u2019t be targeted reliably.`:"This element can\u2019t be targeted reliably, so it can\u2019t be moved.",Dt=()=>{U.disabled=!lt||!M,W.disabled=!lt||!Q,U.title=U.disabled?Ft(M,"above"):"",W.title=W.disabled?Ft(Q,"below"):""},At=r=>{gt.style.display=r?"block":"none",mt.style.display=r?"block":"none",Dt()},Gt=()=>{if(tt&&t&&ut&&ut.insertBefore(t,yt),tt=!1,ut=null,yt=null,t){let r=Tt(t,document);ct=r.prevEl,dt=r.nextEl,M=r.prevLocator,Q=r.nextLocator}s(),At(!1)},jt=r=>{if(C)return;let i=r.target;if(!i||u.contains(i)||i===n)return;ft(document);let l=i.getBoundingClientRect();Object.assign(n.style,{display:"block",left:`${l.left}px`,top:`${l.top}px`,width:`${l.width}px`,height:`${l.height}px`})},fe=r=>{var l;let i=((l=r.textContent)!=null?l:"").trim().replace(/\s+/g," ");return i?i.length>40?`${i.slice(0,37)}\u2026`:i:r.tagName.toLowerCase()},Ut=r=>{if(C)return;let i=r.target;if(!i||u.contains(i))return;r.preventDefault(),r.stopPropagation(),Gt(),R(),t=i,B=pt(i,document);let l=Et(B,i,document);lt=l,s(),J.style.display="block",J.textContent=`Selected: ${fe(i)}`,d(l?"\u2713 Matches exactly 1 element":"\u26A0 Couldn\u2019t target this element uniquely",l);for(let S of Nt)S.style.display="block";let p=i.childElementCount===0;I.disabled=!l||!p,I.title=l?p?"":"This element contains other elements, so testing text here would replace them. Pick the text itself (e.g. the heading), not its container.":"",z.disabled=!l,N.disabled=!l;let f=i.closest("form");F.style.display=f?"block":"none",F.disabled=!f;let k=Tt(i,document);ct=k.prevEl,dt=k.nextEl,M=k.prevLocator,Q=k.nextLocator,Dt()};I.onclick=()=>{var l,p;if(!t||!B)return;let r=B,i=(p=(l=t.textContent)==null?void 0:l.trim())!=null?p:"";ht([{key:"current",label:"Current wording",value:i},{key:"alt",label:"Alternative wording to test",value:""}],"Save draft",async f=>{let k=f.alt.trim();if(!k){d("\u26A0 Enter alternative wording to test.",!1);return}if(k===f.current.trim()){d("\u26A0 Enter different wording \u2014 the alternative matches the current text.",!1);return}let S=Ct("text",r,t);d("Saving\u2026");let b=await P(e,`/v1/editor/slots/${encodeURIComponent(S)}`,{kind:"arms",target:r,draftConfig:{arms:[{id:"a",displayName:"Original",ops:{text:f.current}},{id:"b",displayName:"Alternative",ops:{text:f.alt}}]}});b==="ok"&&(R(),$t(S)),X(b,"\u2713 Saved as a draft. Click \u201CPublish now\u201D to go live.")})};let bt=null,ge=r=>{bt=r,Y.style.display="block"};Y.onclick=async()=>{if(!bt)return;Y.disabled=!0,d("Activating\u2026");let r=await P(e,`/v1/editor/goals/${encodeURIComponent(bt)}/publish`,{});Y.disabled=!1,r==="ok"?(d("\u2713 Tracking is live \u2014 it counts from your next visitor.",!0),Y.style.display="none",bt=null):d(r==="expired"?"Editor session expired \u2014 reopen it from your dashboard to activate. Your saved goal is safe.":"\u26A0 Couldn\u2019t activate \u2014 try again.",!1)};let _t=(r,i)=>`${Lt(r)||"goal"}-${ie(i)}`.slice(0,128),xt=async(r,i)=>{d("Saving\u2026");let l=await P(e,`/v1/editor/goals/${encodeURIComponent(r)}`,i);l==="ok"&&ge(r),X(l,"\u2713 Goal saved. Click \u201CStart tracking now\u201D to go live.")};N.onclick=()=>{var i;if(!t||!B)return;let r=_t(((i=t.textContent)!=null?i:"").trim()||"element-clicked",JSON.stringify(B));xt(r,{event:"click",locator:B})},F.onclick=()=>{var p,f;let r=t==null?void 0:t.closest("form");if(!r)return;let i=pt(r,document),l=(f=(p=r.getAttribute("id"))!=null?p:r.getAttribute("name"))!=null?f:"form-submitted";xt(_t(l,JSON.stringify(i)),{event:"form_submit",locator:i})},it.onclick=()=>{let r=window.location.pathname||"/",i=Lt(r)?`reached-${Lt(r)}`:"page-visited";xt(_t(i,r),{event:"url_reached",urlPattern:r})};let Rt=[{label:"25% \u2014 skimmed the top",value:.25},{label:"50% \u2014 read halfway",value:.5},{label:"75% \u2014 read most of the page",value:.75},{label:"90% \u2014 read to the end",value:.9}];st.onclick=()=>{ht([{key:"depth",label:"Counts once a visitor reads",type:"select",options:Rt.map(r=>r.label)}],"Track it",r=>{var p;let i=(p=Rt.find(f=>f.label===r.depth))!=null?p:Rt[2],l=Math.round(i.value*100);xt(`read-${l}pct`,{event:"scroll_depth",threshold:i.value}),R()})};let vt=null,me=r=>{vt=r,L.style.display="block"};L.onclick=async()=>{if(!vt)return;L.disabled=!0,d("Turning on\u2026");let r=await P(e,`/v1/editor/funnels/${encodeURIComponent(vt)}/publish`,{});L.disabled=!1,r==="ok"?(d("\u2713 Funnel is on \u2014 the drop-off view fills in as visitors move through it.",!0),L.style.display="none",vt=null):d(r==="expired"?"Editor session expired \u2014 reopen it from your dashboard to turn the funnel on. Your draft is safe.":"\u26A0 Couldn\u2019t turn the funnel on \u2014 try again.",!1)},w.onclick=async()=>{var g;d("Loading your goals\u2026");let r=await Ht(e,"/v1/editor/goals"),i=(g=r==null?void 0:r.goals)!=null?g:[];if(i.length<2){d("Track at least 2 goals first \u2014 a funnel is a sequence of them (e.g. \u201Cviewed pricing\u201D \u2192 \u201Csigned up\u201D).",!1);return}d("Pick the steps in order \u2014 first click = first step."),R();let l=[],p=a("label",{display:"block",fontSize:"12px",opacity:"0.85",marginTop:"8px"},"Funnel name"),f=a("input",{display:"block",width:"100%",marginTop:"4px",padding:"7px 9px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.18)",background:"#1f2937",color:"#fff",font:"13px system-ui, sans-serif"});T.append(p,f);let k=a("div",{fontSize:"11px",opacity:"0.7",marginTop:"6px"},"Steps (click in journey order):");T.append(k);let S=new Map,b=()=>{var m,x;for(let[v,H]of S){let et=l.indexOf(v),nt=(x=(m=i.find(ye=>ye.goal_id===v))==null?void 0:m.display_name)!=null?x:v;H.textContent=et===-1?nt:`${et+1}. ${nt}`,H.style.background=et===-1?"#374151":"#6366f1"}};for(let m of i){let x=a("button",ot(D({},y("#374151")),{textAlign:"left"}));S.set(m.goal_id,x),x.onclick=()=>{l=ee(l,m.goal_id),b()},T.append(x)}b();let $=a("button",y("#6366f1"),"Save funnel"),A=a("button",ot(D({},y("transparent")),{opacity:"0.6"}),"Cancel");A.onclick=R,$.onclick=async()=>{let m=ne(f.value,l);if(!m.ok){d(`\u26A0 ${m.error}`,!1);return}d("Saving\u2026");let x=await P(e,`/v1/editor/funnels/${encodeURIComponent(m.funnelId)}`,m.body);x==="ok"&&(R(),me(m.funnelId)),X(x,"\u2713 Funnel saved as a draft. Click \u201CTurn the funnel on\u201D to start measuring.")},T.append($,A)},_.onclick=async()=>{var k,S;let r=at;if(!r)return;d("Loading funnels\u2026");let i=await Ht(e,"/v1/editor/funnels"),l=(k=i==null?void 0:i.funnels)!=null?k:[];if(l.length===0){d("No funnels yet \u2014 click \u201CSet up a funnel\u201D first.",!1);return}let p=await Ht(e,"/v1/editor/goals"),f=new Map(((S=p==null?void 0:p.goals)!=null?S:[]).map(b=>[b.goal_id,b.display_name]));ht([{key:"funnel",label:"Funnel",type:"select",options:l.map(b=>It(b))},{key:"step",label:"Which step does this element serve?",type:"select",options:Mt(l[0],f).map(b=>b.label)}],"Attach",async b=>{var m;let $=(m=l.find(x=>It(x)===b.funnel))!=null?m:l[0],A=Mt($,f).findIndex(x=>x.label===b.step);d("Attaching\u2026");let g=await P(e,`/v1/editor/funnels/${encodeURIComponent($.funnel_id)}/assign`,{slotId:r,stepIndex:A>=0?A:null});g==="ok"&&R(),X(g,`\u2713 Attached \u2014 this test now works toward \u201C${$.display_name}\u201D.`)})},z.onclick=()=>{if(!t||!B)return;let r=B;ht([{key:"color",label:"Text colour",type:"color"},{key:"background",label:"Background colour",type:"color"},{key:"fontSize",label:"Font size (e.g. 20px)"},{key:"fontWeight",label:"Font weight (e.g. 700)"},{key:"fontFamily",label:Ot.length?`Font (this site has: ${Ot.slice(0,3).join(", ")})`:"Font (e.g. Georgia, serif)"},{key:"borderRadius",label:"Corner radius (e.g. 8px)"},{key:"textAlign",label:"Alignment",type:"select",options:["left","center","right","justify"]}],"Save draft",async(i,l)=>{var $;let{style:p,errors:f}=de(i),k=!1;for(let A of le)l(A,($=f[A])!=null?$:null),f[A]&&(k=!0);if(k){d("\u26A0 Fix the highlighted field(s).",!1);return}if(Object.keys(p).length===0){d("\u26A0 Enter at least one style change.",!1);return}let S=Ct("style",r,t);d("Saving\u2026");let b=await P(e,`/v1/editor/slots/${encodeURIComponent(S)}`,{kind:"arms",target:r,draftConfig:{arms:[{id:"a",displayName:"Current look",ops:{}},{id:"b",displayName:"New look",ops:{style:p}}]}});b==="ok"&&(R(),$t(S)),X(b,"\u2713 Saved as a draft. Click \u201CPublish now\u201D to go live.")})};let Wt=r=>{if(!t)return;let i=t.parentElement;if(!i)return;tt||(ut=i,yt=t.nextSibling,tt=!0),r==="up"&&ct?i.insertBefore(t,ct):r==="down"&&dt&&i.insertBefore(t,dt.nextSibling);let l=Tt(t,document);ct=l.prevEl,dt=l.nextEl,M=l.prevLocator,Q=l.nextLocator;try{t.scrollIntoView({block:"nearest",behavior:"smooth"})}catch(p){}s(),At(!0),d("Previewing the new position \u2014 keep moving, save, or undo.")};U.onclick=()=>Wt("up"),W.onclick=()=>Wt("down"),mt.onclick=()=>{Gt(),d("Move undone \u2014 back to the original position.")},gt.onclick=async()=>{if(!t||!B||!tt||!lt)return;let r=M?"moveAfter":"moveBefore",i=M!=null?M:Q;if(!i){d("\u26A0 Couldn\u2019t anchor the new position \u2014 nudge it next to a section with an id.",!1);return}let l=Ct("move",B,t);d("Saving\u2026");let p=await P(e,`/v1/editor/slots/${encodeURIComponent(l)}`,{kind:"arms",target:B,draftConfig:{arms:[{id:"a",ops:{}},{id:"b",ops:{[r]:i}}]}});p==="ok"&&(tt=!1,ut=null,yt=null,At(!1),$t(l)),X(p,"\u2713 Saved as a draft. Click \u201CPublish now\u201D to go live.")};let he=()=>{var r;document.removeEventListener("mousemove",jt,!0),document.removeEventListener("click",Ut,!0),window.removeEventListener("scroll",c,!0),window.removeEventListener("resize",c),ft(document),n.remove(),o.remove(),u.remove(),window.__sentientEditor=null,(r=document.querySelector("meta[data-sentient-editor]"))==null||r.remove(),wt()};zt.onclick=he,document.addEventListener("mousemove",jt,!0),document.addEventListener("click",Ut,!0),window.addEventListener("scroll",c,!0),window.addEventListener("resize",c)}function y(e){return{display:"block",width:"100%",marginTop:"8px",padding:"8px 10px",borderRadius:"8px",border:"none",background:e,color:"#fff",font:"13px system-ui, sans-serif",cursor:"pointer",textAlign:"left"}}var pe="sentient-preview-bar";async function Ve(e,t){var O,C,Z,J,K,j,I,z,N,F,it,st;let n=null;try{let w=await fetch(`${e.apiBase}/v1/editor/slots`,{headers:{authorization:`Bearer ${e.token}`}});w.ok&&(n=(C=((O=(await w.json()).slots)!=null?O:[]).find(L=>L.slot_id===t&&L.kind==="arms"))!=null?C:null)}catch(w){}let o=a("div",{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",borderRadius:"12px",maxWidth:"90vw",flexWrap:"wrap",background:"#111827",color:"#fff",font:"13px system-ui, sans-serif",border:"1px solid rgba(99,102,241,0.55)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});o.id=pe;let s=a("button",{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"12px system-ui, sans-serif",cursor:"pointer",opacity:"0.7"},"Exit preview");s.onclick=()=>{wt();let w=new URL(location.href);for(let _ of["sentient_editor","sentient_preview","sentient_arm"])w.searchParams.delete(_);location.assign(w.toString())};let c=(j=(K=(Z=n==null?void 0:n.draft_config)==null?void 0:Z.arms)!=null?K:(J=n==null?void 0:n.published_config)==null?void 0:J.arms)!=null?j:[];if(!n||c.length===0){o.append(a("span",{},"Couldn\u2019t load this preview \u2014 reopen it from your dashboard."),s),((I=document.body)!=null?I:document.documentElement).append(o);return}let u=new URLSearchParams(location.search).get("sentient_arm"),E=(N=(z=c.find(w=>w.id===u))!=null?z:c[1])!=null?N:c[0];o.append(a("span",{fontWeight:"700"},`Previewing: ${(F=n.display_name)!=null?F:n.slot_id}`));let h=n.target&&typeof n.target=="object"?V(n.target,document):null;if(!h)o.append(a("span",{opacity:"0.85"},"\u2014 we couldn\u2019t find this component on this page. It may live on another page, or the page changed."));else{te(h,E.ops,`preview-${n.slot_id}`,document);try{h.scrollIntoView({block:"center"})}catch(w){}for(let w of c){let _=a("button",{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.3)",cursor:"pointer",background:w.id===E.id?"#6366f1":"transparent",color:"#fff",font:"12px system-ui, sans-serif"},(it=w.displayName)!=null?it:w.id);_.onclick=()=>{let L=new URL(location.href);L.searchParams.set("sentient_arm",w.id),location.assign(L.toString())},o.append(_)}}o.append(s),((st=document.body)!=null?st:document.documentElement).append(o)}async function Ze(){if(typeof document=="undefined")return;let e=Fe();if(!e)return;let t=await De(e);if(!t.ok){t.unauthorized?(wt(),re(ze)):re(Ne);return}let n=new URLSearchParams(location.search).get("sentient_preview");if(n){document.getElementById(pe)||await Ve(e,n);return}if(document.getElementById(rt))return;ue(e);let o=await Ge(e);ae(o,document)}Ze();return Le(Je);})();
|
|
24
|
+
`,((t=document.head)!=null?t:document.documentElement).appendChild(e)}function ae(e){var o,s;de(),(o=document.getElementById(Rt))==null||o.remove();let t=a("div",{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",display:"flex",gap:"10px",alignItems:"flex-start",cursor:"pointer"});t.id=Rt;let n=a("span",{width:"9px",height:"9px",marginTop:"4px",borderRadius:"50%",background:"#f59e0b",flex:"0 0 auto"});t.append(n,a("div",{},e)),((s=document.body)!=null?s:document.documentElement).appendChild(t),t.addEventListener("click",()=>t.remove()),setTimeout(()=>t.remove(),1e4)}function qe(){let e=window.__sentientEditor;return e&&typeof e.token=="string"&&typeof e.apiBase=="string"?e:null}async function Ye(e){try{let t=await fetch(`${e.apiBase}/v1/editor/verify`,{headers:{authorization:`Bearer ${e.token}`}});if(t.status===401)return{ok:!1,unauthorized:!0};if(!t.ok)return{ok:!1,unauthorized:!1};let n=(await t.json()).projectId;return n?{ok:!0,projectId:n}:{ok:!1,unauthorized:!1}}catch(t){return{ok:!1,unauthorized:!1}}}async function O(e,t,n){try{let o=await fetch(`${e.apiBase}${t}`,{method:"POST",headers:{authorization:`Bearer ${e.token}`,"content-type":"application/json"},body:JSON.stringify(n)});return o.ok?"ok":o.status===401?"expired":"error"}catch(o){return"error"}}async function Ve(e,t,n){try{let o=await fetch(`${e.apiBase}${t}`,{method:"POST",headers:{authorization:`Bearer ${e.token}`,"content-type":"application/json"},body:JSON.stringify(n)}),s=await o.json().catch(()=>null);return o.ok?{r:"ok",data:s}:{r:o.status===401?"expired":"error",data:s}}catch(o){return{r:"error",data:null}}}var Nt=[];async function Je(e){try{let t=await fetch(`${e.apiBase}/v1/editor/targets`,{headers:{authorization:`Bearer ${e.token}`}});if(!t.ok)return[];let n=await t.json();return Nt=Array.isArray(n.fonts)?n.fonts.filter(o=>typeof o=="string"):[],Array.isArray(n.targets)?n.targets:[]}catch(t){return[]}}async function $t(e,t){try{let n=await fetch(`${e.apiBase}${t}`,{headers:{authorization:`Bearer ${e.token}`}});return n.ok?await n.json():null}catch(n){return null}}function yt(e=document){for(let t of Array.from(e.querySelectorAll(`.${zt}`)))t.remove()}function ce(e,t=document){var o;yt(t);let n=0;for(let s of e){if(n>=Ge)break;let d=et(s.locator,t);if(!d)continue;let f=d.getBoundingClientRect(),v=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${f.left}px`,top:`${f.top}px`,width:`${f.width}px`,height:`${f.height}px`,border:"2px dashed #10b981",background:"rgba(16,185,129,0.08)"});v.className=zt;let m=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${f.left}px`,top:`${Math.max(0,f.top-20)}px`,padding:"2px 6px",borderRadius:"4px",background:"#10b981",color:"#fff",font:"11px system-ui, sans-serif",whiteSpace:"nowrap"},s.label);m.className=zt,((o=t.body)!=null?o:t.documentElement).append(v,m),n+=1}}function _t(e,t){let n=e.previousElementSibling,o=e.nextElementSibling,s=n?mt(n,t):null,d=o?mt(o,t):null;return{prevEl:n,nextEl:o,prevLocator:n&&s&&Ct(s,n,t)?s:null,nextLocator:o&&d&&Ct(d,o,t)?d:null}}var ue=["color","background","fontSize","fontWeight","borderRadius","textAlign","fontFamily"],Xe=/^(0|\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|pt))$/i,Ze=new Set(["left","center","right","justify","start","end"]),Ke=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,Qe=/^(rgb|rgba|hsl|hsla)\(/i;function tn(e){return Ke.test(e)||Qe.test(e)}function pe(e,t){switch(e){case"fontSize":case"borderRadius":return Xe.test(t)?null:"Add a unit, e.g. 20px or 1.5rem.";case"fontWeight":return/^(normal|bold|bolder|lighter)$/i.test(t)||/^\d{1,4}$/.test(t)&&+t>=1&&+t<=1e3?null:"Use 100\u2013900, or normal/bold.";case"textAlign":return Ze.has(t.toLowerCase())?null:"Choose left, center, right, or justify.";case"color":case"background":return tn(t)?null:"Enter a colour, e.g. #1a1a1a.";case"fontFamily":{let n=t.split(",").map(o=>o.trim().replace(/^['"]|['"]$/g,""));return t.length<=120&&n.length>=1&&n.length<=5&&n.every(o=>/^[A-Za-z0-9][A-Za-z0-9 -]*$/.test(o))?null:"Use a font name, e.g. Georgia, serif."}default:return null}}function fe(e){let t={},n={};for(let o of ue){let s=e[o];if(typeof s!="string")continue;let d=s.trim();if(d==="")continue;if(!Bt(d)){n[o]="That value isn\u2019t allowed.";continue}let f=pe(o,d);if(f){n[o]=f;continue}t[o]=d}return{style:t,errors:n}}function a(e,t,n){let o=document.createElement(e);return Object.assign(o.style,t),n!==void 0&&(o.textContent=n),o}function ge(e){var Vt;let t=null,n=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #6366f1",background:"rgba(99,102,241,0.12)",display:"none"});n.id=De;let o=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #10b981",background:"rgba(16,185,129,0.10)",borderRadius:"4px",display:"none"});o.id=je;let s=()=>{if(!t||!t.isConnected){o.style.display="none";return}let r=t.getBoundingClientRect();Object.assign(o.style,{display:"block",left:`${r.left-2}px`,top:`${r.top-2}px`,width:`${r.width}px`,height:`${r.height}px`})},d=()=>s();de();let f=a("div",{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",width:"320px",padding:"16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.4 system-ui, sans-serif",border:"1px solid rgba(99,102,241,0.55)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});f.id=st;let v=a("span",{width:"9px",height:"9px",borderRadius:"50%",background:"#34d399",display:"inline-block",flex:"0 0 auto"});v.className="sntedi-dot";let m=a("div",{display:"flex",alignItems:"center",gap:"8px",fontWeight:"700",fontSize:"14px",marginBottom:"6px"});m.append(v,a("span",{},"SentientUI editor"));let z=a("div",{opacity:"0.85",marginBottom:"8px"},"Click any element on the page to adapt it."),B=!1,G=a("button",h("#374151"),"Pause selecting");G.onclick=()=>{B=!B,G.textContent=B?"Resume selecting":"Pause selecting",B?(n.style.display="none",yt(document),c("Selection paused \u2014 browse normally, then resume.")):c("Click any element on the page to adapt it.")};let I=a("div",{fontSize:"12px",marginBottom:"6px",padding:"5px 8px",borderRadius:"8px",background:"rgba(16,185,129,0.14)",border:"1px solid rgba(16,185,129,0.45)",display:"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),_=a("div",{fontSize:"12px",marginBottom:"8px",minHeight:"16px"}),M=r=>a("div",{fontSize:"10px",letterSpacing:"0.08em",textTransform:"uppercase",opacity:"0.55",marginTop:"10px",marginBottom:"2px"},r),L=a("button",h("#6366f1"),"Test different text here"),P=a("button",h("#374151"),"Change style"),H=a("button",h("#374151"),"Try a different arrangement"),U=a("button",h("#374151"),"Track clicks as a goal"),W=a("button",h("#374151"),"Track form submissions as a goal"),at=a("button",h("#374151"),"Track page visits as a goal"),S=a("button",h("#374151"),"Track reading this far as a goal"),q=a("button",h("#374151"),"Set up a funnel"),N=a("button",h("#374151"),"Attach this test to a funnel step"),X=a("button",h("#10b981"),"Turn the funnel on"),Z=a("button",h("#374151"),"Move up"),K=a("button",h("#374151"),"Move down"),bt=a("button",h("#6366f1"),"Save this arrangement"),xt=a("button",h("#374151"),"Undo"),Ft=a("button",V(F({},h("transparent")),{opacity:"0.6"}),"Close editor"),Q=a("button",h("#10b981"),"Publish now \u2014 go live"),tt=a("button",h("#10b981"),"Start tracking now");for(let r of[L,P,H,U,Z,K])r.disabled=!0;let Dt=[L,P,H,U,W,Z,K];for(let r of Dt)r.style.display="none";bt.style.display="none",xt.style.display="none",Q.style.display="none",tt.style.display="none",N.style.display="none",X.style.display="none",f.append(m,z,G,I,_,M("Content & style"),L,P,H,M("Track a goal"),U,W,at,S,M("Funnels"),q,N,X,M("Move"),Z,K,bt,xt,Q,tt,Ft),((Vt=document.body)!=null?Vt:document.documentElement).append(n,o,f);let $=a("div",{marginTop:"10px"});f.append($);let R=()=>{$.textContent=""},lt=(r,i,l)=>{var T;R();let p={},u={},g={display:"block",width:"100%",marginTop:"4px",padding:"7px 9px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.18)",background:"#1f2937",color:"#fff",font:"13px system-ui, sans-serif"};for(let b of r){let x=a("label",{display:"block",fontSize:"12px",opacity:"0.85",marginTop:"8px"},b.label);if($.append(x),b.type==="select"){let E=a("select",g);E.setAttribute("data-field",b.key);let j=document.createElement("option");j.value="",j.textContent="\u2014 no change \u2014",E.append(j);for(let rt of(T=b.options)!=null?T:[]){let it=document.createElement("option");it.value=rt,it.textContent=rt,E.append(it)}p[b.key]=()=>E.value,$.append(E)}else if(b.type==="color"){let E=a("input",V(F({},g),{padding:"2px",height:"34px"}));E.type="color",E.setAttribute("data-field",b.key);let j=!1;E.addEventListener("input",()=>{j=!0}),p[b.key]=()=>j?E.value:"",$.append(E)}else{let E=a("input",g);E.setAttribute("data-field",b.key),b.value!==void 0&&(E.value=b.value),p[b.key]=()=>E.value,$.append(E)}let k=a("div",{fontSize:"11px",color:"#fca5a5",marginTop:"3px",display:"none"});k.setAttribute("data-feedback",b.key),u[b.key]=k,$.append(k)}let w=(b,x)=>{let k=u[b];k&&(k.textContent=x!=null?x:"",k.style.display=x?"block":"none")},y=a("button",h("#6366f1"),i),C=a("button",V(F({},h("transparent")),{opacity:"0.6"}),"Cancel");y.onclick=()=>l(Object.fromEntries(Object.entries(p).map(([b,x])=>[b,x()])),w),C.onclick=R,$.append(y,C)},c=(r,i=!0)=>{_.textContent=r,_.style.color=i?"#a7f3d0":"#fca5a5"},Y=(r,i)=>{r==="ok"?c(i,!0):c(r==="expired"?"Editor session expired \u2014 reopen it from your dashboard to save this. Your earlier changes are safe.":"\u26A0 Couldn\u2019t save \u2014 try again.",!1)},dt=null,vt=r=>{dt=r,Q.style.display="block",N.style.display="block"};Q.onclick=async()=>{if(!dt)return;Q.disabled=!0,c("Publishing\u2026");let r=await O(e,`/v1/editor/slots/${encodeURIComponent(dt)}/publish`,{});Q.disabled=!1,r==="ok"?(c("\u2713 Published \u2014 live for new visitors.",!0),Q.style.display="none",dt=null):c(r==="expired"?"Editor session expired \u2014 reopen it from your dashboard to publish. Your saved draft is safe.":"\u26A0 Couldn\u2019t publish \u2014 try again.",!1)};let A=null,ct=!1,ut=null,pt=null,D=null,nt=null,ft=null,kt=null,ot=!1,jt=(r,i)=>ct?r?"":`Nothing to swap with ${i} \u2014 it\u2019s at the edge, or that neighbor can\u2019t be targeted reliably.`:"This element can\u2019t be targeted reliably, so it can\u2019t be moved.",Gt=()=>{Z.disabled=!ct||!D,K.disabled=!ct||!nt,Z.title=Z.disabled?jt(D,"above"):"",K.title=K.disabled?jt(nt,"below"):""},It=r=>{bt.style.display=r?"block":"none",xt.style.display=r?"block":"none",Gt()},Ut=()=>{if(ot&&t&&ft&&ft.insertBefore(t,kt),ot=!1,ft=null,kt=null,t){let r=_t(t,document);ut=r.prevEl,pt=r.nextEl,D=r.prevLocator,nt=r.nextLocator}s(),It(!1)},Wt=r=>{if(B)return;let i=r.target;if(!i||f.contains(i)||i===n)return;yt(document);let l=i.getBoundingClientRect();Object.assign(n.style,{display:"block",left:`${l.left}px`,top:`${l.top}px`,width:`${l.width}px`,height:`${l.height}px`})},he=r=>{var l;let i=((l=r.textContent)!=null?l:"").trim().replace(/\s+/g," ");return i?i.length>40?`${i.slice(0,37)}\u2026`:i:r.tagName.toLowerCase()},qt=r=>{if(B)return;let i=r.target;if(!i||f.contains(i))return;r.preventDefault(),r.stopPropagation(),Ut(),R(),t=i,A=mt(i,document);let l=Ct(A,i,document);ct=l,s(),I.style.display="block",I.textContent=`Selected: ${he(i)}`,c(l?"\u2713 Matches exactly 1 element":"\u26A0 Couldn\u2019t target this element uniquely",l);for(let w of Dt)w.style.display="block";let p=i.childElementCount===0;L.disabled=!l||!p,L.title=l?p?"":"This element contains other elements, so testing text here would replace them. Pick the text itself (e.g. the heading), not its container.":"",P.disabled=!l,H.disabled=!l,U.disabled=!l;let u=i.closest("form");W.style.display=u?"block":"none",W.disabled=!u;let g=_t(i,document);ut=g.prevEl,pt=g.nextEl,D=g.prevLocator,nt=g.nextLocator,Gt()};L.onclick=()=>{var l,p;if(!t||!A)return;let r=A,i=(p=(l=t.textContent)==null?void 0:l.trim())!=null?p:"";lt([{key:"current",label:"Current wording",value:i},{key:"alt",label:"Alternative wording to test",value:""}],"Save draft",async u=>{let g=u.alt.trim();if(!g){c("\u26A0 Enter alternative wording to test.",!1);return}if(g===u.current.trim()){c("\u26A0 Enter different wording \u2014 the alternative matches the current text.",!1);return}let w=ht("text",r,t);c("Saving\u2026");let y=await O(e,`/v1/editor/slots/${encodeURIComponent(w)}`,{kind:"arms",target:r,draftConfig:{arms:[{id:"a",displayName:"Original",ops:{text:u.current}},{id:"b",displayName:"Alternative",ops:{text:u.alt}}]}});y==="ok"&&(R(),vt(w)),Y(y,"\u2713 Saved as a draft. Click \u201CPublish now\u201D to go live.")})};let gt=null,ye=(r,i,l)=>{lt(r.fields.map(p=>{var u;return{key:p.id,label:p.kind==="href"?`${p.label} (link \u2014 required)`:p.label,value:(u=p.default)!=null?u:""}}),"Save draft",async p=>{var y,C,T;c("Saving\u2026");let u=await Ve(e,`/v1/editor/arrangements/${encodeURIComponent(r.id)}/instantiate`,{fields:p});if(u.r!=="ok"||!((y=u.data)!=null&&y.blocks)){u.r==="expired"?Y("expired",""):c(`\u26A0 ${(T=(C=u.data)==null?void 0:C.reason)!=null?T:"Couldn\u2019t build the arrangement \u2014 check the fields."}`,!1);return}let g=ht("arrange",i,l),w=await O(e,`/v1/editor/slots/${encodeURIComponent(g)}`,{kind:"arms",target:i,draftConfig:{arms:[{id:"original",displayName:"Your page today"},{id:r.id,displayName:r.name,blocks:u.data.blocks}],baseline:"original"}});w==="ok"&&(R(),vt(g)),Y(w,"\u2713 Saved as a draft \u2014 it will test against this section as it is today. Click \u201CPublish now\u201D to go live.")})};H.onclick=async()=>{var p;if(!t||!A)return;let r=A,i=t;if(R(),c("Loading arrangements\u2026"),!gt){let u=await $t(e,"/v1/editor/arrangements");gt=(p=u==null?void 0:u.arrangements)!=null?p:null}if(!gt||gt.length===0){c("\u26A0 Couldn\u2019t load the arrangements \u2014 try again.",!1);return}c("Pick an arrangement to test against this section.");for(let u of gt){let g=a("button",V(F({},h("#374151")),{textAlign:"left"}));g.append(a("div",{fontWeight:"600"},u.name),a("div",{fontSize:"11px",opacity:"0.7"},u.description)),g.onclick=()=>ye(u,r,i),$.append(g)}let l=a("button",V(F({},h("transparent")),{opacity:"0.6"}),"Cancel");l.onclick=R,$.append(l)};let Et=null,be=r=>{Et=r,tt.style.display="block"};tt.onclick=async()=>{if(!Et)return;tt.disabled=!0,c("Activating\u2026");let r=await O(e,`/v1/editor/goals/${encodeURIComponent(Et)}/publish`,{});tt.disabled=!1,r==="ok"?(c("\u2713 Tracking is live \u2014 it counts from your next visitor.",!0),tt.style.display="none",Et=null):c(r==="expired"?"Editor session expired \u2014 reopen it from your dashboard to activate. Your saved goal is safe.":"\u26A0 Couldn\u2019t activate \u2014 try again.",!1)};let Mt=(r,i)=>`${At(r)||"goal"}-${le(i)}`.slice(0,128),wt=async(r,i)=>{c("Saving\u2026");let l=await O(e,`/v1/editor/goals/${encodeURIComponent(r)}`,i);l==="ok"&&be(r),Y(l,"\u2713 Goal saved. Click \u201CStart tracking now\u201D to go live.")};U.onclick=()=>{var i;if(!t||!A)return;let r=Mt(((i=t.textContent)!=null?i:"").trim()||"element-clicked",JSON.stringify(A));wt(r,{event:"click",locator:A})},W.onclick=()=>{var p,u;let r=t==null?void 0:t.closest("form");if(!r)return;let i=mt(r,document),l=(u=(p=r.getAttribute("id"))!=null?p:r.getAttribute("name"))!=null?u:"form-submitted";wt(Mt(l,JSON.stringify(i)),{event:"form_submit",locator:i})},at.onclick=()=>{let r=window.location.pathname||"/",i=At(r)?`reached-${At(r)}`:"page-visited";wt(Mt(i,r),{event:"url_reached",urlPattern:r})};let Pt=[{label:"25% \u2014 skimmed the top",value:.25},{label:"50% \u2014 read halfway",value:.5},{label:"75% \u2014 read most of the page",value:.75},{label:"90% \u2014 read to the end",value:.9}];S.onclick=()=>{lt([{key:"depth",label:"Counts once a visitor reads",type:"select",options:Pt.map(r=>r.label)}],"Track it",r=>{var p;let i=(p=Pt.find(u=>u.label===r.depth))!=null?p:Pt[2],l=Math.round(i.value*100);wt(`read-${l}pct`,{event:"scroll_depth",threshold:i.value}),R()})};let St=null,xe=r=>{St=r,X.style.display="block"};X.onclick=async()=>{if(!St)return;X.disabled=!0,c("Turning on\u2026");let r=await O(e,`/v1/editor/funnels/${encodeURIComponent(St)}/publish`,{});X.disabled=!1,r==="ok"?(c("\u2713 Funnel is on \u2014 the drop-off view fills in as visitors move through it.",!0),X.style.display="none",St=null):c(r==="expired"?"Editor session expired \u2014 reopen it from your dashboard to turn the funnel on. Your draft is safe.":"\u26A0 Couldn\u2019t turn the funnel on \u2014 try again.",!1)},q.onclick=async()=>{var b;c("Loading your goals\u2026");let r=await $t(e,"/v1/editor/goals"),i=(b=r==null?void 0:r.goals)!=null?b:[];if(i.length<2){c("Track at least 2 goals first \u2014 a funnel is a sequence of them (e.g. \u201Cviewed pricing\u201D \u2192 \u201Csigned up\u201D).",!1);return}c("Pick the steps in order \u2014 first click = first step."),R();let l=[],p=a("label",{display:"block",fontSize:"12px",opacity:"0.85",marginTop:"8px"},"Funnel name"),u=a("input",{display:"block",width:"100%",marginTop:"4px",padding:"7px 9px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.18)",background:"#1f2937",color:"#fff",font:"13px system-ui, sans-serif"});$.append(p,u);let g=a("div",{fontSize:"11px",opacity:"0.7",marginTop:"6px"},"Steps (click in journey order):");$.append(g);let w=new Map,y=()=>{var x,k;for(let[E,j]of w){let rt=l.indexOf(E),it=(k=(x=i.find(ke=>ke.goal_id===E))==null?void 0:x.display_name)!=null?k:E;j.textContent=rt===-1?it:`${rt+1}. ${it}`,j.style.background=rt===-1?"#374151":"#6366f1"}};for(let x of i){let k=a("button",V(F({},h("#374151")),{textAlign:"left"}));w.set(x.goal_id,k),k.onclick=()=>{l=re(l,x.goal_id),y()},$.append(k)}y();let C=a("button",h("#6366f1"),"Save funnel"),T=a("button",V(F({},h("transparent")),{opacity:"0.6"}),"Cancel");T.onclick=R,C.onclick=async()=>{let x=ie(u.value,l);if(!x.ok){c(`\u26A0 ${x.error}`,!1);return}c("Saving\u2026");let k=await O(e,`/v1/editor/funnels/${encodeURIComponent(x.funnelId)}`,x.body);k==="ok"&&(R(),xe(x.funnelId)),Y(k,"\u2713 Funnel saved as a draft. Click \u201CTurn the funnel on\u201D to start measuring.")},$.append(C,T)},N.onclick=async()=>{var g,w;let r=dt;if(!r)return;c("Loading funnels\u2026");let i=await $t(e,"/v1/editor/funnels"),l=(g=i==null?void 0:i.funnels)!=null?g:[];if(l.length===0){c("No funnels yet \u2014 click \u201CSet up a funnel\u201D first.",!1);return}let p=await $t(e,"/v1/editor/goals"),u=new Map(((w=p==null?void 0:p.goals)!=null?w:[]).map(y=>[y.goal_id,y.display_name]));lt([{key:"funnel",label:"Funnel",type:"select",options:l.map(y=>Ht(y))},{key:"step",label:"Which step does this element serve?",type:"select",options:Ot(l[0],u).map(y=>y.label)}],"Attach",async y=>{var x;let C=(x=l.find(k=>Ht(k)===y.funnel))!=null?x:l[0],T=Ot(C,u).findIndex(k=>k.label===y.step);c("Attaching\u2026");let b=await O(e,`/v1/editor/funnels/${encodeURIComponent(C.funnel_id)}/assign`,{slotId:r,stepIndex:T>=0?T:null});b==="ok"&&R(),Y(b,`\u2713 Attached \u2014 this test now works toward \u201C${C.display_name}\u201D.`)})},P.onclick=()=>{if(!t||!A)return;let r=A;lt([{key:"color",label:"Text colour",type:"color"},{key:"background",label:"Background colour",type:"color"},{key:"fontSize",label:"Font size (e.g. 20px)"},{key:"fontWeight",label:"Font weight (e.g. 700)"},{key:"fontFamily",label:Nt.length?`Font (this site has: ${Nt.slice(0,3).join(", ")})`:"Font (e.g. Georgia, serif)"},{key:"borderRadius",label:"Corner radius (e.g. 8px)"},{key:"textAlign",label:"Alignment",type:"select",options:["left","center","right","justify"]}],"Save draft",async(i,l)=>{var C;let{style:p,errors:u}=fe(i),g=!1;for(let T of ue)l(T,(C=u[T])!=null?C:null),u[T]&&(g=!0);if(g){c("\u26A0 Fix the highlighted field(s).",!1);return}if(Object.keys(p).length===0){c("\u26A0 Enter at least one style change.",!1);return}let w=ht("style",r,t);c("Saving\u2026");let y=await O(e,`/v1/editor/slots/${encodeURIComponent(w)}`,{kind:"arms",target:r,draftConfig:{arms:[{id:"a",displayName:"Current look",ops:{}},{id:"b",displayName:"New look",ops:{style:p}}]}});y==="ok"&&(R(),vt(w)),Y(y,"\u2713 Saved as a draft. Click \u201CPublish now\u201D to go live.")})};let Yt=r=>{if(!t)return;let i=t.parentElement;if(!i)return;ot||(ft=i,kt=t.nextSibling,ot=!0),r==="up"&&ut?i.insertBefore(t,ut):r==="down"&&pt&&i.insertBefore(t,pt.nextSibling);let l=_t(t,document);ut=l.prevEl,pt=l.nextEl,D=l.prevLocator,nt=l.nextLocator;try{t.scrollIntoView({block:"nearest",behavior:"smooth"})}catch(p){}s(),It(!0),c("Previewing the new position \u2014 keep moving, save, or undo.")};Z.onclick=()=>Yt("up"),K.onclick=()=>Yt("down"),xt.onclick=()=>{Ut(),c("Move undone \u2014 back to the original position.")},bt.onclick=async()=>{if(!t||!A||!ot||!ct)return;let r=D?"moveAfter":"moveBefore",i=D!=null?D:nt;if(!i){c("\u26A0 Couldn\u2019t anchor the new position \u2014 nudge it next to a section with an id.",!1);return}let l=ht("move",A,t);c("Saving\u2026");let p=await O(e,`/v1/editor/slots/${encodeURIComponent(l)}`,{kind:"arms",target:A,draftConfig:{arms:[{id:"a",ops:{}},{id:"b",ops:{[r]:i}}]}});p==="ok"&&(ot=!1,ft=null,kt=null,It(!1),vt(l)),Y(p,"\u2713 Saved as a draft. Click \u201CPublish now\u201D to go live.")};let ve=()=>{var r;document.removeEventListener("mousemove",Wt,!0),document.removeEventListener("click",qt,!0),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d),yt(document),n.remove(),o.remove(),f.remove(),window.__sentientEditor=null,(r=document.querySelector("meta[data-sentient-editor]"))==null||r.remove(),Tt()};Ft.onclick=ve,document.addEventListener("mousemove",Wt,!0),document.addEventListener("click",qt,!0),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d)}function h(e){return{display:"block",width:"100%",marginTop:"8px",padding:"8px 10px",borderRadius:"8px",border:"none",background:e,color:"#fff",font:"13px system-ui, sans-serif",cursor:"pointer",textAlign:"left"}}var me="sentient-preview-bar";async function en(e,t){var z,B,G,I,_,M,L,P,H,U,W,at;let n=null;try{let S=await fetch(`${e.apiBase}/v1/editor/slots`,{headers:{authorization:`Bearer ${e.token}`}});S.ok&&(n=(B=((z=(await S.json()).slots)!=null?z:[]).find(N=>N.slot_id===t&&N.kind==="arms"))!=null?B:null)}catch(S){}let o=a("div",{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",borderRadius:"12px",maxWidth:"90vw",flexWrap:"wrap",background:"#111827",color:"#fff",font:"13px system-ui, sans-serif",border:"1px solid rgba(99,102,241,0.55)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});o.id=me;let s=a("button",{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"12px system-ui, sans-serif",cursor:"pointer",opacity:"0.7"},"Exit preview");s.onclick=()=>{Tt();let S=new URL(location.href);for(let q of["sentient_editor","sentient_preview","sentient_arm"])S.searchParams.delete(q);location.assign(S.toString())};let d=(M=(_=(G=n==null?void 0:n.draft_config)==null?void 0:G.arms)!=null?_:(I=n==null?void 0:n.published_config)==null?void 0:I.arms)!=null?M:[];if(!n||d.length===0){o.append(a("span",{},"Couldn\u2019t load this preview \u2014 reopen it from your dashboard."),s),((L=document.body)!=null?L:document.documentElement).append(o);return}let f=new URLSearchParams(location.search).get("sentient_arm"),v=(H=(P=d.find(S=>S.id===f))!=null?P:d[1])!=null?H:d[0];o.append(a("span",{fontWeight:"700"},`Previewing: ${(U=n.display_name)!=null?U:n.slot_id}`));let m=n.target&&typeof n.target=="object"?et(n.target,document):null;if(!m)o.append(a("span",{opacity:"0.85"},"\u2014 we couldn\u2019t find this component on this page. It may live on another page, or the page changed."));else{oe(m,v.ops,`preview-${n.slot_id}`,document);try{m.scrollIntoView({block:"center"})}catch(S){}for(let S of d){let q=a("button",{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.3)",cursor:"pointer",background:S.id===v.id?"#6366f1":"transparent",color:"#fff",font:"12px system-ui, sans-serif"},(W=S.displayName)!=null?W:S.id);q.onclick=()=>{let N=new URL(location.href);N.searchParams.set("sentient_arm",S.id),location.assign(N.toString())},o.append(q)}}o.append(s),((at=document.body)!=null?at:document.documentElement).append(o)}async function nn(){if(typeof document=="undefined")return;let e=qe();if(!e)return;let t=await Ye(e);if(!t.ok){t.unauthorized?(Tt(),ae(Ue)):ae(We);return}let n=new URLSearchParams(location.search).get("sentient_preview");if(n){document.getElementById(me)||await en(e,n);return}if(document.getElementById(st))return;ge(e);let o=Qt(document);o&&O(e,"/v1/editor/palette",o);let s=await Je(e);ce(s,document)}nn();return $e(on);})();
|
package/dist/snippet.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var SentientSnippet=(()=>{var ke=Object.defineProperty;var fn=Object.getOwnPropertyDescriptor;var gn=Object.getOwnPropertyNames,nt=Object.getOwnPropertySymbols;var ot=Object.prototype.hasOwnProperty,mn=Object.prototype.propertyIsEnumerable;var rt=(e,t,n)=>t in e?ke(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pe=(e,t)=>{for(var n in t||(t={}))ot.call(t,n)&&rt(e,n,t[n]);if(nt)for(var n of nt(t))mn.call(t,n)&&rt(e,n,t[n]);return e};var it=(e,t)=>()=>(e&&(t=e(e=0)),t);var st=(e,t)=>{for(var n in t)ke(e,n,{get:t[n],enumerable:!0})},hn=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of gn(t))!ot.call(e,a)&&a!==n&&ke(e,a,{get:()=>t[a],enumerable:!(r=fn(t,a))||r.enumerable});return e};var yn=e=>hn(ke({},"__esModule",{value:!0}),e);var vn,bn,wn,at,Sn,An,lt,R,be,Ie=it(()=>{"use strict";vn=Object.defineProperty,bn=Object.defineProperties,wn=Object.getOwnPropertyDescriptors,at=Object.getOwnPropertySymbols,Sn=Object.prototype.hasOwnProperty,An=Object.prototype.propertyIsEnumerable,lt=(e,t,n)=>t in e?vn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,R=(e,t)=>{for(var n in t||(t={}))Sn.call(t,n)&<(e,n,t[n]);if(at)for(var n of at(t))An.call(t,n)&<(e,n,t[n]);return e},be=(e,t)=>bn(e,wn(t))});var yt={};st(yt,{LOCAL_ENGINE_AVAILABLE:()=>Cn,createLocalEngine:()=>On});function On(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var Cn,vt=it(()=>{"use strict";Cn=!1});var Dr={};st(Dr,{applyPersonaAttributes:()=>Ne,applyRegistrySlots:()=>Be,applySlotArms:()=>Ke,applySlotAttributes:()=>je,parseEditorToken:()=>an,parsePersonaPreview:()=>cn,parsePreview:()=>ln,parseSnippetConfig:()=>$e,reapply:()=>tt,run:()=>dn,version:()=>Ze});Ie();var xn=["buyer","researcher","deal_seeker","browser"];var En={buyer:"Buyer",researcher:"Researcher",deal_seeker:"Deal seeker",browser:"Browser",unknown:"Unknown"};function Ce(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function ct(e){if(e.length===0)return null;let t={};for(let n of e.split("|")){let r=n.indexOf("=");if(r<=0||r!==n.lastIndexOf("=")||r===n.length-1)return null;let a=n.slice(0,r);if(a in t)return null;t[a]=n.slice(r+1)}return t}function We(e){var t,n,r;if(e.arms)return typeof e.baseline=="string"?e.baseline:(t=e.arms[0])!=null?t:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return Ce(e.baseline);if(typeof e.baseline=="string")return e.baseline;let a={};for(let[o,l]of Object.entries((n=e.dims)!=null?n:{}))a[o]=(r=l[0])!=null?r:"";return Ce(a)}function ut(e,t){var n,r;return e.dims!=null?(r=(n=ct(t))!=null?n:ct(We(e)))!=null?r:{}:t}function fe(e){return e>=.3?e<.7?"medium":"high":"low"}var Nr=xn.map(e=>({key:e,displayName:En[e]}));var kn=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function dt(e){return In(e)!==null}function In(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=kn.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function pt(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function ft(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(a){}let r=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(n){return"direct"}}function gt(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function mt(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function Ve(e){return R(R(R({id:e.id},e.arms?{arms:[...e.arms]}:{}),e.dims?{dims:Object.fromEntries(Object.entries(e.dims).map(([t,n])=>[t,[...n]]))}:{}),e.baseline!==void 0?{baseline:e.baseline}:{})}function Fe(e){let t=Ve(e);return ut(t,We(t))}function ht(e){return typeof e=="string"?e:Ce(e)}Ie();function wt(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}try{if(typeof crypto!="undefined"&&typeof crypto.getRandomValues=="function"){let e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t="";for(let n=0;n<16;n++)t+=e[n].toString(16).padStart(2,"0"),(n===3||n===5||n===7||n===9)&&(t+="-");return t}}catch(e){}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function St(e){return e?`_${e.slice(0,12)}`:""}var _n="_snt_uid",Rn=365,Tn="_snt_uid";function Ln(){return wt()}function Pn(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function Dn(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function Mn(e){try{return localStorage.getItem(e)}catch(t){return null}}function $n(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function Nn(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function jn(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function Kn(e){try{sessionStorage.removeItem(e)}catch(t){}}function Bn(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function Un(e){try{localStorage.removeItem(e)}catch(t){}}function Gn(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var qn={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function At(e){var t,n,r,a,o,l;if(typeof window=="undefined")return qn;let d=St(e==null?void 0:e.apiKey),i=(t=e==null?void 0:e.cookieName)!=null?t:`${_n}${d}`,s=`${Tn}${d}`,c=((n=e==null?void 0:e.cookieTTLDays)!=null?n:Rn)*24*60*60,u=h=>h&&h.length>0?h:null,m=(l=(o=(a=(r=u(Pn(i)))!=null?r:u(Mn(s)))!=null?a:u(Nn(s)))!=null?o:u(e==null?void 0:e.ssrSessionId))!=null?l:Ln();Dn(i,m,c);let v=$n(s,m),I=Bn(i),C=v?!1:jn(s,m),k=!v&&!I&&!C;return{getSessionId:()=>m,isEphemeral:()=>k,destroy:()=>{m=null,Gn(i),Un(s),Kn(s)}}}function Re(e){return Math.min(6e4,1e3*2**Math.min(e,6))}function xt(e){if(e.ok===!0)return"delivered";let{status:t}=e;return typeof t!="number"?"retry":t>=200&&t<300?"delivered":t>=400&&t<500&&t!==429?"dropped":"retry"}function Et(e,t){try{let n=localStorage.getItem(e);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?(localStorage.removeItem(e),r.slice(-t)):[]}catch(n){return[]}}function Te(e,t,n){try{let r=(()=>{try{let o=localStorage.getItem(n);if(!o)return[];let l=JSON.parse(o);return Array.isArray(l)?l:[]}catch(o){return[]}})(),a=new Map;for(let o of r)a.set(o.id,o);for(let o of e)a.set(o.id,o);localStorage.setItem(n,JSON.stringify([...a.values()].slice(-t)))}catch(r){}}function kt(e,t){try{let n=localStorage.getItem(t);if(!n)return;let r=JSON.parse(n);if(!Array.isArray(r))return;let a=new Set(e),o=r.filter(l=>!a.has(l.id));if(o.length===r.length)return;o.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(o))}catch(n){}}var zn=500,Wn=56*1024;function It(e){return`_snt_retry_${e.slice(0,12)}`}var Vn={push:()=>{},flush:()=>{},destroy:()=>{}};function Fn(e){var t,n,r;if(typeof window=="undefined")return Vn;let a=(t=e.flushIntervalMs)!=null?t:5e3,o=(n=e.maxBatchSize)!=null?n:20,l=(r=e.maxRetrySize)!=null?r:100,d=e.ingestUrl,i=e.apiKey,s=It(i),c=[],u=new Set,m=[],v=g=>{for(let E of g)I.delete(E),!u.has(E)&&(u.add(E),m.push(E));for(;m.length>zn;){let E=m.shift();E&&u.delete(E)}kt(g,s)},I=new Set,C=g=>{u.has(g.id)||I.has(g.id)||(I.add(g.id),c.push(g))},k=g=>{for(let E of g)u.has(E.id)||(I.add(E.id),c.push(E))},h=Et(s,l);for(let g of h)C(g);let f=0,x=0,O=(g,E=!0)=>{if(g.length===0)return;let te=JSON.stringify(g),q=g.map(H=>H.id),ne;try{ne=fetch(d,{method:"POST",keepalive:!0,body:te,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}})}catch(H){Te(g,l,s),k(g),x++,f=Date.now()+Re(x);return}let ce=H=>{if(xt(H)!=="retry"){if(!H.ok&&E){let ue=g.filter(F=>F.eventType!=="pageview");if(ue.length>0&&ue.length<g.length){v(g.filter(F=>F.eventType==="pageview").map(F=>F.id)),O(ue,!1);return}}v(q),x=0,f=0;return}Te(g,l,s),k(g),x++,f=Date.now()+Re(x)};ne instanceof Promise?ne.then(ce).catch(()=>{Te(g,l,s),k(g),x++,f=Date.now()+Re(x)}):ce(ne)},G=typeof TextEncoder!="undefined"?new TextEncoder:null,b=g=>G?G.encode(g).length:g.length,P=g=>{let E=[],te=2;for(let q of g){let ne=b(JSON.stringify(q))+1;if(E.length>0&&te+ne>Wn||E.length>=o)break;E.push(q),te+=ne}return E},$=()=>{try{if(Date.now()<f)return;for(;c.length>0&&!(Date.now()<f);){let g=c.filter(te=>!u.has(te.id));if(c.length=0,g.length===0)break;let E=P(g);if(E.length===0)break;E.length<g.length&&c.push(...g.slice(E.length)),O(E)}}catch(g){}},D=!0,S=null;S=setInterval(()=>{D&&$()},a);let A=()=>{document.visibilityState==="hidden"&&$()},w=()=>{$()};return document.addEventListener("visibilitychange",A),window.addEventListener("pagehide",w),{push(g){C(g),c.length>=o&&$()},flush:$,destroy(){D=!1,S!==null&&(clearInterval(S),S=null),document.removeEventListener("visibilitychange",A),window.removeEventListener("pagehide",w),$()}}}var Jn=200;function Ct(e){return`_snt_goal_retry_${e.slice(0,12)}`}var Hn={send:()=>{},flush:()=>{},destroy:()=>{}};function Yn(e){var t,n,r;if(typeof window=="undefined")return Hn;let a=(t=e.flushIntervalMs)!=null?t:5e3,o=(n=e.maxRetrySize)!=null?n:100,l=(r=e.maxPerFlush)!=null?r:5,d=Ct(e.apiKey),i=[],s=new Set,c=new Set,u=[],m=0,v=0,I=!1,C=b=>{for(s.delete(b.id),c.has(b.id)||(c.add(b.id),u.push(b.id));u.length>Jn;){let P=u.shift();P&&c.delete(P)}kt([b.id],d)},k=b=>{Te([b],o,d),!c.has(b.id)&&!s.has(b.id)&&(s.add(b.id),i.push(b)),v++,m=Date.now()+Re(v)},h=b=>{let P;try{P=fetch(e.url,{method:"POST",keepalive:!0,body:b.body,headers:e.headers})}catch(D){k(b);return}let $=D=>{var S;let A=xt(D);if(A==="retry"){k(b);return}A==="dropped"&&((S=e.onDrop)==null||S.call(e,b,D.status)),C(b),v=0,m=0};P instanceof Promise?P.then($).catch(()=>k(b)):$(P)},f=()=>{try{if(I||Date.now()<m)return;let b=0;for(;i.length>0&&b<l&&!(Date.now()<m);){let P=i.shift();s.delete(P.id),!c.has(P.id)&&(b++,h(P))}}catch(b){}};for(let b of Et(d,o))s.has(b.id)||(s.add(b.id),i.push(b));let x=setInterval(f,a),O=()=>{document.visibilityState==="hidden"&&f()},G=()=>f();return document.addEventListener("visibilitychange",O),window.addEventListener("pagehide",G),{send(b){if(!I&&!(c.has(b.id)||s.has(b.id))){if(Date.now()<m){s.add(b.id),i.push(b);return}h(b)}},flush:f,destroy(){clearInterval(x),document.removeEventListener("visibilitychange",O),window.removeEventListener("pagehide",G),f(),I=!0}}}var Xn=1800*1e3;function Oe(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Zn(e=Xn,t){let n=new Map,r=`_snt_asgn${St(t)}_`,a=(i,s)=>`${r}${encodeURIComponent(i)}:${encodeURIComponent(s)}`,o=i=>{let s=i.slice(r.length),c=s.indexOf(":");if(c<0)return null;try{return{componentId:decodeURIComponent(s.slice(0,c)),segment:decodeURIComponent(s.slice(c+1))}}catch(u){return null}},l=()=>{try{let i=[];for(let s=0;s<localStorage.length;s++){let c=localStorage.key(s);c!=null&&c.startsWith(r)&&i.push(c)}return i}catch(i){return[]}},d=i=>i.assignedAt+(i.ttlMs&&i.ttlMs>0?i.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let i of l())try{let s=localStorage.getItem(i);if(!s)continue;let c=JSON.parse(s);if(d(c)){localStorage.removeItem(i);continue}let u=o(i);if(!u)continue;n.set(Oe(u.componentId,u.segment),c)}catch(s){}})(),{get(i,s){let c=n.get(Oe(i,s));return c?d(c)?(n.delete(Oe(i,s)),null):c:null},set(i,s,c){let u=Oe(i,s);n.set(u,c);try{localStorage.setItem(a(i,s),JSON.stringify(c))}catch(m){}},invalidate(i){let s=`${encodeURIComponent(i)}:`;for(let c of[...n.keys()])c.startsWith(s)&&n.delete(c);for(let c of l()){let u=o(c);if((u==null?void 0:u.componentId)===i)try{localStorage.removeItem(c)}catch(m){}}},clear(){n.clear();for(let i of l())try{localStorage.removeItem(i)}catch(s){}}}}var Pe="_snt_snap:",Qn=["low","medium","high"];function De(e){try{let t=localStorage.getItem(Pe+e);if(!t)return null;let n=JSON.parse(t);return!n||typeof n!="object"||n.v!==1||typeof n.persona!="string"||typeof n.band!="string"||!Qn.includes(n.band)||typeof n.slots!="object"||n.slots===null||Array.isArray(n.slots)||!(n.layoutOrder===null||Array.isArray(n.layoutOrder))||typeof n.savedAt!="number"||!(n.slotConfig===void 0||typeof n.slotConfig=="object"&&n.slotConfig!==null&&!Array.isArray(n.slotConfig))?null:n}catch(t){return null}}function Se(e,t){try{localStorage.setItem(Pe+e,JSON.stringify(t))}catch(n){}}var He="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",Ot="[sentient] Local mode \u2014 decisions are simulated on-device and nothing is sent over the network. Add an API key to learn from real traffic.",bt=!1,_e=!1;function er(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function tr(e){var t;let n=At({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),r=(t=n.getSessionId())!=null?t:"local",a=er(),o=Promise.resolve().then(()=>(vt(),yt)).then(i=>{let s=i;return s.LOCAL_ENGINE_AVAILABLE?(bt||(bt=!0,console.info(Ot)),s):(_e||(_e=!0,console.error(He)),null)}).catch(()=>(_e||(_e=!0,console.error(He)),null)),l=null;function d(i){let s=document.documentElement;s.dataset.sentientPersona===void 0&&(s.dataset.sentientPersona=i.persona,s.dataset.sentientConfidence=fe(i.confidence))}return{isLocal:!0,async decide(i){var s,c,u;let m=await o;if(!m)return null;let v=m.createLocalEngine({sessionId:r,forcedPersona:a}).decide(i);return l=be(R({},v),{layoutOrder:(c=(s=v.layoutOrder)!=null?s:l==null?void 0:l.layoutOrder)!=null?c:null,slots:R(R({},(u=l==null?void 0:l.slots)!=null?u:{}),v.slots)}),Se(e.apiKey||"local",{v:1,persona:l.persona,band:fe(l.confidence),slots:l.slots,layoutOrder:l.layoutOrder,savedAt:Date.now()}),d(v),v},getSlotResult(i){var s,c,u;return(u=(c=l==null?void 0:l.slots[i])!=null?c:(s=e.initialSlots)==null?void 0:s[i])!=null?u:null},getPersona(){return l?{persona:l.persona,confidence:l.confidence,band:fe(l.confidence)}:null},async assign(i,s){var c;let u=await o;return!u||!s||s.length===0?s!=null&&s[0]?{variantId:s[0],assignmentTtlMs:0}:null:{variantId:(c=u.createLocalEngine({sessionId:r,forcedPersona:a}).decide({components:[{id:i,variantIds:s}]}).assignments[i])!=null?c:s[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function Ae(e,t,n,r){let a=[];{let o=!1,l=[],d=()=>{if(o)return;let i=Date.now();for(l.push(i);l.length>0&&i-l[0]>500;)l.shift();l.length>=3&&(o=!0,e("rage_click"))};t.addEventListener("click",d),a.push(()=>t.removeEventListener("click",d))}{let o=!1,l=d=>{if(o||!(d.target instanceof Node)||!t.contains(d.target)&&t!==d.target)return;o=!0;let i=typeof window!="undefined"?window.getSelection():null,s=i?i.toString().length:0;e("text_copy",{selectionLength:s})};document.addEventListener("copy",l),a.push(()=>document.removeEventListener("copy",l))}{let o=!1,l=!1,d=null,i=()=>{d!==null&&(clearTimeout(d),d=null)},s=()=>{o||!l||(i(),d=setTimeout(()=>{!o&&l&&(o=!0,e("scroll_hesitation"))},3e3))},c=()=>{i(),s()},u=v=>{for(let I of v)l=I.intersectionRatio>.3,l?s():i()},m=new IntersectionObserver(u,{threshold:[.3]});m.observe(t),window.addEventListener("scroll",c,{passive:!0}),a.push(()=>{m.disconnect(),window.removeEventListener("scroll",c),i()})}if((r==null?void 0:r.tabLoss)!==!1){let o=!1,l=n!=null?n:Date.now(),d=()=>{if(o||document.visibilityState!=="hidden")return;let i=Date.now()-l;i<15e3&&(o=!0,e("tab_loss",{timeOnPage:i}))};document.addEventListener("visibilitychange",d),a.push(()=>document.removeEventListener("visibilitychange",d))}return()=>{for(let o of a)o()}}var _t="https://api.sentient-ui.com/v1/events",W=new Map,Rt=null;function nr(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}function Je(){return wt()}function Le(){var e;if(typeof window!="undefined")return((e=window.location)==null?void 0:e.pathname)||void 0}function rr(e){if(typeof MessageChannel=="function"){let t=new MessageChannel;t.port1.onmessage=()=>{e.clear(),t.port1.close(),t.port2.close()},t.port2.postMessage(0)}else setTimeout(()=>e.clear(),0)}var Tt=new Set;function or(e,t,n){let r=typeof window=="undefined"?null:window.history;if(!r)return()=>{};let a=!1,o,l=()=>{if(a)return;let s=Le();!s||s===o||(o=s,e.track({projectId:t,componentId:"__page__",eventType:"pageview",payload:{}}),n(`${t}:${s}`))},d=[];for(let s of["pushState","replaceState"]){let c=r[s],u=function(...m){let v=c.apply(this,m);return l(),v};r[s]=u,d.push([s,c,u])}window.addEventListener("popstate",l);let i=Le();return i&&Tt.has(`${t}:${i}`)?o=i:l(),()=>{if(!a){a=!0,window.removeEventListener("popstate",l);for(let[s,c,u]of d)r[s]===u&&(r[s]=c)}}}var we={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}};function ir(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,r]of t)n.startsWith("utm_")&&(e[n]=r);return e}catch(e){return{}}}function Lt(e){return e.replace(/\/events\/?$/,"")}function ge(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(e=>e==="1"||e==="yes")}function Ye(e){var t;if(typeof window=="undefined")return;let n=e!=null?e:Rt;if(!n){console.warn("[sentient] grantConsent() called before init()");return}let r=W.get(n);if(!r){console.warn("[sentient] grantConsent() called before init()");return}let{config:a,upgrade:o}=r;if(!o||a.respectDoNotTrack!==!1&&ge())return;let l=Me(be(R({},a),{consent:!0}));o(l);let d=(t=W.get(n))==null?void 0:t.dispose;W.set(n,{config:be(R({},a),{consent:!0}),upgrade:null,dispose:d})}function sr(e){var t;let n=e.preConsentBehavior==="statistical_winner",r=Lt((t=e.ingestUrl)!=null?t:_t),a={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(i,s,c){if(!n)return null;try{let u=new URLSearchParams({componentId:i});for(let v of s!=null?s:[])u.append("variantIds[]",v);let m=await fetch(`${r}/winner?${u.toString()}`,{headers:a});return m.ok?{variantId:(await m.json()).variantId,assignmentTtlMs:0}:s!=null&&s[0]?{variantId:s[0],assignmentTtlMs:0}:null}catch(u){return s!=null&&s[0]?{variantId:s[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},l={track:i=>o.track(i),goal:((i,s,c,u)=>o.goal(i,s,c,u)),componentGoal:(i,s,c)=>o.componentGoal(i,s,c),identify:i=>o.identify(i),getAssignment:(i,s)=>o.getAssignment(i,s),assign:(i,s,c,u)=>o.assign(i,s,c,u),decide:i=>o.decide(i),getSlotResult:i=>o.getSlotResult(i),getPersona:()=>o.getPersona(),fetchWeights:()=>o.fetchWeights(),getGraph:()=>o.getGraph(),dispose:()=>o.dispose(),destroy:()=>o.destroy()};function d(i){o=i}return{proxy:l,setInner:d}}function Me(e){var t,n,r,a,o,l,d,i,s;if(typeof window=="undefined")return we;Rt=e.apiKey;let c=W.get(e.apiKey||"local");if(c!=null&&c.dispose)try{c.dispose()}catch(p){}let u=e.respectDoNotTrack!==!1&&ge(),m=e.consent===!1||u,v=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!v&&e.localMode!==!1)return m?(W.set(e.apiKey||"local",{config:e,upgrade:null}),we):(W.set(e.apiKey||"local",{config:e,upgrade:null}),tr(e));if(m){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return e.preConsentBehavior==="statistical_winner"&&console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),W.set(e.apiKey,{config:e,upgrade:null}),we;let{proxy:p,setInner:y}=sr(e);return W.set(e.apiKey,{config:e,upgrade:u?null:y}),p}if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),we;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),we;let I=(t=e.ingestUrl)!=null?t:_t,C=Date.now(),k=At({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),h=Zn(void 0,e.apiKey),f=Fn({ingestUrl:I,apiKey:e.apiKey}),x=Lt(I),O={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},G=Yn({url:`${x}/goals`,apiKey:e.apiKey,headers:O,onDrop:(p,y)=>{e.debug&&console.warn(`[sentient] goal dropped (HTTP ${y}) \u2014 this will not be retried. `+(y===400?"The session was not found: call init() and let the session upsert complete before firing goals.":y===401||y===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),p)}}),b=pt((n=navigator.userAgent)!=null?n:""),P=typeof window!="undefined"?window.location.origin:void 0,$=ft((r=document.referrer)!=null?r:"",P),D=(a=e.sessionSegment)!=null?a:`${b}:${$}`,S=new Map,A=new Map,w=null,g=p=>{for(let y of p)A.has(y.id)||A.set(y.id,Fe(y))};if(e.initialSlots)for(let[p,y]of Object.entries(e.initialSlots))A.set(p,y);let E=De(e.apiKey);if(E)for(let[p,y]of Object.entries(E.slots))A.has(p)||A.set(p,y);let te={low:.15,medium:.5,high:.85};if(e.initialPersona)w=R({},e.initialPersona);else{let p=document.documentElement.dataset;p.sentientPersona?w={persona:p.sentientPersona,confidence:(l=te[(o=p.sentientConfidence)!=null?o:"low"])!=null?l:.15}:E&&(w={persona:E.persona,confidence:(d=te[E.band])!=null?d:.15})}if(e.initialAssignments)for(let[p,y]of Object.entries(e.initialAssignments))h.set(p,D,{variantId:y,assignedAt:Date.now(),segment:D,confidence:1});let q=Promise.resolve(),ne=k.getSessionId();if(ne){let p=gt((i=document.referrer)!=null?i:""),y=R(R(R({sessionId:ne,deviceClass:b,trafficSource:$,referrerDomain:p,utmParams:ir(),timeOfDay:mt(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:k.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||dt((s=navigator.userAgent)!=null?s:"")},e.userId?{userId:e.userId}:{}),e.persona?{persona:e.persona}:{}),e.country?{country:e.country}:{});try{q=fetch(`${x}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(y),headers:O}).then(_=>{_.status===402&&console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing")}).catch(()=>{})}catch(_){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:f});let ce=new Set,H=null,ue=!1,F={goal(p,y={},_=1,Y=0){var X,N,Z,z,K,re;let B=k.getSessionId();if(!B)return;let U=nr(y)?y:{metadata:y},Q=`${p}\0${(X=U.externalId)!=null?X:""}\0${(N=U.stepIndex)!=null?N:Y}\0${(Z=U.weight)!=null?Z:_}`;if(ce.has(Q)){e.debug&&console.log(`[sentient] goal("${p}") already recorded for this action \u2014 not sent twice`);return}ce.add(Q),ce.size===1&&rr(ce);let ye=Je(),T={sessionId:B,name:p,metadata:(z=U.metadata)!=null?z:{},weight:(K=U.weight)!=null?K:_,stepIndex:(re=U.stepIndex)!=null?re:Y,goalId:ye,value:U.value,currency:U.currency,externalId:U.externalId};e.debug&&console.log("[sentient] goal",T);let de={id:ye,body:JSON.stringify(T)};q.then(()=>G.send(de))},componentGoal(p,y,_){var Y,X,N;let Z=k.getSessionId();if(!Z)return;let z=h.get(p,D),K=z?null:(Y=A.get(p))!=null?Y:null;if(!z&&K===null){e.debug&&console.warn(`[sentient] componentGoal("${p}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let re=z?z.variantId:ht(K),B={id:Je(),sessionId:Z,projectId:e.apiKey,componentId:p,variantId:re,eventType:"goal_achieved",goalType:y,payload:R({reward:(X=_==null?void 0:_.reward)!=null?X:1,goalValue:_==null?void 0:_.value,currency:_==null?void 0:_.currency},(N=_==null?void 0:_.metadata)!=null?N:{}),timestamp:Date.now(),timeInSession:Date.now()-C,path:Le()};e.debug&&console.log("[sentient] componentGoal",B),q.then(()=>f.push(B))},identify(p){let y=k.getSessionId();y&&q.then(()=>{fetch(`${x}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:y,userId:p,ephemeral:k.isEphemeral()}),headers:O}).catch(()=>{})})},track(p){let y=k.getSessionId();if(!y)return;let _=be(R({path:Le()},p),{id:Je(),sessionId:y,timestamp:Date.now(),timeInSession:Date.now()-C});e.debug&&console.log("[sentient] track",_),q.then(()=>f.push(_))},getAssignment(p,y){return h.get(p,y)},async assign(p,y,_,Y){let X=k.getSessionId();if(!X)return null;let N=h.get(p,D);if(N&&(y!=null&&y.length||N.content!==void 0)){let K=N.ttlMs&&N.ttlMs>0?Math.max(0,N.assignedAt+N.ttlMs-Date.now()):0;return{variantId:N.variantId,assignmentTtlMs:K,content:N.content}}let Z=S.get(p);if(Z)return Z;let z=(async()=>{await q;try{let K={sessionId:X,componentId:p,variantIds:y};Y!==void 0?K.agentDataByVariant=Y:_!==void 0&&(K.agentData=_);let re=await fetch(`${x}/assign`,{method:"POST",body:JSON.stringify(K),headers:O});if(!re.ok)return null;let B=await re.json();return h.set(p,D,R({variantId:B.variantId,assignedAt:Date.now(),segment:D,confidence:1,content:B.content},B.assignmentTtlMs&&B.assignmentTtlMs>0?{ttlMs:B.assignmentTtlMs}:{})),B}catch(K){return null}finally{S.delete(p)}})();return S.set(p,z),z},async decide(p){var y,_,Y,X,N,Z,z,K,re;let B=k.getSessionId();if(!B)return null;let U=(y=p.slots)!=null?y:[];await q;try{let Q={sessionId:B};p.sections&&p.sections.length>0&&(Q.sections=p.sections.map(J=>({id:J}))),Q.components=(_=p.components)!=null?_:[],U.length>0&&(Q.slots=U.map(Ve)),p.slotsFrom==="registry"&&(Q.slotsFrom="registry"),p.v&&(Q.v=p.v),e.persona&&(Q.persona=e.persona);let ye=await fetch(`${x}/decide`,{method:"POST",body:JSON.stringify(Q),headers:O});if(!ye.ok)return g(U),null;let T=await ye.json(),de={};for(let J of U)de[J.id]=(X=(Y=T.slots)==null?void 0:Y[J.id])!=null?X:Fe(J);if(T.slots)for(let[J,ve]of Object.entries(T.slots))J in de||(de[J]=ve);for(let[J,ve]of Object.entries(de))A.set(J,ve);let pn=w!=null&&w.persona!=="unknown";T.persona&&!(T.persona==="unknown"&&pn)?w={persona:T.persona,confidence:(N=T.confidence)!=null?N:0}:w||(w={persona:"unknown",confidence:0});for(let[J,ve]of Object.entries((Z=T.assignments)!=null?Z:{}))h.set(J,D,{variantId:ve,assignedAt:Date.now(),segment:D,confidence:1});return Se(e.apiKey,R({v:1,persona:w.persona,band:fe(w.confidence),slots:Object.fromEntries(A),layoutOrder:(z=T.layoutOrder)!=null?z:null,savedAt:Date.now()},T.slotConfig?{slotConfig:T.slotConfig}:{})),R(R(R({layoutOrder:(K=T.layoutOrder)!=null?K:null,assignments:(re=T.assignments)!=null?re:{},slots:de,persona:w.persona,confidence:w.confidence},T.slotConfig?{slotConfig:T.slotConfig}:{}),T.goals?{goals:T.goals}:{}),T.sectionMap?{sectionMap:T.sectionMap}:{})}catch(Q){return g(U),null}},getSlotResult(p){var y;return(y=A.get(p))!=null?y:null},getPersona(){return w?{persona:w.persona,confidence:w.confidence,band:fe(w.confidence)}:null},async fetchWeights(){var p;try{let y=await fetch(`${x}/weights`,{headers:O});return y.ok?(p=(await y.json()).components)!=null?p:[]:[]}catch(y){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var p;H==null||H(),ue=!0,f.destroy(),G.destroy(),((p=W.get(e.apiKey))==null?void 0:p.dispose)===F.dispose&&W.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var p;H==null||H(),ue=!0,f.destroy(),G.destroy(),k.destroy(),((p=W.get(e.apiKey))==null?void 0:p.dispose)===F.dispose&&W.delete(e.apiKey);try{localStorage.removeItem(Pe+e.apiKey),localStorage.removeItem(It(e.apiKey)),localStorage.removeItem(Ct(e.apiKey))}catch(y){}e.debug&&console.log("[sentient] destroyed")}};if(W.set(e.apiKey,{config:e,upgrade:null,dispose:F.dispose}),H=or(F,e.apiKey,p=>{q.then(()=>{ue||Tt.add(p)})}),e.debug){let p=window;p.__sentient&&(p.__sentient.client=F)}return F}var Pt=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],ar=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],lr=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function cr(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function Dt(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,r]of ar)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of lr)if(r.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function Mt(e){var t,n;let r=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:cr(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function $t(e){return Dt(Mt(e)).type}Ie();var jt="section, header, footer, nav, main > div, [data-sentient-section]";function ur(e){var t;return((t=e.parentElement)==null?void 0:t.closest(jt))!=null}function dr(e,t,n,r){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:r})}).catch(()=>{})}catch(a){}}var Nt=()=>{};function Kt(e,t){var n,r,a,o,l,d,i,s,c;let u=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!u||typeof IntersectionObserver=="undefined"||ge()||!t.apiKey)return Nt;let m=((r=t.apiBase)!=null?r:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),v=Array.from(u.querySelectorAll(jt)).filter(S=>!ur(S));if(v.length===0)return Nt;let I=new Map,C=new Map,k=new Map;for(let S of v){let A=S.getAttribute("data-sentient-type"),w=A&&Pt.includes(A)?A:null,g=(o=w!=null?w:(a=t.typeOf)==null?void 0:a.call(t,S))!=null?o:$t(S),E=`nc-${g}`;I.set(S,E),C.set(E,g),w?k.set(E,"markup"):k.has(E)||k.set(E,"auto")}let h=(s=(i=(d=(l=u.defaultView)!=null?l:typeof window!="undefined"?window:void 0)==null?void 0:d.location)==null?void 0:i.pathname)!=null?s:"/";dr(t.apiKey,m,h,[...C.entries()].map(([S,A])=>{var w;return{componentId:S,semanticType:A,source:(w=k.get(S))!=null?w:"auto"}}));let f=new Map,x=S=>{let A=f.get(S);return A||(A={ms:0,scroll:0,enterAt:null,intersecting:!1},f.set(S,A)),A},O=new IntersectionObserver(S=>{for(let A of S){let w=I.get(A.target);if(!w)continue;let g=x(w);A.isIntersecting?(g.intersecting=!0,g.enterAt=Date.now(),A.intersectionRatio>g.scroll&&(g.scroll=A.intersectionRatio)):(g.intersecting=!1,g.enterAt!=null&&(g.ms+=Date.now()-g.enterAt,g.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let S of I.keys())O.observe(S);let G=()=>{let S=Date.now();for(let[A,w]of f)if(w.enterAt!=null&&(w.ms+=S-w.enterAt,w.enterAt=null),!(w.ms<=0)){try{e.track({projectId:t.apiKey,componentId:A,eventType:"dwell",payload:{dwell_time:Math.round(w.ms),scroll_depth:Number(w.scroll.toFixed(2))}})}catch(g){}w.ms=0}},b=()=>{if(u.hidden)G();else{let S=Date.now();for(let A of f.values())A.intersecting&&(A.enterAt=S)}},P=()=>{G();try{O.disconnect()}catch(S){}};u.addEventListener("visibilitychange",b);let $=(c=u.defaultView)!=null?c:typeof window!="undefined"?window:void 0;$==null||$.addEventListener("pagehide",P);let D=[];return t.microSignals&&[...I.entries()].forEach(([S,A],w)=>{D.push(Ae((g,E={})=>{try{e.track({projectId:t.apiKey,componentId:A,eventType:"micro_signal",payload:R({signalType:g},E)})}catch(te){}},S,void 0,{tabLoss:w===0}))}),()=>{G(),u.removeEventListener("visibilitychange",b),$==null||$.removeEventListener("pagehide",P);for(let S of D)S();try{O.disconnect()}catch(S){}}}var pr=["landing","ecommerce","saas","marketplace"];function fr(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t=Object.entries(e);if(t.length<1||t.length>4)return null;let n={};for(let[r,a]of t){if(!Array.isArray(a)||a.length<2||a.length>6||!a.every(o=>typeof o=="string"))return null;n[r]=a}return n}function gr(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function mr(e){try{return e()}catch(t){return}}function $e(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.apiKey!="string"||!t.apiKey.startsWith("pk_"))return null;let n=pr.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[l,d]of Object.entries(t.slots)){if(typeof d!="object"||d===null)continue;let i=d,s=fr(i.dims);if(!s||i.target!==void 0&&typeof i.target!="string")continue;let c=i.arms!==void 0?gr(i.arms):null,u={dims:s};typeof i.target=="string"&&(u.target=i.target),c&&(u.arms=c),r[l]=u}let a={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};typeof t.consent=="boolean"&&(a.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(a.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(a.debug=!0),typeof t.registry=="boolean"&&(a.registry=t.registry),typeof t.editorSrc=="string"&&(a.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(a.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(a.sectionCapture=t.sectionCapture);let o=typeof t.persona=="function"?mr(t.persona):t.persona;return typeof o=="string"&&o.trim()!==""&&(a.persona=o),a}function Bt(e){var n,r,a;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(a=t==null?void 0:t.pathname)!=null?a:""}function hr(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let r=((n=e.textContent)!=null?n:"").trim().toLowerCase(),a=t.text.trim().toLowerCase();if(!(r===a||r.startsWith(a)||a.startsWith(r)))return!1}return!0}function Ut(e,t){return!!(e!=null&&e.urlMatch)&&!Bt(t).includes(e.urlMatch)}var yr=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function se(e,t){var a;if(e.urlMatch&&!Bt(t).includes(e.urlMatch))return null;let n=[];if(e.id){let o=t.getElementById(e.id);n=o?[o]:[]}if(n.length===0&&((a=e.dataAttr)!=null&&a.name)&&yr.test(e.dataAttr.name))try{let o=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${o}"]`))}catch(o){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(o){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!hr(r,e.fingerprint)?null:r}var Gt={color:"color",background:"background",fontSize:"font-size",fontWeight:"font-weight",textAlign:"text-align",padding:"padding",margin:"margin",borderRadius:"border-radius",width:"width",height:"height",maxWidth:"max-width",border:"border",boxShadow:"box-shadow",opacity:"opacity",lineHeight:"line-height",letterSpacing:"letter-spacing",textTransform:"text-transform",gap:"gap",fontFamily:"font-family"},vr=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function qt(e){var t;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;for(let n of e.matchAll(/([A-Za-z-]*)\(/g))if(!vr.test((t=n[1])!=null?t:""))return!1;return!0}var zt=/^https:\/\//i,Wt=new Map,ae=null;function br(e){return e.replace(/["\\]/g,"\\$&")}function wr(e){var t;(!ae||!ae.isConnected)&&(ae=e.querySelector("style[data-sentient-ops]"),ae||(ae=e.createElement("style"),ae.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(ae))),ae.textContent=[...Wt.entries()].map(([n,r])=>`[data-snt-e="${br(n)}"]{${r}}`).join(`
|
|
2
|
-
`)}function Vt(e,t,n,r){var d;let a=!1,o=(d=t.moveBefore)!=null?d:t.moveAfter;if(o){let i=se(o,r);!i||i===e||i.parentElement!==e.parentElement||!e.parentElement?a=!0:t.moveBefore?e.parentElement.insertBefore(e,i):e.parentElement.insertBefore(e,i.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&zt.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&zt.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let l=[];if(t.hidden&&l.push("display:none !important"),t.style)for(let[i,s]of Object.entries(t.style)){let c=Gt[i];c&&typeof s=="string"&&qt(s)&&l.push(`${c}:${s.trim()} !important`)}return l.length>0&&(e.setAttribute("data-snt-e",n),Wt.set(n,l.join(";")),wr(r)),{anchorMiss:a}}function Ne(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function je(e,t,n){var r;for(let[a,o]of Object.entries(t)){let l=e[a];if(!l||typeof l=="string")continue;let d=o.target?Array.from(n.querySelectorAll(o.target)):[n.documentElement];for(let i of d)for(let[s,c]of Object.entries(l))(r=o.dims[s])!=null&&r.includes(c)&&i.setAttribute(`data-${s}`,c)}}function Ke(e,t,n){for(let[r,a]of Object.entries(t)){let o=e[r];if(typeof o!="string"||!a.arms||!a.arms.includes(o))continue;let l=a.target?Array.from(n.querySelectorAll(a.target)):[n.documentElement];for(let d of l)d.setAttribute("data-sentient-arm",o)}}function Be(e,t,n,r){var l,d;let a=(l=r==null?void 0:r.contentAndOps)!=null?l:!0,o=[];for(let[i,s]of Object.entries(t)){if(Ut(s.locator,n))continue;let c;if(s.locator){let m=se(s.locator,n);c=m?[m]:[]}else s.target?c=Array.from(n.querySelectorAll(s.target)):c=[n.documentElement];(s.locator||s.target)&&c.length===0&&o.push(i);let u=e[i];for(let m of c){if(u!==void 0)if(typeof u=="string")m.setAttribute("data-sentient-arm",u),a&&((d=r==null?void 0:r.onApplied)==null||d.call(r,i,u,m));else for(let[v,I]of Object.entries(u))m.setAttribute(`data-${v}`,I);a&&(typeof s.content=="string"&&(m.textContent=s.content),s.ops&&Vt(m,s.ops,i,n).anchorMiss&&!o.includes(i)&&o.push(i))}}return o}var Sr=800;function Ue(e,t,n){let r=[];return n.forEach(({slotId:a,arm:o,el:l},d)=>{r.push(Ae((m,v={})=>{try{e.track({projectId:t,componentId:a,variantId:o,eventType:"micro_signal",payload:pe({signalType:m},v)})}catch(I){}},l,void 0,{tabLoss:d===0}));let i=null,s=0,c=()=>{s=Date.now(),i=setTimeout(()=>{try{e.track({projectId:t,componentId:a,variantId:o,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-s}})}catch(m){}i=null},Sr)},u=()=>{i!==null&&(clearTimeout(i),i=null)};l.addEventListener("mouseenter",c),l.addEventListener("mouseleave",u),r.push(()=>{l.removeEventListener("mouseenter",c),l.removeEventListener("mouseleave",u),i!==null&&clearTimeout(i)})}),()=>{for(let a of r)a()}}function Ar(e){var n,r,a;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(a=t==null?void 0:t.pathname)!=null?a:""}function xr(e,t){if(!e)return!1;if(e==="/")return t==="/";let n=e.endsWith("/")?e.slice(0,-1):e;return t===n||t.startsWith(`${n}/`)}var Ft="_snt_fired_goals";function Er(e){try{let t=e==null?void 0:e.sessionStorage.getItem(Ft);if(!t)return new Set;let n=JSON.parse(t);return Array.isArray(n)?new Set(n.filter(r=>typeof r=="string")):new Set}catch(t){return new Set}}function kr(e,t){try{e==null||e.sessionStorage.setItem(Ft,JSON.stringify([...t]))}catch(n){}}function Jt(e,t,n){var C,k;let r=(C=n.defaultView)!=null?C:typeof window!="undefined"?window:null,a=Er(r),o=h=>{if(!a.has(h.goalId)){a.add(h.goalId),kr(r,a);try{h.slotId?t.componentGoal(h.slotId,h.goalId):t.goal(h.goalId)}catch(f){}}},l=e.filter(h=>h.event==="click"),d=e.filter(h=>h.event==="form_submit"),i=e.filter(h=>h.event==="url_reached"),s=e.filter(h=>h.event==="scroll_depth"),c=(h,f)=>{if(!h.locator)return!1;let x=se(h.locator,n);return!!x&&(x===f||x.contains(f))},u=h=>{let f=h.target;if(!(!f||typeof f.closest!="function"))for(let x of l)c(x,f)&&o(x)},m=h=>{let f=h.target;if(f)for(let x of d)c(x,f)&&o(x)},v=()=>{if(i.length===0)return;let h=Ar(n);for(let f of i)f.urlPattern&&xr(f.urlPattern,h)&&o(f)},I=()=>{var x;let h=n.documentElement,f=h.scrollHeight>0?(h.scrollTop+h.clientHeight)/h.scrollHeight:0;for(let O of s)f>=((x=O.threshold)!=null?x:.75)&&o(O);s.every(O=>a.has(O.goalId))&&n.removeEventListener("scroll",I)};return n.addEventListener("click",u,!0),n.addEventListener("submit",m,!0),(k=n.defaultView)==null||k.addEventListener("popstate",v),v(),s.length>0&&(n.addEventListener("scroll",I,{passive:!0}),I()),{checkUrl:v,teardown:()=>{var h;n.removeEventListener("click",u,!0),n.removeEventListener("submit",m,!0),(h=n.defaultView)==null||h.removeEventListener("popstate",v),s.length>0&&n.removeEventListener("scroll",I)}}}var Ht="__snt_editor_token";function Yt(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(Ht):null}catch(e){return null}}function Xt(e){try{sessionStorage.setItem(Ht,e)}catch(t){}}var Ze="0.16.1",on=5e3,Ir=50,Cr=(()=>{try{if(typeof window=="undefined")return[];let e=window.SentientSnippet;return Array.isArray(e==null?void 0:e.q)?e.q:[]}catch(e){return[]}})(),V=null,M=null,ie={},le=null,ee=null,j=null,oe=null,L=null,Zt=!1,Xe=null,Ge=null,qe=null,xe=!1,ze=!1;function sn(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function me(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function he(e,t){return V?(V.personaAttributes&&L&&Ne(L.persona,L.band,e),je(ie,V.slots,e),Ke(ie,V.slots,e),le?Be(ie,le,e,t):[]):[]}function Or(e,t){var n;if(t.length!==0)try{let r=(n=e.apiBase)!=null?n:"https://api.sentient-ui.com";fetch(`${r}/v1/locator-miss`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify({slots:t})}).catch(()=>{})}catch(r){}}function Ee(){return!!(V&&M&&V.sectionCapture!==!1&&(V.consent!==!1||ze)&&!ge())}function _r(){if(!M||!V||!Ee()||oe)return;let e=[];he(document,{contentAndOps:xe,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),et();try{j==null||j(),j=Ue(M,V.apiKey,e)}catch(t){}}function et(){if(typeof document=="undefined"||!Ee())return;let e;try{if(Ge&&Ge.length>0){let t=new Map;for(let n of Ge){if(n.urlMatch!==window.location.pathname)continue;let r=se(n.locator,document);r&&t.set(r,n.type)}t.size>0&&(e=n=>{var r;return(r=t.get(n))!=null?r:null})}}catch(t){}try{oe=Kt(M,pe({apiKey:V.apiKey,apiBase:V.apiBase,doc:document,microSignals:!0},e?{typeOf:e}:{})),qe=window.location.pathname}catch(t){}}function tt(){try{let e=[];if(j==null||j(),j=null,he(document,{contentAndOps:xe,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),e.length>0&&Ee())try{j=Ue(M,V.apiKey,e)}catch(t){}try{typeof window!="undefined"&&qe!==null&&window.location.pathname!==qe&&Ee()&&(oe==null||oe(),oe=null,et())}catch(t){}}catch(e){}}function Qt(){Xe===null&&(Xe=setTimeout(()=>{Xe=null,tt();try{ee==null||ee.checkUrl()}catch(e){}},Ir))}function en(){if(!(Zt||typeof window=="undefined"||typeof history=="undefined")){Zt=!0;try{let e=t=>{let n=history[t];history[t]=function(r,a,o){let l=n.call(this,r,a,o!=null?o:null);return Qt(),l}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Qt)}catch(e){}}}function Qe(e){let t={};for(let[n,r]of Object.entries(e.slots))t[n]=r.target?document.querySelectorAll(r.target).length:1;return t}function an(e){return new URLSearchParams(e).get("sentient_editor")}function Rr(){try{let t=Array.from(document.getElementsByTagName("script")).find(n=>/snippet(\.global)?\.js/.test(n.src));if(t!=null&&t.src)return t.src.replace(/snippet(\.global)?\.js/,"editor.global.js")}catch(e){}return null}function Tr(e,t){var n,r,a,o;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let i=document.createElement("meta");i.name="referrer",i.content="no-referrer",i.setAttribute("data-sentient-editor",""),((r=document.head)!=null?r:document.documentElement).appendChild(i)}catch(i){}let l=(a=e.editorSrc)!=null?a:Rr();if(!l){nn();return}let d=document.createElement("script");d.src=l,d.async=!0,d.onerror=()=>nn(),((o=document.head)!=null?o:document.documentElement).appendChild(d)}catch(l){}}var tn="sentient-editor-load-notice";function nn(){var e;try{if(typeof document=="undefined"||document.getElementById(tn))return;let t=document.createElement("div");t.id=tn,t.textContent="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.",Object.assign(t.style,{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",cursor:"pointer"}),t.addEventListener("click",()=>t.remove()),((e=document.body)!=null?e:document.documentElement).appendChild(t),setTimeout(()=>t.remove(),1e4)}catch(t){}}function ln(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let a=r.indexOf(":"),o=a===-1?"":r.slice(0,a),l=a===-1?"":r.slice(a+1);if(!(!o||!l))if(l.includes("=")){let d={};for(let i of l.split(",")){let[s,c]=i.split("=");s&&c&&(d[s]=c)}Object.keys(d).length&&(n[o]=d)}else n[o]=l}return Object.keys(n).length?n:null}function cn(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var rn="sentient-persona-preview-banner";function Lr(e){var t;try{if(typeof document=="undefined"||document.getElementById(rn))return;let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),r=document.createElement("div");r.id=rn,r.setAttribute("role","status"),Object.assign(r.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",background:"#111827",color:"#fff",font:"13px/1 system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.14)"});let a=document.createElement("span");a.textContent=`Previewing as ${n}`;let o=document.createElement("button");o.type="button",o.textContent="Exit preview",Object.assign(o.style,{cursor:"pointer",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"inherit",padding:"4px 10px",borderRadius:"999px"}),o.addEventListener("click",()=>{try{let l=new URL(window.location.href);l.searchParams.delete("sentient_persona"),window.location.href=l.pathname+l.search+l.hash}catch(l){}}),r.appendChild(a),r.appendChild(o),((t=document.body)!=null?t:document.documentElement).appendChild(r)}catch(n){}}async function Pr(e,t){var s,c,u,m,v,I,C,k,h;let n=(s=e.apiBase)!=null?s:"https://api.sentient-ui.com",a=((c=e.registry)!=null?c:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([f,x])=>({id:f,dims:x.dims}))},o=await sn(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(a)}).then(f=>f.ok?f.json():null).catch(()=>null),on);if(!o){me(e,"persona preview: explain unavailable \u2014 page left as-is");return}let l=o;ie=(u=l.slots)!=null?u:{},le=(m=l.slotConfig)!=null?m:null;let d=(C=(I=(v=l.personaAttributes)==null?void 0:v.persona)!=null?I:l.persona)!=null?C:t,i=(h=(k=l.personaAttributes)==null?void 0:k.confidence)!=null?h:"high";L={persona:d,band:i},he(document),xe=!0,un(e),Lr(d)}function un(e){let t={goal(n,r){try{M==null||M.goal(n,r)}catch(a){}},componentGoal(n,r){try{M==null||M.componentGoal(n,r)}catch(a){}},grantConsent(){try{Ye(e.apiKey)}catch(n){}ze=!0;try{_r()}catch(n){}},revokeConsent(){try{oe==null||oe(),oe=null,qe=null,j==null||j(),j=null,ee==null||ee.teardown(),ee=null,ze=!1,M==null||M.destroy()}catch(n){}},reapply:tt,getState(){var n,r;return{apiKey:e.apiKey,persona:(n=L==null?void 0:L.persona)!=null?n:null,band:(r=L==null?void 0:L.band)!=null?r:null,slots:ie,matchCounts:Qe(e),consent:e.consent!==!1}}};window.SentientSnippet=t;for(let n of Cr.splice(0))try{n[0]==="goal"&&t.goal(n[1],n[2])}catch(r){}}async function dn(){var e,t,n,r,a;try{let o=$e(window.sentient);if(!o)return;V=o,xe=!1,ze=!1;let l=typeof window!="undefined"?an(window.location.search):null;if(l){Xt(l);try{let f=new URL(window.location.href);f.searchParams.delete("sentient_editor"),window.history.replaceState(null,"",f.pathname+f.search+f.hash)}catch(f){}}let d=l!=null?l:Yt();if(d){Tr(o,d),me(o,"editor mode");return}let i=typeof window!="undefined"?ln(window.location.search):null;if(i){ie=i,L=null,he(document),en(),me(o,"preview mode",i);return}let s=typeof window!="undefined"?cn(window.location.search):null;if(s){await Pr(o,s),me(o,"persona preview",s);return}let c=(e=o.registry)!=null?e:Object.keys(o.slots).length===0,u=De(o.apiKey);u&&(L={persona:u.persona,band:u.band},ie=u.slots,u.slotConfig&&(le=u.slotConfig),he(document,{contentAndOps:!1}));let m=Me({apiKey:o.apiKey,context:o.context,consent:o.consent,preConsentBehavior:o.preConsentBehavior,debug:o.debug,persona:o.persona});M=m,un(o),en();let v=Object.entries(o.slots).map(([f,x])=>({id:f,dims:x.dims})),I=Ze!=="0.0.0-dev"?{v:Ze}:{},C=await sn(m.decide(pe(pe({slots:v},I),c?{slotsFrom:"registry"}:{})),on);if(!C){me(o,"decide timeout/null \u2014 snapshot state stands",Qe(o));return}let k=m.getPersona();k?L={persona:k.persona,band:k.band}:C.persona&&(L={persona:C.persona,band:"low"}),ie=C.slots,c?le=(t=C.slotConfig)!=null?t:null:C.slotConfig&&(le=C.slotConfig);let h=[];if(Or(o,he(document,{onApplied:(f,x,O)=>h.push({slotId:f,arm:x,el:O})})),xe=!0,C.goals&&C.goals.length>0&&o.consent!==!1&&M)try{ee==null||ee.teardown(),ee=Jt(C.goals,M,document)}catch(f){}if(Ge=(n=C.sectionMap)!=null?n:null,Ee()){et();try{j==null||j(),j=Ue(M,o.apiKey,h)}catch(f){}}me(o,"applied",{persona:L,slots:ie,matches:Qe(o)}),Se(o.apiKey,pe({v:1,persona:(r=L==null?void 0:L.persona)!=null?r:C.persona,band:(a=L==null?void 0:L.band)!=null?a:"low",slots:C.slots,layoutOrder:C.layoutOrder,savedAt:Date.now()},le?{slotConfig:le}:{}))}catch(o){}}if(typeof window!="undefined"&&window.sentient){let e=window;e.__sentientInitialized||(e.__sentientInitialized=!0,dn())}return yn(Dr);})();
|
|
1
|
+
"use strict";var SentientSnippet=(()=>{var De=Object.defineProperty;var Cn=Object.getOwnPropertyDescriptor;var Ln=Object.getOwnPropertyNames,pt=Object.getOwnPropertySymbols;var mt=Object.prototype.hasOwnProperty,Tn=Object.prototype.propertyIsEnumerable;var gt=(e,t,n)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Y=(e,t)=>{for(var n in t||(t={}))mt.call(t,n)&>(e,n,t[n]);if(pt)for(var n of pt(t))Tn.call(t,n)&>(e,n,t[n]);return e};var ht=(e,t)=>()=>(e&&(t=e(e=0)),t);var yt=(e,t)=>{for(var n in t)De(e,n,{get:t[n],enumerable:!0})},Rn=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ln(t))!mt.call(e,s)&&s!==n&&De(e,s,{get:()=>t[s],enumerable:!(r=Cn(t,s))||r.enumerable});return e};var Pn=e=>Rn(De({},"__esModule",{value:!0}),e);var Dn,Bn,Mn,vt,Nn,Kn,bt,C,ke,Be=ht(()=>{"use strict";Dn=Object.defineProperty,Bn=Object.defineProperties,Mn=Object.getOwnPropertyDescriptors,vt=Object.getOwnPropertySymbols,Nn=Object.prototype.hasOwnProperty,Kn=Object.prototype.propertyIsEnumerable,bt=(e,t,n)=>t in e?Dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))Nn.call(t,n)&&bt(e,n,t[n]);if(vt)for(var n of vt(t))Kn.call(t,n)&&bt(e,n,t[n]);return e},ke=(e,t)=>Bn(e,Mn(t))});var Ot={};yt(Ot,{LOCAL_ENGINE_AVAILABLE:()=>zn,createLocalEngine:()=>qn});function qn(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var zn,Ct=ht(()=>{"use strict";zn=!1});var ao={};yt(ao,{applyPersonaAttributes:()=>He,applyRegistrySlots:()=>Ve,applySlotArms:()=>Fe,applySlotAttributes:()=>We,parseEditorToken:()=>xn,parsePersonaPreview:()=>kn,parsePreview:()=>En,parseSnippetConfig:()=>ze,reapply:()=>ft,run:()=>_n,version:()=>lt});Be();var $n=["buyer","researcher","deal_seeker","browser"];var jn={buyer:"Buyer",researcher:"Researcher",deal_seeker:"Deal seeker",browser:"Browser",unknown:"Unknown"};function Me(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function wt(e){if(e.length===0)return null;let t={};for(let n of e.split("|")){let r=n.indexOf("=");if(r<=0||r!==n.lastIndexOf("=")||r===n.length-1)return null;let s=n.slice(0,r);if(s in t)return null;t[s]=n.slice(r+1)}return t}function Qe(e){var t,n,r;if(e.arms)return typeof e.baseline=="string"?e.baseline:(t=e.arms[0])!=null?t:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return Me(e.baseline);if(typeof e.baseline=="string")return e.baseline;let s={};for(let[l,o]of Object.entries((n=e.dims)!=null?n:{}))s[l]=(r=o[0])!=null?r:"";return Me(s)}function St(e,t){var n,r;return e.dims!=null?(r=(n=wt(t))!=null?n:wt(Qe(e)))!=null?r:{}:t}function me(e){return e>=.3?e<.7?"medium":"high":"low"}var uo=$n.map(e=>({key:e,displayName:jn[e]}));var Un=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function At(e){return Gn(e)!==null}function Gn(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=Un.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function xt(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function Et(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(s){}let r=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(n){return"direct"}}function kt(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function It(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function et(e){return C(C(C({id:e.id},e.arms?{arms:[...e.arms]}:{}),e.dims?{dims:Object.fromEntries(Object.entries(e.dims).map(([t,n])=>[t,[...n]]))}:{}),e.baseline!==void 0?{baseline:e.baseline}:{})}function tt(e){let t=et(e);return St(t,Qe(t))}function _t(e){return typeof e=="string"?e:Me(e)}Be();function Tt(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}try{if(typeof crypto!="undefined"&&typeof crypto.getRandomValues=="function"){let e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t="";for(let n=0;n<16;n++)t+=e[n].toString(16).padStart(2,"0"),(n===3||n===5||n===7||n===9)&&(t+="-");return t}}catch(e){}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function Rt(e){return e?`_${e.slice(0,12)}`:""}var Hn="_snt_uid",Wn=365,Fn="_snt_uid";function Vn(){return Tt()}function Jn(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function Yn(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function Xn(e){try{return localStorage.getItem(e)}catch(t){return null}}function Zn(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function Qn(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function er(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function tr(e){try{sessionStorage.removeItem(e)}catch(t){}}function nr(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function rr(e){try{localStorage.removeItem(e)}catch(t){}}function or(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var ir={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function Pt(e){var t,n,r,s,l,o;if(typeof window=="undefined")return ir;let c=Rt(e==null?void 0:e.apiKey),i=(t=e==null?void 0:e.cookieName)!=null?t:`${Hn}${c}`,a=`${Fn}${c}`,u=((n=e==null?void 0:e.cookieTTLDays)!=null?n:Wn)*24*60*60,f=w=>w&&w.length>0?w:null,d=(o=(l=(s=(r=f(Jn(i)))!=null?r:f(Xn(a)))!=null?s:f(Qn(a)))!=null?l:f(e==null?void 0:e.ssrSessionId))!=null?o:Vn();Yn(i,d,u);let g=Zn(a,d),A=nr(i),L=g?!1:er(a,d),x=!g&&!A&&!L;return{getSessionId:()=>d,isEphemeral:()=>x,destroy:()=>{d=null,or(i),rr(a),tr(a)}}}function _e(e){return Math.min(6e4,1e3*2**Math.min(e,6))}function ot(e){if(e.ok===!0)return"delivered";let{status:t}=e;return typeof t!="number"?"retry":t>=200&&t<300?"delivered":t>=400&&t<500&&t!==429?"dropped":"retry"}function Dt(e,t){try{let n=localStorage.getItem(e);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?(localStorage.removeItem(e),r.slice(-t)):[]}catch(n){return[]}}function we(e,t,n){try{let r=(()=>{try{let l=localStorage.getItem(n);if(!l)return[];let o=JSON.parse(l);return Array.isArray(o)?o:[]}catch(l){return[]}})(),s=new Map;for(let l of r)s.set(l.id,l);for(let l of e)s.set(l.id,l);localStorage.setItem(n,JSON.stringify([...s.values()].slice(-t)))}catch(r){}}function Bt(e,t){try{let n=localStorage.getItem(t);if(!n)return;let r=JSON.parse(n);if(!Array.isArray(r))return;let s=new Set(e),l=r.filter(o=>!s.has(o.id));if(l.length===r.length)return;l.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(l))}catch(n){}}var sr=500,ar=56*1024;function Mt(e){return`_snt_retry_${e.slice(0,12)}`}var lr={push:()=>{},flush:()=>{},destroy:()=>{}};function cr(e){var t,n,r;if(typeof window=="undefined")return lr;let s=(t=e.flushIntervalMs)!=null?t:5e3,l=(n=e.maxBatchSize)!=null?n:20,o=(r=e.maxRetrySize)!=null?r:100,c=e.ingestUrl,i=e.apiKey,a=Mt(i),u=[],f=new Set,d=[],g=p=>{for(let y of p)A.delete(y),!f.has(y)&&(f.add(y),d.push(y));for(;d.length>sr;){let y=d.shift();y&&f.delete(y)}Bt(p,a)},A=new Set,L=p=>{f.has(p.id)||A.has(p.id)||(A.add(p.id),u.push(p))},x=p=>{for(let y of p)f.has(y.id)||(A.add(y.id),u.push(y))},w=Dt(a,o);for(let p of w)L(p);let k=0,h=0,b=(p,y=!0)=>{if(p.length===0)return;let E=JSON.stringify(p),P=p.map(ne=>ne.id),T;try{T=fetch(c,{method:"POST",keepalive:!0,body:E,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}})}catch(ne){we(p,o,a),x(p),h++,k=Date.now()+_e(h);return}let ve=ne=>{if(ot(ne)!=="retry"){if(!ne.ok&&y){let se=p.filter(ae=>ae.eventType!=="pageview");if(se.length>0&&se.length<p.length){g(p.filter(ae=>ae.eventType==="pageview").map(ae=>ae.id)),b(se,!1);return}}g(P),h=0,k=0;return}we(p,o,a),x(p),h++,k=Date.now()+_e(h)};T instanceof Promise?T.then(ve).catch(()=>{we(p,o,a),x(p),h++,k=Date.now()+_e(h)}):ve(T)},I=typeof TextEncoder!="undefined"?new TextEncoder:null,M=p=>I?I.encode(p).length:p.length,S=p=>{let y=[],E=2;for(let P of p){let T=M(JSON.stringify(P))+1;if(y.length>0&&E+T>ar||y.length>=l)break;y.push(P),E+=T}return y},R=()=>{try{if(Date.now()<k)return;for(;u.length>0&&!(Date.now()<k);){let p=u.filter(E=>!f.has(E.id));if(u.length=0,p.length===0)break;let y=S(p);if(y.length===0)break;y.length<p.length&&u.push(...p.slice(y.length)),b(y)}}catch(p){}},X=!0,_=null;_=setInterval(()=>{X&&R()},s);let Z=()=>{document.visibilityState==="hidden"&&R()},N=()=>{R()};return document.addEventListener("visibilitychange",Z),window.addEventListener("pagehide",N),{push(p){L(p),u.length>=l&&R()},flush:R,destroy(){X=!1,_!==null&&(clearInterval(_),_=null),document.removeEventListener("visibilitychange",Z),window.removeEventListener("pagehide",N),R()}}}var ur=200;function Nt(e){return`_snt_goal_retry_${e.slice(0,12)}`}var dr={send:()=>{},flush:()=>{},destroy:()=>{}};function fr(e){var t,n,r;if(typeof window=="undefined")return dr;let s=(t=e.flushIntervalMs)!=null?t:5e3,l=(n=e.maxRetrySize)!=null?n:100,o=(r=e.maxPerFlush)!=null?r:5,c=Nt(e.apiKey),i=[],a=new Set,u=new Set,f=[],d=0,g=0,A=!1,L=S=>{for(a.delete(S.id),u.has(S.id)||(u.add(S.id),f.push(S.id));f.length>ur;){let R=f.shift();R&&u.delete(R)}Bt([S.id],c)},x=S=>{we([S],l,c),!u.has(S.id)&&!a.has(S.id)&&(a.add(S.id),i.push(S)),Date.now()>=d&&(g++,d=Date.now()+_e(g))},w=S=>{let R;try{R=fetch(e.url,{method:"POST",keepalive:!0,body:S.body,headers:e.headers})}catch(_){x(S);return}let X=_=>{var Z;let N=ot(_);if(N==="retry"){x(S);return}N==="dropped"&&((Z=e.onDrop)==null||Z.call(e,S,_.status)),L(S),g=0,d=0};R instanceof Promise?R.then(X).catch(()=>x(S)):X(R)},k=()=>{try{if(A||Date.now()<d)return;let S=0;for(;i.length>0&&S<o&&!(Date.now()<d);){let R=i.shift();a.delete(R.id),!u.has(R.id)&&(S++,w(R))}}catch(S){}},h=Dt(c,l);for(let S of h)a.has(S.id)||(a.add(S.id),i.push(S));h.length>0&&we(h,l,c);let b=setInterval(k,s),I=()=>{document.visibilityState==="hidden"&&k()},M=()=>k();return document.addEventListener("visibilitychange",I),window.addEventListener("pagehide",M),{send(S){if(!A&&!(u.has(S.id)||a.has(S.id))){if(Date.now()<d){we([S],l,c),a.add(S.id),i.push(S);return}w(S)}},flush:k,destroy(){clearInterval(b),document.removeEventListener("visibilitychange",I),window.removeEventListener("pagehide",M),k(),A=!0}}}var pr=1800*1e3;function Ne(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function gr(e=pr,t){let n=new Map,r=`_snt_asgn${Rt(t)}_`,s=(i,a)=>`${r}${encodeURIComponent(i)}:${encodeURIComponent(a)}`,l=i=>{let a=i.slice(r.length),u=a.indexOf(":");if(u<0)return null;try{return{componentId:decodeURIComponent(a.slice(0,u)),segment:decodeURIComponent(a.slice(u+1))}}catch(f){return null}},o=()=>{try{let i=[];for(let a=0;a<localStorage.length;a++){let u=localStorage.key(a);u!=null&&u.startsWith(r)&&i.push(u)}return i}catch(i){return[]}},c=i=>i.assignedAt+(i.ttlMs&&i.ttlMs>0?i.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let i of o())try{let a=localStorage.getItem(i);if(!a)continue;let u=JSON.parse(a);if(c(u)){localStorage.removeItem(i);continue}let f=l(i);if(!f)continue;n.set(Ne(f.componentId,f.segment),u)}catch(a){}})(),{get(i,a){let u=n.get(Ne(i,a));return u?c(u)?(n.delete(Ne(i,a)),null):u:null},set(i,a,u){let f=Ne(i,a);n.set(f,u);try{localStorage.setItem(s(i,a),JSON.stringify(u))}catch(d){}},invalidate(i){let a=`${encodeURIComponent(i)}:`;for(let u of[...n.keys()])u.startsWith(a)&&n.delete(u);for(let u of o()){let f=l(u);if((f==null?void 0:f.componentId)===i)try{localStorage.removeItem(u)}catch(d){}}},clear(){n.clear();for(let i of o())try{localStorage.removeItem(i)}catch(a){}}}}var je="_snt_snap:",mr=["low","medium","high"];function Ue(e){try{let t=localStorage.getItem(je+e);if(!t)return null;let n=JSON.parse(t);return!n||typeof n!="object"||n.v!==1||typeof n.persona!="string"||typeof n.band!="string"||!mr.includes(n.band)||typeof n.slots!="object"||n.slots===null||Array.isArray(n.slots)||!(n.layoutOrder===null||Array.isArray(n.layoutOrder))||typeof n.savedAt!="number"||!(n.slotConfig===void 0||typeof n.slotConfig=="object"&&n.slotConfig!==null&&!Array.isArray(n.slotConfig))?null:n}catch(t){return null}}function Oe(e,t){try{localStorage.setItem(je+e,JSON.stringify(t))}catch(n){}}var rt="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",Kt="[sentient] Local mode \u2014 decisions are simulated on-device and nothing is sent over the network. Add an API key to learn from real traffic.",Lt=!1,Ke=!1;function hr(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function yr(e){var t;let n=Pt({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),r=(t=n.getSessionId())!=null?t:"local",s=hr(),l=Promise.resolve().then(()=>(Ct(),Ot)).then(i=>{let a=i;return a.LOCAL_ENGINE_AVAILABLE?(Lt||(Lt=!0,console.info(Kt)),a):(Ke||(Ke=!0,console.error(rt)),null)}).catch(()=>(Ke||(Ke=!0,console.error(rt)),null)),o=null;function c(i){let a=document.documentElement;a.dataset.sentientPersona===void 0&&(a.dataset.sentientPersona=i.persona,a.dataset.sentientConfidence=me(i.confidence))}return{isLocal:!0,async decide(i){var a,u,f;let d=await l;if(!d)return null;let g=d.createLocalEngine({sessionId:r,forcedPersona:s}).decide(i);return o=ke(C({},g),{layoutOrder:(u=(a=g.layoutOrder)!=null?a:o==null?void 0:o.layoutOrder)!=null?u:null,slots:C(C({},(f=o==null?void 0:o.slots)!=null?f:{}),g.slots)}),Oe(e.apiKey||"local",{v:1,persona:o.persona,band:me(o.confidence),slots:o.slots,layoutOrder:o.layoutOrder,savedAt:Date.now()}),c(g),g},getSlotResult(i){var a,u,f;return(f=(u=o==null?void 0:o.slots[i])!=null?u:(a=e.initialSlots)==null?void 0:a[i])!=null?f:null},getPersona(){return o?{persona:o.persona,confidence:o.confidence,band:me(o.confidence)}:null},async assign(i,a){var u;let f=await l;return!f||!a||a.length===0?a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null:{variantId:(u=f.createLocalEngine({sessionId:r,forcedPersona:s}).decide({components:[{id:i,variantIds:a}]}).assignments[i])!=null?u:a[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function Ce(e,t,n,r){let s=[];{let l=!1,o=[],c=()=>{if(l)return;let i=Date.now();for(o.push(i);o.length>0&&i-o[0]>500;)o.shift();o.length>=3&&(l=!0,e("rage_click"))};t.addEventListener("click",c),s.push(()=>t.removeEventListener("click",c))}{let l=!1,o=c=>{if(l||!(c.target instanceof Node)||!t.contains(c.target)&&t!==c.target)return;l=!0;let i=typeof window!="undefined"?window.getSelection():null,a=i?i.toString().length:0;e("text_copy",{selectionLength:a})};document.addEventListener("copy",o),s.push(()=>document.removeEventListener("copy",o))}{let l=!1,o=!1,c=null,i=()=>{c!==null&&(clearTimeout(c),c=null)},a=()=>{l||!o||(i(),c=setTimeout(()=>{!l&&o&&(l=!0,e("scroll_hesitation"))},3e3))},u=()=>{i(),a()},f=g=>{for(let A of g)o=A.intersectionRatio>.3,o?a():i()},d=new IntersectionObserver(f,{threshold:[.3]});d.observe(t),window.addEventListener("scroll",u,{passive:!0}),s.push(()=>{d.disconnect(),window.removeEventListener("scroll",u),i()})}if((r==null?void 0:r.tabLoss)!==!1){let l=!1,o=n!=null?n:Date.now(),c=()=>{if(l||document.visibilityState!=="hidden")return;let i=Date.now()-o;i<15e3&&(l=!0,e("tab_loss",{timeOnPage:i}))};document.addEventListener("visibilitychange",c),s.push(()=>document.removeEventListener("visibilitychange",c))}return()=>{for(let l of s)l()}}var $t="https://api.sentient-ui.com/v1/events",V=new Map,jt=null;function vr(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}var br=3;function nt(){return Tt()}function $e(){var e;if(typeof window!="undefined")return((e=window.location)==null?void 0:e.pathname)||void 0}function wr(e){if(typeof MessageChannel=="function"){let t=new MessageChannel;t.port1.onmessage=()=>{e.clear(),t.port1.close(),t.port2.close()},t.port2.postMessage(0)}else setTimeout(()=>e.clear(),0)}var Ut=new Set;function Sr(e,t,n){let r=typeof window=="undefined"?null:window.history;if(!r)return()=>{};let s=!1,l,o=()=>{if(s)return;let a=$e();!a||a===l||(l=a,e.track({projectId:t,componentId:"__page__",eventType:"pageview",payload:{}}),n(`${t}:${a}`))},c=[];for(let a of["pushState","replaceState"]){let u=r[a],f=function(...d){let g=u.apply(this,d);return o(),g};r[a]=f,c.push([a,u,f])}window.addEventListener("popstate",o);let i=$e();return i&&Ut.has(`${t}:${i}`)?l=i:o(),()=>{if(!s){s=!0,window.removeEventListener("popstate",o);for(let[a,u,f]of c)r[a]===f&&(r[a]=u)}}}var Ie={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}};function Ar(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,r]of t)n.startsWith("utm_")&&(e[n]=r);return e}catch(e){return{}}}function Gt(e){return e.replace(/\/events\/?$/,"")}function he(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(e=>e==="1"||e==="yes")}function it(e){var t;if(typeof window=="undefined")return;let n=e!=null?e:jt;if(!n){console.warn("[sentient] grantConsent() called before init()");return}let r=V.get(n);if(!r){console.warn("[sentient] grantConsent() called before init()");return}let{config:s,upgrade:l}=r;if(!l||s.respectDoNotTrack!==!1&&he())return;let o=Ge(ke(C({},s),{consent:!0}));l(o);let c=(t=V.get(n))==null?void 0:t.dispose;V.set(n,{config:ke(C({},s),{consent:!0}),upgrade:null,dispose:c})}function xr(e){var t;let n=e.preConsentBehavior==="statistical_winner",r=Gt((t=e.ingestUrl)!=null?t:$t),s={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},l={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(i,a,u){if(!n)return null;try{let f=new URLSearchParams({componentId:i});for(let g of a!=null?a:[])f.append("variantIds[]",g);let d=await fetch(`${r}/winner?${f.toString()}`,{headers:s});return d.ok?{variantId:(await d.json()).variantId,assignmentTtlMs:0}:a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}catch(f){return a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},o={track:i=>l.track(i),goal:((i,a,u,f)=>l.goal(i,a,u,f)),componentGoal:(i,a,u)=>l.componentGoal(i,a,u),identify:i=>l.identify(i),getAssignment:(i,a)=>l.getAssignment(i,a),assign:(i,a,u,f)=>l.assign(i,a,u,f),decide:i=>l.decide(i),getSlotResult:i=>l.getSlotResult(i),getPersona:()=>l.getPersona(),fetchWeights:()=>l.fetchWeights(),getGraph:()=>l.getGraph(),dispose:()=>l.dispose(),destroy:()=>l.destroy()};function c(i){l=i}return{proxy:o,setInner:c}}function Ge(e){var t,n,r,s,l,o,c,i,a;if(typeof window=="undefined")return Ie;jt=e.apiKey;let u=V.get(e.apiKey||"local");if(u!=null&&u.dispose)try{u.dispose()}catch(m){}let f=e.respectDoNotTrack!==!1&&he(),d=e.consent===!1||f,g=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!g&&e.localMode!==!1)return d?(V.set(e.apiKey||"local",{config:e,upgrade:null}),Ie):(V.set(e.apiKey||"local",{config:e,upgrade:null}),yr(e));if(d){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return e.preConsentBehavior==="statistical_winner"&&console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),V.set(e.apiKey,{config:e,upgrade:null}),Ie;let{proxy:m,setInner:v}=xr(e);return V.set(e.apiKey,{config:e,upgrade:f?null:v}),m}if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),Ie;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),Ie;let A=(t=e.ingestUrl)!=null?t:$t,L=Date.now(),x=Pt({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),w=gr(void 0,e.apiKey),k=cr({ingestUrl:A,apiKey:e.apiKey}),h=Gt(A),b={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},I=new Set,M=fr({url:`${h}/goals`,apiKey:e.apiKey,headers:b,onDrop:(m,v)=>{if(!e.debug){if(I.has(v))return;I.add(v)}console.warn(`[sentient] goal dropped (HTTP ${v}) \u2014 this will not be retried. `+(v===400?"The session was not found: call init() and let the session upsert complete before firing goals.":v===401||v===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),m)}}),S=xt((n=navigator.userAgent)!=null?n:""),R=typeof window!="undefined"?window.location.origin:void 0,X=Et((r=document.referrer)!=null?r:"",R),_=(s=e.sessionSegment)!=null?s:`${S}:${X}`,Z=new Map,N=new Map,p=null,y=m=>{for(let v of m)N.has(v.id)||N.set(v.id,tt(v))};if(e.initialSlots)for(let[m,v]of Object.entries(e.initialSlots))N.set(m,v);let E=Ue(e.apiKey);if(E)for(let[m,v]of Object.entries(E.slots))N.has(m)||N.set(m,v);let P={low:.15,medium:.5,high:.85};if(e.initialPersona)p=C({},e.initialPersona);else{let m=document.documentElement.dataset;m.sentientPersona?p={persona:m.sentientPersona,confidence:(o=P[(l=m.sentientConfidence)!=null?l:"low"])!=null?o:.15}:E&&(p={persona:E.persona,confidence:(c=P[E.band])!=null?c:.15})}if(e.initialAssignments)for(let[m,v]of Object.entries(e.initialAssignments))w.set(m,_,{variantId:v,assignedAt:Date.now(),segment:_,confidence:1});let T=Promise.resolve(),ve=x.getSessionId();if(ve){let m=kt((i=document.referrer)!=null?i:""),v=C(C(C({sessionId:ve,deviceClass:S,trafficSource:X,referrerDomain:m,utmParams:Ar(),timeOfDay:It(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:x.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||At((a=navigator.userAgent)!=null?a:"")},e.userId?{userId:e.userId}:{}),e.persona?{persona:e.persona}:{}),e.country?{country:e.country}:{}),D=async()=>{for(let G=0;;G++){try{let K=await fetch(`${h}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(v),headers:b});if(K.status===402){console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing");return}if(K.ok||ot(K)==="dropped")return}catch(K){}if(G>=br){console.warn("[SentientUI] Could not register the session after retries. Conversions in this visit may not be recorded.");return}await new Promise(K=>setTimeout(K,_e(G+1)))}};try{T=D()}catch(G){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:k});let ne=new Set,se=null,ae=!1,be={goal(m,v={},D=1,G=0){var K,j,Q,F,q,re;let H=x.getSessionId();if(!H)return;let W=vr(v)?v:{metadata:v},ee=`${m}\0${(K=W.externalId)!=null?K:""}\0${(j=W.stepIndex)!=null?j:G}\0${(Q=W.weight)!=null?Q:D}`;if(ne.has(ee)){e.debug&&console.log(`[sentient] goal("${m}") already recorded for this action \u2014 not sent twice`);return}ne.add(ee),ne.size===1&&wr(ne);let xe=nt(),O={sessionId:H,name:m,metadata:(F=W.metadata)!=null?F:{},weight:(q=W.weight)!=null?q:D,stepIndex:(re=W.stepIndex)!=null?re:G,goalId:xe,value:W.value,currency:W.currency,externalId:W.externalId};e.debug&&console.log("[sentient] goal",O);let ge={id:xe,body:JSON.stringify(O)};T.then(()=>M.send(ge))},componentGoal(m,v,D){var G,K,j;let Q=x.getSessionId();if(!Q)return;let F=w.get(m,_),q=F?null:(G=N.get(m))!=null?G:null;if(!F&&q===null){e.debug&&console.warn(`[sentient] componentGoal("${m}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let re=F?F.variantId:_t(q),H={id:nt(),sessionId:Q,projectId:e.apiKey,componentId:m,variantId:re,eventType:"goal_achieved",goalType:v,payload:C({reward:(K=D==null?void 0:D.reward)!=null?K:1,goalValue:D==null?void 0:D.value,currency:D==null?void 0:D.currency},(j=D==null?void 0:D.metadata)!=null?j:{}),timestamp:Date.now(),timeInSession:Date.now()-L,path:$e()};e.debug&&console.log("[sentient] componentGoal",H),T.then(()=>k.push(H))},identify(m){let v=x.getSessionId();v&&T.then(()=>{fetch(`${h}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:v,userId:m,ephemeral:x.isEphemeral()}),headers:b}).catch(()=>{})})},track(m){let v=x.getSessionId();if(!v)return;let D=ke(C({path:$e()},m),{id:nt(),sessionId:v,timestamp:Date.now(),timeInSession:Date.now()-L});e.debug&&console.log("[sentient] track",D),T.then(()=>k.push(D))},getAssignment(m,v){return w.get(m,v)},async assign(m,v,D,G){let K=x.getSessionId();if(!K)return null;let j=w.get(m,_);if(j&&(v!=null&&v.length||j.content!==void 0)){let q=j.ttlMs&&j.ttlMs>0?Math.max(0,j.assignedAt+j.ttlMs-Date.now()):0;return{variantId:j.variantId,assignmentTtlMs:q,content:j.content}}let Q=Z.get(m);if(Q)return Q;let F=(async()=>{await T;try{let q={sessionId:K,componentId:m,variantIds:v};G!==void 0?q.agentDataByVariant=G:D!==void 0&&(q.agentData=D);let re=await fetch(`${h}/assign`,{method:"POST",body:JSON.stringify(q),headers:b});if(!re.ok)return null;let H=await re.json();return w.set(m,_,C({variantId:H.variantId,assignedAt:Date.now(),segment:_,confidence:1,content:H.content},H.assignmentTtlMs&&H.assignmentTtlMs>0?{ttlMs:H.assignmentTtlMs}:{})),H}catch(q){return null}finally{Z.delete(m)}})();return Z.set(m,F),F},async decide(m){var v,D,G,K,j,Q,F,q,re;let H=x.getSessionId();if(!H)return null;let W=(v=m.slots)!=null?v:[];await T;try{let ee={sessionId:H};m.sections&&m.sections.length>0&&(ee.sections=m.sections.map(J=>({id:J}))),ee.components=(D=m.components)!=null?D:[],W.length>0&&(ee.slots=W.map(et)),m.slotsFrom==="registry"&&(ee.slotsFrom="registry"),m.v&&(ee.v=m.v),e.persona&&(ee.persona=e.persona);let xe=await fetch(`${h}/decide`,{method:"POST",body:JSON.stringify(ee),headers:b});if(!xe.ok)return y(W),null;let O=await xe.json(),ge={};for(let J of W)ge[J.id]=(K=(G=O.slots)==null?void 0:G[J.id])!=null?K:tt(J);if(O.slots)for(let[J,Ee]of Object.entries(O.slots))J in ge||(ge[J]=Ee);for(let[J,Ee]of Object.entries(ge))N.set(J,Ee);let On=p!=null&&p.persona!=="unknown";O.persona&&!(O.persona==="unknown"&&On)?p={persona:O.persona,confidence:(j=O.confidence)!=null?j:0}:p||(p={persona:"unknown",confidence:0});for(let[J,Ee]of Object.entries((Q=O.assignments)!=null?Q:{}))w.set(J,_,{variantId:Ee,assignedAt:Date.now(),segment:_,confidence:1});return Oe(e.apiKey,C(C({v:1,persona:p.persona,band:me(p.confidence),slots:Object.fromEntries(N),layoutOrder:(F=O.layoutOrder)!=null?F:null,savedAt:Date.now()},O.slotConfig?{slotConfig:O.slotConfig}:{}),O.palette?{palette:O.palette}:{})),C(C(C(C({layoutOrder:(q=O.layoutOrder)!=null?q:null,assignments:(re=O.assignments)!=null?re:{},slots:ge,persona:p.persona,confidence:p.confidence},O.slotConfig?{slotConfig:O.slotConfig}:{}),O.goals?{goals:O.goals}:{}),O.sectionMap?{sectionMap:O.sectionMap}:{}),O.palette?{palette:O.palette}:{})}catch(ee){return y(W),null}},getSlotResult(m){var v;return(v=N.get(m))!=null?v:null},getPersona(){return p?{persona:p.persona,confidence:p.confidence,band:me(p.confidence)}:null},async fetchWeights(){var m;try{let v=await fetch(`${h}/weights`,{headers:b});return v.ok?(m=(await v.json()).components)!=null?m:[]:[]}catch(v){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var m;se==null||se(),ae=!0,k.destroy(),M.destroy(),((m=V.get(e.apiKey))==null?void 0:m.dispose)===be.dispose&&V.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var m;se==null||se(),ae=!0,k.destroy(),M.destroy(),x.destroy(),((m=V.get(e.apiKey))==null?void 0:m.dispose)===be.dispose&&V.delete(e.apiKey);try{localStorage.removeItem(je+e.apiKey),localStorage.removeItem(Mt(e.apiKey)),localStorage.removeItem(Nt(e.apiKey))}catch(v){}e.debug&&console.log("[sentient] destroyed")}};if(V.set(e.apiKey,{config:e,upgrade:null,dispose:be.dispose}),se=Sr(be,e.apiKey,m=>{T.then(()=>{ae||Ut.add(m)})}),e.debug){let m=window;m.__sentient&&(m.__sentient.client=be)}return be}var zt=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Er=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],kr=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function Ir(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function qt(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,r]of Er)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of kr)if(r.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function Ht(e){var t,n;let r=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:Ir(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function Wt(e){return qt(Ht(e)).type}Be();var _r="section, header, footer, nav, main > div, [data-sentient-section]",Or=2e4;function Cr(e){let t=Array.from(e.querySelectorAll(_r)),n=t.filter(r=>t.filter(s=>s!==r&&r.contains(s)).length<2);return n.filter(r=>!n.some(s=>s!==r&&s.contains(r)))}function Lr(e,t,n,r){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:r})}).catch(()=>{})}catch(s){}}var Ft=()=>{};function Vt(e,t){var n,r,s,l,o,c,i,a,u;let f=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!f||typeof IntersectionObserver=="undefined"||he()||!t.apiKey)return Ft;let d=((r=t.apiBase)!=null?r:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),g=Cr(f);if(g.length===0)return Ft;let A=new Map,L=new Map,x=new Map;for(let p of g){let y=p.getAttribute("data-sentient-type"),E=y&&zt.includes(y)?y:null,P=(l=E!=null?E:(s=t.typeOf)==null?void 0:s.call(t,p))!=null?l:Wt(p),T=`nc-${P}`;A.set(p,T),L.set(T,P),E?x.set(T,"markup"):x.has(T)||x.set(T,"auto")}let w=(a=(i=(c=(o=f.defaultView)!=null?o:typeof window!="undefined"?window:void 0)==null?void 0:c.location)==null?void 0:i.pathname)!=null?a:"/";Lr(t.apiKey,d,w,[...L.entries()].map(([p,y])=>{var E;return{componentId:p,semanticType:y,source:(E=x.get(p))!=null?E:"auto"}}));let k=new Map,h=p=>{let y=k.get(p);return y||(y={ms:0,scroll:0,enterAt:null,intersecting:!1},k.set(p,y)),y},b=new IntersectionObserver(p=>{for(let y of p){let E=A.get(y.target);if(!E)continue;let P=h(E);y.isIntersecting?(P.intersecting=!0,P.enterAt=Date.now(),y.intersectionRatio>P.scroll&&(P.scroll=y.intersectionRatio)):(P.intersecting=!1,P.enterAt!=null&&(P.ms+=Date.now()-P.enterAt,P.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let p of A.keys())b.observe(p);let I=()=>{let p=Date.now();for(let[y,E]of k)if(E.enterAt!=null&&(E.ms+=p-E.enterAt,E.enterAt=null),!(E.ms<=0)){try{e.track({projectId:t.apiKey,componentId:y,eventType:"dwell",payload:{dwell_time:Math.round(E.ms),scroll_depth:Number(E.scroll.toFixed(2))}})}catch(P){}E.ms=0}},M=()=>{if(f.hidden)I();else{let p=Date.now();for(let y of k.values())y.intersecting&&(y.enterAt=p)}},S=!1,R=p=>{if(I(),p!=null&&p.persisted){S=!0;return}try{b.disconnect()}catch(y){}},X=p=>{if(!(p!=null&&p.persisted)||!S)return;S=!1;let y=Date.now();for(let E of k.values())E.enterAt=E.intersecting&&!f.hidden?y:null};f.addEventListener("visibilitychange",M);let _=(u=f.defaultView)!=null?u:typeof window!="undefined"?window:void 0;_==null||_.addEventListener("pagehide",R),_==null||_.addEventListener("pageshow",X);let Z=setInterval(()=>{if(f.hidden||S)return;I();let p=Date.now();for(let y of k.values())y.intersecting&&(y.enterAt=p)},Or),N=[];return t.microSignals&&[...A.entries()].forEach(([p,y],E)=>{N.push(Ce((P,T={})=>{try{e.track({projectId:t.apiKey,componentId:y,eventType:"micro_signal",payload:C({signalType:P},T)})}catch(ve){}},p,void 0,{tabLoss:E===0}))}),()=>{I(),clearInterval(Z),f.removeEventListener("visibilitychange",M),_==null||_.removeEventListener("pagehide",R),_==null||_.removeEventListener("pageshow",X);for(let p of N)p();try{b.disconnect()}catch(p){}}}var Tr=["landing","ecommerce","saas","marketplace"];function Rr(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t=Object.entries(e);if(t.length<1||t.length>4)return null;let n={};for(let[r,s]of t){if(!Array.isArray(s)||s.length<2||s.length>6||!s.every(l=>typeof l=="string"))return null;n[r]=s}return n}function Pr(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function Dr(e){try{return e()}catch(t){return}}function ze(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.apiKey!="string"||!t.apiKey.startsWith("pk_"))return null;let n=Tr.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[o,c]of Object.entries(t.slots)){if(typeof c!="object"||c===null)continue;let i=c,a=Rr(i.dims);if(!a||i.target!==void 0&&typeof i.target!="string")continue;let u=i.arms!==void 0?Pr(i.arms):null,f={dims:a};typeof i.target=="string"&&(f.target=i.target),u&&(f.arms=u),r[o]=f}let s={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};typeof t.consent=="boolean"&&(s.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(s.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(s.debug=!0),typeof t.registry=="boolean"&&(s.registry=t.registry),typeof t.editorSrc=="string"&&(s.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(s.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(s.sectionCapture=t.sectionCapture);let l=typeof t.persona=="function"?Dr(t.persona):t.persona;if(typeof l=="string"&&l.trim()!==""&&(s.persona=l),Array.isArray(t.sections)){let o=t.sections.filter(c=>typeof c=="string"&&c.trim()!=="").slice(0,50);o.length>=2&&(s.sections=o)}return s}function Jt(e){var n,r,s;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(s=t==null?void 0:t.pathname)!=null?s:""}function Br(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let r=((n=e.textContent)!=null?n:"").trim().toLowerCase(),s=t.text.trim().toLowerCase();if(!(r===s||r.startsWith(s)||s.startsWith(r)))return!1}return!0}function Yt(e,t){return!!(e!=null&&e.urlMatch)&&!Jt(t).includes(e.urlMatch)}var Mr=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function de(e,t){var s;if(e.urlMatch&&!Jt(t).includes(e.urlMatch))return null;let n=[];if(e.id){let l=t.getElementById(e.id);n=l?[l]:[]}if(n.length===0&&((s=e.dataAttr)!=null&&s.name)&&Mr.test(e.dataAttr.name))try{let l=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${l}"]`))}catch(l){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(l){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!Br(r,e.fingerprint)?null:r}var Xt={color:"color",background:"background",fontSize:"font-size",fontWeight:"font-weight",textAlign:"text-align",padding:"padding",margin:"margin",borderRadius:"border-radius",width:"width",height:"height",maxWidth:"max-width",border:"border",boxShadow:"box-shadow",opacity:"opacity",lineHeight:"line-height",letterSpacing:"letter-spacing",textTransform:"text-transform",gap:"gap",fontFamily:"font-family"},Nr=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function Zt(e){var t;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;for(let n of e.matchAll(/([A-Za-z-]*)\(/g))if(!Nr.test((t=n[1])!=null?t:""))return!1;return!0}var Qt=/^https:\/\//i,en=new Map,fe=null;function Kr(e){return e.replace(/["\\]/g,"\\$&")}function $r(e){var t;(!fe||!fe.isConnected)&&(fe=e.querySelector("style[data-sentient-ops]"),fe||(fe=e.createElement("style"),fe.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(fe))),fe.textContent=[...en.entries()].map(([n,r])=>`[data-snt-e="${Kr(n)}"]{${r}}`).join(`
|
|
2
|
+
`)}function tn(e,t,n,r){var c;let s=!1,l=(c=t.moveBefore)!=null?c:t.moveAfter;if(l){let i=de(l,r);!i||i===e||i.parentElement!==e.parentElement||!e.parentElement?s=!0:t.moveBefore?e.parentElement.insertBefore(e,i):e.parentElement.insertBefore(e,i.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&Qt.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&Qt.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let o=[];if(t.hidden&&o.push("display:none !important"),t.style)for(let[i,a]of Object.entries(t.style)){let u=Xt[i];u&&typeof a=="string"&&Zt(a)&&o.push(`${u}:${a.trim()} !important`)}return o.length>0&&(e.setAttribute("data-snt-e",n),en.set(n,o.join(";")),$r(r)),{anchorMiss:s}}var Le="data-sentient-block-arm",oe=null;function Te(e){oe=e!=null?e:null}var ce="data-sentient-blocks-hid",nn={none:"0",sm:"8px",md:"16px",lg:"24px"},st={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch",between:"space-between"},rn={sm:"0.875em",md:"1em",lg:"1.25em"},jr={sm:"1.25em",md:"1.5em",lg:"2em"},Ur={sm:"6px 14px",md:"10px 20px",lg:"14px 28px"},on={sm:"8px",md:"16px",lg:"32px"},Gr={square:"1 / 1",landscape:"4 / 3",wide:"16 / 9"},zr={normal:"400",medium:"500",bold:"700"};function le(e,t){for(let[n,r]of Object.entries(t))r!==void 0&&e.style.setProperty(n,r);return e}function sn(e){return{opacity:e==="muted"?"0.7":void 0,"font-weight":e==="accent"?"600":void 0}}function an(e,t){var n,r,s,l,o,c,i,a,u,f;try{switch(e.type){case"stack":case"grid":{let d=t.createElement("div");if(e.type==="stack"){let g=e;le(d,{display:"flex","flex-direction":g.direction,gap:nn[(n=g.gap)!=null?n:"md"],"align-items":g.align?st[g.align]:void 0,"justify-content":g.justify?st[g.justify]:void 0,"flex-wrap":g.wrap?"wrap":void 0})}else{let g=e,A=nn[(r=g.gap)!=null?r:"md"];le(d,{display:"grid","grid-template-columns":`repeat(auto-fit, minmax(max(200px, calc((100% - ${g.columns-1} * ${A}) / ${g.columns})), 1fr))`,gap:A,"align-items":g.align?st[g.align]:void 0})}for(let g of(s=e.children)!=null?s:[]){let A=an(g,t);A&&d.appendChild(A)}return d}case"text":{let d=t.createElement("p");return d.textContent=e.value,le(d,Y({margin:"0","font-size":e.size?rn[e.size]:void 0,"font-weight":e.weight?zr[e.weight]:void 0,"text-align":e.align},sn(e.tone)))}case"heading":{let d=t.createElement(`h${e.level}`);return d.textContent=e.value,le(d,{margin:"0","font-size":jr[(l=e.size)!=null?l:"md"],"text-align":e.align})}case"button":{let d=t.createElement("a");d.textContent=e.label,d.href=e.href,e.tag&&d.setAttribute("data-sentient-tag",e.tag);let g=(o=e.emphasis)!=null?o:"primary";return le(d,{display:"inline-block",padding:Ur[(c=e.size)!=null?c:"md"],"border-radius":(i=oe==null?void 0:oe.radius)!=null?i:"8px",font:"inherit","font-size":e.size?rn[e.size]:void 0,"text-decoration":g==="ghost"?"underline":"none",cursor:"pointer",background:g==="primary"?(a=oe==null?void 0:oe.primaryBg)!=null?a:"#111827":"transparent",color:g==="primary"?(u=oe==null?void 0:oe.primaryText)!=null?u:"#ffffff":"inherit",border:g==="secondary"?"1px solid currentColor":"none"})}case"link":{let d=t.createElement("a");return d.textContent=e.label,d.href=e.href,e.tag&&d.setAttribute("data-sentient-tag",e.tag),le(d,{color:"inherit","text-decoration":"underline"})}case"image":{let d=t.createElement("img");return d.src=e.src,d.alt=e.alt,le(d,{display:"block","max-width":"100%","aspect-ratio":e.ratio&&e.ratio!=="auto"?Gr[e.ratio]:void 0,"object-fit":e.fit,width:e.ratio&&e.ratio!=="auto"?"100%":void 0})}case"badge":{let d=t.createElement("span");return d.textContent=e.value,le(d,Y({display:"inline-block",padding:"2px 10px","border-radius":"999px","font-size":"0.75em",border:"1px solid currentColor"},sn(e.tone)))}case"spacer":return le(t.createElement("div"),{height:(f=on[e.size])!=null?f:on.md});default:return null}}catch(d){return null}}function ln(e,t,n,r){try{let s=new Set;for(let o of Array.from(e.children)){let c=o.getAttribute(Le);c!==null&&(t[c]===void 0?o.remove():s.add(c))}for(let[o,c]of Object.entries(t)){if(s.has(o))continue;let i=an(c,r);if(!i)continue;let a=r.createElement("div");a.setAttribute(Le,o),a.style.display="none",a.appendChild(i),e.appendChild(a)}let l=n!==void 0&&t[n]!==void 0;for(let o of Array.from(e.children)){let c=o.getAttribute(Le),i=o;c!==null?i.style.display=l&&c===n?"":"none":l?i.hasAttribute(ce)||(i.setAttribute(ce,i.style.display),i.style.display="none"):i.hasAttribute(ce)&&(i.style.display=i.getAttribute(ce),i.removeAttribute(ce))}}catch(s){}}function qr(e){try{for(let t of Array.from(e.children)){let n=t;if(n.getAttribute(Le)!==null){n.remove();continue}n.hasAttribute(ce)&&(n.style.display=n.getAttribute(ce),n.removeAttribute(ce))}}catch(t){}}function qe(e,t){try{let n=new Set;for(let r of Array.from(e.querySelectorAll(`[${Le}]`)))r.parentElement&&n.add(r.parentElement);for(let r of Array.from(e.querySelectorAll(`[${ce}]`)))r.parentElement&&n.add(r.parentElement);for(let r of n)t.has(r)||qr(r)}catch(n){}}function He(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function We(e,t,n){var r;for(let[s,l]of Object.entries(t)){let o=e[s];if(!o||typeof o=="string")continue;let c=l.target?Array.from(n.querySelectorAll(l.target)):[n.documentElement];for(let i of c)for(let[a,u]of Object.entries(o))(r=l.dims[a])!=null&&r.includes(u)&&i.setAttribute(`data-${a}`,u)}}function Fe(e,t,n){for(let[r,s]of Object.entries(t)){let l=e[r];if(typeof l!="string"||!s.arms||!s.arms.includes(l))continue;let o=s.target?Array.from(n.querySelectorAll(s.target)):[n.documentElement];for(let c of o)c.setAttribute("data-sentient-arm",l)}}function Ve(e,t,n,r){var c,i;let s=new Set,l=(c=r==null?void 0:r.contentAndOps)!=null?c:!0,o=[];for(let[a,u]of Object.entries(t)){if(Yt(u.locator,n))continue;let f;if(u.locator){let g=de(u.locator,n);f=g?[g]:[]}else u.target?f=Array.from(n.querySelectorAll(u.target)):f=[n.documentElement];(u.locator||u.target)&&f.length===0&&o.push(a);let d=e[a];for(let g of f){if(d!==void 0)if(typeof d=="string")g.setAttribute("data-sentient-arm",d),l&&((i=r==null?void 0:r.onApplied)==null||i.call(r,a,d,g));else for(let[A,L]of Object.entries(d))g.setAttribute(`data-${A}`,L);u.blocks&&!Wr(n)&&(ln(g,u.blocks,typeof d=="string"?d:void 0,n),s.add(g)),l&&(typeof u.content=="string"&&(g.textContent=u.content),u.ops&&tn(g,u.ops,a,n).anchorMiss&&!o.includes(a)&&o.push(a))}}return qe(n,s),o}var Hr=/bot|crawler|spider|crawling|googlebot|bingbot|duckduckbot|baiduspider|yandexbot|slurp|gptbot|claudebot|anthropic|perplexity|ccbot|applebot|headlesschrome/i;function Wr(e){var t,n,r;try{let s=(n=(t=e.defaultView)!=null?t:typeof window!="undefined"?window:void 0)==null?void 0:n.navigator;return s?s.webdriver===!0?!0:Hr.test((r=s.userAgent)!=null?r:""):!1}catch(s){return!1}}var Fr=800;function Je(e,t,n){let r=[];return n.forEach(({slotId:s,arm:l,el:o},c)=>{r.push(Ce((d,g={})=>{try{e.track({projectId:t,componentId:s,variantId:l,eventType:"micro_signal",payload:Y({signalType:d},g)})}catch(A){}},o,void 0,{tabLoss:c===0}));let i=null,a=0,u=()=>{a=Date.now(),i=setTimeout(()=>{try{e.track({projectId:t,componentId:s,variantId:l,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-a}})}catch(d){}i=null},Fr)},f=()=>{i!==null&&(clearTimeout(i),i=null)};o.addEventListener("mouseenter",u),o.addEventListener("mouseleave",f),r.push(()=>{o.removeEventListener("mouseenter",u),o.removeEventListener("mouseleave",f),i!==null&&clearTimeout(i)})}),()=>{for(let s of r)s()}}function Vr(e){var n,r,s;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(s=t==null?void 0:t.pathname)!=null?s:""}function Jr(e,t){if(!e)return!1;if(e==="/")return t==="/";let n=e.endsWith("/")?e.slice(0,-1):e;return t===n||t.startsWith(`${n}/`)}function Yr(e){return e?`_snt_fired_goals_${e.slice(0,12)}`:"_snt_fired_goals"}function Xr(e){var t;return[(t=e.slotId)!=null?t:"",e.goalId,e.event,e.locator?JSON.stringify(e.locator):""].join("|")}function Zr(e,t){try{let n=e==null?void 0:e.sessionStorage.getItem(t);if(!n)return new Set;let r=JSON.parse(n);return Array.isArray(r)?new Set(r.filter(s=>typeof s=="string")):new Set}catch(n){return new Set}}function Qr(e,t,n){try{e==null||e.sessionStorage.setItem(t,JSON.stringify([...n]))}catch(r){}}function cn(e,t,n,r){var w,k;let s=(w=n.defaultView)!=null?w:typeof window!="undefined"?window:null,l=Yr(r),o=Zr(s,l),c=h=>{let b=Xr(h);if(!o.has(b))try{h.slotId?t.componentGoal(h.slotId,h.goalId):t.goal(h.goalId),o.add(b),Qr(s,l,o)}catch(I){}},i=e.filter(h=>h.event==="click"),a=e.filter(h=>h.event==="form_submit"),u=e.filter(h=>h.event==="url_reached"),f=e.filter(h=>h.event==="scroll_depth"),d=(h,b)=>{if(!h.locator)return!1;let I=de(h.locator,n);return!!I&&(I===b||I.contains(b))},g=h=>{let b=h.target;if(!(!b||typeof b.closest!="function"))for(let I of i)d(I,b)&&c(I)},A=h=>{let b=h.target;if(b)for(let I of a)d(I,b)&&c(I)},L=()=>{if(u.length===0)return;let h=Vr(n);for(let b of u)b.urlPattern&&Jr(b.urlPattern,h)&&c(b)},x=()=>{var I;let h=n.documentElement,b=h.scrollHeight>0?(h.scrollTop+h.clientHeight)/h.scrollHeight:0;for(let M of f)b>=((I=M.threshold)!=null?I:.75)&&c(M);f.every(M=>o.has(M.goalId))&&n.removeEventListener("scroll",x)};return n.addEventListener("click",g,!0),n.addEventListener("submit",A,!0),(k=n.defaultView)==null||k.addEventListener("popstate",L),L(),f.length>0&&(n.addEventListener("scroll",x,{passive:!0}),x()),{checkUrl:L,teardown:()=>{var h;n.removeEventListener("click",g,!0),n.removeEventListener("submit",A,!0),(h=n.defaultView)==null||h.removeEventListener("popstate",L),f.length>0&&n.removeEventListener("scroll",x)}}}var un="__snt_editor_token";function dn(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(un):null}catch(e){return null}}function fn(e){try{sessionStorage.setItem(un,e)}catch(t){}}var lt="0.17.1",wn=5e3,eo=50,to=(()=>{try{if(typeof window=="undefined")return[];let e=window.SentientSnippet;return Array.isArray(e==null?void 0:e.q)?e.q:[]}catch(e){return[]}})(),z=null,$=null,ue={},pe=null,te=null,U=null,ie=null,B=null,ye=null,pn=!1,at=null,Ye=null,Xe=null,Re=!1,Ze=!1;function Sn(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function Se(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function Ae(e,t){return z?(z.personaAttributes&&B&&He(B.persona,B.band,e),We(ue,z.slots,e),Fe(ue,z.slots,e),pe?Ve(ue,pe,e,t):(qe(e,new Set),[])):[]}function An(e){var n;let t=new Map;for(let r of(n=z==null?void 0:z.sections)!=null?n:[])try{let s=e.querySelectorAll(r);s.length===1&&t.set(r,s[0])}catch(s){}return t}function ct(e,t){try{if(!e||e.length<2||new Set(e).size!==e.length)return;let n=An(t);if(n.size!==e.length)return;let r=[];for(let o of e){let c=n.get(o);if(!c)return;r.push(c)}let s=r[0].parentNode;if(!s||!r.every(o=>o.parentNode===s))return;let l=r.slice().sort((o,c)=>o.compareDocumentPosition(c)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let o=0;o<r.length;o++){let c=r[o];l[o]!==c&&(s.insertBefore(c,l[o]),l.splice(l.indexOf(c),1),l.splice(o,0,c))}}catch(n){}}function no(e,t){var n;if(t.length!==0)try{let r=(n=e.apiBase)!=null?n:"https://api.sentient-ui.com";fetch(`${r}/v1/locator-miss`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify({slots:t})}).catch(()=>{})}catch(r){}}function Pe(){return!!(z&&$&&z.sectionCapture!==!1&&(z.consent!==!1||Ze)&&!he())}function ro(){if(!$||!z||!Pe()||ie)return;let e=[];Ae(document,{contentAndOps:Re,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),dt();try{U==null||U(),U=Je($,z.apiKey,e)}catch(t){}}function dt(){if(typeof document=="undefined"||!Pe())return;let e;try{if(Ye&&Ye.length>0){let t=new Map;for(let n of Ye){if(n.urlMatch!==window.location.pathname)continue;let r=de(n.locator,document);r&&t.set(r,n.type)}t.size>0&&(e=n=>{var r;return(r=t.get(n))!=null?r:null})}}catch(t){}try{ie=Vt($,Y({apiKey:z.apiKey,apiBase:z.apiBase,doc:document,microSignals:!0},e?{typeOf:e}:{})),Xe=window.location.pathname}catch(t){}}function ft(){try{let e=[];if(U==null||U(),U=null,Ae(document,{contentAndOps:Re,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),ct(ye,document),e.length>0&&Pe())try{U=Je($,z.apiKey,e)}catch(t){}try{typeof window!="undefined"&&Xe!==null&&window.location.pathname!==Xe&&Pe()&&(ie==null||ie(),ie=null,dt())}catch(t){}}catch(e){}}function gn(){at===null&&(at=setTimeout(()=>{at=null,ft();try{te==null||te.checkUrl()}catch(e){}},eo))}function mn(){if(!(pn||typeof window=="undefined"||typeof history=="undefined")){pn=!0;try{let e=t=>{let n=history[t];history[t]=function(r,s,l){let o=n.call(this,r,s,l!=null?l:null);return gn(),o}};e("pushState"),e("replaceState"),window.addEventListener("popstate",gn)}catch(e){}}}function ut(e){let t={};for(let[n,r]of Object.entries(e.slots))t[n]=r.target?document.querySelectorAll(r.target).length:1;return t}function xn(e){return new URLSearchParams(e).get("sentient_editor")}function oo(){try{let t=Array.from(document.getElementsByTagName("script")).find(n=>/snippet(\.global)?\.js/.test(n.src));if(t!=null&&t.src)return t.src.replace(/snippet(\.global)?\.js/,"editor.global.js")}catch(e){}return null}function io(e,t){var n,r,s,l;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let i=document.createElement("meta");i.name="referrer",i.content="no-referrer",i.setAttribute("data-sentient-editor",""),((r=document.head)!=null?r:document.documentElement).appendChild(i)}catch(i){}let o=(s=e.editorSrc)!=null?s:oo();if(!o){yn();return}let c=document.createElement("script");c.src=o,c.async=!0,c.onerror=()=>yn(),((l=document.head)!=null?l:document.documentElement).appendChild(c)}catch(o){}}var hn="sentient-editor-load-notice";function yn(){var e;try{if(typeof document=="undefined"||document.getElementById(hn))return;let t=document.createElement("div");t.id=hn,t.textContent="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.",Object.assign(t.style,{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",cursor:"pointer"}),t.addEventListener("click",()=>t.remove()),((e=document.body)!=null?e:document.documentElement).appendChild(t),setTimeout(()=>t.remove(),1e4)}catch(t){}}function En(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let s=r.indexOf(":"),l=s===-1?"":r.slice(0,s),o=s===-1?"":r.slice(s+1);if(!(!l||!o))if(o.includes("=")){let c={};for(let i of o.split(",")){let[a,u]=i.split("=");a&&u&&(c[a]=u)}Object.keys(c).length&&(n[l]=c)}else n[l]=o}return Object.keys(n).length?n:null}function kn(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var vn="sentient-persona-preview-banner";function bn(e,t){var n;try{if(typeof document=="undefined"||document.getElementById(vn))return;let r=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),s=document.createElement("div");s.id=vn,s.setAttribute("role","status"),Object.assign(s.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",background:"#111827",color:"#fff",font:"13px/1 system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.14)"});let l=document.createElement("span");l.textContent=t?`\u201C${e}\u201D isn\u2019t in your personas \u2014 showing the default experience`:`Previewing as ${r}`;let o=document.createElement("button");o.type="button",o.textContent="Exit preview",Object.assign(o.style,{cursor:"pointer",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"inherit",padding:"4px 10px",borderRadius:"999px"}),o.addEventListener("click",()=>{try{let c=new URL(window.location.href);c.searchParams.delete("sentient_persona"),window.location.href=c.pathname+c.search+c.hash}catch(c){}}),s.appendChild(l),s.appendChild(o),((n=document.body)!=null?n:document.documentElement).appendChild(s)}catch(r){}}async function so(e,t){var a,u,f,d,g,A,L,x,w,k;let n=(a=e.apiBase)!=null?a:"https://api.sentient-ui.com",s=((u=e.registry)!=null?u:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([h,b])=>({id:h,dims:b.dims}))},l=await Sn(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(s)}).then(h=>h.ok?h.json():null).catch(()=>null),wn);if(!l){Se(e,"persona preview: explain unavailable \u2014 page left as-is");return}let o=l;ue=(f=o.slots)!=null?f:{},pe=(d=o.slotConfig)!=null?d:null,Te(o.palette);let c=(L=(A=(g=o.personaAttributes)==null?void 0:g.persona)!=null?A:o.persona)!=null?L:t,i=(w=(x=o.personaAttributes)==null?void 0:x.confidence)!=null?w:"high";B={persona:c,band:i},Ae(document),Re=!0,In(e),o.recognized===!1?bn(t,!0):bn((k=o.personaDisplay)!=null?k:c)}function In(e){let t={goal(n,r){try{$==null||$.goal(n,r)}catch(s){}},componentGoal(n,r){try{$==null||$.componentGoal(n,r)}catch(s){}},grantConsent(){try{it(e.apiKey)}catch(n){}Ze=!0;try{ro()}catch(n){}},revokeConsent(){try{ie==null||ie(),ie=null,Xe=null,U==null||U(),U=null,te==null||te.teardown(),te=null,Ze=!1,$==null||$.destroy()}catch(n){}},reapply:ft,getState(){var n,r;return{apiKey:e.apiKey,persona:(n=B==null?void 0:B.persona)!=null?n:null,band:(r=B==null?void 0:B.band)!=null?r:null,slots:ue,matchCounts:ut(e),consent:e.consent!==!1}}};window.SentientSnippet=t;for(let n of to.splice(0))try{n[0]==="goal"&&t.goal(n[1],n[2])}catch(r){}}async function _n(){var e,t,n,r,s,l;try{let o=ze(window.sentient);if(!o)return;z=o,Re=!1,ye=null,Te(null),Ze=!1;let c=typeof window!="undefined"?xn(window.location.search):null;if(c){fn(c);try{let b=new URL(window.location.href);b.searchParams.delete("sentient_editor"),window.history.replaceState(null,"",b.pathname+b.search+b.hash)}catch(b){}}let i=c!=null?c:dn();if(i){io(o,i),Se(o,"editor mode");return}let a=typeof window!="undefined"?En(window.location.search):null;if(a){ue=a,B=null,Ae(document),mn(),Se(o,"preview mode",a);return}let u=typeof window!="undefined"?kn(window.location.search):null;if(u){await so(o,u),Se(o,"persona preview",u);return}let f=(e=o.registry)!=null?e:Object.keys(o.slots).length===0,d=Ue(o.apiKey);d&&(B={persona:d.persona,band:d.band},ue=d.slots,d.slotConfig&&(pe=d.slotConfig),d.palette&&Te(d.palette),Ae(document,{contentAndOps:!1}),d.layoutOrder&&(ye=d.layoutOrder,ct(ye,document)));let g=Ge({apiKey:o.apiKey,context:o.context,consent:o.consent,preConsentBehavior:o.preConsentBehavior,debug:o.debug,persona:o.persona});$=g,In(o),mn();let A=Object.entries(o.slots).map(([b,I])=>({id:b,dims:I.dims})),L=lt!=="0.0.0-dev"?{v:lt}:{},x=Array.from(An(document).keys()),w=await Sn(g.decide(Y(Y(Y({slots:A},L),x.length>=2?{sections:x}:{}),f?{slotsFrom:"registry"}:{})),wn);if(!w){Se(o,"decide timeout/null \u2014 snapshot state stands",ut(o));return}let k=g.getPersona();k?B={persona:k.persona,band:k.band}:w.persona&&(B={persona:w.persona,band:"low"}),ue=w.slots,f?pe=(t=w.slotConfig)!=null?t:null:w.slotConfig&&(pe=w.slotConfig),w.palette&&Te(w.palette);let h=[];if(no(o,Ae(document,{onApplied:(b,I,M)=>h.push({slotId:b,arm:I,el:M})})),ye=(n=w.layoutOrder)!=null?n:ye,ct(ye,document),Re=!0,w.goals&&w.goals.length>0&&o.consent!==!1&&$)try{te==null||te.teardown(),te=cn(w.goals,$,document,o.apiKey)}catch(b){}if(Ye=(r=w.sectionMap)!=null?r:null,Pe()){dt();try{U==null||U(),U=Je($,o.apiKey,h)}catch(b){}}Se(o,"applied",{persona:B,slots:ue,matches:ut(o)}),Oe(o.apiKey,Y(Y({v:1,persona:(s=B==null?void 0:B.persona)!=null?s:w.persona,band:(l=B==null?void 0:B.band)!=null?l:"low",slots:w.slots,layoutOrder:w.layoutOrder,savedAt:Date.now()},pe?{slotConfig:pe}:{}),w.palette?{palette:w.palette}:{}))}catch(o){}}if(typeof window!="undefined"&&window.sentient){let e=window;e.__sentientInitialized||(e.__sentientInitialized=!0,_n())}return Pn(ao);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentientui/snippet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "SentientUI Style-rung snippet for non-React sites — persona attributes and adaptive style tokens from one script tag",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"tsx": "^4.19.2",
|
|
25
25
|
"typescript": "^5.7.2",
|
|
26
26
|
"vitest": "^2.1.8",
|
|
27
|
-
"@sentientui/core": "0.
|
|
27
|
+
"@sentientui/core": "0.21.2"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "tsup",
|