@datacub/web 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/datacub.js +2 -2
- package/dist/datacub.mjs +2 -2
- package/dist/feedback.js +4 -4
- package/dist/feedback.mjs +4 -4
- package/dist/flags.js +1 -1
- package/dist/flags.mjs +1 -1
- package/package.json +1 -1
- package/types/datacub.d.ts +10 -4
- package/types/index.d.ts +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.0](https://github.com/datacub/sdk/compare/web-v0.4.3...web-v0.5.0) (2026-11-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **web:** load the feedback widget itself, one script tag is enough ([#6](https://github.com/datacub/sdk/issues/6)) ([68a0dde](https://github.com/datacub/sdk/commit/68a0dde65013078b44e90b5b5a828cbd3c8bce83))
|
|
9
|
+
|
|
10
|
+
## [0.4.3](https://github.com/datacub/sdk/compare/web-v0.4.2...web-v0.4.3) (2026-11-22)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **web:** send on page hide while a batch is in flight; a 100% flag is on before consent ([5276091](https://github.com/datacub/sdk/commit/5276091fb45581310bf78e691d7816a6ef59127c))
|
|
16
|
+
|
|
3
17
|
## [0.4.2](https://github.com/datacub/sdk/compare/web-v0.4.0...web-v0.4.2) (2026-11-22)
|
|
4
18
|
|
|
5
19
|
|
package/dist/datacub.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(()=>{var v={n:0},vt=(t)=>t.replace(/[\u0660-\u0669\u06f0-\u06f9\uff10-\uff19]/g,(e)=>String(e.charCodeAt(0)&15)),ve=/[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]/g,Bt=(t)=>vt(t).replace(ve,""),ke=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|bearer\s+\S{16,}|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]+|PRIVATE KEY|[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}|eyJ[\w-]+\.[\w-]+\.[\w-]*|\d(?:[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]*\d){8,}|[\w+/=]{32,}/gi;function Z(t){let e="",n=0;for(let r of vt(t).matchAll(ke)){if(/^[0-9a-f]{8}-/i.test(r[0])&&r[0].length===36)continue;e+=`${t.slice(n,r.index)}[redacted]`,n=r.index+r[0].length,v.n++}return e+t.slice(n)}function F(t,e=1024){if(t=t.normalize("NFC"),t.length>256||t.trim().split(/\s+/).length>11)return v.n++,"[redacted]";return Z(t).slice(0,e).replace(/[\uD800-\uDBFF]$/,"")}var H=(t)=>/[\u0000-\u001f\u007f-\u009f\u200e\u200f\u061c\u202a-\u202e\u2066-\u2069]/.test(t),Ee=/(?:passw(?:or)?d|passcode|pwd|pin|pincode|otp|otpcode|onetimecode|mfacode|2facode|tfacode|smscode|secretkey|privatekey|authcode|verificationcode|securitycode|resetcode|cvv|cvc|cardnumber|ccnumber|creditcard|pan|iban|iqama|hawiya|nationalid|nid|idnumber|ssn|token|authorization|secret|apikey|sessionid|cookie|jwt|bearer|csrf|xsrf|passport|\u0643\u0644\u0645\u0647\u0627\u0644\u0645\u0631\u0648\u0631|\u0643\u0644\u0645\u0647\u0627\u0644\u0633\u0631|\u0627\u0644\u0631\u0645\u0632\u0627\u0644\u0633\u0631\u064a|\u0627\u0644\u0631\u0642\u0645\u0627\u0644\u0633\u0631\u064a|\u0631\u0645\u0632\u0627\u0644\u062a\u062d\u0642\u0642|\u0631\u0642\u0645\u0627\u0644\u0647\u0648\u064a\u0647|\u0627\u0644\u0647\u0648\u064a\u0647\u0627\u0644\u0648\u0637\u0646\u064a\u0647|\u0627\u0644\u0627\u0642\u0627\u0645\u0647|\u0627\u0644\u0628\u0637\u0627\u0642\u0647|\u0627\u0644\u0627\u064a\u0628\u0627\u0646)$/;function Kt(t,e){let n=t.normalize("NFKD").replace(/[\p{M}\u0640]/gu,"").replace(/\u0629/g,"\u0647").replace(/\u0649/g,"\u064a").replace(/(\p{Ll})(?=\p{Lu})|(\p{N}+)/gu,"$1 $2 ").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);while(n.length>1&&/^\p{N}+$/u.test(n[n.length-1]))n.pop();return!t||[...t].length>200||/\./.test(t)||H(t)||/^(?:__proto__|constructor|prototype)$/.test(t)||e&&/^(?:\$|(?:distinct_id|person_id|project_id|timestamp|uuid|ip|api_key)$)/.test(t)||Ee.test(n.join(""))&&!/^(?:japan|span|timespan|lifespan|wingspan|saucepan|spin|chopin|android)$/.test(n[n.length-1])||n.some((r)=>/^(?:password|passwd|pwd|passcode|otp|pin|secret|iqama|ssn|cvv|cvc|iban)$/.test(r))}function D(t,e=0){if(typeof t==="string")return F(t);if(typeof t==="number")return Number.isFinite(t)?Number.isInteger(t)&&Z(`${t}`)!==`${t}`?"[redacted]":t:void 0;if(typeof t==="boolean"||t===null)return t;if(t instanceof Date)return Number.isNaN(+t)?void 0:t.toISOString();if(typeof t!=="object")return;if(e>2)return"[depth]";if(Array.isArray(t))return t.slice(0,100).map((i)=>D(i,e+1)).filter((i)=>i!==void 0);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n)return;let r={};for(let[i,s]of Object.entries(t).slice(0,200)){let o=i.trim();if(Kt(o,!e))v.n++;else{let a=D(s,e+1);if(a!==void 0)r[o]=a}}return r}function Xt(t){let e=t;try{e=decodeURIComponent(t)}catch{}e=vt(e);let n=v.n;if(Z(e)!==e)return v.n=n+1,":redacted";if(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(e))return":uuid";if(/^[0-9a-f]{16,}$/i.test(e))return e.length===24?":id":":hash";if(/^[\w-]{20,}$/.test(e)&&/\d/.test(e)&&/[a-z]/.test(e)&&/[A-Z]/.test(e))return":token";let r=e.replace(/\D/g,"").length;return r&&(r===e.length||r>3&&r*2>=e.length)?":id":t}var xe=/^(?:reset|invite|sid|token|jwt|otp|code|key|state|sig(?:nature)?|auth\w*|nonce|session\w*|hash|q|query|search\w*|s|keywords?|term|text|msg|message|comments?|\w*name|e?-?mail\w*|phone|mobile|tel|address\w*|city|zip|postcode|dob|birth\w*)$/i,Se=(t)=>/^(?:[a-z0-9][a-z0-9._~-]*|[A-Z0-9][A-Z0-9_-]*)$/.test(t)&&!(t.length>=8&&/\d/.test(t)&&/[a-z]/i.test(t)),k=(t,e)=>Z(t.normalize("NFC")).slice(0,e),Vt=(t)=>t.split("/").map((e)=>e&&Xt(e)).join("/");function R(t,e,n){let r;try{r=new URL(t)}catch{return null}let i=r.protocol;if(/^(?:mailto|tel|sms|whatsapp):$/.test(i))return{url:i,path:i};if(!/^https?:$/.test(i))return null;let s=Vt(r.pathname);if(e&&/^#!?\//.test(r.hash))s+=`#${Vt(r.hash.slice(1).split("?")[0])}`;s=s.slice(0,1024);let o={url:(r.origin+s).slice(0,2048),path:s};for(let[a,f]of r.searchParams){let g=a.toLowerCase();if(/^utm_(?:source|medium|campaign|term|content)$/.test(g)&&f)o.utm={...o.utm,[g.slice(4)]:F(f,200)};else if(/^(?:gclid|gbraid|wbraid|fbclid|ttclid|msclkid|sccid|twclid|li_fat_id)$/.test(g))o.click_id_type=g.replace(/^[gw]braid$/,"gclid");else if(n&&Object.keys(o.q||{}).length<30){let m=Xt(f);o.q??={},o.q[k(a,64)]=Kt(a,!1)||xe.test(a)||f.length>40||!(m[0]===":"||Se(f))?"":m===":redacted"?"":m}}return o}function Yt(t){let e=t.trim().normalize("NFC");return!e||[...e].length>100||e[0]==="$"||H(e)||/[0-9a-f]{8}-[0-9a-f]{4}-|[0-9a-f]{16}|@/i.test(e)||/\d{6}/.test(Bt(e))?null:e}function kt(t,e){if(typeof t==="number"&&Number.isFinite(t))t=`${t}`;if(typeof t!=="string")return null;let n=t.trim().normalize("NFC"),r=Bt(n),i=0;for(let s=0;s<r.length;s++){let o=+r[r.length-1-s];i+=s%2?o>4?o*2-9:o*2:o}return!n||[...n].length>128||/^(?:null|undefined|0|-1|anonymous|guest|\[object object\]|none|nan|false|true|user|test|unknown|not_authenticated|distinct_id|id)$/i.test(n)||H(n)||/@|^eyJ/.test(n)||/^(?:[12]\d{9}|(?:\+?966|00966|0)5\d{8}|\+\d{8,15})$/.test(r)||/^[2-6]\d{14,15}$/.test(r)&&i%10===0||e.includes(n)?null:n}var Rt="0.4.2",Wt=1800000,Re=86400000,Ae=34560000,At=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,$t=".datacub-no-capture,[data-datacub-no-capture]",re=["datacub_id","datacub_u","datacub_a","datacub_ss"],c,ft=!1,O={},ie=!0,It=0,et=0,nt=0,rt=0,it={},Ot=new Set,Tt,C=0,dt=0,w,ot,pt,J,q={},oe=!1,Ut="",T="",Nt=!1,se=null,Y="pending",Ct=!1,_=!1,B="",gt="",l="",E=null,j=null,P=null,h="",st=0,A=0,ae,G=0,W="",K=null,Ie=0,at=0,mt=0,ht=0,ce="",ct=!0,Q,Zt=0,u=[],qt,le=!1,Jt="",V=!1,lt=0,bt=!1,y=0,Pt=[],x=Date.now;function yt(t){if(oe)console.warn(`[datacub] ${t}`)}var S=(t)=>(...e)=>{try{t(...e)}catch{}},d=(t,e,n)=>t.addEventListener(e,S(n),!0);function L(t){let e=crypto.getRandomValues(new Uint8Array(16));for(let r=5,i=t;t&&r>=0;r--,i=Math.floor(i/256))e[r]=i&255;return e[6]=e[6]&15|(t?112:64),e[8]=e[8]&63|128,Array.from(e,(r)=>(r+256).toString(16).slice(1)).join("").replace(/(.{8})(.{4})(.{4})(.{4})/,"$1-$2-$3-$4-")}function X(){let t={};try{for(let e of c.cookie.split("; ")){let n=e.indexOf("="),r=e.slice(0,n);if(r==="datacub_optout"||B&&r.endsWith(B))t[r==="datacub_optout"?r:r.slice(0,-B.length)]=decodeURIComponent(e.slice(n+1))}}catch{}return t}function b(t,e,n=gt,r=e?Ae:0){try{c.cookie=`${t==="datacub_optout"?t:t+B}=${encodeURIComponent(e||"")};Path=/;Max-Age=${r};SameSite=Lax${n}${location.protocol==="https:"?";Secure":""}`}catch{}}function ue(){let t=location.hostname.split(".");return/^[\d.]+$|:/.test(location.hostname)?[]:t.slice(0,-1).map((e,n)=>`;Domain=${t.slice(n).join(".")}`)}function Mt(){if(!_)return;let t=X(),e=t.datacub_id??null;if(e!==l)l=e&&At.test(e)?e:L(),b("datacub_id",l),h="";E=t.datacub_u??null,j=t.datacub_a??null;let[n,r,i]=(t.datacub_ss||"").split(".");if(ae=n,G=+i,n&&At.test(n)&&G&&(n!==h||G>A))h=n,st=+r,A=G}function fe(t,e){if(!h||t-A>Wt||t-st>Re){if(h=L(x()),st=A=t,_)b("datacub_id",l)}else if(e&&t>A)A=t;if(_&&(ae!==h||A-G>5000))b("datacub_ss",`${h}.${st}.${A}`,gt,Wt/1000)}function I(t){clearTimeout(qt),le=t===0,qt=t==null?void 0:setTimeout(S(zt),t)}function de(t){if((t||u.length>19||c.visibilityState==="hidden")&&!le&&!lt)I(0);else if(!qt)I(5000)}var Oe=new TextEncoder;function p(t,e,n,r){if(!l)return;let i=x();if(Mt(),fe(i,!/^\$(?:pageleave|error|request|form_fields)$/.test(t)),v.n)e={...e,$d:v.n};let s=JSON.stringify([L(i),t,i,l,E,j,h,W||null,Ie++,+(Y==="granted"),+_,K?.url,ce,e,n]),o=Oe.encode(s).length;if(o>31000){y++;return}v.n=0,u.push([s,o]),ye(),de(r)}function Te(t,e){if(!l||typeof t!=="string")return;let n=Yt(t);if(!n)return yt("bad name");p(n,e&&typeof e==="object"&&!Array.isArray(e)&&D(e)||{})}function Dt(t=x()){if(at)mt+=t-at;at=c.visibilityState==="visible"?t:0}var ut=()=>{C=innerWidth,dt=innerHeight,ce=C<360?"xs":C<480?"s":C<768?"m":C<1280?"l":"xl",ht=Math.max(ht,scrollY+dt)};function Ft(t,e){return it[t]=(it[t]||0)+1,it[t]<=e}function pe(){if(!W)return;Dt();let t=mt-It;if(ct&&t<1)return;let e=c.documentElement.scrollHeight,n={$v:t,$s:e?ht/e:null};if(ct)n.$e=!0;if(et)n.$ec=et;if(nt)n.$rq=nt;if(rt)n.$rf=rt;et=nt=rt=0;try{Object.assign(n,q.l?.())}catch{}ct=!0,It=mt,p("$pageleave",n)}function Ht(t,e){if(!l)return;let n=location.pathname+(Nt?location.hash.split("?")[0]:"");if(!t&&n===Jt)return;let r=R(location.href,Nt,O.query!==!1);if(!r)return;Jt=n,pe();let i={};if(K)i.$p=K.path;if(t&&!e)i.$b=!0;if(i.$N=e?performance.getEntriesByType?.("navigation")[0]?.type:t?"back_forward":Tt,r.q)i.$q=r.q;if(O.title!==!1&&c.title)i.$T=k(c.title,200);K=r,W=L(x()),ct=!1,mt=ht=at=It=0,it={},Ot.clear(),Dt(),ut(),i.$vw=C,i.$vh=dt;let s=null;if(e)try{let o=new URL(c.referrer);s=o.hostname,i.$R=R(o.href)?.path}catch{}p("$pageview",i,[r.utm,r.click_id_type,s],e)}var Et=(t)=>()=>{if(!(Q&&t==="replace"&&Tt==="push"))Tt=t;w?.(),clearTimeout(Q),Q=setTimeout(S(()=>{Q=void 0,Ht()}),100)},ge=(t)=>{let e=t.closest("[data-datacub-name]")?.getAttribute("data-datacub-name");return e?F(e,100):null},me=!0;function Ne(t){let e="";for(let n=0;t&&n<10&&t!==c.body;n++,t=t.parentElement){let r=1;for(let o=t.previousElementSibling;o;o=o.previousElementSibling)if(o.localName===t.localName)r++;let i=t.id,s=t.getAttribute("data-datacub-name");e=`${t.localName}${i&&!/\d{4}|[\da-f]{8}|^:|radix-|headlessui-|mui-|ember\d|react-select/i.test(i)?`#${k(i,64)}`:""}${r>1?`:${r}`:""}${s?`[${k(s,64)}]`:""}${e&&">"}${e}`}return e.slice(-512)}function Ce(t){let e=t.querySelector(`input,textarea,select,[contenteditable],${$t}`)?"":(t.textContent||"").replace(/\s+/g," ").trim();return k(e&&e.length<101?e:t.getAttribute("aria-label")||t.getAttribute("title")||t.querySelector("img")?.getAttribute("alt")||"",100)||void 0}function qe(t,e){w?.(),ot=void 0;let n=c.activeElement,r=new MutationObserver(()=>w?.()),i=setTimeout(S(()=>{w?.();let s=e.target.closest('a[href]:not([href^="javascript:"]):not([href^="#"])');if(c.activeElement===n&&!(s&&!e.defaultPrevented)&&!(ot&&!ot.defaultPrevented))p("$deadclick",t)}),1000);w=()=>{r.disconnect(),clearTimeout(i),w=void 0},r.observe(c,{subtree:!0,childList:!0,attributes:!0,characterData:!0})}function Pe(t){let e=t.target,n=t;if(!l||!(e instanceof Element)||e.closest(`${$t},input:not([type=submit]):not([type=button]),textarea,select,[contenteditable]:not([contenteditable=false])`))return;let r=e.closest("a,button,summary,input,[data-datacub-name],[role=button],[role=link],[role=menuitem],[role=tab]"),i=!r&&!/^(?:canvas|video)$/.test(e.localName)&&getComputedStyle(e).cursor==="pointer",s=r||e,o={$t:s.localName,$n:ge(e),$g:Ne(s)};if(s.closest("form"))o.$o=!0;if(n.detail)o.$cx=Math.round(n.clientX/C*100),o.$cy=Math.round(n.clientY/dt*100);if((r||i)&&O.text!==!1)o.$l=Ce(s);if(r){let a=r.getAttribute("role");if(a&&/^(?:button|link|menuitem|tab)$/.test(a))o.$r=a;if(r.localName==="input")o.$y=r.type;if(r.localName==="a"&&r.hasAttribute("href"))o.$h=R(r.href)?.url;p("$click",o)}if(me&&n.detail===3&&!(s.textContent?.trim()&&getSelection()?.isCollapsed===!1))p("$rageclick",{...o});if((r||i)&&!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&!s.closest("[target=_blank],[download]"))qe(o,t)}var wt=(t)=>({$f:ge(t),$a:R(new URL(t.getAttribute("action")||"",location.href).href)?.url,$i:t.querySelectorAll("input,select,textarea").length});function je(t){let e=t.target;if(ot=t,!l||e.localName!=="form"||e.closest($t))return;p("$form_submit",wt(e))}var he=(t)=>{let e=t.target.form;return l&&e&&O.forms!==!1&&!e.closest($t)?e:null},Qt=new WeakSet;function Le(t){w?.();let e=he(t);if(e&&!Qt.has(e))Qt.add(e),p("$form_start",wt(e))}var tt=new Map;function Ue(t){w?.();let e=he(t);if(!e)return;let n=tt.get(e)||0;if(tt.set(e,n+1),!n)setTimeout(S(()=>{if(Ft("i",10))p("$form_invalid",{...wt(e),$iv:tt.get(e)});tt.delete(e)}))}var te=(t)=>t.replace(/https?:\/\/[^\s'"<>()]+/g,(e)=>{let n=/(?::\d+){1,2}$/.exec(e)?.[0]||"";return(R(e.slice(0,e.length-n.length))?.url??"")+n});function xt(t,e,n,r,i){let s=`${r}`.startsWith(T.slice(0,-5));if(!l||O.errors===!1||t==="resource"&&(!i||s))return;et++;let o=e&&typeof e==="object"?e:{},a=k(te(`${o.message??n??(e&&e!==o?e:"")}`).replace(/(["'\u201c\u201d\u00ab\u00bb\u2018\u2019])[^"'\u201c\u201d\u00ab\u00bb\u2018\u2019]*["'\u201c\u201d\u00ab\u00bb\u2018\u2019]/g,'"\u2026"'),200),f=typeof o.stack==="string"?k(te(o.stack.split(`
|
|
1
|
+
(()=>{var _={n:0},Et=(t)=>t.replace(/[\u0660-\u0669\u06f0-\u06f9\uff10-\uff19]/g,(e)=>String(e.charCodeAt(0)&15)),Se=/[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]/g,Xt=(t)=>Et(t).replace(Se,""),Re=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|bearer\s+\S{16,}|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]+|PRIVATE KEY|[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}|eyJ[\w-]+\.[\w-]+\.[\w-]*|\d(?:[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]*\d){8,}|[\w+/=]{32,}/gi;function Z(t){let e="",n=0;for(let r of Et(t).matchAll(Re)){if(/^[0-9a-f]{8}-/i.test(r[0])&&r[0].length===36)continue;e+=`${t.slice(n,r.index)}[redacted]`,n=r.index+r[0].length,_.n++}return e+t.slice(n)}function H(t,e=1024){if(t=t.normalize("NFC"),t.length>256||t.trim().split(/\s+/).length>11)return _.n++,"[redacted]";return Z(t).slice(0,e).replace(/[\uD800-\uDBFF]$/,"")}var z=(t)=>/[\u0000-\u001f\u007f-\u009f\u200e\u200f\u061c\u202a-\u202e\u2066-\u2069]/.test(t),Ae=/(?:passw(?:or)?d|passcode|pwd|pin|pincode|otp|otpcode|onetimecode|mfacode|2facode|tfacode|smscode|secretkey|privatekey|authcode|verificationcode|securitycode|resetcode|cvv|cvc|cardnumber|ccnumber|creditcard|pan|iban|iqama|hawiya|nationalid|nid|idnumber|ssn|token|authorization|secret|apikey|sessionid|cookie|jwt|bearer|csrf|xsrf|passport|\u0643\u0644\u0645\u0647\u0627\u0644\u0645\u0631\u0648\u0631|\u0643\u0644\u0645\u0647\u0627\u0644\u0633\u0631|\u0627\u0644\u0631\u0645\u0632\u0627\u0644\u0633\u0631\u064a|\u0627\u0644\u0631\u0642\u0645\u0627\u0644\u0633\u0631\u064a|\u0631\u0645\u0632\u0627\u0644\u062a\u062d\u0642\u0642|\u0631\u0642\u0645\u0627\u0644\u0647\u0648\u064a\u0647|\u0627\u0644\u0647\u0648\u064a\u0647\u0627\u0644\u0648\u0637\u0646\u064a\u0647|\u0627\u0644\u0627\u0642\u0627\u0645\u0647|\u0627\u0644\u0628\u0637\u0627\u0642\u0647|\u0627\u0644\u0627\u064a\u0628\u0627\u0646)$/;function Yt(t,e){let n=t.normalize("NFKD").replace(/[\p{M}\u0640]/gu,"").replace(/\u0629/g,"\u0647").replace(/\u0649/g,"\u064a").replace(/(\p{Ll})(?=\p{Lu})|(\p{N}+)/gu,"$1 $2 ").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);while(n.length>1&&/^\p{N}+$/u.test(n[n.length-1]))n.pop();return!t||[...t].length>200||/\./.test(t)||z(t)||/^(?:__proto__|constructor|prototype)$/.test(t)||e&&/^(?:\$|(?:distinct_id|person_id|project_id|timestamp|uuid|ip|api_key)$)/.test(t)||Ae.test(n.join(""))&&!/^(?:japan|span|timespan|lifespan|wingspan|saucepan|spin|chopin|android)$/.test(n[n.length-1])||n.some((r)=>/^(?:password|passwd|pwd|passcode|otp|pin|secret|iqama|ssn|cvv|cvc|iban)$/.test(r))}function F(t,e=0){if(typeof t==="string")return H(t);if(typeof t==="number")return Number.isFinite(t)?Number.isInteger(t)&&Z(`${t}`)!==`${t}`?"[redacted]":t:void 0;if(typeof t==="boolean"||t===null)return t;if(t instanceof Date)return Number.isNaN(+t)?void 0:t.toISOString();if(typeof t!=="object")return;if(e>2)return"[depth]";if(Array.isArray(t))return t.slice(0,100).map((i)=>F(i,e+1)).filter((i)=>i!==void 0);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n)return;let r={};for(let[i,s]of Object.entries(t).slice(0,200)){let o=i.trim();if(Yt(o,!e))_.n++;else{let a=F(s,e+1);if(a!==void 0)r[o]=a}}return r}function Wt(t){let e=t;try{e=decodeURIComponent(t)}catch{}e=Et(e);let n=_.n;if(Z(e)!==e)return _.n=n+1,":redacted";if(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(e))return":uuid";if(/^[0-9a-f]{16,}$/i.test(e))return e.length===24?":id":":hash";if(/^[\w-]{20,}$/.test(e)&&/\d/.test(e)&&/[a-z]/.test(e)&&/[A-Z]/.test(e))return":token";let r=e.replace(/\D/g,"").length;return r&&(r===e.length||r>3&&r*2>=e.length)?":id":t}var Oe=/^(?:reset|invite|sid|token|jwt|otp|code|key|state|sig(?:nature)?|auth\w*|nonce|session\w*|hash|q|query|search\w*|s|keywords?|term|text|msg|message|comments?|\w*name|e?-?mail\w*|phone|mobile|tel|address\w*|city|zip|postcode|dob|birth\w*)$/i,Ie=(t)=>/^(?:[a-z0-9][a-z0-9._~-]*|[A-Z0-9][A-Z0-9_-]*)$/.test(t)&&!(t.length>=8&&/\d/.test(t)&&/[a-z]/i.test(t)),v=(t,e)=>Z(t.normalize("NFC")).slice(0,e),Kt=(t)=>t.split("/").map((e)=>e&&Wt(e)).join("/");function R(t,e,n){let r;try{r=new URL(t)}catch{return null}let i=r.protocol;if(/^(?:mailto|tel|sms|whatsapp):$/.test(i))return{url:i,path:i};if(!/^https?:$/.test(i))return null;let s=Kt(r.pathname);if(e&&/^#!?\//.test(r.hash))s+=`#${Kt(r.hash.slice(1).split("?")[0])}`;s=s.slice(0,1024);let o={url:(r.origin+s).slice(0,2048),path:s};for(let[a,f]of r.searchParams){let g=a.toLowerCase();if(/^utm_(?:source|medium|campaign|term|content)$/.test(g)&&f)o.utm={...o.utm,[g.slice(4)]:H(f,200)};else if(/^(?:gclid|gbraid|wbraid|fbclid|ttclid|msclkid|sccid|twclid|li_fat_id)$/.test(g))o.click_id_type=g.replace(/^[gw]braid$/,"gclid");else if(n&&Object.keys(o.q||{}).length<30){let m=Wt(f);o.q??={},o.q[v(a,64)]=Yt(a,!1)||Oe.test(a)||f.length>40||!(m[0]===":"||Ie(f))?"":m===":redacted"?"":m}}return o}function Zt(t){let e=t.trim().normalize("NFC");return!e||[...e].length>100||e[0]==="$"||z(e)||/[0-9a-f]{8}-[0-9a-f]{4}-|[0-9a-f]{16}|@/i.test(e)||/\d{6}/.test(Xt(e))?null:e}function xt(t,e){if(typeof t==="number"&&Number.isFinite(t))t=`${t}`;if(typeof t!=="string")return null;let n=t.trim().normalize("NFC"),r=Xt(n),i=0;for(let s=0;s<r.length;s++){let o=+r[r.length-1-s];i+=s%2?o>4?o*2-9:o*2:o}return!n||[...n].length>128||/^(?:null|undefined|0|-1|anonymous|guest|\[object object\]|none|nan|false|true|user|test|unknown|not_authenticated|distinct_id|id)$/i.test(n)||z(n)||/@|^eyJ/.test(n)||/^(?:[12]\d{9}|(?:\+?966|00966|0)5\d{8}|\+\d{8,15})$/.test(r)||/^[2-6]\d{14,15}$/.test(r)&&i%10===0||e.includes(n)?null:n}var Ot="0.5.0",Jt=1800000,Te=86400000,Ce=34560000,It=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,kt=".datacub-no-capture,[data-datacub-no-capture]",oe=["datacub_id","datacub_u","datacub_a","datacub_ss"],c,ft=!1,I={},se=!0,ae=!0,dt=0,Tt=0,et=0,nt=0,rt=0,it={},Ct=new Set,Nt,j=0,pt=0,w,ot,gt,J,q={},ce=!1,Dt="",T="",jt=!1,le=null,Y="pending",qt=!1,k=!1,B="",mt="",l="",E=null,L=null,P=null,b="",st=0,A=0,ue,G=0,W="",K=null,Ne=0,at=0,bt=0,ht=0,fe="",ct=!0,Q,Qt=0,u=[],Pt,de=!1,te="",V=!1,lt=0,yt=!1,y=0,Lt=[],x=Date.now;function wt(t){if(ce)console.warn(`[datacub] ${t}`)}var S=(t)=>(...e)=>{try{t(...e)}catch{}},d=(t,e,n)=>t.addEventListener(e,S(n),!0);function U(t){let e=crypto.getRandomValues(new Uint8Array(16));for(let r=5,i=t;t&&r>=0;r--,i=Math.floor(i/256))e[r]=i&255;return e[6]=e[6]&15|(t?112:64),e[8]=e[8]&63|128,Array.from(e,(r)=>(r+256).toString(16).slice(1)).join("").replace(/(.{8})(.{4})(.{4})(.{4})/,"$1-$2-$3-$4-")}function X(){let t={};try{for(let e of c.cookie.split("; ")){let n=e.indexOf("="),r=e.slice(0,n);if(r==="datacub_optout"||B&&r.endsWith(B))t[r==="datacub_optout"?r:r.slice(0,-B.length)]=decodeURIComponent(e.slice(n+1))}}catch{}return t}function h(t,e,n=mt,r=e?Ce:0){try{c.cookie=`${t==="datacub_optout"?t:t+B}=${encodeURIComponent(e||"")};Path=/;Max-Age=${r};SameSite=Lax${n}${location.protocol==="https:"?";Secure":""}`}catch{}}function pe(){let t=location.hostname.split(".");return/^[\d.]+$|:/.test(location.hostname)?[]:t.slice(0,-1).map((e,n)=>`;Domain=${t.slice(n).join(".")}`)}function Ft(){if(!k)return;let t=X(),e=t.datacub_id??null;if(e!==l)l=e&&It.test(e)?e:U(),h("datacub_id",l),b="";E=t.datacub_u??null,L=t.datacub_a??null;let[n,r,i]=(t.datacub_ss||"").split(".");if(ue=n,G=+i,n&&It.test(n)&&G&&(n!==b||G>A))b=n,st=+r,A=G}function ge(t,e){if(!b||t-A>Jt||t-st>Te){if(b=U(x()),st=A=t,k)h("datacub_id",l)}else if(e&&t>A)A=t;if(k&&(ue!==b||A-G>5000))h("datacub_ss",`${b}.${st}.${A}`,mt,Jt/1000)}function O(t){clearTimeout(Pt),de=t===0,Pt=t==null?void 0:setTimeout(S(Vt),t)}function me(t){if((t||u.length>19||c.visibilityState==="hidden")&&!de&&!lt)O(0);else if(!Pt)O(5000)}var je=new TextEncoder;function p(t,e,n,r){if(!l)return;let i=x();if(Ft(),ge(i,!/^\$(?:pageleave|error|request|form_fields)$/.test(t)),_.n)e={...e,$d:_.n};let s=JSON.stringify([U(i),t,i,l,E,L,b,W||null,Ne++,+(Y==="granted"),+k,K?.url,fe,e,n]),o=je.encode(s).length;if(o>31000){y++;return}_.n=0,u.push([s,o]),ke(),me(r)}function qe(t,e){if(!l||typeof t!=="string")return;let n=Zt(t);if(!n)return wt("bad name");p(n,e&&typeof e==="object"&&!Array.isArray(e)&&F(e)||{})}function Ht(t=x()){if(at)bt+=t-at;at=c.visibilityState==="visible"?t:0}var ut=()=>{j=innerWidth,pt=innerHeight,fe=j<360?"xs":j<480?"s":j<768?"m":j<1280?"l":"xl",ht=Math.max(ht,scrollY+pt)};function zt(t,e){return it[t]=(it[t]||0)+1,it[t]<=e}function be(){if(!W)return;Ht();let t=bt-Tt;if(ct&&t<1)return;let e=c.documentElement.scrollHeight,n={$v:t,$s:e?ht/e:null};if(ct)n.$e=!0;if(et)n.$ec=et;if(nt)n.$rq=nt;if(rt)n.$rf=rt;et=nt=rt=0;try{Object.assign(n,q.l?.())}catch{}ct=!0,Tt=bt,p("$pageleave",n)}function Gt(t,e){if(!l)return;let n=location.pathname+(jt?location.hash.split("?")[0]:"");if(!t&&n===te)return;let r=R(location.href,jt,I.query!==!1);if(!r)return;te=n,be();let i={};if(K)i.$p=K.path;if(t&&!e)i.$b=!0;if(i.$N=e?performance.getEntriesByType?.("navigation")[0]?.type:t?"back_forward":Nt,r.q)i.$q=r.q;if(I.title!==!1&&c.title)i.$T=v(c.title,200);K=r,W=U(x()),ct=!1,bt=ht=at=Tt=0,it={},Ct.clear(),Ht(),ut(),i.$vw=j,i.$vh=pt;let s=null;if(e)try{let o=new URL(c.referrer);s=o.hostname,i.$R=R(o.href)?.path}catch{}p("$pageview",i,[r.utm,r.click_id_type,s],e)}var St=(t)=>()=>{if(!(Q&&t==="replace"&&Nt==="push"))Nt=t;w?.(),clearTimeout(Q),Q=setTimeout(S(()=>{Q=void 0,Gt()}),100)},he=(t)=>{let e=t.closest("[data-datacub-name]")?.getAttribute("data-datacub-name");return e?H(e,100):null},ye=!0;function Pe(t){let e="";for(let n=0;t&&n<10&&t!==c.body;n++,t=t.parentElement){let r=1;for(let o=t.previousElementSibling;o;o=o.previousElementSibling)if(o.localName===t.localName)r++;let i=t.id,s=t.getAttribute("data-datacub-name");e=`${t.localName}${i&&!/\d{4}|[\da-f]{8}|^:|radix-|headlessui-|mui-|ember\d|react-select/i.test(i)?`#${v(i,64)}`:""}${r>1?`:${r}`:""}${s?`[${v(s,64)}]`:""}${e&&">"}${e}`}return e.slice(-512)}function Le(t){let e=t.querySelector(`input,textarea,select,[contenteditable],${kt}`)?"":(t.textContent||"").replace(/\s+/g," ").trim();return v(e&&e.length<101?e:t.getAttribute("aria-label")||t.getAttribute("title")||t.querySelector("img")?.getAttribute("alt")||"",100)||void 0}function Ue(t,e){w?.(),ot=void 0;let n=c.activeElement,r=new MutationObserver(()=>w?.()),i=setTimeout(S(()=>{w?.();let s=e.target.closest('a[href]:not([href^="javascript:"]):not([href^="#"])');if(c.activeElement===n&&!(s&&!e.defaultPrevented)&&!(ot&&!ot.defaultPrevented))p("$deadclick",t)}),1000);w=()=>{r.disconnect(),clearTimeout(i),w=void 0},r.observe(c,{subtree:!0,childList:!0,attributes:!0,characterData:!0})}function Me(t){let e=t.target,n=t;if(!l||!(e instanceof Element)||e.closest(`${kt},input:not([type=submit]):not([type=button]),textarea,select,[contenteditable]:not([contenteditable=false])`))return;let r=e.closest("a,button,summary,input,[data-datacub-name],[role=button],[role=link],[role=menuitem],[role=tab]"),i=!r&&!/^(?:canvas|video)$/.test(e.localName)&&getComputedStyle(e).cursor==="pointer",s=r||e,o={$t:s.localName,$n:he(e),$g:Pe(s)};if(s.closest("form"))o.$o=!0;if(n.detail)o.$cx=Math.round(n.clientX/j*100),o.$cy=Math.round(n.clientY/pt*100);if((r||i)&&I.text!==!1)o.$l=Le(s);if(r){let a=r.getAttribute("role");if(a&&/^(?:button|link|menuitem|tab)$/.test(a))o.$r=a;if(r.localName==="input")o.$y=r.type;if(r.localName==="a"&&r.hasAttribute("href"))o.$h=R(r.href)?.url;p("$click",o)}if(ye&&n.detail===3&&!(s.textContent?.trim()&&getSelection()?.isCollapsed===!1))p("$rageclick",{...o});if((r||i)&&!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&!s.closest("[target=_blank],[download]"))Ue(o,t)}var _t=(t)=>({$f:he(t),$a:R(new URL(t.getAttribute("action")||"",location.href).href)?.url,$i:t.querySelectorAll("input,select,textarea").length});function De(t){let e=t.target;if(ot=t,!l||e.localName!=="form"||e.closest(kt))return;p("$form_submit",_t(e))}var we=(t)=>{let e=t.target.form;return l&&e&&I.forms!==!1&&!e.closest(kt)?e:null},ee=new WeakSet;function Fe(t){w?.();let e=we(t);if(e&&!ee.has(e))ee.add(e),p("$form_start",_t(e))}var tt=new Map;function He(t){w?.();let e=we(t);if(!e)return;let n=tt.get(e)||0;if(tt.set(e,n+1),!n)setTimeout(S(()=>{if(zt("i",10))p("$form_invalid",{..._t(e),$iv:tt.get(e)});tt.delete(e)}))}var ne=(t)=>t.replace(/https?:\/\/[^\s'"<>()]+/g,(e)=>{let n=/(?::\d+){1,2}$/.exec(e)?.[0]||"";return(R(e.slice(0,e.length-n.length))?.url??"")+n});function Rt(t,e,n,r,i){let s=`${r}`.startsWith(T.slice(0,-5));if(!l||I.errors===!1||t==="resource"&&(!i||s))return;et++;let o=e&&typeof e==="object"?e:{},a=v(ne(`${o.message??n??(e&&e!==o?e:"")}`).replace(/(["'\u201c\u201d\u00ab\u00bb\u2018\u2019])[^"'\u201c\u201d\u00ab\u00bb\u2018\u2019]*["'\u201c\u201d\u00ab\u00bb\u2018\u2019]/g,'"\u2026"'),200),f=typeof o.stack==="string"?v(ne(o.stack.split(`
|
|
2
2
|
`).filter((m)=>/:\d+:\d+/.test(m)).slice(0,5).map((m)=>m.trim().replace(/@(?=https?:)/," ")).join(`
|
|
3
3
|
`)),1000):void 0,g=`${t}${o.name}${a}${f?.split(`
|
|
4
|
-
`)[0]}${r}`;if(
|
|
4
|
+
`)[0]}${r}`;if(Ct.has(g)||!zt("e",20))return;Ct.add(g),p("$error",{$ek:t,$en:typeof o.name==="string"?v(o.name,64):void 0,$em:a||void 0,$es:f||void 0,$eu:r?R(`${r}`)?.url:void 0,$et:i})}function $e(t,e,n,r,i){if(!l||I.network===!1)return;let s=new URL(e,location.href).href;if(s.startsWith(T.slice(0,-5)))return;nt++;let o=x()-r,a=i==="AbortError"?"abort":i?"network_error":n>399?"http_error":o>2999&&"slow";if(!a)return;if(a!=="slow"&&a!=="abort")rt++;if(zt("r",30))p("$request",{$nm:`${t}`.toUpperCase().slice(0,10),$nu:R(s)?.url,$ns:n,$nd:o,$nk:a})}var re=S($e);function ke(){let t=u.length-1000;if(t>0)y+=u.splice(0,t).length}function ze(){if(!J)try{let r=(s)=>+matchMedia(`(${s})`).matches,i=navigator;J=[screen.width,screen.height,Math.round(devicePixelRatio*100)/100,null,i.hardwareConcurrency,i.deviceMemory,i.maxTouchPoints,r("pointer:coarse")?"c":"f",r("prefers-color-scheme:dark")?"d":"l",r("prefers-reduced-motion:reduce")]}catch{J=Array(10)}let t=navigator.connection||{},e=q.h||[];return[...J,t.effectiveType,t.rtt,t.downlink,+t.saveData,e[0],e[1],-new Date().getTimezoneOffset()]}var Ut=(t,e)=>`${JSON.stringify([3,Dt,x(),Ot,e,le,navigator.language,!!navigator.webdriver,ze()]).slice(0,-1)},${t.map((n)=>n[0])}]`;function Mt(t){let e=0,n=200;while(e<u.length&&e<100){if(n+=u[e][1]+1,n>t)break;e++}return u.splice(0,e||1)}var At=!1;async function Vt(){if(O(),V)At=!0;if(V||yt||!u.length||!navigator.onLine)return;V=!0;let t=Mt(30720),e=y;y=0;let n=0;try{let r=await gt(T,{method:"POST",body:Ut(t,e),keepalive:!0,credentials:"omit",referrerPolicy:"no-referrer"}),i=r.status;if(i===401||i===403)yt=!0,u=[];else if(i===429||i>499)n=Math.min(+(r.headers.get("Retry-After")||0),3600)*1000||-1;else if(lt=0,i>299)y+=t.length+e;else{let s=await r.json().catch(()=>0);if(s.directives?.includes("rotate_anon_id"))Bt();if(s.feedback)$t()}}catch{n=-1}V=!1;try{if(n&&l){if(u=t.concat(u),y+=e,ke(),++lt<11)O(n>0?n:Math.random()*Math.min(1000*2**lt,300000))}else if(u.length)me(At);At=!1}catch{}}function ie(){if(w?.(),be(),O(),!V&&typeof Request==="function"&&"keepalive"in Request.prototype){let t=61440;while(u.length&&!yt&&t>2048){let e=Mt(t),n=y,r=Ut(e,n);t-=r.length,y=0;let i=()=>{u=e.concat(u),y+=n,O(1000)};try{gt(T,{method:"POST",body:r,keepalive:!0,credentials:"omit",referrerPolicy:"no-referrer"}).catch(i)}catch{i();break}}}else{let t=61440;while(u.length&&!yt&&navigator.sendBeacon){let e=Mt(t);if(navigator.sendBeacon(T,Ut(e,y)))y=0;else{if(u=e.concat(u),e.length<2)break;t/=2}}}if(u.length)O(1000)}function _e(t){Y=t?"granted":"not_required";for(let n of pe().reverse())if(h("datacub_tld","1",n,9),X().datacub_tld){h("datacub_tld","",n),mt=n;break}let e=X().datacub_id;if(l=e&&It.test(e)?e:U(),h("datacub_id",l),k=X().datacub_id===l,t){for(let n of["",mt])h("datacub_optout","",n);p("$consent",{$m:/^(?:banner|settings|api|cmp)$/.test(`${t.method}`)?t.method:"api",$P:typeof t.policyVersion==="string"?H(t.policyVersion,64):null})}if(P)xe(...P);if(P=null,Gt(!0,!0),se&&!q.v)q.v=Ot,q.e=(n,r)=>n==="$form_fields"&&I.forms!==!1&&p(n,r),q.f=_t,window.__datacub=q,ve(`sdk/insights-${Ot}.min.js`,"sha384-7xNcWolajp48vRTTBdYbGMF2VDBSxZ5qtqZeoosFSuy8Os18qOd9cEUDuSCp9I9z")}function ve(t,e){try{let n=c.createElement("script");if(n.src=T.slice(0,-5)+t,n.async=!0,n.referrerPolicy="no-referrer",e)n.integrity=e,n.crossOrigin="anonymous";n.setAttribute("fetchpriority","low"),(c.head||c.documentElement).append(n)}catch{}}function $t(t){if(!ae||!l||dt===1)return;if(t)dt=t;if(!c.querySelector('script[src*="/v1/feedback.js"]'))ve("feedback.js")}var Ge=()=>{let t=dt;return dt=1,t!==1&&(t||[])};function Ve(t={}){if(!l&&(!qt||t.overrideGPC))_e(t)}function Ee(){Y="denied",O(),u=[];for(let t of oe)for(let e of["",...pe()])h(t,"",e);l=b=W="",E=L=P=K=null,k=!1,h("datacub_optout","1")}function xe(t,e,n){if(Ft(),E&&E!==t)Bt();if(e!==L&&k)h("datacub_a",e);if(L=e,E!==t){if(E=t,k)h("datacub_u",t);n.$A=l}for(let r in n)return p(n.$A?"$identify":"$set",n,0,!0)}function Be(t,e){if(t&&typeof t==="object")e=t,t=e.id??e.userId??e.user_id;let n=[l,b,W],r=xt(t,n),i=e?.account==null?null:xt(e.account,n);if(!r||e?.account!=null&&!i)return wt("bad id");let s=e&&F(e)||{};for(let o in s){let a=/^(?:account|id|user_?id|(email)|(?:full_?)?(name)|(phone)(?:_?number)?)$/i.exec(o);if(a){let f=a[1]||a[2]||a[3];if(f)s[`$${f.toLowerCase()}`]=e[o];delete s[o]}}if(l)xe(r,i,s);else if(Y==="pending")P=[r,i,s]}function Bt(){if(P=null,!l)return;if(Vt(),l=U(),E=L=null,b="",k){h("datacub_id",l);for(let t of oe.slice(1))h(t,"")}}function Ke(t,e={}){if(ce=/^(?:localhost|127\.0\.0\.1|\[::1\])$|\.(?:localhost|test)$/.test(location.hostname),ft||typeof t!=="string")return;if(/^sk_/.test(t))return console.error("[datacub] refused a secret key. Use your project ID.");let n;try{n=new URL(e.apiHost||"https://in.datacub.to",location.href)}catch{}if(!/^(?:pk_(?:live|test)_[A-Za-z0-9]{24,48}|[a-z0-9]{8})$/.test(t))return wt("init: bad key");if(!n||n.username||n.password||!(n.protocol==="https:"||n.protocol==="http:"&&/^(?:localhost|127\.0\.0\.1)$/.test(n.hostname)))return wt("init: bad apiHost");if(ft=!0,Dt=t,B=`_${t.replace(/^pk_[a-z]+_/,"").slice(0,8)}`,T=`${n.origin}${n.pathname.replace(/\/+$/,"")}/v1/batch`,jt=e.hashRouting===!0,le=typeof e.release==="string"&&!z(e.release)?e.release.slice(0,64):null,I=e.capture&&typeof e.capture==="object"&&e.capture||{},se=e.insights!==!1,ae=e.feedback!==!1,d(c,"click",(r)=>r.target?.closest?.("[data-datacub-feedback]")&&$t(["feedback",[]])),gt=fetch,qt=navigator.globalPrivacyControl===!0,qt||X().datacub_optout)Ee();else if(!e.requireConsent)_e();if(ye=e.rageClicks!==!1,e.autocapture!==!1)d(c,"click",Me),d(c,"submit",De),d(c,"input",Fe),d(c,"invalid",He);for(let r of["pointerdown","keydown","scroll"])d(c,r,(i)=>{let s=x();if(i.target===c)ut();if(r==="scroll")w?.();if(b&&c.visibilityState==="visible"&&s-Qt>5000)Qt=s,Ft(),ge(s,!0)});d(c,"visibilitychange",()=>{if(Ht(),c.visibilityState==="hidden")ie()}),ut(),d(window,"resize",ut),d(window,"pagehide",ie),d(window,"pageshow",(r)=>r.persisted&&Gt(!0)),d(window,"online",Vt),d(window,"popstate",St("pop")),d(window,"hashchange",St("hash"));for(let r of["pushState","replaceState"]){let i=history[r];history[r]=function(...s){i.apply(this,s),St(r==="pushState"?"push":"replace")()}}try{d(window,"error",(o)=>o instanceof ErrorEvent?Rt("js",o.error,o.message,o.filename):Rt("resource",0,"",o.target.src||o.target.href,o.target.localName)),d(window,"unhandledrejection",(o)=>Rt("rejection",o.reason)),window.fetch=function(...o){let a=gt.apply(this,o);try{let f=x(),g=o[0],m=`${g.url||g}`,D=o[1]?.method||g.method||"GET";return a.then((C)=>{try{re(D,C.url||m,C.type==="opaque"?200:C.status,f)}catch{}return C},(C)=>{throw re(D,m,0,f,C?.name||"Error"),C})}catch{}return a};let r=XMLHttpRequest.prototype,{open:i,send:s}=r;r.open=function(...o){return this._x=o,i.apply(this,o)},r.send=function(...o){if(this._x&&!this._t)for(let a of["load","error","abort","timeout"])d(this,a,()=>$e(this._x?.[0],`${this._x?.[1]}`,this.status,this._t,a==="load"?"":a==="abort"?"AbortError":"TypeError"));return this._t=x(),s.apply(this,o)}}catch{}}var N=(t)=>S((...e)=>{if(typeof window>"u")return;if(ft)t(...e);else if(Lt.length<100)Lt.push([t,e])}),Xe={init:S((t,e)=>{if(typeof window>"u"||!globalThis.crypto?.getRandomValues)return;c=document;let n=S(()=>{Ke(t,e);for(let[r,i]of Lt.splice(0))if(ft)r(...i)});if(c.prerendering)d(c,"prerenderingchange",n);else n()}),track:N(qe),identify:N(Be),reset:N(Bt),consent:{grant:N(Ve),revoke:N(Ee)},ask:N((...t)=>$t(["ask",t])),feedback:N(()=>$t(["feedback",[]])),_fb:()=>[Y,k,Dt,T,l,E,b,p,Ge]},M=Xe;var vt=window;if(!vt.datacub?._fb){let t=Array.isArray(vt.datacub)?vt.datacub:[],e=document.currentScript,n=e?.dataset,r=e?.src?new URL(e.src).origin:void 0,i=M.init;M.init=(o,a)=>{let f=a?.apiHost||r;return i(o,f?{...a,apiHost:f}:a)},vt.datacub=M;let s=n?.id||n?.key;if(s)M.init(s,{apiHost:n.apiHost,requireConsent:n.requireConsent!=null,feedback:n.feedback!=="off"});for(let o of t)try{let[a,...f]=o,g=String(a).split(".").reduce((m,D)=>m&&Object.hasOwn(m,D)?m[D]:void 0,M);if(typeof g==="function")g(...f)}catch{}}})();
|
package/dist/datacub.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var v={n:0},$t=(t)=>t.replace(/[\u0660-\u0669\u06f0-\u06f9\uff10-\uff19]/g,(e)=>String(e.charCodeAt(0)&15)),we=/[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]/g,Gt=(t)=>$t(t).replace(we,""),_e=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|bearer\s+\S{16,}|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]+|PRIVATE KEY|[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}|eyJ[\w-]+\.[\w-]+\.[\w-]*|\d(?:[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]*\d){8,}|[\w+/=]{32,}/gi;function Y(t){let e="",n=0;for(let r of $t(t).matchAll(_e)){if(/^[0-9a-f]{8}-/i.test(r[0])&&r[0].length===36)continue;e+=`${t.slice(n,r.index)}[redacted]`,n=r.index+r[0].length,v.n++}return e+t.slice(n)}function M(t,e=1024){if(t=t.normalize("NFC"),t.length>256||t.trim().split(/\s+/).length>11)return v.n++,"[redacted]";return Y(t).slice(0,e).replace(/[\uD800-\uDBFF]$/,"")}var D=(t)=>/[\u0000-\u001f\u007f-\u009f\u200e\u200f\u061c\u202a-\u202e\u2066-\u2069]/.test(t),ve=/(?:passw(?:or)?d|passcode|pwd|pin|pincode|otp|otpcode|onetimecode|mfacode|2facode|tfacode|smscode|secretkey|privatekey|authcode|verificationcode|securitycode|resetcode|cvv|cvc|cardnumber|ccnumber|creditcard|pan|iban|iqama|hawiya|nationalid|nid|idnumber|ssn|token|authorization|secret|apikey|sessionid|cookie|jwt|bearer|csrf|xsrf|passport|\u0643\u0644\u0645\u0647\u0627\u0644\u0645\u0631\u0648\u0631|\u0643\u0644\u0645\u0647\u0627\u0644\u0633\u0631|\u0627\u0644\u0631\u0645\u0632\u0627\u0644\u0633\u0631\u064a|\u0627\u0644\u0631\u0642\u0645\u0627\u0644\u0633\u0631\u064a|\u0631\u0645\u0632\u0627\u0644\u062a\u062d\u0642\u0642|\u0631\u0642\u0645\u0627\u0644\u0647\u0648\u064a\u0647|\u0627\u0644\u0647\u0648\u064a\u0647\u0627\u0644\u0648\u0637\u0646\u064a\u0647|\u0627\u0644\u0627\u0642\u0627\u0645\u0647|\u0627\u0644\u0628\u0637\u0627\u0642\u0647|\u0627\u0644\u0627\u064a\u0628\u0627\u0646)$/;function Vt(t,e){let n=t.normalize("NFKD").replace(/[\p{M}\u0640]/gu,"").replace(/\u0629/g,"\u0647").replace(/\u0649/g,"\u064a").replace(/(\p{Ll})(?=\p{Lu})|(\p{N}+)/gu,"$1 $2 ").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);while(n.length>1&&/^\p{N}+$/u.test(n[n.length-1]))n.pop();return!t||[...t].length>200||/\./.test(t)||D(t)||/^(?:__proto__|constructor|prototype)$/.test(t)||e&&/^(?:\$|(?:distinct_id|person_id|project_id|timestamp|uuid|ip|api_key)$)/.test(t)||ve.test(n.join(""))&&!/^(?:japan|span|timespan|lifespan|wingspan|saucepan|spin|chopin|android)$/.test(n[n.length-1])||n.some((r)=>/^(?:password|passwd|pwd|passcode|otp|pin|secret|iqama|ssn|cvv|cvc|iban)$/.test(r))}function U(t,e=0){if(typeof t==="string")return M(t);if(typeof t==="number")return Number.isFinite(t)?Number.isInteger(t)&&Y(`${t}`)!==`${t}`?"[redacted]":t:void 0;if(typeof t==="boolean"||t===null)return t;if(t instanceof Date)return Number.isNaN(+t)?void 0:t.toISOString();if(typeof t!=="object")return;if(e>2)return"[depth]";if(Array.isArray(t))return t.slice(0,100).map((i)=>U(i,e+1)).filter((i)=>i!==void 0);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n)return;let r={};for(let[i,s]of Object.entries(t).slice(0,200)){let o=i.trim();if(Vt(o,!e))v.n++;else{let a=U(s,e+1);if(a!==void 0)r[o]=a}}return r}function Bt(t){let e=t;try{e=decodeURIComponent(t)}catch{}e=$t(e);let n=v.n;if(Y(e)!==e)return v.n=n+1,":redacted";if(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(e))return":uuid";if(/^[0-9a-f]{16,}$/i.test(e))return e.length===24?":id":":hash";if(/^[\w-]{20,}$/.test(e)&&/\d/.test(e)&&/[a-z]/.test(e)&&/[A-Z]/.test(e))return":token";let r=e.replace(/\D/g,"").length;return r&&(r===e.length||r>3&&r*2>=e.length)?":id":t}var ke=/^(?:reset|invite|sid|token|jwt|otp|code|key|state|sig(?:nature)?|auth\w*|nonce|session\w*|hash|q|query|search\w*|s|keywords?|term|text|msg|message|comments?|\w*name|e?-?mail\w*|phone|mobile|tel|address\w*|city|zip|postcode|dob|birth\w*)$/i,Ee=(t)=>/^(?:[a-z0-9][a-z0-9._~-]*|[A-Z0-9][A-Z0-9_-]*)$/.test(t)&&!(t.length>=8&&/\d/.test(t)&&/[a-z]/i.test(t)),k=(t,e)=>Y(t.normalize("NFC")).slice(0,e),Ht=(t)=>t.split("/").map((e)=>e&&Bt(e)).join("/");function R(t,e,n){let r;try{r=new URL(t)}catch{return null}let i=r.protocol;if(/^(?:mailto|tel|sms|whatsapp):$/.test(i))return{url:i,path:i};if(!/^https?:$/.test(i))return null;let s=Ht(r.pathname);if(e&&/^#!?\//.test(r.hash))s+=`#${Ht(r.hash.slice(1).split("?")[0])}`;s=s.slice(0,1024);let o={url:(r.origin+s).slice(0,2048),path:s};for(let[a,p]of r.searchParams){let h=a.toLowerCase();if(/^utm_(?:source|medium|campaign|term|content)$/.test(h)&&p)o.utm={...o.utm,[h.slice(4)]:M(p,200)};else if(/^(?:gclid|gbraid|wbraid|fbclid|ttclid|msclkid|sccid|twclid|li_fat_id)$/.test(h))o.click_id_type=h.replace(/^[gw]braid$/,"gclid");else if(n&&Object.keys(o.q||{}).length<30){let y=Bt(p);o.q??={},o.q[k(a,64)]=Vt(a,!1)||ke.test(a)||p.length>40||!(y[0]===":"||Ee(p))?"":y===":redacted"?"":y}}return o}function Kt(t){let e=t.trim().normalize("NFC");return!e||[...e].length>100||e[0]==="$"||D(e)||/[0-9a-f]{8}-[0-9a-f]{4}-|[0-9a-f]{16}|@/i.test(e)||/\d{6}/.test(Gt(e))?null:e}function wt(t,e){if(typeof t==="number"&&Number.isFinite(t))t=`${t}`;if(typeof t!=="string")return null;let n=t.trim().normalize("NFC"),r=Gt(n),i=0;for(let s=0;s<r.length;s++){let o=+r[r.length-1-s];i+=s%2?o>4?o*2-9:o*2:o}return!n||[...n].length>128||/^(?:null|undefined|0|-1|anonymous|guest|\[object object\]|none|nan|false|true|user|test|unknown|not_authenticated|distinct_id|id)$/i.test(n)||D(n)||/@|^eyJ/.test(n)||/^(?:[12]\d{9}|(?:\+?966|00966|0)5\d{8}|\+\d{8,15})$/.test(r)||/^[2-6]\d{14,15}$/.test(r)&&i%10===0||e.includes(n)?null:n}var Et="0.4.2",Xt=1800000,xe=86400000,Se=34560000,xt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,bt=".datacub-no-capture,[data-datacub-no-capture]",ee=["datacub_id","datacub_u","datacub_a","datacub_ss"],c,lt=!1,N={},ne=!0,St=0,Q=0,tt=0,et=0,nt={},Rt=new Set,At,O=0,ut=0,w,rt,ft,W,P={},re=!1,jt="",T="",It=!1,ie=null,K="pending",Nt=!1,_=!1,G="",dt="",l="",E=null,q=null,j=null,g="",it=0,A=0,oe,z=0,X="",V=null,Re=0,ot=0,pt=0,gt=0,se="",st=!0,Z,Yt=0,u=[],Tt,ae=!1,Wt="",H=!1,at=0,mt=!1,b=0,Ct=[],x=Date.now;function ht(t){if(re)console.warn(`[datacub] ${t}`)}var S=(t)=>(...e)=>{try{t(...e)}catch{}},f=(t,e,n)=>t.addEventListener(e,S(n),!0);function L(t){let e=crypto.getRandomValues(new Uint8Array(16));for(let r=5,i=t;t&&r>=0;r--,i=Math.floor(i/256))e[r]=i&255;return e[6]=e[6]&15|(t?112:64),e[8]=e[8]&63|128,Array.from(e,(r)=>(r+256).toString(16).slice(1)).join("").replace(/(.{8})(.{4})(.{4})(.{4})/,"$1-$2-$3-$4-")}function B(){let t={};try{for(let e of c.cookie.split("; ")){let n=e.indexOf("="),r=e.slice(0,n);if(r==="datacub_optout"||G&&r.endsWith(G))t[r==="datacub_optout"?r:r.slice(0,-G.length)]=decodeURIComponent(e.slice(n+1))}}catch{}return t}function m(t,e,n=dt,r=e?Se:0){try{c.cookie=`${t==="datacub_optout"?t:t+G}=${encodeURIComponent(e||"")};Path=/;Max-Age=${r};SameSite=Lax${n}${location.protocol==="https:"?";Secure":""}`}catch{}}function ce(){let t=location.hostname.split(".");return/^[\d.]+$|:/.test(location.hostname)?[]:t.slice(0,-1).map((e,n)=>`;Domain=${t.slice(n).join(".")}`)}function qt(){if(!_)return;let t=B(),e=t.datacub_id??null;if(e!==l)l=e&&xt.test(e)?e:L(),m("datacub_id",l),g="";E=t.datacub_u??null,q=t.datacub_a??null;let[n,r,i]=(t.datacub_ss||"").split(".");if(oe=n,z=+i,n&&xt.test(n)&&z&&(n!==g||z>A))g=n,it=+r,A=z}function le(t,e){if(!g||t-A>Xt||t-it>xe){if(g=L(x()),it=A=t,_)m("datacub_id",l)}else if(e&&t>A)A=t;if(_&&(oe!==g||A-z>5000))m("datacub_ss",`${g}.${it}.${A}`,dt,Xt/1000)}function I(t){clearTimeout(Tt),ae=t===0,Tt=t==null?void 0:setTimeout(S(Dt),t)}function ue(t){if((t||u.length>19||c.visibilityState==="hidden")&&!ae&&!at)I(0);else if(!Tt)I(5000)}var Ae=new TextEncoder;function d(t,e,n,r){if(!l)return;let i=x();if(qt(),le(i,!/^\$(?:pageleave|error|request|form_fields)$/.test(t)),v.n)e={...e,$d:v.n};let s=JSON.stringify([L(i),t,i,l,E,q,g,X||null,Re++,+(K==="granted"),+_,V?.url,se,e,n]),o=Ae.encode(s).length;if(o>31000){b++;return}v.n=0,u.push([s,o]),he(),ue(r)}function Ie(t,e){if(!l||typeof t!=="string")return;let n=Kt(t);if(!n)return ht("bad name");d(n,e&&typeof e==="object"&&!Array.isArray(e)&&U(e)||{})}function Lt(t=x()){if(ot)pt+=t-ot;ot=c.visibilityState==="visible"?t:0}var ct=()=>{O=innerWidth,ut=innerHeight,se=O<360?"xs":O<480?"s":O<768?"m":O<1280?"l":"xl",gt=Math.max(gt,scrollY+ut)};function Ut(t,e){return nt[t]=(nt[t]||0)+1,nt[t]<=e}function fe(){if(!X)return;Lt();let t=pt-St;if(st&&t<1)return;let e=c.documentElement.scrollHeight,n={$v:t,$s:e?gt/e:null};if(st)n.$e=!0;if(Q)n.$ec=Q;if(tt)n.$rq=tt;if(et)n.$rf=et;Q=tt=et=0;try{Object.assign(n,P.l?.())}catch{}st=!0,St=pt,d("$pageleave",n)}function Mt(t,e){if(!l)return;let n=location.pathname+(It?location.hash.split("?")[0]:"");if(!t&&n===Wt)return;let r=R(location.href,It,N.query!==!1);if(!r)return;Wt=n,fe();let i={};if(V)i.$p=V.path;if(t&&!e)i.$b=!0;if(i.$N=e?performance.getEntriesByType?.("navigation")[0]?.type:t?"back_forward":At,r.q)i.$q=r.q;if(N.title!==!1&&c.title)i.$T=k(c.title,200);V=r,X=L(x()),st=!1,pt=gt=ot=St=0,nt={},Rt.clear(),Lt(),ct(),i.$vw=O,i.$vh=ut;let s=null;if(e)try{let o=new URL(c.referrer);s=o.hostname,i.$R=R(o.href)?.path}catch{}d("$pageview",i,[r.utm,r.click_id_type,s],e)}var _t=(t)=>()=>{if(!(Z&&t==="replace"&&At==="push"))At=t;w?.(),clearTimeout(Z),Z=setTimeout(S(()=>{Z=void 0,Mt()}),100)},de=(t)=>{let e=t.closest("[data-datacub-name]")?.getAttribute("data-datacub-name");return e?M(e,100):null},pe=!0;function Ne(t){let e="";for(let n=0;t&&n<10&&t!==c.body;n++,t=t.parentElement){let r=1;for(let o=t.previousElementSibling;o;o=o.previousElementSibling)if(o.localName===t.localName)r++;let i=t.id,s=t.getAttribute("data-datacub-name");e=`${t.localName}${i&&!/\d{4}|[\da-f]{8}|^:|radix-|headlessui-|mui-|ember\d|react-select/i.test(i)?`#${k(i,64)}`:""}${r>1?`:${r}`:""}${s?`[${k(s,64)}]`:""}${e&&">"}${e}`}return e.slice(-512)}function Te(t){let e=t.querySelector(`input,textarea,select,[contenteditable],${bt}`)?"":(t.textContent||"").replace(/\s+/g," ").trim();return k(e&&e.length<101?e:t.getAttribute("aria-label")||t.getAttribute("title")||t.querySelector("img")?.getAttribute("alt")||"",100)||void 0}function Ce(t,e){w?.(),rt=void 0;let n=c.activeElement,r=new MutationObserver(()=>w?.()),i=setTimeout(S(()=>{w?.();let s=e.target.closest('a[href]:not([href^="javascript:"]):not([href^="#"])');if(c.activeElement===n&&!(s&&!e.defaultPrevented)&&!(rt&&!rt.defaultPrevented))d("$deadclick",t)}),1000);w=()=>{r.disconnect(),clearTimeout(i),w=void 0},r.observe(c,{subtree:!0,childList:!0,attributes:!0,characterData:!0})}function Oe(t){let e=t.target,n=t;if(!l||!(e instanceof Element)||e.closest(`${bt},input:not([type=submit]):not([type=button]),textarea,select,[contenteditable]:not([contenteditable=false])`))return;let r=e.closest("a,button,summary,input,[data-datacub-name],[role=button],[role=link],[role=menuitem],[role=tab]"),i=!r&&!/^(?:canvas|video)$/.test(e.localName)&&getComputedStyle(e).cursor==="pointer",s=r||e,o={$t:s.localName,$n:de(e),$g:Ne(s)};if(s.closest("form"))o.$o=!0;if(n.detail)o.$cx=Math.round(n.clientX/O*100),o.$cy=Math.round(n.clientY/ut*100);if((r||i)&&N.text!==!1)o.$l=Te(s);if(r){let a=r.getAttribute("role");if(a&&/^(?:button|link|menuitem|tab)$/.test(a))o.$r=a;if(r.localName==="input")o.$y=r.type;if(r.localName==="a"&&r.hasAttribute("href"))o.$h=R(r.href)?.url;d("$click",o)}if(pe&&n.detail===3&&!(s.textContent?.trim()&&getSelection()?.isCollapsed===!1))d("$rageclick",{...o});if((r||i)&&!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&!s.closest("[target=_blank],[download]"))Ce(o,t)}var yt=(t)=>({$f:de(t),$a:R(new URL(t.getAttribute("action")||"",location.href).href)?.url,$i:t.querySelectorAll("input,select,textarea").length});function Pe(t){let e=t.target;if(rt=t,!l||e.localName!=="form"||e.closest(bt))return;d("$form_submit",yt(e))}var ge=(t)=>{let e=t.target.form;return l&&e&&N.forms!==!1&&!e.closest(bt)?e:null},Zt=new WeakSet;function je(t){w?.();let e=ge(t);if(e&&!Zt.has(e))Zt.add(e),d("$form_start",yt(e))}var J=new Map;function qe(t){w?.();let e=ge(t);if(!e)return;let n=J.get(e)||0;if(J.set(e,n+1),!n)setTimeout(S(()=>{if(Ut("i",10))d("$form_invalid",{...yt(e),$iv:J.get(e)});J.delete(e)}))}var Jt=(t)=>t.replace(/https?:\/\/[^\s'"<>()]+/g,(e)=>{let n=/(?::\d+){1,2}$/.exec(e)?.[0]||"";return(R(e.slice(0,e.length-n.length))?.url??"")+n});function vt(t,e,n,r,i){let s=`${r}`.startsWith(T.slice(0,-5));if(!l||N.errors===!1||t==="resource"&&(!i||s))return;Q++;let o=e&&typeof e==="object"?e:{},a=k(Jt(`${o.message??n??(e&&e!==o?e:"")}`).replace(/(["'\u201c\u201d\u00ab\u00bb\u2018\u2019])[^"'\u201c\u201d\u00ab\u00bb\u2018\u2019]*["'\u201c\u201d\u00ab\u00bb\u2018\u2019]/g,'"\u2026"'),200),p=typeof o.stack==="string"?k(Jt(o.stack.split(`
|
|
1
|
+
var _={n:0},kt=(t)=>t.replace(/[\u0660-\u0669\u06f0-\u06f9\uff10-\uff19]/g,(e)=>String(e.charCodeAt(0)&15)),Ee=/[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]/g,Bt=(t)=>kt(t).replace(Ee,""),xe=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|bearer\s+\S{16,}|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]+|PRIVATE KEY|[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}|eyJ[\w-]+\.[\w-]+\.[\w-]*|\d(?:[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]*\d){8,}|[\w+/=]{32,}/gi;function Y(t){let e="",n=0;for(let r of kt(t).matchAll(xe)){if(/^[0-9a-f]{8}-/i.test(r[0])&&r[0].length===36)continue;e+=`${t.slice(n,r.index)}[redacted]`,n=r.index+r[0].length,_.n++}return e+t.slice(n)}function D(t,e=1024){if(t=t.normalize("NFC"),t.length>256||t.trim().split(/\s+/).length>11)return _.n++,"[redacted]";return Y(t).slice(0,e).replace(/[\uD800-\uDBFF]$/,"")}var F=(t)=>/[\u0000-\u001f\u007f-\u009f\u200e\u200f\u061c\u202a-\u202e\u2066-\u2069]/.test(t),Se=/(?:passw(?:or)?d|passcode|pwd|pin|pincode|otp|otpcode|onetimecode|mfacode|2facode|tfacode|smscode|secretkey|privatekey|authcode|verificationcode|securitycode|resetcode|cvv|cvc|cardnumber|ccnumber|creditcard|pan|iban|iqama|hawiya|nationalid|nid|idnumber|ssn|token|authorization|secret|apikey|sessionid|cookie|jwt|bearer|csrf|xsrf|passport|\u0643\u0644\u0645\u0647\u0627\u0644\u0645\u0631\u0648\u0631|\u0643\u0644\u0645\u0647\u0627\u0644\u0633\u0631|\u0627\u0644\u0631\u0645\u0632\u0627\u0644\u0633\u0631\u064a|\u0627\u0644\u0631\u0642\u0645\u0627\u0644\u0633\u0631\u064a|\u0631\u0645\u0632\u0627\u0644\u062a\u062d\u0642\u0642|\u0631\u0642\u0645\u0627\u0644\u0647\u0648\u064a\u0647|\u0627\u0644\u0647\u0648\u064a\u0647\u0627\u0644\u0648\u0637\u0646\u064a\u0647|\u0627\u0644\u0627\u0642\u0627\u0645\u0647|\u0627\u0644\u0628\u0637\u0627\u0642\u0647|\u0627\u0644\u0627\u064a\u0628\u0627\u0646)$/;function Kt(t,e){let n=t.normalize("NFKD").replace(/[\p{M}\u0640]/gu,"").replace(/\u0629/g,"\u0647").replace(/\u0649/g,"\u064a").replace(/(\p{Ll})(?=\p{Lu})|(\p{N}+)/gu,"$1 $2 ").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);while(n.length>1&&/^\p{N}+$/u.test(n[n.length-1]))n.pop();return!t||[...t].length>200||/\./.test(t)||F(t)||/^(?:__proto__|constructor|prototype)$/.test(t)||e&&/^(?:\$|(?:distinct_id|person_id|project_id|timestamp|uuid|ip|api_key)$)/.test(t)||Se.test(n.join(""))&&!/^(?:japan|span|timespan|lifespan|wingspan|saucepan|spin|chopin|android)$/.test(n[n.length-1])||n.some((r)=>/^(?:password|passwd|pwd|passcode|otp|pin|secret|iqama|ssn|cvv|cvc|iban)$/.test(r))}function M(t,e=0){if(typeof t==="string")return D(t);if(typeof t==="number")return Number.isFinite(t)?Number.isInteger(t)&&Y(`${t}`)!==`${t}`?"[redacted]":t:void 0;if(typeof t==="boolean"||t===null)return t;if(t instanceof Date)return Number.isNaN(+t)?void 0:t.toISOString();if(typeof t!=="object")return;if(e>2)return"[depth]";if(Array.isArray(t))return t.slice(0,100).map((i)=>M(i,e+1)).filter((i)=>i!==void 0);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n)return;let r={};for(let[i,s]of Object.entries(t).slice(0,200)){let o=i.trim();if(Kt(o,!e))_.n++;else{let a=M(s,e+1);if(a!==void 0)r[o]=a}}return r}function Xt(t){let e=t;try{e=decodeURIComponent(t)}catch{}e=kt(e);let n=_.n;if(Y(e)!==e)return _.n=n+1,":redacted";if(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(e))return":uuid";if(/^[0-9a-f]{16,}$/i.test(e))return e.length===24?":id":":hash";if(/^[\w-]{20,}$/.test(e)&&/\d/.test(e)&&/[a-z]/.test(e)&&/[A-Z]/.test(e))return":token";let r=e.replace(/\D/g,"").length;return r&&(r===e.length||r>3&&r*2>=e.length)?":id":t}var Re=/^(?:reset|invite|sid|token|jwt|otp|code|key|state|sig(?:nature)?|auth\w*|nonce|session\w*|hash|q|query|search\w*|s|keywords?|term|text|msg|message|comments?|\w*name|e?-?mail\w*|phone|mobile|tel|address\w*|city|zip|postcode|dob|birth\w*)$/i,Ae=(t)=>/^(?:[a-z0-9][a-z0-9._~-]*|[A-Z0-9][A-Z0-9_-]*)$/.test(t)&&!(t.length>=8&&/\d/.test(t)&&/[a-z]/i.test(t)),v=(t,e)=>Y(t.normalize("NFC")).slice(0,e),Vt=(t)=>t.split("/").map((e)=>e&&Xt(e)).join("/");function R(t,e,n){let r;try{r=new URL(t)}catch{return null}let i=r.protocol;if(/^(?:mailto|tel|sms|whatsapp):$/.test(i))return{url:i,path:i};if(!/^https?:$/.test(i))return null;let s=Vt(r.pathname);if(e&&/^#!?\//.test(r.hash))s+=`#${Vt(r.hash.slice(1).split("?")[0])}`;s=s.slice(0,1024);let o={url:(r.origin+s).slice(0,2048),path:s};for(let[a,p]of r.searchParams){let h=a.toLowerCase();if(/^utm_(?:source|medium|campaign|term|content)$/.test(h)&&p)o.utm={...o.utm,[h.slice(4)]:D(p,200)};else if(/^(?:gclid|gbraid|wbraid|fbclid|ttclid|msclkid|sccid|twclid|li_fat_id)$/.test(h))o.click_id_type=h.replace(/^[gw]braid$/,"gclid");else if(n&&Object.keys(o.q||{}).length<30){let y=Xt(p);o.q??={},o.q[v(a,64)]=Kt(a,!1)||Re.test(a)||p.length>40||!(y[0]===":"||Ae(p))?"":y===":redacted"?"":y}}return o}function Yt(t){let e=t.trim().normalize("NFC");return!e||[...e].length>100||e[0]==="$"||F(e)||/[0-9a-f]{8}-[0-9a-f]{4}-|[0-9a-f]{16}|@/i.test(e)||/\d{6}/.test(Bt(e))?null:e}function _t(t,e){if(typeof t==="number"&&Number.isFinite(t))t=`${t}`;if(typeof t!=="string")return null;let n=t.trim().normalize("NFC"),r=Bt(n),i=0;for(let s=0;s<r.length;s++){let o=+r[r.length-1-s];i+=s%2?o>4?o*2-9:o*2:o}return!n||[...n].length>128||/^(?:null|undefined|0|-1|anonymous|guest|\[object object\]|none|nan|false|true|user|test|unknown|not_authenticated|distinct_id|id)$/i.test(n)||F(n)||/@|^eyJ/.test(n)||/^(?:[12]\d{9}|(?:\+?966|00966|0)5\d{8}|\+\d{8,15})$/.test(r)||/^[2-6]\d{14,15}$/.test(r)&&i%10===0||e.includes(n)?null:n}var St="0.5.0",Wt=1800000,Ne=86400000,Te=34560000,Rt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,$t=".datacub-no-capture,[data-datacub-no-capture]",re=["datacub_id","datacub_u","datacub_a","datacub_ss"],c,lt=!1,T={},ie=!0,oe=!0,ut=0,At=0,Q=0,tt=0,et=0,nt={},Nt=new Set,Tt,O=0,ft=0,w,rt,dt,W,P={},se=!1,Lt="",I="",It=!1,ae=null,K="pending",jt=!1,k=!1,G="",pt="",l="",E=null,L=null,q=null,g="",it=0,A=0,ce,z=0,X="",V=null,Ie=0,ot=0,gt=0,mt=0,le="",st=!0,Z,Zt=0,u=[],Ct,ue=!1,Jt="",H=!1,at=0,ht=!1,b=0,Ot=[],x=Date.now;function bt(t){if(se)console.warn(`[datacub] ${t}`)}var S=(t)=>(...e)=>{try{t(...e)}catch{}},f=(t,e,n)=>t.addEventListener(e,S(n),!0);function U(t){let e=crypto.getRandomValues(new Uint8Array(16));for(let r=5,i=t;t&&r>=0;r--,i=Math.floor(i/256))e[r]=i&255;return e[6]=e[6]&15|(t?112:64),e[8]=e[8]&63|128,Array.from(e,(r)=>(r+256).toString(16).slice(1)).join("").replace(/(.{8})(.{4})(.{4})(.{4})/,"$1-$2-$3-$4-")}function B(){let t={};try{for(let e of c.cookie.split("; ")){let n=e.indexOf("="),r=e.slice(0,n);if(r==="datacub_optout"||G&&r.endsWith(G))t[r==="datacub_optout"?r:r.slice(0,-G.length)]=decodeURIComponent(e.slice(n+1))}}catch{}return t}function m(t,e,n=pt,r=e?Te:0){try{c.cookie=`${t==="datacub_optout"?t:t+G}=${encodeURIComponent(e||"")};Path=/;Max-Age=${r};SameSite=Lax${n}${location.protocol==="https:"?";Secure":""}`}catch{}}function fe(){let t=location.hostname.split(".");return/^[\d.]+$|:/.test(location.hostname)?[]:t.slice(0,-1).map((e,n)=>`;Domain=${t.slice(n).join(".")}`)}function Ut(){if(!k)return;let t=B(),e=t.datacub_id??null;if(e!==l)l=e&&Rt.test(e)?e:U(),m("datacub_id",l),g="";E=t.datacub_u??null,L=t.datacub_a??null;let[n,r,i]=(t.datacub_ss||"").split(".");if(ce=n,z=+i,n&&Rt.test(n)&&z&&(n!==g||z>A))g=n,it=+r,A=z}function de(t,e){if(!g||t-A>Wt||t-it>Ne){if(g=U(x()),it=A=t,k)m("datacub_id",l)}else if(e&&t>A)A=t;if(k&&(ce!==g||A-z>5000))m("datacub_ss",`${g}.${it}.${A}`,pt,Wt/1000)}function N(t){clearTimeout(Ct),ue=t===0,Ct=t==null?void 0:setTimeout(S(zt),t)}function pe(t){if((t||u.length>19||c.visibilityState==="hidden")&&!ue&&!at)N(0);else if(!Ct)N(5000)}var je=new TextEncoder;function d(t,e,n,r){if(!l)return;let i=x();if(Ut(),de(i,!/^\$(?:pageleave|error|request|form_fields)$/.test(t)),_.n)e={...e,$d:_.n};let s=JSON.stringify([U(i),t,i,l,E,L,g,X||null,Ie++,+(K==="granted"),+k,V?.url,le,e,n]),o=je.encode(s).length;if(o>31000){b++;return}_.n=0,u.push([s,o]),$e(),pe(r)}function Ce(t,e){if(!l||typeof t!=="string")return;let n=Yt(t);if(!n)return bt("bad name");d(n,e&&typeof e==="object"&&!Array.isArray(e)&&M(e)||{})}function Mt(t=x()){if(ot)gt+=t-ot;ot=c.visibilityState==="visible"?t:0}var ct=()=>{O=innerWidth,ft=innerHeight,le=O<360?"xs":O<480?"s":O<768?"m":O<1280?"l":"xl",mt=Math.max(mt,scrollY+ft)};function Dt(t,e){return nt[t]=(nt[t]||0)+1,nt[t]<=e}function ge(){if(!X)return;Mt();let t=gt-At;if(st&&t<1)return;let e=c.documentElement.scrollHeight,n={$v:t,$s:e?mt/e:null};if(st)n.$e=!0;if(Q)n.$ec=Q;if(tt)n.$rq=tt;if(et)n.$rf=et;Q=tt=et=0;try{Object.assign(n,P.l?.())}catch{}st=!0,At=gt,d("$pageleave",n)}function Ft(t,e){if(!l)return;let n=location.pathname+(It?location.hash.split("?")[0]:"");if(!t&&n===Jt)return;let r=R(location.href,It,T.query!==!1);if(!r)return;Jt=n,ge();let i={};if(V)i.$p=V.path;if(t&&!e)i.$b=!0;if(i.$N=e?performance.getEntriesByType?.("navigation")[0]?.type:t?"back_forward":Tt,r.q)i.$q=r.q;if(T.title!==!1&&c.title)i.$T=v(c.title,200);V=r,X=U(x()),st=!1,gt=mt=ot=At=0,nt={},Nt.clear(),Mt(),ct(),i.$vw=O,i.$vh=ft;let s=null;if(e)try{let o=new URL(c.referrer);s=o.hostname,i.$R=R(o.href)?.path}catch{}d("$pageview",i,[r.utm,r.click_id_type,s],e)}var vt=(t)=>()=>{if(!(Z&&t==="replace"&&Tt==="push"))Tt=t;w?.(),clearTimeout(Z),Z=setTimeout(S(()=>{Z=void 0,Ft()}),100)},me=(t)=>{let e=t.closest("[data-datacub-name]")?.getAttribute("data-datacub-name");return e?D(e,100):null},he=!0;function Oe(t){let e="";for(let n=0;t&&n<10&&t!==c.body;n++,t=t.parentElement){let r=1;for(let o=t.previousElementSibling;o;o=o.previousElementSibling)if(o.localName===t.localName)r++;let i=t.id,s=t.getAttribute("data-datacub-name");e=`${t.localName}${i&&!/\d{4}|[\da-f]{8}|^:|radix-|headlessui-|mui-|ember\d|react-select/i.test(i)?`#${v(i,64)}`:""}${r>1?`:${r}`:""}${s?`[${v(s,64)}]`:""}${e&&">"}${e}`}return e.slice(-512)}function Pe(t){let e=t.querySelector(`input,textarea,select,[contenteditable],${$t}`)?"":(t.textContent||"").replace(/\s+/g," ").trim();return v(e&&e.length<101?e:t.getAttribute("aria-label")||t.getAttribute("title")||t.querySelector("img")?.getAttribute("alt")||"",100)||void 0}function qe(t,e){w?.(),rt=void 0;let n=c.activeElement,r=new MutationObserver(()=>w?.()),i=setTimeout(S(()=>{w?.();let s=e.target.closest('a[href]:not([href^="javascript:"]):not([href^="#"])');if(c.activeElement===n&&!(s&&!e.defaultPrevented)&&!(rt&&!rt.defaultPrevented))d("$deadclick",t)}),1000);w=()=>{r.disconnect(),clearTimeout(i),w=void 0},r.observe(c,{subtree:!0,childList:!0,attributes:!0,characterData:!0})}function Le(t){let e=t.target,n=t;if(!l||!(e instanceof Element)||e.closest(`${$t},input:not([type=submit]):not([type=button]),textarea,select,[contenteditable]:not([contenteditable=false])`))return;let r=e.closest("a,button,summary,input,[data-datacub-name],[role=button],[role=link],[role=menuitem],[role=tab]"),i=!r&&!/^(?:canvas|video)$/.test(e.localName)&&getComputedStyle(e).cursor==="pointer",s=r||e,o={$t:s.localName,$n:me(e),$g:Oe(s)};if(s.closest("form"))o.$o=!0;if(n.detail)o.$cx=Math.round(n.clientX/O*100),o.$cy=Math.round(n.clientY/ft*100);if((r||i)&&T.text!==!1)o.$l=Pe(s);if(r){let a=r.getAttribute("role");if(a&&/^(?:button|link|menuitem|tab)$/.test(a))o.$r=a;if(r.localName==="input")o.$y=r.type;if(r.localName==="a"&&r.hasAttribute("href"))o.$h=R(r.href)?.url;d("$click",o)}if(he&&n.detail===3&&!(s.textContent?.trim()&&getSelection()?.isCollapsed===!1))d("$rageclick",{...o});if((r||i)&&!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&!s.closest("[target=_blank],[download]"))qe(o,t)}var wt=(t)=>({$f:me(t),$a:R(new URL(t.getAttribute("action")||"",location.href).href)?.url,$i:t.querySelectorAll("input,select,textarea").length});function Ue(t){let e=t.target;if(rt=t,!l||e.localName!=="form"||e.closest($t))return;d("$form_submit",wt(e))}var be=(t)=>{let e=t.target.form;return l&&e&&T.forms!==!1&&!e.closest($t)?e:null},Qt=new WeakSet;function Me(t){w?.();let e=be(t);if(e&&!Qt.has(e))Qt.add(e),d("$form_start",wt(e))}var J=new Map;function De(t){w?.();let e=be(t);if(!e)return;let n=J.get(e)||0;if(J.set(e,n+1),!n)setTimeout(S(()=>{if(Dt("i",10))d("$form_invalid",{...wt(e),$iv:J.get(e)});J.delete(e)}))}var te=(t)=>t.replace(/https?:\/\/[^\s'"<>()]+/g,(e)=>{let n=/(?::\d+){1,2}$/.exec(e)?.[0]||"";return(R(e.slice(0,e.length-n.length))?.url??"")+n});function Et(t,e,n,r,i){let s=`${r}`.startsWith(I.slice(0,-5));if(!l||T.errors===!1||t==="resource"&&(!i||s))return;Q++;let o=e&&typeof e==="object"?e:{},a=v(te(`${o.message??n??(e&&e!==o?e:"")}`).replace(/(["'\u201c\u201d\u00ab\u00bb\u2018\u2019])[^"'\u201c\u201d\u00ab\u00bb\u2018\u2019]*["'\u201c\u201d\u00ab\u00bb\u2018\u2019]/g,'"\u2026"'),200),p=typeof o.stack==="string"?v(te(o.stack.split(`
|
|
2
2
|
`).filter((y)=>/:\d+:\d+/.test(y)).slice(0,5).map((y)=>y.trim().replace(/@(?=https?:)/," ")).join(`
|
|
3
3
|
`)),1000):void 0,h=`${t}${o.name}${a}${p?.split(`
|
|
4
|
-
`)[0]}${r}`;if(
|
|
4
|
+
`)[0]}${r}`;if(Nt.has(h)||!Dt("e",20))return;Nt.add(h),d("$error",{$ek:t,$en:typeof o.name==="string"?v(o.name,64):void 0,$em:a||void 0,$es:p||void 0,$eu:r?R(`${r}`)?.url:void 0,$et:i})}function ye(t,e,n,r,i){if(!l||T.network===!1)return;let s=new URL(e,location.href).href;if(s.startsWith(I.slice(0,-5)))return;tt++;let o=x()-r,a=i==="AbortError"?"abort":i?"network_error":n>399?"http_error":o>2999&&"slow";if(!a)return;if(a!=="slow"&&a!=="abort")et++;if(Dt("r",30))d("$request",{$nm:`${t}`.toUpperCase().slice(0,10),$nu:R(s)?.url,$ns:n,$nd:o,$nk:a})}var ee=S(ye);function $e(){let t=u.length-1000;if(t>0)b+=u.splice(0,t).length}function Fe(){if(!W)try{let r=(s)=>+matchMedia(`(${s})`).matches,i=navigator;W=[screen.width,screen.height,Math.round(devicePixelRatio*100)/100,null,i.hardwareConcurrency,i.deviceMemory,i.maxTouchPoints,r("pointer:coarse")?"c":"f",r("prefers-color-scheme:dark")?"d":"l",r("prefers-reduced-motion:reduce")]}catch{W=Array(10)}let t=navigator.connection||{},e=P.h||[];return[...W,t.effectiveType,t.rtt,t.downlink,+t.saveData,e[0],e[1],-new Date().getTimezoneOffset()]}var Pt=(t,e)=>`${JSON.stringify([3,Lt,x(),St,e,ae,navigator.language,!!navigator.webdriver,Fe()]).slice(0,-1)},${t.map((n)=>n[0])}]`;function qt(t){let e=0,n=200;while(e<u.length&&e<100){if(n+=u[e][1]+1,n>t)break;e++}return u.splice(0,e||1)}var xt=!1;async function zt(){if(N(),H)xt=!0;if(H||ht||!u.length||!navigator.onLine)return;H=!0;let t=qt(30720),e=b;b=0;let n=0;try{let r=await dt(I,{method:"POST",body:Pt(t,e),keepalive:!0,credentials:"omit",referrerPolicy:"no-referrer"}),i=r.status;if(i===401||i===403)ht=!0,u=[];else if(i===429||i>499)n=Math.min(+(r.headers.get("Retry-After")||0),3600)*1000||-1;else if(at=0,i>299)b+=t.length+e;else{let s=await r.json().catch(()=>0);if(s.directives?.includes("rotate_anon_id"))Ht();if(s.feedback)yt()}}catch{n=-1}H=!1;try{if(n&&l){if(u=t.concat(u),b+=e,$e(),++at<11)N(n>0?n:Math.random()*Math.min(1000*2**at,300000))}else if(u.length)pe(xt);xt=!1}catch{}}function ne(){if(w?.(),ge(),N(),!H&&typeof Request==="function"&&"keepalive"in Request.prototype){let t=61440;while(u.length&&!ht&&t>2048){let e=qt(t),n=b,r=Pt(e,n);t-=r.length,b=0;let i=()=>{u=e.concat(u),b+=n,N(1000)};try{dt(I,{method:"POST",body:r,keepalive:!0,credentials:"omit",referrerPolicy:"no-referrer"}).catch(i)}catch{i();break}}}else{let t=61440;while(u.length&&!ht&&navigator.sendBeacon){let e=qt(t);if(navigator.sendBeacon(I,Pt(e,b)))b=0;else{if(u=e.concat(u),e.length<2)break;t/=2}}}if(u.length)N(1000)}function we(t){K=t?"granted":"not_required";for(let n of fe().reverse())if(m("datacub_tld","1",n,9),B().datacub_tld){m("datacub_tld","",n),pt=n;break}let e=B().datacub_id;if(l=e&&Rt.test(e)?e:U(),m("datacub_id",l),k=B().datacub_id===l,t){for(let n of["",pt])m("datacub_optout","",n);d("$consent",{$m:/^(?:banner|settings|api|cmp)$/.test(`${t.method}`)?t.method:"api",$P:typeof t.policyVersion==="string"?D(t.policyVersion,64):null})}if(q)ve(...q);if(q=null,Ft(!0,!0),ie&&!P.v)P.v=St,P.e=(n,r)=>n==="$form_fields"&&T.forms!==!1&&d(n,r),P.f=wt,window.__datacub=P,ke(`sdk/insights-${St}.min.js`,"sha384-7xNcWolajp48vRTTBdYbGMF2VDBSxZ5qtqZeoosFSuy8Os18qOd9cEUDuSCp9I9z")}function ke(t,e){try{let n=c.createElement("script");if(n.src=I.slice(0,-5)+t,n.async=!0,n.referrerPolicy="no-referrer",e)n.integrity=e,n.crossOrigin="anonymous";n.setAttribute("fetchpriority","low"),(c.head||c.documentElement).append(n)}catch{}}function yt(t){if(!oe||!l||ut===1)return;if(t)ut=t;if(!c.querySelector('script[src*="/v1/feedback.js"]'))ke("feedback.js")}var ze=()=>{let t=ut;return ut=1,t!==1&&(t||[])};function He(t={}){if(!l&&(!jt||t.overrideGPC))we(t)}function _e(){K="denied",N(),u=[];for(let t of re)for(let e of["",...fe()])m(t,"",e);l=g=X="",E=L=q=V=null,k=!1,m("datacub_optout","1")}function ve(t,e,n){if(Ut(),E&&E!==t)Ht();if(e!==L&&k)m("datacub_a",e);if(L=e,E!==t){if(E=t,k)m("datacub_u",t);n.$A=l}for(let r in n)return d(n.$A?"$identify":"$set",n,0,!0)}function Ge(t,e){if(t&&typeof t==="object")e=t,t=e.id??e.userId??e.user_id;let n=[l,g,X],r=_t(t,n),i=e?.account==null?null:_t(e.account,n);if(!r||e?.account!=null&&!i)return bt("bad id");let s=e&&M(e)||{};for(let o in s){let a=/^(?:account|id|user_?id|(email)|(?:full_?)?(name)|(phone)(?:_?number)?)$/i.exec(o);if(a){let p=a[1]||a[2]||a[3];if(p)s[`$${p.toLowerCase()}`]=e[o];delete s[o]}}if(l)ve(r,i,s);else if(K==="pending")q=[r,i,s]}function Ht(){if(q=null,!l)return;if(zt(),l=U(),E=L=null,g="",k){m("datacub_id",l);for(let t of re.slice(1))m(t,"")}}function Ve(t,e={}){if(se=/^(?:localhost|127\.0\.0\.1|\[::1\])$|\.(?:localhost|test)$/.test(location.hostname),lt||typeof t!=="string")return;if(/^sk_/.test(t))return console.error("[datacub] refused a secret key. Use your project ID.");let n;try{n=new URL(e.apiHost||"https://in.datacub.to",location.href)}catch{}if(!/^(?:pk_(?:live|test)_[A-Za-z0-9]{24,48}|[a-z0-9]{8})$/.test(t))return bt("init: bad key");if(!n||n.username||n.password||!(n.protocol==="https:"||n.protocol==="http:"&&/^(?:localhost|127\.0\.0\.1)$/.test(n.hostname)))return bt("init: bad apiHost");if(lt=!0,Lt=t,G=`_${t.replace(/^pk_[a-z]+_/,"").slice(0,8)}`,I=`${n.origin}${n.pathname.replace(/\/+$/,"")}/v1/batch`,It=e.hashRouting===!0,ae=typeof e.release==="string"&&!F(e.release)?e.release.slice(0,64):null,T=e.capture&&typeof e.capture==="object"&&e.capture||{},ie=e.insights!==!1,oe=e.feedback!==!1,f(c,"click",(r)=>r.target?.closest?.("[data-datacub-feedback]")&&yt(["feedback",[]])),dt=fetch,jt=navigator.globalPrivacyControl===!0,jt||B().datacub_optout)_e();else if(!e.requireConsent)we();if(he=e.rageClicks!==!1,e.autocapture!==!1)f(c,"click",Le),f(c,"submit",Ue),f(c,"input",Me),f(c,"invalid",De);for(let r of["pointerdown","keydown","scroll"])f(c,r,(i)=>{let s=x();if(i.target===c)ct();if(r==="scroll")w?.();if(g&&c.visibilityState==="visible"&&s-Zt>5000)Zt=s,Ut(),de(s,!0)});f(c,"visibilitychange",()=>{if(Mt(),c.visibilityState==="hidden")ne()}),ct(),f(window,"resize",ct),f(window,"pagehide",ne),f(window,"pageshow",(r)=>r.persisted&&Ft(!0)),f(window,"online",zt),f(window,"popstate",vt("pop")),f(window,"hashchange",vt("hash"));for(let r of["pushState","replaceState"]){let i=history[r];history[r]=function(...s){i.apply(this,s),vt(r==="pushState"?"push":"replace")()}}try{f(window,"error",(o)=>o instanceof ErrorEvent?Et("js",o.error,o.message,o.filename):Et("resource",0,"",o.target.src||o.target.href,o.target.localName)),f(window,"unhandledrejection",(o)=>Et("rejection",o.reason)),window.fetch=function(...o){let a=dt.apply(this,o);try{let p=x(),h=o[0],y=`${h.url||h}`,Gt=o[1]?.method||h.method||"GET";return a.then((j)=>{try{ee(Gt,j.url||y,j.type==="opaque"?200:j.status,p)}catch{}return j},(j)=>{throw ee(Gt,y,0,p,j?.name||"Error"),j})}catch{}return a};let r=XMLHttpRequest.prototype,{open:i,send:s}=r;r.open=function(...o){return this._x=o,i.apply(this,o)},r.send=function(...o){if(this._x&&!this._t)for(let a of["load","error","abort","timeout"])f(this,a,()=>ye(this._x?.[0],`${this._x?.[1]}`,this.status,this._t,a==="load"?"":a==="abort"?"AbortError":"TypeError"));return this._t=x(),s.apply(this,o)}}catch{}}var C=(t)=>S((...e)=>{if(typeof window>"u")return;if(lt)t(...e);else if(Ot.length<100)Ot.push([t,e])}),Be={init:S((t,e)=>{if(typeof window>"u"||!globalThis.crypto?.getRandomValues)return;c=document;let n=S(()=>{Ve(t,e);for(let[r,i]of Ot.splice(0))if(lt)r(...i)});if(c.prerendering)f(c,"prerenderingchange",n);else n()}),track:C(Ce),identify:C(Ge),reset:C(Ht),consent:{grant:C(He),revoke:C(_e)},ask:C((...t)=>yt(["ask",t])),feedback:C(()=>yt(["feedback",[]])),_fb:()=>[K,k,Lt,I,l,E,g,d,ze]},We=Be;export{St as VERSION,We as default};
|
package/dist/feedback.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var Y={n:0},J=(o)=>o.replace(/[\u0660-\u0669\u06f0-\u06f9\uff10-\uff19]/g,(t)=>String(t.charCodeAt(0)&15));var pe=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|bearer\s+\S{16,}|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]+|PRIVATE KEY|[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}|eyJ[\w-]+\.[\w-]+\.[\w-]*|\d(?:[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]*\d){8,}|[\w+/=]{32,}/gi;function ue(o){let t="",c=0;for(let r of J(o).matchAll(pe)){if(/^[0-9a-f]{8}-/i.test(r[0])&&r[0].length===36)continue;t+=`${o.slice(c,r.index)}[redacted]`,c=r.index+r[0].length,Y.n++}return t+o.slice(c)}function Q(o){let t=o;try{t=decodeURIComponent(o)}catch{}t=J(t);let c=Y.n;if(ue(t)!==t)return Y.n=c+1,":redacted";if(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(t))return":uuid";if(/^[0-9a-f]{16,}$/i.test(t))return t.length===24?":id":":hash";if(/^[\w-]{20,}$/.test(t)&&/\d/.test(t)&&/[a-z]/.test(t)&&/[A-Z]/.test(t))return":token";let r=t.replace(/\D/g,"").length;return r&&(r===t.length||r>3&&r*2>=t.length)?":id":o}var X={en:{close:"Close",send:"Send",sending:"Sending",thanks:"Thanks for sharing!",failed:"Could not send. Try again.",yes:"Yes",no:"No",low:"Not likely",high:"Very likely",type:"Type your answer",general:"What\u2019s on your mind?",tell:"Tell us anything"},ar:{close:"\u0625\u063a\u0644\u0627\u0642",send:"\u0625\u0631\u0633\u0627\u0644",sending:"\u062c\u0627\u0631\u064d \u0627\u0644\u0625\u0631\u0633\u0627\u0644",thanks:"\u0634\u0643\u0631\u064b\u0627 \u0639\u0644\u0649 \u0645\u0634\u0627\u0631\u0643\u062a\u0643!",failed:"\u062a\u0639\u0630\u0651\u0631 \u0627\u0644\u0625\u0631\u0633\u0627\u0644\u060c \u062d\u0627\u0648\u0644 \u0645\u0631\u0629 \u062b\u0627\u0646\u064a\u0629.",yes:"\u0646\u0639\u0645",no:"\u0644\u0627",low:"\u063a\u064a\u0631 \u0645\u062d\u062a\u0645\u0644",high:"\u0645\u062d\u062a\u0645\u0644 \u062c\u062f\u064b\u0627",type:"\u0627\u0643\u062a\u0628 \u0625\u062c\u0627\u0628\u062a\u0643",general:"\u0645\u0627 \u0627\u0644\u0630\u064a \u064a\u062f\u0648\u0631 \u0641\u064a \u0628\u0627\u0644\u0643\u061f",tell:"\u0627\u0643\u062a\u0628 \u0645\u0627 \u062a\u0631\u064a\u062f"}},ee="--bg:#1c1c1f;--fg:#fafafa;--mut:#a1a1aa;--opt:#2a2a2e;--opt-h:#333338;--edge:rgba(255,255,255,.08);--x:#8b8b93;--line:#55555c",te=`
|
|
2
2
|
:host{all:initial}
|
|
3
3
|
*{box-sizing:border-box;margin:0}
|
|
4
4
|
.w{--a:#1f1f1f;--on:#fff;--bg:#fff;--fg:#18181b;--mut:#71717a;--opt:#f4f4f5;--opt-h:#ebebee;--edge:rgba(24,24,27,.07);--x:#a1a1aa;--line:#d4d4d8;
|
|
5
5
|
position:fixed;z-index:2147483000;bottom:16px;right:16px;width:360px;max-width:calc(100vw - 24px);
|
|
6
6
|
font:14px/1.45 system-ui,-apple-system,"Segoe UI","SF Arabic","Noto Sans Arabic",Tahoma,sans-serif;color:var(--fg);-webkit-font-smoothing:antialiased;transition:bottom .2s}
|
|
7
|
-
.w.dk{${
|
|
8
|
-
@media (prefers-color-scheme:dark){.w.au{${
|
|
7
|
+
.w.dk{${ee}}
|
|
8
|
+
@media (prefers-color-scheme:dark){.w.au{${ee}}}
|
|
9
9
|
.w.s{right:auto;left:16px}
|
|
10
10
|
.w.p{position:relative;inset:auto;bottom:auto;right:auto;left:auto;width:100%}
|
|
11
11
|
.c{position:relative;background:var(--bg);border-radius:16px;padding:16px;box-shadow:0 0 0 1px var(--edge),0 12px 32px -8px rgba(24,24,27,.22),0 2px 6px rgba(24,24,27,.06);
|
|
@@ -61,4 +61,4 @@ textarea::placeholder,input::placeholder{color:var(--x)}
|
|
|
61
61
|
@media (max-width:480px){.w:not(.p){bottom:max(12px,env(safe-area-inset-bottom));left:12px;right:12px;width:auto;max-width:none}
|
|
62
62
|
.o1{min-height:44px}.n .o1{min-height:40px}}
|
|
63
63
|
@media (prefers-reduced-motion:reduce){*,.c,.k{animation-duration:.01ms!important;transition-duration:.01ms!important}}
|
|
64
|
-
`,X="http://www.w3.org/2000/svg",K={x:"M4 4l8 8M12 4l-8 8",check:"M3.5 8.5l3 3 6-7",plus:"M8 3.5v9M3.5 8h9",up:"M7 10v10H4V10h3zm0 0l4-7c1.3 0 2.2 1.1 2 2.4L12.4 9H18a2 2 0 0 1 2 2.3l-1.2 6.9A2 2 0 0 1 16.8 20H7",down:"M17 14V4h3v10h-3zm0 0l-4 7c-1.3 0-2.2-1.1-2-2.4l.6-3.6H6a2 2 0 0 1-2-2.3l1.2-6.9A2 2 0 0 1 7.2 4H17"},q={};function R(s,e=16,l=1.6){let r=document.createElementNS(X,"svg");r.setAttribute("viewBox",`0 0 ${e} ${e}`),r.setAttribute("aria-hidden","true"),r.setAttribute("fill","none");let a=document.createElementNS(X,"path");return a.setAttribute("d",s),a.setAttribute("stroke","currentColor"),a.setAttribute("stroke-width",String(l)),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),r.append(a),r}function p(s,e,l){let r=document.createElement(s);if(e)r.className=e;if(l)r.textContent=l;return r}var V=null;function le(s){try{if(V??=new CSSStyleSheet,!V.cssRules.length)V.replaceSync(Q+(q.css??""));s.adoptedStyleSheets=[V]}catch{s.append(p("style",void 0,Q+(q.css??"")))}}var ne=(s)=>{let e=Number.parseInt(s.slice(1),16),[l,r,a]=[e>>16&255,e>>8&255,e&255].map((d)=>{let h=d/255;return h<=0.03928?h/12.92:((h+0.055)/1.055)**2.4});return 0.2126*l+0.7152*r+0.0722*a},de=(s)=>ne(s)>0.4?"#18181b":"#fff";function ce(s,e){let l=/^#[0-9a-f]{6}$/i.test(e.accent)?e.accent:"#1f1f1f";if((e.theme==="dark"||e.theme==="auto"&&typeof matchMedia==="function"&&matchMedia("(prefers-color-scheme: dark)").matches)&&ne(l)<0.05)l="#fafafa";if(s.style.setProperty("--a",l),s.style.setProperty("--on",de(l)),e.theme==="dark")s.classList.add("dk");if(e.theme==="auto")s.classList.add("au")}function pe(s,e,l,r){le(s);let a=Z[e.lang]??Z.en,d=r.edit,h=p("div",`w${l.position==="start"?" s":""}${r.preview||r.inline||d?" p":""}${d?" ed":""}`);h.dir=e.lang==="ar"?"rtl":"ltr",h.lang=e.lang,ce(h,l);let u=p("div",r.quiet||d?"c q":"c"),v=`datacub-fb-${Math.random().toString(36).slice(2,8)}`;u.setAttribute("role",r.preview||r.inline||d?"group":"dialog"),u.setAttribute("aria-labelledby",v);let C=p("p","sr");C.setAttribute("aria-live","polite");let b=p("button","x");if(b.type="button",b.setAttribute("aria-label",a.close),b.append(R(K.x)),d)b.tabIndex=-1,b.setAttribute("aria-hidden","true");let S;if(d)S=q.title(e,d,u);else S=p("p","t",e.type==="general"?a.general:e.title);S.id=v,u.append(b,S),h.append(u,C),s.append(h);let y=null,k=!1,A=!1,j=e.type==="general"?a.tell:e.followup,I=(i)=>!!e.followup&&(!e.followupOn||i!==null&&e.followupOn.includes(i)),L=e.type==="text"||e.type==="general",T=[],N=null,P=(i)=>{if(A)return;if(A=!0,N)visualViewport?.removeEventListener("resize",N);u.classList.add("o"),setTimeout(()=>h.remove(),200),r.done?.(i)},M=p("div",`f${L||d&&e.followup!=null?" on":""}`),D=p("div"),z=p("div","fi"),g=p("textarea");g.maxLength=1000,g.placeholder=e.type==="text"?a.type:j??a.type,g.setAttribute("aria-label",e.type==="text"?e.title:j??a.type);let O=p("div","r"),H=p("span","e");H.setAttribute("role","status");let t=p("button","b",a.send);if(t.type="button",O.append(H,t),d&&e.followup!=null&&e.type!=="text")z.append(q.followup(e,d)),g.placeholder=a.type;if(z.append(g,O),D.append(z),M.append(D),!L&&!j)M.hidden=!0;if(d)g.disabled=!0,t.disabled=!0,t.tabIndex=-1;let n=()=>{if(d)return;t.disabled=L?!g.value.trim():!y};g.addEventListener("input",n);let o=async()=>{if(k||t.disabled||d)return;k=!0,t.setAttribute("aria-busy","true"),t.textContent="",t.append(p("span","sp"),document.createTextNode(a.sending)),H.textContent="";try{await r.send(y,(I(y)||L)&&g.value.trim()?g.value.trim():null)}catch{k=!1,t.removeAttribute("aria-busy"),t.textContent=a.send,H.textContent=a.failed;return}let i=p("div","k");i.setAttribute("role","status"),i.append(R("M7 16.5l5.5 5.5L25 9.5",32,2.4),p("strong",void 0,a.thanks));let f=u.offsetHeight;if(u.replaceChildren(i),!matchMedia("(prefers-reduced-motion: reduce)").matches)u.animate?.([{height:`${f}px`},{height:`${u.offsetHeight}px`}],{duration:280,easing:"cubic-bezier(.2,.9,.25,1)"});if(!r.preview&&!r.inline)setTimeout(()=>P(!0),2400)};t.addEventListener("click",o),g.addEventListener("keydown",(i)=>{if(i.key==="Enter"&&(i.metaKey||i.ctrlKey))o()});let c=(i)=>{y=i;for(let x of T)x.setAttribute("aria-pressed",String(x.dataset.id===i));if(n(),!I(i))return void o();let f=!M.classList.contains("on");if(M.classList.add("on"),f&&!r.preview)setTimeout(()=>g.focus({preventScroll:!0}),120)},m=(i,f,x="o1",E)=>{let w=p("button",x);if(w.type="button",w.dataset.id=i,w.setAttribute("aria-pressed","false"),E)w.append(E),w.setAttribute("aria-label",f);else{let F=p("span","d");F.append(R(K.check,16,2.4)),w.append(F,p("span",void 0,f))}if(d)w.tabIndex=-1;else w.addEventListener("click",()=>!k&&c(i));return T.push(w),w};if(e.type==="choice"&&d)u.append(q.choices(e,d));else if(e.type==="choice"){let i=p("div","g");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v);for(let f of e.options??[])i.append(m(f.id,f.label));u.append(i)}else if(e.type==="thumbs"){let i=p("div","th");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v),i.append(m("up",a.yes,"o1",R(K.up,24)),m("down",a.no,"o1",R(K.down,24))),u.append(i)}else if(e.type==="nps"){let i=p("div","n");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v);for(let x=0;x<=10;x++)i.append(m(String(x),String(x),"o1",p("span",void 0,String(x))));let f=p("div","nl");f.append(p("span",void 0,a.low),p("span",void 0,a.high)),u.append(i,f)}u.append(M),n();let _=()=>{if(!y||k||L||d)return;k=!0,r.send(y,I(y)&&g.value.trim()?g.value.trim():null).catch(()=>{})};if(b.addEventListener("click",()=>{if(d)return;_(),P(!!y||k)}),addEventListener("pagehide",_),h.addEventListener("keydown",(i)=>{if(i.key==="Escape"&&!d)i.stopPropagation(),b.click()}),!r.preview&&!r.inline&&!d&&typeof visualViewport<"u"&&visualViewport){let i=visualViewport;N=()=>{let f=innerHeight-i.height-i.offsetTop;h.style.bottom=innerWidth<=480&&f>40?`${f+12}px`:""},i.addEventListener("resize",N)}if(!r.preview&&!d)C.textContent=e.type==="general"?a.general:e.title;if(r.focus)setTimeout(()=>(L?g:T[0])?.focus(),50);if(d?.focus)q.focus(d,u);return{close:()=>P(k)}}var ee=60000,te=!1;function ue(){let s=document.activeElement;return document.visibilityState!=="visible"||!!s?.closest?.("input,textarea,select,[contenteditable]:not([contenteditable=false])")||!!document.querySelector("dialog[open],[aria-modal=true]")}function ie(s){if(te||typeof window>"u"||!s?._fb)return;te=!0;let e=s._fb,l=[],r={accent:"#1f1f1f",position:"end"},a="",d=0,h=0,u=null,v=!1,C=!1,b=new Set,S=()=>{let[,t,n,o,c,m,_,i]=e();return t&&c?{key:n,base:o.replace(/batch$/,"feedback"),anon:c,user:m??null,sid:_||null,emit:i}:null},y=async(t,n)=>{let o=await fetch(t,{method:"POST",body:JSON.stringify(n),credentials:"omit",keepalive:!0});if(!o.ok)throw Error(String(o.status));return o.json()},k=()=>{let t=document.createElement("div");return t.setAttribute("data-datacub-feedback-widget",""),document.body.append(t),t};async function A(){let t=S();if(!t){j();return}let n=`${t.anon}|${t.user??""}`;if(n===a||Date.now()<h)return;a=n;try{let o=await y(t.base,{api_key:t.key,anon_id:t.anon,user_id:t.user});l=o.questions??[];let c=o.settings;r={accent:c.accent,position:c.position,theme:c.theme??"light"}}catch(o){a="",h=/^4/.test(o?.message)?Number.POSITIVE_INFINITY:Date.now()+Math.min(1000*2**++d,300000);return}d=0,D()}function j(){C=!0,u?.close(),C=!1;for(let t of b)clearTimeout(t);b.clear()}function I(){let t=S();if(!t||u)return;let n=document.activeElement,o=/^ar\b/i.test(document.documentElement.lang)?"ar":"en";L({lang:o,type:"general",title:""},null,t,n)}function L(t,n,o,c,m){let _=k();if(m)m.append(_);let i=_.attachShadow({mode:"open"}),f=crypto.randomUUID?.()??"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(E)=>(+E^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+E/4).toString(16)),x=n?{$question_id:n.id,$version:n.version}:{};u=pe(i,t,r,{focus:!n,inline:!!m,send:async(E,w)=>{let F={api_key:o.key,id:f,question:n?.id??null,version:n?.version??null,anon_id:o.anon,user_id:o.user,session_id:o.sid,choice:E,text:w,path:location.pathname.split("/").map(G).join("/")};for(let U=0;;U++)try{await y(`${o.base}/answer`,F);break}catch(Y){if(U>=2||/^4/.test(Y.message))throw Y;await new Promise((re)=>setTimeout(re,800*2**U))}o.emit("$feedback_answered",{...x,$response_id:f,$choice:E},{},!0)},done:(E)=>{if(u=null,_.remove(),c?.focus?.(),n&&!E&&!C)y(`${o.base}/seen`,{api_key:o.key,anon_id:o.anon,question:n.id,kind:"dismissed"}).catch(()=>{}),o.emit("$feedback_dismissed",x,{},!0)}})}async function T(t,n,o){let c=S();if(!c||u||v)return;if(!o&&t.q.delivery?.waitForIdle!==!1&&ue()){if(Date.now()<n)N(()=>T(t,n,o),2000);return}try{if(!(await y(`${c.base}/seen`,{api_key:c.key,anon_id:c.anon,question:t.id,kind:"shown",user_id:c.user})).ok||u||v)return}catch{return}v=!0,l=l.filter((m)=>m.id!==t.id),c.emit("$feedback_shown",{$question_id:t.id,$version:t.version},{},!0),L(t.q,t,c,null,o)}function N(t,n){let o=setTimeout(()=>{b.delete(o),t()},n);b.add(o)}let P=(t)=>N(()=>T(t,Date.now()+ee),(t.q.trigger.delay??0)*1000);function M(t,n){return n.endsWith("*")?t.startsWith(n.slice(0,-1)):t===n||t===`${n}/`}function D(){let t=location.pathname;for(let n of l)if(n.q.trigger.kind==="page"&&M(t,n.q.trigger.path??""))P(n);for(let n of document.querySelectorAll("[data-datacub-ask]")){let o=l.find((c)=>c.id===n.getAttribute("data-datacub-ask")&&c.q.trigger.kind==="manual");if(o&&!n.querySelector("[data-datacub-feedback-widget]"))T(o,Date.now(),n)}}let z=(t,n)=>{let o=s[t];s[t]=(...c)=>{o(...c);try{n(...c)}catch{}}};z("track",(t)=>{for(let n of l)if(n.q.trigger.kind==="event"&&n.q.trigger.event===String(t).trim())P(n)}),z("identify",()=>setTimeout(A,0)),z("reset",()=>setTimeout(A,0));let g=s.consent.grant;s.consent.grant=(...t)=>{g(...t),setTimeout(A,0)},s.ask=(t,n)=>{let o=l.find((m)=>m.id===t&&m.q.trigger.kind==="manual"),c=null;try{c=typeof n?.into==="string"?document.querySelector(n.into):n?.into??null}catch{}if(o)T(o,Date.now()+ee,c instanceof Element?c:null)},s.feedback=I,document.addEventListener("click",(t)=>{if(t.target?.closest?.("[data-datacub-feedback]"))I()});let O=location.pathname,H=()=>setTimeout(()=>{if(location.pathname===O)return;O=location.pathname,v=!1,D()},150);for(let t of["pushState","replaceState"]){let n=history[t];history[t]=function(...o){n.apply(this,o),H()}}addEventListener("popstate",H),setInterval(()=>{if(S())A();else if(a)a="",j()},1000),A()}var oe=(s=0)=>{let e=window.datacub;if(e?._fb)ie(e);else if(s<100)setTimeout(()=>oe(s+1),100)};oe();})();
|
|
64
|
+
`,ne="http://www.w3.org/2000/svg",V={x:"M4 4l8 8M12 4l-8 8",check:"M3.5 8.5l3 3 6-7",plus:"M8 3.5v9M3.5 8h9",up:"M7 10v10H4V10h3zm0 0l4-7c1.3 0 2.2 1.1 2 2.4L12.4 9H18a2 2 0 0 1 2 2.3l-1.2 6.9A2 2 0 0 1 16.8 20H7",down:"M17 14V4h3v10h-3zm0 0l-4 7c-1.3 0-2.2-1.1-2-2.4l.6-3.6H6a2 2 0 0 1-2-2.3l1.2-6.9A2 2 0 0 1 7.2 4H17"},q={};function F(o,t=16,c=1.6){let r=document.createElementNS(ne,"svg");r.setAttribute("viewBox",`0 0 ${t} ${t}`),r.setAttribute("aria-hidden","true"),r.setAttribute("fill","none");let a=document.createElementNS(ne,"path");return a.setAttribute("d",o),a.setAttribute("stroke","currentColor"),a.setAttribute("stroke-width",String(c)),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),r.append(a),r}function d(o,t,c){let r=document.createElement(o);if(t)r.className=t;if(c)r.textContent=c;return r}var U=null;function fe(o){try{if(U??=new CSSStyleSheet,!U.cssRules.length)U.replaceSync(te+(q.css??""));o.adoptedStyleSheets=[U]}catch{o.append(d("style",void 0,te+(q.css??"")))}}var re=(o)=>{let t=Number.parseInt(o.slice(1),16),[c,r,a]=[t>>16&255,t>>8&255,t&255].map((l)=>{let u=l/255;return u<=0.03928?u/12.92:((u+0.055)/1.055)**2.4});return 0.2126*c+0.7152*r+0.0722*a},ge=(o)=>re(o)>0.4?"#18181b":"#fff";function me(o,t){let c=/^#[0-9a-f]{6}$/i.test(t.accent)?t.accent:"#1f1f1f";if((t.theme==="dark"||t.theme==="auto"&&typeof matchMedia==="function"&&matchMedia("(prefers-color-scheme: dark)").matches)&&re(c)<0.05)c="#fafafa";if(o.style.setProperty("--a",c),o.style.setProperty("--on",ge(c)),t.theme==="dark")o.classList.add("dk");if(t.theme==="auto")o.classList.add("au")}function he(o,t,c,r){fe(o);let a=X[t.lang]??X.en,l=r.edit,u=d("div",`w${c.position==="start"?" s":""}${r.preview||r.inline||l?" p":""}${l?" ed":""}`);u.dir=t.lang==="ar"?"rtl":"ltr",u.lang=t.lang,me(u,c);let p=d("div",r.quiet||l?"c q":"c"),E=`datacub-fb-${Math.random().toString(36).slice(2,8)}`;p.setAttribute("role",r.preview||r.inline||l?"group":"dialog"),p.setAttribute("aria-labelledby",E);let x=d("p","sr");x.setAttribute("aria-live","polite");let b=d("button","x");if(b.type="button",b.setAttribute("aria-label",a.close),b.append(F(V.x)),l)b.tabIndex=-1,b.setAttribute("aria-hidden","true");let S;if(l)S=q.title(t,l,p);else S=d("p","t",t.type==="general"?a.general:t.title);S.id=E,p.append(b,S),u.append(p,x),o.append(u);let y=null,w=!1,T=!1,D=t.type==="general"?a.tell:t.followup,v=(e)=>!!t.followup&&(!t.followupOn||e!==null&&t.followupOn.includes(e)),k=t.type==="text"||t.type==="general",_=[],C=null,L=(e)=>{if(T)return;if(T=!0,C)visualViewport?.removeEventListener("resize",C);p.classList.add("o"),setTimeout(()=>u.remove(),200),r.done?.(e)},A=d("div",`f${k||l&&t.followup!=null?" on":""}`),O=d("div"),R=d("div","fi"),f=d("textarea");f.maxLength=1000,f.placeholder=t.type==="text"?a.type:D??a.type,f.setAttribute("aria-label",t.type==="text"?t.title:D??a.type);let M=d("div","r"),z=d("span","e");z.setAttribute("role","status");let m=d("button","b",a.send);if(m.type="button",M.append(z,m),l&&t.followup!=null&&t.type!=="text")R.append(q.followup(t,l)),f.placeholder=a.type;if(R.append(f,M),O.append(R),A.append(O),!k&&!D)A.hidden=!0;if(l)f.disabled=!0,m.disabled=!0,m.tabIndex=-1;let H=()=>{if(l)return;m.disabled=k?!f.value.trim():!y};f.addEventListener("input",H);let P=async()=>{if(w||m.disabled||l)return;w=!0,m.setAttribute("aria-busy","true"),m.textContent="",m.append(d("span","sp"),document.createTextNode(a.sending)),z.textContent="";try{await r.send(y,(v(y)||k)&&f.value.trim()?f.value.trim():null)}catch{w=!1,m.removeAttribute("aria-busy"),m.textContent=a.send,z.textContent=a.failed;return}let e=d("div","k");e.setAttribute("role","status"),e.append(F("M7 16.5l5.5 5.5L25 9.5",32,2.4),d("strong",void 0,a.thanks));let i=p.offsetHeight;if(p.replaceChildren(e),!matchMedia("(prefers-reduced-motion: reduce)").matches)p.animate?.([{height:`${i}px`},{height:`${p.offsetHeight}px`}],{duration:280,easing:"cubic-bezier(.2,.9,.25,1)"});if(!r.preview&&!r.inline)setTimeout(()=>L(!0),2400)};m.addEventListener("click",P),f.addEventListener("keydown",(e)=>{if(e.key==="Enter"&&(e.metaKey||e.ctrlKey))P()});let K=(e)=>{y=e;for(let s of _)s.setAttribute("aria-pressed",String(s.dataset.id===e));if(H(),!v(e))return void P();let i=!A.classList.contains("on");if(A.classList.add("on"),i&&!r.preview)setTimeout(()=>f.focus({preventScroll:!0}),120)},j=(e,i,s="o1",h)=>{let g=d("button",s);if(g.type="button",g.dataset.id=e,g.setAttribute("aria-pressed","false"),h)g.append(h),g.setAttribute("aria-label",i);else{let I=d("span","d");I.append(F(V.check,16,2.4)),g.append(I,d("span",void 0,i))}if(l)g.tabIndex=-1;else g.addEventListener("click",()=>!w&&K(e));return _.push(g),g};if(t.type==="choice"&&l)p.append(q.choices(t,l));else if(t.type==="choice"){let e=d("div","g");e.setAttribute("role","group"),e.setAttribute("aria-labelledby",E);for(let i of t.options??[])e.append(j(i.id,i.label));p.append(e)}else if(t.type==="thumbs"){let e=d("div","th");e.setAttribute("role","group"),e.setAttribute("aria-labelledby",E),e.append(j("up",a.yes,"o1",F(V.up,24)),j("down",a.no,"o1",F(V.down,24))),p.append(e)}else if(t.type==="nps"){let e=d("div","n");e.setAttribute("role","group"),e.setAttribute("aria-labelledby",E);for(let s=0;s<=10;s++)e.append(j(String(s),String(s),"o1",d("span",void 0,String(s))));let i=d("div","nl");i.append(d("span",void 0,a.low),d("span",void 0,a.high)),p.append(e,i)}p.append(A),H();let n=()=>{if(!y||w||k||l)return;w=!0,r.send(y,v(y)&&f.value.trim()?f.value.trim():null).catch(()=>{})};if(b.addEventListener("click",()=>{if(l)return;n(),L(!!y||w)}),addEventListener("pagehide",n),u.addEventListener("keydown",(e)=>{if(e.key==="Escape"&&!l)e.stopPropagation(),b.click()}),!r.preview&&!r.inline&&!l&&typeof visualViewport<"u"&&visualViewport){let e=visualViewport;C=()=>{let i=innerHeight-e.height-e.offsetTop;u.style.bottom=innerWidth<=480&&i>40?`${i+12}px`:""},e.addEventListener("resize",C)}if(!r.preview&&!l)x.textContent=t.type==="general"?a.general:t.title;if(r.focus)setTimeout(()=>(k?f:_[0])?.focus(),50);if(l?.focus)q.focus(l,p);return{close:()=>L(w)}}var ie=60000,oe=!1;function be(){let o=document.activeElement;return document.visibilityState!=="visible"||!!o?.closest?.("input,textarea,select,[contenteditable]:not([contenteditable=false])")||!!document.querySelector("dialog[open],[aria-modal=true]")}function se(o){if(oe||typeof window>"u"||!o?._fb)return;let t=o._fb,c=t()[8],r=c?c():[];if(!r)return;oe=!0;let a=[],l={accent:"#1f1f1f",position:"end"},u="",p=0,E=0,x=null,b=!1,S=!1,y=new Set,w=()=>{let[,n,e,i,s,h,g,I]=t();return n&&s?{key:e,base:i.replace(/batch$/,"feedback"),anon:s,user:h??null,sid:g||null,emit:I}:null},T=async(n,e)=>{let i=await fetch(n,{method:"POST",body:JSON.stringify(e),credentials:"omit",keepalive:!0});if(!i.ok)throw Error(String(i.status));return i.json()},D=()=>{let n=document.createElement("div");return n.setAttribute("data-datacub-feedback-widget",""),document.body.append(n),n};async function v(){let n=w();if(!n){k();return}let e=`${n.anon}|${n.user??""}`;if(e===u||Date.now()<E)return;u=e;try{let i=await T(n.base,{api_key:n.key,anon_id:n.anon,user_id:n.user});a=i.questions??[];let s=i.settings;l={accent:s.accent,position:s.position,theme:s.theme??"light"}}catch(i){u="",E=/^4/.test(i?.message)?Number.POSITIVE_INFINITY:Date.now()+Math.min(1000*2**++p,300000);return}p=0,f()}function k(){S=!0,x?.close(),S=!1;for(let n of y)clearTimeout(n);y.clear()}function _(){let n=w();if(!n||x)return;let e=document.activeElement,i=/^ar\b/i.test(document.documentElement.lang)?"ar":"en";C({lang:i,type:"general",title:""},null,n,e)}function C(n,e,i,s,h){let g=D();if(h)h.append(g);let I=g.attachShadow({mode:"open"}),W=crypto.randomUUID?.()??"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(N)=>(+N^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+N/4).toString(16)),G=e?{$question_id:e.id,$version:e.version}:{};x=he(I,n,l,{focus:!e,inline:!!h,send:async(N,le)=>{let de={api_key:i.key,id:W,question:e?.id??null,version:e?.version??null,anon_id:i.anon,user_id:i.user,session_id:i.sid,choice:N,text:le,path:location.pathname.split("/").map(Q).join("/")};for(let B=0;;B++)try{await T(`${i.base}/answer`,de);break}catch(Z){if(B>=2||/^4/.test(Z.message))throw Z;await new Promise((ce)=>setTimeout(ce,800*2**B))}i.emit("$feedback_answered",{...G,$response_id:W,$choice:N},{},!0)},done:(N)=>{if(x=null,g.remove(),s?.focus?.(),e&&!N&&!S)T(`${i.base}/seen`,{api_key:i.key,anon_id:i.anon,question:e.id,kind:"dismissed"}).catch(()=>{}),i.emit("$feedback_dismissed",G,{},!0)}})}async function L(n,e,i){let s=w();if(!s||x||b)return;if(!i&&n.q.delivery?.waitForIdle!==!1&&be()){if(Date.now()<e)A(()=>L(n,e,i),2000);return}try{if(!(await T(`${s.base}/seen`,{api_key:s.key,anon_id:s.anon,question:n.id,kind:"shown",user_id:s.user})).ok||x||b)return}catch{return}b=!0,a=a.filter((h)=>h.id!==n.id),s.emit("$feedback_shown",{$question_id:n.id,$version:n.version},{},!0),C(n.q,n,s,null,i)}function A(n,e){let i=setTimeout(()=>{y.delete(i),n()},e);y.add(i)}let O=(n)=>A(()=>L(n,Date.now()+ie),(n.q.trigger.delay??0)*1000);function R(n,e){return e.endsWith("*")?n.startsWith(e.slice(0,-1)):n===e||n===`${e}/`}function f(){let n=location.pathname;for(let e of a)if(e.q.trigger.kind==="page"&&R(n,e.q.trigger.path??""))O(e);for(let e of document.querySelectorAll("[data-datacub-ask]")){let i=a.find((s)=>s.id===e.getAttribute("data-datacub-ask")&&s.q.trigger.kind==="manual");if(i&&!e.querySelector("[data-datacub-feedback-widget]"))L(i,Date.now(),e)}}let M=(n,e)=>{let i=o[n];o[n]=(...s)=>{i(...s);try{e(...s)}catch{}}};M("track",(n)=>{for(let e of a)if(e.q.trigger.kind==="event"&&e.q.trigger.event===String(n).trim())O(e)}),M("identify",()=>setTimeout(v,0)),M("reset",()=>setTimeout(v,0));let z=o.consent.grant;o.consent.grant=(...n)=>{z(...n),setTimeout(v,0)};let m=Promise.resolve();o.ask=(n,e)=>void m.then(()=>{let i=a.find((h)=>h.id===n&&h.q.trigger.kind==="manual"),s=null;try{s=typeof e?.into==="string"?document.querySelector(e.into):e?.into??null}catch{}if(i)L(i,Date.now()+ie,s instanceof Element?s:null)}),o.feedback=_,document.addEventListener("click",(n)=>{if(n.target?.closest?.("[data-datacub-feedback]"))_()});let H=location.pathname,P=()=>setTimeout(()=>{if(location.pathname===H)return;H=location.pathname,b=!1,f()},150);for(let n of["pushState","replaceState"]){let e=history[n];history[n]=function(...i){e.apply(this,i),P()}}addEventListener("popstate",P),setInterval(()=>{if(w())v();else if(u)u="",k()},1000),m=v();let[K,j]=r;if(K==="feedback")_();else if(K==="ask")o.ask(...j)}var ae=(o=0)=>{let t=window.datacub;if(t?._fb)se(t);else if(o<100)setTimeout(()=>ae(o+1),100)};ae();})();
|
package/dist/feedback.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Y={n:0},J=(r)=>r.replace(/[\u0660-\u0669\u06f0-\u06f9\uff10-\uff19]/g,(t)=>String(t.charCodeAt(0)&15));var de=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|bearer\s+\S{16,}|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]+|PRIVATE KEY|[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}|eyJ[\w-]+\.[\w-]+\.[\w-]*|\d(?:[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]*\d){8,}|[\w+/=]{32,}/gi;function ce(r){let t="",c=0;for(let o of J(r).matchAll(de)){if(/^[0-9a-f]{8}-/i.test(o[0])&&o[0].length===36)continue;t+=`${r.slice(c,o.index)}[redacted]`,c=o.index+o[0].length,Y.n++}return t+r.slice(c)}function Q(r){let t=r;try{t=decodeURIComponent(r)}catch{}t=J(t);let c=Y.n;if(ce(t)!==t)return Y.n=c+1,":redacted";if(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(t))return":uuid";if(/^[0-9a-f]{16,}$/i.test(t))return t.length===24?":id":":hash";if(/^[\w-]{20,}$/.test(t)&&/\d/.test(t)&&/[a-z]/.test(t)&&/[A-Z]/.test(t))return":token";let o=t.replace(/\D/g,"").length;return o&&(o===t.length||o>3&&o*2>=t.length)?":id":r}var X={en:{close:"Close",send:"Send",sending:"Sending",thanks:"Thanks for sharing!",failed:"Could not send. Try again.",yes:"Yes",no:"No",low:"Not likely",high:"Very likely",type:"Type your answer",general:"What\u2019s on your mind?",tell:"Tell us anything"},ar:{close:"\u0625\u063a\u0644\u0627\u0642",send:"\u0625\u0631\u0633\u0627\u0644",sending:"\u062c\u0627\u0631\u064d \u0627\u0644\u0625\u0631\u0633\u0627\u0644",thanks:"\u0634\u0643\u0631\u064b\u0627 \u0639\u0644\u0649 \u0645\u0634\u0627\u0631\u0643\u062a\u0643!",failed:"\u062a\u0639\u0630\u0651\u0631 \u0627\u0644\u0625\u0631\u0633\u0627\u0644\u060c \u062d\u0627\u0648\u0644 \u0645\u0631\u0629 \u062b\u0627\u0646\u064a\u0629.",yes:"\u0646\u0639\u0645",no:"\u0644\u0627",low:"\u063a\u064a\u0631 \u0645\u062d\u062a\u0645\u0644",high:"\u0645\u062d\u062a\u0645\u0644 \u062c\u062f\u064b\u0627",type:"\u0627\u0643\u062a\u0628 \u0625\u062c\u0627\u0628\u062a\u0643",general:"\u0645\u0627 \u0627\u0644\u0630\u064a \u064a\u062f\u0648\u0631 \u0641\u064a \u0628\u0627\u0644\u0643\u061f",tell:"\u0627\u0643\u062a\u0628 \u0645\u0627 \u062a\u0631\u064a\u062f"}},ee="--bg:#1c1c1f;--fg:#fafafa;--mut:#a1a1aa;--opt:#2a2a2e;--opt-h:#333338;--edge:rgba(255,255,255,.08);--x:#8b8b93;--line:#55555c",te=`
|
|
2
2
|
:host{all:initial}
|
|
3
3
|
*{box-sizing:border-box;margin:0}
|
|
4
4
|
.w{--a:#1f1f1f;--on:#fff;--bg:#fff;--fg:#18181b;--mut:#71717a;--opt:#f4f4f5;--opt-h:#ebebee;--edge:rgba(24,24,27,.07);--x:#a1a1aa;--line:#d4d4d8;
|
|
5
5
|
position:fixed;z-index:2147483000;bottom:16px;right:16px;width:360px;max-width:calc(100vw - 24px);
|
|
6
6
|
font:14px/1.45 system-ui,-apple-system,"Segoe UI","SF Arabic","Noto Sans Arabic",Tahoma,sans-serif;color:var(--fg);-webkit-font-smoothing:antialiased;transition:bottom .2s}
|
|
7
|
-
.w.dk{${
|
|
8
|
-
@media (prefers-color-scheme:dark){.w.au{${
|
|
7
|
+
.w.dk{${ee}}
|
|
8
|
+
@media (prefers-color-scheme:dark){.w.au{${ee}}}
|
|
9
9
|
.w.s{right:auto;left:16px}
|
|
10
10
|
.w.p{position:relative;inset:auto;bottom:auto;right:auto;left:auto;width:100%}
|
|
11
11
|
.c{position:relative;background:var(--bg);border-radius:16px;padding:16px;box-shadow:0 0 0 1px var(--edge),0 12px 32px -8px rgba(24,24,27,.22),0 2px 6px rgba(24,24,27,.06);
|
|
@@ -61,4 +61,4 @@ textarea::placeholder,input::placeholder{color:var(--x)}
|
|
|
61
61
|
@media (max-width:480px){.w:not(.p){bottom:max(12px,env(safe-area-inset-bottom));left:12px;right:12px;width:auto;max-width:none}
|
|
62
62
|
.o1{min-height:44px}.n .o1{min-height:40px}}
|
|
63
63
|
@media (prefers-reduced-motion:reduce){*,.c,.k{animation-duration:.01ms!important;transition-duration:.01ms!important}}
|
|
64
|
-
`,X="http://www.w3.org/2000/svg",K={x:"M4 4l8 8M12 4l-8 8",check:"M3.5 8.5l3 3 6-7",plus:"M8 3.5v9M3.5 8h9",up:"M7 10v10H4V10h3zm0 0l4-7c1.3 0 2.2 1.1 2 2.4L12.4 9H18a2 2 0 0 1 2 2.3l-1.2 6.9A2 2 0 0 1 16.8 20H7",down:"M17 14V4h3v10h-3zm0 0l-4 7c-1.3 0-2.2-1.1-2-2.4l.6-3.6H6a2 2 0 0 1-2-2.3l1.2-6.9A2 2 0 0 1 7.2 4H17"},P={};function R(s,t=16,l=1.6){let r=document.createElementNS(X,"svg");r.setAttribute("viewBox",`0 0 ${t} ${t}`),r.setAttribute("aria-hidden","true"),r.setAttribute("fill","none");let a=document.createElementNS(X,"path");return a.setAttribute("d",s),a.setAttribute("stroke","currentColor"),a.setAttribute("stroke-width",String(l)),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),r.append(a),r}function p(s,t,l){let r=document.createElement(s);if(t)r.className=t;if(l)r.textContent=l;return r}var V=null;function se(s){try{if(V??=new CSSStyleSheet,!V.cssRules.length)V.replaceSync(Q+(P.css??""));s.adoptedStyleSheets=[V]}catch{s.append(p("style",void 0,Q+(P.css??"")))}}var ne=(s)=>{let t=Number.parseInt(s.slice(1),16),[l,r,a]=[t>>16&255,t>>8&255,t&255].map((d)=>{let h=d/255;return h<=0.03928?h/12.92:((h+0.055)/1.055)**2.4});return 0.2126*l+0.7152*r+0.0722*a},ae=(s)=>ne(s)>0.4?"#18181b":"#fff";function le(s,t){let l=/^#[0-9a-f]{6}$/i.test(t.accent)?t.accent:"#1f1f1f";if((t.theme==="dark"||t.theme==="auto"&&typeof matchMedia==="function"&&matchMedia("(prefers-color-scheme: dark)").matches)&&ne(l)<0.05)l="#fafafa";if(s.style.setProperty("--a",l),s.style.setProperty("--on",ae(l)),t.theme==="dark")s.classList.add("dk");if(t.theme==="auto")s.classList.add("au")}function de(s,t,l,r){se(s);let a=Z[t.lang]??Z.en,d=r.edit,h=p("div",`w${l.position==="start"?" s":""}${r.preview||r.inline||d?" p":""}${d?" ed":""}`);h.dir=t.lang==="ar"?"rtl":"ltr",h.lang=t.lang,le(h,l);let u=p("div",r.quiet||d?"c q":"c"),v=`datacub-fb-${Math.random().toString(36).slice(2,8)}`;u.setAttribute("role",r.preview||r.inline||d?"group":"dialog"),u.setAttribute("aria-labelledby",v);let C=p("p","sr");C.setAttribute("aria-live","polite");let b=p("button","x");if(b.type="button",b.setAttribute("aria-label",a.close),b.append(R(K.x)),d)b.tabIndex=-1,b.setAttribute("aria-hidden","true");let S;if(d)S=P.title(t,d,u);else S=p("p","t",t.type==="general"?a.general:t.title);S.id=v,u.append(b,S),h.append(u,C),s.append(h);let x=null,k=!1,A=!1,j=t.type==="general"?a.tell:t.followup,I=(i)=>!!t.followup&&(!t.followupOn||i!==null&&t.followupOn.includes(i)),L=t.type==="text"||t.type==="general",T=[],N=null,q=(i)=>{if(A)return;if(A=!0,N)visualViewport?.removeEventListener("resize",N);u.classList.add("o"),setTimeout(()=>h.remove(),200),r.done?.(i)},M=p("div",`f${L||d&&t.followup!=null?" on":""}`),D=p("div"),z=p("div","fi"),g=p("textarea");g.maxLength=1000,g.placeholder=t.type==="text"?a.type:j??a.type,g.setAttribute("aria-label",t.type==="text"?t.title:j??a.type);let O=p("div","r"),H=p("span","e");H.setAttribute("role","status");let e=p("button","b",a.send);if(e.type="button",O.append(H,e),d&&t.followup!=null&&t.type!=="text")z.append(P.followup(t,d)),g.placeholder=a.type;if(z.append(g,O),D.append(z),M.append(D),!L&&!j)M.hidden=!0;if(d)g.disabled=!0,e.disabled=!0,e.tabIndex=-1;let n=()=>{if(d)return;e.disabled=L?!g.value.trim():!x};g.addEventListener("input",n);let o=async()=>{if(k||e.disabled||d)return;k=!0,e.setAttribute("aria-busy","true"),e.textContent="",e.append(p("span","sp"),document.createTextNode(a.sending)),H.textContent="";try{await r.send(x,(I(x)||L)&&g.value.trim()?g.value.trim():null)}catch{k=!1,e.removeAttribute("aria-busy"),e.textContent=a.send,H.textContent=a.failed;return}let i=p("div","k");i.setAttribute("role","status"),i.append(R("M7 16.5l5.5 5.5L25 9.5",32,2.4),p("strong",void 0,a.thanks));let f=u.offsetHeight;if(u.replaceChildren(i),!matchMedia("(prefers-reduced-motion: reduce)").matches)u.animate?.([{height:`${f}px`},{height:`${u.offsetHeight}px`}],{duration:280,easing:"cubic-bezier(.2,.9,.25,1)"});if(!r.preview&&!r.inline)setTimeout(()=>q(!0),2400)};e.addEventListener("click",o),g.addEventListener("keydown",(i)=>{if(i.key==="Enter"&&(i.metaKey||i.ctrlKey))o()});let c=(i)=>{x=i;for(let y of T)y.setAttribute("aria-pressed",String(y.dataset.id===i));if(n(),!I(i))return void o();let f=!M.classList.contains("on");if(M.classList.add("on"),f&&!r.preview)setTimeout(()=>g.focus({preventScroll:!0}),120)},m=(i,f,y="o1",E)=>{let w=p("button",y);if(w.type="button",w.dataset.id=i,w.setAttribute("aria-pressed","false"),E)w.append(E),w.setAttribute("aria-label",f);else{let F=p("span","d");F.append(R(K.check,16,2.4)),w.append(F,p("span",void 0,f))}if(d)w.tabIndex=-1;else w.addEventListener("click",()=>!k&&c(i));return T.push(w),w};if(t.type==="choice"&&d)u.append(P.choices(t,d));else if(t.type==="choice"){let i=p("div","g");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v);for(let f of t.options??[])i.append(m(f.id,f.label));u.append(i)}else if(t.type==="thumbs"){let i=p("div","th");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v),i.append(m("up",a.yes,"o1",R(K.up,24)),m("down",a.no,"o1",R(K.down,24))),u.append(i)}else if(t.type==="nps"){let i=p("div","n");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v);for(let y=0;y<=10;y++)i.append(m(String(y),String(y),"o1",p("span",void 0,String(y))));let f=p("div","nl");f.append(p("span",void 0,a.low),p("span",void 0,a.high)),u.append(i,f)}u.append(M),n();let _=()=>{if(!x||k||L||d)return;k=!0,r.send(x,I(x)&&g.value.trim()?g.value.trim():null).catch(()=>{})};if(b.addEventListener("click",()=>{if(d)return;_(),q(!!x||k)}),addEventListener("pagehide",_),h.addEventListener("keydown",(i)=>{if(i.key==="Escape"&&!d)i.stopPropagation(),b.click()}),!r.preview&&!r.inline&&!d&&typeof visualViewport<"u"&&visualViewport){let i=visualViewport;N=()=>{let f=innerHeight-i.height-i.offsetTop;h.style.bottom=innerWidth<=480&&f>40?`${f+12}px`:""},i.addEventListener("resize",N)}if(!r.preview&&!d)C.textContent=t.type==="general"?a.general:t.title;if(r.focus)setTimeout(()=>(L?g:T[0])?.focus(),50);if(d?.focus)P.focus(d,u);return{close:()=>q(k)}}var ee=60000,te=!1;function ce(){let s=document.activeElement;return document.visibilityState!=="visible"||!!s?.closest?.("input,textarea,select,[contenteditable]:not([contenteditable=false])")||!!document.querySelector("dialog[open],[aria-modal=true]")}function fe(s){if(te||typeof window>"u"||!s?._fb)return;te=!0;let t=s._fb,l=[],r={accent:"#1f1f1f",position:"end"},a="",d=0,h=0,u=null,v=!1,C=!1,b=new Set,S=()=>{let[,e,n,o,c,m,_,i]=t();return e&&c?{key:n,base:o.replace(/batch$/,"feedback"),anon:c,user:m??null,sid:_||null,emit:i}:null},x=async(e,n)=>{let o=await fetch(e,{method:"POST",body:JSON.stringify(n),credentials:"omit",keepalive:!0});if(!o.ok)throw Error(String(o.status));return o.json()},k=()=>{let e=document.createElement("div");return e.setAttribute("data-datacub-feedback-widget",""),document.body.append(e),e};async function A(){let e=S();if(!e){j();return}let n=`${e.anon}|${e.user??""}`;if(n===a||Date.now()<h)return;a=n;try{let o=await x(e.base,{api_key:e.key,anon_id:e.anon,user_id:e.user});l=o.questions??[];let c=o.settings;r={accent:c.accent,position:c.position,theme:c.theme??"light"}}catch(o){a="",h=/^4/.test(o?.message)?Number.POSITIVE_INFINITY:Date.now()+Math.min(1000*2**++d,300000);return}d=0,D()}function j(){C=!0,u?.close(),C=!1;for(let e of b)clearTimeout(e);b.clear()}function I(){let e=S();if(!e||u)return;let n=document.activeElement,o=/^ar\b/i.test(document.documentElement.lang)?"ar":"en";L({lang:o,type:"general",title:""},null,e,n)}function L(e,n,o,c,m){let _=k();if(m)m.append(_);let i=_.attachShadow({mode:"open"}),f=crypto.randomUUID?.()??"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(E)=>(+E^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+E/4).toString(16)),y=n?{$question_id:n.id,$version:n.version}:{};u=de(i,e,r,{focus:!n,inline:!!m,send:async(E,w)=>{let F={api_key:o.key,id:f,question:n?.id??null,version:n?.version??null,anon_id:o.anon,user_id:o.user,session_id:o.sid,choice:E,text:w,path:location.pathname.split("/").map(G).join("/")};for(let U=0;;U++)try{await x(`${o.base}/answer`,F);break}catch(Y){if(U>=2||/^4/.test(Y.message))throw Y;await new Promise((ie)=>setTimeout(ie,800*2**U))}o.emit("$feedback_answered",{...y,$response_id:f,$choice:E},{},!0)},done:(E)=>{if(u=null,_.remove(),c?.focus?.(),n&&!E&&!C)x(`${o.base}/seen`,{api_key:o.key,anon_id:o.anon,question:n.id,kind:"dismissed"}).catch(()=>{}),o.emit("$feedback_dismissed",y,{},!0)}})}async function T(e,n,o){let c=S();if(!c||u||v)return;if(!o&&e.q.delivery?.waitForIdle!==!1&&ce()){if(Date.now()<n)N(()=>T(e,n,o),2000);return}try{if(!(await x(`${c.base}/seen`,{api_key:c.key,anon_id:c.anon,question:e.id,kind:"shown",user_id:c.user})).ok||u||v)return}catch{return}v=!0,l=l.filter((m)=>m.id!==e.id),c.emit("$feedback_shown",{$question_id:e.id,$version:e.version},{},!0),L(e.q,e,c,null,o)}function N(e,n){let o=setTimeout(()=>{b.delete(o),e()},n);b.add(o)}let q=(e)=>N(()=>T(e,Date.now()+ee),(e.q.trigger.delay??0)*1000);function M(e,n){return n.endsWith("*")?e.startsWith(n.slice(0,-1)):e===n||e===`${n}/`}function D(){let e=location.pathname;for(let n of l)if(n.q.trigger.kind==="page"&&M(e,n.q.trigger.path??""))q(n);for(let n of document.querySelectorAll("[data-datacub-ask]")){let o=l.find((c)=>c.id===n.getAttribute("data-datacub-ask")&&c.q.trigger.kind==="manual");if(o&&!n.querySelector("[data-datacub-feedback-widget]"))T(o,Date.now(),n)}}let z=(e,n)=>{let o=s[e];s[e]=(...c)=>{o(...c);try{n(...c)}catch{}}};z("track",(e)=>{for(let n of l)if(n.q.trigger.kind==="event"&&n.q.trigger.event===String(e).trim())q(n)}),z("identify",()=>setTimeout(A,0)),z("reset",()=>setTimeout(A,0));let g=s.consent.grant;s.consent.grant=(...e)=>{g(...e),setTimeout(A,0)},s.ask=(e,n)=>{let o=l.find((m)=>m.id===e&&m.q.trigger.kind==="manual"),c=null;try{c=typeof n?.into==="string"?document.querySelector(n.into):n?.into??null}catch{}if(o)T(o,Date.now()+ee,c instanceof Element?c:null)},s.feedback=I,document.addEventListener("click",(e)=>{if(e.target?.closest?.("[data-datacub-feedback]"))I()});let O=location.pathname,H=()=>setTimeout(()=>{if(location.pathname===O)return;O=location.pathname,v=!1,D()},150);for(let e of["pushState","replaceState"]){let n=history[e];history[e]=function(...o){n.apply(this,o),H()}}addEventListener("popstate",H),setInterval(()=>{if(S())A();else if(a)a="",j()},1000),A()}export{K as ICONS,p as el,R as icon,de as mount,P as parts,fe as start};
|
|
64
|
+
`,ne="http://www.w3.org/2000/svg",V={x:"M4 4l8 8M12 4l-8 8",check:"M3.5 8.5l3 3 6-7",plus:"M8 3.5v9M3.5 8h9",up:"M7 10v10H4V10h3zm0 0l4-7c1.3 0 2.2 1.1 2 2.4L12.4 9H18a2 2 0 0 1 2 2.3l-1.2 6.9A2 2 0 0 1 16.8 20H7",down:"M17 14V4h3v10h-3zm0 0l-4 7c-1.3 0-2.2-1.1-2-2.4l.6-3.6H6a2 2 0 0 1-2-2.3l1.2-6.9A2 2 0 0 1 7.2 4H17"},q={};function F(r,t=16,c=1.6){let o=document.createElementNS(ne,"svg");o.setAttribute("viewBox",`0 0 ${t} ${t}`),o.setAttribute("aria-hidden","true"),o.setAttribute("fill","none");let a=document.createElementNS(ne,"path");return a.setAttribute("d",r),a.setAttribute("stroke","currentColor"),a.setAttribute("stroke-width",String(c)),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),o.append(a),o}function d(r,t,c){let o=document.createElement(r);if(t)o.className=t;if(c)o.textContent=c;return o}var U=null;function pe(r){try{if(U??=new CSSStyleSheet,!U.cssRules.length)U.replaceSync(te+(q.css??""));r.adoptedStyleSheets=[U]}catch{r.append(d("style",void 0,te+(q.css??"")))}}var re=(r)=>{let t=Number.parseInt(r.slice(1),16),[c,o,a]=[t>>16&255,t>>8&255,t&255].map((l)=>{let u=l/255;return u<=0.03928?u/12.92:((u+0.055)/1.055)**2.4});return 0.2126*c+0.7152*o+0.0722*a},ue=(r)=>re(r)>0.4?"#18181b":"#fff";function fe(r,t){let c=/^#[0-9a-f]{6}$/i.test(t.accent)?t.accent:"#1f1f1f";if((t.theme==="dark"||t.theme==="auto"&&typeof matchMedia==="function"&&matchMedia("(prefers-color-scheme: dark)").matches)&&re(c)<0.05)c="#fafafa";if(r.style.setProperty("--a",c),r.style.setProperty("--on",ue(c)),t.theme==="dark")r.classList.add("dk");if(t.theme==="auto")r.classList.add("au")}function ge(r,t,c,o){pe(r);let a=X[t.lang]??X.en,l=o.edit,u=d("div",`w${c.position==="start"?" s":""}${o.preview||o.inline||l?" p":""}${l?" ed":""}`);u.dir=t.lang==="ar"?"rtl":"ltr",u.lang=t.lang,fe(u,c);let p=d("div",o.quiet||l?"c q":"c"),E=`datacub-fb-${Math.random().toString(36).slice(2,8)}`;p.setAttribute("role",o.preview||o.inline||l?"group":"dialog"),p.setAttribute("aria-labelledby",E);let w=d("p","sr");w.setAttribute("aria-live","polite");let b=d("button","x");if(b.type="button",b.setAttribute("aria-label",a.close),b.append(F(V.x)),l)b.tabIndex=-1,b.setAttribute("aria-hidden","true");let S;if(l)S=q.title(t,l,p);else S=d("p","t",t.type==="general"?a.general:t.title);S.id=E,p.append(b,S),u.append(p,w),r.append(u);let y=null,x=!1,T=!1,D=t.type==="general"?a.tell:t.followup,v=(e)=>!!t.followup&&(!t.followupOn||e!==null&&t.followupOn.includes(e)),k=t.type==="text"||t.type==="general",_=[],C=null,L=(e)=>{if(T)return;if(T=!0,C)visualViewport?.removeEventListener("resize",C);p.classList.add("o"),setTimeout(()=>u.remove(),200),o.done?.(e)},A=d("div",`f${k||l&&t.followup!=null?" on":""}`),O=d("div"),R=d("div","fi"),f=d("textarea");f.maxLength=1000,f.placeholder=t.type==="text"?a.type:D??a.type,f.setAttribute("aria-label",t.type==="text"?t.title:D??a.type);let M=d("div","r"),z=d("span","e");z.setAttribute("role","status");let m=d("button","b",a.send);if(m.type="button",M.append(z,m),l&&t.followup!=null&&t.type!=="text")R.append(q.followup(t,l)),f.placeholder=a.type;if(R.append(f,M),O.append(R),A.append(O),!k&&!D)A.hidden=!0;if(l)f.disabled=!0,m.disabled=!0,m.tabIndex=-1;let H=()=>{if(l)return;m.disabled=k?!f.value.trim():!y};f.addEventListener("input",H);let P=async()=>{if(x||m.disabled||l)return;x=!0,m.setAttribute("aria-busy","true"),m.textContent="",m.append(d("span","sp"),document.createTextNode(a.sending)),z.textContent="";try{await o.send(y,(v(y)||k)&&f.value.trim()?f.value.trim():null)}catch{x=!1,m.removeAttribute("aria-busy"),m.textContent=a.send,z.textContent=a.failed;return}let e=d("div","k");e.setAttribute("role","status"),e.append(F("M7 16.5l5.5 5.5L25 9.5",32,2.4),d("strong",void 0,a.thanks));let i=p.offsetHeight;if(p.replaceChildren(e),!matchMedia("(prefers-reduced-motion: reduce)").matches)p.animate?.([{height:`${i}px`},{height:`${p.offsetHeight}px`}],{duration:280,easing:"cubic-bezier(.2,.9,.25,1)"});if(!o.preview&&!o.inline)setTimeout(()=>L(!0),2400)};m.addEventListener("click",P),f.addEventListener("keydown",(e)=>{if(e.key==="Enter"&&(e.metaKey||e.ctrlKey))P()});let K=(e)=>{y=e;for(let s of _)s.setAttribute("aria-pressed",String(s.dataset.id===e));if(H(),!v(e))return void P();let i=!A.classList.contains("on");if(A.classList.add("on"),i&&!o.preview)setTimeout(()=>f.focus({preventScroll:!0}),120)},j=(e,i,s="o1",h)=>{let g=d("button",s);if(g.type="button",g.dataset.id=e,g.setAttribute("aria-pressed","false"),h)g.append(h),g.setAttribute("aria-label",i);else{let I=d("span","d");I.append(F(V.check,16,2.4)),g.append(I,d("span",void 0,i))}if(l)g.tabIndex=-1;else g.addEventListener("click",()=>!x&&K(e));return _.push(g),g};if(t.type==="choice"&&l)p.append(q.choices(t,l));else if(t.type==="choice"){let e=d("div","g");e.setAttribute("role","group"),e.setAttribute("aria-labelledby",E);for(let i of t.options??[])e.append(j(i.id,i.label));p.append(e)}else if(t.type==="thumbs"){let e=d("div","th");e.setAttribute("role","group"),e.setAttribute("aria-labelledby",E),e.append(j("up",a.yes,"o1",F(V.up,24)),j("down",a.no,"o1",F(V.down,24))),p.append(e)}else if(t.type==="nps"){let e=d("div","n");e.setAttribute("role","group"),e.setAttribute("aria-labelledby",E);for(let s=0;s<=10;s++)e.append(j(String(s),String(s),"o1",d("span",void 0,String(s))));let i=d("div","nl");i.append(d("span",void 0,a.low),d("span",void 0,a.high)),p.append(e,i)}p.append(A),H();let n=()=>{if(!y||x||k||l)return;x=!0,o.send(y,v(y)&&f.value.trim()?f.value.trim():null).catch(()=>{})};if(b.addEventListener("click",()=>{if(l)return;n(),L(!!y||x)}),addEventListener("pagehide",n),u.addEventListener("keydown",(e)=>{if(e.key==="Escape"&&!l)e.stopPropagation(),b.click()}),!o.preview&&!o.inline&&!l&&typeof visualViewport<"u"&&visualViewport){let e=visualViewport;C=()=>{let i=innerHeight-e.height-e.offsetTop;u.style.bottom=innerWidth<=480&&i>40?`${i+12}px`:""},e.addEventListener("resize",C)}if(!o.preview&&!l)w.textContent=t.type==="general"?a.general:t.title;if(o.focus)setTimeout(()=>(k?f:_[0])?.focus(),50);if(l?.focus)q.focus(l,p);return{close:()=>L(x)}}var ie=60000,oe=!1;function me(){let r=document.activeElement;return document.visibilityState!=="visible"||!!r?.closest?.("input,textarea,select,[contenteditable]:not([contenteditable=false])")||!!document.querySelector("dialog[open],[aria-modal=true]")}function ye(r){if(oe||typeof window>"u"||!r?._fb)return;let t=r._fb,c=t()[8],o=c?c():[];if(!o)return;oe=!0;let a=[],l={accent:"#1f1f1f",position:"end"},u="",p=0,E=0,w=null,b=!1,S=!1,y=new Set,x=()=>{let[,n,e,i,s,h,g,I]=t();return n&&s?{key:e,base:i.replace(/batch$/,"feedback"),anon:s,user:h??null,sid:g||null,emit:I}:null},T=async(n,e)=>{let i=await fetch(n,{method:"POST",body:JSON.stringify(e),credentials:"omit",keepalive:!0});if(!i.ok)throw Error(String(i.status));return i.json()},D=()=>{let n=document.createElement("div");return n.setAttribute("data-datacub-feedback-widget",""),document.body.append(n),n};async function v(){let n=x();if(!n){k();return}let e=`${n.anon}|${n.user??""}`;if(e===u||Date.now()<E)return;u=e;try{let i=await T(n.base,{api_key:n.key,anon_id:n.anon,user_id:n.user});a=i.questions??[];let s=i.settings;l={accent:s.accent,position:s.position,theme:s.theme??"light"}}catch(i){u="",E=/^4/.test(i?.message)?Number.POSITIVE_INFINITY:Date.now()+Math.min(1000*2**++p,300000);return}p=0,f()}function k(){S=!0,w?.close(),S=!1;for(let n of y)clearTimeout(n);y.clear()}function _(){let n=x();if(!n||w)return;let e=document.activeElement,i=/^ar\b/i.test(document.documentElement.lang)?"ar":"en";C({lang:i,type:"general",title:""},null,n,e)}function C(n,e,i,s,h){let g=D();if(h)h.append(g);let I=g.attachShadow({mode:"open"}),W=crypto.randomUUID?.()??"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(N)=>(+N^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+N/4).toString(16)),G=e?{$question_id:e.id,$version:e.version}:{};w=ge(I,n,l,{focus:!e,inline:!!h,send:async(N,se)=>{let ae={api_key:i.key,id:W,question:e?.id??null,version:e?.version??null,anon_id:i.anon,user_id:i.user,session_id:i.sid,choice:N,text:se,path:location.pathname.split("/").map(Q).join("/")};for(let B=0;;B++)try{await T(`${i.base}/answer`,ae);break}catch(Z){if(B>=2||/^4/.test(Z.message))throw Z;await new Promise((le)=>setTimeout(le,800*2**B))}i.emit("$feedback_answered",{...G,$response_id:W,$choice:N},{},!0)},done:(N)=>{if(w=null,g.remove(),s?.focus?.(),e&&!N&&!S)T(`${i.base}/seen`,{api_key:i.key,anon_id:i.anon,question:e.id,kind:"dismissed"}).catch(()=>{}),i.emit("$feedback_dismissed",G,{},!0)}})}async function L(n,e,i){let s=x();if(!s||w||b)return;if(!i&&n.q.delivery?.waitForIdle!==!1&&me()){if(Date.now()<e)A(()=>L(n,e,i),2000);return}try{if(!(await T(`${s.base}/seen`,{api_key:s.key,anon_id:s.anon,question:n.id,kind:"shown",user_id:s.user})).ok||w||b)return}catch{return}b=!0,a=a.filter((h)=>h.id!==n.id),s.emit("$feedback_shown",{$question_id:n.id,$version:n.version},{},!0),C(n.q,n,s,null,i)}function A(n,e){let i=setTimeout(()=>{y.delete(i),n()},e);y.add(i)}let O=(n)=>A(()=>L(n,Date.now()+ie),(n.q.trigger.delay??0)*1000);function R(n,e){return e.endsWith("*")?n.startsWith(e.slice(0,-1)):n===e||n===`${e}/`}function f(){let n=location.pathname;for(let e of a)if(e.q.trigger.kind==="page"&&R(n,e.q.trigger.path??""))O(e);for(let e of document.querySelectorAll("[data-datacub-ask]")){let i=a.find((s)=>s.id===e.getAttribute("data-datacub-ask")&&s.q.trigger.kind==="manual");if(i&&!e.querySelector("[data-datacub-feedback-widget]"))L(i,Date.now(),e)}}let M=(n,e)=>{let i=r[n];r[n]=(...s)=>{i(...s);try{e(...s)}catch{}}};M("track",(n)=>{for(let e of a)if(e.q.trigger.kind==="event"&&e.q.trigger.event===String(n).trim())O(e)}),M("identify",()=>setTimeout(v,0)),M("reset",()=>setTimeout(v,0));let z=r.consent.grant;r.consent.grant=(...n)=>{z(...n),setTimeout(v,0)};let m=Promise.resolve();r.ask=(n,e)=>void m.then(()=>{let i=a.find((h)=>h.id===n&&h.q.trigger.kind==="manual"),s=null;try{s=typeof e?.into==="string"?document.querySelector(e.into):e?.into??null}catch{}if(i)L(i,Date.now()+ie,s instanceof Element?s:null)}),r.feedback=_,document.addEventListener("click",(n)=>{if(n.target?.closest?.("[data-datacub-feedback]"))_()});let H=location.pathname,P=()=>setTimeout(()=>{if(location.pathname===H)return;H=location.pathname,b=!1,f()},150);for(let n of["pushState","replaceState"]){let e=history[n];history[n]=function(...i){e.apply(this,i),P()}}addEventListener("popstate",P),setInterval(()=>{if(x())v();else if(u)u="",k()},1000),m=v();let[K,j]=o;if(K==="feedback")_();else if(K==="ask")r.ask(...j)}export{V as ICONS,d as el,F as icon,ge as mount,q as parts,ye as start};
|
package/dist/flags.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{function k(t,r){let s=`${t}:${r}`,e=2166136261;for(let c=0;c<s.length;c++)e^=s.charCodeAt(c),e=Math.imul(e,16777619);return e^=e>>>16,e=Math.imul(e,2246822507),e^=e>>>13,e=Math.imul(e,3266489909),e^=e>>>16,(e>>>0)%1e4}var _=(t,r,s)=>r>=100||r>0&&k(`f1:${t}`,s)<r*100,h=(t,r)=>k(`e1:${t}`,r)<5000?"A":"B";var j=30000,R=1e4,v=2000;function A(t){let r=null,s=0,e=null,c=0,
|
|
1
|
+
(()=>{function k(t,r){let s=`${t}:${r}`,e=2166136261;for(let c=0;c<s.length;c++)e^=s.charCodeAt(c),e=Math.imul(e,16777619);return e^=e>>>16,e=Math.imul(e,2246822507),e^=e>>>13,e=Math.imul(e,3266489909),e^=e>>>16,(e>>>0)%1e4}var _=(t,r,s)=>r>=100||r>0&&k(`f1:${t}`,s)<r*100,h=(t,r)=>k(`e1:${t}`,r)<5000?"A":"B";var j=30000,R=1e4,v=2000;function A(t){let r=null,s=0,e=null,c=0,w=new Set,d=()=>{let n=t();return typeof n?._fb==="function"?n._fb():null};async function b(){for(let n=0;n<v;n+=50){let i=d();if(i?.[2])return i;await new Promise((o)=>setTimeout(o,50))}return null}async function P(){let n=await b();if(!n)return;let i=new AbortController,o=setTimeout(()=>i.abort(),v);try{let u=`${n[3].replace(/batch$/,"flags")}?api_key=${n[2]}`,f=await fetch(u,{credentials:"omit",signal:i.signal});if(!f.ok)c=Date.now();else{let a=await f.json();r={flags:a.flags&&typeof a.flags==="object"?a.flags:{},experiments:a.experiments&&typeof a.experiments==="object"?a.experiments:{}},s=Date.now()}}catch{c=Date.now()}clearTimeout(o)}async function y(){if(typeof window>"u")return null;if(!r&&Date.now()-c<R)return null;if(!r||Date.now()-s>j){if(e??=P().finally(()=>{e=null}),!r)await e}return r}let p=(n)=>n?.[1]&&typeof n[4]==="string"&&n[4]?n[4]:null;async function H(n){try{if(typeof window>"u")return!1;let i=(await y())?.flags[n];if(typeof i!=="number")return!1;if(i>=100)return!0;let o=p(d());return!!o&&_(n,i,o)}catch{return!1}}async function T(n){try{if(typeof window>"u"||!p(await b()))return"A";let o=(await y())?.experiments[n],u=d(),f=p(u);if(typeof o!=="string"||!f||!u)return"A";let a=h(o,f),x=`${o}:${f}`;if(!w.has(x))u[7]("$experiment_exposure",{$experiment_id:o,$variant:a}),w.add(x);return a}catch{return"A"}}return{flag:H,experiment:T}}var l=window,C=A(()=>l.datacub),m=(t)=>{if(t&&typeof t==="object"&&!t.flag)t.flag=C.flag,t.experiment=C.experiment},g=l.datacub??[];m(g);try{Object.defineProperty(window,"datacub",{configurable:!0,enumerable:!0,get:()=>g,set(t){g=t,m(t)}})}catch{l.datacub=g;let t=0,r=setInterval(()=>{if(m(l.datacub),l.datacub?._fb||++t>300)clearInterval(r)},100)}})();
|
package/dist/flags.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import T from"@datacub/web";function y(
|
|
1
|
+
import T from"@datacub/web";function y(s,e){let a=`${s}:${e}`,t=2166136261;for(let f=0;f<a.length;f++)t^=a.charCodeAt(f),t=Math.imul(t,16777619);return t^=t>>>16,t=Math.imul(t,2246822507),t^=t>>>13,t=Math.imul(t,3266489909),t^=t>>>16,(t>>>0)%1e4}var x=(s,e,a)=>e>=100||e>0&&y(`f1:${s}`,a)<e*100,b=(s,e)=>y(`e1:${s}`,e)<5000?"A":"B";var v=30000,P=1e4,h=2000;function _(s){let e=null,a=0,t=null,f=0,m=new Set,u=()=>{let n=s();return typeof n?._fb==="function"?n._fb():null};async function p(){for(let n=0;n<h;n+=50){let i=u();if(i?.[2])return i;await new Promise((r)=>setTimeout(r,50))}return null}async function k(){let n=await p();if(!n)return;let i=new AbortController,r=setTimeout(()=>i.abort(),h);try{let l=`${n[3].replace(/batch$/,"flags")}?api_key=${n[2]}`,c=await fetch(l,{credentials:"omit",signal:i.signal});if(!c.ok)f=Date.now();else{let o=await c.json();e={flags:o.flags&&typeof o.flags==="object"?o.flags:{},experiments:o.experiments&&typeof o.experiments==="object"?o.experiments:{}},a=Date.now()}}catch{f=Date.now()}clearTimeout(r)}async function d(){if(typeof window>"u")return null;if(!e&&Date.now()-f<P)return null;if(!e||Date.now()-a>v){if(t??=k().finally(()=>{t=null}),!e)await t}return e}let g=(n)=>n?.[1]&&typeof n[4]==="string"&&n[4]?n[4]:null;async function A(n){try{if(typeof window>"u")return!1;let i=(await d())?.flags[n];if(typeof i!=="number")return!1;if(i>=100)return!0;let r=g(u());return!!r&&x(n,i,r)}catch{return!1}}async function C(n){try{if(typeof window>"u"||!g(await p()))return"A";let r=(await d())?.experiments[n],l=u(),c=g(l);if(typeof r!=="string"||!c||!l)return"A";let o=b(r,c),w=`${r}:${c}`;if(!m.has(w))l[7]("$experiment_exposure",{$experiment_id:r,$variant:o}),m.add(w);return o}catch{return"A"}}return{flag:A,experiment:C}}var{flag:E,experiment:M}=_(()=>T);export{M as experiment,E as flag};
|
package/package.json
CHANGED
package/types/datacub.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// datacub web SDK 0.
|
|
2
|
-
export declare const VERSION = "0.
|
|
1
|
+
// datacub web SDK 0.5.0, for the script tag. Save as datacub.d.ts in your project: `datacub` is then typed.
|
|
2
|
+
export declare const VERSION = "0.5.0";
|
|
3
3
|
export type Property = string | number | boolean | null | Date | Property[] | {
|
|
4
4
|
[key: string]: Property;
|
|
5
5
|
};
|
|
@@ -26,6 +26,12 @@ export interface InitOptions {
|
|
|
26
26
|
* model), loaded after tracking starts from apiHost. Default true.
|
|
27
27
|
*/
|
|
28
28
|
insights?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The feedback widget, loaded from apiHost only when the project has a live question or the page
|
|
31
|
+
* opens the "Send feedback" card, and only while tracking. Default true; false never loads it
|
|
32
|
+
* (data-feedback="off" on the script tag).
|
|
33
|
+
*/
|
|
34
|
+
feedback?: boolean;
|
|
29
35
|
/** Turn kinds of capture off on this site. The project's settings in datacub can turn them off too. */
|
|
30
36
|
capture?: Capture;
|
|
31
37
|
}
|
|
@@ -78,11 +84,11 @@ export interface DatacubClient {
|
|
|
78
84
|
grant(options?: GrantOptions): void;
|
|
79
85
|
revoke(): void;
|
|
80
86
|
};
|
|
81
|
-
/**
|
|
87
|
+
/** Show one question now (the feedback widget loads first when it is not on the page yet). */
|
|
82
88
|
ask?(questionId: string, options?: {
|
|
83
89
|
into?: Element | string;
|
|
84
90
|
}): void;
|
|
85
|
-
/**
|
|
91
|
+
/** Open the "Send feedback" card (the feedback widget loads first when it is not on the page yet). */
|
|
86
92
|
feedback?(): void;
|
|
87
93
|
/**
|
|
88
94
|
* Added by the script-tag flags module (/v1/flags.js; with npm, import flag from @datacub/web/flags): is this feature flag on for this
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.5.0";
|
|
2
2
|
export type Property = string | number | boolean | null | Date | Property[] | {
|
|
3
3
|
[key: string]: Property;
|
|
4
4
|
};
|
|
@@ -25,6 +25,12 @@ export interface InitOptions {
|
|
|
25
25
|
* model), loaded after tracking starts from apiHost. Default true.
|
|
26
26
|
*/
|
|
27
27
|
insights?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The feedback widget, loaded from apiHost only when the project has a live question or the page
|
|
30
|
+
* opens the "Send feedback" card, and only while tracking. Default true; false never loads it
|
|
31
|
+
* (data-feedback="off" on the script tag).
|
|
32
|
+
*/
|
|
33
|
+
feedback?: boolean;
|
|
28
34
|
/** Turn kinds of capture off on this site. The project's settings in datacub can turn them off too. */
|
|
29
35
|
capture?: Capture;
|
|
30
36
|
}
|
|
@@ -77,11 +83,11 @@ export interface DatacubClient {
|
|
|
77
83
|
grant(options?: GrantOptions): void;
|
|
78
84
|
revoke(): void;
|
|
79
85
|
};
|
|
80
|
-
/**
|
|
86
|
+
/** Show one question now (the feedback widget loads first when it is not on the page yet). */
|
|
81
87
|
ask?(questionId: string, options?: {
|
|
82
88
|
into?: Element | string;
|
|
83
89
|
}): void;
|
|
84
|
-
/**
|
|
90
|
+
/** Open the "Send feedback" card (the feedback widget loads first when it is not on the page yet). */
|
|
85
91
|
feedback?(): void;
|
|
86
92
|
/**
|
|
87
93
|
* Added by the script-tag flags module (/v1/flags.js; with npm, import flag from @datacub/web/flags): is this feature flag on for this
|