Files
JiaZhiQianYan/node_modules/posthog-js/dist/dead-clicks-autocapture.js

3 lines
12 KiB
JavaScript

!function(){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)({}).hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t},t.apply(null,arguments)}var r="undefined"!=typeof window?window:void 0,n="undefined"!=typeof globalThis?globalThis:r,e=Array.prototype.forEach,i=null==n?void 0:n.navigator,a=null==n?void 0:n.document;null==n||n.location,null==n||n.fetch,null!=n&&n.XMLHttpRequest&&"withCredentials"in new n.XMLHttpRequest&&n.XMLHttpRequest,null==n||n.AbortController,null==i||i.userAgent;var u=null!=r?r:{};function o(t,r){return-1!==t.indexOf(r)}var l=function(t){return t.trim()},s=Array.isArray,c=Object.prototype,f=c.hasOwnProperty,v=c.toString,h=s||function(t){return"[object Array]"===v.call(t)},d=t=>"function"==typeof t,_=t=>d(t)&&-1!==t.toString().indexOf("[native code]"),m=t=>void 0===t,b=t=>"[object String]"==v.call(t),p=t=>null===t,g=t=>m(t)||p(t),w=t=>"[object Number]"==v.call(t),k=t=>t instanceof FormData,y=function(t,n){var{debugEnabled:e}=void 0===n?{}:n,i={t:function(n){if(r&&(u.POSTHOG_DEBUG||e)&&!m(r.console)&&r.console){for(var i=("__rrweb_original__"in r.console[n]?r.console[n].__rrweb_original__:r.console[n]),a=arguments.length,o=new Array(a>1?a-1:0),l=1;l<a;l++)o[l-1]=arguments[l];i(t,...o)}},info:function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];i.t("log",...r)},warn:function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];i.t("warn",...r)},error:function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];i.t("error",...r)},critical:function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];console.error(t,...n)},uninitializedWarning:t=>{i.error("You must initialize PostHog before calling "+t)},createLogger:(r,n)=>y(t+" "+r,n)};return i},A=y("[PostHog.js]"),x=A.createLogger,C={};function O(t,r,n){if(h(t))if(e&&t.forEach===e)t.forEach(r,n);else if("length"in t&&t.length===+t.length)for(var i=0,a=t.length;i<a;i++)if(i in t&&r.call(n,t[i],i)===C)return}function j(t,r,n){if(!g(t)){if(h(t))return O(t,r,n);if(k(t)){for(var e of t.entries())if(r.call(n,e[1],e[0])===C)return}else for(var i in t)if(f.call(t,i)&&r.call(n,t[i],i)===C)return}}var D=function(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),e=1;e<r;e++)n[e-1]=arguments[e];return O(n,(function(r){for(var n in r)void 0!==r[n]&&(t[n]=r[n])})),t};function E(t){for(var r=Object.keys(t),n=r.length,e=new Array(n);n--;)e[n]=[r[n],t[r[n]]];return e}function T(t,r,n,e){var{capture:i=!1,passive:a=!0}=null!=e?e:{};null==t||t.addEventListener(r,n,{capture:i,passive:a})}function R(t){return!!t&&1===t.nodeType}function L(t,r){return!!t&&!!t.tagName&&t.tagName.toLowerCase()===r.toLowerCase()}function M(t){return t?l(t).split(/\s+/):[]}function S(t){var r="";switch(typeof t.className){case"string":r=t.className;break;case"object":r=(t.className&&"baseVal"in t.className?t.className.baseVal:null)||t.getAttribute("class")||"";break;default:r=""}return M(r)}function z(t){var r="";return P(t)&&!I(t)&&t.childNodes&&t.childNodes.length&&j(t.childNodes,(function(t){var n,e;(function(t){return!!t&&3===t.nodeType})(t)&&t.textContent&&(r+=null!==(e=t.textContent,n=g(e)?null:l(e).split(/(\s+)/).filter((t=>V(t))).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255))&&void 0!==n?n:"")})),l(r)}var H=["a","button","form","input","select","textarea","label"];function P(t){for(var r=t;r.parentNode&&!L(r,"body");r=r.parentNode){var n=S(r);if(o(n,"ph-sensitive")||o(n,"ph-no-capture"))return!1}if(o(S(t),"ph-include"))return!0;var e=t.type||"";if(b(e))switch(e.toLowerCase()){case"hidden":case"password":return!1}var i=t.name||t.id||"";if(b(i)){if(/^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(i.replace(/[^a-zA-Z0-9]/g,"")))return!1}return!0}function I(t){return!!(L(t,"input")&&!["button","checkbox","submit","reset"].includes(t.type)||L(t,"select")||L(t,"textarea")||"true"===t.getAttribute("contenteditable"))}var N="(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})",W=new RegExp("^(?:"+N+")$"),q=new RegExp(N),B="\\d{3}-?\\d{2}-?\\d{4}",F=new RegExp("^("+B+")$"),G=new RegExp("("+B+")");function V(t,r){if(void 0===r&&(r=!0),g(t))return!1;if(b(t)){if(t=l(t),(r?W:q).test((t||"").replace(/[- ]/g,"")))return!1;if((r?F:G).test(t))return!1}return!0}function Y(t){var r=z(t);return V(r=(r+" "+Z(t)).trim())?r:""}function Z(t){var r="";return t&&t.childNodes&&t.childNodes.length&&j(t.childNodes,(function(t){var n;if(t&&"span"===(null==(n=t.tagName)?void 0:n.toLowerCase()))try{var e=z(t);r=(r+" "+e).trim(),t.childNodes&&t.childNodes.length&&(r=(r+" "+Z(t)).trim())}catch(t){A.error("[AutoCapture]",t)}})),r}function J(r){return function(r){var n=r.map((r=>{var n,e,i="";if(r.tag_name&&(i+=r.tag_name),r.attr_class)for(var a of(r.attr_class.sort(),r.attr_class))i+="."+a.replace(/"/g,"");var u=t({},r.text?{text:r.text}:{},{"nth-child":null!==(n=r.nth_child)&&void 0!==n?n:0,"nth-of-type":null!==(e=r.nth_of_type)&&void 0!==e?e:0},r.href?{href:r.href}:{},r.attr_id?{attr_id:r.attr_id}:{},r.attributes),o={};return E(u).sort(((t,r)=>{var[n]=t,[e]=r;return n.localeCompare(e)})).forEach((t=>{var[r,n]=t;return o[K(r.toString())]=K(n.toString())})),i+=":",i+=E(o).map((t=>{var[r,n]=t;return r+'="'+n+'"'})).join("")}));return n.join(";")}(function(t){return t.map((t=>{var r,n,e={text:null==(r=t.$el_text)?void 0:r.slice(0,400),tag_name:t.tag_name,href:null==(n=t.attr__href)?void 0:n.slice(0,2048),attr_class:Q(t),attr_id:t.attr__id,nth_child:t.nth_child,nth_of_type:t.nth_of_type,attributes:{}};return E(t).filter((t=>{var[r]=t;return 0===r.indexOf("attr__")})).forEach((t=>{var[r,n]=t;return e.attributes[r]=n})),e}))}(r))}function K(t){return t.replace(/"|\\"/g,'\\"')}function Q(t){var r=t.attr__class;return r?h(r)?r:M(r):void 0}function U(t,r){return r.length>t?r.slice(0,t)+"...":r}function X(t){if(t.previousElementSibling)return t.previousElementSibling;var r=t;do{r=r.previousSibling}while(r&&!R(r));return r}function tt(t,r,n,e){var i=t.tagName.toLowerCase(),a={tag_name:i};H.indexOf(i)>-1&&!n&&("a"===i.toLowerCase()||"button"===i.toLowerCase()?a.$el_text=U(1024,Y(t)):a.$el_text=U(1024,z(t)));var u=S(t);u.length>0&&(a.classes=u.filter((function(t){return""!==t}))),j(t.attributes,(function(n){var i;if((!I(t)||-1!==["name","id","class","aria-label"].indexOf(n.name))&&((null==e||!e.includes(n.name))&&!r&&V(n.value)&&(i=n.name,!b(i)||"_ngcontent"!==i.substring(0,10)&&"_nghost"!==i.substring(0,7)))){var u=n.value;"class"===n.name&&(u=M(u).join(" ")),a["attr__"+n.name]=U(1024,u)}}));for(var o=1,l=1,s=t;s=X(s);)o++,s.tagName===t.tagName&&l++;return a.nth_child=o,a.nth_of_type=l,a}function rt(t,n){for(var e,i,u,{e:l,maskAllElementAttributes:s,maskAllText:c,elementAttributeIgnoreList:f}=n,v=[t],h=t;h.parentNode&&!L(h,"body");)(u=h.parentNode)&&11===u.nodeType?(v.push(h.parentNode.host),h=h.parentNode.host):(v.push(h.parentNode),h=h.parentNode);var d,_,b,p=[],g={},w=!1,k=!1;if(j(v,(t=>{var r=P(t);"a"===t.tagName.toLowerCase()&&(w=t.getAttribute("href"),w=r&&w&&V(w)&&w),o(S(t),"ph-no-capture")&&(k=!0),p.push(tt(t,s,c,f));var n=function(t){if(!P(t))return{};var r={};return j(t.attributes,(function(t){if(t.name&&0===t.name.indexOf("data-ph-capture-attribute")){var n=t.name.replace("data-ph-capture-attribute-",""),e=t.value;n&&e&&V(e)&&(r[n]=e)}})),r}(t);D(g,n)})),k)return{props:{},explicitNoCapture:k};if(c||("a"===t.tagName.toLowerCase()||"button"===t.tagName.toLowerCase()?p[0].$el_text=Y(t):p[0].$el_text=z(t)),w){var y,A;p[0].attr__href=w;var x=null==(_=w,b=null==a?void 0:a.createElement("a"),y=m(b)?null:(b.href=_,b))?void 0:y.host,C=null==r||null==(A=r.location)?void 0:A.host;x&&C&&x!==C&&(d=w)}return{props:D({$event_type:l.type,$ce_version:1},{$elements:p},{$elements_chain:J(p)},null!=(e=p[0])&&e.$el_text?{$el_text:null==(i=p[0])?void 0:i.$el_text}:{},d&&"click"===l.type?{$external_click_url:d}:{},g)}}x("[AutoCapture]");var nt=()=>!!r.Zone,et={};function it(t){return function(t,r){var n=et[t];if(n)return n;var e=r[t];if(_(e)&&!nt())return et[t]=e.bind(r);var i=r.document;if(i&&d(i.createElement))try{var a=i.createElement("iframe");a.hidden=!0,i.head.appendChild(a);var u=a.contentWindow;u&&u[t]&&(e=u[t]),i.head.removeChild(a)}catch(r){A.warn("Could not create sandbox iframe for "+t+" check, bailing to assignableWindow."+t+": ",r)}return e&&d(e)?et[t]=e.bind(r):e}("MutationObserver",t)}function at(t){var r,n,e=m((r=t).target)?r.srcElement||null:null!=(n=r.target)&&n.shadowRoot?r.composedPath()[0]||null:r.target||null;return e?{node:e,originalEvent:t,timestamp:Date.now()}:null}function ut(t,r){return w(t)&&t>=r}class ot{i(t){var r,n,e,i,a=this.u((null==t?void 0:t.__onCapture)||this.o.bind(this));return{element_attribute_ignorelist:null!==(r=null==t?void 0:t.element_attribute_ignorelist)&&void 0!==r?r:a.element_attribute_ignorelist,scroll_threshold_ms:null!==(n=null==t?void 0:t.scroll_threshold_ms)&&void 0!==n?n:a.scroll_threshold_ms,selection_change_threshold_ms:null!==(e=null==t?void 0:t.selection_change_threshold_ms)&&void 0!==e?e:a.selection_change_threshold_ms,mutation_threshold_ms:null!==(i=null==t?void 0:t.mutation_threshold_ms)&&void 0!==i?i:a.mutation_threshold_ms,__onCapture:a.__onCapture}}constructor(t,r){this.l=[],this.u=t=>({element_attribute_ignorelist:[],scroll_threshold_ms:100,selection_change_threshold_ms:100,mutation_threshold_ms:2500,__onCapture:t}),this.v=t=>{var r=at(t);p(r)||this.h(r)||this.l.push(r),this.l.length&&m(this.m)&&(this.m=u.setTimeout((()=>{this.p()}),1e3))},this.k=()=>{var t=Date.now();t%50==0&&this.l.forEach((r=>{m(r.scrollDelayMs)&&(r.scrollDelayMs=t-r.timestamp)}))},this.A=()=>{this.$=Date.now()},this.instance=t,this.C=this.i(r),this._onCapture=this.C.__onCapture}start(t){this.O(),this.j(),this.D(),this.T(t)}T(t){if(!this.R){var r=it(u);this.R=new r((t=>{this.L(t)})),this.R.observe(t,{attributes:!0,characterData:!0,childList:!0,subtree:!0})}}stop(){var t;null==(t=this.R)||t.disconnect(),this.R=void 0,u.removeEventListener("click",this.v),u.removeEventListener("scroll",this.k,{capture:!0}),u.removeEventListener("selectionchange",this.A)}L(t){this.M=Date.now()}O(){T(u,"click",this.v)}j(){T(u,"scroll",this.k,{capture:!0})}D(){T(u,"selectionchange",this.A)}h(t){return!t||(!!((r=t.node)instanceof Element&&("__POSTHOG_TOOLBAR__"===r.id||null!=r.closest&&r.closest(".toolbar-global-fade-container")))||(!!this.l.some((r=>r.node===t.node&&Math.abs(r.timestamp-t.timestamp)<1e3))||!(!L(t.node,"html")&&R(t.node)&&!H.includes(t.node.tagName.toLowerCase()))));var r}p(){if(this.l.length){clearTimeout(this.m),this.m=void 0;var t=this.l;for(var r of(this.l=[],t)){var n;r.mutationDelayMs=null!==(n=r.mutationDelayMs)&&void 0!==n?n:this.M&&r.timestamp<=this.M?this.M-r.timestamp:void 0,r.absoluteDelayMs=Date.now()-r.timestamp,r.selectionChangedDelayMs=this.$&&r.timestamp<=this.$?this.$-r.timestamp:void 0;var e=ut(r.scrollDelayMs,this.C.scroll_threshold_ms),i=ut(r.selectionChangedDelayMs,this.C.selection_change_threshold_ms),a=ut(r.mutationDelayMs,this.C.mutation_threshold_ms),o=ut(r.absoluteDelayMs,1.1*this.C.mutation_threshold_ms),l=w(r.scrollDelayMs)&&r.scrollDelayMs<this.C.scroll_threshold_ms,s=w(r.mutationDelayMs)&&r.mutationDelayMs<this.C.mutation_threshold_ms,c=w(r.selectionChangedDelayMs)&&r.selectionChangedDelayMs<this.C.selection_change_threshold_ms;l||s||c||(e||a||o||i?this._onCapture(r,{$dead_click_last_mutation_timestamp:this.M,$dead_click_event_timestamp:r.timestamp,$dead_click_scroll_timeout:e,$dead_click_mutation_timeout:a,$dead_click_absolute_timeout:o,$dead_click_selection_changed_timeout:i}):r.absoluteDelayMs<this.C.mutation_threshold_ms&&this.l.push(r))}this.l.length&&m(this.m)&&(this.m=u.setTimeout((()=>{this.p()}),1e3))}}o(r,n){this.instance.capture("$dead_click",t({},n,rt(r.node,{e:r.originalEvent,maskAllElementAttributes:this.instance.config.mask_all_element_attributes,maskAllText:this.instance.config.mask_all_text,elementAttributeIgnoreList:this.C.element_attribute_ignorelist}).props,{$dead_click_scroll_delay_ms:r.scrollDelayMs,$dead_click_mutation_delay_ms:r.mutationDelayMs,$dead_click_absolute_delay_ms:r.absoluteDelayMs,$dead_click_selection_changed_delay_ms:r.selectionChangedDelayMs}),{timestamp:new Date(r.timestamp)})}}u.__PosthogExtensions__=u.__PosthogExtensions__||{},u.__PosthogExtensions__.initDeadClicksAutocapture=(t,r)=>new ot(t,r)}();
//# sourceMappingURL=dead-clicks-autocapture.js.map