@stacksjs/stx 0.2.526 → 0.2.528
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/{chunk-hqvdm4h9.js → chunk-07abr1v4.js} +1 -1
- package/dist/chunk-0d9rx3n4.js +2 -0
- package/dist/chunk-0fna7gd0.js +2 -0
- package/dist/chunk-0gzm7em2.js +2 -0
- package/dist/chunk-0ksq0e6s.js +2 -0
- package/dist/{chunk-4c1afy15.js → chunk-0rt5ec7a.js} +2 -2
- package/dist/{chunk-365ktg70.js → chunk-0ytm2ecf.js} +6 -6
- package/dist/{chunk-802qf0vz.js → chunk-1e7g79x4.js} +1 -1
- package/dist/{chunk-w2dn0zfs.js → chunk-1r5zd4a9.js} +3 -3
- package/dist/{chunk-8xpyzcq2.js → chunk-1s7qdv2h.js} +3 -3
- package/dist/{chunk-er7y8hk9.js → chunk-1v6yyvxf.js} +2 -2
- package/dist/{chunk-jcmgj8kk.js → chunk-21rm5kv6.js} +2 -2
- package/dist/{chunk-kp4mzspk.js → chunk-299xbyhn.js} +4 -4
- package/dist/chunk-2bwhc8ea.js +2 -0
- package/dist/chunk-2kjxd3v1.js +2 -0
- package/dist/{chunk-3y8ykqpx.js → chunk-2m5mx0x8.js} +1 -1
- package/dist/{chunk-01rz8h7x.js → chunk-2twfqcxm.js} +2 -2
- package/dist/{chunk-dne8n6h3.js → chunk-2y82wf9d.js} +2 -2
- package/dist/{chunk-8fb1mqw1.js → chunk-346zc43s.js} +1 -1
- package/dist/{chunk-3s9s1mdt.js → chunk-35j1evvy.js} +3 -3
- package/dist/{chunk-bqz4wenr.js → chunk-3cn7973z.js} +1 -1
- package/dist/chunk-3j02tj5n.js +2 -0
- package/dist/{chunk-eacd5755.js → chunk-3j9de8yh.js} +1 -1
- package/dist/chunk-3v2bf157.js +2 -0
- package/dist/{chunk-v6wk57np.js → chunk-44e5tk5g.js} +2 -2
- package/dist/{chunk-b1fw8mwk.js → chunk-4625sykb.js} +3 -3
- package/dist/chunk-4bfdyf1s.js +2 -0
- package/dist/{chunk-t78xq89y.js → chunk-52mjjszq.js} +2 -2
- package/dist/{chunk-fxxrrq9n.js → chunk-58jyc7kp.js} +3 -3
- package/dist/{chunk-yxdyh23k.js → chunk-5tyes97j.js} +2 -2
- package/dist/chunk-62s4jb6m.js +2 -0
- package/dist/{chunk-jbvg29t0.js → chunk-6k7spr38.js} +5 -5
- package/dist/{chunk-e62nw7zk.js → chunk-6t0rq51y.js} +2 -2
- package/dist/chunk-6ywr110f.js +2 -0
- package/dist/chunk-70cr8xzz.js +2 -0
- package/dist/{chunk-zzgqg00a.js → chunk-7e7mcrf9.js} +5 -5
- package/dist/{chunk-gynes6rm.js → chunk-7p0zerfj.js} +8 -8
- package/dist/{chunk-ygetbydb.js → chunk-869wyw0j.js} +6 -6
- package/dist/{chunk-gbfap7rv.js → chunk-8m3k43d3.js} +6 -6
- package/dist/{chunk-6w10wb1b.js → chunk-8rxammgf.js} +2 -2
- package/dist/{chunk-mgm471hk.js → chunk-93cf01s9.js} +1 -1
- package/dist/{chunk-c57j92td.js → chunk-9mjy16pw.js} +2 -2
- package/dist/chunk-ad0czgpa.js +2 -0
- package/dist/chunk-axjzqh7v.js +2 -0
- package/dist/chunk-bqah6yhk.js +2 -0
- package/dist/chunk-byr1derh.js +2 -0
- package/dist/{chunk-8ga1dn8v.js → chunk-cen7wkv8.js} +2 -2
- package/dist/{chunk-tkagcknf.js → chunk-csbft3wz.js} +2 -2
- package/dist/{chunk-67actssw.js → chunk-d8ramz4s.js} +2 -2
- package/dist/chunk-dvph69ej.js +2 -0
- package/dist/{chunk-8c0fmchj.js → chunk-dx23ntmm.js} +1 -1
- package/dist/chunk-e0p7p7p2.js +2 -0
- package/dist/chunk-e1c9gypy.js +2 -0
- package/dist/chunk-eh3nvr2g.js +2 -0
- package/dist/{chunk-6b94c1jb.js → chunk-etdx3fye.js} +27 -10
- package/dist/{chunk-x81vcxzs.js → chunk-f1n4e4jy.js} +2 -2
- package/dist/{chunk-s9mq9x2k.js → chunk-f5pmyxtn.js} +5 -5
- package/dist/chunk-fanmabb0.js +2 -0
- package/dist/chunk-fdbtr4my.js +2 -0
- package/dist/chunk-fhsy7dc5.js +2 -0
- package/dist/chunk-fjd5ka6v.js +2 -0
- package/dist/{chunk-2j04bc8c.js → chunk-fk45zc1b.js} +4 -4
- package/dist/chunk-fq5xecrx.js +2 -0
- package/dist/chunk-gaz311xs.js +2 -0
- package/dist/chunk-gbb8dze1.js +2 -0
- package/dist/{chunk-hktvv0hd.js → chunk-ggb57j6c.js} +2 -2
- package/dist/chunk-gkzvxt62.js +2 -0
- package/dist/chunk-gmx73f50.js +2 -0
- package/dist/chunk-h80p2gkn.js +2 -0
- package/dist/{chunk-h6q8jafh.js → chunk-hbwmmt91.js} +2 -2
- package/dist/{chunk-shjcstfw.js → chunk-he404gbh.js} +4 -4
- package/dist/chunk-hmk2x1t8.js +2 -0
- package/dist/{chunk-nzpp1gcf.js → chunk-j19b6d9m.js} +9 -9
- package/dist/chunk-j1tbfabt.js +2 -0
- package/dist/chunk-j7615qvy.js +33 -0
- package/dist/{chunk-n34kagea.js → chunk-jj8ssn0d.js} +2 -2
- package/dist/chunk-jkd0c82m.js +2 -0
- package/dist/chunk-jnpyzq5m.js +2 -0
- package/dist/chunk-jwx0h9qb.js +2 -0
- package/dist/{chunk-g7xxfcem.js → chunk-jya4r00e.js} +6 -6
- package/dist/chunk-k4p80n25.js +2 -0
- package/dist/chunk-kg4navnh.js +2 -0
- package/dist/chunk-kpbpmmdk.js +2 -0
- package/dist/{chunk-1aw9qbdf.js → chunk-kpns3659.js} +167 -18
- package/dist/{chunk-5fmc9xyx.js → chunk-mftzhj7x.js} +2 -2
- package/dist/chunk-mh7k2ps4.js +2837 -0
- package/dist/{chunk-k7xhky05.js → chunk-my4s7k0x.js} +7 -7
- package/dist/{chunk-rhwkwny1.js → chunk-n48v0cma.js} +2 -2
- package/dist/chunk-nc1wcdfs.js +2 -0
- package/dist/{chunk-1c407nky.js → chunk-p8c5g5n2.js} +5 -5
- package/dist/chunk-pkwed7dt.js +2 -0
- package/dist/{chunk-p3znkt4w.js → chunk-qtvth7eg.js} +3 -3
- package/dist/chunk-r0n937ex.js +2 -0
- package/dist/chunk-rypj5y6d.js +2 -0
- package/dist/chunk-syde729h.js +2 -0
- package/dist/chunk-t3mg529n.js +2 -0
- package/dist/{chunk-vp827ah7.js → chunk-v2zxxjqn.js} +5 -5
- package/dist/chunk-v70hfs6d.js +2 -0
- package/dist/chunk-vfc4fg8v.js +2 -0
- package/dist/chunk-vrdg365w.js +2 -0
- package/dist/chunk-w5kx0qzg.js +2 -0
- package/dist/{chunk-srqhbjcm.js → chunk-w9srfsfk.js} +1 -1
- package/dist/chunk-wg7jz0ta.js +2 -0
- package/dist/{chunk-zv0vgamy.js → chunk-wn5zjs5m.js} +2 -2
- package/dist/{chunk-3ynfz6h8.js → chunk-wqxdx2td.js} +2 -2
- package/dist/{chunk-387mj2t0.js → chunk-wv9es0ra.js} +3 -3
- package/dist/{chunk-xx2pk2ay.js → chunk-x1tzt7yc.js} +4 -4
- package/dist/{chunk-jgz64wmw.js → chunk-xg08g7xd.js} +4 -4
- package/dist/{chunk-gte0wmh8.js → chunk-xpvvne6r.js} +5 -5
- package/dist/{chunk-y4vw1727.js → chunk-xw45r9b5.js} +1 -1
- package/dist/{chunk-fesb4h31.js → chunk-y0c1srgj.js} +5 -5
- package/dist/chunk-y4b60ke0.js +2 -0
- package/dist/{chunk-4hz4g5ym.js → chunk-yh3p86qa.js} +2 -2
- package/dist/chunk-yqh6dny3.js +2 -0
- package/dist/chunk-zfct5zbe.js +2 -0
- package/dist/{chunk-x8mp9yvn.js → chunk-zw029e7n.js} +3 -3
- package/dist/chunk-zw2xxaza.js +2 -0
- package/dist/cli.js +13 -13
- package/dist/client-parameter-bindings.d.ts +14 -0
- package/dist/client-parameter-bindings.js +75 -5
- package/dist/client-script.js +26 -0
- package/dist/composable-loader.js +32 -2
- package/dist/composables/use-router.js +4 -3
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/includes.js +5 -3
- package/dist/pwa.js +3 -3
- package/dist/runtime-injection.js +6 -0
- package/dist/signals.js +21 -4
- package/dist/ssg.js +3 -3
- package/dist/types/config-types.d.ts +13 -0
- package/package.json +5 -5
- package/dist/chunk-0eptxhzy.js +0 -2
- package/dist/chunk-1mkyksne.js +0 -2
- package/dist/chunk-1qr6ht4t.js +0 -2
- package/dist/chunk-22k95k4s.js +0 -2
- package/dist/chunk-2zcamy5t.js +0 -2
- package/dist/chunk-38dn8xcx.js +0 -2
- package/dist/chunk-38x0j2tz.js +0 -2
- package/dist/chunk-3c9t71pc.js +0 -2
- package/dist/chunk-3cd3q0se.js +0 -2
- package/dist/chunk-3djvdg4t.js +0 -2
- package/dist/chunk-3kxh9rsp.js +0 -2
- package/dist/chunk-3vqabd10.js +0 -2
- package/dist/chunk-43s5qsjg.js +0 -2
- package/dist/chunk-490f2x2r.js +0 -2
- package/dist/chunk-4k65naeg.js +0 -2
- package/dist/chunk-5c1qesrs.js +0 -2
- package/dist/chunk-78yge30f.js +0 -2
- package/dist/chunk-7y4844mr.js +0 -2
- package/dist/chunk-9c86wgnk.js +0 -2
- package/dist/chunk-9s3tf3m3.js +0 -2
- package/dist/chunk-a9n36502.js +0 -2
- package/dist/chunk-ab73xcp2.js +0 -2
- package/dist/chunk-avq5209p.js +0 -2
- package/dist/chunk-b0bgprzs.js +0 -2
- package/dist/chunk-beecfd50.js +0 -2
- package/dist/chunk-bppenzpa.js +0 -2
- package/dist/chunk-c5h16dew.js +0 -2
- package/dist/chunk-cncktp6c.js +0 -2
- package/dist/chunk-cvvpffkp.js +0 -2
- package/dist/chunk-eadyddmz.js +0 -2
- package/dist/chunk-eegbfbm4.js +0 -2837
- package/dist/chunk-fh5rp6wb.js +0 -2
- package/dist/chunk-gst25gwa.js +0 -33
- package/dist/chunk-gty89j8s.js +0 -2
- package/dist/chunk-hmyyq2hh.js +0 -2
- package/dist/chunk-j49qp4z7.js +0 -2
- package/dist/chunk-kdkt2z3v.js +0 -2
- package/dist/chunk-kkn0m1eg.js +0 -2
- package/dist/chunk-ktxvmgpz.js +0 -2
- package/dist/chunk-kxvtyh05.js +0 -2
- package/dist/chunk-m6pfe21s.js +0 -2
- package/dist/chunk-mjmea6wr.js +0 -2
- package/dist/chunk-nbtd4jk0.js +0 -2
- package/dist/chunk-njpxfd44.js +0 -2
- package/dist/chunk-p5pna1sn.js +0 -2
- package/dist/chunk-p5tz0r3g.js +0 -2
- package/dist/chunk-qky9zfvx.js +0 -2
- package/dist/chunk-rn2w32kh.js +0 -2
- package/dist/chunk-takvfs50.js +0 -2
- package/dist/chunk-tf239jvd.js +0 -2
- package/dist/chunk-vc1m5fr9.js +0 -2
- package/dist/chunk-vy7927pg.js +0 -2
- package/dist/chunk-wfv7v7tf.js +0 -2
- package/dist/chunk-xb1gnzcs.js +0 -2
- package/dist/chunk-z6nm6rf1.js +0 -2
|
@@ -42,6 +42,7 @@ function analyze(source) {
|
|
|
42
42
|
result.push([begin, end]);
|
|
43
43
|
return result;
|
|
44
44
|
}
|
|
45
|
+
const sites = [];
|
|
45
46
|
function pattern(start, end, names) {
|
|
46
47
|
if (tokens[start]?.text === "...")
|
|
47
48
|
start++;
|
|
@@ -50,6 +51,8 @@ function analyze(source) {
|
|
|
50
51
|
const first = tokens[start].text;
|
|
51
52
|
if (identifier.test(first)) {
|
|
52
53
|
names.add(first);
|
|
54
|
+
if (names === declarations)
|
|
55
|
+
sites.push({ name: first, token: start });
|
|
53
56
|
return;
|
|
54
57
|
}
|
|
55
58
|
if (first !== "{" && first !== "[")
|
|
@@ -92,7 +95,7 @@ function analyze(source) {
|
|
|
92
95
|
}
|
|
93
96
|
return tokens[Math.max(start, index - 1)]?.end ?? code.length;
|
|
94
97
|
}
|
|
95
|
-
const scopes = [];
|
|
98
|
+
const declarations = new Set, scopes = [];
|
|
96
99
|
for (let index = 0;index < tokens.length; index++)
|
|
97
100
|
if (tokens[index].text === "=>") {
|
|
98
101
|
const previous = index - 1;
|
|
@@ -121,7 +124,6 @@ function analyze(source) {
|
|
|
121
124
|
continue;
|
|
122
125
|
scopes.push({ start: tokens[index].start, end: tokens[pairs.get(body)].end, names: parameterNames(index + 1, close) });
|
|
123
126
|
}
|
|
124
|
-
const declarations = new Set;
|
|
125
127
|
function declarationEnd(start) {
|
|
126
128
|
let index = start;
|
|
127
129
|
for (;index < tokens.length; index++) {
|
|
@@ -175,19 +177,34 @@ function analyze(source) {
|
|
|
175
177
|
let name = index + 1;
|
|
176
178
|
if (tokens[name]?.text === "*")
|
|
177
179
|
name++;
|
|
178
|
-
if (tokens[name] && identifier.test(tokens[name].text) && tokens[name].text !== "extends")
|
|
180
|
+
if (tokens[name] && identifier.test(tokens[name].text) && tokens[name].text !== "extends") {
|
|
179
181
|
declarations.add(tokens[name].text);
|
|
182
|
+
sites.push({ name: tokens[name].text, token: name });
|
|
183
|
+
}
|
|
180
184
|
} else if (token === "import") {
|
|
181
185
|
let name = index + 1;
|
|
182
186
|
if (tokens[name]?.text === "*" && tokens[name + 1]?.text === "as")
|
|
183
187
|
name += 2;
|
|
184
188
|
const binding = tokens[name]?.text;
|
|
185
|
-
if (binding && identifier.test(binding) && binding !== "type" && tokens[name + 1]?.text !== "(" && tokens[name + 1]?.text !== ".")
|
|
189
|
+
if (binding && identifier.test(binding) && binding !== "type" && tokens[name + 1]?.text !== "(" && tokens[name + 1]?.text !== ".") {
|
|
186
190
|
declarations.add(binding);
|
|
191
|
+
sites.push({ name: binding, token: name, file: !0 });
|
|
192
|
+
}
|
|
193
|
+
const brace = tokens[name]?.text === "{" ? name : tokens[name + 1]?.text === "," && tokens[name + 2]?.text === "{" ? name + 2 : -1;
|
|
194
|
+
if (brace !== -1 && pairs.has(brace)) {
|
|
195
|
+
const close = pairs.get(brace);
|
|
196
|
+
for (const [begin, finish] of parts(brace + 1, close)) {
|
|
197
|
+
let local = finish - 1;
|
|
198
|
+
while (local >= begin && !identifier.test(tokens[local].text))
|
|
199
|
+
local--;
|
|
200
|
+
if (local >= begin && tokens[local].text !== "type")
|
|
201
|
+
sites.push({ name: tokens[local].text, token: local, file: !0 });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
187
204
|
}
|
|
188
205
|
}
|
|
189
206
|
cachedSource = source;
|
|
190
|
-
cached = { code, scopes, declarations };
|
|
207
|
+
cached = { code, scopes, declarations, sites, tokens, pairs };
|
|
191
208
|
return cached;
|
|
192
209
|
}
|
|
193
210
|
export function parameterAnalysis(source) {
|
|
@@ -197,3 +214,56 @@ export function parameterAnalysis(source) {
|
|
|
197
214
|
export function declaredNames(source) {
|
|
198
215
|
return new Set(analyze(source).declarations);
|
|
199
216
|
}
|
|
217
|
+
export function unboundNames(source, candidates) {
|
|
218
|
+
const { scopes, sites, tokens, pairs } = analyze(source), enclosing = Array.from({ length: tokens.length }, () => -1), open = [];
|
|
219
|
+
for (let index = 0;index < tokens.length; index++) {
|
|
220
|
+
enclosing[index] = open.length ? open[open.length - 1] : -1;
|
|
221
|
+
const text = tokens[index].text;
|
|
222
|
+
if (text === "{" && pairs.has(index))
|
|
223
|
+
open.push(index);
|
|
224
|
+
else if (text === "}" && open.length && pairs.get(index) === open[open.length - 1])
|
|
225
|
+
open.pop();
|
|
226
|
+
}
|
|
227
|
+
const declaredAt = new Set, ranges = new Map;
|
|
228
|
+
for (const site of sites) {
|
|
229
|
+
if (!candidates.has(site.name))
|
|
230
|
+
continue;
|
|
231
|
+
declaredAt.add(site.token);
|
|
232
|
+
const brace = site.file ? -1 : enclosing[site.token], range = brace === -1 ? [0, Number.POSITIVE_INFINITY] : [tokens[brace].start, tokens[pairs.get(brace)].end], list = ranges.get(site.name);
|
|
233
|
+
if (list)
|
|
234
|
+
list.push(range);
|
|
235
|
+
else
|
|
236
|
+
ranges.set(site.name, [range]);
|
|
237
|
+
}
|
|
238
|
+
const inImport = new Set;
|
|
239
|
+
for (let index = 0;index < tokens.length; index++) {
|
|
240
|
+
if (tokens[index].text !== "import" || tokens[index - 1]?.text === ".")
|
|
241
|
+
continue;
|
|
242
|
+
let at = index + 1;
|
|
243
|
+
if (tokens[at]?.text === "type")
|
|
244
|
+
at++;
|
|
245
|
+
if (tokens[at] && identifier.test(tokens[at].text) && tokens[at + 1]?.text === ",")
|
|
246
|
+
at += 2;
|
|
247
|
+
if (tokens[at]?.text === "{" && pairs.has(at))
|
|
248
|
+
for (let inner = at + 1;inner < pairs.get(at); inner++)
|
|
249
|
+
inImport.add(inner);
|
|
250
|
+
}
|
|
251
|
+
const found = new Set;
|
|
252
|
+
for (let index = 0;index < tokens.length; index++) {
|
|
253
|
+
const name = tokens[index].text;
|
|
254
|
+
if (!candidates.has(name) || found.has(name) || declaredAt.has(index) || inImport.has(index))
|
|
255
|
+
continue;
|
|
256
|
+
const previous = tokens[index - 1]?.text;
|
|
257
|
+
if (previous === "." && tokens[index - 2]?.text !== "..")
|
|
258
|
+
continue;
|
|
259
|
+
if (tokens[index + 1]?.text === ":" && (previous === "{" || previous === ","))
|
|
260
|
+
continue;
|
|
261
|
+
const at = tokens[index].start;
|
|
262
|
+
if (ranges.get(name)?.some(([from, to]) => at >= from && at < to))
|
|
263
|
+
continue;
|
|
264
|
+
if (scopes.some((scope) => at >= scope.start && at < scope.end && scope.names.has(name)))
|
|
265
|
+
continue;
|
|
266
|
+
found.add(name);
|
|
267
|
+
}
|
|
268
|
+
return found;
|
|
269
|
+
}
|
package/dist/client-script.js
CHANGED
|
@@ -358,10 +358,36 @@ export function referencesName(code, name, call = !1) {
|
|
|
358
358
|
continue;
|
|
359
359
|
if (call && !/^\s*(?:<[^>]*>)?\s*\(/.test(code.slice(end)))
|
|
360
360
|
continue;
|
|
361
|
+
if (definesMethod(code, end))
|
|
362
|
+
continue;
|
|
361
363
|
return !0;
|
|
362
364
|
}
|
|
363
365
|
return !1;
|
|
364
366
|
}
|
|
367
|
+
function definesMethod(code, end) {
|
|
368
|
+
let i = end;
|
|
369
|
+
while (i < code.length && (code[i] === " " || code[i] === "\t"))
|
|
370
|
+
i++;
|
|
371
|
+
if (code[i] !== "(")
|
|
372
|
+
return !1;
|
|
373
|
+
let depth = 0;
|
|
374
|
+
for (;i < code.length; i++) {
|
|
375
|
+
const ch = code[i];
|
|
376
|
+
if (ch === "(")
|
|
377
|
+
depth++;
|
|
378
|
+
else if (ch === ")") {
|
|
379
|
+
depth--;
|
|
380
|
+
if (depth === 0)
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (depth !== 0)
|
|
385
|
+
return !1;
|
|
386
|
+
i++;
|
|
387
|
+
while (i < code.length && (code[i] === " " || code[i] === "\t"))
|
|
388
|
+
i++;
|
|
389
|
+
return code[i] === "{";
|
|
390
|
+
}
|
|
365
391
|
export function generateAutoImportDestructuring(stxImports, browserImports) {
|
|
366
392
|
const lines = [];
|
|
367
393
|
if (stxImports.length > 0)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { unboundNames } from "./client-parameter-bindings.js";
|
|
2
3
|
import { bundleClientScript, clientBundleDependencies, hasUserImports } from "./client-script-bundler.js";
|
|
3
4
|
import { loadStxConfig } from "./config.js";
|
|
4
5
|
import { getPublicEnvDefine } from "./public-env.js";
|
|
@@ -74,6 +75,30 @@ function mentionedNames(text, names) {
|
|
|
74
75
|
found.add(name);
|
|
75
76
|
return found;
|
|
76
77
|
}
|
|
78
|
+
const usesByText = renderMemo(64);
|
|
79
|
+
function composableUses(text, names) {
|
|
80
|
+
const key = contentKey(text, names.size), remembered = usesByText.get(key);
|
|
81
|
+
if (remembered)
|
|
82
|
+
return remembered;
|
|
83
|
+
let used;
|
|
84
|
+
try {
|
|
85
|
+
used = unboundNames(text, names);
|
|
86
|
+
} catch {
|
|
87
|
+
used = mentionedNames(text, names);
|
|
88
|
+
}
|
|
89
|
+
const forced = [
|
|
90
|
+
...text.matchAll(/(?:const|let|var)\s*\{([^}]*)\}\s*=\s*window\.__composables\u0008/g),
|
|
91
|
+
...text.matchAll(/import\s*\{([^}]*)\}\s*from\s*['"]@composables['"]/g)
|
|
92
|
+
];
|
|
93
|
+
for (const match of forced)
|
|
94
|
+
for (const specifier of match[1].split(",")) {
|
|
95
|
+
const name = specifier.trim().split(/\s*(?::|\u0008as\u0008)\s*/)[0];
|
|
96
|
+
if (name && names.has(name))
|
|
97
|
+
used.add(name);
|
|
98
|
+
}
|
|
99
|
+
usesByText.set(key, used);
|
|
100
|
+
return used;
|
|
101
|
+
}
|
|
77
102
|
function selectReachable(modules, codeByFile, pageSources) {
|
|
78
103
|
const fileForName = new Map;
|
|
79
104
|
for (const { file, names } of modules)
|
|
@@ -85,15 +110,20 @@ function selectReachable(modules, codeByFile, pageSources) {
|
|
|
85
110
|
for (const name of mentionedNames(text, fileForName.keys()))
|
|
86
111
|
found.push(fileForName.get(name));
|
|
87
112
|
return found;
|
|
113
|
+
}, allNames = new Set(fileForName.keys()), filesUsedBy = (text) => {
|
|
114
|
+
const found = [];
|
|
115
|
+
for (const name of composableUses(text, allNames))
|
|
116
|
+
found.push(fileForName.get(name));
|
|
117
|
+
return found;
|
|
88
118
|
}, selected = new Set;
|
|
89
|
-
let frontier = pageSources.flatMap(filesMentionedIn);
|
|
119
|
+
let frontier = pageSources.flatMap((source, index) => index === 0 ? filesMentionedIn(source) : filesUsedBy(source));
|
|
90
120
|
while (frontier.length > 0) {
|
|
91
121
|
const next = [];
|
|
92
122
|
for (const file of frontier) {
|
|
93
123
|
if (selected.has(file))
|
|
94
124
|
continue;
|
|
95
125
|
selected.add(file);
|
|
96
|
-
for (const dependency of
|
|
126
|
+
for (const dependency of filesUsedBy(codeByFile.get(file) ?? ""))
|
|
97
127
|
if (!selected.has(dependency))
|
|
98
128
|
next.push(dependency);
|
|
99
129
|
}
|
|
@@ -76,9 +76,10 @@ export function useSearchParams() {
|
|
|
76
76
|
window.addEventListener("stx:navigate", sync);
|
|
77
77
|
const commit = (url, options) => {
|
|
78
78
|
const replace = !!(options && typeof options === "object" && options.replace), wasPushed = !!(window.history.state && window.history.state.__stxPushed);
|
|
79
|
-
if (replace)
|
|
80
|
-
window.history.
|
|
81
|
-
|
|
79
|
+
if (replace) {
|
|
80
|
+
const current = window.history.state;
|
|
81
|
+
window.history.replaceState(current && typeof current === "object" ? { ...current } : wasPushed ? { __stxPushed: !0 } : {}, "", url);
|
|
82
|
+
} else
|
|
82
83
|
window.history.pushState({ __stxPushed: !0 }, "", url);
|
|
83
84
|
sync();
|
|
84
85
|
}, has = (key) => Object.prototype.hasOwnProperty.call(data(), key);
|
package/dist/craft-entry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Hr,Ao,Po}from"./chunk-
|
|
2
|
+
import{Hr,Ao,Po}from"./chunk-csbft3wz.js";import"./chunk-0ytm2ecf.js";import"./chunk-9mjy16pw.js";import"./chunk-kpns3659.js";import"./chunk-5tyes97j.js";import"./chunk-ba88n1j7.js";import"./chunk-mh7k2ps4.js";import"./chunk-7p0zerfj.js";import"./chunk-8m3k43d3.js";import"./chunk-6k4f583z.js";import"./chunk-w9srfsfk.js";import"./chunk-e6y6s7q8.js";import"./chunk-299xbyhn.js";import{vd,ko,xd,Sd,Co,zr,Eo,kd,$o,Cd,Ed,_o,To,Ro}from"./chunk-jya4r00e.js";import"./chunk-qtvth7eg.js";import"./chunk-58jyc7kp.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{vd as CRAFT_BRIDGE_SCRIPT,zr as CRAFT_COMPONENTS,kd as CRAFT_COMPONENT_RUNTIME,Eo as CRAFT_COMPONENT_STYLES,Hr as NATIVE_COMPONENTS,_o as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Ao as compileToNative,Po as createHotReloadServer,ko as generateCraftBridgeScript,V as generateCraftOptimizations,Ro as getAvailableFormats,To as getAvailableTargets,Ed as getCraftComponents,G as getSSRCacheStats,Co as injectCraftBridge,xd as isCraftEnvironment,Y as prerenderForCraft,$o as processCraftComponents,Sd as processCraftDirective,Cd as registerCraftComponent,Q as renderSSR};
|
package/dist/craft.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Hr,Ao,Po}from"./chunk-
|
|
2
|
+
import{Hr,Ao,Po}from"./chunk-csbft3wz.js";import"./chunk-0ytm2ecf.js";import"./chunk-9mjy16pw.js";import"./chunk-kpns3659.js";import"./chunk-5tyes97j.js";import"./chunk-ba88n1j7.js";import"./chunk-mh7k2ps4.js";import"./chunk-7p0zerfj.js";import"./chunk-8m3k43d3.js";import"./chunk-6k4f583z.js";import"./chunk-w9srfsfk.js";import"./chunk-e6y6s7q8.js";import"./chunk-299xbyhn.js";import{vd,ko,xd,Sd,Co,zr,Eo,kd,$o,Cd,Ed,_o,To,Ro}from"./chunk-jya4r00e.js";import"./chunk-qtvth7eg.js";import"./chunk-58jyc7kp.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{vd as CRAFT_BRIDGE_SCRIPT,zr as CRAFT_COMPONENTS,kd as CRAFT_COMPONENT_RUNTIME,Eo as CRAFT_COMPONENT_STYLES,Hr as NATIVE_COMPONENTS,_o as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Ao as compileToNative,Po as createHotReloadServer,ko as generateCraftBridgeScript,V as generateCraftOptimizations,Ro as getAvailableFormats,To as getAvailableTargets,Ed as getCraftComponents,G as getSSRCacheStats,Co as injectCraftBridge,xd as isCraftEnvironment,Y as prerenderForCraft,$o as processCraftComponents,Sd as processCraftDirective,Cd as registerCraftComponent,Q as renderSSR};
|
package/dist/includes.js
CHANGED
|
@@ -653,7 +653,7 @@ export async function processIncludes(template, context, filePath, options, depe
|
|
|
653
653
|
for (const [key, value] of Object.entries(localVars))
|
|
654
654
|
includeContext[key] = value;
|
|
655
655
|
const scriptRegex = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi, scriptMatches = [...partialContent.matchAll(scriptRegex)];
|
|
656
|
-
let preservedScript = "", signalScopeId = null, declaresSignals = !1;
|
|
656
|
+
let preservedScript = "", signalScopeId = null, declaresSignals = !1, registersBindings = !1;
|
|
657
657
|
for (const scriptMatch of scriptMatches) {
|
|
658
658
|
const scriptAttrs = scriptMatch[1] || "";
|
|
659
659
|
let scriptContent = scriptMatch[2] || "";
|
|
@@ -715,6 +715,8 @@ export async function processIncludes(template, context, filePath, options, depe
|
|
|
715
715
|
const extraAttrs = scriptAttrs.replace(/\bclient\b/i, "").trim();
|
|
716
716
|
signalScopeId = includeScopeId(includeFilePath, context);
|
|
717
717
|
const resolvedContent = transformStoreImports(scriptContent), wrapped = transformScopedScript(resolvedContent, signalScopeId);
|
|
718
|
+
if (/__scopeRegistration\["(?!__stx)[^"]+"\]\s*=/.test(wrapped))
|
|
719
|
+
registersBindings = !0;
|
|
718
720
|
preservedScript += `${vendorStyleTags}<script data-stx-scoped data-stx-run="always" data-stx-owner="${signalScopeId}"${extraAttrs ? ` ${extraAttrs}` : ""}>${wrapped}</script>
|
|
719
721
|
`;
|
|
720
722
|
}
|
|
@@ -737,11 +739,11 @@ export async function processIncludes(template, context, filePath, options, depe
|
|
|
737
739
|
warnedUnscopedSignalPartials.add(includeFilePath);
|
|
738
740
|
console.warn(`[stx] ${path.relative(process.cwd(), includeFilePath)} declares signals but has no element to scope them to, so nothing in it will hydrate. Wrap the partial's markup in a single root element.`);
|
|
739
741
|
}
|
|
740
|
-
if (scopeResult.stamped && scopeResult.root !== "body" && declaresSignals && !warnedMultiRootSignalPartials.has(includeFilePath)) {
|
|
742
|
+
if (scopeResult.stamped && scopeResult.root !== "body" && (declaresSignals || registersBindings) && !warnedMultiRootSignalPartials.has(includeFilePath)) {
|
|
741
743
|
const roots = topLevelElements(workingContent);
|
|
742
744
|
if (roots.length > 1) {
|
|
743
745
|
warnedMultiRootSignalPartials.add(includeFilePath);
|
|
744
|
-
console.warn(`[stx] ${path.relative(process.cwd(), includeFilePath)} declares signals and has ${roots.length} top-level elements (${roots.map((name) => `<${name}>`).join(", ")}). Only the first is scoped, so bindings in the others cannot see this partial's
|
|
746
|
+
console.warn(`[stx] ${path.relative(process.cwd(), includeFilePath)} declares ${declaresSignals ? "signals" : "bindings"} and has ${roots.length} top-level elements (${roots.map((name) => `<${name}>`).join(", ")}). Only the first is scoped, so bindings in the others cannot see what this partial's script declares. Wrap the partial's markup in a single root element.`);
|
|
745
747
|
}
|
|
746
748
|
}
|
|
747
749
|
const ownsRoot = scopeResult.stamped && scopeResult.root !== null && rendersAsElement(scopeResult.root);
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Ln,
|
|
3
|
-
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-
|
|
2
|
+
import{Ln,De,Bo,qa}from"./chunk-0rt5ec7a.js";import{Nn,Vr,Va,Ua,Wa}from"./chunk-6k7spr38.js";import{No,Lo,jo,za,Ha}from"./chunk-6t0rq51y.js";import{oe,gt,Ur}from"./chunk-hkjqqx92.js";import{Gc,Jc,Yc,Zc,fr,hu}from"./chunk-wqxdx2td.js";import B from"fs";import w from"path";import O from"fs";import u from"path";var v=[72,96,128,144,152,192,384,512],S=[120,152,167,180],P=[16,32];async function M(n,t){let e={success:!0,generatedFiles:[],errors:[],warnings:[]},r=n.pwa?.icons;if(!r?.src)return e.errors.push("No source icon specified in pwa.icons.src"),e.success=!1,e;let o=u.isAbsolute(r.src)?r.src:u.resolve(process.cwd(),r.src);if(!await Bun.file(o).exists())return e.errors.push(`Source icon not found: ${o}`),e.success=!1,e;let a=u.resolve(t,r.outputDir||"pwa-icons");try{O.mkdirSync(a,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${a}`),e.success=!1,e}let s=r.sizes||v,l=r.generateWebP??!0,p=r.generateAppleIcons??!0;try{let c;try{c=await import("sharp")}catch{return e.errors.push(`sharp is not installed. Install it with: bun add sharp
|
|
3
|
+
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-bqah6yhk.js"),o=await Bun.file(e).text();return await r(o,{},e,n,new Set)}catch(r){console.warn(`[PWA] Failed to process custom offline page: ${r}`)}else console.warn(`[PWA] Custom offline page not found: ${e}`)}return E(n)}function E(n){let t=n.pwa?.offline,e=n.pwa?.manifest,r=t?.fallbackTitle||"You are offline",o=t?.fallbackMessage||"Please check your internet connection and try again.",a=e?.themeColor||"#4f46e5",s=e?.shortName||e?.name||"App";return`<!DOCTYPE html>
|
|
4
4
|
<html lang="en">
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="UTF-8">
|
|
@@ -233,4 +233,4 @@ Icon generation requires the sharp package for image processing.`),e.success=!1,
|
|
|
233
233
|
}, 5000);
|
|
234
234
|
</script>
|
|
235
235
|
</body>
|
|
236
|
-
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=oe(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=Ln(n,t);if(a){let s=
|
|
236
|
+
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=oe(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=Ln(n,t);if(a){let s=De(n),l=w.join(t,s);await Bun.write(l,a),e.files.serviceWorker=l}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate service worker: ${s}`),e.success=!1}return e}function ae(n,t){return Vr(n,t)}function se(n){return n.pwa?.enabled===!0}export{S as APPLE_TOUCH_ICON_SIZES,v as DEFAULT_ICON_SIZES,P as FAVICON_SIZES,Lo as auditBuildOutput,No as auditConfig,re as buildPwaAssets,jo as calculateAuditResult,Ha as formatAuditResult,Ur as formatSize,j as generateManifest,_ as generateManifestJson,Ua as generateManifestLink,F as generateOfflinePage,oe as generatePrecacheManifest,gt as generatePrecacheManifestJs,M as generatePwaIcons,Nn as generatePwaTags,Ln as generateServiceWorker,qa as generateServiceWorkerAuto,Va as generateSwRegistrationScript,Wa as generateThemeColorMeta,N as getExpectedIconPaths,De as getServiceWorkerFileName,Vr as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,Bo as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,fr as pwaDirectives,Gc as pwaInstallDirective,Yc as pwaOfflineDirective,Zc as pwaPushDirective,Jc as pwaUpdateDirective,hu as registerPwaDirectives,za as runPwaAudit,D as validateManifest};
|
|
@@ -145,6 +145,12 @@ export async function injectRouterScript(template, options) {
|
|
|
145
145
|
configObj.progressColor = routerConfig.progressColor;
|
|
146
146
|
if (routerConfig.progressHeight !== void 0)
|
|
147
147
|
configObj.progressHeight = routerConfig.progressHeight;
|
|
148
|
+
if (routerConfig.prefetchVisible !== void 0)
|
|
149
|
+
configObj.prefetchVisible = routerConfig.prefetchVisible;
|
|
150
|
+
if (routerConfig.prefetchVisibleMax !== void 0)
|
|
151
|
+
configObj.prefetchVisibleMax = routerConfig.prefetchVisibleMax;
|
|
152
|
+
if (routerConfig.keepOpening !== void 0)
|
|
153
|
+
configObj.keepOpening = routerConfig.keepOpening;
|
|
148
154
|
}
|
|
149
155
|
try {
|
|
150
156
|
const owned = await getOwnedRouteMatchers(options?.pagesDir, options?.root);
|
package/dist/signals.js
CHANGED
|
@@ -1725,6 +1725,13 @@ else if (immediate) {
|
|
|
1725
1725
|
return value === undefined ? fallback : value;
|
|
1726
1726
|
}
|
|
1727
1727
|
|
|
1728
|
+
function keptHistoryState(wasPushed) {
|
|
1729
|
+
var current = window.history.state;
|
|
1730
|
+
if (!current || typeof current !== 'object') return wasPushed ? { __stxPushed: true } : {};
|
|
1731
|
+
var copy = {};
|
|
1732
|
+
for (var key in current) copy[key] = current[key];
|
|
1733
|
+
return copy;
|
|
1734
|
+
}
|
|
1728
1735
|
function useSearchParams() {
|
|
1729
1736
|
var params = state(Object.fromEntries(new URLSearchParams(window.location.search)));
|
|
1730
1737
|
var syncFromUrl = function() {
|
|
@@ -1768,8 +1775,11 @@ else if (immediate) {
|
|
|
1768
1775
|
// Pushed entries are marked as the router marks them, and a replaced
|
|
1769
1776
|
// one stays what it was, so Back knows whether it stays in the app.
|
|
1770
1777
|
var wasPushed = !!(window.history.state && window.history.state.__stxPushed);
|
|
1778
|
+
// A replaced entry keeps the state it had: the router's scroll token,
|
|
1779
|
+
// its depth and tab are in there, and an entry stripped of them was
|
|
1780
|
+
// restored to the top on Back and miscounted by the tab bar.
|
|
1771
1781
|
if (replace)
|
|
1772
|
-
window.history.replaceState(wasPushed
|
|
1782
|
+
window.history.replaceState(keptHistoryState(wasPushed), '', url);
|
|
1773
1783
|
else
|
|
1774
1784
|
window.history.pushState({ __stxPushed: true }, '', url);
|
|
1775
1785
|
syncFromUrl();
|
|
@@ -7234,12 +7244,16 @@ catch (e) {} }
|
|
|
7234
7244
|
return panel || entry.root || null;
|
|
7235
7245
|
}
|
|
7236
7246
|
|
|
7237
|
-
function
|
|
7238
|
-
return Array.prototype.filter.call(
|
|
7247
|
+
function _overlayShown(nodes) {
|
|
7248
|
+
return Array.prototype.filter.call(nodes, function(el) {
|
|
7239
7249
|
return el.offsetParent !== null || el === document.activeElement;
|
|
7240
7250
|
});
|
|
7241
7251
|
}
|
|
7242
7252
|
|
|
7253
|
+
function _overlayFocusable(panel) {
|
|
7254
|
+
return _overlayShown(panel.querySelectorAll(_OVERLAY_FOCUSABLE));
|
|
7255
|
+
}
|
|
7256
|
+
|
|
7243
7257
|
// One listener for every overlay, in the bubble phase: a widget inside an
|
|
7244
7258
|
// overlay that consumes Escape (a menu closing itself) calls preventDefault
|
|
7245
7259
|
// and the overlay leaves it alone.
|
|
@@ -7373,7 +7387,10 @@ catch (e) {} }
|
|
|
7373
7387
|
try { target = typeof entry.initialFocus === 'function' ? entry.initialFocus() : entry.initialFocus; }
|
|
7374
7388
|
catch (_e) { target = null; }
|
|
7375
7389
|
var panel = _overlayPanel(entry);
|
|
7376
|
-
|
|
7390
|
+
// An [autofocus] that is not shown (behind a :show, a player in a
|
|
7391
|
+
// dialog that is showing something else) cannot take focus: skipped, or
|
|
7392
|
+
// focus went nowhere and the panel's first control never got it.
|
|
7393
|
+
if (!target && panel) target = _overlayShown(panel.querySelectorAll('[autofocus]'))[0] || _overlayFocusable(panel)[0] || panel;
|
|
7377
7394
|
if (target && target.focus) target.focus();
|
|
7378
7395
|
if (target && document.activeElement === target) return;
|
|
7379
7396
|
if (attempts > 0) _overlaySoon(function() { _overlayFocusIn(entry, attempts - 1); });
|
package/dist/ssg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-2hc5mbw8.js";import"./chunk-
|
|
2
|
+
import"./chunk-2hc5mbw8.js";import"./chunk-0ytm2ecf.js";import"./chunk-9mjy16pw.js";import{et,tt,nt,rt,st,ot}from"./chunk-kpns3659.js";import"./chunk-5tyes97j.js";import"./chunk-ba88n1j7.js";import{f,Be,N,K,n,o}from"./chunk-mh7k2ps4.js";import"./chunk-7p0zerfj.js";import{nr}from"./chunk-8m3k43d3.js";import"./chunk-6k4f583z.js";import"./chunk-w9srfsfk.js";import"./chunk-e6y6s7q8.js";import"./chunk-299xbyhn.js";import"./chunk-he404gbh.js";import{ie,mt,ht}from"./chunk-4625sykb.js";import{Oo,Do,Mo}from"./chunk-1v6yyvxf.js";import{ft,Yt,Zt}from"./chunk-g7ey7mtw.js";import"./chunk-58jyc7kp.js";import{a}from"./chunk-2y82wf9d.js";import x from"fs";import g from"path";import{createHash as Dt}from"crypto";function Rt(t){try{return new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(t).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return t}}var kt=/<script\s+type="stx\/island"\s+data-stx-island="([^"]+)"([^>]*)>([\s\S]*?)<\/script>/g;function Ct(t){return Bun.hash(t).toString(16)}function ut(t,i={}){if(!t.includes('type="stx/island"'))return{html:t,chunks:[]};let s=new Map,r=t.replace(kt,(e,l,w,y)=>{let h=y.trim();if(!h)return e;if(/\bdata-stx-src=/.test(w))return e;if(i.minify)h=Rt(h);let S=Ct(h);if(!s.has(S))s.set(S,h);let P=i.integrity?` data-stx-integrity="sha384-${Dt("sha384").update(h).digest("base64")}"`:"";return`<script type="stx/island" data-stx-island="${l}" data-stx-src="/_stx/islands/${S}.js"${P}${w}></script>`}),c=Array.from(s,([e,l])=>({hash:e,code:l}));return{html:r,chunks:c}}var Et=new Set(["visible","idle"]);function dt(t){if(!t.includes("data-stx-src="))return t;let i=new Map,s=/data-stx-scope="([^"]+)"[^>]*?stx-hydrate="([^"]+)"/g,r;while((r=s.exec(t))!==null)i.set(r[1],r[2]);let c=new Set,e=/data-stx-island="([^"]+)"[^>]*?data-stx-src="([^"]+)"/g,l;while((l=e.exec(t))!==null)if(Et.has(i.get(l[1])||""))c.add(l[2]);let w=t.lastIndexOf("</head>");if(c.size===0||w===-1)return t;let y=Array.from(c).filter((h)=>!t.includes(`rel="prefetch" href="${h}"`)).map((h)=>`<link rel="prefetch" href="${h}" as="script">`).join("");if(!y)return t;return t.slice(0,w)+y+t.slice(w)}var It=["STX_SITE_URL","SITE_URL","URL","VERCEL_URL","CF_PAGES_URL"];function q(t){let i=t.trim();if(!i)return null;let s=/^https?:\/\//i.test(i)?i:`https://${i}`;try{return new URL(s).origin+new URL(s).pathname.replace(/\/$/,"")}catch{return null}}function Bt(t){for(let i of It){let s=t[i];if(!s)continue;let r=q(s);if(r)return{url:r,source:"env",via:i}}return null}function gt(t){if(!t||typeof t!=="object")return null;let i=t,s=i.site?.url??i.url??i.app?.url;return typeof s==="string"?q(s):null}async function jt(t){let{existsSync:i}=await import("fs"),s=await import("path");for(let r of["site.config.ts","site.config.js",".config/site.config.ts"]){let c=s.resolve(t,r);if(!i(c))continue;try{let e=await import(c),l=gt(e.default??e);if(l)return l}catch{}}return null}async function pt(t={}){let i=t.cwd??process.cwd(),s=t.env??process.env;if(t.explicit){let l=q(t.explicit);if(l)return{url:l,source:"option"}}let r=gt(t.stxConfig);if(r)return{url:r,source:"stx.config",via:"site.url"};let c=await jt(i);if(c)return{url:c,source:"site.config",via:"url"};let e=Bt(s);if(e)return e;return{url:"http://localhost",source:"fallback"}}function wt(){return["No site URL configured \u2014 sitemap.xml and robots.txt will point at http://localhost."," Set one in stx.config.ts (site: { url: 'https://example.com' }), in site.config.ts,"," via --domain, or with SITE_URL in the build environment."].join(`
|
|
3
3
|
`)}class yt{cacheDir;cache=new Map;loaded=!1;salt;constructor(t,i=""){this.cacheDir=t,this.salt=i}async load(){if(this.loaded)return;let t=g.join(this.cacheDir,"build-cache.json");if(await Bun.file(t).exists())try{let i=JSON.parse(await Bun.file(t).text());for(let[s,r]of Object.entries(i))this.cache.set(s,r)}catch{}this.loaded=!0}async save(){await x.promises.mkdir(this.cacheDir,{recursive:!0});let t=g.join(this.cacheDir,"build-cache.json"),i={};for(let[s,r]of this.cache)i[s]=r;await Bun.write(t,JSON.stringify(i))}getHash(t,i){let s=x.statSync(t),r=`${this.salt}|${t}:${s.mtimeMs}`;for(let e of i)if(x.existsSync(e)){let l=x.statSync(e);r+=`:${e}:${l.mtimeMs}`}let c=0;for(let e=0;e<r.length;e++){let l=r.charCodeAt(e);c=(c<<5)-c+l,c=c&c}return Math.abs(c).toString(36)}get(t,i){let s=this.cache.get(t);if(!s)return null;let r=this.getHash(i,s.dependencies??[]);if(s.hash!==r)return this.cache.delete(t),null;return s.html}set(t,i,s,r){let c=this.getHash(i,s);this.cache.set(t,{hash:c,html:r,generatedAt:Date.now(),dependencies:s})}}class St{cacheDir;constructor(t){this.cacheDir=t}getFilePath(t){let i=t.replace(/[^a-zA-Z0-9]/g,"_")+".json";return g.join(this.cacheDir,"isr",i)}async get(t){let i=this.getFilePath(t);if(!await Bun.file(i).exists())return null;try{return JSON.parse(await Bun.file(i).text())}catch{return null}}async set(t,i){let s=this.getFilePath(t);await x.promises.mkdir(g.dirname(s),{recursive:!0}),await Bun.write(s,JSON.stringify(i))}async invalidate(t){let i=this.getFilePath(t);if(await Bun.file(i).exists())await x.promises.unlink(i)}async invalidatePattern(t){let i=g.join(this.cacheDir,"isr");if(!x.existsSync(i))return;let s=await x.promises.readdir(i);for(let r of s){let c=r.replace(/_/g,"/").replace(".json","");if(t.test(c))await x.promises.unlink(g.join(i,r))}}async needsRevalidation(t){let i=await this.get(t);if(!i)return!0;return Date.now()>i.revalidateAfter}}async function Ft(t){try{let s=(await Bun.file(t).text()).match(/<script\s+server\b[^>]*>([\s\S]*?)<\/script>/i);if(!s)return null;let r=s[1];if(!r.includes("getStaticPaths"))return null;let c=r.match(/(?:export\s+)?(?:async\s+)?function\s+getStaticPaths\s*\([^)]*\)\s*\{([\s\S]*?)\n[\t ]*\}/);if(!c)return null;return await Function(`
|
|
4
4
|
return (async function getStaticPaths() {
|
|
5
5
|
${c[1]}
|
|
@@ -41,7 +41,7 @@ ${t.map((r)=>{let c=new URL(r.loc,i).href,e=` <url>
|
|
|
41
41
|
${s.join(`
|
|
42
42
|
`)}
|
|
43
43
|
</channel>
|
|
44
|
-
</rss>`}async function zt(t={}){let i=Date.now();ht();let s=await o(process.cwd()),r=s.build||{},c=await pt({explicit:t.domain||r.domain,stxConfig:s});if(c.source==="fallback"&&(t.sitemap??r.sitemap??!0))console.warn(wt());let e={router:t.router??s?.router??{},pagesDir:t.pagesDir||r.pagesDir||"pages",outputDir:t.outputDir||r.outputDir||"dist",baseUrl:t.baseUrl||r.baseUrl||"/",domain:c.url,revalidate:t.revalidate??r.revalidate??!1,sitemap:t.sitemap??r.sitemap??!0,sitemapExclude:t.sitemapExclude||r.sitemapExclude||[],robots:t.robots??r.robots??!0,rss:t.rss??r.rss??!1,concurrency:t.concurrency||r.concurrency||10,cache:t.cache??r.cache??!0,cacheDir:t.cacheDir||r.cacheDir||a(process.cwd(),"ssg-cache"),contentLoaders:t.contentLoaders||[],hooks:t.hooks||{},minify:t.minify??r.minify??!0,generate404:t.generate404??r.generate404??!0,publicDir:t.publicDir||r.publicDir||"public",trailingSlash:t.trailingSlash??r.trailingSlash??!1,cleanOutput:t.cleanOutput??r.cleanOutput??!0,cacheSalt:t.cacheSalt??"",partialsDir:t.partialsDir||s?.partialsDir||"",componentsDir:t.componentsDir||s?.componentsDir||"",failOnIncludeError:t.failOnIncludeError??!0,failOnServerScriptError:t.failOnServerScriptError??!0,chunkIslands:t.chunkIslands===!0,prefetchIslands:t.prefetchIslands===!0,integrityIslands:t.integrityIslands===!0},l={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},w=new Set,y=0,h={},S={};await e.hooks.onBuildStart?.();try{if(e.cleanOutput&&x.existsSync(e.outputDir))await x.promises.rm(e.outputDir,{recursive:!0});await x.promises.mkdir(e.outputDir,{recursive:!0});let D=e.cacheSalt;if(!D){let{resolveUserCssConfig:u,fingerprintConfig:m}=await import("./chunk-
|
|
44
|
+
</rss>`}async function zt(t={}){let i=Date.now();ht();let s=await o(process.cwd()),r=s.build||{},c=await pt({explicit:t.domain||r.domain,stxConfig:s});if(c.source==="fallback"&&(t.sitemap??r.sitemap??!0))console.warn(wt());let e={router:t.router??s?.router??{},pagesDir:t.pagesDir||r.pagesDir||"pages",outputDir:t.outputDir||r.outputDir||"dist",baseUrl:t.baseUrl||r.baseUrl||"/",domain:c.url,revalidate:t.revalidate??r.revalidate??!1,sitemap:t.sitemap??r.sitemap??!0,sitemapExclude:t.sitemapExclude||r.sitemapExclude||[],robots:t.robots??r.robots??!0,rss:t.rss??r.rss??!1,concurrency:t.concurrency||r.concurrency||10,cache:t.cache??r.cache??!0,cacheDir:t.cacheDir||r.cacheDir||a(process.cwd(),"ssg-cache"),contentLoaders:t.contentLoaders||[],hooks:t.hooks||{},minify:t.minify??r.minify??!0,generate404:t.generate404??r.generate404??!0,publicDir:t.publicDir||r.publicDir||"public",trailingSlash:t.trailingSlash??r.trailingSlash??!1,cleanOutput:t.cleanOutput??r.cleanOutput??!0,cacheSalt:t.cacheSalt??"",partialsDir:t.partialsDir||s?.partialsDir||"",componentsDir:t.componentsDir||s?.componentsDir||"",failOnIncludeError:t.failOnIncludeError??!0,failOnServerScriptError:t.failOnServerScriptError??!0,chunkIslands:t.chunkIslands===!0,prefetchIslands:t.prefetchIslands===!0,integrityIslands:t.integrityIslands===!0},l={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},w=new Set,y=0,h={},S={};await e.hooks.onBuildStart?.();try{if(e.cleanOutput&&x.existsSync(e.outputDir))await x.promises.rm(e.outputDir,{recursive:!0});await x.promises.mkdir(e.outputDir,{recursive:!0});let D=e.cacheSalt;if(!D){let{resolveUserCssConfig:u,fingerprintConfig:m}=await import("./chunk-h80p2gkn.js");try{D=m(await u(process.cwd()))}catch{}}let{prepareImageDelivery:p}=await import("./chunk-rypj5y6d.js"),b=await p(e.publicDir,e.outputDir);if(b.count>0)console.log(`Optimized ${b.count} image(s) for responsive delivery`),D=[D,b.fingerprint].filter(Boolean).join(":");let B=new yt(e.cacheDir,D);if(e.cache)await B.load();try{let{generateCss:u}=await import("./chunk-h80p2gkn.js");await u('<div class="bg-black"></div>')}catch{}et();let vt=s?.routeMiddleware?.dir||"middleware";await nt(process.cwd(),vt);let H=tt();if(H.length>0)console.log(`Loaded ${H.length} middleware: ${H.join(", ")}`);let bt=s?.routeMiddleware?.global||[];Mo(s?.layoutsDir,a(process.cwd()));let V=N(".",{pagesDir:e.pagesDir,pagesDirs:s?._layerPageDirs});console.log(`Found ${V.length} routes`);let _=[];for(let u of V){let m=await Ot(u);for(let v of m)_.push({route:u,url:v.url,params:v.params,props:v.props,revalidate:v.revalidate??e.revalidate})}l.totalPages=_.length,console.log(`Generating ${l.totalPages} pages...`);let A=[],X=[];for(let u=0;u<_.length;u+=e.concurrency)X.push(_.slice(u,u+e.concurrency));for(let u of X)await Promise.all(u.map(async(m)=>{let{route:v,url:d,params:L,props:Pt,revalidate:Q}=m;try{await e.hooks.onPageStart?.(d);let j=await Bun.file(v.filePath).text(),F=Jt(j),$t=F?.middleware?Array.isArray(F.middleware)?F.middleware:[F.middleware]:[],it=[...bt,...$t];if(it.length>0){let C=rt(d,L,F||{}),O=st(C,null,void 0,{isServer:!0}),E=await ot(it,O);if(E.redirect){let R=typeof E.redirect==="string"?E.redirect:E.redirect.path||E.redirect,U=Vt(String(R),d),T=Kt(d,e);await x.promises.mkdir(g.dirname(T),{recursive:!0}),await Bun.write(T,U),l.successCount++,l.pages.push({route:d,outputPath:T,size:Buffer.byteLength(U),cached:!1}),A.push({loc:d,lastmod:new Date().toISOString()}),console.log(` \u21B3 ${d} \u2192 redirect to ${R}`);return}if(E.abort){let R=typeof E.abort==="string"?E.abort:E.abort?.error?.message||"aborted";console.warn(` \u21B3 ${d} \u2014 middleware aborted: ${R}`);return}}let at=j.match(/definePageMeta\s*\(\s*\{[\s\S]*?validate\s*:\s*((?:\([^)]*\)|[^,}])*(?:\{[\s\S]*?\})?)/m);if(at)try{if(!await Function("route",`
|
|
45
45
|
const validate = ${at[1]};
|
|
46
46
|
return validate(route);
|
|
47
47
|
`)({params:L})){console.warn(`Validation failed for ${d}, skipping...`);return}}catch{}let k=null,ct=!1;if(e.cache){if(k=B.get(d,v.filePath),k)ct=!0,l.cachedCount++}if(!k){let C=await xt(v,L,Pt,e,s);if(k=C.html,e.failOnIncludeError&&C.includeFailures.length>0)throw Error(`${C.includeFailures.length} include(s) failed to resolve, so this page would have shipped with an error banner where the markup should be:
|
|
@@ -73,7 +73,7 @@ ${u}`)}if(e.cache)await B.save();if(e.generate404){let u=g.join(e.pagesDir,"404.
|
|
|
73
73
|
<a href="/">Go home</a>
|
|
74
74
|
</div>
|
|
75
75
|
</body>
|
|
76
|
-
</html>`)}for(let u of[500]){let m=g.join(e.pagesDir,`${u}.stx`);if(await Bun.file(m).exists()){let v=new Set,d={...s,debug:!1,cache:!1},L=await n(await Bun.file(m).text(),{},m,d,v);await Bun.write(g.join(e.outputDir,`${u}.html`),L)}}let W=g.join(e.pagesDir,"error.stx");if(await Bun.file(W).exists()){let u=new Set,m={...s,debug:!1,cache:!1},v=await n(await Bun.file(W).text(),{},W,m,u);await Bun.write(g.join(e.outputDir,"error.html"),v)}if(e.sitemap&&A.length>0){let u=Gt(A,e.domain),m=g.join(e.outputDir,"sitemap.xml");await Bun.write(m,u),l.sitemapPath=m,console.log(`Generated sitemap.xml with ${A.length} URLs`)}if(e.robots!==!1){let u=typeof e.robots==="object"?e.robots:{},m=[...e.sitemapExclude.filter((d)=>typeof d==="string"),...u.disallow||[]],v=nr({rules:[{userAgent:u.userAgent||"*",allow:u.allow||["/"],...m.length>0?{disallow:m}:{}}],...u.sitemap!==!1&&l.sitemapPath?{sitemap:new URL("/sitemap.xml",e.domain).href}:{}});await Bun.write(g.join(e.outputDir,"robots.txt"),v),console.log("Generated robots.txt")}if(e.rss){let u=typeof e.rss==="object"?e.rss:{title:"Site Feed",description:"Latest updates",link:e.domain},m=[];if(u.getItems)m=await u.getItems();let v=Nt(u,m),d=g.join(e.outputDir,"rss.xml");await Bun.write(d,v),l.rssPath=d,console.log(`Generated rss.xml with ${m.length} items`)}let G=
|
|
76
|
+
</html>`)}for(let u of[500]){let m=g.join(e.pagesDir,`${u}.stx`);if(await Bun.file(m).exists()){let v=new Set,d={...s,debug:!1,cache:!1},L=await n(await Bun.file(m).text(),{},m,d,v);await Bun.write(g.join(e.outputDir,`${u}.html`),L)}}let W=g.join(e.pagesDir,"error.stx");if(await Bun.file(W).exists()){let u=new Set,m={...s,debug:!1,cache:!1},v=await n(await Bun.file(W).text(),{},W,m,u);await Bun.write(g.join(e.outputDir,"error.html"),v)}if(e.sitemap&&A.length>0){let u=Gt(A,e.domain),m=g.join(e.outputDir,"sitemap.xml");await Bun.write(m,u),l.sitemapPath=m,console.log(`Generated sitemap.xml with ${A.length} URLs`)}if(e.robots!==!1){let u=typeof e.robots==="object"?e.robots:{},m=[...e.sitemapExclude.filter((d)=>typeof d==="string"),...u.disallow||[]],v=nr({rules:[{userAgent:u.userAgent||"*",allow:u.allow||["/"],...m.length>0?{disallow:m}:{}}],...u.sitemap!==!1&&l.sitemapPath?{sitemap:new URL("/sitemap.xml",e.domain).href}:{}});await Bun.write(g.join(e.outputDir,"robots.txt"),v),console.log("Generated robots.txt")}if(e.rss){let u=typeof e.rss==="object"?e.rss:{title:"Site Feed",description:"Latest updates",link:e.domain},m=[];if(u.getItems)m=await u.getItems();let v=Nt(u,m),d=g.join(e.outputDir,"rss.xml");await Bun.write(d,v),l.rssPath=d,console.log(`Generated rss.xml with ${m.length} items`)}let G=Oo(e.outputDir);if(G.assets>0)console.log(`Externalized ${G.assets} asset(s) from ${G.pages} page(s) (${(G.bytesInlined/1024).toFixed(1)}KB removed from HTML)`);let z=Do(e.outputDir);if(z.assets>0)console.log(`Externalized ${z.assets} repeated asset(s) from ${z.pages} page(s) (${(z.bytesInlined/1024).toFixed(1)}KB removed from HTML)`);if(e.publicDir&&x.existsSync(e.publicDir))await J(e.publicDir,e.outputDir),console.log(`Copied public assets from ${e.publicDir}`);let Z=Zt();if(Z)await J(Z,g.join(e.outputDir,Yt)),console.log(`Copied assets from ${ft}`)}catch(D){throw await e.hooks.onError?.(D),D}if(l.buildTime=Date.now()-i,w.size>0){l.islandChunks={count:w.size,totalBytes:y};let D={generatedChunks:w.size,totalBytes:y,chunks:h,pages:S};await Bun.write(g.join(e.outputDir,"_stx","islands-manifest.json"),JSON.stringify(D,null,2))}await e.hooks.onBuildEnd?.(l);let P=l.islandChunks?`
|
|
77
77
|
Island chunks: ${l.islandChunks.count} (${(l.islandChunks.totalBytes/1024).toFixed(1)} KB lifted out of inline HTML)`:"";return console.log(`
|
|
78
78
|
Build complete!
|
|
79
79
|
Total: ${l.totalPages} pages
|
|
@@ -996,6 +996,19 @@ export interface StxConfig {
|
|
|
996
996
|
* Progress-bar height including units (e.g. '2px', '3px'). Default: '2px'.
|
|
997
997
|
*/
|
|
998
998
|
progressHeight?: string;
|
|
999
|
+
/**
|
|
1000
|
+
* Fetch the pages of links as they scroll into view, so the first tap on
|
|
1001
|
+
* one is a swap. Their module bundles wait for an intent (a hover, a
|
|
1002
|
+
* touch) or the tap. Default: true.
|
|
1003
|
+
*/
|
|
1004
|
+
prefetchVisible?: boolean;
|
|
1005
|
+
/** At most this many links prefetched on sight per page. Default: 12. */
|
|
1006
|
+
prefetchVisibleMax?: number;
|
|
1007
|
+
/**
|
|
1008
|
+
* Fetch the fragment of the page the app was opened on once it is idle,
|
|
1009
|
+
* so Back to it is a swap rather than a round trip. Default: true.
|
|
1010
|
+
*/
|
|
1011
|
+
keepOpening?: boolean;
|
|
999
1012
|
};
|
|
1000
1013
|
/**
|
|
1001
1014
|
* Custom router instance (e.g. @stacksjs/bun-router) for API handling.
|