@analytickit/simmerjs
Version:
A pure Javascript reverse CSS selector engine which calculates a DOM element's unique CSS selector on the current page.
74 lines (73 loc) • 32.5 kB
JavaScript
;function normalizeSelector(a){function b(){l&&(0<c.length&&/^[~+>]$/.test(c[c.length-1])&&c.push(" "),c.push(l))}var c=[],e,d=[0],g=0,h=/(?:[^\\]|(?:^|[^\\])(?:\\\\)+)$/,p=/^\s+$/,v=[/\s+|\/\*|["'>~+[(]/g,/\s+|\/\*|["'[\]()]/g,/\s+|\/\*|["'[\]()]/g,null,/\*\//g];for(a=a.trim();;){var l="";var n=v[d[d.length-1]];n.lastIndex=g;if(e=n.exec(a)){var t=g;g=n.lastIndex;t<g-e[0].length&&(l=a.substring(t,g-e[0].length));if(3>d[d.length-1]){b();if("["===e[0])d.push(1);else if("("===e[0])d.push(2);
else if(/^["']$/.test(e[0]))d.push(3),v[3]=new RegExp(e[0],"g");else if("/*"===e[0])d.push(4);else if(/^[\])]$/.test(e[0])&&0<d.length)d.pop();else if(/^(?:\s+|[~+>])$/.test(e[0])&&(0<c.length&&!p.test(c[c.length-1])&&0===d[d.length-1]&&c.push(" "),1===d[d.length-1]&&5===c.length&&"="===c[2].charAt(c[2].length-1)&&(c[4]=" "+c[4]),p.test(e[0])))continue;c.push(e[0])}else c[c.length-1]+=l,h.test(c[c.length-1])&&(4===d[d.length-1]&&(2>c.length||p.test(c[c.length-2])?c.pop():c[c.length-1]=" ",e[0]=""),
d.pop()),c[c.length-1]+=e[0]}else{l=a.substr(g);b();break}}return c.join("").trim()}function querySelectorAllDeep(a){return _querySelectorDeep(a,!0,1<arguments.length&&void 0!==arguments[1]?arguments[1]:document,2<arguments.length&&void 0!==arguments[2]?arguments[2]:null)}
function _querySelectorDeep(a,b,c){let e=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null;a=normalizeSelector(a);let d=c.querySelector(a);return document.head.createShadowRoot||document.head.attachShadow?!b&&d?d:splitByCharacterUnlessQuoted(a,",").reduce((a,d)=>{if(!b&&a)return a;var g=splitByCharacterUnlessQuoted(d.replace(/^\s+/g,"").replace(/\s*([>+~]+)\s*/g,"$1")," ").filter(a=>!!a).map(a=>splitByCharacterUnlessQuoted(a,">"));let h=g.length-1;d=collectAllElementsDeep(g[h][g[h].length-
1],c,e);g=findMatchingElement(g,h,c);return b?a=a.concat(d.filter(g)):(a=d.find(g))||null},b?[]:null):b?c.querySelectorAll(a):d}function findMatchingElement(a,b,c){return e=>{let d=b,g=!1;for(;e&&!isDocumentNode(e);){let b=!0;if(1===a[d].length)b=e.matches(a[d]);else{let g=[].concat(a[d]).reverse(),h=e;for(let a of g){if(!h||!h.matches(a)){b=!1;break}h=findParentOrHost(h,c)}}if(b&&0===d){g=!0;break}b&&d--;e=findParentOrHost(e,c)}return g}}
function splitByCharacterUnlessQuoted(a,b){return a.match(/\\?.|^$/g).reduce((a,e)=>{'"'!==e||a.sQuote?"'"!==e||a.quote?a.quote||a.sQuote||e!==b?a.a[a.a.length-1]+=e:a.a.push(""):(a.sQuote^=1,a.a[a.a.length-1]+=e):(a.quote^=1,a.a[a.a.length-1]+=e);return a},{a:[""]}).a}function isDocumentNode(a){return a.nodeType===Node.DOCUMENT_FRAGMENT_NODE||a.nodeType===Node.DOCUMENT_NODE}function findParentOrHost(a,b){return(a=a.parentNode)&&a.host&&11===a.nodeType?a.host:a===b?null:a}
function collectAllElementsDeep(){let a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null,b=1<arguments.length?arguments[1]:void 0,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,e=[];if(c)e=c;else{let a=function(b){for(let c=0;c<b.length;c++){const d=b[c];e.push(d);d.shadowRoot&&a(d.shadowRoot.querySelectorAll("*"))}};b.shadowRoot&&a(b.shadowRoot.querySelectorAll("*"));a(b.querySelectorAll("*"))}return a?e.filter(b=>b.matches(a)):e}
function isUniqueElementID(a,b){return 1===(a(`[id="${b}"]`)||[]).length}function isUniqueDataAttr(a,b,c){return 1===(a(`[${b}="${c}"]`)||[]).length}function traverseAttribute(a,b){let c=[];for(a=a[b];a&&9!==a.nodeType;)1===a.nodeType&&c.push(wrap(a)),a=a[b];return c}
function wrap(a){return{el:a,getClass:function(){return this.el.getAttribute("class")||""},getClasses:function(){return this.getClass().split(" ").map(a=>a.replace(/^\s\s*/,"").replace(/\s\s*$/,"")).filter(a=>0<a.length)},prevAll:function(){return traverseAttribute(this.el,"previousSibling")},nextAll:function(){return traverseAttribute(this.el,"nextSibling")},parent:function(){return this.el.parentNode?11===this.el.parentNode.nodeType?wrap(this.el.parentNode.host):wrap(this.el.parentNode):null}}}
let INVALID_DOCUMENT={querySelectorAll(){throw Error("An invalid context has been provided to Simmer, it doesnt know how to query it");}},documentQuerySelector=a=>{const b="function"===typeof a.querySelectorAll?a:a.document?a.document:INVALID_DOCUMENT;return(a,e)=>{try{return querySelectorAllDeep(a,b)}catch(d){e(d)}}};function initQueryEngine(a,b){let c="function"===typeof b?b:documentQuerySelector(a);return(b,d)=>"string"!==typeof b?[]:c(b,d,a)}
function tagName(a){return"string"===typeof a&&null!==a.match(/^[a-zA-Z0-9-]+$/gi)?a:!1}function attr(a){return"string"===typeof a&&null!==a.match(/^[0-9a-zA-Z][a-zA-Z_\-:0-9.]*$/gi)?a:!1}function className(a){return"string"===typeof a&&null!==a.match(/^\.?[a-zA-Z_\-:0-9]*$/gi)?a:!1}function escapeClassName(a){return a.replace(/([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g,function(a,c){return c?"\x00"===a?"\ufffd":a.slice(0,-1)+"\\"+a.charCodeAt(a.length-1).toString(16)+" ":"\\"+a})}
function inspectDataAttributes(a,b,c,e,d){return a.reduce((a,b,p)=>{if(!a.verified){var g=Array.from(b.el.attributes).map(a=>a.name).filter(a=>"id"!==a&&"class"!==a);let h=new Set;for(let a of e.dataAttributes){let b=a.replace(/[.+?^${}()|[\]\\]/g,"").replace(/\*/g,".*");for(let a of g)(new RegExp(`^${b}$`)).test(a)&&h.add(a)}[g]=Array.from(h).map(a=>[a,b.el.getAttribute(a)]).filter(a=>{let [b,c]=a;return attr(c)||b.match(/^data-/)}).map(b=>{let [g,h]=b;b=isUniqueDataAttr(d,g,h);a.stack[p].push(""===
h?`[${g}]`:`[${g}='${h}']`);a.specificity+=b?100:50;a.specificity>=e.specificityThreshold&&c(a)&&(a.verified=!0);a.verified||0!==p||(a.stack[p].pop(),a.specificity-=b?100:50);return a});return g||a}return a},b)}
function inspectElementID(a,b,c,e,d){return a.reduce((a,b,p)=>a.verified?a:([b]=[b.el.getAttribute("id")].filter(a=>attr(a)).filter(a=>isUniqueElementID(d,a)).map(b=>{a.stack[p].push(`[id='${b}']`);a.specificity+=100;a.specificity>=e.specificityThreshold&&c(a)&&(a.verified=!0);a.verified||0!==p||(a.stack[p].pop(),a.specificity-=100);return a}),b||a),b)}
function inspectTags(a,b){return a.reduce((a,b,d)=>{[b.el.nodeName].filter(tagName).forEach(b=>{a.stack[d].splice(0,0,b);b.includes("-")?a.specificity+=30:a.specificity+=10});return a},b)}var INFINITY$1=1/0,MAX_INTEGER$1=1.7976931348623157E308,NAN$1=0/0,symbolTag$1="[object Symbol]",reTrim$1=/^\s+|\s+$/g,reIsBadHex$1=/^[-+]0x[0-9a-f]+$/i,reIsBinary$1=/^0b[01]+$/i,reIsOctal$1=/^0o[0-7]+$/i,freeParseInt$1=parseInt,objectProto$2=Object.prototype,objectToString$2=objectProto$2.toString;
function baseSlice$1(a,b,c){var e=-1,d=a.length;0>b&&(b=-b>d?0:d+b);c=c>d?d:c;0>c&&(c+=d);d=b>c?0:c-b>>>0;b>>>=0;for(c=Array(d);++e<d;)c[e]=a[e+b];return c}function take(a,b,c){if(!a||!a.length)return[];b=c||void 0===b?1:toInteger$1(b);return baseSlice$1(a,0,0>b?0:b)}function isObject$2(a){var b=typeof a;return!!a&&("object"==b||"function"==b)}function isObjectLike$2(a){return!!a&&"object"==typeof a}
function isSymbol$1(a){return"symbol"==typeof a||isObjectLike$2(a)&&objectToString$2.call(a)==symbolTag$1}function toFinite$1(a){if(!a)return 0===a?a:0;a=toNumber$1(a);return a===INFINITY$1||a===-INFINITY$1?(0>a?-1:1)*MAX_INTEGER$1:a===a?a:0}function toInteger$1(a){a=toFinite$1(a);var b=a%1;return a===a?b?a-b:a:0}
function toNumber$1(a){if("number"==typeof a)return a;if(isSymbol$1(a))return NAN$1;isObject$2(a)&&(a="function"==typeof a.valueOf?a.valueOf():a,a=isObject$2(a)?a+"":a);if("string"!=typeof a)return 0===a?a:+a;a=a.replace(reTrim$1,"");var b=reIsBinary$1.test(a);return b||reIsOctal$1.test(a)?freeParseInt$1(a.slice(2),b?2:8):reIsBadHex$1.test(a)?NAN$1:+a}var lodash_take=take;
function inspectSiblings(a,b){return a.reduce((a,b,d)=>{b=lodash_take(b.getClasses(),10).filter(className).map(a=>`.${escapeClassName(a)}`);b.length&&(a.stack[d].push(b.join("")),a.specificity+=10*b.length);return a},b)}var commonjsGlobal="undefined"!==typeof globalThis?globalThis:"undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:{};
function createCommonjsModule(a,b,c){return c={path:b,exports:{},require:function(a,b){return commonjsRequire(a,void 0===b||null===b?c.path:b)}},a(c,c.exports),c.exports}function commonjsRequire(){throw Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs");}
var LARGE_ARRAY_SIZE=200,HASH_UNDEFINED="__lodash_hash_undefined__",MAX_SAFE_INTEGER=9007199254740991,argsTag="[object Arguments]",funcTag="[object Function]",genTag="[object GeneratorFunction]",reRegExpChar=/[\\^$.*+?()[\]{}|]/g,reIsHostCtor=/^\[object .+?Constructor\]$/,freeGlobal="object"==typeof commonjsGlobal&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,freeSelf="object"==typeof self&&self&&self.Object===Object&&self,root=freeGlobal||freeSelf||Function("return this")();
function apply(a,b,c){switch(c.length){case 0:return a.call(b);case 1:return a.call(b,c[0]);case 2:return a.call(b,c[0],c[1]);case 3:return a.call(b,c[0],c[1],c[2])}return a.apply(b,c)}function arrayIncludes(a,b){return!(!a||!a.length)&&-1<baseIndexOf(a,b,0)}function arrayIncludesWith(a,b,c){for(var e=-1,d=a?a.length:0;++e<d;)if(c(b,a[e]))return!0;return!1}function arrayMap(a,b){for(var c=-1,e=a?a.length:0,d=Array(e);++c<e;)d[c]=b(a[c],c,a);return d}
function arrayPush(a,b){for(var c=-1,e=b.length,d=a.length;++c<e;)a[d+c]=b[c];return a}function baseFindIndex(a,b,c,e){var d=a.length;for(c+=e?1:-1;e?c--:++c<d;)if(b(a[c],c,a))return c;return-1}function baseIndexOf(a,b,c){if(b!==b)return baseFindIndex(a,baseIsNaN,c);--c;for(var e=a.length;++c<e;)if(a[c]===b)return c;return-1}function baseIsNaN(a){return a!==a}function baseUnary(a){return function(b){return a(b)}}function cacheHas(a,b){return a.has(b)}
function getValue(a,b){return null==a?void 0:a[b]}function isHostObject(a){var b=!1;if(null!=a&&"function"!=typeof a.toString)try{b=!!(a+"")}catch(c){}return b}
var arrayProto=Array.prototype,funcProto=Function.prototype,objectProto$1=Object.prototype,coreJsData=root["__core-js_shared__"],maskSrcKey=function(){var a=/[^.]+$/.exec(coreJsData&&coreJsData.keys&&coreJsData.keys.IE_PROTO||"");return a?"Symbol(src)_1."+a:""}(),funcToString=funcProto.toString,hasOwnProperty=objectProto$1.hasOwnProperty,objectToString$1=objectProto$1.toString,reIsNative=RegExp("^"+funcToString.call(hasOwnProperty).replace(reRegExpChar,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,
"$1.*?")+"$"),Symbol=root.Symbol,propertyIsEnumerable=objectProto$1.propertyIsEnumerable,splice=arrayProto.splice,spreadableSymbol=Symbol?Symbol.isConcatSpreadable:void 0,nativeMax=Math.max,Map=getNative(root,"Map"),nativeCreate=getNative(Object,"create");function Hash(a){var b=-1,c=a?a.length:0;for(this.clear();++b<c;){var e=a[b];this.set(e[0],e[1])}}function hashClear(){this.__data__=nativeCreate?nativeCreate(null):{}}function hashDelete(a){return this.has(a)&&delete this.__data__[a]}
function hashGet(a){var b=this.__data__;return nativeCreate?(a=b[a],a===HASH_UNDEFINED?void 0:a):hasOwnProperty.call(b,a)?b[a]:void 0}function hashHas(a){var b=this.__data__;return nativeCreate?void 0!==b[a]:hasOwnProperty.call(b,a)}function hashSet(a,b){this.__data__[a]=nativeCreate&&void 0===b?HASH_UNDEFINED:b;return this}Hash.prototype.clear=hashClear;Hash.prototype["delete"]=hashDelete;Hash.prototype.get=hashGet;Hash.prototype.has=hashHas;Hash.prototype.set=hashSet;
function ListCache(a){var b=-1,c=a?a.length:0;for(this.clear();++b<c;){var e=a[b];this.set(e[0],e[1])}}function listCacheClear(){this.__data__=[]}function listCacheDelete(a){var b=this.__data__;a=assocIndexOf(b,a);if(0>a)return!1;a==b.length-1?b.pop():splice.call(b,a,1);return!0}function listCacheGet(a){var b=this.__data__;a=assocIndexOf(b,a);return 0>a?void 0:b[a][1]}function listCacheHas(a){return-1<assocIndexOf(this.__data__,a)}
function listCacheSet(a,b){var c=this.__data__,e=assocIndexOf(c,a);0>e?c.push([a,b]):c[e][1]=b;return this}ListCache.prototype.clear=listCacheClear;ListCache.prototype["delete"]=listCacheDelete;ListCache.prototype.get=listCacheGet;ListCache.prototype.has=listCacheHas;ListCache.prototype.set=listCacheSet;function MapCache(a){var b=-1,c=a?a.length:0;for(this.clear();++b<c;){var e=a[b];this.set(e[0],e[1])}}
function mapCacheClear(){this.__data__={hash:new Hash,map:new (Map||ListCache),string:new Hash}}function mapCacheDelete(a){return getMapData(this,a)["delete"](a)}function mapCacheGet(a){return getMapData(this,a).get(a)}function mapCacheHas(a){return getMapData(this,a).has(a)}function mapCacheSet(a,b){getMapData(this,a).set(a,b);return this}MapCache.prototype.clear=mapCacheClear;MapCache.prototype["delete"]=mapCacheDelete;MapCache.prototype.get=mapCacheGet;MapCache.prototype.has=mapCacheHas;
MapCache.prototype.set=mapCacheSet;function SetCache(a){var b=-1,c=a?a.length:0;for(this.__data__=new MapCache;++b<c;)this.add(a[b])}function setCacheAdd(a){this.__data__.set(a,HASH_UNDEFINED);return this}function setCacheHas(a){return this.__data__.has(a)}SetCache.prototype.add=SetCache.prototype.push=setCacheAdd;SetCache.prototype.has=setCacheHas;function assocIndexOf(a,b){for(var c=a.length;c--;)if(eq(a[c][0],b))return c;return-1}
function baseDifference(a,b,c,e){var d=-1,g=arrayIncludes,h=!0,p=a.length,v=[],l=b.length;if(!p)return v;c&&(b=arrayMap(b,baseUnary(c)));e?(g=arrayIncludesWith,h=!1):b.length>=LARGE_ARRAY_SIZE&&(g=cacheHas,h=!1,b=new SetCache(b));a:for(;++d<p;){var n=a[d],t=c?c(n):n;n=e||0!==n?n:0;if(h&&t===t){for(var B=l;B--;)if(b[B]===t)continue a;v.push(n)}else g(b,t,e)||v.push(n)}return v}
function baseFlatten(a,b,c,e,d){var g=-1,h=a.length;c||(c=isFlattenable);for(d||(d=[]);++g<h;){var p=a[g];0<b&&c(p)?1<b?baseFlatten(p,b-1,c,e,d):arrayPush(d,p):e||(d[d.length]=p)}return d}function baseIsNative(a){return!isObject$1(a)||isMasked(a)?!1:(isFunction(a)||isHostObject(a)?reIsNative:reIsHostCtor).test(toSource(a))}
function baseRest(a,b){b=nativeMax(void 0===b?a.length-1:b,0);return function(){for(var c=arguments,e=-1,d=nativeMax(c.length-b,0),g=Array(d);++e<d;)g[e]=c[b+e];e=-1;for(d=Array(b+1);++e<b;)d[e]=c[e];d[b]=g;return apply(a,this,d)}}function getMapData(a,b){a=a.__data__;return isKeyable(b)?a["string"==typeof b?"string":"hash"]:a.map}function getNative(a,b){a=getValue(a,b);return baseIsNative(a)?a:void 0}
function isFlattenable(a){return isArray(a)||isArguments(a)||!!(spreadableSymbol&&a&&a[spreadableSymbol])}function isKeyable(a){var b=typeof a;return"string"==b||"number"==b||"symbol"==b||"boolean"==b?"__proto__"!==a:null===a}function isMasked(a){return!!maskSrcKey&&maskSrcKey in a}function toSource(a){if(null!=a){try{return funcToString.call(a)}catch(b){}return a+""}return""}
var difference=baseRest(function(a,b){return isArrayLikeObject(a)?baseDifference(a,baseFlatten(b,1,isArrayLikeObject,!0)):[]});function eq(a,b){return a===b||a!==a&&b!==b}function isArguments(a){return isArrayLikeObject(a)&&hasOwnProperty.call(a,"callee")&&(!propertyIsEnumerable.call(a,"callee")||objectToString$1.call(a)==argsTag)}var isArray=Array.isArray;function isArrayLike(a){return null!=a&&isLength(a.length)&&!isFunction(a)}
function isArrayLikeObject(a){return isObjectLike$1(a)&&isArrayLike(a)}function isFunction(a){a=isObject$1(a)?objectToString$1.call(a):"";return a==funcTag||a==genTag}function isLength(a){return"number"==typeof a&&-1<a&&0==a%1&&a<=MAX_SAFE_INTEGER}function isObject$1(a){var b=typeof a;return!!a&&("object"==b||"function"==b)}function isObjectLike$1(a){return!!a&&"object"==typeof a}
var lodash_difference=difference,lodash_flatmap=createCommonjsModule(function(a,b){function c(a,b){for(var f=-1,m=a?a.length:0,c=Array(m);++f<m;)c[f]=b(a[f],f,a);return c}function e(a,b){for(var f=-1,m=a?a.length:0;++f<m;)if(b(a[f],f,a))return!0;return!1}function d(a){return function(f){return null==f?void 0:f[a]}}function g(a){return function(f){return a(f)}}function h(a){var f=!1;if(null!=a&&"function"!=typeof a.toString)try{f=!!(a+"")}catch(k){}return f}function p(a){var f=-1,b=Array(a.size);a.forEach(function(a,
m){b[++f]=[m,a]});return b}function v(a){var f=-1,b=Array(a.size);a.forEach(function(a){b[++f]=a});return b}function l(a){var f=-1,b=a?a.length:0;for(this.clear();++f<b;){var c=a[f];this.set(c[0],c[1])}}function n(a){var f=-1,b=a?a.length:0;for(this.clear();++f<b;){var c=a[f];this.set(c[0],c[1])}}function t(a){var f=-1,b=a?a.length:0;for(this.clear();++f<b;){var c=a[f];this.set(c[0],c[1])}}function B(a){var f=-1,b=a?a.length:0;for(this.__data__=new t;++f<b;)this.add(a[f])}function w(a){this.__data__=
new n(a)}function J(a,b){for(var f=a.length;f--;)if(ea(a[f][0],b))return f;return-1}function fa(a,b,c,e,d){var f=-1,m=a.length;c||(c=ya);for(d||(d=[]);++f<m;){var k=a[f];if(0<b&&c(k))if(1<b)fa(k,b-1,c,e,d);else for(var q=d,u=-1,h=k.length,g=q.length;++u<h;)q[g+u]=k[u];else e||(d[d.length]=k)}return d}function ha(a,b){b=K(b,a)?[b]:ia(b);for(var f=0,m=b.length;null!=a&&f<m;)a=a[L(b[f++])];return f&&f==m?a:void 0}function D(a,b,c,e,d){if(a===b)return!0;if(null==a||null==b||!G(a)&&!M(b))return a!==a&&
b!==b;a:{var f=x(a),m=x(b),k="[object Array]",q="[object Array]";f||(k=z(a),k="[object Arguments]"==k?"[object Object]":k);m||(q=z(b),q="[object Arguments]"==q?"[object Object]":q);var g="[object Object]"==k&&!h(a);m="[object Object]"==q&&!h(b);if((q=k==q)&&!g)d||(d=new w),b=f||za(a)?ja(a,b,D,c,e,d):Aa(a,b,k,D,c,e,d);else{if(!(e&2)&&(f=g&&y.call(a,"__wrapped__"),k=m&&y.call(b,"__wrapped__"),f||k)){a=f?a.value():a;b=k?b.value():b;d||(d=new w);b=D(a,b,c,e,d);break a}if(q)b:if(d||(d=new w),f=e&2,k=N(a),
m=k.length,q=N(b).length,m==q||f){for(g=m;g--;){var u=k[g];if(!(f?u in b:y.call(b,u))){b=!1;break b}}if((q=d.get(a))&&d.get(b))b=q==b;else{q=!0;d.set(a,b);d.set(b,a);for(var p=f;++g<m;){u=k[g];var l=a[u],n=b[u];if(c)var r=f?c(n,l,u,b,a,d):c(l,n,u,a,b,d);if(void 0===r?l!==n&&!D(l,n,c,e,d):!r){q=!1;break}p||(p="constructor"==u)}q&&!p&&(c=a.constructor,e=b.constructor,c!=e&&"constructor"in a&&"constructor"in b&&!("function"==typeof c&&c instanceof c&&"function"==typeof e&&e instanceof e)&&(q=!1));d["delete"](a);
d["delete"](b);b=q}}else b=!1;else b=!1}}return b}function Ba(a,b,c,e){var f=c.length,m=f,d=!e;if(null==a)return!m;for(a=Object(a);f--;){var k=c[f];if(d&&k[2]?k[1]!==a[k[0]]:!(k[0]in a))return!1}for(;++f<m;){k=c[f];var q=k[0],g=a[q],h=k[1];if(d&&k[2]){if(void 0===g&&!(q in a))return!1}else{k=new w;if(e)var p=e(g,h,q,a,b,k);if(void 0===p?!D(h,g,e,3,k):!p)return!1}}return!0}function Ca(a){return M(a)&&T(a.length)&&!!r[E.call(a)]}function Da(a,b){var f=-1,c=O(a)?Array(a.length):[];Ea(a,function(a,m,
e){c[++f]=b(a,m,e)});return c}function Fa(a){var b=Ga(a);return 1==b.length&&b[0][2]?ka(b[0][0],b[0][1]):function(f){return f===a||Ba(f,a,b)}}function Ha(a,b){return K(a)&&b===b&&!G(b)?ka(L(a),b):function(f){var c=null==f?void 0:ha(f,a);c=void 0===c?void 0:c;var m;if(void 0===c&&c===b){if(c=null!=f){c=a;c=K(c,f)?[c]:ia(c);for(var e=-1,d=c.length;++e<d;){var k=L(c[e]);if(!(m=null!=f&&null!=f&&k in Object(f)))break;f=f[k]}m?c=m:(d=f?f.length:0,c=!!d&&T(d)&&la(k,d)&&(x(f)||U(f)))}m=c}else m=D(b,c,void 0,
3);return m}}function Ia(a){return function(b){return ha(b,a)}}function Ja(a){if("string"==typeof a)return a;if(V(a))return ma?ma.call(a):"";var b=a+"";return"0"==b&&1/a==-na?"-0":b}function ia(a){return x(a)?a:Ka(a)}function ja(a,b,c,d,g,h){var f=g&2,m=a.length,k=b.length;if(m!=k&&!(f&&k>m))return!1;if((k=h.get(a))&&h.get(b))return k==b;k=-1;var q=!0,p=g&1?new B:void 0;h.set(a,b);for(h.set(b,a);++k<m;){var l=a[k],u=b[k];if(d)var n=f?d(u,l,k,b,a,h):d(l,u,k,a,b,h);if(void 0!==n){if(n)continue;q=!1;
break}if(p){if(!e(b,function(a,b){if(!p.has(b)&&(l===a||c(l,a,d,g,h)))return p.add(b)})){q=!1;break}}else if(l!==u&&!c(l,u,d,g,h)){q=!1;break}}h["delete"](a);h["delete"](b);return q}function Aa(a,b,c,e,d,h,g){switch(c){case "[object DataView]":if(a.byteLength!=b.byteLength||a.byteOffset!=b.byteOffset)break;a=a.buffer;b=b.buffer;case "[object ArrayBuffer]":if(a.byteLength!=b.byteLength||!e(new oa(a),new oa(b)))break;return!0;case "[object Boolean]":case "[object Date]":case "[object Number]":return ea(+a,
+b);case "[object Error]":return a.name==b.name&&a.message==b.message;case "[object RegExp]":case "[object String]":return a==b+"";case "[object Map]":var f=p;case "[object Set]":f||(f=v);if(a.size!=b.size&&!(h&2))break;if(c=g.get(a))return c==b;h|=1;g.set(a,b);b=ja(f(a),f(b),e,d,h,g);g["delete"](a);return b;case "[object Symbol]":if(W)return W.call(a)==W.call(b)}return!1}function P(a,b){a=a.__data__;var f=typeof b;return("string"==f||"number"==f||"symbol"==f||"boolean"==f?"__proto__"!==b:null===
b)?a["string"==typeof b?"string":"hash"]:a.map}function Ga(a){for(var b=N(a),f=b.length;f--;){var c=b[f],e=a[c];b[f]=[c,e,e===e&&!G(e)]}return b}function F(a,b){a=null==a?void 0:a[b];b=!G(a)||pa&&pa in a?!1:(qa(a)||h(a)?La:Ma).test(C(a));return b?a:void 0}function ya(a){return x(a)||U(a)||!!(ra&&a&&a[ra])}function la(a,b){b=null==b?9007199254740991:b;return!!b&&("number"==typeof a||Na.test(a))&&-1<a&&0==a%1&&a<b}function K(a,b){if(x(a))return!1;var f=typeof a;return"number"==f||"symbol"==f||"boolean"==
f||null==a||V(a)?!0:Oa.test(a)||!Pa.test(a)||null!=b&&a in Object(b)}function ka(a,b){return function(f){return null==f?!1:f[a]===b&&(void 0!==b||a in Object(f))}}function L(a){if("string"==typeof a||V(a))return a;var b=a+"";return"0"==b&&1/a==-na?"-0":b}function C(a){if(null!=a){try{return sa.call(a)}catch(m){}return a+""}return""}function X(a,b){if("function"!=typeof a||b&&"function"!=typeof b)throw new TypeError("Expected a function");var f=function(){var c=arguments,e=b?b.apply(this,c):c[0],d=
f.cache;if(d.has(e))return d.get(e);c=a.apply(this,c);f.cache=d.set(e,c);return c};f.cache=new (X.Cache||t);return f}function ea(a,b){return a===b||a!==a&&b!==b}function U(a){return M(a)&&O(a)&&y.call(a,"callee")&&(!Qa.call(a,"callee")||"[object Arguments]"==E.call(a))}function O(a){return null!=a&&T(a.length)&&!qa(a)}function qa(a){a=G(a)?E.call(a):"";return"[object Function]"==a||"[object GeneratorFunction]"==a}function T(a){return"number"==typeof a&&-1<a&&0==a%1&&9007199254740991>=a}function G(a){var b=
typeof a;return!!a&&("object"==b||"function"==b)}function M(a){return!!a&&"object"==typeof a}function V(a){return"symbol"==typeof a||M(a)&&"[object Symbol]"==E.call(a)}function N(a){if(O(a)){if(x(a)||U(a)){var b=a.length;for(var c=String,f=-1,e=Array(b);++f<b;)e[f]=c(f);b=e}else b=[];c=b.length;f=!!c;for(var d in a)!y.call(a,d)||f&&("length"==d||la(d,c))||b.push(d);a=b}else if(d=a&&a.constructor,a===("function"==typeof d&&d.prototype||Q)){d=[];for(b in Object(a))y.call(a,b)&&"constructor"!=b&&d.push(b);
a=d}else a=Ra(a);return a}function Sa(a){return a}var na=1/0,Pa=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Oa=/^\w*$/,Ta=/^\./,Ua=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Va=/\\(\\)?/g,Ma=/^\[object .+?Constructor\]$/,Na=/^(?:0|[1-9]\d*)$/,r={};r["[object Float32Array]"]=r["[object Float64Array]"]=r["[object Int8Array]"]=r["[object Int16Array]"]=r["[object Int32Array]"]=r["[object Uint8Array]"]=r["[object Uint8ClampedArray]"]=r["[object Uint16Array]"]=
r["[object Uint32Array]"]=!0;r["[object Arguments]"]=r["[object Array]"]=r["[object ArrayBuffer]"]=r["[object Boolean]"]=r["[object DataView]"]=r["[object Date]"]=r["[object Error]"]=r["[object Function]"]=r["[object Map]"]=r["[object Number]"]=r["[object Object]"]=r["[object RegExp]"]=r["[object Set]"]=r["[object String]"]=r["[object WeakMap]"]=!1;var ta="object"==typeof commonjsGlobal&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,Wa="object"==typeof self&&self&&self.Object===Object&&
self,A=ta||Wa||Function("return this")(),ua=b&&!b.nodeType&&b,va=ua&&a&&!a.nodeType&&a,wa=va&&va.exports===ua&&ta.process;a:{try{var Y=wa&&wa.binding("util");break a}catch(f){}Y=void 0}var xa=Y&&Y.isTypedArray,Xa=Array.prototype,Ya=Function.prototype,Q=Object.prototype,Z=A["__core-js_shared__"],pa=function(){var a=/[^.]+$/.exec(Z&&Z.keys&&Z.keys.IE_PROTO||"");return a?"Symbol(src)_1."+a:""}(),sa=Ya.toString,y=Q.hasOwnProperty,E=Q.toString,La=RegExp("^"+sa.call(y).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,
"$1.*?")+"$"),R=A.Symbol,oa=A.Uint8Array,Qa=Q.propertyIsEnumerable,Za=Xa.splice,ra=R?R.isConcatSpreadable:void 0,Ra=function(a,b){return function(c){return a(b(c))}}(Object.keys,Object),aa=F(A,"DataView"),H=F(A,"Map"),ba=F(A,"Promise"),ca=F(A,"Set"),da=F(A,"WeakMap"),I=F(Object,"create"),$a=C(aa),ab=C(H),bb=C(ba),cb=C(ca),db=C(da),S=R?R.prototype:void 0,W=S?S.valueOf:void 0,ma=S?S.toString:void 0;l.prototype.clear=function(){this.__data__=I?I(null):{}};l.prototype["delete"]=function(a){return this.has(a)&&
delete this.__data__[a]};l.prototype.get=function(a){var b=this.__data__;return I?(a=b[a],"__lodash_hash_undefined__"===a?void 0:a):y.call(b,a)?b[a]:void 0};l.prototype.has=function(a){var b=this.__data__;return I?void 0!==b[a]:y.call(b,a)};l.prototype.set=function(a,b){this.__data__[a]=I&&void 0===b?"__lodash_hash_undefined__":b;return this};n.prototype.clear=function(){this.__data__=[]};n.prototype["delete"]=function(a){var b=this.__data__;a=J(b,a);if(0>a)return!1;a==b.length-1?b.pop():Za.call(b,
a,1);return!0};n.prototype.get=function(a){var b=this.__data__;a=J(b,a);return 0>a?void 0:b[a][1]};n.prototype.has=function(a){return-1<J(this.__data__,a)};n.prototype.set=function(a,b){var c=this.__data__,f=J(c,a);0>f?c.push([a,b]):c[f][1]=b;return this};t.prototype.clear=function(){this.__data__={hash:new l,map:new (H||n),string:new l}};t.prototype["delete"]=function(a){return P(this,a)["delete"](a)};t.prototype.get=function(a){return P(this,a).get(a)};t.prototype.has=function(a){return P(this,
a).has(a)};t.prototype.set=function(a,b){P(this,a).set(a,b);return this};B.prototype.add=B.prototype.push=function(a){this.__data__.set(a,"__lodash_hash_undefined__");return this};B.prototype.has=function(a){return this.__data__.has(a)};w.prototype.clear=function(){this.__data__=new n};w.prototype["delete"]=function(a){return this.__data__["delete"](a)};w.prototype.get=function(a){return this.__data__.get(a)};w.prototype.has=function(a){return this.__data__.has(a)};w.prototype.set=function(a,b){var c=
this.__data__;if(c instanceof n){c=c.__data__;if(!H||199>c.length)return c.push([a,b]),this;c=this.__data__=new t(c)}c.set(a,b);return this};var Ea=function(a,b){return function(c,d){if(null==c)return c;if(!O(c))return a(c,d);for(var e=c.length,f=b?e:-1,h=Object(c);(b?f--:++f<e)&&!1!==d(h[f],f,h););return c}}(function(a,b){return a&&eb(a,b,N)}),eb=function(a){return function(b,c,d){var e=-1,f=Object(b);d=d(b);for(var h=d.length;h--;){var g=d[a?h:++e];if(!1===c(f[g],g,f))break}return b}}(),z=function(a){return E.call(a)};
if(aa&&"[object DataView]"!=z(new aa(new ArrayBuffer(1)))||H&&"[object Map]"!=z(new H)||ba&&"[object Promise]"!=z(ba.resolve())||ca&&"[object Set]"!=z(new ca)||da&&"[object WeakMap]"!=z(new da))z=function(a){var b=E.call(a);if(a=(a="[object Object]"==b?a.constructor:void 0)?C(a):void 0)switch(a){case $a:return"[object DataView]";case ab:return"[object Map]";case bb:return"[object Promise]";case cb:return"[object Set]";case db:return"[object WeakMap]"}return b};var Ka=X(function(a){a=null==a?"":Ja(a);
var b=[];Ta.test(a)&&b.push("");a.replace(Ua,function(a,c,d,e){b.push(d?e.replace(Va,"$1"):c||a)});return b});X.Cache=t;var x=Array.isArray,za=xa?g(xa):Ca;a.exports=function(a,b){var e=x(a)?c:Da;b="function"==typeof b?b:null==b?Sa:"object"==typeof b?x(b)?Ha(b[0],b[1]):Fa(b):K(b)?d(L(b)):Ia(b);a=e(a,b);return fa(a,1)}});let not=a=>!a,getNodeNames=a=>a.map(a=>a.el.nodeName);
function analyzeElementSiblings(a,b){return 0<lodash_difference(a.getClasses(),lodash_flatmap(b,a=>a.getClasses())).length||not(getNodeNames(b).includes(a.el.nodeName))}function inspectNthChild(a,b,c){return a.reduce((a,b,g)=>{if(!a.verified){let d=b.prevAll(),e=b.nextAll(),v=d.length+1;!d.length&&!e.length||analyzeElementSiblings(b,[...d,...e])||(a.stack[g].push(`:nth-child(${v})`),a.verified=c(a))}return a},b)}
let handlers={IMG:(a,b)=>{if(b=b.el.getAttribute("src"))a.stack[0].push(`[src="${b}"]`),a.specificity+=10;return a}};function inspectSpecialAttributes(a,b,c){a=a[0];let e=a.el.nodeName;handlers[e]&&(b=handlers[e](b,a),c(b)?b.verified=!0:b.stack[0].pop());return b}let parsingMethods={methods:[],getMethods:function(){return this.methods.slice(0)},addMethod:function(a){this.methods.push(a)}};parsingMethods.addMethod(inspectDataAttributes);parsingMethods.addMethod(inspectElementID);parsingMethods.addMethod(inspectTags);
parsingMethods.addMethod(inspectSpecialAttributes);parsingMethods.addMethod(inspectSiblings);parsingMethods.addMethod(inspectNthChild);var INFINITY=1/0,MAX_INTEGER=1.7976931348623157E308,NAN=0/0,symbolTag="[object Symbol]",reTrim=/^\s+|\s+$/g,reIsBadHex=/^[-+]0x[0-9a-f]+$/i,reIsBinary=/^0b[01]+$/i,reIsOctal=/^0o[0-7]+$/i,freeParseInt=parseInt,objectProto=Object.prototype,objectToString=objectProto.toString;
function baseSlice(a,b,c){var e=-1,d=a.length;0>b&&(b=-b>d?0:d+b);c=c>d?d:c;0>c&&(c+=d);d=b>c?0:c-b>>>0;b>>>=0;for(c=Array(d);++e<d;)c[e]=a[e+b];return c}function takeRight(a,b,c){var e=a?a.length:0;if(!e)return[];b=c||void 0===b?1:toInteger(b);b=e-b;return baseSlice(a,0>b?0:b,e)}function isObject(a){var b=typeof a;return!!a&&("object"==b||"function"==b)}function isObjectLike(a){return!!a&&"object"==typeof a}
function isSymbol(a){return"symbol"==typeof a||isObjectLike(a)&&objectToString.call(a)==symbolTag}function toFinite(a){if(!a)return 0===a?a:0;a=toNumber(a);return a===INFINITY||a===-INFINITY?(0>a?-1:1)*MAX_INTEGER:a===a?a:0}function toInteger(a){a=toFinite(a);var b=a%1;return a===a?b?a-b:a:0}
function toNumber(a){if("number"==typeof a)return a;if(isSymbol(a))return NAN;isObject(a)&&(a="function"==typeof a.valueOf?a.valueOf():a,a=isObject(a)?a+"":a);if("string"!=typeof a)return 0===a?a:+a;a=a.replace(reTrim,"");var b=reIsBinary.test(a);return b||reIsOctal.test(a)?freeParseInt(a.slice(2),b?2:8):reIsBadHex.test(a)?NAN:+a}var lodash_takeright=takeRight;
function convertSelectorStateIntoCSSSelector(a){let b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:a.stack.length;return lodash_takeright(a.stack.reduceRight((a,b)=>{b.length?a.push(b.join("")):a.length&&a.push("*");return a},[]),b).join(" > ")||"*"}
function validateSelector(a,b,c,e){let {selectorMaxLength:d}=b;return function(b){var h=!1;for(let g=1;g<=b.stack.length&&!h;g+=1){h=convertSelectorStateIntoCSSSelector(b,g).trim();if(!h||!h.length||d&&h.length>d)return!1;h=c(h,e);if(h=1===h.length&&(void 0!==a.el?h[0]===a.el:h[0]===a))b.verificationDepth=g}return h}}function Parser(a){let b=a.getMethods();return{finished(){return 0===b.length},next(){return this.finished()?!1:b.shift()(...arguments)}}}function push(a,b){a.push(b);return a}
function tail(a){return a[a.length-1]}function stackHierarchy(a,b){if(0>=b)throw Error(`Simmer: An invalid depth of ${b} has been specified`);return Array(b-1).fill().reduce((a,b)=>tail(a).parent()?push(a,tail(a).parent()):a,[a])}let DEFAULT_CONFIGURATION={queryEngine:null,specificityThreshold:100,depth:3,errorHandling:!1,selectorMaxLength:512};function configure(){return{...DEFAULT_CONFIGURATION,...0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}}}
function createSimmer(){function a(a,b){if(!0===e.errorHandling)throw a;"function"===typeof e.errorHandling&&e.errorHandling(a,b)}let b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:window,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:!1,e=configure(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}),d=c||initQueryEngine(b,e.queryEngine),g=function(b){if(!b)return a.call(g,Error("Simmer: No element was specified for parsing."),b),null;const c=new Parser(parsingMethods),
h=stackHierarchy(wrap(b),e.depth);let l={stack:Array(h.length).fill().map(()=>[]),specificity:0};const n=validateSelector(b,e,d,a);for(;!c.finished()&&!l.verified;)try{l=c.next(h,l,n,e,d),l.specificity>=e.specificityThreshold&&!l.verified&&(l.verified=n(l))}catch(t){a.call(g,t,b)}if(void 0===l.verified||l.specificity<e.specificityThreshold)l.verified=n(l);return l.verified?l.verificationDepth?convertSelectorStateIntoCSSSelector(l,l.verificationDepth):convertSelectorStateIntoCSSSelector(l):null};g.configure=
function(){let a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:b,c=configure({...e,...0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}});return createSimmer(a,c,initQueryEngine(a,c.queryEngine))};return g}function exposeOnWindow(a,b){let c=a.Simmer;a.Simmer=b;b.noConflict=function(){a.Simmer=c;return b}}exposeOnWindow(window,createSimmer(window))