@stacksjs/stx 0.2.344 → 0.2.346

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/{chunk-krfx5562.js → chunk-1bws4afs.js} +183 -171
  2. package/dist/{chunk-7kcfbc0j.js → chunk-1caep9rn.js} +1 -1
  3. package/dist/{chunk-e4yskgtb.js → chunk-1djdz98r.js} +1 -1
  4. package/dist/{chunk-mvat8js5.js → chunk-1vyz6kr8.js} +2 -2
  5. package/dist/{chunk-efx05ah0.js → chunk-1xayahc6.js} +1 -1
  6. package/dist/{chunk-hsbbfp0c.js → chunk-1xts7768.js} +1 -1
  7. package/dist/{chunk-7t6h8crt.js → chunk-21mmq3aj.js} +1 -1
  8. package/dist/{chunk-7d2gfyk8.js → chunk-3pggfwbf.js} +1 -1
  9. package/dist/{chunk-tscr6bs8.js → chunk-5hhng72w.js} +1 -1
  10. package/dist/{chunk-bpb3xkg4.js → chunk-7hjjckat.js} +1 -1
  11. package/dist/{chunk-jzfk5ect.js → chunk-7w66sc17.js} +1 -1
  12. package/dist/{chunk-mz4breg8.js → chunk-864m3xp2.js} +1 -1
  13. package/dist/{chunk-3n8avn17.js → chunk-8tghv8cf.js} +1 -1
  14. package/dist/{chunk-tthrw91n.js → chunk-akb6mgrb.js} +1 -1
  15. package/dist/{chunk-94sxzp5x.js → chunk-b08taxsf.js} +1 -1
  16. package/dist/{chunk-1bct7pfj.js → chunk-bxwanj4g.js} +1 -1
  17. package/dist/{chunk-dx2s51rr.js → chunk-byn0ptqt.js} +1 -1
  18. package/dist/{chunk-nexpxxsa.js → chunk-ddsgfmhv.js} +1 -1
  19. package/dist/{chunk-a1ghxrb1.js → chunk-dyy74sdv.js} +1 -1
  20. package/dist/{chunk-39qy76ek.js → chunk-es275g3w.js} +1 -1
  21. package/dist/{chunk-8tjg4wbr.js → chunk-fvvdq3ev.js} +1 -1
  22. package/dist/{chunk-csv48xrx.js → chunk-fynb9e02.js} +1 -1
  23. package/dist/{chunk-zkwk82ss.js → chunk-hfvknn03.js} +1 -1
  24. package/dist/{chunk-cmccdayf.js → chunk-j8s9akdq.js} +1 -1
  25. package/dist/{chunk-cdq28mek.js → chunk-jwe0cwff.js} +1 -1
  26. package/dist/{chunk-020hpw7m.js → chunk-k5hv1qqy.js} +1 -1
  27. package/dist/{chunk-72x5v5an.js → chunk-k80kr2t2.js} +1 -1
  28. package/dist/{chunk-cappe4hd.js → chunk-km92eab7.js} +1 -1
  29. package/dist/{chunk-a29x23g7.js → chunk-maq5jag2.js} +1 -1
  30. package/dist/{chunk-5yhv1pe5.js → chunk-p04rck27.js} +1 -1
  31. package/dist/{chunk-gmm82dst.js → chunk-pc8np1bb.js} +1 -1
  32. package/dist/{chunk-6z9pm31g.js → chunk-q45fva8h.js} +1 -1
  33. package/dist/{chunk-9yqt0nf2.js → chunk-qp7sk0ex.js} +1 -1
  34. package/dist/{chunk-ewpbxy5m.js → chunk-rf2cejt3.js} +1 -1
  35. package/dist/{chunk-mpyjnwje.js → chunk-rwk5hwvk.js} +1 -1
  36. package/dist/{chunk-5apmxb4e.js → chunk-s11e8aq9.js} +1 -1
  37. package/dist/{chunk-wfwj4390.js → chunk-s3jyec9k.js} +1 -1
  38. package/dist/{chunk-fs2t4rs3.js → chunk-skd72bn4.js} +2 -2
  39. package/dist/{chunk-3xpk99z4.js → chunk-t2py7vc3.js} +1 -1
  40. package/dist/{chunk-j5qygdy9.js → chunk-t83m2pkm.js} +1 -1
  41. package/dist/{chunk-4kbaky4w.js → chunk-tnm0nez5.js} +1 -1
  42. package/dist/{chunk-g28fs4aa.js → chunk-vw83y4we.js} +2 -2
  43. package/dist/{chunk-zwhnkxgy.js → chunk-vzbcdxd5.js} +1 -1
  44. package/dist/{chunk-q5gzpn1n.js → chunk-washyj03.js} +1 -1
  45. package/dist/{chunk-1exk54qt.js → chunk-wbp4vbm0.js} +1 -1
  46. package/dist/{chunk-xh9paa2g.js → chunk-xytgvfbf.js} +2 -2
  47. package/dist/{chunk-5atmahe4.js → chunk-zdq7emrd.js} +322 -322
  48. package/dist/{chunk-9p5gbhwp.js → chunk-zz2yxsf9.js} +1 -1
  49. package/dist/cli.js +7 -7
  50. package/dist/component-library.d.ts +0 -31
  51. package/dist/component-library.js +279 -17
  52. package/dist/craft-entry.js +1 -1
  53. package/dist/craft.js +1 -1
  54. package/dist/process.js +25 -3
  55. package/dist/pwa.js +1 -1
  56. package/dist/ssg.js +2 -2
  57. package/dist/theme-tokens.js +15 -5
  58. package/dist/variable-extractor.d.ts +31 -0
  59. package/dist/variable-extractor.js +9 -5
  60. package/package.json +5 -5
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Hi as a,Ii as b}from"./chunk-dx2s51rr.js";import"./chunk-7we3xfde.js";import"./chunk-4kbaky4w.js";import"./chunk-zkwk82ss.js";import"./chunk-fvsefztj.js";import"./chunk-5atmahe4.js";import"./chunk-8y1ve8tc.js";import"./chunk-njx93b4z.js";import"./chunk-bqdfbwdf.js";import"./chunk-89mqnh67.js";import"./chunk-xvh1k1a4.js";import"./chunk-fs2t4rs3.js";import"./chunk-y2f41kaq.js";import"./chunk-xj6bcwqa.js";import"./chunk-7t6h8crt.js";import"./chunk-vhta1be7.js";import"./chunk-tc4pj651.js";import"./chunk-san1eq0r.js";import"./chunk-avwywzsj.js";import"./chunk-wj21f1e0.js";import"./chunk-d86q27j8.js";import"./chunk-72x62kch.js";import"./chunk-yg5r7bnm.js";import"./chunk-9nrgjtah.js";import"./chunk-ejqpq0wc.js";export{a as getStoreScript,b as clearStoreCache};
2
+ import{Hi as a,Ii as b}from"./chunk-byn0ptqt.js";import"./chunk-7we3xfde.js";import"./chunk-tnm0nez5.js";import"./chunk-hfvknn03.js";import"./chunk-fvsefztj.js";import"./chunk-zdq7emrd.js";import"./chunk-8y1ve8tc.js";import"./chunk-njx93b4z.js";import"./chunk-bqdfbwdf.js";import"./chunk-89mqnh67.js";import"./chunk-xvh1k1a4.js";import"./chunk-skd72bn4.js";import"./chunk-y2f41kaq.js";import"./chunk-xj6bcwqa.js";import"./chunk-21mmq3aj.js";import"./chunk-vhta1be7.js";import"./chunk-tc4pj651.js";import"./chunk-san1eq0r.js";import"./chunk-avwywzsj.js";import"./chunk-wj21f1e0.js";import"./chunk-d86q27j8.js";import"./chunk-72x62kch.js";import"./chunk-yg5r7bnm.js";import"./chunk-9nrgjtah.js";import"./chunk-ejqpq0wc.js";export{a as getStoreScript,b as clearStoreCache};
package/dist/cli.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{Ha as a,He as F,Je as v,Ke as P,Va as r,de as s,ee as t,nb as n,o as m,oa as l,ob as p,qb as i,wb as e}from"./chunk-krfx5562.js";import"./chunk-cdq28mek.js";import"./chunk-2ver2s2y.js";import"./chunk-a1ghxrb1.js";import"./chunk-mpyjnwje.js";import"./chunk-wfwj4390.js";import"./chunk-ym3r8ktq.js";import"./chunk-msywnv5n.js";import"./chunk-b5hank5e.js";import"./chunk-7qp3zphs.js";import"./chunk-nexpxxsa.js";import"./chunk-xh9paa2g.js";import"./chunk-57atgbyq.js";import"./chunk-8bxtvsgm.js";import"./chunk-5yhv1pe5.js";import"./chunk-rwwfzkz4.js";import"./chunk-7h9fajgs.js";import"./chunk-18018jkn.js";import"./chunk-sqvqwd0p.js";import"./chunk-7r9vgzg4.js";import"./chunk-a959m68j.js";import"./chunk-1vb2rj09.js";import"./chunk-g6czgcg4.js";import"./chunk-zwhnkxgy.js";import"./chunk-1z1efvtw.js";import"./chunk-vgfd9582.js";import"./chunk-qsbjtp60.js";import"./chunk-nf7k53ap.js";import"./chunk-zk6ghjnj.js";import"./chunk-bgrkxzr7.js";import"./chunk-dx2s51rr.js";import"./chunk-7we3xfde.js";import"./chunk-bpb3xkg4.js";import"./chunk-9jbssgem.js";import"./chunk-e4g8wz6t.js";import"./chunk-3xpk99z4.js";import"./chunk-g28fs4aa.js";import"./chunk-v7aa7v85.js";import"./chunk-c0n802j1.js";import{al as u,bl as c}from"./chunk-4kbaky4w.js";import"./chunk-zkwk82ss.js";import"./chunk-fvsefztj.js";import"./chunk-5atmahe4.js";import{as as f}from"./chunk-8y1ve8tc.js";import"./chunk-njx93b4z.js";import"./chunk-bqdfbwdf.js";import"./chunk-89mqnh67.js";import"./chunk-xvh1k1a4.js";import{Es as A}from"./chunk-fs2t4rs3.js";import"./chunk-y2f41kaq.js";import"./chunk-xj6bcwqa.js";import"./chunk-7t6h8crt.js";import"./chunk-vhta1be7.js";import"./chunk-tc4pj651.js";import"./chunk-san1eq0r.js";import"./chunk-avwywzsj.js";import"./chunk-wj21f1e0.js";import"./chunk-d86q27j8.js";import"./chunk-72x62kch.js";import"./chunk-yg5r7bnm.js";import"./chunk-9nrgjtah.js";import{Nw as B}from"./chunk-ejqpq0wc.js";import{spawn as o}from"child_process";import L from"fs";import zb from"os";import $ from"path";import w from"process";import{CLI as wb}from"@stacksjs/clapp";var N="0.2.344";var __dirname="/home/runner/work/stx/stx/packages/stx/bin",E=new wb("stx");function h(J){let Z=typeof J==="string"?Number.parseInt(J,10):J;if(Number.isNaN(Z))return{isValid:!1,error:"Port must be a valid number",suggestion:"Try using a number between 1024 and 65535"};if(Z<1024||Z>65535)return{isValid:!1,error:"Port must be between 1024 and 65535",suggestion:"Try using a port between 1024 and 65535"};return{isValid:!0}}function d(J){try{if(!L.existsSync(J)){let K=$.dirname(J),x=$.basename(J);if(L.existsSync(K)){let z=L.readdirSync(K).filter((j)=>j.toLowerCase().includes(x.toLowerCase().substring(0,3))||j.endsWith(".stx")||j.endsWith(".md")),k=z.length>0?`File not found. Similar files in ${K}: ${z.slice(0,3).join(", ")}`:`File not found. Directory ${K} exists but doesn't contain the specified file.`;return{isValid:!1,error:`File does not exist: ${J}`,suggestion:k}}return{isValid:!1,error:`File does not exist: ${J}`,suggestion:"Check the file path and try again"}}if(L.statSync(J).isDirectory())return{isValid:!1,error:`Expected file but got directory: ${J}`,suggestion:"Specify a .stx or .md file path"};return{isValid:!0}}catch(Z){return{isValid:!1,error:`Cannot access file: ${J}`,suggestion:"Check file permissions and path"}}}function y(J){let Z=typeof J==="string"?Number.parseInt(J,10):J;if(Number.isNaN(Z))return{isValid:!1,error:"Timeout must be a valid number",suggestion:"Specify timeout in milliseconds (e.g., 5000 for 5 seconds)"};if(Z<100)return{isValid:!1,error:"Timeout too short (minimum 100ms)",suggestion:"Use a timeout of at least 100ms"};if(Z>300000)return{isValid:!1,error:"Timeout too long (maximum 5 minutes)",suggestion:"Use a timeout of less than 300000ms (5 minutes)"};return{isValid:!0}}var V=(J)=>J.includes("*")||J.includes("?")||J.includes("{")||J.includes("["),jb=(J)=>J.endsWith(".stx")||J.endsWith(".md");function S(J,Z=1){if(console.error(`\u274C ${J.error}`),J.suggestion)console.error(`\uD83D\uDCA1 suggestion: ${J.suggestion}`);w.exit(Z)}function kb(J){if(!J)return;let Z;try{Z=JSON.parse(J)}catch(K){console.error(`\u274C --info-plist is not valid JSON: ${K.message}`),w.exit(1)}if(typeof Z!=="object"||Z===null||Array.isArray(Z))console.error(`\u274C --info-plist must be a JSON object, e.g. '{"NSFocusStatusUsageDescription":"\u2026"}'`),w.exit(1);for(let[K,x]of Object.entries(Z))if(typeof x!=="string"&&typeof x!=="number"&&typeof x!=="boolean")console.error(`\u274C --info-plist value for "${K}" must be a string, number or boolean`),w.exit(1);return Z}async function Hb(J,Z){try{let K=["test"],x=[];if(J&&J.length>0)for(let W of J)if(V(W))try{let H=await Array.fromAsync(new Bun.Glob(W).scan({onlyFiles:!0,absolute:!0}));if(H.length===0)console.warn(`Warning: No files found matching pattern: ${W}`);else if(x.push(...H),Z.verbose)console.log(`Found ${H.length} file(s) matching pattern: ${W}`)}catch(H){return console.error(`Error expanding glob pattern ${W}:`,H),!1}else x.push(W);if(x.length===0)return console.error("Error: No test files found matching the provided patterns."),!1;if(K.push(...x),Z.filter)K.push("--pattern",Z.filter);if(Z.timeout)K.push("--timeout",Z.timeout.toString());if(Z.reporter&&Z.reporter!=="default")if(Z.reporter==="junit"){let W=$.join(zb.tmpdir(),`stx-test-report-${Date.now()}.xml`);K.push("--reporter",Z.reporter),K.push("--reporter-outfile",W)}else console.warn(`Warning: Reporter '${Z.reporter}' is not supported. Using default reporter.`);if(Z.coverage)K.push("--coverage");if(Z.watch)K.push("--watch");K.push("--preload",$.join(__dirname,"../../../test-utils/happy-dom.ts"));let b={...w.env,STX_TEST_MODE:"true",STX_TEST_UI:Z.ui?"true":"false",STX_TEST_VERBOSE:Z.verbose?"true":"false"},z="bun";if(Z.verbose)console.log(`Running: ${z} ${K.join(" ")}`);let k=performance.now(),j=o(z,K,{stdio:"inherit",shell:!1,env:b});return new Promise((W)=>{j.on("close",(H)=>{let Y=((performance.now()-k)/1000).toFixed(2);if(H===0)W(!0);else W(!1)}),w.on("SIGINT",()=>{console.log(`
3
+ import{Ha as a,He as F,Je as v,Ke as P,Va as r,de as s,ee as t,nb as n,o as m,oa as l,ob as p,qb as i,wb as e}from"./chunk-1bws4afs.js";import"./chunk-jwe0cwff.js";import"./chunk-2ver2s2y.js";import"./chunk-dyy74sdv.js";import"./chunk-rwk5hwvk.js";import"./chunk-s3jyec9k.js";import"./chunk-ym3r8ktq.js";import"./chunk-msywnv5n.js";import"./chunk-b5hank5e.js";import"./chunk-7qp3zphs.js";import"./chunk-ddsgfmhv.js";import"./chunk-xytgvfbf.js";import"./chunk-57atgbyq.js";import"./chunk-8bxtvsgm.js";import"./chunk-p04rck27.js";import"./chunk-rwwfzkz4.js";import"./chunk-7h9fajgs.js";import"./chunk-18018jkn.js";import"./chunk-sqvqwd0p.js";import"./chunk-7r9vgzg4.js";import"./chunk-a959m68j.js";import"./chunk-1vb2rj09.js";import"./chunk-g6czgcg4.js";import"./chunk-vzbcdxd5.js";import"./chunk-1z1efvtw.js";import"./chunk-vgfd9582.js";import"./chunk-qsbjtp60.js";import"./chunk-nf7k53ap.js";import"./chunk-zk6ghjnj.js";import"./chunk-bgrkxzr7.js";import"./chunk-byn0ptqt.js";import"./chunk-7we3xfde.js";import"./chunk-7hjjckat.js";import"./chunk-9jbssgem.js";import"./chunk-e4g8wz6t.js";import"./chunk-t2py7vc3.js";import"./chunk-vw83y4we.js";import"./chunk-v7aa7v85.js";import"./chunk-c0n802j1.js";import{al as u,bl as c}from"./chunk-tnm0nez5.js";import"./chunk-hfvknn03.js";import"./chunk-fvsefztj.js";import"./chunk-zdq7emrd.js";import{as as f}from"./chunk-8y1ve8tc.js";import"./chunk-njx93b4z.js";import"./chunk-bqdfbwdf.js";import"./chunk-89mqnh67.js";import"./chunk-xvh1k1a4.js";import{Es as A}from"./chunk-skd72bn4.js";import"./chunk-y2f41kaq.js";import"./chunk-xj6bcwqa.js";import"./chunk-21mmq3aj.js";import"./chunk-vhta1be7.js";import"./chunk-tc4pj651.js";import"./chunk-san1eq0r.js";import"./chunk-avwywzsj.js";import"./chunk-wj21f1e0.js";import"./chunk-d86q27j8.js";import"./chunk-72x62kch.js";import"./chunk-yg5r7bnm.js";import"./chunk-9nrgjtah.js";import{Nw as B}from"./chunk-ejqpq0wc.js";import{spawn as o}from"child_process";import L from"fs";import zb from"os";import $ from"path";import w from"process";import{CLI as wb}from"@stacksjs/clapp";var N="0.2.346";var __dirname="/home/runner/work/stx/stx/packages/stx/bin",E=new wb("stx");function h(J){let Z=typeof J==="string"?Number.parseInt(J,10):J;if(Number.isNaN(Z))return{isValid:!1,error:"Port must be a valid number",suggestion:"Try using a number between 1024 and 65535"};if(Z<1024||Z>65535)return{isValid:!1,error:"Port must be between 1024 and 65535",suggestion:"Try using a port between 1024 and 65535"};return{isValid:!0}}function d(J){try{if(!L.existsSync(J)){let K=$.dirname(J),x=$.basename(J);if(L.existsSync(K)){let z=L.readdirSync(K).filter((j)=>j.toLowerCase().includes(x.toLowerCase().substring(0,3))||j.endsWith(".stx")||j.endsWith(".md")),k=z.length>0?`File not found. Similar files in ${K}: ${z.slice(0,3).join(", ")}`:`File not found. Directory ${K} exists but doesn't contain the specified file.`;return{isValid:!1,error:`File does not exist: ${J}`,suggestion:k}}return{isValid:!1,error:`File does not exist: ${J}`,suggestion:"Check the file path and try again"}}if(L.statSync(J).isDirectory())return{isValid:!1,error:`Expected file but got directory: ${J}`,suggestion:"Specify a .stx or .md file path"};return{isValid:!0}}catch(Z){return{isValid:!1,error:`Cannot access file: ${J}`,suggestion:"Check file permissions and path"}}}function y(J){let Z=typeof J==="string"?Number.parseInt(J,10):J;if(Number.isNaN(Z))return{isValid:!1,error:"Timeout must be a valid number",suggestion:"Specify timeout in milliseconds (e.g., 5000 for 5 seconds)"};if(Z<100)return{isValid:!1,error:"Timeout too short (minimum 100ms)",suggestion:"Use a timeout of at least 100ms"};if(Z>300000)return{isValid:!1,error:"Timeout too long (maximum 5 minutes)",suggestion:"Use a timeout of less than 300000ms (5 minutes)"};return{isValid:!0}}var V=(J)=>J.includes("*")||J.includes("?")||J.includes("{")||J.includes("["),jb=(J)=>J.endsWith(".stx")||J.endsWith(".md");function S(J,Z=1){if(console.error(`\u274C ${J.error}`),J.suggestion)console.error(`\uD83D\uDCA1 suggestion: ${J.suggestion}`);w.exit(Z)}function kb(J){if(!J)return;let Z;try{Z=JSON.parse(J)}catch(K){console.error(`\u274C --info-plist is not valid JSON: ${K.message}`),w.exit(1)}if(typeof Z!=="object"||Z===null||Array.isArray(Z))console.error(`\u274C --info-plist must be a JSON object, e.g. '{"NSFocusStatusUsageDescription":"\u2026"}'`),w.exit(1);for(let[K,x]of Object.entries(Z))if(typeof x!=="string"&&typeof x!=="number"&&typeof x!=="boolean")console.error(`\u274C --info-plist value for "${K}" must be a string, number or boolean`),w.exit(1);return Z}async function Hb(J,Z){try{let K=["test"],x=[];if(J&&J.length>0)for(let W of J)if(V(W))try{let H=await Array.fromAsync(new Bun.Glob(W).scan({onlyFiles:!0,absolute:!0}));if(H.length===0)console.warn(`Warning: No files found matching pattern: ${W}`);else if(x.push(...H),Z.verbose)console.log(`Found ${H.length} file(s) matching pattern: ${W}`)}catch(H){return console.error(`Error expanding glob pattern ${W}:`,H),!1}else x.push(W);if(x.length===0)return console.error("Error: No test files found matching the provided patterns."),!1;if(K.push(...x),Z.filter)K.push("--pattern",Z.filter);if(Z.timeout)K.push("--timeout",Z.timeout.toString());if(Z.reporter&&Z.reporter!=="default")if(Z.reporter==="junit"){let W=$.join(zb.tmpdir(),`stx-test-report-${Date.now()}.xml`);K.push("--reporter",Z.reporter),K.push("--reporter-outfile",W)}else console.warn(`Warning: Reporter '${Z.reporter}' is not supported. Using default reporter.`);if(Z.coverage)K.push("--coverage");if(Z.watch)K.push("--watch");K.push("--preload",$.join(__dirname,"../../../test-utils/happy-dom.ts"));let b={...w.env,STX_TEST_MODE:"true",STX_TEST_UI:Z.ui?"true":"false",STX_TEST_VERBOSE:Z.verbose?"true":"false"},z="bun";if(Z.verbose)console.log(`Running: ${z} ${K.join(" ")}`);let k=performance.now(),j=o(z,K,{stdio:"inherit",shell:!1,env:b});return new Promise((W)=>{j.on("close",(H)=>{let Y=((performance.now()-k)/1000).toFixed(2);if(H===0)W(!0);else W(!1)}),w.on("SIGINT",()=>{console.log(`
4
4
  Test run interrupted`),j.kill("SIGINT"),w.exit(1)})})}catch(K){return console.error("Error running tests:",K instanceof Error?K.message:String(K)),!1}}var Qb=w.argv.length>=3&&(jb(w.argv[2])&&L.existsSync(w.argv[2])||V(w.argv[2]));if(Qb){let J=w.argv[2],Z={port:3000,watch:!0,cache:!0,markdown:{syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}}};for(let K=3;K<w.argv.length;K++){let x=w.argv[K];if(x==="--port"&&K+1<w.argv.length){let b=h(w.argv[++K]);if(!b.isValid)S(b);Z.port=Number.parseInt(w.argv[K],10)}else if(x==="--no-watch")Z.watch=!1;else if(x==="--highlight-theme"&&K+1<w.argv.length){if(!Z.markdown)Z.markdown={};if(!Z.markdown.syntaxHighlighting)Z.markdown.syntaxHighlighting={};Z.markdown.syntaxHighlighting.defaultTheme=w.argv[++K]}else if(x==="--no-highlight"){if(!Z.markdown)Z.markdown={};if(!Z.markdown.syntaxHighlighting)Z.markdown.syntaxHighlighting={};Z.markdown.syntaxHighlighting.enabled=!1}else if(x==="--no-highlight-unknown"){if(!Z.markdown)Z.markdown={};if(!Z.markdown.syntaxHighlighting)Z.markdown.syntaxHighlighting={};Z.markdown.syntaxHighlighting.highlightUnknownLanguages=!1}else if(x==="--no-cache")Z.cache=!1;else if(x==="--native")Z.native=!0}if(V(J))try{let K=await Array.fromAsync(new Bun.Glob(J).scan({onlyFiles:!0,absolute:!0})),x=J.endsWith(".stx")?K.filter((j)=>j.endsWith(".stx")):J.endsWith(".md")?K.filter((j)=>j.endsWith(".md")):K.filter((j)=>j.endsWith(".stx")||j.endsWith(".md")),b=J.split("*")[0].replace(/\/$/,"")||".",z=$.resolve(b);try{let j=new Bun.Glob("**/*.stx"),H=(await Array.fromAsync(j.scan({cwd:z,onlyFiles:!0,absolute:!0}))).filter((U)=>/\[.+\]/.test($.basename(U)));for(let U of H)if(!x.includes(U))x.push(U)}catch{}if(x.length===0)console.error(`Error: No STX or Markdown files found matching pattern: ${J}`),w.exit(1);if(!await v(x,Z))w.exit(1)}catch(K){console.error("Failed to process files:",K),w.exit(1)}else F(J,Z).catch((K)=>{console.error("Failed to start dev server:",K),w.exit(1)})}else{let J=function(x,b){let z=[];for(let k=0;k<=b.length;k++)z[k]=[k];for(let k=0;k<=x.length;k++)z[0][k]=k;for(let k=1;k<=b.length;k++)for(let j=1;j<=x.length;j++)if(b.charAt(k-1)===x.charAt(j-1))z[k][j]=z[k-1][j-1];else z[k][j]=Math.min(z[k-1][j-1]+1,z[k][j-1]+1,z[k-1][j]+1);return z[b.length][x.length]};E.command("docs","Generate documentation for components, templates, and directives").option("--output <dir>","Output directory for documentation",{default:"docs"}).option("--format <format>","Documentation format (markdown, html, json)",{default:"markdown"}).option("--components-dir <dir>","Components directory",{default:"components"}).option("--templates-dir <dir>","Templates directory",{default:"."}).option("--no-components","Disable components documentation").option("--no-templates","Disable templates documentation").option("--no-directives","Disable directives documentation").option("--extra-content <content>","Extra content to include in documentation").example("stx docs --output docs --format html").action(async(x)=>{try{if(await r(x))console.log("Documentation generated successfully."),w.exit(0);else console.error("Documentation generation failed."),w.exit(1)}catch(b){console.error("Error generating documentation:",b),w.exit(1)}}),E.command("iconify <command>","Generate Iconify icon packages").option("--output <dir>","Output directory for generated packages",{default:"packages"}).option("--icons <icons>","Comma-separated list of specific icons to generate").example("stx iconify list").example("stx iconify generate mdi").example("stx iconify generate lucide --icons home,settings,user").action(async(x,b)=>{try{let{fetchCollections:z,generatePackage:k}=await import("./chunk-05zfez2g.js");if(x==="list"){console.log(`
5
5
  \uD83D\uDCDA Fetching available icon collections...
6
6
  `);let j=await z(),W=Object.entries(j).sort((H,U)=>U[1].total-H[1].total);console.log(`Available collections:
7
7
  `);for(let[H,U]of W){let Y=U;console.log(` ${H.padEnd(30)} ${Y.name} (${Y.total} icons)`)}console.log(`
8
8
  Total: ${W.length} collections`)}else if(x.startsWith("generate")){let j=x==="generate"?"":x.replace("generate:","").replace("generate-","").replace("generate","").trim();if(!j)console.error("Error: Please specify a collection prefix"),console.error("Usage: stx iconify generate <prefix> [--icons icon1,icon2,...]"),w.exit(1);let W=b.output||$.join(w.cwd(),"packages/collections"),H=b.icons?b.icons.split(",").map((U)=>U.trim()):void 0;await k(j,W,H),console.log(`
9
9
  \u2713 Package generated successfully!`),console.log(`
10
- To use the package:`),console.log(` 1. cd packages/collections/iconify-${j}`),console.log(" 2. bun install"),console.log(" 3. bun run build")}else console.error(`Unknown iconify command: ${x}`),console.error("Available commands: list, generate"),w.exit(1)}catch(z){console.error("Error:",z instanceof Error?z.message:String(z)),w.exit(1)}}),E.command("pwa <command>","PWA tools - audit configuration and build output").option("--output <dir>","Build output directory to audit",{default:"dist"}).example("stx pwa audit").example("stx pwa audit --output build").action(async(x,b)=>{try{if(x==="audit"){let{runPwaAudit:z,formatAuditResult:k}=await import("./chunk-dxkjvajv.js"),{loadConfig:j}=await import("./chunk-7d2gfyk8.js");console.log(`
10
+ To use the package:`),console.log(` 1. cd packages/collections/iconify-${j}`),console.log(" 2. bun install"),console.log(" 3. bun run build")}else console.error(`Unknown iconify command: ${x}`),console.error("Available commands: list, generate"),w.exit(1)}catch(z){console.error("Error:",z instanceof Error?z.message:String(z)),w.exit(1)}}),E.command("pwa <command>","PWA tools - audit configuration and build output").option("--output <dir>","Build output directory to audit",{default:"dist"}).example("stx pwa audit").example("stx pwa audit --output build").action(async(x,b)=>{try{if(x==="audit"){let{runPwaAudit:z,formatAuditResult:k}=await import("./chunk-dxkjvajv.js"),{loadConfig:j}=await import("./chunk-3pggfwbf.js");console.log(`
11
11
  \uD83D\uDD0D Running PWA audit...
12
12
  `);let W=await j(),H=b.output||"dist",U=z(W,H);if(console.log(k(U)),U.failed>0)w.exit(1)}else console.error(`Unknown pwa command: ${x}`),console.error("Available commands: audit"),w.exit(1)}catch(z){console.error("Error:",z instanceof Error?z.message:String(z)),w.exit(1)}}),E.command("dev [file]","Start a development server for an STX app or file").option("--port <port>","Port to use for the dev server",{default:3000}).option("--pages <dir>",'Directory containing page templates (default: pagesDir from stx.config.ts, else "pages")').option("--no-watch","Disable file watching and auto-reload").option("--native","Open in a native desktop window using Zyte").option("--titlebar-hidden","Hide the native titlebar but keep the traffic-light buttons (web content draws under a transparent full-size titlebar). Implies --native.").option("--highlight-theme <theme>","Syntax highlighting theme for Markdown code blocks",{default:"github-dark"}).option("--no-highlight","Disable syntax highlighting for Markdown code blocks").option("--no-highlight-unknown","Disable syntax highlighting for unknown languages in Markdown").option("--no-cache","Disable caching of parsed files").option("--no-hmr","Disable HMR / live-reload script injection (useful for clean network traces)").option("--profile","Print per-directive timing for every page render via performanceMonitor").option("--debug-directives","Log directive ordering and intermediate template state during rendering").example("stx dev").example("stx dev --port 8080").example("stx dev --pages src/pages").example("stx dev template.stx").example("stx dev components/hero.stx --port 8080").example("stx dev **/*.stx").example("stx dev docs/guide.md").example("stx dev template.stx --native").action(async(x,b)=>{try{if(b.port!==void 0){let k=h(b.port);if(!k.isValid)S(k);b.port=Number.parseInt(String(b.port),10)}if(b.timeout!==void 0){let k=y(b.timeout);if(!k.isValid)S(k)}let z={syntaxHighlighting:{enabled:b.highlight!==!1,serverSide:!0,defaultTheme:b.highlightTheme||"github-dark",highlightUnknownLanguages:b.highlightUnknown!==!1}};if(!x){if(!await P(".",{port:b.port,watch:b.watch!==!1,native:b.native||b.titlebarHidden||!1,titlebarHidden:b.titlebarHidden===!0,cache:b.cache!==!1,hotReload:b.hmr!==!1,profile:b.profile===!0,debugDirectives:b.debugDirectives===!0,...b.pages&&{pagesDir:b.pages}}))w.exit(1);return}if(!V(x))try{let k=await import("fs");if(k.existsSync(x)&&k.statSync(x).isDirectory()){if(!await P(x,{port:b.port,watch:b.watch!==!1,native:b.native||b.titlebarHidden||!1,titlebarHidden:b.titlebarHidden===!0,cache:b.cache!==!1,hotReload:b.hmr!==!1,profile:b.profile===!0,debugDirectives:b.debugDirectives===!0,...b.pages&&{pagesDir:b.pages}}))w.exit(1);return}}catch{}if(V(x)){console.log(`Expanding glob pattern: ${x}`);let k=await A.timeAsync("glob-expansion",async()=>{return Array.fromAsync(new Bun.Glob(x).scan({onlyFiles:!0,absolute:!0}))}),j=x.endsWith(".stx")?k.filter((Y)=>Y.endsWith(".stx")):x.endsWith(".md")?k.filter((Y)=>Y.endsWith(".md")):k.filter((Y)=>Y.endsWith(".stx")||Y.endsWith(".md"));if(j.length===0)console.error(`No STX or Markdown files found matching pattern: ${x}`),console.error("Try using patterns like '*.stx' or 'components/**/*.stx'"),w.exit(1);let W=x.split("*")[0].replace(/\/$/,"")||".",H=$.resolve(W);try{let Y=new Bun.Glob("**/*.stx"),X=(await Array.fromAsync(Y.scan({cwd:H,onlyFiles:!0,absolute:!0}))).filter((_)=>/\[.+\]/.test($.basename(_)));for(let _ of X)if(!j.includes(_))j.push(_)}catch{}if(console.log(`Found ${j.length} ${j.length===1?"file":"files"} matching ${x}`),!await v(j,{port:b.port,watch:b.watch!==!1,native:b.native||b.titlebarHidden||!1,titlebarHidden:b.titlebarHidden===!0,markdown:z,cache:b.cache!==!1}))w.exit(1)}else{if(!V(x)){let j=d(x);if(!j.isValid)S(j)}if(!await F(x,{port:b.port,watch:b.watch!==!1,native:b.native||b.titlebarHidden||!1,titlebarHidden:b.titlebarHidden===!0,markdown:z,cache:b.cache!==!1}))w.exit(1)}}catch(z){console.error("Error starting dev server:",z),w.exit(1)}}),E.command("a11y [target]","Scan .stx files for accessibility issues (directory, file, or glob)").option("--no-recursive","Disable recursive scanning of directories").option("--ignore <paths>","Comma-separated paths to ignore",{default:""}).option("--json","Output results as JSON").option("--output <file>","Write results to a file instead of stdout").option("--fix","Automatically fix common accessibility issues").example("stx a11y ./templates").example('stx a11y "resources/**/*.stx"').example("stx a11y resources/emails/welcome.stx").example("stx a11y --json --output a11y-report.json").action(async(x=".",b)=>{try{console.log(`Scanning ${x} for accessibility issues...`);let z=b.ignore?b.ignore.split(",").map((U)=>U.trim()):[],{results:k,scannedFiles:j}=await f(x,{recursive:b.recursive!==!1,ignorePaths:z});if(j.length===0)console.log(`
13
13
  No .stx files matched ${x}
@@ -69,7 +69,7 @@ Total: ${H} issues in ${W} files`),b.output){let U=`
69
69
  File not found: ${x}`),w.exit(1);if(!x.endsWith(".stx"))console.error(`
70
70
  File must have .stx extension: ${x}`),w.exit(1)}let k=$.resolve(b.pages),j=$.resolve(b.out);if(!x&&!L.existsSync(k))console.error(`
71
71
  Pages directory not found: ${k}`),console.log(`
72
- Create a 'pages' directory with .stx files, or use --pages to specify a different directory.`),w.exit(1);let{buildApp:W}=await import("./chunk-gmm82dst.js");c();let H=await W({root:x?$.dirname(x):void 0,debug:b.verbose,ssg:{pagesDir:b.pages,outputDir:b.out,domain:b.domain,baseUrl:b.base,sitemap:b.sitemap,rss:b.rss,minify:b.minify,cache:b.cache!==!1,cleanOutput:b.clean,concurrency:Number.parseInt(b.concurrency,10)||10,publicDir:b.public,trailingSlash:b.trailingSlash,generate404:!0,hooks:b.verbose?{onPageStart:(Y)=>console.log(` Generating: ${Y}`),onPageEnd:(Y,Q)=>console.log(` Generated: ${Y} (${Q.length} bytes)`),onError:(Y,Q)=>console.error(` Error in ${Q}: ${Y.message}`)}:void 0},ssr:{outputDir:b.out==="dist"?".output":b.out,debug:b.verbose}}),U=((performance.now()-z)/1000).toFixed(2);if(H.mode==="ssr"&&H.ssr)console.log(`
72
+ Create a 'pages' directory with .stx files, or use --pages to specify a different directory.`),w.exit(1);let{buildApp:W}=await import("./chunk-pc8np1bb.js");c();let H=await W({root:x?$.dirname(x):void 0,debug:b.verbose,ssg:{pagesDir:b.pages,outputDir:b.out,domain:b.domain,baseUrl:b.base,sitemap:b.sitemap,rss:b.rss,minify:b.minify,cache:b.cache!==!1,cleanOutput:b.clean,concurrency:Number.parseInt(b.concurrency,10)||10,publicDir:b.public,trailingSlash:b.trailingSlash,generate404:!0,hooks:b.verbose?{onPageStart:(Y)=>console.log(` Generating: ${Y}`),onPageEnd:(Y,Q)=>console.log(` Generated: ${Y} (${Q.length} bytes)`),onError:(Y,Q)=>console.error(` Error in ${Q}: ${Y.message}`)}:void 0},ssr:{outputDir:b.out==="dist"?".output":b.out,debug:b.verbose}}),U=((performance.now()-z)/1000).toFixed(2);if(H.mode==="ssr"&&H.ssr)console.log(`
73
73
  Build complete! (SSR)
74
74
  `),console.log(` Pages compiled: ${H.ssr.pageCount}`),console.log(` Output: ${H.ssr.outputDir}`),console.log(` Duration: ${U}s
75
75
  `);else if(H.ssg){if(console.log(`
@@ -84,7 +84,7 @@ Total: ${H} issues in ${W} files`),b.output){let U=`
84
84
  Build completed with ${H.ssg.failedCount} error(s). Fix the issues above and try again.
85
85
  `),w.exit(1);console.log(" To preview locally:"),console.log(` cd ${b.out||"dist"} && npx serve
86
86
  `)}}catch(z){console.error(`
87
- Build failed:`,z instanceof Error?z.message:String(z)),w.exit(1)}}),E.command("start","Start the production server (serves pre-built .output/)").option("--port <number>","Server port",{default:"3000"}).option("--output <dir>","Output directory from stx build",{default:".output"}).example("stx start").example("stx start --port 8080").action(async(x)=>{try{let b=$.resolve(x.output);if(!L.existsSync($.join(b,"manifest.json")))console.error("\n No production build found. Run `stx build --out .output` first.\n"),w.exit(1);let{startProductionServer:z}=await import("./chunk-q5gzpn1n.js");await z({outputDir:b,port:Number.parseInt(x.port,10)||3000})}catch(b){console.error(`
87
+ Build failed:`,z instanceof Error?z.message:String(z)),w.exit(1)}}),E.command("start","Start the production server (serves pre-built .output/)").option("--port <number>","Server port",{default:"3000"}).option("--output <dir>","Output directory from stx build",{default:".output"}).example("stx start").example("stx start --port 8080").action(async(x)=>{try{let b=$.resolve(x.output);if(!L.existsSync($.join(b,"manifest.json")))console.error("\n No production build found. Run `stx build --out .output` first.\n"),w.exit(1);let{startProductionServer:z}=await import("./chunk-washyj03.js");await z({outputDir:b,port:Number.parseInt(x.port,10)||3000})}catch(b){console.error(`
88
88
  Failed to start production server:`,b instanceof Error?b.message:String(b)),w.exit(1)}}),E.command("deploy [directory]","Deploy built site to Netlify").option("--site-id <id>","Netlify site ID (or set NETLIFY_SITE_ID env var)").option("--token <token>","Auth token (or set NETLIFY_AUTH_TOKEN env var)").option("--production","Deploy to production (default: draft preview)").option("--message <msg>","Deploy message/title").option("--no-build","Skip build step before deploy").option("--open","Open deployed URL in browser").option("--dry-run","Preview deployment without uploading").option("--init","Initialize Netlify configuration for this project").example("stx deploy").example("stx deploy --production").example("stx deploy dist --site-id my-site-abc123").example("stx deploy --init").example("stx deploy --dry-run").action(async(x,b)=>{try{let{deploy:z,initNetlify:k,DeployError:j}=await import("./chunk-6h3r8v55.js");if(console.log(`\x1B[1mstx deploy\x1B[0m \x1B[2mv${N}\x1B[0m`),b.init){console.log(`
89
89
  \uD83D\uDCDD Initializing Netlify configuration...
90
90
  `);let H=await k({directory:x||w.cwd(),siteId:b.siteId});if(console.log(`\u2713 Created ${H.configPath}`),H.siteId)console.log("\u2713 Saved site ID to .env.local");console.log(`
@@ -124,7 +124,7 @@ To view it in the development server:`),console.log(` stx dev ${x}
124
124
  \uD83D\uDCDD ${$.relative(w.cwd(),Q)}:`),console.log("--- Original"),console.log("+++ Formatted"),console.log(`@@ Changes in ${$.basename(Q)} @@`),console.log("+ Formatted content would be applied");else await Bun.write(Q,q),console.log(`\u2705 Formatted ${$.relative(w.cwd(),Q)}`),U++}catch(X){console.error(`\u274C Error formatting ${$.relative(w.cwd(),Q)}:`,X),Y++}if(b.check&&Y>0)console.log(`
125
125
  ${Y} files need formatting. Run 'stx format' to fix.`),w.exit(1);else if(!b.check&&!b.diff)console.log(`\u2728 Formatted ${U} files successfully`)}catch(z){console.error("Error formatting files:",z),w.exit(1)}}),E.command("perf [command...]","Show performance statistics for STX operations").option("--clear","Clear performance statistics").option("--json","Output as JSON").example("stx perf").example("stx perf --clear").example("stx perf --json").action(async(x,b)=>{try{if(b.clear){A.clear(),console.log("\u2705 Performance statistics cleared");return}let z=A.getStats();if(Object.keys(z).length===0){if(b.json){console.log(JSON.stringify({},null,2));return}console.log("No performance data available. Run some STX commands first.");return}if(b.json)console.log(JSON.stringify(z,null,2));else{console.log(`
126
126
  \uD83D\uDCCA STX Performance Statistics
127
- `);for(let[k,j]of Object.entries(z))console.log(`\uD83D\uDD27 ${k}:`),console.log(` Count: ${j.count}`),console.log(` Average: ${j.avgTime.toFixed(2)}ms`),console.log(` Total: ${j.totalTime.toFixed(2)}ms`),console.log(` Min: ${j.minTime.toFixed(2)}ms`),console.log(` Max: ${j.maxTime.toFixed(2)}ms`),console.log("")}}catch(z){console.error("Error showing performance stats:",z),w.exit(1)}}),E.command("typecheck [patterns...]","Type-check the TypeScript inside .stx script blocks").option("--no-client","Skip <script client> and bare <script> blocks").option("--no-server","Skip <script server> blocks").option("--no-templates","Skip {{ }} and directive expressions in the markup").option("--lib <path>","Extra ambient declaration file (repeatable)").example("stx typecheck").example('stx typecheck "resources/views/**/*.stx"').action(async(x,b)=>{let{formatTypecheckDiagnostics:z,typecheckStxFiles:k}=await import("./chunk-efx05ah0.js"),{resolveStxTargets:j}=await import("./chunk-erb294sv.js"),W=Array.isArray(x)?x:x?[x]:[],H=W.length?W:["**/*.stx"],U=await j(H);if(U.length===0){console.log(`
127
+ `);for(let[k,j]of Object.entries(z))console.log(`\uD83D\uDD27 ${k}:`),console.log(` Count: ${j.count}`),console.log(` Average: ${j.avgTime.toFixed(2)}ms`),console.log(` Total: ${j.totalTime.toFixed(2)}ms`),console.log(` Min: ${j.minTime.toFixed(2)}ms`),console.log(` Max: ${j.maxTime.toFixed(2)}ms`),console.log("")}}catch(z){console.error("Error showing performance stats:",z),w.exit(1)}}),E.command("typecheck [patterns...]","Type-check the TypeScript inside .stx script blocks").option("--no-client","Skip <script client> and bare <script> blocks").option("--no-server","Skip <script server> blocks").option("--no-templates","Skip {{ }} and directive expressions in the markup").option("--lib <path>","Extra ambient declaration file (repeatable)").example("stx typecheck").example('stx typecheck "resources/views/**/*.stx"').action(async(x,b)=>{let{formatTypecheckDiagnostics:z,typecheckStxFiles:k}=await import("./chunk-1xayahc6.js"),{resolveStxTargets:j}=await import("./chunk-erb294sv.js"),W=Array.isArray(x)?x:x?[x]:[],H=W.length?W:["**/*.stx"],U=await j(H);if(U.length===0){console.log(`
128
128
  No .stx files matched ${H.join(", ")}
129
129
  `);return}let Y=m(w.argv,"--lib"),Q=Y.length>0?Y:b.lib?Array.isArray(b.lib)?b.lib:[b.lib]:[],X=await k(U,{client:b.client!==!1,server:b.server!==!1,templates:b.templates!==!1,extraLibs:Q});if(X.failure)console.error(`
130
130
  Type-check did not run.
@@ -160,11 +160,11 @@ Press Ctrl+C to stop watching...
160
160
  \uD83D\uDCC4 Files with issues:`),Y.forEach((Q)=>{let X=Q.issues.filter((_)=>j[_.type]>=W).length;if(X>0)console.log(` ${$.relative(w.cwd(),Q.file)} (${X} issues)`)});if(b.saveReport){let Q={summary:U,results:Y,generatedAt:new Date().toISOString(),commandOptions:b};await Bun.write(b.saveReport,JSON.stringify(Q,null,2)),console.log(`
161
161
  \uD83D\uDCCB Analysis report saved to: ${b.saveReport}`)}console.log(`
162
162
  \u2728 Analysis complete! Use --detailed for more information.`)}catch(z){console.error("Error analyzing templates:",z),w.exit(1)}}),E.command("screenshot [input]","Capture PNG screenshot(s) of page(s) via Bun WebView \u2014 a file, URL, or dist directory").option("--out <dir>","Output directory",{default:"screenshots"}).option("--width <px>","Viewport width",{default:"1440"}).option("--height <px>","Viewport height",{default:"2200"}).option("--wait <ms>","Settle time after navigation before capture",{default:"800"}).option("--timeout <ms>","Hard cap on waiting for navigation",{default:"15000"}).option("--full-page","Capture the entire scrollable page, not just the viewport").option("--wait-selector <sel>","Wait until a CSS selector exists before capturing").option("--format <fmt>","Image format: png | jpeg | webp",{default:"png"}).option("--backend <name>","WebView backend: webkit (macOS, default) | chrome").action(async(x,b)=>{let{captureScreenshots:z}=await import("./chunk-gsc2vds7.js"),k=x||"dist";try{let j=await z(k,b.out,{width:Number.parseInt(b.width,10),height:Number.parseInt(b.height,10),waitMs:Number.parseInt(b.wait,10),timeoutMs:Number.parseInt(b.timeout,10),fullPage:Boolean(b.fullPage),waitSelector:b.waitSelector,format:b.format,backend:b.backend});for(let W of j)console.log(`\uD83D\uDCF8 ${W.output} (${(W.bytes/1024).toFixed(0)} KB)`);console.log(`
163
- \u2728 Captured ${j.length} screenshot(s) to ${b.out}/ via Bun WebView`)}catch(j){console.error(`Screenshot failed: ${j.message}`),w.exit(1)}}),E.command("version","Show the version of the CLI").action(()=>{console.log(N)}),E.command("interactive","Start interactive REPL mode for template development").alias("i").option("--context <file>","Load initial context from JSON file").option("--cwd <directory>","Set working directory").option("--verbose","Show verbose output").action(async(x)=>{let{startInteractive:b}=await import("./chunk-9yqt0nf2.js"),z={};if(x.context){let k=$.resolve(x.context);if(L.existsSync(k))try{let j=L.readFileSync(k,"utf-8");z=JSON.parse(j)}catch(j){console.error("Error loading context file:",j),w.exit(1)}else console.error(`Context file not found: ${k}`),w.exit(1)}await b({context:z,cwd:x.cwd?$.resolve(x.cwd):w.cwd(),verbose:x.verbose})}),E.command("build:native <input>","Build stx template into a native desktop/mobile app").option("--output <dir>","Output directory",{default:"dist/native"}).option("--target <platform>","Target platform: macos, windows, linux, ios, android").option("--format <format>","Output format: app, dmg, pkg, msi, zip, deb, rpm, appimage, ipa, apk").option("--name <name>","Application name (defaults to filename)").option("--version <version>","Application version",{default:"1.0.0"}).option("--description <desc>","Application description").option("--author <author>","Author/Maintainer name").option("--bundle-id <id>","Bundle identifier (macOS/iOS)").option("--icon <path>","Path to application icon").option("--width <width>","Window width",{default:"1200"}).option("--height <height>","Window height",{default:"800"}).option("--title <title>","Window title").option("--system-tray","Enable system tray/menubar mode").option("--menubar-only","Run without a dock icon (implied by --system-tray)").option("--category <type>","LSApplicationCategoryType (macOS)").option("--copyright <text>","NSHumanReadableCopyright (macOS)").option("--min-system-version <v>","LSMinimumSystemVersion (macOS)").option("--info-plist <json>","Extra Info.plist keys as a JSON object (macOS)").option("--dev-tools","Enable developer tools").option("--frameless","Create frameless window").option("--always-on-top","Keep window always on top").option("--craft-path <path>","Path to Craft binary").option("--verbose","Show verbose output").example("stx build:native app.stx --target macos").example("stx build:native app.stx --target macos --format dmg").example("stx build:native app.stx --target linux --format appimage").example('stx build:native app.stx --name "My App" --icon icon.png').action(async(x,b)=>{try{let{buildNative:z,getAvailableTargets:k,getAvailableFormats:j}=await import("./chunk-5apmxb4e.js"),W=$.resolve(x);if(!L.existsSync(W))console.error(`\u274C Input file not found: ${x}`),w.exit(1);let H=k();if(b.target&&!["macos","windows","linux","ios","android"].includes(b.target))console.error(`\u274C Invalid target: ${b.target}`),console.error("\uD83D\uDCA1 Available targets: macos, windows, linux, ios, android"),console.error(`\uD83D\uDCA1 Targets available on this machine: ${H.join(", ")}`),w.exit(1);let U=b.target||H[0],Y=j(U);if(b.format&&!Y.includes(b.format))console.error(`\u274C Invalid format for ${U}: ${b.format}`),console.error(`\uD83D\uDCA1 Available formats: ${Y.join(", ")}`),w.exit(1);console.log(`
163
+ \u2728 Captured ${j.length} screenshot(s) to ${b.out}/ via Bun WebView`)}catch(j){console.error(`Screenshot failed: ${j.message}`),w.exit(1)}}),E.command("version","Show the version of the CLI").action(()=>{console.log(N)}),E.command("interactive","Start interactive REPL mode for template development").alias("i").option("--context <file>","Load initial context from JSON file").option("--cwd <directory>","Set working directory").option("--verbose","Show verbose output").action(async(x)=>{let{startInteractive:b}=await import("./chunk-qp7sk0ex.js"),z={};if(x.context){let k=$.resolve(x.context);if(L.existsSync(k))try{let j=L.readFileSync(k,"utf-8");z=JSON.parse(j)}catch(j){console.error("Error loading context file:",j),w.exit(1)}else console.error(`Context file not found: ${k}`),w.exit(1)}await b({context:z,cwd:x.cwd?$.resolve(x.cwd):w.cwd(),verbose:x.verbose})}),E.command("build:native <input>","Build stx template into a native desktop/mobile app").option("--output <dir>","Output directory",{default:"dist/native"}).option("--target <platform>","Target platform: macos, windows, linux, ios, android").option("--format <format>","Output format: app, dmg, pkg, msi, zip, deb, rpm, appimage, ipa, apk").option("--name <name>","Application name (defaults to filename)").option("--version <version>","Application version",{default:"1.0.0"}).option("--description <desc>","Application description").option("--author <author>","Author/Maintainer name").option("--bundle-id <id>","Bundle identifier (macOS/iOS)").option("--icon <path>","Path to application icon").option("--width <width>","Window width",{default:"1200"}).option("--height <height>","Window height",{default:"800"}).option("--title <title>","Window title").option("--system-tray","Enable system tray/menubar mode").option("--menubar-only","Run without a dock icon (implied by --system-tray)").option("--category <type>","LSApplicationCategoryType (macOS)").option("--copyright <text>","NSHumanReadableCopyright (macOS)").option("--min-system-version <v>","LSMinimumSystemVersion (macOS)").option("--info-plist <json>","Extra Info.plist keys as a JSON object (macOS)").option("--dev-tools","Enable developer tools").option("--frameless","Create frameless window").option("--always-on-top","Keep window always on top").option("--craft-path <path>","Path to Craft binary").option("--verbose","Show verbose output").example("stx build:native app.stx --target macos").example("stx build:native app.stx --target macos --format dmg").example("stx build:native app.stx --target linux --format appimage").example('stx build:native app.stx --name "My App" --icon icon.png').action(async(x,b)=>{try{let{buildNative:z,getAvailableTargets:k,getAvailableFormats:j}=await import("./chunk-s11e8aq9.js"),W=$.resolve(x);if(!L.existsSync(W))console.error(`\u274C Input file not found: ${x}`),w.exit(1);let H=k();if(b.target&&!["macos","windows","linux","ios","android"].includes(b.target))console.error(`\u274C Invalid target: ${b.target}`),console.error("\uD83D\uDCA1 Available targets: macos, windows, linux, ios, android"),console.error(`\uD83D\uDCA1 Targets available on this machine: ${H.join(", ")}`),w.exit(1);let U=b.target||H[0],Y=j(U);if(b.format&&!Y.includes(b.format))console.error(`\u274C Invalid format for ${U}: ${b.format}`),console.error(`\uD83D\uDCA1 Available formats: ${Y.join(", ")}`),w.exit(1);console.log(`
164
164
  \uD83D\uDD28 Building native app...`),console.log(` Input: ${x}`),console.log(` Target: ${U}`),console.log(` Format: ${b.format||"default"}`),console.log(` Output: ${b.output}
165
165
  `);let Q=await z({input:W,output:$.resolve(b.output),target:U,format:b.format,name:b.name,version:b.version,description:b.description,author:b.author,bundleId:b.bundleId,icon:b.icon?$.resolve(b.icon):void 0,window:{title:b.title,width:Number.parseInt(b.width,10),height:Number.parseInt(b.height,10),frameless:b.frameless,alwaysOnTop:b.alwaysOnTop},systemTray:b.systemTray,menubarOnly:b.menubarOnly,category:b.category,copyright:b.copyright,minimumSystemVersion:b.minSystemVersion,infoPlist:kb(b.infoPlist),devTools:b.devTools,craftPath:b.craftPath,verbose:b.verbose});if(Q.success){if(console.log("\u2705 Build successful!"),console.log(` Output: ${Q.outputPath}`),Q.duration)console.log(` Duration: ${(Q.duration/1000).toFixed(2)}s`);if(U==="macos"&&Q.format==="app")console.log(`
166
166
  \uD83D\uDCA1 To run: open "${Q.outputPath}"`);else if(U==="linux"&&Q.format==="appimage")console.log(`
167
- \uD83D\uDCA1 To run: chmod +x "${Q.outputPath}" && "${Q.outputPath}"`)}else console.error(`\u274C Build failed: ${Q.error}`),w.exit(1)}catch(z){console.error(`\u274C Build error: ${z.message}`),w.exit(1)}}),E.command("story","Start component showcase and testing server").option("-p, --port <port>","Server port",{default:"6006"}).option("-o, --open","Open browser automatically",{default:!1}).option("--host <host>","Host to bind to",{default:"localhost"}).example("stx story").example("stx story --port 3000 --open").action(async(x)=>{try{let{devCommand:b}=await import("./chunk-mvat8js5.js");await b({port:x.port?Number.parseInt(x.port,10):6006,open:x.open,host:x.host})}catch(b){console.error(`\u274C Story error: ${b.message}`),w.exit(1)}}),E.command("story:build","Build static story site").option("-o, --outDir <dir>","Output directory",{default:".stx/dist/story"}).example("stx story:build").example("stx story:build --outDir ./docs/components").action(async(x)=>{try{let{buildCommand:b}=await import("./chunk-kw9cgyfc.js");await b({outDir:x.outDir})}catch(b){console.error(`\u274C Story build error: ${b.message}`),w.exit(1)}}),E.command("story:test","Run visual regression tests").option("-u, --update","Update snapshots",{default:!1}).option("-f, --filter <name>","Filter components by name").example("stx story:test").example("stx story:test --update").example("stx story:test --filter Button").action(async(x)=>{try{let{createContext:b}=await import("./chunk-59906baj.js"),{runVisualTests:z,updateSnapshots:k,formatTestResults:j}=await import("./chunk-nm60wh6r.js"),W=await b({mode:"build"});if(x.update){let H=await k(W,{filter:x.filter?[x.filter]:void 0});console.log(`Updated ${H} snapshots`)}else{let H=await z(W,{filter:x.filter?[x.filter]:void 0});if(console.log(j(H)),H.failed>0)w.exit(1)}}catch(b){console.error(`\u274C Story test error: ${b.message}`),w.exit(1)}}),E.command("compile <input>","Compile stx template to native Craft component code").option("--target <platform>","Target platform: macos, windows, linux, ios, android, universal",{default:"universal"}).option("--format <format>","Output format: zig, typescript, json",{default:"zig"}).option("--output <path>","Output directory for compiled files",{default:"./dist"}).option("--optimize","Enable optimizations",{default:!0}).option("--tree-shake","Enable tree shaking",{default:!0}).option("--hot-reload","Enable hot reload support",{default:!1}).option("--sourcemaps","Generate source maps",{default:!1}).option("--bundle","Bundle all dependencies",{default:!0}).option("--minify","Minify output",{default:!1}).option("--verbose","Show detailed output",{default:!1}).example("stx compile app.stx").example("stx compile app.stx --target macos --format zig").example("stx compile app.stx --format typescript --output ./native").example("stx compile app.stx --optimize --tree-shake --minify").action(async(x,b)=>{try{let{compileToNative:z}=await import("./chunk-e7np0h2q.js"),k=$.resolve(x);if(!L.existsSync(k))console.error(`\u274C Input file not found: ${x}`),w.exit(1);let j=["macos","windows","linux","ios","android","universal"];if(!j.includes(b.target))console.error(`\u274C Invalid target: ${b.target}`),console.error(`\uD83D\uDCA1 Available targets: ${j.join(", ")}`),w.exit(1);let W=["zig","typescript","json"];if(!W.includes(b.format))console.error(`\u274C Invalid format: ${b.format}`),console.error(`\uD83D\uDCA1 Available formats: ${W.join(", ")}`),w.exit(1);console.log(`
167
+ \uD83D\uDCA1 To run: chmod +x "${Q.outputPath}" && "${Q.outputPath}"`)}else console.error(`\u274C Build failed: ${Q.error}`),w.exit(1)}catch(z){console.error(`\u274C Build error: ${z.message}`),w.exit(1)}}),E.command("story","Start component showcase and testing server").option("-p, --port <port>","Server port",{default:"6006"}).option("-o, --open","Open browser automatically",{default:!1}).option("--host <host>","Host to bind to",{default:"localhost"}).example("stx story").example("stx story --port 3000 --open").action(async(x)=>{try{let{devCommand:b}=await import("./chunk-1vyz6kr8.js");await b({port:x.port?Number.parseInt(x.port,10):6006,open:x.open,host:x.host})}catch(b){console.error(`\u274C Story error: ${b.message}`),w.exit(1)}}),E.command("story:build","Build static story site").option("-o, --outDir <dir>","Output directory",{default:".stx/dist/story"}).example("stx story:build").example("stx story:build --outDir ./docs/components").action(async(x)=>{try{let{buildCommand:b}=await import("./chunk-kw9cgyfc.js");await b({outDir:x.outDir})}catch(b){console.error(`\u274C Story build error: ${b.message}`),w.exit(1)}}),E.command("story:test","Run visual regression tests").option("-u, --update","Update snapshots",{default:!1}).option("-f, --filter <name>","Filter components by name").example("stx story:test").example("stx story:test --update").example("stx story:test --filter Button").action(async(x)=>{try{let{createContext:b}=await import("./chunk-59906baj.js"),{runVisualTests:z,updateSnapshots:k,formatTestResults:j}=await import("./chunk-nm60wh6r.js"),W=await b({mode:"build"});if(x.update){let H=await k(W,{filter:x.filter?[x.filter]:void 0});console.log(`Updated ${H} snapshots`)}else{let H=await z(W,{filter:x.filter?[x.filter]:void 0});if(console.log(j(H)),H.failed>0)w.exit(1)}}catch(b){console.error(`\u274C Story test error: ${b.message}`),w.exit(1)}}),E.command("compile <input>","Compile stx template to native Craft component code").option("--target <platform>","Target platform: macos, windows, linux, ios, android, universal",{default:"universal"}).option("--format <format>","Output format: zig, typescript, json",{default:"zig"}).option("--output <path>","Output directory for compiled files",{default:"./dist"}).option("--optimize","Enable optimizations",{default:!0}).option("--tree-shake","Enable tree shaking",{default:!0}).option("--hot-reload","Enable hot reload support",{default:!1}).option("--sourcemaps","Generate source maps",{default:!1}).option("--bundle","Bundle all dependencies",{default:!0}).option("--minify","Minify output",{default:!1}).option("--verbose","Show detailed output",{default:!1}).example("stx compile app.stx").example("stx compile app.stx --target macos --format zig").example("stx compile app.stx --format typescript --output ./native").example("stx compile app.stx --optimize --tree-shake --minify").action(async(x,b)=>{try{let{compileToNative:z}=await import("./chunk-e7np0h2q.js"),k=$.resolve(x);if(!L.existsSync(k))console.error(`\u274C Input file not found: ${x}`),w.exit(1);let j=["macos","windows","linux","ios","android","universal"];if(!j.includes(b.target))console.error(`\u274C Invalid target: ${b.target}`),console.error(`\uD83D\uDCA1 Available targets: ${j.join(", ")}`),w.exit(1);let W=["zig","typescript","json"];if(!W.includes(b.format))console.error(`\u274C Invalid format: ${b.format}`),console.error(`\uD83D\uDCA1 Available formats: ${W.join(", ")}`),w.exit(1);console.log(`
168
168
  \uD83D\uDD27 Compiling stx template to native code...`),console.log(` Input: ${x}`),console.log(` Target: ${b.target}`),console.log(` Format: ${b.format}`),console.log(` Output: ${b.output}
169
169
  `);let H=L.readFileSync(k,"utf-8"),U=await z(H,{target:b.target,format:b.format,optimize:b.optimize,treeShake:b.treeShake,hotReload:b.hotReload,debug:b.verbose,sourceMaps:b.sourcemaps,bundle:b.bundle,minify:b.minify}),Y=$.resolve(b.output);if(!L.existsSync(Y))L.mkdirSync(Y,{recursive:!0});let Q=$.basename(x,$.extname(x)),X=b.format==="typescript"?"ts":b.format==="json"?"json":"zig",_=$.join(Y,`${Q}.${X}`);L.writeFileSync(_,U.code);let q=$.join(Y,`${Q}.manifest.json`);if(L.writeFileSync(q,JSON.stringify(U.manifest,null,2)),b.sourcemaps&&U.sourceMaps){let O=$.join(Y,`${Q}.${X}.map`);L.writeFileSync(O,U.sourceMaps)}if(b.target==="universal"&&U.platformCode.size>0)for(let[O,M]of U.platformCode){let G=$.join(Y,`${Q}.${O}.${X}`);L.writeFileSync(G,M)}if(console.log("\u2705 Compilation successful!"),console.log(` Output: ${_}`),console.log(` Manifest: ${q}`),console.log(`
170
170
  \uD83D\uDCCA Statistics:`),console.log(` Compilation time: ${U.stats.compilationTime.toFixed(2)}ms`),console.log(` Total components: ${U.stats.totalComponents}`),console.log(` Native components: ${U.stats.nativeComponents}`),console.log(` Web fallback components: ${U.stats.webComponents}`),console.log(` Bundle size: ${(U.stats.bundleSize/1024).toFixed(2)}KB`),U.stats.warnings.length>0){console.log(`
@@ -1,35 +1,4 @@
1
1
  import type { ComponentLibraryBuildResult, ComponentLibraryConfig } from './types';
2
- /**
3
- * Carry the component's computed values into the element.
4
- *
5
- * A component's script is where its thinking lives: the formatted total, the
6
- * colour that says whether a number moved the right way, the geometry of a
7
- * path. Dropping it and keeping only the markup, which is what this build did
8
- * before, leaves a component that can display a value but cannot derive one,
9
- * and every real component derives something.
10
- *
11
- * Top-level `const` and `let` declarations become the scope the template reads.
12
- * Imports are hoisted to the generated module so a component can share helpers
13
- * with the rest of a codebase rather than restating them, which is the whole
14
- * reason to write the component in stx and not in the consuming language.
15
- *
16
- * `defineProps` / `withDefaults` are recognised and removed: they declare the
17
- * element's public surface, which is already expressed as properties, and
18
- * leaving the call in would reference an import that does not exist at runtime.
19
- */
20
- /**
21
- * Split a `withDefaults(..., { ... })` object into name/value pairs.
22
- *
23
- * Values are read by scanning to the comma that actually ends them, rather
24
- * than to the first comma in the text. The difference is not academic: a
25
- * default of `'To begin, click your user name'` used to be cut at its own
26
- * comma and emitted as `'To begin`, so the generated render function failed
27
- * to parse with "Unterminated string literal" and the whole component library
28
- * build stopped on a component whose only sin was a comma in a sentence.
29
- *
30
- * Quotes (including template literals and escapes) and nested brackets are
31
- * tracked so an object, array or function default survives intact too.
32
- */
33
2
  export declare function parseDefaults(object: string): Array<[string, string]>;
34
3
  /**
35
4
  * Compile a directory of .stx single-file components into a progressive,
@@ -1,5 +1,12 @@
1
1
  import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
+ function reservedMethodMessage(name) {
4
+ if (name === "connectedCallback")
5
+ return `method "${name}" is reserved; define "onConnect" instead, which the element calls once it is connected, rendered and bound`;
6
+ if (name === "disconnectedCallback")
7
+ return `method "${name}" is reserved; define "onDisconnect" instead, which the element calls as it leaves the DOM, before it releases its own listeners`;
8
+ return `method "${name}" is reserved`;
9
+ }
3
10
  const RESERVED_METHODS = new Set([
4
11
  "constructor",
5
12
  "connectedCallback",
@@ -69,7 +76,7 @@ function extractClientMethods(source, file) {
69
76
  while (match = functionPattern.exec(code)) {
70
77
  const name = match[1];
71
78
  if (RESERVED_METHODS.has(name))
72
- throw Error(`${file}: client method "${name}" is reserved`);
79
+ throw Error(`${file}: client ${reservedMethodMessage(name)}`);
73
80
  const bodyStart = functionPattern.lastIndex;
74
81
  let depth = 1, quote = "", escaped = !1, cursor = bodyStart;
75
82
  for (;cursor < code.length && depth > 0; cursor++) {
@@ -235,6 +242,242 @@ function compileTemplateToRender(template) {
235
242
  return parts.join(`
236
243
  `);
237
244
  }
245
+ function skipBalanced(source, index, open, close) {
246
+ if (source[index] !== open)
247
+ return -1;
248
+ let depth = 0, quote = null;
249
+ for (let i = index;i < source.length; i++) {
250
+ const char = source[i];
251
+ if (quote) {
252
+ if (char === "\\") {
253
+ i++;
254
+ continue;
255
+ }
256
+ if (char === quote)
257
+ quote = null;
258
+ continue;
259
+ }
260
+ if (char === "'" || char === '"' || char === "`") {
261
+ quote = char;
262
+ continue;
263
+ }
264
+ if (char === open)
265
+ depth++;
266
+ else if (char === close) {
267
+ if (close === ">" && source[i - 1] === "=")
268
+ continue;
269
+ depth--;
270
+ if (depth === 0)
271
+ return i + 1;
272
+ }
273
+ }
274
+ return -1;
275
+ }
276
+ function splitTopLevel(body, separators, angles) {
277
+ const opening = angles ? "([{<" : "([{", closing = angles ? ")]}>" : ")]}", parts = [];
278
+ let depth = 0, quote = null, current = "";
279
+ for (let i = 0;i < body.length; i++) {
280
+ const char = body[i];
281
+ if (quote) {
282
+ current += char;
283
+ if (char === "\\") {
284
+ current += body[++i] ?? "";
285
+ continue;
286
+ }
287
+ if (char === quote)
288
+ quote = null;
289
+ continue;
290
+ }
291
+ if (char === "'" || char === '"' || char === "`") {
292
+ quote = char;
293
+ current += char;
294
+ continue;
295
+ }
296
+ if (opening.includes(char))
297
+ depth++;
298
+ else if (closing.includes(char))
299
+ depth--;
300
+ if (depth === 0 && separators.includes(char)) {
301
+ parts.push(current);
302
+ current = "";
303
+ continue;
304
+ }
305
+ current += char;
306
+ }
307
+ parts.push(current);
308
+ return parts.map((part) => part.trim()).filter(Boolean);
309
+ }
310
+ function defaultAssignmentIndex(entry) {
311
+ let depth = 0, quote = null;
312
+ for (let i = 0;i < entry.length; i++) {
313
+ const char = entry[i];
314
+ if (quote) {
315
+ if (char === "\\") {
316
+ i++;
317
+ continue;
318
+ }
319
+ if (char === quote)
320
+ quote = null;
321
+ continue;
322
+ }
323
+ if (char === "'" || char === '"' || char === "`") {
324
+ quote = char;
325
+ continue;
326
+ }
327
+ if ("([{".includes(char))
328
+ depth++;
329
+ else if (")]}".includes(char))
330
+ depth--;
331
+ if (depth !== 0 || char !== "=")
332
+ continue;
333
+ const previous = entry[i - 1];
334
+ if (entry[i + 1] === "=" || previous === "=" || previous === "!" || previous === "<" || previous === ">")
335
+ continue;
336
+ return i;
337
+ }
338
+ return -1;
339
+ }
340
+ function typeFromConstructor(value) {
341
+ switch (value.trim()) {
342
+ case "String":
343
+ return "string";
344
+ case "Number":
345
+ return "number";
346
+ case "Boolean":
347
+ return "boolean";
348
+ case "Array":
349
+ return "unknown[]";
350
+ case "Object":
351
+ return "Record<string, unknown>";
352
+ default:
353
+ return;
354
+ }
355
+ }
356
+ function parsePropsDeclaration(code) {
357
+ const call = /\bdefineProps\b/.exec(code);
358
+ if (!call)
359
+ return null;
360
+ const keyword = /(?:^|[\s;{}()])(const|let|var)\s+/g;
361
+ let start = -1;
362
+ for (let found = keyword.exec(code);found && found.index < call.index; found = keyword.exec(code))
363
+ start = found.index + found[0].indexOf(found[1]);
364
+ if (start === -1)
365
+ return null;
366
+ const declared = {}, defaults = {}, propNames = [];
367
+ let cursor = start + (/^(?:const|let|var)\s+/.exec(code.slice(start))?.[0].length ?? 0);
368
+ const skipSpace = () => {
369
+ while (cursor < code.length && /\s/.test(code[cursor]))
370
+ cursor++;
371
+ };
372
+ let pattern;
373
+ if (code[cursor] === "{") {
374
+ const end = skipBalanced(code, cursor, "{", "}");
375
+ if (end === -1)
376
+ return null;
377
+ pattern = code.slice(cursor, end);
378
+ cursor = end;
379
+ } else {
380
+ const identifier = /^[A-Za-z_$][\w$]*/.exec(code.slice(cursor));
381
+ if (!identifier)
382
+ return null;
383
+ pattern = identifier[0];
384
+ cursor += identifier[0].length;
385
+ }
386
+ skipSpace();
387
+ if (code[cursor] !== "=")
388
+ return null;
389
+ cursor++;
390
+ skipSpace();
391
+ const wrapper = /^withDefaults\s*\(\s*/.exec(code.slice(cursor)), wrapped = Boolean(wrapper);
392
+ if (wrapper)
393
+ cursor += wrapper[0].length;
394
+ const marker = /^defineProps\b/.exec(code.slice(cursor));
395
+ if (!marker)
396
+ return null;
397
+ cursor += marker[0].length;
398
+ let typeText = "";
399
+ skipSpace();
400
+ if (code[cursor] === "<") {
401
+ const end = skipBalanced(code, cursor, "<", ">");
402
+ if (end === -1)
403
+ return null;
404
+ typeText = code.slice(cursor + 1, end - 1).trim();
405
+ cursor = end;
406
+ }
407
+ skipSpace();
408
+ if (code[cursor] !== "(")
409
+ return null;
410
+ const callEnd = skipBalanced(code, cursor, "(", ")");
411
+ if (callEnd === -1)
412
+ return null;
413
+ const runtimeArgument = code.slice(cursor + 1, callEnd - 1).trim();
414
+ cursor = callEnd;
415
+ if (wrapped) {
416
+ skipSpace();
417
+ if (code[cursor] === ",") {
418
+ cursor++;
419
+ skipSpace();
420
+ }
421
+ if (code[cursor] === "{") {
422
+ const end = skipBalanced(code, cursor, "{", "}");
423
+ if (end === -1)
424
+ return null;
425
+ for (const [name, value] of parseDefaults(code.slice(cursor, end)))
426
+ defaults[name] = value;
427
+ cursor = end;
428
+ }
429
+ skipSpace();
430
+ if (code[cursor] === ",") {
431
+ cursor++;
432
+ skipSpace();
433
+ }
434
+ if (code[cursor] === ")")
435
+ cursor++;
436
+ }
437
+ if (code[cursor] === ";")
438
+ cursor++;
439
+ const typeName = /^[A-Za-z_$][\w$]*$/.test(typeText) ? typeText : void 0;
440
+ if (typeText.startsWith("{"))
441
+ for (const member of splitTopLevel(typeText.replace(/^\{/, "").replace(/\}$/, ""), ",;", !0)) {
442
+ const parsed = /^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(member);
443
+ if (parsed)
444
+ declared[parsed[1]] = parsed[2].trim();
445
+ }
446
+ if (runtimeArgument.startsWith("{"))
447
+ for (const [name, value] of parseDefaults(runtimeArgument)) {
448
+ propNames.push(name);
449
+ if (!value.startsWith("{")) {
450
+ const fromConstructor = typeFromConstructor(value);
451
+ if (fromConstructor)
452
+ declared[name] = fromConstructor;
453
+ continue;
454
+ }
455
+ for (const [key, inner] of parseDefaults(value))
456
+ if (key === "default")
457
+ defaults[name] = inner;
458
+ else if (key === "type") {
459
+ const fromConstructor = typeFromConstructor(inner);
460
+ if (fromConstructor)
461
+ declared[name] = fromConstructor;
462
+ }
463
+ }
464
+ else if (runtimeArgument.startsWith("["))
465
+ for (const entry of splitTopLevel(runtimeArgument.slice(1, -1), ",", !1))
466
+ propNames.push(entry.replace(/^['"`]/, "").replace(/['"`]$/, ""));
467
+ if (pattern.startsWith("{")) {
468
+ propNames.length = 0;
469
+ for (const entry of splitTopLevel(pattern.replace(/^\{/, "").replace(/\}$/, ""), ",", !1)) {
470
+ const assignment = defaultAssignmentIndex(entry), name = (assignment === -1 ? entry : entry.slice(0, assignment)).split(":")[0].trim().replace(/^\.\.\./, "");
471
+ if (!name)
472
+ continue;
473
+ propNames.push(name);
474
+ if (assignment !== -1)
475
+ defaults[name] = entry.slice(assignment + 1).trim();
476
+ }
477
+ } else if (propNames.length === 0)
478
+ propNames.push(...Object.keys(declared));
479
+ return { text: code.slice(start, cursor), propNames, defaults, declared, typeName };
480
+ }
238
481
  export function parseDefaults(object) {
239
482
  const body = object.trim().replace(/^\{/, "").replace(/\}$/, ""), pairs = [];
240
483
  let index = 0;
@@ -286,20 +529,27 @@ function compileScriptScope(source, file, outputDir) {
286
529
  }));
287
530
  return "";
288
531
  });
289
- const propMatch = /const\s*\{([^}]*)\}\s*=\s*(?:withDefaults\s*\(\s*)?defineProps\s*<[^>]*>\s*\(\s*\)\s*(?:,\s*(\{[\s\S]*?\})\s*,?\s*\))?/.exec(code);
290
- if (propMatch) {
291
- for (const name of propMatch[1].split(",")) {
292
- const clean = name.split(":")[0].trim();
293
- if (clean)
294
- propNames.push(clean);
295
- }
296
- for (const [name, value] of parseDefaults(propMatch[2] || ""))
297
- defaults[name] = value;
298
- code = code.replace(propMatch[0], "");
299
- }
300
- for (const block of code.matchAll(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{([\s\S]*?)\n\}/g))
301
- for (const member of block[1].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))
532
+ const props = parsePropsDeclaration(code);
533
+ if (props) {
534
+ propNames.push(...props.propNames);
535
+ Object.assign(defaults, props.defaults);
536
+ Object.assign(declared, props.declared);
537
+ code = code.replace(props.text, "");
538
+ }
539
+ const interfaceMembers = {};
540
+ for (const block of code.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)) {
541
+ const members = [];
542
+ for (const member of block[2].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm)) {
302
543
  declared[member[1]] = member[2].trim();
544
+ members.push(member[1]);
545
+ }
546
+ interfaceMembers[block[1]] = members;
547
+ }
548
+ if (props && props.propNames.length === 0 && props.typeName) {
549
+ for (const name of interfaceMembers[props.typeName] ?? [])
550
+ if (!propNames.includes(name))
551
+ propNames.push(name);
552
+ }
303
553
  code = code.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g, "");
304
554
  return { imports, body: code.trim(), propNames, defaults, declared };
305
555
  }
@@ -469,12 +719,24 @@ export class StxElement extends HTMLElementBase {
469
719
  this.setAttribute?.('hydrated', '');
470
720
  this.dispatchEvent?.(new CustomEvent('stx:hydrated', { bubbles: true, composed: true }));
471
721
  }
722
+ // Called last, so a component that acquires something sees its own rendered
723
+ // markup and its events already bound. Reported rather than rethrown: a
724
+ // component that fails to set up must not take the element down with it.
725
+ try { this.onConnect?.(); }
726
+ catch (error) { console.error('[stx] onConnect failed', error); }
472
727
  }
473
728
 
474
729
  disconnectedCallback() {
475
730
  this._connected = false;
476
- for (const [event, listener] of this._listeners) this.renderRoot.removeEventListener(event, listener);
477
- this._listeners.clear();
731
+ // Called before the framework releases anything, so the element is still
732
+ // intact for a component that needs to read it on the way out, and inside
733
+ // try/finally so a throwing hook cannot leak the framework's own listeners.
734
+ try { this.onDisconnect?.(); }
735
+ catch (error) { console.error('[stx] onDisconnect failed', error); }
736
+ finally {
737
+ for (const [event, listener] of this._listeners) this.renderRoot.removeEventListener(event, listener);
738
+ this._listeners.clear();
739
+ }
478
740
  }
479
741
 
480
742
  attributeChangedCallback(attribute, oldValue, newValue) {
@@ -677,7 +939,7 @@ function componentModule(component) {
677
939
  bindings: component.bindings
678
940
  }, null, 2), methodCode = Object.entries(component.methods).map(([name, body]) => {
679
941
  if (RESERVED_METHODS.has(name))
680
- throw Error(`${component.sourcePath}: method "${name}" is reserved`);
942
+ throw Error(`${component.sourcePath}: ${reservedMethodMessage(name)}`);
681
943
  if (/^(?:async\s+)?[A-Za-z_$][\w$]*\s*\(/.test(body.trim()))
682
944
  return ` ${body.trim()}`;
683
945
  return ` ${name}($event) {
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Xj as Nj,Yj as wj,Zj as Aj}from"./chunk-f5cw54q3.js";import{$j as Uj,ak as Xj,bk as Yj,ck as Zj,dk as _j,ek as $j,fk as qj,gk as Fj,hk as Oj,ik as Vj,jk as Ij,kk as Qj,lk as Wj,mk as Kj}from"./chunk-72x5v5an.js";import"./chunk-g28fs4aa.js";import"./chunk-5atmahe4.js";import"./chunk-8y1ve8tc.js";import"./chunk-njx93b4z.js";import"./chunk-bqdfbwdf.js";import"./chunk-89mqnh67.js";import"./chunk-xvh1k1a4.js";import"./chunk-fs2t4rs3.js";import"./chunk-y2f41kaq.js";import"./chunk-xj6bcwqa.js";import"./chunk-7t6h8crt.js";import"./chunk-vhta1be7.js";import"./chunk-tc4pj651.js";import"./chunk-san1eq0r.js";import"./chunk-avwywzsj.js";import"./chunk-wj21f1e0.js";import"./chunk-d86q27j8.js";import"./chunk-72x62kch.js";import"./chunk-yg5r7bnm.js";import"./chunk-9nrgjtah.js";import"./chunk-ejqpq0wc.js";var I=new Map,Q=new Map;function L(j,B){let G=B?.id||g(j),J=h(j),U=I.get(G);if(U&&U.hash===J)return U;let X=S(j),Z=y(j),Y=T(j),_=v(X),{staticParts:q,dynamicParts:$}=C(X),F=u(j),O={id:G,hash:J,tree:X,scripts:Z,styles:Y,staticParts:q,dynamicParts:$,dependencies:F,metadata:_};return I.set(G,O),O}async function r(j,B={},G={}){let J=performance.now();if(G.cache){let Y=`${j.id}:${JSON.stringify(B)}`,_=Q.get(Y);if(_&&Date.now()-_.timestamp<(G.cacheTTL||60000))return{html:_.html,styles:j.styles.join(`
2
+ import{Xj as Nj,Yj as wj,Zj as Aj}from"./chunk-f5cw54q3.js";import{$j as Uj,ak as Xj,bk as Yj,ck as Zj,dk as _j,ek as $j,fk as qj,gk as Fj,hk as Oj,ik as Vj,jk as Ij,kk as Qj,lk as Wj,mk as Kj}from"./chunk-k80kr2t2.js";import"./chunk-vw83y4we.js";import"./chunk-zdq7emrd.js";import"./chunk-8y1ve8tc.js";import"./chunk-njx93b4z.js";import"./chunk-bqdfbwdf.js";import"./chunk-89mqnh67.js";import"./chunk-xvh1k1a4.js";import"./chunk-skd72bn4.js";import"./chunk-y2f41kaq.js";import"./chunk-xj6bcwqa.js";import"./chunk-21mmq3aj.js";import"./chunk-vhta1be7.js";import"./chunk-tc4pj651.js";import"./chunk-san1eq0r.js";import"./chunk-avwywzsj.js";import"./chunk-wj21f1e0.js";import"./chunk-d86q27j8.js";import"./chunk-72x62kch.js";import"./chunk-yg5r7bnm.js";import"./chunk-9nrgjtah.js";import"./chunk-ejqpq0wc.js";var I=new Map,Q=new Map;function L(j,B){let G=B?.id||g(j),J=h(j),U=I.get(G);if(U&&U.hash===J)return U;let X=S(j),Z=y(j),Y=T(j),_=v(X),{staticParts:q,dynamicParts:$}=C(X),F=u(j),O={id:G,hash:J,tree:X,scripts:Z,styles:Y,staticParts:q,dynamicParts:$,dependencies:F,metadata:_};return I.set(G,O),O}async function r(j,B={},G={}){let J=performance.now();if(G.cache){let Y=`${j.id}:${JSON.stringify(B)}`,_=Q.get(Y);if(_&&Date.now()-_.timestamp<(G.cacheTTL||60000))return{html:_.html,styles:j.styles.join(`
3
3
  `),scripts:j.scripts.join(`
4
4
  `),metadata:{renderTime:0,cacheHit:!0,totalSize:_.html.length,componentCount:j.metadata.componentCount}}}let U;if(G.streaming)U=await H(j.tree,B);else U=W(j.tree,B);let X;if(G.hydrate){let Y=k(U,j,B);U=Y.html,X=Y.data}if(G.minify)U=x(U);if(G.cache){let Y=`${j.id}:${JSON.stringify(B)}`;Q.set(Y,{html:U,timestamp:Date.now()})}let Z=performance.now()-J;return{html:U,styles:j.styles.join(`
5
5
  `),scripts:j.scripts.join(`
package/dist/craft.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Xj as Nj,Yj as wj,Zj as Aj}from"./chunk-f5cw54q3.js";import{$j as Uj,ak as Xj,bk as Yj,ck as Zj,dk as _j,ek as $j,fk as qj,gk as Fj,hk as Oj,ik as Vj,jk as Ij,kk as Qj,lk as Wj,mk as Kj}from"./chunk-72x5v5an.js";import"./chunk-g28fs4aa.js";import"./chunk-5atmahe4.js";import"./chunk-8y1ve8tc.js";import"./chunk-njx93b4z.js";import"./chunk-bqdfbwdf.js";import"./chunk-89mqnh67.js";import"./chunk-xvh1k1a4.js";import"./chunk-fs2t4rs3.js";import"./chunk-y2f41kaq.js";import"./chunk-xj6bcwqa.js";import"./chunk-7t6h8crt.js";import"./chunk-vhta1be7.js";import"./chunk-tc4pj651.js";import"./chunk-san1eq0r.js";import"./chunk-avwywzsj.js";import"./chunk-wj21f1e0.js";import"./chunk-d86q27j8.js";import"./chunk-72x62kch.js";import"./chunk-yg5r7bnm.js";import"./chunk-9nrgjtah.js";import"./chunk-ejqpq0wc.js";var I=new Map,Q=new Map;function L(j,B){let G=B?.id||g(j),J=h(j),U=I.get(G);if(U&&U.hash===J)return U;let X=S(j),Z=y(j),Y=T(j),_=v(X),{staticParts:q,dynamicParts:$}=C(X),F=u(j),O={id:G,hash:J,tree:X,scripts:Z,styles:Y,staticParts:q,dynamicParts:$,dependencies:F,metadata:_};return I.set(G,O),O}async function r(j,B={},G={}){let J=performance.now();if(G.cache){let Y=`${j.id}:${JSON.stringify(B)}`,_=Q.get(Y);if(_&&Date.now()-_.timestamp<(G.cacheTTL||60000))return{html:_.html,styles:j.styles.join(`
2
+ import{Xj as Nj,Yj as wj,Zj as Aj}from"./chunk-f5cw54q3.js";import{$j as Uj,ak as Xj,bk as Yj,ck as Zj,dk as _j,ek as $j,fk as qj,gk as Fj,hk as Oj,ik as Vj,jk as Ij,kk as Qj,lk as Wj,mk as Kj}from"./chunk-k80kr2t2.js";import"./chunk-vw83y4we.js";import"./chunk-zdq7emrd.js";import"./chunk-8y1ve8tc.js";import"./chunk-njx93b4z.js";import"./chunk-bqdfbwdf.js";import"./chunk-89mqnh67.js";import"./chunk-xvh1k1a4.js";import"./chunk-skd72bn4.js";import"./chunk-y2f41kaq.js";import"./chunk-xj6bcwqa.js";import"./chunk-21mmq3aj.js";import"./chunk-vhta1be7.js";import"./chunk-tc4pj651.js";import"./chunk-san1eq0r.js";import"./chunk-avwywzsj.js";import"./chunk-wj21f1e0.js";import"./chunk-d86q27j8.js";import"./chunk-72x62kch.js";import"./chunk-yg5r7bnm.js";import"./chunk-9nrgjtah.js";import"./chunk-ejqpq0wc.js";var I=new Map,Q=new Map;function L(j,B){let G=B?.id||g(j),J=h(j),U=I.get(G);if(U&&U.hash===J)return U;let X=S(j),Z=y(j),Y=T(j),_=v(X),{staticParts:q,dynamicParts:$}=C(X),F=u(j),O={id:G,hash:J,tree:X,scripts:Z,styles:Y,staticParts:q,dynamicParts:$,dependencies:F,metadata:_};return I.set(G,O),O}async function r(j,B={},G={}){let J=performance.now();if(G.cache){let Y=`${j.id}:${JSON.stringify(B)}`,_=Q.get(Y);if(_&&Date.now()-_.timestamp<(G.cacheTTL||60000))return{html:_.html,styles:j.styles.join(`
3
3
  `),scripts:j.scripts.join(`
4
4
  `),metadata:{renderTime:0,cacheHit:!0,totalSize:_.html.length,componentCount:j.metadata.componentCount}}}let U;if(G.streaming)U=await H(j.tree,B);else U=W(j.tree,B);let X;if(G.hydrate){let Y=k(U,j,B);U=Y.html,X=Y.data}if(G.minify)U=x(U);if(G.cache){let Y=`${j.id}:${JSON.stringify(B)}`;Q.set(Y,{html:U,timestamp:Date.now()})}let Z=performance.now()-J;return{html:U,styles:j.styles.join(`
5
5
  `),scripts:j.scripts.join(`