vite-devtools-svelte 0.4.1 → 0.6.0

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 (96) hide show
  1. package/README.md +19 -7
  2. package/dist/analyzers/api.d.ts +17 -4
  3. package/dist/analyzers/assets.d.ts +0 -1
  4. package/dist/analyzers/build.d.ts +7 -1
  5. package/dist/analyzers/http.d.ts +9 -0
  6. package/dist/analyzers/module-graph.d.ts +9 -0
  7. package/dist/analyzers/og.d.ts +21 -4
  8. package/dist/analyzers/routes.d.ts +16 -1
  9. package/dist/client/assets/ApiPlayground-qRDX0tRk.js +3 -0
  10. package/dist/client/assets/Assets-yTFLB7w2.js +1 -0
  11. package/dist/client/assets/BuildAnalysis-C6yO6EJN.js +1 -0
  12. package/dist/client/assets/CaptureNotice-DykEK0Kp.js +1 -0
  13. package/dist/client/assets/Components-BTG8jKec.js +2 -0
  14. package/dist/client/assets/DataTable-C5C0HrMd.js +1 -0
  15. package/dist/client/assets/DataTable-gMBzprA7.css +1 -0
  16. package/dist/client/assets/ErrorDashboard-DHdptxQP.js +1 -0
  17. package/dist/client/assets/FpsMonitor-G1xRBjK3.js +1 -0
  18. package/dist/client/assets/Inspect-Ba_b5o73.js +4 -0
  19. package/dist/client/assets/{Inspector-DGmAzhki.js → Inspector-mTvtYmwt.js} +1 -1
  20. package/dist/client/assets/{versions-Co596WUJ.css → LiveControls-CMau2xlU.css} +1 -1
  21. package/dist/client/assets/LiveControls-nrc1-cBk.js +1 -0
  22. package/dist/client/assets/LoadProfiler-eYXaLPba.js +1 -0
  23. package/dist/client/assets/ModuleGraph-Dp-bJUnD.js +1 -0
  24. package/dist/client/assets/OGPreview-BzZ_MAg7.js +1 -0
  25. package/dist/client/assets/Overview-Cbi5ayT1.js +1 -0
  26. package/dist/client/assets/Overview-Neh721Uf.css +1 -0
  27. package/dist/client/assets/Panel-CKQaY_Qq.js +1 -0
  28. package/dist/client/assets/Panel-b1jDvzob.css +1 -0
  29. package/dist/client/assets/ReactiveGraph-CQpsrwa7.js +19 -0
  30. package/dist/client/assets/RenderProfiler-CCG8KJ2a.js +1 -0
  31. package/dist/client/assets/Routes-Dg3ZrLhJ.js +1 -0
  32. package/dist/client/assets/SearchField-B5EQ5IIf.js +1 -0
  33. package/dist/client/assets/Segmented-Dz1OdcPr.js +1 -0
  34. package/dist/client/assets/SplitView-CxRUXpY5.js +1 -0
  35. package/dist/client/assets/StateTimeline-CLt2yN8k.js +1 -0
  36. package/dist/client/assets/TreeView-BYOJBzxO.js +1 -0
  37. package/dist/client/assets/VirtualList-Bfn8is0p.js +1 -0
  38. package/dist/client/assets/{browser-agent-rpc-BXhoSh1z-D9g7mT9G.js → browser-agent-rpc-BXhoSh1z-CuoUGU_3.js} +1 -1
  39. package/dist/client/assets/capture.svelte-BLIttZ2Z.js +1 -0
  40. package/dist/client/assets/collections-uqk9p1aQ.js +1 -0
  41. package/dist/client/assets/format-BEILGi1v.js +1 -0
  42. package/dist/client/assets/{index-eZHqMk0z.css → index-BmEfdt6W.css} +1 -1
  43. package/dist/client/assets/{index-BzMw8R8l.js → index-Cf5oAFpK.js} +6 -6
  44. package/dist/client/assets/{reactive-C2hv2QLH.js → reactive-DuxZv-g7.js} +1 -1
  45. package/dist/client/assets/reactive-selection.svelte-iv05jhlt.js +1 -0
  46. package/dist/client/assets/versions-Bd19hz8p.js +1 -0
  47. package/dist/client/index.html +2 -2
  48. package/dist/index.mjs +1655 -1353
  49. package/dist/index.mjs.map +1 -1
  50. package/dist/mcp/issues.d.ts +19 -6
  51. package/dist/mcp/server.d.ts +0 -5
  52. package/dist/mcp/sessions.d.ts +8 -1
  53. package/dist/plugin.d.ts +20 -0
  54. package/dist/runtime/ids.d.ts +3 -0
  55. package/dist/runtime/index.d.ts +18 -0
  56. package/dist/runtime/transform.d.ts +22 -0
  57. package/dist/{collector.d.ts → server/collector.d.ts} +11 -16
  58. package/dist/{devframe.d.ts → server/devframe.d.ts} +10 -10
  59. package/dist/{mount.d.ts → server/mount.d.ts} +4 -9
  60. package/dist/{security.d.ts → server/security.d.ts} +10 -2
  61. package/dist/types.d.ts +26 -2
  62. package/package.json +12 -4
  63. package/skills/vite-devtools-svelte-perf-audit/SKILL.md +2 -2
  64. package/skills/vite-devtools-svelte-perf-fix/SKILL.md +3 -3
  65. package/dist/client/assets/ApiPlayground-BMx5j-7t.js +0 -3
  66. package/dist/client/assets/Assets-BHhg5Smm.js +0 -1
  67. package/dist/client/assets/Badge-BBLKgCiU.css +0 -1
  68. package/dist/client/assets/Badge-CBVv8IFU.js +0 -1
  69. package/dist/client/assets/BuildAnalysis-BdVCnWpb.js +0 -1
  70. package/dist/client/assets/CaptureNotice-BeXCVhO0.js +0 -1
  71. package/dist/client/assets/Components-D_qDgEUt.js +0 -1
  72. package/dist/client/assets/DataTable-C6-tmcTQ.js +0 -1
  73. package/dist/client/assets/DataTable-CdVIFm8T.css +0 -1
  74. package/dist/client/assets/ErrorDashboard-CfUhPzue.js +0 -1
  75. package/dist/client/assets/FpsMonitor-B_AuHgyu.js +0 -1
  76. package/dist/client/assets/Inspect-BOgmKm6W.js +0 -3
  77. package/dist/client/assets/LoadProfiler-5xhnDLjR.js +0 -1
  78. package/dist/client/assets/ModuleGraph-Cp7f0Nz0.js +0 -1
  79. package/dist/client/assets/OGPreview-CjBhXSgn.js +0 -1
  80. package/dist/client/assets/Overview-B8hvIsIM.css +0 -1
  81. package/dist/client/assets/Overview-Kbpkgsas.js +0 -1
  82. package/dist/client/assets/ReactiveGraph-w2TK82c8.js +0 -5
  83. package/dist/client/assets/RenderProfiler-CeF8_j3b.js +0 -1
  84. package/dist/client/assets/Routes-DArWZtzC.js +0 -1
  85. package/dist/client/assets/SearchField-eocQu1eB.js +0 -1
  86. package/dist/client/assets/Segmented-JGNuI5EZ.js +0 -1
  87. package/dist/client/assets/SplitView-B8lYXXEm.js +0 -1
  88. package/dist/client/assets/StateTimeline-HpyvgoK1.js +0 -1
  89. package/dist/client/assets/TreeView-fty5aCC5.js +0 -1
  90. package/dist/client/assets/VirtualList-BvOBTnYJ.js +0 -1
  91. package/dist/client/assets/capture.svelte-CUhwdJwX.js +0 -1
  92. package/dist/client/assets/format-CW_NXiBg.js +0 -1
  93. package/dist/client/assets/reactive-selection.svelte-Dfd9zWsh.js +0 -1
  94. package/dist/client/assets/versions-CZjRj40E.js +0 -1
  95. package/dist/runtime.d.ts +0 -19
  96. /package/dist/{template-injector.d.ts → server/template-injector.d.ts} +0 -0
package/dist/index.mjs CHANGED
@@ -1,39 +1,158 @@
1
- import e from "node:path";
2
- import t from "node:crypto";
1
+ import e from "node:crypto";
2
+ import t from "node:path";
3
3
  import { launchEditor as n } from "devframe/utils/launch-editor";
4
- import r from "fs";
5
- import i from "path";
6
- import a from "node:fs";
7
- import { createRequire as o } from "node:module";
8
- import { fileURLToPath as s } from "node:url";
4
+ import r from "node:fs";
5
+ import { McpServer as i } from "@modelcontextprotocol/sdk/server/mcp.js";
6
+ import { StreamableHTTPServerTransport as a } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
7
+ import { z as o } from "zod";
8
+ import { createRequire as s } from "node:module";
9
9
  import { defineDevframe as c, defineRpcFunction as l } from "devframe";
10
- import { z as u } from "zod";
10
+ import { parseSync as u } from "vite";
11
11
  import d from "node:dns/promises";
12
12
  import f from "node:net";
13
13
  import p from "node:os";
14
14
  import { initDevframe as m } from "devframe/initiate";
15
- import { McpServer as ee } from "@modelcontextprotocol/sdk/server/mcp.js";
16
- import { StreamableHTTPServerTransport as te } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
17
- import { DEVTOOLS_MOUNT_PATH as ne } from "@vitejs/devtools-kit/constants";
15
+ import { DEVTOOLS_MOUNT_PATH as h } from "@vitejs/devtools-kit/constants";
16
+ //#region src/analyzers/components.ts
17
+ function g(e) {
18
+ let n = t.join(e, "src");
19
+ if (!r.existsSync(n)) return [];
20
+ let i = [];
21
+ return _(n, i), i.map((n) => {
22
+ let i = "";
23
+ try {
24
+ i = r.readFileSync(n, "utf-8");
25
+ } catch {}
26
+ let a = ee(i, n, e), o = ne(n);
27
+ return {
28
+ file: t.relative(e, n),
29
+ name: o,
30
+ imports: a.map((n) => t.relative(e, n))
31
+ };
32
+ });
33
+ }
34
+ function _(e, n) {
35
+ let i = r.readdirSync(e, { withFileTypes: !0 });
36
+ for (let r of i) {
37
+ let i = t.join(e, r.name);
38
+ if (r.isDirectory()) {
39
+ if (r.name === "node_modules" || r.name === ".svelte-kit") continue;
40
+ _(i, n);
41
+ } else r.name.endsWith(".svelte") && n.push(i);
42
+ }
43
+ }
44
+ function ee(e, n, r) {
45
+ let i = /* @__PURE__ */ new Set(), a = t.dirname(n), o = /import\s+[\w${}\s,*]+\s+from\s+['"]([^'"]+\.svelte)['"]/g, s;
46
+ for (; (s = o.exec(e)) !== null;) {
47
+ let e = s[1], t = te(e, a, r);
48
+ t && i.add(t);
49
+ }
50
+ return [...i];
51
+ }
52
+ function te(e, n, i) {
53
+ if (e.startsWith("$lib/") || e.startsWith("#lib/")) {
54
+ let n = t.join(i, "src", "lib", e.slice(5));
55
+ return r.existsSync(n) ? n : null;
56
+ }
57
+ if (e.startsWith(".")) {
58
+ let i = t.resolve(n, e);
59
+ if (r.existsSync(i)) return i;
60
+ }
61
+ return null;
62
+ }
63
+ function ne(e) {
64
+ return t.basename(e, ".svelte");
65
+ }
66
+ //#endregion
67
+ //#region src/analyzers/project.ts
68
+ var re = 5e3, v = null, ie = null, ae = 0;
69
+ function y(e) {
70
+ let t = Date.now();
71
+ if (v && ie === e && t - ae < re) return v;
72
+ let n = ce(e);
73
+ return v = n, ie = e, ae = t, n;
74
+ }
75
+ function b(e) {
76
+ return typeof e == "string" && e !== "" ? e : void 0;
77
+ }
78
+ function x(e) {
79
+ return typeof e == "object" && !!e && !Array.isArray(e);
80
+ }
81
+ function oe(e) {
82
+ let t = {};
83
+ if (!x(e)) return t;
84
+ for (let [n, r] of Object.entries(e)) typeof r == "string" && (t[n] = r);
85
+ return t;
86
+ }
87
+ function se(e) {
88
+ let t = {};
89
+ try {
90
+ t = JSON.parse(r.readFileSync(e, "utf-8"));
91
+ } catch {}
92
+ let n = x(t) ? t : {};
93
+ return {
94
+ name: b(n.name),
95
+ version: b(n.version),
96
+ dependencies: oe(n.dependencies),
97
+ devDependencies: oe(n.devDependencies)
98
+ };
99
+ }
100
+ function ce(e) {
101
+ let n = se(t.join(e, "package.json")), r = n.dependencies, i = n.devDependencies, a = (e) => b(r[e]) ?? b(i[e]);
102
+ return {
103
+ name: n.name ?? t.basename(e),
104
+ version: n.version ?? "0.0.0",
105
+ svelteVersion: S(e, "svelte") ?? a("svelte") ?? "unknown",
106
+ sveltekitVersion: S(e, "@sveltejs/kit") ?? a("@sveltejs/kit") ?? "unknown",
107
+ viteVersion: S(e, "vite") ?? a("vite") ?? "unknown",
108
+ dependencies: r,
109
+ devDependencies: i,
110
+ routesDir: le(e),
111
+ staticDir: ue(e)
112
+ };
113
+ }
114
+ function S(e, n) {
115
+ try {
116
+ let i = t.join(e, "node_modules", n, "package.json");
117
+ if (r.existsSync(i)) {
118
+ let e = JSON.parse(r.readFileSync(i, "utf-8"));
119
+ return x(e) ? b(e.version) : void 0;
120
+ }
121
+ } catch {}
122
+ }
123
+ function le(e) {
124
+ let n = [t.join(e, "src", "routes"), t.join(e, "src", "pages")];
125
+ for (let e of n) if (r.existsSync(e)) return e;
126
+ return t.join(e, "src", "routes");
127
+ }
128
+ function ue(e) {
129
+ let n = [t.join(e, "static"), t.join(e, "public")];
130
+ for (let e of n) if (r.existsSync(e)) return e;
131
+ return t.join(e, "static");
132
+ }
133
+ //#endregion
18
134
  //#region src/analyzers/routes.ts
19
- function re(e) {
135
+ function de(e) {
20
136
  if (!r.existsSync(e)) return [];
21
137
  let t = [];
22
- return ie(e, e, t), t.sort((e, t) => e.path.localeCompare(t.path));
138
+ return fe(e, e, t), t.toSorted((e, t) => e.path.localeCompare(t.path) || e.id.localeCompare(t.id));
23
139
  }
24
- function ie(e, t, n) {
25
- let a = r.readdirSync(e, { withFileTypes: !0 }), o = [], s = !1;
140
+ function fe(e, n, i) {
141
+ let a = r.readdirSync(e, { withFileTypes: !0 }), o = [];
26
142
  for (let r of a) {
27
143
  if (r.isDirectory()) {
28
- ie(i.join(e, r.name), t, n);
144
+ fe(t.join(e, r.name), n, i);
29
145
  continue;
30
146
  }
31
- let a = ae(r.name, i.join(e, r.name));
32
- a && (o.push(a), s = !0);
147
+ let a = me(r.name);
148
+ a && o.push({
149
+ type: a,
150
+ path: t.join(e, r.name)
151
+ });
33
152
  }
34
- if (s) {
35
- let r = i.relative(t, e), a = oe(r), s = se(r);
36
- n.push({
153
+ if (o.length > 0) {
154
+ let r = t.relative(n, e).split(t.sep).join("/"), { routePath: a, params: s } = ge(r);
155
+ i.push({
37
156
  id: r || "/",
38
157
  path: a,
39
158
  pattern: a,
@@ -49,168 +168,712 @@ function ie(e, t, n) {
49
168
  files: o
50
169
  });
51
170
  }
52
- }
53
- function ae(e, t) {
54
- let n = {
55
- "+page.svelte": "page",
56
- "+layout.svelte": "layout",
57
- "+page.server.ts": "page-load-server",
58
- "+page.server.js": "page-load-server",
59
- "+layout.server.ts": "layout-load-server",
60
- "+layout.server.js": "layout-load-server",
61
- "+page.ts": "page-load",
62
- "+page.js": "page-load",
63
- "+layout.ts": "layout-load",
64
- "+layout.js": "layout-load",
65
- "+server.ts": "endpoint",
66
- "+server.js": "endpoint",
67
- "+error.svelte": "error"
68
- }[e];
69
- return n ? {
70
- type: n,
71
- path: t
72
- } : null;
73
- }
74
- function oe(e) {
75
- return e ? "/" + e.split(i.sep).map((e) => {
76
- if (e.startsWith("(") && e.endsWith(")")) return null;
77
- if (e.startsWith("[") && e.endsWith("]")) {
78
- let t = e.slice(1, -1);
79
- return t.startsWith("...") ? `*${t.slice(3)}` : t.startsWith("[") && t.endsWith("]") ? `:${t.slice(1, -1)}?` : `:${t}`;
171
+ }
172
+ var pe = /^\+(page|layout|error|server)(@[^/\\]*)?(?:\.(server))?\.(svelte|js|ts)$/;
173
+ function me(e) {
174
+ let t = pe.exec(e);
175
+ if (!t) return null;
176
+ let [, n, r, i, a] = t;
177
+ return a === "svelte" ? i ? null : n === "page" ? "page" : n === "layout" ? "layout" : n === "error" && !r ? "error" : null : r ? null : n === "server" ? i ? null : "endpoint" : n === "page" ? i ? "page-load-server" : "page-load" : n === "layout" ? i ? "layout-load-server" : "layout-load" : null;
178
+ }
179
+ var he = /^(\.\.\.)?(\w+)(?:=(\w+))?$/;
180
+ function ge(e) {
181
+ let t = [], n = [];
182
+ for (let r of e.split("/")) r && !/^\(.+\)$/.test(r) && n.push(_e(r, t));
183
+ return {
184
+ routePath: "/" + n.join("/"),
185
+ params: t
186
+ };
187
+ }
188
+ function _e(e, t) {
189
+ let n = "", r = 0;
190
+ for (; r < e.length;) {
191
+ if (e[r] !== "[") {
192
+ n += e[r], r++;
193
+ continue;
194
+ }
195
+ let i = e.startsWith("[[", r), a = e.indexOf(i ? "]]" : "]", r);
196
+ if (a === -1) {
197
+ n += e.slice(r);
198
+ break;
199
+ }
200
+ let o = e.slice(r + (i ? 2 : 1), a), s = a + (i ? 2 : 1), c = i ? null : ve(o), l = he.exec(o);
201
+ if (c !== null) n += c;
202
+ else if (l) {
203
+ let [, e, r, a] = l, o = {
204
+ name: r,
205
+ optional: i,
206
+ rest: !!e
207
+ };
208
+ a && (o.matcher = a), t.push(o), n += e ? `*${r}` : `:${r}${i ? "?" : ""}`;
209
+ } else n += e.slice(r, s);
210
+ r = s;
211
+ }
212
+ return n;
213
+ }
214
+ function ve(e) {
215
+ let t = /^x\+([0-9a-f]{2})$/i.exec(e);
216
+ if (t) return String.fromCodePoint(Number.parseInt(t[1], 16));
217
+ let n = /^u\+([0-9a-f]{4,6})$/i.exec(e);
218
+ if (!n) return null;
219
+ let r = Number.parseInt(n[1], 16);
220
+ return r <= 1114111 ? String.fromCodePoint(r) : null;
221
+ }
222
+ //#endregion
223
+ //#region src/mcp/issues.ts
224
+ var ye = {
225
+ avgRenderTimeMs: 4,
226
+ renderCount: 30,
227
+ loadDurationMs: 200,
228
+ fpsDropThreshold: 40,
229
+ effectMaxDeps: 8
230
+ };
231
+ function be(e) {
232
+ let t = { ...ye };
233
+ for (let n of Object.keys(ye)) {
234
+ let r = e[n];
235
+ r !== void 0 && (t[n] = r);
236
+ }
237
+ return t;
238
+ }
239
+ function xe(e, t = {}) {
240
+ let n = be(t), r = [];
241
+ for (let t of e.renderProfiles) {
242
+ let e = t.renderCount > 0 ? t.totalRenderTime / t.renderCount : 0;
243
+ e >= n.avgRenderTimeMs && r.push({
244
+ id: `slow-render:${t.file}:${t.componentId}`,
245
+ kind: "slow-component-render",
246
+ severity: e >= n.avgRenderTimeMs * 4 ? "high" : e >= n.avgRenderTimeMs * 2 ? "medium" : "low",
247
+ summary: `${t.name} averages ${e.toFixed(2)}ms per render (${t.renderCount} renders)`,
248
+ file: t.file,
249
+ metric: {
250
+ avgRenderTimeMs: C(e),
251
+ renderCount: t.renderCount,
252
+ totalRenderTimeMs: C(t.totalRenderTime)
253
+ },
254
+ suggestedTool: "get_render_profile"
255
+ }), t.renderCount >= n.renderCount && r.push({
256
+ id: `over-render:${t.file}:${t.componentId}`,
257
+ kind: "over-rendered-component",
258
+ severity: t.renderCount >= n.renderCount * 8 ? "high" : t.renderCount >= n.renderCount * 3 ? "medium" : "low",
259
+ summary: `${t.name} rendered ${t.renderCount} times`,
260
+ file: t.file,
261
+ metric: {
262
+ renderCount: t.renderCount,
263
+ avgRenderTimeMs: C(e)
264
+ },
265
+ suggestedTool: "get_component_hotspots"
266
+ });
267
+ }
268
+ for (let t of e.loadProfiles) t.duration >= n.loadDurationMs && r.push({
269
+ id: `slow-load:${t.route}:${t.timestamp}`,
270
+ kind: "slow-load",
271
+ severity: t.duration >= n.loadDurationMs * 5 ? "high" : t.duration >= n.loadDurationMs * 2 ? "medium" : "low",
272
+ summary: `${t.type} load for ${t.route} took ${t.duration.toFixed(0)}ms`,
273
+ file: t.file,
274
+ metric: {
275
+ durationMs: C(t.duration),
276
+ dataSizeBytes: t.dataSize
277
+ },
278
+ suggestedTool: "get_load_waterfall"
279
+ });
280
+ let i = e.fpsSamples.filter((e) => e.fps < n.fpsDropThreshold);
281
+ if (i.length > 0) {
282
+ let t = i.reduce((e, t) => Math.min(e, t.fps), Infinity);
283
+ r.push({
284
+ id: `fps-drops:${e.fpsSamples[0]?.timestamp ?? 0}`,
285
+ kind: "fps-drop",
286
+ severity: t < 15 ? "high" : t < 30 ? "medium" : "low",
287
+ summary: `${i.length} FPS samples below ${n.fpsDropThreshold} (min ${t})`,
288
+ metric: {
289
+ dropCount: i.length,
290
+ minFps: t,
291
+ threshold: n.fpsDropThreshold
292
+ },
293
+ suggestedTool: "get_fps_drops"
294
+ });
295
+ }
296
+ let { inDegree: a } = we(e.reactiveGraph);
297
+ for (let t of e.reactiveGraph.nodes) if (t.type === "effect") {
298
+ let e = a.get(t.id) ?? 0;
299
+ e >= n.effectMaxDeps && r.push({
300
+ id: `effect-deps:${t.id}`,
301
+ kind: "effect-overconnected",
302
+ severity: e >= n.effectMaxDeps * 3 ? "high" : e >= n.effectMaxDeps * 2 ? "medium" : "low",
303
+ summary: `effect "${t.name}" depends on ${e} reactive values`,
304
+ file: t.componentFile,
305
+ metric: { depCount: e },
306
+ suggestedTool: "get_reactive_graph_problems"
307
+ });
308
+ }
309
+ return r.toSorted(Ce);
310
+ }
311
+ var Se = {
312
+ high: 0,
313
+ medium: 1,
314
+ low: 2
315
+ };
316
+ function Ce(e, t) {
317
+ return Se[e.severity] - Se[t.severity];
318
+ }
319
+ function we(e) {
320
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
321
+ for (let i of e.edges) {
322
+ let e = JSON.stringify([i.from, i.to]);
323
+ r.has(e) || (r.add(e), t.set(i.to, (t.get(i.to) ?? 0) + 1), n.set(i.from, (n.get(i.from) ?? 0) + 1));
324
+ }
325
+ return {
326
+ inDegree: t,
327
+ outDegree: n
328
+ };
329
+ }
330
+ function C(e) {
331
+ return Math.round(e * 100) / 100;
332
+ }
333
+ function Te(e, t = {}) {
334
+ let n = be(t), { inDegree: r, outDegree: i } = we(e), a = [], o = [], s = [];
335
+ for (let t of e.nodes) {
336
+ let e = r.get(t.id) ?? 0, c = i.get(t.id) ?? 0;
337
+ t.type === "effect" && e >= n.effectMaxDeps && a.push({
338
+ id: t.id,
339
+ name: t.name,
340
+ file: t.componentFile,
341
+ depCount: e
342
+ }), t.type !== "template" && (t.type === "derived" && t.unevaluated ? o.push({
343
+ id: t.id,
344
+ name: t.name,
345
+ file: t.componentFile
346
+ }) : e === 0 && c === 0 && !t.untrackedDeps && s.push({
347
+ id: t.id,
348
+ name: t.name,
349
+ type: t.type,
350
+ file: t.componentFile
351
+ }));
352
+ }
353
+ return {
354
+ effects: a,
355
+ orphanDeriveds: o,
356
+ isolatedNodes: s
357
+ };
358
+ }
359
+ //#endregion
360
+ //#region src/mcp/sessions.ts
361
+ var Ee = 1, De = 5, Oe = 1, ke = 30;
362
+ function w(e) {
363
+ return {
364
+ renderProfiles: e.getRenderProfiles().map((e) => ({
365
+ componentId: e.componentId,
366
+ file: e.file,
367
+ name: e.name,
368
+ renderCount: e.renderCount,
369
+ totalRenderTime: e.totalRenderTime
370
+ })),
371
+ loadProfilesCount: e.getLoadProfiles().length,
372
+ fpsCount: e.getFpsSamples().length,
373
+ takenAt: Date.now()
374
+ };
375
+ }
376
+ function T(e, t, n) {
377
+ return Math.abs(e) < t ? "unchanged" : n ? e < 0 ? "improved" : "regressed" : e > 0 ? "improved" : "regressed";
378
+ }
379
+ var Ae = /^s_[0-9a-z]{1,16}_[0-9a-f]{6}$/;
380
+ function E(e) {
381
+ return typeof e == "string" && Ae.test(e);
382
+ }
383
+ var je = class {
384
+ sessions = /* @__PURE__ */ new Map();
385
+ active = null;
386
+ persistDir;
387
+ getters;
388
+ constructor(e) {
389
+ this.persistDir = t.resolve(e.persistDir), this.getters = e.getters;
390
+ }
391
+ start(t, n) {
392
+ if (this.active) throw Error(`A session is already active: ${this.active}. Call end_session before starting a new one.`);
393
+ let r = `s_${Date.now().toString(36)}_${e.randomBytes(3).toString("hex")}`, i = {
394
+ id: r,
395
+ label: t,
396
+ startedAt: Date.now(),
397
+ persist: n,
398
+ startSnapshot: w(this.getters),
399
+ loadProfiles: [],
400
+ fpsSamples: []
401
+ };
402
+ return this.sessions.set(r, i), this.active = r, i;
403
+ }
404
+ recordLoadProfile(e) {
405
+ if (!this.active) return;
406
+ let t = this.sessions.get(this.active);
407
+ t && t.loadProfiles.push(e);
408
+ }
409
+ recordFpsSample(e) {
410
+ if (!this.active) return;
411
+ let t = this.sessions.get(this.active);
412
+ t && t.fpsSamples.push(e);
413
+ }
414
+ end(e) {
415
+ if (!this.active) throw Error("No active session");
416
+ let t = this.sessions.get(this.active);
417
+ if (!t) throw Error("Active session missing from store");
418
+ return t.endedAt = Date.now(), t.endSnapshot = w(this.getters), this.active = null, e === "discard" ? this.sessions.delete(t.id) : (e === "disk" || t.persist) && this.persistToDisk(t), t;
419
+ }
420
+ get(e) {
421
+ return E(e) ? this.sessions.get(e) || this.loadFromDisk(e) : void 0;
422
+ }
423
+ list() {
424
+ let e = /* @__PURE__ */ new Set(), t = [];
425
+ for (let n of this.sessions.values()) e.add(n.id), t.push({
426
+ id: n.id,
427
+ label: n.label,
428
+ startedAt: n.startedAt,
429
+ endedAt: n.endedAt,
430
+ persisted: r.existsSync(this.pathFor(n.id)),
431
+ active: this.active === n.id
432
+ });
433
+ try {
434
+ if (r.existsSync(this.persistDir)) for (let n of r.readdirSync(this.persistDir)) {
435
+ if (!n.endsWith(".json")) continue;
436
+ let r = n.slice(0, -5);
437
+ if (!E(r) || e.has(r)) continue;
438
+ let i = this.loadFromDisk(r);
439
+ i && t.push({
440
+ id: i.id,
441
+ label: i.label,
442
+ startedAt: i.startedAt,
443
+ endedAt: i.endedAt,
444
+ persisted: !0,
445
+ active: !1
446
+ });
447
+ }
448
+ } catch {}
449
+ return t.toSorted((e, t) => t.startedAt - e.startedAt);
450
+ }
451
+ delete(e) {
452
+ if (!E(e)) return !1;
453
+ let t = this.sessions.delete(e), n = !1;
454
+ try {
455
+ let t = this.pathFor(e);
456
+ r.existsSync(t) && (r.unlinkSync(t), n = !0);
457
+ } catch {}
458
+ return this.active === e && (this.active = null), t || n;
459
+ }
460
+ delta(e) {
461
+ let t = this.get(e);
462
+ if (!t) throw Error(`Session not found: ${e}`);
463
+ return this.deltaOf(t);
464
+ }
465
+ deltaOf(e) {
466
+ if (!e.endSnapshot || e.endedAt === void 0) throw Error(`Session ${e.id} has not been ended yet`);
467
+ let t = new Map(e.startSnapshot.renderProfiles.map((e) => [e.componentId, e])), n = e.endSnapshot.renderProfiles.map((e) => {
468
+ let n = t.get(e.componentId), r = n?.renderCount ?? 0, i = n?.totalRenderTime ?? 0, a = e.renderCount - r, o = e.totalRenderTime - i;
469
+ return {
470
+ componentId: e.componentId,
471
+ file: e.file,
472
+ name: e.name,
473
+ renderCountDelta: a,
474
+ totalRenderTimeDelta: o,
475
+ avgRenderTimeDelta: a > 0 ? o / a : 0
476
+ };
477
+ }).filter((e) => e.renderCountDelta > 0).toSorted((e, t) => t.totalRenderTimeDelta - e.totalRenderTimeDelta), r = e.loadProfiles.map((e) => e.duration), i = Me(r), a = Ne(r, 95), o = e.fpsSamples.map((e) => e.fps), s = Me(o), c = o.length > 0 ? o.reduce((e, t) => Math.min(e, t), Infinity) : 0, l = o.filter((e) => e < ke).length;
478
+ return {
479
+ durationMs: e.endedAt - e.startedAt,
480
+ components: n,
481
+ loadProfiles: {
482
+ count: e.loadProfiles.length,
483
+ avgDuration: i,
484
+ p95Duration: a
485
+ },
486
+ fps: {
487
+ samples: o.length,
488
+ avg: s,
489
+ min: c,
490
+ drops: l
491
+ }
492
+ };
493
+ }
494
+ compare(e, t) {
495
+ let n = this.delta(e), r = this.delta(t), i = this.get(e), a = this.get(t), o = n.components.reduce((e, t) => e + t.totalRenderTimeDelta, 0), s = r.components.reduce((e, t) => e + t.totalRenderTimeDelta, 0), c = s - o, l = r.loadProfiles.avgDuration - n.loadProfiles.avgDuration, u = r.fps.avg - n.fps.avg;
496
+ return {
497
+ a: {
498
+ id: i.id,
499
+ label: i.label
500
+ },
501
+ b: {
502
+ id: a.id,
503
+ label: a.label
504
+ },
505
+ render: {
506
+ totalRenderTimeDeltaA: o,
507
+ totalRenderTimeDeltaB: s,
508
+ diff: c,
509
+ verdict: T(c, Ee, !0)
510
+ },
511
+ load: {
512
+ avgA: n.loadProfiles.avgDuration,
513
+ avgB: r.loadProfiles.avgDuration,
514
+ diff: l,
515
+ verdict: T(l, De, !0)
516
+ },
517
+ fps: {
518
+ avgA: n.fps.avg,
519
+ avgB: r.fps.avg,
520
+ diff: u,
521
+ verdict: T(u, Oe, !1)
522
+ }
523
+ };
524
+ }
525
+ pathFor(e) {
526
+ if (!E(e)) throw Error("Invalid session id");
527
+ let n = t.resolve(this.persistDir, `${e}.json`);
528
+ if (t.dirname(n) !== this.persistDir) throw Error("Invalid session id");
529
+ return n;
530
+ }
531
+ persistToDisk(e) {
532
+ try {
533
+ r.mkdirSync(this.persistDir, { recursive: !0 }), r.writeFileSync(this.pathFor(e.id), JSON.stringify(e, null, 2), { mode: 384 });
534
+ } catch {}
535
+ }
536
+ loadFromDisk(e) {
537
+ try {
538
+ let t = r.readFileSync(this.pathFor(e), "utf-8"), n = JSON.parse(t);
539
+ return Fe(n) && n.id === e ? n : void 0;
540
+ } catch {
541
+ return;
542
+ }
543
+ }
544
+ };
545
+ function Me(e) {
546
+ return e.length === 0 ? 0 : e.reduce((e, t) => e + t, 0) / e.length;
547
+ }
548
+ function Ne(e, t) {
549
+ if (e.length === 0) return 0;
550
+ let n = e.toSorted((e, t) => e - t);
551
+ return n[Math.max(1, Math.ceil(t / 100 * n.length)) - 1];
552
+ }
553
+ var D = (e) => typeof e == "object" && !!e, O = (e) => typeof e == "number" && Number.isFinite(e);
554
+ function Pe(e) {
555
+ return D(e) && Array.isArray(e.renderProfiles) && e.renderProfiles.every((e) => D(e) && O(e.componentId) && typeof e.file == "string" && typeof e.name == "string" && O(e.renderCount) && O(e.totalRenderTime));
556
+ }
557
+ function Fe(e) {
558
+ return D(e) && typeof e.id == "string" && typeof e.label == "string" && O(e.startedAt) && (e.endedAt === void 0 || O(e.endedAt)) && Pe(e.startSnapshot) && (e.endSnapshot === void 0 || Pe(e.endSnapshot)) && Array.isArray(e.loadProfiles) && e.loadProfiles.every((e) => D(e) && O(e.duration)) && Array.isArray(e.fpsSamples) && e.fpsSamples.every((e) => D(e) && O(e.fps));
559
+ }
560
+ var Ie = {
561
+ default: 2048,
562
+ max: 32768
563
+ };
564
+ function Le(e, t) {
565
+ let n;
566
+ try {
567
+ n = JSON.stringify(e);
568
+ } catch {
569
+ return { omitted: "not serializable" };
570
+ }
571
+ return n === void 0 || n.length <= t ? e : {
572
+ omitted: "too large",
573
+ chars: n.length,
574
+ preview: n.slice(0, Math.min(200, t))
575
+ };
576
+ }
577
+ var k = o.string().max(64).regex(Ae, "not a session id"), A = (e) => ({ content: [{
578
+ type: "text",
579
+ text: typeof e == "string" ? e : JSON.stringify(e, null, 2)
580
+ }] });
581
+ function Re(e) {
582
+ let t = new i({
583
+ name: "vite-devtools-svelte",
584
+ version: "0.1.0"
585
+ });
586
+ if (t.registerTool("list_performance_issues", {
587
+ title: "List performance issues",
588
+ description: "Cross-cuts render/reactive/load/fps metrics and returns ranked issues. The entry point for AI-driven performance audits. Each issue carries `suggestedTool` naming the detail tool to call next.",
589
+ inputSchema: {
590
+ avgRenderTimeMs: o.number().positive().optional(),
591
+ renderCount: o.number().int().min(1).optional(),
592
+ loadDurationMs: o.number().positive().optional(),
593
+ fpsDropThreshold: o.number().min(1).max(120).optional(),
594
+ effectMaxDeps: o.number().int().min(1).optional()
595
+ }
596
+ }, async (t) => {
597
+ let n = t, r = await e.getReactiveGraph(), i = xe({
598
+ renderProfiles: e.getRenderProfiles(),
599
+ reactiveGraph: r,
600
+ loadProfiles: e.getLoadProfiles(),
601
+ fpsSamples: e.getFpsSamples()
602
+ }, n);
603
+ return A({
604
+ count: i.length,
605
+ issues: i
606
+ });
607
+ }), t.registerTool("get_component_hotspots", {
608
+ title: "Component render hotspots",
609
+ description: "Top components by total render time, with render count and per-render average.",
610
+ inputSchema: { topN: o.number().int().min(1).max(200).optional() }
611
+ }, ({ topN: t = 20 }) => A([...e.getRenderProfiles()].map((e) => ({
612
+ file: e.file,
613
+ name: e.name,
614
+ componentId: e.componentId,
615
+ renderCount: e.renderCount,
616
+ totalRenderTimeMs: j(e.totalRenderTime),
617
+ avgRenderTimeMs: j(e.renderCount > 0 ? e.totalRenderTime / e.renderCount : 0),
618
+ lastRenderTimeMs: j(e.lastRenderTime),
619
+ lastRenderAt: e.lastRenderAt
620
+ })).toSorted((e, t) => t.totalRenderTimeMs - e.totalRenderTimeMs).slice(0, t))), t.registerTool("get_reactive_graph_problems", {
621
+ title: "Reactive graph problems",
622
+ description: "Classified reactive graph issues: over-connected effects, orphan deriveds (declared but never evaluated so far — may still be read later, e.g. in a branch not shown yet), isolated nodes (no tracked dependency or reader; reads from the markup count as readers). Returns categories instead of the full graph.",
623
+ inputSchema: { effectMaxDeps: o.number().int().min(1).optional() }
624
+ }, async ({ effectMaxDeps: t }) => A(Te(await e.getReactiveGraph(), { effectMaxDeps: t }))), t.registerTool("get_load_waterfall", {
625
+ title: "SvelteKit load waterfall",
626
+ description: "Load profiles grouped by route, with timing and data size. Optionally filtered by route.",
627
+ inputSchema: { route: o.string().optional() }
628
+ }, ({ route: t }) => {
629
+ let n = e.getLoadProfiles();
630
+ t && (n = n.filter((e) => e.route === t));
631
+ let r = /* @__PURE__ */ new Map();
632
+ for (let e of n) {
633
+ let t = r.get(e.route) ?? [];
634
+ t.push(e), r.set(e.route, t);
635
+ }
636
+ return A([...r.entries()].map(([e, t]) => {
637
+ let n = t.map((e) => e.duration);
638
+ return {
639
+ route: e,
640
+ file: t[0]?.file,
641
+ count: t.length,
642
+ avgDuration: j(ze(n)),
643
+ maxDuration: j(n.reduce((e, t) => Math.max(e, t), -Infinity)),
644
+ totalDataBytes: t.reduce((e, t) => e + t.dataSize, 0),
645
+ samples: t
646
+ };
647
+ }).toSorted((e, t) => t.avgDuration - e.avgDuration));
648
+ }), t.registerTool("get_fps_drops", {
649
+ title: "FPS drops",
650
+ description: "Samples whose FPS fell below `threshold`. Returns timestamp + fps for each.",
651
+ inputSchema: {
652
+ threshold: o.number().min(1).max(120).optional(),
653
+ sinceMs: o.number().nonnegative().optional()
654
+ }
655
+ }, ({ threshold: t = 40, sinceMs: n }) => {
656
+ let r = e.getFpsSamples();
657
+ if (n !== void 0) {
658
+ let e = Date.now() - n;
659
+ r = r.filter((t) => t.timestamp >= e);
660
+ }
661
+ let i = r.filter((e) => e.fps < t);
662
+ return A({
663
+ threshold: t,
664
+ sampleCount: r.length,
665
+ dropCount: i.length,
666
+ minFps: i.length > 0 ? i.reduce((e, t) => Math.min(e, t.fps), Infinity) : null,
667
+ drops: i
668
+ });
669
+ }), t.registerTool("get_render_profile", {
670
+ title: "Render profile for a specific file",
671
+ description: "Returns render profile entries matching the given component file (substring match).",
672
+ inputSchema: { file: o.string() }
673
+ }, ({ file: t }) => A(e.getRenderProfiles().filter((e) => e.file.includes(t)).map((e) => ({
674
+ componentId: e.componentId,
675
+ file: e.file,
676
+ name: e.name,
677
+ initTime: e.initTime,
678
+ renderCount: e.renderCount,
679
+ totalRenderTime: e.totalRenderTime,
680
+ lastRenderTime: e.lastRenderTime,
681
+ lastRenderAt: e.lastRenderAt,
682
+ totalRenderTimeMs: j(e.totalRenderTime),
683
+ avgRenderTimeMs: j(e.renderCount > 0 ? e.totalRenderTime / e.renderCount : 0)
684
+ })))), t.registerTool("get_project_info", {
685
+ title: "Project info",
686
+ description: "Package name/version, Svelte / SvelteKit / Vite versions, dependency lists.",
687
+ inputSchema: {}
688
+ }, () => A(e.getProject())), t.registerTool("get_routes", {
689
+ title: "SvelteKit routes",
690
+ description: "Static analysis of the SvelteKit routes tree.",
691
+ inputSchema: {}
692
+ }, () => A(e.getRoutes())), t.registerTool("get_live_components", {
693
+ title: "Currently mounted components",
694
+ description: "Component instances with file, parent, mounted status as currently mounted in the browser (an array, parents first). With `includeMeta: true` the answer is `{ epoch, total, captured, truncated, components }` instead, limited to `limit` (default 1000): component ids are only valid within that `epoch` (one page load), so pass both to get_reactive_scope.",
695
+ inputSchema: {
696
+ includeMeta: o.boolean().optional(),
697
+ limit: o.number().int().min(1).max(5e4).optional()
698
+ }
699
+ }, ({ includeMeta: t, limit: n }) => {
700
+ if (!t || !e.getLiveSnapshot) {
701
+ let t = e.getLiveComponents();
702
+ return A(n === void 0 ? t : t.slice(0, n));
703
+ }
704
+ let r = e.getLiveSnapshot(), i = n ?? 1e3;
705
+ return A({
706
+ epoch: r.epoch,
707
+ total: r.total,
708
+ captured: r.components.length,
709
+ truncated: r.total > r.components.length || r.components.length > i,
710
+ components: r.components.slice(0, i)
711
+ });
712
+ }), t.registerTool("get_component_relations", {
713
+ title: "Component import graph",
714
+ description: "Static import relations between .svelte components.",
715
+ inputSchema: {}
716
+ }, () => A(e.getComponentRelations())), e.getReactiveSummary) {
717
+ let n = e.getReactiveSummary;
718
+ t.registerTool("get_reactive_summary", {
719
+ title: "Reactive overview (top components)",
720
+ description: "Busiest component instances from runtime counters over all instances, without capturing the graph. Counts are sampled state changes (at most one per state per 200 ms) and renders within the window, not rates. Tracked: state created during component init and shared state of .svelte.js/.ts modules (rows with kind \"module\"; their componentId is a module scope id, usable with get_reactive_scope). `rows` + `other` add up to the totals; null means unknown. Use get_reactive_scope with a componentId to look at one instance. The same request is answered from a cache for up to 1 s; `window.until` says when the answer was computed.",
721
+ inputSchema: {
722
+ topK: o.number().int().min(1).max(200).optional(),
723
+ windowMs: o.number().int().min(1e3).max(6e4).optional()
724
+ }
725
+ }, async ({ topK: e, windowMs: t }) => A(await n({
726
+ topK: e,
727
+ windowMs: t
728
+ })));
729
+ }
730
+ if (e.getReactiveScope) {
731
+ let n = e.getReactiveScope;
732
+ t.registerTool("get_reactive_scope", {
733
+ title: "Reactive graph of one component",
734
+ description: "$state/$derived/$effect nodes of one component instance and their direct neighbours, built in the app within the caps. Edges mean 'can affect' (current dependencies), not a recorded cause. `componentId` requires the `epoch` it came from (get_live_components with includeMeta): after a reload the answer is empty with staleReason 'epoch-changed' instead of another instance. Omit componentId only for the whole-app graph (capped; see total/truncated). The same request may be answered from a cache for up to 1 s; `computedAt` says when the app built the graph (null when unknown or for an empty fallback). `stale: true` only marks a fallback after the app did not answer (an earlier answer with its own computedAt, or empty).",
735
+ inputSchema: {
736
+ componentId: o.number().int().nonnegative().optional(),
737
+ epoch: o.string().max(200).optional(),
738
+ maxNodes: o.number().int().min(1).max(5e3).optional(),
739
+ maxEdges: o.number().int().min(1).max(2e4).optional()
740
+ }
741
+ }, async ({ componentId: e, epoch: t, maxNodes: r, maxEdges: i }) => e !== void 0 && t === void 0 ? {
742
+ content: [{
743
+ type: "text",
744
+ text: "componentId requires epoch (from get_live_components with includeMeta: true)"
745
+ }],
746
+ isError: !0
747
+ } : A(await n({
748
+ componentId: e,
749
+ epoch: t,
750
+ maxNodes: r,
751
+ maxEdges: i
752
+ })));
753
+ }
754
+ if (e.getStateTimelineDelta) {
755
+ let n = e.getStateTimelineDelta;
756
+ t.registerTool("get_state_timeline", {
757
+ title: "State changes since a cursor",
758
+ description: "Sampled $state changes (200 ms) after `since` (the cursor from the previous call). Contains values of state in the running app. `reset: true` means the cursor was stale and this is the whole buffer. At most `limit` newest entries are returned; `omitted` counts older ones in the range that were left out. Values larger than `maxValueChars` (JSON) are replaced by a size summary. Timestamps are detection times, so order within about a second is not causal.",
759
+ inputSchema: {
760
+ since: o.number().int().nonnegative().optional(),
761
+ limit: o.number().int().min(1).max(500).optional(),
762
+ maxValueChars: o.number().int().min(16).max(Ie.max).optional()
763
+ }
764
+ }, ({ since: e, limit: t, maxValueChars: r }) => {
765
+ let i = n(e), a = t ?? 100, o = r ?? Ie.default, s = Math.max(0, i.changes.length - a), c = i.changes.slice(s).map((e) => ({
766
+ ...e,
767
+ oldValue: Le(e.oldValue, o),
768
+ newValue: Le(e.newValue, o)
769
+ }));
770
+ return A({
771
+ ...i,
772
+ changes: c,
773
+ omitted: s,
774
+ maxValueChars: o
775
+ });
776
+ });
777
+ }
778
+ if (e.getCaptureInfo) {
779
+ let n = e.getCaptureInfo;
780
+ t.registerTool("get_capture_info", {
781
+ title: "What the DevTools hold versus what the app reported",
782
+ description: "Per dataset: captured count, total (null = unknown), truncated, selection policy and dropped counts by reason. Read this before drawing conclusions from capped data.",
783
+ inputSchema: {}
784
+ }, () => A(n()));
785
+ }
786
+ return t.registerTool("start_session", {
787
+ title: "Start measurement session",
788
+ description: "Begin capturing metrics under a labelled session. Required before compare_sessions. Set `persist:true` to write to disk on end; otherwise the session lives in memory only.",
789
+ inputSchema: {
790
+ label: o.string().max(256),
791
+ persist: o.boolean().optional()
80
792
  }
81
- return e;
82
- }).filter(Boolean).join("/") : "/";
83
- }
84
- function se(e) {
85
- if (!e) return [];
86
- let t = [], n = e.split(i.sep);
87
- for (let e of n) {
88
- if (!e.startsWith("[") || !e.endsWith("]")) continue;
89
- let n = e.slice(1, -1);
90
- if (n.startsWith("...")) t.push({
91
- name: n.slice(3),
92
- optional: !1,
93
- rest: !0
793
+ }, ({ label: t, persist: n = !1 }) => {
794
+ let r = e.sessions.start(t, n);
795
+ return A({
796
+ id: r.id,
797
+ label: r.label,
798
+ startedAt: r.startedAt,
799
+ persist: r.persist
94
800
  });
95
- else if (n.startsWith("[") && n.endsWith("]")) t.push({
96
- name: n.slice(1, -1),
97
- optional: !0,
98
- rest: !1
801
+ }), t.registerTool("end_session", {
802
+ title: "End current measurement session",
803
+ description: "Closes the active session and returns its delta. `keep` decides disposal: \"memory\" keeps it for this dev-server lifetime, \"disk\" writes to .vite-devtools-svelte/sessions/, \"discard\" deletes it.",
804
+ inputSchema: { keep: o.enum([
805
+ "memory",
806
+ "disk",
807
+ "discard"
808
+ ]).optional() }
809
+ }, ({ keep: t = "memory" }) => {
810
+ let n = e.sessions.end(t), r = e.sessions.deltaOf(n);
811
+ return A({
812
+ id: n.id,
813
+ label: n.label,
814
+ startedAt: n.startedAt,
815
+ endedAt: n.endedAt,
816
+ keep: t,
817
+ delta: r
99
818
  });
100
- else {
101
- let e = n.split("=");
102
- t.push({
103
- name: e[0],
104
- optional: !1,
105
- rest: !1,
106
- matcher: e[1]
107
- });
819
+ }), t.registerTool("compare_sessions", {
820
+ title: "Compare two sessions",
821
+ description: "Diff render / load / fps metrics between two ended sessions. Each section carries `verdict`: improved | regressed | unchanged.",
822
+ inputSchema: {
823
+ a: k,
824
+ b: k
108
825
  }
109
- }
110
- return t;
111
- }
112
- //#endregion
113
- //#region src/analyzers/project.ts
114
- var ce = 5e3, h = null, g = null, _ = 0;
115
- function v(e) {
116
- let t = Date.now();
117
- if (h && g === e && t - _ < ce) return h;
118
- let n = le(e);
119
- return h = n, g = e, _ = t, n;
120
- }
121
- function le(e) {
122
- let t = i.join(e, "package.json"), n = r.existsSync(t) ? JSON.parse(r.readFileSync(t, "utf-8")) : {}, a = n.dependencies || {}, o = n.devDependencies || {};
123
- return {
124
- name: n.name || i.basename(e),
125
- version: n.version || "0.0.0",
126
- svelteVersion: y(e, "svelte") || a.svelte || o.svelte || "unknown",
127
- sveltekitVersion: y(e, "@sveltejs/kit") || a["@sveltejs/kit"] || o["@sveltejs/kit"] || "unknown",
128
- viteVersion: y(e, "vite") || a.vite || o.vite || "unknown",
129
- dependencies: a,
130
- devDependencies: o,
131
- routesDir: ue(e),
132
- staticDir: de(e)
133
- };
134
- }
135
- function y(e, t) {
136
- try {
137
- let n = i.join(e, "node_modules", t, "package.json");
138
- if (r.existsSync(n)) return JSON.parse(r.readFileSync(n, "utf-8")).version;
139
- } catch {}
140
- return null;
141
- }
142
- function ue(e) {
143
- let t = [i.join(e, "src", "routes"), i.join(e, "src", "pages")];
144
- for (let e of t) if (r.existsSync(e)) return e;
145
- return i.join(e, "src", "routes");
146
- }
147
- function de(e) {
148
- let t = [i.join(e, "static"), i.join(e, "public")];
149
- for (let e of t) if (r.existsSync(e)) return e;
150
- return i.join(e, "static");
151
- }
152
- //#endregion
153
- //#region src/analyzers/components.ts
154
- function b(e) {
155
- let t = i.join(e, "src");
156
- if (!r.existsSync(t)) return [];
157
- let n = [];
158
- return x(t, n), n.map((t) => {
159
- let n = fe(r.readFileSync(t, "utf-8"), t), a = he(t);
160
- return {
161
- file: i.relative(e, t),
162
- name: a,
163
- imports: n.map((t) => i.relative(e, t))
826
+ }, ({ a: t, b: n }) => A(e.sessions.compare(t, n))), t.registerTool("list_sessions", {
827
+ title: "List sessions",
828
+ description: "In-memory + on-disk sessions, most recent first.",
829
+ inputSchema: {}
830
+ }, () => A(e.sessions.list())), t.registerTool("load_session", {
831
+ title: "Load a session by id",
832
+ description: "Returns the full session record (including delta if ended) by id.",
833
+ inputSchema: { id: k }
834
+ }, ({ id: t }) => {
835
+ let n = e.sessions.get(t);
836
+ if (!n) return {
837
+ ...A(`Session not found: ${t}`),
838
+ isError: !0
164
839
  };
165
- });
166
- }
167
- function x(e, t) {
168
- let n = r.readdirSync(e, { withFileTypes: !0 });
169
- for (let r of n) {
170
- let n = i.join(e, r.name);
171
- if (r.isDirectory()) {
172
- if (r.name === "node_modules" || r.name === ".svelte-kit") continue;
173
- x(n, t);
174
- } else r.name.endsWith(".svelte") && t.push(n);
175
- }
840
+ let r = n.endedAt === void 0 ? null : e.sessions.deltaOf(n);
841
+ return A({
842
+ ...n,
843
+ delta: r
844
+ });
845
+ }), t.registerTool("delete_session", {
846
+ title: "Delete a session",
847
+ description: "Removes a session from memory and disk.",
848
+ inputSchema: { id: k }
849
+ }, ({ id: t }) => A({ deleted: e.sessions.delete(t) })), t;
176
850
  }
177
- function fe(e, t) {
178
- let n = [], r = i.dirname(t), a = /import\s+[\w{}\s,*]+\s+from\s+['"]([^'"]+\.svelte)['"]/g, o;
179
- for (; (o = a.exec(e)) !== null;) {
180
- let e = o[1], i = pe(e, r, t);
181
- i && n.push(i);
182
- }
183
- return n;
851
+ function ze(e) {
852
+ return e.length === 0 ? 0 : e.reduce((e, t) => e + t, 0) / e.length;
184
853
  }
185
- function pe(e, t, n) {
186
- if (e.startsWith("$lib/") || e.startsWith("#lib/")) {
187
- let t = me(n);
188
- if (t) {
189
- let n = i.join(t, "src", "lib", e.slice(5));
190
- if (r.existsSync(n)) return n;
191
- }
192
- return null;
193
- }
194
- if (e.startsWith(".")) {
195
- let n = i.resolve(t, e);
196
- if (r.existsSync(n)) return n;
197
- }
198
- return null;
854
+ function j(e) {
855
+ return Math.round(e * 100) / 100;
199
856
  }
200
- function me(e) {
201
- let t = i.dirname(e);
202
- for (; t !== i.dirname(t);) {
203
- if (r.existsSync(i.join(t, "package.json"))) return t;
204
- t = i.dirname(t);
205
- }
206
- return null;
857
+ //#endregion
858
+ //#region src/runtime/client.js?raw
859
+ var Be = "// FNV-1a over UTF-16 code units: cheap change detection for large snapshots.\nfunction __hash(str) {\n let h = 0x811c9dc5\n for (let i = 0; i < str.length; i++) {\n // oxlint-disable-next-line unicorn/prefer-code-point -- hashes UTF-16 code units on purpose (one per index, no surrogate decoding)\n h ^= str.charCodeAt(i)\n h = Math.imul(h, 0x01000193)\n }\n return (h >>> 0).toString(36)\n}\n\n// Wire shape of one component in a components message.\nfunction __componentEntry(instance) {\n return {\n id: instance.id,\n file: instance.file,\n name: instance.name,\n parentId: instance.parentId,\n mounted: instance.mounted,\n }\n}\n\n// An integer within [lo, hi], or `d` when `v` is not a finite number.\nfunction __clampInt(v, lo, hi, d) {\n const n = Math.floor(Number(v))\n return Number.isFinite(n) ? Math.min(hi, Math.max(lo, n)) : d\n}\n\nif (typeof window !== 'undefined' && !window.__SVELTE_DEVTOOLS__) {\n const __NO_VALUE = Symbol('no value')\n // State timeline ring (§6.7 C): every read sees at most 500 entries and\n // __TIMELINE_BYTES (also the server's buffer budget). The raw array may\n // hold up to __TIMELINE_TRIM_AT (2 x the 500 cap) between bulk trims.\n const __TIMELINE_BYTES = 4 * 1024 * 1024\n const __TIMELINE_TRIM_AT = 1000\n const __SVELTE_DT = {\n _nextId: 0,\n _instances: new Map(),\n _stack: [],\n _pendingParent: undefined,\n _pendingFile: null,\n _debounceTimer: null,\n _listeners: new Set(),\n\n // Phase 2: Profiling data\n _profiles: new Map(),\n _initStartTimes: new Map(),\n _profileDebounceTimer: null,\n\n // Phase 2: Reactive graph data\n _reactiveNodes: new Map(),\n _reactiveProxies: new Map(),\n\n // componentId -> Set<nodeId>. Lets unmount purge a component's reactive\n // nodes without scanning every node of the app (was O(components x nodes)).\n _nodesByComponent: new Map(),\n\n // Phase 3: State timeline\n _stateTimeline: [],\n _stateSnapshots: new Map(),\n _timelineDebounceTimer: null,\n // signal (or proxy marker) -> nodeId, set at track time and removed by\n // _forgetNode: a scoped graph resolves dependencies without scanning\n // every node (§6.7 D).\n _idBySignal: new WeakMap(),\n // proxy -> nodeId (tag_proxy nodes; the marker above is per node)\n _idByProxy: new WeakMap(),\n // Svelte component context -> component id (set by the wrapper on mount)\n _idByContext: new WeakMap(),\n // componentId -> (name -> last suffix) for names declared more than once\n // per instance ({@const} in {#each} items, several $state class instances)\n _nameSeq: new Map(),\n // Module scopes: signals created while a .svelte.js/.ts module body runs\n // (shared state such as `export const cart = $state(...)`) belong to a\n // scope per module file. Ids come from the component id counter (never\n // reused, non-negative) but scopes are not components: they are not in\n // _instances / the component tree, and live as long as the page.\n _modules: new Map(),\n _moduleByFile: new Map(),\n // $state node name -> (scope id -> Set<nodeId>): resolves a proxy's property source\n // (labelled '<name>.prop' by Svelte in dev) to the node of its proxy —\n // a tag_proxy node, or a state signal holding a proxy (reassigned object\n // state, class fields)\n _proxyNames: new Map(),\n // file of the module body running now (set by the module transform)\n _moduleFile: null,\n // componentId -> { effect, effect_pre } counters: effect names are\n // numbered per component, so instances of one file match\n _effectSeq: new Map(),\n // Every tracked node id (dense, swap-remove like _pollIds) for the\n // incremental liveness sweep, and its cursor.\n _sweepIds: [],\n _sweepIndex: new Map(),\n _sweepCursor: 0,\n // Polling bookkeeping (§6.7 D): $state node ids in a dense array kept up\n // to date incrementally (_pollIndex: nodeId -> position; removal is\n // swap-with-last), a cursor carried across ticks, nodes found changed but\n // not yet serialized (_pollDirty), and per-node change hints\n // (nodeId -> { ref, wv, nextCheckAt }).\n _pollIds: [],\n _pollIndex: new Map(),\n _pollCursor: 0,\n _pollDirty: new Set(),\n // Full-sweep bookkeeping: how long the last complete pass over all $state\n // nodes took (ms), for disclosure (= the worst-case detection delay).\n _pollSweep: { startedAt: 0, lastMs: null, nodes: 0 },\n _pollMeta: new Map(),\n _deepCredit: 0,\n _lastSnapshotSize: new Map(),\n _timelineSeq: 0,\n _pushedSeq: 0,\n _timelineReset: false,\n _entryInfo: new WeakMap(),\n // Sum of _entryInfo.bytes over _stateTimeline (runtime byte budget).\n _timelineBytes: 0,\n // Disclosure since the last push (§6.7 C): unsent entries the ring removed\n // (by count / by bytes) and changes recorded only as a size summary.\n _timelineDropped: { 'runtime-count': 0, 'runtime-bytes': 0 },\n _valueTooLarge: 0,\n\n // Overview aggregate (§6.7 I/J), O(1) per event: registered nodes per\n // component and type (+ app totals), and per-component activity in a\n // ring of 60 one-second buckets (sampled changes, renders, render ms,\n // plus how long sampling ran in that second).\n _nodeCounts: new Map(),\n _nodeTotals: { state: 0, derived: 0, effect: 0 },\n _activity: [],\n _epoch: Math.random().toString(36).slice(2) + Date.now().toString(36),\n\n // --- Activity subscription (docs/devframe-migration.md §6.3) ---\n // Inactive until the server says a DevTools client (UI tab or MCP lease)\n // is watching: no state polling, FPS rAF loop, or periodic HMR sends.\n _active: false,\n _componentsCost: { ms: 0, bytes: 0 },\n _componentDeltas: false,\n _pendingAdded: new Set(),\n _pendingRemoved: new Set(),\n _lastFullAt: 0,\n _resync: false,\n _profilesCost: { ms: 0, bytes: 0 },\n // = collector LIMITS.renderProfiles (pinned by a unit test): the server\n // keeps only the newest entries, so sending more is wasted bytes.\n _profileCap: 5000,\n _sampling: null,\n _baselining: false,\n // Polled state nodes not observed yet (no seed value). Their first\n // observation is a seed, not a change: no timeline entry, no activity\n // count, no drops — the old value is unknown, not null (review B-1/B-2).\n _unseeded: new Set(),\n // pendingNodes last sent on a state-timeline message (null = none yet)\n _sentPendingNodes: null,\n _fpsGen: 0,\n\n register(file) {\n const id = this._nextId++\n // Parent: the wrapper's context-derived hint (components created by a\n // later block update, review B1b) when it names a live instance, else\n // the synchronous init stack (children created during the parent's own\n // init, before the parent is mapped).\n const hint = this._pendingParent\n this._pendingParent = undefined\n const parentId =\n hint !== undefined && hint !== null && this._instances.has(hint)\n ? hint\n : this._stack.length > 0\n ? this._stack.at(-1)\n : null\n const baseName = file.slice(file.lastIndexOf('/') + 1).replace('.svelte', '')\n const name = baseName === '' ? 'Unknown' : baseName\n // children is a Set so unmounting one row of a 5 000-row list is O(1).\n this._instances.set(id, { id, file, name, parentId, mounted: true, children: new Set() })\n if (parentId !== null) {\n const parent = this._instances.get(parentId)\n if (parent) parent.children.add(id)\n }\n this._stack.push(id)\n if (this._active) this._pendingAdded.add(id)\n this._scheduleUpdate()\n return id\n },\n\n registered(id) {\n const idx = this._stack.indexOf(id)\n if (idx !== -1) this._stack.splice(idx, 1)\n },\n\n mount(id) {\n const instance = this._instances.get(id)\n if (instance && !instance.mounted) {\n instance.mounted = true\n if (this._active) this._pendingAdded.add(id)\n this._scheduleUpdate()\n }\n },\n\n unmount(id) {\n const instance = this._instances.get(id)\n if (instance) {\n if (instance.parentId !== null) {\n const parent = this._instances.get(instance.parentId)\n if (parent) parent.children.delete(id)\n }\n this._removeChildren(id)\n this._cleanupComponent(id)\n }\n this._scheduleUpdate()\n this._scheduleProfileUpdate()\n },\n\n // Remounts get a fresh id, so entries keyed by a dead id would otherwise\n // survive forever — every per-component map must be purged here.\n _cleanupComponent(id) {\n // Delta bookkeeping: an id added and removed between two pushes was\n // never sent, so it cancels out.\n if (this._active && !this._pendingAdded.delete(id)) this._pendingRemoved.add(id)\n this._cleanupReactiveNodes(id)\n this._effectSeq.delete(id)\n this._nameSeq.delete(id)\n this._instances.delete(id)\n this._profiles.delete(id)\n this._initStartTimes.delete(id)\n },\n\n _cleanupReactiveNodes(componentId) {\n const nodeIds = this._nodesByComponent.get(componentId)\n if (!nodeIds) return\n this._nodesByComponent.delete(componentId)\n // a copy: _forgetNode() deletes from this set\n for (const nodeId of Array.from(nodeIds)) this._forgetNode(nodeId)\n },\n\n _forgetNode(nodeId) {\n const entry = this._reactiveNodes.get(nodeId)\n if (entry) {\n this._countNode(entry.meta.componentId, entry.meta.type, -1)\n const set = this._nodesByComponent.get(entry.meta.componentId)\n if (set) set.delete(nodeId)\n }\n const signal = entry?.signal?.deref()\n if (signal && this._idBySignal.get(signal) === nodeId) this._idBySignal.delete(signal)\n const proxy = this._reactiveProxies.get(nodeId)?.deref()\n if (proxy && this._idByProxy.get(proxy) === nodeId) this._idByProxy.delete(proxy)\n if (entry?.meta.type === 'state') {\n const named = this._proxyNames.get(entry.meta.name)\n const inScope = named?.get(entry.meta.componentId)\n if (inScope) {\n inScope.delete(nodeId)\n if (inScope.size === 0) named.delete(entry.meta.componentId)\n if (named.size === 0) this._proxyNames.delete(entry.meta.name)\n }\n }\n this._pollRemove(nodeId)\n this._sweepRemove(nodeId)\n this._pollDirty.delete(nodeId)\n this._reactiveNodes.delete(nodeId)\n this._reactiveProxies.delete(nodeId)\n this._stateSnapshots.delete(nodeId)\n if (this._stateSnapshotStrs) this._stateSnapshotStrs.delete(nodeId)\n this._pollMeta.delete(nodeId)\n this._lastSnapshotSize.delete(nodeId)\n },\n\n // A component instance or a module scope that is still live.\n _scopeLive(id) {\n return this._instances.has(id) || this._modules.has(id)\n },\n\n _scopeFile(id) {\n const scope = this._instances.get(id) ?? this._modules.get(id)\n return scope ? scope.file : ''\n },\n\n _enterModule(file) {\n this._moduleFile = file\n // a module body that throws (or awaits) never reaches _leaveModule\n queueMicrotask(() => {\n if (this._moduleFile === file) this._moduleFile = null\n })\n },\n\n _leaveModule() {\n this._moduleFile = null\n },\n\n trackModuleSignal(kind, target, name) {\n const file = this._moduleFile\n let id = this._moduleByFile.get(file)\n if (id === undefined) {\n id = this._nextId++\n const lastSegment = file.slice(file.lastIndexOf('/') + 1)\n const base = lastSegment === '' ? file : lastSegment\n this._modules.set(id, { id, file, name: base, kind: 'module' })\n this._moduleByFile.set(file, id)\n }\n if (kind === 'proxy') this.trackProxy(target, name, id, null)\n else if (kind === 'derived') this.trackDerived(target, name, id, null)\n else this.trackState(target, name, id, null)\n },\n\n // A node is live while its signal is reachable, its component is mounted,\n // and the effect it was created in (an {#each} item, an effect run) has\n // not been destroyed. Svelte nulls effect.fn when it destroys an effect\n // (internal/client destroy_effect), which is checked instead of the\n // internal DESTROYED flag value. Returns the signal or null.\n _liveSignal(nodeId) {\n const entry = this._reactiveNodes.get(nodeId)\n if (!entry) return null\n const signal = entry.signal.deref()\n if (signal && this._scopeLive(entry.meta.componentId) && this._ownerAlive(entry)) {\n if (!entry.effect) return signal\n // a bound effect is destroyed when Svelte clears its callback\n if (signal.fn !== null) return signal\n }\n this._forgetNode(nodeId)\n return null\n },\n\n _ownerAlive(entry) {\n if (!entry.owner) return true\n const owner = entry.owner.deref()\n return !!owner && owner.fn !== null\n },\n\n _sweepAdd(nodeId) {\n if (this._sweepIndex.has(nodeId)) return\n this._sweepIndex.set(nodeId, this._sweepIds.length)\n this._sweepIds.push(nodeId)\n },\n\n _sweepRemove(nodeId) {\n const i = this._sweepIndex.get(nodeId)\n if (i === undefined) return\n const ids = this._sweepIds\n const last = ids.pop()\n this._sweepIndex.delete(nodeId)\n if (i < ids.length) {\n ids[i] = last\n this._sweepIndex.set(last, i)\n }\n },\n\n // Liveness of up to `max` nodes, continuing from a cursor (each poll\n // tick): nodes of destroyed {#each} items / effect runs leave the counts\n // and the graph without waiting for a graph request or GC.\n _sweepNodes(max) {\n const ids = this._sweepIds\n for (let n = 0; n < max && ids.length > 0; n++) {\n if (this._sweepCursor >= ids.length) this._sweepCursor = 0\n const nodeId = ids[this._sweepCursor]\n // a forgotten node's slot is refilled by the last id: re-check it\n if (this._liveSignal(nodeId)) this._sweepCursor++\n }\n },\n\n // Unique node id for a signal: componentId:name, or componentId:name#k\n // when this instance already holds a live node of that name for another\n // signal. The same signal (re-tagged) keeps its id.\n _nodeIdFor(identity, byIdentity, componentId, name) {\n const known = byIdentity.get(identity)\n if (known !== undefined && this._reactiveNodes.has(known)) return known\n const base = componentId + ':' + name\n if (!this._reactiveNodes.has(base) || !this._liveSignal(base)) return base\n let seq = this._nameSeq.get(componentId)\n if (!seq) {\n seq = new Map()\n this._nameSeq.set(componentId, seq)\n }\n let k = seq.get(name) ?? 1\n let id\n do {\n k++\n id = base + '#' + k\n } while (this._reactiveNodes.has(id) && this._liveSignal(id))\n seq.set(name, k)\n return id\n },\n\n _registerNode(nodeId, componentId, type, name, signalRef, owner, extra) {\n this._trackNodeCount(nodeId, componentId, type)\n const entry = {\n signal: signalRef,\n owner: owner ? new WeakRef(owner) : null,\n meta: { id: nodeId, type, name, componentId, componentFile: this._scopeFile(componentId) },\n }\n if (extra) Object.assign(entry, extra)\n this._reactiveNodes.set(nodeId, entry)\n this._indexNode(nodeId, componentId)\n this._sweepAdd(nodeId)\n return entry\n },\n\n _indexNode(nodeId, componentId) {\n let set = this._nodesByComponent.get(componentId)\n if (!set) {\n set = new Set()\n this._nodesByComponent.set(componentId, set)\n }\n set.add(nodeId)\n },\n\n _pollAdd(nodeId) {\n if (this._pollIndex.has(nodeId)) return\n if (!this._stateSnapshots.has(nodeId)) this._unseeded.add(nodeId)\n this._pollIndex.set(nodeId, this._pollIds.length)\n this._pollIds.push(nodeId)\n },\n\n // O(1): the last id takes the removed slot. If that slot is behind the\n // cursor, the moved id is visited in the next sweep instead of this one\n // (still visited within a bounded number of ticks).\n // Before a track* call replaces/creates nodeId: move the count from the\n // previous registration (same name re-tracked) to the new one.\n _trackNodeCount(nodeId, componentId, type) {\n const prev = this._reactiveNodes.get(nodeId)\n if (prev) this._countNode(prev.meta.componentId, prev.meta.type, -1)\n this._countNode(componentId, type, 1)\n },\n\n _countNode(componentId, type, d) {\n const kind = type === 'derived' || type === 'effect' ? type : 'state'\n let c = this._nodeCounts.get(componentId)\n if (!c) {\n if (d < 0) return\n c = { state: 0, derived: 0, effect: 0 }\n this._nodeCounts.set(componentId, c)\n }\n c[kind] += d\n this._nodeTotals[kind] += d\n if (c.state + c.derived + c.effect <= 0) this._nodeCounts.delete(componentId)\n },\n\n _bucket() {\n const sec = Math.floor(performance.now() / 1000)\n const slot = ((sec % 60) + 60) % 60\n let b = this._activity[slot]\n if (!b || b.second !== sec) {\n b = { second: sec, sampledMs: 0, rows: new Map() }\n this._activity[slot] = b\n }\n return b\n },\n\n _activityRow(componentId) {\n const rows = this._bucket().rows\n let r = rows.get(componentId)\n if (!r) {\n r = { changes: 0, renders: 0, renderMs: 0 }\n rows.set(componentId, r)\n }\n return r\n },\n\n _pollRemove(nodeId) {\n const i = this._pollIndex.get(nodeId)\n if (i === undefined) return\n this._unseeded.delete(nodeId)\n const ids = this._pollIds\n const last = ids.pop()\n this._pollIndex.delete(nodeId)\n if (i < ids.length) {\n ids[i] = last\n this._pollIndex.set(last, i)\n }\n },\n\n _removeChildren(parentId) {\n const parent = this._instances.get(parentId)\n if (!parent) return\n // a copy: _cleanupComponent() changes this set\n for (const childId of Array.from(parent.children)) {\n this._removeChildren(childId)\n this._cleanupComponent(childId)\n }\n },\n\n // Full-list pushes are throttled, not debounced: a pending timer is not\n // reset, so continuous churn still produces updates (a debounce would\n // starve), and the interval adapts to the last push's cost so a 10 000+\n // instance app can't spend its main thread serializing (review P3):\n // max(min, 20 x last send ms, 1 s when the last payload exceeded ~1 MB).\n _sendInterval(cost, min) {\n return Math.max(min, 20 * cost.ms, cost.bytes > 1000000 ? 1000 : 0)\n },\n\n _scheduleUpdate() {\n if (!this._active || this._debounceTimer) return\n this._debounceTimer = setTimeout(\n () => {\n this._debounceTimer = null\n this._sendUpdate()\n },\n this._sendInterval(this._componentsCost, 100),\n )\n },\n\n // components push (§6.5). Full form { epoch, components } replaces the\n // server's tree for this epoch: sent on activation, when the server does\n // not advertise componentDeltas, as a periodic checkpoint, or when the\n // delta would be larger than the tree. Otherwise the delta form\n // { epoch, added, removed } (removed ids first, ≤ 2 000 entries per\n // message, added in registration order = parents first).\n _sendUpdate(forceFull) {\n // Nobody watching: keep the registry, skip the O(N) payload. A full\n // snapshot is sent on activation (§6.3).\n if (!this._active) return\n const t0 = performance.now()\n const CHUNK = 2000\n const CHECKPOINT_MS = 30000\n const pending = this._pendingAdded.size + this._pendingRemoved.size\n const full =\n forceFull === true ||\n !this._componentDeltas ||\n t0 - this._lastFullAt >= CHECKPOINT_MS ||\n pending > this._instances.size\n let bytes = 0\n const msgs = []\n if (full) {\n const components = []\n for (const [, instance] of this._instances) {\n if (instance.mounted) {\n components.push(__componentEntry(instance))\n bytes += instance.file.length + instance.name.length + 72\n }\n }\n msgs.push({ epoch: this._epoch, reset: true, components })\n this._lastFullAt = t0\n } else if (pending > 0) {\n const removed = [...this._pendingRemoved]\n const added = []\n for (const id of this._pendingAdded) {\n const instance = this._instances.get(id)\n if (instance?.mounted) {\n added.push(__componentEntry(instance))\n bytes += instance.file.length + instance.name.length + 72\n }\n }\n bytes += removed.length * 8\n for (let r = 0; r < removed.length; r += CHUNK) {\n msgs.push({ epoch: this._epoch, added: [], removed: removed.slice(r, r + CHUNK) })\n }\n for (let a = 0; a < added.length; a += CHUNK) {\n msgs.push({ epoch: this._epoch, added: added.slice(a, a + CHUNK), removed: [] })\n }\n }\n this._pendingAdded.clear()\n this._pendingRemoved.clear()\n if (import.meta.hot) {\n for (const msg of msgs) import.meta.hot.send('svelte-devtools:components', msg)\n }\n this._componentsCost = { ms: performance.now() - t0, bytes }\n },\n\n getTree() {\n const components = []\n for (const [, instance] of this._instances) {\n if (instance.mounted) {\n components.push({\n id: instance.id,\n file: instance.file,\n name: instance.name,\n parentId: instance.parentId,\n mounted: instance.mounted,\n })\n }\n }\n return components\n },\n\n // --- Phase 2: Render Profiling ---\n\n startInit(id) {\n this._initStartTimes.set(id, performance.now())\n },\n\n endInit(id) {\n const start = this._initStartTimes.get(id)\n if (start === undefined) return\n const initTime = performance.now() - start\n this._initStartTimes.delete(id)\n const instance = this._instances.get(id)\n if (!instance) return\n this._profiles.set(id, {\n componentId: id,\n file: instance.file,\n name: instance.name,\n initTime,\n renderCount: 0,\n totalRenderTime: 0,\n lastRenderTime: 0,\n lastRenderAt: Date.now(),\n })\n this._scheduleProfileUpdate()\n },\n\n recordRender(id) {\n const profile = this._profiles.get(id)\n if (profile) {\n profile.renderCount++\n profile.lastRenderAt = Date.now()\n } else {\n const instance = this._instances.get(id)\n if (!instance) return\n this._profiles.set(id, {\n componentId: id,\n file: instance.file,\n name: instance.name,\n initTime: 0,\n renderCount: 1,\n totalRenderTime: 0,\n lastRenderTime: 0,\n lastRenderAt: Date.now(),\n })\n }\n this._activityRow(id).renders++\n this._scheduleProfileUpdate()\n },\n\n recordRenderTime(id, duration) {\n const profile = this._profiles.get(id)\n if (profile) {\n profile.totalRenderTime += duration\n profile.lastRenderTime = duration\n this._activityRow(id).renderMs += duration\n }\n },\n\n // Profiles push (review P-1 Option A; contract in\n // docs/performance-status.md). Throttled like components, but the floor\n // grows with the payload: every push carries the whole retained map, so\n // a large app coalesces bursts instead of resending ~1 MB twice a second.\n // Hard cap 2 s (contract R6): a slow serialization must not stretch the\n // latency beyond it.\n _profileInterval() {\n const cost = this._profilesCost\n return Math.min(\n 2000,\n Math.max(500, 20 * cost.ms, cost.bytes > 1000000 ? 2000 : cost.bytes > 250000 ? 1000 : 0),\n )\n },\n\n _scheduleProfileUpdate() {\n if (!this._active || this._profileDebounceTimer) return\n this._profileDebounceTimer = setTimeout(() => {\n this._profileDebounceTimer = null\n this._sendProfileUpdate()\n }, this._profileInterval())\n },\n\n // Also the forced path (activation / resync): a pending throttled push is\n // cancelled so the same state is not sent twice.\n _sendProfileUpdate() {\n if (this._profileDebounceTimer) {\n clearTimeout(this._profileDebounceTimer)\n this._profileDebounceTimer = null\n }\n if (!this._active) return\n const t0 = performance.now()\n const all = Array.from(this._profiles.values())\n // Exactly what the collector retains: its tail, in the same order.\n const profiles =\n all.length > this._profileCap ? all.slice(all.length - this._profileCap) : all\n if (import.meta.hot) {\n // total = all retained profiles; the message carries the newest-mounted\n // tail (§6.7 J IA1 capture policy 'newest-mounted').\n import.meta.hot.send('svelte-devtools:profiles', {\n epoch: this._epoch,\n profiles,\n total: all.length,\n })\n }\n // Payload size from a small sample (entries differ mainly by file path).\n const k = Math.min(8, profiles.length)\n let sampled = 0\n for (let i = 0; i < k; i++) sampled += JSON.stringify(profiles[i]).length\n const bytes = k > 0 ? Math.round((sampled / k) * profiles.length) : 0\n this._profilesCost = { ms: performance.now() - t0, bytes }\n },\n\n getProfiles() {\n return Array.from(this._profiles.values())\n },\n\n resetProfiles() {\n this._profiles.clear()\n this._scheduleProfileUpdate()\n },\n\n // --- Phase 2: Reactive Graph Tracking ---\n\n // `owner` (optional): the effect active when the signal was created; the\n // node dies with it (an {#each} item's {@const}, a class instance created\n // in an effect run).\n trackState(signal, name, componentId, owner) {\n const nodeId = this._nodeIdFor(signal, this._idBySignal, componentId, name)\n this._registerNode(nodeId, componentId, 'state', name, new WeakRef(signal), owner)\n this._idBySignal.set(signal, nodeId)\n this._nameProxyRoot(nodeId, name, componentId)\n this._pollAdd(nodeId)\n },\n\n trackProxy(proxy, name, componentId, owner) {\n const nodeId = this._nodeIdFor(proxy, this._idByProxy, componentId, name)\n this._reactiveProxies.set(nodeId, new WeakRef(proxy))\n // The proxy itself stays weakly held (_reactiveProxies). The marker is\n // held strongly so the node is not GC-dropped while the component lives;\n // _cleanupComponent removes it on unmount.\n const marker = { v: '(proxy)', _isProxy: true }\n this._registerNode(nodeId, componentId, 'state', name, { deref: () => marker }, owner)\n this._idBySignal.set(marker, nodeId)\n this._idByProxy.set(proxy, nodeId)\n this._nameProxyRoot(nodeId, name, componentId)\n this._pollAdd(nodeId)\n },\n\n trackDerived(signal, name, componentId, owner) {\n const nodeId = this._nodeIdFor(signal, this._idBySignal, componentId, name)\n this._registerNode(nodeId, componentId, 'derived', name, new WeakRef(signal), owner)\n this._idBySignal.set(signal, nodeId)\n },\n\n // A user effect object (already created). Kept for callers that have one.\n trackEffect(effect, name, componentId) {\n const nodeId = componentId + ':' + name\n const target = effect ?? { v: undefined, _isEffect: true }\n this._registerNode(\n nodeId,\n componentId,\n 'effect',\n name,\n effect ? new WeakRef(target) : { deref: () => target },\n )\n this._idBySignal.set(target, nodeId)\n return effect\n },\n\n // $effect / $effect.pre being created now (the wrapper). The effect object\n // may not exist yet (deferred to mount): the node holds a placeholder\n // until bindEffect() is called on the effect's first run. kind: 'effect'\n // | 'effect_pre'; names are effect_1, effect_pre_1, ... per component.\n trackUserEffect(kind, componentId, owner) {\n let seq = this._effectSeq.get(componentId)\n if (!seq) {\n seq = { effect: 0, effect_pre: 0 }\n this._effectSeq.set(componentId, seq)\n }\n const name = kind + '_' + ++seq[kind]\n const nodeId = componentId + ':' + name\n const placeholder = { v: undefined, _isEffect: true }\n this._registerNode(nodeId, componentId, 'effect', name, { deref: () => placeholder }, owner)\n return nodeId\n },\n\n bindEffect(nodeId, effect) {\n const entry = nodeId !== null && this._reactiveNodes.get(nodeId)\n if (!entry || !effect || typeof effect !== 'object') return\n entry.signal = new WeakRef(effect)\n entry.effect = true\n this._idBySignal.set(effect, nodeId)\n },\n\n // The component's mount hook effect (the wrapper's, created at pop): its\n // parent is the effect the component's markup effects were created in.\n setComponentEffect(id, effect) {\n const instance = this._instances.get(id)\n if (instance) instance.hook = new WeakRef(effect)\n },\n\n // Markup effects of a component: the effects of its template\n // (template_effect, {#if}/{#each}/... blocks, <svelte:head>), i.e. the\n // effects under the hook's parent created in the component's context\n // (effect.ctx), without descending into other components or the\n // tracked $effect nodes. Svelte links child effects via first/next.\n _markupEffects(id) {\n const instance = this._instances.get(id)\n const hook = instance?.hook?.deref()\n if (!hook?.ctx || !hook.parent) return []\n const ctx = hook.ctx\n const out = []\n const stack = []\n for (let e = hook.parent.first; e; e = e.next) stack.push(e)\n while (stack.length > 0) {\n const e = stack.pop()\n if (e === hook || e.ctx !== ctx) continue\n if (e.deps && !this._idBySignal.has(e)) out.push(e)\n for (let c = e.first; c; c = c.next) stack.push(c)\n }\n return out\n },\n\n // The tracked node a proxy's property source belongs to. Svelte (dev)\n // labels a proxy's sources after the proxy's path ('todos[0].text',\n // 'cart.items.length', 'todos version'); the root name is a $state node\n // name. Many live nodes may share the name (one per instance), so the\n // candidates are looked up per scope: the reader's component, then its\n // ancestors (props flow down), then module scopes, then all — each\n // narrowed by the source's value at that path (identity for objects).\n // Cost O(label + ancestry depth) for the common cases. null when\n // unresolved.\n _sourceOwner(source, readerCid, liveSignal) {\n const label = source.label\n if (typeof label !== 'string' || this._proxyNames.size === 0) return null\n let named = null\n let rest = ''\n for (let i = label.length; i > 0; i--) {\n const ch = i === label.length ? '' : label[i]\n if (ch !== '' && ch !== '.' && ch !== '[' && ch !== ' ') continue\n named = this._proxyNames.get(label.slice(0, i))\n if (named) {\n rest = label.slice(i)\n break\n }\n }\n if (!named) return null\n let path\n // live candidates whose value at the source's path is the source's\n // value; without a property path (' version'), all live candidates\n const fits = ids => {\n const live = [...ids].filter(id => liveSignal(id))\n if (live.length === 0) return live\n if (path === undefined) path = this._labelPath(rest)\n if (!path) return live\n const v = source.v\n return live.filter(id => {\n const at = this._valueAt(this._rootValue(id), path)\n return (\n at !== __NO_VALUE && (Object.is(at, v) || (typeof v === 'symbol' && at === undefined))\n )\n })\n }\n const scopes = []\n for (let cid = readerCid; cid !== null && cid !== undefined;) {\n scopes.push(cid)\n const instance = this._instances.get(cid)\n cid = instance ? instance.parentId : null\n }\n // Module scopes holding the name. Iterated from the module list, not\n // from `named`: a name shared by every row of a list (one scope per\n // instance) made this O(instances) per source, O(n²) per graph build.\n for (const cid of this._modules.keys()) if (named.has(cid)) scopes.push(cid)\n for (const cid of scopes) {\n const ids = named.get(cid)\n const found = ids ? fits(ids) : []\n if (found.length > 0) return found[0]\n }\n // not in the reader's ancestry or a module: any matching node, else the\n // nearest live one by name\n const all = []\n for (const ids of named.values()) for (const id of ids) all.push(id)\n const found = fits(all)\n if (found.length > 0) return found[0]\n for (const cid of scopes) for (const id of named.get(cid) ?? []) if (liveSignal(id)) return id\n return all.find(id => liveSignal(id)) ?? null\n },\n\n // '.items[0].text' -> ['items', '0', 'text']; null for ' version' and\n // anything else that is not a property path.\n _labelPath(rest) {\n const path = []\n const re = /\\.([A-Za-z_$][\\w$]*)|\\[(\\d+)\\]|\\['((?:[^'\\\\]|\\\\.)*)'\\]/y\n let m\n while (re.lastIndex < rest.length && (m = re.exec(rest))) path.push(m[1] ?? m[2] ?? m[3])\n return re.lastIndex === rest.length || rest.length === 0 ? path : null\n },\n\n // Own-property walk (getOwnPropertyDescriptor does not create sources on\n // a Svelte proxy, unlike reading a missing property).\n _valueAt(obj, path) {\n let v = obj\n for (const key of path) {\n if (v === null || (typeof v !== 'object' && typeof v !== 'function')) return __NO_VALUE\n let d\n try {\n d = Object.getOwnPropertyDescriptor(v, key)\n } catch {\n return __NO_VALUE\n }\n if (!d) return __NO_VALUE\n v = 'value' in d ? d.value : __NO_VALUE\n if (v === __NO_VALUE) return v\n }\n return v\n },\n\n _nameProxyRoot(nodeId, name, componentId) {\n let named = this._proxyNames.get(name)\n if (!named) {\n named = new Map()\n this._proxyNames.set(name, named)\n }\n let inScope = named.get(componentId)\n if (!inScope) {\n inScope = new Set()\n named.set(componentId, inScope)\n }\n inScope.add(nodeId)\n },\n\n // The proxy a $state node holds now (tag_proxy: the proxy itself; a\n // state signal: its current value), or undefined.\n _rootValue(nodeId) {\n const proxy = this._reactiveProxies.get(nodeId)\n if (proxy) return proxy.deref()\n const signal = this._reactiveNodes.get(nodeId)?.signal.deref()\n return signal ? signal.v : undefined\n },\n\n // A component whose init threw (the wrapper unwinds its stack): it never\n // mounted and never will, so it leaves the tree and the init stack.\n abortInit(id) {\n const idx = this._stack.indexOf(id)\n if (idx !== -1) this._stack.splice(idx, 1)\n const instance = this._instances.get(id)\n if (!instance) return\n if (instance.parentId !== null) {\n const parent = this._instances.get(instance.parentId)\n if (parent) parent.children.delete(id)\n }\n this._removeChildren(id)\n this._cleanupComponent(id)\n this._scheduleUpdate()\n },\n\n _graphNode(nodeId, entry, signal) {\n const node = { ...entry.meta }\n if (signal._isProxy) {\n const proxy = this._reactiveProxies.get(nodeId)?.deref()\n if (proxy) {\n try {\n node.value = Array.isArray(proxy)\n ? '[' + proxy.length + ']'\n : '{' + Object.keys(proxy).length + '}'\n } catch {\n node.value = '(proxy)'\n }\n }\n } else if (node.type === 'derived' && typeof signal.v === 'symbol') {\n // Svelte computes a derived lazily: until something reads it, v is\n // the UNINITIALIZED marker (a symbol)\n node.unevaluated = true\n } else if (node.type !== 'effect' && signal.v !== undefined && typeof signal.v !== 'symbol') {\n try {\n const v = signal.v\n if (\n typeof v === 'number' ||\n typeof v === 'string' ||\n typeof v === 'boolean' ||\n v === null\n ) {\n node.value = v\n } else {\n node.value = '(object)'\n }\n } catch {\n /* ignore */\n }\n }\n return node\n },\n\n // Reactive graph (§6.7 A/D). Caps are applied while building: past\n // maxNodes no node objects are created and only edges whose endpoints\n // are both included are emitted (the rest are counted in edgesOmitted).\n // - scoped (componentId): that component's nodes plus the tracked nodes\n // directly connected to them (via deps / reactions through untracked\n // intermediates). Dependencies are resolved through _idBySignal, so\n // the cost is O(scope + neighbours), not O(all nodes). The walk is\n // completed even past the cap, so total.nodes/edges are exact.\n // - global: nodes in registration order up to maxNodes ('global-head'),\n // with their incoming dependency edges. Nodes past the cap are not\n // dereferenced; total.nodes is the registered count (may include\n // nodes whose signal was already collected, nodesKind 'registered')\n // and total.edges is null when the walk stopped early (not guessed).\n // Template consumers: the compiler turns every dynamic part of the markup\n // ({expr}, attributes, {#if}/{#each}/{#key}/{#await} conditions,\n // <svelte:head>) into effects that are not tracked one by one. A read\n // from such an effect is reported as an edge to the synthetic node\n // '<componentId>:(template)' (type 'template') of the component the\n // effect belongs to (effect.ctx), so a value only the markup reads is\n // not shown without readers.\n getReactiveGraph(componentId, caps) {\n const scoped = componentId !== undefined && componentId !== null\n const maxNodes = this._graphCap(caps?.maxNodes, 5000)\n const maxEdges = this._graphCap(caps?.maxEdges, 20000)\n const live = new Map()\n // Live signal of a tracked node, or null (forgets dead / unmounted nodes).\n const liveSignal = nodeId => {\n if (live.has(nodeId)) return live.get(nodeId)\n const signal = this._liveSignal(nodeId)\n live.set(nodeId, signal)\n return signal\n }\n const idOf = dep => {\n const id = this._idBySignal.get(dep)\n return id !== undefined && liveSignal(id) === dep ? id : null\n }\n // Synthetic template nodes reached in this build: id -> componentId.\n const templates = new Map()\n // Template node of an untracked effect (no reactions: not a derived),\n // or null when its component is unknown / unmounted.\n const templateOf = effect => {\n if (!effect || 'reactions' in effect || !effect.ctx) return null\n const cid = this._idByContext.get(effect.ctx)\n if (cid === undefined || !this._instances.has(cid)) return null\n const id = cid + ':(template)'\n templates.set(id, cid)\n return id\n }\n\n const included = new Set()\n const seen = new Set()\n const edges = []\n const edgeSet = new Set()\n let edgesOmitted = 0\n let truncated = false\n const see = id => {\n seen.add(id)\n if (!included.has(id) && included.size < maxNodes) included.add(id)\n return included.has(id)\n }\n const addEdge = (from, to) => {\n const key = from + '>' + to\n if (from === to || edgeSet.has(key)) return\n edgeSet.add(key)\n const inFrom = see(from)\n const inTo = see(to)\n if (inFrom && inTo && edges.length < maxEdges) edges.push({ from, to })\n else edgesOmitted++\n }\n // Walk a signal's neighbours (deps or reactions) through untracked\n // intermediates until tracked nodes are reached. onTemplate (reactions\n // only) receives the template node of each untracked effect reached.\n // On the deps side an untracked leaf source (a proxy's property) is\n // resolved to its proxy's node (readerCid: the reading component).\n // nodeId -> dependencies on signals devtools does not track (created\n // in node_modules, e.g. SvelteKit's page state, or outside any\n // component/module body): reported so such a node is not \"isolated\"\n const untracked = new Map()\n const walk = (start, field, onHit, onTemplate, readerCid, onUntracked) => {\n if (!start) return\n const visited = new Set()\n const queue = [...start]\n // Index cursor instead of queue.shift(): shift is O(queue) per pop.\n for (let qi = 0; qi < queue.length; qi++) {\n const dep = queue[qi]\n if (!dep || visited.has(dep)) continue\n visited.add(dep)\n const id = idOf(dep)\n if (id) {\n if (onHit) onHit(id)\n } else if (dep[field]) {\n for (const d of dep[field]) queue.push(d)\n } else if (onTemplate) {\n const t = templateOf(dep)\n if (t) onTemplate(t)\n } else if (field === 'deps' && onHit && !('fn' in dep)) {\n const owner = this._sourceOwner(dep, readerCid, liveSignal)\n if (owner) onHit(owner)\n else if (onUntracked) onUntracked()\n }\n }\n }\n const nodeCid = nodeId => this._reactiveNodes.get(nodeId).meta.componentId\n const countUntracked = nodeId => () => untracked.set(nodeId, (untracked.get(nodeId) ?? 0) + 1)\n // Reads of a component's markup effects: edges into its template node\n // (filter: keep only edges from these node ids, for neighbours).\n const markupEdges = (cid, filter) => {\n const effects = this._markupEffects(cid)\n if (effects.length === 0) return\n const t = cid + ':(template)'\n for (const effect of effects) {\n walk(\n effect.deps,\n 'deps',\n id => {\n if (filter && !filter(id)) return\n templates.set(t, cid)\n addEdge(id, t)\n },\n null,\n cid,\n )\n }\n }\n\n let totalNodes = 0\n let totalEdges = null\n if (scoped) {\n // a copy: liveSignal() forgets dead nodes during the loop\n for (const nodeId of Array.from(this._nodesByComponent.get(componentId) ?? [])) {\n const signal = liveSignal(nodeId)\n if (!signal) continue\n see(nodeId)\n walk(\n signal.deps,\n 'deps',\n depId => addEdge(depId, nodeId),\n null,\n componentId,\n countUntracked(nodeId),\n )\n const toReader = rId => addEdge(nodeId, rId)\n walk(signal.reactions, 'reactions', toReader, toReader)\n }\n if (this._instances.has(componentId)) markupEdges(componentId, null)\n // Readers in direct children (props): a proxy has no reactions list\n // of its own, so its readers are found from their dependencies.\n const own = id => nodeCid(id) === componentId\n const instance = this._instances.get(componentId)\n for (const child of instance ? instance.children : []) {\n // a copy: liveSignal() forgets dead nodes during the loop\n for (const nodeId of Array.from(this._nodesByComponent.get(child) ?? [])) {\n const signal = liveSignal(nodeId)\n if (signal)\n walk(signal.deps, 'deps', depId => own(depId) && addEdge(depId, nodeId), null, child)\n }\n markupEdges(child, own)\n }\n totalNodes = seen.size\n totalEdges = edgeSet.size\n truncated = included.size < seen.size || edgesOmitted > 0\n } else {\n let complete = true\n // a copy: liveSignal() forgets dead nodes during the loop\n for (const nodeId of Array.from(this._reactiveNodes.keys())) {\n if (included.size >= maxNodes && !included.has(nodeId)) {\n complete = false\n break\n }\n const signal = liveSignal(nodeId)\n if (!signal) continue\n see(nodeId)\n walk(\n signal.deps,\n 'deps',\n depId => addEdge(depId, nodeId),\n null,\n nodeCid(nodeId),\n countUntracked(nodeId),\n )\n // tracked readers are found from their own deps; only template\n // readers need the reactions side\n walk(signal.reactions, 'reactions', null, t => addEdge(nodeId, t))\n }\n if (complete) for (const cid of this._instances.keys()) markupEdges(cid, null)\n // registered count (+ template nodes reached), minus nodes found\n // dead while building\n totalNodes = this._reactiveNodes.size + templates.size\n totalEdges = complete ? edgeSet.size : null\n truncated = !complete || edgesOmitted > 0\n }\n\n const nodes = []\n for (const nodeId of included) {\n const cid = templates.get(nodeId)\n if (cid !== undefined) {\n const instance = this._instances.get(cid)\n nodes.push({\n id: nodeId,\n type: 'template',\n name: '(template)',\n componentId: cid,\n componentFile: instance ? instance.file : '',\n })\n continue\n }\n const signal = liveSignal(nodeId)\n if (!signal) continue\n const node = this._graphNode(nodeId, this._reactiveNodes.get(nodeId), signal)\n if (untracked.has(nodeId)) node.untrackedDeps = untracked.get(nodeId)\n nodes.push(node)\n }\n return {\n scope: scoped ? componentId : null,\n nodes,\n edges,\n total: { nodes: totalNodes, nodesKind: 'registered', edges: totalEdges },\n truncated,\n edgesOmitted,\n policy: scoped ? 'scoped' : 'global-head',\n }\n },\n\n _graphCap(value, max) {\n const n = Math.floor(Number(value))\n return Number.isFinite(n) && n >= 1 ? Math.min(n, max) : max\n },\n\n // Request (§6.7 A + review M1): { requestId?, epoch?, componentId?,\n // maxNodes?, maxEdges? }. A request for another page load (epoch) is not\n // answered by this one; the reply echoes requestId and epoch. An old\n // server sends {} → global graph with the default caps (= its LIMITS).\n sendReactiveGraph(request) {\n const req = request ?? {}\n if (req.epoch !== undefined && req.epoch !== null && req.epoch !== this._epoch) return\n const cid = typeof req.componentId === 'number' ? req.componentId : null\n const graph = this.getReactiveGraph(cid, { maxNodes: req.maxNodes, maxEdges: req.maxEdges })\n graph.epoch = this._epoch\n // freshness (review): when this answer was built; caches keep it\n graph.computedAt = Date.now()\n if (req.requestId !== undefined) graph.requestId = req.requestId\n if (import.meta.hot) {\n import.meta.hot.send('svelte-devtools:reactive-graph', graph)\n }\n },\n\n // Overview aggregate (§6.7 I/J). Built from the activity buckets of the\n // window (whole seconds: the current partial second plus the previous\n // ones, ceil(windowMs / 1000) buckets) — cost O(components active in the\n // window), no graph, no node scan. Rows rank by sampled changes, then\n // renders, then render ms; rows + other = total (components and nodes).\n getReactiveSummary(opts) {\n const o = opts ?? {}\n const topK = __clampInt(o.topK, 1, 200, 50)\n const windowMs = __clampInt(o.windowMs, 1000, 60000, 10000)\n const nowSec = Math.floor(performance.now() / 1000)\n const agg = new Map()\n let sampledMs = 0\n for (let k = 0; k < Math.ceil(windowMs / 1000); k++) {\n const sec = nowSec - k\n const b = this._activity[((sec % 60) + 60) % 60]\n if (!b || b.second !== sec) continue\n sampledMs += b.sampledMs\n for (const [cid, r] of b.rows) {\n if (!this._scopeLive(cid)) continue\n let a = agg.get(cid)\n if (!a) {\n a = { changes: 0, renders: 0, renderMs: 0 }\n agg.set(cid, a)\n }\n a.changes += r.changes\n a.renders += r.renders\n a.renderMs += r.renderMs\n }\n }\n const ranked = [...agg].toSorted(\n (x, y) =>\n y[1].changes - x[1].changes ||\n y[1].renders - x[1].renders ||\n y[1].renderMs - x[1].renderMs ||\n x[0] - y[0],\n )\n let rowNodes = 0\n const rows = ranked.slice(0, topK).map(([cid, a]) => {\n const n = this._nodeCounts.get(cid) ?? { state: 0, derived: 0, effect: 0 }\n rowNodes += n.state + n.derived + n.effect\n const row = {\n componentId: cid,\n file: this._scopeFile(cid),\n nodes: { state: n.state, derived: n.derived, effect: n.effect },\n changes: a.changes,\n renders: a.renders,\n renderMs: Math.round(a.renderMs * 1000) / 1000,\n }\n // module scope (shared .svelte.js state), not a component instance\n if (this._modules.has(cid)) row.kind = 'module'\n return row\n })\n const t = this._nodeTotals\n // module scopes count as rows like components (rows + other = total)\n const scopes = this._instances.size + this._modules.size\n const until = Date.now()\n return {\n epoch: this._epoch,\n window: {\n ms: windowMs,\n since: until - windowMs,\n until,\n sampledActiveMs: Math.min(windowMs, sampledMs),\n },\n policy: 'sampled-200ms',\n coverage: 'component-init',\n components: { total: scopes, withActivity: agg.size },\n rows,\n other: {\n components: scopes - rows.length,\n nodes: t.state + t.derived + t.effect - rowNodes,\n },\n truncated: agg.size > topK,\n capabilities: { valueInspection: false, signalHistory: false, writeCause: false },\n // Seed coverage: changes of pending nodes are not observable yet.\n baseline: this._baselineInfo(),\n }\n },\n\n // Request { requestId?, epoch?, topK?, windowMs? } (same correlation as\n // the graph, review M1).\n sendReactiveSummary(request) {\n const req = request ?? {}\n if (req.epoch !== undefined && req.epoch !== null && req.epoch !== this._epoch) return\n const summary = this.getReactiveSummary(req)\n if (req.requestId !== undefined) summary.requestId = req.requestId\n if (import.meta.hot) {\n import.meta.hot.send('svelte-devtools:reactive-summary', summary)\n }\n },\n\n // --- Phase 3: State Timeline ---\n\n // Current value of a $state node: the signal value, or for tag_proxy\n // nodes (non-reassigned object/array state) the live proxy itself.\n // Returns a sentinel when the value can't be read.\n _readStateValue(nodeId, signal) {\n if (signal._isProxy) {\n const proxy = this._reactiveProxies.get(nodeId)?.deref()\n return proxy === undefined ? __NO_VALUE : proxy\n }\n const v = signal.v\n // Svelte's UNINITIALIZED marker is a symbol; functions aren't state data.\n return typeof v === 'symbol' || typeof v === 'function' ? __NO_VALUE : v\n },\n\n // Runs every 200 ms in the user's app, so it must stay cheap regardless of\n // how much state the app holds (§6.7 D).\n // 1. Hint pass, time-sliced: at most HINT_NODES $state nodes per tick,\n // continuing from a cursor carried across ticks, so a full sweep over\n // n nodes takes ceil(n / HINT_NODES) ticks (_pollSweep.lastMs is the\n // measured sweep time = worst-case detection delay). Per node O(1):\n // primitives are compared directly and recorded at once; objects\n // whose reference or Svelte write version (wv) changed are added to\n // _pollDirty, which persists across ticks until serialized.\n // 2. Serialization work is limited to BUDGET_MS per tick (dirty nodes\n // carry over, nothing is dropped).\n // 3. In-place deep mutations (proxies don't bump an outer wv) are found by\n // time-based re-checks: each object is re-verified no earlier than\n // nextCheckAt = now + max(RECHECK_MS, 50 x its serialization cost),\n // paid from a DEEP_MS-per-tick credit, so the amortized cost is bounded\n // however many large states the app holds.\n // 4. Values serializing above MAX_SNAPSHOT_CHARS are kept as length+hash\n // (not the string) and appear in the timeline as a summary.\n // Writes between two visits of a node are observed as one change (the\n // timeline is a sample, policy 'sampled-200ms'; not counted as dropped).\n _pollStateValues(baseline) {\n const HINT_NODES = 4096\n const SWEEP_NODES = 2048\n const BUDGET_MS = 2\n const DEEP_MS = 0.5\n const now = performance.now()\n if (!baseline) {\n // nodes of destroyed {#each} items / effect runs leave the counts\n this._sweepNodes(SWEEP_NODES)\n this._deepCredit = Math.min(10 * DEEP_MS, (this._deepCredit || 0) + DEEP_MS)\n // this tick samples 200 ms of wall time (window.sampledActiveMs)\n const bucket = this._bucket()\n bucket.sampledMs = Math.min(1000, bucket.sampledMs + 200)\n }\n const ids = this._pollIds\n const due = []\n const limit = Math.min(HINT_NODES, ids.length)\n for (let visited = 0; visited < limit && ids.length > 0; visited++) {\n if (this._pollCursor >= ids.length) {\n this._pollCursor = 0\n if (!baseline) {\n if (this._pollSweep.startedAt) this._pollSweep.lastMs = now - this._pollSweep.startedAt\n this._pollSweep.startedAt = now\n this._pollSweep.nodes = ids.length\n }\n }\n if (!baseline && !this._pollSweep.startedAt) this._pollSweep.startedAt = now\n const nodeId = ids[this._pollCursor]\n const entry = this._reactiveNodes.get(nodeId)\n if (entry?.meta.type !== 'state') {\n // re-tracked as another type: drop from the poll list (slot reused)\n this._pollRemove(nodeId)\n continue\n }\n if (!this._scopeLive(entry.meta.componentId)) {\n this._forgetNode(nodeId) // swaps the last id into this slot\n continue\n }\n this._pollCursor++\n const signal = entry.signal.deref()\n const value = signal ? this._readStateValue(nodeId, signal) : __NO_VALUE\n if (value === __NO_VALUE) {\n // nothing readable (collected, uninitialized, function): not pending\n this._unseeded.delete(nodeId)\n continue\n }\n if (value === null || typeof value !== 'object') {\n const had = this._stateSnapshots.has(nodeId)\n const prev = this._stateSnapshots.get(nodeId)\n if (had && Object.is(prev, value)) continue\n // Forget the object key so object -> primitive -> same object again\n // is still recorded as a change.\n if (this._stateSnapshotStrs) this._stateSnapshotStrs.delete(nodeId)\n this._pollDirty.delete(nodeId)\n if (!had) {\n // first observation: seed only\n this._stateSnapshots.set(nodeId, value)\n this._unseeded.delete(nodeId)\n continue\n }\n this._recordChange(\n nodeId,\n entry,\n prev,\n value,\n typeof value === 'string' ? 2 * value.length : 64,\n )\n continue\n }\n let meta = this._pollMeta.get(nodeId)\n if (!meta) {\n meta = { ref: undefined, wv: undefined, nextCheckAt: 0 }\n this._pollMeta.set(nodeId, meta)\n }\n if (meta.ref !== value || meta.wv !== signal.wv) this._pollDirty.add(nodeId)\n else if (now >= meta.nextCheckAt) due.push(nodeId)\n }\n const start = performance.now()\n for (const nodeId of this._pollDirty) {\n if (performance.now() - start > BUDGET_MS) return\n this._pollDirty.delete(nodeId)\n this._serializeNode(nodeId, false)\n }\n for (const nodeId of due) {\n if (this._deepCredit <= 0 || performance.now() - start > BUDGET_MS) return\n this._serializeNode(nodeId, true)\n }\n },\n\n // Activation (late consumer): nodes registered while inactive have no\n // seed yet, so a write before their first visit could not be seen as a\n // change. The first slice is seeded at activation instead of 200 ms later:\n // ONE normal pass (<= HINT_NODES nodes, the per-tick serialization budget;\n // the rest follow on the usual ticks). Seeds record nothing; readiness is\n // disclosed in the summary as baseline { complete, pendingNodes }.\n _pollBaseline() {\n this._baselining = true\n try {\n this._pollStateValues(true)\n } catch {\n /* never break activation */\n } finally {\n this._baselining = false\n }\n },\n\n _serializeNode(nodeId, deep) {\n const MAX_SNAPSHOT_CHARS = 32768\n const RECHECK_MS = 1000\n const entry = this._reactiveNodes.get(nodeId)\n const meta = this._pollMeta.get(nodeId)\n if (!entry || !meta) return\n const signal = entry.signal.deref()\n if (!signal) return\n const value = this._readStateValue(nodeId, signal)\n if (value === __NO_VALUE || value === null || typeof value !== 'object') return\n try {\n const t0 = performance.now()\n const str = JSON.stringify(value)\n const cost = performance.now() - t0\n if (deep) this._deepCredit -= cost\n meta.ref = value\n meta.wv = signal.wv\n meta.nextCheckAt = t0 + Math.max(RECHECK_MS, 50 * cost)\n // Small values keep the string (exact compare); large ones only a\n // length+hash so a 5 MB array doesn't pin 5 MB per node.\n const key =\n str === undefined\n ? ''\n : str.length > MAX_SNAPSHOT_CHARS\n ? str.length + ':' + __hash(str)\n : str\n this._stateSnapshotStrs ??= new Map()\n const hadKey = this._stateSnapshotStrs.has(nodeId)\n if (hadKey && this._stateSnapshotStrs.get(nodeId) === key) return\n this._stateSnapshotStrs.set(nodeId, key)\n const tooLarge = str !== undefined && str.length > MAX_SNAPSHOT_CHARS\n const snapshot =\n str === undefined\n ? null\n : tooLarge\n ? '(object: ' + str.length + ' chars, too large to snapshot)'\n : JSON.parse(str)\n const size = typeof snapshot === 'string' ? 64 : str.length\n if (!this._stateSnapshots.has(nodeId)) {\n // first observation: seed only (no entry, no counters)\n this._stateSnapshots.set(nodeId, snapshot)\n this._lastSnapshotSize.set(nodeId, size)\n this._unseeded.delete(nodeId)\n return\n }\n if (tooLarge) this._valueTooLarge++\n const prev = this._stateSnapshots.get(nodeId)\n this._recordChange(\n nodeId,\n entry,\n prev,\n snapshot,\n size + (this._lastSnapshotSize.get(nodeId) ?? 0),\n )\n this._lastSnapshotSize.set(nodeId, size)\n } catch {\n // non-serializable (cycles, BigInt): never observable, so not pending\n this._unseeded.delete(nodeId)\n }\n },\n\n _recordChange(nodeId, entry, oldValue, newValue, approxBytes) {\n const change = {\n id: nodeId,\n name: entry.meta.name,\n componentFile: entry.meta.componentFile,\n oldValue,\n newValue,\n timestamp: Date.now(),\n }\n // 0 (an empty string) or no estimate: assume a small value.\n const bytes = (approxBytes > 0 ? approxBytes : 64) + 192\n // seq stays runtime-internal: the server assigns its own seq (§6.4).\n this._entryInfo.set(change, { seq: ++this._timelineSeq, bytes })\n this._stateTimeline.push(change)\n this._timelineBytes += bytes\n // sampled change count (§6.7 J IA2): independent of the ring\n this._activityRow(entry.meta.componentId).changes++\n this._stateSnapshots.set(nodeId, newValue)\n // The ring (_trimTimeline) is applied in bulk, not with one splice per\n // change (a poll tick can record thousands): before every read (each\n // push — with a hot channel and an active consumer, at least every 200\n // changes — the full snapshot, getStateTimeline() and clear), and here\n // once more than __TIMELINE_TRIM_AT entries are held or the byte budget\n // is exceeded, which bounds memory when nothing reads or pushes.\n if (\n this._stateTimeline.length > __TIMELINE_TRIM_AT ||\n this._timelineBytes > __TIMELINE_BYTES\n ) {\n this._trimTimeline()\n }\n this._scheduleTimelineUpdate()\n },\n\n // Ring: at most 500 entries and __TIMELINE_BYTES (the newest entry is\n // always kept). Removed entries that were never pushed are disclosed\n // as dropped (§6.7 C); pushed ones are already on the server.\n _trimTimeline() {\n const all = this._stateTimeline\n let cut = 0\n let bytesLeft = this._timelineBytes\n while (cut < all.length - 1 && (all.length - cut > 500 || bytesLeft > __TIMELINE_BYTES)) {\n const info = this._entryInfo.get(all[cut])\n const reason = all.length - cut > 500 ? 'runtime-count' : 'runtime-bytes'\n if (info.seq > this._pushedSeq) this._timelineDropped[reason]++\n bytesLeft -= info.bytes\n cut++\n }\n if (cut > 0) {\n all.splice(0, cut)\n this._timelineBytes = bytesLeft\n }\n },\n\n // Push (§6.7 C): a throttle, not a debounce — a pending timer is never\n // re-armed, so unsent entries leave within 300 ms of the first one even\n // under continuous change — plus an immediate flush once 200 entries\n // (one message) are unsent, since one poll tick can record thousands.\n _scheduleTimelineUpdate() {\n if (!this._active || this._baselining) return\n if (this._timelineSeq - this._pushedSeq >= 200) {\n this._flushTimeline()\n return\n }\n if (this._timelineDebounceTimer) return\n this._timelineDebounceTimer = setTimeout(() => {\n this._timelineDebounceTimer = null\n this._flushTimeline()\n }, 300)\n },\n\n _flushTimeline() {\n if (this._timelineDebounceTimer) {\n clearTimeout(this._timelineDebounceTimer)\n this._timelineDebounceTimer = null\n }\n if (!import.meta.hot) return\n for (const msg of this._timelineDeltas()) {\n import.meta.hot.send('svelte-devtools:state-timeline', msg)\n }\n },\n\n // Disclosure counters since the previous push, attached to (and reset\n // by) the next message: dropped [{ reason, count }] and valueTooLarge.\n _takeTimelineDisclosure(msg) {\n msg.baseline = this._baselineInfo()\n this._sentPendingNodes = msg.baseline.pendingNodes\n const dropped = []\n for (const reason of ['runtime-count', 'runtime-bytes']) {\n const count = this._timelineDropped[reason]\n if (count > 0) dropped.push({ reason, count })\n this._timelineDropped[reason] = 0\n }\n if (dropped.length > 0) msg.dropped = dropped\n if (this._valueTooLarge > 0) msg.valueTooLarge = this._valueTooLarge\n this._valueTooLarge = 0\n return msg\n },\n\n // Seed coverage (review B-2), on every state-timeline message and the\n // summary: pendingNodes = polled $state nodes without a first sample;\n // their writes are not observable yet.\n _baselineInfo() {\n return { complete: this._unseeded.size === 0, pendingNodes: this._unseeded.size }\n },\n\n _hasTimelineDisclosure() {\n return (\n this._sentPendingNodes !== this._unseeded.size ||\n this._timelineDropped['runtime-count'] > 0 ||\n this._timelineDropped['runtime-bytes'] > 0 ||\n this._valueTooLarge > 0\n )\n },\n\n // Delta push (docs/devframe-migration.md §6.4): only entries recorded\n // since the previous push, ≤ 200 per message, tagged with a per-page-load\n // epoch; reset after clearStateTimeline(). A message with no changes is\n // still sent when there is something to disclose (all unsent dropped).\n _timelineDeltas() {\n this._trimTimeline()\n const all = this._stateTimeline\n let start = all.length\n while (start > 0 && this._entryInfo.get(all[start - 1]).seq > this._pushedSeq) start--\n const pending = all.slice(start)\n const msgs = []\n const first = this._timelineReset || this._hasTimelineDisclosure()\n // A first message goes out even with no pending changes (disclosure only).\n const end = first ? Math.max(pending.length, 1) : pending.length\n for (let i = 0; i < end; i += 200) {\n const msg = { epoch: this._epoch, changes: pending.slice(i, i + 200) }\n if (i === 0 && this._timelineReset) msg.reset = true\n if (i === 0) this._takeTimelineDisclosure(msg)\n else msg.baseline = this._baselineInfo()\n msgs.push(msg)\n }\n this._timelineReset = false\n this._pushedSeq = this._timelineSeq\n return msgs\n },\n\n // Full buffer (reset: true) — reply to request-state-timeline and the\n // activation snapshot. Newest entries first up to __TIMELINE_BYTES, the\n // server's own buffer budget, so nothing is sent that it would drop.\n _timelineFull() {\n this._trimTimeline()\n const all = this._stateTimeline\n let start = all.length\n let bytes = 0\n while (start > 0) {\n const size = this._entryInfo.get(all[start - 1]).bytes\n if (bytes + size > __TIMELINE_BYTES && start < all.length) break\n bytes += size\n start--\n }\n this._timelineReset = false\n this._pushedSeq = this._timelineSeq\n return this._takeTimelineDisclosure({\n epoch: this._epoch,\n changes: all.slice(start),\n reset: true,\n })\n },\n\n getStateTimeline() {\n this._trimTimeline()\n return this._stateTimeline\n },\n\n clearStateTimeline() {\n // Ring first: unsent entries past the cap are disclosed as dropped,\n // exactly as if they had been removed when recorded.\n this._trimTimeline()\n this._stateTimeline = []\n this._timelineBytes = 0\n this._pushedSeq = this._timelineSeq\n this._timelineReset = true\n this._scheduleTimelineUpdate()\n },\n\n // --- FPS Monitoring ---\n // Uses requestAnimationFrame to measure frame rate with minimal overhead.\n // Only stores timestamps - no allocations per frame beyond a single array push.\n _fpsFrameTimes: [],\n\n _fpsLoop(gen) {\n if (gen !== this._fpsGen) return\n this._fpsFrameTimes.push(performance.now())\n requestAnimationFrame(() => this._fpsLoop(gen))\n },\n\n _isVisible() {\n if (typeof document === 'undefined') return true\n return document.visibilityState !== 'hidden'\n },\n\n _setSubscription(data) {\n const wasActive = this._active\n this._active = !!data?.active\n this._componentDeltas = !!data?.componentDeltas\n if (!this._active) {\n this._pendingAdded.clear()\n this._pendingRemoved.clear()\n }\n // resync: the server holds no full base for this epoch (§6.5, review\n // C1), or we reconnected to a possibly restarted server.\n const resync = this._resync || !!data?.resync\n this._resync = false\n if (this._active && !wasActive) this._pollBaseline()\n if (this._active && (!wasActive || resync)) {\n // Collector state may be stale or empty (first activation, resync, or a\n // reconnect to a possibly restarted server): resend everything once, in\n // the order components -> profiles -> timeline(reset: true); the\n // reset push marks the activation snapshot complete (D4).\n this._sendUpdate(true)\n this._sendProfileUpdate()\n if (import.meta.hot) {\n import.meta.hot.send('svelte-devtools:state-timeline', this._timelineFull())\n }\n }\n this._syncSampling()\n },\n\n // Sampling (state poll + FPS) runs only while active AND the app tab is\n // visible.\n _syncSampling() {\n const want = this._active && this._isVisible()\n if (want && !this._sampling) {\n this._fpsFrameTimes = []\n const gen = ++this._fpsGen\n this._sampling = {\n poll: setInterval(() => {\n this._pollStateValues()\n // seed progress changed: push it even without changes (B-2)\n if (this._sentPendingNodes !== this._unseeded.size) this._scheduleTimelineUpdate()\n }, 200),\n fps: setInterval(() => {\n this._sampleFps()\n }, 500),\n }\n requestAnimationFrame(() => this._fpsLoop(gen))\n } else if (!want && this._sampling) {\n clearInterval(this._sampling.poll)\n clearInterval(this._sampling.fps)\n this._sampling = null\n this._fpsGen++\n this._fpsFrameTimes = []\n }\n },\n\n _sampleFps() {\n const now = performance.now()\n // Remove frame timestamps older than 1 second\n const cutoff = now - 1000\n let i = 0\n while (i < this._fpsFrameTimes.length && this._fpsFrameTimes[i] < cutoff) i++\n if (i > 0) this._fpsFrameTimes.splice(0, i)\n const fps = this._fpsFrameTimes.length\n if (import.meta.hot) {\n import.meta.hot.send('svelte-devtools:fps', { timestamp: Date.now(), fps })\n }\n },\n }\n\n window.__SVELTE_DEVTOOLS__ = __SVELTE_DT\n\n // State polling and FPS sampling start on the server's subscription\n // message (§6.3) and pause while the app tab is hidden.\n if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {\n document.addEventListener('visibilitychange', () => __SVELTE_DT._syncSampling())\n }\n\n // Phase 3: Capture runtime errors\n window.addEventListener('error', event => {\n if (import.meta.hot) {\n import.meta.hot.send('svelte-devtools:runtime-error', {\n message: event.message,\n file: event.filename,\n line: event.lineno,\n column: event.colno,\n stack: event.error?.stack ?? '',\n timestamp: Date.now(),\n })\n }\n })\n window.addEventListener('unhandledrejection', event => {\n if (import.meta.hot) {\n const reason = event.reason\n const message = reason?.message\n import.meta.hot.send('svelte-devtools:runtime-error', {\n // No (or an empty / non-string) message: the stringified reason.\n message: typeof message === 'string' && message !== '' ? message : String(reason),\n stack: reason?.stack ?? '',\n timestamp: Date.now(),\n })\n }\n })\n\n // Listen for reactive graph requests from server\n // Pull requests are answered regardless of the subscription state.\n if (import.meta.hot) {\n import.meta.hot.on('svelte-devtools:subscription', data => {\n __SVELTE_DT._setSubscription(data)\n })\n import.meta.hot.on('vite:ws:connect', () => {\n // The server may have restarted with an empty collector: the reply to\n // runtime-ready is treated as a fresh activation (full snapshot).\n __SVELTE_DT._resync = true\n import.meta.hot.send('svelte-devtools:runtime-ready', {})\n })\n import.meta.hot.send('svelte-devtools:runtime-ready', {})\n import.meta.hot.on('svelte-devtools:request-reactive-graph', data => {\n __SVELTE_DT.sendReactiveGraph(data)\n })\n import.meta.hot.on('svelte-devtools:request-reactive-summary', data => {\n __SVELTE_DT.sendReactiveSummary(data)\n })\n import.meta.hot.on('svelte-devtools:request-state-timeline', () => {\n import.meta.hot.send('svelte-devtools:state-timeline', __SVELTE_DT._timelineFull())\n })\n import.meta.hot.on('svelte-devtools:clear-state-timeline', () => {\n __SVELTE_DT.clearStateTimeline()\n })\n }\n}\n", Ve = "import * as __svelte_original from 'svelte/internal/client'\nexport * from 'svelte/internal/client'\n\nfunction __dt() {\n return typeof window === 'undefined' ? null : window.__SVELTE_DEVTOOLS__\n}\n\n// Component ID stack (parallel to runtime._stack but local to wrapper)\nconst __idStack = []\nfunction __currentId() {\n return __idStack.length > 0 ? __idStack.at(-1) : null\n}\n\n// Tracks the most recently created signal for type determination in tag()\nconst __pendingSignal = { ref: null, type: null }\n\n// Component context -> devtools id (review B1b). A component created later\n// by a block update ({#each}/{#if} after mount) runs outside its parent's\n// push..pop, where the runtime's init stack is empty (the wrapper stack\n// below covers the wrapped block helpers; this covers the rest). Svelte (5.56.8,\n// internal/client) exports active_effect; every effect records the\n// component context it was created in (effect.ctx) and runs with that\n// context restored. The block effect that creates the child belongs to the\n// parent's template, so active_effect.ctx at push time IS the parent's\n// context. Each context is mapped to its id once the component mounted\n// (inside its own deferred effect, where active_effect.ctx is the\n// component's own context). The map lives on the runtime (dt._idByContext)\n// so the reactive graph can name the component of any effect it reaches.\n// Weak map: no leak, no Svelte state touched.\nfunction __parentFromContext() {\n const dt = __dt()\n const effect = __svelte_original.active_effect\n const ctx = effect ? effect.ctx : null\n return dt && ctx && dt._idByContext ? dt._idByContext.get(ctx) : undefined\n}\n\n// Owner of a signal/effect created right now: the component whose init (or\n// wrapped block callback) is running, else — outside init, e.g. an effect\n// created while another effect runs — the component of the active effect.\nfunction __owner() {\n const cid = __currentId()\n if (cid !== null) return cid\n const fromContext = __parentFromContext()\n return fromContext === undefined ? null : fromContext\n}\n\n// --- Component Lifecycle ---\n//\n// Observer must not break the observed: every devtools side-effect below is\n// wrapped in try/catch so a bug or an out-of-shape runtime cannot tear down\n// the user's app. The original Svelte function is always called, and its\n// return value always returned, regardless of devtools failures.\n\nexport function push() {\n // Parent hint, read before this component's own id exists:\n // 1. the wrapper stack: the component whose init is running (children\n // rendered directly by a template, where active_effect still belongs to\n // an outer block), or the block owner re-pushed by __wrapBlockFn for a\n // later {#each}/{#if}/{#key} update (see Block Attribution below);\n // 2. else the context-derived owner, for re-creation paths the wrapper\n // does not wrap (snippet, svelte:element, ...).\n let parentHint = null\n try {\n parentHint = __currentId()\n } catch {}\n if (parentHint === null) {\n try {\n parentHint = __parentFromContext()\n } catch {}\n }\n const result = __svelte_original.push.apply(null, arguments)\n try {\n const dt = __dt()\n if (dt) {\n const file = dt._pendingFile ?? 'Unknown'\n dt._pendingFile = null\n dt._pendingParent = parentHint\n const id = dt.register(file)\n __idStack.push(id)\n dt.startInit(id)\n try {\n __svelte_original.user_effect(() => {\n try {\n const own = __svelte_original.active_effect\n if (own?.ctx) dt._idByContext.set(own.ctx, id)\n if (own) dt.setComponentEffect(id, own)\n } catch {}\n return () => {\n try {\n dt.unmount(id)\n } catch {}\n }\n })\n } catch {}\n }\n } catch {}\n return result\n}\n\nexport function pop() {\n // Capture devtools errors but ALWAYS forward to the original pop so the\n // Svelte component stack stays balanced.\n try {\n const dt = __dt()\n if (dt && __idStack.length > 0) {\n const id = __idStack.pop()\n try {\n dt.endInit(id)\n } catch {}\n try {\n dt.registered(id)\n } catch {}\n }\n } catch {}\n return __svelte_original.pop.apply(null, arguments)\n}\n\n// --- Signal Creation (type markers) ---\n\nexport function state() {\n const signal = __svelte_original.state.apply(null, arguments)\n try {\n __pendingSignal.ref = signal\n __pendingSignal.type = 'state'\n } catch {}\n return signal\n}\n\nexport function derived() {\n const signal = __svelte_original.derived.apply(null, arguments)\n try {\n __pendingSignal.ref = signal\n __pendingSignal.type = 'derived'\n } catch {}\n return signal\n}\n\nexport function proxy() {\n const p = __svelte_original.proxy.apply(null, arguments)\n try {\n __pendingSignal.ref = p\n __pendingSignal.type = 'proxy'\n } catch {}\n return p\n}\n\n// --- Signal Tagging (Svelte dev mode) ---\n\nexport function tag(signal, name) {\n const result = __svelte_original.tag.apply(null, arguments)\n try {\n const dt = __dt()\n const cid = __owner()\n const type = __pendingSignal.ref === signal ? __pendingSignal.type : 'state'\n if (dt && cid !== null) {\n const owner = __svelte_original.active_effect\n if (type === 'derived') {\n dt.trackDerived(signal, name, cid, owner)\n } else {\n dt.trackState(signal, name, cid, owner)\n }\n } else if (dt?._moduleFile) {\n // created while a .svelte.js/.ts module body runs (shared state)\n dt.trackModuleSignal(type === 'derived' ? 'derived' : 'state', signal, name)\n }\n __pendingSignal.ref = null\n __pendingSignal.type = null\n } catch {}\n return result\n}\n\nexport function tag_proxy(value, name) {\n const result = __svelte_original.tag_proxy.apply(null, arguments)\n try {\n const dt = __dt()\n const cid = __owner()\n if (dt && cid !== null) {\n dt.trackProxy(value, name, cid, __svelte_original.active_effect)\n } else if (dt?._moduleFile) {\n dt.trackModuleSignal('proxy', value, name)\n }\n __pendingSignal.ref = null\n __pendingSignal.type = null\n } catch {}\n return result\n}\n\n// --- Effect Tracking ---\n//\n// A top-level $effect in a component is deferred by Svelte until mount:\n// user_effect() returns undefined and the effect object is created later,\n// in pop(). So the node is registered now (named per component) and bound\n// to the real effect object on its first run, where active_effect IS the\n// effect; the Svelte runtime then keeps effect.deps current, which is what\n// getReactiveGraph() reads to build edges. The wrapped callback forwards\n// this, arguments and the return value (teardown) unchanged.\n\nfunction __trackUserEffect(original, kind, args) {\n let cid = null\n let dt = null\n let fn = null\n try {\n dt = __dt()\n fn = args[0]\n if (dt && typeof fn === 'function') cid = __owner()\n } catch {}\n if (cid === null) return original.apply(null, args)\n let nodeId = null\n let bound = false\n const wrapped = Array.prototype.slice.call(args)\n wrapped[0] = function () {\n if (!bound) {\n bound = true\n try {\n dt.bindEffect(nodeId, __svelte_original.active_effect)\n } catch {}\n }\n return fn.apply(this, arguments)\n }\n try {\n nodeId = dt.trackUserEffect(kind, cid, __svelte_original.active_effect)\n } catch {}\n const result = original.apply(null, wrapped)\n if (result && !bound) {\n bound = true\n try {\n dt.bindEffect(nodeId, result)\n } catch {}\n }\n return result\n}\n\nexport function user_effect() {\n return __trackUserEffect(__svelte_original.user_effect, 'effect', arguments)\n}\n\nexport function user_pre_effect() {\n return __trackUserEffect(__svelte_original.user_pre_effect, 'effect_pre', arguments)\n}\n\n// --- Render Profiling ---\n//\n// Svelte 5 has no virtual DOM: the compiler wraps every dynamic part of a\n// template in a template_effect (deferred_template_effect for <svelte:head>\n// <title>). A re-run of such an effect IS the component updating the DOM, so\n// these two functions are the measurement points for renders / render time.\n//\n// The first run of an effect is the mount-time paint, already covered by\n// initTime, so it is skipped (initialRun). One state change re-runs several\n// effects of the same component, so durations are pooled per microtask and\n// recorded once per flush: recordRender() +1, recordRenderTime() the sum.\n\nconst __pendingRenderDurations = new Map()\nlet __renderFlushScheduled = false\n\nfunction __flushRenderDurations() {\n __renderFlushScheduled = false\n const dt = __dt()\n for (const [cid, duration] of __pendingRenderDurations) {\n if (dt) {\n try {\n dt.recordRender(cid)\n } catch {}\n try {\n dt.recordRenderTime(cid, duration)\n } catch {}\n }\n }\n __pendingRenderDurations.clear()\n}\n\nfunction __recordRenderDuration(cid, duration) {\n __pendingRenderDurations.set(cid, (__pendingRenderDurations.get(cid) ?? 0) + duration)\n if (!__renderFlushScheduled) {\n __renderFlushScheduled = true\n queueMicrotask(__flushRenderDurations)\n }\n}\n\n// Returns a (possibly new) args array whose first element times each re-run\n// of the effect closure. The owning component is whatever id is on top of\n// __idStack at effect-creation time. User exceptions propagate untouched;\n// only the args are built inside try so the original is called exactly once.\nfunction __wrapTemplateEffect(args) {\n const cid = __owner()\n const fn = args[0]\n if (cid === null || typeof fn !== 'function') return args\n const wrapped = Array.prototype.slice.call(args)\n let initialRun = true\n wrapped[0] = function () {\n if (initialRun) {\n initialRun = false\n return fn.apply(this, arguments)\n }\n const start = performance.now()\n try {\n return fn.apply(this, arguments)\n } finally {\n try {\n __recordRenderDuration(cid, performance.now() - start)\n } catch {}\n }\n }\n return wrapped\n}\n\nexport function template_effect() {\n let args = arguments\n try {\n args = __wrapTemplateEffect(arguments)\n } catch {}\n return __svelte_original.template_effect.apply(null, args)\n}\n\nexport function deferred_template_effect() {\n let args = arguments\n try {\n args = __wrapTemplateEffect(arguments)\n } catch {}\n return __svelte_original.deferred_template_effect.apply(null, args)\n}\n\n// --- Block Attribution ---\n//\n// Svelte creates render effects synchronously at creation time. At mount this\n// happens during the component function (between push/pop), so __idStack has\n// the owner. But effects for {#each} items added later or re-created {#if}\n// branches are created during a batch flush, when the stack is empty — they\n// would never be attributed. Block helpers themselves ARE always called\n// during their owner's init (or inside an outer block's callback), so the\n// owner id is on the stack at block-creation time. __wrapBlock captures it\n// and re-pushes it around every function argument the block invokes later,\n// so effects created inside land on the innermost owner. Child components\n// push their own id on top, keeping nested attribution correct.\n\n// A component whose init throws (caught by <svelte:boundary>, or by the\n// block's caller) never reaches pop(): its id would stay on both stacks and\n// every later signal/child would be attributed to it. On the way out — normal\n// or thrown — the stack is cut back to its depth on entry, and ids left\n// above it are dropped as aborted inits (registered, never mounted).\nfunction __wrapBlockFn(fn, cid) {\n return function () {\n let depth = -1\n try {\n depth = __idStack.length\n __idStack.push(cid)\n } catch {}\n try {\n return fn.apply(this, arguments)\n } finally {\n if (depth !== -1) {\n try {\n if (__idStack.length > depth + 1) {\n const dt = __dt()\n const aborted = __idStack.slice(depth + 1)\n for (let i = aborted.length - 1; i >= 0; i--) {\n try {\n if (dt) dt.abortInit(aborted[i])\n } catch {}\n }\n }\n __idStack.length = depth\n } catch {}\n }\n }\n }\n}\n\nfunction __wrapBlock(args) {\n const cid = __owner()\n if (cid === null) return args\n const wrapped = Array.prototype.slice.call(args)\n for (let i = 0; i < wrapped.length; i++) {\n if (typeof wrapped[i] === 'function') wrapped[i] = __wrapBlockFn(wrapped[i], cid)\n }\n return wrapped\n}\n\nexport function each() {\n let args = arguments\n try {\n args = __wrapBlock(arguments)\n } catch {}\n return __svelte_original.each.apply(null, args)\n}\n\nexport function key() {\n let args = arguments\n try {\n args = __wrapBlock(arguments)\n } catch {}\n return __svelte_original.key.apply(null, args)\n}\n\nexport function component() {\n let args = arguments\n try {\n args = __wrapBlock(arguments)\n } catch {}\n return __svelte_original.component.apply(null, args)\n}\n\nexport function boundary() {\n let args = arguments\n try {\n args = __wrapBlock(arguments)\n } catch {}\n return __svelte_original.boundary.apply(null, args)\n}\n\n// 'if' and 'await' are reserved words, so they cannot be declared as\n// function names and are exported via aliases instead.\nfunction __if_block() {\n let args = arguments\n try {\n args = __wrapBlock(arguments)\n } catch {}\n return __svelte_original.if.apply(null, args)\n}\n\nfunction __await_block() {\n let args = arguments\n try {\n args = __wrapBlock(arguments)\n } catch {}\n return __svelte_original.await.apply(null, args)\n}\n\nexport { __if_block as if, __await_block as await }\n", M = "virtual:svelte-devtools-runtime", He = "\0virtual:svelte-devtools-runtime", Ue = "\0svelte-devtools:wrapped-client", We = Ve, Ge = Be;
860
+ //#endregion
861
+ //#region src/runtime/transform.ts
862
+ function Ke(e, t) {
863
+ let n = /^[ \t]*\$\.push\(\$\$props\b/m.exec(e);
864
+ if (!n) return null;
865
+ let r = n.index + n[0].indexOf("$.push("), i = `if (typeof window !== 'undefined' && window.__SVELTE_DEVTOOLS__) { window.__SVELTE_DEVTOOLS__._pendingFile = ${JSON.stringify(t)}; } `;
866
+ return `import '${M}';` + e.slice(0, r) + i + e.slice(r);
207
867
  }
208
- function he(e) {
209
- return i.basename(e, ".svelte");
868
+ var qe = /\.svelte\.[cm]?[jt]s$/;
869
+ function Je(e, t) {
870
+ if (e.includes("svelte/internal/server")) return null;
871
+ let n = JSON.stringify(t), r = "(typeof window !== 'undefined' && window.__SVELTE_DEVTOOLS__)";
872
+ return `import '${M}';if (${r}) { window.__SVELTE_DEVTOOLS__._enterModule(${n}); }` + e + `\n;if (${r}) { window.__SVELTE_DEVTOOLS__._leaveModule(); }\n`;
210
873
  }
211
874
  //#endregion
212
- //#region src/runtime.ts
213
- var S = "virtual:svelte-devtools-runtime", ge = "\0virtual:svelte-devtools-runtime", _e = "\0svelte-devtools:wrapped-client", ve = "\nimport * as __svelte_original from 'svelte/internal/client';\nexport * from 'svelte/internal/client';\n\nfunction __dt() {\n return typeof window !== 'undefined' ? window.__SVELTE_DEVTOOLS__ : null;\n}\n\n// Component ID stack (parallel to runtime._stack but local to wrapper)\nconst __idStack = [];\nfunction __currentId() {\n return __idStack.length > 0 ? __idStack[__idStack.length - 1] : null;\n}\n\n// Tracks the most recently created signal for type determination in tag()\nconst __pendingSignal = { ref: null, type: null };\n\n// Component context -> devtools id (review B1b). A component created later\n// by a block update ({#each}/{#if} after mount) runs outside its parent's\n// push..pop, where the runtime's init stack is empty (the wrapper stack\n// below covers the wrapped block helpers; this covers the rest). Svelte (5.56.8,\n// internal/client) exports active_effect; every effect records the\n// component context it was created in (effect.ctx) and runs with that\n// context restored. The block effect that creates the child belongs to the\n// parent's template, so active_effect.ctx at push time IS the parent's\n// context. Each context is mapped to its id once the component mounted\n// (inside its own deferred effect, where active_effect.ctx is the\n// component's own context). Weak map: no leak, no Svelte state touched.\nconst __idByContext = new WeakMap();\nfunction __parentFromContext() {\n const effect = __svelte_original.active_effect;\n const ctx = effect ? effect.ctx : null;\n return ctx ? __idByContext.get(ctx) : undefined;\n}\n\n// --- Component Lifecycle ---\n//\n// Observer must not break the observed: every devtools side-effect below is\n// wrapped in try/catch so a bug or an out-of-shape runtime cannot tear down\n// the user's app. The original Svelte function is always called, and its\n// return value always returned, regardless of devtools failures.\n\nexport function push() {\n // Parent hint, read before this component's own id exists:\n // 1. the wrapper stack: the component whose init is running (children\n // rendered directly by a template, where active_effect still belongs to\n // an outer block), or the block owner re-pushed by __wrapBlockFn for a\n // later {#each}/{#if}/{#key} update (see Block Attribution below);\n // 2. else the context-derived owner, for re-creation paths the wrapper\n // does not wrap (snippet, svelte:element, ...).\n let parentHint = null;\n try { parentHint = __currentId(); } catch {}\n if (parentHint === null) {\n try { parentHint = __parentFromContext(); } catch {}\n }\n const result = __svelte_original.push.apply(null, arguments);\n try {\n const dt = __dt();\n if (dt) {\n const file = dt._pendingFile || 'Unknown';\n dt._pendingFile = null;\n dt._pendingParent = parentHint;\n const id = dt.register(file);\n __idStack.push(id);\n dt.startInit(id);\n try {\n __svelte_original.user_effect(() => {\n try {\n const own = __svelte_original.active_effect;\n if (own && own.ctx) __idByContext.set(own.ctx, id);\n } catch {}\n return () => { try { dt.unmount(id); } catch {} };\n });\n } catch {}\n }\n } catch {}\n return result;\n}\n\nexport function pop() {\n // Capture devtools errors but ALWAYS forward to the original pop so the\n // Svelte component stack stays balanced.\n try {\n const dt = __dt();\n if (dt && __idStack.length > 0) {\n const id = __idStack.pop();\n try { dt.endInit(id); } catch {}\n try { dt.registered(id); } catch {}\n }\n } catch {}\n return __svelte_original.pop.apply(null, arguments);\n}\n\n// --- Signal Creation (type markers) ---\n\nexport function state() {\n const signal = __svelte_original.state.apply(null, arguments);\n try {\n __pendingSignal.ref = signal;\n __pendingSignal.type = 'state';\n } catch {}\n return signal;\n}\n\nexport function derived() {\n const signal = __svelte_original.derived.apply(null, arguments);\n try {\n __pendingSignal.ref = signal;\n __pendingSignal.type = 'derived';\n } catch {}\n return signal;\n}\n\nexport function proxy() {\n const p = __svelte_original.proxy.apply(null, arguments);\n try {\n __pendingSignal.ref = p;\n __pendingSignal.type = 'proxy';\n } catch {}\n return p;\n}\n\n// --- Signal Tagging (Svelte dev mode) ---\n\nexport function tag(signal, name) {\n const result = __svelte_original.tag.apply(null, arguments);\n try {\n const dt = __dt();\n const cid = __currentId();\n if (dt && cid !== null) {\n const type = (__pendingSignal.ref === signal) ? __pendingSignal.type : 'state';\n if (type === 'derived') {\n dt.trackDerived(signal, name, cid);\n } else {\n dt.trackState(signal, name, cid);\n }\n }\n __pendingSignal.ref = null;\n __pendingSignal.type = null;\n } catch {}\n return result;\n}\n\nexport function tag_proxy(proxy, name) {\n const result = __svelte_original.tag_proxy.apply(null, arguments);\n try {\n const dt = __dt();\n const cid = __currentId();\n if (dt && cid !== null) {\n dt.trackProxy(proxy, name, cid);\n }\n __pendingSignal.ref = null;\n __pendingSignal.type = null;\n } catch {}\n return result;\n}\n\n// --- Effect Tracking ---\n\nexport function user_effect() {\n const result = __svelte_original.user_effect.apply(null, arguments);\n try {\n const dt = __dt();\n const cid = __currentId();\n if (dt && cid !== null) {\n dt._effectCounter = (dt._effectCounter || 0) + 1;\n // Track the effect OBJECT (not the callback). The Svelte runtime\n // populates result.deps with the signals this effect depends on,\n // which is what getReactiveGraph() reads to build edges.\n dt.trackEffect(result, 'effect_' + dt._effectCounter, cid);\n }\n } catch {}\n return result;\n}\n\nexport function user_pre_effect() {\n const result = __svelte_original.user_pre_effect.apply(null, arguments);\n try {\n const dt = __dt();\n const cid = __currentId();\n if (dt && cid !== null) {\n dt._effectCounter = (dt._effectCounter || 0) + 1;\n dt.trackEffect(result, 'effect_pre_' + dt._effectCounter, cid);\n }\n } catch {}\n return result;\n}\n\n// --- Render Profiling ---\n//\n// Svelte 5 has no virtual DOM: the compiler wraps every dynamic part of a\n// template in a template_effect (deferred_template_effect for <svelte:head>\n// <title>). A re-run of such an effect IS the component updating the DOM, so\n// these two functions are the measurement points for renders / render time.\n//\n// The first run of an effect is the mount-time paint, already covered by\n// initTime, so it is skipped (initialRun). One state change re-runs several\n// effects of the same component, so durations are pooled per microtask and\n// recorded once per flush: recordRender() +1, recordRenderTime() the sum.\n\nconst __pendingRenderDurations = new Map();\nlet __renderFlushScheduled = false;\n\nfunction __flushRenderDurations() {\n __renderFlushScheduled = false;\n const dt = __dt();\n for (const [cid, duration] of __pendingRenderDurations) {\n if (dt) {\n try { dt.recordRender(cid); } catch {}\n try { dt.recordRenderTime(cid, duration); } catch {}\n }\n }\n __pendingRenderDurations.clear();\n}\n\nfunction __recordRenderDuration(cid, duration) {\n __pendingRenderDurations.set(cid, (__pendingRenderDurations.get(cid) || 0) + duration);\n if (!__renderFlushScheduled) {\n __renderFlushScheduled = true;\n queueMicrotask(__flushRenderDurations);\n }\n}\n\n// Returns a (possibly new) args array whose first element times each re-run\n// of the effect closure. The owning component is whatever id is on top of\n// __idStack at effect-creation time. User exceptions propagate untouched;\n// only the args are built inside try so the original is called exactly once.\nfunction __wrapTemplateEffect(args) {\n const cid = __currentId();\n const fn = args[0];\n if (cid === null || typeof fn !== 'function') return args;\n const wrapped = Array.prototype.slice.call(args);\n let initialRun = true;\n wrapped[0] = function () {\n if (initialRun) {\n initialRun = false;\n return fn.apply(this, arguments);\n }\n const start = performance.now();\n try {\n return fn.apply(this, arguments);\n } finally {\n try { __recordRenderDuration(cid, performance.now() - start); } catch {}\n }\n };\n return wrapped;\n}\n\nexport function template_effect() {\n let args = arguments;\n try { args = __wrapTemplateEffect(arguments); } catch {}\n return __svelte_original.template_effect.apply(null, args);\n}\n\nexport function deferred_template_effect() {\n let args = arguments;\n try { args = __wrapTemplateEffect(arguments); } catch {}\n return __svelte_original.deferred_template_effect.apply(null, args);\n}\n\n// --- Block Attribution ---\n//\n// Svelte creates render effects synchronously at creation time. At mount this\n// happens during the component function (between push/pop), so __idStack has\n// the owner. But effects for {#each} items added later or re-created {#if}\n// branches are created during a batch flush, when the stack is empty — they\n// would never be attributed. Block helpers themselves ARE always called\n// during their owner's init (or inside an outer block's callback), so the\n// owner id is on the stack at block-creation time. __wrapBlock captures it\n// and re-pushes it around every function argument the block invokes later,\n// so effects created inside land on the innermost owner. Child components\n// push their own id on top, keeping nested attribution correct.\n\nfunction __wrapBlockFn(fn, cid) {\n return function () {\n let pushed = false;\n try { __idStack.push(cid); pushed = true; } catch {}\n try {\n return fn.apply(this, arguments);\n } finally {\n if (pushed) { try { __idStack.pop(); } catch {} }\n }\n };\n}\n\nfunction __wrapBlock(args) {\n const cid = __currentId();\n if (cid === null) return args;\n const wrapped = Array.prototype.slice.call(args);\n for (let i = 0; i < wrapped.length; i++) {\n if (typeof wrapped[i] === 'function') wrapped[i] = __wrapBlockFn(wrapped[i], cid);\n }\n return wrapped;\n}\n\nexport function each() {\n let args = arguments;\n try { args = __wrapBlock(arguments); } catch {}\n return __svelte_original.each.apply(null, args);\n}\n\nexport function key() {\n let args = arguments;\n try { args = __wrapBlock(arguments); } catch {}\n return __svelte_original.key.apply(null, args);\n}\n\nexport function component() {\n let args = arguments;\n try { args = __wrapBlock(arguments); } catch {}\n return __svelte_original.component.apply(null, args);\n}\n\nexport function boundary() {\n let args = arguments;\n try { args = __wrapBlock(arguments); } catch {}\n return __svelte_original.boundary.apply(null, args);\n}\n\n// 'if' and 'await' are reserved words, so they cannot be declared as\n// function names and are exported via aliases instead.\nfunction __if_block() {\n let args = arguments;\n try { args = __wrapBlock(arguments); } catch {}\n return __svelte_original['if'].apply(null, args);\n}\n\nfunction __await_block() {\n let args = arguments;\n try { args = __wrapBlock(arguments); } catch {}\n return __svelte_original['await'].apply(null, args);\n}\n\nexport { __if_block as if, __await_block as await };\n", ye = "\nif (typeof window !== 'undefined' && !window.__SVELTE_DEVTOOLS__) {\n const __NO_VALUE = Symbol('no value');\n // State timeline ring (§6.7 C): every read sees at most 500 entries and\n // __TIMELINE_BYTES (also the server's buffer budget). The raw array may\n // hold up to __TIMELINE_TRIM_AT (2 x the 500 cap) between bulk trims.\n const __TIMELINE_BYTES = 4 * 1024 * 1024;\n const __TIMELINE_TRIM_AT = 1000;\n // FNV-1a over UTF-16 code units: cheap change detection for large snapshots.\n const __hash = (str) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < str.length; i++) {\n h ^= str.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0).toString(36);\n };\n const __SVELTE_DT = {\n _nextId: 0,\n _instances: new Map(),\n _stack: [],\n _pendingParent: undefined,\n _pendingFile: null,\n _effectCounter: 0,\n _debounceTimer: null,\n _listeners: new Set(),\n\n // Phase 2: Profiling data\n _profiles: new Map(),\n _initStartTimes: new Map(),\n _profileDebounceTimer: null,\n\n // Phase 2: Reactive graph data\n _reactiveNodes: new Map(),\n _reactiveProxies: new Map(),\n\n // componentId -> Set<nodeId>. Lets unmount purge a component's reactive\n // nodes without scanning every node of the app (was O(components x nodes)).\n _nodesByComponent: new Map(),\n\n // Phase 3: State timeline\n _stateTimeline: [],\n _stateSnapshots: new Map(),\n _timelineDebounceTimer: null,\n // signal (or proxy marker) -> nodeId, set at track time and removed by\n // _forgetNode: a scoped graph resolves dependencies without scanning\n // every node (§6.7 D).\n _idBySignal: new WeakMap(),\n // Polling bookkeeping (§6.7 D): $state node ids in a dense array kept up\n // to date incrementally (_pollIndex: nodeId -> position; removal is\n // swap-with-last), a cursor carried across ticks, nodes found changed but\n // not yet serialized (_pollDirty), and per-node change hints\n // (nodeId -> { ref, wv, nextCheckAt }).\n _pollIds: [],\n _pollIndex: new Map(),\n _pollCursor: 0,\n _pollDirty: new Set(),\n // Full-sweep bookkeeping: how long the last complete pass over all $state\n // nodes took (ms), for disclosure (= the worst-case detection delay).\n _pollSweep: { startedAt: 0, lastMs: null, nodes: 0 },\n _pollMeta: new Map(),\n _deepCredit: 0,\n _lastSnapshotSize: new Map(),\n _timelineSeq: 0,\n _pushedSeq: 0,\n _timelineReset: false,\n _entryInfo: new WeakMap(),\n // Sum of _entryInfo.bytes over _stateTimeline (runtime byte budget).\n _timelineBytes: 0,\n // Disclosure since the last push (§6.7 C): unsent entries the ring removed\n // (by count / by bytes) and changes recorded only as a size summary.\n _timelineDropped: { 'runtime-count': 0, 'runtime-bytes': 0 },\n _valueTooLarge: 0,\n\n // Overview aggregate (§6.7 I/J), O(1) per event: registered nodes per\n // component and type (+ app totals), and per-component activity in a\n // ring of 60 one-second buckets (sampled changes, renders, render ms,\n // plus how long sampling ran in that second).\n _nodeCounts: new Map(),\n _nodeTotals: { state: 0, derived: 0, effect: 0 },\n _activity: [],\n _epoch: Math.random().toString(36).slice(2) + Date.now().toString(36),\n\n // --- Activity subscription (docs/devframe-migration.md §6.3) ---\n // Inactive until the server says a DevTools client (UI tab or MCP lease)\n // is watching: no state polling, FPS rAF loop, or periodic HMR sends.\n _active: false,\n _componentsCost: { ms: 0, bytes: 0 },\n _componentDeltas: false,\n _pendingAdded: new Set(),\n _pendingRemoved: new Set(),\n _lastFullAt: 0,\n _resync: false,\n _profilesCost: { ms: 0, bytes: 0 },\n // = collector LIMITS.renderProfiles (pinned by a unit test): the server\n // keeps only the newest entries, so sending more is wasted bytes.\n _profileCap: 5000,\n _sampling: null,\n _baselining: false,\n // Polled state nodes not observed yet (no seed value). Their first\n // observation is a seed, not a change: no timeline entry, no activity\n // count, no drops — the old value is unknown, not null (review B-1/B-2).\n _unseeded: new Set(),\n // pendingNodes last sent on a state-timeline message (null = none yet)\n _sentPendingNodes: null,\n _fpsGen: 0,\n\n register(file) {\n const id = this._nextId++;\n // Parent: the wrapper's context-derived hint (components created by a\n // later block update, review B1b) when it names a live instance, else\n // the synchronous init stack (children created during the parent's own\n // init, before the parent is mapped).\n const hint = this._pendingParent;\n this._pendingParent = undefined;\n const parentId =\n hint !== undefined && hint !== null && this._instances.has(hint)\n ? hint\n : this._stack.length > 0 ? this._stack[this._stack.length - 1] : null;\n const name = file.split('/').pop()?.replace('.svelte', '') || 'Unknown';\n // children is a Set so unmounting one row of a 5 000-row list is O(1).\n this._instances.set(id, { id, file, name, parentId, mounted: true, children: new Set() });\n if (parentId !== null) {\n const parent = this._instances.get(parentId);\n if (parent) parent.children.add(id);\n }\n this._stack.push(id);\n if (this._active) this._pendingAdded.add(id);\n this._scheduleUpdate();\n return id;\n },\n\n registered(id) {\n const idx = this._stack.indexOf(id);\n if (idx !== -1) this._stack.splice(idx, 1);\n },\n\n mount(id) {\n const instance = this._instances.get(id);\n if (instance && !instance.mounted) {\n instance.mounted = true;\n if (this._active) this._pendingAdded.add(id);\n this._scheduleUpdate();\n }\n },\n\n unmount(id) {\n const instance = this._instances.get(id);\n if (instance) {\n if (instance.parentId !== null) {\n const parent = this._instances.get(instance.parentId);\n if (parent) parent.children.delete(id);\n }\n this._removeChildren(id);\n this._cleanupComponent(id);\n }\n this._scheduleUpdate();\n this._scheduleProfileUpdate();\n },\n\n // Remounts get a fresh id, so entries keyed by a dead id would otherwise\n // survive forever — every per-component map must be purged here.\n _cleanupComponent(id) {\n // Delta bookkeeping: an id added and removed between two pushes was\n // never sent, so it cancels out.\n if (this._active && !this._pendingAdded.delete(id)) this._pendingRemoved.add(id);\n this._cleanupReactiveNodes(id);\n this._instances.delete(id);\n this._profiles.delete(id);\n this._initStartTimes.delete(id);\n },\n\n _cleanupReactiveNodes(componentId) {\n const nodeIds = this._nodesByComponent.get(componentId);\n if (!nodeIds) return;\n this._nodesByComponent.delete(componentId);\n for (const nodeId of nodeIds) this._forgetNode(nodeId);\n },\n\n _forgetNode(nodeId) {\n const entry = this._reactiveNodes.get(nodeId);\n if (entry) this._countNode(entry.meta.componentId, entry.meta.type, -1);\n const signal = entry && entry.signal.deref();\n if (signal && this._idBySignal.get(signal) === nodeId) this._idBySignal.delete(signal);\n this._pollRemove(nodeId);\n this._pollDirty.delete(nodeId);\n this._reactiveNodes.delete(nodeId);\n this._reactiveProxies.delete(nodeId);\n this._stateSnapshots.delete(nodeId);\n if (this._stateSnapshotStrs) this._stateSnapshotStrs.delete(nodeId);\n this._pollMeta.delete(nodeId);\n this._lastSnapshotSize.delete(nodeId);\n },\n\n _indexNode(nodeId, componentId) {\n let set = this._nodesByComponent.get(componentId);\n if (!set) {\n set = new Set();\n this._nodesByComponent.set(componentId, set);\n }\n set.add(nodeId);\n },\n\n _pollAdd(nodeId) {\n if (this._pollIndex.has(nodeId)) return;\n if (!this._stateSnapshots.has(nodeId)) this._unseeded.add(nodeId);\n this._pollIndex.set(nodeId, this._pollIds.length);\n this._pollIds.push(nodeId);\n },\n\n // O(1): the last id takes the removed slot. If that slot is behind the\n // cursor, the moved id is visited in the next sweep instead of this one\n // (still visited within a bounded number of ticks).\n // Before a track* call replaces/creates nodeId: move the count from the\n // previous registration (same name re-tracked) to the new one.\n _trackNodeCount(nodeId, componentId, type) {\n const prev = this._reactiveNodes.get(nodeId);\n if (prev) this._countNode(prev.meta.componentId, prev.meta.type, -1);\n this._countNode(componentId, type, 1);\n },\n\n _countNode(componentId, type, d) {\n const kind = type === 'derived' || type === 'effect' ? type : 'state';\n let c = this._nodeCounts.get(componentId);\n if (!c) {\n if (d < 0) return;\n c = { state: 0, derived: 0, effect: 0 };\n this._nodeCounts.set(componentId, c);\n }\n c[kind] += d;\n this._nodeTotals[kind] += d;\n if (c.state + c.derived + c.effect <= 0) this._nodeCounts.delete(componentId);\n },\n\n _bucket() {\n const sec = Math.floor(performance.now() / 1000);\n const slot = ((sec % 60) + 60) % 60;\n let b = this._activity[slot];\n if (!b || b.second !== sec) {\n b = { second: sec, sampledMs: 0, rows: new Map() };\n this._activity[slot] = b;\n }\n return b;\n },\n\n _activityRow(componentId) {\n const rows = this._bucket().rows;\n let r = rows.get(componentId);\n if (!r) {\n r = { changes: 0, renders: 0, renderMs: 0 };\n rows.set(componentId, r);\n }\n return r;\n },\n\n _pollRemove(nodeId) {\n const i = this._pollIndex.get(nodeId);\n if (i === undefined) return;\n this._unseeded.delete(nodeId);\n const ids = this._pollIds;\n const last = ids.pop();\n this._pollIndex.delete(nodeId);\n if (i < ids.length) {\n ids[i] = last;\n this._pollIndex.set(last, i);\n }\n },\n\n _removeChildren(parentId) {\n const parent = this._instances.get(parentId);\n if (!parent) return;\n for (const childId of [...parent.children]) {\n this._removeChildren(childId);\n this._cleanupComponent(childId);\n }\n },\n\n // Full-list pushes are throttled, not debounced: a pending timer is not\n // reset, so continuous churn still produces updates (a debounce would\n // starve), and the interval adapts to the last push's cost so a 10 000+\n // instance app can't spend its main thread serializing (review P3):\n // max(min, 20 x last send ms, 1 s when the last payload exceeded ~1 MB).\n _sendInterval(cost, min) {\n return Math.max(min, 20 * cost.ms, cost.bytes > 1000000 ? 1000 : 0);\n },\n\n _scheduleUpdate() {\n if (!this._active || this._debounceTimer) return;\n this._debounceTimer = setTimeout(() => {\n this._debounceTimer = null;\n this._sendUpdate();\n }, this._sendInterval(this._componentsCost, 100));\n },\n\n // components push (§6.5). Full form { epoch, components } replaces the\n // server's tree for this epoch: sent on activation, when the server does\n // not advertise componentDeltas, as a periodic checkpoint, or when the\n // delta would be larger than the tree. Otherwise the delta form\n // { epoch, added, removed } (removed ids first, ≤ 2 000 entries per\n // message, added in registration order = parents first).\n _sendUpdate(forceFull) {\n // Nobody watching: keep the registry, skip the O(N) payload. A full\n // snapshot is sent on activation (§6.3).\n if (!this._active) return;\n const t0 = performance.now();\n const CHUNK = 2000;\n const CHECKPOINT_MS = 30000;\n const pending = this._pendingAdded.size + this._pendingRemoved.size;\n const full =\n forceFull ||\n !this._componentDeltas ||\n t0 - this._lastFullAt >= CHECKPOINT_MS ||\n pending > this._instances.size;\n const toEntry = (instance) => ({\n id: instance.id,\n file: instance.file,\n name: instance.name,\n parentId: instance.parentId,\n mounted: instance.mounted,\n });\n let bytes = 0;\n const msgs = [];\n if (full) {\n const components = [];\n for (const [, instance] of this._instances) {\n if (instance.mounted) {\n components.push(toEntry(instance));\n bytes += instance.file.length + instance.name.length + 72;\n }\n }\n msgs.push({ epoch: this._epoch, reset: true, components });\n this._lastFullAt = t0;\n } else if (pending > 0) {\n const removed = [...this._pendingRemoved];\n const added = [];\n for (const id of this._pendingAdded) {\n const instance = this._instances.get(id);\n if (instance && instance.mounted) {\n added.push(toEntry(instance));\n bytes += instance.file.length + instance.name.length + 72;\n }\n }\n bytes += removed.length * 8;\n for (let r = 0; r < removed.length; r += CHUNK) {\n msgs.push({ epoch: this._epoch, added: [], removed: removed.slice(r, r + CHUNK) });\n }\n for (let a = 0; a < added.length; a += CHUNK) {\n msgs.push({ epoch: this._epoch, added: added.slice(a, a + CHUNK), removed: [] });\n }\n }\n this._pendingAdded.clear();\n this._pendingRemoved.clear();\n if (import.meta.hot) {\n for (const msg of msgs) import.meta.hot.send('svelte-devtools:components', msg);\n }\n this._componentsCost = { ms: performance.now() - t0, bytes };\n },\n\n getTree() {\n const components = [];\n for (const [, instance] of this._instances) {\n if (instance.mounted) {\n components.push({\n id: instance.id,\n file: instance.file,\n name: instance.name,\n parentId: instance.parentId,\n mounted: instance.mounted,\n });\n }\n }\n return components;\n },\n\n // --- Phase 2: Render Profiling ---\n\n startInit(id) {\n this._initStartTimes.set(id, performance.now());\n },\n\n endInit(id) {\n const start = this._initStartTimes.get(id);\n if (start === undefined) return;\n const initTime = performance.now() - start;\n this._initStartTimes.delete(id);\n const instance = this._instances.get(id);\n if (!instance) return;\n this._profiles.set(id, {\n componentId: id,\n file: instance.file,\n name: instance.name,\n initTime,\n renderCount: 0,\n totalRenderTime: 0,\n lastRenderTime: 0,\n lastRenderAt: Date.now(),\n });\n this._scheduleProfileUpdate();\n },\n\n recordRender(id) {\n const profile = this._profiles.get(id);\n if (!profile) {\n const instance = this._instances.get(id);\n if (!instance) return;\n this._profiles.set(id, {\n componentId: id,\n file: instance.file,\n name: instance.name,\n initTime: 0,\n renderCount: 1,\n totalRenderTime: 0,\n lastRenderTime: 0,\n lastRenderAt: Date.now(),\n });\n } else {\n profile.renderCount++;\n profile.lastRenderAt = Date.now();\n }\n this._activityRow(id).renders++;\n this._scheduleProfileUpdate();\n },\n\n recordRenderTime(id, duration) {\n const profile = this._profiles.get(id);\n if (profile) {\n profile.totalRenderTime += duration;\n profile.lastRenderTime = duration;\n this._activityRow(id).renderMs += duration;\n }\n },\n\n // Profiles push (review P-1 Option A; contract in\n // docs/performance-status.md). Throttled like components, but the floor\n // grows with the payload: every push carries the whole retained map, so\n // a large app coalesces bursts instead of resending ~1 MB twice a second.\n // Hard cap 2 s (contract R6): a slow serialization must not stretch the\n // latency beyond it.\n _profileInterval() {\n const cost = this._profilesCost;\n return Math.min(\n 2000,\n Math.max(500, 20 * cost.ms, cost.bytes > 1000000 ? 2000 : cost.bytes > 250000 ? 1000 : 0),\n );\n },\n\n _scheduleProfileUpdate() {\n if (!this._active || this._profileDebounceTimer) return;\n this._profileDebounceTimer = setTimeout(() => {\n this._profileDebounceTimer = null;\n this._sendProfileUpdate();\n }, this._profileInterval());\n },\n\n // Also the forced path (activation / resync): a pending throttled push is\n // cancelled so the same state is not sent twice.\n _sendProfileUpdate() {\n if (this._profileDebounceTimer) {\n clearTimeout(this._profileDebounceTimer);\n this._profileDebounceTimer = null;\n }\n if (!this._active) return;\n const t0 = performance.now();\n const all = Array.from(this._profiles.values());\n // Exactly what the collector retains: its tail, in the same order.\n const profiles = all.length > this._profileCap ? all.slice(all.length - this._profileCap) : all;\n if (import.meta.hot) {\n // total = all retained profiles; the message carries the newest-mounted\n // tail (§6.7 J IA1 capture policy 'newest-mounted').\n import.meta.hot.send('svelte-devtools:profiles', { epoch: this._epoch, profiles, total: all.length });\n }\n // Payload size from a small sample (entries differ mainly by file path).\n const k = Math.min(8, profiles.length);\n let sampled = 0;\n for (let i = 0; i < k; i++) sampled += JSON.stringify(profiles[i]).length;\n const bytes = k > 0 ? Math.round((sampled / k) * profiles.length) : 0;\n this._profilesCost = { ms: performance.now() - t0, bytes };\n },\n\n getProfiles() {\n return Array.from(this._profiles.values());\n },\n\n resetProfiles() {\n this._profiles.clear();\n this._scheduleProfileUpdate();\n },\n\n // --- Phase 2: Reactive Graph Tracking ---\n\n trackState(signal, name, componentId) {\n const instance = this._instances.get(componentId);\n const nodeId = componentId + ':' + name;\n this._trackNodeCount(nodeId, componentId, 'state');\n this._reactiveNodes.set(nodeId, {\n signal: new WeakRef(signal),\n meta: { id: nodeId, type: 'state', name, componentId, componentFile: instance ? instance.file : '' }\n });\n this._idBySignal.set(signal, nodeId);\n this._indexNode(nodeId, componentId);\n this._pollAdd(nodeId);\n },\n\n trackProxy(proxy, name, componentId) {\n const instance = this._instances.get(componentId);\n const nodeId = componentId + ':' + name;\n this._reactiveProxies.set(nodeId, new WeakRef(proxy));\n // The proxy itself stays weakly held (_reactiveProxies). The marker is\n // held strongly so the node is not GC-dropped while the component lives;\n // _cleanupComponent removes it on unmount.\n const marker = { v: '(proxy)', _isProxy: true };\n this._trackNodeCount(nodeId, componentId, 'state');\n this._reactiveNodes.set(nodeId, {\n signal: { deref: () => marker },\n meta: { id: nodeId, type: 'state', name, componentId, componentFile: instance ? instance.file : '' }\n });\n this._idBySignal.set(marker, nodeId);\n this._indexNode(nodeId, componentId);\n this._pollAdd(nodeId);\n },\n\n trackDerived(signal, name, componentId) {\n const instance = this._instances.get(componentId);\n const nodeId = componentId + ':' + name;\n this._trackNodeCount(nodeId, componentId, 'derived');\n this._reactiveNodes.set(nodeId, {\n signal: new WeakRef(signal),\n meta: { id: nodeId, type: 'derived', name, componentId, componentFile: instance ? instance.file : '' }\n });\n this._idBySignal.set(signal, nodeId);\n this._indexNode(nodeId, componentId);\n },\n\n trackEffect(effect, name, componentId) {\n const instance = this._instances.get(componentId);\n const nodeId = componentId + ':' + name;\n const target = effect || { v: undefined, _isEffect: true };\n this._trackNodeCount(nodeId, componentId, 'effect');\n this._reactiveNodes.set(nodeId, {\n signal: new WeakRef(target),\n meta: { id: nodeId, type: 'effect', name, componentId, componentFile: instance ? instance.file : '' }\n });\n this._idBySignal.set(target, nodeId);\n this._indexNode(nodeId, componentId);\n return effect;\n },\n\n _graphNode(nodeId, entry, signal) {\n const node = { ...entry.meta };\n if (signal._isProxy) {\n const proxy = this._reactiveProxies.get(nodeId)?.deref();\n if (proxy) {\n try {\n node.value = Array.isArray(proxy) ? '[' + proxy.length + ']' : '{' + Object.keys(proxy).length + '}';\n } catch { node.value = '(proxy)'; }\n }\n } else if (node.type !== 'effect' && signal.v !== undefined && typeof signal.v !== 'symbol') {\n try {\n const v = signal.v;\n if (typeof v === 'number' || typeof v === 'string' || typeof v === 'boolean' || v === null) {\n node.value = v;\n } else {\n node.value = '(object)';\n }\n } catch { /* ignore */ }\n }\n return node;\n },\n\n // Reactive graph (§6.7 A/D). Caps are applied while building: past\n // maxNodes no node objects are created and only edges whose endpoints\n // are both included are emitted (the rest are counted in edgesOmitted).\n // - scoped (componentId): that component's nodes plus the tracked nodes\n // directly connected to them (via deps / reactions through untracked\n // intermediates). Dependencies are resolved through _idBySignal, so\n // the cost is O(scope + neighbours), not O(all nodes). The walk is\n // completed even past the cap, so total.nodes/edges are exact.\n // - global: nodes in registration order up to maxNodes ('global-head'),\n // with their incoming dependency edges. Nodes past the cap are not\n // dereferenced; total.nodes is the registered count (may include\n // nodes whose signal was already collected, nodesKind 'registered')\n // and total.edges is null when the walk stopped early (not guessed).\n getReactiveGraph(componentId, caps) {\n const scoped = componentId !== undefined && componentId !== null;\n const maxNodes = this._graphCap(caps && caps.maxNodes, 5000);\n const maxEdges = this._graphCap(caps && caps.maxEdges, 20000);\n const live = new Map();\n // Live signal of a tracked node, or null (forgets dead / unmounted nodes).\n const liveSignal = (nodeId) => {\n if (live.has(nodeId)) return live.get(nodeId);\n const entry = this._reactiveNodes.get(nodeId);\n let signal = entry ? entry.signal.deref() : null;\n if (entry && (!signal || !this._instances.has(entry.meta.componentId))) {\n this._forgetNode(nodeId);\n signal = null;\n }\n live.set(nodeId, signal || null);\n return signal || null;\n };\n const idOf = (dep) => {\n const id = this._idBySignal.get(dep);\n return id !== undefined && liveSignal(id) === dep ? id : null;\n };\n\n const included = new Set();\n const seen = new Set();\n const edges = [];\n const edgeSet = new Set();\n let edgesOmitted = 0;\n let truncated = false;\n const see = (id) => {\n seen.add(id);\n if (!included.has(id) && included.size < maxNodes) included.add(id);\n return included.has(id);\n };\n const addEdge = (from, to) => {\n const key = from + '>' + to;\n if (from === to || edgeSet.has(key)) return;\n edgeSet.add(key);\n const inFrom = see(from);\n const inTo = see(to);\n if (inFrom && inTo && edges.length < maxEdges) edges.push({ from, to });\n else edgesOmitted++;\n };\n // Walk a signal's neighbours (deps or reactions) through untracked\n // intermediates until tracked nodes are reached.\n const walk = (start, field, onHit) => {\n if (!start) return;\n const visited = new Set();\n const queue = [...start];\n // Index cursor instead of queue.shift(): shift is O(queue) per pop.\n for (let qi = 0; qi < queue.length; qi++) {\n const dep = queue[qi];\n if (!dep || visited.has(dep)) continue;\n visited.add(dep);\n const id = idOf(dep);\n if (id) onHit(id);\n else if (dep[field]) for (const d of dep[field]) queue.push(d);\n }\n };\n\n let totalNodes = 0;\n let totalEdges = null;\n if (scoped) {\n for (const nodeId of [...(this._nodesByComponent.get(componentId) || [])]) {\n const signal = liveSignal(nodeId);\n if (!signal) continue;\n see(nodeId);\n walk(signal.deps, 'deps', (depId) => addEdge(depId, nodeId));\n walk(signal.reactions, 'reactions', (rId) => addEdge(nodeId, rId));\n }\n totalNodes = seen.size;\n totalEdges = edgeSet.size;\n truncated = included.size < seen.size || edgesOmitted > 0;\n } else {\n let complete = true;\n for (const nodeId of [...this._reactiveNodes.keys()]) {\n if (included.size >= maxNodes && !included.has(nodeId)) {\n complete = false;\n break;\n }\n const signal = liveSignal(nodeId);\n if (!signal) continue;\n see(nodeId);\n walk(signal.deps, 'deps', (depId) => addEdge(depId, nodeId));\n }\n // registered count, minus nodes found dead while building\n totalNodes = this._reactiveNodes.size;\n totalEdges = complete ? edgeSet.size : null;\n truncated = !complete || edgesOmitted > 0;\n }\n\n const nodes = [];\n for (const nodeId of included) {\n const signal = liveSignal(nodeId);\n if (signal) nodes.push(this._graphNode(nodeId, this._reactiveNodes.get(nodeId), signal));\n }\n return {\n scope: scoped ? componentId : null,\n nodes,\n edges,\n total: { nodes: totalNodes, nodesKind: 'registered', edges: totalEdges },\n truncated,\n edgesOmitted,\n policy: scoped ? 'scoped' : 'global-head',\n };\n },\n\n _graphCap(value, max) {\n const n = Math.floor(Number(value));\n return Number.isFinite(n) && n >= 1 ? Math.min(n, max) : max;\n },\n\n // Request (§6.7 A + review M1): { requestId?, epoch?, componentId?,\n // maxNodes?, maxEdges? }. A request for another page load (epoch) is not\n // answered by this one; the reply echoes requestId and epoch. An old\n // server sends {} → global graph with the default caps (= its LIMITS).\n sendReactiveGraph(request) {\n const req = request || {};\n if (req.epoch !== undefined && req.epoch !== null && req.epoch !== this._epoch) return;\n const cid = typeof req.componentId === 'number' ? req.componentId : null;\n const graph = this.getReactiveGraph(cid, { maxNodes: req.maxNodes, maxEdges: req.maxEdges });\n graph.epoch = this._epoch;\n // freshness (review): when this answer was built; caches keep it\n graph.computedAt = Date.now();\n if (req.requestId !== undefined) graph.requestId = req.requestId;\n if (import.meta.hot) {\n import.meta.hot.send('svelte-devtools:reactive-graph', graph);\n }\n },\n\n // Overview aggregate (§6.7 I/J). Built from the activity buckets of the\n // window (whole seconds: the current partial second plus the previous\n // ones, ceil(windowMs / 1000) buckets) — cost O(components active in the\n // window), no graph, no node scan. Rows rank by sampled changes, then\n // renders, then render ms; rows + other = total (components and nodes).\n getReactiveSummary(opts) {\n const o = opts || {};\n const clampInt = (v, lo, hi, d) => {\n const n = Math.floor(Number(v));\n return Number.isFinite(n) ? Math.min(hi, Math.max(lo, n)) : d;\n };\n const topK = clampInt(o.topK, 1, 200, 50);\n const windowMs = clampInt(o.windowMs, 1000, 60000, 10000);\n const nowSec = Math.floor(performance.now() / 1000);\n const agg = new Map();\n let sampledMs = 0;\n for (let k = 0; k < Math.ceil(windowMs / 1000); k++) {\n const sec = nowSec - k;\n const b = this._activity[((sec % 60) + 60) % 60];\n if (!b || b.second !== sec) continue;\n sampledMs += b.sampledMs;\n for (const [cid, r] of b.rows) {\n if (!this._instances.has(cid)) continue;\n let a = agg.get(cid);\n if (!a) {\n a = { changes: 0, renders: 0, renderMs: 0 };\n agg.set(cid, a);\n }\n a.changes += r.changes;\n a.renders += r.renders;\n a.renderMs += r.renderMs;\n }\n }\n const ranked = [...agg].sort(\n (x, y) =>\n y[1].changes - x[1].changes || y[1].renders - x[1].renders || y[1].renderMs - x[1].renderMs || x[0] - y[0],\n );\n let rowNodes = 0;\n const rows = ranked.slice(0, topK).map(([cid, a]) => {\n const n = this._nodeCounts.get(cid) || { state: 0, derived: 0, effect: 0 };\n rowNodes += n.state + n.derived + n.effect;\n return {\n componentId: cid,\n file: this._instances.get(cid).file,\n nodes: { state: n.state, derived: n.derived, effect: n.effect },\n changes: a.changes,\n renders: a.renders,\n renderMs: Math.round(a.renderMs * 1000) / 1000,\n };\n });\n const t = this._nodeTotals;\n const until = Date.now();\n return {\n epoch: this._epoch,\n window: { ms: windowMs, since: until - windowMs, until, sampledActiveMs: Math.min(windowMs, sampledMs) },\n policy: 'sampled-200ms',\n coverage: 'component-init',\n components: { total: this._instances.size, withActivity: agg.size },\n rows,\n other: { components: this._instances.size - rows.length, nodes: t.state + t.derived + t.effect - rowNodes },\n truncated: agg.size > topK,\n capabilities: { valueInspection: false, signalHistory: false, writeCause: false },\n // Seed coverage: changes of pending nodes are not observable yet.\n baseline: this._baselineInfo(),\n };\n },\n\n // Request { requestId?, epoch?, topK?, windowMs? } (same correlation as\n // the graph, review M1).\n sendReactiveSummary(request) {\n const req = request || {};\n if (req.epoch !== undefined && req.epoch !== null && req.epoch !== this._epoch) return;\n const summary = this.getReactiveSummary(req);\n if (req.requestId !== undefined) summary.requestId = req.requestId;\n if (import.meta.hot) {\n import.meta.hot.send('svelte-devtools:reactive-summary', summary);\n }\n },\n\n // --- Phase 3: State Timeline ---\n\n // Current value of a $state node: the signal value, or for tag_proxy\n // nodes (non-reassigned object/array state) the live proxy itself.\n // Returns a sentinel when the value can't be read.\n _readStateValue(nodeId, signal) {\n if (signal._isProxy) {\n const proxy = this._reactiveProxies.get(nodeId)?.deref();\n return proxy === undefined ? __NO_VALUE : proxy;\n }\n const v = signal.v;\n // Svelte's UNINITIALIZED marker is a symbol; functions aren't state data.\n return typeof v === 'symbol' || typeof v === 'function' ? __NO_VALUE : v;\n },\n\n // Runs every 200 ms in the user's app, so it must stay cheap regardless of\n // how much state the app holds (§6.7 D).\n // 1. Hint pass, time-sliced: at most HINT_NODES $state nodes per tick,\n // continuing from a cursor carried across ticks, so a full sweep over\n // n nodes takes ceil(n / HINT_NODES) ticks (_pollSweep.lastMs is the\n // measured sweep time = worst-case detection delay). Per node O(1):\n // primitives are compared directly and recorded at once; objects\n // whose reference or Svelte write version (wv) changed are added to\n // _pollDirty, which persists across ticks until serialized.\n // 2. Serialization work is limited to BUDGET_MS per tick (dirty nodes\n // carry over, nothing is dropped).\n // 3. In-place deep mutations (proxies don't bump an outer wv) are found by\n // time-based re-checks: each object is re-verified no earlier than\n // nextCheckAt = now + max(RECHECK_MS, 50 x its serialization cost),\n // paid from a DEEP_MS-per-tick credit, so the amortized cost is bounded\n // however many large states the app holds.\n // 4. Values serializing above MAX_SNAPSHOT_CHARS are kept as length+hash\n // (not the string) and appear in the timeline as a summary.\n // Writes between two visits of a node are observed as one change (the\n // timeline is a sample, policy 'sampled-200ms'; not counted as dropped).\n _pollStateValues(baseline) {\n const HINT_NODES = 4096;\n const BUDGET_MS = 2;\n const DEEP_MS = 0.5;\n const now = performance.now();\n if (!baseline) {\n this._deepCredit = Math.min(10 * DEEP_MS, (this._deepCredit || 0) + DEEP_MS);\n // this tick samples 200 ms of wall time (window.sampledActiveMs)\n const bucket = this._bucket();\n bucket.sampledMs = Math.min(1000, bucket.sampledMs + 200);\n }\n const ids = this._pollIds;\n const due = [];\n const limit = Math.min(HINT_NODES, ids.length);\n for (let visited = 0; visited < limit && ids.length > 0; visited++) {\n if (this._pollCursor >= ids.length) {\n this._pollCursor = 0;\n if (!baseline) {\n if (this._pollSweep.startedAt) this._pollSweep.lastMs = now - this._pollSweep.startedAt;\n this._pollSweep.startedAt = now;\n this._pollSweep.nodes = ids.length;\n }\n }\n if (!baseline && !this._pollSweep.startedAt) this._pollSweep.startedAt = now;\n const nodeId = ids[this._pollCursor];\n const entry = this._reactiveNodes.get(nodeId);\n if (!entry || entry.meta.type !== 'state') {\n // re-tracked as another type: drop from the poll list (slot reused)\n this._pollRemove(nodeId);\n continue;\n }\n if (!this._instances.has(entry.meta.componentId)) {\n this._forgetNode(nodeId); // swaps the last id into this slot\n continue;\n }\n this._pollCursor++;\n const signal = entry.signal.deref();\n const value = signal ? this._readStateValue(nodeId, signal) : __NO_VALUE;\n if (value === __NO_VALUE) {\n // nothing readable (collected, uninitialized, function): not pending\n this._unseeded.delete(nodeId);\n continue;\n }\n if (value === null || typeof value !== 'object') {\n const had = this._stateSnapshots.has(nodeId);\n const prev = this._stateSnapshots.get(nodeId);\n if (had && Object.is(prev, value)) continue;\n // Forget the object key so object -> primitive -> same object again\n // is still recorded as a change.\n if (this._stateSnapshotStrs) this._stateSnapshotStrs.delete(nodeId);\n this._pollDirty.delete(nodeId);\n if (!had) {\n // first observation: seed only\n this._stateSnapshots.set(nodeId, value);\n this._unseeded.delete(nodeId);\n continue;\n }\n this._recordChange(nodeId, entry, prev, value, typeof value === 'string' ? 2 * value.length : 64);\n continue;\n }\n let meta = this._pollMeta.get(nodeId);\n if (!meta) {\n meta = { ref: undefined, wv: undefined, nextCheckAt: 0 };\n this._pollMeta.set(nodeId, meta);\n }\n if (meta.ref !== value || meta.wv !== signal.wv) this._pollDirty.add(nodeId);\n else if (now >= meta.nextCheckAt) due.push(nodeId);\n }\n const start = performance.now();\n for (const nodeId of this._pollDirty) {\n if (performance.now() - start > BUDGET_MS) return;\n this._pollDirty.delete(nodeId);\n this._serializeNode(nodeId, false);\n }\n for (const nodeId of due) {\n if (this._deepCredit <= 0 || performance.now() - start > BUDGET_MS) return;\n this._serializeNode(nodeId, true);\n }\n },\n\n // Activation (late consumer): nodes registered while inactive have no\n // seed yet, so a write before their first visit could not be seen as a\n // change. The first slice is seeded at activation instead of 200 ms later:\n // ONE normal pass (<= HINT_NODES nodes, the per-tick serialization budget;\n // the rest follow on the usual ticks). Seeds record nothing; readiness is\n // disclosed in the summary as baseline { complete, pendingNodes }.\n _pollBaseline() {\n this._baselining = true;\n try {\n this._pollStateValues(true);\n } catch { /* never break activation */ } finally {\n this._baselining = false;\n }\n },\n\n _serializeNode(nodeId, deep) {\n const MAX_SNAPSHOT_CHARS = 32768;\n const RECHECK_MS = 1000;\n const entry = this._reactiveNodes.get(nodeId);\n const meta = this._pollMeta.get(nodeId);\n if (!entry || !meta) return;\n const signal = entry.signal.deref();\n if (!signal) return;\n const value = this._readStateValue(nodeId, signal);\n if (value === __NO_VALUE || value === null || typeof value !== 'object') return;\n try {\n const t0 = performance.now();\n const str = JSON.stringify(value);\n const cost = performance.now() - t0;\n if (deep) this._deepCredit -= cost;\n meta.ref = value;\n meta.wv = signal.wv;\n meta.nextCheckAt = t0 + Math.max(RECHECK_MS, 50 * cost);\n // Small values keep the string (exact compare); large ones only a\n // length+hash so a 5 MB array doesn't pin 5 MB per node.\n const key = str === undefined ? '' : str.length > MAX_SNAPSHOT_CHARS ? str.length + ':' + __hash(str) : str;\n if (!this._stateSnapshotStrs) this._stateSnapshotStrs = new Map();\n const hadKey = this._stateSnapshotStrs.has(nodeId);\n if (hadKey && this._stateSnapshotStrs.get(nodeId) === key) return;\n this._stateSnapshotStrs.set(nodeId, key);\n const tooLarge = str !== undefined && str.length > MAX_SNAPSHOT_CHARS;\n const snapshot =\n str === undefined\n ? null\n : tooLarge\n ? '(object: ' + str.length + ' chars, too large to snapshot)'\n : JSON.parse(str);\n const size = typeof snapshot === 'string' ? 64 : str.length;\n if (!this._stateSnapshots.has(nodeId)) {\n // first observation: seed only (no entry, no counters)\n this._stateSnapshots.set(nodeId, snapshot);\n this._lastSnapshotSize.set(nodeId, size);\n this._unseeded.delete(nodeId);\n return;\n }\n if (tooLarge) this._valueTooLarge++;\n const prev = this._stateSnapshots.get(nodeId);\n this._recordChange(nodeId, entry, prev, snapshot, size + (this._lastSnapshotSize.get(nodeId) || 0));\n this._lastSnapshotSize.set(nodeId, size);\n } catch {\n // non-serializable (cycles, BigInt): never observable, so not pending\n this._unseeded.delete(nodeId);\n }\n },\n\n _recordChange(nodeId, entry, oldValue, newValue, approxBytes) {\n const change = {\n id: nodeId,\n name: entry.meta.name,\n componentFile: entry.meta.componentFile,\n oldValue,\n newValue,\n timestamp: Date.now(),\n };\n const bytes = (approxBytes || 64) + 192;\n // seq stays runtime-internal: the server assigns its own seq (§6.4).\n this._entryInfo.set(change, { seq: ++this._timelineSeq, bytes });\n this._stateTimeline.push(change);\n this._timelineBytes += bytes;\n // sampled change count (§6.7 J IA2): independent of the ring\n this._activityRow(entry.meta.componentId).changes++;\n this._stateSnapshots.set(nodeId, newValue);\n // The ring (_trimTimeline) is applied in bulk, not with one splice per\n // change (a poll tick can record thousands): before every read (each\n // push — with a hot channel and an active consumer, at least every 200\n // changes — the full snapshot, getStateTimeline() and clear), and here\n // once more than __TIMELINE_TRIM_AT entries are held or the byte budget\n // is exceeded, which bounds memory when nothing reads or pushes.\n if (this._stateTimeline.length > __TIMELINE_TRIM_AT || this._timelineBytes > __TIMELINE_BYTES) {\n this._trimTimeline();\n }\n this._scheduleTimelineUpdate();\n },\n\n // Ring: at most 500 entries and __TIMELINE_BYTES (the newest entry is\n // always kept). Removed entries that were never pushed are disclosed\n // as dropped (§6.7 C); pushed ones are already on the server.\n _trimTimeline() {\n const all = this._stateTimeline;\n let cut = 0;\n let bytesLeft = this._timelineBytes;\n while (cut < all.length - 1 && (all.length - cut > 500 || bytesLeft > __TIMELINE_BYTES)) {\n const info = this._entryInfo.get(all[cut]);\n const reason = all.length - cut > 500 ? 'runtime-count' : 'runtime-bytes';\n if (info.seq > this._pushedSeq) this._timelineDropped[reason]++;\n bytesLeft -= info.bytes;\n cut++;\n }\n if (cut > 0) {\n all.splice(0, cut);\n this._timelineBytes = bytesLeft;\n }\n },\n\n // Push (§6.7 C): a throttle, not a debounce — a pending timer is never\n // re-armed, so unsent entries leave within 300 ms of the first one even\n // under continuous change — plus an immediate flush once 200 entries\n // (one message) are unsent, since one poll tick can record thousands.\n _scheduleTimelineUpdate() {\n if (!this._active || this._baselining) return;\n if (this._timelineSeq - this._pushedSeq >= 200) {\n this._flushTimeline();\n return;\n }\n if (this._timelineDebounceTimer) return;\n this._timelineDebounceTimer = setTimeout(() => {\n this._timelineDebounceTimer = null;\n this._flushTimeline();\n }, 300);\n },\n\n _flushTimeline() {\n if (this._timelineDebounceTimer) {\n clearTimeout(this._timelineDebounceTimer);\n this._timelineDebounceTimer = null;\n }\n if (!import.meta.hot) return;\n for (const msg of this._timelineDeltas()) {\n import.meta.hot.send('svelte-devtools:state-timeline', msg);\n }\n },\n\n // Disclosure counters since the previous push, attached to (and reset\n // by) the next message: dropped [{ reason, count }] and valueTooLarge.\n _takeTimelineDisclosure(msg) {\n msg.baseline = this._baselineInfo();\n this._sentPendingNodes = msg.baseline.pendingNodes;\n const dropped = [];\n for (const reason of ['runtime-count', 'runtime-bytes']) {\n const count = this._timelineDropped[reason];\n if (count > 0) dropped.push({ reason, count });\n this._timelineDropped[reason] = 0;\n }\n if (dropped.length) msg.dropped = dropped;\n if (this._valueTooLarge > 0) msg.valueTooLarge = this._valueTooLarge;\n this._valueTooLarge = 0;\n return msg;\n },\n\n // Seed coverage (review B-2), on every state-timeline message and the\n // summary: pendingNodes = polled $state nodes without a first sample;\n // their writes are not observable yet.\n _baselineInfo() {\n return { complete: this._unseeded.size === 0, pendingNodes: this._unseeded.size };\n },\n\n _hasTimelineDisclosure() {\n return (\n this._sentPendingNodes !== this._unseeded.size ||\n this._timelineDropped['runtime-count'] > 0 ||\n this._timelineDropped['runtime-bytes'] > 0 ||\n this._valueTooLarge > 0\n );\n },\n\n // Delta push (docs/devframe-migration.md §6.4): only entries recorded\n // since the previous push, ≤ 200 per message, tagged with a per-page-load\n // epoch; reset after clearStateTimeline(). A message with no changes is\n // still sent when there is something to disclose (all unsent dropped).\n _timelineDeltas() {\n this._trimTimeline();\n const all = this._stateTimeline;\n let start = all.length;\n while (start > 0 && this._entryInfo.get(all[start - 1]).seq > this._pushedSeq) start--;\n const pending = all.slice(start);\n const msgs = [];\n const first = this._timelineReset || this._hasTimelineDisclosure();\n for (let i = 0; i < pending.length || (first && i === 0); i += 200) {\n const msg = { epoch: this._epoch, changes: pending.slice(i, i + 200) };\n if (i === 0 && this._timelineReset) msg.reset = true;\n if (i === 0) this._takeTimelineDisclosure(msg);\n else msg.baseline = this._baselineInfo();\n msgs.push(msg);\n }\n this._timelineReset = false;\n this._pushedSeq = this._timelineSeq;\n return msgs;\n },\n\n // Full buffer (reset: true) — reply to request-state-timeline and the\n // activation snapshot. Newest entries first up to __TIMELINE_BYTES, the\n // server's own buffer budget, so nothing is sent that it would drop.\n _timelineFull() {\n this._trimTimeline();\n const all = this._stateTimeline;\n let start = all.length;\n let bytes = 0;\n while (start > 0) {\n const size = this._entryInfo.get(all[start - 1]).bytes;\n if (bytes + size > __TIMELINE_BYTES && start < all.length) break;\n bytes += size;\n start--;\n }\n this._timelineReset = false;\n this._pushedSeq = this._timelineSeq;\n return this._takeTimelineDisclosure({ epoch: this._epoch, changes: all.slice(start), reset: true });\n },\n\n getStateTimeline() {\n this._trimTimeline();\n return this._stateTimeline;\n },\n\n clearStateTimeline() {\n // Ring first: unsent entries past the cap are disclosed as dropped,\n // exactly as if they had been removed when recorded.\n this._trimTimeline();\n this._stateTimeline = [];\n this._timelineBytes = 0;\n this._pushedSeq = this._timelineSeq;\n this._timelineReset = true;\n this._scheduleTimelineUpdate();\n },\n\n // --- FPS Monitoring ---\n // Uses requestAnimationFrame to measure frame rate with minimal overhead.\n // Only stores timestamps - no allocations per frame beyond a single array push.\n _fpsFrameTimes: [],\n\n _fpsLoop(gen) {\n if (gen !== this._fpsGen) return;\n this._fpsFrameTimes.push(performance.now());\n requestAnimationFrame(() => this._fpsLoop(gen));\n },\n\n _isVisible() {\n return typeof document === 'undefined' || document.visibilityState !== 'hidden';\n },\n\n _setSubscription(data) {\n const wasActive = this._active;\n this._active = !!(data && data.active);\n this._componentDeltas = !!(data && data.componentDeltas);\n if (!this._active) {\n this._pendingAdded.clear();\n this._pendingRemoved.clear();\n }\n // resync: the server holds no full base for this epoch (§6.5, review\n // C1), or we reconnected to a possibly restarted server.\n const resync = this._resync || !!(data && data.resync);\n this._resync = false;\n if (this._active && !wasActive) this._pollBaseline();\n if (this._active && (!wasActive || resync)) {\n // Collector state may be stale or empty (first activation, resync, or a\n // reconnect to a possibly restarted server): resend everything once, in\n // the order components -> profiles -> timeline(reset: true); the\n // reset push marks the activation snapshot complete (D4).\n this._sendUpdate(true);\n this._sendProfileUpdate();\n if (import.meta.hot) {\n import.meta.hot.send('svelte-devtools:state-timeline', this._timelineFull());\n }\n }\n this._syncSampling();\n },\n\n // Sampling (state poll + FPS) runs only while active AND the app tab is\n // visible.\n _syncSampling() {\n const want = this._active && this._isVisible();\n if (want && !this._sampling) {\n this._fpsFrameTimes = [];\n const gen = ++this._fpsGen;\n this._sampling = {\n poll: setInterval(() => {\n this._pollStateValues();\n // seed progress changed: push it even without changes (B-2)\n if (this._sentPendingNodes !== this._unseeded.size) this._scheduleTimelineUpdate();\n }, 200),\n fps: setInterval(() => { this._sampleFps(); }, 500),\n };\n requestAnimationFrame(() => this._fpsLoop(gen));\n } else if (!want && this._sampling) {\n clearInterval(this._sampling.poll);\n clearInterval(this._sampling.fps);\n this._sampling = null;\n this._fpsGen++;\n this._fpsFrameTimes = [];\n }\n },\n\n _sampleFps() {\n const now = performance.now();\n // Remove frame timestamps older than 1 second\n const cutoff = now - 1000;\n let i = 0;\n while (i < this._fpsFrameTimes.length && this._fpsFrameTimes[i] < cutoff) i++;\n if (i > 0) this._fpsFrameTimes.splice(0, i);\n const fps = this._fpsFrameTimes.length;\n if (import.meta.hot) {\n import.meta.hot.send('svelte-devtools:fps', { timestamp: Date.now(), fps });\n }\n }\n };\n\n window.__SVELTE_DEVTOOLS__ = __SVELTE_DT;\n\n // State polling and FPS sampling start on the server's subscription\n // message (§6.3) and pause while the app tab is hidden.\n if (typeof document !== 'undefined' && document.addEventListener) {\n document.addEventListener('visibilitychange', () => __SVELTE_DT._syncSampling());\n }\n\n // Phase 3: Capture runtime errors\n window.addEventListener('error', (event) => {\n if (import.meta.hot) {\n import.meta.hot.send('svelte-devtools:runtime-error', {\n message: event.message,\n file: event.filename,\n line: event.lineno,\n column: event.colno,\n stack: event.error?.stack || '',\n timestamp: Date.now(),\n });\n }\n });\n window.addEventListener('unhandledrejection', (event) => {\n if (import.meta.hot) {\n const reason = event.reason;\n import.meta.hot.send('svelte-devtools:runtime-error', {\n message: reason?.message || String(reason),\n stack: reason?.stack || '',\n timestamp: Date.now(),\n });\n }\n });\n\n // Listen for reactive graph requests from server\n // Pull requests are answered regardless of the subscription state.\n if (import.meta.hot) {\n import.meta.hot.on('svelte-devtools:subscription', (data) => {\n __SVELTE_DT._setSubscription(data);\n });\n import.meta.hot.on('vite:ws:connect', () => {\n // The server may have restarted with an empty collector: the reply to\n // runtime-ready is treated as a fresh activation (full snapshot).\n __SVELTE_DT._resync = true;\n import.meta.hot.send('svelte-devtools:runtime-ready', {});\n });\n import.meta.hot.send('svelte-devtools:runtime-ready', {});\n import.meta.hot.on('svelte-devtools:request-reactive-graph', (data) => {\n __SVELTE_DT.sendReactiveGraph(data);\n });\n import.meta.hot.on('svelte-devtools:request-reactive-summary', (data) => {\n __SVELTE_DT.sendReactiveSummary(data);\n });\n import.meta.hot.on('svelte-devtools:request-state-timeline', () => {\n import.meta.hot.send('svelte-devtools:state-timeline', __SVELTE_DT._timelineFull());\n });\n import.meta.hot.on('svelte-devtools:clear-state-timeline', () => {\n __SVELTE_DT.clearStateTimeline();\n });\n }\n}\n", C = {
875
+ //#region src/server/collector.ts
876
+ var N = {
214
877
  liveComponents: 5e4,
215
878
  renderProfiles: 5e3,
216
879
  stateTimeline: 500,
@@ -220,7 +883,7 @@ var S = "virtual:svelte-devtools-runtime", ge = "\0virtual:svelte-devtools-runti
220
883
  runtimeErrors: 200,
221
884
  loadProfiles: 200,
222
885
  compilerWarnings: 500
223
- }, be = 1e3, xe = Date.now() * 1e3, w = () => ++xe, T = "(legacy)", E = {
886
+ }, Ye = 1e3, Xe = Date.now() * 1e3, P = () => ++Xe, F = "(legacy)", I = {
224
887
  components: "svelte-devtools:components",
225
888
  profiles: "svelte-devtools:profiles",
226
889
  stateTimeline: "svelte-devtools:state-timeline",
@@ -234,36 +897,56 @@ var S = "virtual:svelte-devtools-runtime", ge = "\0virtual:svelte-devtools-runti
234
897
  clearStateTimeline: "svelte-devtools:clear-state-timeline",
235
898
  runtimeReady: "svelte-devtools:runtime-ready",
236
899
  subscription: "svelte-devtools:subscription"
237
- }, Se = 32, D = {
900
+ }, Ze = 32, L = {
238
901
  topK: 50,
239
902
  maxTopK: 200,
240
903
  windowMs: 1e4,
241
904
  minWindowMs: 1e3,
242
905
  maxWindowMs: 6e4
243
- }, O = [
906
+ }, Qe = [
244
907
  "runtime-count",
245
908
  "runtime-bytes",
246
909
  "server-count",
247
910
  "server-bytes"
248
911
  ];
249
- function k(e) {
912
+ function R(e) {
250
913
  let t = e;
251
914
  return !!t && typeof t.complete == "boolean" && Number.isInteger(t.pendingNodes) && t.pendingNodes >= 0;
252
915
  }
253
- function A(e, t, n, r) {
916
+ function z(e, t, n, r) {
254
917
  return typeof e != "number" || !Number.isFinite(e) ? r : Math.min(n, Math.max(t, Math.trunc(e)));
255
918
  }
256
- var Ce = 15e3;
257
- function j(e, t) {
919
+ function B(e) {
920
+ return z(e, 0, 2 ** 53 - 1, 0);
921
+ }
922
+ function V(e) {
923
+ return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
924
+ }
925
+ function $e(e) {
926
+ let t = V(e);
927
+ return typeof t?.timestamp == "number" && typeof t.fps == "number";
928
+ }
929
+ function et(e) {
930
+ return typeof V(e)?.message == "string";
931
+ }
932
+ function H(e, t) {
933
+ return {
934
+ captured: e,
935
+ total: t,
936
+ truncated: t > e,
937
+ policy: "tail"
938
+ };
939
+ }
940
+ var tt = 15e3;
941
+ function nt(e, t) {
258
942
  let n = Array.isArray(e) ? e : [];
259
943
  return n.length > t ? n.slice(-t) : n;
260
944
  }
261
- function M(e, t) {
945
+ function U(e, t) {
262
946
  let n = Array.isArray(e) ? e : [];
263
947
  return n.length > t ? n.slice(0, t) : n;
264
948
  }
265
- var we = class {
266
- hooks;
949
+ var rt = class {
267
950
  epochs = /* @__PURE__ */ new Map();
268
951
  servedEpoch;
269
952
  liveCache;
@@ -276,22 +959,22 @@ var we = class {
276
959
  runtimeErrors = [];
277
960
  fpsSamples = [];
278
961
  versions = {
279
- components: w(),
280
- renderProfiles: w(),
281
- loadProfiles: w(),
282
- stateTimeline: w(),
283
- reactiveGraph: w(),
284
- errors: w(),
285
- fps: w()
962
+ components: P(),
963
+ renderProfiles: P(),
964
+ loadProfiles: P(),
965
+ stateTimeline: P(),
966
+ reactiveGraph: P(),
967
+ errors: P(),
968
+ fps: P()
286
969
  };
287
970
  bump(...e) {
288
- for (let t of e) this.versions[t] = w();
971
+ for (let t of e) this.versions[t] = P();
289
972
  }
290
973
  timeline = [];
291
974
  timelineSizes = [];
292
975
  timelineEpochs = [];
293
976
  timelineBytes = 0;
294
- timelineSeq = w();
977
+ timelineSeq = P();
295
978
  timelineResetAt = this.timelineSeq;
296
979
  timelineTrimmedAt = this.timelineSeq;
297
980
  lastPull = { stateTimeline: 0 };
@@ -317,20 +1000,25 @@ var we = class {
317
1000
  active = !1;
318
1001
  sweepTimer;
319
1002
  stateTimelineResolvers = [];
1003
+ hooks;
320
1004
  constructor(e = {}) {
321
1005
  this.hooks = e;
322
1006
  }
323
1007
  attach(e) {
324
1008
  this.detach(), this.hot = e;
325
1009
  let t = [
326
- [E.runtimeReady, (e, t) => t?.send(E.subscription, this.subscription)],
327
- [E.components, (e, t) => this.ingestComponents(e, t)],
328
- [E.profiles, (e) => this.ingestProfiles(e)],
329
- [E.stateTimeline, (e) => this.ingestStateTimeline(e)],
330
- [E.fps, (e) => this.ingestFps(e)],
331
- [E.runtimeError, (e) => this.ingestRuntimeError(e)],
332
- [E.reactiveGraph, (e) => this.ingestReactiveGraph(e)],
333
- [E.reactiveSummary, (e) => this.ingestReactiveSummary(e)]
1010
+ [I.runtimeReady, (e, t) => t?.send(I.subscription, this.subscription)],
1011
+ [I.components, (e, t) => this.ingestComponents(V(e), t)],
1012
+ [I.profiles, (e) => this.ingestProfiles(V(e))],
1013
+ [I.stateTimeline, (e) => this.ingestStateTimeline(V(e))],
1014
+ [I.fps, (e) => {
1015
+ $e(e) && this.ingestFps(e);
1016
+ }],
1017
+ [I.runtimeError, (e) => {
1018
+ et(e) && this.ingestRuntimeError(e);
1019
+ }],
1020
+ [I.reactiveGraph, (e) => this.ingestReactiveGraph(V(e))],
1021
+ [I.reactiveSummary, (e) => this.ingestReactiveSummary(V(e))]
334
1022
  ];
335
1023
  for (let [n, r] of t) e.on(n, r);
336
1024
  this.detachHot = () => {
@@ -402,7 +1090,7 @@ var we = class {
402
1090
  serve(e) {
403
1091
  this.servedEpoch !== e && (this.servedEpoch !== void 0 && this.bump("components", "renderProfiles"), this.servedEpoch = e, this.liveCache = void 0);
404
1092
  }
405
- lease(e, t = Ce) {
1093
+ lease(e, t = tt) {
406
1094
  let n = this.active;
407
1095
  return this.leases.set(e, Date.now() + t), this.updateSubscription(), !n && this.active;
408
1096
  }
@@ -423,12 +1111,12 @@ var we = class {
423
1111
  let e = Date.now(), t = Infinity;
424
1112
  for (let [n, r] of this.leases) r <= e ? this.leases.delete(n) : t = Math.min(t, r);
425
1113
  let n = this.leases.size > 0;
426
- n !== this.active && (this.active = n, this.hot?.send(E.subscription, this.subscription)), clearTimeout(this.sweepTimer), this.sweepTimer = void 0, t !== Infinity && (this.sweepTimer = setTimeout(() => this.updateSubscription(), t - e + 1), this.sweepTimer.unref?.());
1114
+ n !== this.active && (this.active = n, this.hot?.send(I.subscription, this.subscription)), clearTimeout(this.sweepTimer), this.sweepTimer = void 0, t !== Infinity && (this.sweepTimer = setTimeout(() => this.updateSubscription(), t - e + 1), this.sweepTimer.unref?.());
427
1115
  }
428
1116
  ingestComponents(e, t) {
429
- let n = typeof e?.epoch == "string" ? e.epoch : T, r = !Array.isArray(e?.components) && (Array.isArray(e?.added) || Array.isArray(e?.removed));
1117
+ let n = typeof e?.epoch == "string" ? e.epoch : F, r = !Array.isArray(e?.components) && (Array.isArray(e?.added) || Array.isArray(e?.removed));
430
1118
  if (r && !this.epochs.get(n)?.hasBase) {
431
- this.resyncRequested.has(n) || (this.resyncRequested.add(n), t?.send(E.subscription, {
1119
+ this.resyncRequested.has(n) || (this.resyncRequested.add(n), t?.send(I.subscription, {
432
1120
  ...this.subscription,
433
1121
  resync: !0
434
1122
  }));
@@ -443,33 +1131,29 @@ var we = class {
443
1131
  i.components.set(t, e);
444
1132
  continue;
445
1133
  }
446
- (e?.parentId == null || i.components.has(e.parentId)) && i.components.size < C.liveComponents ? (i.overflow.delete(t), i.components.set(t, e)) : i.overflow.add(t);
1134
+ let n = e?.parentId;
1135
+ (n == null || i.components.has(n)) && i.components.size < N.liveComponents ? (i.overflow.delete(t), i.components.set(t, e)) : i.overflow.add(t);
447
1136
  }
448
1137
  this.liveCache = void 0, this.bump("components");
449
1138
  }
450
1139
  ingestProfiles(e) {
451
- let t = typeof e?.epoch == "string" ? e.epoch : T, n = this.touchEpoch(t);
452
- n.profiles = j(e?.profiles, C.renderProfiles), n.profilesTotal = typeof e?.total == "number" && Number.isFinite(e.total) ? e.total : null, this.bump("renderProfiles");
1140
+ let t = typeof e?.epoch == "string" ? e.epoch : F, n = this.touchEpoch(t);
1141
+ n.profiles = nt(e?.profiles, N.renderProfiles), n.profilesTotal = typeof e?.total == "number" && Number.isFinite(e.total) ? e.total : null, this.bump("renderProfiles");
453
1142
  }
454
1143
  getCaptureInfo() {
455
- let e = this.servedState(), t = this.servedEpoch, n = (e, t) => ({
456
- captured: e,
457
- total: t,
458
- truncated: t > e,
459
- policy: "tail"
460
- }), r = {
1144
+ let e = this.servedState(), t = this.servedEpoch, n = {
461
1145
  "runtime-count": 0,
462
1146
  "runtime-bytes": 0,
463
1147
  "server-count": 0,
464
1148
  "server-bytes": 0
465
1149
  };
466
- for (let e of this.timelineDrops.values()) for (let t of O) r[t] += e[t];
467
- let i = O.filter((e) => r[e] > 0).map((e) => ({
1150
+ for (let e of this.timelineDrops.values()) for (let t of Qe) n[t] += e[t];
1151
+ let r = Qe.filter((e) => n[e] > 0).map((e) => ({
468
1152
  reason: e,
469
- count: r[e]
470
- })), a = 0;
471
- for (let e of this.timelineTooLarge.values()) a += e;
472
- let o = e?.profiles.length ?? 0, s = e?.profilesTotal ?? null, c = this.lastGraph, l = {
1153
+ count: n[e]
1154
+ })), i = 0;
1155
+ for (let e of this.timelineTooLarge.values()) i += e;
1156
+ let a = e?.profiles.length ?? 0, o = e?.profilesTotal ?? null, s = this.lastGraph, c = {
473
1157
  liveComponents: {
474
1158
  captured: e?.components.size ?? 0,
475
1159
  total: this.liveComponentsTotal,
@@ -478,74 +1162,75 @@ var we = class {
478
1162
  ...t !== void 0 && { epoch: t }
479
1163
  },
480
1164
  renderProfiles: {
481
- captured: o,
482
- total: s,
483
- truncated: s !== null && s > o,
1165
+ captured: a,
1166
+ total: o,
1167
+ truncated: o !== null && o > a,
484
1168
  policy: "newest-mounted",
485
1169
  ...t !== void 0 && { epoch: t }
486
1170
  },
487
1171
  stateTimeline: {
488
1172
  captured: this.timeline.length,
489
1173
  total: null,
490
- truncated: i.length > 0,
1174
+ truncated: r.length > 0,
491
1175
  policy: "sampled-200ms",
492
- ...i.length > 0 && { dropped: i },
493
- ...a > 0 && { valueTooLarge: a },
1176
+ ...r.length > 0 && { dropped: r },
1177
+ ...i > 0 && { valueTooLarge: i },
494
1178
  ...t !== void 0 && this.timelineBaseline.has(t) && { baseline: this.timelineBaseline.get(t) }
495
1179
  },
496
- fpsSamples: n(this.fpsSamples.length, this.received.fps),
497
- runtimeErrors: n(this.runtimeErrors.length, this.received.runtimeErrors),
498
- loadProfiles: n(this.loadProfiles.length, this.received.loadProfiles),
499
- compilerWarnings: n(this.compilerWarnings.length, this.received.compilerWarnings)
1180
+ fpsSamples: H(this.fpsSamples.length, this.received.fps),
1181
+ runtimeErrors: H(this.runtimeErrors.length, this.received.runtimeErrors),
1182
+ loadProfiles: H(this.loadProfiles.length, this.received.loadProfiles),
1183
+ compilerWarnings: H(this.compilerWarnings.length, this.received.compilerWarnings)
500
1184
  };
501
- if (c) {
1185
+ if (s) {
502
1186
  let e = {
503
- truncated: c.truncated,
504
- policy: c.policy,
505
- ...c.epoch !== null && { epoch: c.epoch }
1187
+ truncated: s.truncated,
1188
+ policy: s.policy,
1189
+ ...s.epoch !== null && { epoch: s.epoch }
506
1190
  };
507
- l.reactiveNodes = {
508
- captured: c.nodes.length,
509
- total: c.total?.nodes ?? null,
1191
+ c.reactiveNodes = {
1192
+ captured: s.nodes.length,
1193
+ total: s.total?.nodes ?? null,
510
1194
  ...e
511
- }, l.reactiveEdges = {
512
- captured: c.edges.length,
513
- total: c.total?.edges ?? null,
1195
+ }, c.reactiveEdges = {
1196
+ captured: s.edges.length,
1197
+ total: s.total?.edges ?? null,
514
1198
  ...e
515
1199
  };
516
1200
  }
517
- return l;
1201
+ return c;
518
1202
  }
519
1203
  get stateTimeline() {
520
1204
  return this.timeline;
521
1205
  }
522
1206
  ingestStateTimeline(e) {
523
- let t = j(e?.changes, C.stateTimeline);
524
- if (typeof e?.epoch == "string") this.touchEpoch(e.epoch), this.countRuntimeLosses(e.epoch, e.dropped, e.valueTooLarge), e.reset === !0 && this.dropEpoch(e.epoch), this.appendTimeline(t, e.epoch), k(e.baseline) && this.timelineBaseline.set(e.epoch, {
1207
+ let t = nt(e?.changes, N.stateTimeline);
1208
+ if (typeof e?.epoch == "string") this.touchEpoch(e.epoch), this.countRuntimeLosses(e.epoch, e.dropped, e.valueTooLarge), e.reset === !0 && this.dropEpoch(e.epoch), this.appendTimeline(t, e.epoch), R(e.baseline) && this.timelineBaseline.set(e.epoch, {
525
1209
  complete: e.baseline.complete,
526
1210
  pendingNodes: e.baseline.pendingNodes
527
1211
  });
528
1212
  else {
529
1213
  let e;
530
- for (let t = this.timeline.length - 1; t >= 0 && !e; t--) this.timelineEpochs[t] === T && (e = this.timeline[t]);
1214
+ for (let t = this.timeline.length - 1; t >= 0 && !e; t--) this.timelineEpochs[t] === F && (e = this.timeline[t]);
531
1215
  let n = -1;
532
- if (e) {
533
- for (let r = t.length - 1; r >= 0; r--) if (t[r].timestamp === e.timestamp && t[r].id === e.id) {
1216
+ if (e) for (let r = t.length - 1; r >= 0; r--) {
1217
+ let i = t[r];
1218
+ if (i.timestamp === e.timestamp && i.id === e.id) {
534
1219
  n = r + 1;
535
1220
  break;
536
1221
  }
537
1222
  }
538
- n === -1 && (this.dropEpoch(T), n = 0), this.appendTimeline(t.slice(n), T);
1223
+ n === -1 && (this.dropEpoch(F), n = 0), this.appendTimeline(t.slice(n), F);
539
1224
  }
540
1225
  this.lastPull.stateTimeline = Date.now(), this.flushStateTimeline(), e?.reset === !0 && this.resolveSnapshotWaiters();
541
1226
  }
542
1227
  countRuntimeLosses(e, t, n) {
543
1228
  if (Array.isArray(t)) for (let n of t) {
544
1229
  if (n?.reason !== "runtime-count" && n?.reason !== "runtime-bytes") continue;
545
- let t = A(n.count, 0, 2 ** 53 - 1, 0);
1230
+ let t = z(n.count, 0, 2 ** 53 - 1, 0);
546
1231
  t > 0 && this.addDrop(e, n.reason, t);
547
1232
  }
548
- let r = A(n, 0, 2 ** 53 - 1, 0);
1233
+ let r = z(n, 0, 2 ** 53 - 1, 0);
549
1234
  r > 0 && this.timelineTooLarge.set(e, (this.timelineTooLarge.get(e) ?? 0) + r);
550
1235
  }
551
1236
  addDrop(e, t, n) {
@@ -573,7 +1258,7 @@ var we = class {
573
1258
  };
574
1259
  }
575
1260
  markTimelineReset() {
576
- this.timelineResetAt = this.timelineSeq = w(), this.bump("stateTimeline");
1261
+ this.timelineResetAt = this.timelineSeq = P(), this.bump("stateTimeline");
577
1262
  }
578
1263
  dropEpoch(e) {
579
1264
  if (!this.timelineEpochs.includes(e)) return;
@@ -591,10 +1276,10 @@ var we = class {
591
1276
  }
592
1277
  this.timeline.push({
593
1278
  ...n,
594
- seq: this.timelineSeq = w()
1279
+ seq: this.timelineSeq = P()
595
1280
  }), this.timelineSizes.push(e), this.timelineEpochs.push(t), this.timelineBytes += e;
596
1281
  }
597
- let n = Math.max(0, this.timeline.length - C.stateTimeline), r = this.timelineBytes;
1282
+ let n = Math.max(0, this.timeline.length - N.stateTimeline), r = this.timelineBytes;
598
1283
  for (let e = 0; e < n; e++) r -= this.timelineSizes[e], this.addDrop(this.timelineEpochs[e], "server-count", 1);
599
1284
  for (; r > 4194304 && n < this.timeline.length - 1;) this.addDrop(this.timelineEpochs[n], "server-bytes", 1), r -= this.timelineSizes[n++];
600
1285
  n > 0 && (this.timelineTrimmedAt = this.timeline[n - 1].seq, this.timeline = this.timeline.slice(n), this.timelineSizes = this.timelineSizes.slice(n), this.timelineEpochs = this.timelineEpochs.slice(n)), this.timelineBytes = r, this.bump("stateTimeline");
@@ -604,23 +1289,23 @@ var we = class {
604
1289
  }
605
1290
  ingestReactiveGraph(e) {
606
1291
  let t = typeof e?.requestId == "string" ? e.requestId : void 0;
607
- if (t !== void 0) {
608
- let n = this.pulls.get(t);
609
- if (!n || n.kind !== "graph" || n.epoch !== null && typeof e?.epoch == "string" && e.epoch !== n.epoch) return;
610
- this.settle(t, this.normalizeGraph(e, n.scope, n.epoch));
611
- } else {
1292
+ if (t === void 0) {
612
1293
  let t = !1;
613
1294
  for (let [n, r] of this.pulls) r.kind === "graph" && (t = !0, this.settle(n, this.normalizeGraph(e, r.scope, r.epoch)));
614
1295
  t || this.storeGraph(this.normalizeGraph(e, null, this.servedEpoch ?? null));
1296
+ } else {
1297
+ let n = this.pulls.get(t);
1298
+ if (n?.kind !== "graph" || n.epoch !== null && typeof e?.epoch == "string" && e.epoch !== n.epoch) return;
1299
+ this.settle(t, this.normalizeGraph(e, n.scope, n.epoch));
615
1300
  }
616
1301
  this.bump("reactiveGraph");
617
1302
  }
618
1303
  normalizeGraph(e, t, n) {
619
- let r = typeof e?.requestId != "string", i = M(e?.nodes, Infinity), a = M(e?.edges, Infinity), o = e?.policy === "scoped" || e?.policy === "global-head" ? e.policy : t === null ? "global-head" : "scoped", s = null;
620
- if (!r && e?.total && typeof e.total.nodes == "number" && (s = {
621
- nodes: e.total.nodes,
1304
+ let r = typeof e?.requestId != "string", i = U(e?.nodes, Infinity), a = U(e?.edges, Infinity), o = e?.policy === "scoped" || e?.policy === "global-head" ? e.policy : t === null ? "global-head" : "scoped", s = null, c = V(e?.total);
1305
+ if (!r && typeof c?.nodes == "number" && (s = {
1306
+ nodes: c.nodes,
622
1307
  nodesKind: "registered",
623
- edges: typeof e.total.edges == "number" ? e.total.edges : null
1308
+ edges: typeof c.edges == "number" ? c.edges : null
624
1309
  }), r && t !== null) {
625
1310
  let e = new Set(i.filter((e) => e?.componentId === t).map((e) => e.id)), n = new Set(e);
626
1311
  for (let t of a) e.has(t?.from) && n.add(t.to), e.has(t?.to) && n.add(t.from);
@@ -630,18 +1315,18 @@ var we = class {
630
1315
  nodesKind: "sent",
631
1316
  edges: a.length
632
1317
  });
633
- let c = e?.truncated === !0;
634
- i.length > C.reactiveNodes && (i = i.slice(0, C.reactiveNodes), c = !0);
635
- let l = new Set(i.map((e) => e?.id)), u = A(e?.edgesOmitted, 0, 2 ** 53 - 1, 0), d = [];
636
- for (let e of a) !l.has(e?.from) || !l.has(e?.to) ? o !== "server-filter" && u++ : d.length < C.reactiveEdges ? d.push(e) : (u++, c = !0);
1318
+ let l = e?.truncated === !0;
1319
+ i.length > N.reactiveNodes && (i = i.slice(0, N.reactiveNodes), l = !0);
1320
+ let u = new Set(i.map((e) => e?.id)), d = z(e?.edgesOmitted, 0, 2 ** 53 - 1, 0), f = [];
1321
+ for (let e of a) !u.has(e?.from) || !u.has(e?.to) ? o !== "server-filter" && d++ : f.length < N.reactiveEdges ? f.push(e) : (d++, l = !0);
637
1322
  return {
638
1323
  nodes: i,
639
- edges: d,
1324
+ edges: f,
640
1325
  scope: t,
641
1326
  epoch: typeof e?.epoch == "string" ? e.epoch : n,
642
1327
  total: s,
643
- truncated: c,
644
- edgesOmitted: u,
1328
+ truncated: l,
1329
+ edgesOmitted: d,
645
1330
  computedAt: typeof e?.computedAt == "number" && Number.isFinite(e.computedAt) ? e.computedAt : null,
646
1331
  policy: o
647
1332
  };
@@ -654,60 +1339,63 @@ var we = class {
654
1339
  }
655
1340
  ingestReactiveSummary(e) {
656
1341
  let t = typeof e?.requestId == "string" ? e.requestId : void 0, n = t === void 0 ? void 0 : this.pulls.get(t);
657
- n && n.kind === "summary" && (n.epoch === null || typeof e?.epoch != "string" || e.epoch === n.epoch) && this.settle(t, this.normalizeSummary(e, n.epoch));
1342
+ n?.kind === "summary" && (n.epoch === null || typeof e?.epoch != "string" || e.epoch === n.epoch) && this.settle(t, this.normalizeSummary(e, n.epoch));
658
1343
  }
659
1344
  normalizeSummary(e, t) {
660
- let n = (e) => A(e, 0, 2 ** 53 - 1, 0), r = M(e?.rows, D.maxTopK).map((e) => ({
661
- componentId: n(e?.componentId),
662
- file: typeof e?.file == "string" ? e.file : "",
663
- nodes: {
664
- state: n(e?.nodes?.state),
665
- derived: n(e?.nodes?.derived),
666
- effect: n(e?.nodes?.effect)
667
- },
668
- changes: n(e?.changes),
669
- renders: n(e?.renders),
670
- renderMs: typeof e?.renderMs == "number" && e.renderMs >= 0 ? e.renderMs : 0
671
- })), i = e?.window;
1345
+ let n = U(e?.rows, L.maxTopK).map((e) => {
1346
+ let t = V(e), n = V(t?.nodes), r = {
1347
+ componentId: B(t?.componentId),
1348
+ file: typeof t?.file == "string" ? t.file : "",
1349
+ nodes: {
1350
+ state: B(n?.state),
1351
+ derived: B(n?.derived),
1352
+ effect: B(n?.effect)
1353
+ },
1354
+ changes: B(t?.changes),
1355
+ renders: B(t?.renders),
1356
+ renderMs: typeof t?.renderMs == "number" && t.renderMs >= 0 ? t.renderMs : 0
1357
+ };
1358
+ return t?.kind === "module" && (r.kind = "module"), r;
1359
+ }), r = V(e?.window), i = V(e?.components), a = V(e?.other), o = V(e?.capabilities);
672
1360
  return {
673
1361
  epoch: typeof e?.epoch == "string" ? e.epoch : t,
674
1362
  window: {
675
- ms: n(i?.ms),
676
- since: n(i?.since),
677
- until: n(i?.until),
678
- sampledActiveMs: n(i?.sampledActiveMs)
1363
+ ms: B(r?.ms),
1364
+ since: B(r?.since),
1365
+ until: B(r?.until),
1366
+ sampledActiveMs: B(r?.sampledActiveMs)
679
1367
  },
680
1368
  policy: "sampled-200ms",
681
1369
  coverage: "component-init",
682
1370
  components: {
683
- total: typeof e?.components?.total == "number" ? e.components.total : null,
684
- withActivity: n(e?.components?.withActivity)
1371
+ total: typeof i?.total == "number" ? i.total : null,
1372
+ withActivity: B(i?.withActivity)
685
1373
  },
686
- rows: r,
687
- other: e?.other && typeof e.other.components == "number" && typeof e.other.nodes == "number" ? {
688
- components: e.other.components,
689
- nodes: e.other.nodes
1374
+ rows: n,
1375
+ other: typeof a?.components == "number" && typeof a.nodes == "number" ? {
1376
+ components: a.components,
1377
+ nodes: a.nodes
690
1378
  } : null,
691
1379
  truncated: e?.truncated === !0,
692
1380
  capabilities: {
693
- valueInspection: e?.capabilities?.valueInspection === !0,
694
- signalHistory: e?.capabilities?.signalHistory === !0,
695
- writeCause: e?.capabilities?.writeCause === !0
1381
+ valueInspection: o?.valueInspection === !0,
1382
+ signalHistory: o?.signalHistory === !0,
1383
+ writeCause: o?.writeCause === !0
696
1384
  },
697
- ...k(e?.baseline) && { baseline: { ...e.baseline } }
1385
+ ...R(e?.baseline) && { baseline: { ...e.baseline } }
698
1386
  };
699
1387
  }
700
1388
  ingestFps(e) {
701
- this.received.fps++, this.fpsSamples.push(e), this.fpsSamples.length > C.fpsSamples && (this.fpsSamples = this.fpsSamples.slice(-C.fpsSamples)), this.bump("fps"), this.hooks.onFpsSample?.(e);
1389
+ this.received.fps++, this.fpsSamples.push(e), this.fpsSamples.length > N.fpsSamples && (this.fpsSamples = this.fpsSamples.slice(-N.fpsSamples)), this.bump("fps"), this.hooks.onFpsSample?.(e);
702
1390
  }
703
1391
  ingestRuntimeError(e) {
704
- this.received.runtimeErrors++, this.runtimeErrors.push(e), this.runtimeErrors.length > C.runtimeErrors && (this.runtimeErrors = this.runtimeErrors.slice(-C.runtimeErrors)), this.bump("errors");
1392
+ this.received.runtimeErrors++, this.runtimeErrors.push(e), this.runtimeErrors.length > N.runtimeErrors && (this.runtimeErrors = this.runtimeErrors.slice(-N.runtimeErrors)), this.bump("errors");
705
1393
  }
706
1394
  recordLoadProfile(e) {
707
- this.received.loadProfiles++, this.loadProfiles.push(e), this.loadProfiles.length > C.loadProfiles && (this.loadProfiles = this.loadProfiles.slice(-C.loadProfiles)), this.bump("loadProfiles"), this.hooks.onLoadProfile?.(e);
1395
+ this.received.loadProfiles++, this.loadProfiles.push(e), this.loadProfiles.length > N.loadProfiles && (this.loadProfiles = this.loadProfiles.slice(-N.loadProfiles)), this.bump("loadProfiles"), this.hooks.onLoadProfile?.(e);
708
1396
  }
709
1397
  recordCompilerWarning(e) {
710
- this.received.compilerWarnings++, this.compilerWarnings.push(e), this.compilerWarnings.length > C.compilerWarnings && (this.compilerWarnings = this.compilerWarnings.slice(-C.compilerWarnings)), this.bump("errors");
1398
+ this.received.compilerWarnings++, this.compilerWarnings.push(e), this.compilerWarnings.length > N.compilerWarnings && (this.compilerWarnings = this.compilerWarnings.slice(-N.compilerWarnings)), this.bump("errors");
711
1399
  }
712
1400
  clearLoadProfiles() {
713
1401
  this.loadProfiles = [], this.received.loadProfiles = 0, this.bump("loadProfiles");
@@ -719,10 +1407,10 @@ var we = class {
719
1407
  this.fpsSamples = [], this.received.fps = 0, this.bump("fps");
720
1408
  }
721
1409
  clearStateTimeline() {
722
- this.timeline = [], this.timelineSizes = [], this.timelineEpochs = [], this.timelineBytes = 0, this.timelineDrops.clear(), this.timelineTooLarge.clear(), this.markTimelineReset(), this.hot?.send(E.clearStateTimeline, {});
1410
+ this.timeline = [], this.timelineSizes = [], this.timelineEpochs = [], this.timelineBytes = 0, this.timelineDrops.clear(), this.timelineTooLarge.clear(), this.markTimelineReset(), this.hot?.send(I.clearStateTimeline, {});
723
1411
  }
724
1412
  requestReactiveGraph(e = {}) {
725
- let t = typeof e.componentId == "number" && Number.isInteger(e.componentId) && e.componentId >= 0 ? e.componentId : null, n = A(e.maxNodes, 1, C.reactiveNodes, C.reactiveNodes), r = A(e.maxEdges, 1, C.reactiveEdges, C.reactiveEdges), i = this.servedEpoch ?? null;
1413
+ let t = typeof e.componentId == "number" && Number.isInteger(e.componentId) && e.componentId >= 0 ? e.componentId : null, n = z(e.maxNodes, 1, N.reactiveNodes, N.reactiveNodes), r = z(e.maxEdges, 1, N.reactiveEdges, N.reactiveEdges), i = this.servedEpoch ?? null;
726
1414
  if (t !== null && i === null) return Promise.resolve({
727
1415
  nodes: [],
728
1416
  edges: [],
@@ -750,7 +1438,7 @@ var we = class {
750
1438
  staleReason: "epoch-changed"
751
1439
  });
752
1440
  let a = `graph|${i ?? ""}|${t ?? "*"}|${n}|${r}`;
753
- return this.keyedPull("graph", a, i, t, E.requestReactiveGraph, {
1441
+ return this.keyedPull("graph", a, i, t, I.requestReactiveGraph, {
754
1442
  ...t !== null && { componentId: t },
755
1443
  maxNodes: n,
756
1444
  maxEdges: r
@@ -769,8 +1457,8 @@ var we = class {
769
1457
  }));
770
1458
  }
771
1459
  requestReactiveSummary(e = {}) {
772
- let t = A(e.topK, 1, D.maxTopK, D.topK), n = A(e.windowMs, D.minWindowMs, D.maxWindowMs, D.windowMs), r = this.servedEpoch ?? null, i = `summary|${r ?? ""}|${t}|${n}`;
773
- return this.keyedPull("summary", i, r, null, E.requestReactiveSummary, {
1460
+ let t = z(e.topK, 1, L.maxTopK, L.topK), n = z(e.windowMs, L.minWindowMs, L.maxWindowMs, L.windowMs), r = this.servedEpoch ?? null, i = `summary|${r ?? ""}|${t}|${n}`;
1461
+ return this.keyedPull("summary", i, r, null, I.requestReactiveSummary, {
774
1462
  topK: t,
775
1463
  windowMs: n
776
1464
  }, (e) => ({
@@ -815,7 +1503,7 @@ var we = class {
815
1503
  let u = this.hot, d = `r${++this.requestSeq}`, f = new Promise((o) => {
816
1504
  let c = setTimeout(() => {
817
1505
  this.pulls.delete(d), o(s("timeout"));
818
- }, be);
1506
+ }, Ye);
819
1507
  this.pulls.set(d, {
820
1508
  kind: e,
821
1509
  key: t,
@@ -839,7 +1527,7 @@ var we = class {
839
1527
  for (this.pulls.delete(e), clearTimeout(n.timer), this.pullCache.delete(n.key), this.pullCache.set(n.key, {
840
1528
  value: t,
841
1529
  at: Date.now()
842
- }); this.pullCache.size > Se;) this.pullCache.delete(this.pullCache.keys().next().value);
1530
+ }); this.pullCache.size > Ze;) this.pullCache.delete(this.pullCache.keys().next().value);
843
1531
  n.kind === "graph" && this.storeGraph(t), n.resolve(t);
844
1532
  }
845
1533
  }
@@ -891,7 +1579,7 @@ var we = class {
891
1579
  }
892
1580
  }
893
1581
  requestStateTimeline() {
894
- return this.pull("stateTimeline", E.requestStateTimeline, this.stateTimelineResolvers, () => this.stateTimeline);
1582
+ return this.pull("stateTimeline", I.requestStateTimeline, this.stateTimelineResolvers, () => this.stateTimeline);
895
1583
  }
896
1584
  pull(e, t, n, r) {
897
1585
  if (!this.hot || Date.now() - this.lastPull[e] < 1e3) return Promise.resolve(r());
@@ -903,7 +1591,7 @@ var we = class {
903
1591
  }, o = setTimeout(() => {
904
1592
  let t = n.indexOf(i);
905
1593
  t !== -1 && n.splice(t, 1), e(r());
906
- }, be);
1594
+ }, Ye);
907
1595
  n.push(i), a.send(t, {});
908
1596
  }).finally(() => {
909
1597
  this.inflight[e] === o && (this.inflight[e] = void 0);
@@ -915,62 +1603,10 @@ var we = class {
915
1603
  this.stateTimelineResolvers = [];
916
1604
  for (let t of e) t(this.stateTimeline);
917
1605
  }
918
- }, Te = {
919
- ".png": "image/png",
920
- ".jpg": "image/jpeg",
921
- ".jpeg": "image/jpeg",
922
- ".gif": "image/gif",
923
- ".svg": "image/svg+xml",
924
- ".webp": "image/webp",
925
- ".avif": "image/avif",
926
- ".ico": "image/x-icon",
927
- ".woff": "font/woff",
928
- ".woff2": "font/woff2",
929
- ".ttf": "font/ttf",
930
- ".eot": "application/vnd.ms-fontobject",
931
- ".otf": "font/otf",
932
- ".mp4": "video/mp4",
933
- ".webm": "video/webm",
934
- ".mp3": "audio/mpeg",
935
- ".wav": "audio/wav",
936
- ".ogg": "audio/ogg",
937
- ".json": "application/json",
938
- ".xml": "application/xml",
939
- ".pdf": "application/pdf",
940
- ".txt": "text/plain",
941
- ".css": "text/css",
942
- ".js": "text/javascript",
943
- ".html": "text/html"
944
1606
  };
945
- function Ee(e, t = "/") {
946
- if (!r.existsSync(e)) return [];
947
- let n = [];
948
- return N(e, e, t.endsWith("/") ? t : `${t}/`, n), n.sort((e, t) => e.relativePath.localeCompare(t.relativePath));
949
- }
950
- function N(e, t, n, a) {
951
- let o = r.readdirSync(e, { withFileTypes: !0 });
952
- for (let s of o) {
953
- let o = i.join(e, s.name);
954
- if (s.isDirectory()) {
955
- N(o, t, n, a);
956
- continue;
957
- }
958
- if (s.name.startsWith(".")) continue;
959
- let c = r.statSync(o), l = i.extname(s.name).toLowerCase(), u = i.relative(t, o);
960
- a.push({
961
- name: s.name,
962
- path: o,
963
- relativePath: u,
964
- url: n + u.split(i.sep).map(encodeURIComponent).join("/"),
965
- size: c.size,
966
- type: Te[l] || "application/octet-stream",
967
- mtime: c.mtimeMs
968
- });
969
- }
970
- }
971
1607
  //#endregion
972
- //#region src/security.ts
973
- function De(e) {
1608
+ //#region src/server/security.ts
1609
+ function it(e) {
974
1610
  let t;
975
1611
  try {
976
1612
  t = new URL(e);
@@ -978,17 +1614,19 @@ function De(e) {
978
1614
  throw Error(`Invalid URL: ${e}`);
979
1615
  }
980
1616
  if (t.protocol !== "http:" && t.protocol !== "https:") throw Error(`Blocked URL scheme: ${t.protocol}`);
981
- let n = t.hostname;
982
- if (n === "::1" || n === "[::1]") throw Error("Blocked: loopback address");
1617
+ let n = at(t);
983
1618
  if (f.isIP(n)) {
984
- if (F(n)) throw Error(`Blocked: private IP address ${n}`);
985
- } else {
986
- let e = n.toLowerCase();
987
- if (e === "localhost" || e.endsWith(".local") || e.endsWith(".internal")) throw Error(`Blocked: internal hostname ${n}`);
988
- }
1619
+ if (lt(n)) throw Error(`Blocked: private IP address ${n}`);
1620
+ } else if (ot(n)) throw Error(`Blocked: internal hostname ${n}`);
989
1621
  return t;
990
1622
  }
991
- async function P(e, t = {}) {
1623
+ function at(e) {
1624
+ return e.hostname.replaceAll(/^\[|\]$/g, "").toLowerCase().replace(/\.$/, "");
1625
+ }
1626
+ function ot(e) {
1627
+ return e === "localhost" || e.endsWith(".localhost") || e.endsWith(".local") || e.endsWith(".internal");
1628
+ }
1629
+ async function st(e, t = {}) {
992
1630
  let n;
993
1631
  try {
994
1632
  n = new URL(e);
@@ -996,122 +1634,297 @@ async function P(e, t = {}) {
996
1634
  throw Error(`Invalid URL: ${e}`);
997
1635
  }
998
1636
  if (t.allowedOrigins?.includes(n.origin)) return n;
999
- De(e);
1000
- let r = n.hostname.replace(/^\[|\]$/g, "");
1637
+ it(e);
1638
+ let r = at(n);
1001
1639
  if (f.isIP(r)) return n;
1002
- let i = await d.lookup(r, { all: !0 }).catch(() => []);
1003
- for (let { address: e } of i) if (F(e)) throw Error(`Blocked: ${r} resolves to private address`);
1640
+ let i;
1641
+ try {
1642
+ i = await d.lookup(r, { all: !0 });
1643
+ } catch {
1644
+ throw Error(`Blocked: ${r} does not resolve`);
1645
+ }
1646
+ for (let { address: e } of i) if (lt(e)) throw Error(`Blocked: ${r} resolves to private address`);
1004
1647
  return n;
1005
1648
  }
1006
- function F(e) {
1007
- if (e.includes(":")) return Oe(e);
1008
- let t = e.split(".").map(Number);
1009
- return !!(t.length === 4 && (t[0] === 127 || t[0] === 10 || t[0] === 172 && t[1] >= 16 && t[1] <= 31 || t[0] === 192 && t[1] === 168 || t[0] === 169 && t[1] === 254 || t.every((e) => e === 0)));
1649
+ var W = new f.BlockList();
1650
+ for (let [e, t] of [
1651
+ ["0.0.0.0", 8],
1652
+ ["10.0.0.0", 8],
1653
+ ["100.64.0.0", 10],
1654
+ ["127.0.0.0", 8],
1655
+ ["169.254.0.0", 16],
1656
+ ["172.16.0.0", 12],
1657
+ ["192.0.0.0", 24],
1658
+ ["192.0.2.0", 24],
1659
+ ["192.168.0.0", 16],
1660
+ ["198.18.0.0", 15],
1661
+ ["198.51.100.0", 24],
1662
+ ["203.0.113.0", 24],
1663
+ ["224.0.0.0", 4],
1664
+ ["240.0.0.0", 4]
1665
+ ]) W.addSubnet(e, t, "ipv4");
1666
+ var ct = new f.BlockList();
1667
+ for (let [e, t] of [
1668
+ ["::", 128],
1669
+ ["::1", 128],
1670
+ ["::", 96],
1671
+ ["100::", 64],
1672
+ ["2001:db8::", 32],
1673
+ ["fc00::", 7],
1674
+ ["fe80::", 10],
1675
+ ["fec0::", 10],
1676
+ ["ff00::", 8]
1677
+ ]) ct.addSubnet(e, t, "ipv6");
1678
+ function lt(e) {
1679
+ let t = e.replaceAll(/^\[|\]$/g, "").toLowerCase(), n = f.isIP(t);
1680
+ if (n === 4) return W.check(t, "ipv4");
1681
+ if (n !== 6) return !0;
1682
+ let r = ft(ut(t));
1683
+ return r === null ? ct.check(t, "ipv6") : W.check(r, "ipv4");
1684
+ }
1685
+ function ut(e) {
1686
+ let t = e, n = /(\d+\.\d+\.\d+\.\d+)$/.exec(t);
1687
+ if (n) {
1688
+ let [e, r, i, a] = n[1].split(".").map(Number);
1689
+ t = `${t.slice(0, n.index)}${(e << 8 | r).toString(16)}:${(i << 8 | a).toString(16)}`;
1690
+ }
1691
+ let [r, i] = t.split("::");
1692
+ if (i === void 0) return G(r);
1693
+ let a = G(r), o = G(i);
1694
+ return [
1695
+ ...a,
1696
+ ...Array.from({ length: 8 - a.length - o.length }, () => 0),
1697
+ ...o
1698
+ ];
1699
+ }
1700
+ function G(e) {
1701
+ return e === "" ? [] : e.split(":").map((e) => Number.parseInt(e, 16));
1702
+ }
1703
+ function dt(e, t) {
1704
+ return `${e >> 8}.${e & 255}.${t >> 8}.${t & 255}`;
1010
1705
  }
1011
- function Oe(e) {
1012
- let t = e.toLowerCase().replace(/^\[|\]$/g, ""), n = t.match(/^::(?:ffff:)?(\d+\.\d+\.\d+\.\d+)$/);
1013
- return n ? F(n[1]) : t === "::" || t === "::1" || /^f[cd][0-9a-f]{2}:/.test(t) || /^fe[89ab][0-9a-f]:/.test(t);
1706
+ function ft(e) {
1707
+ let [t, n, r, i, a, o, s, c] = e;
1708
+ return t === 0 && n === 0 && r === 0 && i === 0 && a === 0 && (o === 65535 || o === 0) && (s !== 0 || o === 65535) || t === 100 && n === 65435 && r === 0 && i === 0 && a === 0 && o === 0 ? dt(s, c) : t === 8194 ? dt(n, r) : null;
1014
1709
  }
1015
- function I(t, n) {
1710
+ function K(e, n) {
1016
1711
  if (typeof n != "string" || n.length === 0) throw Error("Invalid file path");
1017
- let r = a.realpathSync(t), i = e.isAbsolute(n) ? n : e.resolve(t, n), o;
1712
+ let i = r.realpathSync(e), a = t.isAbsolute(n) ? n : t.resolve(e, n), o;
1018
1713
  try {
1019
- o = a.realpathSync(i);
1714
+ o = r.realpathSync(a);
1020
1715
  } catch {
1021
1716
  throw Error("File not found");
1022
1717
  }
1023
- if (o !== r && !o.startsWith(r + e.sep)) throw Error("Forbidden: path outside project root");
1718
+ if (o !== i && !o.startsWith(i + t.sep)) throw Error("Forbidden: path outside project root");
1024
1719
  return o;
1025
1720
  }
1026
1721
  //#endregion
1722
+ //#region src/analyzers/http.ts
1723
+ var pt = 3e4;
1724
+ async function mt(e, t, n, r = pt) {
1725
+ let i = new AbortController(), a, o = new Promise((e, t) => {
1726
+ a = setTimeout(() => {
1727
+ let e = /* @__PURE__ */ Error(`Timed out after ${r}ms`);
1728
+ i.abort(e), t(e);
1729
+ }, r);
1730
+ }), s = (async () => n(await fetch(e, {
1731
+ ...t,
1732
+ redirect: "manual",
1733
+ signal: i.signal
1734
+ })))();
1735
+ s.catch(() => {});
1736
+ try {
1737
+ return await Promise.race([s, o]);
1738
+ } finally {
1739
+ clearTimeout(a);
1740
+ }
1741
+ }
1742
+ //#endregion
1027
1743
  //#region src/analyzers/api.ts
1028
- var ke = [
1744
+ var ht = [
1029
1745
  "GET",
1030
1746
  "POST",
1031
1747
  "PUT",
1032
1748
  "PATCH",
1033
- "DELETE"
1749
+ "DELETE",
1750
+ "HEAD",
1751
+ "OPTIONS"
1034
1752
  ];
1035
- function Ae(e) {
1753
+ function gt(e, t) {
1754
+ let { program: n, errors: r } = u(t, e);
1755
+ if (r.length > 0) return null;
1756
+ let i = /* @__PURE__ */ new Set();
1757
+ for (let e of n.body) {
1758
+ if (e.type !== "ExportNamedDeclaration") continue;
1759
+ let t = e.declaration;
1760
+ if (t?.type === "FunctionDeclaration" && t.id) i.add(t.id.name);
1761
+ else if (t?.type === "VariableDeclaration") for (let e of t.declarations) e.id.type === "Identifier" && i.add(e.id.name);
1762
+ for (let t of e.specifiers) {
1763
+ let e = t.exported;
1764
+ i.add(e.type === "Literal" ? e.value : e.name);
1765
+ }
1766
+ }
1767
+ return i;
1768
+ }
1769
+ function _t(e) {
1036
1770
  let t = [];
1037
1771
  for (let n of e) {
1038
1772
  let e = n.files.find((e) => e.type === "endpoint");
1039
1773
  if (!e) continue;
1040
- let r = "";
1774
+ let i = null;
1041
1775
  try {
1042
- r = a.readFileSync(e.path, "utf-8");
1776
+ i = gt(r.readFileSync(e.path, "utf-8"), e.path);
1043
1777
  } catch {}
1044
- let i = ke.filter((e) => r.includes(`export const ${e}`) || r.includes(`export async function ${e}`) || r.includes(`export function ${e}`));
1045
- i.length === 0 && i.push("GET"), t.push({
1778
+ let a = i?.has("fallback") ? [...ht] : ht.filter((e) => i?.has(e));
1779
+ t.push({
1046
1780
  route: n.id,
1047
1781
  path: n.path,
1048
- methods: i,
1782
+ methods: a,
1049
1783
  file: e.path
1050
1784
  });
1051
1785
  }
1052
1786
  return t;
1053
1787
  }
1054
- async function je(e, t = {}) {
1055
- let n = performance.now(), r = () => Math.round((performance.now() - n) * 100) / 100;
1788
+ function vt(e) {
1789
+ if (!e.trim()) return {};
1790
+ let t = JSON.parse(e);
1791
+ if (typeof t != "object" || !t || Array.isArray(t) || !Object.values(t).every((e) => typeof e == "string")) throw TypeError("Headers must be a JSON object of string values");
1792
+ return t;
1793
+ }
1794
+ async function yt(e, t = {}, n) {
1795
+ let r = performance.now(), i = () => Math.round((performance.now() - r) * 100) / 100;
1056
1796
  try {
1057
- await P(e.url, t);
1058
- let n = e.headers ? JSON.parse(e.headers) : {}, i = {
1797
+ await st(e.url, t);
1798
+ let r = {
1059
1799
  method: e.method,
1060
- headers: n,
1061
- redirect: "manual"
1062
- };
1063
- e.body && e.method !== "GET" && e.method !== "HEAD" && (i.body = e.body);
1064
- let a = await fetch(e.url, i), o = await a.text(), s = {};
1065
- return a.headers.forEach((e, t) => {
1066
- s[t] = e;
1067
- }), {
1068
- status: a.status,
1069
- statusText: a.statusText,
1070
- headers: s,
1071
- body: o,
1072
- duration: r()
1800
+ headers: vt(e.headers)
1073
1801
  };
1802
+ return e.body && e.method !== "GET" && e.method !== "HEAD" && (r.body = e.body), await mt(e.url, r, async (e) => {
1803
+ let t = await e.text(), n = {};
1804
+ return e.headers.forEach((e, t) => {
1805
+ n[t] = e;
1806
+ }), {
1807
+ status: e.status,
1808
+ statusText: e.statusText,
1809
+ headers: n,
1810
+ body: t,
1811
+ duration: i()
1812
+ };
1813
+ }, n);
1074
1814
  } catch (e) {
1075
1815
  return {
1076
1816
  status: 0,
1077
1817
  statusText: String(e),
1078
1818
  headers: {},
1079
1819
  body: "",
1080
- duration: r()
1820
+ duration: i()
1081
1821
  };
1082
1822
  }
1083
1823
  }
1084
1824
  //#endregion
1825
+ //#region src/analyzers/assets.ts
1826
+ var bt = {
1827
+ ".png": "image/png",
1828
+ ".jpg": "image/jpeg",
1829
+ ".jpeg": "image/jpeg",
1830
+ ".gif": "image/gif",
1831
+ ".svg": "image/svg+xml",
1832
+ ".webp": "image/webp",
1833
+ ".avif": "image/avif",
1834
+ ".ico": "image/x-icon",
1835
+ ".woff": "font/woff",
1836
+ ".woff2": "font/woff2",
1837
+ ".ttf": "font/ttf",
1838
+ ".eot": "application/vnd.ms-fontobject",
1839
+ ".otf": "font/otf",
1840
+ ".mp4": "video/mp4",
1841
+ ".webm": "video/webm",
1842
+ ".mp3": "audio/mpeg",
1843
+ ".wav": "audio/wav",
1844
+ ".ogg": "audio/ogg",
1845
+ ".json": "application/json",
1846
+ ".xml": "application/xml",
1847
+ ".pdf": "application/pdf",
1848
+ ".txt": "text/plain",
1849
+ ".css": "text/css",
1850
+ ".js": "text/javascript",
1851
+ ".html": "text/html"
1852
+ };
1853
+ function xt(e, t = "/") {
1854
+ if (!r.existsSync(e)) return [];
1855
+ let n = [];
1856
+ return St(e, e, t.endsWith("/") ? t : `${t}/`, n), n.toSorted((e, t) => e.relativePath.localeCompare(t.relativePath));
1857
+ }
1858
+ function St(e, n, i, a) {
1859
+ let o = r.readdirSync(e, { withFileTypes: !0 });
1860
+ for (let s of o) {
1861
+ let o = t.join(e, s.name);
1862
+ if (s.isDirectory()) {
1863
+ St(o, n, i, a);
1864
+ continue;
1865
+ }
1866
+ if (s.name.startsWith(".")) continue;
1867
+ let c;
1868
+ try {
1869
+ c = r.statSync(o);
1870
+ } catch {
1871
+ continue;
1872
+ }
1873
+ if (!c.isFile()) continue;
1874
+ let l = t.extname(s.name).toLowerCase(), u = t.relative(n, o);
1875
+ a.push({
1876
+ name: s.name,
1877
+ path: o,
1878
+ relativePath: u,
1879
+ url: i + u.split(t.sep).map(encodeURIComponent).join("/"),
1880
+ size: c.size,
1881
+ type: bt[l] ?? "application/octet-stream",
1882
+ mtime: c.mtimeMs
1883
+ });
1884
+ }
1885
+ }
1886
+ //#endregion
1085
1887
  //#region src/analyzers/build.ts
1086
- var Me = /* @__PURE__ */ new Set([
1888
+ var Ct = /* @__PURE__ */ new Set([
1087
1889
  ".js",
1088
1890
  ".css",
1089
1891
  ".html"
1090
1892
  ]);
1091
- function Ne(t) {
1092
- let n = [], r = [
1093
- e.resolve(t, ".svelte-kit/output"),
1094
- e.resolve(t, "build/client"),
1095
- e.resolve(t, "build")
1096
- ], i = (r) => {
1097
- for (let o of a.readdirSync(r, { withFileTypes: !0 })) {
1098
- let s = e.join(r, o.name);
1099
- if (o.isDirectory()) {
1100
- i(s);
1893
+ function wt(e) {
1894
+ let n = [], i = /* @__PURE__ */ new Set(), a = [
1895
+ t.resolve(e, ".svelte-kit/output"),
1896
+ t.resolve(e, "build/client"),
1897
+ t.resolve(e, "build")
1898
+ ], o = (a) => {
1899
+ let s;
1900
+ try {
1901
+ s = r.readdirSync(a, { withFileTypes: !0 });
1902
+ } catch {
1903
+ return;
1904
+ }
1905
+ for (let c of s) {
1906
+ let s = t.join(a, c.name);
1907
+ if (c.isDirectory()) {
1908
+ o(s);
1101
1909
  continue;
1102
1910
  }
1103
- Me.has(e.extname(o.name).toLowerCase()) && n.push({
1104
- name: o.name,
1105
- file: e.relative(t, s),
1106
- size: a.statSync(s).size,
1911
+ if (!Ct.has(t.extname(c.name).toLowerCase())) continue;
1912
+ let l, u;
1913
+ try {
1914
+ l = r.realpathSync(s), u = r.statSync(l);
1915
+ } catch {
1916
+ continue;
1917
+ }
1918
+ u.isFile() && !i.has(l) && (i.add(l), n.push({
1919
+ name: c.name,
1920
+ file: t.relative(e, s),
1921
+ size: u.size,
1107
1922
  modules: [],
1108
- isEntry: o.name.includes("index") || o.name.includes("start")
1109
- });
1923
+ isEntry: c.name.includes("index") || c.name.includes("start")
1924
+ }));
1110
1925
  }
1111
1926
  };
1112
- for (let e of r) try {
1113
- i(e);
1114
- } catch {}
1927
+ for (let e of a) o(e);
1115
1928
  return n.sort((e, t) => t.size - e.size), {
1116
1929
  chunks: n,
1117
1930
  totalSize: n.reduce((e, t) => e + t.size, 0),
@@ -1120,72 +1933,165 @@ function Ne(t) {
1120
1933
  }
1121
1934
  //#endregion
1122
1935
  //#region src/analyzers/module-graph.ts
1123
- function Pe(t) {
1124
- let n = e.extname(t).toLowerCase();
1936
+ function Tt(e) {
1937
+ let n = t.extname(e).toLowerCase();
1125
1938
  return n === ".svelte" ? "svelte" : n === ".ts" ? "ts" : n === ".js" ? "js" : n === ".css" ? "css" : "other";
1126
1939
  }
1127
- function Fe(t, n) {
1128
- let r = [], i = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
1129
- for (let s of n) {
1130
- if (!s.file || s.file.includes("node_modules")) continue;
1131
- let n = e.relative(t, s.file);
1132
- if (n.startsWith("..") || i.has(s.file)) continue;
1133
- let c;
1940
+ function Et(e, n) {
1941
+ let r = t.relative(e, n);
1942
+ return r !== "" && r !== ".." && !r.startsWith(`..${t.sep}`) && !t.isAbsolute(r);
1943
+ }
1944
+ function Dt(e, n) {
1945
+ let i = [], a = /* @__PURE__ */ new Map();
1946
+ for (let o of n) {
1947
+ if (!o.file || o.file.split(/[\\/]/).includes("node_modules") || !Et(e, o.file) || a.has(o.file)) continue;
1948
+ let n;
1134
1949
  try {
1135
- c = a.statSync(s.file).size;
1950
+ n = r.statSync(o.file).size;
1136
1951
  } catch {}
1137
- let l = {
1138
- id: n,
1139
- file: s.file,
1140
- type: Pe(s.file),
1952
+ let s = {
1953
+ id: t.relative(e, o.file),
1954
+ file: o.file,
1955
+ type: Tt(o.file),
1141
1956
  importedBy: [],
1142
1957
  imports: [],
1143
- size: c
1958
+ size: n
1144
1959
  };
1145
- i.set(s.file, l), o.set(n, l), r.push(l);
1960
+ a.set(o.file, s), i.push(s);
1146
1961
  }
1147
- let s = /* @__PURE__ */ new Map();
1962
+ let o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
1148
1963
  for (let e of n) {
1149
- if (!e.file) continue;
1150
- let t = i.get(e.file);
1964
+ let t = e.file ? a.get(e.file) : void 0;
1151
1965
  if (!t) continue;
1152
- let n = new Set(t.imports);
1966
+ let n = o.get(t);
1967
+ n || o.set(t, n = /* @__PURE__ */ new Set());
1153
1968
  for (let r of e.importedModules) {
1154
- let e = r.file ? i.get(r.file) : void 0;
1155
- if (!e) continue;
1969
+ let e = r.file ? a.get(r.file) : void 0;
1970
+ if (!e || e === t) continue;
1156
1971
  n.has(e.id) || (n.add(e.id), t.imports.push(e.id));
1157
- let a = s.get(e);
1158
- a || s.set(e, a = new Set(e.importedBy)), a.has(t.id) || (a.add(t.id), e.importedBy.push(t.id));
1972
+ let i = s.get(e);
1973
+ i || s.set(e, i = /* @__PURE__ */ new Set()), i.has(t.id) || (i.add(t.id), e.importedBy.push(t.id));
1974
+ }
1975
+ }
1976
+ let c = new Map(i.map((e) => [e.id, e])), l = Ot(i, c), u = /* @__PURE__ */ new Map();
1977
+ for (let e of l.values()) u.set(e, (u.get(e) ?? 0) + 1);
1978
+ let d = (e) => u.get(l.get(e)) > 1, f = [], p = /* @__PURE__ */ new Set();
1979
+ for (let e of i) {
1980
+ if (!d(e.id) || (e.isCyclic = !0, p.has(e.id))) continue;
1981
+ let t = kt(e.id, c, l);
1982
+ for (let e of t) p.add(e);
1983
+ f.push(t);
1984
+ }
1985
+ return {
1986
+ modules: i,
1987
+ cycles: f
1988
+ };
1989
+ }
1990
+ function Ot(e, t) {
1991
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = [], a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map(), s = 0, c = 0, l = (e) => {
1992
+ n.set(e, s), r.set(e, s), s++, i.push(e), a.add(e);
1993
+ };
1994
+ for (let s of e) {
1995
+ if (n.has(s.id)) continue;
1996
+ l(s.id);
1997
+ let e = [{
1998
+ id: s.id,
1999
+ i: 0
2000
+ }];
2001
+ for (; e.length > 0;) {
2002
+ let s = e.at(-1), u = t.get(s.id).imports;
2003
+ if (s.i < u.length) {
2004
+ let t = u[s.i++];
2005
+ n.has(t) ? a.has(t) && r.set(s.id, Math.min(r.get(s.id), n.get(t))) : (l(t), e.push({
2006
+ id: t,
2007
+ i: 0
2008
+ }));
2009
+ continue;
2010
+ }
2011
+ e.pop();
2012
+ let d = e.at(-1);
2013
+ if (d && r.set(d.id, Math.min(r.get(d.id), r.get(s.id))), r.get(s.id) === n.get(s.id)) {
2014
+ let e;
2015
+ do
2016
+ e = i.pop(), a.delete(e), o.set(e, c);
2017
+ while (e !== s.id);
2018
+ c++;
2019
+ }
1159
2020
  }
1160
2021
  }
1161
- let c = [], l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), d = [];
1162
- function f(e) {
1163
- if (u.has(e)) {
1164
- let t = d.indexOf(e);
1165
- if (t >= 0) {
1166
- let n = d.slice(t).concat(e);
1167
- n.length > 2 && c.push(n);
2022
+ return o;
2023
+ }
2024
+ function kt(e, t, n) {
2025
+ let r = n.get(e), i = /* @__PURE__ */ new Map(), a = [e];
2026
+ for (let o = 0; o < a.length; o++) {
2027
+ let s = a[o];
2028
+ for (let o of t.get(s).imports) {
2029
+ if (o === e) {
2030
+ let t = [e];
2031
+ for (let n = s; n !== e; n = i.get(n)) t.splice(1, 0, n);
2032
+ return t.push(e), t;
1168
2033
  }
1169
- return;
2034
+ n.get(o) !== r || i.has(o) || (i.set(o, s), a.push(o));
1170
2035
  }
1171
- if (l.has(e)) return;
1172
- l.add(e), u.add(e), d.push(e);
1173
- let t = o.get(e);
1174
- if (t) for (let e of t.imports) f(e);
1175
- d.pop(), u.delete(e);
1176
- }
1177
- for (let e of r) f(e.id);
1178
- let p = new Set(c.flat());
1179
- for (let e of r) p.has(e.id) && (e.isCyclic = !0);
1180
- return {
1181
- modules: r,
1182
- cycles: c
1183
- };
2036
+ }
2037
+ /* v8 ignore next -- unreachable: every module of a non-trivial component is on a cycle */
2038
+ return [e, e];
1184
2039
  }
1185
2040
  //#endregion
1186
2041
  //#region src/analyzers/og.ts
1187
- async function Ie(e, t = {}) {
1188
- let n = {
2042
+ var At = {
2043
+ amp: "&",
2044
+ lt: "<",
2045
+ gt: ">",
2046
+ quot: "\"",
2047
+ apos: "'",
2048
+ nbsp: "\xA0"
2049
+ };
2050
+ function q(e) {
2051
+ return e.replaceAll(/&(?:#(\d+)|#x([0-9a-f]+)|([a-z]+));/gi, (e, t, n, r) => {
2052
+ if (r) return At[r.toLowerCase()] ?? e;
2053
+ let i = t ? Number(t) : Number.parseInt(n, 16);
2054
+ return i > 0 && i <= 1114111 ? String.fromCodePoint(i) : e;
2055
+ });
2056
+ }
2057
+ var jt = /<meta\b((?:[^>"']|"[^"]*"|'[^']*')*)>/gi, Mt = /([^\s=/>"']+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/g;
2058
+ function Nt(e) {
2059
+ let t = [];
2060
+ for (let n of e.matchAll(jt)) {
2061
+ let e = /* @__PURE__ */ new Map();
2062
+ for (let t of n[1].matchAll(Mt)) {
2063
+ let n = t[1].toLowerCase();
2064
+ e.has(n) || e.set(n, t[2] ?? t[3] ?? t[4] ?? "");
2065
+ }
2066
+ let r = e.get("property") ?? e.get("name"), i = e.get("content");
2067
+ r && i !== void 0 && t.push({
2068
+ property: q(r),
2069
+ content: q(i)
2070
+ });
2071
+ }
2072
+ return t;
2073
+ }
2074
+ function Pt(e) {
2075
+ return e?.match(/charset\s*=\s*["']?\s*([\w.:-]+)/i)?.[1];
2076
+ }
2077
+ function Ft(e, t) {
2078
+ let n = new TextDecoder("latin1").decode(e.subarray(0, 1024)), r = /<meta\b[^>]*charset[^>]*>/i.exec(n)?.[0] ?? null, i = Pt(t) ?? Pt(r) ?? "utf-8", a;
2079
+ try {
2080
+ a = new TextDecoder(i);
2081
+ } catch {
2082
+ a = new TextDecoder("utf-8");
2083
+ }
2084
+ return a.decode(e);
2085
+ }
2086
+ function It(e, t) {
2087
+ try {
2088
+ return new URL(e, t).href;
2089
+ } catch {
2090
+ return e;
2091
+ }
2092
+ }
2093
+ async function Lt(e, t = {}, n) {
2094
+ let r = {
1189
2095
  url: e,
1190
2096
  title: "",
1191
2097
  description: "",
@@ -1194,47 +2100,43 @@ async function Ie(e, t = {}) {
1194
2100
  issues: []
1195
2101
  };
1196
2102
  try {
1197
- await P(e, t);
1198
- let r = await fetch(e, { redirect: "manual" });
1199
- if (r.status >= 300 && r.status < 400) return n.issues.push(`Redirects to ${r.headers.get("location") ?? "(no location)"} (not followed)`), n;
1200
- let i = await r.text(), a = /<meta\s+([^>]*?)\/?>/gi, o = /(?:property|name)=["']([^"']+)["']/, s = /content=["']([^"']+)["']/, c;
1201
- for (; (c = a.exec(i)) !== null;) {
1202
- let e = c[1], t = e.match(o), r = e.match(s);
1203
- if (t && r) {
1204
- let e = t[1], i = r[1];
1205
- n.tags.push({
1206
- property: e,
1207
- content: i
1208
- }), e === "og:title" ? n.title = i : e === "og:description" ? n.description = i : e === "og:image" && (n.image = i);
1209
- }
1210
- }
1211
- if (!n.title) {
1212
- let e = i.match(/<title>([^<]+)<\/title>/i);
1213
- e && (n.title = e[1]);
1214
- }
1215
- if (!n.description) {
1216
- let e = n.tags.find((e) => e.property === "description");
1217
- e && (n.description = e.content);
2103
+ await st(e, t);
2104
+ let i = await mt(e, {}, async (e) => ({
2105
+ status: e.status,
2106
+ location: e.headers.get("location"),
2107
+ html: e.status >= 300 && e.status < 400 ? "" : Ft(new Uint8Array(await e.arrayBuffer()), e.headers.get("content-type"))
2108
+ }), n);
2109
+ if (i.status >= 300 && i.status < 400) return r.issues.push(`Redirects to ${i.location ?? "(no location)"} (not followed)`), r;
2110
+ i.status >= 400 && r.issues.push(`Responded with HTTP ${i.status}`);
2111
+ let a = i.html;
2112
+ r.tags = Nt(a);
2113
+ let o = (e) => r.tags.find((t) => t.property === e)?.content;
2114
+ r.title = o("og:title") ?? "", r.description = o("og:description") ?? "";
2115
+ let s = o("og:image");
2116
+ if (r.image = s ? It(s, e) : "", !r.title) {
2117
+ let e = /<title\b[^>]*>([\s\S]*?)<\/title>/i.exec(a);
2118
+ e && (r.title = q(e[1]).replaceAll(/\s+/g, " ").trim());
1218
2119
  }
1219
- n.title || n.issues.push("Missing og:title or <title>"), n.description || n.issues.push("Missing og:description or meta description"), n.image || n.issues.push("Missing og:image"), n.tags.some((e) => e.property === "og:url") || n.issues.push("Missing og:url"), n.tags.some((e) => e.property === "og:type") || n.issues.push("Missing og:type");
2120
+ r.description ||= o("description") ?? "", r.title || r.issues.push("Missing og:title or <title>"), r.description || r.issues.push("Missing og:description or meta description"), r.image || r.issues.push("Missing og:image"), r.tags.some((e) => e.property === "og:url") || r.issues.push("Missing og:url"), r.tags.some((e) => e.property === "og:type") || r.issues.push("Missing og:type");
1220
2121
  } catch (e) {
1221
- n.issues.push(`Failed to fetch: ${String(e)}`);
2122
+ r.issues.push(`Failed to fetch: ${String(e)}`);
1222
2123
  }
1223
- return n;
2124
+ return r;
1224
2125
  }
1225
2126
  //#endregion
1226
2127
  //#region src/analyzers/source.ts
1227
- function Le(e, t, n) {
2128
+ function Rt(e, t, n) {
1228
2129
  let r = e.split("\n");
1229
2130
  if (n === "effect") return r.findIndex((e) => e.includes("$effect(") || e.includes("$effect.pre(")) + 1;
1230
- let i = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), a = RegExp(`(?:let|const|var)\\s+${i}\\b`);
2131
+ if (!t) return 0;
2132
+ let i = t.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&"), a = RegExp(`\\b(?:let|const|var)\\s+${i}(?![\\w$])`);
1231
2133
  return r.findIndex((e) => a.test(e)) + 1;
1232
2134
  }
1233
2135
  //#endregion
1234
- //#region src/devframe.ts
1235
- var Re = "svelte-devtools", L = "/.svelte-devtools/", R = o(import.meta.url)("../package.json"), ze = e.resolve(e.dirname(s(import.meta.url)), "client"), z = u.string().min(1).max(4096);
1236
- function Be(e) {
1237
- let { collector: t } = e, n = () => v(e.root()), r = () => re(n().routesDir);
2136
+ //#region src/server/devframe.ts
2137
+ var J = "svelte-devtools", Y = "/.svelte-devtools/", zt = s(import.meta.url), Bt = zt.resolve("vite-devtools-svelte/package.json"), X = zt(Bt), Vt = t.join(t.dirname(Bt), "dist/client"), Z = o.string().min(1).max(4096);
2138
+ function Ht(e) {
2139
+ let { collector: t } = e, n = () => y(e.root()), i = () => de(n().routesDir);
1238
2140
  return [
1239
2141
  l({
1240
2142
  name: "get-project",
@@ -1246,25 +2148,25 @@ function Be(e) {
1246
2148
  name: "get-routes",
1247
2149
  type: "query",
1248
2150
  jsonSerializable: !0,
1249
- handler: () => r()
2151
+ handler: () => i()
1250
2152
  }),
1251
2153
  l({
1252
2154
  name: "get-assets",
1253
2155
  type: "query",
1254
2156
  jsonSerializable: !0,
1255
- handler: () => Ee(n().staticDir, e.publicBase())
2157
+ handler: () => xt(n().staticDir, e.publicBase())
1256
2158
  }),
1257
2159
  l({
1258
2160
  name: "get-component-relations",
1259
2161
  type: "query",
1260
2162
  jsonSerializable: !0,
1261
- handler: () => b(e.root())
2163
+ handler: () => g(e.root())
1262
2164
  }),
1263
2165
  l({
1264
2166
  name: "get-svelte-files",
1265
2167
  type: "query",
1266
2168
  jsonSerializable: !0,
1267
- handler: () => b(e.root()).map((e) => ({
2169
+ handler: () => g(e.root()).map((e) => ({
1268
2170
  file: e.file,
1269
2171
  name: e.name
1270
2172
  }))
@@ -1290,11 +2192,11 @@ function Be(e) {
1290
2192
  name: "set-active",
1291
2193
  type: "action",
1292
2194
  jsonSerializable: !0,
1293
- args: [u.object({
1294
- client: u.string().min(1).max(64),
1295
- active: u.boolean()
2195
+ args: [o.object({
2196
+ client: o.string().min(1).max(64),
2197
+ active: o.boolean()
1296
2198
  })],
1297
- returns: u.void(),
2199
+ returns: o.void(),
1298
2200
  handler: ({ client: e, active: n }) => {
1299
2201
  n ? t.lease(`ui:${e}`) : t.release(`ui:${e}`);
1300
2202
  }
@@ -1303,13 +2205,13 @@ function Be(e) {
1303
2205
  name: "open-in-editor",
1304
2206
  type: "action",
1305
2207
  jsonSerializable: !0,
1306
- args: [u.object({
1307
- file: z,
1308
- line: u.number().int().nonnegative().optional()
2208
+ args: [o.object({
2209
+ file: Z,
2210
+ line: o.number().int().nonnegative().optional()
1309
2211
  })],
1310
- returns: u.void(),
2212
+ returns: o.void(),
1311
2213
  handler: ({ file: t, line: n }) => {
1312
- let r = I(e.root(), t);
2214
+ let r = K(e.root(), t);
1313
2215
  e.openInEditor(n ? `${r}:${n}` : r);
1314
2216
  }
1315
2217
  }),
@@ -1317,18 +2219,18 @@ function Be(e) {
1317
2219
  name: "open-reactive-in-editor",
1318
2220
  type: "action",
1319
2221
  jsonSerializable: !0,
1320
- args: [u.object({
1321
- file: z,
1322
- name: u.string().max(256),
1323
- type: u.string().max(32)
2222
+ args: [o.object({
2223
+ file: Z,
2224
+ name: o.string().max(256),
2225
+ type: o.string().max(32)
1324
2226
  })],
1325
- returns: u.void(),
1326
- handler: ({ file: t, name: n, type: r }) => {
1327
- let i = I(e.root(), t), o = 0;
2227
+ returns: o.void(),
2228
+ handler: ({ file: t, name: n, type: i }) => {
2229
+ let a = K(e.root(), t), o = 0;
1328
2230
  try {
1329
- o = Le(a.readFileSync(i, "utf-8"), n, r);
2231
+ o = Rt(r.readFileSync(a, "utf-8"), n, i);
1330
2232
  } catch {}
1331
- e.openInEditor(o > 0 ? `${i}:${o}` : i);
2233
+ e.openInEditor(o > 0 ? `${a}:${o}` : a);
1332
2234
  }
1333
2235
  }),
1334
2236
  l({
@@ -1341,24 +2243,24 @@ function Be(e) {
1341
2243
  name: "get-reactive-graph",
1342
2244
  type: "query",
1343
2245
  jsonSerializable: !0,
1344
- args: [u.object({
1345
- componentId: u.number().int().nonnegative().optional(),
1346
- epoch: u.string().max(200).optional(),
1347
- maxNodes: u.number().int().positive().optional(),
1348
- maxEdges: u.number().int().positive().optional()
2246
+ args: [o.object({
2247
+ componentId: o.number().int().nonnegative().optional(),
2248
+ epoch: o.string().max(200).optional(),
2249
+ maxNodes: o.number().int().positive().optional(),
2250
+ maxEdges: o.number().int().positive().optional()
1349
2251
  }).optional()],
1350
- returns: u.custom(),
2252
+ returns: o.custom(),
1351
2253
  handler: (e) => t.requestReactiveGraph(e ?? {})
1352
2254
  }),
1353
2255
  l({
1354
2256
  name: "get-reactive-summary",
1355
2257
  type: "query",
1356
2258
  jsonSerializable: !0,
1357
- args: [u.object({
1358
- topK: u.number().int().positive().optional(),
1359
- windowMs: u.number().int().positive().optional()
2259
+ args: [o.object({
2260
+ topK: o.number().int().positive().optional(),
2261
+ windowMs: o.number().int().positive().optional()
1360
2262
  }).optional()],
1361
- returns: u.custom(),
2263
+ returns: o.custom(),
1362
2264
  handler: (e) => t.requestReactiveSummary(e ?? {})
1363
2265
  }),
1364
2266
  l({
@@ -1389,8 +2291,8 @@ function Be(e) {
1389
2291
  name: "get-state-timeline-delta",
1390
2292
  type: "query",
1391
2293
  jsonSerializable: !0,
1392
- args: [u.object({ since: u.number().int().nonnegative().optional() })],
1393
- returns: u.custom(),
2294
+ args: [o.object({ since: o.number().int().nonnegative().optional() })],
2295
+ returns: o.custom(),
1394
2296
  handler: ({ since: e }) => t.getStateTimelineDelta(e)
1395
2297
  }),
1396
2298
  l({
@@ -1409,15 +2311,15 @@ function Be(e) {
1409
2311
  name: "get-api-endpoints",
1410
2312
  type: "query",
1411
2313
  jsonSerializable: !0,
1412
- handler: () => Ae(r())
2314
+ handler: () => _t(i())
1413
2315
  }),
1414
2316
  l({
1415
2317
  name: "send-api-request",
1416
2318
  type: "action",
1417
2319
  jsonSerializable: !0,
1418
- args: [u.object({
1419
- url: u.string().max(8192),
1420
- method: u.enum([
2320
+ args: [o.object({
2321
+ url: o.string().max(8192),
2322
+ method: o.enum([
1421
2323
  "GET",
1422
2324
  "POST",
1423
2325
  "PUT",
@@ -1426,11 +2328,11 @@ function Be(e) {
1426
2328
  "HEAD",
1427
2329
  "OPTIONS"
1428
2330
  ]),
1429
- headers: u.string().max(65536),
1430
- body: u.string().max(1e6)
2331
+ headers: o.string().max(65536),
2332
+ body: o.string().max(1e6)
1431
2333
  })],
1432
- returns: u.custom(),
1433
- handler: (t) => je(t, { allowedOrigins: e.serverOrigins() })
2334
+ returns: o.custom(),
2335
+ handler: (t) => yt(t, { allowedOrigins: e.serverOrigins() })
1434
2336
  }),
1435
2337
  l({
1436
2338
  name: "get-compiler-warnings",
@@ -1454,35 +2356,35 @@ function Be(e) {
1454
2356
  name: "inspect-file",
1455
2357
  type: "query",
1456
2358
  jsonSerializable: !0,
1457
- args: [u.object({ file: z })],
1458
- returns: u.custom(),
2359
+ args: [o.object({ file: Z })],
2360
+ returns: o.custom(),
1459
2361
  handler: async ({ file: t }) => {
1460
2362
  let n = {
1461
2363
  source: "",
1462
2364
  compiled: "",
1463
2365
  file: t
1464
- }, r, i;
2366
+ }, i, a;
1465
2367
  try {
1466
- r = I(e.root(), t), i = a.readFileSync(r, "utf-8");
2368
+ i = K(e.root(), t), a = r.readFileSync(i, "utf-8");
1467
2369
  } catch {
1468
2370
  return n;
1469
2371
  }
1470
2372
  if (!e.transformRequest) return {
1471
2373
  ...n,
1472
- source: i
2374
+ source: a
1473
2375
  };
1474
2376
  try {
1475
- let n = await e.transformRequest(r), a = typeof n?.map == "string" ? JSON.parse(n.map) : n?.map;
2377
+ let n = await e.transformRequest(i), r = Wt(n?.map);
1476
2378
  return {
1477
- source: i,
1478
- compiled: n?.code || "",
2379
+ source: a,
2380
+ compiled: n?.code ?? "",
1479
2381
  file: t,
1480
- mappings: a?.mappings,
1481
- sources: a?.sources
2382
+ mappings: r?.mappings,
2383
+ sources: r?.sources
1482
2384
  };
1483
2385
  } catch {
1484
2386
  return {
1485
- source: i,
2387
+ source: a,
1486
2388
  compiled: "// Transform failed",
1487
2389
  file: t
1488
2390
  };
@@ -1493,21 +2395,21 @@ function Be(e) {
1493
2395
  name: "get-module-graph",
1494
2396
  type: "query",
1495
2397
  jsonSerializable: !0,
1496
- handler: () => Fe(e.root(), e.modules())
2398
+ handler: () => Dt(e.root(), e.modules())
1497
2399
  }),
1498
2400
  l({
1499
2401
  name: "get-og-preview",
1500
2402
  type: "action",
1501
2403
  jsonSerializable: !0,
1502
- args: [u.object({ url: u.string().max(8192) })],
1503
- returns: u.custom(),
1504
- handler: ({ url: t }) => Ie(t, { allowedOrigins: e.serverOrigins() })
2404
+ args: [o.object({ url: o.string().max(8192) })],
2405
+ returns: o.custom(),
2406
+ handler: ({ url: t }) => Lt(t, { allowedOrigins: e.serverOrigins() })
1505
2407
  }),
1506
2408
  l({
1507
2409
  name: "get-build-analysis",
1508
2410
  type: "query",
1509
2411
  jsonSerializable: !0,
1510
- handler: () => Ne(e.root())
2412
+ handler: () => wt(e.root())
1511
2413
  }),
1512
2414
  l({
1513
2415
  name: "get-fps",
@@ -1523,717 +2425,106 @@ function Be(e) {
1523
2425
  })
1524
2426
  ];
1525
2427
  }
1526
- function Ve(e) {
2428
+ function Ut(e) {
1527
2429
  return c({
1528
- id: Re,
2430
+ id: J,
1529
2431
  name: "Svelte",
1530
- version: R.version,
1531
- packageName: R.name,
2432
+ version: X.version,
2433
+ packageName: X.name,
1532
2434
  importMetaUrl: import.meta.url,
1533
- homepage: R.homepage,
1534
- description: R.description,
2435
+ homepage: X.homepage,
2436
+ description: X.description,
1535
2437
  icon: "simple-icons:svelte",
1536
- basePath: L,
2438
+ basePath: Y,
1537
2439
  capabilities: {
1538
2440
  dev: !0,
1539
2441
  build: !1
1540
2442
  },
1541
- dock: { category: "framework" },
1542
- clientAssets: ze,
1543
- setup(t) {
1544
- let n = t.scope(Re);
1545
- for (let t of Be(e)) n.rpc.register(t);
1546
- }
1547
- });
1548
- }
1549
- //#endregion
1550
- //#region src/mount.ts
1551
- var He = /* @__PURE__ */ new Set(["0.0.0.0", "::"]), Ue = /* @__PURE__ */ new Set([
1552
- "127.0.0.1",
1553
- "::1",
1554
- "localhost"
1555
- ]);
1556
- function We(e) {
1557
- return e.includes(":") ? `[${e}]` : e;
1558
- }
1559
- function Ge(e, t) {
1560
- return Ue.has(e.address) ? [] : (He.has(e.address) ? Object.values(p.networkInterfaces()).flat().filter((e) => e && !e.internal).map((e) => e.address) : [e.address]).map((n) => `${t}://${We(n)}:${e.port}`);
1561
- }
1562
- function Ke(e, t) {
1563
- let n, r = !1, i = e.httpServer;
1564
- if (e.middlewares.use((e, t, r) => {
1565
- if (n) return n.nodeMiddleware(e, t, r);
1566
- if (e.url?.startsWith("/.svelte-devtools/")) {
1567
- t.statusCode = 503, t.end("Svelte DevTools is starting");
1568
- return;
1569
- }
1570
- r();
1571
- }), !i) {
1572
- let e = m(t, {
1573
- base: L,
1574
- ws: !1,
1575
- sse: !0,
1576
- mcp: !1
1577
- });
1578
- return n = e, async () => {
1579
- n = void 0, await e.close().catch(() => {});
1580
- };
1581
- }
1582
- i.once("listening", () => {
1583
- let a = i.address();
1584
- if (r || !a || typeof a == "string") return;
1585
- let o = e.config.server.https ? "https" : "http", s = `${o}://localhost:${a.port}`;
1586
- n = m(t, {
1587
- base: L,
1588
- server: i,
1589
- mcp: !1,
1590
- origin: `${s}${L}`,
1591
- allowedOrigins: Ge(a, o)
1592
- }), e.config.logger.info(` ➜ Svelte DevTools: ${s}${L}`);
1593
- }), i.once("close", () => {
1594
- r = !0;
1595
- let e = n;
1596
- n = void 0, e?.close().catch(() => {});
1597
- });
1598
- }
1599
- //#endregion
1600
- //#region src/mcp/sessions.ts
1601
- var qe = 1, Je = 5, Ye = 1, Xe = 30;
1602
- function B(e) {
1603
- return {
1604
- renderProfiles: e.getRenderProfiles().map((e) => ({
1605
- componentId: e.componentId,
1606
- file: e.file,
1607
- name: e.name,
1608
- renderCount: e.renderCount,
1609
- totalRenderTime: e.totalRenderTime
1610
- })),
1611
- loadProfilesCount: e.getLoadProfiles().length,
1612
- fpsCount: e.getFpsSamples().length,
1613
- takenAt: Date.now()
1614
- };
1615
- }
1616
- function V(e, t, n) {
1617
- return Math.abs(e) < t ? "unchanged" : n ? e < 0 ? "improved" : "regressed" : e > 0 ? "improved" : "regressed";
1618
- }
1619
- var H = /^s_[0-9a-z]{1,16}_[0-9a-f]{6}$/;
1620
- function U(e) {
1621
- return typeof e == "string" && H.test(e);
1622
- }
1623
- var Ze = class {
1624
- sessions = /* @__PURE__ */ new Map();
1625
- active = null;
1626
- persistDir;
1627
- getters;
1628
- constructor(t) {
1629
- this.persistDir = e.resolve(t.persistDir), this.getters = t.getters;
1630
- }
1631
- start(e, n) {
1632
- if (this.active) throw Error(`A session is already active: ${this.active}. Call end_session before starting a new one.`);
1633
- let r = `s_${Date.now().toString(36)}_${t.randomBytes(3).toString("hex")}`, i = {
1634
- id: r,
1635
- label: e,
1636
- startedAt: Date.now(),
1637
- persist: n,
1638
- startSnapshot: B(this.getters),
1639
- loadProfiles: [],
1640
- fpsSamples: []
1641
- };
1642
- return this.sessions.set(r, i), this.active = r, i;
1643
- }
1644
- recordLoadProfile(e) {
1645
- if (!this.active) return;
1646
- let t = this.sessions.get(this.active);
1647
- t && t.loadProfiles.push(e);
1648
- }
1649
- recordFpsSample(e) {
1650
- if (!this.active) return;
1651
- let t = this.sessions.get(this.active);
1652
- t && t.fpsSamples.push(e);
1653
- }
1654
- end(e) {
1655
- if (!this.active) throw Error("No active session");
1656
- let t = this.sessions.get(this.active);
1657
- if (!t) throw Error("Active session missing from store");
1658
- return t.endedAt = Date.now(), t.endSnapshot = B(this.getters), this.active = null, e === "discard" ? this.sessions.delete(t.id) : (e === "disk" || t.persist) && this.persistToDisk(t), t;
1659
- }
1660
- get(e) {
1661
- return U(e) ? this.sessions.get(e) || this.loadFromDisk(e) : void 0;
1662
- }
1663
- list() {
1664
- let e = /* @__PURE__ */ new Set(), t = [];
1665
- for (let n of this.sessions.values()) e.add(n.id), t.push({
1666
- id: n.id,
1667
- label: n.label,
1668
- startedAt: n.startedAt,
1669
- endedAt: n.endedAt,
1670
- persisted: a.existsSync(this.pathFor(n.id)),
1671
- active: this.active === n.id
1672
- });
1673
- try {
1674
- if (a.existsSync(this.persistDir)) for (let n of a.readdirSync(this.persistDir)) {
1675
- if (!n.endsWith(".json")) continue;
1676
- let r = n.slice(0, -5);
1677
- if (U(r) && !e.has(r)) try {
1678
- let e = JSON.parse(a.readFileSync(this.pathFor(r), "utf-8"));
1679
- if (e?.id !== r) continue;
1680
- t.push({
1681
- id: e.id,
1682
- label: e.label,
1683
- startedAt: e.startedAt,
1684
- endedAt: e.endedAt,
1685
- persisted: !0,
1686
- active: !1
1687
- });
1688
- } catch {}
1689
- }
1690
- } catch {}
1691
- return t.sort((e, t) => t.startedAt - e.startedAt);
1692
- }
1693
- delete(e) {
1694
- if (!U(e)) return !1;
1695
- let t = this.sessions.delete(e), n = !1;
1696
- try {
1697
- let t = this.pathFor(e);
1698
- a.existsSync(t) && (a.unlinkSync(t), n = !0);
1699
- } catch {}
1700
- return this.active === e && (this.active = null), t || n;
1701
- }
1702
- delta(e) {
1703
- let t = this.get(e);
1704
- if (!t) throw Error(`Session not found: ${e}`);
1705
- if (!t.endSnapshot || t.endedAt === void 0) throw Error(`Session ${e} has not been ended yet`);
1706
- let n = new Map(t.startSnapshot.renderProfiles.map((e) => [e.componentId, e])), r = t.endSnapshot.renderProfiles.map((e) => {
1707
- let t = n.get(e.componentId), r = t?.renderCount ?? 0, i = t?.totalRenderTime ?? 0, a = e.renderCount - r, o = e.totalRenderTime - i;
1708
- return {
1709
- componentId: e.componentId,
1710
- file: e.file,
1711
- name: e.name,
1712
- renderCountDelta: a,
1713
- totalRenderTimeDelta: o,
1714
- avgRenderTimeDelta: a > 0 ? o / a : 0
1715
- };
1716
- }).filter((e) => e.renderCountDelta > 0).sort((e, t) => t.totalRenderTimeDelta - e.totalRenderTimeDelta), i = t.loadProfiles.map((e) => e.duration), a = W(i), o = Qe(i, 95), s = t.fpsSamples.map((e) => e.fps), c = W(s), l = s.length ? Math.min(...s) : 0, u = s.filter((e) => e < Xe).length;
1717
- return {
1718
- durationMs: t.endedAt - t.startedAt,
1719
- components: r,
1720
- loadProfiles: {
1721
- count: t.loadProfiles.length,
1722
- avgDuration: a,
1723
- p95Duration: o
1724
- },
1725
- fps: {
1726
- samples: s.length,
1727
- avg: c,
1728
- min: l,
1729
- drops: u
1730
- }
1731
- };
1732
- }
1733
- compare(e, t) {
1734
- let n = this.delta(e), r = this.delta(t), i = this.get(e), a = this.get(t), o = n.components.reduce((e, t) => e + t.totalRenderTimeDelta, 0), s = r.components.reduce((e, t) => e + t.totalRenderTimeDelta, 0), c = s - o, l = r.loadProfiles.avgDuration - n.loadProfiles.avgDuration, u = r.fps.avg - n.fps.avg;
1735
- return {
1736
- a: {
1737
- id: i.id,
1738
- label: i.label
1739
- },
1740
- b: {
1741
- id: a.id,
1742
- label: a.label
1743
- },
1744
- render: {
1745
- totalRenderTimeDeltaA: o,
1746
- totalRenderTimeDeltaB: s,
1747
- diff: c,
1748
- verdict: V(c, qe, !0)
1749
- },
1750
- load: {
1751
- avgA: n.loadProfiles.avgDuration,
1752
- avgB: r.loadProfiles.avgDuration,
1753
- diff: l,
1754
- verdict: V(l, Je, !0)
1755
- },
1756
- fps: {
1757
- avgA: n.fps.avg,
1758
- avgB: r.fps.avg,
1759
- diff: u,
1760
- verdict: V(u, Ye, !1)
1761
- }
1762
- };
1763
- }
1764
- pathFor(t) {
1765
- if (!U(t)) throw Error("Invalid session id");
1766
- let n = e.resolve(this.persistDir, `${t}.json`);
1767
- if (e.dirname(n) !== this.persistDir) throw Error("Invalid session id");
1768
- return n;
1769
- }
1770
- persistToDisk(e) {
1771
- try {
1772
- a.mkdirSync(this.persistDir, { recursive: !0 }), a.writeFileSync(this.pathFor(e.id), JSON.stringify(e, null, 2), { mode: 384 });
1773
- } catch {}
1774
- }
1775
- loadFromDisk(e) {
1776
- try {
1777
- let t = a.readFileSync(this.pathFor(e), "utf-8"), n = JSON.parse(t);
1778
- return n?.id === e ? n : void 0;
1779
- } catch {
1780
- return;
1781
- }
1782
- }
1783
- };
1784
- function W(e) {
1785
- return e.length ? e.reduce((e, t) => e + t, 0) / e.length : 0;
1786
- }
1787
- function Qe(e, t) {
1788
- if (!e.length) return 0;
1789
- let n = [...e].sort((e, t) => e - t);
1790
- return n[Math.min(n.length - 1, Math.floor(t / 100 * n.length))];
1791
- }
1792
- //#endregion
1793
- //#region src/mcp/issues.ts
1794
- var G = {
1795
- avgRenderTimeMs: 4,
1796
- renderCount: 30,
1797
- loadDurationMs: 200,
1798
- fpsDropThreshold: 40,
1799
- effectMaxDeps: 8
1800
- };
1801
- function $e(e, t = {}) {
1802
- let n = {
1803
- ...G,
1804
- ...t
1805
- }, r = [];
1806
- for (let t of e.renderProfiles) {
1807
- let e = t.renderCount > 0 ? t.totalRenderTime / t.renderCount : 0;
1808
- e >= n.avgRenderTimeMs && r.push({
1809
- id: `slow-render:${t.file}:${t.componentId}`,
1810
- kind: "slow-component-render",
1811
- severity: e >= n.avgRenderTimeMs * 4 ? "high" : e >= n.avgRenderTimeMs * 2 ? "medium" : "low",
1812
- summary: `${t.name} averages ${e.toFixed(2)}ms per render (${t.renderCount} renders)`,
1813
- file: t.file,
1814
- metric: {
1815
- avgRenderTimeMs: q(e),
1816
- renderCount: t.renderCount,
1817
- totalRenderTimeMs: q(t.totalRenderTime)
1818
- },
1819
- suggestedTool: "get_render_profile"
1820
- }), t.renderCount >= n.renderCount && r.push({
1821
- id: `over-render:${t.file}:${t.componentId}`,
1822
- kind: "over-rendered-component",
1823
- severity: t.renderCount >= n.renderCount * 8 ? "high" : t.renderCount >= n.renderCount * 3 ? "medium" : "low",
1824
- summary: `${t.name} rendered ${t.renderCount} times`,
1825
- file: t.file,
1826
- metric: {
1827
- renderCount: t.renderCount,
1828
- avgRenderTimeMs: q(e)
1829
- },
1830
- suggestedTool: "get_component_hotspots"
1831
- });
1832
- }
1833
- for (let t of e.loadProfiles) t.duration >= n.loadDurationMs && r.push({
1834
- id: `slow-load:${t.route}:${t.timestamp}`,
1835
- kind: "slow-load",
1836
- severity: t.duration >= n.loadDurationMs * 5 ? "high" : t.duration >= n.loadDurationMs * 2 ? "medium" : "low",
1837
- summary: `${t.type} load for ${t.route} took ${t.duration.toFixed(0)}ms`,
1838
- file: t.file,
1839
- metric: {
1840
- durationMs: q(t.duration),
1841
- dataSizeBytes: t.dataSize
1842
- },
1843
- suggestedTool: "get_load_waterfall"
1844
- });
1845
- let i = e.fpsSamples.filter((e) => e.fps < n.fpsDropThreshold);
1846
- if (i.length > 0) {
1847
- let t = Math.min(...i.map((e) => e.fps));
1848
- r.push({
1849
- id: `fps-drops:${e.fpsSamples[0]?.timestamp ?? 0}`,
1850
- kind: "fps-drop",
1851
- severity: t < 15 ? "high" : t < 30 ? "medium" : "low",
1852
- summary: `${i.length} FPS samples below ${n.fpsDropThreshold} (min ${t})`,
1853
- metric: {
1854
- dropCount: i.length,
1855
- minFps: t,
1856
- threshold: n.fpsDropThreshold
1857
- },
1858
- suggestedTool: "get_fps_drops"
1859
- });
1860
- }
1861
- let a = /* @__PURE__ */ new Map();
1862
- for (let t of e.reactiveGraph.edges) a.set(t.from, (a.get(t.from) ?? 0) + 1);
1863
- let o = /* @__PURE__ */ new Map();
1864
- for (let t of e.reactiveGraph.edges) o.set(t.to, (o.get(t.to) ?? 0) + 1);
1865
- for (let t of e.reactiveGraph.nodes) {
1866
- if (t.type === "effect") {
1867
- let e = o.get(t.id) ?? 0;
1868
- e >= n.effectMaxDeps && r.push({
1869
- id: `effect-deps:${t.id}`,
1870
- kind: "effect-overconnected",
1871
- severity: e >= n.effectMaxDeps * 3 ? "high" : e >= n.effectMaxDeps * 2 ? "medium" : "low",
1872
- summary: `effect "${t.name}" depends on ${e} reactive values`,
1873
- file: t.componentFile,
1874
- metric: { depCount: e },
1875
- suggestedTool: "get_reactive_graph_problems"
1876
- });
1877
- }
1878
- if (t.type === "derived") {
1879
- let e = a.get(t.id) ?? 0;
1880
- e === 0 && (o.get(t.id) ?? 0) > 0 && r.push({
1881
- id: `derived-orphan:${t.id}`,
1882
- kind: "derived-orphan",
1883
- severity: "low",
1884
- summary: `derived "${t.name}" has dependencies but is unused`,
1885
- file: t.componentFile,
1886
- metric: { fanout: e },
1887
- suggestedTool: "get_reactive_graph_problems"
1888
- });
2443
+ dock: { category: "framework" },
2444
+ clientAssets: Vt,
2445
+ setup(t) {
2446
+ let n = t.scope(J);
2447
+ for (let t of Ht(e)) n.rpc.register(t);
1889
2448
  }
1890
- }
1891
- return r.sort(et);
1892
- }
1893
- var K = {
1894
- high: 0,
1895
- medium: 1,
1896
- low: 2
1897
- };
1898
- function et(e, t) {
1899
- return K[e.severity] - K[t.severity];
1900
- }
1901
- function q(e) {
1902
- return Math.round(e * 100) / 100;
2449
+ });
1903
2450
  }
1904
- function tt(e, t = {}) {
1905
- let n = {
1906
- ...G,
1907
- ...t
1908
- }, r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
1909
- for (let t of e.edges) r.set(t.to, (r.get(t.to) ?? 0) + 1), i.set(t.from, (i.get(t.from) ?? 0) + 1);
1910
- let a = [], o = [], s = [];
1911
- for (let t of e.nodes) {
1912
- let e = r.get(t.id) ?? 0, c = i.get(t.id) ?? 0;
1913
- t.type === "effect" && e >= n.effectMaxDeps && a.push({
1914
- id: t.id,
1915
- name: t.name,
1916
- file: t.componentFile,
1917
- depCount: e
1918
- }), t.type === "derived" && c === 0 && e > 0 && o.push({
1919
- id: t.id,
1920
- name: t.name,
1921
- file: t.componentFile
1922
- }), e === 0 && c === 0 && s.push({
1923
- id: t.id,
1924
- name: t.name,
1925
- type: t.type,
1926
- file: t.componentFile
1927
- });
1928
- }
2451
+ function Wt(e) {
2452
+ if (typeof e != "string") return e ?? void 0;
2453
+ let t = JSON.parse(e);
2454
+ if (typeof t != "object" || !t) return;
2455
+ let { mappings: n, sources: r } = t;
1929
2456
  return {
1930
- effects: a,
1931
- orphanDeriveds: o,
1932
- isolatedNodes: s
2457
+ mappings: typeof n == "string" ? n : void 0,
2458
+ sources: Array.isArray(r) && r.every((e) => typeof e == "string") ? r : void 0
1933
2459
  };
1934
2460
  }
1935
- var J = {
1936
- default: 2048,
1937
- max: 32768
1938
- };
1939
- function Y(e, t) {
1940
- let n;
1941
- try {
1942
- n = JSON.stringify(e);
1943
- } catch {
1944
- return { omitted: "not serializable" };
1945
- }
1946
- return n === void 0 || n.length <= t ? e : {
1947
- omitted: "too large",
1948
- chars: n.length,
1949
- preview: n.slice(0, Math.min(200, t))
1950
- };
2461
+ //#endregion
2462
+ //#region src/server/mount.ts
2463
+ var Gt = /* @__PURE__ */ new Set(["0.0.0.0", "::"]), Kt = /* @__PURE__ */ new Set([
2464
+ "127.0.0.1",
2465
+ "::1",
2466
+ "localhost"
2467
+ ]);
2468
+ function qt(e) {
2469
+ return e.includes(":") ? `[${e}]` : e;
1951
2470
  }
1952
- var X = u.string().max(64).regex(H, "not a session id"), Z = (e) => ({ content: [{
1953
- type: "text",
1954
- text: typeof e == "string" ? e : JSON.stringify(e, null, 2)
1955
- }] });
1956
- function nt(e) {
1957
- let t = new ee({
1958
- name: "vite-devtools-svelte",
1959
- version: "0.1.0"
1960
- });
1961
- if (t.registerTool("list_performance_issues", {
1962
- title: "List performance issues",
1963
- description: "Cross-cuts render/reactive/load/fps metrics and returns ranked issues. The entry point for AI-driven performance audits. Each issue carries `suggestedTool` naming the detail tool to call next.",
1964
- inputSchema: {
1965
- avgRenderTimeMs: u.number().optional(),
1966
- renderCount: u.number().optional(),
1967
- loadDurationMs: u.number().optional(),
1968
- fpsDropThreshold: u.number().optional(),
1969
- effectMaxDeps: u.number().optional()
1970
- }
1971
- }, async (t) => {
1972
- let n = t, r = await e.getReactiveGraph(), i = $e({
1973
- renderProfiles: e.getRenderProfiles(),
1974
- reactiveGraph: r,
1975
- loadProfiles: e.getLoadProfiles(),
1976
- fpsSamples: e.getFpsSamples()
1977
- }, n);
1978
- return Z({
1979
- count: i.length,
1980
- issues: i
1981
- });
1982
- }), t.registerTool("get_component_hotspots", {
1983
- title: "Component render hotspots",
1984
- description: "Top components by total render time, with render count and per-render average.",
1985
- inputSchema: { topN: u.number().int().min(1).max(200).optional() }
1986
- }, async ({ topN: t = 20 }) => Z([...e.getRenderProfiles()].map((e) => ({
1987
- file: e.file,
1988
- name: e.name,
1989
- componentId: e.componentId,
1990
- renderCount: e.renderCount,
1991
- totalRenderTimeMs: Q(e.totalRenderTime),
1992
- avgRenderTimeMs: Q(e.renderCount > 0 ? e.totalRenderTime / e.renderCount : 0),
1993
- lastRenderTimeMs: Q(e.lastRenderTime),
1994
- lastRenderAt: e.lastRenderAt
1995
- })).sort((e, t) => t.totalRenderTimeMs - e.totalRenderTimeMs).slice(0, t))), t.registerTool("get_reactive_graph_problems", {
1996
- title: "Reactive graph problems",
1997
- description: "Classified reactive graph issues: over-connected effects, orphan deriveds, isolated nodes. Returns categories instead of the full graph.",
1998
- inputSchema: { effectMaxDeps: u.number().int().min(1).optional() }
1999
- }, async ({ effectMaxDeps: t }) => Z(tt(await e.getReactiveGraph(), { effectMaxDeps: t }))), t.registerTool("get_load_waterfall", {
2000
- title: "SvelteKit load waterfall",
2001
- description: "Load profiles grouped by route, with timing and data size. Optionally filtered by route.",
2002
- inputSchema: { route: u.string().optional() }
2003
- }, async ({ route: t }) => {
2004
- let n = e.getLoadProfiles();
2005
- t && (n = n.filter((e) => e.route === t));
2006
- let r = /* @__PURE__ */ new Map();
2007
- for (let e of n) {
2008
- let t = r.get(e.route) ?? [];
2009
- t.push(e), r.set(e.route, t);
2010
- }
2011
- return Z([...r.entries()].map(([e, t]) => {
2012
- let n = t.map((e) => e.duration);
2013
- return {
2014
- route: e,
2015
- file: t[0]?.file,
2016
- count: t.length,
2017
- avgDuration: Q(rt(n)),
2018
- maxDuration: Q(Math.max(...n)),
2019
- totalDataBytes: t.reduce((e, t) => e + t.dataSize, 0),
2020
- samples: t
2021
- };
2022
- }).sort((e, t) => t.avgDuration - e.avgDuration));
2023
- }), t.registerTool("get_fps_drops", {
2024
- title: "FPS drops",
2025
- description: "Samples whose FPS fell below `threshold`. Returns timestamp + fps for each.",
2026
- inputSchema: {
2027
- threshold: u.number().min(1).max(120).optional(),
2028
- sinceMs: u.number().optional()
2029
- }
2030
- }, async ({ threshold: t = 40, sinceMs: n }) => {
2031
- let r = e.getFpsSamples();
2032
- if (n !== void 0) {
2033
- let e = Date.now() - n;
2034
- r = r.filter((t) => t.timestamp >= e);
2035
- }
2036
- let i = r.filter((e) => e.fps < t);
2037
- return Z({
2038
- threshold: t,
2039
- sampleCount: r.length,
2040
- dropCount: i.length,
2041
- minFps: i.length ? Math.min(...i.map((e) => e.fps)) : null,
2042
- drops: i
2043
- });
2044
- }), t.registerTool("get_render_profile", {
2045
- title: "Render profile for a specific file",
2046
- description: "Returns render profile entries matching the given component file (substring match).",
2047
- inputSchema: { file: u.string() }
2048
- }, async ({ file: t }) => Z(e.getRenderProfiles().filter((e) => e.file.includes(t)).map((e) => ({
2049
- ...e,
2050
- totalRenderTimeMs: Q(e.totalRenderTime),
2051
- avgRenderTimeMs: Q(e.renderCount > 0 ? e.totalRenderTime / e.renderCount : 0)
2052
- })))), t.registerTool("get_project_info", {
2053
- title: "Project info",
2054
- description: "Package name/version, Svelte / SvelteKit / Vite versions, dependency lists.",
2055
- inputSchema: {}
2056
- }, async () => Z(e.getProject())), t.registerTool("get_routes", {
2057
- title: "SvelteKit routes",
2058
- description: "Static analysis of the SvelteKit routes tree.",
2059
- inputSchema: {}
2060
- }, async () => Z(e.getRoutes())), t.registerTool("get_live_components", {
2061
- title: "Currently mounted components",
2062
- description: "Component instances with file, parent, mounted status as currently mounted in the browser (an array, parents first). With `includeMeta: true` the answer is `{ epoch, total, captured, truncated, components }` instead, limited to `limit` (default 1000): component ids are only valid within that `epoch` (one page load), so pass both to get_reactive_scope.",
2063
- inputSchema: {
2064
- includeMeta: u.boolean().optional(),
2065
- limit: u.number().int().min(1).max(5e4).optional()
2066
- }
2067
- }, async ({ includeMeta: t, limit: n }) => {
2068
- if (!t || !e.getLiveSnapshot) {
2069
- let t = e.getLiveComponents();
2070
- return Z(n === void 0 ? t : t.slice(0, n));
2471
+ function Jt(e, t) {
2472
+ return Kt.has(e.address) ? [] : (Gt.has(e.address) ? Object.values(p.networkInterfaces()).flat().filter((e) => e && !e.internal).map((e) => e.address) : [e.address]).map((n) => `${t}://${qt(n)}:${e.port}`);
2473
+ }
2474
+ function Yt(e, t, { auth: n = !0 } = {}) {
2475
+ let r, i = !1, a = e.httpServer;
2476
+ if (e.middlewares.use((e, t, n) => {
2477
+ if (r) return r.nodeMiddleware(e, t, n);
2478
+ if (e.url?.startsWith("/.svelte-devtools/")) {
2479
+ t.statusCode = 503, t.end("Svelte DevTools is starting");
2480
+ return;
2071
2481
  }
2072
- let r = e.getLiveSnapshot(), i = n ?? 1e3;
2073
- return Z({
2074
- epoch: r.epoch,
2075
- total: r.total,
2076
- captured: r.components.length,
2077
- truncated: r.total > r.components.length || r.components.length > i,
2078
- components: r.components.slice(0, i)
2079
- });
2080
- }), t.registerTool("get_component_relations", {
2081
- title: "Component import graph",
2082
- description: "Static import relations between .svelte components.",
2083
- inputSchema: {}
2084
- }, async () => Z(e.getComponentRelations())), e.getReactiveSummary) {
2085
- let n = e.getReactiveSummary;
2086
- t.registerTool("get_reactive_summary", {
2087
- title: "Reactive overview (top components)",
2088
- description: "Busiest component instances from runtime counters over all instances, without capturing the graph. Counts are sampled state changes (at most one per state per 200 ms) and renders within the window, not rates. Only state created during component init is tracked. `rows` + `other` add up to the totals; null means unknown. Use get_reactive_scope with a componentId to look at one instance. The same request is answered from a cache for up to 1 s; `window.until` says when the answer was computed.",
2089
- inputSchema: {
2090
- topK: u.number().int().min(1).max(200).optional(),
2091
- windowMs: u.number().int().min(1e3).max(6e4).optional()
2092
- }
2093
- }, async ({ topK: e, windowMs: t }) => Z(await n({
2094
- topK: e,
2095
- windowMs: t
2096
- })));
2097
- }
2098
- if (e.getReactiveScope) {
2099
- let n = e.getReactiveScope;
2100
- t.registerTool("get_reactive_scope", {
2101
- title: "Reactive graph of one component",
2102
- description: "$state/$derived/$effect nodes of one component instance and their direct neighbours, built in the app within the caps. Edges mean 'can affect' (current dependencies), not a recorded cause. `componentId` requires the `epoch` it came from (get_live_components with includeMeta): after a reload the answer is empty with staleReason 'epoch-changed' instead of another instance. Omit componentId only for the whole-app graph (capped; see total/truncated). The same request may be answered from a cache for up to 1 s; `computedAt` says when the app built the graph (null when unknown or for an empty fallback). `stale: true` only marks a fallback after the app did not answer (an earlier answer with its own computedAt, or empty).",
2103
- inputSchema: {
2104
- componentId: u.number().int().nonnegative().optional(),
2105
- epoch: u.string().max(200).optional(),
2106
- maxNodes: u.number().int().min(1).max(5e3).optional(),
2107
- maxEdges: u.number().int().min(1).max(2e4).optional()
2108
- }
2109
- }, async ({ componentId: e, epoch: t, maxNodes: r, maxEdges: i }) => e !== void 0 && t === void 0 ? {
2110
- content: [{
2111
- type: "text",
2112
- text: "componentId requires epoch (from get_live_components with includeMeta: true)"
2113
- }],
2114
- isError: !0
2115
- } : Z(await n({
2116
- componentId: e,
2117
- epoch: t,
2118
- maxNodes: r,
2119
- maxEdges: i
2120
- })));
2121
- }
2122
- if (e.getStateTimelineDelta) {
2123
- let n = e.getStateTimelineDelta;
2124
- t.registerTool("get_state_timeline", {
2125
- title: "State changes since a cursor",
2126
- description: "Sampled $state changes (200 ms) after `since` (the cursor from the previous call). Contains values of state in the running app. `reset: true` means the cursor was stale and this is the whole buffer. At most `limit` newest entries are returned; `omitted` counts older ones in the range that were left out. Values larger than `maxValueChars` (JSON) are replaced by a size summary. Timestamps are detection times, so order within about a second is not causal.",
2127
- inputSchema: {
2128
- since: u.number().int().nonnegative().optional(),
2129
- limit: u.number().int().min(1).max(500).optional(),
2130
- maxValueChars: u.number().int().min(16).max(J.max).optional()
2131
- }
2132
- }, async ({ since: e, limit: t, maxValueChars: r }) => {
2133
- let i = n(e), a = t ?? 100, o = r ?? J.default, s = Math.max(0, i.changes.length - a), c = i.changes.slice(s).map((e) => ({
2134
- ...e,
2135
- oldValue: Y(e.oldValue, o),
2136
- newValue: Y(e.newValue, o)
2137
- }));
2138
- return Z({
2139
- ...i,
2140
- changes: c,
2141
- omitted: s,
2142
- maxValueChars: o
2143
- });
2482
+ n();
2483
+ }), !a) {
2484
+ let e = m(t, {
2485
+ base: Y,
2486
+ ws: !1,
2487
+ sse: !0,
2488
+ mcp: !1,
2489
+ auth: n
2144
2490
  });
2491
+ return r = e, async () => {
2492
+ r = void 0, await e.close().catch(() => {});
2493
+ };
2145
2494
  }
2146
- if (e.getCaptureInfo) {
2147
- let n = e.getCaptureInfo;
2148
- t.registerTool("get_capture_info", {
2149
- title: "What the DevTools hold versus what the app reported",
2150
- description: "Per dataset: captured count, total (null = unknown), truncated, selection policy and dropped counts by reason. Read this before drawing conclusions from capped data.",
2151
- inputSchema: {}
2152
- }, async () => Z(n()));
2153
- }
2154
- return t.registerTool("start_session", {
2155
- title: "Start measurement session",
2156
- description: "Begin capturing metrics under a labelled session. Required before compare_sessions. Set `persist:true` to write to disk on end; otherwise the session lives in memory only.",
2157
- inputSchema: {
2158
- label: u.string(),
2159
- persist: u.boolean().optional()
2160
- }
2161
- }, async ({ label: t, persist: n = !1 }) => {
2162
- let r = e.sessions.start(t, n);
2163
- return Z({
2164
- id: r.id,
2165
- label: r.label,
2166
- startedAt: r.startedAt,
2167
- persist: r.persist
2168
- });
2169
- }), t.registerTool("end_session", {
2170
- title: "End current measurement session",
2171
- description: "Closes the active session and returns its delta. `keep` decides disposal: \"memory\" keeps it for this dev-server lifetime, \"disk\" writes to .vite-devtools-svelte/sessions/, \"discard\" deletes it.",
2172
- inputSchema: { keep: u.enum([
2173
- "memory",
2174
- "disk",
2175
- "discard"
2176
- ]).optional() }
2177
- }, async ({ keep: t = "memory" }) => {
2178
- let n = e.sessions.end(t), r = n.endedAt ? e.sessions.delta(n.id) : null;
2179
- return Z({
2180
- id: n.id,
2181
- label: n.label,
2182
- startedAt: n.startedAt,
2183
- endedAt: n.endedAt,
2184
- keep: t,
2185
- delta: r
2186
- });
2187
- }), t.registerTool("compare_sessions", {
2188
- title: "Compare two sessions",
2189
- description: "Diff render / load / fps metrics between two ended sessions. Each section carries `verdict`: improved | regressed | unchanged.",
2190
- inputSchema: {
2191
- a: X,
2192
- b: X
2193
- }
2194
- }, async ({ a: t, b: n }) => Z(e.sessions.compare(t, n))), t.registerTool("list_sessions", {
2195
- title: "List sessions",
2196
- description: "In-memory + on-disk sessions, most recent first.",
2197
- inputSchema: {}
2198
- }, async () => Z(e.sessions.list())), t.registerTool("load_session", {
2199
- title: "Load a session by id",
2200
- description: "Returns the full session record (including delta if ended) by id.",
2201
- inputSchema: { id: X }
2202
- }, async ({ id: t }) => {
2203
- let n = e.sessions.get(t);
2204
- if (!n) return Z({ error: `Session not found: ${t}` });
2205
- let r = n.endedAt ? e.sessions.delta(t) : null;
2206
- return Z({
2207
- ...n,
2208
- delta: r
2209
- });
2210
- }), t.registerTool("delete_session", {
2211
- title: "Delete a session",
2212
- description: "Removes a session from memory and disk.",
2213
- inputSchema: { id: X }
2214
- }, async ({ id: t }) => Z({ deleted: e.sessions.delete(t) })), t;
2215
- }
2216
- function rt(e) {
2217
- return e.length ? e.reduce((e, t) => e + t, 0) / e.length : 0;
2218
- }
2219
- function Q(e) {
2220
- return Math.round(e * 100) / 100;
2495
+ a.once("listening", () => {
2496
+ let o = a.address();
2497
+ if (i || !o || typeof o == "string") return;
2498
+ let s = e.config.server.https ? "https" : "http", c = `${s}://localhost:${o.port}`;
2499
+ r = m(t, {
2500
+ base: Y,
2501
+ server: a,
2502
+ mcp: !1,
2503
+ auth: n,
2504
+ origin: `${c}${Y}`,
2505
+ allowedOrigins: Jt(o, s)
2506
+ }), e.config.logger.info(` ➜ Svelte DevTools: ${c}${Y}`);
2507
+ }), a.once("close", () => {
2508
+ i = !0;
2509
+ let e = r;
2510
+ r = void 0, e?.close().catch(() => {});
2511
+ });
2221
2512
  }
2222
- var it = [".svelte-kit/generated/server/internal.js", ".svelte-kit/generated/dev/server.js"], at = "templates: {", ot = `${ne}embedded.js`, st = `<script type=\\"module\\" src=\\"${ot}\\"><\/script>`, ct = "</body>";
2223
- function lt(e) {
2224
- if (!e.includes("templates: {") || !e.includes(ct) || e.includes(ot)) return null;
2225
- let t = e.indexOf(at), n = e.indexOf(ct, t);
2226
- return n === -1 ? null : e.slice(0, n) + st + e.slice(n);
2513
+ var Xt = [".svelte-kit/generated/server/internal.js", ".svelte-kit/generated/dev/server.js"], Zt = "templates: {", Qt = `${h}embedded.js`, $t = `<script type=\\"module\\" src=\\"${Qt}\\"><\/script>`, Q = "</body>";
2514
+ function en(e) {
2515
+ if (!e.includes("templates: {") || !e.includes(Q) || e.includes(Qt)) return null;
2516
+ let t = e.indexOf(Zt), n = e.indexOf("app:", t), r = n === -1 ? -1 : e.indexOf("\n", n), i = n === -1 ? -1 : e.lastIndexOf(Q, r === -1 ? e.length : r), a = i > n ? i : e.indexOf(Q, t);
2517
+ return a === -1 ? null : e.slice(0, a) + $t + e.slice(a);
2227
2518
  }
2228
- function ut(e) {
2519
+ function tn(e) {
2229
2520
  return {
2230
2521
  name: "vite-devtools-svelte:sveltekit-template-injector",
2231
2522
  enforce: "post",
2232
2523
  apply: (e, t) => t.command === "serve" && !t.isSsrBuild,
2233
2524
  transform(t, n) {
2234
- if (!it.some((e) => n.endsWith(e)) || !e()) return;
2235
- let r = lt(t);
2236
- if (r !== null) return {
2525
+ if (!Xt.some((e) => n.endsWith(e)) || !e()) return null;
2526
+ let r = en(t);
2527
+ return r === null ? null : {
2237
2528
  code: r,
2238
2529
  map: null
2239
2530
  };
@@ -2242,8 +2533,13 @@ function ut(e) {
2242
2533
  }
2243
2534
  //#endregion
2244
2535
  //#region src/plugin.ts
2245
- var dt = "vite:devtools", $ = Symbol.for("vite-devtools-svelte:warn-sink"), ft = 0;
2246
- function pt(e) {
2536
+ var nn = "vite:devtools", $ = Symbol.for("vite-devtools-svelte:warn-sink"), rn = 0;
2537
+ function an(t, n) {
2538
+ if (typeof t != "string") return !1;
2539
+ let r = Buffer.from(t), i = Buffer.from(n);
2540
+ return r.length === i.length && e.timingSafeEqual(r, i);
2541
+ }
2542
+ function on(e) {
2247
2543
  let t = [];
2248
2544
  for (let n of Object.values(e.environments ?? {})) {
2249
2545
  let e = n.moduleGraph;
@@ -2255,124 +2551,126 @@ function pt(e) {
2255
2551
  }
2256
2552
  return t;
2257
2553
  }
2258
- function mt(r = {}) {
2259
- let { componentTracking: i = !0 } = r, a, o, s, c = !1, l = t.randomUUID(), u = null;
2260
- function d() {
2261
- return u ||= new Ze({
2262
- persistDir: e.join(s, "node_modules", ".vite-devtools-svelte", "sessions"),
2554
+ function sn(r = {}) {
2555
+ let { componentTracking: i = !0, clientAuth: o = !0 } = r, s, c, l, u = !1, d = e.randomUUID(), f = null;
2556
+ function p() {
2557
+ return f ??= new je({
2558
+ persistDir: t.join(l, "node_modules", ".vite-devtools-svelte", "sessions"),
2263
2559
  getters: {
2264
- getRenderProfiles: () => f.renderProfiles,
2265
- getLoadProfiles: () => f.loadProfiles,
2266
- getFpsSamples: () => f.fpsSamples
2560
+ getRenderProfiles: () => m.renderProfiles,
2561
+ getLoadProfiles: () => m.loadProfiles,
2562
+ getFpsSamples: () => m.fpsSamples
2267
2563
  }
2268
- }), u;
2269
- }
2270
- let f = new we({
2271
- onFpsSample: (e) => d().recordFpsSample(e),
2272
- onLoadProfile: (e) => d().recordLoadProfile(e)
2273
- }), p = Ve({
2274
- collector: f,
2275
- root: () => s,
2276
- publicBase: () => a?.base ?? "/",
2277
- modules: () => o ? pt(o) : [],
2278
- transformRequest: (e) => o ? o.transformRequest(e) : Promise.resolve(null),
2564
+ }), f;
2565
+ }
2566
+ let m = new rt({
2567
+ onFpsSample: (e) => p().recordFpsSample(e),
2568
+ onLoadProfile: (e) => p().recordLoadProfile(e)
2569
+ }), h = Ut({
2570
+ collector: m,
2571
+ root: () => l,
2572
+ publicBase: () => s?.base ?? "/",
2573
+ modules: () => c ? on(c) : [],
2574
+ transformRequest: (e) => c ? c.transformRequest(e) : Promise.resolve(null),
2279
2575
  serverOrigins: () => {
2280
- let e = o?.resolvedUrls;
2576
+ let e = c?.resolvedUrls;
2281
2577
  return e ? [...e.local, ...e.network].map((e) => new URL(e).origin) : [];
2282
2578
  },
2283
2579
  openInEditor: (e) => n(e)
2284
- }), m = [];
2580
+ }), _ = [];
2285
2581
  return [
2286
2582
  {
2287
2583
  name: "vite-devtools-svelte",
2288
2584
  enforce: "pre",
2289
2585
  apply: "serve",
2290
- api: { getDevtoolsToken: () => l },
2586
+ api: { getDevtoolsToken: () => d },
2291
2587
  configResolved(e) {
2292
- a = e, s = a.root, c = a.plugins.some((e) => e.name === dt);
2588
+ s = e, l = s.root, u = s.plugins.some((e) => e.name === nn);
2293
2589
  },
2294
2590
  configureServer(e) {
2295
- o = e;
2296
- let t = ++ft;
2297
- if (f.attach(e.hot), e.httpServer?.once("close", () => {
2298
- o === e && (f.detach(), o = void 0);
2299
- }), !c) {
2300
- let n = Ke(e, p);
2301
- n && m.push({
2591
+ c = e;
2592
+ let t = ++rn;
2593
+ if (m.attach(e.hot), e.httpServer?.once("close", () => {
2594
+ c === e && (m.detach(), c = void 0);
2595
+ }), !u) {
2596
+ let n = Yt(e, h, { auth: o });
2597
+ n && _.push({
2302
2598
  generation: t,
2303
2599
  dispose: n
2304
2600
  });
2305
2601
  }
2306
- let n = () => nt({
2307
- getProject: () => v(s),
2308
- getRoutes: () => re(v(s).routesDir),
2309
- getLiveComponents: () => f.liveComponents,
2310
- getLiveSnapshot: () => f.liveSnapshot,
2311
- getComponentRelations: () => b(s),
2312
- getRenderProfiles: () => f.renderProfiles,
2313
- getReactiveGraph: () => f.requestReactiveGraph(),
2314
- getLoadProfiles: () => f.loadProfiles,
2315
- getFpsSamples: () => f.fpsSamples,
2316
- sessions: d(),
2317
- getReactiveSummary: (e) => f.requestReactiveSummary(e),
2318
- getReactiveScope: (e) => f.requestReactiveGraph(e),
2319
- getStateTimelineDelta: (e) => f.getStateTimelineDelta(e),
2320
- getCaptureInfo: () => f.getCaptureInfo()
2602
+ let n = () => Re({
2603
+ getProject: () => y(l),
2604
+ getRoutes: () => de(y(l).routesDir),
2605
+ getLiveComponents: () => m.liveComponents,
2606
+ getLiveSnapshot: () => m.liveSnapshot,
2607
+ getComponentRelations: () => g(l),
2608
+ getRenderProfiles: () => m.renderProfiles,
2609
+ getReactiveGraph: () => m.requestReactiveGraph(),
2610
+ getLoadProfiles: () => m.loadProfiles,
2611
+ getFpsSamples: () => m.fpsSamples,
2612
+ sessions: p(),
2613
+ getReactiveSummary: (e) => m.requestReactiveSummary(e),
2614
+ getReactiveScope: (e) => m.requestReactiveGraph(e),
2615
+ getStateTimelineDelta: (e) => m.getStateTimelineDelta(e),
2616
+ getCaptureInfo: () => m.getCaptureInfo()
2321
2617
  });
2322
2618
  e.httpServer?.once("listening", () => {
2323
2619
  try {
2324
2620
  let t = e.httpServer?.address();
2325
2621
  if (!t || typeof t == "string") return;
2326
- let n = `claude mcp add --transport http svelte ${`${e.config.server?.https ? "https" : "http"}://${t.address === "::" || t.address === "0.0.0.0" || t.address === "::1" || t.address === "127.0.0.1" ? "localhost" : t.family === "IPv6" ? `[${t.address}]` : t.address}:${t.port}/__svelte-devtools/mcp`} --header x-svelte-devtools-token:${l}`;
2622
+ let n = `claude mcp add --transport http svelte ${`${e.config.server?.https ? "https" : "http"}://${t.address === "::" || t.address === "0.0.0.0" || t.address === "::1" || t.address === "127.0.0.1" ? "localhost" : t.family === "IPv6" ? `[${t.address}]` : t.address}:${t.port}/__svelte-devtools/mcp`} --header x-svelte-devtools-token:${d}`;
2327
2623
  e.config.logger.info(""), e.config.logger.info(" svelte-devtools MCP ready — register with Claude Code:"), e.config.logger.info(` ${n}`), e.config.logger.info("");
2328
2624
  } catch {}
2329
- }), e.middlewares.use("/__svelte-devtools/mcp", async (t, r) => {
2330
- let i = t.headers["x-svelte-devtools-token"];
2331
- if ((Array.isArray(i) ? i[0] : i) !== l) {
2625
+ });
2626
+ let r = async (t, r) => {
2627
+ if (!an(t.headers["x-svelte-devtools-token"], d)) {
2332
2628
  r.statusCode = 403, r.end("Forbidden");
2333
2629
  return;
2334
2630
  }
2335
- f.lease("mcp", 6e4) && await f.waitForSnapshot(1e3);
2336
- let a = n(), o = new te({
2631
+ m.lease("mcp", 6e4) && await m.waitForSnapshot(1e3);
2632
+ let i = n(), o = new a({
2337
2633
  sessionIdGenerator: void 0,
2338
2634
  enableJsonResponse: !0
2339
2635
  });
2340
2636
  o.onerror = (t) => {
2341
- e.config.logger.error(`[svelte-devtools] MCP transport error: ${t.stack || t.message}`);
2637
+ e.config.logger.error(`[svelte-devtools] MCP transport error: ${t.stack ?? t.message}`);
2342
2638
  };
2343
2639
  try {
2344
- await a.connect(o), await o.handleRequest(t, r);
2640
+ await i.connect(o), await o.handleRequest(t, r);
2345
2641
  } catch (t) {
2346
- e.config.logger.error(`[svelte-devtools] MCP handler error: ${t instanceof Error ? t.stack || t.message : String(t)}`), r.headersSent || (r.statusCode = 500, r.setHeader("Content-Type", "application/json"), r.end(JSON.stringify({ error: String(t) })));
2642
+ e.config.logger.error(`[svelte-devtools] MCP handler error: ${t instanceof Error ? t.stack ?? t.message : String(t)}`), r.headersSent || (r.statusCode = 500, r.setHeader("Content-Type", "application/json"), r.end(JSON.stringify({ error: String(t) })));
2347
2643
  } finally {
2348
- await o.close().catch(() => {}), await a.close().catch(() => {});
2644
+ await o.close().catch(() => {}), await i.close().catch(() => {});
2349
2645
  }
2646
+ };
2647
+ e.middlewares.use("/__svelte-devtools/mcp", (t, n) => {
2648
+ r(t, n).catch((t) => {
2649
+ e.config.logger.error(`[svelte-devtools] MCP handler error: ${String(t)}`), n.headersSent || (n.statusCode = 500, n.setHeader("Content-Type", "application/json"), n.end(JSON.stringify({ error: String(t) })));
2650
+ });
2350
2651
  });
2351
2652
  },
2352
2653
  async closeServer({ reason: e }) {
2353
- let t = m.filter((t) => e === "close" || t.generation < ft);
2354
- for (let e of t) m.splice(m.indexOf(e), 1);
2654
+ let t = _.filter((t) => e === "close" || t.generation < rn);
2655
+ for (let e of t) _.splice(_.indexOf(e), 1);
2355
2656
  await Promise.all(t.map((e) => e.dispose()));
2356
2657
  },
2357
2658
  resolveId(e, t) {
2358
- if (a?.command === "serve") {
2359
- if (e === "virtual:svelte-devtools-runtime") return ge;
2360
- if (i && e === "svelte/internal/client" && t && !t.includes("node_modules") && !t.startsWith("\0")) return _e;
2361
- }
2659
+ return s?.command === "serve" ? e === "virtual:svelte-devtools-runtime" ? He : i && e === "svelte/internal/client" && t && !t.includes("node_modules") && !t.startsWith("\0") ? Ue : null : null;
2362
2660
  },
2363
2661
  load(e) {
2364
- if (a?.command === "serve") {
2365
- if (e === "\0virtual:svelte-devtools-runtime") return ye;
2366
- if (e === "\0svelte-devtools:wrapped-client") return ve;
2367
- }
2662
+ return s?.command === "serve" ? e === "\0virtual:svelte-devtools-runtime" ? Ge : e === "\0svelte-devtools:wrapped-client" ? We : null : null;
2368
2663
  },
2369
- transformIndexHtml() {
2370
- return a.command === "serve" ? [{
2371
- tag: "script",
2372
- attrs: { type: "module" },
2373
- children: `import '${S}'`,
2374
- injectTo: "head-prepend"
2375
- }] : [];
2664
+ transformIndexHtml: {
2665
+ order: "pre",
2666
+ handler() {
2667
+ return s.command === "serve" ? [{
2668
+ tag: "script",
2669
+ attrs: { type: "module" },
2670
+ children: `import '${M}'`,
2671
+ injectTo: "head-prepend"
2672
+ }] : [];
2673
+ }
2376
2674
  },
2377
2675
  devtools: {
2378
2676
  capabilities: {
@@ -2381,7 +2679,7 @@ function mt(r = {}) {
2381
2679
  },
2382
2680
  async setup(e) {
2383
2681
  let { createPluginFromDevframe: t } = await import("@vitejs/devtools-kit/node");
2384
- await t(p, { base: L }).devtools?.setup?.(e);
2682
+ await t(h, { base: Y }).devtools?.setup?.(e);
2385
2683
  }
2386
2684
  }
2387
2685
  },
@@ -2389,11 +2687,11 @@ function mt(r = {}) {
2389
2687
  name: "vite-devtools-svelte:tracking",
2390
2688
  enforce: "post",
2391
2689
  apply: "serve",
2392
- transform(e, t) {
2393
- if (!i || !t.endsWith(".svelte") || t.includes("node_modules") || a?.command !== "serve" || !e.includes("$.push(")) return null;
2394
- let n = JSON.stringify(t);
2395
- return {
2396
- code: `import '${S}';\n` + e.replace(/(\$\.push\([^)]+\);?)/, `if (typeof window !== 'undefined' && window.__SVELTE_DEVTOOLS__) { window.__SVELTE_DEVTOOLS__._pendingFile = ${n}; }\n$1`),
2690
+ transform(e, t, n) {
2691
+ if (!i || t.includes("node_modules") || s?.command !== "serve" || n?.ssr) return null;
2692
+ let [r = t] = t.split("?"), a = r.endsWith(".svelte") ? Ke(e, r) : qe.test(r) ? Je(e, r) : null;
2693
+ return a === null ? null : {
2694
+ code: a,
2397
2695
  map: null
2398
2696
  };
2399
2697
  }
@@ -2403,25 +2701,28 @@ function mt(r = {}) {
2403
2701
  enforce: "post",
2404
2702
  apply: "serve",
2405
2703
  transform(e, t) {
2406
- if (a?.command !== "serve") return null;
2704
+ if (s?.command !== "serve") return null;
2407
2705
  let n = /\+page\.server\.[tj]s$/.test(t) || /\+layout\.server\.[tj]s$/.test(t), r = /\+(page|layout)\.[tj]s$/.test(t) && !t.includes(".server.");
2408
2706
  if (!n && !r || t.includes("node_modules") || !e.includes("export") || !e.includes("load")) return null;
2409
- let i = n ? "server" : "universal", o = t.match(/routes(.*)\/\+/), s = o && o[1] || "/", c = JSON.stringify(s), l = JSON.stringify(t), u = JSON.stringify(i), d = e.replace(/export\s+const\s+load\s*=\s*/, "const __original_load = ");
2410
- if (d === e && (d = e.replace(/export\s+(async\s+)?function\s+load\s*\(/, "const __original_load = $1function __load_impl(")), d === e) return null;
2411
- let f = `
2707
+ let i = n ? "server" : "universal", a = (t.match(/routes(.*)\/\+/)?.[1] ?? "") || "/", o = JSON.stringify(a), c = JSON.stringify(t), l = JSON.stringify(i), u = e.replace(/export\s+(const|let|var)\s+load\s*=\s*/, "$1 __original_load = ");
2708
+ if (u === e && (u = e.replace(/export\s+(async\s+)?function\s+load\s*\(/, "const __original_load = $1function __load_impl(")), u === e) return null;
2709
+ let d = `
2412
2710
  export const load = async (event) => {
2413
2711
  const __start = performance.now();
2414
2712
  const __result = await __original_load(event);
2415
- const __duration = performance.now() - __start;
2416
- const __dataSize = JSON.stringify(__result || {}).length;
2417
- if (typeof globalThis.__svelte_devtools_record_load === 'function') {
2418
- globalThis.__svelte_devtools_record_load(${c}, ${l}, ${u}, __duration, __dataSize);
2419
- }
2713
+ try {
2714
+ const __duration = performance.now() - __start;
2715
+ let __dataSize = 0;
2716
+ try { __dataSize = JSON.stringify(__result || {}).length; } catch {}
2717
+ if (typeof globalThis.__svelte_devtools_record_load === 'function') {
2718
+ globalThis.__svelte_devtools_record_load(${o}, ${c}, ${l}, __duration, __dataSize);
2719
+ }
2720
+ } catch {}
2420
2721
  return __result;
2421
2722
  };
2422
2723
  `;
2423
2724
  return {
2424
- code: d + f,
2725
+ code: u + d,
2425
2726
  map: null
2426
2727
  };
2427
2728
  }
@@ -2439,7 +2740,7 @@ export const load = async (event) => {
2439
2740
  dataSize: i,
2440
2741
  timestamp: Date.now()
2441
2742
  };
2442
- f.recordLoadProfile(a);
2743
+ m.recordLoadProfile(a);
2443
2744
  };
2444
2745
  }
2445
2746
  },
@@ -2450,26 +2751,27 @@ export const load = async (event) => {
2450
2751
  configResolved(e) {
2451
2752
  let t = e.logger, n = $ in t;
2452
2753
  if (t[$] = (e) => {
2453
- if (!e.includes(".svelte") || a?.command !== "serve") return;
2454
- let t = e.match(/(?:^|\s)((?:\/|\.\/|\w:)[^\s:]+\.svelte)(?::(\d+):(\d+))?/), n = e.match(/\(([a-z0-9_-]+)\)/);
2455
- f.recordCompilerWarning({
2456
- code: n?.[1] || "unknown",
2457
- message: e.replace(/\x1b\[[0-9;]*m/g, "").trim(),
2458
- file: t?.[1] || "",
2459
- line: t?.[2] ? parseInt(t[2]) : void 0,
2460
- column: t?.[3] ? parseInt(t[3]) : void 0
2754
+ let t = e.replaceAll(/\u001B\[[0-9;]*m/g, "").trim();
2755
+ if (!t.includes(".svelte") || s?.command !== "serve") return;
2756
+ let n = t.match(/(?:^|\s)((?:\/|\.\/|\w:)[^\s:]+\.svelte)(?::(\d+):(\d+))?/), r = t.match(/\(([a-z0-9_-]+)\)/);
2757
+ m.recordCompilerWarning({
2758
+ code: r?.[1] ?? "unknown",
2759
+ message: t,
2760
+ file: n?.[1] ?? "",
2761
+ line: n?.[2] ? Number(n[2]) : void 0,
2762
+ column: n?.[3] ? Number(n[3]) : void 0
2461
2763
  });
2462
2764
  }, n) return;
2463
- let r = t.warn;
2765
+ let r = t.warn.bind(t);
2464
2766
  t.warn = (e, n) => {
2465
2767
  t[$]?.(e), r(e, n);
2466
2768
  };
2467
2769
  }
2468
2770
  },
2469
- ut(() => c)
2771
+ tn(() => u)
2470
2772
  ];
2471
2773
  }
2472
2774
  //#endregion
2473
- export { mt as svelteDevtools };
2775
+ export { sn as svelteDevtools };
2474
2776
 
2475
2777
  //# sourceMappingURL=index.mjs.map