astralis-devtools 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,92 @@
1
+ import { IDENTITY_ATTRIBUTE, readIdentity } from "./identity.mjs";
2
+
3
+ /* What is on the page, and which of the validator's findings belong to it.
4
+ Pure apart from reading the DOM it is given, so it runs in Node tests. */
5
+
6
+ /**
7
+ * Every astralis-ui component rendered on the page, in document order, each
8
+ * with its chain (outermost first). The overlay's own element is skipped.
9
+ */
10
+ export function scanPage(root, skip = null) {
11
+ const instances = [];
12
+ for (const element of root.querySelectorAll(`[${IDENTITY_ATTRIBUTE}]`)) {
13
+ if (skip && (element === skip || skip.contains(element))) continue;
14
+ const chain = readIdentity(element);
15
+ if (chain.length) instances.push({ element, chain, name: chain[0].name });
16
+ }
17
+ return instances;
18
+ }
19
+
20
+ /** The instances grouped by the component they are, most used first, then by name. */
21
+ export function groupByComponent(instances) {
22
+ const groups = new Map();
23
+ for (const instance of instances) {
24
+ if (!groups.has(instance.name)) groups.set(instance.name, []);
25
+ groups.get(instance.name).push(instance);
26
+ }
27
+ return [...groups]
28
+ .map(([name, list]) => ({ name, instances: list }))
29
+ .sort((a, b) => b.instances.length - a.instances.length || a.name.localeCompare(b.name));
30
+ }
31
+
32
+ /**
33
+ * The findings, flattened, each with its file and severity. `files` limits
34
+ * them to the files that render the page, when those are known.
35
+ */
36
+ export function flatFindings(findings, files = null) {
37
+ const out = [];
38
+ for (const result of findings?.results ?? []) {
39
+ if (files && !files.includes(result.file)) continue;
40
+ for (const finding of result.errors) out.push({ ...finding, file: result.file, kind: "error" });
41
+ for (const finding of result.warnings) out.push({ ...finding, file: result.file, kind: "warning" });
42
+ }
43
+ return out;
44
+ }
45
+
46
+ /**
47
+ * The findings about this instance's component, from anywhere in the project.
48
+ * `exact`: certainly about this very instance, because the finding names an
49
+ * attribute and value this instance was given, or it is in a file that renders
50
+ * the page and this is the only one of its component there. `onPage`: in a
51
+ * file that renders the page. Exact ones first, then the page's, errors first.
52
+ */
53
+ export function findingsFor(instance, findings, { routeFiles = [], alone = false } = {}) {
54
+ const names = new Set(instance.chain.map((c) => c.name));
55
+ return flatFindings(findings)
56
+ .filter((finding) => finding.component && names.has(finding.component))
57
+ .map((finding) => {
58
+ const props = instance.chain.find((c) => c.name === finding.component)?.props ?? {};
59
+ const onPage = routeFiles.includes(finding.file);
60
+ const given = finding.prop !== undefined && finding.value !== undefined && finding.prop in props && String(props[finding.prop]) === String(finding.value);
61
+ return { ...finding, onPage, exact: given || (alone && onPage) };
62
+ })
63
+ .sort(
64
+ (a, b) =>
65
+ Number(b.exact) - Number(a.exact) ||
66
+ Number(b.onPage) - Number(a.onPage) ||
67
+ (a.kind === b.kind ? 0 : a.kind === "error" ? -1 : 1),
68
+ );
69
+ }
70
+
71
+ /** The findings that are likely on a group's instances: exact for one of them, or in the page's files. */
72
+ export function findingsForGroup(group, findings, routeFiles = []) {
73
+ const seen = new Map();
74
+ for (const instance of group.instances) {
75
+ for (const finding of findingsFor(instance, findings, { routeFiles, alone: group.instances.length === 1 })) {
76
+ if (!finding.exact && !finding.onPage) continue;
77
+ seen.set(`${finding.file}:${finding.line}:${finding.column}:${finding.code}`, finding);
78
+ }
79
+ }
80
+ const list = [...seen.values()];
81
+ return { errors: list.filter((f) => f.kind === "error").length, warnings: list.filter((f) => f.kind === "warning").length };
82
+ }
83
+
84
+ /** A short, local description of one instance for a list: its text, else its first props. */
85
+ export function instanceLabel(instance) {
86
+ const text = (instance.element.textContent ?? "").replace(/\s+/g, " ").trim();
87
+ const props = Object.entries(instance.chain[0].props)
88
+ .slice(0, 2)
89
+ .map(([key, value]) => `${key}=${typeof value === "string" ? `"${value}"` : JSON.stringify(value)}`)
90
+ .join(" ");
91
+ return { text: text.length > 42 ? `${text.slice(0, 40)}…` : text, props };
92
+ }
@@ -0,0 +1,118 @@
1
+ import { h, icon } from "./dom.mjs";
2
+ import { IDENTITY_ATTRIBUTE, readIdentity } from "./identity.mjs";
3
+ import { ICONS } from "./icons.mjs";
4
+
5
+ /* Picking a component on the page, and the outline that shows one. While
6
+ picking, the page never sees the pointer: no click, no navigation, no menu. */
7
+
8
+ export function createPicker({ host, shadow, onPicked, onChange }) {
9
+ const label = h("span", { class: "label" });
10
+ const highlight = h("div", { class: "highlight", hidden: true }, label);
11
+ const toast = h(
12
+ "div",
13
+ { class: "toast", role: "status", hidden: true },
14
+ icon(ICONS.pick),
15
+ h("span", {}, "Click a component to inspect it"),
16
+ h("span", { class: "kbd" }, "Esc"),
17
+ );
18
+ shadow.append(highlight, toast);
19
+
20
+ let picking = false;
21
+ let hovered = null;
22
+ let shown = null; // the element outlined when not picking
23
+
24
+ const named = (target) => {
25
+ if (!(target instanceof Element) || target === host || host.contains(target)) return null;
26
+ return target.closest(`[${IDENTITY_ATTRIBUTE}]`);
27
+ };
28
+
29
+ function outline(element) {
30
+ if (!element?.isConnected) {
31
+ highlight.hidden = true;
32
+ return;
33
+ }
34
+ const rect = element.getBoundingClientRect();
35
+ Object.assign(highlight.style, {
36
+ transform: `translate(${rect.left}px, ${rect.top}px)`,
37
+ width: `${rect.width}px`,
38
+ height: `${rect.height}px`,
39
+ });
40
+ highlight.classList.toggle("below", rect.top < 32);
41
+ label.replaceChildren(
42
+ h("span", {}, readIdentity(element).map((c) => c.name).join(" → ")),
43
+ h("span", { class: "size" }, `${Math.round(rect.width)}×${Math.round(rect.height)}`),
44
+ );
45
+ highlight.hidden = false;
46
+ }
47
+
48
+ const refresh = () => outline(picking ? hovered : shown);
49
+
50
+ function onPointerMove(event) {
51
+ const next = named(event.target);
52
+ if (next === hovered) return;
53
+ hovered = next;
54
+ refresh();
55
+ }
56
+
57
+ function swallow(event) {
58
+ if (event.target === host) return;
59
+ event.preventDefault();
60
+ event.stopPropagation();
61
+ }
62
+
63
+ function onClick(event) {
64
+ if (event.target === host) return;
65
+ swallow(event);
66
+ const element = named(event.target);
67
+ stop();
68
+ if (element) onPicked(element);
69
+ }
70
+
71
+ function start() {
72
+ if (picking) return;
73
+ picking = true;
74
+ toast.hidden = false;
75
+ document.addEventListener("pointermove", onPointerMove, true);
76
+ document.addEventListener("pointerdown", swallow, true);
77
+ document.addEventListener("mousedown", swallow, true);
78
+ document.addEventListener("click", onClick, true);
79
+ onChange(true);
80
+ }
81
+
82
+ function stop() {
83
+ if (!picking) return;
84
+ picking = false;
85
+ hovered = null;
86
+ toast.hidden = true;
87
+ document.removeEventListener("pointermove", onPointerMove, true);
88
+ document.removeEventListener("pointerdown", swallow, true);
89
+ document.removeEventListener("mousedown", swallow, true);
90
+ document.removeEventListener("click", onClick, true);
91
+ refresh();
92
+ onChange(false);
93
+ }
94
+
95
+ return {
96
+ start,
97
+ stop,
98
+ get picking() {
99
+ return picking;
100
+ },
101
+ /** Outline an element while not picking (the open component, a hovered row); null hides it. */
102
+ show(element) {
103
+ shown = element;
104
+ refresh();
105
+ },
106
+ /** Scroll an element into view and pulse its outline. */
107
+ locate(element) {
108
+ if (!element?.isConnected) return;
109
+ element.scrollIntoView?.({ block: "center", behavior: "smooth" });
110
+ shown = element;
111
+ highlight.classList.remove("flash");
112
+ void highlight.offsetWidth;
113
+ highlight.classList.add("flash");
114
+ setTimeout(refresh, 350);
115
+ },
116
+ refresh,
117
+ };
118
+ }
@@ -0,0 +1,161 @@
1
+ import { LIMITS, cleanConsoleMessage, contentOf, keptText, redactedText } from "astralis-cli/snapshot";
2
+ import { IDENTITY_ATTRIBUTE, readIdentity } from "./identity.mjs";
3
+
4
+ /* The page's part of an issue snapshot: the component tree under the
5
+ selected element, the browser's facts, console errors and an optional
6
+ screenshot. Nothing here sends anything; the bridge assembles the rest. */
7
+
8
+ const SKIP = new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT"]);
9
+
10
+ /**
11
+ * One element's chain as nested nodes. "Modal.Trigger Button" is a trigger
12
+ * wrapping the Button the page wrote, because a Trigger takes one element
13
+ * (its spec content is "element"); "Card.Body Box" would be Card.Body
14
+ * rendering its own Box, which the page never wrote, so it is recorded under
15
+ * `renders` instead of as a child.
16
+ */
17
+ function chainNode(chain, spec, children) {
18
+ const [first, ...rest] = chain;
19
+ const node = { component: first.name, props: first.props, children };
20
+ if (rest.length === 0) return node;
21
+ if (contentOf(spec, first.name) === "element") {
22
+ node.children = [chainNode(rest, spec, children)];
23
+ } else {
24
+ node.renders = rest.map((c) => c.name);
25
+ }
26
+ return node;
27
+ }
28
+
29
+ /**
30
+ * The astralis-ui components at and under `element`, as snapshot tree nodes.
31
+ * Plain elements in between are passed through; text becomes a placeholder
32
+ * unless `includeText`. The overlay's own element is never included.
33
+ */
34
+ export function treeFromElement(element, spec, { includeText = false, skip = null } = {}) {
35
+ let count = 0;
36
+ const walk = (nodes, depth) => {
37
+ const out = [];
38
+ for (const node of nodes) {
39
+ if (count >= LIMITS.nodes || depth > LIMITS.depth) break;
40
+ if (node.nodeType === 3) {
41
+ const text = node.textContent.replace(/\s+/g, " ").trim();
42
+ if (text) out.push(includeText ? keptText(text) : redactedText(text));
43
+ continue;
44
+ }
45
+ if (node.nodeType !== 1 || node === skip || SKIP.has(node.tagName)) continue;
46
+ if (node.hasAttribute(IDENTITY_ATTRIBUTE)) {
47
+ count++;
48
+ out.push(chainNode(readIdentity(node), spec, walk(node.childNodes, depth + 1)));
49
+ } else {
50
+ out.push(...walk(node.childNodes, depth));
51
+ }
52
+ }
53
+ return out;
54
+ };
55
+ return walk([element], 0).filter((node) => "component" in node);
56
+ }
57
+
58
+ /** "Chrome 140", "Firefox 131", "Safari 18": the browser and its major version, no more. */
59
+ export function browserName(userAgent = globalThis.navigator?.userAgent ?? "") {
60
+ const rules = [
61
+ [/Edg\/(\d+)/, "Edge"],
62
+ [/OPR\/(\d+)/, "Opera"],
63
+ [/Firefox\/(\d+)/, "Firefox"],
64
+ [/Chrome\/(\d+)/, "Chrome"],
65
+ [/Version\/(\d+)[\d.]* Safari/, "Safari"],
66
+ ];
67
+ for (const [pattern, name] of rules) {
68
+ const m = userAgent.match(pattern);
69
+ if (m) return `${name} ${m[1]}`;
70
+ }
71
+ return null;
72
+ }
73
+
74
+ /** The facts about this browser a snapshot carries. */
75
+ export function browserEnvironment(win = globalThis.window) {
76
+ const dark = win.document.documentElement.classList.contains("astralis-dark");
77
+ return {
78
+ browser: browserName(win.navigator.userAgent),
79
+ viewport: { width: Math.round(win.innerWidth), height: Math.round(win.innerHeight) },
80
+ colorMode: dark ? "dark" : "light",
81
+ };
82
+ }
83
+
84
+ /**
85
+ * Record console errors, uncaught errors and unhandled rejections from now
86
+ * on, cleaned as they arrive, keeping the last few. Returns { messages, stop }.
87
+ */
88
+ export function recordConsoleErrors(win = globalThis.window) {
89
+ const messages = [];
90
+ const origin = win.location.origin;
91
+ const push = (parts) => {
92
+ const text = parts.map((p) => (p instanceof Error ? p.stack || p.message : typeof p === "string" ? p : safeString(p))).join(" ");
93
+ messages.push(cleanConsoleMessage(text, origin));
94
+ if (messages.length > LIMITS.console) messages.shift();
95
+ };
96
+ const original = win.console.error;
97
+ win.console.error = function (...args) {
98
+ push(args);
99
+ return original.apply(this, args);
100
+ };
101
+ const onError = (event) => push([event.error ?? event.message]);
102
+ const onRejection = (event) => push(["Unhandled rejection:", event.reason]);
103
+ win.addEventListener("error", onError);
104
+ win.addEventListener("unhandledrejection", onRejection);
105
+ return {
106
+ messages,
107
+ stop() {
108
+ if (win.console.error !== original) win.console.error = original;
109
+ win.removeEventListener("error", onError);
110
+ win.removeEventListener("unhandledrejection", onRejection);
111
+ },
112
+ };
113
+ }
114
+
115
+ function safeString(value) {
116
+ try {
117
+ return JSON.stringify(value) ?? String(value);
118
+ } catch {
119
+ return String(value);
120
+ }
121
+ }
122
+
123
+ const MAX_SCREENSHOT_BYTES = 180 * 1024;
124
+
125
+ /**
126
+ * A screenshot of this tab through the browser's own capture prompt, as a
127
+ * JPEG data URL small enough for a snapshot. `hide` and `show` take the
128
+ * overlay out of the picture. Rejects if the reporter declines the prompt.
129
+ */
130
+ export async function captureScreenshot({ hide = () => {}, show = () => {}, win = globalThis.window } = {}) {
131
+ const stream = await win.navigator.mediaDevices.getDisplayMedia({
132
+ video: { displaySurface: "browser" },
133
+ audio: false,
134
+ preferCurrentTab: true,
135
+ selfBrowserSurface: "include",
136
+ });
137
+ const video = win.document.createElement("video");
138
+ try {
139
+ video.srcObject = stream;
140
+ video.muted = true;
141
+ await video.play();
142
+ hide();
143
+ // Two frames, so the capture shows the page without the overlay.
144
+ await new Promise((done) => win.requestAnimationFrame(() => win.requestAnimationFrame(done)));
145
+ for (const [width, quality] of [[1280, 0.72], [960, 0.6], [720, 0.5]]) {
146
+ const scale = Math.min(1, width / video.videoWidth);
147
+ const canvas = win.document.createElement("canvas");
148
+ canvas.width = Math.round(video.videoWidth * scale);
149
+ canvas.height = Math.round(video.videoHeight * scale);
150
+ canvas.getContext("2d").drawImage(video, 0, 0, canvas.width, canvas.height);
151
+ const url = canvas.toDataURL("image/jpeg", quality);
152
+ if (url.length * 0.75 <= MAX_SCREENSHOT_BYTES) return url;
153
+ }
154
+ throw new Error("The screenshot is too large to include.");
155
+ } finally {
156
+ show();
157
+ for (const track of stream.getTracks()) track.stop();
158
+ video.srcObject = null;
159
+ }
160
+ }
161
+
@@ -0,0 +1,151 @@
1
+ import { formatValue, h, icon, plural } from "../dom.mjs";
2
+ import { describeComponent, IDENTITY_ATTRIBUTE, readIdentity } from "../identity.mjs";
3
+ import { ICONS } from "../icons.mjs";
4
+ import { findingsFor } from "../page.mjs";
5
+ import { findingRow } from "./shared.mjs";
6
+
7
+ /* One component on the page: what it is, the props it was given, how it
8
+ reaches the browser, where it sits, and the findings and recommendations
9
+ about it. */
10
+
11
+ export function componentScreen(app, element) {
12
+ const root = h("div", {});
13
+ const chain = readIdentity(element);
14
+ const name = chain[0]?.name ?? "Component";
15
+
16
+ function propsCard(entry, first) {
17
+ const about = describeComponent(app.state.spec, entry.name, app.framework);
18
+ const props = Object.entries(entry.props);
19
+ return h(
20
+ "div",
21
+ { class: "card pad" },
22
+ h(
23
+ "div",
24
+ { class: "row", style: "margin-bottom:10px" },
25
+ h("span", { class: "code grow", style: "font-weight:600" }, first ? "Props" : entry.name),
26
+ h("a", { class: "link", href: about.docsUrl, target: "_blank", rel: "noreferrer" }, "Docs", icon(ICONS.external)),
27
+ ),
28
+ app.state.spec && !about.known
29
+ ? h(
30
+ "p",
31
+ { class: "muted", style: "margin-bottom:8px" },
32
+ about.partOf ? `Part of ${about.partOf}. The spec has no entry of its own for it, so no client tier is shown.` : `${entry.name} is not in the installed spec.`,
33
+ )
34
+ : null,
35
+ props.length
36
+ ? h("table", { class: "props" }, h("tbody", {}, props.map(([key, value]) => h("tr", {}, h("td", {}, key), h("td", {}, formatValue(value))))))
37
+ : h("p", { class: "muted" }, "No props beyond its defaults."),
38
+ );
39
+ }
40
+
41
+ function findingsSection(title, list, tone) {
42
+ return h(
43
+ "section",
44
+ {},
45
+ h("h3", { class: "section-title" }, title, h("span", { class: "n" }, String(list.length))),
46
+ list.length
47
+ ? h(
48
+ "div",
49
+ { class: "file-card" },
50
+ list.map((finding) => findingRow(app, finding, { showFile: true, showComponent: false, exactLabel: finding.exact ? "This one" : null })),
51
+ )
52
+ : h("p", { class: "muted", style: "margin-bottom:4px" }, tone === "error" ? "Nothing broken here." : "Nothing to suggest."),
53
+ );
54
+ }
55
+
56
+ function update() {
57
+ const { state } = app;
58
+ if (!element.isConnected) {
59
+ root.replaceChildren(
60
+ h("div", { class: "gone" }, icon(ICONS.findings), "This component has left the page."),
61
+ h("button", { class: "btn", type: "button", onclick: () => app.navigate("components") }, icon(ICONS.back), "All components"),
62
+ );
63
+ return;
64
+ }
65
+ const about = describeComponent(state.spec, name, app.framework);
66
+ const sameKind = state.instances.filter((i) => i.name === name);
67
+ const instance = state.instances.find((i) => i.element === element) ?? { element, chain, name };
68
+ const found = findingsFor(instance, state.findings, { routeFiles: state.routeFiles, alone: sameKind.length === 1 });
69
+ const errors = found.filter((f) => f.kind === "error" && (f.exact || f.onPage));
70
+ const warnings = found.filter((f) => f.kind === "warning" && (f.exact || f.onPage));
71
+
72
+ const ancestors = [];
73
+ for (let node = element.parentElement?.closest(`[${IDENTITY_ATTRIBUTE}]`); node; node = node.parentElement?.closest(`[${IDENTITY_ATTRIBUTE}]`)) {
74
+ ancestors.unshift(node);
75
+ }
76
+ const inside = state.instances.filter((i) => i.element !== element && element.contains(i.element) && i.element.parentElement?.closest(`[${IDENTITY_ATTRIBUTE}]`) === element);
77
+
78
+ const head = h(
79
+ "div",
80
+ { class: "detail-head" },
81
+ h("span", { class: "detail-icon" }, icon(ICONS.components)),
82
+ h(
83
+ "div",
84
+ { class: "grow" },
85
+ h("h2", {}, name),
86
+ chain.length > 1 ? h("p", { class: "chain" }, `renders through ${chain.slice(1).map((c) => c.name).join(" → ")}`) : null,
87
+ h(
88
+ "div",
89
+ { class: "row" },
90
+ about.client ? h("span", { class: `pill ${about.client}`, title: about.clientDetail }, h("i"), about.clientLabel) : null,
91
+ about.category ? h("span", { class: "pill" }, about.category) : null,
92
+ sameKind.length > 1 ? h("span", { class: "pill" }, `${sameKind.indexOf(instance) + 1} of ${sameKind.length} on this page`) : null,
93
+ errors.length ? h("span", { class: "pill error" }, plural(errors.length, "finding")) : null,
94
+ warnings.length ? h("span", { class: "pill advice" }, plural(warnings.length, "recommendation")) : null,
95
+ ),
96
+ about.client ? h("p", { class: "muted", style: "margin-top:8px;font-size:12.5px" }, about.clientDetail) : null,
97
+ ),
98
+ );
99
+
100
+ const actions = h(
101
+ "div",
102
+ { class: "actions" },
103
+ h("button", { class: "btn", type: "button", onclick: () => app.locate(element) }, icon(ICONS.locate), "Locate on page"),
104
+ h("button", { class: "btn", type: "button", onclick: () => app.navigate("report") }, icon(ICONS.report), "Report a problem"),
105
+ h("a", { class: "btn ghost", href: about.docsUrl, target: "_blank", rel: "noreferrer" }, "Docs", icon(ICONS.external)),
106
+ );
107
+
108
+ const crumbs = (title, nodes) =>
109
+ nodes.length
110
+ ? h(
111
+ "section",
112
+ {},
113
+ h("h3", { class: "section-title" }, title),
114
+ h(
115
+ "div",
116
+ { class: "tags" },
117
+ nodes.map((node) =>
118
+ h(
119
+ "button",
120
+ {
121
+ class: "chip",
122
+ type: "button",
123
+ onclick: () => app.openComponent(node),
124
+ onpointerenter: () => app.preview(node),
125
+ onpointerleave: () => app.preview(element),
126
+ },
127
+ readIdentity(node)[0]?.name ?? "?",
128
+ ),
129
+ ),
130
+ ),
131
+ )
132
+ : null;
133
+
134
+ root.replaceChildren(
135
+ head,
136
+ actions,
137
+ h(
138
+ "div",
139
+ { class: "stack" },
140
+ findingsSection("Findings", errors, "error"),
141
+ findingsSection("Recommendations", warnings, "advice"),
142
+ h("section", {}, h("h3", { class: "section-title" }, "Props"), h("div", { class: "stack" }, chain.map((entry, index) => propsCard(entry, index === 0)))),
143
+ crumbs("Inside", ancestors),
144
+ crumbs("Contains", inside.map((i) => i.element)),
145
+ ),
146
+ );
147
+ }
148
+
149
+ update();
150
+ return { title: [{ label: "Components", screen: "components" }, { label: name, code: true }], root, update, element };
151
+ }
@@ -0,0 +1,117 @@
1
+ import { h, icon, plural } from "../dom.mjs";
2
+ import { describeComponent } from "../identity.mjs";
3
+ import { ICONS } from "../icons.mjs";
4
+ import { findingsForGroup, groupByComponent, instanceLabel } from "../page.mjs";
5
+ import { empty } from "./shared.mjs";
6
+
7
+ /* Components: every astralis-ui component on the page, grouped by what it is.
8
+ Hovering an instance outlines it on the page; choosing one opens its page. */
9
+
10
+ export function componentsScreen(app) {
11
+ const input = h("input", { type: "search", placeholder: "Filter components", "aria-label": "Filter components", autocomplete: "off", spellcheck: "false" });
12
+ const list = h("div", { class: "list", role: "list" });
13
+ const open = new Set(); // groups the reader expanded
14
+ let query = "";
15
+
16
+ input.addEventListener("input", () => {
17
+ query = input.value.trim().toLowerCase();
18
+ update();
19
+ });
20
+
21
+ function groupView(group) {
22
+ const { state } = app;
23
+ const about = describeComponent(state.spec, group.name, app.framework);
24
+ const counts = findingsForGroup(group, state.findings, state.routeFiles);
25
+ const single = group.instances.length === 1;
26
+ const expanded = open.has(group.name) || (query && group.instances.length <= 6);
27
+
28
+ const row = h(
29
+ "button",
30
+ {
31
+ class: "group-row",
32
+ type: "button",
33
+ "aria-expanded": single ? null : String(Boolean(expanded)),
34
+ onclick: (event) => {
35
+ if (single) return app.openComponent(group.instances[0].element);
36
+ // Toggled in place, so the instances slide open rather than appear.
37
+ const now = !open.has(group.name);
38
+ if (now) open.add(group.name);
39
+ else open.delete(group.name);
40
+ event.currentTarget.setAttribute("aria-expanded", String(now));
41
+ event.currentTarget.parentElement.dataset.open = String(now);
42
+ },
43
+ onpointerenter: () => single && app.preview(group.instances[0].element),
44
+ onpointerleave: () => single && app.preview(null),
45
+ },
46
+ icon(ICONS.chevron, "icon chev"),
47
+ h("span", { class: `tier-dot ${about.client ?? ""}`, title: about.clientLabel ?? "" }),
48
+ h("span", { class: "name grow" }, group.name),
49
+ counts.errors ? h("span", { class: "mini error", title: plural(counts.errors, "finding") }, h("i"), String(counts.errors)) : null,
50
+ counts.warnings ? h("span", { class: "mini advice", title: plural(counts.warnings, "recommendation") }, h("i"), String(counts.warnings)) : null,
51
+ h("span", { class: "n-pill" }, String(group.instances.length)),
52
+ );
53
+
54
+ const instances = single
55
+ ? null
56
+ : h(
57
+ "div",
58
+ { class: "instances" },
59
+ h(
60
+ "div",
61
+ {},
62
+ h(
63
+ "div",
64
+ { class: "list" },
65
+ group.instances.map((instance, index) => {
66
+ const { text, props } = instanceLabel(instance);
67
+ return h(
68
+ "button",
69
+ {
70
+ class: "instance-row",
71
+ type: "button",
72
+ onclick: () => app.openComponent(instance.element),
73
+ onpointerenter: () => app.preview(instance.element),
74
+ onpointerleave: () => app.preview(null),
75
+ },
76
+ h("span", { class: "idx" }, `#${index + 1}`),
77
+ text ? h("span", { class: "text" }, text) : null,
78
+ h("span", { class: "props grow" }, props),
79
+ icon(ICONS.arrow, "icon go"),
80
+ );
81
+ }),
82
+ ),
83
+ ),
84
+ );
85
+ return h("div", { class: "group", role: "listitem", "data-open": String(Boolean(expanded) && !single) }, row, instances);
86
+ }
87
+
88
+ function update() {
89
+ const { state } = app;
90
+ if (!state.instances.length) {
91
+ list.replaceChildren(
92
+ empty(ICONS.components, "No components on this page", "Components from astralis-ui show up here as they render, Server Components included.", { neutral: true }),
93
+ );
94
+ return;
95
+ }
96
+ const groups = groupByComponent(state.instances).filter((g) => !query || g.name.toLowerCase().includes(query));
97
+ list.replaceChildren(
98
+ ...(groups.length ? groups.map(groupView) : [empty(ICONS.search, "No matches", `Nothing on this page is called “${input.value}”.`, { neutral: true })]),
99
+ );
100
+ }
101
+
102
+ const root = h(
103
+ "div",
104
+ {},
105
+ h("label", { class: "search" }, icon(ICONS.search), input),
106
+ list,
107
+ h(
108
+ "div",
109
+ { class: "legend" },
110
+ h("span", {}, h("span", { class: "tier-dot none" }), "Server Component"),
111
+ h("span", {}, h("span", { class: "tier-dot leaf" }), "Server shell, client island"),
112
+ h("span", {}, h("span", { class: "tier-dot required" }), "Client Component"),
113
+ ),
114
+ );
115
+ update();
116
+ return { title: [{ label: "Components" }], root, update, focus: () => input.focus({ preventScroll: true }) };
117
+ }