@krate/runtime 0.5.0-rc.1 → 0.5.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/action-context.js +1 -1
- package/dist/actions.d.ts +7 -0
- package/dist/actions.js +34 -10
- package/dist/after.d.ts +28 -0
- package/dist/after.js +48 -0
- package/dist/assets-static.d.ts +10 -1
- package/dist/assets-static.js +10 -2
- package/dist/base-path.d.ts +7 -0
- package/dist/base-path.js +20 -0
- package/dist/boundary.js +1 -1
- package/dist/builtin-tags.d.ts +12 -0
- package/dist/builtin-tags.js +42 -0
- package/dist/cache-adapter.js +1 -1
- package/dist/cache-scope.d.ts +8 -0
- package/dist/cache-scope.js +14 -1
- package/dist/cloudflare-workers.d.ts +2 -0
- package/dist/cloudflare-workers.js +27 -0
- package/dist/context.d.ts +5 -0
- package/dist/context.js +28 -17
- package/dist/dev-overlay.d.ts +54 -3
- package/dist/dev-overlay.js +470 -77
- package/dist/dom.js +18 -3
- package/dist/effects.js +2 -2
- package/dist/flight-props.d.ts +7 -0
- package/dist/flight-props.js +105 -0
- package/dist/handler-html.js +4 -4
- package/dist/handler-routing.d.ts +2 -23
- package/dist/handler-routing.js +9 -190
- package/dist/handler-segments.d.ts +6 -0
- package/dist/handler-segments.js +18 -4
- package/dist/head-tags.d.ts +9 -0
- package/dist/head-tags.js +93 -6
- package/dist/highlight-bind.js +1 -1
- package/dist/highlight.d.ts +3 -2
- package/dist/highlight.js +17 -12
- package/dist/hints.d.ts +25 -2
- package/dist/hints.js +147 -74
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/island-swap.d.ts +47 -0
- package/dist/island-swap.js +635 -0
- package/dist/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx-types.d.ts +99 -3
- package/dist/krate-core.js +1 -1
- package/dist/krate-dev.js +385 -66
- package/dist/krate-f-actions.js +1 -1
- package/dist/krate-f-classes.js +1 -1
- package/dist/krate-f-highlight.js +1 -1
- package/dist/krate-f-list.js +1 -1
- package/dist/krate-f-navigation.js +1 -1
- package/dist/krate-f-router-lite.js +1 -1
- package/dist/krate-f-router.js +1 -1
- package/dist/krate-features.json +454 -0
- package/dist/krate-hydrate-lite.js +5 -5
- package/dist/krate-hydrate.js +5 -5
- package/dist/krate-island-swap.js +1 -0
- package/dist/krate-runtime.js +5 -5
- package/dist/list.d.ts +14 -4
- package/dist/list.js +4 -5
- package/dist/metadata.js +5 -2
- package/dist/navigation-react.d.ts +13 -0
- package/dist/navigation-react.js +86 -0
- package/dist/navigation.d.ts +19 -0
- package/dist/navigation.js +35 -0
- package/dist/node-server.js +3 -3
- package/dist/og.js +1 -1
- package/dist/platform.d.ts +52 -0
- package/dist/platform.js +57 -0
- package/dist/react-compat.d.ts +39 -0
- package/dist/react-compat.js +359 -0
- package/dist/react-server.d.ts +63 -0
- package/dist/react-server.js +125 -0
- package/dist/region-wire.d.ts +10 -0
- package/dist/region-wire.js +154 -0
- package/dist/request-context.js +1 -1
- package/dist/request-extras.d.ts +4 -0
- package/dist/request-extras.js +51 -0
- package/dist/resp.js +1 -1
- package/dist/route-source.d.ts +39 -0
- package/dist/route-source.js +532 -0
- package/dist/router-lite.js +3 -9
- package/dist/router.d.ts +1 -1
- package/dist/router.js +628 -98
- package/dist/server-handler.d.ts +69 -1
- package/dist/server-handler.js +515 -96
- package/dist/server-renderer.js +16 -7
- package/dist/server.d.ts +73 -16
- package/dist/server.js +619 -102
- package/dist/sha256.js +9 -9
- package/dist/signal.js +0 -6
- package/dist/site-config.d.ts +15 -0
- package/dist/site-config.js +28 -0
- package/dist/slot.d.ts +12 -0
- package/dist/slot.js +23 -0
- package/dist/ssr-core.d.ts +2 -0
- package/dist/ssr-core.js +12 -4
- package/dist/testing.d.ts +62 -0
- package/dist/testing.js +90 -0
- package/dist/use-id.js +1 -1
- package/package.json +28 -3
- package/dist/action-context.test.d.ts +0 -1
- package/dist/action-context.test.js +0 -72
- package/dist/actions.test.d.ts +0 -1
- package/dist/actions.test.js +0 -477
- package/dist/cache-adapter.test.d.ts +0 -1
- package/dist/cache-adapter.test.js +0 -244
- package/dist/cache.test.d.ts +0 -1
- package/dist/cache.test.js +0 -233
- package/dist/class-component.test.d.ts +0 -1
- package/dist/class-component.test.js +0 -462
- package/dist/class-helpers.test.d.ts +0 -1
- package/dist/class-helpers.test.js +0 -169
- package/dist/context.test.d.ts +0 -1
- package/dist/context.test.js +0 -57
- package/dist/derived.test.d.ts +0 -1
- package/dist/derived.test.js +0 -140
- package/dist/dev-overlay.test.d.ts +0 -1
- package/dist/dev-overlay.test.js +0 -165
- package/dist/discrete.test.d.ts +0 -1
- package/dist/discrete.test.js +0 -100
- package/dist/dom.test.d.ts +0 -1
- package/dist/dom.test.js +0 -39
- package/dist/effect-errors.test.d.ts +0 -1
- package/dist/effect-errors.test.js +0 -199
- package/dist/effects.test.d.ts +0 -1
- package/dist/effects.test.js +0 -485
- package/dist/events.test.d.ts +0 -1
- package/dist/events.test.js +0 -447
- package/dist/handler-html.test.d.ts +0 -1
- package/dist/handler-html.test.js +0 -256
- package/dist/handler-routing.test.d.ts +0 -1
- package/dist/handler-routing.test.js +0 -99
- package/dist/handler-segments.test.d.ts +0 -1
- package/dist/handler-segments.test.js +0 -217
- package/dist/head-tags.test.d.ts +0 -1
- package/dist/head-tags.test.js +0 -131
- package/dist/highlight-bind.test.d.ts +0 -1
- package/dist/highlight-bind.test.js +0 -124
- package/dist/highlight.test.d.ts +0 -1
- package/dist/highlight.test.js +0 -56
- package/dist/lanes.test.d.ts +0 -1
- package/dist/lanes.test.js +0 -59
- package/dist/list.test.d.ts +0 -1
- package/dist/list.test.js +0 -435
- package/dist/metadata.test.d.ts +0 -1
- package/dist/metadata.test.js +0 -167
- package/dist/navigation.test.d.ts +0 -1
- package/dist/navigation.test.js +0 -130
- package/dist/node-server.test.d.ts +0 -1
- package/dist/node-server.test.js +0 -492
- package/dist/optimistic-lanes.test.d.ts +0 -1
- package/dist/optimistic-lanes.test.js +0 -45
- package/dist/patterns.test.d.ts +0 -1
- package/dist/patterns.test.js +0 -125
- package/dist/portal.test.d.ts +0 -1
- package/dist/portal.test.js +0 -99
- package/dist/react-effects.test.d.ts +0 -1
- package/dist/react-effects.test.js +0 -133
- package/dist/react-suspense.test.d.ts +0 -1
- package/dist/react-suspense.test.js +0 -194
- package/dist/react.test.d.ts +0 -1
- package/dist/react.test.js +0 -60
- package/dist/react19.test.d.ts +0 -1
- package/dist/react19.test.js +0 -176
- package/dist/reactivity-core.test.d.ts +0 -1
- package/dist/reactivity-core.test.js +0 -152
- package/dist/reconcile.test.d.ts +0 -1
- package/dist/reconcile.test.js +0 -110
- package/dist/refs.test.d.ts +0 -1
- package/dist/refs.test.js +0 -257
- package/dist/router-layout.test.d.ts +0 -1
- package/dist/router-layout.test.js +0 -249
- package/dist/router-nav.test.d.ts +0 -1
- package/dist/router-nav.test.js +0 -559
- package/dist/router-slots.test.d.ts +0 -1
- package/dist/router-slots.test.js +0 -144
- package/dist/router-speculation.test.d.ts +0 -1
- package/dist/router-speculation.test.js +0 -25
- package/dist/router-styles.test.d.ts +0 -1
- package/dist/router-styles.test.js +0 -98
- package/dist/router.test.d.ts +0 -1
- package/dist/router.test.js +0 -36
- package/dist/server-async.test.d.ts +0 -1
- package/dist/server-async.test.js +0 -216
- package/dist/server-handler.test.d.ts +0 -1
- package/dist/server-handler.test.js +0 -535
- package/dist/server-highlight.test.d.ts +0 -1
- package/dist/server-highlight.test.js +0 -32
- package/dist/server-renderer.test.d.ts +0 -1
- package/dist/server-renderer.test.js +0 -266
- package/dist/server.test.d.ts +0 -1
- package/dist/server.test.js +0 -88
- package/dist/sha256.test.d.ts +0 -1
- package/dist/sha256.test.js +0 -13
- package/dist/signal-lanes.test.d.ts +0 -1
- package/dist/signal-lanes.test.js +0 -32
- package/dist/signal.test.d.ts +0 -1
- package/dist/signal.test.js +0 -68
- package/dist/slots.test.d.ts +0 -1
- package/dist/slots.test.js +0 -187
- package/dist/snapshots.test.d.ts +0 -1
- package/dist/snapshots.test.js +0 -208
- package/dist/ssr-core-behavior.test.d.ts +0 -1
- package/dist/ssr-core-behavior.test.js +0 -620
- package/dist/ssr-core.test.d.ts +0 -1
- package/dist/ssr-core.test.js +0 -324
- package/dist/static-memory.test.d.ts +0 -1
- package/dist/static-memory.test.js +0 -26
- package/dist/storage.test.d.ts +0 -1
- package/dist/storage.test.js +0 -46
- package/dist/suspense-actions.test.d.ts +0 -1
- package/dist/suspense-actions.test.js +0 -72
- package/dist/suspense.test.d.ts +0 -1
- 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 =
|
|
32
|
+
const runtime = siteConfig();
|
|
33
|
+
const native = isNativeOrigin();
|
|
6
34
|
return {
|
|
7
35
|
sse: raw?.sse ?? "/__krate/hotreload",
|
|
8
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
/^(.*?)((?:
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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 (
|
|
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.
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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 === "
|
|
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
|
-
|
|
468
|
-
this.
|
|
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
|
-
|
|
476
|
-
|
|
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
|
|
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() {
|
package/dist/krate-f-actions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var __krate_exports=(()=>{var
|
|
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]; }
|