async function queryAXTree(e,r,t,a){const{nodes:n}=await e.send("Accessibility.queryAXTree",{objectId:r._remoteObject.objectId,accessibleName:t,role:a});return n.filter((e=>"text"!==e.role.value))}function parseAriaSelector(e){const r=e=>e.replace(/ +/g," ").trim(),t=new Set(["name","role"]),a={},n=e.replace(/\[\s*(?<attribute>\w+)\s*=\s*"(?<value>\\.|[^"\\]*)"\s*\]/,((e,n,o)=>{if(n=n.trim(),!t.has(n))throw new Error('Unkown aria attribute "${groups.attribute}" in selector');return a[n]=r(o),""}));return n&&!a.name&&(a.name=r(n)),a}const queryOne=async(e,r)=>{const t=e.executionContext(),{name:a,role:n}=parseAriaSelector(r),o=await queryAXTree(t._client,e,a,n);return o.length<1?null:t._adoptBackendNodeId(o[0].backendDOMNodeId)},waitFor=async(e,r,t)=>{const a={name:"ariaQuerySelector",pptrFunction:async r=>{const t=await e._document();return await queryOne(t,r)}};return e.waitForSelectorInPage(((e,r)=>globalThis.ariaQuerySelector(r)),r,t,a)},queryAll=async(e,r)=>{const t=e.executionContext(),{name:a,role:n}=parseAriaSelector(r),o=await queryAXTree(t._client,e,a,n);return Promise.all(o.map((e=>t._adoptBackendNodeId(e.backendDOMNodeId))))},queryAllArray=async(e,r)=>{const t=await queryAll(e,r);return e.executionContext().evaluateHandle(((...e)=>e),...t)};export const ariaHandler={queryOne:queryOne,waitFor:waitFor,queryAll:queryAll,queryAllArray:queryAllArray};