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