var s=class{constructor(e={}){this.config=e,this.enabled=e.enabled!==!1,this.priority=e.priority||50}getName(){throw new Error("EventEnricher.getName() must be implemented")}canEnrich(e){return this.enabled}async enrich(e,r){throw new Error("EventEnricher.enrich() must be implemented")}handleError(e,r){return console.warn(`[${this.getName()}] Enrichment failed for event ${r.type}:`,e.message),null}};import o from"node:crypto";var h=class extends s{getName(){return"AccessibilityEnricher"}getPriority(){return 100}canEnrich(e){return!this.enabled||!e.element||!e.event?!1:["click","fill","type","selectOption","hover"].includes(e.event.type)}async enrich(e,r){try{let{page:t,element:n}=r,i=await t.accessibility.snapshot(),a=await this.findAxNode(n,i);if(!a)return null;let l=await this.getAxContext(a,i),u=this.hashAxSubtree(a),f=this.hashAxPath(l.path);return{accessibility:{role:a.role,name:a.name||"",level:l.level,parent:l.parent,siblings:l.siblings,axTreeHash:u,axPathHash:f}}}catch(t){return this.handleError(t,e)}}async findAxNode(e,r){let t=await e.evaluate(n=>({role:n.getAttribute("role")||n.tagName.toLowerCase(),name:n.getAttribute("aria-label")||n.textContent?.trim()||"",tagName:n.tagName.toLowerCase()}));return this.searchAxTree(r,t)}searchAxTree(e,r){if(!e)return null;if(e.role===r.role&&(e.name||"").includes(r.name.substring(0,20)))return e;if(e.children)for(let t of e.children){let n=this.searchAxTree(t,r);if(n)return n}return null}getAxContext(e,r){let t={level:0,parent:null,siblings:[],path:[]},n=this.findParent(e,r);return n&&(t.parent={role:n.role,name:n.name},t.siblings=(n.children||[]).filter(i=>i!==e).map(i=>({role:i.role,name:i.name})).slice(0,3)),t.level=this.calculateLevel(e,r),t.path=this.buildPath(e,r),t}findParent(e,r,t=r){if(!t||!t.children)return null;if(t.children.includes(e))return t;for(let n of t.children){let i=this.findParent(e,r,n);if(i)return i}return null}calculateLevel(e,r,t=r,n=0){if(t===e)return n;if(t.children)for(let i of t.children){let a=this.calculateLevel(e,r,i,n+1);if(a>=0)return a}return-1}buildPath(e,r,t=r,n=[]){if(t===e)return[...n,{role:t.role,name:t.name}];if(t.children)for(let i of t.children){let a=this.buildPath(e,r,i,[...n,{role:t.role,name:t.name}]);if(a)return a}return null}hashAxSubtree(e){let r=JSON.stringify({role:e.role,name:e.name,children:(e.children||[]).map(t=>({role:t.role,name:t.name}))});return o.createHash("md5").update(r).digest("hex").substring(0,12)}hashAxPath(e){let r=e.map(t=>`${t.role}:${t.name}`).join("/");return o.createHash("md5").update(r).digest("hex").substring(0,12)}},p=h;export{h as AccessibilityEnricher,p as default};
