@sentientui/snippet 0.22.1 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,6 +29,10 @@ page is left exactly as it was.
29
29
  },
30
30
  };
31
31
  </script>
32
+ <!-- Optional but recommended: the pre-paint tag. Copy the real thing from your
33
+ dashboard's Install page — it is one ~2.6 KB inline script, byte-identical
34
+ for every site, so it is not reproduced here. -->
35
+ <script>/* SentientUI pre-paint */</script>
32
36
  <script
33
37
  src="https://unpkg.com/@sentientui/snippet/dist/snippet.global.js"
34
38
  defer
@@ -36,6 +40,21 @@ page is left exactly as it was.
36
40
  ></script>
37
41
  ```
38
42
 
43
+ **The pre-paint tag.** The loader above is `defer`, so it runs after your page has parsed —
44
+ and on a return visit the browser may already have painted your original section order and
45
+ baseline styles before it does. The middle tag closes that gap: a tiny synchronous inline
46
+ script that applies the last served decision *before* the page paints. It reads only the
47
+ snapshot already stored on that visitor's own device, makes no network request, hides nothing
48
+ (there is no cloak here, by design), and does nothing at all on a first visit or for a
49
+ Do-Not-Track / Global Privacy Control / consent-gated visitor. Anything it gets wrong — a
50
+ selector that resolved differently mid-parse, say — the loader reverts within the same page
51
+ load. Skip it and everything still works; your returning visitors just see the change land a
52
+ beat later. Generating it yourself:
53
+
54
+ ```js
55
+ import { renderSnippetPrePaintScript } from '@sentientui/snippet/install';
56
+ ```
57
+
39
58
  The URL above carries no version: unpkg resolves it to the latest release, so your site picks
40
59
  up new snippet versions on its own and this tag is pasted once. That is the recommended setup,
41
60
  and what the Shopify app embed and the dashboard's install page both hand out.
@@ -68,11 +87,12 @@ role label — never a user id or email.
68
87
  your theme renders them (the first learned baseline). Each selector must match exactly one
69
88
  element and all of them must share one parent; anything else — a missing section, an ambiguous
70
89
  selector, a served order that isn't a permutation of your list — applies nothing. Return visits
71
- pre-paint the last served order from a local snapshot, so there is no natural-order flash.
90
+ apply the last served order from a local snapshot; with the pre-paint tag installed that
91
+ happens before the browser paints, so there is no natural-order flash at all.
72
92
 
73
93
  The snippet also captures per-section attention (visible time + scroll depth) and behavioral
74
94
  signals by default — that's what builds audience profiles with zero tagging. Add
75
95
  `sectionCapture: false` to `window.sentient` to turn it off; it never runs for a Do-Not-Track,
76
96
  Global Privacy Control, or consent-gated visitor.
77
97
 
78
- Bundle ≤ 21 KiB gzip (CI-enforced). MIT.
98
+ Bundle ≤ 23 KiB gzip, pre-paint tag ≤ 3 KiB raw (both CI-enforced). MIT.
@@ -1,5 +1,5 @@
1
- "use strict";var SentientSnippet=(()=>{var at=Object.defineProperty,zn=Object.defineProperties,Nn=Object.getOwnPropertyDescriptor,Dn=Object.getOwnPropertyDescriptors,Fn=Object.getOwnPropertyNames,an=Object.getOwnPropertySymbols;var dn=Object.prototype.hasOwnProperty,jn=Object.prototype.propertyIsEnumerable;var ln=(n,t,r)=>t in n?at(n,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[t]=r,A=(n,t)=>{for(var r in t||(t={}))dn.call(t,r)&&ln(n,r,t[r]);if(an)for(var r of an(t))jn.call(t,r)&&ln(n,r,t[r]);return n},Y=(n,t)=>zn(n,Dn(t));var Un=(n,t)=>{for(var r in t)at(n,r,{get:t[r],enumerable:!0})},qn=(n,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of Fn(t))!dn.call(n,c)&&c!==r&&at(n,c,{get:()=>t[c],enumerable:!(i=Nn(t,c))||i.enumerable});return n};var Gn=n=>qn(at({},"__esModule",{value:!0}),n);var ko={};Un(ko,{buildStyleOps:()=>Ht,clearTargetHighlights:()=>ze,computeMoveAnchors:()=>mt,deriveSlotId:()=>Je,drawTargetHighlights:()=>wn,isHex6:()=>yt,mount:()=>Sn,registerAuditTargets:()=>kn,styleFieldError:()=>En,toHexColor:()=>gt});function Wn(n){var r,i,c;let t=(i=(r=n.defaultView)!=null?r:typeof window!="undefined"?window:void 0)==null?void 0:i.location;return(c=t==null?void 0:t.pathname)!=null?c:""}function Yn(n,t){var r;if(t.tag&&n.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let i=((r=n.textContent)!=null?r:"").replace(/\s+/g," ").trim().toLowerCase(),c=t.text.replace(/\s+/g," ").trim().toLowerCase();if(!(i===c||i.startsWith(c)||c.startsWith(i)))return!1}return!0}var Vn=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function ue(n,t){var c;if(n.urlMatch&&!Wn(t).includes(n.urlMatch))return null;let r=[];if(n.id){let p=t.getElementById(n.id);r=p?[p]:[]}if(r.length===0&&((c=n.dataAttr)!=null&&c.name)&&Vn.test(n.dataAttr.name))try{let p=n.dataAttr.value.replace(/["\\]/g,"\\$&");r=Array.from(t.querySelectorAll(`[${n.dataAttr.name}="${p}"]`))}catch(p){r=[]}if(r.length===0&&n.selector)try{r=Array.from(t.querySelectorAll(n.selector))}catch(p){r=[]}if(r.length!==1)return null;let i=r[0];return n.fingerprint&&!Yn(i,n.fingerprint)?null:i}function cn(n){let t=globalThis;if(t.CSS&&typeof t.CSS.escape=="function")return t.CSS.escape(n);let r="";for(let i=0;i<n.length;i++){let c=n[i],p=c>="0"&&c<="9";i===0&&p||i===1&&p&&n[0]==="-"?r+=`\\3${c} `:i===0&&c==="-"&&n.length===1?r+="\\-":/[a-zA-Z0-9_-]/.test(c)?r+=c:r+=`\\${c}`}return r}function Jn(n,t){if(n.id)return`#${cn(n.id)}`;let r=[],i=n,c=0;for(;i&&i!==t.body&&i!==t.documentElement&&c<6;){if(i.id){r.unshift(`#${cn(i.id)}`);break}let p=i.tagName.toLowerCase(),w=i.parentElement;if(w){let $=Array.from(w.children).filter(L=>L.tagName===i.tagName);$.length>1&&(p+=`:nth-of-type(${$.indexOf(i)+1})`)}r.unshift(p),i=i.parentElement,c++}return r.join(" > ")}function Pe(n,t){var c;let r={v:1};n.id&&(r.id=n.id);for(let p of["data-framer-name","data-w-id","data-sentient-name"]){let w=n.getAttribute(p);if(w){r.dataAttr={name:p,value:w};break}}r.selector=Jn(n,t);let i=((c=n.textContent)!=null?c:"").trim().replace(/\s+/g," ").slice(0,80);return r.fingerprint=A({tag:n.tagName.toLowerCase()},i?{text:i}:{}),r}function Ye(n,t,r){return ue(n,r)===t}var Kn="__snt_editor_token";function lt(){try{sessionStorage.removeItem(Kn)}catch(n){}}var Xn=/rgba\([^)]*,\s*0\s*\)$/,Zn=/^\d+(\.\d+)?px$/;function un(n){var t,r;try{let i=n.defaultView;if(!i||!n.body)return null;let c=i.getComputedStyle(n.body).backgroundColor,p=n.querySelectorAll('button, [role="button"], input[type="submit"], a[class*="btn" i], a[class*="button" i]'),w=new Map;for(let V of Array.from(p).slice(0,300)){let D=V.getBoundingClientRect();if(D.width>0&&(D.width<48||D.height<24))continue;let M=i.getComputedStyle(V),F=M.backgroundColor;if(!F||F==="transparent"||F===c||Xn.test(F))continue;let G=(t=(M.borderRadius||"").split(" ")[0])!=null?t:"",Z=`${F}|${M.color}|${Zn.test(G)?G:"8px"}`;w.set(Z,((r=w.get(Z))!=null?r:0)+1)}let $=null,L=0;for(let[V,D]of w)D>L&&($=V,L=D);if(!$)return null;let[z,H,fe]=$.split("|");return{primaryBg:z,primaryText:H,radius:fe}}catch(i){return null}}var dt={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"},Qn=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function Ve(n){var i;if(n.trim().length===0||/[;{}<>]/.test(n))return!1;let t=/([A-Za-z-]*)\(/g,r;for(;(r=t.exec(n))!==null;)if(!Qn.test((i=r[1])!=null?i:""))return!1;return!0}var pn=/^https:\/\//i,fn=new Map,pe=null;function eo(n){return n.replace(/["\\]/g,"\\$&")}function to(n){var t;(!pe||!pe.isConnected)&&(pe=n.querySelector("style[data-sentient-ops]"),pe||(pe=n.createElement("style"),pe.setAttribute("data-sentient-ops",""),((t=n.head)!=null?t:n.documentElement).appendChild(pe))),pe.textContent=[...fn.entries()].map(([r,i])=>`[data-snt-e="${eo(r)}"]{${i}}`).join(`
2
- `)}function gn(n,t,r,i){var $;let c=!1,p=($=t.moveBefore)!=null?$:t.moveAfter;if(p){let L=ue(p,i);!L||L===n||L.parentElement!==n.parentElement||!n.parentElement?c=!0:t.moveBefore?n.parentElement.insertBefore(n,L):n.parentElement.insertBefore(n,L.nextSibling)}typeof t.text=="string"&&(n.textContent=t.text),typeof t.href=="string"&&pn.test(t.href)&&n.setAttribute("href",t.href),typeof t.imageSrc=="string"&&pn.test(t.imageSrc)&&n.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&n.setAttribute("alt",t.imageAlt);let w=[];if(t.hidden&&w.push("display:none !important"),t.style)for(let[L,z]of Object.entries(t.style)){let H=dt[L];H&&typeof z=="string"&&Ve(z)&&w.push(`${H}:${z.trim()} !important`)}return w.length>0&&(n.setAttribute("data-snt-e",r),fn.set(r,w.join(";")),to(i)),{anchorMiss:c}}function ct(n){let t=n.steps.length,r=n.status==="active"?"":` (${n.status})`;return`${n.display_name} \u2014 ${t} step${t===1?"":"s"}${r}`}function ut(n,t){return n.steps.map(r=>{var i;return{value:r.step_index,label:`${r.step_index+1}. ${(i=t.get(r.goal_id))!=null?i:r.goal_id}`}})}function mn(n,t){return n.includes(t)?n.filter(r=>r!==t):[...n,t]}function no(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"funnel"}function hn(n,t){let r=n.trim();return r?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:no(r),body:{displayName:r.slice(0,128),steps:t.map(i=>({goalId:i}))}}:{ok:!1,error:"Give the funnel a name."}}function bn(n){let t=5381;for(let r=0;r<n.length;r++)t=(t<<5)+t+n.charCodeAt(r)>>>0;return t.toString(36)}function ft(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40)}function Je(n,t,r){var $,L;let i=t.id||(($=t.dataAttr)==null?void 0:$.value)||((L=r.textContent)!=null?L:"").trim()||r.tagName,c=ft(i)||"el",p=bn(JSON.stringify(t));return`${n}-${c}-${p}`.slice(0,128)}var oo="sentient-editor-highlight",ro="sentient-editor-selection",Oe="sentient-editor-panel",ht="sentient-editor-toast",$t="sentient-editor-styles",At="sentient-editor-target-highlight",io=10,so="Editor session expired. Reopen it from your dashboard to keep editing \u2014 your saved changes are safe.",ao="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.";function xn(){var t;if(document.getElementById($t))return;let n=document.createElement("style");n.id=$t,n.textContent=`
1
+ "use strict";var SentientSnippet=(()=>{var at=Object.defineProperty,Fn=Object.defineProperties,jn=Object.getOwnPropertyDescriptor,qn=Object.getOwnPropertyDescriptors,Un=Object.getOwnPropertyNames,ln=Object.getOwnPropertySymbols;var cn=Object.prototype.hasOwnProperty,Gn=Object.prototype.propertyIsEnumerable;var dn=(n,t,r)=>t in n?at(n,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[t]=r,A=(n,t)=>{for(var r in t||(t={}))cn.call(t,r)&&dn(n,r,t[r]);if(ln)for(var r of ln(t))Gn.call(t,r)&&dn(n,r,t[r]);return n},U=(n,t)=>Fn(n,qn(t));var Wn=(n,t)=>{for(var r in t)at(n,r,{get:t[r],enumerable:!0})},Yn=(n,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of Un(t))!cn.call(n,u)&&u!==r&&at(n,u,{get:()=>t[u],enumerable:!(i=jn(t,u))||i.enumerable});return n};var Vn=n=>Yn(at({},"__esModule",{value:!0}),n);var To={};Wn(To,{buildStyleOps:()=>Ht,clearTargetHighlights:()=>Fe,computeMoveAnchors:()=>mt,deriveSlotId:()=>Ke,drawTargetHighlights:()=>En,isHex6:()=>yt,mount:()=>Cn,registerAuditTargets:()=>wn,sectionTypesFor:()=>Sn,styleFieldError:()=>Tn,toHexColor:()=>gt});function Jn(n){var r,i,u;let t=(i=(r=n.defaultView)!=null?r:typeof window!="undefined"?window:void 0)==null?void 0:i.location;return(u=t==null?void 0:t.pathname)!=null?u:""}function Kn(n,t){var r;if(t.tag&&n.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let i=((r=n.textContent)!=null?r:"").replace(/\s+/g," ").trim().toLowerCase(),u=t.text.replace(/\s+/g," ").trim().toLowerCase();if(!(i===u||i.startsWith(u)||u.startsWith(i)))return!1}return!0}var Xn=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function he(n,t){var u;if(n.urlMatch&&!Jn(t).includes(n.urlMatch))return null;let r=[];if(n.id){let p=t.getElementById(n.id);r=p?[p]:[]}if(r.length===0&&((u=n.dataAttr)!=null&&u.name)&&Xn.test(n.dataAttr.name))try{let p=n.dataAttr.value.replace(/["\\]/g,"\\$&");r=Array.from(t.querySelectorAll(`[${n.dataAttr.name}="${p}"]`))}catch(p){r=[]}if(r.length===0&&n.selector)try{r=Array.from(t.querySelectorAll(n.selector))}catch(p){r=[]}if(r.length!==1)return null;let i=r[0];return n.fingerprint&&!Kn(i,n.fingerprint)?null:i}function un(n){let t=globalThis;if(t.CSS&&typeof t.CSS.escape=="function")return t.CSS.escape(n);let r="";for(let i=0;i<n.length;i++){let u=n[i],p=u>="0"&&u<="9";i===0&&p||i===1&&p&&n[0]==="-"?r+=`\\3${u} `:i===0&&u==="-"&&n.length===1?r+="\\-":/[a-zA-Z0-9_-]/.test(u)?r+=u:r+=`\\${u}`}return r}function Zn(n,t){if(n.id)return`#${un(n.id)}`;let r=[],i=n,u=0;for(;i&&i!==t.body&&i!==t.documentElement&&u<6;){if(i.id){r.unshift(`#${un(i.id)}`);break}let p=i.tagName.toLowerCase(),k=i.parentElement;if(k){let $=Array.from(k.children).filter(L=>L.tagName===i.tagName);$.length>1&&(p+=`:nth-of-type(${$.indexOf(i)+1})`)}r.unshift(p),i=i.parentElement,u++}return r.join(" > ")}function Ne(n,t){var u;let r={v:1};n.id&&(r.id=n.id);for(let p of["data-framer-name","data-w-id","data-sentient-name"]){let k=n.getAttribute(p);if(k){r.dataAttr={name:p,value:k};break}}r.selector=Zn(n,t);let i=((u=n.textContent)!=null?u:"").trim().replace(/\s+/g," ").slice(0,80);return r.fingerprint=A({tag:n.tagName.toLowerCase()},i?{text:i}:{}),r}function Ve(n,t,r){return he(n,r)===t}var Qn="__snt_editor_token";function lt(){try{sessionStorage.removeItem(Qn)}catch(n){}}var eo=/rgba\([^)]*,\s*0\s*\)$/,to=/^\d+(\.\d+)?px$/;function pn(n){var t,r;try{let i=n.defaultView;if(!i||!n.body)return null;let u=i.getComputedStyle(n.body).backgroundColor,p=n.querySelectorAll('button, [role="button"], input[type="submit"], a[class*="btn" i], a[class*="button" i]'),k=new Map;for(let V of Array.from(p).slice(0,300)){let j=V.getBoundingClientRect();if(j.width>0&&(j.width<48||j.height<24))continue;let H=i.getComputedStyle(V),q=H.backgroundColor;if(!q||q==="transparent"||q===u||eo.test(q))continue;let W=(t=(H.borderRadius||"").split(" ")[0])!=null?t:"",Z=`${q}|${H.color}|${to.test(W)?W:"8px"}`;k.set(Z,((r=k.get(Z))!=null?r:0)+1)}let $=null,L=0;for(let[V,j]of k)j>L&&($=V,L=j);if(!$)return null;let[D,I,be]=$.split("|");return{primaryBg:D,primaryText:I,radius:be}}catch(i){return null}}var dt={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"},no=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function Je(n){var i;if(n.trim().length===0||/[;{}<>]/.test(n))return!1;let t=/([A-Za-z-]*)\(/g,r;for(;(r=t.exec(n))!==null;)if(!no.test((i=r[1])!=null?i:""))return!1;return!0}var fn=/^https:\/\//i,gn=new Map,ye=null;function oo(n){return n.replace(/["\\]/g,"\\$&")}function ro(n){var t;(!ye||!ye.isConnected)&&(ye=n.querySelector("style[data-sentient-ops]"),ye||(ye=n.createElement("style"),ye.setAttribute("data-sentient-ops",""),((t=n.head)!=null?t:n.documentElement).appendChild(ye))),ye.textContent=[...gn.entries()].map(([r,i])=>`[data-snt-e="${oo(r)}"]{${i}}`).join(`
2
+ `)}function mn(n,t,r,i){var $;let u=!1,p=($=t.moveBefore)!=null?$:t.moveAfter;if(p){let L=he(p,i);!L||L===n||L.parentElement!==n.parentElement||!n.parentElement?u=!0:t.moveBefore?n.parentElement.insertBefore(n,L):n.parentElement.insertBefore(n,L.nextSibling)}typeof t.text=="string"&&(n.textContent=t.text),typeof t.href=="string"&&fn.test(t.href)&&n.setAttribute("href",t.href),typeof t.imageSrc=="string"&&fn.test(t.imageSrc)&&n.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&n.setAttribute("alt",t.imageAlt);let k=[];if(t.hidden&&k.push("display:none !important"),t.style)for(let[L,D]of Object.entries(t.style)){let I=dt[L];I&&typeof D=="string"&&Je(D)&&k.push(`${I}:${D.trim()} !important`)}return k.length>0&&(n.setAttribute("data-snt-e",r),gn.set(r,k.join(";")),ro(i)),{anchorMiss:u}}function ct(n){let t=n.steps.length,r=n.status==="active"?"":` (${n.status})`;return`${n.display_name} \u2014 ${t} step${t===1?"":"s"}${r}`}function ut(n,t){return n.steps.map(r=>{var i;return{value:r.step_index,label:`${r.step_index+1}. ${(i=t.get(r.goal_id))!=null?i:r.goal_id}`}})}function hn(n,t){return n.includes(t)?n.filter(r=>r!==t):[...n,t]}function io(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"funnel"}function yn(n,t){let r=n.trim();return r?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:io(r),body:{displayName:r.slice(0,128),steps:t.map(i=>({goalId:i}))}}:{ok:!1,error:"Give the funnel a name."}}function xn(n){let t=5381;for(let r=0;r<n.length;r++)t=(t<<5)+t+n.charCodeAt(r)>>>0;return t.toString(36)}function ft(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40)}function Ke(n,t,r){var $,L;let i=t.id||(($=t.dataAttr)==null?void 0:$.value)||((L=r.textContent)!=null?L:"").trim()||r.tagName,u=ft(i)||"el",p=xn(JSON.stringify(t));return`${n}-${u}-${p}`.slice(0,128)}var so="sentient-editor-highlight",ao="sentient-editor-selection",De="sentient-editor-panel",ht="sentient-editor-toast",$t="sentient-editor-styles",At="sentient-editor-target-highlight",lo=10,co="Editor session expired. Reopen it from your dashboard to keep editing \u2014 your saved changes are safe.",uo="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.";function vn(){var t;if(document.getElementById($t))return;let n=document.createElement("style");n.id=$t,n.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
- #${Oe} {
15
+ #${De} {
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
- #${Oe} .sntedi-dot { animation: sntedi-dot 1.4s ease-in-out infinite; }
19
+ #${De} .sntedi-dot { animation: sntedi-dot 1.4s ease-in-out infinite; }
20
20
  #${ht} { animation: sntedi-in 0.42s cubic-bezier(0.2,0.9,0.25,1.15) both; }
21
21
  @media (prefers-reduced-motion: reduce) {
22
- #${Oe}, #${Oe} .sntedi-dot, #${ht} { animation: none !important; }
22
+ #${De}, #${De} .sntedi-dot, #${ht} { animation: none !important; }
23
23
  }
24
- `,((t=document.head)!=null?t:document.documentElement).appendChild(n)}function yn(n){var i,c;xn(),(i=document.getElementById(ht))==null||i.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=ht;let r=a("span",{width:"9px",height:"9px",marginTop:"4px",borderRadius:"50%",background:"#f59e0b",flex:"0 0 auto"});t.append(r,a("div",{},n)),((c=document.body)!=null?c:document.documentElement).appendChild(t),t.addEventListener("click",()=>t.remove()),setTimeout(()=>t.remove(),1e4)}function lo(){let n=window.__sentientEditor;return n&&typeof n.token=="string"&&typeof n.apiBase=="string"?n:null}async function co(n){try{let t=await fetch(`${n.apiBase}/v1/editor/verify`,{headers:{authorization:`Bearer ${n.token}`}});if(t.status===401)return{ok:!1,unauthorized:!0};if(!t.ok)return{ok:!1,unauthorized:!1};let r=(await t.json()).projectId;return r?{ok:!0,projectId:r}:{ok:!1,unauthorized:!1}}catch(t){return{ok:!1,unauthorized:!1}}}function It(n,t){return A(A(A(A({r:n===401?"expired":"error",status:n},typeof(t==null?void 0:t.error)=="string"?{code:t.error}:{}),typeof(t==null?void 0:t.message)=="string"?{message:t.message}:{}),typeof(t==null?void 0:t.feature)=="string"?{feature:t.feature}:{}),typeof(t==null?void 0:t.plan)=="string"?{plan:t.plan}:{})}async function q(n,t,r){try{let i=await fetch(`${n.apiBase}${t}`,{method:"POST",headers:{authorization:`Bearer ${n.token}`,"content-type":"application/json"},body:JSON.stringify(r)});if(i.ok)return{r:"ok"};let c=await i.json().catch(()=>null);return It(i.status,c)}catch(i){return{r:"error"}}}async function uo(n,t){try{let r=await fetch(`${n.apiBase}${t}`,{method:"DELETE",headers:{authorization:`Bearer ${n.token}`}});if(r.ok)return{r:"ok"};let i=await r.json().catch(()=>null);return It(r.status,i)}catch(r){return{r:"error"}}}async function po(n,t,r){try{let i=await fetch(`${n.apiBase}${t}`,{method:"POST",headers:{authorization:`Bearer ${n.token}`,"content-type":"application/json"},body:JSON.stringify(r)}),c=await i.json().catch(()=>null);return i.ok?{r:"ok",data:c,outcome:{r:"ok"}}:{r:i.status===401?"expired":"error",data:c,outcome:It(i.status,c)}}catch(i){return{r:"error",data:null,outcome:{r:"error"}}}}var Rt=[];function yt(n){return/^#[0-9a-fA-F]{6}$/.test(n)}function gt(n){let t=n.trim();if(yt(t))return t;let r=/^#([0-9a-fA-F]{3})$/.exec(t);if(r)return`#${r[1].split("").map(p=>p+p).join("")}`;let i=/^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/.exec(t);if(!i)return t;let c=p=>Math.min(255,Number(p)).toString(16).padStart(2,"0");return`#${c(i[1])}${c(i[2])}${c(i[3])}`}var ie=null,vn=[];function kn(n){vn=n}async function fo(n){try{let t=await fetch(`${n.apiBase}/v1/editor/targets`,{headers:{authorization:`Bearer ${n.token}`}});if(!t.ok)return[];let r=await t.json();return Rt=Array.isArray(r.fonts)?r.fonts.filter(i=>typeof i=="string"):[],Array.isArray(r.targets)?r.targets:[]}catch(t){return[]}}async function pt(n,t){try{let r=await fetch(`${n.apiBase}${t}`,{headers:{authorization:`Bearer ${n.token}`}});return r.ok?await r.json():null}catch(r){return null}}function ze(n=document){for(let t of Array.from(n.querySelectorAll(`.${At}`)))t.remove()}function wn(n,t=document){var i;ze(t);let r=0;for(let c of n){if(r>=io)break;let p=ue(c.locator,t);if(!p)continue;let w=p.getBoundingClientRect(),$=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${w.left}px`,top:`${w.top}px`,width:`${w.width}px`,height:`${w.height}px`,border:"2px dashed #10b981",background:"rgba(16,185,129,0.08)"});$.className=At;let L=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${w.left}px`,top:`${Math.max(0,w.top-20)}px`,padding:"2px 6px",borderRadius:"4px",background:"#10b981",color:"#fff",font:"11px system-ui, sans-serif",whiteSpace:"nowrap"},c.label);L.className=At,((i=t.body)!=null?i:t.documentElement).append($,L),r+=1}}function mt(n,t){let r=n.previousElementSibling,i=n.nextElementSibling,c=r?Pe(r,t):null,p=i?Pe(i,t):null;return{prevEl:r,nextEl:i,prevLocator:r&&c&&Ye(c,r,t)?c:null,nextLocator:i&&p&&Ye(p,i,t)?p:null}}var Mt=["color","background","fontSize","fontWeight","borderRadius","textAlign","fontFamily"],go=/^(0|\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|pt))$/i,mo=new Set(["left","center","right","justify","start","end"]),ho=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,yo=/^(rgb|rgba|hsl|hsla)\(/i;function bo(n){return ho.test(n)||yo.test(n)}function En(n,t){switch(n){case"fontSize":case"borderRadius":return go.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 mo.has(t.toLowerCase())?null:"Choose left, center, right, or justify.";case"color":case"background":return bo(t)?null:"Enter a colour, e.g. #1a1a1a.";case"fontFamily":{let r=t.split(",").map(i=>i.trim().replace(/^['"]|['"]$/g,""));return t.length<=120&&r.length>=1&&r.length<=5&&r.every(i=>/^[A-Za-z0-9][A-Za-z0-9 -]*$/.test(i))?null:"Use a font name, e.g. Georgia, serif."}default:return null}}function Ht(n){let t={},r={};for(let i of Mt){let c=n[i];if(typeof c!="string")continue;let p=c.trim();if(p==="")continue;if(!Ve(p)){r[i]="That value isn\u2019t allowed.";continue}let w=En(i,p);if(w){r[i]=w;continue}t[i]=p}return{style:t,errors:r}}function a(n,t,r){let i=document.createElement(n);return Object.assign(i.style,t),r!==void 0&&(i.textContent=r),i}function Sn(n){var sn;let t=null,r=[],i=null,c=()=>{for(;r.length>0;){let e=r.splice(0,20);try{fetch(`${n.apiBase}/v1/editor/telemetry`,{method:"POST",keepalive:!0,headers:{authorization:`Bearer ${n.token}`,"content-type":"application/json"},body:JSON.stringify({events:e})}).catch(()=>{})}catch(o){}}},p=(e,o)=>{r.push(A({kind:e},o?{meta:o}:{})),i&&clearTimeout(i),i=setTimeout(c,2e3)};window.addEventListener("pagehide",c);let w=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #6366f1",background:"rgba(99,102,241,0.12)",display:"none"});w.id=oo;let $=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #10b981",background:"rgba(16,185,129,0.10)",borderRadius:"4px",display:"none"});$.id=ro;let L=()=>{if(!t||!t.isConnected){$.style.display="none";return}let e=t.getBoundingClientRect();Object.assign($.style,{display:"block",left:`${e.left-2}px`,top:`${e.top-2}px`,width:`${e.width}px`,height:`${e.height}px`})},z=()=>L();xn();let H=a("div",{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",width:"min(408px, calc(100vw - 32px))",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)",maxHeight:"calc(100vh - 32px)",overflowY:"auto",overscrollBehavior:"contain"});H.id=Oe;let fe=a("span",{width:"9px",height:"9px",borderRadius:"50%",background:"#34d399",display:"inline-block",flex:"0 0 auto"});fe.className="sntedi-dot";let V=a("div",{display:"flex",alignItems:"center",gap:"8px",fontWeight:"700",fontSize:"14px",marginBottom:"6px"});V.append(fe,a("span",{},"SentientUI"));let D=a("div",{opacity:"0.85",marginBottom:"8px"},"Click any element on the page to adapt it."),M=!1,F=a("button",T("#374151"),"Pause selecting");F.onclick=()=>{M=!M,F.textContent=M?"Resume selecting":"Pause selecting",M?(w.style.display="none",ze(document),y("Selection paused \u2014 browse normally, then resume.")):y("Click any element on the page to adapt it.")};let G=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"}),Z=a("div",{fontSize:"12px",marginBottom:"8px",minHeight:"16px"}),I=a("button",T("#6366f1"),"Test different text here"),N=a("button",T("#374151"),"Change style"),se=a("button",T("#374151"),"Try a different arrangement"),W=a("button",T("#374151"),"Track clicks as a goal"),C=a("button",T("#374151"),"Track form submissions as a goal"),Q=a("button",T("#374151"),"Track page visits as a goal"),ae=a("button",T("#374151"),"Track reading this far as a goal"),Pt=a("button",T("#374151"),"Set up a funnel"),Ne=a("button",T("#374151"),"Attach this test to a funnel step"),ge=a("button",T("#10b981"),"Turn the funnel on"),le=a("button",T("#374151"),"Move up"),de=a("button",T("#374151"),"Move down"),Ke=a("button",T("#6366f1"),"Save this arrangement"),Xe=a("button",T("#374151"),"Undo"),Ce=a("button",Y(A({},T("transparent")),{opacity:"0.6"}),"Close editor"),te=a("button",T("#10b981"),"Publish now \u2014 go live"),ne=a("button",T("#10b981"),"Start tracking now");for(let e of[I,N,se,W,le,de])e.disabled=!0;let bt=[I,N,se,W,C,le,de];for(let e of bt)e.style.display="none";Ke.style.display="none",Xe.style.display="none",te.style.display="none",ne.style.display="none",Ne.style.display="none",ge.style.display="none";let oe=a("div",{display:"none",fontSize:"11px",opacity:"0.75",marginBottom:"2px",lineHeight:"1.8",overflow:"hidden",textOverflow:"ellipsis"}),Le=a("div",{}),Ot=[{id:"text",label:"Text",icon:"\u270F\uFE0F"},{id:"style",label:"Style",icon:"\u{1F3A8}"},{id:"layout",label:"Layout",icon:"\u{1F9F1}"},{id:"goals",label:"Goals",icon:"\u{1F3AF}"},{id:"funnels",label:"Funnels",icon:"\u{1F9ED}"},{id:"drafts",label:"Drafts",icon:"\u{1F5C2}\uFE0F"}],J="text",zt=new Map,ce=new Map,xt=new Map,Nt=a("div",{display:"flex",gap:"0",margin:"10px 0 0",justifyContent:"space-between",borderBottom:"1px solid rgba(255,255,255,0.1)"}),Dt=a("div",{paddingTop:"10px"});for(let e of Ot){let o=a("button",{background:"transparent",border:"none",cursor:"pointer",font:"600 11.5px system-ui, sans-serif",color:"#9ca3af",whiteSpace:"nowrap",padding:"7px 5px",borderBottom:"2px solid transparent",marginBottom:"-1px"});o.append(a("span",{fontSize:"11px",marginRight:"3px"},e.icon),a("span",{},e.label)),o.onclick=()=>vt(e.id),zt.set(e.id,o),Nt.append(o);let s=a("div",{display:"none"}),l=a("div",{fontSize:"12px",opacity:"0.7",padding:"2px 0 6px",display:"none"});s.append(l),xt.set(e.id,l),ce.set(e.id,s),Dt.append(s)}ce.get("text").append(I),ce.get("style").append(N),ce.get("layout").append(se,le,de,Ke,Xe),ce.get("goals").append(W,C,Q,ae),ce.get("funnels").append(Pt,Ne,ge);let K=a("div",{});ce.get("drafts").append(K);let Ze=()=>{var o,s;for(let l of Ot){let d=l.id===J,f=zt.get(l.id);f.style.color=d?"#ffffff":"#9ca3af",f.style.borderBottom=d?"2px solid #6366f1":"2px solid transparent",ce.get(l.id).style.display=d?"block":"none",xt.get(l.id).style.display="none"}let e=l=>{let d=xt.get(J);d.textContent=l,d.style.display="block"};J==="text"?t?I.disabled?e(I.title||"This element can\u2019t be targeted reliably \u2014 try its heading or a button."):(o=I.onclick)==null||o.call(I,new MouseEvent("click")):e("Click any text on the page to test a different wording."):J==="style"?t?N.disabled?e("This element can\u2019t be targeted reliably \u2014 try a heading, a button, or a whole section."):(s=N.onclick)==null||s.call(N,new MouseEvent("click")):e("Click any element on the page to change how it looks."):J==="layout"?t||e("Click a section to rearrange it, move it, or test a catalog layout against it."):J==="goals"?t||e("Page-level goals work right away; click a button or form to track it specifically."):J==="funnels"?e("Chain tracked goals into a journey \u2014 the drop-off view fills in as visitors move through it."):J==="drafts"&&_e()},Cn=(e,o,s)=>{e.onclick=()=>{if(e.dataset.armed==="1"){e.dataset.armed="",s();return}e.dataset.armed="1",e.textContent="Sure?",setTimeout(()=>{e.isConnected&&e.dataset.armed==="1"&&(e.dataset.armed="",e.textContent=o)},4e3)}},Be=(e,o)=>a("button",Y(A({},T(e)),{display:"inline-block",width:"auto",margin:"0",padding:"4px 9px",fontSize:"11px",flex:"0 0 auto"}),o),Ft=(e,o)=>{let s=new URL(window.location.href);s.searchParams.delete("sentient_editor"),s.searchParams.set("sentient_preview",e),o&&s.searchParams.set("sentient_arm",o),window.location.assign(s.toString())},Qe=(e,o,s)=>{let l=Be("#374151","Discard");return Cn(l,"Discard",async()=>{l.disabled=!0;let d=await uo(n,e);l.disabled=!1,X(d,o),d.r==="ok"&&s()}),l},jt=(e,o)=>{he.textContent="";let s=a("div",{margin:"0 0 6px",padding:"8px 10px",borderRadius:"8px",fontSize:"12px",background:"rgba(99,102,241,0.10)",border:"1px solid rgba(99,102,241,0.35)"}),l=a("div",{display:"flex",gap:"6px",flexWrap:"wrap"});l.append(...o),s.append(a("div",{marginBottom:"6px"},e),l),he.append(s)},_e=async()=>{var g,b,m,x,E,v,S,R,j,Ee,qe,st;K.textContent="",K.append(a("div",{fontSize:"12px",opacity:"0.6",padding:"4px 0"},"Loading\u2026"));let e=[],o=[],s=null,l=!1;if(await Promise.all([(async()=>{var k;try{let _=await fetch(`${n.apiBase}/v1/editor/slots`,{headers:{authorization:`Bearer ${n.token}`}});_.ok?e=(k=(await _.json()).slots)!=null?k:[]:s=_.status===401?"expired":"error"}catch(_){s="error"}})(),(async()=>{var k;try{let _=await fetch(`${n.apiBase}/v1/editor/goals`,{headers:{authorization:`Bearer ${n.token}`}});_.ok?o=(k=(await _.json()).goals)!=null?k:[]:l=!0}catch(_){l=!0}})()]),J!=="drafts")return;if(K.textContent="",s){if(K.append(a("div",{fontSize:"12px",opacity:"0.8",padding:"4px 0"},s==="expired"?"Editor session expired \u2014 reopen it from your dashboard to see your drafts. They\u2019re safe.":"Couldn\u2019t load your drafts \u2014 they\u2019re safe; check your connection and retry.")),s==="error"){let k=Be("#374151","Retry");k.onclick=()=>{_e()},K.append(k)}return}let d=e.filter(k=>{var _,U,Se,Ge,Te,We;return((Se=(U=(_=k.draft_config)==null?void 0:_.arms)==null?void 0:U.length)!=null?Se:0)>0||((We=(Te=(Ge=k.published_config)==null?void 0:Ge.arms)==null?void 0:Te.length)!=null?We:0)>0}),f=o.filter(k=>k.event!=="custom"&&(k.status==="draft"||k.status==="active"));if(d.length===0&&f.length===0&&!l){K.append(a("div",{fontSize:"12px",opacity:"0.7",padding:"4px 0"},"Nothing saved yet \u2014 changes and goals you save land here, previewable before they go live."));return}let u=k=>a("span",{fontSize:"10px",padding:"2px 7px",borderRadius:"999px",flex:"0 0 auto",background:k?"rgba(16,185,129,0.2)":"rgba(99,102,241,0.25)",color:k?"#6ee7b7":"#c7d2fe"},k?"live":"draft"),h=k=>{let _=a("div",{display:"flex",alignItems:"center",gap:"6px",padding:"7px 0",borderBottom:"1px solid rgba(255,255,255,0.08)",fontSize:"12px"}),U=a("div",{flex:"1 1 auto",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},k);return _.append(U),{row:_,name:U}};for(let k of d){let{row:_}=h((g=k.display_name)!=null?g:k.slot_id);_.append(u(k.status==="published"));let U=(E=(x=(b=k.draft_config)==null?void 0:b.arms)!=null?x:(m=k.published_config)==null?void 0:m.arms)!=null?E:[],Se=(R=(v=U[1])==null?void 0:v.id)!=null?R:(S=U[0])==null?void 0:S.id,Ge=Be("#374151","Preview");if(Ge.onclick=()=>Ft(k.slot_id,Se),_.append(Ge),k.status!=="published"&&((qe=(Ee=(j=k.draft_config)==null?void 0:j.arms)==null?void 0:Ee.length)!=null?qe:0)>0){let Te=Be("#10b981","Publish");Te.onclick=async()=>{Te.disabled=!0;let We=await q(n,`/v1/editor/slots/${encodeURIComponent(k.slot_id)}/publish`,{});Te.disabled=!1,X(We,"\u2713 Published \u2014 live for new visitors."),We.r==="ok"&&(p("published",{kind:"slot"}),_e())},_.append(Te)}k.status!=="published"&&_.append(Qe(`/v1/editor/slots/${encodeURIComponent(k.slot_id)}`,"\u{1F5D1} Draft discarded \u2014 nothing changed for your visitors.",()=>{Kt(k.slot_id),_e()})),K.append(_)}if(l)K.append(a("div",{fontSize:"11px",opacity:"0.6",padding:"6px 0 2px"},"Couldn\u2019t load your goals right now \u2014 they\u2019re safe."));else if(f.length>0){K.append(a("div",{fontSize:"11px",opacity:"0.6",padding:"8px 0 2px"},"Goals"));for(let k of f){let{row:_}=h((st=k.display_name)!=null?st:k.goal_id);if(_.append(u(k.status==="active")),k.status==="draft"){let U=Be("#10b981","Start tracking");U.onclick=async()=>{U.disabled=!0;let Se=await q(n,`/v1/editor/goals/${encodeURIComponent(k.goal_id)}/publish`,{});U.disabled=!1,X(Se,"\u2713 Tracking is live \u2014 it counts from your next visitor."),Se.r==="ok"&&(p("published",{kind:"goal"}),_e())},_.append(U,Qe(`/v1/editor/goals/${encodeURIComponent(k.goal_id)}`,"\u{1F5D1} Draft goal discarded \u2014 it never tracked anything.",()=>{Xt(k.goal_id),_e()}))}K.append(_)}}},vt=e=>{J!==e&&(P(),je(),J=e,Ze())},Ut=a("div",{display:"flex",alignItems:"center",gap:"6px",marginBottom:"10px"});Object.assign(V.style,{marginBottom:"0",flex:"1 1 auto",fontSize:"13px",whiteSpace:"nowrap"});let qt=!1,me=a("button",{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",width:"46px",height:"46px",borderRadius:"50%",border:"1px solid rgba(99,102,241,0.55)",background:"#111827",color:"#fff",cursor:"pointer",display:"none",alignItems:"center",justifyContent:"center",gap:"4px",font:"700 15px system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"}),Gt=a("span",{width:"7px",height:"7px",borderRadius:"50%",background:"#34d399",display:"inline-block"});Gt.className="sntedi-dot",me.append(Gt,a("span",{},"S")),me.title="Open the SentientUI editor";let Wt=a("button",{display:"inline-block",width:"auto",margin:"0",padding:"3px 8px",fontSize:"10.5px",borderRadius:"999px",background:"#374151",color:"#fff",border:"none",cursor:"pointer",whiteSpace:"nowrap"},"Minimize");Wt.onclick=()=>{H.style.display="none",me.style.display="flex",qt=M,M=!0,w.style.display="none",ze(document)},me.onclick=()=>{H.style.display="block",me.style.display="none",M=qt},Object.assign(F.style,{display:"inline-block",width:"auto",margin:"0",padding:"3px 8px",fontSize:"10.5px",borderRadius:"999px",background:"#374151",whiteSpace:"nowrap"}),Object.assign(Ce.style,{display:"inline-block",width:"auto",margin:"0",padding:"3px 8px",fontSize:"10.5px",borderRadius:"999px",whiteSpace:"nowrap"}),Ut.append(V,F,Wt,Ce);let Yt=a("div",{marginTop:"10px",borderTop:"1px solid rgba(255,255,255,0.1)",paddingTop:"8px"}),he=a("div",{});Object.assign(Z.style,{marginBottom:"4px"}),Yt.append(he,Z,te,ne);let re=a("button",{display:"none",width:"auto",margin:"0",padding:"5px 10px",flex:"0 0 auto",fontSize:"11px",borderRadius:"999px",background:"rgba(250,204,21,0.15)",border:"1px solid rgba(250,204,21,0.45)",color:"#fde68a",cursor:"pointer",whiteSpace:"nowrap"},"\u{1F4A1} Suggest"),kt=a("div",{display:"flex",alignItems:"center",gap:"6px"});Object.assign(G.style,{flex:"1 1 auto",marginBottom:"0"}),kt.append(G,re),Object.assign(kt.style,{marginBottom:"6px"});let ye=a("div",{}),B=a("div",{marginTop:"4px"});B.addEventListener("input",()=>{$e=!0}),B.addEventListener("change",()=>{$e=!0}),H.append(Ut,D,kt,oe,Le,ye,Nt,Dt,B,Yt),((sn=document.body)!=null?sn:document.documentElement).append(w,$,H,me);let be=null,Vt=()=>{be==null||be(),be=null},Jt=()=>{be=null},$e=!1,wt=null,P=()=>{Vt(),B.textContent="",$e=!1,wt=null,_t=!1},De=(e,o,s)=>{var b;P();let l={},d={},f={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 e){let x=a("label",{display:"block",fontSize:"12px",opacity:"0.85",marginTop:"8px"},m.label);if(B.append(x),m.type==="select"){let v=a("select",f);v.setAttribute("data-field",m.key);let S=document.createElement("option");S.value="",S.textContent="\u2014 no change \u2014",v.append(S);for(let R of(b=m.options)!=null?b:[]){let j=document.createElement("option");j.value=R,j.textContent=R,v.append(j)}l[m.key]=()=>v.value,B.append(v)}else if(m.type==="color"){let v=a("input",Y(A({},f),{padding:"2px",height:"34px"}));v.type="color",v.setAttribute("data-field",m.key);let S=!1;v.addEventListener("input",()=>{S=!0}),l[m.key]=()=>S?v.value:"",B.append(v)}else{let v=a("input",f);v.setAttribute("data-field",m.key),m.value!==void 0&&(v.value=m.value),l[m.key]=()=>v.value,B.append(v)}let E=a("div",{fontSize:"11px",color:"#fca5a5",marginTop:"3px",display:"none"});E.setAttribute("data-feedback",m.key),d[m.key]=E,B.append(E)}let u=(m,x)=>{let E=d[m];E&&(E.textContent=x!=null?x:"",E.style.display=x?"block":"none")},h=a("button",T("#6366f1"),o),g=a("button",Y(A({},T("transparent")),{opacity:"0.6"}),"Cancel");h.onclick=()=>s(Object.fromEntries(Object.entries(l).map(([m,x])=>[m,x()])),u),g.onclick=P,B.append(h,g)},y=(e,o=!0)=>{Z.textContent=e,Z.style.color=o?"#a7f3d0":"#fca5a5"},Et=(e,o)=>{var l,d;if(p("error_shown",{code:(d=e.code)!=null?d:`http_${(l=e.status)!=null?l:"network"}`}),e.code==="plan_limit_reached"){let f=e.feature==="live_goals"?"live goal":"of these",u=e.plan?`${e.plan} plan`:"plan";return e.feature==="live_goals"?`Your ${u} includes 1 live goal. Pause another goal in your dashboard, or upgrade to track more.`:`Your ${u} has reached its limit for ${f}. Manage them in your dashboard, or upgrade for more.`}if(e.code==="role_required")return"Your account can view but not edit this project \u2014 ask an admin for editor access.";if(e.code==="demo_read_only"&&e.message)return e.message;let s=e.status?` (HTTP ${e.status})`:"";return`\u26A0 Couldn\u2019t ${o} \u2014 try again.${s}`},X=(e,o)=>{e.r==="ok"?y(o,!0):e.r==="expired"?y("Editor session expired \u2014 reopen it from your dashboard to save this. Your earlier changes are safe.",!1):y(Et(e,"save"),!1)},xe=null,et=e=>e.length>30?`${e.slice(0,27)}\u2026`:e,Kt=e=>{xe===e&&(xe=null,te.style.display="none",Ne.style.display="none",he.textContent="")},Xt=e=>{Ie===e&&(Ie=null,ne.style.display="none",he.textContent="")},tt=(e,o,s)=>{xe=e,te.textContent=o?`Publish \u201C${et(o)}\u201D \u2014 go live`:"Publish now \u2014 go live",te.style.display="block",Ne.style.display="block";let l=[];if(s){let d=Be("#374151","Preview");d.onclick=()=>Ft(e,s),l.push(d)}l.push(Qe(`/v1/editor/slots/${encodeURIComponent(e)}`,"\u{1F5D1} Draft discarded \u2014 nothing changed for your visitors.",()=>Kt(e))),jt(o?`Draft saved for \u201C${et(o)}\u201D \u2014 nothing is live for visitors yet.`:"Draft saved \u2014 nothing is live for visitors yet.",l)};te.onclick=async()=>{if(!xe)return;te.disabled=!0,y("Publishing\u2026");let e=await q(n,`/v1/editor/slots/${encodeURIComponent(xe)}/publish`,{});te.disabled=!1,e.r==="ok"?(p("published",{kind:"slot"}),y("\u2713 Published \u2014 live for new visitors.",!0),te.style.display="none",xe=null,he.textContent=""):e.r==="expired"?y("Editor session expired \u2014 reopen it from your dashboard to publish. Your saved draft is safe.",!1):y(Et(e,"publish"),!1)};let O=null,Ae=!1,Re=null,Me=null,ee=null,ve=null,Fe=null,nt=null,ke=!1,Zt=(e,o)=>Ae?e?"":`Nothing to swap with ${o} \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.",Qt=()=>{le.disabled=!Ae||!ee,de.disabled=!Ae||!ve,le.title=le.disabled?Zt(ee,"above"):"",de.title=de.disabled?Zt(ve,"below"):""},St=e=>{Ke.style.display=e?"block":"none",Xe.style.display=e?"block":"none",Qt()},je=()=>{if(ke&&t&&Fe&&Fe.insertBefore(t,nt),ke=!1,Fe=null,nt=null,t){let e=mt(t,document);Re=e.prevEl,Me=e.nextEl,ee=e.prevLocator,ve=e.nextLocator}L(),St(!1)},en=e=>{if(M)return;let o=e.target;if(!o||H.contains(o)||o===w)return;ze(document);let s=o.getBoundingClientRect();Object.assign(w.style,{display:"block",left:`${s.left}px`,top:`${s.top}px`,width:`${s.width}px`,height:`${s.height}px`})},we=e=>{var s;let o=((s=e.textContent)!=null?s:"").trim().replace(/\s+/g," ");return o?o.length>40?`${o.slice(0,37)}\u2026`:o:e.tagName.toLowerCase()},Ln=e=>!!e.id||["section","header","footer","nav","main","form","article","aside"].includes(e.tagName.toLowerCase())||!!e.querySelector(":scope > h1, :scope > h2, :scope > h3"),Bn=e=>{var l;let o=e.querySelector("h1, h2, h3"),s=(l=o==null?void 0:o.textContent)==null?void 0:l.replace(/\s+/g," ").trim();return s?s.length>28?`${s.slice(0,25)}\u2026`:s:e.id?`#${e.id.length>24?`${e.id.slice(0,21)}\u2026`:e.id}`:`<${e.tagName.toLowerCase()}>`},_n=e=>{oe.textContent="";let o=[];for(let u=e.parentElement;u&&u!==document.body&&o.length<3;u=u.parentElement)Ln(u)&&o.push(u);let s=we(e),l=()=>a("span",{opacity:"0.5",margin:"0 4px"},"\u2039"),d=!0;for(let u of o){let h=Bn(u);if(h===s||s.startsWith(h))continue;let g=a("button",{background:"transparent",border:"none",color:"#a5b4fc",cursor:"pointer",font:"inherit",padding:"0",textDecoration:"underline"},h);g.onclick=()=>ot(u),d||oe.append(l()),oe.append(g),d=!1}d||oe.append(l());let f=a("button",{background:"transparent",border:"none",color:"#a5b4fc",cursor:"pointer",font:"inherit",padding:"0",textDecoration:"underline",opacity:"0.7"},"Page");f.onclick=()=>tn(),oe.append(f),oe.style.display="block"},$n=e=>{Le.textContent="";let o=null,s=0;for(let d=e.parentElement;d&&d!==document.body&&s<6;d=d.parentElement,s++)if(Ye(Pe(d,document),d,document)){o=d;break}let l=a("div",{marginBottom:"8px",padding:"8px 10px",borderRadius:"8px",fontSize:"12px",background:"rgba(252,165,165,0.12)",border:"1px solid rgba(252,165,165,0.4)"});if(o){let d=o;l.append(a("div",{marginBottom:"6px"},"This exact element can\u2019t be tracked safely \u2014 it looks identical to others on the page. You can pick something more specific inside it, or work with the whole block, which we can target reliably."));let f=a("button",Y(A({},T("#6366f1")),{marginTop:"0"}),`Select \u201C${we(d)}\u201D instead`);f.onclick=()=>ot(d);let u=a("button",Y(A({},T("transparent")),{opacity:"0.6"}),"Pick something else");u.onclick=()=>{Le.textContent=""},l.append(f,u)}else l.append(a("div",{},"This part of the page can\u2019t be targeted reliably \u2014 try a heading, a button, or a whole section instead."));Le.append(l)},ot=e=>{je(),P(),Le.textContent="",t=e,O=Pe(e,document);let o=Ye(O,e,document);Ae=o,L(),G.style.display="block",G.textContent=`Selected: ${we(e)}`,_n(e),p("element_selected",{unique:o}),y(o?"\u2713 Matches exactly 1 element":"",o),o||$n(e),D.style.display="none",re.style.display="inline-block",ye.textContent="";for(let f of bt)f.style.display="block";I.style.display="none",N.style.display="none";let s=e.childElementCount===0;I.disabled=!o||!s,I.title=o?s?"":"This element contains other elements, so testing text here would replace them. Pick the text itself (e.g. the heading), not its container.":"",N.disabled=!o,se.disabled=!o,W.disabled=!o;let l=e.closest("form");C.style.display=l?"block":"none",C.disabled=!l;let d=mt(e,document);Re=d.prevEl,Me=d.nextEl,ee=d.prevLocator,ve=d.nextLocator,Qt(),Ze()},tn=()=>{je(),P(),t=null,O=null,Ae=!1,Re=null,Me=null,ee=null,ve=null,L(),Le.textContent="",ye.textContent="",oe.textContent="",oe.style.display="none",G.textContent="",G.style.display="none",re.style.display="none";for(let e of bt)e.style.display="none";D.style.display="block",y(""),Ze()},He=!1,Tt=-1,nn=e=>{var l,d;let o=e.target,s=!!((l=o==null?void 0:o.closest)!=null&&l.call(o,'input, textarea, select, [contenteditable="true"]'));if(e.key==="Escape"){if(B.childElementCount>0){P(),He=!1;return}if(t){tn(),He=!1;return}if(!He){He=!0,y("Press Esc again to close the editor.");return}He=!1,(d=Ce.onclick)==null||d.call(Ce,new MouseEvent("click"));return}if(He=!1,!(s||M)){if(e.key==="ArrowUp"||e.key==="ArrowDown"){if(!t||(e.key==="ArrowUp"?le:de).disabled)return;e.preventDefault(),Bt(e.key==="ArrowUp"?"up":"down");return}if(e.key==="Tab"){let f=[];for(let h of vn){let g=ue(h.locator,document);g&&!f.includes(g)&&f.push(g)}if(f.length===0)return;if($e){y("\u26A0 You have unsaved changes \u2014 Save or Cancel before picking another element.",!1),e.preventDefault();return}e.preventDefault(),Tt=(Tt+(e.shiftKey?-1:1)+f.length)%f.length;let u=f[Tt];ot(u);try{u.scrollIntoView({block:"center",behavior:"smooth"})}catch(h){}}}},on=e=>{if(M)return;let o=e.target;if(!(!o||H.contains(o))){if(e.preventDefault(),e.stopPropagation(),$e&&o!==t&&wt!==o){wt=o,y("\u26A0 You have unsaved changes \u2014 Save or Cancel first, or click that element again to discard them.",!1);return}ot(o)}};I.onclick=()=>{var f,u,h;if(!t||!O)return;p("form_opened",{kind:"text"});let e=O,o=(u=(f=t.textContent)==null?void 0:f.trim())!=null?u:"";De([{key:"current",label:"Current wording",value:o},{key:"alt",label:"Alternative wording to test",value:""}],"Save draft",async g=>{let b=g.alt.trim();if(!b){y("\u26A0 Enter alternative wording to test.",!1);return}if(b===g.current.trim()){y("\u26A0 Enter different wording \u2014 the alternative matches the current text.",!1);return}let m=Je("text",e,t);y("Saving\u2026");let x=await q(n,`/v1/editor/slots/${encodeURIComponent(m)}`,{kind:"arms",target:e,draftConfig:{arms:[{id:"a",displayName:"Original",ops:{text:g.current}},{id:"b",displayName:"Alternative",ops:{text:g.alt}}]}});x.r==="ok"&&(p("draft_saved",{kind:"slot"}),Jt(),P(),tt(m,we(t),"b")),X(x,"\u2713 Saved as a draft. Click \u201CPublish\u201D below to go live.")});let s=t,l=(h=s.textContent)!=null?h:"";be=()=>{s.textContent=l};let d=B.querySelector('input[data-field="alt"]');d==null||d.addEventListener("input",()=>{s.textContent=d.value.trim()===""?l:d.value})};let Ue=null,An=e=>{let o=u=>{var h;return((h=u.textContent)!=null?h:"").replace(/\s+/g," ").trim()},s=Array.from(e.querySelectorAll("h1,h2,h3,h4")).map(o).filter(Boolean);if(s.length===0){let u=e.closest("h1,h2,h3,h4");u&&s.push(o(u))}let l=Array.from(e.querySelectorAll("p")).map(o).filter(u=>u.length>0&&u.length<=300),d=[];for(let u of Array.from(e.querySelectorAll("a[href], button"))){let h=o(u);if(!h||h.length>60)continue;let g="",b=u.getAttribute("href");if(b)try{let m=new URL(b,window.location.href);m.protocol==="https:"&&(g=m.href)}catch(m){}d.push({label:h,href:g})}let f=Array.from(e.querySelectorAll("blockquote, q")).map(o).filter(Boolean);return{headings:s,paragraphs:l,links:d,quotes:f}},Rn=(e,o)=>{var l,d,f,u,h,g,b,m,x,E,v,S,R,j,Ee,qe;let s=st=>{var k;return o.paragraphs.length>=3&&(k=o.paragraphs[o.paragraphs.length-3+st])!=null?k:""};switch(e){case"headline":return(l=o.headings[0])!=null?l:"";case"supporting":return(d=o.paragraphs[0])!=null?d:"";case"cta_label":return(u=(f=o.links[0])==null?void 0:f.label)!=null?u:"";case"cta_href":return(g=(h=o.links[0])==null?void 0:h.href)!=null?g:"";case"secondary_label":return(m=(b=o.links[1])==null?void 0:b.label)!=null?m:"";case"secondary_href":return(E=(x=o.links[1])==null?void 0:x.href)!=null?E:"";case"quote":case"q1":return(v=o.quotes[0])!=null?v:"";case"q2":return(S=o.quotes[1])!=null?S:"";case"q3":return(R=o.quotes[2])!=null?R:"";case"f1_title":return(j=o.headings[1])!=null?j:"";case"f2_title":return(Ee=o.headings[2])!=null?Ee:"";case"f3_title":return(qe=o.headings[3])!=null?qe:"";case"f1_body":return s(0);case"f2_body":return s(1);case"f3_body":return s(2);default:return""}},Mn=(e,o,s)=>{p("form_opened",{kind:"arrangement"});let l=An(s);De(e.fields.map(d=>({key:d.id,label:d.kind==="href"?`${d.label} (https link \u2014 required)`:d.label,value:Rn(d.id,l)||d.default||""})),"Save draft",async(d,f)=>{var m,x,E,v;let u=!1;for(let S of e.fields){if(S.kind!=="href")continue;let R=!1;try{R=new URL((m=d[S.id])!=null?m:"").protocol==="https:"}catch(j){}f(S.id,R?null:"Links need to start with https://"),R||(u=!0)}if(u){y("\u26A0 Fix the highlighted link(s).",!1);return}y("Saving\u2026");let h=await po(n,`/v1/editor/arrangements/${encodeURIComponent(e.id)}/instantiate`,{fields:d});if(h.r!=="ok"||!((x=h.data)!=null&&x.blocks)){h.r==="expired"?X(h.outcome,""):y(`\u26A0 ${(v=(E=h.data)==null?void 0:E.reason)!=null?v:"Couldn\u2019t build the arrangement \u2014 check the fields."}`,!1);return}let g=Je("arrange",o,s),b=await q(n,`/v1/editor/slots/${encodeURIComponent(g)}`,{kind:"arms",target:o,draftConfig:{arms:[{id:"original",displayName:"Your page today"},{id:e.id,displayName:e.name,blocks:h.data.blocks}],baseline:"original"}});b.r==="ok"&&(p("draft_saved",{kind:"arrangement"}),P(),tt(g,e.name,e.id)),X(b,"\u2713 Saved as a draft \u2014 it will test against this section as it is today. Click \u201CPublish\u201D below to go live.")})};se.onclick=async()=>{var l,d;if(!t||!O)return;let e=O,o=t;if(P(),y("Loading arrangements\u2026"),!Ue){let f=await pt(n,"/v1/editor/arrangements");Ue=(l=f==null?void 0:f.arrangements)!=null?l:null}if(!Ue||Ue.length===0){y("\u26A0 Couldn\u2019t load the arrangements \u2014 try again.",!1);return}y("Pick an arrangement to test against this section.");for(let f of Ue){let u=a("button",Y(A({},T("#374151")),{textAlign:"left"}));u.append(a("div",{fontWeight:"600"},f.name),a("div",{fontSize:"11px",opacity:"0.7"},f.description)),u.onclick=()=>Mn(f,e,o),B.append(u)}let s=a("button",Y(A({},T("transparent")),{opacity:"0.6"}),"Cancel");s.onclick=P,B.append(s),(d=B.scrollIntoView)==null||d.call(B,{block:"nearest"})};let Ie=null,Hn=(e,o)=>{Ie=e,ne.textContent=o?`Start tracking \u201C${et(o)}\u201D now`:"Start tracking now",ne.style.display="block",jt(o?`Goal \u201C${et(o)}\u201D saved \u2014 it isn\u2019t counting anything until you start it.`:"Goal saved \u2014 it isn\u2019t counting anything until you start it.",[Qe(`/v1/editor/goals/${encodeURIComponent(e)}`,"\u{1F5D1} Draft goal discarded \u2014 it never tracked anything.",()=>Xt(e))])};ne.onclick=async()=>{if(!Ie)return;ne.disabled=!0,y("Activating\u2026");let e=await q(n,`/v1/editor/goals/${encodeURIComponent(Ie)}/publish`,{});ne.disabled=!1,e.r==="ok"?(p("published",{kind:"goal"}),y("\u2713 Tracking is live \u2014 it counts from your next visitor.",!0),ne.style.display="none",Ie=null,he.textContent=""):e.r==="expired"?y("Editor session expired \u2014 reopen it from your dashboard to activate. Your saved goal is safe.",!1):y(Et(e,"activate"),!1)};let Ct=(e,o)=>`${ft(e)||"goal"}-${bn(o)}`.slice(0,128),In=e=>{var l,d,f;let o=((l=e.textContent)!=null?l:"").replace(/\s+/g," ").trim();return o&&o.length<=60?o:((f=(d=e.getAttribute("aria-label"))!=null?d:e.getAttribute("id"))!=null?f:"").trim()||"element-clicked"},rt=async(e,o,s)=>{y("Saving\u2026");let l=await q(n,`/v1/editor/goals/${encodeURIComponent(e)}`,o);l.r==="ok"&&(p("draft_saved",{kind:"goal"}),Hn(e,s)),X(l,"\u2713 Goal saved. Click \u201CStart tracking\u201D below to go live.")};W.onclick=()=>{if(!t||!O)return;let e=Ct(In(t),JSON.stringify(O));rt(e,{event:"click",locator:O},we(t))},C.onclick=()=>{var l,d;let e=t==null?void 0:t.closest("form");if(!e)return;let o=Pe(e,document),s=(d=(l=e.getAttribute("id"))!=null?l:e.getAttribute("name"))!=null?d:"form-submitted";rt(Ct(s,JSON.stringify(o)),{event:"form_submit",locator:o},s)},Q.onclick=()=>{let e=window.location.pathname||"/",o=ft(e)?`reached-${ft(e)}`:"page-visited";rt(Ct(o,e),{event:"url_reached",urlPattern:e},e)};let Lt=[{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}];ae.onclick=()=>{De([{key:"depth",label:"Counts once a visitor reads",type:"select",options:Lt.map(e=>e.label)}],"Track it",e=>{var l;let o=(l=Lt.find(d=>d.label===e.depth))!=null?l:Lt[2],s=Math.round(o.value*100);rt(`read-${s}pct`,{event:"scroll_depth",threshold:o.value},`read ${s}%`),P()})};let it=null,Pn=e=>{it=e,ge.style.display="block"};ge.onclick=async()=>{if(!it)return;ge.disabled=!0,y("Turning on\u2026");let e=await q(n,`/v1/editor/funnels/${encodeURIComponent(it)}/publish`,{});ge.disabled=!1,e.r==="ok"?(p("published",{kind:"funnel"}),y("\u2713 Funnel is on \u2014 the drop-off view fills in as visitors move through it.",!0),ge.style.display="none",it=null):e.r==="expired"?y("Editor session expired \u2014 reopen it from your dashboard to turn the funnel on. Your draft is safe.",!1):y("\u26A0 Couldn\u2019t turn the funnel on \u2014 try again.",!1)},Pt.onclick=async()=>{var m;y("Loading your goals\u2026");let e=await pt(n,"/v1/editor/goals"),o=(m=e==null?void 0:e.goals)!=null?m:[];if(o.length<2){y("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}y("Pick the steps in order \u2014 first click = first step."),P();let s=[],l=a("label",{display:"block",fontSize:"12px",opacity:"0.85",marginTop:"8px"},"Funnel name"),d=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"});B.append(l,d);let f=a("div",{fontSize:"11px",opacity:"0.7",marginTop:"6px"},"Steps (click in journey order):");B.append(f);let u=new Map,h=()=>{var x,E;for(let[v,S]of u){let R=s.indexOf(v),j=(E=(x=o.find(Ee=>Ee.goal_id===v))==null?void 0:x.display_name)!=null?E:v;S.textContent=R===-1?j:`${R+1}. ${j}`,S.style.background=R===-1?"#374151":"#6366f1"}};for(let x of o){let E=a("button",Y(A({},T("#374151")),{textAlign:"left"}));u.set(x.goal_id,E),E.onclick=()=>{s=mn(s,x.goal_id),h()},B.append(E)}h();let g=a("button",T("#6366f1"),"Save funnel"),b=a("button",Y(A({},T("transparent")),{opacity:"0.6"}),"Cancel");b.onclick=P,g.onclick=async()=>{let x=hn(d.value,s);if(!x.ok){y(`\u26A0 ${x.error}`,!1);return}y("Saving\u2026");let E=await q(n,`/v1/editor/funnels/${encodeURIComponent(x.funnelId)}`,x.body);E.r==="ok"&&(p("draft_saved",{kind:"funnel"}),P(),Pn(x.funnelId)),X(E,"\u2713 Funnel saved as a draft. Click \u201CTurn the funnel on\u201D to start measuring.")},B.append(g,b)},Ne.onclick=async()=>{var h,g;let e=xe;if(!e)return;y("Loading funnels\u2026");let o=await pt(n,"/v1/editor/funnels"),s=(h=o==null?void 0:o.funnels)!=null?h:[];if(s.length===0){y("No funnels yet \u2014 click \u201CSet up a funnel\u201D first.",!1);return}let l=await pt(n,"/v1/editor/goals"),d=new Map(((g=l==null?void 0:l.goals)!=null?g:[]).map(b=>[b.goal_id,b.display_name]));De([{key:"funnel",label:"Funnel",type:"select",options:s.map(b=>ct(b))},{key:"step",label:"Which step does this element serve?",type:"select",options:ut(s[0],d).map(b=>b.label)}],"Attach",async b=>{var v;let m=(v=s.find(S=>ct(S)===b.funnel))!=null?v:s[0],x=ut(m,d).findIndex(S=>S.label===b.step);if(x<0){y("\u26A0 Pick which step this element serves.",!1);return}y("Attaching\u2026");let E=await q(n,`/v1/editor/funnels/${encodeURIComponent(m.funnel_id)}/assign`,{slotId:e,stepIndex:x});E.r==="ok"&&P(),X(E,`\u2713 Attached \u2014 this test now works toward \u201C${m.display_name}\u201D.`)});let f=B.querySelector('select[data-field="funnel"]'),u=B.querySelector('select[data-field="step"]');f&&u&&f.addEventListener("change",()=>{var m;let b=(m=s.find(x=>ct(x)===f.value))!=null?m:s[0];u.length=1;for(let x of ut(b,d)){let E=document.createElement("option");E.value=x.label,E.textContent=x.label,u.append(E)}})},N.onclick=()=>{if(!t||!O)return;p("form_opened",{kind:"style"});let e=O;De([{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:Rt.length?`Font (this site has: ${Rt.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(u,h)=>{var v;let{style:g,errors:b}=Ht(u),m=!1;for(let S of Mt)h(S,(v=b[S])!=null?v:null),b[S]&&(m=!0);if(m){y("\u26A0 Fix the highlighted field(s).",!1);return}if(Object.keys(g).length===0){y("\u26A0 Enter at least one style change.",!1);return}let x=Je("style",e,t);y("Saving\u2026");let E=await q(n,`/v1/editor/slots/${encodeURIComponent(x)}`,{kind:"arms",target:e,draftConfig:{arms:[{id:"a",displayName:"Current look",ops:{}},{id:"b",displayName:"New look",ops:{style:g}}]}});E.r==="ok"&&(p("draft_saved",{kind:"slot"}),Jt(),P(),tt(x,we(t),"b")),X(E,"\u2713 Saved as a draft. Click \u201CPublish\u201D below to go live.")});let o=t,s=o.style.cssText;be=()=>{o.style.cssText=s};let l={},d=()=>{let{style:u}=Ht(l);o.style.cssText=s;for(let[h,g]of Object.entries(u)){let b=dt[h];b&&Ve(g)&&o.style.setProperty(b,g.trim(),"important")}};for(let u of Mt){let h=B.querySelector(`[data-field="${u}"]`);if(!h)continue;let g=()=>{l[u]=h.value,d()};h.addEventListener("input",g),h.addEventListener("change",g)}let f=[ie==null?void 0:ie.primaryBg,ie==null?void 0:ie.primaryText,"#ffffff"].filter(u=>!!u).map(gt).filter((u,h,g)=>yt(u)&&g.indexOf(u)===h);for(let u of["color","background"]){let h=B.querySelector(`input[data-field="${u}"]`);if(!h)continue;let g=a("div",{display:"flex",gap:"6px",marginTop:"4px"});for(let b of f){let m=a("button",{width:"22px",height:"22px",borderRadius:"6px",cursor:"pointer",border:"1px solid rgba(255,255,255,0.35)",background:b,padding:"0"});m.title=b,m.onclick=()=>{h.value=gt(b),h.dispatchEvent(new Event("input"))},g.append(m)}h.after(g)}};let rn=e=>{var l;let o=e==="text"?I:N;if(o.disabled)return y(o.title||"This element can\u2019t be targeted reliably \u2014 try a heading, a button, or a whole section.",!1),!1;vt(e);let s=e==="text"?'[data-field="alt"]':'[data-field="color"]';return B.querySelector(s)||(l=o.onclick)==null||l.call(o,new MouseEvent("click")),!0};re.onclick=async()=>{var u,h;if(!t)return;let e=t;re.disabled=!0;let o=re.textContent;re.textContent="Thinking\u2026",ye.textContent="",p("form_opened",{kind:"suggest"});let s={},l=null;try{let g=await fetch(`${n.apiBase}/v1/editor/suggest`,{method:"POST",headers:{authorization:`Bearer ${n.token}`,"content-type":"application/json"},body:JSON.stringify(A({element:{tag:e.tagName.toLowerCase(),text:((u=e.textContent)!=null?u:"").replace(/\s+/g," ").trim().slice(0,400)},pageUrl:window.location.pathname},ie?{palette:ie}:{}))});g.ok?s=await g.json():l=g.status===401?"expired":"error"}catch(g){l="error"}if(re.disabled=!1,re.textContent=o,t!==e)return;if(l){y(l==="expired"?"Editor session expired \u2014 reopen it from your dashboard to keep editing.":"\u26A0 Couldn\u2019t get suggestions \u2014 check your connection and try again.",!1);return}if(s.locked){y("AI suggestions aren\u2019t included in this plan.",!1);return}if(s.exhausted){y("You\u2019ve used today\u2019s AI allowance \u2014 more tomorrow, or upgrade for a bigger daily budget.",!1);return}let d=(h=s.suggestions)!=null?h:[];if(d.length===0){y("No safe suggestions for this element \u2014 try a headline, a button, or a section.",!1);return}let f=(g,b)=>{let m=B.querySelector(`[data-field="${g}"]`);m&&(m.value=b,m.dispatchEvent(new Event("input")))};for(let g of d){let b=a("div",{margin:"0 0 8px",padding:"9px 11px",borderRadius:"10px",fontSize:"12px",background:"rgba(250,204,21,0.08)",border:"1px solid rgba(250,204,21,0.3)"});b.append(a("div",{fontWeight:"600",marginBottom:"2px"},g.title),a("div",{opacity:"0.75",marginBottom:"6px"},g.reason));let m=a("button",Y(A({},T("#6366f1")),{display:"inline-block",width:"auto",margin:"0",padding:"4px 10px",fontSize:"11px"}),"Try it");m.onclick=()=>{var x,E;if(t!==e){ye.textContent="";return}if(ye.textContent="",g.kind==="text"){if(!rn("text"))return;f("alt",g.variant)}else if(g.kind==="style"){if(!rn("style"))return;for(let[v,S]of Object.entries(g.style))if(v==="color"||v==="background"){let R=gt(S);yt(R)&&f(v,R)}else v==="textAlign"?f(v,S==="start"?"left":S==="end"?"right":S):f(v,S)}else{let v=g.goalType==="form_submit"&&!C.disabled;if(!v&&W.disabled){y("This element can\u2019t be tracked reliably \u2014 select a specific button or link instead.",!1);return}vt("goals"),v?(x=C.onclick)==null||x.call(C,new MouseEvent("click")):(E=W.onclick)==null||E.call(W,new MouseEvent("click"))}},b.append(m),ye.append(b)}};let Bt=e=>{if(!t)return;let o=t.parentElement;if(!o)return;ke||(Fe=o,nt=t.nextSibling,ke=!0),e==="up"&&Re?o.insertBefore(t,Re):e==="down"&&Me&&o.insertBefore(t,Me.nextSibling);let s=mt(t,document);Re=s.prevEl,Me=s.nextEl,ee=s.prevLocator,ve=s.nextLocator;try{t.scrollIntoView({block:"nearest",behavior:"smooth"})}catch(l){}L(),St(!0),y("Previewing the new position \u2014 keep moving, save, or undo.")};le.onclick=()=>Bt("up"),de.onclick=()=>Bt("down"),Xe.onclick=()=>{je(),y("Move undone \u2014 back to the original position.")},Ke.onclick=async()=>{if(!t||!O||!ke||!Ae)return;let e=ee?"moveAfter":"moveBefore",o=ee!=null?ee:ve;if(!o){y("\u26A0 Couldn\u2019t anchor the new position \u2014 nudge it next to a section with an id.",!1);return}let s=Je("move",O,t);y("Saving\u2026");let l=await q(n,`/v1/editor/slots/${encodeURIComponent(s)}`,{kind:"arms",target:O,draftConfig:{arms:[{id:"a",ops:{}},{id:"b",ops:{[e]:o}}]}});l.r==="ok"&&(p("draft_saved",{kind:"move"}),ke=!1,Fe=null,nt=null,St(!1),tt(s,we(t),"b")),X(l,"\u2713 Saved as a draft. Click \u201CPublish\u201D below to go live.")};let On=()=>{var e,o;p("editor_closed"),c(),window.removeEventListener("pagehide",c),i&&clearTimeout(i),je(),Vt(),document.removeEventListener("mousemove",en,!0),document.removeEventListener("click",on,!0),document.removeEventListener("keydown",nn,!0),window.removeEventListener("scroll",z,!0),window.removeEventListener("resize",z),ze(document),(e=document.getElementById($t))==null||e.remove(),w.remove(),$.remove(),H.remove(),me.remove(),window.__sentientEditor=null,(o=document.querySelector("meta[data-sentient-editor]"))==null||o.remove(),lt()},_t=!1;Ce.onclick=()=>{if(($e||ke)&&!_t){_t=!0,y("\u26A0 Unsaved changes \u2014 click \u201CClose editor\u201D again to discard them.",!1);return}On()},document.addEventListener("mousemove",en,!0),document.addEventListener("click",on,!0),document.addEventListener("keydown",nn,!0),window.addEventListener("scroll",z,!0),window.addEventListener("resize",z),Ze(),p("editor_opened")}function T(n){return{display:"block",width:"100%",marginTop:"8px",padding:"8px 10px",borderRadius:"8px",border:"none",background:n,color:"#fff",font:"13px system-ui, sans-serif",cursor:"pointer",textAlign:"left"}}var Tn="sentient-preview-bar";async function xo(n,t){var H,fe,V,D,M,F,G,Z,I,N,se,W;try{fetch(`${n.apiBase}/v1/editor/telemetry`,{method:"POST",keepalive:!0,headers:{authorization:`Bearer ${n.token}`,"content-type":"application/json"},body:JSON.stringify({events:[{kind:"previewed"}]})}).catch(()=>{})}catch(C){}let r=null;try{let C=await fetch(`${n.apiBase}/v1/editor/slots`,{headers:{authorization:`Bearer ${n.token}`}});C.ok&&(r=(fe=((H=(await C.json()).slots)!=null?H:[]).find(ae=>ae.slot_id===t&&ae.kind==="arms"))!=null?fe:null)}catch(C){}let i=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)"});i.id=Tn;let c=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");c.onclick=()=>{lt();let C=new URL(location.href);for(let Q of["sentient_editor","sentient_preview","sentient_arm"])C.searchParams.delete(Q);location.assign(C.toString())};let p=a("button",{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.3)",background:"#6366f1",color:"#fff",font:"12px system-ui, sans-serif",cursor:"pointer"},"Back to editor");p.onclick=()=>{let C=new URL(location.href);for(let Q of["sentient_preview","sentient_arm"])C.searchParams.delete(Q);location.assign(C.toString())};let w=(F=(M=(V=r==null?void 0:r.draft_config)==null?void 0:V.arms)!=null?M:(D=r==null?void 0:r.published_config)==null?void 0:D.arms)!=null?F:[];if(!r||w.length===0){i.append(a("span",{},"Couldn\u2019t load this preview \u2014 reopen it from your dashboard."),p,c),((G=document.body)!=null?G:document.documentElement).append(i);return}let $=new URLSearchParams(location.search).get("sentient_arm"),L=(I=(Z=w.find(C=>C.id===$))!=null?Z:w[1])!=null?I:w[0];i.append(a("span",{fontWeight:"700"},`Previewing: ${(N=r.display_name)!=null?N:r.slot_id}`));let z=r.target&&typeof r.target=="object"?ue(r.target,document):null;if(!z)i.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{gn(z,L.ops,`preview-${r.slot_id}`,document);try{z.scrollIntoView({block:"center"})}catch(C){}for(let C of w){let Q=a("button",{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.3)",cursor:"pointer",background:C.id===L.id?"#6366f1":"transparent",color:"#fff",font:"12px system-ui, sans-serif"},(se=C.displayName)!=null?se:C.id);Q.onclick=()=>{let ae=new URL(location.href);ae.searchParams.set("sentient_arm",C.id),location.assign(ae.toString())},i.append(Q)}}i.append(p,c),((W=document.body)!=null?W:document.documentElement).append(i)}async function vo(){if(typeof document=="undefined")return;let n=lo();if(!n)return;let t=await co(n);if(!t.ok){t.unauthorized?(lt(),yn(so)):yn(ao);return}let r=new URLSearchParams(location.search).get("sentient_preview");if(r){document.getElementById(Tn)||await xo(n,r);return}if(document.getElementById(Oe))return;Sn(n);let i=un(document);ie=i,i&&q(n,"/v1/editor/palette",i);let c=await fo(n);kn(c),wn(c,document)}vo();return Gn(ko);})();
24
+ `,((t=document.head)!=null?t:document.documentElement).appendChild(n)}function bn(n){var i,u;vn(),(i=document.getElementById(ht))==null||i.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=ht;let r=a("span",{width:"9px",height:"9px",marginTop:"4px",borderRadius:"50%",background:"#f59e0b",flex:"0 0 auto"});t.append(r,a("div",{},n)),((u=document.body)!=null?u:document.documentElement).appendChild(t),t.addEventListener("click",()=>t.remove()),setTimeout(()=>t.remove(),1e4)}function po(){let n=window.__sentientEditor;return n&&typeof n.token=="string"&&typeof n.apiBase=="string"?n:null}async function fo(n){try{let t=await fetch(`${n.apiBase}/v1/editor/verify`,{headers:{authorization:`Bearer ${n.token}`}});if(t.status===401)return{ok:!1,unauthorized:!0};if(!t.ok)return{ok:!1,unauthorized:!1};let r=(await t.json()).projectId;return r?{ok:!0,projectId:r}:{ok:!1,unauthorized:!1}}catch(t){return{ok:!1,unauthorized:!1}}}function It(n,t){return A(A(A(A({r:n===401?"expired":"error",status:n},typeof(t==null?void 0:t.error)=="string"?{code:t.error}:{}),typeof(t==null?void 0:t.message)=="string"?{message:t.message}:{}),typeof(t==null?void 0:t.feature)=="string"?{feature:t.feature}:{}),typeof(t==null?void 0:t.plan)=="string"?{plan:t.plan}:{})}async function G(n,t,r){try{let i=await fetch(`${n.apiBase}${t}`,{method:"POST",headers:{authorization:`Bearer ${n.token}`,"content-type":"application/json"},body:JSON.stringify(r)});if(i.ok)return{r:"ok"};let u=await i.json().catch(()=>null);return It(i.status,u)}catch(i){return{r:"error"}}}async function go(n,t){try{let r=await fetch(`${n.apiBase}${t}`,{method:"DELETE",headers:{authorization:`Bearer ${n.token}`}});if(r.ok)return{r:"ok"};let i=await r.json().catch(()=>null);return It(r.status,i)}catch(r){return{r:"error"}}}async function mo(n,t,r){try{let i=await fetch(`${n.apiBase}${t}`,{method:"POST",headers:{authorization:`Bearer ${n.token}`,"content-type":"application/json"},body:JSON.stringify(r)}),u=await i.json().catch(()=>null);return i.ok?{r:"ok",data:u,outcome:{r:"ok"}}:{r:i.status===401?"expired":"error",data:u,outcome:It(i.status,u)}}catch(i){return{r:"error",data:null,outcome:{r:"error"}}}}var Mt=[];function yt(n){return/^#[0-9a-fA-F]{6}$/.test(n)}function gt(n){let t=n.trim();if(yt(t))return t;let r=/^#([0-9a-fA-F]{3})$/.exec(t);if(r)return`#${r[1].split("").map(p=>p+p).join("")}`;let i=/^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/.exec(t);if(!i)return t;let u=p=>Math.min(255,Number(p)).toString(16).padStart(2,"0");return`#${u(i[1])}${u(i[2])}${u(i[3])}`}var de=null,kn=[];function wn(n){kn=n}async function ho(n){try{let t=await fetch(`${n.apiBase}/v1/editor/targets`,{headers:{authorization:`Bearer ${n.token}`}});if(!t.ok)return[];let r=await t.json();return Mt=Array.isArray(r.fonts)?r.fonts.filter(i=>typeof i=="string"):[],Array.isArray(r.targets)?r.targets:[]}catch(t){return[]}}async function pt(n,t){try{let r=await fetch(`${n.apiBase}${t}`,{headers:{authorization:`Bearer ${n.token}`}});return r.ok?await r.json():null}catch(r){return null}}function Fe(n=document){for(let t of Array.from(n.querySelectorAll(`.${At}`)))t.remove()}function En(n,t=document){var i;Fe(t);let r=0;for(let u of n){if(r>=lo)break;let p=he(u.locator,t);if(!p)continue;let k=p.getBoundingClientRect(),$=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${k.left}px`,top:`${k.top}px`,width:`${k.width}px`,height:`${k.height}px`,border:"2px dashed #10b981",background:"rgba(16,185,129,0.08)"});$.className=At;let L=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${k.left}px`,top:`${Math.max(0,k.top-20)}px`,padding:"2px 6px",borderRadius:"4px",background:"#10b981",color:"#fff",font:"11px system-ui, sans-serif",whiteSpace:"nowrap"},u.label);L.className=At,((i=t.body)!=null?i:t.documentElement).append($,L),r+=1}}function mt(n,t){let r=n.previousElementSibling,i=n.nextElementSibling,u=r?Ne(r,t):null,p=i?Ne(i,t):null;return{prevEl:r,nextEl:i,prevLocator:r&&u&&Ve(u,r,t)?u:null,nextLocator:i&&p&&Ve(p,i,t)?p:null}}var yo=/testimonial|review|quote/i;function Sn(n){let t=[],r=n.headings.length>=1,i=n.links.length>=1;return r&&i&&t.push("hero","cta_band"),n.headings.length>=2&&n.paragraphs.length>=2&&t.push("feature_grid"),n.quotes.length>=1&&t.push("testimonial"),t}var Rt=["color","background","fontSize","fontWeight","borderRadius","textAlign","fontFamily"],bo=/^(0|\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|pt))$/i,xo=new Set(["left","center","right","justify","start","end"]),vo=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,ko=/^(rgb|rgba|hsl|hsla)\(/i;function wo(n){return vo.test(n)||ko.test(n)}function Tn(n,t){switch(n){case"fontSize":case"borderRadius":return bo.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 xo.has(t.toLowerCase())?null:"Choose left, center, right, or justify.";case"color":case"background":return wo(t)?null:"Enter a colour, e.g. #1a1a1a.";case"fontFamily":{let r=t.split(",").map(i=>i.trim().replace(/^['"]|['"]$/g,""));return t.length<=120&&r.length>=1&&r.length<=5&&r.every(i=>/^[A-Za-z0-9][A-Za-z0-9 -]*$/.test(i))?null:"Use a font name, e.g. Georgia, serif."}default:return null}}function Ht(n){let t={},r={};for(let i of Rt){let u=n[i];if(typeof u!="string")continue;let p=u.trim();if(p==="")continue;if(!Je(p)){r[i]="That value isn\u2019t allowed.";continue}let k=Tn(i,p);if(k){r[i]=k;continue}t[i]=p}return{style:t,errors:r}}function a(n,t,r){let i=document.createElement(n);return Object.assign(i.style,t),r!==void 0&&(i.textContent=r),i}function Cn(n){var an;let t=null,r=[],i=null,u=()=>{for(;r.length>0;){let e=r.splice(0,20);try{fetch(`${n.apiBase}/v1/editor/telemetry`,{method:"POST",keepalive:!0,headers:{authorization:`Bearer ${n.token}`,"content-type":"application/json"},body:JSON.stringify({events:e})}).catch(()=>{})}catch(o){}}},p=(e,o)=>{r.push(A({kind:e},o?{meta:o}:{})),i&&clearTimeout(i),i=setTimeout(u,2e3)};window.addEventListener("pagehide",u);let k=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #6366f1",background:"rgba(99,102,241,0.12)",display:"none"});k.id=so;let $=a("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #10b981",background:"rgba(16,185,129,0.10)",borderRadius:"4px",display:"none"});$.id=ao;let L=()=>{if(!t||!t.isConnected){$.style.display="none";return}let e=t.getBoundingClientRect();Object.assign($.style,{display:"block",left:`${e.left-2}px`,top:`${e.top-2}px`,width:`${e.width}px`,height:`${e.height}px`})},D=()=>L();vn();let I=a("div",{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",width:"min(408px, calc(100vw - 32px))",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)",maxHeight:"calc(100vh - 32px)",overflowY:"auto",overscrollBehavior:"contain"});I.id=De;let be=a("span",{width:"9px",height:"9px",borderRadius:"50%",background:"#34d399",display:"inline-block",flex:"0 0 auto"});be.className="sntedi-dot";let V=a("div",{display:"flex",alignItems:"center",gap:"8px",fontWeight:"700",fontSize:"14px",marginBottom:"6px"});V.append(be,a("span",{},"SentientUI"));let j=a("div",{opacity:"0.85",marginBottom:"8px"},"Click any element on the page to adapt it."),H=!1,q=a("button",T("#374151"),"Pause selecting");q.onclick=()=>{H=!H,q.textContent=H?"Resume selecting":"Pause selecting",H?(k.style.display="none",Fe(document),h("Selection paused \u2014 browse normally, then resume.")):h("Click any element on the page to adapt it.")};let W=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"}),Z=a("div",{fontSize:"12px",marginBottom:"8px",minHeight:"16px"}),P=a("button",T("#6366f1"),"Test different text here"),F=a("button",T("#374151"),"Change style"),ce=a("button",T("#374151"),"Try a different layout for this section"),Y=a("button",T("#374151"),"Track clicks as a goal"),C=a("button",T("#374151"),"Track form submissions as a goal"),Q=a("button",T("#374151"),"Track page visits as a goal"),ue=a("button",T("#374151"),"Track reading this far as a goal"),Pt=a("button",T("#374151"),"Set up a funnel"),je=a("button",T("#374151"),"Attach this test to a funnel step"),xe=a("button",T("#10b981"),"Turn the funnel on"),pe=a("button",T("#374151"),"Move up"),fe=a("button",T("#374151"),"Move down"),Xe=a("button",T("#6366f1"),"Save this arrangement"),Ze=a("button",T("#374151"),"Undo"),Be=a("button",U(A({},T("transparent")),{opacity:"0.6"}),"Close editor"),ne=a("button",T("#10b981"),"Publish now \u2014 go live"),oe=a("button",T("#10b981"),"Start tracking now");for(let e of[P,F,ce,Y,pe,fe])e.disabled=!0;let bt=[P,F,ce,Y,C,pe,fe];for(let e of bt)e.style.display="none";Xe.style.display="none",Ze.style.display="none",ne.style.display="none",oe.style.display="none",je.style.display="none",xe.style.display="none";let re=a("div",{display:"none",fontSize:"11px",opacity:"0.75",marginBottom:"2px",lineHeight:"1.8",overflow:"hidden",textOverflow:"ellipsis"}),_e=a("div",{}),Ot=[{id:"text",label:"Text",icon:"\u270F\uFE0F"},{id:"style",label:"Style",icon:"\u{1F3A8}"},{id:"layout",label:"Layout",icon:"\u{1F9F1}"},{id:"goals",label:"Goals",icon:"\u{1F3AF}"},{id:"funnels",label:"Funnels",icon:"\u{1F9ED}"},{id:"drafts",label:"Drafts",icon:"\u{1F5C2}\uFE0F"}],J="text",zt=new Map,ge=new Map,xt=new Map,Nt=a("div",{display:"flex",gap:"0",margin:"10px 0 0",justifyContent:"space-between",borderBottom:"1px solid rgba(255,255,255,0.1)"}),Dt=a("div",{paddingTop:"10px"});for(let e of Ot){let o=a("button",{background:"transparent",border:"none",cursor:"pointer",font:"600 11.5px system-ui, sans-serif",color:"#9ca3af",whiteSpace:"nowrap",padding:"7px 5px",borderBottom:"2px solid transparent",marginBottom:"-1px"});o.append(a("span",{fontSize:"11px",marginRight:"3px"},e.icon),a("span",{},e.label)),o.onclick=()=>vt(e.id),zt.set(e.id,o),Nt.append(o);let s=a("div",{display:"none"}),l=a("div",{fontSize:"12px",opacity:"0.7",padding:"2px 0 6px",display:"none"});s.append(l),xt.set(e.id,l),ge.set(e.id,s),Dt.append(s)}ge.get("text").append(P),ge.get("style").append(F),ge.get("layout").append(ce,pe,fe,Xe,Ze),ge.get("goals").append(Y,C,Q,ue),ge.get("funnels").append(Pt,je,xe);let K=a("div",{});ge.get("drafts").append(K);let Qe=()=>{var o,s;for(let l of Ot){let d=l.id===J,m=zt.get(l.id);m.style.color=d?"#ffffff":"#9ca3af",m.style.borderBottom=d?"2px solid #6366f1":"2px solid transparent",ge.get(l.id).style.display=d?"block":"none",xt.get(l.id).style.display="none"}let e=l=>{let d=xt.get(J);d.textContent=l,d.style.display="block"};J==="text"?t?P.disabled?e(P.title||"This element can\u2019t be targeted reliably \u2014 try its heading or a button."):(o=P.onclick)==null||o.call(P,new MouseEvent("click")):e("Click any text on the page to test a different wording."):J==="style"?t?F.disabled?e("This element can\u2019t be targeted reliably \u2014 try a heading, a button, or a whole section."):(s=F.onclick)==null||s.call(F,new MouseEvent("click")):e("Click any element on the page to change how it looks."):J==="layout"?t||e("Click a section to move it or lay it out differently. Layouts re-arrange the words already on the page \u2014 they never add a section you don\u2019t have."):J==="goals"?t||e("Page-level goals work right away; click a button or form to track it specifically."):J==="funnels"?e("Chain tracked goals into a journey \u2014 the drop-off view fills in as visitors move through it."):J==="drafts"&&Ae()},Bn=(e,o,s)=>{e.onclick=()=>{if(e.dataset.armed==="1"){e.dataset.armed="",s();return}e.dataset.armed="1",e.textContent="Sure?",setTimeout(()=>{e.isConnected&&e.dataset.armed==="1"&&(e.dataset.armed="",e.textContent=o)},4e3)}},$e=(e,o)=>a("button",U(A({},T(e)),{display:"inline-block",width:"auto",margin:"0",padding:"4px 9px",fontSize:"11px",flex:"0 0 auto"}),o),Ft=(e,o)=>{let s=new URL(window.location.href);s.searchParams.delete("sentient_editor"),s.searchParams.set("sentient_preview",e),o&&s.searchParams.set("sentient_arm",o),window.location.assign(s.toString())},et=(e,o,s)=>{let l=$e("#374151","Discard");return Bn(l,"Discard",async()=>{l.disabled=!0;let d=await go(n,e);l.disabled=!1,X(d,o),d.r==="ok"&&s()}),l},jt=(e,o)=>{ke.textContent="";let s=a("div",{margin:"0 0 6px",padding:"8px 10px",borderRadius:"8px",fontSize:"12px",background:"rgba(99,102,241,0.10)",border:"1px solid rgba(99,102,241,0.35)"}),l=a("div",{display:"flex",gap:"6px",flexWrap:"wrap"});l.append(...o),s.append(a("div",{marginBottom:"6px"},e),l),ke.append(s)},Ae=async()=>{var g,y,b,x,w,E,S,M,R,te,ae,ze;K.textContent="",K.append(a("div",{fontSize:"12px",opacity:"0.6",padding:"4px 0"},"Loading\u2026"));let e=[],o=[],s=null,l=!1;if(await Promise.all([(async()=>{var v;try{let _=await fetch(`${n.apiBase}/v1/editor/slots`,{headers:{authorization:`Bearer ${n.token}`}});_.ok?e=(v=(await _.json()).slots)!=null?v:[]:s=_.status===401?"expired":"error"}catch(_){s="error"}})(),(async()=>{var v;try{let _=await fetch(`${n.apiBase}/v1/editor/goals`,{headers:{authorization:`Bearer ${n.token}`}});_.ok?o=(v=(await _.json()).goals)!=null?v:[]:l=!0}catch(_){l=!0}})()]),J!=="drafts")return;if(K.textContent="",s){if(K.append(a("div",{fontSize:"12px",opacity:"0.8",padding:"4px 0"},s==="expired"?"Editor session expired \u2014 reopen it from your dashboard to see your drafts. They\u2019re safe.":"Couldn\u2019t load your drafts \u2014 they\u2019re safe; check your connection and retry.")),s==="error"){let v=$e("#374151","Retry");v.onclick=()=>{Ae()},K.append(v)}return}let d=e.filter(v=>{var _,z,le,me,Le,Ye;return((le=(z=(_=v.draft_config)==null?void 0:_.arms)==null?void 0:z.length)!=null?le:0)>0||((Ye=(Le=(me=v.published_config)==null?void 0:me.arms)==null?void 0:Le.length)!=null?Ye:0)>0}),m=o.filter(v=>v.event!=="custom"&&(v.status==="draft"||v.status==="active"));if(d.length===0&&m.length===0&&!l){K.append(a("div",{fontSize:"12px",opacity:"0.7",padding:"4px 0"},"Nothing saved yet \u2014 changes and goals you save land here, previewable before they go live."));return}let f=v=>a("span",{fontSize:"10px",padding:"2px 7px",borderRadius:"999px",flex:"0 0 auto",background:v?"rgba(16,185,129,0.2)":"rgba(99,102,241,0.25)",color:v?"#6ee7b7":"#c7d2fe"},v?"live":"draft"),c=v=>{let _=a("div",{display:"flex",alignItems:"center",gap:"6px",padding:"7px 0",borderBottom:"1px solid rgba(255,255,255,0.08)",fontSize:"12px"}),z=a("div",{flex:"1 1 auto",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},v);return _.append(z),{row:_,name:z}};for(let v of d){let{row:_}=c((g=v.display_name)!=null?g:v.slot_id);_.append(f(v.status==="published"));let z=(w=(x=(y=v.draft_config)==null?void 0:y.arms)!=null?x:(b=v.published_config)==null?void 0:b.arms)!=null?w:[],le=(M=(E=z[1])==null?void 0:E.id)!=null?M:(S=z[0])==null?void 0:S.id,me=$e("#374151","Preview");if(me.onclick=()=>Ft(v.slot_id,le),_.append(me),v.status!=="published"&&((ae=(te=(R=v.draft_config)==null?void 0:R.arms)==null?void 0:te.length)!=null?ae:0)>0){let Le=$e("#10b981","Publish");Le.onclick=async()=>{Le.disabled=!0;let Ye=await G(n,`/v1/editor/slots/${encodeURIComponent(v.slot_id)}/publish`,{});Le.disabled=!1,X(Ye,"\u2713 Published \u2014 live for new visitors."),Ye.r==="ok"&&(p("published",{kind:"slot"}),Ae())},_.append(Le)}v.status!=="published"&&_.append(et(`/v1/editor/slots/${encodeURIComponent(v.slot_id)}`,"\u{1F5D1} Draft discarded \u2014 nothing changed for your visitors.",()=>{Kt(v.slot_id),Ae()})),K.append(_)}if(l)K.append(a("div",{fontSize:"11px",opacity:"0.6",padding:"6px 0 2px"},"Couldn\u2019t load your goals right now \u2014 they\u2019re safe."));else if(m.length>0){K.append(a("div",{fontSize:"11px",opacity:"0.6",padding:"8px 0 2px"},"Goals"));for(let v of m){let{row:_}=c((ze=v.display_name)!=null?ze:v.goal_id);if(_.append(f(v.status==="active")),v.status==="draft"){let z=$e("#10b981","Start tracking");z.onclick=async()=>{z.disabled=!0;let le=await G(n,`/v1/editor/goals/${encodeURIComponent(v.goal_id)}/publish`,{});z.disabled=!1,X(le,"\u2713 Tracking is live \u2014 it counts from your next visitor."),le.r==="ok"&&(p("published",{kind:"goal"}),Ae())},_.append(z,et(`/v1/editor/goals/${encodeURIComponent(v.goal_id)}`,"\u{1F5D1} Draft goal discarded \u2014 it never tracked anything.",()=>{Xt(v.goal_id),Ae()}))}K.append(_)}}},vt=e=>{J!==e&&(O(),Ge(),J=e,Qe())},qt=a("div",{display:"flex",alignItems:"center",gap:"6px",marginBottom:"10px"});Object.assign(V.style,{marginBottom:"0",flex:"1 1 auto",fontSize:"13px",whiteSpace:"nowrap"});let Ut=!1,ve=a("button",{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",width:"46px",height:"46px",borderRadius:"50%",border:"1px solid rgba(99,102,241,0.55)",background:"#111827",color:"#fff",cursor:"pointer",display:"none",alignItems:"center",justifyContent:"center",gap:"4px",font:"700 15px system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"}),Gt=a("span",{width:"7px",height:"7px",borderRadius:"50%",background:"#34d399",display:"inline-block"});Gt.className="sntedi-dot",ve.append(Gt,a("span",{},"S")),ve.title="Open the SentientUI editor";let Wt=a("button",{display:"inline-block",width:"auto",margin:"0",padding:"3px 8px",fontSize:"10.5px",borderRadius:"999px",background:"#374151",color:"#fff",border:"none",cursor:"pointer",whiteSpace:"nowrap"},"Minimize");Wt.onclick=()=>{I.style.display="none",ve.style.display="flex",Ut=H,H=!0,k.style.display="none",Fe(document)},ve.onclick=()=>{I.style.display="block",ve.style.display="none",H=Ut},Object.assign(q.style,{display:"inline-block",width:"auto",margin:"0",padding:"3px 8px",fontSize:"10.5px",borderRadius:"999px",background:"#374151",whiteSpace:"nowrap"}),Object.assign(Be.style,{display:"inline-block",width:"auto",margin:"0",padding:"3px 8px",fontSize:"10.5px",borderRadius:"999px",whiteSpace:"nowrap"}),qt.append(V,q,Wt,Be);let Yt=a("div",{marginTop:"10px",borderTop:"1px solid rgba(255,255,255,0.1)",paddingTop:"8px"}),ke=a("div",{});Object.assign(Z.style,{marginBottom:"4px"}),Yt.append(ke,Z,ne,oe);let ie=a("button",{display:"none",width:"auto",margin:"0",padding:"5px 10px",flex:"0 0 auto",fontSize:"11px",borderRadius:"999px",background:"rgba(250,204,21,0.15)",border:"1px solid rgba(250,204,21,0.45)",color:"#fde68a",cursor:"pointer",whiteSpace:"nowrap"},"\u2728 Ask AI"),kt=a("div",{display:"flex",alignItems:"center",gap:"6px"});Object.assign(W.style,{flex:"1 1 auto",marginBottom:"0"}),kt.append(W,ie),Object.assign(kt.style,{marginBottom:"6px"});let se=a("div",{}),B=a("div",{marginTop:"4px"});B.addEventListener("input",()=>{Me=!0}),B.addEventListener("change",()=>{Me=!0}),I.append(qt,j,kt,re,_e,se,Nt,Dt,B,Yt),((an=document.body)!=null?an:document.documentElement).append(k,$,I,ve);let we=null,Vt=()=>{we==null||we(),we=null},Jt=()=>{we=null},Me=!1,wt=null,O=()=>{Vt(),B.textContent="",Me=!1,wt=null,_t=!1},qe=(e,o,s)=>{var y;O();let l={},d={},m={display:"block",width:"100%",marginTop:"4px",padding:"7px 9px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.18)",background:"#1f2937",color:"#fff",font:"13px system-ui, sans-serif"};for(let b of e){let x=a("label",{display:"block",fontSize:"12px",opacity:"0.85",marginTop:"8px"},b.label);if(B.append(x),b.type==="select"){let E=a("select",m);E.setAttribute("data-field",b.key);let S=document.createElement("option");S.value="",S.textContent="\u2014 no change \u2014",E.append(S);for(let M of(y=b.options)!=null?y:[]){let R=document.createElement("option");R.value=M,R.textContent=M,E.append(R)}l[b.key]=()=>E.value,B.append(E)}else if(b.type==="color"){let E=a("input",U(A({},m),{padding:"2px",height:"34px"}));E.type="color",E.setAttribute("data-field",b.key);let S=!1;E.addEventListener("input",()=>{S=!0}),l[b.key]=()=>S?E.value:"",B.append(E)}else{let E=a("input",m);E.setAttribute("data-field",b.key),b.value!==void 0&&(E.value=b.value),l[b.key]=()=>E.value,B.append(E)}let w=a("div",{fontSize:"11px",color:"#fca5a5",marginTop:"3px",display:"none"});w.setAttribute("data-feedback",b.key),d[b.key]=w,B.append(w)}let f=(b,x)=>{let w=d[b];w&&(w.textContent=x!=null?x:"",w.style.display=x?"block":"none")},c=a("button",T("#6366f1"),o),g=a("button",U(A({},T("transparent")),{opacity:"0.6"}),"Cancel");c.onclick=()=>s(Object.fromEntries(Object.entries(l).map(([b,x])=>[b,x()])),f),g.onclick=O,B.append(c,g)},h=(e,o=!0)=>{Z.textContent=e,Z.style.color=o?"#a7f3d0":"#fca5a5"},Et=(e,o)=>{var l,d;if(p("error_shown",{code:(d=e.code)!=null?d:`http_${(l=e.status)!=null?l:"network"}`}),e.code==="plan_limit_reached"){let m=e.feature==="live_goals"?"live goal":"of these",f=e.plan?`${e.plan} plan`:"plan";return e.feature==="live_goals"?`Your ${f} includes 1 live goal. Pause another goal in your dashboard, or upgrade to track more.`:`Your ${f} has reached its limit for ${m}. Manage them in your dashboard, or upgrade for more.`}if(e.code==="role_required")return"Your account can view but not edit this project \u2014 ask an admin for editor access.";if(e.code==="demo_read_only"&&e.message)return e.message;let s=e.status?` (HTTP ${e.status})`:"";return`\u26A0 Couldn\u2019t ${o} \u2014 try again.${s}`},X=(e,o)=>{e.r==="ok"?h(o,!0):e.r==="expired"?h("Editor session expired \u2014 reopen it from your dashboard to save this. Your earlier changes are safe.",!1):h(Et(e,"save"),!1)},Ee=null,tt=e=>e.length>30?`${e.slice(0,27)}\u2026`:e,Kt=e=>{Ee===e&&(Ee=null,ne.style.display="none",je.style.display="none",ke.textContent="")},Xt=e=>{Oe===e&&(Oe=null,oe.style.display="none",ke.textContent="")},nt=(e,o,s)=>{Ee=e,ne.textContent=o?`Publish \u201C${tt(o)}\u201D \u2014 go live`:"Publish now \u2014 go live",ne.style.display="block",je.style.display="block";let l=[];if(s){let d=$e("#374151","Preview");d.onclick=()=>Ft(e,s),l.push(d)}l.push(et(`/v1/editor/slots/${encodeURIComponent(e)}`,"\u{1F5D1} Draft discarded \u2014 nothing changed for your visitors.",()=>Kt(e))),jt(o?`Draft saved for \u201C${tt(o)}\u201D \u2014 nothing is live for visitors yet.`:"Draft saved \u2014 nothing is live for visitors yet.",l)};ne.onclick=async()=>{if(!Ee)return;ne.disabled=!0,h("Publishing\u2026");let e=await G(n,`/v1/editor/slots/${encodeURIComponent(Ee)}/publish`,{});ne.disabled=!1,e.r==="ok"?(p("published",{kind:"slot"}),h("\u2713 Published \u2014 live for new visitors.",!0),ne.style.display="none",Ee=null,ke.textContent=""):e.r==="expired"?h("Editor session expired \u2014 reopen it from your dashboard to publish. Your saved draft is safe.",!1):h(Et(e,"publish"),!1)};let N=null,Re=!1,He=null,Ie=null,ee=null,Se=null,Ue=null,ot=null,Te=!1,Zt=(e,o)=>Re?e?"":`Nothing to swap with ${o} \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.",Qt=()=>{pe.disabled=!Re||!ee,fe.disabled=!Re||!Se,pe.title=pe.disabled?Zt(ee,"above"):"",fe.title=fe.disabled?Zt(Se,"below"):""},St=e=>{Xe.style.display=e?"block":"none",Ze.style.display=e?"block":"none",Qt()},Ge=()=>{if(Te&&t&&Ue&&Ue.insertBefore(t,ot),Te=!1,Ue=null,ot=null,t){let e=mt(t,document);He=e.prevEl,Ie=e.nextEl,ee=e.prevLocator,Se=e.nextLocator}L(),St(!1)},en=e=>{if(H)return;let o=e.target;if(!o||I.contains(o)||o===k)return;Fe(document);let s=o.getBoundingClientRect();Object.assign(k.style,{display:"block",left:`${s.left}px`,top:`${s.top}px`,width:`${s.width}px`,height:`${s.height}px`})},Ce=e=>{var s;let o=((s=e.textContent)!=null?s:"").trim().replace(/\s+/g," ");return o?o.length>40?`${o.slice(0,37)}\u2026`:o:e.tagName.toLowerCase()},_n=e=>!!e.id||["section","header","footer","nav","main","form","article","aside"].includes(e.tagName.toLowerCase())||!!e.querySelector(":scope > h1, :scope > h2, :scope > h3"),$n=e=>{var l;let o=e.querySelector("h1, h2, h3"),s=(l=o==null?void 0:o.textContent)==null?void 0:l.replace(/\s+/g," ").trim();return s?s.length>28?`${s.slice(0,25)}\u2026`:s:e.id?`#${e.id.length>24?`${e.id.slice(0,21)}\u2026`:e.id}`:`<${e.tagName.toLowerCase()}>`},An=e=>{re.textContent="";let o=[];for(let f=e.parentElement;f&&f!==document.body&&o.length<3;f=f.parentElement)_n(f)&&o.push(f);let s=Ce(e),l=()=>a("span",{opacity:"0.5",margin:"0 4px"},"\u2039"),d=!0;for(let f of o){let c=$n(f);if(c===s||s.startsWith(c))continue;let g=a("button",{background:"transparent",border:"none",color:"#a5b4fc",cursor:"pointer",font:"inherit",padding:"0",textDecoration:"underline"},c);g.onclick=()=>rt(f),d||re.append(l()),re.append(g),d=!1}d||re.append(l());let m=a("button",{background:"transparent",border:"none",color:"#a5b4fc",cursor:"pointer",font:"inherit",padding:"0",textDecoration:"underline",opacity:"0.7"},"Page");m.onclick=()=>tn(),re.append(m),re.style.display="block"},Mn=e=>{_e.textContent="";let o=null,s=0;for(let d=e.parentElement;d&&d!==document.body&&s<6;d=d.parentElement,s++)if(Ve(Ne(d,document),d,document)){o=d;break}let l=a("div",{marginBottom:"8px",padding:"8px 10px",borderRadius:"8px",fontSize:"12px",background:"rgba(252,165,165,0.12)",border:"1px solid rgba(252,165,165,0.4)"});if(o){let d=o;l.append(a("div",{marginBottom:"6px"},"This exact element can\u2019t be tracked safely \u2014 it looks identical to others on the page. You can pick something more specific inside it, or work with the whole block, which we can target reliably."));let m=a("button",U(A({},T("#6366f1")),{marginTop:"0"}),`Select \u201C${Ce(d)}\u201D instead`);m.onclick=()=>rt(d);let f=a("button",U(A({},T("transparent")),{opacity:"0.6"}),"Pick something else");f.onclick=()=>{_e.textContent=""},l.append(m,f)}else l.append(a("div",{},"This part of the page can\u2019t be targeted reliably \u2014 try a heading, a button, or a whole section instead."));_e.append(l)},rt=e=>{Ge(),O(),_e.textContent="",t=e,N=Ne(e,document);let o=Ve(N,e,document);Re=o,L(),W.style.display="block",W.textContent=`Selected: ${Ce(e)}`,An(e),p("element_selected",{unique:o}),h(o?"\u2713 Matches exactly 1 element":"",o),o||Mn(e),j.style.display="none",ie.style.display="inline-block",se.textContent="";for(let m of bt)m.style.display="block";P.style.display="none",F.style.display="none";let s=e.childElementCount===0;P.disabled=!o||!s,P.title=o?s?"":"This element contains other elements, so testing text here would replace them. Pick the text itself (e.g. the heading), not its container.":"",F.disabled=!o,ce.disabled=!o,Y.disabled=!o;let l=e.closest("form");C.style.display=l?"block":"none",C.disabled=!l;let d=mt(e,document);He=d.prevEl,Ie=d.nextEl,ee=d.prevLocator,Se=d.nextLocator,Qt(),Qe()},tn=()=>{Ge(),O(),t=null,N=null,Re=!1,He=null,Ie=null,ee=null,Se=null,L(),_e.textContent="",se.textContent="",re.textContent="",re.style.display="none",W.textContent="",W.style.display="none",ie.style.display="none";for(let e of bt)e.style.display="none";j.style.display="block",h(""),Qe()},Pe=!1,Tt=-1,nn=e=>{var l,d;let o=e.target,s=!!((l=o==null?void 0:o.closest)!=null&&l.call(o,'input, textarea, select, [contenteditable="true"]'));if(e.key==="Escape"){if(B.childElementCount>0){O(),Pe=!1;return}if(t){tn(),Pe=!1;return}if(!Pe){Pe=!0,h("Press Esc again to close the editor.");return}Pe=!1,(d=Be.onclick)==null||d.call(Be,new MouseEvent("click"));return}if(Pe=!1,!(s||H)){if(e.key==="ArrowUp"||e.key==="ArrowDown"){if(!t||(e.key==="ArrowUp"?pe:fe).disabled)return;e.preventDefault(),Bt(e.key==="ArrowUp"?"up":"down");return}if(e.key==="Tab"){let m=[];for(let c of kn){let g=he(c.locator,document);g&&!m.includes(g)&&m.push(g)}if(m.length===0)return;if(Me){h("\u26A0 You have unsaved changes \u2014 Save or Cancel before picking another element.",!1),e.preventDefault();return}e.preventDefault(),Tt=(Tt+(e.shiftKey?-1:1)+m.length)%m.length;let f=m[Tt];rt(f);try{f.scrollIntoView({block:"center",behavior:"smooth"})}catch(c){}}}},on=e=>{if(H)return;let o=e.target;if(!(!o||I.contains(o))){if(e.preventDefault(),e.stopPropagation(),Me&&o!==t&&wt!==o){wt=o,h("\u26A0 You have unsaved changes \u2014 Save or Cancel first, or click that element again to discard them.",!1);return}rt(o)}};P.onclick=()=>{var m,f,c;if(!t||!N)return;p("form_opened",{kind:"text"});let e=N,o=(f=(m=t.textContent)==null?void 0:m.trim())!=null?f:"";qe([{key:"current",label:"Current wording",value:o},{key:"alt",label:"Alternative wording to test",value:""}],"Save draft",async g=>{let y=g.alt.trim();if(!y){h("\u26A0 Enter alternative wording to test.",!1);return}if(y===g.current.trim()){h("\u26A0 Enter different wording \u2014 the alternative matches the current text.",!1);return}let b=Ke("text",e,t);h("Saving\u2026");let x=await G(n,`/v1/editor/slots/${encodeURIComponent(b)}`,{kind:"arms",target:e,draftConfig:{arms:[{id:"a",displayName:"Original",ops:{text:g.current}},{id:"b",displayName:"Alternative",ops:{text:g.alt}}]}});x.r==="ok"&&(p("draft_saved",{kind:"slot"}),Jt(),O(),nt(b,Ce(t),"b")),X(x,"\u2713 Saved as a draft. Click \u201CPublish\u201D below to go live.")});let s=t,l=(c=s.textContent)!=null?c:"";we=()=>{s.textContent=l};let d=B.querySelector('input[data-field="alt"]');d==null||d.addEventListener("input",()=>{s.textContent=d.value.trim()===""?l:d.value})};let We=null,rn=e=>{let o=c=>{var g;return((g=c.textContent)!=null?g:"").replace(/\s+/g," ").trim()},s=Array.from(e.querySelectorAll("h1,h2,h3,h4")).map(o).filter(Boolean);if(s.length===0){let c=e.closest("h1,h2,h3,h4");c&&s.push(o(c))}let l=Array.from(e.querySelectorAll("p")).map(o).filter(c=>c.length>0&&c.length<=300),d=[];for(let c of Array.from(e.querySelectorAll("a[href], button"))){let g=o(c);if(!g||g.length>60)continue;let y="",b=c.getAttribute("href");if(b)try{let x=new URL(b,window.location.href);x.protocol==="https:"&&(y=x.href)}catch(x){}d.push({label:g,href:y})}let m=Array.from(e.querySelectorAll("blockquote, q")).map(o).filter(Boolean);if(m.length===0&&yo.test(`${e.className} ${e.id}`))for(let c of l)c.length>=20&&m.push(c);let f=Array.from(e.querySelectorAll('cite, figcaption, footer, [class*="author"]')).map(o).filter(c=>c.length>0&&c.length<=80);return{headings:s,paragraphs:l,links:d,quotes:m,attributions:f}},Rn=(e,o)=>{var l,d,m,f,c,g,y,b,x,w,E,S,M,R,te,ae,ze,v,_,z;let s=le=>{var me;return o.paragraphs.length>=3&&(me=o.paragraphs[o.paragraphs.length-3+le])!=null?me:""};switch(e){case"headline":return(l=o.headings[0])!=null?l:"";case"supporting":return(d=o.paragraphs[0])!=null?d:"";case"cta_label":return(f=(m=o.links[0])==null?void 0:m.label)!=null?f:"";case"cta_href":return(g=(c=o.links[0])==null?void 0:c.href)!=null?g:"";case"secondary_label":return(b=(y=o.links[1])==null?void 0:y.label)!=null?b:"";case"secondary_href":return(w=(x=o.links[1])==null?void 0:x.href)!=null?w:"";case"quote":case"q1":return(E=o.quotes[0])!=null?E:"";case"q2":return(S=o.quotes[1])!=null?S:"";case"q3":return(M=o.quotes[2])!=null?M:"";case"name":case"n1":return(R=o.attributions[0])!=null?R:"";case"n2":return(te=o.attributions[1])!=null?te:"";case"n3":return(ae=o.attributions[2])!=null?ae:"";case"role":return(ze=o.attributions[1])!=null?ze:"";case"eyebrow":return"";case"f1_title":return(v=o.headings[1])!=null?v:"";case"f2_title":return(_=o.headings[2])!=null?_:"";case"f3_title":return(z=o.headings[3])!=null?z:"";case"f1_body":return s(0);case"f2_body":return s(1);case"f3_body":return s(2);default:return""}},Hn=(e,o,s)=>{p("form_opened",{kind:"arrangement"});let l=rn(s);qe(e.fields.map(d=>({key:d.id,label:d.kind==="href"?`${d.label} (https link \u2014 required)`:d.label,value:Rn(d.id,l)})),"Save draft",async(d,m)=>{var x,w,E,S,M;let f=!1,c=!1;for(let R of e.fields){if(R.kind==="href"){let ae=!1;try{ae=new URL((x=d[R.id])!=null?x:"").protocol==="https:"}catch(ze){}m(R.id,ae?null:"Links need to start with https://"),ae||(f=!0);continue}let te=((w=d[R.id])!=null?w:"").trim()==="";m(R.id,te?"Fill this in with your own words":null),te&&(c=!0)}if(f){h("\u26A0 Fix the highlighted link(s).",!1);return}if(c){h("\u26A0 Every field needs your own words \u2014 this layout re-arranges your copy, it doesn\u2019t write any.",!1);return}h("Saving\u2026");let g=await mo(n,`/v1/editor/arrangements/${encodeURIComponent(e.id)}/instantiate`,{fields:d});if(g.r!=="ok"||!((E=g.data)!=null&&E.blocks)){g.r==="expired"?X(g.outcome,""):h(`\u26A0 ${(M=(S=g.data)==null?void 0:S.reason)!=null?M:"Couldn\u2019t build the arrangement \u2014 check the fields."}`,!1);return}let y=Ke("arrange",o,s),b=await G(n,`/v1/editor/slots/${encodeURIComponent(y)}`,{kind:"arms",target:o,draftConfig:{arms:[{id:"original",displayName:"Your page today"},{id:e.id,displayName:e.name,blocks:g.data.blocks}],baseline:"original"}});b.r==="ok"&&(p("draft_saved",{kind:"arrangement"}),O(),nt(y,e.name,e.id)),X(b,"\u2713 Saved as a draft \u2014 it will test against this section as it is today. Click \u201CPublish\u201D below to go live.")})};ce.onclick=async()=>{var m,f;if(!t||!N)return;let e=N,o=t;if(O(),h("Loading arrangements\u2026"),!We){let c=await pt(n,"/v1/editor/arrangements");We=(m=c==null?void 0:c.arrangements)!=null?m:null}if(!We||We.length===0){h("\u26A0 Couldn\u2019t load the arrangements \u2014 try again.",!1);return}let s=Sn(rn(o)),l=We.filter(c=>s.includes(c.sectionType));if(l.length===0){h("No other layout fits this section. Layouts re-arrange the words already here \u2014 they don\u2019t add sections your page doesn\u2019t have.",!1);return}h("Pick a layout for this section \u2014 your own words are carried across.");for(let c of l){let g=a("button",U(A({},T("#374151")),{textAlign:"left"}));g.append(a("div",{fontWeight:"600"},c.name),a("div",{fontSize:"11px",opacity:"0.7"},c.description)),g.onclick=()=>Hn(c,e,o),B.append(g)}let d=a("button",U(A({},T("transparent")),{opacity:"0.6"}),"Cancel");d.onclick=O,B.append(d),(f=B.scrollIntoView)==null||f.call(B,{block:"nearest"})};let Oe=null,In=(e,o)=>{Oe=e,oe.textContent=o?`Start tracking \u201C${tt(o)}\u201D now`:"Start tracking now",oe.style.display="block",jt(o?`Goal \u201C${tt(o)}\u201D saved \u2014 it isn\u2019t counting anything until you start it.`:"Goal saved \u2014 it isn\u2019t counting anything until you start it.",[et(`/v1/editor/goals/${encodeURIComponent(e)}`,"\u{1F5D1} Draft goal discarded \u2014 it never tracked anything.",()=>Xt(e))])};oe.onclick=async()=>{if(!Oe)return;oe.disabled=!0,h("Activating\u2026");let e=await G(n,`/v1/editor/goals/${encodeURIComponent(Oe)}/publish`,{});oe.disabled=!1,e.r==="ok"?(p("published",{kind:"goal"}),h("\u2713 Tracking is live \u2014 it counts from your next visitor.",!0),oe.style.display="none",Oe=null,ke.textContent=""):e.r==="expired"?h("Editor session expired \u2014 reopen it from your dashboard to activate. Your saved goal is safe.",!1):h(Et(e,"activate"),!1)};let Ct=(e,o)=>`${ft(e)||"goal"}-${xn(o)}`.slice(0,128),Pn=e=>{var l,d,m;let o=((l=e.textContent)!=null?l:"").replace(/\s+/g," ").trim();return o&&o.length<=60?o:((m=(d=e.getAttribute("aria-label"))!=null?d:e.getAttribute("id"))!=null?m:"").trim()||"element-clicked"},it=async(e,o,s)=>{h("Saving\u2026");let l=await G(n,`/v1/editor/goals/${encodeURIComponent(e)}`,o);l.r==="ok"&&(p("draft_saved",{kind:"goal"}),In(e,s)),X(l,"\u2713 Goal saved. Click \u201CStart tracking\u201D below to go live.")};Y.onclick=()=>{if(!t||!N)return;let e=Ct(Pn(t),JSON.stringify(N));it(e,{event:"click",locator:N},Ce(t))},C.onclick=()=>{var l,d;let e=t==null?void 0:t.closest("form");if(!e)return;let o=Ne(e,document),s=(d=(l=e.getAttribute("id"))!=null?l:e.getAttribute("name"))!=null?d:"form-submitted";it(Ct(s,JSON.stringify(o)),{event:"form_submit",locator:o},s)},Q.onclick=()=>{let e=window.location.pathname||"/",o=ft(e)?`reached-${ft(e)}`:"page-visited";it(Ct(o,e),{event:"url_reached",urlPattern:e},e)};let Lt=[{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}];ue.onclick=()=>{qe([{key:"depth",label:"Counts once a visitor reads",type:"select",options:Lt.map(e=>e.label)}],"Track it",e=>{var l;let o=(l=Lt.find(d=>d.label===e.depth))!=null?l:Lt[2],s=Math.round(o.value*100);it(`read-${s}pct`,{event:"scroll_depth",threshold:o.value},`read ${s}%`),O()})};let st=null,On=e=>{st=e,xe.style.display="block"};xe.onclick=async()=>{if(!st)return;xe.disabled=!0,h("Turning on\u2026");let e=await G(n,`/v1/editor/funnels/${encodeURIComponent(st)}/publish`,{});xe.disabled=!1,e.r==="ok"?(p("published",{kind:"funnel"}),h("\u2713 Funnel is on \u2014 the drop-off view fills in as visitors move through it.",!0),xe.style.display="none",st=null):e.r==="expired"?h("Editor session expired \u2014 reopen it from your dashboard to turn the funnel on. Your draft is safe.",!1):h("\u26A0 Couldn\u2019t turn the funnel on \u2014 try again.",!1)},Pt.onclick=async()=>{var b;h("Loading your goals\u2026");let e=await pt(n,"/v1/editor/goals"),o=(b=e==null?void 0:e.goals)!=null?b:[];if(o.length<2){h("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}h("Pick the steps in order \u2014 first click = first step."),O();let s=[],l=a("label",{display:"block",fontSize:"12px",opacity:"0.85",marginTop:"8px"},"Funnel name"),d=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"});B.append(l,d);let m=a("div",{fontSize:"11px",opacity:"0.7",marginTop:"6px"},"Steps (click in journey order):");B.append(m);let f=new Map,c=()=>{var x,w;for(let[E,S]of f){let M=s.indexOf(E),R=(w=(x=o.find(te=>te.goal_id===E))==null?void 0:x.display_name)!=null?w:E;S.textContent=M===-1?R:`${M+1}. ${R}`,S.style.background=M===-1?"#374151":"#6366f1"}};for(let x of o){let w=a("button",U(A({},T("#374151")),{textAlign:"left"}));f.set(x.goal_id,w),w.onclick=()=>{s=hn(s,x.goal_id),c()},B.append(w)}c();let g=a("button",T("#6366f1"),"Save funnel"),y=a("button",U(A({},T("transparent")),{opacity:"0.6"}),"Cancel");y.onclick=O,g.onclick=async()=>{let x=yn(d.value,s);if(!x.ok){h(`\u26A0 ${x.error}`,!1);return}h("Saving\u2026");let w=await G(n,`/v1/editor/funnels/${encodeURIComponent(x.funnelId)}`,x.body);w.r==="ok"&&(p("draft_saved",{kind:"funnel"}),O(),On(x.funnelId)),X(w,"\u2713 Funnel saved as a draft. Click \u201CTurn the funnel on\u201D to start measuring.")},B.append(g,y)},je.onclick=async()=>{var c,g;let e=Ee;if(!e)return;h("Loading funnels\u2026");let o=await pt(n,"/v1/editor/funnels"),s=(c=o==null?void 0:o.funnels)!=null?c:[];if(s.length===0){h("No funnels yet \u2014 click \u201CSet up a funnel\u201D first.",!1);return}let l=await pt(n,"/v1/editor/goals"),d=new Map(((g=l==null?void 0:l.goals)!=null?g:[]).map(y=>[y.goal_id,y.display_name]));qe([{key:"funnel",label:"Funnel",type:"select",options:s.map(y=>ct(y))},{key:"step",label:"Which step does this element serve?",type:"select",options:ut(s[0],d).map(y=>y.label)}],"Attach",async y=>{var E;let b=(E=s.find(S=>ct(S)===y.funnel))!=null?E:s[0],x=ut(b,d).findIndex(S=>S.label===y.step);if(x<0){h("\u26A0 Pick which step this element serves.",!1);return}h("Attaching\u2026");let w=await G(n,`/v1/editor/funnels/${encodeURIComponent(b.funnel_id)}/assign`,{slotId:e,stepIndex:x});w.r==="ok"&&O(),X(w,`\u2713 Attached \u2014 this test now works toward \u201C${b.display_name}\u201D.`)});let m=B.querySelector('select[data-field="funnel"]'),f=B.querySelector('select[data-field="step"]');m&&f&&m.addEventListener("change",()=>{var b;let y=(b=s.find(x=>ct(x)===m.value))!=null?b:s[0];f.length=1;for(let x of ut(y,d)){let w=document.createElement("option");w.value=x.label,w.textContent=x.label,f.append(w)}})},F.onclick=()=>{if(!t||!N)return;p("form_opened",{kind:"style"});let e=N;qe([{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:Mt.length?`Font (this site has: ${Mt.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(f,c)=>{var E;let{style:g,errors:y}=Ht(f),b=!1;for(let S of Rt)c(S,(E=y[S])!=null?E:null),y[S]&&(b=!0);if(b){h("\u26A0 Fix the highlighted field(s).",!1);return}if(Object.keys(g).length===0){h("\u26A0 Enter at least one style change.",!1);return}let x=Ke("style",e,t);h("Saving\u2026");let w=await G(n,`/v1/editor/slots/${encodeURIComponent(x)}`,{kind:"arms",target:e,draftConfig:{arms:[{id:"a",displayName:"Current look",ops:{}},{id:"b",displayName:"New look",ops:{style:g}}]}});w.r==="ok"&&(p("draft_saved",{kind:"slot"}),Jt(),O(),nt(x,Ce(t),"b")),X(w,"\u2713 Saved as a draft. Click \u201CPublish\u201D below to go live.")});let o=t,s=o.style.cssText;we=()=>{o.style.cssText=s};let l={},d=()=>{let{style:f}=Ht(l);o.style.cssText=s;for(let[c,g]of Object.entries(f)){let y=dt[c];y&&Je(g)&&o.style.setProperty(y,g.trim(),"important")}};for(let f of Rt){let c=B.querySelector(`[data-field="${f}"]`);if(!c)continue;let g=()=>{l[f]=c.value,d()};c.addEventListener("input",g),c.addEventListener("change",g)}let m=[de==null?void 0:de.primaryBg,de==null?void 0:de.primaryText,"#ffffff"].filter(f=>!!f).map(gt).filter((f,c,g)=>yt(f)&&g.indexOf(f)===c);for(let f of["color","background"]){let c=B.querySelector(`input[data-field="${f}"]`);if(!c)continue;let g=a("div",{display:"flex",gap:"6px",marginTop:"4px"});for(let y of m){let b=a("button",{width:"22px",height:"22px",borderRadius:"6px",cursor:"pointer",border:"1px solid rgba(255,255,255,0.35)",background:y,padding:"0"});b.title=y,b.onclick=()=>{c.value=gt(y),c.dispatchEvent(new Event("input"))},g.append(b)}c.after(g)}};let sn=e=>{var l;let o=e==="text"?P:F;if(o.disabled)return h(o.title||"This element can\u2019t be targeted reliably \u2014 try a heading, a button, or a whole section.",!1),!1;vt(e);let s=e==="text"?'[data-field="alt"]':'[data-field="color"]';return B.querySelector(s)||(l=o.onclick)==null||l.call(o,new MouseEvent("click")),!0},zn=()=>{if(!t)return;se.textContent="";let e=a("div",{margin:"0 0 8px",padding:"9px 11px",borderRadius:"10px",background:"rgba(250,204,21,0.08)",border:"1px solid rgba(250,204,21,0.3)"}),o=a("input",{width:"100%",boxSizing:"border-box",padding:"6px 8px",borderRadius:"7px",border:"1px solid rgba(255,255,255,0.18)",background:"rgba(0,0,0,0.25)",color:"#fff",font:"12px system-ui, sans-serif"});o.type="text",o.maxLength=300,o.placeholder="e.g. shorter and more urgent",o.setAttribute("data-field","ai-instruction");let s=a("button",U(A({},T("#6366f1")),{display:"inline-block",width:"auto",margin:"8px 0 0",padding:"4px 10px",fontSize:"11px"}),"Go");s.setAttribute("data-action","ai-go"),s.onclick=()=>{Nn(o.value.trim())},o.onkeydown=l=>{var d;l.key==="Enter"&&(l.preventDefault(),(d=s.onclick)==null||d.call(s,new MouseEvent("click")))},e.append(a("div",{fontWeight:"600",marginBottom:"4px"},"What should this element do differently?"),o,a("div",{opacity:"0.7",fontSize:"11px",marginTop:"4px"},"Leave it blank for ideas. Nothing goes live \u2014 you review and save whatever comes back."),s),se.append(e),o.focus()};ie.onclick=()=>zn();let Nn=async e=>{var c,g;if(!t)return;let o=t;ie.disabled=!0;let s=ie.textContent;ie.textContent="Thinking\u2026",se.textContent="",p("form_opened",{kind:"suggest"});let l={},d=null;try{let y=await fetch(`${n.apiBase}/v1/editor/suggest`,{method:"POST",headers:{authorization:`Bearer ${n.token}`,"content-type":"application/json"},body:JSON.stringify(A(A({element:{tag:o.tagName.toLowerCase(),text:((c=o.textContent)!=null?c:"").replace(/\s+/g," ").trim().slice(0,400)},pageUrl:window.location.pathname},e?{instruction:e.slice(0,300)}:{}),de?{palette:de}:{}))});y.ok?l=await y.json():d=y.status===401?"expired":"error"}catch(y){d="error"}if(ie.disabled=!1,ie.textContent=s,t!==o)return;if(d){h(d==="expired"?"Editor session expired \u2014 reopen it from your dashboard to keep editing.":"\u26A0 Couldn\u2019t get suggestions \u2014 check your connection and try again.",!1);return}if(l.locked){h("AI suggestions aren\u2019t included in this plan.",!1);return}if(l.exhausted){h("You\u2019ve used today\u2019s AI allowance \u2014 more tomorrow, or upgrade for a bigger daily budget.",!1);return}let m=(g=l.suggestions)!=null?g:[];if(m.length===0){h(e?"Couldn\u2019t do that safely on this element \u2014 try asking for a smaller change, or pick a headline or a button.":"No safe suggestions for this element \u2014 try a headline, a button, or a section.",!1);return}let f=(y,b)=>{let x=B.querySelector(`[data-field="${y}"]`);x&&(x.value=b,x.dispatchEvent(new Event("input")))};for(let y of m){let b=a("div",{margin:"0 0 8px",padding:"9px 11px",borderRadius:"10px",fontSize:"12px",background:"rgba(250,204,21,0.08)",border:"1px solid rgba(250,204,21,0.3)"});b.append(a("div",{fontWeight:"600",marginBottom:"2px"},y.title),a("div",{opacity:"0.75",marginBottom:"6px"},y.reason));let x=a("button",U(A({},T("#6366f1")),{display:"inline-block",width:"auto",margin:"0",padding:"4px 10px",fontSize:"11px"}),"Try it");x.onclick=()=>{var w,E;if(t!==o){se.textContent="";return}if(se.textContent="",y.kind==="text"){if(!sn("text"))return;f("alt",y.variant)}else if(y.kind==="style"){if(!sn("style"))return;for(let[S,M]of Object.entries(y.style))if(S==="color"||S==="background"){let R=gt(M);yt(R)&&f(S,R)}else S==="textAlign"?f(S,M==="start"?"left":M==="end"?"right":M):f(S,M)}else{let S=y.goalType==="form_submit"&&!C.disabled;if(!S&&Y.disabled){h("This element can\u2019t be tracked reliably \u2014 select a specific button or link instead.",!1);return}vt("goals"),S?(w=C.onclick)==null||w.call(C,new MouseEvent("click")):(E=Y.onclick)==null||E.call(Y,new MouseEvent("click"))}},b.append(x),se.append(b)}},Bt=e=>{if(!t)return;let o=t.parentElement;if(!o)return;Te||(Ue=o,ot=t.nextSibling,Te=!0),e==="up"&&He?o.insertBefore(t,He):e==="down"&&Ie&&o.insertBefore(t,Ie.nextSibling);let s=mt(t,document);He=s.prevEl,Ie=s.nextEl,ee=s.prevLocator,Se=s.nextLocator;try{t.scrollIntoView({block:"nearest",behavior:"smooth"})}catch(l){}L(),St(!0),h("Previewing the new position \u2014 keep moving, save, or undo.")};pe.onclick=()=>Bt("up"),fe.onclick=()=>Bt("down"),Ze.onclick=()=>{Ge(),h("Move undone \u2014 back to the original position.")},Xe.onclick=async()=>{if(!t||!N||!Te||!Re)return;let e=ee?"moveAfter":"moveBefore",o=ee!=null?ee:Se;if(!o){h("\u26A0 Couldn\u2019t anchor the new position \u2014 nudge it next to a section with an id.",!1);return}let s=Ke("move",N,t);h("Saving\u2026");let l=await G(n,`/v1/editor/slots/${encodeURIComponent(s)}`,{kind:"arms",target:N,draftConfig:{arms:[{id:"a",ops:{}},{id:"b",ops:{[e]:o}}]}});l.r==="ok"&&(p("draft_saved",{kind:"move"}),Te=!1,Ue=null,ot=null,St(!1),nt(s,Ce(t),"b")),X(l,"\u2713 Saved as a draft. Click \u201CPublish\u201D below to go live.")};let Dn=()=>{var e,o;p("editor_closed"),u(),window.removeEventListener("pagehide",u),i&&clearTimeout(i),Ge(),Vt(),document.removeEventListener("mousemove",en,!0),document.removeEventListener("click",on,!0),document.removeEventListener("keydown",nn,!0),window.removeEventListener("scroll",D,!0),window.removeEventListener("resize",D),Fe(document),(e=document.getElementById($t))==null||e.remove(),k.remove(),$.remove(),I.remove(),ve.remove(),window.__sentientEditor=null,(o=document.querySelector("meta[data-sentient-editor]"))==null||o.remove(),lt()},_t=!1;Be.onclick=()=>{if((Me||Te)&&!_t){_t=!0,h("\u26A0 Unsaved changes \u2014 click \u201CClose editor\u201D again to discard them.",!1);return}Dn()},document.addEventListener("mousemove",en,!0),document.addEventListener("click",on,!0),document.addEventListener("keydown",nn,!0),window.addEventListener("scroll",D,!0),window.addEventListener("resize",D),Qe(),p("editor_opened")}function T(n){return{display:"block",width:"100%",marginTop:"8px",padding:"8px 10px",borderRadius:"8px",border:"none",background:n,color:"#fff",font:"13px system-ui, sans-serif",cursor:"pointer",textAlign:"left"}}var Ln="sentient-preview-bar";async function Eo(n,t){var I,be,V,j,H,q,W,Z,P,F,ce,Y;try{fetch(`${n.apiBase}/v1/editor/telemetry`,{method:"POST",keepalive:!0,headers:{authorization:`Bearer ${n.token}`,"content-type":"application/json"},body:JSON.stringify({events:[{kind:"previewed"}]})}).catch(()=>{})}catch(C){}let r=null;try{let C=await fetch(`${n.apiBase}/v1/editor/slots`,{headers:{authorization:`Bearer ${n.token}`}});C.ok&&(r=(be=((I=(await C.json()).slots)!=null?I:[]).find(ue=>ue.slot_id===t&&ue.kind==="arms"))!=null?be:null)}catch(C){}let i=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)"});i.id=Ln;let u=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");u.onclick=()=>{lt();let C=new URL(location.href);for(let Q of["sentient_editor","sentient_preview","sentient_arm"])C.searchParams.delete(Q);location.assign(C.toString())};let p=a("button",{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.3)",background:"#6366f1",color:"#fff",font:"12px system-ui, sans-serif",cursor:"pointer"},"Back to editor");p.onclick=()=>{let C=new URL(location.href);for(let Q of["sentient_preview","sentient_arm"])C.searchParams.delete(Q);location.assign(C.toString())};let k=(q=(H=(V=r==null?void 0:r.draft_config)==null?void 0:V.arms)!=null?H:(j=r==null?void 0:r.published_config)==null?void 0:j.arms)!=null?q:[];if(!r||k.length===0){i.append(a("span",{},"Couldn\u2019t load this preview \u2014 reopen it from your dashboard."),p,u),((W=document.body)!=null?W:document.documentElement).append(i);return}let $=new URLSearchParams(location.search).get("sentient_arm"),L=(P=(Z=k.find(C=>C.id===$))!=null?Z:k[1])!=null?P:k[0];i.append(a("span",{fontWeight:"700"},`Previewing: ${(F=r.display_name)!=null?F:r.slot_id}`));let D=r.target&&typeof r.target=="object"?he(r.target,document):null;if(!D)i.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{mn(D,L.ops,`preview-${r.slot_id}`,document);try{D.scrollIntoView({block:"center"})}catch(C){}for(let C of k){let Q=a("button",{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.3)",cursor:"pointer",background:C.id===L.id?"#6366f1":"transparent",color:"#fff",font:"12px system-ui, sans-serif"},(ce=C.displayName)!=null?ce:C.id);Q.onclick=()=>{let ue=new URL(location.href);ue.searchParams.set("sentient_arm",C.id),location.assign(ue.toString())},i.append(Q)}}i.append(p,u),((Y=document.body)!=null?Y:document.documentElement).append(i)}async function So(){if(typeof document=="undefined")return;let n=po();if(!n)return;let t=await fo(n);if(!t.ok){t.unauthorized?(lt(),bn(co)):bn(uo);return}let r=new URLSearchParams(location.search).get("sentient_preview");if(r){document.getElementById(Ln)||await Eo(n,r);return}if(document.getElementById(De))return;Cn(n);let i=pn(document);de=i,i&&G(n,"/v1/editor/palette",i);let u=await ho(n);wn(u),En(u,document)}So();return Vn(To);})();
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/install.ts
21
+ var install_exports = {};
22
+ __export(install_exports, {
23
+ SNIPPET_PREPAINT_VERSION: () => SNIPPET_PREPAINT_VERSION,
24
+ renderSnippetPrePaintScript: () => renderSnippetPrePaintScript
25
+ });
26
+ module.exports = __toCommonJS(install_exports);
27
+
28
+ // src/prepaint-script.ts
29
+ var SNIPPET_PREPAINT_VERSION = 1;
30
+ function renderSnippetPrePaintScript() {
31
+ return `(function(){try{var W=window,D=document,N=navigator,L=W.location,c=W.sentient,n=Date.now();if(!c||typeof c.apiKey!="string"||c.consent===!1||W.__sntPP)return;if(N.doNotTrack=="1"||N.globalPrivacyControl||N.webdriver)return;if(/[?&]sentient_(editor|preview|persona)=/.test(L.search))return;var s=JSON.parse(localStorage.getItem("_snt_snap:"+c.apiKey)),S=s.slots;if(s.v!==1||typeof s.persona!="string"||typeof s.band!="string"||!S||typeof S!="object"||!(2592e6>n-s.savedAt))return;var H=["data-sentient-persona","data-sentient-confidence"],d=D.documentElement,P=W.__sntPP={v:1,at:n,stamped:[],html:[],reordered:!1,done:!1,stop:function(){X()}},b=P.stamped,p=[],i,k,t,e,l,m,x,V=c.sections,O=s.layoutOrder,q=!(V&&V.length>1&&O&&O.length==V.length);if(c.personaAttributes&&!d.hasAttribute(H[0])){d.setAttribute(H[0],s.persona);d.setAttribute(H[1],s.band);P.html=H}var Q=function(v){return(""+v).replace(/["\\\\]/g,"\\\\$&")},A=function(t,v,g){if(typeof v=="string"){if(!g||(g.arms||[]).indexOf(v)>-1)p.push([t,"data-sentient-arm",v])}else if(v)for(k in v)if(!g||((g.dims||{})[k]||[]).indexOf(v[k])>-1)p.push([t,"data-"+k,v[k]])},U=function(t){var a=t[3];if(!a)return;a[2]==null?a[0].removeAttribute(a[1]):a[0].setAttribute(a[1],a[2]);x=b.indexOf(a);if(x>-1)b.splice(x,1);t[3]=0},R=function(){var g={},f=[],y,z,a,n=0;for(i in V){try{y=D.querySelectorAll(V[i])}catch(_){return 1}if(y.length==1){g[V[i]]=y[0];n++}}if(n!=V.length)return 0;for(i in O){z=g[O[i]];if(!z||~f.indexOf(z))return 1;f.push(z)}a=f[0].parentNode;if(!a)return 1;for(i in f)if(f[i].parentNode!=a)return 1;y=f.slice().sort(function(u,v){return u.compareDocumentPosition(v)&4?-1:1});for(i=0;i in f;i++){z=f[i];if(y[i]!=z){a.insertBefore(z,y[i]);y.splice(y.indexOf(z),1);y.splice(i,0,z)}}P.reordered=!0;return 1},F=function(){if(P.done)return;for(i=0;i in p;i++){t=p[i];if(!t)continue;try{m=D.querySelectorAll(t[0])}catch(_){p[i]=0;continue}if(m.length>1){U(t);p[i]=0}else if(m.length==1&&(!t[3]||t[3][0]!=m[0])){U(t);e=m[0];t[3]=[e,t[1],e.getAttribute(t[1])];e.setAttribute(t[1],t[2]);b.push(t[3])}}if(!q)q=R()},X=function(){if(P.done)return;P.done=!0;try{o.disconnect()}catch(_){}clearTimeout(T)},G=c.slots,C=s.slotConfig;for(i in G)if(G[i]&&G[i].target)A(G[i].target,S[i],G[i]);for(i in C){e=C[i]||{};l=e.locator;t=e.target;if(l){if(l.urlMatch&&!~L.pathname.indexOf(l.urlMatch))continue;t=l.id?'[id="'+Q(l.id)+'"]':l.dataAttr&&/^[\\w-]+$/.test(l.dataAttr.name)?"["+l.dataAttr.name+'="'+Q(l.dataAttr.value)+'"]':l.selector}if(t)A(t,S[i])}var o=new MutationObserver(F),T=setTimeout(X,3e3);o.observe(d,{childList:!0,subtree:!0});D.addEventListener("DOMContentLoaded",function(){F();X()});F();}catch(_){}})();`;
32
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The snippet install's inline pre-paint script — the middle tag of the
3
+ * three-tag install, and the only SentientUI code that runs before the page
4
+ * paints on a return visit.
5
+ *
6
+ * It lives here rather than in @sentientui/core because it is an artefact of the
7
+ * SNIPPET install specifically: it reads `window.sentient`, it hands off to this
8
+ * bundle through `window.__sntPP`, and its contract version is this package's to
9
+ * keep. Core owns the snapshot format it reads; nothing else is shared.
10
+ *
11
+ * Design: docs/superpowers/specs/2026-09-07-snippet-prepaint-script-design.md
12
+ */
13
+ /**
14
+ * What the inline pre-paint script leaves behind for the bundle. The bundle must
15
+ * tolerate this being absent (a two-tag install), a HIGHER `v` (a newer inline
16
+ * pasted before the bundle updated — read only the fields you know), and
17
+ * malformed (treat as absent).
18
+ */
19
+ type PrePaintRecord = {
20
+ v: number;
21
+ /** Date.now() when the inline script ran. */
22
+ at: number;
23
+ /** [element, attribute, value before we stamped it] — null means "absent". */
24
+ stamped: Array<[Element, string, string | null]>;
25
+ /** <html> attribute names the inline script set (empty when it set none). */
26
+ html: string[];
27
+ reordered: boolean;
28
+ /** True once the observer is disconnected. */
29
+ done: boolean;
30
+ /** Disconnect now — the bundle has taken over. */
31
+ stop(): void;
32
+ };
33
+ /** Contract version of the snippet inline pre-paint script — mirrored at runtime
34
+ * as `window.__sntPP.v`, and reported to /v1/decide as `pp` so the dashboard can
35
+ * tell a two-tag install from a three-tag one. The script is pasted into a site
36
+ * once and never floats, so v1 must stay supported by the bundle indefinitely. */
37
+ declare const SNIPPET_PREPAINT_VERSION = 1;
38
+ /**
39
+ * Snippet-install inline pre-paint script (v1).
40
+ *
41
+ * The snippet loader is `defer`, so the bundle's snapshot pass is pre-*decide*
42
+ * but not necessarily pre-*paint*: on a return visit a page can show its natural
43
+ * section order and baseline dims and then restamp. This script closes that gap
44
+ * with zero network — it reads the snapshot the visitor's own prior visit wrote
45
+ * and applies the reversible subset (persona attributes, slot attributes, the
46
+ * cached section order) as the parser inserts the elements, before they paint.
47
+ * It is a CONSTANT — it reads `window.sentient` at runtime instead of baking the
48
+ * key in, so the dashboard install page, the README and the Shopify Liquid embed
49
+ * all inline the same bytes and a test can pin them.
50
+ *
51
+ * Safety properties (pinned by tests):
52
+ * - No interpolation at all, so nothing a hostile config value could reach.
53
+ * - Built by string concatenation and contains no backticks, so the output
54
+ * survives being embedded in template-literal-based renderers.
55
+ * - Contains no `<` whatsoever (comparisons are written with `>` / `~indexOf`),
56
+ * so it cannot terminate the inline `<script>` in any parser state.
57
+ * - Every path is inside one try/catch: any error leaves the DOM alone, and the
58
+ * bundle's authoritative pass corrects anything this got wrong (see the
59
+ * `__sntPP` reconcile in index.ts).
60
+ *
61
+ * What it deliberately does NOT do: no `textContent`, no ops stylesheet, no
62
+ * `moveBefore`/`moveAfter`, no Composition-Block rendering, and no cloak of any
63
+ * kind. Those either need the decide response to be trustworthy or need the
64
+ * renderer that lives in the bundle.
65
+ */
66
+ declare function renderSnippetPrePaintScript(): string;
67
+
68
+ export { type PrePaintRecord, SNIPPET_PREPAINT_VERSION, renderSnippetPrePaintScript };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The snippet install's inline pre-paint script — the middle tag of the
3
+ * three-tag install, and the only SentientUI code that runs before the page
4
+ * paints on a return visit.
5
+ *
6
+ * It lives here rather than in @sentientui/core because it is an artefact of the
7
+ * SNIPPET install specifically: it reads `window.sentient`, it hands off to this
8
+ * bundle through `window.__sntPP`, and its contract version is this package's to
9
+ * keep. Core owns the snapshot format it reads; nothing else is shared.
10
+ *
11
+ * Design: docs/superpowers/specs/2026-09-07-snippet-prepaint-script-design.md
12
+ */
13
+ /**
14
+ * What the inline pre-paint script leaves behind for the bundle. The bundle must
15
+ * tolerate this being absent (a two-tag install), a HIGHER `v` (a newer inline
16
+ * pasted before the bundle updated — read only the fields you know), and
17
+ * malformed (treat as absent).
18
+ */
19
+ type PrePaintRecord = {
20
+ v: number;
21
+ /** Date.now() when the inline script ran. */
22
+ at: number;
23
+ /** [element, attribute, value before we stamped it] — null means "absent". */
24
+ stamped: Array<[Element, string, string | null]>;
25
+ /** <html> attribute names the inline script set (empty when it set none). */
26
+ html: string[];
27
+ reordered: boolean;
28
+ /** True once the observer is disconnected. */
29
+ done: boolean;
30
+ /** Disconnect now — the bundle has taken over. */
31
+ stop(): void;
32
+ };
33
+ /** Contract version of the snippet inline pre-paint script — mirrored at runtime
34
+ * as `window.__sntPP.v`, and reported to /v1/decide as `pp` so the dashboard can
35
+ * tell a two-tag install from a three-tag one. The script is pasted into a site
36
+ * once and never floats, so v1 must stay supported by the bundle indefinitely. */
37
+ declare const SNIPPET_PREPAINT_VERSION = 1;
38
+ /**
39
+ * Snippet-install inline pre-paint script (v1).
40
+ *
41
+ * The snippet loader is `defer`, so the bundle's snapshot pass is pre-*decide*
42
+ * but not necessarily pre-*paint*: on a return visit a page can show its natural
43
+ * section order and baseline dims and then restamp. This script closes that gap
44
+ * with zero network — it reads the snapshot the visitor's own prior visit wrote
45
+ * and applies the reversible subset (persona attributes, slot attributes, the
46
+ * cached section order) as the parser inserts the elements, before they paint.
47
+ * It is a CONSTANT — it reads `window.sentient` at runtime instead of baking the
48
+ * key in, so the dashboard install page, the README and the Shopify Liquid embed
49
+ * all inline the same bytes and a test can pin them.
50
+ *
51
+ * Safety properties (pinned by tests):
52
+ * - No interpolation at all, so nothing a hostile config value could reach.
53
+ * - Built by string concatenation and contains no backticks, so the output
54
+ * survives being embedded in template-literal-based renderers.
55
+ * - Contains no `<` whatsoever (comparisons are written with `>` / `~indexOf`),
56
+ * so it cannot terminate the inline `<script>` in any parser state.
57
+ * - Every path is inside one try/catch: any error leaves the DOM alone, and the
58
+ * bundle's authoritative pass corrects anything this got wrong (see the
59
+ * `__sntPP` reconcile in index.ts).
60
+ *
61
+ * What it deliberately does NOT do: no `textContent`, no ops stylesheet, no
62
+ * `moveBefore`/`moveAfter`, no Composition-Block rendering, and no cloak of any
63
+ * kind. Those either need the decide response to be trustworthy or need the
64
+ * renderer that lives in the bundle.
65
+ */
66
+ declare function renderSnippetPrePaintScript(): string;
67
+
68
+ export { type PrePaintRecord, SNIPPET_PREPAINT_VERSION, renderSnippetPrePaintScript };
@@ -0,0 +1,9 @@
1
+ // src/prepaint-script.ts
2
+ var SNIPPET_PREPAINT_VERSION = 1;
3
+ function renderSnippetPrePaintScript() {
4
+ return `(function(){try{var W=window,D=document,N=navigator,L=W.location,c=W.sentient,n=Date.now();if(!c||typeof c.apiKey!="string"||c.consent===!1||W.__sntPP)return;if(N.doNotTrack=="1"||N.globalPrivacyControl||N.webdriver)return;if(/[?&]sentient_(editor|preview|persona)=/.test(L.search))return;var s=JSON.parse(localStorage.getItem("_snt_snap:"+c.apiKey)),S=s.slots;if(s.v!==1||typeof s.persona!="string"||typeof s.band!="string"||!S||typeof S!="object"||!(2592e6>n-s.savedAt))return;var H=["data-sentient-persona","data-sentient-confidence"],d=D.documentElement,P=W.__sntPP={v:1,at:n,stamped:[],html:[],reordered:!1,done:!1,stop:function(){X()}},b=P.stamped,p=[],i,k,t,e,l,m,x,V=c.sections,O=s.layoutOrder,q=!(V&&V.length>1&&O&&O.length==V.length);if(c.personaAttributes&&!d.hasAttribute(H[0])){d.setAttribute(H[0],s.persona);d.setAttribute(H[1],s.band);P.html=H}var Q=function(v){return(""+v).replace(/["\\\\]/g,"\\\\$&")},A=function(t,v,g){if(typeof v=="string"){if(!g||(g.arms||[]).indexOf(v)>-1)p.push([t,"data-sentient-arm",v])}else if(v)for(k in v)if(!g||((g.dims||{})[k]||[]).indexOf(v[k])>-1)p.push([t,"data-"+k,v[k]])},U=function(t){var a=t[3];if(!a)return;a[2]==null?a[0].removeAttribute(a[1]):a[0].setAttribute(a[1],a[2]);x=b.indexOf(a);if(x>-1)b.splice(x,1);t[3]=0},R=function(){var g={},f=[],y,z,a,n=0;for(i in V){try{y=D.querySelectorAll(V[i])}catch(_){return 1}if(y.length==1){g[V[i]]=y[0];n++}}if(n!=V.length)return 0;for(i in O){z=g[O[i]];if(!z||~f.indexOf(z))return 1;f.push(z)}a=f[0].parentNode;if(!a)return 1;for(i in f)if(f[i].parentNode!=a)return 1;y=f.slice().sort(function(u,v){return u.compareDocumentPosition(v)&4?-1:1});for(i=0;i in f;i++){z=f[i];if(y[i]!=z){a.insertBefore(z,y[i]);y.splice(y.indexOf(z),1);y.splice(i,0,z)}}P.reordered=!0;return 1},F=function(){if(P.done)return;for(i=0;i in p;i++){t=p[i];if(!t)continue;try{m=D.querySelectorAll(t[0])}catch(_){p[i]=0;continue}if(m.length>1){U(t);p[i]=0}else if(m.length==1&&(!t[3]||t[3][0]!=m[0])){U(t);e=m[0];t[3]=[e,t[1],e.getAttribute(t[1])];e.setAttribute(t[1],t[2]);b.push(t[3])}}if(!q)q=R()},X=function(){if(P.done)return;P.done=!0;try{o.disconnect()}catch(_){}clearTimeout(T)},G=c.slots,C=s.slotConfig;for(i in G)if(G[i]&&G[i].target)A(G[i].target,S[i],G[i]);for(i in C){e=C[i]||{};l=e.locator;t=e.target;if(l){if(l.urlMatch&&!~L.pathname.indexOf(l.urlMatch))continue;t=l.id?'[id="'+Q(l.id)+'"]':l.dataAttr&&/^[\\w-]+$/.test(l.dataAttr.name)?"["+l.dataAttr.name+'="'+Q(l.dataAttr.value)+'"]':l.selector}if(t)A(t,S[i])}var o=new MutationObserver(F),T=setTimeout(X,3e3);o.observe(d,{childList:!0,subtree:!0});D.addEventListener("DOMContentLoaded",function(){F();X()});F();}catch(_){}})();`;
5
+ }
6
+ export {
7
+ SNIPPET_PREPAINT_VERSION,
8
+ renderSnippetPrePaintScript
9
+ };
@@ -1,2 +1,2 @@
1
- "use strict";var SentientSnippet=(()=>{var Fe=Object.defineProperty;var or=Object.getOwnPropertyDescriptor;var ir=Object.getOwnPropertyNames,Pt=Object.getOwnPropertySymbols;var Mt=Object.prototype.hasOwnProperty,sr=Object.prototype.propertyIsEnumerable;var Dt=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Q=(e,t)=>{for(var n in t||(t={}))Mt.call(t,n)&&Dt(e,n,t[n]);if(Pt)for(var n of Pt(t))sr.call(t,n)&&Dt(e,n,t[n]);return e};var Bt=(e,t)=>()=>(e&&(t=e(e=0)),t);var Nt=(e,t)=>{for(var n in t)Fe(e,n,{get:t[n],enumerable:!0})},ar=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ir(t))!Mt.call(e,o)&&o!==n&&Fe(e,o,{get:()=>t[o],enumerable:!(r=or(t,o))||r.enumerable});return e};var lr=e=>ar(Fe({},"__esModule",{value:!0}),e);var cr,ur,dr,$t,fr,pr,Kt,_,be,Te=Bt(()=>{"use strict";cr=Object.defineProperty,ur=Object.defineProperties,dr=Object.getOwnPropertyDescriptors,$t=Object.getOwnPropertySymbols,fr=Object.prototype.hasOwnProperty,pr=Object.prototype.propertyIsEnumerable,Kt=(e,t,n)=>t in e?cr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_=(e,t)=>{for(var n in t||(t={}))fr.call(t,n)&&Kt(e,n,t[n]);if($t)for(var n of $t(t))pr.call(t,n)&&Kt(e,n,t[n]);return e},be=(e,t)=>ur(e,dr(t))});var Xt={};Nt(Xt,{LOCAL_ENGINE_AVAILABLE:()=>wr,createLocalEngine:()=>Sr});function Sr(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var wr,Zt=Bt(()=>{"use strict";wr=!1});var Mo={};Nt(Mo,{applyPersonaAttributes:()=>rt,applyRegistrySlots:()=>st,applySlotArms:()=>it,applySlotAttributes:()=>ot,parseEditorToken:()=>Qn,parsePersonaPreview:()=>nr,parsePreview:()=>tr,parseSnippetConfig:()=>Qe,reapply:()=>Lt,run:()=>rr,version:()=>ze});Te();var gr=["buyer","researcher","deal_seeker","browser"];var mr={buyer:"Buyer",researcher:"Researcher",deal_seeker:"Deal seeker",browser:"Browser",unknown:"Unknown"};function We(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function jt(e){if(e.length===0)return null;let t={};for(let n of e.split("|")){let r=n.indexOf("=");if(r<=0||r!==n.lastIndexOf("=")||r===n.length-1)return null;let o=n.slice(0,r);if(o in t)return null;t[o]=n.slice(r+1)}return t}function pt(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 We(e.baseline);if(typeof e.baseline=="string")return e.baseline;let o={};for(let[l,i]of Object.entries((n=e.dims)!=null?n:{}))o[l]=(r=i[0])!=null?r:"";return We(o)}function Gt(e,t){var n,r;return e.dims!=null?(r=(n=jt(t))!=null?n:jt(pt(e)))!=null?r:{}:t}function Ut(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t}function we(e){return e>=.3?e<.7?"medium":"high":"low"}var $o=gr.map(e=>({key:e,displayName:mr[e]}));function He(e){return e?`_${e.slice(0,12)}`:""}var hr="_snt_uid";function zt(e){return`${hr}${He(e)}`}var yr=["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 qt(e){return vr(e)!==null}function vr(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=yr.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function Ft(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 Wt(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(o){}let r=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(n){return"direct"}}function Ht(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}var br=["gclid","gbraid","wbraid","fbclid","ttclid","msclkid","twclid","li_fat_id"];function Vt(e){let t={},n={};try{let r=typeof e=="string"||e instanceof URLSearchParams?new URLSearchParams(e):Object.entries(e).flatMap(([o,l])=>{let i=Array.isArray(l)?l[0]:l;return i===void 0?[]:[[o,i]]});for(let[o,l]of r)o.startsWith("utm_")?o in t||(t[o]=l):br.includes(o)&&(o in n||(n[o]=l))}catch(r){}return{utmParams:t,clickIds:n}}function Jt(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function gt(e){return _(_(_({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 mt(e){let t=gt(e);return Gt(t,pt(t))}function Yt(e){return typeof e=="string"?e:We(e)}Te();function rn(){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)})}var Ar="_snt_uid",xr=365,Ve="_snt_uid";function kr(){return rn()}function Qt(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function Er(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function ht(e){try{return localStorage.getItem(e)}catch(t){return null}}function en(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 Cr(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function _r(e){try{sessionStorage.removeItem(e)}catch(t){}}function Ir(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 Or(e){try{localStorage.removeItem(e)}catch(t){}}function Lr(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var Tr={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function on(e){var t,n,r,o,l,i,s;if(typeof window=="undefined")return Tr;let c=He(e==null?void 0:e.apiKey),u=(t=e==null?void 0:e.cookieName)!=null?t:zt(e==null?void 0:e.apiKey),a=`${Ve}${c}`,d=`${Ve}_tomb${c}`,g=((n=e==null?void 0:e.cookieTTLDays)!=null?n:xr)*24*60*60,m=w=>w&&w.length>0?w:null,p=()=>{var w,I;return c&&!(e!=null&&e.cookieName)&&ht(d)===null?(I=(w=m(Qt(Ar)))!=null?w:m(ht(Ve)))!=null?I:m(tn(Ve)):null},f=(s=(i=(l=(o=(r=m(Qt(u)))!=null?r:m(ht(a)))!=null?o:m(tn(a)))!=null?l:p())!=null?i:m(e==null?void 0:e.ssrSessionId))!=null?s:kr();Er(u,f,g);let A=en(a,f),C=Ir(u),L=A?!1:Cr(a,f),y=!A&&!C&&!L;return{getSessionId:()=>f,isEphemeral:()=>y,destroy:()=>{f=null,Lr(u),Or(a),_r(a),c&&!(e!=null&&e.cookieName)&&en(d,"1")}}}function Pe(e){return Math.min(6e4,1e3*2**Math.min(e,6))}function wt(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 sn(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 Ee(e,t,n){try{let r=(()=>{try{let l=localStorage.getItem(n);if(!l)return[];let i=JSON.parse(l);return Array.isArray(i)?i:[]}catch(l){return[]}})(),o=new Map;for(let l of r)o.set(l.id,l);for(let l of e)o.set(l.id,l);localStorage.setItem(n,JSON.stringify([...o.values()].slice(-t)))}catch(r){}}function an(e,t){try{let n=localStorage.getItem(t);if(!n)return;let r=JSON.parse(n);if(!Array.isArray(r))return;let o=new Set(e),l=r.filter(i=>!o.has(i.id));if(l.length===r.length)return;l.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(l))}catch(n){}}var Rr=500,Pr=56*1024;function ln(e){return`_snt_retry_${e.slice(0,12)}`}var Dr={push:()=>{},flush:()=>{},destroy:()=>{}};function Mr(e){var t,n,r;if(typeof window=="undefined")return Dr;let o=(t=e.flushIntervalMs)!=null?t:5e3,l=(n=e.maxBatchSize)!=null?n:20,i=(r=e.maxRetrySize)!=null?r:100,s=e.ingestUrl,c=e.apiKey,u=ln(c),a=[],d=new Set,g=[],m=v=>{for(let b of v)p.delete(b),!d.has(b)&&(d.add(b),g.push(b));for(;g.length>Rr;){let b=g.shift();b&&d.delete(b)}an(v,u)},p=new Set,f=()=>{for(;a.length>i;){let v=a.shift();v&&p.delete(v.id)}},A=v=>{d.has(v.id)||p.has(v.id)||(p.add(v.id),a.push(v),f())},C=v=>{for(let b of v)d.has(b.id)||(p.add(b.id),a.push(b));f()},L=sn(u,i);for(let v of L)A(v);let y=0,w=0,I=(v,b=!0)=>{if(v.length===0)return;let k=JSON.stringify(v),O=v.map(V=>V.id),E;try{E=fetch(s,{method:"POST",keepalive:!0,body:k,headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`}})}catch(V){Ee(v,i,u),C(v),w++,y=Date.now()+Pe(w);return}let oe=V=>{if(wt(V)!=="retry"){if(!V.ok&&b){let te=v.filter(ne=>ne.eventType!=="pageview");if(te.length>0&&te.length<v.length){m(v.filter(ne=>ne.eventType==="pageview").map(ne=>ne.id)),I(te,!1);return}}m(O),w=0,y=0;return}Ee(v,i,u),C(v),w++,y=Date.now()+Pe(w)};E instanceof Promise?E.then(oe).catch(()=>{Ee(v,i,u),C(v),w++,y=Date.now()+Pe(w)}):oe(E)},N=typeof TextEncoder!="undefined"?new TextEncoder:null,x=v=>N?N.encode(v).length:v.length,D=v=>{let b=[],k=2;for(let O of v){let E=x(JSON.stringify(O))+1;if(b.length>0&&k+E>Pr||b.length>=l)break;b.push(O),k+=E}return b},K=()=>{try{if(Date.now()<y)return;for(;a.length>0&&!(Date.now()<y);){let v=a.filter(k=>!d.has(k.id));if(a.length=0,v.length===0)break;let b=D(v);if(b.length===0)break;b.length<v.length&&a.push(...v.slice(b.length)),I(b)}}catch(v){}},j=!0,Z=null;Z=setInterval(()=>{j&&K()},o);let q=()=>{document.visibilityState==="hidden"&&K()},U=()=>{K()};return document.addEventListener("visibilitychange",q),window.addEventListener("pagehide",U),{push(v){A(v),a.length>=l&&K()},flush:K,destroy(){j=!1,Z!==null&&(clearInterval(Z),Z=null),document.removeEventListener("visibilitychange",q),window.removeEventListener("pagehide",U),K()}}}var Br=200;function cn(e){return`_snt_goal_retry_${e.slice(0,12)}`}var Nr={send:()=>{},flush:()=>{},destroy:()=>{}};function $r(e){var t,n,r;if(typeof window=="undefined")return Nr;let o=(t=e.flushIntervalMs)!=null?t:5e3,l=(n=e.maxRetrySize)!=null?n:100,i=(r=e.maxPerFlush)!=null?r:5,s=cn(e.apiKey),c=[],u=new Set,a=new Set,d=[],g=0,m=0,p=!1,f=x=>{for(u.delete(x.id),a.has(x.id)||(a.add(x.id),d.push(x.id));d.length>Br;){let D=d.shift();D&&a.delete(D)}an([x.id],s)},A=x=>{Ee([x],l,s),!a.has(x.id)&&!u.has(x.id)&&(u.add(x.id),c.push(x)),Date.now()>=g&&(m++,g=Date.now()+Pe(m))},C=x=>{let D;try{D=fetch(e.url,{method:"POST",keepalive:!0,body:x.body,headers:e.headers})}catch(j){A(x);return}let K=j=>{var Z;let q=wt(j);if(q==="retry"){A(x);return}q==="dropped"&&((Z=e.onDrop)==null||Z.call(e,x,j.status)),f(x),m=0,g=0};D instanceof Promise?D.then(K).catch(()=>A(x)):K(D)},L=()=>{try{if(p||Date.now()<g)return;let x=0;for(;c.length>0&&x<i&&!(Date.now()<g);){let D=c.shift();u.delete(D.id),!a.has(D.id)&&(x++,C(D))}}catch(x){}},y=sn(s,l);for(let x of y)u.has(x.id)||(u.add(x.id),c.push(x));y.length>0&&Ee(y,l,s);let w=setInterval(L,o),I=()=>{document.visibilityState==="hidden"&&L()},N=()=>L();return document.addEventListener("visibilitychange",I),window.addEventListener("pagehide",N),{send(x){if(!p&&!(a.has(x.id)||u.has(x.id))){if(Date.now()<g){Ee([x],l,s),u.add(x.id),c.push(x);return}C(x)}},flush:L,destroy(){clearInterval(w),document.removeEventListener("visibilitychange",I),window.removeEventListener("pagehide",N),L(),p=!0}}}var Kr=1800*1e3;function Je(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function jr(e=Kr,t){let n=new Map,r=`_snt_asgn${He(t)}_`,o=(c,u)=>`${r}${encodeURIComponent(c)}:${encodeURIComponent(u)}`,l=c=>{let u=c.slice(r.length),a=u.indexOf(":");if(a<0)return null;try{return{componentId:decodeURIComponent(u.slice(0,a)),segment:decodeURIComponent(u.slice(a+1))}}catch(d){return null}},i=()=>{try{let c=[];for(let u=0;u<localStorage.length;u++){let a=localStorage.key(u);a!=null&&a.startsWith(r)&&c.push(a)}return c}catch(c){return[]}},s=c=>c.assignedAt+(c.ttlMs&&c.ttlMs>0?c.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let c of i())try{let u=localStorage.getItem(c);if(!u)continue;let a=JSON.parse(u);if(s(a)){localStorage.removeItem(c);continue}let d=l(c);if(!d)continue;n.set(Je(d.componentId,d.segment),a)}catch(u){}})(),{get(c,u){let a=n.get(Je(c,u));return a?s(a)?(n.delete(Je(c,u)),null):a:null},set(c,u,a){let d=Je(c,u);n.set(d,a);try{localStorage.setItem(o(c,u),JSON.stringify(a))}catch(g){}},clear(){n.clear();for(let c of i())try{localStorage.removeItem(c)}catch(u){}}}}var Ze="_snt_snap:",Gr=["low","medium","high"];function De(e){try{let t=localStorage.getItem(Ze+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"||!Gr.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 Me(e,t){try{localStorage.setItem(Ze+e,JSON.stringify(t))}catch(n){}}var vt="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",un="[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.",nn=!1,Ye=!1;function Ur(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function zr(e){var t;let n=on({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),r=(t=n.getSessionId())!=null?t:"local",o=Ur(),l=Promise.resolve().then(()=>(Zt(),Xt)).then(a=>{let d=a;return d.LOCAL_ENGINE_AVAILABLE?(nn||(nn=!0,console.info(un)),d):(Ye||(Ye=!0,console.error(vt)),null)}).catch(()=>(Ye||(Ye=!0,console.error(vt)),null)),i=null,s={low:.15,medium:.5,high:.85},c=(()=>{var a;if(e.initialPersona)return _({},e.initialPersona);let d=De(e.apiKey||"local");return d?{persona:d.persona,confidence:(a=s[d.band])!=null?a:.15}:null})();function u(a){let d=document.documentElement;d.dataset.sentientPersona===void 0&&(d.dataset.sentientPersona=a.persona,d.dataset.sentientConfidence=we(a.confidence))}return{isLocal:!0,async decide(a){var d,g,m;let p=await l;if(!p)return null;let f=p.createLocalEngine({sessionId:r,forcedPersona:o}).decide(a);return i=be(_({},f),{layoutOrder:(g=(d=f.layoutOrder)!=null?d:i==null?void 0:i.layoutOrder)!=null?g:null,slots:_(_({},(m=i==null?void 0:i.slots)!=null?m:{}),f.slots)}),Me(e.apiKey||"local",{v:1,persona:i.persona,band:we(i.confidence),slots:i.slots,layoutOrder:i.layoutOrder,savedAt:Date.now()}),u(f),f},getSlotResult(a){var d,g,m;return(m=(g=i==null?void 0:i.slots[a])!=null?g:(d=e.initialSlots)==null?void 0:d[a])!=null?m:null},getPersona(){let a=i!=null?i:c;return a?{persona:a.persona,confidence:a.confidence,band:we(a.confidence)}:null},async assign(a,d){var g;let m=await l;return!m||!d||d.length===0?d!=null&&d[0]?{variantId:d[0],assignmentTtlMs:0}:null:{variantId:(g=m.createLocalEngine({sessionId:r,forcedPersona:o}).decide({components:[{id:a,variantIds:d}]}).assignments[a])!=null?g:d[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function Be(e,t,n,r){let o=[];{let l=!1,i=[],s=()=>{if(l)return;let c=Date.now();for(i.push(c);i.length>0&&c-i[0]>500;)i.shift();i.length>=3&&(l=!0,e("rage_click"))};t.addEventListener("click",s),o.push(()=>t.removeEventListener("click",s))}{let l=!1,i=s=>{if(l||!(s.target instanceof Node)||!t.contains(s.target)&&t!==s.target)return;l=!0;let c=typeof window!="undefined"?window.getSelection():null,u=c?c.toString().length:0;e("text_copy",{selectionLength:u})};document.addEventListener("copy",i),o.push(()=>document.removeEventListener("copy",i))}{let l=!1,i=!1,s=null,c=()=>{s!==null&&(clearTimeout(s),s=null)},u=()=>{l||!i||(c(),s=setTimeout(()=>{!l&&i&&(l=!0,e("scroll_hesitation"))},3e3))},a=()=>{c(),u()},d=m=>{for(let p of m)i=p.intersectionRatio>.3,i?u():c()},g=new IntersectionObserver(d,{threshold:[.3]});g.observe(t),window.addEventListener("scroll",a,{passive:!0}),o.push(()=>{g.disconnect(),window.removeEventListener("scroll",a),c()})}if((r==null?void 0:r.tabLoss)!==!1){let l=!1,i=n!=null?n:Date.now(),s=()=>{if(l||document.visibilityState!=="hidden")return;let c=Date.now()-i;c<15e3&&(l=!0,e("tab_loss",{timeOnPage:c}))};document.addEventListener("visibilitychange",s),o.push(()=>document.removeEventListener("visibilitychange",s))}return()=>{for(let l of o)l()}}var dn="https://api.sentient-ui.com/v1/events",re=new Map,fn=null;function qr(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}var Fr=3;function yt(){return rn()}function Xe(){var e;if(typeof window!="undefined")return((e=window.location)==null?void 0:e.pathname)||void 0}function Wr(){let e=new WeakMap,t=new Map,n=!1,r=(s,c,u)=>{let a=s.get(c);return u===null?a?!0:(s.set(c,new Set),!1):a?a.has(u)?!0:(a.add(u),!1):(s.set(c,new Set([u])),!1)},o=typeof window!="undefined"&&"event"in window,l=()=>{if(!o)return;let s=window.event;return typeof Event=="function"&&s instanceof Event?s:void 0},i=()=>{if(o){Promise.resolve().then(()=>{n=!1,t.clear()});return}let s=!1,c=()=>{s||(s=!0,n=!1,t.clear())};if(setTimeout(c,0),typeof MessageChannel=="function"){let u=new MessageChannel;u.port1.onmessage=()=>{u.port1.close(),u.port2.close(),c()},u.port2.postMessage(0)}};return{firedBefore(s,c){let u=l();if(u){let d=e.get(u);return d||(d=new Map,e.set(u,d)),r(d,s,c)}let a=r(t,s,c);return!a&&!n&&(n=!0,i()),a}}}var pn=new Set;function Hr(e,t,n){let r=typeof window=="undefined"?null:window.history;if(!r)return()=>{};let o=!1,l,i=()=>{if(o)return;let u=Xe();!u||u===l||(l=u,e.track({projectId:t,componentId:"__page__",eventType:"pageview",payload:{}}),n(`${t}:${u}`))},s=[];for(let u of["pushState","replaceState"]){let a=r[u],d=function(...g){let m=a.apply(this,g);return i(),m};r[u]=d,s.push([u,a,d])}window.addEventListener("popstate",i);let c=Xe();return c&&pn.has(`${t}:${c}`)?l=c:i(),()=>{if(!o){o=!0,window.removeEventListener("popstate",i);for(let[u,a,d]of s)r[u]===d&&(r[u]=a)}}}var Re={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 Vr(){try{return Vt(window.location.search)}catch(e){return{utmParams:{},clickIds:{}}}}function gn(e){return e.replace(/\/events\/?$/,"")}function Se(){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 St(e){var t;if(typeof window=="undefined")return;let n=e!=null?e:fn;if(!n){console.warn("[sentient] grantConsent() called before init()");return}let r=re.get(n);if(!r){console.warn("[sentient] grantConsent() called before init()");return}let{config:o,upgrade:l,reinit:i}=r;if(!l){r.upgradeBlockedReason&&console.warn(r.upgradeBlockedReason);return}if(o.respectDoNotTrack!==!1&&Se())return;let s=(i!=null?i:Ne)(be(_({},o),{consent:!0}));l(s);let c=(t=re.get(n))==null?void 0:t.dispose;re.set(n,{config:be(_({},o),{consent:!0}),upgrade:null,dispose:c})}function Jr(e){var t;let n=e.preConsentBehavior==="statistical_winner",r=gn((t=e.ingestUrl)!=null?t:dn),o={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},l=new Map,i=new Map,s={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),assign(a,d,g){if(!n)return Promise.resolve(null);let m=l.get(a);return m?Promise.resolve(m):bt(i,a,async()=>{try{let p=new URLSearchParams({componentId:a});for(let C of d!=null?d:[])p.append("variantIds[]",C);let f=await fetch(`${r}/winner?${p.toString()}`,{headers:o});if(!f.ok)return d!=null&&d[0]?{variantId:d[0],assignmentTtlMs:0}:null;let A={variantId:(await f.json()).variantId,assignmentTtlMs:0};return l.set(a,A),A}catch(p){return d!=null&&d[0]?{variantId:d[0],assignmentTtlMs:0}:null}})},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},c={track:a=>s.track(a),goal:((a,d,g,m)=>s.goal(a,d,g,m)),componentGoal:(a,d,g)=>s.componentGoal(a,d,g),identify:a=>s.identify(a),getAssignment:(a,d)=>s.getAssignment(a,d),assign:(a,d,g,m)=>s.assign(a,d,g,m),decide:a=>s.decide(a),getSlotResult:a=>s.getSlotResult(a),getPersona:()=>s.getPersona(),fetchWeights:()=>s.fetchWeights(),getGraph:()=>s.getGraph(),dispose:()=>s.dispose(),destroy:()=>s.destroy()};function u(a){s=a}return{proxy:c,setInner:u}}function bt(e,t,n){let r=e.get(t);if(r)return r;let o=(async()=>{try{return await n()}finally{e.delete(t)}})();return e.set(t,o),o}function Ne(e){var t,n,r,o,l,i,s,c,u;if(typeof window=="undefined")return Re;fn=e.apiKey||"local";let a=re.get(e.apiKey||"local");if(a!=null&&a.dispose)try{a.dispose()}catch(h){}let d=e.respectDoNotTrack!==!1&&Se(),g=e.consent===!1||d,m=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!m&&e.localMode!==!1)return re.set(e.apiKey||"local",{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): this client is keyless/local \u2014 there is no hosted client to upgrade to. Configure a pk_ API key to enable tracking."}),g?Re:zr(e);if(g){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."),re.set(e.apiKey||"local",{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): the client was initialized with an invalid apiKey (expected a pk_ public key) \u2014 consent cannot enable tracking."}),Re;let{proxy:h,setInner:S}=Jr(e);return re.set(e.apiKey,{config:e,upgrade:d?null:S}),h}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."),Re;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),Re;let p=(t=e.ingestUrl)!=null?t:dn,f=Date.now(),A=on({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),C=jr(void 0,e.apiKey),L=Mr({ingestUrl:p,apiKey:e.apiKey}),y=gn(p),w={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},I=new Set,N=$r({url:`${y}/goals`,apiKey:e.apiKey,headers:w,onDrop:(h,S)=>{if(!e.debug){if(I.has(S))return;I.add(S)}console.warn(`[sentient] goal dropped (HTTP ${S}) \u2014 this will not be retried. `+(S===400?"The session was not found: call init() and let the session upsert complete before firing goals.":S===401||S===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),h)}}),x=Ft((n=navigator.userAgent)!=null?n:""),D=window.location.origin,K=Wt((r=document.referrer)!=null?r:"",D),j=(o=e.sessionSegment)!=null?o:`${x}:${K}`,Z=new Map,q=new Map,U=new Map,v=null,b=h=>{for(let S of h)U.has(S.id)||U.set(S.id,mt(S))};if(e.initialSlots)for(let[h,S]of Object.entries(e.initialSlots))U.set(h,S);let k=De(e.apiKey);if(k)for(let[h,S]of Object.entries(k.slots))U.has(h)||U.set(h,S);let O={low:.15,medium:.5,high:.85};if(e.initialPersona)v=_({},e.initialPersona);else{let h=document.documentElement.dataset;h.sentientPersona?v={persona:h.sentientPersona,confidence:(i=O[(l=h.sentientConfidence)!=null?l:"low"])!=null?i:.15}:k&&(v={persona:k.persona,confidence:(s=O[k.band])!=null?s:.15})}if(e.initialAssignments)for(let[h,S]of Object.entries(e.initialAssignments))C.set(h,j,{variantId:S,assignedAt:Date.now(),segment:j,confidence:1});let E=Promise.resolve(),oe=A.getSessionId();if(oe){let h=Ht((c=document.referrer)!=null?c:""),{utmParams:S,clickIds:M}=Vr(),ee=_(_(_(_({sessionId:oe,deviceClass:x,trafficSource:K,referrerDomain:h,utmParams:S,clickIds:M,timeOfDay:Jt(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:A.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||qt((u=navigator.userAgent)!=null?u:"")},e.userId?{userId:e.userId}:{}),e.persona?{persona:e.persona}:{}),e.country?{country:e.country}:{}),e.sdk?{sdk:e.sdk.name,sdkVersion:e.sdk.version}:{}),F=async()=>{for(let T=0;;T++){try{let B=await fetch(`${y}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(ee),headers:w});if(B.status===402){console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing");return}if(B.ok||wt(B)==="dropped")return}catch(B){}if(T>=Fr){console.warn("[SentientUI] Could not register the session after retries. Conversions in this visit may not be recorded.");return}await new Promise(B=>setTimeout(B,Pe(T+1)))}};try{E=F()}catch(T){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:L});let V=Wr(),te=null,ne=!1,ie={goal(h,S={},M=1,ee=0){var F,T,B,J,Y,ve,fe;let Oe=A.getSessionId();if(!Oe)return;let X=qr(S)?S:{metadata:S},Le=[h,(F=X.externalId)!=null?F:"",(T=X.stepIndex)!=null?T:ee,(B=X.weight)!=null?B:M].join("\0"),R=X.value!==void 0?`${X.value}\0${(J=X.currency)!=null?J:""}`:null;if(V.firedBefore(Le,R)){e.debug&&console.log(`[sentient] goal("${h}") already recorded for this action \u2014 not sent twice`);return}let le=yt(),qe={sessionId:Oe,name:h,metadata:(Y=X.metadata)!=null?Y:{},weight:(ve=X.weight)!=null?ve:M,stepIndex:(fe=X.stepIndex)!=null?fe:ee,goalId:le,value:X.value,currency:X.currency,externalId:X.externalId};e.debug&&console.log("[sentient] goal",qe);let W={id:le,body:JSON.stringify(qe)};E.then(()=>N.send(W))},componentGoal(h,S,M){var ee,F,T;let B=A.getSessionId();if(!B)return;let J=C.get(h,j),Y=J?null:(ee=U.get(h))!=null?ee:null;if(!J&&Y===null){e.debug&&console.warn(`[sentient] componentGoal("${h}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let ve=J?J.variantId:Yt(Y),fe={id:yt(),sessionId:B,projectId:e.apiKey,componentId:h,variantId:ve,eventType:"goal_achieved",goalType:S,payload:_({reward:(F=M==null?void 0:M.reward)!=null?F:1,goalValue:M==null?void 0:M.value,currency:M==null?void 0:M.currency},(T=M==null?void 0:M.metadata)!=null?T:{}),timestamp:Date.now(),timeInSession:Date.now()-f,path:Xe()};e.debug&&console.log("[sentient] componentGoal",fe),E.then(()=>L.push(fe))},identify(h){let S=A.getSessionId();S&&E.then(()=>{fetch(`${y}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:S,userId:h,ephemeral:A.isEphemeral()}),headers:w}).catch(()=>{})})},track(h){let S=A.getSessionId();if(!S)return;let M=be(_({path:Xe()},h),{id:yt(),sessionId:S,timestamp:Date.now(),timeInSession:Date.now()-f});e.debug&&console.log("[sentient] track",M),E.then(()=>L.push(M))},getAssignment(h,S){return C.get(h,S)},async assign(h,S,M,ee){let F=A.getSessionId();if(!F)return null;let T=C.get(h,j);if(T&&(S!=null&&S.length||T.content!==void 0)){let B=T.ttlMs&&T.ttlMs>0?Math.max(0,T.assignedAt+T.ttlMs-Date.now()):0;return{variantId:T.variantId,assignmentTtlMs:B,content:T.content}}return bt(Z,h,async()=>{await E;try{let B={sessionId:F,componentId:h,variantIds:S};ee!==void 0?B.agentDataByVariant=ee:M!==void 0&&(B.agentData=M);let J=await fetch(`${y}/assign`,{method:"POST",body:JSON.stringify(B),headers:w});if(!J.ok)return null;let Y=await J.json();return C.set(h,j,_({variantId:Y.variantId,assignedAt:Date.now(),segment:j,confidence:1,content:Y.content},Y.assignmentTtlMs&&Y.assignmentTtlMs>0?{ttlMs:Y.assignmentTtlMs}:{})),Y}catch(B){return null}})},async decide(h){var S,M;let ee=A.getSessionId();if(!ee)return null;let F=(S=h.slots)!=null?S:[],T={sessionId:ee};h.sections&&h.sections.length>0&&(T.sections=h.sections.map(J=>({id:J}))),T.components=(M=h.components)!=null?M:[],F.length>0&&(T.slots=F.map(gt)),h.slotsFrom==="registry"&&(T.slotsFrom="registry"),h.v&&(T.v=h.v),e.persona&&(T.persona=e.persona);let B=JSON.stringify(T);return bt(q,B,async()=>{var J,Y,ve,fe,Oe,X;await E;try{let Le=await fetch(`${y}/decide`,{method:"POST",body:B,headers:w});if(!Le.ok)return b(F),null;let R=await Le.json(),le={};for(let W of F){let pe=(J=R.slots)==null?void 0:J[W.id];if(pe!==void 0){le[W.id]=pe,U.set(W.id,pe);continue}let Tt=U.get(W.id);if(Tt!==void 0)le[W.id]=Tt;else{let Rt=mt(W);le[W.id]=Rt,U.set(W.id,Rt)}}if(R.slots)for(let[W,pe]of Object.entries(R.slots))W in le||(le[W]=pe,U.set(W,pe));let qe=v!=null&&v.persona!=="unknown";R.persona&&!(R.persona==="unknown"&&qe)?v={persona:R.persona,confidence:(Y=R.confidence)!=null?Y:0}:v||(v={persona:"unknown",confidence:0});for(let[W,pe]of Object.entries((ve=R.assignments)!=null?ve:{}))C.set(W,j,{variantId:pe,assignedAt:Date.now(),segment:j,confidence:1});return Me(e.apiKey,_(_({v:1,persona:v.persona,band:we(v.confidence),slots:Object.fromEntries(U),layoutOrder:(fe=R.layoutOrder)!=null?fe:null,savedAt:Date.now()},R.slotConfig?{slotConfig:R.slotConfig}:{}),R.palette?{palette:R.palette}:{})),_(_(_(_({layoutOrder:(Oe=R.layoutOrder)!=null?Oe:null,assignments:(X=R.assignments)!=null?X:{},slots:le,persona:v.persona,confidence:v.confidence},R.slotConfig?{slotConfig:R.slotConfig}:{}),R.goals?{goals:R.goals}:{}),R.sectionMap?{sectionMap:R.sectionMap}:{}),R.palette?{palette:R.palette}:{})}catch(Le){return b(F),null}})},getSlotResult(h){var S;return(S=U.get(h))!=null?S:null},getPersona(){return v?{persona:v.persona,confidence:v.confidence,band:we(v.confidence)}:null},async fetchWeights(){var h;try{let S=await fetch(`${y}/weights`,{headers:w});return S.ok?(h=(await S.json()).components)!=null?h:[]:[]}catch(S){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var h;te==null||te(),ne=!0,L.destroy(),N.destroy(),((h=re.get(e.apiKey))==null?void 0:h.dispose)===ie.dispose&&re.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var h;te==null||te(),ne=!0,L.destroy(),N.destroy(),A.destroy(),C.clear(),((h=re.get(e.apiKey))==null?void 0:h.dispose)===ie.dispose&&re.delete(e.apiKey);try{localStorage.removeItem(Ze+e.apiKey),localStorage.removeItem(ln(e.apiKey)),localStorage.removeItem(cn(e.apiKey))}catch(S){}e.debug&&console.log("[sentient] destroyed")}};if(re.set(e.apiKey,{config:e,upgrade:null,dispose:ie.dispose}),te=Hr(ie,e.apiKey,h=>{E.then(()=>{ne||pn.add(h)})}),e.debug){let h=window;h.__sentient&&(h.__sentient.client=ie)}return ie}var Yr=["data-sentient-id","data-testid","data-test","data-id","data-name","data-cy"];function At(e){var t;return((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim()}function Xr(e){return{tag:e.tagName.toLowerCase(),text:At(e).slice(0,40)}}function mn(e){return e.replace(/["\\\]]/g,"\\$&")}function $e(e,t){try{return e.querySelectorAll(t).length===1}catch(n){return!1}}function hn(e,t){var n;let r=e.tagName.toLowerCase();if(!r)return null;let o=((n=e.getAttribute("class"))!=null?n:"").split(/\s+/).filter(s=>/^[a-zA-Z][\w-]*$/.test(s)),l=[r,...o.map(s=>`${r}.${s}`)];for(let s of l)if($e(t,s))return s;let i=e.parentElement;if(i&&i!==t){let s=hn(i,t);if(s){for(let d of l){let g=`${s} > ${d}`;if($e(t,g))return g}let c=Array.from(i.children).filter(d=>d.tagName.toLowerCase()===r),u=c.indexOf(e),a=c.some(d=>d!==e&&At(d)!==At(e));if(u>=0&&a){let d=`${s} > ${r}:nth-of-type(${u+1})`;if($e(t,d))return d}}}return null}function yn(e,t){let n=Xr(e),r=e.getAttribute("id");if(r&&$e(t,`#${mn(r)}`))return{v:1,id:r,fingerprint:n};for(let l of Yr){let i=e.getAttribute(l);if(i&&$e(t,`[${l}="${mn(i)}"]`))return{v:1,dataAttr:{name:l,value:i},fingerprint:n}}let o=hn(e,t);return o?{v:1,selector:o,fingerprint:n}:null}Te();var bn=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Zr={banner:"hero",navigation:"navigation",contentinfo:"footer"};function Qr(e){let t=e.ariaRole?Zr[e.ariaRole.toLowerCase()]:void 0;if(t)return t;if(e.tag==="nav")return"navigation";if(e.tag==="footer")return"footer";if(e.tag==="header")return e.actionCount>=5?"navigation":"hero";let n=`${e.idClass} ${e.headingText}`.toLowerCase();return/\b(navbar|nav-bar|navigation|site-nav|main-nav|topbar|footer)\b/.test(n)?/footer/.test(n)?"footer":"navigation":/\b(hero|masthead|jumbotron)\b/i.test(e.idClass)?"hero":null}function eo(e){return e.actionCount>=1&&e.textLength>0&&e.textLength<200?"cta":"generic"}var to=[["pricing",/\b(pricing|price list|per month|\/mo|subscriptions?)\b|\bplans?\b(?=[^.]{0,40}(from|start|month|year|[$€£]))/i],["faq",/\bfaq\b|frequently asked|common questions?/i],["comparison",/\b(compare|comparison|versus)\b|\bvs\./i],["social_proof",/\b(reviews?|ratings?|testimonial|brands?|galler(y|ies)|logos)\b|trusted by|loved by|case stud|what our customers say/i],["trust",/\b(insurance|warrant(y|ies)|guarantees?|certifi|accredit|security|privacy|compliance|gdpr|encrypt)\b|why choose|about us|our team/i],["cta",/\b(book|booking|reserve|appointments?|newsletter|subscribe)\b|contact us|get in touch|opening hours/i],["features",/\b(features?|benefits?|capabilit|services?|repairs?|menus?|products?)\b|how it works|our process|what we (do|offer)|what you get/i]],xt=[["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|free returns?|returns? within|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]],vn={navigation:"navigation",footer:"navigation",hero:"hero",cta:"cta",generic:"generic"};function no(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function wn(e){var t,n;let r=Qr(e);if(r)return{type:(t=vn[r])!=null?t:"generic",strength:"strong"};let o=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[i,s]of to)if(s.test(o))return{type:i,strength:"strong"};for(let[i,s]of xt)if(s.test(e.bodyText))return{type:i,strength:"strong"};let l=eo(e);return{type:(n=vn[l])!=null?n:"generic",strength:"weak"}}function Sn(e){var t,n;let r=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim(),o=e.getAttribute("role");return _({tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:no(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length},o?{ariaRole:o}:{})}Te();var ro="section, header, footer, nav, main > div, [data-sentient-section]",oo=2e4;function io(e){let t=Array.from(e.querySelectorAll(ro)),n=t.filter(r=>t.filter(o=>o!==r&&r.contains(o)).length<2);return n.filter(r=>!n.some(o=>o!==r&&o.contains(r)))}function so(e,t,n,r){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:r})}).catch(()=>{})}catch(o){}}var An=()=>{};function xn(e,t){var n,r,o,l,i,s,c,u,a,d,g,m;let p=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!p||typeof IntersectionObserver=="undefined"||Se()||!t.apiKey||!t.apiKey.startsWith("pk_"))return An;let f=((r=t.apiBase)!=null?r:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),A=io(p);if(A.length===0)return An;let C=new Map,L=[];for(let b of A){let k=b.getAttribute("data-sentient-type"),O=k&&bn.includes(k)?k:null,E=Sn(b),oe=(l=O!=null?O:(o=t.typeOf)==null?void 0:o.call(t,b))!=null?l:wn(E).type,V=yn(b,p),te=V?`nc-${oe}-${Ut(JSON.stringify({id:(i=V.id)!=null?i:null,dataAttr:(s=V.dataAttr)!=null?s:null,selector:(c=V.selector)!=null?c:null})).toString(36)}`:`nc-${oe}`;C.set(b,te);let ne=xt.filter(([,ie])=>ie.test(E.bodyText)).map(([ie])=>ie);L.push(be(_({componentId:te,semanticType:oe,source:O?"markup":"auto"},V?{locator:V}:{}),{observation:_(_({tag:E.tag,idClass:E.idClass.slice(0,200),headingText:E.headingText,textLength:E.textLength,actionCount:E.actionCount},E.ariaRole?{ariaRole:E.ariaRole}:{}),ne.length>0?{patternFlags:ne}:{})}))}let y=(g=(d=(a=(u=p.defaultView)!=null?u:typeof window!="undefined"?window:void 0)==null?void 0:a.location)==null?void 0:d.pathname)!=null?g:"/";so(t.apiKey,f,y,L);let w=new Map,I=b=>{let k=w.get(b);return k||(k={ms:0,scroll:0,enterAt:null,intersecting:!1},w.set(b,k)),k},N=new IntersectionObserver(b=>{for(let k of b){let O=C.get(k.target);if(!O)continue;let E=I(O);k.isIntersecting?(E.intersecting=!0,E.enterAt=Date.now(),k.intersectionRatio>E.scroll&&(E.scroll=k.intersectionRatio)):(E.intersecting=!1,E.enterAt!=null&&(E.ms+=Date.now()-E.enterAt,E.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let b of C.keys())N.observe(b);let x=()=>{let b=Date.now();for(let[k,O]of w)if(O.enterAt!=null&&(O.ms+=b-O.enterAt,O.enterAt=null),!(O.ms<=0)){try{e.track({projectId:t.apiKey,componentId:k,eventType:"dwell",payload:{dwell_time:Math.round(O.ms),scroll_depth:Number(O.scroll.toFixed(2))}})}catch(E){}O.ms=0}},D=()=>{if(p.hidden)x();else{let b=Date.now();for(let k of w.values())k.intersecting&&(k.enterAt=b)}},K=!1,j=b=>{if(x(),b!=null&&b.persisted){K=!0;return}try{N.disconnect()}catch(k){}},Z=b=>{if(!(b!=null&&b.persisted)||!K)return;K=!1;let k=Date.now();for(let O of w.values())O.enterAt=O.intersecting&&!p.hidden?k:null};p.addEventListener("visibilitychange",D);let q=(m=p.defaultView)!=null?m:typeof window!="undefined"?window:void 0;q==null||q.addEventListener("pagehide",j),q==null||q.addEventListener("pageshow",Z);let U=setInterval(()=>{if(p.hidden||K)return;x();let b=Date.now();for(let k of w.values())k.intersecting&&(k.enterAt=b)},oo),v=[];return t.microSignals&&[...C.entries()].forEach(([b,k],O)=>{v.push(Be((E,oe={})=>{try{e.track({projectId:t.apiKey,componentId:k,eventType:"micro_signal",payload:_({signalType:E},oe)})}catch(V){}},b,void 0,{tabLoss:O===0}))}),()=>{x(),clearInterval(U),p.removeEventListener("visibilitychange",D),q==null||q.removeEventListener("pagehide",j),q==null||q.removeEventListener("pageshow",Z);for(let b of v)b();try{N.disconnect()}catch(b){}}}var ao=["landing","ecommerce","saas","marketplace"];function lo(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t=Object.entries(e);if(t.length<1||t.length>4)return null;let n={};for(let[r,o]of t){if(!Array.isArray(o)||o.length<2||o.length>6||!o.every(l=>typeof l=="string"))return null;n[r]=o}return n}function co(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function uo(e){try{return e()}catch(t){return}}function Qe(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=ao.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[i,s]of Object.entries(t.slots)){if(typeof s!="object"||s===null)continue;let c=s,u=lo(c.dims);if(!u||c.target!==void 0&&typeof c.target!="string")continue;let a=c.arms!==void 0?co(c.arms):null,d={dims:u};typeof c.target=="string"&&(d.target=c.target),a&&(d.arms=a),r[i]=d}let o={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};typeof t.consent=="boolean"&&(o.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(o.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(o.debug=!0),typeof t.registry=="boolean"&&(o.registry=t.registry),typeof t.editorSrc=="string"&&(o.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(o.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(o.sectionCapture=t.sectionCapture);let l=typeof t.persona=="function"?uo(t.persona):t.persona;if(typeof l=="string"&&l.trim()!==""&&(o.persona=l),Array.isArray(t.sections)){let i=t.sections.filter(s=>typeof s=="string"&&s.trim()!=="").slice(0,50);i.length>=2&&(o.sections=i)}return o}function et(e){var n,r,o;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(o=t==null?void 0:t.pathname)!=null?o:""}function fo(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:"").replace(/\s+/g," ").trim().toLowerCase(),o=t.text.replace(/\s+/g," ").trim().toLowerCase();if(!(r===o||r.startsWith(o)||o.startsWith(r)))return!1}return!0}function kn(e,t){return!!(e!=null&&e.urlMatch)&&!et(t).includes(e.urlMatch)}var po=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function ge(e,t){var o;if(e.urlMatch&&!et(t).includes(e.urlMatch))return null;let n=[];if(e.id){let l=t.getElementById(e.id);n=l?[l]:[]}if(n.length===0&&((o=e.dataAttr)!=null&&o.name)&&po.test(e.dataAttr.name))try{let l=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${l}"]`))}catch(l){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(l){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!fo(r,e.fingerprint)?null:r}var En={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"},go=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function Cn(e){var r;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;let t=/([A-Za-z-]*)\(/g,n;for(;(n=t.exec(e))!==null;)if(!go.test((r=n[1])!=null?r:""))return!1;return!0}var _n=/^https:\/\//i,In=new Map,me=null;function mo(e){return e.replace(/["\\]/g,"\\$&")}function ho(e){var t;(!me||!me.isConnected)&&(me=e.querySelector("style[data-sentient-ops]"),me||(me=e.createElement("style"),me.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(me))),me.textContent=[...In.entries()].map(([n,r])=>`[data-snt-e="${mo(n)}"]{${r}}`).join(`
2
- `)}function On(e,t,n,r){var s;let o=!1,l=(s=t.moveBefore)!=null?s:t.moveAfter;if(l){let c=ge(l,r);!c||c===e||c.parentElement!==e.parentElement||!e.parentElement?o=!0:t.moveBefore?e.parentElement.insertBefore(e,c):e.parentElement.insertBefore(e,c.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&_n.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&_n.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let i=[];if(t.hidden&&i.push("display:none !important"),t.style)for(let[c,u]of Object.entries(t.style)){let a=En[c];a&&typeof u=="string"&&Cn(u)&&i.push(`${a}:${u.trim()} !important`)}return i.length>0&&(e.setAttribute("data-snt-e",n),In.set(n,i.join(";")),ho(r)),{anchorMiss:o}}var Ke="data-sentient-block-arm",se=null;function je(e){se=e!=null?e:null}var ue="data-sentient-blocks-hid",tt={none:"0",sm:"8px",md:"16px",lg:"24px"},kt={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch",between:"space-between"},Ln={sm:"0.875em",md:"1em",lg:"1.25em"},yo={sm:"1.25em",md:"1.5em",lg:"2em"},vo={sm:"6px 14px",md:"10px 20px",lg:"14px 28px"},Tn={sm:"8px",md:"16px",lg:"32px"},bo={square:"1 / 1",landscape:"4 / 3",wide:"16 / 9"},wo={normal:"400",medium:"500",bold:"700"};function ce(e,t){for(let[n,r]of Object.entries(t))r!==void 0&&e.style.setProperty(n,r);return e}function Rn(e){return{opacity:e==="muted"?"0.7":void 0,"font-weight":e==="accent"?"600":void 0}}function Pn(e,t){var n,r,o,l,i,s,c,u,a,d,g,m;try{switch(e.type){case"stack":case"grid":{let p=t.createElement("div");if(e.type==="stack"){let f=e;ce(p,{display:"flex","flex-direction":f.direction,gap:(r=tt[(n=f.gap)!=null?n:"md"])!=null?r:tt.md,"align-items":f.align?kt[f.align]:void 0,"justify-content":f.justify?kt[f.justify]:void 0,"flex-wrap":f.wrap?"wrap":void 0})}else{let f=e,A=(l=tt[(o=f.gap)!=null?o:"md"])!=null?l:tt.md;ce(p,{display:"grid","grid-template-columns":`repeat(auto-fit, minmax(max(200px, calc((100% - ${f.columns-1} * ${A}) / ${f.columns})), 1fr))`,gap:A,"align-items":f.align?kt[f.align]:void 0})}for(let f of(i=e.children)!=null?i:[]){let A=Pn(f,t);A&&p.appendChild(A)}return p}case"text":{let p=t.createElement("p");return p.textContent=e.value,ce(p,Q({margin:"0","font-size":e.size?Ln[e.size]:void 0,"font-weight":e.weight?wo[e.weight]:void 0,"text-align":e.align},Rn(e.tone)))}case"heading":{let p=t.createElement(`h${e.level}`);return p.textContent=e.value,ce(p,{margin:"0","font-size":yo[(s=e.size)!=null?s:"md"],"text-align":e.align})}case"button":{let p=t.createElement("a");p.textContent=e.label,p.href=e.href,e.tag&&p.setAttribute("data-sentient-tag",e.tag);let f=(c=e.emphasis)!=null?c:"primary";return ce(p,{display:"inline-block",padding:vo[(u=e.size)!=null?u:"md"],"border-radius":(a=se==null?void 0:se.radius)!=null?a:"8px",font:"inherit","font-size":e.size?Ln[e.size]:void 0,"text-decoration":f==="ghost"?"underline":"none",cursor:"pointer",background:f==="primary"?(d=se==null?void 0:se.primaryBg)!=null?d:"#111827":"transparent",color:f==="primary"?(g=se==null?void 0:se.primaryText)!=null?g:"#ffffff":"inherit",border:f==="secondary"?"1px solid currentColor":"none"})}case"link":{let p=t.createElement("a");return p.textContent=e.label,p.href=e.href,e.tag&&p.setAttribute("data-sentient-tag",e.tag),ce(p,{color:"inherit","text-decoration":"underline"})}case"image":{let p=t.createElement("img");return p.src=e.src,p.alt=e.alt,ce(p,{display:"block","max-width":"100%","aspect-ratio":e.ratio&&e.ratio!=="auto"?bo[e.ratio]:void 0,"object-fit":e.fit,width:e.ratio&&e.ratio!=="auto"?"100%":void 0})}case"badge":{let p=t.createElement("span");return p.textContent=e.value,ce(p,Q({display:"inline-block",padding:"2px 10px","border-radius":"999px","font-size":"0.75em",border:"1px solid currentColor"},Rn(e.tone)))}case"spacer":return ce(t.createElement("div"),{height:(m=Tn[e.size])!=null?m:Tn.md});default:return null}}catch(p){return null}}function Dn(e,t,n,r){try{let o=new Set;for(let i of Array.from(e.children)){let s=i.getAttribute(Ke);s!==null&&(t[s]===void 0?i.remove():o.add(s))}for(let[i,s]of Object.entries(t)){if(o.has(i))continue;let c=Pn(s,r);if(!c)continue;let u=r.createElement("div");u.setAttribute(Ke,i),u.style.display="none",u.appendChild(c),e.appendChild(u)}let l=n!==void 0&&t[n]!==void 0;for(let i of Array.from(e.children)){let s=i.getAttribute(Ke),c=i;s!==null?c.style.display=l&&s===n?"":"none":l?c.hasAttribute(ue)||(c.setAttribute(ue,c.style.display),c.style.display="none"):c.hasAttribute(ue)&&(c.style.display=c.getAttribute(ue),c.removeAttribute(ue))}}catch(o){}}function So(e){try{for(let t of Array.from(e.children)){let n=t;if(n.getAttribute(Ke)!==null){n.remove();continue}n.hasAttribute(ue)&&(n.style.display=n.getAttribute(ue),n.removeAttribute(ue))}}catch(t){}}function nt(e,t){try{let n=new Set;for(let r of Array.from(e.querySelectorAll(`[${Ke}]`)))r.parentElement&&n.add(r.parentElement);for(let r of Array.from(e.querySelectorAll(`[${ue}]`)))r.parentElement&&n.add(r.parentElement);for(let r of n)t.has(r)||So(r)}catch(n){}}function Et(e,t){if(!e)return[t.documentElement];try{return Array.from(t.querySelectorAll(e))}catch(n){return[]}}function rt(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function ot(e,t,n){var r;for(let[o,l]of Object.entries(t)){let i=e[o];if(!i||typeof i=="string")continue;let s=Et(l.target,n);for(let c of s)for(let[u,a]of Object.entries(i))(r=l.dims[u])!=null&&r.includes(a)&&c.setAttribute(`data-${u}`,a)}}function it(e,t,n){for(let[r,o]of Object.entries(t)){let l=e[r];if(typeof l!="string"||!o.arms||!o.arms.includes(l))continue;let i=Et(o.target,n);for(let s of i)s.setAttribute("data-sentient-arm",l)}}function st(e,t,n,r){var s,c;let o=new Set,l=(s=r==null?void 0:r.contentAndOps)!=null?s:!0,i=[];for(let[u,a]of Object.entries(t)){if(kn(a.locator,n))continue;let d;if(a.locator){let m=ge(a.locator,n);d=m?[m]:[]}else d=Et(a.target,n);(a.locator||a.target)&&d.length===0&&i.push(u);let g=e[u];for(let m of d){if(g!==void 0)if(typeof g=="string")m.setAttribute("data-sentient-arm",g),l&&((c=r==null?void 0:r.onApplied)==null||c.call(r,u,g,m));else for(let[p,f]of Object.entries(g))m.setAttribute(`data-${p}`,f);a.blocks&&!xo(n)&&(Dn(m,a.blocks,typeof g=="string"?g:void 0,n),o.add(m)),l&&(typeof a.content=="string"&&(m.textContent=a.content),a.ops&&On(m,a.ops,u,n).anchorMiss&&!i.includes(u)&&i.push(u))}}return nt(n,o),i}var Ao=/bot|crawler|spider|crawling|googlebot|bingbot|duckduckbot|baiduspider|yandexbot|slurp|gptbot|claudebot|anthropic|perplexity|ccbot|applebot|headlesschrome/i;function xo(e){var t,n,r;try{let o=(n=(t=e.defaultView)!=null?t:typeof window!="undefined"?window:void 0)==null?void 0:n.navigator;return o?o.webdriver===!0?!0:Ao.test((r=o.userAgent)!=null?r:""):!1}catch(o){return!1}}var ko=800;function at(e,t,n){let r=[];return n.forEach(({slotId:o,arm:l,el:i},s)=>{r.push(Be((g,m={})=>{try{e.track({projectId:t,componentId:o,variantId:l,eventType:"micro_signal",payload:Q({signalType:g},m)})}catch(p){}},i,void 0,{tabLoss:s===0}));let c=null,u=0,a=()=>{u=Date.now(),c=setTimeout(()=>{try{e.track({projectId:t,componentId:o,variantId:l,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-u}})}catch(g){}c=null},ko)},d=()=>{c!==null&&(clearTimeout(c),c=null)};i.addEventListener("mouseenter",a),i.addEventListener("mouseleave",d),r.push(()=>{i.removeEventListener("mouseenter",a),i.removeEventListener("mouseleave",d),c!==null&&clearTimeout(c)})}),()=>{for(let o of r)o()}}function Eo(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 Bn(e){return e?`_snt_fired_goals_${e.slice(0,12)}`:"_snt_fired_goals"}var Co="_snt_fired_goals";function Nn(e,t){try{e==null||e.sessionStorage.removeItem(Bn(t)),e==null||e.sessionStorage.removeItem(Co)}catch(n){}}function Mn(e){var t;return[(t=e.slotId)!=null?t:"",e.goalId,e.event,e.locator?JSON.stringify(e.locator):""].join("|")}function _o(e,t){try{let n=e==null?void 0:e.sessionStorage.getItem(t);if(!n)return new Set;let r=JSON.parse(n);return Array.isArray(r)?new Set(r.filter(o=>typeof o=="string")):new Set}catch(n){return new Set}}function Io(e,t,n){try{e==null||e.sessionStorage.setItem(t,JSON.stringify([...n]))}catch(r){}}function lt(e,t,n,r){var C,L;let o=(C=n.defaultView)!=null?C:typeof window!="undefined"?window:null,l=Bn(r),i=_o(o,l),s=y=>{let w=Mn(y);if(!i.has(w))try{y.slotId?t.componentGoal(y.slotId,y.goalId):t.goal(y.goalId),i.add(w),Io(o,l,i)}catch(I){}},c=e.filter(y=>y.event==="click"),u=e.filter(y=>y.event==="form_submit"),a=e.filter(y=>y.event==="url_reached"),d=e.filter(y=>y.event==="scroll_depth"),g=(y,w)=>{if(!y.locator)return!1;let I=ge(y.locator,n);return!!I&&(I===w||I.contains(w))},m=y=>{let w=y.target;if(!(!w||typeof w.closest!="function"))for(let I of c)g(I,w)&&s(I)},p=y=>{let w=y.target;if(w)for(let I of u)g(I,w)&&s(I)},f=()=>{if(a.length===0)return;let y=et(n);for(let w of a)w.urlPattern&&Eo(w.urlPattern,y)&&s(w)},A=()=>{var I;let y=n.documentElement,w=y.scrollHeight>0?(y.scrollTop+y.clientHeight)/y.scrollHeight:0;for(let N of d)w>=((I=N.threshold)!=null?I:.75)&&s(N);d.every(N=>i.has(Mn(N)))&&n.removeEventListener("scroll",A)};return n.addEventListener("click",m,!0),n.addEventListener("submit",p,!0),(L=n.defaultView)==null||L.addEventListener("popstate",f),f(),d.length>0&&(n.addEventListener("scroll",A,{passive:!0}),A()),{checkUrl:f,teardown:()=>{var y;n.removeEventListener("click",m,!0),n.removeEventListener("submit",p,!0),(y=n.defaultView)==null||y.removeEventListener("popstate",f),d.length>0&&n.removeEventListener("scroll",A)}}}var $n="__snt_editor_token";function Kn(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem($n):null}catch(e){return null}}function jn(e){try{sessionStorage.setItem($n,e)}catch(t){}}var ze="0.22.1",dt=ze!=="0.0.0-dev"?{name:"snippet",version:ze}:void 0,Vn=5e3,Oo=50,Jn=(()=>{try{if(typeof window=="undefined")return[];let e=window.SentientSnippet;return Array.isArray(e==null?void 0:e.q)?e.q:[]}catch(e){return[]}})(),H=null,P=null,de={},ye=null,G=null,he=null,z=null,ae=null,$=null,Ae=null,Gn=!1,Ct=null,ct=null,ft=null,Ce=!1,Ge=!1,ke=!1;function Yn(e,t){let n,r=new Promise(o=>{n=setTimeout(()=>o(null),t)});return Promise.race([e,r]).then(o=>(clearTimeout(n),o),o=>{throw clearTimeout(n),o})}function xe(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function _e(e,t){return H?(H.personaAttributes&&$&&rt($.persona,$.band,e),ot(de,H.slots,e),it(de,H.slots,e),ye?st(de,ye,e,t):(nt(e,new Set),[])):[]}function Xn(e){var n;let t=new Map;for(let r of(n=H==null?void 0:H.sections)!=null?n:[])try{let o=e.querySelectorAll(r);o.length===1&&t.set(r,o[0])}catch(o){}return t}function _t(e,t){try{if(!e||e.length<2||new Set(e).size!==e.length)return;let n=Xn(t);if(n.size!==e.length)return;let r=[];for(let i of e){let s=n.get(i);if(!s)return;r.push(s)}let o=r[0].parentNode;if(!o||!r.every(i=>i.parentNode===o))return;let l=r.slice().sort((i,s)=>i.compareDocumentPosition(s)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let i=0;i<r.length;i++){let s=r[i];l[i]!==s&&(o.insertBefore(s,l[i]),l.splice(l.indexOf(s),1),l.splice(i,0,s))}}catch(n){}}function Zn(e){return e.apiBase?`${e.apiBase.replace(/\/+$/,"")}/v1/events`:void 0}function Lo(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 Ie(){return!!(H&&P&&H.sectionCapture!==!1&&(H.consent!==!1||Ge)&&!Se())}function To(){if(!P||!H||!Ie()||ae)return;let e=[];_e(document,{contentAndOps:Ce,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),Ot();try{z==null||z(),z=at(P,H.apiKey,e)}catch(t){}}function Ot(){if(typeof document=="undefined"||!Ie())return;let e;try{if(ct&&ct.length>0){let t=new Map;for(let n of ct){if(n.urlMatch!==window.location.pathname)continue;let r=ge(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{ae=xn(P,Q({apiKey:H.apiKey,apiBase:H.apiBase,doc:document,microSignals:!0},e?{typeOf:e}:{})),ft=window.location.pathname}catch(t){}}function Lt(){try{let e=[];if(z==null||z(),z=null,_e(document,{contentAndOps:Ce,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),_t(Ae,document),e.length>0&&Ie())try{z=at(P,H.apiKey,e)}catch(t){}try{typeof window!="undefined"&&ft!==null&&window.location.pathname!==ft&&Ie()&&(ae==null||ae(),ae=null,Ot())}catch(t){}}catch(e){}}function Un(){Ct===null&&(Ct=setTimeout(()=>{Ct=null,Lt();try{G==null||G.checkUrl()}catch(e){}},Oo))}function It(){if(!(Gn||typeof window=="undefined"||typeof history=="undefined")){Gn=!0;try{let e=t=>{let n=history[t];history[t]=function(r,o,l){let i=n.call(this,r,o,l!=null?l:null);return Un(),i}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Un)}catch(e){}}}function ut(e){let t={};for(let[n,r]of Object.entries(e.slots))try{t[n]=r.target?document.querySelectorAll(r.target).length:1}catch(o){t[n]=0}return t}function Qn(e){return new URLSearchParams(e).get("sentient_editor")}function Ro(){try{let e=Array.from(document.getElementsByTagName("script")),t=/(^|\/)snippet(\.global)?\.js(\?|$)/,n=e.find(r=>t.test(r.src));if(n!=null&&n.src)return n.src.replace(t,"$1editor.global.js$3")}catch(e){}return null}function Po(e,t){var n,r,o,l;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let c=document.createElement("meta");c.name="referrer",c.content="no-referrer",c.setAttribute("data-sentient-editor",""),((r=document.head)!=null?r:document.documentElement).appendChild(c)}catch(c){}let i=(o=e.editorSrc)!=null?o:Ro();if(!i){qn();return}let s=document.createElement("script");s.src=i,s.async=!0,s.onerror=()=>qn(),((l=document.head)!=null?l:document.documentElement).appendChild(s)}catch(i){}}var zn="sentient-editor-load-notice",er={position:"fixed",bottom:"16px",zIndex:"2147483647",background:"#111827",color:"#fff",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"};function qn(){var e,t;try{if(typeof document=="undefined"||document.getElementById(zn))return;(e=document.querySelector('meta[name="referrer"][data-sentient-editor]'))==null||e.remove();let n=document.createElement("div");n.id=zn,n.textContent="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.",Object.assign(n.style,er,{right:"16px",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",cursor:"pointer"}),n.addEventListener("click",()=>n.remove()),((t=document.body)!=null?t:document.documentElement).appendChild(n),setTimeout(()=>n.remove(),1e4)}catch(n){}}function tr(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let o=r.indexOf(":"),l=o===-1?"":r.slice(0,o),i=o===-1?"":r.slice(o+1);if(!(!l||!i))if(i.includes("=")){let s={};for(let c of i.split(",")){let[u,a]=c.split("=");u&&a&&(s[u]=a)}Object.keys(s).length&&(n[l]=s)}else n[l]=i}return Object.keys(n).length?n:null}function nr(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var Fn="sentient-persona-preview-banner";function Wn(e,t){var n;try{if(typeof document=="undefined"||document.getElementById(Fn))return;let r=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),o=document.createElement("div");o.id=Fn,o.setAttribute("role","status"),Object.assign(o.style,er,{left:"50%",transform:"translateX(-50%)",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",font:"13px/1 system-ui, sans-serif",border:"1px solid rgba(255,255,255,0.14)"});let l=document.createElement("span");l.textContent=t?`\u201C${e}\u201D isn\u2019t in your personas \u2014 showing the default experience`:`Previewing as ${r}`;let i=document.createElement("button");i.type="button",i.textContent="Exit preview",Object.assign(i.style,{cursor:"pointer",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"inherit",padding:"4px 10px",borderRadius:"999px"}),i.addEventListener("click",()=>{try{let s=new URL(window.location.href);s.searchParams.delete("sentient_persona"),window.location.href=s.pathname+s.search+s.hash}catch(s){}}),o.appendChild(l),o.appendChild(i),((n=document.body)!=null?n:document.documentElement).appendChild(o)}catch(r){}}async function Do(e,t){var u,a,d,g,m,p,f,A,C,L;let n=(u=e.apiBase)!=null?u:"https://api.sentient-ui.com",o=((a=e.registry)!=null?a:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([y,w])=>({id:y,dims:w.dims}))},l=await Yn(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(o)}).then(y=>y.ok?y.json():null).catch(()=>null),Vn);if(!l){Ue(e),xe(e,"persona preview: explain unavailable \u2014 page left as-is");return}let i=l;de=(d=i.slots)!=null?d:{},ye=(g=i.slotConfig)!=null?g:null,je(i.palette);let s=(f=(p=(m=i.personaAttributes)==null?void 0:m.persona)!=null?p:i.persona)!=null?f:t,c=(C=(A=i.personaAttributes)==null?void 0:A.confidence)!=null?C:"high";$={persona:s,band:c},_e(document),Ce=!0,It(),Ue(e),i.recognized===!1?Wn(t,!0):Wn((L=i.personaDisplay)!=null?L:s)}function Ue(e){let t={goal(n,r){try{P==null||P.goal(n,r)}catch(o){}},componentGoal(n,r){try{P==null||P.componentGoal(n,r)}catch(o){}},grantConsent(){try{!P&&ke?(P=Ne(Q({apiKey:e.apiKey,context:e.context,consent:!0,preConsentBehavior:e.preConsentBehavior,debug:e.debug,persona:e.persona,ingestUrl:Zn(e)},dt?{sdk:dt}:{})),he&&he.length>0&&(G==null||G.teardown(),G=lt(he,P,document,e.apiKey))):(St(e.apiKey),P&&he&&he.length>0&&(G==null||G.teardown(),G=lt(he,P,document,e.apiKey))),ke=!1}catch(n){}Ge=!0;try{To()}catch(n){}},revokeConsent(){try{ae==null||ae(),ae=null,ft=null,z==null||z(),z=null,G==null||G.teardown(),G=null,Nn(typeof window!="undefined"?window:null,e.apiKey),Ge=!1,ke=!0,P==null||P.destroy(),P=null}catch(n){}},reapply:Lt,getState(){var n,r;try{return{apiKey:e.apiKey,persona:(n=$==null?void 0:$.persona)!=null?n:null,band:(r=$==null?void 0:$.band)!=null?r:null,slots:de,matchCounts:ut(e),consent:!ke&&(e.consent!==!1||Ge)}}catch(o){return{apiKey:e.apiKey,persona:null,band:null,slots:{},matchCounts:{},consent:!1}}}};window.SentientSnippet=t;for(let n of Jn.splice(0))try{n[0]==="goal"&&t.goal(n[1],n[2])}catch(r){}}function Hn(){var e;try{if(typeof window=="undefined")return;let t=window;if(typeof((e=t.SentientSnippet)==null?void 0:e.goal)=="function")return;let n=()=>{};t.SentientSnippet={goal:n,componentGoal:n,grantConsent:n,revokeConsent:n,reapply:n,getState:()=>({apiKey:"",persona:null,band:null,slots:{},matchCounts:{},consent:!1})},Jn.length=0}catch(t){}}async function rr(){var e;try{let t=Qe(window.sentient);if(!t){Hn();return}H=t,Ce=!1,Ae=null,je(null),Ge=!1,ke=!1,he=null;let n=typeof window!="undefined"?Qn(window.location.search):null;if(n){jn(n);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 r=n!=null?n:Kn();if(r){Po(t,r),Ue(t),xe(t,"editor mode");return}let o=typeof window!="undefined"?tr(window.location.search):null;if(o){de=o,$=null,_e(document),It(),Ue(t),xe(t,"preview mode",o);return}let l=typeof window!="undefined"?nr(window.location.search):null;if(l){await Do(t,l),xe(t,"persona preview",l);return}let i=(e=t.registry)!=null?e:Object.keys(t.slots).length===0,s=De(t.apiKey);s&&($={persona:s.persona,band:s.band},de=s.slots,s.slotConfig&&(ye=s.slotConfig),s.palette&&je(s.palette),_e(document,{contentAndOps:!1}),s.layoutOrder&&(Ae=s.layoutOrder,_t(Ae,document)));let c=Ne(Q({apiKey:t.apiKey,context:t.context,consent:t.consent,preConsentBehavior:t.preConsentBehavior,debug:t.debug,persona:t.persona,ingestUrl:Zn(t)},dt?{sdk:dt}:{}));P=c,Ue(t),It();let u=Object.entries(t.slots).map(([f,A])=>({id:f,dims:A.dims})),a=ze!=="0.0.0-dev"?{v:ze}:{},d=Array.from(Xn(document).keys()),g=c.decide(Q(Q(Q({slots:u},a),d.length>=2?{sections:d}:{}),i?{slotsFrom:"registry"}:{})),m=await Yn(g,Vn),p=f=>{var L,y,w,I,N,x;let A=c.getPersona();A?$={persona:A.persona,band:A.band}:f.persona&&($={persona:f.persona,band:"low"}),de=f.slots,i?ye=(L=f.slotConfig)!=null?L:null:f.slotConfig&&(ye=f.slotConfig),f.palette&&je(f.palette),Ae=(y=f.layoutOrder)!=null?y:Ae;let C=()=>{let D=[];if(Lo(t,_e(document,{onApplied:(K,j,Z)=>D.push({slotId:K,arm:j,el:Z})})),_t(Ae,document),Ce=!0,Ie())try{z==null||z(),z=at(P,t.apiKey,D)}catch(K){}};if(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",C,{once:!0}):C(),he=(w=f.goals)!=null?w:null,f.goals&&f.goals.length>0&&t.consent!==!1&&P)try{G==null||G.teardown(),G=lt(f.goals,P,document,t.apiKey)}catch(D){}ct=(I=f.sectionMap)!=null?I:null,Ie()&&Ot(),xe(t,"applied",{persona:$,slots:de,matches:ut(t)}),!ke&&Me(t.apiKey,Q(Q({v:1,persona:(N=$==null?void 0:$.persona)!=null?N:f.persona,band:(x=$==null?void 0:$.band)!=null?x:"low",slots:f.slots,layoutOrder:f.layoutOrder,savedAt:Date.now()},ye?{slotConfig:ye}:{}),f.palette?{palette:f.palette}:{}))};if(!m){xe(t,"decide timeout/null \u2014 snapshot state stands",ut(t)),g.then(f=>{!f||Ce||ke||P!==c||(p(f),xe(t,"late decide applied",ut(t)))}).catch(()=>{});return}p(m)}catch(t){Hn()}}if(typeof window!="undefined"&&window.sentient){let e=window;e.__sentientInitialized||(e.__sentientInitialized=!0,Promise.resolve().then(()=>{rr()}))}return lr(Mo);})();
1
+ "use strict";var SentientSnippet=(()=>{var Fe=Object.defineProperty;var ir=Object.getOwnPropertyDescriptor;var ar=Object.getOwnPropertyNames,Dt=Object.getOwnPropertySymbols;var Bt=Object.prototype.hasOwnProperty,sr=Object.prototype.propertyIsEnumerable;var Mt=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,H=(e,t)=>{for(var n in t||(t={}))Bt.call(t,n)&&Mt(e,n,t[n]);if(Dt)for(var n of Dt(t))sr.call(t,n)&&Mt(e,n,t[n]);return e};var Nt=(e,t)=>()=>(e&&(t=e(e=0)),t);var $t=(e,t)=>{for(var n in t)Fe(e,n,{get:t[n],enumerable:!0})},lr=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ar(t))!Bt.call(e,o)&&o!==n&&Fe(e,o,{get:()=>t[o],enumerable:!(r=ir(t,o))||r.enumerable});return e};var cr=e=>lr(Fe({},"__esModule",{value:!0}),e);var ur,dr,fr,Kt,pr,gr,jt,_,be,Re=Nt(()=>{"use strict";ur=Object.defineProperty,dr=Object.defineProperties,fr=Object.getOwnPropertyDescriptors,Kt=Object.getOwnPropertySymbols,pr=Object.prototype.hasOwnProperty,gr=Object.prototype.propertyIsEnumerable,jt=(e,t,n)=>t in e?ur(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_=(e,t)=>{for(var n in t||(t={}))pr.call(t,n)&&jt(e,n,t[n]);if(Kt)for(var n of Kt(t))gr.call(t,n)&&jt(e,n,t[n]);return e},be=(e,t)=>dr(e,fr(t))});var Zt={};$t(Zt,{LOCAL_ENGINE_AVAILABLE:()=>Sr,createLocalEngine:()=>Ar});function Ar(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var Sr,Qt=Nt(()=>{"use strict";Sr=!1});var $o={};$t($o,{applyPersonaAttributes:()=>rt,applyRegistrySlots:()=>at,applySlotArms:()=>it,applySlotAttributes:()=>ot,parseEditorToken:()=>er,parsePersonaPreview:()=>rr,parsePreview:()=>nr,parseSnippetConfig:()=>Qe,planReorder:()=>ct,reapply:()=>Rt,run:()=>or,version:()=>ze});Re();var mr=["buyer","researcher","deal_seeker","browser"];var hr={buyer:"Buyer",researcher:"Researcher",deal_seeker:"Deal seeker",browser:"Browser",unknown:"Unknown"};function We(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function Gt(e){if(e.length===0)return null;let t={};for(let n of e.split("|")){let r=n.indexOf("=");if(r<=0||r!==n.lastIndexOf("=")||r===n.length-1)return null;let o=n.slice(0,r);if(o in t)return null;t[o]=n.slice(r+1)}return t}function gt(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 We(e.baseline);if(typeof e.baseline=="string")return e.baseline;let o={};for(let[l,i]of Object.entries((n=e.dims)!=null?n:{}))o[l]=(r=i[0])!=null?r:"";return We(o)}function Ut(e,t){var n,r;return e.dims!=null?(r=(n=Gt(t))!=null?n:Gt(gt(e)))!=null?r:{}:t}function zt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t}function we(e){return e>=.3?e<.7?"medium":"high":"low"}var Go=mr.map(e=>({key:e,displayName:hr[e]}));function He(e){return e?`_${e.slice(0,12)}`:""}var yr="_snt_uid";function qt(e){return`${yr}${He(e)}`}var vr=["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 Ft(e){return br(e)!==null}function br(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=vr.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function Wt(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 Ht(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(o){}let r=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(n){return"direct"}}function Vt(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}var wr=["gclid","gbraid","wbraid","fbclid","ttclid","msclkid","twclid","li_fat_id"];function Jt(e){let t={},n={};try{let r=typeof e=="string"||e instanceof URLSearchParams?new URLSearchParams(e):Object.entries(e).flatMap(([o,l])=>{let i=Array.isArray(l)?l[0]:l;return i===void 0?[]:[[o,i]]});for(let[o,l]of r)o.startsWith("utm_")?o in t||(t[o]=l):wr.includes(o)&&(o in n||(n[o]=l))}catch(r){}return{utmParams:t,clickIds:n}}function Yt(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function mt(e){return _(_(_({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 ht(e){let t=mt(e);return Ut(t,gt(t))}function Xt(e){return typeof e=="string"?e:We(e)}Re();function on(){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)})}var xr="_snt_uid",kr=365,Ve="_snt_uid";function Er(){return on()}function en(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function Cr(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function yt(e){try{return localStorage.getItem(e)}catch(t){return null}}function tn(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function nn(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function _r(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function Ir(e){try{sessionStorage.removeItem(e)}catch(t){}}function Or(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 Lr(e){try{localStorage.removeItem(e)}catch(t){}}function Rr(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var Tr={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function an(e){var t,n,r,o,l,i,a;if(typeof window=="undefined")return Tr;let s=He(e==null?void 0:e.apiKey),u=(t=e==null?void 0:e.cookieName)!=null?t:qt(e==null?void 0:e.apiKey),c=`${Ve}${s}`,d=`${Ve}_tomb${s}`,g=((n=e==null?void 0:e.cookieTTLDays)!=null?n:kr)*24*60*60,w=v=>v&&v.length>0?v:null,p=()=>{var v,I;return s&&!(e!=null&&e.cookieName)&&yt(d)===null?(I=(v=w(en(xr)))!=null?v:w(yt(Ve)))!=null?I:w(nn(Ve)):null},m=(a=(i=(l=(o=(r=w(en(u)))!=null?r:w(yt(c)))!=null?o:w(nn(c)))!=null?l:p())!=null?i:w(e==null?void 0:e.ssrSessionId))!=null?a:Er();Cr(u,m,g);let A=tn(c,m),C=Or(u),R=A?!1:_r(c,m),f=!A&&!C&&!R;return{getSessionId:()=>m,isEphemeral:()=>f,destroy:()=>{m=null,Rr(u),Lr(c),Ir(c),s&&!(e!=null&&e.cookieName)&&tn(d,"1")}}}function Pe(e){return Math.min(6e4,1e3*2**Math.min(e,6))}function St(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 sn(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 Ee(e,t,n){try{let r=(()=>{try{let l=localStorage.getItem(n);if(!l)return[];let i=JSON.parse(l);return Array.isArray(i)?i:[]}catch(l){return[]}})(),o=new Map;for(let l of r)o.set(l.id,l);for(let l of e)o.set(l.id,l);localStorage.setItem(n,JSON.stringify([...o.values()].slice(-t)))}catch(r){}}function ln(e,t){try{let n=localStorage.getItem(t);if(!n)return;let r=JSON.parse(n);if(!Array.isArray(r))return;let o=new Set(e),l=r.filter(i=>!o.has(i.id));if(l.length===r.length)return;l.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(l))}catch(n){}}var Pr=500,Dr=56*1024;function cn(e){return`_snt_retry_${e.slice(0,12)}`}var Mr={push:()=>{},flush:()=>{},destroy:()=>{}};function Br(e){var t,n,r;if(typeof window=="undefined")return Mr;let o=(t=e.flushIntervalMs)!=null?t:5e3,l=(n=e.maxBatchSize)!=null?n:20,i=(r=e.maxRetrySize)!=null?r:100,a=e.ingestUrl,s=e.apiKey,u=cn(s),c=[],d=new Set,g=[],w=y=>{for(let b of y)p.delete(b),!d.has(b)&&(d.add(b),g.push(b));for(;g.length>Pr;){let b=g.shift();b&&d.delete(b)}ln(y,u)},p=new Set,m=()=>{for(;c.length>i;){let y=c.shift();y&&p.delete(y.id)}},A=y=>{d.has(y.id)||p.has(y.id)||(p.add(y.id),c.push(y),m())},C=y=>{for(let b of y)d.has(b.id)||(p.add(b.id),c.push(b));m()},R=sn(u,i);for(let y of R)A(y);let f=0,v=0,I=(y,b=!0)=>{if(y.length===0)return;let k=JSON.stringify(y),O=y.map(Y=>Y.id),E;try{E=fetch(a,{method:"POST",keepalive:!0,body:k,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(Y){Ee(y,i,u),C(y),v++,f=Date.now()+Pe(v);return}let oe=Y=>{if(St(Y)!=="retry"){if(!Y.ok&&b){let te=y.filter(ne=>ne.eventType!=="pageview");if(te.length>0&&te.length<y.length){w(y.filter(ne=>ne.eventType==="pageview").map(ne=>ne.id)),I(te,!1);return}}w(O),v=0,f=0;return}Ee(y,i,u),C(y),v++,f=Date.now()+Pe(v)};E instanceof Promise?E.then(oe).catch(()=>{Ee(y,i,u),C(y),v++,f=Date.now()+Pe(v)}):oe(E)},B=typeof TextEncoder!="undefined"?new TextEncoder:null,x=y=>B?B.encode(y).length:y.length,N=y=>{let b=[],k=2;for(let O of y){let E=x(JSON.stringify(O))+1;if(b.length>0&&k+E>Dr||b.length>=l)break;b.push(O),k+=E}return b},j=()=>{try{if(Date.now()<f)return;for(;c.length>0&&!(Date.now()<f);){let y=c.filter(k=>!d.has(k.id));if(c.length=0,y.length===0)break;let b=N(y);if(b.length===0)break;b.length<y.length&&c.push(...y.slice(b.length)),I(b)}}catch(y){}},$=!0,J=null;J=setInterval(()=>{$&&j()},o);let G=()=>{document.visibilityState==="hidden"&&j()},U=()=>{j()};return document.addEventListener("visibilitychange",G),window.addEventListener("pagehide",U),{push(y){A(y),c.length>=l&&j()},flush:j,destroy(){$=!1,J!==null&&(clearInterval(J),J=null),document.removeEventListener("visibilitychange",G),window.removeEventListener("pagehide",U),j()}}}var Nr=200;function un(e){return`_snt_goal_retry_${e.slice(0,12)}`}var $r={send:()=>{},flush:()=>{},destroy:()=>{}};function Kr(e){var t,n,r;if(typeof window=="undefined")return $r;let o=(t=e.flushIntervalMs)!=null?t:5e3,l=(n=e.maxRetrySize)!=null?n:100,i=(r=e.maxPerFlush)!=null?r:5,a=un(e.apiKey),s=[],u=new Set,c=new Set,d=[],g=0,w=0,p=!1,m=x=>{for(u.delete(x.id),c.has(x.id)||(c.add(x.id),d.push(x.id));d.length>Nr;){let N=d.shift();N&&c.delete(N)}ln([x.id],a)},A=x=>{Ee([x],l,a),!c.has(x.id)&&!u.has(x.id)&&(u.add(x.id),s.push(x)),Date.now()>=g&&(w++,g=Date.now()+Pe(w))},C=x=>{let N;try{N=fetch(e.url,{method:"POST",keepalive:!0,body:x.body,headers:e.headers})}catch($){A(x);return}let j=$=>{var J;let G=St($);if(G==="retry"){A(x);return}G==="dropped"&&((J=e.onDrop)==null||J.call(e,x,$.status)),m(x),w=0,g=0};N instanceof Promise?N.then(j).catch(()=>A(x)):j(N)},R=()=>{try{if(p||Date.now()<g)return;let x=0;for(;s.length>0&&x<i&&!(Date.now()<g);){let N=s.shift();u.delete(N.id),!c.has(N.id)&&(x++,C(N))}}catch(x){}},f=sn(a,l);for(let x of f)u.has(x.id)||(u.add(x.id),s.push(x));f.length>0&&Ee(f,l,a);let v=setInterval(R,o),I=()=>{document.visibilityState==="hidden"&&R()},B=()=>R();return document.addEventListener("visibilitychange",I),window.addEventListener("pagehide",B),{send(x){if(!p&&!(c.has(x.id)||u.has(x.id))){if(Date.now()<g){Ee([x],l,a),u.add(x.id),s.push(x);return}C(x)}},flush:R,destroy(){clearInterval(v),document.removeEventListener("visibilitychange",I),window.removeEventListener("pagehide",B),R(),p=!0}}}var jr=1800*1e3;function Je(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Gr(e=jr,t){let n=new Map,r=`_snt_asgn${He(t)}_`,o=(s,u)=>`${r}${encodeURIComponent(s)}:${encodeURIComponent(u)}`,l=s=>{let u=s.slice(r.length),c=u.indexOf(":");if(c<0)return null;try{return{componentId:decodeURIComponent(u.slice(0,c)),segment:decodeURIComponent(u.slice(c+1))}}catch(d){return null}},i=()=>{try{let s=[];for(let u=0;u<localStorage.length;u++){let c=localStorage.key(u);c!=null&&c.startsWith(r)&&s.push(c)}return s}catch(s){return[]}},a=s=>s.assignedAt+(s.ttlMs&&s.ttlMs>0?s.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let s of i())try{let u=localStorage.getItem(s);if(!u)continue;let c=JSON.parse(u);if(a(c)){localStorage.removeItem(s);continue}let d=l(s);if(!d)continue;n.set(Je(d.componentId,d.segment),c)}catch(u){}})(),{get(s,u){let c=n.get(Je(s,u));return c?a(c)?(n.delete(Je(s,u)),null):c:null},set(s,u,c){let d=Je(s,u);n.set(d,c);try{localStorage.setItem(o(s,u),JSON.stringify(c))}catch(g){}},clear(){n.clear();for(let s of i())try{localStorage.removeItem(s)}catch(u){}}}}var Ze="_snt_snap:",Ur=["low","medium","high"];function De(e){try{let t=localStorage.getItem(Ze+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"||!Ur.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 Me(e,t){try{localStorage.setItem(Ze+e,JSON.stringify(t))}catch(n){}}var bt="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",dn="[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.",rn=!1,Ye=!1;function zr(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function qr(e){var t;let n=an({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),r=(t=n.getSessionId())!=null?t:"local",o=zr(),l=Promise.resolve().then(()=>(Qt(),Zt)).then(c=>{let d=c;return d.LOCAL_ENGINE_AVAILABLE?(rn||(rn=!0,console.info(dn)),d):(Ye||(Ye=!0,console.error(bt)),null)}).catch(()=>(Ye||(Ye=!0,console.error(bt)),null)),i=null,a={low:.15,medium:.5,high:.85},s=(()=>{var c;if(e.initialPersona)return _({},e.initialPersona);let d=De(e.apiKey||"local");return d?{persona:d.persona,confidence:(c=a[d.band])!=null?c:.15}:null})();function u(c){let d=document.documentElement;d.dataset.sentientPersona===void 0&&(d.dataset.sentientPersona=c.persona,d.dataset.sentientConfidence=we(c.confidence))}return{isLocal:!0,async decide(c){var d,g,w;let p=await l;if(!p)return null;let m=p.createLocalEngine({sessionId:r,forcedPersona:o}).decide(c);return i=be(_({},m),{layoutOrder:(g=(d=m.layoutOrder)!=null?d:i==null?void 0:i.layoutOrder)!=null?g:null,slots:_(_({},(w=i==null?void 0:i.slots)!=null?w:{}),m.slots)}),Me(e.apiKey||"local",{v:1,persona:i.persona,band:we(i.confidence),slots:i.slots,layoutOrder:i.layoutOrder,savedAt:Date.now()}),u(m),m},getSlotResult(c){var d,g,w;return(w=(g=i==null?void 0:i.slots[c])!=null?g:(d=e.initialSlots)==null?void 0:d[c])!=null?w:null},getPersona(){let c=i!=null?i:s;return c?{persona:c.persona,confidence:c.confidence,band:we(c.confidence)}:null},async assign(c,d){var g;let w=await l;return!w||!d||d.length===0?d!=null&&d[0]?{variantId:d[0],assignmentTtlMs:0}:null:{variantId:(g=w.createLocalEngine({sessionId:r,forcedPersona:o}).decide({components:[{id:c,variantIds:d}]}).assignments[c])!=null?g:d[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function Be(e,t,n,r){let o=[];{let l=!1,i=[],a=()=>{if(l)return;let s=Date.now();for(i.push(s);i.length>0&&s-i[0]>500;)i.shift();i.length>=3&&(l=!0,e("rage_click"))};t.addEventListener("click",a),o.push(()=>t.removeEventListener("click",a))}{let l=!1,i=a=>{if(l||!(a.target instanceof Node)||!t.contains(a.target)&&t!==a.target)return;l=!0;let s=typeof window!="undefined"?window.getSelection():null,u=s?s.toString().length:0;e("text_copy",{selectionLength:u})};document.addEventListener("copy",i),o.push(()=>document.removeEventListener("copy",i))}{let l=!1,i=!1,a=null,s=()=>{a!==null&&(clearTimeout(a),a=null)},u=()=>{l||!i||(s(),a=setTimeout(()=>{!l&&i&&(l=!0,e("scroll_hesitation"))},3e3))},c=()=>{s(),u()},d=w=>{for(let p of w)i=p.intersectionRatio>.3,i?u():s()},g=new IntersectionObserver(d,{threshold:[.3]});g.observe(t),window.addEventListener("scroll",c,{passive:!0}),o.push(()=>{g.disconnect(),window.removeEventListener("scroll",c),s()})}if((r==null?void 0:r.tabLoss)!==!1){let l=!1,i=n!=null?n:Date.now(),a=()=>{if(l||document.visibilityState!=="hidden")return;let s=Date.now()-i;s<15e3&&(l=!0,e("tab_loss",{timeOnPage:s}))};document.addEventListener("visibilitychange",a),o.push(()=>document.removeEventListener("visibilitychange",a))}return()=>{for(let l of o)l()}}var fn="https://api.sentient-ui.com/v1/events",re=new Map,pn=null;function Fr(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}var Wr=3;function vt(){return on()}function Xe(){var e;if(typeof window!="undefined")return((e=window.location)==null?void 0:e.pathname)||void 0}function Hr(){let e=new WeakMap,t=new Map,n=!1,r=(a,s,u)=>{let c=a.get(s);return u===null?c?!0:(a.set(s,new Set),!1):c?c.has(u)?!0:(c.add(u),!1):(a.set(s,new Set([u])),!1)},o=typeof window!="undefined"&&"event"in window,l=()=>{if(!o)return;let a=window.event;return typeof Event=="function"&&a instanceof Event?a:void 0},i=()=>{if(o){Promise.resolve().then(()=>{n=!1,t.clear()});return}let a=!1,s=()=>{a||(a=!0,n=!1,t.clear())};if(setTimeout(s,0),typeof MessageChannel=="function"){let u=new MessageChannel;u.port1.onmessage=()=>{u.port1.close(),u.port2.close(),s()},u.port2.postMessage(0)}};return{firedBefore(a,s){let u=l();if(u){let d=e.get(u);return d||(d=new Map,e.set(u,d)),r(d,a,s)}let c=r(t,a,s);return!c&&!n&&(n=!0,i()),c}}}var gn=new Set;function Vr(e,t,n){let r=typeof window=="undefined"?null:window.history;if(!r)return()=>{};let o=!1,l,i=()=>{if(o)return;let u=Xe();!u||u===l||(l=u,e.track({projectId:t,componentId:"__page__",eventType:"pageview",payload:{}}),n(`${t}:${u}`))},a=[];for(let u of["pushState","replaceState"]){let c=r[u],d=function(...g){let w=c.apply(this,g);return i(),w};r[u]=d,a.push([u,c,d])}window.addEventListener("popstate",i);let s=Xe();return s&&gn.has(`${t}:${s}`)?l=s:i(),()=>{if(!o){o=!0,window.removeEventListener("popstate",i);for(let[u,c,d]of a)r[u]===d&&(r[u]=c)}}}var Te={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 Jr(){try{return Jt(window.location.search)}catch(e){return{utmParams:{},clickIds:{}}}}function mn(e){return e.replace(/\/events\/?$/,"")}function Se(){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 At(e){var t;if(typeof window=="undefined")return;let n=e!=null?e:pn;if(!n){console.warn("[sentient] grantConsent() called before init()");return}let r=re.get(n);if(!r){console.warn("[sentient] grantConsent() called before init()");return}let{config:o,upgrade:l,reinit:i}=r;if(!l){r.upgradeBlockedReason&&console.warn(r.upgradeBlockedReason);return}if(o.respectDoNotTrack!==!1&&Se())return;let a=(i!=null?i:Ne)(be(_({},o),{consent:!0}));l(a);let s=(t=re.get(n))==null?void 0:t.dispose;re.set(n,{config:be(_({},o),{consent:!0}),upgrade:null,dispose:s})}function Yr(e){var t;let n=e.preConsentBehavior==="statistical_winner",r=mn((t=e.ingestUrl)!=null?t:fn),o={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},l=new Map,i=new Map,a={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),assign(c,d,g){if(!n)return Promise.resolve(null);let w=l.get(c);return w?Promise.resolve(w):wt(i,c,async()=>{try{let p=new URLSearchParams({componentId:c});for(let C of d!=null?d:[])p.append("variantIds[]",C);let m=await fetch(`${r}/winner?${p.toString()}`,{headers:o});if(!m.ok)return d!=null&&d[0]?{variantId:d[0],assignmentTtlMs:0}:null;let A={variantId:(await m.json()).variantId,assignmentTtlMs:0};return l.set(c,A),A}catch(p){return d!=null&&d[0]?{variantId:d[0],assignmentTtlMs:0}:null}})},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},s={track:c=>a.track(c),goal:((c,d,g,w)=>a.goal(c,d,g,w)),componentGoal:(c,d,g)=>a.componentGoal(c,d,g),identify:c=>a.identify(c),getAssignment:(c,d)=>a.getAssignment(c,d),assign:(c,d,g,w)=>a.assign(c,d,g,w),decide:c=>a.decide(c),getSlotResult:c=>a.getSlotResult(c),getPersona:()=>a.getPersona(),fetchWeights:()=>a.fetchWeights(),getGraph:()=>a.getGraph(),dispose:()=>a.dispose(),destroy:()=>a.destroy()};function u(c){a=c}return{proxy:s,setInner:u}}function wt(e,t,n){let r=e.get(t);if(r)return r;let o=(async()=>{try{return await n()}finally{e.delete(t)}})();return e.set(t,o),o}function Ne(e){var t,n,r,o,l,i,a,s,u;if(typeof window=="undefined")return Te;pn=e.apiKey||"local";let c=re.get(e.apiKey||"local");if(c!=null&&c.dispose)try{c.dispose()}catch(h){}let d=e.respectDoNotTrack!==!1&&Se(),g=e.consent===!1||d,w=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!w&&e.localMode!==!1)return re.set(e.apiKey||"local",{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): this client is keyless/local \u2014 there is no hosted client to upgrade to. Configure a pk_ API key to enable tracking."}),g?Te:qr(e);if(g){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."),re.set(e.apiKey||"local",{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): the client was initialized with an invalid apiKey (expected a pk_ public key) \u2014 consent cannot enable tracking."}),Te;let{proxy:h,setInner:S}=Yr(e);return re.set(e.apiKey,{config:e,upgrade:d?null:S}),h}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."),Te;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),Te;let p=(t=e.ingestUrl)!=null?t:fn,m=Date.now(),A=an({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),C=Gr(void 0,e.apiKey),R=Br({ingestUrl:p,apiKey:e.apiKey}),f=mn(p),v={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},I=new Set,B=Kr({url:`${f}/goals`,apiKey:e.apiKey,headers:v,onDrop:(h,S)=>{if(!e.debug){if(I.has(S))return;I.add(S)}console.warn(`[sentient] goal dropped (HTTP ${S}) \u2014 this will not be retried. `+(S===400?"The session was not found: call init() and let the session upsert complete before firing goals.":S===401||S===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),h)}}),x=Wt((n=navigator.userAgent)!=null?n:""),N=window.location.origin,j=Ht((r=document.referrer)!=null?r:"",N),$=(o=e.sessionSegment)!=null?o:`${x}:${j}`,J=new Map,G=new Map,U=new Map,y=null,b=h=>{for(let S of h)U.has(S.id)||U.set(S.id,ht(S))};if(e.initialSlots)for(let[h,S]of Object.entries(e.initialSlots))U.set(h,S);let k=De(e.apiKey);if(k)for(let[h,S]of Object.entries(k.slots))U.has(h)||U.set(h,S);let O={low:.15,medium:.5,high:.85};if(e.initialPersona)y=_({},e.initialPersona);else{let h=document.documentElement.dataset;h.sentientPersona?y={persona:h.sentientPersona,confidence:(i=O[(l=h.sentientConfidence)!=null?l:"low"])!=null?i:.15}:k&&(y={persona:k.persona,confidence:(a=O[k.band])!=null?a:.15})}if(e.initialAssignments)for(let[h,S]of Object.entries(e.initialAssignments))C.set(h,$,{variantId:S,assignedAt:Date.now(),segment:$,confidence:1});let E=Promise.resolve(),oe=A.getSessionId();if(oe){let h=Vt((s=document.referrer)!=null?s:""),{utmParams:S,clickIds:D}=Jr(),ee=_(_(_(_({sessionId:oe,deviceClass:x,trafficSource:j,referrerDomain:h,utmParams:S,clickIds:D,timeOfDay:Yt(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:A.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||Ft((u=navigator.userAgent)!=null?u:"")},e.userId?{userId:e.userId}:{}),e.persona?{persona:e.persona}:{}),e.country?{country:e.country}:{}),e.sdk?{sdk:e.sdk.name,sdkVersion:e.sdk.version}:{}),F=async()=>{for(let L=0;;L++){try{let M=await fetch(`${f}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(ee),headers:v});if(M.status===402){console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing");return}if(M.ok||St(M)==="dropped")return}catch(M){}if(L>=Wr){console.warn("[SentientUI] Could not register the session after retries. Conversions in this visit may not be recorded.");return}await new Promise(M=>setTimeout(M,Pe(L+1)))}};try{E=F()}catch(L){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:R});let Y=Hr(),te=null,ne=!1,ie={goal(h,S={},D=1,ee=0){var F,L,M,X,Z,ve,fe;let Oe=A.getSessionId();if(!Oe)return;let Q=Fr(S)?S:{metadata:S},Le=[h,(F=Q.externalId)!=null?F:"",(L=Q.stepIndex)!=null?L:ee,(M=Q.weight)!=null?M:D].join("\0"),T=Q.value!==void 0?`${Q.value}\0${(X=Q.currency)!=null?X:""}`:null;if(Y.firedBefore(Le,T)){e.debug&&console.log(`[sentient] goal("${h}") already recorded for this action \u2014 not sent twice`);return}let le=vt(),qe={sessionId:Oe,name:h,metadata:(Z=Q.metadata)!=null?Z:{},weight:(ve=Q.weight)!=null?ve:D,stepIndex:(fe=Q.stepIndex)!=null?fe:ee,goalId:le,value:Q.value,currency:Q.currency,externalId:Q.externalId};e.debug&&console.log("[sentient] goal",qe);let W={id:le,body:JSON.stringify(qe)};E.then(()=>B.send(W))},componentGoal(h,S,D){var ee,F,L;let M=A.getSessionId();if(!M)return;let X=C.get(h,$),Z=X?null:(ee=U.get(h))!=null?ee:null;if(!X&&Z===null){e.debug&&console.warn(`[sentient] componentGoal("${h}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let ve=X?X.variantId:Xt(Z),fe={id:vt(),sessionId:M,projectId:e.apiKey,componentId:h,variantId:ve,eventType:"goal_achieved",goalType:S,payload:_({reward:(F=D==null?void 0:D.reward)!=null?F:1,goalValue:D==null?void 0:D.value,currency:D==null?void 0:D.currency},(L=D==null?void 0:D.metadata)!=null?L:{}),timestamp:Date.now(),timeInSession:Date.now()-m,path:Xe()};e.debug&&console.log("[sentient] componentGoal",fe),E.then(()=>R.push(fe))},identify(h){let S=A.getSessionId();S&&E.then(()=>{fetch(`${f}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:S,userId:h,ephemeral:A.isEphemeral()}),headers:v}).catch(()=>{})})},track(h){let S=A.getSessionId();if(!S)return;let D=be(_({path:Xe()},h),{id:vt(),sessionId:S,timestamp:Date.now(),timeInSession:Date.now()-m});e.debug&&console.log("[sentient] track",D),E.then(()=>R.push(D))},getAssignment(h,S){return C.get(h,S)},async assign(h,S,D,ee){let F=A.getSessionId();if(!F)return null;let L=C.get(h,$);if(L&&(S!=null&&S.length||L.content!==void 0)){let M=L.ttlMs&&L.ttlMs>0?Math.max(0,L.assignedAt+L.ttlMs-Date.now()):0;return{variantId:L.variantId,assignmentTtlMs:M,content:L.content}}return wt(J,h,async()=>{await E;try{let M={sessionId:F,componentId:h,variantIds:S};ee!==void 0?M.agentDataByVariant=ee:D!==void 0&&(M.agentData=D);let X=await fetch(`${f}/assign`,{method:"POST",body:JSON.stringify(M),headers:v});if(!X.ok)return null;let Z=await X.json();return C.set(h,$,_({variantId:Z.variantId,assignedAt:Date.now(),segment:$,confidence:1,content:Z.content},Z.assignmentTtlMs&&Z.assignmentTtlMs>0?{ttlMs:Z.assignmentTtlMs}:{})),Z}catch(M){return null}})},async decide(h){var S,D;let ee=A.getSessionId();if(!ee)return null;let F=(S=h.slots)!=null?S:[],L={sessionId:ee};h.sections&&h.sections.length>0&&(L.sections=h.sections.map(X=>({id:X}))),L.components=(D=h.components)!=null?D:[],F.length>0&&(L.slots=F.map(mt)),h.slotsFrom==="registry"&&(L.slotsFrom="registry"),h.v&&(L.v=h.v),typeof h.pp=="number"&&(L.pp=h.pp),e.persona&&(L.persona=e.persona);let M=JSON.stringify(L);return wt(G,M,async()=>{var X,Z,ve,fe,Oe,Q;await E;try{let Le=await fetch(`${f}/decide`,{method:"POST",body:M,headers:v});if(!Le.ok)return b(F),null;let T=await Le.json(),le={};for(let W of F){let pe=(X=T.slots)==null?void 0:X[W.id];if(pe!==void 0){le[W.id]=pe,U.set(W.id,pe);continue}let Tt=U.get(W.id);if(Tt!==void 0)le[W.id]=Tt;else{let Pt=ht(W);le[W.id]=Pt,U.set(W.id,Pt)}}if(T.slots)for(let[W,pe]of Object.entries(T.slots))W in le||(le[W]=pe,U.set(W,pe));let qe=y!=null&&y.persona!=="unknown";T.persona&&!(T.persona==="unknown"&&qe)?y={persona:T.persona,confidence:(Z=T.confidence)!=null?Z:0}:y||(y={persona:"unknown",confidence:0});for(let[W,pe]of Object.entries((ve=T.assignments)!=null?ve:{}))C.set(W,$,{variantId:pe,assignedAt:Date.now(),segment:$,confidence:1});return Me(e.apiKey,_(_({v:1,persona:y.persona,band:we(y.confidence),slots:Object.fromEntries(U),layoutOrder:(fe=T.layoutOrder)!=null?fe:null,savedAt:Date.now()},T.slotConfig?{slotConfig:T.slotConfig}:{}),T.palette?{palette:T.palette}:{})),_(_(_(_({layoutOrder:(Oe=T.layoutOrder)!=null?Oe:null,assignments:(Q=T.assignments)!=null?Q:{},slots:le,persona:y.persona,confidence:y.confidence},T.slotConfig?{slotConfig:T.slotConfig}:{}),T.goals?{goals:T.goals}:{}),T.sectionMap?{sectionMap:T.sectionMap}:{}),T.palette?{palette:T.palette}:{})}catch(Le){return b(F),null}})},getSlotResult(h){var S;return(S=U.get(h))!=null?S:null},getPersona(){return y?{persona:y.persona,confidence:y.confidence,band:we(y.confidence)}:null},async fetchWeights(){var h;try{let S=await fetch(`${f}/weights`,{headers:v});return S.ok?(h=(await S.json()).components)!=null?h:[]:[]}catch(S){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var h;te==null||te(),ne=!0,R.destroy(),B.destroy(),((h=re.get(e.apiKey))==null?void 0:h.dispose)===ie.dispose&&re.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var h;te==null||te(),ne=!0,R.destroy(),B.destroy(),A.destroy(),C.clear(),((h=re.get(e.apiKey))==null?void 0:h.dispose)===ie.dispose&&re.delete(e.apiKey);try{localStorage.removeItem(Ze+e.apiKey),localStorage.removeItem(cn(e.apiKey)),localStorage.removeItem(un(e.apiKey))}catch(S){}e.debug&&console.log("[sentient] destroyed")}};if(re.set(e.apiKey,{config:e,upgrade:null,dispose:ie.dispose}),te=Vr(ie,e.apiKey,h=>{E.then(()=>{ne||gn.add(h)})}),e.debug){let h=window;h.__sentient&&(h.__sentient.client=ie)}return ie}var Xr=["data-sentient-id","data-testid","data-test","data-id","data-name","data-cy"];function xt(e){var t;return((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim()}function Zr(e){return{tag:e.tagName.toLowerCase(),text:xt(e).slice(0,40)}}function hn(e){return e.replace(/["\\\]]/g,"\\$&")}function $e(e,t){try{return e.querySelectorAll(t).length===1}catch(n){return!1}}function yn(e,t){var n;let r=e.tagName.toLowerCase();if(!r)return null;let o=((n=e.getAttribute("class"))!=null?n:"").split(/\s+/).filter(a=>/^[a-zA-Z][\w-]*$/.test(a)),l=[r,...o.map(a=>`${r}.${a}`)];for(let a of l)if($e(t,a))return a;let i=e.parentElement;if(i&&i!==t){let a=yn(i,t);if(a){for(let d of l){let g=`${a} > ${d}`;if($e(t,g))return g}let s=Array.from(i.children).filter(d=>d.tagName.toLowerCase()===r),u=s.indexOf(e),c=s.some(d=>d!==e&&xt(d)!==xt(e));if(u>=0&&c){let d=`${a} > ${r}:nth-of-type(${u+1})`;if($e(t,d))return d}}}return null}function vn(e,t){let n=Zr(e),r=e.getAttribute("id");if(r&&$e(t,`#${hn(r)}`))return{v:1,id:r,fingerprint:n};for(let l of Xr){let i=e.getAttribute(l);if(i&&$e(t,`[${l}="${hn(i)}"]`))return{v:1,dataAttr:{name:l,value:i},fingerprint:n}}let o=yn(e,t);return o?{v:1,selector:o,fingerprint:n}:null}Re();var wn=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Qr={banner:"hero",navigation:"navigation",contentinfo:"footer"};function eo(e){let t=e.ariaRole?Qr[e.ariaRole.toLowerCase()]:void 0;if(t)return t;if(e.tag==="nav")return"navigation";if(e.tag==="footer")return"footer";if(e.tag==="header")return e.actionCount>=5?"navigation":"hero";let n=`${e.idClass} ${e.headingText}`.toLowerCase();return/\b(navbar|nav-bar|navigation|site-nav|main-nav|topbar|footer)\b/.test(n)?/footer/.test(n)?"footer":"navigation":/\b(hero|masthead|jumbotron)\b/i.test(e.idClass)?"hero":null}function to(e){return e.actionCount>=1&&e.textLength>0&&e.textLength<200?"cta":"generic"}var no=[["pricing",/\b(pricing|price list|per month|\/mo|subscriptions?)\b|\bplans?\b(?=[^.]{0,40}(from|start|month|year|[$€£]))/i],["faq",/\bfaq\b|frequently asked|common questions?/i],["comparison",/\b(compare|comparison|versus)\b|\bvs\./i],["social_proof",/\b(reviews?|ratings?|testimonial|brands?|galler(y|ies)|logos)\b|trusted by|loved by|case stud|what our customers say/i],["trust",/\b(insurance|warrant(y|ies)|guarantees?|certifi|accredit|security|privacy|compliance|gdpr|encrypt)\b|why choose|about us|our team/i],["cta",/\b(book|booking|reserve|appointments?|newsletter|subscribe)\b|contact us|get in touch|opening hours/i],["features",/\b(features?|benefits?|capabilit|services?|repairs?|menus?|products?)\b|how it works|our process|what we (do|offer)|what you get/i]],kt=[["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|free returns?|returns? within|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]],bn={navigation:"navigation",footer:"navigation",hero:"hero",cta:"cta",generic:"generic"};function ro(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function Sn(e){var t,n;let r=eo(e);if(r)return{type:(t=bn[r])!=null?t:"generic",strength:"strong"};let o=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[i,a]of no)if(a.test(o))return{type:i,strength:"strong"};for(let[i,a]of kt)if(a.test(e.bodyText))return{type:i,strength:"strong"};let l=to(e);return{type:(n=bn[l])!=null?n:"generic",strength:"weak"}}function An(e){var t,n;let r=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim(),o=e.getAttribute("role");return _({tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:ro(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length},o?{ariaRole:o}:{})}Re();var oo="section, header, footer, nav, main > div, [data-sentient-section]",io=2e4;function ao(e){let t=Array.from(e.querySelectorAll(oo)),n=t.filter(r=>t.filter(o=>o!==r&&r.contains(o)).length<2);return n.filter(r=>!n.some(o=>o!==r&&o.contains(r)))}function so(e,t,n,r){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:r})}).catch(()=>{})}catch(o){}}var xn=()=>{};function kn(e,t){var n,r,o,l,i,a,s,u,c,d,g,w;let p=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!p||typeof IntersectionObserver=="undefined"||Se()||!t.apiKey||!t.apiKey.startsWith("pk_"))return xn;let m=((r=t.apiBase)!=null?r:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),A=ao(p);if(A.length===0)return xn;let C=new Map,R=[];for(let b of A){let k=b.getAttribute("data-sentient-type"),O=k&&wn.includes(k)?k:null,E=An(b),oe=(l=O!=null?O:(o=t.typeOf)==null?void 0:o.call(t,b))!=null?l:Sn(E).type,Y=vn(b,p),te=Y?`nc-${oe}-${zt(JSON.stringify({id:(i=Y.id)!=null?i:null,dataAttr:(a=Y.dataAttr)!=null?a:null,selector:(s=Y.selector)!=null?s:null})).toString(36)}`:`nc-${oe}`;C.set(b,te);let ne=kt.filter(([,ie])=>ie.test(E.bodyText)).map(([ie])=>ie);R.push(be(_({componentId:te,semanticType:oe,source:O?"markup":"auto"},Y?{locator:Y}:{}),{observation:_(_({tag:E.tag,idClass:E.idClass.slice(0,200),headingText:E.headingText,textLength:E.textLength,actionCount:E.actionCount},E.ariaRole?{ariaRole:E.ariaRole}:{}),ne.length>0?{patternFlags:ne}:{})}))}let f=(g=(d=(c=(u=p.defaultView)!=null?u:typeof window!="undefined"?window:void 0)==null?void 0:c.location)==null?void 0:d.pathname)!=null?g:"/";so(t.apiKey,m,f,R);let v=new Map,I=b=>{let k=v.get(b);return k||(k={ms:0,scroll:0,enterAt:null,intersecting:!1},v.set(b,k)),k},B=new IntersectionObserver(b=>{for(let k of b){let O=C.get(k.target);if(!O)continue;let E=I(O);k.isIntersecting?(E.intersecting=!0,E.enterAt=Date.now(),k.intersectionRatio>E.scroll&&(E.scroll=k.intersectionRatio)):(E.intersecting=!1,E.enterAt!=null&&(E.ms+=Date.now()-E.enterAt,E.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let b of C.keys())B.observe(b);let x=()=>{let b=Date.now();for(let[k,O]of v)if(O.enterAt!=null&&(O.ms+=b-O.enterAt,O.enterAt=null),!(O.ms<=0)){try{e.track({projectId:t.apiKey,componentId:k,eventType:"dwell",payload:{dwell_time:Math.round(O.ms),scroll_depth:Number(O.scroll.toFixed(2))}})}catch(E){}O.ms=0}},N=()=>{if(p.hidden)x();else{let b=Date.now();for(let k of v.values())k.intersecting&&(k.enterAt=b)}},j=!1,$=b=>{if(x(),b!=null&&b.persisted){j=!0;return}try{B.disconnect()}catch(k){}},J=b=>{if(!(b!=null&&b.persisted)||!j)return;j=!1;let k=Date.now();for(let O of v.values())O.enterAt=O.intersecting&&!p.hidden?k:null};p.addEventListener("visibilitychange",N);let G=(w=p.defaultView)!=null?w:typeof window!="undefined"?window:void 0;G==null||G.addEventListener("pagehide",$),G==null||G.addEventListener("pageshow",J);let U=setInterval(()=>{if(p.hidden||j)return;x();let b=Date.now();for(let k of v.values())k.intersecting&&(k.enterAt=b)},io),y=[];return t.microSignals&&[...C.entries()].forEach(([b,k],O)=>{y.push(Be((E,oe={})=>{try{e.track({projectId:t.apiKey,componentId:k,eventType:"micro_signal",payload:_({signalType:E},oe)})}catch(Y){}},b,void 0,{tabLoss:O===0}))}),()=>{x(),clearInterval(U),p.removeEventListener("visibilitychange",N),G==null||G.removeEventListener("pagehide",$),G==null||G.removeEventListener("pageshow",J);for(let b of y)b();try{B.disconnect()}catch(b){}}}var lo=["landing","ecommerce","saas","marketplace"];function co(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t=Object.entries(e);if(t.length<1||t.length>4)return null;let n={};for(let[r,o]of t){if(!Array.isArray(o)||o.length<2||o.length>6||!o.every(l=>typeof l=="string"))return null;n[r]=o}return n}function uo(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function fo(e){try{return e()}catch(t){return}}function Qe(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=lo.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[i,a]of Object.entries(t.slots)){if(typeof a!="object"||a===null)continue;let s=a,u=co(s.dims);if(!u||s.target!==void 0&&typeof s.target!="string")continue;let c=s.arms!==void 0?uo(s.arms):null,d={dims:u};typeof s.target=="string"&&(d.target=s.target),c&&(d.arms=c),r[i]=d}let o={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};typeof t.consent=="boolean"&&(o.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(o.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(o.debug=!0),typeof t.registry=="boolean"&&(o.registry=t.registry),typeof t.editorSrc=="string"&&(o.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(o.apiBase=t.apiBase),typeof t.sectionCapture=="boolean"&&(o.sectionCapture=t.sectionCapture);let l=typeof t.persona=="function"?fo(t.persona):t.persona;if(typeof l=="string"&&l.trim()!==""&&(o.persona=l),Array.isArray(t.sections)){let i=t.sections.filter(a=>typeof a=="string"&&a.trim()!=="").slice(0,50);i.length>=2&&(o.sections=i)}return o}function et(e){var n,r,o;let t=(r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:r.location;return(o=t==null?void 0:t.pathname)!=null?o:""}function po(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:"").replace(/\s+/g," ").trim().toLowerCase(),o=t.text.replace(/\s+/g," ").trim().toLowerCase();if(!(r===o||r.startsWith(o)||o.startsWith(r)))return!1}return!0}function En(e,t){return!!(e!=null&&e.urlMatch)&&!et(t).includes(e.urlMatch)}var go=/^[a-zA-Z_][-a-zA-Z0-9_]*$/;function ge(e,t){var o;if(e.urlMatch&&!et(t).includes(e.urlMatch))return null;let n=[];if(e.id){let l=t.getElementById(e.id);n=l?[l]:[]}if(n.length===0&&((o=e.dataAttr)!=null&&o.name)&&go.test(e.dataAttr.name))try{let l=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${l}"]`))}catch(l){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(l){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!po(r,e.fingerprint)?null:r}var Cn={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"},mo=/^(rgb|rgba|hsl|hsla|calc|var|min|max|clamp)$/i;function _n(e){var r;if(e.trim().length===0||/[;{}<>]/.test(e))return!1;let t=/([A-Za-z-]*)\(/g,n;for(;(n=t.exec(e))!==null;)if(!mo.test((r=n[1])!=null?r:""))return!1;return!0}var In=/^https:\/\//i,On=new Map,me=null;function ho(e){return e.replace(/["\\]/g,"\\$&")}function yo(e){var t;(!me||!me.isConnected)&&(me=e.querySelector("style[data-sentient-ops]"),me||(me=e.createElement("style"),me.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(me))),me.textContent=[...On.entries()].map(([n,r])=>`[data-snt-e="${ho(n)}"]{${r}}`).join(`
2
+ `)}function Ln(e,t,n,r){var a;let o=!1,l=(a=t.moveBefore)!=null?a:t.moveAfter;if(l){let s=ge(l,r);!s||s===e||s.parentElement!==e.parentElement||!e.parentElement?o=!0:t.moveBefore?e.parentElement.insertBefore(e,s):e.parentElement.insertBefore(e,s.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&In.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&In.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let i=[];if(t.hidden&&i.push("display:none !important"),t.style)for(let[s,u]of Object.entries(t.style)){let c=Cn[s];c&&typeof u=="string"&&_n(u)&&i.push(`${c}:${u.trim()} !important`)}return i.length>0&&(e.setAttribute("data-snt-e",n),On.set(n,i.join(";")),yo(r)),{anchorMiss:o}}var Ke="data-sentient-block-arm",ae=null;function je(e){ae=e!=null?e:null}var ue="data-sentient-blocks-hid",tt={none:"0",sm:"8px",md:"16px",lg:"24px"},Et={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch",between:"space-between"},Rn={sm:"0.875em",md:"1em",lg:"1.25em"},vo={sm:"1.25em",md:"1.5em",lg:"2em"},bo={sm:"6px 14px",md:"10px 20px",lg:"14px 28px"},Tn={sm:"8px",md:"16px",lg:"32px"},wo={square:"1 / 1",landscape:"4 / 3",wide:"16 / 9"},So={normal:"400",medium:"500",bold:"700"};function ce(e,t){for(let[n,r]of Object.entries(t))r!==void 0&&e.style.setProperty(n,r);return e}function Pn(e){return{opacity:e==="muted"?"0.7":void 0,"font-weight":e==="accent"?"600":void 0}}function Dn(e,t){var n,r,o,l,i,a,s,u,c,d,g,w;try{switch(e.type){case"stack":case"grid":{let p=t.createElement("div");if(e.type==="stack"){let m=e;ce(p,{display:"flex","flex-direction":m.direction,gap:(r=tt[(n=m.gap)!=null?n:"md"])!=null?r:tt.md,"align-items":m.align?Et[m.align]:void 0,"justify-content":m.justify?Et[m.justify]:void 0,"flex-wrap":m.wrap?"wrap":void 0})}else{let m=e,A=(l=tt[(o=m.gap)!=null?o:"md"])!=null?l:tt.md;ce(p,{display:"grid","grid-template-columns":`repeat(auto-fit, minmax(max(200px, calc((100% - ${m.columns-1} * ${A}) / ${m.columns})), 1fr))`,gap:A,"align-items":m.align?Et[m.align]:void 0})}for(let m of(i=e.children)!=null?i:[]){let A=Dn(m,t);A&&p.appendChild(A)}return p}case"text":{let p=t.createElement("p");return p.textContent=e.value,ce(p,H({margin:"0","font-size":e.size?Rn[e.size]:void 0,"font-weight":e.weight?So[e.weight]:void 0,"text-align":e.align},Pn(e.tone)))}case"heading":{let p=t.createElement(`h${e.level}`);return p.textContent=e.value,ce(p,{margin:"0","font-size":vo[(a=e.size)!=null?a:"md"],"text-align":e.align})}case"button":{let p=t.createElement("a");p.textContent=e.label,p.href=e.href,e.tag&&p.setAttribute("data-sentient-tag",e.tag);let m=(s=e.emphasis)!=null?s:"primary";return ce(p,{display:"inline-block",padding:bo[(u=e.size)!=null?u:"md"],"border-radius":(c=ae==null?void 0:ae.radius)!=null?c:"8px",font:"inherit","font-size":e.size?Rn[e.size]:void 0,"text-decoration":m==="ghost"?"underline":"none",cursor:"pointer",background:m==="primary"?(d=ae==null?void 0:ae.primaryBg)!=null?d:"#111827":"transparent",color:m==="primary"?(g=ae==null?void 0:ae.primaryText)!=null?g:"#ffffff":"inherit",border:m==="secondary"?"1px solid currentColor":"none"})}case"link":{let p=t.createElement("a");return p.textContent=e.label,p.href=e.href,e.tag&&p.setAttribute("data-sentient-tag",e.tag),ce(p,{color:"inherit","text-decoration":"underline"})}case"image":{let p=t.createElement("img");return p.src=e.src,p.alt=e.alt,ce(p,{display:"block","max-width":"100%","aspect-ratio":e.ratio&&e.ratio!=="auto"?wo[e.ratio]:void 0,"object-fit":e.fit,width:e.ratio&&e.ratio!=="auto"?"100%":void 0})}case"badge":{let p=t.createElement("span");return p.textContent=e.value,ce(p,H({display:"inline-block",padding:"2px 10px","border-radius":"999px","font-size":"0.75em",border:"1px solid currentColor"},Pn(e.tone)))}case"spacer":return ce(t.createElement("div"),{height:(w=Tn[e.size])!=null?w:Tn.md});default:return null}}catch(p){return null}}function Mn(e,t,n,r){try{let o=new Set;for(let i of Array.from(e.children)){let a=i.getAttribute(Ke);a!==null&&(t[a]===void 0?i.remove():o.add(a))}for(let[i,a]of Object.entries(t)){if(o.has(i))continue;let s=Dn(a,r);if(!s)continue;let u=r.createElement("div");u.setAttribute(Ke,i),u.style.display="none",u.appendChild(s),e.appendChild(u)}let l=n!==void 0&&t[n]!==void 0;for(let i of Array.from(e.children)){let a=i.getAttribute(Ke),s=i;a!==null?s.style.display=l&&a===n?"":"none":l?s.hasAttribute(ue)||(s.setAttribute(ue,s.style.display),s.style.display="none"):s.hasAttribute(ue)&&(s.style.display=s.getAttribute(ue),s.removeAttribute(ue))}}catch(o){}}function Ao(e){try{for(let t of Array.from(e.children)){let n=t;if(n.getAttribute(Ke)!==null){n.remove();continue}n.hasAttribute(ue)&&(n.style.display=n.getAttribute(ue),n.removeAttribute(ue))}}catch(t){}}function nt(e,t){try{let n=new Set;for(let r of Array.from(e.querySelectorAll(`[${Ke}]`)))r.parentElement&&n.add(r.parentElement);for(let r of Array.from(e.querySelectorAll(`[${ue}]`)))r.parentElement&&n.add(r.parentElement);for(let r of n)t.has(r)||Ao(r)}catch(n){}}function Ct(e,t){if(!e)return[t.documentElement];try{return Array.from(t.querySelectorAll(e))}catch(n){return[]}}function rt(e,t,n,r){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t),r==null||r(n.documentElement,"data-sentient-persona"),r==null||r(n.documentElement,"data-sentient-confidence")}function ot(e,t,n,r){var o;for(let[l,i]of Object.entries(t)){let a=e[l];if(!a||typeof a=="string")continue;let s=Ct(i.target,n);for(let u of s)for(let[c,d]of Object.entries(a))(o=i.dims[c])!=null&&o.includes(d)&&(u.setAttribute(`data-${c}`,d),r==null||r(u,`data-${c}`))}}function it(e,t,n,r){for(let[o,l]of Object.entries(t)){let i=e[o];if(typeof i!="string"||!l.arms||!l.arms.includes(i))continue;let a=Ct(l.target,n);for(let s of a)s.setAttribute("data-sentient-arm",i),r==null||r(s,"data-sentient-arm")}}function at(e,t,n,r){var a,s,u,c;let o=new Set,l=(a=r==null?void 0:r.contentAndOps)!=null?a:!0,i=[];for(let[d,g]of Object.entries(t)){if(En(g.locator,n))continue;let w;if(g.locator){let m=ge(g.locator,n);w=m?[m]:[]}else w=Ct(g.target,n);(g.locator||g.target)&&w.length===0&&i.push(d);let p=e[d];for(let m of w){if(p!==void 0)if(typeof p=="string")m.setAttribute("data-sentient-arm",p),(s=r==null?void 0:r.onAttr)==null||s.call(r,m,"data-sentient-arm"),l&&((u=r==null?void 0:r.onApplied)==null||u.call(r,d,p,m));else for(let[A,C]of Object.entries(p))m.setAttribute(`data-${A}`,C),(c=r==null?void 0:r.onAttr)==null||c.call(r,m,`data-${A}`);g.blocks&&!ko(n)&&(Mn(m,g.blocks,typeof p=="string"?p:void 0,n),o.add(m)),l&&(typeof g.content=="string"&&(m.textContent=g.content),g.ops&&Ln(m,g.ops,d,n).anchorMiss&&!i.includes(d)&&i.push(d))}}return nt(n,o),i}var xo=/bot|crawler|spider|crawling|googlebot|bingbot|duckduckbot|baiduspider|yandexbot|slurp|gptbot|claudebot|anthropic|perplexity|ccbot|applebot|headlesschrome/i;function ko(e){var t,n,r;try{let o=(n=(t=e.defaultView)!=null?t:typeof window!="undefined"?window:void 0)==null?void 0:n.navigator;return o?o.webdriver===!0?!0:xo.test((r=o.userAgent)!=null?r:""):!1}catch(o){return!1}}var Eo=800;function st(e,t,n){let r=[];return n.forEach(({slotId:o,arm:l,el:i},a)=>{r.push(Be((g,w={})=>{try{e.track({projectId:t,componentId:o,variantId:l,eventType:"micro_signal",payload:H({signalType:g},w)})}catch(p){}},i,void 0,{tabLoss:a===0}));let s=null,u=0,c=()=>{u=Date.now(),s=setTimeout(()=>{try{e.track({projectId:t,componentId:o,variantId:l,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-u}})}catch(g){}s=null},Eo)},d=()=>{s!==null&&(clearTimeout(s),s=null)};i.addEventListener("mouseenter",c),i.addEventListener("mouseleave",d),r.push(()=>{i.removeEventListener("mouseenter",c),i.removeEventListener("mouseleave",d),s!==null&&clearTimeout(s)})}),()=>{for(let o of r)o()}}function Co(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 Nn(e){return e?`_snt_fired_goals_${e.slice(0,12)}`:"_snt_fired_goals"}var _o="_snt_fired_goals";function $n(e,t){try{e==null||e.sessionStorage.removeItem(Nn(t)),e==null||e.sessionStorage.removeItem(_o)}catch(n){}}function Bn(e){var t;return[(t=e.slotId)!=null?t:"",e.goalId,e.event,e.locator?JSON.stringify(e.locator):""].join("|")}function Io(e,t){try{let n=e==null?void 0:e.sessionStorage.getItem(t);if(!n)return new Set;let r=JSON.parse(n);return Array.isArray(r)?new Set(r.filter(o=>typeof o=="string")):new Set}catch(n){return new Set}}function Oo(e,t,n){try{e==null||e.sessionStorage.setItem(t,JSON.stringify([...n]))}catch(r){}}function lt(e,t,n,r){var C,R;let o=(C=n.defaultView)!=null?C:typeof window!="undefined"?window:null,l=Nn(r),i=Io(o,l),a=f=>{let v=Bn(f);if(!i.has(v))try{f.slotId?t.componentGoal(f.slotId,f.goalId):t.goal(f.goalId),i.add(v),Oo(o,l,i)}catch(I){}},s=e.filter(f=>f.event==="click"),u=e.filter(f=>f.event==="form_submit"),c=e.filter(f=>f.event==="url_reached"),d=e.filter(f=>f.event==="scroll_depth"),g=(f,v)=>{if(!f.locator)return!1;let I=ge(f.locator,n);return!!I&&(I===v||I.contains(v))},w=f=>{let v=f.target;if(!(!v||typeof v.closest!="function"))for(let I of s)g(I,v)&&a(I)},p=f=>{let v=f.target;if(v)for(let I of u)g(I,v)&&a(I)},m=()=>{if(c.length===0)return;let f=et(n);for(let v of c)v.urlPattern&&Co(v.urlPattern,f)&&a(v)},A=()=>{var I;let f=n.documentElement,v=f.scrollHeight>0?(f.scrollTop+f.clientHeight)/f.scrollHeight:0;for(let B of d)v>=((I=B.threshold)!=null?I:.75)&&a(B);d.every(B=>i.has(Bn(B)))&&n.removeEventListener("scroll",A)};return n.addEventListener("click",w,!0),n.addEventListener("submit",p,!0),(R=n.defaultView)==null||R.addEventListener("popstate",m),m(),d.length>0&&(n.addEventListener("scroll",A,{passive:!0}),A()),{checkUrl:m,teardown:()=>{var f;n.removeEventListener("click",w,!0),n.removeEventListener("submit",p,!0),(f=n.defaultView)==null||f.removeEventListener("popstate",m),d.length>0&&n.removeEventListener("scroll",A)}}}function ct(e,t){if(!e||e.length<2||t.size!==e.length)return null;let n=[];for(let i of e){let a=t.get(i);if(!a||n.includes(a))return null;n.push(a)}let r=n[0].parentNode;if(!r||!n.every(i=>i.parentNode===r))return null;let o=n.slice().sort((i,a)=>i.compareDocumentPosition(a)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),l=[];for(let i=0;i<n.length;i++){let a=n[i];o[i]!==a&&(l.push({el:a,before:o[i]}),o.splice(o.indexOf(a),1),o.splice(i,0,a))}return l}var Kn="__snt_editor_token";function jn(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(Kn):null}catch(e){return null}}function Gn(e){try{sessionStorage.setItem(Kn,e)}catch(t){}}var ze="0.24.0",ft=ze!=="0.0.0-dev"?{name:"snippet",version:ze}:void 0,Jn=5e3,Lo=50,Yn=(()=>{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,P=null,de={},ye=null,z=null,he=null,q=null,se=null,K=null,Ae=null,Un=!1,_t=null,ut=null,pt=null,Ce=!1,Ge=!1,ke=!1;function Xn(e,t){let n,r=new Promise(o=>{n=setTimeout(()=>o(null),t)});return Promise.race([e,r]).then(o=>(clearTimeout(n),o),o=>{throw clearTimeout(n),o})}function xe(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function _e(e,t){return V?(V.personaAttributes&&K&&rt(K.persona,K.band,e,t==null?void 0:t.onAttr),ot(de,V.slots,e,t==null?void 0:t.onAttr),it(de,V.slots,e,t==null?void 0:t.onAttr),ye?at(de,ye,e,t):(nt(e,new Set),[])):[]}function Zn(e){var n;let t=new Map;for(let r of(n=V==null?void 0:V.sections)!=null?n:[])try{let o=e.querySelectorAll(r);o.length===1&&t.set(r,o[0])}catch(o){}return t}function It(e,t){var n,r;try{if(!e||e.length<2)return;for(let o of(n=ct(e,Zn(t)))!=null?n:[])(r=o.before.parentNode)==null||r.insertBefore(o.el,o.before)}catch(o){}}function Ro(e,t,n){let r=(o,l)=>t.some(([i,a])=>i===o&&a===l);try{if(Array.isArray(e.stamped))for(let o of e.stamped){if(!Array.isArray(o))continue;let[l,i,a]=o;!l||typeof i!="string"||r(l,i)||(a==null?l.removeAttribute(i):l.setAttribute(i,a))}if(Array.isArray(e.html))for(let o of e.html)typeof o!="string"||r(n.documentElement,o)||n.documentElement.removeAttribute(o)}catch(o){}}function To(){try{let e=window.__sntPP;return e&&typeof e=="object"&&typeof e.v=="number"?e:null}catch(e){return null}}function Qn(e){return e.apiBase?`${e.apiBase.replace(/\/+$/,"")}/v1/events`:void 0}function Po(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 Ie(){return!!(V&&P&&V.sectionCapture!==!1&&(V.consent!==!1||Ge)&&!Se())}function Do(){if(!P||!V||!Ie()||se)return;let e=[];_e(document,{contentAndOps:Ce,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),Lt();try{q==null||q(),q=st(P,V.apiKey,e)}catch(t){}}function Lt(){if(typeof document=="undefined"||!Ie())return;let e;try{if(ut&&ut.length>0){let t=new Map;for(let n of ut){if(n.urlMatch!==window.location.pathname)continue;let r=ge(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{se=kn(P,H({apiKey:V.apiKey,apiBase:V.apiBase,doc:document,microSignals:!0},e?{typeOf:e}:{})),pt=window.location.pathname}catch(t){}}function Rt(){try{let e=[];if(q==null||q(),q=null,_e(document,{contentAndOps:Ce,onApplied:(t,n,r)=>e.push({slotId:t,arm:n,el:r})}),It(Ae,document),e.length>0&&Ie())try{q=st(P,V.apiKey,e)}catch(t){}try{typeof window!="undefined"&&pt!==null&&window.location.pathname!==pt&&Ie()&&(se==null||se(),se=null,Lt())}catch(t){}}catch(e){}}function zn(){_t===null&&(_t=setTimeout(()=>{_t=null,Rt();try{z==null||z.checkUrl()}catch(e){}},Lo))}function Ot(){if(!(Un||typeof window=="undefined"||typeof history=="undefined")){Un=!0;try{let e=t=>{let n=history[t];history[t]=function(r,o,l){let i=n.call(this,r,o,l!=null?l:null);return zn(),i}};e("pushState"),e("replaceState"),window.addEventListener("popstate",zn)}catch(e){}}}function dt(e){let t={};for(let[n,r]of Object.entries(e.slots))try{t[n]=r.target?document.querySelectorAll(r.target).length:1}catch(o){t[n]=0}return t}function er(e){return new URLSearchParams(e).get("sentient_editor")}function Mo(){try{let e=Array.from(document.getElementsByTagName("script")),t=/(^|\/)snippet(\.global)?\.js(\?|$)/,n=e.find(r=>t.test(r.src));if(n!=null&&n.src)return n.src.replace(t,"$1editor.global.js$3")}catch(e){}return null}function Bo(e,t){var n,r,o,l;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let s=document.createElement("meta");s.name="referrer",s.content="no-referrer",s.setAttribute("data-sentient-editor",""),((r=document.head)!=null?r:document.documentElement).appendChild(s)}catch(s){}let i=(o=e.editorSrc)!=null?o:Mo();if(!i){Fn();return}let a=document.createElement("script");a.src=i,a.async=!0,a.onerror=()=>Fn(),((l=document.head)!=null?l:document.documentElement).appendChild(a)}catch(i){}}var qn="sentient-editor-load-notice",tr={position:"fixed",bottom:"16px",zIndex:"2147483647",background:"#111827",color:"#fff",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"};function Fn(){var e,t;try{if(typeof document=="undefined"||document.getElementById(qn))return;(e=document.querySelector('meta[name="referrer"][data-sentient-editor]'))==null||e.remove();let n=document.createElement("div");n.id=qn,n.textContent="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.",Object.assign(n.style,tr,{right:"16px",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",cursor:"pointer"}),n.addEventListener("click",()=>n.remove()),((t=document.body)!=null?t:document.documentElement).appendChild(n),setTimeout(()=>n.remove(),1e4)}catch(n){}}function nr(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let o=r.indexOf(":"),l=o===-1?"":r.slice(0,o),i=o===-1?"":r.slice(o+1);if(!(!l||!i))if(i.includes("=")){let a={};for(let s of i.split(",")){let[u,c]=s.split("=");u&&c&&(a[u]=c)}Object.keys(a).length&&(n[l]=a)}else n[l]=i}return Object.keys(n).length?n:null}function rr(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var Wn="sentient-persona-preview-banner";function Hn(e,t){var n;try{if(typeof document=="undefined"||document.getElementById(Wn))return;let r=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),o=document.createElement("div");o.id=Wn,o.setAttribute("role","status"),Object.assign(o.style,tr,{left:"50%",transform:"translateX(-50%)",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",font:"13px/1 system-ui, sans-serif",border:"1px solid rgba(255,255,255,0.14)"});let l=document.createElement("span");l.textContent=t?`\u201C${e}\u201D isn\u2019t in your personas \u2014 showing the default experience`:`Previewing as ${r}`;let i=document.createElement("button");i.type="button",i.textContent="Exit preview",Object.assign(i.style,{cursor:"pointer",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"inherit",padding:"4px 10px",borderRadius:"999px"}),i.addEventListener("click",()=>{try{let a=new URL(window.location.href);a.searchParams.delete("sentient_persona"),window.location.href=a.pathname+a.search+a.hash}catch(a){}}),o.appendChild(l),o.appendChild(i),((n=document.body)!=null?n:document.documentElement).appendChild(o)}catch(r){}}async function No(e,t){var u,c,d,g,w,p,m,A,C,R;let n=(u=e.apiBase)!=null?u:"https://api.sentient-ui.com",o=((c=e.registry)!=null?c:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([f,v])=>({id:f,dims:v.dims}))},l=await Xn(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(o)}).then(f=>f.ok?f.json():null).catch(()=>null),Jn);if(!l){Ue(e),xe(e,"persona preview: explain unavailable \u2014 page left as-is");return}let i=l;de=(d=i.slots)!=null?d:{},ye=(g=i.slotConfig)!=null?g:null,je(i.palette);let a=(m=(p=(w=i.personaAttributes)==null?void 0:w.persona)!=null?p:i.persona)!=null?m:t,s=(C=(A=i.personaAttributes)==null?void 0:A.confidence)!=null?C:"high";K={persona:a,band:s},_e(document),Ce=!0,Ot(),Ue(e),i.recognized===!1?Hn(t,!0):Hn((R=i.personaDisplay)!=null?R:a)}function Ue(e){let t={goal(n,r){try{P==null||P.goal(n,r)}catch(o){}},componentGoal(n,r){try{P==null||P.componentGoal(n,r)}catch(o){}},grantConsent(){try{!P&&ke?(P=Ne(H({apiKey:e.apiKey,context:e.context,consent:!0,preConsentBehavior:e.preConsentBehavior,debug:e.debug,persona:e.persona,ingestUrl:Qn(e)},ft?{sdk:ft}:{})),he&&he.length>0&&(z==null||z.teardown(),z=lt(he,P,document,e.apiKey))):(At(e.apiKey),P&&he&&he.length>0&&(z==null||z.teardown(),z=lt(he,P,document,e.apiKey))),ke=!1}catch(n){}Ge=!0;try{Do()}catch(n){}},revokeConsent(){try{se==null||se(),se=null,pt=null,q==null||q(),q=null,z==null||z.teardown(),z=null,$n(typeof window!="undefined"?window:null,e.apiKey),Ge=!1,ke=!0,P==null||P.destroy(),P=null}catch(n){}},reapply:Rt,getState(){var n,r;try{return{apiKey:e.apiKey,persona:(n=K==null?void 0:K.persona)!=null?n:null,band:(r=K==null?void 0:K.band)!=null?r:null,slots:de,matchCounts:dt(e),consent:!ke&&(e.consent!==!1||Ge)}}catch(o){return{apiKey:e.apiKey,persona:null,band:null,slots:{},matchCounts:{},consent:!1}}}};window.SentientSnippet=t;for(let n of Yn.splice(0))try{n[0]==="goal"&&t.goal(n[1],n[2])}catch(r){}}function Vn(){var e;try{if(typeof window=="undefined")return;let t=window;if(typeof((e=t.SentientSnippet)==null?void 0:e.goal)=="function")return;let n=()=>{};t.SentientSnippet={goal:n,componentGoal:n,grantConsent:n,revokeConsent:n,reapply:n,getState:()=>({apiKey:"",persona:null,band:null,slots:{},matchCounts:{},consent:!1})},Yn.length=0}catch(t){}}async function or(){var e,t;try{let n=Qe(window.sentient);if(!n){Vn();return}V=n,Ce=!1,Ae=null,je(null),Ge=!1,ke=!1,he=null;let r=typeof window!="undefined"?er(window.location.search):null;if(r){Gn(r);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 o=r!=null?r:jn();if(o){Bo(n,o),Ue(n),xe(n,"editor mode");return}let l=typeof window!="undefined"?nr(window.location.search):null;if(l){de=l,K=null,_e(document),Ot(),Ue(n),xe(n,"preview mode",l);return}let i=typeof window!="undefined"?rr(window.location.search):null;if(i){await No(n,i),xe(n,"persona preview",i);return}let a=(e=n.registry)!=null?e:Object.keys(n.slots).length===0,s=To();try{(t=s==null?void 0:s.stop)==null||t.call(s)}catch(f){}let u=De(n.apiKey),c=[];u&&(K={persona:u.persona,band:u.band},de=u.slots,u.slotConfig&&(ye=u.slotConfig),u.palette&&je(u.palette),_e(document,H({contentAndOps:!1},s?{onAttr:(f,v)=>c.push([f,v])}:{})),u.layoutOrder&&(Ae=u.layoutOrder,It(Ae,document))),s&&Ro(s,c,document);let d=Ne(H({apiKey:n.apiKey,context:n.context,consent:n.consent,preConsentBehavior:n.preConsentBehavior,debug:n.debug,persona:n.persona,ingestUrl:Qn(n)},ft?{sdk:ft}:{}));P=d,Ue(n),Ot();let g=Object.entries(n.slots).map(([f,v])=>({id:f,dims:v.dims})),w=ze!=="0.0.0-dev"?{v:ze}:{},p={pp:s?s.v:0},m=Array.from(Zn(document).keys()),A=d.decide(H(H(H(H({slots:g},w),p),m.length>=2?{sections:m}:{}),a?{slotsFrom:"registry"}:{})),C=await Xn(A,Jn),R=f=>{var B,x,N,j,$,J;let v=d.getPersona();v?K={persona:v.persona,band:v.band}:f.persona&&(K={persona:f.persona,band:"low"}),de=f.slots,a?ye=(B=f.slotConfig)!=null?B:null:f.slotConfig&&(ye=f.slotConfig),f.palette&&je(f.palette),Ae=(x=f.layoutOrder)!=null?x:Ae;let I=()=>{let G=[];if(Po(n,_e(document,{onApplied:(U,y,b)=>G.push({slotId:U,arm:y,el:b})})),It(Ae,document),Ce=!0,Ie())try{q==null||q(),q=st(P,n.apiKey,G)}catch(U){}};if(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",I,{once:!0}):I(),he=(N=f.goals)!=null?N:null,f.goals&&f.goals.length>0&&n.consent!==!1&&P)try{z==null||z.teardown(),z=lt(f.goals,P,document,n.apiKey)}catch(G){}ut=(j=f.sectionMap)!=null?j:null,Ie()&&Lt(),xe(n,"applied",{persona:K,slots:de,matches:dt(n)}),!ke&&Me(n.apiKey,H(H({v:1,persona:($=K==null?void 0:K.persona)!=null?$:f.persona,band:(J=K==null?void 0:K.band)!=null?J:"low",slots:f.slots,layoutOrder:f.layoutOrder,savedAt:Date.now()},ye?{slotConfig:ye}:{}),f.palette?{palette:f.palette}:{}))};if(!C){xe(n,"decide timeout/null \u2014 snapshot state stands",dt(n)),A.then(f=>{!f||Ce||ke||P!==d||(R(f),xe(n,"late decide applied",dt(n)))}).catch(()=>{});return}R(C)}catch(n){Vn()}}if(typeof window!="undefined"&&window.sentient){let e=window;e.__sentientInitialized||(e.__sentientInitialized=!0,Promise.resolve().then(()=>{or()}))}return cr($o);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentientui/snippet",
3
- "version": "0.22.1",
3
+ "version": "0.24.0",
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",
@@ -13,6 +13,20 @@
13
13
  "bugs": "https://github.com/SentientUI/sdk/issues",
14
14
  "type": "module",
15
15
  "main": "./dist/snippet.global.js",
16
+ "exports": {
17
+ ".": "./dist/snippet.global.js",
18
+ "./install": {
19
+ "import": {
20
+ "types": "./dist/install.d.ts",
21
+ "default": "./dist/install.js"
22
+ },
23
+ "require": {
24
+ "types": "./dist/install.d.cts",
25
+ "default": "./dist/install.cjs"
26
+ }
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
16
30
  "files": [
17
31
  "dist",
18
32
  "README.md"