@sentientui/core 0.31.1 → 0.32.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.
@@ -27,7 +27,7 @@ type SessionManager = {
27
27
  };
28
28
 
29
29
  /** Batched event queue with reliable transport (fetch + keepalive, localStorage retry). */
30
- type EventType = 'variant_assigned' | 'goal_achieved' | 'scroll_depth' | 'dwell' | 'cursor_signal' | 'component_visible' | 'component_exited' | 'micro_signal' | 'funnel_declared' | 'pageview';
30
+ type EventType = 'variant_assigned' | 'goal_achieved' | 'scroll_depth' | 'dwell' | 'cursor_signal' | 'component_visible' | 'component_exited' | 'micro_signal' | 'funnel_declared' | 'pageview' | 'interaction_stats';
31
31
  type SentientEvent = {
32
32
  id: string;
33
33
  sessionId: string;
@@ -535,6 +535,19 @@ type SentientClient = {
535
535
  * KEEPS the visitor identity, decision snapshot, and retry bucket. Use for
536
536
  * component unmount / re-init (framework providers call this on cleanup).
537
537
  */
538
+ /**
539
+ * Drain the event queue now, without tearing anything down.
540
+ *
541
+ * The queue flushes on its own timer and on its own pagehide /
542
+ * visibilitychange listeners, both registered when this client is built. The
543
+ * engagement capture is imported later and banks dwell and the interaction
544
+ * snapshot INSIDE those same lifecycle events — i.e. after the queue has
545
+ * already drained — so on the leave path its events sat in the queue while
546
+ * the page went away. Delivery on that path measured ~5-8% (Bodyshop audit
547
+ * 2026-08-30); a visit shorter than the 5 s tick delivered nothing at all.
548
+ * Anything that banks late in a lifecycle handler must call this after.
549
+ */
550
+ flush(): void;
538
551
  dispose(): void;
539
552
  /**
540
553
  * Consent-revocation / forget-me teardown: everything `dispose()` does,
@@ -1,6 +1,40 @@
1
1
  import { b as SemanticType } from './classify-DYlSjkFP.cjs';
2
2
  export { S as SEMANTIC_TYPES, a as SectionFeatures, c as classifyFeatures, d as classifySection, f as featuresFromElement } from './classify-DYlSjkFP.cjs';
3
3
 
4
+ type InteractionStats = {
5
+ v: 1;
6
+ active_ms: number;
7
+ mm: number;
8
+ /** Mousemoves per VISIBLE second, 2 dp. The count alone does not separate:
9
+ * a driver dispatches one mousemove per click, so `mm === 0` is false for
10
+ * the commonest automation stack (measured: Playwright emits 3 over a
11
+ * 6-action script). The rate does — humans emit tens per second, drivers
12
+ * around one. Carried alongside `mm` so a future threshold can use either. */
13
+ mm_rate: number;
14
+ touches: number;
15
+ clicks: number;
16
+ /** How many mousedown→mouseup pairs `hold_mean`/`hold_std` rest on. Without
17
+ * it a zero-variance hold (a driver pressing and releasing in one tick) is
18
+ * indistinguishable from never having measured one at all, and the scorer
19
+ * would condemn the second case on the evidence of the first. */
20
+ hold_n: number;
21
+ hold_mean: number;
22
+ hold_std: number;
23
+ teleport: number;
24
+ wheel: number;
25
+ scroll_px: number;
26
+ keydowns: number;
27
+ input_chars: number;
28
+ ik_cv: number;
29
+ backspaces: number;
30
+ gaps: [number, number, number, number, number, number];
31
+ reduced_motion: boolean;
32
+ kb_nav: number;
33
+ renderer: 'sw' | 'hw' | 'unknown';
34
+ vp: [number, number];
35
+ dpr: number;
36
+ };
37
+
4
38
  type CaptureClient = {
5
39
  track(event: {
6
40
  projectId: string;
@@ -8,6 +42,10 @@ type CaptureClient = {
8
42
  eventType: string;
9
43
  payload: Record<string, unknown>;
10
44
  }): void;
45
+ /** Drain the event queue now. Optional so an embedder can pass a bare
46
+ * tracker, but every first-party client has it — see the leave-path flush
47
+ * in `emit`, which is what makes a short visit deliverable at all. */
48
+ flush?(): void;
11
49
  };
12
50
  type EngagementCaptureOptions = {
13
51
  apiKey: string;
@@ -35,6 +73,12 @@ type EngagementCaptureOptions = {
35
73
  */
36
74
  typeOf?: (el: Element) => SemanticType | null;
37
75
  };
76
+ /** Sentinel component for the session-level interaction snapshot — same
77
+ * pattern as pageview's `__page__`: not a component, never attributed to one.
78
+ * Every report producer filters `raw_events` by event_type, so the sentinel
79
+ * cannot leak into a component table. */
80
+ declare const INTERACTION_STATS_COMPONENT = "__session__";
81
+
38
82
  declare function startEngagementCapture(client: CaptureClient, opts: EngagementCaptureOptions): () => void;
39
83
 
40
- export { type EngagementCaptureOptions, SemanticType, startEngagementCapture };
84
+ export { type EngagementCaptureOptions, INTERACTION_STATS_COMPONENT, type InteractionStats, SemanticType, startEngagementCapture };
@@ -1,6 +1,40 @@
1
1
  import { b as SemanticType } from './classify-DYlSjkFP.js';
2
2
  export { S as SEMANTIC_TYPES, a as SectionFeatures, c as classifyFeatures, d as classifySection, f as featuresFromElement } from './classify-DYlSjkFP.js';
3
3
 
4
+ type InteractionStats = {
5
+ v: 1;
6
+ active_ms: number;
7
+ mm: number;
8
+ /** Mousemoves per VISIBLE second, 2 dp. The count alone does not separate:
9
+ * a driver dispatches one mousemove per click, so `mm === 0` is false for
10
+ * the commonest automation stack (measured: Playwright emits 3 over a
11
+ * 6-action script). The rate does — humans emit tens per second, drivers
12
+ * around one. Carried alongside `mm` so a future threshold can use either. */
13
+ mm_rate: number;
14
+ touches: number;
15
+ clicks: number;
16
+ /** How many mousedown→mouseup pairs `hold_mean`/`hold_std` rest on. Without
17
+ * it a zero-variance hold (a driver pressing and releasing in one tick) is
18
+ * indistinguishable from never having measured one at all, and the scorer
19
+ * would condemn the second case on the evidence of the first. */
20
+ hold_n: number;
21
+ hold_mean: number;
22
+ hold_std: number;
23
+ teleport: number;
24
+ wheel: number;
25
+ scroll_px: number;
26
+ keydowns: number;
27
+ input_chars: number;
28
+ ik_cv: number;
29
+ backspaces: number;
30
+ gaps: [number, number, number, number, number, number];
31
+ reduced_motion: boolean;
32
+ kb_nav: number;
33
+ renderer: 'sw' | 'hw' | 'unknown';
34
+ vp: [number, number];
35
+ dpr: number;
36
+ };
37
+
4
38
  type CaptureClient = {
5
39
  track(event: {
6
40
  projectId: string;
@@ -8,6 +42,10 @@ type CaptureClient = {
8
42
  eventType: string;
9
43
  payload: Record<string, unknown>;
10
44
  }): void;
45
+ /** Drain the event queue now. Optional so an embedder can pass a bare
46
+ * tracker, but every first-party client has it — see the leave-path flush
47
+ * in `emit`, which is what makes a short visit deliverable at all. */
48
+ flush?(): void;
11
49
  };
12
50
  type EngagementCaptureOptions = {
13
51
  apiKey: string;
@@ -35,6 +73,12 @@ type EngagementCaptureOptions = {
35
73
  */
36
74
  typeOf?: (el: Element) => SemanticType | null;
37
75
  };
76
+ /** Sentinel component for the session-level interaction snapshot — same
77
+ * pattern as pageview's `__page__`: not a component, never attributed to one.
78
+ * Every report producer filters `raw_events` by event_type, so the sentinel
79
+ * cannot leak into a component table. */
80
+ declare const INTERACTION_STATS_COMPONENT = "__session__";
81
+
38
82
  declare function startEngagementCapture(client: CaptureClient, opts: EngagementCaptureOptions): () => void;
39
83
 
40
- export { type EngagementCaptureOptions, SemanticType, startEngagementCapture };
84
+ export { type EngagementCaptureOptions, INTERACTION_STATS_COMPONENT, type InteractionStats, SemanticType, startEngagementCapture };
@@ -1,2 +1,2 @@
1
- "use strict";var R=Object.defineProperty,de=Object.defineProperties,ue=Object.getOwnPropertyDescriptor,ge=Object.getOwnPropertyDescriptors,pe=Object.getOwnPropertyNames,Y=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var X=(e,t,n)=>t in e?R(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,w=(e,t)=>{for(var n in t||(t={}))Z.call(t,n)&&X(e,n,t[n]);if(Y)for(var n of Y(t))fe.call(t,n)&&X(e,n,t[n]);return e},O=(e,t)=>de(e,ge(t));var me=(e,t)=>{for(var n in t)R(e,n,{get:t[n],enumerable:!0})},ye=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of pe(t))!Z.call(e,o)&&o!==n&&R(e,o,{get:()=>t[o],enumerable:!(a=ue(t,o))||a.enumerable});return e};var he=e=>ye(R({},"__esModule",{value:!0}),e);var Oe={};me(Oe,{SEMANTIC_TYPES:()=>I,classifyFeatures:()=>T,classifySection:()=>te,featuresFromElement:()=>E,startEngagementCapture:()=>le});module.exports=he(Oe);var I=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Se={banner:"hero",navigation:"navigation",contentinfo:"footer"};function we(e){let t=e.ariaRole?Se[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 be(e){return e.actionCount>=1&&e.textLength>0&&e.textLength<200?"cta":"generic"}var ve=[["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]],ee={navigation:"navigation",footer:"navigation",hero:"hero",cta:"cta",generic:"generic"};function Te(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function T(e){var o,i;let t=we(e);if(t)return{type:(o=ee[t])!=null?o:"generic",strength:"strong"};let n=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[u,r]of ve)if(r.test(n))return{type:u,strength:"strong"};for(let[u,r]of _)if(r.test(e.bodyText))return{type:u,strength:"strong"};let a=be(e);return{type:(i=ee[a])!=null?i:"generic",strength:"weak"}}function E(e){var a,o;let t=((a=e.textContent)!=null?a:"").replace(/\s+/g," ").trim(),n=e.getAttribute("role");return w({tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((o=e.className)!=null?o:"")}`,headingText:Te(e),bodyText:t.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:t.length},n?{ariaRole:n}:{})}function te(e){return T(E(e)).type}var ae=require("@sentientui/policy");var Ee=require("@sentientui/policy");function ne(e,t,n,a){let o=[];{let r=!1,c=[],f=()=>{if(r)return;let y=Date.now();for(c.push(y);c.length>0&&y-c[0]>500;)c.shift();c.length>=3&&(r=!0,e("rage_click"))};t.addEventListener("click",f),o.push(()=>t.removeEventListener("click",f))}{let i=!1,u=r=>{if(i||!(r.target instanceof Node)||!t.contains(r.target)&&t!==r.target)return;i=!0;let c=typeof window!="undefined"?window.getSelection():null,f=c?c.toString().length:0;e("text_copy",{selectionLength:f})};document.addEventListener("copy",u),o.push(()=>document.removeEventListener("copy",u))}{let i=!1,u=!1,r=null,c=()=>{r!==null&&(clearTimeout(r),r=null)},f=()=>{i||!u||(c(),r=setTimeout(()=>{!i&&u&&(i=!0,e("scroll_hesitation"))},3e3))},y=()=>{c(),f()},g=b=>{for(let k of b)u=k.intersectionRatio>.3,u?f():c()},h=new IntersectionObserver(g,{threshold:[.3]});h.observe(t),window.addEventListener("scroll",y,{passive:!0}),o.push(()=>{h.disconnect(),window.removeEventListener("scroll",y),c()})}if((a==null?void 0:a.tabLoss)!==!1){let i=!1,u=n!=null?n:Date.now(),r=()=>{if(i||document.visibilityState!=="hidden")return;let c=Date.now()-u;c<15e3&&(i=!0,e("tab_loss",{timeOnPage:c}))};document.addEventListener("visibilitychange",r),o.push(()=>document.removeEventListener("visibilitychange",r))}return()=>{for(let i of o)i()}}function oe(){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 ke(e){return{tag:e.tagName.toLowerCase(),text:P(e).slice(0,40)}}function se(e){return e.replace(/["\\\]]/g,"\\$&")}function C(e,t){try{return e.querySelectorAll(t).length===1}catch(n){return!1}}function re(e,t){var u;let n=e.tagName.toLowerCase();if(!n)return null;let a=((u=e.getAttribute("class"))!=null?u:"").split(/\s+/).filter(r=>/^[a-zA-Z][\w-]*$/.test(r)),o=[n,...a.map(r=>`${n}.${r}`)];for(let r of o)if(C(t,r))return r;let i=e.parentElement;if(i&&i!==t){let r=re(i,t);if(r){for(let g of o){let h=`${r} > ${g}`;if(C(t,h))return h}let c=Array.from(i.children).filter(g=>g.tagName.toLowerCase()===n),f=c.indexOf(e),y=c.some(g=>g!==e&&P(g)!==P(e));if(f>=0&&y){let g=`${r} > ${n}:nth-of-type(${f+1})`;if(C(t,g))return g}}}return null}function ie(e,t){let n=ke(e),a=e.getAttribute("id");if(a&&C(t,`#${se(a)}`))return{v:1,id:a,fingerprint:n};for(let i of Ce){let u=e.getAttribute(i);if(u&&C(t,`[${i}="${se(u)}"]`))return{v:1,dataAttr:{name:i,value:u},fingerprint:n}}let o=re(e,t);return o?{v:1,selector:o,fingerprint:n}:null}var Re="section, header, footer, nav, main > div, [data-sentient-section]",Ie=2e4;function xe(e){let t=Array.from(e.querySelectorAll(Re)),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 Ae(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 le(e,t){var N,L,$,K,G,j,F,B,W,q,U,z,H,V,Q;let n=(N=t.doc)!=null?N:typeof document!="undefined"?document:void 0;if(!n||typeof IntersectionObserver=="undefined"||oe()||!t.apiKey||!t.apiKey.startsWith("pk_"))return x;let a=((L=t.apiBase)!=null?L:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),o=xe(n);if(o.length===0)return x;let i=new Map,u=[];for(let s of o){let l=(G=[(K=t.sectionTypes)==null?void 0:K[($=s.getAttribute("data-sentient-id"))!=null?$:""],s.getAttribute("data-sentient-type")].find(v=>I.includes(v)))!=null?G:null,d=E(s),p=(F=l!=null?l:(j=t.typeOf)==null?void 0:j.call(t,s))!=null?F:T(d).type,S=ie(s,n),A=S?`nc-${p}-${(0,ae.fnv1a)(JSON.stringify({id:(B=S.id)!=null?B:null,dataAttr:(W=S.dataAttr)!=null?W:null,selector:(q=S.selector)!=null?q:null})).toString(36)}`:`nc-${p}`;i.set(s,A);let J=_.filter(([,v])=>v.test(d.bodyText)).map(([v])=>v);u.push(O(w({componentId:A,semanticType:p,source:l?"markup":"auto"},S?{locator:S}:{}),{observation:w(w({tag:d.tag,idClass:d.idClass.slice(0,200),headingText:d.headingText,textLength:d.textLength,actionCount:d.actionCount},d.ariaRole?{ariaRole:d.ariaRole}:{}),J.length>0?{patternFlags:J}:{})}))}let r=(V=(H=(z=(U=n.defaultView)!=null?U:typeof window!="undefined"?window:void 0)==null?void 0:z.location)==null?void 0:H.pathname)!=null?V:"/";Ae(t.apiKey,a,r,u);let c=new Map,f=s=>{let l=c.get(s);return l||(l={ms:0,scroll:0,enterAt:null,intersecting:!1},c.set(s,l)),l},y=new IntersectionObserver(s=>{for(let l of s){let d=i.get(l.target);if(!d)continue;let p=f(d);l.isIntersecting?(p.intersecting=!0,p.enterAt=Date.now(),l.intersectionRatio>p.scroll&&(p.scroll=l.intersectionRatio)):(p.intersecting=!1,p.enterAt!=null&&(p.ms+=Date.now()-p.enterAt,p.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let s of i.keys())y.observe(s);let g=()=>{let s=Date.now();for(let[l,d]of c)if(d.enterAt!=null&&(d.ms+=s-d.enterAt,d.enterAt=null),!(d.ms<=0)){try{e.track({projectId:t.apiKey,componentId:l,eventType:"dwell",payload:{dwell_time:Math.round(d.ms),scroll_depth:Number(d.scroll.toFixed(2))}})}catch(p){}d.ms=0}},h=()=>{if(n.hidden)g();else{let s=Date.now();for(let l of c.values())l.intersecting&&(l.enterAt=s)}},b=!1,k=s=>{if(g(),s!=null&&s.persisted){b=!0;return}try{y.disconnect()}catch(l){}},D=s=>{if(!(s!=null&&s.persisted)||!b)return;b=!1;let l=Date.now();for(let d of c.values())d.enterAt=d.intersecting&&!n.hidden?l: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 ce=setInterval(()=>{if(n.hidden||b)return;g();let s=Date.now();for(let l of c.values())l.intersecting&&(l.enterAt=s)},Ie),M=[];return t.microSignals&&[...i.entries()].forEach(([s,l],d)=>{M.push(ne((p,S={})=>{try{e.track({projectId:t.apiKey,componentId:l,eventType:"micro_signal",payload:w({signalType:p},S)})}catch(A){}},s,void 0,{tabLoss:d===0}))}),()=>{g(),clearInterval(ce),n.removeEventListener("visibilitychange",h),m==null||m.removeEventListener("pagehide",k),m==null||m.removeEventListener("pageshow",D);for(let s of M)s();try{y.disconnect()}catch(s){}}}0&&(module.exports={SEMANTIC_TYPES,classifyFeatures,classifySection,featuresFromElement,startEngagementCapture});
1
+ "use strict";var V=Object.defineProperty,he=Object.defineProperties,Se=Object.getOwnPropertyDescriptor,ve=Object.getOwnPropertyDescriptors,be=Object.getOwnPropertyNames,te=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable;var ne=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))oe.call(t,n)&&ne(e,n,t[n]);if(te)for(var n of te(t))we.call(t,n)&&ne(e,n,t[n]);return e},J=(e,t)=>he(e,ve(t));var Ee=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},Te=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of be(t))!oe.call(e,o)&&o!==n&&V(e,o,{get:()=>t[o],enumerable:!(i=Se(t,o))||i.enumerable});return e};var ke=e=>Te(V({},"__esModule",{value:!0}),e);var je={};Ee(je,{INTERACTION_STATS_COMPONENT:()=>ee,SEMANTIC_TYPES:()=>Y,classifyFeatures:()=>U,classifySection:()=>re,featuresFromElement:()=>H,startEngagementCapture:()=>ye});module.exports=ke(je);var Y=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Ce={banner:"hero",navigation:"navigation",contentinfo:"footer"};function Ie(e){let t=e.ariaRole?Ce[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 _e(e){return e.actionCount>=1&&e.textLength>0&&e.textLength<200?"cta":"generic"}var Re=[["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]],X=[["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]],se={navigation:"navigation",footer:"navigation",hero:"hero",cta:"cta",generic:"generic"};function xe(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function U(e){var o,a;let t=Ie(e);if(t)return{type:(o=se[t])!=null?o:"generic",strength:"strong"};let n=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[d,l]of Re)if(l.test(n))return{type:d,strength:"strong"};for(let[d,l]of X)if(l.test(e.bodyText))return{type:d,strength:"strong"};let i=_e(e);return{type:(a=se[i])!=null?a:"generic",strength:"weak"}}function H(e){var i,o;let t=((i=e.textContent)!=null?i:"").replace(/\s+/g," ").trim(),n=e.getAttribute("role");return C({tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((o=e.className)!=null?o:"")}`,headingText:xe(e),bodyText:t.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:t.length},n?{ariaRole:n}:{})}function re(e){return U(H(e)).type}var me=require("@sentientui/policy");var Ae=require("@sentientui/policy");function ie(e,t,n,i){let o=[];{let l=!1,u=[],v=()=>{if(l)return;let y=Date.now();for(u.push(y);u.length>0&&y-u[0]>500;)u.shift();u.length>=3&&(l=!0,e("rage_click"))};t.addEventListener("click",v),o.push(()=>t.removeEventListener("click",v))}{let a=!1,d=l=>{if(a||!(l.target instanceof Node)||!t.contains(l.target)&&t!==l.target)return;a=!0;let u=typeof window!="undefined"?window.getSelection():null,v=u?u.toString().length:0;e("text_copy",{selectionLength:v})};document.addEventListener("copy",d),o.push(()=>document.removeEventListener("copy",d))}{let a=!1,d=!1,l=null,u=()=>{l!==null&&(clearTimeout(l),l=null)},v=()=>{a||!d||(u(),l=setTimeout(()=>{!a&&d&&(a=!0,e("scroll_hesitation"))},3e3))},y=()=>{u(),v()},S=T=>{for(let I of T)d=I.intersectionRatio>.3,d?v():u()},b=new IntersectionObserver(S,{threshold:[.3]});b.observe(t),window.addEventListener("scroll",y,{passive:!0}),o.push(()=>{b.disconnect(),window.removeEventListener("scroll",y),u()})}if((i==null?void 0:i.tabLoss)!==!1){let a=!1,d=n!=null?n:Date.now(),l=()=>{if(a||document.visibilityState!=="hidden")return;let u=Date.now()-d;u<15e3&&(a=!0,e("tab_loss",{timeOnPage:u}))};document.addEventListener("visibilitychange",l),o.push(()=>document.removeEventListener("visibilitychange",l))}return()=>{for(let a of o)a()}}function ae(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(t=>t==="1"||t==="yes")}var Oe=["data-sentient-id","data-testid","data-test","data-id","data-name","data-cy"];function Z(e){var t;return((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim()}function De(e){return{tag:e.tagName.toLowerCase(),text:Z(e).slice(0,40)}}function le(e){return e.replace(/["\\\]]/g,"\\$&")}function z(e,t){try{return e.querySelectorAll(t).length===1}catch(n){return!1}}function ce(e,t){var d;let n=e.tagName.toLowerCase();if(!n)return null;let i=((d=e.getAttribute("class"))!=null?d:"").split(/\s+/).filter(l=>/^[a-zA-Z][\w-]*$/.test(l)),o=[n,...i.map(l=>`${n}.${l}`)];for(let l of o)if(z(t,l))return l;let a=e.parentElement;if(a&&a!==t){let l=ce(a,t);if(l){for(let S of o){let b=`${l} > ${S}`;if(z(t,b))return b}let u=Array.from(a.children).filter(S=>S.tagName.toLowerCase()===n),v=u.indexOf(e),y=u.some(S=>S!==e&&Z(S)!==Z(e));if(v>=0&&y){let S=`${l} > ${n}:nth-of-type(${v+1})`;if(z(t,S))return S}}}return null}function de(e,t){let n=De(e),i=e.getAttribute("id");if(i&&z(t,`#${le(i)}`))return{v:1,id:i,fingerprint:n};for(let a of Oe){let d=e.getAttribute(a);if(d&&z(t,`[${a}="${le(d)}"]`))return{v:1,dataAttr:{name:a,value:d},fingerprint:n}}let o=ce(e,t);return o?{v:1,selector:o,fingerprint:n}:null}var ue=[100,300,1e3,3e3,1e4],Pe=250,Le=1e3,Me=new Set(["Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);function pe(e,t){e.n++;let n=t-e.mean;e.mean+=n/e.n,e.m2+=n*(t-e.mean)}var ge=e=>e.n>1?Math.sqrt(e.m2/e.n):0;function Ne(e){var t;try{let n=e.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(!i)return"unknown";let o=i.getExtension("WEBGL_debug_renderer_info"),a=o?String((t=i.getParameter(o.UNMASKED_RENDERER_WEBGL))!=null?t:""):"";return a?/swiftshader|llvmpipe|softpipe|software|mesa offscreen/i.test(a)?"sw":"hw":"unknown"}catch(n){return"unknown"}}function fe(e,t=Date.now){var g,f;let n=(g=e.defaultView)!=null?g:typeof window!="undefined"?window:void 0,i={n:0,mean:0,m2:0},o={n:0,mean:0,m2:0},a=[0,0,0,0,0,0],d=0,l=0,u=0,v=0,y=0,S=0,b=0,T=0,I=0,_=0,O=-1/0,D=-1/0,h=null,P=null,A=null,L=(f=n==null?void 0:n.scrollY)!=null?f:0,M=0,w=e.hidden?null:t(),R=()=>{let s=t();if(A!=null){let m=s-A,E=0;for(;E<ue.length&&m>=ue[E];)E++;a[E]++}A=s},N=()=>{d++,O=t()},K=()=>{l++,D=t()},$=()=>{h=t()},G=()=>{h!=null&&(pe(i,t()-h),h=null)},W=()=>{let s=t();u++,s-O>Pe&&s-D>Le&&v++,R()},x=()=>{y++},j=()=>{var m;let s=(m=n==null?void 0:n.scrollY)!=null?m:0;S+=Math.abs(s-L),L=s,R()},F=s=>{let m=t();b++,(s.key==="Backspace"||s.key==="Delete")&&I++,Me.has(s.key)&&_++,P!=null&&pe(o,m-P),P=m,R()},B=s=>{let m=s.data;typeof m=="string"&&(T+=m.length),R()},q=()=>{let s=t();e.hidden?w!=null&&(M+=s-w,w=null):w==null&&(w=s)},p={passive:!0,capture:!0};e.addEventListener("mousemove",N,p),e.addEventListener("touchstart",K,p),e.addEventListener("touchmove",x,p),e.addEventListener("mousedown",$,p),e.addEventListener("mouseup",G,p),e.addEventListener("click",W,p),e.addEventListener("wheel",x,p),e.addEventListener("keydown",F,p),e.addEventListener("input",B,p),e.addEventListener("visibilitychange",q),n==null||n.addEventListener("scroll",j,p);let r=Ne(e),c=(()=>{var s;try{return((s=n==null?void 0:n.matchMedia)==null?void 0:s.call(n,"(prefers-reduced-motion: reduce)").matches)===!0}catch(m){return!1}})();return{snapshot(){var E,k;let s=t(),m=M+(w!=null?s-w:0);return{v:1,active_ms:Math.round(m),mm:d,mm_rate:m>0?Number((d*1e3/m).toFixed(2)):0,touches:l,clicks:u,hold_n:i.n,hold_mean:Math.round(i.mean),hold_std:Math.round(ge(i)),teleport:v,wheel:y,scroll_px:Math.round(S),keydowns:b,input_chars:T,ik_cv:o.mean>0?Number((ge(o)/o.mean).toFixed(2)):0,backspaces:I,gaps:[...a],reduced_motion:c,kb_nav:_,renderer:r,vp:[(E=n==null?void 0:n.innerWidth)!=null?E:0,(k=n==null?void 0:n.innerHeight)!=null?k:0],dpr:(n==null?void 0:n.devicePixelRatio)||1}},stop(){e.removeEventListener("mousemove",N,p),e.removeEventListener("touchstart",K,p),e.removeEventListener("touchmove",x,p),e.removeEventListener("mousedown",$,p),e.removeEventListener("mouseup",G,p),e.removeEventListener("click",W,p),e.removeEventListener("wheel",x,p),e.removeEventListener("keydown",F,p),e.removeEventListener("input",B,p),e.removeEventListener("visibilitychange",q),n==null||n.removeEventListener("scroll",j,p)}}}var Ke="section, header, footer, nav, main > div, [data-sentient-section]",$e=2e4,ee="__session__";function Ge(e){let t=Array.from(e.querySelectorAll(Ke)),n=t.filter(i=>t.filter(o=>o!==i&&i.contains(o)).length<2);return n.filter(i=>!n.some(o=>o!==i&&o.contains(i)))}function We(e,t,n,i){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:i})}).catch(()=>{})}catch(o){}}var Q=()=>{};function ye(e,t){var L,M,w,R,N,K,$,G,W,x,j,F,B,q,p;let n=(L=t.doc)!=null?L:typeof document!="undefined"?document:void 0;if(!n||typeof IntersectionObserver=="undefined"||ae()||!t.apiKey||!t.apiKey.startsWith("pk_"))return Q;let i=((M=t.apiBase)!=null?M:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),o=Ge(n);if(o.length===0)return Q;let a=new Map,d=[];for(let r of o){let c=(N=[(R=t.sectionTypes)==null?void 0:R[(w=r.getAttribute("data-sentient-id"))!=null?w:""],r.getAttribute("data-sentient-type")].find(k=>Y.includes(k)))!=null?N:null,g=H(r),f=($=c!=null?c:(K=t.typeOf)==null?void 0:K.call(t,r))!=null?$:U(g).type,s=de(r,n),m=s?`nc-${f}-${(0,me.fnv1a)(JSON.stringify({id:(G=s.id)!=null?G:null,dataAttr:(W=s.dataAttr)!=null?W:null,selector:(x=s.selector)!=null?x:null})).toString(36)}`:`nc-${f}`;a.set(r,m);let E=X.filter(([,k])=>k.test(g.bodyText)).map(([k])=>k);d.push(J(C({componentId:m,semanticType:f,source:c?"markup":"auto"},s?{locator:s}:{}),{observation:C(C({tag:g.tag,idClass:g.idClass.slice(0,200),headingText:g.headingText,textLength:g.textLength,actionCount:g.actionCount},g.ariaRole?{ariaRole:g.ariaRole}:{}),E.length>0?{patternFlags:E}:{})}))}let l=(q=(B=(F=(j=n.defaultView)!=null?j:typeof window!="undefined"?window:void 0)==null?void 0:F.location)==null?void 0:B.pathname)!=null?q:"/";We(t.apiKey,i,l,d);let u=fe(n),v=()=>{let r;try{r=u.snapshot()}catch(c){return}try{e.track({projectId:t.apiKey,componentId:ee,eventType:"interaction_stats",payload:r})}catch(c){}},y=new Map,S=r=>{let c=y.get(r);return c||(c={ms:0,scroll:0,enterAt:null,intersecting:!1},y.set(r,c)),c},b=new IntersectionObserver(r=>{for(let c of r){let g=a.get(c.target);if(!g)continue;let f=S(g);c.isIntersecting?(f.intersecting=!0,f.enterAt=Date.now(),c.intersectionRatio>f.scroll&&(f.scroll=c.intersectionRatio)):(f.intersecting=!1,f.enterAt!=null&&(f.ms+=Date.now()-f.enterAt,f.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let r of a.keys())b.observe(r);let T=(r=!1)=>{var g;let c=Date.now();for(let[f,s]of y)if(s.enterAt!=null&&(s.ms+=c-s.enterAt,s.enterAt=null),!(s.ms<=0)){try{e.track({projectId:t.apiKey,componentId:f,eventType:"dwell",payload:{dwell_time:Math.round(s.ms),scroll_depth:Number(s.scroll.toFixed(2))}})}catch(m){}s.ms=0}if(v(),r)try{(g=e.flush)==null||g.call(e)}catch(f){}},I=()=>{if(n.hidden)T(!0);else{let r=Date.now();for(let c of y.values())c.intersecting&&(c.enterAt=r)}},_=!1,O=r=>{if(T(!0),r!=null&&r.persisted){_=!0;return}try{b.disconnect()}catch(c){}},D=r=>{if(!(r!=null&&r.persisted)||!_)return;_=!1;let c=Date.now();for(let g of y.values())g.enterAt=g.intersecting&&!n.hidden?c:null};n.addEventListener("visibilitychange",I);let h=(p=n.defaultView)!=null?p:typeof window!="undefined"?window:void 0;h==null||h.addEventListener("pagehide",O),h==null||h.addEventListener("pageshow",D);let P=setInterval(()=>{if(n.hidden||_)return;T();let r=Date.now();for(let c of y.values())c.intersecting&&(c.enterAt=r)},$e),A=[];return t.microSignals&&[...a.entries()].forEach(([r,c],g)=>{A.push(ie((f,s={})=>{try{e.track({projectId:t.apiKey,componentId:c,eventType:"micro_signal",payload:C({signalType:f},s)})}catch(m){}},r,void 0,{tabLoss:g===0}))}),()=>{T(!0),clearInterval(P),u.stop(),n.removeEventListener("visibilitychange",I),h==null||h.removeEventListener("pagehide",O),h==null||h.removeEventListener("pageshow",D);for(let r of A)r();try{b.disconnect()}catch(r){}}}0&&(module.exports={INTERACTION_STATS_COMPONENT,SEMANTIC_TYPES,classifyFeatures,classifySection,featuresFromElement,startEngagementCapture});
2
2
  //# sourceMappingURL=index-engagement.js.map