@stacksjs/stx 0.2.454 → 0.2.456
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/app-service-worker.d.ts +4 -1
- package/dist/chunk-087t6m0p.js +2 -0
- package/dist/chunk-0bdgcm01.js +2 -0
- package/dist/{chunk-yx37nrgr.js → chunk-0trfbqa7.js} +4 -4
- package/dist/{chunk-8ah8npj3.js → chunk-0v5dpk7r.js} +1 -1
- package/dist/{chunk-47jq9j1w.js → chunk-0vgfe5bf.js} +2 -2
- package/dist/chunk-143gpdxy.js +2 -0
- package/dist/{chunk-w8ek4fe8.js → chunk-1sdtg9np.js} +2 -2
- package/dist/chunk-1vgmzmsw.js +2 -0
- package/dist/{chunk-4q366fhp.js → chunk-28qkwe2b.js} +5 -5
- package/dist/{chunk-7mbx7dzg.js → chunk-2bdthb37.js} +2 -2
- package/dist/{chunk-149r1q6c.js → chunk-2cy956js.js} +2 -2
- package/dist/{chunk-2428rqy1.js → chunk-2d1n2fsz.js} +14 -7
- package/dist/chunk-2hddf9pn.js +2 -0
- package/dist/chunk-2zh91zea.js +2 -0
- package/dist/chunk-3227dnct.js +2 -0
- package/dist/chunk-32t5agpk.js +2 -0
- package/dist/chunk-33kwpw1a.js +4 -0
- package/dist/chunk-3ar8gdyd.js +2 -0
- package/dist/chunk-3s2vnqcf.js +2 -0
- package/dist/{chunk-hhjff2r8.js → chunk-44msrx2e.js} +3 -3
- package/dist/{chunk-0tchj3ct.js → chunk-462jmw0a.js} +6 -6
- package/dist/chunk-491pm0a9.js +2 -0
- package/dist/{chunk-g8k5rsqq.js → chunk-4fa3jec9.js} +12 -12
- package/dist/chunk-4henqdjf.js +2 -0
- package/dist/chunk-4qv9me8f.js +2 -0
- package/dist/chunk-561yczfn.js +2 -0
- package/dist/chunk-58n62bxb.js +3 -0
- package/dist/chunk-5arm42dc.js +17 -0
- package/dist/chunk-5hhrbzam.js +2 -0
- package/dist/chunk-5m8q7c5r.js +2 -0
- package/dist/{chunk-pkpmyr0x.js → chunk-5p56w2ke.js} +3 -3
- package/dist/chunk-5pjsc9zv.js +3 -0
- package/dist/{chunk-n9jn3qzw.js → chunk-5qns2sdz.js} +2 -2
- package/dist/chunk-68txmj8d.js +2 -0
- package/dist/{chunk-45rfv3a5.js → chunk-6cp3afft.js} +2 -2
- package/dist/chunk-6qv189mb.js +2 -0
- package/dist/{chunk-dwp3knc4.js → chunk-6r2709dj.js} +3 -3
- package/dist/{chunk-81v9crqy.js → chunk-6wpm3r4h.js} +1 -1
- package/dist/chunk-7rv3nvfh.js +2 -0
- package/dist/chunk-7tt84v1y.js +3 -0
- package/dist/{chunk-33xh91s8.js → chunk-7xeb9szc.js} +2 -2
- package/dist/chunk-8efg91ak.js +4 -0
- package/dist/chunk-8j16292d.js +33 -0
- package/dist/{chunk-qbhbe9cw.js → chunk-8nrttk4f.js} +5 -5
- package/dist/{chunk-73h7qjgq.js → chunk-8xz8t9xp.js} +2 -2
- package/dist/chunk-9t50hw97.js +2 -0
- package/dist/chunk-9z22zs86.js +2 -0
- package/dist/chunk-a32kqsff.js +2 -0
- package/dist/{chunk-19h1j59a.js → chunk-ab56jdah.js} +1 -1
- package/dist/chunk-arvst4wq.js +2 -0
- package/dist/chunk-b70kzmyd.js +3 -0
- package/dist/{chunk-0xztxj98.js → chunk-bq2e9qf6.js} +3 -3
- package/dist/{chunk-aem9hs8n.js → chunk-br1gra4w.js} +2 -2
- package/dist/{chunk-hqywyyez.js → chunk-c491hsm1.js} +5 -5
- package/dist/{chunk-jn8tj4kn.js → chunk-d3mpxr3s.js} +4 -4
- package/dist/chunk-d3zpz5r0.js +2 -0
- package/dist/{chunk-rbkna5rw.js → chunk-d4f1bxtt.js} +11 -11
- package/dist/{chunk-849wf19d.js → chunk-dxxs52yw.js} +3 -3
- package/dist/chunk-ef0gstkd.js +2 -0
- package/dist/{chunk-zqzv5jy2.js → chunk-exgyf65a.js} +4 -4
- package/dist/chunk-f0nf5p60.js +2 -0
- package/dist/{chunk-538h1sfc.js → chunk-f4c39nfh.js} +2 -2
- package/dist/{chunk-s5drjm2j.js → chunk-gkqxnetc.js} +6 -6
- package/dist/chunk-gp5n35mt.js +2 -0
- package/dist/{chunk-axydabse.js → chunk-h9e032kq.js} +3 -3
- package/dist/chunk-ha5z623e.js +2 -0
- package/dist/chunk-hehtgsrt.js +2 -0
- package/dist/chunk-hqzq3a61.js +2 -0
- package/dist/chunk-hskrxdcc.js +2 -0
- package/dist/chunk-hsv23bw6.js +2 -0
- package/dist/chunk-hvx3pc13.js +2 -0
- package/dist/chunk-hz3r02zb.js +2 -0
- package/dist/chunk-jdhs9w6h.js +2 -0
- package/dist/{chunk-vraddzkf.js → chunk-jepq6316.js} +4 -4
- package/dist/{chunk-3pc22sve.js → chunk-jfra00dj.js} +6 -6
- package/dist/{chunk-b5wh10s9.js → chunk-jnmngqs9.js} +78 -78
- package/dist/chunk-jv9xhgvy.js +2 -0
- package/dist/{chunk-dqr5n49p.js → chunk-jz7pvh7b.js} +2 -2
- package/dist/chunk-kcs71ks8.js +2 -0
- package/dist/{chunk-26wmppja.js → chunk-kppgyqwb.js} +1 -1
- package/dist/{chunk-fmj4xvqm.js → chunk-mhpsz5m0.js} +5 -5
- package/dist/chunk-mrk31q6x.js +2 -0
- package/dist/{chunk-b1q5sh7x.js → chunk-n1dyjhte.js} +3 -3
- package/dist/chunk-n38wvr7z.js +2831 -0
- package/dist/{chunk-mnz6bdp3.js → chunk-n866vbgj.js} +5 -5
- package/dist/chunk-n8hd5qap.js +2 -0
- package/dist/{chunk-s59r34p5.js → chunk-nmf12mx3.js} +4 -4
- package/dist/chunk-nqvb9094.js +2 -0
- package/dist/{chunk-9zbjk8pg.js → chunk-nww25qj9.js} +8 -8
- package/dist/chunk-p1mvzdhy.js +2 -0
- package/dist/chunk-pdqt4me8.js +2 -0
- package/dist/chunk-pe214qcn.js +2 -0
- package/dist/chunk-pqxhn8nj.js +2 -0
- package/dist/{chunk-4yyzje7d.js → chunk-pw34r8r5.js} +1 -1
- package/dist/chunk-q6pet6hn.js +2 -0
- package/dist/chunk-q98v7bhs.js +2 -0
- package/dist/chunk-qk6nasfm.js +2 -0
- package/dist/{chunk-d1xbamr1.js → chunk-qn2mx2js.js} +2 -2
- package/dist/{chunk-5xj1df83.js → chunk-r6pax860.js} +7 -7
- package/dist/{chunk-rdq113p4.js → chunk-r80km6mn.js} +2 -2
- package/dist/{chunk-tehvry9a.js → chunk-rcr57c30.js} +10 -10
- package/dist/{chunk-8fj8sm1a.js → chunk-ree9weje.js} +2 -2
- package/dist/{chunk-x4ztj64h.js → chunk-rgwvqmhh.js} +2 -2
- package/dist/{chunk-tn85vr56.js → chunk-rvgvt161.js} +2 -2
- package/dist/{chunk-z68rb7qp.js → chunk-s07kcpc3.js} +5 -5
- package/dist/chunk-sb9nkthv.js +2 -0
- package/dist/chunk-sk1pm2d1.js +11 -0
- package/dist/{chunk-yfd0e7dr.js → chunk-tbjyp03h.js} +1 -1
- package/dist/{chunk-g2afpsw0.js → chunk-tpeyn7wr.js} +2 -2
- package/dist/{chunk-s6e8mmk1.js → chunk-tpvc8xnk.js} +6 -6
- package/dist/chunk-tr7dz5g5.js +2 -0
- package/dist/{chunk-5cyme1g0.js → chunk-v3yqeh15.js} +2 -2
- package/dist/chunk-vc1816wk.js +2 -0
- package/dist/{chunk-9ndzk9r4.js → chunk-vg7wfkt5.js} +3 -3
- package/dist/chunk-vrvnctex.js +2 -0
- package/dist/{chunk-afhkvj3k.js → chunk-w1zvh5y7.js} +2 -2
- package/dist/chunk-wpmzsmrj.js +2 -0
- package/dist/chunk-wywv3kj8.js +2 -0
- package/dist/chunk-xfr3acjk.js +2 -0
- package/dist/chunk-xjqq3jrx.js +2 -0
- package/dist/chunk-xq2v4jpx.js +2 -0
- package/dist/{chunk-3nydw825.js → chunk-y2v0hny6.js} +8 -8
- package/dist/{chunk-56rk985x.js → chunk-y3cqh2jv.js} +3 -3
- package/dist/{chunk-697zcjzg.js → chunk-y8zt1j3h.js} +12 -12
- package/dist/chunk-yyfv2snf.js +2 -0
- package/dist/{chunk-0vbpcef6.js → chunk-z2daw0th.js} +4 -4
- package/dist/{chunk-nw8p8eg9.js → chunk-z3etxty5.js} +5 -5
- package/dist/{chunk-g3h7j2n7.js → chunk-z80d9dd2.js} +2 -2
- package/dist/chunk-z990jtmx.js +2 -0
- package/dist/{chunk-jwpcck1b.js → chunk-zydg3wgt.js} +2 -2
- package/dist/cli.js +20 -20
- package/dist/client-script.d.ts +0 -21
- package/dist/client-script.js +21 -0
- package/dist/composable-loader.js +41 -17
- package/dist/compression.js +25 -6
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/html-masking.js +36 -8
- package/dist/i18n.js +4 -3
- package/dist/includes.js +6 -2
- package/dist/misc-directives.d.ts +0 -10
- package/dist/misc-directives.js +12 -0
- package/dist/offline/app-service-worker.d.ts +4 -1
- package/dist/offline/app-service-worker.js +62 -27
- package/dist/process.js +4 -0
- package/dist/pwa.js +3 -3
- package/dist/signals.js +8 -1
- package/dist/source-signature.d.ts +5 -2
- package/dist/source-signature.js +7 -0
- package/dist/ssg.js +8 -8
- package/dist/store-loader.js +2 -1
- package/dist/utils.js +27 -15
- package/package.json +5 -5
- package/dist/chunk-14x69rt4.js +0 -2
- package/dist/chunk-1kmd0g1k.js +0 -3
- package/dist/chunk-3wezvz6m.js +0 -2
- package/dist/chunk-5402rpwg.js +0 -2
- package/dist/chunk-58ymq1h4.js +0 -2
- package/dist/chunk-5rtbs8zv.js +0 -2
- package/dist/chunk-5tx1wqns.js +0 -2
- package/dist/chunk-6fw3rfcj.js +0 -2
- package/dist/chunk-6nfecsbt.js +0 -2
- package/dist/chunk-6sw7sxh2.js +0 -17
- package/dist/chunk-7qbv0xh6.js +0 -2
- package/dist/chunk-7vdsd9rn.js +0 -2
- package/dist/chunk-8gk34047.js +0 -2
- package/dist/chunk-8nsfkr5n.js +0 -2
- package/dist/chunk-90562q79.js +0 -3
- package/dist/chunk-a1dggchm.js +0 -2
- package/dist/chunk-a1kv42kp.js +0 -2
- package/dist/chunk-a5695s8k.js +0 -2
- package/dist/chunk-avjgetkh.js +0 -2
- package/dist/chunk-bcgth8qf.js +0 -2
- package/dist/chunk-bemksdz5.js +0 -33
- package/dist/chunk-br3ktpyq.js +0 -2
- package/dist/chunk-by1s70jp.js +0 -2
- package/dist/chunk-cwc3p6p7.js +0 -2
- package/dist/chunk-e593pr1r.js +0 -2
- package/dist/chunk-e8y69gg0.js +0 -2
- package/dist/chunk-eam7eann.js +0 -2
- package/dist/chunk-ej7m406s.js +0 -2
- package/dist/chunk-es85mgdw.js +0 -2
- package/dist/chunk-fa5x9zbk.js +0 -2
- package/dist/chunk-fkrzsk74.js +0 -2
- package/dist/chunk-fm3k5v8s.js +0 -2
- package/dist/chunk-fmc9fj4a.js +0 -2
- package/dist/chunk-fn863yek.js +0 -2
- package/dist/chunk-fv30avp2.js +0 -2
- package/dist/chunk-gpmk4s4f.js +0 -2
- package/dist/chunk-hd64hz1n.js +0 -2
- package/dist/chunk-hd75916k.js +0 -4
- package/dist/chunk-hz6a476h.js +0 -2
- package/dist/chunk-j7zywbq0.js +0 -4
- package/dist/chunk-jjm3754f.js +0 -2
- package/dist/chunk-ktk30f6d.js +0 -2
- package/dist/chunk-m3f50p6c.js +0 -2
- package/dist/chunk-m90a5dpn.js +0 -2
- package/dist/chunk-mmp7x8f0.js +0 -2
- package/dist/chunk-nqcg2bf0.js +0 -2
- package/dist/chunk-nrp8qg9j.js +0 -2831
- package/dist/chunk-ns7e951g.js +0 -2
- package/dist/chunk-nycvwnty.js +0 -2
- package/dist/chunk-p9shre7t.js +0 -2
- package/dist/chunk-pe9hxhrb.js +0 -2
- package/dist/chunk-ph6xg67j.js +0 -11
- package/dist/chunk-qewxfhex.js +0 -2
- package/dist/chunk-qfrg8mnf.js +0 -2
- package/dist/chunk-rmnhy5az.js +0 -2
- package/dist/chunk-t6m5wmpy.js +0 -2
- package/dist/chunk-v404gvm0.js +0 -2
- package/dist/chunk-vgvsefz8.js +0 -2
- package/dist/chunk-w9k7pvre.js +0 -2
- package/dist/chunk-wf09xg7j.js +0 -2
- package/dist/chunk-wgqt5pnv.js +0 -2
- package/dist/chunk-wr3h8dmt.js +0 -2
- package/dist/chunk-wtqjfar3.js +0 -2
- package/dist/chunk-x1xncm97.js +0 -2
- package/dist/chunk-yd50awqp.js +0 -3
- package/dist/chunk-ykxd78b2.js +0 -2
- package/dist/chunk-yqsza22w.js +0 -3
- package/dist/chunk-zj80vrv6.js +0 -2
|
@@ -2,13 +2,14 @@ import path from "node:path";
|
|
|
2
2
|
import { bundleClientScript, clientBundleDependencies, hasUserImports } from "./client-script-bundler.js";
|
|
3
3
|
import { loadStxConfig } from "./config.js";
|
|
4
4
|
import { getPublicEnvDefine } from "./public-env.js";
|
|
5
|
-
import {
|
|
5
|
+
import { contentKey, renderMemo } from "./render-memo.js";
|
|
6
|
+
import { clearSourceSignatures, readSigned, sourceSignature, writeSigned } from "./source-signature.js";
|
|
6
7
|
import { stripModuleImports } from "./store-imports.js";
|
|
7
8
|
import { STX_RUNTIME_GLOBALS } from "./runtime-globals.js";
|
|
8
9
|
import { stripStxRuntimeImports } from "./signal-processing.js";
|
|
9
10
|
import { transformStoreImports } from "./store-imports.js";
|
|
10
11
|
import { getSharedTranspiler } from "./utils.js";
|
|
11
|
-
const _cachedComposableScripts = new Map, _cachedDirs = new Map, DEFAULT_DIR_CANDIDATES = ["composables", "functions"];
|
|
12
|
+
const _cachedComposableScripts = new Map, _scannedComposables = new Map, reachableByPage = renderMemo(64), _cachedDirs = new Map, DEFAULT_DIR_CANDIDATES = ["composables", "functions"];
|
|
12
13
|
function isSkippedFile(file) {
|
|
13
14
|
const name = path.basename(file, ".ts");
|
|
14
15
|
return name === "index" || name === "types" || file.endsWith(".d.ts");
|
|
@@ -66,6 +67,13 @@ export async function listComposableModules(composablesDir) {
|
|
|
66
67
|
function mentions(text, name) {
|
|
67
68
|
return new RegExp(`\\b${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`).test(text);
|
|
68
69
|
}
|
|
70
|
+
function mentionedNames(text, names) {
|
|
71
|
+
const words = new Set(text.match(/\w+/g)), found = new Set;
|
|
72
|
+
for (const name of names)
|
|
73
|
+
if (/^\w+$/.test(name) ? words.has(name) : mentions(text, name))
|
|
74
|
+
found.add(name);
|
|
75
|
+
return found;
|
|
76
|
+
}
|
|
69
77
|
function selectReachable(modules, codeByFile, pageSources) {
|
|
70
78
|
const fileForName = new Map;
|
|
71
79
|
for (const { file, names } of modules)
|
|
@@ -74,9 +82,8 @@ function selectReachable(modules, codeByFile, pageSources) {
|
|
|
74
82
|
fileForName.set(name, file);
|
|
75
83
|
const filesMentionedIn = (text) => {
|
|
76
84
|
const found = [];
|
|
77
|
-
for (const
|
|
78
|
-
|
|
79
|
-
found.push(file);
|
|
85
|
+
for (const name of mentionedNames(text, fileForName.keys()))
|
|
86
|
+
found.push(fileForName.get(name));
|
|
80
87
|
return found;
|
|
81
88
|
}, selected = new Set;
|
|
82
89
|
let frontier = pageSources.flatMap(filesMentionedIn);
|
|
@@ -108,18 +115,32 @@ export async function getComposableScript(composablesDir, pageSource, extraSourc
|
|
|
108
115
|
return null;
|
|
109
116
|
}
|
|
110
117
|
composableFiles.sort();
|
|
111
|
-
const transpiler = getSharedTranspiler({ loader: "ts", target: "browser", define: getPublicEnvDefine() })
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
const transpiler = getSharedTranspiler({ loader: "ts", target: "browser", define: getPublicEnvDefine() });
|
|
119
|
+
let scanned = readSigned(_scannedComposables, resolvedDir, signature);
|
|
120
|
+
if (!scanned) {
|
|
121
|
+
const codeByFile = new Map, modules = [];
|
|
122
|
+
for (const file of composableFiles)
|
|
123
|
+
try {
|
|
124
|
+
const code = await Bun.file(file).text();
|
|
125
|
+
codeByFile.set(file, code);
|
|
126
|
+
const names = transpiler.scan(code).exports.filter((name) => name !== "default");
|
|
127
|
+
if (names.length > 0)
|
|
128
|
+
modules.push({ file, names });
|
|
129
|
+
} catch {
|
|
130
|
+
codeByFile.set(file, "");
|
|
131
|
+
}
|
|
132
|
+
scanned = writeSigned(_scannedComposables, resolvedDir, signature, { codeByFile, modules });
|
|
133
|
+
}
|
|
134
|
+
const { codeByFile, modules } = scanned;
|
|
135
|
+
let selected;
|
|
136
|
+
if (pageSource === void 0)
|
|
137
|
+
selected = new Set(composableFiles);
|
|
138
|
+
else {
|
|
139
|
+
const pageSources = extraSources ? [pageSource, ...extraSources] : [pageSource], selectionKey = contentKey(pageSources.join("\x00"), resolvedDir, pageSources.length, signature), remembered = reachableByPage.get(selectionKey);
|
|
140
|
+
selected = remembered ?? selectReachable(modules, codeByFile, pageSources);
|
|
141
|
+
if (!remembered)
|
|
142
|
+
reachableByPage.set(selectionKey, selected);
|
|
143
|
+
}
|
|
123
144
|
if (selected.size === 0)
|
|
124
145
|
return null;
|
|
125
146
|
const includedFiles = composableFiles.filter((file) => selected.has(file)), cacheKey = `${resolvedDir}\x00${includedFiles.join("\x00")}`, cached = readSigned(_cachedComposableScripts, cacheKey, signature);
|
|
@@ -191,5 +212,8 @@ ${assignments}
|
|
|
191
212
|
}
|
|
192
213
|
export function clearComposableCache() {
|
|
193
214
|
_cachedComposableScripts.clear();
|
|
215
|
+
clearSourceSignatures();
|
|
216
|
+
_scannedComposables.clear();
|
|
217
|
+
reachableByPage.clear();
|
|
194
218
|
_cachedDirs.clear();
|
|
195
219
|
}
|
package/dist/compression.js
CHANGED
|
@@ -51,6 +51,20 @@ export function negotiateEncoding(acceptEncoding) {
|
|
|
51
51
|
return "gzip";
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
|
+
const COMPRESSED_CACHE_BYTES = 33554432, compressedByBody = new Map;
|
|
55
|
+
let compressedBytes = 0;
|
|
56
|
+
function rememberCompressed(key, value) {
|
|
57
|
+
if (value.length > COMPRESSED_CACHE_BYTES / 8)
|
|
58
|
+
return;
|
|
59
|
+
compressedByBody.set(key, value);
|
|
60
|
+
compressedBytes += value.length;
|
|
61
|
+
for (const [oldest, kept] of compressedByBody) {
|
|
62
|
+
if (compressedBytes <= COMPRESSED_CACHE_BYTES)
|
|
63
|
+
break;
|
|
64
|
+
compressedByBody.delete(oldest);
|
|
65
|
+
compressedBytes -= kept.length;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
54
68
|
export async function compressResponse(request, response, options = {}) {
|
|
55
69
|
if (response.headers.get("content-encoding"))
|
|
56
70
|
return response;
|
|
@@ -75,12 +89,17 @@ export async function compressResponse(request, response, options = {}) {
|
|
|
75
89
|
if (body.length < (options.threshold ?? MIN_BYTES))
|
|
76
90
|
return passthrough();
|
|
77
91
|
try {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
const quality = options.quality ?? 5, key = `${encoding}:${quality}:${body.length}:${Bun.hash(body)}`;
|
|
93
|
+
let compressed = compressedByBody.get(key);
|
|
94
|
+
if (!compressed) {
|
|
95
|
+
compressed = encoding === "br" ? await brotliCompress(body, {
|
|
96
|
+
params: {
|
|
97
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: quality,
|
|
98
|
+
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: body.length
|
|
99
|
+
}
|
|
100
|
+
}) : await gzipCompress(body);
|
|
101
|
+
rememberCompressed(key, compressed);
|
|
102
|
+
}
|
|
84
103
|
if (compressed.length >= body.length)
|
|
85
104
|
return passthrough();
|
|
86
105
|
const headers = varyByAcceptEncoding(response.headers);
|
package/dist/craft-entry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Br,$o,Eo}from"./chunk-44msrx2e.js";import"./chunk-r6pax860.js";import"./chunk-8xz8t9xp.js";import"./chunk-nmf12mx3.js";import"./chunk-w1zvh5y7.js";import"./chunk-h9e032kq.js";import"./chunk-n38wvr7z.js";import"./chunk-exgyf65a.js";import"./chunk-4fa3jec9.js";import"./chunk-zydg3wgt.js";import"./chunk-br1gra4w.js";import"./chunk-jz7pvh7b.js";import"./chunk-0trfbqa7.js";import{cu,bo,lu,uu,wo,jr,vo,du,xo,pu,fu,So,ko,Co}from"./chunk-d4f1bxtt.js";import"./chunk-jepq6316.js";import"./chunk-bq2e9qf6.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
|
|
3
3
|
`),scripts:t.scripts.join(`
|
|
4
4
|
`),metadata:{renderTime:0,cacheHit:!0,totalSize:c.html.length,componentCount:t.metadata.componentCount}}}let a;if(n.streaming)a=await H(t.tree,e);else a=h(t.tree,e);let i;if(n.hydrate){let o=j(a,t,e);a=o.html,i=o.data}if(n.minify)a=D(a);if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`;d.set(o,{html:a,timestamp:Date.now()})}let s=performance.now()-r;return{html:a,styles:t.styles.join(`
|
|
5
5
|
`),scripts:t.scripts.join(`
|
|
6
6
|
`),hydrationData:i,metadata:{renderTime:s,cacheHit:!1,totalSize:a.length,componentCount:t.metadata.componentCount}}}function V(t,e){let n=[],r=[],a=[],i=new Map,s=[];return y(t.tree,(o,c)=>{if(o.type==="component"&&o.componentName){if(T(o.componentName))n.push(o.componentName)}if(o.type==="element"&&o.tag){let p=J(o);if(p)s.push(p);if(o.props){for(let[l,f]of Object.entries(o.props))if(l.startsWith("on")&&typeof f==="string"){let g=`handler_${i.size}`;i.set(g,f)}}}if(o.isStatic&&o.type==="element")r.push(b(o));else if(!o.isStatic&&o.type!=="text")a.push(o.tag||o.componentName||"unknown")}),{nativeComponents:n,staticHTML:r,dynamicParts:a,eventHandlers:i,nativeWidgets:s}}function Y(t,e={}){let n=R(t),r=P(n,e),a=new Map,i=[];return y(n.tree,(s)=>{if(s.type==="component"&&s.componentName){if(T(s.componentName)){i.push(s.componentName);let o=`<!--craft:${s.componentName}:${s.hydrationKey||"default"}-->`;a.set(s.hydrationKey||s.componentName,o)}}}),{staticHTML:r,dynamicPlaceholders:a,craftComponents:i}}function M(t){let e={type:"fragment",children:[]},n=e,r=[e],a=t,i=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);while(a.length>0){let s=a.match(/^<(@?[\w-]+)([^>]*)>/);if(s){let[p,l,f]=s,g=z(f),u=l.startsWith("@craft-"),C=u?l:l.toLowerCase(),S={type:u?"component":"element",tag:C,props:g,children:[],componentName:u?C.slice(1):void 0,isStatic:!v(f),hydrationKey:F()};if(n.children=n.children||[],n.children.push(S),!i.has(C)&&!f.endsWith("/"))r.push(S),n=S;a=a.slice(p.length);continue}let o=a.match(/^<\/(@?[\w-]+)>/);if(o){let[p,l]=o,g=l.startsWith("@craft-")?l:l.toLowerCase();while(r.length>1){let u=r.pop();if(n=r[r.length-1],u.tag===g)break}a=a.slice(p.length);continue}let c=a.match(/^[^<]+/);if(c){let p=c[0];if(p.trim()){let l={type:"text",text:p,isStatic:!v(p)};n.children=n.children||[],n.children.push(l)}a=a.slice(p.length);continue}a=a.slice(1)}return e}function z(t){let e={},n=/([\w-:@]+)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,r;while((r=n.exec(t))!==null){let[,a,i,s,o]=r,c=i??s??o??!0;e[a]=c}return e}function y(t,e,n=[]){if(e(t,n),t.children)t.children.forEach((r,a)=>{y(r,e,[...n,`${a}`])})}function h(t,e){switch(t.type){case"text":return x(t.text||"",e);case"element":case"component":{let n=t.tag||"div",r=N(t.props||{},e),a=(t.children||[]).map((i)=>h(i,e)).join("");if(!t.children||t.children.length===0){if(["input","br","hr","img","meta","link"].includes(n))return`<${n}${r} />`}return`<${n}${r}>${a}</${n}>`}case"fragment":return(t.children||[]).map((n)=>h(n,e)).join("");case"slot":return`<!--slot:${t.slotName||"default"}-->`;default:return""}}function b(t){if(t.type==="text")return t.text||"";let e=t.tag||"div",n=N(t.props||{},{});return`<${e}${n}></${e}>`}function N(t,e){let n=[];for(let[r,a]of Object.entries(t))if(a===!0)n.push(` ${r}`);else if(a!==!1&&a!==null&&a!==void 0){let i=x(String(a),e);n.push(` ${r}="${k(i)}"`)}return n.join("")}async function H(t,e){return h(t,e)}function P(t,e){let n=[];return y(t.tree,(r)=>{if(r.isStatic)n.push(h(r,e))}),n.join("")}function j(t,e,n){let r={templateId:e.id,context:n,dynamicParts:Array.from(e.dynamicParts.entries())},a=`
|
|
7
7
|
<script data-craft-hydration>
|
|
8
8
|
window.__CRAFT_HYDRATION__ = ${JSON.stringify(r)};
|
|
9
|
-
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{
|
|
9
|
+
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{cu as CRAFT_BRIDGE_SCRIPT,jr as CRAFT_COMPONENTS,du as CRAFT_COMPONENT_RUNTIME,vo as CRAFT_COMPONENT_STYLES,Br as NATIVE_COMPONENTS,So as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,$o as compileToNative,Eo as createHotReloadServer,bo as generateCraftBridgeScript,V as generateCraftOptimizations,Co as getAvailableFormats,ko as getAvailableTargets,fu as getCraftComponents,G as getSSRCacheStats,wo as injectCraftBridge,lu as isCraftEnvironment,Y as prerenderForCraft,xo as processCraftComponents,uu as processCraftDirective,pu as registerCraftComponent,Q as renderSSR};
|
package/dist/craft.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Br,$o,Eo}from"./chunk-44msrx2e.js";import"./chunk-r6pax860.js";import"./chunk-8xz8t9xp.js";import"./chunk-nmf12mx3.js";import"./chunk-w1zvh5y7.js";import"./chunk-h9e032kq.js";import"./chunk-n38wvr7z.js";import"./chunk-exgyf65a.js";import"./chunk-4fa3jec9.js";import"./chunk-zydg3wgt.js";import"./chunk-br1gra4w.js";import"./chunk-jz7pvh7b.js";import"./chunk-0trfbqa7.js";import{cu,bo,lu,uu,wo,jr,vo,du,xo,pu,fu,So,ko,Co}from"./chunk-d4f1bxtt.js";import"./chunk-jepq6316.js";import"./chunk-bq2e9qf6.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
|
|
3
3
|
`),scripts:t.scripts.join(`
|
|
4
4
|
`),metadata:{renderTime:0,cacheHit:!0,totalSize:c.html.length,componentCount:t.metadata.componentCount}}}let a;if(n.streaming)a=await H(t.tree,e);else a=h(t.tree,e);let i;if(n.hydrate){let o=j(a,t,e);a=o.html,i=o.data}if(n.minify)a=D(a);if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`;d.set(o,{html:a,timestamp:Date.now()})}let s=performance.now()-r;return{html:a,styles:t.styles.join(`
|
|
5
5
|
`),scripts:t.scripts.join(`
|
|
6
6
|
`),hydrationData:i,metadata:{renderTime:s,cacheHit:!1,totalSize:a.length,componentCount:t.metadata.componentCount}}}function V(t,e){let n=[],r=[],a=[],i=new Map,s=[];return y(t.tree,(o,c)=>{if(o.type==="component"&&o.componentName){if(T(o.componentName))n.push(o.componentName)}if(o.type==="element"&&o.tag){let p=J(o);if(p)s.push(p);if(o.props){for(let[l,f]of Object.entries(o.props))if(l.startsWith("on")&&typeof f==="string"){let g=`handler_${i.size}`;i.set(g,f)}}}if(o.isStatic&&o.type==="element")r.push(b(o));else if(!o.isStatic&&o.type!=="text")a.push(o.tag||o.componentName||"unknown")}),{nativeComponents:n,staticHTML:r,dynamicParts:a,eventHandlers:i,nativeWidgets:s}}function Y(t,e={}){let n=R(t),r=P(n,e),a=new Map,i=[];return y(n.tree,(s)=>{if(s.type==="component"&&s.componentName){if(T(s.componentName)){i.push(s.componentName);let o=`<!--craft:${s.componentName}:${s.hydrationKey||"default"}-->`;a.set(s.hydrationKey||s.componentName,o)}}}),{staticHTML:r,dynamicPlaceholders:a,craftComponents:i}}function M(t){let e={type:"fragment",children:[]},n=e,r=[e],a=t,i=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);while(a.length>0){let s=a.match(/^<(@?[\w-]+)([^>]*)>/);if(s){let[p,l,f]=s,g=z(f),u=l.startsWith("@craft-"),C=u?l:l.toLowerCase(),S={type:u?"component":"element",tag:C,props:g,children:[],componentName:u?C.slice(1):void 0,isStatic:!v(f),hydrationKey:F()};if(n.children=n.children||[],n.children.push(S),!i.has(C)&&!f.endsWith("/"))r.push(S),n=S;a=a.slice(p.length);continue}let o=a.match(/^<\/(@?[\w-]+)>/);if(o){let[p,l]=o,g=l.startsWith("@craft-")?l:l.toLowerCase();while(r.length>1){let u=r.pop();if(n=r[r.length-1],u.tag===g)break}a=a.slice(p.length);continue}let c=a.match(/^[^<]+/);if(c){let p=c[0];if(p.trim()){let l={type:"text",text:p,isStatic:!v(p)};n.children=n.children||[],n.children.push(l)}a=a.slice(p.length);continue}a=a.slice(1)}return e}function z(t){let e={},n=/([\w-:@]+)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,r;while((r=n.exec(t))!==null){let[,a,i,s,o]=r,c=i??s??o??!0;e[a]=c}return e}function y(t,e,n=[]){if(e(t,n),t.children)t.children.forEach((r,a)=>{y(r,e,[...n,`${a}`])})}function h(t,e){switch(t.type){case"text":return x(t.text||"",e);case"element":case"component":{let n=t.tag||"div",r=N(t.props||{},e),a=(t.children||[]).map((i)=>h(i,e)).join("");if(!t.children||t.children.length===0){if(["input","br","hr","img","meta","link"].includes(n))return`<${n}${r} />`}return`<${n}${r}>${a}</${n}>`}case"fragment":return(t.children||[]).map((n)=>h(n,e)).join("");case"slot":return`<!--slot:${t.slotName||"default"}-->`;default:return""}}function b(t){if(t.type==="text")return t.text||"";let e=t.tag||"div",n=N(t.props||{},{});return`<${e}${n}></${e}>`}function N(t,e){let n=[];for(let[r,a]of Object.entries(t))if(a===!0)n.push(` ${r}`);else if(a!==!1&&a!==null&&a!==void 0){let i=x(String(a),e);n.push(` ${r}="${k(i)}"`)}return n.join("")}async function H(t,e){return h(t,e)}function P(t,e){let n=[];return y(t.tree,(r)=>{if(r.isStatic)n.push(h(r,e))}),n.join("")}function j(t,e,n){let r={templateId:e.id,context:n,dynamicParts:Array.from(e.dynamicParts.entries())},a=`
|
|
7
7
|
<script data-craft-hydration>
|
|
8
8
|
window.__CRAFT_HYDRATION__ = ${JSON.stringify(r)};
|
|
9
|
-
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{
|
|
9
|
+
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{cu as CRAFT_BRIDGE_SCRIPT,jr as CRAFT_COMPONENTS,du as CRAFT_COMPONENT_RUNTIME,vo as CRAFT_COMPONENT_STYLES,Br as NATIVE_COMPONENTS,So as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,$o as compileToNative,Eo as createHotReloadServer,bo as generateCraftBridgeScript,V as generateCraftOptimizations,Co as getAvailableFormats,ko as getAvailableTargets,fu as getCraftComponents,G as getSSRCacheStats,wo as injectCraftBridge,lu as isCraftEnvironment,Y as prerenderForCraft,xo as processCraftComponents,uu as processCraftDirective,pu as registerCraftComponent,Q as renderSSR};
|
package/dist/html-masking.js
CHANGED
|
@@ -133,16 +133,31 @@ export function evictOldest(cache, maxEntries) {
|
|
|
133
133
|
cache.delete(oldest.value);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
-
const MASK_CACHE_MIN_BYTES =
|
|
136
|
+
const MASK_CACHE_MIN_BYTES = 1024, MASK_CACHE_MAX_CHARS = 16777216, maskCache = new Map;
|
|
137
|
+
let maskCacheChars = 0;
|
|
138
|
+
function rememberMask(key, entry) {
|
|
139
|
+
maskCache.set(key, entry);
|
|
140
|
+
maskCacheChars += key.length + entry.output.length;
|
|
141
|
+
for (const [oldest, kept] of maskCache) {
|
|
142
|
+
if (maskCacheChars <= MASK_CACHE_MAX_CHARS)
|
|
143
|
+
break;
|
|
144
|
+
maskCache.delete(oldest);
|
|
145
|
+
maskCacheChars -= oldest.length + kept.output.length;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
137
148
|
export function clearMaskCache() {
|
|
138
149
|
maskCache.clear();
|
|
150
|
+
maskCacheChars = 0;
|
|
139
151
|
}
|
|
140
152
|
export function maskAtElementPosition(html, match, placeholder, cacheKey) {
|
|
141
153
|
const cacheable = cacheKey !== void 0 && html.length >= MASK_CACHE_MIN_BYTES, key = cacheable ? `${cacheKey}\x00${html}` : "";
|
|
142
154
|
if (cacheable) {
|
|
143
155
|
const hit = maskCache.get(key);
|
|
144
|
-
if (hit)
|
|
156
|
+
if (hit) {
|
|
157
|
+
maskCache.delete(key);
|
|
158
|
+
maskCache.set(key, hit);
|
|
145
159
|
return { output: hit.output, tokens: hit.tokens.slice() };
|
|
160
|
+
}
|
|
146
161
|
}
|
|
147
162
|
const matches = scanAtElementPosition(html, match);
|
|
148
163
|
if (matches.length === 0)
|
|
@@ -157,13 +172,23 @@ export function maskAtElementPosition(html, match, placeholder, cacheKey) {
|
|
|
157
172
|
}
|
|
158
173
|
output += html.slice(cursor);
|
|
159
174
|
if (cacheable) {
|
|
160
|
-
|
|
161
|
-
maskCache.set(key, { output, tokens });
|
|
175
|
+
rememberMask(key, { output, tokens });
|
|
162
176
|
return { output, tokens: tokens.slice() };
|
|
163
177
|
}
|
|
164
178
|
return { output, tokens };
|
|
165
179
|
}
|
|
166
|
-
const STASH_CACHE_MIN_BYTES =
|
|
180
|
+
const STASH_CACHE_MIN_BYTES = 1024, STASH_CACHE_MAX_CHARS = 16777216, stashCache = new Map;
|
|
181
|
+
let stashCacheChars = 0;
|
|
182
|
+
function rememberStash(html, entry) {
|
|
183
|
+
stashCache.set(html, entry);
|
|
184
|
+
stashCacheChars += html.length + entry.output.length;
|
|
185
|
+
for (const [oldest, kept] of stashCache) {
|
|
186
|
+
if (stashCacheChars <= STASH_CACHE_MAX_CHARS)
|
|
187
|
+
break;
|
|
188
|
+
stashCache.delete(oldest);
|
|
189
|
+
stashCacheChars -= oldest.length + kept.output.length;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
167
192
|
function stashResult(input, output, scripts) {
|
|
168
193
|
return {
|
|
169
194
|
output,
|
|
@@ -175,19 +200,22 @@ export function stashScriptElements(html) {
|
|
|
175
200
|
const cacheable = html.length >= STASH_CACHE_MIN_BYTES;
|
|
176
201
|
if (cacheable) {
|
|
177
202
|
const hit = stashCache.get(html);
|
|
178
|
-
if (hit)
|
|
203
|
+
if (hit) {
|
|
204
|
+
stashCache.delete(html);
|
|
205
|
+
stashCache.set(html, hit);
|
|
179
206
|
return stashResult(html, hit.output, hit.scripts.slice());
|
|
207
|
+
}
|
|
180
208
|
}
|
|
181
209
|
const { output, tokens } = maskAtElementPosition(html, matchScriptElement, (_token, index) => `\x00STX_SCRIPT_${index}\x00`);
|
|
182
210
|
if (cacheable) {
|
|
183
|
-
|
|
184
|
-
stashCache.set(html, { output, scripts: tokens });
|
|
211
|
+
rememberStash(html, { output, scripts: tokens });
|
|
185
212
|
return stashResult(html, output, tokens.slice());
|
|
186
213
|
}
|
|
187
214
|
return stashResult(html, output, tokens);
|
|
188
215
|
}
|
|
189
216
|
export function clearStashCache() {
|
|
190
217
|
stashCache.clear();
|
|
218
|
+
stashCacheChars = 0;
|
|
191
219
|
}
|
|
192
220
|
export function restoreStashedScripts(html, scripts) {
|
|
193
221
|
if (scripts.length === 0)
|
package/dist/i18n.js
CHANGED
|
@@ -170,9 +170,10 @@ async function loadTranslationInternal(locale, options) {
|
|
|
170
170
|
sources: formatToSources(i18nConfig.format)
|
|
171
171
|
}) : await loadTranslationFromFile(locale, i18nConfig, translationsDir);
|
|
172
172
|
if (tree === void 0) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
const fallback = locale !== i18nConfig.defaultLocale ? await loadTranslationInternal(i18nConfig.defaultLocale, options) : {};
|
|
174
|
+
if (i18nConfig.cache)
|
|
175
|
+
translationsCache[locale] = { translations: fallback, loadedAt: Date.now(), locale };
|
|
176
|
+
return fallback;
|
|
176
177
|
}
|
|
177
178
|
const translations = tree;
|
|
178
179
|
if (i18nConfig.cache)
|
package/dist/includes.js
CHANGED
|
@@ -263,6 +263,10 @@ function addScopeToRootElement(html, scopeId) {
|
|
|
263
263
|
return { html, mergedIntoExisting: null, stamped: !1, root: null };
|
|
264
264
|
}
|
|
265
265
|
let scopeIdCounter = 0;
|
|
266
|
+
function includeScopeId(includeFilePath, context) {
|
|
267
|
+
const name = path.basename(includeFilePath, ".stx").replace(/[^a-zA-Z0-9]/g, "_"), seq = context.__stx_scope_seq;
|
|
268
|
+
return seq ? `stx_scope_${name}_${++seq.n}_${seq.key}` : `stx_scope_${name}_${++scopeIdCounter}`;
|
|
269
|
+
}
|
|
266
270
|
const warnedUnscopedSignalPartials = new Set;
|
|
267
271
|
export function resetUnscopedSignalWarnings() {
|
|
268
272
|
warnedUnscopedSignalPartials.clear();
|
|
@@ -658,7 +662,7 @@ export async function processIncludes(template, context, filePath, options, depe
|
|
|
658
662
|
const isSignalScript = hasSignalApis(scriptContent);
|
|
659
663
|
if (isSignalScript && !isServerScript) {
|
|
660
664
|
declaresSignals = !0;
|
|
661
|
-
signalScopeId =
|
|
665
|
+
signalScopeId = includeScopeId(includeFilePath, context);
|
|
662
666
|
const resolvedContent = transformStoreImports(scriptContent), transformedScript = transformScopedScript(resolvedContent, signalScopeId);
|
|
663
667
|
preservedScript += `${vendorStyleTags}<script data-stx-scoped data-stx-run="always" data-stx-owner="${signalScopeId}">${transformedScript}</script>
|
|
664
668
|
`;
|
|
@@ -674,7 +678,7 @@ export async function processIncludes(template, context, filePath, options, depe
|
|
|
674
678
|
}
|
|
675
679
|
if (!isServerScript && !isSignalScript) {
|
|
676
680
|
const extraAttrs = scriptAttrs.replace(/\bclient\b/i, "").trim();
|
|
677
|
-
signalScopeId =
|
|
681
|
+
signalScopeId = includeScopeId(includeFilePath, context);
|
|
678
682
|
const resolvedContent = transformStoreImports(scriptContent), wrapped = transformScopedScript(resolvedContent, signalScopeId);
|
|
679
683
|
preservedScript += `${vendorStyleTags}<script data-stx-scoped data-stx-run="always" data-stx-owner="${signalScopeId}"${extraAttrs ? ` ${extraAttrs}` : ""}>${wrapped}</script>
|
|
680
684
|
`;
|
|
@@ -43,15 +43,5 @@ export declare function processMemoDirective(template: string): string;
|
|
|
43
43
|
export declare function processRefAttributes(template: string): string;
|
|
44
44
|
/** Keep the caller of a projected ref explicit after slot content is flattened. */
|
|
45
45
|
export declare function markProjectedRefs(template: string, receiver: string): string;
|
|
46
|
-
/**
|
|
47
|
-
* Add x-cloak to HTML elements whose own text contains an unresolved {{ }}
|
|
48
|
-
* expression. Those were preserved for client-side evaluation (signals, loop
|
|
49
|
-
* vars, etc.), and x-cloak hides them until the runtime binds and reveals them,
|
|
50
|
-
* so the raw mustache never flashes.
|
|
51
|
-
*
|
|
52
|
-
* Only the element that actually holds the expression is stamped — see
|
|
53
|
-
* `ownTextContainsMustache` for why that scoping is the fix rather than a refinement. An
|
|
54
|
-
* element carrying `x-no-cloak` is left visible regardless.
|
|
55
|
-
*/
|
|
56
46
|
export declare function addCloakToUnresolvedExpressions(html: string): string;
|
|
57
47
|
export declare function addCloakToConditionalDirectives(html: string): string;
|
package/dist/misc-directives.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { errorLogger } from "./error-handling.js";
|
|
2
2
|
import { mightContainOwnTextMustache, scanAtElementPosition } from "./html-masking.js";
|
|
3
3
|
import { createSafeFunction, isExpressionSafe } from "./safe-evaluator.js";
|
|
4
|
+
import { contentKey, renderMemo } from "./render-memo.js";
|
|
4
5
|
export function processJsonDirective(template, context) {
|
|
5
6
|
let result = template;
|
|
6
7
|
const jsonPat = /@json\s*\(/g;
|
|
@@ -274,7 +275,18 @@ function ownTextContainsMustache(html, contentStart) {
|
|
|
274
275
|
}
|
|
275
276
|
return !1;
|
|
276
277
|
}
|
|
278
|
+
const cloakedByMarkup = renderMemo(256);
|
|
277
279
|
export function addCloakToUnresolvedExpressions(html) {
|
|
280
|
+
if (html.length < 1024)
|
|
281
|
+
return addCloakToUnresolvedExpressionsUncached(html);
|
|
282
|
+
const key = contentKey(html), known = cloakedByMarkup.get(key);
|
|
283
|
+
if (known !== void 0)
|
|
284
|
+
return known;
|
|
285
|
+
const cloaked = addCloakToUnresolvedExpressionsUncached(html);
|
|
286
|
+
cloakedByMarkup.set(key, cloaked);
|
|
287
|
+
return cloaked;
|
|
288
|
+
}
|
|
289
|
+
function addCloakToUnresolvedExpressionsUncached(html) {
|
|
278
290
|
if (html.length >= 32768 && !mightContainOwnTextMustache(html))
|
|
279
291
|
return html;
|
|
280
292
|
const tagStartRe = new RegExp(`<(${"div|span|p|h[1-6]|td|th|li|a|button|label|section|article|header|footer|main|nav|aside|dd|dt|figcaption|summary|caption|blockquote|pre|code|em|strong|small|sub|sup|time|mark|abbr|cite|q|s|u|b|i"})\\b`, "gi");
|
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
* page stands in. The screens named in `pages` are fetched when the worker
|
|
17
17
|
* installs, so they open offline even before they were visited, with the
|
|
18
18
|
* stylesheets and scripts they link to. Kept per build: a fragment from
|
|
19
|
-
* another build would make the router reload into nothing.
|
|
19
|
+
* another build would make the router reload into nothing. A kept copy
|
|
20
|
+
* whose module bundles (`/_stx/modules.<hash>.js`) are not kept too is not
|
|
21
|
+
* answered first, since a later server process cannot answer them and the
|
|
22
|
+
* page would never bind; it stands in only with no network at all.
|
|
20
23
|
* - Dynamic screens named in `routes` (`/m/workout/:id`): one never opened is
|
|
21
24
|
* answered offline with the route's kept page, its params swapped for the
|
|
22
25
|
* ones asked for. For a page drawn on the device from the API, every value
|
|
@@ -588,6 +588,36 @@ function coldStartUpdate(request) {
|
|
|
588
588
|
}).catch(function () { return false; });
|
|
589
589
|
}
|
|
590
590
|
|
|
591
|
+
// Whether every module bundle a kept page links to is kept too.
|
|
592
|
+
//
|
|
593
|
+
// A page's registry, stores and composables are /_stx/modules.<hash>.js,
|
|
594
|
+
// answered by the server process that rendered the page, and only by it: a
|
|
595
|
+
// deploy starts a process that has never heard of the old hashes and answers
|
|
596
|
+
// them 404. A kept page whose bundles are not kept beside it is therefore one
|
|
597
|
+
// that may never bind -- opened cold, it showed its markup with every {{ }}
|
|
598
|
+
// empty and no button working, until a revalidation happened to replace it.
|
|
599
|
+
// Such a copy is not answered first: the network is, and the copy only stands
|
|
600
|
+
// in when there is no network at all, where it is the best there is.
|
|
601
|
+
// ignoreVary: a script was kept under the browser's own request, whose
|
|
602
|
+
// Accept-Encoding a lookup by URL does not carry.
|
|
603
|
+
var MODULE_BUNDLE = /\\/_stx\\/modules\\.[0-9a-f]{16}\\.js/g;
|
|
604
|
+
function bundlesKept(response) {
|
|
605
|
+
return response.clone().text().then(function (html) {
|
|
606
|
+
var urls = [];
|
|
607
|
+
var match;
|
|
608
|
+
MODULE_BUNDLE.lastIndex = 0;
|
|
609
|
+
while ((match = MODULE_BUNDLE.exec(html))) {
|
|
610
|
+
if (urls.indexOf(match[0]) === -1) urls.push(match[0]);
|
|
611
|
+
}
|
|
612
|
+
if (!urls.length) return true;
|
|
613
|
+
return caches.open(ASSETS).then(function (assets) {
|
|
614
|
+
return Promise.all(urls.map(function (url) { return assets.match(url, { ignoreVary: true }); }));
|
|
615
|
+
}).then(function (kept) {
|
|
616
|
+
return kept.every(Boolean);
|
|
617
|
+
});
|
|
618
|
+
}).catch(function () { return true; });
|
|
619
|
+
}
|
|
620
|
+
|
|
591
621
|
function pageResponse(request, event) {
|
|
592
622
|
var fragment = isFragment(request);
|
|
593
623
|
var key = variantUrl(request.url, fragment);
|
|
@@ -597,34 +627,39 @@ function pageResponse(request, event) {
|
|
|
597
627
|
var cache = opened[0];
|
|
598
628
|
var networkFirst = opened[1] || wantsNetworkFirst(request, new URL(request.url).pathname);
|
|
599
629
|
return cache.match(key).then(function (hit) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
if (hit) return Promise.resolve(hit);
|
|
612
|
-
var route = dynamic ? cache.match(routeKey(dynamic.route, fragment)) : Promise.resolve(null);
|
|
613
|
-
return route.then(function (kept) {
|
|
614
|
-
if (kept) return withParams(kept, dynamic.params);
|
|
615
|
-
if (!offline) return null;
|
|
616
|
-
if (!S.fallback || fragment) return Response.error();
|
|
617
|
-
return cache.match(variantUrl(S.fallback, false)).then(function (fallback) { return fallback ? markFallback(fallback) : Response.error(); });
|
|
630
|
+
return (hit && !networkFirst ? bundlesKept(hit) : Promise.resolve(false)).then(function (whole) {
|
|
631
|
+
if (whole) {
|
|
632
|
+
keepAlive(event, revalidate(request, cache, keys, hit, 'page'));
|
|
633
|
+
return hit;
|
|
634
|
+
}
|
|
635
|
+
// Kept, but without its module bundles: not shown while the network
|
|
636
|
+
// might answer (bundlesKept).
|
|
637
|
+
var partial = hit && !networkFirst;
|
|
638
|
+
var network = fetch(request).then(function (response) {
|
|
639
|
+
if (keepable(response) || keepStaticPage(request, response)) keepAlive(event, store(cache, keys, response.clone()));
|
|
640
|
+
return response;
|
|
618
641
|
});
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
if (
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
642
|
+
// What stands in when the network is not there, or slow: the kept copy,
|
|
643
|
+
// then a dynamic route's kept page, then the fallback screen.
|
|
644
|
+
var standIn = function (offline) {
|
|
645
|
+
if (hit && (!partial || offline)) return Promise.resolve(hit);
|
|
646
|
+
var route = dynamic ? cache.match(routeKey(dynamic.route, fragment)) : Promise.resolve(null);
|
|
647
|
+
return route.then(function (kept) {
|
|
648
|
+
if (kept) return withParams(kept, dynamic.params);
|
|
649
|
+
if (!offline) return null;
|
|
650
|
+
if (!S.fallback || fragment) return Response.error();
|
|
651
|
+
return cache.match(variantUrl(S.fallback, false)).then(function (fallback) { return fallback ? markFallback(fallback) : Response.error(); });
|
|
652
|
+
});
|
|
653
|
+
};
|
|
654
|
+
return withTimeout(network, S.timeout).catch(function () {
|
|
655
|
+
return standIn(false).then(function (kept) {
|
|
656
|
+
if (kept) {
|
|
657
|
+
keepAlive(event, network);
|
|
658
|
+
return kept;
|
|
659
|
+
}
|
|
660
|
+
// Slower than the timeout, nothing kept to show: wait for it rather than fail.
|
|
661
|
+
return network.catch(function () { return standIn(true); });
|
|
662
|
+
});
|
|
628
663
|
});
|
|
629
664
|
});
|
|
630
665
|
});
|
package/dist/process.js
CHANGED
|
@@ -285,6 +285,10 @@ export async function processDirectives(template, context, filePath, options, de
|
|
|
285
285
|
await prepareRuntimeConfig(context, filePath, options.runtimeConfig);
|
|
286
286
|
if (isTopLevel) {
|
|
287
287
|
initializeComponentClientFactories(context);
|
|
288
|
+
context.__stx_scope_seq ??= {
|
|
289
|
+
n: 0,
|
|
290
|
+
key: Bun.hash(String(context.__filename ?? filePath)).toString(36).slice(0, 6)
|
|
291
|
+
};
|
|
288
292
|
context.__stx_head_injections = createHeadInjections();
|
|
289
293
|
context.__stx_seo_staged = !1;
|
|
290
294
|
}
|