@sentientui/snippet 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/snippet.global.js +2 -2
- package/package.json +8 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Carlos Sánchez Campos / SentientUI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/snippet.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var SentientSnippet=(()=>{var me=Object.defineProperty;var Jt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames,He=Object.getOwnPropertySymbols;var Xe=Object.prototype.hasOwnProperty,Ft=Object.prototype.propertyIsEnumerable;var Ye=(e,t,n)=>t in e?me(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,he=(e,t)=>{for(var n in t||(t={}))Xe.call(t,n)&&Ye(e,n,t[n]);if(He)for(var n of He(t))Ft.call(t,n)&&Ye(e,n,t[n]);return e};var Ze=(e,t)=>()=>(e&&(t=e(e=0)),t);var Qe=(e,t)=>{for(var n in t)me(e,n,{get:t[n],enumerable:!0})},Ht=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Vt(t))!Xe.call(e,o)&&o!==n&&me(e,o,{get:()=>t[o],enumerable:!(r=Jt(t,o))||r.enumerable});return e};var Yt=e=>Ht(me({},"__esModule",{value:!0}),e);var Xt,Zt,Qt,et,en,tn,tt,I,de,oe=Ze(()=>{"use strict";Xt=Object.defineProperty,Zt=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,et=Object.getOwnPropertySymbols,en=Object.prototype.hasOwnProperty,tn=Object.prototype.propertyIsEnumerable,tt=(e,t,n)=>t in e?Xt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,I=(e,t)=>{for(var n in t||(t={}))en.call(t,n)&&tt(e,n,t[n]);if(et)for(var n of et(t))tn.call(t,n)&&tt(e,n,t[n]);return e},de=(e,t)=>Zt(e,Qt(t))});var st={};Qe(st,{LOCAL_ENGINE_AVAILABLE:()=>nn,createLocalEngine:()=>rn});function rn(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var nn,at=Ze(()=>{"use strict";oe();nn=!1});var Fn={};Qe(Fn,{applyPersonaAttributes:()=>Oe,applyRegistrySlots:()=>_e,applySlotArms:()=>Ce,applySlotAttributes:()=>Ie,parseEditorToken:()=>Ut,parsePersonaPreview:()=>qt,parsePreview:()=>Gt,parseSnippetConfig:()=>Ee,reapply:()=>Je,run:()=>zt,version:()=>$t});oe();function ye(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function nt(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 Pe(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 ye(e.baseline);if(typeof e.baseline=="string")return e.baseline;let o={};for(let[i,s]of Object.entries((n=e.dims)!=null?n:{}))o[i]=(r=s[0])!=null?r:"";return ye(o)}function rt(e,t){var n,r;return e.dims!=null?(r=(n=nt(t))!=null?n:nt(Pe(e)))!=null?r:{}:t}function Q(e){return e>=.3?e<.7?"medium":"high":"low"}var ot=["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 Re(e){return it(e)!==null}function it(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=ot.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function Le(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 Te(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 De(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function je(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function be(e){return I(I(I({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 ve(e){let t=be(e);return rt(t,Pe(t))}function Ne(e){return typeof e=="string"?e:ye(e)}oe();var on="_snt_uid",ie="_snt_uid";function sn(){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 an(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function ln(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function cn(e){try{return localStorage.getItem(e)}catch(t){return null}}function un(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function dn(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function fn(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function pn(e){try{sessionStorage.removeItem(e)}catch(t){}}function gn(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 mn(e){try{localStorage.removeItem(e)}catch(t){}}function hn(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var yn={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ut(e){var t,n,r,o,i,s;if(typeof window=="undefined")return yn;let l=(t=e==null?void 0:e.cookieName)!=null?t:on,a=((n=e==null?void 0:e.cookieTTLDays)!=null?n:365)*24*60*60,c=(s=(i=(o=(r=an(l))!=null?r:cn(ie))!=null?o:dn(ie))!=null?i:e==null?void 0:e.ssrSessionId)!=null?s:sn();ln(l,c,a);let d=un(ie,c),p=gn(l),b=d?!1:fn(ie,c),g=!d&&!p&&!b;return{getSessionId:()=>c,isEphemeral:()=>g,destroy:()=>{c=null,hn(l),mn(ie),pn(ie)}}}function dt(e){return`_snt_retry_${e.slice(0,12)}`}var bn={push:()=>{},flush:()=>{},destroy:()=>{}};function vn(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 Me(e,t,n){try{let r=[...(()=>{try{let o=localStorage.getItem(n);if(!o)return[];let i=JSON.parse(o);return Array.isArray(i)?i:[]}catch(o){return[]}})(),...e].slice(-t);localStorage.setItem(n,JSON.stringify(r))}catch(r){}}function wn(e){var t,n,r;if(typeof window=="undefined")return bn;let o=(t=e.flushIntervalMs)!=null?t:5e3,i=(n=e.maxBatchSize)!=null?n:20,s=(r=e.maxRetrySize)!=null?r:100,l=e.ingestUrl,a=e.apiKey,c=dt(a),d=[],p=new Set,b=[],g=f=>{for(let w of f)v.delete(w),!p.has(w)&&(p.add(w),b.push(w));for(;b.length>500;){let w=b.shift();w&&p.delete(w)}},v=new Set,m=f=>{p.has(f.id)||v.has(f.id)||(v.add(f.id),d.push(f))},A=vn(s,c);for(let f of A)m(f);let E=0,S=0,T=f=>{if(f.length===0)return;let w=JSON.stringify(f),k=f.map(u=>u.id),$;try{$=fetch(l,{method:"POST",keepalive:!0,body:w,headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}})}catch(u){Me(f,s,c);for(let h of k)v.delete(h);S++,E=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6));return}let z=u=>{if(u.ok||u.status>=400&&u.status<500&&u.status!==429){g(k),S=0,E=0;return}Me(f,s,c);for(let h of k)v.delete(h);S++,E=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6))};$ instanceof Promise?$.then(z).catch(()=>{Me(f,s,c);for(let u of k)v.delete(u);S++,E=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6))}):z($)},G=typeof TextEncoder!="undefined"?new TextEncoder:null,H=f=>G?G.encode(f).length:f.length,Y=f=>{let w=[],k=2;for(let $ of f){let z=H(JSON.stringify($))+1;if(w.length>0&&k+z>57344||w.length>=i)break;w.push($),k+=z}return w},C=()=>{try{if(Date.now()<E)return;for(;d.length>0;){let f=d.filter(k=>!p.has(k.id));if(d.length=0,f.length===0)break;let w=Y(f);if(w.length===0)break;w.length<f.length&&d.push(...f.slice(w.length)),T(w)}}catch(f){}},N=!0,P=null;P=setInterval(()=>{N&&C()},o);let y=()=>{document.visibilityState==="hidden"&&C()},x=()=>{C()};return document.addEventListener("visibilitychange",y),window.addEventListener("beforeunload",x),{push(f){m(f),d.length>=i&&C()},flush:C,destroy(){N=!1,P!==null&&(clearInterval(P),P=null),document.removeEventListener("visibilitychange",y),window.removeEventListener("beforeunload",x),C()}}}var Ue="_snt_asgn_";function we(e,t){return`${e}:${t}`}function Sn(e,t){return`${Ue}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function lt(e){let t=e.slice(Ue.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 $e(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(Ue)&&e.push(n)}return e}catch(e){return[]}}function xn(e=18e5){let t=new Map,n=r=>r.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let r of $e())try{let o=localStorage.getItem(r);if(!o)continue;let i=JSON.parse(o);if(n(i)){localStorage.removeItem(r);continue}let s=lt(r);if(!s)continue;t.set(we(s.componentId,s.segment),i)}catch(o){}})(),{get(r,o){let i=t.get(we(r,o));return i?n(i)?(t.delete(we(r,o)),null):i:null},set(r,o,i){let s=we(r,o);t.set(s,i);try{localStorage.setItem(Sn(r,o),JSON.stringify(i))}catch(l){}},invalidate(r){let o=`${r}:`;for(let i of[...t.keys()])i.startsWith(o)&&t.delete(i);for(let i of $e()){let s=lt(i);if((s==null?void 0:s.componentId)===r)try{localStorage.removeItem(i)}catch(l){}}},clear(){t.clear();for(let r of $e())try{localStorage.removeItem(r)}catch(o){}}}}var xe="_snt_snap:",kn=["low","medium","high"];function ke(e){try{let t=localStorage.getItem(xe+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"||!kn.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 fe(e,t){try{localStorage.setItem(xe+e,JSON.stringify(t))}catch(n){}}var Ke="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",ft="[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.",ct=!1,Se=!1;function An(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function En(e){var t;let n=ut({ssrSessionId:e.ssrSessionId}),r=(t=n.getSessionId())!=null?t:"local",o=An(),i=Promise.resolve().then(()=>(at(),st)).then(a=>{let c=a;return c.LOCAL_ENGINE_AVAILABLE?(ct||(ct=!0,console.info(ft)),c):(Se||(Se=!0,console.error(Ke)),null)}).catch(()=>(Se||(Se=!0,console.error(Ke)),null)),s=null;function l(a){let c=document.documentElement;c.dataset.sentientPersona===void 0&&(c.dataset.sentientPersona=a.persona,c.dataset.sentientConfidence=Q(a.confidence))}return{isLocal:!0,async decide(a){var c,d,p;let b=await i;if(!b)return null;let g=b.createLocalEngine({sessionId:r,forcedPersona:o}).decide(a);return s=de(I({},g),{layoutOrder:(d=(c=g.layoutOrder)!=null?c:s==null?void 0:s.layoutOrder)!=null?d:null,slots:I(I({},(p=s==null?void 0:s.slots)!=null?p:{}),g.slots)}),fe(e.apiKey||"local",{v:1,persona:s.persona,band:Q(s.confidence),slots:s.slots,layoutOrder:s.layoutOrder,savedAt:Date.now()}),l(g),g},getSlotResult(a){var c,d,p;return(p=(d=s==null?void 0:s.slots[a])!=null?d:(c=e.initialSlots)==null?void 0:c[a])!=null?p:null},getPersona(){return s?{persona:s.persona,confidence:s.confidence,band:Q(s.confidence)}:null},async assign(a,c){var d;let p=await i;return!p||!c||c.length===0?c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null:{variantId:(d=p.createLocalEngine({sessionId:r,forcedPersona:o}).decide({components:[{id:a,variantIds:c}]}).assignments[a])!=null?d:c[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function Ge(e,t,n){var r;let o=[];{let i=!1,s=[],l=()=>{if(i)return;let a=Date.now();for(s.push(a);s.length>0&&a-s[0]>500;)s.shift();s.length>=3&&(i=!0,e("rage_click"))};t.addEventListener("click",l),o.push(()=>t.removeEventListener("click",l))}{let i=!1,s=l=>{if(i||!(l.target instanceof Node)||!t.contains(l.target)&&t!==l.target)return;i=!0;let a=typeof window!="undefined"?window.getSelection():null,c=a?a.toString().length:0;e("text_copy",{selectionLength:c})};document.addEventListener("copy",s),o.push(()=>document.removeEventListener("copy",s))}{let i=!1,s=!1,l=null,a=()=>{l!==null&&(clearTimeout(l),l=null)},c=()=>{i||!s||(a(),l=setTimeout(()=>{!i&&s&&(i=!0,e("scroll_hesitation"))},3e3))},d=()=>{a(),c()},p=g=>{for(let v of g)s=v.intersectionRatio>.3,s?c():a()};typeof process!="undefined"&&((r=process.env)==null?void 0:r.NODE_ENV)!=="production"&&(window.__lastIOCallback=p);let b=new IntersectionObserver(p,{threshold:[.3]});b.observe(t),window.addEventListener("scroll",d,{passive:!0}),o.push(()=>{b.disconnect(),window.removeEventListener("scroll",d),a()})}{let i=!1,s=n!=null?n:Date.now(),l=()=>{if(i||document.visibilityState!=="hidden")return;let a=Date.now()-s;a<15e3&&(i=!0,e("tab_loss",{timeOnPage:a}))};document.addEventListener("visibilitychange",l),o.push(()=>document.removeEventListener("visibilitychange",l))}return()=>{for(let i of o)i()}}var pt="https://api.sentient-ui.com/v1/events",ee=new Map,gt=null;function Be(){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 se={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 On(){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 mt(e){return e.replace(/\/events\/?$/,"")}function te(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(e=>e==="1"||e==="yes")}function qe(e){if(typeof window=="undefined")return;let t=e!=null?e:gt;if(!t){console.warn("[sentient] grantConsent() called before init()");return}let n=ee.get(t);if(!n){console.warn("[sentient] grantConsent() called before init()");return}let{config:r,upgrade:o}=n;if(!o||r.respectDoNotTrack!==!1&&te())return;let i=Ae(de(I({},r),{consent:!0}));o(i),ee.set(t,{config:de(I({},r),{consent:!0}),upgrade:null})}function In(e){var t;let n=mt((t=e.ingestUrl)!=null?t:pt),r={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(l,a,c){try{let d=new URLSearchParams({componentId:l});for(let b of a!=null?a:[])d.append("variantIds[]",b);let p=await fetch(`${n}/winner?${d.toString()}`,{headers:r});return p.ok?{variantId:(await p.json()).variantId,assignmentTtlMs:0}:a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}catch(d){return a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},i={track:l=>o.track(l),goal:(l,a,c,d)=>o.goal(l,a,c,d),componentGoal:(l,a,c)=>o.componentGoal(l,a,c),identify:l=>o.identify(l),getAssignment:(l,a)=>o.getAssignment(l,a),assign:(l,a,c,d)=>o.assign(l,a,c,d),decide:l=>o.decide(l),getSlotResult:l=>o.getSlotResult(l),getPersona:()=>o.getPersona(),fetchWeights:()=>o.fetchWeights(),getGraph:()=>o.getGraph(),dispose:()=>o.dispose(),destroy:()=>o.destroy()};function s(l){o=l}return{proxy:i,setInner:s}}function Ae(e){var t,n,r,o,i,s,l,a,c;if(typeof window=="undefined")return se;gt=e.apiKey;let d=e.respectDoNotTrack!==!1&&te(),p=e.consent===!1||d,b=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!b&&e.localMode!==!1)return p?(ee.set(e.apiKey||"local",{config:e,upgrade:null}),se):(ee.set(e.apiKey||"local",{config:e,upgrade:null}),En(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."),se;let{proxy:u,setInner:h}=In(e);return ee.set(e.apiKey,{config:e,upgrade:d?null:h}),u}return ee.set(e.apiKey,{config:e,upgrade:null}),se}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."),se;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),se;let g=(t=e.ingestUrl)!=null?t:pt,v=Date.now(),m=ut({ssrSessionId:e.ssrSessionId}),A=xn(),E=wn({ingestUrl:g,apiKey:e.apiKey}),S=mt(g),T={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},G=Le((n=navigator.userAgent)!=null?n:""),H=typeof window!="undefined"?window.location.origin:void 0,Y=Te((r=document.referrer)!=null?r:"",H),C=(o=e.sessionSegment)!=null?o:`${G}:${Y}`,N=new Map,P=new Map,y=null,x=u=>{for(let h of u)P.has(h.id)||P.set(h.id,ve(h))};if(e.initialSlots)for(let[u,h]of Object.entries(e.initialSlots))P.set(u,h);let f=ke(e.apiKey);if(f)for(let[u,h]of Object.entries(f.slots))P.has(u)||P.set(u,h);let w={low:.15,medium:.5,high:.85};if(e.initialPersona)y=I({},e.initialPersona);else{let u=document.documentElement.dataset;u.sentientPersona?y={persona:u.sentientPersona,confidence:(s=w[(i=u.sentientConfidence)!=null?i:"low"])!=null?s:.15}:f&&(y={persona:f.persona,confidence:(l=w[f.band])!=null?l:.15})}if(e.initialAssignments)for(let[u,h]of Object.entries(e.initialAssignments))A.set(u,C,{variantId:h,assignedAt:Date.now(),segment:C,confidence:1});let k=Promise.resolve(),$=m.getSessionId();if($){let u=De((a=document.referrer)!=null?a:""),h=I(I({sessionId:$,deviceClass:G,trafficSource:Y,referrerDomain:u,utmParams:On(),timeOfDay:je(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:m.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||Re((c=navigator.userAgent)!=null?c:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{k=fetch(`${S}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(h),headers:T}).then(_=>{_.status===402&&console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing")}).catch(()=>{})}catch(_){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:E});let z={goal(u,h={},_=1,B=0){let M=m.getSessionId();if(!M)return;let D=Be();k.then(()=>{fetch(`${S}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:M,name:u,metadata:h,weight:_,stepIndex:B,goalId:D}),headers:T}).catch(()=>{})})},componentGoal(u,h,_){var B,M,D;let J=m.getSessionId();if(!J)return;let K=A.get(u,C),U=K?null:(B=P.get(u))!=null?B:null;if(!K&&U===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 X=K?K.variantId:Ne(U),q={id:Be(),sessionId:J,projectId:e.apiKey,componentId:u,variantId:X,eventType:"goal_achieved",goalType:h,payload:I({reward:(M=_==null?void 0:_.reward)!=null?M:1},(D=_==null?void 0:_.metadata)!=null?D:{}),timestamp:Date.now(),timeInSession:Date.now()-v};e.debug&&console.log("[sentient] componentGoal",q),k.then(()=>E.push(q))},identify(u){let h=m.getSessionId();h&&k.then(()=>{fetch(`${S}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:h,userId:u,ephemeral:m.isEphemeral()}),headers:T}).catch(()=>{})})},track(u){let h=m.getSessionId();if(!h)return;let _=de(I({},u),{id:Be(),sessionId:h,timestamp:Date.now(),timeInSession:Date.now()-v});e.debug&&console.log("[sentient] track",_),k.then(()=>E.push(_))},getAssignment(u,h){return A.get(u,h)},async assign(u,h,_,B){let M=m.getSessionId();if(!M)return null;let D=A.get(u,C);if(D&&(h!=null&&h.length||D.content!==void 0))return{variantId:D.variantId,assignmentTtlMs:0,content:D.content};let J=N.get(u);if(J)return J;let K=(async()=>{await k;try{let U={sessionId:M,componentId:u,variantIds:h};B!==void 0?U.agentDataByVariant=B:_!==void 0&&(U.agentData=_);let X=await fetch(`${S}/assign`,{method:"POST",body:JSON.stringify(U),headers:T});if(!X.ok)return null;let q=await X.json();return A.set(u,C,{variantId:q.variantId,assignedAt:Date.now(),segment:C,confidence:1,content:q.content}),q}catch(U){return null}finally{N.delete(u)}})();return N.set(u,K),K},async decide(u){var h,_,B,M,D,J,K,U,X,q;let Ve=m.getSessionId();if(!Ve)return null;let le=(h=u.slots)!=null?h:[];await k;try{let Z={sessionId:Ve};u.sections&&u.sections.length>0&&(Z.sections=u.sections.map(j=>({id:j}))),Z.components=(_=u.components)!=null?_:[],le.length>0&&(Z.slots=le.map(be)),u.slotsFrom==="registry"&&(Z.slotsFrom="registry"),u.v&&(Z.v=u.v);let Fe=await fetch(`${S}/decide`,{method:"POST",body:JSON.stringify(Z),headers:T});if(!Fe.ok)return x(le),null;let R=await Fe.json(),ce={};for(let j of le)ce[j.id]=(M=(B=R.slots)==null?void 0:B[j.id])!=null?M:ve(j);if(R.slots)for(let[j,ue]of Object.entries(R.slots))j in ce||(ce[j]=ue);for(let[j,ue]of Object.entries(ce))P.set(j,ue);y={persona:(D=R.persona)!=null?D:"unknown",confidence:(J=R.confidence)!=null?J:0};for(let[j,ue]of Object.entries((K=R.assignments)!=null?K:{}))A.set(j,C,{variantId:ue,assignedAt:Date.now(),segment:C,confidence:1});return fe(e.apiKey,I({v:1,persona:y.persona,band:Q(y.confidence),slots:Object.fromEntries(P),layoutOrder:(U=R.layoutOrder)!=null?U:null,savedAt:Date.now()},R.slotConfig?{slotConfig:R.slotConfig}:{})),I(I({layoutOrder:(X=R.layoutOrder)!=null?X:null,assignments:(q=R.assignments)!=null?q:{},slots:ce,persona:y.persona,confidence:y.confidence},R.slotConfig?{slotConfig:R.slotConfig}:{}),R.goals?{goals:R.goals}:{})}catch(Z){return x(le),null}},getSlotResult(u){var h;return(h=P.get(u))!=null?h:null},getPersona(){return y?{persona:y.persona,confidence:y.confidence,band:Q(y.confidence)}:null},async fetchWeights(){var u;try{let h=await fetch(`${S}/weights`,{headers:T});return h.ok?(u=(await h.json()).components)!=null?u:[]:[]}catch(h){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){E.destroy(),e.debug&&console.log("[sentient] disposed")},destroy(){E.destroy(),m.destroy();try{localStorage.removeItem(xe+e.apiKey),localStorage.removeItem(dt(e.apiKey))}catch(u){}e.debug&&console.log("[sentient] destroyed")}};if(ee.set(e.apiKey,{config:e,upgrade:null}),e.debug){let u=window;u.__sentient&&(u.__sentient.client=z)}return z}oe();var ht=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Cn=[["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]],_n=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function Pn(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function yt(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,r]of Cn)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of _n)if(r.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function bt(e){var t,n;let r=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:Pn(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function vt(e){return yt(bt(e)).type}oe();var St="section, header, footer, nav, main > div, [data-sentient-section]";function Rn(e){var t;return((t=e.parentElement)==null?void 0:t.closest(St))!=null}function Ln(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 wt=()=>{};function xt(e,t){var n,r,o,i,s,l,a,c,d;let p=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!p||typeof IntersectionObserver=="undefined"||te()||!t.apiKey)return wt;let b=(r=t.apiBase)!=null?r:"https://api.sentient-ui.com",g=Array.from(p.querySelectorAll(St)).filter(y=>!Rn(y));if(g.length===0)return wt;let v=new Map,m=new Map,A=new Map;for(let y of g){let x=y.getAttribute("data-sentient-type"),f=x&&ht.includes(x)?x:null,w=(i=f!=null?f:(o=t.typeOf)==null?void 0:o.call(t,y))!=null?i:vt(y),k=`nc-${w}`;v.set(y,k),m.set(k,w),f?A.set(k,"markup"):A.has(k)||A.set(k,"auto")}let E=(c=(a=(l=(s=p.defaultView)!=null?s:typeof window!="undefined"?window:void 0)==null?void 0:l.location)==null?void 0:a.pathname)!=null?c:"/";Ln(t.apiKey,b,E,[...m.entries()].map(([y,x])=>{var f;return{componentId:y,semanticType:x,source:(f=A.get(y))!=null?f:"auto"}}));let S=new Map,T=y=>{let x=S.get(y);return x||(x={ms:0,scroll:0,enterAt:null,intersecting:!1},S.set(y,x)),x},G=new IntersectionObserver(y=>{for(let x of y){let f=v.get(x.target);if(!f)continue;let w=T(f);x.isIntersecting?(w.intersecting=!0,w.enterAt=Date.now(),x.intersectionRatio>w.scroll&&(w.scroll=x.intersectionRatio)):(w.intersecting=!1,w.enterAt!=null&&(w.ms+=Date.now()-w.enterAt,w.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let y of v.keys())G.observe(y);let H=()=>{let y=Date.now();for(let[x,f]of S)if(f.enterAt!=null&&(f.ms+=y-f.enterAt,f.enterAt=null),!(f.ms<=0)){try{e.track({projectId:t.apiKey,componentId:x,eventType:"dwell",payload:{dwell_time:Math.round(f.ms),scroll_depth:Number(f.scroll.toFixed(2))}})}catch(w){}f.ms=0}},Y=()=>{if(p.hidden)H();else{let y=Date.now();for(let x of S.values())x.intersecting&&(x.enterAt=y)}},C=()=>{H();try{G.disconnect()}catch(y){}};p.addEventListener("visibilitychange",Y);let N=(d=p.defaultView)!=null?d:typeof window!="undefined"?window:void 0;N==null||N.addEventListener("pagehide",C);let P=[];if(t.microSignals)for(let[y,x]of v)P.push(Ge((f,w={})=>{try{e.track({projectId:t.apiKey,componentId:x,eventType:"micro_signal",payload:I({signalType:f},w)})}catch(k){}},y));return()=>{H(),p.removeEventListener("visibilitychange",Y),N==null||N.removeEventListener("pagehide",C);for(let y of P)y();try{G.disconnect()}catch(y){}}}var Tn=["landing","ecommerce","saas","marketplace"];function Dn(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(i=>typeof i=="string"))return null;n[r]=o}return n}function jn(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function Ee(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=Tn.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 l=s,a=Dn(l.dims);if(!a||l.target!==void 0&&typeof l.target!="string")continue;let c=l.arms!==void 0?jn(l.arms):null,d={dims:a};typeof l.target=="string"&&(d.target=l.target),c&&(d.arms=c),r[i]=d}let o={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};return 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),o}function kt(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 Nn(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let r=((n=e.textContent)!=null?n:"").trim().toLowerCase(),o=t.text.trim().toLowerCase();if(!(r===o||r.startsWith(o)||o.startsWith(r)))return!1}return!0}function At(e,t){return!!(e!=null&&e.urlMatch)&&!kt(t).includes(e.urlMatch)}function V(e,t){var o;if(e.urlMatch&&!kt(t).includes(e.urlMatch))return null;let n=[];if(e.id){let i=t.getElementById(e.id);n=i?[i]:[]}if(n.length===0&&((o=e.dataAttr)!=null&&o.name))try{let i=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${i}"]`))}catch(i){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(i){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!Nn(r,e.fingerprint)?null:r}var Et=/^https:\/\//i,Mn={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 $n(e){return!/[;{}<>]/.test(e)}var Ot=new Map,F=null;function Bn(e){return e.replace(/["\\]/g,"\\$&")}function Kn(e){var t;(!F||!F.isConnected)&&(F=e.querySelector("style[data-sentient-ops]"),F||(F=e.createElement("style"),F.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(F))),F.textContent=[...Ot.entries()].map(([n,r])=>`[data-snt-e="${Bn(n)}"]{${r}}`).join(`
|
|
2
|
-
`)}function It(e,t,n,r){var l;let o=!1,i=(l=t.moveBefore)!=null?l:t.moveAfter;if(i){let a=V(i,r);!a||a===e||a.parentElement!==e.parentElement||!e.parentElement?o=!0:t.moveBefore?e.parentElement.insertBefore(e,a):e.parentElement.insertBefore(e,a.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&Et.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&Et.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let s=[];if(t.hidden&&s.push("display:none !important"),t.style)for(let[a,c]of Object.entries(t.style)){let d=Mn[a];d&&typeof c=="string"&&$n(c)&&s.push(`${d}:${c.trim()} !important`)}return s.length>0&&(e.setAttribute("data-snt-e",n),Ot.set(n,s.join(";")),Kn(r)),{anchorMiss:o}}function Oe(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function Ie(e,t,n){var r;for(let[o,i]of Object.entries(t)){let s=e[o];if(!s||typeof s=="string")continue;let l=i.target?Array.from(n.querySelectorAll(i.target)):[n.documentElement];for(let a of l)for(let[c,d]of Object.entries(s))(r=i.dims[c])!=null&&r.includes(d)&&a.setAttribute(`data-${c}`,d)}}function Ce(e,t,n){for(let[r,o]of Object.entries(t)){let i=e[r];if(typeof i!="string"||!o.arms||!o.arms.includes(i))continue;let s=o.target?Array.from(n.querySelectorAll(o.target)):[n.documentElement];for(let l of s)l.setAttribute("data-sentient-arm",i)}}function _e(e,t,n,r){var s;let o=(s=r==null?void 0:r.contentAndOps)!=null?s:!0,i=[];for(let[l,a]of Object.entries(t)){if(At(a.locator,n))continue;let c;if(a.locator){let p=V(a.locator,n);c=p?[p]:[]}else a.target?c=Array.from(n.querySelectorAll(a.target)):c=[n.documentElement];(a.locator||a.target)&&c.length===0&&i.push(l);let d=e[l];for(let p of c){if(d!==void 0)if(typeof d=="string")p.setAttribute("data-sentient-arm",d);else for(let[b,g]of Object.entries(d))p.setAttribute(`data-${b}`,g);o&&(typeof a.content=="string"&&(p.textContent=a.content),a.ops&&It(p,a.ops,l,n).anchorMiss&&!i.includes(l)&&i.push(l))}}return i}function Un(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 Ct(e,t,n){var b;let r=new Set,o=g=>{if(!r.has(g.goalId)){r.add(g.goalId);try{g.slotId?t.componentGoal(g.slotId,g.goalId):t.goal(g.goalId)}catch(v){}}},i=e.filter(g=>g.event==="click"),s=e.filter(g=>g.event==="form_submit"),l=e.filter(g=>g.event==="url_reached"),a=(g,v)=>{if(!g.locator)return!1;let m=V(g.locator,n);return!!m&&(m===v||m.contains(v))},c=g=>{let v=g.target;if(!(!v||typeof v.closest!="function"))for(let m of i)a(m,v)&&o(m)},d=g=>{let v=g.target;if(v)for(let m of s)a(m,v)&&o(m)},p=()=>{if(l.length===0)return;let g=Un(n);for(let v of l)v.urlPattern&&g.includes(v.urlPattern)&&o(v)};return n.addEventListener("click",c,!0),n.addEventListener("submit",d,!0),(b=n.defaultView)==null||b.addEventListener("popstate",p),p(),{checkUrl:p,teardown:()=>{var g;n.removeEventListener("click",c,!0),n.removeEventListener("submit",d,!0),(g=n.defaultView)==null||g.removeEventListener("popstate",p)}}}var _t="__snt_editor_token";function Pt(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(_t):null}catch(e){return null}}function Rt(e){try{sessionStorage.setItem(_t,e)}catch(t){}}var $t="0.10.0",Bt=5e3,Gn=50,pe=null,L=null,W={},ne=null,re=null,O=null,Lt=!1,We=null;function Kt(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function ae(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function ge(e,t){return pe?(pe.personaAttributes&&O&&Oe(O.persona,O.band,e),Ie(W,pe.slots,e),Ce(W,pe.slots,e),ne?_e(W,ne,e,t):[]):[]}function qn(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 Je(){try{ge(document)}catch(e){}}function Tt(){We===null&&(We=setTimeout(()=>{We=null,Je();try{re==null||re.checkUrl()}catch(e){}},Gn))}function Dt(){if(!(Lt||typeof window=="undefined"||typeof history=="undefined")){Lt=!0;try{let e=t=>{let n=history[t];history[t]=function(r,o,i){let s=n.call(this,r,o,i!=null?i:null);return Tt(),s}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Tt)}catch(e){}}}function ze(e){let t={};for(let[n,r]of Object.entries(e.slots))t[n]=r.target?document.querySelectorAll(r.target).length:1;return t}function Ut(e){return new URLSearchParams(e).get("sentient_editor")}function Wn(){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 zn(e,t){var n,r,o,i;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let a=document.createElement("meta");a.name="referrer",a.content="no-referrer",((r=document.head)!=null?r:document.documentElement).appendChild(a)}catch(a){}let s=(o=e.editorSrc)!=null?o:Wn();if(!s){Nt();return}let l=document.createElement("script");l.src=s,l.async=!0,l.onerror=()=>Nt(),((i=document.head)!=null?i:document.documentElement).appendChild(l)}catch(s){}}var jt="sentient-editor-load-notice";function Nt(){var e;try{if(typeof document=="undefined"||document.getElementById(jt))return;let t=document.createElement("div");t.id=jt,t.textContent="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.",Object.assign(t.style,{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",cursor:"pointer"}),t.addEventListener("click",()=>t.remove()),((e=document.body)!=null?e:document.documentElement).appendChild(t),setTimeout(()=>t.remove(),1e4)}catch(t){}}function Gt(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let r of t.split("|")){let[o,i]=r.split(":");if(!(!o||!i))if(i.includes("=")){let s={};for(let l of i.split(",")){let[a,c]=l.split("=");a&&c&&(s[a]=c)}Object.keys(s).length&&(n[o]=s)}else n[o]=i}return Object.keys(n).length?n:null}function qt(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var Mt="sentient-persona-preview-banner";function Jn(e){var t;try{if(typeof document=="undefined"||document.getElementById(Mt))return;let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),r=document.createElement("div");r.id=Mt,r.setAttribute("role","status"),Object.assign(r.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",background:"#111827",color:"#fff",font:"13px/1 system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.14)"});let o=document.createElement("span");o.textContent=`Previewing as ${n}`;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){}}),r.appendChild(o),r.appendChild(i),((t=document.body)!=null?t:document.documentElement).appendChild(r)}catch(n){}}async function Vn(e,t){var c,d,p,b,g,v,m,A,E;let n=(c=e.apiBase)!=null?c:"https://api.sentient-ui.com",o=((d=e.registry)!=null?d:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([S,T])=>({id:S,dims:T.dims}))},i=await Kt(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(o)}).then(S=>S.ok?S.json():null).catch(()=>null),Bt);if(!i){ae(e,"persona preview: explain unavailable \u2014 page left as-is");return}let s=i;W=(p=s.slots)!=null?p:{},ne=(b=s.slotConfig)!=null?b:null;let l=(m=(v=(g=s.personaAttributes)==null?void 0:g.persona)!=null?v:s.persona)!=null?m:t,a=(E=(A=s.personaAttributes)==null?void 0:A.confidence)!=null?E:"high";O={persona:l,band:a},ge(document),Wt(e),Jn(l)}function Wt(e){let t={goal(n,r){try{L==null||L.goal(n,r)}catch(o){}},componentGoal(n,r){try{L==null||L.componentGoal(n,r)}catch(o){}},grantConsent(){try{qe(e.apiKey)}catch(n){}},revokeConsent(){try{L==null||L.destroy()}catch(n){}},reapply:Je,getState(){var n,r;return{apiKey:e.apiKey,persona:(n=O==null?void 0:O.persona)!=null?n:null,band:(r=O==null?void 0:O.band)!=null?r:null,slots:W,matchCounts:ze(e),consent:e.consent!==!1}}};window.SentientSnippet=t}async function zt(){var e,t,n;try{let r=Ee(window.sentient);if(!r)return;pe=r;let o=typeof window!="undefined"?Ut(window.location.search):null;if(o){Rt(o);try{let m=new URL(window.location.href);m.searchParams.delete("sentient_editor"),window.history.replaceState(null,"",m.pathname+m.search+m.hash)}catch(m){}}let i=o!=null?o:Pt();if(i){zn(r,i),ae(r,"editor mode");return}let s=typeof window!="undefined"?Gt(window.location.search):null;if(s){W=s,O=null,ge(document),Dt(),ae(r,"preview mode",s);return}let l=typeof window!="undefined"?qt(window.location.search):null;if(l){await Vn(r,l),ae(r,"persona preview",l);return}let a=(e=r.registry)!=null?e:Object.keys(r.slots).length===0,c=ke(r.apiKey);c&&(O={persona:c.persona,band:c.band},W=c.slots,c.slotConfig&&(ne=c.slotConfig),ge(document,{contentAndOps:!1}));let d=Ae({apiKey:r.apiKey,context:r.context,consent:r.consent,preConsentBehavior:r.preConsentBehavior,debug:r.debug});L=d,Wt(r),Dt();let p=Object.entries(r.slots).map(([m,A])=>({id:m,dims:A.dims})),b=await Kt(d.decide(he({slots:p,v:$t},a?{slotsFrom:"registry"}:{})),Bt);if(!b){ae(r,"decide timeout/null \u2014 snapshot state stands",ze(r));return}let g=d.getPersona();if(g?O={persona:g.persona,band:g.band}:b.persona&&(O={persona:b.persona,band:"low"}),W=b.slots,b.slotConfig&&(ne=b.slotConfig),qn(r,ge(document)),b.goals&&b.goals.length>0&&r.consent!==!1&&L)try{re==null||re.teardown(),re=Ct(b.goals,L,document)}catch(m){}let v;try{let m=b.sectionMap;if(m&&m.length>0){let A=new Map;for(let E of m){if(E.urlMatch!==window.location.pathname)continue;let S=V(E.locator,document);S&&A.set(S,E.type)}A.size>0&&(v=E=>{var S;return(S=A.get(E))!=null?S:null})}}catch(m){}if(r.sectionCapture!==!1&&r.consent!==!1&&L&&!te())try{xt(L,he({apiKey:r.apiKey,apiBase:r.apiBase,doc:document,microSignals:!0},v?{typeOf:v}:{}))}catch(m){}ae(r,"applied",{persona:O,slots:W,matches:ze(r)}),fe(r.apiKey,he({v:1,persona:(t=O==null?void 0:O.persona)!=null?t:b.persona,band:(n=O==null?void 0:O.band)!=null?n:"low",slots:b.slots,layoutOrder:b.layoutOrder,savedAt:Date.now()},ne?{slotConfig:ne}:{}))}catch(r){}}typeof window!="undefined"&&window.sentient&&zt();return Yt(Fn);})();
|
|
1
|
+
"use strict";var SentientSnippet=(()=>{var ge=Object.defineProperty;var Wt=Object.getOwnPropertyDescriptor;var zt=Object.getOwnPropertyNames,qe=Object.getOwnPropertySymbols;var ze=Object.prototype.hasOwnProperty,Jt=Object.prototype.propertyIsEnumerable;var We=(e,t,n)=>t in e?ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,me=(e,t)=>{for(var n in t||(t={}))ze.call(t,n)&&We(e,n,t[n]);if(qe)for(var n of qe(t))Jt.call(t,n)&&We(e,n,t[n]);return e};var Je=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ve=(e,t)=>{for(var n in t)ge(e,n,{get:t[n],enumerable:!0})},Vt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of zt(t))!ze.call(e,o)&&o!==n&&ge(e,o,{get:()=>t[o],enumerable:!(r=Wt(t,o))||r.enumerable});return e};var Ft=e=>Vt(ge({},"__esModule",{value:!0}),e);var Ht,Yt,Xt,Fe,Zt,Qt,He,I,ue,he=Je(()=>{"use strict";Ht=Object.defineProperty,Yt=Object.defineProperties,Xt=Object.getOwnPropertyDescriptors,Fe=Object.getOwnPropertySymbols,Zt=Object.prototype.hasOwnProperty,Qt=Object.prototype.propertyIsEnumerable,He=(e,t,n)=>t in e?Ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,I=(e,t)=>{for(var n in t||(t={}))Zt.call(t,n)&&He(e,n,t[n]);if(Fe)for(var n of Fe(t))Qt.call(t,n)&&He(e,n,t[n]);return e},ue=(e,t)=>Yt(e,Xt(t))});var ot={};Ve(ot,{LOCAL_ENGINE_AVAILABLE:()=>nn,createLocalEngine:()=>rn});function rn(e){throw new Error("[sentient] createLocalEngine is not available in production builds. The local engine only exists under the `development` export condition.")}var nn,it=Je(()=>{"use strict";nn=!1});var Fn={};Ve(Fn,{applyPersonaAttributes:()=>Ae,applyRegistrySlots:()=>Ie,applySlotArms:()=>Oe,applySlotAttributes:()=>Ee,parseEditorToken:()=>Bt,parsePersonaPreview:()=>Ut,parsePreview:()=>Kt,parseSnippetConfig:()=>ke,reapply:()=>Ke,run:()=>qt,version:()=>Mt});he();function ye(e){return Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join("|")}function Ye(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 Ce(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 ye(e.baseline);if(typeof e.baseline=="string")return e.baseline;let o={};for(let[i,s]of Object.entries((n=e.dims)!=null?n:{}))o[i]=(r=s[0])!=null?r:"";return ye(o)}function Xe(e,t){var n,r;return e.dims!=null?(r=(n=Ye(t))!=null?n:Ye(Ce(e)))!=null?r:{}:t}function Q(e){return e>=.3?e<.7?"medium":"high":"low"}var en=["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 Ze(e){return tn(e)!==null}function tn(e){var t;if(!e)return null;let n=e.toLowerCase();return(t=en.find(r=>n.includes(r.toLowerCase())))!=null?t:null}function Qe(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function et(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(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 tt(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function nt(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function _e(e){return I(I(I({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 Pe(e){let t=_e(e);return Xe(t,Ce(t))}function rt(e){return typeof e=="string"?e:ye(e)}he();var on="_snt_uid",oe="_snt_uid";function sn(){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 an(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function ln(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(r){}}function cn(e){try{return localStorage.getItem(e)}catch(t){return null}}function un(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function dn(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function fn(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function pn(e){try{sessionStorage.removeItem(e)}catch(t){}}function gn(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 mn(e){try{localStorage.removeItem(e)}catch(t){}}function hn(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var yn={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function lt(e){var t,n,r,o,i,s;if(typeof window=="undefined")return yn;let a=(t=e==null?void 0:e.cookieName)!=null?t:on,l=((n=e==null?void 0:e.cookieTTLDays)!=null?n:365)*24*60*60,c=(s=(i=(o=(r=an(a))!=null?r:cn(oe))!=null?o:dn(oe))!=null?i:e==null?void 0:e.ssrSessionId)!=null?s:sn();ln(a,c,l);let d=un(oe,c),p=gn(a),b=d?!1:fn(oe,c),g=!d&&!p&&!b;return{getSessionId:()=>c,isEphemeral:()=>g,destroy:()=>{c=null,hn(a),mn(oe),pn(oe)}}}function ct(e){return`_snt_retry_${e.slice(0,12)}`}var bn={push:()=>{},flush:()=>{},destroy:()=>{}};function vn(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 Re(e,t,n){try{let r=[...(()=>{try{let o=localStorage.getItem(n);if(!o)return[];let i=JSON.parse(o);return Array.isArray(i)?i:[]}catch(o){return[]}})(),...e].slice(-t);localStorage.setItem(n,JSON.stringify(r))}catch(r){}}function wn(e){var t,n,r;if(typeof window=="undefined")return bn;let o=(t=e.flushIntervalMs)!=null?t:5e3,i=(n=e.maxBatchSize)!=null?n:20,s=(r=e.maxRetrySize)!=null?r:100,a=e.ingestUrl,l=e.apiKey,c=ct(l),d=[],p=new Set,b=[],g=f=>{for(let v of f)w.delete(v),!p.has(v)&&(p.add(v),b.push(v));for(;b.length>500;){let v=b.shift();v&&p.delete(v)}},w=new Set,m=f=>{p.has(f.id)||w.has(f.id)||(w.add(f.id),d.push(f))},A=vn(s,c);for(let f of A)m(f);let E=0,S=0,T=f=>{if(f.length===0)return;let v=JSON.stringify(f),k=f.map(u=>u.id),$;try{$=fetch(a,{method:"POST",keepalive:!0,body:v,headers:{"Content-Type":"application/json",Authorization:`Bearer ${l}`}})}catch(u){Re(f,s,c);for(let h of k)w.delete(h);S++,E=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6));return}let z=u=>{if(u.ok||u.status>=400&&u.status<500&&u.status!==429){g(k),S=0,E=0;return}Re(f,s,c);for(let h of k)w.delete(h);S++,E=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6))};$ instanceof Promise?$.then(z).catch(()=>{Re(f,s,c);for(let u of k)w.delete(u);S++,E=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6))}):z($)},G=typeof TextEncoder!="undefined"?new TextEncoder:null,H=f=>G?G.encode(f).length:f.length,Y=f=>{let v=[],k=2;for(let $ of f){let z=H(JSON.stringify($))+1;if(v.length>0&&k+z>57344||v.length>=i)break;v.push($),k+=z}return v},C=()=>{try{if(Date.now()<E)return;for(;d.length>0;){let f=d.filter(k=>!p.has(k.id));if(d.length=0,f.length===0)break;let v=Y(f);if(v.length===0)break;v.length<f.length&&d.push(...f.slice(v.length)),T(v)}}catch(f){}},M=!0,P=null;P=setInterval(()=>{M&&C()},o);let y=()=>{document.visibilityState==="hidden"&&C()},x=()=>{C()};return document.addEventListener("visibilitychange",y),window.addEventListener("pagehide",x),{push(f){m(f),d.length>=i&&C()},flush:C,destroy(){M=!1,P!==null&&(clearInterval(P),P=null),document.removeEventListener("visibilitychange",y),window.removeEventListener("pagehide",x),C()}}}var je="_snt_asgn_";function be(e,t){return`${e}:${t}`}function Sn(e,t){return`${je}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function st(e){let t=e.slice(je.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 Le(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(je)&&e.push(n)}return e}catch(e){return[]}}function xn(e=18e5){let t=new Map,n=r=>r.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let r of Le())try{let o=localStorage.getItem(r);if(!o)continue;let i=JSON.parse(o);if(n(i)){localStorage.removeItem(r);continue}let s=st(r);if(!s)continue;t.set(be(s.componentId,s.segment),i)}catch(o){}})(),{get(r,o){let i=t.get(be(r,o));return i?n(i)?(t.delete(be(r,o)),null):i:null},set(r,o,i){let s=be(r,o);t.set(s,i);try{localStorage.setItem(Sn(r,o),JSON.stringify(i))}catch(a){}},invalidate(r){let o=`${r}:`;for(let i of[...t.keys()])i.startsWith(o)&&t.delete(i);for(let i of Le()){let s=st(i);if((s==null?void 0:s.componentId)===r)try{localStorage.removeItem(i)}catch(a){}}},clear(){t.clear();for(let r of Le())try{localStorage.removeItem(r)}catch(o){}}}}var we="_snt_snap:",kn=["low","medium","high"];function Se(e){try{let t=localStorage.getItem(we+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"||!kn.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 de(e,t){try{localStorage.setItem(we+e,JSON.stringify(t))}catch(n){}}var De="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",ut="[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.",at=!1,ve=!1;function An(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function En(e){var t;let n=lt({ssrSessionId:e.ssrSessionId}),r=(t=n.getSessionId())!=null?t:"local",o=An(),i=Promise.resolve().then(()=>(it(),ot)).then(l=>{let c=l;return c.LOCAL_ENGINE_AVAILABLE?(at||(at=!0,console.info(ut)),c):(ve||(ve=!0,console.error(De)),null)}).catch(()=>(ve||(ve=!0,console.error(De)),null)),s=null;function a(l){let c=document.documentElement;c.dataset.sentientPersona===void 0&&(c.dataset.sentientPersona=l.persona,c.dataset.sentientConfidence=Q(l.confidence))}return{isLocal:!0,async decide(l){var c,d,p;let b=await i;if(!b)return null;let g=b.createLocalEngine({sessionId:r,forcedPersona:o}).decide(l);return s=ue(I({},g),{layoutOrder:(d=(c=g.layoutOrder)!=null?c:s==null?void 0:s.layoutOrder)!=null?d:null,slots:I(I({},(p=s==null?void 0:s.slots)!=null?p:{}),g.slots)}),de(e.apiKey||"local",{v:1,persona:s.persona,band:Q(s.confidence),slots:s.slots,layoutOrder:s.layoutOrder,savedAt:Date.now()}),a(g),g},getSlotResult(l){var c,d,p;return(p=(d=s==null?void 0:s.slots[l])!=null?d:(c=e.initialSlots)==null?void 0:c[l])!=null?p:null},getPersona(){return s?{persona:s.persona,confidence:s.confidence,band:Q(s.confidence)}:null},async assign(l,c){var d;let p=await i;return!p||!c||c.length===0?c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null:{variantId:(d=p.createLocalEngine({sessionId:r,forcedPersona:o}).decide({components:[{id:l,variantIds:c}]}).assignments[l])!=null?d:c[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}function Me(e,t,n){let r=[];{let o=!1,i=[],s=()=>{if(o)return;let a=Date.now();for(i.push(a);i.length>0&&a-i[0]>500;)i.shift();i.length>=3&&(o=!0,e("rage_click"))};t.addEventListener("click",s),r.push(()=>t.removeEventListener("click",s))}{let o=!1,i=s=>{if(o||!(s.target instanceof Node)||!t.contains(s.target)&&t!==s.target)return;o=!0;let a=typeof window!="undefined"?window.getSelection():null,l=a?a.toString().length:0;e("text_copy",{selectionLength:l})};document.addEventListener("copy",i),r.push(()=>document.removeEventListener("copy",i))}{let o=!1,i=!1,s=null,a=()=>{s!==null&&(clearTimeout(s),s=null)},l=()=>{o||!i||(a(),s=setTimeout(()=>{!o&&i&&(o=!0,e("scroll_hesitation"))},3e3))},c=()=>{a(),l()},d=b=>{for(let g of b)i=g.intersectionRatio>.3,i?l():a()},p=new IntersectionObserver(d,{threshold:[.3]});p.observe(t),window.addEventListener("scroll",c,{passive:!0}),r.push(()=>{p.disconnect(),window.removeEventListener("scroll",c),a()})}{let o=!1,i=n!=null?n:Date.now(),s=()=>{if(o||document.visibilityState!=="hidden")return;let a=Date.now()-i;a<15e3&&(o=!0,e("tab_loss",{timeOnPage:a}))};document.addEventListener("visibilitychange",s),r.push(()=>document.removeEventListener("visibilitychange",s))}return()=>{for(let o of r)o()}}var dt="https://api.sentient-ui.com/v1/events",ee=new Map,ft=null;function Te(){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 ie={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}};function On(){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 pt(e){return e.replace(/\/events\/?$/,"")}function te(){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 Ne(e){if(typeof window=="undefined")return;let t=e!=null?e:ft;if(!t){console.warn("[sentient] grantConsent() called before init()");return}let n=ee.get(t);if(!n){console.warn("[sentient] grantConsent() called before init()");return}let{config:r,upgrade:o}=n;if(!o||r.respectDoNotTrack!==!1&&te())return;let i=xe(ue(I({},r),{consent:!0}));o(i),ee.set(t,{config:ue(I({},r),{consent:!0}),upgrade:null})}function In(e){var t;let n=pt((t=e.ingestUrl)!=null?t:dt),r={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(a,l,c){try{let d=new URLSearchParams({componentId:a});for(let b of l!=null?l:[])d.append("variantIds[]",b);let p=await fetch(`${n}/winner?${d.toString()}`,{headers:r});return p.ok?{variantId:(await p.json()).variantId,assignmentTtlMs:0}:l!=null&&l[0]?{variantId:l[0],assignmentTtlMs:0}:null}catch(d){return l!=null&&l[0]?{variantId:l[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},i={track:a=>o.track(a),goal:(a,l,c,d)=>o.goal(a,l,c,d),componentGoal:(a,l,c)=>o.componentGoal(a,l,c),identify:a=>o.identify(a),getAssignment:(a,l)=>o.getAssignment(a,l),assign:(a,l,c,d)=>o.assign(a,l,c,d),decide:a=>o.decide(a),getSlotResult:a=>o.getSlotResult(a),getPersona:()=>o.getPersona(),fetchWeights:()=>o.fetchWeights(),getGraph:()=>o.getGraph(),dispose:()=>o.dispose(),destroy:()=>o.destroy()};function s(a){o=a}return{proxy:i,setInner:s}}function xe(e){var t,n,r,o,i,s,a,l,c;if(typeof window=="undefined")return ie;ft=e.apiKey;let d=e.respectDoNotTrack!==!1&&te(),p=e.consent===!1||d,b=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!b&&e.localMode!==!1)return p?(ee.set(e.apiKey||"local",{config:e,upgrade:null}),ie):(ee.set(e.apiKey||"local",{config:e,upgrade:null}),En(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."),ie;let{proxy:u,setInner:h}=In(e);return ee.set(e.apiKey,{config:e,upgrade:d?null:h}),u}return ee.set(e.apiKey,{config:e,upgrade:null}),ie}if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),ie;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),ie;let g=(t=e.ingestUrl)!=null?t:dt,w=Date.now(),m=lt({ssrSessionId:e.ssrSessionId}),A=xn(),E=wn({ingestUrl:g,apiKey:e.apiKey}),S=pt(g),T={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},G=Qe((n=navigator.userAgent)!=null?n:""),H=typeof window!="undefined"?window.location.origin:void 0,Y=et((r=document.referrer)!=null?r:"",H),C=(o=e.sessionSegment)!=null?o:`${G}:${Y}`,M=new Map,P=new Map,y=null,x=u=>{for(let h of u)P.has(h.id)||P.set(h.id,Pe(h))};if(e.initialSlots)for(let[u,h]of Object.entries(e.initialSlots))P.set(u,h);let f=Se(e.apiKey);if(f)for(let[u,h]of Object.entries(f.slots))P.has(u)||P.set(u,h);let v={low:.15,medium:.5,high:.85};if(e.initialPersona)y=I({},e.initialPersona);else{let u=document.documentElement.dataset;u.sentientPersona?y={persona:u.sentientPersona,confidence:(s=v[(i=u.sentientConfidence)!=null?i:"low"])!=null?s:.15}:f&&(y={persona:f.persona,confidence:(a=v[f.band])!=null?a:.15})}if(e.initialAssignments)for(let[u,h]of Object.entries(e.initialAssignments))A.set(u,C,{variantId:h,assignedAt:Date.now(),segment:C,confidence:1});let k=Promise.resolve(),$=m.getSessionId();if($){let u=tt((l=document.referrer)!=null?l:""),h=I(I({sessionId:$,deviceClass:G,trafficSource:Y,referrerDomain:u,utmParams:On(),timeOfDay:nt(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:m.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||Ze((c=navigator.userAgent)!=null?c:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{k=fetch(`${S}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(h),headers:T}).then(_=>{_.status===402&&console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing")}).catch(()=>{})}catch(_){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:E});let z={goal(u,h={},_=1,B=0){let N=m.getSessionId();if(!N)return;let D=Te();k.then(()=>{fetch(`${S}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:N,name:u,metadata:h,weight:_,stepIndex:B,goalId:D}),headers:T}).catch(()=>{})})},componentGoal(u,h,_){var B,N,D;let J=m.getSessionId();if(!J)return;let K=A.get(u,C),U=K?null:(B=P.get(u))!=null?B:null;if(!K&&U===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 X=K?K.variantId:rt(U),q={id:Te(),sessionId:J,projectId:e.apiKey,componentId:u,variantId:X,eventType:"goal_achieved",goalType:h,payload:I({reward:(N=_==null?void 0:_.reward)!=null?N:1},(D=_==null?void 0:_.metadata)!=null?D:{}),timestamp:Date.now(),timeInSession:Date.now()-w};e.debug&&console.log("[sentient] componentGoal",q),k.then(()=>E.push(q))},identify(u){let h=m.getSessionId();h&&k.then(()=>{fetch(`${S}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:h,userId:u,ephemeral:m.isEphemeral()}),headers:T}).catch(()=>{})})},track(u){let h=m.getSessionId();if(!h)return;let _=ue(I({},u),{id:Te(),sessionId:h,timestamp:Date.now(),timeInSession:Date.now()-w});e.debug&&console.log("[sentient] track",_),k.then(()=>E.push(_))},getAssignment(u,h){return A.get(u,h)},async assign(u,h,_,B){let N=m.getSessionId();if(!N)return null;let D=A.get(u,C);if(D&&(h!=null&&h.length||D.content!==void 0))return{variantId:D.variantId,assignmentTtlMs:0,content:D.content};let J=M.get(u);if(J)return J;let K=(async()=>{await k;try{let U={sessionId:N,componentId:u,variantIds:h};B!==void 0?U.agentDataByVariant=B:_!==void 0&&(U.agentData=_);let X=await fetch(`${S}/assign`,{method:"POST",body:JSON.stringify(U),headers:T});if(!X.ok)return null;let q=await X.json();return A.set(u,C,{variantId:q.variantId,assignedAt:Date.now(),segment:C,confidence:1,content:q.content}),q}catch(U){return null}finally{M.delete(u)}})();return M.set(u,K),K},async decide(u){var h,_,B,N,D,J,K,U,X,q;let Ue=m.getSessionId();if(!Ue)return null;let ae=(h=u.slots)!=null?h:[];await k;try{let Z={sessionId:Ue};u.sections&&u.sections.length>0&&(Z.sections=u.sections.map(j=>({id:j}))),Z.components=(_=u.components)!=null?_:[],ae.length>0&&(Z.slots=ae.map(_e)),u.slotsFrom==="registry"&&(Z.slotsFrom="registry"),u.v&&(Z.v=u.v);let Ge=await fetch(`${S}/decide`,{method:"POST",body:JSON.stringify(Z),headers:T});if(!Ge.ok)return x(ae),null;let R=await Ge.json(),le={};for(let j of ae)le[j.id]=(N=(B=R.slots)==null?void 0:B[j.id])!=null?N:Pe(j);if(R.slots)for(let[j,ce]of Object.entries(R.slots))j in le||(le[j]=ce);for(let[j,ce]of Object.entries(le))P.set(j,ce);y={persona:(D=R.persona)!=null?D:"unknown",confidence:(J=R.confidence)!=null?J:0};for(let[j,ce]of Object.entries((K=R.assignments)!=null?K:{}))A.set(j,C,{variantId:ce,assignedAt:Date.now(),segment:C,confidence:1});return de(e.apiKey,I({v:1,persona:y.persona,band:Q(y.confidence),slots:Object.fromEntries(P),layoutOrder:(U=R.layoutOrder)!=null?U:null,savedAt:Date.now()},R.slotConfig?{slotConfig:R.slotConfig}:{})),I(I({layoutOrder:(X=R.layoutOrder)!=null?X:null,assignments:(q=R.assignments)!=null?q:{},slots:le,persona:y.persona,confidence:y.confidence},R.slotConfig?{slotConfig:R.slotConfig}:{}),R.goals?{goals:R.goals}:{})}catch(Z){return x(ae),null}},getSlotResult(u){var h;return(h=P.get(u))!=null?h:null},getPersona(){return y?{persona:y.persona,confidence:y.confidence,band:Q(y.confidence)}:null},async fetchWeights(){var u;try{let h=await fetch(`${S}/weights`,{headers:T});return h.ok?(u=(await h.json()).components)!=null?u:[]:[]}catch(h){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){E.destroy(),e.debug&&console.log("[sentient] disposed")},destroy(){E.destroy(),m.destroy();try{localStorage.removeItem(we+e.apiKey),localStorage.removeItem(ct(e.apiKey))}catch(u){}e.debug&&console.log("[sentient] destroyed")}};if(ee.set(e.apiKey,{config:e,upgrade:null}),e.debug){let u=window;u.__sentient&&(u.__sentient.client=z)}return z}var gt=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Cn=[["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]],_n=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function Pn(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function mt(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,r]of Cn)if(r.test(t))return{type:n,strength:"strong"};for(let[n,r]of _n)if(r.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function ht(e){var t,n;let r=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:Pn(e),bodyText:r.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:r.length}}function yt(e){return mt(ht(e)).type}he();var vt="section, header, footer, nav, main > div, [data-sentient-section]";function Rn(e){var t;return((t=e.parentElement)==null?void 0:t.closest(vt))!=null}function Ln(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 bt=()=>{};function wt(e,t){var n,r,o,i,s,a,l,c,d;let p=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!p||typeof IntersectionObserver=="undefined"||te()||!t.apiKey)return bt;let b=(r=t.apiBase)!=null?r:"https://api.sentient-ui.com",g=Array.from(p.querySelectorAll(vt)).filter(y=>!Rn(y));if(g.length===0)return bt;let w=new Map,m=new Map,A=new Map;for(let y of g){let x=y.getAttribute("data-sentient-type"),f=x&>.includes(x)?x:null,v=(i=f!=null?f:(o=t.typeOf)==null?void 0:o.call(t,y))!=null?i:yt(y),k=`nc-${v}`;w.set(y,k),m.set(k,v),f?A.set(k,"markup"):A.has(k)||A.set(k,"auto")}let E=(c=(l=(a=(s=p.defaultView)!=null?s:typeof window!="undefined"?window:void 0)==null?void 0:a.location)==null?void 0:l.pathname)!=null?c:"/";Ln(t.apiKey,b,E,[...m.entries()].map(([y,x])=>{var f;return{componentId:y,semanticType:x,source:(f=A.get(y))!=null?f:"auto"}}));let S=new Map,T=y=>{let x=S.get(y);return x||(x={ms:0,scroll:0,enterAt:null,intersecting:!1},S.set(y,x)),x},G=new IntersectionObserver(y=>{for(let x of y){let f=w.get(x.target);if(!f)continue;let v=T(f);x.isIntersecting?(v.intersecting=!0,v.enterAt=Date.now(),x.intersectionRatio>v.scroll&&(v.scroll=x.intersectionRatio)):(v.intersecting=!1,v.enterAt!=null&&(v.ms+=Date.now()-v.enterAt,v.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let y of w.keys())G.observe(y);let H=()=>{let y=Date.now();for(let[x,f]of S)if(f.enterAt!=null&&(f.ms+=y-f.enterAt,f.enterAt=null),!(f.ms<=0)){try{e.track({projectId:t.apiKey,componentId:x,eventType:"dwell",payload:{dwell_time:Math.round(f.ms),scroll_depth:Number(f.scroll.toFixed(2))}})}catch(v){}f.ms=0}},Y=()=>{if(p.hidden)H();else{let y=Date.now();for(let x of S.values())x.intersecting&&(x.enterAt=y)}},C=()=>{H();try{G.disconnect()}catch(y){}};p.addEventListener("visibilitychange",Y);let M=(d=p.defaultView)!=null?d:typeof window!="undefined"?window:void 0;M==null||M.addEventListener("pagehide",C);let P=[];if(t.microSignals)for(let[y,x]of w)P.push(Me((f,v={})=>{try{e.track({projectId:t.apiKey,componentId:x,eventType:"micro_signal",payload:I({signalType:f},v)})}catch(k){}},y));return()=>{H(),p.removeEventListener("visibilitychange",Y),M==null||M.removeEventListener("pagehide",C);for(let y of P)y();try{G.disconnect()}catch(y){}}}var Tn=["landing","ecommerce","saas","marketplace"];function Dn(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(i=>typeof i=="string"))return null;n[r]=o}return n}function jn(e){return!Array.isArray(e)||e.length<2||e.length>12||!e.every(t=>typeof t=="string")?null:e}function ke(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=Tn.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 a=s,l=Dn(a.dims);if(!l||a.target!==void 0&&typeof a.target!="string")continue;let c=a.arms!==void 0?jn(a.arms):null,d={dims:l};typeof a.target=="string"&&(d.target=a.target),c&&(d.arms=c),r[i]=d}let o={apiKey:t.apiKey,context:n,personaAttributes:t.personaAttributes===!0,slots:r};return 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),o}function St(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 Mn(e,t){var n;if(t.tag&&e.tagName.toLowerCase()!==t.tag.toLowerCase())return!1;if(t.text){let r=((n=e.textContent)!=null?n:"").trim().toLowerCase(),o=t.text.trim().toLowerCase();if(!(r===o||r.startsWith(o)||o.startsWith(r)))return!1}return!0}function xt(e,t){return!!(e!=null&&e.urlMatch)&&!St(t).includes(e.urlMatch)}function V(e,t){var o;if(e.urlMatch&&!St(t).includes(e.urlMatch))return null;let n=[];if(e.id){let i=t.getElementById(e.id);n=i?[i]:[]}if(n.length===0&&((o=e.dataAttr)!=null&&o.name))try{let i=e.dataAttr.value.replace(/["\\]/g,"\\$&");n=Array.from(t.querySelectorAll(`[${e.dataAttr.name}="${i}"]`))}catch(i){n=[]}if(n.length===0&&e.selector)try{n=Array.from(t.querySelectorAll(e.selector))}catch(i){n=[]}if(n.length!==1)return null;let r=n[0];return e.fingerprint&&!Mn(r,e.fingerprint)?null:r}var kt=/^https:\/\//i,Nn={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 $n(e){return!/[;{}<>]/.test(e)}var At=new Map,F=null;function Bn(e){return e.replace(/["\\]/g,"\\$&")}function Kn(e){var t;(!F||!F.isConnected)&&(F=e.querySelector("style[data-sentient-ops]"),F||(F=e.createElement("style"),F.setAttribute("data-sentient-ops",""),((t=e.head)!=null?t:e.documentElement).appendChild(F))),F.textContent=[...At.entries()].map(([n,r])=>`[data-snt-e="${Bn(n)}"]{${r}}`).join(`
|
|
2
|
+
`)}function Et(e,t,n,r){var a;let o=!1,i=(a=t.moveBefore)!=null?a:t.moveAfter;if(i){let l=V(i,r);!l||l===e||l.parentElement!==e.parentElement||!e.parentElement?o=!0:t.moveBefore?e.parentElement.insertBefore(e,l):e.parentElement.insertBefore(e,l.nextSibling)}typeof t.text=="string"&&(e.textContent=t.text),typeof t.href=="string"&&kt.test(t.href)&&e.setAttribute("href",t.href),typeof t.imageSrc=="string"&&kt.test(t.imageSrc)&&e.setAttribute("src",t.imageSrc),typeof t.imageAlt=="string"&&e.setAttribute("alt",t.imageAlt);let s=[];if(t.hidden&&s.push("display:none !important"),t.style)for(let[l,c]of Object.entries(t.style)){let d=Nn[l];d&&typeof c=="string"&&$n(c)&&s.push(`${d}:${c.trim()} !important`)}return s.length>0&&(e.setAttribute("data-snt-e",n),At.set(n,s.join(";")),Kn(r)),{anchorMiss:o}}function Ae(e,t,n){n.documentElement.setAttribute("data-sentient-persona",e),n.documentElement.setAttribute("data-sentient-confidence",t)}function Ee(e,t,n){var r;for(let[o,i]of Object.entries(t)){let s=e[o];if(!s||typeof s=="string")continue;let a=i.target?Array.from(n.querySelectorAll(i.target)):[n.documentElement];for(let l of a)for(let[c,d]of Object.entries(s))(r=i.dims[c])!=null&&r.includes(d)&&l.setAttribute(`data-${c}`,d)}}function Oe(e,t,n){for(let[r,o]of Object.entries(t)){let i=e[r];if(typeof i!="string"||!o.arms||!o.arms.includes(i))continue;let s=o.target?Array.from(n.querySelectorAll(o.target)):[n.documentElement];for(let a of s)a.setAttribute("data-sentient-arm",i)}}function Ie(e,t,n,r){var s;let o=(s=r==null?void 0:r.contentAndOps)!=null?s:!0,i=[];for(let[a,l]of Object.entries(t)){if(xt(l.locator,n))continue;let c;if(l.locator){let p=V(l.locator,n);c=p?[p]:[]}else l.target?c=Array.from(n.querySelectorAll(l.target)):c=[n.documentElement];(l.locator||l.target)&&c.length===0&&i.push(a);let d=e[a];for(let p of c){if(d!==void 0)if(typeof d=="string")p.setAttribute("data-sentient-arm",d);else for(let[b,g]of Object.entries(d))p.setAttribute(`data-${b}`,g);o&&(typeof l.content=="string"&&(p.textContent=l.content),l.ops&&Et(p,l.ops,a,n).anchorMiss&&!i.includes(a)&&i.push(a))}}return i}function Un(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 Ot(e,t,n){var b;let r=new Set,o=g=>{if(!r.has(g.goalId)){r.add(g.goalId);try{g.slotId?t.componentGoal(g.slotId,g.goalId):t.goal(g.goalId)}catch(w){}}},i=e.filter(g=>g.event==="click"),s=e.filter(g=>g.event==="form_submit"),a=e.filter(g=>g.event==="url_reached"),l=(g,w)=>{if(!g.locator)return!1;let m=V(g.locator,n);return!!m&&(m===w||m.contains(w))},c=g=>{let w=g.target;if(!(!w||typeof w.closest!="function"))for(let m of i)l(m,w)&&o(m)},d=g=>{let w=g.target;if(w)for(let m of s)l(m,w)&&o(m)},p=()=>{if(a.length===0)return;let g=Un(n);for(let w of a)w.urlPattern&&g.includes(w.urlPattern)&&o(w)};return n.addEventListener("click",c,!0),n.addEventListener("submit",d,!0),(b=n.defaultView)==null||b.addEventListener("popstate",p),p(),{checkUrl:p,teardown:()=>{var g;n.removeEventListener("click",c,!0),n.removeEventListener("submit",d,!0),(g=n.defaultView)==null||g.removeEventListener("popstate",p)}}}var It="__snt_editor_token";function Ct(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(It):null}catch(e){return null}}function _t(e){try{sessionStorage.setItem(It,e)}catch(t){}}var Mt="0.10.1",Nt=5e3,Gn=50,fe=null,L=null,W={},ne=null,re=null,O=null,Pt=!1,$e=null;function $t(e,t){return Promise.race([e,new Promise(n=>setTimeout(()=>n(null),t))])}function se(e,...t){e!=null&&e.debug&&console.log("[sentient-snippet]",...t)}function pe(e,t){return fe?(fe.personaAttributes&&O&&Ae(O.persona,O.band,e),Ee(W,fe.slots,e),Oe(W,fe.slots,e),ne?Ie(W,ne,e,t):[]):[]}function qn(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 Ke(){try{pe(document)}catch(e){}}function Rt(){$e===null&&($e=setTimeout(()=>{$e=null,Ke();try{re==null||re.checkUrl()}catch(e){}},Gn))}function Lt(){if(!(Pt||typeof window=="undefined"||typeof history=="undefined")){Pt=!0;try{let e=t=>{let n=history[t];history[t]=function(r,o,i){let s=n.call(this,r,o,i!=null?i:null);return Rt(),s}};e("pushState"),e("replaceState"),window.addEventListener("popstate",Rt)}catch(e){}}}function Be(e){let t={};for(let[n,r]of Object.entries(e.slots))t[n]=r.target?document.querySelectorAll(r.target).length:1;return t}function Bt(e){return new URLSearchParams(e).get("sentient_editor")}function Wn(){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 zn(e,t){var n,r,o,i;try{window.__sentientEditor={token:t,apiBase:(n=e.apiBase)!=null?n:"https://api.sentient-ui.com"};try{let l=document.createElement("meta");l.name="referrer",l.content="no-referrer",((r=document.head)!=null?r:document.documentElement).appendChild(l)}catch(l){}let s=(o=e.editorSrc)!=null?o:Wn();if(!s){Dt();return}let a=document.createElement("script");a.src=s,a.async=!0,a.onerror=()=>Dt(),((i=document.head)!=null?i:document.documentElement).appendChild(a)}catch(s){}}var Tt="sentient-editor-load-notice";function Dt(){var e;try{if(typeof document=="undefined"||document.getElementById(Tt))return;let t=document.createElement("div");t.id=Tt,t.textContent="Couldn\u2019t load the editor \u2014 check your connection and reopen it from your dashboard.",Object.assign(t.style,{position:"fixed",bottom:"16px",right:"16px",zIndex:"2147483647",maxWidth:"320px",padding:"14px 16px",borderRadius:"14px",background:"#111827",color:"#fff",font:"13px/1.45 system-ui, sans-serif",border:"1px solid rgba(245,158,11,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",cursor:"pointer"}),t.addEventListener("click",()=>t.remove()),((e=document.body)!=null?e:document.documentElement).appendChild(t),setTimeout(()=>t.remove(),1e4)}catch(t){}}function Kt(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(":"),i=o===-1?"":r.slice(0,o),s=o===-1?"":r.slice(o+1);if(!(!i||!s))if(s.includes("=")){let a={};for(let l of s.split(",")){let[c,d]=l.split("=");c&&d&&(a[c]=d)}Object.keys(a).length&&(n[i]=a)}else n[i]=s}return Object.keys(n).length?n:null}function Ut(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var jt="sentient-persona-preview-banner";function Jn(e){var t;try{if(typeof document=="undefined"||document.getElementById(jt))return;let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),r=document.createElement("div");r.id=jt,r.setAttribute("role","status"),Object.assign(r.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",background:"#111827",color:"#fff",font:"13px/1 system-ui, sans-serif",boxShadow:"0 10px 34px rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.14)"});let o=document.createElement("span");o.textContent=`Previewing as ${n}`;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){}}),r.appendChild(o),r.appendChild(i),((t=document.body)!=null?t:document.documentElement).appendChild(r)}catch(n){}}async function Vn(e,t){var c,d,p,b,g,w,m,A,E;let n=(c=e.apiBase)!=null?c:"https://api.sentient-ui.com",o=((d=e.registry)!=null?d:Object.keys(e.slots).length===0)?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(e.slots).map(([S,T])=>({id:S,dims:T.dims}))},i=await $t(fetch(`${n}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.apiKey}`},body:JSON.stringify(o)}).then(S=>S.ok?S.json():null).catch(()=>null),Nt);if(!i){se(e,"persona preview: explain unavailable \u2014 page left as-is");return}let s=i;W=(p=s.slots)!=null?p:{},ne=(b=s.slotConfig)!=null?b:null;let a=(m=(w=(g=s.personaAttributes)==null?void 0:g.persona)!=null?w:s.persona)!=null?m:t,l=(E=(A=s.personaAttributes)==null?void 0:A.confidence)!=null?E:"high";O={persona:a,band:l},pe(document),Gt(e),Jn(a)}function Gt(e){let t={goal(n,r){try{L==null||L.goal(n,r)}catch(o){}},componentGoal(n,r){try{L==null||L.componentGoal(n,r)}catch(o){}},grantConsent(){try{Ne(e.apiKey)}catch(n){}},revokeConsent(){try{L==null||L.destroy()}catch(n){}},reapply:Ke,getState(){var n,r;return{apiKey:e.apiKey,persona:(n=O==null?void 0:O.persona)!=null?n:null,band:(r=O==null?void 0:O.band)!=null?r:null,slots:W,matchCounts:Be(e),consent:e.consent!==!1}}};window.SentientSnippet=t}async function qt(){var e,t,n;try{let r=ke(window.sentient);if(!r)return;fe=r;let o=typeof window!="undefined"?Bt(window.location.search):null;if(o){_t(o);try{let m=new URL(window.location.href);m.searchParams.delete("sentient_editor"),window.history.replaceState(null,"",m.pathname+m.search+m.hash)}catch(m){}}let i=o!=null?o:Ct();if(i){zn(r,i),se(r,"editor mode");return}let s=typeof window!="undefined"?Kt(window.location.search):null;if(s){W=s,O=null,pe(document),Lt(),se(r,"preview mode",s);return}let a=typeof window!="undefined"?Ut(window.location.search):null;if(a){await Vn(r,a),se(r,"persona preview",a);return}let l=(e=r.registry)!=null?e:Object.keys(r.slots).length===0,c=Se(r.apiKey);c&&(O={persona:c.persona,band:c.band},W=c.slots,c.slotConfig&&(ne=c.slotConfig),pe(document,{contentAndOps:!1}));let d=xe({apiKey:r.apiKey,context:r.context,consent:r.consent,preConsentBehavior:r.preConsentBehavior,debug:r.debug});L=d,Gt(r),Lt();let p=Object.entries(r.slots).map(([m,A])=>({id:m,dims:A.dims})),b=await $t(d.decide(me({slots:p,v:Mt},l?{slotsFrom:"registry"}:{})),Nt);if(!b){se(r,"decide timeout/null \u2014 snapshot state stands",Be(r));return}let g=d.getPersona();if(g?O={persona:g.persona,band:g.band}:b.persona&&(O={persona:b.persona,band:"low"}),W=b.slots,b.slotConfig&&(ne=b.slotConfig),qn(r,pe(document)),b.goals&&b.goals.length>0&&r.consent!==!1&&L)try{re==null||re.teardown(),re=Ot(b.goals,L,document)}catch(m){}let w;try{let m=b.sectionMap;if(m&&m.length>0){let A=new Map;for(let E of m){if(E.urlMatch!==window.location.pathname)continue;let S=V(E.locator,document);S&&A.set(S,E.type)}A.size>0&&(w=E=>{var S;return(S=A.get(E))!=null?S:null})}}catch(m){}if(r.sectionCapture!==!1&&r.consent!==!1&&L&&!te())try{wt(L,me({apiKey:r.apiKey,apiBase:r.apiBase,doc:document,microSignals:!0},w?{typeOf:w}:{}))}catch(m){}se(r,"applied",{persona:O,slots:W,matches:Be(r)}),de(r.apiKey,me({v:1,persona:(t=O==null?void 0:O.persona)!=null?t:b.persona,band:(n=O==null?void 0:O.band)!=null?n:"low",slots:b.slots,layoutOrder:b.layoutOrder,savedAt:Date.now()},ne?{slotConfig:ne}:{}))}catch(r){}}typeof window!="undefined"&&window.sentient&&qt();return Ft(Fn);})();
|
package/package.json
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentientui/snippet",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "SentientUI Style-rung snippet for non-React sites — persona attributes and adaptive style tokens from one script tag",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/casancam/SentientUI.git",
|
|
10
|
+
"directory": "packages/snippet"
|
|
11
|
+
},
|
|
6
12
|
"type": "module",
|
|
7
13
|
"main": "./dist/snippet.global.js",
|
|
8
14
|
"files": [
|
|
@@ -16,7 +22,7 @@
|
|
|
16
22
|
"tsx": "^4.19.2",
|
|
17
23
|
"typescript": "^5.7.2",
|
|
18
24
|
"vitest": "^2.1.8",
|
|
19
|
-
"@sentientui/core": "0.16.
|
|
25
|
+
"@sentientui/core": "0.16.2"
|
|
20
26
|
},
|
|
21
27
|
"scripts": {
|
|
22
28
|
"build": "tsup",
|