@sentientui/snippet 0.13.0 → 0.14.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/dist/editor.global.js +7 -7
- package/dist/snippet.global.js +2 -2
- package/package.json +2 -2
package/dist/editor.global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var SentientSnippet=(()=>{var
|
|
2
|
-
`)}function
|
|
1
|
+
"use strict";var SentientSnippet=(()=>{var kt=Object.defineProperty,be=Object.defineProperties,xe=Object.getOwnPropertyDescriptor,ve=Object.getOwnPropertyDescriptors,ke=Object.getOwnPropertyNames,Yt=Object.getOwnPropertySymbols;var Zt=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var Vt=(e,t,n)=>t in e?kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,D=(e,t)=>{for(var n in t||(t={}))Zt.call(t,n)&&Vt(e,n,t[n]);if(Yt)for(var n of Yt(t))Ee.call(t,n)&&Vt(e,n,t[n]);return e},ot=(e,t)=>be(e,ve(t));var we=(e,t)=>{for(var n in t)kt(e,n,{get:t[n],enumerable:!0})},Se=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ke(t))!Zt.call(e,s)&&s!==n&&kt(e,s,{get:()=>t[s],enumerable:!(o=xe(t,s))||o.enumerable});return e};var Le=e=>Se(kt({},"__esModule",{value:!0}),e);var Je={};we(Je,{buildStyleOps:()=>de,clearTargetHighlights:()=>ft,computeMoveAnchors:()=>Tt,deriveSlotId:()=>Ct,drawTargetHighlights:()=>ae,mount:()=>ue,styleFieldError:()=>ce});function Ce(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 Te(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 Be=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function V(e,t){var s;if(e.urlMatch&&!Ce(t).includes(e.urlMatch))return null;let n=[];if(e.id){let c=t.getElementById(e.id);n=c?[c]:[]}if(n.length===0&&((s=e.dataAttr)!=null&&s.name)&&Be.test(e.dataAttr.name))try{let c=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${c}"]`))}catch(c){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(c){n=[]}if(n.length!==1)return null;let o=n[0];return e.fingerprint&&!Te(o,e.fingerprint)?null:o}function Jt(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],c=s>="0"&&s<="9";o===0&&c||o===1&&c&&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 $e(e,t){if(e.id)return`#${Jt(e.id)}`;let n=[],o=e,s=0;for(;o&&o!==t.body&&o!==t.documentElement&&s<6;){if(o.id){n.unshift(`#${Jt(o.id)}`);break}let c=o.tagName.toLowerCase(),u=o.parentElement;if(u){let E=Array.from(u.children).filter(h=>h.tagName===o.tagName);E.length>1&&(c+=`:nth-of-type(${E.indexOf(o)+1})`)}n.unshift(c),o=o.parentElement,s++}return n.join(" > ")}function pt(e,t){var s;let n={v:1};e.id&&(n.id=e.id);for(let c of["data-framer-name","data-w-id","data-sentient-name"]){let u=e.getAttribute(c);if(u){n.dataAttr={name:c,value:u};break}}n.selector=$e(e,t);let o=((s=e.textContent)!=null?s:"").trim().replace(/\s+/g," ").slice(0,80);return n.fingerprint=D({tag:e.tagName.toLowerCase()},o?{text:o}:{}),n}function Et(e,t,n){return V(e,n)===t}var Ae="__snt_editor_token";function wt(){try{sessionStorage.removeItem(Ae)}catch(e){}}var Kt={color:"color",background:"background",fontSize:"font-size",fontWeight:"font-weight",textAlign:"text-align",padding:"padding",margin:"margin",borderRadius:"border-radius",width:"width",height:"height",maxWidth:"max-width",border:"border",boxShadow:"box-shadow",opacity:"opacity",lineHeight:"line-height",letterSpacing:"letter-spacing",textTransform:"text-transform",gap:"gap",fontFamily:"font-family"},_e=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function St(e){var t;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;for(let n of e.matchAll(/([A-Za-z-]*)\(/g))if(!_e.test((t=n[1])!=null?t:""))return!1;return!0}var Xt=/^https:\/\//i,Qt=new Map,G=null;function Re(e){return e.replace(/["\\]/g,"\\$&")}function Ie(e){var t;(!G||!G.isConnected)&&(G=e.querySelector("style[data-sentient-ops]"),G||(G=e.createElement("style"),G.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(G))),G.textContent=[...Qt.entries()].map(([n,o])=>`[data-snt-e="${Re(n)}"]{${o}}`).join(`
|
|
2
|
+
`)}function te(e,t,n,o){var E;let s=!1,c=(E=t.moveBefore)!=null?E:t.moveAfter;if(c){let h=V(c,o);!h||h===e||h.parentElement!==e.parentElement||!e.parentElement?s=!0:t.moveBefore?e.parentElement.insertBefore(e,h):e.parentElement.insertBefore(e,h.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&Xt.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&Xt.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let u=[];if(t.hidden&&u.push("display:none !important"),t.style)for(let[h,O]of Object.entries(t.style)){let C=Kt[h];C&&typeof O=="string"&&St(O)&&u.push(`${C}:${O.trim()} !important`)}return u.length>0&&(e.setAttribute("data-snt-e",n),Qt.set(n,u.join(";")),Ie(o)),{anchorMiss:s}}function It(e){let t=e.steps.length,n=e.status==="active"?"":` (${e.status})`;return`${e.display_name} \u2014 ${t} step${t===1?"":"s"}${n}`}function Mt(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 ee(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function Me(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"funnel"}function ne(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:Me(n),body:{displayName:n.slice(0,128),steps:t.map(o=>({goalId:o}))}}:{ok:!1,error:"Give the funnel a name."}}function ie(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 Lt(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40)}function Ct(e,t,n){var E,h;let o=t.id||((E=t.dataAttr)==null?void 0:E.value)||((h=n.textContent)!=null?h:"").trim()||n.tagName,s=Lt(o)||"el",c=ie(JSON.stringify(t));return`${e}-${s}-${c}`.slice(0,128)}var He="sentient-editor-highlight",Pe="sentient-editor-selection",rt="sentient-editor-panel",Bt="sentient-editor-toast",oe="sentient-editor-styles",Pt="sentient-editor-target-highlight",Oe=10,ze="Editor session expired. Reopen it from your dashboard to keep editing \u2014 your saved changes are safe.",Ne="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.";function se(){var t;if(document.getElementById(oe))return;let e=document.createElement("style");e.id=oe,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
|
+
#${rt} {
|
|
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
|
+
#${rt} .sntedi-dot { animation: sntedi-dot 1.4s ease-in-out infinite; }
|
|
20
|
+
#${Bt} { 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
|
+
#${rt}, #${rt} .sntedi-dot, #${Bt} { animation: none !important; }
|
|
23
23
|
}
|
|
24
|
-
`,((t=document.head)!=null?t:document.documentElement).appendChild(e)}function Yt(e){var o,i;Zt(),(o=document.getElementById(xt))==null||o.remove();let t=l("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=xt;let n=l("span",{width:"9px",height:"9px",marginTop:"4px",borderRadius:"50%",background:"#f59e0b",flex:"0 0 auto"});t.append(n,l("div",{},e)),((i=document.body)!=null?i:document.documentElement).appendChild(t),t.addEventListener("click",()=>t.remove()),setTimeout(()=>t.remove(),1e4)}function Ce(){let e=window.__sentientEditor;return e&&typeof e.token=="string"&&typeof e.apiBase=="string"?e:null}async function Te(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 K(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 Ct=[];async function Ae(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 Ct=Array.isArray(n.fonts)?n.fonts.filter(o=>typeof o=="string"):[],Array.isArray(n.targets)?n.targets:[]}catch(t){return[]}}function st(e=document){for(let t of Array.from(e.querySelectorAll(`.${Lt}`)))t.remove()}function Kt(e,t=document){var o;st(t);let n=0;for(let i of e){if(n>=we)break;let a=D(i.locator,t);if(!a)continue;let d=a.getBoundingClientRect(),h=l("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${d.left}px`,top:`${d.top}px`,width:`${d.width}px`,height:`${d.height}px`,border:"2px dashed #10b981",background:"rgba(16,185,129,0.08)"});h.className=Lt;let p=l("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${d.left}px`,top:`${Math.max(0,d.top-20)}px`,padding:"2px 6px",borderRadius:"4px",background:"#10b981",color:"#fff",font:"11px system-ui, sans-serif",whiteSpace:"nowrap"},i.label);p.className=Lt,((o=t.body)!=null?o:t.documentElement).append(h,p),n+=1}}function yt(e,t){let n=e.previousElementSibling,o=e.nextElementSibling,i=n?it(n,t):null,a=o?it(o,t):null;return{prevEl:n,nextEl:o,prevLocator:n&&i&&ft(i,n,t)?i:null,nextLocator:o&&a&&ft(a,o,t)?a:null}}var Xt=["color","background","fontSize","fontWeight","borderRadius","textAlign","fontFamily"],Be=/^(0|\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|pt))$/i,$e=new Set(["left","center","right","justify","start","end"]),Re=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,_e=/^(rgb|rgba|hsl|hsla)\(/i;function Ie(e){return Re.test(e)||_e.test(e)}function Jt(e,t){switch(e){case"fontSize":case"borderRadius":return Be.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 $e.has(t.toLowerCase())?null:"Choose left, center, right, or justify.";case"color":case"background":return Ie(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 Qt(e){let t={},n={};for(let o of Xt){let i=e[o];if(typeof i!="string")continue;let a=i.trim();if(a==="")continue;if(!mt(a)){n[o]="That value isn\u2019t allowed.";continue}let d=Jt(o,a);if(d){n[o]=d;continue}t[o]=a}return{style:t,errors:n}}function l(e,t,n){let o=document.createElement(e);return Object.assign(o.style,t),n!==void 0&&(o.textContent=n),o}function te(e){var Ht;let t=null,n=l("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #6366f1",background:"rgba(99,102,241,0.12)",display:"none"});n.id=Ee;let o=l("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #10b981",background:"rgba(16,185,129,0.10)",borderRadius:"4px",display:"none"});o.id=ke;let i=()=>{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`})},a=()=>i();Zt();let d=l("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)"});d.id=X;let h=l("span",{width:"9px",height:"9px",borderRadius:"50%",background:"#34d399",display:"inline-block",flex:"0 0 auto"});h.className="sntedi-dot";let p=l("div",{display:"flex",alignItems:"center",gap:"8px",fontWeight:"700",fontSize:"14px",marginBottom:"6px"});p.append(h,l("span",{},"SentientUI editor"));let B=l("div",{opacity:"0.85",marginBottom:"8px"},"Click any element on the page to adapt it."),E=!1,j=l("button",x("#374151"),"Pause selecting");j.onclick=()=>{E=!E,j.textContent=E?"Resume selecting":"Pause selecting",E?(n.style.display="none",st(document),u("Selection paused \u2014 browse normally, then resume.")):u("Click any element on the page to adapt it.")};let G=l("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"}),F=l("div",{fontSize:"12px",marginBottom:"8px",minHeight:"16px"}),U=r=>l("div",{fontSize:"10px",letterSpacing:"0.08em",textTransform:"uppercase",opacity:"0.55",marginTop:"10px",marginBottom:"2px"},r),C=l("button",x("#6366f1"),"Test different text here"),$=l("button",x("#374151"),"Change style"),R=l("button",x("#374151"),"Track clicks as a goal"),_=l("button",x("#374151"),"Track form submissions as a goal"),J=l("button",x("#374151"),"Track page visits as a goal"),w=l("button",x("#374151"),"Move up"),f=l("button",x("#374151"),"Move down"),S=l("button",x("#6366f1"),"Save this arrangement"),L=l("button",x("#374151"),"Undo"),Tt=l("button",pt(Z({},x("transparent")),{opacity:"0.6"}),"Close editor"),O=l("button",x("#10b981"),"Publish now \u2014 go live"),z=l("button",x("#10b981"),"Start tracking now");for(let r of[C,$,R,w,f])r.disabled=!0;let At=[C,$,R,_,w,f];for(let r of At)r.style.display="none";S.style.display="none",L.style.display="none",O.style.display="none",z.style.display="none",d.append(p,B,j,G,F,U("Content & style"),C,$,U("Track a goal"),R,_,J,U("Move"),w,f,S,L,O,z,Tt),((Ht=document.body)!=null?Ht:document.documentElement).append(n,o,d);let I=l("div",{marginTop:"10px"});d.append(I);let Q=()=>{I.textContent=""},Bt=(r,s,c)=>{var Y;Q();let g={},b={},v={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 m of r){let P=l("label",{display:"block",fontSize:"12px",opacity:"0.85",marginTop:"8px"},m.label);if(I.append(P),m.type==="select"){let y=l("select",v);y.setAttribute("data-field",m.key);let V=document.createElement("option");V.value="",V.textContent="\u2014 no change \u2014",y.append(V);for(let Ot of(Y=m.options)!=null?Y:[]){let St=document.createElement("option");St.value=Ot,St.textContent=Ot,y.append(St)}g[m.key]=()=>y.value,I.append(y)}else if(m.type==="color"){let y=l("input",pt(Z({},v),{padding:"2px",height:"34px"}));y.type="color",y.setAttribute("data-field",m.key);let V=!1;y.addEventListener("input",()=>{V=!0}),g[m.key]=()=>V?y.value:"",I.append(y)}else{let y=l("input",v);y.setAttribute("data-field",m.key),m.value!==void 0&&(y.value=m.value),g[m.key]=()=>y.value,I.append(y)}let N=l("div",{fontSize:"11px",color:"#fca5a5",marginTop:"3px",display:"none"});N.setAttribute("data-feedback",m.key),b[m.key]=N,I.append(N)}let A=(m,P)=>{let N=b[m];N&&(N.textContent=P!=null?P:"",N.style.display=P?"block":"none")},M=l("button",x("#6366f1"),s),rt=l("button",pt(Z({},x("transparent")),{opacity:"0.6"}),"Cancel");M.onclick=()=>c(Object.fromEntries(Object.entries(g).map(([m,P])=>[m,P()])),A),rt.onclick=Q,I.append(M,rt)},u=(r,s=!0)=>{F.textContent=r,F.style.color=s?"#a7f3d0":"#fca5a5"},at=(r,s)=>{r==="ok"?u(s,!0):u(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)},lt=null,vt=r=>{lt=r,O.style.display="block"};O.onclick=async()=>{if(!lt)return;O.disabled=!0,u("Publishing\u2026");let r=await K(e,`/v1/editor/slots/${encodeURIComponent(lt)}/publish`,{});O.disabled=!1,r==="ok"?(u("\u2713 Published \u2014 live for new visitors.",!0),O.style.display="none",lt=null):u(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 k=null,tt=!1,et=null,nt=null,T=null,W=null,ot=null,ct=null,q=!1,$t=(r,s)=>tt?r?"":`Nothing to swap with ${s} \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.",Rt=()=>{w.disabled=!tt||!T,f.disabled=!tt||!W,w.title=w.disabled?$t(T,"above"):"",f.title=f.disabled?$t(W,"below"):""},Et=r=>{S.style.display=r?"block":"none",L.style.display=r?"block":"none",Rt()},_t=()=>{if(q&&t&&ot&&ot.insertBefore(t,ct),q=!1,ot=null,ct=null,t){let r=yt(t,document);et=r.prevEl,nt=r.nextEl,T=r.prevLocator,W=r.nextLocator}i(),Et(!1)},It=r=>{if(E)return;let s=r.target;if(!s||d.contains(s)||s===n)return;st(document);let c=s.getBoundingClientRect();Object.assign(n.style,{display:"block",left:`${c.left}px`,top:`${c.top}px`,width:`${c.width}px`,height:`${c.height}px`})},ne=r=>{var c;let s=((c=r.textContent)!=null?c:"").trim().replace(/\s+/g," ");return s?s.length>40?`${s.slice(0,37)}\u2026`:s:r.tagName.toLowerCase()},Mt=r=>{if(E)return;let s=r.target;if(!s||d.contains(s))return;r.preventDefault(),r.stopPropagation(),_t(),Q(),t=s,k=it(s,document);let c=ft(k,s,document);tt=c,i(),G.style.display="block",G.textContent=`Selected: ${ne(s)}`,u(c?"\u2713 Matches exactly 1 element":"\u26A0 Couldn\u2019t target this element uniquely",c);for(let A of At)A.style.display="block";let g=s.childElementCount===0;C.disabled=!c||!g,C.title=c?g?"":"This element contains other elements, so testing text here would replace them. Pick the text itself (e.g. the heading), not its container.":"",$.disabled=!c,R.disabled=!c;let b=s.closest("form");_.style.display=b?"block":"none",_.disabled=!b;let v=yt(s,document);et=v.prevEl,nt=v.nextEl,T=v.prevLocator,W=v.nextLocator,Rt()};C.onclick=()=>{var c,g;if(!t||!k)return;let r=k,s=(g=(c=t.textContent)==null?void 0:c.trim())!=null?g:"";Bt([{key:"current",label:"Current wording",value:s},{key:"alt",label:"Alternative wording to test",value:""}],"Save draft",async b=>{let v=b.alt.trim();if(!v){u("\u26A0 Enter alternative wording to test.",!1);return}if(v===b.current.trim()){u("\u26A0 Enter different wording \u2014 the alternative matches the current text.",!1);return}let A=bt("text",r,t);u("Saving\u2026");let M=await K(e,`/v1/editor/slots/${encodeURIComponent(A)}`,{kind:"arms",target:r,draftConfig:{arms:[{id:"a",displayName:"Original",ops:{text:b.current}},{id:"b",displayName:"Alternative",ops:{text:b.alt}}]}});M==="ok"&&(Q(),vt(A)),at(M,"\u2713 Saved as a draft. Click \u201CPublish now\u201D to go live.")})};let dt=null,oe=r=>{dt=r,z.style.display="block"};z.onclick=async()=>{if(!dt)return;z.disabled=!0,u("Activating\u2026");let r=await K(e,`/v1/editor/goals/${encodeURIComponent(dt)}/publish`,{});z.disabled=!1,r==="ok"?(u("\u2713 Tracking is live \u2014 it counts from your next visitor.",!0),z.style.display="none",dt=null):u(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 kt=(r,s)=>`${ht(r)||"goal"}-${Vt(s)}`.slice(0,128),wt=async(r,s)=>{u("Saving\u2026");let c=await K(e,`/v1/editor/goals/${encodeURIComponent(r)}`,s);c==="ok"&&oe(r),at(c,"\u2713 Goal saved. Click \u201CStart tracking now\u201D to go live.")};R.onclick=()=>{var s;if(!t||!k)return;let r=kt(((s=t.textContent)!=null?s:"").trim()||"element-clicked",JSON.stringify(k));wt(r,{event:"click",locator:k})},_.onclick=()=>{var g,b;let r=t==null?void 0:t.closest("form");if(!r)return;let s=it(r,document),c=(b=(g=r.getAttribute("id"))!=null?g:r.getAttribute("name"))!=null?b:"form-submitted";wt(kt(c,JSON.stringify(s)),{event:"form_submit",locator:s})},J.onclick=()=>{let r=window.location.pathname||"/",s=ht(r)?`reached-${ht(r)}`:"page-visited";wt(kt(s,r),{event:"url_reached",urlPattern:r})},$.onclick=()=>{if(!t||!k)return;let r=k;Bt([{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:Ct.length?`Font (this site has: ${Ct.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(s,c)=>{var rt;let{style:g,errors:b}=Qt(s),v=!1;for(let Y of Xt)c(Y,(rt=b[Y])!=null?rt:null),b[Y]&&(v=!0);if(v){u("\u26A0 Fix the highlighted field(s).",!1);return}if(Object.keys(g).length===0){u("\u26A0 Enter at least one style change.",!1);return}let A=bt("style",r,t);u("Saving\u2026");let M=await K(e,`/v1/editor/slots/${encodeURIComponent(A)}`,{kind:"arms",target:r,draftConfig:{arms:[{id:"a",displayName:"Current look",ops:{}},{id:"b",displayName:"New look",ops:{style:g}}]}});M==="ok"&&(Q(),vt(A)),at(M,"\u2713 Saved as a draft. Click \u201CPublish now\u201D to go live.")})};let Pt=r=>{if(!t)return;let s=t.parentElement;if(!s)return;q||(ot=s,ct=t.nextSibling,q=!0),r==="up"&&et?s.insertBefore(t,et):r==="down"&&nt&&s.insertBefore(t,nt.nextSibling);let c=yt(t,document);et=c.prevEl,nt=c.nextEl,T=c.prevLocator,W=c.nextLocator;try{t.scrollIntoView({block:"nearest",behavior:"smooth"})}catch(g){}i(),Et(!0),u("Previewing the new position \u2014 keep moving, save, or undo.")};w.onclick=()=>Pt("up"),f.onclick=()=>Pt("down"),L.onclick=()=>{_t(),u("Move undone \u2014 back to the original position.")},S.onclick=async()=>{if(!t||!k||!q||!tt)return;let r=T?"moveAfter":"moveBefore",s=T!=null?T:W;if(!s){u("\u26A0 Couldn\u2019t anchor the new position \u2014 nudge it next to a section with an id.",!1);return}let c=bt("move",k,t);u("Saving\u2026");let g=await K(e,`/v1/editor/slots/${encodeURIComponent(c)}`,{kind:"arms",target:k,draftConfig:{arms:[{id:"a",ops:{}},{id:"b",ops:{[r]:s}}]}});g==="ok"&&(q=!1,ot=null,ct=null,Et(!1),vt(c)),at(g,"\u2713 Saved as a draft. Click \u201CPublish now\u201D to go live.")};let re=()=>{var r;document.removeEventListener("mousemove",It,!0),document.removeEventListener("click",Mt,!0),window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a),st(document),n.remove(),o.remove(),d.remove(),window.__sentientEditor=null,(r=document.querySelector("meta[data-sentient-editor]"))==null||r.remove(),gt()};Tt.onclick=re,document.addEventListener("mousemove",It,!0),document.addEventListener("click",Mt,!0),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a)}function x(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 ee="sentient-preview-bar";async function Me(e,t){var B,E,j,G,F,U,C,$,R,_,J,w;let n=null;try{let f=await fetch(`${e.apiBase}/v1/editor/slots`,{headers:{authorization:`Bearer ${e.token}`}});f.ok&&(n=(E=((B=(await f.json()).slots)!=null?B:[]).find(L=>L.slot_id===t&&L.kind==="arms"))!=null?E:null)}catch(f){}let o=l("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=ee;let i=l("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");i.onclick=()=>{gt();let f=new URL(location.href);for(let S of["sentient_editor","sentient_preview","sentient_arm"])f.searchParams.delete(S);location.assign(f.toString())};let a=(U=(F=(j=n==null?void 0:n.draft_config)==null?void 0:j.arms)!=null?F:(G=n==null?void 0:n.published_config)==null?void 0:G.arms)!=null?U:[];if(!n||a.length===0){o.append(l("span",{},"Couldn\u2019t load this preview \u2014 reopen it from your dashboard."),i),((C=document.body)!=null?C:document.documentElement).append(o);return}let d=new URLSearchParams(location.search).get("sentient_arm"),h=(R=($=a.find(f=>f.id===d))!=null?$:a[1])!=null?R:a[0];o.append(l("span",{fontWeight:"700"},`Previewing: ${(_=n.display_name)!=null?_:n.slot_id}`));let p=n.target&&typeof n.target=="object"?D(n.target,document):null;if(!p)o.append(l("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{Wt(p,h.ops,`preview-${n.slot_id}`,document);try{p.scrollIntoView({block:"center"})}catch(f){}for(let f of a){let S=l("button",{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.3)",cursor:"pointer",background:f.id===h.id?"#6366f1":"transparent",color:"#fff",font:"12px system-ui, sans-serif"},(J=f.displayName)!=null?J:f.id);S.onclick=()=>{let L=new URL(location.href);L.searchParams.set("sentient_arm",f.id),location.assign(L.toString())},o.append(S)}}o.append(i),((w=document.body)!=null?w:document.documentElement).append(o)}async function Pe(){if(typeof document=="undefined")return;let e=Ce();if(!e)return;let t=await Te(e);if(!t.ok){t.unauthorized?(gt(),Yt(Se)):Yt(Le);return}let n=new URLSearchParams(location.search).get("sentient_preview");if(n){document.getElementById(ee)||await Me(e,n);return}if(document.getElementById(X))return;te(e);let o=await Ae(e);Kt(o,document)}Pe();return pe(He);})();
|
|
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);})();
|
package/dist/snippet.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var SentientSnippet=(()=>{var we=Object.defineProperty;var en=Object.getOwnPropertyDescriptor;var tn=Object.getOwnPropertyNames,Ye=Object.getOwnPropertySymbols;var Ze=Object.prototype.hasOwnProperty,nn=Object.prototype.propertyIsEnumerable;var Xe=(e,t,n)=>t in e?we(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))Ze.call(t,n)&&Xe(e,n,t[n]);if(Ye)for(var n of Ye(t))nn.call(t,n)&&Xe(e,n,t[n]);return e};var Qe=(e,t)=>()=>(e&&(t=e(e=0)),t);var et=(e,t)=>{for(var n in t)we(e,n,{get:t[n],enumerable:!0})},rn=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of tn(t))!Ze.call(e,l)&&l!==n&&we(e,l,{get:()=>t[l],enumerable:!(r=en(t,l))||r.enumerable});return e};var on=e=>rn(we({},"__esModule",{value:!0}),e);var sn,an,ln,tt,cn,un,nt,O,ge,Se=Qe(()=>{"use strict";sn=Object.defineProperty,an=Object.defineProperties,ln=Object.getOwnPropertyDescriptors,tt=Object.getOwnPropertySymbols,cn=Object.prototype.hasOwnProperty,un=Object.prototype.propertyIsEnumerable,nt=(e,t,n)=>t in e?sn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,O=(e,t)=>{for(var n in t||(t={}))cn.call(t,n)&&nt(e,n,t[n]);if(tt)for(var n of tt(t))un.call(t,n)&&nt(e,n,t[n]);return e},ge=(e,t)=>an(e,ln(t))});var dt={};et(dt,{LOCAL_ENGINE_AVAILABLE:()=>fn,createLocalEngine:()=>gn});function gn(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var fn,pt=Qe(()=>{"use strict";fn=!1});var pr={};et(pr,{applyPersonaAttributes:()=>_e,applyRegistrySlots:()=>Re,applySlotArms:()=>Pe,applySlotAttributes:()=>Te,parseEditorToken:()=>Ft,parsePersonaPreview:()=>Yt,parsePreview:()=>Ht,parseSnippetConfig:()=>Ce,reapply:()=>Fe,run:()=>Zt,version:()=>ze});Se();function xe(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function rt(e){if(e.length===0)return null;let t={};for(let n of e.split("|")){let r=n.indexOf("=");if(r<=0||r!==n.lastIndexOf("=")||r===n.length-1)return null;let l=n.slice(0,r);if(l in t)return null;t[l]=n.slice(r+1)}return t}function Ne(e){var t,n,r;if(e.arms)return typeof e.baseline=="string"?e.baseline:(t=e.arms[0])!=null?t:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return xe(e.baseline);if(typeof e.baseline=="string")return e.baseline;let l={};for(let[o,s]of Object.entries((n=e.dims)!=null?n:{}))l[o]=(r=s[0])!=null?r:"";return xe(l)}function ot(e,t){var n,r;return e.dims!=null?(r=(n=rt(t))!=null?n:rt(Ne(e)))!=null?r:{}:t}function se(e){return e>=.3?e<.7?"medium":"high":"low"}var dn=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function it(e){return pn(e)!==null}function pn(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=dn.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function st(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function at(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(l){}let r=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(n){return"direct"}}function lt(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function ct(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function $e(e){return O(O(O({id:e.id},e.arms?{arms:[...e.arms]}:{}),e.dims?{dims:Object.fromEntries(Object.entries(e.dims).map(([t,n])=>[t,[...n]]))}:{}),e.baseline!==void 0?{baseline:e.baseline}:{})}function Be(e){let t=$e(e);return ot(t,Ne(t))}function ut(e){return typeof e=="string"?e:xe(e)}Se();function gt(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}try{if(typeof crypto!="undefined"&&typeof crypto.getRandomValues=="function"){let e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t="";for(let n=0;n<16;n++)t+=e[n].toString(16).padStart(2,"0"),(n===3||n===5||n===7||n===9)&&(t+="-");return t}}catch(e){}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function mt(e){return e?`_${e.slice(0,12)}`:""}var mn="_snt_uid",hn=365,yn="_snt_uid";function vn(){return gt()}function bn(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function wn(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function Sn(e){try{return localStorage.getItem(e)}catch(t){return null}}function xn(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function An(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function kn(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function In(e){try{sessionStorage.removeItem(e)}catch(t){}}function En(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function On(e){try{localStorage.removeItem(e)}catch(t){}}function Cn(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var _n={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ht(e){var t,n,r,l,o,s;if(typeof window=="undefined")return _n;let u=mt(e==null?void 0:e.apiKey),i=(t=e==null?void 0:e.cookieName)!=null?t:`${mn}${u}`,a=`${yn}${u}`,c=((n=e==null?void 0:e.cookieTTLDays)!=null?n:hn)*24*60*60,d=_=>_&&_.length>0?_:null,m=(s=(o=(l=(r=d(bn(i)))!=null?r:d(Sn(a)))!=null?l:d(An(a)))!=null?o:d(e==null?void 0:e.ssrSessionId))!=null?s:vn();wn(i,m,c);let g=xn(a,m),b=En(i),w=g?!1:kn(a,m),A=!g&&!b&&!w;return{getSessionId:()=>m,isEphemeral:()=>A,destroy:()=>{m=null,Cn(i),On(a),In(a)}}}function yt(e){return`_snt_retry_${e.slice(0,12)}`}var Tn={push:()=>{},flush:()=>{},destroy:()=>{}};function Pn(e,t){try{let n=localStorage.getItem(t);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?(localStorage.removeItem(t),r.slice(-e)):[]}catch(n){return[]}}function Ke(e,t,n){try{let r=(()=>{try{let s=localStorage.getItem(n);if(!s)return[];let u=JSON.parse(s);return Array.isArray(u)?u:[]}catch(s){return[]}})(),l=new Map;for(let s of r)l.set(s.id,s);for(let s of e)l.set(s.id,s);let o=[...l.values()].slice(-t);localStorage.setItem(n,JSON.stringify(o))}catch(r){}}function Rn(e,t){try{let n=localStorage.getItem(t);if(!n)return;let r=JSON.parse(n);if(!Array.isArray(r))return;let l=new Set(e),o=r.filter(s=>!l.has(s.id));if(o.length===r.length)return;o.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(o))}catch(n){}}function Ln(e){var t,n,r;if(typeof window=="undefined")return Tn;let l=(t=e.flushIntervalMs)!=null?t:5e3,o=(n=e.maxBatchSize)!=null?n:20,s=(r=e.maxRetrySize)!=null?r:100,u=e.ingestUrl,i=e.apiKey,a=yt(i),c=[],d=new Set,m=[],g=f=>{for(let x of f)b.delete(x),!d.has(x)&&(d.add(x),m.push(x));for(;m.length>500;){let x=m.shift();x&&d.delete(x)}Rn(f,a)},b=new Set,w=f=>{d.has(f.id)||b.has(f.id)||(b.add(f.id),c.push(f))},A=f=>{for(let x of f)d.has(x.id)||(b.add(x.id),c.push(x))},_=Pn(s,a);for(let f of _)w(f);let S=0,I=0,N=f=>{if(f.length===0)return;let x=JSON.stringify(f),j=f.map(p=>p.id),J;try{J=fetch(u,{method:"POST",keepalive:!0,body:x,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}})}catch(p){Ke(f,s,a),A(f),I++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(I,6));return}let q=p=>{if(p.ok||p.status>=400&&p.status<500&&p.status!==429){g(j),I=0,S=0;return}Ke(f,s,a),A(f),I++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(I,6))};J instanceof Promise?J.then(q).catch(()=>{Ke(f,s,a),A(f),I++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(I,6))}):q(J)},Y=typeof TextEncoder!="undefined"?new TextEncoder:null,le=f=>Y?Y.encode(f).length:f.length,re=f=>{let x=[],j=2;for(let J of f){let q=le(JSON.stringify(J))+1;if(x.length>0&&j+q>57344||x.length>=o)break;x.push(J),j+=q}return x},T=()=>{try{if(Date.now()<S)return;for(;c.length>0&&!(Date.now()<S);){let f=c.filter(j=>!d.has(j.id));if(c.length=0,f.length===0)break;let x=re(f);if(x.length===0)break;x.length<f.length&&c.push(...f.slice(x.length)),N(x)}}catch(f){}},X=!0,v=null;v=setInterval(()=>{X&&T()},l);let h=()=>{document.visibilityState==="hidden"&&T()},k=()=>{T()};return document.addEventListener("visibilitychange",h),window.addEventListener("pagehide",k),{push(f){w(f),c.length>=o&&T()},flush:T,destroy(){X=!1,v!==null&&(clearInterval(v),v=null),document.removeEventListener("visibilitychange",h),window.removeEventListener("pagehide",k),T()}}}var Dn=1800*1e3;function Ae(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Mn(e=Dn,t){let n=new Map,r=`_snt_asgn${mt(t)}_`,l=(i,a)=>`${r}${encodeURIComponent(i)}:${encodeURIComponent(a)}`,o=i=>{let a=i.slice(r.length),c=a.indexOf(":");if(c<0)return null;try{return{componentId:decodeURIComponent(a.slice(0,c)),segment:decodeURIComponent(a.slice(c+1))}}catch(d){return null}},s=()=>{try{let i=[];for(let a=0;a<localStorage.length;a++){let c=localStorage.key(a);c!=null&&c.startsWith(r)&&i.push(c)}return i}catch(i){return[]}},u=i=>i.assignedAt+(i.ttlMs&&i.ttlMs>0?i.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let i of s())try{let a=localStorage.getItem(i);if(!a)continue;let c=JSON.parse(a);if(u(c)){localStorage.removeItem(i);continue}let d=o(i);if(!d)continue;n.set(Ae(d.componentId,d.segment),c)}catch(a){}})(),{get(i,a){let c=n.get(Ae(i,a));return c?u(c)?(n.delete(Ae(i,a)),null):c:null},set(i,a,c){let d=Ae(i,a);n.set(d,c);try{localStorage.setItem(l(i,a),JSON.stringify(c))}catch(m){}},invalidate(i){let a=`${encodeURIComponent(i)}:`;for(let c of[...n.keys()])c.startsWith(a)&&n.delete(c);for(let c of s()){let d=o(c);if((d==null?void 0:d.componentId)===i)try{localStorage.removeItem(c)}catch(m){}}},clear(){n.clear();for(let i of s())try{localStorage.removeItem(i)}catch(a){}}}}var Ie="_snt_snap:",jn=["low","medium","high"];function Ee(e){try{let t=localStorage.getItem(Ie+e);if(!t)return null;let n=JSON.parse(t);return!n||typeof n!="object"||n.v!==1||typeof n.persona!="string"||typeof n.band!="string"||!jn.includes(n.band)||typeof n.slots!="object"||n.slots===null||Array.isArray(n.slots)||!(n.layoutOrder===null||Array.isArray(n.layoutOrder))||typeof n.savedAt!="number"||!(n.slotConfig===void 0||typeof n.slotConfig=="object"&&n.slotConfig!==null&&!Array.isArray(n.slotConfig))?null:n}catch(t){return null}}function he(e,t){try{localStorage.setItem(Ie+e,JSON.stringify(t))}catch(n){}}var Ge="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",vt="[sentient] Local mode \u2014 decisions are simulated on-device and nothing is sent over the network. Add an API key to learn from real traffic.",ft=!1,ke=!1;function Nn(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function $n(e){var t;let n=ht({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),r=(t=n.getSessionId())!=null?t:"local",l=Nn(),o=Promise.resolve().then(()=>(pt(),dt)).then(i=>{let a=i;return a.LOCAL_ENGINE_AVAILABLE?(ft||(ft=!0,console.info(vt)),a):(ke||(ke=!0,console.error(Ge)),null)}).catch(()=>(ke||(ke=!0,console.error(Ge)),null)),s=null;function u(i){let a=document.documentElement;a.dataset.sentientPersona===void 0&&(a.dataset.sentientPersona=i.persona,a.dataset.sentientConfidence=se(i.confidence))}return{isLocal:!0,async decide(i){var a,c,d;let m=await o;if(!m)return null;let g=m.createLocalEngine({sessionId:r,forcedPersona:l}).decide(i);return s=ge(O({},g),{layoutOrder:(c=(a=g.layoutOrder)!=null?a:s==null?void 0:s.layoutOrder)!=null?c:null,slots:O(O({},(d=s==null?void 0:s.slots)!=null?d:{}),g.slots)}),he(e.apiKey||"local",{v:1,persona:s.persona,band:se(s.confidence),slots:s.slots,layoutOrder:s.layoutOrder,savedAt:Date.now()}),u(g),g},getSlotResult(i){var a,c,d;return(d=(c=s==null?void 0:s.slots[i])!=null?c:(a=e.initialSlots)==null?void 0:a[i])!=null?d:null},getPersona(){return s?{persona:s.persona,confidence:s.confidence,band:se(s.confidence)}:null},async assign(i,a){var c;let d=await o;return!d||!a||a.length===0?a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null:{variantId:(c=d.createLocalEngine({sessionId:r,forcedPersona:l}).decide({components:[{id:i,variantIds:a}]}).assignments[i])!=null?c:a[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function ye(e,t,n,r){let l=[];{let o=!1,s=[],u=()=>{if(o)return;let i=Date.now();for(s.push(i);s.length>0&&i-s[0]>500;)s.shift();s.length>=3&&(o=!0,e("rage_click"))};t.addEventListener("click",u),l.push(()=>t.removeEventListener("click",u))}{let o=!1,s=u=>{if(o||!(u.target instanceof Node)||!t.contains(u.target)&&t!==u.target)return;o=!0;let i=typeof window!="undefined"?window.getSelection():null,a=i?i.toString().length:0;e("text_copy",{selectionLength:a})};document.addEventListener("copy",s),l.push(()=>document.removeEventListener("copy",s))}{let o=!1,s=!1,u=null,i=()=>{u!==null&&(clearTimeout(u),u=null)},a=()=>{o||!s||(i(),u=setTimeout(()=>{!o&&s&&(o=!0,e("scroll_hesitation"))},3e3))},c=()=>{i(),a()},d=g=>{for(let b of g)s=b.intersectionRatio>.3,s?a():i()},m=new IntersectionObserver(d,{threshold:[.3]});m.observe(t),window.addEventListener("scroll",c,{passive:!0}),l.push(()=>{m.disconnect(),window.removeEventListener("scroll",c),i()})}if((r==null?void 0:r.tabLoss)!==!1){let o=!1,s=n!=null?n:Date.now(),u=()=>{if(o||document.visibilityState!=="hidden")return;let i=Date.now()-s;i<15e3&&(o=!0,e("tab_loss",{timeOnPage:i}))};document.addEventListener("visibilitychange",u),l.push(()=>document.removeEventListener("visibilitychange",u))}return()=>{for(let o of l)o()}}var bt="https://api.sentient-ui.com/v1/events",K=new Map,wt=null;function Bn(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}function Ue(){return gt()}var me={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}};function Kn(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,r]of t)n.startsWith("utm_")&&(e[n]=r);return e}catch(e){return{}}}function St(e){return e.replace(/\/events\/?$/,"")}function ae(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(e=>e==="1"||e==="yes")}function qe(e){var t;if(typeof window=="undefined")return;let n=e!=null?e:wt;if(!n){console.warn("[sentient] grantConsent() called before init()");return}let r=K.get(n);if(!r){console.warn("[sentient] grantConsent() called before init()");return}let{config:l,upgrade:o}=r;if(!o||l.respectDoNotTrack!==!1&&ae())return;let s=Oe(ge(O({},l),{consent:!0}));o(s);let u=(t=K.get(n))==null?void 0:t.dispose;K.set(n,{config:ge(O({},l),{consent:!0}),upgrade:null,dispose:u})}function Un(e){var t;let n=e.preConsentBehavior==="statistical_winner",r=St((t=e.ingestUrl)!=null?t:bt),l={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(i,a,c){if(!n)return null;try{let d=new URLSearchParams({componentId:i});for(let g of a!=null?a:[])d.append("variantIds[]",g);let m=await fetch(`${r}/winner?${d.toString()}`,{headers:l});return m.ok?{variantId:(await m.json()).variantId,assignmentTtlMs:0}:a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}catch(d){return a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},s={track:i=>o.track(i),goal:((i,a,c,d)=>o.goal(i,a,c,d)),componentGoal:(i,a,c)=>o.componentGoal(i,a,c),identify:i=>o.identify(i),getAssignment:(i,a)=>o.getAssignment(i,a),assign:(i,a,c,d)=>o.assign(i,a,c,d),decide:i=>o.decide(i),getSlotResult:i=>o.getSlotResult(i),getPersona:()=>o.getPersona(),fetchWeights:()=>o.fetchWeights(),getGraph:()=>o.getGraph(),dispose:()=>o.dispose(),destroy:()=>o.destroy()};function u(i){o=i}return{proxy:s,setInner:u}}function Oe(e){var t,n,r,l,o,s,u,i,a;if(typeof window=="undefined")return me;wt=e.apiKey;let c=K.get(e.apiKey||"local");if(c!=null&&c.dispose)try{c.dispose()}catch(p){}let d=e.respectDoNotTrack!==!1&&ae(),m=e.consent===!1||d,g=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!g&&e.localMode!==!1)return m?(K.set(e.apiKey||"local",{config:e,upgrade:null}),me):(K.set(e.apiKey||"local",{config:e,upgrade:null}),$n(e));if(m){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return e.preConsentBehavior==="statistical_winner"&&console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),K.set(e.apiKey,{config:e,upgrade:null}),me;let{proxy:p,setInner:y}=Un(e);return K.set(e.apiKey,{config:e,upgrade:d?null:y}),p}if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),me;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),me;let b=(t=e.ingestUrl)!=null?t:bt,w=Date.now(),A=ht({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),_=Mn(void 0,e.apiKey),S=Ln({ingestUrl:b,apiKey:e.apiKey}),I=St(b),N={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},Y=st((n=navigator.userAgent)!=null?n:""),le=typeof window!="undefined"?window.location.origin:void 0,re=at((r=document.referrer)!=null?r:"",le),T=(l=e.sessionSegment)!=null?l:`${Y}:${re}`,X=new Map,v=new Map,h=null,k=p=>{for(let y of p)v.has(y.id)||v.set(y.id,Be(y))};if(e.initialSlots)for(let[p,y]of Object.entries(e.initialSlots))v.set(p,y);let f=Ee(e.apiKey);if(f)for(let[p,y]of Object.entries(f.slots))v.has(p)||v.set(p,y);let x={low:.15,medium:.5,high:.85};if(e.initialPersona)h=O({},e.initialPersona);else{let p=document.documentElement.dataset;p.sentientPersona?h={persona:p.sentientPersona,confidence:(s=x[(o=p.sentientConfidence)!=null?o:"low"])!=null?s:.15}:f&&(h={persona:f.persona,confidence:(u=x[f.band])!=null?u:.15})}if(e.initialAssignments)for(let[p,y]of Object.entries(e.initialAssignments))_.set(p,T,{variantId:y,assignedAt:Date.now(),segment:T,confidence:1});let j=Promise.resolve(),J=A.getSessionId();if(J){let p=lt((i=document.referrer)!=null?i:""),y=O(O({sessionId:J,deviceClass:Y,trafficSource:re,referrerDomain:p,utmParams:Kn(),timeOfDay:ct(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:A.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||it((a=navigator.userAgent)!=null?a:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{j=fetch(`${I}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(y),headers:N}).then(E=>{E.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){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:S});let q={goal(p,y={},E=1,F=0){var W,D,z;let B=A.getSessionId();if(!B)return;let P=Bn(y)?y:{metadata:y},Z=Ue(),$={sessionId:B,name:p,metadata:(W=P.metadata)!=null?W:{},weight:(D=P.weight)!=null?D:E,stepIndex:(z=P.stepIndex)!=null?z:F,goalId:Z,value:P.value,currency:P.currency,externalId:P.externalId};j.then(()=>{fetch(`${I}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify($),headers:N}).catch(()=>{})})},componentGoal(p,y,E){var F,W,D;let z=A.getSessionId();if(!z)return;let B=_.get(p,T),P=B?null:(F=v.get(p))!=null?F:null;if(!B&&P===null){e.debug&&console.warn(`[sentient] componentGoal("${p}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let Z=B?B.variantId:ut(P),$={id:Ue(),sessionId:z,projectId:e.apiKey,componentId:p,variantId:Z,eventType:"goal_achieved",goalType:y,payload:O({reward:(W=E==null?void 0:E.reward)!=null?W:1,goalValue:E==null?void 0:E.value,currency:E==null?void 0:E.currency},(D=E==null?void 0:E.metadata)!=null?D:{}),timestamp:Date.now(),timeInSession:Date.now()-w};e.debug&&console.log("[sentient] componentGoal",$),j.then(()=>S.push($))},identify(p){let y=A.getSessionId();y&&j.then(()=>{fetch(`${I}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:y,userId:p,ephemeral:A.isEphemeral()}),headers:N}).catch(()=>{})})},track(p){let y=A.getSessionId();if(!y)return;let E=ge(O({},p),{id:Ue(),sessionId:y,timestamp:Date.now(),timeInSession:Date.now()-w});e.debug&&console.log("[sentient] track",E),j.then(()=>S.push(E))},getAssignment(p,y){return _.get(p,y)},async assign(p,y,E,F){let W=A.getSessionId();if(!W)return null;let D=_.get(p,T);if(D&&(y!=null&&y.length||D.content!==void 0)){let P=D.ttlMs&&D.ttlMs>0?Math.max(0,D.assignedAt+D.ttlMs-Date.now()):0;return{variantId:D.variantId,assignmentTtlMs:P,content:D.content}}let z=X.get(p);if(z)return z;let B=(async()=>{await j;try{let P={sessionId:W,componentId:p,variantIds:y};F!==void 0?P.agentDataByVariant=F:E!==void 0&&(P.agentData=E);let Z=await fetch(`${I}/assign`,{method:"POST",body:JSON.stringify(P),headers:N});if(!Z.ok)return null;let $=await Z.json();return _.set(p,T,O({variantId:$.variantId,assignedAt:Date.now(),segment:T,confidence:1,content:$.content},$.assignmentTtlMs&&$.assignmentTtlMs>0?{ttlMs:$.assignmentTtlMs}:{})),$}catch(P){return null}finally{X.delete(p)}})();return X.set(p,B),B},async decide(p){var y,E,F,W,D,z,B,P,Z;let $=A.getSessionId();if(!$)return null;let de=(y=p.slots)!=null?y:[];await j;try{let oe={sessionId:$};p.sections&&p.sections.length>0&&(oe.sections=p.sections.map(G=>({id:G}))),oe.components=(E=p.components)!=null?E:[],de.length>0&&(oe.slots=de.map($e)),p.slotsFrom==="registry"&&(oe.slotsFrom="registry"),p.v&&(oe.v=p.v);let He=await fetch(`${I}/decide`,{method:"POST",body:JSON.stringify(oe),headers:N});if(!He.ok)return k(de),null;let R=await He.json(),pe={};for(let G of de)pe[G.id]=(W=(F=R.slots)==null?void 0:F[G.id])!=null?W:Be(G);if(R.slots)for(let[G,fe]of Object.entries(R.slots))G in pe||(pe[G]=fe);for(let[G,fe]of Object.entries(pe))v.set(G,fe);let Qt=h!=null&&h.persona!=="unknown";R.persona&&!(R.persona==="unknown"&&Qt)?h={persona:R.persona,confidence:(D=R.confidence)!=null?D:0}:h||(h={persona:"unknown",confidence:0});for(let[G,fe]of Object.entries((z=R.assignments)!=null?z:{}))_.set(G,T,{variantId:fe,assignedAt:Date.now(),segment:T,confidence:1});return he(e.apiKey,O({v:1,persona:h.persona,band:se(h.confidence),slots:Object.fromEntries(v),layoutOrder:(B=R.layoutOrder)!=null?B:null,savedAt:Date.now()},R.slotConfig?{slotConfig:R.slotConfig}:{})),O(O(O({layoutOrder:(P=R.layoutOrder)!=null?P:null,assignments:(Z=R.assignments)!=null?Z:{},slots:pe,persona:h.persona,confidence:h.confidence},R.slotConfig?{slotConfig:R.slotConfig}:{}),R.goals?{goals:R.goals}:{}),R.sectionMap?{sectionMap:R.sectionMap}:{})}catch(oe){return k(de),null}},getSlotResult(p){var y;return(y=v.get(p))!=null?y:null},getPersona(){return h?{persona:h.persona,confidence:h.confidence,band:se(h.confidence)}:null},async fetchWeights(){var p;try{let y=await fetch(`${I}/weights`,{headers:N});return y.ok?(p=(await y.json()).components)!=null?p:[]:[]}catch(y){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var p;S.destroy(),((p=K.get(e.apiKey))==null?void 0:p.dispose)===q.dispose&&K.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var p;S.destroy(),A.destroy(),((p=K.get(e.apiKey))==null?void 0:p.dispose)===q.dispose&&K.delete(e.apiKey);try{localStorage.removeItem(Ie+e.apiKey),localStorage.removeItem(yt(e.apiKey))}catch(y){}e.debug&&console.log("[sentient] destroyed")}};if(K.set(e.apiKey,{config:e,upgrade:null,dispose:q.dispose}),e.debug){let p=window;p.__sentient&&(p.__sentient.client=q)}return q}var xt=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Gn=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],qn=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function Wn(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function At(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,r]of Gn)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of qn)if(r.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function kt(e){var t,n;let r=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:Wn(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function It(e){return At(kt(e)).type}Se();var Ot="section, header, footer, nav, main > div, [data-sentient-section]";function zn(e){var t;return((t=e.parentElement)==null?void 0:t.closest(Ot))!=null}function Vn(e,t,n,r){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:r})}).catch(()=>{})}catch(l){}}var Et=()=>{};function Ct(e,t){var n,r,l,o,s,u,i,a,c;let d=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!d||typeof IntersectionObserver=="undefined"||ae()||!t.apiKey)return Et;let m=((r=t.apiBase)!=null?r:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),g=Array.from(d.querySelectorAll(Ot)).filter(v=>!zn(v));if(g.length===0)return Et;let b=new Map,w=new Map,A=new Map;for(let v of g){let h=v.getAttribute("data-sentient-type"),k=h&&xt.includes(h)?h:null,f=(o=k!=null?k:(l=t.typeOf)==null?void 0:l.call(t,v))!=null?o:It(v),x=`nc-${f}`;b.set(v,x),w.set(x,f),k?A.set(x,"markup"):A.has(x)||A.set(x,"auto")}let _=(a=(i=(u=(s=d.defaultView)!=null?s:typeof window!="undefined"?window:void 0)==null?void 0:u.location)==null?void 0:i.pathname)!=null?a:"/";Vn(t.apiKey,m,_,[...w.entries()].map(([v,h])=>{var k;return{componentId:v,semanticType:h,source:(k=A.get(v))!=null?k:"auto"}}));let S=new Map,I=v=>{let h=S.get(v);return h||(h={ms:0,scroll:0,enterAt:null,intersecting:!1},S.set(v,h)),h},N=new IntersectionObserver(v=>{for(let h of v){let k=b.get(h.target);if(!k)continue;let f=I(k);h.isIntersecting?(f.intersecting=!0,f.enterAt=Date.now(),h.intersectionRatio>f.scroll&&(f.scroll=h.intersectionRatio)):(f.intersecting=!1,f.enterAt!=null&&(f.ms+=Date.now()-f.enterAt,f.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let v of b.keys())N.observe(v);let Y=()=>{let v=Date.now();for(let[h,k]of S)if(k.enterAt!=null&&(k.ms+=v-k.enterAt,k.enterAt=null),!(k.ms<=0)){try{e.track({projectId:t.apiKey,componentId:h,eventType:"dwell",payload:{dwell_time:Math.round(k.ms),scroll_depth:Number(k.scroll.toFixed(2))}})}catch(f){}k.ms=0}},le=()=>{if(d.hidden)Y();else{let v=Date.now();for(let h of S.values())h.intersecting&&(h.enterAt=v)}},re=()=>{Y();try{N.disconnect()}catch(v){}};d.addEventListener("visibilitychange",le);let T=(c=d.defaultView)!=null?c:typeof window!="undefined"?window:void 0;T==null||T.addEventListener("pagehide",re);let X=[];return t.microSignals&&[...b.entries()].forEach(([v,h],k)=>{X.push(ye((f,x={})=>{try{e.track({projectId:t.apiKey,componentId:h,eventType:"micro_signal",payload:O({signalType:f},x)})}catch(j){}},v,void 0,{tabLoss:k===0}))}),()=>{Y(),d.removeEventListener("visibilitychange",le),T==null||T.removeEventListener("pagehide",re);for(let v of X)v();try{N.disconnect()}catch(v){}}}var Jn=["landing","ecommerce","saas","marketplace"];function Fn(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t=Object.entries(e);if(t.length<1||t.length>4)return null;let n={};for(let[r,l]of t){if(!Array.isArray(l)||l.length<2||l.length>6||!l.every(o=>typeof o=="string"))return null;n[r]=l}return n}function Hn(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function Ce(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.apiKey!="string"||!t.apiKey.startsWith("pk_"))return null;let n=Jn.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[o,s]of Object.entries(t.slots)){if(typeof s!="object"||s===null)continue;let u=s,i=Fn(u.dims);if(!i||u.target!==void 0&&typeof u.target!="string")continue;let a=u.arms!==void 0?Hn(u.arms):null,c={dims:i};typeof u.target=="string"&&(c.target=u.target),a&&(c.arms=a),r[o]=c}let l={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};return typeof t.consent=="boolean"&&(l.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(l.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(l.debug=!0),typeof t.registry=="boolean"&&(l.registry=t.registry),typeof t.editorSrc=="string"&&(l.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(l.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(l.sectionCapture=t.sectionCapture),l}function _t(e){var n,r,l;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(l=t==null?void 0:t.pathname)!=null?l:""}function Yn(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let r=((n=e.textContent)!=null?n:"").trim().toLowerCase(),l=t.text.trim().toLowerCase();if(!(r===l||r.startsWith(l)||l.startsWith(r)))return!1}return!0}function Tt(e,t){return!!(e!=null&&e.urlMatch)&&!_t(t).includes(e.urlMatch)}var Xn=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function ee(e,t){var l;if(e.urlMatch&&!_t(t).includes(e.urlMatch))return null;let n=[];if(e.id){let o=t.getElementById(e.id);n=o?[o]:[]}if(n.length===0&&((l=e.dataAttr)!=null&&l.name)&&Xn.test(e.dataAttr.name))try{let o=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${o}"]`))}catch(o){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(o){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!Yn(r,e.fingerprint)?null:r}var Pt={color:"color",background:"background",fontSize:"font-size",fontWeight:"font-weight",textAlign:"text-align",padding:"padding",margin:"margin",borderRadius:"border-radius",width:"width",height:"height",maxWidth:"max-width",border:"border",boxShadow:"box-shadow",opacity:"opacity",lineHeight:"line-height",letterSpacing:"letter-spacing",textTransform:"text-transform",gap:"gap",fontFamily:"font-family"},Zn=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function Rt(e){var t;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;for(let n of e.matchAll(/([A-Za-z-]*)\(/g))if(!Zn.test((t=n[1])!=null?t:""))return!1;return!0}var Lt=/^https:\/\//i,Dt=new Map,te=null;function Qn(e){return e.replace(/["\\]/g,"\\$&")}function er(e){var t;(!te||!te.isConnected)&&(te=e.querySelector("style[data-sentient-ops]"),te||(te=e.createElement("style"),te.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(te))),te.textContent=[...Dt.entries()].map(([n,r])=>`[data-snt-e="${Qn(n)}"]{${r}}`).join(`
|
|
2
|
-
`)}function Mt(e,t,n,r){var u;let l=!1,o=(u=t.moveBefore)!=null?u:t.moveAfter;if(o){let i=ee(o,r);!i||i===e||i.parentElement!==e.parentElement||!e.parentElement?l=!0:t.moveBefore?e.parentElement.insertBefore(e,i):e.parentElement.insertBefore(e,i.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&Lt.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&Lt.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let s=[];if(t.hidden&&s.push("display:none !important"),t.style)for(let[i,a]of Object.entries(t.style)){let c=Pt[i];c&&typeof a=="string"&&Rt(a)&&s.push(`${c}:${a.trim()} !important`)}return s.length>0&&(e.setAttribute("data-snt-e",n),Dt.set(n,s.join(";")),er(r)),{anchorMiss:l}}function _e(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function Te(e,t,n){var r;for(let[l,o]of Object.entries(t)){let s=e[l];if(!s||typeof s=="string")continue;let u=o.target?Array.from(n.querySelectorAll(o.target)):[n.documentElement];for(let i of u)for(let[a,c]of Object.entries(s))(r=o.dims[a])!=null&&r.includes(c)&&i.setAttribute(`data-${a}`,c)}}function Pe(e,t,n){for(let[r,l]of Object.entries(t)){let o=e[r];if(typeof o!="string"||!l.arms||!l.arms.includes(o))continue;let s=l.target?Array.from(n.querySelectorAll(l.target)):[n.documentElement];for(let u of s)u.setAttribute("data-sentient-arm",o)}}function Re(e,t,n,r){var s,u;let l=(s=r==null?void 0:r.contentAndOps)!=null?s:!0,o=[];for(let[i,a]of Object.entries(t)){if(Tt(a.locator,n))continue;let c;if(a.locator){let m=ee(a.locator,n);c=m?[m]:[]}else a.target?c=Array.from(n.querySelectorAll(a.target)):c=[n.documentElement];(a.locator||a.target)&&c.length===0&&o.push(i);let d=e[i];for(let m of c){if(d!==void 0)if(typeof d=="string")m.setAttribute("data-sentient-arm",d),l&&((u=r==null?void 0:r.onApplied)==null||u.call(r,i,d,m));else for(let[g,b]of Object.entries(d))m.setAttribute(`data-${g}`,b);l&&(typeof a.content=="string"&&(m.textContent=a.content),a.ops&&Mt(m,a.ops,i,n).anchorMiss&&!o.includes(i)&&o.push(i))}}return o}var tr=800;function Le(e,t,n){let r=[];return n.forEach(({slotId:l,arm:o,el:s},u)=>{r.push(ye((m,g={})=>{try{e.track({projectId:t,componentId:l,variantId:o,eventType:"micro_signal",payload:ie({signalType:m},g)})}catch(b){}},s,void 0,{tabLoss:u===0}));let i=null,a=0,c=()=>{a=Date.now(),i=setTimeout(()=>{try{e.track({projectId:t,componentId:l,variantId:o,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-a}})}catch(m){}i=null},tr)},d=()=>{i!==null&&(clearTimeout(i),i=null)};s.addEventListener("mouseenter",c),s.addEventListener("mouseleave",d),r.push(()=>{s.removeEventListener("mouseenter",c),s.removeEventListener("mouseleave",d),i!==null&&clearTimeout(i)})}),()=>{for(let l of r)l()}}function nr(e){var n,r,l;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(l=t==null?void 0:t.pathname)!=null?l:""}function rr(e,t){if(!e)return!1;if(e==="/")return t==="/";let n=e.endsWith("/")?e.slice(0,-1):e;return t===n||t.startsWith(`${n}/`)}function jt(e,t,n){var m;let r=new Set,l=g=>{if(!r.has(g.goalId)){r.add(g.goalId);try{g.slotId?t.componentGoal(g.slotId,g.goalId):t.goal(g.goalId)}catch(b){}}},o=e.filter(g=>g.event==="click"),s=e.filter(g=>g.event==="form_submit"),u=e.filter(g=>g.event==="url_reached"),i=(g,b)=>{if(!g.locator)return!1;let w=ee(g.locator,n);return!!w&&(w===b||w.contains(b))},a=g=>{let b=g.target;if(!(!b||typeof b.closest!="function"))for(let w of o)i(w,b)&&l(w)},c=g=>{let b=g.target;if(b)for(let w of s)i(w,b)&&l(w)},d=()=>{if(u.length===0)return;let g=nr(n);for(let b of u)b.urlPattern&&rr(b.urlPattern,g)&&l(b)};return n.addEventListener("click",a,!0),n.addEventListener("submit",c,!0),(m=n.defaultView)==null||m.addEventListener("popstate",d),d(),{checkUrl:d,teardown:()=>{var g;n.removeEventListener("click",a,!0),n.removeEventListener("submit",c,!0),(g=n.defaultView)==null||g.removeEventListener("popstate",d)}}}var Nt="__snt_editor_token";function $t(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(Nt):null}catch(e){return null}}function Bt(e){try{sessionStorage.setItem(Nt,e)}catch(t){}}var ze="0.13.0",Vt=5e3,or=50,ir=(()=>{try{if(typeof window=="undefined")return[];let e=window.SentientSnippet;return Array.isArray(e==null?void 0:e.q)?e.q:[]}catch(e){return[]}})(),U=null,L=null,Q={},ne=null,V=null,M=null,H=null,C=null,Kt=!1,We=null,De=null,Me=null,ve=!1,je=!1;function Jt(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function ce(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function ue(e,t){return U?(U.personaAttributes&&C&&_e(C.persona,C.band,e),Te(Q,U.slots,e),Pe(Q,U.slots,e),ne?Re(Q,ne,e,t):[]):[]}function sr(e,t){var n;if(t.length!==0)try{let r=(n=e.apiBase)!=null?n:"https://api.sentient-ui.com";fetch(`${r}/v1/locator-miss`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify({slots:t})}).catch(()=>{})}catch(r){}}function be(){return!!(U&&L&&U.sectionCapture!==!1&&(U.consent!==!1||je)&&!ae())}function ar(){if(!L||!U||!be()||H)return;let e=[];ue(document,{contentAndOps:ve,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),Je();try{M==null||M(),M=Le(L,U.apiKey,e)}catch(t){}}function Je(){if(typeof document=="undefined"||!be())return;let e;try{if(De&&De.length>0){let t=new Map;for(let n of De){if(n.urlMatch!==window.location.pathname)continue;let r=ee(n.locator,document);r&&t.set(r,n.type)}t.size>0&&(e=n=>{var r;return(r=t.get(n))!=null?r:null})}}catch(t){}try{H=Ct(L,ie({apiKey:U.apiKey,apiBase:U.apiBase,doc:document,microSignals:!0},e?{typeOf:e}:{})),Me=window.location.pathname}catch(t){}}function Fe(){try{let e=[];if(M==null||M(),M=null,ue(document,{contentAndOps:ve,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),e.length>0&&be())try{M=Le(L,U.apiKey,e)}catch(t){}try{typeof window!="undefined"&&Me!==null&&window.location.pathname!==Me&&be()&&(H==null||H(),H=null,Je())}catch(t){}}catch(e){}}function Ut(){We===null&&(We=setTimeout(()=>{We=null,Fe();try{V==null||V.checkUrl()}catch(e){}},or))}function Gt(){if(!(Kt||typeof window=="undefined"||typeof history=="undefined")){Kt=!0;try{let e=t=>{let n=history[t];history[t]=function(r,l,o){let s=n.call(this,r,l,o!=null?o:null);return Ut(),s}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Ut)}catch(e){}}}function Ve(e){let t={};for(let[n,r]of Object.entries(e.slots))t[n]=r.target?document.querySelectorAll(r.target).length:1;return t}function Ft(e){return new URLSearchParams(e).get("sentient_editor")}function lr(){try{let t=Array.from(document.getElementsByTagName("script")).find(n=>/snippet(\.global)?\.js/.test(n.src));if(t!=null&&t.src)return t.src.replace(/snippet(\.global)?\.js/,"editor.global.js")}catch(e){}return null}function cr(e,t){var n,r,l,o;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let i=document.createElement("meta");i.name="referrer",i.content="no-referrer",i.setAttribute("data-sentient-editor",""),((r=document.head)!=null?r:document.documentElement).appendChild(i)}catch(i){}let s=(l=e.editorSrc)!=null?l:lr();if(!s){Wt();return}let u=document.createElement("script");u.src=s,u.async=!0,u.onerror=()=>Wt(),((o=document.head)!=null?o:document.documentElement).appendChild(u)}catch(s){}}var qt="sentient-editor-load-notice";function Wt(){var e;try{if(typeof document=="undefined"||document.getElementById(qt))return;let t=document.createElement("div");t.id=qt,t.textContent="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.",Object.assign(t.style,{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",cursor:"pointer"}),t.addEventListener("click",()=>t.remove()),((e=document.body)!=null?e:document.documentElement).appendChild(t),setTimeout(()=>t.remove(),1e4)}catch(t){}}function Ht(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let l=r.indexOf(":"),o=l===-1?"":r.slice(0,l),s=l===-1?"":r.slice(l+1);if(!(!o||!s))if(s.includes("=")){let u={};for(let i of s.split(",")){let[a,c]=i.split("=");a&&c&&(u[a]=c)}Object.keys(u).length&&(n[o]=u)}else n[o]=s}return Object.keys(n).length?n:null}function Yt(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var zt="sentient-persona-preview-banner";function ur(e){var t;try{if(typeof document=="undefined"||document.getElementById(zt))return;let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),r=document.createElement("div");r.id=zt,r.setAttribute("role","status"),Object.assign(r.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",background:"#111827",color:"#fff",font:"13px/1 system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.14)"});let l=document.createElement("span");l.textContent=`Previewing as ${n}`;let o=document.createElement("button");o.type="button",o.textContent="Exit preview",Object.assign(o.style,{cursor:"pointer",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"inherit",padding:"4px 10px",borderRadius:"999px"}),o.addEventListener("click",()=>{try{let s=new URL(window.location.href);s.searchParams.delete("sentient_persona"),window.location.href=s.pathname+s.search+s.hash}catch(s){}}),r.appendChild(l),r.appendChild(o),((t=document.body)!=null?t:document.documentElement).appendChild(r)}catch(n){}}async function dr(e,t){var a,c,d,m,g,b,w,A,_;let n=(a=e.apiBase)!=null?a:"https://api.sentient-ui.com",l=((c=e.registry)!=null?c:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([S,I])=>({id:S,dims:I.dims}))},o=await Jt(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(l)}).then(S=>S.ok?S.json():null).catch(()=>null),Vt);if(!o){ce(e,"persona preview: explain unavailable \u2014 page left as-is");return}let s=o;Q=(d=s.slots)!=null?d:{},ne=(m=s.slotConfig)!=null?m:null;let u=(w=(b=(g=s.personaAttributes)==null?void 0:g.persona)!=null?b:s.persona)!=null?w:t,i=(_=(A=s.personaAttributes)==null?void 0:A.confidence)!=null?_:"high";C={persona:u,band:i},ue(document),ve=!0,Xt(e),ur(u)}function Xt(e){let t={goal(n,r){try{L==null||L.goal(n,r)}catch(l){}},componentGoal(n,r){try{L==null||L.componentGoal(n,r)}catch(l){}},grantConsent(){try{qe(e.apiKey)}catch(n){}je=!0;try{ar()}catch(n){}},revokeConsent(){try{H==null||H(),H=null,Me=null,M==null||M(),M=null,V==null||V.teardown(),V=null,je=!1,L==null||L.destroy()}catch(n){}},reapply:Fe,getState(){var n,r;return{apiKey:e.apiKey,persona:(n=C==null?void 0:C.persona)!=null?n:null,band:(r=C==null?void 0:C.band)!=null?r:null,slots:Q,matchCounts:Ve(e),consent:e.consent!==!1}}};window.SentientSnippet=t;for(let n of ir.splice(0))try{n[0]==="goal"&&t.goal(n[1],n[2])}catch(r){}}async function Zt(){var e,t,n,r,l;try{let o=Ce(window.sentient);if(!o)return;U=o,ve=!1,je=!1;let s=typeof window!="undefined"?Ft(window.location.search):null;if(s){Bt(s);try{let S=new URL(window.location.href);S.searchParams.delete("sentient_editor"),window.history.replaceState(null,"",S.pathname+S.search+S.hash)}catch(S){}}let u=s!=null?s:$t();if(u){cr(o,u),ce(o,"editor mode");return}let i=typeof window!="undefined"?Ht(window.location.search):null;if(i){Q=i,C=null,ue(document),Gt(),ce(o,"preview mode",i);return}let a=typeof window!="undefined"?Yt(window.location.search):null;if(a){await dr(o,a),ce(o,"persona preview",a);return}let c=(e=o.registry)!=null?e:Object.keys(o.slots).length===0,d=Ee(o.apiKey);d&&(C={persona:d.persona,band:d.band},Q=d.slots,d.slotConfig&&(ne=d.slotConfig),ue(document,{contentAndOps:!1}));let m=Oe({apiKey:o.apiKey,context:o.context,consent:o.consent,preConsentBehavior:o.preConsentBehavior,debug:o.debug});L=m,Xt(o),Gt();let g=Object.entries(o.slots).map(([S,I])=>({id:S,dims:I.dims})),b=ze!=="0.0.0-dev"?{v:ze}:{},w=await Jt(m.decide(ie(ie({slots:g},b),c?{slotsFrom:"registry"}:{})),Vt);if(!w){ce(o,"decide timeout/null \u2014 snapshot state stands",Ve(o));return}let A=m.getPersona();A?C={persona:A.persona,band:A.band}:w.persona&&(C={persona:w.persona,band:"low"}),Q=w.slots,c?ne=(t=w.slotConfig)!=null?t:null:w.slotConfig&&(ne=w.slotConfig);let _=[];if(sr(o,ue(document,{onApplied:(S,I,N)=>_.push({slotId:S,arm:I,el:N})})),ve=!0,w.goals&&w.goals.length>0&&o.consent!==!1&&L)try{V==null||V.teardown(),V=jt(w.goals,L,document)}catch(S){}if(De=(n=w.sectionMap)!=null?n:null,be()){Je();try{M==null||M(),M=Le(L,o.apiKey,_)}catch(S){}}ce(o,"applied",{persona:C,slots:Q,matches:Ve(o)}),he(o.apiKey,ie({v:1,persona:(r=C==null?void 0:C.persona)!=null?r:w.persona,band:(l=C==null?void 0:C.band)!=null?l:"low",slots:w.slots,layoutOrder:w.layoutOrder,savedAt:Date.now()},ne?{slotConfig:ne}:{}))}catch(o){}}if(typeof window!="undefined"&&window.sentient){let e=window;e.__sentientInitialized||(e.__sentientInitialized=!0,Zt())}return on(pr);})();
|
|
1
|
+
"use strict";var SentientSnippet=(()=>{var Se=Object.defineProperty;var ln=Object.getOwnPropertyDescriptor;var cn=Object.getOwnPropertyNames,Ze=Object.getOwnPropertySymbols;var et=Object.prototype.hasOwnProperty,un=Object.prototype.propertyIsEnumerable;var Qe=(e,t,n)=>t in e?Se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,le=(e,t)=>{for(var n in t||(t={}))et.call(t,n)&&Qe(e,n,t[n]);if(Ze)for(var n of Ze(t))un.call(t,n)&&Qe(e,n,t[n]);return e};var tt=(e,t)=>()=>(e&&(t=e(e=0)),t);var nt=(e,t)=>{for(var n in t)Se(e,n,{get:t[n],enumerable:!0})},dn=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of cn(t))!et.call(e,a)&&a!==n&&Se(e,a,{get:()=>t[a],enumerable:!(r=ln(t,a))||r.enumerable});return e};var pn=e=>dn(Se({},"__esModule",{value:!0}),e);var fn,gn,mn,rt,hn,yn,ot,T,me,Ae=tt(()=>{"use strict";fn=Object.defineProperty,gn=Object.defineProperties,mn=Object.getOwnPropertyDescriptors,rt=Object.getOwnPropertySymbols,hn=Object.prototype.hasOwnProperty,yn=Object.prototype.propertyIsEnumerable,ot=(e,t,n)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,T=(e,t)=>{for(var n in t||(t={}))hn.call(t,n)&&ot(e,n,t[n]);if(rt)for(var n of rt(t))yn.call(t,n)&&ot(e,n,t[n]);return e},me=(e,t)=>gn(e,mn(t))});var ft={};nt(ft,{LOCAL_ENGINE_AVAILABLE:()=>wn,createLocalEngine:()=>Sn});function Sn(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var wn,gt=tt(()=>{"use strict";wn=!1});var Ir={};nt(Ir,{applyPersonaAttributes:()=>Re,applyRegistrySlots:()=>Me,applySlotArms:()=>De,applySlotAttributes:()=>Pe,parseEditorToken:()=>tn,parsePersonaPreview:()=>rn,parsePreview:()=>nn,parseSnippetConfig:()=>Le,reapply:()=>Ye,run:()=>sn,version:()=>Je});Ae();function xe(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function it(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 Be(e){var t,n,r;if(e.arms)return typeof e.baseline=="string"?e.baseline:(t=e.arms[0])!=null?t:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return xe(e.baseline);if(typeof e.baseline=="string")return e.baseline;let a={};for(let[o,l]of Object.entries((n=e.dims)!=null?n:{}))a[o]=(r=l[0])!=null?r:"";return xe(a)}function st(e,t){var n,r;return e.dims!=null?(r=(n=it(t))!=null?n:it(Be(e)))!=null?r:{}:t}function ce(e){return e>=.3?e<.7?"medium":"high":"low"}var vn=["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 bn(e)!==null}function bn(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=vn.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function lt(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 ct(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 ut(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function dt(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function Ue(e){return T(T(T({id:e.id},e.arms?{arms:[...e.arms]}:{}),e.dims?{dims:Object.fromEntries(Object.entries(e.dims).map(([t,n])=>[t,[...n]]))}:{}),e.baseline!==void 0?{baseline:e.baseline}:{})}function Ge(e){let t=Ue(e);return st(t,Be(t))}function pt(e){return typeof e=="string"?e:xe(e)}Ae();function ht(){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 yt(e){return e?`_${e.slice(0,12)}`:""}var An="_snt_uid",xn=365,In="_snt_uid";function kn(){return ht()}function En(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function Cn(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function On(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 Tn(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function Ln(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function Rn(e){try{sessionStorage.removeItem(e)}catch(t){}}function Pn(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 Dn(e){try{localStorage.removeItem(e)}catch(t){}}function Mn(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var Nn={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function vt(e){var t,n,r,a,o,l;if(typeof window=="undefined")return Nn;let d=yt(e==null?void 0:e.apiKey),i=(t=e==null?void 0:e.cookieName)!=null?t:`${An}${d}`,s=`${In}${d}`,c=((n=e==null?void 0:e.cookieTTLDays)!=null?n:xn)*24*60*60,u=g=>g&&g.length>0?g:null,m=(l=(o=(a=(r=u(En(i)))!=null?r:u(On(s)))!=null?a:u(Tn(s)))!=null?o:u(e==null?void 0:e.ssrSessionId))!=null?l:kn();Cn(i,m,c);let w=_n(s,m),E=Pn(i),C=w?!1:Ln(s,m),k=!w&&!E&&!C;return{getSessionId:()=>m,isEphemeral:()=>k,destroy:()=>{m=null,Mn(i),Dn(s),Rn(s)}}}function Ee(e){return Math.min(6e4,1e3*2**Math.min(e,6))}function bt(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 wt(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 Ce(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 St(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 $n=500,jn=56*1024;function At(e){return`_snt_retry_${e.slice(0,12)}`}var Kn={push:()=>{},flush:()=>{},destroy:()=>{}};function Bn(e){var t,n,r;if(typeof window=="undefined")return Kn;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=At(i),c=[],u=new Set,m=[],w=h=>{for(let I of h)E.delete(I),!u.has(I)&&(u.add(I),m.push(I));for(;m.length>$n;){let I=m.shift();I&&u.delete(I)}St(h,s)},E=new Set,C=h=>{u.has(h.id)||E.has(h.id)||(E.add(h.id),c.push(h))},k=h=>{for(let I of h)u.has(I.id)||(E.add(I.id),c.push(I))},g=wt(s,l);for(let h of g)C(h);let f=0,x=0,O=h=>{if(h.length===0)return;let I=JSON.stringify(h),Y=h.map(X=>X.id),B;try{B=fetch(d,{method:"POST",keepalive:!0,body:I,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}})}catch(X){Ce(h,l,s),k(h),x++,f=Date.now()+Ee(x);return}let ne=X=>{if(bt(X)!=="retry"){w(Y),x=0,f=0;return}Ce(h,l,s),k(h),x++,f=Date.now()+Ee(x)};B instanceof Promise?B.then(ne).catch(()=>{Ce(h,l,s),k(h),x++,f=Date.now()+Ee(x)}):ne(B)},G=typeof TextEncoder!="undefined"?new TextEncoder:null,v=h=>G?G.encode(h).length:h.length,D=h=>{let I=[],Y=2;for(let B of h){let ne=v(JSON.stringify(B))+1;if(I.length>0&&Y+ne>jn||I.length>=o)break;I.push(B),Y+=ne}return I},$=()=>{try{if(Date.now()<f)return;for(;c.length>0&&!(Date.now()<f);){let h=c.filter(Y=>!u.has(Y.id));if(c.length=0,h.length===0)break;let I=D(h);if(I.length===0)break;I.length<h.length&&c.push(...h.slice(I.length)),O(I)}}catch(h){}},M=!0,S=null;S=setInterval(()=>{M&&$()},a);let A=()=>{document.visibilityState==="hidden"&&$()},b=()=>{$()};return document.addEventListener("visibilitychange",A),window.addEventListener("pagehide",b),{push(h){C(h),c.length>=o&&$()},flush:$,destroy(){M=!1,S!==null&&(clearInterval(S),S=null),document.removeEventListener("visibilitychange",A),window.removeEventListener("pagehide",b),$()}}}var Un=200;function xt(e){return`_snt_goal_retry_${e.slice(0,12)}`}var Gn={send:()=>{},flush:()=>{},destroy:()=>{}};function qn(e){var t,n,r;if(typeof window=="undefined")return Gn;let a=(t=e.flushIntervalMs)!=null?t:5e3,o=(n=e.maxRetrySize)!=null?n:100,l=(r=e.maxPerFlush)!=null?r:5,d=xt(e.apiKey),i=[],s=new Set,c=new Set,u=[],m=0,w=0,E=!1,C=v=>{for(s.delete(v.id),c.has(v.id)||(c.add(v.id),u.push(v.id));u.length>Un;){let D=u.shift();D&&c.delete(D)}St([v.id],d)},k=v=>{Ce([v],o,d),!c.has(v.id)&&!s.has(v.id)&&(s.add(v.id),i.push(v)),w++,m=Date.now()+Ee(w)},g=v=>{let D;try{D=fetch(e.url,{method:"POST",keepalive:!0,body:v.body,headers:e.headers})}catch(M){k(v);return}let $=M=>{var S;let A=bt(M);if(A==="retry"){k(v);return}A==="dropped"&&((S=e.onDrop)==null||S.call(e,v,M.status)),C(v),w=0,m=0};D instanceof Promise?D.then($).catch(()=>k(v)):$(D)},f=()=>{try{if(E||Date.now()<m)return;let v=0;for(;i.length>0&&v<l&&!(Date.now()<m);){let D=i.shift();s.delete(D.id),!c.has(D.id)&&(v++,g(D))}}catch(v){}};for(let v of wt(d,o))s.has(v.id)||(s.add(v.id),i.push(v));let x=setInterval(f,a),O=()=>{document.visibilityState==="hidden"&&f()},G=()=>f();return document.addEventListener("visibilitychange",O),window.addEventListener("pagehide",G),{send(v){if(!E&&!(c.has(v.id)||s.has(v.id))){if(Date.now()<m){s.add(v.id),i.push(v);return}g(v)}},flush:f,destroy(){clearInterval(x),document.removeEventListener("visibilitychange",O),window.removeEventListener("pagehide",G),f(),E=!0}}}var Wn=1800*1e3;function Ie(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Vn(e=Wn,t){let n=new Map,r=`_snt_asgn${yt(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(Ie(u.componentId,u.segment),c)}catch(s){}})(),{get(i,s){let c=n.get(Ie(i,s));return c?d(c)?(n.delete(Ie(i,s)),null):c:null},set(i,s,c){let u=Ie(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 Oe="_snt_snap:",zn=["low","medium","high"];function _e(e){try{let t=localStorage.getItem(Oe+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"||!zn.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 ye(e,t){try{localStorage.setItem(Oe+e,JSON.stringify(t))}catch(n){}}var We="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",It="[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.",mt=!1,ke=!1;function Jn(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function Fn(e){var t;let n=vt({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),r=(t=n.getSessionId())!=null?t:"local",a=Jn(),o=Promise.resolve().then(()=>(gt(),ft)).then(i=>{let s=i;return s.LOCAL_ENGINE_AVAILABLE?(mt||(mt=!0,console.info(It)),s):(ke||(ke=!0,console.error(We)),null)}).catch(()=>(ke||(ke=!0,console.error(We)),null)),l=null;function d(i){let s=document.documentElement;s.dataset.sentientPersona===void 0&&(s.dataset.sentientPersona=i.persona,s.dataset.sentientConfidence=ce(i.confidence))}return{isLocal:!0,async decide(i){var s,c,u;let m=await o;if(!m)return null;let w=m.createLocalEngine({sessionId:r,forcedPersona:a}).decide(i);return l=me(T({},w),{layoutOrder:(c=(s=w.layoutOrder)!=null?s:l==null?void 0:l.layoutOrder)!=null?c:null,slots:T(T({},(u=l==null?void 0:l.slots)!=null?u:{}),w.slots)}),ye(e.apiKey||"local",{v:1,persona:l.persona,band:ce(l.confidence),slots:l.slots,layoutOrder:l.layoutOrder,savedAt:Date.now()}),d(w),w},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:ce(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 ve(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=w=>{for(let E of w)l=E.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 kt="https://api.sentient-ui.com/v1/events",W=new Map,Et=null;function Hn(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}function qe(){return ht()}var he={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 Yn(){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 Ct(e){return e.replace(/\/events\/?$/,"")}function ue(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(e=>e==="1"||e==="yes")}function Ve(e){var t;if(typeof window=="undefined")return;let n=e!=null?e:Et;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&&ue())return;let l=Te(me(T({},a),{consent:!0}));o(l);let d=(t=W.get(n))==null?void 0:t.dispose;W.set(n,{config:me(T({},a),{consent:!0}),upgrade:null,dispose:d})}function Xn(e){var t;let n=e.preConsentBehavior==="statistical_winner",r=Ct((t=e.ingestUrl)!=null?t:kt),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 w of s!=null?s:[])u.append("variantIds[]",w);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 Te(e){var t,n,r,a,o,l,d,i,s;if(typeof window=="undefined")return he;Et=e.apiKey;let c=W.get(e.apiKey||"local");if(c!=null&&c.dispose)try{c.dispose()}catch(p){}let u=e.respectDoNotTrack!==!1&&ue(),m=e.consent===!1||u,w=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!w&&e.localMode!==!1)return m?(W.set(e.apiKey||"local",{config:e,upgrade:null}),he):(W.set(e.apiKey||"local",{config:e,upgrade:null}),Fn(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}),he;let{proxy:p,setInner:y}=Xn(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."),he;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),he;let E=(t=e.ingestUrl)!=null?t:kt,C=Date.now(),k=vt({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),g=Vn(void 0,e.apiKey),f=Bn({ingestUrl:E,apiKey:e.apiKey}),x=Ct(E),O={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},G=qn({url:`${x}/goals`,apiKey:e.apiKey,headers:O,onDrop:(p,y)=>{e.debug&&console.warn(`[sentient] goal dropped (HTTP ${y}) \u2014 this will not be retried. `+(y===400?"The session was not found: call init() and let the session upsert complete before firing goals.":y===401||y===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),p)}}),v=lt((n=navigator.userAgent)!=null?n:""),D=typeof window!="undefined"?window.location.origin:void 0,$=ct((r=document.referrer)!=null?r:"",D),M=(a=e.sessionSegment)!=null?a:`${v}:${$}`,S=new Map,A=new Map,b=null,h=p=>{for(let y of p)A.has(y.id)||A.set(y.id,Ge(y))};if(e.initialSlots)for(let[p,y]of Object.entries(e.initialSlots))A.set(p,y);let I=_e(e.apiKey);if(I)for(let[p,y]of Object.entries(I.slots))A.has(p)||A.set(p,y);let Y={low:.15,medium:.5,high:.85};if(e.initialPersona)b=T({},e.initialPersona);else{let p=document.documentElement.dataset;p.sentientPersona?b={persona:p.sentientPersona,confidence:(l=Y[(o=p.sentientConfidence)!=null?o:"low"])!=null?l:.15}:I&&(b={persona:I.persona,confidence:(d=Y[I.band])!=null?d:.15})}if(e.initialAssignments)for(let[p,y]of Object.entries(e.initialAssignments))g.set(p,M,{variantId:y,assignedAt:Date.now(),segment:M,confidence:1});let B=Promise.resolve(),ne=k.getSessionId();if(ne){let p=ut((i=document.referrer)!=null?i:""),y=T(T({sessionId:ne,deviceClass:v,trafficSource:$,referrerDomain:p,utmParams:Yn(),timeOfDay:dt(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:k.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||at((s=navigator.userAgent)!=null?s:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{B=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 X={goal(p,y={},_=1,Z=0){var J,j,F;let q=k.getSessionId();if(!q)return;let R=Hn(y)?y:{metadata:y},Q=qe(),U={sessionId:q,name:p,metadata:(J=R.metadata)!=null?J:{},weight:(j=R.weight)!=null?j:_,stepIndex:(F=R.stepIndex)!=null?F:Z,goalId:Q,value:R.value,currency:R.currency,externalId:R.externalId};e.debug&&console.log("[sentient] goal",U);let se={id:Q,body:JSON.stringify(U)};B.then(()=>G.send(se))},componentGoal(p,y,_){var Z,J,j;let F=k.getSessionId();if(!F)return;let q=g.get(p,M),R=q?null:(Z=A.get(p))!=null?Z:null;if(!q&&R===null){e.debug&&console.warn(`[sentient] componentGoal("${p}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let Q=q?q.variantId:pt(R),U={id:qe(),sessionId:F,projectId:e.apiKey,componentId:p,variantId:Q,eventType:"goal_achieved",goalType:y,payload:T({reward:(J=_==null?void 0:_.reward)!=null?J:1,goalValue:_==null?void 0:_.value,currency:_==null?void 0:_.currency},(j=_==null?void 0:_.metadata)!=null?j:{}),timestamp:Date.now(),timeInSession:Date.now()-C};e.debug&&console.log("[sentient] componentGoal",U),B.then(()=>f.push(U))},identify(p){let y=k.getSessionId();y&&B.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 _=me(T({},p),{id:qe(),sessionId:y,timestamp:Date.now(),timeInSession:Date.now()-C});e.debug&&console.log("[sentient] track",_),B.then(()=>f.push(_))},getAssignment(p,y){return g.get(p,y)},async assign(p,y,_,Z){let J=k.getSessionId();if(!J)return null;let j=g.get(p,M);if(j&&(y!=null&&y.length||j.content!==void 0)){let R=j.ttlMs&&j.ttlMs>0?Math.max(0,j.assignedAt+j.ttlMs-Date.now()):0;return{variantId:j.variantId,assignmentTtlMs:R,content:j.content}}let F=S.get(p);if(F)return F;let q=(async()=>{await B;try{let R={sessionId:J,componentId:p,variantIds:y};Z!==void 0?R.agentDataByVariant=Z:_!==void 0&&(R.agentData=_);let Q=await fetch(`${x}/assign`,{method:"POST",body:JSON.stringify(R),headers:O});if(!Q.ok)return null;let U=await Q.json();return g.set(p,M,T({variantId:U.variantId,assignedAt:Date.now(),segment:M,confidence:1,content:U.content},U.assignmentTtlMs&&U.assignmentTtlMs>0?{ttlMs:U.assignmentTtlMs}:{})),U}catch(R){return null}finally{S.delete(p)}})();return S.set(p,q),q},async decide(p){var y,_,Z,J,j,F,q,R,Q;let U=k.getSessionId();if(!U)return null;let se=(y=p.slots)!=null?y:[];await B;try{let ae={sessionId:U};p.sections&&p.sections.length>0&&(ae.sections=p.sections.map(z=>({id:z}))),ae.components=(_=p.components)!=null?_:[],se.length>0&&(ae.slots=se.map(Ue)),p.slotsFrom==="registry"&&(ae.slotsFrom="registry"),p.v&&(ae.v=p.v);let Xe=await fetch(`${x}/decide`,{method:"POST",body:JSON.stringify(ae),headers:O});if(!Xe.ok)return h(se),null;let P=await Xe.json(),fe={};for(let z of se)fe[z.id]=(J=(Z=P.slots)==null?void 0:Z[z.id])!=null?J:Ge(z);if(P.slots)for(let[z,ge]of Object.entries(P.slots))z in fe||(fe[z]=ge);for(let[z,ge]of Object.entries(fe))A.set(z,ge);let an=b!=null&&b.persona!=="unknown";P.persona&&!(P.persona==="unknown"&&an)?b={persona:P.persona,confidence:(j=P.confidence)!=null?j:0}:b||(b={persona:"unknown",confidence:0});for(let[z,ge]of Object.entries((F=P.assignments)!=null?F:{}))g.set(z,M,{variantId:ge,assignedAt:Date.now(),segment:M,confidence:1});return ye(e.apiKey,T({v:1,persona:b.persona,band:ce(b.confidence),slots:Object.fromEntries(A),layoutOrder:(q=P.layoutOrder)!=null?q:null,savedAt:Date.now()},P.slotConfig?{slotConfig:P.slotConfig}:{})),T(T(T({layoutOrder:(R=P.layoutOrder)!=null?R:null,assignments:(Q=P.assignments)!=null?Q:{},slots:fe,persona:b.persona,confidence:b.confidence},P.slotConfig?{slotConfig:P.slotConfig}:{}),P.goals?{goals:P.goals}:{}),P.sectionMap?{sectionMap:P.sectionMap}:{})}catch(ae){return h(se),null}},getSlotResult(p){var y;return(y=A.get(p))!=null?y:null},getPersona(){return b?{persona:b.persona,confidence:b.confidence,band:ce(b.confidence)}:null},async fetchWeights(){var p;try{let y=await fetch(`${x}/weights`,{headers:O});return y.ok?(p=(await y.json()).components)!=null?p:[]:[]}catch(y){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var p;f.destroy(),G.destroy(),((p=W.get(e.apiKey))==null?void 0:p.dispose)===X.dispose&&W.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var p;f.destroy(),G.destroy(),k.destroy(),((p=W.get(e.apiKey))==null?void 0:p.dispose)===X.dispose&&W.delete(e.apiKey);try{localStorage.removeItem(Oe+e.apiKey),localStorage.removeItem(At(e.apiKey)),localStorage.removeItem(xt(e.apiKey))}catch(y){}e.debug&&console.log("[sentient] destroyed")}};if(W.set(e.apiKey,{config:e,upgrade:null,dispose:X.dispose}),e.debug){let p=window;p.__sentient&&(p.__sentient.client=X)}return X}var Ot=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Zn=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],Qn=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function er(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function _t(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 Zn)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of Qn)if(r.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function Tt(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:er(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function Lt(e){return _t(Tt(e)).type}Ae();var Pt="section, header, footer, nav, main > div, [data-sentient-section]";function tr(e){var t;return((t=e.parentElement)==null?void 0:t.closest(Pt))!=null}function nr(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 Rt=()=>{};function Dt(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"||ue()||!t.apiKey)return Rt;let m=((r=t.apiBase)!=null?r:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),w=Array.from(u.querySelectorAll(Pt)).filter(S=>!tr(S));if(w.length===0)return Rt;let E=new Map,C=new Map,k=new Map;for(let S of w){let A=S.getAttribute("data-sentient-type"),b=A&&Ot.includes(A)?A:null,h=(o=b!=null?b:(a=t.typeOf)==null?void 0:a.call(t,S))!=null?o:Lt(S),I=`nc-${h}`;E.set(S,I),C.set(I,h),b?k.set(I,"markup"):k.has(I)||k.set(I,"auto")}let g=(s=(i=(d=(l=u.defaultView)!=null?l:typeof window!="undefined"?window:void 0)==null?void 0:d.location)==null?void 0:i.pathname)!=null?s:"/";nr(t.apiKey,m,g,[...C.entries()].map(([S,A])=>{var b;return{componentId:S,semanticType:A,source:(b=k.get(S))!=null?b:"auto"}}));let f=new Map,x=S=>{let A=f.get(S);return A||(A={ms:0,scroll:0,enterAt:null,intersecting:!1},f.set(S,A)),A},O=new IntersectionObserver(S=>{for(let A of S){let b=E.get(A.target);if(!b)continue;let h=x(b);A.isIntersecting?(h.intersecting=!0,h.enterAt=Date.now(),A.intersectionRatio>h.scroll&&(h.scroll=A.intersectionRatio)):(h.intersecting=!1,h.enterAt!=null&&(h.ms+=Date.now()-h.enterAt,h.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let S of E.keys())O.observe(S);let G=()=>{let S=Date.now();for(let[A,b]of f)if(b.enterAt!=null&&(b.ms+=S-b.enterAt,b.enterAt=null),!(b.ms<=0)){try{e.track({projectId:t.apiKey,componentId:A,eventType:"dwell",payload:{dwell_time:Math.round(b.ms),scroll_depth:Number(b.scroll.toFixed(2))}})}catch(h){}b.ms=0}},v=()=>{if(u.hidden)G();else{let S=Date.now();for(let A of f.values())A.intersecting&&(A.enterAt=S)}},D=()=>{G();try{O.disconnect()}catch(S){}};u.addEventListener("visibilitychange",v);let $=(c=u.defaultView)!=null?c:typeof window!="undefined"?window:void 0;$==null||$.addEventListener("pagehide",D);let M=[];return t.microSignals&&[...E.entries()].forEach(([S,A],b)=>{M.push(ve((h,I={})=>{try{e.track({projectId:t.apiKey,componentId:A,eventType:"micro_signal",payload:T({signalType:h},I)})}catch(Y){}},S,void 0,{tabLoss:b===0}))}),()=>{G(),u.removeEventListener("visibilitychange",v),$==null||$.removeEventListener("pagehide",D);for(let S of M)S();try{O.disconnect()}catch(S){}}}var rr=["landing","ecommerce","saas","marketplace"];function or(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 ir(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function Le(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=rr.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[o,l]of Object.entries(t.slots)){if(typeof l!="object"||l===null)continue;let d=l,i=or(d.dims);if(!i||d.target!==void 0&&typeof d.target!="string")continue;let s=d.arms!==void 0?ir(d.arms):null,c={dims:i};typeof d.target=="string"&&(c.target=d.target),s&&(c.arms=s),r[o]=c}let a={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};return typeof t.consent=="boolean"&&(a.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(a.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(a.debug=!0),typeof t.registry=="boolean"&&(a.registry=t.registry),typeof t.editorSrc=="string"&&(a.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(a.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(a.sectionCapture=t.sectionCapture),a}function Mt(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 sr(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 Nt(e,t){return!!(e!=null&&e.urlMatch)&&!Mt(t).includes(e.urlMatch)}var ar=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function re(e,t){var a;if(e.urlMatch&&!Mt(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)&&ar.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&&!sr(r,e.fingerprint)?null:r}var $t={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"},lr=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function jt(e){var t;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;for(let n of e.matchAll(/([A-Za-z-]*)\(/g))if(!lr.test((t=n[1])!=null?t:""))return!1;return!0}var Kt=/^https:\/\//i,Bt=new Map,oe=null;function cr(e){return e.replace(/["\\]/g,"\\$&")}function ur(e){var t;(!oe||!oe.isConnected)&&(oe=e.querySelector("style[data-sentient-ops]"),oe||(oe=e.createElement("style"),oe.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(oe))),oe.textContent=[...Bt.entries()].map(([n,r])=>`[data-snt-e="${cr(n)}"]{${r}}`).join(`
|
|
2
|
+
`)}function Ut(e,t,n,r){var d;let a=!1,o=(d=t.moveBefore)!=null?d:t.moveAfter;if(o){let i=re(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"&&Kt.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&Kt.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=$t[i];c&&typeof s=="string"&&jt(s)&&l.push(`${c}:${s.trim()} !important`)}return l.length>0&&(e.setAttribute("data-snt-e",n),Bt.set(n,l.join(";")),ur(r)),{anchorMiss:a}}function Re(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function Pe(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 De(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 Me(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(Nt(s.locator,n))continue;let c;if(s.locator){let m=re(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[w,E]of Object.entries(u))m.setAttribute(`data-${w}`,E);a&&(typeof s.content=="string"&&(m.textContent=s.content),s.ops&&Ut(m,s.ops,i,n).anchorMiss&&!o.includes(i)&&o.push(i))}}return o}var dr=800;function Ne(e,t,n){let r=[];return n.forEach(({slotId:a,arm:o,el:l},d)=>{r.push(ve((m,w={})=>{try{e.track({projectId:t,componentId:a,variantId:o,eventType:"micro_signal",payload:le({signalType:m},w)})}catch(E){}},l,void 0,{tabLoss: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},dr)},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 pr(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 fr(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 Gt="_snt_fired_goals";function gr(e){try{let t=e==null?void 0:e.sessionStorage.getItem(Gt);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 mr(e,t){try{e==null||e.sessionStorage.setItem(Gt,JSON.stringify([...t]))}catch(n){}}function qt(e,t,n){var C,k;let r=(C=n.defaultView)!=null?C:typeof window!="undefined"?window:null,a=gr(r),o=g=>{if(!a.has(g.goalId)){a.add(g.goalId),mr(r,a);try{g.slotId?t.componentGoal(g.slotId,g.goalId):t.goal(g.goalId)}catch(f){}}},l=e.filter(g=>g.event==="click"),d=e.filter(g=>g.event==="form_submit"),i=e.filter(g=>g.event==="url_reached"),s=e.filter(g=>g.event==="scroll_depth"),c=(g,f)=>{if(!g.locator)return!1;let x=re(g.locator,n);return!!x&&(x===f||x.contains(f))},u=g=>{let f=g.target;if(!(!f||typeof f.closest!="function"))for(let x of l)c(x,f)&&o(x)},m=g=>{let f=g.target;if(f)for(let x of d)c(x,f)&&o(x)},w=()=>{if(i.length===0)return;let g=pr(n);for(let f of i)f.urlPattern&&fr(f.urlPattern,g)&&o(f)},E=()=>{var x;let g=n.documentElement,f=g.scrollHeight>0?(g.scrollTop+g.clientHeight)/g.scrollHeight:0;for(let O of s)f>=((x=O.threshold)!=null?x:.75)&&o(O);s.every(O=>a.has(O.goalId))&&n.removeEventListener("scroll",E)};return n.addEventListener("click",u,!0),n.addEventListener("submit",m,!0),(k=n.defaultView)==null||k.addEventListener("popstate",w),w(),s.length>0&&(n.addEventListener("scroll",E,{passive:!0}),E()),{checkUrl:w,teardown:()=>{var g;n.removeEventListener("click",u,!0),n.removeEventListener("submit",m,!0),(g=n.defaultView)==null||g.removeEventListener("popstate",w),s.length>0&&n.removeEventListener("scroll",E)}}}var Wt="__snt_editor_token";function Vt(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(Wt):null}catch(e){return null}}function zt(e){try{sessionStorage.setItem(Wt,e)}catch(t){}}var Je="0.14.1",Qt=5e3,hr=50,yr=(()=>{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,N=null,te={},ie=null,H=null,K=null,ee=null,L=null,Jt=!1,ze=null,$e=null,je=null,be=!1,Ke=!1;function en(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function de(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function pe(e,t){return V?(V.personaAttributes&&L&&Re(L.persona,L.band,e),Pe(te,V.slots,e),De(te,V.slots,e),ie?Me(te,ie,e,t):[]):[]}function vr(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 we(){return!!(V&&N&&V.sectionCapture!==!1&&(V.consent!==!1||Ke)&&!ue())}function br(){if(!N||!V||!we()||ee)return;let e=[];pe(document,{contentAndOps:be,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),He();try{K==null||K(),K=Ne(N,V.apiKey,e)}catch(t){}}function He(){if(typeof document=="undefined"||!we())return;let e;try{if($e&&$e.length>0){let t=new Map;for(let n of $e){if(n.urlMatch!==window.location.pathname)continue;let r=re(n.locator,document);r&&t.set(r,n.type)}t.size>0&&(e=n=>{var r;return(r=t.get(n))!=null?r:null})}}catch(t){}try{ee=Dt(N,le({apiKey:V.apiKey,apiBase:V.apiBase,doc:document,microSignals:!0},e?{typeOf:e}:{})),je=window.location.pathname}catch(t){}}function Ye(){try{let e=[];if(K==null||K(),K=null,pe(document,{contentAndOps:be,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),e.length>0&&we())try{K=Ne(N,V.apiKey,e)}catch(t){}try{typeof window!="undefined"&&je!==null&&window.location.pathname!==je&&we()&&(ee==null||ee(),ee=null,He())}catch(t){}}catch(e){}}function Ft(){ze===null&&(ze=setTimeout(()=>{ze=null,Ye();try{H==null||H.checkUrl()}catch(e){}},hr))}function Ht(){if(!(Jt||typeof window=="undefined"||typeof history=="undefined")){Jt=!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 Ft(),l}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Ft)}catch(e){}}}function Fe(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 tn(e){return new URLSearchParams(e).get("sentient_editor")}function wr(){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 Sr(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:wr();if(!l){Xt();return}let d=document.createElement("script");d.src=l,d.async=!0,d.onerror=()=>Xt(),((o=document.head)!=null?o:document.documentElement).appendChild(d)}catch(l){}}var Yt="sentient-editor-load-notice";function Xt(){var e;try{if(typeof document=="undefined"||document.getElementById(Yt))return;let t=document.createElement("div");t.id=Yt,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 nn(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 rn(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var Zt="sentient-persona-preview-banner";function Ar(e){var t;try{if(typeof document=="undefined"||document.getElementById(Zt))return;let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),r=document.createElement("div");r.id=Zt,r.setAttribute("role","status"),Object.assign(r.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",background:"#111827",color:"#fff",font:"13px/1 system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.14)"});let 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 xr(e,t){var s,c,u,m,w,E,C,k,g;let n=(s=e.apiBase)!=null?s:"https://api.sentient-ui.com",a=((c=e.registry)!=null?c:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([f,x])=>({id:f,dims:x.dims}))},o=await en(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),Qt);if(!o){de(e,"persona preview: explain unavailable \u2014 page left as-is");return}let l=o;te=(u=l.slots)!=null?u:{},ie=(m=l.slotConfig)!=null?m:null;let d=(C=(E=(w=l.personaAttributes)==null?void 0:w.persona)!=null?E:l.persona)!=null?C:t,i=(g=(k=l.personaAttributes)==null?void 0:k.confidence)!=null?g:"high";L={persona:d,band:i},pe(document),be=!0,on(e),Ar(d)}function on(e){let t={goal(n,r){try{N==null||N.goal(n,r)}catch(a){}},componentGoal(n,r){try{N==null||N.componentGoal(n,r)}catch(a){}},grantConsent(){try{Ve(e.apiKey)}catch(n){}Ke=!0;try{br()}catch(n){}},revokeConsent(){try{ee==null||ee(),ee=null,je=null,K==null||K(),K=null,H==null||H.teardown(),H=null,Ke=!1,N==null||N.destroy()}catch(n){}},reapply:Ye,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:te,matchCounts:Fe(e),consent:e.consent!==!1}}};window.SentientSnippet=t;for(let n of yr.splice(0))try{n[0]==="goal"&&t.goal(n[1],n[2])}catch(r){}}async function sn(){var e,t,n,r,a;try{let o=Le(window.sentient);if(!o)return;V=o,be=!1,Ke=!1;let l=typeof window!="undefined"?tn(window.location.search):null;if(l){zt(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:Vt();if(d){Sr(o,d),de(o,"editor mode");return}let i=typeof window!="undefined"?nn(window.location.search):null;if(i){te=i,L=null,pe(document),Ht(),de(o,"preview mode",i);return}let s=typeof window!="undefined"?rn(window.location.search):null;if(s){await xr(o,s),de(o,"persona preview",s);return}let c=(e=o.registry)!=null?e:Object.keys(o.slots).length===0,u=_e(o.apiKey);u&&(L={persona:u.persona,band:u.band},te=u.slots,u.slotConfig&&(ie=u.slotConfig),pe(document,{contentAndOps:!1}));let m=Te({apiKey:o.apiKey,context:o.context,consent:o.consent,preConsentBehavior:o.preConsentBehavior,debug:o.debug});N=m,on(o),Ht();let w=Object.entries(o.slots).map(([f,x])=>({id:f,dims:x.dims})),E=Je!=="0.0.0-dev"?{v:Je}:{},C=await en(m.decide(le(le({slots:w},E),c?{slotsFrom:"registry"}:{})),Qt);if(!C){de(o,"decide timeout/null \u2014 snapshot state stands",Fe(o));return}let k=m.getPersona();k?L={persona:k.persona,band:k.band}:C.persona&&(L={persona:C.persona,band:"low"}),te=C.slots,c?ie=(t=C.slotConfig)!=null?t:null:C.slotConfig&&(ie=C.slotConfig);let g=[];if(vr(o,pe(document,{onApplied:(f,x,O)=>g.push({slotId:f,arm:x,el:O})})),be=!0,C.goals&&C.goals.length>0&&o.consent!==!1&&N)try{H==null||H.teardown(),H=qt(C.goals,N,document)}catch(f){}if($e=(n=C.sectionMap)!=null?n:null,we()){He();try{K==null||K(),K=Ne(N,o.apiKey,g)}catch(f){}}de(o,"applied",{persona:L,slots:te,matches:Fe(o)}),ye(o.apiKey,le({v:1,persona:(r=L==null?void 0:L.persona)!=null?r:C.persona,band:(a=L==null?void 0:L.band)!=null?a:"low",slots:C.slots,layoutOrder:C.layoutOrder,savedAt:Date.now()},ie?{slotConfig:ie}:{}))}catch(o){}}if(typeof window!="undefined"&&window.sentient){let e=window;e.__sentientInitialized||(e.__sentientInitialized=!0,sn())}return pn(Ir);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentientui/snippet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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.18.1"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "tsup",
|