@sentientui/core 0.21.3 → 0.22.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.
@@ -207,7 +207,7 @@ type Assignment = {
207
207
  type AssignmentCache = {
208
208
  get(componentId: string, segment: string): Assignment | null;
209
209
  set(componentId: string, segment: string, assignment: Assignment): void;
210
- invalidate(componentId: string): void;
210
+ /** Drops every entry, memory and localStorage — the forget-me path. */
211
211
  clear(): void;
212
212
  };
213
213
 
@@ -242,8 +242,6 @@ type GraphClient = {
242
242
  /** One-shot batch sync of all current page nodes to the backend. */
243
243
  syncOnce(): void;
244
244
  snapshot(): GraphSnapshot;
245
- serialize(): string;
246
- restore(data: string): void;
247
245
  destroy(): void;
248
246
  };
249
247
  /**
@@ -368,6 +366,15 @@ declare function attachMicroSignalDetectors(emit: MicroSignalEmitter, node: Elem
368
366
  tabLoss?: boolean;
369
367
  }): () => void;
370
368
 
369
+ /**
370
+ * @internal Wires an alternate entry point's init as grantConsent()'s upgrade
371
+ * path for `apiKey`. The /graph entry calls this when its init is gated on
372
+ * consent: without it, grantConsent() upgraded through the LEAN init, so a
373
+ * graph-configured page granted consent but never mounted the scanner (the
374
+ * graph resources exist only in the /graph entry). No-op unless the entry is
375
+ * actually upgradeable — DNT-blocked and local entries register no hook.
376
+ */
377
+ declare function _registerConsentUpgradeInit(apiKey: string, reinit: (config: SentientConfig) => SentientClient): void;
371
378
  type SentientConfig = {
372
379
  apiKey: string;
373
380
  context: 'landing' | 'ecommerce' | 'saas' | 'marketplace';
@@ -612,4 +619,4 @@ declare function grantConsent(apiKey?: string): void;
612
619
  */
613
620
  declare function init(config: SentientConfig): SentientClient;
614
621
 
615
- export { type MicroSignalType as $, type AssignResult as A, BLOCK_ALIGNS as B, type ComponentGoalOptions as C, type ComponentWeightEntry as D, type CompoundLocator as E, type DecideInput as F, type DecideOutcome as G, type DecisionSnapshot as H, type EventQueue as I, type EventType as J, type GoalDefinition as K, type GoalOptions as L, type GraphClient as M, type GraphConfig as N, type GraphSnapshot as O, type GridBlock as P, type HeadingBlock as Q, type ImageBlock as R, LEGACY_SESSION_COOKIE_NAME as S, LOCAL_MODE_BANNER as T, type LinkBlock as U, MAX_BLOCK_ARMS as V, MAX_BLOCK_CHILDREN as W, MAX_BLOCK_DEPTH as X, MAX_BLOCK_NODES as Y, MAX_BLOCK_TEXT_LEN as Z, type MicroSignalEmitter as _, type Assignment as a, PROD_KEYLESS_ERROR as a0, type PageNode as a1, type QueueConfig as a2, SNAPSHOT_STORAGE_KEY_PREFIX as a3, type SectionMapEntry as a4, type SentientClient as a5, type SentientConfig as a6, type SentientEvent as a7, type SessionConfig as a8, type SessionManager as a9, type SitePalette as aa, type SlotConfigEntry as ab, type SlotOps as ac, type SpacerBlock as ad, type StackBlock as ae, type TextBlock as af, type WeightEntry as ag, attachMicroSignalDetectors as ah, grantConsent as ai, init as aj, isDoNotTrackEnabled as ak, readSnapshot as al, renderPrePaintScript as am, sanitizePageUrl as an, sessionCookieName as ao, writeSnapshot as ap, type AssignmentCache as b, BLOCK_EMPHASES as c, BLOCK_FITS as d, BLOCK_GAPS as e, BLOCK_GRID_COLUMNS as f, BLOCK_HEADING_LEVELS as g, BLOCK_JUSTIFIES as h, BLOCK_RATIOS as i, BLOCK_SIZES as j, BLOCK_TEXT_ALIGNS as k, BLOCK_TONES as l, BLOCK_WEIGHTS as m, type BadgeBlock as n, type BlockAlign as o, type BlockEmphasis as p, type BlockFit as q, type BlockGap as r, type BlockJustify as s, type BlockNode as t, type BlockRatio as u, type BlockSize as v, type BlockTextAlign as w, type BlockTone as x, type BlockWeight as y, type ButtonBlock as z };
622
+ export { type MicroSignalType as $, type AssignResult as A, BLOCK_ALIGNS as B, type ComponentGoalOptions as C, type ComponentWeightEntry as D, type CompoundLocator as E, type DecideInput as F, type DecideOutcome as G, type DecisionSnapshot as H, type EventQueue as I, type EventType as J, type GoalDefinition as K, type GoalOptions as L, type GraphClient as M, type GraphConfig as N, type GraphSnapshot as O, type GridBlock as P, type HeadingBlock as Q, type ImageBlock as R, LEGACY_SESSION_COOKIE_NAME as S, LOCAL_MODE_BANNER as T, type LinkBlock as U, MAX_BLOCK_ARMS as V, MAX_BLOCK_CHILDREN as W, MAX_BLOCK_DEPTH as X, MAX_BLOCK_NODES as Y, MAX_BLOCK_TEXT_LEN as Z, type MicroSignalEmitter as _, type Assignment as a, PROD_KEYLESS_ERROR as a0, type PageNode as a1, type QueueConfig as a2, SNAPSHOT_STORAGE_KEY_PREFIX as a3, type SectionMapEntry as a4, type SentientClient as a5, type SentientConfig as a6, type SentientEvent as a7, type SessionConfig as a8, type SessionManager as a9, type SitePalette as aa, type SlotConfigEntry as ab, type SlotOps as ac, type SpacerBlock as ad, type StackBlock as ae, type TextBlock as af, type WeightEntry as ag, _registerConsentUpgradeInit as ah, attachMicroSignalDetectors as ai, grantConsent as aj, init as ak, isDoNotTrackEnabled as al, readSnapshot as am, renderPrePaintScript as an, sanitizePageUrl as ao, sessionCookieName as ap, writeSnapshot as aq, type AssignmentCache as b, BLOCK_EMPHASES as c, BLOCK_FITS as d, BLOCK_GAPS as e, BLOCK_GRID_COLUMNS as f, BLOCK_HEADING_LEVELS as g, BLOCK_JUSTIFIES as h, BLOCK_RATIOS as i, BLOCK_SIZES as j, BLOCK_TEXT_ALIGNS as k, BLOCK_TONES as l, BLOCK_WEIGHTS as m, type BadgeBlock as n, type BlockAlign as o, type BlockEmphasis as p, type BlockFit as q, type BlockGap as r, type BlockJustify as s, type BlockNode as t, type BlockRatio as u, type BlockSize as v, type BlockTextAlign as w, type BlockTone as x, type BlockWeight as y, type ButtonBlock as z };
@@ -1,2 +1,2 @@
1
- "use strict";var v=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var j=(t,e,n)=>e in t?v(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,k=(t,e)=>{for(var n in e||(e={}))F.call(e,n)&&j(t,n,e[n]);if(W)for(var n of W(e))Y.call(e,n)&&j(t,n,e[n]);return t};var z=(t,e)=>{for(var n in e)v(t,n,{get:e[n],enumerable:!0})},J=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of V(e))!F.call(t,a)&&a!==n&&v(t,a,{get:()=>e[a],enumerable:!(i=Q(e,a))||i.enumerable});return t};var X=t=>J(v({},"__esModule",{value:!0}),t);var ae={};z(ae,{SEMANTIC_TYPES:()=>E,classifyFeatures:()=>I,classifySection:()=>C,featuresFromElement:()=>x,startEngagementCapture:()=>H});module.exports=X(ae);var E=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Z=[["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]],ee=[["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 te(t){var n;let e=t.querySelector("h1, h2, h3");return((n=e==null?void 0:e.textContent)!=null?n:"").slice(0,160)}function I(t){if(t.tag==="nav"||t.tag==="footer")return{type:"navigation",strength:"weak"};let e=`${t.idClass} ${t.headingText}`.toLowerCase();for(let[n,i]of Z)if(i.test(e))return{type:n,strength:"strong"};for(let[n,i]of ee)if(i.test(t.bodyText))return{type:n,strength:"strong"};return t.actionCount>=1&&t.textLength>0&&t.textLength<200?{type:"cta",strength:"weak"}:t.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(e)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function x(t){var n,i;let e=((n=t.textContent)!=null?n:"").replace(/\s+/g," ").trim();return{tag:t.tagName.toLowerCase(),idClass:`${t.id} ${String((i=t.className)!=null?i:"")}`,headingText:te(t),bodyText:e.slice(0,2e3),actionCount:t.querySelectorAll('a, button, [role="button"]').length,textLength:e.length}}function C(t){return I(x(t)).type}var ne=require("@sentientui/policy");function U(t,e,n,i){let a=[];{let l=!1,c=[],p=()=>{if(l)return;let m=Date.now();for(c.push(m);c.length>0&&m-c[0]>500;)c.shift();c.length>=3&&(l=!0,t("rage_click"))};e.addEventListener("click",p),a.push(()=>e.removeEventListener("click",p))}{let d=!1,g=l=>{if(d||!(l.target instanceof Node)||!e.contains(l.target)&&e!==l.target)return;d=!0;let c=typeof window!="undefined"?window.getSelection():null,p=c?c.toString().length:0;t("text_copy",{selectionLength:p})};document.addEventListener("copy",g),a.push(()=>document.removeEventListener("copy",g))}{let d=!1,g=!1,l=null,c=()=>{l!==null&&(clearTimeout(l),l=null)},p=()=>{d||!g||(c(),l=setTimeout(()=>{!d&&g&&(d=!0,t("scroll_hesitation"))},3e3))},m=()=>{c(),p()},w=b=>{for(let S of b)g=S.intersectionRatio>.3,g?p():c()},y=new IntersectionObserver(w,{threshold:[.3]});y.observe(e),window.addEventListener("scroll",m,{passive:!0}),a.push(()=>{y.disconnect(),window.removeEventListener("scroll",m),c()})}if((i==null?void 0:i.tabLoss)!==!1){let d=!1,g=n!=null?n:Date.now(),l=()=>{if(d||document.visibilityState!=="hidden")return;let c=Date.now()-g;c<15e3&&(d=!0,t("tab_loss",{timeOnPage:c}))};document.addEventListener("visibilitychange",l),a.push(()=>document.removeEventListener("visibilitychange",l))}return()=>{for(let d of a)d()}}function B(){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")}var se="section, header, footer, nav, main > div, [data-sentient-section]",oe=2e4;function re(t){let e=Array.from(t.querySelectorAll(se)),n=e.filter(i=>e.filter(a=>a!==i&&i.contains(a)).length<2);return n.filter(i=>!n.some(a=>a!==i&&a.contains(i)))}function ie(t,e,n,i){try{fetch(`${e}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${t}`},body:JSON.stringify({pageUrl:n,sections:i})}).catch(()=>{})}catch(a){}}var T=()=>{};function H(t,e){var A,D,M,P,N,L,K,G,$;let n=(A=e.doc)!=null?A:typeof document!="undefined"?document:void 0;if(!n||typeof IntersectionObserver=="undefined"||B()||!e.apiKey)return T;let i=((D=e.apiBase)!=null?D:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),a=re(n);if(a.length===0)return T;let d=new Map,g=new Map,l=new Map;for(let s of a){let o=s.getAttribute("data-sentient-type"),r=o&&E.includes(o)?o:null,u=(P=r!=null?r:(M=e.typeOf)==null?void 0:M.call(e,s))!=null?P:C(s),h=`nc-${u}`;d.set(s,h),g.set(h,u),r?l.set(h,"markup"):l.has(h)||l.set(h,"auto")}let c=(G=(K=(L=(N=n.defaultView)!=null?N:typeof window!="undefined"?window:void 0)==null?void 0:L.location)==null?void 0:K.pathname)!=null?G:"/";ie(e.apiKey,i,c,[...g.entries()].map(([s,o])=>{var r;return{componentId:s,semanticType:o,source:(r=l.get(s))!=null?r:"auto"}}));let p=new Map,m=s=>{let o=p.get(s);return o||(o={ms:0,scroll:0,enterAt:null,intersecting:!1},p.set(s,o)),o},w=new IntersectionObserver(s=>{for(let o of s){let r=d.get(o.target);if(!r)continue;let u=m(r);o.isIntersecting?(u.intersecting=!0,u.enterAt=Date.now(),o.intersectionRatio>u.scroll&&(u.scroll=o.intersectionRatio)):(u.intersecting=!1,u.enterAt!=null&&(u.ms+=Date.now()-u.enterAt,u.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let s of d.keys())w.observe(s);let y=()=>{let s=Date.now();for(let[o,r]of p)if(r.enterAt!=null&&(r.ms+=s-r.enterAt,r.enterAt=null),!(r.ms<=0)){try{t.track({projectId:e.apiKey,componentId:o,eventType:"dwell",payload:{dwell_time:Math.round(r.ms),scroll_depth:Number(r.scroll.toFixed(2))}})}catch(u){}r.ms=0}},b=()=>{if(n.hidden)y();else{let s=Date.now();for(let o of p.values())o.intersecting&&(o.enterAt=s)}},S=!1,R=s=>{if(y(),s!=null&&s.persisted){S=!0;return}try{w.disconnect()}catch(o){}},O=s=>{if(!(s!=null&&s.persisted)||!S)return;S=!1;let o=Date.now();for(let r of p.values())r.enterAt=r.intersecting&&!n.hidden?o:null};n.addEventListener("visibilitychange",b);let f=($=n.defaultView)!=null?$:typeof window!="undefined"?window:void 0;f==null||f.addEventListener("pagehide",R),f==null||f.addEventListener("pageshow",O);let q=setInterval(()=>{if(n.hidden||S)return;y();let s=Date.now();for(let o of p.values())o.intersecting&&(o.enterAt=s)},oe),_=[];return e.microSignals&&[...d.entries()].forEach(([s,o],r)=>{_.push(U((u,h={})=>{try{t.track({projectId:e.apiKey,componentId:o,eventType:"micro_signal",payload:k({signalType:u},h)})}catch(le){}},s,void 0,{tabLoss:r===0}))}),()=>{y(),clearInterval(q),n.removeEventListener("visibilitychange",b),f==null||f.removeEventListener("pagehide",R),f==null||f.removeEventListener("pageshow",O);for(let s of _)s();try{w.disconnect()}catch(s){}}}0&&(module.exports={SEMANTIC_TYPES,classifyFeatures,classifySection,featuresFromElement,startEngagementCapture});
1
+ "use strict";var b=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var B=(t,e,n)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,T=(t,e)=>{for(var n in e||(e={}))j.call(e,n)&&B(t,n,e[n]);if(W)for(var n of W(e))Y.call(e,n)&&B(t,n,e[n]);return t};var z=(t,e)=>{for(var n in e)b(t,n,{get:e[n],enumerable:!0})},J=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of V(e))!j.call(t,a)&&a!==n&&b(t,a,{get:()=>e[a],enumerable:!(r=Q(e,a))||r.enumerable});return t};var X=t=>J(b({},"__esModule",{value:!0}),t);var ae={};z(ae,{SEMANTIC_TYPES:()=>E,classifyFeatures:()=>R,classifySection:()=>C,featuresFromElement:()=>I,startEngagementCapture:()=>H});module.exports=X(ae);var E=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Z=[["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]],ee=[["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 te(t){var n;let e=t.querySelector("h1, h2, h3");return((n=e==null?void 0:e.textContent)!=null?n:"").slice(0,160)}function R(t){if(t.tag==="nav"||t.tag==="footer")return{type:"navigation",strength:"weak"};let e=`${t.idClass} ${t.headingText}`.toLowerCase();for(let[n,r]of Z)if(r.test(e))return{type:n,strength:"strong"};for(let[n,r]of ee)if(r.test(t.bodyText))return{type:n,strength:"strong"};return t.actionCount>=1&&t.textLength>0&&t.textLength<200?{type:"cta",strength:"weak"}:t.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(e)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function I(t){var n,r;let e=((n=t.textContent)!=null?n:"").replace(/\s+/g," ").trim();return{tag:t.tagName.toLowerCase(),idClass:`${t.id} ${String((r=t.className)!=null?r:"")}`,headingText:te(t),bodyText:e.slice(0,2e3),actionCount:t.querySelectorAll('a, button, [role="button"]').length,textLength:e.length}}function C(t){return R(I(t)).type}var ne=require("@sentientui/policy");function U(t,e,n,r){let a=[];{let l=!1,c=[],p=()=>{if(l)return;let m=Date.now();for(c.push(m);c.length>0&&m-c[0]>500;)c.shift();c.length>=3&&(l=!0,t("rage_click"))};e.addEventListener("click",p),a.push(()=>e.removeEventListener("click",p))}{let d=!1,g=l=>{if(d||!(l.target instanceof Node)||!e.contains(l.target)&&e!==l.target)return;d=!0;let c=typeof window!="undefined"?window.getSelection():null,p=c?c.toString().length:0;t("text_copy",{selectionLength:p})};document.addEventListener("copy",g),a.push(()=>document.removeEventListener("copy",g))}{let d=!1,g=!1,l=null,c=()=>{l!==null&&(clearTimeout(l),l=null)},p=()=>{d||!g||(c(),l=setTimeout(()=>{!d&&g&&(d=!0,t("scroll_hesitation"))},3e3))},m=()=>{c(),p()},w=v=>{for(let S of v)g=S.intersectionRatio>.3,g?p():c()},y=new IntersectionObserver(w,{threshold:[.3]});y.observe(e),window.addEventListener("scroll",m,{passive:!0}),a.push(()=>{y.disconnect(),window.removeEventListener("scroll",m),c()})}if((r==null?void 0:r.tabLoss)!==!1){let d=!1,g=n!=null?n:Date.now(),l=()=>{if(d||document.visibilityState!=="hidden")return;let c=Date.now()-g;c<15e3&&(d=!0,t("tab_loss",{timeOnPage:c}))};document.addEventListener("visibilitychange",l),a.push(()=>document.removeEventListener("visibilitychange",l))}return()=>{for(let d of a)d()}}function F(){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")}var se="section, header, footer, nav, main > div, [data-sentient-section]",oe=2e4;function ie(t){let e=Array.from(t.querySelectorAll(se)),n=e.filter(r=>e.filter(a=>a!==r&&r.contains(a)).length<2);return n.filter(r=>!n.some(a=>a!==r&&a.contains(r)))}function re(t,e,n,r){try{fetch(`${e}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${t}`},body:JSON.stringify({pageUrl:n,sections:r})}).catch(()=>{})}catch(a){}}var k=()=>{};function H(t,e){var O,D,P,M,N,K,L,G,$;let n=(O=e.doc)!=null?O:typeof document!="undefined"?document:void 0;if(!n||typeof IntersectionObserver=="undefined"||F()||!e.apiKey||!e.apiKey.startsWith("pk_"))return k;let r=((D=e.apiBase)!=null?D:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),a=ie(n);if(a.length===0)return k;let d=new Map,g=new Map,l=new Map;for(let s of a){let o=s.getAttribute("data-sentient-type"),i=o&&E.includes(o)?o:null,u=(M=i!=null?i:(P=e.typeOf)==null?void 0:P.call(e,s))!=null?M:C(s),h=`nc-${u}`;d.set(s,h),g.set(h,u),i?l.set(h,"markup"):l.has(h)||l.set(h,"auto")}let c=(G=(L=(K=(N=n.defaultView)!=null?N:typeof window!="undefined"?window:void 0)==null?void 0:K.location)==null?void 0:L.pathname)!=null?G:"/";re(e.apiKey,r,c,[...g.entries()].map(([s,o])=>{var i;return{componentId:s,semanticType:o,source:(i=l.get(s))!=null?i:"auto"}}));let p=new Map,m=s=>{let o=p.get(s);return o||(o={ms:0,scroll:0,enterAt:null,intersecting:!1},p.set(s,o)),o},w=new IntersectionObserver(s=>{for(let o of s){let i=d.get(o.target);if(!i)continue;let u=m(i);o.isIntersecting?(u.intersecting=!0,u.enterAt=Date.now(),o.intersectionRatio>u.scroll&&(u.scroll=o.intersectionRatio)):(u.intersecting=!1,u.enterAt!=null&&(u.ms+=Date.now()-u.enterAt,u.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let s of d.keys())w.observe(s);let y=()=>{let s=Date.now();for(let[o,i]of p)if(i.enterAt!=null&&(i.ms+=s-i.enterAt,i.enterAt=null),!(i.ms<=0)){try{t.track({projectId:e.apiKey,componentId:o,eventType:"dwell",payload:{dwell_time:Math.round(i.ms),scroll_depth:Number(i.scroll.toFixed(2))}})}catch(u){}i.ms=0}},v=()=>{if(n.hidden)y();else{let s=Date.now();for(let o of p.values())o.intersecting&&(o.enterAt=s)}},S=!1,x=s=>{if(y(),s!=null&&s.persisted){S=!0;return}try{w.disconnect()}catch(o){}},_=s=>{if(!(s!=null&&s.persisted)||!S)return;S=!1;let o=Date.now();for(let i of p.values())i.enterAt=i.intersecting&&!n.hidden?o:null};n.addEventListener("visibilitychange",v);let f=($=n.defaultView)!=null?$:typeof window!="undefined"?window:void 0;f==null||f.addEventListener("pagehide",x),f==null||f.addEventListener("pageshow",_);let q=setInterval(()=>{if(n.hidden||S)return;y();let s=Date.now();for(let o of p.values())o.intersecting&&(o.enterAt=s)},oe),A=[];return e.microSignals&&[...d.entries()].forEach(([s,o],i)=>{A.push(U((u,h={})=>{try{t.track({projectId:e.apiKey,componentId:o,eventType:"micro_signal",payload:T({signalType:u},h)})}catch(le){}},s,void 0,{tabLoss:i===0}))}),()=>{y(),clearInterval(q),n.removeEventListener("visibilitychange",v),f==null||f.removeEventListener("pagehide",x),f==null||f.removeEventListener("pageshow",_);for(let s of A)s();try{w.disconnect()}catch(s){}}}0&&(module.exports={SEMANTIC_TYPES,classifyFeatures,classifySection,featuresFromElement,startEngagementCapture});
2
2
  //# sourceMappingURL=index-engagement.js.map