@stacksjs/actions 0.70.86 → 0.70.88

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 (284) hide show
  1. package/package.json +16 -16
  2. package/dist/action.d.ts +0 -149
  3. package/dist/action.js +0 -2
  4. package/dist/actions.d.ts +0 -2
  5. package/dist/actions.js +0 -2
  6. package/dist/add.d.ts +0 -6
  7. package/dist/add.js +0 -2
  8. package/dist/ai/request-model-access.d.ts +0 -1
  9. package/dist/ai/request-model-access.js +0 -2
  10. package/dist/auth/client.d.ts +0 -1
  11. package/dist/auth/client.js +0 -3
  12. package/dist/auth/prune.d.ts +0 -1
  13. package/dist/auth/prune.js +0 -2
  14. package/dist/auth/setup.d.ts +0 -1
  15. package/dist/auth/setup.js +0 -206
  16. package/dist/auth/token.d.ts +0 -1
  17. package/dist/auth/token.js +0 -2
  18. package/dist/blog.d.ts +0 -19
  19. package/dist/blog.js +0 -148
  20. package/dist/build/cli.d.ts +0 -1
  21. package/dist/build/cli.js +0 -2
  22. package/dist/build/component-libs.d.ts +0 -1
  23. package/dist/build/component-libs.js +0 -2
  24. package/dist/build/core.d.ts +0 -1
  25. package/dist/build/core.js +0 -2
  26. package/dist/build/desktop.d.ts +0 -1
  27. package/dist/build/desktop.js +0 -2
  28. package/dist/build/docs.d.ts +0 -1
  29. package/dist/build/docs.js +0 -2
  30. package/dist/build/frontend-static.d.ts +0 -16
  31. package/dist/build/frontend-static.js +0 -9
  32. package/dist/build/server.d.ts +0 -1
  33. package/dist/build/server.js +0 -2
  34. package/dist/build/stacks.d.ts +0 -1
  35. package/dist/build/stacks.js +0 -2
  36. package/dist/build/views.d.ts +0 -1
  37. package/dist/build/views.js +0 -2
  38. package/dist/build.d.ts +0 -9
  39. package/dist/build.js +0 -2
  40. package/dist/bump.d.ts +0 -1
  41. package/dist/bump.js +0 -8
  42. package/dist/cdn/invalidate-cache.d.ts +0 -1
  43. package/dist/cdn/invalidate-cache.js +0 -1
  44. package/dist/changelog.d.ts +0 -9
  45. package/dist/changelog.js +0 -3
  46. package/dist/check/ports.d.ts +0 -1
  47. package/dist/check/ports.js +0 -2
  48. package/dist/chunk-0c8sd1t6.js +0 -2
  49. package/dist/chunk-0g2nzhx9.js +0 -240
  50. package/dist/chunk-0gadhvn7.js +0 -3
  51. package/dist/chunk-0h27aa4r.js +0 -93
  52. package/dist/chunk-3peh8kqs.js +0 -851
  53. package/dist/chunk-62gdfav8.js +0 -3
  54. package/dist/chunk-6bk53y02.js +0 -3
  55. package/dist/chunk-78c5n3s2.js +0 -3
  56. package/dist/chunk-c74qv38e.js +0 -17
  57. package/dist/chunk-cdk2r2jd.js +0 -1
  58. package/dist/chunk-dbz9dp2h.js +0 -3
  59. package/dist/chunk-e142dheq.js +0 -3
  60. package/dist/chunk-ec4gky40.js +0 -3
  61. package/dist/chunk-h3d81wrg.js +0 -3
  62. package/dist/chunk-m3q0x4h0.js +0 -688
  63. package/dist/chunk-mqgbyhph.js +0 -5
  64. package/dist/chunk-n24m8prb.js +0 -3
  65. package/dist/chunk-n5eqwhck.js +0 -7
  66. package/dist/chunk-nsvnqv8y.js +0 -5
  67. package/dist/chunk-nty6mmx4.js +0 -283
  68. package/dist/chunk-s735m9mg.js +0 -1
  69. package/dist/chunk-tpb8jgsk.js +0 -7
  70. package/dist/chunk-tsbk5vne.js +0 -3
  71. package/dist/chunk-xg9xscqz.js +0 -1
  72. package/dist/chunk-y6e448he.js +0 -7
  73. package/dist/clean.d.ts +0 -1
  74. package/dist/clean.js +0 -2
  75. package/dist/commit.d.ts +0 -3
  76. package/dist/commit.js +0 -2
  77. package/dist/copy-types.d.ts +0 -1
  78. package/dist/copy-types.js +0 -3
  79. package/dist/database/seed.d.ts +0 -1
  80. package/dist/database/seed.js +0 -2
  81. package/dist/deploy/create-receipt-rule.d.ts +0 -1
  82. package/dist/deploy/create-receipt-rule.js +0 -2
  83. package/dist/deploy/index.d.ts +0 -1
  84. package/dist/deploy/index.js +0 -300
  85. package/dist/dev/api.d.ts +0 -1
  86. package/dist/dev/api.js +0 -6
  87. package/dist/dev/components.d.ts +0 -1
  88. package/dist/dev/components.js +0 -2
  89. package/dist/dev/dashboard-globals.d.ts +0 -4
  90. package/dist/dev/dashboard-globals.js +0 -3
  91. package/dist/dev/dashboard-utils.d.ts +0 -150
  92. package/dist/dev/dashboard-utils.js +0 -2
  93. package/dist/dev/dashboard.d.ts +0 -22
  94. package/dist/dev/dashboard.js +0 -8
  95. package/dist/dev/desktop.d.ts +0 -1
  96. package/dist/dev/desktop.js +0 -2
  97. package/dist/dev/docs.d.ts +0 -1
  98. package/dist/dev/docs.js +0 -2
  99. package/dist/dev/index.d.ts +0 -10
  100. package/dist/dev/index.js +0 -2
  101. package/dist/dev/migrate-watcher.d.ts +0 -1
  102. package/dist/dev/migrate-watcher.js +0 -2
  103. package/dist/dev/system-tray.d.ts +0 -1
  104. package/dist/dev/system-tray.js +0 -2
  105. package/dist/dev/views.d.ts +0 -1
  106. package/dist/dev/views.js +0 -2
  107. package/dist/discover-packages.d.ts +0 -18
  108. package/dist/discover-packages.js +0 -2
  109. package/dist/domains/add.d.ts +0 -1
  110. package/dist/domains/add.js +0 -2
  111. package/dist/domains/purchase.d.ts +0 -1
  112. package/dist/domains/purchase.js +0 -2
  113. package/dist/domains/remove.d.ts +0 -1
  114. package/dist/domains/remove.js +0 -2
  115. package/dist/examples.d.ts +0 -5
  116. package/dist/examples.js +0 -2
  117. package/dist/find-projects.d.ts +0 -1
  118. package/dist/find-projects.js +0 -2
  119. package/dist/fresh.d.ts +0 -1
  120. package/dist/fresh.js +0 -2
  121. package/dist/generate/action-types.d.ts +0 -1
  122. package/dist/generate/action-types.js +0 -8
  123. package/dist/generate/component-meta.d.ts +0 -1
  124. package/dist/generate/component-meta.js +0 -3
  125. package/dist/generate/custom-cli-file.d.ts +0 -1
  126. package/dist/generate/custom-cli-file.js +0 -4
  127. package/dist/generate/env-files.d.ts +0 -1
  128. package/dist/generate/env-files.js +0 -26
  129. package/dist/generate/ide-helpers.d.ts +0 -1
  130. package/dist/generate/ide-helpers.js +0 -3
  131. package/dist/generate/index.d.ts +0 -36
  132. package/dist/generate/index.js +0 -2
  133. package/dist/generate/lib-entries.d.ts +0 -1
  134. package/dist/generate/lib-entries.js +0 -3
  135. package/dist/generate/pantry-file.d.ts +0 -1
  136. package/dist/generate/pantry-file.js +0 -2
  137. package/dist/generate/symlink-core.d.ts +0 -1
  138. package/dist/generate/symlink-core.js +0 -2
  139. package/dist/generate/types.d.ts +0 -1
  140. package/dist/generate/types.js +0 -2
  141. package/dist/generate/vscode-custom-data.d.ts +0 -1
  142. package/dist/generate/vscode-custom-data.js +0 -3
  143. package/dist/generate/web-types.d.ts +0 -1
  144. package/dist/generate/web-types.js +0 -1
  145. package/dist/helpers/component-meta.d.ts +0 -26
  146. package/dist/helpers/component-meta.js +0 -2
  147. package/dist/helpers/index.d.ts +0 -4
  148. package/dist/helpers/index.js +0 -2
  149. package/dist/helpers/lib-entries.d.ts +0 -12
  150. package/dist/helpers/lib-entries.js +0 -2
  151. package/dist/helpers/package-json.d.ts +0 -2
  152. package/dist/helpers/package-json.js +0 -43
  153. package/dist/helpers/utils.d.ts +0 -23
  154. package/dist/helpers/utils.js +0 -2
  155. package/dist/helpers/vscode-custom-data.d.ts +0 -3
  156. package/dist/helpers/vscode-custom-data.js +0 -2
  157. package/dist/index.d.ts +0 -49
  158. package/dist/index.js +0 -2
  159. package/dist/key-generate.d.ts +0 -1
  160. package/dist/key-generate.js +0 -2
  161. package/dist/lint/fix.d.ts +0 -1
  162. package/dist/lint/fix.js +0 -3
  163. package/dist/lint/index.d.ts +0 -1
  164. package/dist/lint/index.js +0 -3
  165. package/dist/lint/lint.d.ts +0 -14
  166. package/dist/lint/lint.js +0 -2
  167. package/dist/make-command.d.ts +0 -10
  168. package/dist/make-command.js +0 -45
  169. package/dist/make-job.d.ts +0 -5
  170. package/dist/make-job.js +0 -129
  171. package/dist/make-policy.d.ts +0 -10
  172. package/dist/make-policy.js +0 -94
  173. package/dist/make-resource.d.ts +0 -10
  174. package/dist/make-resource.js +0 -113
  175. package/dist/make.d.ts +0 -52
  176. package/dist/make.js +0 -2
  177. package/dist/migrate/database.d.ts +0 -1
  178. package/dist/migrate/database.js +0 -2
  179. package/dist/migrate/fresh.d.ts +0 -1
  180. package/dist/migrate/fresh.js +0 -2
  181. package/dist/orm/base.d.ts +0 -1
  182. package/dist/orm/base.js +0 -2
  183. package/dist/orm/test.d.ts +0 -1
  184. package/dist/orm/test.js +0 -1
  185. package/dist/prepublish.d.ts +0 -1
  186. package/dist/prepublish.js +0 -2
  187. package/dist/queue/clear.d.ts +0 -1
  188. package/dist/queue/clear.js +0 -2
  189. package/dist/queue/dlq-purge.d.ts +0 -1
  190. package/dist/queue/dlq-purge.js +0 -2
  191. package/dist/queue/dlq-retry.d.ts +0 -1
  192. package/dist/queue/dlq-retry.js +0 -2
  193. package/dist/queue/dlq.d.ts +0 -1
  194. package/dist/queue/dlq.js +0 -5
  195. package/dist/queue/failed.d.ts +0 -1
  196. package/dist/queue/failed.js +0 -5
  197. package/dist/queue/flush.d.ts +0 -1
  198. package/dist/queue/flush.js +0 -3
  199. package/dist/queue/inspect.d.ts +0 -1
  200. package/dist/queue/inspect.js +0 -8
  201. package/dist/queue/list.d.ts +0 -1
  202. package/dist/queue/list.js +0 -5
  203. package/dist/queue/monitor.d.ts +0 -1
  204. package/dist/queue/monitor.js +0 -7
  205. package/dist/queue/pause.d.ts +0 -1
  206. package/dist/queue/pause.js +0 -2
  207. package/dist/queue/quarantine.d.ts +0 -1
  208. package/dist/queue/quarantine.js +0 -3
  209. package/dist/queue/resume.d.ts +0 -1
  210. package/dist/queue/resume.js +0 -2
  211. package/dist/queue/retry.d.ts +0 -1
  212. package/dist/queue/retry.js +0 -2
  213. package/dist/queue/schedule-list.d.ts +0 -1
  214. package/dist/queue/schedule-list.js +0 -5
  215. package/dist/queue/schedule.d.ts +0 -1
  216. package/dist/queue/schedule.js +0 -2
  217. package/dist/queue/status.d.ts +0 -1
  218. package/dist/queue/status.js +0 -5
  219. package/dist/queue/table.d.ts +0 -1
  220. package/dist/queue/table.js +0 -2
  221. package/dist/queue/unquarantine.d.ts +0 -1
  222. package/dist/queue/unquarantine.js +0 -2
  223. package/dist/queue/work.d.ts +0 -1
  224. package/dist/queue/work.js +0 -2
  225. package/dist/release.d.ts +0 -1
  226. package/dist/release.js +0 -3
  227. package/dist/route/list.d.ts +0 -1
  228. package/dist/route/list.js +0 -3
  229. package/dist/run-action.d.ts +0 -2
  230. package/dist/run-action.js +0 -2
  231. package/dist/saas/setup.d.ts +0 -1
  232. package/dist/saas/setup.js +0 -2
  233. package/dist/scaffold-crud.d.ts +0 -25
  234. package/dist/scaffold-crud.js +0 -87
  235. package/dist/schedule/run.d.ts +0 -1
  236. package/dist/schedule/run.js +0 -2
  237. package/dist/search/flush.d.ts +0 -1
  238. package/dist/search/flush.js +0 -2
  239. package/dist/search/import.d.ts +0 -1
  240. package/dist/search/import.js +0 -2
  241. package/dist/search/settings-list.d.ts +0 -1
  242. package/dist/search/settings-list.js +0 -2
  243. package/dist/search/settings.d.ts +0 -1
  244. package/dist/search/settings.js +0 -2
  245. package/dist/serve/api.d.ts +0 -1
  246. package/dist/serve/api.js +0 -2
  247. package/dist/setup/index.d.ts +0 -1
  248. package/dist/setup/index.js +0 -2
  249. package/dist/setup/ssl.d.ts +0 -38
  250. package/dist/setup/ssl.js +0 -2
  251. package/dist/stacks.d.ts +0 -4
  252. package/dist/stacks.js +0 -2
  253. package/dist/templates.d.ts +0 -28
  254. package/dist/templates.js +0 -2
  255. package/dist/test/feature.d.ts +0 -1
  256. package/dist/test/feature.js +0 -2
  257. package/dist/test/index.d.ts +0 -1
  258. package/dist/test/index.js +0 -2
  259. package/dist/test/ui.d.ts +0 -1
  260. package/dist/test/ui.js +0 -2
  261. package/dist/test/unit.d.ts +0 -1
  262. package/dist/test/unit.js +0 -2
  263. package/dist/typecheck.d.ts +0 -1
  264. package/dist/typecheck.js +0 -2
  265. package/dist/types.d.ts +0 -3
  266. package/dist/types.js +0 -2
  267. package/dist/upgrade/binary.d.ts +0 -1
  268. package/dist/upgrade/binary.js +0 -2
  269. package/dist/upgrade/bun.d.ts +0 -1
  270. package/dist/upgrade/bun.js +0 -1
  271. package/dist/upgrade/dependencies.d.ts +0 -1
  272. package/dist/upgrade/dependencies.js +0 -2
  273. package/dist/upgrade/framework-utils.d.ts +0 -150
  274. package/dist/upgrade/framework-utils.js +0 -2
  275. package/dist/upgrade/framework.d.ts +0 -1
  276. package/dist/upgrade/framework.js +0 -7
  277. package/dist/upgrade/index.d.ts +0 -1
  278. package/dist/upgrade/index.js +0 -2
  279. package/dist/upgrade/packages.d.ts +0 -14
  280. package/dist/upgrade/packages.js +0 -12
  281. package/dist/upgrade/shell.d.ts +0 -1
  282. package/dist/upgrade/shell.js +0 -5
  283. package/dist/upgrade.d.ts +0 -7
  284. package/dist/upgrade.js +0 -2
@@ -1,851 +0,0 @@
1
- // @bun
2
- import{a as b,b as v}from"./chunk-dbz9dp2h.js";import"./chunk-xg9xscqz.js";import"./chunk-h3d81wrg.js";import T from"fs";import $ from"path";import _ from"fs";import G from"path";import q from"path";import x from"fs";import L from"path";import N from"fs";import C from"path";function w(I,B){let J=["// Auto-generated by STX - do not edit",'declare module "stx/routes" {'," interface RouteMap {"];for(let K of I){let O=[];for(let V of K.params){let Y=K.pattern.includes(`:${V}*`)?"string[]":"string";O.push(`${V}: ${Y}`)}let W=O.join("; ");J.push(` '${K.pattern}': { ${W} }`)}J.push(" }","}",""),_.mkdirSync(B,{recursive:!0}),_.writeFileSync(G.join(B,"route-types.d.ts"),J.join(`
3
- `))}function D(I,B,J){let K=process.cwd(),O=G.relative(K,J),W=["components","layouts","partials"],V=I.filter((X)=>!W.some((Z)=>X.pattern.startsWith(`/${Z}/`)||X.pattern===`/${Z}`)),Y=["// Auto-generated by stx \u2014 do not edit",`// Source: ${O||"pages"}/`,"","export const routes = ["];for(let X of V){let Z=G.relative(K,X.filePath).replace(/\\/g,"/"),z=JSON.stringify(X.params),j=X.layout?`, layout: '${G.relative(K,X.layout).replace(/\\/g,"/")}'`:"";Y.push(` { pattern: '${X.pattern}', filePath: '${Z}', isDynamic: ${X.isDynamic}, params: ${z}${j} },`)}Y.push("] as const",""),Y.push("export type RouteName = typeof routes[number]['pattern']",""),_.mkdirSync(B,{recursive:!0}),_.writeFileSync(G.join(B,"routes.ts"),Y.join(`
4
- `))}function P(I,B){let K=q.relative(B,I).replace(/\.(stx|md)$/,"");if(K=K.split(q.sep).join("/"),K==="index")return"/";if(K.endsWith("/index"))K=K.slice(0,-6);return K=K.replace(/\[\[([^\]]+)\]\]/g,":$1?"),K=K.replace(/\[([^\]]+)\]/g,":$1"),K=K.replace(/:\.\.\.([^/]+)/g,":$1*"),`/${K}`}function k(I){let B=[],J=I.replace(/[.+^${}()|[\]\\]/g,"\\$&");return J=J.replace(/\/:([^/]+)\?/g,(K,O)=>{return B.push(O),"(?:/([^/]+))?"}),J=J.replace(/:([^/]+)\*/g,(K,O)=>{return B.push(O),"(.+)"}),J=J.replace(/:([^/]+)/g,(K,O)=>{return B.push(O),"([^/]+)"}),J=`^${J}$`,{regex:new RegExp(J),params:B}}function o(I,B){let J=I===""?"/":I;for(let K of B){let O=J.match(K.regex);if(O){let W={};return K.params.forEach((V,Y)=>{W[V]=O[Y+1]}),{route:K,params:W}}}return null}function y(I,B){let J=[],K=L.dirname(I);while(K.startsWith(B)||K===B){let O=L.join(K,"_layout.stx");if(x.existsSync(O))J.unshift(O);if(K===B)break;K=L.dirname(K)}return J}function R(I,B){let J=[];if(!T.existsSync(I))return J;let K=T.readdirSync(I,{withFileTypes:!0});for(let O of K){let W=$.join(I,O.name);if(O.isDirectory()){if(O.name.startsWith("."))continue;J.push(...R(W,B))}else if(O.isFile()){let V=$.extname(O.name);if(B.includes(V)){if(O.name.startsWith("_")&&O.name!=="_layout.stx")continue;if(O.name==="_layout.stx")continue;J.push(W)}}}return J}class S{routes;pagesDir;pagesDirs;config;constructor(I,B={}){this.config=B;let J=B.pagesDirs&&B.pagesDirs.length>0?B.pagesDirs:[B.pagesDir||"pages"];this.pagesDirs=J.map((V)=>$.resolve(I,V)),this.pagesDir=this.pagesDirs[0];let K=B.extensions||[".stx"],O=new Set;this.routes=[];for(let V of this.pagesDirs){let Y=R(V,K);for(let X of Y){let Z=P(X,V);if(O.has(Z))continue;O.add(Z);let{regex:z,params:j}=k(Z),F=B.layouts!==!1?y(X,V):[];this.routes.push({pattern:Z,regex:z,params:j,filePath:X,isDynamic:j.length>0,layout:F.length>0?F[F.length-1]:void 0})}}this.routes.sort((V,Y)=>{if(!V.isDynamic&&Y.isDynamic)return-1;if(V.isDynamic&&!Y.isDynamic)return 1;let X=V.pattern.split("/").length,Z=Y.pattern.split("/").length;if(X!==Z)return Z-X;return V.pattern.localeCompare(Y.pattern)});let W=$.join(I,".stx");w(this.routes,W),D(this.routes,W,this.pagesDir)}match(I){let B=I===""?"/":I;for(let J of this.routes){let K=B.match(J.regex);if(K){let O={};return J.params.forEach((W,V)=>{O[W]=K[V+1]}),{route:J,params:O}}}return null}resolve(I,B){let J=this.routes.find((O)=>O.pattern===I||O.filePath.includes(I));if(!J)return"#not-found";let K=J.pattern;if(B)for(let[O,W]of Object.entries(B))K=K.replace(`:${O}`,encodeURIComponent(W));return K}addRoute(I){this.routes.push(I),this.routes.sort((B,J)=>{if(!B.isDynamic&&J.isDynamic)return-1;if(B.isDynamic&&!J.isDynamic)return 1;return B.pattern.localeCompare(J.pattern)})}getLayout(I){return I.layout??null}}function a(I,B){return new S(I,B)}function e(I,B){let J=[`${B}.stx`,"error.stx"];for(let K of J){let O=$.join(I,K);if(T.existsSync(O))return O}return null}function BB(I,B){return I.map((J)=>{let K=$.relative(B,J.filePath),O=J.isDynamic?" (dynamic)":"";return`${J.pattern} \u2192 ${K}${O}`})}var A={},E="";function IB(I){E=I.replace(/\/$/,"")}function JB(I,B,J={}){A[I]={path:B,name:I,params:J}}function KB(I){for(let[B,J]of Object.entries(I))if(typeof J==="string")A[B]={path:J,name:B};else A[B]={...J,name:B}}function OB(I,B={},J=!1){let K=A[I];if(!K)return console.warn(`Route [${I}] not defined.`),"#undefined-route";let O={...K.params,...B},W=K.path;W=W.replace(/:(\w+)/g,(Y,X)=>{let Z=O[X];if(Z===void 0)return console.warn(`Missing parameter [${X}] for route [${I}].`),`:${X}`;return delete O[X],encodeURIComponent(String(Z))});let V=Object.entries(O);if(V.length>0){let Y=V.map(([X,Z])=>`${encodeURIComponent(X)}=${encodeURIComponent(String(Z))}`).join("&");W+=(W.includes("?")?"&":"?")+Y}return J&&E?`${E}${W}`:W}function VB(){for(let I of Object.keys(A))delete A[I];E=""}function YB(I,B={}){return{type:"redirect",path:I,options:{replace:B.replace??!1,external:B.external??!1,redirectCode:B.redirectCode??302}}}function ZB(I){return{type:"abort",error:typeof I==="string"?{statusCode:500,message:I}:I}}function $B(I,B={}){return{handler:I,mode:B.mode??"universal"}}function H(I){let B={};if(!I)return B;let J=I.split(";");for(let K of J){let[O,...W]=K.split("=");if(O){let V=O.trim(),Y=W.join("=").trim();if(V)B[V]=decodeURIComponent(Y)}}return B}function U(I,B,J={}){let K=`${encodeURIComponent(I)}=${encodeURIComponent(B)}`;if(J.expires){let O=typeof J.expires==="number"?new Date(Date.now()+J.expires*1000):J.expires;K+=`; Expires=${O.toUTCString()}`}if(J.path)K+=`; Path=${J.path}`;if(J.domain)K+=`; Domain=${J.domain}`;if(J.secure)K+="; Secure";if(J.httpOnly)K+="; HttpOnly";if(J.sameSite)K+=`; SameSite=${J.sameSite}`;return K}function f(I,B){let J=I.headers.get("cookie")||"",K=H(J);return{get(O){return K[O]},set(O,W,V={}){K[O]=W,B.append("Set-Cookie",U(O,W,V))},delete(O){delete K[O],B.append("Set-Cookie",U(O,"",{expires:new Date(0),path:"/"}))},getAll(){return{...K}}}}function g(){return{get(I){if(typeof document>"u")return;return H(document.cookie)[I]},set(I,B,J={}){if(typeof document>"u")return;document.cookie=U(I,B,J)},delete(I){if(typeof document>"u")return;document.cookie=U(I,"",{expires:new Date(0),path:"/"})},getAll(){if(typeof document>"u")return{};return H(document.cookie)}}}function h(){let I=typeof window<"u"&&typeof window.localStorage<"u";return{get(B){if(!I)return null;try{return window.localStorage.getItem(B)}catch{return null}},set(B,J){if(!I)return;try{window.localStorage.setItem(B,J)}catch{}},remove(B){if(!I)return;try{window.localStorage.removeItem(B)}catch{}},isAvailable(){return I}}}var Q=new Map;function M(I,B){Q.set(I,B)}function c(I){return Q.get(I)}function AB(I){return Q.has(I)}function GB(){Q.clear()}function QB(){return Array.from(Q.keys())}async function jB(I,B="middleware"){let J=C.resolve(I,B);if(!N.existsSync(J))return;let K=N.readdirSync(J);for(let O of K){if(!O.endsWith(".ts")&&!O.endsWith(".js"))continue;if(O.includes(".test.")||O.includes(".spec."))continue;let W=O.replace(/\.(ts|js)$/,""),V=C.join(J,O);try{let X=(await import(V)).default;if(X&&typeof X.handler==="function")M(W,X);else if(typeof X==="function")M(W,{handler:X,mode:"universal"})}catch(Y){console.warn(`Failed to load middleware '${W}' from ${V}:`,Y)}}}function d(I){let B={};if(!I)return B;let J=new URLSearchParams(I);for(let[K,O]of J)B[K]=O;return B}function _B(I,B,J,K=""){return{path:I,params:B,query:d(K),fullPath:K?`${I}?${K}`:I,meta:J}}function EB(I,B,J){let K=typeof window>"u",O=!K,W=new Headers;return{to:I,from:B,isClient:O,isServer:K,cookies:K&&J?f(J,W):g(),storage:h(),state:{},request:J,responseHeaders:W}}async function UB(I,B){let J=Array.isArray(I)?I:[I],K=B.isServer;for(let O of J){let W=c(O);if(!W){console.warn(`Middleware '${O}' not found`);continue}if(W.mode==="server"&&!K)continue;if(W.mode==="client"&&K)continue;try{let V=await W.handler(B);if(V){if(V.type==="redirect")return{passed:!1,redirect:V,state:B.state,responseHeaders:B.responseHeaders};if(V.type==="abort")return{passed:!1,abort:V,state:B.state,responseHeaders:B.responseHeaders}}}catch(V){return console.error(`Error in middleware '${O}':`,V),{passed:!1,abort:{type:"abort",error:{statusCode:500,message:V instanceof Error?V.message:"Middleware error"}},state:B.state,responseHeaders:B.responseHeaders}}}return{passed:!0,state:B.state,responseHeaders:B.responseHeaders}}function zB(){return`
5
- ;(function(){
6
- 'use strict';
7
- var ROUTER_REV=3;
8
- if(window.__stxRouter&&window.__stxRouter.__rev===ROUTER_REV)return;
9
-
10
- // \u2500\u2500 Configuration \u2500\u2500
11
- var defaults={container:'main',loadingClass:'stx-navigating',viewTransitions:true,cache:true,scrollToTop:true,prefetch:true,progress:true,progressColor:'#78dce8',progressHeight:'2px',interceptAllLinks:false,prefetchCacheMax:50};
12
- var o=Object.assign({},defaults,window.__stxRouterConfig||{},window.STX_ROUTER_OPTIONS||{});
13
- var containerSel=o.container;
14
- var debug=!!o.debug;
15
- function log(){if(debug&&typeof console!=='undefined'&&console.log)console.log.apply(console,arguments)}
16
- function runViewTransition(callback){
17
- if(!o.viewTransitions||!document.startViewTransition)return false;
18
- try{
19
- var transition=document.startViewTransition(callback);
20
- var onAbort=function(err){log('[router] view transition aborted:',err&&err.message?err.message:err)};
21
- if(transition&&transition.finished&&transition.finished.catch)transition.finished.catch(onAbort);
22
- if(transition&&transition.updateCallbackDone&&transition.updateCallbackDone.catch)transition.updateCallbackDone.catch(onAbort);
23
- return true;
24
- }catch(err){
25
- log('[router] view transition unavailable:',err&&err.message?err.message:err);
26
- return false;
27
- }
28
- }
29
-
30
- // \u2500\u2500 Progress bar (0\u2192100% at top of viewport) \u2500\u2500
31
- // Native loading indicator baked into the router. Starts when navigation
32
- // begins, trickles up to ~90% during fetch, snaps to 100% + fades on
33
- // completion. Opt-out via window.__stxRouterConfig={progress:false}.
34
- var progEl=null;
35
- var progVal=0;
36
- var progTimer=null;
37
- function setProgress(v){
38
- progVal=v<0?0:(v>100?100:v);
39
- if(!progEl)return;
40
- progEl.style.opacity=progVal>0?'1':'0';
41
- progEl.style.transform='scaleX('+(progVal/100)+')';
42
- }
43
- function startProgress(){
44
- if(!o.progress||!progEl)return;
45
- if(progTimer){clearInterval(progTimer);progTimer=null}
46
- setProgress(8);
47
- progTimer=setInterval(function(){
48
- if(progVal>=90)return;
49
- // Asymptotic trickle \u2014 fast at first, slower near 90%
50
- var inc=Math.max(0.4,(90-progVal)*0.08);
51
- setProgress(progVal+inc);
52
- },160);
53
- }
54
- function finishProgress(){
55
- if(!o.progress||!progEl)return;
56
- if(progTimer){clearInterval(progTimer);progTimer=null}
57
- setProgress(100);
58
- // Fade out, then reset. Delays chosen so the "full" state is briefly
59
- // visible before the bar disappears.
60
- setTimeout(function(){
61
- if(!progEl)return;
62
- progEl.style.opacity='0';
63
- setTimeout(function(){progVal=0;if(progEl)progEl.style.transform='scaleX(0)'},260);
64
- },180);
65
- }
66
-
67
- var cache={};
68
- var prefetching={};
69
- var isNavigating=false;
70
-
71
- // LRU bookkeeping for cache/layoutCache/layoutGroupCache. Pre-fix
72
- // (stacksjs/stx#1719) these were plain objects with no eviction, so
73
- // hover-prefetch on a sidebar of 200 internal links retained ~10MB
74
- // of HTML strings for the page's lifetime. cacheOrder is a most-
75
- // recently-used-last list of keys; setCache pushes new entries and
76
- // evicts the oldest when length exceeds o.prefetchCacheMax (default
77
- // 50). touchCache promotes a key on cache-hit. We use a plain array
78
- // rather than a Map to keep the diff localized and the runtime
79
- // hand-minified shape consistent.
80
- var cacheOrder=[];
81
- function setCache(key,html,layout,group){
82
- if(!(key in cache))cacheOrder.push(key);
83
- cache[key]=html;
84
- layoutCache[key]=layout;
85
- layoutGroupCache[key]=group;
86
- while(cacheOrder.length>o.prefetchCacheMax){
87
- var oldest=cacheOrder.shift();
88
- delete cache[oldest];
89
- delete layoutCache[oldest];
90
- delete layoutGroupCache[oldest];
91
- }
92
- }
93
- function touchCache(key){
94
- var i=cacheOrder.indexOf(key);
95
- if(i>=0){cacheOrder.splice(i,1);cacheOrder.push(key)}
96
- }
97
- function evictCache(key){
98
- var i=cacheOrder.indexOf(key);
99
- if(i>=0)cacheOrder.splice(i,1);
100
- delete cache[key];
101
- delete layoutCache[key];
102
- delete layoutGroupCache[key];
103
- }
104
-
105
- // Extract top-level CSS blocks (rules AND @media blocks with nested braces).
106
- // The old regex ([^{}]+{[^{}]*}) silently dropped @media blocks because
107
- // it couldn't handle nested braces \u2014 causing responsive classes (lg:, md:)
108
- // to vanish after SPA navigation.
109
- function extractCssBlocks(css){
110
- var blocks=[];
111
- var i=0;
112
- var len=css.length;
113
- while(i<len){
114
- // Skip whitespace
115
- while(i<len&&(css[i]===' '||css[i]==='\\n'||css[i]==='\\r'||css[i]==='\\t'))i++;
116
- if(i>=len)break;
117
- // Find the start of a block (first {)
118
- var blockStart=i;
119
- var bracePos=css.indexOf('{',i);
120
- if(bracePos===-1)break;
121
- // Walk forward tracking brace depth to find the matching close
122
- var depth=0;
123
- var j=bracePos;
124
- while(j<len){
125
- if(css[j]==='{')depth++;
126
- else if(css[j]==='}'){depth--;if(depth===0){j++;break}}
127
- j++;
128
- }
129
- if(depth!==0)break;
130
- blocks.push(css.slice(blockStart,j).trim());
131
- i=j;
132
- }
133
- return blocks;
134
- }
135
-
136
- function mergeCrosswindCSS(existing,incoming){
137
- var blocks=extractCssBlocks(incoming);
138
- var newBlocks=[];
139
- for(var bi=0;bi<blocks.length;bi++){
140
- if(existing.indexOf(blocks[bi])===-1)newBlocks.push(blocks[bi]);
141
- }
142
- if(newBlocks.length>0)return existing+'\\n'+newBlocks.join('\\n');
143
- return null;
144
- }
145
-
146
- function getContainer(){
147
- return document.querySelector(containerSel)||document.querySelector('[data-stx-content]')||document.querySelector('main');
148
- }
149
-
150
- // \u2500\u2500 Navigation \u2500\u2500
151
- // Layout group detection \u2014 layouts in the same group share a <main> container.
152
- // Only truly different layout groups trigger a full page reload.
153
- var layoutCache={};
154
- var layoutGroupCache={};
155
- // Track executed script hashes to prevent redeclaration errors on navigation.
156
- // Layout-level scripts (theme, nav setup) execute on initial page load and
157
- // should NOT re-execute when navigating to another page with the same layout.
158
- var executedScriptHashes={};
159
- function hashScript(code){
160
- var h=0;for(var i=0;i<code.length;i++){h=((h<<5)-h)+code.charCodeAt(i);h|=0}
161
- return h;
162
- }
163
- // Record scripts from the initial page load
164
- document.querySelectorAll('script').forEach(function(s){
165
- var text=s.textContent||'';
166
- if(text.trim()&&!s.hasAttribute('src'))executedScriptHashes[hashScript(text)]=1;
167
- });
168
- function cacheKey(url){
169
- var u=new URL(url,location.origin);
170
- return u.pathname+u.search;
171
- }
172
- // Keep SPA fetches inside the active locale (/en/... when viewing English).
173
- function withCurrentLocale(href){
174
- var d=window.__stxI18n;
175
- if(d&&typeof d.localizeHref==='function')return d.localizeHref(href);
176
- return href;
177
- }
178
- function defaultLayoutGroup(layout){
179
- if(!layout)return 'app';
180
- var clean=String(layout).replace(/\\\\/g,'/');
181
- var parts=clean.split('/').filter(Boolean);
182
- var idx=parts.lastIndexOf('layouts');
183
- var part=idx>=0?parts[idx+1]:parts[parts.length-1];
184
- return part?part.replace(/\\.stx$/i,''):'app';
185
- }
186
- function getCurrentLayoutGroup(){
187
- var meta=document.querySelector('meta[name="stx-layout-group"]');
188
- if(meta&&meta.getAttribute('content'))return meta.getAttribute('content');
189
- var layout=document.querySelector('meta[name="stx-layout"]');
190
- return defaultLayoutGroup(layout?layout.getAttribute('content'):'');
191
- }
192
- function getDocLayoutGroup(doc,layout){
193
- var meta=doc&&doc.querySelector?doc.querySelector('meta[name="stx-layout-group"]'):null;
194
- return meta&&meta.getAttribute('content')?meta.getAttribute('content'):defaultLayoutGroup(layout||'');
195
- }
196
- function checkLayoutChange(newLayout,targetUrl,newGroup){
197
- var currentLayout=document.querySelector('meta[name="stx-layout"]');
198
- var curLayoutName=currentLayout?currentLayout.getAttribute('content'):'';
199
- var curGroup=getCurrentLayoutGroup();
200
- var nextGroup=newGroup||defaultLayoutGroup(newLayout);
201
- log('[router] layout check: current='+curLayoutName+'('+curGroup+') new='+(newLayout||'')+'('+nextGroup+')');
202
- // Different layout GROUP (e.g. app \u2192 auth): full reload
203
- if(curGroup!==nextGroup){
204
- log('[router] layout group change:',curGroup,'\u2192',nextGroup,'\u2014 full reload to:',targetUrl);
205
- return true;
206
- }
207
- // Same group but different SPECIFIC layout (e.g. layouts/app \u2192 layouts/coach):
208
- // full body swap so nav, sidebar, and other layout-level elements update
209
- if(curLayoutName && newLayout && curLayoutName!==newLayout){
210
- log('[router] layout name change:',curLayoutName,'\u2192',newLayout,'\u2014 full body swap');
211
- return true;
212
- }
213
- return false;
214
- }
215
-
216
- function shouldUseFragmentResponse(){
217
- return containerSel==='main'||containerSel==='[data-stx-content]';
218
- }
219
-
220
- function navigate(url,pushState,force){
221
- // Lang-picker passes force=true with an already-localized path (/en/...).
222
- // Re-localizing would map it back to the *current* locale and no-op.
223
- if(!force) url=withCurrentLocale(url);
224
- log('[router] navigate() called:',url,'isNavigating:',isNavigating);
225
- if(isNavigating)return;
226
- var t=new URL(url,location.origin);
227
-
228
- if(t.origin!==location.origin){location.href=url;return}
229
-
230
- if(t.pathname===location.pathname&&t.hash){
231
- if(pushState!==false)history.pushState({},'',t.href);
232
- var el=document.querySelector(t.hash);
233
- if(el)el.scrollIntoView({behavior:'smooth'});
234
- return;
235
- }
236
-
237
- // Skip if user clicks a link to the page they're already on. We
238
- // deliberately allow popstate (pushState===false) through because
239
- // the browser has already updated location.href to the popped
240
- // entry \u2014 without this allowance, hitting back would early-return
241
- // and the visible page content would be left frozen on the
242
- // forward-navigation page.
243
- if(pushState!==false&&t.href===location.href&&!t.hash&&!force)return;
244
-
245
- isNavigating=true;
246
- document.body.classList.add(o.loadingClass);
247
- startProgress();
248
-
249
- var targetHref=t.href;
250
- var targetPath=cacheKey(url);
251
- var targetHash=t.hash;
252
-
253
- function done(){isNavigating=false;document.body.classList.remove(o.loadingClass);finishProgress()}
254
-
255
- if(o.cache&&cache[targetPath]&&!force){
256
- // Cache hit \u2192 promote in LRU order so this entry survives eviction
257
- // longer than other entries that haven't been touched.
258
- touchCache(targetPath);
259
- if(checkLayoutChange(layoutCache[targetPath],url,layoutGroupCache[targetPath])){
260
- // Layout changed \u2014 fetch full page and do full document swap
261
- log('[router] cache hit but layout changed \u2014 fetching full page');
262
- fetch(url,{headers:{'Accept':'text/html'}}).then(function(r){
263
- if(!r.ok)throw new Error(r.status);
264
- return r.text();
265
- }).then(function(html){
266
- log('[router] full page fetched from cache path, len:',html.length);
267
- swap(html,targetPath,pushState,targetHash);
268
- }).catch(function(err){
269
- console.error('[router] full page fetch error:',err);
270
- location.href=url;
271
- }).finally(done);
272
- return;
273
- }
274
- swap(cache[targetPath],targetPath,pushState,targetHash);
275
- done();
276
- }
277
- else {
278
- if(force&&cache[targetPath])evictCache(targetPath);
279
- // First fetch as fragment (SPA mode) when the configured container is
280
- // the page content. Custom app-shell containers need full documents so
281
- // the router does not inject a <main> fragment into the wrong element.
282
- var wantsFragment=shouldUseFragmentResponse();
283
- fetch(url,{headers:wantsFragment?{'X-STX-Router':'true','Accept':'text/html'}:{'Accept':'text/html'}}).then(function(r){
284
- if(!r.ok)throw new Error(r.status);
285
- var isFragment=wantsFragment&&r.headers.get('X-STX-Fragment')==='true';
286
- var newLayout=r.headers.get('X-STX-Layout')||'';
287
- var newGroup=r.headers.get('X-STX-Layout-Group')||'';
288
- // Layout change? Fetch the FULL page (no X-STX-Router header) and do full document swap
289
- if(isFragment&&checkLayoutChange(newLayout,url,newGroup)){
290
- log('[router] layout change \u2014 fetching full page for document swap');
291
- return fetch(url,{headers:{'Accept':'text/html'}}).then(function(fullRes){
292
- log('[router] full page fetched:',fullRes.status,'ok:',fullRes.ok);
293
- if(!fullRes.ok)throw new Error(fullRes.status);
294
- return fullRes.text().then(function(html){
295
- log('[router] full page html length:',html.length);
296
- return{html:html,isFragment:false,layout:newLayout,layoutGroup:newGroup};
297
- });
298
- });
299
- }
300
- return r.text().then(function(html){return{html:html,isFragment:isFragment,layout:newLayout,layoutGroup:newGroup}});
301
- }).then(function(result){
302
- if(!result)return;
303
- if(result.isFragment)result.html='<!--stx-fragment-->'+result.html;
304
- if(o.cache)setCache(targetPath,result.html,result.layout,result.layoutGroup);
305
- swap(result.html,targetPath,pushState,targetHash);
306
- }).catch(function(err){
307
- console.error('[router] fetch error:',err);
308
- location.href=url;
309
- }).finally(done);
310
- }
311
- }
312
-
313
- function swap(html,url,pushState,hash){
314
- var isFragment=html.indexOf('<!--stx-fragment-->')===0;
315
- if(isFragment)html=html.slice('<!--stx-fragment-->'.length);
316
- var currentContent=getContainer();
317
- log('[router] swap: isFragment='+isFragment+' container='+!!currentContent+' tag='+(currentContent&&currentContent.tagName)+' selector='+containerSel+' htmlLen='+html.length);
318
- if(!currentContent){log('[router] no container \u2014 falling back');location.href=url;return}
319
-
320
- // Fragment mode: server returned just the page content (no document wrapper)
321
- if(isFragment){
322
- if(window.stx&&window.stx._cleanupContainer)window.stx._cleanupContainer(currentContent);
323
- function doFragSwap(){
324
- // Extract scripts from fragment before injecting HTML
325
- var fragScripts=[];
326
- var fragStyles=[];
327
- var fragCrosswindCSS=null;
328
- var cleanFrag=html.replace(new RegExp('<scr'+'ipt\\\\b[^>]*>([\\\\s\\\\S]*?)<\\\\/scr'+'ipt>','gi'),function(m,code){
329
- if(code&&code.trim())fragScripts.push(code);
330
- return '';
331
- });
332
- cleanFrag=cleanFrag.replace(new RegExp('<sty'+'le\\\\b([^>]*)>([\\\\s\\\\S]*?)<\\\\/sty'+'le>','gi'),function(m,attrs,css){
333
- if(attrs.indexOf('data-crosswind')!==-1){
334
- fragCrosswindCSS=css;
335
- }else{
336
- fragStyles.push({attrs:attrs,css:css});
337
- }
338
- return '';
339
- });
340
- // Remove old page styles (not crosswind \u2014 that gets merged)
341
- document.querySelectorAll('style[data-stx-page]').forEach(function(s){s.remove()});
342
- // Merge crosswind CSS from fragment into existing crosswind style
343
- if(fragCrosswindCSS){
344
- var curCrosswind=document.querySelector('head style[data-crosswind]');
345
- if(curCrosswind){
346
- var merged=mergeCrosswindCSS(curCrosswind.textContent||'',fragCrosswindCSS);
347
- if(merged)curCrosswind.textContent=merged;
348
- }else{
349
- var cw=document.createElement('style');
350
- cw.setAttribute('data-crosswind','generated');
351
- cw.textContent=fragCrosswindCSS;
352
- document.head.appendChild(cw);
353
- }
354
- }
355
- // Add new page styles
356
- fragStyles.forEach(function(s){
357
- var el=document.createElement('style');
358
- el.textContent=s.css;
359
- el.setAttribute('data-stx-page','');
360
- document.head.appendChild(el);
361
- });
362
- // Swap content
363
- currentContent.innerHTML=cleanFrag;
364
- // Remove old page scripts
365
- document.querySelectorAll('script[data-stx-page]').forEach(function(s){s.remove()});
366
- if(pushState!==false)history.pushState({},'',url+(hash||''));
367
- updateNav(url);
368
- updateActiveLinks();
369
- if(o.scrollToTop&&!hash)window.scrollTo({top:0,behavior:'instant'});
370
- else if(hash){var el=document.querySelector(hash);if(el)el.scrollIntoView({behavior:'smooth'})}
371
- window.dispatchEvent(new CustomEvent('stx:navigate',{detail:{url:url}}));
372
- // Execute page scripts FIRST \u2014 they define setup functions and set _latestSetup
373
- log('[router] frag scripts:', fragScripts.length);
374
- document.querySelectorAll('script[data-stx-page]').forEach(function(s){s.remove()});
375
- fragScripts.forEach(function(code){
376
- log('[router] exec script len:', code.length, 'has __stx_setup:', code.indexOf('__stx_setup')>-1);
377
- // Skip scripts that were already executed (layout-level partials
378
- // like theme.stx, stores.stx, nav.stx). Their top-level const/let
379
- // declarations would throw "Identifier has already been declared"
380
- // on re-execution. Setup functions (__stx_setup_) must always
381
- // re-execute because each page has its own setup.
382
- var h=hashScript(code);
383
- var isSetup=code.indexOf('__stx_setup_')!==-1;
384
- // Compute isAlreadyScoped first so the dedup check can exempt
385
- // self-contained IIFE scripts. data-stx-scoped scope IIFEs
386
- // (the (function(){ ... })() shape) must re-execute on every
387
- // navigation. They own their own scope and won't collide
388
- // with prior runs, AND _cleanupContainer deleted their
389
- // entry from window.stx._scopes on the way out. Without
390
- // this exemption, navigating away and back leaves the page
391
- // leaf with no scope registered: bindIf/@event never re-bind
392
- // and all :if branches stay visible at once.
393
- // Mirrors the full-doc swap path's runAlways escape below.
394
- var isAlreadyScoped=code.trimStart().charAt(0)==='('||code.trimStart().charAt(0)===';'||code.indexOf('window.stx.mount')>-1;
395
- if(!isSetup&&!isAlreadyScoped&&executedScriptHashes[h]){
396
- log('[router] skipping already-executed script (hash dedup)');
397
- return;
398
- }
399
- executedScriptHashes[h]=1;
400
- var ns=document.createElement('script');
401
- var hasImport=code.indexOf('import ')!==-1;
402
- if(hasImport){
403
- ns.type='module';
404
- }
405
- ns.textContent=(hasImport||isAlreadyScoped)?code:'{'+code+'}';
406
- ns.setAttribute('data-stx-page','');
407
- document.body.appendChild(ns);
408
- });
409
- log('[router] scripts done. _latestSetup:', !!window.stx._latestSetup);
410
- // THEN fire stx:load \u2014 now _latestSetup is set and processElement has the right scope
411
- window.dispatchEvent(new Event('stx:load'));
412
- }
413
- if(runViewTransition(doFragSwap)){}
414
- else{currentContent.style.transition='opacity 0.12s ease-out';currentContent.style.opacity='0';setTimeout(function(){doFragSwap();currentContent.style.opacity='1';setTimeout(function(){currentContent.style.transition=''},150)},120)}
415
- return;
416
- }
417
-
418
- // Full document mode: parse with DOMParser and extract container content
419
- var parser=new DOMParser();
420
- var doc=parser.parseFromString(html,'text/html');
421
- var newContent=doc.querySelector(containerSel)||doc.querySelector('[data-stx-content]')||doc.querySelector('main');
422
- if(!newContent){location.href=url;return}
423
-
424
- // Clean up existing signals/effects
425
- if(window.stx&&window.stx._cleanupContainer){
426
- window.stx._cleanupContainer(currentContent);
427
- }
428
-
429
- function doSwap(){
430
- // \u2500\u2500 Swap <head> styles \u2500\u2500
431
- // Inject new styles FIRST, then remove old to prevent unstyled flash
432
- var keepIds={'stx-view-transitions':1,'stx-r-css':1};
433
- var curStyles=document.querySelectorAll('head style');
434
- var newStyles=doc.querySelectorAll('head style');
435
-
436
- // Merge crosswind styles instead of replacing \u2014 persistent elements
437
- // (nav, footer) outside <main> still need their utility classes
438
- var curCrosswind=document.querySelector('head style[data-crosswind]');
439
- var newCrosswind=null;
440
- newStyles.forEach(function(s){if(s.getAttribute('data-crosswind'))newCrosswind=s});
441
-
442
- if(curCrosswind&&newCrosswind){
443
- var merged=mergeCrosswindCSS(curCrosswind.textContent||'',newCrosswind.textContent||'');
444
- if(merged)curCrosswind.textContent=merged;
445
- }
446
-
447
- var incoming=[];
448
- newStyles.forEach(function(s){
449
- if(!keepIds[s.id]&&!s.getAttribute('data-crosswind')){
450
- var ns=document.createElement('style');
451
- ns.textContent=s.textContent;
452
- ns.setAttribute('data-stx-incoming','');
453
- document.head.appendChild(ns);
454
- incoming.push(ns);
455
- }
456
- });
457
-
458
- // If no existing crosswind but new page has one, add it
459
- if(!curCrosswind&&newCrosswind){
460
- var ns=document.createElement('style');
461
- ns.textContent=newCrosswind.textContent;
462
- ns.setAttribute('data-crosswind',newCrosswind.getAttribute('data-crosswind'));
463
- document.head.appendChild(ns);
464
- }
465
-
466
- // Remove old styles (except persistent ones, crosswind, and incoming)
467
- curStyles.forEach(function(s){
468
- if(!keepIds[s.id]&&!s.hasAttribute('data-stx-incoming')&&!s.hasAttribute('data-crosswind'))s.remove();
469
- });
470
-
471
- incoming.forEach(function(s){s.removeAttribute('data-stx-incoming')});
472
-
473
- // \u2500\u2500 Swap content \u2500\u2500
474
- // For layout changes: swap the entire <body> to replace layout chrome (nav, footer, etc.)
475
- // For same-layout: swap only the container (<main>)
476
- var newBody=doc.querySelector('body');
477
- var isLayoutChange=false;
478
- if(newBody){
479
- var newMeta=doc.querySelector('meta[name="stx-layout"]');
480
- var curMeta=document.querySelector('meta[name="stx-layout"]');
481
- var curLayout=curMeta?curMeta.getAttribute('content'):'';
482
- var newLayout=newMeta?newMeta.getAttribute('content'):'';
483
- var curGroup=getCurrentLayoutGroup();
484
- var newGroup=getDocLayoutGroup(doc,newLayout);
485
- isLayoutChange=curGroup!==newGroup||(curLayout&&newLayout&&curLayout!==newLayout);
486
- }
487
- if(isLayoutChange&&newBody){
488
- log('[router] full body swap for layout change');
489
- // Replace entire body content \u2014 layout chrome and all
490
- var bodyHTML=newBody.innerHTML.replace(new RegExp('<scr'+'ipt\\\\b[^>]*>[\\\\s\\\\S]*?<\\\\/scr'+'ipt\\\\s*>','gi'),'');
491
- document.body.innerHTML=bodyHTML;
492
- // Copy body attributes (class, data-stx, etc.)
493
- Array.from(newBody.attributes).forEach(function(attr){document.body.setAttribute(attr.name,attr.value)});
494
- // Update layout meta tag
495
- var oldMeta=document.querySelector('meta[name="stx-layout"]');
496
- var freshMeta=doc.querySelector('meta[name="stx-layout"]');
497
- if(oldMeta&&freshMeta)oldMeta.setAttribute('content',freshMeta.getAttribute('content')||'');
498
- else if(freshMeta){var m=document.createElement('meta');m.name='stx-layout';m.content=freshMeta.getAttribute('content')||'';document.head.appendChild(m)}
499
- var oldGroupMeta=document.querySelector('meta[name="stx-layout-group"]');
500
- var freshGroupMeta=doc.querySelector('meta[name="stx-layout-group"]');
501
- if(oldGroupMeta&&freshGroupMeta)oldGroupMeta.setAttribute('content',freshGroupMeta.getAttribute('content')||'');
502
- else if(freshGroupMeta){var gm=document.createElement('meta');gm.name='stx-layout-group';gm.content=freshGroupMeta.getAttribute('content')||'';document.head.appendChild(gm)}
503
- // Update container reference for script execution below
504
- currentContent=document.querySelector(containerSel)||document.querySelector('main')||document.body;
505
- } else {
506
- // Same layout \u2014 swap only container content
507
- var cleanHTML=newContent.innerHTML.replace(new RegExp('<scr'+'ipt\\\\b[^>]*>[\\\\s\\\\S]*?<\\\\/scr'+'ipt\\\\s*>','gi'),'');
508
- currentContent.innerHTML=cleanHTML;
509
- }
510
-
511
- // \u2500\u2500 Load new external <head> scripts \u2500\u2500
512
- var loadedSrcs={};
513
- document.querySelectorAll('head script[src]').forEach(function(s){loadedSrcs[s.src]=1});
514
- var extPromises=[];
515
- doc.querySelectorAll('head script[src]').forEach(function(s){
516
- var src=new URL(s.getAttribute('src'),location.origin).href;
517
- if(loadedSrcs[src])return;
518
- loadedSrcs[src]=1;
519
- extPromises.push(new Promise(function(resolve,reject){
520
- var ns=document.createElement('script');
521
- ns.src=src;
522
- ns.onload=resolve;
523
- ns.onerror=reject;
524
- document.head.appendChild(ns);
525
- }));
526
- });
527
-
528
- // \u2500\u2500 Script re-execution \u2500\u2500
529
- // Remove previously injected page scripts
530
- document.querySelectorAll('script[data-stx-page]').forEach(function(s){s.remove()});
531
-
532
- var scripts=[];
533
- function addScript(text, runAlways){
534
- scripts.push({text:text,runAlways:!!runAlways});
535
- }
536
- if(isLayoutChange){
537
- // Layout change: collect ALL scripts from the new document body
538
- // (layout scripts, component mounts, setup functions \u2014 everything)
539
- var newBodyEl=doc.querySelector('body');
540
- if(newBodyEl){
541
- newBodyEl.querySelectorAll('script').forEach(function(s){
542
- var text=s.textContent||'';
543
- if(s.hasAttribute('src'))return;
544
- if(!text.trim())return;
545
- // Skip the signals runtime IIFE \u2014 it's already loaded
546
- if(text.indexOf("'use strict';var cloakStyle")!==-1)return;
547
- if(text.indexOf('__stxRouter')!==-1)return;
548
- addScript(text,true);
549
- });
550
- }
551
- // Also collect setup functions from <head>
552
- doc.querySelectorAll('head script').forEach(function(s){
553
- var text=s.textContent||'';
554
- if(s.hasAttribute('src'))return;
555
- if(!text.trim())return;
556
- if(text.indexOf('__stx_setup_')!==-1)addScript(text,true);
557
- });
558
- } else {
559
- // Same layout: collect scripts from the container
560
- newContent.querySelectorAll('script').forEach(function(s){
561
- var text=s.textContent||'';
562
- if(s.hasAttribute('src'))return;
563
- if(!text.trim())return;
564
- addScript(text,true);
565
- });
566
- // Collect page scripts from <head> AND <body> (outside container).
567
- // SSG builds place the setup function in <body> before <main>, not
568
- // in <head>. Without this, SPA navigation on static sites never
569
- // runs the setup and reactive data stays empty.
570
- var seenSetups={};
571
- scripts.forEach(function(entry){var t=entry.text;if(t.indexOf('__stx_setup_')!==-1)seenSetups[t.substring(0,80)]=1});
572
- doc.querySelectorAll('script').forEach(function(s){
573
- var text=s.textContent||'';
574
- if(s.hasAttribute('src'))return;
575
- if(!text.trim())return;
576
- // Skip signals runtime and router (they contain __stx_setup references but aren't setup functions)
577
- if(text.indexOf("'use strict';var cloakStyle")!==-1)return;
578
- if(text.indexOf('__stxRouter')!==-1)return;
579
- if(newContent.contains(s))return;
580
- if(text.indexOf('__stx_setup_')===-1&&!s.hasAttribute('data-stx-scoped')&&!s.hasAttribute('data-stx-page'))return;
581
- var key=text.substring(0,80);
582
- if(seenSetups[key])return;
583
- seenSetups[key]=1;
584
- addScript(text,true);
585
- });
586
- }
587
-
588
- // Push history state (before active link updates so location.pathname is current)
589
- if(pushState!==false)history.pushState({},'',url+(hash||''));
590
-
591
- // Update active nav links
592
- updateNav(url);
593
- updateActiveLinks();
594
-
595
- // Scroll
596
- if(o.scrollToTop&&!hash)window.scrollTo({top:0,behavior:'instant'});
597
- else if(hash){var el=document.querySelector(hash);if(el)el.scrollIntoView({behavior:'smooth'})}
598
-
599
- // Update title
600
- var newTitle=doc.querySelector('title');
601
- if(newTitle)document.title=newTitle.textContent;
602
-
603
- // Update <html lang> from the destination doc so screen readers,
604
- // CSS :lang() selectors, and any i18n picker that mirrors
605
- // document.documentElement.lang stay accurate after SPA hops.
606
- if(doc.documentElement&&doc.documentElement.lang){
607
- document.documentElement.lang=doc.documentElement.lang;
608
- }
609
-
610
- window.dispatchEvent(new CustomEvent('stx:navigate',{detail:{url:url}}));
611
-
612
- // Execute page scripts FIRST \u2014 they define setup functions and set _latestSetup
613
- function execScripts(){
614
- scripts.forEach(function(entry){
615
- var text=typeof entry==='string'?entry:entry.text;
616
- var runAlways=typeof entry==='string'?false:entry.runAlways;
617
- // Skip scripts that were already executed (layout-level partials
618
- // like theme.stx). Their top-level const/function declarations
619
- // would throw "Identifier has already been declared" on re-execution.
620
- // Exception: setup functions (__stx_setup_) must always re-execute
621
- // because each page has its own setup, and import statements
622
- // need special handling.
623
- var h=hashScript(text);
624
- var isSetup=text.indexOf('__stx_setup_')!==-1;
625
- var hasImport=text.indexOf('import ')!==-1;
626
- if(!runAlways&&!isSetup&&executedScriptHashes[h])return;
627
- executedScriptHashes[h]=1;
628
- // Wrap scripts with import statements as modules (Bug 3 fix)
629
- var ns=document.createElement('script');
630
- if(hasImport){
631
- ns.type='module';
632
- }
633
- // Wrap in block scope to prevent const/let collisions on re-navigation.
634
- // Top-level const/let in <script> tags are global-scoped in browsers
635
- // and throw "Identifier has already been declared" on re-execution.
636
- // Skip the wrap for module scripts \u2014 they get their own scope from
637
- // ESM, and top-level 'import' is illegal inside a block, which
638
- // would throw SyntaxError before the script ever runs.
639
- var alreadyScoped=text.trimStart().charAt(0)==='('||text.trimStart().charAt(0)===';'||text.indexOf('window.stx.mount')>-1;
640
- ns.textContent=(hasImport||alreadyScoped)?text:'{'+text+'}';
641
- ns.setAttribute('data-stx-page','');
642
- document.body.appendChild(ns);
643
- });
644
- // THEN fire stx:load \u2014 now _latestSetup is set and processElement has the right scope
645
- window.dispatchEvent(new Event('stx:load'));
646
- }
647
-
648
- if(extPromises.length>0){
649
- Promise.all(extPromises).then(execScripts).catch(execScripts);
650
- }
651
- else {
652
- execScripts();
653
- }
654
- }
655
-
656
- if(runViewTransition(doSwap)){
657
- }
658
- else {
659
- // Fallback fade for browsers without View Transitions API
660
- currentContent.style.transition='opacity 0.12s ease-out';
661
- currentContent.style.opacity='0';
662
- setTimeout(function(){
663
- doSwap();
664
- currentContent.style.opacity='1';
665
- setTimeout(function(){currentContent.style.transition=''},150);
666
- },120);
667
- }
668
- }
669
-
670
- // \u2500\u2500 Link interception \u2500\u2500
671
- function shouldIntercept(link){
672
- if(!link)return false;
673
- var href=link.getAttribute('href');
674
- if(!href)return false;
675
- if(href.startsWith('http')||href.startsWith('#')||href.startsWith('mailto:')||href.startsWith('tel:')||href.startsWith('javascript:'))return false;
676
- if(link.target==='_blank')return false;
677
- if(link.hasAttribute('data-stx-no-router')||link.hasAttribute('data-no-router')||link.hasAttribute('download'))return false;
678
- if(href.startsWith('?'))return true;
679
- if(href===location.pathname)return false;
680
- if(!getContainer())return false;
681
- return true;
682
- }
683
-
684
- // SPA click handling. By default only [data-stx-link] elements get
685
- // SPA navigation; regular <a href> does native full page reload. Set
686
- // interceptAllLinks:true (window.__stxRouterConfig or build-time
687
- // config) to intercept any same-origin anchor \u2014 used by static-site
688
- // mode where every page is part of the same SPA shell.
689
- document.addEventListener('click',function(e){
690
- if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0)return;
691
- if(!e.target||!e.target.closest)return;
692
- var link=e.target.closest('[data-stx-link]');
693
- if(!link&&o.interceptAllLinks){
694
- var anchor=e.target.closest('a[href]');
695
- if(anchor&&shouldIntercept(anchor))link=anchor;
696
- }
697
- if(!link){return}
698
- var href=link.getAttribute('href');
699
- log('[router] click intercepted:',href,'container:',!!getContainer(),'defaultPrevented:',e.defaultPrevented);
700
- if(!href||href.startsWith('http')||href.startsWith('#')||href.startsWith('mailto:')||href.startsWith('tel:')){log('[router] skipped:',href);return}
701
- if(link.target==='_blank'||link.hasAttribute('download'))return;
702
- e.preventDefault();
703
- e.stopPropagation();
704
- log('[router] navigating to:',href);
705
- navigate(withCurrentLocale(href));
706
- },true);
707
-
708
- // \u2500\u2500 Back/forward \u2500\u2500
709
- window.addEventListener('popstate',function(){
710
- navigate(location.pathname+location.search+location.hash,false);
711
- });
712
-
713
- // \u2500\u2500 Prefetch on hover \u2500\u2500
714
- if(o.prefetch){
715
- document.addEventListener('mouseover',function(e){
716
- if(!e.target||!e.target.closest)return;
717
- var link=e.target.closest('[data-stx-link]');
718
- if(!link)return;
719
- var href=withCurrentLocale(link.getAttribute('href'));
720
- var key=cacheKey(href);
721
- if(cache[key]||prefetching[key])return;
722
- prefetching[key]=true;
723
- var wantsFragment=shouldUseFragmentResponse();
724
- fetch(href,{headers:wantsFragment?{'X-STX-Router':'true','Accept':'text/html'}:{'Accept':'text/html'}}).then(function(r){
725
- var isFrag=wantsFragment&&r.headers.get('X-STX-Fragment')==='true';
726
- var pLayout=r.headers.get('X-STX-Layout')||'';
727
- var pGroup=r.headers.get('X-STX-Layout-Group')||'';
728
- return r.text().then(function(html){return{html:isFrag?'<!--stx-fragment-->'+html:html,layout:pLayout,layoutGroup:pGroup}});
729
- }).then(function(result){
730
- if(o.cache)setCache(key,result.html,result.layout,result.layoutGroup);
731
- }).catch(function(){}).finally(function(){delete prefetching[key]});
732
- },true);
733
- }
734
-
735
- // \u2500\u2500 Active link management \u2500\u2500
736
- function updateNav(url){
737
- document.querySelectorAll('nav a[href], #mobileNav a[href], [data-stx-nav] a[href]').forEach(function(a){
738
- var href=a.getAttribute('href');
739
- if(!href||href.startsWith('#')||href.startsWith('http'))return;
740
- var isActive=(href===url)||(href==='/'&&url==='/');
741
- if(a.hasAttribute('data-stx-link')){
742
- var ac=a.getAttribute('data-stx-active-class')||'active';
743
- if(isActive)ac.split(' ').forEach(function(cls){if(cls)a.classList.add(cls)});else ac.split(' ').forEach(function(cls){if(cls)a.classList.remove(cls)});
744
- }
745
- });
746
- }
747
-
748
- function updateActiveLinks(){
749
- // Update active classes on <stx-link> elements (and legacy data-stx-link)
750
- var links=document.querySelectorAll('[data-stx-link]');
751
- var cur=location.pathname;
752
- links.forEach(function(link){
753
- var href=link.getAttribute('to')||link.getAttribute('href')||'';
754
- var ac=link.getAttribute('active-class')||link.getAttribute('data-stx-active-class')||'active';
755
- var eac=link.getAttribute('exact-active-class')||link.getAttribute('data-stx-exact-active-class')||'exact-active';
756
- ac.split(' ').forEach(function(cls){if(cls)link.classList.remove(cls)});
757
- eac.split(' ').forEach(function(cls){if(cls)link.classList.remove(cls)});
758
- var isExact=cur===href;
759
- var isActive=href!=='/'?cur.startsWith(href):cur==='/';
760
- if(isExact)eac.split(' ').forEach(function(cls){if(cls)link.classList.add(cls)});
761
- if(isActive)ac.split(' ').forEach(function(cls){if(cls)link.classList.add(cls)});
762
- });
763
- }
764
-
765
- // \u2500\u2500 Progress bar DOM + style \u2500\u2500
766
- // Injects a fixed-position element at the top of the viewport plus the
767
- // minimal CSS for its transform/opacity transitions. Kept idempotent so
768
- // repeated init() calls (e.g. after full-body swaps) don't duplicate.
769
- // Also ships the default View Transitions fade+slide CSS when
770
- // viewTransitions is enabled and the browser supports it. Apps can
771
- // override by defining more specific ::view-transition-* rules later in
772
- // the cascade, or opt out entirely with viewTransitions:false.
773
- function injectStyles(){
774
- if(!document.getElementById('stx-r-css')){
775
- var s=document.createElement('style');s.id='stx-r-css';
776
- // Strip characters that could escape our CSS block and inject new
777
- // declarations: ; { } ( ) " ' \\ < > plus whitespace control chars.
778
- // This keeps the value safe to concat into a stylesheet even if a
779
- // caller wires the config from an untrusted source.
780
- var sanitize=function(v){return String(v).replace(/[;{}()"'\\\\<>\\n\\r\\t]/g,'')};
781
- var pc=sanitize(o.progressColor);
782
- var ph=sanitize(o.progressHeight);
783
- var css='.stx-navigating{cursor:wait}.stx-navigating a,.stx-navigating button{pointer-events:none}#stx-router-progress{position:fixed;top:0;left:0;right:0;height:'+ph+';background:'+pc+';box-shadow:0 0 8px '+pc+',0 0 4px '+pc+';transform:scaleX(0);transform-origin:left;transition:transform .18s ease-out,opacity .26s ease;opacity:0;pointer-events:none;z-index:999999}';
784
- if(o.viewTransitions&&'startViewTransition' in document){
785
- var dur=(o.viewTransitionDuration||220)+'ms';
786
- var ease=o.viewTransitionEasing||'cubic-bezier(0.16, 1, 0.3, 1)';
787
- css+='::view-transition-old(root),::view-transition-new(root){animation-duration:'+dur+';animation-timing-function:'+ease+'}';
788
- css+='::view-transition-old(root){animation-name:stx-r-fade-out}::view-transition-new(root){animation-name:stx-r-fade-in}';
789
- css+='@keyframes stx-r-fade-out{from{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-4px)}}';
790
- css+='@keyframes stx-r-fade-in{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}';
791
- css+='@media (prefers-reduced-motion: reduce){::view-transition-old(root),::view-transition-new(root){animation-duration:0s;animation-name:none}}';
792
- }
793
- s.textContent=css;
794
- document.head.appendChild(s);
795
- }
796
- if(o.progress&&!document.getElementById('stx-router-progress')){
797
- var el=document.createElement('div');
798
- el.id='stx-router-progress';
799
- el.setAttribute('role','progressbar');
800
- el.setAttribute('aria-hidden','true');
801
- // Append to <html>, not <body>: when the router swaps the body
802
- // (container:'body' for full-page static-site SPAs) the progress
803
- // element gets wiped along with it. <html> stays put across
804
- // swaps, so the bar survives multi-hop navigation.
805
- document.documentElement.appendChild(el);
806
- progEl=el;
807
- } else if(o.progress){
808
- progEl=document.getElementById('stx-router-progress');
809
- }
810
- }
811
-
812
- function injectViewTransitionCSS(){
813
- if(document.getElementById('stx-view-transitions'))return;
814
- var s=document.createElement('style');s.id='stx-view-transitions';
815
- s.textContent='::view-transition-group(root){animation:none}::view-transition-old(root){animation:none}::view-transition-new(root){animation:none}main,#app-content,[data-stx-content]{view-transition-name:stx-content}::view-transition-old(stx-content){animation:stx-fade-out .15s ease-out both}::view-transition-new(stx-content){animation:stx-fade-in .15s ease-in .1s both}@keyframes stx-fade-out{from{opacity:1}to{opacity:0}}@keyframes stx-fade-in{from{opacity:0}to{opacity:1}}::view-transition{background:transparent}::view-transition-group(stx-content){background:inherit;overflow:hidden}';
816
- (document.head||document.documentElement).appendChild(s);
817
- }
818
-
819
- // \u2500\u2500 Public API \u2500\u2500
820
- var router={
821
- navigate:navigate,
822
- navigateTo:navigate,
823
- prefetch:function(url){
824
- var key=cacheKey(url);
825
- if(!cache[key]){
826
- var wantsFragment=shouldUseFragmentResponse();
827
- fetch(url,{headers:wantsFragment?{'X-STX-Router':'true'}:{'Accept':'text/html'}}).then(function(r){var isFrag=wantsFragment&&r.headers.get('X-STX-Fragment')==='true';var pLayout=r.headers.get('X-STX-Layout')||'';var pGroup=r.headers.get('X-STX-Layout-Group')||'';return r.text().then(function(html){return{html:isFrag?'<!--stx-fragment-->'+html:html,layout:pLayout,layoutGroup:pGroup}})}).then(function(result){setCache(key,result.html,result.layout,result.layoutGroup)}).catch(function(){});
828
- }
829
- },
830
- clearCache:function(){for(var k in cache)delete cache[k];for(var lk in layoutCache)delete layoutCache[lk];for(var gk in layoutGroupCache)delete layoutGroupCache[gk];cacheOrder.length=0},
831
- cache:cache,
832
- swap:swap,
833
- updateNav:updateNav
834
- };
835
-
836
- router.__rev=ROUTER_REV;
837
- window.__stxRouter=router;
838
- window.stxRouter=router;
839
- if(window.stx)window.stx.router=router;
840
-
841
- // \u2500\u2500 Initialize \u2500\u2500
842
- function init(){
843
- injectStyles();
844
- injectViewTransitionCSS();
845
- updateActiveLinks();
846
- updateNav(location.pathname);
847
- }
848
-
849
- if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',init);else init();
850
- })();
851
- `}export{IB as setAppUrl,UB as runMiddleware,OB as route,y as resolveLayoutChain,VB as resetRoutes,M as registerMiddleware,k as patternToRegex,YB as navigateTo,o as matchRoute,jB as loadMiddlewareFromDirectory,AB as hasMiddleware,zB as getRouterScript,QB as getMiddlewareNames,c as getMiddleware,w as generateRouteTypes,D as generateRouteManifest,BB as formatRoutes,e as findErrorPage,P as filePathToPattern,v as extractLayoutMetadata,b as deriveLayoutGroup,KB as defineRoutes,JB as defineRoute,$B as defineMiddleware,h as createStorageManager,f as createServerCookieManager,a as createRouter,_B as createRouteLocation,EB as createMiddlewareContext,g as createClientCookieManager,GB as clearMiddleware,ZB as abortNavigation,S as Router};