@sentientui/snippet 0.32.3 → 0.33.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/README.md +36 -8
- package/dist/editor.global.js +9 -9
- package/dist/engagement.global.js +1 -1
- package/dist/install.cjs +2 -2
- package/dist/install.d.cts +28 -5
- package/dist/install.d.ts +28 -5
- package/dist/install.js +2 -2
- package/dist/preview.global.js +1 -1
- package/dist/snippet.global.js +2 -2
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __sentientEngagement=(()=>{var W=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var he=Object.prototype.hasOwnProperty;var ve=(e,t)=>()=>(e&&(t=e(e=0)),t);var ye=(e,t)=>{for(var n in t)W(e,n,{get:t[n],enumerable:!0})},be=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of me(t))!he.call(e,r)&&r!==n&&W(e,r,{get:()=>t[r],enumerable:!(l=ge(t,r))||l.enumerable});return e};var we=e=>be(W({},"__esModule",{value:!0}),e);var _e,xe,Ie,X,Ae,$e,ee,O,te,Y=ve(()=>{"use strict";_e=Object.defineProperty,xe=Object.defineProperties,Ie=Object.getOwnPropertyDescriptors,X=Object.getOwnPropertySymbols,Ae=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable,ee=(e,t,n)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,O=(e,t)=>{for(var n in t||(t={}))Ae.call(t,n)&&ee(e,n,t[n]);if(X)for(var n of X(t))$e.call(t,n)&&ee(e,n,t[n]);return e},te=(e,t)=>xe(e,Ie(t))});var qe={};ye(qe,{startEngagementCapture:()=>pe});var Se=["data-sentient-id","data-testid","data-test","data-id","data-name","data-cy"];function V(e){var t;return((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim()}function ke(e){return{tag:e.tagName.toLowerCase(),text:V(e).slice(0,40)}}function J(e){return e.replace(/["\\\]]/g,"\\$&")}function B(e,t){try{return e.querySelectorAll(t).length===1}catch(n){return!1}}function Z(e,t){var n;let l=e.tagName.toLowerCase();if(!l)return null;let r=((n=e.getAttribute("class"))!=null?n:"").split(/\s+/).filter(u=>/^[a-zA-Z][\w-]*$/.test(u)),c=[l,...r.map(u=>`${l}.${u}`)];for(let u of c)if(B(t,u))return u;let i=e.parentElement;if(i&&i!==t){let u=Z(i,t);if(u){for(let m of c){let b=`${u} > ${m}`;if(B(t,b))return b}let d=Array.from(i.children).filter(m=>m.tagName.toLowerCase()===l),y=d.indexOf(e),S=d.some(m=>m!==e&&V(m)!==V(e));if(y>=0&&S){let m=`${u} > ${l}:nth-of-type(${y+1})`;if(B(t,m))return m}}}return null}function Q(e,t){let n=ke(e),l=e.getAttribute("id");if(l&&B(t,`#${J(l)}`))return{v:1,id:l,fingerprint:n};for(let c of Se){let i=e.getAttribute(c);if(i&&B(t,`[${c}="${J(i)}"]`))return{v:1,dataAttr:{name:c,value:i},fingerprint:n}}let r=Z(e,t);return r?{v:1,selector:r,fingerprint:n}:null}Y();var re=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Ee={banner:"hero",navigation:"navigation",contentinfo:"footer"};function Ce(e){let t=e.ariaRole?Ee[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 Oe(e){return e.actionCount>=1&&e.textLength>0&&e.textLength<200?"cta":"generic"}var Le=[["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]],H=[["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]],ne={navigation:"navigation",footer:"navigation",hero:"hero",cta:"cta",generic:"generic"};function Me(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function ae(e){var t,n;let l=Ce(e);if(l)return{type:(t=ne[l])!=null?t:"generic",strength:"strong"};let r=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[i,u]of Le)if(u.test(r))return{type:i,strength:"strong"};for(let[i,u]of H)if(u.test(e.bodyText))return{type:i,strength:"strong"};let c=Oe(e);return{type:(n=ne[c])!=null?n:"generic",strength:"weak"}}function oe(e){var t,n;let l=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim(),r=e.getAttribute("role");return O({tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:Me(e),bodyText:l.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:l.length},r?{ariaRole:r}:{})}function le(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t}var Je=1800*1e3;function ie(e,t,n,l){let r=[];{let c=!1,i=[],u=()=>{if(c)return;let d=Date.now();for(i.push(d);i.length>0&&d-i[0]>500;)i.shift();i.length>=3&&(c=!0,e("rage_click"))};t.addEventListener("click",u),r.push(()=>t.removeEventListener("click",u))}{let c=!1,i=u=>{if(c||!(u.target instanceof Node)||!t.contains(u.target)&&t!==u.target)return;c=!0;let d=typeof window!="undefined"?window.getSelection():null,y=d?d.toString().length:0;e("text_copy",{selectionLength:y})};document.addEventListener("copy",i),r.push(()=>document.removeEventListener("copy",i))}{let c=!1,i=!1,u=null,d=()=>{u!==null&&(clearTimeout(u),u=null)},y=()=>{c||!i||(d(),u=setTimeout(()=>{!c&&i&&(c=!0,e("scroll_hesitation"))},3e3))},S=()=>{d(),y()},m=I=>{for(let A of I)i=A.intersectionRatio>.3,i?y():d()},b=new IntersectionObserver(m,{threshold:[.3]});b.observe(t),window.addEventListener("scroll",S,{passive:!0}),r.push(()=>{b.disconnect(),window.removeEventListener("scroll",S),d()})}if((l==null?void 0:l.tabLoss)!==!1){let c=!1,i=n!=null?n:Date.now(),u=()=>{if(c||document.visibilityState!=="hidden")return;let d=Date.now()-i;d<15e3&&(c=!0,e("tab_loss",{timeOnPage:d}))};document.addEventListener("visibilitychange",u),r.push(()=>document.removeEventListener("visibilitychange",u))}return()=>{for(let c of r)c()}}function se(){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")}Y();var ue=[100,300,1e3,3e3,1e4],Pe=250,Te=1e3,Ne=new Set(["Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);function ce(e,t){e.n++;let n=t-e.mean;e.mean+=n/e.n,e.m2+=n*(t-e.mean)}var de=e=>e.n>1?Math.sqrt(e.m2/e.n):0;function Ke(e){var t;try{let n=e.createElement("canvas"),l=n.getContext("webgl")||n.getContext("experimental-webgl");if(!l)return"unknown";let r=l.getExtension("WEBGL_debug_renderer_info"),c=r?String((t=l.getParameter(r.UNMASKED_RENDERER_WEBGL))!=null?t:""):"";return c?/swiftshader|llvmpipe|softpipe|software|mesa offscreen/i.test(c)?"sw":"hw":"unknown"}catch(n){return"unknown"}}function De(e,t=Date.now){var n,l;let r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0,c={n:0,mean:0,m2:0},i={n:0,mean:0,m2:0},u=[0,0,0,0,0,0],d=0,y=0,S=0,m=0,b=0,I=0,A=0,T=0,N=0,h=0,q=-1/0,K=-1/0,k=null,L=null,D=null,R=(l=r==null?void 0:r.scrollY)!=null?l:0,z=0,v=e.hidden?null:t(),M=()=>{let o=t();if(D!=null){let g=o-D,_=0;for(;_<ue.length&&g>=ue[_];)_++;u[_]++}D=o},P=()=>{d++,q=t()},$=()=>{y++,K=t()},j=()=>{k=t()},E=()=>{k!=null&&(ce(c,t()-k),k=null)},U=()=>{let o=t();S++,o-q>Pe&&o-K>Te&&m++,M()},C=()=>{b++},w=()=>{var o;let g=(o=r==null?void 0:r.scrollY)!=null?o:0;I+=Math.abs(g-R),R=g,M()},G=o=>{let g=t();A++,(o.key==="Backspace"||o.key==="Delete")&&N++,Ne.has(o.key)&&h++,L!=null&&ce(i,g-L),L=g,M()},F=o=>{let g=o.data;typeof g=="string"&&(T+=g.length),M()},s=()=>{let o=t();e.hidden?v!=null&&(z+=o-v,v=null):v==null&&(v=o)},a={passive:!0,capture:!0};e.addEventListener("mousemove",P,a),e.addEventListener("touchstart",$,a),e.addEventListener("touchmove",C,a),e.addEventListener("mousedown",j,a),e.addEventListener("mouseup",E,a),e.addEventListener("click",U,a),e.addEventListener("wheel",C,a),e.addEventListener("keydown",G,a),e.addEventListener("input",F,a),e.addEventListener("visibilitychange",s),r==null||r.addEventListener("scroll",w,a);let f=Ke(e),p=(()=>{var o;try{return((o=r==null?void 0:r.matchMedia)==null?void 0:o.call(r,"(prefers-reduced-motion: reduce)").matches)===!0}catch(g){return!1}})();return{snapshot(){var o,g;let _=t(),x=z+(v!=null?_-v:0);return{v:1,active_ms:Math.round(x),mm:d,mm_rate:x>0?Number((d*1e3/x).toFixed(2)):0,touches:y,clicks:S,hold_n:c.n,hold_mean:Math.round(c.mean),hold_std:Math.round(de(c)),teleport:m,wheel:b,scroll_px:Math.round(I),keydowns:A,input_chars:T,ik_cv:i.mean>0?Number((de(i)/i.mean).toFixed(2)):0,backspaces:N,gaps:[...u],reduced_motion:p,kb_nav:h,renderer:f,vp:[(o=r==null?void 0:r.innerWidth)!=null?o:0,(g=r==null?void 0:r.innerHeight)!=null?g:0],dpr:(r==null?void 0:r.devicePixelRatio)||1}},stop(){e.removeEventListener("mousemove",P,a),e.removeEventListener("touchstart",$,a),e.removeEventListener("touchmove",C,a),e.removeEventListener("mousedown",j,a),e.removeEventListener("mouseup",E,a),e.removeEventListener("click",U,a),e.removeEventListener("wheel",C,a),e.removeEventListener("keydown",G,a),e.removeEventListener("input",F,a),e.removeEventListener("visibilitychange",s),r==null||r.removeEventListener("scroll",w,a)}}}var Re="section, header, footer, nav, main > div, [data-sentient-section]",je=2e4,Ue="__session__";function Fe(e){let t=Array.from(e.querySelectorAll(Re)),n=t.filter(l=>t.filter(r=>r!==l&&l.contains(r)).length<2);return n.filter(l=>!n.some(r=>r!==l&&r.contains(l)))}function Be(e,t,n,l){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:l})}).catch(()=>{})}catch(r){}}var fe=()=>{};function pe(e,t){var n,l,r,c,i,u,d,y,S,m,b,I,A,T,N;let h=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!h||typeof IntersectionObserver=="undefined"||se()||!t.apiKey||!t.apiKey.startsWith("pk_"))return fe;let q=((l=t.apiBase)!=null?l:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),K=Fe(h);if(K.length===0)return fe;let k=new Map,L=[];for(let s of K){let a=(i=[(c=t.sectionTypes)==null?void 0:c[(r=s.getAttribute("data-sentient-id"))!=null?r:""],s.getAttribute("data-sentient-type")].find(x=>re.includes(x)))!=null?i:null,f=oe(s),p=(d=a!=null?a:(u=t.typeOf)==null?void 0:u.call(t,s))!=null?d:ae(f).type,o=Q(s,h),g=o?`nc-${p}-${le(JSON.stringify({id:(y=o.id)!=null?y:null,dataAttr:(S=o.dataAttr)!=null?S:null,selector:(m=o.selector)!=null?m:null})).toString(36)}`:`nc-${p}`;k.set(s,g);let _=H.filter(([,x])=>x.test(f.bodyText)).map(([x])=>x);L.push(te(O({componentId:g,semanticType:p,source:a?"markup":"auto"},o?{locator:o}:{}),{observation:O(O({tag:f.tag,idClass:f.idClass.slice(0,200),headingText:f.headingText,textLength:f.textLength,actionCount:f.actionCount},f.ariaRole?{ariaRole:f.ariaRole}:{}),_.length>0?{patternFlags:_}:{})}))}let D=(T=(A=(I=(b=h.defaultView)!=null?b:typeof window!="undefined"?window:void 0)==null?void 0:I.location)==null?void 0:A.pathname)!=null?T:"/";Be(t.apiKey,q,D,L);let R=De(h),z=()=>{let s;try{s=R.snapshot()}catch(a){return}try{e.track({projectId:t.apiKey,componentId:Ue,eventType:"interaction_stats",payload:s})}catch(a){}},v=new Map,M=s=>{let a=v.get(s);return a||(a={ms:0,scroll:0,enterAt:null,intersecting:!1},v.set(s,a)),a},P=new IntersectionObserver(s=>{for(let a of s){let f=k.get(a.target);if(!f)continue;let p=M(f);a.isIntersecting?(p.intersecting=!0,p.enterAt=Date.now(),a.intersectionRatio>p.scroll&&(p.scroll=a.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 k.keys())P.observe(s);let $=(s=!1)=>{var a;let f=Date.now();for(let[p,o]of v)if(o.enterAt!=null&&(o.ms+=f-o.enterAt,o.enterAt=null),!(o.ms<=0)){try{e.track({projectId:t.apiKey,componentId:p,eventType:"dwell",payload:{dwell_time:Math.round(o.ms),scroll_depth:Number(o.scroll.toFixed(2))}})}catch(g){}o.ms=0}if(z(),s)try{(a=e.flush)==null||a.call(e)}catch(p){}},j=()=>{if(h.hidden)$(!0);else{let s=Date.now();for(let a of v.values())a.intersecting&&(a.enterAt=s)}},E=!1,U=s=>{if($(!0),s!=null&&s.persisted){E=!0;return}try{P.disconnect()}catch(a){}},C=s=>{if(!(s!=null&&s.persisted)||!E)return;E=!1;let a=Date.now();for(let f of v.values())f.enterAt=f.intersecting&&!h.hidden?a:null};h.addEventListener("visibilitychange",j);let w=(N=h.defaultView)!=null?N:typeof window!="undefined"?window:void 0;w==null||w.addEventListener("pagehide",U),w==null||w.addEventListener("pageshow",C);let G=setInterval(()=>{if(h.hidden||E)return;$();let s=Date.now();for(let a of v.values())a.intersecting&&(a.enterAt=s)},je),F=[];return t.microSignals&&[...k.entries()].forEach(([s,a],f)=>{F.push(ie((p,o={})=>{try{e.track({projectId:t.apiKey,componentId:a,eventType:"micro_signal",payload:O({signalType:p},o)})}catch(g){}},s,void 0,{tabLoss:f===0}))}),()=>{$(!0),clearInterval(G),R.stop(),h.removeEventListener("visibilitychange",j),w==null||w.removeEventListener("pagehide",U),w==null||w.removeEventListener("pageshow",C);for(let s of F)s();try{P.disconnect()}catch(s){}}}return we(qe);})();
|
|
1
|
+
"use strict";var __sentientEngagement=(()=>{var z=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var he=Object.prototype.hasOwnProperty;var ve=(e,t)=>()=>(e&&(t=e(e=0)),t);var ye=(e,t)=>{for(var n in t)z(e,n,{get:t[n],enumerable:!0})},be=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of me(t))!he.call(e,r)&&r!==n&&z(e,r,{get:()=>t[r],enumerable:!(l=ge(t,r))||l.enumerable});return e};var we=e=>be(z({},"__esModule",{value:!0}),e);var _e,xe,Ie,X,Ae,$e,ee,O,te,H=ve(()=>{"use strict";_e=Object.defineProperty,xe=Object.defineProperties,Ie=Object.getOwnPropertyDescriptors,X=Object.getOwnPropertySymbols,Ae=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable,ee=(e,t,n)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,O=(e,t)=>{for(var n in t||(t={}))Ae.call(t,n)&&ee(e,n,t[n]);if(X)for(var n of X(t))$e.call(t,n)&&ee(e,n,t[n]);return e},te=(e,t)=>xe(e,Ie(t))});var Ve={};ye(Ve,{startEngagementCapture:()=>pe});var Se=["data-sentient-id","data-testid","data-test","data-id","data-name","data-cy"];function G(e){var t;return((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim()}function ke(e){return{tag:e.tagName.toLowerCase(),text:G(e).slice(0,40)}}function J(e){return e.replace(/["\\\]]/g,"\\$&")}function F(e,t){try{return e.querySelectorAll(t).length===1}catch(n){return!1}}function Z(e,t){var n;let l=e.tagName.toLowerCase();if(!l)return null;let r=((n=e.getAttribute("class"))!=null?n:"").split(/\s+/).filter(u=>/^[a-zA-Z][\w-]*$/.test(u)),c=[l,...r.map(u=>`${l}.${u}`)];for(let u of c)if(F(t,u))return u;let i=e.parentElement;if(i&&i!==t){let u=Z(i,t);if(u){for(let m of c){let b=`${u} > ${m}`;if(F(t,b))return b}let d=Array.from(i.children).filter(m=>m.tagName.toLowerCase()===l),y=d.indexOf(e),S=d.some(m=>m!==e&&G(m)!==G(e));if(y>=0&&S){let m=`${u} > ${l}:nth-of-type(${y+1})`;if(F(t,m))return m}}}return null}function Q(e,t){let n=ke(e),l=e.getAttribute("id");if(l&&F(t,`#${J(l)}`))return{v:1,id:l,fingerprint:n};for(let c of Se){let i=e.getAttribute(c);if(i&&F(t,`[${c}="${J(i)}"]`))return{v:1,dataAttr:{name:c,value:i},fingerprint:n}}let r=Z(e,t);return r?{v:1,selector:r,fingerprint:n}:null}H();var re=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Ee={banner:"hero",navigation:"navigation",contentinfo:"footer"};function Ce(e){let t=e.ariaRole?Ee[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 Oe(e){return e.actionCount>=1&&e.textLength>0&&e.textLength<200?"cta":"generic"}var Le=[["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]],Y=[["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]],ne={navigation:"navigation",footer:"navigation",hero:"hero",cta:"cta",generic:"generic"};function Me(e){var t;let n=e.querySelector("h1, h2, h3");return((t=n==null?void 0:n.textContent)!=null?t:"").slice(0,160)}function ae(e){var t,n;let l=Ce(e);if(l)return{type:(t=ne[l])!=null?t:"generic",strength:"strong"};let r=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[i,u]of Le)if(u.test(r))return{type:i,strength:"strong"};for(let[i,u]of Y)if(u.test(e.bodyText))return{type:i,strength:"strong"};let c=Oe(e);return{type:(n=ne[c])!=null?n:"generic",strength:"weak"}}function oe(e){var t,n;let l=((t=e.textContent)!=null?t:"").replace(/\s+/g," ").trim(),r=e.getAttribute("role");return O({tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:Me(e),bodyText:l.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:l.length},r?{ariaRole:r}:{})}function le(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t}var Je=1800*1e3;function ie(e,t,n,l){let r=[];{let c=!1,i=[],u=()=>{if(c)return;let d=Date.now();for(i.push(d);i.length>0&&d-i[0]>500;)i.shift();i.length>=3&&(c=!0,e("rage_click"))};t.addEventListener("click",u),r.push(()=>t.removeEventListener("click",u))}{let c=!1,i=u=>{if(c||!(u.target instanceof Node)||!t.contains(u.target)&&t!==u.target)return;c=!0;let d=typeof window!="undefined"?window.getSelection():null,y=d?d.toString().length:0;e("text_copy",{selectionLength:y})};document.addEventListener("copy",i),r.push(()=>document.removeEventListener("copy",i))}{let c=!1,i=!1,u=null,d=()=>{u!==null&&(clearTimeout(u),u=null)},y=()=>{c||!i||(d(),u=setTimeout(()=>{!c&&i&&(c=!0,e("scroll_hesitation"))},3e3))},S=()=>{d(),y()},m=I=>{for(let A of I)i=A.intersectionRatio>.3,i?y():d()},b=new IntersectionObserver(m,{threshold:[.3]});b.observe(t),window.addEventListener("scroll",S,{passive:!0}),r.push(()=>{b.disconnect(),window.removeEventListener("scroll",S),d()})}if((l==null?void 0:l.tabLoss)!==!1){let c=!1,i=n!=null?n:Date.now(),u=()=>{if(c||document.visibilityState!=="hidden")return;let d=Date.now()-i;d<15e3&&(c=!0,e("tab_loss",{timeOnPage:d}))};document.addEventListener("visibilitychange",u),r.push(()=>document.removeEventListener("visibilitychange",u))}return()=>{for(let c of r)c()}}function se(){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")}H();var ue=[100,300,1e3,3e3,1e4],Pe=250,Te=1e3,Ne=new Set(["Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);function ce(e,t){e.n++;let n=t-e.mean;e.mean+=n/e.n,e.m2+=n*(t-e.mean)}var de=e=>e.n>1?Math.sqrt(e.m2/e.n):0;function Re(e){var t;try{let n=e.createElement("canvas"),l=n.getContext("webgl")||n.getContext("experimental-webgl");if(!l)return"unknown";let r=l.getExtension("WEBGL_debug_renderer_info"),c=r?String((t=l.getParameter(r.UNMASKED_RENDERER_WEBGL))!=null?t:""):"";return c?/swiftshader|llvmpipe|softpipe|software|mesa offscreen/i.test(c)?"sw":"hw":"unknown"}catch(n){return"unknown"}}function Ke(e,t=Date.now){var n,l;let r=(n=e.defaultView)!=null?n:typeof window!="undefined"?window:void 0,c={n:0,mean:0,m2:0},i={n:0,mean:0,m2:0},u=[0,0,0,0,0,0],d=0,y=0,S=0,m=0,b=0,I=0,A=0,T=0,N=0,h=0,V=-1/0,R=-1/0,k=null,L=null,K=null,D=(l=r==null?void 0:r.scrollY)!=null?l:0,W=0,v=e.hidden?null:t(),M=()=>{let o=t();if(K!=null){let g=o-K,_=0;for(;_<ue.length&&g>=ue[_];)_++;u[_]++}K=o},P=()=>{d++,V=t()},$=()=>{y++,R=t()},j=()=>{k=t()},E=()=>{k!=null&&(ce(c,t()-k),k=null)},U=()=>{let o=t();S++,o-V>Pe&&o-R>Te&&m++,M()},C=()=>{b++},w=()=>{var o;let g=(o=r==null?void 0:r.scrollY)!=null?o:0;I+=Math.abs(g-D),D=g,M()},q=o=>{let g=t();A++,(o.key==="Backspace"||o.key==="Delete")&&N++,Ne.has(o.key)&&h++,L!=null&&ce(i,g-L),L=g,M()},B=o=>{let g=o.data;typeof g=="string"&&(T+=g.length),M()},s=()=>{let o=t();e.hidden?v!=null&&(W+=o-v,v=null):v==null&&(v=o)},a={passive:!0,capture:!0};e.addEventListener("mousemove",P,a),e.addEventListener("touchstart",$,a),e.addEventListener("touchmove",C,a),e.addEventListener("mousedown",j,a),e.addEventListener("mouseup",E,a),e.addEventListener("click",U,a),e.addEventListener("wheel",C,a),e.addEventListener("keydown",q,a),e.addEventListener("input",B,a),e.addEventListener("visibilitychange",s),r==null||r.addEventListener("scroll",w,a);let f=Re(e),p=(()=>{var o;try{return((o=r==null?void 0:r.matchMedia)==null?void 0:o.call(r,"(prefers-reduced-motion: reduce)").matches)===!0}catch(g){return!1}})();return{snapshot(){var o,g;let _=t(),x=W+(v!=null?_-v:0);return{v:1,active_ms:Math.round(x),mm:d,mm_rate:x>0?Number((d*1e3/x).toFixed(2)):0,touches:y,clicks:S,hold_n:c.n,hold_mean:Math.round(c.mean),hold_std:Math.round(de(c)),teleport:m,wheel:b,scroll_px:Math.round(I),keydowns:A,input_chars:T,ik_cv:i.mean>0?Number((de(i)/i.mean).toFixed(2)):0,backspaces:N,gaps:[...u],reduced_motion:p,kb_nav:h,renderer:f,vp:[(o=r==null?void 0:r.innerWidth)!=null?o:0,(g=r==null?void 0:r.innerHeight)!=null?g:0],dpr:(r==null?void 0:r.devicePixelRatio)||1}},stop(){e.removeEventListener("mousemove",P,a),e.removeEventListener("touchstart",$,a),e.removeEventListener("touchmove",C,a),e.removeEventListener("mousedown",j,a),e.removeEventListener("mouseup",E,a),e.removeEventListener("click",U,a),e.removeEventListener("wheel",C,a),e.removeEventListener("keydown",q,a),e.removeEventListener("input",B,a),e.removeEventListener("visibilitychange",s),r==null||r.removeEventListener("scroll",w,a)}}}var De="section, header, footer, nav, main > div, [data-sentient-section]",je=2e4,Ue="__session__";function Be(e){let t=Array.from(e.querySelectorAll(De)),n=t.filter(l=>t.filter(r=>r!==l&&l.contains(r)).length<2);return n.filter(l=>!n.some(r=>r!==l&&r.contains(l)))}function Fe(e,t,n,l){try{fetch(`${t}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({pageUrl:n,sections:l})}).catch(()=>{})}catch(r){}}var fe=()=>{};function pe(e,t){var n,l,r,c,i,u,d,y,S,m,b,I,A,T,N;let h=(n=t.doc)!=null?n:typeof document!="undefined"?document:void 0;if(!h||typeof IntersectionObserver=="undefined"||se()||!t.apiKey||!t.apiKey.startsWith("pk_"))return fe;let V=((l=t.apiBase)!=null?l:"https://api.sentient-ui.com").replace(/\/+$/,"").replace(/\/v1$/,""),R=Be(h);if(R.length===0)return fe;let k=new Map,L=[];for(let s of R){let a=(i=[(c=t.sectionTypes)==null?void 0:c[(r=s.getAttribute("data-sentient-id"))!=null?r:""],s.getAttribute("data-sentient-type")].find(x=>re.includes(x)))!=null?i:null,f=oe(s),p=(d=a!=null?a:(u=t.typeOf)==null?void 0:u.call(t,s))!=null?d:ae(f).type,o=Q(s,h),g=o?`nc-${p}-${le(JSON.stringify({id:(y=o.id)!=null?y:null,dataAttr:(S=o.dataAttr)!=null?S:null,selector:(m=o.selector)!=null?m:null})).toString(36)}`:`nc-${p}`;k.set(s,g);let _=Y.filter(([,x])=>x.test(f.bodyText)).map(([x])=>x);L.push(te(O({componentId:g,semanticType:p,source:a?"markup":"auto"},o?{locator:o}:{}),{observation:O(O({tag:f.tag,idClass:f.idClass.slice(0,200),headingText:f.headingText,textLength:f.textLength,actionCount:f.actionCount},f.ariaRole?{ariaRole:f.ariaRole}:{}),_.length>0?{patternFlags:_}:{})}))}let K=(T=(A=(I=(b=h.defaultView)!=null?b:typeof window!="undefined"?window:void 0)==null?void 0:I.location)==null?void 0:A.pathname)!=null?T:"/";Fe(t.apiKey,V,K,L);let D=Ke(h),W=()=>{let s;try{s=D.snapshot()}catch(a){return}try{e.track({projectId:t.apiKey,componentId:Ue,eventType:"interaction_stats",payload:s})}catch(a){}},v=new Map,M=s=>{let a=v.get(s);return a||(a={ms:0,scroll:0,enterAt:null,intersecting:!1},v.set(s,a)),a},P=new IntersectionObserver(s=>{for(let a of s){let f=k.get(a.target);if(!f)continue;let p=M(f);a.isIntersecting?(p.intersecting=!0,p.enterAt=Date.now(),a.intersectionRatio>p.scroll&&(p.scroll=a.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 k.keys())P.observe(s);let $=(s=!1)=>{var a;let f=Date.now();for(let[p,o]of v)if(o.enterAt!=null&&(o.ms+=f-o.enterAt,o.enterAt=null),!(o.ms<=0)){try{e.track({projectId:t.apiKey,componentId:p,eventType:"dwell",payload:{dwell_time:Math.round(o.ms),scroll_depth:Number(o.scroll.toFixed(2))}})}catch(g){}o.ms=0}if(W(),s)try{(a=e.flush)==null||a.call(e)}catch(p){}},j=()=>{if(h.hidden)$(!0);else{let s=Date.now();for(let a of v.values())a.intersecting&&(a.enterAt=s)}},E=!1,U=s=>{if($(!0),s!=null&&s.persisted){E=!0;return}try{P.disconnect()}catch(a){}},C=s=>{if(!(s!=null&&s.persisted)||!E)return;E=!1;let a=Date.now();for(let f of v.values())f.enterAt=f.intersecting&&!h.hidden?a:null};h.addEventListener("visibilitychange",j);let w=(N=h.defaultView)!=null?N:typeof window!="undefined"?window:void 0;w==null||w.addEventListener("pagehide",U),w==null||w.addEventListener("pageshow",C);let q=setInterval(()=>{if(h.hidden||E)return;$();let s=Date.now();for(let a of v.values())a.intersecting&&(a.enterAt=s)},je),B=[];return t.microSignals&&[...k.entries()].forEach(([s,a],f)=>{B.push(ie((p,o={})=>{try{e.track({projectId:t.apiKey,componentId:a,eventType:"micro_signal",payload:O({signalType:p},o)})}catch(g){}},s,void 0,{tabLoss:f===0}))}),()=>{$(!0),clearInterval(q),D.stop(),h.removeEventListener("visibilitychange",j),w==null||w.removeEventListener("pagehide",U),w==null||w.removeEventListener("pageshow",C);for(let s of B)s();try{P.disconnect()}catch(s){}}}return we(Ve);})();
|
package/dist/install.cjs
CHANGED
|
@@ -29,9 +29,9 @@ __export(install_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(install_exports);
|
|
30
30
|
|
|
31
31
|
// src/prepaint-script.ts
|
|
32
|
-
var SNIPPET_PREPAINT_VERSION =
|
|
32
|
+
var SNIPPET_PREPAINT_VERSION = 2;
|
|
33
33
|
function renderSnippetPrePaintScript() {
|
|
34
|
-
return `(function(){try{var W=window,D=document,N=navigator,L=W.location,c=W.sentient,n=Date.now();if(!c||typeof c.apiKey!="string"||c.consentFrom!==void 0||(c.consent!==void 0?c.consent!==!0:W.Shopify&&W.Shopify.shop)||W.__sntPP)return;if(N.doNotTrack=="1"||N.doNotTrack=="yes"||W.doNotTrack=="1"||N.msDoNotTrack=="1"||N.globalPrivacyControl||N.webdriver)return;if(/[
|
|
34
|
+
return `(function(){try{var W=window,D=document,N=navigator,L=W.location,c=W.sentient,n=Date.now();if(!c||typeof c.apiKey!="string"||c.consentFrom!==void 0||(c.consent!==void 0?c.consent!==!0:W.Shopify&&W.Shopify.shop)||W.__sntPP)return;if(N.doNotTrack=="1"||N.doNotTrack=="yes"||W.doNotTrack=="1"||N.msDoNotTrack=="1"||N.globalPrivacyControl||N.webdriver)return;if(/[?&#]sentient_(editor|preview|persona|context)/.test(L.search+L.hash)||sessionStorage.getItem("__snt_editor_token"))return;var s=JSON.parse(localStorage.getItem("_snt_snap:"+c.apiKey)),S=s.slots;if(s.v!==1||typeof s.persona!="string"||typeof s.band!="string"||!S||typeof S!="object"||!(2592e6>n-s.savedAt))return;var u=L.search,I=/[?&](gclid|gbraid|wbraid|ttclid|msclkid|twclid|li_fat_id)=/.test(u)||/[?&]utm_medium=(cpc|ppc|cp[mv]|sem|paid([-_+]?s(earch|ocial))?|social[-_+]?paid|display|banner|re(targeting|marketing)|shopping|pmax|e-?mail|newsletter|sms|text|push)(&|$)/i.test(u)||/^\\/discount\\//.test(L.pathname);var H=["data-sentient-persona","data-sentient-confidence","data-sentient-stage"],d=D.documentElement,P=W.__sntPP={v:2,at:n,stamped:[],html:[],reordered:!1,done:!1,held:!1,stop:function(){X()},reveal:function(){Z()}},b=P.stamped,p=[],h=[],j=[],i,k,t,e,l,m,x,K,V=c.sections,O=s.layoutOrder,q=!(V&&V.length>1&&O&&O.length==V.length);if(c.personaAttributes&&!d.hasAttribute(H[0])){d.setAttribute(H[0],s.persona);d.setAttribute(H[1],s.band);P.html.push(H[0],H[1])}if(c.stageAttributes&&typeof(t=s.stage)=="string"&&!d.hasAttribute(H[2])){d.setAttribute(H[2],c.stageAttributes!="detailed"&&/^(customer|lapsed)$/.test(t)?"returning":t);P.html.push(H[2])}var Q=function(v){return(""+v).replace(/["\\\\]/g,"\\\\$&")},A=function(t,v,g){if(typeof v=="string"){if(!g||(g.arms||[]).indexOf(v)>-1)p.push([t,"data-sentient-arm",v])}else if(v)for(k in v)if(!g||((g.dims||{})[k]||[]).indexOf(v[k])>-1)p.push([t,"data-"+k,v[k]])},U=function(t){var a=t[3];if(!a)return;a[2]==null?a[0].removeAttribute(a[1]):a[0].setAttribute(a[1],a[2]);x=b.indexOf(a);if(x>-1)b.splice(x,1);t[3]=0},R=function(){var g={},f=[],y,z,a,n=0;for(i in V){try{y=D.querySelectorAll(V[i])}catch(_){return 1}if(y.length==1){g[V[i]]=y[0];n++}}if(n!=V.length)return 0;for(i in O){z=g[O[i]];if(!z||~f.indexOf(z))return 1;f.push(z)}a=f[0].parentNode;if(!a)return 1;for(i in f)if(f[i].parentNode!=a)return 1;y=f.slice().sort(function(u,v){return u.compareDocumentPosition(v)&4?-1:1});for(i=0;i in f;i++){z=f[i];if(y[i]!=z){a.insertBefore(z,y[i]);y.splice(y.indexOf(z),1);y.splice(i,0,z)}}P.reordered=!0;return 1},F=function(){if(P.done)return;for(i=0;i in p;i++){t=p[i];if(!t)continue;try{m=D.querySelectorAll(t[0])}catch(_){p[i]=0;continue}if(m.length>1){U(t);p[i]=0}else if(m.length==1&&(!t[3]||t[3][0]!=m[0])){U(t);e=m[0];t[3]=[e,t[1],e.getAttribute(t[1])];e.setAttribute(t[1],t[2]);b.push(t[3])}}if(P.held)for(i in h){try{m=D.querySelectorAll(h[i])}catch(_){continue}if(m.length==1&&(e=m[0]).style.visibility!="hidden"){j.push([e,e.style.visibility]);e.style.visibility="hidden"}}if(!q)q=R()},X=function(){if(P.done)return;P.done=!0;try{o.disconnect()}catch(_){}clearTimeout(T)},Z=function(){if(!P.held)return;P.held=!1;clearTimeout(K);for(i in j)j[i][0].style.visibility=j[i][1];j=[]},G=c.slots,C=s.slotConfig;for(i in G)if(G[i]&&G[i].target)A(G[i].target,S[i],G[i]);for(i in C){e=C[i]||{};l=e.locator;t=e.target;if(l){if(l.urlMatch&&!~L.pathname.indexOf(l.urlMatch))continue;t=l.id?'[id="'+Q(l.id)+'"]':l.dataAttr&&/^[\\w-]+$/.test(l.dataAttr.name)?"["+l.dataAttr.name+'="'+Q(l.dataAttr.value)+'"]':l.selector}if(t){A(t,S[i]);h.push(t)}}if(P.held=!!(I&&h[0]))K=setTimeout(Z,300);var o=new MutationObserver(F),T=setTimeout(X,3e3);o.observe(d,{childList:!0,subtree:!0});D.addEventListener("DOMContentLoaded",function(){F();X()});F();}catch(_){}})();`;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// src/install.ts
|
package/dist/install.d.cts
CHANGED
|
@@ -29,14 +29,25 @@ type PrePaintRecord = {
|
|
|
29
29
|
done: boolean;
|
|
30
30
|
/** Disconnect now — the bundle has taken over. */
|
|
31
31
|
stop(): void;
|
|
32
|
+
/** v2+: true while the strong-intent hold keeps registry targets hidden. */
|
|
33
|
+
held?: boolean;
|
|
34
|
+
/** v2+: end the hold now (the decision is on the page). Idempotent; absent on v1. */
|
|
35
|
+
reveal?(): void;
|
|
32
36
|
};
|
|
33
37
|
/** Contract version of the snippet inline pre-paint script — mirrored at runtime
|
|
34
38
|
* as `window.__sntPP.v`, and reported to /v1/decide as `pp` so the dashboard can
|
|
35
39
|
* tell a two-tag install from a three-tag one. The script is pasted into a site
|
|
36
|
-
* once and never floats, so
|
|
37
|
-
|
|
40
|
+
* once and never floats, so every version must stay supported by the bundle
|
|
41
|
+
* indefinitely — v1 has no `held`/`reveal`, and the bundle calls `reveal`
|
|
42
|
+
* only when it exists.
|
|
43
|
+
*
|
|
44
|
+
* v2 (2026-10-09): `data-sentient-stage` from the snapshot (opt-in
|
|
45
|
+
* `stageAttributes`), the strong-intent hold, and the QA gate widened to the
|
|
46
|
+
* context preview, the URL fragment (`#sentient_editor_code`,
|
|
47
|
+
* `#sentient_preview_token`) and a cached editor session. */
|
|
48
|
+
declare const SNIPPET_PREPAINT_VERSION = 2;
|
|
38
49
|
/**
|
|
39
|
-
* Snippet-install inline pre-paint script (
|
|
50
|
+
* Snippet-install inline pre-paint script (v2).
|
|
40
51
|
*
|
|
41
52
|
* The snippet loader is `defer`, so the bundle's snapshot pass is pre-*decide*
|
|
42
53
|
* but not necessarily pre-*paint*: on a return visit a page can show its natural
|
|
@@ -59,9 +70,21 @@ declare const SNIPPET_PREPAINT_VERSION = 1;
|
|
|
59
70
|
* `__sntPP` reconcile in index.ts).
|
|
60
71
|
*
|
|
61
72
|
* What it deliberately does NOT do: no `textContent`, no ops stylesheet, no
|
|
62
|
-
* `moveBefore`/`moveAfter`, no Composition-Block rendering, and no
|
|
63
|
-
*
|
|
73
|
+
* `moveBefore`/`moveAfter`, no Composition-Block rendering, and no page-wide
|
|
74
|
+
* cloak. Those either need the decide response to be trustworthy or need the
|
|
64
75
|
* renderer that lives in the bundle.
|
|
76
|
+
*
|
|
77
|
+
* The one hiding it does (v2) is the strong-intent hold: when the landing URL
|
|
78
|
+
* says the visitor clicked an ad or an email (a click ID, a paid or email
|
|
79
|
+
* `utm_medium`, a `/discount/` link), this visit's decide may serve a version
|
|
80
|
+
* written for that arrival, and showing last visit's version first is the
|
|
81
|
+
* flicker that wastes the click. So ONLY the registry slots' target elements
|
|
82
|
+
* (the ones resolved below) get `visibility:hidden` — layout is kept, so no
|
|
83
|
+
* shift — until the bundle has applied the decision (`__sntPP.reveal()`) or
|
|
84
|
+
* 300 ms have passed, whichever comes first; then the merchant's own inline
|
|
85
|
+
* value is restored. Every other visitor pays nothing. Those targets come from
|
|
86
|
+
* the snapshot, so a browser with none (a true first visit, a wiped Safari
|
|
87
|
+
* storage) has nothing to hold and none is attempted.
|
|
65
88
|
*/
|
|
66
89
|
declare function renderSnippetPrePaintScript(): string;
|
|
67
90
|
|
package/dist/install.d.ts
CHANGED
|
@@ -29,14 +29,25 @@ type PrePaintRecord = {
|
|
|
29
29
|
done: boolean;
|
|
30
30
|
/** Disconnect now — the bundle has taken over. */
|
|
31
31
|
stop(): void;
|
|
32
|
+
/** v2+: true while the strong-intent hold keeps registry targets hidden. */
|
|
33
|
+
held?: boolean;
|
|
34
|
+
/** v2+: end the hold now (the decision is on the page). Idempotent; absent on v1. */
|
|
35
|
+
reveal?(): void;
|
|
32
36
|
};
|
|
33
37
|
/** Contract version of the snippet inline pre-paint script — mirrored at runtime
|
|
34
38
|
* as `window.__sntPP.v`, and reported to /v1/decide as `pp` so the dashboard can
|
|
35
39
|
* tell a two-tag install from a three-tag one. The script is pasted into a site
|
|
36
|
-
* once and never floats, so
|
|
37
|
-
|
|
40
|
+
* once and never floats, so every version must stay supported by the bundle
|
|
41
|
+
* indefinitely — v1 has no `held`/`reveal`, and the bundle calls `reveal`
|
|
42
|
+
* only when it exists.
|
|
43
|
+
*
|
|
44
|
+
* v2 (2026-10-09): `data-sentient-stage` from the snapshot (opt-in
|
|
45
|
+
* `stageAttributes`), the strong-intent hold, and the QA gate widened to the
|
|
46
|
+
* context preview, the URL fragment (`#sentient_editor_code`,
|
|
47
|
+
* `#sentient_preview_token`) and a cached editor session. */
|
|
48
|
+
declare const SNIPPET_PREPAINT_VERSION = 2;
|
|
38
49
|
/**
|
|
39
|
-
* Snippet-install inline pre-paint script (
|
|
50
|
+
* Snippet-install inline pre-paint script (v2).
|
|
40
51
|
*
|
|
41
52
|
* The snippet loader is `defer`, so the bundle's snapshot pass is pre-*decide*
|
|
42
53
|
* but not necessarily pre-*paint*: on a return visit a page can show its natural
|
|
@@ -59,9 +70,21 @@ declare const SNIPPET_PREPAINT_VERSION = 1;
|
|
|
59
70
|
* `__sntPP` reconcile in index.ts).
|
|
60
71
|
*
|
|
61
72
|
* What it deliberately does NOT do: no `textContent`, no ops stylesheet, no
|
|
62
|
-
* `moveBefore`/`moveAfter`, no Composition-Block rendering, and no
|
|
63
|
-
*
|
|
73
|
+
* `moveBefore`/`moveAfter`, no Composition-Block rendering, and no page-wide
|
|
74
|
+
* cloak. Those either need the decide response to be trustworthy or need the
|
|
64
75
|
* renderer that lives in the bundle.
|
|
76
|
+
*
|
|
77
|
+
* The one hiding it does (v2) is the strong-intent hold: when the landing URL
|
|
78
|
+
* says the visitor clicked an ad or an email (a click ID, a paid or email
|
|
79
|
+
* `utm_medium`, a `/discount/` link), this visit's decide may serve a version
|
|
80
|
+
* written for that arrival, and showing last visit's version first is the
|
|
81
|
+
* flicker that wastes the click. So ONLY the registry slots' target elements
|
|
82
|
+
* (the ones resolved below) get `visibility:hidden` — layout is kept, so no
|
|
83
|
+
* shift — until the bundle has applied the decision (`__sntPP.reveal()`) or
|
|
84
|
+
* 300 ms have passed, whichever comes first; then the merchant's own inline
|
|
85
|
+
* value is restored. Every other visitor pays nothing. Those targets come from
|
|
86
|
+
* the snapshot, so a browser with none (a true first visit, a wiped Safari
|
|
87
|
+
* storage) has nothing to hold and none is attempted.
|
|
65
88
|
*/
|
|
66
89
|
declare function renderSnippetPrePaintScript(): string;
|
|
67
90
|
|
package/dist/install.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/prepaint-script.ts
|
|
2
|
-
var SNIPPET_PREPAINT_VERSION =
|
|
2
|
+
var SNIPPET_PREPAINT_VERSION = 2;
|
|
3
3
|
function renderSnippetPrePaintScript() {
|
|
4
|
-
return `(function(){try{var W=window,D=document,N=navigator,L=W.location,c=W.sentient,n=Date.now();if(!c||typeof c.apiKey!="string"||c.consentFrom!==void 0||(c.consent!==void 0?c.consent!==!0:W.Shopify&&W.Shopify.shop)||W.__sntPP)return;if(N.doNotTrack=="1"||N.doNotTrack=="yes"||W.doNotTrack=="1"||N.msDoNotTrack=="1"||N.globalPrivacyControl||N.webdriver)return;if(/[
|
|
4
|
+
return `(function(){try{var W=window,D=document,N=navigator,L=W.location,c=W.sentient,n=Date.now();if(!c||typeof c.apiKey!="string"||c.consentFrom!==void 0||(c.consent!==void 0?c.consent!==!0:W.Shopify&&W.Shopify.shop)||W.__sntPP)return;if(N.doNotTrack=="1"||N.doNotTrack=="yes"||W.doNotTrack=="1"||N.msDoNotTrack=="1"||N.globalPrivacyControl||N.webdriver)return;if(/[?&#]sentient_(editor|preview|persona|context)/.test(L.search+L.hash)||sessionStorage.getItem("__snt_editor_token"))return;var s=JSON.parse(localStorage.getItem("_snt_snap:"+c.apiKey)),S=s.slots;if(s.v!==1||typeof s.persona!="string"||typeof s.band!="string"||!S||typeof S!="object"||!(2592e6>n-s.savedAt))return;var u=L.search,I=/[?&](gclid|gbraid|wbraid|ttclid|msclkid|twclid|li_fat_id)=/.test(u)||/[?&]utm_medium=(cpc|ppc|cp[mv]|sem|paid([-_+]?s(earch|ocial))?|social[-_+]?paid|display|banner|re(targeting|marketing)|shopping|pmax|e-?mail|newsletter|sms|text|push)(&|$)/i.test(u)||/^\\/discount\\//.test(L.pathname);var H=["data-sentient-persona","data-sentient-confidence","data-sentient-stage"],d=D.documentElement,P=W.__sntPP={v:2,at:n,stamped:[],html:[],reordered:!1,done:!1,held:!1,stop:function(){X()},reveal:function(){Z()}},b=P.stamped,p=[],h=[],j=[],i,k,t,e,l,m,x,K,V=c.sections,O=s.layoutOrder,q=!(V&&V.length>1&&O&&O.length==V.length);if(c.personaAttributes&&!d.hasAttribute(H[0])){d.setAttribute(H[0],s.persona);d.setAttribute(H[1],s.band);P.html.push(H[0],H[1])}if(c.stageAttributes&&typeof(t=s.stage)=="string"&&!d.hasAttribute(H[2])){d.setAttribute(H[2],c.stageAttributes!="detailed"&&/^(customer|lapsed)$/.test(t)?"returning":t);P.html.push(H[2])}var Q=function(v){return(""+v).replace(/["\\\\]/g,"\\\\$&")},A=function(t,v,g){if(typeof v=="string"){if(!g||(g.arms||[]).indexOf(v)>-1)p.push([t,"data-sentient-arm",v])}else if(v)for(k in v)if(!g||((g.dims||{})[k]||[]).indexOf(v[k])>-1)p.push([t,"data-"+k,v[k]])},U=function(t){var a=t[3];if(!a)return;a[2]==null?a[0].removeAttribute(a[1]):a[0].setAttribute(a[1],a[2]);x=b.indexOf(a);if(x>-1)b.splice(x,1);t[3]=0},R=function(){var g={},f=[],y,z,a,n=0;for(i in V){try{y=D.querySelectorAll(V[i])}catch(_){return 1}if(y.length==1){g[V[i]]=y[0];n++}}if(n!=V.length)return 0;for(i in O){z=g[O[i]];if(!z||~f.indexOf(z))return 1;f.push(z)}a=f[0].parentNode;if(!a)return 1;for(i in f)if(f[i].parentNode!=a)return 1;y=f.slice().sort(function(u,v){return u.compareDocumentPosition(v)&4?-1:1});for(i=0;i in f;i++){z=f[i];if(y[i]!=z){a.insertBefore(z,y[i]);y.splice(y.indexOf(z),1);y.splice(i,0,z)}}P.reordered=!0;return 1},F=function(){if(P.done)return;for(i=0;i in p;i++){t=p[i];if(!t)continue;try{m=D.querySelectorAll(t[0])}catch(_){p[i]=0;continue}if(m.length>1){U(t);p[i]=0}else if(m.length==1&&(!t[3]||t[3][0]!=m[0])){U(t);e=m[0];t[3]=[e,t[1],e.getAttribute(t[1])];e.setAttribute(t[1],t[2]);b.push(t[3])}}if(P.held)for(i in h){try{m=D.querySelectorAll(h[i])}catch(_){continue}if(m.length==1&&(e=m[0]).style.visibility!="hidden"){j.push([e,e.style.visibility]);e.style.visibility="hidden"}}if(!q)q=R()},X=function(){if(P.done)return;P.done=!0;try{o.disconnect()}catch(_){}clearTimeout(T)},Z=function(){if(!P.held)return;P.held=!1;clearTimeout(K);for(i in j)j[i][0].style.visibility=j[i][1];j=[]},G=c.slots,C=s.slotConfig;for(i in G)if(G[i]&&G[i].target)A(G[i].target,S[i],G[i]);for(i in C){e=C[i]||{};l=e.locator;t=e.target;if(l){if(l.urlMatch&&!~L.pathname.indexOf(l.urlMatch))continue;t=l.id?'[id="'+Q(l.id)+'"]':l.dataAttr&&/^[\\w-]+$/.test(l.dataAttr.name)?"["+l.dataAttr.name+'="'+Q(l.dataAttr.value)+'"]':l.selector}if(t){A(t,S[i]);h.push(t)}}if(P.held=!!(I&&h[0]))K=setTimeout(Z,300);var o=new MutationObserver(F),T=setTimeout(X,3e3);o.observe(d,{childList:!0,subtree:!0});D.addEventListener("DOMContentLoaded",function(){F();X()});F();}catch(_){}})();`;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
// src/install.ts
|
package/dist/preview.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __sentientPreview=(()=>{var
|
|
1
|
+
"use strict";var __sentientPreview=(()=>{var p=Object.defineProperty,U=Object.defineProperties,j=Object.getOwnPropertyDescriptor,F=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertyNames,I=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var E=(e,t,n)=>t in e?p(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,d=(e,t)=>{for(var n in t||(t={}))A.call(t,n)&&E(e,n,t[n]);if(I)for(var n of I(t))H.call(t,n)&&E(e,n,t[n]);return e},O=(e,t)=>U(e,F(t));var V=(e,t)=>{for(var n in t)p(e,n,{get:t[n],enumerable:!0})},z=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of G(t))!A.call(e,r)&&r!==n&&p(e,r,{get:()=>t[r],enumerable:!(a=j(t,r))||a.enumerable});return e};var W=e=>z(p({},"__esModule",{value:!0}),e);var ne={};V(ne,{parseContextPreview:()=>$,parsePersonaPreview:()=>K,parsePreview:()=>R,runPreview:()=>Z});var C=["new","browsing","carted","customer","lapsed"];var oe=1800*1e3;var f="data-sentient-stage";function g(e,t){return!t||typeof e!="string"||!(e==="returning"||C.includes(e))?null:t!=="detailed"&&(e==="customer"||e==="lapsed")?"returning":e}function m(e,t=document){try{e?t.documentElement.setAttribute(f,e):t.documentElement.removeAttribute(f)}catch(n){}}var q="__snt_editor_token";function P(){try{return typeof sessionStorage!="undefined"?sessionStorage.getItem(q):null}catch(e){return null}}function T(e){let t=null;try{let n=location.hash.slice(1),a=RegExp("(^|[?&])"+e+"=([^&]*)").exec(n);if(a){t=a[2];let r=n.slice(a.index+a[0].length);a[1]!="&"&&r[0]=="&"&&(r=a[1]+r.slice(1));let l=n.slice(0,a.index)+r;history.replaceState(history.state,"",l?"#"+l:location.pathname+location.search)}}catch(n){}return t}var Y=5e3;function J(e,t){let n,a=new Promise(r=>{n=setTimeout(()=>r(null),t)});return Promise.race([e,a]).then(r=>(clearTimeout(n),r),r=>{throw clearTimeout(n),r})}var X={position:"fixed",bottom:"16px",zIndex:"2147483647",background:"#111827",color:"#fff",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"};async function Z(e){let t=$(window.location.search),n=R(window.location.search);if(n)return await ee(e,n,t),!0;let a=K(window.location.search);return a||t?(await te(e,a!=null?a:"",t),e.dbg("persona preview",a,t),!0):!1}function $(e){try{let t=new URLSearchParams(e).get("sentient_context");return t&&/^[a-z_]{1,40}$/.test(t)?t:null}catch(t){return null}}function R(e){let t=new URLSearchParams(e).get("sentient_preview");if(!t)return null;let n={};for(let a of t.split("|")){let r=a.indexOf(":"),l=r===-1?"":a.slice(0,r),s=r===-1?"":a.slice(r+1);if(!(!l||!s))if(s.includes("=")){let o={};for(let c of s.split(",")){let[u,i]=c.split("=");u&&i&&(o[u]=i)}Object.keys(o).length&&(n[l]=o)}else n[l]=s}return Object.keys(n).length?n:null}function K(e){try{return new URLSearchParams(e).get("sentient_persona")||null}catch(t){return null}}var M="sentient-persona-preview-banner";function L(e,t,n,a){var r;try{if(typeof document=="undefined"||document.getElementById(M))return;let l=e.charAt(0).toUpperCase()+e.slice(1).replace(/[_-]+/g," "),s=document.createElement("div");s.id=M,s.setAttribute("role","status"),Object.assign(s.style,X,{left:"50%",transform:"translateX(-50%)",display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"999px",font:"13px/1 system-ui, sans-serif",border:"1px solid rgba(255,255,255,0.14)"});let o=document.createElement("span"),c=n?` \xB7 ${n.replace(/_/g," ")} visitors${a?" (not served until stage serving is on)":""}`:"";o.textContent=(t?`\u201C${e}\u201D isn\u2019t in your personas \u2014 showing the default experience`:e?`Previewing as ${l}`:"Previewing")+c;let u=document.createElement("button");u.type="button",u.textContent="Exit preview",Object.assign(u.style,{cursor:"pointer",border:"1px solid rgba(255,255,255,0.3)",background:"transparent",color:"#fff",font:"inherit",padding:"4px 10px",borderRadius:"999px"}),u.addEventListener("click",()=>{try{let i=new URL(window.location.href);i.searchParams.delete("sentient_persona"),i.searchParams.delete("sentient_context"),window.location.href=i.pathname+i.search+i.hash}catch(i){}}),s.appendChild(o),s.appendChild(u),((r=document.body)!=null?r:document.documentElement).appendChild(s)}catch(l){}}function Q(){var e;return(e=T("sentient_preview_token"))!=null?e:P()}function N(e,t){let n=e.cfg;return J(fetch(`${e.apiBase}/v1/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${n.apiKey}`},body:JSON.stringify(t)}).then(a=>a.ok?a.json():null).catch(()=>null),Y)}async function ee(e,t,n=null){var s;let a=e.cfg,r=(s=a.registry)!=null?s:Object.keys(a.slots).length===0,l=Q();if(r){let o=await N(e,O(d(d({slotsFrom:"registry",includeDrafts:!0},l?{previewToken:l}:{}),n?{context:n}:{}),{force:Object.fromEntries(Object.entries(t).filter(c=>typeof c[1]=="string"))}));if(!(o!=null&&o.slotConfig)){e.exposeGlobal(),e.dbg("preview mode: slot config unavailable \u2014 page left as-is");return}e.set({slotConfig:o.slotConfig,look:o})}e.set({slots:t,persona:null}),e.apply(),e.installSpaHooks(),e.exposeGlobal(),e.dbg("preview mode",t)}async function te(e,t,n=null){var h,v,y,S,b,w,_,x,k;let a=e.cfg,r=(h=a.registry)!=null?h:Object.keys(a.slots).length===0,l=n?{context:n}:{},s=await N(e,d(r?{persona:t,slotsFrom:"registry"}:{persona:t,slots:Object.entries(a.slots).map(([D,B])=>({id:D,dims:B.dims}))},l));if(!s){e.exposeGlobal(),e.dbg("persona preview: explain unavailable \u2014 page left as-is");return}let o=s,c=(S=(y=(v=o.personaAttributes)==null?void 0:v.persona)!=null?y:o.persona)!=null?S:t,u=(w=(b=o.personaAttributes)==null?void 0:b.confidence)!=null?w:"high";e.set({slots:(_=o.slots)!=null?_:{},slotConfig:(x=o.slotConfig)!=null?x:null,look:o,persona:{persona:c,band:u},decided:!0}),e.apply(),e.installSpaHooks(),e.exposeGlobal(),n&&a.stageAttributes&&m(g(n,a.stageAttributes));let i=o.contextServing===!1;t&&o.recognized===!1?L(t,!0,n,i):L(t?(k=o.personaDisplay)!=null?k:c:"",!1,n,i)}return W(ne);})();
|