@krate/runtime 0.5.0-rc.1 → 0.5.0-rc.10

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 (214) hide show
  1. package/dist/action-context.js +1 -1
  2. package/dist/actions.d.ts +7 -0
  3. package/dist/actions.js +34 -10
  4. package/dist/after.d.ts +28 -0
  5. package/dist/after.js +48 -0
  6. package/dist/assets-static.d.ts +10 -1
  7. package/dist/assets-static.js +10 -2
  8. package/dist/base-path.d.ts +7 -0
  9. package/dist/base-path.js +20 -0
  10. package/dist/boundary.js +1 -1
  11. package/dist/builtin-tags.d.ts +12 -0
  12. package/dist/builtin-tags.js +42 -0
  13. package/dist/cache-adapter.js +1 -1
  14. package/dist/cache-scope.d.ts +8 -0
  15. package/dist/cache-scope.js +14 -1
  16. package/dist/cloudflare-workers.d.ts +2 -0
  17. package/dist/cloudflare-workers.js +27 -0
  18. package/dist/context.d.ts +5 -0
  19. package/dist/context.js +28 -17
  20. package/dist/dev-overlay.d.ts +54 -3
  21. package/dist/dev-overlay.js +470 -77
  22. package/dist/dom.js +18 -3
  23. package/dist/effects.js +2 -2
  24. package/dist/flight-props.d.ts +7 -0
  25. package/dist/flight-props.js +105 -0
  26. package/dist/handler-html.js +4 -4
  27. package/dist/handler-routing.d.ts +2 -23
  28. package/dist/handler-routing.js +9 -190
  29. package/dist/handler-segments.d.ts +6 -0
  30. package/dist/handler-segments.js +18 -4
  31. package/dist/head-tags.d.ts +9 -0
  32. package/dist/head-tags.js +93 -6
  33. package/dist/highlight-bind.js +1 -1
  34. package/dist/highlight.d.ts +3 -2
  35. package/dist/highlight.js +17 -12
  36. package/dist/hints.d.ts +25 -2
  37. package/dist/hints.js +147 -74
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +3 -0
  40. package/dist/island-swap.d.ts +47 -0
  41. package/dist/island-swap.js +635 -0
  42. package/dist/jsx-dev-runtime.d.ts +1 -1
  43. package/dist/jsx-types.d.ts +99 -3
  44. package/dist/krate-core.js +1 -1
  45. package/dist/krate-dev.js +385 -66
  46. package/dist/krate-f-actions.js +1 -1
  47. package/dist/krate-f-classes.js +1 -1
  48. package/dist/krate-f-highlight.js +1 -1
  49. package/dist/krate-f-list.js +1 -1
  50. package/dist/krate-f-navigation.js +1 -1
  51. package/dist/krate-f-router-lite.js +1 -1
  52. package/dist/krate-f-router.js +1 -1
  53. package/dist/krate-features.json +454 -0
  54. package/dist/krate-hydrate-lite.js +5 -5
  55. package/dist/krate-hydrate.js +5 -5
  56. package/dist/krate-island-swap.js +1 -0
  57. package/dist/krate-runtime.js +5 -5
  58. package/dist/list.d.ts +14 -4
  59. package/dist/list.js +4 -5
  60. package/dist/metadata.js +5 -2
  61. package/dist/navigation-react.d.ts +13 -0
  62. package/dist/navigation-react.js +86 -0
  63. package/dist/navigation.d.ts +19 -0
  64. package/dist/navigation.js +35 -0
  65. package/dist/node-server.js +3 -3
  66. package/dist/og.js +1 -1
  67. package/dist/platform.d.ts +52 -0
  68. package/dist/platform.js +57 -0
  69. package/dist/react-compat.d.ts +39 -0
  70. package/dist/react-compat.js +359 -0
  71. package/dist/react-server.d.ts +63 -0
  72. package/dist/react-server.js +125 -0
  73. package/dist/region-wire.d.ts +10 -0
  74. package/dist/region-wire.js +154 -0
  75. package/dist/request-context.js +1 -1
  76. package/dist/request-extras.d.ts +4 -0
  77. package/dist/request-extras.js +51 -0
  78. package/dist/resp.js +1 -1
  79. package/dist/route-source.d.ts +39 -0
  80. package/dist/route-source.js +532 -0
  81. package/dist/router-lite.js +3 -9
  82. package/dist/router.d.ts +1 -1
  83. package/dist/router.js +628 -98
  84. package/dist/server-handler.d.ts +69 -1
  85. package/dist/server-handler.js +515 -96
  86. package/dist/server-renderer.js +16 -7
  87. package/dist/server.d.ts +73 -16
  88. package/dist/server.js +619 -102
  89. package/dist/sha256.js +9 -9
  90. package/dist/signal.js +0 -6
  91. package/dist/site-config.d.ts +15 -0
  92. package/dist/site-config.js +28 -0
  93. package/dist/slot.d.ts +12 -0
  94. package/dist/slot.js +23 -0
  95. package/dist/ssr-core.d.ts +2 -0
  96. package/dist/ssr-core.js +12 -4
  97. package/dist/testing.d.ts +62 -0
  98. package/dist/testing.js +90 -0
  99. package/dist/use-id.js +1 -1
  100. package/package.json +28 -3
  101. package/dist/action-context.test.d.ts +0 -1
  102. package/dist/action-context.test.js +0 -72
  103. package/dist/actions.test.d.ts +0 -1
  104. package/dist/actions.test.js +0 -477
  105. package/dist/cache-adapter.test.d.ts +0 -1
  106. package/dist/cache-adapter.test.js +0 -244
  107. package/dist/cache.test.d.ts +0 -1
  108. package/dist/cache.test.js +0 -233
  109. package/dist/class-component.test.d.ts +0 -1
  110. package/dist/class-component.test.js +0 -462
  111. package/dist/class-helpers.test.d.ts +0 -1
  112. package/dist/class-helpers.test.js +0 -169
  113. package/dist/context.test.d.ts +0 -1
  114. package/dist/context.test.js +0 -57
  115. package/dist/derived.test.d.ts +0 -1
  116. package/dist/derived.test.js +0 -140
  117. package/dist/dev-overlay.test.d.ts +0 -1
  118. package/dist/dev-overlay.test.js +0 -165
  119. package/dist/discrete.test.d.ts +0 -1
  120. package/dist/discrete.test.js +0 -100
  121. package/dist/dom.test.d.ts +0 -1
  122. package/dist/dom.test.js +0 -39
  123. package/dist/effect-errors.test.d.ts +0 -1
  124. package/dist/effect-errors.test.js +0 -199
  125. package/dist/effects.test.d.ts +0 -1
  126. package/dist/effects.test.js +0 -485
  127. package/dist/events.test.d.ts +0 -1
  128. package/dist/events.test.js +0 -447
  129. package/dist/handler-html.test.d.ts +0 -1
  130. package/dist/handler-html.test.js +0 -256
  131. package/dist/handler-routing.test.d.ts +0 -1
  132. package/dist/handler-routing.test.js +0 -99
  133. package/dist/handler-segments.test.d.ts +0 -1
  134. package/dist/handler-segments.test.js +0 -217
  135. package/dist/head-tags.test.d.ts +0 -1
  136. package/dist/head-tags.test.js +0 -131
  137. package/dist/highlight-bind.test.d.ts +0 -1
  138. package/dist/highlight-bind.test.js +0 -124
  139. package/dist/highlight.test.d.ts +0 -1
  140. package/dist/highlight.test.js +0 -56
  141. package/dist/lanes.test.d.ts +0 -1
  142. package/dist/lanes.test.js +0 -59
  143. package/dist/list.test.d.ts +0 -1
  144. package/dist/list.test.js +0 -435
  145. package/dist/metadata.test.d.ts +0 -1
  146. package/dist/metadata.test.js +0 -167
  147. package/dist/navigation.test.d.ts +0 -1
  148. package/dist/navigation.test.js +0 -130
  149. package/dist/node-server.test.d.ts +0 -1
  150. package/dist/node-server.test.js +0 -492
  151. package/dist/optimistic-lanes.test.d.ts +0 -1
  152. package/dist/optimistic-lanes.test.js +0 -45
  153. package/dist/patterns.test.d.ts +0 -1
  154. package/dist/patterns.test.js +0 -125
  155. package/dist/portal.test.d.ts +0 -1
  156. package/dist/portal.test.js +0 -99
  157. package/dist/react-effects.test.d.ts +0 -1
  158. package/dist/react-effects.test.js +0 -133
  159. package/dist/react-suspense.test.d.ts +0 -1
  160. package/dist/react-suspense.test.js +0 -194
  161. package/dist/react.test.d.ts +0 -1
  162. package/dist/react.test.js +0 -60
  163. package/dist/react19.test.d.ts +0 -1
  164. package/dist/react19.test.js +0 -176
  165. package/dist/reactivity-core.test.d.ts +0 -1
  166. package/dist/reactivity-core.test.js +0 -152
  167. package/dist/reconcile.test.d.ts +0 -1
  168. package/dist/reconcile.test.js +0 -110
  169. package/dist/refs.test.d.ts +0 -1
  170. package/dist/refs.test.js +0 -257
  171. package/dist/router-layout.test.d.ts +0 -1
  172. package/dist/router-layout.test.js +0 -249
  173. package/dist/router-nav.test.d.ts +0 -1
  174. package/dist/router-nav.test.js +0 -559
  175. package/dist/router-slots.test.d.ts +0 -1
  176. package/dist/router-slots.test.js +0 -144
  177. package/dist/router-speculation.test.d.ts +0 -1
  178. package/dist/router-speculation.test.js +0 -25
  179. package/dist/router-styles.test.d.ts +0 -1
  180. package/dist/router-styles.test.js +0 -98
  181. package/dist/router.test.d.ts +0 -1
  182. package/dist/router.test.js +0 -36
  183. package/dist/server-async.test.d.ts +0 -1
  184. package/dist/server-async.test.js +0 -216
  185. package/dist/server-handler.test.d.ts +0 -1
  186. package/dist/server-handler.test.js +0 -535
  187. package/dist/server-highlight.test.d.ts +0 -1
  188. package/dist/server-highlight.test.js +0 -32
  189. package/dist/server-renderer.test.d.ts +0 -1
  190. package/dist/server-renderer.test.js +0 -266
  191. package/dist/server.test.d.ts +0 -1
  192. package/dist/server.test.js +0 -88
  193. package/dist/sha256.test.d.ts +0 -1
  194. package/dist/sha256.test.js +0 -13
  195. package/dist/signal-lanes.test.d.ts +0 -1
  196. package/dist/signal-lanes.test.js +0 -32
  197. package/dist/signal.test.d.ts +0 -1
  198. package/dist/signal.test.js +0 -68
  199. package/dist/slots.test.d.ts +0 -1
  200. package/dist/slots.test.js +0 -187
  201. package/dist/snapshots.test.d.ts +0 -1
  202. package/dist/snapshots.test.js +0 -208
  203. package/dist/ssr-core-behavior.test.d.ts +0 -1
  204. package/dist/ssr-core-behavior.test.js +0 -620
  205. package/dist/ssr-core.test.d.ts +0 -1
  206. package/dist/ssr-core.test.js +0 -324
  207. package/dist/static-memory.test.d.ts +0 -1
  208. package/dist/static-memory.test.js +0 -26
  209. package/dist/storage.test.d.ts +0 -1
  210. package/dist/storage.test.js +0 -46
  211. package/dist/suspense-actions.test.d.ts +0 -1
  212. package/dist/suspense-actions.test.js +0 -72
  213. package/dist/suspense.test.d.ts +0 -1
  214. package/dist/suspense.test.js +0 -556
package/dist/krate-dev.js CHANGED
@@ -1,11 +1,42 @@
1
1
  var __krate_exports = (() => {
2
+ // src/site-config.ts
3
+ var CFG_BLOCK_ID = "__krate_cfg__";
4
+ function siteConfig() {
5
+ const g = globalThis;
6
+ if (g.__KRATE_CFG__) return g.__KRATE_CFG__;
7
+ const doc = g.document;
8
+ const el = doc && typeof doc.getElementById === "function" ? doc.getElementById(CFG_BLOCK_ID) : null;
9
+ if (el) {
10
+ try {
11
+ const parsed = JSON.parse(el.textContent || "{}");
12
+ if (parsed && typeof parsed === "object") {
13
+ g.__KRATE_CFG__ = parsed;
14
+ return parsed;
15
+ }
16
+ } catch {
17
+ }
18
+ }
19
+ return {};
20
+ }
21
+
2
22
  // src/dev-overlay.ts
23
+ function isNativeOrigin() {
24
+ try {
25
+ return location.protocol === "krate:" || location.origin === "https://app.localhost";
26
+ } catch {
27
+ return false;
28
+ }
29
+ }
3
30
  function devConfig() {
4
31
  const raw = window.__KRATE_DEV__;
5
- const runtime = window.__KRATE_CFG__;
32
+ const runtime = siteConfig();
33
+ const native = isNativeOrigin();
6
34
  return {
7
35
  sse: raw?.sse ?? "/__krate/hotreload",
8
- errors: raw?.errors ?? "/__krate/client-error",
36
+ frames: raw?.frames ?? (native ? "/__krate/hmr" : ""),
37
+ events: raw?.events ?? (native ? "/__krate/dev/events" : ""),
38
+ memory: raw?.memory ?? (native ? "/__krate/dev/memory" : ""),
39
+ errors: raw?.errors ?? (native ? "/__krate/dev/client-error" : "/__krate/client-error"),
9
40
  open: raw?.open ?? "/__krate/open",
10
41
  overlay: raw?.overlay ?? true,
11
42
  toolbar: raw?.toolbar ?? true,
@@ -60,7 +91,9 @@ var __krate_exports = (() => {
60
91
  if (!part) continue;
61
92
  const nums = decodeVLQ(part);
62
93
  genCol += nums[0] || 0;
63
- if (nums.length >= 4) {
94
+ if (nums.length === 1) {
95
+ segs.push({ genCol, src: -1, srcLine: 0, srcCol: 0 });
96
+ } else if (nums.length >= 4) {
64
97
  src += nums[1];
65
98
  srcLine += nums[2];
66
99
  srcCol += nums[3];
@@ -78,7 +111,8 @@ var __krate_exports = (() => {
78
111
  if (cached) return cached;
79
112
  const p = (async () => {
80
113
  try {
81
- if (/^[a-z]+:\/\//i.test(url) && !url.startsWith(location.origin)) return null;
114
+ const u = new URL(url, location.href);
115
+ if (u.protocol !== location.protocol || u.host !== location.host) return null;
82
116
  const res = await fetch(url + ".map");
83
117
  if (!res.ok) return null;
84
118
  const json = await res.json();
@@ -93,7 +127,7 @@ var __krate_exports = (() => {
93
127
  }
94
128
  function parseStackFrame(line) {
95
129
  const patterns = [
96
- /^(.*?)((?:https?:)?\/\/[^\s)]+|\/[^\s):]+):(\d+):(\d+)(.*)$/
130
+ /^(.*?)((?:[a-z][a-z0-9+.-]*:)?\/\/[^\s)]+|\/[^\s):]+):(\d+):(\d+)(.*)$/
97
131
  ];
98
132
  for (const re of patterns) {
99
133
  const m = re.exec(line);
@@ -103,19 +137,27 @@ var __krate_exports = (() => {
103
137
  return null;
104
138
  }
105
139
  function remapLocation(map, line, col) {
106
- const segs = map.lines[line - 1];
107
- if (!segs || segs.length === 0) return null;
108
140
  let best = null;
109
- for (const s of segs) {
110
- if (s.genCol <= col - 1) best = s;
111
- else break;
141
+ const segs = map.lines[line - 1];
142
+ if (segs && segs.length > 0) {
143
+ for (const s of segs) {
144
+ if (s.genCol <= col - 1) best = s;
145
+ else break;
146
+ }
147
+ if (!best) best = segs[0];
148
+ } else {
149
+ for (let i = Math.min(line - 1, map.lines.length) - 1; i >= 0 && !best; i--) {
150
+ const prev = map.lines[i];
151
+ if (prev && prev.length > 0) best = prev[prev.length - 1];
152
+ }
153
+ if (!best) return null;
112
154
  }
113
- if (!best) best = segs[0];
155
+ if (best.src < 0) return null;
114
156
  const source = map.sources[best.src] || "";
115
157
  return { source, line: best.srcLine + 1, col: best.srcCol + 1 };
116
158
  }
117
159
  async function symbolicateStack(stack) {
118
- if (!stack || stack.indexOf(".js") === -1) return stack;
160
+ if (!stack || !stack.includes(".js")) return stack;
119
161
  const lines = stack.split("\n");
120
162
  const out = await Promise.all(
121
163
  lines.map(async (line) => {
@@ -124,12 +166,21 @@ var __krate_exports = (() => {
124
166
  const map = await loadSourceMap(frame.url);
125
167
  if (!map) return line;
126
168
  const loc = remapLocation(map, frame.line, frame.col);
127
- if (!loc) return line;
169
+ if (!loc || !loc.source || loc.source === "krate-hydration.js") return line;
128
170
  return frame.prefix + loc.source + ":" + loc.line + ":" + loc.col + frame.suffix;
129
171
  })
130
172
  );
131
173
  return out.join("\n");
132
174
  }
175
+ function formatArg(a) {
176
+ if (a instanceof Error) return a.message || String(a);
177
+ if (typeof a === "string") return a;
178
+ try {
179
+ return JSON.stringify(a) ?? String(a);
180
+ } catch {
181
+ return String(a);
182
+ }
183
+ }
133
184
  function routeMatches(pattern, pathname, basePath = "") {
134
185
  const a = norm(stripBase(pathname, basePath)).split("/");
135
186
  const b = norm(pattern).split("/");
@@ -143,8 +194,79 @@ var __krate_exports = (() => {
143
194
  }
144
195
  return a.length === b.length;
145
196
  }
197
+ function parseFrames(buf) {
198
+ const values = [];
199
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
200
+ const td = new TextDecoder();
201
+ let pos = 0;
202
+ while (buf.length - pos >= 4) {
203
+ const n = view.getUint32(pos);
204
+ let end = pos + 4 + n;
205
+ if (buf.length < end + 2) break;
206
+ const json = td.decode(buf.subarray(pos + 4, end));
207
+ const blobs = view.getUint16(end);
208
+ end += 2;
209
+ let complete = true;
210
+ for (let i = 0; i < blobs; i++) {
211
+ if (buf.length < end + 4) {
212
+ complete = false;
213
+ break;
214
+ }
215
+ end += 4 + view.getUint32(end);
216
+ if (buf.length < end) {
217
+ complete = false;
218
+ break;
219
+ }
220
+ }
221
+ if (!complete) break;
222
+ try {
223
+ values.push(JSON.parse(json));
224
+ } catch {
225
+ }
226
+ pos = end;
227
+ }
228
+ return { values, rest: buf.subarray(pos) };
229
+ }
230
+ function hostStackOf(reason) {
231
+ const data = reason?.data;
232
+ const stack = data && typeof data === "object" ? data.stack : void 0;
233
+ return typeof stack === "string" ? stack : "";
234
+ }
235
+ function hostEventLine(ev) {
236
+ const t = ev.time ? new Date(ev.time).toLocaleTimeString() : "";
237
+ const dur = ev.durNs ? (ev.durNs / 1e6 >= 10 ? Math.round(ev.durNs / 1e6) : Math.round(ev.durNs / 1e5) / 10) + "ms" : "";
238
+ const err = ev.code ? " " + ev.code + (ev.message ? ": " + ev.message : "") : "";
239
+ return [t, ev.kind, ev.fn, dur].filter(Boolean).join(" ") + err;
240
+ }
241
+ function formatBytes(n) {
242
+ if (!Number.isFinite(n) || n < 0) return "n/a";
243
+ if (n >= 1 << 30) return (n / (1 << 30)).toFixed(2) + " GiB";
244
+ if (n >= 1 << 20) return (n / (1 << 20)).toFixed(1) + " MiB";
245
+ if (n >= 1 << 10) return Math.round(n / (1 << 10)) + " KiB";
246
+ return Math.round(n) + " B";
247
+ }
248
+ function jsHeapBytes() {
249
+ const m = typeof performance !== "undefined" ? performance.memory : void 0;
250
+ return m && typeof m.usedJSHeapSize === "number" ? m.usedJSHeapSize : null;
251
+ }
252
+ function memoryRows(rep, domNodes, heap) {
253
+ const rows = [];
254
+ if (rep && rep.procs) {
255
+ for (const p of rep.procs) {
256
+ rows.push([p.role + " (" + p.pid + ")", "PSS " + formatBytes(p.pss) + " / private dirty " + formatBytes(p.privateDirty)]);
257
+ }
258
+ if (rep.total) rows.push(["total", "PSS " + formatBytes(rep.total.pss) + " / private dirty " + formatBytes(rep.total.privateDirty)]);
259
+ } else {
260
+ rows.push(["processes", "unavailable"]);
261
+ }
262
+ rows.push(["DOM nodes", String(domNodes)]);
263
+ rows.push(["JS heap", heap === null ? "unavailable in this engine (see the web process row)" : formatBytes(heap)]);
264
+ return rows;
265
+ }
266
+ var ICON_MEM = '<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="6" width="16" height="12" rx="1"/><path d="M8 10v4M12 10v4M16 10v4"/><path d="M7 18v2M12 18v2M17 18v2"/></svg>';
146
267
  var ICON_RELOAD = '<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12a9 9 0 1 1-2.64-6.36"/><path d="M21 3v6h-6"/></svg>';
147
268
  var ICON_ALERT = '<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>';
269
+ var ICON_HOST = '<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4" width="18" height="12" rx="2"/><path d="M8 20h8"/><path d="M12 16v4"/></svg>';
148
270
  var STYLE = `
149
271
  :host { all: initial; }
150
272
  * { box-sizing: border-box; }
@@ -247,6 +369,31 @@ var __krate_exports = (() => {
247
369
  .frame .src { color: #d4d4d4; }
248
370
  .frame .caret { color: var(--red); }
249
371
  .hint { margin-top: 8px; color: #a3e635; }
372
+ .hostpanel {
373
+ position: fixed; right: 12px; bottom: 12px; z-index: 2147483002;
374
+ width: min(560px, calc(100vw - 24px)); max-height: 50vh; display: flex; flex-direction: column;
375
+ background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
376
+ box-shadow: 0 16px 48px rgba(0,0,0,.5); overflow: hidden;
377
+ font: 12px/1.45 "SF Mono", Menlo, Monaco, Consolas, "Courier New", monospace; color: var(--fg);
378
+ }
379
+ .hostpanel[hidden] { display: none; }
380
+ .hostpanel .card-head { padding: 8px 12px; }
381
+ .hostrows { overflow: auto; padding: 4px 0; }
382
+ .hostrow { padding: 2px 12px; white-space: pre-wrap; word-break: break-word; }
383
+ .hostrow.err { color: var(--red); }
384
+ .hostrow.sig { color: var(--muted); }
385
+ .mempanel {
386
+ position: fixed; right: 12px; bottom: 12px; z-index: 2147483002;
387
+ width: min(460px, calc(100vw - 24px));
388
+ background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
389
+ box-shadow: 0 16px 48px rgba(0,0,0,.5); overflow: hidden;
390
+ font: 12px/1.45 "SF Mono", Menlo, Monaco, Consolas, "Courier New", monospace; color: var(--fg);
391
+ }
392
+ .mempanel[hidden] { display: none; }
393
+ .mempanel .card-head { padding: 8px 12px; }
394
+ .memrow { display: flex; gap: 12px; justify-content: space-between; padding: 2px 12px; }
395
+ .memrow .k { color: var(--muted); }
396
+ .memrow .v { text-align: right; }
250
397
  .stack {
251
398
  margin-top: 10px; color: var(--muted); white-space: pre-wrap; word-break: break-word;
252
399
  max-height: 320px; overflow: auto;
@@ -257,6 +404,7 @@ var __krate_exports = (() => {
257
404
  this.cfg = devConfig();
258
405
  this.buildDiags = [];
259
406
  this.runtimeErrors = [];
407
+ this.hostSeq = 0;
260
408
  this.seen = /* @__PURE__ */ new Set();
261
409
  }
262
410
  init() {
@@ -277,7 +425,7 @@ var __krate_exports = (() => {
277
425
  if (this.cfg.toolbar) {
278
426
  this.toolbar = document.createElement("div");
279
427
  this.toolbar.className = "toolbar";
280
- this.toolbar.innerHTML = '<button class="tb-btn errors" type="button" title="Show errors">' + ICON_ALERT + '<span class="tb-label">Errors</span></button><div class="tb-center"><span class="brand">krate</span><span class="route"></span></div><button class="tb-btn reload" type="button" title="Reload">' + ICON_RELOAD + '<span class="tb-label">Reload</span></button>';
428
+ this.toolbar.innerHTML = '<button class="tb-btn errors" type="button" title="Show errors">' + ICON_ALERT + '<span class="tb-label">Errors</span></button>' + (this.cfg.events ? '<button class="tb-btn host" type="button" title="Host calls">' + ICON_HOST + '<span class="tb-label">Host</span></button>' : "") + '<div class="tb-center"><span class="brand">krate</span><span class="route"></span></div>' + (this.cfg.memory ? '<button class="tb-btn mem" type="button" title="Memory">' + ICON_MEM + '<span class="tb-label">Memory</span></button>' : "") + '<button class="tb-btn reload" type="button" title="Reload">' + ICON_RELOAD + '<span class="tb-label">Reload</span></button>';
281
429
  this.shadow.appendChild(this.toolbar);
282
430
  this.routeEl = this.toolbar.querySelector(".route");
283
431
  this.routeEl.textContent = location.pathname;
@@ -287,7 +435,8 @@ var __krate_exports = (() => {
287
435
  document.addEventListener("keydown", (e) => {
288
436
  if (e.key === "Escape") this.hide();
289
437
  });
290
- this.connectSSE();
438
+ if (this.cfg.frames) this.connectFrames();
439
+ else this.connectSSE();
291
440
  this.captureRuntimeErrors();
292
441
  }
293
442
  onClick(e) {
@@ -303,6 +452,22 @@ var __krate_exports = (() => {
303
452
  else this.hide();
304
453
  return;
305
454
  }
455
+ if (t.classList.contains("host")) {
456
+ this.toggleHost();
457
+ return;
458
+ }
459
+ if (t.classList.contains("mem")) {
460
+ this.toggleMemory();
461
+ return;
462
+ }
463
+ if (t.classList.contains("memclose")) {
464
+ this.toggleMemory(false);
465
+ return;
466
+ }
467
+ if (t.classList.contains("hostclose")) {
468
+ this.toggleHost(false);
469
+ return;
470
+ }
306
471
  if (t.classList.contains("reload")) {
307
472
  location.reload();
308
473
  return;
@@ -350,49 +515,159 @@ var __krate_exports = (() => {
350
515
  if (connectedOnce) location.reload();
351
516
  connectedOnce = true;
352
517
  });
353
- sse.addEventListener("reload", (e) => {
354
- if (this.buildDiags.length > 0) {
355
- this.buildDiags = [];
356
- this.setStatus(true);
357
- this.render();
358
- }
359
- let cssOnly = false;
518
+ const parse = (e) => {
360
519
  try {
361
- const d = JSON.parse(e.data);
362
- cssOnly = d.cssOnly === true;
363
- if (d.pages && Array.isArray(d.pages) && !d.pages.some(
364
- (p) => p === "/404" || p === "/500" || routeMatches(p, location.pathname, this.cfg.basePath)
365
- )) {
366
- return;
367
- }
520
+ return JSON.parse(e.data);
368
521
  } catch {
522
+ return null;
369
523
  }
370
- if (cssOnly) {
371
- this.swapStylesheets().catch(() => location.reload());
372
- return;
373
- }
374
- location.reload();
375
- });
376
- sse.addEventListener("build-error", (e) => {
377
- try {
378
- const d = JSON.parse(e.data);
379
- this.buildDiags = Array.isArray(d.diagnostics) ? d.diagnostics : [];
380
- } catch {
381
- this.buildDiags = [];
524
+ };
525
+ sse.addEventListener("reload", (e) => this.onReload(parse(e)));
526
+ sse.addEventListener("build-error", (e) => this.onBuildError(parse(e)));
527
+ sse.addEventListener("client-error", (e) => this.onClientError(parse(e)));
528
+ }
529
+ /**
530
+ * Krate Native: the same events as SSE, as `{hmr: {type, ...}}` frames on a
531
+ * streaming fetch. Reconnects after the stream ends; a second "connected"
532
+ * means the shell restarted, so the page is stale.
533
+ */
534
+ connectFrames() {
535
+ let connectedOnce = false;
536
+ const run = async () => {
537
+ const res = await fetch(this.cfg.frames, { cache: "no-store" });
538
+ if (!res.ok || !res.body) throw new Error("hmr stream unavailable");
539
+ const reader = res.body.getReader();
540
+ let buf = new Uint8Array(0);
541
+ for (; ; ) {
542
+ const { done, value } = await reader.read();
543
+ if (done) return;
544
+ const joined = new Uint8Array(buf.length + value.length);
545
+ joined.set(buf);
546
+ joined.set(value, buf.length);
547
+ const parsed = parseFrames(joined);
548
+ buf = parsed.rest;
549
+ for (const v of parsed.values) {
550
+ const m = v?.hmr;
551
+ if (!m || typeof m !== "object") continue;
552
+ if (m.type === "connected") {
553
+ if (connectedOnce) location.reload();
554
+ connectedOnce = true;
555
+ } else if (m.type === "reload") this.onReload(m);
556
+ else if (m.type === "build-error") this.onBuildError(m);
557
+ else if (m.type === "client-error") this.onClientError(m);
558
+ }
382
559
  }
383
- this.setStatus(this.buildDiags.length === 0);
560
+ };
561
+ const loop = () => {
562
+ run().then(
563
+ () => setTimeout(loop, 1e3),
564
+ () => setTimeout(loop, 1e3)
565
+ );
566
+ };
567
+ loop();
568
+ }
569
+ onReload(d) {
570
+ if (this.buildDiags.length > 0) {
571
+ this.buildDiags = [];
572
+ this.setStatus(true);
384
573
  this.render();
385
- });
386
- sse.addEventListener("client-error", (e) => {
387
- try {
388
- const d = JSON.parse(e.data);
389
- if (!d.clientError) return;
390
- const err = d.clientError;
391
- if (this.seen.has(err.message + "|" + (err.stack || ""))) return;
392
- this.addRuntime("Runtime Error", err.message, err.stack);
393
- } catch {
574
+ }
575
+ let cssOnly = false;
576
+ if (d) {
577
+ cssOnly = d.cssOnly === true;
578
+ const pages = d.pages;
579
+ if (pages && Array.isArray(pages) && !pages.some((p) => p === "/404" || p === "/500" || routeMatches(p, location.pathname, this.cfg.basePath))) {
580
+ return;
394
581
  }
395
- });
582
+ }
583
+ if (cssOnly) {
584
+ this.swapStylesheets().catch(() => location.reload());
585
+ return;
586
+ }
587
+ location.reload();
588
+ }
589
+ onBuildError(d) {
590
+ this.buildDiags = d && Array.isArray(d.diagnostics) ? d.diagnostics : [];
591
+ this.setStatus(this.buildDiags.length === 0);
592
+ this.render();
593
+ }
594
+ onClientError(d) {
595
+ if (!d || !d.clientError) return;
596
+ const err = d.clientError;
597
+ if (this.seen.has(err.message + "|" + (err.stack || ""))) return;
598
+ this.addRuntime("Runtime Error", err.message, err.stack);
599
+ }
600
+ toggleHost(force) {
601
+ if (!this.cfg.events) return;
602
+ if (!this.hostPanel) {
603
+ const el = document.createElement("div");
604
+ el.className = "hostpanel";
605
+ el.hidden = true;
606
+ el.innerHTML = '<div class="card-head"><span class="title" style="color:inherit">Host calls</span><span class="spacer"></span><button class="btn hostclose" type="button">Close</button></div><div class="hostrows"></div>';
607
+ this.shadow.appendChild(el);
608
+ this.hostPanel = el;
609
+ this.hostRows = el.querySelector(".hostrows");
610
+ }
611
+ const open = force ?? this.hostPanel.hidden;
612
+ this.hostPanel.hidden = !open;
613
+ if (this.hostTimer) clearInterval(this.hostTimer);
614
+ this.hostTimer = void 0;
615
+ if (open) {
616
+ void this.pollHost();
617
+ this.hostTimer = setInterval(() => void this.pollHost(), 1e3);
618
+ }
619
+ }
620
+ /** The Memory panel samples only while it is open (every 2 seconds). */
621
+ toggleMemory(force) {
622
+ if (!this.cfg.memory) return;
623
+ if (!this.memPanel) {
624
+ const el = document.createElement("div");
625
+ el.className = "mempanel";
626
+ el.hidden = true;
627
+ el.innerHTML = '<div class="card-head"><span class="title" style="color:inherit">Memory</span><span class="spacer"></span><button class="btn memclose" type="button">Close</button></div><div class="memrows"></div>';
628
+ this.shadow.appendChild(el);
629
+ this.memPanel = el;
630
+ this.memRows = el.querySelector(".memrows");
631
+ }
632
+ const open = force ?? this.memPanel.hidden;
633
+ this.memPanel.hidden = !open;
634
+ if (this.memTimer) clearInterval(this.memTimer);
635
+ this.memTimer = void 0;
636
+ if (open) {
637
+ void this.pollMemory();
638
+ this.memTimer = setInterval(() => void this.pollMemory(), 2e3);
639
+ }
640
+ }
641
+ async pollMemory() {
642
+ let rep = null;
643
+ try {
644
+ const res = await fetch(this.cfg.memory, { cache: "no-store" });
645
+ if (res.ok) rep = await res.json();
646
+ } catch {
647
+ }
648
+ const rows = memoryRows(rep, document.getElementsByTagName("*").length, jsHeapBytes());
649
+ this.memRows.innerHTML = rows.map(([k, v]) => '<div class="memrow"><span class="k">' + esc(k) + '</span><span class="v">' + esc(v) + "</span></div>").join("");
650
+ }
651
+ async pollHost() {
652
+ try {
653
+ const res = await fetch(this.cfg.events + "?since=" + this.hostSeq, { cache: "no-store" });
654
+ if (!res.ok) return;
655
+ const parsed = parseFrames(new Uint8Array(await res.arrayBuffer()));
656
+ const rows = this.hostRows;
657
+ const pinned = rows.scrollTop + rows.clientHeight >= rows.scrollHeight - 8;
658
+ for (const v of parsed.values) {
659
+ const ev = v?.ev;
660
+ if (!ev) continue;
661
+ this.hostSeq = Math.max(this.hostSeq, ev.seq);
662
+ const row = document.createElement("div");
663
+ row.className = "hostrow" + (ev.code ? " err" : ev.kind === "signal" ? " sig" : "");
664
+ row.textContent = hostEventLine(ev);
665
+ rows.appendChild(row);
666
+ }
667
+ while (rows.childElementCount > 200) rows.firstElementChild.remove();
668
+ if (pinned) rows.scrollTop = rows.scrollHeight;
669
+ } catch {
670
+ }
396
671
  }
397
672
  /**
398
673
  * Apply a CSS-only rebuild without a full reload: fetch the freshly built
@@ -440,50 +715,93 @@ var __krate_exports = (() => {
440
715
  captureRuntimeErrors() {
441
716
  window.addEventListener("error", (e) => this.onError(e));
442
717
  window.addEventListener("unhandledrejection", (e) => this.onRejection(e));
718
+ window.addEventListener("error", (e) => this.onResourceError(e), true);
719
+ this.captureConsole();
443
720
  const early = window.__KRATE_EARLY_ERRORS__;
444
721
  window.__KRATE_EARLY_ERRORS__ = void 0;
445
722
  for (const e of early ?? []) {
446
- if (e.type === "error") this.onError(e);
723
+ if (e.type === "console") this.onConsole(e.message, e.stack);
724
+ else if (e.type === "error" && e.target && e.target !== window) this.onResourceError(e);
725
+ else if (e.type === "error") this.onError(e);
447
726
  else this.onRejection(e);
448
727
  }
449
728
  }
729
+ captureConsole() {
730
+ const c = console;
731
+ const orig = c.error;
732
+ c.error = (...args) => {
733
+ try {
734
+ const first = args.find((a) => a instanceof Error);
735
+ this.onConsole(args.map(formatArg).join(" "), first?.stack);
736
+ } catch {
737
+ }
738
+ return orig.apply(c, args);
739
+ };
740
+ }
741
+ onConsole(message, stack) {
742
+ this.report({ message, stack, url: location.href, kind: "console" });
743
+ this.addRuntime("console.error", message, stack);
744
+ }
745
+ onResourceError(e) {
746
+ const t = e.target;
747
+ if (!t || t === window || !t.tagName) return;
748
+ const src = t.src || t.href || "";
749
+ if (!src) return;
750
+ const message = "failed to load <" + t.tagName.toLowerCase() + "> " + src;
751
+ this.report({ message, url: src, kind: "resource" });
752
+ this.addRuntime("Resource Error", message);
753
+ }
450
754
  onError(e) {
451
755
  const stack = e.error?.stack || "";
452
756
  const message = e.message || "Unknown error";
757
+ const hostStack = hostStackOf(e.error);
453
758
  this.report({
454
759
  message,
455
- stack,
760
+ stack: hostStack ? stack + "\nHost stack:\n" + hostStack : stack,
456
761
  url: e.filename,
457
762
  line: e.lineno,
458
763
  col: e.colno,
459
764
  kind: "error"
460
765
  });
461
- this.addRuntime("Runtime Error", message, stack);
766
+ this.addRuntime("Runtime Error", message, stack, hostStack);
462
767
  }
463
768
  onRejection(e) {
464
769
  const reason = e.reason;
465
770
  const message = reason instanceof Error ? reason.message : String(reason);
466
771
  const stack = reason instanceof Error ? reason.stack : "";
467
- this.report({ message, stack, url: location.href, kind: "unhandledrejection" });
468
- this.addRuntime("Unhandled Promise Rejection", message, stack);
772
+ const hostStack = hostStackOf(reason);
773
+ this.report({ message, stack: hostStack ? (stack || "") + "\nHost stack:\n" + hostStack : stack, url: location.href, kind: "unhandledrejection" });
774
+ this.addRuntime("Unhandled Promise Rejection", message, stack, hostStack);
469
775
  }
470
776
  report(payload) {
471
777
  const key = payload.message + "|" + (payload.stack || "");
472
778
  if (this.seen.has(key)) return;
473
779
  this.seen.add(key);
780
+ const win = globalThis.__KRATE_WINDOW__;
781
+ if (typeof win === "string" && win) payload.window = win;
782
+ if (!payload.stack || !payload.stack.includes(".js")) {
783
+ this.send(payload);
784
+ return;
785
+ }
786
+ const raw = payload.stack;
787
+ Promise.race([symbolicateStack(raw), new Promise((r) => setTimeout(() => r(raw), 1500))]).catch(() => raw).then((stack) => this.send({ ...payload, stack }));
788
+ }
789
+ send(payload) {
790
+ const body = JSON.stringify(payload);
474
791
  try {
475
- const body = JSON.stringify(payload);
476
- if (navigator.sendBeacon) {
477
- navigator.sendBeacon(this.cfg.errors, new Blob([body], { type: "application/json" }));
478
- } else {
479
- fetch(this.cfg.errors, { method: "POST", body, headers: { "Content-Type": "application/json" }, keepalive: true }).catch(() => {
480
- });
792
+ if (!this.cfg.frames && navigator.sendBeacon) {
793
+ if (navigator.sendBeacon(this.cfg.errors, new Blob([body], { type: "application/json" }))) return;
481
794
  }
482
795
  } catch {
483
796
  }
797
+ try {
798
+ fetch(this.cfg.errors, { method: "POST", body, headers: { "Content-Type": "application/json" }, keepalive: true }).catch(() => {
799
+ });
800
+ } catch {
801
+ }
484
802
  }
485
- addRuntime(title, message, stack) {
486
- const entry = { title, message, stack };
803
+ addRuntime(title, message, stack, hostStack) {
804
+ const entry = { title, message, stack, hostStack };
487
805
  this.runtimeErrors.push(entry);
488
806
  this.setStatus(false);
489
807
  this.render();
@@ -516,7 +834,8 @@ var __krate_exports = (() => {
516
834
  return '<div class="diag">' + actions + '<div class="msg">' + esc(d.message) + "</div>" + this.frameHTML(d) + hint + "</div>";
517
835
  }
518
836
  runtimeHTML(r) {
519
- const stack = r.stack ? '<div class="stack">' + esc(r.stack) + "</div>" : "";
837
+ const host = r.hostStack ? '<div class="stack">Host stack:\n' + esc(r.hostStack) + "</div>" : "";
838
+ const stack = host + (r.stack ? '<div class="stack">' + esc(r.stack) + "</div>" : "");
520
839
  return '<div class="diag"><div class="msg">' + esc(r.message) + "</div>" + stack + "</div>";
521
840
  }
522
841
  render() {
@@ -1,2 +1,2 @@
1
- var __krate_exports=(()=>{var g=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var K=(t,e)=>{for(var n in e)g(t,n,{get:e[n],enumerable:!0})},U=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of W(e))!J.call(t,r)&&r!==n&&g(t,r,{get:()=>e[r],enumerable:!(o=N(e,r))||o.enumerable});return t};var Q=t=>U(g({},"__esModule",{value:!0}),t);var wt={};K(wt,{ACTION_ARGS_FIELD:()=>v,ServerActionError:()=>p,__krateAction:()=>tt,__krateActionState:()=>ft,__krateAssignRef:()=>rt,__krateBeginAction:()=>y,__krateBindFormAction:()=>st,__krateFormStatusMount:()=>ot,__krateOptimistic:()=>pt,callServerAction:()=>A,getFormStatus:()=>at,installActionForms:()=>j,isActionPending:()=>et,isServerAction:()=>D,reportActionError:()=>T,requestFormReset:()=>it,runActionTransition:()=>F,setActionTransitionRunner:()=>nt,submitFormAction:()=>$,takeFlash:()=>I});var _=window.createEffect;var R=window.krateRunEvent;var d=window.krateTransitionWrites,P=window.onCleanup;var v="__krate_args",p=class extends Error{constructor(e,n,o){super(e),this.name="ServerActionError",this.status=n,o&&(this.digest=o)}};function V(){let t=globalThis.__KRATE_CFG__;return t&&t.basePath?t.basePath:""}function D(t){return typeof t=="function"&&typeof t.$$krateAction=="string"}var S=0;function z(t){let e=X(t);if(!e)return;let n=globalThis.navigate;typeof n=="function"?n(e):typeof location<"u"&&location.assign(e)}function X(t){return!t||!t.startsWith("/")||t.startsWith("//")||t.includes("\\")||/[\u0000-\u001f\u007f]/.test(t)?"":t}function Y(t){if(typeof window>"u"||typeof CustomEvent>"u")return;let e={paths:t&&Array.isArray(t.paths)?t.paths:[],tags:t&&Array.isArray(t.tags)?t.tags:[]};window.dispatchEvent(new CustomEvent("krate:revalidate",{detail:e}))}function Z(t,e,n){let o=t?t.error:void 0;if(o&&typeof o=="object")return new p(o.message||"Server action failed",e,o.digest);let r=t&&(t.details||(typeof o=="string"?o:""))||n||"Server action failed";return new p(r,e)}async function A(t,e){let n={accept:"application/json","x-krate-action":"fetch"};typeof location<"u"&&(n["x-krate-return"]=location.pathname+location.search);let o,r=e[e.length-1];if(typeof FormData<"u"&&r instanceof FormData){let s=new FormData;r.forEach((u,l)=>{l!==v&&s.append(l,u)});let c=e.slice(0,-1);c.length>0&&s.set(v,JSON.stringify(c)),o=s}else n["content-type"]="application/json",o=JSON.stringify({args:e});let a=await fetch(t,{method:"POST",credentials:"same-origin",headers:n,body:o}),i=null;try{i=await a.json()}catch{i=null}if(!a.ok||!i||i.ok===!1)throw Z(i,a.status,a.statusText);return i.revalidated&&Y(i.revalidation),typeof i.redirect=="string"&&i.redirect&&(S++,z(i.redirect)),i.result}function L(t,e){let n=V()+"/__krate/action/"+t,o=function(...r){return A(n,e.concat(r))};return Object.defineProperty(o,"actionUrl",{value:n}),Object.defineProperty(o,"$$krateAction",{value:t}),Object.defineProperty(o,"$$krateBound",{value:e}),Object.defineProperty(o,"bind",{value:(r,...a)=>L(t,e.concat(a))}),o.toString=()=>n,o}function tt(t){return L(t,[])}var f=0,h=new Set;function y(){f++;let t=!1;return()=>{t||(t=!0,f--,f===0&&d(()=>{for(let e of Array.from(h))e()}))}}function et(){return f>0}var H=t=>{let e=y(),n;try{n=t()}catch(o){return e(),Promise.reject(o)}return Promise.resolve(n).finally(e)},G=H;function nt(t){G=t||H}function F(t){return G(t)}function T(t,e){let n=globalThis;if(typeof n.__krateActionError=="function")try{if(n.__krateActionError(t,e)===!0)return}catch{}let o=e||(typeof document<"u"?document:null),r=!1;if(o&&typeof CustomEvent<"u"){let a=new CustomEvent("krate:action-error",{bubbles:!0,cancelable:!0,detail:{error:t}});r=!o.dispatchEvent(a)}r||console.error("krate server action:",t)}var b=Object.freeze({pending:!1,data:null,method:null,action:null}),w=new WeakMap;function q(t){let e=w.get(t);return e||(e={status:b,subs:new Set,running:0,resetRequested:!1},w.set(t,e)),e}function O(t,e){t.status=e;for(let n of Array.from(t.subs))n(e)}function ot(t,e){let n=null;for(let a=t?t.parentElement:null;a;a=a.parentElement)if(a.tagName==="FORM"){n=a;break}if(!n)return()=>{};let o=q(n),r=a=>{e.status&&e.status(a),e.pending&&e.pending(a.pending),e.data&&e.data(a.data),e.method&&e.method(a.method),e.action&&e.action(a.action)};return o.subs.add(r),r(o.status),()=>{o.subs.delete(r)}}function rt(t,e){typeof t=="function"?t(e):t&&typeof t=="object"&&(t.current=e)}function at(t){return w.get(t)?.status||b}function B(t){let e=Array.from(t.querySelectorAll("[data-kattr-value],[data-kattr-checked]")).map(n=>({el:n,value:n.value,checked:n.checked}));t.reset();for(let n of e)n.el.hasAttribute("data-kattr-value")&&(n.el.value=n.value),n.el.hasAttribute("data-kattr-checked")&&(n.el.checked=n.checked)}function it(t){let e=w.get(t);if(e&&e.running>0){e.resetRequested=!0;return}B(t)}function st(t,e){t&&(t.__krateFormAction=e,t.tagName==="FORM"?(t.removeAttribute("action"),t.removeAttribute("method")):(t.removeAttribute("formaction"),t.removeAttribute("formmethod")),t.removeAttribute("data-krate-action"))}function C(t){if(!t)return null;let e=t.__krateFormAction;if(typeof e!="function")return null;try{return e()}catch{return null}}function ct(t,e){if(e&&e!==t){let o=C(e);if(typeof o=="function")return{fn:o};if(e.hasAttribute("data-krate-action"))return{url:e.formAction||t.action};if(e.hasAttribute("formaction"))return null}let n=C(t);return typeof n=="function"?{fn:n}:t.hasAttribute("data-krate-action")?{url:t.action}:null}function ut(t,e){let n;try{n=e?new FormData(t,e):new FormData(t)}catch{n=new FormData(t);let o=e;o&&o.name&&n.append(o.name,o.value)}return n}function lt(t){let e=t.indexOf("?");return e<0?t:t.slice(0,e)}async function $(t,e,n,o=null,r){let a=q(t),i=(o&&o.getAttribute("formmethod")||t.getAttribute("method")||"get").toLowerCase();a.running++,O(a,{pending:!0,data:n,method:i,action:e||r||null}),t.setAttribute("data-krate-action-pending","1");let s=!1;try{await F(async()=>{let c=e;if(c&&typeof c.__krateRun=="function"){s=await c.__krateRun(n);return}typeof c=="function"?await c(n):r&&await A(lt(r),[n]),s=!0})}catch(c){T(c,t)}finally{a.running--,a.running===0&&(t.removeAttribute("data-krate-action-pending"),d(()=>O(a,b)),(s||a.resetRequested)&&(a.resetRequested=!1,s&&t.hasAttribute("data-krate-reload")?location.reload():B(t)))}return s}function dt(t){let e=t.target;if(!e||e.tagName!=="FORM"||t.defaultPrevented)return;let n=t.submitter||null,o=ct(e,n);if(!o)return;t.preventDefault();let r=ut(e,n);R("submit",!0,()=>{$(e,o.fn,r,n,o.url)})}function j(t=typeof document<"u"?document:void 0){if(!t)return;let e=t.defaultView;!e||e.__krateActionBound||(e.__krateActionBound=!0,t.addEventListener("submit",dt,!1))}function x(t){try{let e=t.split(".")[0].replace(/-/g,"+").replace(/_/g,"/"),n=atob(e+"=".repeat((4-e.length%4)%4));return JSON.parse(decodeURIComponent(escape(n)))}catch{return null}}function I(t){if(typeof document>"u")return{found:!1};let e=/(?:^|;\s*)krate_flash=([^;]*)/.exec(document.cookie||"");if(e){let o=x(e[1]);return o&&o.a===t?(document.cookie="krate_flash=; Path=/; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax",M(t),{found:!0,value:o.r}):{found:!1}}let n=document.querySelectorAll("[data-krate-flash]");for(let o=0;o<n.length;o++){let r=x(n[o].getAttribute("data-krate-flash")||"");if(r&&r.a===t)return M(t),{found:!0,value:r.r}}return{found:!1}}function M(t){let e=document.querySelectorAll("[data-krate-flash]");for(let n=0;n<e.length;n++){let o=x(e[n].getAttribute("data-krate-flash")||"");o&&o.a===t&&e[n].parentNode?.removeChild(e[n])}}function ft(t,e,n,o){let r=[],a=!1;if(D(t)){let u=I(t.$$krateAction);u.found&&n(u.value)}let i=async()=>{for(a=!0;r.length>0;){let u=r.shift(),l=!1;try{let k=S,m=await F(()=>t(e(),u.payload));S===k&&d(()=>n(m)),l=!0}catch(k){let m=r.splice(0);for(let E of m)E.end(),E.done(!1);T(k)}finally{d(()=>{u.end(),u.done(l)})}}a=!1,d(()=>o(!1))},s=u=>new Promise(l=>{r.push({payload:u,end:y(),done:l}),o(!0),a||i()}),c=(u=>{s(u)});return c.__krateRun=s,c}function pt(t,e,n){let o=[],r=i=>{let s=i;for(let c of o)s=n?n(s,c):c;return s};_(()=>{e(r(t()))});let a=()=>{o.length!==0&&(o=[],e(t()))};return h.add(a),P(()=>{h.delete(a)}),i=>{o.push(i),e(r(t())),f===0&&queueMicrotask(()=>{f===0&&a()})}}typeof document<"u"&&j(document);return Q(wt);})();
1
+ var __krate_exports=(()=>{var v=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var z=(t,e)=>{for(var n in e)v(t,n,{get:e[n],enumerable:!0})},X=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Q(e))!V.call(t,r)&&r!==n&&v(t,r,{get:()=>e[r],enumerable:!(o=U(e,r))||o.enumerable});return t};var Y=t=>X(v({},"__esModule",{value:!0}),t);var vt={};z(vt,{ACTION_ARGS_FIELD:()=>p,ServerActionError:()=>w,__krateAction:()=>at,__krateActionState:()=>mt,__krateAssignRef:()=>ut,__krateBeginAction:()=>F,__krateBindFormAction:()=>ft,__krateFormStatusMount:()=>ct,__krateOptimistic:()=>gt,callServerAction:()=>y,getFormStatus:()=>lt,installActionForms:()=>W,isActionPending:()=>it,isServerAction:()=>G,reportActionError:()=>_,requestFormReset:()=>dt,runActionTransition:()=>b,setActionTransitionRunner:()=>st,stripActionURL:()=>N,submitFormAction:()=>K,takeFlash:()=>J});var Z="__krate_cfg__";function R(){let t=globalThis;if(t.__KRATE_CFG__)return t.__KRATE_CFG__;let e=t.document,n=e&&typeof e.getElementById=="function"?e.getElementById(Z):null;if(n)try{let o=JSON.parse(n.textContent||"{}");if(o&&typeof o=="object")return t.__KRATE_CFG__=o,o}catch{}return{}}function h(){let t=R(),e=t&&t.basePath||"";return!e||e==="/"?"":"/"+e.replace(/^\/+|\/+$/g,"")}function C(t){let e=h();return e&&t.charCodeAt(0)===47&&t.charCodeAt(1)!==47?e+t:t}var P=window.createEffect;var O=window.krateRunEvent;var d=window.krateTransitionWrites,L=window.onCleanup;var p="__krate_args",w=class extends Error{constructor(e,n,o){super(e),this.name="ServerActionError",this.status=n,o&&(this.digest=o)}};function G(t){return typeof t=="function"&&typeof t.$$krateAction=="string"}var S=0;function tt(t){let e=nt(t);if(!e)return;let n=globalThis.navigate;typeof n=="function"?n(e):typeof location<"u"&&location.assign(C(e))}function et(t){typeof location>"u"||!/^https?:\/\//i.test(t)||location.assign(t)}function nt(t){return!t||!t.startsWith("/")||t.startsWith("//")||t.includes("\\")||/[\u0000-\u001F\u007F]/.test(t)?"":t}function ot(t){if(typeof window>"u"||typeof CustomEvent>"u")return;let e={paths:t&&Array.isArray(t.paths)?t.paths:[],tags:t&&Array.isArray(t.tags)?t.tags:[]};window.dispatchEvent(new CustomEvent("krate:revalidate",{detail:e}))}function rt(t,e,n){let o=t?t.error:void 0;if(o&&typeof o=="object")return new w(o.message||"Server action failed",e,o.digest);let r=t&&(t.details||(typeof o=="string"?o:""))||n||"Server action failed";return new w(r,e)}async function y(t,e){let n={accept:"application/json","x-krate-action":"fetch"};typeof location<"u"&&(n["x-krate-return"]=location.pathname+location.search);let o,r=e[e.length-1];if(typeof FormData<"u"&&r instanceof FormData){let s=new FormData;r.forEach((u,l)=>{l!==p&&s.append(l,u)});let c=e.slice(0,-1);c.length>0&&s.set(p,JSON.stringify(c)),o=s}else n["content-type"]="application/json",o=JSON.stringify({args:e});let a=await fetch(t,{method:"POST",credentials:"same-origin",headers:n,body:o}),i=null;try{i=await a.json()}catch{i=null}if(!a.ok||!i||i.ok===!1)throw rt(i,a.status,a.statusText);return i.revalidated&&ot(i.revalidation),typeof i.redirect=="string"&&i.redirect&&(S++,i.external?et(i.redirect):tt(i.redirect)),i.result}function B(t,e){let n=h()+"/__krate/action/"+t,o=function(...r){return y(n,e.concat(r))};return Object.defineProperty(o,"actionUrl",{value:n}),Object.defineProperty(o,"$$krateAction",{value:t}),Object.defineProperty(o,"$$krateBound",{value:e}),Object.defineProperty(o,"bind",{value:(r,...a)=>B(t,e.concat(a))}),o.toString=()=>n,o}function at(t){return B(t,[])}var f=0,x=new Set;function F(){f++;let t=!1;return()=>{t||(t=!0,f--,f===0&&d(()=>{for(let e of Array.from(x))e()}))}}function it(){return f>0}var I=t=>{let e=F(),n;try{n=t()}catch(o){return e(),Promise.reject(o)}return Promise.resolve(n).finally(e)},q=I;function st(t){q=t||I}function b(t){return q(t)}function _(t,e){let n=globalThis;if(typeof n.__krateActionError=="function")try{if(n.__krateActionError(t,e)===!0)return}catch{}let o=e||(typeof document<"u"?document:null),r=!1;if(o&&typeof CustomEvent<"u"){let a=new CustomEvent("krate:action-error",{bubbles:!0,cancelable:!0,detail:{error:t}});r=!o.dispatchEvent(a)}r||console.error("krate server action:",t)}var T=Object.freeze({pending:!1,data:null,method:null,action:null}),k=new WeakMap;function $(t){let e=k.get(t);return e||(e={status:T,subs:new Set,running:0,resetRequested:!1},k.set(t,e)),e}function D(t,e){t.status=e;for(let n of Array.from(t.subs))n(e)}function ct(t,e){let n=null;for(let a=t?t.parentElement:null;a;a=a.parentElement)if(a.tagName==="FORM"){n=a;break}if(!n)return()=>{};let o=$(n),r=a=>{e.status&&e.status(a),e.pending&&e.pending(a.pending),e.data&&e.data(a.data),e.method&&e.method(a.method),e.action&&e.action(a.action)};return o.subs.add(r),r(o.status),()=>{o.subs.delete(r)}}function ut(t,e){typeof t=="function"?t(e):t&&typeof t=="object"&&(t.current=e)}function lt(t){return k.get(t)?.status||T}function j(t){let e=Array.from(t.querySelectorAll("[data-kattr-value],[data-kattr-checked]")).map(n=>({el:n,value:n.value,checked:n.checked}));t.reset();for(let n of e)n.el.hasAttribute("data-kattr-value")&&(n.el.value=n.value),n.el.hasAttribute("data-kattr-checked")&&(n.el.checked=n.checked)}function dt(t){let e=k.get(t);if(e&&e.running>0){e.resetRequested=!0;return}j(t)}function ft(t,e){t&&(t.__krateFormAction=e,t.tagName==="FORM"?(t.removeAttribute("action"),t.removeAttribute("method")):(t.removeAttribute("formaction"),t.removeAttribute("formmethod")),t.removeAttribute("data-krate-action"))}function M(t){if(!t)return null;let e=t.__krateFormAction;if(typeof e!="function")return null;try{return e()}catch{return null}}function pt(t,e){if(e&&e!==t){let o=M(e);if(typeof o=="function")return{fn:o};if(e.hasAttribute("data-krate-action"))return{url:e.formAction||t.action};if(e.hasAttribute("formaction"))return null}let n=M(t);return typeof n=="function"?{fn:n}:t.hasAttribute("data-krate-action")?{url:t.action}:null}function wt(t,e){let n;try{n=e?new FormData(t,e):new FormData(t)}catch{n=new FormData(t);let o=e;o&&o.name&&n.append(o.name,o.value)}return n}function N(t){let e=t.indexOf("?");if(e===-1)return t;let n=t.slice(0,e);try{let o=new URLSearchParams(t.slice(e+1)).get(p),r=o?JSON.parse(o):null;if(Array.isArray(r)&&typeof r[0]=="string"&&r[0].startsWith("k1."))return n+"?"+p+"="+encodeURIComponent(JSON.stringify([r[0]]))}catch{}return n}async function K(t,e,n,o=null,r){let a=$(t),i=(o&&o.getAttribute("formmethod")||t.getAttribute("method")||"get").toLowerCase();a.running++,D(a,{pending:!0,data:n,method:i,action:e||r||null}),t.setAttribute("data-krate-action-pending","1");let s=!1;try{await b(async()=>{let c=e;if(c&&typeof c.__krateRun=="function"){s=await c.__krateRun(n);return}typeof c=="function"?await c(n):r&&await y(N(r),[n]),s=!0})}catch(c){_(c,t)}finally{a.running--,a.running===0&&(t.removeAttribute("data-krate-action-pending"),d(()=>D(a,T)),(s||a.resetRequested)&&(a.resetRequested=!1,s&&t.hasAttribute("data-krate-reload")?location.reload():j(t)))}return s}function kt(t){let e=t.target;if(!e||e.tagName!=="FORM"||t.defaultPrevented)return;let n=t.submitter||null,o=pt(e,n);if(!o)return;t.preventDefault();let r=wt(e,n);O("submit",!0,()=>{K(e,o.fn,r,n,o.url)})}function W(t=typeof document<"u"?document:void 0){if(!t)return;let e=t.defaultView;!e||e.__krateActionBound||(e.__krateActionBound=!0,t.addEventListener("submit",kt,!1))}function A(t){try{let e=t.split(".")[0].replace(/-/g,"+").replace(/_/g,"/"),n=atob(e+"=".repeat((4-e.length%4)%4));return JSON.parse(decodeURIComponent(escape(n)))}catch{return null}}function J(t){if(typeof document>"u")return{found:!1};let e=/(?:^|;\s*)krate_flash=([^;]*)/.exec(document.cookie||"");if(e){let o=A(e[1]);return o&&o.a===t?(document.cookie="krate_flash=; Path=/; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax",H(t),{found:!0,value:o.r}):{found:!1}}let n=document.querySelectorAll("[data-krate-flash]");for(let o=0;o<n.length;o++){let r=A(n[o].getAttribute("data-krate-flash")||"");if(r&&r.a===t)return H(t),{found:!0,value:r.r}}return{found:!1}}function H(t){let e=document.querySelectorAll("[data-krate-flash]");for(let n=0;n<e.length;n++){let o=A(e[n].getAttribute("data-krate-flash")||"");o&&o.a===t&&e[n].parentNode?.removeChild(e[n])}}function mt(t,e,n,o){let r=[],a=!1;if(G(t)){let u=J(t.$$krateAction);u.found&&n(u.value)}let i=async()=>{for(a=!0;r.length>0;){let u=r.shift(),l=!1;try{let m=S,g=await b(()=>t(e(),u.payload));S===m&&d(()=>n(g)),l=!0}catch(m){let g=r.splice(0);for(let E of g)E.end(),E.done(!1);_(m)}finally{d(()=>{u.end(),u.done(l)})}}a=!1,d(()=>o(!1))},s=u=>new Promise(l=>{r.push({payload:u,end:F(),done:l}),o(!0),a||i()}),c=(u=>{s(u)});return c.__krateRun=s,c}function gt(t,e,n){let o=[],r=i=>{let s=i;for(let c of o)s=n?n(s,c):c;return s};P(()=>{e(r(t()))});let a=()=>{o.length!==0&&(o=[],e(t()))};return x.add(a),L(()=>{x.delete(a)}),i=>{o.push(i),e(r(t())),f===0&&queueMicrotask(()=>{f===0&&a()})}}typeof document<"u"&&W(document);return Y(vt);})();
2
2
  for (const k in __krate_exports) { window[k] = __krate_exports[k]; }