@stacksjs/stx 0.2.490 → 0.2.491
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-service-worker.d.ts +12 -0
- package/dist/{chunk-rd2w20hg.js → chunk-0acycggt.js} +1 -1
- package/dist/{chunk-9gqkdzhq.js → chunk-0gx8he4p.js} +1 -1
- package/dist/{chunk-hem4ak5x.js → chunk-0zs1fd9z.js} +1 -1
- package/dist/{chunk-rcn6m3cj.js → chunk-1x4b64mx.js} +1 -1
- package/dist/{chunk-nr7qak48.js → chunk-2b1zg7xp.js} +1 -1
- package/dist/{chunk-2cybh8dh.js → chunk-4tb1mqr8.js} +1 -1
- package/dist/{chunk-2hbygqzj.js → chunk-52fcqzmc.js} +1 -1
- package/dist/{chunk-yhv65tpd.js → chunk-6mqb6vf7.js} +1 -1
- package/dist/{chunk-rn4cppcj.js → chunk-7c18zqdc.js} +1 -1
- package/dist/{chunk-93wkn776.js → chunk-86vgttef.js} +1 -1
- package/dist/{chunk-ah4ww997.js → chunk-aertsqje.js} +1 -1
- package/dist/chunk-af944jrx.js +2 -0
- package/dist/{chunk-4b5hg8y1.js → chunk-b6xrqx6w.js} +1 -1
- package/dist/{chunk-egax8990.js → chunk-bay6snzz.js} +1 -1
- package/dist/{chunk-jva1bbpw.js → chunk-bt58m9y8.js} +1 -1
- package/dist/{chunk-0ttq5enq.js → chunk-c0jedy4d.js} +1 -1
- package/dist/{chunk-ftdabyt6.js → chunk-cfj3c9ss.js} +1 -1
- package/dist/{chunk-p5bwcppv.js → chunk-djwms13g.js} +1 -1
- package/dist/{chunk-rt71qxdq.js → chunk-dnq9fhwf.js} +1 -1
- package/dist/{chunk-s6v5p03w.js → chunk-e43ckdk2.js} +1 -1
- package/dist/{chunk-6ejfx4qw.js → chunk-emx5wsaa.js} +1 -1
- package/dist/{chunk-qv3rrz9a.js → chunk-f324yttz.js} +1 -1
- package/dist/{chunk-p6trwjap.js → chunk-fh3r97cq.js} +1 -1
- package/dist/{chunk-hsywkvng.js → chunk-fh7w72xm.js} +1 -1
- package/dist/{chunk-0ma6yhg9.js → chunk-ft6k76e4.js} +1 -1
- package/dist/{chunk-ezvy497d.js → chunk-fzwy4nny.js} +1 -1
- package/dist/{chunk-8b71njp8.js → chunk-g3hn7ncc.js} +2 -2
- package/dist/{chunk-rbsn2vf5.js → chunk-gparzn81.js} +1 -1
- package/dist/{chunk-vzxkwr23.js → chunk-gwvg2c50.js} +1 -1
- package/dist/{chunk-1yckkva7.js → chunk-j1d4aemv.js} +1 -1
- package/dist/{chunk-qk5j55r0.js → chunk-jaghd4j0.js} +2 -2
- package/dist/{chunk-baprpeby.js → chunk-jnf8vt18.js} +1 -1
- package/dist/{chunk-5f7qy42x.js → chunk-jws8btr5.js} +115 -115
- package/dist/{chunk-nxxmhrd0.js → chunk-kzg3h5wg.js} +1 -1
- package/dist/{chunk-svywp38a.js → chunk-nf9fhj10.js} +1 -1
- package/dist/{chunk-34154wz1.js → chunk-nfd56dgj.js} +1 -1
- package/dist/{chunk-yxgfw906.js → chunk-nnqjjtqz.js} +1 -1
- package/dist/{chunk-g7jcpd5j.js → chunk-nwy97xaa.js} +1 -1
- package/dist/{chunk-9ds5dn6f.js → chunk-perp76wy.js} +1 -1
- package/dist/{chunk-8j8egh39.js → chunk-q21e52cb.js} +1 -1
- package/dist/chunk-q9w7sb6r.js +2 -0
- package/dist/chunk-qnyfg99e.js +2 -0
- package/dist/{chunk-9mywx2x0.js → chunk-sdxq5ej9.js} +1 -1
- package/dist/{chunk-jd9c46cc.js → chunk-vbthtg0x.js} +1 -1
- package/dist/{chunk-368zt1db.js → chunk-z26ty1t1.js} +1 -1
- package/dist/{chunk-24jeywdh.js → chunk-z7bqn398.js} +5 -5
- package/dist/{chunk-aabzyk88.js → chunk-ze9vhhvc.js} +2 -2
- package/dist/{chunk-zkjp87ak.js → chunk-zxkzdbcv.js} +1 -1
- package/dist/cli.js +7 -7
- package/dist/composables/use-network.d.ts +4 -0
- package/dist/composables/use-network.js +4 -3
- package/dist/composables/use-outbox.d.ts +1 -0
- package/dist/composables/use-outbox.js +51 -22
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/offline/app-service-worker.d.ts +12 -0
- package/dist/offline/app-service-worker.js +56 -12
- package/dist/pwa.js +1 -1
- package/dist/ssg.js +2 -2
- package/package.json +5 -5
- package/dist/chunk-0jfrzq0r.js +0 -2
- package/dist/chunk-5cd0jbt4.js +0 -2
- package/dist/chunk-vwybce48.js +0 -2
|
@@ -25,6 +25,10 @@ export declare function useOnline(): { isOnline: boolean; subscribe: (cb: (onlin
|
|
|
25
25
|
* useNetwork - Reactive network status composables
|
|
26
26
|
*
|
|
27
27
|
* Provides reactive tracking of network connectivity and information.
|
|
28
|
+
*
|
|
29
|
+
* Online means the app can reach its server: the browser's own flag, and,
|
|
30
|
+
* where stx's offline worker runs, whether its last request to the server got
|
|
31
|
+
* there (`window.stxOffline.reachable`, kept current by `stx:reachability`).
|
|
28
32
|
*/
|
|
29
33
|
export declare interface NetworkState {
|
|
30
34
|
isOnline: boolean
|
|
@@ -14,10 +14,10 @@ export function useNetwork() {
|
|
|
14
14
|
rtt: null,
|
|
15
15
|
saveData: !1
|
|
16
16
|
};
|
|
17
|
-
const connection = getConnection();
|
|
17
|
+
const connection = getConnection(), online = navigator.onLine && window.stxOffline?.reachable !== !1;
|
|
18
18
|
return {
|
|
19
|
-
isOnline:
|
|
20
|
-
isOffline: !
|
|
19
|
+
isOnline: online,
|
|
20
|
+
isOffline: !online,
|
|
21
21
|
type: connection?.type || null,
|
|
22
22
|
effectiveType: connection?.effectiveType || null,
|
|
23
23
|
downlink: connection?.downlink || null,
|
|
@@ -39,6 +39,7 @@ export function useNetwork() {
|
|
|
39
39
|
if (isClient) {
|
|
40
40
|
window.addEventListener("online", notify);
|
|
41
41
|
window.addEventListener("offline", notify);
|
|
42
|
+
window.addEventListener("stx:reachability", notify);
|
|
42
43
|
const connection = getConnection();
|
|
43
44
|
if (connection)
|
|
44
45
|
connection.addEventListener("change", notify);
|
|
@@ -42,6 +42,7 @@ export declare interface OutboxOptions {
|
|
|
42
42
|
idempotency?: boolean
|
|
43
43
|
overlays?: Record<string, OutboxOverlay>
|
|
44
44
|
apply?: OutboxOverlay
|
|
45
|
+
lock?: { acquire: () => boolean, release: () => void }
|
|
45
46
|
}
|
|
46
47
|
export declare interface Outbox {
|
|
47
48
|
send: (url: string, init?: OutboxSendInit) => Promise<OutboxSendResult>
|
|
@@ -160,32 +160,54 @@ export function useOutbox(name, options = {}) {
|
|
|
160
160
|
async function flush(force = !1) {
|
|
161
161
|
if (flushing)
|
|
162
162
|
return flushing;
|
|
163
|
-
flushing = (
|
|
164
|
-
for (const entry of read()) {
|
|
165
|
-
if (!force && entry.nextAt > Date.now())
|
|
166
|
-
break;
|
|
167
|
-
const outcome = await deliver(entry), list = read(), at = list.findIndex((item) => item.id === entry.id);
|
|
168
|
-
if (outcome === "kept") {
|
|
169
|
-
if (at >= 0) {
|
|
170
|
-
list[at] = { ...list[at], attempts: list[at].attempts + 1, nextAt: Date.now() + delayFor(list[at].attempts + 1) };
|
|
171
|
-
write(list);
|
|
172
|
-
}
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
if (at >= 0) {
|
|
176
|
-
if (outcome === "sent")
|
|
177
|
-
announce(name, list, list[at]);
|
|
178
|
-
list.splice(at, 1);
|
|
179
|
-
write(list);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
})();
|
|
163
|
+
flushing = opts.lock && read().length ? lockedFlush(opts.lock, force) : sendDue(force);
|
|
183
164
|
try {
|
|
184
165
|
await flushing;
|
|
185
166
|
} finally {
|
|
186
167
|
flushing = null;
|
|
187
168
|
}
|
|
188
169
|
}
|
|
170
|
+
async function lockedFlush(lock, force) {
|
|
171
|
+
let held = !1;
|
|
172
|
+
try {
|
|
173
|
+
held = lock.acquire();
|
|
174
|
+
} catch {}
|
|
175
|
+
if (!held) {
|
|
176
|
+
if (timer)
|
|
177
|
+
clearTimeout(timer);
|
|
178
|
+
timer = typeof setTimeout > "u" ? null : setTimeout(() => {
|
|
179
|
+
flush(force);
|
|
180
|
+
}, 5000);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
await sendDue(force);
|
|
185
|
+
} finally {
|
|
186
|
+
try {
|
|
187
|
+
lock.release();
|
|
188
|
+
} catch {}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async function sendDue(force) {
|
|
192
|
+
for (const entry of read()) {
|
|
193
|
+
if (!force && entry.nextAt > Date.now())
|
|
194
|
+
break;
|
|
195
|
+
const outcome = await deliver(entry), list = read(), at = list.findIndex((item) => item.id === entry.id);
|
|
196
|
+
if (outcome === "kept") {
|
|
197
|
+
if (at >= 0) {
|
|
198
|
+
list[at] = { ...list[at], attempts: list[at].attempts + 1, nextAt: Date.now() + delayFor(list[at].attempts + 1) };
|
|
199
|
+
write(list);
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
if (at >= 0) {
|
|
204
|
+
if (outcome === "sent")
|
|
205
|
+
announce(name, list, list[at]);
|
|
206
|
+
list.splice(at, 1);
|
|
207
|
+
write(list);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
189
211
|
async function send(url, init = {}) {
|
|
190
212
|
const { background, meta, affects, apply, overlay, ...requestInit } = init, id = newId(), entry = {
|
|
191
213
|
id,
|
|
@@ -252,12 +274,17 @@ export function useOutbox(name, options = {}) {
|
|
|
252
274
|
}
|
|
253
275
|
const onOnline = () => {
|
|
254
276
|
flush(!0);
|
|
277
|
+
}, onReachable = (event) => {
|
|
278
|
+
if (event.detail?.reachable !== !1)
|
|
279
|
+
flush(!0);
|
|
255
280
|
}, onVisible = () => {
|
|
256
281
|
if (typeof document < "u" && document.visibilityState === "visible")
|
|
257
282
|
flush(!0);
|
|
258
283
|
};
|
|
259
|
-
if (typeof addEventListener === "function")
|
|
284
|
+
if (typeof addEventListener === "function") {
|
|
260
285
|
addEventListener("online", onOnline);
|
|
286
|
+
addEventListener("stx:reachability", onReachable);
|
|
287
|
+
}
|
|
261
288
|
if (typeof document < "u")
|
|
262
289
|
document.addEventListener("visibilitychange", onVisible);
|
|
263
290
|
const outbox = {
|
|
@@ -279,8 +306,10 @@ export function useOutbox(name, options = {}) {
|
|
|
279
306
|
if (timer)
|
|
280
307
|
clearTimeout(timer);
|
|
281
308
|
timer = null;
|
|
282
|
-
if (typeof removeEventListener === "function")
|
|
309
|
+
if (typeof removeEventListener === "function") {
|
|
283
310
|
removeEventListener("online", onOnline);
|
|
311
|
+
removeEventListener("stx:reachability", onReachable);
|
|
312
|
+
}
|
|
284
313
|
if (typeof document < "u")
|
|
285
314
|
document.removeEventListener("visibilitychange", onVisible);
|
|
286
315
|
outboxes.delete(name);
|
package/dist/craft-entry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Hr,Ao,Po}from"./chunk-gzt3ghgq.js";import"./chunk-2pph3dh0.js";import"./chunk-c57j92td.js";import"./chunk-rmavqxd8.js";import"./chunk-v7vkqg8f.js";import"./chunk-d4k4nyj0.js";import"./chunk-
|
|
2
|
+
import{Hr,Ao,Po}from"./chunk-gzt3ghgq.js";import"./chunk-2pph3dh0.js";import"./chunk-c57j92td.js";import"./chunk-rmavqxd8.js";import"./chunk-v7vkqg8f.js";import"./chunk-d4k4nyj0.js";import"./chunk-jws8btr5.js";import"./chunk-b77v56fz.js";import"./chunk-qmcmjdy7.js";import"./chunk-1erc0vrb.js";import"./chunk-kzg3h5wg.js";import"./chunk-e6y6s7q8.js";import"./chunk-kp4mzspk.js";import{wu,ko,vu,xu,Co,zr,$o,Su,Eo,ku,Cu,_o,To,Ro}from"./chunk-f324yttz.js";import"./chunk-ze9vhhvc.js";import"./chunk-szry3s17.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(`
|
package/dist/craft.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Hr,Ao,Po}from"./chunk-gzt3ghgq.js";import"./chunk-2pph3dh0.js";import"./chunk-c57j92td.js";import"./chunk-rmavqxd8.js";import"./chunk-v7vkqg8f.js";import"./chunk-d4k4nyj0.js";import"./chunk-
|
|
2
|
+
import{Hr,Ao,Po}from"./chunk-gzt3ghgq.js";import"./chunk-2pph3dh0.js";import"./chunk-c57j92td.js";import"./chunk-rmavqxd8.js";import"./chunk-v7vkqg8f.js";import"./chunk-d4k4nyj0.js";import"./chunk-jws8btr5.js";import"./chunk-b77v56fz.js";import"./chunk-qmcmjdy7.js";import"./chunk-1erc0vrb.js";import"./chunk-kzg3h5wg.js";import"./chunk-e6y6s7q8.js";import"./chunk-kp4mzspk.js";import{wu,ko,vu,xu,Co,zr,$o,Su,Eo,ku,Cu,_o,To,Ro}from"./chunk-f324yttz.js";import"./chunk-ze9vhhvc.js";import"./chunk-szry3s17.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(`
|
|
@@ -34,6 +34,12 @@
|
|
|
34
34
|
* before the app's last write is not answered at once (the write would
|
|
35
35
|
* seem not to have happened), nor is one for a request made with
|
|
36
36
|
* `cache: 'no-cache'` (a pull to refresh) or under a `networkFirst` prefix.
|
|
37
|
+
* - Whether the server can be reached: a page whose reads are all answered
|
|
38
|
+
* from kept copies cannot tell that the network behind them is gone (a
|
|
39
|
+
* phone on one bar of gym wifi says it is online). When a request to the
|
|
40
|
+
* server fails for want of a network, or succeeds again, every open page
|
|
41
|
+
* hears `stx:reachability` { reachable, at }, `at` being when the server
|
|
42
|
+
* last answered; `useNetwork()` counts an unreachable server as offline.
|
|
37
43
|
* - Writes are never cached or replayed here. The page queues them itself
|
|
38
44
|
* (`useOutbox`), where it can tell the person what happened.
|
|
39
45
|
* - A new build installs beside the running one and waits. It takes over when
|
|
@@ -50,6 +56,12 @@ export interface OfflineAppConfig {
|
|
|
50
56
|
* Listed pages whose HTML is an account-independent shell. These may be
|
|
51
57
|
* retained despite the server's default no-store header. Never list pages
|
|
52
58
|
* containing server-rendered personal data; API no-store remains enforced.
|
|
59
|
+
*
|
|
60
|
+
* A route of `routes` may be listed too (`/m/go/:id`, as written there):
|
|
61
|
+
* its kept page, the one every value of it stands in with offline, is then
|
|
62
|
+
* refreshed by each visit despite no-store. Without that, a server that
|
|
63
|
+
* marks every page no-store left a route only the copy fetched when the
|
|
64
|
+
* worker installed, and a page in `pages` none at all after its first visit.
|
|
53
65
|
*/
|
|
54
66
|
staticPages?: string[];
|
|
55
67
|
/** Path prefix of the app's API, whose GET answers are kept for offline. Default '/api/'. */
|
|
@@ -25,6 +25,8 @@ export function registerOfflineWorker(path) {
|
|
|
25
25
|
let registration = null, reloadOnTakeOver = !1;
|
|
26
26
|
const waitingCallbacks = [], api = {
|
|
27
27
|
updateReady: !1,
|
|
28
|
+
reachable: !0,
|
|
29
|
+
reachedAt: 0,
|
|
28
30
|
registration: () => registration,
|
|
29
31
|
onUpdateReady(callback) {
|
|
30
32
|
if (api.updateReady)
|
|
@@ -68,6 +70,14 @@ export function registerOfflineWorker(path) {
|
|
|
68
70
|
try {
|
|
69
71
|
window.dispatchEvent(new CustomEvent("stx:updated", { detail: { url: data.url, kind: data.kind, fragment: !!data.fragment } }));
|
|
70
72
|
} catch {}
|
|
73
|
+
if (data.type === "stx:reachability") {
|
|
74
|
+
w.stxOffline.reachable = data.reachable !== !1;
|
|
75
|
+
if (Number(data.at) > 0)
|
|
76
|
+
w.stxOffline.reachedAt = Number(data.at);
|
|
77
|
+
try {
|
|
78
|
+
window.dispatchEvent(new CustomEvent("stx:reachability", { detail: { reachable: data.reachable !== !1, at: Number(data.at) || 0 } }));
|
|
79
|
+
} catch {}
|
|
80
|
+
}
|
|
71
81
|
});
|
|
72
82
|
sw.addEventListener("controllerchange", () => {
|
|
73
83
|
if (reloadOnTakeOver) {
|
|
@@ -82,6 +92,9 @@ export function registerOfflineWorker(path) {
|
|
|
82
92
|
const register = () => {
|
|
83
93
|
sw.register(path, { scope: "/" }).then((reg) => {
|
|
84
94
|
registration = reg;
|
|
95
|
+
try {
|
|
96
|
+
sw.controller?.postMessage({ type: "stx:reachability?" });
|
|
97
|
+
} catch {}
|
|
85
98
|
if (reg.waiting) {
|
|
86
99
|
ready(reg);
|
|
87
100
|
reg.waiting.postMessage({ type: "stx:activate-update", reason: "load" });
|
|
@@ -136,7 +149,7 @@ export function generateOfflineWorker(config, buildId) {
|
|
|
136
149
|
const settings = {
|
|
137
150
|
build: String(buildId || "dev"),
|
|
138
151
|
pages: Array.from(new Set((config.pages || []).filter((page) => typeof page === "string" && page.startsWith("/")))),
|
|
139
|
-
staticPages: (config.staticPages || []).filter((page) => typeof page === "string" && (config.pages || []).includes(page)),
|
|
152
|
+
staticPages: (config.staticPages || []).filter((page) => typeof page === "string" && ((config.pages || []).includes(page) || (config.routes || []).includes(page))),
|
|
140
153
|
api: config.apiPrefix || "/api/",
|
|
141
154
|
timeout: Math.max(500, Number(config.networkTimeoutMs) || 1500),
|
|
142
155
|
networkFirst: (config.networkFirst || []).filter((path) => typeof path === "string" && path.startsWith("/")),
|
|
@@ -268,6 +281,29 @@ function unchanged(hit, response, hash) {
|
|
|
268
281
|
return keptHash(hit).then(function (known) { return known === hash; });
|
|
269
282
|
}
|
|
270
283
|
|
|
284
|
+
// Whether the server answered the last request that went to it, and when it
|
|
285
|
+
// last did. Pages hear a change of the first (stx:reachability).
|
|
286
|
+
var reachable = true;
|
|
287
|
+
var reachedAt = 0;
|
|
288
|
+
function reached(yes) {
|
|
289
|
+
if (yes) reachedAt = Date.now();
|
|
290
|
+
if (yes === reachable) return;
|
|
291
|
+
reachable = yes;
|
|
292
|
+
announce({ type: 'stx:reachability', reachable: yes, at: reachedAt });
|
|
293
|
+
}
|
|
294
|
+
// A fetch to the server, noting whether it got there. Any answer counts,
|
|
295
|
+
// an error status included: the server was reached.
|
|
296
|
+
function network(request, init) {
|
|
297
|
+
return fetch(request, init).then(function (response) {
|
|
298
|
+
reached(true);
|
|
299
|
+
return response;
|
|
300
|
+
}, function (error) {
|
|
301
|
+
// A TypeError is the network's; an abort is the page's own doing.
|
|
302
|
+
if (!error || error.name !== 'AbortError') reached(false);
|
|
303
|
+
throw error;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
271
307
|
// Every open page of the app hears what changed, so it can redraw.
|
|
272
308
|
function announce(message) {
|
|
273
309
|
if (!self.clients || !self.clients.matchAll) return Promise.resolve();
|
|
@@ -283,7 +319,7 @@ function announce(message) {
|
|
|
283
319
|
// answer replaces the copy and is announced; the same one only refreshes
|
|
284
320
|
// when it was kept.
|
|
285
321
|
function revalidate(request, cache, keys, hit, kind) {
|
|
286
|
-
return
|
|
322
|
+
return network(request).then(function (response) {
|
|
287
323
|
var staticPage = kind === 'page' && keepStaticPage(request, response);
|
|
288
324
|
if (noStore(response) && !staticPage) return Promise.all(keys.map(function (key) { return cache.delete(key); }));
|
|
289
325
|
if (!keepable(response) && !staticPage) return;
|
|
@@ -299,8 +335,12 @@ function revalidate(request, cache, keys, hit, kind) {
|
|
|
299
335
|
}
|
|
300
336
|
|
|
301
337
|
function keepStaticPage(request, response) {
|
|
302
|
-
|
|
303
|
-
|
|
338
|
+
if (response.status !== 200 || response.redirected || response.type !== 'basic') return false;
|
|
339
|
+
var pathname = new URL(request.url).pathname;
|
|
340
|
+
if (S.staticPages.indexOf(pathname) !== -1) return true;
|
|
341
|
+
// A route declared static: every value of it is the same shell.
|
|
342
|
+
var dynamic = routeOf(pathname);
|
|
343
|
+
return !!dynamic && S.staticPages.indexOf(dynamic.route.path) !== -1;
|
|
304
344
|
}
|
|
305
345
|
|
|
306
346
|
// A dynamic route's kept page, under a key no real path has.
|
|
@@ -549,6 +589,10 @@ function mediaResponse(request) {
|
|
|
549
589
|
|
|
550
590
|
self.addEventListener('message', function (event) {
|
|
551
591
|
var data = event.data || {};
|
|
592
|
+
if (data.type === 'stx:reachability?') {
|
|
593
|
+
// A page just opened: what this worker last saw of the server.
|
|
594
|
+
event.waitUntil(announce({ type: 'stx:reachability', reachable: reachable, at: reachedAt }));
|
|
595
|
+
}
|
|
552
596
|
if (data.type === 'stx:clear-offline-data') {
|
|
553
597
|
lastWrite = null;
|
|
554
598
|
event.waitUntil(Promise.all([caches.delete(DATA), caches.delete(MEDIA)]));
|
|
@@ -651,7 +695,7 @@ function pageResponse(request, event) {
|
|
|
651
695
|
// Kept, but without its module bundles: not shown while the network
|
|
652
696
|
// might answer (bundlesKept).
|
|
653
697
|
var partial = hit && !networkFirst;
|
|
654
|
-
var
|
|
698
|
+
var asked = network(request).then(function (response) {
|
|
655
699
|
if (keepable(response) || keepStaticPage(request, response)) keepAlive(event, store(cache, keys, response.clone()));
|
|
656
700
|
return response;
|
|
657
701
|
});
|
|
@@ -667,14 +711,14 @@ function pageResponse(request, event) {
|
|
|
667
711
|
return cache.match(variantUrl(S.fallback, false)).then(function (fallback) { return fallback ? markFallback(fallback) : Response.error(); });
|
|
668
712
|
});
|
|
669
713
|
};
|
|
670
|
-
return withTimeout(
|
|
714
|
+
return withTimeout(asked, S.timeout).catch(function () {
|
|
671
715
|
return standIn(false).then(function (kept) {
|
|
672
716
|
if (kept) {
|
|
673
|
-
keepAlive(event,
|
|
717
|
+
keepAlive(event, asked);
|
|
674
718
|
return kept;
|
|
675
719
|
}
|
|
676
720
|
// Slower than the timeout, nothing kept to show: wait for it rather than fail.
|
|
677
|
-
return
|
|
721
|
+
return asked.catch(function () { return standIn(true); });
|
|
678
722
|
});
|
|
679
723
|
});
|
|
680
724
|
});
|
|
@@ -730,13 +774,13 @@ function apiResponse(request, event) {
|
|
|
730
774
|
keepAlive(event, revalidate(request, cache, [key], hit, 'api'));
|
|
731
775
|
return hit;
|
|
732
776
|
}
|
|
733
|
-
var
|
|
777
|
+
var asked = network(request).then(function (response) {
|
|
734
778
|
if (noStore(response)) keepAlive(event, cache.delete(key));
|
|
735
779
|
if (keepable(response)) keepAlive(event, store(cache, [key], response.clone()));
|
|
736
780
|
return response;
|
|
737
781
|
});
|
|
738
|
-
return withTimeout(
|
|
739
|
-
return hit ||
|
|
782
|
+
return withTimeout(asked, S.timeout).catch(function () {
|
|
783
|
+
return hit || asked;
|
|
740
784
|
});
|
|
741
785
|
});
|
|
742
786
|
});
|
|
@@ -755,7 +799,7 @@ self.addEventListener('fetch', function (event) {
|
|
|
755
799
|
// Live status and other explicitly uncached reads must never be answered
|
|
756
800
|
// from offline storage, including when the network fails.
|
|
757
801
|
if (request.cache === 'no-store') {
|
|
758
|
-
event.respondWith(
|
|
802
|
+
event.respondWith(network(request));
|
|
759
803
|
return;
|
|
760
804
|
}
|
|
761
805
|
// Media kept for offline is answered from the device, a range included;
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import{Ln,Oe,Bo,Wa}from"./chunk-4c1afy15.js";import{Nn,Vr,Ha,Va,Ua}from"./chunk-jbvg29t0.js";import{No,Lo,jo,Fa,za}from"./chunk-e62nw7zk.js";import{oe,gt,Ur}from"./chunk-hkjqqx92.js";import{Xc,Gc,Jc,Yc,fr,md}from"./chunk-jwjggr91.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-
|
|
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-dnq9fhwf.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">
|
package/dist/ssg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-2hc5mbw8.js";import"./chunk-2pph3dh0.js";import"./chunk-c57j92td.js";import{et,tt,nt,rt,st,ot}from"./chunk-rmavqxd8.js";import"./chunk-v7vkqg8f.js";import"./chunk-d4k4nyj0.js";import{f,Be,N,K,n,o}from"./chunk-
|
|
2
|
+
import"./chunk-2hc5mbw8.js";import"./chunk-2pph3dh0.js";import"./chunk-c57j92td.js";import{et,tt,nt,rt,st,ot}from"./chunk-rmavqxd8.js";import"./chunk-v7vkqg8f.js";import"./chunk-d4k4nyj0.js";import{f,Be,N,K,n,o}from"./chunk-jws8btr5.js";import"./chunk-b77v56fz.js";import{nr}from"./chunk-qmcmjdy7.js";import"./chunk-1erc0vrb.js";import"./chunk-kzg3h5wg.js";import"./chunk-e6y6s7q8.js";import"./chunk-kp4mzspk.js";import"./chunk-nfd56dgj.js";import{ie,mt,ht}from"./chunk-7c18zqdc.js";import{Do,Oo,Mo}from"./chunk-er7y8hk9.js";import{ft,Yt,Zt}from"./chunk-g7ey7mtw.js";import"./chunk-szry3s17.js";import{a}from"./chunk-jbj6xh7f.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-nf9fhj10.js");try{D=m(await u(process.cwd()))}catch{}}let{prepareImageDelivery:p}=await import("./chunk-sdxq5ej9.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-nf9fhj10.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:
|
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.491",
|
|
5
5
|
"description": "A performant UI Framework. Powered by Bun.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -122,12 +122,12 @@
|
|
|
122
122
|
"dependencies": {
|
|
123
123
|
"@stacksjs/ts-css": "^0.3.2",
|
|
124
124
|
"@stacksjs/clapp": "^0.2.16",
|
|
125
|
-
"@stacksjs/desktop": "0.2.
|
|
126
|
-
"@stacksjs/sanitizer": "0.2.
|
|
125
|
+
"@stacksjs/desktop": "0.2.491",
|
|
126
|
+
"@stacksjs/sanitizer": "0.2.491",
|
|
127
127
|
"@stacksjs/ts-i18n": "^0.1.11",
|
|
128
|
-
"bun-plugin-stx": "0.2.
|
|
128
|
+
"bun-plugin-stx": "0.2.491",
|
|
129
129
|
"bunfig": "^0.15.19",
|
|
130
|
-
"stx-router": "0.2.
|
|
130
|
+
"stx-router": "0.2.491",
|
|
131
131
|
"ts-broadcasting": "^0.0.11",
|
|
132
132
|
"ts-images": "^0.2.22",
|
|
133
133
|
"ts-syntax-highlighter": "^0.2.1"
|
package/dist/chunk-0jfrzq0r.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{Ui,Wi}from"./chunk-24jeywdh.js";import"./chunk-baprpeby.js";import"./chunk-nr7qak48.js";import"./chunk-0egg3666.js";import"./chunk-z9fz5dby.js";import"./chunk-jva1bbpw.js";import"./chunk-01rz8h7x.js";import"./chunk-yhv65tpd.js";import{io}from"./chunk-8b71njp8.js";import"./chunk-rhrv2j36.js";import"./chunk-z9tvn738.js";import"./chunk-2hbygqzj.js";import"./chunk-8fb1mqw1.js";import"./chunk-298s08st.js";import"./chunk-2cybh8dh.js";import"./chunk-vg9dyc4y.js";import"./chunk-zv0vgamy.js";import"./chunk-1v86h5vn.js";import"./chunk-vp827ah7.js";import"./chunk-3mynjdqr.js";import"./chunk-cp7hph6f.js";import"./chunk-67actssw.js";import"./chunk-zkjp87ak.js";import"./chunk-h6q8jafh.js";import"./chunk-3s9s1mdt.js";import"./chunk-s9mq9x2k.js";import"./chunk-1c407nky.js";import"./chunk-71bbv43t.js";import"./chunk-8j8egh39.js";import"./chunk-25m2wqsd.js";import"./chunk-0ma6yhg9.js";import"./chunk-aabzyk88.js";import"./chunk-er7y8hk9.js";import"./chunk-rn4cppcj.js";import"./chunk-34154wz1.js";import"./chunk-2hc5mbw8.js";import{he,nn,rn,K,d,n,Jn,I,o,le}from"./chunk-5f7qy42x.js";import"./chunk-szry3s17.js";import"./chunk-c57j92td.js";import"./chunk-kp4mzspk.js";import"./chunk-nxxmhrd0.js";import"./chunk-1erc0vrb.js";import"./chunk-qmcmjdy7.js";import"./chunk-b77v56fz.js";import"./chunk-2pph3dh0.js";import"./chunk-d4k4nyj0.js";import"./chunk-v7vkqg8f.js";import"./chunk-rmavqxd8.js";import"./chunk-e6y6s7q8.js";export{Jn as buildWebComponents,rn as cacheTemplate,nn as checkCache,io as classifyAllScripts,Ui as createMiddleware,Wi as createRoute,I as defaultConfig,d as extractVariables,K as injectRouterScript,o as loadStxConfig,he as processClientScript,n as processDirectives,le as readMarkdownFile};
|
package/dist/chunk-5cd0jbt4.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{Lr,Ml,Nl}from"./chunk-zkjp87ak.js";import"./chunk-rn4cppcj.js";import"./chunk-34154wz1.js";import"./chunk-2hc5mbw8.js";import"./chunk-5f7qy42x.js";import"./chunk-szry3s17.js";import"./chunk-c57j92td.js";import"./chunk-kp4mzspk.js";import"./chunk-nxxmhrd0.js";import"./chunk-1erc0vrb.js";import"./chunk-qmcmjdy7.js";import"./chunk-b77v56fz.js";import"./chunk-2pph3dh0.js";import"./chunk-d4k4nyj0.js";import"./chunk-v7vkqg8f.js";import"./chunk-rmavqxd8.js";import"./chunk-e6y6s7q8.js";export{Nl as clearComposableCache,Ml as getComposableScript,Lr as listComposableModules};
|
package/dist/chunk-vwybce48.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{nu,ru}from"./chunk-8j8egh39.js";import"./chunk-rn4cppcj.js";import"./chunk-34154wz1.js";import"./chunk-2hc5mbw8.js";import"./chunk-5f7qy42x.js";import"./chunk-szry3s17.js";import"./chunk-c57j92td.js";import"./chunk-kp4mzspk.js";import"./chunk-nxxmhrd0.js";import"./chunk-1erc0vrb.js";import"./chunk-qmcmjdy7.js";import"./chunk-b77v56fz.js";import"./chunk-2pph3dh0.js";import"./chunk-d4k4nyj0.js";import"./chunk-v7vkqg8f.js";import"./chunk-rmavqxd8.js";import"./chunk-e6y6s7q8.js";export{ru as clearStoreCache,nu as getStoreScript};
|