@stacksjs/stx 0.2.406 → 0.2.407

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 (211) hide show
  1. package/dist/app-service-worker.d.ts +120 -0
  2. package/dist/chunk-00g9x6w2.js +2 -0
  3. package/dist/chunk-02g67164.js +2 -0
  4. package/dist/chunk-04tgatyy.js +2 -0
  5. package/dist/{chunk-4g4yz97f.js → chunk-0a315nbf.js} +3 -3
  6. package/dist/{chunk-zwb8wv5p.js → chunk-0akydm2d.js} +1 -1
  7. package/dist/{chunk-tfy07tmv.js → chunk-0btmm4m2.js} +1 -1
  8. package/dist/{chunk-g0w8dyat.js → chunk-0c2h69k2.js} +1 -1
  9. package/dist/{chunk-aa4ss5pb.js → chunk-0pkk226n.js} +1 -1
  10. package/dist/{chunk-6de3hczw.js → chunk-0we9nw1d.js} +1 -1
  11. package/dist/chunk-178n9c40.js +2 -0
  12. package/dist/{chunk-2r399td7.js → chunk-1fs9jvpb.js} +1 -1
  13. package/dist/chunk-1hc58sh2.js +2 -0
  14. package/dist/chunk-1q4jrkhw.js +2 -0
  15. package/dist/chunk-1qembpzh.js +2 -0
  16. package/dist/chunk-1qq26zt0.js +2 -0
  17. package/dist/{chunk-7q06md6v.js → chunk-1te8k8gp.js} +1 -1
  18. package/dist/{chunk-jw6s8rkk.js → chunk-1ws3xcea.js} +2 -2
  19. package/dist/{chunk-z9a0ft6h.js → chunk-213jwgpx.js} +1 -1
  20. package/dist/{chunk-1yvx8s3v.js → chunk-26r88x1t.js} +2 -2
  21. package/dist/{chunk-k4x5we49.js → chunk-27fgag95.js} +2 -2
  22. package/dist/chunk-2c6t60vw.js +2 -0
  23. package/dist/{chunk-x7qyx7vn.js → chunk-2fw05hs2.js} +1 -1
  24. package/dist/{chunk-0seyntda.js → chunk-38wvkv3s.js} +1 -1
  25. package/dist/chunk-3w6z6tw9.js +2 -0
  26. package/dist/chunk-3za7m29m.js +2 -0
  27. package/dist/{chunk-ypw4egcv.js → chunk-4m7ajama.js} +1 -1
  28. package/dist/{chunk-g81ymdat.js → chunk-4zcbj36p.js} +2 -2
  29. package/dist/{chunk-yh9apppb.js → chunk-50pszj17.js} +1 -1
  30. package/dist/{chunk-59pakqdv.js → chunk-563shnkz.js} +2 -2
  31. package/dist/{chunk-h1yb87ep.js → chunk-5r4s9s38.js} +2 -2
  32. package/dist/chunk-603x5gb2.js +2 -0
  33. package/dist/{chunk-afwbqeb2.js → chunk-6jrczd12.js} +2 -2
  34. package/dist/{chunk-abs56gdt.js → chunk-6kd5jjwc.js} +1 -1
  35. package/dist/{chunk-ewxbx67c.js → chunk-6kdrncsx.js} +1 -1
  36. package/dist/{chunk-pkspqh0m.js → chunk-72rwcbp6.js} +1 -1
  37. package/dist/{chunk-4m4n1sfc.js → chunk-76w34xne.js} +1 -1
  38. package/dist/chunk-7ypm243n.js +2 -0
  39. package/dist/{chunk-z80v5h5h.js → chunk-8036mdat.js} +2 -2
  40. package/dist/{chunk-46zx4pt8.js → chunk-82pd4b5w.js} +1 -1
  41. package/dist/chunk-8ds7rrdc.js +2 -0
  42. package/dist/chunk-8w2mqdnv.js +2 -0
  43. package/dist/chunk-8x05b790.js +2 -0
  44. package/dist/{chunk-pqhpcxsd.js → chunk-90b2vt2n.js} +1 -1
  45. package/dist/{chunk-arjhs9bb.js → chunk-920779jx.js} +2 -2
  46. package/dist/chunk-934eeghd.js +2 -0
  47. package/dist/{chunk-245ft0zp.js → chunk-9e8t0twa.js} +1 -1
  48. package/dist/{chunk-wpsx5avz.js → chunk-9fqp72ze.js} +1 -1
  49. package/dist/chunk-9wze2290.js +2 -0
  50. package/dist/{chunk-dj658wyq.js → chunk-9xew0kgf.js} +1 -1
  51. package/dist/{chunk-ca57sg6v.js → chunk-akwd34xt.js} +2 -2
  52. package/dist/{chunk-rqr735w8.js → chunk-anydpa34.js} +1 -1
  53. package/dist/{chunk-ffdxdgep.js → chunk-aq1xq0r4.js} +2 -2
  54. package/dist/{chunk-9dap2hdv.js → chunk-avaywwsc.js} +2 -2
  55. package/dist/{chunk-36rnwhn2.js → chunk-bbt3tp6f.js} +1 -1
  56. package/dist/{chunk-n4197kjq.js → chunk-bjar18jd.js} +1 -1
  57. package/dist/{chunk-twg0y6ga.js → chunk-bjcsc6wx.js} +1 -1
  58. package/dist/{chunk-akzmq0jr.js → chunk-bn1edb1y.js} +2 -2
  59. package/dist/{chunk-503wfstj.js → chunk-btd7ds3x.js} +1 -1
  60. package/dist/{chunk-8mm86z5w.js → chunk-bwsxym3d.js} +1 -1
  61. package/dist/{chunk-c1f1vtjt.js → chunk-cj3adc77.js} +1 -1
  62. package/dist/{chunk-sjc7x8y1.js → chunk-cqchpe34.js} +396 -165
  63. package/dist/chunk-ct1jwd4r.js +2 -0
  64. package/dist/{chunk-znt6t1dz.js → chunk-ej16bgrr.js} +2 -2
  65. package/dist/{chunk-2c23jad1.js → chunk-esq1k7fj.js} +2 -2
  66. package/dist/{chunk-ayhhvep9.js → chunk-f6s7d1jq.js} +2 -2
  67. package/dist/{chunk-bds4s9d8.js → chunk-fcnrgxck.js} +1 -1
  68. package/dist/chunk-fphs5g19.js +2 -0
  69. package/dist/{chunk-stdkw5st.js → chunk-fpwzacpm.js} +1 -1
  70. package/dist/chunk-gbmeh7jg.js +3 -0
  71. package/dist/{chunk-81zw5vw5.js → chunk-gc06g35w.js} +1 -1
  72. package/dist/{chunk-rctgq5xp.js → chunk-gcvj5zdy.js} +3 -3
  73. package/dist/{chunk-1nnskved.js → chunk-gengvwb7.js} +3 -3
  74. package/dist/{chunk-63dyh42m.js → chunk-gjrgr367.js} +2 -2
  75. package/dist/{chunk-69c5rv6n.js → chunk-gna6dc48.js} +169 -169
  76. package/dist/{chunk-pyyccs6a.js → chunk-gvbf1mhs.js} +1 -1
  77. package/dist/chunk-h1r17awz.js +2 -0
  78. package/dist/chunk-ha46rg9g.js +2 -0
  79. package/dist/chunk-hcvjstmr.js +2 -0
  80. package/dist/{chunk-a01sf1sc.js → chunk-hdysywd8.js} +1 -1
  81. package/dist/{chunk-55g4qm7m.js → chunk-hx998w7n.js} +1 -1
  82. package/dist/chunk-j3r97xs5.js +2 -0
  83. package/dist/chunk-j5qeaprt.js +2 -0
  84. package/dist/chunk-jxvmf02k.js +2 -0
  85. package/dist/{chunk-8t3h7fsk.js → chunk-k80sn8d1.js} +1 -1
  86. package/dist/chunk-kajym1cx.js +2 -0
  87. package/dist/{chunk-f02g2h4p.js → chunk-kbwhs5df.js} +2 -2
  88. package/dist/{chunk-4n6ekt06.js → chunk-kmsyvaex.js} +1 -1
  89. package/dist/{chunk-4tsjysng.js → chunk-kvmx7dnb.js} +1 -1
  90. package/dist/{chunk-s1gwy2rp.js → chunk-m072c38p.js} +2 -2
  91. package/dist/{chunk-jpnja3jy.js → chunk-mgrckqww.js} +1 -1
  92. package/dist/{chunk-971yqxa2.js → chunk-mq5ewmz6.js} +1 -1
  93. package/dist/{chunk-sptvg80e.js → chunk-mrahwn5v.js} +1 -1
  94. package/dist/{chunk-vyq86x5c.js → chunk-n2swas11.js} +1 -1
  95. package/dist/{chunk-zgzzn9qk.js → chunk-n9cqrw9j.js} +1 -1
  96. package/dist/{chunk-3sea73fx.js → chunk-naw4jt7j.js} +1 -1
  97. package/dist/{chunk-1n2ng8nx.js → chunk-ny67c03k.js} +1 -1
  98. package/dist/chunk-p0m4ty6g.js +2 -0
  99. package/dist/chunk-p32x2apf.js +2 -0
  100. package/dist/{chunk-8bg1qmhg.js → chunk-p4zrvt5f.js} +1 -1
  101. package/dist/{chunk-0tnsyynz.js → chunk-p5wp0ce6.js} +2 -2
  102. package/dist/{chunk-mywrb5fy.js → chunk-pcxp4r9n.js} +1 -1
  103. package/dist/{chunk-me7ypzw9.js → chunk-pdfjy3at.js} +2 -2
  104. package/dist/chunk-pjrn29gg.js +2 -0
  105. package/dist/chunk-q738pwv6.js +2 -0
  106. package/dist/{chunk-w6n5c479.js → chunk-qmmp5kb5.js} +1 -1
  107. package/dist/{chunk-015p3jq5.js → chunk-qn5srnj3.js} +1 -1
  108. package/dist/{chunk-1vrk5y92.js → chunk-qvnbnsv9.js} +1 -1
  109. package/dist/{chunk-z8zmp74b.js → chunk-rt3cx932.js} +1025 -58
  110. package/dist/{chunk-7ba7x6jt.js → chunk-rz9f3zqz.js} +2 -2
  111. package/dist/{chunk-dxjtszaa.js → chunk-s8jd13nb.js} +1 -1
  112. package/dist/{chunk-qem2tw9r.js → chunk-s9za1vvd.js} +1 -1
  113. package/dist/{chunk-r909bddf.js → chunk-spxsw4mp.js} +1 -1
  114. package/dist/chunk-ssn5k77d.js +2 -0
  115. package/dist/chunk-sy9pfe3h.js +2 -0
  116. package/dist/{chunk-0nhpymyy.js → chunk-t1htzg9e.js} +1 -1
  117. package/dist/{chunk-rkzfwgr8.js → chunk-t1tdjjht.js} +1 -1
  118. package/dist/{chunk-1x6c4ys1.js → chunk-t5ja7qkn.js} +131 -34
  119. package/dist/{chunk-rx0cntdm.js → chunk-td08rnk3.js} +2 -2
  120. package/dist/chunk-tgadbsd4.js +2 -0
  121. package/dist/{chunk-xakdgn9h.js → chunk-tgrpp58r.js} +1 -1
  122. package/dist/{chunk-pgeh4g3a.js → chunk-tkyrk66a.js} +1 -1
  123. package/dist/chunk-tpcmn119.js +2 -0
  124. package/dist/{chunk-0n054h7w.js → chunk-v3nwkveg.js} +1 -1
  125. package/dist/{chunk-83tefmh1.js → chunk-vsbmc9kt.js} +1 -1
  126. package/dist/{chunk-qcpnfw0k.js → chunk-vx86cf4r.js} +1 -1
  127. package/dist/{chunk-yn8qq8tn.js → chunk-w6hqh4z5.js} +2 -2
  128. package/dist/{chunk-k3wcezqg.js → chunk-w9n12yzf.js} +3 -3
  129. package/dist/chunk-wkanrfb3.js +2 -0
  130. package/dist/chunk-wvegegmb.js +2 -0
  131. package/dist/{chunk-seqmzr8k.js → chunk-xq1acw1r.js} +1 -1
  132. package/dist/{chunk-vtjegbgy.js → chunk-xsng1mtq.js} +1 -1
  133. package/dist/chunk-xv9bhvye.js +12 -0
  134. package/dist/{chunk-gyccx2pr.js → chunk-z52f4zcy.js} +2 -2
  135. package/dist/{chunk-vtmhh3dp.js → chunk-z5rwnnk1.js} +2 -2
  136. package/dist/{chunk-m8bdy2wt.js → chunk-zcz9rs6p.js} +1 -1
  137. package/dist/{chunk-1phxzej9.js → chunk-zpcnbdhn.js} +2 -2
  138. package/dist/{chunk-wxkn47vk.js → chunk-zq4ssxj9.js} +1 -1
  139. package/dist/cli.js +14 -14
  140. package/dist/composables/index.d.ts +10 -1
  141. package/dist/composables/index.js +6 -1
  142. package/dist/composables/use-cached-query.d.ts +18 -0
  143. package/dist/composables/use-cached-query.js +27 -0
  144. package/dist/composables/use-offline.d.ts +18 -0
  145. package/dist/composables/use-offline.js +17 -0
  146. package/dist/composables/use-outbox.d.ts +19 -27
  147. package/dist/composables/use-outbox.js +100 -16
  148. package/dist/composables/use-query.d.ts +2 -0
  149. package/dist/composables/use-storage.d.ts +7 -3
  150. package/dist/composables/use-storage.js +22 -13
  151. package/dist/craft-entry.js +1 -1
  152. package/dist/craft.js +1 -1
  153. package/dist/database.js +1 -1
  154. package/dist/index.d.ts +10 -0
  155. package/dist/index.js +5 -0
  156. package/dist/offline/app-service-worker.d.ts +61 -13
  157. package/dist/offline/app-service-worker.js +398 -58
  158. package/dist/offline/kept-store.d.ts +67 -0
  159. package/dist/offline/kept-store.js +252 -0
  160. package/dist/offline/query-cache.d.ts +137 -0
  161. package/dist/offline/query-cache.js +260 -0
  162. package/dist/pwa.js +2 -2
  163. package/dist/runtime-globals.js +3 -0
  164. package/dist/signals.js +123 -24
  165. package/dist/ssg.js +2 -2
  166. package/dist/stx-module.d.ts +3 -0
  167. package/dist/stx.d.ts +48 -1
  168. package/dist/unresolved-identifiers.js +2 -0
  169. package/dist/visual-testing.js +1 -1
  170. package/package.json +5 -5
  171. package/stx-module.d.ts +3 -0
  172. package/stx.d.ts +48 -1
  173. package/dist/chunk-4hqaxar9.js +0 -2
  174. package/dist/chunk-4md4tj27.js +0 -3
  175. package/dist/chunk-53x9hrx3.js +0 -2
  176. package/dist/chunk-5e2d3grq.js +0 -2
  177. package/dist/chunk-5s44f83p.js +0 -2
  178. package/dist/chunk-62btdm51.js +0 -2
  179. package/dist/chunk-68gspceh.js +0 -2
  180. package/dist/chunk-6cbjhg0y.js +0 -2
  181. package/dist/chunk-8vg5tpts.js +0 -2
  182. package/dist/chunk-b26mjv83.js +0 -2
  183. package/dist/chunk-bmfg13wx.js +0 -2
  184. package/dist/chunk-ccct2hsa.js +0 -2
  185. package/dist/chunk-d8yksesg.js +0 -2
  186. package/dist/chunk-db6fm81v.js +0 -2
  187. package/dist/chunk-emx4ey5d.js +0 -2
  188. package/dist/chunk-gxc02n32.js +0 -2
  189. package/dist/chunk-hch1t137.js +0 -2
  190. package/dist/chunk-jc5kqj3t.js +0 -2
  191. package/dist/chunk-jqm6tbtb.js +0 -2
  192. package/dist/chunk-k6vz8455.js +0 -2
  193. package/dist/chunk-m7b67r66.js +0 -12
  194. package/dist/chunk-mtata78t.js +0 -2
  195. package/dist/chunk-n1yz08j4.js +0 -2
  196. package/dist/chunk-nsese4as.js +0 -2
  197. package/dist/chunk-pqskmpz0.js +0 -2
  198. package/dist/chunk-qa333652.js +0 -2
  199. package/dist/chunk-qcbn5mrw.js +0 -2
  200. package/dist/chunk-sgmqfphy.js +0 -2
  201. package/dist/chunk-wj66sab5.js +0 -2
  202. package/dist/chunk-wqgyb4zb.js +0 -2
  203. package/dist/chunk-wszdgqe3.js +0 -2
  204. package/dist/chunk-wz7ca99x.js +0 -2
  205. package/dist/chunk-xqz9dqef.js +0 -2
  206. package/dist/chunk-xvsz1qy3.js +0 -2
  207. package/dist/chunk-xw23twxw.js +0 -2
  208. package/dist/chunk-xz870mf2.js +0 -2
  209. package/dist/chunk-y3cz15x3.js +0 -2
  210. package/dist/chunk-yf0v44v8.js +0 -2
  211. package/dist/chunk-zawdn9z8.js +0 -2
@@ -0,0 +1,252 @@
1
+ export function indexedDbBackend(name) {
2
+ let factory = null;
3
+ try {
4
+ factory = typeof indexedDB < "u" ? indexedDB : null;
5
+ } catch {
6
+ factory = null;
7
+ }
8
+ if (!factory)
9
+ return null;
10
+ const idb = factory, dbName = name || "stx-kept";
11
+ let opened = null;
12
+ const open = () => {
13
+ if (!opened) {
14
+ opened = new Promise((resolve, reject) => {
15
+ const request = idb.open(dbName, 1);
16
+ request.onupgradeneeded = () => {
17
+ request.result.createObjectStore("kv");
18
+ };
19
+ request.onsuccess = () => resolve(request.result);
20
+ request.onerror = () => reject(request.error);
21
+ request.onblocked = () => reject(Error("blocked"));
22
+ });
23
+ opened.catch(() => {
24
+ opened = null;
25
+ });
26
+ }
27
+ return opened;
28
+ }, run = (mode, fn) => open().then((db) => new Promise((resolve, reject) => {
29
+ const tx = db.transaction("kv", mode), request = fn(tx.objectStore("kv"));
30
+ tx.oncomplete = () => resolve(request ? request.result : void 0);
31
+ tx.onerror = () => reject(tx.error);
32
+ tx.onabort = () => reject(tx.error);
33
+ }));
34
+ return {
35
+ get: (key) => run("readonly", (store) => store.get(key)),
36
+ set: (key, value) => run("readwrite", (store) => {
37
+ store.put(value, key);
38
+ }),
39
+ remove: (key) => run("readwrite", (store) => {
40
+ store.delete(key);
41
+ }),
42
+ removePrefix: (prefix) => run("readwrite", (store) => {
43
+ store.delete(IDBKeyRange.bound(prefix, `${prefix}\uFFFF`));
44
+ })
45
+ };
46
+ }
47
+ export function createKeptStore(options, openBackend) {
48
+ const opts = options || {};
49
+ let storage = null;
50
+ if (opts.storage !== void 0)
51
+ storage = opts.storage;
52
+ else
53
+ try {
54
+ storage = typeof localStorage < "u" ? localStorage : null;
55
+ } catch {
56
+ storage = null;
57
+ }
58
+ let backend = null, backendOpened = opts.backend !== void 0;
59
+ if (backendOpened)
60
+ backend = opts.backend || null;
61
+ const useBackend = () => {
62
+ if (backendOpened)
63
+ return backend;
64
+ backendOpened = !0;
65
+ try {
66
+ backend = openBackend ? openBackend() : null;
67
+ } catch {
68
+ backend = null;
69
+ }
70
+ if (backend) {
71
+ const probe = backend;
72
+ probe.get("__stx_probe__").catch(() => {
73
+ if (backend === probe)
74
+ backend = null;
75
+ });
76
+ }
77
+ return backend;
78
+ }, limit = opts.limit || 32768, defer = opts.defer || ((fn) => {
79
+ const idle = typeof requestIdleCallback === "function" ? requestIdleCallback : null;
80
+ if (idle)
81
+ idle(fn, { timeout: 200 });
82
+ else
83
+ setTimeout(fn, 16);
84
+ }), memory = new Map, inBackend = new Set, waiting = new Map;
85
+ let scheduled = !1, writes = Promise.resolve();
86
+ const parse = (raw) => {
87
+ try {
88
+ return JSON.parse(raw);
89
+ } catch {
90
+ return raw;
91
+ }
92
+ }, writeStorage = (key, json) => {
93
+ if (!storage)
94
+ return !1;
95
+ try {
96
+ storage.setItem(key, json);
97
+ return !0;
98
+ } catch {
99
+ return !1;
100
+ }
101
+ }, removeStorage = (key) => {
102
+ try {
103
+ if (storage)
104
+ storage.removeItem(key);
105
+ } catch {}
106
+ }, drain = () => {
107
+ scheduled = !1;
108
+ if (!waiting.size)
109
+ return writes;
110
+ const batch = Array.from(waiting.entries());
111
+ waiting.clear();
112
+ writes = writes.then(() => Promise.all(batch.map(([key, value]) => {
113
+ if (!backend) {
114
+ inBackend.delete(key);
115
+ try {
116
+ writeStorage(key, JSON.stringify(value === void 0 ? null : value));
117
+ } catch {}
118
+ return;
119
+ }
120
+ let record;
121
+ try {
122
+ record = { v: value };
123
+ return backend.set(key, record).catch(() => {
124
+ let json;
125
+ try {
126
+ json = JSON.stringify(value);
127
+ } catch {
128
+ return;
129
+ }
130
+ return backend ? backend.set(key, { j: json }).catch(() => {
131
+ writeStorage(key, json);
132
+ }) : void 0;
133
+ });
134
+ } catch {
135
+ return;
136
+ }
137
+ }))).then(() => {});
138
+ return writes;
139
+ }, schedule = (key, value) => {
140
+ waiting.set(key, value);
141
+ inBackend.add(key);
142
+ if (scheduled)
143
+ return;
144
+ scheduled = !0;
145
+ defer(() => {
146
+ drain();
147
+ });
148
+ }, unwrap = (record) => {
149
+ if (!record || typeof record !== "object")
150
+ return;
151
+ const r = record;
152
+ if ("v" in r)
153
+ return { value: r.v };
154
+ if (typeof r.j === "string")
155
+ return { value: parse(r.j) };
156
+ return;
157
+ }, store = {
158
+ peek(key) {
159
+ if (memory.has(key))
160
+ return { value: memory.get(key) };
161
+ let raw = null;
162
+ try {
163
+ raw = storage ? storage.getItem(key) : null;
164
+ } catch {
165
+ raw = null;
166
+ }
167
+ if (raw === null || raw === void 0)
168
+ return;
169
+ const value = parse(raw);
170
+ memory.set(key, value);
171
+ return { value };
172
+ },
173
+ load(key) {
174
+ const hit = store.peek(key), from = hit ? null : useBackend();
175
+ if (hit || !from)
176
+ return Promise.resolve(hit);
177
+ return from.get(key).then((record) => {
178
+ if (memory.has(key))
179
+ return { value: memory.get(key) };
180
+ const found = unwrap(record);
181
+ if (found) {
182
+ memory.set(key, found.value);
183
+ inBackend.add(key);
184
+ }
185
+ return found;
186
+ }, () => {
187
+ return;
188
+ });
189
+ },
190
+ set(key, value) {
191
+ memory.set(key, value);
192
+ if (backend && inBackend.has(key)) {
193
+ schedule(key, value);
194
+ return;
195
+ }
196
+ let json;
197
+ try {
198
+ json = JSON.stringify(value === void 0 ? null : value);
199
+ } catch {
200
+ return;
201
+ }
202
+ if (json.length <= limit && writeStorage(key, json))
203
+ return;
204
+ if (!useBackend()) {
205
+ if (json.length > limit)
206
+ writeStorage(key, json);
207
+ return;
208
+ }
209
+ removeStorage(key);
210
+ schedule(key, value);
211
+ },
212
+ forget(prefix) {
213
+ for (const key of Array.from(memory.keys()))
214
+ if (key.indexOf(prefix) === 0)
215
+ memory.delete(key);
216
+ for (const key of Array.from(waiting.keys()))
217
+ if (key.indexOf(prefix) === 0)
218
+ waiting.delete(key);
219
+ for (const key of Array.from(inBackend))
220
+ if (key.indexOf(prefix) === 0)
221
+ inBackend.delete(key);
222
+ try {
223
+ if (storage)
224
+ for (let i = storage.length - 1;i >= 0; i--) {
225
+ const key = storage.key(i);
226
+ if (key && key.indexOf(prefix) === 0)
227
+ storage.removeItem(key);
228
+ }
229
+ } catch {}
230
+ const gone = useBackend();
231
+ if (!gone)
232
+ return writes;
233
+ writes = writes.then(() => gone.removePrefix(prefix)).catch(() => {});
234
+ return writes;
235
+ },
236
+ flush() {
237
+ return drain();
238
+ }
239
+ };
240
+ try {
241
+ if (typeof document < "u" && document.addEventListener)
242
+ document.addEventListener("visibilitychange", () => {
243
+ if (document.visibilityState === "hidden")
244
+ drain();
245
+ });
246
+ if (typeof addEventListener === "function")
247
+ addEventListener("pagehide", () => {
248
+ drain();
249
+ });
250
+ } catch {}
251
+ return store;
252
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Persisted queries: data a screen shows at once from last time, refreshed
3
+ * behind, kept per signed-in account.
4
+ *
5
+ * The phone app's stores each did this by hand: a `keptState` for the data,
6
+ * a `loadedAt` to decide whether to fetch again, a flag against two screens
7
+ * fetching at once, and nothing to tell them when the offline worker had a
8
+ * newer answer or when a write waiting in the outbox should still show. A
9
+ * cached query is that, once:
10
+ *
11
+ * - seeded synchronously from the kept store (`keptState`'s storage, per
12
+ * account scope), so the first draw has data;
13
+ * - fetched again behind when older than `staleTime` (a copy kept from an
14
+ * earlier launch is always revalidated once), one request for every caller;
15
+ * - kept again after every answer;
16
+ * - refreshed when the offline worker says the API answer changed
17
+ * (`stx:updated` { kind: 'api', url });
18
+ * - shown with the outbox's waiting writes applied on top (`affects` /
19
+ * `apply` on an outbox entry), so a change made offline never disappears
20
+ * when the data is fetched again before it synced.
21
+ *
22
+ * Closure-free: the browser runtime embeds `createQueryCache` and
23
+ * `queryTargetMatches` by source (signals.ts), so neither may use anything
24
+ * from this module's scope. The signal implementation and the kept store are
25
+ * passed in.
26
+ */
27
+ import type { KeptStore } from './kept-store';
28
+ /** The part of a signal this needs. */
29
+ export interface QuerySignal<T> {
30
+ (): T;
31
+ set: (value: T) => void;
32
+ }
33
+ export type KeptScope = string | number | false | null | undefined;
34
+ /** What a query is known by: its key, and the URL it reads, when it has one. */
35
+ export interface QueryTarget {
36
+ key: string;
37
+ url?: string | null;
38
+ }
39
+ export interface CachedQueryOptions<T> {
40
+ /** The URL to GET (or a function giving it). Answered as JSON. */
41
+ url?: string | (() => string | null | undefined);
42
+ /** Load the data some other way than a GET of `url`. */
43
+ load?: (context: {
44
+ force: boolean;
45
+ url: string | null;
46
+ signal?: AbortSignal;
47
+ }) => Promise<T>;
48
+ /** How to send the GET: give it current credentials here (default `fetch`). */
49
+ fetch?: (url: string, init: RequestInit) => Promise<Response>;
50
+ /**
51
+ * Whose data this is, as for `keptState`: the signed-in account's id, or a
52
+ * function returning it (read at every load, so signing in as someone else
53
+ * swaps the data). `false`, `null` or `''` keeps nothing on the device.
54
+ * Default: the scope given to `setKeptScope`.
55
+ */
56
+ scope?: KeptScope | (() => KeptScope);
57
+ /** How long an answer counts as fresh, ms: `load()` within it does not fetch. Default 0. */
58
+ staleTime?: number;
59
+ /** The value before anything was kept or fetched. Default null. */
60
+ initial?: T;
61
+ /** Shape the answer before it is kept and shown. */
62
+ transform?: (raw: any) => T;
63
+ /** Give up on a request after this long, ms (the data stays). Default 15000. */
64
+ timeoutMs?: number;
65
+ /** Fetch when created, rather than at the first `load()`. */
66
+ immediate?: boolean;
67
+ }
68
+ export interface CachedQuery<T> {
69
+ /** What to show: the last answer, with writes still waiting in the outbox applied. */
70
+ data: QuerySignal<T>;
71
+ /** True while fetching with nothing to show yet. */
72
+ loading: QuerySignal<boolean>;
73
+ /** True while any request is out, a background one included. */
74
+ isFetching: QuerySignal<boolean>;
75
+ /** The last request's error message, cleared by the next answer. */
76
+ error: QuerySignal<string | null>;
77
+ /** When the data shown was fetched (ms), from this launch or a kept one; 0 for none. */
78
+ updatedAt: QuerySignal<number>;
79
+ /** Fetch when older than `staleTime` (or always, with `force`). Every caller shares one request. */
80
+ load: (force?: boolean) => Promise<T>;
81
+ /** Fetch now, past any cache: a pull to refresh. */
82
+ refresh: () => Promise<T>;
83
+ /** Replace the data here (an edit made on this device), kept like an answer. */
84
+ set: (value: T | ((current: T) => T)) => void;
85
+ /** Count the data as stale, so the next `load()` fetches. */
86
+ invalidate: () => void;
87
+ readonly key: string;
88
+ }
89
+ export interface QueryCacheEnv {
90
+ state: <T>(value: T) => QuerySignal<T>;
91
+ kept: KeptStore;
92
+ /** Where kept values live, as `keptState` names them. Default 'stx:kept:'. */
93
+ prefix?: string;
94
+ /** Listen for `stx:updated` and `stx:outbox` on window. Default true. */
95
+ listen?: boolean;
96
+ matches?: (item: string, target: QueryTarget) => boolean;
97
+ }
98
+ export interface QueryWatcher {
99
+ target: () => QueryTarget;
100
+ /** The worker has a newer answer for this query's URL. */
101
+ updated: () => void;
102
+ /** The outbox changed. `sent` is an entry that just reached the server. */
103
+ outbox: (sent: {
104
+ id: string;
105
+ affects?: string[];
106
+ } | null) => void;
107
+ }
108
+ export interface QueryCache {
109
+ cachedQuery: <T>(key: string, options?: CachedQueryOptions<T>) => CachedQuery<T>;
110
+ /** The account scope queries (and kept state) use when given none. */
111
+ setScope: (scope: KeptScope) => void;
112
+ scope: () => KeptScope;
113
+ /** The kept-store key of a query's data in a scope, or null when that scope keeps nothing. */
114
+ keyFor: (key: string, scope?: KeptScope) => string | null;
115
+ /** A kept answer, synchronously, or undefined. */
116
+ seed: (key: string, scope?: KeptScope) => {
117
+ data: unknown;
118
+ at: number;
119
+ } | undefined;
120
+ /** A kept answer, from anywhere it is kept. */
121
+ restore: (key: string, scope?: KeptScope) => Promise<{
122
+ data: unknown;
123
+ at: number;
124
+ } | undefined>;
125
+ persist: (key: string, data: unknown, scope?: KeptScope) => void;
126
+ /** `data` with the outbox's waiting writes for this target applied (only entry `onlyId`, when given). */
127
+ overlay: <T>(target: QueryTarget, data: T, onlyId?: string) => T;
128
+ watch: (watcher: QueryWatcher) => () => void;
129
+ }
130
+ /**
131
+ * Whether an outbox entry's `affects` item, or a URL the worker refreshed,
132
+ * names this query: its key, or its URL (an item without a query string
133
+ * matches the URL's path with any). Closure-free.
134
+ */
135
+ export declare function queryTargetMatches(item: string, target: QueryTarget): boolean;
136
+ /** The query layer, for one page. Closure-free. */
137
+ export declare function createQueryCache(env: QueryCacheEnv): QueryCache;
@@ -0,0 +1,260 @@
1
+ export function queryTargetMatches(item, target) {
2
+ if (!item)
3
+ return !1;
4
+ if (item === target.key)
5
+ return !0;
6
+ if (!target.url)
7
+ return !1;
8
+ if (item === target.url)
9
+ return !0;
10
+ try {
11
+ const base = typeof location < "u" && location.origin && location.origin !== "null" ? location.origin : "http://localhost", a = new URL(item, base), b = new URL(target.url, base);
12
+ if (a.origin !== b.origin || a.pathname !== b.pathname)
13
+ return !1;
14
+ return !a.search || a.search === b.search;
15
+ } catch {
16
+ return !1;
17
+ }
18
+ }
19
+ export function createQueryCache(env) {
20
+ const prefix = env.prefix || "stx:kept:", matches = env.matches || ((item, target) => item === target.key || item === target.url), watchers = new Set, queries = new Map;
21
+ let defaultScope;
22
+ const resolveScope = (scope) => scope === void 0 ? defaultScope : scope, keyFor = (key, scope) => {
23
+ const s = resolveScope(scope);
24
+ if (s === !1 || s === null || s === "")
25
+ return null;
26
+ return `${prefix}${s === void 0 ? "" : `${s}:`}query:${key}`;
27
+ }, unpack = (found) => {
28
+ const record = found && found.value;
29
+ if (!record || typeof record !== "object" || !("d" in record))
30
+ return;
31
+ return { data: record.d, at: Number(record.at) || 0 };
32
+ }, outboxes = () => {
33
+ const g = globalThis;
34
+ return g.__stx_outboxes instanceof Map ? g.__stx_outboxes : null;
35
+ }, cache = {
36
+ setScope(scope) {
37
+ defaultScope = scope;
38
+ },
39
+ scope: () => defaultScope,
40
+ keyFor,
41
+ seed(key, scope) {
42
+ const at = keyFor(key, scope);
43
+ return at ? unpack(env.kept.peek(at)) : void 0;
44
+ },
45
+ restore(key, scope) {
46
+ const at = keyFor(key, scope);
47
+ return at ? env.kept.load(at).then(unpack) : Promise.resolve(void 0);
48
+ },
49
+ persist(key, data, scope) {
50
+ const at = keyFor(key, scope);
51
+ if (at)
52
+ env.kept.set(at, { d: data, at: Date.now() });
53
+ },
54
+ overlay(target, data, onlyId) {
55
+ const boxes = outboxes();
56
+ if (!boxes || !boxes.size)
57
+ return data;
58
+ let out = data;
59
+ boxes.forEach((box) => {
60
+ try {
61
+ out = box.overlay(target, out, onlyId);
62
+ } catch {}
63
+ });
64
+ return out;
65
+ },
66
+ watch(watcher) {
67
+ watchers.add(watcher);
68
+ return () => {
69
+ watchers.delete(watcher);
70
+ };
71
+ },
72
+ cachedQuery(key, options) {
73
+ const existing = queries.get(key);
74
+ if (existing) {
75
+ if (options && existing.__options)
76
+ existing.__options(options);
77
+ return existing;
78
+ }
79
+ let opts = options || {};
80
+ const initial = opts.initial === void 0 ? null : opts.initial, scopeNow = () => typeof opts.scope === "function" ? opts.scope() : opts.scope, urlNow = () => {
81
+ return (typeof opts.url === "function" ? opts.url() : opts.url) || null;
82
+ }, target = () => ({ key, url: urlNow() });
83
+ let scope = scopeNow(), base = initial, fetchedAt = 0, inflight = null;
84
+ const seeded = cache.seed(key, scope);
85
+ if (seeded)
86
+ base = seeded.data;
87
+ const data = env.state(cache.overlay(target(), base)), loading = env.state(!1), isFetching = env.state(!1), error = env.state(null), updatedAt = env.state(seeded ? seeded.at : 0);
88
+ let generation = 0;
89
+ const show = () => {
90
+ data.set(cache.overlay(target(), base));
91
+ }, restoreFrom = (from) => {
92
+ const asked = generation;
93
+ cache.restore(key, from).then((found) => {
94
+ if (!found || asked !== generation || fetchedAt)
95
+ return;
96
+ base = found.data;
97
+ updatedAt.set(found.at);
98
+ show();
99
+ });
100
+ };
101
+ if (!seeded)
102
+ restoreFrom(scope);
103
+ const followScope = () => {
104
+ const now = scopeNow();
105
+ if (now === scope)
106
+ return;
107
+ scope = now;
108
+ generation++;
109
+ inflight = null;
110
+ fetchedAt = 0;
111
+ const found = cache.seed(key, scope);
112
+ base = found ? found.data : initial;
113
+ updatedAt.set(found ? found.at : 0);
114
+ show();
115
+ if (!found)
116
+ restoreFrom(scope);
117
+ }, request = (force) => {
118
+ const url = urlNow(), timeout = opts.timeoutMs || 15000, controller = typeof AbortController < "u" ? new AbortController : null;
119
+ let timer = null;
120
+ const expired = new Promise((_, reject) => {
121
+ timer = setTimeout(() => {
122
+ if (controller)
123
+ controller.abort();
124
+ reject(Error("The request took too long."));
125
+ }, timeout);
126
+ });
127
+ let work;
128
+ if (opts.load)
129
+ work = opts.load({ force, url, signal: controller ? controller.signal : void 0 });
130
+ else if (url) {
131
+ const send = opts.fetch || ((u, init) => fetch(u, init)), init = { method: "GET", headers: { Accept: "application/json" } };
132
+ if (force)
133
+ init.cache = "no-cache";
134
+ if (controller)
135
+ init.signal = controller.signal;
136
+ work = send(url, init).then((response) => {
137
+ if (!response.ok)
138
+ return response.json().catch(() => null).then((body) => {
139
+ throw Error(body && (body.error || body.message) || `Request failed (${response.status})`);
140
+ });
141
+ return response.json();
142
+ });
143
+ } else
144
+ return Promise.resolve(data());
145
+ return Promise.race([work, expired]).then((raw) => {
146
+ if (timer)
147
+ clearTimeout(timer);
148
+ return opts.transform ? opts.transform(raw) : raw;
149
+ }, (cause) => {
150
+ if (timer)
151
+ clearTimeout(timer);
152
+ throw cause;
153
+ });
154
+ }, run = (force) => {
155
+ if (inflight)
156
+ return inflight;
157
+ const asked = generation;
158
+ isFetching.set(!0);
159
+ if (fetchedAt === 0 && !updatedAt())
160
+ loading.set(!0);
161
+ const done = () => {
162
+ if (asked !== generation)
163
+ return;
164
+ inflight = null;
165
+ isFetching.set(!1);
166
+ loading.set(!1);
167
+ }, promise = request(force).then((value) => {
168
+ if (asked !== generation)
169
+ return data();
170
+ base = value;
171
+ fetchedAt = Date.now();
172
+ updatedAt.set(fetchedAt);
173
+ error.set(null);
174
+ cache.persist(key, value, scope);
175
+ show();
176
+ done();
177
+ return data();
178
+ }, (cause) => {
179
+ if (asked === generation)
180
+ error.set(cause && cause.message ? cause.message : "Could not load.");
181
+ done();
182
+ return data();
183
+ });
184
+ inflight = promise;
185
+ return promise;
186
+ }, query = {
187
+ data,
188
+ loading,
189
+ isFetching,
190
+ error,
191
+ updatedAt,
192
+ get key() {
193
+ return key;
194
+ },
195
+ load(force) {
196
+ followScope();
197
+ if (!force && fetchedAt && Date.now() - fetchedAt < (opts.staleTime || 0))
198
+ return Promise.resolve(data());
199
+ return run(!!force);
200
+ },
201
+ refresh() {
202
+ return query.load(!0);
203
+ },
204
+ set(value) {
205
+ base = typeof value === "function" ? value(base) : value;
206
+ cache.persist(key, base, scope);
207
+ show();
208
+ },
209
+ invalidate() {
210
+ fetchedAt = 0;
211
+ },
212
+ __options(next) {
213
+ opts = { ...opts, ...next };
214
+ }
215
+ };
216
+ watchers.add({
217
+ target,
218
+ updated: () => {
219
+ if (fetchedAt || updatedAt())
220
+ run(!1);
221
+ },
222
+ outbox: (sent) => {
223
+ if (sent) {
224
+ base = cache.overlay(target(), base, sent.id);
225
+ fetchedAt = 0;
226
+ run(!0);
227
+ }
228
+ show();
229
+ }
230
+ });
231
+ queries.set(key, query);
232
+ if (opts.immediate)
233
+ query.load();
234
+ return query;
235
+ }
236
+ }, events = typeof window < "u" ? window : typeof addEventListener === "function" ? globalThis : null;
237
+ if (env.listen !== !1 && events && typeof events.addEventListener === "function") {
238
+ events.addEventListener("stx:updated", (event) => {
239
+ const detail = event.detail || {};
240
+ if (detail.kind !== "api" || typeof detail.url !== "string")
241
+ return;
242
+ watchers.forEach((watcher) => {
243
+ if (matches(detail.url, watcher.target()))
244
+ watcher.updated();
245
+ });
246
+ });
247
+ events.addEventListener("stx:outbox", (event) => {
248
+ const detail = event.detail || {}, sent = detail.sent && typeof detail.sent.id === "string" ? detail.sent : null;
249
+ watchers.forEach((watcher) => {
250
+ if (sent) {
251
+ const affects = Array.isArray(sent.affects) ? sent.affects : [], t = watcher.target();
252
+ if (!affects.some((item) => matches(item, t)))
253
+ return;
254
+ }
255
+ watcher.outbox(sent);
256
+ });
257
+ });
258
+ }
259
+ return cache;
260
+ }
package/dist/pwa.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // @bun
2
- import{Kk as wq,Lk as dq,Mk as Cq,Nk as mq,Ok as gq}from"./chunk-4n6ekt06.js";import{$k as Oq,Pk as S,Qk as Tq,Rk as _q,Sk as z,Tk as D,Uk as P,Vk as kq,Wk as vq,Xk as w,Yk as Iq,Zk as d,_k as Hq,al as Mq}from"./chunk-jw6s8rkk.js";import{Qw as Aq,Rw as bq,Sw as Sq,Tw as zq,Uw as Dq,Vw as Pq}from"./chunk-qcpnfw0k.js";import"./chunk-59pakqdv.js";import{bx as N}from"./chunk-x7qyx7vn.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-hch1t137.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>
2
+ import{Rk as wq,Sk as dq,Tk as Cq,Uk as mq,Vk as gq}from"./chunk-kmsyvaex.js";import{$k as P,Wk as S,Xk as Tq,Yk as _q,Zk as z,_k as D,al as kq,bl as vq,cl as w,dl as Iq,el as d,fl as Hq,gl as Oq,hl as Mq}from"./chunk-1ws3xcea.js";import{$w as Dq,Xw as Aq,Yw as bq,Zw as Sq,_w as zq,ax as Pq}from"./chunk-vx86cf4r.js";import"./chunk-563shnkz.js";import{ix as N}from"./chunk-2fw05hs2.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-kajym1cx.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">