@whenessel/seql-js 1.6.1 → 1.7.0

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.
@@ -1,11 +1,11 @@
1
- (function(p,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(p=typeof globalThis<"u"?globalThis:p||self,F(p.SeqlJS={}))})(this,(function(p){"use strict";const j={ANCHOR:.4,PATH:.3,TARGET:.2,UNIQUENESS:.1},I={SEMANTIC_TAG:.5,ROLE:.3,ARIA_LABEL:.1,STABLE_ID:.25,TEST_MARKER:.05,DEPTH_PENALTY_THRESHOLD:5,DEPTH_PENALTY_FACTOR:.05,DEGRADED_SCORE:.3},Dt={MIN_CONFIDENCE_FOR_SKIP:.7},V=["form","main","nav","section","article","footer","header"],Q=["form","navigation","main","region","contentinfo","complementary","banner","search"],at=["article","aside","details","figcaption","figure","footer","header","main","mark","nav","section","summary","time","button","datalist","fieldset","form","input","label","legend","meter","optgroup","option","output","progress","select","textarea","a","audio","video","canvas","dialog","menu","blockquote","dd","dl","dt","hr","li","ol","ul","p","pre","h1","h2","h3","h4","h5","h6","caption","col","colgroup","table","tbody","td","tfoot","th","thead","tr","svg","path","circle","rect","line","polyline","polygon","ellipse","g","text","use"],Rt=["rect","path","circle","line","polyline","polygon","ellipse","g","text","use","defs","clipPath","mask"],Mt=["aria-label","aria-labelledby","aria-describedby","name","type","data-testid","data-qa","data-test","href","title","placeholder","alt"],w={"data-testid":100,"data-qa":99,"data-cy":98,"data-test":97,"data-test-id":96,"aria-label":90,"aria-labelledby":85,"aria-describedby":80,name:75,href:70,src:70,type:65,role:60,alt:55,title:50,for:45,placeholder:40,"data-*":30,"aria-*":25},Y=new Set(["id","class","style","xmlns","tabindex","contenteditable"]),it={maxPathDepth:10,enableSvgFingerprint:!0,confidenceThreshold:0,fallbackToBody:!0,includeUtilityClasses:!1,source:"dom-dsl"},ot={strictMode:!1,enableFallback:!0,maxCandidates:20,matchUrlsByPathOnly:!0};function L(r){if(/^[a-z]+-\d+$/i.test(r)||/^[a-z]+(-[a-z]+)+-\d+$/i.test(r)||/^[a-z]+(_[a-z]+)*_\d+$/i.test(r)||/^\d+$/.test(r)||/^:[a-z0-9]+:$/i.test(r)||/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(r))return!0;if(/^[a-z]{1,3}[A-Za-z0-9]{8,}$/.test(r)){const t=/\d/.test(r),e=/[A-Z]/.test(r),s=r.length>=20;if(t&&e||s)return!0}return!!(/^radix-/.test(r)||/^mui-\d+$/.test(r))}const X=new Set(["aria-labelledby","aria-describedby","aria-controls","aria-owns","aria-activedescendant","for","form","list","headers","aria-details","aria-errormessage","aria-flowto"]);function Z(r){return r.trim().split(/\s+/).some(e=>L(e))}class ct{constructor(t,e){this.maxDepth=t.maxPathDepth??10,this.cache=e}findAnchor(t){if(this.cache){const c=this.cache.getAnchor(t);if(c!==void 0)return c}const e=t.tagName.toLowerCase(),s=t.ownerDocument;if(e==="html"){const c={element:t,score:1,tier:"A",depth:0};return this.cacheResult(t,c),c}if(e==="head"||this.isInsideHead(t)){const c=s?.documentElement;if(c){const u={element:c,score:1,tier:"A",depth:0};return this.cacheResult(t,u),u}}if(e==="body"){const c=s?.documentElement;if(c){const u={element:c,score:1,tier:"A",depth:0};return this.cacheResult(t,u),u}}let n=t.parentElement,a=0,i=null;for(;n&&a<this.maxDepth;){if(n.tagName.toLowerCase()==="body")return i||{element:n,score:I.DEGRADED_SCORE,tier:"C",depth:a};const c=this.scoreAnchor(n);if(c>0){const u=this.applyDepthPenalty(c,a),d=this.getTier(n),l={element:n,score:u,tier:d,depth:a};if(d==="A")return l;(!i||u>i.score)&&(i=l)}n=n.parentElement,a++}const o=i;return this.cache&&this.cache.setAnchor(t,o),o}scoreAnchor(t){let e=0;const s=t.tagName.toLowerCase();V.includes(s)&&(e+=I.SEMANTIC_TAG);const n=t.getAttribute("role");n&&Q.includes(n)&&(e+=I.ROLE),(t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby"))&&(e+=I.ARIA_LABEL);const a=t.id;return a&&!L(a)&&(e+=I.STABLE_ID),(t.hasAttribute("data-testid")||t.hasAttribute("data-qa")||t.hasAttribute("data-test"))&&(e+=I.TEST_MARKER),Math.min(e,1)}applyDepthPenalty(t,e){if(e<=I.DEPTH_PENALTY_THRESHOLD)return t;const s=(e-I.DEPTH_PENALTY_THRESHOLD)*I.DEPTH_PENALTY_FACTOR;return Math.max(0,t-s)}getTier(t){const e=t.tagName.toLowerCase();if(V.includes(e))return"A";const s=t.getAttribute("role");return s&&Q.includes(s)?"B":"C"}isInsideHead(t){let e=t.parentElement;for(;e;){const s=e.tagName.toLowerCase();if(s==="head")return!0;if(s==="body")return!1;e=e.parentElement}return!1}cacheResult(t,e){this.cache&&this.cache.setAnchor(t,e)}}const Pt=[/^css-[a-z0-9]+$/i,/^sc-[a-z0-9]+-\d+$/i,/^[a-z]{5,8}$/i,/^Mui[A-Z]\w+-\w+-\w+/,/^makeStyles-\w+-\d+$/,/^jss\d+$/,/^(emotion|linaria)-[a-z0-9]+/i,/^(chakra|tw-|ant-)[a-z0-9]+-\w+/i,/-[a-f0-9]{6,}$/i,/^_[a-z0-9]{5,}$/i,/\d{5,}/],Lt=[/^\[/,/^(first|last|odd|even|only|first-of-type|last-of-type|only-of-type):/,/^(hover|focus|active|disabled|enabled|checked|indeterminate|default|required|valid|invalid|in-range|out-of-range|placeholder-shown|autofill|read-only):/,/^(focus-within|focus-visible|visited|target|open):/,/^(sm|md|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl):/,/^dark:/,/^(rtl|ltr):/,/^(group|peer)(-hover|-focus|-active)?:/,/^[a-z][a-z-]*:/,/\/([\d.]+|full|auto|screen)$/,/^(inset|top|right|bottom|left)(-|$)/,/^(flex|inline-flex|grid|block|inline|inline-block|hidden|visible)$/,/^(absolute|relative|fixed|sticky|static)$/,/^(items|justify|content|self|place)-/,/^flex-(row|col|wrap|nowrap|1|auto|initial|none)/,/^grid-(cols|rows|flow)/,/^(gap|space)-/,/^[mp][trblxy]?-(\d+|auto|px)$/,/^-[mp][trblxy]?-\d+$/,/^-(top|right|bottom|left|inset)-\d+$/,/^-z-\d+$/,/^-space-[xy]-\d+$/,/^-translate-[xy]-\d+$/,/^-rotate-\d+$/,/^-scale-\d+$/,/^-skew-[xy]-\d+$/,/^(w|h|min-w|min-h|max-w|max-h|size)-/,/^text-(center|left|right|justify|start|end|xs|sm|base|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl|8xl|9xl)$/,/^text-(uppercase|lowercase|capitalize|normal-case|underline|line-through|no-underline)$/,/^text-(truncate|ellipsis|clip)$/,/^(bg|border|ring|shadow|outline)-/,/^rounded(-|$)/,/^(font|leading|tracking|whitespace|break|truncate)-/,/^(uppercase|lowercase|capitalize|normal-case)$/,/^(transform|transition|duration|delay|ease|animate)-/,/^(scale|rotate|translate|skew)-/,/^transform$/,/^backdrop-blur-/,/^motion-/,/^(fade|slide|zoom|bounce|pulse|spin|ping)-/,/^(overflow|overscroll|scroll)-/,/^object-(contain|cover|fill|none|scale-down)$/,/^(cursor|pointer-events|select|resize)-/,/^(opacity|z)-/,/^(visible|invisible|collapse)$/,/^d-(none|inline|inline-block|block|grid|table|flex)$/,/^(float|clearfix|text)-(left|right|center|justify|start|end)$/,/^(m|p)[trblxy]?-[0-5]$/,/^(w|h)-(25|50|75|100|auto)$/,/^btn-(sm|lg|block)$/,/^text-(muted|primary|success|danger|warning|info|light|dark|white)$/,/^bg-(primary|secondary|success|danger|warning|info|light|dark|white|transparent)$/,/^border(-top|-bottom|-left|-right)?(-0)?$/,/^rounded(-top|-bottom|-left|-right|-circle|-pill|-0)?$/,/^shadow(-sm|-lg|-none)?$/,/^(align|justify|order|flex)-(start|end|center|between|around|fill|grow|shrink)$/,/^col(-sm|-md|-lg|-xl)?(-\d+|-auto)?$/,/^row(-cols)?(-\d+)?$/,/^g[xy]?-[0-5]$/,/^(show|hide|invisible|visible)$/,/^(position|top|bottom|start|end)-(static|relative|absolute|fixed|sticky|-\d+)$/,/^(row|col)$/,/^clearfix$/,/^pull-(left|right)$/,/^float-(left|right|none)$/],Ht=[/^(nav|menu|header|footer|sidebar|topbar|navbar|breadcrumb)/,/(navigation|dropdown|megamenu)$/,/^(btn|button|link|card|modal|dialog|popup|tooltip|alert|badge|chip)/,/^(form|input|select|checkbox|radio|textarea|label|fieldset)/,/^(table|list|item|row|cell|column)/,/^(accordion|tab|carousel|slider|gallery)/,/^(content|main|article|post|comment|title|subtitle|description|caption)/,/^(hero|banner|jumbotron|section|wrapper|box)/,/^(user|profile|avatar|account|auth)/,/^(product|item|price|cart|checkout|order)/,/^(page|layout|panel|widget|block)/,/-(primary|secondary|tertiary|success|error|warning|info|danger)$/,/-(active|inactive|disabled|enabled|selected|highlighted|focused)$/,/-(open|closed|expanded|collapsed|visible|hidden)$/,/-(large|medium|small|tiny|xs|sm|md|lg|xl)$/,/^(submit|cancel|close|delete|edit|save|back|next|prev|search)/,/^(loading|pending|complete|failed|draft|published)/];function k(r){return Pt.some(t=>t.test(r))}function q(r){return r.length<=2||/^\d/.test(r)?!0:Lt.some(t=>t.test(r))}function _t(r){return k(r)||q(r)?!1:Ht.some(t=>t.test(r))}function Ot(r){return!k(r)&&!q(r)}function P(r){return r.filter(t=>Ot(t))}function kt(r){if(k(r)||q(r))return 0;let t=.5;return _t(r)&&(t=.8),r.length<3?t*=.3:r.length<5&&(t*=.6),/\d/.test(r)&&(t*=.7),Math.min(t,1)}function lt(r){const t=[],e=[];for(const s of r)q(s)||k(s)?e.push(s):t.push(s);return{semantic:t,utility:e}}function K(r){return q(r)||k(r)}function qt(r){return kt(r)}const ht=r=>r.replace(/([#:.[\]@])/g,"\\$1");class ut{constructor(t,e){this.maxDepth=t.maxPathDepth??10,this.cache=e}buildPath(t,e,s){const n=t.tagName.toLowerCase(),a=e.tagName.toLowerCase();if(n==="html"&&(a==="head"||a==="body"))return{path:[],degraded:!1};if(n==="html"&&this.isInsideHead(e))return this.buildHeadPath(t,e,s);const i=[];let o=e.parentElement;for(;o&&o!==t&&i.length<this.maxDepth;)i.unshift(o),o=o.parentElement;const c=i.length>=this.maxDepth&&o!==t;if(!c&&o!==t)return console.warn("[PathBuilder] Target is not a descendant of anchor"),{path:[],degraded:!0,degradationReason:"target-not-descendant-of-anchor"};let u=this.filterNoise(i);return u=this.ensureUniqueness(i,u,t,e,s),{path:u.map(l=>{const h=l.parentElement;let g;if(h){const m=Array.from(h.children).indexOf(l);m!==-1&&(g=m+1)}return{tag:l.tagName.toLowerCase(),semantics:s.extract(l),score:s.scoreElement(l),nthChild:g}}),degraded:c,degradationReason:c?"path-depth-overflow":void 0}}buildPathNodes(t,e,s){return this.buildPath(t,e,s).path}ensureUniqueness(t,e,s,n,a){const i=this.buildTestSelector(s,e,n);try{const o=n.ownerDocument;if(!o)return e;let c;if(this.cache){const d=this.cache.getSelectorResults(i);d!==void 0?c=d:(c=Array.from(o.querySelectorAll(i)),this.cache.setSelectorResults(i,c))}else c=o.querySelectorAll(i);if(c.length<=1)return e;const u=t.filter(d=>!e.includes(d));for(const d of u){if(a.scoreElement(d)<Dt.MIN_CONFIDENCE_FOR_SKIP)continue;const h=this.insertNodeInOrder(e,d,t),g=this.buildTestSelector(s,h,n);try{let f;if(this.cache){const m=this.cache.getSelectorResults(g);m!==void 0?f=m:(f=Array.from(o.querySelectorAll(g)),this.cache.setSelectorResults(g,f))}else f=o.querySelectorAll(g);if(f.length===1)return h;f.length<c.length&&(e=h)}catch{}}return e}catch{return e}}insertNodeInOrder(t,e,s){const n=s.indexOf(e),a=[...t];let i=0;for(let o=0;o<a.length&&!(s.indexOf(a[o])>n);o++)i=o+1;return a.splice(i,0,e),a}buildTestSelector(t,e,s){const n=[];n.push(this.elementToSelector(t));for(const a of e)n.push(this.elementToSelector(a));return n.push(this.elementToSelector(s)),n.join(" ")}elementToSelector(t){let e=t.tagName.toLowerCase();t.id&&!L(t.id)&&(e+=`#${ht(t.id)}`);for(const s of Array.from(t.classList))K(s)||(e+=`.${ht(s)}`);return e}filterNoise(t){return t.filter(e=>this.shouldInclude(e))}shouldInclude(t){const e=t.tagName.toLowerCase();return at.includes(e)?!0:e==="div"||e==="span"?this.hasSemanticFeatures(t):!1}hasSemanticFeatures(t){if(t.hasAttribute("role"))return!0;for(const s of Array.from(t.attributes))if(s.name.startsWith("aria-"))return!0;if(t.classList.length>0){for(const s of Array.from(t.classList))if(!K(s))return!0}if(t.hasAttribute("data-testid")||t.hasAttribute("data-qa")||t.hasAttribute("data-test"))return!0;const e=t.id;return!!(e&&!L(e))}isInsideHead(t){let e=t.parentElement;for(;e;){const s=e.tagName.toLowerCase();if(s==="head")return!0;if(s==="body")return!1;e=e.parentElement}return!1}buildHeadPath(t,e,s){const n=[];let a=e.parentElement;for(;a&&a!==t;)n.unshift(a),a=a.parentElement;return a!==t?{path:[],degraded:!0,degradationReason:"target-not-descendant-of-html"}:n.findIndex(c=>c.tagName.toLowerCase()==="head")===-1?{path:[],degraded:!0,degradationReason:"head-not-found-in-path"}:{path:n.map(c=>{const u=c.parentElement;let d;if(u){const h=Array.from(u.children).indexOf(c);h!==-1&&(d=h+1)}return{tag:c.tagName.toLowerCase(),semantics:s.extract(c),score:s.scoreElement(c),nthChild:d}}),degraded:!1}}}function U(r){return r?r.trim().replace(/[\n\t\r]/g," ").replace(/\s+/g," "):""}const Ut={preserveQueryForAbsolute:!0,removeDynamicHashes:!0};function zt(r){return r?[/\d{5,}/,/[a-f0-9]{8,}/i,/(session|token|temp|random|timestamp|nonce|cache)/i,/^\d+$/,/^[a-f0-9-]{32,}$/i].some(e=>e.test(r)):!1}function Ft(r,t){if(!r)return r;const e=r.startsWith("http://")||r.startsWith("https://"),[s,n]=r.split("#"),[a,i]=s.split("?");let o=a;return e&&t.preserveQueryForAbsolute&&i&&(o+=`?${i}`),n&&(t.removeDynamicHashes&&zt(n)||(o+=`#${n}`)),o}function R(r,t,e={}){if(!t)return t;const s={...Ut,...e};return r==="href"||r==="src"?Ft(t,s):t}const jt=["role","aria-label","aria-labelledby","aria-describedby","aria-controls","aria-owns","aria-level","aria-posinset","aria-setsize","aria-haspopup"],Wt=["aria-selected","aria-checked","aria-pressed","aria-expanded","aria-hidden","aria-disabled","aria-current","aria-busy","aria-invalid","aria-grabbed","aria-live","aria-atomic"],Bt=["data-state","data-active","data-inactive","data-selected","data-open","data-closed","data-visible","data-hidden","data-disabled","data-enabled","data-loading","data-error","data-success","data-highlighted","data-focused","data-hover","data-orientation","data-theme"],Gt=["data-radix-","data-headlessui-","data-reach-","data-mui-","data-chakra-","data-mantine-","data-tw-"],Vt=["data-testid","data-test-id","data-test","data-cy","data-qa","data-automation-id","data-id","data-component","data-entity-id","data-product-id","data-user-id"],Qt=["data-ga","data-gtm","data-google","data-layer","data-event","data-yandex","data-ym","data-metrika","data-optimizely","data-vwo","data-optimize","data-hj","data-hotjar","data-fs","data-mouseflow","data-mf","data-smartlook","data-sl","data-fb","data-facebook","data-tt","data-li","data-track","data-tracking","data-click","data-impression","data-conversion","data-segment","data-analytics"],Yt=["data-category","data-action","data-label","data-value"],Xt=["id","name","type","placeholder","title","for","alt","href"],Zt=["disabled","checked","selected","hidden","readonly","required","value"],Kt=[/^radix-/,/^headlessui-/,/^mui-/,/:\w+:/];function Jt(r,t){return jt.includes(r)?!0:Wt.includes(r)||Bt.includes(r)||Gt.some(e=>r.startsWith(e))?!1:Vt.includes(r)?!0:Qt.some(e=>r.startsWith(e))||Yt.includes(r)?!1:r.startsWith("data-")&&r.endsWith("-id")?!0:r==="id"?!Kt.some(e=>e.test(t)):Xt.includes(r)?!0:Zt.includes(r)?!1:!!r.startsWith("data-")}class J{constructor(t,e){this.includeUtilityClasses=t.includeUtilityClasses??!1,this.cache=e}extract(t){if(this.cache){const i=this.cache.getSemantics(t);if(i!==void 0)return i}const e={},s=t.id;if(s&&!L(s)&&(e.id=s),t.classList.length>0){const i=Array.from(t.classList);if(this.includeUtilityClasses)e.classes=i;else{const{semantic:o}=lt(i);o.length>0&&(e.classes=o)}}const n=this.extractAttributes(t);Object.keys(n).length>0&&(e.attributes=n);const a=t.getAttribute("role");if(a&&(e.role=a),this.shouldExtractText(t)){const i=this.extractText(t);i&&(e.text=i)}return this.cache&&this.cache.setSemantics(t,e),e}scoreElement(t){let e=.5;const s=this.extract(t);return s.id&&(e+=.15),s.classes&&s.classes.length>0&&(e+=.1),s.attributes&&Object.keys(s.attributes).length>0&&(e+=.1),s.role&&(e+=.1),s.text&&(e+=.05),Math.min(e,1)}shouldIgnoreAttribute(t){return!!(Y.has(t)||t.startsWith("on")||t.startsWith("ng-")||t.startsWith("_ng")||t.startsWith("data-reactid")||t.startsWith("data-react")||t.startsWith("data-v-"))}getAttributePriority(t){return w[t]!==void 0?w[t]:t.startsWith("data-")?w["data-*"]:t.startsWith("aria-")?w["aria-*"]:0}isDynamicValue(t){return[/^[a-f0-9]{32,}$/i,/^\d{10,}$/,/^(undefined|null|\[object)/,/^{{.*}}$/].some(s=>s.test(t))}extractAttributes(t){const e={};for(const s of Array.from(t.attributes)){const n=s.name;if(this.shouldIgnoreAttribute(n)||!Jt(n,s.value)||X.has(n)&&Z(s.value)||this.getAttributePriority(n)===0)continue;const i=n==="href"||n==="src"?R(n,s.value):s.value;!i||i.trim()===""||this.isDynamicValue(i)||(e[n]=i)}return e}extractText(t){const e=this.getDirectTextContent(t);if(!e)return null;const s=U(e);if(!s)return null;const n=100,a=e.length>n?e.slice(0,n)+"...":e,i=s.length>n?s.slice(0,n)+"...":s;return{raw:a,normalized:i}}getDirectTextContent(t){const e=[];for(const s of Array.from(t.childNodes))if(s.nodeType===Node.TEXT_NODE&&s.textContent){const n=s.textContent.trim();n&&e.push(n)}return e.length>0?e.join(" "):t.textContent??null}shouldExtractText(t){const e=t.tagName.toLowerCase();return["button","a","label","h1","h2","h3","h4","h5","h6","p","span","li","th","td","dt","dd","legend","figcaption","summary"].includes(e)}}class dt{fingerprint(t){const e=t.tagName.toLowerCase(),s=this.getShape(e),n={shape:s,hasAnimation:this.hasAnimation(t)};if(s==="path"){const o=t.getAttribute("d");o&&(n.dHash=this.computePathHash(o))}else["circle","rect","ellipse","line"].includes(s)&&(n.geomHash=this.computeGeomHash(t,s));const a=t.getAttribute("role");a&&(n.role=a);const i=t.querySelector("title");return i?.textContent&&(n.titleText=i.textContent.trim()),n}computePathHash(t){const e=this.normalizePathData(t);return this.simpleHash(e)}getShape(t){return["path","circle","rect","line","polyline","polygon","ellipse","g","text","use","svg"].find(s=>s===t)??"path"}normalizePathData(t){return(t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi)??[]).slice(0,5).map(n=>n.trim().replace(/(-?\d+\.?\d*)/g,a=>parseFloat(a).toFixed(1))).join(" ")}computeGeomHash(t,e){const s=[];switch(e){case"circle":s.push(`r=${t.getAttribute("r")??"0"}`);break;case"rect":{const n=parseFloat(t.getAttribute("width")??"0"),a=parseFloat(t.getAttribute("height")??"0");n>0&&a>0&&s.push(`ratio=${(n/a).toFixed(2)}`)}break;case"ellipse":{const n=parseFloat(t.getAttribute("rx")??"0"),a=parseFloat(t.getAttribute("ry")??"0");n>0&&a>0&&s.push(`ratio=${(n/a).toFixed(2)}`)}break;case"line":{const n=parseFloat(t.getAttribute("x1")??"0"),a=parseFloat(t.getAttribute("y1")??"0"),i=parseFloat(t.getAttribute("x2")??"0"),o=parseFloat(t.getAttribute("y2")??"0"),c=Math.atan2(o-a,i-n);s.push(`angle=${c.toFixed(2)}`)}break}return this.simpleHash(s.join(";"))}hasAnimation(t){if(t.querySelector("animate, animateTransform, animateMotion"))return!0;const e=t.ownerDocument;if(e?.defaultView)try{const s=e.defaultView.getComputedStyle(t);if(s.animationName!=="none"||s.transitionProperty!=="all"&&s.transitionProperty!=="none")return!0}catch{}return!1}simpleHash(t){let e=0;for(let s=0;s<t.length;s++){const n=t.charCodeAt(s);e=(e<<5)-e+n,e=e&e}return Math.abs(e).toString(16).padStart(8,"0")}}function ft(r,t=0){const e=r.anchor.score,s=r.path.length>0?r.path.reduce((o,c)=>o+c.score,0)/r.path.length:.5,n=r.target.score,a=e*j.ANCHOR+s*j.PATH+n*j.TARGET+t*j.UNIQUENESS,i=r.anchor.degraded?.2:0;return Math.max(0,Math.min(1,a-i))}function te(r,t,e){let s=.5;return t&&(s+=.2),e&&(s+=.15),s+=Math.min(r*.05,.15),Math.min(s,1)}class ee{constructor(t){this.cache=new Map,this.maxSize=t}get(t){const e=this.cache.get(t);if(e!==void 0)return this.cache.delete(t),this.cache.set(t,e),e}set(t,e){if(this.cache.has(t))this.cache.delete(t);else if(this.cache.size>=this.maxSize){const s=this.cache.keys().next().value;s!==void 0&&this.cache.delete(s)}this.cache.set(t,e)}has(t){return this.cache.has(t)}delete(t){this.cache.delete(t)}clear(){this.cache.clear()}get size(){return this.cache.size}}class gt{constructor(t={}){this.eidCache=new WeakMap,this.selectorResultCache=new ee(t.maxSelectorCacheSize??1e3),this.anchorCache=new WeakMap,this.semanticsCache=new WeakMap,this.stats={eidHits:0,eidMisses:0,selectorHits:0,selectorMisses:0,anchorHits:0,anchorMisses:0,semanticsHits:0,semanticsMisses:0,selectorCacheSize:0,maxSelectorCacheSize:t.maxSelectorCacheSize??1e3}}getEID(t){const e=this.eidCache.get(t);if(e!==void 0)return this.stats.eidHits++,e;this.stats.eidMisses++}setEID(t,e){this.eidCache.set(t,e)}getSelectorResults(t){const e=this.selectorResultCache.get(t);if(e!==void 0)return this.stats.selectorHits++,this.stats.selectorCacheSize=this.selectorResultCache.size,e;this.stats.selectorMisses++,this.stats.selectorCacheSize=this.selectorResultCache.size}setSelectorResults(t,e){this.selectorResultCache.set(t,e),this.stats.selectorCacheSize=this.selectorResultCache.size}getAnchor(t){if(this.anchorCache.has(t))return this.stats.anchorHits++,this.anchorCache.get(t);this.stats.anchorMisses++}setAnchor(t,e){this.anchorCache.set(t,e)}getSemantics(t){const e=this.semanticsCache.get(t);if(e!==void 0)return this.stats.semanticsHits++,e;this.stats.semanticsMisses++}setSemantics(t,e){this.semanticsCache.set(t,e)}clear(){this.selectorResultCache.clear(),this.stats.selectorCacheSize=0,this.stats={eidHits:0,eidMisses:0,selectorHits:0,selectorMisses:0,anchorHits:0,anchorMisses:0,semanticsHits:0,semanticsMisses:0,selectorCacheSize:0,maxSelectorCacheSize:this.stats.maxSelectorCacheSize}}invalidateElement(t){}invalidateSelector(t){this.selectorResultCache.delete(t),this.stats.selectorCacheSize=this.selectorResultCache.size}getStats(){return{...this.stats,selectorCacheSize:this.selectorResultCache.size}}getEIDHitRate(){const t=this.stats.eidHits+this.stats.eidMisses;return t>0?this.stats.eidHits/t:0}getSelectorHitRate(){const t=this.stats.selectorHits+this.stats.selectorMisses;return t>0?this.stats.selectorHits/t:0}getAnchorHitRate(){const t=this.stats.anchorHits+this.stats.anchorMisses;return t>0?this.stats.anchorHits/t:0}getSemanticsHitRate(){const t=this.stats.semanticsHits+this.stats.semanticsMisses;return t>0?this.stats.semanticsHits/t:0}getOverallHitRate(){const t=this.stats.eidHits+this.stats.selectorHits+this.stats.anchorHits+this.stats.semanticsHits,e=this.stats.eidMisses+this.stats.selectorMisses+this.stats.anchorMisses+this.stats.semanticsMisses,s=t+e;return s>0?t/s:0}}function mt(r){return new gt(r)}let W=null;function B(){return W||(W=mt()),W}function se(){W=null}function H(r){if(r.ownerDocument)return r.ownerDocument;let t=r;for(;t;){if(t.nodeType===9)return t;t=t.parentNode}throw new Error(`Element does not have an ownerDocument. This typically means:
1
+ (function(b,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(b=typeof globalThis<"u"?globalThis:b||self,j(b.SeqlJS={}))})(this,(function(b){"use strict";const W={ANCHOR:.4,PATH:.3,TARGET:.2,UNIQUENESS:.1},N={SEMANTIC_TAG:.5,ROLE:.3,ARIA_LABEL:.1,STABLE_ID:.25,TEST_MARKER:.05,DEPTH_PENALTY_THRESHOLD:5,DEPTH_PENALTY_FACTOR:.05,DEGRADED_SCORE:.3},Lt={MIN_CONFIDENCE_FOR_SKIP:.7},Q=["form","main","nav","section","article","footer","header"],Y=["form","navigation","main","region","contentinfo","complementary","banner","search"],ot=["article","aside","details","figcaption","figure","footer","header","main","mark","nav","section","summary","time","button","datalist","fieldset","form","input","label","legend","meter","optgroup","option","output","progress","select","textarea","a","audio","video","canvas","dialog","menu","blockquote","dd","dl","dt","hr","li","ol","ul","p","pre","h1","h2","h3","h4","h5","h6","caption","col","colgroup","table","tbody","td","tfoot","th","thead","tr","svg","path","circle","rect","line","polyline","polygon","ellipse","g","text","use"],Pt=["rect","path","circle","line","polyline","polygon","ellipse","g","text","use","defs","clipPath","mask"],_t=["aria-label","aria-labelledby","aria-describedby","name","type","data-testid","data-qa","data-test","href","title","placeholder","alt"],v={"data-testid":100,"data-qa":99,"data-cy":98,"data-test":97,"data-test-id":96,"aria-label":90,"aria-labelledby":85,"aria-describedby":80,name:75,href:70,src:70,type:65,role:60,alt:55,title:50,for:45,placeholder:40,"data-*":30,"aria-*":25},X=new Set(["id","class","style","xmlns","tabindex","contenteditable"]),ct={maxPathDepth:10,enableSvgFingerprint:!0,confidenceThreshold:0,fallbackToBody:!0,includeUtilityClasses:!1,source:"dom-dsl"},lt={strictMode:!1,enableFallback:!0,maxCandidates:20,matchUrlsByPathOnly:!0};function P(r){if(/^[a-z]+-\d+$/i.test(r)||/^[a-z]+(-[a-z]+)+-\d+$/i.test(r)||/^[a-z]+(_[a-z]+)*_\d+$/i.test(r)||/^\d+$/.test(r)||/^:[a-z0-9]+:$/i.test(r)||/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(r))return!0;if(/^[a-z]{1,3}[A-Za-z0-9]{8,}$/.test(r)){const t=/\d/.test(r),e=/[A-Z]/.test(r),s=r.length>=20;if(t&&e||s)return!0}return!!(/^radix-/.test(r)||/^mui-\d+$/.test(r))}const Z=new Set(["aria-labelledby","aria-describedby","aria-controls","aria-owns","aria-activedescendant","for","form","list","headers","aria-details","aria-errormessage","aria-flowto"]);function K(r){return r.trim().split(/\s+/).some(e=>P(e))}class ht{constructor(t,e){this.maxDepth=t.maxPathDepth??10,this.cache=e}findAnchor(t){if(this.cache){const c=this.cache.getAnchor(t);if(c!==void 0)return c}const e=t.tagName.toLowerCase(),s=t.ownerDocument;if(e==="html"){const c={element:t,score:1,tier:"A",depth:0};return this.cacheResult(t,c),c}if(e==="head"||this.isInsideHead(t)){const c=s?.documentElement;if(c){const l={element:c,score:1,tier:"A",depth:0};return this.cacheResult(t,l),l}}if(e==="body"){const c=s?.documentElement;if(c){const l={element:c,score:1,tier:"A",depth:0};return this.cacheResult(t,l),l}}let n=t.parentElement,a=0,i=null;for(;n&&a<this.maxDepth;){if(n.tagName.toLowerCase()==="body")return i||{element:n,score:N.DEGRADED_SCORE,tier:"C",depth:a};const c=this.scoreAnchor(n);if(c>0){const l=this.applyDepthPenalty(c,a),f=this.getTier(n),h={element:n,score:l,tier:f,depth:a};if(f==="A")return h;(!i||l>i.score)&&(i=h)}n=n.parentElement,a++}const o=i;return this.cache&&this.cache.setAnchor(t,o),o}scoreAnchor(t){let e=0;const s=t.tagName.toLowerCase();Q.includes(s)&&(e+=N.SEMANTIC_TAG);const n=t.getAttribute("role");n&&Y.includes(n)&&(e+=N.ROLE),(t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby"))&&(e+=N.ARIA_LABEL);const a=t.id;return a&&!P(a)&&(e+=N.STABLE_ID),(t.hasAttribute("data-testid")||t.hasAttribute("data-qa")||t.hasAttribute("data-test"))&&(e+=N.TEST_MARKER),Math.min(e,1)}applyDepthPenalty(t,e){if(e<=N.DEPTH_PENALTY_THRESHOLD)return t;const s=(e-N.DEPTH_PENALTY_THRESHOLD)*N.DEPTH_PENALTY_FACTOR;return Math.max(0,t-s)}getTier(t){const e=t.tagName.toLowerCase();if(Q.includes(e))return"A";const s=t.getAttribute("role");return s&&Y.includes(s)?"B":"C"}isInsideHead(t){let e=t.parentElement;for(;e;){const s=e.tagName.toLowerCase();if(s==="head")return!0;if(s==="body")return!1;e=e.parentElement}return!1}cacheResult(t,e){this.cache&&this.cache.setAnchor(t,e)}}const Ht=[/^css-[a-z0-9]+$/i,/^sc-[a-z0-9]+-\d+$/i,/^[a-z]{5,8}$/i,/^Mui[A-Z]\w+-\w+-\w+/,/^makeStyles-\w+-\d+$/,/^jss\d+$/,/^(emotion|linaria)-[a-z0-9]+/i,/^(chakra|tw-|ant-)[a-z0-9]+-\w+/i,/-[a-f0-9]{6,}$/i,/^_[a-z0-9]{5,}$/i,/\d{5,}/],Ot=[/^\[/,/^(first|last|odd|even|only|first-of-type|last-of-type|only-of-type):/,/^(hover|focus|active|disabled|enabled|checked|indeterminate|default|required|valid|invalid|in-range|out-of-range|placeholder-shown|autofill|read-only):/,/^(focus-within|focus-visible|visited|target|open):/,/^(sm|md|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl):/,/^dark:/,/^(rtl|ltr):/,/^(group|peer)(-hover|-focus|-active)?:/,/^[a-z][a-z-]*:/,/\/([\d.]+|full|auto|screen)$/,/^(inset|top|right|bottom|left)(-|$)/,/^(flex|inline-flex|grid|block|inline|inline-block|hidden|visible)$/,/^(absolute|relative|fixed|sticky|static)$/,/^(items|justify|content|self|place)-/,/^flex-(row|col|wrap|nowrap|1|auto|initial|none)/,/^grid-(cols|rows|flow)/,/^(gap|space)-/,/^[mp][trblxy]?-(\d+|auto|px)$/,/^-[mp][trblxy]?-\d+$/,/^-(top|right|bottom|left|inset)-\d+$/,/^-z-\d+$/,/^-space-[xy]-\d+$/,/^-translate-[xy]-\d+$/,/^-rotate-\d+$/,/^-scale-\d+$/,/^-skew-[xy]-\d+$/,/^(w|h|min-w|min-h|max-w|max-h|size)-/,/^text-(center|left|right|justify|start|end|xs|sm|base|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl|8xl|9xl)$/,/^text-(uppercase|lowercase|capitalize|normal-case|underline|line-through|no-underline)$/,/^text-(truncate|ellipsis|clip)$/,/^(bg|border|ring|shadow|outline)-/,/^rounded(-|$)/,/^(font|leading|tracking|whitespace|break|truncate)-/,/^(uppercase|lowercase|capitalize|normal-case)$/,/^(transform|transition|duration|delay|ease|animate)-/,/^(scale|rotate|translate|skew)-/,/^transform$/,/^backdrop-blur-/,/^motion-/,/^(fade|slide|zoom|bounce|pulse|spin|ping)-/,/^(overflow|overscroll|scroll)-/,/^object-(contain|cover|fill|none|scale-down)$/,/^(cursor|pointer-events|select|resize)-/,/^(opacity|z)-/,/^(visible|invisible|collapse)$/,/^d-(none|inline|inline-block|block|grid|table|flex)$/,/^(float|clearfix|text)-(left|right|center|justify|start|end)$/,/^(m|p)[trblxy]?-[0-5]$/,/^(w|h)-(25|50|75|100|auto)$/,/^btn-(sm|lg|block)$/,/^text-(muted|primary|success|danger|warning|info|light|dark|white)$/,/^bg-(primary|secondary|success|danger|warning|info|light|dark|white|transparent)$/,/^border(-top|-bottom|-left|-right)?(-0)?$/,/^rounded(-top|-bottom|-left|-right|-circle|-pill|-0)?$/,/^shadow(-sm|-lg|-none)?$/,/^(align|justify|order|flex)-(start|end|center|between|around|fill|grow|shrink)$/,/^col(-sm|-md|-lg|-xl)?(-\d+|-auto)?$/,/^row(-cols)?(-\d+)?$/,/^g[xy]?-[0-5]$/,/^(show|hide|invisible|visible)$/,/^(position|top|bottom|start|end)-(static|relative|absolute|fixed|sticky|-\d+)$/,/^(row|col)$/,/^clearfix$/,/^pull-(left|right)$/,/^float-(left|right|none)$/],kt=[/^(nav|menu|header|footer|sidebar|topbar|navbar|breadcrumb)/,/(navigation|dropdown|megamenu)$/,/^(btn|button|link|card|modal|dialog|popup|tooltip|alert|badge|chip)/,/^(form|input|select|checkbox|radio|textarea|label|fieldset)/,/^(table|list|item|row|cell|column)/,/^(accordion|tab|carousel|slider|gallery)/,/^(content|main|article|post|comment|title|subtitle|description|caption)/,/^(hero|banner|jumbotron|section|wrapper|box)/,/^(user|profile|avatar|account|auth)/,/^(product|item|price|cart|checkout|order)/,/^(page|layout|panel|widget|block)/,/-(primary|secondary|tertiary|success|error|warning|info|danger)$/,/-(active|inactive|disabled|enabled|selected|highlighted|focused)$/,/-(open|closed|expanded|collapsed|visible|hidden)$/,/-(large|medium|small|tiny|xs|sm|md|lg|xl)$/,/^(submit|cancel|close|delete|edit|save|back|next|prev|search)/,/^(loading|pending|complete|failed|draft|published)/];function q(r){return Ht.some(t=>t.test(r))}function U(r){return r.length<=2||/^\d/.test(r)?!0:Ot.some(t=>t.test(r))}function qt(r){return q(r)||U(r)?!1:kt.some(t=>t.test(r))}function Ut(r){return!q(r)&&!U(r)}function L(r){return r.filter(t=>Ut(t))}function zt(r){if(q(r)||U(r))return 0;let t=.5;return qt(r)&&(t=.8),r.length<3?t*=.3:r.length<5&&(t*=.6),/\d/.test(r)&&(t*=.7),Math.min(t,1)}function ut(r){const t=[],e=[];for(const s of r)U(s)||q(s)?e.push(s):t.push(s);return{semantic:t,utility:e}}function J(r){return U(r)||q(r)}function Ft(r){return zt(r)}const jt=new Set(["tr","td","th","thead","tbody","tfoot"]),Wt=new Set(["data-testid","data-qa","data-cy","data-test","aria-label","name","href"]);function Bt(r){if(r.id)return!0;if(r.attributes){for(const t of Object.keys(r.attributes))if(Wt.has(t))return!0}return!1}function Gt(r,t,e){const s=r.parentElement;if(!s)return!0;for(const n of Array.from(s.children)){if(n===r||n.tagName.toLowerCase()!==t)continue;if((n.textContent?.trim()??"")===e)return!1}return!0}function _(r,t,e){if(jt.has(r))return!0;if(Bt(t))return!1;if(e){const s=e.parentElement;if(s){const n=t.text?.normalized;if(n&&Gt(e,r,n))return!1;if(Array.from(s.children).some(i=>i!==e&&i.tagName.toLowerCase()===r))return!0}return!1}return!0}const dt=r=>r.replace(/([#:.[\]@])/g,"\\$1");class ft{constructor(t,e){this.maxDepth=t.maxPathDepth??10,this.cache=e}buildPath(t,e,s){const n=t.tagName.toLowerCase(),a=e.tagName.toLowerCase();if(n==="html"&&(a==="head"||a==="body"))return{path:[],degraded:!1};if(n==="html"&&this.isInsideHead(e))return this.buildHeadPath(t,e,s);const i=[];let o=e.parentElement;for(;o&&o!==t&&i.length<this.maxDepth;)i.unshift(o),o=o.parentElement;const c=i.length>=this.maxDepth&&o!==t;if(!c&&o!==t)return console.warn("[PathBuilder] Target is not a descendant of anchor"),{path:[],degraded:!0,degradationReason:"target-not-descendant-of-anchor"};let l=this.filterNoise(i);return l=this.ensureUniqueness(i,l,t,e,s),{path:l.map(h=>{const d=h.tagName.toLowerCase(),u=s.extract(h);let g;if(_(d,u,h)){const m=h.parentElement;if(m){const S=Array.from(m.children).indexOf(h);S!==-1&&(g=S+1)}}return{tag:d,semantics:u,score:s.scoreElement(h),nthChild:g}}),degraded:c,degradationReason:c?"path-depth-overflow":void 0}}buildPathNodes(t,e,s){return this.buildPath(t,e,s).path}ensureUniqueness(t,e,s,n,a){const i=this.buildTestSelector(s,e,n);try{const o=n.ownerDocument;if(!o)return e;let c;if(this.cache){const f=this.cache.getSelectorResults(i);f!==void 0?c=f:(c=Array.from(o.querySelectorAll(i)),this.cache.setSelectorResults(i,c))}else c=o.querySelectorAll(i);if(c.length<=1)return e;const l=t.filter(f=>!e.includes(f));for(const f of l){if(a.scoreElement(f)<Lt.MIN_CONFIDENCE_FOR_SKIP)continue;const d=this.insertNodeInOrder(e,f,t),u=this.buildTestSelector(s,d,n);try{let g;if(this.cache){const m=this.cache.getSelectorResults(u);m!==void 0?g=m:(g=Array.from(o.querySelectorAll(u)),this.cache.setSelectorResults(u,g))}else g=o.querySelectorAll(u);if(g.length===1)return d;g.length<c.length&&(e=d)}catch{}}return e}catch{return e}}insertNodeInOrder(t,e,s){const n=s.indexOf(e),a=[...t];let i=0;for(let o=0;o<a.length&&!(s.indexOf(a[o])>n);o++)i=o+1;return a.splice(i,0,e),a}buildTestSelector(t,e,s){const n=[];n.push(this.elementToSelector(t));for(const a of e)n.push(this.elementToSelector(a));return n.push(this.elementToSelector(s)),n.join(" ")}elementToSelector(t){let e=t.tagName.toLowerCase();t.id&&!P(t.id)&&(e+=`#${dt(t.id)}`);for(const s of Array.from(t.classList))J(s)||(e+=`.${dt(s)}`);return e}filterNoise(t){return t.filter(e=>this.shouldInclude(e))}shouldInclude(t){const e=t.tagName.toLowerCase();return ot.includes(e)?!0:e==="div"||e==="span"?this.hasSemanticFeatures(t):!1}hasSemanticFeatures(t){if(t.hasAttribute("role"))return!0;for(const s of Array.from(t.attributes))if(s.name.startsWith("aria-"))return!0;if(t.classList.length>0){for(const s of Array.from(t.classList))if(!J(s))return!0}if(t.hasAttribute("data-testid")||t.hasAttribute("data-qa")||t.hasAttribute("data-test"))return!0;const e=t.id;return!!(e&&!P(e))}isInsideHead(t){let e=t.parentElement;for(;e;){const s=e.tagName.toLowerCase();if(s==="head")return!0;if(s==="body")return!1;e=e.parentElement}return!1}buildHeadPath(t,e,s){const n=[];let a=e.parentElement;for(;a&&a!==t;)n.unshift(a),a=a.parentElement;return a!==t?{path:[],degraded:!0,degradationReason:"target-not-descendant-of-html"}:n.findIndex(c=>c.tagName.toLowerCase()==="head")===-1?{path:[],degraded:!0,degradationReason:"head-not-found-in-path"}:{path:n.map(c=>{const l=c.tagName.toLowerCase(),f=s.extract(c);let h;if(_(l,f,c)){const d=c.parentElement;if(d){const g=Array.from(d.children).indexOf(c);g!==-1&&(h=g+1)}}return{tag:l,semantics:f,score:s.scoreElement(c),nthChild:h}}),degraded:!1}}}function z(r){return r?r.trim().replace(/[\n\t\r]/g," ").replace(/\s+/g," "):""}const Vt={preserveQueryForAbsolute:!0,removeDynamicHashes:!0};function Qt(r){return r?[/\d{5,}/,/[a-f0-9]{8,}/i,/(session|token|temp|random|timestamp|nonce|cache)/i,/^\d+$/,/^[a-f0-9-]{32,}$/i].some(e=>e.test(r)):!1}function Yt(r,t){if(!r)return r;const e=r.startsWith("http://")||r.startsWith("https://"),[s,n]=r.split("#"),[a,i]=s.split("?");let o=a;return e&&t.preserveQueryForAbsolute&&i&&(o+=`?${i}`),n&&(t.removeDynamicHashes&&Qt(n)||(o+=`#${n}`)),o}function D(r,t,e={}){if(!t)return t;const s={...Vt,...e};return r==="href"||r==="src"?Yt(t,s):t}const Xt=["role","aria-label","aria-labelledby","aria-describedby","aria-controls","aria-owns","aria-level","aria-posinset","aria-setsize","aria-haspopup"],Zt=["aria-selected","aria-checked","aria-pressed","aria-expanded","aria-hidden","aria-disabled","aria-current","aria-busy","aria-invalid","aria-grabbed","aria-live","aria-atomic"],Kt=["data-state","data-active","data-inactive","data-selected","data-open","data-closed","data-visible","data-hidden","data-disabled","data-enabled","data-loading","data-error","data-success","data-highlighted","data-focused","data-hover","data-orientation","data-theme"],Jt=["data-radix-","data-headlessui-","data-reach-","data-mui-","data-chakra-","data-mantine-","data-tw-"],te=["data-testid","data-test-id","data-test","data-cy","data-qa","data-automation-id","data-id","data-component","data-entity-id","data-product-id","data-user-id"],ee=["data-ga","data-gtm","data-google","data-layer","data-event","data-yandex","data-ym","data-metrika","data-optimizely","data-vwo","data-optimize","data-hj","data-hotjar","data-fs","data-mouseflow","data-mf","data-smartlook","data-sl","data-fb","data-facebook","data-tt","data-li","data-track","data-tracking","data-click","data-impression","data-conversion","data-segment","data-analytics"],se=["data-category","data-action","data-label","data-value"],re=["id","name","type","placeholder","title","for","alt","href"],ne=["disabled","checked","selected","hidden","readonly","required","value"],ae=[/^radix-/,/^headlessui-/,/^mui-/,/:\w+:/];function ie(r,t){return Xt.includes(r)?!0:Zt.includes(r)||Kt.includes(r)||Jt.some(e=>r.startsWith(e))?!1:te.includes(r)?!0:ee.some(e=>r.startsWith(e))||se.includes(r)?!1:r.startsWith("data-")&&r.endsWith("-id")?!0:r==="id"?!ae.some(e=>e.test(t)):re.includes(r)?!0:ne.includes(r)?!1:!!r.startsWith("data-")}class tt{constructor(t,e){this.includeUtilityClasses=t.includeUtilityClasses??!1,this.cache=e}extract(t){if(this.cache){const i=this.cache.getSemantics(t);if(i!==void 0)return i}const e={},s=t.id;if(s&&!P(s)&&(e.id=s),t.classList.length>0){const i=Array.from(t.classList);if(this.includeUtilityClasses)e.classes=i;else{const{semantic:o}=ut(i);o.length>0&&(e.classes=o)}}const n=this.extractAttributes(t);Object.keys(n).length>0&&(e.attributes=n);const a=t.getAttribute("role");if(a&&(e.role=a),this.shouldExtractText(t)){const i=this.extractText(t);i&&(e.text=i)}return this.cache&&this.cache.setSemantics(t,e),e}scoreElement(t){let e=.5;const s=this.extract(t);return s.id&&(e+=.15),s.classes&&s.classes.length>0&&(e+=.1),s.attributes&&Object.keys(s.attributes).length>0&&(e+=.1),s.role&&(e+=.1),s.text&&(e+=.05),Math.min(e,1)}shouldIgnoreAttribute(t){return!!(X.has(t)||t.startsWith("on")||t.startsWith("ng-")||t.startsWith("_ng")||t.startsWith("data-reactid")||t.startsWith("data-react")||t.startsWith("data-v-"))}getAttributePriority(t){return v[t]!==void 0?v[t]:t.startsWith("data-")?v["data-*"]:t.startsWith("aria-")?v["aria-*"]:0}isDynamicValue(t){return[/^[a-f0-9]{32,}$/i,/^\d{10,}$/,/^(undefined|null|\[object)/,/^{{.*}}$/].some(s=>s.test(t))}extractAttributes(t){const e={};for(const s of Array.from(t.attributes)){const n=s.name;if(this.shouldIgnoreAttribute(n)||!ie(n,s.value)||Z.has(n)&&K(s.value)||this.getAttributePriority(n)===0)continue;const i=n==="href"||n==="src"?D(n,s.value):s.value;!i||i.trim()===""||this.isDynamicValue(i)||(e[n]=i)}return e}extractText(t){const e=this.getDirectTextContent(t);if(!e)return null;const s=z(e);if(!s)return null;const n=100,a=e.length>n?e.slice(0,n)+"...":e,i=s.length>n?s.slice(0,n)+"...":s;return{raw:a,normalized:i}}getDirectTextContent(t){const e=[];for(const s of Array.from(t.childNodes))if(s.nodeType===Node.TEXT_NODE&&s.textContent){const n=s.textContent.trim();n&&e.push(n)}return e.length>0?e.join(" "):t.textContent??null}shouldExtractText(t){const e=t.tagName.toLowerCase();return["button","a","label","h1","h2","h3","h4","h5","h6","p","span","li","th","td","dt","dd","legend","figcaption","summary"].includes(e)}}class gt{fingerprint(t){const e=t.tagName.toLowerCase(),s=this.getShape(e),n={shape:s,hasAnimation:this.hasAnimation(t)};if(s==="path"){const o=t.getAttribute("d");o&&(n.dHash=this.computePathHash(o))}else["circle","rect","ellipse","line"].includes(s)&&(n.geomHash=this.computeGeomHash(t,s));const a=t.getAttribute("role");a&&(n.role=a);const i=t.querySelector("title");return i?.textContent&&(n.titleText=i.textContent.trim()),n}computePathHash(t){const e=this.normalizePathData(t);return this.simpleHash(e)}getShape(t){return["path","circle","rect","line","polyline","polygon","ellipse","g","text","use","svg"].find(s=>s===t)??"path"}normalizePathData(t){return(t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi)??[]).slice(0,5).map(n=>n.trim().replace(/(-?\d+\.?\d*)/g,a=>parseFloat(a).toFixed(1))).join(" ")}computeGeomHash(t,e){const s=[];switch(e){case"circle":s.push(`r=${t.getAttribute("r")??"0"}`);break;case"rect":{const n=parseFloat(t.getAttribute("width")??"0"),a=parseFloat(t.getAttribute("height")??"0");n>0&&a>0&&s.push(`ratio=${(n/a).toFixed(2)}`)}break;case"ellipse":{const n=parseFloat(t.getAttribute("rx")??"0"),a=parseFloat(t.getAttribute("ry")??"0");n>0&&a>0&&s.push(`ratio=${(n/a).toFixed(2)}`)}break;case"line":{const n=parseFloat(t.getAttribute("x1")??"0"),a=parseFloat(t.getAttribute("y1")??"0"),i=parseFloat(t.getAttribute("x2")??"0"),o=parseFloat(t.getAttribute("y2")??"0"),c=Math.atan2(o-a,i-n);s.push(`angle=${c.toFixed(2)}`)}break}return this.simpleHash(s.join(";"))}hasAnimation(t){if(t.querySelector("animate, animateTransform, animateMotion"))return!0;const e=t.ownerDocument;if(e?.defaultView)try{const s=e.defaultView.getComputedStyle(t);if(s.animationName!=="none"||s.transitionProperty!=="all"&&s.transitionProperty!=="none")return!0}catch{}return!1}simpleHash(t){let e=0;for(let s=0;s<t.length;s++){const n=t.charCodeAt(s);e=(e<<5)-e+n,e=e&e}return Math.abs(e).toString(16).padStart(8,"0")}}function mt(r,t=0){const e=r.anchor.score,s=r.path.length>0?r.path.reduce((o,c)=>o+c.score,0)/r.path.length:.5,n=r.target.score,a=e*W.ANCHOR+s*W.PATH+n*W.TARGET+t*W.UNIQUENESS,i=r.anchor.degraded?.2:0;return Math.max(0,Math.min(1,a-i))}function oe(r,t,e){let s=.5;return t&&(s+=.2),e&&(s+=.15),s+=Math.min(r*.05,.15),Math.min(s,1)}class ce{constructor(t){this.cache=new Map,this.maxSize=t}get(t){const e=this.cache.get(t);if(e!==void 0)return this.cache.delete(t),this.cache.set(t,e),e}set(t,e){if(this.cache.has(t))this.cache.delete(t);else if(this.cache.size>=this.maxSize){const s=this.cache.keys().next().value;s!==void 0&&this.cache.delete(s)}this.cache.set(t,e)}has(t){return this.cache.has(t)}delete(t){this.cache.delete(t)}clear(){this.cache.clear()}get size(){return this.cache.size}}class pt{constructor(t={}){this.eidCache=new WeakMap,this.selectorResultCache=new ce(t.maxSelectorCacheSize??1e3),this.anchorCache=new WeakMap,this.semanticsCache=new WeakMap,this.stats={eidHits:0,eidMisses:0,selectorHits:0,selectorMisses:0,anchorHits:0,anchorMisses:0,semanticsHits:0,semanticsMisses:0,selectorCacheSize:0,maxSelectorCacheSize:t.maxSelectorCacheSize??1e3}}getEID(t){const e=this.eidCache.get(t);if(e!==void 0)return this.stats.eidHits++,e;this.stats.eidMisses++}setEID(t,e){this.eidCache.set(t,e)}getSelectorResults(t){const e=this.selectorResultCache.get(t);if(e!==void 0)return this.stats.selectorHits++,this.stats.selectorCacheSize=this.selectorResultCache.size,e;this.stats.selectorMisses++,this.stats.selectorCacheSize=this.selectorResultCache.size}setSelectorResults(t,e){this.selectorResultCache.set(t,e),this.stats.selectorCacheSize=this.selectorResultCache.size}getAnchor(t){if(this.anchorCache.has(t))return this.stats.anchorHits++,this.anchorCache.get(t);this.stats.anchorMisses++}setAnchor(t,e){this.anchorCache.set(t,e)}getSemantics(t){const e=this.semanticsCache.get(t);if(e!==void 0)return this.stats.semanticsHits++,e;this.stats.semanticsMisses++}setSemantics(t,e){this.semanticsCache.set(t,e)}clear(){this.selectorResultCache.clear(),this.stats.selectorCacheSize=0,this.stats={eidHits:0,eidMisses:0,selectorHits:0,selectorMisses:0,anchorHits:0,anchorMisses:0,semanticsHits:0,semanticsMisses:0,selectorCacheSize:0,maxSelectorCacheSize:this.stats.maxSelectorCacheSize}}invalidateElement(t){}invalidateSelector(t){this.selectorResultCache.delete(t),this.stats.selectorCacheSize=this.selectorResultCache.size}getStats(){return{...this.stats,selectorCacheSize:this.selectorResultCache.size}}getEIDHitRate(){const t=this.stats.eidHits+this.stats.eidMisses;return t>0?this.stats.eidHits/t:0}getSelectorHitRate(){const t=this.stats.selectorHits+this.stats.selectorMisses;return t>0?this.stats.selectorHits/t:0}getAnchorHitRate(){const t=this.stats.anchorHits+this.stats.anchorMisses;return t>0?this.stats.anchorHits/t:0}getSemanticsHitRate(){const t=this.stats.semanticsHits+this.stats.semanticsMisses;return t>0?this.stats.semanticsHits/t:0}getOverallHitRate(){const t=this.stats.eidHits+this.stats.selectorHits+this.stats.anchorHits+this.stats.semanticsHits,e=this.stats.eidMisses+this.stats.selectorMisses+this.stats.anchorMisses+this.stats.semanticsMisses,s=t+e;return s>0?t/s:0}}function bt(r){return new pt(r)}let B=null;function G(){return B||(B=bt()),B}function le(){B=null}function H(r){if(r.ownerDocument)return r.ownerDocument;let t=r;for(;t;){if(t.nodeType===9)return t;t=t.parentNode}throw new Error(`Element does not have an ownerDocument. This typically means:
2
2
  1. The element is detached from the DOM
3
3
  2. The element was created but never attached
4
- 3. You are working with a document node instead of an element`)}function re(r,t){if(!t)return;const e=H(r),s=t instanceof Document?t:H(t);if(e!==s)throw new Error(`Cross-document operation detected: element and root are from different documents.
4
+ 3. You are working with a document node instead of an element`)}function he(r,t){if(!t)return;const e=H(r),s=t instanceof Document?t:H(t);if(e!==s)throw new Error(`Cross-document operation detected: element and root are from different documents.
5
5
  Common causes:
6
6
  1. Working with iframe: pass iframe.contentDocument as root parameter
7
7
  2. Element from one iframe, root from another
8
8
  3. Element from main document, root from iframe (or vice versa)
9
9
 
10
- Solution: Ensure element and root parameter are from the same document context.`)}function G(r,t={}){if(!r||!r.ownerDocument||!r.isConnected)return null;const e={...it,...t};if(e.root)try{re(r,e.root)}catch(C){return console.error("Cross-document generation detected:",C),null}const s=e.cache??B(),n=s.getEID(r);if(n!==void 0)return n;if(r.tagName.toLowerCase()==="html"){const C=new J(e,s),y=ie(r,e,C);return s.setEID(r,y),y}const i=new ct(e,s),o=new ut(e,s),c=new J(e,s),u=new dt,d=i.findAnchor(r);if(!d&&!e.fallbackToBody)return null;const l=d?.element??r.ownerDocument?.body??null;if(!l)return null;const h=!d||d.tier==="C",g=l.tagName.toLowerCase(),f=l.parentElement;let m;if(f&&g!=="body"&&g!=="html"){const y=Array.from(f.children).indexOf(l);y!==-1&&(m=y+1)}const b=c.extract(l),S={tag:l.tagName.toLowerCase(),semantics:b,score:d?.score??I.DEGRADED_SCORE,degraded:h,nthChild:m},A=o.buildPath(l,r,c),v=c.extract(r);e.enableSvgFingerprint&&ne(r)&&(v.svg=u.fingerprint(r));const T=r.parentElement;let E;if(T){const y=Array.from(T.children).indexOf(r);y!==-1&&(E=y+1)}const $={tag:r.tagName.toLowerCase(),semantics:v,score:c.scoreElement(r),nthChild:E},_=[],N={onMultiple:"best-score",onMissing:"anchor-only",maxDepth:3},x=S.degraded||A.degraded,M=ae(S.degraded,A),D={version:"1.0",anchor:S,path:A.path,target:$,constraints:_,fallback:N,meta:{confidence:0,generatedAt:new Date().toISOString(),generator:"dom-eid@1.0",source:e.source,degraded:x,degradationReason:M}};return D.meta.confidence=ft(D),D.meta.confidence<e.confidenceThreshold?null:(s.setEID(r,D),D)}function ne(r){return r.namespaceURI==="http://www.w3.org/2000/svg"||r.tagName.toLowerCase()==="svg"||r instanceof SVGElement}function ae(r,t){if(r&&t.degraded)return"anchor-and-path-degraded";if(r)return"no-semantic-anchor";if(t.degraded)return t.degradationReason}function ie(r,t,e,s){const a={tag:"html",semantics:e.extract(r),score:1,degraded:!1,nthChild:void 0};return{version:"1.0",anchor:a,path:[],target:a,constraints:[],fallback:{onMultiple:"best-score",onMissing:"anchor-only",maxDepth:3},meta:{confidence:1,generatedAt:new Date().toISOString(),generator:"dom-eid@1.0",source:t.source,degraded:!1,degradationReason:void 0}}}class tt{buildSelector(t,e){if(t.target.tag==="html"){const l="html";return e?.ensureUnique?{selector:l,isUnique:!0,usedNthOfType:!1,extraClassesAdded:0}:l}if(t.anchor.tag==="html"&&t.path.length===0){const h=`html > ${this.buildNodeSelector(t.target.tag,t.target.semantics)}`;return e?.ensureUnique?{selector:h,isUnique:this.isUnique(h,e.root??document),usedNthOfType:!1,extraClassesAdded:0}:h}if(t.anchor.tag==="html"&&t.path.length>0&&t.path[0].tag==="head")return this.buildHeadSelector(t,e);if(t.path.length===0&&t.anchor.tag===t.target.tag&&JSON.stringify(t.anchor.semantics)===JSON.stringify(t.target.semantics)){const l=this.buildNodeSelector(t.target.tag,t.target.semantics,{excludeClasses:!1});return e?.ensureUnique?this.ensureUniqueSelector(l,t,e):l}const n=[],a=e?.ensureUnique?this.ensureUniqueAnchor(t,e.root):this.buildNodeSelector(t.anchor.tag,t.anchor.semantics);n.push(a);for(const l of t.path){let h=this.buildNodeSelector(l.tag,l.semantics);l.nthChild!==void 0&&(["tr","td","th","thead","tbody","tfoot"].includes(l.tag)?h+=`:nth-child(${l.nthChild})`:h+=`:nth-child(${l.nthChild})`),n.push(h)}let i=this.buildNodeSelector(t.target.tag,t.target.semantics,{excludeClasses:e?.ensureUnique});t.target.nthChild!==void 0&&(["tr","td","th","thead","tbody","tfoot"].includes(t.target.tag)?i+=`:nth-child(${t.target.nthChild})`:i+=`:nth-child(${t.target.nthChild})`),n.push(i);const o=this.isSvgChildElement(t.target.tag),c=t.path.some(l=>l.tag==="svg");let u;if(o&&c){const l=t.path.findIndex(h=>h.tag==="svg");if(l!==-1){const h=l+1,g=n.slice(0,h+1),f=n.slice(h+1,-1),m=n[n.length-1];f.length>0?u=g.join(" ")+" > "+f.join(" > ")+" > "+m:u=g.join(" ")+" > "+m}else u=n.join(" ")}else u=n.join(" ");if(!e?.ensureUnique)return u;const d=this.querySelectorSafe(u,e.root??document);if(d.length===1)return{selector:u,isUnique:!0,usedNthOfType:u.includes(":nth-"),extraClassesAdded:0};if(d.length===0||d.length>1){const l=this.buildFullDomPathSelector(t,t.target.semantics,e.root??document);if(l&&this.isUnique(l,e.root??document))return{selector:l,isUnique:!0,usedNthOfType:l.includes(":nth-"),extraClassesAdded:0}}return this.ensureUniqueSelector(u,t,e)}buildAnchorSelector(t){return this.buildNodeSelector(t.anchor.tag,t.anchor.semantics)}ensureUniqueSelector(t,e,s){const n=s.root??document,a=s.maxClasses??4,i=e.target.tag,o=e.target.semantics;let c=t,u=0,d=!1;if(this.querySelectorSafe(c,n).length===0){const f=this.buildFullDomPathSelector(e,o,n);if(f&&(c=f,this.isUnique(c,n)))return{selector:c,isUnique:!0,usedNthOfType:!1,extraClassesAdded:0}}if(this.isUnique(c,n))return{selector:c,isUnique:!0,usedNthOfType:!1,extraClassesAdded:0};const h=P(o.classes??[]);for(let f=0;f<Math.min(h.length,a);f++){const m=h[f];if(c+=`.${this.escapeCSS(m)}`,u++,this.isUnique(c,n))return{selector:c,isUnique:!0,usedNthOfType:!1,extraClassesAdded:u}}if(!this.isUnique(c,n)){const f=this.buildFullDomPathSelector(e,o,n);if(f&&this.isUnique(f,n))return{selector:f,isUnique:!0,usedNthOfType:f.includes(":nth-of-type("),extraClassesAdded:u}}const g=this.findNthElementByText(c,o,n);return g&&(c+=this.getNthSelector(g,i),d=!0),{selector:c,isUnique:this.isUnique(c,n),usedNthOfType:d,extraClassesAdded:u}}buildFullDomPathSelector(t,e,s){const n=this.buildNodeSelector(t.anchor.tag,t.anchor.semantics),a=this.querySelectorSafe(n,s);if(a.length===0)return null;for(const i of a){const o=this.findTargetWithinAnchor(i,t.target.tag,e);if(o.length===0)continue;const c=o.map(u=>{const d=this.scorePathMatch(u,i,t.path);return{element:u,score:d}});c.sort((u,d)=>d.score-u.score);for(const{element:u}of c){const d=this.buildPathFromAnchorToTarget(i,u,t,s);if(d&&this.isUnique(d,s))return d}}return null}scorePathMatch(t,e,s){const n=[];let a=t.parentElement;for(;a&&a!==e;)n.unshift(a),a=a.parentElement;let i=0;const o=Math.min(n.length,s.length);for(let u=0;u<o;u++){const d=n[u],l=s[u];if(d.tagName.toLowerCase()===l.tag){if(i+=10,l.nthChild!==void 0){const h=d.parentElement;h&&(Array.from(h.children).indexOf(d)+1===l.nthChild?i+=20:i-=10)}}else i-=5;if(l.semantics.classes&&l.semantics.classes.length>0){const h=l.semantics.classes.filter(g=>d.classList.contains(g));i+=h.length*2}if(l.semantics.attributes){const h=Object.entries(l.semantics.attributes).filter(([g,f])=>d.getAttribute(g)===f);i+=h.length*3}}const c=Math.abs(n.length-s.length);return i-=c*2,i}findTargetWithinAnchor(t,e,s){return Array.from(t.querySelectorAll(e)).filter(a=>{if(s.text){const i=a.textContent?.trim()||"",o=s.text.normalized;if(!i.includes(o)&&!o.includes(i))return!1}return!!(s.classes&&s.classes.length>0&&s.classes.every(o=>a.classList.contains(o))||s.attributes&&Object.entries(s.attributes).every(([o,c])=>{const u=a.getAttribute(o);return o==="href"||o==="src"?R(o,u||"")===R(o,c):u===c})||s.text)})}disambiguateParent(t,e,s,n,a){if(s?.semantics?.attributes){const o=this.buildNodeSelector(e,s.semantics,{excludeClasses:!0}),c=[...n,e].join(" > "),u=this.querySelectorSafe(c,a),d=[...n,o].join(" > "),l=this.querySelectorSafe(d,a);if(l.length>0&&l.length<u.length)return o}if(s?.semantics?.classes){const o=P(s.semantics.classes);if(o.length>0){const c=`${e}.${this.escapeCSS(o[0])}`,u=[...n,e].join(" > "),d=this.querySelectorSafe(u,a),l=[...n,c].join(" > "),h=this.querySelectorSafe(l,a);if(h.length>0&&h.length<d.length)return c}}const i=t.parentElement;return i&&Array.from(i.children).filter(c=>c.tagName.toLowerCase()===e).length>1?`${e}${this.getNthSelector(t,e)}`:e}buildPathFromAnchorToTarget(t,e,s,n){const a=[];let i=e;for(;i&&i!==t;)a.unshift(i),i=i.parentElement;if(i!==t)return null;const o=[()=>{const c=this.buildNodeSelector(s.anchor.tag,s.anchor.semantics),u=s.target.tag,d=s.target.semantics,l=[];for(const b of s.path)l.push(b.tag);const g=[c,...l,u].filter(Boolean).join(" ");if(this.isUnique(g,n))return g;const f=this.buildNodeSelector(u,d,{excludeClasses:!0}),m=[c,...l.slice(0,-1),f].join(" ");return this.isUnique(m,n)?m:null},()=>{const c=[this.buildNodeSelector(s.anchor.tag,s.anchor.semantics)],u=new Map;let d=0;for(let h=0;h<a.length-1;h++){const g=a[h],f=g.tagName.toLowerCase();d<s.path.length&&s.path[d].tag===f?(u.set(g,s.path[d]),d++):u.set(g,null)}for(let h=0;h<a.length;h++){const g=a[h],f=g.tagName.toLowerCase();if(h<a.length-1){const S=u.get(g)||null,A=this.disambiguateParent(g,f,S,c,n);c.push(A);continue}const m=this.buildNodeSelector(s.target.tag,s.target.semantics,{excludeClasses:!0}),b=g.parentElement;b&&["td","th","tr","thead","tbody","tfoot"].includes(f)&&Array.from(b.children).filter(A=>A.tagName.toLowerCase()===f).length>1?c.push(`${m}${this.getNthSelector(g,f)}`):c.push(m)}const l=c.join(" > ");return this.isUnique(l,n)?l:null},()=>{const u=[this.buildNodeSelector(s.anchor.tag,s.anchor.semantics)];for(let h=0;h<a.length-1;h++){const f=a[h].tagName.toLowerCase(),m=s.path[h]||null,b=u.join(" ")+" "+f;if(this.querySelectorSafe(b,n).length>1){if(m?.semantics?.attributes){const T=this.buildNodeSelector(f,m.semantics,{excludeClasses:!0}),E=u.join(" ")+" "+T;if(this.querySelectorSafe(E,n).length===1||this.querySelectorSafe(E+" "+s.target.tag,n).length===1){u.push(T);continue}}if(m?.semantics?.classes){const T=P(m.semantics.classes);if(T.length>0){const E=`${f}.${this.escapeCSS(T[0])}`,$=u.join(" ")+" "+E;if(this.querySelectorSafe($,n).length===1||this.querySelectorSafe($+" "+s.target.tag,n).length===1){u.push(E);continue}}}const A=a[h],v=A.parentElement;if(v&&Array.from(v.children).filter(E=>E.tagName.toLowerCase()===f).length>1){u.push(`${f}${this.getNthSelector(A,f)}`);continue}}u.push(f)}const d=this.buildNodeSelector(s.target.tag,s.target.semantics,{excludeClasses:!0});u.push(d);const l=u.join(" ");return this.isUnique(l,n)?l:null},()=>{const c=this.buildNodeSelector(s.anchor.tag,s.anchor.semantics),u=[];for(const g of s.path)u.push(g.tag);if(P(s.target.semantics.classes??[]).length===0)return null;const l=this.buildNodeSelector(s.target.tag,s.target.semantics,{maxClasses:1}),h=[c,...u.slice(0,-1),l].join(" ");return this.isUnique(h,n)?h:null},()=>{const c=this.buildNodeSelector(s.anchor.tag,s.anchor.semantics),u=[];for(const m of s.path)u.push(m.tag);const d=a[a.length-1],l=d.parentElement;if(!l||Array.from(l.children).filter(m=>m.tagName.toLowerCase()===s.target.tag).length<=1)return null;const g=this.buildNodeSelector(s.target.tag,s.target.semantics,{excludeClasses:!0})+this.getNthSelector(d,s.target.tag),f=[c,...u.slice(0,-1),g].join(" ");return this.isUnique(f,n)?f:null}];for(const c of o){const u=c();if(u)return u}return null}buildElementSelector(t){const e=t.tagName.toLowerCase();let s=e;if(t.id&&!L(t.id))return`${e}#${this.escapeCSS(t.id)}`;const n=Array.from(t.classList),a=P(n);a.length>0&&(s+=a.slice(0,2).map(o=>`.${this.escapeCSS(o)}`).join(""));const i=t.getAttribute("role");return i&&(s+=`[role="${this.escapeAttr(i)}"]`),s}querySelectorSafe(t,e){try{return Array.from(e.querySelectorAll(t))}catch{return[]}}findNthElementByText(t,e,s){const n=this.querySelectorSafe(t,s);if(n.length<=1)return null;if(e.text){const a=e.text.normalized;for(const i of n){const o=i.textContent?.trim()||"";if(o===a||o.includes(a)||a.includes(o))return i}}return null}isUnique(t,e){try{return e.querySelectorAll(t).length===1}catch{return!1}}getNthOfTypeIndex(t,e){const s=t.parentElement;if(!s)return null;const a=Array.from(s.children).filter(i=>i.tagName.toLowerCase()===e).indexOf(t);return a!==-1?a+1:null}ensureUniqueAnchor(t,e){const s=t.anchor.tag,n=t.anchor.semantics;if(this.isUnique(s,e))return s;if(n.classes&&n.classes.length>0){const i=P(n.classes);if(i.length>0){const o=`${s}.${this.escapeCSS(i[0])}`;if(this.isUnique(o,e))return o}}if(n.attributes){const i=this.getSortedAttributes(n.attributes);for(const{name:o,value:c}of i){const u=o==="href"||o==="src"?R(o,c):c;if(u){const d=`${s}[${o}="${this.escapeAttr(u)}"]`;if(this.isUnique(d,e))return d}}}if(t.anchor.nthChild!==void 0){const i=`${s}:nth-child(${t.anchor.nthChild})`;if(this.isUnique(i,e))return i}const a=Array.from(e.querySelectorAll(s));if(a.length>1){const i=this.findElementBySemantics(a,n);if(i){const o=this.getNthOfTypeIndex(i,s);if(o)return`${s}:nth-of-type(${o})`}}return s}findElementBySemantics(t,e){return e.classes&&e.classes.length>0||e.attributes&&Object.keys(e.attributes).length>0||e.text?t.find(n=>{if(e.classes&&e.classes.length>0&&e.classes.every(i=>n.classList.contains(i))||e.attributes&&Object.entries(e.attributes).every(([i,o])=>n.getAttribute(i)===o))return!0;if(e.text){const a=n.textContent?.trim()||"",i=e.text.normalized;if(a.includes(i)||i.includes(a))return!0}return!1})||null:t.length>0?t[0]:null}getNthSelector(t,e){const s=t.parentElement;if(!s)return"";const n=Array.from(s.children),a=n.indexOf(t)+1;return["tr","td","th","thead","tbody","tfoot"].includes(e)?`:nth-child(${a})`:`:nth-of-type(${n.filter(c=>c.tagName.toLowerCase()===e).indexOf(t)+1})`}getAttributePriority(t){return w[t]!==void 0?w[t]:t.startsWith("data-")?w["data-*"]:t.startsWith("aria-")?w["aria-*"]:0}shouldIgnoreAttribute(t){return!!(Y.has(t)||t.startsWith("on")||t.startsWith("ng-")||t.startsWith("_ng")||t.startsWith("data-reactid")||t.startsWith("data-react")||t.startsWith("data-v-"))}getSortedAttributes(t){return Object.entries(t).filter(([e])=>!this.shouldIgnoreAttribute(e)).filter(([e,s])=>!X.has(e)||!Z(s)).map(([e,s])=>({name:e,value:s,priority:this.getAttributePriority(e)})).filter(e=>e.priority>0).sort((e,s)=>s.priority-e.priority)}buildNodeSelector(t,e,s){let n=t;if(e.id)return n+=`#${this.escapeCSS(e.id)}`,n;if(e.attributes){const a=this.getSortedAttributes(e.attributes);for(const{name:i,value:o}of a)i==="href"||i==="src"||o&&(n+=`[${i}="${this.escapeAttr(o)}"]`)}if(e.role&&!e.attributes?.role&&(n+=`[role="${this.escapeAttr(e.role)}"]`),!s?.excludeClasses&&e.classes&&e.classes.length>0){const a=P(e.classes),i=s?.maxClasses!==void 0?a.slice(0,s.maxClasses):a;n+=i.map(o=>`.${this.escapeCSS(o)}`).join("")}return n}escapeCSS(t){let e=t;return e.startsWith("-")&&(e="\\-"+e.slice(1)),e=e.replace(/([!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g,"\\$1"),e}escapeAttr(t){return t.replace(/"/g,'\\"').replace(/\\/g,"\\\\")}isSvgChildElement(t){return Rt.includes(t)}buildHeadSelector(t,e){const s=["html"];for(const o of t.path){let c=this.buildNodeSelector(o.tag,o.semantics);o.nthChild!==void 0&&(c+=`:nth-child(${o.nthChild})`),s.push(c)}let n=this.buildNodeSelector(t.target.tag,t.target.semantics);t.target.nthChild!==void 0&&(n+=`:nth-child(${t.target.nthChild})`),s.push(n);const a=s.join(" > ");if(!e?.ensureUnique)return a;const i=this.isUnique(a,e.root??document);return{selector:a,isUnique:i,usedNthOfType:a.includes(":nth-"),extraClassesAdded:0}}}function pt(r,t){if(!r)return r;const e=le(t);try{if(oe(r)||r.startsWith("//")||ce(r))return r;const s=new URL(r,e);if(!e)return r;const n=new URL(e);if(s.origin===n.origin){let a=s.pathname;return s.search&&(a+=s.search),s.hash&&(a+=s.hash),a}return r}catch{return r}}function oe(r){return!r.startsWith("http://")&&!r.startsWith("https://")&&!r.startsWith("//")}function ce(r){return["javascript:","mailto:","tel:","data:","blob:","file:"].some(e=>r.startsWith(e))}function le(r){if(r)return r;if(typeof window<"u"&&window.location&&window.location.href)return window.location.href}function bt(r){if(!r||typeof r!="string")return"";if(r.startsWith("javascript:")||r.startsWith("mailto:")||r.startsWith("tel:")||r.startsWith("data:")||r.startsWith("blob:")||r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;try{const t=new URL(r);return t.pathname+t.search+t.hash}catch{return r}}class St{match(t,e,s,n){return t.filter(a=>this.matchElement(a,e,s,n))}matchElement(t,e,s,n){return!(e.text&&!this.matchText(t,e.text)||e.attributes&&!this.matchAttributes(t,e.attributes,s,n)||e.svg&&!this.matchSvgFingerprint(t,e.svg))}matchText(t,e){const a=Array.from(t.childNodes).filter(o=>o.nodeType===Node.TEXT_NODE).map(o=>o.textContent?.trim()??"").join(" ")||(t.textContent?.trim()??"");if(!a)return!1;const i=U(a);return e.matchMode==="partial"?i.includes(e.normalized):i===e.normalized}matchTextLenient(t,e){const a=Array.from(t.childNodes).filter(o=>o.nodeType===Node.TEXT_NODE).map(o=>o.textContent?.trim()??"").join(" ")||(t.textContent?.trim()??"");if(!a)return!1;const i=U(a);return i.includes(e.normalized)||e.normalized.includes(i)}matchElementLenient(t,e,s,n){return!(e.text&&!this.matchTextLenient(t,e.text)||e.attributes&&!this.matchAttributes(t,e.attributes,s,n)||e.svg&&!this.matchSvgFingerprint(t,e.svg))}matchLenient(t,e,s,n){return t.filter(a=>this.matchElementLenient(a,e,s,n))}matchAttributes(t,e,s,n=!0){for(const[a,i]of Object.entries(e)){const o=t.getAttribute(a);if(a==="href"||a==="src")if(n){const c=R(a,i,{preserveQueryForAbsolute:!1}),u=R(a,o||"",{preserveQueryForAbsolute:!1}),d=bt(c),l=bt(u);if(d!==l)return!1}else{const c=pt(R(a,i,{preserveQueryForAbsolute:!1}),s),u=pt(R(a,o||"",{preserveQueryForAbsolute:!1}),s);if(c!==u)return!1}else if(o!==i)return!1}return!0}matchSvgFingerprint(t,e){if(t.tagName.toLowerCase()!==e.shape)return!1;if(e.dHash&&e.shape==="path"){const s=t.getAttribute("d");if(s&&this.computePathHash(s)!==e.dHash)return!1}return!(e.geomHash&&["circle","rect","ellipse","line"].includes(e.shape)&&this.computeGeomHash(t,e.shape)!==e.geomHash||e.titleText&&t.querySelector("title")?.textContent?.trim()!==e.titleText)}computePathHash(t){const n=(t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi)??[]).slice(0,5).map(a=>a.trim().replace(/(-?\d+\.?\d*)/g,i=>parseFloat(i).toFixed(1))).join(" ");return this.simpleHash(n)}computeGeomHash(t,e){const s=[];switch(e){case"circle":s.push(`r=${t.getAttribute("r")??"0"}`);break;case"rect":{const n=parseFloat(t.getAttribute("width")??"0"),a=parseFloat(t.getAttribute("height")??"0");n>0&&a>0&&s.push(`ratio=${(n/a).toFixed(2)}`);break}case"ellipse":{const n=parseFloat(t.getAttribute("rx")??"0"),a=parseFloat(t.getAttribute("ry")??"0");n>0&&a>0&&s.push(`ratio=${(n/a).toFixed(2)}`);break}case"line":{const n=parseFloat(t.getAttribute("x1")??"0"),a=parseFloat(t.getAttribute("y1")??"0"),i=parseFloat(t.getAttribute("x2")??"0"),o=parseFloat(t.getAttribute("y2")??"0"),c=Math.atan2(o-a,i-n);s.push(`angle=${c.toFixed(2)}`);break}}return this.simpleHash(s.join(";"))}simpleHash(t){let e=0;for(let s=0;s<t.length;s++){const n=t.charCodeAt(s);e=(e<<5)-e+n,e=e&e}return Math.abs(e).toString(16).padStart(8,"0")}}class yt{applyConstraint(t,e){switch(e.type){case"text-proximity":return this.applyTextProximity(t,e.params);case"position":return this.applyPosition(t,e.params);default:return t}}applyTextProximity(t,e){return t.filter(s=>{const n=s.textContent?.trim()??"";return this.levenshteinDistance(n,e.reference)<=e.maxDistance})}applyPosition(t,e){if(t.length<=1)return t;switch(e.strategy){case"first-in-dom":return[t[0]];case"top-most":return[this.getTopMost(t)];case"left-most":return[this.getLeftMost(t)];default:return[t[0]]}}getTopMost(t){return t.reduce((e,s)=>{try{const n=e.getBoundingClientRect();return s.getBoundingClientRect().top<n.top?s:e}catch{return e}})}getLeftMost(t){return t.reduce((e,s)=>{try{const n=e.getBoundingClientRect();return s.getBoundingClientRect().left<n.left?s:e}catch{return e}})}levenshteinDistance(t,e){if(t===e)return 0;if(t.length===0)return e.length;if(e.length===0)return t.length;const s=Array.from({length:e.length+1},(n,a)=>a);for(let n=1;n<=t.length;n++){let a=n;for(let i=1;i<=e.length;i++){const o=t[n-1]===e[i-1]?s[i-1]:Math.min(s[i-1],a,s[i])+1;s[i-1]=a,a=o}s[e.length]=a}return s[e.length]}}class At{constructor(){this.cssGenerator=new tt}handleFallback(t,e){const{onMissing:s}=t.fallback;switch(s){case"anchor-only":return this.fallbackToAnchor(t,e);case"strict":return{status:"error",elements:[],warnings:["Element not found (strict mode)"],confidence:0,meta:{degraded:!0,degradationReason:"strict-not-found"}};default:return{status:"error",elements:[],warnings:["Element not found"],confidence:0,meta:{degraded:!0,degradationReason:"not-found"}}}}fallbackToAnchor(t,e){const s=this.cssGenerator.buildAnchorSelector(t),n=e instanceof Document?e:e.ownerDocument??e;try{const a=n.querySelector(s);if(a)return{status:"degraded-fallback",elements:[a],warnings:["Target not found, returning anchor"],confidence:t.meta.confidence*.3,meta:{degraded:!0,degradationReason:"anchor-fallback"}}}catch(a){const i=a instanceof Error?a.message:"Unknown selector error";return{status:"error",elements:[],warnings:[`Invalid anchor selector: ${i}`],confidence:0,meta:{degraded:!0,degradationReason:"invalid-anchor-selector"}}}return{status:"error",elements:[],warnings:["Anchor also not found"],confidence:0,meta:{degraded:!0,degradationReason:"anchor-not-found"}}}handleAmbiguous(t,e){const{onMultiple:s}=e.fallback;switch(s){case"first":return{status:"success",elements:[t[0]],warnings:["Multiple matches, returning first"],confidence:e.meta.confidence*.7,meta:{degraded:!0,degradationReason:"first-of-multiple"}};case"best-score":return this.selectBestScoring(t,e);default:return{status:"ambiguous",elements:t,warnings:[`Multiple matches: ${t.length}`],confidence:e.meta.confidence*.5,meta:{degraded:!0,degradationReason:"multiple-matches"}}}}selectBestScoring(t,e){const s=e.target.semantics;let n=t[0],a=-1;for(const i of t){const o=this.scoreElementMatch(i,s);o>a&&(a=o,n=i)}return{status:"success",elements:[n],warnings:[`Multiple matches (${t.length}), selected best-scoring element`],confidence:e.meta.confidence*(.7+a*.2),meta:{degraded:!0,degradationReason:"best-of-multiple"}}}scoreElementMatch(t,e){let s=0,n=0;if(e.id&&(n+=.3,t.id===e.id&&(s+=.3)),e.classes&&e.classes.length>0){n+=.25;const a=Array.from(t.classList),i=e.classes.filter(o=>a.includes(o)).length;s+=i/e.classes.length*.25}if(e.attributes){const a=Object.entries(e.attributes);if(a.length>0){n+=.2;let i=0;for(const[o,c]of a)t.getAttribute(o)===c&&i++;s+=i/a.length*.2}}if(e.role&&(n+=.15,t.getAttribute("role")===e.role&&(s+=.15)),e.text){n+=.1;const a=U(t.textContent);a===e.text.normalized?s+=.1:a.includes(e.text.normalized)&&(s+=.05)}return n>0?s/n:0}}function Et(r,t,e={}){const s={...ot,...e};let n;try{t instanceof Document?n=t:n=H(t)}catch(b){const S=b instanceof Error?b.message:"Unknown error";return{status:"error",elements:[],warnings:["Failed to resolve document context",S],confidence:0,meta:{degraded:!0,degradationReason:"invalid-context"}}}if(s.root){const b=s.root instanceof Document?s.root:s.root.ownerDocument;b&&b!==n&&console.warn("options.root does not match dom parameter document. Using document from dom parameter. This may indicate a cross-document operation issue.")}const a=s.documentUrl??n.defaultView?.location?.href,i=s.matchUrlsByPathOnly??!0,o=new tt,c=new St,u=new yt,d=new At,l=o.buildSelector(r,{ensureUnique:!1,root:n});let h;try{h=Array.from(n.querySelectorAll(l))}catch(b){const S=b instanceof Error?b.message:"Unknown selector error";return{status:"error",elements:[],warnings:[`Invalid CSS selector: ${l}`,`Error: ${S}`],confidence:0,meta:{degraded:!0,degradationReason:"invalid-selector"}}}const g=h.length;h.length>s.maxCandidates&&(h=h.slice(0,s.maxCandidates));const f=c.match(h,r.target.semantics,a,i);if(f.length===0&&g>0&&r.target.semantics.text!==void 0){const b=c.matchLenient(h,r.target.semantics,a,i);if(b.length>0){if(b.length===1)return{status:"success",elements:b,warnings:["Used relaxed text matching due to exact match failure"],confidence:r.meta.confidence*.8,meta:{degraded:!0,degradationReason:"relaxed-text-matching"}};const S=Ct(b,r,u,d,n,s,1);if(S.elements.length>0)return{...S,warnings:[...S.warnings,"Used relaxed text matching"],confidence:S.confidence*.8}}}if(f.length===1)return{status:"success",elements:f,warnings:[],confidence:r.meta.confidence,meta:{degraded:!1}};if(f.length===0){const b=g>0?`CSS selector found ${g} candidates but semantic filtering rejected all. This may indicate text content mismatch.`:"CSS selector found no candidates";if(s.enableFallback){const S=d.handleFallback(r,n);return{...S,warnings:[...S.warnings,b]}}return{status:"error",elements:[],warnings:["No matching elements found",b],confidence:0,meta:{degraded:!0,degradationReason:"not-found"}}}return Ct(f,r,u,d,n,s,1)}function he(r){return[...r].sort((t,e)=>e.priority-t.priority)}function Ct(r,t,e,s,n,a,i){let o=r;const c=he(t.constraints);for(const d of c){if(o=e.applyConstraint(o,d),o.length===1)return{status:"success",elements:o,warnings:[],confidence:t.meta.confidence*.9*i,meta:{degraded:!1}};if(o.length===0)return a.enableFallback?s.handleFallback(t,n):{status:"error",elements:[],warnings:["Constraints eliminated all candidates"],confidence:0,meta:{degraded:!0,degradationReason:"over-constrained"}}}if(a.strictMode)return{status:"ambiguous",elements:o,warnings:[`Non-unique resolution: ${o.length} matches`],confidence:t.meta.confidence*.7*i,meta:{degraded:!0,degradationReason:"ambiguous"}};const u=s.handleAmbiguous(o,t);return{...u,confidence:u.confidence*i}}function ue(r){const t=[],e=[];if(r.version?r.version!=="1.0"&&e.push(`Unknown version: ${r.version}`):t.push("Missing version field"),r.anchor?(r.anchor.tag||t.push("Anchor missing tag"),typeof r.anchor.score!="number"&&t.push("Anchor missing score"),r.anchor.semantics||t.push("Anchor missing semantics")):t.push("Missing anchor field"),r.target?(r.target.tag||t.push("Target missing tag"),typeof r.target.score!="number"&&t.push("Target missing score"),r.target.semantics||t.push("Target missing semantics")):t.push("Missing target field"),!Array.isArray(r.path))t.push("Path must be an array");else for(let s=0;s<r.path.length;s++){const n=r.path[s];n.tag||t.push(`Path node ${s} missing tag`),n.semantics||t.push(`Path node ${s} missing semantics`)}return r.meta?(typeof r.meta.confidence!="number"&&e.push("Missing confidence score"),r.meta.generatedAt||e.push("Missing generatedAt timestamp")):t.push("Missing meta field"),Array.isArray(r.constraints)||e.push("Constraints should be an array"),r.fallback||e.push("Missing fallback rules"),{valid:t.length===0,errors:t,warnings:e}}function de(r){if(!r||typeof r!="object")return!1;const t=r;return typeof t.version=="string"&&typeof t.anchor=="object"&&Array.isArray(t.path)&&typeof t.target=="object"}const Tt={maxClasses:2,maxAttributes:5,includeText:!0,maxTextLength:50,simplifyTarget:!0,includeConstraints:!0};function xt(r){return r==="id"?101:w[r]!==void 0?w[r]:r.startsWith("data-")?w["data-*"]:r.startsWith("aria-")?w["aria-*"]:0}function fe(r){return["id","data-testid","data-qa","data-cy","href","text","role"].includes(r)}function ge(r){return!!(/@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/.test(r)||/(\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/.test(r)||/\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}/.test(r))}function wt(r,t){const e={...Tt,...t},s=`v${r.version}`,n=et(r.anchor,!1,e),a=r.path.length>0?r.path.map(c=>et(c,!1,e)).join(" > ")+" > ":"",i=et(r.target,!0,e),o=e.includeConstraints?me(r):"";return`${s}: ${n} :: ${a}${i}${o}`}function vt(r){r=r.trim();const t=r.match(/^v(\d+(?:\.\d+)?)\s*:\s*/);if(!t)throw new Error('Invalid SEQL Selector: missing version prefix (expected "v1:")');const e=t[1];if(e!=="1.0"&&e!=="1")throw new Error(`Unsupported SEQL Selector version: v${e} (only v1.0 is supported)`);let s=r.slice(t[0].length);const n=s.match(/^(.+?)\s*::\s*/);if(!n)throw new Error('Invalid SEQL Selector: missing anchor separator "::"');const a=n[1].trim();s=s.slice(n[0].length);const i=s.match(/\s*\{([^}]+)\}\s*$/);let o="";i&&(o=i[1],s=s.slice(0,i.index));const c=s.split(/\s*>\s*/).map(b=>b.trim()).filter(b=>b);if(c.length===0)throw new Error("Invalid SEQL Selector: missing target node");const u=c[c.length-1],d=c.slice(0,-1),l=st(a,!0),h=d.map(b=>st(b,!1)),g=st(u,!1),f=pe(o);return{version:"1.0",anchor:l,path:h,target:g,constraints:f,fallback:{onMultiple:"best-score",onMissing:"anchor-only",maxDepth:10},meta:{confidence:.7,generatedAt:new Date().toISOString(),generator:"seql-parser@1.0",source:"seql-string",degraded:!1}}}function et(r,t=!1,e=Tt){const{tag:s,semantics:n}=r;let a=s;const i=[],o={...n.attributes};n.id&&(o.id=n.id),n.role&&!o.role&&(o.role=n.role);const c=Object.entries(o).map(([l,h])=>{const g=xt(l),f=l==="href"||l==="src"?R(l,h):h;return{name:l,value:f,priority:g}}).filter(l=>l.name!=="id"&&l.name!=="class"&&Y.has(l.name)||X.has(l.name)&&Z(l.value)?!1:l.priority>0||l.name==="role"||l.name==="id");c.sort((l,h)=>h.priority-l.priority);const u=c.slice(0,e.maxAttributes);u.sort((l,h)=>l.name.localeCompare(h.name));for(const{name:l,value:h}of u)i.push(`${l}="${rt(h)}"`);if(e.includeText&&n.text&&!ge(n.text.normalized)){const l=n.text.normalized;l.length>0&&l.length<=e.maxTextLength&&i.push(`text="${rt(l)}"`)}let d=i;if(i.length>0&&(t&&e.simplifyTarget&&n.id&&(d=i.filter(l=>{const h=l.split("=")[0];return xt(h)>=60||h==="text"||h==="id"||h==="role"})),d.length>0&&d.sort((l,h)=>l.localeCompare(h))),n.classes&&n.classes.length>0){const l=P(n.classes),h=!!n.id||i.some(f=>f.startsWith("href=")||f.startsWith("data-testid=")||f.startsWith("text=")||f.startsWith("role="));if(!(t&&e.simplifyTarget&&h)&&l.length>0){const f=l.sort().slice(0,e.maxClasses);a+=f.map(m=>`.${m}`).join("")}}if(d.length>0&&(a+=`[${d.join(",")}]`),"nthChild"in r&&r.nthChild){const l=!!n.id||n.attributes&&Object.keys(n.attributes).some(fe);t&&e.simplifyTarget&&l||(a+=`#${r.nthChild}`)}return a}function me(r){if(!r.constraints||r.constraints.length===0)return"";const t=[];for(const e of r.constraints)switch(e.type){case"uniqueness":t.push("unique=true");break;case"position":e.params&&e.params.strategy&&t.push(`pos=${e.params.strategy}`);break;case"text-proximity":if(e.params&&e.params.reference){const s=rt(String(e.params.reference));t.push(`text="${s}"`)}break}return t.length===0?"":` {${t.join(",")}}`}function st(r,t){let e=r;const s={},n=e.match(/^([a-z][a-z0-9-]*)/);if(!n)throw new Error(`Invalid node: missing tag name in "${r}"`);const a=n[1];e=e.slice(a.length);const i=[];let o;for(;o=e.match(/^\.([a-zA-Z][a-zA-Z0-9-_]*)/);)i.push(o[1]),e=e.slice(o[0].length);i.length>0&&(s.classes=i);const c=e.match(/^\[([^\]]+)\]/);if(c){const l=c[1],h={},g=be(l);for(const f of g){const m=f.match(/^([a-z][a-z0-9-]*)(?:=|~=)"((?:[^"\\]|\\.)*)"/);if(m){const[,b,S]=m;h[b]=It(S)}}Object.keys(h).length>0&&(h.text&&(s.text={raw:h.text,normalized:h.text},delete h.text),h.id&&(s.id=h.id,delete h.id),h.role&&(s.role=h.role,delete h.role),Object.keys(h).length>0&&(s.attributes=h)),e=e.slice(c[0].length)}let u;const d=e.match(/^#(\d+)/);if(d&&(u=parseInt(d[1],10),e=e.slice(d[0].length)),e.trim())throw new Error(`Invalid node: unexpected content "${e}" in "${r}"`);return t?{tag:a,semantics:s,score:.7,degraded:!1}:{tag:a,semantics:s,score:.7,nthChild:u}}function pe(r){if(!r.trim())return[];const t=[],e=r.split(",").map(s=>s.trim());for(const s of e){const[n,a]=s.split("=").map(i=>i.trim());switch(n){case"unique":a==="true"&&t.push({type:"uniqueness",params:{mode:"strict"},priority:90});break;case"pos":t.push({type:"position",params:{strategy:a},priority:70});break;case"text":{const i=a.replace(/^"(.*)"$/,"$1");t.push({type:"text-proximity",params:{reference:It(i),maxDistance:5},priority:60});break}}}return t}function be(r){const t=[];let e="",s=!1;for(let n=0;n<r.length;n++){const a=r[n];a==='"'&&(n===0||r[n-1]!=="\\")?(s=!s,e+=a):a===","&&!s?(e.trim()&&t.push(e.trim()),e=""):e+=a}return e.trim()&&t.push(e.trim()),t}function rt(r){return r.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/>/g,"\\>").replace(/:/g,"\\:")}function It(r){return r.replace(/\\\\/g,"\0").replace(/\\"/g,'"').replace(/\\>/g,">").replace(/\\:/g,":").replace(/\x00/g,"\\")}function Se(r,t,e){const s=G(r,t);return s?wt(s,e):null}function ye(r,t,e){try{const s=vt(r),n={...e,root:e?.root||t};return Et(s,t,n).elements||[]}catch(s){return console.error("Failed to resolve SEQL Selector:",s),[]}}const Ae=new Set(["script","style","noscript","meta","link","head","title"]);function nt(r){return r.id&&!L(r.id)?3:r.hasAttribute("role")||r.hasAttribute("aria-label")||r.hasAttribute("aria-labelledby")||r.hasAttribute("data-testid")||r.hasAttribute("data-qa")||r.hasAttribute("data-test")?2:1}function $t(r,t){const e=r.tagName.toLowerCase();return!!(Ae.has(e)||t&&nt(r)===1&&!["form","main","nav","section","article","footer","header","button","a","input","label","select","textarea"].includes(e))}function Nt(r){return[...r].sort((t,e)=>{const s=nt(t);return nt(e)-s})}function Ee(r={}){const t=performance.now();let{root:e,filter:s="*",limit:n=1/0,onProgress:a,progressInterval:i=100,skipNonSemantic:o=!0,generatorOptions:c={},cache:u,signal:d}=r;const l=u??B(),h={...c,cache:l};let g;try{if(e)e instanceof Document,g=Array.from(e.querySelectorAll(s));else if(typeof document<"u")g=Array.from(document.querySelectorAll(s));else throw new Error("Root element or document is required when document is not available")}catch{return{results:[],failed:[],stats:{totalElements:0,successful:0,failed:0,skipped:0,totalTimeMs:0,avgTimePerElementMs:0,cacheHitRate:0}}}if(!e){if(g.length===0)throw new Error("Root element or document is required when no elements are found");const C=H(g[0]);e=C.body||C.documentElement}const f=e instanceof Document?e:H(e);g.forEach((C,y)=>{if(H(C)!==f)throw new Error(`Batch generation requires all elements from the same document. Element at index ${y} is from a different document. If working with iframes, ensure all elements are from the same iframe's contentDocument.`)});const m=g.filter(C=>!$t(C,o)),S=Nt(m).slice(0,n),A=[],v=[];let T=0;const E=S.length;let $=0;for(let C=0;C<S.length&&!d?.aborted;C++){const y=S[C],z=l.getEID(y);if(z)A.push({element:y,eid:z,generationTimeMs:0});else{const Te=performance.now();try{const O=G(y,h),xe=performance.now()-Te;O?A.push({element:y,eid:O,generationTimeMs:xe}):T++}catch(O){v.push({element:y,error:O instanceof Error?O.message:String(O)})}}a&&C-$>=i&&(a(C+1,E),$=C)}a&&a(E,E);const _=performance.now()-t,N=l.getStats(),x=N.eidHits+N.eidMisses+N.selectorHits+N.selectorMisses,M=N.eidHits+N.selectorHits,D=x>0?M/x:0;return{results:A,failed:v,stats:{totalElements:E,successful:A.length,failed:v.length,skipped:T,totalTimeMs:_,avgTimePerElementMs:A.length>0?_/A.length:0,cacheHitRate:D}}}function Ce(r,t={}){const e=performance.now(),{limit:s=1/0,onProgress:n,progressInterval:a=100,skipNonSemantic:i=!0,generatorOptions:o={},cache:c,signal:u}=t,d=c??B(),l={...o,cache:d},h=r.filter(x=>!$t(x,i)),f=Nt(h).slice(0,s),m=[],b=[];let S=0;const A=f.length;let v=0;for(let x=0;x<f.length&&!u?.aborted;x++){const M=f[x],D=d.getEID(M);if(D)m.push({element:M,eid:D,generationTimeMs:0});else{const C=performance.now();try{const y=G(M,l),z=performance.now()-C;y?m.push({element:M,eid:y,generationTimeMs:z}):S++}catch(y){b.push({element:M,error:y instanceof Error?y.message:String(y)})}}n&&x-v>=a&&(n(x+1,A),v=x)}n&&n(A,A);const T=performance.now()-e,E=d.getStats(),$=E.eidHits+E.eidMisses+E.selectorHits+E.selectorMisses,_=E.eidHits+E.selectorHits,N=$>0?_/$:0;return{results:m,failed:b,stats:{totalElements:A,successful:m.length,failed:b.length,skipped:S,totalTimeMs:T,avgTimePerElementMs:m.length>0?T/m.length:0,cacheHitRate:N}}}p.AnchorFinder=ct,p.ConstraintsEvaluator=yt,p.CssGenerator=tt,p.DEFAULT_GENERATOR_OPTIONS=it,p.DEFAULT_RESOLVER_OPTIONS=ot,p.EIDCache=gt,p.EID_VERSION="1.0",p.FallbackHandler=At,p.MAX_PATH_DEPTH=10,p.PathBuilder=ut,p.ROLE_ANCHOR_VALUES=Q,p.SEMANTIC_ANCHOR_TAGS=V,p.SEMANTIC_ATTRIBUTES=Mt,p.SEMANTIC_TAGS=at,p.SemanticExtractor=J,p.SemanticsMatcher=St,p.SvgFingerprinter=dt,p.calculateConfidence=ft,p.calculateElementScore=te,p.createEIDCache=mt,p.filterClasses=lt,p.generateEID=G,p.generateEIDBatch=Ee,p.generateEIDForElements=Ce,p.generateSEQL=Se,p.getClassScore=qt,p.getGlobalCache=B,p.isEID=de,p.isUtilityClass=K,p.normalizeText=U,p.parseSEQL=vt,p.resetGlobalCache=se,p.resolve=Et,p.resolveSEQL=ye,p.stringifySEQL=wt,p.validateEID=ue,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
10
+ Solution: Ensure element and root parameter are from the same document context.`)}function V(r,t={}){if(!r||!r.ownerDocument||!r.isConnected)return null;const e={...ct,...t};if(e.root)try{he(r,e.root)}catch(E){return console.error("Cross-document generation detected:",E),null}const s=e.cache??G(),n=s.getEID(r);if(n!==void 0)return n;const a=r.tagName.toLowerCase();if(a==="html"){const E=new tt(e,s),A=fe(r,e,E);return s.setEID(r,A),A}const i=new ht(e,s),o=new ft(e,s),c=new tt(e,s),l=new gt,f=i.findAnchor(r);if(!f&&!e.fallbackToBody)return null;const h=f?.element??r.ownerDocument?.body??null;if(!h)return null;const d=!f||f.tier==="C",u=h.tagName.toLowerCase(),g=c.extract(h),m=h.parentElement;let p;if(m&&u!=="body"&&u!=="html"&&_(u,g,h)){const A=Array.from(m.children).indexOf(h);A!==-1&&(p=A+1)}const S={tag:h.tagName.toLowerCase(),semantics:g,score:f?.score??N.DEGRADED_SCORE,degraded:d,nthChild:p},y=o.buildPath(h,r,c),x=c.extract(r);e.enableSvgFingerprint&&ue(r)&&(x.svg=l.fingerprint(r));const C=r.parentElement;let T;if(C&&_(a,x,r)){const A=Array.from(C.children).indexOf(r);A!==-1&&(T=A+1)}const I={tag:r.tagName.toLowerCase(),semantics:x,score:c.scoreElement(r),nthChild:T},O=[],$={onMultiple:"best-score",onMissing:"anchor-only",maxDepth:3},w=S.degraded||y.degraded,M=de(S.degraded,y),R={version:"1.0",anchor:S,path:y.path,target:I,constraints:O,fallback:$,meta:{confidence:0,generatedAt:new Date().toISOString(),generator:"dom-eid@1.0",source:e.source,degraded:w,degradationReason:M}};return R.meta.confidence=mt(R),R.meta.confidence<e.confidenceThreshold?null:(s.setEID(r,R),R)}function ue(r){return r.namespaceURI==="http://www.w3.org/2000/svg"||r.tagName.toLowerCase()==="svg"||r instanceof SVGElement}function de(r,t){if(r&&t.degraded)return"anchor-and-path-degraded";if(r)return"no-semantic-anchor";if(t.degraded)return t.degradationReason}function fe(r,t,e,s){const a={tag:"html",semantics:e.extract(r),score:1,degraded:!1,nthChild:void 0};return{version:"1.0",anchor:a,path:[],target:a,constraints:[],fallback:{onMultiple:"best-score",onMissing:"anchor-only",maxDepth:3},meta:{confidence:1,generatedAt:new Date().toISOString(),generator:"dom-eid@1.0",source:t.source,degraded:!1,degradationReason:void 0}}}class et{buildSelector(t,e){if(t.target.tag==="html"){const h="html";return e?.ensureUnique?{selector:h,isUnique:!0,usedNthOfType:!1,extraClassesAdded:0}:h}if(t.anchor.tag==="html"&&t.path.length===0){const d=`html > ${this.buildNodeSelector(t.target.tag,t.target.semantics)}`;return e?.ensureUnique?{selector:d,isUnique:this.isUnique(d,e.root??document),usedNthOfType:!1,extraClassesAdded:0}:d}if(t.anchor.tag==="html"&&t.path.length>0&&t.path[0].tag==="head")return this.buildHeadSelector(t,e);if(t.path.length===0&&t.anchor.tag===t.target.tag&&JSON.stringify(t.anchor.semantics)===JSON.stringify(t.target.semantics)){const h=this.buildNodeSelector(t.target.tag,t.target.semantics,{excludeClasses:!1});return e?.ensureUnique?this.ensureUniqueSelector(h,t,e):h}const n=[],a=e?.ensureUnique?this.ensureUniqueAnchor(t,e.root):this.buildNodeSelector(t.anchor.tag,t.anchor.semantics);n.push(a);for(const h of t.path){let d=this.buildNodeSelector(h.tag,h.semantics);h.nthChild!==void 0&&_(h.tag,h.semantics)&&(d+=`:nth-child(${h.nthChild})`),n.push(d)}let i=this.buildNodeSelector(t.target.tag,t.target.semantics,{excludeClasses:e?.ensureUnique});t.target.nthChild!==void 0&&_(t.target.tag,t.target.semantics)&&(i+=`:nth-child(${t.target.nthChild})`),n.push(i);const o=this.isSvgChildElement(t.target.tag),c=t.path.some(h=>h.tag==="svg");let l;if(o&&c){const h=t.path.findIndex(d=>d.tag==="svg");if(h!==-1){const d=h+1,u=n.slice(0,d+1),g=n.slice(d+1,-1),m=n[n.length-1];g.length>0?l=u.join(" ")+" > "+g.join(" > ")+" > "+m:l=u.join(" ")+" > "+m}else l=n.join(" ")}else l=n.join(" ");if(!e?.ensureUnique)return l;const f=this.querySelectorSafe(l,e.root??document);if(f.length===1)return{selector:l,isUnique:!0,usedNthOfType:l.includes(":nth-"),extraClassesAdded:0};if(f.length===0||f.length>1){const h=this.buildFullDomPathSelector(t,t.target.semantics,e.root??document);if(h&&this.isUnique(h,e.root??document))return{selector:h,isUnique:!0,usedNthOfType:h.includes(":nth-"),extraClassesAdded:0}}return this.ensureUniqueSelector(l,t,e)}buildAnchorSelector(t){return this.buildNodeSelector(t.anchor.tag,t.anchor.semantics)}ensureUniqueSelector(t,e,s){const n=s.root??document,a=s.maxClasses??4,i=e.target.tag,o=e.target.semantics;let c=t,l=0,f=!1;if(this.querySelectorSafe(c,n).length===0){const g=this.buildFullDomPathSelector(e,o,n);if(g&&(c=g,this.isUnique(c,n)))return{selector:c,isUnique:!0,usedNthOfType:!1,extraClassesAdded:0}}if(this.isUnique(c,n))return{selector:c,isUnique:!0,usedNthOfType:!1,extraClassesAdded:0};const d=L(o.classes??[]);for(let g=0;g<Math.min(d.length,a);g++){const m=d[g];if(c+=`.${this.escapeCSS(m)}`,l++,this.isUnique(c,n))return{selector:c,isUnique:!0,usedNthOfType:!1,extraClassesAdded:l}}if(!this.isUnique(c,n)){const g=this.buildFullDomPathSelector(e,o,n);if(g&&this.isUnique(g,n))return{selector:g,isUnique:!0,usedNthOfType:g.includes(":nth-of-type("),extraClassesAdded:l}}const u=this.findNthElementByText(c,o,n);return u&&(c+=this.getNthSelector(u,i),f=!0),{selector:c,isUnique:this.isUnique(c,n),usedNthOfType:f,extraClassesAdded:l}}buildFullDomPathSelector(t,e,s){const n=this.buildNodeSelector(t.anchor.tag,t.anchor.semantics),a=this.querySelectorSafe(n,s);if(a.length===0)return null;for(const i of a){const o=this.findTargetWithinAnchor(i,t.target.tag,e);if(o.length===0)continue;const c=o.map(l=>{const f=this.scorePathMatch(l,i,t.path);return{element:l,score:f}});c.sort((l,f)=>f.score-l.score);for(const{element:l}of c){const f=this.buildPathFromAnchorToTarget(i,l,t,s);if(f&&this.isUnique(f,s))return f}}return null}scorePathMatch(t,e,s){const n=[];let a=t.parentElement;for(;a&&a!==e;)n.unshift(a),a=a.parentElement;let i=0;const o=Math.min(n.length,s.length);for(let l=0;l<o;l++){const f=n[l],h=s[l];if(f.tagName.toLowerCase()===h.tag){if(i+=10,h.nthChild!==void 0){const d=f.parentElement;d&&(Array.from(d.children).indexOf(f)+1===h.nthChild?i+=20:i-=10)}}else i-=5;if(h.semantics.classes&&h.semantics.classes.length>0){const d=h.semantics.classes.filter(u=>f.classList.contains(u));i+=d.length*2}if(h.semantics.attributes){const d=Object.entries(h.semantics.attributes).filter(([u,g])=>f.getAttribute(u)===g);i+=d.length*3}}const c=Math.abs(n.length-s.length);return i-=c*2,i}findTargetWithinAnchor(t,e,s){return Array.from(t.querySelectorAll(e)).filter(a=>{if(s.text){const i=a.textContent?.trim()||"",o=s.text.normalized;if(!i.includes(o)&&!o.includes(i))return!1}return!!(s.classes&&s.classes.length>0&&s.classes.every(o=>a.classList.contains(o))||s.attributes&&Object.entries(s.attributes).every(([o,c])=>{const l=a.getAttribute(o);return o==="href"||o==="src"?D(o,l||"")===D(o,c):l===c})||s.text)})}disambiguateParent(t,e,s,n,a){if(s?.semantics?.attributes){const o=this.buildNodeSelector(e,s.semantics,{excludeClasses:!0}),c=[...n,e].join(" > "),l=this.querySelectorSafe(c,a),f=[...n,o].join(" > "),h=this.querySelectorSafe(f,a);if(h.length>0&&h.length<l.length)return o}if(s?.semantics?.classes){const o=L(s.semantics.classes);if(o.length>0){const c=`${e}.${this.escapeCSS(o[0])}`,l=[...n,e].join(" > "),f=this.querySelectorSafe(l,a),h=[...n,c].join(" > "),d=this.querySelectorSafe(h,a);if(d.length>0&&d.length<f.length)return c}}const i=t.parentElement;return i&&Array.from(i.children).filter(c=>c.tagName.toLowerCase()===e).length>1?`${e}${this.getNthSelector(t,e)}`:e}buildPathFromAnchorToTarget(t,e,s,n){const a=[];let i=e;for(;i&&i!==t;)a.unshift(i),i=i.parentElement;if(i!==t)return null;const o=[()=>{const c=this.buildNodeSelector(s.anchor.tag,s.anchor.semantics),l=s.target.tag,f=s.target.semantics,h=[];for(const p of s.path)h.push(p.tag);const u=[c,...h,l].filter(Boolean).join(" ");if(this.isUnique(u,n))return u;const g=this.buildNodeSelector(l,f,{excludeClasses:!0}),m=[c,...h.slice(0,-1),g].join(" ");return this.isUnique(m,n)?m:null},()=>{const c=[this.buildNodeSelector(s.anchor.tag,s.anchor.semantics)],l=new Map;let f=0;for(let d=0;d<a.length-1;d++){const u=a[d],g=u.tagName.toLowerCase();f<s.path.length&&s.path[f].tag===g?(l.set(u,s.path[f]),f++):l.set(u,null)}for(let d=0;d<a.length;d++){const u=a[d],g=u.tagName.toLowerCase();if(d<a.length-1){const S=l.get(u)||null,y=this.disambiguateParent(u,g,S,c,n);c.push(y);continue}const m=this.buildNodeSelector(s.target.tag,s.target.semantics,{excludeClasses:!0}),p=u.parentElement;p&&["td","th","tr","thead","tbody","tfoot"].includes(g)&&Array.from(p.children).filter(y=>y.tagName.toLowerCase()===g).length>1?c.push(`${m}${this.getNthSelector(u,g)}`):c.push(m)}const h=c.join(" > ");return this.isUnique(h,n)?h:null},()=>{const l=[this.buildNodeSelector(s.anchor.tag,s.anchor.semantics)];for(let d=0;d<a.length-1;d++){const g=a[d].tagName.toLowerCase(),m=s.path[d]||null,p=l.join(" ")+" "+g;if(this.querySelectorSafe(p,n).length>1){if(m?.semantics?.attributes){const C=this.buildNodeSelector(g,m.semantics,{excludeClasses:!0}),T=l.join(" ")+" "+C;if(this.querySelectorSafe(T,n).length===1||this.querySelectorSafe(T+" "+s.target.tag,n).length===1){l.push(C);continue}}if(m?.semantics?.classes){const C=L(m.semantics.classes);if(C.length>0){const T=`${g}.${this.escapeCSS(C[0])}`,I=l.join(" ")+" "+T;if(this.querySelectorSafe(I,n).length===1||this.querySelectorSafe(I+" "+s.target.tag,n).length===1){l.push(T);continue}}}const y=a[d],x=y.parentElement;if(x&&Array.from(x.children).filter(T=>T.tagName.toLowerCase()===g).length>1){l.push(`${g}${this.getNthSelector(y,g)}`);continue}}l.push(g)}const f=this.buildNodeSelector(s.target.tag,s.target.semantics,{excludeClasses:!0});l.push(f);const h=l.join(" ");return this.isUnique(h,n)?h:null},()=>{const c=this.buildNodeSelector(s.anchor.tag,s.anchor.semantics),l=[];for(const u of s.path)l.push(u.tag);if(L(s.target.semantics.classes??[]).length===0)return null;const h=this.buildNodeSelector(s.target.tag,s.target.semantics,{maxClasses:1}),d=[c,...l.slice(0,-1),h].join(" ");return this.isUnique(d,n)?d:null},()=>{const c=this.buildNodeSelector(s.anchor.tag,s.anchor.semantics),l=[];for(const m of s.path)l.push(m.tag);const f=a[a.length-1],h=f.parentElement;if(!h||Array.from(h.children).filter(m=>m.tagName.toLowerCase()===s.target.tag).length<=1)return null;const u=this.buildNodeSelector(s.target.tag,s.target.semantics,{excludeClasses:!0})+this.getNthSelector(f,s.target.tag),g=[c,...l.slice(0,-1),u].join(" ");return this.isUnique(g,n)?g:null}];for(const c of o){const l=c();if(l)return l}return null}buildElementSelector(t){const e=t.tagName.toLowerCase();let s=e;if(t.id&&!P(t.id))return`${e}#${this.escapeCSS(t.id)}`;const n=Array.from(t.classList),a=L(n);a.length>0&&(s+=a.slice(0,2).map(o=>`.${this.escapeCSS(o)}`).join(""));const i=t.getAttribute("role");return i&&(s+=`[role="${this.escapeAttr(i)}"]`),s}querySelectorSafe(t,e){try{return Array.from(e.querySelectorAll(t))}catch{return[]}}findNthElementByText(t,e,s){const n=this.querySelectorSafe(t,s);if(n.length<=1)return null;if(e.text){const a=e.text.normalized;for(const i of n){const o=i.textContent?.trim()||"";if(o===a||o.includes(a)||a.includes(o))return i}}return null}isUnique(t,e){try{return e.querySelectorAll(t).length===1}catch{return!1}}getNthOfTypeIndex(t,e){const s=t.parentElement;if(!s)return null;const a=Array.from(s.children).filter(i=>i.tagName.toLowerCase()===e).indexOf(t);return a!==-1?a+1:null}ensureUniqueAnchor(t,e){const s=t.anchor.tag,n=t.anchor.semantics;if(this.isUnique(s,e))return s;if(n.classes&&n.classes.length>0){const i=L(n.classes);if(i.length>0){const o=`${s}.${this.escapeCSS(i[0])}`;if(this.isUnique(o,e))return o}}if(n.attributes){const i=this.getSortedAttributes(n.attributes);for(const{name:o,value:c}of i){const l=o==="href"||o==="src"?D(o,c):c;if(l){const f=`${s}[${o}="${this.escapeAttr(l)}"]`;if(this.isUnique(f,e))return f}}}if(t.anchor.nthChild!==void 0){const i=`${s}:nth-child(${t.anchor.nthChild})`;if(this.isUnique(i,e))return i}const a=Array.from(e.querySelectorAll(s));if(a.length>1){const i=this.findElementBySemantics(a,n);if(i){const o=this.getNthOfTypeIndex(i,s);if(o)return`${s}:nth-of-type(${o})`}}return s}findElementBySemantics(t,e){return e.classes&&e.classes.length>0||e.attributes&&Object.keys(e.attributes).length>0||e.text?t.find(n=>{if(e.classes&&e.classes.length>0&&e.classes.every(i=>n.classList.contains(i))||e.attributes&&Object.entries(e.attributes).every(([i,o])=>n.getAttribute(i)===o))return!0;if(e.text){const a=n.textContent?.trim()||"",i=e.text.normalized;if(a.includes(i)||i.includes(a))return!0}return!1})||null:t.length>0?t[0]:null}getNthSelector(t,e){const s=t.parentElement;if(!s)return"";const n=Array.from(s.children),a=n.indexOf(t)+1;return["tr","td","th","thead","tbody","tfoot"].includes(e)?`:nth-child(${a})`:`:nth-of-type(${n.filter(c=>c.tagName.toLowerCase()===e).indexOf(t)+1})`}getAttributePriority(t){return v[t]!==void 0?v[t]:t.startsWith("data-")?v["data-*"]:t.startsWith("aria-")?v["aria-*"]:0}shouldIgnoreAttribute(t){return!!(X.has(t)||t.startsWith("on")||t.startsWith("ng-")||t.startsWith("_ng")||t.startsWith("data-reactid")||t.startsWith("data-react")||t.startsWith("data-v-"))}getSortedAttributes(t){return Object.entries(t).filter(([e])=>!this.shouldIgnoreAttribute(e)).filter(([e,s])=>!Z.has(e)||!K(s)).map(([e,s])=>({name:e,value:s,priority:this.getAttributePriority(e)})).filter(e=>e.priority>0).sort((e,s)=>s.priority-e.priority)}buildNodeSelector(t,e,s){let n=t;if(e.id)return n+=`#${this.escapeCSS(e.id)}`,n;if(e.attributes){const a=this.getSortedAttributes(e.attributes);for(const{name:i,value:o}of a)i==="href"||i==="src"||o&&(n+=`[${i}="${this.escapeAttr(o)}"]`)}if(e.role&&!e.attributes?.role&&(n+=`[role="${this.escapeAttr(e.role)}"]`),!s?.excludeClasses&&e.classes&&e.classes.length>0){const a=L(e.classes),i=s?.maxClasses!==void 0?a.slice(0,s.maxClasses):a;n+=i.map(o=>`.${this.escapeCSS(o)}`).join("")}return n}escapeCSS(t){let e=t;return e.startsWith("-")&&(e="\\-"+e.slice(1)),e=e.replace(/([!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g,"\\$1"),e}escapeAttr(t){return t.replace(/"/g,'\\"').replace(/\\/g,"\\\\")}isSvgChildElement(t){return Pt.includes(t)}buildHeadSelector(t,e){const s=["html"];for(const o of t.path){let c=this.buildNodeSelector(o.tag,o.semantics);o.nthChild!==void 0&&(c+=`:nth-child(${o.nthChild})`),s.push(c)}let n=this.buildNodeSelector(t.target.tag,t.target.semantics);t.target.nthChild!==void 0&&(n+=`:nth-child(${t.target.nthChild})`),s.push(n);const a=s.join(" > ");if(!e?.ensureUnique)return a;const i=this.isUnique(a,e.root??document);return{selector:a,isUnique:i,usedNthOfType:a.includes(":nth-"),extraClassesAdded:0}}}function St(r,t){if(!r)return r;const e=pe(t);try{if(ge(r)||r.startsWith("//")||me(r))return r;const s=new URL(r,e);if(!e)return r;const n=new URL(e);if(s.origin===n.origin){let a=s.pathname;return s.search&&(a+=s.search),s.hash&&(a+=s.hash),a}return r}catch{return r}}function ge(r){return!r.startsWith("http://")&&!r.startsWith("https://")&&!r.startsWith("//")}function me(r){return["javascript:","mailto:","tel:","data:","blob:","file:"].some(e=>r.startsWith(e))}function pe(r){if(r)return r;if(typeof window<"u"&&window.location&&window.location.href)return window.location.href}function yt(r){if(!r||typeof r!="string")return"";if(r.startsWith("javascript:")||r.startsWith("mailto:")||r.startsWith("tel:")||r.startsWith("data:")||r.startsWith("blob:")||r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;try{const t=new URL(r);return t.pathname+t.search+t.hash}catch{return r}}class At{match(t,e,s,n){return t.filter(a=>this.matchElement(a,e,s,n))}matchElement(t,e,s,n){return!(e.text&&!this.matchText(t,e.text)||e.attributes&&!this.matchAttributes(t,e.attributes,s,n)||e.svg&&!this.matchSvgFingerprint(t,e.svg))}matchText(t,e){const a=Array.from(t.childNodes).filter(o=>o.nodeType===Node.TEXT_NODE).map(o=>o.textContent?.trim()??"").join(" ")||(t.textContent?.trim()??"");if(!a)return!1;const i=z(a);return e.matchMode==="partial"?i.includes(e.normalized):i===e.normalized}matchTextLenient(t,e){const a=Array.from(t.childNodes).filter(o=>o.nodeType===Node.TEXT_NODE).map(o=>o.textContent?.trim()??"").join(" ")||(t.textContent?.trim()??"");if(!a)return!1;const i=z(a);return i.includes(e.normalized)||e.normalized.includes(i)}matchElementLenient(t,e,s,n){return!(e.text&&!this.matchTextLenient(t,e.text)||e.attributes&&!this.matchAttributes(t,e.attributes,s,n)||e.svg&&!this.matchSvgFingerprint(t,e.svg))}matchLenient(t,e,s,n){return t.filter(a=>this.matchElementLenient(a,e,s,n))}matchAttributes(t,e,s,n=!0){for(const[a,i]of Object.entries(e)){const o=t.getAttribute(a);if(a==="href"||a==="src")if(n){const c=D(a,i,{preserveQueryForAbsolute:!1}),l=D(a,o||"",{preserveQueryForAbsolute:!1}),f=yt(c),h=yt(l);if(f!==h)return!1}else{const c=St(D(a,i,{preserveQueryForAbsolute:!1}),s),l=St(D(a,o||"",{preserveQueryForAbsolute:!1}),s);if(c!==l)return!1}else if(o!==i)return!1}return!0}matchSvgFingerprint(t,e){if(t.tagName.toLowerCase()!==e.shape)return!1;if(e.dHash&&e.shape==="path"){const s=t.getAttribute("d");if(s&&this.computePathHash(s)!==e.dHash)return!1}return!(e.geomHash&&["circle","rect","ellipse","line"].includes(e.shape)&&this.computeGeomHash(t,e.shape)!==e.geomHash||e.titleText&&t.querySelector("title")?.textContent?.trim()!==e.titleText)}computePathHash(t){const n=(t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi)??[]).slice(0,5).map(a=>a.trim().replace(/(-?\d+\.?\d*)/g,i=>parseFloat(i).toFixed(1))).join(" ");return this.simpleHash(n)}computeGeomHash(t,e){const s=[];switch(e){case"circle":s.push(`r=${t.getAttribute("r")??"0"}`);break;case"rect":{const n=parseFloat(t.getAttribute("width")??"0"),a=parseFloat(t.getAttribute("height")??"0");n>0&&a>0&&s.push(`ratio=${(n/a).toFixed(2)}`);break}case"ellipse":{const n=parseFloat(t.getAttribute("rx")??"0"),a=parseFloat(t.getAttribute("ry")??"0");n>0&&a>0&&s.push(`ratio=${(n/a).toFixed(2)}`);break}case"line":{const n=parseFloat(t.getAttribute("x1")??"0"),a=parseFloat(t.getAttribute("y1")??"0"),i=parseFloat(t.getAttribute("x2")??"0"),o=parseFloat(t.getAttribute("y2")??"0"),c=Math.atan2(o-a,i-n);s.push(`angle=${c.toFixed(2)}`);break}}return this.simpleHash(s.join(";"))}simpleHash(t){let e=0;for(let s=0;s<t.length;s++){const n=t.charCodeAt(s);e=(e<<5)-e+n,e=e&e}return Math.abs(e).toString(16).padStart(8,"0")}}class Tt{applyConstraint(t,e){switch(e.type){case"text-proximity":return this.applyTextProximity(t,e.params);case"position":return this.applyPosition(t,e.params);default:return t}}applyTextProximity(t,e){return t.filter(s=>{const n=s.textContent?.trim()??"";return this.levenshteinDistance(n,e.reference)<=e.maxDistance})}applyPosition(t,e){if(t.length<=1)return t;switch(e.strategy){case"first-in-dom":return[t[0]];case"top-most":return[this.getTopMost(t)];case"left-most":return[this.getLeftMost(t)];default:return[t[0]]}}getTopMost(t){return t.reduce((e,s)=>{try{const n=e.getBoundingClientRect();return s.getBoundingClientRect().top<n.top?s:e}catch{return e}})}getLeftMost(t){return t.reduce((e,s)=>{try{const n=e.getBoundingClientRect();return s.getBoundingClientRect().left<n.left?s:e}catch{return e}})}levenshteinDistance(t,e){if(t===e)return 0;if(t.length===0)return e.length;if(e.length===0)return t.length;const s=Array.from({length:e.length+1},(n,a)=>a);for(let n=1;n<=t.length;n++){let a=n;for(let i=1;i<=e.length;i++){const o=t[n-1]===e[i-1]?s[i-1]:Math.min(s[i-1],a,s[i])+1;s[i-1]=a,a=o}s[e.length]=a}return s[e.length]}}class Et{constructor(){this.cssGenerator=new et}handleFallback(t,e){const{onMissing:s}=t.fallback;switch(s){case"anchor-only":return this.fallbackToAnchor(t,e);case"strict":return{status:"error",elements:[],warnings:["Element not found (strict mode)"],confidence:0,meta:{degraded:!0,degradationReason:"strict-not-found"}};default:return{status:"error",elements:[],warnings:["Element not found"],confidence:0,meta:{degraded:!0,degradationReason:"not-found"}}}}fallbackToAnchor(t,e){const s=this.cssGenerator.buildAnchorSelector(t),n=e instanceof Document?e:e.ownerDocument??e;try{const a=n.querySelector(s);if(a)return{status:"degraded-fallback",elements:[a],warnings:["Target not found, returning anchor"],confidence:t.meta.confidence*.3,meta:{degraded:!0,degradationReason:"anchor-fallback"}}}catch(a){const i=a instanceof Error?a.message:"Unknown selector error";return{status:"error",elements:[],warnings:[`Invalid anchor selector: ${i}`],confidence:0,meta:{degraded:!0,degradationReason:"invalid-anchor-selector"}}}return{status:"error",elements:[],warnings:["Anchor also not found"],confidence:0,meta:{degraded:!0,degradationReason:"anchor-not-found"}}}handleAmbiguous(t,e){const{onMultiple:s}=e.fallback;switch(s){case"first":return{status:"success",elements:[t[0]],warnings:["Multiple matches, returning first"],confidence:e.meta.confidence*.7,meta:{degraded:!0,degradationReason:"first-of-multiple"}};case"best-score":return this.selectBestScoring(t,e);default:return{status:"ambiguous",elements:t,warnings:[`Multiple matches: ${t.length}`],confidence:e.meta.confidence*.5,meta:{degraded:!0,degradationReason:"multiple-matches"}}}}selectBestScoring(t,e){const s=e.target.semantics;let n=t[0],a=-1;for(const i of t){const o=this.scoreElementMatch(i,s);o>a&&(a=o,n=i)}return{status:"success",elements:[n],warnings:[`Multiple matches (${t.length}), selected best-scoring element`],confidence:e.meta.confidence*(.7+a*.2),meta:{degraded:!0,degradationReason:"best-of-multiple"}}}scoreElementMatch(t,e){let s=0,n=0;if(e.id&&(n+=.3,t.id===e.id&&(s+=.3)),e.classes&&e.classes.length>0){n+=.25;const a=Array.from(t.classList),i=e.classes.filter(o=>a.includes(o)).length;s+=i/e.classes.length*.25}if(e.attributes){const a=Object.entries(e.attributes);if(a.length>0){n+=.2;let i=0;for(const[o,c]of a)t.getAttribute(o)===c&&i++;s+=i/a.length*.2}}if(e.role&&(n+=.15,t.getAttribute("role")===e.role&&(s+=.15)),e.text){n+=.1;const a=z(t.textContent);a===e.text.normalized?s+=.1:a.includes(e.text.normalized)&&(s+=.05)}return n>0?s/n:0}}function Ct(r,t,e={}){const s={...lt,...e};let n;try{t instanceof Document?n=t:n=H(t)}catch(p){const S=p instanceof Error?p.message:"Unknown error";return{status:"error",elements:[],warnings:["Failed to resolve document context",S],confidence:0,meta:{degraded:!0,degradationReason:"invalid-context"}}}if(s.root){const p=s.root instanceof Document?s.root:s.root.ownerDocument;p&&p!==n&&console.warn("options.root does not match dom parameter document. Using document from dom parameter. This may indicate a cross-document operation issue.")}const a=s.documentUrl??n.defaultView?.location?.href,i=s.matchUrlsByPathOnly??!0,o=new et,c=new At,l=new Tt,f=new Et,h=o.buildSelector(r,{ensureUnique:!1,root:n});let d;try{d=Array.from(n.querySelectorAll(h))}catch(p){const S=p instanceof Error?p.message:"Unknown selector error";return{status:"error",elements:[],warnings:[`Invalid CSS selector: ${h}`,`Error: ${S}`],confidence:0,meta:{degraded:!0,degradationReason:"invalid-selector"}}}const u=d.length;d.length>s.maxCandidates&&(d=d.slice(0,s.maxCandidates));const g=c.match(d,r.target.semantics,a,i);if(g.length===0&&u>0&&r.target.semantics.text!==void 0){const p=c.matchLenient(d,r.target.semantics,a,i);if(p.length>0){if(p.length===1)return{status:"success",elements:p,warnings:["Used relaxed text matching due to exact match failure"],confidence:r.meta.confidence*.8,meta:{degraded:!0,degradationReason:"relaxed-text-matching"}};const S=xt(p,r,l,f,n,s,1);if(S.elements.length>0)return{...S,warnings:[...S.warnings,"Used relaxed text matching"],confidence:S.confidence*.8}}}if(g.length===1)return{status:"success",elements:g,warnings:[],confidence:r.meta.confidence,meta:{degraded:!1}};if(g.length===0){const p=u>0?`CSS selector found ${u} candidates but semantic filtering rejected all. This may indicate text content mismatch.`:"CSS selector found no candidates";if(s.enableFallback){const S=f.handleFallback(r,n);return{...S,warnings:[...S.warnings,p]}}return{status:"error",elements:[],warnings:["No matching elements found",p],confidence:0,meta:{degraded:!0,degradationReason:"not-found"}}}return xt(g,r,l,f,n,s,1)}function be(r){return[...r].sort((t,e)=>e.priority-t.priority)}function xt(r,t,e,s,n,a,i){let o=r;const c=be(t.constraints);for(const f of c){if(o=e.applyConstraint(o,f),o.length===1)return{status:"success",elements:o,warnings:[],confidence:t.meta.confidence*.9*i,meta:{degraded:!1}};if(o.length===0)return a.enableFallback?s.handleFallback(t,n):{status:"error",elements:[],warnings:["Constraints eliminated all candidates"],confidence:0,meta:{degraded:!0,degradationReason:"over-constrained"}}}if(a.strictMode)return{status:"ambiguous",elements:o,warnings:[`Non-unique resolution: ${o.length} matches`],confidence:t.meta.confidence*.7*i,meta:{degraded:!0,degradationReason:"ambiguous"}};const l=s.handleAmbiguous(o,t);return{...l,confidence:l.confidence*i}}function Se(r){const t=[],e=[];if(r.version?r.version!=="1.0"&&e.push(`Unknown version: ${r.version}`):t.push("Missing version field"),r.anchor?(r.anchor.tag||t.push("Anchor missing tag"),typeof r.anchor.score!="number"&&t.push("Anchor missing score"),r.anchor.semantics||t.push("Anchor missing semantics")):t.push("Missing anchor field"),r.target?(r.target.tag||t.push("Target missing tag"),typeof r.target.score!="number"&&t.push("Target missing score"),r.target.semantics||t.push("Target missing semantics")):t.push("Missing target field"),!Array.isArray(r.path))t.push("Path must be an array");else for(let s=0;s<r.path.length;s++){const n=r.path[s];n.tag||t.push(`Path node ${s} missing tag`),n.semantics||t.push(`Path node ${s} missing semantics`)}return r.meta?(typeof r.meta.confidence!="number"&&e.push("Missing confidence score"),r.meta.generatedAt||e.push("Missing generatedAt timestamp")):t.push("Missing meta field"),Array.isArray(r.constraints)||e.push("Constraints should be an array"),r.fallback||e.push("Missing fallback rules"),{valid:t.length===0,errors:t,warnings:e}}function ye(r){if(!r||typeof r!="object")return!1;const t=r;return typeof t.version=="string"&&typeof t.anchor=="object"&&Array.isArray(t.path)&&typeof t.target=="object"}const wt={id:"i","data-testid":"tid","data-qa":"qa","data-cy":"cy","data-test":"dt","aria-label":"al","aria-labelledby":"alb","aria-describedby":"adb",name:"n",href:"h",src:"s",type:"t",role:"r",alt:"at",title:"tt",for:"f",placeholder:"ph",text:"x"},st=Object.fromEntries(Object.entries(wt).map(([r,t])=>[t,r])),vt={maxClasses:2,maxAttributes:5,includeText:!0,maxTextLength:50,simplifyTarget:!0,includeConstraints:!0,format:"compact"};function Nt(r){return r==="id"?101:v[r]!==void 0?v[r]:r.startsWith("data-")?v["data-*"]:r.startsWith("aria-")?v["aria-*"]:0}function Ae(r){return["id","data-testid","data-qa","data-cy","href","text","role"].includes(r)}function Te(r){return!!(/@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/.test(r)||/(\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/.test(r)||/\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}/.test(r))}function It(r,t){const e={...vt,...t},s=e.format==="compact",n=s?"v1":`v${r.version}`,a=s?":":": ",i=s?"::":" :: ",o=s?">":" > ",c=e.includeText&&r.target.semantics.text?r.target.semantics.text.normalized:void 0,l=rt(r.anchor,!1,e),f=r.path.length>0?r.path.map(u=>rt(u,!1,e,c)).join(o)+o:"",h=rt(r.target,!0,e),d=e.includeConstraints?Ee(r,e):"";return`${n}${a}${l}${i}${f}${h}${d}`}function $t(r){r=r.trim();const t=r.match(/^v(\d+(?:\.\d+)?)\s*:\s*/);if(!t)throw new Error('Invalid SEQL Selector: missing version prefix (expected "v1:")');const e=t[1];if(e!=="1.0"&&e!=="1")throw new Error(`Unsupported SEQL Selector version: v${e} (only v1.0 is supported)`);let s=r.slice(t[0].length);const n=s.match(/^(.+?)\s*::\s*/);if(!n)throw new Error('Invalid SEQL Selector: missing anchor separator "::"');const a=n[1].trim();s=s.slice(n[0].length);const i=s.match(/\s*\{([^}]+)\}\s*$/);let o="";i&&(o=i[1],s=s.slice(0,i.index));const c=s.split(/\s*>\s*/).map(p=>p.trim()).filter(p=>p);if(c.length===0)throw new Error("Invalid SEQL Selector: missing target node");const l=c[c.length-1],f=c.slice(0,-1),h=nt(a,!0),d=f.map(p=>nt(p,!1)),u=nt(l,!1),g=Ce(o);return{version:"1.0",anchor:h,path:d,target:u,constraints:g,fallback:{onMultiple:"best-score",onMissing:"anchor-only",maxDepth:10},meta:{confidence:.7,generatedAt:new Date().toISOString(),generator:"seql-parser@1.0",source:"seql-string",degraded:!1}}}function rt(r,t=!1,e=vt,s){const{tag:n,semantics:a}=r,i=e.format==="compact";let o=n;const c=[],l={...a.attributes};a.id&&(l.id=a.id),a.role&&!l.role&&(l.role=a.role);const f=Object.entries(l).map(([u,g])=>{const m=Nt(u),p=u==="href"||u==="src"?D(u,g):g;return{name:u,value:p,priority:m}}).filter(u=>u.name!=="id"&&u.name!=="class"&&X.has(u.name)||Z.has(u.name)&&K(u.value)?!1:u.priority>0||u.name==="role"||u.name==="id");f.sort((u,g)=>g.priority-u.priority);const h=f.slice(0,e.maxAttributes);h.sort((u,g)=>u.name.localeCompare(g.name));for(const{name:u,value:g}of h){const m=i?wt[u]??u:u;c.push(`${m}="${at(g)}"`)}if(e.includeText&&a.text&&!Te(a.text.normalized)){const u=a.text.normalized;if(u.length>0&&u.length<=e.maxTextLength&&!(!t&&s!==void 0&&u===s)){const m=i?"x":"text";c.push(`${m}="${at(u)}"`)}}let d=c;if(c.length>0&&t&&e.simplifyTarget&&a.id&&(d=c.filter(u=>{const g=u.split("=")[0],m=st[g]??g;return Nt(m)>=60||m==="text"||m==="id"||m==="role"})),a.classes&&a.classes.length>0){const u=L(a.classes),g=!!a.id||c.some(p=>{const S=p.split("=")[0],y=st[S]??S;return y==="href"||y==="data-testid"||y==="text"||y==="role"});if(!(t&&e.simplifyTarget&&g)&&u.length>0){const p=u.sort().slice(0,e.maxClasses);o+=p.map(S=>`.${S}`).join("")}}if(d.length>0&&(o+=`[${d.join(",")}]`),"nthChild"in r&&r.nthChild){const u=!!a.id||a.attributes&&Object.keys(a.attributes).some(Ae);t&&e.simplifyTarget&&u||(o+=`#${r.nthChild}`)}return o}function Ee(r,t){if(!r.constraints||r.constraints.length===0)return"";const e=[];for(const n of r.constraints)switch(n.type){case"uniqueness":e.push("unique=true");break;case"position":n.params&&n.params.strategy&&e.push(`pos=${n.params.strategy}`);break;case"text-proximity":if(n.params&&n.params.reference){const a=at(String(n.params.reference));e.push(`text="${a}"`)}break}return e.length===0?"":`${t.format==="verbose"?" ":""}{${e.join(",")}}`}function nt(r,t){let e=r;const s={},n=e.match(/^([a-z][a-z0-9-]*)/);if(!n)throw new Error(`Invalid node: missing tag name in "${r}"`);const a=n[1];e=e.slice(a.length);const i=[];let o;for(;o=e.match(/^\.([a-zA-Z][a-zA-Z0-9-_]*)/);)i.push(o[1]),e=e.slice(o[0].length);i.length>0&&(s.classes=i);const c=e.match(/^\[([^\]]+)\]/);if(c){const h=c[1],d={},u=xe(h);for(const g of u){const m=g.match(/^([a-z][a-z0-9-]*)(?:=|~=)"((?:[^"\\]|\\.)*)"/);if(m){const[,p,S]=m,y=st[p]??p;d[y]=Rt(S)}}Object.keys(d).length>0&&(d.text&&(s.text={raw:d.text,normalized:d.text},delete d.text),d.id&&(s.id=d.id,delete d.id),d.role&&(s.role=d.role,delete d.role),Object.keys(d).length>0&&(s.attributes=d)),e=e.slice(c[0].length)}let l;const f=e.match(/^#(\d+)/);if(f&&(l=parseInt(f[1],10),e=e.slice(f[0].length)),e.trim())throw new Error(`Invalid node: unexpected content "${e}" in "${r}"`);return t?{tag:a,semantics:s,score:.7,degraded:!1}:{tag:a,semantics:s,score:.7,nthChild:l}}function Ce(r){if(!r.trim())return[];const t=[],e=r.split(",").map(s=>s.trim());for(const s of e){const[n,a]=s.split("=").map(i=>i.trim());switch(n){case"unique":a==="true"&&t.push({type:"uniqueness",params:{mode:"strict"},priority:90});break;case"pos":t.push({type:"position",params:{strategy:a},priority:70});break;case"text":{const i=a.replace(/^"(.*)"$/,"$1");t.push({type:"text-proximity",params:{reference:Rt(i),maxDistance:5},priority:60});break}}}return t}function xe(r){const t=[];let e="",s=!1;for(let n=0;n<r.length;n++){const a=r[n];a==='"'&&(n===0||r[n-1]!=="\\")?(s=!s,e+=a):a===","&&!s?(e.trim()&&t.push(e.trim()),e=""):e+=a}return e.trim()&&t.push(e.trim()),t}function at(r){return r.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/>/g,"\\>").replace(/:/g,"\\:")}function Rt(r){return r.replace(/\\\\/g,"\0").replace(/\\"/g,'"').replace(/\\>/g,">").replace(/\\:/g,":").replace(/\x00/g,"\\")}function we(r,t,e){const s=V(r,t);return s?It(s,e):null}function ve(r,t,e){try{const s=$t(r),n={...e,root:e?.root||t};return Ct(s,t,n).elements||[]}catch(s){return console.error("Failed to resolve SEQL Selector:",s),[]}}const Ne=new Set(["script","style","noscript","meta","link","head","title"]);function it(r){return r.id&&!P(r.id)?3:r.hasAttribute("role")||r.hasAttribute("aria-label")||r.hasAttribute("aria-labelledby")||r.hasAttribute("data-testid")||r.hasAttribute("data-qa")||r.hasAttribute("data-test")?2:1}function Dt(r,t){const e=r.tagName.toLowerCase();return!!(Ne.has(e)||t&&it(r)===1&&!["form","main","nav","section","article","footer","header","button","a","input","label","select","textarea"].includes(e))}function Mt(r){return[...r].sort((t,e)=>{const s=it(t);return it(e)-s})}function Ie(r={}){const t=performance.now();let{root:e,filter:s="*",limit:n=1/0,onProgress:a,progressInterval:i=100,skipNonSemantic:o=!0,generatorOptions:c={},cache:l,signal:f}=r;const h=l??G(),d={...c,cache:h};let u;try{if(e)e instanceof Document,u=Array.from(e.querySelectorAll(s));else if(typeof document<"u")u=Array.from(document.querySelectorAll(s));else throw new Error("Root element or document is required when document is not available")}catch{return{results:[],failed:[],stats:{totalElements:0,successful:0,failed:0,skipped:0,totalTimeMs:0,avgTimePerElementMs:0,cacheHitRate:0}}}if(!e){if(u.length===0)throw new Error("Root element or document is required when no elements are found");const E=H(u[0]);e=E.body||E.documentElement}const g=e instanceof Document?e:H(e);u.forEach((E,A)=>{if(H(E)!==g)throw new Error(`Batch generation requires all elements from the same document. Element at index ${A} is from a different document. If working with iframes, ensure all elements are from the same iframe's contentDocument.`)});const m=u.filter(E=>!Dt(E,o)),S=Mt(m).slice(0,n),y=[],x=[];let C=0;const T=S.length;let I=0;for(let E=0;E<S.length&&!f?.aborted;E++){const A=S[E],F=h.getEID(A);if(F)y.push({element:A,eid:F,generationTimeMs:0});else{const Re=performance.now();try{const k=V(A,d),De=performance.now()-Re;k?y.push({element:A,eid:k,generationTimeMs:De}):C++}catch(k){x.push({element:A,error:k instanceof Error?k.message:String(k)})}}a&&E-I>=i&&(a(E+1,T),I=E)}a&&a(T,T);const O=performance.now()-t,$=h.getStats(),w=$.eidHits+$.eidMisses+$.selectorHits+$.selectorMisses,M=$.eidHits+$.selectorHits,R=w>0?M/w:0;return{results:y,failed:x,stats:{totalElements:T,successful:y.length,failed:x.length,skipped:C,totalTimeMs:O,avgTimePerElementMs:y.length>0?O/y.length:0,cacheHitRate:R}}}function $e(r,t={}){const e=performance.now(),{limit:s=1/0,onProgress:n,progressInterval:a=100,skipNonSemantic:i=!0,generatorOptions:o={},cache:c,signal:l}=t,f=c??G(),h={...o,cache:f},d=r.filter(w=>!Dt(w,i)),g=Mt(d).slice(0,s),m=[],p=[];let S=0;const y=g.length;let x=0;for(let w=0;w<g.length&&!l?.aborted;w++){const M=g[w],R=f.getEID(M);if(R)m.push({element:M,eid:R,generationTimeMs:0});else{const E=performance.now();try{const A=V(M,h),F=performance.now()-E;A?m.push({element:M,eid:A,generationTimeMs:F}):S++}catch(A){p.push({element:M,error:A instanceof Error?A.message:String(A)})}}n&&w-x>=a&&(n(w+1,y),x=w)}n&&n(y,y);const C=performance.now()-e,T=f.getStats(),I=T.eidHits+T.eidMisses+T.selectorHits+T.selectorMisses,O=T.eidHits+T.selectorHits,$=I>0?O/I:0;return{results:m,failed:p,stats:{totalElements:y,successful:m.length,failed:p.length,skipped:S,totalTimeMs:C,avgTimePerElementMs:m.length>0?C/m.length:0,cacheHitRate:$}}}b.AnchorFinder=ht,b.ConstraintsEvaluator=Tt,b.CssGenerator=et,b.DEFAULT_GENERATOR_OPTIONS=ct,b.DEFAULT_RESOLVER_OPTIONS=lt,b.EIDCache=pt,b.EID_VERSION="1.0",b.FallbackHandler=Et,b.MAX_PATH_DEPTH=10,b.PathBuilder=ft,b.ROLE_ANCHOR_VALUES=Y,b.SEMANTIC_ANCHOR_TAGS=Q,b.SEMANTIC_ATTRIBUTES=_t,b.SEMANTIC_TAGS=ot,b.SemanticExtractor=tt,b.SemanticsMatcher=At,b.SvgFingerprinter=gt,b.calculateConfidence=mt,b.calculateElementScore=oe,b.createEIDCache=bt,b.filterClasses=ut,b.generateEID=V,b.generateEIDBatch=Ie,b.generateEIDForElements=$e,b.generateSEQL=we,b.getClassScore=Ft,b.getGlobalCache=G,b.isEID=ye,b.isUtilityClass=J,b.normalizeText=z,b.parseSEQL=$t,b.resetGlobalCache=le,b.resolve=Ct,b.resolveSEQL=ve,b.stringifySEQL=It,b.validateEID=Se,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
11
11
  //# sourceMappingURL=seql-js.umd.cjs.map