text: import*as SDK from"../sdk/sdk.js";export const fullQualifiedSelector=function(e,t){return e.nodeType()!==Node.ELEMENT_NODE?e.localName()||e.nodeName().toLowerCase():cssPath(e,t)};export const cssPath=function(e,t){if(e.nodeType()!==Node.ELEMENT_NODE)return"";const o=[];let n=e;for(;n;){const r=_cssPathStep(n,!!t,n===e);if(!r)break;if(o.push(r),r.optimized)break;n=n.parentNode}return o.reverse(),o.join(" > ")};export const canGetJSPath=function(e){let t=e;for(;t;){if(t.ancestorShadowRoot()&&t.ancestorShadowRoot().shadowRootType()!==SDK.DOMModel.DOMNode.ShadowRootTypes.Open)return!1;t=t.ancestorShadowHost()}return!0};export const jsPath=function(e,t){if(e.nodeType()!==Node.ELEMENT_NODE)return"";const o=[];let n=e;for(;n;)o.push(cssPath(n,t)),n=n.ancestorShadowHost();o.reverse();let r="";for(let e=0;e<o.length;++e){const t=JSON.stringify(o[e]);r+=e?`.shadowRoot.querySelector(${t})`:`document.querySelector(${t})`}return r};export const _cssPathStep=function(e,t,o){if(e.nodeType()!==Node.ELEMENT_NODE)return null;const n=e.getAttribute("id");if(t){if(n)return new Step(c(n),!0);const t=e.nodeName().toLowerCase();if("body"===t||"head"===t||"html"===t)return new Step(e.nodeNameInCorrectCase(),!0)}const r=e.nodeNameInCorrectCase();if(n)return new Step(r+c(n),!0);const s=e.parentNode;if(!s||s.nodeType()===Node.DOCUMENT_NODE)return new Step(r,!0);function i(e){const t=e.getAttribute("class");return t?t.split(/\s+/g).filter(Boolean).map((function(e){return"$"+e})):[]}function c(e){return"#"+CSS.escape(e)}const a=i(e);let d=!1,N=!1,u=-1,p=-1;const f=s.children();for(let t=0;(-1===u||!N)&&t<f.length;++t){const o=f[t];if(o.nodeType()!==Node.ELEMENT_NODE)continue;if(p+=1,o===e){u=p;continue}if(N)continue;if(o.nodeNameInCorrectCase()!==r)continue;d=!0;const n=new Set(a);if(!n.size){N=!0;continue}const s=i(o);for(let e=0;e<s.length;++e){const t=s[e];if(n.has(t)&&(n.delete(t),!n.size)){N=!0;break}}}let l=r;if(o&&"input"===r.toLowerCase()&&e.getAttribute("type")&&!e.getAttribute("id")&&!e.getAttribute("class")&&(l+="[type="+CSS.escape(e.getAttribute("type"))+"]"),N)l+=":nth-child("+(u+1)+")";else if(d)for(const e of a)l+="."+CSS.escape(e.slice(1));return new Step(l,!1)};export const xPath=function(e,t){if(e.nodeType()===Node.DOCUMENT_NODE)return"/";const o=[];let n=e;for(;n;){const e=_xPathValue(n,t);if(!e)break;if(o.push(e),e.optimized)break;n=n.parentNode}return o.reverse(),(o.length&&o[0].optimized?"":"/")+o.join("/")};export const _xPathValue=function(e,t){let o;const n=_xPathIndex(e);if(-1===n)return null;switch(e.nodeType()){case Node.ELEMENT_NODE:if(t&&e.getAttribute("id"))return new Step('//*[@id="'+e.getAttribute("id")+'"]',!0);o=e.localName();break;case Node.ATTRIBUTE_NODE:o="@"+e.nodeName();break;case Node.TEXT_NODE:case Node.CDATA_SECTION_NODE:o="text()";break;case Node.PROCESSING_INSTRUCTION_NODE:o="processing-instruction()";break;case Node.COMMENT_NODE:o="comment()";break;case Node.DOCUMENT_NODE:default:o=""}return n>0&&(o+="["+n+"]"),new Step(o,e.nodeType()===Node.DOCUMENT_NODE)};export const _xPathIndex=function(e){function t(e,t){if(e===t)return!0;if(e.nodeType()===Node.ELEMENT_NODE&&t.nodeType()===Node.ELEMENT_NODE)return e.localName()===t.localName();if(e.nodeType()===t.nodeType())return!0;return(e.nodeType()===Node.CDATA_SECTION_NODE?Node.TEXT_NODE:e.nodeType())===(t.nodeType()===Node.CDATA_SECTION_NODE?Node.TEXT_NODE:t.nodeType())}const o=e.parentNode?e.parentNode.children():null;if(!o)return 0;let n;for(let r=0;r<o.length;++r)if(t(e,o[r])&&o[r]!==e){n=!0;break}if(!n)return 0;let r=1;for(let n=0;n<o.length;++n)if(t(e,o[n])){if(o[n]===e)return r;++r}return-1};export class Step{constructor(e,t){this.value=e,this.optimized=t||!1}toString(){return this.value}}