UNPKG

posthog-js

Version:

Posthog-js allows you to automatically capture usage and send events to PostHog.

2 lines • 24.1 kB
!function(){const t="u">typeof window?window:void 0,i="u">typeof globalThis?globalThis:t,e=null==i?void 0:i.document;null!=i&&i.XMLHttpRequest&&new i.XMLHttpRequest;const n="undefined"!=typeof globalThis?globalThis:t;n&&"undefined"==typeof self&&(n.self=n),n&&"undefined"==typeof File&&(n.File=function(){});const o=null!=t?t:{};function s(t,i){return-1!==t.indexOf(i)}const r=function(t){return t.trim()},u=Object.prototype,l=u.hasOwnProperty,c=u.toString,a=Array.isArray||function(t){return"[object Array]"===c.call(t)},h=t=>"function"==typeof t,d=t=>void 0===t,f=t=>"[object String]"==c.call(t),v=t=>null===t,_=t=>d(t)||v(t),p=t=>"[object Number]"==c.call(t)&&t==t;function b(t){return t?t.split("#")[0]:t}function m(t){try{return t()}catch(t){return}}function g(t){return g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},g(t)}function w(t,i,e){return(i=function(t){var i=function(t){if("object"!=g(t)||!t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var e=i.call(t,"string");if("object"!=g(e))return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==g(i)?i:i+""}(i))in t?Object.defineProperty(t,i,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[i]=e,t}function y(t,i){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);i&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),e.push.apply(e,n)}return e}function k(t){for(var i=1;arguments.length>i;i++){var e=null!=arguments[i]?arguments[i]:{};i%2?y(Object(e),!0).forEach(function(i){w(t,i,e[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):y(Object(e)).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(e,i))})}return t}const C=(t,{debugEnabled:i}={})=>{const e={N(e,...n){let o;try{o=typeof window>"u"?void 0:window}catch(t){return}o&&(o.POSTHOG_DEBUG||i)&&!d(o.console)&&o.console&&("__rrweb_original__"in o.console[e]?o.console[e].__rrweb_original__:o.console[e])(t,...n)},debug(...t){e.N("debug",...t)},info(...t){e.N("log",...t)},warn(...t){e.N("warn",...t)},error(...t){e.N("error",...t)},critical(...i){console.error(t,...i)},uninitializedWarning(t){e.error(`You must initialize PostHog before calling ${t}`)},createLogger:(i,e)=>C(`${t} ${i}`,e)};return e},O=C("[PostHog.js]"),x=O.createLogger;function j(t,i){if(!_(t))if(a(t))t.forEach(i);else if(t instanceof FormData)t.forEach((t,e)=>i(t,e));else for(const e in t)l.call(t,e)&&i(t[e],e)}const S=function(t,...i){for(const e of i)for(const i in e)void 0!==e[i]&&(t[i]=e[i]);return t};function A(t){const i=Object.keys(t);let e=i.length;const n=new Array(e);for(;e--;)n[e]=[i[e],t[i[e]]];return n}function D(t,i,e,n){const{capture:o=!1,passive:s=!0}=null!=n?n:{};null==t||t.addEventListener(i,e,{capture:o,passive:s})}function E(t){return!!t&&1===t.nodeType}function T(t,i){return!!t&&!!t.tagName&&t.tagName.toLowerCase()===i.toLowerCase()}function M(t){return!!t&&11===t.nodeType&&E(t.host)}function R(t){return t?r(t).split(/\s+/):[]}function L(t){let i="";switch(typeof t.className){case"string":i=t.className;break;case"object":i=(t.className&&"baseVal"in t.className?t.className.baseVal:null)||t.getAttribute("class")||"";break;default:i=""}return R(i)}function I(t){let i="";return B(t)&&!N(t)&&t.childNodes&&t.childNodes.length&&j(t.childNodes,function(t){var e,n;(function(t){return!!t&&3===t.nodeType})(t)&&t.textContent&&(i+=null!==(e=_(n=t.textContent)?null:r(n).split(/(\s+)/).filter(t=>it(t)).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255))&&void 0!==e?e:"")}),r(i)}function z(t){var i;return d(t.target)?t.srcElement||null:(null===(i=t.target)||void 0===i?void 0:i.shadowRoot)?t.composedPath()[0]||null:t.target||null}const H=["a","button","form","input","select","textarea","label"];function P(t,i){const e=t.matches||t.matchesSelector||t.msMatchesSelector||t.mozMatchesSelector||t.webkitMatchesSelector||t.oMatchesSelector;try{return!!e&&e.call(t,i)}catch(t){return!1}}function U(t){const i=t.parentNode;return!(!i||!E(i))&&i}const W=[".ph-no-deadclick",".ph-no-capture"];const G=["","text","search","email","password","url","tel","number"];function Z(t){return!(!t||!E(t))&&(!!T(t,"textarea")||(T(t,"input")?s(G,(t.getAttribute("type")||"").toLowerCase()):function(t){var i;if(t.isContentEditable)return!0;const e=null===(i=t.getAttribute)||void 0===i?void 0:i.call(t,"contenteditable");return"true"===e||""===e}(t)))}const F=t=>!t||T(t,"html")||!E(t),q=(t,i)=>{const e=typeof window>"u"?void 0:window;if(!e||F(t))return{parentIsUsefulElement:!1,targetElementList:[]};let n=!1;const o=[t];let s=t;for(;s.parentNode&&!T(s,"body");){if(M(s.parentNode)){o.push(s.parentNode.host),s=s.parentNode.host;continue}const t=U(s);if(!t)break;if(i||H.indexOf(t.tagName.toLowerCase())>-1)n=!0;else try{const i=e.getComputedStyle(t);i&&"pointer"===i.getPropertyValue("cursor")&&(n=!0)}catch(t){}o.push(t),s=t}return{parentIsUsefulElement:n,targetElementList:o}};function B(t){const i=new Set;let e=0;for(let n=t;n.parentNode&&!T(n,"body");n=n.parentNode){if(e++>=1e3||i.has(n))return!1;i.add(n);const t=L(n);if(s(t,"ph-sensitive")||s(t,"ph-no-capture"))return!1}if(s(L(t),"ph-include"))return!0;const n=t.type||"";if(f(n))switch(n.toLowerCase()){case"hidden":case"password":return!1}const o=t.name||t.id||"";return!f(o)||!/^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(o.replace(/[^a-zA-Z0-9]/g,""))}function N(t){return!!(T(t,"input")&&!["button","checkbox","submit","reset"].includes(t.type)||T(t,"select")||T(t,"textarea")||"true"===t.getAttribute("contenteditable"))}const V=new RegExp("^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$"),K=/(^|[^0-9A-Za-z_])([0-9][0-9 -]*[0-9])(?=$|[^0-9A-Za-z_])/g,Y=[16,15,14,13],J=new RegExp("^(\\d{3}-?\\d{2}-?\\d{4})$"),Q=new RegExp("(^|[^0-9])((?!000|666)[0-9]{3}-?(?!00)[0-9]{2}-?(?!0000)[0-9]{4})(?=$|([^0-9]))","g"),X=/[0-9A-Za-z_]/;function tt(t){let i=0,e=!1;for(let n=t.length-1;n>=0;n--){let o=t.charCodeAt(n)-48;e&&(o*=2,o>9&&(o-=9)),i+=o,e=!e}return i%10==0}function it(t,i=!0){if(_(t))return!1;if(f(t)){if(t=r(t),i?V.test((t||"").replace(/[- ]/g,"")):function(t){let i;for(K.lastIndex=0;i=K.exec(t);){const t=i[2];if(!t)continue;const e=t.replace(/[- ]/g,"");for(let t=0;e.length>t;t++)for(const i of Y){const n=t+i;if(e.length>=n){const i=e.slice(t,n);if(V.test(i)&&tt(i))return!0}}}return!1}(t))return!1;if(i?J.test(t):function(t){let i;for(Q.lastIndex=0;i=Q.exec(t);){const t=i[1],e=i[3];if(!(t&&e&&X.test(t)&&X.test(e)))return!0}return!1}(t))return!1}return!0}function et(t){let i=I(t);return i=`${i} ${nt(t)}`.trim(),it(i)?i:""}function nt(t){let i="";return t&&t.childNodes&&t.childNodes.length&&j(t.childNodes,function(t){var e;if(t&&"span"===(null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase()))try{const e=I(t);i=`${i} ${e}`.trim(),t.childNodes&&t.childNodes.length&&(i=`${i} ${nt(t)}`.trim())}catch(t){O.error("[AutoCapture]",t)}}),i}function ot(t){return t.replace(/"|\\"/g,'\\"')}function st(t){const i=t.attr__class;if(i)return a(i)?i:R(i)}function rt(t,i){return i.length>t?i.slice(0,t)+"...":i}function ut(t){if(t.previousElementSibling)return t.previousElementSibling;let i=t;do{i=i.previousSibling}while(i&&!E(i));return i}function lt(t,{e:i,maskAllElementAttributes:e,maskAllText:n,elementAttributeIgnoreList:o,elementsChainAsString:r,disableCaptureUrlHashes:u}){var l,c;if(!E(t))return{props:{}};const h=[t],v=new Set([t]);let _=t;for(;_.parentNode&&!T(_,"body")&&1e3>h.length;){if(M(_.parentNode)){const t=_.parentNode.host;if(v.has(t))break;v.add(t),h.push(t),_=t;continue}if(!E(_.parentNode))break;if(v.has(_.parentNode))break;v.add(_.parentNode),h.push(_.parentNode),_=_.parentNode}const p="click"===i.type&&"http://www.w3.org/2000/svg"===t.namespaceURI?h.findIndex(t=>T(t,"button")||T(t,"a")):-1;p>0&&(n=n||h.slice(0,p+1).some(t=>!B(t)||N(t)));const m=[],g={};let w,y=!1,C=!1;if(j(h,t=>{const i=B(t);if(T(t,"a")&&!e&&!(null==o?void 0:o.includes("href"))){const e=t.getAttribute("href");y=!!(i&&e&&it(e))&&(u?b(e):e)}s(L(t),"ph-no-capture")&&(C=!0),m.push(function(t,i,e,n,o=!1){const s=t.tagName.toLowerCase(),r={tag_name:s};H.indexOf(s)>-1&&!e&&(r.$el_text="a"===s.toLowerCase()||"button"===s.toLowerCase()?rt(1024,et(t)):rt(1024,I(t)));const u=L(t);i||(null==n?void 0:n.includes("class"))||0>=u.length||(r.classes=u.filter(function(t){return""!==t})),j(t.attributes,function(e){var s;if((!N(t)||-1!==["name","id","class","aria-label"].indexOf(e.name))&&!(null==n?void 0:n.includes(e.name))&&!i&&it(e.value)&&(!f(s=e.name)||"_ngcontent"!==s.substring(0,10)&&"_nghost"!==s.substring(0,7))){let t=e.value;"class"===e.name&&(t=R(t).join(" ")),r["attr__"+e.name]=rt(1024,"href"===e.name&&o?b(t):t)}});let l=1,c=1,a=t;for(;a=ut(a);)l++,a.tagName===t.tagName&&c++;return r.nth_child=l,r.nth_of_type=c,r}(t,e,n,o,u)),j(function(t){if(!B(t))return{};const i={};return j(t.attributes,function(t){if(t.name&&0===t.name.indexOf("data-ph-capture-attribute")){const e=t.name.replace("data-ph-capture-attribute-",""),n=t.value;e&&n&&it(n)&&(i[e]=n)}}),i}(t),(t,i)=>{({}).hasOwnProperty.call(g,i)||(g[i]=t)})}),C)return{props:{},explicitNoCapture:C};if(p>0&&(t=h[p],m.splice(0,p)),n||(m[0].$el_text=T(t,"a")||T(t,"button")?et(t):I(t)),y){var O,x;m[0].attr__href=y;const t=null===(O=(t=>{const i=typeof document>"u"?void 0:document,e=null==i?void 0:i.createElement("a");return d(e)?null:(e.href=t,e)})(y))||void 0===O?void 0:O.host,i=null===(x=typeof window>"u"?void 0:window)||void 0===x||null===(x=x.location)||void 0===x?void 0:x.host;t&&i&&t!==i&&(w=y)}return{props:S((z=i.type,{$event_type:z,$ce_version:1}),r?{}:{$elements:m},{$elements_chain:(D=m,a(D)?function(t){return t.map(t=>{var i,e;let n="";if(t.tag_name&&(n+=t.tag_name),t.attr_class){t.attr_class.sort();for(const i of t.attr_class)n+=`.${i.replace(/"/g,"")}`}const o=k(k(k(k({},t.text?{text:t.text}:{}),{},{"nth-child":null!==(i=t.nth_child)&&void 0!==i?i:0,"nth-of-type":null!==(e=t.nth_of_type)&&void 0!==e?e:0},t.href?{href:t.href}:{}),t.attr_id?{attr_id:t.attr_id}:{}),t.attributes),s={};return A(o).sort(([t],[i])=>function(t,i){return i>t?-1:t>i?1:0}(t,i)).forEach(([t,i])=>s[ot(t.toString())]=ot(i.toString())),n+=":",n+=A(s).map(([t,i])=>`${t}="${i}"`).join(""),n}).join(";")}(function(t){return t.map(t=>{var i,e;const n={text:null===(i=t.$el_text)||void 0===i?void 0:i.slice(0,400),tag_name:t.tag_name,href:null===(e=t.attr__href)||void 0===e?void 0:e.slice(0,2048),attr_class:st(t),attr_id:t.attr__id,nth_child:t.nth_child,nth_of_type:t.nth_of_type,attributes:{}};return A(t).filter(([t])=>0===t.indexOf("attr__")).forEach(([t,i])=>n.attributes[t]=i),n})}(D)):"")},(null===(l=m[0])||void 0===l?void 0:l.$el_text)?{$el_text:null===(c=m[0])||void 0===c?void 0:c.$el_text}:{},w&&"click"===i.type?{$external_click_url:w}:{},g),target:t};var D,z}x("[AutoCapture]");const ct={};function at(t,i){const e=z(t);return e?k({node:e,originalEvent:t,timestamp:Date.now()},i):null}function ht(t){return!!m(()=>E(t))}function dt(t,i){return Math.abs(t)<Math.abs(i)?0>i?"up":"down":0>t?"left":"right"}function ft(t){return"swipe"===t.type?"$dead_swipe":"$dead_click"}const vt="canvas,video,audio,embed,object";function _t(t,i){return p(t)&&t>=i}function pt(t,i=1e3){return t>=0&&i>t?t:void 0}function bt(t,i,e=1e3){return p(i)?pt(t-i,e):void 0}var mt=class{pr(t){var i,e,n,o,s,r,u,l;const c=this.mr((null==t?void 0:t.__onCapture)||this.gr.bind(this));return{element_attribute_ignorelist:null!==(i=null==t?void 0:t.element_attribute_ignorelist)&&void 0!==i?i:c.element_attribute_ignorelist,scroll_threshold_ms:null!==(e=null==t?void 0:t.scroll_threshold_ms)&&void 0!==e?e:c.scroll_threshold_ms,selection_change_threshold_ms:null!==(n=null==t?void 0:t.selection_change_threshold_ms)&&void 0!==n?n:c.selection_change_threshold_ms,mutation_threshold_ms:null!==(o=null==t?void 0:t.mutation_threshold_ms)&&void 0!==o?o:c.mutation_threshold_ms,capture_clicks_with_modifier_keys:null!==(s=null==t?void 0:t.capture_clicks_with_modifier_keys)&&void 0!==s?s:c.capture_clicks_with_modifier_keys,capture_dead_swipes:null!==(r=null==t?void 0:t.capture_dead_swipes)&&void 0!==r?r:c.capture_dead_swipes,swipe_threshold_px:null!==(u=null==t?void 0:t.swipe_threshold_px)&&void 0!==u?u:c.swipe_threshold_px,max_dead_swipes_per_page_load:null!==(l=null==t?void 0:t.max_dead_swipes_per_page_load)&&void 0!==l?l:c.max_dead_swipes_per_page_load,css_selector_ignorelist:null==t?void 0:t.css_selector_ignorelist,__onCapture:c.__onCapture}}constructor(t,i){this.instance=t,this.yr=new WeakSet,this.br=!1,this.wr=[],this.kr=0,this.mr=t=>({element_attribute_ignorelist:[],scroll_threshold_ms:100,selection_change_threshold_ms:100,mutation_threshold_ms:2500,capture_clicks_with_modifier_keys:!1,capture_dead_swipes:!0,swipe_threshold_px:30,max_dead_swipes_per_page_load:10,__onCapture:t}),this.Sr=()=>{clearTimeout(this._r),this._r=void 0,this.Cr=void 0},this.Ir=t=>{if(this.Mr(t),this.Sr(),0===t.button){const i={path:t.composedPath(),trusted:t.isTrusted,selectionChanged:!1,selectionInitiallyRelated:!1},n=null==e?void 0:e.getSelection();i.selectionInitiallyRelated="Range"===(null==n?void 0:n.type)&&this.Tr(n,i),this.Cr=i}},this.Rr=t=>{v(t.relatedTarget)&&this.Sr()},this.Er=t=>{const i=this.Cr,e=t;if(!i||0!==e.button||t.isTrusted!==i.trusted)return;const n=t.composedPath();for(const t of i.path)if(ht(t)&&-1!==n.indexOf(t)){i.clickTarget=t;break}i.clickDetail=e.detail,this._r=o.setTimeout(this.Sr,0)},this.$r=t=>{this.Mr(t);const i=t,e=at(i,{type:"click"}),n=this.Cr;e&&n&&0===i.button&&i.detail>0&&i.detail===n.clickDetail&&t.isTrusted===n.trusted&&e.node===n.clickTarget&&(e.selectionChangedDuringGesture=n.selectionChanged&&this.Ar.selection_change_threshold_ms>0,this.Sr()),v(e)||this.Or(e)||this.Pr(e),this.Fr()},this.Lr=()=>{const t=Date.now();this.Dr=t,t%50==0&&this.wr.forEach(i=>{d(i.scrollDelayMs)&&(i.scrollDelayMs=t-i.timestamp)})},this.Nr=t=>{var i,n;const o=null==e?void 0:e.getSelection(),s=this.br;this.br="Range"===(null==o?void 0:o.type);const r=null==o?void 0:o.focusNode,u=r&&(E(r)?r:r.parentElement),l=null==e?void 0:e.activeElement;let c=l;for(;null==c||null===(i=c.shadowRoot)||void 0===i?void 0:i.activeElement;)c=c.shadowRoot.activeElement;const a=Z(z(t))||Z(null!=u?u:null)||Z(null!==(n=c)&&void 0!==n?n:null),h="Caret"===(null==o?void 0:o.type)&&c&&!c.shadowRoot&&r&&r!==l&&r.contains(null!=l?l:null);if(!(s||this.br||a||h))return;const f=Date.now();this.qr=f;const v=this.Cr;if(v&&(s||this.br||a)){const i=z(t);let e;if(Z(i))e=i;else if("Caret"===(null==o?void 0:o.type)){var _;Z(null!==(_=c)&&void 0!==_?_:null)||h?e=c:a&&(e=u)}const n=e?this.jr(e,v):o&&(r||o.anchorNode)?this.Tr(o,v):s&&!this.br&&v.selectionInitiallyRelated;v.selectionChanged=v.selectionChanged||n}this.wr.forEach(t=>{const i=f-t.timestamp;0>i||!d(t.selectionChangedDelayMs)&&i>=t.selectionChangedDelayMs||(t.selectionChangedDelayMs=i)})},this.sn=()=>{"hidden"===(null==e?void 0:e.visibilityState)&&this.Sr();const t=Date.now();this.Br=t,this.zr("visibilityChangedDelayMs",t)},this.Hr=()=>{const t=Date.now();this.Ur=t,this.zr("focusChangedDelayMs",t)},this.Wr=t=>{this.Mr(t);const i=t.touches,e=1===(null==i?void 0:i.length)?i[0]:void 0;this.Vr=e?{x:e.clientX,y:e.clientY,timestamp:Date.now()}:void 0},this.Gr=()=>{this.Vr=void 0},this.Qr=t=>{var i;const n=this.Vr;if(this.Vr=void 0,d(n)||this.kr>=this.Ar.max_dead_swipes_per_page_load)return;const o=t,s=null===(i=o.changedTouches)||void 0===i?void 0:i[0];if(!s)return;const r=s.clientX-n.x,u=s.clientY-n.y,l=r*r+u*u,c=this.Ar.swipe_threshold_px;if(c*c>l)return;if([this.Dr,this.Zr,this.qr].some(t=>p(t)&&t>=n.timestamp))return;var a,h;if(this.Jr()&&(null!==(a=null==e||null===(h=e.elementsFromPoint)||void 0===h?void 0:h.call(e,n.x,n.y))&&void 0!==a?a:[]).some(t=>{var i;return null===(i=t.matches)||void 0===i?void 0:i.call(t,vt)}))return;const f=at(o,{type:"swipe",swipeDirection:dt(r,u),swipeDistancePx:Math.round(Math.sqrt(l))});v(f)||this.Or(f)||this.Pr(f),this.Fr()},this.Ar=this.pr(i),this._onCapture=this.Ar.__onCapture}start(t){this.Kr(),this.Xr(),this.Yr(),this.eo(),this.no(),this.io(t),this.Ar.capture_dead_swipes&&this.ro()}io(i){if(!this.oo){const e=function(i){return function(i,e){const n=ct[i];if(n)return n;let o=e[i];if(h(r=o)&&-1!==r.toString().indexOf("[native code]")&&!(null==t?void 0:t.Zone))return ct[i]=o.bind(e);var r;const u=e.document;if(u&&h(u.createElement)){let t,n=!1;try{t=u.createElement("iframe"),t.hidden=!0,u.head.appendChild(t);const r=t.contentWindow;var l,c;r&&r[i]&&(o=r[i],"MutationObserver"===i&&s(a=null!==(l=null===(c=e.navigator)||void 0===c?void 0:c.userAgent)&&void 0!==l?l:"","AppleWebKit")&&!s(a,"Chrome")&&(t.classList.add("rr-block","ph-no-capture"),n=!0))}catch(t){O.warn(`Could not create sandbox iframe for ${i} check, bailing to assignableWindow.${i}: `,t)}finally{!n&&(null==t?void 0:t.parentNode)&&t.parentNode.removeChild(t)}}var a;return o&&h(o)?ct[i]=o.bind(e):o}("MutationObserver",i)}(o);this.oo=new e(t=>{this.so(t)}),this.ao(i)}}ao(t){t&&this.oo&&(this.yr.has(t)||(this.oo.observe(t,{attributes:!0,characterData:!0,childList:!0,subtree:!0}),this.yr.add(t),this.lo(t)))}lo(t,i){var e,n;E(t)&&t.shadowRoot&&this.ao(t.shadowRoot);const o=null!==(e=null===(n=t.querySelectorAll)||void 0===n?void 0:n.call(t,"*"))&&void 0!==e?e:[];for(let t=0;o.length>t;t++)null==i||i.add(o[t]),this.ao(o[t].shadowRoot)}Mr(t){var i,e;const n=null!==(i=null===(e=t.composedPath)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];for(let t=0;n.length>t;t++){const i=n[t];ht(i)&&this.ao(i.shadowRoot)}}stop(){var t;null===(t=this.oo)||void 0===t||t.disconnect(),this.oo=void 0,this.yr=new WeakSet,o.removeEventListener("click",this.$r,{capture:!0}),o.removeEventListener("mousedown",this.Ir,{capture:!0}),o.removeEventListener("mouseup",this.Er,{capture:!0}),o.removeEventListener("mouseout",this.Rr,{capture:!0}),o.removeEventListener("dragstart",this.Sr,{capture:!0}),o.removeEventListener("pointercancel",this.Sr,{capture:!0}),o.removeEventListener("blur",this.Sr),this.Sr(),o.removeEventListener("scroll",this.Lr,{capture:!0}),null==e||e.removeEventListener("selectionchange",this.Nr),o.removeEventListener("touchstart",this.Wr,{capture:!0}),o.removeEventListener("touchend",this.Qr,{capture:!0}),o.removeEventListener("touchcancel",this.Gr,{capture:!0}),null==e||e.removeEventListener("visibilitychange",this.sn),o.removeEventListener("blur",this.Hr),o.removeEventListener("focus",this.Hr),this.Vr=void 0}so(t){const i=new Set;for(const n of t)try{var e;if(!1===(null===(e=n.target)||void 0===e?void 0:e.isConnected))continue;this.Zr=Date.now();const t=n.addedNodes;for(let e=0;t.length>e;e++){const n=t[e];ht(n)&&!i.has(n)&&this.lo(n,i)}}catch(t){}}Kr(){D(o,"click",this.$r,{capture:!0}),D(o,"mousedown",this.Ir,{capture:!0}),D(o,"mouseup",this.Er,{capture:!0}),D(o,"mouseout",this.Rr,{capture:!0}),D(o,"dragstart",this.Sr,{capture:!0}),D(o,"pointercancel",this.Sr,{capture:!0}),D(o,"blur",this.Sr)}Pr(t){t.selectionChangedDelayMs=bt(t.timestamp,this.qr,this.Ar.selection_change_threshold_ms),t.visibilityChangedDelayMs=bt(t.timestamp,this.Br),t.focusChangedDelayMs=bt(t.timestamp,this.Ur),this.wr.push(t)}Fr(){this.wr.length&&d(this.uo)&&(this.uo=o.setTimeout(()=>{this.co()},1e3))}Xr(){D(o,"scroll",this.Lr,{capture:!0})}Yr(){var t;this.br="Range"===(null==e||null===(t=e.getSelection())||void 0===t?void 0:t.type),D(e,"selectionchange",this.Nr)}jr(t,i){const e=i.path[0];try{for(;t;){if(-1!==i.path.indexOf(t)||E(e)&&e.contains(t))return!0;t=t.getRootNode().host}}catch(t){}return!1}Tr(t,i){const e=i.path[0],n=t.rangeCount>0?t.getRangeAt(0):void 0,o=!!n&&m(()=>n.startContainer.getRootNode()===e.getRootNode());if(n&&o&&E(e)){var s;if(!n.collapsed)return n.intersectsNode(e);const t=E(n.startContainer)&&null!==(s=n.startContainer.childNodes[n.startOffset])&&void 0!==s?s:n.startContainer;return this.jr(t,i)}return this.jr(t.focusNode,i)||this.jr(t.anchorNode,i)}eo(){D(e,"visibilitychange",this.sn)}no(){D(o,"blur",this.Hr),D(o,"focus",this.Hr)}zr(t,i){this.wr.forEach(e=>{const n=pt(i-e.timestamp);p(n)&&(d(e[t])||e[t]>n)&&(e[t]=n)})}ro(){D(o,"touchstart",this.Wr,{capture:!0,passive:!0}),D(o,"touchend",this.Qr,{capture:!0,passive:!0}),D(o,"touchcancel",this.Gr,{capture:!0,passive:!0})}Jr(){const t=d(this.do)||p(this.Zr)&&this.Zr>this.do;return(d(this.ho)||t)&&(this.do=Date.now(),this.ho=!!(null==e?void 0:e.querySelector(vt))),!!this.ho}Or(t){return!t||("swipe"===t.type?this.fo(t):this.vo(t))}fo(t){return!((!((i=t.node)instanceof Element)||"__POSTHOG_TOOLBAR__"!==i.id&&!(null===(e=i.closest)||void 0===e?void 0:e.call(i,".toolbar-global-fade-container")))&&!this.wr.some(i=>i.type===t.type&&i.node===t.node&&1e3>Math.abs(i.timestamp-t.timestamp))&&!T(t.node,"html")&&E(t.node)&&function(t,i){var e;if(!(typeof window>"u"?void 0:window)||F(t))return!1;const n="[object Boolean]"===c.call(i)?W:null!==(e=null==i?void 0:i.css_selector_ignorelist)&&void 0!==e?e:W,{targetElementList:o}=q(t,!1);return!function(t,i){if(d(i))return!0;for(const e of t)if(i.some(t=>P(e,t)))return!0;return!1}(o,n)}(t.node,{css_selector_ignorelist:this.Ar.css_selector_ignorelist}));var i,e}vo(t){return!(this.Ar.capture_clicks_with_modifier_keys||(i=t.originalEvent,!(i.ctrlKey||i.metaKey||i.altKey||i.shiftKey)))||!!this.fo(t)||function(t){if(!(typeof window>"u"?void 0:window)||F(t))return!1;const{targetElementList:i}=q(t,!1);return i.some(t=>T(t,"a"))}(t.node);var i}co(){if(!this.wr.length)return;clearTimeout(this.uo),this.uo=void 0;const t=this.wr;this.wr=[];for(const e of t){var i;e.mutationDelayMs=null!==(i=e.mutationDelayMs)&&void 0!==i?i:this.Zr&&this.Zr>=e.timestamp?this.Zr-e.timestamp:void 0,e.absoluteDelayMs=Date.now()-e.timestamp;const t=_t(e.scrollDelayMs,this.Ar.scroll_threshold_ms),n=_t(e.selectionChangedDelayMs,this.Ar.selection_change_threshold_ms),o=_t(e.mutationDelayMs,this.Ar.mutation_threshold_ms),s=_t(e.absoluteDelayMs,1.1*this.Ar.mutation_threshold_ms),r=p(e.scrollDelayMs)&&this.Ar.scroll_threshold_ms>e.scrollDelayMs,u=p(e.mutationDelayMs)&&this.Ar.mutation_threshold_ms>e.mutationDelayMs,l=e.selectionChangedDuringGesture||p(e.selectionChangedDelayMs)&&this.Ar.selection_change_threshold_ms>e.selectionChangedDelayMs,c=p(e.visibilityChangedDelayMs),a=p(e.focusChangedDelayMs);if(!(r||u||l||c||a))if(t||o||s||n){const i=ft(e);if("$dead_swipe"===i){if(this.kr>=this.Ar.max_dead_swipes_per_page_load)continue;this.kr++}this._onCapture(e,{[`${i}_last_mutation_timestamp`]:this.Zr,[`${i}_event_timestamp`]:e.timestamp,[`${i}_scroll_timeout`]:t,[`${i}_mutation_timeout`]:o,[`${i}_absolute_timeout`]:s,[`${i}_selection_changed_timeout`]:n,[`${i}_visibility_changed_timeout`]:!1})}else this.Ar.mutation_threshold_ms>e.absoluteDelayMs&&this.wr.push(e)}this.Fr()}gr(t,i){const e=ft(t);this.instance.capture(e,k(k(k({},i),lt(t.node,{e:t.originalEvent,maskAllElementAttributes:this.instance.config.mask_all_element_attributes,maskAllText:this.instance.config.mask_all_text,elementAttributeIgnoreList:this.Ar.element_attribute_ignorelist,elementsChainAsString:!1,disableCaptureUrlHashes:this.instance.config.disable_capture_url_hashes}).props),{},{[`${e}_scroll_delay_ms`]:t.scrollDelayMs,[`${e}_mutation_delay_ms`]:t.mutationDelayMs,[`${e}_absolute_delay_ms`]:t.absoluteDelayMs,[`${e}_selection_changed_delay_ms`]:t.selectionChangedDelayMs,[`${e}_visibility_changed_delay_ms`]:t.visibilityChangedDelayMs,[`${e}_focus_changed_delay_ms`]:t.focusChangedDelayMs,$dead_swipe_direction:t.swipeDirection,$dead_swipe_distance_px:t.swipeDistancePx}),{timestamp:new Date(t.timestamp)})}};o.__PosthogExtensions__=o.__PosthogExtensions__||{},o.__PosthogExtensions__.initDeadClicksAutocapture=(t,i)=>new mt(t,i)}(); //# sourceMappingURL=dead-clicks-autocapture.js.map