UNPKG

posthog-js

Version:

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

2 lines • 5.28 kB
function n(n,t){return n.match(/\\?.|^$/g).reduce((n,e)=>('"'!==e||n.sQuote?"'"!==e||n.quote?n.quote||n.sQuote||e!==t?n.a[n.a.length-1]+=e:n.a.push(""):(n.sQuote^=1,n.a[n.a.length-1]+=e):(n.quote^=1,n.a[n.a.length-1]+=e),n),{a:[""]}).a}function t(n){return n.nodeType===Node.DOCUMENT_FRAGMENT_NODE||n.nodeType===Node.DOCUMENT_NODE}function e(n,t){const e=n.parentNode;return e&&e.host&&11===e.nodeType?e.host:e===t?null:e}const r="u">typeof window?window:void 0,o="u">typeof globalThis?globalThis:r;null!=o&&o.XMLHttpRequest&&new o.XMLHttpRequest;const u=Object.prototype.toString,l=Array.isArray||function(n){return"[object Array]"===u.call(n)},i=n=>void 0===n,c=(n,t,e)=>{function r(r,...o){t(()=>{(0,e[r])(n,...o)})}return{debug(...n){r("debug",...n)},info(...n){r("log",...n)},warn(...n){r("warn",...n)},error(...n){r("error",...n)},critical(...t){e.error(n,...t)},createLogger:r=>c(`${n} ${r}`,t,e)}},f=n=>n(),s=r,a=function(n,t=f){return c("[Element Inference]",t,function(n=console){return{log:n.log.bind(n),warn:n.warn.bind(n),error:n.error.bind(n),debug:n.debug.bind(n)}}())}();function d(n,t){try{const e=t.get(n);if(!i(e))return e;if(n.checkVisibility){const e=n.checkVisibility({checkOpacity:!0,checkVisibilityCSS:!0});return t.set(n,e),e}const r=s.getComputedStyle(n);if("none"===r.display||"hidden"===r.visibility||0===parseFloat(r.opacity))return t.set(n,!1),!1;let o=n.parentElement;for(;o;){const n=t.get(o);if(!i(n)){if(!n)return!1;o=o.parentElement;continue}const e=s.getComputedStyle(o),r="none"!==e.display&&"hidden"!==e.visibility;if(t.set(o,r),!r)return!1;o=o.parentElement}const u=n.getBoundingClientRect(),l=u.width>0||u.height>0||n.getClientRects().length>0;return t.set(n,l),l}catch(n){return!0}}function g(n,t){const e=function(n){var t;const e=null===(t=n.innerText)||void 0===t?void 0:t.trim();return!e||e.length>250?null:e}(n);return(null==e?void 0:e.toLowerCase())===t.toLowerCase()}function*h(r,o,u){let l;try{l=function(r,o=document,u=null){return function(r,o,u,l=null){r=function(n){function t(){r&&(l.length>0&&/^[~+>]$/.test(l[l.length-1])&&l.push(" "),l.push(r))}var e,r,o,u,l=[],i=[0],c=0,f=/(?:[^\\]|(?:^|[^\\])(?:\\\\)+)$/,s=/^\s+$/,a=[/\s+|\/\*|["'>~+[(]/g,/\s+|\/\*|["'[\]()]/g,/\s+|\/\*|["'[\]()]/g,null,/\*\//g];for(n=n.trim();;){if(r="",(o=a[i[i.length-1]]).lastIndex=c,!(e=o.exec(n))){r=n.substr(c),t();break}if(u=c,(c=o.lastIndex)-e[0].length>u&&(r=n.substring(u,c-e[0].length)),3>i[i.length-1]){if(t(),"["===e[0])i.push(1);else if("("===e[0])i.push(2);else if(/^["']$/.test(e[0]))i.push(3),a[3]=new RegExp(e[0],"g");else if("/*"===e[0])i.push(4);else if(/^[\])]$/.test(e[0])&&i.length>0)i.pop();else if(/^(?:\s+|[~+>])$/.test(e[0])&&(l.length>0&&!s.test(l[l.length-1])&&0===i[i.length-1]&&l.push(" "),1===i[i.length-1]&&5===l.length&&"="===l[2].charAt(l[2].length-1)&&(l[4]=" "+l[4]),s.test(e[0])))continue;l.push(e[0])}else l[l.length-1]+=r,f.test(l[l.length-1])&&(4===i[i.length-1]&&(2>l.length||s.test(l[l.length-2])?l.pop():l[l.length-1]=" ",e[0]=""),i.pop()),l[l.length-1]+=e[0]}return l.join("").trim()}(r);let i=u.querySelector(r);return document.head.createShadowRoot||document.head.attachShadow?!o&&i?i:n(r,",").reduce((r,i)=>{if(!o&&r)return r;const c=n(i.replace(/^\s+/g,"").replace(/\s*([>+~]+)\s*/g,"$1")," ").filter(n=>!!n).map(t=>n(t,">")),f=c.length-1,s=function(n=null,t,e=null){let r=[];if(e)r=e;else{const n=function(t){for(let e=0;t.length>e;e++){const o=t[e];r.push(o),o.shadowRoot&&n(o.shadowRoot.querySelectorAll("*"))}};t.shadowRoot&&n(t.shadowRoot.querySelectorAll("*")),n(t.querySelectorAll("*"))}return n?r.filter(t=>t.matches(n)):r}(c[f][c[f].length-1],u,l),a=function(n,r,o){return u=>{let l=r,i=u,c=!1;for(;i&&!t(i);){let t=!0;if(1===n[l].length)t=i.matches(n[l]);else{const r=[].concat(n[l]).reverse();let u=i;for(const n of r){if(!u||!u.matches(n)){t=!1;break}u=e(u,o)}}if(t&&0===l){c=!0;break}t&&l--,i=e(i,o)}return c}}(c,f,u);return o?r=r.concat(s.filter(a)):(r=s.find(a))||null},o?[]:null):o?u.querySelectorAll(r):i}(r,!0,o,u)}(r)}catch(n){return}for(const n of l){const t=n;o&&!g(t,o)||d(t,u)&&(yield t)}}function v(n,t){let e=0;for(const r of n){if(e===t)return r;e++}return null}function b(n){try{const e=JSON.parse(n.autoData);if(!l(null==e?void 0:e.textGroups)||!l(null==e?void 0:e.notextGroups))return a.error("Invalid autoData structure:",e),null;const{text:r,excludeText:o,precision:u=1}=n,i=null!=r&&!o,c=(i?e.textGroups:e.notextGroups).sort((n,t)=>n.cardinality-t.cardinality);if(0===c.length)return null;const f=Math.max(1,Math.ceil((1-u)*c.length)),s=new WeakMap;for(let n=0;f>n;n++){const e=c[n],o=new Map;let u=null,l=0;for(const{css:n,offset:c}of e.cssSelectors){var t;const f=v(h(n,i?r:null,s),c);if(!f)continue;const a=(null!==(t=o.get(f))&&void 0!==t?t:0)+1;if(o.set(f,a),a>l&&(l=a,u=f,a>=Math.ceil(e.cssSelectors.length/2)))return u}if(u)return u}return null}catch(n){return a.error("Error finding element:",n),null}}function w(n,t=4){if(!n)return null;const e=[];let r=n;for(;r&&t>e.length&&"BODY"!==r.tagName;){let n=r.tagName.toLowerCase();r.id?n+=`#${r.id}`:r.classList.length&&(n+=`.${r.classList[0]}`),e.unshift(n),r=r.parentElement}return e.join(" > ")}export{d as elementIsVisible,b as findElement,w as getElementPath}; //# sourceMappingURL=element-inference.js.map