@stacksjs/stx 0.2.490 → 0.2.492

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.
Files changed (66) hide show
  1. package/dist/app-service-worker.d.ts +12 -0
  2. package/dist/{chunk-rd2w20hg.js → chunk-0acycggt.js} +1 -1
  3. package/dist/{chunk-9gqkdzhq.js → chunk-0gx8he4p.js} +1 -1
  4. package/dist/{chunk-hem4ak5x.js → chunk-0zs1fd9z.js} +1 -1
  5. package/dist/{chunk-rcn6m3cj.js → chunk-1x4b64mx.js} +1 -1
  6. package/dist/{chunk-nr7qak48.js → chunk-2b1zg7xp.js} +1 -1
  7. package/dist/{chunk-2cybh8dh.js → chunk-4tb1mqr8.js} +1 -1
  8. package/dist/{chunk-2hbygqzj.js → chunk-52fcqzmc.js} +1 -1
  9. package/dist/{chunk-yhv65tpd.js → chunk-6mqb6vf7.js} +1 -1
  10. package/dist/{chunk-rn4cppcj.js → chunk-7c18zqdc.js} +1 -1
  11. package/dist/{chunk-93wkn776.js → chunk-86vgttef.js} +1 -1
  12. package/dist/{chunk-ah4ww997.js → chunk-aertsqje.js} +1 -1
  13. package/dist/chunk-af944jrx.js +2 -0
  14. package/dist/{chunk-4b5hg8y1.js → chunk-b6xrqx6w.js} +1 -1
  15. package/dist/{chunk-egax8990.js → chunk-bay6snzz.js} +1 -1
  16. package/dist/{chunk-jva1bbpw.js → chunk-bt58m9y8.js} +1 -1
  17. package/dist/{chunk-0ttq5enq.js → chunk-c0jedy4d.js} +1 -1
  18. package/dist/{chunk-ftdabyt6.js → chunk-cfj3c9ss.js} +1 -1
  19. package/dist/{chunk-p5bwcppv.js → chunk-djwms13g.js} +1 -1
  20. package/dist/{chunk-rt71qxdq.js → chunk-dnq9fhwf.js} +1 -1
  21. package/dist/{chunk-s6v5p03w.js → chunk-e43ckdk2.js} +1 -1
  22. package/dist/{chunk-6ejfx4qw.js → chunk-emx5wsaa.js} +1 -1
  23. package/dist/{chunk-qv3rrz9a.js → chunk-f324yttz.js} +1 -1
  24. package/dist/{chunk-p6trwjap.js → chunk-fh3r97cq.js} +1 -1
  25. package/dist/{chunk-hsywkvng.js → chunk-fh7w72xm.js} +1 -1
  26. package/dist/{chunk-0ma6yhg9.js → chunk-ft6k76e4.js} +1 -1
  27. package/dist/{chunk-ezvy497d.js → chunk-fzwy4nny.js} +1 -1
  28. package/dist/{chunk-8b71njp8.js → chunk-g3hn7ncc.js} +2 -2
  29. package/dist/{chunk-rbsn2vf5.js → chunk-gparzn81.js} +1 -1
  30. package/dist/{chunk-vzxkwr23.js → chunk-gwvg2c50.js} +1 -1
  31. package/dist/{chunk-1yckkva7.js → chunk-j1d4aemv.js} +1 -1
  32. package/dist/{chunk-qk5j55r0.js → chunk-jaghd4j0.js} +2 -2
  33. package/dist/{chunk-baprpeby.js → chunk-jnf8vt18.js} +1 -1
  34. package/dist/{chunk-5f7qy42x.js → chunk-jws8btr5.js} +115 -115
  35. package/dist/{chunk-nxxmhrd0.js → chunk-kzg3h5wg.js} +1 -1
  36. package/dist/{chunk-svywp38a.js → chunk-nf9fhj10.js} +1 -1
  37. package/dist/{chunk-34154wz1.js → chunk-nfd56dgj.js} +1 -1
  38. package/dist/{chunk-yxgfw906.js → chunk-nnqjjtqz.js} +1 -1
  39. package/dist/{chunk-g7jcpd5j.js → chunk-nwy97xaa.js} +1 -1
  40. package/dist/{chunk-9ds5dn6f.js → chunk-perp76wy.js} +1 -1
  41. package/dist/{chunk-8j8egh39.js → chunk-q21e52cb.js} +1 -1
  42. package/dist/chunk-q9w7sb6r.js +2 -0
  43. package/dist/chunk-qnyfg99e.js +2 -0
  44. package/dist/{chunk-9mywx2x0.js → chunk-sdxq5ej9.js} +1 -1
  45. package/dist/{chunk-jd9c46cc.js → chunk-vbthtg0x.js} +1 -1
  46. package/dist/{chunk-368zt1db.js → chunk-z26ty1t1.js} +1 -1
  47. package/dist/{chunk-24jeywdh.js → chunk-z7bqn398.js} +5 -5
  48. package/dist/{chunk-aabzyk88.js → chunk-ze9vhhvc.js} +2 -2
  49. package/dist/{chunk-zkjp87ak.js → chunk-zxkzdbcv.js} +1 -1
  50. package/dist/cli.js +7 -7
  51. package/dist/composables/use-network.d.ts +4 -0
  52. package/dist/composables/use-network.js +4 -3
  53. package/dist/composables/use-outbox.d.ts +1 -0
  54. package/dist/composables/use-outbox.js +51 -22
  55. package/dist/craft-entry.js +1 -1
  56. package/dist/craft.js +1 -1
  57. package/dist/native/runtime/jsc-globals.d.ts +38 -0
  58. package/dist/native/runtime/jsc-globals.js +275 -0
  59. package/dist/offline/app-service-worker.d.ts +12 -0
  60. package/dist/offline/app-service-worker.js +56 -12
  61. package/dist/pwa.js +1 -1
  62. package/dist/ssg.js +2 -2
  63. package/package.json +5 -5
  64. package/dist/chunk-0jfrzq0r.js +0 -2
  65. package/dist/chunk-5cd0jbt4.js +0 -2
  66. 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: navigator.onLine,
20
- isOffline: !navigator.onLine,
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 = (async () => {
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);
@@ -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-5f7qy42x.js";import"./chunk-b77v56fz.js";import"./chunk-qmcmjdy7.js";import"./chunk-1erc0vrb.js";import"./chunk-nxxmhrd0.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-qv3rrz9a.js";import"./chunk-aabzyk88.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(`
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-5f7qy42x.js";import"./chunk-b77v56fz.js";import"./chunk-qmcmjdy7.js";import"./chunk-1erc0vrb.js";import"./chunk-nxxmhrd0.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-qv3rrz9a.js";import"./chunk-aabzyk88.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(`
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,7 @@ declare class NativeTextDecoder {
34
34
  * spaces as `+`, everything else outside the unreserved set percent-encoded.
35
35
  */
36
36
  declare class NativeURLSearchParams {
37
+ static linked(query: string, owner: (query: string) => void): NativeURLSearchParams;
37
38
  constructor(init?: string | Record<string, unknown> | Iterable<[unknown, unknown]> | NativeURLSearchParams);
38
39
  get size(): number;
39
40
  append(name: string, value: unknown): void;
@@ -50,4 +51,41 @@ declare class NativeURLSearchParams {
50
51
  [Symbol.iterator](): IterableIterator<[string, string]>;
51
52
  toString(): string;
52
53
  }
54
+ /**
55
+ * `URL`, which JavaScriptCore does not have either: it is a web API.
56
+ * Sign-in code shared with web pages reads and builds addresses with it (an
57
+ * authorize URL's query, the address a sign-in sheet came back to), and on a
58
+ * native screen it threw. Absolute and relative parsing, special schemes and
59
+ * custom ones (`hqtraining://m/login`), and a live `searchParams`, as a
60
+ * browser's. Hostnames are kept as given, lower-cased: no IDNA mapping.
61
+ */
62
+ declare class NativeURL {
63
+ constructor(input: string | { href: string }, base?: string | { href: string });
64
+ static canParse(input: string, base?: string): boolean;
65
+ static parse(input: string, base?: string): NativeURL | null;
66
+ get protocol(): string;
67
+ get username(): string;
68
+ set username(value: string);
69
+ get password(): string;
70
+ set password(value: string);
71
+ get hostname(): string;
72
+ set hostname(value: string);
73
+ get port(): string;
74
+ set port(value: string | number);
75
+ get host(): string;
76
+ set host(value: string);
77
+ get origin(): string;
78
+ get pathname(): string;
79
+ set pathname(value: string);
80
+ get search(): string;
81
+ set search(value: string);
82
+ get searchParams(): NativeURLSearchParams;
83
+ get hash(): string;
84
+ set hash(value: string);
85
+ get href(): string;
86
+ set href(value: string);
87
+ toString(): string;
88
+ toJSON(): string;
89
+ }
53
90
  export { NativeURLSearchParams };
91
+ export { NativeURL };
@@ -80,6 +80,15 @@ class NativeTextDecoder {
80
80
 
81
81
  class NativeURLSearchParams {
82
82
  list = [];
83
+ owner = null;
84
+ static linked(query, owner) {
85
+ const params = new NativeURLSearchParams(query);
86
+ params.owner = owner;
87
+ return params;
88
+ }
89
+ changed() {
90
+ this.owner?.(this.toString());
91
+ }
83
92
  constructor(init) {
84
93
  if (init == null)
85
94
  return;
@@ -115,9 +124,11 @@ class NativeURLSearchParams {
115
124
  }
116
125
  append(name, value) {
117
126
  this.list.push([String(name), String(value)]);
127
+ this.changed();
118
128
  }
119
129
  delete(name) {
120
130
  this.list = this.list.filter(([key]) => key !== name);
131
+ this.changed();
121
132
  }
122
133
  get(name) {
123
134
  return this.list.find(([key]) => key === name)?.[1] ?? null;
@@ -136,9 +147,11 @@ class NativeURLSearchParams {
136
147
  }
137
148
  this.list[at] = [String(name), String(value)];
138
149
  this.list = this.list.filter(([key], index) => key !== name || index === at);
150
+ this.changed();
139
151
  }
140
152
  sort() {
141
153
  this.list.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
154
+ this.changed();
142
155
  }
143
156
  forEach(callback) {
144
157
  for (const [name, value] of [...this.list])
@@ -162,6 +175,267 @@ class NativeURLSearchParams {
162
175
  }
163
176
 
164
177
  export { NativeURLSearchParams };
178
+ const SPECIAL_SCHEMES = { "http:": "80", "https:": "443", "ws:": "80", "wss:": "443", "ftp:": "21", "file:": "" };
179
+ function escapeURLPart(text, unsafe) {
180
+ let out = "";
181
+ for (const char of text)
182
+ if (char.charCodeAt(0) > 126 || char.charCodeAt(0) < 33 || unsafe.test(char))
183
+ out += encodeURIComponent(char);
184
+ else
185
+ out += char;
186
+ return out;
187
+ }
188
+ function removeDotSegments(path) {
189
+ const segments = path.split("/"), out = [];
190
+ for (let i = 0;i < segments.length; i++) {
191
+ const segment = segments[i], last = i === segments.length - 1;
192
+ if (segment === "." || segment.toLowerCase() === "%2e") {
193
+ if (last)
194
+ out.push("");
195
+ continue;
196
+ }
197
+ if (segment === ".." || /^(?:\.|%2e){2}$/i.test(segment)) {
198
+ if (out.length > 1)
199
+ out.pop();
200
+ if (last)
201
+ out.push("");
202
+ continue;
203
+ }
204
+ out.push(segment);
205
+ }
206
+ return out.join("/");
207
+ }
208
+
209
+ class NativeURL {
210
+ parts;
211
+ params = null;
212
+ constructor(input, base) {
213
+ const text = typeof input === "string" ? input : String(input?.href ?? input), baseParts = base === void 0 ? null : NativeURL.parts(typeof base === "string" ? base : String(base?.href ?? base), null);
214
+ if (base !== void 0 && !baseParts)
215
+ throw TypeError(`Invalid base URL: ${String(base)}`);
216
+ const parts = NativeURL.parts(text, baseParts);
217
+ if (!parts)
218
+ throw TypeError(`Invalid URL: ${text}`);
219
+ this.parts = parts;
220
+ }
221
+ static canParse(input, base) {
222
+ try {
223
+ new NativeURL(input, base);
224
+ return !0;
225
+ } catch {
226
+ return !1;
227
+ }
228
+ }
229
+ static parse(input, base) {
230
+ try {
231
+ return new NativeURL(input, base);
232
+ } catch {
233
+ return null;
234
+ }
235
+ }
236
+ static parts(input, base) {
237
+ const text = String(input).replace(/[\t\n\r]/g, "").trim(), scheme = /^([a-z][a-z\d+.-]*):/i.exec(text);
238
+ if (scheme) {
239
+ const protocol = `${scheme[1].toLowerCase()}:`, rest = text.slice(scheme[0].length);
240
+ if (base && base.protocol === protocol && protocol in SPECIAL_SCHEMES && !/^[/\\]/.test(rest))
241
+ return NativeURL.relative(rest, base);
242
+ return NativeURL.absolute(protocol, rest);
243
+ }
244
+ if (!base)
245
+ return null;
246
+ return NativeURL.relative(text, base);
247
+ }
248
+ static absolute(protocol, rest) {
249
+ const special = protocol in SPECIAL_SCHEMES, parts = { protocol, username: "", password: "", hostname: "", port: "", authority: !1, pathname: "", query: null, fragment: null };
250
+ let remaining = rest;
251
+ const hashAt = remaining.indexOf("#");
252
+ if (hashAt !== -1) {
253
+ parts.fragment = remaining.slice(hashAt + 1);
254
+ remaining = remaining.slice(0, hashAt);
255
+ }
256
+ const queryAt = remaining.indexOf("?");
257
+ if (queryAt !== -1) {
258
+ parts.query = remaining.slice(queryAt + 1);
259
+ remaining = remaining.slice(0, queryAt);
260
+ }
261
+ if (special || remaining.startsWith("//")) {
262
+ parts.authority = !0;
263
+ remaining = parts.protocol === "file:" ? remaining.replace(/^[/\\]{2}/, "") : special ? remaining.replace(/^[/\\]*/, "") : remaining.slice(2);
264
+ const end = remaining.search(special ? /[/\\]/ : /\//), authority = end === -1 ? remaining : remaining.slice(0, end);
265
+ remaining = end === -1 ? "" : remaining.slice(end);
266
+ if (!NativeURL.authority(parts, authority, special))
267
+ return null;
268
+ }
269
+ parts.pathname = NativeURL.path(remaining, parts);
270
+ return NativeURL.finish(parts);
271
+ }
272
+ static authority(parts, authority, special) {
273
+ const at = authority.lastIndexOf("@");
274
+ if (at !== -1) {
275
+ const info = authority.slice(0, at), colon = info.indexOf(":");
276
+ parts.username = escapeURLPart(colon === -1 ? info : info.slice(0, colon), /[ "#<>?`{}/:;=@[\\\]^|]/);
277
+ parts.password = colon === -1 ? "" : escapeURLPart(info.slice(colon + 1), /[ "#<>?`{}/:;=@[\\\]^|]/);
278
+ }
279
+ const host = at === -1 ? authority : authority.slice(at + 1), portAt = host.startsWith("[") ? host.indexOf(":", host.indexOf("]")) : host.lastIndexOf(":"), hostname = portAt === -1 ? host : host.slice(0, portAt), port = portAt === -1 ? "" : host.slice(portAt + 1);
280
+ if (port && (!/^\d+$/.test(port) || Number(port) > 65535))
281
+ return !1;
282
+ if (/[\s#%/:<>?@[\\\]^|]/.test(hostname.replace(/^\[[\da-f:.]+\]$/i, "")))
283
+ return !1;
284
+ if (special && parts.protocol !== "file:" && !hostname)
285
+ return !1;
286
+ parts.hostname = special ? hostname.toLowerCase() : hostname;
287
+ parts.port = port === "" ? "" : String(Number(port));
288
+ if (parts.port === SPECIAL_SCHEMES[parts.protocol])
289
+ parts.port = "";
290
+ return !0;
291
+ }
292
+ static path(path, parts) {
293
+ const special = parts.protocol in SPECIAL_SCHEMES;
294
+ let out = special ? path.replace(/\\/g, "/") : path;
295
+ if (!parts.authority && !out.startsWith("/"))
296
+ return escapeURLPart(out, /[ "<>`]/);
297
+ if (special && !out.startsWith("/"))
298
+ out = `/${out}`;
299
+ return escapeURLPart(removeDotSegments(out), /[ "#<>?`{}]/);
300
+ }
301
+ static finish(parts) {
302
+ const special = parts.protocol in SPECIAL_SCHEMES;
303
+ if (parts.query !== null)
304
+ parts.query = escapeURLPart(parts.query, special ? /[ "#<>']/ : /[ "#<>]/);
305
+ if (parts.fragment !== null)
306
+ parts.fragment = escapeURLPart(parts.fragment, /[ "<>`]/);
307
+ return parts;
308
+ }
309
+ static relative(input, base) {
310
+ const special = base.protocol in SPECIAL_SCHEMES;
311
+ if (!base.authority && !base.pathname.startsWith("/")) {
312
+ if (!input.startsWith("#"))
313
+ return null;
314
+ return { ...base, fragment: escapeURLPart(input.slice(1), /[ "<>`]/) };
315
+ }
316
+ if (special ? /^[/\\]{2}/.test(input) : input.startsWith("//"))
317
+ return NativeURL.absolute(base.protocol, input);
318
+ const parts = { ...base, query: base.query, fragment: null };
319
+ let remaining = input;
320
+ const hashAt = remaining.indexOf("#");
321
+ if (hashAt !== -1) {
322
+ parts.fragment = remaining.slice(hashAt + 1);
323
+ remaining = remaining.slice(0, hashAt);
324
+ }
325
+ const queryAt = remaining.indexOf("?");
326
+ if (queryAt !== -1) {
327
+ parts.query = remaining.slice(queryAt + 1);
328
+ remaining = remaining.slice(0, queryAt);
329
+ } else if (remaining)
330
+ parts.query = null;
331
+ if (remaining) {
332
+ const absolutePath = special ? /^[/\\]/.test(remaining) : remaining.startsWith("/"), directory = base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) || "/";
333
+ parts.pathname = NativeURL.path(absolutePath ? remaining : directory + remaining, parts);
334
+ }
335
+ return NativeURL.finish(parts);
336
+ }
337
+ get protocol() {
338
+ return this.parts.protocol;
339
+ }
340
+ get username() {
341
+ return this.parts.username;
342
+ }
343
+ set username(value) {
344
+ this.parts.username = escapeURLPart(String(value), /[ "#<>?`{}/:;=@[\\\]^|]/);
345
+ }
346
+ get password() {
347
+ return this.parts.password;
348
+ }
349
+ set password(value) {
350
+ this.parts.password = escapeURLPart(String(value), /[ "#<>?`{}/:;=@[\\\]^|]/);
351
+ }
352
+ get hostname() {
353
+ return this.parts.hostname;
354
+ }
355
+ set hostname(value) {
356
+ const special = this.parts.protocol in SPECIAL_SCHEMES, next = String(value);
357
+ if (/[\s#%/:<>?@[\\\]^|]/.test(next) || special && !next)
358
+ return;
359
+ this.parts.hostname = special ? next.toLowerCase() : next;
360
+ }
361
+ get port() {
362
+ return this.parts.port;
363
+ }
364
+ set port(value) {
365
+ const digits = /^\d*/.exec(String(value))[0];
366
+ if (digits === "") {
367
+ if (String(value) === "")
368
+ this.parts.port = "";
369
+ return;
370
+ }
371
+ if (Number(digits) > 65535)
372
+ return;
373
+ const port = String(Number(digits));
374
+ this.parts.port = port === SPECIAL_SCHEMES[this.parts.protocol] ? "" : port;
375
+ }
376
+ get host() {
377
+ return this.parts.port ? `${this.parts.hostname}:${this.parts.port}` : this.parts.hostname;
378
+ }
379
+ set host(value) {
380
+ const parts = { ...this.parts };
381
+ if (NativeURL.authority(parts, String(value), this.parts.protocol in SPECIAL_SCHEMES)) {
382
+ this.parts.hostname = parts.hostname;
383
+ this.parts.port = parts.port;
384
+ }
385
+ }
386
+ get origin() {
387
+ const { protocol } = this.parts;
388
+ return protocol in SPECIAL_SCHEMES && protocol !== "file:" ? `${protocol}//${this.host}` : "null";
389
+ }
390
+ get pathname() {
391
+ return this.parts.pathname;
392
+ }
393
+ set pathname(value) {
394
+ if (!this.parts.authority && !this.parts.pathname.startsWith("/"))
395
+ return;
396
+ this.parts.pathname = NativeURL.path(String(value), this.parts);
397
+ }
398
+ get search() {
399
+ return this.parts.query ? `?${this.parts.query}` : "";
400
+ }
401
+ set search(value) {
402
+ const next = String(value).replace(/^\?/, "");
403
+ this.parts.query = next === "" ? null : NativeURL.finish({ ...this.parts, query: next, fragment: null }).query;
404
+ this.params = null;
405
+ }
406
+ get searchParams() {
407
+ this.params ??= NativeURLSearchParams.linked(this.parts.query ?? "", (query) => {
408
+ this.parts.query = query === "" ? null : query;
409
+ });
410
+ return this.params;
411
+ }
412
+ get hash() {
413
+ return this.parts.fragment ? `#${this.parts.fragment}` : "";
414
+ }
415
+ set hash(value) {
416
+ const next = String(value).replace(/^#/, "");
417
+ this.parts.fragment = next === "" ? null : escapeURLPart(next, /[ "<>`]/);
418
+ }
419
+ get href() {
420
+ const { protocol, username, password, authority, pathname, query, fragment } = this.parts, credentials = username || password ? `${username}${password ? `:${password}` : ""}@` : "";
421
+ return `${protocol}${authority ? `//${credentials}${this.host}` : ""}${pathname}${query === null ? "" : `?${query}`}${fragment === null ? "" : `#${fragment}`}`;
422
+ }
423
+ set href(value) {
424
+ const parts = NativeURL.parts(String(value), null);
425
+ if (!parts)
426
+ throw TypeError(`Invalid URL: ${String(value)}`);
427
+ this.parts = parts;
428
+ this.params = null;
429
+ }
430
+ toString() {
431
+ return this.href;
432
+ }
433
+ toJSON() {
434
+ return this.href;
435
+ }
436
+ }
437
+
438
+ export { NativeURL };
165
439
  export function installJSCGlobals(target = globalThis) {
166
440
  const listeners = new Map, addEventListener = (name, listener) => {
167
441
  const group = listeners.get(name) ?? new Set;
@@ -184,6 +458,7 @@ export function installJSCGlobals(target = globalThis) {
184
458
  target.removeEventListener ??= removeEventListener;
185
459
  target.dispatchEvent ??= dispatchEvent;
186
460
  target.URLSearchParams ??= NativeURLSearchParams;
461
+ target.URL ??= NativeURL;
187
462
  target.TextEncoder ??= NativeTextEncoder;
188
463
  target.TextDecoder ??= NativeTextDecoder;
189
464
  target.performance ??= { now: () => Date.now() };
@@ -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/'. */