// @bun
var{defineProperty:V,getOwnPropertyNames:B,getOwnPropertyDescriptor:I}=Object,M=Object.prototype.hasOwnProperty;function R(z){return this[z]}var h=(z)=>{var q=(F??=new WeakMap).get(z),G;if(q)return q;if(q=V({},"__esModule",{value:!0}),z&&typeof z==="object"||typeof z==="function"){for(var H of B(z))if(!M.call(q,H))V(q,H,{get:R.bind(z,H),enumerable:!(G=I(z,H))||G.enumerable})}return F.set(z,q),q},F;var w=(z)=>z;function C(z,q){this[z]=w.bind(null,q)}var x=(z,q)=>{for(var G in q)V(z,G,{get:q[G],enumerable:!0,configurable:!0,set:C.bind(q,G)})};var u=(z,q)=>()=>(z&&(q=z(z=0)),q);var l=import.meta.require;function $(z){let q=z.trim();if(["string","number","boolean","null","undefined","any","unknown","never","void"].includes(q))return{kind:"primitive",value:q};if(q.endsWith("[]"))return{kind:"array",elementType:$(q.slice(0,-2))};if(q.startsWith("Array<")&&q.endsWith(">"))return{kind:"array",elementType:$(q.slice(6,-1))};if(q.includes("|")&&!q.startsWith("{")&&!q.startsWith("("))return{kind:"union",types:D(q,"|").map((J)=>$(J))};if(q.includes("&")&&!q.startsWith("{")&&!q.startsWith("("))return{kind:"intersection",types:D(q,"&").map((J)=>$(J))};if(q.startsWith("'")&&q.endsWith("'")||q.startsWith('"')&&q.endsWith('"'))return{kind:"literal",literalValue:q.slice(1,-1)};if(/^\d+$/.test(q))return{kind:"literal",literalValue:Number.parseInt(q)};if(q==="true"||q==="false")return{kind:"literal",literalValue:q==="true"};if(q.startsWith("{")&&q.endsWith("}"))return P(q);if(q.includes("=>"))return b(q);if(q.includes("<")&&q.endsWith(">")){let H=q.indexOf("<"),J=q.slice(0,H),L=q.slice(H+1,-1),Q=O(L).map((U)=>$(U));return{kind:"generic",value:J,typeArguments:Q}}return{kind:"reference",value:q}}function P(z){let q=z.slice(1,-1).trim(),G={};if(!q)return{kind:"object",properties:G};let H=N(q);for(let J of H){let L=J.trim();if(!L)continue;let Q=L.startsWith("readonly "),U=Q?L.slice(9):L,W=U.indexOf(":");if(W===-1)continue;let Y=U.slice(0,W).trim(),Z=U.slice(W+1).trim(),K=Y.endsWith("?");if(K)Y=Y.slice(0,-1);G[Y]={type:$(Z),optional:K,readonly:Q}}return{kind:"object",properties:G}}function b(z){let q=z.indexOf("=>"),G=z.slice(0,q).trim(),H=z.slice(q+2).trim(),J=[];if(G.startsWith("(")&&G.endsWith(")")){let L=G.slice(1,-1),Q=O(L);for(let U of Q){let W=U.trim();if(!W)continue;let Y=W.startsWith("..."),Z=Y?W.slice(3):W,K=Z.indexOf(":");if(K===-1)J.push({name:Z,type:{kind:"primitive",value:"any"},optional:!1,rest:Y});else{let X=Z.slice(0,K).trim(),E=Z.slice(K+1).trim(),j=X.endsWith("?");if(j)X=X.slice(0,-1);J.push({name:X,type:$(E),optional:j,rest:Y})}}}return{kind:"function",parameters:J,returnType:$(H)}}function D(z,q){let G=[],H="",J=0;for(let L=0;L<z.length;L++){let Q=z[L];if(Q==="<"||Q==="("||Q==="{"||Q==="[")J++,H+=Q;else if(Q===">"||Q===")"||Q==="}"||Q==="]")J--,H+=Q;else if(Q===q&&J===0)G.push(H.trim()),H="";else H+=Q}if(H.trim())G.push(H.trim());return G}function O(z){return D(z,",")}function N(z){let q=[],G="",H=0;for(let J=0;J<z.length;J++){let L=z[J];if(L==="<"||L==="("||L==="{"||L==="[")H++,G+=L;else if(L===">"||L===")"||L==="}"||L==="]")H--,G+=L;else if((L===";"||L===`
`)&&H===0){if(G.trim())q.push(G.trim());G=""}else G+=L}if(G.trim())q.push(G.trim());return q}function g(z){let q=[],G=/interface\s+(\w+)(?:\s+extends\s+([\w,\s]+))?\s*\{/g,H;while((H=G.exec(z))!==null){let J=H[1],L=H[2],Q=H.index+H[0].length-1,U=1,W=Q+1;while(W<z.length&&U>0){if(z[W]==="{")U++;else if(z[W]==="}")U--;W++}let Y=z.slice(Q+1,W-1);q.push({name:J,body:Y,extends:L?L.split(",").map((Z)=>Z.trim()):void 0})}return q}function A(z){let q=[],G=[],H=[],J,L=/@types\s*([\s\S]*?)@endtypes/g,Q=z.matchAll(L);for(let U of Q){let W=U[1],Y=g(W);for(let X of Y){let E=P(`{${X.body}}`),j={name:X.name,properties:E.properties||{},extends:X.extends};if(q.push(j),X.name==="PageContext"||X.name==="TemplateContext"||X.name==="Context")J=j}let Z=/type\s+(\w+)\s*=\s*([^;]+);?/g,K=W.matchAll(Z);for(let X of K){let E=X[1],j=X[2].trim();G.push({name:E,type:$(j)})}}if(!J&&q.length>0)J=q[0];return{interfaces:q,typeAliases:G,contextType:J,errors:H}}function v(z,q){let G={interfaces:new Map,typeAliases:new Map,variables:new Map,errors:[],warnings:[]};for(let H of z.interfaces)G.interfaces.set(H.name,H);for(let H of z.typeAliases)G.typeAliases.set(H.name,H);if(z.contextType)for(let[H,J]of Object.entries(z.contextType.properties))G.variables.set(H,J.type);if(q&&G.variables.size===0)for(let[H,J]of Object.entries(q))G.variables.set(H,k(J));return G}function k(z){if(z===null)return{kind:"primitive",value:"null"};if(z===void 0)return{kind:"primitive",value:"undefined"};let q=typeof z;if(q==="string")return{kind:"primitive",value:"string"};if(q==="number")return{kind:"primitive",value:"number"};if(q==="boolean")return{kind:"primitive",value:"boolean"};if(q==="function")return{kind:"function",parameters:[],returnType:{kind:"primitive",value:"any"}};if(Array.isArray(z)){if(z.length===0)return{kind:"array",elementType:{kind:"primitive",value:"any"}};return{kind:"array",elementType:k(z[0])}}if(q==="object"){let G={};for(let[H,J]of Object.entries(z))G[H]={type:k(J),optional:!1,readonly:!1};return{kind:"object",properties:G}}return{kind:"primitive",value:"any"}}function f(z,q){let G=z.trim();if(/^\w+$/.test(G)){let H=q.variables.get(G);if(!H)return{message:`Unknown variable '${G}'`,expression:G};return H}if(G.includes(".")){let H=G.split("."),J=q.variables.get(H[0]);if(!J)return{message:`Unknown variable '${H[0]}'`,expression:G};for(let L=1;L<H.length;L++){let Q=H[L],U=Q.endsWith("?")?Q.slice(0,-1):Q;if(!J)return{message:`Cannot access property '${U}' on undefined type`,expression:G};if(J.kind==="object"&&J.properties){let W=J.properties[U];if(!W)return{message:`Property '${U}' does not exist on type`,expression:G};J=W.type}else if(J.kind==="reference"){let W=q.interfaces.get(J.value);if(W&&W.properties[U])J=W.properties[U].type;else return{message:`Property '${U}' does not exist on type '${J.value}'`,expression:G}}else if(J.kind==="array"&&U==="length")J={kind:"primitive",value:"number"};else return{message:`Cannot access property '${U}' on type`,expression:G}}return J??{kind:"primitive",value:"any"}}return{kind:"primitive",value:"any"}}function S(z,q){let G=[],H=/\{\{([^}]+)\}\}/g,J=z.matchAll(H);for(let L of J){let Q=L[1].trim();if(Q.includes("|"))continue;let U=f(Q,q);if("message"in U)G.push(U)}return G}function y(z,q){let G=["// Auto-generated by stx - DO NOT EDIT",`// Source: ${z}`,"",'declare module "*.stx" {'];for(let J of q.interfaces){G.push(`  export interface ${J.name} {`);for(let[L,Q]of Object.entries(J.properties)){let U=Q.optional?"?":"",W=Q.readonly?"readonly ":"";G.push(`    ${W}${L}${U}: ${_(Q.type)};`)}G.push("  }"),G.push("")}for(let J of q.typeAliases)G.push(`  export type ${J.name} = ${_(J.type)};`);if(q.contextType)G.push(""),G.push(`  export function render(context: ${q.contextType.name}): Promise<string>;`);else G.push(""),G.push("  export function render(context: Record<string, unknown>): Promise<string>;");G.push("}");let H=z.replace(/\.stx$/,".d.ts");return{content:G.join(`
`),filename:H}}function _(z){switch(z.kind){case"primitive":return z.value||"any";case"array":return`Array<${_(z.elementType)}>`;case"object":{if(!z.properties||Object.keys(z.properties).length===0)return"{}";return`{ ${Object.entries(z.properties).map(([G,H])=>{let J=H.optional?"?":"";return`${H.readonly?"readonly ":""}${G}${J}: ${_(H.type)}`}).join("; ")} }`}case"union":return z.types.map((q)=>_(q)).join(" | ");case"intersection":return z.types.map((q)=>_(q)).join(" & ");case"literal":if(typeof z.literalValue==="string")return`'${z.literalValue}'`;return String(z.literalValue);case"function":return`(${(z.parameters||[]).map((G)=>{let H=G.optional?"?":"";return`${G.rest?"...":""}${G.name}${H}: ${_(G.type)}`}).join(", ")}) => ${_(z.returnType)}`;case"generic":return`${z.value}<${z.typeArguments.map((q)=>_(q)).join(", ")}>`;case"reference":return z.value||"unknown";default:return"unknown"}}function T(z){let q=A(z);return{template:z.replace(/@types\s*[\s\S]*?@endtypes/g,""),types:q}}function c(z,q){let{types:G}=T(z),H=v(G,q);return{errors:S(z,H),warnings:H.warnings}}export{S as validateTemplateTypes,_ as typeToString,f as typeCheckExpression,T as processTypesDirective,$ as parseTypeAnnotation,k as inferTypeFromValue,y as generateTypeDefinitions,A as extractTypesFromTemplate,v as createTypeContext,c as compileTimeTypeCheck};
