@sentientui/core 0.28.0 → 0.29.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.
@@ -142,6 +142,59 @@ declare const LEGACY_SESSION_COOKIE_NAME = "_snt_uid";
142
142
  */
143
143
  declare function sessionCookieName(apiKey?: string): string;
144
144
 
145
+ /**
146
+ * The adaptation reveal — the 0.X-second moment a visitor notices the page is
147
+ * for them (`what-sentient-is-becoming.md` §"Fast generation and the wow",
148
+ * where it is listed as the pending adaptation-visibility layer).
149
+ *
150
+ * THREE RULES, and the first two are the ones that make this shippable at all.
151
+ *
152
+ * 1. NEVER A CLOAK. The 2026-09-07 decision was explicit: nothing is hidden and
153
+ * then revealed. This animates from 55% opacity to full — the element is
154
+ * legible at every frame, so a visitor who arrives mid-animation reads real
155
+ * content rather than a blank space, and a failed script leaves a page that
156
+ * was never hidden in the first place. That rules out a true crossfade
157
+ * (which needs the old content held somewhere invisible) and it is the right
158
+ * trade: the point is to draw the eye to a change, not to conceal one.
159
+ *
160
+ * 2. ONLY ON A REAL, POST-PAINT CHANGE. A return visitor's arm is applied by
161
+ * the inline pre-paint tag, so the page was ALWAYS that way and there is
162
+ * nothing to reveal — animating it would be theatre, and worse, it would
163
+ * animate on every page load. The caller passes the text it is replacing;
164
+ * identical content animates nothing.
165
+ *
166
+ * 3. REDUCED MOTION WINS, unconditionally. Not a config option, not
167
+ * overridable: a vestibular trigger is not a growth experiment. Under
168
+ * `prefers-reduced-motion: reduce` the change still happens, instantly.
169
+ *
170
+ * The visitor-facing "shown because X" caption from the original sketch is
171
+ * deliberately NOT here. Telling a customer's visitors that they are being
172
+ * personalized is the customer's decision to make about their own site, not a
173
+ * default we ship; the provenance is exposed as data attributes for devtools
174
+ * and the editor instead.
175
+ */
176
+ /** Total motion. 240ms sits inside the 200–400ms the spec asks for: long enough
177
+ * to be seen, short enough that a visitor reading the line is not waiting. */
178
+ declare const REVEAL_MS = 240;
179
+ /** For tests and for `destroy()` — a second init must not stack sheets. */
180
+ declare function resetRevealStyles(): void;
181
+ type RevealOptions = {
182
+ /** Text the element showed BEFORE the change. Identical text reveals nothing. */
183
+ previous?: string | null;
184
+ /** The arm now serving, exposed for devtools/editor — never rendered. */
185
+ arm?: string;
186
+ /** Why it was chosen. Same: data, not visible copy. */
187
+ persona?: string;
188
+ doc?: Document;
189
+ };
190
+ /**
191
+ * Animate `el` as having just changed, and record what it changed to.
192
+ *
193
+ * Returns true when motion was applied — false when there was nothing to
194
+ * reveal, which callers can treat as "the page already looked like this".
195
+ */
196
+ declare function reveal(el: Element, opts?: RevealOptions): boolean;
197
+
145
198
  type MicroSignalEmitter = (signalType: 'rage_click' | 'text_copy' | 'scroll_hesitation' | 'tab_loss', extra?: Record<string, unknown>) => void;
146
199
  type MicroSignalType = Parameters<MicroSignalEmitter>[0];
147
200
  /**
@@ -450,4 +503,4 @@ declare function grantConsent(apiKey?: string): void;
450
503
  */
451
504
  declare function init(config: SentientConfig): SentientClient;
452
505
 
453
- export { type AssignResult as A, type ComponentGoalOptions as C, type DecideInput as D, type EventQueue as E, type GoalDefinition as G, LEGACY_SESSION_COOKIE_NAME as L, type MicroSignalEmitter as M, PROD_KEYLESS_ERROR as P, type QueueConfig as Q, type SectionMapEntry as S, type WeightEntry as W, _registerConsentUpgradeInit as _, type Assignment as a, type AssignmentCache as b, type ComponentWeightEntry as c, type DecideOutcome as d, type EventType as e, type GoalOptions as f, type GraphClient as g, type GraphConfig as h, type GraphSnapshot as i, LOCAL_MODE_BANNER as j, type MicroSignalType as k, type PageNode as l, type SentientClient as m, type SentientConfig as n, type SentientEvent as o, type SessionConfig as p, type SessionManager as q, attachMicroSignalDetectors as r, grantConsent as s, init as t, isDoNotTrackEnabled as u, sanitizePageUrl as v, sessionCookieName as w };
506
+ export { type AssignResult as A, type ComponentGoalOptions as C, type DecideInput as D, type EventQueue as E, type GoalDefinition as G, LEGACY_SESSION_COOKIE_NAME as L, type MicroSignalEmitter as M, PROD_KEYLESS_ERROR as P, type QueueConfig as Q, REVEAL_MS as R, type SectionMapEntry as S, type WeightEntry as W, _registerConsentUpgradeInit as _, type Assignment as a, type AssignmentCache as b, type ComponentWeightEntry as c, type DecideOutcome as d, type EventType as e, type GoalOptions as f, type GraphClient as g, type GraphConfig as h, type GraphSnapshot as i, LOCAL_MODE_BANNER as j, type MicroSignalType as k, type PageNode as l, type RevealOptions as m, type SentientClient as n, type SentientConfig as o, type SentientEvent as p, type SessionConfig as q, type SessionManager as r, attachMicroSignalDetectors as s, grantConsent as t, init as u, isDoNotTrackEnabled as v, resetRevealStyles as w, reveal as x, sanitizePageUrl as y, sessionCookieName as z };
@@ -142,6 +142,59 @@ declare const LEGACY_SESSION_COOKIE_NAME = "_snt_uid";
142
142
  */
143
143
  declare function sessionCookieName(apiKey?: string): string;
144
144
 
145
+ /**
146
+ * The adaptation reveal — the 0.X-second moment a visitor notices the page is
147
+ * for them (`what-sentient-is-becoming.md` §"Fast generation and the wow",
148
+ * where it is listed as the pending adaptation-visibility layer).
149
+ *
150
+ * THREE RULES, and the first two are the ones that make this shippable at all.
151
+ *
152
+ * 1. NEVER A CLOAK. The 2026-09-07 decision was explicit: nothing is hidden and
153
+ * then revealed. This animates from 55% opacity to full — the element is
154
+ * legible at every frame, so a visitor who arrives mid-animation reads real
155
+ * content rather than a blank space, and a failed script leaves a page that
156
+ * was never hidden in the first place. That rules out a true crossfade
157
+ * (which needs the old content held somewhere invisible) and it is the right
158
+ * trade: the point is to draw the eye to a change, not to conceal one.
159
+ *
160
+ * 2. ONLY ON A REAL, POST-PAINT CHANGE. A return visitor's arm is applied by
161
+ * the inline pre-paint tag, so the page was ALWAYS that way and there is
162
+ * nothing to reveal — animating it would be theatre, and worse, it would
163
+ * animate on every page load. The caller passes the text it is replacing;
164
+ * identical content animates nothing.
165
+ *
166
+ * 3. REDUCED MOTION WINS, unconditionally. Not a config option, not
167
+ * overridable: a vestibular trigger is not a growth experiment. Under
168
+ * `prefers-reduced-motion: reduce` the change still happens, instantly.
169
+ *
170
+ * The visitor-facing "shown because X" caption from the original sketch is
171
+ * deliberately NOT here. Telling a customer's visitors that they are being
172
+ * personalized is the customer's decision to make about their own site, not a
173
+ * default we ship; the provenance is exposed as data attributes for devtools
174
+ * and the editor instead.
175
+ */
176
+ /** Total motion. 240ms sits inside the 200–400ms the spec asks for: long enough
177
+ * to be seen, short enough that a visitor reading the line is not waiting. */
178
+ declare const REVEAL_MS = 240;
179
+ /** For tests and for `destroy()` — a second init must not stack sheets. */
180
+ declare function resetRevealStyles(): void;
181
+ type RevealOptions = {
182
+ /** Text the element showed BEFORE the change. Identical text reveals nothing. */
183
+ previous?: string | null;
184
+ /** The arm now serving, exposed for devtools/editor — never rendered. */
185
+ arm?: string;
186
+ /** Why it was chosen. Same: data, not visible copy. */
187
+ persona?: string;
188
+ doc?: Document;
189
+ };
190
+ /**
191
+ * Animate `el` as having just changed, and record what it changed to.
192
+ *
193
+ * Returns true when motion was applied — false when there was nothing to
194
+ * reveal, which callers can treat as "the page already looked like this".
195
+ */
196
+ declare function reveal(el: Element, opts?: RevealOptions): boolean;
197
+
145
198
  type MicroSignalEmitter = (signalType: 'rage_click' | 'text_copy' | 'scroll_hesitation' | 'tab_loss', extra?: Record<string, unknown>) => void;
146
199
  type MicroSignalType = Parameters<MicroSignalEmitter>[0];
147
200
  /**
@@ -450,4 +503,4 @@ declare function grantConsent(apiKey?: string): void;
450
503
  */
451
504
  declare function init(config: SentientConfig): SentientClient;
452
505
 
453
- export { type AssignResult as A, type ComponentGoalOptions as C, type DecideInput as D, type EventQueue as E, type GoalDefinition as G, LEGACY_SESSION_COOKIE_NAME as L, type MicroSignalEmitter as M, PROD_KEYLESS_ERROR as P, type QueueConfig as Q, type SectionMapEntry as S, type WeightEntry as W, _registerConsentUpgradeInit as _, type Assignment as a, type AssignmentCache as b, type ComponentWeightEntry as c, type DecideOutcome as d, type EventType as e, type GoalOptions as f, type GraphClient as g, type GraphConfig as h, type GraphSnapshot as i, LOCAL_MODE_BANNER as j, type MicroSignalType as k, type PageNode as l, type SentientClient as m, type SentientConfig as n, type SentientEvent as o, type SessionConfig as p, type SessionManager as q, attachMicroSignalDetectors as r, grantConsent as s, init as t, isDoNotTrackEnabled as u, sanitizePageUrl as v, sessionCookieName as w };
506
+ export { type AssignResult as A, type ComponentGoalOptions as C, type DecideInput as D, type EventQueue as E, type GoalDefinition as G, LEGACY_SESSION_COOKIE_NAME as L, type MicroSignalEmitter as M, PROD_KEYLESS_ERROR as P, type QueueConfig as Q, REVEAL_MS as R, type SectionMapEntry as S, type WeightEntry as W, _registerConsentUpgradeInit as _, type Assignment as a, type AssignmentCache as b, type ComponentWeightEntry as c, type DecideOutcome as d, type EventType as e, type GoalOptions as f, type GraphClient as g, type GraphConfig as h, type GraphSnapshot as i, LOCAL_MODE_BANNER as j, type MicroSignalType as k, type PageNode as l, type RevealOptions as m, type SentientClient as n, type SentientConfig as o, type SentientEvent as p, type SessionConfig as q, type SessionManager as r, attachMicroSignalDetectors as s, grantConsent as t, init as u, isDoNotTrackEnabled as v, resetRevealStyles as w, reveal as x, sanitizePageUrl as y, sessionCookieName as z };
@@ -1,2 +1,2 @@
1
- "use strict";var R=Object.defineProperty,le=Object.defineProperties,ce=Object.getOwnPropertyDescriptor,de=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertyNames,Q=Object.getOwnPropertySymbols;var Y=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var J=(e,t,n)=>t in e?R(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,S=(e,t)=>{for(var n in t||(t={}))Y.call(t,n)&&J(e,n,t[n]);if(Q)for(var n of Q(t))pe.call(t,n)&&J(e,n,t[n]);return e},O=(e,t)=>le(e,de(t));var ge=(e,t)=>{for(var n in t)R(e,n,{get:t[n],enumerable:!0})},fe=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ue(t))!Y.call(e,o)&&o!==n&&R(e,o,{get:()=>t[o],enumerable:!(a=ce(t,o))||a.enumerable});return e};var me=e=>fe(R({},"__esModule",{value:!0}),e);var xe={};ge(xe,{SEMANTIC_TYPES:()=>I,classifyFeatures:()=>C,classifySection:()=>Z,featuresFromElement:()=>T,startEngagementCapture:()=>ie});module.exports=me(xe);var I=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],ye={banner:"hero",navigation:"navigation",contentinfo:"footer"};function he(e){let t=e.ariaRole?ye[e.ariaRole.toLowerCase()]:void 0;if(t)return t;if(e.tag==="nav")return"navigation";if(e.tag==="footer")return"footer";if(e.tag==="header")return e.actionCount>=5?"navigation":"hero";let n=`${e.idClass} ${e.headingText}`.toLowerCase();return/\b(navbar|nav-bar|navigation|site-nav|main-nav|topbar|footer)\b/.test(n)?/footer/.test(n)?"footer":"navigation":/\b(hero|masthead|jumbotron)\b/i.test(e.idClass)?"hero":null}function Se(e){return e.actionCount>=1&&e.textLength>0&&e.textLength<200?"cta":"generic"}var we=[["pricing",/\b(pricing|price list|per month|\/mo|subscriptions?)\b|\bplans?\b(?=[^.]{0,40}(from|start|month|year|[$€£]))/i],["faq",/\bfaq\b|frequently asked|common questions?/i],["comparison",/\b(compare|comparison|versus)\b|\bvs\./i],["social_proof",/\b(reviews?|ratings?|testimonial|brands?|galler(y|ies)|logos)\b|trusted by|loved by|case stud|what our customers say/i],["trust",/\b(insurance|warrant(y|ies)|guarantees?|certifi|accredit|security|privacy|compliance|gdpr|encrypt)\b|why choose|about us|our team/i],["cta",/\b(book|booking|reserve|appointments?|newsletter|subscribe)\b|contact us|get in touch|opening hours/i],["features",/\b(features?|benefits?|capabilit|services?|repairs?|menus?|products?)\b|how it works|our process|what we (do|offer)|what you get/i]],P=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|free returns?|returns? within|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]],X={navigation:"navigation",footer:"navigation",hero:"hero",cta:"cta",generic:"generic"};function be(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function C(e){var o,i;let t=he(e);if(t)return{type:(o=X[t])!=null?o:"generic",strength:"strong"};let n=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[d,s]of we)if(s.test(n))return{type:d,strength:"strong"};for(let[d,s]of P)if(s.test(e.bodyText))return{type:d,strength:"strong"};let a=Se(e);return{type:(i=X[a])!=null?i:"generic",strength:"weak"}}function T(e){var a,o;let t=((a=e.textContent)!=null?a:"").replace(/\s+/g," ").trim(),n=e.getAttribute("role");return S({tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((o=e.className)!=null?o:"")}`,headingText:be(e),bodyText:t.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:t.length},n?{ariaRole:n}:{})}function Z(e){return C(T(e)).type}var re=require("@sentientui/policy");var ve=require("@sentientui/policy");function ee(e,t,n,a){let o=[];{let s=!1,l=[],f=()=>{if(s)return;let y=Date.now();for(l.push(y);l.length>0&&y-l[0]>500;)l.shift();l.length>=3&&(s=!0,e("rage_click"))};t.addEventListener("click",f),o.push(()=>t.removeEventListener("click",f))}{let i=!1,d=s=>{if(i||!(s.target instanceof Node)||!t.contains(s.target)&&t!==s.target)return;i=!0;let l=typeof window!="undefined"?window.getSelection():null,f=l?l.toString().length:0;e("text_copy",{selectionLength:f})};document.addEventListener("copy",d),o.push(()=>document.removeEventListener("copy",d))}{let i=!1,d=!1,s=null,l=()=>{s!==null&&(clearTimeout(s),s=null)},f=()=>{i||!d||(l(),s=setTimeout(()=>{!i&&d&&(i=!0,e("scroll_hesitation"))},3e3))},y=()=>{l(),f()},g=b=>{for(let k of b)d=k.intersectionRatio>.3,d?f():l()},h=new IntersectionObserver(g,{threshold:[.3]});h.observe(t),window.addEventListener("scroll",y,{passive:!0}),o.push(()=>{h.disconnect(),window.removeEventListener("scroll",y),l()})}if((a==null?void 0:a.tabLoss)!==!1){let i=!1,d=n!=null?n:Date.now(),s=()=>{if(i||document.visibilityState!=="hidden")return;let l=Date.now()-d;l<15e3&&(i=!0,e("tab_loss",{timeOnPage:l}))};document.addEventListener("visibilitychange",s),o.push(()=>document.removeEventListener("visibilitychange",s))}return()=>{for(let i of o)i()}}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(t=>t==="1"||t==="yes")}var Ce=["data-sentient-id","data-testid","data-test","data-id","data-name","data-cy"];function _(e){var t;return((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim()}function Te(e){return{tag:e.tagName.toLowerCase(),text:_(e).slice(0,40)}}function ne(e){return e.replace(/["\\\]]/g,"\\$&")}function E(e,t){try{return e.querySelectorAll(t).length===1}catch(n){return!1}}function oe(e,t){var d;let n=e.tagName.toLowerCase();if(!n)return null;let a=((d=e.getAttribute("class"))!=null?d:"").split(/\s+/).filter(s=>/^[a-zA-Z][\w-]*$/.test(s)),o=[n,...a.map(s=>`${n}.${s}`)];for(let s of o)if(E(t,s))return s;let i=e.parentElement;if(i&&i!==t){let s=oe(i,t);if(s){for(let g of o){let h=`${s} > ${g}`;if(E(t,h))return h}let l=Array.from(i.children).filter(g=>g.tagName.toLowerCase()===n),f=l.indexOf(e),y=l.some(g=>g!==e&&_(g)!==_(e));if(f>=0&&y){let g=`${s} > ${n}:nth-of-type(${f+1})`;if(E(t,g))return g}}}return null}function se(e,t){let n=Te(e),a=e.getAttribute("id");if(a&&E(t,`#${ne(a)}`))return{v:1,id:a,fingerprint:n};for(let i of Ce){let d=e.getAttribute(i);if(d&&E(t,`[${i}="${ne(d)}"]`))return{v:1,dataAttr:{name:i,value:d},fingerprint:n}}let o=oe(e,t);return o?{v:1,selector:o,fingerprint:n}:null}var Ee="section, header, footer, nav, main > div, [data-sentient-section]",ke=2e4;function Re(e){let t=Array.from(e.querySelectorAll(Ee)),n=t.filter(a=>t.filter(o=>o!==a&&a.contains(o)).length<2);return n.filter(a=>!n.some(o=>o!==a&&o.contains(a)))}function Ie(e,t,n,a){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:a})}).catch(()=>{})}catch(o){}}var x=()=>{};function ie(e,t){var N,L,$,K,G,j,F,B,W,U,H,q;let n=(N=t.doc)!=null?N:typeof document!="undefined"?document:void 0;if(!n||typeof IntersectionObserver=="undefined"||te()||!t.apiKey||!t.apiKey.startsWith("pk_"))return x;let a=((L=t.apiBase)!=null?L:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),o=Re(n);if(o.length===0)return x;let i=new Map,d=[];for(let r of o){let c=r.getAttribute("data-sentient-type"),p=c&&I.includes(c)?c:null,u=T(r),v=(K=p!=null?p:($=t.typeOf)==null?void 0:$.call(t,r))!=null?K:C(u).type,w=se(r,n),z=w?`nc-${v}-${(0,re.fnv1a)(JSON.stringify({id:(G=w.id)!=null?G:null,dataAttr:(j=w.dataAttr)!=null?j:null,selector:(F=w.selector)!=null?F:null})).toString(36)}`:`nc-${v}`;i.set(r,z);let V=P.filter(([,A])=>A.test(u.bodyText)).map(([A])=>A);d.push(O(S({componentId:z,semanticType:v,source:p?"markup":"auto"},w?{locator:w}:{}),{observation:S(S({tag:u.tag,idClass:u.idClass.slice(0,200),headingText:u.headingText,textLength:u.textLength,actionCount:u.actionCount},u.ariaRole?{ariaRole:u.ariaRole}:{}),V.length>0?{patternFlags:V}:{})}))}let s=(H=(U=(W=(B=n.defaultView)!=null?B:typeof window!="undefined"?window:void 0)==null?void 0:W.location)==null?void 0:U.pathname)!=null?H:"/";Ie(t.apiKey,a,s,d);let l=new Map,f=r=>{let c=l.get(r);return c||(c={ms:0,scroll:0,enterAt:null,intersecting:!1},l.set(r,c)),c},y=new IntersectionObserver(r=>{for(let c of r){let p=i.get(c.target);if(!p)continue;let u=f(p);c.isIntersecting?(u.intersecting=!0,u.enterAt=Date.now(),c.intersectionRatio>u.scroll&&(u.scroll=c.intersectionRatio)):(u.intersecting=!1,u.enterAt!=null&&(u.ms+=Date.now()-u.enterAt,u.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let r of i.keys())y.observe(r);let g=()=>{let r=Date.now();for(let[c,p]of l)if(p.enterAt!=null&&(p.ms+=r-p.enterAt,p.enterAt=null),!(p.ms<=0)){try{e.track({projectId:t.apiKey,componentId:c,eventType:"dwell",payload:{dwell_time:Math.round(p.ms),scroll_depth:Number(p.scroll.toFixed(2))}})}catch(u){}p.ms=0}},h=()=>{if(n.hidden)g();else{let r=Date.now();for(let c of l.values())c.intersecting&&(c.enterAt=r)}},b=!1,k=r=>{if(g(),r!=null&&r.persisted){b=!0;return}try{y.disconnect()}catch(c){}},D=r=>{if(!(r!=null&&r.persisted)||!b)return;b=!1;let c=Date.now();for(let p of l.values())p.enterAt=p.intersecting&&!n.hidden?c:null};n.addEventListener("visibilitychange",h);let m=(q=n.defaultView)!=null?q:typeof window!="undefined"?window:void 0;m==null||m.addEventListener("pagehide",k),m==null||m.addEventListener("pageshow",D);let ae=setInterval(()=>{if(n.hidden||b)return;g();let r=Date.now();for(let c of l.values())c.intersecting&&(c.enterAt=r)},ke),M=[];return t.microSignals&&[...i.entries()].forEach(([r,c],p)=>{M.push(ee((u,v={})=>{try{e.track({projectId:t.apiKey,componentId:c,eventType:"micro_signal",payload:S({signalType:u},v)})}catch(w){}},r,void 0,{tabLoss:p===0}))}),()=>{g(),clearInterval(ae),n.removeEventListener("visibilitychange",h),m==null||m.removeEventListener("pagehide",k),m==null||m.removeEventListener("pageshow",D);for(let r of M)r();try{y.disconnect()}catch(r){}}}0&&(module.exports={SEMANTIC_TYPES,classifyFeatures,classifySection,featuresFromElement,startEngagementCapture});
1
+ "use strict";var R=Object.defineProperty,le=Object.defineProperties,ce=Object.getOwnPropertyDescriptor,de=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertyNames,Q=Object.getOwnPropertySymbols;var Y=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var J=(e,t,n)=>t in e?R(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,S=(e,t)=>{for(var n in t||(t={}))Y.call(t,n)&&J(e,n,t[n]);if(Q)for(var n of Q(t))pe.call(t,n)&&J(e,n,t[n]);return e},O=(e,t)=>le(e,de(t));var ge=(e,t)=>{for(var n in t)R(e,n,{get:t[n],enumerable:!0})},fe=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ue(t))!Y.call(e,o)&&o!==n&&R(e,o,{get:()=>t[o],enumerable:!(a=ce(t,o))||a.enumerable});return e};var me=e=>fe(R({},"__esModule",{value:!0}),e);var xe={};ge(xe,{SEMANTIC_TYPES:()=>I,classifyFeatures:()=>C,classifySection:()=>Z,featuresFromElement:()=>T,startEngagementCapture:()=>ie});module.exports=me(xe);var I=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],ye={banner:"hero",navigation:"navigation",contentinfo:"footer"};function he(e){let t=e.ariaRole?ye[e.ariaRole.toLowerCase()]:void 0;if(t)return t;if(e.tag==="nav")return"navigation";if(e.tag==="footer")return"footer";if(e.tag==="header")return e.actionCount>=5?"navigation":"hero";let n=`${e.idClass} ${e.headingText}`.toLowerCase();return/\b(navbar|nav-bar|navigation|site-nav|main-nav|topbar|footer)\b/.test(n)?/footer/.test(n)?"footer":"navigation":/\b(hero|masthead|jumbotron)\b/i.test(e.idClass)?"hero":null}function Se(e){return e.actionCount>=1&&e.textLength>0&&e.textLength<200?"cta":"generic"}var we=[["pricing",/\b(pricing|price list|per month|\/mo|subscriptions?)\b|\bplans?\b(?=[^.]{0,40}(from|start|month|year|[$€£]))/i],["faq",/\bfaq\b|frequently asked|common questions?/i],["comparison",/\b(compare|comparison|versus)\b|\bvs\./i],["social_proof",/\b(reviews?|ratings?|testimonial|brands?|galler(y|ies)|logos)\b|trusted by|loved by|case stud|what our customers say/i],["trust",/\b(insurance|warrant(y|ies)|guarantees?|certifi|accredit|security|privacy|compliance|gdpr|encrypt)\b|why choose|about us|our team/i],["cta",/\b(book|booking|reserve|appointments?|newsletter|subscribe)\b|contact us|get in touch|opening hours/i],["features",/\b(features?|benefits?|capabilit|services?|repairs?|menus?|products?)\b|how it works|our process|what we (do|offer)|what you get/i]],_=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|free returns?|returns? within|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]],X={navigation:"navigation",footer:"navigation",hero:"hero",cta:"cta",generic:"generic"};function be(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function C(e){var o,i;let t=he(e);if(t)return{type:(o=X[t])!=null?o:"generic",strength:"strong"};let n=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[d,s]of we)if(s.test(n))return{type:d,strength:"strong"};for(let[d,s]of _)if(s.test(e.bodyText))return{type:d,strength:"strong"};let a=Se(e);return{type:(i=X[a])!=null?i:"generic",strength:"weak"}}function T(e){var a,o;let t=((a=e.textContent)!=null?a:"").replace(/\s+/g," ").trim(),n=e.getAttribute("role");return S({tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((o=e.className)!=null?o:"")}`,headingText:be(e),bodyText:t.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:t.length},n?{ariaRole:n}:{})}function Z(e){return C(T(e)).type}var re=require("@sentientui/policy");var ve=require("@sentientui/policy");function ee(e,t,n,a){let o=[];{let s=!1,l=[],f=()=>{if(s)return;let y=Date.now();for(l.push(y);l.length>0&&y-l[0]>500;)l.shift();l.length>=3&&(s=!0,e("rage_click"))};t.addEventListener("click",f),o.push(()=>t.removeEventListener("click",f))}{let i=!1,d=s=>{if(i||!(s.target instanceof Node)||!t.contains(s.target)&&t!==s.target)return;i=!0;let l=typeof window!="undefined"?window.getSelection():null,f=l?l.toString().length:0;e("text_copy",{selectionLength:f})};document.addEventListener("copy",d),o.push(()=>document.removeEventListener("copy",d))}{let i=!1,d=!1,s=null,l=()=>{s!==null&&(clearTimeout(s),s=null)},f=()=>{i||!d||(l(),s=setTimeout(()=>{!i&&d&&(i=!0,e("scroll_hesitation"))},3e3))},y=()=>{l(),f()},g=b=>{for(let k of b)d=k.intersectionRatio>.3,d?f():l()},h=new IntersectionObserver(g,{threshold:[.3]});h.observe(t),window.addEventListener("scroll",y,{passive:!0}),o.push(()=>{h.disconnect(),window.removeEventListener("scroll",y),l()})}if((a==null?void 0:a.tabLoss)!==!1){let i=!1,d=n!=null?n:Date.now(),s=()=>{if(i||document.visibilityState!=="hidden")return;let l=Date.now()-d;l<15e3&&(i=!0,e("tab_loss",{timeOnPage:l}))};document.addEventListener("visibilitychange",s),o.push(()=>document.removeEventListener("visibilitychange",s))}return()=>{for(let i of o)i()}}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(t=>t==="1"||t==="yes")}var Ce=["data-sentient-id","data-testid","data-test","data-id","data-name","data-cy"];function P(e){var t;return((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim()}function Te(e){return{tag:e.tagName.toLowerCase(),text:P(e).slice(0,40)}}function ne(e){return e.replace(/["\\\]]/g,"\\$&")}function E(e,t){try{return e.querySelectorAll(t).length===1}catch(n){return!1}}function oe(e,t){var d;let n=e.tagName.toLowerCase();if(!n)return null;let a=((d=e.getAttribute("class"))!=null?d:"").split(/\s+/).filter(s=>/^[a-zA-Z][\w-]*$/.test(s)),o=[n,...a.map(s=>`${n}.${s}`)];for(let s of o)if(E(t,s))return s;let i=e.parentElement;if(i&&i!==t){let s=oe(i,t);if(s){for(let g of o){let h=`${s} > ${g}`;if(E(t,h))return h}let l=Array.from(i.children).filter(g=>g.tagName.toLowerCase()===n),f=l.indexOf(e),y=l.some(g=>g!==e&&P(g)!==P(e));if(f>=0&&y){let g=`${s} > ${n}:nth-of-type(${f+1})`;if(E(t,g))return g}}}return null}function se(e,t){let n=Te(e),a=e.getAttribute("id");if(a&&E(t,`#${ne(a)}`))return{v:1,id:a,fingerprint:n};for(let i of Ce){let d=e.getAttribute(i);if(d&&E(t,`[${i}="${ne(d)}"]`))return{v:1,dataAttr:{name:i,value:d},fingerprint:n}}let o=oe(e,t);return o?{v:1,selector:o,fingerprint:n}:null}var Ee="section, header, footer, nav, main > div, [data-sentient-section]",ke=2e4;function Re(e){let t=Array.from(e.querySelectorAll(Ee)),n=t.filter(a=>t.filter(o=>o!==a&&a.contains(o)).length<2);return n.filter(a=>!n.some(o=>o!==a&&o.contains(a)))}function Ie(e,t,n,a){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:a})}).catch(()=>{})}catch(o){}}var x=()=>{};function ie(e,t){var N,L,$,K,G,j,F,B,W,U,H,q;let n=(N=t.doc)!=null?N:typeof document!="undefined"?document:void 0;if(!n||typeof IntersectionObserver=="undefined"||te()||!t.apiKey||!t.apiKey.startsWith("pk_"))return x;let a=((L=t.apiBase)!=null?L:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),o=Re(n);if(o.length===0)return x;let i=new Map,d=[];for(let r of o){let c=r.getAttribute("data-sentient-type"),p=c&&I.includes(c)?c:null,u=T(r),v=(K=p!=null?p:($=t.typeOf)==null?void 0:$.call(t,r))!=null?K:C(u).type,w=se(r,n),z=w?`nc-${v}-${(0,re.fnv1a)(JSON.stringify({id:(G=w.id)!=null?G:null,dataAttr:(j=w.dataAttr)!=null?j:null,selector:(F=w.selector)!=null?F:null})).toString(36)}`:`nc-${v}`;i.set(r,z);let V=_.filter(([,A])=>A.test(u.bodyText)).map(([A])=>A);d.push(O(S({componentId:z,semanticType:v,source:p?"markup":"auto"},w?{locator:w}:{}),{observation:S(S({tag:u.tag,idClass:u.idClass.slice(0,200),headingText:u.headingText,textLength:u.textLength,actionCount:u.actionCount},u.ariaRole?{ariaRole:u.ariaRole}:{}),V.length>0?{patternFlags:V}:{})}))}let s=(H=(U=(W=(B=n.defaultView)!=null?B:typeof window!="undefined"?window:void 0)==null?void 0:W.location)==null?void 0:U.pathname)!=null?H:"/";Ie(t.apiKey,a,s,d);let l=new Map,f=r=>{let c=l.get(r);return c||(c={ms:0,scroll:0,enterAt:null,intersecting:!1},l.set(r,c)),c},y=new IntersectionObserver(r=>{for(let c of r){let p=i.get(c.target);if(!p)continue;let u=f(p);c.isIntersecting?(u.intersecting=!0,u.enterAt=Date.now(),c.intersectionRatio>u.scroll&&(u.scroll=c.intersectionRatio)):(u.intersecting=!1,u.enterAt!=null&&(u.ms+=Date.now()-u.enterAt,u.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let r of i.keys())y.observe(r);let g=()=>{let r=Date.now();for(let[c,p]of l)if(p.enterAt!=null&&(p.ms+=r-p.enterAt,p.enterAt=null),!(p.ms<=0)){try{e.track({projectId:t.apiKey,componentId:c,eventType:"dwell",payload:{dwell_time:Math.round(p.ms),scroll_depth:Number(p.scroll.toFixed(2))}})}catch(u){}p.ms=0}},h=()=>{if(n.hidden)g();else{let r=Date.now();for(let c of l.values())c.intersecting&&(c.enterAt=r)}},b=!1,k=r=>{if(g(),r!=null&&r.persisted){b=!0;return}try{y.disconnect()}catch(c){}},D=r=>{if(!(r!=null&&r.persisted)||!b)return;b=!1;let c=Date.now();for(let p of l.values())p.enterAt=p.intersecting&&!n.hidden?c:null};n.addEventListener("visibilitychange",h);let m=(q=n.defaultView)!=null?q:typeof window!="undefined"?window:void 0;m==null||m.addEventListener("pagehide",k),m==null||m.addEventListener("pageshow",D);let ae=setInterval(()=>{if(n.hidden||b)return;g();let r=Date.now();for(let c of l.values())c.intersecting&&(c.enterAt=r)},ke),M=[];return t.microSignals&&[...i.entries()].forEach(([r,c],p)=>{M.push(ee((u,v={})=>{try{e.track({projectId:t.apiKey,componentId:c,eventType:"micro_signal",payload:S({signalType:u},v)})}catch(w){}},r,void 0,{tabLoss:p===0}))}),()=>{g(),clearInterval(ae),n.removeEventListener("visibilitychange",h),m==null||m.removeEventListener("pagehide",k),m==null||m.removeEventListener("pageshow",D);for(let r of M)r();try{y.disconnect()}catch(r){}}}0&&(module.exports={SEMANTIC_TYPES,classifyFeatures,classifySection,featuresFromElement,startEngagementCapture});
2
2
  //# sourceMappingURL=index-engagement.js.map