@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.
- package/dist/api-client.d.ts +26 -0
- package/dist/api-client.js +22 -0
- package/dist/api-handler.d.ts +6 -0
- package/dist/api-handler.js +3 -0
- package/dist/app-shell.js +11 -2
- package/dist/application-layers.d.ts +30 -0
- package/dist/application-layers.js +202 -0
- package/dist/build.js +9 -1
- package/dist/chunk-02hm88m5.js +2 -0
- package/dist/{chunk-7eea1cse.js → chunk-09zjty4k.js} +1 -1
- package/dist/{chunk-7nfn7nj9.js → chunk-0gz0rhvs.js} +1 -1
- package/dist/{chunk-jsfch50r.js → chunk-1c2j4eby.js} +1 -1
- package/dist/{chunk-m6wz1hf5.js → chunk-2h94c5hm.js} +2 -2
- package/dist/{chunk-mjpqz66q.js → chunk-2ver2s2y.js} +1 -1
- package/dist/{chunk-2wcd2031.js → chunk-30nbe9hr.js} +2 -2
- package/dist/chunk-39qzhpn6.js +18 -0
- package/dist/chunk-3z6bqqr7.js +2 -0
- package/dist/chunk-43p1qq7g.js +2 -0
- package/dist/{chunk-52rkkkmt.js → chunk-45y8bjrv.js} +287 -352
- package/dist/{chunk-2rp09y5j.js → chunk-4evbx7sz.js} +1 -1
- package/dist/chunk-4jgr954p.js +2 -0
- package/dist/chunk-51j2aqvb.js +2 -0
- package/dist/{chunk-8d15pd4g.js → chunk-54f8bpp6.js} +3 -3
- package/dist/{chunk-cbwp8prr.js → chunk-5k1hznvq.js} +2 -2
- package/dist/chunk-5qfpcgcs.js +2 -0
- package/dist/{chunk-7eg7ep8f.js → chunk-5tefa8qb.js} +2 -2
- package/dist/chunk-5x2fc4vk.js +30 -0
- package/dist/{chunk-683tfkz4.js → chunk-64djh88a.js} +1 -1
- package/dist/{chunk-btrmvj2y.js → chunk-695fkras.js} +1 -1
- package/dist/chunk-6hcc4973.js +2 -0
- package/dist/{chunk-svg37jzs.js → chunk-6vswphz4.js} +2 -2
- package/dist/chunk-7gqbr8nr.js +2 -0
- package/dist/{chunk-x4prtyjs.js → chunk-7kw3grq5.js} +1 -1
- package/dist/{chunk-7jebw3ea.js → chunk-7skk34dh.js} +2 -2
- package/dist/chunk-8215nhej.js +12 -0
- package/dist/chunk-8ee62a9q.js +2 -0
- package/dist/{chunk-jj6yp7gm.js → chunk-8jam44my.js} +1 -1
- package/dist/chunk-8z0n5mtg.js +2 -0
- package/dist/{chunk-3bc8bqw2.js → chunk-9368t9jm.js} +1 -1
- package/dist/chunk-9499k64n.js +6 -0
- package/dist/chunk-976g5qe5.js +2 -0
- package/dist/{chunk-3jwmcf4k.js → chunk-9c835qjn.js} +1 -1
- package/dist/chunk-9px4y692.js +2 -0
- package/dist/{chunk-38t0fxh0.js → chunk-9vqnrcrw.js} +2 -2
- package/dist/chunk-9wrrr7g3.js +4 -0
- package/dist/{chunk-q0y1yxg3.js → chunk-9xzszvn5.js} +1 -1
- package/dist/chunk-a07chbgj.js +2 -0
- package/dist/{chunk-454kar39.js → chunk-ankp4reb.js} +2 -2
- package/dist/{chunk-5d9cy7a0.js → chunk-awj7yy37.js} +1 -1
- package/dist/chunk-b1hd8kvy.js +2 -0
- package/dist/chunk-b4xwbh8a.js +2 -0
- package/dist/{chunk-d6wq91cw.js → chunk-bd9wrcq1.js} +277 -21
- package/dist/{chunk-q25mr70f.js → chunk-c131k3mt.js} +1 -1
- package/dist/chunk-c3tmzx7q.js +2 -0
- package/dist/{chunk-6btbgxh1.js → chunk-c79nfdyj.js} +1 -1
- package/dist/{chunk-cfgpk6bh.js → chunk-cbgh359m.js} +1 -1
- package/dist/chunk-ckzhp09g.js +2 -0
- package/dist/{chunk-weqpt9nt.js → chunk-cr8v8k53.js} +1 -1
- package/dist/{chunk-p3wwm6k4.js → chunk-d19tvdvv.js} +1 -1
- package/dist/{chunk-nb1zdh1y.js → chunk-d3srvh3q.js} +1 -1
- package/dist/{chunk-rqrfq305.js → chunk-d57gb0v2.js} +1 -1
- package/dist/{chunk-1xyhk1wr.js → chunk-d5cqnwdd.js} +1 -1
- package/dist/chunk-dgpjxmhs.js +2 -0
- package/dist/chunk-dvvx1wny.js +3 -0
- package/dist/{chunk-ctz53mbz.js → chunk-ej8mv2k6.js} +1 -1
- package/dist/{chunk-dv3z80gt.js → chunk-env6knrs.js} +1 -1
- package/dist/{chunk-rf10fkrf.js → chunk-ess2pgt5.js} +1 -1
- package/dist/chunk-ez28vck6.js +2 -0
- package/dist/{chunk-0tbgvp70.js → chunk-fczfdsab.js} +21 -5
- package/dist/{chunk-xdq52pwj.js → chunk-fp7ms6e7.js} +1 -1
- package/dist/{chunk-qg6pg6ze.js → chunk-fqq5k9ve.js} +1 -1
- package/dist/chunk-fvtv1s5j.js +3 -0
- package/dist/{chunk-5t0w4h6z.js → chunk-g912mb7x.js} +1 -1
- package/dist/chunk-g97atepq.js +2 -0
- package/dist/{chunk-wj25qt72.js → chunk-gbwhbasw.js} +1 -1
- package/dist/{chunk-38e9wgfc.js → chunk-gfc3qye3.js} +2 -2
- package/dist/{chunk-cratkhhb.js → chunk-ghw5p1yk.js} +1 -1
- package/dist/{chunk-f0g2q51j.js → chunk-gssbag3e.js} +1 -1
- package/dist/{chunk-c9vhtjtr.js → chunk-gt8ja700.js} +2 -2
- package/dist/chunk-hay1rzb0.js +3754 -0
- package/dist/{chunk-q5sw26s7.js → chunk-hg2afckn.js} +1 -1
- package/dist/chunk-hgjjnjas.js +7 -0
- package/dist/{chunk-hhnzd03k.js → chunk-hrcxfvh1.js} +1 -1
- package/dist/chunk-hzav4hyd.js +2 -0
- package/dist/{chunk-29gjwajm.js → chunk-jfzfrmzy.js} +1 -1
- package/dist/chunk-jjq9q9jr.js +2 -0
- package/dist/{chunk-ddqkj56r.js → chunk-jp2f8yzw.js} +1 -1
- package/dist/{chunk-ry3a2674.js → chunk-jsg1rthc.js} +1 -1
- package/dist/chunk-jxxv18a0.js +5 -0
- package/dist/chunk-kbw2qzqx.js +2 -0
- package/dist/chunk-kdxvraec.js +2 -0
- package/dist/chunk-krfjb7b8.js +2 -0
- package/dist/{chunk-6b4k8fay.js → chunk-kxavsh3m.js} +1 -1
- package/dist/{chunk-4tffxxpd.js → chunk-m31n9pkr.js} +1 -1
- package/dist/{chunk-fj6fbqgb.js → chunk-m3a20mmb.js} +1 -1
- package/dist/{chunk-j21csh4j.js → chunk-mbmqpaq1.js} +1 -1
- package/dist/{chunk-y9nyqcha.js → chunk-mwh3ymwc.js} +1 -1
- package/dist/{chunk-51g95yts.js → chunk-mygq61f5.js} +2 -2
- package/dist/chunk-nqq7y7m9.js +3 -0
- package/dist/chunk-nws8fbde.js +2 -0
- package/dist/{chunk-q6xfyasj.js → chunk-pcvayb2f.js} +1 -1
- package/dist/{chunk-nvxv2wxv.js → chunk-ppyz9623.js} +1 -1
- package/dist/chunk-pr14wjkn.js +2 -0
- package/dist/{chunk-jb2r696a.js → chunk-qev11kg8.js} +1 -1
- package/dist/{chunk-6njgsr6w.js → chunk-qeyw5za9.js} +1 -1
- package/dist/chunk-rpfcnq8n.js +2 -0
- package/dist/chunk-rrankpmj.js +3 -0
- package/dist/chunk-rst1rw09.js +2 -0
- package/dist/{chunk-3p0zgfgz.js → chunk-rzevgemj.js} +2 -2
- package/dist/{chunk-aa6kt84c.js → chunk-sart9ehj.js} +1 -1
- package/dist/chunk-sb7ana2z.js +19 -0
- package/dist/chunk-snt2773t.js +2 -0
- package/dist/{chunk-jptkc64r.js → chunk-t3qb9s6s.js} +2 -2
- package/dist/{chunk-w8yac9xp.js → chunk-t41aaehf.js} +1 -1
- package/dist/{chunk-qjkzpd68.js → chunk-t51mwjyq.js} +1 -1
- package/dist/chunk-tt4r8q4v.js +2 -0
- package/dist/chunk-vd3h9z7e.js +2 -0
- package/dist/{chunk-6rzwef28.js → chunk-vd5xvsnv.js} +1 -1
- package/dist/chunk-wbecqx03.js +2 -0
- package/dist/{chunk-dcxtrqfy.js → chunk-wfffa8zm.js} +1 -1
- package/dist/{chunk-22p0ezj6.js → chunk-wx13qmaw.js} +1 -1
- package/dist/chunk-xd5ahrtn.js +2 -0
- package/dist/{chunk-vh0qr8k9.js → chunk-xganfzgn.js} +2 -2
- package/dist/chunk-xq1swv2e.js +2 -0
- package/dist/chunk-xsfwcj6x.js +2 -0
- package/dist/{chunk-91007tan.js → chunk-xwxdwqn9.js} +1 -1
- package/dist/{chunk-634gaa9d.js → chunk-xz3evxqp.js} +1 -1
- package/dist/chunk-xzgvcrnz.js +2 -0
- package/dist/chunk-y2kmm6bt.js +43 -0
- package/dist/{chunk-v8474ah4.js → chunk-y4nzmkea.js} +1 -1
- package/dist/chunk-y7wsk78j.js +3 -0
- package/dist/{chunk-6w8fa3b8.js → chunk-ya5m5vbn.js} +1 -1
- package/dist/{chunk-ps20v1ah.js → chunk-ym3r8ktq.js} +1 -1
- package/dist/chunk-yyebm8q4.js +2 -0
- package/dist/chunk-yyyxt326.js +2 -0
- package/dist/chunk-yz16bgs3.js +28 -0
- package/dist/{chunk-em8p71et.js → chunk-z9ezmjwd.js} +2 -2
- package/dist/chunk-zbtfhxhn.js +2 -0
- package/dist/chunk-zggm7kjd.js +17 -0
- package/dist/{chunk-mdf3jbe6.js → chunk-zhcs8m2a.js} +2 -2
- package/dist/{chunk-f9d27v49.js → chunk-zs5y7xnt.js} +1 -1
- package/dist/cli.js +14 -14
- package/dist/client-script-bundler.js +22 -11
- package/dist/component-contract-checks.d.ts +19 -0
- package/dist/component-contract-checks.js +147 -0
- package/dist/component-contract.d.ts +20 -0
- package/dist/component-contract.js +108 -0
- package/dist/component-model.d.ts +29 -0
- package/dist/component-model.js +59 -0
- package/dist/component-registry.js +7 -64
- package/dist/component-renderer.d.ts +1 -26
- package/dist/component-renderer.js +4 -239
- package/dist/component-resolution.d.ts +21 -0
- package/dist/component-resolution.js +118 -0
- package/dist/component-tags.d.ts +9 -0
- package/dist/component-tags.js +174 -0
- package/dist/composable-loader.d.ts +2 -13
- package/dist/composable-loader.js +15 -26
- package/dist/composables/index.d.ts +1 -0
- package/dist/composables/index.js +1 -0
- package/dist/composables/use-fetch.d.ts +117 -42
- package/dist/composables/use-fetch.js +47 -4
- package/dist/composition-api.d.ts +43 -19
- package/dist/config.d.ts +1 -1
- package/dist/config.js +46 -4
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/database.js +1 -1
- package/dist/dev-server/serve-app.js +57 -17
- package/dist/dev-server/serve-file.js +8 -1
- package/dist/expressions.js +1 -1
- package/dist/imported-signals.js +1 -1
- package/dist/includes.js +8 -2
- package/dist/index.d.ts +11 -0
- package/dist/index.js +7 -0
- package/dist/manifest.d.ts +6 -0
- package/dist/misc-directives.d.ts +2 -0
- package/dist/misc-directives.js +39 -1
- package/dist/process.js +18 -1
- package/dist/production-builder.d.ts +4 -0
- package/dist/production-builder.js +47 -8
- package/dist/production-server.d.ts +4 -1
- package/dist/production-server.js +119 -71
- package/dist/pwa.js +2 -2
- package/dist/render.js +9 -2
- package/dist/route-response-cache.d.ts +7 -0
- package/dist/route-response-cache.js +72 -0
- package/dist/route-rules.d.ts +17 -0
- package/dist/route-rules.js +40 -0
- package/dist/router.d.ts +1 -0
- package/dist/runtime-config-loader.d.ts +5 -0
- package/dist/runtime-config-loader.js +42 -0
- package/dist/runtime-config-server.d.ts +26 -0
- package/dist/runtime-config-server.js +77 -0
- package/dist/runtime-config-types.d.ts +2 -0
- package/dist/runtime-config-types.js +0 -0
- package/dist/runtime-config.d.ts +5 -0
- package/dist/runtime-config.js +9 -0
- package/dist/runtime-globals.js +3 -0
- package/dist/serve.js +32 -10
- package/dist/server-api.d.ts +27 -0
- package/dist/server-api.js +181 -0
- package/dist/server-data.d.ts +17 -0
- package/dist/server-data.js +40 -0
- package/dist/signal-processing.js +2 -2
- package/dist/signals.js +210 -17
- package/dist/ssg.js +2 -2
- package/dist/stx-virtual-ts.d.ts +6 -0
- package/dist/stx-virtual-ts.js +31 -7
- package/dist/stx.d.ts +28 -0
- package/dist/template-compiler.d.ts +1 -0
- package/dist/template-compiler.js +1 -1
- package/dist/template-hydrator.js +15 -4
- package/dist/typecheck.d.ts +1 -0
- package/dist/typecheck.js +4 -3
- package/dist/types/config-types.d.ts +17 -0
- package/dist/utils.js +15 -5
- package/dist/variable-extractor.d.ts +1 -1
- package/dist/variable-extractor.js +12 -1
- package/dist/visual-testing.js +1 -1
- package/dist/vue-template.js +19 -41
- package/package.json +5 -5
- package/stx.d.ts +28 -0
- package/dist/chunk-0p44z42s.js +0 -2
- package/dist/chunk-1na1dvda.js +0 -2
- package/dist/chunk-2yp8ang5.js +0 -2
- package/dist/chunk-35x7s4cr.js +0 -2
- package/dist/chunk-39qnycbc.js +0 -2
- package/dist/chunk-4qj6pq60.js +0 -2
- package/dist/chunk-4r1qdp25.js +0 -19
- package/dist/chunk-4xs545h1.js +0 -2
- package/dist/chunk-70cf5h11.js +0 -2
- package/dist/chunk-7k63nhap.js +0 -28
- package/dist/chunk-7w3dttqh.js +0 -2
- package/dist/chunk-813dt09p.js +0 -2
- package/dist/chunk-9cp3430d.js +0 -2
- package/dist/chunk-ac9vpa5z.js +0 -2
- package/dist/chunk-b26xazrf.js +0 -2
- package/dist/chunk-b2ghmxpj.js +0 -4
- package/dist/chunk-btnky17z.js +0 -12
- package/dist/chunk-c7av0px6.js +0 -2
- package/dist/chunk-cthpzv4p.js +0 -18
- package/dist/chunk-d41b0rqp.js +0 -2
- package/dist/chunk-dkd0bg8g.js +0 -2
- package/dist/chunk-e0s519df.js +0 -2
- package/dist/chunk-ebr2344x.js +0 -3
- package/dist/chunk-ehp6fez3.js +0 -2
- package/dist/chunk-fc5t3cxt.js +0 -2
- package/dist/chunk-g6ttsdz1.js +0 -2
- package/dist/chunk-gd73rpks.js +0 -2
- package/dist/chunk-gv42xz15.js +0 -17
- package/dist/chunk-h3t6fjba.js +0 -2
- package/dist/chunk-h65nep6y.js +0 -2
- package/dist/chunk-h7d01cy7.js +0 -2
- package/dist/chunk-jc57j887.js +0 -2
- package/dist/chunk-k5xtf38q.js +0 -3
- package/dist/chunk-mc4rtf5d.js +0 -2
- package/dist/chunk-me5kq4e6.js +0 -22
- package/dist/chunk-mzf6c0h7.js +0 -2
- package/dist/chunk-n1j7gfe1.js +0 -3
- package/dist/chunk-pczxwdes.js +0 -2
- package/dist/chunk-pq6rabcy.js +0 -3754
- package/dist/chunk-qr59yfq9.js +0 -2
- package/dist/chunk-s454ytp4.js +0 -2
- package/dist/chunk-s4sp78fn.js +0 -2
- package/dist/chunk-shr928nn.js +0 -2
- package/dist/chunk-that7v95.js +0 -2
- package/dist/chunk-vwnnbzsp.js +0 -2
- package/dist/chunk-w63052rn.js +0 -2
- package/dist/chunk-w9kzfesd.js +0 -2
- package/dist/chunk-zwy5e35f.js +0 -30
package/dist/manifest.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { RouteRules } from './route-rules';
|
|
2
|
+
import type { ServerApiRoute } from './server-api';
|
|
1
3
|
/**
|
|
2
4
|
* Generate a build manifest from compiled pages and assets.
|
|
3
5
|
*/
|
|
@@ -20,6 +22,7 @@ export declare interface ManifestRoute {
|
|
|
20
22
|
fragmentPath: string
|
|
21
23
|
isDynamic: boolean
|
|
22
24
|
hasParams: boolean
|
|
25
|
+
prerendered?: boolean
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
28
|
* Asset entries in the build manifest.
|
|
@@ -38,4 +41,7 @@ export declare interface BuildManifest {
|
|
|
38
41
|
routes: ManifestRoute[]
|
|
39
42
|
assets: ManifestAssets
|
|
40
43
|
outputDir: string
|
|
44
|
+
routeRules?: RouteRules
|
|
45
|
+
routerContainer?: string
|
|
46
|
+
apiRoutes?: ServerApiRoute[]
|
|
41
47
|
}
|
|
@@ -41,6 +41,8 @@ export declare function processMemoDirective(template: string): string;
|
|
|
41
41
|
* The client-side runtime will automatically bind these to ref objects.
|
|
42
42
|
*/
|
|
43
43
|
export declare function processRefAttributes(template: string): string;
|
|
44
|
+
/** Keep the caller of a projected ref explicit after slot content is flattened. */
|
|
45
|
+
export declare function markProjectedRefs(template: string, receiver: string): string;
|
|
44
46
|
/**
|
|
45
47
|
* Add x-cloak to HTML elements whose own text contains an unresolved {{ }}
|
|
46
48
|
* expression. Those were preserved for client-side evaluation (signals, loop
|
package/dist/misc-directives.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { errorLogger } from "./error-handling.js";
|
|
2
|
-
import { mightContainOwnTextMustache } from "./html-masking.js";
|
|
2
|
+
import { mightContainOwnTextMustache, scanAtElementPosition } from "./html-masking.js";
|
|
3
3
|
import { createSafeFunction, isExpressionSafe } from "./safe-evaluator.js";
|
|
4
4
|
export function processJsonDirective(template, context) {
|
|
5
5
|
let result = template;
|
|
@@ -139,6 +139,44 @@ export function processRefAttributes(template) {
|
|
|
139
139
|
result = result.replace(/(<[a-zA-Z][a-zA-Z0-9-]*\b[^>]*?)\sref="([^"]+)"/g, '$1 data-stx-ref="$2"');
|
|
140
140
|
return result;
|
|
141
141
|
}
|
|
142
|
+
export function markProjectedRefs(template, receiver) {
|
|
143
|
+
if (!/\bref\s*=/.test(template))
|
|
144
|
+
return template;
|
|
145
|
+
const tagPattern = /<\/?([a-zA-Z][\w-]*)\b(?:"[^"]*"|'[^']*'|[^'">])*>/y, tags = scanAtElementPosition(template, (html, index) => {
|
|
146
|
+
tagPattern.lastIndex = index;
|
|
147
|
+
const match = tagPattern.exec(html);
|
|
148
|
+
if (!match || /^(?:script|style)$/i.test(match[1]))
|
|
149
|
+
return -1;
|
|
150
|
+
return tagPattern.lastIndex;
|
|
151
|
+
}), ancestors = [];
|
|
152
|
+
let scopedDepth = 0, cursor = 0;
|
|
153
|
+
const output = [];
|
|
154
|
+
for (const { start, end, token } of tags) {
|
|
155
|
+
const name = /^<\/?([\w-]+)/.exec(token)[1].toLowerCase();
|
|
156
|
+
if (token.startsWith("</")) {
|
|
157
|
+
let ancestor;
|
|
158
|
+
while (ancestor = ancestors.pop()) {
|
|
159
|
+
if (ancestor.scoped)
|
|
160
|
+
scopedDepth--;
|
|
161
|
+
if (ancestor.name === name)
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const scoped = /\sdata-stx-scope\s*=/.test(token);
|
|
167
|
+
if (!scopedDepth && !scoped && /\s(?:ref|@ref|:ref|x-ref|data-stx-ref)\s*=/.test(token) && !/\sdata-stx-ref-caller\s*=/.test(token)) {
|
|
168
|
+
output.push(template.slice(cursor, start), token.replace(/\s*\/?>$/, (ending) => ` data-stx-ref-caller="${receiver}"${ending}`));
|
|
169
|
+
cursor = end;
|
|
170
|
+
}
|
|
171
|
+
if (!VOID_TAGS.has(name) && !/\/>$/.test(token)) {
|
|
172
|
+
ancestors.push({ name, scoped });
|
|
173
|
+
if (scoped)
|
|
174
|
+
scopedDepth++;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
output.push(template.slice(cursor));
|
|
178
|
+
return output.join("");
|
|
179
|
+
}
|
|
142
180
|
const VOID_TAGS = new Set([
|
|
143
181
|
"area",
|
|
144
182
|
"base",
|
package/dist/process.js
CHANGED
|
@@ -43,6 +43,9 @@ import { dedupeScopedStyles, processScopedStyles } from "./style-scoping.js";
|
|
|
43
43
|
import { injectColorModeBootScript, normalizeCriticalHeadOrder } from "./color-mode-boot.js";
|
|
44
44
|
import { buildIdFragment } from "./build-id.js";
|
|
45
45
|
import { applyHeadInjections, createHeadInjections } from "./head-injection.js";
|
|
46
|
+
import { serverDataScope, serverDataTag } from "./server-data.js";
|
|
47
|
+
import { prepareRuntimeConfig } from "./runtime-config-loader.js";
|
|
48
|
+
import { injectRuntimeConfig } from "./runtime-config-server.js";
|
|
46
49
|
import { applyHtmlAttrs, cloakStyleFragment, ensureDocumentShell, hasDocumentShell, injectConfigHeadTags, mergeHtmlAttrs, metaDedupKey, startsDocument } from "./document-shell.js";
|
|
47
50
|
import { hasSignalsSyntax, convertSignalDirectivesToAttributes, convertSignalLoopsToAttributes, preEvalLiteralReactiveIfs, processSignals } from "./signal-processing.js";
|
|
48
51
|
import { processComponents } from "./component-renderer.js";
|
|
@@ -278,6 +281,11 @@ export async function processDirectives(template, context, filePath, options, de
|
|
|
278
281
|
if (context.__stx_signals_gate === void 0)
|
|
279
282
|
context.__stx_signals_gate = usesSignalsInScript(template, filePath);
|
|
280
283
|
const isTopLevel = !context.__stxProcessingDepth;
|
|
284
|
+
serverDataScope(context);
|
|
285
|
+
for (const dependency of options._layerGraph?.configDependencies ?? [])
|
|
286
|
+
dependencies.add(dependency);
|
|
287
|
+
if (isTopLevel && options.runtimeConfig)
|
|
288
|
+
await prepareRuntimeConfig(context, filePath, options.runtimeConfig);
|
|
281
289
|
if (isTopLevel) {
|
|
282
290
|
initializeComponentClientFactories(context);
|
|
283
291
|
context.__stx_head_injections = createHeadInjections();
|
|
@@ -365,7 +373,7 @@ export async function processDirectives(template, context, filePath, options, de
|
|
|
365
373
|
frameworkScript = await getFrameworkComposableScript(result);
|
|
366
374
|
} catch {}
|
|
367
375
|
try {
|
|
368
|
-
const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, pending = [modulesTag, storeTag, frameworkScript].filter((text) => text !== null), composableCode = await getComposableScript(resolvedComposablesDir, result, pending);
|
|
376
|
+
const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, pending = [modulesTag, storeTag, frameworkScript].filter((text) => text !== null), composableCode = await getComposableScript(options._layerComposableDirs ?? resolvedComposablesDir, result, pending);
|
|
369
377
|
if (composableCode)
|
|
370
378
|
composableTag = `<script data-stx-composables>${composableCode}</script>`;
|
|
371
379
|
} catch {}
|
|
@@ -388,6 +396,15 @@ ${tag}`).join("");
|
|
|
388
396
|
else if (isTopLevel)
|
|
389
397
|
result = dedupeScopedStyles(result);
|
|
390
398
|
result = result.replace(/\x00STX_ESCAPED_AT\x00/g, "@");
|
|
399
|
+
if (isTopLevel && context.__stx_runtime_config)
|
|
400
|
+
result = injectRuntimeConfig(result, context.__stx_runtime_config);
|
|
401
|
+
if (isTopLevel && !context.__stx_defer_server_data) {
|
|
402
|
+
const dataTag = serverDataTag(context);
|
|
403
|
+
if (dataTag) {
|
|
404
|
+
const head = /<head\b[^>]*>/i.exec(result), at = head ? head.index + head[0].length : 0;
|
|
405
|
+
result = result.slice(0, at) + dataTag + result.slice(at);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
391
408
|
return result;
|
|
392
409
|
});
|
|
393
410
|
} catch (error) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type ManifestAssets } from './manifest';
|
|
2
|
+
import { type RouteRules } from './route-rules';
|
|
3
|
+
import { type ServerApiOptions } from './server-api';
|
|
2
4
|
/**
|
|
3
5
|
* Build the stx application for production.
|
|
4
6
|
*
|
|
@@ -30,6 +32,8 @@ export declare interface ProductionBuildOptions {
|
|
|
30
32
|
partialsDir?: string
|
|
31
33
|
layoutsDir?: string
|
|
32
34
|
publicDir?: string
|
|
35
|
+
routeRules?: RouteRules
|
|
36
|
+
serverApi?: boolean | ServerApiOptions
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
35
39
|
* Result of a production build.
|
|
@@ -10,6 +10,12 @@ import { applyHtmlAttrs, ensureDocumentShell } from "./document-shell.js";
|
|
|
10
10
|
import { extractContainerContent } from "./app-shell.js";
|
|
11
11
|
import { injectCss } from "./dev-server/ts-css.js";
|
|
12
12
|
import { loadStxConfig } from "./config.js";
|
|
13
|
+
import { createRouteRuleResolver } from "./route-rules.js";
|
|
14
|
+
import { hydrateTemplateStream } from "./template-hydrator.js";
|
|
15
|
+
import { buildServerApi, discoverServerApi } from "./server-api.js";
|
|
16
|
+
import { resolveRuntimeConfig } from "./runtime-config-server.js";
|
|
17
|
+
import { generateRuntimeConfigTypes } from "./runtime-config-loader.js";
|
|
18
|
+
import { layerManifest } from "./application-layers.js";
|
|
13
19
|
const PUBLIC_ASSET_BLOCKLIST = new Set([
|
|
14
20
|
".DS_Store",
|
|
15
21
|
"Thumbs.db",
|
|
@@ -46,11 +52,11 @@ function copyPublicAssets(srcDir, destDir) {
|
|
|
46
52
|
export async function buildForProduction(options = {}) {
|
|
47
53
|
const startTime = Date.now(), root = path.resolve(options.root || process.cwd()), outputDir = path.resolve(root, options.outputDir || ".output");
|
|
48
54
|
console.log("[stx build] Starting production build...");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
const projectConfig = await loadStxConfig(root), componentsDir = path.resolve(root, options.componentsDir ?? projectConfig.componentsDir ?? "components"), partialsDir = path.resolve(root, options.partialsDir ?? projectConfig.partialsDir ?? "partials"), layoutsDir = path.resolve(root, options.layoutsDir ?? projectConfig.layoutsDir ?? "layouts"), publicDir = options.publicDir ?? projectConfig.publicDir ?? "public", headConfigDefault = projectConfig.app?.head || {}, colorModeConfig = projectConfig.app?.colorMode, routerContainer = projectConfig.router?.container || "main", routeRules = options.routeRules ?? projectConfig.routeRules ?? {}, resolveRule = createRouteRuleResolver(routeRules), serverApi = options.serverApi ?? projectConfig.serverApi, apiOptions = typeof serverApi === "object" ? serverApi : {};
|
|
56
|
+
if (serverApi)
|
|
57
|
+
discoverServerApi(root, apiOptions);
|
|
58
|
+
if (projectConfig.runtimeConfig)
|
|
59
|
+
resolveRuntimeConfig(projectConfig.runtimeConfig, {});
|
|
54
60
|
if (fs.existsSync(outputDir))
|
|
55
61
|
fs.rmSync(outputDir, { recursive: !0 });
|
|
56
62
|
const dirs = [
|
|
@@ -62,7 +68,7 @@ export async function buildForProduction(options = {}) {
|
|
|
62
68
|
for (const dir of dirs)
|
|
63
69
|
fs.mkdirSync(dir, { recursive: !0 });
|
|
64
70
|
console.log("[stx build] Discovering routes...");
|
|
65
|
-
const allRoutes = createRouter(root), excludeDirs = ["components", "layouts", "partials"], routes = allRoutes.filter((r) => {
|
|
71
|
+
const allRoutes = createRouter(root, { pagesDirs: projectConfig._layerPageDirs }), excludeDirs = ["components", "layouts", "partials"], routes = allRoutes.filter((r) => {
|
|
66
72
|
return !excludeDirs.some((dir) => r.pattern.startsWith(`/${dir}/`) || r.pattern === `/${dir}`);
|
|
67
73
|
});
|
|
68
74
|
console.log(`[stx build] Found ${routes.length} page routes (${allRoutes.length - routes.length} non-page files excluded)`);
|
|
@@ -74,9 +80,13 @@ export async function buildForProduction(options = {}) {
|
|
|
74
80
|
console.log(`[stx build] Router: ${routerAsset.filename} (${(routerAsset.content.length / 1024).toFixed(1)}KB)`);
|
|
75
81
|
console.log("[stx build] Compiling templates...");
|
|
76
82
|
const compiledPages = [], manifestRoutes = [];
|
|
77
|
-
for (const route of routes)
|
|
83
|
+
for (const route of routes) {
|
|
84
|
+
const rule = resolveRule(route.pattern), prerendered = rule.rendering === "prerender";
|
|
85
|
+
if (prerendered && (route.pattern.includes(":") || route.pattern.includes("[")))
|
|
86
|
+
throw Error(`Cannot prerender parameter route ${route.pattern}; use dynamic rendering (explicit path enumeration is not supported here)`);
|
|
78
87
|
try {
|
|
79
88
|
const compiled = await compileTemplate(route.filePath, route.pattern, {
|
|
89
|
+
configDir: root,
|
|
80
90
|
componentsDir,
|
|
81
91
|
partialsDir,
|
|
82
92
|
layoutsDir,
|
|
@@ -102,6 +112,21 @@ export async function buildForProduction(options = {}) {
|
|
|
102
112
|
}
|
|
103
113
|
compiled.html = compiled.html.replace(/<style data-css="generated">[\s\S]*?<\/style>\s*/g, "");
|
|
104
114
|
compiled.html = await injectCss(compiled.html);
|
|
115
|
+
if (prerendered) {
|
|
116
|
+
const rendered = await hydrateTemplateStream(compiled, {
|
|
117
|
+
params: {},
|
|
118
|
+
request: new Request(`http://stx.build${route.pattern}`),
|
|
119
|
+
method: "GET",
|
|
120
|
+
__stx_strict_hydration: !0
|
|
121
|
+
});
|
|
122
|
+
if (rendered.redirect || rendered.cookies?.length || rendered.boundaries?.length || rendered.headers && Object.keys(rendered.headers).length)
|
|
123
|
+
throw Error(`Prerendered route ${route.pattern} cannot set response headers/cookies, redirect or stream`);
|
|
124
|
+
compiled.html = rendered.html;
|
|
125
|
+
compiled.status = rendered.status ?? compiled.status;
|
|
126
|
+
compiled.hasServerScripts = !1;
|
|
127
|
+
compiled.serverScriptContent = [];
|
|
128
|
+
compiled.placeholders = {};
|
|
129
|
+
}
|
|
105
130
|
compiled.fragment = extractContainerContent(compiled.html, routerContainer);
|
|
106
131
|
const safeRouteName = route.pattern === "/" ? "index" : route.pattern.slice(1).replace(/\//g, "-").replace(/[[\]]/g, "_"), compiledPath = path.join("server", "pages", `${safeRouteName}.compiled.json`), fragmentPath = path.join("server", "fragments", `${safeRouteName}.html`);
|
|
107
132
|
await Bun.write(path.join(outputDir, compiledPath), JSON.stringify(compiled, null, 2));
|
|
@@ -111,12 +136,16 @@ export async function buildForProduction(options = {}) {
|
|
|
111
136
|
compiledPath,
|
|
112
137
|
fragmentPath,
|
|
113
138
|
isDynamic: compiled.hasServerScripts,
|
|
114
|
-
hasParams: route.pattern.includes(":") || route.pattern.includes("[")
|
|
139
|
+
hasParams: route.pattern.includes(":") || route.pattern.includes("["),
|
|
140
|
+
prerendered
|
|
115
141
|
});
|
|
116
142
|
console.log(`[stx build] \u2713 ${route.pattern}`);
|
|
117
143
|
} catch (error) {
|
|
144
|
+
if (Object.keys(rule).length)
|
|
145
|
+
throw error;
|
|
118
146
|
console.error(`[stx build] \u2717 ${route.pattern}:`, error instanceof Error ? error.message : error);
|
|
119
147
|
}
|
|
148
|
+
}
|
|
120
149
|
const userPublicSrc = path.resolve(root, publicDir);
|
|
121
150
|
if (fs.existsSync(userPublicSrc)) {
|
|
122
151
|
const { copied, bytes } = copyPublicAssets(userPublicSrc, path.join(outputDir, "public"));
|
|
@@ -133,6 +162,16 @@ export async function buildForProduction(options = {}) {
|
|
|
133
162
|
runtime: runtimeAsset.filename,
|
|
134
163
|
router: routerAsset.filename
|
|
135
164
|
}, manifest = generateManifest(manifestRoutes, assets, outputDir);
|
|
165
|
+
manifest.routeRules = routeRules;
|
|
166
|
+
manifest.routerContainer = routerContainer;
|
|
167
|
+
if (serverApi)
|
|
168
|
+
manifest.apiRoutes = await buildServerApi(root, outputDir, apiOptions);
|
|
169
|
+
if (projectConfig.runtimeConfig) {
|
|
170
|
+
await Bun.write(path.join(outputDir, "server/runtime-config.json"), JSON.stringify(projectConfig.runtimeConfig));
|
|
171
|
+
await generateRuntimeConfigTypes(root, projectConfig.runtimeConfig);
|
|
172
|
+
}
|
|
173
|
+
if (projectConfig._layerGraph)
|
|
174
|
+
await Bun.write(path.join(outputDir, "server/layers.json"), JSON.stringify(layerManifest(projectConfig._layerGraph), null, 2));
|
|
136
175
|
writeManifest(manifest, outputDir);
|
|
137
176
|
const duration = Date.now() - startTime;
|
|
138
177
|
console.log(`
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RuntimeConfigDefaults } from './runtime-config-server';
|
|
1
2
|
/**
|
|
2
3
|
* Start the production server.
|
|
3
4
|
*
|
|
@@ -7,13 +8,15 @@
|
|
|
7
8
|
* - Static pages: served directly (zero processing)
|
|
8
9
|
* - Dynamic pages: hydrated with request-time data
|
|
9
10
|
*/
|
|
10
|
-
export declare function startProductionServer(options?: ProductionServerOptions): Promise<{ port: number, stop: () => void }>;
|
|
11
|
+
export declare function startProductionServer(options?: ProductionServerOptions): Promise<{ port: number, stop: () => void, invalidate: (pathname?: string) => void }>;
|
|
11
12
|
/**
|
|
12
13
|
* Production server configuration.
|
|
13
14
|
*/
|
|
14
15
|
export declare interface ProductionServerOptions {
|
|
15
16
|
outputDir?: string
|
|
16
17
|
port?: number
|
|
18
|
+
runtimeConfig?: RuntimeConfigDefaults
|
|
17
19
|
onRequest?: (req: Request) => Response | Promise<Response> | null | Promise<null>
|
|
18
20
|
apiRoutes?: Record<string, (req: Request) => Response | Promise<Response>>
|
|
21
|
+
apiRouter?: { handleRequest: (request: Request) => Response | Promise<Response> }
|
|
19
22
|
}
|
|
@@ -2,13 +2,17 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { serve } from "bun";
|
|
4
4
|
import { loadManifest } from "./manifest.js";
|
|
5
|
-
import { hydrateTemplateStream
|
|
6
|
-
import { extractLayoutMetadata } from "./app-shell.js";
|
|
5
|
+
import { hydrateTemplateStream } from "./template-hydrator.js";
|
|
6
|
+
import { extractContainerContent, extractLayoutMetadata } from "./app-shell.js";
|
|
7
7
|
import { pageShipsSignalsRuntime } from "./runtime-injection.js";
|
|
8
8
|
import { patternToRegex } from "stx-router";
|
|
9
9
|
import { compressResponse } from "./compression.js";
|
|
10
10
|
import { actionRedirectResponse, isActionableMethod } from "./page-action.js";
|
|
11
11
|
import { FRAGMENT_CACHE_CONTROL, isSpaNavRequest, spaNavVaryHeaders } from "./spa-nav.js";
|
|
12
|
+
import { createRouteRuleResolver } from "./route-rules.js";
|
|
13
|
+
import { RouteResponseCache } from "./route-response-cache.js";
|
|
14
|
+
import { productionApiDispatcher } from "./server-api.js";
|
|
15
|
+
import { injectRuntimeConfig, resolveRuntimeConfig, withRuntimeConfig } from "./runtime-config-server.js";
|
|
12
16
|
const MIME_TYPES = {
|
|
13
17
|
".js": "application/javascript",
|
|
14
18
|
".mjs": "application/javascript",
|
|
@@ -39,22 +43,26 @@ const MIME_TYPES = {
|
|
|
39
43
|
".eot": "application/vnd.ms-fontobject"
|
|
40
44
|
};
|
|
41
45
|
export async function startProductionServer(options = {}) {
|
|
42
|
-
const outputDir = path.resolve(options.outputDir || ".output"), port = options.port
|
|
46
|
+
const outputDir = path.resolve(options.outputDir || ".output"), port = options.port ?? 3000, manifest = loadManifest(outputDir);
|
|
43
47
|
if (!manifest) {
|
|
44
48
|
console.error("[stx] No build manifest found. Run `stx build` first.");
|
|
45
49
|
process.exit(1);
|
|
46
50
|
}
|
|
47
51
|
console.log(`[stx] Production server loading ${manifest.routes.length} routes...`);
|
|
48
|
-
const compiledTemplates = new Map, fragmentCache = new Map, layoutMetadataCache = new Map, runtimeCache = new Map;
|
|
52
|
+
const resolveRule = createRouteRuleResolver(manifest.routeRules), responseCache = new RouteResponseCache, handleApi = productionApiDispatcher(outputDir, manifest.apiRoutes ?? []), configFile = Bun.file(path.join(outputDir, "server/runtime-config.json")), runtimeDefaults = options.runtimeConfig ?? (await configFile.exists() ? await configFile.json() : void 0), runtimeConfig = runtimeDefaults ? resolveRuntimeConfig(runtimeDefaults) : void 0, compiledTemplates = new Map, fragmentCache = new Map, layoutMetadataCache = new Map, runtimeCache = new Map;
|
|
49
53
|
for (const route of manifest.routes)
|
|
50
54
|
try {
|
|
51
55
|
const compiledPath = path.join(outputDir, route.compiledPath), compiled = JSON.parse(await Bun.file(compiledPath).text());
|
|
56
|
+
if (runtimeConfig)
|
|
57
|
+
compiled.html = injectRuntimeConfig(compiled.html, runtimeConfig);
|
|
52
58
|
compiledTemplates.set(route.pattern, compiled);
|
|
53
59
|
layoutMetadataCache.set(route.pattern, extractLayoutMetadata(compiled.html));
|
|
54
60
|
runtimeCache.set(route.pattern, pageShipsSignalsRuntime(compiled.html));
|
|
55
61
|
const fragmentPath = path.join(outputDir, route.fragmentPath);
|
|
56
|
-
if (await Bun.file(fragmentPath).exists())
|
|
57
|
-
|
|
62
|
+
if (await Bun.file(fragmentPath).exists()) {
|
|
63
|
+
const fragment = await Bun.file(fragmentPath).text();
|
|
64
|
+
fragmentCache.set(route.pattern, runtimeConfig ? injectRuntimeConfig(fragment, runtimeConfig) : fragment);
|
|
65
|
+
}
|
|
58
66
|
} catch (error) {
|
|
59
67
|
console.warn(`[stx] Failed to load route ${route.pattern}:`, error);
|
|
60
68
|
}
|
|
@@ -68,15 +76,23 @@ export async function startProductionServer(options = {}) {
|
|
|
68
76
|
const server = serve({
|
|
69
77
|
port,
|
|
70
78
|
async fetch(request) {
|
|
71
|
-
return compressResponse(request, await (async () => {
|
|
79
|
+
return compressResponse(request, await withRuntimeConfig(runtimeConfig ?? resolveRuntimeConfig(), async () => {
|
|
72
80
|
const pathname = new URL(request.url).pathname;
|
|
73
81
|
if (options.onRequest) {
|
|
74
82
|
const response = await options.onRequest(request);
|
|
75
83
|
if (response)
|
|
76
84
|
return response;
|
|
77
85
|
}
|
|
86
|
+
if (options.apiRouter) {
|
|
87
|
+
const response = await options.apiRouter.handleRequest(request);
|
|
88
|
+
if (response.status !== 404)
|
|
89
|
+
return response;
|
|
90
|
+
}
|
|
78
91
|
if (options.apiRoutes?.[pathname])
|
|
79
92
|
return options.apiRoutes[pathname](request);
|
|
93
|
+
const apiResponse = await handleApi(request);
|
|
94
|
+
if (apiResponse)
|
|
95
|
+
return apiResponse;
|
|
80
96
|
if ((request.method === "GET" || request.method === "HEAD") && pathname !== "/") {
|
|
81
97
|
const publicRoot = path.resolve(outputDir, "public");
|
|
82
98
|
let safePathname;
|
|
@@ -127,82 +143,114 @@ export async function startProductionServer(options = {}) {
|
|
|
127
143
|
}
|
|
128
144
|
return new Response("Not Found", { status: 404 });
|
|
129
145
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
146
|
+
const rule = resolveRule(pathname), controlled = Object.keys(rule).length > 0;
|
|
147
|
+
return responseCache.respond(request, rule.cache, async () => {
|
|
148
|
+
const candidate = compiledTemplates.get(matchedRoute.pattern);
|
|
149
|
+
if (isSpaNav && request.method === "GET" && candidate && !candidate.hasServerScripts && Object.keys(candidate.placeholders).length === 0) {
|
|
150
|
+
const fragment = fragmentCache.get(matchedRoute.pattern);
|
|
151
|
+
if (fragment) {
|
|
152
|
+
const layoutMetadata = layoutMetadataCache.get(matchedRoute.pattern);
|
|
153
|
+
return new Response(fragment, {
|
|
154
|
+
status: candidate.status ?? 200,
|
|
155
|
+
headers: {
|
|
156
|
+
"Content-Type": "text/html",
|
|
157
|
+
"X-STX-Fragment": "true",
|
|
158
|
+
...runtimeCache.has(matchedRoute.pattern) ? { "X-STX-Runtime": runtimeCache.get(matchedRoute.pattern) ? "true" : "false" } : {},
|
|
159
|
+
...layoutMetadata ? {
|
|
160
|
+
"X-STX-Layout": layoutMetadata.layout,
|
|
161
|
+
"X-STX-Layout-Group": layoutMetadata.group
|
|
162
|
+
} : {},
|
|
163
|
+
...spaNavVaryHeaders(),
|
|
164
|
+
...rule.cache ? {} : { "Cache-Control": FRAGMENT_CACHE_CONTROL }
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const isMutating = isActionableMethod(request.method), compiled = compiledTemplates.get(matchedRoute.pattern);
|
|
170
|
+
if (!compiled) {
|
|
171
|
+
const errorPage = exactRoutes.get("/500") || null;
|
|
172
|
+
if (errorPage) {
|
|
173
|
+
const compiledError = compiledTemplates.get(errorPage.pattern);
|
|
174
|
+
if (compiledError)
|
|
175
|
+
return new Response(compiledError.html, {
|
|
176
|
+
status: 500,
|
|
177
|
+
headers: { "Content-Type": "text/html" }
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
181
|
+
}
|
|
182
|
+
if (matchedRoute.prerendered && isMutating)
|
|
183
|
+
return new Response("Prerendered pages do not accept actions", { status: 405, headers: { Allow: "GET, HEAD" } });
|
|
184
|
+
if (!isMutating && !compiled.hasServerScripts && Object.keys(compiled.placeholders).length === 0)
|
|
185
|
+
return new Response(compiled.html, {
|
|
186
|
+
status: compiled.status ?? 200,
|
|
135
187
|
headers: {
|
|
136
188
|
"Content-Type": "text/html",
|
|
137
|
-
"X-STX-Fragment": "true",
|
|
138
|
-
...runtimeCache.has(matchedRoute.pattern) ? { "X-STX-Runtime": runtimeCache.get(matchedRoute.pattern) ? "true" : "false" } : {},
|
|
139
|
-
...layoutMetadata ? {
|
|
140
|
-
"X-STX-Layout": layoutMetadata.layout,
|
|
141
|
-
"X-STX-Layout-Group": layoutMetadata.group
|
|
142
|
-
} : {},
|
|
143
189
|
...spaNavVaryHeaders(),
|
|
144
|
-
"Cache-Control":
|
|
190
|
+
"Cache-Control": "public, max-age=60"
|
|
145
191
|
}
|
|
146
192
|
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
193
|
+
try {
|
|
194
|
+
const { html, boundaries, redirect, cookies, status, headers: pageHeaders } = await hydrateTemplateStream(compiled, {
|
|
195
|
+
params,
|
|
196
|
+
request,
|
|
197
|
+
method: request.method,
|
|
198
|
+
__stx_strict_hydration: controlled,
|
|
199
|
+
__stx_runtime_config: runtimeConfig
|
|
200
|
+
});
|
|
201
|
+
if (redirect)
|
|
202
|
+
return actionRedirectResponse(redirect, cookies, pageHeaders);
|
|
203
|
+
if (boundaries && boundaries.length > 0) {
|
|
204
|
+
const { renderStreamingPage, streamToResponse } = await import("./streaming.js"), headers = new Headers({ ...spaNavVaryHeaders(), ...pageHeaders, "Cache-Control": "private, no-store" });
|
|
205
|
+
for (const cookie of cookies ?? [])
|
|
206
|
+
headers.append("Set-Cookie", cookie);
|
|
207
|
+
if (isSpaNav && !isMutating) {
|
|
208
|
+
const layout = extractLayoutMetadata(html);
|
|
209
|
+
headers.set("X-STX-Fragment", "true");
|
|
210
|
+
headers.set("X-STX-Runtime", pageShipsSignalsRuntime(html) ? "true" : "false");
|
|
211
|
+
headers.set("X-STX-Layout", layout.layout);
|
|
212
|
+
headers.set("X-STX-Layout-Group", layout.group);
|
|
213
|
+
}
|
|
214
|
+
return streamToResponse(renderStreamingPage(isSpaNav && !isMutating ? extractContainerContent(html, manifest.routerContainer || "main") : html, boundaries, { timeoutMs: 30000 }), {
|
|
215
|
+
status: status ?? compiled.status ?? 200,
|
|
216
|
+
headers
|
|
158
217
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
if (!isMutating && !compiled.hasServerScripts && Object.keys(compiled.placeholders).length === 0)
|
|
163
|
-
return new Response(compiled.html, {
|
|
164
|
-
status: compiled.status ?? 200,
|
|
165
|
-
headers: {
|
|
218
|
+
}
|
|
219
|
+
const headers = new Headers({
|
|
166
220
|
"Content-Type": "text/html",
|
|
167
221
|
...spaNavVaryHeaders(),
|
|
168
|
-
"Cache-Control": "
|
|
222
|
+
...rule.cache ? {} : { "Cache-Control": "private, no-store" }
|
|
223
|
+
});
|
|
224
|
+
for (const cookie of cookies ?? [])
|
|
225
|
+
headers.append("Set-Cookie", cookie);
|
|
226
|
+
for (const [name, value] of Object.entries(pageHeaders ?? {}))
|
|
227
|
+
headers.set(name, value);
|
|
228
|
+
headers.set("Vary", spaNavVaryHeaders(headers.get("Vary")).Vary);
|
|
229
|
+
if (isSpaNav && !isMutating) {
|
|
230
|
+
const layout = extractLayoutMetadata(html);
|
|
231
|
+
headers.set("X-STX-Fragment", "true");
|
|
232
|
+
headers.set("X-STX-Runtime", pageShipsSignalsRuntime(html) ? "true" : "false");
|
|
233
|
+
headers.set("X-STX-Layout", layout.layout);
|
|
234
|
+
headers.set("X-STX-Layout-Group", layout.group);
|
|
235
|
+
return new Response(extractContainerContent(html, manifest.routerContainer || "main"), { status: status ?? compiled.status ?? 200, headers });
|
|
169
236
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (redirect)
|
|
178
|
-
return actionRedirectResponse(redirect, cookies, pageHeaders);
|
|
179
|
-
if (boundaries && boundaries.length > 0) {
|
|
180
|
-
const { renderStreamingPage, streamToResponse } = await import("./streaming.js");
|
|
181
|
-
return streamToResponse(renderStreamingPage(html, boundaries, { timeoutMs: 30000 }), {
|
|
182
|
-
status: status ?? compiled.status ?? 200,
|
|
183
|
-
headers: { "Cache-Control": "no-cache", ...pageHeaders }
|
|
237
|
+
return new Response(html, { status: status ?? compiled.status ?? 200, headers });
|
|
238
|
+
} catch (error) {
|
|
239
|
+
console.error(`[stx] Hydration error for ${pathname}:`, error);
|
|
240
|
+
if (controlled)
|
|
241
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
242
|
+
return new Response(compiled.html, {
|
|
243
|
+
headers: { "Content-Type": "text/html" }
|
|
184
244
|
});
|
|
185
245
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
...spaNavVaryHeaders(),
|
|
189
|
-
"Cache-Control": "no-cache"
|
|
190
|
-
});
|
|
191
|
-
for (const cookie of cookies ?? [])
|
|
192
|
-
headers.append("Set-Cookie", cookie);
|
|
193
|
-
for (const [name, value] of Object.entries(pageHeaders ?? {}))
|
|
194
|
-
headers.set(name, value);
|
|
195
|
-
return new Response(html, { status: status ?? compiled.status ?? 200, headers });
|
|
196
|
-
} catch (error) {
|
|
197
|
-
console.error(`[stx] Hydration error for ${pathname}:`, error);
|
|
198
|
-
return new Response(compiled.html, {
|
|
199
|
-
headers: { "Content-Type": "text/html" }
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
})());
|
|
246
|
+
});
|
|
247
|
+
}));
|
|
203
248
|
}
|
|
204
249
|
});
|
|
205
|
-
console.log(`[stx] Production server running at http://localhost:${port}`);
|
|
250
|
+
console.log(`[stx] Production server running at http://localhost:${server.port}`);
|
|
206
251
|
console.log(`[stx] Serving ${manifest.routes.length} routes (${compiledTemplates.size} pre-loaded)`);
|
|
207
|
-
return { port, stop: () =>
|
|
252
|
+
return { port: server.port, stop: () => {
|
|
253
|
+
responseCache.invalidate();
|
|
254
|
+
server.stop();
|
|
255
|
+
}, invalidate: (pathname) => responseCache.invalidate(pathname) };
|
|
208
256
|
}
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
3
|
-
Icon generation requires the sharp package for image processing.`),q.success=!1,q}let R=await y.default(Y).metadata();if(R.width&&R.width<512)q.warnings.push(`Source icon is ${R.width}x${R.height}. Recommend using at least 512x512 for best quality.`);for(let $ of X){let x=L.join(Q,`icon-${$}x${$}.png`);if(await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x),j){let F=L.join(Q,`icon-${$}x${$}.webp`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(F),q.generatedFiles.push(F)}}if(J){for(let x of v){let F=L.join(Q,`apple-touch-icon-${x}x${x}.png`);await y.default(Y).resize(x,x,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(F),q.generatedFiles.push(F)}let $=L.join(Q,"apple-touch-icon.png");await y.default(Y).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile($),q.generatedFiles.push($)}for(let $ of I){let x=L.join(Q,`favicon-${$}x${$}.png`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x)}let U=512,T=L.join(Q,`icon-maskable-${U}x${U}.png`),Z=Math.floor(U*0.1),_=U-Z*2;await y.default(Y).resize(_,_,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:Z,bottom:Z,left:Z,right:Z,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(T),q.generatedFiles.push(T)}catch(y){let V=y instanceof Error?y.message:String(y);q.errors.push(`Icon generation failed: ${V}`),q.success=!1}return q}function n(G){let B=G.sizes||k,q=G.outputDir?`/${G.outputDir}`:"/pwa-icons",K=G.generateWebP??!0,Y=G.generateAppleIcons??!0,Q=[];for(let X of B)if(Q.push(`${q}/icon-${X}x${X}.png`),K)Q.push(`${q}/icon-${X}x${X}.webp`);if(Y){Q.push(`${q}/apple-touch-icon.png`);for(let X of v)Q.push(`${q}/apple-touch-icon-${X}x${X}.png`)}for(let X of I)Q.push(`${q}/favicon-${X}x${X}.png`);return Q.push(`${q}/icon-maskable-512x512.png`),Q}async function O(){try{return await import("sharp"),!0}catch{return!1}}function m(G,B,q,K){let Y=[],Q=K.join(" ");for(let X of G)if(Y.push({src:`${B}/icon-${X}x${X}.png`,sizes:`${X}x${X}`,type:"image/png",purpose:Q}),q)Y.push({src:`${B}/icon-${X}x${X}.webp`,sizes:`${X}x${X}`,type:"image/webp",purpose:Q});return Y}function g(G){return G.map((B)=>({name:B.name,short_name:B.shortName,description:B.description,url:B.url,icons:B.icons?.map((q)=>({src:q.src,sizes:q.sizes,type:q.type}))}))}function h(G){let B=G.pwa?.shareTarget;if(!B?.enabled)return;let q={action:B.action||"/share",method:B.method||"POST",enctype:B.enctype||"multipart/form-data",params:{title:B.params?.title||"title",text:B.params?.text||"text",url:B.params?.url||"url"}};if(B.acceptFiles&&B.acceptFiles.length>0)q.params.files=B.acceptFiles.map((K)=>({name:K.name,accept:K.accept}));return q}function c(G){let B=G.pwa?.fileHandlers;if(!B?.enabled||!B.accept)return;let q=[{action:B.action||"/",accept:B.accept,launch_type:B.launchType||"single-client"}];if(B.icons)q[0].icons=B.icons.map((K)=>({src:K.src,sizes:K.sizes,type:K.type}));return q}function l(G){let B=G.pwa?.protocolHandlers;if(!B||B.length===0)return;return B.map((q)=>({protocol:q.protocol,url:q.url}))}function u(G){let B=G.pwa;if(!B?.enabled||!B.manifest)return null;let{manifest:q,icons:K}=B,Y=K?.sizes||[72,96,128,144,152,192,384,512],Q=K?.outputDir?`/${K.outputDir}`:"/pwa-icons",X=K?.generateWebP??!0,j=K?.purpose||["any","maskable"],J={name:q.name,short_name:q.shortName||q.name,description:q.description,start_url:q.startUrl||"/",display:q.display||"standalone",display_override:q.displayOverride,orientation:q.orientation,theme_color:q.themeColor,background_color:q.backgroundColor,scope:q.scope||"/",lang:q.lang,dir:q.dir,id:q.id,categories:q.categories,icons:m(Y,Q,X,j)};if(q.shortcuts&&q.shortcuts.length>0)J.shortcuts=g(q.shortcuts);if(q.screenshots&&q.screenshots.length>0)J.screenshots=q.screenshots.map((U)=>({src:U.src,sizes:U.sizes,type:U.type,label:U.label,form_factor:U.platform}));let y=h(G);if(y)J.share_target=y;let V=c(G);if(V)J.file_handlers=V;let R=l(G);if(R)J.protocol_handlers=R;if(q.launchHandler)J.launch_handler={client_mode:q.launchHandler};if(q.handleLinks)J.handle_links=q.handleLinks;if(q.edgeSidePanel?.enabled)J.edge_side_panel={preferred_width:q.edgeSidePanel.preferredWidth};return J}function M(G){let B=u(G);if(!B)return"";let q=JSON.parse(JSON.stringify(B));return JSON.stringify(q,null,2)}function i(G,B){return{...B,...G,shortcuts:G.shortcuts||B.shortcuts,screenshots:G.screenshots||B.screenshots,categories:G.categories||B.categories}}function s(G){let B=[],q=G.pwa;if(!q?.enabled)return B;let K=q.manifest;if(!K)return B.push("PWA manifest configuration is missing"),B;if(!K.name)B.push("Manifest name is required");let Y=["fullscreen","standalone","minimal-ui","browser"];if(K.display&&!Y.includes(K.display))B.push(`Invalid display mode: ${K.display}. Must be one of: ${Y.join(", ")}`);let Q=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(K.orientation&&!Q.includes(K.orientation))B.push(`Invalid orientation: ${K.orientation}`);let X=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(K.themeColor&&!X.test(K.themeColor))B.push(`Invalid theme color: ${K.themeColor}. Must be a valid hex color.`);if(K.backgroundColor&&!X.test(K.backgroundColor))B.push(`Invalid background color: ${K.backgroundColor}. Must be a valid hex color.`);if(q.shareTarget?.enabled){if(!q.shareTarget.action)B.push("Share target action URL is required")}if(q.fileHandlers?.enabled){if(!q.fileHandlers.accept||Object.keys(q.fileHandlers.accept).length===0)B.push("File handlers must specify accepted MIME types")}if(q.protocolHandlers)for(let j of q.protocolHandlers){if(!j.protocol)B.push("Protocol handler missing protocol");if(!j.url||!j.url.includes("%s"))B.push(`Protocol handler URL must contain %s placeholder: ${j.protocol}`)}return B}import A from"path";async function b(G){let B=G.pwa?.offline;if(!B?.enabled)return"";if(B.page){let q=A.isAbsolute(B.page)?B.page:A.resolve(process.cwd(),B.page);if(await Bun.file(q).exists())try{let{processDirectives:K}=await import("./chunk-
|
|
2
|
+
import{Ok as wq,Pk as dq,Qk as Cq,Rk as mq,Sk as gq}from"./chunk-m3a20mmb.js";import{$k as w,Tk as S,Uk as Tq,Vk as _q,Wk as z,Xk as D,Yk as P,Zk as kq,_k as vq,al as Iq,bl as d,cl as Hq,dl as Oq,el as Mq}from"./chunk-7skk34dh.js";import{Vv as Aq,Wv as bq,Xv as Sq,Yv as zq,Zv as Dq,_v as Pq}from"./chunk-fp7ms6e7.js";import{cw as N}from"./chunk-jp2f8yzw.js";import p from"fs";import E from"path";import C from"fs";import L from"path";var k=[72,96,128,144,152,192,384,512],v=[120,152,167,180],I=[16,32];async function H(G,B){let q={success:!0,generatedFiles:[],errors:[],warnings:[]},K=G.pwa?.icons;if(!K?.src)return q.errors.push("No source icon specified in pwa.icons.src"),q.success=!1,q;let Y=L.isAbsolute(K.src)?K.src:L.resolve(process.cwd(),K.src);if(!await Bun.file(Y).exists())return q.errors.push(`Source icon not found: ${Y}`),q.success=!1,q;let Q=L.resolve(B,K.outputDir||"pwa-icons");try{C.mkdirSync(Q,{recursive:!0})}catch{return q.errors.push(`Failed to create output directory: ${Q}`),q.success=!1,q}let X=K.sizes||k,j=K.generateWebP??!0,J=K.generateAppleIcons??!0;try{let y;try{y=await import("sharp")}catch{return q.errors.push(`sharp is not installed. Install it with: bun add sharp
|
|
3
|
+
Icon generation requires the sharp package for image processing.`),q.success=!1,q}let R=await y.default(Y).metadata();if(R.width&&R.width<512)q.warnings.push(`Source icon is ${R.width}x${R.height}. Recommend using at least 512x512 for best quality.`);for(let $ of X){let x=L.join(Q,`icon-${$}x${$}.png`);if(await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x),j){let F=L.join(Q,`icon-${$}x${$}.webp`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(F),q.generatedFiles.push(F)}}if(J){for(let x of v){let F=L.join(Q,`apple-touch-icon-${x}x${x}.png`);await y.default(Y).resize(x,x,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(F),q.generatedFiles.push(F)}let $=L.join(Q,"apple-touch-icon.png");await y.default(Y).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile($),q.generatedFiles.push($)}for(let $ of I){let x=L.join(Q,`favicon-${$}x${$}.png`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x)}let U=512,T=L.join(Q,`icon-maskable-${U}x${U}.png`),Z=Math.floor(U*0.1),_=U-Z*2;await y.default(Y).resize(_,_,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:Z,bottom:Z,left:Z,right:Z,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(T),q.generatedFiles.push(T)}catch(y){let V=y instanceof Error?y.message:String(y);q.errors.push(`Icon generation failed: ${V}`),q.success=!1}return q}function n(G){let B=G.sizes||k,q=G.outputDir?`/${G.outputDir}`:"/pwa-icons",K=G.generateWebP??!0,Y=G.generateAppleIcons??!0,Q=[];for(let X of B)if(Q.push(`${q}/icon-${X}x${X}.png`),K)Q.push(`${q}/icon-${X}x${X}.webp`);if(Y){Q.push(`${q}/apple-touch-icon.png`);for(let X of v)Q.push(`${q}/apple-touch-icon-${X}x${X}.png`)}for(let X of I)Q.push(`${q}/favicon-${X}x${X}.png`);return Q.push(`${q}/icon-maskable-512x512.png`),Q}async function O(){try{return await import("sharp"),!0}catch{return!1}}function m(G,B,q,K){let Y=[],Q=K.join(" ");for(let X of G)if(Y.push({src:`${B}/icon-${X}x${X}.png`,sizes:`${X}x${X}`,type:"image/png",purpose:Q}),q)Y.push({src:`${B}/icon-${X}x${X}.webp`,sizes:`${X}x${X}`,type:"image/webp",purpose:Q});return Y}function g(G){return G.map((B)=>({name:B.name,short_name:B.shortName,description:B.description,url:B.url,icons:B.icons?.map((q)=>({src:q.src,sizes:q.sizes,type:q.type}))}))}function h(G){let B=G.pwa?.shareTarget;if(!B?.enabled)return;let q={action:B.action||"/share",method:B.method||"POST",enctype:B.enctype||"multipart/form-data",params:{title:B.params?.title||"title",text:B.params?.text||"text",url:B.params?.url||"url"}};if(B.acceptFiles&&B.acceptFiles.length>0)q.params.files=B.acceptFiles.map((K)=>({name:K.name,accept:K.accept}));return q}function c(G){let B=G.pwa?.fileHandlers;if(!B?.enabled||!B.accept)return;let q=[{action:B.action||"/",accept:B.accept,launch_type:B.launchType||"single-client"}];if(B.icons)q[0].icons=B.icons.map((K)=>({src:K.src,sizes:K.sizes,type:K.type}));return q}function l(G){let B=G.pwa?.protocolHandlers;if(!B||B.length===0)return;return B.map((q)=>({protocol:q.protocol,url:q.url}))}function u(G){let B=G.pwa;if(!B?.enabled||!B.manifest)return null;let{manifest:q,icons:K}=B,Y=K?.sizes||[72,96,128,144,152,192,384,512],Q=K?.outputDir?`/${K.outputDir}`:"/pwa-icons",X=K?.generateWebP??!0,j=K?.purpose||["any","maskable"],J={name:q.name,short_name:q.shortName||q.name,description:q.description,start_url:q.startUrl||"/",display:q.display||"standalone",display_override:q.displayOverride,orientation:q.orientation,theme_color:q.themeColor,background_color:q.backgroundColor,scope:q.scope||"/",lang:q.lang,dir:q.dir,id:q.id,categories:q.categories,icons:m(Y,Q,X,j)};if(q.shortcuts&&q.shortcuts.length>0)J.shortcuts=g(q.shortcuts);if(q.screenshots&&q.screenshots.length>0)J.screenshots=q.screenshots.map((U)=>({src:U.src,sizes:U.sizes,type:U.type,label:U.label,form_factor:U.platform}));let y=h(G);if(y)J.share_target=y;let V=c(G);if(V)J.file_handlers=V;let R=l(G);if(R)J.protocol_handlers=R;if(q.launchHandler)J.launch_handler={client_mode:q.launchHandler};if(q.handleLinks)J.handle_links=q.handleLinks;if(q.edgeSidePanel?.enabled)J.edge_side_panel={preferred_width:q.edgeSidePanel.preferredWidth};return J}function M(G){let B=u(G);if(!B)return"";let q=JSON.parse(JSON.stringify(B));return JSON.stringify(q,null,2)}function i(G,B){return{...B,...G,shortcuts:G.shortcuts||B.shortcuts,screenshots:G.screenshots||B.screenshots,categories:G.categories||B.categories}}function s(G){let B=[],q=G.pwa;if(!q?.enabled)return B;let K=q.manifest;if(!K)return B.push("PWA manifest configuration is missing"),B;if(!K.name)B.push("Manifest name is required");let Y=["fullscreen","standalone","minimal-ui","browser"];if(K.display&&!Y.includes(K.display))B.push(`Invalid display mode: ${K.display}. Must be one of: ${Y.join(", ")}`);let Q=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(K.orientation&&!Q.includes(K.orientation))B.push(`Invalid orientation: ${K.orientation}`);let X=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(K.themeColor&&!X.test(K.themeColor))B.push(`Invalid theme color: ${K.themeColor}. Must be a valid hex color.`);if(K.backgroundColor&&!X.test(K.backgroundColor))B.push(`Invalid background color: ${K.backgroundColor}. Must be a valid hex color.`);if(q.shareTarget?.enabled){if(!q.shareTarget.action)B.push("Share target action URL is required")}if(q.fileHandlers?.enabled){if(!q.fileHandlers.accept||Object.keys(q.fileHandlers.accept).length===0)B.push("File handlers must specify accepted MIME types")}if(q.protocolHandlers)for(let j of q.protocolHandlers){if(!j.protocol)B.push("Protocol handler missing protocol");if(!j.url||!j.url.includes("%s"))B.push(`Protocol handler URL must contain %s placeholder: ${j.protocol}`)}return B}import A from"path";async function b(G){let B=G.pwa?.offline;if(!B?.enabled)return"";if(B.page){let q=A.isAbsolute(B.page)?B.page:A.resolve(process.cwd(),B.page);if(await Bun.file(q).exists())try{let{processDirectives:K}=await import("./chunk-rst1rw09.js"),Y=await Bun.file(q).text();return await K(Y,{},q,G,new Set)}catch(K){console.warn(`[PWA] Failed to process custom offline page: ${K}`)}else console.warn(`[PWA] Custom offline page not found: ${q}`)}return f(G)}function f(G){let B=G.pwa?.offline,q=G.pwa?.manifest,K=B?.fallbackTitle||"You are offline",Y=B?.fallbackMessage||"Please check your internet connection and try again.",Q=q?.themeColor||"#4f46e5",X=q?.shortName||q?.name||"App";return`<!DOCTYPE html>
|
|
4
4
|
<html lang="en">
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="UTF-8">
|
package/dist/render.js
CHANGED
|
@@ -6,6 +6,7 @@ import { extractBridgeData, processClientScript } from "./client-script.js";
|
|
|
6
6
|
import { findSfcTemplateBlock } from "./sfc-template.js";
|
|
7
7
|
import { isMarkdownPath, renderMarkdownView } from "./markdown-view.js";
|
|
8
8
|
import { responseBindings, syncRecordedResponse } from "./page-response.js";
|
|
9
|
+
import { serverDataScope } from "./server-data.js";
|
|
9
10
|
function parseTemplate(content) {
|
|
10
11
|
let workingContent = content;
|
|
11
12
|
const templateBlock = findSfcTemplateBlock(content);
|
|
@@ -73,8 +74,14 @@ export async function renderTemplate(filePath, renderOptions = {}) {
|
|
|
73
74
|
const layoutPath = resolve(renderOptions.layout), layoutFile = Bun.file(layoutPath);
|
|
74
75
|
if (!await layoutFile.exists())
|
|
75
76
|
throw Error(`Layout template not found: ${layoutPath}`);
|
|
76
|
-
const { layout, injectCSS, ...pageOptions } = renderOptions,
|
|
77
|
-
|
|
77
|
+
const { layout, injectCSS, ...pageOptions } = renderOptions, sharedContext = { ...renderOptions.context || {} };
|
|
78
|
+
serverDataScope(sharedContext);
|
|
79
|
+
const pageHtml = await renderTemplateString(content, resolvedPath, {
|
|
80
|
+
...pageOptions,
|
|
81
|
+
context: { ...sharedContext, __stx_defer_server_data: !0 },
|
|
82
|
+
injectCSS: !1
|
|
83
|
+
}), layoutContent = await layoutFile.text(), layoutContext = {
|
|
84
|
+
...sharedContext,
|
|
78
85
|
content: pageHtml
|
|
79
86
|
}, layoutOptions = {
|
|
80
87
|
...pageOptions,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RouteCacheRule } from './route-rules';
|
|
2
|
+
/** Process-local, bounded origin cache; never caches actions or personalized responses. */
|
|
3
|
+
export declare class RouteResponseCache {
|
|
4
|
+
constructor(now?: () => number);
|
|
5
|
+
invalidate(pathname?: string): void;
|
|
6
|
+
respond(request: Request, policy: RouteCacheRule | false | undefined, render: () => Promise<Response>): Promise<Response>;
|
|
7
|
+
}
|