@sentientui/core 0.33.0 → 0.34.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/dist/chunk-DGRAS5VP.mjs +2 -0
- package/dist/chunk-DGRAS5VP.mjs.map +1 -0
- package/dist/chunk-G6VP7HGJ.mjs +2 -0
- package/dist/chunk-G6VP7HGJ.mjs.map +1 -0
- package/dist/chunk-NCLBL5V3.mjs +2 -0
- package/dist/chunk-NCLBL5V3.mjs.map +1 -0
- package/dist/{index-COl_pfNm.d.cts → index-DX-MuX8O.d.ts} +43 -4
- package/dist/{index-CgkImSaM.d.ts → index-DnQbmMkx.d.cts} +43 -4
- package/dist/index-engagement.js +1 -1
- package/dist/index-engagement.js.map +1 -1
- package/dist/index-engagement.mjs +1 -1
- package/dist/index-engagement.mjs.map +1 -1
- package/dist/index-graph.d.cts +6 -4
- package/dist/index-graph.d.ts +6 -4
- package/dist/index-graph.js +1 -1
- package/dist/index-graph.js.map +1 -1
- package/dist/index-graph.mjs +1 -1
- package/dist/index-graph.mjs.map +1 -1
- package/dist/index-local.d.cts +4 -2
- package/dist/index-local.d.ts +4 -2
- package/dist/index-region.d.cts +40 -0
- package/dist/index-region.d.ts +40 -0
- package/dist/index-region.js +2 -0
- package/dist/index-region.js.map +1 -0
- package/dist/index-region.mjs +2 -0
- package/dist/index-region.mjs.map +1 -0
- package/dist/index-server.d.cts +15 -2
- package/dist/index-server.d.ts +15 -2
- package/dist/index-server.js +1 -1
- package/dist/index-server.js.map +1 -1
- package/dist/index-server.mjs +1 -1
- package/dist/index-server.mjs.map +1 -1
- package/dist/index-style-sample.d.cts +12 -0
- package/dist/index-style-sample.d.ts +12 -0
- package/dist/index-style-sample.js +2 -0
- package/dist/index-style-sample.js.map +1 -0
- package/dist/index-style-sample.mjs +2 -0
- package/dist/index-style-sample.mjs.map +1 -0
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/region-skeleton-D2ahkcbe.d.cts +61 -0
- package/dist/region-skeleton-D2ahkcbe.d.ts +61 -0
- package/dist/session-meta-B0sXgtFN.d.ts +226 -0
- package/dist/session-meta-Dk8ivs-l.d.cts +226 -0
- package/dist/style-vocabulary-BqviEw9O.d.cts +285 -0
- package/dist/style-vocabulary-BqviEw9O.d.ts +285 -0
- package/package.json +11 -1
- package/dist/chunk-EVYMV2C6.mjs +0 -2
- package/dist/chunk-EVYMV2C6.mjs.map +0 -1
- package/dist/session-meta-DydKfQiR.d.cts +0 -416
- package/dist/session-meta-DydKfQiR.d.ts +0 -416
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=/(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\([^()]*\)|#[0-9a-f]{3,8}\b/gi,c=/^rgba?\(\s*[\d.]+[,\s]+[\d.]+[,\s]+[\d.]+(?:[,\s/]+[\d.]+%?)?\s*\)$/i,a;function d(e){if(a!==void 0)return a;try{let r=e.createElement("canvas");r.width=r.height=1,a=r.getContext("2d",{willReadFrequently:!0})}catch(r){a=null}return a}function f(e,r){let t=(e!=null?e:"").trim();if(t===""||t==="transparent")return t==="transparent"?"rgba(0, 0, 0, 0)":"";if(c.test(t)||/^#[0-9a-f]{3,8}$/i.test(t))return t;let n=d(r);if(!n)return"";try{if(n.fillStyle="#010203",n.fillStyle=t,String(n.fillStyle).toLowerCase()==="#010203"&&t.toLowerCase()!=="#010203")return"";n.clearRect(0,0,1,1),n.fillRect(0,0,1,1);let[i,l,s,u]=n.getImageData(0,0,1,1).data;return u===255?`rgb(${i}, ${l}, ${s})`:`rgba(${i}, ${l}, ${s}, ${Math.round(u/255*1e3)/1e3})`}catch(i){return""}}function g(e,r){var t;return!e||e==="none"||!/gradient/i.test(e)?[]:((t=e.match(o))!=null?t:[]).map(n=>f(n,r)).filter(n=>n!=="")}export{f as a,g as b};
|
|
2
|
+
//# sourceMappingURL=chunk-G6VP7HGJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/css-color.ts"],"sourcesContent":["// Browser colour normalization for capture (spec 2026-09-23 §4.1/§4.2).\n// Chrome reports Tailwind v4 colours as `lab(…)` / `oklch(…)`, and the\n// contrast math, the server's colour check and the prompts all read `rgb()`.\n// Without this, a Tailwind v4 site's blue primary button had no measurable\n// fill (captured as a secondary button), its grey body text had no colour\n// (unusable under the contrast gate) and a slate gradient lost a stop —\n// found on bodyshopmanchester.co.uk, 2026-09-23.\n//\n// The browser is the one colour-space converter that is always right, so the\n// colour is painted to a 1×1 canvas and read back. No canvas (jsdom, some\n// privacy modes) → '' for non-rgb input: unknown, which every consumer\n// already treats as \"not measured\" rather than guessing.\n\nconst FN = /(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\\([^()]*\\)|#[0-9a-f]{3,8}\\b/gi;\nconst RGB = /^rgba?\\(\\s*[\\d.]+[,\\s]+[\\d.]+[,\\s]+[\\d.]+(?:[,\\s/]+[\\d.]+%?)?\\s*\\)$/i;\n\nlet ctx: CanvasRenderingContext2D | null | undefined;\n\nfunction context(doc: Document): CanvasRenderingContext2D | null {\n if (ctx !== undefined) return ctx;\n try {\n const c = doc.createElement('canvas');\n c.width = c.height = 1;\n ctx = c.getContext('2d', { willReadFrequently: true }) as CanvasRenderingContext2D | null;\n } catch {\n ctx = null;\n }\n return ctx;\n}\n\n/** `rgb(r, g, b)` / `rgba(r, g, b, a)` for any CSS colour; '' when unknown. */\nexport function toRgb(color: string | null | undefined, doc: Document): string {\n const c = (color ?? '').trim();\n if (c === '' || c === 'transparent') return c === 'transparent' ? 'rgba(0, 0, 0, 0)' : '';\n if (RGB.test(c) || /^#[0-9a-f]{3,8}$/i.test(c)) return c;\n const g = context(doc);\n if (!g) return '';\n try {\n // A sentinel detects an unparsable value: assigning garbage to fillStyle\n // is silently ignored, which would otherwise read back the sentinel.\n g.fillStyle = '#010203';\n g.fillStyle = c;\n if (String(g.fillStyle).toLowerCase() === '#010203' && c.toLowerCase() !== '#010203') return '';\n g.clearRect(0, 0, 1, 1);\n g.fillRect(0, 0, 1, 1);\n const [r, gr, b, a] = g.getImageData(0, 0, 1, 1).data as unknown as number[];\n return a === 255 ? `rgb(${r}, ${gr}, ${b})` : `rgba(${r}, ${gr}, ${b}, ${Math.round((a! / 255) * 1000) / 1000})`;\n } catch {\n return '';\n }\n}\n\n/** Colour stops of a `background-image` gradient, normalized; [] for none. */\nexport function gradientStopsRgb(img: string | null | undefined, doc: Document): string[] {\n if (!img || img === 'none' || !/gradient/i.test(img)) return [];\n return (img.match(FN) ?? []).map((s) => toRgb(s, doc)).filter((s) => s !== '');\n}\n\n/** Test seam: forget the cached canvas context. */\nexport function resetColorCanvas(): void {\n ctx = undefined;\n}\n"],"mappings":"AAaA,IAAMA,EAAK,6EACLC,EAAM,uEAERC,EAEJ,SAASC,EAAQC,EAAgD,CAC/D,GAAIF,IAAQ,OAAW,OAAOA,EAC9B,GAAI,CACF,IAAMG,EAAID,EAAI,cAAc,QAAQ,EACpCC,EAAE,MAAQA,EAAE,OAAS,EACrBH,EAAMG,EAAE,WAAW,KAAM,CAAE,mBAAoB,EAAK,CAAC,CACvD,OAAQC,EAAA,CACNJ,EAAM,IACR,CACA,OAAOA,CACT,CAGO,SAASK,EAAMC,EAAkCJ,EAAuB,CAC7E,IAAMC,GAAKG,GAAA,KAAAA,EAAS,IAAI,KAAK,EAC7B,GAAIH,IAAM,IAAMA,IAAM,cAAe,OAAOA,IAAM,cAAgB,mBAAqB,GACvF,GAAIJ,EAAI,KAAKI,CAAC,GAAK,oBAAoB,KAAKA,CAAC,EAAG,OAAOA,EACvD,IAAMI,EAAIN,EAAQC,CAAG,EACrB,GAAI,CAACK,EAAG,MAAO,GACf,GAAI,CAKF,GAFAA,EAAE,UAAY,UACdA,EAAE,UAAYJ,EACV,OAAOI,EAAE,SAAS,EAAE,YAAY,IAAM,WAAaJ,EAAE,YAAY,IAAM,UAAW,MAAO,GAC7FI,EAAE,UAAU,EAAG,EAAG,EAAG,CAAC,EACtBA,EAAE,SAAS,EAAG,EAAG,EAAG,CAAC,EACrB,GAAM,CAACC,EAAGC,EAAIC,EAAGC,CAAC,EAAIJ,EAAE,aAAa,EAAG,EAAG,EAAG,CAAC,EAAE,KACjD,OAAOI,IAAM,IAAM,OAAOH,CAAC,KAAKC,CAAE,KAAKC,CAAC,IAAM,QAAQF,CAAC,KAAKC,CAAE,KAAKC,CAAC,KAAK,KAAK,MAAOC,EAAK,IAAO,GAAI,EAAI,GAAI,GAC/G,OAAQP,EAAA,CACN,MAAO,EACT,CACF,CAGO,SAASQ,EAAiBC,EAAgCX,EAAyB,CArD1F,IAAAY,EAsDE,MAAI,CAACD,GAAOA,IAAQ,QAAU,CAAC,YAAY,KAAKA,CAAG,EAAU,CAAC,IACtDC,EAAAD,EAAI,MAAMf,CAAE,IAAZ,KAAAgB,EAAiB,CAAC,GAAG,IAAKC,GAAMV,EAAMU,EAAGb,CAAG,CAAC,EAAE,OAAQa,GAAMA,IAAM,EAAE,CAC/E","names":["FN","RGB","ctx","context","doc","c","e","toRgb","color","g","r","gr","b","a","gradientStopsRgb","img","_a","s"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/region-skeleton.ts"],"sourcesContent":["// Region skeleton (spec 2026-09-23 §4.1). The generator used to see a region\n// as its flattened textContent — \"Get in touch WhatsApp photos\" — and wrote a\n// heading + paragraph for what were two buttons. The skeleton is the region's\n// STRUCTURE: every element that carries text, its role, link, emphasis and\n// colour, so generation can write per-element edits and both SDKs can apply\n// them to the developer's own elements.\n//\n// Only the wrapped region is ever read (same scope as baselineText); query\n// strings and hashes never leave the page (tracking ids, sometimes PII).\n\nexport const MAX_SKELETON_NODES = 40;\nexport const MAX_SKELETON_LEAVES = 120;\nexport const MAX_SKELETON_TEXT = 300;\n\nexport type SkeletonRole = 'action' | 'heading' | 'text' | 'label' | 'image';\nexport type SkeletonNode = {\n tag: string;\n role: SkeletonRole;\n level?: 1 | 2 | 3 | 4 | 5 | 6;\n text: string; // joined normalized leaves of this node (image: alt)\n classes: string; // class attribute, whitespace-normalized\n filled?: boolean; // action only\n href?: string; // action only; same-origin → path; else origin+path; never query/hash\n src?: string; // image only; same rule\n color: string; // computed `color`\n group: number; // index of the node owner's parentElement among distinct parents\n restylable: boolean; // snippet: always true; React: set by annotateSkeletonForReact\n};\nexport type RegionSkeleton = {\n v: 1;\n root: { tag: string; classes: string; ambientBg: string | null; ambientBgAlt?: string; ambientText: string };\n nodes: SkeletonNode[];\n leaves: string[]; // normalized non-blank text leaves, document order\n leafToNode: number[]; // leaves[i] belongs to nodes[leafToNode[i]]\n fp: string;\n /** false = the page can't address these elements for per-element edits\n * (React: the region wraps a component whose text the element tree can't\n * see). The capture still describes the region — enough to REDESIGN it,\n * which replaces the whole region — but no Rewrite arm may target it. */\n editable?: false;\n};\nexport type ArmEdits = {\n nodes: Record<string, { text?: string; hidden?: true; like?: number }>;\n order?: Record<string, number[]>;\n};\n/** What the requesting page can render for one slot (decide `render` field). */\nexport type RenderCaps = {\n fp?: string; // omitted = unknown (SSR): server assumes the stored skeleton\n forms: boolean; // a form-arm handler exists\n compose: boolean; // phase 2; always false in phase 1\n authored?: string[]; // phase 3\n content?: boolean; // false = a content arm cannot land (0 or >1 text leaves). Omitted = true.\n children?: boolean; // phase 3: false = no children to render, the first authored key is the baseline. Omitted = true.\n};\n/** How the server serves an `edits` arm (SlotConfigEntry.edits). */\nexport type ServedEdits = { edits: ArmEdits; fp: string; leafToNode: number[] };\n\n// DOM capture lives in ./region-capture.ts, exported from\n// `@sentientui/core/region`: only React and the snippet need it, and it would\n// otherwise ship in the lean entry every plain-JS install downloads.\n"],"mappings":"AAUO,IAAMA,EAAqB,GACrBC,EAAsB,IACtBC,EAAoB","names":["MAX_SKELETON_NODES","MAX_SKELETON_LEAVES","MAX_SKELETON_TEXT"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as SitePalette, a4 as StyleVocabulary } from './style-vocabulary-BqviEw9O.js';
|
|
2
|
+
import { d as SlotConfigEntry, e as SlotDeclInput, b as CompoundLocator } from './session-meta-B0sXgtFN.js';
|
|
3
|
+
import { c as RenderCaps, R as RegionSkeleton } from './region-skeleton-D2ahkcbe.js';
|
|
2
4
|
import { SlotResult } from '@sentientui/policy';
|
|
3
5
|
|
|
4
6
|
/** Manages anonymous session identity with cookie + localStorage layers. */
|
|
@@ -225,6 +227,17 @@ declare function attachMicroSignalDetectors(emit: MicroSignalEmitter, node: Elem
|
|
|
225
227
|
tabLoss?: boolean;
|
|
226
228
|
}): () => void;
|
|
227
229
|
|
|
230
|
+
/** A captured skeleton, or why none could be captured. */
|
|
231
|
+
type SkeletonReport = RegionSkeleton | {
|
|
232
|
+
status: 'too_large' | 'empty' | 'unaddressable';
|
|
233
|
+
};
|
|
234
|
+
/** One authored arm of a hybrid <Adaptive>, as it rendered. */
|
|
235
|
+
type AuthoredArmReport = {
|
|
236
|
+
key: string;
|
|
237
|
+
text?: string;
|
|
238
|
+
skeleton?: RegionSkeleton;
|
|
239
|
+
};
|
|
240
|
+
|
|
228
241
|
/**
|
|
229
242
|
* @internal Wires an alternate entry point's init as grantConsent()'s upgrade
|
|
230
243
|
* path for `apiKey`. The /graph entry calls this when its init is gated on
|
|
@@ -315,6 +328,8 @@ type SentientConfig = {
|
|
|
315
328
|
initialSlotConfig?: Record<string, SlotConfigEntry>;
|
|
316
329
|
/** Site palette decided outside the browser (SSR). Seeds `getSitePalette()`. */
|
|
317
330
|
initialPalette?: SitePalette;
|
|
331
|
+
/** Site styles the SSR decision's Redesign arms borrow. Seeds `getStyleVocabulary()`. */
|
|
332
|
+
initialVocabulary?: StyleVocabulary;
|
|
318
333
|
/**
|
|
319
334
|
* Persona decided during SSR. Takes priority over the html-attribute
|
|
320
335
|
* adoption and the local snapshot.
|
|
@@ -383,6 +398,7 @@ type DecideOutcome = {
|
|
|
383
398
|
goals?: GoalDefinition[];
|
|
384
399
|
sectionMap?: SectionMapEntry[];
|
|
385
400
|
palette?: SitePalette;
|
|
401
|
+
vocabulary?: StyleVocabulary;
|
|
386
402
|
};
|
|
387
403
|
type DecideInput = {
|
|
388
404
|
sections?: string[];
|
|
@@ -398,6 +414,10 @@ type DecideInput = {
|
|
|
398
414
|
/** Registry mode only: `false` omits the snippet bootstrap data (editor goals,
|
|
399
415
|
* section map) the React SDK never reads — two queries per page saved. */
|
|
400
416
|
bootstrap?: false;
|
|
417
|
+
/** Registry mode only: what the page can render per mounted slot. The
|
|
418
|
+
* server narrows each slot's arm space to it before drawing (CONTRACTS §2
|
|
419
|
+
* — an arm the page would refuse still books a trial). */
|
|
420
|
+
render?: Record<string, RenderCaps>;
|
|
401
421
|
/**
|
|
402
422
|
* Caller's build version (e.g. the snippet's `__SNIPPET_VERSION__`), sent
|
|
403
423
|
* as `v` on the wire. Additive/best-effort: the server persists it for
|
|
@@ -482,7 +502,20 @@ type SentientClient = {
|
|
|
482
502
|
* generation can ground its versions in what they replace — sent only on
|
|
483
503
|
* the first report of an id, capped, and the server keeps it only at
|
|
484
504
|
* first registration. */
|
|
485
|
-
reportSlots(slotIds: string[], baselineTexts?: Record<string, string
|
|
505
|
+
reportSlots(slotIds: string[], baselineTexts?: Record<string, string>, baselineSkeletons?: Record<string, SkeletonReport>,
|
|
506
|
+
/** A hybrid <Adaptive>'s authored arms seen on screen (spec 2026-09-23
|
|
507
|
+
* §7.4): recorded for the dashboard and to ground generation. Sent once
|
|
508
|
+
* per (slot, key) per client. */
|
|
509
|
+
authoredArms?: Record<string, AuthoredArmReport[]>): void;
|
|
510
|
+
/** Report a skeleton for a PUBLISHED slot the server flagged `needsSkeleton`
|
|
511
|
+
* (registered before skeletons existed). Once per id per client; the server
|
|
512
|
+
* stores it only while the slot has none. Optional for hand-rolled clients. */
|
|
513
|
+
reportSkeleton?(slotId: string, skeleton: SkeletonReport): void;
|
|
514
|
+
/** A served Rewrite arm could not be applied because the region's markup no
|
|
515
|
+
* longer matches the skeleton it was written for. Batched, deduped per
|
|
516
|
+
* (slot, fingerprint), never throws. Enough distinct visitors reporting the
|
|
517
|
+
* same drift suspend that skeleton's arms. Optional for hand-rolled clients. */
|
|
518
|
+
reportDrift?(slotId: string, expectedFp: string, observedFp: string | null, reason: 'fp_mismatch' | 'unaddressable' | 'forms'): void;
|
|
486
519
|
/**
|
|
487
520
|
* Ask the server for the registry config of these MOUNTED slots. Batches a
|
|
488
521
|
* tick's mounts into one decide scoped to exactly those ids, once per id per
|
|
@@ -491,7 +524,10 @@ type SentientClient = {
|
|
|
491
524
|
* Listeners from `onSlotsChanged` fire when the answer lands. Optional so
|
|
492
525
|
* hand-rolled/test clients keep type-checking.
|
|
493
526
|
*/
|
|
494
|
-
requestSlots?(slotIds: string[], baselineTexts?: Record<string, string
|
|
527
|
+
requestSlots?(slotIds: string[], baselineTexts?: Record<string, string>, extras?: {
|
|
528
|
+
render?: Record<string, RenderCaps>;
|
|
529
|
+
skeletons?: Record<string, SkeletonReport>;
|
|
530
|
+
}): void;
|
|
495
531
|
/**
|
|
496
532
|
* Decide these MOUNTED request-declared slots (useAdaptiveTokens,
|
|
497
533
|
* AdaptiveGroup) that nothing preloaded: a tick's mounts batch into one
|
|
@@ -521,6 +557,9 @@ type SentientClient = {
|
|
|
521
557
|
isSlotDecided?(slotId: string): boolean;
|
|
522
558
|
/** Site palette served with registry block decisions. Null when absent. */
|
|
523
559
|
getSitePalette(): SitePalette | null;
|
|
560
|
+
/** Site styles the served Redesign (compose) arms borrow; null when none.
|
|
561
|
+
* Optional so hand-rolled clients keep type-checking. */
|
|
562
|
+
getStyleVocabulary?(): StyleVocabulary | null;
|
|
524
563
|
/** Current persona estimate. Band is always `confidenceBand(confidence)`. Null when nothing is known yet. */
|
|
525
564
|
getPersona(): {
|
|
526
565
|
persona: string;
|
|
@@ -581,4 +620,4 @@ declare function grantConsent(apiKey?: string): void;
|
|
|
581
620
|
*/
|
|
582
621
|
declare function init(config: SentientConfig): SentientClient;
|
|
583
622
|
|
|
584
|
-
export { type AssignResult as A,
|
|
623
|
+
export { type AssignResult as A, resetRevealStyles as B, type ComponentGoalOptions as C, type DecideInput as D, type EventQueue as E, reveal as F, type GoalDefinition as G, sanitizePageUrl as H, sessionCookieName as I, LEGACY_SESSION_COOKIE_NAME as L, type MicroSignalEmitter as M, PAGE_SCOPE_RE 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 AuthoredArmReport as c, type ComponentWeightEntry as d, type DecideOutcome as e, type EventType as f, type GoalOptions as g, type GraphClient as h, type GraphConfig as i, type GraphSnapshot as j, LOCAL_MODE_BANNER as k, type MicroSignalType as l, PROD_KEYLESS_ERROR as m, type PageNode as n, type RevealOptions as o, type SentientClient as p, type SentientConfig as q, type SentientEvent as r, type SessionConfig as s, type SessionManager as t, type SkeletonReport as u, attachMicroSignalDetectors as v, grantConsent as w, init as x, isDoNotTrackEnabled as y, pageScopeMatches as z };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as SitePalette, a4 as StyleVocabulary } from './style-vocabulary-BqviEw9O.cjs';
|
|
2
|
+
import { d as SlotConfigEntry, e as SlotDeclInput, b as CompoundLocator } from './session-meta-Dk8ivs-l.cjs';
|
|
3
|
+
import { c as RenderCaps, R as RegionSkeleton } from './region-skeleton-D2ahkcbe.cjs';
|
|
2
4
|
import { SlotResult } from '@sentientui/policy';
|
|
3
5
|
|
|
4
6
|
/** Manages anonymous session identity with cookie + localStorage layers. */
|
|
@@ -225,6 +227,17 @@ declare function attachMicroSignalDetectors(emit: MicroSignalEmitter, node: Elem
|
|
|
225
227
|
tabLoss?: boolean;
|
|
226
228
|
}): () => void;
|
|
227
229
|
|
|
230
|
+
/** A captured skeleton, or why none could be captured. */
|
|
231
|
+
type SkeletonReport = RegionSkeleton | {
|
|
232
|
+
status: 'too_large' | 'empty' | 'unaddressable';
|
|
233
|
+
};
|
|
234
|
+
/** One authored arm of a hybrid <Adaptive>, as it rendered. */
|
|
235
|
+
type AuthoredArmReport = {
|
|
236
|
+
key: string;
|
|
237
|
+
text?: string;
|
|
238
|
+
skeleton?: RegionSkeleton;
|
|
239
|
+
};
|
|
240
|
+
|
|
228
241
|
/**
|
|
229
242
|
* @internal Wires an alternate entry point's init as grantConsent()'s upgrade
|
|
230
243
|
* path for `apiKey`. The /graph entry calls this when its init is gated on
|
|
@@ -315,6 +328,8 @@ type SentientConfig = {
|
|
|
315
328
|
initialSlotConfig?: Record<string, SlotConfigEntry>;
|
|
316
329
|
/** Site palette decided outside the browser (SSR). Seeds `getSitePalette()`. */
|
|
317
330
|
initialPalette?: SitePalette;
|
|
331
|
+
/** Site styles the SSR decision's Redesign arms borrow. Seeds `getStyleVocabulary()`. */
|
|
332
|
+
initialVocabulary?: StyleVocabulary;
|
|
318
333
|
/**
|
|
319
334
|
* Persona decided during SSR. Takes priority over the html-attribute
|
|
320
335
|
* adoption and the local snapshot.
|
|
@@ -383,6 +398,7 @@ type DecideOutcome = {
|
|
|
383
398
|
goals?: GoalDefinition[];
|
|
384
399
|
sectionMap?: SectionMapEntry[];
|
|
385
400
|
palette?: SitePalette;
|
|
401
|
+
vocabulary?: StyleVocabulary;
|
|
386
402
|
};
|
|
387
403
|
type DecideInput = {
|
|
388
404
|
sections?: string[];
|
|
@@ -398,6 +414,10 @@ type DecideInput = {
|
|
|
398
414
|
/** Registry mode only: `false` omits the snippet bootstrap data (editor goals,
|
|
399
415
|
* section map) the React SDK never reads — two queries per page saved. */
|
|
400
416
|
bootstrap?: false;
|
|
417
|
+
/** Registry mode only: what the page can render per mounted slot. The
|
|
418
|
+
* server narrows each slot's arm space to it before drawing (CONTRACTS §2
|
|
419
|
+
* — an arm the page would refuse still books a trial). */
|
|
420
|
+
render?: Record<string, RenderCaps>;
|
|
401
421
|
/**
|
|
402
422
|
* Caller's build version (e.g. the snippet's `__SNIPPET_VERSION__`), sent
|
|
403
423
|
* as `v` on the wire. Additive/best-effort: the server persists it for
|
|
@@ -482,7 +502,20 @@ type SentientClient = {
|
|
|
482
502
|
* generation can ground its versions in what they replace — sent only on
|
|
483
503
|
* the first report of an id, capped, and the server keeps it only at
|
|
484
504
|
* first registration. */
|
|
485
|
-
reportSlots(slotIds: string[], baselineTexts?: Record<string, string
|
|
505
|
+
reportSlots(slotIds: string[], baselineTexts?: Record<string, string>, baselineSkeletons?: Record<string, SkeletonReport>,
|
|
506
|
+
/** A hybrid <Adaptive>'s authored arms seen on screen (spec 2026-09-23
|
|
507
|
+
* §7.4): recorded for the dashboard and to ground generation. Sent once
|
|
508
|
+
* per (slot, key) per client. */
|
|
509
|
+
authoredArms?: Record<string, AuthoredArmReport[]>): void;
|
|
510
|
+
/** Report a skeleton for a PUBLISHED slot the server flagged `needsSkeleton`
|
|
511
|
+
* (registered before skeletons existed). Once per id per client; the server
|
|
512
|
+
* stores it only while the slot has none. Optional for hand-rolled clients. */
|
|
513
|
+
reportSkeleton?(slotId: string, skeleton: SkeletonReport): void;
|
|
514
|
+
/** A served Rewrite arm could not be applied because the region's markup no
|
|
515
|
+
* longer matches the skeleton it was written for. Batched, deduped per
|
|
516
|
+
* (slot, fingerprint), never throws. Enough distinct visitors reporting the
|
|
517
|
+
* same drift suspend that skeleton's arms. Optional for hand-rolled clients. */
|
|
518
|
+
reportDrift?(slotId: string, expectedFp: string, observedFp: string | null, reason: 'fp_mismatch' | 'unaddressable' | 'forms'): void;
|
|
486
519
|
/**
|
|
487
520
|
* Ask the server for the registry config of these MOUNTED slots. Batches a
|
|
488
521
|
* tick's mounts into one decide scoped to exactly those ids, once per id per
|
|
@@ -491,7 +524,10 @@ type SentientClient = {
|
|
|
491
524
|
* Listeners from `onSlotsChanged` fire when the answer lands. Optional so
|
|
492
525
|
* hand-rolled/test clients keep type-checking.
|
|
493
526
|
*/
|
|
494
|
-
requestSlots?(slotIds: string[], baselineTexts?: Record<string, string
|
|
527
|
+
requestSlots?(slotIds: string[], baselineTexts?: Record<string, string>, extras?: {
|
|
528
|
+
render?: Record<string, RenderCaps>;
|
|
529
|
+
skeletons?: Record<string, SkeletonReport>;
|
|
530
|
+
}): void;
|
|
495
531
|
/**
|
|
496
532
|
* Decide these MOUNTED request-declared slots (useAdaptiveTokens,
|
|
497
533
|
* AdaptiveGroup) that nothing preloaded: a tick's mounts batch into one
|
|
@@ -521,6 +557,9 @@ type SentientClient = {
|
|
|
521
557
|
isSlotDecided?(slotId: string): boolean;
|
|
522
558
|
/** Site palette served with registry block decisions. Null when absent. */
|
|
523
559
|
getSitePalette(): SitePalette | null;
|
|
560
|
+
/** Site styles the served Redesign (compose) arms borrow; null when none.
|
|
561
|
+
* Optional so hand-rolled clients keep type-checking. */
|
|
562
|
+
getStyleVocabulary?(): StyleVocabulary | null;
|
|
524
563
|
/** Current persona estimate. Band is always `confidenceBand(confidence)`. Null when nothing is known yet. */
|
|
525
564
|
getPersona(): {
|
|
526
565
|
persona: string;
|
|
@@ -581,4 +620,4 @@ declare function grantConsent(apiKey?: string): void;
|
|
|
581
620
|
*/
|
|
582
621
|
declare function init(config: SentientConfig): SentientClient;
|
|
583
622
|
|
|
584
|
-
export { type AssignResult as A,
|
|
623
|
+
export { type AssignResult as A, resetRevealStyles as B, type ComponentGoalOptions as C, type DecideInput as D, type EventQueue as E, reveal as F, type GoalDefinition as G, sanitizePageUrl as H, sessionCookieName as I, LEGACY_SESSION_COOKIE_NAME as L, type MicroSignalEmitter as M, PAGE_SCOPE_RE 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 AuthoredArmReport as c, type ComponentWeightEntry as d, type DecideOutcome as e, type EventType as f, type GoalOptions as g, type GraphClient as h, type GraphConfig as i, type GraphSnapshot as j, LOCAL_MODE_BANNER as k, type MicroSignalType as l, PROD_KEYLESS_ERROR as m, type PageNode as n, type RevealOptions as o, type SentientClient as p, type SentientConfig as q, type SentientEvent as r, type SessionConfig as s, type SessionManager as t, type SkeletonReport as u, attachMicroSignalDetectors as v, grantConsent as w, init as x, isDoNotTrackEnabled as y, pageScopeMatches as z };
|
package/dist/index-engagement.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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});
|
|
1
|
+
"use strict";var z=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?z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,R=(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},Q=(e,t)=>he(e,ve(t));var Ee=(e,t)=>{for(var n in t)z(e,n,{get:t[n],enumerable:!0})},ke=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of be(t))!oe.call(e,o)&&o!==n&&z(e,o,{get:()=>t[o],enumerable:!(i=Se(t,o))||i.enumerable});return e};var Te=e=>ke(z({},"__esModule",{value:!0}),e);var We={};Ee(We,{INTERACTION_STATS_COMPONENT:()=>ee,SEMANTIC_TYPES:()=>Y,classifyFeatures:()=>q,classifySection:()=>re,featuresFromElement:()=>U,startEngagementCapture:()=>ye});module.exports=Te(We);var Y=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Re={banner:"hero",navigation:"navigation",contentinfo:"footer"};function Ce(e){let t=e.ariaRole?Re[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 Ie(e){return e.actionCount>=1&&e.textLength>0&&e.textLength<200?"cta":"generic"}var _e=[["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 Ae(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function q(e){var o,a;let t=Ce(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 _e)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=Ie(e);return{type:(a=se[i])!=null?a:"generic",strength:"weak"}}function U(e){var i,o;let t=((i=e.textContent)!=null?i:"").replace(/\s+/g," ").trim(),n=e.getAttribute("role");return R({tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((o=e.className)!=null?o:"")}`,headingText:Ae(e),bodyText:t.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:t.length},n?{ariaRole:n}:{})}function re(e){return q(U(e)).type}var me=require("@sentientui/policy");var xe=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=k=>{for(let C of k)d=C.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 H(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(H(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(H(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(H(t,S))return S}}}return null}function de(e,t){let n=De(e),i=e.getAttribute("id");if(i&&H(t,`#${le(i)}`))return{v:1,id:i,fingerprint:n};for(let a of Oe){let d=e.getAttribute(a);if(d&&H(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,Ne=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 Le(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,k=0,C=0,I=0,O=-1/0,D=-1/0,h=null,P=null,x=null,N=(f=n==null?void 0:n.scrollY)!=null?f:0,M=0,w=e.hidden?null:t(),_=()=>{let s=t();if(x!=null){let m=s-x,E=0;for(;E<ue.length&&m>=ue[E];)E++;a[E]++}x=s},L=()=>{d++,O=t()},$=()=>{l++,D=t()},K=()=>{h=t()},j=()=>{h!=null&&(pe(i,t()-h),h=null)},G=()=>{let s=t();u++,s-O>Pe&&s-D>Ne&&v++,_()},A=()=>{y++},W=()=>{var m;let s=(m=n==null?void 0:n.scrollY)!=null?m:0;S+=Math.abs(s-N),N=s,_()},F=s=>{let m=t();b++,(s.key==="Backspace"||s.key==="Delete")&&C++,Me.has(s.key)&&I++,P!=null&&pe(o,m-P),P=m,_()},B=s=>{let m=s.data;typeof m=="string"&&(k+=m.length),_()},V=()=>{let s=t();e.hidden?w!=null&&(M+=s-w,w=null):w==null&&(w=s)},p={passive:!0,capture:!0};e.addEventListener("mousemove",L,p),e.addEventListener("touchstart",$,p),e.addEventListener("touchmove",A,p),e.addEventListener("mousedown",K,p),e.addEventListener("mouseup",j,p),e.addEventListener("click",G,p),e.addEventListener("wheel",A,p),e.addEventListener("keydown",F,p),e.addEventListener("input",B,p),e.addEventListener("visibilitychange",V),n==null||n.addEventListener("scroll",W,p);let r=Le(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,T;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:k,ik_cv:o.mean>0?Number((ge(o)/o.mean).toFixed(2)):0,backspaces:C,gaps:[...a],reduced_motion:c,kb_nav:I,renderer:r,vp:[(E=n==null?void 0:n.innerWidth)!=null?E:0,(T=n==null?void 0:n.innerHeight)!=null?T:0],dpr:(n==null?void 0:n.devicePixelRatio)||1}},stop(){e.removeEventListener("mousemove",L,p),e.removeEventListener("touchstart",$,p),e.removeEventListener("touchmove",A,p),e.removeEventListener("mousedown",K,p),e.removeEventListener("mouseup",j,p),e.removeEventListener("click",G,p),e.removeEventListener("wheel",A,p),e.removeEventListener("keydown",F,p),e.removeEventListener("input",B,p),e.removeEventListener("visibilitychange",V),n==null||n.removeEventListener("scroll",W,p)}}}var $e="section, header, footer, nav, main > div, [data-sentient-section]",Ke=2e4,ee="__session__";function je(e){let t=Array.from(e.querySelectorAll($e)),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 Ge(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 J=()=>{};function ye(e,t){var N,M,w,_,L,$,K,j,G,A,W,F,B,V,p;let n=(N=t.doc)!=null?N:typeof document!="undefined"?document:void 0;if(!n||typeof IntersectionObserver=="undefined"||ae()||!t.apiKey||!t.apiKey.startsWith("pk_"))return J;let i=((M=t.apiBase)!=null?M:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),o=je(n);if(o.length===0)return J;let a=new Map,d=[];for(let r of o){let c=(L=[(_=t.sectionTypes)==null?void 0:_[(w=r.getAttribute("data-sentient-id"))!=null?w:""],r.getAttribute("data-sentient-type")].find(T=>Y.includes(T)))!=null?L:null,g=U(r),f=(K=c!=null?c:($=t.typeOf)==null?void 0:$.call(t,r))!=null?K:q(g).type,s=de(r,n),m=s?`nc-${f}-${(0,me.fnv1a)(JSON.stringify({id:(j=s.id)!=null?j:null,dataAttr:(G=s.dataAttr)!=null?G:null,selector:(A=s.selector)!=null?A:null})).toString(36)}`:`nc-${f}`;a.set(r,m);let E=X.filter(([,T])=>T.test(g.bodyText)).map(([T])=>T);d.push(Q(R({componentId:m,semanticType:f,source:c?"markup":"auto"},s?{locator:s}:{}),{observation:R(R({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=(V=(B=(F=(W=n.defaultView)!=null?W:typeof window!="undefined"?window:void 0)==null?void 0:F.location)==null?void 0:B.pathname)!=null?V:"/";Ge(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 k=(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){}},C=()=>{if(n.hidden)k(!0);else{let r=Date.now();for(let c of y.values())c.intersecting&&(c.enterAt=r)}},I=!1,O=r=>{if(k(!0),r!=null&&r.persisted){I=!0;return}try{b.disconnect()}catch(c){}},D=r=>{if(!(r!=null&&r.persisted)||!I)return;I=!1;let c=Date.now();for(let g of y.values())g.enterAt=g.intersecting&&!n.hidden?c:null};n.addEventListener("visibilitychange",C);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||I)return;k();let r=Date.now();for(let c of y.values())c.intersecting&&(c.enterAt=r)},Ke),x=[];return t.microSignals&&[...a.entries()].forEach(([r,c],g)=>{x.push(ie((f,s={})=>{try{e.track({projectId:t.apiKey,componentId:c,eventType:"micro_signal",payload:R({signalType:f},s)})}catch(m){}},r,void 0,{tabLoss:g===0}))}),()=>{k(!0),clearInterval(P),u.stop(),n.removeEventListener("visibilitychange",C),h==null||h.removeEventListener("pagehide",O),h==null||h.removeEventListener("pageshow",D);for(let r of x)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
|