@nodebug/browser-element-finder 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/index.js +10 -15
- package/index.min.js +2 -2
- package/package.json +1 -1
- package/src/element-finder.js +15 -21
package/README.md
CHANGED
|
@@ -225,7 +225,7 @@ The package is ESM-only (`"type": "module"`), so CommonJS `require()` examples a
|
|
|
225
225
|
| `findElements(type, text, exact, parent)` | Find elements by type/text, returns `{ elements: [...] }` |
|
|
226
226
|
| `findElementsByType(type, parent)` | Find elements by type only, returns `{ elements: [...] }` |
|
|
227
227
|
| `findElementsByAttribute(value, exact, parent)` | Find elements by text/attribute, returns `{ elements: [...] }` |
|
|
228
|
-
| `getElementCounts(type, parent)` | Count elements by semantic type and visibility,
|
|
228
|
+
| `getElementCounts(type, parent)` | Count elements by semantic type and visibility, including generic `element` by default |
|
|
229
229
|
| `findProbableElements(type, text, exact, parent)` | Find elements with fallback to nearby elements, returns `{ elements: [...] }` |
|
|
230
230
|
| `highlight(elements, color, width)` | Highlight elements with outline |
|
|
231
231
|
| `unhighlight(elements)` | Remove highlight |
|
|
@@ -420,17 +420,17 @@ Finds elements by type only. Searches all frames by default.
|
|
|
420
420
|
|
|
421
421
|
Counts elements by semantic type and visibility on the current screen. Searches all frames (main document + iframes) by default.
|
|
422
422
|
|
|
423
|
-
| Parameter | Type | Default | Description
|
|
424
|
-
| --------- | --------- | ------- |
|
|
425
|
-
| `type` | `string` | `null` | Specific element type to count. If `null`/`undefined`, returns counts for all defined types
|
|
426
|
-
| `parent` | `Element` | `null` | Parent element to count within
|
|
423
|
+
| Parameter | Type | Default | Description |
|
|
424
|
+
| --------- | --------- | ------- | -------------------------------------------------------------------------------------------- |
|
|
425
|
+
| `type` | `string` | `null` | Specific element type to count. If `null`/`undefined`, returns counts for all defined types. |
|
|
426
|
+
| `parent` | `Element` | `null` | Parent element to count within |
|
|
427
427
|
|
|
428
428
|
**Returns**: `Object.<string, { visible: number, hidden: number, total: number }>` keyed by semantic element type.
|
|
429
429
|
|
|
430
430
|
```javascript
|
|
431
|
-
// Count all defined
|
|
431
|
+
// Count all defined types
|
|
432
432
|
const counts = ElementFinder.getElementCounts()
|
|
433
|
-
// { button: { visible: 3, hidden: 0, total: 3 }, textbox: { visible: 2, hidden: 0, total: 2 }, ... }
|
|
433
|
+
// { element: { visible: 98, hidden: 6, total: 104 }, button: { visible: 3, hidden: 0, total: 3 }, textbox: { visible: 2, hidden: 0, total: 2 }, ... }
|
|
434
434
|
|
|
435
435
|
// Count one type
|
|
436
436
|
const buttons = ElementFinder.getElementCounts('button')
|
|
@@ -444,7 +444,7 @@ const inputs = ElementFinder.getElementCounts(
|
|
|
444
444
|
// { textbox: { visible: 2, hidden: 0, total: 2 } }
|
|
445
445
|
```
|
|
446
446
|
|
|
447
|
-
The generic `element` type is
|
|
447
|
+
The generic `element` type is included in the all-types count, so the result contains both the catch-all `element` count and semantic types such as `button`, `textbox`, `link`, and `table`.
|
|
448
448
|
|
|
449
449
|
### `findElementsByAttribute(value, exact, parent)`
|
|
450
450
|
|
package/index.js
CHANGED
|
@@ -746,6 +746,7 @@ var ElementFinder = (() => {
|
|
|
746
746
|
}
|
|
747
747
|
function getElementCounts(type = null, parent = null, options = null) {
|
|
748
748
|
const hasType = type !== null && type !== void 0;
|
|
749
|
+
const targetTypes = hasType ? [type] : Object.keys(ELEMENT_DEFINITIONS);
|
|
749
750
|
if (hasType) {
|
|
750
751
|
if (typeof type !== "string") {
|
|
751
752
|
throw new TypeError(`type must be a string, got ${typeof type}`);
|
|
@@ -760,24 +761,18 @@ var ElementFinder = (() => {
|
|
|
760
761
|
}
|
|
761
762
|
}
|
|
762
763
|
const counts = {};
|
|
763
|
-
const targetTypes = hasType ? [type] : Object.keys(ELEMENT_DEFINITIONS).filter((item) => item !== "element");
|
|
764
764
|
for (let i = 0; i < targetTypes.length; i++) {
|
|
765
765
|
counts[targetTypes[i]] = { visible: 0, hidden: 0, total: 0 };
|
|
766
766
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
const
|
|
770
|
-
const
|
|
771
|
-
for (let j = 0; j <
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
const bucket = isHidden(el) ? "hidden" : "visible";
|
|
777
|
-
counts[targetType][bucket] += 1;
|
|
778
|
-
counts[targetType].total += 1;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
767
|
+
for (let i = 0; i < targetTypes.length; i++) {
|
|
768
|
+
const targetType = targetTypes[i];
|
|
769
|
+
const result = findElements(targetType, null, false, parent, options);
|
|
770
|
+
const typeCounts = counts[targetType];
|
|
771
|
+
for (let j = 0; j < result.elements.length; j++) {
|
|
772
|
+
const item = result.elements[j];
|
|
773
|
+
const bucket = item.isHidden ? "hidden" : "visible";
|
|
774
|
+
typeCounts[bucket] += 1;
|
|
775
|
+
typeCounts.total += 1;
|
|
781
776
|
}
|
|
782
777
|
}
|
|
783
778
|
return counts;
|
package/index.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ElementFinder=(()=>{var D=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var Q=(e,t)=>{for(var n in t)D(e,n,{get:t[n],enumerable:!0})},J=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Z(t))!G.call(e,r)&&r!==n&&D(e,r,{get:()=>t[r],enumerable:!(o=Y(t,r))||o.enumerable});return e};var K=e=>J(D({},"__esModule",{value:!0}),e);var Te={};Q(Te,{ELEMENT_DEFINITIONS:()=>p,findElements:()=>me,findElementsByAttribute:()=>W,findElementsByType:()=>z,findProbableElements:()=>ge,getAllElements:()=>y,getAllFrames:()=>x,getBoundingBox:()=>A,getElementCounts:()=>de,getElementDescriptor:()=>fe,getSearchableAttributeValues:()=>H,getSearchableAttributes:()=>re,getValidAttributes:()=>xe,getValidTypes:()=>Ee,highlight:()=>pe,isHidden:()=>N,matchesAttribute:()=>S,matchesType:()=>g,parseCondition:()=>V,parseXPath:()=>w,pauseAnimations:()=>be,resumeAnimations:()=>we,setSearchableAttributes:()=>ne,splitByOperator:()=>B,unhighlight:()=>ye});var P={link:"self::a or @role='link' or @href",navigation:"@role='navigation' or self::nav",heading:"@role='heading' or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6",button:"self::button or @role='button' or @type='button' or @type='submit'",checkbox:"(self::input and @type='checkbox') or @role='checkbox'",switch:"(self::input and @type='checkbox') or @role='switch' or (self::button and (contains(@class, 'switch') or @data-state))",slider:"self::input[@type='range'] or @role='slider'",datepicker:"self::input[@type='date'] or @role='date'",colorpicker:"self::input[@type='color'] or @role='color'",radio:"(self::input and @type='radio') or @role='radio'",dropdown:"(self::select[descendant::option] or @role='combobox' or @role='listbox' or contains(@class, 'dropdown') or contains(@class, 'trigger') or ancestor::*[contains(@class, 'dropdown') or @role='combobox'])",textbox:"self::textarea or (self::input and (@type='text' or @type='password' or @type='search' or @type='email' or @type='number' or @type='tel' or @type='url')) or @role='textbox'",file:"self::input and @type='file'",list:"self::ul or self::ol or @role='list'",listitem:"self::li or @role='listitem'",menu:"self::menu or @role='menu'",menuitem:"@role='menuitem'",toolbar:"@role='toolbar'",dialog:"@role='dialog' or @role='alertdialog'",table:"self::table or @role='table'",row:"self::tr or @role='row'",column:"self::td or self::th or @role='cell' or @role='gridcell' or @role='columnheader'",cell:"self::td or @role='cell' or @role='gridcell'",image:"self::img or @role='img' or @alt",element:"true()"};var R=["placeholder","value","data-value","data-test-id","data-testid","id","resource-id","name","aria-label","hint","title","tooltip","alt","src","aria-labelledby"];var b={selfWithTag:/^self::([a-zA-Z0-9-]+)(?:\[([^\]]+)\])?$/,contains:/contains\(@([a-zA-Z0-9-]+),\s*['"]([^'"]+)['"]\)/i,attrEquals:/@([a-zA-Z0-9-]+)\s*=\s*['"]([^'"]*)['"]/,attrExists:/^@([a-zA-Z0-9-]+)$/,descendant:/descendant::([a-zA-Z0-9-]+)/i,ancestor:/ancestor::\*\[([^\]]+)\]/i,operatorOr:/^\s*\bor\b\s*/i,operatorAnd:/^\s*\band\b\s*/i},te=100,U=25,C=new Map;for(let[e,t]of Object.entries(P))t==="true()"?C.set(e,()=>!0):C.set(e,n=>w(t,n));var E=R;function ne(e){if(!Array.isArray(e))throw new TypeError("attributes must be an array");E=e}function re(){return[...E]}function H(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return{};let t={},n=E;for(let o=0;o<n.length;o++){let r=n[o],i;try{i=e.getAttribute(r)}catch(l){continue}i!=null&&i!==""&&(t[r]=i)}return t}function I(e){return e==null?"":String(e).replace(/\s+/g," ").trim()}function j(e){if(e==null)return"";let t=String(e).split(/\r\n|\r|\n/),n="";for(let i=0;i<t.length&&(n=I(t[i]),!n);i++);if(!n||n.length<=U)return n;let o=n.slice(0,U),r=o.lastIndexOf(" ");return r>0?o.slice(0,r):n}function oe(e){let t=I(e);if(!t)return"";let n=t.split(/[?#]/)[0],o=Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\")),r=o>=0?n.slice(o+1):n,i=r.lastIndexOf(".");return i>0?r.slice(0,i):r}function ie(e){let t=e.getAttribute("aria-labelledby");if(!t)return"";let n=t.split(/\s+/),o=e.ownerDocument||document,r="";for(let i of n)try{let l=o.getElementById(i);if(!l)continue;let s=I(l.textContent);s&&(r=r?`${r} ${s}`:s)}catch(l){}return r}function _(e){let t=H(e),n=E;for(let i=0;i<n.length;i++){let l=n[i];if(!Object.prototype.hasOwnProperty.call(t,l))continue;let s=l==="aria-labelledby"?ie(e):l==="src"?oe(t[l]):t[l],a=I(s);if(a)return{attributeName:l,identifiableText:a}}let o=j($(e));if(o)return{attributeName:"text",identifiableText:o};let r=j(e.textContent);return r?{attributeName:"text",identifiableText:r}:null}function se(e){if(!e||!e.ownerDocument)return null;try{let t=x(window);for(let n=0;n<t.length;n++)if(t[n].document===e.ownerDocument)return t[n].document}catch(t){}return e.ownerDocument}function le(e,t){let n=se(e);if(!n)return{index:1};let o=y(n),r=1,i=0;for(let l=0;l<o.length;l++){let s=o[l];if(s!==e&&(s===n.documentElement||s.tagName==="BODY"))continue;let a=_(s);!a||a.identifiableText!==t||(i++,s===e&&(r=i))}return{index:r}}function ae(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return null;let t=Object.keys(p);for(let n=0;n<t.length;n++){let o=t[n];if(o!=="element"&&g(e,o))return o}return"element"}function fe(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return{identifiableText:null,attributeName:null,index:1,type:null,tagName:null};let t=ae(e),n=_(e);if(!n)return{identifiableText:null,attributeName:null,index:1,type:t,tagName:e.tagName.toLowerCase()};let o=le(e,n.identifiableText);return{identifiableText:n.identifiableText,attributeName:n.attributeName,index:o.index,type:t,tagName:e.tagName.toLowerCase()}}function w(e,t,n=0){if(e==null||t==null)return!1;if(n>te)throw new Error("XPath expression exceeds maximum recursion depth");if(e=e.trim(),e==="true()")return!0;if(e[0]==="("&&e[e.length-1]===")"){let i=1,l=!0;for(let s=1;s<e.length-1;s++)if(e[s]==="("?i++:e[s]===")"&&i--,i===0){l=!1;break}if(l)return w(e.slice(1,-1),t,n+1)}let o=B(e,"or");if(o.length>1){for(let i of o)if(w(i,t,n+1))return!0;return!1}let r=B(e,"and");if(r.length>1){for(let i of r)if(!w(i,t,n+1))return!1;return!0}return V(e,t,n)}function B(e,t){let n=[],o=0,r="",i=!1,l="",s=t==="or"?b.operatorOr:b.operatorAnd;for(let a=0;a<e.length;a++){let f=e[a];if((f==="'"||f==='"')&&(a===0||e[a-1]!=="\\")&&(i?f===l&&(i=!1):(i=!0,l=f)),!i&&(f==="("?o++:f===")"&&o--,o===0)){let c=e.slice(a).match(s);if(c){n.push(r.trim()),a+=c[0].length-1,r="";continue}}r+=f}return r.trim()&&n.push(r.trim()),n}function V(e,t,n=0){if(e==null||t==null)return!1;e=e.trim();let o=e.match(b.selfWithTag);if(o){let f=o[1].toUpperCase();return t.tagName!==f?!1:o[2]?w(o[2],t,n+1):!0}let r=e.match(b.contains);if(r)return(t.getAttribute(r[1])||"").toLowerCase().includes(r[2].toLowerCase());let i=e.match(b.attrEquals);if(i)return t.getAttribute(i[1])===i[2];let l=e.match(b.attrExists);if(l)return t.hasAttribute(l[1]);let s=e.match(b.descendant);if(s)return t.querySelector(s[1])!==null;let a=e.match(b.ancestor);if(a){let f=t.parentElement;for(;f;){if(w(a[1],f,n+1))return!0;f=f.parentElement}return!1}return!1}var p=Object.freeze(P);function $(e){let t="";for(let n=0;n<e.childNodes.length;n++){let o=e.childNodes[n];o.nodeType===Node.TEXT_NODE&&(t+=o.textContent)}return t.trim()}function ce(e){if(e.tagName==="STYLE"||e.tagName==="SCRIPT"||e.querySelector("STYLE, SCRIPT"))return!0;let t=e.parentElement;for(;t;){if(t.tagName==="STYLE"||t.tagName==="SCRIPT")return!0;t=t.parentElement}return!1}function F(e){let t=e.getAttribute("aria-labelledby");if(!t)return"";let n=t.split(/\s+/),o="";for(let r of n)try{let i=document.getElementById(r);i&&(o+=i.textContent)}catch(i){}return o}function S(e,t,n=!1){if(e==null)return!1;if(t==null||t==="")return!0;if(ce(e))return!1;let o=E;for(let l=0;l<o.length;l++){let s=o[l],a;try{a=e.getAttribute(s)}catch(f){continue}if(a){if(s==="aria-labelledby"){if(n?a===t:a.includes(t))return!0;let f=F(e);if(f&&(n?f===t:f.includes(t)))return!0}else if(n?a===t:a.includes(t))return!0}}let r=$(e);if(n?r===t:r.includes(t))return!0;let i=e.textContent;return!!(n?i.trim()===t:i.includes(t))}function g(e,t){if(e==null)return!1;let n=C.get(t);return n?n(e):!1}function y(e=document){let t=[];if(e==null)return t;let n=e.nodeType===Node.DOCUMENT_NODE?e.documentElement:e;if(!n)return t;let o=[n];for(;o.length>0;){let r=o.pop();if(r.nodeType!==Node.ELEMENT_NODE||r.tagName==="SCRIPT"||r.tagName==="STYLE")continue;t.push(r);let i=r.children;for(let l=i.length-1;l>=0;l--)o.push(i[l]);try{if(r.shadowRoot){let l=r.shadowRoot.children;for(let s=l.length-1;s>=0;s--)o.push(l[s])}}catch(l){}}return t}function x(e=window){let t=[];try{t.push({window:e,document:e.document,isMainFrame:!0,frameIndex:-1});let n=e.document.querySelectorAll("iframe");for(let o=0;o<n.length;o++){let r=n[o];try{r.contentWindow&&r.contentDocument&&t.push({window:r.contentWindow,document:r.contentDocument,isMainFrame:!1,frameElement:r,frameIndex:o})}catch(i){i.name==="SecurityError"?console.warn("Skipping cross-origin iframe:",i.message):console.warn("Error accessing iframe:",i.message)}}}catch(n){console.warn("Error getting frames:",n.message)}return t}function A(e){let t=e.getBoundingClientRect();return{x:t.x,y:t.y,width:t.width,height:t.height,top:t.top,bottom:t.bottom,left:t.left,right:t.right,midx:t.x+t.width/2,midy:t.y+t.height/2,tagName:e.tagName.toLowerCase()}}function N(e){if(e==null)return!0;let t=e;for(;t;){if(ue(t))return!0;t=t.parentElement}return!1}function ue(e){if(e.hasAttribute("hidden")||e.getAttribute("aria-hidden")==="true"||e.inert||e.offsetWidth===0&&e.offsetHeight===0)return!0;if(typeof e.checkVisibility=="function")return!e.checkVisibility({checkOpacity:!0,checkVisibilityCSS:!0,contentVisibilityAuto:!0});try{let t=window.getComputedStyle(e);if(t.visibility==="hidden"||t.visibility==="collapse"||t.display==="none"||t.opacity==="0")return!0}catch(t){}return!1}function z(e="element",t=null,n=null){if(e==null&&(e="element"),typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);let o=n&&n.failOnUnknownType===!0;if(e&&!p[e]){let a=`Unknown element type: ${e}. Valid types: ${Object.keys(p).join(", ")}`;if(o)throw new TypeError(`Unknown element type: ${e}`);return console.warn(a),{elements:[]}}let r=[],i=x(window);for(let a of i){let f=y(t||a.document);for(let u=0;u<f.length;u++){let c=f[u];e&&!g(c,e)||r.push({element:c,frame:a})}}let l=[];if(r.length>0){let a=new Set(r.map(u=>u.element)),f=new Set;for(let u=r.length-1;u>=0;u--){let c=r[u],d=c.element;if(!f.has(d)){l.unshift(c);let m=d.parentElement;for(;m;)a.has(m)&&f.add(m),m=m.parentElement}}}return{elements:l.map(a=>{let f=A(a.element),u=a.element.tagName.toLowerCase(),c=N(a.element);return a.frame.isMainFrame?{element:a.element,boundingBox:f,tagName:u,frameIndex:a.frame.frameIndex,isHidden:c}:{boundingBox:f,tagName:u,frameIndex:a.frame.frameIndex,isHidden:c}})}}function W(e,t=!1,n=null){if(e==null&&(e=""),typeof e!="string")throw new TypeError(`value must be a string, got ${typeof e}`);let o=[],r=x(window);for(let s of r){let a=y(n||s.document);for(let f=0;f<a.length;f++){let u=a[f];S(u,e,t)&&o.push({element:u,frame:s})}}return{elements:o.filter(s=>{let a=s.element;if(k(a,e,t))return!0;for(let u of o)if(u.element!==a&&a.contains(u.element))return!1;return!0}).map(s=>{let a=A(s.element),f=s.element.tagName.toLowerCase(),u=N(s.element);return s.frame.isMainFrame?{element:s.element,boundingBox:a,tagName:f,frameIndex:s.frame.frameIndex,isHidden:u}:{boundingBox:a,tagName:f,frameIndex:s.frame.frameIndex,isHidden:u}})}}function k(e,t,n=!1){if(t==null||t==="")return!0;let o=E;for(let i=0;i<o.length;i++){let l=o[i],s;try{s=e.getAttribute(l)}catch(a){continue}if(s){if(l==="aria-labelledby"){if(n?s===t:s.includes(t))return!0;let a=F(e);if(a&&(n?a===t:a.includes(t)))return!0}else if(n?s===t:s.includes(t))return!0}}let r=$(e);return!!(n?r===t:r.includes(t))}function de(e=null,t=null,n=null){let o=e!=null;if(o){if(typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);if(!p[e]){let s=`Unknown element type: ${e}. Valid types: ${Object.keys(p).join(", ")}`;if(n&&n.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(s),{[e]:{visible:0,hidden:0,total:0}}}}let r={},i=o?[e]:Object.keys(p).filter(s=>s!=="element");for(let s=0;s<i.length;s++)r[i[s]]={visible:0,hidden:0,total:0};let l=x(window);for(let s=0;s<l.length;s++){let a=l[s],f=y(t||a.document);for(let u=0;u<f.length;u++){let c=f[u];for(let d=0;d<i.length;d++){let m=i[d];if(g(c,m)){let h=N(c)?"hidden":"visible";r[m][h]+=1,r[m].total+=1}}}}return r}function me(e=null,t=null,n=!1,o=null,r=null){if(t==null&&(t=""),e!=null){if(typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);if(!p[e]){let f=`Unknown element type: ${e}. Valid types: ${Object.keys(p).join(", ")}`;if(r&&r.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(f),{elements:[]}}}if(t!==""&&typeof t!="string")throw new TypeError(`text must be a string, got ${typeof t}`);let i=[],l=x(window);for(let f of l){let u=y(o||f.document);for(let c=0;c<u.length;c++){let d=u[c];e!=null&&!g(d,e)||t!==""&&!S(d,t,n)||i.push({element:d,frame:f})}}return{elements:(t!==""?i.filter(f=>{let u=f.element;if(k(u,t,n))return!0;for(let d of i)if(d.element!==u&&u.contains(d.element))return!1;return!0}):i).map(f=>{let u=A(f.element),c=f.element.tagName.toLowerCase(),d=N(f.element);return f.frame.isMainFrame?{element:f.element,boundingBox:u,tagName:c,frameIndex:f.frame.frameIndex,isHidden:d}:{boundingBox:u,tagName:c,frameIndex:f.frame.frameIndex,isHidden:d}})}}function L(e){if(e.parentElement)return e.parentElement;try{let t=e.getRootNode();if(t&&t.host)return t.host}catch(t){}return null}function q(e){let t=L(e);if(!t)return[];if(t.shadowRoot)try{return Array.from(t.shadowRoot.children)}catch(n){return[]}return Array.from(t.children)}function he(e,t){let n=L(e);for(;n;){if(g(n,t))return n;n=L(n)}let o=e.children||[];for(let l of o)if(g(l,t))return l;let r=q(e);for(let l of r)if(l!==e&&g(l,t))return l;for(let l of r){if(l===e)continue;let s=y(l);for(let a=0;a<s.length;a++)if(g(s[a],t))return s[a]}let i=e.parentElement;for(;i;){let l=q(i);for(let s of l)if(s!==i){if(g(s,t))return s;let a=y(s);for(let f=0;f<a.length;f++)if(g(a[f],t))return a[f]}i=i.parentElement}return null}function ge(e,t,n=!1,o=null,r=null){let i=e!=null&&e!=="",l=t!=null&&t!=="";if(i&&!l)return z(e,o,r);if(!i&&l)return W(t,n,o);if(i){if(typeof e!="string")throw new TypeError(`elementType must be a string, got ${typeof e}`);if(!p[e]){let c=`Unknown element type: ${e}. Valid types: ${Object.keys(p).join(", ")}`;if(r&&r.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(c),{elements:[]}}}if(l&&typeof t!="string")throw new TypeError(`attributeText must be a string, got ${typeof t}`);let s=[],a=x(window);for(let c of a){let d=y(o||c.document);for(let m=0;m<d.length;m++){let h=d[m];i&&!g(h,e)||l&&!S(h,t,n)||s.push({element:h,frame:c})}}if(s.length===0&&i&&l){let c=[];for(let m of a){let h=y(o||m.document);for(let O=0;O<h.length;O++){let M=h[O];S(M,t,n)&&k(M,t,n)&&c.push({element:M,frame:m})}}let d=new Set;for(let m of c){let h=he(m.element,e);h&&!d.has(h)&&(d.add(h),s.push({element:h,frame:m.frame}))}}return{elements:(l?s.filter(c=>{let d=c.element;if(k(d,t,n))return!0;for(let h of s)if(h.element!==d&&d.contains(h.element))return!1;return!0}):s).map(c=>{let d=A(c.element),m=c.element.tagName.toLowerCase(),h=N(c.element);return c.frame.isMainFrame?{element:c.element,boundingBox:d,tagName:m,frameIndex:c.frame.frameIndex,isHidden:h}:{boundingBox:d,tagName:m,frameIndex:c.frame.frameIndex,isHidden:h}})}}function X(e){return e?e&&e.elements&&Array.isArray(e.elements)?e.elements:Array.isArray(e)?e:[e]:[]}function pe(e,t="red",n=3){let o=X(e);for(let r=0;r<o.length;r++){let i=o[r],l=i.element?i.element:i;l&&l.style&&(l.style.outline=`${n}px solid ${t}`,l.style.outlineOffset="2px",l.style.boxShadow="0 0 0 2px rgba(255, 255, 255, 0.8)",l.classList.add("elementfinder-highlighted"))}}function ye(e){let t=X(e);for(let n=0;n<t.length;n++){let o=t[n],r=o.element?o.element:o;r&&r.style&&(r.style.outline="",r.style.outlineOffset="",r.style.boxShadow="",r.classList.remove("elementfinder-highlighted"))}}var T=[];function be(){let e=new Map,t=y();for(let r of t)r&&r.style&&r.style.animationPlayState!=="paused"&&(e.set(r,{animationPlayState:r.style.animationPlayState,transitionProperty:r.style.transitionProperty,webkitAnimationPlayState:r.style.webkitAnimationPlayState,webkitTransitionProperty:r.style.webkitTransitionProperty}),r.style.animationPlayState="paused",r.style.transitionProperty="none",r.style.webkitAnimationPlayState="paused",r.style.webkitTransitionProperty="none");let n=document.getElementById("elementfinder-animation-pause");n||(n=document.createElement("style"),n.id="elementfinder-animation-pause",n.textContent=`
|
|
1
|
+
var ElementFinder=(()=>{var D=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var J=(e,t)=>{for(var n in t)D(e,n,{get:t[n],enumerable:!0})},K=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of G(t))!Q.call(e,r)&&r!==n&&D(e,r,{get:()=>t[r],enumerable:!(o=Z(t,r))||o.enumerable});return e};var v=e=>K(D({},"__esModule",{value:!0}),e);var Te={};J(Te,{ELEMENT_DEFINITIONS:()=>g,findElements:()=>X,findElementsByAttribute:()=>W,findElementsByType:()=>z,findProbableElements:()=>ge,getAllElements:()=>y,getAllFrames:()=>T,getBoundingBox:()=>S,getElementCounts:()=>me,getElementDescriptor:()=>ce,getSearchableAttributeValues:()=>H,getSearchableAttributes:()=>oe,getValidAttributes:()=>xe,getValidTypes:()=>Ee,highlight:()=>pe,isHidden:()=>A,matchesAttribute:()=>N,matchesType:()=>p,parseCondition:()=>V,parseXPath:()=>w,pauseAnimations:()=>be,resumeAnimations:()=>we,setSearchableAttributes:()=>re,splitByOperator:()=>B,unhighlight:()=>ye});var P={link:"self::a or @role='link' or @href",navigation:"@role='navigation' or self::nav",heading:"@role='heading' or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6",button:"self::button or @role='button' or @type='button' or @type='submit'",checkbox:"(self::input and @type='checkbox') or @role='checkbox'",switch:"(self::input and @type='checkbox') or @role='switch' or (self::button and (contains(@class, 'switch') or @data-state))",slider:"self::input[@type='range'] or @role='slider'",datepicker:"self::input[@type='date'] or @role='date'",colorpicker:"self::input[@type='color'] or @role='color'",radio:"(self::input and @type='radio') or @role='radio'",dropdown:"(self::select[descendant::option] or @role='combobox' or @role='listbox' or contains(@class, 'dropdown') or contains(@class, 'trigger') or ancestor::*[contains(@class, 'dropdown') or @role='combobox'])",textbox:"self::textarea or (self::input and (@type='text' or @type='password' or @type='search' or @type='email' or @type='number' or @type='tel' or @type='url')) or @role='textbox'",file:"self::input and @type='file'",list:"self::ul or self::ol or @role='list'",listitem:"self::li or @role='listitem'",menu:"self::menu or @role='menu'",menuitem:"@role='menuitem'",toolbar:"@role='toolbar'",dialog:"@role='dialog' or @role='alertdialog'",table:"self::table or @role='table'",row:"self::tr or @role='row'",column:"self::td or self::th or @role='cell' or @role='gridcell' or @role='columnheader'",cell:"self::td or @role='cell' or @role='gridcell'",image:"self::img or @role='img' or @alt",element:"true()"};var R=["placeholder","value","data-value","data-test-id","data-testid","id","resource-id","name","aria-label","hint","title","tooltip","alt","src","aria-labelledby"];var b={selfWithTag:/^self::([a-zA-Z0-9-]+)(?:\[([^\]]+)\])?$/,contains:/contains\(@([a-zA-Z0-9-]+),\s*['"]([^'"]+)['"]\)/i,attrEquals:/@([a-zA-Z0-9-]+)\s*=\s*['"]([^'"]*)['"]/,attrExists:/^@([a-zA-Z0-9-]+)$/,descendant:/descendant::([a-zA-Z0-9-]+)/i,ancestor:/ancestor::\*\[([^\]]+)\]/i,operatorOr:/^\s*\bor\b\s*/i,operatorAnd:/^\s*\band\b\s*/i},ne=100,U=25,C=new Map;for(let[e,t]of Object.entries(P))t==="true()"?C.set(e,()=>!0):C.set(e,n=>w(t,n));var E=R;function re(e){if(!Array.isArray(e))throw new TypeError("attributes must be an array");E=e}function oe(){return[...E]}function H(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return{};let t={},n=E;for(let o=0;o<n.length;o++){let r=n[o],i;try{i=e.getAttribute(r)}catch(s){continue}i!=null&&i!==""&&(t[r]=i)}return t}function I(e){return e==null?"":String(e).replace(/\s+/g," ").trim()}function j(e){if(e==null)return"";let t=String(e).split(/\r\n|\r|\n/),n="";for(let i=0;i<t.length&&(n=I(t[i]),!n);i++);if(!n||n.length<=U)return n;let o=n.slice(0,U),r=o.lastIndexOf(" ");return r>0?o.slice(0,r):n}function ie(e){let t=I(e);if(!t)return"";let n=t.split(/[?#]/)[0],o=Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\")),r=o>=0?n.slice(o+1):n,i=r.lastIndexOf(".");return i>0?r.slice(0,i):r}function se(e){let t=e.getAttribute("aria-labelledby");if(!t)return"";let n=t.split(/\s+/),o=e.ownerDocument||document,r="";for(let i of n)try{let s=o.getElementById(i);if(!s)continue;let l=I(s.textContent);l&&(r=r?`${r} ${l}`:l)}catch(s){}return r}function _(e){let t=H(e),n=E;for(let i=0;i<n.length;i++){let s=n[i];if(!Object.prototype.hasOwnProperty.call(t,s))continue;let l=s==="aria-labelledby"?se(e):s==="src"?ie(t[s]):t[s],a=I(l);if(a)return{attributeName:s,identifiableText:a}}let o=j($(e));if(o)return{attributeName:"text",identifiableText:o};let r=j(e.textContent);return r?{attributeName:"text",identifiableText:r}:null}function le(e){if(!e||!e.ownerDocument)return null;try{let t=T(window);for(let n=0;n<t.length;n++)if(t[n].document===e.ownerDocument)return t[n].document}catch(t){}return e.ownerDocument}function ae(e,t){let n=le(e);if(!n)return{index:1};let o=y(n),r=1,i=0;for(let s=0;s<o.length;s++){let l=o[s];if(l!==e&&(l===n.documentElement||l.tagName==="BODY"))continue;let a=_(l);!a||a.identifiableText!==t||(i++,l===e&&(r=i))}return{index:r}}function fe(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return null;let t=Object.keys(g);for(let n=0;n<t.length;n++){let o=t[n];if(o!=="element"&&p(e,o))return o}return"element"}function ce(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return{identifiableText:null,attributeName:null,index:1,type:null,tagName:null};let t=fe(e),n=_(e);if(!n)return{identifiableText:null,attributeName:null,index:1,type:t,tagName:e.tagName.toLowerCase()};let o=ae(e,n.identifiableText);return{identifiableText:n.identifiableText,attributeName:n.attributeName,index:o.index,type:t,tagName:e.tagName.toLowerCase()}}function w(e,t,n=0){if(e==null||t==null)return!1;if(n>ne)throw new Error("XPath expression exceeds maximum recursion depth");if(e=e.trim(),e==="true()")return!0;if(e[0]==="("&&e[e.length-1]===")"){let i=1,s=!0;for(let l=1;l<e.length-1;l++)if(e[l]==="("?i++:e[l]===")"&&i--,i===0){s=!1;break}if(s)return w(e.slice(1,-1),t,n+1)}let o=B(e,"or");if(o.length>1){for(let i of o)if(w(i,t,n+1))return!0;return!1}let r=B(e,"and");if(r.length>1){for(let i of r)if(!w(i,t,n+1))return!1;return!0}return V(e,t,n)}function B(e,t){let n=[],o=0,r="",i=!1,s="",l=t==="or"?b.operatorOr:b.operatorAnd;for(let a=0;a<e.length;a++){let f=e[a];if((f==="'"||f==='"')&&(a===0||e[a-1]!=="\\")&&(i?f===s&&(i=!1):(i=!0,s=f)),!i&&(f==="("?o++:f===")"&&o--,o===0)){let c=e.slice(a).match(l);if(c){n.push(r.trim()),a+=c[0].length-1,r="";continue}}r+=f}return r.trim()&&n.push(r.trim()),n}function V(e,t,n=0){if(e==null||t==null)return!1;e=e.trim();let o=e.match(b.selfWithTag);if(o){let f=o[1].toUpperCase();return t.tagName!==f?!1:o[2]?w(o[2],t,n+1):!0}let r=e.match(b.contains);if(r)return(t.getAttribute(r[1])||"").toLowerCase().includes(r[2].toLowerCase());let i=e.match(b.attrEquals);if(i)return t.getAttribute(i[1])===i[2];let s=e.match(b.attrExists);if(s)return t.hasAttribute(s[1]);let l=e.match(b.descendant);if(l)return t.querySelector(l[1])!==null;let a=e.match(b.ancestor);if(a){let f=t.parentElement;for(;f;){if(w(a[1],f,n+1))return!0;f=f.parentElement}return!1}return!1}var g=Object.freeze(P);function $(e){let t="";for(let n=0;n<e.childNodes.length;n++){let o=e.childNodes[n];o.nodeType===Node.TEXT_NODE&&(t+=o.textContent)}return t.trim()}function ue(e){if(e.tagName==="STYLE"||e.tagName==="SCRIPT"||e.querySelector("STYLE, SCRIPT"))return!0;let t=e.parentElement;for(;t;){if(t.tagName==="STYLE"||t.tagName==="SCRIPT")return!0;t=t.parentElement}return!1}function F(e){let t=e.getAttribute("aria-labelledby");if(!t)return"";let n=t.split(/\s+/),o="";for(let r of n)try{let i=document.getElementById(r);i&&(o+=i.textContent)}catch(i){}return o}function N(e,t,n=!1){if(e==null)return!1;if(t==null||t==="")return!0;if(ue(e))return!1;let o=E;for(let s=0;s<o.length;s++){let l=o[s],a;try{a=e.getAttribute(l)}catch(f){continue}if(a){if(l==="aria-labelledby"){if(n?a===t:a.includes(t))return!0;let f=F(e);if(f&&(n?f===t:f.includes(t)))return!0}else if(n?a===t:a.includes(t))return!0}}let r=$(e);if(n?r===t:r.includes(t))return!0;let i=e.textContent;return!!(n?i.trim()===t:i.includes(t))}function p(e,t){if(e==null)return!1;let n=C.get(t);return n?n(e):!1}function y(e=document){let t=[];if(e==null)return t;let n=e.nodeType===Node.DOCUMENT_NODE?e.documentElement:e;if(!n)return t;let o=[n];for(;o.length>0;){let r=o.pop();if(r.nodeType!==Node.ELEMENT_NODE||r.tagName==="SCRIPT"||r.tagName==="STYLE")continue;t.push(r);let i=r.children;for(let s=i.length-1;s>=0;s--)o.push(i[s]);try{if(r.shadowRoot){let s=r.shadowRoot.children;for(let l=s.length-1;l>=0;l--)o.push(s[l])}}catch(s){}}return t}function T(e=window){let t=[];try{t.push({window:e,document:e.document,isMainFrame:!0,frameIndex:-1});let n=e.document.querySelectorAll("iframe");for(let o=0;o<n.length;o++){let r=n[o];try{r.contentWindow&&r.contentDocument&&t.push({window:r.contentWindow,document:r.contentDocument,isMainFrame:!1,frameElement:r,frameIndex:o})}catch(i){i.name==="SecurityError"?console.warn("Skipping cross-origin iframe:",i.message):console.warn("Error accessing iframe:",i.message)}}}catch(n){console.warn("Error getting frames:",n.message)}return t}function S(e){let t=e.getBoundingClientRect();return{x:t.x,y:t.y,width:t.width,height:t.height,top:t.top,bottom:t.bottom,left:t.left,right:t.right,midx:t.x+t.width/2,midy:t.y+t.height/2,tagName:e.tagName.toLowerCase()}}function A(e){if(e==null)return!0;let t=e;for(;t;){if(de(t))return!0;t=t.parentElement}return!1}function de(e){if(e.hasAttribute("hidden")||e.getAttribute("aria-hidden")==="true"||e.inert||e.offsetWidth===0&&e.offsetHeight===0)return!0;if(typeof e.checkVisibility=="function")return!e.checkVisibility({checkOpacity:!0,checkVisibilityCSS:!0,contentVisibilityAuto:!0});try{let t=window.getComputedStyle(e);if(t.visibility==="hidden"||t.visibility==="collapse"||t.display==="none"||t.opacity==="0")return!0}catch(t){}return!1}function z(e="element",t=null,n=null){if(e==null&&(e="element"),typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);let o=n&&n.failOnUnknownType===!0;if(e&&!g[e]){let a=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(o)throw new TypeError(`Unknown element type: ${e}`);return console.warn(a),{elements:[]}}let r=[],i=T(window);for(let a of i){let f=y(t||a.document);for(let u=0;u<f.length;u++){let c=f[u];e&&!p(c,e)||r.push({element:c,frame:a})}}let s=[];if(r.length>0){let a=new Set(r.map(u=>u.element)),f=new Set;for(let u=r.length-1;u>=0;u--){let c=r[u],d=c.element;if(!f.has(d)){s.unshift(c);let m=d.parentElement;for(;m;)a.has(m)&&f.add(m),m=m.parentElement}}}return{elements:s.map(a=>{let f=S(a.element),u=a.element.tagName.toLowerCase(),c=A(a.element);return a.frame.isMainFrame?{element:a.element,boundingBox:f,tagName:u,frameIndex:a.frame.frameIndex,isHidden:c}:{boundingBox:f,tagName:u,frameIndex:a.frame.frameIndex,isHidden:c}})}}function W(e,t=!1,n=null){if(e==null&&(e=""),typeof e!="string")throw new TypeError(`value must be a string, got ${typeof e}`);let o=[],r=T(window);for(let l of r){let a=y(n||l.document);for(let f=0;f<a.length;f++){let u=a[f];N(u,e,t)&&o.push({element:u,frame:l})}}return{elements:o.filter(l=>{let a=l.element;if(k(a,e,t))return!0;for(let u of o)if(u.element!==a&&a.contains(u.element))return!1;return!0}).map(l=>{let a=S(l.element),f=l.element.tagName.toLowerCase(),u=A(l.element);return l.frame.isMainFrame?{element:l.element,boundingBox:a,tagName:f,frameIndex:l.frame.frameIndex,isHidden:u}:{boundingBox:a,tagName:f,frameIndex:l.frame.frameIndex,isHidden:u}})}}function k(e,t,n=!1){if(t==null||t==="")return!0;let o=E;for(let i=0;i<o.length;i++){let s=o[i],l;try{l=e.getAttribute(s)}catch(a){continue}if(l){if(s==="aria-labelledby"){if(n?l===t:l.includes(t))return!0;let a=F(e);if(a&&(n?a===t:a.includes(t)))return!0}else if(n?l===t:l.includes(t))return!0}}let r=$(e);return!!(n?r===t:r.includes(t))}function me(e=null,t=null,n=null){let o=e!=null,r=o?[e]:Object.keys(g);if(o){if(typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);if(!g[e]){let s=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(n&&n.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(s),{[e]:{visible:0,hidden:0,total:0}}}}let i={};for(let s=0;s<r.length;s++)i[r[s]]={visible:0,hidden:0,total:0};for(let s=0;s<r.length;s++){let l=r[s],a=X(l,null,!1,t,n),f=i[l];for(let u=0;u<a.elements.length;u++){let d=a.elements[u].isHidden?"hidden":"visible";f[d]+=1,f.total+=1}}return i}function X(e=null,t=null,n=!1,o=null,r=null){if(t==null&&(t=""),e!=null){if(typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);if(!g[e]){let f=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(r&&r.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(f),{elements:[]}}}if(t!==""&&typeof t!="string")throw new TypeError(`text must be a string, got ${typeof t}`);let i=[],s=T(window);for(let f of s){let u=y(o||f.document);for(let c=0;c<u.length;c++){let d=u[c];e!=null&&!p(d,e)||t!==""&&!N(d,t,n)||i.push({element:d,frame:f})}}return{elements:(t!==""?i.filter(f=>{let u=f.element;if(k(u,t,n))return!0;for(let d of i)if(d.element!==u&&u.contains(d.element))return!1;return!0}):i).map(f=>{let u=S(f.element),c=f.element.tagName.toLowerCase(),d=A(f.element);return f.frame.isMainFrame?{element:f.element,boundingBox:u,tagName:c,frameIndex:f.frame.frameIndex,isHidden:d}:{boundingBox:u,tagName:c,frameIndex:f.frame.frameIndex,isHidden:d}})}}function L(e){if(e.parentElement)return e.parentElement;try{let t=e.getRootNode();if(t&&t.host)return t.host}catch(t){}return null}function q(e){let t=L(e);if(!t)return[];if(t.shadowRoot)try{return Array.from(t.shadowRoot.children)}catch(n){return[]}return Array.from(t.children)}function he(e,t){let n=L(e);for(;n;){if(p(n,t))return n;n=L(n)}let o=e.children||[];for(let s of o)if(p(s,t))return s;let r=q(e);for(let s of r)if(s!==e&&p(s,t))return s;for(let s of r){if(s===e)continue;let l=y(s);for(let a=0;a<l.length;a++)if(p(l[a],t))return l[a]}let i=e.parentElement;for(;i;){let s=q(i);for(let l of s)if(l!==i){if(p(l,t))return l;let a=y(l);for(let f=0;f<a.length;f++)if(p(a[f],t))return a[f]}i=i.parentElement}return null}function ge(e,t,n=!1,o=null,r=null){let i=e!=null&&e!=="",s=t!=null&&t!=="";if(i&&!s)return z(e,o,r);if(!i&&s)return W(t,n,o);if(i){if(typeof e!="string")throw new TypeError(`elementType must be a string, got ${typeof e}`);if(!g[e]){let c=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(r&&r.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(c),{elements:[]}}}if(s&&typeof t!="string")throw new TypeError(`attributeText must be a string, got ${typeof t}`);let l=[],a=T(window);for(let c of a){let d=y(o||c.document);for(let m=0;m<d.length;m++){let h=d[m];i&&!p(h,e)||s&&!N(h,t,n)||l.push({element:h,frame:c})}}if(l.length===0&&i&&s){let c=[];for(let m of a){let h=y(o||m.document);for(let O=0;O<h.length;O++){let M=h[O];N(M,t,n)&&k(M,t,n)&&c.push({element:M,frame:m})}}let d=new Set;for(let m of c){let h=he(m.element,e);h&&!d.has(h)&&(d.add(h),l.push({element:h,frame:m.frame}))}}return{elements:(s?l.filter(c=>{let d=c.element;if(k(d,t,n))return!0;for(let h of l)if(h.element!==d&&d.contains(h.element))return!1;return!0}):l).map(c=>{let d=S(c.element),m=c.element.tagName.toLowerCase(),h=A(c.element);return c.frame.isMainFrame?{element:c.element,boundingBox:d,tagName:m,frameIndex:c.frame.frameIndex,isHidden:h}:{boundingBox:d,tagName:m,frameIndex:c.frame.frameIndex,isHidden:h}})}}function Y(e){return e?e&&e.elements&&Array.isArray(e.elements)?e.elements:Array.isArray(e)?e:[e]:[]}function pe(e,t="red",n=3){let o=Y(e);for(let r=0;r<o.length;r++){let i=o[r],s=i.element?i.element:i;s&&s.style&&(s.style.outline=`${n}px solid ${t}`,s.style.outlineOffset="2px",s.style.boxShadow="0 0 0 2px rgba(255, 255, 255, 0.8)",s.classList.add("elementfinder-highlighted"))}}function ye(e){let t=Y(e);for(let n=0;n<t.length;n++){let o=t[n],r=o.element?o.element:o;r&&r.style&&(r.style.outline="",r.style.outlineOffset="",r.style.boxShadow="",r.classList.remove("elementfinder-highlighted"))}}var x=[];function be(){let e=new Map,t=y();for(let r of t)r&&r.style&&r.style.animationPlayState!=="paused"&&(e.set(r,{animationPlayState:r.style.animationPlayState,transitionProperty:r.style.transitionProperty,webkitAnimationPlayState:r.style.webkitAnimationPlayState,webkitTransitionProperty:r.style.webkitTransitionProperty}),r.style.animationPlayState="paused",r.style.transitionProperty="none",r.style.webkitAnimationPlayState="paused",r.style.webkitTransitionProperty="none");let n=document.getElementById("elementfinder-animation-pause");n||(n=document.createElement("style"),n.id="elementfinder-animation-pause",n.textContent=`
|
|
2
2
|
*, *::before, *::after {
|
|
3
3
|
animation-play-state: paused !important;
|
|
4
4
|
transition-property: none !important;
|
|
@@ -12,4 +12,4 @@ var ElementFinder=(()=>{var D=Object.defineProperty;var Y=Object.getOwnPropertyD
|
|
|
12
12
|
transition-duration: 0s !important;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
`,document.head.appendChild(n));let o={originalStyles:e,pausedCount:e.size};return
|
|
15
|
+
`,document.head.appendChild(n));let o={originalStyles:e,pausedCount:e.size};return x.push(o),o}function we(e){if(e){let n=x.indexOf(e);if(n===-1)return;x.splice(n,1)}else{if(x.length===0)return;e=x.pop()}let t=e.originalStyles;if(t)for(let[n,o]of t)n&&n.style&&(n.style.animationPlayState=o.animationPlayState||"",n.style.transitionProperty=o.transitionProperty||"",n.style.webkitAnimationPlayState=o.webkitAnimationPlayState||"",n.style.webkitTransitionProperty=o.webkitTransitionProperty||"");if(x.length===0){let n=document.getElementById("elementfinder-animation-pause");n&&n.remove()}}function Ee(){return Object.keys(g)}function xe(){return[...E]}return v(Te);})();
|
package/package.json
CHANGED
package/src/element-finder.js
CHANGED
|
@@ -1017,16 +1017,17 @@ function hasOwnMatch(el, value, exact = false) {
|
|
|
1017
1017
|
|
|
1018
1018
|
/**
|
|
1019
1019
|
* Gets counts of elements by semantic type and visibility on the current screen.
|
|
1020
|
-
*
|
|
1021
|
-
* If no type is provided, returns counts for all defined
|
|
1020
|
+
* Includes the generic `element` type by default.
|
|
1021
|
+
* If no type is provided, returns counts for all defined types.
|
|
1022
1022
|
* Searches all frames (main document + iframes) by default.
|
|
1023
|
-
* @param {string|null|undefined} [type=null] - Element type to count. If null/undefined, count all defined
|
|
1023
|
+
* @param {string|null|undefined} [type=null] - Element type to count. If null/undefined, count all defined types.
|
|
1024
1024
|
* @param {Element|null} [parent=null] - Parent element to count within
|
|
1025
1025
|
* @param {{failOnUnknownType?: boolean}} [options=null] - Search options
|
|
1026
1026
|
* @returns {Object.<string, {visible: number, hidden: number, total: number}>} Counts keyed by semantic element type, or `{ [type]: { visible, hidden, total } }` when type is provided
|
|
1027
1027
|
*/
|
|
1028
1028
|
export function getElementCounts(type = null, parent = null, options = null) {
|
|
1029
1029
|
const hasType = type !== null && type !== undefined;
|
|
1030
|
+
const targetTypes = hasType ? [type] : Object.keys(ELEMENT_DEFINITIONS);
|
|
1030
1031
|
|
|
1031
1032
|
if (hasType) {
|
|
1032
1033
|
if (typeof type !== 'string') {
|
|
@@ -1043,30 +1044,23 @@ export function getElementCounts(type = null, parent = null, options = null) {
|
|
|
1043
1044
|
}
|
|
1044
1045
|
|
|
1045
1046
|
const counts = {};
|
|
1046
|
-
const targetTypes = hasType ? [type] : Object.keys(ELEMENT_DEFINITIONS).filter((item) => item !== 'element');
|
|
1047
|
-
|
|
1048
1047
|
for (let i = 0; i < targetTypes.length; i++) {
|
|
1049
1048
|
counts[targetTypes[i]] = { visible: 0, hidden: 0, total: 0 };
|
|
1050
1049
|
}
|
|
1051
1050
|
|
|
1052
|
-
|
|
1051
|
+
// Use findElements() as the source of truth so counts match its returned
|
|
1052
|
+
// element set, including its filtering behavior for each semantic type.
|
|
1053
|
+
for (let i = 0; i < targetTypes.length; i++) {
|
|
1054
|
+
const targetType = targetTypes[i];
|
|
1055
|
+
const result = findElements(targetType, null, false, parent, options);
|
|
1056
|
+
const typeCounts = counts[targetType];
|
|
1053
1057
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1058
|
+
for (let j = 0; j < result.elements.length; j++) {
|
|
1059
|
+
const item = result.elements[j];
|
|
1060
|
+
const bucket = item.isHidden ? 'hidden' : 'visible';
|
|
1057
1061
|
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
// Check against all target types and increment count for each match
|
|
1062
|
-
for (let k = 0; k < targetTypes.length; k++) {
|
|
1063
|
-
const targetType = targetTypes[k];
|
|
1064
|
-
if (matchesType(el, targetType)) {
|
|
1065
|
-
const bucket = isHidden(el) ? 'hidden' : 'visible';
|
|
1066
|
-
counts[targetType][bucket] += 1;
|
|
1067
|
-
counts[targetType].total += 1;
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1062
|
+
typeCounts[bucket] += 1;
|
|
1063
|
+
typeCounts.total += 1;
|
|
1070
1064
|
}
|
|
1071
1065
|
}
|
|
1072
1066
|
|