@hamur/devtools 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +24 -2
  3. package/dist/src/client.js +780 -0
  4. package/dist/src/index.js +1711 -0
  5. package/dist/types/src/apps/locator.d.ts +3 -0
  6. package/dist/types/src/bridge.d.ts +8 -0
  7. package/dist/types/src/client.d.ts +3 -0
  8. package/dist/types/src/dev/analyze.d.ts +31 -0
  9. package/dist/types/src/dev/assets.d.ts +33 -0
  10. package/dist/types/src/dev/authz.d.ts +49 -0
  11. package/dist/types/src/dev/bundle.d.ts +22 -0
  12. package/dist/types/src/dev/config.d.ts +24 -0
  13. package/dist/types/src/dev/handler.d.ts +20 -0
  14. package/dist/types/src/dev/modules.d.ts +28 -0
  15. package/dist/types/src/dev/overview.d.ts +20 -0
  16. package/dist/types/src/dev/processes.d.ts +4 -0
  17. package/dist/types/src/dev/server-routes.d.ts +7 -0
  18. package/dist/types/src/dev/tasks.d.ts +26 -0
  19. package/dist/types/src/dev/timeline.d.ts +20 -0
  20. package/dist/types/src/dev/virtual.d.ts +9 -0
  21. package/dist/types/src/icons.d.ts +24 -0
  22. package/dist/types/src/index.d.ts +8 -0
  23. package/dist/types/src/locator.d.ts +17 -0
  24. package/dist/types/src/mask.d.ts +8 -0
  25. package/dist/types/src/module.d.ts +27 -0
  26. package/dist/types/src/open-in-editor.d.ts +4 -0
  27. package/dist/types/src/options.d.ts +14 -0
  28. package/dist/types/src/panel/document.d.ts +16 -0
  29. package/dist/types/src/panel/groups.d.ts +14 -0
  30. package/dist/types/src/panel/index.d.ts +1 -0
  31. package/dist/types/src/panel/settings.d.ts +69 -0
  32. package/dist/types/src/panel/style.d.ts +1 -0
  33. package/dist/types/src/panel/ui.d.ts +34 -0
  34. package/dist/types/src/server/authz.d.ts +30 -0
  35. package/dist/types/src/server/index.d.ts +3 -0
  36. package/dist/types/src/server/routes.d.ts +6 -0
  37. package/dist/types/src/server/storage.d.ts +56 -0
  38. package/dist/types/src/source-link.d.ts +2 -0
  39. package/dist/types/src/tabs/analyze-model.d.ts +31 -0
  40. package/dist/types/src/tabs/analyze.d.ts +2 -0
  41. package/dist/types/src/tabs/assets.d.ts +11 -0
  42. package/dist/types/src/tabs/audit-model.d.ts +42 -0
  43. package/dist/types/src/tabs/audit.d.ts +2 -0
  44. package/dist/types/src/tabs/authz-model.d.ts +11 -0
  45. package/dist/types/src/tabs/authz.d.ts +2 -0
  46. package/dist/types/src/tabs/config.d.ts +8 -0
  47. package/dist/types/src/tabs/inspect.d.ts +7 -0
  48. package/dist/types/src/tabs/modules.d.ts +4 -0
  49. package/dist/types/src/tabs/overview.d.ts +2 -0
  50. package/dist/types/src/tabs/pages.d.ts +2 -0
  51. package/dist/types/src/tabs/payload.d.ts +6 -0
  52. package/dist/types/src/tabs/plugins-model.d.ts +15 -0
  53. package/dist/types/src/tabs/plugins.d.ts +2 -0
  54. package/dist/types/src/tabs/seo-model.d.ts +36 -0
  55. package/dist/types/src/tabs/seo.d.ts +2 -0
  56. package/dist/types/src/tabs/server-routes.d.ts +2 -0
  57. package/dist/types/src/tabs/storage.d.ts +13 -0
  58. package/dist/types/src/tabs/tasks-model.d.ts +16 -0
  59. package/dist/types/src/tabs/tasks.d.ts +2 -0
  60. package/dist/types/src/tabs/terminals-model.d.ts +53 -0
  61. package/dist/types/src/tabs/terminals.d.ts +2 -0
  62. package/dist/types/src/tabs/timeline-model.d.ts +58 -0
  63. package/dist/types/src/tabs/timeline.d.ts +2 -0
  64. package/dist/types/src/tester.d.ts +43 -0
  65. package/dist/types/src/toolbar/element.d.ts +28 -0
  66. package/dist/types/src/toolbar/shortcut.d.ts +14 -0
  67. package/dist/types/src/toolbar/style.d.ts +3 -0
  68. package/dist/types/src/view-context.d.ts +13 -0
  69. package/package.json +28 -4
  70. package/src/apps/locator.ts +131 -0
  71. package/src/bridge.ts +172 -0
  72. package/src/client.ts +10 -0
  73. package/src/dev/analyze.ts +128 -0
  74. package/src/dev/assets.ts +208 -0
  75. package/src/dev/authz.ts +162 -0
  76. package/src/dev/bundle.ts +91 -0
  77. package/src/dev/config.ts +132 -0
  78. package/src/dev/handler.ts +161 -0
  79. package/src/dev/modules.ts +60 -0
  80. package/src/dev/overview.ts +57 -0
  81. package/src/dev/processes.ts +34 -0
  82. package/src/dev/server-routes.ts +14 -0
  83. package/src/dev/tasks.ts +93 -0
  84. package/src/dev/timeline.ts +43 -0
  85. package/src/dev/virtual.ts +40 -0
  86. package/src/env.d.ts +21 -0
  87. package/src/icons.ts +48 -0
  88. package/src/index.ts +12 -0
  89. package/src/locator.ts +31 -0
  90. package/src/mask.ts +16 -0
  91. package/src/module.ts +352 -0
  92. package/src/open-in-editor.ts +18 -0
  93. package/src/options.ts +36 -0
  94. package/src/panel/document.ts +60 -0
  95. package/src/panel/groups.ts +41 -0
  96. package/src/panel/index.ts +429 -0
  97. package/src/panel/settings.ts +224 -0
  98. package/src/panel/style.ts +321 -0
  99. package/src/panel/ui.ts +52 -0
  100. package/src/server/authz.ts +110 -0
  101. package/src/server/index.ts +25 -0
  102. package/src/server/routes.ts +51 -0
  103. package/src/server/storage.ts +251 -0
  104. package/src/source-link.ts +29 -0
  105. package/src/tabs/analyze-model.ts +97 -0
  106. package/src/tabs/analyze.ts +217 -0
  107. package/src/tabs/assets.ts +375 -0
  108. package/src/tabs/audit-model.ts +216 -0
  109. package/src/tabs/audit.ts +223 -0
  110. package/src/tabs/authz-model.ts +28 -0
  111. package/src/tabs/authz.ts +337 -0
  112. package/src/tabs/config.ts +250 -0
  113. package/src/tabs/inspect.ts +101 -0
  114. package/src/tabs/modules.ts +58 -0
  115. package/src/tabs/overview.ts +104 -0
  116. package/src/tabs/pages.ts +188 -0
  117. package/src/tabs/payload.ts +224 -0
  118. package/src/tabs/plugins-model.ts +44 -0
  119. package/src/tabs/plugins.ts +95 -0
  120. package/src/tabs/seo-model.ts +140 -0
  121. package/src/tabs/seo.ts +162 -0
  122. package/src/tabs/server-routes.ts +469 -0
  123. package/src/tabs/storage.ts +313 -0
  124. package/src/tabs/tasks-model.ts +59 -0
  125. package/src/tabs/tasks.ts +287 -0
  126. package/src/tabs/terminals-model.ts +127 -0
  127. package/src/tabs/terminals.ts +294 -0
  128. package/src/tabs/timeline-model.ts +200 -0
  129. package/src/tabs/timeline.ts +260 -0
  130. package/src/tester.ts +158 -0
  131. package/src/toolbar/element.ts +428 -0
  132. package/src/toolbar/shortcut.ts +56 -0
  133. package/src/toolbar/style.ts +94 -0
  134. package/src/view-context.ts +93 -0
@@ -0,0 +1,1711 @@
1
+ // packages/devtools/src/module.ts
2
+ import { join as join6 } from "node:path";
3
+ import {
4
+ addAppPlugin,
5
+ addDevServerHandler,
6
+ addDevtoolsApp,
7
+ addDevtoolsTab,
8
+ addServer,
9
+ addTemplate,
10
+ cancelDevTaskRun,
11
+ createRedactor,
12
+ createResolver,
13
+ defineModule,
14
+ extendDevtoolsRpc,
15
+ matchDevRoute,
16
+ resetDevRuntimeConfig,
17
+ runDevAnalyze,
18
+ setDevRuntimeConfig,
19
+ useDevChannel,
20
+ useDevHooks,
21
+ useDevRouteTable,
22
+ useDevServerConfig,
23
+ useDevServerRoutes,
24
+ useDevSpans,
25
+ useDevTaskRuns,
26
+ useAppPlugins,
27
+ useDevPublicAssets,
28
+ useDevtoolsRegistry,
29
+ useHamur,
30
+ useInstalledModules,
31
+ useLogger,
32
+ useServerPlugins
33
+ } from "hamur/kit";
34
+
35
+ // packages/devtools/src/dev/analyze.ts
36
+ import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
37
+ import { join, resolve, sep } from "node:path";
38
+ import { renderAnalyzeTreemap } from "hamur/kit";
39
+
40
+ class AnalyzeError extends Error {
41
+ status;
42
+ constructor(message, status) {
43
+ super(message);
44
+ this.status = status;
45
+ }
46
+ }
47
+ var RUN_ID = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
48
+ var isReport = (value) => {
49
+ const report = value;
50
+ return typeof report === "object" && report !== null && Array.isArray(report.client?.chunks) && Array.isArray(report.routes);
51
+ };
52
+ function createAnalyzer({
53
+ dir,
54
+ build,
55
+ now = () => new Date
56
+ }) {
57
+ const root = resolve(dir);
58
+ const answer = (id, report) => ({
59
+ id,
60
+ client: report.client,
61
+ routes: report.routes,
62
+ treemap: renderAnalyzeTreemap(report.client)
63
+ });
64
+ async function load(id) {
65
+ if (!RUN_ID.test(id))
66
+ throw new AnalyzeError(`Invalid analyze run id ${JSON.stringify(id)}`, 400);
67
+ const file = resolve(root, `${id}.json`);
68
+ if (!file.startsWith(`${root}${sep}`))
69
+ throw new AnalyzeError(`Invalid analyze run id ${JSON.stringify(id)}`, 400);
70
+ let text;
71
+ try {
72
+ text = await readFile(file, "utf8");
73
+ } catch {
74
+ throw new AnalyzeError(`No analyze run ${JSON.stringify(id)}`, 404);
75
+ }
76
+ let parsed;
77
+ try {
78
+ parsed = JSON.parse(text);
79
+ } catch {
80
+ throw new AnalyzeError(`Analyze run ${JSON.stringify(id)} is not valid JSON`, 500);
81
+ }
82
+ if (!isReport(parsed))
83
+ throw new AnalyzeError(`Analyze run ${JSON.stringify(id)} is not an analyze report`, 500);
84
+ return parsed;
85
+ }
86
+ async function save() {
87
+ const report = await build();
88
+ if (!report)
89
+ throw new AnalyzeError("The analyze build runs only under hamur dev", 503);
90
+ const id = now().toISOString();
91
+ await mkdir(root, { recursive: true });
92
+ await writeFile(join(root, `${id}.json`), `${JSON.stringify({ client: report.client, routes: report.routes })}
93
+ `);
94
+ return answer(id, report);
95
+ }
96
+ let running;
97
+ return {
98
+ run() {
99
+ return running ??= save().finally(() => {
100
+ running = undefined;
101
+ });
102
+ },
103
+ async list() {
104
+ const names = await readdir(root).catch(() => []);
105
+ const ids = names.filter((name) => name.endsWith(".json") && RUN_ID.test(name.slice(0, -5))).map((name) => name.slice(0, -5));
106
+ ids.sort().reverse();
107
+ const rows = await Promise.all(ids.map(async (id) => {
108
+ const report = await load(id).catch(() => {
109
+ return;
110
+ });
111
+ return report && {
112
+ id,
113
+ bytes: report.client.bytes,
114
+ gzip: report.client.gzip,
115
+ chunks: report.client.chunks.length,
116
+ routes: report.routes.length
117
+ };
118
+ }));
119
+ return rows.filter((row) => row !== undefined);
120
+ },
121
+ async read(id) {
122
+ return answer(id, await load(id));
123
+ }
124
+ };
125
+ }
126
+
127
+ // packages/devtools/src/dev/authz.ts
128
+ import { existsSync } from "node:fs";
129
+ import { readFile as readFile2 } from "node:fs/promises";
130
+ import { join as join2 } from "node:path";
131
+ function hasPolicies(options) {
132
+ return [options.serverDir, ...options.layers.map((layer) => layer.serverDir)].some((dir) => existsSync(join2(dir, "policies")));
133
+ }
134
+ function typeText(type) {
135
+ switch (type.kind) {
136
+ case "bool":
137
+ return "Bool";
138
+ case "long":
139
+ return "Long";
140
+ case "string":
141
+ return "String";
142
+ case "set":
143
+ return `Set<${typeText(type.element)}>`;
144
+ case "record": {
145
+ const parts = [...type.attributes].map(([name, { type: attribute, required }]) => `${name}${required ? "" : "?"}: ${typeText(attribute)}`);
146
+ return parts.length ? `{ ${parts.join(", ")} }` : "{}";
147
+ }
148
+ default:
149
+ return type.name;
150
+ }
151
+ }
152
+ var uid = (target) => target.kind === "slot" ? target.name : `${target.type}::${JSON.stringify(target.id)}`;
153
+ function headText(scope) {
154
+ if (scope.kind === "any")
155
+ return "any";
156
+ if (scope.kind === "eq")
157
+ return `== ${uid(scope.entity)}`;
158
+ if (scope.kind === "in")
159
+ return `in ${uid(scope.entity)}`;
160
+ return `is ${scope.type}${scope.in ? ` in ${uid(scope.in)}` : ""}`;
161
+ }
162
+ function actionText(scope) {
163
+ if (scope.kind === "any")
164
+ return "any";
165
+ if (scope.kind === "eq")
166
+ return `== ${uid(scope.entity)}`;
167
+ return `in [${scope.entities.map(uid).join(", ")}]`;
168
+ }
169
+ function policyText(lines, line, next) {
170
+ const end = next !== undefined && next > line ? next - 1 : next === undefined ? lines.length : line;
171
+ const kept = lines.slice(line - 1, end);
172
+ while (kept.length > 1 && /^\s*(\/\/.*)?$/.test(kept[kept.length - 1]))
173
+ kept.pop();
174
+ return kept.join(`
175
+ `);
176
+ }
177
+ async function policiesAnswer(state) {
178
+ if (!state)
179
+ return { policies: [], entityTypes: [], actions: [] };
180
+ const texts = new Map;
181
+ for (const { file, shown } of state.files)
182
+ texts.set(shown, (await readFile2(file, "utf8")).split(/\r?\n/));
183
+ const starts = new Map;
184
+ for (const { policy } of state.policies)
185
+ starts.set(policy.loc.file, [...starts.get(policy.loc.file) ?? [], policy.loc.line].sort((a, b) => a - b));
186
+ return {
187
+ policies: state.policies.map(({ id, policy }) => {
188
+ const { file, line, column } = policy.loc;
189
+ const after = starts.get(file)?.find((start) => start > line);
190
+ return {
191
+ id,
192
+ effect: policy.effect,
193
+ principal: headText(policy.principal),
194
+ action: actionText(policy.action),
195
+ resource: headText(policy.resource),
196
+ template: policy.template,
197
+ file,
198
+ line,
199
+ column,
200
+ text: policyText(texts.get(file) ?? [], line, after)
201
+ };
202
+ }),
203
+ entityTypes: [...state.schema.entityTypes.values()].map((type) => ({
204
+ name: type.name,
205
+ attributes: [...type.attributes].map(([name, { type: attribute, required }]) => ({
206
+ name,
207
+ type: typeText(attribute),
208
+ required
209
+ })),
210
+ parents: [...type.ancestors].sort(),
211
+ ...type.tags ? { tags: typeText(type.tags) } : {},
212
+ ...type.enum ? { enum: [...type.enum] } : {}
213
+ })),
214
+ actions: Object.entries(state.actions).map(([name, action]) => {
215
+ const applies = state.schema.actions.get(`${action.type}::${JSON.stringify(action.id)}`)?.appliesTo;
216
+ return {
217
+ name,
218
+ groups: action.groups.map(({ type, id }) => `${type}::${JSON.stringify(id)}`),
219
+ ...applies ? {
220
+ appliesTo: {
221
+ principals: [...applies.principals],
222
+ resources: [...applies.resources],
223
+ context: typeText(applies.context)
224
+ }
225
+ } : {}
226
+ };
227
+ })
228
+ };
229
+ }
230
+
231
+ // packages/devtools/src/dev/assets.ts
232
+ import { link, lstat, mkdir as mkdir2, open, realpath, rename, unlink } from "node:fs/promises";
233
+ import { dirname, extname, isAbsolute, join as join3, relative, sep as sep2 } from "node:path";
234
+
235
+ // packages/devtools/src/icons.ts
236
+ var TAB_ICONS = {
237
+ overview: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 16.5c0-5.5 3.6-9.5 8-9.5s8 4 8 9.5z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M4 16.5c0-5.5 3.6-9.5 8-9.5s8 4 8 9.5M3 16.5h18M9.5 12v1M14.5 12v1"></path></svg>',
238
+ pages: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7.5 3.5h6l5 5v10a2.5 2.5 0 0 1-2.5 2.5h-8.5A2.5 2.5 0 0 1 5 18.5V6a2.5 2.5 0 0 1 2.5-2.5z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M7.5 3.5h6l5 5v10a2.5 2.5 0 0 1-2.5 2.5h-8.5A2.5 2.5 0 0 1 5 18.5V6a2.5 2.5 0 0 1 2.5-2.5zM13.5 3.5v5h5"></path></svg>',
239
+ payload: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 9a3 3 0 1 1 0 6 3 3 0 0 1 0-6z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M8.5 4H8a2.5 2.5 0 0 0-2.5 2.5V10L3.5 12l2 2v3.5A2.5 2.5 0 0 0 8 20h.5M15.5 4h.5a2.5 2.5 0 0 1 2.5 2.5V10l2 2-2 2v3.5A2.5 2.5 0 0 1 16 20h-.5"></path></svg>',
240
+ config: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 5a3 3 0 1 1 0 6 3 3 0 0 1 0-6zM15 13a3 3 0 1 1 0 6 3 3 0 0 1 0-6z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M3.5 8h2.5M12 8h8.5M3.5 16h8.5M18 16h2.5M9 5a3 3 0 1 1 0 6 3 3 0 0 1 0-6zM15 13a3 3 0 1 1 0 6 3 3 0 0 1 0-6z"></path></svg>',
241
+ "server-routes": '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 16a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM18 2a3 3 0 1 0 0 6 3 3 0 0 0 0-6z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M6 16a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM18 2a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM9 19h5.5a3.5 3.5 0 0 0 0-7h-5a3.5 3.5 0 0 1 0-7H15"></path></svg>',
242
+ storage: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 10h15v7.5a3 3 0 0 1-3 3h-9a3 3 0 0 1-3-3z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M4.5 10h15v7.5a3 3 0 0 1-3 3h-9a3 3 0 0 1-3-3zM3.5 10c0-3.3 3.8-6 8.5-6s8.5 2.7 8.5 6"></path></svg>',
243
+ assets: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 17c2.3-3.5 5-5 8.5-5s6.2 1.5 8.5 5v.5a3 3 0 0 1-3 3h-11a3 3 0 0 1-3-3zM16 6a2 2 0 1 1 0 4 2 2 0 0 1 0-4z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M6.5 3.5h11a3 3 0 0 1 3 3v11a3 3 0 0 1-3 3h-11a3 3 0 0 1-3-3v-11a3 3 0 0 1 3-3zM3.5 17c2.3-3.5 5-5 8.5-5s6.2 1.5 8.5 5"></path></svg>',
244
+ tasks: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.5 4.5h13a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-11a2 2 0 0 1 2-2z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M5.5 4.5h13a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-11a2 2 0 0 1 2-2zM7.5 9l1.5 1.5 2.5-3M7.5 15l1.5 1.5 2.5-3M14 9h3.5M14 15h3.5"></path></svg>',
245
+ authz: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3.5l7 2.5v5.5c0 4.2-2.9 7.6-7 9-4.1-1.4-7-4.8-7-9V6z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M12 3.5l7 2.5v5.5c0 4.2-2.9 7.6-7 9-4.1-1.4-7-4.8-7-9V6zM9 12l2 2 4-4"></path></svg>',
246
+ timeline: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 4.5h7.0a2 2 0 0 1 0 4h-7.0a2 2 0 0 1 0-4zM9.5 10h10.0a2 2 0 0 1 0 4h-10.0a2 2 0 0 1 0-4zM6.5 15.5h6.0a2 2 0 0 1 0 4h-6.0a2 2 0 0 1 0-4z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M4.5 4.5h7.0a2 2 0 0 1 0 4h-7.0a2 2 0 0 1 0-4zM9.5 10h10.0a2 2 0 0 1 0 4h-10.0a2 2 0 0 1 0-4zM6.5 15.5h6.0a2 2 0 0 1 0 4h-6.0a2 2 0 0 1 0-4z"></path></svg>',
247
+ plugins: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 7h12v3a6 6 0 0 1-12 0z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M6 7h12v3a6 6 0 0 1-12 0zM12 16v5M9 3v4M15 3v4"></path></svg>',
248
+ modules: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 4.5a2 2 0 1 1 4 0V6h3a2 2 0 0 1 2 2v3h-1.5a2 2 0 1 0 0 4H19v3a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-3h1.5a2 2 0 1 0 0-4H5V8a2 2 0 0 1 2-2h3z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M10 4.5a2 2 0 1 1 4 0V6h3a2 2 0 0 1 2 2v3h-1.5a2 2 0 1 0 0 4H19v3a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-3h1.5a2 2 0 1 0 0-4H5V8a2 2 0 0 1 2-2h3z"></path></svg>',
249
+ inspect: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3.5l8.5 4.5-8.5 4.5L3.5 8z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M12 3.5l8.5 4.5-8.5 4.5L3.5 8zM3.5 13l8.5 4.5 8.5-4.5"></path></svg>',
250
+ analyze: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 17a8.5 8.5 0 1 1 17 0z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M3.5 17a8.5 8.5 0 1 1 17 0zM12 17l4-5"></path></svg>',
251
+ terminals: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6.5 4h11a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3h-11a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M6.5 4h11a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3h-11a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3zM8 9.5l3 2.5-3 2.5M13.5 15H16"></path></svg>',
252
+ audit: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3c2.7 1.7 5.3 2.5 8 2.6v5.9c0 4.6-3.3 8.3-8 9.5-4.7-1.2-8-4.9-8-9.5V5.6c2.7-.1 5.3-.9 8-2.6z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M12 3c2.7 1.7 5.3 2.5 8 2.6v5.9c0 4.6-3.3 8.3-8 9.5-4.7-1.2-8-4.9-8-9.5V5.6c2.7-.1 5.3-.9 8-2.6zM8.5 12l2.5 2.5 4.5-4.5"></path></svg>',
253
+ seo: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.5 3.5a7 7 0 1 1 0 14 7 7 0 0 1 0-14z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M10.5 3.5a7 7 0 1 1 0 14 7 7 0 0 1 0-14zM15.5 15.5l5 5"></path></svg>'
254
+ };
255
+ var LOCATOR_ICON = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 8.5a3.5 3.5 0 1 1 0 7 3.5 3.5 0 0 1 0-7z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M12 4.5a7.5 7.5 0 1 1 0 15 7.5 7.5 0 0 1 0-15zM12 1.5v3M12 19.5v3M1.5 12h3M19.5 12h3"></path></svg>';
256
+ var SETTINGS_ICON = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15.5 4.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5zM8.5 14.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5z" fill="currentColor" fill-opacity="0.16" stroke="none"></path><path d="M3.5 7h9M18.5 7h2M3.5 17h2M11.5 17h9M15.5 4.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5zM8.5 14.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5z"></path></svg>';
257
+ var WINDOW_ICON = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.5 5.5h13a1 1 0 0 1 1 1v11a1 1 0 0 1-1 1h-13a1 1 0 0 1-1-1v-11a1 1 0 0 1 1-1zM4.5 9.5h15M13 13.5l3-3M13.5 10.5H16v2.5"></path></svg>';
258
+ var HAMUR_MARK = '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 16c0-5 3.4-9 7.5-9s7.5 4 7.5 9M3.5 16h17M9.5 12.5v.5M14.5 12.5v.5"></path></svg>';
259
+
260
+ // packages/devtools/src/panel/style.ts
261
+ var PANEL_CSS = String.raw`
262
+ :root {
263
+ --app: #f5f4f2;
264
+ --panel: #fffefc;
265
+ --raised: #ffffff;
266
+ --hover: #f6f5f3;
267
+ --active: #f0efee;
268
+ --field: #f9f7f6;
269
+ --line: #e8e6e5;
270
+ --line-strong: #dedcdb;
271
+ --hairline: rgba(255,248,240,0.08);
272
+ --fg: #222120;
273
+ --fg-2: #5b5956;
274
+ --fg-3: #7e7c79;
275
+ --fg-4: #a5a3a0;
276
+ --side: #605e5b;
277
+ --side-icon: #888683;
278
+ --accent: #db5e29;
279
+ --accent-soft: rgba(219,94,41,0.1);
280
+ --amber: #be7c1b;
281
+ --red: #cf4445;
282
+ --green: #2b8d52;
283
+ --blue: #5375cf;
284
+ --violet: #8661bb;
285
+ color-scheme: light;
286
+ }
287
+ @media (prefers-color-scheme: dark) {
288
+ :root:not([data-theme="light"]) {
289
+ --app: #121110;
290
+ --panel: #191817;
291
+ --raised: #1f1e1d;
292
+ --hover: #21201f;
293
+ --active: #252423;
294
+ --field: #1d1c1b;
295
+ --line: #272725;
296
+ --line-strong: #2f2e2d;
297
+ --hairline: rgba(255,248,240,0.08);
298
+ --fg: #f8f6f4;
299
+ --fg-2: #a3a09d;
300
+ --fg-3: #74726e;
301
+ --fg-4: #54524f;
302
+ --side: #93908d;
303
+ --side-icon: #6f6d6a;
304
+ --accent: #ff8a4a;
305
+ --accent-soft: rgba(255,138,74,0.12);
306
+ --amber: #e0ac49;
307
+ --red: #eb635e;
308
+ --green: #60b780;
309
+ --blue: #889fe8;
310
+ --violet: #af8cdc;
311
+ color-scheme: dark;
312
+ }
313
+ }
314
+ :root[data-theme="dark"] {
315
+ --app: #121110;
316
+ --panel: #191817;
317
+ --raised: #1f1e1d;
318
+ --hover: #21201f;
319
+ --active: #252423;
320
+ --field: #1d1c1b;
321
+ --line: #272725;
322
+ --line-strong: #2f2e2d;
323
+ --hairline: rgba(255,248,240,0.08);
324
+ --fg: #f8f6f4;
325
+ --fg-2: #a3a09d;
326
+ --fg-3: #74726e;
327
+ --fg-4: #54524f;
328
+ --side: #93908d;
329
+ --side-icon: #6f6d6a;
330
+ --accent: #ff8a4a;
331
+ --accent-soft: rgba(255,138,74,0.12);
332
+ --amber: #e0ac49;
333
+ --red: #eb635e;
334
+ --green: #60b780;
335
+ --blue: #889fe8;
336
+ --violet: #af8cdc;
337
+ color-scheme: dark;
338
+ }
339
+ *, ::before, ::after { box-sizing: border-box; }
340
+ html, body { height: 100%; margin: 0; }
341
+ body { font-family: Inter, system-ui, sans-serif; line-height: 1.45; -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01"; }
342
+ button, input, select, textarea { font: inherit; color: inherit; }
343
+ svg { overflow: visible; flex: none; }
344
+ [hidden] { display: none !important; }
345
+ .flex{display:flex}
346
+ .inline-flex{display:inline-flex}
347
+ .grid{display:grid}
348
+ .block{display:block}
349
+ .sticky{position:sticky}
350
+ .relative{position:relative}
351
+ .absolute{position:absolute}
352
+ .top-0{top:0}
353
+ .top-0\.5{top:0.125rem}
354
+ .top-2{top:0.5rem}
355
+ .right-2{right:0.5rem}
356
+ .inset-y-0\.5{top:0.125rem;bottom:0.125rem}
357
+ .flex-1{flex:1 1 0%}
358
+ .flex-none{flex:none}
359
+ .flex-col{flex-direction:column}
360
+ .flex-wrap{flex-wrap:wrap}
361
+ .items-center{align-items:center}
362
+ .items-start{align-items:flex-start}
363
+ .self-start{align-self:flex-start}
364
+ .justify-center{justify-content:center}
365
+ .justify-between{justify-content:space-between}
366
+ .place-items-center{place-items:center}
367
+ .grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}
368
+ .grid-cols-\[12rem_minmax\(0\,1fr\)_4\.5rem\]{grid-template-columns:12rem minmax(0,1fr) 4.5rem}
369
+ .grid-cols-\[repeat\(auto-fill\,minmax\(8\.5rem\,1fr\)\)\]{grid-template-columns:repeat(auto-fill,minmax(8.5rem,1fr))}
370
+ .min-w-0{min-width:0}
371
+ .min-w-40{min-width:10rem}
372
+ .min-h-0{min-height:0}
373
+ .min-h-7{min-height:1.75rem}
374
+ .min-h-8{min-height:2rem}
375
+ .min-h-20{min-height:5rem}
376
+ .w-full{width:100%}
377
+ .max-w-full{max-width:100%}
378
+ .max-h-full{max-height:100%}
379
+ .max-h-80{max-height:20rem}
380
+ .max-h-96{max-height:24rem}
381
+ .overflow-auto{overflow:auto}
382
+ .overflow-x-auto{overflow-x:auto}
383
+ .overflow-hidden{overflow:hidden}
384
+ .list-none{list-style:none}
385
+ .border-collapse{border-collapse:collapse}
386
+ .align-middle{vertical-align:middle}
387
+ .align-top{vertical-align:top}
388
+ .text-left{text-align:left}
389
+ .text-center{text-align:center}
390
+ .text-right{text-align:right}
391
+ .truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
392
+ .whitespace-nowrap{white-space:nowrap}
393
+ .whitespace-pre-wrap{white-space:pre-wrap}
394
+ .break-all{word-break:break-all}
395
+ .break-words{overflow-wrap:break-word}
396
+ .no-underline{text-decoration:none}
397
+ .underline{text-decoration:underline}
398
+ .decoration-dotted{text-decoration-style:dotted}
399
+ .cursor-pointer{cursor:pointer}
400
+ .object-contain{object-fit:contain}
401
+ .rounded{border-radius:4px}
402
+ .rounded-sm{border-radius:2px}
403
+ .rounded-md{border-radius:6px}
404
+ .rounded-lg{border-radius:8px}
405
+ .rounded-full{border-radius:9999px}
406
+ .font-sans{font-family:Inter,system-ui,sans-serif}
407
+ .font-mono{font-family:'JetBrains Mono',ui-monospace,monospace}
408
+ .text-2xs{font-size:0.6875rem}
409
+ .text-xs{font-size:0.75rem}
410
+ .text-sm{font-size:0.8125rem}
411
+ .text-xl{font-size:1.25rem}
412
+ .font-medium{font-weight:500}
413
+ .font-semibold{font-weight:600}
414
+ .tracking-tight{letter-spacing:-0.02em}
415
+ .leading-none{line-height:1}
416
+ .leading-normal{line-height:1.5}
417
+ .uppercase{text-transform:uppercase}
418
+ .not-italic{font-style:normal}
419
+ .tabular-nums{font-variant-numeric:tabular-nums}
420
+ .bg-transparent{background:transparent}
421
+ .text-inherit{color:inherit}
422
+ .accent-accent{accent-color:var(--accent)}
423
+ .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}
424
+ .h-1\.5{height:0.375rem}
425
+ .h-1{height:0.25rem}
426
+ .h-3\.5{height:0.875rem}
427
+ .h-5{height:1.25rem}
428
+ .h-20{height:5rem}
429
+ .h-32{height:8rem}
430
+ .h-4{height:1rem}
431
+ .size-5{width:1.25rem;height:1.25rem}
432
+ .size-2{width:0.5rem;height:0.5rem}
433
+ .size-6{width:1.5rem;height:1.5rem}
434
+ .h-6{height:1.5rem}
435
+ .size-7{width:1.75rem;height:1.75rem}
436
+ .h-7{height:1.75rem}
437
+ .h-8{height:2rem}
438
+ .h-9{height:2.25rem}
439
+ .h-10{height:2.5rem}
440
+ .h-11{height:2.75rem}
441
+ .h-12{height:3rem}
442
+ .w-4{width:1rem}
443
+ .w-11{width:2.75rem}
444
+ .w-12{width:3rem}
445
+ .w-20{width:5rem}
446
+ .w-24{width:6rem}
447
+ .w-28{width:7rem}
448
+ .w-40{width:10rem}
449
+ .w-48{width:12rem}
450
+ .w-60{width:15rem}
451
+ .w-56{width:14rem}
452
+ .w-64{width:16rem}
453
+ .w-72{width:18rem}
454
+ .w-80{width:20rem}
455
+ .w-96{width:24rem}
456
+ .gap-0\.5{gap:0.125rem}
457
+ .gap-1{gap:0.25rem}
458
+ .gap-1\.5{gap:0.375rem}
459
+ .gap-2{gap:0.5rem}
460
+ .gap-2\.5{gap:0.625rem}
461
+ .gap-3{gap:0.75rem}
462
+ .gap-3\.5{gap:0.875rem}
463
+ .gap-4{gap:1rem}
464
+ .gap-5{gap:1.25rem}
465
+ .m-0{margin:0}
466
+ .mx-1\.5{margin-left:0.375rem;margin-right:0.375rem}
467
+ .mx-4{margin-left:1rem;margin-right:1rem}
468
+ .mx-auto{margin-left:auto;margin-right:auto}
469
+ .my-1{margin-top:0.25rem;margin-bottom:0.25rem}
470
+ .my-1\.5{margin-top:0.375rem;margin-bottom:0.375rem}
471
+ .my-2{margin-top:0.5rem;margin-bottom:0.5rem}
472
+ .mt-1{margin-top:0.25rem}
473
+ .mt-2{margin-top:0.5rem}
474
+ .mr-2{margin-right:0.5rem}
475
+ .mr-1\.5{margin-right:0.375rem}
476
+ .mr-3\.5{margin-right:0.875rem}
477
+ .mr-18{margin-right:4.5rem}
478
+ .mr-auto{margin-right:auto}
479
+ .mb-1{margin-bottom:0.25rem}
480
+ .mb-1\.5{margin-bottom:0.375rem}
481
+ .mb-2{margin-bottom:0.5rem}
482
+ .ml-2{margin-left:0.5rem}
483
+ .ml-48{margin-left:12rem}
484
+ .ml-auto{margin-left:auto}
485
+ .p-0{padding:0}
486
+ .p-1\.5{padding:0.375rem}
487
+ .p-2{padding:0.5rem}
488
+ .p-4{padding:1rem}
489
+ .px-1{padding-left:0.25rem;padding-right:0.25rem}
490
+ .px-0\.5{padding-left:0.125rem;padding-right:0.125rem}
491
+ .px-1\.5{padding-left:0.375rem;padding-right:0.375rem}
492
+ .px-2{padding-left:0.5rem;padding-right:0.5rem}
493
+ .px-2\.5{padding-left:0.625rem;padding-right:0.625rem}
494
+ .py-2\.5{padding-top:0.625rem;padding-bottom:0.625rem}
495
+ .py-0\.5{padding-top:0.125rem;padding-bottom:0.125rem}
496
+ .py-1{padding-top:0.25rem;padding-bottom:0.25rem}
497
+ .py-1\.5{padding-top:0.375rem;padding-bottom:0.375rem}
498
+ .py-2{padding-top:0.5rem;padding-bottom:0.5rem}
499
+ .px-3{padding-left:0.75rem;padding-right:0.75rem}
500
+ .py-3{padding-top:0.75rem;padding-bottom:0.75rem}
501
+ .px-3\.5{padding-left:0.875rem;padding-right:0.875rem}
502
+ .py-3\.5{padding-top:0.875rem;padding-bottom:0.875rem}
503
+ .px-4{padding-left:1rem;padding-right:1rem}
504
+ .py-4{padding-top:1rem;padding-bottom:1rem}
505
+ .px-5{padding-left:1.25rem;padding-right:1.25rem}
506
+ .pt-0\.5{padding-top:0.125rem}
507
+ .pt-1{padding-top:0.25rem}
508
+ .pt-1\.5{padding-top:0.375rem}
509
+ .pt-3\.5{padding-top:0.875rem}
510
+ .pt-3{padding-top:0.75rem}
511
+ .pl-0\.5{padding-left:0.125rem}
512
+ .pr-1\.5{padding-right:0.375rem}
513
+ .pr-3{padding-right:0.75rem}
514
+ .pb-0\.5{padding-bottom:0.125rem}
515
+ .pb-1{padding-bottom:0.25rem}
516
+ .pb-1\.5{padding-bottom:0.375rem}
517
+ .pb-2{padding-bottom:0.5rem}
518
+ .pl-4{padding-left:1rem}
519
+ .border-0{border:0}
520
+ .border-t{border-top:1px solid}
521
+ .border-r{border-right:1px solid}
522
+ .border-b{border-bottom:1px solid}
523
+ .border-l{border-left:1px solid}
524
+ .border-2{border-width:2px;border-style:solid}
525
+ .border-b-2{border-bottom:2px solid}
526
+ .border-dashed{border-style:dashed}
527
+ .ring-1{box-shadow:var(--tw-ring-inset,) 0 0 0 1px var(--tw-ring-c,currentColor)}
528
+ .ring-inset{--tw-ring-inset:inset}
529
+ .bg-app{background:var(--app)}
530
+ .text-app{color:var(--app)}
531
+ .bg-panel{background:var(--panel)}
532
+ .bg-active{background:var(--active)}
533
+ .bg-field{background:var(--field)}
534
+ .border-line{border-color:var(--line)}
535
+ .border-line-strong{border-color:var(--line-strong)}
536
+ .border-fg{border-color:var(--fg)}
537
+ .border-accent{border-color:var(--accent)}
538
+ .border-transparent{border-color:transparent}
539
+ .ring-line{--tw-ring-c:var(--line)}
540
+ .ring-line-strong{--tw-ring-c:var(--line-strong)}
541
+ .ring-accent{--tw-ring-c:var(--accent)}
542
+ .bg-fg{background:var(--fg)}
543
+ .text-fg{color:var(--fg)}
544
+ .text-fg-2{color:var(--fg-2)}
545
+ .text-fg-3{color:var(--fg-3)}
546
+ .text-fg-4{color:var(--fg-4)}
547
+ .text-side{color:var(--side)}
548
+ .text-side-icon{color:var(--side-icon)}
549
+ .bg-accent{background:var(--accent)}
550
+ .bg-accent-soft{background:var(--accent-soft)}
551
+ .bg-fg-3{background:var(--fg-3)}
552
+ .bg-fg-4{background:var(--fg-4)}
553
+ .bg-green{background:var(--green)}
554
+ .bg-red{background:var(--red)}
555
+ .text-amber{color:var(--amber)}
556
+ .text-green{color:var(--green)}
557
+ .text-blue{color:var(--blue)}
558
+ .text-red{color:var(--red)}
559
+ .bg-blue{background:var(--blue)}
560
+ .bg-amber{background:var(--amber)}
561
+ .opacity-0{opacity:0}
562
+ .opacity-55{opacity:0.55}
563
+ .hover\:bg-hover:hover{background:var(--hover)}
564
+ .hover\:text-fg:hover{color:var(--fg)}
565
+ .hover\:underline:hover{text-decoration:underline}
566
+ .group:hover .group-hover\:opacity-100{opacity:1}
567
+ .focus\:opacity-100:focus{opacity:1}
568
+ .placeholder\:text-fg-4::placeholder{color:var(--fg-4)}
569
+ .disabled\:cursor-default:disabled{cursor:default}
570
+ .disabled\:opacity-40:disabled{opacity:0.4}
571
+ .empty\:hidden:empty{display:none}
572
+ .focus-visible\:outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}
573
+ .focus-visible\:ring-2:focus-visible{box-shadow:var(--tw-ring-inset,) 0 0 0 2px var(--tw-ring-c,currentColor)}
574
+ .focus-visible\:ring-accent:focus-visible{--tw-ring-c:var(--accent)}
575
+ [data-treemap] { --c: 84%; --p: 74%; --m: 64%; }
576
+ @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) [data-treemap] { --c: 26%; --p: 34%; --m: 42%; } }
577
+ :root[data-theme="dark"] [data-treemap] { --c: 26%; --p: 34%; --m: 42%; }
578
+ [data-treemap] svg { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; }
579
+ [data-treemap] svg rect { stroke: var(--panel); stroke-width: 1; }
580
+ [data-treemap] svg text { font: 11px 'JetBrains Mono', ui-monospace, monospace; fill: var(--fg); pointer-events: none; }
581
+ `;
582
+
583
+ // packages/devtools/src/panel/ui.ts
584
+ var FOCUS = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent";
585
+ var UI = {
586
+ button: `inline-flex items-center gap-1.5 h-6 px-2 rounded-md border-0 bg-transparent text-fg-2 ring-1 ring-inset ring-line-strong font-medium text-sm whitespace-nowrap cursor-pointer hover:bg-hover hover:text-fg disabled:opacity-40 disabled:cursor-default ${FOCUS}`,
587
+ primary: `inline-flex items-center gap-1.5 h-6 px-2 rounded-md border-0 bg-fg text-app font-medium text-sm whitespace-nowrap cursor-pointer ${FOCUS}`,
588
+ iconButton: `inline-flex items-center justify-center size-6 rounded-md border-0 bg-transparent text-fg-3 cursor-pointer hover:bg-hover hover:text-fg disabled:opacity-40 disabled:cursor-default ${FOCUS}`,
589
+ field: `h-6 min-w-0 px-2 rounded-md border-0 bg-field ring-1 ring-inset ring-line text-xs text-fg placeholder:text-fg-4 ${FOCUS}`,
590
+ strip: "flex-none flex items-center gap-2 h-9 px-3 border-b border-line",
591
+ groupHead: "flex items-center gap-2 h-8 mt-1 px-4 bg-field text-xs",
592
+ label: "pb-0.5 text-xs font-medium text-fg-3",
593
+ row: "flex items-center gap-3 min-h-7 text-sm",
594
+ rowKey: "flex-none w-24 text-fg-3",
595
+ rowValue: "flex-1 flex items-center gap-2 min-w-0 text-fg",
596
+ notice: "m-0 p-4 text-sm text-fg-3",
597
+ error: "m-0 p-4 whitespace-pre-wrap font-mono text-xs text-red",
598
+ th: "h-8 px-2.5 border-b border-line text-left text-xs font-medium text-fg-3 whitespace-nowrap",
599
+ td: "h-9 px-2.5 align-middle",
600
+ tr: "hover:bg-hover",
601
+ textarea: `block w-full min-h-20 px-2 py-1.5 rounded-md border-0 bg-field ring-1 ring-inset ring-line font-mono text-xs text-fg placeholder:text-fg-4 ${FOCUS}`,
602
+ pill: `inline-flex items-center gap-1.5 h-6 px-2 rounded-md border-0 font-medium text-xs whitespace-nowrap cursor-pointer ${FOCUS}`,
603
+ chip: "inline-flex items-center justify-center h-5 px-1.5 rounded-full ring-1 ring-inset ring-line-strong font-mono text-2xs font-semibold text-fg-2",
604
+ hint: "text-xs text-fg-3",
605
+ fail: "text-xs text-red",
606
+ item: "flex items-center gap-3 min-h-8 mx-1.5 px-2.5 rounded-md",
607
+ listButton: `flex items-center gap-2 w-full min-h-7 px-2.5 py-1 border-0 rounded-md bg-transparent text-left text-xs font-mono cursor-pointer hover:bg-hover ${FOCUS}`
608
+ };
609
+
610
+ // packages/devtools/src/panel/document.ts
611
+ var PANEL_CONFIG_ID = "hamur-devtools-config";
612
+ var escapeHtml = (text) => text.replace(/[&<>"]/g, (char) => `&#${char.charCodeAt(0)};`);
613
+ function panelDocument(config, error) {
614
+ const json = JSON.stringify(config).replace(/</g, "\\u003c");
615
+ const main = error === undefined ? "" : `<pre data-error class="${UI.error}">${escapeHtml(error)}</pre>`;
616
+ const script = error === undefined ? `<script type="module" src="${escapeHtml(`${config.baseURL}_hamur/devtools/panel.js`)}"></script>` : "";
617
+ const windowButton = error === undefined ? `<button type="button" data-window aria-label="Open in its own window" title="Open in its own window" class="inline-flex items-center justify-center size-7 border-0 rounded-md bg-transparent text-side-icon cursor-pointer hover:bg-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent">${WINDOW_ICON}</button>` : "";
618
+ const shortcut = config.shortcut === false ? "" : `<span class="flex-1"></span><kbd class="inline-flex items-center h-4 px-1 rounded bg-active font-sans font-medium text-2xs text-fg-4 leading-none">${escapeHtml(config.shortcut)}</kbd>`;
619
+ return `<!doctype html>
620
+ <html lang="en">
621
+ <head>
622
+ <meta charset="utf-8">
623
+ <meta name="viewport" content="width=device-width, initial-scale=1">
624
+ <title>Hamur devtools</title>
625
+ <style>${PANEL_CSS}</style>
626
+ </head>
627
+ <body class="flex bg-app text-fg text-sm">
628
+ <aside class="flex-none flex flex-col w-56 min-h-0">
629
+ <div data-drag class="flex-none flex items-center gap-2 h-12 px-3.5"><span class="inline-flex items-center justify-center size-5 rounded-md bg-accent text-app">${HAMUR_MARK}</span><span class="flex-1 font-medium text-sm">Hamur</span>${windowButton}</div>
630
+ <nav data-tabs aria-label="Devtools tabs" class="flex-1 min-h-0 overflow-auto flex flex-col px-2 pb-2"></nav>
631
+ <footer class="flex-none flex items-center gap-0.5 h-10 px-2.5 border-t border-line"><button type="button" data-settings aria-label="Settings" title="Settings" class="inline-flex items-center justify-center size-7 border-0 rounded-md bg-transparent text-side-icon cursor-pointer hover:bg-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent">${SETTINGS_ICON}</button>${shortcut}</footer>
632
+ </aside>
633
+ <main data-content class="flex-1 min-w-0 my-2 mr-2 flex flex-col rounded-lg bg-panel ring-1 ring-line overflow-hidden">${main}</main>
634
+ <script type="application/json" id="${PANEL_CONFIG_ID}">${json}</script>
635
+ ${script}
636
+ </body>
637
+ </html>
638
+ `;
639
+ }
640
+ var PANEL_HEADERS = {
641
+ "content-type": "text/html; charset=utf-8",
642
+ "cache-control": "no-store",
643
+ "content-security-policy": "frame-ancestors 'self'",
644
+ "x-frame-options": "SAMEORIGIN",
645
+ "referrer-policy": "no-referrer"
646
+ };
647
+
648
+ // packages/devtools/src/dev/handler.ts
649
+ var JSON_HEADERS = {
650
+ "content-type": "application/json",
651
+ "cache-control": "no-store",
652
+ "x-content-type-options": "nosniff"
653
+ };
654
+ var json = (body, status = 200, headers = {}) => new Response(JSON.stringify(body), { status, headers: { ...JSON_HEADERS, ...headers } });
655
+ var RPC_MAX_BYTES = 1024 * 1024;
656
+ var NOT_JSON = "The body of a devtools RPC call must be JSON";
657
+ async function readCapped(request) {
658
+ if (Number(request.headers.get("content-length") ?? 0) > RPC_MAX_BYTES)
659
+ return;
660
+ if (!request.body)
661
+ return "";
662
+ const reader = request.body.getReader();
663
+ const chunks = [];
664
+ let size = 0;
665
+ for (;; ) {
666
+ const { done, value } = await reader.read();
667
+ if (done)
668
+ break;
669
+ size += value.byteLength;
670
+ if (size > RPC_MAX_BYTES) {
671
+ await reader.cancel();
672
+ return;
673
+ }
674
+ chunks.push(value);
675
+ }
676
+ return new TextDecoder().decode(Buffer.concat(chunks));
677
+ }
678
+ async function answerRpc(rpc, encoded, request, log) {
679
+ let name;
680
+ try {
681
+ name = decodeURIComponent(encoded);
682
+ } catch {
683
+ name = encoded;
684
+ }
685
+ const fn = rpc.get(name);
686
+ if (!fn)
687
+ return json({ error: `No devtools RPC ${JSON.stringify(name)}` }, 404);
688
+ if (request.method !== "POST")
689
+ return json({ error: "Devtools RPC calls answer POST" }, 405, { allow: "POST" });
690
+ const type = request.headers.get("content-type");
691
+ if (type !== null && type.split(";")[0].trim().toLowerCase() !== "application/json")
692
+ return json({ error: NOT_JSON }, 400);
693
+ const text = await readCapped(request);
694
+ if (text === undefined)
695
+ return json({ error: `The body of a devtools RPC call is over ${RPC_MAX_BYTES} bytes` }, 413);
696
+ if (text !== "" && type === null)
697
+ return json({ error: NOT_JSON }, 400);
698
+ let args;
699
+ try {
700
+ args = text === "" ? undefined : JSON.parse(text);
701
+ } catch {
702
+ return json({ error: NOT_JSON }, 400);
703
+ }
704
+ let result;
705
+ try {
706
+ result = await fn.call(args);
707
+ } catch (error) {
708
+ const message = error instanceof Error ? error.message : String(error);
709
+ log(`devtools RPC ${name} threw: ${message}`);
710
+ return json({ error: message }, 500);
711
+ }
712
+ let body;
713
+ try {
714
+ body = JSON.stringify({ result });
715
+ } catch (error) {
716
+ return json({
717
+ error: `devtools RPC ${name} returned a value that is not JSON (${error instanceof Error ? error.message : String(error)})`
718
+ }, 500);
719
+ }
720
+ return new Response(body, { headers: JSON_HEADERS });
721
+ }
722
+ async function answerDataRoute(routes, name, request) {
723
+ let route = Object.hasOwn(routes, name) ? routes[name] : undefined;
724
+ let param;
725
+ if (!route) {
726
+ const slash = name.indexOf("/");
727
+ const parent = slash < 0 ? undefined : name.slice(0, slash);
728
+ const parentRoute = parent !== undefined && Object.hasOwn(routes, parent) ? routes[parent] : undefined;
729
+ if (!parentRoute?.param)
730
+ return;
731
+ route = parentRoute;
732
+ param = name.slice(slash + 1);
733
+ try {
734
+ param = decodeURIComponent(param);
735
+ } catch {}
736
+ }
737
+ const methods = Array.isArray(route.method) ? route.method : [route.method];
738
+ if (!methods.includes(request.method))
739
+ return json({ error: `Devtools data route ${JSON.stringify(name)} answers ${methods.join(", ")}` }, 405, {
740
+ allow: methods.join(", ")
741
+ });
742
+ const answer = await route.answer(request, param);
743
+ return answer instanceof Response ? answer : json(answer);
744
+ }
745
+ function createDevtoolsHandler(options) {
746
+ const prefix = `${options.config.baseURL}_hamur/devtools`;
747
+ return async (request) => {
748
+ const { pathname } = new URL(request.url);
749
+ if (pathname !== prefix && !pathname.startsWith(`${prefix}/`))
750
+ return;
751
+ const rest = pathname.slice(prefix.length + 1);
752
+ if (rest.startsWith("api/rpc/"))
753
+ return answerRpc(options.rpc, rest.slice("api/rpc/".length), request, options.log);
754
+ if (rest.startsWith("api/"))
755
+ return answerDataRoute(options.routes, rest.slice("api/".length), request);
756
+ if (request.method !== "GET" && request.method !== "HEAD")
757
+ return new Response(null, { status: 405, headers: { allow: "GET, HEAD", "cache-control": "no-store" } });
758
+ const built = await options.bundle.build();
759
+ if (rest === "")
760
+ return new Response(panelDocument(options.config, "error" in built ? built.error : undefined), {
761
+ headers: PANEL_HEADERS
762
+ });
763
+ if ("error" in built)
764
+ return new Response(built.error, {
765
+ status: 500,
766
+ headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" }
767
+ });
768
+ const file = built.files.get(rest);
769
+ if (!file)
770
+ return new Response(`No devtools file ${JSON.stringify(rest)}`, {
771
+ status: 404,
772
+ headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" }
773
+ });
774
+ return new Response(file, {
775
+ headers: { "content-type": "text/javascript; charset=utf-8", "cache-control": "no-store" }
776
+ });
777
+ };
778
+ }
779
+
780
+ // packages/devtools/src/dev/assets.ts
781
+ var shown = (rootDir, path) => {
782
+ if (!isAbsolute(path))
783
+ return path;
784
+ const inside = relative(rootDir, path);
785
+ return inside.startsWith("..") || isAbsolute(inside) ? path : inside.split(sep2).join("/");
786
+ };
787
+ var MAX_UPLOAD_BYTES = 50 * 1024 * 1024;
788
+ var MULTIPART_SLACK = 64 * 1024;
789
+ var TOO_LARGE = "File is over 50 MB";
790
+ var NOT_MULTIPART = "The body must be multipart/form-data with one file part";
791
+ var BAD_NAME = "A file name may not hold .. or a slash";
792
+ var EXTENSIONS = {
793
+ image: ["png", "jpg", "jpeg", "gif", "webp", "avif", "svg", "ico", "bmp", "tif", "tiff", "heic"],
794
+ font: ["woff", "woff2", "ttf", "otf", "eot"],
795
+ text: [
796
+ "txt",
797
+ "md",
798
+ "json",
799
+ "xml",
800
+ "csv",
801
+ "css",
802
+ "js",
803
+ "mjs",
804
+ "html",
805
+ "htm",
806
+ "webmanifest",
807
+ "yml",
808
+ "yaml",
809
+ "toml",
810
+ "map"
811
+ ],
812
+ other: []
813
+ };
814
+ var TYPES = new Map(Object.entries(EXTENSIONS).flatMap(([type, extensions]) => extensions.map((extension) => [`.${extension}`, type])));
815
+ var RASTER = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".avif", ".bmp", ".tif", ".tiff", ".heic"]);
816
+ var assetType = (path) => TYPES.get(extname(path).toLowerCase()) ?? "other";
817
+ async function imageSize(input) {
818
+ try {
819
+ const { width, height } = await new Bun.Image(input).metadata();
820
+ return { width, height };
821
+ } catch {
822
+ return;
823
+ }
824
+ }
825
+ async function assetRow(rootDir, baseURL, asset) {
826
+ let bytes;
827
+ let input;
828
+ if (asset.bytes) {
829
+ bytes = asset.bytes.length;
830
+ input = asset.bytes;
831
+ } else {
832
+ const file = Bun.file(asset.file);
833
+ const info = await file.stat().catch(() => {
834
+ return;
835
+ });
836
+ if (!info?.isFile())
837
+ return;
838
+ bytes = info.size;
839
+ input = file;
840
+ }
841
+ const type = assetType(asset.path);
842
+ const size = type === "image" && RASTER.has(extname(asset.path).toLowerCase()) ? await imageSize(input) : undefined;
843
+ return {
844
+ url: `${baseURL}${asset.path.slice(1)}`,
845
+ ...asset.file ? { file: shown(rootDir, asset.file) } : {},
846
+ bytes,
847
+ type,
848
+ ...size,
849
+ ...asset.source === "public" ? {} : { module: asset.module ?? (asset.source === "dir" ? "addPublicAssets" : "emitPublicAsset") }
850
+ };
851
+ }
852
+ async function assetsAnswer(rootDir, baseURL, assets) {
853
+ const rows = await Promise.all(assets.map((asset) => assetRow(rootDir, baseURL, asset)));
854
+ return rows.filter((row) => row !== undefined);
855
+ }
856
+ function nameProblem(name) {
857
+ if (name === "")
858
+ return "The file part has no name";
859
+ if (name.includes("..") || name.includes("/") || name.includes("\\"))
860
+ return BAD_NAME;
861
+ if (/[\u0000-\u001f\u007f]/.test(name))
862
+ return "A file name may not hold a control character";
863
+ if (name.startsWith("."))
864
+ return "A file name may not start with a dot";
865
+ return;
866
+ }
867
+ function capped(body, limit) {
868
+ let seen = 0;
869
+ const stream = body.pipeThrough(new TransformStream({
870
+ transform(chunk, controller) {
871
+ seen += chunk.byteLength;
872
+ if (seen > limit)
873
+ controller.error(new Error(TOO_LARGE));
874
+ else
875
+ controller.enqueue(chunk);
876
+ }
877
+ }));
878
+ return { stream, over: () => seen > limit };
879
+ }
880
+ var foldCase = (url) => url.normalize("NFC").toLowerCase();
881
+ var isCode = (error, code) => error?.code === code;
882
+ async function uploadAsset(request, options) {
883
+ const type = request.headers.get("content-type") ?? "";
884
+ if (!type.toLowerCase().startsWith("multipart/form-data") || !request.body)
885
+ return json({ error: NOT_MULTIPART }, 400);
886
+ const limit = MAX_UPLOAD_BYTES + MULTIPART_SLACK;
887
+ if (Number(request.headers.get("content-length") ?? 0) > limit)
888
+ return json({ error: TOO_LARGE }, 413);
889
+ const body = capped(request.body, limit);
890
+ let form;
891
+ try {
892
+ form = await new Response(body.stream, { headers: { "content-type": type } }).formData();
893
+ } catch {
894
+ return json({ error: body.over() ? TOO_LARGE : NOT_MULTIPART }, body.over() ? 413 : 400);
895
+ }
896
+ const parts = form.getAll("file");
897
+ const file = parts[0];
898
+ if (parts.length !== 1 || file === undefined || typeof file === "string")
899
+ return json({ error: NOT_MULTIPART }, 400);
900
+ if (file.size > MAX_UPLOAD_BYTES)
901
+ return json({ error: TOO_LARGE }, 413);
902
+ const problem = nameProblem(file.name);
903
+ if (problem)
904
+ return json({ error: problem }, 400);
905
+ const url = `${options.baseURL}${file.name}`;
906
+ const folded = foldCase(url);
907
+ const held = (await options.rows()).find((row) => row.module !== undefined && foldCase(row.url) === folded);
908
+ if (held)
909
+ return json({ error: `${url} comes from ${held.module}; module assets are read-only` }, 409);
910
+ await mkdir2(options.publicDir, { recursive: true });
911
+ const dir = await realpath(options.publicDir);
912
+ const target = join3(dir, file.name);
913
+ if (dirname(target) !== dir)
914
+ return json({ error: BAD_NAME }, 400);
915
+ const overwrite = new URL(request.url).searchParams.get("overwrite") === "1";
916
+ const existing = await lstat(target).catch(() => {
917
+ return;
918
+ });
919
+ if (existing && !existing.isFile())
920
+ return json({ error: `public/${file.name} is not a regular file` }, 409);
921
+ const exists = `public/${file.name} exists; send overwrite=1 to replace it`;
922
+ if (existing && !overwrite)
923
+ return json({ error: exists }, 409);
924
+ const temp = join3(dir, `.hamur-upload-${crypto.randomUUID()}`);
925
+ try {
926
+ await (await open(temp, "wx")).close();
927
+ await Bun.write(temp, file);
928
+ if (overwrite)
929
+ await rename(temp, target);
930
+ else {
931
+ const linked = await link(temp, target).then(() => true, (error) => {
932
+ if (isCode(error, "EEXIST"))
933
+ return false;
934
+ throw error;
935
+ });
936
+ if (!linked)
937
+ return json({ error: exists }, 409);
938
+ }
939
+ } finally {
940
+ await unlink(temp).catch(() => {});
941
+ }
942
+ const row = await assetRow(options.rootDir, options.baseURL, {
943
+ path: `/${file.name}`,
944
+ source: "public",
945
+ file: join3(options.publicDir, file.name)
946
+ });
947
+ return json(row, existing ? 200 : 201);
948
+ }
949
+
950
+ // packages/devtools/src/dev/bundle.ts
951
+ import { existsSync as existsSync2, realpathSync } from "node:fs";
952
+ import { dirname as dirname2, isAbsolute as isAbsolute2, resolve as resolve2 } from "node:path";
953
+ function viewsSource(views) {
954
+ return `export const views = {
955
+ ${views.map(({ name, entry }) => ` ${JSON.stringify(name)}: () => import(${JSON.stringify(entry)}),
956
+ `).join("")}};
957
+ `;
958
+ }
959
+ function createPanelBundle(entry, views = () => [], define = {}) {
960
+ const root = dirname2(dirname2(entry));
961
+ let built;
962
+ let inputs = new Set;
963
+ const realInputs = (input) => {
964
+ const candidates = isAbsolute2(input) ? [input] : [resolve2(root, input), resolve2(process.cwd(), input)];
965
+ return [...new Set(candidates.filter((path) => existsSync2(path)).map((path) => realpathSync(path)))];
966
+ };
967
+ async function run() {
968
+ const result = await Bun.build({
969
+ entrypoints: [entry],
970
+ root,
971
+ target: "browser",
972
+ format: "esm",
973
+ splitting: true,
974
+ minify: false,
975
+ sourcemap: "inline",
976
+ metafile: true,
977
+ naming: { entry: "panel.[ext]", chunk: "chunk-[hash].[ext]" },
978
+ define,
979
+ throw: false,
980
+ plugins: [
981
+ {
982
+ name: "hamur-devtools-views",
983
+ setup(build) {
984
+ build.onResolve({ filter: /^#hamur\/devtools-views$/ }, () => ({
985
+ path: "views",
986
+ namespace: "hamur-devtools"
987
+ }));
988
+ build.onLoad({ filter: /^views$/, namespace: "hamur-devtools" }, () => ({
989
+ contents: viewsSource(views()),
990
+ loader: "js"
991
+ }));
992
+ }
993
+ }
994
+ ]
995
+ }).catch((error) => ({
996
+ success: false,
997
+ logs: [error],
998
+ outputs: [],
999
+ metafile: undefined
1000
+ }));
1001
+ if (!result.success)
1002
+ return {
1003
+ error: `The devtools panel build failed:
1004
+ ${result.logs.map((log) => log instanceof Error ? log.message : String(log)).join(`
1005
+ `)}`
1006
+ };
1007
+ inputs = new Set(Object.keys(result.metafile?.inputs ?? {}).flatMap(realInputs));
1008
+ return { files: new Map(result.outputs.map((output) => [output.path.replace(/^\.\//, ""), output])) };
1009
+ }
1010
+ return {
1011
+ build: () => built ??= run().then((result) => {
1012
+ if ("error" in result)
1013
+ built = undefined;
1014
+ return result;
1015
+ }),
1016
+ drop(file) {
1017
+ if (!built || !inputs.has(existsSync2(file) ? realpathSync(file) : file))
1018
+ return false;
1019
+ built = undefined;
1020
+ inputs = new Set;
1021
+ return true;
1022
+ }
1023
+ };
1024
+ }
1025
+
1026
+ // packages/devtools/src/dev/config.ts
1027
+ import { REDACTED } from "hamur/kit";
1028
+
1029
+ // packages/devtools/src/mask.ts
1030
+ var MASKED = "••••";
1031
+ var TOO_DEEP = "[Max depth]";
1032
+ var CIRCULAR = "[Circular]";
1033
+
1034
+ // packages/devtools/src/dev/config.ts
1035
+ var MAX_DEPTH = 8;
1036
+ var isPlain = (value) => {
1037
+ const proto = Object.getPrototypeOf(value);
1038
+ return proto === Object.prototype || proto === null;
1039
+ };
1040
+ function serialize(value, redactor, depth = 0, seen = []) {
1041
+ if (typeof value === "function")
1042
+ return `[Function ${value.name || "anonymous"}]`;
1043
+ if (typeof value === "bigint")
1044
+ return `${value}n`;
1045
+ if (typeof value === "symbol")
1046
+ return value.toString();
1047
+ if (typeof value === "number" && !Number.isFinite(value))
1048
+ return String(value);
1049
+ if (value === null || typeof value !== "object")
1050
+ return value;
1051
+ if (seen.includes(value))
1052
+ return CIRCULAR;
1053
+ if (depth >= MAX_DEPTH)
1054
+ return TOO_DEEP;
1055
+ if (value instanceof Date)
1056
+ return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
1057
+ if (value instanceof RegExp || value instanceof URL)
1058
+ return String(value);
1059
+ const inner = [...seen, value];
1060
+ if (Array.isArray(value))
1061
+ return value.map((item) => serialize(item, redactor, depth + 1, inner) ?? null);
1062
+ if (value instanceof Set)
1063
+ return [...value].map((item) => serialize(item, redactor, depth + 1, inner) ?? null);
1064
+ if (value instanceof Map)
1065
+ return [...value].map(([key, item]) => [
1066
+ serialize(key, redactor, depth + 1, inner),
1067
+ typeof key === "string" && redactor.test(key) ? REDACTED : serialize(item, redactor, depth + 1, inner)
1068
+ ]);
1069
+ if (value instanceof Error)
1070
+ return `[${value.name}: ${value.message}]`;
1071
+ if (!isPlain(value))
1072
+ return `[${value.constructor?.name || "Object"}]`;
1073
+ const result = {};
1074
+ for (const [key, item] of Object.entries(value)) {
1075
+ if (item === undefined)
1076
+ continue;
1077
+ result[key] = redactor.test(key) ? REDACTED : serialize(item, redactor, depth + 1, inner);
1078
+ }
1079
+ return result;
1080
+ }
1081
+ function maskPrivate(value, redactor, depth = 0) {
1082
+ if (value === null || typeof value !== "object")
1083
+ return MASKED;
1084
+ if (depth >= MAX_DEPTH)
1085
+ return TOO_DEEP;
1086
+ if (Array.isArray(value) || !isPlain(value))
1087
+ return MASKED;
1088
+ const result = {};
1089
+ for (const [key, item] of Object.entries(value))
1090
+ result[key] = redactor.test(key) ? REDACTED : maskPrivate(item, redactor, depth + 1);
1091
+ return result;
1092
+ }
1093
+ var withoutPublic = (config) => Object.fromEntries(Object.entries(config).filter(([key]) => key !== "public"));
1094
+ function configAnswer(options, server, redactor) {
1095
+ const written = options.runtimeConfig ?? {};
1096
+ const shown = serialize({ ...options, runtimeConfig: null }, redactor);
1097
+ shown.runtimeConfig = {
1098
+ public: serialize(written.public ?? {}, redactor),
1099
+ ...maskPrivate(withoutPublic(written), redactor)
1100
+ };
1101
+ return {
1102
+ options: shown,
1103
+ runtimeConfig: {
1104
+ public: serialize(server.runtimeConfig.public, redactor),
1105
+ private: maskPrivate(withoutPublic(server.runtimeConfig), redactor)
1106
+ }
1107
+ };
1108
+ }
1109
+ var lookup = (root, keys) => {
1110
+ let node = root;
1111
+ for (const key of keys) {
1112
+ if (node === null || typeof node !== "object" || !Object.hasOwn(node, key))
1113
+ return { found: false };
1114
+ node = node[key];
1115
+ }
1116
+ return { found: true, value: node };
1117
+ };
1118
+ function revealAnswer(server, path, redactor) {
1119
+ const keys = typeof path === "string" && path !== "" ? path.split(".") : [];
1120
+ if (!keys.length || keys[0] === "public")
1121
+ throw new Error(`Reveal takes the dot path of a private runtime config value (got ${JSON.stringify(path)})`);
1122
+ const hit = lookup(withoutPublic(server.runtimeConfig), keys);
1123
+ if (!hit.found)
1124
+ throw new Error(`No private runtime config value at ${JSON.stringify(path)}`);
1125
+ if (keys.some((key) => redactor.test(key)))
1126
+ return { value: REDACTED };
1127
+ return { value: serialize(hit.value, redactor) };
1128
+ }
1129
+ var kind = (value) => value === null ? "null" : Array.isArray(value) ? "array" : typeof value;
1130
+ function jsonSafe(value, depth, redactor) {
1131
+ if (value === null || typeof value === "string" || typeof value === "boolean")
1132
+ return true;
1133
+ if (typeof value === "number")
1134
+ return Number.isFinite(value);
1135
+ if (typeof value !== "object" || depth >= MAX_DEPTH || !Array.isArray(value) && !isPlain(value))
1136
+ return false;
1137
+ return Object.entries(value).every(([key, item]) => (Array.isArray(value) || !redactor.test(key)) && jsonSafe(item, depth + 1, redactor));
1138
+ }
1139
+ function publicEdit(server, args, redactor) {
1140
+ const { path, value } = typeof args === "object" && args !== null ? args : {};
1141
+ if (typeof path !== "string" || !path.startsWith("public."))
1142
+ throw new Error(`Only runtimeConfig.public values can be edited (got ${JSON.stringify(path)})`);
1143
+ if (value === undefined)
1144
+ throw new Error(`The edit of ${JSON.stringify(path)} needs a value`);
1145
+ const keys = path.split(".");
1146
+ const hit = lookup(server.runtimeConfig, keys);
1147
+ if (!hit.found)
1148
+ throw new Error(`runtimeConfig has no key ${JSON.stringify(path)}`);
1149
+ if (keys.some((key) => redactor.test(key)) || !jsonSafe(hit.value, keys.length - 1, redactor))
1150
+ throw new Error(`runtimeConfig ${JSON.stringify(path)} is shown redacted or cut short, so it cannot be edited`);
1151
+ if (kind(value) !== kind(hit.value))
1152
+ throw new Error(`The value of ${JSON.stringify(path)} must be ${kind(hit.value)} like the current one (got ${kind(value)})`);
1153
+ return { path, value };
1154
+ }
1155
+
1156
+ // packages/devtools/src/dev/server-routes.ts
1157
+ function serverRoutesAnswer(table, served) {
1158
+ return table.serverRoutes.map((route) => {
1159
+ const bodySchema = served?.bodySchemas[`${route.method} ${route.path}`];
1160
+ return { ...route, middleware: served?.middleware ?? [], ...bodySchema ? { bodySchema } : {} };
1161
+ });
1162
+ }
1163
+
1164
+ // packages/devtools/src/dev/timeline.ts
1165
+ import { REDACTED as REDACTED2 } from "hamur/kit";
1166
+ var TRACE = /^[0-9a-f]{32}$/;
1167
+ function traceOf(args) {
1168
+ const trace = typeof args === "object" && args !== null ? args.trace : undefined;
1169
+ if (trace === undefined || trace === null || trace === "")
1170
+ throw new Error("The trace query parameter is missing");
1171
+ if (typeof trace !== "string" || !TRACE.test(trace))
1172
+ throw new Error("The trace query parameter must be a 32-character hex trace id");
1173
+ return trace;
1174
+ }
1175
+ function spansAnswer(spans, redactor) {
1176
+ return spans.map((span) => ({
1177
+ traceId: span.traceId,
1178
+ spanId: span.spanId,
1179
+ ...span.parentSpanId === undefined ? {} : { parentSpanId: span.parentSpanId },
1180
+ name: span.name,
1181
+ kind: span.kind,
1182
+ startTime: span.startTime,
1183
+ endTime: span.endTime,
1184
+ status: span.status,
1185
+ attributes: Object.fromEntries(Object.entries(span.attributes).map(([key, value]) => [key, redactor.test(key) ? REDACTED2 : value])),
1186
+ events: span.events.map(({ name, time }) => ({ name, time }))
1187
+ }));
1188
+ }
1189
+
1190
+ // packages/devtools/src/dev/modules.ts
1191
+ import { existsSync as existsSync3, readFileSync } from "node:fs";
1192
+ import { dirname as dirname3, isAbsolute as isAbsolute3, join as join4, relative as relative2 } from "node:path";
1193
+ function moduleVersion(file, rootDir) {
1194
+ if (!file)
1195
+ return null;
1196
+ for (let dir = dirname3(file);dir !== rootDir && dir !== dirname3(dir); dir = dirname3(dir)) {
1197
+ const manifest = join4(dir, "package.json");
1198
+ if (!existsSync3(manifest))
1199
+ continue;
1200
+ try {
1201
+ const version = JSON.parse(readFileSync(manifest, "utf8")).version;
1202
+ if (typeof version === "string")
1203
+ return version;
1204
+ } catch {}
1205
+ }
1206
+ return null;
1207
+ }
1208
+ function modulesAnswer(modules, rootDir, redactor) {
1209
+ return modules.map((module) => ({
1210
+ name: module.name,
1211
+ version: moduleVersion(module.file, rootDir),
1212
+ configKey: module.configKey ?? null,
1213
+ options: serialize(module.options, redactor)
1214
+ }));
1215
+ }
1216
+ var shown2 = (file, rootDir) => {
1217
+ const path = relative2(rootDir, file);
1218
+ return isAbsolute3(file) && !path.startsWith("..") && !isAbsolute3(path) ? path.split("\\").join("/") : file;
1219
+ };
1220
+ function pluginsAnswer(app, server, rootDir) {
1221
+ return {
1222
+ app: app.map(({ name, file, mode, order }) => ({ name, file: shown2(file, rootDir), mode, order })),
1223
+ server: server.map(({ file, module }) => ({
1224
+ file: shown2(file, rootDir),
1225
+ ...module === undefined ? {} : { module }
1226
+ }))
1227
+ };
1228
+ }
1229
+
1230
+ // packages/devtools/src/dev/overview.ts
1231
+ import { existsSync as existsSync4, readFileSync as readFileSync2 } from "node:fs";
1232
+ import { dirname as dirname4, join as join5 } from "node:path";
1233
+ var LIBRARIES = { html: undefined, solid: "solid-js" };
1234
+ function packageVersion(specifier, name, from) {
1235
+ let dir;
1236
+ try {
1237
+ dir = dirname4(Bun.resolveSync(specifier, from));
1238
+ } catch {
1239
+ return null;
1240
+ }
1241
+ for (;; ) {
1242
+ const file = join5(dir, "package.json");
1243
+ if (existsSync4(file)) {
1244
+ const pkg = JSON.parse(readFileSync2(file, "utf8"));
1245
+ if (pkg.name === name)
1246
+ return pkg.version ?? null;
1247
+ }
1248
+ const parent = dirname4(dir);
1249
+ if (parent === dir)
1250
+ return null;
1251
+ dir = parent;
1252
+ }
1253
+ }
1254
+ var pageCount = (routes) => routes.reduce((sum, route) => sum + (route.pathless ? 0 : 1) + pageCount(route.children ?? []), 0);
1255
+ function overviewAnswer(hamur, serverPlugins) {
1256
+ const { rootDir, framework } = hamur.options;
1257
+ const library = LIBRARIES[framework] ?? (framework in LIBRARIES ? undefined : framework);
1258
+ return {
1259
+ versions: {
1260
+ hamur: packageVersion("hamur/kit", "hamur", rootDir),
1261
+ adapter: packageVersion(`@hamur/adapter-${framework}`, `@hamur/adapter-${framework}`, rootDir),
1262
+ library: library ? packageVersion(library, library, rootDir) : null,
1263
+ bun: Bun.version
1264
+ },
1265
+ counts: {
1266
+ pages: pageCount(hamur.routes),
1267
+ serverRoutes: hamur.serverRoutes.length,
1268
+ modules: hamur.options.modules.length,
1269
+ appPlugins: hamur.plugins.length,
1270
+ serverPlugins: serverPlugins.count ?? null
1271
+ }
1272
+ };
1273
+ }
1274
+
1275
+ // packages/devtools/src/dev/processes.ts
1276
+ var ACTION = /^(.+)\/(restart|kill)$/;
1277
+ function createProcessesRoute(processes) {
1278
+ return {
1279
+ method: ["GET", "POST"],
1280
+ param: true,
1281
+ async answer(request, param) {
1282
+ if (param === undefined)
1283
+ return request.method === "GET" ? processes.list() : json({ error: 'Devtools data route "processes" answers GET' }, 405, { allow: "GET" });
1284
+ const match = ACTION.exec(param);
1285
+ if (!match)
1286
+ return json({
1287
+ error: `No devtools data route "processes/${param}"; use processes/<name>/restart or processes/<name>/kill`
1288
+ }, 404);
1289
+ if (request.method !== "POST")
1290
+ return json({ error: `Devtools data route "processes/<name>/${match[2]}" answers POST` }, 405, {
1291
+ allow: "POST"
1292
+ });
1293
+ const name = match[1];
1294
+ const done = match[2] === "restart" ? await processes.restart(name) : await processes.kill(name);
1295
+ if (!done)
1296
+ return json({ error: `No dev process ${JSON.stringify(name)}` }, 404);
1297
+ return new Response(null, { status: 204, headers: { "cache-control": "no-store" } });
1298
+ }
1299
+ };
1300
+ }
1301
+
1302
+ // packages/devtools/src/dev/tasks.ts
1303
+ import { isAbsolute as isAbsolute4, relative as relative3 } from "node:path";
1304
+ function tasksAnswer(tasks, scheduled, rootDir, now = Date.now()) {
1305
+ const next = (cron) => {
1306
+ try {
1307
+ return Bun.cron.parse(cron, now, { tz: "UTC" })?.getTime();
1308
+ } catch {
1309
+ return;
1310
+ }
1311
+ };
1312
+ return {
1313
+ tasks: tasks.map(({ name, file, description, listener }) => {
1314
+ const shown = relative3(rootDir, file);
1315
+ return {
1316
+ name,
1317
+ ...description === undefined ? {} : { description },
1318
+ file: shown.startsWith("..") || isAbsolute4(shown) ? file : shown.replaceAll("\\", "/"),
1319
+ ...listener === undefined ? {} : { listener },
1320
+ schedules: Object.entries(scheduled).filter(([, value]) => typeof value === "string" ? value === name : value.includes(name)).map(([cron]) => {
1321
+ const at = next(cron);
1322
+ return { cron, ...at === undefined ? {} : { next: at } };
1323
+ })
1324
+ };
1325
+ })
1326
+ };
1327
+ }
1328
+ var USE = "use tasks/runs, tasks/pending or tasks/cancel";
1329
+ function createTasksRoute(rpc) {
1330
+ const runs = () => rpc.get("devtools:task-runs").call(undefined);
1331
+ const only = (route, method, request) => request.method === method ? undefined : json({ error: `Devtools data route "tasks/${route}" answers ${method}` }, 405, { allow: method });
1332
+ return {
1333
+ method: ["GET", "POST"],
1334
+ param: true,
1335
+ async answer(request, param) {
1336
+ if (param === "runs")
1337
+ return only(param, "GET", request) ?? { runs: await runs() };
1338
+ if (param === "pending")
1339
+ return only(param, "GET", request) ?? {
1340
+ runs: (await runs()).filter((run) => run.status === "pending").sort((a, b) => (a.startsAt ?? a.createdAt) - (b.startsAt ?? b.createdAt))
1341
+ };
1342
+ if (param !== "cancel")
1343
+ return json({ error: `No devtools data route "tasks${param === undefined ? "" : `/${param}`}"; ${USE}` }, 404);
1344
+ const refused = only(param, "POST", request);
1345
+ if (refused)
1346
+ return refused;
1347
+ const body = await request.json().catch(() => {
1348
+ return;
1349
+ });
1350
+ const id = typeof body === "object" && body !== null ? body.id : undefined;
1351
+ if (typeof id !== "string")
1352
+ return json({ error: "The body must be a JSON object { id }" }, 400);
1353
+ const run = (await runs()).find((entry) => entry.id === id);
1354
+ if (!run)
1355
+ return json({ error: `No task run "${id}"` }, 404);
1356
+ if (run.status !== "pending")
1357
+ return json({ error: `Task run "${id}" is ${run.status}; only a pending run can be cancelled` }, 409);
1358
+ let cancelled;
1359
+ try {
1360
+ cancelled = await rpc.get("devtools:task-cancel").call({ id });
1361
+ } catch (error) {
1362
+ return json({ error: error instanceof Error ? error.message : String(error) }, 504);
1363
+ }
1364
+ if (cancelled !== true)
1365
+ return json({ error: `Task run "${id}" started before the cancel reached it` }, 409);
1366
+ return new Response(null, { status: 204, headers: { "cache-control": "no-store" } });
1367
+ }
1368
+ };
1369
+ }
1370
+
1371
+ // packages/devtools/src/dev/virtual.ts
1372
+ var messageOf = (error) => error instanceof Error ? error.message : String(error);
1373
+ async function virtualAnswer(hamur) {
1374
+ const templates = hamur.templates;
1375
+ const made = new Set(templates.map((template) => `#hamur/${template.filename}`));
1376
+ const read = async (get) => {
1377
+ try {
1378
+ return await get();
1379
+ } catch (error) {
1380
+ return `Could not read this source: ${messageOf(error)}`;
1381
+ }
1382
+ };
1383
+ const modules = await Promise.all(hamur.vfs.ids().filter((id) => !made.has(id)).toSorted().map(async (id) => ({ id, source: await read(() => hamur.vfs.source(id, "client")) })));
1384
+ const files = await Promise.all(templates.toSorted((a, b) => a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0).map(async (template) => ({
1385
+ id: `.hamur/${template.filename}`,
1386
+ source: await read(() => template.getContents(hamur)),
1387
+ ...template.write ? { file: `.hamur/${template.filename}` } : {}
1388
+ })));
1389
+ return [...modules, ...files];
1390
+ }
1391
+
1392
+ // packages/devtools/src/panel/settings.ts
1393
+ var PLACEMENTS = [
1394
+ "bottom-center",
1395
+ "bottom-left",
1396
+ "bottom-right",
1397
+ "top-center",
1398
+ "top-left",
1399
+ "top-right"
1400
+ ];
1401
+
1402
+ // packages/devtools/src/toolbar/shortcut.ts
1403
+ var MODIFIERS = ["ctrl", "alt", "shift", "meta"];
1404
+ function parseShortcut(text) {
1405
+ const parts = text.toLowerCase().split("+").map((part) => part.trim());
1406
+ const key = parts.pop() ?? "";
1407
+ const shortcut = { ctrl: false, alt: false, shift: false, meta: false, code: "" };
1408
+ for (const part of parts) {
1409
+ if (!MODIFIERS.includes(part) || shortcut[part])
1410
+ return;
1411
+ shortcut[part] = true;
1412
+ }
1413
+ if (/^[a-z]$/.test(key))
1414
+ shortcut.code = `Key${key.toUpperCase()}`;
1415
+ else if (/^[0-9]$/.test(key))
1416
+ shortcut.code = `Digit${key}`;
1417
+ else if (/^f(?:[1-9]|1[0-2])$/.test(key))
1418
+ shortcut.code = key.toUpperCase();
1419
+ else
1420
+ return;
1421
+ return shortcut;
1422
+ }
1423
+
1424
+ // packages/devtools/src/options.ts
1425
+ import { DiagnosticError } from "hamur/kit";
1426
+ var show = (value) => JSON.stringify(value) ?? String(value);
1427
+ function resolveOptions(input) {
1428
+ const { enabled = true, shortcut = "shift+alt+d", placement = "bottom-center" } = input ?? {};
1429
+ if (typeof enabled !== "boolean")
1430
+ throw new DiagnosticError("HAMUR_E5601", `devtools.enabled must be a boolean (got ${show(enabled)})`);
1431
+ if (shortcut !== false && (typeof shortcut !== "string" || !parseShortcut(shortcut)))
1432
+ throw new DiagnosticError("HAMUR_E5602", `devtools.shortcut must be a key combination such as "shift+alt+d", or false (got ${show(shortcut)})`);
1433
+ if (!PLACEMENTS.includes(placement))
1434
+ throw new DiagnosticError("HAMUR_E5603", `devtools.placement must be one of ${PLACEMENTS.map((name) => `"${name}"`).join(", ")} (got ${show(placement)})`);
1435
+ return { enabled, shortcut, placement };
1436
+ }
1437
+
1438
+ // packages/devtools/src/module.ts
1439
+ function tabsAnswer(registry) {
1440
+ return {
1441
+ tabs: registry.tabs.map(({ name, title, icon, view, module }) => ({
1442
+ name,
1443
+ title,
1444
+ icon,
1445
+ view: view.type === "module" ? { type: "module" } : view,
1446
+ module
1447
+ })),
1448
+ apps: registry.apps.map(({ name, title, icon, module }) => ({ name, title, icon, module }))
1449
+ };
1450
+ }
1451
+ var NOT_SERVING = "No server process serves yet; the config shows once the server is built";
1452
+ var readJson = (request) => request.json().catch(() => {
1453
+ throw new Error("The body of a devtools data route must be JSON");
1454
+ });
1455
+ function rpcRoute(registry, method, name, args = () => {
1456
+ return;
1457
+ }) {
1458
+ return {
1459
+ method,
1460
+ async answer(request) {
1461
+ try {
1462
+ return await registry.rpc.get(name).call(await args(request));
1463
+ } catch (error) {
1464
+ return json({ error: error instanceof Error ? error.message : String(error) }, 400);
1465
+ }
1466
+ }
1467
+ };
1468
+ }
1469
+ function appsSource(registry) {
1470
+ const apps = registry.apps.map(({ name, title, icon, entry }) => ` { name: ${JSON.stringify(name)}, title: ${JSON.stringify(title)}, icon: ${JSON.stringify(icon)}, load: () => import(${JSON.stringify(entry)}) },
1471
+ `);
1472
+ return `export const apps = [
1473
+ ${apps.join("")}];
1474
+ `;
1475
+ }
1476
+ var module_default = defineModule({
1477
+ meta: { name: "devtools", configKey: "devtools" },
1478
+ setup(input, hamur) {
1479
+ const options = resolveOptions(input);
1480
+ if (!hamur.options.dev || !options.enabled)
1481
+ return;
1482
+ const resolver = createResolver(new URL("../../src/module.ts", import.meta.url).href);
1483
+ const registry = useDevtoolsRegistry();
1484
+ const context = useHamur();
1485
+ addDevtoolsTab({
1486
+ name: "overview",
1487
+ title: "Overview",
1488
+ icon: TAB_ICONS.overview,
1489
+ view: { type: "module", entry: resolver.resolve("./tabs/overview.ts") }
1490
+ });
1491
+ extendDevtoolsRpc("devtools:overview", () => overviewAnswer(context, useServerPlugins()));
1492
+ addDevtoolsTab({
1493
+ name: "pages",
1494
+ title: "Pages",
1495
+ icon: TAB_ICONS.pages,
1496
+ view: { type: "module", entry: resolver.resolve("./tabs/pages.ts") }
1497
+ });
1498
+ extendDevtoolsRpc("devtools:routes", () => useDevRouteTable());
1499
+ extendDevtoolsRpc("devtools:match", (args) => {
1500
+ if (typeof args?.path !== "string")
1501
+ throw new Error("devtools:match needs { path: string }");
1502
+ return matchDevRoute(args.path).then((match) => match ?? null);
1503
+ });
1504
+ addDevtoolsTab({
1505
+ name: "payload",
1506
+ title: "Payload and state",
1507
+ icon: TAB_ICONS.payload,
1508
+ view: { type: "module", entry: resolver.resolve("./tabs/payload.ts") }
1509
+ });
1510
+ addDevtoolsTab({
1511
+ name: "config",
1512
+ title: "Config",
1513
+ icon: TAB_ICONS.config,
1514
+ view: { type: "module", entry: resolver.resolve("./tabs/config.ts") }
1515
+ });
1516
+ addDevtoolsTab({
1517
+ name: "server-routes",
1518
+ title: "Server routes",
1519
+ icon: TAB_ICONS["server-routes"],
1520
+ view: { type: "module", entry: resolver.resolve("./tabs/server-routes.ts") }
1521
+ });
1522
+ extendDevtoolsRpc("devtools:server-routes", async () => serverRoutesAnswer(await useDevRouteTable(), await useDevServerRoutes()));
1523
+ addDevtoolsTab({
1524
+ name: "storage",
1525
+ title: "Storage",
1526
+ icon: TAB_ICONS.storage,
1527
+ view: { type: "module", entry: resolver.resolve("./tabs/storage.ts") }
1528
+ });
1529
+ addServer(resolver.resolve("./server/index.ts"));
1530
+ addDevtoolsTab({
1531
+ name: "assets",
1532
+ title: "Assets",
1533
+ icon: TAB_ICONS.assets,
1534
+ view: { type: "module", entry: resolver.resolve("./tabs/assets.ts") }
1535
+ });
1536
+ extendDevtoolsRpc("devtools:assets", async () => assetsAnswer(hamur.options.rootDir, hamur.options.app.baseURL, await useDevPublicAssets()));
1537
+ addDevtoolsTab({
1538
+ name: "tasks",
1539
+ title: "Tasks",
1540
+ icon: TAB_ICONS.tasks,
1541
+ view: { type: "module", entry: resolver.resolve("./tabs/tasks.ts") }
1542
+ });
1543
+ extendDevtoolsRpc("devtools:tasks", () => tasksAnswer(hamur.tasks, hamur.options.scheduledTasks, hamur.options.rootDir));
1544
+ extendDevtoolsRpc("devtools:task-runs", () => useDevTaskRuns());
1545
+ extendDevtoolsRpc("devtools:task-cancel", (args) => cancelDevTaskRun(String(args?.id)));
1546
+ const policies = hasPolicies(hamur.options);
1547
+ if (policies)
1548
+ addDevtoolsTab({
1549
+ name: "authz",
1550
+ title: "Authorization",
1551
+ icon: TAB_ICONS.authz,
1552
+ view: { type: "module", entry: resolver.resolve("./tabs/authz.ts") }
1553
+ });
1554
+ const redactor = createRedactor(hamur.options.server.logRedact);
1555
+ addDevtoolsTab({
1556
+ name: "timeline",
1557
+ title: "Timeline",
1558
+ icon: TAB_ICONS.timeline,
1559
+ view: { type: "module", entry: resolver.resolve("./tabs/timeline.ts") }
1560
+ });
1561
+ extendDevtoolsRpc("devtools:spans", (args) => spansAnswer(useDevSpans(traceOf(args)), redactor));
1562
+ extendDevtoolsRpc("devtools:hooks", () => useDevHooks());
1563
+ addDevtoolsTab({
1564
+ name: "plugins",
1565
+ title: "Plugins",
1566
+ icon: TAB_ICONS.plugins,
1567
+ view: { type: "module", entry: resolver.resolve("./tabs/plugins.ts") }
1568
+ });
1569
+ extendDevtoolsRpc("devtools:plugins", () => pluginsAnswer(useAppPlugins(), useServerPlugins().files, hamur.options.rootDir));
1570
+ addDevtoolsTab({
1571
+ name: "modules",
1572
+ title: "Modules",
1573
+ icon: TAB_ICONS.modules,
1574
+ view: { type: "module", entry: resolver.resolve("./tabs/modules.ts") }
1575
+ });
1576
+ extendDevtoolsRpc("devtools:modules", () => modulesAnswer(useInstalledModules(), hamur.options.rootDir, redactor));
1577
+ addDevtoolsTab({
1578
+ name: "inspect",
1579
+ title: "Inspect",
1580
+ icon: TAB_ICONS.inspect,
1581
+ view: { type: "module", entry: resolver.resolve("./tabs/inspect.ts") }
1582
+ });
1583
+ extendDevtoolsRpc("devtools:virtual", () => virtualAnswer(hamur));
1584
+ addDevtoolsTab({
1585
+ name: "analyze",
1586
+ title: "Analyze",
1587
+ icon: TAB_ICONS.analyze,
1588
+ view: { type: "module", entry: resolver.resolve("./tabs/analyze.ts") }
1589
+ });
1590
+ const analyzer = createAnalyzer({ dir: join6(hamur.options.cacheDir, "analyze"), build: () => runDevAnalyze() });
1591
+ extendDevtoolsRpc("devtools:analyze", () => analyzer.run());
1592
+ const analyzeRoute = {
1593
+ method: ["GET", "POST"],
1594
+ param: true,
1595
+ async answer(request, id) {
1596
+ try {
1597
+ if (id !== undefined)
1598
+ return request.method === "GET" ? await analyzer.read(id) : json({ error: 'Devtools data route "analyze/<id>" answers GET' }, 405, { allow: "GET" });
1599
+ return request.method === "POST" ? await registry.rpc.get("devtools:analyze").call(undefined) : await analyzer.list();
1600
+ } catch (error) {
1601
+ return json({ error: error instanceof Error ? error.message : String(error) }, error instanceof AnalyzeError ? error.status : 500);
1602
+ }
1603
+ }
1604
+ };
1605
+ addDevtoolsTab({
1606
+ name: "terminals",
1607
+ title: "Terminals and logs",
1608
+ icon: TAB_ICONS.terminals,
1609
+ view: { type: "module", entry: resolver.resolve("./tabs/terminals.ts") }
1610
+ });
1611
+ addDevtoolsTab({
1612
+ name: "audit",
1613
+ title: "Audit",
1614
+ icon: TAB_ICONS.audit,
1615
+ view: { type: "module", entry: resolver.resolve("./tabs/audit.ts") }
1616
+ });
1617
+ addDevtoolsTab({
1618
+ name: "seo",
1619
+ title: "SEO",
1620
+ icon: TAB_ICONS.seo,
1621
+ view: { type: "module", entry: resolver.resolve("./tabs/seo.ts") }
1622
+ });
1623
+ const processesRoute = createProcessesRoute(registry.processes);
1624
+ const serverConfig = async () => {
1625
+ const found = await useDevServerConfig();
1626
+ if (!found)
1627
+ throw new Error(NOT_SERVING);
1628
+ return found;
1629
+ };
1630
+ extendDevtoolsRpc("devtools:config", async () => configAnswer(hamur.options, await serverConfig(), redactor));
1631
+ extendDevtoolsRpc("devtools:config-reveal", async (args) => revealAnswer(await serverConfig(), args?.path, redactor));
1632
+ extendDevtoolsRpc("devtools:config-runtime", async (args) => {
1633
+ const edit = publicEdit(await serverConfig(), args, redactor);
1634
+ await setDevRuntimeConfig(edit.path, edit.value);
1635
+ return edit;
1636
+ });
1637
+ extendDevtoolsRpc("devtools:config-reset", async () => {
1638
+ await resetDevRuntimeConfig();
1639
+ return null;
1640
+ });
1641
+ addDevtoolsApp({
1642
+ name: "locator",
1643
+ title: "Open component source",
1644
+ icon: LOCATOR_ICON,
1645
+ entry: resolver.resolve("./apps/locator.ts")
1646
+ });
1647
+ const config = { baseURL: hamur.options.app.baseURL, shortcut: options.shortcut, placement: options.placement };
1648
+ addTemplate({
1649
+ filename: "devtools/config",
1650
+ getContents: () => Object.entries(config).map(([key, value]) => `export const ${key} = ${JSON.stringify(value)};
1651
+ `).join("")
1652
+ });
1653
+ addTemplate({ filename: "devtools/apps", getContents: () => appsSource(registry) });
1654
+ addAppPlugin({ src: resolver.resolve("./client.ts"), mode: "client" });
1655
+ const views = () => registry.tabs.flatMap(({ name, view }) => view.type === "module" ? [{ name, entry: view.entry }] : []);
1656
+ const bundle = createPanelBundle(resolver.resolve("./panel/index.ts"), views, {
1657
+ "import.meta.appId": JSON.stringify(hamur.options.appId)
1658
+ });
1659
+ const logger = useLogger();
1660
+ const assetUpload = {
1661
+ rootDir: hamur.options.rootDir,
1662
+ publicDir: hamur.options.publicDir,
1663
+ baseURL: hamur.options.app.baseURL,
1664
+ rows: () => registry.rpc.get("devtools:assets").call(undefined)
1665
+ };
1666
+ addDevServerHandler({
1667
+ route: "/_hamur/devtools/",
1668
+ handler: createDevtoolsHandler({
1669
+ config,
1670
+ bundle,
1671
+ routes: {
1672
+ tabs: { method: "GET", answer: () => tabsAnswer(registry) },
1673
+ overview: { method: "GET", answer: () => registry.rpc.get("devtools:overview").call(undefined) },
1674
+ routes: { method: "GET", answer: () => registry.rpc.get("devtools:routes").call(undefined) },
1675
+ "server-routes": rpcRoute(registry, "GET", "devtools:server-routes"),
1676
+ config: rpcRoute(registry, "GET", "devtools:config"),
1677
+ "config/reveal": rpcRoute(registry, "GET", "devtools:config-reveal", (request) => ({
1678
+ path: new URL(request.url).searchParams.get("path")
1679
+ })),
1680
+ "config/runtime": rpcRoute(registry, "POST", "devtools:config-runtime", readJson),
1681
+ "config/reset": rpcRoute(registry, "POST", "devtools:config-reset"),
1682
+ spans: rpcRoute(registry, "GET", "devtools:spans", (request) => ({
1683
+ trace: new URL(request.url).searchParams.get("trace")
1684
+ })),
1685
+ hooks: rpcRoute(registry, "GET", "devtools:hooks"),
1686
+ plugins: rpcRoute(registry, "GET", "devtools:plugins"),
1687
+ modules: rpcRoute(registry, "GET", "devtools:modules"),
1688
+ virtual: rpcRoute(registry, "GET", "devtools:virtual"),
1689
+ assets: {
1690
+ method: ["GET", "POST"],
1691
+ answer: (request) => request.method === "POST" ? uploadAsset(request, assetUpload) : registry.rpc.get("devtools:assets").call(undefined)
1692
+ },
1693
+ analyze: analyzeRoute,
1694
+ processes: processesRoute,
1695
+ tasks: createTasksRoute(registry.rpc),
1696
+ ...policies ? { "authz/policies": { method: "GET", answer: () => policiesAnswer(hamur.authz) } } : {}
1697
+ },
1698
+ rpc: registry.rpc,
1699
+ log: (message) => logger.error(message)
1700
+ })
1701
+ });
1702
+ const channel = useDevChannel();
1703
+ hamur.hooks.hook("dev:change", (change) => {
1704
+ if (bundle.drop(change.file))
1705
+ channel.send("devtools:reload", {}, "devtools");
1706
+ });
1707
+ }
1708
+ });
1709
+ export {
1710
+ module_default as default
1711
+ };