noofpi 1.2.0 → 2.0.1

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 (42) hide show
  1. package/README.md +20 -4
  2. package/dist/{build-25H52PWT.js → build-WPHZ7TYZ.js} +5 -4
  3. package/dist/chunk-3PSMWWUB.js +68 -0
  4. package/dist/{chunk-NALDZ3PS.js → chunk-I6TFIGFO.js} +13 -5
  5. package/dist/{chunk-NX6BO7UB.js → chunk-IE3WF5XF.js} +82 -2
  6. package/dist/{chunk-FIJJ3EGL.js → chunk-MN5PVHC5.js} +4 -0
  7. package/dist/{chunk-UF6YTIXD.js → chunk-NHBXVKEQ.js} +368 -130
  8. package/dist/chunk-OKNF6XDO.js +14 -0
  9. package/dist/chunk-PPUFFGCH.js +168 -0
  10. package/dist/{chunk-WX2V6EYH.js → chunk-RUNIVVFH.js} +34 -10
  11. package/dist/{chunk-2XCZWFIQ.js → chunk-X3DYEZLK.js} +1 -1
  12. package/dist/{chunk-4YOOGEOF.js → chunk-YJVMBHNL.js} +1 -1
  13. package/dist/cli.js +130 -34
  14. package/dist/{dev-CC3RXV3G.js → dev-OAGCOGHA.js} +47 -59
  15. package/dist/devtools-PLUN2DYV.js +958 -0
  16. package/dist/handler-C6NnwBfC.d.ts +17 -0
  17. package/dist/index.d.ts +21 -1
  18. package/dist/index.js +2 -2
  19. package/dist/{validation-ClXd_DAW.d.ts → payload-CL6tYBin.d.ts} +2 -40
  20. package/dist/prepare-BN7NMCVQ.js +24 -0
  21. package/dist/runtime/default-app.d.ts +6 -0
  22. package/dist/runtime/entry-client.d.ts +3 -0
  23. package/dist/runtime/entry-client.js +18 -7
  24. package/dist/runtime/entry-server.d.ts +8 -0
  25. package/dist/runtime/entry-server.js +2 -2
  26. package/dist/runtime/index.d.ts +7 -8
  27. package/dist/runtime/index.js +2 -2
  28. package/dist/runtime/routes.d.ts +13 -0
  29. package/dist/runtime/silent-diagnostics.d.ts +5 -0
  30. package/dist/server/bun.d.ts +15 -0
  31. package/dist/server/bun.js +14 -11
  32. package/dist/server/index.d.ts +9 -90
  33. package/dist/server/index.js +2 -2
  34. package/dist/server/node.d.ts +20 -0
  35. package/dist/server/node.js +2 -2
  36. package/dist/{start-PARBW5KN.js → start-ITRND3BY.js} +11 -7
  37. package/dist/typecheck-QACZZ6FN.js +30 -0
  38. package/dist/types-B6rQOOxS.d.ts +76 -0
  39. package/dist/validation-Dwpex2JZ.d.ts +40 -0
  40. package/package.json +24 -8
  41. package/dist/chunk-KGZP2RCF.js +0 -51
  42. package/dist/devtools-KTDSD5PR.js +0 -564
@@ -0,0 +1,958 @@
1
+ import {
2
+ DEV_ERRORS_ELEMENT_ID,
3
+ parseDevErrors,
4
+ toDevError
5
+ } from "./chunk-3PSMWWUB.js";
6
+ import {
7
+ normalizeMiddleware,
8
+ parseMiddlewareFile
9
+ } from "./chunk-6OWKWAIW.js";
10
+ import {
11
+ isServerRendered,
12
+ matchRouteRules,
13
+ resolveFetchMode
14
+ } from "./chunk-MN5PVHC5.js";
15
+
16
+ // src/runtime/devtools.ts
17
+ import {
18
+ computed,
19
+ createApp,
20
+ defineComponent,
21
+ h,
22
+ reactive,
23
+ ref,
24
+ watch
25
+ } from "vue";
26
+ function inspectRoute(route, config, middlewareFiles) {
27
+ const files = [...middlewareFiles].sort().map(parseMiddlewareFile);
28
+ const known = new Set(files.map((file) => file.name));
29
+ const { layout } = route.meta;
30
+ return {
31
+ path: route.path,
32
+ pattern: route.matched.at(-1)?.path ?? "(no match)",
33
+ layout: layout === false ? "none" : typeof layout === "string" ? layout : "default",
34
+ middleware: [
35
+ ...files.filter((file) => file.global).map((file) => ({
36
+ name: file.name,
37
+ scope: "global",
38
+ missing: false
39
+ })),
40
+ ...normalizeMiddleware(route.meta.middleware).map((name) => ({
41
+ name,
42
+ scope: "named",
43
+ missing: !known.has(name)
44
+ }))
45
+ ],
46
+ fetch: resolveFetchMode(config.doofpi.fetch, config.routeRules, route.path),
47
+ rendering: isServerRendered(config.ssr, config.routeRules, route.path) ? "server" : "client",
48
+ rule: matchRouteRules(config.routeRules, route.path)
49
+ };
50
+ }
51
+ function listRoutes(records, config, middlewareFiles) {
52
+ return records.map(
53
+ (record) => inspectRoute(
54
+ {
55
+ path: record.path,
56
+ matched: [record],
57
+ meta: record.meta
58
+ },
59
+ config,
60
+ middlewareFiles
61
+ )
62
+ ).sort((a, b) => a.path.localeCompare(b.path));
63
+ }
64
+ var byteLength = (text) => new TextEncoder().encode(text).length;
65
+ function payloadEntry(key, value) {
66
+ const compact = JSON.stringify(value) ?? "undefined";
67
+ return {
68
+ key,
69
+ json: JSON.stringify(value, null, 2) ?? "undefined",
70
+ bytes: byteLength(compact)
71
+ };
72
+ }
73
+ function describePayload(payload) {
74
+ const entries = (values) => Object.entries(values ?? {}).map(([key, value]) => payloadEntry(key, value)).sort((a, b) => b.bytes - a.bytes);
75
+ const data = entries(payload.data);
76
+ const errors = entries(payload.errors);
77
+ const state = entries(payload.state);
78
+ const error = payload.error === void 0 ? void 0 : payloadEntry("error", payload.error);
79
+ return {
80
+ data,
81
+ errors,
82
+ state,
83
+ ...payload.locale ? { locale: payload.locale } : {},
84
+ ...error ? { error } : {},
85
+ bytes: [...data, ...errors, ...state, ...error ? [error] : []].reduce(
86
+ (sum, entry) => sum + entry.bytes,
87
+ 0
88
+ )
89
+ };
90
+ }
91
+ var formatBytes = (bytes) => bytes < 1024 ? `${bytes} B` : `${(bytes / 1024).toFixed(1)} KB`;
92
+ function describeRequest(entry, origin) {
93
+ const url = entry.url.startsWith(origin) ? entry.url.slice(origin.length) : entry.url;
94
+ const result = entry.error !== void 0 ? `failed: ${entry.error}` : entry.status === void 0 ? "pending" : String(entry.status);
95
+ return {
96
+ request: `${entry.method} ${url}`,
97
+ detail: [
98
+ entry.side,
99
+ entry.mode,
100
+ entry.transport,
101
+ result,
102
+ ...entry.ms === void 0 ? [] : [`${entry.ms}ms`]
103
+ ].join(" \xB7 ")
104
+ };
105
+ }
106
+ var MAX_VIOLATIONS = 50;
107
+ var MAX_ERRORS = 50;
108
+ var colors = {
109
+ bg: "rgba(24,24,27,.96)",
110
+ fg: "#e4e4e7",
111
+ dim: "#a1a1aa",
112
+ accent: "#42d392",
113
+ alert: "#f87171",
114
+ line: "rgba(255,255,255,.08)",
115
+ card: "rgba(255,255,255,.035)"
116
+ };
117
+ var sans = "ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif";
118
+ var mono = "ui-monospace, 'SF Mono', Menlo, Consolas, monospace";
119
+ var panelStyle = {
120
+ position: "fixed",
121
+ right: "12px",
122
+ bottom: "52px",
123
+ zIndex: "2147483647",
124
+ width: "380px",
125
+ height: "min(70vh, 460px)",
126
+ maxHeight: "70vh",
127
+ display: "flex",
128
+ flexDirection: "column",
129
+ overflow: "hidden",
130
+ boxSizing: "border-box",
131
+ background: colors.bg,
132
+ backdropFilter: "blur(12px)",
133
+ color: colors.fg,
134
+ font: `12px/1.5 ${sans}`,
135
+ borderRadius: "14px",
136
+ border: "1px solid rgba(66,211,146,.28)",
137
+ boxShadow: "0 16px 48px rgba(0,0,0,.55), 0 0 32px rgba(66,211,146,.1), inset 0 1px 0 rgba(255,255,255,.06)"
138
+ };
139
+ var headerStyle = {
140
+ display: "flex",
141
+ alignItems: "center",
142
+ gap: "10px",
143
+ padding: "12px 14px",
144
+ background: "linear-gradient(120deg, rgba(34,70,57,.9) 0%, rgba(24,24,27,0) 75%)",
145
+ borderBottom: `1px solid ${colors.line}`,
146
+ flexShrink: "0"
147
+ };
148
+ var bodyStyle = {
149
+ flex: "1 1 auto",
150
+ minHeight: "0",
151
+ overflow: "auto",
152
+ padding: "10px 12px 12px",
153
+ display: "flex",
154
+ flexDirection: "column",
155
+ gap: "10px"
156
+ };
157
+ var closeStyle = {
158
+ display: "grid",
159
+ placeItems: "center",
160
+ width: "24px",
161
+ height: "24px",
162
+ padding: "0",
163
+ background: "rgba(255,255,255,.06)",
164
+ border: `1px solid ${colors.line}`,
165
+ borderRadius: "50%",
166
+ color: colors.dim,
167
+ cursor: "pointer",
168
+ font: `16px/1 ${sans}`
169
+ };
170
+ var sectionStyle = {
171
+ background: colors.card,
172
+ border: `1px solid ${colors.line}`,
173
+ borderRadius: "10px",
174
+ padding: "8px 10px 10px"
175
+ };
176
+ var sectionTitleStyle = {
177
+ display: "flex",
178
+ alignItems: "center",
179
+ gap: "6px",
180
+ marginBottom: "6px",
181
+ color: colors.accent,
182
+ fontSize: "10px",
183
+ fontWeight: "700",
184
+ letterSpacing: ".1em",
185
+ textTransform: "uppercase"
186
+ };
187
+ var tones = {
188
+ accent: {
189
+ bg: "rgba(66,211,146,.14)",
190
+ fg: "#6ee7b7",
191
+ border: "rgba(66,211,146,.35)"
192
+ },
193
+ neutral: {
194
+ bg: "rgba(255,255,255,.06)",
195
+ fg: "#d4d4d8",
196
+ border: colors.line
197
+ },
198
+ alert: {
199
+ bg: "rgba(248,113,113,.14)",
200
+ fg: "#fca5a5",
201
+ border: "rgba(248,113,113,.4)"
202
+ }
203
+ };
204
+ var chipStyle = (tone) => ({
205
+ display: "inline-block",
206
+ padding: "1px 7px",
207
+ borderRadius: "999px",
208
+ background: tones[tone].bg,
209
+ color: tones[tone].fg,
210
+ border: `1px solid ${tones[tone].border}`,
211
+ fontSize: "10px",
212
+ fontWeight: "600",
213
+ letterSpacing: ".03em",
214
+ whiteSpace: "nowrap"
215
+ });
216
+ var buttonStyle = {
217
+ position: "fixed",
218
+ right: "12px",
219
+ bottom: "12px",
220
+ zIndex: "2147483647",
221
+ display: "inline-flex",
222
+ alignItems: "center",
223
+ gap: "8px",
224
+ height: "34px",
225
+ boxSizing: "border-box",
226
+ padding: "0 14px 0 12px",
227
+ background: "linear-gradient(135deg, rgba(34,70,57,.92) 0%, rgba(24,24,27,.92) 70%)",
228
+ backdropFilter: "blur(8px)",
229
+ color: colors.fg,
230
+ font: "600 12px/1 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif",
231
+ letterSpacing: ".02em",
232
+ border: "1px solid rgba(66,211,146,.4)",
233
+ borderRadius: "999px",
234
+ boxShadow: "0 6px 20px rgba(0,0,0,.35), 0 0 18px rgba(66,211,146,.18), inset 0 1px 0 rgba(255,255,255,.08)",
235
+ cursor: "grab",
236
+ touchAction: "none",
237
+ userSelect: "none"
238
+ };
239
+ var dotStyle = (color) => ({
240
+ width: "8px",
241
+ height: "8px",
242
+ borderRadius: "50%",
243
+ background: color,
244
+ boxShadow: `0 0 0 3px ${color}33, 0 0 10px ${color}`,
245
+ flexShrink: "0"
246
+ });
247
+ var badgeStyle = {
248
+ padding: "3px 7px",
249
+ borderRadius: "999px",
250
+ background: "rgba(248,113,113,.16)",
251
+ border: "1px solid rgba(248,113,113,.4)",
252
+ color: "#fca5a5",
253
+ fontSize: "10px",
254
+ fontWeight: "700",
255
+ letterSpacing: ".04em"
256
+ };
257
+ var alertColor = colors.alert;
258
+ var TABS = [
259
+ { id: "errors", label: "Errors" },
260
+ { id: "route", label: "Route" },
261
+ { id: "routes", label: "Routes" },
262
+ { id: "payload", label: "Payload" },
263
+ { id: "doofpi", label: "doofpi" },
264
+ { id: "csp", label: "CSP" }
265
+ ];
266
+ var tabsStyle = {
267
+ display: "flex",
268
+ gap: "2px",
269
+ padding: "6px 10px 0",
270
+ borderBottom: `1px solid ${colors.line}`,
271
+ flexShrink: "0",
272
+ overflowX: "auto"
273
+ };
274
+ var tabStyle = (active) => ({
275
+ display: "inline-flex",
276
+ alignItems: "center",
277
+ gap: "5px",
278
+ padding: "5px 9px",
279
+ background: "none",
280
+ border: "0",
281
+ borderBottom: `2px solid ${active ? colors.accent : "transparent"}`,
282
+ color: active ? colors.fg : colors.dim,
283
+ font: `600 11px/1.4 ${sans}`,
284
+ cursor: "pointer",
285
+ whiteSpace: "nowrap"
286
+ });
287
+ var codeStyle = {
288
+ margin: "4px 0 0",
289
+ padding: "6px 8px",
290
+ maxHeight: "160px",
291
+ overflow: "auto",
292
+ background: "rgba(0,0,0,.3)",
293
+ borderRadius: "6px",
294
+ fontFamily: mono,
295
+ fontSize: "11px",
296
+ whiteSpace: "pre-wrap",
297
+ wordBreak: "break-all"
298
+ };
299
+ var POSITION_KEY = "__noofpi_devtools_position";
300
+ var DRAG_THRESHOLD = 4;
301
+ var EDGE = 4;
302
+ var BUTTON_SIZE = { width: 140, height: 34 };
303
+ var PANEL_WIDTH = 380;
304
+ var PANEL_GAP = 10;
305
+ function clampPosition({ right, bottom }) {
306
+ return {
307
+ right: Math.max(
308
+ EDGE,
309
+ Math.min(right, window.innerWidth - BUTTON_SIZE.width - EDGE)
310
+ ),
311
+ bottom: Math.max(
312
+ EDGE,
313
+ Math.min(bottom, window.innerHeight - BUTTON_SIZE.height - EDGE)
314
+ )
315
+ };
316
+ }
317
+ function loadPosition() {
318
+ try {
319
+ const saved = JSON.parse(localStorage.getItem(POSITION_KEY) ?? "null");
320
+ if (typeof saved?.right === "number" && typeof saved?.bottom === "number") {
321
+ return clampPosition(saved);
322
+ }
323
+ } catch {
324
+ }
325
+ return { right: 12, bottom: 12 };
326
+ }
327
+ function savePosition(position) {
328
+ try {
329
+ localStorage.setItem(POSITION_KEY, JSON.stringify(position));
330
+ } catch {
331
+ }
332
+ }
333
+ function panelPlacement({ right, bottom }) {
334
+ const maxRight = Math.max(EDGE, window.innerWidth - PANEL_WIDTH - EDGE);
335
+ const horizontal = { right: `${Math.min(right, maxRight)}px` };
336
+ return bottom > window.innerHeight / 2 ? {
337
+ ...horizontal,
338
+ top: `${window.innerHeight - bottom + PANEL_GAP}px`,
339
+ bottom: "auto"
340
+ } : { ...horizontal, bottom: `${bottom + BUTTON_SIZE.height + PANEL_GAP}px` };
341
+ }
342
+ var Devtools = defineComponent({
343
+ name: "NoofpiDevtools",
344
+ props: {
345
+ router: { type: Object, required: true },
346
+ config: { type: Object, required: true },
347
+ middlewareFiles: { type: Array, required: true },
348
+ violations: {
349
+ type: Object,
350
+ required: true
351
+ },
352
+ requests: { type: Object, required: false },
353
+ payload: { type: Object, required: false },
354
+ errors: {
355
+ type: Object,
356
+ required: true
357
+ }
358
+ },
359
+ setup(props) {
360
+ const open = ref(false);
361
+ const tab = ref("route");
362
+ watch(
363
+ () => props.errors.list.length,
364
+ (length, previous = 0) => {
365
+ if (length > previous) {
366
+ open.value = true;
367
+ tab.value = "errors";
368
+ }
369
+ },
370
+ { immediate: true }
371
+ );
372
+ const pos = reactive(loadPosition());
373
+ let drag = null;
374
+ let moved = false;
375
+ const report = computed(
376
+ () => inspectRoute(
377
+ props.router.currentRoute.value,
378
+ props.config,
379
+ props.middlewareFiles
380
+ )
381
+ );
382
+ const routes = computed(
383
+ () => listRoutes(props.router.getRoutes(), props.config, props.middlewareFiles)
384
+ );
385
+ const payloadReport = computed(
386
+ () => describePayload(props.payload ?? { data: {}, errors: {} })
387
+ );
388
+ const onPointerDown = (event) => {
389
+ drag = {
390
+ x: event.clientX,
391
+ y: event.clientY,
392
+ right: pos.right,
393
+ bottom: pos.bottom
394
+ };
395
+ moved = false;
396
+ event.currentTarget.setPointerCapture(event.pointerId);
397
+ };
398
+ const onPointerMove = (event) => {
399
+ if (!drag) return;
400
+ const dx = event.clientX - drag.x;
401
+ const dy = event.clientY - drag.y;
402
+ if (!moved && Math.hypot(dx, dy) < DRAG_THRESHOLD) return;
403
+ moved = true;
404
+ Object.assign(
405
+ pos,
406
+ clampPosition({ right: drag.right - dx, bottom: drag.bottom - dy })
407
+ );
408
+ };
409
+ const onPointerUp = () => {
410
+ if (drag && moved) savePosition(pos);
411
+ drag = null;
412
+ };
413
+ const onToggle = () => {
414
+ if (moved) return void (moved = false);
415
+ open.value = !open.value;
416
+ };
417
+ const chip = (text, tone = "neutral") => h("span", { style: chipStyle(tone) }, text);
418
+ const none = () => h("div", { style: { color: colors.dim, fontStyle: "italic" } }, "none");
419
+ const row = (label, value) => h("div", { style: { display: "flex", gap: "10px", padding: "2px 0" } }, [
420
+ h("span", { style: { color: colors.dim, flex: "0 0 68px" } }, label),
421
+ h(
422
+ "span",
423
+ {
424
+ style: { fontFamily: mono, wordBreak: "break-all", minWidth: "0" }
425
+ },
426
+ value
427
+ )
428
+ ]);
429
+ const section = (title, children, count) => h("section", { style: sectionStyle }, [
430
+ h("div", { style: sectionTitleStyle }, [
431
+ h("span", title),
432
+ ...count === void 0 ? [] : [chip(String(count), count ? "accent" : "neutral")]
433
+ ]),
434
+ ...children
435
+ ]);
436
+ const requestStatus = (entry) => entry.error !== void 0 || entry.status !== void 0 && entry.status >= 400 ? colors.alert : entry.status === void 0 ? colors.dim : colors.accent;
437
+ const show = (name, nodes) => tab.value === name ? nodes : [];
438
+ const tabBar = (counts) => h(
439
+ "div",
440
+ { style: tabsStyle, role: "tablist" },
441
+ // The Errors tab only exists while there are errors
442
+ TABS.filter(({ id }) => id !== "errors" || counts.errors).map(
443
+ ({ id, label }) => h(
444
+ "button",
445
+ {
446
+ type: "button",
447
+ role: "tab",
448
+ "aria-selected": tab.value === id,
449
+ style: tabStyle(tab.value === id),
450
+ "data-noofpi-devtools": `tab-${id}`,
451
+ onClick: () => tab.value = id
452
+ },
453
+ [
454
+ label,
455
+ ...counts[id] === void 0 ? [] : [
456
+ chip(
457
+ String(counts[id]),
458
+ counts[id] ? id === "csp" || id === "errors" ? "alert" : "accent" : "neutral"
459
+ )
460
+ ]
461
+ ]
462
+ )
463
+ )
464
+ );
465
+ const errorsPanel = () => [
466
+ h(
467
+ "button",
468
+ {
469
+ type: "button",
470
+ style: {
471
+ ...closeStyle,
472
+ width: "auto",
473
+ padding: "2px 10px",
474
+ borderRadius: "999px",
475
+ font: `600 11px/1.4 ${sans}`,
476
+ alignSelf: "flex-end"
477
+ },
478
+ onClick: () => {
479
+ props.errors.list = [];
480
+ tab.value = "route";
481
+ }
482
+ },
483
+ "Clear"
484
+ ),
485
+ ...props.errors.list.map(
486
+ (error, index) => h(
487
+ "section",
488
+ {
489
+ style: {
490
+ ...sectionStyle,
491
+ borderColor: tones.alert.border,
492
+ background: tones.alert.bg
493
+ },
494
+ key: index
495
+ },
496
+ [
497
+ h("div", { style: { display: "flex", gap: "6px" } }, [
498
+ chip(error.source, "alert"),
499
+ chip(error.name),
500
+ ...error.info ? [chip(error.info)] : []
501
+ ]),
502
+ h(
503
+ "div",
504
+ {
505
+ style: {
506
+ margin: "6px 0",
507
+ fontFamily: mono,
508
+ fontWeight: "600",
509
+ wordBreak: "break-word"
510
+ }
511
+ },
512
+ error.message
513
+ ),
514
+ ...error.stack ? [
515
+ h("details", [
516
+ h(
517
+ "summary",
518
+ { style: { cursor: "pointer", color: colors.dim } },
519
+ "stack trace"
520
+ ),
521
+ h("pre", { style: codeStyle }, error.stack)
522
+ ])
523
+ ] : []
524
+ ]
525
+ )
526
+ ).reverse()
527
+ ];
528
+ const routesPanel = () => {
529
+ const current = props.router.currentRoute.value.matched.at(-1)?.path;
530
+ return [
531
+ section(
532
+ "App routes",
533
+ routes.value.length ? routes.value.map((entry) => {
534
+ const navigable = !entry.path.includes(":");
535
+ return h(
536
+ "div",
537
+ {
538
+ style: {
539
+ margin: "4px 0",
540
+ padding: "2px 0 2px 8px",
541
+ borderLeft: `2px solid ${entry.path === current ? colors.accent : colors.line}`
542
+ }
543
+ },
544
+ [
545
+ h(
546
+ navigable ? "a" : "span",
547
+ {
548
+ style: {
549
+ fontFamily: mono,
550
+ wordBreak: "break-all",
551
+ color: colors.fg,
552
+ ...navigable ? { cursor: "pointer" } : {}
553
+ },
554
+ ...navigable ? {
555
+ onClick: () => void props.router.push(entry.path)
556
+ } : {}
557
+ },
558
+ entry.path
559
+ ),
560
+ h(
561
+ "div",
562
+ {
563
+ style: {
564
+ display: "flex",
565
+ flexWrap: "wrap",
566
+ gap: "4px",
567
+ marginTop: "2px"
568
+ }
569
+ },
570
+ [
571
+ chip(
572
+ `${entry.rendering} render`,
573
+ entry.rendering === "server" ? "accent" : "neutral"
574
+ ),
575
+ chip(`${entry.fetch} fetch`),
576
+ chip(`layout: ${entry.layout}`),
577
+ ...entry.middleware.some((m) => m.scope === "named") ? [
578
+ chip(
579
+ `middleware: ${entry.middleware.filter((m) => m.scope === "named").map((m) => m.name).join(", ")}`
580
+ )
581
+ ] : []
582
+ ]
583
+ )
584
+ ]
585
+ );
586
+ }) : [none()],
587
+ routes.value.length
588
+ )
589
+ ];
590
+ };
591
+ const payloadEntries = (title, entries) => section(
592
+ title,
593
+ entries.length ? entries.map(
594
+ (entry) => h("details", { style: { margin: "4px 0" } }, [
595
+ h(
596
+ "summary",
597
+ { style: { cursor: "pointer", fontFamily: mono } },
598
+ [
599
+ entry.key,
600
+ " ",
601
+ h(
602
+ "span",
603
+ { style: { color: colors.dim } },
604
+ formatBytes(entry.bytes)
605
+ )
606
+ ]
607
+ ),
608
+ h("pre", { style: codeStyle }, entry.json)
609
+ ])
610
+ ) : [none()],
611
+ entries.length
612
+ );
613
+ const payloadPanel = () => {
614
+ const p = payloadReport.value;
615
+ return [
616
+ section("Transferred to the browser", [
617
+ row("size", formatBytes(p.bytes)),
618
+ row("locale", p.locale ?? "-"),
619
+ h(
620
+ "div",
621
+ {
622
+ style: { color: colors.dim, fontSize: "11px", marginTop: "4px" }
623
+ },
624
+ "What the server embedded in the HTML for the first render. Client-side navigations fetch fresh data."
625
+ )
626
+ ]),
627
+ payloadEntries("useAsyncData / loaders", p.data),
628
+ payloadEntries("useState", p.state),
629
+ payloadEntries("Errors", p.errors),
630
+ ...p.error ? [payloadEntries("Error page", [p.error])] : []
631
+ ];
632
+ };
633
+ return () => {
634
+ const r = report.value;
635
+ const count = props.violations.list.length;
636
+ const errorCount = props.errors.list.length;
637
+ const requests = props.requests?.list ?? [];
638
+ const at = clampPosition(pos);
639
+ const nodes = [
640
+ h(
641
+ "button",
642
+ {
643
+ type: "button",
644
+ title: "Drag to move",
645
+ style: {
646
+ ...buttonStyle,
647
+ right: `${at.right}px`,
648
+ bottom: `${at.bottom}px`
649
+ },
650
+ "data-noofpi-devtools": "toggle",
651
+ onPointerdown: onPointerDown,
652
+ onPointermove: onPointerMove,
653
+ onPointerup: onPointerUp,
654
+ onPointercancel: onPointerUp,
655
+ onClick: onToggle
656
+ },
657
+ [
658
+ h("span", {
659
+ style: dotStyle(count || errorCount ? alertColor : colors.accent)
660
+ }),
661
+ h("span", "noofpi"),
662
+ ...errorCount ? [
663
+ h(
664
+ "span",
665
+ { style: badgeStyle },
666
+ `${errorCount} ${errorCount === 1 ? "error" : "errors"}`
667
+ )
668
+ ] : [],
669
+ ...count ? [h("span", { style: badgeStyle }, `${count} CSP`)] : []
670
+ ]
671
+ )
672
+ ];
673
+ if (open.value) {
674
+ nodes.push(
675
+ h(
676
+ "div",
677
+ {
678
+ style: { ...panelStyle, ...panelPlacement(at) },
679
+ "data-noofpi-devtools": "panel"
680
+ },
681
+ [
682
+ h("div", { style: headerStyle }, [
683
+ h("span", { style: dotStyle(colors.accent) }),
684
+ h(
685
+ "span",
686
+ {
687
+ style: {
688
+ flex: "1",
689
+ fontSize: "14px",
690
+ fontWeight: "700",
691
+ letterSpacing: ".02em"
692
+ }
693
+ },
694
+ [
695
+ h("span", { style: { color: colors.accent } }, "noofpi"),
696
+ h(
697
+ "span",
698
+ { style: { color: colors.dim, fontWeight: "500" } },
699
+ " devtools"
700
+ )
701
+ ]
702
+ ),
703
+ h(
704
+ "button",
705
+ {
706
+ type: "button",
707
+ "aria-label": "Close devtools",
708
+ style: closeStyle,
709
+ onClick: () => open.value = false
710
+ },
711
+ "\xD7"
712
+ )
713
+ ]),
714
+ tabBar({
715
+ errors: errorCount,
716
+ route: void 0,
717
+ routes: routes.value.length,
718
+ payload: payloadReport.value.data.length + payloadReport.value.state.length + payloadReport.value.errors.length,
719
+ doofpi: requests.length,
720
+ csp: count
721
+ }),
722
+ h("div", { style: bodyStyle }, [
723
+ ...show("route", [
724
+ section("Route", [
725
+ row("path", r.path),
726
+ row("pattern", r.pattern),
727
+ row("layout", r.layout),
728
+ row(
729
+ "mode",
730
+ h("span", { style: { display: "flex", gap: "6px" } }, [
731
+ chip(
732
+ `${r.rendering} render`,
733
+ r.rendering === "server" ? "accent" : "neutral"
734
+ ),
735
+ chip(`${r.fetch} fetch`, "accent")
736
+ ])
737
+ )
738
+ ]),
739
+ section(
740
+ "Middleware chain",
741
+ r.middleware.length ? r.middleware.map(
742
+ (m, index) => h(
743
+ "div",
744
+ {
745
+ style: {
746
+ display: "flex",
747
+ alignItems: "center",
748
+ gap: "8px",
749
+ padding: "2px 0"
750
+ }
751
+ },
752
+ [
753
+ h(
754
+ "span",
755
+ { style: { color: colors.dim, width: "14px" } },
756
+ String(index + 1)
757
+ ),
758
+ chip(
759
+ m.scope,
760
+ m.scope === "global" ? "neutral" : "accent"
761
+ ),
762
+ h(
763
+ "span",
764
+ { style: { fontFamily: mono } },
765
+ m.name
766
+ ),
767
+ ...m.missing ? [chip("missing", "alert")] : []
768
+ ]
769
+ )
770
+ ) : [none()],
771
+ r.middleware.length
772
+ ),
773
+ section("Route rules", [
774
+ Object.keys(r.rule).length ? h(
775
+ "div",
776
+ {
777
+ style: {
778
+ fontFamily: mono,
779
+ wordBreak: "break-all"
780
+ }
781
+ },
782
+ JSON.stringify(r.rule)
783
+ ) : none()
784
+ ])
785
+ ]),
786
+ ...show("routes", routesPanel()),
787
+ ...show("payload", payloadPanel()),
788
+ ...show("doofpi", [
789
+ ...requests.length ? [
790
+ h(
791
+ "button",
792
+ {
793
+ type: "button",
794
+ style: {
795
+ ...closeStyle,
796
+ width: "auto",
797
+ padding: "2px 10px",
798
+ borderRadius: "999px",
799
+ font: `600 11px/1.4 ${sans}`,
800
+ alignSelf: "flex-end"
801
+ },
802
+ onClick: () => props.requests.list = []
803
+ },
804
+ "Clear"
805
+ )
806
+ ] : [],
807
+ section(
808
+ "doofpi requests",
809
+ requests.length ? requests.map((entry) => {
810
+ const { request, detail } = describeRequest(
811
+ entry,
812
+ window.location.origin
813
+ );
814
+ return h(
815
+ "div",
816
+ {
817
+ style: {
818
+ margin: "4px 0",
819
+ padding: "2px 0 2px 8px",
820
+ borderLeft: `2px solid ${requestStatus(entry)}`
821
+ }
822
+ },
823
+ [
824
+ h(
825
+ "div",
826
+ {
827
+ style: {
828
+ fontFamily: mono,
829
+ wordBreak: "break-all"
830
+ }
831
+ },
832
+ request
833
+ ),
834
+ h(
835
+ "div",
836
+ {
837
+ style: {
838
+ color: colors.dim,
839
+ fontSize: "11px"
840
+ }
841
+ },
842
+ detail
843
+ )
844
+ ]
845
+ );
846
+ }) : [none()],
847
+ requests.length
848
+ )
849
+ ]),
850
+ ...show("csp", [
851
+ section(
852
+ "CSP violations",
853
+ count ? props.violations.list.map(
854
+ (v) => h(
855
+ "div",
856
+ {
857
+ style: {
858
+ display: "flex",
859
+ gap: "8px",
860
+ padding: "2px 0",
861
+ alignItems: "baseline"
862
+ }
863
+ },
864
+ [
865
+ chip(v.directive, "alert"),
866
+ h(
867
+ "span",
868
+ {
869
+ style: {
870
+ fontFamily: mono,
871
+ wordBreak: "break-all",
872
+ minWidth: "0"
873
+ }
874
+ },
875
+ `${v.blocked} ${v.source}`.trim()
876
+ )
877
+ ]
878
+ )
879
+ ) : [none()],
880
+ count
881
+ )
882
+ ]),
883
+ ...show("errors", errorsPanel())
884
+ ])
885
+ ]
886
+ )
887
+ );
888
+ }
889
+ return nodes;
890
+ };
891
+ }
892
+ });
893
+ function mountDevtools(options) {
894
+ const { app: target, ...componentOptions } = options;
895
+ const violations = reactive({ list: [] });
896
+ const onViolation = (event) => {
897
+ violations.list = [
898
+ ...violations.list,
899
+ {
900
+ directive: event.effectiveDirective,
901
+ blocked: event.blockedURI || "inline",
902
+ source: event.sourceFile ? `${event.sourceFile}:${event.lineNumber}` : ""
903
+ }
904
+ ].slice(-MAX_VIOLATIONS);
905
+ };
906
+ document.addEventListener("securitypolicyviolation", onViolation);
907
+ const errors = reactive({ list: [] });
908
+ const addError = (error) => {
909
+ errors.list = [...errors.list, error].slice(-MAX_ERRORS);
910
+ };
911
+ const serverErrors = document.getElementById(DEV_ERRORS_ELEMENT_ID);
912
+ if (serverErrors) {
913
+ errors.list = parseDevErrors(serverErrors.textContent ?? "");
914
+ serverErrors.remove();
915
+ }
916
+ const onError = (event) => {
917
+ if (event.error || event.message)
918
+ addError(toDevError(event.error ?? event.message, "window"));
919
+ };
920
+ const onRejection = (event) => addError(toDevError(event.reason, "promise"));
921
+ window.addEventListener("error", onError);
922
+ window.addEventListener("unhandledrejection", onRejection);
923
+ options.router.onError((error) => addError(toDevError(error, "router")));
924
+ if (target) {
925
+ const previous = target.config.errorHandler;
926
+ target.config.errorHandler = (error, instance, info) => {
927
+ addError(toDevError(error, "vue", info));
928
+ if (previous) previous(error, instance, info);
929
+ else console.error(error);
930
+ };
931
+ }
932
+ const host = document.createElement("div");
933
+ host.id = "__noofpi_devtools";
934
+ document.body.append(host);
935
+ const app = createApp({
936
+ render: () => h(Devtools, {
937
+ ...componentOptions,
938
+ violations,
939
+ errors
940
+ })
941
+ });
942
+ app.mount(host);
943
+ return () => {
944
+ document.removeEventListener("securitypolicyviolation", onViolation);
945
+ window.removeEventListener("error", onError);
946
+ window.removeEventListener("unhandledrejection", onRejection);
947
+ app.unmount();
948
+ host.remove();
949
+ };
950
+ }
951
+ export {
952
+ describePayload,
953
+ describeRequest,
954
+ formatBytes,
955
+ inspectRoute,
956
+ listRoutes,
957
+ mountDevtools
958
+ };