@stacksjs/stx 0.2.401 → 0.2.403
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-0j5wwmha.js +2 -0
- package/dist/{chunk-197z74b9.js → chunk-111tdjzz.js} +1 -1
- package/dist/{chunk-0fwecpfm.js → chunk-13y7rx8s.js} +2 -2
- package/dist/chunk-1h9scy70.js +2 -0
- package/dist/chunk-1hw8p2g4.js +2 -0
- package/dist/chunk-1xtexfat.js +2 -0
- package/dist/{chunk-fffbzsmv.js → chunk-21adgg8e.js} +1 -1
- package/dist/{chunk-x86qttwm.js → chunk-2g3ffsc9.js} +1 -1
- package/dist/{chunk-dz29q408.js → chunk-2m17v3yx.js} +1 -1
- package/dist/{chunk-k2nydt80.js → chunk-2n3twnde.js} +1 -1
- package/dist/{chunk-h55mae9h.js → chunk-3t953qe0.js} +1 -1
- package/dist/{chunk-1ktxk84n.js → chunk-3tmnemhq.js} +1 -1
- package/dist/{chunk-cy8hgd86.js → chunk-4azk3jdd.js} +1 -1
- package/dist/{chunk-v7q2nf37.js → chunk-4m2e8w2g.js} +1 -1
- package/dist/{chunk-c9kj8p6j.js → chunk-4yc9gx6h.js} +1 -1
- package/dist/chunk-50dtatwe.js +2 -0
- package/dist/chunk-55d66wh7.js +2 -0
- package/dist/{chunk-7bym5kky.js → chunk-55zcahp8.js} +168 -168
- package/dist/{chunk-45etne17.js → chunk-591hdx99.js} +1 -1
- package/dist/{chunk-zh3q10wd.js → chunk-5kzcyx1w.js} +1 -1
- package/dist/{chunk-1rskz446.js → chunk-65c929m6.js} +1 -1
- package/dist/{chunk-cd6pe75s.js → chunk-6jns68ee.js} +1 -1
- package/dist/chunk-6r6vhgvs.js +2 -0
- package/dist/{chunk-3znzj20j.js → chunk-6sjgte7b.js} +1 -1
- package/dist/{chunk-pm8wzxsb.js → chunk-7sfyczn6.js} +1 -1
- package/dist/{chunk-yj5gkn17.js → chunk-7vftjm43.js} +1 -1
- package/dist/chunk-7xfg6y4j.js +2 -0
- package/dist/chunk-823mas5p.js +2 -0
- package/dist/{chunk-zrnppyqz.js → chunk-8e287qw8.js} +1 -1
- package/dist/{chunk-e1rv01pn.js → chunk-8ghwewek.js} +2 -2
- package/dist/chunk-8v4jamr6.js +2 -0
- package/dist/chunk-8xv6f2y5.js +2 -0
- package/dist/{chunk-p81zbym6.js → chunk-9a79ev5a.js} +1 -1
- package/dist/{chunk-88tt0qg0.js → chunk-9rp8f7jz.js} +2 -2
- package/dist/{chunk-8xm3z6dh.js → chunk-a4fpc5cy.js} +1 -1
- package/dist/{chunk-twws9vvz.js → chunk-ab9b859e.js} +2 -2
- package/dist/{chunk-7tgjn256.js → chunk-ah8gs0q2.js} +1 -1
- package/dist/{chunk-aewsgyzc.js → chunk-av7a1sct.js} +1 -1
- package/dist/{chunk-d4km7egg.js → chunk-b1hqgm6j.js} +1 -1
- package/dist/{chunk-aeaf5nsy.js → chunk-b89mqprp.js} +1 -1
- package/dist/{chunk-j9x1hxhg.js → chunk-baa5pana.js} +1 -1
- package/dist/{chunk-5zmppe0c.js → chunk-bd0eyzgz.js} +1 -1
- package/dist/{chunk-caj47vtj.js → chunk-bdy1fpqq.js} +1 -1
- package/dist/chunk-bsjdt7a2.js +2 -0
- package/dist/{chunk-rxz43r6k.js → chunk-cevkpyn9.js} +1 -1
- package/dist/{chunk-8kkqx4sc.js → chunk-cjcttjtx.js} +1 -1
- package/dist/{chunk-61cwdy7h.js → chunk-cpx2gkpr.js} +1 -1
- package/dist/{chunk-0rdhrgff.js → chunk-cvkty3ha.js} +1 -1
- package/dist/{chunk-kfhm9vh1.js → chunk-cxq9g7ys.js} +2 -2
- package/dist/{chunk-x2wmn8m7.js → chunk-d6rkgay9.js} +2 -2
- package/dist/{chunk-r1d9x0dy.js → chunk-ddh21d04.js} +1 -1
- package/dist/chunk-dggtfj6h.js +2 -0
- package/dist/chunk-dhq182fh.js +2 -0
- package/dist/{chunk-ar5stjnb.js → chunk-dnew7qmv.js} +1 -1
- package/dist/{chunk-pqc4sv02.js → chunk-dpe25csh.js} +2 -2
- package/dist/{chunk-8ded3tn8.js → chunk-e5aqq9ms.js} +1 -1
- package/dist/{chunk-wmqhn6rq.js → chunk-eby93tx5.js} +1 -1
- package/dist/{chunk-bf6zcjr5.js → chunk-egbb8eg8.js} +1 -1
- package/dist/{chunk-vs4dafbz.js → chunk-ek069b44.js} +1 -1
- package/dist/chunk-f4f5dzfg.js +2 -0
- package/dist/{chunk-57yhrery.js → chunk-fpqz7msz.js} +1 -1
- package/dist/{chunk-rwtj7j0r.js → chunk-fpxz25xz.js} +1 -1
- package/dist/{chunk-pdxbys31.js → chunk-fwc5p9bn.js} +1 -1
- package/dist/{chunk-4x73bm95.js → chunk-gbwqy9py.js} +1 -1
- package/dist/{chunk-dvpk2rer.js → chunk-gs67nnfb.js} +1 -1
- package/dist/chunk-gtrn2yht.js +2 -0
- package/dist/{chunk-kdwbpcm4.js → chunk-h7qv6sc5.js} +1 -1
- package/dist/chunk-hmz9rr5a.js +2 -0
- package/dist/{chunk-gtn2agxa.js → chunk-ht9rdkf3.js} +1 -1
- package/dist/{chunk-h01bbt3r.js → chunk-hw96m872.js} +1 -1
- package/dist/{chunk-xfedcdb2.js → chunk-j665en0c.js} +1 -1
- package/dist/{chunk-w4nmvn5v.js → chunk-j6p78bma.js} +1 -1
- package/dist/{chunk-3769e62c.js → chunk-jct6cs2k.js} +1 -1
- package/dist/chunk-jz8tbpkr.js +2 -0
- package/dist/{chunk-4eyzkbzj.js → chunk-kdqcb0r5.js} +1 -1
- package/dist/chunk-kvdd2zfn.js +2 -0
- package/dist/{chunk-mgndzdqy.js → chunk-m28xqhyz.js} +1 -1
- package/dist/{chunk-h7sgg3vh.js → chunk-m2z8dygn.js} +2 -2
- package/dist/{chunk-g7qmxjyc.js → chunk-mjearf0g.js} +1 -1
- package/dist/{chunk-980w4zcq.js → chunk-mntzk6ga.js} +1 -1
- package/dist/{chunk-kyw2cbvn.js → chunk-msecn1gm.js} +1 -1
- package/dist/{chunk-ef3y864p.js → chunk-myy3t2d9.js} +1 -1
- package/dist/{chunk-eqhsprr0.js → chunk-nn42gs3q.js} +1 -1
- package/dist/chunk-nnrddx81.js +2 -0
- package/dist/{chunk-hm66z7e8.js → chunk-nt03zdme.js} +1 -1
- package/dist/chunk-nxpj3hcz.js +2 -0
- package/dist/chunk-nz0kaf2c.js +2 -0
- package/dist/chunk-pp8e3t71.js +2 -0
- package/dist/{chunk-d0qy1ezf.js → chunk-qbc0bebg.js} +2 -2
- package/dist/{chunk-fsvkqeya.js → chunk-qnye902b.js} +1 -1
- package/dist/{chunk-nm7jfzmz.js → chunk-rb8re2my.js} +2 -2
- package/dist/{chunk-bdz7nznw.js → chunk-rk8p4b1z.js} +2 -2
- package/dist/chunk-s8kfsq5y.js +2 -0
- package/dist/{chunk-h8zp2fz9.js → chunk-saf4xhac.js} +1 -1
- package/dist/chunk-skzpase5.js +2 -0
- package/dist/{chunk-btn4481e.js → chunk-sq13nzd0.js} +1 -1
- package/dist/{chunk-q4v62yed.js → chunk-szcxpbfn.js} +38 -6
- package/dist/{chunk-76q768gt.js → chunk-tev79q0a.js} +1 -1
- package/dist/{chunk-7c8r36ve.js → chunk-tft187yn.js} +3 -3
- package/dist/chunk-tjc1mdsb.js +2 -0
- package/dist/chunk-tqrcnb4e.js +2 -0
- package/dist/{chunk-zstrcmbj.js → chunk-tte381m0.js} +415 -332
- package/dist/{chunk-csgshaeh.js → chunk-v54tq312.js} +1 -1
- package/dist/{chunk-epzm35py.js → chunk-v9jmsv0r.js} +1 -1
- package/dist/{chunk-wh8vwykh.js → chunk-vaxepwj5.js} +1 -1
- package/dist/{chunk-re9rv45k.js → chunk-vr5benrm.js} +1 -1
- package/dist/{chunk-ekvejzvk.js → chunk-wheh08v2.js} +1 -1
- package/dist/{chunk-5zapxgys.js → chunk-wm07h8q1.js} +1 -1
- package/dist/{chunk-hh8abhtc.js → chunk-wvhgsjdt.js} +1 -1
- package/dist/{chunk-8qzc5n61.js → chunk-x1c4vcds.js} +1 -1
- package/dist/{chunk-21dz636m.js → chunk-xnnyfxxv.js} +1 -1
- package/dist/{chunk-4cv7bw5e.js → chunk-y9f9g2kh.js} +2 -2
- package/dist/chunk-yzkm9hzf.js +2 -0
- package/dist/chunk-zan0j833.js +2 -0
- package/dist/{chunk-r0jqyxbc.js → chunk-zbwr9zbp.js} +1 -1
- package/dist/cli.js +14 -14
- package/dist/composables/use-offline.d.ts +6 -5
- package/dist/composables/use-offline.js +20 -1
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/database.js +1 -1
- package/dist/doctor.d.ts +35 -0
- package/dist/doctor.js +95 -0
- package/dist/offline/app-service-worker.d.ts +28 -2
- package/dist/offline/app-service-worker.js +115 -13
- package/dist/process.d.ts +0 -3
- package/dist/process.js +12 -3
- package/dist/pwa.js +2 -2
- package/dist/signal-processing.d.ts +29 -11
- package/dist/signal-processing.js +40 -0
- package/dist/signals.js +37 -5
- package/dist/ssg.js +2 -2
- package/dist/visual-testing.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-07syq64h.js +0 -2
- package/dist/chunk-0nqcv7z7.js +0 -2
- package/dist/chunk-160zge7a.js +0 -2
- package/dist/chunk-19kj26z3.js +0 -2
- package/dist/chunk-1nj174s0.js +0 -2
- package/dist/chunk-1s9jswhp.js +0 -2
- package/dist/chunk-2m88psbh.js +0 -2
- package/dist/chunk-2x9gpv2d.js +0 -2
- package/dist/chunk-3t17hkar.js +0 -2
- package/dist/chunk-3wsrhb1a.js +0 -2
- package/dist/chunk-65y5abx7.js +0 -2
- package/dist/chunk-6n0jamtd.js +0 -2
- package/dist/chunk-7vnkqnyh.js +0 -2
- package/dist/chunk-8ywzw4h9.js +0 -2
- package/dist/chunk-9hh5eg8y.js +0 -2
- package/dist/chunk-bgy4hwh4.js +0 -2
- package/dist/chunk-ch2aycnm.js +0 -2
- package/dist/chunk-cmnve329.js +0 -2
- package/dist/chunk-k9t7pyb8.js +0 -2
- package/dist/chunk-kp4ja0w3.js +0 -2
- package/dist/chunk-kxxph6d4.js +0 -2
- package/dist/chunk-s4yq7q1d.js +0 -2
- package/dist/chunk-vyn2y774.js +0 -2
- package/dist/chunk-w680bfze.js +0 -2
- package/dist/chunk-waz1sddd.js +0 -2
- package/dist/chunk-wdszjnbp.js +0 -2
- package/dist/chunk-x3h04mgd.js +0 -2
- package/dist/chunk-y5gyez1p.js +0 -2
- package/dist/chunk-zfs01pjr.js +0 -2
|
@@ -10,8 +10,13 @@
|
|
|
10
10
|
* - Pages and fragments: network first, with a short timeout, and the last
|
|
11
11
|
* copy when the network is not there. The screens named in `pages` are
|
|
12
12
|
* fetched when the worker installs, so they open offline even before they
|
|
13
|
-
* were visited
|
|
14
|
-
* the router reload into
|
|
13
|
+
* were visited, with the stylesheets and scripts they link to. Kept per
|
|
14
|
+
* build: a fragment from another build would make the router reload into
|
|
15
|
+
* nothing.
|
|
16
|
+
* - Dynamic screens named in `routes` (`/m/workout/:id`): one never opened is
|
|
17
|
+
* answered offline with the route's kept page, its params swapped for the
|
|
18
|
+
* ones asked for. For a page drawn on the device from the API, every value
|
|
19
|
+
* shares the page, so a session the phone never showed still opens.
|
|
15
20
|
* - The build's own files (`/_stx/…`) and public assets: the cached copy at
|
|
16
21
|
* once, refreshed behind.
|
|
17
22
|
* - API reads (`apiPrefix`, GET only): network first, the last answer offline.
|
|
@@ -31,6 +36,15 @@ export interface OfflineAppConfig {
|
|
|
31
36
|
networkTimeoutMs?: number;
|
|
32
37
|
/** Where a page that was never cached goes offline (one of `pages`). Default: the first of `pages`. */
|
|
33
38
|
fallback?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Dynamic screens whose page is the same for every value, drawn on the
|
|
41
|
+
* device from the API: `/m/workout/:id` or `/m/workout/[id]`. One that was
|
|
42
|
+
* never opened is answered offline with the route's kept page, its route
|
|
43
|
+
* params replaced by the ones asked for. The route's page is fetched when
|
|
44
|
+
* the worker installs (each param as `0`) and refreshed by every visit.
|
|
45
|
+
* Leave out a route whose server renders the value's own data.
|
|
46
|
+
*/
|
|
47
|
+
routes?: string[];
|
|
34
48
|
/** Paths the worker leaves alone entirely (prefixes). */
|
|
35
49
|
exclude?: string[];
|
|
36
50
|
/**
|
|
@@ -40,7 +54,19 @@ export interface OfflineAppConfig {
|
|
|
40
54
|
mediaMaxBytes?: number;
|
|
41
55
|
}
|
|
42
56
|
export declare const OFFLINE_WORKER_PATH = "/_stx/sw.js";
|
|
57
|
+
interface OfflineRoute {
|
|
58
|
+
/** The route as configured, which names its kept page. */
|
|
59
|
+
path: string;
|
|
60
|
+
/** Matches a path of this route, one group per param. */
|
|
61
|
+
re: string;
|
|
62
|
+
names: string[];
|
|
63
|
+
/** The path fetched when the worker installs. */
|
|
64
|
+
sample: string;
|
|
65
|
+
}
|
|
66
|
+
/** `/m/workout/:id` and `/m/workout/[id]` as a matcher the worker can carry. */
|
|
67
|
+
export declare function offlineRoute(path: string): OfflineRoute | null;
|
|
43
68
|
/** The tag every page carries so the worker is installed. */
|
|
44
69
|
export declare const OFFLINE_REGISTER_SCRIPT = "<script data-stx-offline>if('serviceWorker' in navigator){addEventListener('load',function(){navigator.serviceWorker.register('/_stx/sw.js',{scope:'/'}).catch(function(){})})}</script>";
|
|
45
70
|
/** The worker itself, for one build. */
|
|
46
71
|
export declare function generateOfflineWorker(config: OfflineAppConfig, buildId: string): string;
|
|
72
|
+
export {};
|
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
export const OFFLINE_WORKER_PATH = "/_stx/sw.js"
|
|
1
|
+
export const OFFLINE_WORKER_PATH = "/_stx/sw.js";
|
|
2
|
+
export function offlineRoute(path) {
|
|
3
|
+
if (typeof path !== "string" || !path.startsWith("/"))
|
|
4
|
+
return null;
|
|
5
|
+
const names = [], sample = [], parts = path.replace(/\/+$/, "").split("/").slice(1).map((segment) => {
|
|
6
|
+
const param = /^:(\w+)$/.exec(segment) || /^\[(\w+)\]$/.exec(segment);
|
|
7
|
+
if (param) {
|
|
8
|
+
names.push(param[1]);
|
|
9
|
+
sample.push("0");
|
|
10
|
+
return "([^/]+)";
|
|
11
|
+
}
|
|
12
|
+
sample.push(segment);
|
|
13
|
+
return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
14
|
+
});
|
|
15
|
+
if (!names.length)
|
|
16
|
+
return null;
|
|
17
|
+
return { path, re: `^/${parts.join("/")}/?$`, names, sample: `/${sample.join("/")}` };
|
|
18
|
+
}
|
|
19
|
+
export const OFFLINE_REGISTER_SCRIPT = `<script data-stx-offline>if('serviceWorker' in navigator){addEventListener('load',function(){navigator.serviceWorker.register('${OFFLINE_WORKER_PATH}',{scope:'/'}).catch(function(){})})}</script>`;
|
|
2
20
|
export function generateOfflineWorker(config, buildId) {
|
|
3
21
|
const settings = {
|
|
4
22
|
build: String(buildId || "dev"),
|
|
@@ -6,6 +24,7 @@ export function generateOfflineWorker(config, buildId) {
|
|
|
6
24
|
api: config.apiPrefix || "/api/",
|
|
7
25
|
timeout: Math.max(500, Number(config.networkTimeoutMs) || 3500),
|
|
8
26
|
fallback: config.fallback || config.pages && config.pages[0] || null,
|
|
27
|
+
routes: (config.routes || []).map(offlineRoute).filter(Boolean),
|
|
9
28
|
exclude: ["/_stx/hmr", OFFLINE_WORKER_PATH, ...config.exclude || []],
|
|
10
29
|
mediaMax: Math.max(10485760, Number(config.mediaMaxBytes) || 629145600)
|
|
11
30
|
};
|
|
@@ -44,13 +63,79 @@ function hashOf(text) {
|
|
|
44
63
|
});
|
|
45
64
|
}
|
|
46
65
|
|
|
66
|
+
// A dynamic route's kept page, under a key no real path has.
|
|
67
|
+
function routeKey(route, fragment) {
|
|
68
|
+
return variantUrl('/__stx_route__' + route.path, fragment);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function routeOf(pathname) {
|
|
72
|
+
for (var i = 0; i < S.routes.length; i++) {
|
|
73
|
+
var match = new RegExp(S.routes[i].re).exec(pathname);
|
|
74
|
+
if (!match) continue;
|
|
75
|
+
var params = {};
|
|
76
|
+
S.routes[i].names.forEach(function (name, at) {
|
|
77
|
+
try { params[name] = decodeURIComponent(match[at + 1]); }
|
|
78
|
+
catch (error) { params[name] = match[at + 1]; }
|
|
79
|
+
});
|
|
80
|
+
return { route: S.routes[i], params: params };
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// The route's kept page with the params asked for in its params script, so
|
|
86
|
+
// useRoute().params reads the value that was opened, not the one kept.
|
|
87
|
+
var PARAMS_SCRIPT = /(<script\\b[^>]*data-stx-route-params[^>]*>\\(function\\(\\)\\{var p=)[\\s\\S]*?(;window\\.__stx_rp)/;
|
|
88
|
+
function withParams(response, params) {
|
|
89
|
+
return response.text().then(function (html) {
|
|
90
|
+
var json = JSON.stringify(params).replace(/</g, '\\\\u003C').replace(/\\u2028/g, '\\\\u2028').replace(/\\u2029/g, '\\\\u2029');
|
|
91
|
+
var body = html.replace(PARAMS_SCRIPT, function (all, open, close) { return open + json + close; });
|
|
92
|
+
var headers = new Headers(response.headers);
|
|
93
|
+
headers.delete('Content-Length');
|
|
94
|
+
return new Response(body, { status: 200, headers: headers });
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The stylesheets and scripts a kept page links to. Each page has its own
|
|
99
|
+
// generated CSS, fetched only when the page is shown: a screen kept at
|
|
100
|
+
// install but never opened online came up offline without its styles.
|
|
101
|
+
var keepingAssets = {};
|
|
102
|
+
var ASSET_REF = /<(?:link|script)\\b[^>]*?\\s(?:href|src)="(\\/[^"]+\\.(?:css|js))"/g;
|
|
103
|
+
function keepAssetsOf(response) {
|
|
104
|
+
return response.text().then(function (html) {
|
|
105
|
+
var urls = [];
|
|
106
|
+
var match;
|
|
107
|
+
ASSET_REF.lastIndex = 0;
|
|
108
|
+
while ((match = ASSET_REF.exec(html))) {
|
|
109
|
+
if (urls.indexOf(match[1]) === -1) urls.push(match[1]);
|
|
110
|
+
}
|
|
111
|
+
return caches.open(ASSETS).then(function (cache) {
|
|
112
|
+
return Promise.all(urls.map(function (url) {
|
|
113
|
+
// A page and its fragment link the same files: one fetch each.
|
|
114
|
+
if (!keepingAssets[url]) {
|
|
115
|
+
keepingAssets[url] = cache.match(url).then(function (hit) {
|
|
116
|
+
if (hit) return;
|
|
117
|
+
return fetch(url, { credentials: 'same-origin' }).then(function (asset) {
|
|
118
|
+
if (asset.status === 200) return cache.put(url, asset);
|
|
119
|
+
});
|
|
120
|
+
}).catch(function () {});
|
|
121
|
+
}
|
|
122
|
+
return keepingAssets[url];
|
|
123
|
+
}));
|
|
124
|
+
});
|
|
125
|
+
}).catch(function () {});
|
|
126
|
+
}
|
|
127
|
+
|
|
47
128
|
function precache() {
|
|
129
|
+
var wanted = S.pages.map(function (page) { return { url: page, key: function (fragment) { return variantUrl(page, fragment); } }; })
|
|
130
|
+
.concat(S.routes.map(function (route) { return { url: route.sample, key: function (fragment) { return routeKey(route, fragment); } }; }));
|
|
48
131
|
return caches.open(SHELL).then(function (cache) {
|
|
49
|
-
return Promise.all(
|
|
132
|
+
return Promise.all(wanted.map(function (page) {
|
|
50
133
|
return Promise.all([false, true].map(function (fragment) {
|
|
51
134
|
var headers = fragment ? { 'X-STX-Router': 'true', 'Accept': 'text/html' } : { 'Accept': 'text/html' };
|
|
52
|
-
return fetch(page, { headers: headers, credentials: 'same-origin' }).then(function (response) {
|
|
53
|
-
if (response.status
|
|
135
|
+
return fetch(page.url, { headers: headers, credentials: 'same-origin' }).then(function (response) {
|
|
136
|
+
if (response.status !== 200 || response.redirected) return;
|
|
137
|
+
var copy = response.clone();
|
|
138
|
+
return Promise.all([cache.put(page.key(fragment), response), keepAssetsOf(copy)]);
|
|
54
139
|
}).catch(function () {});
|
|
55
140
|
}));
|
|
56
141
|
}));
|
|
@@ -93,14 +178,23 @@ function keepMedia(urls) {
|
|
|
93
178
|
wanted.forEach(function (key) {
|
|
94
179
|
chain = chain.then(function () {
|
|
95
180
|
if (index[key]) { index[key].at = Date.now(); return; }
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
181
|
+
// Already stored by the page (cacheMedia downloads while the app is
|
|
182
|
+
// open), so only its size is wanted. Otherwise fetched here.
|
|
183
|
+
return cache.match(key).then(function (stored) {
|
|
184
|
+
if (stored) return stored;
|
|
185
|
+
return fetch(key, { credentials: 'same-origin' }).then(function (response) {
|
|
186
|
+
if (response.status !== 200 || !response.body) return null;
|
|
187
|
+
var type = response.headers.get('Content-Type') || 'application/octet-stream';
|
|
188
|
+
// Streamed into the cache, never held whole: a coach's 300 MB
|
|
189
|
+
// upload read into one blob was enough for iOS to end the worker
|
|
190
|
+
// part way, and nothing was kept.
|
|
191
|
+
return cache.put(key, new Response(response.body, { headers: { 'Content-Type': type, 'Accept-Ranges': 'bytes' } })).then(function () {
|
|
192
|
+
return cache.match(key);
|
|
102
193
|
});
|
|
103
194
|
});
|
|
195
|
+
}).then(function (kept) {
|
|
196
|
+
if (!kept) return;
|
|
197
|
+
return kept.blob().then(function (blob) { index[key] = { bytes: blob.size, at: Date.now() }; });
|
|
104
198
|
}).catch(function () {});
|
|
105
199
|
});
|
|
106
200
|
});
|
|
@@ -179,12 +273,16 @@ function markFallback(response) {
|
|
|
179
273
|
function pageResponse(request) {
|
|
180
274
|
var fragment = isFragment(request);
|
|
181
275
|
var key = variantUrl(request.url, fragment);
|
|
276
|
+
var dynamic = routeOf(new URL(request.url).pathname);
|
|
182
277
|
var network = fetch(request).then(function (response) {
|
|
183
278
|
// Only a page that is what was asked for: a redirect (to a sign-in page)
|
|
184
279
|
// or an error is not kept as this screen.
|
|
185
280
|
if (response.status === 200 && !response.redirected && response.type === 'basic') {
|
|
186
281
|
var copy = response.clone();
|
|
187
|
-
|
|
282
|
+
var routeCopy = dynamic ? response.clone() : null;
|
|
283
|
+
caches.open(SHELL).then(function (cache) {
|
|
284
|
+
return Promise.all([cache.put(key, copy), routeCopy && cache.put(routeKey(dynamic.route, fragment), routeCopy)]);
|
|
285
|
+
}).catch(function () {});
|
|
188
286
|
}
|
|
189
287
|
return response;
|
|
190
288
|
});
|
|
@@ -194,8 +292,12 @@ function pageResponse(request) {
|
|
|
194
292
|
if (hit) return hit;
|
|
195
293
|
// Slower than the timeout but still coming: wait for it rather than fail.
|
|
196
294
|
return network.catch(function () {
|
|
197
|
-
|
|
198
|
-
return
|
|
295
|
+
var route = dynamic ? cache.match(routeKey(dynamic.route, fragment)) : Promise.resolve(null);
|
|
296
|
+
return route.then(function (kept) {
|
|
297
|
+
if (kept) return withParams(kept, dynamic.params);
|
|
298
|
+
if (!S.fallback || fragment) return Response.error();
|
|
299
|
+
return cache.match(variantUrl(S.fallback, false)).then(function (fallback) { return fallback ? markFallback(fallback) : Response.error(); });
|
|
300
|
+
});
|
|
199
301
|
});
|
|
200
302
|
});
|
|
201
303
|
});
|
package/dist/process.d.ts
CHANGED
|
@@ -10,7 +10,4 @@ import type { StxOptions } from './types';
|
|
|
10
10
|
export { injectRouterScript } from './runtime-injection';
|
|
11
11
|
export { processJsonDirective, processOnceDirective } from './misc-directives';
|
|
12
12
|
export { validateClientScript } from './script-validation';
|
|
13
|
-
/**
|
|
14
|
-
* Process all template directives with enhanced error handling and performance monitoring
|
|
15
|
-
*/
|
|
16
13
|
export declare function processDirectives(template: string, context: Record<string, any>, filePath: string, options: StxOptions, dependencies: Set<string>): Promise<string>;
|
package/dist/process.js
CHANGED
|
@@ -49,7 +49,7 @@ import { serverDataScope, serverDataTag } from "./server-data.js";
|
|
|
49
49
|
import { prepareRuntimeConfig } from "./runtime-config-loader.js";
|
|
50
50
|
import { injectRuntimeConfig } from "./runtime-config-server.js";
|
|
51
51
|
import { applyHtmlAttrs, cloakStyleFragment, ensureDocumentShell, hasDocumentShell, injectConfigHeadTags, mergeHtmlAttrs, metaDedupKey, startsDocument } from "./document-shell.js";
|
|
52
|
-
import { hasSignalsSyntax, convertSignalDirectivesToAttributes, convertSignalLoopsToAttributes, preEvalLiteralReactiveIfs, processSignals } from "./signal-processing.js";
|
|
52
|
+
import { hasSignalsSyntax, convertSignalDirectivesToAttributes, convertSignalLoopsToAttributes, convertServerLoopAttributesToDirectives, preEvalLiteralReactiveIfs, processSignals } from "./signal-processing.js";
|
|
53
53
|
import { processComponents } from "./component-renderer.js";
|
|
54
54
|
import { processInlineAssets } from "./inline-assets.js";
|
|
55
55
|
import { addCloakToConditionalDirectives, addCloakToUnresolvedExpressions, processJsonDirective, processMemoDirective, processOnceDirective, processRefAttributes } from "./misc-directives.js";
|
|
@@ -257,6 +257,13 @@ function placeSignalsRuntimeBeforeScripts(html, afterRuntime = "") {
|
|
|
257
257
|
return withoutRuntime.slice(0, insertionPoint) + runtimeTag + afterRuntime + `
|
|
258
258
|
` + withoutRuntime.slice(insertionPoint);
|
|
259
259
|
}
|
|
260
|
+
function restoreEscapedMustaches(html) {
|
|
261
|
+
const PAIR = /\x00STX_ESC_MUSTACHE_OPEN\x00([\s\S]*?)\x00STX_ESC_MUSTACHE_CLOSE\x00/g;
|
|
262
|
+
return html.replace(PAIR, (_match, content, offset) => {
|
|
263
|
+
const before = html.slice(0, offset);
|
|
264
|
+
return before.lastIndexOf("<") > before.lastIndexOf(">") ? `{{${content}}}` : `{<!--stx-literal-->{${content}}}`;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
260
267
|
export async function processDirectives(template, context, filePath, options, dependencies) {
|
|
261
268
|
if (options.ssr === !1 && !options.autoShell && options.buildMode === "spa")
|
|
262
269
|
return template;
|
|
@@ -380,6 +387,7 @@ ${tag}`).join("");
|
|
|
380
387
|
else if (isTopLevel)
|
|
381
388
|
result = dedupeScopedStyles(result);
|
|
382
389
|
result = result.replace(/\x00STX_ESCAPED_AT\x00/g, "@");
|
|
390
|
+
result = restoreEscapedMustaches(result);
|
|
383
391
|
if (isTopLevel && context.__stx_runtime_config)
|
|
384
392
|
result = injectRuntimeConfig(result, context.__stx_runtime_config);
|
|
385
393
|
if (isTopLevel && !context.__stx_defer_server_data) {
|
|
@@ -419,10 +427,10 @@ async function processDirectivesInternal(template, context, filePath, options, d
|
|
|
419
427
|
output = output.replace(/\{\{--[\s\S]*?--\}\}/g, "");
|
|
420
428
|
const masked = maskAtElementPosition(output, matchHtmlComment, (_token, index) => `\x00STX_HTML_COMMENT_${index}\x00`);
|
|
421
429
|
output = masked.output;
|
|
422
|
-
const htmlComments = masked.tokens, unmaskHtmlComments = (s) => htmlComments.length === 0 ? s : s.replace(/\x00STX_HTML_COMMENT_(\d+)\x00/g, (_, i) => htmlComments[Number(i)] ?? ""), ESCAPED_AT_PLACEHOLDER = "\x00STX_ESCAPED_AT\x00";
|
|
430
|
+
const htmlComments = masked.tokens, unmaskHtmlComments = (s) => htmlComments.length === 0 ? s : s.replace(/\x00STX_HTML_COMMENT_(\d+)\x00/g, (_, i) => htmlComments[Number(i)] ?? ""), ESCAPED_AT_PLACEHOLDER = "\x00STX_ESCAPED_AT\x00", ESCAPED_MUSTACHE_OPEN = "\x00STX_ESC_MUSTACHE_OPEN\x00", ESCAPED_MUSTACHE_CLOSE = "\x00STX_ESC_MUSTACHE_CLOSE\x00";
|
|
423
431
|
output = output.replace(/@@/g, ESCAPED_AT_PLACEHOLDER);
|
|
424
432
|
output = output.replace(/@\{\{([\s\S]*?)\}\}/g, (_, content) => {
|
|
425
|
-
return
|
|
433
|
+
return `${ESCAPED_MUSTACHE_OPEN}${content}${ESCAPED_MUSTACHE_CLOSE}`;
|
|
426
434
|
});
|
|
427
435
|
output = processVueTemplate(output);
|
|
428
436
|
output = await processInlineAssets(output, filePath, dependencies);
|
|
@@ -720,6 +728,7 @@ async function processOtherDirectives(template, context, filePath, options, depe
|
|
|
720
728
|
if (usesSignalsInScript(output)) {
|
|
721
729
|
output = convertSignalDirectivesToAttributes(output, context);
|
|
722
730
|
output = convertSignalLoopsToAttributes(output, context);
|
|
731
|
+
output = convertServerLoopAttributesToDirectives(output, context);
|
|
723
732
|
}
|
|
724
733
|
output = preEvalLiteralReactiveIfs(output);
|
|
725
734
|
const { processStreamDirectives } = await importOnce("stx/streaming", () => import("./streaming.js"));
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Jk as wq,Kk as dq,Lk as Cq,Mk as mq,Nk as gq}from"./chunk-fj6fbqgb.js";import{$k as Mq,Ok as S,Pk as Tq,Qk as _q,Rk as z,Sk as D,Tk as P,Uk as kq,Vk as vq,Wk as w,Xk as Iq,Yk as d,Zk as Hq,_k as Oq}from"./chunk-
|
|
3
|
-
Icon generation requires the sharp package for image processing.`),q.success=!1,q}let R=await y.default(Y).metadata();if(R.width&&R.width<512)q.warnings.push(`Source icon is ${R.width}x${R.height}. Recommend using at least 512x512 for best quality.`);for(let $ of X){let x=L.join(Q,`icon-${$}x${$}.png`);if(await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x),j){let F=L.join(Q,`icon-${$}x${$}.webp`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(F),q.generatedFiles.push(F)}}if(J){for(let x of v){let F=L.join(Q,`apple-touch-icon-${x}x${x}.png`);await y.default(Y).resize(x,x,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(F),q.generatedFiles.push(F)}let $=L.join(Q,"apple-touch-icon.png");await y.default(Y).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile($),q.generatedFiles.push($)}for(let $ of I){let x=L.join(Q,`favicon-${$}x${$}.png`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x)}let U=512,T=L.join(Q,`icon-maskable-${U}x${U}.png`),Z=Math.floor(U*0.1),_=U-Z*2;await y.default(Y).resize(_,_,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:Z,bottom:Z,left:Z,right:Z,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(T),q.generatedFiles.push(T)}catch(y){let V=y instanceof Error?y.message:String(y);q.errors.push(`Icon generation failed: ${V}`),q.success=!1}return q}function n(G){let B=G.sizes||k,q=G.outputDir?`/${G.outputDir}`:"/pwa-icons",K=G.generateWebP??!0,Y=G.generateAppleIcons??!0,Q=[];for(let X of B)if(Q.push(`${q}/icon-${X}x${X}.png`),K)Q.push(`${q}/icon-${X}x${X}.webp`);if(Y){Q.push(`${q}/apple-touch-icon.png`);for(let X of v)Q.push(`${q}/apple-touch-icon-${X}x${X}.png`)}for(let X of I)Q.push(`${q}/favicon-${X}x${X}.png`);return Q.push(`${q}/icon-maskable-512x512.png`),Q}async function O(){try{return await import("sharp"),!0}catch{return!1}}function m(G,B,q,K){let Y=[],Q=K.join(" ");for(let X of G)if(Y.push({src:`${B}/icon-${X}x${X}.png`,sizes:`${X}x${X}`,type:"image/png",purpose:Q}),q)Y.push({src:`${B}/icon-${X}x${X}.webp`,sizes:`${X}x${X}`,type:"image/webp",purpose:Q});return Y}function g(G){return G.map((B)=>({name:B.name,short_name:B.shortName,description:B.description,url:B.url,icons:B.icons?.map((q)=>({src:q.src,sizes:q.sizes,type:q.type}))}))}function h(G){let B=G.pwa?.shareTarget;if(!B?.enabled)return;let q={action:B.action||"/share",method:B.method||"POST",enctype:B.enctype||"multipart/form-data",params:{title:B.params?.title||"title",text:B.params?.text||"text",url:B.params?.url||"url"}};if(B.acceptFiles&&B.acceptFiles.length>0)q.params.files=B.acceptFiles.map((K)=>({name:K.name,accept:K.accept}));return q}function c(G){let B=G.pwa?.fileHandlers;if(!B?.enabled||!B.accept)return;let q=[{action:B.action||"/",accept:B.accept,launch_type:B.launchType||"single-client"}];if(B.icons)q[0].icons=B.icons.map((K)=>({src:K.src,sizes:K.sizes,type:K.type}));return q}function l(G){let B=G.pwa?.protocolHandlers;if(!B||B.length===0)return;return B.map((q)=>({protocol:q.protocol,url:q.url}))}function u(G){let B=G.pwa;if(!B?.enabled||!B.manifest)return null;let{manifest:q,icons:K}=B,Y=K?.sizes||[72,96,128,144,152,192,384,512],Q=K?.outputDir?`/${K.outputDir}`:"/pwa-icons",X=K?.generateWebP??!0,j=K?.purpose||["any","maskable"],J={name:q.name,short_name:q.shortName||q.name,description:q.description,start_url:q.startUrl||"/",display:q.display||"standalone",display_override:q.displayOverride,orientation:q.orientation,theme_color:q.themeColor,background_color:q.backgroundColor,scope:q.scope||"/",lang:q.lang,dir:q.dir,id:q.id,categories:q.categories,icons:m(Y,Q,X,j)};if(q.shortcuts&&q.shortcuts.length>0)J.shortcuts=g(q.shortcuts);if(q.screenshots&&q.screenshots.length>0)J.screenshots=q.screenshots.map((U)=>({src:U.src,sizes:U.sizes,type:U.type,label:U.label,form_factor:U.platform}));let y=h(G);if(y)J.share_target=y;let V=c(G);if(V)J.file_handlers=V;let R=l(G);if(R)J.protocol_handlers=R;if(q.launchHandler)J.launch_handler={client_mode:q.launchHandler};if(q.handleLinks)J.handle_links=q.handleLinks;if(q.edgeSidePanel?.enabled)J.edge_side_panel={preferred_width:q.edgeSidePanel.preferredWidth};return J}function M(G){let B=u(G);if(!B)return"";let q=JSON.parse(JSON.stringify(B));return JSON.stringify(q,null,2)}function i(G,B){return{...B,...G,shortcuts:G.shortcuts||B.shortcuts,screenshots:G.screenshots||B.screenshots,categories:G.categories||B.categories}}function s(G){let B=[],q=G.pwa;if(!q?.enabled)return B;let K=q.manifest;if(!K)return B.push("PWA manifest configuration is missing"),B;if(!K.name)B.push("Manifest name is required");let Y=["fullscreen","standalone","minimal-ui","browser"];if(K.display&&!Y.includes(K.display))B.push(`Invalid display mode: ${K.display}. Must be one of: ${Y.join(", ")}`);let Q=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(K.orientation&&!Q.includes(K.orientation))B.push(`Invalid orientation: ${K.orientation}`);let X=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(K.themeColor&&!X.test(K.themeColor))B.push(`Invalid theme color: ${K.themeColor}. Must be a valid hex color.`);if(K.backgroundColor&&!X.test(K.backgroundColor))B.push(`Invalid background color: ${K.backgroundColor}. Must be a valid hex color.`);if(q.shareTarget?.enabled){if(!q.shareTarget.action)B.push("Share target action URL is required")}if(q.fileHandlers?.enabled){if(!q.fileHandlers.accept||Object.keys(q.fileHandlers.accept).length===0)B.push("File handlers must specify accepted MIME types")}if(q.protocolHandlers)for(let j of q.protocolHandlers){if(!j.protocol)B.push("Protocol handler missing protocol");if(!j.url||!j.url.includes("%s"))B.push(`Protocol handler URL must contain %s placeholder: ${j.protocol}`)}return B}import A from"path";async function b(G){let B=G.pwa?.offline;if(!B?.enabled)return"";if(B.page){let q=A.isAbsolute(B.page)?B.page:A.resolve(process.cwd(),B.page);if(await Bun.file(q).exists())try{let{processDirectives:K}=await import("./chunk-
|
|
2
|
+
import{Jk as wq,Kk as dq,Lk as Cq,Mk as mq,Nk as gq}from"./chunk-fj6fbqgb.js";import{$k as Mq,Ok as S,Pk as Tq,Qk as _q,Rk as z,Sk as D,Tk as P,Uk as kq,Vk as vq,Wk as w,Xk as Iq,Yk as d,Zk as Hq,_k as Oq}from"./chunk-e5aqq9ms.js";import{Pw as Aq,Qw as bq,Rw as Sq,Sw as zq,Tw as Dq,Uw as Pq}from"./chunk-4yc9gx6h.js";import"./chunk-d6rkgay9.js";import{ax as N}from"./chunk-cevkpyn9.js";import p from"fs";import E from"path";import C from"fs";import L from"path";var k=[72,96,128,144,152,192,384,512],v=[120,152,167,180],I=[16,32];async function H(G,B){let q={success:!0,generatedFiles:[],errors:[],warnings:[]},K=G.pwa?.icons;if(!K?.src)return q.errors.push("No source icon specified in pwa.icons.src"),q.success=!1,q;let Y=L.isAbsolute(K.src)?K.src:L.resolve(process.cwd(),K.src);if(!await Bun.file(Y).exists())return q.errors.push(`Source icon not found: ${Y}`),q.success=!1,q;let Q=L.resolve(B,K.outputDir||"pwa-icons");try{C.mkdirSync(Q,{recursive:!0})}catch{return q.errors.push(`Failed to create output directory: ${Q}`),q.success=!1,q}let X=K.sizes||k,j=K.generateWebP??!0,J=K.generateAppleIcons??!0;try{let y;try{y=await import("sharp")}catch{return q.errors.push(`sharp is not installed. Install it with: bun add sharp
|
|
3
|
+
Icon generation requires the sharp package for image processing.`),q.success=!1,q}let R=await y.default(Y).metadata();if(R.width&&R.width<512)q.warnings.push(`Source icon is ${R.width}x${R.height}. Recommend using at least 512x512 for best quality.`);for(let $ of X){let x=L.join(Q,`icon-${$}x${$}.png`);if(await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x),j){let F=L.join(Q,`icon-${$}x${$}.webp`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(F),q.generatedFiles.push(F)}}if(J){for(let x of v){let F=L.join(Q,`apple-touch-icon-${x}x${x}.png`);await y.default(Y).resize(x,x,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(F),q.generatedFiles.push(F)}let $=L.join(Q,"apple-touch-icon.png");await y.default(Y).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile($),q.generatedFiles.push($)}for(let $ of I){let x=L.join(Q,`favicon-${$}x${$}.png`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x)}let U=512,T=L.join(Q,`icon-maskable-${U}x${U}.png`),Z=Math.floor(U*0.1),_=U-Z*2;await y.default(Y).resize(_,_,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:Z,bottom:Z,left:Z,right:Z,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(T),q.generatedFiles.push(T)}catch(y){let V=y instanceof Error?y.message:String(y);q.errors.push(`Icon generation failed: ${V}`),q.success=!1}return q}function n(G){let B=G.sizes||k,q=G.outputDir?`/${G.outputDir}`:"/pwa-icons",K=G.generateWebP??!0,Y=G.generateAppleIcons??!0,Q=[];for(let X of B)if(Q.push(`${q}/icon-${X}x${X}.png`),K)Q.push(`${q}/icon-${X}x${X}.webp`);if(Y){Q.push(`${q}/apple-touch-icon.png`);for(let X of v)Q.push(`${q}/apple-touch-icon-${X}x${X}.png`)}for(let X of I)Q.push(`${q}/favicon-${X}x${X}.png`);return Q.push(`${q}/icon-maskable-512x512.png`),Q}async function O(){try{return await import("sharp"),!0}catch{return!1}}function m(G,B,q,K){let Y=[],Q=K.join(" ");for(let X of G)if(Y.push({src:`${B}/icon-${X}x${X}.png`,sizes:`${X}x${X}`,type:"image/png",purpose:Q}),q)Y.push({src:`${B}/icon-${X}x${X}.webp`,sizes:`${X}x${X}`,type:"image/webp",purpose:Q});return Y}function g(G){return G.map((B)=>({name:B.name,short_name:B.shortName,description:B.description,url:B.url,icons:B.icons?.map((q)=>({src:q.src,sizes:q.sizes,type:q.type}))}))}function h(G){let B=G.pwa?.shareTarget;if(!B?.enabled)return;let q={action:B.action||"/share",method:B.method||"POST",enctype:B.enctype||"multipart/form-data",params:{title:B.params?.title||"title",text:B.params?.text||"text",url:B.params?.url||"url"}};if(B.acceptFiles&&B.acceptFiles.length>0)q.params.files=B.acceptFiles.map((K)=>({name:K.name,accept:K.accept}));return q}function c(G){let B=G.pwa?.fileHandlers;if(!B?.enabled||!B.accept)return;let q=[{action:B.action||"/",accept:B.accept,launch_type:B.launchType||"single-client"}];if(B.icons)q[0].icons=B.icons.map((K)=>({src:K.src,sizes:K.sizes,type:K.type}));return q}function l(G){let B=G.pwa?.protocolHandlers;if(!B||B.length===0)return;return B.map((q)=>({protocol:q.protocol,url:q.url}))}function u(G){let B=G.pwa;if(!B?.enabled||!B.manifest)return null;let{manifest:q,icons:K}=B,Y=K?.sizes||[72,96,128,144,152,192,384,512],Q=K?.outputDir?`/${K.outputDir}`:"/pwa-icons",X=K?.generateWebP??!0,j=K?.purpose||["any","maskable"],J={name:q.name,short_name:q.shortName||q.name,description:q.description,start_url:q.startUrl||"/",display:q.display||"standalone",display_override:q.displayOverride,orientation:q.orientation,theme_color:q.themeColor,background_color:q.backgroundColor,scope:q.scope||"/",lang:q.lang,dir:q.dir,id:q.id,categories:q.categories,icons:m(Y,Q,X,j)};if(q.shortcuts&&q.shortcuts.length>0)J.shortcuts=g(q.shortcuts);if(q.screenshots&&q.screenshots.length>0)J.screenshots=q.screenshots.map((U)=>({src:U.src,sizes:U.sizes,type:U.type,label:U.label,form_factor:U.platform}));let y=h(G);if(y)J.share_target=y;let V=c(G);if(V)J.file_handlers=V;let R=l(G);if(R)J.protocol_handlers=R;if(q.launchHandler)J.launch_handler={client_mode:q.launchHandler};if(q.handleLinks)J.handle_links=q.handleLinks;if(q.edgeSidePanel?.enabled)J.edge_side_panel={preferred_width:q.edgeSidePanel.preferredWidth};return J}function M(G){let B=u(G);if(!B)return"";let q=JSON.parse(JSON.stringify(B));return JSON.stringify(q,null,2)}function i(G,B){return{...B,...G,shortcuts:G.shortcuts||B.shortcuts,screenshots:G.screenshots||B.screenshots,categories:G.categories||B.categories}}function s(G){let B=[],q=G.pwa;if(!q?.enabled)return B;let K=q.manifest;if(!K)return B.push("PWA manifest configuration is missing"),B;if(!K.name)B.push("Manifest name is required");let Y=["fullscreen","standalone","minimal-ui","browser"];if(K.display&&!Y.includes(K.display))B.push(`Invalid display mode: ${K.display}. Must be one of: ${Y.join(", ")}`);let Q=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(K.orientation&&!Q.includes(K.orientation))B.push(`Invalid orientation: ${K.orientation}`);let X=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(K.themeColor&&!X.test(K.themeColor))B.push(`Invalid theme color: ${K.themeColor}. Must be a valid hex color.`);if(K.backgroundColor&&!X.test(K.backgroundColor))B.push(`Invalid background color: ${K.backgroundColor}. Must be a valid hex color.`);if(q.shareTarget?.enabled){if(!q.shareTarget.action)B.push("Share target action URL is required")}if(q.fileHandlers?.enabled){if(!q.fileHandlers.accept||Object.keys(q.fileHandlers.accept).length===0)B.push("File handlers must specify accepted MIME types")}if(q.protocolHandlers)for(let j of q.protocolHandlers){if(!j.protocol)B.push("Protocol handler missing protocol");if(!j.url||!j.url.includes("%s"))B.push(`Protocol handler URL must contain %s placeholder: ${j.protocol}`)}return B}import A from"path";async function b(G){let B=G.pwa?.offline;if(!B?.enabled)return"";if(B.page){let q=A.isAbsolute(B.page)?B.page:A.resolve(process.cwd(),B.page);if(await Bun.file(q).exists())try{let{processDirectives:K}=await import("./chunk-8v4jamr6.js"),Y=await Bun.file(q).text();return await K(Y,{},q,G,new Set)}catch(K){console.warn(`[PWA] Failed to process custom offline page: ${K}`)}else console.warn(`[PWA] Custom offline page not found: ${q}`)}return f(G)}function f(G){let B=G.pwa?.offline,q=G.pwa?.manifest,K=B?.fallbackTitle||"You are offline",Y=B?.fallbackMessage||"Please check your internet connection and try again.",Q=q?.themeColor||"#4f46e5",X=q?.shortName||q?.name||"App";return`<!DOCTYPE html>
|
|
4
4
|
<html lang="en">
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="UTF-8">
|
|
@@ -145,18 +145,36 @@ export declare function convertSignalDirectivesToAttributes(template: string, co
|
|
|
145
145
|
*/
|
|
146
146
|
export declare function preEvalLiteralReactiveIfs(template: string): string;
|
|
147
147
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
148
|
+
* A `:for` over `<script server>` data becomes a server loop (stacksjs/stx#2051).
|
|
149
|
+
*
|
|
150
|
+
* `convertSignalLoopsToAttributes` below already makes this decision in the
|
|
151
|
+
* other direction: an `@foreach` whose iterable is server data is left for
|
|
152
|
+
* `processLoops`, and one whose iterable is a signal becomes a client `:for`.
|
|
153
|
+
* The missing half was an author writing `:for` directly over a server name.
|
|
154
|
+
* That is expanded on the client, against a scope the client script declares,
|
|
155
|
+
* where a `<script server>` const has never existed — so the list rendered
|
|
156
|
+
* **zero rows**, with one console warning and no other signal.
|
|
157
|
+
*
|
|
158
|
+
* It cost a real app its architecture. It iterated monitors fetched in a
|
|
159
|
+
* server block, read a warning that guessed at signals, concluded the whole
|
|
160
|
+
* `:for` pattern was unreliable, and was rebuilt on hand-written
|
|
161
|
+
* `getElementById` wiring.
|
|
162
|
+
*
|
|
163
|
+
* Deliberately narrow. Only an iterable whose ROOT identifier is a server
|
|
164
|
+
* context key is converted, because that is the case that cannot work any
|
|
165
|
+
* other way:
|
|
166
|
+
*
|
|
167
|
+
* - A literal (`:for="n in [1,2,3]"`) already works on the client. Converting
|
|
168
|
+
* it would move working markup to the server for no gain.
|
|
169
|
+
* - A declared signal stays on the client even when the context happens to
|
|
170
|
+
* carry the same name, since the signal is what the author is iterating.
|
|
171
|
+
* - A name in neither is left alone, so a typo still reaches the runtime
|
|
172
|
+
* warning that now names the cause.
|
|
173
|
+
*
|
|
174
|
+
* `<template>` is unwrapped rather than emitted, since a server loop repeats
|
|
175
|
+
* real markup and a template element renders nothing.
|
|
159
176
|
*/
|
|
177
|
+
export declare function convertServerLoopAttributesToDirectives(template: string, context?: Record<string, any>): string;
|
|
160
178
|
export declare function convertSignalLoopsToAttributes(template: string, context?: Record<string, any>): string;
|
|
161
179
|
export declare function processScriptSetup(template: string, filePath?: string, serverData?: Record<string, unknown>): Promise<{
|
|
162
180
|
output: string;
|
|
@@ -489,6 +489,46 @@ export function preEvalLiteralReactiveIfs(template) {
|
|
|
489
489
|
}
|
|
490
490
|
return output;
|
|
491
491
|
}
|
|
492
|
+
const LOOP_ATTRS = [":for", "@for", "x-for"];
|
|
493
|
+
export function convertServerLoopAttributesToDirectives(template, context) {
|
|
494
|
+
if (!context || Object.keys(context).length === 0)
|
|
495
|
+
return template;
|
|
496
|
+
if (!LOOP_ATTRS.some((attr) => template.includes(`${attr}=`)))
|
|
497
|
+
return template;
|
|
498
|
+
const signalNames = extractClientSignalNames(template);
|
|
499
|
+
let output = template;
|
|
500
|
+
const replacements = [], tagRe = /<([a-zA-Z][\w-]*)((?:[^>"']|"[^"]*"|'[^']*')*)>/g;
|
|
501
|
+
let match;
|
|
502
|
+
while ((match = tagRe.exec(output)) !== null) {
|
|
503
|
+
const [openTag, tag, rawAttrs] = match, startIdx = match.index, startTagEnd = startIdx + openTag.length, attrMatch = LOOP_ATTRS.map((attr) => ({ attr, m: new RegExp(`\\s${attr}="([^"]*)"`).exec(rawAttrs) })).find((entry) => entry.m !== null);
|
|
504
|
+
if (!attrMatch || !attrMatch.m)
|
|
505
|
+
continue;
|
|
506
|
+
const parsed = parseLoopExpression(attrMatch.m[1]);
|
|
507
|
+
if (!parsed.iterable || !parsed.itemVar)
|
|
508
|
+
continue;
|
|
509
|
+
const rootVar = parsed.iterable.trim().split(/[.[(]/)[0].trim();
|
|
510
|
+
if (!rootVar || signalNames.has(rootVar) || !(rootVar in context))
|
|
511
|
+
continue;
|
|
512
|
+
const end = findElementEnd(output, startIdx, tag, startTagEnd);
|
|
513
|
+
if (end === -1)
|
|
514
|
+
continue;
|
|
515
|
+
const cleanedAttrs = rawAttrs.replace(new RegExp(`\\s${attrMatch.attr}="[^"]*"`), "").replace(/\s:key="[^"]*"/, "").replace(/\sx-cloak(?=\s|$)/, ""), inner = output.slice(startTagEnd, end - `</${tag}>`.length), nestedContext = { ...context, [parsed.itemVar]: void 0 };
|
|
516
|
+
if (parsed.indexVar)
|
|
517
|
+
nestedContext[parsed.indexVar] = void 0;
|
|
518
|
+
const body = convertServerLoopAttributesToDirectives(inner, nestedContext), binding = parsed.indexVar ? `${parsed.iterable} as ${parsed.indexVar} => ${parsed.itemVar}` : `${parsed.iterable} as ${parsed.itemVar}`, repeated = tag.toLowerCase() === "template" ? body : `<${tag}${cleanedAttrs}>${body}</${tag}>`;
|
|
519
|
+
replacements.push({
|
|
520
|
+
start: startIdx,
|
|
521
|
+
end,
|
|
522
|
+
replacement: `@foreach(${binding})${repeated}@endforeach`
|
|
523
|
+
});
|
|
524
|
+
tagRe.lastIndex = end;
|
|
525
|
+
}
|
|
526
|
+
for (let i = replacements.length - 1;i >= 0; i--) {
|
|
527
|
+
const { start, end, replacement } = replacements[i];
|
|
528
|
+
output = output.slice(0, start) + replacement + output.slice(end);
|
|
529
|
+
}
|
|
530
|
+
return output;
|
|
531
|
+
}
|
|
492
532
|
export function convertSignalLoopsToAttributes(template, context) {
|
|
493
533
|
let output = template;
|
|
494
534
|
const forDirectiveStart = /@(for|foreach)\s*\(/g;
|
package/dist/signals.js
CHANGED
|
@@ -4498,19 +4498,51 @@ catch (e) {
|
|
|
4498
4498
|
// _isStxStore marker). Only fires on the warn path, which is
|
|
4499
4499
|
// rare, so the extra Object.keys / spread cost is negligible.
|
|
4500
4500
|
var diagScope;
|
|
4501
|
+
var rootName = '?';
|
|
4502
|
+
var rootInScope = true;
|
|
4503
|
+
var rootVal;
|
|
4501
4504
|
try {
|
|
4502
4505
|
var diagMerged = { ...globalHelpers, ...passedScope, ...(capturedScope || {}) };
|
|
4503
4506
|
var firstIdent = listExpr.match(/^[A-Za-z_$][\\w$]*/);
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
+
rootName = firstIdent ? firstIdent[0] : '?';
|
|
4508
|
+
rootInScope = Object.prototype.hasOwnProperty.call(diagMerged, rootName);
|
|
4509
|
+
rootVal = rootInScope ? diagMerged[rootName] : '<NOT-IN-SCOPE>';
|
|
4507
4510
|
var rootKeys = (rootVal && typeof rootVal === 'object')
|
|
4508
4511
|
? Object.keys(rootVal).slice(0, 8).join(',')
|
|
4509
4512
|
: '-';
|
|
4510
4513
|
diagScope = '[root=' + rootName + ' inScope=' + rootInScope + ' type=' + (typeof rootVal) + ' isStxStore=' + !!(rootVal && rootVal._isStxStore) + ' keys=' + rootKeys + ']';
|
|
4511
4514
|
}
|
|
4512
|
-
catch (_e) { diagScope = '[diag-error]'; }
|
|
4513
|
-
|
|
4515
|
+
catch (_e) { diagScope = '[diag-error]'; rootInScope = true; }
|
|
4516
|
+
|
|
4517
|
+
/*
|
|
4518
|
+
* Name the cause rather than guessing at it (stacksjs/stx#2051).
|
|
4519
|
+
*
|
|
4520
|
+
* This used to end with "If this is a signal call, try the bare
|
|
4521
|
+
* reference" every single time. In the most common failure the
|
|
4522
|
+
* identifier is not a signal at all -- it is a bare name the client
|
|
4523
|
+
* scope has never heard of, usually a declaration from a
|
|
4524
|
+
* script-server block, which :for cannot see because it is expanded
|
|
4525
|
+
* on the client. The hint sent people to the wrong layer: one app
|
|
4526
|
+
* read it, concluded the signals-and-:for pattern was unreliable, and
|
|
4527
|
+
* was rebuilt on hand-written getElementById wiring.
|
|
4528
|
+
*
|
|
4529
|
+
* The scope dump already answered the question -- inScope=false was
|
|
4530
|
+
* right there, ahead of the guess -- so lead with it, and keep the
|
|
4531
|
+
* signal advice for when the value really is a signal, which is the
|
|
4532
|
+
* one case where it applies.
|
|
4533
|
+
*/
|
|
4534
|
+
var advice;
|
|
4535
|
+
if (!rootInScope) {
|
|
4536
|
+
advice = 'Nothing named ' + rootName + ' is in the client scope. A script-server declaration is not available here: :for is expanded on the client. '
|
|
4537
|
+
+ 'Either wrap it in state() inside a script-client block, or iterate it with the server-side @foreach(' + rootName + ' as item).';
|
|
4538
|
+
}
|
|
4539
|
+
else if (typeof rootVal === 'function' && (rootVal._isSignal || rootVal._isDerived)) {
|
|
4540
|
+
advice = rootName + ' is a signal, so try the bare reference: ' + rootName + ' instead of ' + rootName + '().';
|
|
4541
|
+
}
|
|
4542
|
+
else {
|
|
4543
|
+
advice = rootName + ' resolved to a ' + (typeof rootVal) + ', not an array.';
|
|
4544
|
+
}
|
|
4545
|
+
console.warn('[STX] :for expected an array; got ' + (list === '' ? 'empty/error' : typeof list) + ' for expression "' + listExpr + '". ' + diagScope + ' ' + advice);
|
|
4514
4546
|
return;
|
|
4515
4547
|
}
|
|
4516
4548
|
|
package/dist/ssg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Ak as Uq,Bk as Iq,Fk as wq}from"./chunk-
|
|
2
|
+
import{Ak as Uq,Bk as Iq,Fk as wq}from"./chunk-ht9rdkf3.js";import{Gk as Eq,Hk as Tq,Ik as Dq}from"./chunk-7eea1cse.js";import{bl as _q,el as zq,fl as Aq}from"./chunk-xnnyfxxv.js";import"./chunk-m2z8dygn.js";import"./chunk-2andsajh.js";import{Gr as n,Up as C,Xm as Oq,no as l,qo as Hq}from"./chunk-tte381m0.js";import"./chunk-y9f9g2kh.js";import"./chunk-ah8gs0q2.js";import"./chunk-saf4xhac.js";import"./chunk-wheh08v2.js";import"./chunk-jct6cs2k.js";import{wt as Xq}from"./chunk-tft187yn.js";import{Bt as d}from"./chunk-7vftjm43.js";import"./chunk-4azk3jdd.js";import"./chunk-ab9b859e.js";import"./chunk-mjearf0g.js";import{gu as Bq}from"./chunk-9rp8f7jz.js";import"./chunk-8ghwewek.js";import"./chunk-rk8p4b1z.js";import"./chunk-fpxz25xz.js";import"./chunk-nn42gs3q.js";import"./chunk-v54tq312.js";import{Cw as Yq,Dw as Vq,Ew as jq,Fw as Gq,Gw as Lq,Hw as Nq}from"./chunk-qbc0bebg.js";import"./chunk-4yc9gx6h.js";import"./chunk-d6rkgay9.js";import{ax as P}from"./chunk-cevkpyn9.js";import X from"fs";import j from"path";import{createHash as xq}from"crypto";function yq(q){try{return new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(q).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return q}}var Pq=/<script\s+type="stx\/island"\s+data-stx-island="([^"]+)"([^>]*)>([\s\S]*?)<\/script>/g;function Cq(q){return Bun.hash(q).toString(16)}function Qq(q,Z={}){if(!q.includes('type="stx/island"'))return{html:q,chunks:[]};let $=new Map,Q=q.replace(Pq,(J,W,_,z)=>{let L=z.trim();if(!L)return J;if(/\bdata-stx-src=/.test(_))return J;if(Z.minify)L=yq(L);let A=Cq(L);if(!$.has(A))$.set(A,L);let B=Z.integrity?` data-stx-integrity="sha384-${xq("sha384").update(L).digest("base64")}"`:"";return`<script type="stx/island" data-stx-island="${W}" data-stx-src="/_stx/islands/${A}.js"${B}${_}></script>`}),K=Array.from($,([J,W])=>({hash:J,code:W}));return{html:Q,chunks:K}}var gq=new Set(["visible","idle"]);function Zq(q){if(!q.includes("data-stx-src="))return q;let Z=new Map,$=/data-stx-scope="([^"]+)"[^>]*?stx-hydrate="([^"]+)"/g,Q;while((Q=$.exec(q))!==null)Z.set(Q[1],Q[2]);let K=new Set,J=/data-stx-island="([^"]+)"[^>]*?data-stx-src="([^"]+)"/g,W;while((W=J.exec(q))!==null)if(gq.has(Z.get(W[1])||""))K.add(W[2]);let _=q.lastIndexOf("</head>");if(K.size===0||_===-1)return q;let z=Array.from(K).filter((L)=>!q.includes(`rel="prefetch" href="${L}"`)).map((L)=>`<link rel="prefetch" href="${L}" as="script">`).join("");if(!z)return q;return q.slice(0,_)+z+q.slice(_)}var fq=["STX_SITE_URL","SITE_URL","URL","VERCEL_URL","CF_PAGES_URL"];function h(q){let Z=q.trim();if(!Z)return null;let $=/^https?:\/\//i.test(Z)?Z:`https://${Z}`;try{return new URL($).origin+new URL($).pathname.replace(/\/$/,"")}catch{return null}}function mq(q){for(let Z of fq){let $=q[Z];if(!$)continue;let Q=h($);if(Q)return{url:Q,source:"env",via:Z}}return null}function $q(q){if(!q||typeof q!=="object")return null;let Z=q,$=Z.site?.url??Z.url??Z.app?.url;return typeof $==="string"?h($):null}async function dq(q){let{existsSync:Z}=await import("fs"),$=await import("path");for(let Q of["site.config.ts","site.config.js",".config/site.config.ts"]){let K=$.resolve(q,Q);if(!Z(K))continue;try{let J=await import(K),W=$q(J.default??J);if(W)return W}catch{}}return null}async function Kq(q={}){let Z=q.cwd??process.cwd(),$=q.env??process.env;if(q.explicit){let W=h(q.explicit);if(W)return{url:W,source:"option"}}let Q=$q(q.stxConfig);if(Q)return{url:Q,source:"stx.config",via:"site.url"};let K=await dq(Z);if(K)return{url:K,source:"site.config",via:"url"};let J=mq($);if(J)return J;return{url:"http://localhost",source:"fallback"}}function Wq(){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 Fq{cacheDir;cache=new Map;loaded=!1;salt;constructor(q,Z=""){this.cacheDir=q,this.salt=Z}async load(){if(this.loaded)return;let q=j.join(this.cacheDir,"build-cache.json");if(await Bun.file(q).exists())try{let Z=JSON.parse(await Bun.file(q).text());for(let[$,Q]of Object.entries(Z))this.cache.set($,Q)}catch{}this.loaded=!0}async save(){await X.promises.mkdir(this.cacheDir,{recursive:!0});let q=j.join(this.cacheDir,"build-cache.json"),Z={};for(let[$,Q]of this.cache)Z[$]=Q;await Bun.write(q,JSON.stringify(Z))}getHash(q,Z){let $=X.statSync(q),Q=`${this.salt}|${q}:${$.mtimeMs}`;for(let J of Z)if(X.existsSync(J)){let W=X.statSync(J);Q+=`:${J}:${W.mtimeMs}`}let K=0;for(let J=0;J<Q.length;J++){let W=Q.charCodeAt(J);K=(K<<5)-K+W,K=K&K}return Math.abs(K).toString(36)}get(q,Z){let $=this.cache.get(q);if(!$)return null;let Q=this.getHash(Z,$.dependencies??[]);if($.hash!==Q)return this.cache.delete(q),null;return $.html}set(q,Z,$,Q){let K=this.getHash(Z,$);this.cache.set(q,{hash:K,html:Q,generatedAt:Date.now(),dependencies:$})}}class Rq{cacheDir;constructor(q){this.cacheDir=q}getFilePath(q){let Z=q.replace(/[^a-zA-Z0-9]/g,"_")+".json";return j.join(this.cacheDir,"isr",Z)}async get(q){let Z=this.getFilePath(q);if(!await Bun.file(Z).exists())return null;try{return JSON.parse(await Bun.file(Z).text())}catch{return null}}async set(q,Z){let $=this.getFilePath(q);await X.promises.mkdir(j.dirname($),{recursive:!0}),await Bun.write($,JSON.stringify(Z))}async invalidate(q){let Z=this.getFilePath(q);if(await Bun.file(Z).exists())await X.promises.unlink(Z)}async invalidatePattern(q){let Z=j.join(this.cacheDir,"isr");if(!X.existsSync(Z))return;let $=await X.promises.readdir(Z);for(let Q of $){let K=Q.replace(/_/g,"/").replace(".json","");if(q.test(K))await X.promises.unlink(j.join(Z,Q))}}async needsRevalidation(q){let Z=await this.get(q);if(!Z)return!0;return Date.now()>Z.revalidateAfter}}async function pq(q){try{let $=(await Bun.file(q).text()).match(/<script\s+server\b[^>]*>([\s\S]*?)<\/script>/i);if(!$)return null;let Q=$[1];if(!Q.includes("getStaticPaths"))return null;let K=Q.match(/(?:export\s+)?(?:async\s+)?function\s+getStaticPaths\s*\([^)]*\)\s*\{([\s\S]*?)\n[\t ]*\}/);if(!K)return null;return await Function(`
|
|
4
4
|
return (async function getStaticPaths() {
|
|
5
5
|
${K[1]}
|
|
@@ -41,7 +41,7 @@ ${q.map((Q)=>{let K=new URL(Q.loc,Z).href,J=` <url>
|
|
|
41
41
|
${$.join(`
|
|
42
42
|
`)}
|
|
43
43
|
</channel>
|
|
44
|
-
</rss>`}async function rq(q={}){let Z=Date.now();Aq();let $=await n(process.cwd()),Q=$.build||{},K=await Kq({explicit:q.domain||Q.domain,stxConfig:$});if(K.source==="fallback"&&(q.sitemap??Q.sitemap??!0))console.warn(Wq());let J={router:q.router??$?.router??{},pagesDir:q.pagesDir||Q.pagesDir||"pages",outputDir:q.outputDir||Q.outputDir||"dist",baseUrl:q.baseUrl||Q.baseUrl||"/",domain:K.url,revalidate:q.revalidate??Q.revalidate??!1,sitemap:q.sitemap??Q.sitemap??!0,sitemapExclude:q.sitemapExclude||Q.sitemapExclude||[],robots:q.robots??Q.robots??!0,rss:q.rss??Q.rss??!1,concurrency:q.concurrency||Q.concurrency||10,cache:q.cache??Q.cache??!0,cacheDir:q.cacheDir||Q.cacheDir||d(process.cwd(),"ssg-cache"),contentLoaders:q.contentLoaders||[],hooks:q.hooks||{},minify:q.minify??Q.minify??!0,generate404:q.generate404??Q.generate404??!0,publicDir:q.publicDir||Q.publicDir||"public",trailingSlash:q.trailingSlash??Q.trailingSlash??!1,cleanOutput:q.cleanOutput??Q.cleanOutput??!0,cacheSalt:q.cacheSalt??"",partialsDir:q.partialsDir||$?.partialsDir||"",componentsDir:q.componentsDir||$?.componentsDir||"",failOnIncludeError:q.failOnIncludeError??!0,failOnServerScriptError:q.failOnServerScriptError??!0,chunkIslands:q.chunkIslands===!0,prefetchIslands:q.prefetchIslands===!0,integrityIslands:q.integrityIslands===!0},W={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},_=new Set,z=0,L={},A={};await J.hooks.onBuildStart?.();try{if(J.cleanOutput&&X.existsSync(J.outputDir))await X.promises.rm(J.outputDir,{recursive:!0});await X.promises.mkdir(J.outputDir,{recursive:!0});let U=J.cacheSalt;if(!U){let{resolveUserCssConfig:Y,fingerprintConfig:N}=await import("./chunk-
|
|
44
|
+
</rss>`}async function rq(q={}){let Z=Date.now();Aq();let $=await n(process.cwd()),Q=$.build||{},K=await Kq({explicit:q.domain||Q.domain,stxConfig:$});if(K.source==="fallback"&&(q.sitemap??Q.sitemap??!0))console.warn(Wq());let J={router:q.router??$?.router??{},pagesDir:q.pagesDir||Q.pagesDir||"pages",outputDir:q.outputDir||Q.outputDir||"dist",baseUrl:q.baseUrl||Q.baseUrl||"/",domain:K.url,revalidate:q.revalidate??Q.revalidate??!1,sitemap:q.sitemap??Q.sitemap??!0,sitemapExclude:q.sitemapExclude||Q.sitemapExclude||[],robots:q.robots??Q.robots??!0,rss:q.rss??Q.rss??!1,concurrency:q.concurrency||Q.concurrency||10,cache:q.cache??Q.cache??!0,cacheDir:q.cacheDir||Q.cacheDir||d(process.cwd(),"ssg-cache"),contentLoaders:q.contentLoaders||[],hooks:q.hooks||{},minify:q.minify??Q.minify??!0,generate404:q.generate404??Q.generate404??!0,publicDir:q.publicDir||Q.publicDir||"public",trailingSlash:q.trailingSlash??Q.trailingSlash??!1,cleanOutput:q.cleanOutput??Q.cleanOutput??!0,cacheSalt:q.cacheSalt??"",partialsDir:q.partialsDir||$?.partialsDir||"",componentsDir:q.componentsDir||$?.componentsDir||"",failOnIncludeError:q.failOnIncludeError??!0,failOnServerScriptError:q.failOnServerScriptError??!0,chunkIslands:q.chunkIslands===!0,prefetchIslands:q.prefetchIslands===!0,integrityIslands:q.integrityIslands===!0},W={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},_=new Set,z=0,L={},A={};await J.hooks.onBuildStart?.();try{if(J.cleanOutput&&X.existsSync(J.outputDir))await X.promises.rm(J.outputDir,{recursive:!0});await X.promises.mkdir(J.outputDir,{recursive:!0});let U=J.cacheSalt;if(!U){let{resolveUserCssConfig:Y,fingerprintConfig:N}=await import("./chunk-65c929m6.js");try{U=N(await Y(process.cwd()))}catch{}}let{prepareImageDelivery:G}=await import("./chunk-av7a1sct.js"),H=await G(J.publicDir,J.outputDir);if(H.count>0)console.log(`Optimized ${H.count} image(s) for responsive delivery`),U=[U,H.fingerprint].filter(Boolean).join(":");let F=new Fq(J.cacheDir,U);if(J.cache)await F.load();try{let{generateCss:Y}=await import("./chunk-65c929m6.js");await Y('<div class="bg-black"></div>')}catch{}Yq();let kq=$?.routeMiddleware?.dir||"middleware";await jq(process.cwd(),kq);let p=Vq();if(p.length>0)console.log(`Loaded ${p.length} middleware: ${p.join(", ")}`);let bq=$?.routeMiddleware?.global||[];wq($?.layoutsDir,d(process.cwd()));let i=l(".",{pagesDir:J.pagesDir,pagesDirs:$?._layerPageDirs});console.log(`Found ${i.length} routes`);let g=[];for(let Y of i){let N=await uq(Y);for(let O of N)g.push({route:Y,url:O.url,params:O.params,props:O.props,revalidate:O.revalidate??J.revalidate})}W.totalPages=g.length,console.log(`Generating ${W.totalPages} pages...`);let S=[],s=[];for(let Y=0;Y<g.length;Y+=J.concurrency)s.push(g.slice(Y,Y+J.concurrency));for(let Y of s)await Promise.all(Y.map(async(N)=>{let{route:O,url:V,params:v,props:Sq,revalidate:r}=N;try{await J.hooks.onPageStart?.(V);let R=await Bun.file(O.filePath).text(),M=JJ(R),vq=M?.middleware?Array.isArray(M.middleware)?M.middleware:[M.middleware]:[],t=[...bq,...vq];if(t.length>0){let T=Gq(V,v,M||{}),k=Lq(T,null,void 0,{isServer:!0}),D=await Nq(t,k);if(D.redirect){let I=typeof D.redirect==="string"?D.redirect:D.redirect.path||D.redirect,y=QJ(String(I),V),b=ZJ(V,J);await X.promises.mkdir(j.dirname(b),{recursive:!0}),await Bun.write(b,y),W.successCount++,W.pages.push({route:V,outputPath:b,size:Buffer.byteLength(y),cached:!1}),S.push({loc:V,lastmod:new Date().toISOString()}),console.log(` \u21B3 ${V} \u2192 redirect to ${I}`);return}if(D.abort){let I=typeof D.abort==="string"?D.abort:D.abort?.error?.message||"aborted";console.warn(` \u21B3 ${V} \u2014 middleware aborted: ${I}`);return}}let e=R.match(/definePageMeta\s*\(\s*\{[\s\S]*?validate\s*:\s*((?:\([^)]*\)|[^,}])*(?:\{[\s\S]*?\})?)/m);if(e)try{if(!await Function("route",`
|
|
45
45
|
const validate = ${e[1]};
|
|
46
46
|
return validate(route);
|
|
47
47
|
`)({params:v})){console.warn(`Validation failed for ${V}, skipping...`);return}}catch{}let E=null,qq=!1;if(J.cache){if(E=F.get(V,O.filePath),E)qq=!0,W.cachedCount++}if(!E){let T=await Mq(O,v,Sq,J,$);if(E=T.html,J.failOnIncludeError&&T.includeFailures.length>0)throw Error(`${T.includeFailures.length} include(s) failed to resolve, so this page would have shipped with an error banner where the markup should be:
|
package/dist/visual-testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-
|
|
2
|
+
import"./chunk-cevkpyn9.js";import B from"fs";import $ from"path";import k from"crypto";var V=[{name:"mobile",width:375,height:667,isMobile:!0,hasTouch:!0},{name:"tablet",width:768,height:1024,isMobile:!0,hasTouch:!0},{name:"desktop",width:1280,height:800,isMobile:!1,hasTouch:!1},{name:"wide",width:1920,height:1080,isMobile:!1,hasTouch:!1}];function J(N={}){let Y={snapshotDir:N.snapshotDir||"__snapshots__",screenshotDir:N.screenshotDir||"__screenshots__",updateSnapshots:N.updateSnapshots||process.env.UPDATE_SNAPSHOTS==="true",threshold:N.threshold??0.01,viewports:N.viewports||V,generateDiff:N.generateDiff??!0,diffDir:N.diffDir||"__diffs__",compare:N.compare||b,ci:N.ci??process.env.CI==="true",retries:N.retries??(N.ci?3:1)};return{async snapshot(M,X){let q=$.join(Y.snapshotDir,`${X}.html`),G=C(M),Q=K(G);if(await Bun.file(q).exists()){let W=await Bun.file(q).text(),Z=K(C(W));if(Q===Z)return{passed:!0,snapshotPath:q,message:"Snapshot matches"};if(Y.updateSnapshots)return await B.promises.mkdir($.dirname(q),{recursive:!0}),await Bun.write(q,G),{passed:!0,snapshotPath:q,message:"Snapshot updated"};let F=$.join(Y.diffDir,`${X}.actual.html`),U=$.join(Y.diffDir,`${X}.diff.html`);return await B.promises.mkdir(Y.diffDir,{recursive:!0}),await Bun.write(F,G),await Bun.write(U,I(W,G)),{passed:!1,snapshotPath:q,actualPath:F,diffPath:U,message:"Snapshot does not match"}}return await B.promises.mkdir($.dirname(q),{recursive:!0}),await Bun.write(q,G),{passed:!0,snapshotPath:q,message:"New snapshot created"}},async snapshotJson(M,X){let q=$.join(Y.snapshotDir,`${X}.json`),G=JSON.stringify(M,null,2);if(await Bun.file(q).exists()){let Q=await Bun.file(q).text();if(G===Q)return{passed:!0,snapshotPath:q};if(Y.updateSnapshots)return await Bun.write(q,G),{passed:!0,snapshotPath:q,message:"Snapshot updated"};return{passed:!1,snapshotPath:q,message:`JSON snapshot mismatch:
|
|
3
3
|
${z(Q,G)}`}}return await B.promises.mkdir($.dirname(q),{recursive:!0}),await Bun.write(q,G),{passed:!0,snapshotPath:q,message:"New snapshot created"}},matchInlineSnapshot(M,X){let q=C(M);if(X===void 0)return{passed:!0,expected:q};let G=C(X);return{passed:q===G,expected:q}},getConfig(){return Y}}}function D(N={}){let Y=J(N),M=Y.getConfig();return{async compareScreenshots(X,q,G="desktop"){let Q=$.join(M.screenshotDir,G,`${X}.png`),W=$.join(M.diffDir,G,`${X}.actual.png`),Z=$.join(M.diffDir,G,`${X}.diff.png`);if(await Bun.file(Q).exists()){let F=await Bun.file(Q).arrayBuffer(),U=Buffer.from(F),_=await M.compare(q,U);if(_.match||_.diffPercentage<=M.threshold)return{viewport:G,passed:!0,baselinePath:Q};if(M.updateSnapshots)return await B.promises.mkdir($.dirname(Q),{recursive:!0}),await Bun.write(Q,q),{viewport:G,passed:!0,baselinePath:Q};if(await B.promises.mkdir($.dirname(W),{recursive:!0}),await Bun.write(W,q),_.diffImage&&M.generateDiff)await Bun.write(Z,_.diffImage);return{viewport:G,passed:!1,baselinePath:Q,actualPath:W,diffPath:M.generateDiff?Z:void 0,diffPercentage:_.diffPercentage}}return await B.promises.mkdir($.dirname(Q),{recursive:!0}),await Bun.write(Q,q),{viewport:G,passed:!0,baselinePath:Q}},async testViewports(X,q,G=M.viewports){let Q=[];for(let W of G){let Z=null;for(let F=0;F<M.retries;F++)try{let U=await q(W),_=await this.compareScreenshots(X,U,W.name);Q.push(_),Z=null;break}catch(U){if(Z=U,F<M.retries-1)await new Promise((_)=>setTimeout(_,100*(F+1)))}if(Z)Q.push({viewport:W.name,passed:!1,baselinePath:"",diffPercentage:100})}return Q},getSnapshotTester(){return Y}}}function L(N={}){let M=D(N).getSnapshotTester(),X=new Map;return{addStory(q){X.set(`${q.component}/${q.name}`,q)},addStories(q){for(let G of q)this.addStory(G)},getStories(){return Array.from(X.values())},getStoriesForComponent(q){return Array.from(X.values()).filter((G)=>G.component===q)},async testStory(q){let G=X.get(q);if(!G)return{name:q,passed:!1,duration:0,snapshots:[],screenshots:[],errors:[Error(`Story not found: ${q}`)]};let Q=Date.now(),W={name:q,passed:!0,duration:0,snapshots:[],screenshots:[],errors:[]};try{let Z=await G.render(),F=await M.snapshot(Z,q.replace(/\//g,"-"));if(W.snapshots.push(F),!F.passed)W.passed=!1}catch(Z){W.passed=!1,W.errors.push(Z)}return W.duration=Date.now()-Q,W},async testAllStories(){let q=[];for(let G of X.keys()){let Q=await this.testStory(G);q.push(Q)}return q},async generateStoryIndex(){let q={};for(let G of X.values()){if(!q[G.component])q[G.component]=[];q[G.component].push({name:G.name,args:G.args})}return JSON.stringify(q,null,2)}}}async function S(N,Y={}){let M={outputDir:Y.outputDir||"visual-test-report",format:Y.format||"html",title:Y.title||"Visual Test Report",includeScreenshots:Y.includeScreenshots??!0};await B.promises.mkdir(M.outputDir,{recursive:!0});let X=N.length,q=N.filter((F)=>F.passed).length,G=X-q,Q=N.reduce((F,U)=>F+U.duration,0);if(M.format==="json"){let F={title:M.title,summary:{total:X,passed:q,failed:G,duration:Q},results:N,generatedAt:new Date().toISOString()},U=$.join(M.outputDir,"report.json");return await Bun.write(U,JSON.stringify(F,null,2)),U}if(M.format==="markdown"){let F=`# ${M.title}
|
|
4
4
|
|
|
5
5
|
`;F+=`## Summary
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.403",
|
|
5
5
|
"description": "A performant UI Framework. Powered by Bun.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -118,12 +118,12 @@
|
|
|
118
118
|
"dependencies": {
|
|
119
119
|
"@stacksjs/ts-css": "^0.3.2",
|
|
120
120
|
"@stacksjs/clapp": "^0.2.16",
|
|
121
|
-
"@stacksjs/desktop": "0.2.
|
|
122
|
-
"@stacksjs/sanitizer": "0.2.
|
|
121
|
+
"@stacksjs/desktop": "0.2.403",
|
|
122
|
+
"@stacksjs/sanitizer": "0.2.403",
|
|
123
123
|
"@stacksjs/ts-i18n": "^0.1.11",
|
|
124
|
-
"bun-plugin-stx": "0.2.
|
|
124
|
+
"bun-plugin-stx": "0.2.403",
|
|
125
125
|
"bunfig": "^0.15.19",
|
|
126
|
-
"stx-router": "0.2.
|
|
126
|
+
"stx-router": "0.2.403",
|
|
127
127
|
"ts-broadcasting": "^0.0.11",
|
|
128
128
|
"ts-images": "^0.2.22",
|
|
129
129
|
"ts-syntax-highlighter": "^0.2.1"
|
package/dist/chunk-07syq64h.js
DELETED
package/dist/chunk-0nqcv7z7.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{To as a,Uo as b,Vo as c,Wo as d}from"./chunk-zstrcmbj.js";import"./chunk-4cv7bw5e.js";import"./chunk-7tgjn256.js";import"./chunk-h8zp2fz9.js";import"./chunk-ekvejzvk.js";import"./chunk-3769e62c.js";import"./chunk-7c8r36ve.js";import"./chunk-yj5gkn17.js";import"./chunk-cy8hgd86.js";import"./chunk-twws9vvz.js";import"./chunk-g7qmxjyc.js";import"./chunk-88tt0qg0.js";import"./chunk-e1rv01pn.js";import"./chunk-bdz7nznw.js";import"./chunk-rwtj7j0r.js";import"./chunk-eqhsprr0.js";import"./chunk-csgshaeh.js";import"./chunk-d0qy1ezf.js";import"./chunk-c9kj8p6j.js";import"./chunk-x2wmn8m7.js";import"./chunk-rxz43r6k.js";export{b as reportDeferredLoopWarnings,c as processLoops,a as parseLoopBinding,d as declareBareLoopHead};
|
package/dist/chunk-160zge7a.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{ok as a,pk as b,qk as c,rk as d}from"./chunk-hh8abhtc.js";import"./chunk-pqc4sv02.js";import"./chunk-zstrcmbj.js";import"./chunk-4cv7bw5e.js";import"./chunk-7tgjn256.js";import"./chunk-h8zp2fz9.js";import"./chunk-ekvejzvk.js";import"./chunk-3769e62c.js";import"./chunk-7c8r36ve.js";import"./chunk-yj5gkn17.js";import"./chunk-cy8hgd86.js";import"./chunk-twws9vvz.js";import"./chunk-g7qmxjyc.js";import"./chunk-88tt0qg0.js";import"./chunk-e1rv01pn.js";import"./chunk-bdz7nznw.js";import"./chunk-rwtj7j0r.js";import"./chunk-eqhsprr0.js";import"./chunk-csgshaeh.js";import"./chunk-d0qy1ezf.js";import"./chunk-c9kj8p6j.js";import"./chunk-x2wmn8m7.js";import"./chunk-rxz43r6k.js";export{b as getAvailableTargets,c as getAvailableFormats,d as default,a as buildNative};
|