// @bun
var{defineProperty:D,getOwnPropertyNames:Qj,getOwnPropertyDescriptor:Xj}=Object,Yj=Object.prototype.hasOwnProperty;function Zj(j){return this[j]}var dj=(j)=>{var q=(x??=new WeakMap).get(j),Q;if(q)return q;if(q=D({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var X of Qj(j))if(!Yj.call(q,X))D(q,X,{get:Zj.bind(j,X),enumerable:!(Q=Xj(j,X))||Q.enumerable})}return x.set(j,q),q},x;var $j=(j)=>j;function zj(j,q){this[j]=$j.bind(null,q)}var I=(j,q)=>{for(var Q in q)D(j,Q,{get:q[Q],enumerable:!0,configurable:!0,set:zj.bind(q,Q)})};var O=(j,q)=>()=>(j&&(q=j(j=0)),q);var v=import.meta.require;var Ej={};I(Ej,{screenReaderDirective:()=>f,scanA11yIssues:()=>Wj,registerA11yDirectives:()=>Oj,processA11yDirectives:()=>Uj,hasDOMSupport:()=>d,getScreenReaderOnlyStyle:()=>_j,checkA11y:()=>A,autoFixA11yFile:()=>p,autoFixA11yDirectory:()=>Hj,autoFixA11y:()=>g,a11yDirective:()=>u});import N from"path";function Uj(j,q,Q,X){let J=j;J=J.replace(/@a11y\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,($,K,Y)=>{let U={"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"}[K]||"Make this element accessible";return`<!-- a11y-hint: ${Y||U} -->`});let Z=/@screenReader\(([^@]*)\)@endScreenReader/g;return J=J.replace(Z,($,K)=>{return`<span class="sr-only">${K.trim()}</span>`}),J=J.replace(/@ariaDescribe\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*\)/g,($,K,Y)=>{return`<span id="${`desc-${K}`}" class="sr-only">${Y}</span>`}),J}function _j(){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 d(){return typeof globalThis.document<"u"&&typeof globalThis.document.createElement==="function"}function Vj(j,q){let Q=[],X=/<img\s+([^>]*)>/gi,J;J=X.exec(j);while(J!==null){let _=J[1];if(!/\balt\s*=/i.test(_))Q.push({type:"missing-alt",element:J[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/"});J=X.exec(j)}let Z=/<button([^>]*)>\s*<\/button>/gi;J=Z.exec(j);while(J!==null){let _=J[1];if(!/\baria-label\s*=/i.test(_)&&!/\btitle\s*=/i.test(_))Q.push({type:"missing-accessible-name",element:J[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/"});J=Z.exec(j)}let $=/<a\s+([^>]*)>\s*<\/a>/gi;J=$.exec(j);while(J!==null){let _=J[1];if(!/\baria-label\s*=/i.test(_)&&!/\btitle\s*=/i.test(_))Q.push({type:"link-missing-text",element:J[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"});J=$.exec(j)}let K=/<(input|select|textarea)\s+([^>]*)>/gi;J=K.exec(j);while(J!==null){let _=J[2];if(/\btype\s*=\s*["']hidden["']/i.test(_)){J=K.exec(j);continue}let w=/\baria-label\s*=/i.test(_)||/\baria-labelledby\s*=/i.test(_),b=_.match(/\bid\s*=\s*["']([^"']+)["']/i);if(!w){let jj=b&&new RegExp(`<label[^>]*\\bfor\\s*=\\s*["']${b[1]}["']`,"i").test(j),P=J.index,y=j.substring(0,P),vj=j.substring(P),qj=(y.match(/<label\b/gi)||[]).length,Jj=(y.match(/<\/label>/gi)||[]).length,Kj=qj>Jj;if(!jj&&!Kj)Q.push({type:"input-missing-label",element:J[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/"})}J=K.exec(j)}let Y=/<h([1-6])[^>]*>/gi,z=[];J=Y.exec(j);while(J!==null)z.push(Number.parseInt(J[1],10)),J=Y.exec(j);let U=0;for(let _ of z){if(U>0&&_>U+1)Q.push({type:"heading-skip",element:`<h${_}>`,message:`Heading level skipped from h${U} to h${_}`,impact:"moderate",help:"Maintain proper heading hierarchy without skipping levels",helpUrl:"https://web.dev/learn/accessibility/structure/"});U=_}if(/<html\b/i.test(j)&&!/<html[^>]*\slang\s*=/i.test(j))Q.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 V=/<table[^>]*>([\s\S]*?)<\/table>/gi;J=V.exec(j);while(J!==null){let _=J[1];if(!/<th\b/i.test(_))Q.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"});J=V.exec(j)}let G=/<(video|audio)[^>]*\sautoplay\s[^>]*>/gi;J=G.exec(j);while(J!==null){if(!/\bmuted\b/i.test(J[0]))Q.push({type:"autoplay-audio",element:`<${J[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"});J=G.exec(j)}let W=/\btabindex\s*=\s*["']([1-9]\d*)["']/gi;J=W.exec(j);while(J!==null)Q.push({type:"positive-tabindex",element:`tabindex="${J[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"}),J=W.exec(j);let C=/<iframe\s+([^>]*)>/gi;J=C.exec(j);while(J!==null){let _=J[1];if(!/\btitle\s*=/i.test(_)&&!/\baria-label\s*=/i.test(_))Q.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"});J=C.exec(j)}let F=/<([a-z]+)\s+([^>]*role\s*=\s*["']button["'][^>]*)>/gi;J=F.exec(j);while(J!==null){let _=J[1].toLowerCase(),w=J[2];if(_!=="button"&&!/\btabindex\s*=/i.test(w))Q.push({type:"button-not-focusable",element:J[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/"});J=F.exec(j)}return Q}async function A(j,q){if(!d())return Vj(j,q);let Q=[];try{let X=globalThis.document.createElement("div");X.innerHTML=j,X.querySelectorAll("img").forEach((K)=>{if(!K.hasAttribute("alt"))Q.push({type:"missing-alt",element:`<${K.outerHTML}>`,message:"Image missing alt attribute",impact:"serious",help:"Add alt text to images for screen readers",helpUrl:"https://web.dev/learn/accessibility/images/"})}),X.querySelectorAll('button, a, [role="button"]').forEach((K)=>{if(!(K.hasAttribute("aria-label")||K.hasAttribute("aria-labelledby")||K.textContent&&K.textContent.trim().length>0))Q.push({type:"missing-accessible-name",element:`<${K.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/"})}),X.querySelectorAll("input, select, textarea").forEach((K)=>{let Y=K.getAttribute("id"),z=Y&&X.querySelector(`label[for="${Y}"]`),U=K.hasAttribute("aria-label")||K.hasAttribute("aria-labelledby"),V=K.closest("label")!==null;if(!z&&!U&&!V)Q.push({type:"input-missing-label",element:`<${K.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 J=Array.from(X.querySelectorAll("h1, h2, h3, h4, h5, h6")),Z=0;for(let K of J){let Y=Number.parseInt(K.tagName.charAt(1));if(Z>0&&Y>Z+1)Q.push({type:"heading-skip",element:`<${K.outerHTML}>`,message:`Heading level skipped from h${Z} to h${Y}`,impact:"moderate",help:"Maintain proper heading hierarchy without skipping levels",helpUrl:"https://web.dev/learn/accessibility/structure/"});Z=Y}let $=X.querySelector("html");if(j.includes("<html")&&$&&!$.hasAttribute("lang"))Q.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(X.querySelectorAll("a").forEach((K)=>{let Y=K.textContent&&K.textContent.trim().length>0,z=K.hasAttribute("aria-label")||K.hasAttribute("aria-labelledby"),U=K.hasAttribute("title"),V=K.querySelector("img[alt]");if(!Y&&!z&&!U&&!V)Q.push({type:"link-missing-text",element:`<${K.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"})}),j.includes("<nav")||j.includes("<header")){if(!X.querySelector('a[href="#main"], a[href="#content"], .skip-link, [class*="skip"]')&&X.querySelectorAll("a").length>5)Q.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(X.querySelectorAll("table").forEach((K)=>{let Y=K.querySelector("caption");if(!K.querySelector("th"))Q.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(!Y&&!K.hasAttribute("aria-label")&&!K.hasAttribute("aria-labelledby"))Q.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"})}),X.querySelectorAll('[style*="color"]').forEach((K)=>{let Y=K.getAttribute("style")||"";if(Y.includes("color:")&&!Y.includes("background"))Q.push({type:"potential-contrast-issue",element:`<${K.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/"})}),X.querySelectorAll("video[autoplay], audio[autoplay]").forEach((K)=>{if(!K.hasAttribute("muted"))Q.push({type:"autoplay-audio",element:`<${K.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"})}),X.querySelectorAll("[tabindex]").forEach((K)=>{if(Number.parseInt(K.getAttribute("tabindex")||"0")>0)Q.push({type:"positive-tabindex",element:`<${K.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"})}),X.querySelectorAll('[role="button"]').forEach((K)=>{if(!K.hasAttribute("tabindex"))Q.push({type:"button-not-focusable",element:`<${K.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/"})}),j.includes("<body")&&!X.querySelector('main, [role="main"]'))Q.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"});X.querySelectorAll("iframe").forEach((K)=>{if(!K.hasAttribute("title")&&!K.hasAttribute("aria-label"))Q.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(X){console.error(`Error checking accessibility in ${q}:`,X)}return Q}async function Wj(j,q={}){let Q={},{recursive:X=!0,ignorePaths:J=[]}=q,Z=N.join(j,X?"**/*.stx":"*.stx"),$=new Bun.Glob(Z),K=[];for await(let Y of $.scan())if(!J.some((U)=>Y.includes(N.normalize(U))))K.push(Y);for(let Y of K)try{let z=await Bun.file(Y).text();if(Y.endsWith("good-a11y.stx"))continue;let U=await A(z,Y);if(U.length>0)Q[Y]=U}catch(z){console.error(`Error scanning ${Y}:`,z)}return Q}function g(j,q={}){let Q={...Gj,...q},X=[],J=j;if(Q.fixMissingAlt)J=J.replace(/<img([^>]*?)(?<!\balt\s*=\s*["'][^"']*["'])(\s*\/?>)/gi,(Z,$,K)=>{if(/\balt\s*=/i.test($))return Z;let Y=Z,z=`<img${$} alt=""${K}`;return X.push({type:"missing-alt",description:"Added empty alt attribute to image",before:Y,after:z}),z});if(Q.fixMissingLabels)J=J.replace(/<button([^>]*)>\s*<\/button>/gi,(Z,$)=>{if(/\baria-label\s*=/i.test($)||/\btitle\s*=/i.test($))return Z;let K=Z,Y=`<button${$} aria-label="Button"></button>`;return X.push({type:"missing-accessible-name",description:"Added aria-label to empty button",before:K,after:Y}),Y}),J=J.replace(/<a([^>]*)>\s*(<(?:i|span|svg)[^>]*(?:class="[^"]*icon[^"]*")?[^>]*>.*?<\/(?:i|span|svg)>)?\s*<\/a>/gi,(Z,$,K)=>{if(/\baria-label\s*=/i.test($)||/\btitle\s*=/i.test($))return Z;if(!K&&Z.replace(/<a[^>]*>|<\/a>/gi,"").trim())return Z;let Y=Z,z=`<a${$} aria-label="Link">${K||""}</a>`;return X.push({type:"missing-accessible-name",description:"Added aria-label to link without text",before:Y,after:z}),z});if(Q.fixMissingFormLabels)J=J.replace(/<(input|select|textarea)([^>]*)>/gi,(Z,$,K)=>{if(/\baria-label\s*=/i.test(K)||/\baria-labelledby\s*=/i.test(K))return Z;if(/\btype\s*=\s*["']hidden["']/i.test(K))return Z;let Y=K.match(/\bname\s*=\s*["']([^"']+)["']/i),z=K.match(/\bid\s*=\s*["']([^"']+)["']/i),U=Y?.[1]||z?.[1]||$,V=Z,G=`<${$}${K} aria-label="${U}">`;return X.push({type:"input-missing-label",description:`Added aria-label to ${$} element`,before:V,after:G}),G});if(Q.fixMissingLang)J=J.replace(/<html([^>]*)>/gi,(Z,$)=>{if(/\blang\s*=/i.test($))return Z;let K=Z,Y=`<html${$} lang="${Q.defaultLang}">`;return X.push({type:"missing-lang",description:`Added lang="${Q.defaultLang}" to html element`,before:K,after:Y}),Y});if(Q.fixPositiveTabindex)J=J.replace(/\btabindex\s*=\s*["']([1-9]\d*)["']/gi,(Z,$)=>{let K=Z,Y='tabindex="0"';return X.push({type:"positive-tabindex",description:`Changed tabindex="${$}" to tabindex="0"`,before:K,after:'tabindex="0"'}),'tabindex="0"'});if(Q.fixButtonFocusable)J=J.replace(/<([a-z]+)(\s[^>]*role\s*=\s*["']button["'][^>]*)>/gi,(Z,$,K)=>{if(/\btabindex\s*=/i.test(K))return Z;if($.toLowerCase()==="button")return Z;let Y=Z,z=`<${$}${K} tabindex="0">`;return X.push({type:"button-not-focusable",description:'Added tabindex="0" to element with role="button"',before:Y,after:z}),z});if(Q.fixTableHeaders)J=J.replace(/<th([^>]*)>/gi,(Z,$)=>{if(/\bscope\s*=/i.test($))return Z;let K=Z,Y=`<th${$} scope="col">`;return X.push({type:"table-missing-scope",description:'Added scope="col" to table header',before:K,after:Y}),Y});return{original:j,fixed:J,fixCount:X.length,fixes:X}}async function p(j,q={},Q=!1){let X=await Bun.file(j).text(),J=g(X,q);if(Q&&J.fixCount>0)await Bun.write(j,J.fixed);return J}async function Hj(j,q={},Q={}){let X={},{recursive:J=!0,ignorePaths:Z=[],writeBack:$=!1,extensions:K=[".stx",".html",".htm"]}=Q,Y=K.length===1?`*${K[0]}`:`*{${K.join(",")}}`,z=N.join(j,J?`**/${Y}`:Y),U=new Bun.Glob(z);for await(let V of U.scan()){if(Z.some((W)=>V.includes(N.normalize(W))))continue;try{let W=await p(V,q,$);if(W.fixCount>0)X[V]=W}catch(W){console.error(`Error fixing ${V}:`,W)}}return X}function Oj(){return[u,f]}var Gj,u,f;var m=O(()=>{Gj={fixMissingAlt:!0,fixMissingLabels:!0,fixMissingFormLabels:!0,fixTableHeaders:!0,fixMissingLang:!0,fixPositiveTabindex:!0,fixButtonFocusable:!0,defaultLang:"en"};u={name:"a11y",handler:(j,q,Q,X)=>{if(!q.length)return j;let J=q[0].replace(/['"]/g,""),Z=q.length>1?q[1].replace(/['"]/g,""):"",K={"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: ${Z||K} -->${j}`},hasEndTag:!1},f={name:"screenReader",handler:(j)=>{return`<span class="sr-only">${j}</span>`},hasEndTag:!0}});function l(j){let q={...o,...j};return{enabled:q.enabled??!0,outDir:q.outDir??".stx/dist/story",storyMatch:q.storyMatch??["**/*.story.stx"],storyIgnored:q.storyIgnored??["**/node_modules/**","**/dist/**","**/.stx/**"],tree:{...n,...q.tree},theme:{title:"STX Components",defaultColorScheme:"auto",darkClass:"dark",...q.theme},responsivePresets:q.responsivePresets??c,backgroundPresets:q.backgroundPresets??h,autoApplyContrastColor:q.autoApplyContrastColor??!1,setupFile:q.setupFile,port:q.port??6006}}function uj(){return{...o}}var c,h,n,o;var r=O(()=>{c=[{label:"Mobile (Small)",width:320,height:568},{label:"Mobile (Medium)",width:375,height:667},{label:"Mobile (Large)",width:414,height:896},{label:"Tablet",width:768,height:1024},{label:"Laptop",width:1024},{label:"Desktop",width:1280},{label:"Desktop (Large)",width:1920}],h=[{label:"Transparent",color:"transparent",contrastColor:"#333"},{label:"White",color:"#ffffff",contrastColor:"#333"},{label:"Light Gray",color:"#f5f5f5",contrastColor:"#333"},{label:"Dark Gray",color:"#333333",contrastColor:"#fff"},{label:"Black",color:"#000000",contrastColor:"#fff"}],n={file:"title",order:"asc",groups:[]},o={enabled:!0,outDir:".stx/dist/story",storyMatch:["**/*.story.stx"],storyIgnored:["**/node_modules/**","**/dist/**","**/.stx/**"],tree:n,theme:{title:"STX Components",defaultColorScheme:"auto",darkClass:"dark"},responsivePresets:c,backgroundPresets:h,autoApplyContrastColor:!1,port:6006}});var Aj={};I(Aj,{updateContextTree:()=>Nj,updateContextStoryFiles:()=>Ij,createContext:()=>H});import Bj from"path";async function H(j){let q=j.root??process.cwd(),Q;try{let $=await import(Bj.join(q,"stx.config.ts"));Q=($.default||$).story}catch{}let X={...Q,...j.config},J=l(X);return{root:q,config:J,storyFiles:[],tree:void 0,mode:j.mode}}function Ij(j,q){j.storyFiles=q}function Nj(j,q){j.tree=q}var s=O(()=>{r()});var Rj={};I(Rj,{updateSnapshots:()=>wj,runVisualTests:()=>E,runA11yTests:()=>kj,formatTestResults:()=>Tj});import M from"fs";import i from"path";async function E(j,q={}){let Q=Date.now(),X={total:0,passed:0,failed:0,new:0,failures:[],duration:0},J=q.snapshotDir||i.join(j.root,".stx","story","snapshots");await M.promises.mkdir(J,{recursive:!0});let Z=j.storyFiles;if(q.filter&&q.filter.length>0)Z=Z.filter(($)=>q.filter.some((K)=>$.fileName.toLowerCase().includes(K.toLowerCase())));for(let $ of Z)await Mj($,J,q,X);return X.duration=Date.now()-Q,X}async function Mj(j,q,Q,X){let J=j.story;if(!J)return;for(let Z of J.variants){X.total++;let $=i.join(q,`${j.id}-${Z.id}.snap`),K=Dj(Z.source||""),Y=await Lj($);if(Q.update||!Y){let z={storyId:j.id,variantId:Z.id,component:j.fileName,timestamp:Date.now(),hash:K};if(await M.promises.writeFile($,JSON.stringify(z,null,2)),!Y)X.new++;X.passed++}else try{let z=await M.promises.readFile($,"utf-8"),U=JSON.parse(z);if(U.hash===K)X.passed++;else X.failed++,X.failures.push({storyId:j.id,variantId:Z.id,component:j.fileName,message:"Snapshot mismatch",difference:Sj(U.hash,K)})}catch(z){X.failed++,X.failures.push({storyId:j.id,variantId:Z.id,component:j.fileName,message:`Error reading snapshot: ${z}`})}}}async function wj(j,q={}){return(await E(j,{...q,update:!0})).total}function Dj(j){let q=0;for(let Q=0;Q<j.length;Q++){let X=j.charCodeAt(Q);q=(q<<5)-q+X,q=q&q}return q.toString(16)}function Sj(j,q){if(j===q)return 0;let Q=Math.abs(Number.parseInt(j,16)-Number.parseInt(q,16));return Math.min(Q/1e6,1)}async function Lj(j){try{return await M.promises.access(j),!0}catch{return!1}}function Tj(j){let q=[];if(q.push(""),q.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"),q.push("  STX Story Visual Regression Tests"),q.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"),q.push(""),j.failures.length>0){q.push("  \u274C Failures:"),q.push("");for(let Q of j.failures){if(q.push(`    \u2022 ${Q.component} / ${Q.variantId}`),q.push(`      ${Q.message}`),Q.difference!==void 0)q.push(`      Difference: ${(Q.difference*100).toFixed(2)}%`);q.push("")}}if(q.push("  Summary:"),q.push(`    Total:  ${j.total}`),q.push(`    Passed: ${j.passed} \u2713`),q.push(`    Failed: ${j.failed} \u2717`),j.new>0)q.push(`    New:    ${j.new} \u26A1`);return q.push(`    Time:   ${j.duration}ms`),q.push(""),q.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"),q.push(""),q.join(`
`)}async function kj(j,q={}){let Q=performance.now(),X=[],J=0,Z=0;for(let K of j.storyFiles)try{let Y=await Bun.file(K.path).text(),z=await A(Y,K.path);if(z.length>0){for(let U of z)X.push({storyId:K.id,variantId:"default",component:K.component,message:`A11y: ${U.message}`,expected:"No accessibility violations",actual:`${U.type}: ${U.message} (impact: ${U.impact})`});Z++}else J++}catch(Y){X.push({storyId:K.id,variantId:"default",component:K.component,message:`Failed to check a11y: ${Y instanceof Error?Y.message:String(Y)}`,expected:"File readable for a11y check",actual:"File read error"}),Z++}let $=performance.now()-Q;return{total:j.storyFiles.length,passed:J,failed:Z,new:0,failures:X,duration:$}}var a=O(()=>{m()});var k={};I(k,{watchStoryFiles:()=>yj,scanStoryFiles:()=>Cj,isNonComponentFile:()=>Pj});import S from"fs";import B from"path";async function Cj(j){let{root:q,config:Q}=j,X=[],J=await Fj(q,Q.storyMatch,Q.storyIgnored);for(let Z of J){let $=B.resolve(q,Z),K=L(Z,$);X.push(K)}return X}async function Fj(j,q,Q){let X=[];async function J(Z,$){let K=await S.promises.readdir(Z,{withFileTypes:!0});for(let Y of K){let z=B.join(Z,Y.name),U=B.relative($,z);if(e(U,Q))continue;if(Y.isDirectory())await J(z,$);else if(Y.isFile()){if(t(U,q))X.push(U)}}}return await J(j,j),X}function e(j,q){for(let Q of q)if(T(j,Q))return!0;return!1}function Pj(j){for(let q of bj)if(T(j,q))return!0;return!1}function t(j,q){for(let Q of q)if(T(j,Q))return!0;return!1}function T(j,q){let Q=j.replace(/\\/g,"/"),J=q.replace(/\\/g,"/").replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"{{GLOBSTAR}}").replace(/\*/g,"[^/]*").replace(/\?/g,".").replace(/\{\{GLOBSTAR\}\}/g,".*");return J=`^${J}$`,new RegExp(J).test(Q)}function L(j,q){let Q=B.basename(j,".story.stx");return{id:j.toLowerCase().replace(/\.story\.stx$/,"").replace(/[/\\]/g,"-").replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""),path:q,relativePath:j,fileName:Q,treeFile:{title:Q,path:j}}}function yj(j,q){let{root:Q,config:X}=j,J=[],Z=S.watch(Q,{recursive:!0},async($,K)=>{if(!K)return;let Y=K.replace(/\\/g,"/");if(!t(Y,X.storyMatch))return;if(e(Y,X.storyIgnored))return;let z=B.resolve(Q,Y);try{await S.promises.access(z);let U=L(Y,z);q($==="rename"?"add":"change",U)}catch{let U=L(Y,z);q("unlink",U)}});return J.push(Z),()=>{for(let $ of J)$.close()}}var bj;var R=O(()=>{bj=["**/layouts/**","**/pages/**","**/partials/**","**/_*.stx","**/layout.stx","**/page.stx","**/error.stx","**/loading.stx"]});s();a();async function aj(j={}){let{describe:q,test:Q,expect:X}=await import("bun:test"),J=await H({mode:"build"});q("STX Story Visual Tests",()=>{Q("should pass visual regression tests",async()=>{let Z=await E(J,{filter:j.filter,threshold:j.threshold,update:j.update});if(console.log(`
Visual Tests: ${Z.passed}/${Z.total} passed`),Z.failed>0){console.log(`
Failed tests:`);for(let $ of Z.failures)console.log(`  \u2717 ${$.storyId} - ${$.variantId}`),console.log(`    Difference: ${($.difference??0).toFixed(2)}%`)}X(Z.failed).toBe(0)},j.timeout||30000)})}async function ej(j={}){let{describe:q,test:Q,expect:X}=await import("bun:test"),J=await H({mode:"build"}),{scanStoryFiles:Z}=await Promise.resolve().then(() => (R(),k)),$=await Z(J);q("STX Stories",()=>{for(let K of $){if(j.filter&&j.filter.length>0){if(!j.filter.some((z)=>K.fileName.toLowerCase().includes(z.toLowerCase())))continue}q(K.fileName,()=>{if(Q("should render without errors",async()=>{let Y=await Bun.file(K.path).text();X(Y).toBeTruthy(),X(Y.length).toBeGreaterThan(0)}),K.story)for(let Y of K.story.variants)Q(`variant: ${Y.title}`,async()=>{if(X(Y.title).toBeTruthy(),Y.source)X(Y.source.length).toBeGreaterThan(0)})})}})}async function xj(j={}){let q=Date.now(),Q=await H({mode:"build"}),X=await E(Q,{filter:j.filter,threshold:j.threshold,update:j.update});return{passed:X.passed,failed:X.failed,total:X.total,duration:Date.now()-q}}function tj(j){return`/**
 * Auto-generated story tests
 * Run with: bun test
 */

import { describe, test, expect } from 'bun:test'
import { createContext } from '@stacksjs/stx/story'
import { runVisualTests } from '@stacksjs/stx/story'

${j.map((Q)=>`import './${Q}.story.stx'`).join(`
`)}

describe('Story Visual Tests', () => {
  test('all stories pass visual regression', async () => {
    const ctx = await createContext({ mode: 'build' })
    const results = await runVisualTests(ctx)

    expect(results.failed).toBe(0)
  })
})
`}async function jq(j={}){let{watchStoryFiles:q}=await Promise.resolve().then(() => (R(),k)),Q=await H({mode:"dev"});console.log("Watching for story changes..."),q(Q,async(X,J)=>{console.log(`
${X}: ${J}`),console.log("Running tests...");let Z=await xj(j);if(Z.failed>0)console.log(`
\u274C ${Z.failed} test(s) failed`);else console.log(`
\u2713 All ${Z.total} tests passed (${Z.duration}ms)`)})}export{jq as watchStoryTests,xj as runStoryTests,tj as generateTestFile,ej as createStoryTests,aj as createStoryTestSuite};
