@ecopages/dev-toolbar 0.2.0-beta.30

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 (80) hide show
  1. package/README.md +61 -0
  2. package/package.json +54 -0
  3. package/src/api/dev-manifest.d.ts +33 -0
  4. package/src/api/dev-manifest.js +34 -0
  5. package/src/api/types.d.ts +21 -0
  6. package/src/api/types.js +1 -0
  7. package/src/apps/a11y/a11y-badge.d.ts +3 -0
  8. package/src/apps/a11y/a11y-badge.js +10 -0
  9. package/src/apps/a11y/a11y-issue-groups.d.ts +12 -0
  10. package/src/apps/a11y/a11y-issue-groups.js +27 -0
  11. package/src/apps/a11y/audit-cache.d.ts +6 -0
  12. package/src/apps/a11y/audit-cache.js +16 -0
  13. package/src/apps/a11y/dom-path.d.ts +10 -0
  14. package/src/apps/a11y/dom-path.js +32 -0
  15. package/src/apps/a11y/run-a11y-checks.d.ts +30 -0
  16. package/src/apps/a11y/run-a11y-checks.js +286 -0
  17. package/src/apps/a11y-panel.d.ts +29 -0
  18. package/src/apps/a11y-panel.js +163 -0
  19. package/src/apps/deps/load-deps-insights.d.ts +19 -0
  20. package/src/apps/deps/load-deps-insights.js +76 -0
  21. package/src/apps/deps-panel.d.ts +24 -0
  22. package/src/apps/deps-panel.js +100 -0
  23. package/src/apps/islands-panel.d.ts +26 -0
  24. package/src/apps/islands-panel.js +126 -0
  25. package/src/apps/navigation-panel.d.ts +25 -0
  26. package/src/apps/navigation-panel.js +95 -0
  27. package/src/apps/settings-panel.d.ts +17 -0
  28. package/src/apps/settings-panel.js +58 -0
  29. package/src/bootstrap.d.ts +1 -0
  30. package/src/bootstrap.js +6 -0
  31. package/src/config.d.ts +14 -0
  32. package/src/config.js +10 -0
  33. package/src/islands/island-discovery.d.ts +5 -0
  34. package/src/islands/island-discovery.js +99 -0
  35. package/src/islands/island-record-builder.d.ts +21 -0
  36. package/src/islands/island-record-builder.js +100 -0
  37. package/src/islands/read-island-records.d.ts +11 -0
  38. package/src/islands/read-island-records.js +43 -0
  39. package/src/runtime/constants.d.ts +20 -0
  40. package/src/runtime/constants.js +20 -0
  41. package/src/runtime/highlight-element.d.ts +3 -0
  42. package/src/runtime/highlight-element.js +46 -0
  43. package/src/runtime/navigation-telemetry.d.ts +51 -0
  44. package/src/runtime/navigation-telemetry.js +259 -0
  45. package/src/runtime/preferences.d.ts +9 -0
  46. package/src/runtime/preferences.js +32 -0
  47. package/src/shell/badges.d.ts +2 -0
  48. package/src/shell/badges.js +9 -0
  49. package/src/shell/brand-logo.d.ts +4 -0
  50. package/src/shell/brand-logo.js +4 -0
  51. package/src/shell/eco-dev-toolbar.d.ts +67 -0
  52. package/src/shell/eco-dev-toolbar.js +356 -0
  53. package/src/shell/ensure-dev-toolbar-styles.d.ts +7 -0
  54. package/src/shell/ensure-dev-toolbar-styles.js +18 -0
  55. package/src/shell/icons.d.ts +8 -0
  56. package/src/shell/icons.js +29 -0
  57. package/src/shell/legacy-app-host.d.ts +23 -0
  58. package/src/shell/legacy-app-host.js +36 -0
  59. package/src/shell/motion.d.ts +6 -0
  60. package/src/shell/motion.js +82 -0
  61. package/src/shell/navigation-loading.d.ts +14 -0
  62. package/src/shell/navigation-loading.js +39 -0
  63. package/src/shell/panel-slot-visibility.d.ts +10 -0
  64. package/src/shell/panel-slot-visibility.js +25 -0
  65. package/src/shell/stealth-controller.d.ts +27 -0
  66. package/src/shell/stealth-controller.js +83 -0
  67. package/src/shell/styles/base.d.ts +1 -0
  68. package/src/shell/styles/base.js +65 -0
  69. package/src/shell/styles/content.d.ts +1 -0
  70. package/src/shell/styles/content.js +209 -0
  71. package/src/shell/styles/dock.d.ts +1 -0
  72. package/src/shell/styles/dock.js +207 -0
  73. package/src/shell/styles/index.d.ts +1 -0
  74. package/src/shell/styles/index.js +12 -0
  75. package/src/shell/styles/panel.d.ts +1 -0
  76. package/src/shell/styles/panel.js +121 -0
  77. package/src/shell/styles/settings.d.ts +1 -0
  78. package/src/shell/styles/settings.js +206 -0
  79. package/src/shell/styles.d.ts +1 -0
  80. package/src/shell/styles.js +1 -0
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @ecopages/dev-toolbar
2
+
3
+ Development-only browser toolbar for Ecopages, inspired by [Astro's dev toolbar](https://docs.astro.build/en/guides/dev-toolbar/).
4
+
5
+ User-facing docs: [Dev toolbar](https://ecopages.dev/docs/core/dev-toolbar) (enablement, manifest, built-in apps).
6
+
7
+ ## Install
8
+
9
+ Add the package to your app and opt in from config:
10
+
11
+ ```ts
12
+ import { ConfigBuilder } from '@ecopages/core/config-builder';
13
+ import { devToolbar } from '@ecopages/dev-toolbar/config';
14
+
15
+ export default new ConfigBuilder()
16
+ .setRootDir(import.meta.dirname)
17
+ .setDevToolbar(devToolbar())
18
+ .build();
19
+ ```
20
+
21
+ ```bash
22
+ pnpm add -D @ecopages/dev-toolbar
23
+ ```
24
+
25
+ During `ecopages dev`, core bundles your configured package to `/_dev_toolbar.js` and injects the dev manifest for the Deps panel. Restart the dev server after toolbar client changes.
26
+
27
+ Disable per project with `devToolbar: { enabled: false }`, or per process with `ECOPAGES_DEV_TOOLBAR=false`.
28
+
29
+ ## Built-in apps
30
+
31
+ - **Navigation** — route timing archive, initial load, client navigation latency, HMR status, page Integration (route owner); writes `#__ECO_DEV_NAV_TELEMETRY__` for machine/AI debug
32
+ - **Deps** — Page Browser Graph entry/chunk assets, vendor URLs, lazy-load hints
33
+ - **Islands** — inspect island hosts stamped with `data-eco-island` (plus legacy React `eco-island` roots); click a row to highlight the live DOM node
34
+ - **A11y** — axe-core audit (with built-in fallback checks) and in-page highlights
35
+ - **Settings** — dock placement (top, bottom, left, right), stealth mode, and documentation link
36
+
37
+ ## Bring your own dev toolbar
38
+
39
+ Core delivers the configured client at `/_dev_toolbar.js` and injects `#__ECO_DEV_MANIFEST__` per page. Your package owns the dock UI and panels.
40
+
41
+ To replace this reference toolbar:
42
+
43
+ 1. Create a client package that exports a browser bootstrap module (same layout as `@ecopages/dev-toolbar`).
44
+ 2. Set `devToolbar.package` in `eco.config.ts` (use `defineDevTool` from `@ecopages/core/dev-toolbar/define-dev-tool` for BYO packages).
45
+ 3. Fork or copy this package if you want Radiant panels, manifest readers, and stealth dock behavior.
46
+
47
+ `@ecopages/dev-toolbar` is the reference implementation.
48
+
49
+ ## Reference-toolbar internals
50
+
51
+ `window.__ECO_DEV_TOOLBAR_APPS__` is an optional registry used inside this package for experimental extra dock apps. It is **not** a supported Ecopages extension API — app authors should replace `devToolbar.package` instead.
52
+
53
+ ## Package layout
54
+
55
+ - `src/bootstrap.ts` — injects toolbar CSS into `document.head`, boots navigation telemetry, and mounts `eco-dev-toolbar`
56
+ - `src/shell/eco-dev-toolbar.tsx` — Radiant light-DOM host (JSX `render()`, no shadow root); panel positioning is pure CSS
57
+ - `src/shell/motion.ts` — WAAPI motion for stealth dock reveal only; panel show/hide is CSS
58
+ - `src/apps/*-panel.tsx` — Radiant JSX panels (navigation, deps, islands, a11y, settings)
59
+ - `src/api/` — manifest and app contracts
60
+ - `src/apps/` — built-in toolbar apps
61
+ - `src/shell/` — custom element host, SVG icons, styles, and `ensureDevToolbarStyles()` (optional CSS override for BYO toolbars)
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@ecopages/dev-toolbar",
3
+ "version": "0.2.0-beta.30",
4
+ "description": "Development toolbar for Ecopages",
5
+ "keywords": [
6
+ "ecopages",
7
+ "devtools",
8
+ "dev-toolbar"
9
+ ],
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./src/bootstrap.d.ts",
15
+ "default": "./src/bootstrap.js"
16
+ },
17
+ "./config": {
18
+ "types": "./src/config.d.ts",
19
+ "default": "./src/config.js"
20
+ },
21
+ "./api": {
22
+ "types": "./src/api/types.d.ts",
23
+ "default": "./src/api/types.js"
24
+ },
25
+ "./manifest": {
26
+ "types": "./src/api/dev-manifest.d.ts",
27
+ "default": "./src/api/dev-manifest.js"
28
+ },
29
+ "./config.ts": {
30
+ "types": "./src/config.d.ts",
31
+ "default": "./src/config.js"
32
+ },
33
+ "./api.ts": {
34
+ "types": "./src/api/types.d.ts",
35
+ "default": "./src/api/types.js"
36
+ },
37
+ "./manifest.ts": {
38
+ "types": "./src/api/dev-manifest.d.ts",
39
+ "default": "./src/api/dev-manifest.js"
40
+ }
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/ecopages/ecopages.git",
45
+ "directory": "packages/dev-toolbar"
46
+ },
47
+ "dependencies": {
48
+ "@ecopages/jsx": "0.3.0-beta.3",
49
+ "@ecopages/radiant": "0.3.0-beta.3",
50
+ "@ecopages/signals": "0.3.0-beta.3",
51
+ "axe-core": "^4.10.3"
52
+ },
53
+ "types": "./src/bootstrap.d.ts"
54
+ }
@@ -0,0 +1,33 @@
1
+ export declare const DEV_MANIFEST_ELEMENT_ID = "__ECO_DEV_MANIFEST__";
2
+ export type DevManifestAsset = {
3
+ srcUrl?: string;
4
+ kind: 'script' | 'stylesheet';
5
+ packageRole?: string;
6
+ inline?: boolean;
7
+ };
8
+ export type DevManifestPageBrowserGraph = {
9
+ entryAssets: DevManifestAsset[];
10
+ chunkAssets: DevManifestAsset[];
11
+ };
12
+ /**
13
+ * Server-serialized development metadata injected into HTML responses.
14
+ */
15
+ export type EcoDevManifest = {
16
+ route: string;
17
+ integration?: string;
18
+ pageBrowserGraph?: DevManifestPageBrowserGraph;
19
+ vendorUrls: string[];
20
+ devTransformUrls: string[];
21
+ };
22
+ /**
23
+ * Parses `#__ECO_DEV_MANIFEST__` from the active document.
24
+ *
25
+ * @returns Parsed manifest, or `undefined` when the element is missing or invalid JSON.
26
+ */
27
+ export declare function readDevManifestFromDocument(doc?: Document): EcoDevManifest | undefined;
28
+ /**
29
+ * Writes or replaces `#__ECO_DEV_MANIFEST__` in the active document.
30
+ *
31
+ * @remarks Used after client navigations so toolbar panels can read the latest route payload.
32
+ */
33
+ export declare function updateDevManifestInDocument(manifest: EcoDevManifest, doc?: Document): void;
@@ -0,0 +1,34 @@
1
+ export const DEV_MANIFEST_ELEMENT_ID = '__ECO_DEV_MANIFEST__';
2
+ /**
3
+ * Parses `#__ECO_DEV_MANIFEST__` from the active document.
4
+ *
5
+ * @returns Parsed manifest, or `undefined` when the element is missing or invalid JSON.
6
+ */
7
+ export function readDevManifestFromDocument(doc = document) {
8
+ const element = doc.getElementById(DEV_MANIFEST_ELEMENT_ID);
9
+ if (!element?.textContent) {
10
+ return undefined;
11
+ }
12
+ try {
13
+ return JSON.parse(element.textContent);
14
+ }
15
+ catch {
16
+ return undefined;
17
+ }
18
+ }
19
+ /**
20
+ * Writes or replaces `#__ECO_DEV_MANIFEST__` in the active document.
21
+ *
22
+ * @remarks Used after client navigations so toolbar panels can read the latest route payload.
23
+ */
24
+ export function updateDevManifestInDocument(manifest, doc = document) {
25
+ let element = doc.getElementById(DEV_MANIFEST_ELEMENT_ID);
26
+ if (!element) {
27
+ const script = doc.createElement('script');
28
+ script.id = DEV_MANIFEST_ELEMENT_ID;
29
+ script.setAttribute('type', 'application/json');
30
+ element = script;
31
+ doc.body.append(element);
32
+ }
33
+ element.textContent = JSON.stringify(manifest);
34
+ }
@@ -0,0 +1,21 @@
1
+ import type { EcoDevManifest } from './dev-manifest.js';
2
+ export type DevToolbarBadge = {
3
+ count?: number;
4
+ severity?: 'info' | 'warning' | 'error';
5
+ };
6
+ export type DevToolbarPanelContext = {
7
+ document: Document;
8
+ manifest: EcoDevManifest | undefined;
9
+ mountTarget: HTMLElement;
10
+ onBadgeChange: (badge: DevToolbarBadge | undefined) => void;
11
+ onRouteChange: (listener: () => void) => () => void;
12
+ };
13
+ /**
14
+ * Contract for one toolbar app panel.
15
+ */
16
+ export type DevToolbarApp = {
17
+ id: string;
18
+ label: string;
19
+ icon: string;
20
+ mount: (context: DevToolbarPanelContext) => void | (() => void);
21
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { DevToolbarBadge } from '../../api/types.js';
2
+ import type { A11yIssueView } from './run-a11y-checks.js';
3
+ export declare function toA11yBadge(issues: A11yIssueView[]): DevToolbarBadge | undefined;
@@ -0,0 +1,10 @@
1
+ export function toA11yBadge(issues) {
2
+ if (issues.length === 0) {
3
+ return undefined;
4
+ }
5
+ const hasError = issues.some((issue) => issue.severity === 'error');
6
+ return {
7
+ count: issues.length,
8
+ severity: hasError ? 'error' : 'warning',
9
+ };
10
+ }
@@ -0,0 +1,12 @@
1
+ import type { A11yIssueView } from './run-a11y-checks.js';
2
+ export type A11yIssueGroup = {
3
+ id: string;
4
+ message: string;
5
+ severity: A11yIssueView['severity'];
6
+ source: A11yIssueView['source'];
7
+ nodes: A11yIssueView[];
8
+ };
9
+ /**
10
+ * Groups audit rows that share the same rule and message so multi-node issues can be stepped through.
11
+ */
12
+ export declare function groupA11yIssues(issues: A11yIssueView[]): A11yIssueGroup[];
@@ -0,0 +1,27 @@
1
+ function groupKey(issue) {
2
+ return `${issue.source}:${issue.id}:${issue.message}`;
3
+ }
4
+ /**
5
+ * Groups audit rows that share the same rule and message so multi-node issues can be stepped through.
6
+ */
7
+ export function groupA11yIssues(issues) {
8
+ const groups = [];
9
+ const indexByKey = new Map();
10
+ for (const issue of issues) {
11
+ const key = groupKey(issue);
12
+ const existingIndex = indexByKey.get(key);
13
+ if (existingIndex === undefined) {
14
+ indexByKey.set(key, groups.length);
15
+ groups.push({
16
+ id: issue.id,
17
+ message: issue.message,
18
+ severity: issue.severity,
19
+ source: issue.source,
20
+ nodes: [issue],
21
+ });
22
+ continue;
23
+ }
24
+ groups[existingIndex]?.nodes.push(issue);
25
+ }
26
+ return groups;
27
+ }
@@ -0,0 +1,6 @@
1
+ import type { A11yIssueView } from './run-a11y-checks.js';
2
+ export declare function auditCacheKey(doc: Document): string;
3
+ export declare function readAuditCache(doc: Document): A11yIssueView[] | undefined;
4
+ export declare function writeAuditCache(doc: Document, issues: A11yIssueView[]): void;
5
+ export declare function clearAuditCache(doc: Document): void;
6
+ export declare function resetAuditCacheForTests(): void;
@@ -0,0 +1,16 @@
1
+ const auditCache = new Map();
2
+ export function auditCacheKey(doc) {
3
+ return doc.defaultView?.location.href ?? '';
4
+ }
5
+ export function readAuditCache(doc) {
6
+ return auditCache.get(auditCacheKey(doc));
7
+ }
8
+ export function writeAuditCache(doc, issues) {
9
+ auditCache.set(auditCacheKey(doc), issues);
10
+ }
11
+ export function clearAuditCache(doc) {
12
+ auditCache.delete(auditCacheKey(doc));
13
+ }
14
+ export function resetAuditCacheForTests() {
15
+ auditCache.clear();
16
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Builds a child-index path from the document root to `element`.
3
+ *
4
+ * @remarks Used to re-resolve audit targets after the live `Element` reference is dropped from cache.
5
+ */
6
+ export declare function buildDomPath(element: Element): number[];
7
+ /**
8
+ * Walks a {@link buildDomPath} sequence from `doc.documentElement`.
9
+ */
10
+ export declare function resolveDomPath(doc: Document, path: readonly number[]): Element | null;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Builds a child-index path from the document root to `element`.
3
+ *
4
+ * @remarks Used to re-resolve audit targets after the live `Element` reference is dropped from cache.
5
+ */
6
+ export function buildDomPath(element) {
7
+ const path = [];
8
+ let current = element;
9
+ while (current?.parentElement) {
10
+ const parent = current.parentElement;
11
+ path.unshift([...parent.children].indexOf(current));
12
+ current = parent;
13
+ }
14
+ return path;
15
+ }
16
+ /**
17
+ * Walks a {@link buildDomPath} sequence from `doc.documentElement`.
18
+ */
19
+ export function resolveDomPath(doc, path) {
20
+ if (path.length === 0) {
21
+ return null;
22
+ }
23
+ let current = doc.documentElement;
24
+ for (const index of path) {
25
+ const child = current.children[index];
26
+ if (!child) {
27
+ return null;
28
+ }
29
+ current = child;
30
+ }
31
+ return current;
32
+ }
@@ -0,0 +1,30 @@
1
+ export type A11yIssue = {
2
+ id: string;
3
+ message: string;
4
+ severity: 'warning' | 'error';
5
+ element: Element;
6
+ source: 'axe' | 'builtin';
7
+ targetSelector: string;
8
+ /** Stable child-index path for re-resolving the audited node. */
9
+ domPath: number[];
10
+ /** Index within `querySelectorAll(targetSelector)` when the selector matches multiple nodes. */
11
+ matchIndex: number;
12
+ };
13
+ export type A11yIssueView = Omit<A11yIssue, 'element'>;
14
+ export declare function toA11yIssueView(issue: A11yIssue): A11yIssueView;
15
+ /**
16
+ * Re-resolves the DOM node for a cached audit row.
17
+ *
18
+ * @remarks Prefers {@link A11yIssueView.domPath} because selectors can match multiple nodes (for example duplicate ids).
19
+ */
20
+ export declare function resolveA11yIssueElement(doc: Document, issue: Pick<A11yIssueView, 'targetSelector' | 'domPath' | 'matchIndex'>): Element | null;
21
+ export declare function runBuiltinChecks(doc: Document): A11yIssue[];
22
+ export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, label: string): Promise<T>;
23
+ /**
24
+ * Yields to the browser so dock clicks and panel switches stay responsive before heavy work.
25
+ */
26
+ export declare function yieldToBrowser(): Promise<void>;
27
+ /**
28
+ * Runs built-in checks immediately, then axe-core after yielding to the browser.
29
+ */
30
+ export declare function runA11yChecks(doc: Document, onBuiltin?: (issues: A11yIssue[]) => void): Promise<A11yIssue[]>;
@@ -0,0 +1,286 @@
1
+ import { buildDomPath, resolveDomPath } from './dom-path.js';
2
+ const AXE_RUN_TIMEOUT_MS = 15_000;
3
+ const AXE_EXCLUDE_SELECTORS = ['eco-dev-toolbar', '.eco-dev-toolbar__panel-shell'];
4
+ let axeRunLock = Promise.resolve();
5
+ function buildCssSelector(element, doc) {
6
+ if (element.id) {
7
+ const idSelector = `#${CSS.escape(element.id)}`;
8
+ try {
9
+ if (doc.querySelectorAll(idSelector).length === 1) {
10
+ return idSelector;
11
+ }
12
+ }
13
+ catch {
14
+ // fall through to a structural selector when the id selector is invalid or duplicated
15
+ }
16
+ }
17
+ const segments = [];
18
+ let current = element;
19
+ while (current && current !== current.ownerDocument.documentElement) {
20
+ let segment = current.tagName.toLowerCase();
21
+ const parent = current.parentElement;
22
+ if (parent) {
23
+ const siblings = [...parent.children].filter((child) => child.tagName === current.tagName);
24
+ if (siblings.length > 1) {
25
+ segment += `:nth-of-type(${siblings.indexOf(current) + 1})`;
26
+ }
27
+ }
28
+ segments.unshift(segment);
29
+ current = parent;
30
+ }
31
+ return segments.join(' > ');
32
+ }
33
+ function attachDomTarget(doc, element, targetSelector) {
34
+ const domPath = buildDomPath(element);
35
+ let matchIndex = 0;
36
+ try {
37
+ const matches = [...doc.querySelectorAll(targetSelector)].filter((candidate) => !candidate.closest('eco-dev-toolbar'));
38
+ const index = matches.indexOf(element);
39
+ if (index >= 0) {
40
+ matchIndex = index;
41
+ }
42
+ }
43
+ catch {
44
+ // keep the default match index
45
+ }
46
+ return { targetSelector, domPath, matchIndex };
47
+ }
48
+ export function toA11yIssueView(issue) {
49
+ const { element: _element, ...view } = issue;
50
+ return view;
51
+ }
52
+ /**
53
+ * Re-resolves the DOM node for a cached audit row.
54
+ *
55
+ * @remarks Prefers {@link A11yIssueView.domPath} because selectors can match multiple nodes (for example duplicate ids).
56
+ */
57
+ export function resolveA11yIssueElement(doc, issue) {
58
+ if (issue.domPath.length > 0) {
59
+ const fromPath = resolveDomPath(doc, issue.domPath);
60
+ if (fromPath instanceof Element && !fromPath.closest('eco-dev-toolbar')) {
61
+ return fromPath;
62
+ }
63
+ }
64
+ const selectors = issue.targetSelector
65
+ .split(',')
66
+ .map((selector) => selector.trim())
67
+ .filter((selector) => selector.length > 0);
68
+ const candidates = [issue.targetSelector, ...selectors];
69
+ for (const selector of candidates) {
70
+ try {
71
+ const matches = [...doc.querySelectorAll(selector)].filter((candidate) => !candidate.closest('eco-dev-toolbar'));
72
+ if (matches.length === 0) {
73
+ continue;
74
+ }
75
+ const matchIndex = issue.matchIndex ?? 0;
76
+ return matches[matchIndex] ?? matches[0] ?? null;
77
+ }
78
+ catch {
79
+ continue;
80
+ }
81
+ }
82
+ return null;
83
+ }
84
+ export function runBuiltinChecks(doc) {
85
+ const issues = [];
86
+ const ids = new Map();
87
+ for (const image of doc.querySelectorAll('img')) {
88
+ if (image.closest('eco-dev-toolbar')) {
89
+ continue;
90
+ }
91
+ if (!image.getAttribute('alt')?.trim()) {
92
+ const targetSelector = buildCssSelector(image, doc);
93
+ issues.push({
94
+ id: 'img-alt',
95
+ message: 'Image is missing alt text',
96
+ severity: 'error',
97
+ element: image,
98
+ source: 'builtin',
99
+ ...attachDomTarget(doc, image, targetSelector),
100
+ });
101
+ }
102
+ }
103
+ for (const input of doc.querySelectorAll('input, textarea, select')) {
104
+ if (input.closest('eco-dev-toolbar')) {
105
+ continue;
106
+ }
107
+ const type = input instanceof HTMLInputElement ? input.type : 'text';
108
+ if (type === 'hidden') {
109
+ continue;
110
+ }
111
+ const hasLabel = Boolean(input.labels?.length || input.getAttribute('aria-label') || input.getAttribute('aria-labelledby'));
112
+ if (!hasLabel) {
113
+ const targetSelector = buildCssSelector(input, doc);
114
+ issues.push({
115
+ id: 'form-label',
116
+ message: 'Form control is missing an accessible label',
117
+ severity: 'error',
118
+ element: input,
119
+ source: 'builtin',
120
+ ...attachDomTarget(doc, input, targetSelector),
121
+ });
122
+ }
123
+ }
124
+ let previousHeading = 0;
125
+ for (const heading of doc.querySelectorAll('h1, h2, h3, h4, h5, h6')) {
126
+ if (heading.closest('eco-dev-toolbar')) {
127
+ continue;
128
+ }
129
+ const level = Number.parseInt(heading.tagName.slice(1), 10);
130
+ if (previousHeading > 0 && level - previousHeading > 1) {
131
+ const targetSelector = buildCssSelector(heading, doc);
132
+ issues.push({
133
+ id: 'heading-order',
134
+ message: `Heading level skips from h${previousHeading} to h${level}`,
135
+ severity: 'warning',
136
+ element: heading,
137
+ source: 'builtin',
138
+ ...attachDomTarget(doc, heading, targetSelector),
139
+ });
140
+ }
141
+ previousHeading = level;
142
+ }
143
+ for (const element of doc.querySelectorAll('[id]')) {
144
+ if (element.closest('eco-dev-toolbar')) {
145
+ continue;
146
+ }
147
+ const id = element.id;
148
+ if (!id) {
149
+ continue;
150
+ }
151
+ const existing = ids.get(id);
152
+ if (existing) {
153
+ const targetSelector = buildCssSelector(element, doc);
154
+ issues.push({
155
+ id: 'duplicate-id',
156
+ message: `Duplicate id "${id}"`,
157
+ severity: 'error',
158
+ element: element,
159
+ source: 'builtin',
160
+ ...attachDomTarget(doc, element, targetSelector),
161
+ });
162
+ }
163
+ else {
164
+ ids.set(id, element);
165
+ }
166
+ }
167
+ return issues;
168
+ }
169
+ function mapAxeImpact(impact) {
170
+ if (impact === 'critical' || impact === 'serious') {
171
+ return 'error';
172
+ }
173
+ return 'warning';
174
+ }
175
+ function resolveAxeTarget(doc, target) {
176
+ const selector = Array.isArray(target) ? target.join(' ') : String(target);
177
+ if (!selector) {
178
+ return null;
179
+ }
180
+ try {
181
+ return doc.querySelector(selector);
182
+ }
183
+ catch {
184
+ return null;
185
+ }
186
+ }
187
+ export function withTimeout(promise, timeoutMs, label) {
188
+ return Promise.race([
189
+ promise,
190
+ new Promise((_resolve, reject) => {
191
+ globalThis.setTimeout(() => {
192
+ reject(new Error(`${label}-timeout`));
193
+ }, timeoutMs);
194
+ }),
195
+ ]);
196
+ }
197
+ async function withAxeRunLock(run) {
198
+ const previous = axeRunLock;
199
+ let releaseLock;
200
+ axeRunLock = new Promise((resolve) => {
201
+ releaseLock = resolve;
202
+ });
203
+ await previous;
204
+ try {
205
+ return await run();
206
+ }
207
+ finally {
208
+ releaseLock();
209
+ }
210
+ }
211
+ async function runAxeChecks(doc) {
212
+ return withAxeRunLock(async () => {
213
+ const axeModule = await import('axe-core');
214
+ const axe = axeModule.default;
215
+ const runAxe = axe.run;
216
+ const results = await withTimeout(runAxe(doc.documentElement, {
217
+ exclude: AXE_EXCLUDE_SELECTORS.map((selector) => [selector]),
218
+ iframes: false,
219
+ }), AXE_RUN_TIMEOUT_MS, 'axe-run');
220
+ const issues = [];
221
+ for (const violation of results.violations) {
222
+ for (const node of violation.nodes) {
223
+ const selector = Array.isArray(node.target) ? node.target.join(' ') : node.target;
224
+ const element = selector ? resolveAxeTarget(doc, selector) : null;
225
+ if (!(element instanceof Element) || element.closest('eco-dev-toolbar')) {
226
+ continue;
227
+ }
228
+ issues.push({
229
+ id: violation.id,
230
+ message: node.failureSummary?.trim() || violation.help,
231
+ severity: mapAxeImpact(violation.impact),
232
+ element,
233
+ source: 'axe',
234
+ ...attachDomTarget(doc, element, selector),
235
+ });
236
+ }
237
+ }
238
+ return issues;
239
+ });
240
+ }
241
+ function issueKey(issue) {
242
+ return `${issue.source}:${issue.id}:${issue.domPath.join('.')}`;
243
+ }
244
+ function dedupeIssues(issues) {
245
+ const seen = new Set();
246
+ const result = [];
247
+ for (const issue of issues) {
248
+ const key = issueKey(issue);
249
+ if (seen.has(key)) {
250
+ continue;
251
+ }
252
+ seen.add(key);
253
+ result.push(issue);
254
+ }
255
+ return result;
256
+ }
257
+ /**
258
+ * Yields to the browser so dock clicks and panel switches stay responsive before heavy work.
259
+ */
260
+ export function yieldToBrowser() {
261
+ return new Promise((resolve) => {
262
+ globalThis.requestAnimationFrame(() => {
263
+ globalThis.setTimeout(resolve, 0);
264
+ });
265
+ });
266
+ }
267
+ /**
268
+ * Runs built-in checks immediately, then axe-core after yielding to the browser.
269
+ */
270
+ export async function runA11yChecks(doc, onBuiltin) {
271
+ const builtinIssues = runBuiltinChecks(doc);
272
+ onBuiltin?.(builtinIssues);
273
+ await yieldToBrowser();
274
+ let axeIssues = [];
275
+ try {
276
+ axeIssues = await runAxeChecks(doc);
277
+ }
278
+ catch {
279
+ return builtinIssues;
280
+ }
281
+ if (axeIssues.length === 0) {
282
+ return builtinIssues;
283
+ }
284
+ const extraBuiltin = builtinIssues.filter((issue) => !axeIssues.some((axeIssue) => axeIssue.element === issue.element && axeIssue.id === issue.id));
285
+ return dedupeIssues([...axeIssues, ...extraBuiltin]);
286
+ }