@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,34 @@
1
+ import type { DevtoolsRegistry } from "hamur/kit"
2
+ import { json, type DataRoute } from "./handler.ts"
3
+
4
+ const ACTION = /^(.+)\/(restart|kill)$/
5
+
6
+ /** `api/processes` (GET) and `api/processes/<name>/restart`, `api/processes/<name>/kill` (POST, 204), only for a registered name. */
7
+ export function createProcessesRoute(processes: DevtoolsRegistry["processes"]): DataRoute {
8
+ return {
9
+ method: ["GET", "POST"],
10
+ param: true,
11
+ async answer(request, param) {
12
+ if (param === undefined)
13
+ return request.method === "GET"
14
+ ? processes.list()
15
+ : json({ error: 'Devtools data route "processes" answers GET' }, 405, { allow: "GET" })
16
+ const match = ACTION.exec(param)
17
+ if (!match)
18
+ return json(
19
+ {
20
+ error: `No devtools data route "processes/${param}"; use processes/<name>/restart or processes/<name>/kill`,
21
+ },
22
+ 404,
23
+ )
24
+ if (request.method !== "POST")
25
+ return json({ error: `Devtools data route "processes/<name>/${match[2]}" answers POST` }, 405, {
26
+ allow: "POST",
27
+ })
28
+ const name = match[1]!
29
+ const done = match[2] === "restart" ? await processes.restart(name) : await processes.kill(name)
30
+ if (!done) return json({ error: `No dev process ${JSON.stringify(name)}` }, 404)
31
+ return new Response(null, { status: 204, headers: { "cache-control": "no-store" } })
32
+ },
33
+ }
34
+ }
@@ -0,0 +1,14 @@
1
+ import type { DevRouteTable, DevServerRoutes } from "hamur/kit"
2
+
3
+ export type ServerRouteRow = DevRouteTable["serverRoutes"][number] & {
4
+ middleware: string[]
5
+ bodySchema?: Record<string, unknown>
6
+ }
7
+
8
+ /** `api/server-routes`: the route table's server routes, the serving process's middleware on each and the JSON Schema of each handler's `schema.body`; both are empty while no server process serves. */
9
+ export function serverRoutesAnswer(table: DevRouteTable, served: DevServerRoutes | undefined): ServerRouteRow[] {
10
+ return table.serverRoutes.map((route) => {
11
+ const bodySchema = served?.bodySchemas[`${route.method} ${route.path}`]
12
+ return { ...route, middleware: served?.middleware ?? [], ...(bodySchema ? { bodySchema } : {}) }
13
+ })
14
+ }
@@ -0,0 +1,93 @@
1
+ import { isAbsolute, relative } from "node:path"
2
+ import type { DevtoolsRegistry, TaskRunRecord } from "hamur/kit"
3
+ import { json, type DataRoute } from "./handler.ts"
4
+
5
+ /** One task of the build. */
6
+ export interface TaskRow {
7
+ name: string
8
+ description?: string
9
+ /** From the app root. */
10
+ file: string
11
+ /** Set for a queued listener: the app event it runs on. */
12
+ listener?: string
13
+ /** Epoch ms of the next firing in UTC; none when the expression cannot be read. */
14
+ schedules: Array<{ cron: string; next?: number }>
15
+ }
16
+
17
+ export function tasksAnswer(
18
+ tasks: readonly { name: string; file: string; description?: string; listener?: string }[],
19
+ scheduled: Readonly<Record<string, string | readonly string[]>>,
20
+ rootDir: string,
21
+ now = Date.now(),
22
+ ): { tasks: TaskRow[] } {
23
+ const next = (cron: string): number | undefined => {
24
+ try {
25
+ return Bun.cron.parse(cron, now, { tz: "UTC" })?.getTime()
26
+ } catch {
27
+ return undefined
28
+ }
29
+ }
30
+ return {
31
+ tasks: tasks.map(({ name, file, description, listener }) => {
32
+ const shown = relative(rootDir, file)
33
+ return {
34
+ name,
35
+ ...(description === undefined ? {} : { description }),
36
+ file: shown.startsWith("..") || isAbsolute(shown) ? file : shown.replaceAll("\\", "/"),
37
+ ...(listener === undefined ? {} : { listener }),
38
+ schedules: Object.entries(scheduled)
39
+ .filter(([, value]) => (typeof value === "string" ? value === name : value.includes(name)))
40
+ .map(([cron]) => {
41
+ const at = next(cron)
42
+ return { cron, ...(at === undefined ? {} : { next: at }) }
43
+ }),
44
+ }
45
+ }),
46
+ }
47
+ }
48
+
49
+ const USE = "use tasks/runs, tasks/pending or tasks/cancel"
50
+
51
+ /** `api/tasks/runs` (GET), `api/tasks/pending` (GET) and `api/tasks/cancel` (POST, 204) over the RPCs `devtools:task-runs` and `devtools:task-cancel`. */
52
+ export function createTasksRoute(rpc: DevtoolsRegistry["rpc"]): DataRoute {
53
+ const runs = () => rpc.get("devtools:task-runs")!.call(undefined) as Promise<TaskRunRecord[]>
54
+ const only = (route: string, method: string, request: Request) =>
55
+ request.method === method
56
+ ? undefined
57
+ : json({ error: `Devtools data route "tasks/${route}" answers ${method}` }, 405, { allow: method })
58
+
59
+ return {
60
+ method: ["GET", "POST"],
61
+ param: true,
62
+ async answer(request, param) {
63
+ if (param === "runs") return only(param, "GET", request) ?? { runs: await runs() }
64
+ if (param === "pending")
65
+ return (
66
+ only(param, "GET", request) ?? {
67
+ runs: (await runs())
68
+ .filter((run) => run.status === "pending")
69
+ .sort((a, b) => (a.startsAt ?? a.createdAt) - (b.startsAt ?? b.createdAt)),
70
+ }
71
+ )
72
+ if (param !== "cancel")
73
+ return json({ error: `No devtools data route "tasks${param === undefined ? "" : `/${param}`}"; ${USE}` }, 404)
74
+ const refused = only(param, "POST", request)
75
+ if (refused) return refused
76
+ const body: unknown = await request.json().catch(() => undefined)
77
+ const id = typeof body === "object" && body !== null ? (body as { id?: unknown }).id : undefined
78
+ if (typeof id !== "string") return json({ error: "The body must be a JSON object { id }" }, 400)
79
+ const run = (await runs()).find((entry) => entry.id === id)
80
+ if (!run) return json({ error: `No task run "${id}"` }, 404)
81
+ if (run.status !== "pending")
82
+ return json({ error: `Task run "${id}" is ${run.status}; only a pending run can be cancelled` }, 409)
83
+ let cancelled: unknown
84
+ try {
85
+ cancelled = await rpc.get("devtools:task-cancel")!.call({ id })
86
+ } catch (error) {
87
+ return json({ error: error instanceof Error ? error.message : String(error) }, 504)
88
+ }
89
+ if (cancelled !== true) return json({ error: `Task run "${id}" started before the cancel reached it` }, 409)
90
+ return new Response(null, { status: 204, headers: { "cache-control": "no-store" } })
91
+ },
92
+ }
93
+ }
@@ -0,0 +1,43 @@
1
+ import { REDACTED, type DevSpan, type Redactor } from "hamur/kit"
2
+
3
+ /** `api/spans`: a server span of one trace, its attributes redacted by the redactor's rule. */
4
+ export interface SpanRow {
5
+ traceId: string
6
+ spanId: string
7
+ parentSpanId?: string
8
+ name: string
9
+ kind: DevSpan["kind"]
10
+ startTime: number
11
+ endTime: number
12
+ status: DevSpan["status"]
13
+ attributes: Record<string, unknown>
14
+ events: Array<{ name: string; time: number }>
15
+ }
16
+
17
+ const TRACE = /^[0-9a-f]{32}$/
18
+
19
+ /** The trace id of an `api/spans` call; a missing or malformed one throws, which answers 400. */
20
+ export function traceOf(args: unknown): string {
21
+ const trace = typeof args === "object" && args !== null ? (args as { trace?: unknown }).trace : undefined
22
+ if (trace === undefined || trace === null || trace === "") throw new Error("The trace query parameter is missing")
23
+ if (typeof trace !== "string" || !TRACE.test(trace))
24
+ throw new Error("The trace query parameter must be a 32-character hex trace id")
25
+ return trace
26
+ }
27
+
28
+ export function spansAnswer(spans: readonly DevSpan[], redactor: Redactor): SpanRow[] {
29
+ return spans.map((span) => ({
30
+ traceId: span.traceId,
31
+ spanId: span.spanId,
32
+ ...(span.parentSpanId === undefined ? {} : { parentSpanId: span.parentSpanId }),
33
+ name: span.name,
34
+ kind: span.kind,
35
+ startTime: span.startTime,
36
+ endTime: span.endTime,
37
+ status: span.status,
38
+ attributes: Object.fromEntries(
39
+ Object.entries(span.attributes).map(([key, value]) => [key, redactor.test(key) ? REDACTED : value]),
40
+ ),
41
+ events: span.events.map(({ name, time }) => ({ name, time })),
42
+ }))
43
+ }
@@ -0,0 +1,40 @@
1
+ import type { HamurContext } from "hamur/kit"
2
+
3
+ /** `api/virtual`: a `#hamur/*` virtual module or a `.hamur/` template with the text a build reads; `file` when the template is also written to `.hamur/`. */
4
+ export interface VirtualRow {
5
+ id: string
6
+ source: string
7
+ file?: string
8
+ }
9
+
10
+ const messageOf = (error: unknown): string => (error instanceof Error ? error.message : String(error))
11
+
12
+ /** The virtual modules a template does not make, then the templates, each sorted by name; a source that throws is the message in its place. */
13
+ export async function virtualAnswer(hamur: Pick<HamurContext, "vfs" | "templates">): Promise<VirtualRow[]> {
14
+ const templates = hamur.templates as Array<HamurContext["templates"][number] & { write?: boolean }>
15
+ const made = new Set(templates.map((template) => `#hamur/${template.filename}`))
16
+ const read = async (get: () => string | Promise<string>): Promise<string> => {
17
+ try {
18
+ return await get()
19
+ } catch (error) {
20
+ return `Could not read this source: ${messageOf(error)}`
21
+ }
22
+ }
23
+ const modules = await Promise.all(
24
+ hamur.vfs
25
+ .ids()
26
+ .filter((id) => !made.has(id))
27
+ .toSorted()
28
+ .map(async (id): Promise<VirtualRow> => ({ id, source: await read(() => hamur.vfs.source(id, "client")) })),
29
+ )
30
+ const files = await Promise.all(
31
+ templates
32
+ .toSorted((a, b) => (a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0))
33
+ .map(async (template): Promise<VirtualRow> => ({
34
+ id: `.hamur/${template.filename}`,
35
+ source: await read(() => template.getContents(hamur as HamurContext)),
36
+ ...(template.write ? { file: `.hamur/${template.filename}` } : {}),
37
+ })),
38
+ )
39
+ return [...modules, ...files]
40
+ }
package/src/env.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ declare module "#hamur/devtools/config" {
2
+ /** What the toolbar reads of the `devtools` key and `app.baseURL`. */
3
+ export const baseURL: string
4
+ export const shortcut: string | false
5
+ export const placement: import("./panel/settings.ts").Placement
6
+ }
7
+
8
+ declare module "#hamur/devtools-views" {
9
+ /** One lazy import per module tab, by tab name. */
10
+ export const views: Record<string, () => Promise<{ default: import("hamur/app").DevtoolsApp }>>
11
+ }
12
+
13
+ declare module "#hamur/devtools/apps" {
14
+ /** The registered devtools apps, each entry imported on the first click of its button. */
15
+ export const apps: Array<{
16
+ name: string
17
+ title: string
18
+ icon: string
19
+ load: () => Promise<{ default: import("hamur/app").DevtoolsApp }>
20
+ }>
21
+ }
package/src/icons.ts ADDED
@@ -0,0 +1,48 @@
1
+ /** The 16 px SVG icons of the built-in tabs (by tab name), the locator app, the settings button and the Hamur mark. */
2
+ export const TAB_ICONS = {
3
+ overview:
4
+ '<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>',
5
+ pages:
6
+ '<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>',
7
+ payload:
8
+ '<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>',
9
+ config:
10
+ '<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>',
11
+ "server-routes":
12
+ '<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>',
13
+ storage:
14
+ '<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>',
15
+ assets:
16
+ '<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>',
17
+ tasks:
18
+ '<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>',
19
+ authz:
20
+ '<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>',
21
+ timeline:
22
+ '<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>',
23
+ plugins:
24
+ '<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>',
25
+ modules:
26
+ '<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>',
27
+ inspect:
28
+ '<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>',
29
+ analyze:
30
+ '<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>',
31
+ terminals:
32
+ '<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>',
33
+ audit:
34
+ '<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>',
35
+ 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>',
36
+ }
37
+
38
+ export const LOCATOR_ICON =
39
+ '<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>'
40
+
41
+ export const SETTINGS_ICON =
42
+ '<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>'
43
+
44
+ export const WINDOW_ICON =
45
+ '<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>'
46
+
47
+ export const HAMUR_MARK =
48
+ '<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>'
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ // Loads hamur so the augmentation below resolves in a program where nothing else imports bare "hamur".
2
+ import type {} from "hamur"
3
+ import type { DevtoolsOptions } from "./options.ts"
4
+
5
+ export { default } from "./module.ts"
6
+ export type { DevtoolsOptions } from "./options.ts"
7
+
8
+ declare module "hamur" {
9
+ interface HamurModuleOptions {
10
+ devtools?: DevtoolsOptions
11
+ }
12
+ }
package/src/locator.ts ADDED
@@ -0,0 +1,31 @@
1
+ export interface SourceLocation {
2
+ file: string
3
+ line: number
4
+ column: number
5
+ }
6
+
7
+ const LOCATION = /^(.+):(\d+):(\d+)$/
8
+
9
+ /** The value of `data-hamur-src`, `<file>:<line>:<column>`; `undefined` for any other text. */
10
+ export function parseLocation(value: string | null | undefined): SourceLocation | undefined {
11
+ const found = LOCATION.exec(value ?? "")
12
+ return found ? { file: found[1]!, line: Number(found[2]), column: Number(found[3]) } : undefined
13
+ }
14
+
15
+ /** The nearest element at or above `element` that carries a source locator, with what it says. */
16
+ export function nearestLocation(element: Element | null): { element: Element; location: SourceLocation } | undefined {
17
+ for (
18
+ let node = element?.closest("[data-hamur-src]") ?? null;
19
+ node;
20
+ node = node.parentElement?.closest("[data-hamur-src]") ?? null
21
+ ) {
22
+ const location = parseLocation(node.getAttribute("data-hamur-src"))
23
+ if (location) return { element: node, location }
24
+ }
25
+ return undefined
26
+ }
27
+
28
+ /** An island's component name and hydration directive from its `component` chunk key and `on` attributes. */
29
+ export function describeIsland(component: string | null, on: string | null): { name: string; directive: string } {
30
+ return { name: (component ?? "").split("/").pop() || "unknown", directive: on || "load" }
31
+ }
package/src/mask.ts ADDED
@@ -0,0 +1,16 @@
1
+ /** What `api/config` shows in place of a private runtime config value until it is revealed. */
2
+ export const MASKED = "••••"
3
+ export const TOO_DEEP = "[Max depth]"
4
+ export const CIRCULAR = "[Circular]"
5
+ /** `REDACTED` of `hamur/kit`, written out because the panel bundle cannot import the kit. */
6
+ export const REDACTED_TEXT = "[redacted]"
7
+
8
+ const LOSSY = /^\[Function .*\]$|^-?\d+n$/
9
+
10
+ /** True when `value` holds text the serializer wrote in place of a value, which an edit must not write back. */
11
+ export function holdsPlaceholder(value: unknown): boolean {
12
+ if (typeof value === "string")
13
+ return value === REDACTED_TEXT || value === TOO_DEEP || value === CIRCULAR || LOSSY.test(value)
14
+ if (typeof value !== "object" || value === null) return false
15
+ return Object.values(value).some(holdsPlaceholder)
16
+ }