feat(browser): expand browser control surface

This commit is contained in:
Peter Steinberger
2026-01-12 17:31:49 +00:00
parent f5d5661adf
commit eeca541dde
12 changed files with 1747 additions and 65 deletions

View File

@@ -7,6 +7,13 @@ export type RoleRef = {
export type RoleRefMap = Record<string, RoleRef>;
export type RoleSnapshotStats = {
lines: number;
chars: number;
refs: number;
interactive: number;
};
export type RoleSnapshotOptions = {
/** Only include interactive elements (buttons, links, inputs, etc.). */
interactive?: boolean;
@@ -70,6 +77,21 @@ const STRUCTURAL_ROLES = new Set([
"none",
]);
export function getRoleSnapshotStats(
snapshot: string,
refs: RoleRefMap,
): RoleSnapshotStats {
const interactive = Object.values(refs).filter((r) =>
INTERACTIVE_ROLES.has(r.role),
).length;
return {
lines: snapshot.split("\n").length,
chars: snapshot.length,
refs: Object.keys(refs).length,
interactive,
};
}
function getIndentLevel(line: string): number {
const match = line.match(/^(\s*)/);
return match ? Math.floor(match[1].length / 2) : 0;