@whenessel/seql-js 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/seql-js.js CHANGED
@@ -1,2 +1,2640 @@
1
- const t="1.0",e=10,s=.4,r=.3,n=.2,i=.1,a=.5,o=.3,c=.1,l=.1,h=.05,u=5,d=.05,g=.3,f=.7,m=["form","main","nav","section","article","footer","header"],p=["form","navigation","main","region","contentinfo","complementary","banner","search"],b=["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"],y=["rect","path","circle","line","polyline","polygon","ellipse","g","text","use","defs","clipPath","mask"],x=["aria-label","aria-labelledby","aria-describedby","name","type","data-testid","data-qa","data-test","href","title","placeholder","alt"],S={"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},A=/* @__PURE__ */new Set(["id","class","style","xmlns","tabindex","contenteditable"]),C={maxPathDepth:10,enableSvgFingerprint:!0,confidenceThreshold:.1,fallbackToBody:!0,includeUtilityClasses:!1,source:"dom-dsl"},w={strictMode:!1,enableFallback:!0,maxCandidates:20};function $(t){return!!/^[a-z]+-\d+$/i.test(t)||(!!/^\d+$/.test(t)||(!!/^:[a-z0-9]+:$/i.test(t)||(!!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(t)||(!(!/^[a-z]{1,3}[A-Za-z0-9]{8,}$/.test(t)||!/\d/.test(t)&&!/[A-Z]/.test(t))||(!!/^radix-/.test(t)||!!/^mui-\d+$/.test(t))))))}class v{constructor(t,e){this.maxDepth=t.maxPathDepth??10,this.cache=e}findAnchor(t){if(this.cache){const e=this.cache.getAnchor(t);if(void 0!==e)return e}let e=t.parentElement,s=0,r=null;for(;e&&s<this.maxDepth;){if("body"===e.tagName.toLowerCase())return r||{element:e,score:g,tier:"C",depth:s};const t=this.scoreAnchor(e);if(t>0){const n=this.applyDepthPenalty(t,s),i=this.getTier(e),a={element:e,score:n,tier:i,depth:s};if("A"===i)return a;(!r||n>r.score)&&(r=a)}e=e.parentElement,s++}const n=r;return this.cache&&this.cache.setAnchor(t,n),n}scoreAnchor(t){let e=0;const s=t.tagName.toLowerCase();m.includes(s)&&(e+=a);const r=t.getAttribute("role");r&&p.includes(r)&&(e+=o),(t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby"))&&(e+=c);const n=t.id;return n&&!$(n)&&(e+=l),(t.hasAttribute("data-testid")||t.hasAttribute("data-qa")||t.hasAttribute("data-test"))&&(e+=h),Math.min(e,1)}applyDepthPenalty(t,e){if(e<=u)return t;const s=(e-u)*d;return Math.max(0,t-s)}getTier(t){const e=t.tagName.toLowerCase();if(m.includes(e))return"A";const s=t.getAttribute("role");return s&&p.includes(s)?"B":"C"}}const M=[/^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,}/],q=[/^\[/,/^(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)?:/,/\/([\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)$/,/^(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)-/,/^(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)$/],T=[/^(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 N(t){return M.some(e=>e.test(t))}function k(t){return t.length<=2||(!!/^\d/.test(t)||q.some(e=>e.test(t)))}function E(t){return t.filter(t=>{return!N(e=t)&&!k(e);var e})}function H(t){if(N(t)||k(t))return 0;let e=.5;return function(t){return!N(t)&&!k(t)&&T.some(e=>e.test(t))}(t)&&(e=.8),t.length<3?e*=.3:t.length<5&&(e*=.6),/\d/.test(t)&&(e*=.7),Math.min(e,1)}function z(t){const e=[],s=[];for(const r of t)k(r)||N(r)?s.push(r):e.push(r);return{semantic:e,utility:s}}function j(t){return k(t)||N(t)}function D(t){return H(t)}const F=t=>t.replace(/([#:.[\]@])/g,"\\$1");class L{constructor(t,e){this.maxDepth=t.maxPathDepth??10,this.cache=e}buildPath(t,e,s){const r=[];let n=e.parentElement;for(;n&&n!==t&&r.length<this.maxDepth;)r.unshift(n),n=n.parentElement;const i=r.length>=this.maxDepth&&n!==t;let a=this.filterNoise(r);a=this.ensureUniqueness(r,a,t,e,s);return{path:a.map(t=>{const e=t.parentElement;let r;if(e){const s=Array.from(e.children).indexOf(t);-1!==s&&(r=s+1)}return{tag:t.tagName.toLowerCase(),semantics:s.extract(t),score:s.scoreElement(t),nthChild:r}}),degraded:i,degradationReason:i?"path-depth-overflow":void 0}}buildPathNodes(t,e,s){return this.buildPath(t,e,s).path}ensureUniqueness(t,e,s,r,n){const i=this.buildTestSelector(s,e,r);try{const a=r.ownerDocument;if(!a)return e;let o;if(this.cache){const t=this.cache.getSelectorResults(i);void 0!==t?o=t:(o=Array.from(a.querySelectorAll(i)),this.cache.setSelectorResults(i,o))}else o=a.querySelectorAll(i);if(o.length<=1)return e;const c=t.filter(t=>!e.includes(t));for(const i of c){if(n.scoreElement(i)<f)continue;const c=this.insertNodeInOrder(e,i,t),l=this.buildTestSelector(s,c,r);try{let t;if(this.cache){const e=this.cache.getSelectorResults(l);void 0!==e?t=e:(t=Array.from(a.querySelectorAll(l)),this.cache.setSelectorResults(l,t))}else t=a.querySelectorAll(l);if(1===t.length)return c;t.length<o.length&&(e=c)}catch{}}return e}catch{return e}}insertNodeInOrder(t,e,s){const r=s.indexOf(e),n=[...t];let i=0;for(let a=0;a<n.length;a++){if(s.indexOf(n[a])>r)break;i=a+1}return n.splice(i,0,e),n}buildTestSelector(t,e,s){const r=[];r.push(this.elementToSelector(t));for(const n of e)r.push(this.elementToSelector(n));return r.push(this.elementToSelector(s)),r.join(" ")}elementToSelector(t){let e=t.tagName.toLowerCase();t.id&&!$(t.id)&&(e+=`#${F(t.id)}`);for(const s of Array.from(t.classList))j(s)||(e+=`.${F(s)}`);return e}filterNoise(t){return t.filter(t=>this.shouldInclude(t))}shouldInclude(t){const e=t.tagName.toLowerCase();return!!b.includes(e)||("div"===e||"span"===e)&&this.hasSemanticFeatures(t)}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||$(e))}}function U(t){return t?t.trim().replace(/[\n\t\r]/g," ").replace(/\s+/g," "):""}const R={preserveQueryForAbsolute:!0,removeDynamicHashes:!0};function P(t,e,s={}){if(!e)return e;const r={...R,...s};return"href"===t||"src"===t?function(t,e){if(!t)return t;const s=t.startsWith("http://")||t.startsWith("https://");let[r,n]=t.split("#");const[i,a]=r.split("?");let o=i;return s&&e.preserveQueryForAbsolute&&a&&(o+=`?${a}`),n&&(e.removeDynamicHashes&&function(t){return!!t&&[/\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(t))}(n)||(o+=`#${n}`)),o}(e,r):e}class O{constructor(t,e){this.includeUtilityClasses=t.includeUtilityClasses??!1,this.cache=e}extract(t){if(this.cache){const e=this.cache.getSemantics(t);if(void 0!==e)return e}const e={},s=t.id;if(s&&!$(s)&&(e.id=s),t.classList.length>0){const s=Array.from(t.classList);if(this.includeUtilityClasses)e.classes=s;else{const{semantic:t}=z(s);t.length>0&&(e.classes=t)}}const r=this.extractAttributes(t);Object.keys(r).length>0&&(e.attributes=r);const n=t.getAttribute("role");if(n&&(e.role=n),this.shouldExtractText(t)){const s=this.extractText(t);s&&(e.text=s)}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!!A.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 void 0!==S[t]?S[t]:t.startsWith("data-")?S["data-*"]:t.startsWith("aria-")?S["aria-*"]:0}isDynamicValue(t){return[/^[a-f0-9]{32,}$/i,/^\d{10,}$/,/^(undefined|null|\[object)/,/^{{.*}}$/].some(e=>e.test(t))}extractAttributes(t){const e={};for(const s of Array.from(t.attributes)){const t=s.name;if(this.shouldIgnoreAttribute(t))continue;if(0===this.getAttributePriority(t))continue;const r="href"===t||"src"===t?P(t,s.value):s.value;r&&""!==r.trim()&&(this.isDynamicValue(r)||(e[t]=r))}return e}extractText(t){const e=this.getDirectTextContent(t);if(!e)return null;const s=U(e);if(!s)return null;const r=100;return{raw:e.length>r?e.slice(0,r)+"...":e,normalized:s.length>r?s.slice(0,r)+"...":s}}getDirectTextContent(t){const e=[];for(const s of Array.from(t.childNodes))if(s.nodeType===Node.TEXT_NODE&&s.textContent){const t=s.textContent.trim();t&&e.push(t)}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 I{fingerprint(t){const e=t.tagName.toLowerCase(),s=this.getShape(e),r={shape:s,hasAnimation:this.hasAnimation(t)};if("path"===s){const e=t.getAttribute("d");e&&(r.dHash=this.computePathHash(e))}else["circle","rect","ellipse","line"].includes(s)&&(r.geomHash=this.computeGeomHash(t,s));const n=t.getAttribute("role");n&&(r.role=n);const i=t.querySelector("title");return i?.textContent&&(r.titleText=i.textContent.trim()),r}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(e=>e===t)??"path"}normalizePathData(t){return(t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi)??[]).slice(0,5).map(t=>t.trim().replace(/(-?\d+\.?\d*)/g,t=>parseFloat(t).toFixed(1))).join(" ")}computeGeomHash(t,e){const s=[];switch(e){case"circle":s.push(`r=${t.getAttribute("r")??"0"}`);break;case"rect":{const e=parseFloat(t.getAttribute("width")??"0"),r=parseFloat(t.getAttribute("height")??"0");e>0&&r>0&&s.push(`ratio=${(e/r).toFixed(2)}`)}break;case"ellipse":{const e=parseFloat(t.getAttribute("rx")??"0"),r=parseFloat(t.getAttribute("ry")??"0");e>0&&r>0&&s.push(`ratio=${(e/r).toFixed(2)}`)}break;case"line":{const e=parseFloat(t.getAttribute("x1")??"0"),r=parseFloat(t.getAttribute("y1")??"0"),n=parseFloat(t.getAttribute("x2")??"0"),i=parseFloat(t.getAttribute("y2")??"0"),a=Math.atan2(i-r,n-e);s.push(`angle=${a.toFixed(2)}`)}}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("none"!==s.animationName||"all"!==s.transitionProperty&&"none"!==s.transitionProperty)return!0}catch{}return!1}simpleHash(t){let e=0;for(let s=0;s<t.length;s++){e=(e<<5)-e+t.charCodeAt(s),e&=e}return Math.abs(e).toString(16).padStart(8,"0")}}function W(t,e=0){const a=t.anchor.score,o=t.path.length>0?t.path.reduce((t,e)=>t+e.score,0)/t.path.length:.5,c=t.target.score,l=a*s+o*r+c*n+e*i,h=t.anchor.degraded?.2:0;return Math.max(0,Math.min(1,l-h))}function B(t,e,s){let r=.5;return e&&(r+=.2),s&&(r+=.15),r+=Math.min(.05*t,.15),Math.min(r,1)}class Q{constructor(t){this.cache=/* @__PURE__ */new Map,this.maxSize=t}get(t){if(!this.cache.has(t))return;const e=this.cache.get(t);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 t=this.cache.keys().next().value;void 0!==t&&this.cache.delete(t)}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 Z{constructor(t={}){this.eidCache=/* @__PURE__ */new WeakMap,this.selectorResultCache=new Q(t.maxSelectorCacheSize??1e3),this.anchorCache=/* @__PURE__ */new WeakMap,this.semanticsCache=/* @__PURE__ */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(void 0!==e)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(void 0!==e)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(void 0!==e)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=t+(this.stats.eidMisses+this.stats.selectorMisses+this.stats.anchorMisses+this.stats.semanticsMisses);return e>0?t/e:0}}function V(t){return new Z(t)}let G=null;function _(){return G||(G=V()),G}function J(){G=null}function X(e,s={}){if(!e||!e.ownerDocument)return null;if(!e.isConnected)return null;const r={...C,...s},n=r.cache??_(),i=n.getEID(e);if(void 0!==i)return i;const a=new v(r,n),o=new L(r,n),c=new O(r,n),l=new I,h=a.findAnchor(e);if(!h&&!r.fallbackToBody)return null;const u=h?.element??e.ownerDocument?.body??null;if(!u)return null;const d=!h||"C"===h.tier,f=c.extract(u),m={tag:u.tagName.toLowerCase(),semantics:f,score:h?.score??g,degraded:d},p=o.buildPath(u,e,c),b=c.extract(e);var y;r.enableSvgFingerprint&&("http://www.w3.org/2000/svg"===(y=e).namespaceURI||"svg"===y.tagName.toLowerCase()||y instanceof SVGElement)&&(b.svg=l.fingerprint(e));const x=e.parentElement;let S;if(x){const t=Array.from(x.children).indexOf(e);-1!==t&&(S=t+1)}const A={tag:e.tagName.toLowerCase(),semantics:b,score:c.scoreElement(e),nthChild:S},w=m.degraded||p.degraded,$=function(t,e){if(t&&e.degraded)return"anchor-and-path-degraded";if(t)return"no-semantic-anchor";if(e.degraded)return e.degradationReason;return}(m.degraded,p),M={version:t,anchor:m,path:p.path,target:A,constraints:[],fallback:{onMultiple:"best-score",onMissing:"anchor-only",maxDepth:3},meta:{confidence:0,generatedAt:/* @__PURE__ */(new Date).toISOString(),generator:`dom-eid@${t}`,source:r.source,degraded:w,degradationReason:$}};return M.meta.confidence=W(M),M.meta.confidence<r.confidenceThreshold?null:(n.setEID(e,M),M)}class K{buildSelector(t,e){if(0===t.path.length&&t.anchor.tag===t.target.tag&&JSON.stringify(t.anchor.semantics)===JSON.stringify(t.target.semantics)){const s=this.buildNodeSelector(t.target.tag,t.target.semantics,{excludeClasses:!1});return e?.ensureUnique?this.ensureUniqueSelector(s,t,e):s}const s=[],r=e?.ensureUnique?this.ensureUniqueAnchor(t,e.root??document):this.buildNodeSelector(t.anchor.tag,t.anchor.semantics);s.push(r);for(const l of t.path){let t=this.buildNodeSelector(l.tag,l.semantics);if(void 0!==l.nthChild){["tr","td","th","thead","tbody","tfoot"].includes(l.tag);t+=`:nth-child(${l.nthChild})`}s.push(t)}let n=this.buildNodeSelector(t.target.tag,t.target.semantics,{excludeClasses:e?.ensureUnique});if(void 0!==t.target.nthChild){["tr","td","th","thead","tbody","tfoot"].includes(t.target.tag);n+=`:nth-child(${t.target.nthChild})`}s.push(n);const i=this.isSvgChildElement(t.target.tag),a=t.path.some(t=>"svg"===t.tag);let o;if(i&&a){const e=t.path.findIndex(t=>"svg"===t.tag);if(-1!==e){const t=e+1,r=s.slice(0,t+1),n=s.slice(t+1,-1),i=s[s.length-1];o=n.length>0?r.join(" ")+" > "+n.join(" > ")+" > "+i:r.join(" ")+" > "+i}else o=s.join(" ")}else o=s.join(" ");if(!e?.ensureUnique)return o;const c=this.querySelectorSafe(o,e.root??document);if(1===c.length)return{selector:o,isUnique:!0,usedNthOfType:o.includes(":nth-"),extraClassesAdded:0};if(0===c.length||c.length>1){const s=this.buildFullDomPathSelector(t,t.target.semantics,e.root??document);if(s&&this.isUnique(s,e.root??document))return{selector:s,isUnique:!0,usedNthOfType:s.includes(":nth-"),extraClassesAdded:0}}return this.ensureUniqueSelector(o,t,e)}buildAnchorSelector(t){return this.buildNodeSelector(t.anchor.tag,t.anchor.semantics)}ensureUniqueSelector(t,e,s){const r=s.root??document,n=s.maxClasses??4,i=e.target.tag,a=e.target.semantics;let o=t,c=0,l=!1;if(0===this.querySelectorSafe(o,r).length){const t=this.buildFullDomPathSelector(e,a,r);if(t&&(o=t,this.isUnique(o,r)))return{selector:o,isUnique:!0,usedNthOfType:!1,extraClassesAdded:0}}if(this.isUnique(o,r))return{selector:o,isUnique:!0,usedNthOfType:!1,extraClassesAdded:0};const h=E(a.classes??[]);for(let d=0;d<Math.min(h.length,n);d++){const t=h[d];if(o+=`.${this.escapeCSS(t)}`,c++,this.isUnique(o,r))return{selector:o,isUnique:!0,usedNthOfType:!1,extraClassesAdded:c}}if(!this.isUnique(o,r)){const t=this.buildFullDomPathSelector(e,a,r);if(t&&this.isUnique(t,r))return{selector:t,isUnique:!0,usedNthOfType:t.includes(":nth-of-type("),extraClassesAdded:c}}const u=this.findNthElementByText(o,a,r);return u&&(o+=this.getNthSelector(u,i),l=!0),{selector:o,isUnique:this.isUnique(o,r),usedNthOfType:l,extraClassesAdded:c}}buildFullDomPathSelector(t,e,s){const r=this.buildNodeSelector(t.anchor.tag,t.anchor.semantics),n=this.querySelectorSafe(r,s);if(0===n.length)return null;for(const i of n){const r=this.findTargetWithinAnchor(i,t.target.tag,e);if(0===r.length)continue;const n=r.map(e=>({element:e,score:this.scorePathMatch(e,i,t.path)}));n.sort((t,e)=>e.score-t.score);for(const{element:e}of n){const r=this.buildPathFromAnchorToTarget(i,e,t,s);if(r&&this.isUnique(r,s))return r}}return null}scorePathMatch(t,e,s){const r=[];let n=t.parentElement;for(;n&&n!==e;)r.unshift(n),n=n.parentElement;let i=0;const a=Math.min(r.length,s.length);for(let o=0;o<a;o++){const t=r[o],e=s[o];if(t.tagName.toLowerCase()===e.tag){if(i+=10,void 0!==e.nthChild){const s=t.parentElement;if(s){Array.from(s.children).indexOf(t)+1===e.nthChild?i+=20:i-=10}}}else i-=5;if(e.semantics.classes&&e.semantics.classes.length>0){i+=2*e.semantics.classes.filter(e=>t.classList.contains(e)).length}if(e.semantics.attributes){i+=3*Object.entries(e.semantics.attributes).filter(([e,s])=>t.getAttribute(e)===s).length}}return i-=2*Math.abs(r.length-s.length),i}findTargetWithinAnchor(t,e,s){return Array.from(t.querySelectorAll(e)).filter(t=>{if(s.text){const e=t.textContent?.trim()||"",r=s.text.normalized;if(!e.includes(r)&&!r.includes(e))return!1}if(s.classes&&s.classes.length>0){if(s.classes.every(e=>t.classList.contains(e)))return!0}if(s.attributes){if(Object.entries(s.attributes).every(([e,s])=>{const r=t.getAttribute(e);return"href"===e||"src"===e?P(e,r||"")===P(e,s):r===s}))return!0}return!!s.text})}disambiguateParent(t,e,s,r,n){if(s?.semantics?.attributes){const t=this.buildNodeSelector(e,s.semantics,{excludeClasses:!0}),i=[...r,e].join(" > "),a=this.querySelectorSafe(i,n),o=[...r,t].join(" > "),c=this.querySelectorSafe(o,n);if(c.length>0&&c.length<a.length)return t}if(s?.semantics?.classes){const t=E(s.semantics.classes);if(t.length>0){const s=`${e}.${this.escapeCSS(t[0])}`,i=[...r,e].join(" > "),a=this.querySelectorSafe(i,n),o=[...r,s].join(" > "),c=this.querySelectorSafe(o,n);if(c.length>0&&c.length<a.length)return s}}const i=t.parentElement;if(i){if(Array.from(i.children).filter(t=>t.tagName.toLowerCase()===e).length>1)return`${e}${this.getNthSelector(t,e)}`}return e}buildPathFromAnchorToTarget(t,e,s,r){const n=[];let i=e;for(;i&&i!==t;)n.unshift(i),i=i.parentElement;if(i!==t)return null;const a=[()=>{const t=this.buildNodeSelector(s.anchor.tag,s.anchor.semantics),e=s.target.tag,n=s.target.semantics,i=[];for(const r of s.path)i.push(r.tag);const a=[t,...i,e].filter(Boolean).join(" ");if(this.isUnique(a,r))return a;const o=this.buildNodeSelector(e,n,{excludeClasses:!0}),c=[t,...i.slice(0,-1),o].join(" ");return this.isUnique(c,r)?c:null},()=>{const t=[this.buildNodeSelector(s.anchor.tag,s.anchor.semantics)],e=/* @__PURE__ */new Map;let i=0;for(let r=0;r<n.length-1;r++){const t=n[r],a=t.tagName.toLowerCase();i<s.path.length&&s.path[i].tag===a?(e.set(t,s.path[i]),i++):e.set(t,null)}for(let o=0;o<n.length;o++){const i=n[o],a=i.tagName.toLowerCase();if(o<n.length-1){const s=e.get(i)||null,n=this.disambiguateParent(i,a,s,t,r);t.push(n);continue}const c=this.buildNodeSelector(s.target.tag,s.target.semantics,{excludeClasses:!0}),l=i.parentElement;if(l&&["td","th","tr","thead","tbody","tfoot"].includes(a)){Array.from(l.children).filter(t=>t.tagName.toLowerCase()===a).length>1?t.push(`${c}${this.getNthSelector(i,a)}`):t.push(c)}else t.push(c)}const a=t.join(" > ");return this.isUnique(a,r)?a:null},()=>{const t=[this.buildNodeSelector(s.anchor.tag,s.anchor.semantics)];for(let a=0;a<n.length-1;a++){const e=n[a].tagName.toLowerCase(),i=s.path[a]||null,o=t.join(" ")+" "+e;if(this.querySelectorSafe(o,r).length>1){if(i?.semantics?.attributes){const n=this.buildNodeSelector(e,i.semantics,{excludeClasses:!0}),a=t.join(" ")+" "+n;if(1===this.querySelectorSafe(a,r).length||1===this.querySelectorSafe(a+" "+s.target.tag,r).length){t.push(n);continue}}if(i?.semantics?.classes){const n=E(i.semantics.classes);if(n.length>0){const i=`${e}.${this.escapeCSS(n[0])}`,a=t.join(" ")+" "+i;if(1===this.querySelectorSafe(a,r).length||1===this.querySelectorSafe(a+" "+s.target.tag,r).length){t.push(i);continue}}}const o=n[a],c=o.parentElement;if(c){if(Array.from(c.children).filter(t=>t.tagName.toLowerCase()===e).length>1){t.push(`${e}${this.getNthSelector(o,e)}`);continue}}}t.push(e)}const e=this.buildNodeSelector(s.target.tag,s.target.semantics,{excludeClasses:!0});t.push(e);const i=t.join(" ");return this.isUnique(i,r)?i:null},()=>{const t=this.buildNodeSelector(s.anchor.tag,s.anchor.semantics),e=[];for(const r of s.path)e.push(r.tag);if(0===E(s.target.semantics.classes??[]).length)return null;const n=this.buildNodeSelector(s.target.tag,s.target.semantics,{maxClasses:1}),i=[t,...e.slice(0,-1),n].join(" ");return this.isUnique(i,r)?i:null},()=>{const t=this.buildNodeSelector(s.anchor.tag,s.anchor.semantics),e=[];for(const r of s.path)e.push(r.tag);const i=n[n.length-1],a=i.parentElement;if(!a)return null;if(Array.from(a.children).filter(t=>t.tagName.toLowerCase()===s.target.tag).length<=1)return null;const o=this.buildNodeSelector(s.target.tag,s.target.semantics,{excludeClasses:!0})+this.getNthSelector(i,s.target.tag),c=[t,...e.slice(0,-1),o].join(" ");return this.isUnique(c,r)?c:null}];for(const o of a){const t=o();if(t)return t}return null}buildElementSelector(t){const e=t.tagName.toLowerCase();let s=e;if(t.id&&!this.isDynamicId(t.id))return`${e}#${this.escapeCSS(t.id)}`;const r=E(Array.from(t.classList));r.length>0&&(s+=r.slice(0,2).map(t=>`.${this.escapeCSS(t)}`).join(""));const n=t.getAttribute("role");return n&&(s+=`[role="${this.escapeAttr(n)}"]`),s}isDynamicId(t){return[/^[a-f0-9]{8,}$/i,/^\d{5,}$/,/^(r|react|ember|vue)[\d_]/i,/:r\d+:$/].some(e=>e.test(t))}querySelectorSafe(t,e){try{return Array.from(e.querySelectorAll(t))}catch{return[]}}findNthElementByText(t,e,s){const r=this.querySelectorSafe(t,s);if(r.length<=1)return null;if(e.text){const t=e.text.normalized;for(const e of r){const s=e.textContent?.trim()||"";if(s===t||s.includes(t)||t.includes(s))return e}}return null}isUnique(t,e){try{return 1===e.querySelectorAll(t).length}catch{return!1}}getNthOfTypeIndex(t,e){const s=t.parentElement;if(!s)return null;const r=Array.from(s.children).filter(t=>t.tagName.toLowerCase()===e).indexOf(t);return-1!==r?r+1:null}ensureUniqueAnchor(t,e){const s=t.anchor.tag,r=t.anchor.semantics;if(this.isUnique(s,e))return s;if(r.classes&&r.classes.length>0){const t=E(r.classes);if(t.length>0){const r=`${s}.${this.escapeCSS(t[0])}`;if(this.isUnique(r,e))return r}}if(r.attributes){const t=this.getSortedAttributes(r.attributes);for(const{name:r,value:n}of t){const t="href"===r||"src"===r?P(r,n):n;if(t){const n=`${s}[${r}="${this.escapeAttr(t)}"]`;if(this.isUnique(n,e))return n}}}const n=Array.from(e.querySelectorAll(s));if(n.length>1){const t=this.findElementBySemantics(n,r);if(t){const e=this.getNthOfTypeIndex(t,s);if(e)return`${s}:nth-of-type(${e})`}}return s}findElementBySemantics(t,e){return e.classes&&e.classes.length>0||e.attributes&&Object.keys(e.attributes).length>0||e.text?t.find(t=>{if(e.classes&&e.classes.length>0){if(e.classes.every(e=>t.classList.contains(e)))return!0}if(e.attributes){if(Object.entries(e.attributes).every(([e,s])=>t.getAttribute(e)===s))return!0}if(e.text){const s=t.textContent?.trim()||"",r=e.text.normalized;if(s.includes(r)||r.includes(s))return!0}return!1})||null:t.length>0?t[0]:null}getNthSelector(t,e){const s=t.parentElement;if(!s)return"";const r=Array.from(s.children),n=r.indexOf(t)+1;if(["tr","td","th","thead","tbody","tfoot"].includes(e))return`:nth-child(${n})`;return`:nth-of-type(${r.filter(t=>t.tagName.toLowerCase()===e).indexOf(t)+1})`}getAttributePriority(t){return void 0!==S[t]?S[t]:t.startsWith("data-")?S["data-*"]:t.startsWith("aria-")?S["aria-*"]:0}shouldIgnoreAttribute(t){return!!A.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(([t])=>!this.shouldIgnoreAttribute(t)).map(([t,e])=>({name:t,value:e,priority:this.getAttributePriority(t)})).filter(t=>t.priority>0).sort((t,e)=>e.priority-t.priority)}buildNodeSelector(t,e,s){let r=t;if(e.id)return r+=`#${this.escapeCSS(e.id)}`,r;if(e.attributes){const t=this.getSortedAttributes(e.attributes);for(const{name:e,value:s}of t){const t="href"===e||"src"===e?P(e,s):s;t&&(r+=`[${e}="${this.escapeAttr(t)}"]`)}}if(e.role&&!e.attributes?.role&&(r+=`[role="${this.escapeAttr(e.role)}"]`),!s?.excludeClasses&&e.classes&&e.classes.length>0){const t=E(e.classes);r+=(void 0!==s?.maxClasses?t.slice(0,s.maxClasses):t).map(t=>`.${this.escapeCSS(t)}`).join("")}return r}escapeCSS(t){return t.replace(/([!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g,"\\$1")}escapeAttr(t){return t.replace(/"/g,'\\"').replace(/\\/g,"\\\\")}isSvgChildElement(t){return y.includes(t)}}class Y{match(t,e){return t.filter(t=>this.matchElement(t,e))}matchElement(t,e){return!(e.text&&!this.matchText(t,e.text))&&(!(e.attributes&&!this.matchAttributes(t,e.attributes))&&!(e.svg&&!this.matchSvgFingerprint(t,e.svg)))}matchText(t,e){const s=Array.from(t.childNodes).filter(t=>t.nodeType===Node.TEXT_NODE).map(t=>t.textContent?.trim()??"").join(" ")||(t.textContent?.trim()??"");if(!s)return!1;const r=U(s);return"partial"===e.matchMode?r.includes(e.normalized):r===e.normalized}matchAttributes(t,e){for(const[s,r]of Object.entries(e)){if(t.getAttribute(s)!==r)return!1}return!0}matchSvgFingerprint(t,e){if(t.tagName.toLowerCase()!==e.shape)return!1;if(e.dHash&&"path"===e.shape){const s=t.getAttribute("d");if(s){if(this.computePathHash(s)!==e.dHash)return!1}}if(e.geomHash&&["circle","rect","ellipse","line"].includes(e.shape)){if(this.computeGeomHash(t,e.shape)!==e.geomHash)return!1}if(e.titleText){const s=t.querySelector("title");if(s?.textContent?.trim()!==e.titleText)return!1}return!0}computePathHash(t){const e=(t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi)??[]).slice(0,5).map(t=>t.trim().replace(/(-?\d+\.?\d*)/g,t=>parseFloat(t).toFixed(1))).join(" ");return this.simpleHash(e)}computeGeomHash(t,e){const s=[];switch(e){case"circle":s.push(`r=${t.getAttribute("r")??"0"}`);break;case"rect":{const e=parseFloat(t.getAttribute("width")??"0"),r=parseFloat(t.getAttribute("height")??"0");e>0&&r>0&&s.push(`ratio=${(e/r).toFixed(2)}`);break}case"ellipse":{const e=parseFloat(t.getAttribute("rx")??"0"),r=parseFloat(t.getAttribute("ry")??"0");e>0&&r>0&&s.push(`ratio=${(e/r).toFixed(2)}`);break}case"line":{const e=parseFloat(t.getAttribute("x1")??"0"),r=parseFloat(t.getAttribute("y1")??"0"),n=parseFloat(t.getAttribute("x2")??"0"),i=parseFloat(t.getAttribute("y2")??"0"),a=Math.atan2(i-r,n-e);s.push(`angle=${a.toFixed(2)}`);break}}return this.simpleHash(s.join(";"))}simpleHash(t){let e=0;for(let s=0;s<t.length;s++){e=(e<<5)-e+t.charCodeAt(s),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(t=>{const s=t.textContent?.trim()??"";return this.levenshteinDistance(s,e.reference)<=e.maxDistance})}applyPosition(t,e){if(t.length<=1)return t;switch(e.strategy){case"first-in-dom":default:return[t[0]];case"top-most":return[this.getTopMost(t)];case"left-most":return[this.getLeftMost(t)]}}getTopMost(t){return t.reduce((t,e)=>{try{const s=t.getBoundingClientRect();return e.getBoundingClientRect().top<s.top?e:t}catch{return t}})}getLeftMost(t){return t.reduce((t,e)=>{try{const s=t.getBoundingClientRect();return e.getBoundingClientRect().left<s.left?e:t}catch{return t}})}levenshteinDistance(t,e){if(t===e)return 0;if(0===t.length)return e.length;if(0===e.length)return t.length;const s=Array.from({length:e.length+1},(t,e)=>e);for(let r=1;r<=t.length;r++){let n=r;for(let i=1;i<=e.length;i++){const a=t[r-1]===e[i-1]?s[i-1]:Math.min(s[i-1],n,s[i])+1;s[i-1]=n,n=a}s[e.length]=n}return s[e.length]}}class et{constructor(){this.cssGenerator=new K}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),r=e instanceof Document?e:e.ownerDocument??e;try{const e=r.querySelector(s);if(e)return{status:"degraded-fallback",elements:[e],warnings:["Target not found, returning anchor"],confidence:.3*t.meta.confidence,meta:{degraded:!0,degradationReason:"anchor-fallback"}}}catch(n){return{status:"error",elements:[],warnings:[`Invalid anchor selector: ${n instanceof Error?n.message:"Unknown selector error"}`],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:.7*e.meta.confidence,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:.5*e.meta.confidence,meta:{degraded:!0,degradationReason:"multiple-matches"}}}}selectBestScoring(t,e){const s=e.target.semantics;let r=t[0],n=-1;for(const i of t){const t=this.scoreElementMatch(i,s);t>n&&(n=t,r=i)}return{status:"success",elements:[r],warnings:[`Multiple matches (${t.length}), selected best-scoring element`],confidence:e.meta.confidence*(.7+.2*n),meta:{degraded:!0,degradationReason:"best-of-multiple"}}}scoreElementMatch(t,e){let s=0,r=0;if(e.id&&(r+=.3,t.id===e.id&&(s+=.3)),e.classes&&e.classes.length>0){r+=.25;const n=Array.from(t.classList);s+=e.classes.filter(t=>n.includes(t)).length/e.classes.length*.25}if(e.attributes){const n=Object.entries(e.attributes);if(n.length>0){r+=.2;let e=0;for(const[s,r]of n)t.getAttribute(s)===r&&e++;s+=e/n.length*.2}}if(e.role&&(r+=.15,t.getAttribute("role")===e.role&&(s+=.15)),e.text){r+=.1;const n=U(t.textContent);n===e.text.normalized?s+=.1:n.includes(e.text.normalized)&&(s+=.05)}return r>0?s/r:0}}function st(t,e,s={}){const r={...w,...s},n=new K,i=new Y,a=new tt,o=new et,c=e instanceof Document?e:e.ownerDocument??e,l=n.buildSelector(t,{ensureUnique:!1,root:c});let h;try{h=Array.from(c.querySelectorAll(l))}catch(m){return{status:"error",elements:[],warnings:[`Invalid CSS selector: ${l}`,`Error: ${m instanceof Error?m.message:"Unknown selector error"}`],confidence:0,meta:{degraded:!0,degradationReason:"invalid-selector"}}}h.length>r.maxCandidates&&(h=h.slice(0,r.maxCandidates));const u=i.match(h,t.target.semantics);if(1===u.length)return{status:"success",elements:u,warnings:[],confidence:t.meta.confidence,meta:{degraded:!1}};if(0===u.length)return r.enableFallback?o.handleFallback(t,c):{status:"error",elements:[],warnings:["No matching elements found"],confidence:0,meta:{degraded:!0,degradationReason:"not-found"}};let d=u;const g=(f=t.constraints,[...f].sort((t,e)=>e.priority-t.priority));var f;for(const p of g){if(d=a.applyConstraint(d,p),1===d.length)return{status:"success",elements:d,warnings:[],confidence:.9*t.meta.confidence,meta:{degraded:!1}};if(0===d.length)return r.enableFallback?o.handleFallback(t,c):{status:"error",elements:[],warnings:["Constraints eliminated all candidates"],confidence:0,meta:{degraded:!0,degradationReason:"over-constrained"}}}return r.strictMode?{status:"ambiguous",elements:d,warnings:[`Non-unique resolution: ${d.length} matches`],confidence:.7*t.meta.confidence,meta:{degraded:!0,degradationReason:"ambiguous"}}:o.handleAmbiguous(d,t)}function rt(t){const e=[],s=[];if(t.version?"1.0"!==t.version&&s.push(`Unknown version: ${t.version}`):e.push("Missing version field"),t.anchor?(t.anchor.tag||e.push("Anchor missing tag"),"number"!=typeof t.anchor.score&&e.push("Anchor missing score"),t.anchor.semantics||e.push("Anchor missing semantics")):e.push("Missing anchor field"),t.target?(t.target.tag||e.push("Target missing tag"),"number"!=typeof t.target.score&&e.push("Target missing score"),t.target.semantics||e.push("Target missing semantics")):e.push("Missing target field"),Array.isArray(t.path))for(let r=0;r<t.path.length;r++){const s=t.path[r];s.tag||e.push(`Path node ${r} missing tag`),s.semantics||e.push(`Path node ${r} missing semantics`)}else e.push("Path must be an array");return t.meta?("number"!=typeof t.meta.confidence&&s.push("Missing confidence score"),t.meta.generatedAt||s.push("Missing generatedAt timestamp")):e.push("Missing meta field"),Array.isArray(t.constraints)||s.push("Constraints should be an array"),t.fallback||s.push("Missing fallback rules"),{valid:0===e.length,errors:e,warnings:s}}function nt(t){if(!t||"object"!=typeof t)return!1;const e=t;return"string"==typeof e.version&&"object"==typeof e.anchor&&Array.isArray(e.path)&&"object"==typeof e.target}const it={maxClasses:2,maxAttributes:5,includeText:!0,maxTextLength:50,simplifyTarget:!0,includeConstraints:!0};function at(t){return"id"===t?101:void 0!==S[t]?S[t]:t.startsWith("data-")?S["data-*"]:t.startsWith("aria-")?S["aria-*"]:0}function ot(t){return["id","data-testid","data-qa","data-cy","href","text","role"].includes(t)}function ct(t,e){const s={...it,...e},r=`v${t.version}`,n=ht(t.anchor,!1,s),i=t.path.length>0?t.path.map(t=>ht(t,!1,s)).join(" > ")+" > ":"",a=ht(t.target,!0,s),o=s.includeConstraints?function(t){if(!t.constraints||0===t.constraints.length)return"";const e=[];for(const s of t.constraints)switch(s.type){case"uniqueness":e.push("unique=true");break;case"position":s.params&&s.params.strategy&&e.push(`pos=${s.params.strategy}`);break;case"text-proximity":if(s.params&&s.params.reference){const t=dt(String(s.params.reference));e.push(`text="${t}"`)}}if(0===e.length)return"";return` {${e.join(",")}}`}(t):"";return`${r}: ${n} :: ${i}${a}${o}`}function lt(t){const e=(t=t.trim()).match(/^v(\d+(?:\.\d+)?)\s*:\s*/);if(!e)throw new Error('Invalid SEQL Selector: missing version prefix (expected "v1:")');const s=e[1];if("1.0"!==s&&"1"!==s)throw new Error(`Unsupported SEQL Selector version: v${s} (only v1.0 is supported)`);let r=t.slice(e[0].length);const n=r.match(/^(.+?)\s*::\s*/);if(!n)throw new Error('Invalid SEQL Selector: missing anchor separator "::"');const i=n[1].trim();r=r.slice(n[0].length);const a=r.match(/\s*\{([^}]+)\}\s*$/);let o="";a&&(o=a[1],r=r.slice(0,a.index));const c=r.split(/\s*>\s*/).map(t=>t.trim()).filter(t=>t);if(0===c.length)throw new Error("Invalid SEQL Selector: missing target node");const l=c[c.length-1],h=c.slice(0,-1),u=ut(i,!0),d=h.map(t=>ut(t,!1)),g=ut(l,!1),f=function(t){if(!t.trim())return[];const e=[],s=t.split(",").map(t=>t.trim());for(const r of s){const[t,s]=r.split("=").map(t=>t.trim());switch(t){case"unique":"true"===s&&e.push({type:"uniqueness",params:{mode:"strict"},priority:90});break;case"pos":e.push({type:"position",params:{strategy:s},priority:70});break;case"text":const t=s.replace(/^"(.*)"$/,"$1");e.push({type:"text-proximity",params:{reference:gt(t),maxDistance:5},priority:60})}}return e}(o);return{version:"1.0",anchor:u,path:d,target:g,constraints:f,fallback:{onMultiple:"best-score",onMissing:"anchor-only",maxDepth:10},meta:{confidence:.7,generatedAt:/* @__PURE__ */(new Date).toISOString(),generator:"seql-parser@1.0",source:"seql-string",degraded:!1}}}function ht(t,e=!1,s=it){const{tag:r,semantics:n}=t;let i=r;const a=[],o={...n.attributes};n.id&&(o.id=n.id),n.role&&!o.role&&(o.role=n.role);const c=Object.entries(o).map(([t,e])=>{const s=at(t);return{name:t,value:"href"===t||"src"===t?P(t,e):e,priority:s}}).filter(t=>!["style","xmlns","tabindex","contenteditable"].includes(t.name)&&(t.priority>0||"role"===t.name||"id"===t.name));c.sort((t,e)=>e.priority-t.priority);const l=c.slice(0,s.maxAttributes);l.sort((t,e)=>t.name.localeCompare(e.name));for(const{name:u,value:d}of l)a.push(`${u}="${dt(d)}"`);if(s.includeText&&n.text&&(h=n.text.normalized,!(/@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/.test(h)||/(\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/.test(h)||/\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}/.test(h)))){const t=n.text.normalized;t.length>0&&t.length<=s.maxTextLength&&a.push(`text="${dt(t)}"`)}var h;if(a.length>0){let t=a;e&&s.simplifyTarget&&n.id&&(t=a.filter(t=>{const e=t.split("=")[0];return at(e)>=60||"text"===e||"id"===e||"role"===e})),t.length>0&&(t.sort((t,e)=>t.localeCompare(e)),i+=`[${t.join(",")}]`)}if(n.classes&&n.classes.length>0){const t=E(n.classes),r=!!n.id||a.some(t=>t.startsWith("href=")||t.startsWith("data-testid=")||t.startsWith("text=")||t.startsWith("role="));if(!(e&&s.simplifyTarget&&r)&&t.length>0){i+=t.sort().slice(0,s.maxClasses).map(t=>`.${t}`).join("")}}if("nthChild"in t&&t.nthChild){const r=!!n.id||n.attributes&&Object.keys(n.attributes).some(ot);e&&s.simplifyTarget&&r||(i+=`#${t.nthChild}`)}return i}function ut(t,e){let s=t;const r={},n=s.match(/^([a-z][a-z0-9-]*)/);if(!n)throw new Error(`Invalid node: missing tag name in "${t}"`);const i=n[1];s=s.slice(i.length);const a=[];let o;for(;o=s.match(/^\.([a-zA-Z][a-zA-Z0-9-_]*)/);)a.push(o[1]),s=s.slice(o[0].length);a.length>0&&(r.classes=a);const c=s.match(/^\[([^\]]+)\]/);if(c){const t={},e=function(t){const e=[];let s="",r=!1;for(let n=0;n<t.length;n++){const i=t[n];'"'!==i||0!==n&&"\\"===t[n-1]?","!==i||r?s+=i:(s.trim()&&e.push(s.trim()),s=""):(r=!r,s+=i)}s.trim()&&e.push(s.trim());return e}(c[1]);for(const s of e){const e=s.match(/^([a-z][a-z0-9-]*)(?:=|~=)"((?:[^"\\]|\\.)*)"/);if(e){const[,s,r]=e;t[s]=gt(r)}}Object.keys(t).length>0&&(t.text&&(r.text={raw:t.text,normalized:t.text},delete t.text),t.id&&(r.id=t.id,delete t.id),t.role&&(r.role=t.role,delete t.role),Object.keys(t).length>0&&(r.attributes=t)),s=s.slice(c[0].length)}let l;const h=s.match(/^#(\d+)/);if(h&&(l=parseInt(h[1],10),s=s.slice(h[0].length)),s.trim())throw new Error(`Invalid node: unexpected content "${s}" in "${t}"`);return e?{tag:i,semantics:r,score:.7,degraded:!1}:{tag:i,semantics:r,score:.7,nthChild:l}}function dt(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/>/g,"\\>").replace(/:/g,"\\:")}function gt(t){return t.replace(/\\\\/g,"\0").replace(/\\"/g,'"').replace(/\\>/g,">").replace(/\\:/g,":").replace(/\x00/g,"\\")}function ft(t,e,s){const r=X(t,e);return r?ct(r,s):null}function mt(t,e,s){try{const r=lt(t);return st(r,e,s).elements||[]}catch(r){return console.error("Failed to resolve SEQL Selector:",r),[]}}const pt=/* @__PURE__ */new Set(["script","style","noscript","meta","link","head","title"]);function bt(t){return t.id&&!$(t.id)?3:t.hasAttribute("role")||t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby")||t.hasAttribute("data-testid")||t.hasAttribute("data-qa")||t.hasAttribute("data-test")?2:1}function yt(t,e){const s=t.tagName.toLowerCase();if(pt.has(s))return!0;if(e){if(1===bt(t)){if(!["form","main","nav","section","article","footer","header","button","a","input","label","select","textarea"].includes(s))return!0}}return!1}function xt(t){return[...t].sort((t,e)=>{const s=bt(t);return bt(e)-s})}function St(t={}){const e=performance.now(),{root:s=("undefined"!=typeof document?document.body:void 0),filter:r="*",limit:n=1/0,onProgress:i,progressInterval:a=100,skipNonSemantic:o=!0,generatorOptions:c={},cache:l,signal:h}=t;if(!s)throw new Error("Root element or document is required");const u=l??_(),d={...c,cache:u};let g;try{g=(Document,Array.from(s.querySelectorAll(r)))}catch(v){return{results:[],failed:[],stats:{totalElements:0,successful:0,failed:0,skipped:0,totalTimeMs:0,avgTimePerElementMs:0,cacheHitRate:0}}}const f=xt(g.filter(t=>!yt(t,o))).slice(0,n),m=[],p=[];let b=0;const y=f.length;let x=0;for(let M=0;M<f.length&&!h?.aborted;M++){const t=f[M],e=u.getEID(t);if(e)m.push({element:t,eid:e,generationTimeMs:0});else{const e=performance.now();try{const s=X(t,d),r=performance.now()-e;s?m.push({element:t,eid:s,generationTimeMs:r}):b++}catch(v){p.push({element:t,error:v instanceof Error?v.message:String(v)})}}i&&M-x>=a&&(i(M+1,y),x=M)}i&&i(y,y);const S=performance.now()-e,A=u.getStats(),C=A.eidHits+A.eidMisses+A.selectorHits+A.selectorMisses,w=A.eidHits+A.selectorHits,$=C>0?w/C:0;return{results:m,failed:p,stats:{totalElements:y,successful:m.length,failed:p.length,skipped:b,totalTimeMs:S,avgTimePerElementMs:m.length>0?S/m.length:0,cacheHitRate:$}}}function At(t,e={}){const s=performance.now(),{limit:r=1/0,onProgress:n,progressInterval:i=100,skipNonSemantic:a=!0,generatorOptions:o={},cache:c,signal:l}=e,h=c??_(),u={...o,cache:h},d=xt(t.filter(t=>!yt(t,a))).slice(0,r),g=[],f=[];let m=0;const p=d.length;let b=0;for(let $=0;$<d.length&&!l?.aborted;$++){const t=d[$],e=h.getEID(t);if(e)g.push({element:t,eid:e,generationTimeMs:0});else{const e=performance.now();try{const s=X(t,u),r=performance.now()-e;s?g.push({element:t,eid:s,generationTimeMs:r}):m++}catch(w){f.push({element:t,error:w instanceof Error?w.message:String(w)})}}n&&$-b>=i&&(n($+1,p),b=$)}n&&n(p,p);const y=performance.now()-s,x=h.getStats(),S=x.eidHits+x.eidMisses+x.selectorHits+x.selectorMisses,A=x.eidHits+x.selectorHits,C=S>0?A/S:0;return{results:g,failed:f,stats:{totalElements:p,successful:g.length,failed:f.length,skipped:m,totalTimeMs:y,avgTimePerElementMs:g.length>0?y/g.length:0,cacheHitRate:C}}}export{v as AnchorFinder,tt as ConstraintsEvaluator,K as CssGenerator,C as DEFAULT_GENERATOR_OPTIONS,w as DEFAULT_RESOLVER_OPTIONS,Z as EIDCache,t as EID_VERSION,et as FallbackHandler,e as MAX_PATH_DEPTH,L as PathBuilder,p as ROLE_ANCHOR_VALUES,m as SEMANTIC_ANCHOR_TAGS,x as SEMANTIC_ATTRIBUTES,b as SEMANTIC_TAGS,O as SemanticExtractor,Y as SemanticsMatcher,I as SvgFingerprinter,W as calculateConfidence,B as calculateElementScore,V as createEIDCache,z as filterClasses,X as generateEID,St as generateEIDBatch,At as generateEIDForElements,ft as generateSEQL,D as getClassScore,_ as getGlobalCache,nt as isEID,j as isUtilityClass,U as normalizeText,lt as parseSEQL,J as resetGlobalCache,st as resolve,mt as resolveSEQL,ct as stringifySEQL,rt as validateEID};
1
+ const Gt = "1.0", Vt = 10, L = {
2
+ ANCHOR: 0.4,
3
+ PATH: 0.3,
4
+ TARGET: 0.2,
5
+ UNIQUENESS: 0.1
6
+ }, $ = {
7
+ SEMANTIC_TAG: 0.5,
8
+ ROLE: 0.3,
9
+ ARIA_LABEL: 0.1,
10
+ STABLE_ID: 0.1,
11
+ TEST_MARKER: 0.05,
12
+ DEPTH_PENALTY_THRESHOLD: 5,
13
+ DEPTH_PENALTY_FACTOR: 0.05,
14
+ DEGRADED_SCORE: 0.3
15
+ }, ct = {
16
+ MIN_CONFIDENCE_FOR_SKIP: 0.7
17
+ }, Y = [
18
+ "form",
19
+ "main",
20
+ "nav",
21
+ "section",
22
+ "article",
23
+ "footer",
24
+ "header"
25
+ ], K = [
26
+ "form",
27
+ "navigation",
28
+ "main",
29
+ "region",
30
+ "contentinfo",
31
+ "complementary",
32
+ "banner",
33
+ "search"
34
+ ], lt = [
35
+ // HTML5 Semantic
36
+ "article",
37
+ "aside",
38
+ "details",
39
+ "figcaption",
40
+ "figure",
41
+ "footer",
42
+ "header",
43
+ "main",
44
+ "mark",
45
+ "nav",
46
+ "section",
47
+ "summary",
48
+ "time",
49
+ // Form elements
50
+ "button",
51
+ "datalist",
52
+ "fieldset",
53
+ "form",
54
+ "input",
55
+ "label",
56
+ "legend",
57
+ "meter",
58
+ "optgroup",
59
+ "option",
60
+ "output",
61
+ "progress",
62
+ "select",
63
+ "textarea",
64
+ // Interactive
65
+ "a",
66
+ "audio",
67
+ "video",
68
+ "canvas",
69
+ "dialog",
70
+ "menu",
71
+ // Text content
72
+ "blockquote",
73
+ "dd",
74
+ "dl",
75
+ "dt",
76
+ "hr",
77
+ "li",
78
+ "ol",
79
+ "ul",
80
+ "p",
81
+ "pre",
82
+ "h1",
83
+ "h2",
84
+ "h3",
85
+ "h4",
86
+ "h5",
87
+ "h6",
88
+ // Table
89
+ "caption",
90
+ "col",
91
+ "colgroup",
92
+ "table",
93
+ "tbody",
94
+ "td",
95
+ "tfoot",
96
+ "th",
97
+ "thead",
98
+ "tr",
99
+ // SVG
100
+ "svg",
101
+ "path",
102
+ "circle",
103
+ "rect",
104
+ "line",
105
+ "polyline",
106
+ "polygon",
107
+ "ellipse",
108
+ "g",
109
+ "text",
110
+ "use"
111
+ ], ht = [
112
+ "rect",
113
+ "path",
114
+ "circle",
115
+ "line",
116
+ "polyline",
117
+ "polygon",
118
+ "ellipse",
119
+ "g",
120
+ "text",
121
+ "use",
122
+ "defs",
123
+ "clipPath",
124
+ "mask"
125
+ ], Qt = [
126
+ "aria-label",
127
+ "aria-labelledby",
128
+ "aria-describedby",
129
+ "name",
130
+ "type",
131
+ "data-testid",
132
+ "data-qa",
133
+ "data-test",
134
+ "href",
135
+ "title",
136
+ "placeholder",
137
+ "alt"
138
+ ], T = {
139
+ // Test attributes (highest priority)
140
+ "data-testid": 100,
141
+ "data-qa": 99,
142
+ "data-cy": 98,
143
+ "data-test": 97,
144
+ "data-test-id": 96,
145
+ // ARIA (accessibility semantics)
146
+ "aria-label": 90,
147
+ "aria-labelledby": 85,
148
+ "aria-describedby": 80,
149
+ // Semantic HTML attributes
150
+ name: 75,
151
+ href: 70,
152
+ // for <a>
153
+ src: 70,
154
+ // for <img>, <script>, etc.
155
+ type: 65,
156
+ role: 60,
157
+ alt: 55,
158
+ title: 50,
159
+ for: 45,
160
+ placeholder: 40,
161
+ // Any data-* attribute (if not above)
162
+ "data-*": 30,
163
+ // Any aria-* attribute (if not above)
164
+ "aria-*": 25
165
+ }, et = /* @__PURE__ */ new Set([
166
+ "id",
167
+ // handled separately
168
+ "class",
169
+ // handled separately
170
+ "style",
171
+ // unstable
172
+ "xmlns",
173
+ // service attribute for SVG
174
+ "tabindex",
175
+ // can change
176
+ "contenteditable"
177
+ ]), ut = {
178
+ maxPathDepth: 10,
179
+ enableSvgFingerprint: !0,
180
+ confidenceThreshold: 0.1,
181
+ fallbackToBody: !0,
182
+ includeUtilityClasses: !1,
183
+ source: "dom-dsl"
184
+ }, ft = {
185
+ strictMode: !1,
186
+ enableFallback: !0,
187
+ maxCandidates: 20
188
+ };
189
+ function D(n) {
190
+ return !!(/^[a-z]+-\d+$/i.test(n) || /^[a-z]+(-[a-z]+)+-\d+$/i.test(n) || /^[a-z]+(_[a-z]+)*_\d+$/i.test(n) || /^\d+$/.test(n) || /^:[a-z0-9]+:$/i.test(n) || /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(n) || /^[a-z]{1,3}[A-Za-z0-9]{8,}$/.test(n) && (/\d/.test(n) || /[A-Z]/.test(n)) || /^radix-/.test(n) || /^mui-\d+$/.test(n));
191
+ }
192
+ const B = /* @__PURE__ */ new Set([
193
+ "aria-labelledby",
194
+ "aria-describedby",
195
+ "aria-controls",
196
+ "aria-owns",
197
+ "aria-activedescendant",
198
+ "for",
199
+ "form",
200
+ "list",
201
+ "headers",
202
+ "aria-details",
203
+ "aria-errormessage",
204
+ "aria-flowto"
205
+ ]);
206
+ function G(n) {
207
+ return n.trim().split(/\s+/).some((e) => D(e));
208
+ }
209
+ class dt {
210
+ constructor(t, e) {
211
+ this.maxDepth = t.maxPathDepth ?? 10, this.cache = e;
212
+ }
213
+ /**
214
+ * Finds the best anchor element for the target
215
+ * @param target - Target element to find anchor for
216
+ * @returns Anchor result or null if not found
217
+ */
218
+ findAnchor(t) {
219
+ if (this.cache) {
220
+ const a = this.cache.getAnchor(t);
221
+ if (a !== void 0)
222
+ return a;
223
+ }
224
+ let e = t.parentElement, s = 0, r = null;
225
+ for (; e && s < this.maxDepth; ) {
226
+ if (e.tagName.toLowerCase() === "body")
227
+ return r || {
228
+ element: e,
229
+ score: $.DEGRADED_SCORE,
230
+ tier: "C",
231
+ depth: s
232
+ };
233
+ const a = this.scoreAnchor(e);
234
+ if (a > 0) {
235
+ const o = this.applyDepthPenalty(a, s), l = this.getTier(e), h = { element: e, score: o, tier: l, depth: s };
236
+ if (l === "A")
237
+ return h;
238
+ (!r || o > r.score) && (r = h);
239
+ }
240
+ e = e.parentElement, s++;
241
+ }
242
+ const i = r;
243
+ return this.cache && this.cache.setAnchor(t, i), i;
244
+ }
245
+ /**
246
+ * Scores an element as anchor candidate (without depth penalty)
247
+ * @param element - Element to score
248
+ * @returns Raw score from 0 to 1
249
+ */
250
+ scoreAnchor(t) {
251
+ let e = 0;
252
+ const s = t.tagName.toLowerCase();
253
+ Y.includes(s) && (e += $.SEMANTIC_TAG);
254
+ const r = t.getAttribute("role");
255
+ r && K.includes(r) && (e += $.ROLE), (t.hasAttribute("aria-label") || t.hasAttribute("aria-labelledby")) && (e += $.ARIA_LABEL);
256
+ const i = t.id;
257
+ return i && !D(i) && (e += $.STABLE_ID), (t.hasAttribute("data-testid") || t.hasAttribute("data-qa") || t.hasAttribute("data-test")) && (e += $.TEST_MARKER), Math.min(e, 1);
258
+ }
259
+ /**
260
+ * Applies depth penalty to score
261
+ * Following SPECIFICATION.md §7: depthPenalty = (depth - threshold) * factor
262
+ */
263
+ applyDepthPenalty(t, e) {
264
+ if (e <= $.DEPTH_PENALTY_THRESHOLD)
265
+ return t;
266
+ const s = (e - $.DEPTH_PENALTY_THRESHOLD) * $.DEPTH_PENALTY_FACTOR;
267
+ return Math.max(0, t - s);
268
+ }
269
+ /**
270
+ * Determines the tier of an anchor element
271
+ */
272
+ getTier(t) {
273
+ const e = t.tagName.toLowerCase();
274
+ if (Y.includes(e))
275
+ return "A";
276
+ const s = t.getAttribute("role");
277
+ return s && K.includes(s) ? "B" : "C";
278
+ }
279
+ }
280
+ const gt = [
281
+ // CSS-in-JS
282
+ /^css-[a-z0-9]+$/i,
283
+ /^sc-[a-z0-9]+-\d+$/i,
284
+ /^[a-z]{5,8}$/i,
285
+ // Short generated classes (abcdef)
286
+ // Material-UI / MUI
287
+ /^Mui[A-Z]\w+-\w+-\w+/,
288
+ /^makeStyles-\w+-\d+$/,
289
+ // JSS
290
+ /^jss\d+$/,
291
+ // Emotion / Linaria
292
+ /^(emotion|linaria)-[a-z0-9]+/i,
293
+ // Component libraries with hashes
294
+ /^(chakra|tw-|ant-)[a-z0-9]+-\w+/i,
295
+ // Hash-based (hashes in classes)
296
+ /-[a-f0-9]{6,}$/i,
297
+ /^_[a-z0-9]{5,}$/i,
298
+ /\d{5,}/
299
+ // 5+ digits in a row
300
+ ], mt = [
301
+ // === FIX 4: Tailwind arbitrary values and variants (highest priority) ===
302
+ /^\[/,
303
+ // Any arbitrary value or variant starting with [ (e.g., [&_svg]:..., [mask-type:luminance])
304
+ // === FIX 4: Pseudo-class variants (must be before specific patterns) ===
305
+ /^(first|last|odd|even|only|first-of-type|last-of-type|only-of-type):/,
306
+ // first:, last:, etc.
307
+ /^(hover|focus|active|disabled|enabled|checked|indeterminate|default|required|valid|invalid|in-range|out-of-range|placeholder-shown|autofill|read-only):/,
308
+ // State pseudo-classes
309
+ /^(focus-within|focus-visible|visited|target|open):/,
310
+ // Advanced pseudo-classes
311
+ // === FIX 4: Responsive variants (must be before specific patterns) ===
312
+ /^(sm|md|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl):/,
313
+ // === FIX 4: Dark mode and directional variants ===
314
+ /^dark:/,
315
+ /^(rtl|ltr):/,
316
+ // === FIX 4: Group and peer variants ===
317
+ /^(group|peer)(-hover|-focus|-active)?:/,
318
+ // === FIX 4: Tailwind utilities with fraction values ===
319
+ /\/([\d.]+|full|auto|screen)$/,
320
+ // /50, /100, /full, /auto, /screen
321
+ // === FIX 4: Positioning utilities ===
322
+ /^(inset|top|right|bottom|left)(-|$)/,
323
+ // inset-0, top-0, left-0
324
+ // === Layout & Display ===
325
+ /^(flex|inline-flex|grid|block|inline|inline-block|hidden|visible)$/,
326
+ /^(absolute|relative|fixed|sticky|static)$/,
327
+ // === Flexbox & Grid ===
328
+ /^(items|justify|content|self|place)-/,
329
+ /^flex-(row|col|wrap|nowrap|1|auto|initial|none)/,
330
+ /^grid-(cols|rows|flow)/,
331
+ // === Spacing (Tailwind) ===
332
+ /^(gap|space)-/,
333
+ /^[mp][trblxy]?-(\d+|auto|px)$/,
334
+ // === Sizing ===
335
+ /^(w|h|min-w|min-h|max-w|max-h|size)-/,
336
+ // === Colors & Styling ===
337
+ // Note: text-* can be semantic (text-muted, text-primary) or utility (text-center, text-lg)
338
+ // More specific patterns for utility text-* classes
339
+ /^text-(center|left|right|justify|start|end|xs|sm|base|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl|8xl|9xl)$/,
340
+ /^text-(uppercase|lowercase|capitalize|normal-case|underline|line-through|no-underline)$/,
341
+ /^text-(truncate|ellipsis|clip)$/,
342
+ /^(bg|border|ring|shadow|outline)-/,
343
+ /^rounded(-|$)/,
344
+ // === Typography ===
345
+ /^(font|leading|tracking|whitespace|break|truncate)-/,
346
+ /^(uppercase|lowercase|capitalize|normal-case)$/,
347
+ // === Transform & Animation (IMPORTANT!) ===
348
+ /^(transform|transition|duration|delay|ease|animate)-/,
349
+ /^(scale|rotate|translate|skew)-/,
350
+ /^transform$/,
351
+ /^backdrop-blur-/,
352
+ /^motion-/,
353
+ // Framer Motion
354
+ /^(fade|slide|zoom|bounce|pulse|spin|ping)-/,
355
+ // animations
356
+ // === Overflow & Scrolling ===
357
+ /^(overflow|overscroll|scroll)-/,
358
+ // === Interactivity ===
359
+ /^(cursor|pointer-events|select|resize)-/,
360
+ // === Visibility & Opacity ===
361
+ /^(opacity|z)-/,
362
+ /^(visible|invisible|collapse)$/,
363
+ // === Bootstrap utilities ===
364
+ /^d-(none|inline|inline-block|block|grid|table|flex)$/,
365
+ /^(float|clearfix|text)-(left|right|center|justify|start|end)$/,
366
+ /^(m|p)[trblxy]?-[0-5]$/,
367
+ /^(w|h)-(25|50|75|100|auto)$/,
368
+ // Note: btn-* classes are semantic (component classes), not utility
369
+ // /^btn-(primary|secondary|success|danger|warning|info|light|dark|link)$/,
370
+ /^btn-(sm|lg|block)$/,
371
+ // Only size modifiers are utility
372
+ /^text-(muted|primary|success|danger|warning|info|light|dark|white)$/,
373
+ /^bg-(primary|secondary|success|danger|warning|info|light|dark|white|transparent)$/,
374
+ /^border(-top|-bottom|-left|-right)?(-0)?$/,
375
+ /^rounded(-top|-bottom|-left|-right|-circle|-pill|-0)?$/,
376
+ /^shadow(-sm|-lg|-none)?$/,
377
+ /^(align|justify|order|flex)-(start|end|center|between|around|fill|grow|shrink)$/,
378
+ /^col(-sm|-md|-lg|-xl)?(-\d+|-auto)?$/,
379
+ /^row(-cols)?(-\d+)?$/,
380
+ /^g[xy]?-[0-5]$/,
381
+ /^(show|hide|invisible|visible)$/,
382
+ /^(position|top|bottom|start|end)-(static|relative|absolute|fixed|sticky|-\d+)$/,
383
+ // === Common utility patterns ===
384
+ /^(row|col)$/,
385
+ /^clearfix$/,
386
+ /^pull-(left|right)$/,
387
+ /^float-(left|right|none)$/
388
+ ], pt = [
389
+ // === Navigation ===
390
+ /^(nav|menu|header|footer|sidebar|topbar|navbar|breadcrumb)/,
391
+ /(navigation|dropdown|megamenu)$/,
392
+ // === Components ===
393
+ /^(btn|button|link|card|modal|dialog|popup|tooltip|alert|badge|chip)/,
394
+ /^(form|input|select|checkbox|radio|textarea|label|fieldset)/,
395
+ /^(table|list|item|row|cell|column)/,
396
+ /^(accordion|tab|carousel|slider|gallery)/,
397
+ // === Content ===
398
+ /^(content|main|article|post|comment|title|subtitle|description|caption)/,
399
+ /^(hero|banner|jumbotron|section|wrapper|box)/,
400
+ // === User/Data ===
401
+ /^(user|profile|avatar|account|auth)/,
402
+ /^(product|item|price|cart|checkout|order)/,
403
+ // === Layout sections ===
404
+ /^(page|layout|panel|widget|block)/,
405
+ // === States (semantic naming) ===
406
+ /-(primary|secondary|tertiary|success|error|warning|info|danger)$/,
407
+ /-(active|inactive|disabled|enabled|selected|highlighted|focused)$/,
408
+ /-(open|closed|expanded|collapsed|visible|hidden)$/,
409
+ /-(large|medium|small|tiny|xs|sm|md|lg|xl)$/,
410
+ // === Action buttons ===
411
+ /^(submit|cancel|close|delete|edit|save|back|next|prev|search)/,
412
+ // === Status ===
413
+ /^(loading|pending|complete|failed|draft|published)/
414
+ ];
415
+ function q(n) {
416
+ return gt.some((t) => t.test(n));
417
+ }
418
+ function O(n) {
419
+ return n.length <= 2 || /^\d/.test(n) ? !0 : mt.some((t) => t.test(n));
420
+ }
421
+ function bt(n) {
422
+ return q(n) || O(n) ? !1 : pt.some((t) => t.test(n));
423
+ }
424
+ function St(n) {
425
+ return !q(n) && !O(n);
426
+ }
427
+ function I(n) {
428
+ return n.filter((t) => St(t));
429
+ }
430
+ function yt(n) {
431
+ if (q(n) || O(n))
432
+ return 0;
433
+ let t = 0.5;
434
+ return bt(n) && (t = 0.8), n.length < 3 ? t *= 0.3 : n.length < 5 && (t *= 0.6), /\d/.test(n) && (t *= 0.7), Math.min(t, 1);
435
+ }
436
+ function At(n) {
437
+ const t = [], e = [];
438
+ for (const s of n)
439
+ O(s) || q(s) ? e.push(s) : t.push(s);
440
+ return { semantic: t, utility: e };
441
+ }
442
+ function X(n) {
443
+ return O(n) || q(n);
444
+ }
445
+ function Zt(n) {
446
+ return yt(n);
447
+ }
448
+ const J = (n) => n.replace(/([#:.[\]@])/g, "\\$1");
449
+ class xt {
450
+ constructor(t, e) {
451
+ this.maxDepth = t.maxPathDepth ?? 10, this.cache = e;
452
+ }
453
+ /**
454
+ * Builds path from anchor to target (excluding both)
455
+ * @param anchor - Anchor element (start)
456
+ * @param target - Target element (end)
457
+ * @param extractor - Semantic extractor instance
458
+ * @returns Path build result with nodes and degradation info
459
+ */
460
+ buildPath(t, e, s) {
461
+ const r = [];
462
+ let i = e.parentElement;
463
+ for (; i && i !== t && r.length < this.maxDepth; )
464
+ r.unshift(i), i = i.parentElement;
465
+ const a = r.length >= this.maxDepth && i !== t;
466
+ let o = this.filterNoise(r);
467
+ return o = this.ensureUniqueness(
468
+ r,
469
+ o,
470
+ t,
471
+ e,
472
+ s
473
+ ), {
474
+ path: o.map((h) => {
475
+ const c = h.parentElement;
476
+ let u;
477
+ if (c) {
478
+ const g = Array.from(c.children).indexOf(h);
479
+ g !== -1 && (u = g + 1);
480
+ }
481
+ return {
482
+ tag: h.tagName.toLowerCase(),
483
+ semantics: s.extract(h),
484
+ score: s.scoreElement(h),
485
+ nthChild: u
486
+ };
487
+ }),
488
+ degraded: a,
489
+ degradationReason: a ? "path-depth-overflow" : void 0
490
+ };
491
+ }
492
+ /**
493
+ * Legacy method for backward compatibility
494
+ */
495
+ buildPathNodes(t, e, s) {
496
+ return this.buildPath(t, e, s).path;
497
+ }
498
+ /**
499
+ * Ensures path uniqueness by adding nodes if needed
500
+ * Following SPECIFICATION.md §8 Disambiguation Algorithm
501
+ */
502
+ ensureUniqueness(t, e, s, r, i) {
503
+ const a = this.buildTestSelector(s, e, r);
504
+ try {
505
+ const o = r.ownerDocument;
506
+ if (!o) return e;
507
+ let l;
508
+ if (this.cache) {
509
+ const c = this.cache.getSelectorResults(a);
510
+ c !== void 0 ? l = c : (l = Array.from(o.querySelectorAll(a)), this.cache.setSelectorResults(a, l));
511
+ } else
512
+ l = o.querySelectorAll(a);
513
+ if (l.length <= 1)
514
+ return e;
515
+ const h = t.filter((c) => !e.includes(c));
516
+ for (const c of h) {
517
+ if (i.scoreElement(c) < ct.MIN_CONFIDENCE_FOR_SKIP)
518
+ continue;
519
+ const f = this.insertNodeInOrder(e, c, t), g = this.buildTestSelector(s, f, r);
520
+ try {
521
+ let d;
522
+ if (this.cache) {
523
+ const m = this.cache.getSelectorResults(g);
524
+ m !== void 0 ? d = m : (d = Array.from(o.querySelectorAll(g)), this.cache.setSelectorResults(g, d));
525
+ } else
526
+ d = o.querySelectorAll(g);
527
+ if (d.length === 1)
528
+ return f;
529
+ d.length < l.length && (e = f);
530
+ } catch {
531
+ }
532
+ }
533
+ return e;
534
+ } catch {
535
+ return e;
536
+ }
537
+ }
538
+ /**
539
+ * Inserts node into path maintaining original order
540
+ */
541
+ insertNodeInOrder(t, e, s) {
542
+ const r = s.indexOf(e), i = [...t];
543
+ let a = 0;
544
+ for (let o = 0; o < i.length && !(s.indexOf(i[o]) > r); o++)
545
+ a = o + 1;
546
+ return i.splice(a, 0, e), i;
547
+ }
548
+ /**
549
+ * Builds a test CSS selector from path
550
+ */
551
+ buildTestSelector(t, e, s) {
552
+ const r = [];
553
+ r.push(this.elementToSelector(t));
554
+ for (const i of e)
555
+ r.push(this.elementToSelector(i));
556
+ return r.push(this.elementToSelector(s)), r.join(" ");
557
+ }
558
+ /**
559
+ * Converts element to basic CSS selector
560
+ */
561
+ elementToSelector(t) {
562
+ let e = t.tagName.toLowerCase();
563
+ t.id && !D(t.id) && (e += `#${J(t.id)}`);
564
+ for (const s of Array.from(t.classList))
565
+ X(s) || (e += `.${J(s)}`);
566
+ return e;
567
+ }
568
+ /**
569
+ * Filters out noise/layout elements
570
+ */
571
+ filterNoise(t) {
572
+ return t.filter((e) => this.shouldInclude(e));
573
+ }
574
+ /**
575
+ * Determines if element should be included in path
576
+ */
577
+ shouldInclude(t) {
578
+ const e = t.tagName.toLowerCase();
579
+ return lt.includes(e) ? !0 : e === "div" || e === "span" ? this.hasSemanticFeatures(t) : !1;
580
+ }
581
+ /**
582
+ * Checks if element has meaningful semantic features
583
+ */
584
+ hasSemanticFeatures(t) {
585
+ if (t.hasAttribute("role")) return !0;
586
+ for (const s of Array.from(t.attributes))
587
+ if (s.name.startsWith("aria-")) return !0;
588
+ if (t.classList.length > 0) {
589
+ for (const s of Array.from(t.classList))
590
+ if (!X(s)) return !0;
591
+ }
592
+ if (t.hasAttribute("data-testid") || t.hasAttribute("data-qa") || t.hasAttribute("data-test"))
593
+ return !0;
594
+ const e = t.id;
595
+ return !!(e && !D(e));
596
+ }
597
+ }
598
+ function V(n) {
599
+ return n ? n.trim().replace(/[\n\t\r]/g, " ").replace(/\s+/g, " ") : "";
600
+ }
601
+ const Ct = {
602
+ preserveQueryForAbsolute: !0,
603
+ removeDynamicHashes: !0
604
+ };
605
+ function Et(n) {
606
+ return n ? [
607
+ /\d{5,}/,
608
+ // 5+ digits
609
+ /[a-f0-9]{8,}/i,
610
+ // hex hash 8+ characters
611
+ /(session|token|temp|random|timestamp|nonce|cache)/i,
612
+ // dynamic words
613
+ /^\d+$/,
614
+ // only digits
615
+ /^[a-f0-9-]{32,}$/i
616
+ // UUID-like
617
+ ].some((e) => e.test(n)) : !1;
618
+ }
619
+ function Tt(n, t) {
620
+ if (!n) return n;
621
+ const e = n.startsWith("http://") || n.startsWith("https://");
622
+ let [s, r] = n.split("#");
623
+ const [i, a] = s.split("?");
624
+ let o = i;
625
+ return e && t.preserveQueryForAbsolute && a && (o += `?${a}`), r && (t.removeDynamicHashes && Et(r) || (o += `#${r}`)), o;
626
+ }
627
+ function P(n, t, e = {}) {
628
+ if (!t) return t;
629
+ const s = { ...Ct, ...e };
630
+ return n === "href" || n === "src" ? Tt(t, s) : t;
631
+ }
632
+ class wt {
633
+ constructor(t, e) {
634
+ this.includeUtilityClasses = t.includeUtilityClasses ?? !1, this.cache = e;
635
+ }
636
+ /**
637
+ * Extracts semantic features from element
638
+ * @param element - DOM element to extract from
639
+ * @returns Semantic features object
640
+ */
641
+ extract(t) {
642
+ if (this.cache) {
643
+ const a = this.cache.getSemantics(t);
644
+ if (a !== void 0)
645
+ return a;
646
+ }
647
+ const e = {}, s = t.id;
648
+ if (s && !D(s) && (e.id = s), t.classList.length > 0) {
649
+ const a = Array.from(t.classList);
650
+ if (this.includeUtilityClasses)
651
+ e.classes = a;
652
+ else {
653
+ const { semantic: o } = At(a);
654
+ o.length > 0 && (e.classes = o);
655
+ }
656
+ }
657
+ const r = this.extractAttributes(t);
658
+ Object.keys(r).length > 0 && (e.attributes = r);
659
+ const i = t.getAttribute("role");
660
+ if (i && (e.role = i), this.shouldExtractText(t)) {
661
+ const a = this.extractText(t);
662
+ a && (e.text = a);
663
+ }
664
+ return this.cache && this.cache.setSemantics(t, e), e;
665
+ }
666
+ /**
667
+ * Scores element based on semantic richness
668
+ * @param element - Element to score
669
+ * @returns Score from 0 to 1
670
+ */
671
+ scoreElement(t) {
672
+ let e = 0.5;
673
+ const s = this.extract(t);
674
+ return s.id && (e += 0.15), s.classes && s.classes.length > 0 && (e += 0.1), s.attributes && Object.keys(s.attributes).length > 0 && (e += 0.1), s.role && (e += 0.1), s.text && (e += 0.05), Math.min(e, 1);
675
+ }
676
+ /**
677
+ * Checks if attribute should be ignored
678
+ * @param attrName - Attribute name
679
+ * @returns True if should be ignored
680
+ */
681
+ shouldIgnoreAttribute(t) {
682
+ return !!(et.has(t) || t.startsWith("on") || t.startsWith("ng-") || t.startsWith("_ng") || t.startsWith("data-reactid") || t.startsWith("data-react") || t.startsWith("data-v-"));
683
+ }
684
+ /**
685
+ * Gets attribute priority
686
+ * @param attrName - Attribute name
687
+ * @returns Priority number (higher = more priority)
688
+ */
689
+ getAttributePriority(t) {
690
+ return T[t] !== void 0 ? T[t] : t.startsWith("data-") ? T["data-*"] : t.startsWith("aria-") ? T["aria-*"] : 0;
691
+ }
692
+ /**
693
+ * Checks if attribute value is dynamic (should be ignored)
694
+ * @param value - Attribute value
695
+ * @returns True if value is dynamic
696
+ */
697
+ isDynamicValue(t) {
698
+ return [
699
+ /^[a-f0-9]{32,}$/i,
700
+ // Long hashes
701
+ /^\d{10,}$/,
702
+ // Timestamp
703
+ /^(undefined|null|\[object)/,
704
+ // JS artifacts
705
+ /^{{.*}}$/
706
+ // Template literals
707
+ ].some((s) => s.test(t));
708
+ }
709
+ /**
710
+ * Extracts relevant semantic attributes from element
711
+ * Iterates through all attributes and filters by priority
712
+ */
713
+ extractAttributes(t) {
714
+ const e = {};
715
+ for (const s of Array.from(t.attributes)) {
716
+ const r = s.name;
717
+ if (this.shouldIgnoreAttribute(r) || B.has(r) && G(s.value) || this.getAttributePriority(r) === 0) continue;
718
+ const a = r === "href" || r === "src" ? P(r, s.value) : s.value;
719
+ !a || a.trim() === "" || this.isDynamicValue(a) || (e[r] = a);
720
+ }
721
+ return e;
722
+ }
723
+ /**
724
+ * Extracts and normalizes text content
725
+ */
726
+ extractText(t) {
727
+ const e = this.getDirectTextContent(t);
728
+ if (!e) return null;
729
+ const s = V(e);
730
+ if (!s) return null;
731
+ const r = 100, i = e.length > r ? e.slice(0, r) + "..." : e, a = s.length > r ? s.slice(0, r) + "..." : s;
732
+ return {
733
+ raw: i,
734
+ normalized: a
735
+ };
736
+ }
737
+ /**
738
+ * Gets direct text content excluding child elements
739
+ */
740
+ getDirectTextContent(t) {
741
+ const e = [];
742
+ for (const s of Array.from(t.childNodes))
743
+ if (s.nodeType === Node.TEXT_NODE && s.textContent) {
744
+ const r = s.textContent.trim();
745
+ r && e.push(r);
746
+ }
747
+ return e.length > 0 ? e.join(" ") : t.textContent ?? null;
748
+ }
749
+ /**
750
+ * Determines if text should be extracted for this element
751
+ */
752
+ shouldExtractText(t) {
753
+ const e = t.tagName.toLowerCase();
754
+ return [
755
+ "button",
756
+ "a",
757
+ "label",
758
+ "h1",
759
+ "h2",
760
+ "h3",
761
+ "h4",
762
+ "h5",
763
+ "h6",
764
+ "p",
765
+ "span",
766
+ "li",
767
+ "th",
768
+ "td",
769
+ "dt",
770
+ "dd",
771
+ "legend",
772
+ "figcaption",
773
+ "summary"
774
+ ].includes(e);
775
+ }
776
+ }
777
+ class vt {
778
+ /**
779
+ * Generates fingerprint for SVG element
780
+ * @param element - SVG element to fingerprint
781
+ * @returns SVG fingerprint object
782
+ */
783
+ fingerprint(t) {
784
+ const e = t.tagName.toLowerCase(), s = this.getShape(e), r = {
785
+ shape: s,
786
+ hasAnimation: this.hasAnimation(t)
787
+ };
788
+ if (s === "path") {
789
+ const o = t.getAttribute("d");
790
+ o && (r.dHash = this.computePathHash(o));
791
+ } else ["circle", "rect", "ellipse", "line"].includes(s) && (r.geomHash = this.computeGeomHash(t, s));
792
+ const i = t.getAttribute("role");
793
+ i && (r.role = i);
794
+ const a = t.querySelector("title");
795
+ return a?.textContent && (r.titleText = a.textContent.trim()), r;
796
+ }
797
+ /**
798
+ * Computes hash from path data (first N commands)
799
+ * @param d - SVG path d attribute value
800
+ * @returns Hash string
801
+ */
802
+ computePathHash(t) {
803
+ const e = this.normalizePathData(t);
804
+ return this.simpleHash(e);
805
+ }
806
+ /**
807
+ * Gets the shape type from tag name
808
+ */
809
+ getShape(t) {
810
+ return [
811
+ "path",
812
+ "circle",
813
+ "rect",
814
+ "line",
815
+ "polyline",
816
+ "polygon",
817
+ "ellipse",
818
+ "g",
819
+ "text",
820
+ "use",
821
+ "svg"
822
+ ].find((s) => s === t) ?? "path";
823
+ }
824
+ /**
825
+ * Normalizes path data for consistent hashing
826
+ */
827
+ normalizePathData(t) {
828
+ return (t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi) ?? []).slice(0, 5).map((r) => r.trim().replace(/(-?\d+\.?\d*)/g, (i) => parseFloat(i).toFixed(1))).join(" ");
829
+ }
830
+ /**
831
+ * Computes geometry hash for non-path shapes
832
+ */
833
+ computeGeomHash(t, e) {
834
+ const s = [];
835
+ switch (e) {
836
+ case "circle":
837
+ s.push(`r=${t.getAttribute("r") ?? "0"}`);
838
+ break;
839
+ case "rect":
840
+ {
841
+ const r = parseFloat(t.getAttribute("width") ?? "0"), i = parseFloat(t.getAttribute("height") ?? "0");
842
+ r > 0 && i > 0 && s.push(`ratio=${(r / i).toFixed(2)}`);
843
+ }
844
+ break;
845
+ case "ellipse":
846
+ {
847
+ const r = parseFloat(t.getAttribute("rx") ?? "0"), i = parseFloat(t.getAttribute("ry") ?? "0");
848
+ r > 0 && i > 0 && s.push(`ratio=${(r / i).toFixed(2)}`);
849
+ }
850
+ break;
851
+ case "line":
852
+ {
853
+ const r = parseFloat(t.getAttribute("x1") ?? "0"), i = parseFloat(t.getAttribute("y1") ?? "0"), a = parseFloat(t.getAttribute("x2") ?? "0"), o = parseFloat(t.getAttribute("y2") ?? "0"), l = Math.atan2(o - i, a - r);
854
+ s.push(`angle=${l.toFixed(2)}`);
855
+ }
856
+ break;
857
+ }
858
+ return this.simpleHash(s.join(";"));
859
+ }
860
+ /**
861
+ * Detects animations on SVG element
862
+ */
863
+ hasAnimation(t) {
864
+ if (t.querySelector("animate, animateTransform, animateMotion"))
865
+ return !0;
866
+ const e = t.ownerDocument;
867
+ if (e?.defaultView)
868
+ try {
869
+ const s = e.defaultView.getComputedStyle(t);
870
+ if (s.animationName !== "none" || s.transitionProperty !== "all" && s.transitionProperty !== "none")
871
+ return !0;
872
+ } catch {
873
+ }
874
+ return !1;
875
+ }
876
+ /**
877
+ * Simple hash function for fingerprinting (not cryptographic)
878
+ */
879
+ simpleHash(t) {
880
+ let e = 0;
881
+ for (let s = 0; s < t.length; s++) {
882
+ const r = t.charCodeAt(s);
883
+ e = (e << 5) - e + r, e = e & e;
884
+ }
885
+ return Math.abs(e).toString(16).padStart(8, "0");
886
+ }
887
+ }
888
+ function $t(n, t = 0) {
889
+ const e = n.anchor.score, s = n.path.length > 0 ? n.path.reduce((o, l) => o + l.score, 0) / n.path.length : 0.5, r = n.target.score, i = e * L.ANCHOR + s * L.PATH + r * L.TARGET + t * L.UNIQUENESS, a = n.anchor.degraded ? 0.2 : 0;
890
+ return Math.max(0, Math.min(1, i - a));
891
+ }
892
+ function Yt(n, t, e) {
893
+ let s = 0.5;
894
+ return t && (s += 0.2), e && (s += 0.15), s += Math.min(n * 0.05, 0.15), Math.min(s, 1);
895
+ }
896
+ class Mt {
897
+ constructor(t) {
898
+ this.cache = /* @__PURE__ */ new Map(), this.maxSize = t;
899
+ }
900
+ get(t) {
901
+ if (!this.cache.has(t)) return;
902
+ const e = this.cache.get(t);
903
+ return this.cache.delete(t), this.cache.set(t, e), e;
904
+ }
905
+ set(t, e) {
906
+ if (this.cache.has(t))
907
+ this.cache.delete(t);
908
+ else if (this.cache.size >= this.maxSize) {
909
+ const s = this.cache.keys().next().value;
910
+ s !== void 0 && this.cache.delete(s);
911
+ }
912
+ this.cache.set(t, e);
913
+ }
914
+ has(t) {
915
+ return this.cache.has(t);
916
+ }
917
+ delete(t) {
918
+ this.cache.delete(t);
919
+ }
920
+ clear() {
921
+ this.cache.clear();
922
+ }
923
+ get size() {
924
+ return this.cache.size;
925
+ }
926
+ }
927
+ class It {
928
+ constructor(t = {}) {
929
+ this.eidCache = /* @__PURE__ */ new WeakMap(), this.selectorResultCache = new Mt(
930
+ t.maxSelectorCacheSize ?? 1e3
931
+ ), this.anchorCache = /* @__PURE__ */ new WeakMap(), this.semanticsCache = /* @__PURE__ */ new WeakMap(), this.stats = {
932
+ eidHits: 0,
933
+ eidMisses: 0,
934
+ selectorHits: 0,
935
+ selectorMisses: 0,
936
+ anchorHits: 0,
937
+ anchorMisses: 0,
938
+ semanticsHits: 0,
939
+ semanticsMisses: 0,
940
+ selectorCacheSize: 0,
941
+ maxSelectorCacheSize: t.maxSelectorCacheSize ?? 1e3
942
+ };
943
+ }
944
+ /**
945
+ * Get cached EID for element
946
+ */
947
+ getEID(t) {
948
+ const e = this.eidCache.get(t);
949
+ if (e !== void 0)
950
+ return this.stats.eidHits++, e;
951
+ this.stats.eidMisses++;
952
+ }
953
+ /**
954
+ * Cache EID for element
955
+ */
956
+ setEID(t, e) {
957
+ this.eidCache.set(t, e);
958
+ }
959
+ /**
960
+ * Get cached selector results
961
+ */
962
+ getSelectorResults(t) {
963
+ const e = this.selectorResultCache.get(t);
964
+ if (e !== void 0)
965
+ return this.stats.selectorHits++, this.stats.selectorCacheSize = this.selectorResultCache.size, e;
966
+ this.stats.selectorMisses++, this.stats.selectorCacheSize = this.selectorResultCache.size;
967
+ }
968
+ /**
969
+ * Cache selector results
970
+ */
971
+ setSelectorResults(t, e) {
972
+ this.selectorResultCache.set(t, e), this.stats.selectorCacheSize = this.selectorResultCache.size;
973
+ }
974
+ /**
975
+ * Get cached anchor result
976
+ */
977
+ getAnchor(t) {
978
+ if (this.anchorCache.has(t))
979
+ return this.stats.anchorHits++, this.anchorCache.get(t);
980
+ this.stats.anchorMisses++;
981
+ }
982
+ /**
983
+ * Cache anchor result
984
+ */
985
+ setAnchor(t, e) {
986
+ this.anchorCache.set(t, e);
987
+ }
988
+ /**
989
+ * Get cached semantics
990
+ */
991
+ getSemantics(t) {
992
+ const e = this.semanticsCache.get(t);
993
+ if (e !== void 0)
994
+ return this.stats.semanticsHits++, e;
995
+ this.stats.semanticsMisses++;
996
+ }
997
+ /**
998
+ * Cache semantics
999
+ */
1000
+ setSemantics(t, e) {
1001
+ this.semanticsCache.set(t, e);
1002
+ }
1003
+ /**
1004
+ * Clear all caches
1005
+ */
1006
+ clear() {
1007
+ this.selectorResultCache.clear(), this.stats.selectorCacheSize = 0, this.stats = {
1008
+ eidHits: 0,
1009
+ eidMisses: 0,
1010
+ selectorHits: 0,
1011
+ selectorMisses: 0,
1012
+ anchorHits: 0,
1013
+ anchorMisses: 0,
1014
+ semanticsHits: 0,
1015
+ semanticsMisses: 0,
1016
+ selectorCacheSize: 0,
1017
+ maxSelectorCacheSize: this.stats.maxSelectorCacheSize
1018
+ };
1019
+ }
1020
+ /**
1021
+ * Invalidate cache for a specific element
1022
+ * Note: WeakMaps don't support deletion, but we can clear selector cache
1023
+ * if needed. This method is mainly for future extensibility.
1024
+ */
1025
+ invalidateElement(t) {
1026
+ }
1027
+ /**
1028
+ * Invalidate a specific selector from cache
1029
+ */
1030
+ invalidateSelector(t) {
1031
+ this.selectorResultCache.delete(t), this.stats.selectorCacheSize = this.selectorResultCache.size;
1032
+ }
1033
+ /**
1034
+ * Get cache statistics
1035
+ */
1036
+ getStats() {
1037
+ return {
1038
+ ...this.stats,
1039
+ selectorCacheSize: this.selectorResultCache.size
1040
+ };
1041
+ }
1042
+ /**
1043
+ * Get cache hit rate for EID cache
1044
+ */
1045
+ getEIDHitRate() {
1046
+ const t = this.stats.eidHits + this.stats.eidMisses;
1047
+ return t > 0 ? this.stats.eidHits / t : 0;
1048
+ }
1049
+ /**
1050
+ * Get cache hit rate for selector cache
1051
+ */
1052
+ getSelectorHitRate() {
1053
+ const t = this.stats.selectorHits + this.stats.selectorMisses;
1054
+ return t > 0 ? this.stats.selectorHits / t : 0;
1055
+ }
1056
+ /**
1057
+ * Get cache hit rate for anchor cache
1058
+ */
1059
+ getAnchorHitRate() {
1060
+ const t = this.stats.anchorHits + this.stats.anchorMisses;
1061
+ return t > 0 ? this.stats.anchorHits / t : 0;
1062
+ }
1063
+ /**
1064
+ * Get cache hit rate for semantics cache
1065
+ */
1066
+ getSemanticsHitRate() {
1067
+ const t = this.stats.semanticsHits + this.stats.semanticsMisses;
1068
+ return t > 0 ? this.stats.semanticsHits / t : 0;
1069
+ }
1070
+ /**
1071
+ * Get overall cache hit rate
1072
+ */
1073
+ getOverallHitRate() {
1074
+ 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;
1075
+ return s > 0 ? t / s : 0;
1076
+ }
1077
+ }
1078
+ function Nt(n) {
1079
+ return new It(n);
1080
+ }
1081
+ let _ = null;
1082
+ function Q() {
1083
+ return _ || (_ = Nt()), _;
1084
+ }
1085
+ function Kt() {
1086
+ _ = null;
1087
+ }
1088
+ function Z(n, t = {}) {
1089
+ if (!n || !n.ownerDocument || !n.isConnected)
1090
+ return null;
1091
+ const e = { ...ut, ...t }, s = e.cache ?? Q(), r = s.getEID(n);
1092
+ if (r !== void 0)
1093
+ return r;
1094
+ const i = new dt(e, s), a = new xt(e, s), o = new wt(e, s), l = new vt(), h = i.findAnchor(n);
1095
+ if (!h && !e.fallbackToBody)
1096
+ return null;
1097
+ const c = h?.element ?? n.ownerDocument?.body ?? null;
1098
+ if (!c) return null;
1099
+ const u = !h || h.tier === "C", f = o.extract(c), g = {
1100
+ tag: c.tagName.toLowerCase(),
1101
+ semantics: f,
1102
+ score: h?.score ?? $.DEGRADED_SCORE,
1103
+ degraded: u
1104
+ }, d = a.buildPath(
1105
+ c,
1106
+ n,
1107
+ o
1108
+ ), m = o.extract(n);
1109
+ e.enableSvgFingerprint && Rt(n) && (m.svg = l.fingerprint(n));
1110
+ const p = n.parentElement;
1111
+ let S;
1112
+ if (p) {
1113
+ const C = Array.from(p.children).indexOf(n);
1114
+ C !== -1 && (S = C + 1);
1115
+ }
1116
+ const y = {
1117
+ tag: n.tagName.toLowerCase(),
1118
+ semantics: m,
1119
+ score: o.scoreElement(n),
1120
+ nthChild: S
1121
+ }, w = [], A = {
1122
+ onMultiple: "best-score",
1123
+ onMissing: "anchor-only",
1124
+ maxDepth: 3
1125
+ }, b = g.degraded || d.degraded, v = Dt(g.degraded, d), x = {
1126
+ version: "1.0",
1127
+ anchor: g,
1128
+ path: d.path,
1129
+ target: y,
1130
+ constraints: w,
1131
+ fallback: A,
1132
+ meta: {
1133
+ confidence: 0,
1134
+ // Calculated below
1135
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
1136
+ generator: "dom-eid@1.0",
1137
+ source: e.source,
1138
+ degraded: b,
1139
+ degradationReason: v
1140
+ }
1141
+ };
1142
+ return x.meta.confidence = $t(x), x.meta.confidence < e.confidenceThreshold ? null : (s.setEID(n, x), x);
1143
+ }
1144
+ function Rt(n) {
1145
+ return n.namespaceURI === "http://www.w3.org/2000/svg" || n.tagName.toLowerCase() === "svg" || n instanceof SVGElement;
1146
+ }
1147
+ function Dt(n, t) {
1148
+ if (n && t.degraded)
1149
+ return "anchor-and-path-degraded";
1150
+ if (n)
1151
+ return "no-semantic-anchor";
1152
+ if (t.degraded)
1153
+ return t.degradationReason;
1154
+ }
1155
+ class st {
1156
+ buildSelector(t, e) {
1157
+ if (t.path.length === 0 && t.anchor.tag === t.target.tag && JSON.stringify(t.anchor.semantics) === JSON.stringify(t.target.semantics)) {
1158
+ const u = this.buildNodeSelector(
1159
+ t.target.tag,
1160
+ t.target.semantics,
1161
+ { excludeClasses: !1 }
1162
+ // Include classes for same-element case
1163
+ );
1164
+ return e?.ensureUnique ? this.ensureUniqueSelector(u, t, e) : u;
1165
+ }
1166
+ const r = [], i = e?.ensureUnique ? this.ensureUniqueAnchor(t, e.root ?? document) : this.buildNodeSelector(t.anchor.tag, t.anchor.semantics);
1167
+ r.push(i);
1168
+ for (const u of t.path) {
1169
+ let f = this.buildNodeSelector(u.tag, u.semantics);
1170
+ u.nthChild !== void 0 && (["tr", "td", "th", "thead", "tbody", "tfoot"].includes(u.tag) ? f += `:nth-child(${u.nthChild})` : f += `:nth-child(${u.nthChild})`), r.push(f);
1171
+ }
1172
+ let a = this.buildNodeSelector(
1173
+ t.target.tag,
1174
+ t.target.semantics,
1175
+ { excludeClasses: e?.ensureUnique }
1176
+ // Exclude classes initially if we need unique
1177
+ );
1178
+ t.target.nthChild !== void 0 && (["tr", "td", "th", "thead", "tbody", "tfoot"].includes(t.target.tag) ? a += `:nth-child(${t.target.nthChild})` : a += `:nth-child(${t.target.nthChild})`), r.push(a);
1179
+ const o = this.isSvgChildElement(t.target.tag), l = t.path.some((u) => u.tag === "svg");
1180
+ let h;
1181
+ if (o && l) {
1182
+ const u = t.path.findIndex((f) => f.tag === "svg");
1183
+ if (u !== -1) {
1184
+ const f = u + 1, g = r.slice(0, f + 1), d = r.slice(f + 1, -1), m = r[r.length - 1];
1185
+ d.length > 0 ? h = g.join(" ") + " > " + d.join(" > ") + " > " + m : h = g.join(" ") + " > " + m;
1186
+ } else
1187
+ h = r.join(" ");
1188
+ } else
1189
+ h = r.join(" ");
1190
+ if (!e?.ensureUnique)
1191
+ return h;
1192
+ const c = this.querySelectorSafe(h, e.root ?? document);
1193
+ if (c.length === 1)
1194
+ return {
1195
+ selector: h,
1196
+ isUnique: !0,
1197
+ usedNthOfType: h.includes(":nth-"),
1198
+ extraClassesAdded: 0
1199
+ };
1200
+ if (c.length === 0 || c.length > 1) {
1201
+ const u = this.buildFullDomPathSelector(
1202
+ t,
1203
+ t.target.semantics,
1204
+ e.root ?? document
1205
+ );
1206
+ if (u && this.isUnique(u, e.root ?? document))
1207
+ return {
1208
+ selector: u,
1209
+ isUnique: !0,
1210
+ usedNthOfType: u.includes(":nth-"),
1211
+ extraClassesAdded: 0
1212
+ };
1213
+ }
1214
+ return this.ensureUniqueSelector(
1215
+ h,
1216
+ t,
1217
+ e
1218
+ );
1219
+ }
1220
+ /**
1221
+ * Builds selector for anchor only (used in fallback)
1222
+ * @param eid - Element Identity
1223
+ * @returns CSS selector for anchor
1224
+ */
1225
+ buildAnchorSelector(t) {
1226
+ return this.buildNodeSelector(t.anchor.tag, t.anchor.semantics);
1227
+ }
1228
+ /**
1229
+ * Ensures selector uniqueness by progressively adding classes and nth-of-type
1230
+ */
1231
+ ensureUniqueSelector(t, e, s) {
1232
+ const r = s.root ?? document, i = s.maxClasses ?? 4, a = e.target.tag, o = e.target.semantics;
1233
+ let l = t, h = 0, c = !1;
1234
+ if (this.querySelectorSafe(l, r).length === 0) {
1235
+ const d = this.buildFullDomPathSelector(e, o, r);
1236
+ if (d && (l = d, this.isUnique(l, r)))
1237
+ return {
1238
+ selector: l,
1239
+ isUnique: !0,
1240
+ usedNthOfType: !1,
1241
+ extraClassesAdded: 0
1242
+ };
1243
+ }
1244
+ if (this.isUnique(l, r))
1245
+ return {
1246
+ selector: l,
1247
+ isUnique: !0,
1248
+ usedNthOfType: !1,
1249
+ extraClassesAdded: 0
1250
+ };
1251
+ const f = I(o.classes ?? []);
1252
+ for (let d = 0; d < Math.min(f.length, i); d++) {
1253
+ const m = f[d];
1254
+ if (l += `.${this.escapeCSS(m)}`, h++, this.isUnique(l, r))
1255
+ return {
1256
+ selector: l,
1257
+ isUnique: !0,
1258
+ usedNthOfType: !1,
1259
+ extraClassesAdded: h
1260
+ };
1261
+ }
1262
+ if (!this.isUnique(l, r)) {
1263
+ const d = this.buildFullDomPathSelector(e, o, r);
1264
+ if (d && this.isUnique(d, r))
1265
+ return {
1266
+ selector: d,
1267
+ isUnique: !0,
1268
+ usedNthOfType: d.includes(":nth-of-type("),
1269
+ extraClassesAdded: h
1270
+ };
1271
+ }
1272
+ const g = this.findNthElementByText(l, o, r);
1273
+ return g && (l += this.getNthSelector(g, a), c = !0), {
1274
+ selector: l,
1275
+ isUnique: this.isUnique(l, r),
1276
+ usedNthOfType: c,
1277
+ extraClassesAdded: h
1278
+ };
1279
+ }
1280
+ /**
1281
+ * Builds full DOM path selector by traversing actual DOM from anchor
1282
+ * This handles cases where intermediate div/span elements were filtered out
1283
+ */
1284
+ buildFullDomPathSelector(t, e, s) {
1285
+ const r = this.buildNodeSelector(t.anchor.tag, t.anchor.semantics), i = this.querySelectorSafe(r, s);
1286
+ if (i.length === 0) return null;
1287
+ for (const a of i) {
1288
+ const o = this.findTargetWithinAnchor(
1289
+ a,
1290
+ t.target.tag,
1291
+ e
1292
+ );
1293
+ if (o.length === 0) continue;
1294
+ const l = o.map((h) => {
1295
+ const c = this.scorePathMatch(h, a, t.path);
1296
+ return { element: h, score: c };
1297
+ });
1298
+ l.sort((h, c) => c.score - h.score);
1299
+ for (const { element: h } of l) {
1300
+ const c = this.buildPathFromAnchorToTarget(
1301
+ a,
1302
+ h,
1303
+ t,
1304
+ s
1305
+ );
1306
+ if (c && this.isUnique(c, s))
1307
+ return c;
1308
+ }
1309
+ }
1310
+ return null;
1311
+ }
1312
+ /**
1313
+ * Scores how well a candidate's DOM path matches the EID path
1314
+ * Compares tags, classes, attributes, and nthChild positions
1315
+ * @param candidate - Target element candidate
1316
+ * @param anchor - Anchor element
1317
+ * @param eidPath - EID path nodes
1318
+ * @returns Score (higher = better match)
1319
+ */
1320
+ scorePathMatch(t, e, s) {
1321
+ const r = [];
1322
+ let i = t.parentElement;
1323
+ for (; i && i !== e; )
1324
+ r.unshift(i), i = i.parentElement;
1325
+ let a = 0;
1326
+ const o = Math.min(r.length, s.length);
1327
+ for (let h = 0; h < o; h++) {
1328
+ const c = r[h], u = s[h];
1329
+ if (c.tagName.toLowerCase() === u.tag) {
1330
+ if (a += 10, u.nthChild !== void 0) {
1331
+ const f = c.parentElement;
1332
+ f && (Array.from(f.children).indexOf(c) + 1 === u.nthChild ? a += 20 : a -= 10);
1333
+ }
1334
+ } else
1335
+ a -= 5;
1336
+ if (u.semantics.classes && u.semantics.classes.length > 0) {
1337
+ const f = u.semantics.classes.filter(
1338
+ (g) => c.classList.contains(g)
1339
+ );
1340
+ a += f.length * 2;
1341
+ }
1342
+ if (u.semantics.attributes) {
1343
+ const f = Object.entries(u.semantics.attributes).filter(
1344
+ ([g, d]) => c.getAttribute(g) === d
1345
+ );
1346
+ a += f.length * 3;
1347
+ }
1348
+ }
1349
+ const l = Math.abs(r.length - s.length);
1350
+ return a -= l * 2, a;
1351
+ }
1352
+ /**
1353
+ * Finds target elements within an anchor by matching semantics
1354
+ */
1355
+ findTargetWithinAnchor(t, e, s) {
1356
+ return Array.from(t.querySelectorAll(e)).filter((i) => {
1357
+ if (s.text) {
1358
+ const a = i.textContent?.trim() || "", o = s.text.normalized;
1359
+ if (!a.includes(o) && !o.includes(a))
1360
+ return !1;
1361
+ }
1362
+ return !!(s.classes && s.classes.length > 0 && s.classes.every(
1363
+ (o) => i.classList.contains(o)
1364
+ ) || s.attributes && Object.entries(s.attributes).every(
1365
+ ([o, l]) => {
1366
+ const h = i.getAttribute(o);
1367
+ return o === "href" || o === "src" ? P(o, h || "") === P(o, l) : h === l;
1368
+ }
1369
+ ) || s.text);
1370
+ });
1371
+ }
1372
+ /**
1373
+ * Disambiguates a parent element by trying attributes, classes, then nth-of-type
1374
+ * Priority: stable attributes > one stable class > nth-of-type
1375
+ * @param element The DOM element to disambiguate
1376
+ * @param tag The tag name
1377
+ * @param pathNode EID path node with semantics (if available)
1378
+ * @param fullPath Current selector path (for uniqueness testing)
1379
+ * @param root Root element for queries
1380
+ * @returns Disambiguated selector part (e.g., "div[role='main']" or "div.sidebar" or "div:nth-of-type(3)")
1381
+ */
1382
+ disambiguateParent(t, e, s, r, i) {
1383
+ if (s?.semantics?.attributes) {
1384
+ const o = this.buildNodeSelector(e, s.semantics, {
1385
+ excludeClasses: !0
1386
+ }), l = [...r, e].join(" > "), h = this.querySelectorSafe(l, i), c = [...r, o].join(" > "), u = this.querySelectorSafe(c, i);
1387
+ if (u.length > 0 && u.length < h.length)
1388
+ return o;
1389
+ }
1390
+ if (s?.semantics?.classes) {
1391
+ const o = I(s.semantics.classes);
1392
+ if (o.length > 0) {
1393
+ const l = `${e}.${this.escapeCSS(o[0])}`, h = [...r, e].join(" > "), c = this.querySelectorSafe(h, i), u = [...r, l].join(" > "), f = this.querySelectorSafe(u, i);
1394
+ if (f.length > 0 && f.length < c.length)
1395
+ return l;
1396
+ }
1397
+ }
1398
+ const a = t.parentElement;
1399
+ return a && Array.from(a.children).filter(
1400
+ (l) => l.tagName.toLowerCase() === e
1401
+ ).length > 1 ? `${e}${this.getNthSelector(t, e)}` : e;
1402
+ }
1403
+ /**
1404
+ * Builds CSS selector path from anchor to target by traversing actual DOM
1405
+ */
1406
+ buildPathFromAnchorToTarget(t, e, s, r) {
1407
+ const i = [];
1408
+ let a = e;
1409
+ for (; a && a !== t; )
1410
+ i.unshift(a), a = a.parentElement;
1411
+ if (a !== t)
1412
+ return null;
1413
+ const o = [
1414
+ // ============================================================
1415
+ // Strategy 0: anchor path target[attrs_only]
1416
+ // Most flexible - no classes on target, only semantic attributes
1417
+ // ============================================================
1418
+ () => {
1419
+ const l = this.buildNodeSelector(s.anchor.tag, s.anchor.semantics), h = s.target.tag, c = s.target.semantics, u = [];
1420
+ for (const p of s.path)
1421
+ u.push(p.tag);
1422
+ const g = [l, ...u, h].filter(Boolean).join(" ");
1423
+ if (this.isUnique(g, r))
1424
+ return g;
1425
+ const d = this.buildNodeSelector(h, c, {
1426
+ excludeClasses: !0
1427
+ // KEY: no classes on target in Strategy 0
1428
+ }), m = [l, ...u.slice(0, -1), d].join(" ");
1429
+ return this.isUnique(m, r) ? m : null;
1430
+ },
1431
+ // ============================================================
1432
+ // Strategy 1: anchor > parent[attrs|class|nth] > target[attrs_only]
1433
+ // Full path with '>' combinator
1434
+ // Parents: disambiguated using attrs > stable class > nth-of-type
1435
+ // Target: ONLY attributes, NO classes
1436
+ // ============================================================
1437
+ () => {
1438
+ const l = [this.buildNodeSelector(s.anchor.tag, s.anchor.semantics)], h = /* @__PURE__ */ new Map();
1439
+ let c = 0;
1440
+ for (let f = 0; f < i.length - 1; f++) {
1441
+ const g = i[f], d = g.tagName.toLowerCase();
1442
+ c < s.path.length && s.path[c].tag === d ? (h.set(g, s.path[c]), c++) : h.set(g, null);
1443
+ }
1444
+ for (let f = 0; f < i.length; f++) {
1445
+ const g = i[f], d = g.tagName.toLowerCase();
1446
+ if (f < i.length - 1) {
1447
+ const S = h.get(g) || null, y = this.disambiguateParent(g, d, S, l, r);
1448
+ l.push(y);
1449
+ continue;
1450
+ }
1451
+ const m = this.buildNodeSelector(
1452
+ s.target.tag,
1453
+ s.target.semantics,
1454
+ { excludeClasses: !0 }
1455
+ // KEY: no classes on target
1456
+ ), p = g.parentElement;
1457
+ p && ["td", "th", "tr", "thead", "tbody", "tfoot"].includes(d) && Array.from(p.children).filter(
1458
+ (y) => y.tagName.toLowerCase() === d
1459
+ ).length > 1 ? l.push(`${m}${this.getNthSelector(g, d)}`) : l.push(m);
1460
+ }
1461
+ const u = l.join(" > ");
1462
+ return this.isUnique(u, r) ? u : null;
1463
+ },
1464
+ // ============================================================
1465
+ // Strategy 2: anchor parent[attrs|class|nth] target[attrs_only]
1466
+ // Descendant combinator (space) - more flexible
1467
+ // Parents: disambiguated using attrs > stable class > nth-of-type
1468
+ // Target: ONLY attributes, NO classes
1469
+ // ============================================================
1470
+ () => {
1471
+ const h = [this.buildNodeSelector(s.anchor.tag, s.anchor.semantics)];
1472
+ for (let f = 0; f < i.length - 1; f++) {
1473
+ const d = i[f].tagName.toLowerCase(), m = s.path[f] || null, p = h.join(" ") + " " + d;
1474
+ if (this.querySelectorSafe(p, r).length > 1) {
1475
+ if (m?.semantics?.attributes) {
1476
+ const A = this.buildNodeSelector(d, m.semantics, {
1477
+ excludeClasses: !0
1478
+ }), b = h.join(" ") + " " + A;
1479
+ if (this.querySelectorSafe(b, r).length === 1 || this.querySelectorSafe(b + " " + s.target.tag, r).length === 1) {
1480
+ h.push(A);
1481
+ continue;
1482
+ }
1483
+ }
1484
+ if (m?.semantics?.classes) {
1485
+ const A = I(m.semantics.classes);
1486
+ if (A.length > 0) {
1487
+ const b = `${d}.${this.escapeCSS(A[0])}`, v = h.join(" ") + " " + b;
1488
+ if (this.querySelectorSafe(v, r).length === 1 || this.querySelectorSafe(v + " " + s.target.tag, r).length === 1) {
1489
+ h.push(b);
1490
+ continue;
1491
+ }
1492
+ }
1493
+ }
1494
+ const y = i[f], w = y.parentElement;
1495
+ if (w && Array.from(w.children).filter(
1496
+ (b) => b.tagName.toLowerCase() === d
1497
+ ).length > 1) {
1498
+ h.push(`${d}${this.getNthSelector(y, d)}`);
1499
+ continue;
1500
+ }
1501
+ }
1502
+ h.push(d);
1503
+ }
1504
+ const c = this.buildNodeSelector(
1505
+ s.target.tag,
1506
+ s.target.semantics,
1507
+ { excludeClasses: !0 }
1508
+ // KEY: no classes on target
1509
+ );
1510
+ h.push(c);
1511
+ const u = h.join(" ");
1512
+ return this.isUnique(u, r) ? u : null;
1513
+ },
1514
+ // ============================================================
1515
+ // Strategy 3: anchor path target[attrs + 1_stable_class]
1516
+ // Add ONE stable class to target (must be semantic, NOT utility)
1517
+ // Only use this if attrs alone are not sufficient
1518
+ // ============================================================
1519
+ () => {
1520
+ const l = this.buildNodeSelector(s.anchor.tag, s.anchor.semantics), h = [];
1521
+ for (const g of s.path)
1522
+ h.push(g.tag);
1523
+ if (I(s.target.semantics.classes ?? []).length === 0)
1524
+ return null;
1525
+ const u = this.buildNodeSelector(
1526
+ s.target.tag,
1527
+ s.target.semantics,
1528
+ { maxClasses: 1 }
1529
+ // KEY: ONE stable class only
1530
+ ), f = [l, ...h.slice(0, -1), u].join(" ");
1531
+ return this.isUnique(f, r) ? f : null;
1532
+ },
1533
+ // ============================================================
1534
+ // Strategy 4: anchor path target[attrs]:nth-of-type(N)
1535
+ // Last resort - add nth-of-type to target
1536
+ // Only use when all other strategies fail
1537
+ // ============================================================
1538
+ () => {
1539
+ const l = this.buildNodeSelector(s.anchor.tag, s.anchor.semantics), h = [];
1540
+ for (const m of s.path)
1541
+ h.push(m.tag);
1542
+ const c = i[i.length - 1], u = c.parentElement;
1543
+ if (!u || Array.from(u.children).filter(
1544
+ (m) => m.tagName.toLowerCase() === s.target.tag
1545
+ ).length <= 1) return null;
1546
+ const g = this.buildNodeSelector(
1547
+ s.target.tag,
1548
+ s.target.semantics,
1549
+ { excludeClasses: !0 }
1550
+ // No classes, just attrs + nth
1551
+ ) + this.getNthSelector(c, s.target.tag), d = [l, ...h.slice(0, -1), g].join(" ");
1552
+ return this.isUnique(d, r) ? d : null;
1553
+ }
1554
+ ];
1555
+ for (const l of o) {
1556
+ const h = l();
1557
+ if (h) return h;
1558
+ }
1559
+ return null;
1560
+ }
1561
+ /**
1562
+ * Builds a minimal selector for a DOM element
1563
+ * @param element The DOM element to create a selector for
1564
+ * @returns A minimal CSS selector for the element
1565
+ */
1566
+ // @ts-ignore: Method is used dynamically in buildPathFromAnchorToTarget
1567
+ buildElementSelector(t) {
1568
+ const e = t.tagName.toLowerCase();
1569
+ let s = e;
1570
+ if (t.id && !D(t.id))
1571
+ return `${e}#${this.escapeCSS(t.id)}`;
1572
+ const r = Array.from(t.classList), i = I(r);
1573
+ i.length > 0 && (s += i.slice(0, 2).map((o) => `.${this.escapeCSS(o)}`).join(""));
1574
+ const a = t.getAttribute("role");
1575
+ return a && (s += `[role="${this.escapeAttr(a)}"]`), s;
1576
+ }
1577
+ /**
1578
+ * Safe querySelectorAll that doesn't throw
1579
+ */
1580
+ querySelectorSafe(t, e) {
1581
+ try {
1582
+ return Array.from(e.querySelectorAll(t));
1583
+ } catch {
1584
+ return [];
1585
+ }
1586
+ }
1587
+ /**
1588
+ * Finds element by matching text content
1589
+ * Returns the matching element (used with getNthSelector for table-aware positioning)
1590
+ */
1591
+ findNthElementByText(t, e, s) {
1592
+ const r = this.querySelectorSafe(t, s);
1593
+ if (r.length <= 1) return null;
1594
+ if (e.text) {
1595
+ const i = e.text.normalized;
1596
+ for (const a of r) {
1597
+ const o = a.textContent?.trim() || "";
1598
+ if (o === i || o.includes(i) || i.includes(o))
1599
+ return a;
1600
+ }
1601
+ }
1602
+ return null;
1603
+ }
1604
+ /**
1605
+ * Checks if selector matches exactly one element
1606
+ */
1607
+ isUnique(t, e) {
1608
+ try {
1609
+ return e.querySelectorAll(t).length === 1;
1610
+ } catch {
1611
+ return !1;
1612
+ }
1613
+ }
1614
+ /**
1615
+ * Gets nth-of-type index for an element
1616
+ */
1617
+ getNthOfTypeIndex(t, e) {
1618
+ const s = t.parentElement;
1619
+ if (!s) return null;
1620
+ const i = Array.from(s.children).filter(
1621
+ (a) => a.tagName.toLowerCase() === e
1622
+ ).indexOf(t);
1623
+ return i !== -1 ? i + 1 : null;
1624
+ }
1625
+ /**
1626
+ * FIX 2: Ensures anchor selector is unique in the document
1627
+ * Priority order: tag → tag.class → tag[attr] → tag:nth-of-type(N)
1628
+ * @param eid - Element Identity with anchor information
1629
+ * @param root - Root element for uniqueness check
1630
+ * @returns Unique selector for anchor
1631
+ */
1632
+ ensureUniqueAnchor(t, e) {
1633
+ const s = t.anchor.tag, r = t.anchor.semantics;
1634
+ if (this.isUnique(s, e))
1635
+ return s;
1636
+ if (r.classes && r.classes.length > 0) {
1637
+ const a = I(r.classes);
1638
+ if (a.length > 0) {
1639
+ const o = `${s}.${this.escapeCSS(a[0])}`;
1640
+ if (this.isUnique(o, e))
1641
+ return o;
1642
+ }
1643
+ }
1644
+ if (r.attributes) {
1645
+ const a = this.getSortedAttributes(r.attributes);
1646
+ for (const { name: o, value: l } of a) {
1647
+ const h = o === "href" || o === "src" ? P(o, l) : l;
1648
+ if (h) {
1649
+ const c = `${s}[${o}="${this.escapeAttr(h)}"]`;
1650
+ if (this.isUnique(c, e))
1651
+ return c;
1652
+ }
1653
+ }
1654
+ }
1655
+ const i = Array.from(e.querySelectorAll(s));
1656
+ if (i.length > 1) {
1657
+ const a = this.findElementBySemantics(i, r);
1658
+ if (a) {
1659
+ const o = this.getNthOfTypeIndex(a, s);
1660
+ if (o)
1661
+ return `${s}:nth-of-type(${o})`;
1662
+ }
1663
+ }
1664
+ return s;
1665
+ }
1666
+ /**
1667
+ * FIX 2: Finds element by matching semantics
1668
+ * @param elements - Array of candidate elements
1669
+ * @param semantics - Semantics to match against
1670
+ * @returns Matching element or null
1671
+ */
1672
+ findElementBySemantics(t, e) {
1673
+ return e.classes && e.classes.length > 0 || e.attributes && Object.keys(e.attributes).length > 0 || e.text ? t.find((r) => {
1674
+ if (e.classes && e.classes.length > 0 && e.classes.every(
1675
+ (a) => r.classList.contains(a)
1676
+ ) || e.attributes && Object.entries(e.attributes).every(
1677
+ ([a, o]) => r.getAttribute(a) === o
1678
+ ))
1679
+ return !0;
1680
+ if (e.text) {
1681
+ const i = r.textContent?.trim() || "", a = e.text.normalized;
1682
+ if (i.includes(a) || a.includes(i))
1683
+ return !0;
1684
+ }
1685
+ return !1;
1686
+ }) || null : t.length > 0 ? t[0] : null;
1687
+ }
1688
+ /**
1689
+ * FIX 3: Gets nth selector - nth-child for tables, nth-of-type for others
1690
+ * This method is now ACTIVELY INTEGRATED in selector generation logic
1691
+ * to ensure table elements use position-specific nth-child selectors
1692
+ * @param element - Element to get selector for
1693
+ * @param tag - Tag name
1694
+ * @returns nth selector string (e.g., ":nth-child(2)" or ":nth-of-type(2)")
1695
+ */
1696
+ getNthSelector(t, e) {
1697
+ const s = t.parentElement;
1698
+ if (!s) return "";
1699
+ const r = Array.from(s.children), i = r.indexOf(t) + 1;
1700
+ return ["tr", "td", "th", "thead", "tbody", "tfoot"].includes(e) ? `:nth-child(${i})` : `:nth-of-type(${r.filter((l) => l.tagName.toLowerCase() === e).indexOf(t) + 1})`;
1701
+ }
1702
+ /**
1703
+ * Gets attribute priority for sorting
1704
+ * @param attrName - Attribute name
1705
+ * @returns Priority number (higher = more priority)
1706
+ */
1707
+ getAttributePriority(t) {
1708
+ return T[t] !== void 0 ? T[t] : t.startsWith("data-") ? T["data-*"] : t.startsWith("aria-") ? T["aria-*"] : 0;
1709
+ }
1710
+ /**
1711
+ * Checks if attribute should be ignored
1712
+ * @param attrName - Attribute name
1713
+ * @returns True if should be ignored
1714
+ */
1715
+ shouldIgnoreAttribute(t) {
1716
+ return !!(et.has(t) || t.startsWith("on") || t.startsWith("ng-") || t.startsWith("_ng") || t.startsWith("data-reactid") || t.startsWith("data-react") || t.startsWith("data-v-"));
1717
+ }
1718
+ /**
1719
+ * Gets attributes sorted by priority
1720
+ * @param attributes - Attributes object
1721
+ * @returns Sorted array of attributes with priority
1722
+ */
1723
+ getSortedAttributes(t) {
1724
+ return Object.entries(t).filter(([e]) => !this.shouldIgnoreAttribute(e)).filter(([e, s]) => !B.has(e) || !G(s)).map(([e, s]) => ({
1725
+ name: e,
1726
+ value: s,
1727
+ priority: this.getAttributePriority(e)
1728
+ })).filter((e) => e.priority > 0).sort((e, s) => s.priority - e.priority);
1729
+ }
1730
+ /**
1731
+ * Builds selector for a single node
1732
+ * Priority: ID → semantic attributes → role → classes
1733
+ */
1734
+ buildNodeSelector(t, e, s) {
1735
+ let r = t;
1736
+ if (e.id)
1737
+ return r += `#${this.escapeCSS(e.id)}`, r;
1738
+ if (e.attributes) {
1739
+ const i = this.getSortedAttributes(e.attributes);
1740
+ for (const { name: a, value: o } of i) {
1741
+ const l = a === "href" || a === "src" ? P(a, o) : o;
1742
+ l && (r += `[${a}="${this.escapeAttr(l)}"]`);
1743
+ }
1744
+ }
1745
+ if (e.role && !e.attributes?.role && (r += `[role="${this.escapeAttr(e.role)}"]`), !s?.excludeClasses && e.classes && e.classes.length > 0) {
1746
+ const i = I(e.classes), a = s?.maxClasses !== void 0 ? i.slice(0, s.maxClasses) : i;
1747
+ r += a.map((o) => `.${this.escapeCSS(o)}`).join("");
1748
+ }
1749
+ return r;
1750
+ }
1751
+ /**
1752
+ * Escapes special characters for CSS selector
1753
+ */
1754
+ escapeCSS(t) {
1755
+ return t.replace(/([!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g, "\\$1");
1756
+ }
1757
+ /**
1758
+ * Escapes quotes for attribute values
1759
+ */
1760
+ escapeAttr(t) {
1761
+ return t.replace(/"/g, '\\"').replace(/\\/g, "\\\\");
1762
+ }
1763
+ /**
1764
+ * Checks if element tag is an SVG child element
1765
+ * @param tag - Element tag name
1766
+ * @returns True if element is an SVG child
1767
+ */
1768
+ isSvgChildElement(t) {
1769
+ return ht.includes(t);
1770
+ }
1771
+ }
1772
+ class Ht {
1773
+ /**
1774
+ * Filters elements that match the semantics
1775
+ * @param elements - Candidate elements
1776
+ * @param semantics - Target semantics to match
1777
+ * @returns Filtered elements that match
1778
+ */
1779
+ match(t, e) {
1780
+ return t.filter((s) => this.matchElement(s, e));
1781
+ }
1782
+ /**
1783
+ * Checks if a single element matches the semantics
1784
+ */
1785
+ matchElement(t, e) {
1786
+ return !(e.text && !this.matchText(t, e.text) || e.attributes && !this.matchAttributes(t, e.attributes) || e.svg && !this.matchSvgFingerprint(t, e.svg));
1787
+ }
1788
+ /**
1789
+ * Matches text content
1790
+ * Prioritizes direct text nodes, but falls back to full textContent if no direct text
1791
+ */
1792
+ matchText(t, e) {
1793
+ const i = Array.from(t.childNodes).filter((o) => o.nodeType === Node.TEXT_NODE).map((o) => o.textContent?.trim() ?? "").join(" ") || (t.textContent?.trim() ?? "");
1794
+ if (!i) return !1;
1795
+ const a = V(i);
1796
+ return e.matchMode === "partial" ? a.includes(e.normalized) : a === e.normalized;
1797
+ }
1798
+ /**
1799
+ * Matches attributes
1800
+ */
1801
+ matchAttributes(t, e) {
1802
+ for (const [s, r] of Object.entries(e))
1803
+ if (t.getAttribute(s) !== r)
1804
+ return !1;
1805
+ return !0;
1806
+ }
1807
+ /**
1808
+ * Matches SVG fingerprint
1809
+ */
1810
+ matchSvgFingerprint(t, e) {
1811
+ if (t.tagName.toLowerCase() !== e.shape)
1812
+ return !1;
1813
+ if (e.dHash && e.shape === "path") {
1814
+ const s = t.getAttribute("d");
1815
+ if (s && this.computePathHash(s) !== e.dHash)
1816
+ return !1;
1817
+ }
1818
+ 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);
1819
+ }
1820
+ /**
1821
+ * Computes simple path hash (matching SvgFingerprinter)
1822
+ */
1823
+ computePathHash(t) {
1824
+ const r = (t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi) ?? []).slice(0, 5).map((i) => i.trim().replace(/(-?\d+\.?\d*)/g, (a) => parseFloat(a).toFixed(1))).join(" ");
1825
+ return this.simpleHash(r);
1826
+ }
1827
+ /**
1828
+ * Computes geometry hash for non-path shapes (matching SvgFingerprinter)
1829
+ */
1830
+ computeGeomHash(t, e) {
1831
+ const s = [];
1832
+ switch (e) {
1833
+ case "circle":
1834
+ s.push(`r=${t.getAttribute("r") ?? "0"}`);
1835
+ break;
1836
+ case "rect": {
1837
+ const r = parseFloat(t.getAttribute("width") ?? "0"), i = parseFloat(t.getAttribute("height") ?? "0");
1838
+ r > 0 && i > 0 && s.push(`ratio=${(r / i).toFixed(2)}`);
1839
+ break;
1840
+ }
1841
+ case "ellipse": {
1842
+ const r = parseFloat(t.getAttribute("rx") ?? "0"), i = parseFloat(t.getAttribute("ry") ?? "0");
1843
+ r > 0 && i > 0 && s.push(`ratio=${(r / i).toFixed(2)}`);
1844
+ break;
1845
+ }
1846
+ case "line": {
1847
+ const r = parseFloat(t.getAttribute("x1") ?? "0"), i = parseFloat(t.getAttribute("y1") ?? "0"), a = parseFloat(t.getAttribute("x2") ?? "0"), o = parseFloat(t.getAttribute("y2") ?? "0"), l = Math.atan2(o - i, a - r);
1848
+ s.push(`angle=${l.toFixed(2)}`);
1849
+ break;
1850
+ }
1851
+ }
1852
+ return this.simpleHash(s.join(";"));
1853
+ }
1854
+ /**
1855
+ * Simple hash function (matching SvgFingerprinter)
1856
+ */
1857
+ simpleHash(t) {
1858
+ let e = 0;
1859
+ for (let s = 0; s < t.length; s++) {
1860
+ const r = t.charCodeAt(s);
1861
+ e = (e << 5) - e + r, e = e & e;
1862
+ }
1863
+ return Math.abs(e).toString(16).padStart(8, "0");
1864
+ }
1865
+ }
1866
+ class Pt {
1867
+ /**
1868
+ * Applies a single constraint to candidates
1869
+ * @param candidates - Current candidate elements
1870
+ * @param constraint - Constraint to apply
1871
+ * @returns Filtered candidates
1872
+ */
1873
+ applyConstraint(t, e) {
1874
+ switch (e.type) {
1875
+ case "text-proximity":
1876
+ return this.applyTextProximity(
1877
+ t,
1878
+ e.params
1879
+ );
1880
+ case "position":
1881
+ return this.applyPosition(
1882
+ t,
1883
+ e.params
1884
+ );
1885
+ default:
1886
+ return t;
1887
+ }
1888
+ }
1889
+ /**
1890
+ * Applies text proximity constraint using Levenshtein distance
1891
+ */
1892
+ applyTextProximity(t, e) {
1893
+ return t.filter((s) => {
1894
+ const r = s.textContent?.trim() ?? "";
1895
+ return this.levenshteinDistance(r, e.reference) <= e.maxDistance;
1896
+ });
1897
+ }
1898
+ /**
1899
+ * Applies position constraint
1900
+ */
1901
+ applyPosition(t, e) {
1902
+ if (t.length <= 1) return t;
1903
+ switch (e.strategy) {
1904
+ case "first-in-dom":
1905
+ return [t[0]];
1906
+ case "top-most":
1907
+ return [this.getTopMost(t)];
1908
+ case "left-most":
1909
+ return [this.getLeftMost(t)];
1910
+ default:
1911
+ return [t[0]];
1912
+ }
1913
+ }
1914
+ /**
1915
+ * Gets the top-most element by bounding rect
1916
+ */
1917
+ getTopMost(t) {
1918
+ return t.reduce((e, s) => {
1919
+ try {
1920
+ const r = e.getBoundingClientRect();
1921
+ return s.getBoundingClientRect().top < r.top ? s : e;
1922
+ } catch {
1923
+ return e;
1924
+ }
1925
+ });
1926
+ }
1927
+ /**
1928
+ * Gets the left-most element by bounding rect
1929
+ */
1930
+ getLeftMost(t) {
1931
+ return t.reduce((e, s) => {
1932
+ try {
1933
+ const r = e.getBoundingClientRect();
1934
+ return s.getBoundingClientRect().left < r.left ? s : e;
1935
+ } catch {
1936
+ return e;
1937
+ }
1938
+ });
1939
+ }
1940
+ /**
1941
+ * Calculates Levenshtein distance between two strings
1942
+ */
1943
+ levenshteinDistance(t, e) {
1944
+ if (t === e) return 0;
1945
+ if (t.length === 0) return e.length;
1946
+ if (e.length === 0) return t.length;
1947
+ const s = Array.from({ length: e.length + 1 }, (r, i) => i);
1948
+ for (let r = 1; r <= t.length; r++) {
1949
+ let i = r;
1950
+ for (let a = 1; a <= e.length; a++) {
1951
+ const o = t[r - 1] === e[a - 1] ? s[a - 1] : Math.min(s[a - 1], i, s[a]) + 1;
1952
+ s[a - 1] = i, i = o;
1953
+ }
1954
+ s[e.length] = i;
1955
+ }
1956
+ return s[e.length];
1957
+ }
1958
+ }
1959
+ class kt {
1960
+ constructor() {
1961
+ this.cssGenerator = new st();
1962
+ }
1963
+ /**
1964
+ * Handles fallback when resolution fails
1965
+ * @param eid - Element Identity being resolved
1966
+ * @param dom - Document or element to search in
1967
+ * @returns Fallback resolution result
1968
+ */
1969
+ handleFallback(t, e) {
1970
+ const { onMissing: s } = t.fallback;
1971
+ switch (s) {
1972
+ case "anchor-only":
1973
+ return this.fallbackToAnchor(t, e);
1974
+ case "strict":
1975
+ return {
1976
+ status: "error",
1977
+ elements: [],
1978
+ warnings: ["Element not found (strict mode)"],
1979
+ confidence: 0,
1980
+ meta: { degraded: !0, degradationReason: "strict-not-found" }
1981
+ };
1982
+ default:
1983
+ return {
1984
+ status: "error",
1985
+ elements: [],
1986
+ warnings: ["Element not found"],
1987
+ confidence: 0,
1988
+ meta: { degraded: !0, degradationReason: "not-found" }
1989
+ };
1990
+ }
1991
+ }
1992
+ /**
1993
+ * Attempts to find and return the anchor element as fallback
1994
+ */
1995
+ fallbackToAnchor(t, e) {
1996
+ const s = this.cssGenerator.buildAnchorSelector(t), r = e instanceof Document ? e : e.ownerDocument ?? e;
1997
+ try {
1998
+ const i = r.querySelector(s);
1999
+ if (i)
2000
+ return {
2001
+ status: "degraded-fallback",
2002
+ elements: [i],
2003
+ warnings: ["Target not found, returning anchor"],
2004
+ confidence: t.meta.confidence * 0.3,
2005
+ meta: { degraded: !0, degradationReason: "anchor-fallback" }
2006
+ };
2007
+ } catch (i) {
2008
+ const a = i instanceof Error ? i.message : "Unknown selector error";
2009
+ return {
2010
+ status: "error",
2011
+ elements: [],
2012
+ warnings: [`Invalid anchor selector: ${a}`],
2013
+ confidence: 0,
2014
+ meta: { degraded: !0, degradationReason: "invalid-anchor-selector" }
2015
+ };
2016
+ }
2017
+ return {
2018
+ status: "error",
2019
+ elements: [],
2020
+ warnings: ["Anchor also not found"],
2021
+ confidence: 0,
2022
+ meta: { degraded: !0, degradationReason: "anchor-not-found" }
2023
+ };
2024
+ }
2025
+ /**
2026
+ * Handles ambiguous results (multiple matches)
2027
+ * @param elements - All matching elements
2028
+ * @param eid - Original Element Identity
2029
+ * @returns Resolution result based on fallback rules
2030
+ */
2031
+ handleAmbiguous(t, e) {
2032
+ const { onMultiple: s } = e.fallback;
2033
+ switch (s) {
2034
+ case "first":
2035
+ return {
2036
+ status: "success",
2037
+ elements: [t[0]],
2038
+ warnings: ["Multiple matches, returning first"],
2039
+ confidence: e.meta.confidence * 0.7,
2040
+ meta: { degraded: !0, degradationReason: "first-of-multiple" }
2041
+ };
2042
+ case "best-score":
2043
+ return this.selectBestScoring(t, e);
2044
+ default:
2045
+ return {
2046
+ status: "ambiguous",
2047
+ elements: t,
2048
+ warnings: [`Multiple matches: ${t.length}`],
2049
+ confidence: e.meta.confidence * 0.5,
2050
+ meta: { degraded: !0, degradationReason: "multiple-matches" }
2051
+ };
2052
+ }
2053
+ }
2054
+ /**
2055
+ * Selects the best-scoring element from candidates
2056
+ * Re-scores each element based on semantic match quality
2057
+ */
2058
+ selectBestScoring(t, e) {
2059
+ const s = e.target.semantics;
2060
+ let r = t[0], i = -1;
2061
+ for (const a of t) {
2062
+ const o = this.scoreElementMatch(a, s);
2063
+ o > i && (i = o, r = a);
2064
+ }
2065
+ return {
2066
+ status: "success",
2067
+ elements: [r],
2068
+ warnings: [
2069
+ `Multiple matches (${t.length}), selected best-scoring element`
2070
+ ],
2071
+ confidence: e.meta.confidence * (0.7 + i * 0.2),
2072
+ meta: { degraded: !0, degradationReason: "best-of-multiple" }
2073
+ };
2074
+ }
2075
+ /**
2076
+ * Scores how well an element matches the target semantics
2077
+ * @returns Score from 0 to 1
2078
+ */
2079
+ scoreElementMatch(t, e) {
2080
+ let s = 0, r = 0;
2081
+ if (e.id && (r += 0.3, t.id === e.id && (s += 0.3)), e.classes && e.classes.length > 0) {
2082
+ r += 0.25;
2083
+ const i = Array.from(t.classList), a = e.classes.filter(
2084
+ (o) => i.includes(o)
2085
+ ).length;
2086
+ s += a / e.classes.length * 0.25;
2087
+ }
2088
+ if (e.attributes) {
2089
+ const i = Object.entries(e.attributes);
2090
+ if (i.length > 0) {
2091
+ r += 0.2;
2092
+ let a = 0;
2093
+ for (const [o, l] of i)
2094
+ t.getAttribute(o) === l && a++;
2095
+ s += a / i.length * 0.2;
2096
+ }
2097
+ }
2098
+ if (e.role && (r += 0.15, t.getAttribute("role") === e.role && (s += 0.15)), e.text) {
2099
+ r += 0.1;
2100
+ const i = V(t.textContent);
2101
+ i === e.text.normalized ? s += 0.1 : i.includes(e.text.normalized) && (s += 0.05);
2102
+ }
2103
+ return r > 0 ? s / r : 0;
2104
+ }
2105
+ }
2106
+ function qt(n, t, e = {}) {
2107
+ const s = { ...ft, ...e }, r = new st(), i = new Ht(), a = new Pt(), o = new kt(), l = t instanceof Document ? t : t.ownerDocument ?? t, h = r.buildSelector(n, {
2108
+ ensureUnique: !1,
2109
+ root: l
2110
+ });
2111
+ let c;
2112
+ try {
2113
+ c = Array.from(l.querySelectorAll(h));
2114
+ } catch (d) {
2115
+ const m = d instanceof Error ? d.message : "Unknown selector error";
2116
+ return {
2117
+ status: "error",
2118
+ elements: [],
2119
+ warnings: [
2120
+ `Invalid CSS selector: ${h}`,
2121
+ `Error: ${m}`
2122
+ ],
2123
+ confidence: 0,
2124
+ meta: { degraded: !0, degradationReason: "invalid-selector" }
2125
+ };
2126
+ }
2127
+ c.length > s.maxCandidates && (c = c.slice(0, s.maxCandidates));
2128
+ const u = i.match(c, n.target.semantics);
2129
+ if (u.length === 1)
2130
+ return {
2131
+ status: "success",
2132
+ elements: u,
2133
+ warnings: [],
2134
+ confidence: n.meta.confidence,
2135
+ meta: { degraded: !1 }
2136
+ };
2137
+ if (u.length === 0)
2138
+ return s.enableFallback ? o.handleFallback(n, l) : {
2139
+ status: "error",
2140
+ elements: [],
2141
+ warnings: ["No matching elements found"],
2142
+ confidence: 0,
2143
+ meta: { degraded: !0, degradationReason: "not-found" }
2144
+ };
2145
+ let f = u;
2146
+ const g = Ot(n.constraints);
2147
+ for (const d of g) {
2148
+ if (f = a.applyConstraint(f, d), f.length === 1)
2149
+ return {
2150
+ status: "success",
2151
+ elements: f,
2152
+ warnings: [],
2153
+ confidence: n.meta.confidence * 0.9,
2154
+ meta: { degraded: !1 }
2155
+ };
2156
+ if (f.length === 0)
2157
+ return s.enableFallback ? o.handleFallback(n, l) : {
2158
+ status: "error",
2159
+ elements: [],
2160
+ warnings: ["Constraints eliminated all candidates"],
2161
+ confidence: 0,
2162
+ meta: { degraded: !0, degradationReason: "over-constrained" }
2163
+ };
2164
+ }
2165
+ return s.strictMode ? {
2166
+ status: "ambiguous",
2167
+ elements: f,
2168
+ warnings: [`Non-unique resolution: ${f.length} matches`],
2169
+ confidence: n.meta.confidence * 0.7,
2170
+ meta: { degraded: !0, degradationReason: "ambiguous" }
2171
+ } : o.handleAmbiguous(f, n);
2172
+ }
2173
+ function Ot(n) {
2174
+ return [...n].sort((t, e) => e.priority - t.priority);
2175
+ }
2176
+ function Xt(n) {
2177
+ const t = [], e = [];
2178
+ if (n.version ? n.version !== "1.0" && e.push(`Unknown version: ${n.version}`) : t.push("Missing version field"), n.anchor ? (n.anchor.tag || t.push("Anchor missing tag"), typeof n.anchor.score != "number" && t.push("Anchor missing score"), n.anchor.semantics || t.push("Anchor missing semantics")) : t.push("Missing anchor field"), n.target ? (n.target.tag || t.push("Target missing tag"), typeof n.target.score != "number" && t.push("Target missing score"), n.target.semantics || t.push("Target missing semantics")) : t.push("Missing target field"), !Array.isArray(n.path))
2179
+ t.push("Path must be an array");
2180
+ else
2181
+ for (let s = 0; s < n.path.length; s++) {
2182
+ const r = n.path[s];
2183
+ r.tag || t.push(`Path node ${s} missing tag`), r.semantics || t.push(`Path node ${s} missing semantics`);
2184
+ }
2185
+ return n.meta ? (typeof n.meta.confidence != "number" && e.push("Missing confidence score"), n.meta.generatedAt || e.push("Missing generatedAt timestamp")) : t.push("Missing meta field"), Array.isArray(n.constraints) || e.push("Constraints should be an array"), n.fallback || e.push("Missing fallback rules"), {
2186
+ valid: t.length === 0,
2187
+ errors: t,
2188
+ warnings: e
2189
+ };
2190
+ }
2191
+ function Jt(n) {
2192
+ if (!n || typeof n != "object") return !1;
2193
+ const t = n;
2194
+ return typeof t.version == "string" && typeof t.anchor == "object" && Array.isArray(t.path) && typeof t.target == "object";
2195
+ }
2196
+ const rt = {
2197
+ maxClasses: 2,
2198
+ maxAttributes: 5,
2199
+ includeText: !0,
2200
+ maxTextLength: 50,
2201
+ simplifyTarget: !0,
2202
+ includeConstraints: !0
2203
+ };
2204
+ function tt(n) {
2205
+ return n === "id" ? 101 : T[n] !== void 0 ? T[n] : n.startsWith("data-") ? T["data-*"] : n.startsWith("aria-") ? T["aria-*"] : 0;
2206
+ }
2207
+ function Lt(n) {
2208
+ return ["id", "data-testid", "data-qa", "data-cy", "href", "text", "role"].includes(n);
2209
+ }
2210
+ function _t(n) {
2211
+ return !!(/@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/.test(n) || /(\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/.test(n) || /\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}/.test(n));
2212
+ }
2213
+ function zt(n, t) {
2214
+ const e = { ...rt, ...t }, s = `v${n.version}`, r = F(n.anchor, !1, e), i = n.path.length > 0 ? n.path.map((l) => F(l, !1, e)).join(" > ") + " > " : "", a = F(n.target, !0, e), o = e.includeConstraints ? Ut(n) : "";
2215
+ return `${s}: ${r} :: ${i}${a}${o}`;
2216
+ }
2217
+ function Ft(n) {
2218
+ n = n.trim();
2219
+ const t = n.match(/^v(\d+(?:\.\d+)?)\s*:\s*/);
2220
+ if (!t)
2221
+ throw new Error('Invalid SEQL Selector: missing version prefix (expected "v1:")');
2222
+ const e = t[1];
2223
+ if (e !== "1.0" && e !== "1")
2224
+ throw new Error(`Unsupported SEQL Selector version: v${e} (only v1.0 is supported)`);
2225
+ let s = n.slice(t[0].length);
2226
+ const r = s.match(/^(.+?)\s*::\s*/);
2227
+ if (!r)
2228
+ throw new Error('Invalid SEQL Selector: missing anchor separator "::"');
2229
+ const i = r[1].trim();
2230
+ s = s.slice(r[0].length);
2231
+ const a = s.match(/\s*\{([^}]+)\}\s*$/);
2232
+ let o = "";
2233
+ a && (o = a[1], s = s.slice(0, a.index));
2234
+ const l = s.split(/\s*>\s*/).map((p) => p.trim()).filter((p) => p);
2235
+ if (l.length === 0)
2236
+ throw new Error("Invalid SEQL Selector: missing target node");
2237
+ const h = l[l.length - 1], c = l.slice(0, -1), u = U(i, !0), f = c.map((p) => U(p, !1)), g = U(h, !1), d = jt(o);
2238
+ return {
2239
+ version: "1.0",
2240
+ anchor: u,
2241
+ path: f,
2242
+ target: g,
2243
+ constraints: d,
2244
+ fallback: {
2245
+ onMultiple: "best-score",
2246
+ onMissing: "anchor-only",
2247
+ maxDepth: 10
2248
+ },
2249
+ meta: {
2250
+ confidence: 0.7,
2251
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
2252
+ generator: "seql-parser@1.0",
2253
+ source: "seql-string",
2254
+ degraded: !1
2255
+ }
2256
+ };
2257
+ }
2258
+ function F(n, t = !1, e = rt) {
2259
+ const { tag: s, semantics: r } = n;
2260
+ let i = s;
2261
+ const a = [], o = { ...r.attributes };
2262
+ r.id && (o.id = r.id), r.role && !o.role && (o.role = r.role);
2263
+ const l = Object.entries(o).map(([c, u]) => {
2264
+ const f = tt(c), g = c === "href" || c === "src" ? P(c, u) : u;
2265
+ return { name: c, value: g, priority: f };
2266
+ }).filter((c) => ["style", "xmlns", "tabindex", "contenteditable"].includes(c.name) || B.has(c.name) && G(c.value) ? !1 : c.priority > 0 || c.name === "role" || c.name === "id");
2267
+ l.sort((c, u) => u.priority - c.priority);
2268
+ const h = l.slice(0, e.maxAttributes);
2269
+ h.sort((c, u) => c.name.localeCompare(u.name));
2270
+ for (const { name: c, value: u } of h)
2271
+ a.push(`${c}="${j(u)}"`);
2272
+ if (e.includeText && r.text && !_t(r.text.normalized)) {
2273
+ const c = r.text.normalized;
2274
+ c.length > 0 && c.length <= e.maxTextLength && a.push(`text="${j(c)}"`);
2275
+ }
2276
+ if (a.length > 0) {
2277
+ let c = a;
2278
+ t && e.simplifyTarget && r.id && (c = a.filter((u) => {
2279
+ const f = u.split("=")[0];
2280
+ return tt(f) >= 60 || f === "text" || f === "id" || f === "role";
2281
+ })), c.length > 0 && (c.sort((u, f) => u.localeCompare(f)), i += `[${c.join(",")}]`);
2282
+ }
2283
+ if (r.classes && r.classes.length > 0) {
2284
+ const c = I(r.classes), u = !!r.id || a.some((g) => g.startsWith("href=") || g.startsWith("data-testid=") || g.startsWith("text=") || g.startsWith("role="));
2285
+ if (!(t && e.simplifyTarget && u) && c.length > 0) {
2286
+ const g = c.sort().slice(0, e.maxClasses);
2287
+ i += g.map((d) => `.${d}`).join("");
2288
+ }
2289
+ }
2290
+ if ("nthChild" in n && n.nthChild) {
2291
+ const c = !!r.id || r.attributes && Object.keys(r.attributes).some(Lt);
2292
+ t && e.simplifyTarget && c || (i += `#${n.nthChild}`);
2293
+ }
2294
+ return i;
2295
+ }
2296
+ function Ut(n) {
2297
+ if (!n.constraints || n.constraints.length === 0)
2298
+ return "";
2299
+ const t = [];
2300
+ for (const e of n.constraints)
2301
+ switch (e.type) {
2302
+ case "uniqueness":
2303
+ t.push("unique=true");
2304
+ break;
2305
+ case "position":
2306
+ e.params && e.params.strategy && t.push(`pos=${e.params.strategy}`);
2307
+ break;
2308
+ case "text-proximity":
2309
+ if (e.params && e.params.reference) {
2310
+ const s = j(String(e.params.reference));
2311
+ t.push(`text="${s}"`);
2312
+ }
2313
+ break;
2314
+ }
2315
+ return t.length === 0 ? "" : ` {${t.join(",")}}`;
2316
+ }
2317
+ function U(n, t) {
2318
+ let e = n;
2319
+ const s = {}, r = e.match(/^([a-z][a-z0-9-]*)/);
2320
+ if (!r)
2321
+ throw new Error(`Invalid node: missing tag name in "${n}"`);
2322
+ const i = r[1];
2323
+ e = e.slice(i.length);
2324
+ const a = [];
2325
+ let o;
2326
+ for (; o = e.match(/^\.([a-zA-Z][a-zA-Z0-9-_]*)/); )
2327
+ a.push(o[1]), e = e.slice(o[0].length);
2328
+ a.length > 0 && (s.classes = a);
2329
+ const l = e.match(/^\[([^\]]+)\]/);
2330
+ if (l) {
2331
+ const u = l[1], f = {}, g = Wt(u);
2332
+ for (const d of g) {
2333
+ const m = d.match(/^([a-z][a-z0-9-]*)(?:=|~=)"((?:[^"\\]|\\.)*)"/);
2334
+ if (m) {
2335
+ const [, p, S] = m;
2336
+ f[p] = nt(S);
2337
+ }
2338
+ }
2339
+ Object.keys(f).length > 0 && (f.text && (s.text = {
2340
+ raw: f.text,
2341
+ normalized: f.text
2342
+ }, delete f.text), f.id && (s.id = f.id, delete f.id), f.role && (s.role = f.role, delete f.role), Object.keys(f).length > 0 && (s.attributes = f)), e = e.slice(l[0].length);
2343
+ }
2344
+ let h;
2345
+ const c = e.match(/^#(\d+)/);
2346
+ if (c && (h = parseInt(c[1], 10), e = e.slice(c[0].length)), e.trim())
2347
+ throw new Error(`Invalid node: unexpected content "${e}" in "${n}"`);
2348
+ return t ? {
2349
+ tag: i,
2350
+ semantics: s,
2351
+ score: 0.7,
2352
+ degraded: !1
2353
+ } : {
2354
+ tag: i,
2355
+ semantics: s,
2356
+ score: 0.7,
2357
+ nthChild: h
2358
+ };
2359
+ }
2360
+ function jt(n) {
2361
+ if (!n.trim())
2362
+ return [];
2363
+ const t = [], e = n.split(",").map((s) => s.trim());
2364
+ for (const s of e) {
2365
+ const [r, i] = s.split("=").map((a) => a.trim());
2366
+ switch (r) {
2367
+ case "unique":
2368
+ i === "true" && t.push({
2369
+ type: "uniqueness",
2370
+ params: {
2371
+ mode: "strict"
2372
+ },
2373
+ priority: 90
2374
+ });
2375
+ break;
2376
+ case "pos":
2377
+ t.push({
2378
+ type: "position",
2379
+ params: {
2380
+ strategy: i
2381
+ },
2382
+ priority: 70
2383
+ });
2384
+ break;
2385
+ case "text":
2386
+ const a = i.replace(/^"(.*)"$/, "$1");
2387
+ t.push({
2388
+ type: "text-proximity",
2389
+ params: {
2390
+ reference: nt(a),
2391
+ maxDistance: 5
2392
+ },
2393
+ priority: 60
2394
+ });
2395
+ break;
2396
+ }
2397
+ }
2398
+ return t;
2399
+ }
2400
+ function Wt(n) {
2401
+ const t = [];
2402
+ let e = "", s = !1;
2403
+ for (let r = 0; r < n.length; r++) {
2404
+ const i = n[r];
2405
+ i === '"' && (r === 0 || n[r - 1] !== "\\") ? (s = !s, e += i) : i === "," && !s ? (e.trim() && t.push(e.trim()), e = "") : e += i;
2406
+ }
2407
+ return e.trim() && t.push(e.trim()), t;
2408
+ }
2409
+ function j(n) {
2410
+ return n.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/>/g, "\\>").replace(/:/g, "\\:");
2411
+ }
2412
+ function nt(n) {
2413
+ return n.replace(/\\\\/g, "\0").replace(/\\"/g, '"').replace(/\\>/g, ">").replace(/\\:/g, ":").replace(/\x00/g, "\\");
2414
+ }
2415
+ function te(n, t, e) {
2416
+ const s = Z(n, t);
2417
+ return s ? zt(s, e) : null;
2418
+ }
2419
+ function ee(n, t, e) {
2420
+ try {
2421
+ const s = Ft(n);
2422
+ return qt(s, t, e).elements || [];
2423
+ } catch (s) {
2424
+ return console.error("Failed to resolve SEQL Selector:", s), [];
2425
+ }
2426
+ }
2427
+ const Bt = /* @__PURE__ */ new Set([
2428
+ "script",
2429
+ "style",
2430
+ "noscript",
2431
+ "meta",
2432
+ "link",
2433
+ "head",
2434
+ "title"
2435
+ ]);
2436
+ function W(n) {
2437
+ return n.id && !D(n.id) ? 3 : n.hasAttribute("role") || n.hasAttribute("aria-label") || n.hasAttribute("aria-labelledby") || n.hasAttribute("data-testid") || n.hasAttribute("data-qa") || n.hasAttribute("data-test") ? 2 : 1;
2438
+ }
2439
+ function it(n, t) {
2440
+ const e = n.tagName.toLowerCase();
2441
+ return !!(Bt.has(e) || t && W(n) === 1 && ![
2442
+ "form",
2443
+ "main",
2444
+ "nav",
2445
+ "section",
2446
+ "article",
2447
+ "footer",
2448
+ "header",
2449
+ "button",
2450
+ "a",
2451
+ "input",
2452
+ "label",
2453
+ "select",
2454
+ "textarea"
2455
+ ].includes(e));
2456
+ }
2457
+ function at(n) {
2458
+ return [...n].sort((t, e) => {
2459
+ const s = W(t);
2460
+ return W(e) - s;
2461
+ });
2462
+ }
2463
+ function se(n = {}) {
2464
+ const t = performance.now(), {
2465
+ root: e = typeof document < "u" ? document.body : void 0,
2466
+ filter: s = "*",
2467
+ limit: r = 1 / 0,
2468
+ onProgress: i,
2469
+ progressInterval: a = 100,
2470
+ skipNonSemantic: o = !0,
2471
+ generatorOptions: l = {},
2472
+ cache: h,
2473
+ signal: c
2474
+ } = n;
2475
+ if (!e)
2476
+ throw new Error("Root element or document is required");
2477
+ const u = h ?? Q(), f = { ...l, cache: u };
2478
+ let g;
2479
+ try {
2480
+ e instanceof Document, g = Array.from(e.querySelectorAll(s));
2481
+ } catch {
2482
+ return {
2483
+ results: [],
2484
+ failed: [],
2485
+ stats: {
2486
+ totalElements: 0,
2487
+ successful: 0,
2488
+ failed: 0,
2489
+ skipped: 0,
2490
+ totalTimeMs: 0,
2491
+ avgTimePerElementMs: 0,
2492
+ cacheHitRate: 0
2493
+ }
2494
+ };
2495
+ }
2496
+ const d = g.filter(
2497
+ (E) => !it(E, o)
2498
+ ), p = at(d).slice(0, r), S = [], y = [];
2499
+ let w = 0;
2500
+ const A = p.length;
2501
+ let b = 0;
2502
+ for (let E = 0; E < p.length && !c?.aborted; E++) {
2503
+ const R = p[E], M = u.getEID(R);
2504
+ if (M)
2505
+ S.push({
2506
+ element: R,
2507
+ eid: M,
2508
+ generationTimeMs: 0
2509
+ // Cached, no generation time
2510
+ });
2511
+ else {
2512
+ const z = performance.now();
2513
+ try {
2514
+ const H = Z(R, f), ot = performance.now() - z;
2515
+ H ? S.push({
2516
+ element: R,
2517
+ eid: H,
2518
+ generationTimeMs: ot
2519
+ }) : w++;
2520
+ } catch (H) {
2521
+ y.push({
2522
+ element: R,
2523
+ error: H instanceof Error ? H.message : String(H)
2524
+ });
2525
+ }
2526
+ }
2527
+ i && E - b >= a && (i(E + 1, A), b = E);
2528
+ }
2529
+ i && i(A, A);
2530
+ const v = performance.now() - t, x = u.getStats(), k = x.eidHits + x.eidMisses + x.selectorHits + x.selectorMisses, C = x.eidHits + x.selectorHits, N = k > 0 ? C / k : 0;
2531
+ return {
2532
+ results: S,
2533
+ failed: y,
2534
+ stats: {
2535
+ totalElements: A,
2536
+ successful: S.length,
2537
+ failed: y.length,
2538
+ skipped: w,
2539
+ totalTimeMs: v,
2540
+ avgTimePerElementMs: S.length > 0 ? v / S.length : 0,
2541
+ cacheHitRate: N
2542
+ }
2543
+ };
2544
+ }
2545
+ function re(n, t = {}) {
2546
+ const e = performance.now(), {
2547
+ limit: s = 1 / 0,
2548
+ onProgress: r,
2549
+ progressInterval: i = 100,
2550
+ skipNonSemantic: a = !0,
2551
+ generatorOptions: o = {},
2552
+ cache: l,
2553
+ signal: h
2554
+ } = t, c = l ?? Q(), u = { ...o, cache: c }, f = n.filter(
2555
+ (C) => !it(C, a)
2556
+ ), d = at(f).slice(0, s), m = [], p = [];
2557
+ let S = 0;
2558
+ const y = d.length;
2559
+ let w = 0;
2560
+ for (let C = 0; C < d.length && !h?.aborted; C++) {
2561
+ const N = d[C], E = c.getEID(N);
2562
+ if (E)
2563
+ m.push({
2564
+ element: N,
2565
+ eid: E,
2566
+ generationTimeMs: 0
2567
+ });
2568
+ else {
2569
+ const R = performance.now();
2570
+ try {
2571
+ const M = Z(N, u), z = performance.now() - R;
2572
+ M ? m.push({
2573
+ element: N,
2574
+ eid: M,
2575
+ generationTimeMs: z
2576
+ }) : S++;
2577
+ } catch (M) {
2578
+ p.push({
2579
+ element: N,
2580
+ error: M instanceof Error ? M.message : String(M)
2581
+ });
2582
+ }
2583
+ }
2584
+ r && C - w >= i && (r(C + 1, y), w = C);
2585
+ }
2586
+ r && r(y, y);
2587
+ const A = performance.now() - e, b = c.getStats(), v = b.eidHits + b.eidMisses + b.selectorHits + b.selectorMisses, x = b.eidHits + b.selectorHits, k = v > 0 ? x / v : 0;
2588
+ return {
2589
+ results: m,
2590
+ failed: p,
2591
+ stats: {
2592
+ totalElements: y,
2593
+ successful: m.length,
2594
+ failed: p.length,
2595
+ skipped: S,
2596
+ totalTimeMs: A,
2597
+ avgTimePerElementMs: m.length > 0 ? A / m.length : 0,
2598
+ cacheHitRate: k
2599
+ }
2600
+ };
2601
+ }
2602
+ export {
2603
+ dt as AnchorFinder,
2604
+ Pt as ConstraintsEvaluator,
2605
+ st as CssGenerator,
2606
+ ut as DEFAULT_GENERATOR_OPTIONS,
2607
+ ft as DEFAULT_RESOLVER_OPTIONS,
2608
+ It as EIDCache,
2609
+ Gt as EID_VERSION,
2610
+ kt as FallbackHandler,
2611
+ Vt as MAX_PATH_DEPTH,
2612
+ xt as PathBuilder,
2613
+ K as ROLE_ANCHOR_VALUES,
2614
+ Y as SEMANTIC_ANCHOR_TAGS,
2615
+ Qt as SEMANTIC_ATTRIBUTES,
2616
+ lt as SEMANTIC_TAGS,
2617
+ wt as SemanticExtractor,
2618
+ Ht as SemanticsMatcher,
2619
+ vt as SvgFingerprinter,
2620
+ $t as calculateConfidence,
2621
+ Yt as calculateElementScore,
2622
+ Nt as createEIDCache,
2623
+ At as filterClasses,
2624
+ Z as generateEID,
2625
+ se as generateEIDBatch,
2626
+ re as generateEIDForElements,
2627
+ te as generateSEQL,
2628
+ Zt as getClassScore,
2629
+ Q as getGlobalCache,
2630
+ Jt as isEID,
2631
+ X as isUtilityClass,
2632
+ V as normalizeText,
2633
+ Ft as parseSEQL,
2634
+ Kt as resetGlobalCache,
2635
+ qt as resolve,
2636
+ ee as resolveSEQL,
2637
+ zt as stringifySEQL,
2638
+ Xt as validateEID
2639
+ };
2
2640
  //# sourceMappingURL=seql-js.js.map