@sentientui/snippet 0.2.2 → 0.4.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
@@ -17,16 +17,17 @@ page is left exactly as it was.
17
17
  };
18
18
  </script>
19
19
  <script
20
- src="https://unpkg.com/@sentientui/snippet@0.2.1/dist/snippet.global.js"
20
+ src="https://unpkg.com/@sentientui/snippet@0.3.0/dist/snippet.global.js"
21
21
  defer
22
22
  crossorigin="anonymous"
23
- integrity="sha384-REPLACE_WITH_RELEASE_HASH"
24
23
  ></script>
25
24
  ```
26
25
 
27
- Pin the exact version and add Subresource Integrity compute the hash from the published file:
28
- `openssl dgst -sha384 -binary dist/snippet.global.js | openssl base64 -A`. Or self-host the
29
- file and skip the CDN entirely.
26
+ The version above is pinned to the current published release. To lock the file down, add your
27
+ own Subresource Integrity hash computed from the published file
28
+ (`openssl dgst -sha384 -binary dist/snippet.global.js | openssl base64 -A`) as an `integrity="sha384-…"`
29
+ attribute, or self-host the file and skip the CDN entirely. Do **not** ship a placeholder
30
+ `integrity` value — a hash that doesn't match makes the browser refuse to run the script.
30
31
 
31
32
  ```css
32
33
  #hero[data-tone='urgent'] .cta { font-weight: 700; }
@@ -0,0 +1 @@
1
+ "use strict";var SentientSnippet=(()=>{var $=Object.defineProperty,Z=Object.defineProperties,Q=Object.getOwnPropertyDescriptor,Y=Object.getOwnPropertyDescriptors,tt=Object.getOwnPropertyNames,z=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable;var G=(t,e,n)=>e in t?$(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,I=(t,e)=>{for(var n in e||(e={}))W.call(e,n)&&G(t,n,e[n]);if(z)for(var n of z(e))et.call(e,n)&&G(t,n,e[n]);return t},F=(t,e)=>Z(t,Y(e));var nt=(t,e)=>{for(var n in e)$(t,n,{get:e[n],enumerable:!0})},ot=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of tt(e))!W.call(t,i)&&i!==n&&$(t,i,{get:()=>e[i],enumerable:!(o=Q(e,i))||o.enumerable});return t};var rt=t=>ot($({},"__esModule",{value:!0}),t);var gt={};nt(gt,{clearTargetHighlights:()=>D,drawTargetHighlights:()=>V});function it(t){var n,o,i;let e=(o=(n=t.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:o.location;return(i=e==null?void 0:e.pathname)!=null?i:""}function at(t,e){var n;if(e.tag&&t.tagName.toLowerCase()!==e.tag.toLowerCase())return!1;if(e.text){let o=((n=t.textContent)!=null?n:"").trim().toLowerCase(),i=e.text.trim().toLowerCase();if(!(o===i||o.startsWith(i)||i.startsWith(o)))return!1}return!0}function H(t,e){var i;if(t.urlMatch&&!it(e).includes(t.urlMatch))return null;let n=[];if(t.id){let s=e.getElementById(t.id);n=s?[s]:[]}if(n.length===0&&((i=t.dataAttr)!=null&&i.name))try{let s=t.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(e.querySelectorAll(`[${t.dataAttr.name}="${s}"]`))}catch(s){n=[]}if(n.length===0&&t.selector)try{n=Array.from(e.querySelectorAll(t.selector))}catch(s){n=[]}if(n.length!==1)return null;let o=n[0];return t.fingerprint&&!at(o,t.fingerprint)?null:o}function J(t){let e=globalThis;return e.CSS&&typeof e.CSS.escape=="function"?e.CSS.escape(t):t.replace(/[^a-zA-Z0-9_-]/g,n=>`\\${n}`)}function st(t,e){if(t.id)return`#${J(t.id)}`;let n=[],o=t,i=0;for(;o&&o!==e.body&&o!==e.documentElement&&i<6;){if(o.id){n.unshift(`#${J(o.id)}`);break}let s=o.tagName.toLowerCase(),d=o.parentElement;if(d){let u=Array.from(d.children).filter(h=>h.tagName===o.tagName);u.length>1&&(s+=`:nth-of-type(${u.indexOf(o)+1})`)}n.unshift(s),o=o.parentElement,i++}return n.join(" > ")}function N(t,e){var i;let n={v:1};t.id&&(n.id=t.id);for(let s of["data-framer-name","data-w-id","data-sentient-name"]){let d=t.getAttribute(s);if(d){n.dataAttr={name:s,value:d};break}}n.selector=st(t,e);let o=((i=t.textContent)!=null?i:"").trim().replace(/\s+/g," ").slice(0,80);return n.fingerprint=I({tag:t.tagName.toLowerCase()},o?{text:o}:{}),n}function P(t,e,n){return H(t,n)===e}var lt="sentient-editor-highlight",K="sentient-editor-panel",U="sentient-editor-target-highlight",ct=10;function dt(){let t=window.__sentientEditor;return t&&typeof t.token=="string"&&typeof t.apiBase=="string"?t:null}async function ut(t){var e;try{let n=await fetch(`${t.apiBase}/v1/editor/verify`,{headers:{authorization:`Bearer ${t.token}`}});return n.ok&&(e=(await n.json()).projectId)!=null?e:null}catch(n){return null}}async function _(t,e,n){try{return(await fetch(`${t.apiBase}${e}`,{method:"POST",headers:{authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(n)})).ok}catch(o){return!1}}async function pt(t){try{let e=await fetch(`${t.apiBase}/v1/editor/targets`,{headers:{authorization:`Bearer ${t.token}`}});if(!e.ok)return[];let n=await e.json();return Array.isArray(n.targets)?n.targets:[]}catch(e){return[]}}function D(t=document){for(let e of Array.from(t.querySelectorAll(`.${U}`)))e.remove()}function V(t,e=document){D(e);let n=0;for(let o of t){if(n>=ct)break;let i=H(o.locator,e);if(!i)continue;let s=i.getBoundingClientRect(),d=c("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${s.left}px`,top:`${s.top}px`,width:`${s.width}px`,height:`${s.height}px`,border:"2px dashed #10b981",background:"rgba(16,185,129,0.08)"});d.className=U;let u=c("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483645",left:`${s.left}px`,top:`${Math.max(0,s.top-20)}px`,padding:"2px 6px",borderRadius:"4px",background:"#10b981",color:"#fff",font:"11px system-ui, sans-serif",whiteSpace:"nowrap"},o.label);u.className=U,e.body.append(d,u),n+=1}}function c(t,e,n){let o=document.createElement(t);return Object.assign(o.style,e),n!==void 0&&(o.textContent=n),o}function mt(t){let e=null,n=c("div",{position:"fixed",pointerEvents:"none",zIndex:"2147483646",border:"2px solid #6366f1",background:"rgba(99,102,241,0.12)",display:"none"});n.id=lt;let o=c("div",{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",width:"300px",padding:"14px",borderRadius:"12px",background:"#111827",color:"#fff",font:"13px/1.4 system-ui, sans-serif",boxShadow:"0 8px 30px rgba(0,0,0,0.4)"});o.id=K;let i=c("div",{fontWeight:"600",marginBottom:"6px"},"SentientUI editor"),s=c("div",{opacity:"0.7",marginBottom:"10px"},"Click any element on the page to adapt it."),d=c("div",{fontSize:"12px",marginBottom:"10px",minHeight:"16px"}),u=c("button",x("#6366f1"),"Test different text here"),h=c("button",x("#374151"),"Track clicks as a goal"),w=c("button",x("#374151"),"Move up"),L=c("button",x("#374151"),"Move down"),S=c("button",x("#6366f1"),"Save this arrangement"),k=c("button",x("#374151"),"Undo"),T=c("button",F(I({},x("transparent")),{opacity:"0.6"}),"Close editor");for(let r of[u,h,w,L,T])r.disabled=!0;S.style.display="none",k.style.display="none",o.append(i,s,d,u,h,w,L,S,k,T),document.body.append(n,o);let m=(r,a=!0)=>{d.textContent=r,d.style.color=a?"#a7f3d0":"#fca5a5"},g=null,A=!1,v=null,y=null,E=null,C=null,p=null,B=r=>{S.style.display=r?"block":"none",k.style.display=r?"block":"none",w.disabled=r||!A||!E,L.disabled=r||!A||!C},j=()=>{if(!p||!e){p=null,B(!1);return}p.origParent.insertBefore(e,p.origNext),p=null,B(!1)},O=r=>{let a=r.target;if(!a||o.contains(a)||a===n)return;D(document);let l=a.getBoundingClientRect();Object.assign(n.style,{display:"block",left:`${l.left}px`,top:`${l.top}px`,width:`${l.width}px`,height:`${l.height}px`})},R=r=>{let a=r.target;if(!a||o.contains(a))return;r.preventDefault(),r.stopPropagation(),j(),e=a,g=N(a,document);let l=P(g,a,document);A=l,m(l?"\u2713 Selected \u2014 matches exactly 1 element":"\u26A0 Couldn\u2019t target this element uniquely",l);for(let M of[u,h,T])M.disabled=!1;u.disabled=!l,h.disabled=!l,v=a.previousElementSibling,y=a.nextElementSibling;let f=v?N(v,document):null,b=y?N(y,document):null;E=v&&f&&P(f,v,document)?f:null,C=y&&b&&P(b,y,document)?b:null,w.disabled=!l||!E,L.disabled=!l||!C};u.onclick=async()=>{var b,M,q;if(!e||!g)return;let r=window.prompt("First wording (what you show today):",(M=(b=e.textContent)==null?void 0:b.trim())!=null?M:"");if(r===null)return;let a=window.prompt("Alternative wording to test:","");if(a===null)return;let l=((q=window.prompt("Name this slot:","hero-cta"))!=null?q:"hero-cta").trim()||"hero-cta";m("Saving\u2026");let f=await _(t,`/v1/editor/slots/${encodeURIComponent(l)}`,{kind:"arms",target:g,draftConfig:{arms:[{id:"a",displayName:"Original",ops:{text:r}},{id:"b",displayName:"Alternative",ops:{text:a}}]}});m(f?"\u2713 Saved as a draft \u2014 publish it from your dashboard.":"\u26A0 Couldn\u2019t save \u2014 try again.",f)},h.onclick=async()=>{var l;if(!e||!g)return;let r=((l=window.prompt("Name this goal:","demo_requested"))!=null?l:"").trim();if(!r)return;m("Saving\u2026");let a=await _(t,`/v1/editor/goals/${encodeURIComponent(r)}`,{event:"click",locator:g});m(a?"\u2713 Goal saved as a draft.":"\u26A0 Couldn\u2019t save \u2014 try again.",a)},w.onclick=()=>{if(!e||!v||!E)return;let r=e.parentElement;if(!r)return;let a=e.nextSibling;r.insertBefore(e,v),p={direction:"up",origParent:r,origNext:a,anchorLocator:E},B(!0),m("Previewing the new position \u2014 save it or undo.")},L.onclick=()=>{if(!e||!y||!C)return;let r=e.parentElement;if(!r)return;let a=e.nextSibling;r.insertBefore(e,y.nextSibling),p={direction:"down",origParent:r,origNext:a,anchorLocator:C},B(!0),m("Previewing the new position \u2014 save it or undo.")},k.onclick=()=>{j(),m("Move undone \u2014 back to the original position.")},S.onclick=async()=>{var f;if(!e||!g||!p||!A)return;let r=((f=window.prompt("Name this slot:","reorder-slot"))!=null?f:"reorder-slot").trim()||"reorder-slot";m("Saving\u2026");let a=p.direction==="up"?"moveBefore":"moveAfter",l=await _(t,`/v1/editor/slots/${encodeURIComponent(r)}`,{kind:"arms",target:g,draftConfig:{arms:[{id:"a",ops:{}},{id:"b",ops:{[a]:p.anchorLocator}}]}});l&&(p=null,B(!1)),m(l?"\u2713 Saved as a draft \u2014 publish it from your dashboard.":"\u26A0 Couldn\u2019t save \u2014 try again.",l)};let X=()=>{document.removeEventListener("mousemove",O,!0),document.removeEventListener("click",R,!0),D(document),n.remove(),o.remove()};T.onclick=X,document.addEventListener("mousemove",O,!0),document.addEventListener("click",R,!0)}function x(t){return{display:"block",width:"100%",marginTop:"8px",padding:"8px 10px",borderRadius:"8px",border:"none",background:t,color:"#fff",font:"13px system-ui, sans-serif",cursor:"pointer",textAlign:"left"}}async function ft(){if(typeof document=="undefined")return;let t=dt();if(!t||!await ut(t)||document.getElementById(K))return;mt(t);let n=await pt(t);V(n,document)}ft();return rt(gt);})();
@@ -1 +1,2 @@
1
- "use strict";var SentientSnippet=(()=>{var fe=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var Pe=(e,t)=>()=>(e&&(t=e(e=0)),t);var De=(e,t)=>{for(var n in t)fe(e,n,{get:t[n],enumerable:!0})},Xe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ve(t))!He.call(e,o)&&o!==n&&fe(e,o,{get:()=>t[o],enumerable:!(r=Fe(t,o))||r.enumerable});return e};var Qe=e=>Xe(fe({},"__esModule",{value:!0}),e);var Ze,et,tt,Te,nt,rt,Re,S,pe,Y=Pe(()=>{"use strict";Ze=Object.defineProperty,et=Object.defineProperties,tt=Object.getOwnPropertyDescriptors,Te=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,Re=(e,t,n)=>t in e?Ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,S=(e,t)=>{for(var n in t||(t={}))nt.call(t,n)&&Re(e,n,t[n]);if(Te)for(var n of Te(t))rt.call(t,n)&&Re(e,n,t[n]);return e},pe=(e,t)=>et(e,tt(t))});var Me={};De(Me,{LOCAL_ENGINE_AVAILABLE:()=>ot,createLocalEngine:()=>st});function st(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var ot,$e=Pe(()=>{"use strict";Y();ot=!1});var Ct={};De(Ct,{applyPersonaAttributes:()=>H,applySlotAttributes:()=>X,parseSnippetConfig:()=>ue,run:()=>Ye,version:()=>Rt});Y();function te(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function Ne(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 ge(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 te(e.baseline);if(typeof e.baseline=="string")return e.baseline;let o={};for(let[u,a]of Object.entries((n=e.dims)!=null?n:{}))o[u]=(r=a[0])!=null?r:"";return te(o)}function je(e,t){var n,r;return e.dims!=null?(r=(n=Ne(t))!=null?n:Ne(ge(e)))!=null?r:{}:t}function G(e){return e>=.3?e<.7?"medium":"high":"low"}var Ce=["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 me(e){return Le(e)!==null}function Le(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=Ce.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function he(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 ye(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|x\.com|facebook|linkedin|reddit|t\.co)/.test(r)?"social":"referral"}catch(n){return"direct"}}function ve(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function be(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function ne(e){return S(S(S({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 re(e){let t=ne(e);return je(t,ge(t))}function we(e){return typeof e=="string"?e:te(e)}Y();var at="_snt_uid",W="_snt_uid";function it(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function lt(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function ut(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function ct(e){try{return localStorage.getItem(e)}catch(t){return null}}function dt(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function ft(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function pt(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function gt(e){try{sessionStorage.removeItem(e)}catch(t){}}function mt(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function ht(e){try{localStorage.removeItem(e)}catch(t){}}function yt(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var vt={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function Be(e){var t,n,r,o,u,a;if(typeof window=="undefined")return vt;let i=(t=e==null?void 0:e.cookieName)!=null?t:at,d=((n=e==null?void 0:e.cookieTTLDays)!=null?n:365)*24*60*60,c=(a=(u=(o=(r=lt(i))!=null?r:ct(W))!=null?o:ft(W))!=null?u:e==null?void 0:e.ssrSessionId)!=null?a:it();ut(i,c,d);let f=dt(W,c),m=mt(i),w=f?!1:pt(W,c),k=!f&&!m&&!w;return{getSessionId:()=>c,isEphemeral:()=>k,destroy:()=>{c=null,yt(i),ht(W),gt(W)}}}function Ge(e){return`_snt_retry_${e.slice(0,12)}`}var bt={push:()=>{},flush:()=>{},destroy:()=>{}};function wt(e,t){try{let n=localStorage.getItem(t);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?(localStorage.removeItem(t),r.slice(-e)):[]}catch(n){return[]}}function Se(e,t,n){try{let r=[...(()=>{try{let o=localStorage.getItem(n);if(!o)return[];let u=JSON.parse(o);return Array.isArray(u)?u:[]}catch(o){return[]}})(),...e].slice(-t);localStorage.setItem(n,JSON.stringify(r))}catch(r){}}function St(e){var t,n,r;if(typeof window=="undefined")return bt;let o=(t=e.flushIntervalMs)!=null?t:5e3,u=(n=e.maxBatchSize)!=null?n:20,a=(r=e.maxRetrySize)!=null?r:100,i=e.ingestUrl,d=e.apiKey,c=Ge(d),f=[],m=new Set,w=[],k=p=>{for(let g of p)y.delete(g),!m.has(g)&&(m.add(g),w.push(g));for(;w.length>500;){let g=w.shift();g&&m.delete(g)}},y=new Set,j=p=>{m.has(p.id)||y.has(p.id)||(y.add(p.id),f.push(p))},K=wt(a,c);for(let p of K)j(p);let I=0,b=0,Q=p=>{if(p.length===0)return;let g=JSON.stringify(p),O=p.map(l=>l.id),D;try{D=fetch(i,{method:"POST",keepalive:!0,body:g,headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`}})}catch(l){Se(p,a,c);for(let h of O)y.delete(h);b++,I=Date.now()+Math.min(6e4,1e3*2**Math.min(b,6));return}let s=l=>{if(l.ok||l.status>=400&&l.status<500&&l.status!==429){k(O),b=0,I=0;return}Se(p,a,c);for(let h of O)y.delete(h);b++,I=Date.now()+Math.min(6e4,1e3*2**Math.min(b,6))};D instanceof Promise?D.then(s).catch(()=>{Se(p,a,c);for(let l of O)y.delete(l);b++,I=Date.now()+Math.min(6e4,1e3*2**Math.min(b,6))}):s(D)},Z=typeof TextEncoder!="undefined"?new TextEncoder:null,ee=p=>Z?Z.encode(p).length:p.length,E=p=>{let g=[],O=2;for(let D of p){let s=ee(JSON.stringify(D))+1;if(g.length>0&&O+s>57344||g.length>=u)break;g.push(D),O+=s}return g},P=()=>{try{if(Date.now()<I)return;for(;f.length>0;){let p=f.filter(O=>!m.has(O.id));if(f.length=0,p.length===0)break;let g=E(p);if(g.length===0)break;g.length<p.length&&f.push(...p.slice(g.length)),Q(g)}}catch(p){}},A=!0,v=null;v=setInterval(()=>{A&&P()},o);let J=()=>{document.visibilityState==="hidden"&&P()},M=()=>{P()};return document.addEventListener("visibilitychange",J),window.addEventListener("beforeunload",M),{push(p){j(p),f.length>=u&&P()},flush:P,destroy(){A=!1,v!==null&&(clearInterval(v),v=null),document.removeEventListener("visibilitychange",J),window.removeEventListener("beforeunload",M),P()}}}var Oe="_snt_asgn_";function oe(e,t){return`${e}:${t}`}function kt(e,t){return`${Oe}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Ke(e){let t=e.slice(Oe.length),n=t.indexOf(":");if(n<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,n)),segment:decodeURIComponent(t.slice(n+1))}}catch(r){return null}}function ke(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(Oe)&&e.push(n)}return e}catch(e){return[]}}function It(e=18e5){let t=new Map,n=r=>r.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let r of ke())try{let o=localStorage.getItem(r);if(!o)continue;let u=JSON.parse(o);if(n(u)){localStorage.removeItem(r);continue}let a=Ke(r);if(!a)continue;t.set(oe(a.componentId,a.segment),u)}catch(o){}})(),{get(r,o){let u=t.get(oe(r,o));return u?n(u)?(t.delete(oe(r,o)),null):u:null},set(r,o,u){let a=oe(r,o);t.set(a,u);try{localStorage.setItem(kt(r,o),JSON.stringify(u))}catch(i){}},invalidate(r){let o=`${r}:`;for(let u of[...t.keys()])u.startsWith(o)&&t.delete(u);for(let u of ke()){let a=Ke(u);if((a==null?void 0:a.componentId)===r)try{localStorage.removeItem(u)}catch(i){}}},clear(){t.clear();for(let r of ke())try{localStorage.removeItem(r)}catch(o){}}}}var ie="_snt_snap:",At=["low","medium","high"];function le(e){try{let t=localStorage.getItem(ie+e);if(!t)return null;let n=JSON.parse(t);return!n||typeof n!="object"||n.v!==1||typeof n.persona!="string"||typeof n.band!="string"||!At.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"?null:n}catch(t){return null}}function V(e,t){try{localStorage.setItem(ie+e,JSON.stringify(t))}catch(n){}}var Ae="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",We="[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.",Ue=!1,se=!1;function Ot(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function xt(e){var t;let n=Be({ssrSessionId:e.ssrSessionId}),r=(t=n.getSessionId())!=null?t:"local",o=Ot(),u=Promise.resolve().then(()=>($e(),Me)).then(d=>{let c=d;return c.LOCAL_ENGINE_AVAILABLE?(Ue||(Ue=!0,console.info(We)),c):(se||(se=!0,console.error(Ae)),null)}).catch(()=>(se||(se=!0,console.error(Ae)),null)),a=null;function i(d){let c=document.documentElement;c.dataset.sentientPersona===void 0&&(c.dataset.sentientPersona=d.persona,c.dataset.sentientConfidence=G(d.confidence))}return{isLocal:!0,async decide(d){var c,f,m;let w=await u;if(!w)return null;let k=w.createLocalEngine({sessionId:r,forcedPersona:o}).decide(d);return a=pe(S({},k),{layoutOrder:(f=(c=k.layoutOrder)!=null?c:a==null?void 0:a.layoutOrder)!=null?f:null,slots:S(S({},(m=a==null?void 0:a.slots)!=null?m:{}),k.slots)}),V(e.apiKey||"local",{v:1,persona:a.persona,band:G(a.confidence),slots:a.slots,layoutOrder:a.layoutOrder,savedAt:Date.now()}),i(k),k},getSlotResult(d){var c,f,m;return(m=(f=a==null?void 0:a.slots[d])!=null?f:(c=e.initialSlots)==null?void 0:c[d])!=null?m:null},getPersona(){return a?{persona:a.persona,confidence:a.confidence,band:G(a.confidence)}:null},async assign(d,c){var f;let m=await u;return!m||!c||c.length===0?c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null:{variantId:(f=m.createLocalEngine({sessionId:r,forcedPersona:o}).decide({components:[{id:d,variantIds:c}]}).assignments[d])!=null?f:c[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}var Je="https://api.sentient-ui.com/v1/events",ae=new Map,_t=null;function Ie(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}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 F={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 Et(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,r]of t)n.startsWith("utm_")&&(e[n]=r);return e}catch(e){return{}}}function qe(e){return e.replace(/\/events\/?$/,"")}function ze(){return[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 Pt(e){var t;let n=qe((t=e.ingestUrl)!=null?t:Je),r={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(i,d,c){try{let f=new URLSearchParams({componentId:i});for(let w of d!=null?d:[])f.append("variantIds[]",w);let m=await fetch(`${n}/winner?${f.toString()}`,{headers:r});return m.ok?{variantId:(await m.json()).variantId,assignmentTtlMs:0}:d!=null&&d[0]?{variantId:d[0],assignmentTtlMs:0}:null}catch(f){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:()=>{}},u={track:i=>o.track(i),goal:(i,d,c,f)=>o.goal(i,d,c,f),componentGoal:(i,d,c)=>o.componentGoal(i,d,c),identify:i=>o.identify(i),getAssignment:(i,d)=>o.getAssignment(i,d),assign:(i,d,c,f)=>o.assign(i,d,c,f),decide:i=>o.decide(i),getSlotResult:i=>o.getSlotResult(i),getPersona:()=>o.getPersona(),fetchWeights:()=>o.fetchWeights(),getGraph:()=>o.getGraph(),dispose:()=>o.dispose(),destroy:()=>o.destroy()};function a(i){o=i}return{proxy:u,setInner:a}}function xe(e){var t,n,r,o,u,a,i,d,c;if(typeof window=="undefined")return F;_t=e.apiKey;let f=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!f&&e.localMode!==!1)return ae.set(e.apiKey||"local",{config:e,upgrade:null}),xt(e);let m=e.respectDoNotTrack!==!1&&ze();if(e.consent===!1||m){if(e.preConsentBehavior==="statistical_winner"){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."),F;let{proxy:s,setInner:l}=Pt(e);return ae.set(e.apiKey,{config:e,upgrade:m?null:l}),s}return ae.set(e.apiKey,{config:e,upgrade:null}),F}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."),F;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),F;let w=(t=e.ingestUrl)!=null?t:Je,k=Date.now(),y=Be({ssrSessionId:e.ssrSessionId}),j=It(),K=St({ingestUrl:w,apiKey:e.apiKey}),I=qe(w),b={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},Q=he((n=navigator.userAgent)!=null?n:""),Z=typeof window!="undefined"?window.location.origin:void 0,ee=ye((r=document.referrer)!=null?r:"",Z),E=(o=e.sessionSegment)!=null?o:`${Q}:${ee}`,P=new Map,A=new Map,v=null,J=s=>{for(let l of s)A.has(l.id)||A.set(l.id,re(l))};if(e.initialSlots)for(let[s,l]of Object.entries(e.initialSlots))A.set(s,l);let M=le(e.apiKey);if(M)for(let[s,l]of Object.entries(M.slots))A.has(s)||A.set(s,l);let p={low:.15,medium:.5,high:.85};if(e.initialPersona)v=S({},e.initialPersona);else{let s=document.documentElement.dataset;s.sentientPersona?v={persona:s.sentientPersona,confidence:(a=p[(u=s.sentientConfidence)!=null?u:"low"])!=null?a:.15}:M&&(v={persona:M.persona,confidence:(i=p[M.band])!=null?i:.15})}if(e.initialAssignments)for(let[s,l]of Object.entries(e.initialAssignments))j.set(s,E,{variantId:l,assignedAt:Date.now(),segment:E,confidence:1});let g=Promise.resolve(),O=y.getSessionId();if(O){let s=ve((d=document.referrer)!=null?d:""),l=S(S({sessionId:O,deviceClass:Q,trafficSource:ee,referrerDomain:s,utmParams:Et(),timeOfDay:be(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:y.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||me((c=navigator.userAgent)!=null?c:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{g=fetch(`${I}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(l),headers:b}).then(h=>{h.status===402&&console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing")}).catch(()=>{})}catch(h){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:K});let D={goal(s,l={},h=1,T=0){let _=y.getSessionId();if(!_)return;let x=Ie();g.then(()=>{fetch(`${I}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:_,name:s,metadata:l,weight:h,stepIndex:T,goalId:x}),headers:b}).catch(()=>{})})},componentGoal(s,l,h){var T,_,x;let $=y.getSessionId();if(!$)return;let R=j.get(s,E),N=R?null:(T=A.get(s))!=null?T:null;if(!R&&N===null){e.debug&&console.warn(`[sentient] componentGoal("${s}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let U=R?R.variantId:we(N),C={id:Ie(),sessionId:$,projectId:e.apiKey,componentId:s,variantId:U,eventType:"goal_achieved",goalType:l,payload:S({reward:(_=h==null?void 0:h.reward)!=null?_:1},(x=h==null?void 0:h.metadata)!=null?x:{}),timestamp:Date.now(),timeInSession:Date.now()-k};e.debug&&console.log("[sentient] componentGoal",C),g.then(()=>K.push(C))},identify(s){let l=y.getSessionId();l&&g.then(()=>{fetch(`${I}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:l,userId:s,ephemeral:y.isEphemeral()}),headers:b}).catch(()=>{})})},track(s){let l=y.getSessionId();if(!l)return;let h=pe(S({},s),{id:Ie(),sessionId:l,timestamp:Date.now(),timeInSession:Date.now()-k});e.debug&&console.log("[sentient] track",h),g.then(()=>K.push(h))},getAssignment(s,l){return j.get(s,l)},async assign(s,l,h,T){let _=y.getSessionId();if(!_)return null;let x=j.get(s,E);if(x&&(l!=null&&l.length||x.content!==void 0))return{variantId:x.variantId,assignmentTtlMs:0,content:x.content};let $=P.get(s);if($)return $;let R=(async()=>{await g;try{let N={sessionId:_,componentId:s,variantIds:l};T!==void 0?N.agentDataByVariant=T:h!==void 0&&(N.agentData=h);let U=await fetch(`${I}/assign`,{method:"POST",body:JSON.stringify(N),headers:b});if(!U.ok)return null;let C=await U.json();return j.set(s,E,{variantId:C.variantId,assignedAt:Date.now(),segment:E,confidence:1,content:C.content}),C}catch(N){return null}finally{P.delete(s)}})();return P.set(s,R),R},async decide(s){var l,h,T,_,x,$,R,N,U,C;let _e=y.getSessionId();if(!_e)return null;let q=(l=s.slots)!=null?l:[];await g;try{let z={sessionId:_e};s.sections&&s.sections.length>0&&(z.sections=s.sections.map(L=>({id:L}))),z.components=(h=s.components)!=null?h:[],q.length>0&&(z.slots=q.map(ne));let Ee=await fetch(`${I}/decide`,{method:"POST",body:JSON.stringify(z),headers:b});if(!Ee.ok)return J(q),null;let B=await Ee.json(),ce={};for(let L of q)ce[L.id]=(_=(T=B.slots)==null?void 0:T[L.id])!=null?_:re(L);for(let[L,de]of Object.entries(ce))A.set(L,de);v={persona:(x=B.persona)!=null?x:"unknown",confidence:($=B.confidence)!=null?$:0};for(let[L,de]of Object.entries((R=B.assignments)!=null?R:{}))j.set(L,E,{variantId:de,assignedAt:Date.now(),segment:E,confidence:1});return V(e.apiKey,{v:1,persona:v.persona,band:G(v.confidence),slots:Object.fromEntries(A),layoutOrder:(N=B.layoutOrder)!=null?N:null,savedAt:Date.now()}),{layoutOrder:(U=B.layoutOrder)!=null?U:null,assignments:(C=B.assignments)!=null?C:{},slots:ce,persona:v.persona,confidence:v.confidence}}catch(z){return J(q),null}},getSlotResult(s){var l;return(l=A.get(s))!=null?l:null},getPersona(){return v?{persona:v.persona,confidence:v.confidence,band:G(v.confidence)}:null},async fetchWeights(){var s;try{let l=await fetch(`${I}/weights`,{headers:b});return l.ok?(s=(await l.json()).components)!=null?s:[]:[]}catch(l){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){K.destroy(),e.debug&&console.log("[sentient] disposed")},destroy(){K.destroy(),y.destroy();try{localStorage.removeItem(ie+e.apiKey),localStorage.removeItem(Ge(e.apiKey))}catch(s){}e.debug&&console.log("[sentient] destroyed")}};if(ae.set(e.apiKey,{config:e,upgrade:null}),e.debug){let s=window;s.__sentient&&(s.__sentient.client=D)}return D}Y();var Dt=["landing","ecommerce","saas","marketplace"];function Tt(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(u=>typeof u=="string"))return null;n[r]=o}return n}function ue(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=Dt.includes(t.context)?t.context:"landing",r={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[o,u]of Object.entries(t.slots)){if(typeof u!="object"||u===null)continue;let a=u,i=Tt(a.dims);i&&(a.target!==void 0&&typeof a.target!="string"||(r[o]=a.target===void 0?{dims:i}:{dims:i,target:a.target}))}return{apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r}}function H(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function X(e,t,n){var r;for(let[o,u]of Object.entries(t)){let a=e[o];if(!a||typeof a=="string")continue;let i=u.target?Array.from(n.querySelectorAll(u.target)):[n.documentElement];for(let d of i)for(let[c,f]of Object.entries(a))(r=u.dims[c])!=null&&r.includes(f)&&d.setAttribute(`data-${c}`,f)}}var Rt="0.2.1",Nt=5e3;function jt(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}async function Ye(){var e,t;try{let n=ue(window.sentient);if(!n)return;let r=le(n.apiKey);r&&(n.personaAttributes&&H(r.persona,r.band,document),X(r.slots,n.slots,document));let o=xe({apiKey:n.apiKey,context:n.context}),u=Object.entries(n.slots).map(([d,c])=>({id:d,dims:c.dims})),a=await jt(o.decide({slots:u}),Nt);if(!a)return;let i=o.getPersona();n.personaAttributes&&i&&H(i.persona,i.band,document),X(a.slots,n.slots,document),V(n.apiKey,{v:1,persona:(e=i==null?void 0:i.persona)!=null?e:a.persona,band:(t=i==null?void 0:i.band)!=null?t:"low",slots:a.slots,layoutOrder:a.layoutOrder,savedAt:Date.now()})}catch(n){}}typeof window!="undefined"&&window.sentient&&Ye();return Qe(Ct);})();
1
+ "use strict";var SentientSnippet=(()=>{var pe=Object.defineProperty;var Dt=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyNames,He=Object.getOwnPropertySymbols;var Ye=Object.prototype.hasOwnProperty,Lt=Object.prototype.propertyIsEnumerable;var Fe=(e,t,n)=>t in e?pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_e=(e,t)=>{for(var n in t||(t={}))Ye.call(t,n)&&Fe(e,n,t[n]);if(He)for(var n of He(t))Lt.call(t,n)&&Fe(e,n,t[n]);return e};var Xe=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ze=(e,t)=>{for(var n in t)pe(e,n,{get:t[n],enumerable:!0})},Pt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Tt(t))!Ye.call(e,r)&&r!==n&&pe(e,r,{get:()=>t[r],enumerable:!(o=Dt(t,r))||o.enumerable});return e};var Nt=e=>Pt(pe({},"__esModule",{value:!0}),e);var jt,$t,Mt,Qe,Ut,Bt,et,E,ae,le=Xe(()=>{"use strict";jt=Object.defineProperty,$t=Object.defineProperties,Mt=Object.getOwnPropertyDescriptors,Qe=Object.getOwnPropertySymbols,Ut=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable,et=(e,t,n)=>t in e?jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,E=(e,t)=>{for(var n in t||(t={}))Ut.call(t,n)&&et(e,n,t[n]);if(Qe)for(var n of Qe(t))Bt.call(t,n)&&et(e,n,t[n]);return e},ae=(e,t)=>$t(e,Mt(t))});var it={};Ze(it,{LOCAL_ENGINE_AVAILABLE:()=>Kt,createLocalEngine:()=>Gt});function Gt(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var Kt,st=Xe(()=>{"use strict";le();Kt=!1});var Pn={};Ze(Pn,{applyPersonaAttributes:()=>ke,applyRegistrySlots:()=>Oe,applySlotArms:()=>Ee,applySlotAttributes:()=>Ie,parseEditorToken:()=>Ct,parsePreview:()=>_t,parseSnippetConfig:()=>Ae,reapply:()=>Je,run:()=>Rt,version:()=>xt});le();function ge(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function tt(e){if(e.length===0)return null;let t={};for(let n of e.split("|")){let o=n.indexOf("=");if(o<=0||o!==n.lastIndexOf("=")||o===n.length-1)return null;let r=n.slice(0,o);if(r in t)return null;t[r]=n.slice(o+1)}return t}function Re(e){var t,n,o;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 ge(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[s,a]of Object.entries((n=e.dims)!=null?n:{}))r[s]=(o=a[0])!=null?o:"";return ge(r)}function nt(e,t){var n,o;return e.dims!=null?(o=(n=tt(t))!=null?n:tt(Re(e)))!=null?o:{}:t}function F(e){return e>=.3?e<.7?"medium":"high":"low"}var rt=["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 De(e){return ot(e)!==null}function ot(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=rt.find(o=>n.includes(o.toLowerCase())))!=null?t:null}function Te(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 Le(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(r){}let o=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(o)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(o)?"social":"referral"}catch(n){return"direct"}}function Pe(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function Ne(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function me(e){return E(E(E({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 he(e){let t=me(e);return nt(t,Re(t))}function je(e){return typeof e=="string"?e:ge(e)}le();var qt="_snt_uid",Q="_snt_uid";function Wt(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function Jt(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function Vt(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(o){}}function zt(e){try{return localStorage.getItem(e)}catch(t){return null}}function Ht(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function Ft(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function Yt(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function Xt(e){try{sessionStorage.removeItem(e)}catch(t){}}function Zt(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function Qt(e){try{localStorage.removeItem(e)}catch(t){}}function en(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var tn={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ct(e){var t,n,o,r,s,a;if(typeof window=="undefined")return tn;let c=(t=e==null?void 0:e.cookieName)!=null?t:qt,i=((n=e==null?void 0:e.cookieTTLDays)!=null?n:365)*24*60*60,l=(a=(s=(r=(o=Jt(c))!=null?o:zt(Q))!=null?r:Ft(Q))!=null?s:e==null?void 0:e.ssrSessionId)!=null?a:Wt();Vt(c,l,i);let d=Ht(Q,l),p=Zt(c),S=d?!1:Yt(Q,l),f=!d&&!p&&!S;return{getSessionId:()=>l,isEphemeral:()=>f,destroy:()=>{l=null,en(c),Qt(Q),Xt(Q)}}}function ut(e){return`_snt_retry_${e.slice(0,12)}`}var nn={push:()=>{},flush:()=>{},destroy:()=>{}};function rn(e,t){try{let n=localStorage.getItem(t);if(!n)return[];let o=JSON.parse(n);return Array.isArray(o)?(localStorage.removeItem(t),o.slice(-e)):[]}catch(n){return[]}}function $e(e,t,n){try{let o=[...(()=>{try{let r=localStorage.getItem(n);if(!r)return[];let s=JSON.parse(r);return Array.isArray(s)?s:[]}catch(r){return[]}})(),...e].slice(-t);localStorage.setItem(n,JSON.stringify(o))}catch(o){}}function on(e){var t,n,o;if(typeof window=="undefined")return nn;let r=(t=e.flushIntervalMs)!=null?t:5e3,s=(n=e.maxBatchSize)!=null?n:20,a=(o=e.maxRetrySize)!=null?o:100,c=e.ingestUrl,i=e.apiKey,l=ut(i),d=[],p=new Set,S=[],f=m=>{for(let w of m)y.delete(w),!p.has(w)&&(p.add(w),S.push(w));for(;S.length>500;){let w=S.shift();w&&p.delete(w)}},y=new Set,b=m=>{p.has(m.id)||y.has(m.id)||(y.add(m.id),d.push(m))},j=rn(a,l);for(let m of j)b(m);let R=0,h=0,v=m=>{if(m.length===0)return;let w=JSON.stringify(m),O=m.map(u=>u.id),M;try{M=fetch(c,{method:"POST",keepalive:!0,body:w,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}})}catch(u){$e(m,a,l);for(let g of O)y.delete(g);h++,R=Date.now()+Math.min(6e4,1e3*2**Math.min(h,6));return}let q=u=>{if(u.ok||u.status>=400&&u.status<500&&u.status!==429){f(O),h=0,R=0;return}$e(m,a,l);for(let g of O)y.delete(g);h++,R=Date.now()+Math.min(6e4,1e3*2**Math.min(h,6))};M instanceof Promise?M.then(q).catch(()=>{$e(m,a,l);for(let u of O)y.delete(u);h++,R=Date.now()+Math.min(6e4,1e3*2**Math.min(h,6))}):q(M)},A=typeof TextEncoder!="undefined"?new TextEncoder:null,D=m=>A?A.encode(m).length:m.length,fe=m=>{let w=[],O=2;for(let M of m){let q=D(JSON.stringify(M))+1;if(w.length>0&&O+q>57344||w.length>=s)break;w.push(M),O+=q}return w},x=()=>{try{if(Date.now()<R)return;for(;d.length>0;){let m=d.filter(O=>!p.has(O.id));if(d.length=0,m.length===0)break;let w=fe(m);if(w.length===0)break;w.length<m.length&&d.push(...m.slice(w.length)),v(w)}}catch(m){}},Z=!0,T=null;T=setInterval(()=>{Z&&x()},r);let C=()=>{document.visibilityState==="hidden"&&x()},re=()=>{x()};return document.addEventListener("visibilitychange",C),window.addEventListener("beforeunload",re),{push(m){b(m),d.length>=s&&x()},flush:x,destroy(){Z=!1,T!==null&&(clearInterval(T),T=null),document.removeEventListener("visibilitychange",C),window.removeEventListener("beforeunload",re),x()}}}var Ke="_snt_asgn_";function ye(e,t){return`${e}:${t}`}function sn(e,t){return`${Ke}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function at(e){let t=e.slice(Ke.length),n=t.indexOf(":");if(n<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,n)),segment:decodeURIComponent(t.slice(n+1))}}catch(o){return null}}function Me(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(Ke)&&e.push(n)}return e}catch(e){return[]}}function an(e=18e5){let t=new Map,n=o=>o.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let o of Me())try{let r=localStorage.getItem(o);if(!r)continue;let s=JSON.parse(r);if(n(s)){localStorage.removeItem(o);continue}let a=at(o);if(!a)continue;t.set(ye(a.componentId,a.segment),s)}catch(r){}})(),{get(o,r){let s=t.get(ye(o,r));return s?n(s)?(t.delete(ye(o,r)),null):s:null},set(o,r,s){let a=ye(o,r);t.set(a,s);try{localStorage.setItem(sn(o,r),JSON.stringify(s))}catch(c){}},invalidate(o){let r=`${o}:`;for(let s of[...t.keys()])s.startsWith(r)&&t.delete(s);for(let s of Me()){let a=at(s);if((a==null?void 0:a.componentId)===o)try{localStorage.removeItem(s)}catch(c){}}},clear(){t.clear();for(let o of Me())try{localStorage.removeItem(o)}catch(r){}}}}var be="_snt_snap:",ln=["low","medium","high"];function Se(e){try{let t=localStorage.getItem(be+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"||!ln.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 ce(e,t){try{localStorage.setItem(be+e,JSON.stringify(t))}catch(n){}}var Be="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",dt="[sentient] Local mode \u2014 decisions are simulated on-device and nothing is sent over the network. Add an API key to learn from real traffic.",lt=!1,ve=!1;function cn(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function un(e){var t;let n=ct({ssrSessionId:e.ssrSessionId}),o=(t=n.getSessionId())!=null?t:"local",r=cn(),s=Promise.resolve().then(()=>(st(),it)).then(i=>{let l=i;return l.LOCAL_ENGINE_AVAILABLE?(lt||(lt=!0,console.info(dt)),l):(ve||(ve=!0,console.error(Be)),null)}).catch(()=>(ve||(ve=!0,console.error(Be)),null)),a=null;function c(i){let l=document.documentElement;l.dataset.sentientPersona===void 0&&(l.dataset.sentientPersona=i.persona,l.dataset.sentientConfidence=F(i.confidence))}return{isLocal:!0,async decide(i){var l,d,p;let S=await s;if(!S)return null;let f=S.createLocalEngine({sessionId:o,forcedPersona:r}).decide(i);return a=ae(E({},f),{layoutOrder:(d=(l=f.layoutOrder)!=null?l:a==null?void 0:a.layoutOrder)!=null?d:null,slots:E(E({},(p=a==null?void 0:a.slots)!=null?p:{}),f.slots)}),ce(e.apiKey||"local",{v:1,persona:a.persona,band:F(a.confidence),slots:a.slots,layoutOrder:a.layoutOrder,savedAt:Date.now()}),c(f),f},getSlotResult(i){var l,d,p;return(p=(d=a==null?void 0:a.slots[i])!=null?d:(l=e.initialSlots)==null?void 0:l[i])!=null?p:null},getPersona(){return a?{persona:a.persona,confidence:a.confidence,band:F(a.confidence)}:null},async assign(i,l){var d;let p=await s;return!p||!l||l.length===0?l!=null&&l[0]?{variantId:l[0],assignmentTtlMs:0}:null:{variantId:(d=p.createLocalEngine({sessionId:o,forcedPersona:r}).decide({components:[{id:i,variantIds:l}]}).assignments[i])!=null?d:l[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}var ft="https://api.sentient-ui.com/v1/events",Y=new Map,pt=null;function Ue(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}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 ee={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 dn(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,o]of t)n.startsWith("utm_")&&(e[n]=o);return e}catch(e){return{}}}function gt(e){return e.replace(/\/events\/?$/,"")}function ue(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(e=>e==="1"||e==="yes")}function Ge(e){if(typeof window=="undefined")return;let t=e!=null?e:pt;if(!t){console.warn("[sentient] grantConsent() called before init()");return}let n=Y.get(t);if(!n){console.warn("[sentient] grantConsent() called before init()");return}let{config:o,upgrade:r}=n;if(!r||o.respectDoNotTrack!==!1&&ue())return;let s=we(ae(E({},o),{consent:!0}));r(s),Y.set(t,{config:ae(E({},o),{consent:!0}),upgrade:null})}function fn(e){var t;let n=gt((t=e.ingestUrl)!=null?t:ft),o={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},r={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(c,i,l){try{let d=new URLSearchParams({componentId:c});for(let S of i!=null?i:[])d.append("variantIds[]",S);let p=await fetch(`${n}/winner?${d.toString()}`,{headers:o});return p.ok?{variantId:(await p.json()).variantId,assignmentTtlMs:0}:i!=null&&i[0]?{variantId:i[0],assignmentTtlMs:0}:null}catch(d){return i!=null&&i[0]?{variantId:i[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},s={track:c=>r.track(c),goal:(c,i,l,d)=>r.goal(c,i,l,d),componentGoal:(c,i,l)=>r.componentGoal(c,i,l),identify:c=>r.identify(c),getAssignment:(c,i)=>r.getAssignment(c,i),assign:(c,i,l,d)=>r.assign(c,i,l,d),decide:c=>r.decide(c),getSlotResult:c=>r.getSlotResult(c),getPersona:()=>r.getPersona(),fetchWeights:()=>r.fetchWeights(),getGraph:()=>r.getGraph(),dispose:()=>r.dispose(),destroy:()=>r.destroy()};function a(c){r=c}return{proxy:s,setInner:a}}function we(e){var t,n,o,r,s,a,c,i,l;if(typeof window=="undefined")return ee;pt=e.apiKey;let d=e.respectDoNotTrack!==!1&&ue(),p=e.consent===!1||d,S=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!S&&e.localMode!==!1)return p?(Y.set(e.apiKey||"local",{config:e,upgrade:null}),ee):(Y.set(e.apiKey||"local",{config:e,upgrade:null}),un(e));if(p){if(e.preConsentBehavior==="statistical_winner"){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."),ee;let{proxy:u,setInner:g}=fn(e);return Y.set(e.apiKey,{config:e,upgrade:d?null:g}),u}return Y.set(e.apiKey,{config:e,upgrade:null}),ee}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."),ee;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),ee;let f=(t=e.ingestUrl)!=null?t:ft,y=Date.now(),b=ct({ssrSessionId:e.ssrSessionId}),j=an(),R=on({ingestUrl:f,apiKey:e.apiKey}),h=gt(f),v={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},A=Te((n=navigator.userAgent)!=null?n:""),D=typeof window!="undefined"?window.location.origin:void 0,fe=Le((o=document.referrer)!=null?o:"",D),x=(r=e.sessionSegment)!=null?r:`${A}:${fe}`,Z=new Map,T=new Map,C=null,re=u=>{for(let g of u)T.has(g.id)||T.set(g.id,he(g))};if(e.initialSlots)for(let[u,g]of Object.entries(e.initialSlots))T.set(u,g);let m=Se(e.apiKey);if(m)for(let[u,g]of Object.entries(m.slots))T.has(u)||T.set(u,g);let w={low:.15,medium:.5,high:.85};if(e.initialPersona)C=E({},e.initialPersona);else{let u=document.documentElement.dataset;u.sentientPersona?C={persona:u.sentientPersona,confidence:(a=w[(s=u.sentientConfidence)!=null?s:"low"])!=null?a:.15}:m&&(C={persona:m.persona,confidence:(c=w[m.band])!=null?c:.15})}if(e.initialAssignments)for(let[u,g]of Object.entries(e.initialAssignments))j.set(u,x,{variantId:g,assignedAt:Date.now(),segment:x,confidence:1});let O=Promise.resolve(),M=b.getSessionId();if(M){let u=Pe((i=document.referrer)!=null?i:""),g=E(E({sessionId:M,deviceClass:A,trafficSource:fe,referrerDomain:u,utmParams:dn(),timeOfDay:Ne(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:b.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||De((l=navigator.userAgent)!=null?l:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{O=fetch(`${h}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(g),headers:v}).then(I=>{I.status===402&&console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing")}).catch(()=>{})}catch(I){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:R});let q={goal(u,g={},I=1,U=0){let $=b.getSessionId();if(!$)return;let P=Ue();O.then(()=>{fetch(`${h}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:$,name:u,metadata:g,weight:I,stepIndex:U,goalId:P}),headers:v}).catch(()=>{})})},componentGoal(u,g,I){var U,$,P;let W=b.getSessionId();if(!W)return;let B=j.get(u,x),K=B?null:(U=T.get(u))!=null?U:null;if(!B&&K===null){e.debug&&console.warn(`[sentient] componentGoal("${u}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let z=B?B.variantId:je(K),G={id:Ue(),sessionId:W,projectId:e.apiKey,componentId:u,variantId:z,eventType:"goal_achieved",goalType:g,payload:E({reward:($=I==null?void 0:I.reward)!=null?$:1},(P=I==null?void 0:I.metadata)!=null?P:{}),timestamp:Date.now(),timeInSession:Date.now()-y};e.debug&&console.log("[sentient] componentGoal",G),O.then(()=>R.push(G))},identify(u){let g=b.getSessionId();g&&O.then(()=>{fetch(`${h}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:g,userId:u,ephemeral:b.isEphemeral()}),headers:v}).catch(()=>{})})},track(u){let g=b.getSessionId();if(!g)return;let I=ae(E({},u),{id:Ue(),sessionId:g,timestamp:Date.now(),timeInSession:Date.now()-y});e.debug&&console.log("[sentient] track",I),O.then(()=>R.push(I))},getAssignment(u,g){return j.get(u,g)},async assign(u,g,I,U){let $=b.getSessionId();if(!$)return null;let P=j.get(u,x);if(P&&(g!=null&&g.length||P.content!==void 0))return{variantId:P.variantId,assignmentTtlMs:0,content:P.content};let W=Z.get(u);if(W)return W;let B=(async()=>{await O;try{let K={sessionId:$,componentId:u,variantIds:g};U!==void 0?K.agentDataByVariant=U:I!==void 0&&(K.agentData=I);let z=await fetch(`${h}/assign`,{method:"POST",body:JSON.stringify(K),headers:v});if(!z.ok)return null;let G=await z.json();return j.set(u,x,{variantId:G.variantId,assignedAt:Date.now(),segment:x,confidence:1,content:G.content}),G}catch(K){return null}finally{Z.delete(u)}})();return Z.set(u,B),B},async decide(u){var g,I,U,$,P,W,B,K,z,G;let Ve=b.getSessionId();if(!Ve)return null;let oe=(g=u.slots)!=null?g:[];await O;try{let H={sessionId:Ve};u.sections&&u.sections.length>0&&(H.sections=u.sections.map(N=>({id:N}))),H.components=(I=u.components)!=null?I:[],oe.length>0&&(H.slots=oe.map(me)),u.slotsFrom==="registry"&&(H.slotsFrom="registry"),u.v&&(H.v=u.v);let ze=await fetch(`${h}/decide`,{method:"POST",body:JSON.stringify(H),headers:v});if(!ze.ok)return re(oe),null;let _=await ze.json(),ie={};for(let N of oe)ie[N.id]=($=(U=_.slots)==null?void 0:U[N.id])!=null?$:he(N);if(_.slots)for(let[N,se]of Object.entries(_.slots))N in ie||(ie[N]=se);for(let[N,se]of Object.entries(ie))T.set(N,se);C={persona:(P=_.persona)!=null?P:"unknown",confidence:(W=_.confidence)!=null?W:0};for(let[N,se]of Object.entries((B=_.assignments)!=null?B:{}))j.set(N,x,{variantId:se,assignedAt:Date.now(),segment:x,confidence:1});return ce(e.apiKey,E({v:1,persona:C.persona,band:F(C.confidence),slots:Object.fromEntries(T),layoutOrder:(K=_.layoutOrder)!=null?K:null,savedAt:Date.now()},_.slotConfig?{slotConfig:_.slotConfig}:{})),E(E({layoutOrder:(z=_.layoutOrder)!=null?z:null,assignments:(G=_.assignments)!=null?G:{},slots:ie,persona:C.persona,confidence:C.confidence},_.slotConfig?{slotConfig:_.slotConfig}:{}),_.goals?{goals:_.goals}:{})}catch(H){return re(oe),null}},getSlotResult(u){var g;return(g=T.get(u))!=null?g:null},getPersona(){return C?{persona:C.persona,confidence:C.confidence,band:F(C.confidence)}:null},async fetchWeights(){var u;try{let g=await fetch(`${h}/weights`,{headers:v});return g.ok?(u=(await g.json()).components)!=null?u:[]:[]}catch(g){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){R.destroy(),e.debug&&console.log("[sentient] disposed")},destroy(){R.destroy(),b.destroy();try{localStorage.removeItem(be+e.apiKey),localStorage.removeItem(ut(e.apiKey))}catch(u){}e.debug&&console.log("[sentient] destroyed")}};if(Y.set(e.apiKey,{config:e,upgrade:null}),e.debug){let u=window;u.__sentient&&(u.__sentient.client=q)}return q}le();var pn=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]];function gn(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function mn(e){var o;let t=e.querySelectorAll('a, button, [role="button"]').length,n=((o=e.textContent)!=null?o:"").trim().length;return t>=1&&n>0&&n<200}function mt(e){let t=e.tagName.toLowerCase();if(t==="nav"||t==="footer")return"navigation";let n=`${e.id} ${e.className} ${gn(e)}`.toLowerCase();for(let[o,r]of pn)if(r.test(n))return o;return mn(e)?"cta":t==="header"||/\b(hero|headline|banner)\b/i.test(n)?"hero":"generic"}var ht="section, header, footer, nav, main > div, [data-sentient-section]";function hn(e){var t;return((t=e.parentElement)==null?void 0:t.closest(ht))!=null}function yn(e,t,n,o){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:o})}).catch(()=>{})}catch(r){}}function yt(e,t,n,o=document){var S,f,y,b,j,R;if(typeof IntersectionObserver=="undefined"||typeof o=="undefined")return;let r=Array.from(o.querySelectorAll(ht)).filter(h=>!hn(h));if(r.length===0)return;let s=new Map,a=new Map;for(let h of r){let v=mt(h),A=`nc-${v}`;s.set(h,A),a.set(A,v)}let c=(b=(y=(f=(S=o.defaultView)!=null?S:typeof window!="undefined"?window:void 0)==null?void 0:f.location)==null?void 0:y.pathname)!=null?b:"/";yn(t,n,c,[...a.entries()].map(([h,v])=>({componentId:h,semanticType:v})));let i=new Map,l=h=>{let v=i.get(h);return v||(v={ms:0,scroll:0,enterAt:null,intersecting:!1},i.set(h,v)),v},d=new IntersectionObserver(h=>{for(let v of h){let A=s.get(v.target);if(!A)continue;let D=l(A);v.isIntersecting?(D.intersecting=!0,D.enterAt=Date.now(),v.intersectionRatio>D.scroll&&(D.scroll=v.intersectionRatio)):(D.intersecting=!1,D.enterAt!=null&&(D.ms+=Date.now()-D.enterAt,D.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let h of s.keys())d.observe(h);let p=()=>{let h=Date.now();for(let[v,A]of i)if(A.enterAt!=null&&(A.ms+=h-A.enterAt,A.enterAt=null),!(A.ms<=0)){try{e.track({projectId:t,componentId:v,eventType:"dwell",payload:{dwell_time:Math.round(A.ms),scroll_depth:Number(A.scroll.toFixed(2))}})}catch(D){}A.ms=0}};o.addEventListener("visibilitychange",()=>{if(o.hidden)p();else{let h=Date.now();for(let v of i.values())v.intersecting&&(v.enterAt=h)}}),(R=(j=o.defaultView)!=null?j:window)==null||R.addEventListener("pagehide",()=>{p();try{d.disconnect()}catch(h){}})}var vn=["landing","ecommerce","saas","marketplace"];function bn(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[o,r]of t){if(!Array.isArray(r)||r.length<2||r.length>6||!r.every(s=>typeof s=="string"))return null;n[o]=r}return n}function Sn(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function Ae(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=vn.includes(t.context)?t.context:"landing",o={};if(typeof t.slots=="object"&&t.slots!==null&&!Array.isArray(t.slots))for(let[s,a]of Object.entries(t.slots)){if(typeof a!="object"||a===null)continue;let c=a,i=bn(c.dims);if(!i||c.target!==void 0&&typeof c.target!="string")continue;let l=c.arms!==void 0?Sn(c.arms):null,d={dims:i};typeof c.target=="string"&&(d.target=c.target),l&&(d.arms=l),o[s]=d}let r={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:o};return typeof t.consent=="boolean"&&(r.consent=t.consent),(t.preConsentBehavior==="statistical_winner"||t.preConsentBehavior==="control")&&(r.preConsentBehavior=t.preConsentBehavior),t.debug===!0&&(r.debug=!0),typeof t.registry=="boolean"&&(r.registry=t.registry),typeof t.editorSrc=="string"&&(r.editorSrc=t.editorSrc),typeof t.apiBase=="string"&&(r.apiBase=t.apiBase),t.sectionCapture===!0&&(r.sectionCapture=!0),r}function vt(e){var n,o,r;let t=(o=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:o.location;return(r=t==null?void 0:t.pathname)!=null?r:""}function wn(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let o=((n=e.textContent)!=null?n:"").trim().toLowerCase(),r=t.text.trim().toLowerCase();if(!(o===r||o.startsWith(r)||r.startsWith(o)))return!1}return!0}function bt(e,t){return!!(e!=null&&e.urlMatch)&&!vt(t).includes(e.urlMatch)}function te(e,t){var r;if(e.urlMatch&&!vt(t).includes(e.urlMatch))return null;let n=[];if(e.id){let s=t.getElementById(e.id);n=s?[s]:[]}if(n.length===0&&((r=e.dataAttr)!=null&&r.name))try{let s=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${s}"]`))}catch(s){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(s){n=[]}if(n.length!==1)return null;let o=n[0];return e.fingerprint&&!wn(o,e.fingerprint)?null:o}var St=/^https:\/\//i,An={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"};function kn(e){return!/[;{}<>]/.test(e)}var wt=new Map,J=null;function In(e){return e.replace(/["\\]/g,"\\$&")}function En(e){var t;(!J||!J.isConnected)&&(J=e.querySelector("style[data-sentient-ops]"),J||(J=e.createElement("style"),J.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(J))),J.textContent=[...wt.entries()].map(([n,o])=>`[data-snt-e="${In(n)}"]{${o}}`).join(`
2
+ `)}function At(e,t,n,o){var c;let r=!1,s=(c=t.moveBefore)!=null?c:t.moveAfter;if(s){let i=te(s,o);!i||i===e||i.parentElement!==e.parentElement||!e.parentElement?r=!0:t.moveBefore?e.parentElement.insertBefore(e,i):e.parentElement.insertBefore(e,i.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&St.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&St.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let a=[];if(t.hidden&&a.push("display:none !important"),t.style)for(let[i,l]of Object.entries(t.style)){let d=An[i];d&&typeof l=="string"&&kn(l)&&a.push(`${d}:${l.trim()} !important`)}return a.length>0&&(e.setAttribute("data-snt-e",n),wt.set(n,a.join(";")),En(o)),{anchorMiss:r}}function ke(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function Ie(e,t,n){var o;for(let[r,s]of Object.entries(t)){let a=e[r];if(!a||typeof a=="string")continue;let c=s.target?Array.from(n.querySelectorAll(s.target)):[n.documentElement];for(let i of c)for(let[l,d]of Object.entries(a))(o=s.dims[l])!=null&&o.includes(d)&&i.setAttribute(`data-${l}`,d)}}function Ee(e,t,n){for(let[o,r]of Object.entries(t)){let s=e[o];if(typeof s!="string"||!r.arms||!r.arms.includes(s))continue;let a=r.target?Array.from(n.querySelectorAll(r.target)):[n.documentElement];for(let c of a)c.setAttribute("data-sentient-arm",s)}}function Oe(e,t,n,o){var a;let r=(a=o==null?void 0:o.contentAndOps)!=null?a:!0,s=[];for(let[c,i]of Object.entries(t)){if(bt(i.locator,n))continue;let l;if(i.locator){let p=te(i.locator,n);l=p?[p]:[]}else i.target?l=Array.from(n.querySelectorAll(i.target)):l=[n.documentElement];(i.locator||i.target)&&l.length===0&&s.push(c);let d=e[c];for(let p of l){if(d!==void 0)if(typeof d=="string")p.setAttribute("data-sentient-arm",d);else for(let[S,f]of Object.entries(d))p.setAttribute(`data-${S}`,f);r&&(typeof i.content=="string"&&(p.textContent=i.content),i.ops&&At(p,i.ops,c,n).anchorMiss&&!s.includes(c)&&s.push(c))}}return s}function On(e){var n,o,r;let t=(o=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0)==null?void 0:o.location;return(r=t==null?void 0:t.pathname)!=null?r:""}function kt(e,t,n){var S;let o=new Set,r=f=>{if(!o.has(f.goalId)){o.add(f.goalId);try{f.slotId?t.componentGoal(f.slotId,f.goalId):t.goal(f.goalId)}catch(y){}}},s=e.filter(f=>f.event==="click"),a=e.filter(f=>f.event==="form_submit"),c=e.filter(f=>f.event==="url_reached"),i=(f,y)=>{if(!f.locator)return!1;let b=te(f.locator,n);return!!b&&(b===y||b.contains(y))},l=f=>{let y=f.target;if(!(!y||typeof y.closest!="function"))for(let b of s)i(b,y)&&r(b)},d=f=>{let y=f.target;if(y)for(let b of a)i(b,y)&&r(b)},p=()=>{if(c.length===0)return;let f=On(n);for(let y of c)y.urlPattern&&f.includes(y.urlPattern)&&r(y)};return n.addEventListener("click",l,!0),n.addEventListener("submit",d,!0),(S=n.defaultView)==null||S.addEventListener("popstate",p),p(),{checkUrl:p,teardown:()=>{var f;n.removeEventListener("click",l,!0),n.removeEventListener("submit",d,!0),(f=n.defaultView)==null||f.removeEventListener("popstate",p)}}}var xt="0.4.0",xn=5e3,Cn=50,de=null,L=null,V={},ne=null,X=null,k=null,It=!1,qe=null;function _n(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function xe(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function Ce(e,t){return de?(de.personaAttributes&&k&&ke(k.persona,k.band,e),Ie(V,de.slots,e),Ee(V,de.slots,e),ne?Oe(V,ne,e,t):[]):[]}function Rn(e,t){var n;if(t.length!==0)try{let o=(n=e.apiBase)!=null?n:"https://api.sentient-ui.com";fetch(`${o}/v1/locator-miss`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify({slots:t})}).catch(()=>{})}catch(o){}}function Je(){try{Ce(document)}catch(e){}}function Et(){qe===null&&(qe=setTimeout(()=>{qe=null,Je();try{X==null||X.checkUrl()}catch(e){}},Cn))}function Ot(){if(!(It||typeof window=="undefined"||typeof history=="undefined")){It=!0;try{let e=t=>{let n=history[t];history[t]=function(o,r,s){let a=n.call(this,o,r,s!=null?s:null);return Et(),a}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Et)}catch(e){}}}function We(e){let t={};for(let[n,o]of Object.entries(e.slots))t[n]=o.target?document.querySelectorAll(o.target).length:1;return t}function Ct(e){return new URLSearchParams(e).get("sentient_editor")}function Dn(){try{let t=Array.from(document.getElementsByTagName("script")).find(n=>/snippet(\.global)?\.js/.test(n.src));if(t!=null&&t.src)return t.src.replace(/snippet(\.global)?\.js/,"editor.global.js")}catch(e){}return null}function Tn(e,t){var n,o,r,s;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let i=document.createElement("meta");i.name="referrer",i.content="no-referrer",((o=document.head)!=null?o:document.documentElement).appendChild(i)}catch(i){}let a=(r=e.editorSrc)!=null?r:Dn();if(!a)return;let c=document.createElement("script");c.src=a,c.async=!0,((s=document.head)!=null?s:document.documentElement).appendChild(c)}catch(a){}}function _t(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let o of t.split("|")){let[r,s]=o.split(":");if(!(!r||!s))if(s.includes("=")){let a={};for(let c of s.split(",")){let[i,l]=c.split("=");i&&l&&(a[i]=l)}Object.keys(a).length&&(n[r]=a)}else n[r]=s}return Object.keys(n).length?n:null}function Ln(e){let t={goal(n,o){try{L==null||L.goal(n,o)}catch(r){}},componentGoal(n,o){try{L==null||L.componentGoal(n,o)}catch(r){}},grantConsent(){try{Ge(e.apiKey)}catch(n){}},revokeConsent(){try{L==null||L.destroy()}catch(n){}},reapply:Je,getState(){var n,o;return{apiKey:e.apiKey,persona:(n=k==null?void 0:k.persona)!=null?n:null,band:(o=k==null?void 0:k.band)!=null?o:null,slots:V,matchCounts:We(e),consent:e.consent!==!1}}};window.SentientSnippet=t}async function Rt(){var e,t,n,o;try{let r=Ae(window.sentient);if(!r)return;de=r;let s=typeof window!="undefined"?Ct(window.location.search):null;if(s){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){}Tn(r,s),xe(r,"editor mode");return}let a=typeof window!="undefined"?_t(window.location.search):null;if(a){V=a,k=null,Ce(document),Ot(),xe(r,"preview mode",a);return}let c=(e=r.registry)!=null?e:Object.keys(r.slots).length===0,i=Se(r.apiKey);i&&(k={persona:i.persona,band:i.band},V=i.slots,i.slotConfig&&(ne=i.slotConfig),Ce(document,{contentAndOps:!1}));let l=we({apiKey:r.apiKey,context:r.context,consent:r.consent,preConsentBehavior:r.preConsentBehavior,debug:r.debug});L=l,Ln(r),Ot();let d=Object.entries(r.slots).map(([f,y])=>({id:f,dims:y.dims})),p=await _n(l.decide(_e({slots:d,v:xt},c?{slotsFrom:"registry"}:{})),xn);if(!p){xe(r,"decide timeout/null \u2014 snapshot state stands",We(r));return}let S=l.getPersona();if(S?k={persona:S.persona,band:S.band}:p.persona&&(k={persona:p.persona,band:"low"}),V=p.slots,p.slotConfig&&(ne=p.slotConfig),Rn(r,Ce(document)),p.goals&&p.goals.length>0&&r.consent!==!1&&L)try{X==null||X.teardown(),X=kt(p.goals,L,document)}catch(f){}if(r.sectionCapture&&r.consent!==!1&&L&&!ue())try{yt(L,r.apiKey,(t=r.apiBase)!=null?t:"https://api.sentient-ui.com",document)}catch(f){}xe(r,"applied",{persona:k,slots:V,matches:We(r)}),ce(r.apiKey,_e({v:1,persona:(n=k==null?void 0:k.persona)!=null?n:p.persona,band:(o=k==null?void 0:k.band)!=null?o:"low",slots:p.slots,layoutOrder:p.layoutOrder,savedAt:Date.now()},ne?{slotConfig:ne}:{}))}catch(r){}}typeof window!="undefined"&&window.sentient&&Rt();return Nt(Pn);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentientui/snippet",
3
- "version": "0.2.2",
3
+ "version": "0.4.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
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  "tsx": "^4.19.2",
17
17
  "typescript": "^5.7.2",
18
18
  "vitest": "^2.1.8",
19
- "@sentientui/core": "0.12.0"
19
+ "@sentientui/core": "0.14.0"
20
20
  },
21
21
  "scripts": {
22
22
  "build": "tsup",