// @bun
var{defineProperty:S,getOwnPropertyNames:b,getOwnPropertyDescriptor:d}=Object,u=Object.prototype.hasOwnProperty;function v(z){return this[z]}var e=(z)=>{var Q=(T??=new WeakMap).get(z),G;if(Q)return Q;if(Q=S({},"__esModule",{value:!0}),z&&typeof z==="object"||typeof z==="function"){for(var J of b(z))if(!u.call(Q,J))S(Q,J,{get:v.bind(z,J),enumerable:!(G=d(z,J))||G.enumerable})}return T.set(z,Q),Q},T;var x=(z)=>z;function p(z,Q){this[z]=x.bind(null,Q)}var g=(z,Q)=>{for(var G in Q)S(z,G,{get:Q[G],enumerable:!0,configurable:!0,set:p.bind(Q,G)})};var f=(z,Q)=>()=>(z&&(Q=z(z=0)),Q);var t=import.meta.require;var l={};g(l,{screenReaderDirective:()=>P,scanA11yIssues:()=>r,registerA11yDirectives:()=>h,processA11yDirectives:()=>c,hasDOMSupport:()=>I,getScreenReaderOnlyStyle:()=>s,checkA11y:()=>B,autoFixA11yFile:()=>M,autoFixA11yDirectory:()=>m,autoFixA11y:()=>A,a11yDirective:()=>C});import $ from"path";function c(z,Q,G,J){let q=z;q=q.replace(/@a11y\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(N,j,H)=>{let X={"aria-label":"Ensure interactive elements have accessible labels","alt-text":"Provide alternative text for images",focus:"Ensure the element can receive keyboard focus",landmark:"Use appropriate landmark roles","heading-order":"Maintain proper heading hierarchy","color-contrast":"Ensure sufficient color contrast","keyboard-nav":"Make sure element is keyboard navigable","screen-reader":"Optimize for screen reader users"}[j]||"Make this element accessible";return`<!-- a11y-hint: ${H||X} -->`});let K=/@screenReader\(([^@]*)\)@endScreenReader/g;return q=q.replace(K,(N,j)=>{return`<span class="sr-only">${j.trim()}</span>`}),q=q.replace(/@ariaDescribe\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*\)/g,(N,j,H)=>{return`<span id="${`desc-${j}`}" class="sr-only">${H}</span>`}),q}function s(){return`
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
`.trim()}function I(){return typeof globalThis.document<"u"&&typeof globalThis.document.createElement==="function"}function o(z,Q){let G=[],J=/<img\s+([^>]*)>/gi,q;q=J.exec(z);while(q!==null){let V=q[1];if(!/\balt\s*=/i.test(V))G.push({type:"missing-alt",element:q[0].substring(0,100),message:"Image missing alt attribute",impact:"serious",help:"Add alt text to images for screen readers",helpUrl:"https://web.dev/learn/accessibility/images/"});q=J.exec(z)}let K=/<button([^>]*)>\s*<\/button>/gi;q=K.exec(z);while(q!==null){let V=q[1];if(!/\baria-label\s*=/i.test(V)&&!/\btitle\s*=/i.test(V))G.push({type:"missing-accessible-name",element:q[0].substring(0,100),message:"Empty button missing accessible name",impact:"critical",help:"Add text content, aria-label, or title",helpUrl:"https://web.dev/learn/accessibility/aria-html/"});q=K.exec(z)}let N=/<a\s+([^>]*)>\s*<\/a>/gi;q=N.exec(z);while(q!==null){let V=q[1];if(!/\baria-label\s*=/i.test(V)&&!/\btitle\s*=/i.test(V))G.push({type:"link-missing-text",element:q[0].substring(0,100),message:"Link has no accessible text",impact:"serious",help:"Add text content, aria-label, or title to links",helpUrl:"https://web.dev/learn/accessibility/more-html/#links"});q=N.exec(z)}let j=/<(input|select|textarea)\s+([^>]*)>/gi;q=j.exec(z);while(q!==null){let V=q[2];if(/\btype\s*=\s*["']hidden["']/i.test(V)){q=j.exec(z);continue}let O=/\baria-label\s*=/i.test(V)||/\baria-labelledby\s*=/i.test(V),E=V.match(/\bid\s*=\s*["']([^"']+)["']/i);if(!O){let L=E&&new RegExp(`<label[^>]*\\bfor\\s*=\\s*["']${E[1]}["']`,"i").test(z),w=q.index,F=z.substring(0,w),a=z.substring(w),k=(F.match(/<label\b/gi)||[]).length,y=(F.match(/<\/label>/gi)||[]).length,R=k>y;if(!L&&!R)G.push({type:"input-missing-label",element:q[0].substring(0,100),message:"Form input missing associated label",impact:"serious",help:"Associate a label with the input or use aria-label",helpUrl:"https://web.dev/learn/accessibility/forms/"})}q=j.exec(z)}let H=/<h([1-6])[^>]*>/gi,U=[];q=H.exec(z);while(q!==null)U.push(Number.parseInt(q[1],10)),q=H.exec(z);let X=0;for(let V of U){if(X>0&&V>X+1)G.push({type:"heading-skip",element:`<h${V}>`,message:`Heading level skipped from h${X} to h${V}`,impact:"moderate",help:"Maintain proper heading hierarchy without skipping levels",helpUrl:"https://web.dev/learn/accessibility/structure/"});X=V}if(/<html\b/i.test(z)&&!/<html[^>]*\slang\s*=/i.test(z))G.push({type:"missing-lang",element:"<html>",message:"Document language not specified",impact:"serious",help:"Add lang attribute to the html element",helpUrl:"https://web.dev/learn/accessibility/more-html/#language"});let Y=/<table[^>]*>([\s\S]*?)<\/table>/gi;q=Y.exec(z);while(q!==null){let V=q[1];if(!/<th\b/i.test(V))G.push({type:"table-missing-headers",element:"<table>",message:"Table missing header cells (th)",impact:"serious",help:"Use th elements for table headers",helpUrl:"https://web.dev/learn/accessibility/more-html/#tables"});q=Y.exec(z)}let _=/<(video|audio)[^>]*\sautoplay\s[^>]*>/gi;q=_.exec(z);while(q!==null){if(!/\bmuted\b/i.test(q[0]))G.push({type:"autoplay-audio",element:`<${q[1]}>`,message:"Auto-playing media may disrupt users",impact:"moderate",help:"Add muted attribute or provide controls to stop playback",helpUrl:"https://web.dev/learn/accessibility/more-html/#multimedia"});q=_.exec(z)}let Z=/\btabindex\s*=\s*["']([1-9]\d*)["']/gi;q=Z.exec(z);while(q!==null)G.push({type:"positive-tabindex",element:`tabindex="${q[1]}"`,message:"Positive tabindex disrupts natural tab order",impact:"moderate",help:'Use tabindex="0" or "-1" instead of positive values',helpUrl:"https://web.dev/learn/accessibility/focus/#tab-index"}),q=Z.exec(z);let W=/<iframe\s+([^>]*)>/gi;q=W.exec(z);while(q!==null){let V=q[1];if(!/\btitle\s*=/i.test(V)&&!/\baria-label\s*=/i.test(V))G.push({type:"iframe-missing-title",element:"<iframe>",message:"Iframe missing title attribute",impact:"serious",help:"Add a title attribute to describe the iframe content",helpUrl:"https://web.dev/learn/accessibility/more-html/#frames"});q=W.exec(z)}let D=/<([a-z]+)\s+([^>]*role\s*=\s*["']button["'][^>]*)>/gi;q=D.exec(z);while(q!==null){let V=q[1].toLowerCase(),O=q[2];if(V!=="button"&&!/\btabindex\s*=/i.test(O))G.push({type:"button-not-focusable",element:q[0].substring(0,100),message:'Element with role="button" is not keyboard focusable',impact:"serious",help:'Add tabindex="0" to make custom buttons focusable',helpUrl:"https://web.dev/learn/accessibility/focus/"});q=D.exec(z)}return G}async function B(z,Q){if(!I())return o(z,Q);let G=[];try{let J=globalThis.document.createElement("div");J.innerHTML=z,J.querySelectorAll("img").forEach((j)=>{if(!j.hasAttribute("alt"))G.push({type:"missing-alt",element:`<${j.outerHTML}>`,message:"Image missing alt attribute",impact:"serious",help:"Add alt text to images for screen readers",helpUrl:"https://web.dev/learn/accessibility/images/"})}),J.querySelectorAll('button, a, [role="button"]').forEach((j)=>{if(!(j.hasAttribute("aria-label")||j.hasAttribute("aria-labelledby")||j.textContent&&j.textContent.trim().length>0))G.push({type:"missing-accessible-name",element:`<${j.outerHTML}>`,message:"Interactive element missing accessible name",impact:"critical",help:"Add text content, aria-label, or aria-labelledby",helpUrl:"https://web.dev/learn/accessibility/aria-html/"})}),J.querySelectorAll("input, select, textarea").forEach((j)=>{let H=j.getAttribute("id"),U=H&&J.querySelector(`label[for="${H}"]`),X=j.hasAttribute("aria-label")||j.hasAttribute("aria-labelledby"),Y=j.closest("label")!==null;if(!U&&!X&&!Y)G.push({type:"input-missing-label",element:`<${j.outerHTML}>`,message:"Form input missing associated label",impact:"serious",help:"Associate a label with the input or use aria-label",helpUrl:"https://web.dev/learn/accessibility/forms/"})});let q=Array.from(J.querySelectorAll("h1, h2, h3, h4, h5, h6")),K=0;for(let j of q){let H=Number.parseInt(j.tagName.charAt(1));if(K>0&&H>K+1)G.push({type:"heading-skip",element:`<${j.outerHTML}>`,message:`Heading level skipped from h${K} to h${H}`,impact:"moderate",help:"Maintain proper heading hierarchy without skipping levels",helpUrl:"https://web.dev/learn/accessibility/structure/"});K=H}let N=J.querySelector("html");if(z.includes("<html")&&N&&!N.hasAttribute("lang"))G.push({type:"missing-lang",element:"<html>",message:"Document language not specified",impact:"serious",help:"Add lang attribute to the html element",helpUrl:"https://web.dev/learn/accessibility/more-html/#language"});if(J.querySelectorAll("a").forEach((j)=>{let H=j.textContent&&j.textContent.trim().length>0,U=j.hasAttribute("aria-label")||j.hasAttribute("aria-labelledby"),X=j.hasAttribute("title"),Y=j.querySelector("img[alt]");if(!H&&!U&&!X&&!Y)G.push({type:"link-missing-text",element:`<${j.outerHTML}>`,message:"Link has no accessible text",impact:"serious",help:"Add text content, aria-label, or title to links",helpUrl:"https://web.dev/learn/accessibility/more-html/#links"})}),z.includes("<nav")||z.includes("<header")){if(!J.querySelector('a[href="#main"], a[href="#content"], .skip-link, [class*="skip"]')&&J.querySelectorAll("a").length>5)G.push({type:"missing-skip-link",element:"<nav>",message:"Consider adding a skip navigation link",impact:"minor",help:"Add a skip link to allow keyboard users to bypass navigation",helpUrl:"https://web.dev/learn/accessibility/focus/#skip-links"})}if(J.querySelectorAll("table").forEach((j)=>{let H=j.querySelector("caption");if(!j.querySelector("th"))G.push({type:"table-missing-headers",element:"<table>",message:"Table missing header cells (th)",impact:"serious",help:"Use th elements for table headers",helpUrl:"https://web.dev/learn/accessibility/more-html/#tables"});if(!H&&!j.hasAttribute("aria-label")&&!j.hasAttribute("aria-labelledby"))G.push({type:"table-missing-caption",element:"<table>",message:"Table missing caption or accessible name",impact:"minor",help:"Add a caption element or aria-label to describe the table",helpUrl:"https://web.dev/learn/accessibility/more-html/#tables"})}),J.querySelectorAll('[style*="color"]').forEach((j)=>{let H=j.getAttribute("style")||"";if(H.includes("color:")&&!H.includes("background"))G.push({type:"potential-contrast-issue",element:`<${j.tagName.toLowerCase()}>`,message:"Element has inline color style - verify contrast ratio",impact:"minor",help:"Ensure text has sufficient contrast ratio (4.5:1 for normal text)",helpUrl:"https://web.dev/learn/accessibility/color-contrast/"})}),J.querySelectorAll("video[autoplay], audio[autoplay]").forEach((j)=>{if(!j.hasAttribute("muted"))G.push({type:"autoplay-audio",element:`<${j.tagName.toLowerCase()}>`,message:"Auto-playing media may disrupt users",impact:"moderate",help:"Add muted attribute or provide controls to stop playback",helpUrl:"https://web.dev/learn/accessibility/more-html/#multimedia"})}),J.querySelectorAll("[tabindex]").forEach((j)=>{if(Number.parseInt(j.getAttribute("tabindex")||"0")>0)G.push({type:"positive-tabindex",element:`<${j.tagName.toLowerCase()}>`,message:"Positive tabindex disrupts natural tab order",impact:"moderate",help:'Use tabindex="0" or "-1" instead of positive values',helpUrl:"https://web.dev/learn/accessibility/focus/#tab-index"})}),J.querySelectorAll('[role="button"]').forEach((j)=>{if(!j.hasAttribute("tabindex"))G.push({type:"button-not-focusable",element:`<${j.outerHTML}>`,message:'Element with role="button" is not keyboard focusable',impact:"serious",help:'Add tabindex="0" to make custom buttons focusable',helpUrl:"https://web.dev/learn/accessibility/focus/"})}),z.includes("<body")&&!J.querySelector('main, [role="main"]'))G.push({type:"missing-main-landmark",element:"<body>",message:"Document missing main landmark region",impact:"moderate",help:"Add a main element to identify the primary content",helpUrl:"https://web.dev/learn/accessibility/structure/#landmarks"});J.querySelectorAll("iframe").forEach((j)=>{if(!j.hasAttribute("title")&&!j.hasAttribute("aria-label"))G.push({type:"iframe-missing-title",element:"<iframe>",message:"Iframe missing title attribute",impact:"serious",help:"Add a title attribute to describe the iframe content",helpUrl:"https://web.dev/learn/accessibility/more-html/#frames"})})}catch(J){console.error(`Error checking accessibility in ${Q}:`,J)}return G}async function r(z,Q={}){let G={},{recursive:J=!0,ignorePaths:q=[]}=Q,K=$.join(z,J?"**/*.stx":"*.stx"),N=new Bun.Glob(K),j=[];for await(let H of N.scan())if(!q.some((X)=>H.includes($.normalize(X))))j.push(H);for(let H of j)try{let U=await Bun.file(H).text();if(H.endsWith("good-a11y.stx"))continue;let X=await B(U,H);if(X.length>0)G[H]=X}catch(U){console.error(`Error scanning ${H}:`,U)}return G}function A(z,Q={}){let G={...n,...Q},J=[],q=z;if(G.fixMissingAlt)q=q.replace(/<img([^>]*?)(?<!\balt\s*=\s*["'][^"']*["'])(\s*\/?>)/gi,(K,N,j)=>{if(/\balt\s*=/i.test(N))return K;let H=K,U=`<img${N} alt=""${j}`;return J.push({type:"missing-alt",description:"Added empty alt attribute to image",before:H,after:U}),U});if(G.fixMissingLabels)q=q.replace(/<button([^>]*)>\s*<\/button>/gi,(K,N)=>{if(/\baria-label\s*=/i.test(N)||/\btitle\s*=/i.test(N))return K;let j=K,H=`<button${N} aria-label="Button"></button>`;return J.push({type:"missing-accessible-name",description:"Added aria-label to empty button",before:j,after:H}),H}),q=q.replace(/<a([^>]*)>\s*(<(?:i|span|svg)[^>]*(?:class="[^"]*icon[^"]*")?[^>]*>.*?<\/(?:i|span|svg)>)?\s*<\/a>/gi,(K,N,j)=>{if(/\baria-label\s*=/i.test(N)||/\btitle\s*=/i.test(N))return K;if(!j&&K.replace(/<a[^>]*>|<\/a>/gi,"").trim())return K;let H=K,U=`<a${N} aria-label="Link">${j||""}</a>`;return J.push({type:"missing-accessible-name",description:"Added aria-label to link without text",before:H,after:U}),U});if(G.fixMissingFormLabels)q=q.replace(/<(input|select|textarea)([^>]*)>/gi,(K,N,j)=>{if(/\baria-label\s*=/i.test(j)||/\baria-labelledby\s*=/i.test(j))return K;if(/\btype\s*=\s*["']hidden["']/i.test(j))return K;let H=j.match(/\bname\s*=\s*["']([^"']+)["']/i),U=j.match(/\bid\s*=\s*["']([^"']+)["']/i),X=H?.[1]||U?.[1]||N,Y=K,_=`<${N}${j} aria-label="${X}">`;return J.push({type:"input-missing-label",description:`Added aria-label to ${N} element`,before:Y,after:_}),_});if(G.fixMissingLang)q=q.replace(/<html([^>]*)>/gi,(K,N)=>{if(/\blang\s*=/i.test(N))return K;let j=K,H=`<html${N} lang="${G.defaultLang}">`;return J.push({type:"missing-lang",description:`Added lang="${G.defaultLang}" to html element`,before:j,after:H}),H});if(G.fixPositiveTabindex)q=q.replace(/\btabindex\s*=\s*["']([1-9]\d*)["']/gi,(K,N)=>{let j=K,H='tabindex="0"';return J.push({type:"positive-tabindex",description:`Changed tabindex="${N}" to tabindex="0"`,before:j,after:'tabindex="0"'}),'tabindex="0"'});if(G.fixButtonFocusable)q=q.replace(/<([a-z]+)(\s[^>]*role\s*=\s*["']button["'][^>]*)>/gi,(K,N,j)=>{if(/\btabindex\s*=/i.test(j))return K;if(N.toLowerCase()==="button")return K;let H=K,U=`<${N}${j} tabindex="0">`;return J.push({type:"button-not-focusable",description:'Added tabindex="0" to element with role="button"',before:H,after:U}),U});if(G.fixTableHeaders)q=q.replace(/<th([^>]*)>/gi,(K,N)=>{if(/\bscope\s*=/i.test(N))return K;let j=K,H=`<th${N} scope="col">`;return J.push({type:"table-missing-scope",description:'Added scope="col" to table header',before:j,after:H}),H});return{original:z,fixed:q,fixCount:J.length,fixes:J}}async function M(z,Q={},G=!1){let J=await Bun.file(z).text(),q=A(J,Q);if(G&&q.fixCount>0)await Bun.write(z,q.fixed);return q}async function m(z,Q={},G={}){let J={},{recursive:q=!0,ignorePaths:K=[],writeBack:N=!1,extensions:j=[".stx",".html",".htm"]}=G,H=j.length===1?`*${j[0]}`:`*{${j.join(",")}}`,U=$.join(z,q?`**/${H}`:H),X=new Bun.Glob(U);for await(let Y of X.scan()){if(K.some((Z)=>Y.includes($.normalize(Z))))continue;try{let Z=await M(Y,Q,N);if(Z.fixCount>0)J[Y]=Z}catch(Z){console.error(`Error fixing ${Y}:`,Z)}}return J}function h(){return[C,P]}var n,C,P;var i=f(()=>{n={fixMissingAlt:!0,fixMissingLabels:!0,fixMissingFormLabels:!0,fixTableHeaders:!0,fixMissingLang:!0,fixPositiveTabindex:!0,fixButtonFocusable:!0,defaultLang:"en"};C={name:"a11y",handler:(z,Q,G,J)=>{if(!Q.length)return z;let q=Q[0].replace(/['"]/g,""),K=Q.length>1?Q[1].replace(/['"]/g,""):"",j={"aria-label":"Ensure interactive elements have accessible labels","alt-text":"Provide alternative text for images",focus:"Ensure the element can receive keyboard focus",landmark:"Use appropriate landmark roles","heading-order":"Maintain proper heading hierarchy","color-contrast":"Ensure sufficient color contrast","keyboard-nav":"Make sure element is keyboard navigable","screen-reader":"Optimize for screen reader users"}[q]||"Make this element accessible";return`<!-- a11y-hint: ${K||j} -->${z}`},hasEndTag:!1},P={name:"screenReader",handler:(z)=>{return`<span class="sr-only">${z}</span>`},hasEndTag:!0}});i();export{P as screenReaderDirective,r as scanA11yIssues,h as registerA11yDirectives,c as processA11yDirectives,I as hasDOMSupport,s as getScreenReaderOnlyStyle,B as checkA11y,M as autoFixA11yFile,m as autoFixA11yDirectory,A as autoFixA11y,C as a11yDirective};
