// @bun
var{defineProperty:k,getOwnPropertyNames:T,getOwnPropertyDescriptor:w}=Object,I=Object.prototype.hasOwnProperty;function L(B){return this[B]}var v=(B)=>{var q=(z??=new WeakMap).get(B),H;if(q)return q;if(q=k({},"__esModule",{value:!0}),B&&typeof B==="object"||typeof B==="function"){for(var G of T(B))if(!I.call(q,G))k(q,G,{get:L.bind(B,G),enumerable:!(H=w(B,G))||H.enumerable})}return z.set(B,q),q},z;var O=(B)=>B;function V(B,q){this[B]=O.bind(null,q)}var d=(B,q)=>{for(var H in q)k(B,H,{get:q[H],enumerable:!0,configurable:!0,set:V.bind(q,H)})};var p=(B,q)=>()=>(B&&(q=B(B=0)),q);var y=import.meta.require;import N from"fs";async function x(B){let q=await N.promises.readFile(B,"utf-8");return j(q,B)}function j(B,q){let H=B.match(/<Story\s+([^>]*)>([\s\S]*?)<\/Story>/i);if(!H)return null;let G=H[1],J=H[2],Q=K(G,"title")||S(q),U=E(Q),W=K(G,"group"),Y=K(G,"icon"),Z=K(G,"icon-color")||K(G,"iconColor"),_=K(G,"docs-only")==="true"||K(G,"docsOnly")==="true",X=C(G),$=R(J);return{id:U,title:Q,group:W,variants:$,layout:X,icon:Y,iconColor:Z,docsOnly:_}}function R(B){let q=[],H=/<Variant\s+([^>]*)>([\s\S]*?)<\/Variant>/gi,G=H.exec(B);while(G!==null){let J=G[1],Q=G[2],U=K(J,"title")||"Default",W=E(U),Y=K(J,"icon"),Z=K(J,"icon-color")||K(J,"iconColor"),_=K(J,"responsive-disabled")==="true",X=K(J,":init-state")||K(J,"init-state"),$=X?M(B,X):{},F=g(Q);q.push({id:W,title:U,icon:Y,iconColor:Z,state:$,source:F,responsiveDisabled:_}),G=H.exec(B)}if(q.length===0)q.push({id:"default",title:"Default",state:{}});return q}function K(B,q){let H=[new RegExp(`:${q}\\s*=\\s*["']([^"']+)["']`,"i"),new RegExp(`${q}\\s*=\\s*["']([^"']+)["']`,"i"),new RegExp(`:${q}\\s*=\\s*"([^"]+)"`,"i"),new RegExp(`${q}\\s*=\\s*"([^"]+)"`,"i")];for(let G of H){let J=B.match(G);if(J)return J[1]}return}function C(B){let q=K(B,":layout")||K(B,"layout");if(!q)return;try{let H=q.replace(/'/g,'"').replace(/(\w+):/g,'"$1":');return JSON.parse(H)}catch{return{type:"single"}}}function M(B,q){let H=B.match(/<script[^>]*>([\s\S]*?)<\/script>/i);if(!H)return{};let G=H[1],J=new RegExp(`function\\s+${q}\\s*\\(\\)\\s*\\{([\\s\\S]*?)\\breturn\\s*\\{([\\s\\S]*?)\\}`,"i"),Q=G.match(J);if(!Q){let U=new RegExp(`(?:const|let|var)\\s+${q}\\s*=\\s*\\(\\)\\s*=>\\s*\\(\\{([\\s\\S]*?)\\}\\)`,"i"),W=G.match(U);if(W)return D(W[1]);return{}}return D(Q[2])}function D(B){let q={},H=/(\w+)\s*:\s*([^,\n]+)/g,G=H.exec(B);while(G!==null){let J=G[1],Q=G[2].trim();q[J]=P(Q),G=H.exec(B)}return q}function P(B){let q=B.trim();if(q==="true")return!0;if(q==="false")return!1;if(q==="null")return null;if(q==="undefined")return;if(/^-?\d+(?:\.\d+)?$/.test(q))return Number(q);if(/^['"].*['"]$/.test(q))return q.slice(1,-1);return q}function g(B){let q=B;return q=q.replace(/<template\s+#default[^>]*>([\s\S]*?)<\/template>/gi,"$1"),q=q.replace(/<template\s+#controls[^>]*>[\s\S]*?<\/template>/gi,""),q=q.trim(),q}function S(B){return(B.split("/").pop()||B).replace(/\.story\.stx$/i,"").replace(/([A-Z])/g," $1").trim()}function E(B){return B.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function A(B){let q=B.match(/<script[^>]*>([\s\S]*?)<\/script>/i);return q?q[1]:""}function h(B){return B.replace(/<script[^>]*>[\s\S]*?<\/script>/gi,"").trim()}export{x as parseStoryFile,j as parseStoryContent,h as extractTemplateContent,A as extractScriptContent};
