@stacksjs/stx 0.2.302 → 0.2.304

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 (271) hide show
  1. package/dist/api-client.d.ts +26 -0
  2. package/dist/api-client.js +22 -0
  3. package/dist/api-handler.d.ts +6 -0
  4. package/dist/api-handler.js +3 -0
  5. package/dist/app-shell.js +11 -2
  6. package/dist/application-layers.d.ts +30 -0
  7. package/dist/application-layers.js +202 -0
  8. package/dist/build.js +9 -1
  9. package/dist/chunk-02hm88m5.js +2 -0
  10. package/dist/{chunk-7eea1cse.js → chunk-09zjty4k.js} +1 -1
  11. package/dist/{chunk-7nfn7nj9.js → chunk-0gz0rhvs.js} +1 -1
  12. package/dist/{chunk-jsfch50r.js → chunk-1c2j4eby.js} +1 -1
  13. package/dist/{chunk-m6wz1hf5.js → chunk-2h94c5hm.js} +2 -2
  14. package/dist/{chunk-mjpqz66q.js → chunk-2ver2s2y.js} +1 -1
  15. package/dist/{chunk-2wcd2031.js → chunk-30nbe9hr.js} +2 -2
  16. package/dist/chunk-39qzhpn6.js +18 -0
  17. package/dist/chunk-3z6bqqr7.js +2 -0
  18. package/dist/chunk-43p1qq7g.js +2 -0
  19. package/dist/{chunk-52rkkkmt.js → chunk-45y8bjrv.js} +287 -352
  20. package/dist/{chunk-2rp09y5j.js → chunk-4evbx7sz.js} +1 -1
  21. package/dist/chunk-4jgr954p.js +2 -0
  22. package/dist/chunk-51j2aqvb.js +2 -0
  23. package/dist/{chunk-8d15pd4g.js → chunk-54f8bpp6.js} +3 -3
  24. package/dist/{chunk-cbwp8prr.js → chunk-5k1hznvq.js} +2 -2
  25. package/dist/chunk-5qfpcgcs.js +2 -0
  26. package/dist/{chunk-7eg7ep8f.js → chunk-5tefa8qb.js} +2 -2
  27. package/dist/chunk-5x2fc4vk.js +30 -0
  28. package/dist/{chunk-683tfkz4.js → chunk-64djh88a.js} +1 -1
  29. package/dist/{chunk-btrmvj2y.js → chunk-695fkras.js} +1 -1
  30. package/dist/chunk-6hcc4973.js +2 -0
  31. package/dist/{chunk-svg37jzs.js → chunk-6vswphz4.js} +2 -2
  32. package/dist/chunk-7gqbr8nr.js +2 -0
  33. package/dist/{chunk-x4prtyjs.js → chunk-7kw3grq5.js} +1 -1
  34. package/dist/{chunk-7jebw3ea.js → chunk-7skk34dh.js} +2 -2
  35. package/dist/chunk-8215nhej.js +12 -0
  36. package/dist/chunk-8ee62a9q.js +2 -0
  37. package/dist/{chunk-jj6yp7gm.js → chunk-8jam44my.js} +1 -1
  38. package/dist/chunk-8z0n5mtg.js +2 -0
  39. package/dist/{chunk-3bc8bqw2.js → chunk-9368t9jm.js} +1 -1
  40. package/dist/chunk-9499k64n.js +6 -0
  41. package/dist/chunk-976g5qe5.js +2 -0
  42. package/dist/{chunk-3jwmcf4k.js → chunk-9c835qjn.js} +1 -1
  43. package/dist/chunk-9px4y692.js +2 -0
  44. package/dist/{chunk-38t0fxh0.js → chunk-9vqnrcrw.js} +2 -2
  45. package/dist/chunk-9wrrr7g3.js +4 -0
  46. package/dist/{chunk-q0y1yxg3.js → chunk-9xzszvn5.js} +1 -1
  47. package/dist/chunk-a07chbgj.js +2 -0
  48. package/dist/{chunk-454kar39.js → chunk-ankp4reb.js} +2 -2
  49. package/dist/{chunk-5d9cy7a0.js → chunk-awj7yy37.js} +1 -1
  50. package/dist/chunk-b1hd8kvy.js +2 -0
  51. package/dist/chunk-b4xwbh8a.js +2 -0
  52. package/dist/{chunk-d6wq91cw.js → chunk-bd9wrcq1.js} +277 -21
  53. package/dist/{chunk-q25mr70f.js → chunk-c131k3mt.js} +1 -1
  54. package/dist/chunk-c3tmzx7q.js +2 -0
  55. package/dist/{chunk-6btbgxh1.js → chunk-c79nfdyj.js} +1 -1
  56. package/dist/{chunk-cfgpk6bh.js → chunk-cbgh359m.js} +1 -1
  57. package/dist/chunk-ckzhp09g.js +2 -0
  58. package/dist/{chunk-weqpt9nt.js → chunk-cr8v8k53.js} +1 -1
  59. package/dist/{chunk-p3wwm6k4.js → chunk-d19tvdvv.js} +1 -1
  60. package/dist/{chunk-nb1zdh1y.js → chunk-d3srvh3q.js} +1 -1
  61. package/dist/{chunk-rqrfq305.js → chunk-d57gb0v2.js} +1 -1
  62. package/dist/{chunk-1xyhk1wr.js → chunk-d5cqnwdd.js} +1 -1
  63. package/dist/chunk-dgpjxmhs.js +2 -0
  64. package/dist/chunk-dvvx1wny.js +3 -0
  65. package/dist/{chunk-ctz53mbz.js → chunk-ej8mv2k6.js} +1 -1
  66. package/dist/{chunk-dv3z80gt.js → chunk-env6knrs.js} +1 -1
  67. package/dist/{chunk-rf10fkrf.js → chunk-ess2pgt5.js} +1 -1
  68. package/dist/chunk-ez28vck6.js +2 -0
  69. package/dist/{chunk-0tbgvp70.js → chunk-fczfdsab.js} +21 -5
  70. package/dist/{chunk-xdq52pwj.js → chunk-fp7ms6e7.js} +1 -1
  71. package/dist/{chunk-qg6pg6ze.js → chunk-fqq5k9ve.js} +1 -1
  72. package/dist/chunk-fvtv1s5j.js +3 -0
  73. package/dist/{chunk-5t0w4h6z.js → chunk-g912mb7x.js} +1 -1
  74. package/dist/chunk-g97atepq.js +2 -0
  75. package/dist/{chunk-wj25qt72.js → chunk-gbwhbasw.js} +1 -1
  76. package/dist/{chunk-38e9wgfc.js → chunk-gfc3qye3.js} +2 -2
  77. package/dist/{chunk-cratkhhb.js → chunk-ghw5p1yk.js} +1 -1
  78. package/dist/{chunk-f0g2q51j.js → chunk-gssbag3e.js} +1 -1
  79. package/dist/{chunk-c9vhtjtr.js → chunk-gt8ja700.js} +2 -2
  80. package/dist/chunk-hay1rzb0.js +3754 -0
  81. package/dist/{chunk-q5sw26s7.js → chunk-hg2afckn.js} +1 -1
  82. package/dist/chunk-hgjjnjas.js +7 -0
  83. package/dist/{chunk-hhnzd03k.js → chunk-hrcxfvh1.js} +1 -1
  84. package/dist/chunk-hzav4hyd.js +2 -0
  85. package/dist/{chunk-29gjwajm.js → chunk-jfzfrmzy.js} +1 -1
  86. package/dist/chunk-jjq9q9jr.js +2 -0
  87. package/dist/{chunk-ddqkj56r.js → chunk-jp2f8yzw.js} +1 -1
  88. package/dist/{chunk-ry3a2674.js → chunk-jsg1rthc.js} +1 -1
  89. package/dist/chunk-jxxv18a0.js +5 -0
  90. package/dist/chunk-kbw2qzqx.js +2 -0
  91. package/dist/chunk-kdxvraec.js +2 -0
  92. package/dist/chunk-krfjb7b8.js +2 -0
  93. package/dist/{chunk-6b4k8fay.js → chunk-kxavsh3m.js} +1 -1
  94. package/dist/{chunk-4tffxxpd.js → chunk-m31n9pkr.js} +1 -1
  95. package/dist/{chunk-fj6fbqgb.js → chunk-m3a20mmb.js} +1 -1
  96. package/dist/{chunk-j21csh4j.js → chunk-mbmqpaq1.js} +1 -1
  97. package/dist/{chunk-y9nyqcha.js → chunk-mwh3ymwc.js} +1 -1
  98. package/dist/{chunk-51g95yts.js → chunk-mygq61f5.js} +2 -2
  99. package/dist/chunk-nqq7y7m9.js +3 -0
  100. package/dist/chunk-nws8fbde.js +2 -0
  101. package/dist/{chunk-q6xfyasj.js → chunk-pcvayb2f.js} +1 -1
  102. package/dist/{chunk-nvxv2wxv.js → chunk-ppyz9623.js} +1 -1
  103. package/dist/chunk-pr14wjkn.js +2 -0
  104. package/dist/{chunk-jb2r696a.js → chunk-qev11kg8.js} +1 -1
  105. package/dist/{chunk-6njgsr6w.js → chunk-qeyw5za9.js} +1 -1
  106. package/dist/chunk-rpfcnq8n.js +2 -0
  107. package/dist/chunk-rrankpmj.js +3 -0
  108. package/dist/chunk-rst1rw09.js +2 -0
  109. package/dist/{chunk-3p0zgfgz.js → chunk-rzevgemj.js} +2 -2
  110. package/dist/{chunk-aa6kt84c.js → chunk-sart9ehj.js} +1 -1
  111. package/dist/chunk-sb7ana2z.js +19 -0
  112. package/dist/chunk-snt2773t.js +2 -0
  113. package/dist/{chunk-jptkc64r.js → chunk-t3qb9s6s.js} +2 -2
  114. package/dist/{chunk-w8yac9xp.js → chunk-t41aaehf.js} +1 -1
  115. package/dist/{chunk-qjkzpd68.js → chunk-t51mwjyq.js} +1 -1
  116. package/dist/chunk-tt4r8q4v.js +2 -0
  117. package/dist/chunk-vd3h9z7e.js +2 -0
  118. package/dist/{chunk-6rzwef28.js → chunk-vd5xvsnv.js} +1 -1
  119. package/dist/chunk-wbecqx03.js +2 -0
  120. package/dist/{chunk-dcxtrqfy.js → chunk-wfffa8zm.js} +1 -1
  121. package/dist/{chunk-22p0ezj6.js → chunk-wx13qmaw.js} +1 -1
  122. package/dist/chunk-xd5ahrtn.js +2 -0
  123. package/dist/{chunk-vh0qr8k9.js → chunk-xganfzgn.js} +2 -2
  124. package/dist/chunk-xq1swv2e.js +2 -0
  125. package/dist/chunk-xsfwcj6x.js +2 -0
  126. package/dist/{chunk-91007tan.js → chunk-xwxdwqn9.js} +1 -1
  127. package/dist/{chunk-634gaa9d.js → chunk-xz3evxqp.js} +1 -1
  128. package/dist/chunk-xzgvcrnz.js +2 -0
  129. package/dist/chunk-y2kmm6bt.js +43 -0
  130. package/dist/{chunk-v8474ah4.js → chunk-y4nzmkea.js} +1 -1
  131. package/dist/chunk-y7wsk78j.js +3 -0
  132. package/dist/{chunk-6w8fa3b8.js → chunk-ya5m5vbn.js} +1 -1
  133. package/dist/{chunk-ps20v1ah.js → chunk-ym3r8ktq.js} +1 -1
  134. package/dist/chunk-yyebm8q4.js +2 -0
  135. package/dist/chunk-yyyxt326.js +2 -0
  136. package/dist/chunk-yz16bgs3.js +28 -0
  137. package/dist/{chunk-em8p71et.js → chunk-z9ezmjwd.js} +2 -2
  138. package/dist/chunk-zbtfhxhn.js +2 -0
  139. package/dist/chunk-zggm7kjd.js +17 -0
  140. package/dist/{chunk-mdf3jbe6.js → chunk-zhcs8m2a.js} +2 -2
  141. package/dist/{chunk-f9d27v49.js → chunk-zs5y7xnt.js} +1 -1
  142. package/dist/cli.js +14 -14
  143. package/dist/client-script-bundler.js +22 -11
  144. package/dist/component-contract-checks.d.ts +19 -0
  145. package/dist/component-contract-checks.js +147 -0
  146. package/dist/component-contract.d.ts +20 -0
  147. package/dist/component-contract.js +108 -0
  148. package/dist/component-model.d.ts +29 -0
  149. package/dist/component-model.js +59 -0
  150. package/dist/component-registry.js +7 -64
  151. package/dist/component-renderer.d.ts +1 -26
  152. package/dist/component-renderer.js +4 -239
  153. package/dist/component-resolution.d.ts +21 -0
  154. package/dist/component-resolution.js +118 -0
  155. package/dist/component-tags.d.ts +9 -0
  156. package/dist/component-tags.js +174 -0
  157. package/dist/composable-loader.d.ts +2 -13
  158. package/dist/composable-loader.js +15 -26
  159. package/dist/composables/index.d.ts +1 -0
  160. package/dist/composables/index.js +1 -0
  161. package/dist/composables/use-fetch.d.ts +117 -42
  162. package/dist/composables/use-fetch.js +47 -4
  163. package/dist/composition-api.d.ts +43 -19
  164. package/dist/config.d.ts +1 -1
  165. package/dist/config.js +46 -4
  166. package/dist/craft-entry.js +1 -1
  167. package/dist/craft.js +1 -1
  168. package/dist/database.js +1 -1
  169. package/dist/dev-server/serve-app.js +57 -17
  170. package/dist/dev-server/serve-file.js +8 -1
  171. package/dist/expressions.js +1 -1
  172. package/dist/imported-signals.js +1 -1
  173. package/dist/includes.js +8 -2
  174. package/dist/index.d.ts +11 -0
  175. package/dist/index.js +7 -0
  176. package/dist/manifest.d.ts +6 -0
  177. package/dist/misc-directives.d.ts +2 -0
  178. package/dist/misc-directives.js +39 -1
  179. package/dist/process.js +18 -1
  180. package/dist/production-builder.d.ts +4 -0
  181. package/dist/production-builder.js +47 -8
  182. package/dist/production-server.d.ts +4 -1
  183. package/dist/production-server.js +119 -71
  184. package/dist/pwa.js +2 -2
  185. package/dist/render.js +9 -2
  186. package/dist/route-response-cache.d.ts +7 -0
  187. package/dist/route-response-cache.js +72 -0
  188. package/dist/route-rules.d.ts +17 -0
  189. package/dist/route-rules.js +40 -0
  190. package/dist/router.d.ts +1 -0
  191. package/dist/runtime-config-loader.d.ts +5 -0
  192. package/dist/runtime-config-loader.js +42 -0
  193. package/dist/runtime-config-server.d.ts +26 -0
  194. package/dist/runtime-config-server.js +77 -0
  195. package/dist/runtime-config-types.d.ts +2 -0
  196. package/dist/runtime-config-types.js +0 -0
  197. package/dist/runtime-config.d.ts +5 -0
  198. package/dist/runtime-config.js +9 -0
  199. package/dist/runtime-globals.js +3 -0
  200. package/dist/serve.js +32 -10
  201. package/dist/server-api.d.ts +27 -0
  202. package/dist/server-api.js +181 -0
  203. package/dist/server-data.d.ts +17 -0
  204. package/dist/server-data.js +40 -0
  205. package/dist/signal-processing.js +2 -2
  206. package/dist/signals.js +210 -17
  207. package/dist/ssg.js +2 -2
  208. package/dist/stx-virtual-ts.d.ts +6 -0
  209. package/dist/stx-virtual-ts.js +31 -7
  210. package/dist/stx.d.ts +28 -0
  211. package/dist/template-compiler.d.ts +1 -0
  212. package/dist/template-compiler.js +1 -1
  213. package/dist/template-hydrator.js +15 -4
  214. package/dist/typecheck.d.ts +1 -0
  215. package/dist/typecheck.js +4 -3
  216. package/dist/types/config-types.d.ts +17 -0
  217. package/dist/utils.js +15 -5
  218. package/dist/variable-extractor.d.ts +1 -1
  219. package/dist/variable-extractor.js +12 -1
  220. package/dist/visual-testing.js +1 -1
  221. package/dist/vue-template.js +19 -41
  222. package/package.json +5 -5
  223. package/stx.d.ts +28 -0
  224. package/dist/chunk-0p44z42s.js +0 -2
  225. package/dist/chunk-1na1dvda.js +0 -2
  226. package/dist/chunk-2yp8ang5.js +0 -2
  227. package/dist/chunk-35x7s4cr.js +0 -2
  228. package/dist/chunk-39qnycbc.js +0 -2
  229. package/dist/chunk-4qj6pq60.js +0 -2
  230. package/dist/chunk-4r1qdp25.js +0 -19
  231. package/dist/chunk-4xs545h1.js +0 -2
  232. package/dist/chunk-70cf5h11.js +0 -2
  233. package/dist/chunk-7k63nhap.js +0 -28
  234. package/dist/chunk-7w3dttqh.js +0 -2
  235. package/dist/chunk-813dt09p.js +0 -2
  236. package/dist/chunk-9cp3430d.js +0 -2
  237. package/dist/chunk-ac9vpa5z.js +0 -2
  238. package/dist/chunk-b26xazrf.js +0 -2
  239. package/dist/chunk-b2ghmxpj.js +0 -4
  240. package/dist/chunk-btnky17z.js +0 -12
  241. package/dist/chunk-c7av0px6.js +0 -2
  242. package/dist/chunk-cthpzv4p.js +0 -18
  243. package/dist/chunk-d41b0rqp.js +0 -2
  244. package/dist/chunk-dkd0bg8g.js +0 -2
  245. package/dist/chunk-e0s519df.js +0 -2
  246. package/dist/chunk-ebr2344x.js +0 -3
  247. package/dist/chunk-ehp6fez3.js +0 -2
  248. package/dist/chunk-fc5t3cxt.js +0 -2
  249. package/dist/chunk-g6ttsdz1.js +0 -2
  250. package/dist/chunk-gd73rpks.js +0 -2
  251. package/dist/chunk-gv42xz15.js +0 -17
  252. package/dist/chunk-h3t6fjba.js +0 -2
  253. package/dist/chunk-h65nep6y.js +0 -2
  254. package/dist/chunk-h7d01cy7.js +0 -2
  255. package/dist/chunk-jc57j887.js +0 -2
  256. package/dist/chunk-k5xtf38q.js +0 -3
  257. package/dist/chunk-mc4rtf5d.js +0 -2
  258. package/dist/chunk-me5kq4e6.js +0 -22
  259. package/dist/chunk-mzf6c0h7.js +0 -2
  260. package/dist/chunk-n1j7gfe1.js +0 -3
  261. package/dist/chunk-pczxwdes.js +0 -2
  262. package/dist/chunk-pq6rabcy.js +0 -3754
  263. package/dist/chunk-qr59yfq9.js +0 -2
  264. package/dist/chunk-s454ytp4.js +0 -2
  265. package/dist/chunk-s4sp78fn.js +0 -2
  266. package/dist/chunk-shr928nn.js +0 -2
  267. package/dist/chunk-that7v95.js +0 -2
  268. package/dist/chunk-vwnnbzsp.js +0 -2
  269. package/dist/chunk-w63052rn.js +0 -2
  270. package/dist/chunk-w9kzfesd.js +0 -2
  271. package/dist/chunk-zwy5e35f.js +0 -30
@@ -0,0 +1,118 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ const pkgStxIndexCache = new Map;
4
+ export function buildStxIndex(pkgDir, cache = !0) {
5
+ const cached = pkgStxIndexCache.get(pkgDir);
6
+ if (cache && cached)
7
+ return cached;
8
+ const index = new Map, roots = [path.join(pkgDir, "src"), path.join(pkgDir, "dist"), pkgDir];
9
+ function walk(dir, depth) {
10
+ if (depth > 6)
11
+ return;
12
+ let entries;
13
+ try {
14
+ entries = fs.readdirSync(dir, { withFileTypes: !0 });
15
+ } catch {
16
+ return;
17
+ }
18
+ for (const entry of entries) {
19
+ const full = path.join(dir, entry.name);
20
+ if (entry.isDirectory()) {
21
+ if (entry.name === "node_modules" || entry.name.startsWith("."))
22
+ continue;
23
+ walk(full, depth + 1);
24
+ } else if (entry.isFile() && entry.name.endsWith(".stx")) {
25
+ const base = entry.name.slice(0, -4);
26
+ if (!index.has(base))
27
+ index.set(base, full);
28
+ const lower = base.toLowerCase();
29
+ if (!index.has(lower))
30
+ index.set(lower, full);
31
+ const kebab = base.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
32
+ if (!index.has(kebab))
33
+ index.set(kebab, full);
34
+ }
35
+ }
36
+ }
37
+ for (const root of roots) {
38
+ walk(root, 0);
39
+ if (index.size > 0)
40
+ break;
41
+ }
42
+ if (cache)
43
+ pkgStxIndexCache.set(pkgDir, index);
44
+ return index;
45
+ }
46
+ export function resolvePackageDir(spec, fromDir) {
47
+ if (spec.startsWith(".") || spec.startsWith("/"))
48
+ return null;
49
+ let dir = fromDir;
50
+ while (!0) {
51
+ const candidate = path.join(dir, "node_modules", spec);
52
+ try {
53
+ if (fs.statSync(candidate).isDirectory())
54
+ return candidate;
55
+ } catch {}
56
+ const parent = path.dirname(dir);
57
+ if (parent === dir)
58
+ return null;
59
+ dir = parent;
60
+ }
61
+ }
62
+ export function componentImportCandidates(componentPath, filePath, options = {}) {
63
+ return [
64
+ path.resolve(path.dirname(filePath), `${componentPath}.stx`),
65
+ path.resolve(path.dirname(filePath), componentPath),
66
+ path.resolve(options.componentsDir || "components", `${componentPath}.stx`),
67
+ path.resolve(options.componentsDir || "components", componentPath),
68
+ componentPath.endsWith(".stx") ? componentPath : `${componentPath}.stx`
69
+ ];
70
+ }
71
+ function variants(name) {
72
+ const base = name.endsWith(".stx") ? name.slice(0, -4) : name, pascal = base.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(""), kebab = base.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
73
+ return [base, pascal, kebab];
74
+ }
75
+ export function importedComponentPath(name, context) {
76
+ const [base, pascal, kebab] = variants(name);
77
+ for (const candidate of [base, base.toLowerCase(), pascal, kebab]) {
78
+ const imported = context?.__importedComponents?.get(candidate);
79
+ if (imported !== void 0)
80
+ return imported;
81
+ }
82
+ }
83
+ export function* componentFileCandidates(name, fromFile, options = {}, context) {
84
+ const names = variants(name);
85
+ if (names[0].startsWith("./") || names[0].startsWith("../")) {
86
+ yield path.resolve(path.dirname(fromFile), `${names[0]}.stx`);
87
+ return;
88
+ }
89
+ const files = [...new Set(names.map((base) => `${base}.stx`))], projectRoot = options.projectRoot || process.cwd(), directories = [
90
+ ...context?.__originalFilePath ? [path.join(path.dirname(context.__originalFilePath), "components")] : [],
91
+ ...options.componentsDir ? [options.componentsDir] : [],
92
+ path.join(path.dirname(fromFile), "components"),
93
+ path.resolve(projectRoot, "src/components"),
94
+ path.resolve(projectRoot, "components"),
95
+ ...import.meta.dir ? [path.resolve(import.meta.dir, "components")] : []
96
+ ];
97
+ for (const directory of new Set(directories)) {
98
+ for (const file of files)
99
+ yield path.join(directory, file);
100
+ try {
101
+ for (const entry of fs.readdirSync(directory, { withFileTypes: !0 }))
102
+ if (entry.isDirectory())
103
+ for (const file of files)
104
+ yield path.join(directory, entry.name, file);
105
+ } catch {}
106
+ }
107
+ }
108
+ export function resolveComponentFileSync(name, fromFile, options = {}, context) {
109
+ const imported = importedComponentPath(name, context);
110
+ if (imported !== void 0)
111
+ return imported;
112
+ for (const candidate of componentFileCandidates(name, fromFile, options, context))
113
+ try {
114
+ if (fs.statSync(candidate, { throwIfNoEntry: !1 })?.isFile())
115
+ return candidate;
116
+ } catch {}
117
+ return null;
118
+ }
@@ -0,0 +1,9 @@
1
+ export declare const htmlTags: Set<string>;
2
+ /**
3
+ * Whether `tagName` certainly reaches the page as the element it names, by the
4
+ * three passes of `processComponents` below. A component tag is replaced by
5
+ * the component's markup, and attributes stamped on the tag do not survive it.
6
+ * A kebab-case tag is a component when a file of that name exists, which this
7
+ * cannot know, so it never counts as certain.
8
+ */
9
+ export declare function rendersAsElement(tagName: string): boolean;
@@ -0,0 +1,174 @@
1
+ export const htmlTags = new Set([
2
+ "a",
3
+ "abbr",
4
+ "address",
5
+ "area",
6
+ "article",
7
+ "aside",
8
+ "audio",
9
+ "b",
10
+ "base",
11
+ "bdi",
12
+ "bdo",
13
+ "blockquote",
14
+ "body",
15
+ "br",
16
+ "button",
17
+ "canvas",
18
+ "caption",
19
+ "cite",
20
+ "code",
21
+ "col",
22
+ "colgroup",
23
+ "component",
24
+ "data",
25
+ "datalist",
26
+ "dd",
27
+ "del",
28
+ "details",
29
+ "dfn",
30
+ "dialog",
31
+ "div",
32
+ "dl",
33
+ "dt",
34
+ "em",
35
+ "embed",
36
+ "fieldset",
37
+ "figcaption",
38
+ "figure",
39
+ "footer",
40
+ "form",
41
+ "h1",
42
+ "h2",
43
+ "h3",
44
+ "h4",
45
+ "h5",
46
+ "h6",
47
+ "head",
48
+ "header",
49
+ "hgroup",
50
+ "hr",
51
+ "html",
52
+ "i",
53
+ "iframe",
54
+ "img",
55
+ "input",
56
+ "ins",
57
+ "kbd",
58
+ "label",
59
+ "legend",
60
+ "li",
61
+ "link",
62
+ "main",
63
+ "map",
64
+ "mark",
65
+ "menu",
66
+ "meta",
67
+ "meter",
68
+ "nav",
69
+ "noscript",
70
+ "object",
71
+ "ol",
72
+ "optgroup",
73
+ "option",
74
+ "output",
75
+ "p",
76
+ "param",
77
+ "picture",
78
+ "pre",
79
+ "progress",
80
+ "q",
81
+ "rp",
82
+ "rt",
83
+ "ruby",
84
+ "s",
85
+ "samp",
86
+ "script",
87
+ "section",
88
+ "select",
89
+ "slot",
90
+ "small",
91
+ "source",
92
+ "span",
93
+ "strong",
94
+ "style",
95
+ "sub",
96
+ "summary",
97
+ "sup",
98
+ "svg",
99
+ "table",
100
+ "tbody",
101
+ "td",
102
+ "template",
103
+ "textarea",
104
+ "tfoot",
105
+ "th",
106
+ "thead",
107
+ "time",
108
+ "title",
109
+ "tr",
110
+ "track",
111
+ "u",
112
+ "ul",
113
+ "var",
114
+ "video",
115
+ "wbr",
116
+ "path",
117
+ "circle",
118
+ "rect",
119
+ "line",
120
+ "polygon",
121
+ "polyline",
122
+ "ellipse",
123
+ "text",
124
+ "tspan",
125
+ "textPath",
126
+ "g",
127
+ "defs",
128
+ "use",
129
+ "symbol",
130
+ "image",
131
+ "clipPath",
132
+ "mask",
133
+ "pattern",
134
+ "marker",
135
+ "linearGradient",
136
+ "radialGradient",
137
+ "stop",
138
+ "filter",
139
+ "feBlend",
140
+ "feColorMatrix",
141
+ "feComponentTransfer",
142
+ "feComposite",
143
+ "feConvolveMatrix",
144
+ "feDiffuseLighting",
145
+ "feDisplacementMap",
146
+ "feDropShadow",
147
+ "feFlood",
148
+ "feGaussianBlur",
149
+ "feImage",
150
+ "feMerge",
151
+ "feMergeNode",
152
+ "feMorphology",
153
+ "feOffset",
154
+ "feSpecularLighting",
155
+ "feTile",
156
+ "feTurbulence",
157
+ "foreignObject",
158
+ "animate",
159
+ "animateMotion",
160
+ "animateTransform",
161
+ "set",
162
+ "mpath",
163
+ "desc",
164
+ "metadata",
165
+ "switch",
166
+ "view"
167
+ ]);
168
+ export function rendersAsElement(tagName) {
169
+ if (tagName.includes("-") || tagName === "component")
170
+ return !1;
171
+ if (/^[A-Z]/.test(tagName))
172
+ return !/[a-z]/.test(tagName) && [...htmlTags].some((tag) => tag.toLowerCase() === tagName.toLowerCase());
173
+ return htmlTags.has(tagName) || /[A-Z]/.test(tagName);
174
+ }
@@ -29,24 +29,13 @@ export interface ComposableModule {
29
29
  /** Exported binding names, excluding `default`. */
30
30
  names: string[];
31
31
  }
32
- /**
33
- * Every composable file in the resolved directory, with its exported names.
34
- *
35
- * Shared by the two consumers that need the names without the bundle: the
36
- * typechecker, which has to declare them or an app's own composables read as
37
- * undefined (#1934), and the per-page pruning that decides which of them a page
38
- * actually references (#1936).
39
- *
40
- * Returns an empty array when there is no composables directory, which is the
41
- * common case and not an error.
42
- */
43
- export declare function listComposableModules(composablesDir?: string): Promise<ComposableModule[]>;
32
+ export declare function listComposableModules(composablesDir?: string | string[]): Promise<ComposableModule[]>;
44
33
  /**
45
34
  * @param pageSource - the rendered page, used to drop composables it cannot
46
35
  * reach. Omit to emit every composable, which is what a caller with no page in
47
36
  * hand needs.
48
37
  */
49
- export declare function getComposableScript(composablesDir?: string, pageSource?: string,
38
+ export declare function getComposableScript(composablesDir?: string | string[], pageSource?: string,
50
39
  /**
51
40
  * Text that is not (yet) part of `pageSource` but will ship with the page --
52
41
  * the store bundle and the framework-composable bundle, which are collected
@@ -37,21 +37,22 @@ async function probeDefaultDirs() {
37
37
  }
38
38
  return null;
39
39
  }
40
- export async function listComposableModules(composablesDir) {
41
- const resolvedDir = await resolveComposablesDir(composablesDir);
42
- if (!resolvedDir)
43
- return [];
44
- const files = [];
45
- try {
40
+ async function composableSources(input) {
41
+ const dirs = Array.isArray(input) ? input : input ? [path.resolve(input)] : (await loadStxConfig())._layerComposableDirs ?? [await resolveComposablesDir()].filter((dir) => !!dir), selected = new Map;
42
+ for (const dir of dirs) {
46
43
  const glob = new Bun.Glob("**/*.ts");
47
- for await (const file of glob.scan({ cwd: resolvedDir, absolute: !0 }))
48
- if (!isSkippedFile(file))
49
- files.push(file);
50
- } catch {
51
- return [];
44
+ try {
45
+ for await (const file of glob.scan({ cwd: dir, absolute: !0 })) {
46
+ const relative = path.relative(dir, file);
47
+ if (!isSkippedFile(file) && !selected.has(relative))
48
+ selected.set(relative, file);
49
+ }
50
+ } catch {}
52
51
  }
53
- files.sort();
54
- const transpiler = getSharedTranspiler({ loader: "ts", target: "browser", define: getPublicEnvDefine() }), modules = [];
52
+ return { key: dirs.join("\x00"), files: [...selected.values()].sort() };
53
+ }
54
+ export async function listComposableModules(composablesDir) {
55
+ const { files } = await composableSources(composablesDir), transpiler = getSharedTranspiler({ loader: "ts", target: "browser", define: getPublicEnvDefine() }), modules = [];
55
56
  for (const file of files)
56
57
  try {
57
58
  const code = await Bun.file(file).text(), names = transpiler.scan(code).exports.filter((name) => name !== "default");
@@ -92,21 +93,9 @@ function selectReachable(modules, codeByFile, pageSources) {
92
93
  return selected;
93
94
  }
94
95
  export async function getComposableScript(composablesDir, pageSource, extraSources) {
95
- const resolvedDir = await resolveComposablesDir(composablesDir);
96
+ const { key: resolvedDir, files: composableFiles } = await composableSources(composablesDir);
96
97
  if (!resolvedDir)
97
98
  return null;
98
- const composableFiles = [];
99
- try {
100
- const glob = new Bun.Glob("**/*.ts");
101
- for await (const file of glob.scan({ cwd: resolvedDir, absolute: !0 })) {
102
- if (isSkippedFile(file))
103
- continue;
104
- composableFiles.push(file);
105
- }
106
- } catch {
107
- writeSigned(_cachedComposableScripts, resolvedDir, "", "");
108
- return null;
109
- }
110
99
  const signature = sourceSignature(composableFiles);
111
100
  if (composableFiles.length === 0) {
112
101
  writeSigned(_cachedComposableScripts, resolvedDir, signature, "");
@@ -143,6 +143,7 @@ export {
143
143
  useAsyncData,
144
144
  usePost,
145
145
  clearFetchCache,
146
+ clearServerData,
146
147
  prefetch,
147
148
  type FetchOptions,
148
149
  type FetchRef,
@@ -73,6 +73,7 @@ export {
73
73
  useAsyncData,
74
74
  usePost,
75
75
  clearFetchCache,
76
+ clearServerData,
76
77
  prefetch
77
78
  } from "./use-fetch.js";
78
79
  export {
@@ -1,5 +1,111 @@
1
- import { state } from '../signals-api';
1
+ /**
2
+ * useFetch — reactive data fetching (module-import path).
3
+ *
4
+ * stx ships two `useFetch` implementations:
5
+ *
6
+ * 1. This one (signals-api / module-import path) — used by tests,
7
+ * SSR-side tooling, and any code that imports from `'stx'` or
8
+ * `'@stacksjs/stx/composables'` directly.
9
+ * 2. The runtime template literal inside `packages/stx/src/signals.ts`
10
+ * (search for `function useFetch`), injected into client pages and
11
+ * exposed at `window.stx.useFetch`.
12
+ *
13
+ * Pre-stacksjs/stx#1726 these returned different shapes (composable used
14
+ * a Vue-style `{ get, subscribe, refresh, execute, abort }` ref;
15
+ * runtime returned Signal-shaped `{ data, loading, error, refetch }`).
16
+ * That meant the same code crashed on one path or the other depending
17
+ * on which entry point the bundler resolved. Now both return the
18
+ * Signal shape — `data`, `loading`, `error` are signals; `refetch` is
19
+ * a function. The composable additionally exposes `abort`, `status`,
20
+ * `statusText` and accepts the richer options set (retry, cache,
21
+ * refetchOnFocus, etc.) — these are supersets the runtime doesn't
22
+ * implement, available to module-import consumers only.
23
+ *
24
+ * Parity tests in `test/composables/use-fetch-parity.test.ts` pin the
25
+ * shared shape across both impls; do not change one side without the
26
+ * other.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const { data, loading, error, refetch } = useFetch('/api/users')
31
+ * // data() — current value (null while loading)
32
+ * // loading() — boolean signal
33
+ * // error() — Error | null signal
34
+ * // refetch() — trigger a new request
35
+ * ```
36
+ */
2
37
  import type { Signal } from '../signals-api';
38
+ /** @internal Closure-free: also embedded in the generated browser runtime. */
39
+ export declare function readHydratedData(key?: string, hydrate?: boolean, transform?: (data: any) => unknown): {
40
+ data: unknown;
41
+ error?: Error;
42
+ } | undefined;
43
+ /** Forget a hydration snapshot; existing signals change only on explicit refresh. */
44
+ export declare function clearServerData(key?: string): void;
45
+ export interface FetchOptions<T = unknown> extends Omit<RequestInit, 'body'> {
46
+ /** Request body (will be JSON stringified if object) */
47
+ body?: BodyInit | Record<string, unknown> | null;
48
+ /** Base URL to prepend */
49
+ baseURL?: string;
50
+ /** Query parameters */
51
+ query?: Record<string, string | number | boolean | undefined>;
52
+ /** Fetch immediately on creation (default: true) */
53
+ immediate?: boolean;
54
+ /** Transform response data */
55
+ transform?: (data: unknown) => T;
56
+ /** Custom response parser (default: json) */
57
+ parseResponse?: (response: Response) => Promise<unknown>;
58
+ /** Timeout in milliseconds (default: 30000) */
59
+ timeout?: number;
60
+ /** Retry count on failure (default: 0) */
61
+ retry?: number;
62
+ /** Retry delay in milliseconds (default: 1000) */
63
+ retryDelay?: number;
64
+ /** Cache key for deduplication */
65
+ key?: string;
66
+ /** Reuse matching useServerData data for the initial load (default: true). */
67
+ hydrate?: boolean;
68
+ /** Cache time in milliseconds (0 = no cache) */
69
+ cacheTime?: number;
70
+ /** Refetch on document visibility change (default: false) */
71
+ refetchOnFocus?: boolean;
72
+ /** Refetch interval in milliseconds */
73
+ refetchInterval?: number;
74
+ /** Initial value while loading (matches runtime's `initialData`) */
75
+ initialData?: T | null;
76
+ }
77
+ /** How one run of the request should behave. */
78
+ export interface RefetchOptions {
79
+ /**
80
+ * Refresh without touching `loading` or clearing the current error.
81
+ *
82
+ * A poll refreshes data that is already on screen, so driving the first-load
83
+ * state from it puts a spinner over a populated view on every tick. Bind
84
+ * `isFetching` for a subtle in-flight indicator instead (stacksjs/stx#1929).
85
+ */
86
+ background?: boolean;
87
+ }
88
+ /** Signal-shaped fetch result. Matches the runtime's `useFetch` return. */
89
+ export interface FetchRef<T> {
90
+ /** Current data, or `initialData`/null while loading. */
91
+ data: Signal<T | null>;
92
+ /** True while a first-load request is in flight. A background one leaves it alone. */
93
+ loading: Signal<boolean>;
94
+ /** True while ANY request is in flight, background ones included. */
95
+ isFetching: Signal<boolean>;
96
+ /** The most recent error, or null. */
97
+ error: Signal<Error | null>;
98
+ /** HTTP status code of the most recent response, or null. */
99
+ status: Signal<number | null>;
100
+ /** HTTP status text of the most recent response, or null. */
101
+ statusText: Signal<string | null>;
102
+ /** Trigger a new request. */
103
+ refetch: (_options?: RefetchOptions) => Promise<void>;
104
+ /** Same as refetch — kept for runtime-parity callers. */
105
+ execute: () => Promise<void>;
106
+ /** Abort the in-flight request. */
107
+ abort: () => void;
108
+ }
3
109
  /**
4
110
  * Reactive fetch with loading/error states. Returns Signal-shaped state.
5
111
  */
@@ -8,52 +114,21 @@ export declare function useFetch<T = unknown>(url: string | (() => string), opti
8
114
  * Generic async data fetcher. Same Signal shape as `useFetch`.
9
115
  */
10
116
  export declare function useAsyncData<T>(fetcher: () => Promise<T>, options?: {
11
- immediate?: boolean
12
- transform?: (data: T) => T
13
- initialData?: T | null
14
- key?: string
15
- cacheTime?: number
16
- }): FetchRef<T>;
117
+ immediate?: boolean;
118
+ transform?: (data: T) => T;
119
+ initialData?: T | null;
120
+ key?: string;
121
+ hydrate?: boolean;
122
+ cacheTime?: number;
123
+ }): FetchRef<T>;
17
124
  /**
18
125
  * POST request helper. Returns the fetch state plus an execute(body) helper.
19
126
  */
20
127
  export declare function usePost<T = unknown, B = unknown>(url: string, options?: Omit<FetchOptions<T>, 'method' | 'body'>): {
21
- execute: (body?: B) => Promise<T | null>
22
- state: FetchRef<T>
23
- };
128
+ execute: (body?: B) => Promise<T | null>;
129
+ state: FetchRef<T>;
130
+ };
24
131
  /** Clear fetch cache (one key or all). */
25
132
  export declare function clearFetchCache(key?: string): void;
26
133
  /** Prefetch data into cache. */
27
134
  export declare function prefetch<T>(url: string, options?: FetchOptions<T>): Promise<void>;
28
- export declare interface FetchOptions<T = unknown> extends Omit<RequestInit, 'body'> {
29
- body?: BodyInit | Record<string, unknown> | null
30
- baseURL?: string
31
- query?: Record<string, string | number | boolean | undefined>
32
- immediate?: boolean
33
- transform?: (data: unknown) => T
34
- parseResponse?: (response: Response) => Promise<unknown>
35
- timeout?: number
36
- retry?: number
37
- retryDelay?: number
38
- key?: string
39
- cacheTime?: number
40
- refetchOnFocus?: boolean
41
- refetchInterval?: number
42
- initialData?: T | null
43
- }
44
- /** How one run of the request should behave. */
45
- export declare interface RefetchOptions {
46
- background?: boolean
47
- }
48
- /** Signal-shaped fetch result. Matches the runtime's `useFetch` return. */
49
- export declare interface FetchRef<T> {
50
- data: Signal<T | null>
51
- loading: Signal<boolean>
52
- isFetching: Signal<boolean>
53
- error: Signal<Error | null>
54
- status: Signal<number | null>
55
- statusText: Signal<string | null>
56
- refetch: (_options?: RefetchOptions) => Promise<void>
57
- execute: () => Promise<void>
58
- abort: () => void
59
- }
@@ -1,4 +1,44 @@
1
1
  import { state } from "../signals-api.js";
2
+ export function readHydratedData(key, hydrate = !0, transform) {
3
+ if (!hydrate || !key || typeof window > "u")
4
+ return;
5
+ const host = window;
6
+ if (!host.__STX_DATA__) {
7
+ const tag = document.querySelector("script[data-stx-server-data]");
8
+ try {
9
+ const parsed = JSON.parse(tag?.textContent || "{}");
10
+ host.__STX_DATA__ = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
11
+ } catch {
12
+ host.__STX_DATA__ = {};
13
+ }
14
+ }
15
+ const values = host.__STX_DATA__;
16
+ if (values && Object.prototype.hasOwnProperty.call(values, key))
17
+ try {
18
+ return { data: transform ? transform(values[key]) : values[key] };
19
+ } catch (error) {
20
+ return { data: null, error: error instanceof Error ? error : Error(String(error)) };
21
+ }
22
+ return;
23
+ }
24
+ export function clearServerData(key) {
25
+ if (typeof window > "u")
26
+ return;
27
+ const host = window;
28
+ if (key === void 0)
29
+ host.__STX_DATA__ = {};
30
+ else {
31
+ if (!host.__STX_DATA__)
32
+ try {
33
+ const parsed = JSON.parse(document.querySelector("script[data-stx-server-data]")?.textContent || "{}");
34
+ host.__STX_DATA__ = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
35
+ } catch {
36
+ host.__STX_DATA__ = {};
37
+ }
38
+ if (host.__STX_DATA__)
39
+ delete host.__STX_DATA__[key];
40
+ }
41
+ }
2
42
  const fetchCache = new Map;
3
43
  function buildURL(url, baseURL, query) {
4
44
  let fullURL = baseURL ? `${baseURL.replace(/\/$/, "")}/${url.replace(/^\//, "")}` : url;
@@ -22,6 +62,7 @@ export function useFetch(url, options = {}) {
22
62
  retry = 0,
23
63
  retryDelay = 1000,
24
64
  key,
65
+ hydrate = !0,
25
66
  cacheTime = 0,
26
67
  refetchOnFocus = !1,
27
68
  refetchInterval,
@@ -30,7 +71,7 @@ export function useFetch(url, options = {}) {
30
71
  query,
31
72
  body,
32
73
  ...fetchOptions
33
- } = options, data = state(initialData), loading = state(!1), isFetching = state(!1), error = state(null), status = state(null), statusText = state(null);
74
+ } = options, hydrated = readHydratedData(key, hydrate, transform), hydratedValue = hydrated ? hydrated.data : initialData, data = state(hydratedValue), loading = state(!1), isFetching = state(!1), error = state(hydrated?.error ?? null), status = state(null), statusText = state(null);
34
75
  let abortController = null, focusHandler = null, intervalId = null;
35
76
  const getURL = () => {
36
77
  const rawURL = typeof url === "function" ? url() : url;
@@ -149,7 +190,8 @@ export function useFetch(url, options = {}) {
149
190
  intervalId = setInterval(() => void doFetch(0, !0), refetchInterval);
150
191
  };
151
192
  if (immediate) {
152
- doFetch();
193
+ if (!hydrated)
194
+ doFetch();
153
195
  setupRefetchOnFocus();
154
196
  setupRefetchInterval();
155
197
  }
@@ -186,8 +228,9 @@ export function useAsyncData(fetcher, options = {}) {
186
228
  transform,
187
229
  initialData = null,
188
230
  key,
231
+ hydrate = !0,
189
232
  cacheTime = 0
190
- } = options, data = state(initialData), loading = state(!1), isFetching = state(!1), error = state(null), status = state(null), statusText = state(null), getCacheKey = () => key || fetcher.toString(), getFromCache = () => {
233
+ } = options, hydrated = readHydratedData(key, hydrate, transform), hydratedValue = hydrated ? hydrated.data : initialData, data = state(hydratedValue), loading = state(!1), isFetching = state(!1), error = state(hydrated?.error ?? null), status = state(null), statusText = state(null), getCacheKey = () => key || fetcher.toString(), getFromCache = () => {
191
234
  if (cacheTime <= 0)
192
235
  return null;
193
236
  const cached = fetchCache.get(getCacheKey());
@@ -229,7 +272,7 @@ export function useAsyncData(fetcher, options = {}) {
229
272
  isFetching.set(!1);
230
273
  }
231
274
  };
232
- if (immediate)
275
+ if (immediate && !hydrated)
233
276
  doFetch();
234
277
  return {
235
278
  data,