@krate/runtime 0.5.0-rc.14 → 0.5.0-rc.16

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 (70) hide show
  1. package/NOTICE +10 -0
  2. package/dist/action-context.js +5 -1
  3. package/dist/cache-scope.d.ts +10 -2
  4. package/dist/cache-scope.js +26 -4
  5. package/dist/dev/api.d.ts +93 -0
  6. package/dist/dev/api.js +2 -0
  7. package/dist/dev/app.d.ts +165 -0
  8. package/dist/dev/app.js +1204 -0
  9. package/dist/dev/commands.d.ts +49 -0
  10. package/dist/dev/commands.js +114 -0
  11. package/dist/dev/highlight.d.ts +4 -0
  12. package/dist/dev/highlight.js +126 -0
  13. package/dist/dev/icons.d.ts +4 -0
  14. package/dist/dev/icons.js +57 -0
  15. package/dist/dev/inspect.d.ts +55 -0
  16. package/dist/dev/inspect.js +256 -0
  17. package/dist/dev/inspector.d.ts +39 -0
  18. package/dist/dev/inspector.js +348 -0
  19. package/dist/dev/issues.d.ts +83 -0
  20. package/dist/dev/issues.js +166 -0
  21. package/dist/dev/modal.d.ts +16 -0
  22. package/dist/dev/modal.js +836 -0
  23. package/dist/dev/native.d.ts +53 -0
  24. package/dist/dev/native.js +95 -0
  25. package/dist/dev/palette.d.ts +9 -0
  26. package/dist/dev/palette.js +250 -0
  27. package/dist/dev/panel.d.ts +31 -0
  28. package/dist/dev/panel.js +848 -0
  29. package/dist/dev/requests.d.ts +36 -0
  30. package/dist/dev/requests.js +150 -0
  31. package/dist/dev/settings.d.ts +32 -0
  32. package/dist/dev/settings.js +78 -0
  33. package/dist/dev/sourcemap.d.ts +22 -0
  34. package/dist/dev/sourcemap.js +148 -0
  35. package/dist/dev/stack.d.ts +38 -0
  36. package/dist/dev/stack.js +115 -0
  37. package/dist/dev/styles.d.ts +1 -0
  38. package/dist/dev/styles.js +424 -0
  39. package/dist/dev/util.d.ts +63 -0
  40. package/dist/dev/util.js +190 -0
  41. package/dist/dev-overlay.d.ts +9 -83
  42. package/dist/dev-overlay.js +17 -1038
  43. package/dist/island-swap.js +53 -9
  44. package/dist/krate-core.js +1 -1
  45. package/dist/krate-dev.js +441 -871
  46. package/dist/krate-f-list.js +1 -1
  47. package/dist/krate-f-navigation.js +1 -1
  48. package/dist/krate-hydrate-lite.js +5 -5
  49. package/dist/krate-hydrate.js +5 -5
  50. package/dist/krate-island-swap.js +1 -1
  51. package/dist/krate-runtime.js +5 -5
  52. package/dist/list.js +23 -1
  53. package/dist/memsize.d.ts +14 -0
  54. package/dist/memsize.js +71 -0
  55. package/dist/metadata.js +23 -12
  56. package/dist/request-context.d.ts +10 -0
  57. package/dist/request-context.js +24 -0
  58. package/dist/segmented-lru.d.ts +14 -1
  59. package/dist/segmented-lru.js +90 -21
  60. package/dist/server-handler.d.ts +3 -0
  61. package/dist/server-handler.js +4 -2
  62. package/dist/server-renderer.js +10 -3
  63. package/dist/server.d.ts +3 -1
  64. package/dist/server.js +55 -29
  65. package/dist/shared-isr.js +2 -1
  66. package/dist/signal.d.ts +8 -0
  67. package/dist/signal.js +4 -0
  68. package/dist/ssr-core.d.ts +13 -2
  69. package/dist/ssr-core.js +63 -11
  70. package/package.json +3 -2
@@ -1,1059 +1,38 @@
1
1
  /**
2
- * Dev-only error overlay + toolbar.
2
+ * Dev-only overlay: the dock, its panel, the error overlay, the command menu
3
+ * and the component inspector.
3
4
  *
4
5
  * Bundled separately as `krate-dev.js` and injected only by `krate dev`; it is
5
- * never part of the production runtime. It renders structured compiler
6
- * diagnostics (file:line:col + source + caret + hint) and client runtime errors,
7
- * forwards runtime errors back to the dev server, and offers open-in-editor.
6
+ * never part of the production runtime. The modules live in ./dev/.
8
7
  */
9
- import { siteConfig } from './site-config.js';
10
- /** True inside a Krate Native window (`krate://app`, or `https://app.localhost` on Windows). */
11
- export function isNativeOrigin() {
12
- try {
13
- return location.protocol === 'krate:' || location.origin === 'https://app.localhost';
14
- }
15
- catch {
16
- return false;
17
- }
18
- }
19
- function devConfig() {
20
- const raw = window.__KRATE_DEV__;
21
- const runtime = siteConfig();
22
- const native = isNativeOrigin();
23
- return {
24
- sse: raw?.sse ?? '/__krate/hotreload',
25
- frames: raw?.frames ?? (native ? '/__krate/hmr' : ''),
26
- events: raw?.events ?? (native ? '/__krate/dev/events' : ''),
27
- memory: raw?.memory ?? (native ? '/__krate/dev/memory' : ''),
28
- errors: raw?.errors ?? (native ? '/__krate/dev/client-error' : '/__krate/client-error'),
29
- open: raw?.open ?? '/__krate/open',
30
- overlay: raw?.overlay ?? true,
31
- toolbar: raw?.toolbar ?? true,
32
- basePath: raw?.basePath ?? runtime?.basePath ?? '',
33
- };
34
- }
35
- function esc(s) {
36
- return String(s)
37
- .replace(/&/g, '&')
38
- .replace(/</g, '&lt;')
39
- .replace(/>/g, '&gt;')
40
- .replace(/"/g, '&quot;')
41
- .replace(/'/g, '&#39;');
42
- }
43
- function norm(p) {
44
- return p.replace(/\/+$/, '') || '/';
45
- }
46
- /** Strips the configured base path so match patterns (unprefixed) line up. */
47
- function stripBase(pathname, basePath) {
48
- if (basePath && (pathname === basePath || pathname.startsWith(basePath + '/'))) {
49
- const rest = pathname.slice(basePath.length);
50
- return rest === '' ? '/' : rest;
51
- }
52
- return pathname;
53
- }
54
- const B64_VLQ = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
55
- /** Decodes a Base64 VLQ mapping segment into a delta array. */
56
- export function decodeVLQ(str) {
57
- const out = [];
58
- let shift = 0;
59
- let value = 0;
60
- for (let i = 0; i < str.length; i++) {
61
- const digit = B64_VLQ.indexOf(str[i]);
62
- if (digit === -1)
63
- continue;
64
- const cont = (digit & 32) !== 0;
65
- value += (digit & 31) << shift;
66
- if (cont) {
67
- shift += 5;
68
- continue;
69
- }
70
- const neg = (value & 1) === 1;
71
- value >>= 1;
72
- out.push(neg ? -value : value);
73
- value = 0;
74
- shift = 0;
75
- }
76
- return out;
77
- }
78
- /** Decodes a v3 `mappings` string into per-generated-line segments. */
79
- export function decodeMappings(mappings) {
80
- const lines = [];
81
- let src = 0;
82
- let srcLine = 0;
83
- let srcCol = 0;
84
- for (const line of mappings.split(';')) {
85
- const segs = [];
86
- let genCol = 0;
87
- if (line) {
88
- for (const part of line.split(',')) {
89
- if (!part)
90
- continue;
91
- const nums = decodeVLQ(part);
92
- genCol += nums[0] || 0;
93
- if (nums.length === 1) {
94
- // An end marker: no original position from here on.
95
- segs.push({ genCol, src: -1, srcLine: 0, srcCol: 0 });
96
- }
97
- else if (nums.length >= 4) {
98
- src += nums[1];
99
- srcLine += nums[2];
100
- srcCol += nums[3];
101
- segs.push({ genCol, src, srcLine, srcCol });
102
- }
103
- }
104
- }
105
- lines.push(segs);
106
- }
107
- return lines;
108
- }
109
- const mapCache = new Map();
110
- async function loadSourceMap(url) {
111
- const cached = mapCache.get(url);
112
- if (cached)
113
- return cached;
114
- const p = (async () => {
115
- try {
116
- const u = new URL(url, location.href);
117
- if (u.protocol !== location.protocol || u.host !== location.host)
118
- return null;
119
- const res = await fetch(url + '.map');
120
- if (!res.ok)
121
- return null;
122
- const json = await res.json();
123
- if (!json || typeof json.mappings !== 'string')
124
- return null;
125
- return { sources: json.sources || [], lines: decodeMappings(json.mappings) };
126
- }
127
- catch {
128
- return null;
129
- }
130
- })();
131
- mapCache.set(url, p);
132
- return p;
133
- }
134
- /** Parses a V8/Firefox stack line into its script location, if present. */
135
- export function parseStackFrame(line) {
136
- const patterns = [
137
- /^(.*?)((?:[a-z][a-z0-9+.-]*:)?\/\/[^\s)]+|\/[^\s):]+):(\d+):(\d+)(.*)$/,
138
- ];
139
- for (const re of patterns) {
140
- const m = re.exec(line);
141
- if (!m)
142
- continue;
143
- return { prefix: m[1], url: m[2], line: Number(m[3]), col: Number(m[4]), suffix: m[5] };
144
- }
145
- return null;
146
- }
147
- function remapLocation(map, line, col) {
148
- let best = null;
149
- const segs = map.lines[line - 1];
150
- if (segs && segs.length > 0) {
151
- for (const s of segs) {
152
- if (s.genCol <= col - 1)
153
- best = s;
154
- else
155
- break;
156
- }
157
- if (!best)
158
- best = segs[0];
159
- }
160
- else {
161
- // An unminified hydration map has a mapping only where a marker starts;
162
- // it holds until the next one, so a line without any takes the last
163
- // mapping before it.
164
- for (let i = Math.min(line - 1, map.lines.length) - 1; i >= 0 && !best; i--) {
165
- const prev = map.lines[i];
166
- if (prev && prev.length > 0)
167
- best = prev[prev.length - 1];
168
- }
169
- if (!best)
170
- return null;
171
- }
172
- if (best.src < 0)
173
- return null;
174
- const source = map.sources[best.src] || '';
175
- return { source, line: best.srcLine + 1, col: best.srcCol + 1 };
176
- }
177
- /** Rewrites each mappable frame of a stack trace to its original location. */
178
- export async function symbolicateStack(stack) {
179
- if (!stack || !stack.includes('.js'))
180
- return stack;
181
- const lines = stack.split('\n');
182
- const out = await Promise.all(lines.map(async (line) => {
183
- const frame = parseStackFrame(line);
184
- if (!frame)
185
- return line;
186
- const map = await loadSourceMap(frame.url);
187
- if (!map)
188
- return line;
189
- const loc = remapLocation(map, frame.line, frame.col);
190
- // The generic label of a compiler-generated bundle says nothing more
191
- // than the frame's own file and line.
192
- if (!loc || !loc.source || loc.source === 'krate-hydration.js')
193
- return line;
194
- return frame.prefix + loc.source + ':' + loc.line + ':' + loc.col + frame.suffix;
195
- }));
196
- return out.join('\n');
197
- }
198
- /**
199
- * Route matcher: a segment starting with `[` matches anything; `[...x]` matches
200
- * the rest. Exported (pure) for testing.
201
- */
202
- function formatArg(a) {
203
- if (a instanceof Error)
204
- return a.message || String(a);
205
- if (typeof a === 'string')
206
- return a;
207
- try {
208
- return JSON.stringify(a) ?? String(a);
209
- }
210
- catch {
211
- return String(a);
212
- }
213
- }
214
- export function routeMatches(pattern, pathname, basePath = '') {
215
- const a = norm(stripBase(pathname, basePath)).split('/');
216
- const b = norm(pattern).split('/');
217
- for (let i = 0; i < b.length; i++) {
218
- const s = b[i];
219
- if (s.charAt(0) === '[') {
220
- if (s.indexOf('[...') === 0)
221
- return true;
222
- continue;
223
- }
224
- if (s !== a[i])
225
- return false;
226
- }
227
- return a.length === b.length;
228
- }
229
- /**
230
- * Splits a buffer of Krate frames (u32 length, JSON, u16 blob count, blobs)
231
- * into its complete JSON values. `rest` is the incomplete tail to prepend to
232
- * the next chunk. Exported (pure) for testing.
233
- */
234
- export function parseFrames(buf) {
235
- const values = [];
236
- const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
237
- const td = new TextDecoder();
238
- let pos = 0;
239
- while (buf.length - pos >= 4) {
240
- const n = view.getUint32(pos);
241
- let end = pos + 4 + n;
242
- if (buf.length < end + 2)
243
- break;
244
- const json = td.decode(buf.subarray(pos + 4, end));
245
- const blobs = view.getUint16(end);
246
- end += 2;
247
- let complete = true;
248
- for (let i = 0; i < blobs; i++) {
249
- if (buf.length < end + 4) {
250
- complete = false;
251
- break;
252
- }
253
- end += 4 + view.getUint32(end);
254
- if (buf.length < end) {
255
- complete = false;
256
- break;
257
- }
258
- }
259
- if (!complete)
260
- break;
261
- try {
262
- values.push(JSON.parse(json));
263
- }
264
- catch {
265
- /* skip a malformed frame */
266
- }
267
- pos = end;
268
- }
269
- return { values, rest: buf.subarray(pos) };
270
- }
271
- /** The host-side stack a KrateError carries in dev (`data.stack`), or "". */
272
- export function hostStackOf(reason) {
273
- const data = reason?.data;
274
- const stack = data && typeof data === 'object' ? data.stack : undefined;
275
- return typeof stack === 'string' ? stack : '';
276
- }
277
- /** One line of the Host panel. Exported (pure) for testing. */
278
- export function hostEventLine(ev) {
279
- const t = ev.time ? new Date(ev.time).toLocaleTimeString() : '';
280
- const dur = ev.durNs ? (ev.durNs / 1e6 >= 10 ? Math.round(ev.durNs / 1e6) : Math.round(ev.durNs / 1e5) / 10) + 'ms' : '';
281
- const err = ev.code ? ' ' + ev.code + (ev.message ? ': ' + ev.message : '') : '';
282
- return [t, ev.kind, ev.fn, dur].filter(Boolean).join(' ') + err;
283
- }
284
- /** Format a byte count for the Memory panel. Exported (pure) for testing. */
285
- export function formatBytes(n) {
286
- if (!Number.isFinite(n) || n < 0)
287
- return 'n/a';
288
- if (n >= 1 << 30)
289
- return (n / (1 << 30)).toFixed(2) + ' GiB';
290
- if (n >= 1 << 20)
291
- return (n / (1 << 20)).toFixed(1) + ' MiB';
292
- if (n >= 1 << 10)
293
- return Math.round(n / (1 << 10)) + ' KiB';
294
- return Math.round(n) + ' B';
295
- }
296
- /**
297
- * The JS heap of this page, or null where the engine does not expose it.
298
- * Chromium has performance.memory; WebKit (the engine of the Linux and macOS
299
- * webviews) has no heap size API, so the panel shows the web process row
300
- * (PSS and private dirty, which include the JS heap) instead.
301
- */
302
- export function jsHeapBytes() {
303
- const m = (typeof performance !== 'undefined' ? performance.memory : undefined);
304
- return m && typeof m.usedJSHeapSize === 'number' ? m.usedJSHeapSize : null;
305
- }
306
- /** The rows of the Memory panel as [label, value] pairs. Exported (pure) for testing. */
307
- export function memoryRows(rep, domNodes, heap) {
308
- const rows = [];
309
- if (rep && rep.procs) {
310
- for (const p of rep.procs) {
311
- rows.push([p.role + ' (' + p.pid + ')', 'PSS ' + formatBytes(p.pss) + ' / private dirty ' + formatBytes(p.privateDirty)]);
312
- }
313
- if (rep.total)
314
- rows.push(['total', 'PSS ' + formatBytes(rep.total.pss) + ' / private dirty ' + formatBytes(rep.total.privateDirty)]);
315
- }
316
- else {
317
- rows.push(['processes', 'unavailable']);
318
- }
319
- rows.push(['DOM nodes', String(domNodes)]);
320
- rows.push(['JS heap', heap === null ? 'unavailable in this engine (see the web process row)' : formatBytes(heap)]);
321
- return rows;
322
- }
323
- const ICON_MEM = '<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" ' +
324
- 'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
325
- '<rect x="4" y="6" width="16" height="12" rx="1"/><path d="M8 10v4M12 10v4M16 10v4"/><path d="M7 18v2M12 18v2M17 18v2"/></svg>';
326
- const ICON_RELOAD = '<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" ' +
327
- 'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
328
- '<path d="M21 12a9 9 0 1 1-2.64-6.36"/><path d="M21 3v6h-6"/></svg>';
329
- const ICON_ALERT = '<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" ' +
330
- 'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
331
- '<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"/>' +
332
- '<path d="M12 9v4"/><path d="M12 17h.01"/></svg>';
333
- const ICON_HOST = '<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" ' +
334
- 'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
335
- '<rect x="3" y="4" width="18" height="12" rx="2"/><path d="M8 20h8"/><path d="M12 16v4"/></svg>';
336
- const STYLE = `
337
- :host { all: initial; }
338
- * { box-sizing: border-box; }
339
-
340
- /* palette */
341
- :host {
342
- --red: #f87171;
343
- --green: #34d399;
344
- --bg: #111111;
345
- --bg-2: #171717;
346
- --line: #2a2a2a;
347
- --fg: #e5e5e5;
348
- --muted: #a3a3a3;
349
- }
350
-
351
- /* toolbar */
352
- .toolbar {
353
- position: fixed; left: 50%; bottom: 0; z-index: 2147483001;
354
- transform: translate(-50%, 54%);
355
- transition: transform .28s cubic-bezier(.22,.61,.36,1),
356
- border-top-color .35s ease;
357
- display: flex; align-items: stretch; gap: 2px;
358
- background: var(--bg);
359
- border: 1px solid var(--line);
360
- border-top: 3px solid var(--green);
361
- border-radius: 16px 16px 0 0;
362
- padding: 7px 8px 9px;
363
- box-shadow: 0 -10px 30px rgba(0,0,0,.45);
364
- font: 12px/1.3 ui-sans-serif, system-ui, -apple-system, sans-serif;
365
- color: var(--fg);
366
- }
367
- .toolbar:hover, .toolbar:focus-within { transform: translate(-50%, 0); }
368
- .toolbar.bad { border-top-color: var(--red); }
369
-
370
- .tb-btn {
371
- display: flex; flex-direction: column; align-items: center; justify-content: center;
372
- gap: 3px; min-width: 56px; padding: 5px 10px;
373
- background: transparent; border: 1px solid transparent; border-radius: 11px;
374
- color: var(--muted); cursor: pointer; font: inherit;
375
- transition: color .15s ease, background .15s ease;
376
- }
377
- .tb-btn:hover { color: var(--fg); background: rgba(255,255,255,.06); }
378
- .tb-btn .ic { display: block; width: 18px; height: 18px; }
379
- .tb-btn .tb-label { font-size: 10px; letter-spacing: .02em; }
380
- .toolbar.bad .tb-btn.errors { color: var(--red); }
381
-
382
- .tb-center {
383
- display: flex; flex-direction: column; align-items: center; justify-content: center;
384
- gap: 1px; min-width: 130px; padding: 2px 16px;
385
- }
386
- .tb-center .brand { font-size: 12px; font-weight: 700; letter-spacing: .05em; color: #f3f4f6; }
387
- .tb-center .route {
388
- font-size: 10px; color: var(--muted);
389
- max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
390
- }
391
-
392
- /* overlay */
393
- .overlay {
394
- position: fixed; inset: 0; z-index: 2147483000;
395
- background: rgba(10, 10, 10, 0.72); backdrop-filter: blur(6px);
396
- display: flex; align-items: flex-start; justify-content: center;
397
- padding: 4vh 16px; overflow: auto;
398
- font: 13px/1.5 "SF Mono", Menlo, Monaco, Consolas, "Courier New", monospace;
399
- color: var(--fg);
400
- }
401
- .overlay[hidden] { display: none; }
402
- .card {
403
- width: min(920px, 100%); background: var(--bg);
404
- border: 1px solid var(--line);
405
- border-radius: 14px; box-shadow: 0 24px 64px rgba(0,0,0,0.5); overflow: hidden;
406
- }
407
- .card-head {
408
- display: flex; align-items: center; gap: 10px; padding: 14px 18px;
409
- border-bottom: 1px solid var(--line); background: var(--bg-2);
410
- }
411
- .title { font-weight: 600; font-size: 14px; color: var(--red); }
412
- .count { color: var(--muted); font-size: 12px; }
413
- .spacer { flex: 1; }
414
- .btn {
415
- border: 1px solid var(--line); background: transparent; color: var(--muted);
416
- border-radius: 9px; padding: 6px 12px; cursor: pointer; font: inherit; font-size: 12px;
417
- transition: color .15s ease, background .15s ease, border-color .15s ease;
418
- }
419
- .btn:hover { color: var(--fg); background: rgba(255,255,255,.06); border-color: #444444; }
420
- .list { padding: 6px 0; }
421
- .diag { padding: 14px 18px; border-bottom: 1px solid #1f1f1f; }
422
- .diag:last-child { border-bottom: none; }
423
- .actions { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
424
- .loc {
425
- display: inline-flex; align-items: center; gap: 6px; color: #60a5fa;
426
- background: transparent; border: none; padding: 0; cursor: pointer;
427
- font: inherit; font-size: 12px;
428
- }
429
- .loc:hover { text-decoration: underline; }
430
- .msg { color: #f3f4f6; white-space: pre-wrap; word-break: break-word; }
431
- .frame {
432
- margin-top: 10px; background: #0b0b0b; border: 1px solid #262626;
433
- border-radius: 7px; padding: 8px 10px; overflow-x: auto; white-space: pre;
434
- }
435
- .frame .src { color: #d4d4d4; }
436
- .frame .caret { color: var(--red); }
437
- .hint { margin-top: 8px; color: #a3e635; }
438
- .hostpanel {
439
- position: fixed; right: 12px; bottom: 12px; z-index: 2147483002;
440
- width: min(560px, calc(100vw - 24px)); max-height: 50vh; display: flex; flex-direction: column;
441
- background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
442
- box-shadow: 0 16px 48px rgba(0,0,0,.5); overflow: hidden;
443
- font: 12px/1.45 "SF Mono", Menlo, Monaco, Consolas, "Courier New", monospace; color: var(--fg);
444
- }
445
- .hostpanel[hidden] { display: none; }
446
- .hostpanel .card-head { padding: 8px 12px; }
447
- .hostrows { overflow: auto; padding: 4px 0; }
448
- .hostrow { padding: 2px 12px; white-space: pre-wrap; word-break: break-word; }
449
- .hostrow.err { color: var(--red); }
450
- .hostrow.sig { color: var(--muted); }
451
- .mempanel {
452
- position: fixed; right: 12px; bottom: 12px; z-index: 2147483002;
453
- width: min(460px, calc(100vw - 24px));
454
- background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
455
- box-shadow: 0 16px 48px rgba(0,0,0,.5); overflow: hidden;
456
- font: 12px/1.45 "SF Mono", Menlo, Monaco, Consolas, "Courier New", monospace; color: var(--fg);
457
- }
458
- .mempanel[hidden] { display: none; }
459
- .mempanel .card-head { padding: 8px 12px; }
460
- .memrow { display: flex; gap: 12px; justify-content: space-between; padding: 2px 12px; }
461
- .memrow .k { color: var(--muted); }
462
- .memrow .v { text-align: right; }
463
- .stack {
464
- margin-top: 10px; color: var(--muted); white-space: pre-wrap; word-break: break-word;
465
- max-height: 320px; overflow: auto;
466
- }
467
- `;
468
- class KrateDev {
469
- constructor() {
470
- this.cfg = devConfig();
471
- this.buildDiags = [];
472
- this.runtimeErrors = [];
473
- this.hostSeq = 0;
474
- this.seen = new Set();
475
- }
476
- init() {
477
- const host = document.createElement('div');
478
- host.id = 'krate-dev-root';
479
- (document.body || document.documentElement).appendChild(host);
480
- this.shadow = host.attachShadow({ mode: 'open' });
481
- const style = document.createElement('style');
482
- style.textContent = STYLE;
483
- this.shadow.appendChild(style);
484
- this.overlay = document.createElement('div');
485
- this.overlay.className = 'overlay';
486
- this.overlay.hidden = true;
487
- this.overlay.innerHTML =
488
- '<div class="card"><div class="card-head">' +
489
- '<span class="title"></span><span class="count"></span>' +
490
- '<span class="spacer"></span>' +
491
- '<button class="btn close" type="button">Dismiss (Esc)</button></div>' +
492
- '<div class="list"></div></div>';
493
- this.shadow.appendChild(this.overlay);
494
- this.title = this.overlay.querySelector('.title');
495
- this.list = this.overlay.querySelector('.list');
496
- if (this.cfg.toolbar) {
497
- this.toolbar = document.createElement('div');
498
- this.toolbar.className = 'toolbar';
499
- this.toolbar.innerHTML =
500
- '<button class="tb-btn errors" type="button" title="Show errors">' +
501
- ICON_ALERT +
502
- '<span class="tb-label">Errors</span></button>' +
503
- (this.cfg.events
504
- ? '<button class="tb-btn host" type="button" title="Host calls">' + ICON_HOST + '<span class="tb-label">Host</span></button>'
505
- : '') +
506
- '<div class="tb-center"><span class="brand">krate</span>' +
507
- '<span class="route"></span></div>' +
508
- (this.cfg.memory
509
- ? '<button class="tb-btn mem" type="button" title="Memory">' + ICON_MEM + '<span class="tb-label">Memory</span></button>'
510
- : '') +
511
- '<button class="tb-btn reload" type="button" title="Reload">' +
512
- ICON_RELOAD +
513
- '<span class="tb-label">Reload</span></button>';
514
- this.shadow.appendChild(this.toolbar);
515
- this.routeEl = this.toolbar.querySelector('.route');
516
- this.routeEl.textContent = location.pathname;
517
- this.watchLocation();
518
- }
519
- this.shadow.addEventListener('click', (e) => this.onClick(e));
520
- document.addEventListener('keydown', (e) => {
521
- if (e.key === 'Escape')
522
- this.hide();
523
- });
524
- if (this.cfg.frames)
525
- this.connectFrames();
526
- else
527
- this.connectSSE();
528
- this.captureRuntimeErrors();
529
- }
530
- onClick(e) {
531
- const t = e.target.closest('.btn, .loc, .tb-btn');
532
- if (!t)
533
- return;
534
- // Toolbar buttons are inside a `:focus-within` container that keeps the
535
- // half-hidden toolbar raised; blur after acting so a click (with no errors
536
- // to show) lets it slide back down. Keyboard focus still raises it.
537
- if (t.classList.contains('tb-btn'))
538
- t.blur();
539
- if (t.classList.contains('close')) {
540
- this.hide();
541
- return;
542
- }
543
- if (t.classList.contains('errors') || t.classList.contains('toggle')) {
544
- if (this.overlay.hidden)
545
- this.show();
546
- else
547
- this.hide();
548
- return;
549
- }
550
- if (t.classList.contains('host')) {
551
- this.toggleHost();
552
- return;
553
- }
554
- if (t.classList.contains('mem')) {
555
- this.toggleMemory();
556
- return;
557
- }
558
- if (t.classList.contains('memclose')) {
559
- this.toggleMemory(false);
560
- return;
561
- }
562
- if (t.classList.contains('hostclose')) {
563
- this.toggleHost(false);
564
- return;
565
- }
566
- if (t.classList.contains('reload')) {
567
- location.reload();
568
- return;
569
- }
570
- if (t.classList.contains('loc') || t.classList.contains('open')) {
571
- this.openInEditor(t.getAttribute('data-file') || '', t.getAttribute('data-line') || '');
572
- }
573
- }
574
- openInEditor(file, line) {
575
- if (!file)
576
- return;
577
- const url = this.cfg.open + '?file=' + encodeURIComponent(file) + '&line=' + encodeURIComponent(line);
578
- fetch(url).catch(() => { });
579
- }
580
- /** Keep the toolbar route label in sync with SPA (history) navigation. */
581
- watchLocation() {
582
- const update = () => {
583
- if (this.routeEl)
584
- this.routeEl.textContent = location.pathname;
585
- };
586
- window.addEventListener('popstate', update);
587
- const h = history;
588
- const push = h.pushState.bind(history);
589
- h.pushState = function (...args) {
590
- const r = push(...args);
591
- update();
592
- return r;
593
- };
594
- const replace = h.replaceState.bind(history);
595
- h.replaceState = function (...args) {
596
- const r = replace(...args);
597
- update();
598
- return r;
599
- };
600
- // Safety net for routers that swap content without touching history.
601
- setInterval(update, 500);
602
- }
603
- connectSSE() {
604
- let sse;
605
- try {
606
- sse = new EventSource(this.cfg.sse);
607
- }
608
- catch {
609
- return;
610
- }
611
- let connectedOnce = false;
612
- sse.addEventListener('connected', () => {
613
- // A second "connected" means the stream dropped and came back: the dev
614
- // server restarted (config or env change), so the page is stale.
615
- if (connectedOnce)
616
- location.reload();
617
- connectedOnce = true;
618
- });
619
- const parse = (e) => {
620
- try {
621
- return JSON.parse(e.data);
622
- }
623
- catch {
624
- return null;
625
- }
626
- };
627
- sse.addEventListener('reload', (e) => this.onReload(parse(e)));
628
- sse.addEventListener('build-error', (e) => this.onBuildError(parse(e)));
629
- sse.addEventListener('client-error', (e) => this.onClientError(parse(e)));
630
- }
631
- /**
632
- * Krate Native: the same events as SSE, as `{hmr: {type, ...}}` frames on a
633
- * streaming fetch. Reconnects after the stream ends; a second "connected"
634
- * means the shell restarted, so the page is stale.
635
- */
636
- connectFrames() {
637
- let connectedOnce = false;
638
- const run = async () => {
639
- const res = await fetch(this.cfg.frames, { cache: 'no-store' });
640
- if (!res.ok || !res.body)
641
- throw new Error('hmr stream unavailable');
642
- const reader = res.body.getReader();
643
- let buf = new Uint8Array(0);
644
- for (;;) {
645
- const { done, value } = await reader.read();
646
- if (done)
647
- return;
648
- const joined = new Uint8Array(buf.length + value.length);
649
- joined.set(buf);
650
- joined.set(value, buf.length);
651
- const parsed = parseFrames(joined);
652
- buf = parsed.rest;
653
- for (const v of parsed.values) {
654
- const m = v?.hmr;
655
- if (!m || typeof m !== 'object')
656
- continue;
657
- if (m.type === 'connected') {
658
- if (connectedOnce)
659
- location.reload();
660
- connectedOnce = true;
661
- }
662
- else if (m.type === 'reload')
663
- this.onReload(m);
664
- else if (m.type === 'build-error')
665
- this.onBuildError(m);
666
- else if (m.type === 'client-error')
667
- this.onClientError(m);
668
- }
669
- }
670
- };
671
- const loop = () => {
672
- run().then(() => setTimeout(loop, 1000), () => setTimeout(loop, 1000));
673
- };
674
- loop();
675
- }
676
- onReload(d) {
677
- // A rebuild without diagnostics supersedes any compile error on screen,
678
- // whichever route it touched.
679
- if (this.buildDiags.length > 0) {
680
- this.buildDiags = [];
681
- this.setStatus(true);
682
- this.render();
683
- }
684
- let cssOnly = false;
685
- if (d) {
686
- cssOnly = d.cssOnly === true;
687
- const pages = d.pages;
688
- if (pages &&
689
- Array.isArray(pages) &&
690
- !pages.some((p) => p === '/404' || p === '/500' || routeMatches(p, location.pathname, this.cfg.basePath))) {
691
- return;
692
- }
693
- }
694
- if (cssOnly) {
695
- this.swapStylesheets().catch(() => location.reload());
696
- return;
697
- }
698
- location.reload();
699
- }
700
- onBuildError(d) {
701
- this.buildDiags = d && Array.isArray(d.diagnostics) ? d.diagnostics : [];
702
- this.setStatus(this.buildDiags.length === 0);
703
- this.render();
704
- }
705
- onClientError(d) {
706
- if (!d || !d.clientError)
707
- return;
708
- const err = d.clientError;
709
- // This tab reported the error itself and already shows it.
710
- if (this.seen.has(err.message + '|' + (err.stack || '')))
711
- return;
712
- this.addRuntime('Runtime Error', err.message, err.stack);
713
- }
714
- toggleHost(force) {
715
- if (!this.cfg.events)
716
- return;
717
- if (!this.hostPanel) {
718
- const el = document.createElement('div');
719
- el.className = 'hostpanel';
720
- el.hidden = true;
721
- el.innerHTML =
722
- '<div class="card-head"><span class="title" style="color:inherit">Host calls</span>' +
723
- '<span class="spacer"></span><button class="btn hostclose" type="button">Close</button></div>' +
724
- '<div class="hostrows"></div>';
725
- this.shadow.appendChild(el);
726
- this.hostPanel = el;
727
- this.hostRows = el.querySelector('.hostrows');
728
- }
729
- const open = force ?? this.hostPanel.hidden;
730
- this.hostPanel.hidden = !open;
731
- if (this.hostTimer)
732
- clearInterval(this.hostTimer);
733
- this.hostTimer = undefined;
734
- if (open) {
735
- void this.pollHost();
736
- this.hostTimer = setInterval(() => void this.pollHost(), 1000);
737
- }
738
- }
739
- /** The Memory panel samples only while it is open (every 2 seconds). */
740
- toggleMemory(force) {
741
- if (!this.cfg.memory)
742
- return;
743
- if (!this.memPanel) {
744
- const el = document.createElement('div');
745
- el.className = 'mempanel';
746
- el.hidden = true;
747
- el.innerHTML =
748
- '<div class="card-head"><span class="title" style="color:inherit">Memory</span>' +
749
- '<span class="spacer"></span><button class="btn memclose" type="button">Close</button></div>' +
750
- '<div class="memrows"></div>';
751
- this.shadow.appendChild(el);
752
- this.memPanel = el;
753
- this.memRows = el.querySelector('.memrows');
754
- }
755
- const open = force ?? this.memPanel.hidden;
756
- this.memPanel.hidden = !open;
757
- if (this.memTimer)
758
- clearInterval(this.memTimer);
759
- this.memTimer = undefined;
760
- if (open) {
761
- void this.pollMemory();
762
- this.memTimer = setInterval(() => void this.pollMemory(), 2000);
763
- }
764
- }
765
- async pollMemory() {
766
- let rep = null;
767
- try {
768
- const res = await fetch(this.cfg.memory, { cache: 'no-store' });
769
- if (res.ok)
770
- rep = (await res.json());
771
- }
772
- catch {
773
- /* the panel is best-effort */
774
- }
775
- const rows = memoryRows(rep, document.getElementsByTagName('*').length, jsHeapBytes());
776
- this.memRows.innerHTML = rows
777
- .map(([k, v]) => '<div class="memrow"><span class="k">' + esc(k) + '</span><span class="v">' + esc(v) + '</span></div>')
778
- .join('');
779
- }
780
- async pollHost() {
781
- try {
782
- const res = await fetch(this.cfg.events + '?since=' + this.hostSeq, { cache: 'no-store' });
783
- if (!res.ok)
784
- return;
785
- const parsed = parseFrames(new Uint8Array(await res.arrayBuffer()));
786
- const rows = this.hostRows;
787
- const pinned = rows.scrollTop + rows.clientHeight >= rows.scrollHeight - 8;
788
- for (const v of parsed.values) {
789
- const ev = v?.ev;
790
- if (!ev)
791
- continue;
792
- this.hostSeq = Math.max(this.hostSeq, ev.seq);
793
- const row = document.createElement('div');
794
- row.className = 'hostrow' + (ev.code ? ' err' : ev.kind === 'signal' ? ' sig' : '');
795
- row.textContent = hostEventLine(ev);
796
- rows.appendChild(row);
797
- }
798
- while (rows.childElementCount > 200)
799
- rows.firstElementChild.remove();
800
- if (pinned)
801
- rows.scrollTop = rows.scrollHeight;
802
- }
803
- catch {
804
- /* the panel is best-effort */
805
- }
806
- }
807
- /**
808
- * Apply a CSS-only rebuild without a full reload: fetch the freshly built
809
- * document, add its stylesheet links, and drop the ones it no longer has.
810
- * Inline <style> changes cannot be diffed safely, so they fall back to a
811
- * reload (the caller reloads when this rejects).
812
- */
813
- async swapStylesheets() {
814
- const res = await fetch(location.href, { cache: 'no-store', headers: { Accept: 'text/html' } });
815
- if (!res.ok)
816
- throw new Error('fetch failed');
817
- const next = new DOMParser().parseFromString(await res.text(), 'text/html');
818
- const inline = (d) => Array.from(d.querySelectorAll('style'))
819
- .map((el) => el.textContent || '')
820
- .join('\u0000');
821
- if (inline(next) !== inline(document))
822
- throw new Error('inline styles changed');
823
- const abs = (href) => new URL(href, location.href).href;
824
- const want = Array.from(next.querySelectorAll('link[rel~="stylesheet"]')).map((l) => abs(l.getAttribute('href') || ''));
825
- const current = Array.from(document.querySelectorAll('link[rel~="stylesheet"]'));
826
- const have = new Set(current.map((l) => abs(l.getAttribute('href') || '')));
827
- const loads = [];
828
- for (const href of want) {
829
- if (have.has(href))
830
- continue;
831
- const link = document.createElement('link');
832
- link.rel = 'stylesheet';
833
- link.href = href;
834
- loads.push(new Promise((resolve, reject) => {
835
- link.onload = () => resolve();
836
- link.onerror = () => reject(new Error('stylesheet failed'));
837
- }));
838
- document.head.appendChild(link);
839
- }
840
- await Promise.all(loads);
841
- const keep = new Set(want);
842
- for (const l of current) {
843
- if (!keep.has(abs(l.getAttribute('href') || '')))
844
- l.remove();
845
- }
846
- // A same-named stylesheet is cache-busted in place.
847
- for (const l of current) {
848
- const href = abs(l.getAttribute('href') || '');
849
- if (!keep.has(href) || !l.isConnected)
850
- continue;
851
- const u = new URL(href);
852
- u.searchParams.set('_krate', String(Date.now()));
853
- l.href = u.href;
854
- }
855
- }
856
- captureRuntimeErrors() {
857
- window.addEventListener('error', (e) => this.onError(e));
858
- window.addEventListener('unhandledrejection', (e) => this.onRejection(e));
859
- // A script or stylesheet that fails to load fires on its element and does
860
- // not bubble, so only the capture phase sees it.
861
- window.addEventListener('error', (e) => this.onResourceError(e), true);
862
- this.captureConsole();
863
- // This bundle loads after the page script, so the page's first render ran
864
- // before these listeners existed. The head buffers what happened until now.
865
- const early = window.__KRATE_EARLY_ERRORS__;
866
- window.__KRATE_EARLY_ERRORS__ = undefined;
867
- for (const e of early ?? []) {
868
- if (e.type === 'console')
869
- this.onConsole(e.message, e.stack);
870
- else if (e.type === 'error' && e.target && e.target !== window)
871
- this.onResourceError(e);
872
- else if (e.type === 'error')
873
- this.onError(e);
874
- else
875
- this.onRejection(e);
876
- }
877
- }
878
- captureConsole() {
879
- const c = console;
880
- const orig = c.error;
881
- c.error = (...args) => {
882
- try {
883
- const first = args.find((a) => a instanceof Error);
884
- this.onConsole(args.map(formatArg).join(' '), first?.stack);
885
- }
886
- catch {
887
- /* never break the page's own logging */
888
- }
889
- return orig.apply(c, args);
890
- };
891
- }
892
- onConsole(message, stack) {
893
- this.report({ message, stack, url: location.href, kind: 'console' });
894
- this.addRuntime('console.error', message, stack);
895
- }
896
- onResourceError(e) {
897
- const t = e.target;
898
- if (!t || t === window || !t.tagName)
899
- return;
900
- const src = t.src || t.href || '';
901
- if (!src)
902
- return;
903
- const message = 'failed to load <' + t.tagName.toLowerCase() + '> ' + src;
904
- this.report({ message, url: src, kind: 'resource' });
905
- this.addRuntime('Resource Error', message);
906
- }
907
- onError(e) {
908
- const stack = e.error?.stack || '';
909
- const message = e.message || 'Unknown error';
910
- const hostStack = hostStackOf(e.error);
911
- this.report({
912
- message,
913
- stack: hostStack ? stack + '\nHost stack:\n' + hostStack : stack,
914
- url: e.filename,
915
- line: e.lineno,
916
- col: e.colno,
917
- kind: 'error',
918
- });
919
- this.addRuntime('Runtime Error', message, stack, hostStack);
920
- }
921
- onRejection(e) {
922
- const reason = e.reason;
923
- const message = reason instanceof Error ? reason.message : String(reason);
924
- const stack = reason instanceof Error ? reason.stack : '';
925
- const hostStack = hostStackOf(reason);
926
- this.report({ message, stack: hostStack ? (stack || '') + '\nHost stack:\n' + hostStack : stack, url: location.href, kind: 'unhandledrejection' });
927
- this.addRuntime('Unhandled Promise Rejection', message, stack, hostStack);
928
- }
929
- report(payload) {
930
- const key = payload.message + '|' + (payload.stack || '');
931
- if (this.seen.has(key))
932
- return;
933
- this.seen.add(key);
934
- const win = globalThis.__KRATE_WINDOW__;
935
- if (typeof win === 'string' && win)
936
- payload.window = win;
937
- if (!payload.stack || !payload.stack.includes('.js')) {
938
- this.send(payload);
939
- return;
940
- }
941
- // Map the stack to the sources before it reaches the terminal, but never
942
- // hold the report back for long: the source maps are best-effort.
943
- const raw = payload.stack;
944
- Promise.race([symbolicateStack(raw), new Promise((r) => setTimeout(() => r(raw), 1500))])
945
- .catch(() => raw)
946
- .then((stack) => this.send({ ...payload, stack }));
947
- }
948
- send(payload) {
949
- const body = JSON.stringify(payload);
950
- // sendBeacon throws on the custom scheme of a native webview (WebKitGTK),
951
- // so a failed or absent beacon falls back to fetch.
952
- try {
953
- if (!this.cfg.frames && navigator.sendBeacon) {
954
- if (navigator.sendBeacon(this.cfg.errors, new Blob([body], { type: 'application/json' })))
955
- return;
956
- }
957
- }
958
- catch {
959
- /* fall through to fetch */
960
- }
961
- try {
962
- fetch(this.cfg.errors, { method: 'POST', body, headers: { 'Content-Type': 'application/json' }, keepalive: true }).catch(() => { });
963
- }
964
- catch {
965
- /* reporting is best-effort */
966
- }
967
- }
968
- addRuntime(title, message, stack, hostStack) {
969
- const entry = { title, message, stack, hostStack };
970
- this.runtimeErrors.push(entry);
971
- this.setStatus(false);
972
- this.render();
973
- // Render immediately with the raw stack, then upgrade in place if a source
974
- // map lets us point at the original location.
975
- if (stack) {
976
- void symbolicateStack(stack).then((mapped) => {
977
- if (mapped && mapped !== stack) {
978
- entry.stack = mapped;
979
- this.render();
980
- }
981
- });
982
- }
983
- }
984
- setStatus(ok) {
985
- if (!this.toolbar)
986
- return;
987
- this.toolbar.classList.toggle('bad', !ok);
988
- }
989
- frameHTML(d) {
990
- if (!d.source)
991
- return '';
992
- const col = Math.max(1, d.col || 1);
993
- const caret = ' '.repeat(col - 1) + '^';
994
- return '<div class="frame"><span class="src">' + esc(d.source) + '</span>\n<span class="caret">' + esc(caret) + '</span></div>';
995
- }
996
- diagHTML(d) {
997
- let actions = '';
998
- if (d.file) {
999
- const loc = d.file + (d.line ? ':' + d.line + (d.col ? ':' + d.col : '') : '');
1000
- actions =
1001
- '<div class="actions">' +
1002
- '<button class="loc" data-file="' + esc(d.file) + '" data-line="' + esc(d.line || '') + '">' + esc(loc) + '</button>' +
1003
- '<button class="btn open" data-file="' + esc(d.file) + '" data-line="' + esc(d.line || '') + '">Open in editor</button>' +
1004
- '</div>';
1005
- }
1006
- const hint = d.hint ? '<div class="hint">hint: ' + esc(d.hint) + '</div>' : '';
1007
- return '<div class="diag">' + actions + '<div class="msg">' + esc(d.message) + '</div>' + this.frameHTML(d) + hint + '</div>';
1008
- }
1009
- runtimeHTML(r) {
1010
- const host = r.hostStack ? '<div class="stack">Host stack:\n' + esc(r.hostStack) + '</div>' : '';
1011
- const stack = host + (r.stack ? '<div class="stack">' + esc(r.stack) + '</div>' : '');
1012
- return '<div class="diag"><div class="msg">' + esc(r.message) + '</div>' + stack + '</div>';
1013
- }
1014
- render() {
1015
- const total = this.buildDiags.length + this.runtimeErrors.length;
1016
- if (total === 0) {
1017
- this.hide();
1018
- return;
1019
- }
1020
- this.title.textContent = this.buildDiags.length > 0 ? 'Compilation failed' : 'Runtime error';
1021
- let html = '';
1022
- for (const d of this.buildDiags)
1023
- html += this.diagHTML(d);
1024
- for (const r of this.runtimeErrors)
1025
- html += this.runtimeHTML(r);
1026
- this.list.innerHTML = html;
1027
- this.overlay.querySelector('.count').textContent = total > 1 ? String(total) : '';
1028
- if (this.cfg.overlay)
1029
- this.overlay.hidden = false;
1030
- }
1031
- show() {
1032
- if (this.buildDiags.length + this.runtimeErrors.length > 0)
1033
- this.overlay.hidden = false;
1034
- }
1035
- hide() {
1036
- this.overlay.hidden = true;
1037
- }
1038
- }
8
+ import { KrateDev } from './dev/app.js';
9
+ export { KrateDev } from './dev/app.js';
10
+ export { isNativeOrigin, routeMatches } from './dev/util.js';
11
+ export { decodeVLQ, decodeMappings, parseStackFrame, symbolicateStack } from './dev/sourcemap.js';
12
+ export { parseFrames, hostStackOf, hostEventLine, formatBytes, jsHeapBytes, memoryRows } from './dev/native.js';
1039
13
  /** Initialise the dev overlay. Safe to call more than once. */
1040
14
  export function initDevOverlay() {
1041
15
  if (typeof window === 'undefined' || typeof document === 'undefined')
1042
- return;
16
+ return undefined;
1043
17
  if (window.__krate_dev_overlay)
1044
- return;
18
+ return undefined;
1045
19
  window.__krate_dev_overlay = true;
1046
20
  try {
1047
- new KrateDev().init();
21
+ const app = new KrateDev();
22
+ app.init();
23
+ // The instance, for debugging from the console and for browser tests.
24
+ window.__krate_dev_overlay = app;
25
+ return app;
1048
26
  }
1049
27
  catch (err) {
1050
28
  // Never let the dev tooling break the app.
1051
29
  console.error('[krate] dev overlay failed to initialise', err);
30
+ return undefined;
1052
31
  }
1053
32
  }
1054
33
  if (typeof window !== 'undefined' && typeof document !== 'undefined') {
1055
34
  if (document.readyState === 'loading') {
1056
- document.addEventListener('DOMContentLoaded', initDevOverlay, { once: true });
35
+ document.addEventListener('DOMContentLoaded', () => initDevOverlay(), { once: true });
1057
36
  }
1058
37
  else {
1059
38
  initDevOverlay();