@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
@@ -0,0 +1,259 @@
1
+ export const NAV_TELEMETRY_ELEMENT_ID = '__ECO_DEV_NAV_TELEMETRY__';
2
+ export const NAV_TELEMETRY_STORAGE_KEY = 'ecopages:dev-toolbar:nav-telemetry';
3
+ export const NAV_TELEMETRY_MAX_ENTRIES = 50;
4
+ let nextEntryId = 0;
5
+ let activeEntry = null;
6
+ let history = [];
7
+ let swapStartedAt = null;
8
+ let initialized = false;
9
+ let telemetryDocument;
10
+ /** @internal */
11
+ export function resetNavigationTelemetryForTests() {
12
+ initialized = false;
13
+ telemetryDocument = undefined;
14
+ nextEntryId = 0;
15
+ activeEntry = null;
16
+ history = [];
17
+ swapStartedAt = null;
18
+ }
19
+ function createEntryId() {
20
+ nextEntryId += 1;
21
+ return `nav-${nextEntryId}`;
22
+ }
23
+ function getNavigationOwner() {
24
+ const runtime = window.__ECO_PAGES__?.navigation;
25
+ const owner = runtime?.getNavigationOwner?.();
26
+ if (owner) {
27
+ return owner;
28
+ }
29
+ if (window.__ecopages_browser_router__) {
30
+ return 'browser-router';
31
+ }
32
+ return 'full-document';
33
+ }
34
+ function readHydrationMs() {
35
+ const value = window.__ECO_DEV_HYDRATION_MS__;
36
+ return typeof value === 'number' ? Math.round(value) : undefined;
37
+ }
38
+ function readNavigationTimingMetrics() {
39
+ const [entry] = performance.getEntriesByType('navigation');
40
+ if (!entry) {
41
+ return undefined;
42
+ }
43
+ return {
44
+ ttfbMs: Math.round(entry.responseStart),
45
+ domInteractiveMs: Math.round(entry.domInteractive),
46
+ loadEventMs: Math.round(entry.loadEventEnd),
47
+ domContentLoadedMs: Math.round(entry.domContentLoadedEventEnd),
48
+ };
49
+ }
50
+ function readPersistedHistory() {
51
+ try {
52
+ const raw = localStorage.getItem(NAV_TELEMETRY_STORAGE_KEY);
53
+ if (!raw) {
54
+ return [];
55
+ }
56
+ const parsed = JSON.parse(raw);
57
+ return Array.isArray(parsed) ? parsed : [];
58
+ }
59
+ catch {
60
+ return [];
61
+ }
62
+ }
63
+ function persistHistory(entries) {
64
+ try {
65
+ localStorage.setItem(NAV_TELEMETRY_STORAGE_KEY, JSON.stringify(entries));
66
+ }
67
+ catch {
68
+ // Ignore quota errors in dev tooling.
69
+ }
70
+ }
71
+ function summarize(entries) {
72
+ const initial = entries.find((entry) => entry.kind === 'initial');
73
+ const navigations = entries.filter((entry) => entry.kind === 'client-navigation' && entry.status !== 'aborted' && typeof entry.durationMs === 'number');
74
+ const durations = navigations.map((entry) => entry.durationMs);
75
+ const averageNavigationMs = durations.length === 0
76
+ ? undefined
77
+ : Math.round(durations.reduce((sum, value) => sum + value, 0) / durations.length);
78
+ return {
79
+ initialLoadMs: initial?.durationMs,
80
+ lastNavigationMs: navigations[navigations.length - 1]?.durationMs,
81
+ averageNavigationMs,
82
+ navigationCount: navigations.length,
83
+ };
84
+ }
85
+ function getTelemetryDocument() {
86
+ if (telemetryDocument) {
87
+ return telemetryDocument;
88
+ }
89
+ return document;
90
+ }
91
+ function buildSnapshot(doc = getTelemetryDocument()) {
92
+ const route = `${window.location.pathname}${window.location.search}`;
93
+ return {
94
+ updatedAt: new Date().toISOString(),
95
+ currentRoute: route,
96
+ active: activeEntry,
97
+ history,
98
+ summary: summarize(history),
99
+ };
100
+ }
101
+ function syncTelemetryElement(doc = getTelemetryDocument()) {
102
+ const snapshot = buildSnapshot(doc);
103
+ let element = doc.getElementById(NAV_TELEMETRY_ELEMENT_ID);
104
+ if (!element) {
105
+ const script = doc.createElement('script');
106
+ script.id = NAV_TELEMETRY_ELEMENT_ID;
107
+ script.setAttribute('type', 'application/json');
108
+ element = script;
109
+ doc.body.append(element);
110
+ }
111
+ element.textContent = JSON.stringify(snapshot);
112
+ window.__ECO_DEV_NAV_TELEMETRY__ = createNavigationTelemetryApi();
113
+ return snapshot;
114
+ }
115
+ function finalizeEntry(entry, patch) {
116
+ const endedAt = patch.endedAt ?? new Date().toISOString();
117
+ const completed = {
118
+ ...entry,
119
+ ...patch,
120
+ status: patch.status ?? entry.status ?? 'completed',
121
+ endedAt,
122
+ durationMs: patch.durationMs ??
123
+ (typeof entry.durationMs === 'number'
124
+ ? entry.durationMs
125
+ : Math.max(0, Math.round(performance.now() - performance.timeOrigin))),
126
+ hydrationMs: patch.hydrationMs ?? readHydrationMs(),
127
+ navigationOwner: patch.navigationOwner ?? getNavigationOwner(),
128
+ };
129
+ history = [...history, completed].slice(-NAV_TELEMETRY_MAX_ENTRIES);
130
+ persistHistory(history);
131
+ activeEntry = null;
132
+ return completed;
133
+ }
134
+ function abortActiveNavigation() {
135
+ if (!activeEntry || activeEntry.kind !== 'client-navigation') {
136
+ return;
137
+ }
138
+ const durationMs = swapStartedAt === null ? undefined : Math.max(0, Math.round(performance.now() - swapStartedAt));
139
+ finalizeEntry(activeEntry, {
140
+ status: 'aborted',
141
+ route: `${window.location.pathname}${window.location.search}`,
142
+ durationMs,
143
+ swapMs: durationMs,
144
+ });
145
+ swapStartedAt = null;
146
+ }
147
+ function beginClientNavigation(fromRoute) {
148
+ activeEntry = {
149
+ id: createEntryId(),
150
+ kind: 'client-navigation',
151
+ route: fromRoute,
152
+ fromRoute,
153
+ startedAt: new Date().toISOString(),
154
+ navigationOwner: getNavigationOwner(),
155
+ };
156
+ syncTelemetryElement();
157
+ }
158
+ function completeActiveNavigation(doc, patch = {}) {
159
+ if (!activeEntry) {
160
+ return;
161
+ }
162
+ const durationMs = patch.durationMs ??
163
+ (swapStartedAt === null ? undefined : Math.max(0, Math.round(performance.now() - swapStartedAt)));
164
+ finalizeEntry(activeEntry, {
165
+ route: `${window.location.pathname}${window.location.search}`,
166
+ swapMs: durationMs,
167
+ durationMs,
168
+ ...patch,
169
+ });
170
+ swapStartedAt = null;
171
+ syncTelemetryElement(doc);
172
+ }
173
+ function recordInitialLoad(doc) {
174
+ if (history.some((entry) => entry.kind === 'initial')) {
175
+ completeActiveNavigation(doc);
176
+ return;
177
+ }
178
+ const navigationTiming = readNavigationTimingMetrics();
179
+ const durationMs = navigationTiming?.loadEventMs ?? navigationTiming?.domContentLoadedMs;
180
+ finalizeEntry({
181
+ id: createEntryId(),
182
+ kind: 'initial',
183
+ route: `${window.location.pathname}${window.location.search}`,
184
+ startedAt: new Date(performance.timeOrigin).toISOString(),
185
+ navigationTiming,
186
+ navigationOwner: getNavigationOwner(),
187
+ }, {
188
+ durationMs,
189
+ hydrationMs: readHydrationMs(),
190
+ });
191
+ syncTelemetryElement(doc);
192
+ }
193
+ function createNavigationTelemetryApi() {
194
+ return {
195
+ getSnapshot: () => buildSnapshot(),
196
+ clearHistory: () => {
197
+ history = [];
198
+ activeEntry = null;
199
+ persistHistory(history);
200
+ return syncTelemetryElement();
201
+ },
202
+ };
203
+ }
204
+ /**
205
+ * Boots route timing collection, DOM JSON trace export, and `window.__ECO_DEV_NAV_TELEMETRY__`.
206
+ */
207
+ export function initNavigationTelemetry(doc = document) {
208
+ if (initialized) {
209
+ return createNavigationTelemetryApi();
210
+ }
211
+ initialized = true;
212
+ telemetryDocument = doc;
213
+ history = readPersistedHistory();
214
+ const handleBeforeSwap = () => {
215
+ abortActiveNavigation();
216
+ swapStartedAt = performance.now();
217
+ beginClientNavigation(`${window.location.pathname}${window.location.search}`);
218
+ };
219
+ const handleAfterSwap = () => {
220
+ completeActiveNavigation(doc);
221
+ };
222
+ const handlePageLoad = () => {
223
+ if (activeEntry?.kind === 'client-navigation') {
224
+ completeActiveNavigation(doc);
225
+ return;
226
+ }
227
+ recordInitialLoad(doc);
228
+ };
229
+ doc.addEventListener('eco:before-swap', handleBeforeSwap);
230
+ doc.addEventListener('eco:after-swap', handleAfterSwap);
231
+ doc.addEventListener('eco:page-load', handlePageLoad);
232
+ if (doc.readyState === 'complete' || doc.readyState === 'interactive') {
233
+ recordInitialLoad(doc);
234
+ }
235
+ else {
236
+ doc.addEventListener('DOMContentLoaded', () => recordInitialLoad(doc), { once: true });
237
+ }
238
+ const api = createNavigationTelemetryApi();
239
+ window.__ECO_DEV_NAV_TELEMETRY__ = api;
240
+ syncTelemetryElement(doc);
241
+ return api;
242
+ }
243
+ export function readNavigationTelemetrySnapshot(doc = document) {
244
+ const element = doc.getElementById(NAV_TELEMETRY_ELEMENT_ID);
245
+ if (!element?.textContent) {
246
+ return undefined;
247
+ }
248
+ try {
249
+ return JSON.parse(element.textContent);
250
+ }
251
+ catch {
252
+ return undefined;
253
+ }
254
+ }
255
+ /** Clears persisted navigation history and the DOM telemetry trace. */
256
+ export function clearNavigationTelemetryHistory() {
257
+ const api = window.__ECO_DEV_NAV_TELEMETRY__;
258
+ return api?.clearHistory();
259
+ }
@@ -0,0 +1,9 @@
1
+ export type DevToolbarPlacement = 'top' | 'bottom' | 'left' | 'right';
2
+ export type DevToolbarPreferences = {
3
+ placement: DevToolbarPlacement;
4
+ stealth: boolean;
5
+ };
6
+ export declare function parseDevToolbarPlacement(value: string | null | undefined): DevToolbarPlacement;
7
+ export declare function isVerticalDockPlacement(placement: DevToolbarPlacement): boolean;
8
+ export declare function readDevToolbarPreferences(): DevToolbarPreferences;
9
+ export declare function writeDevToolbarPreferences(partial: Partial<DevToolbarPreferences>): DevToolbarPreferences;
@@ -0,0 +1,32 @@
1
+ import { DEV_TOOLBAR_PLACEMENT_STORAGE_KEY, DEV_TOOLBAR_STEALTH_STORAGE_KEY } from './constants.js';
2
+ const DEFAULT_PREFERENCES = {
3
+ placement: 'bottom',
4
+ stealth: true,
5
+ };
6
+ export function parseDevToolbarPlacement(value) {
7
+ if (value === 'top' || value === 'bottom' || value === 'left' || value === 'right') {
8
+ return value;
9
+ }
10
+ return DEFAULT_PREFERENCES.placement;
11
+ }
12
+ export function isVerticalDockPlacement(placement) {
13
+ return placement === 'left' || placement === 'right';
14
+ }
15
+ export function readDevToolbarPreferences() {
16
+ const placement = localStorage.getItem(DEV_TOOLBAR_PLACEMENT_STORAGE_KEY);
17
+ const stealth = localStorage.getItem(DEV_TOOLBAR_STEALTH_STORAGE_KEY);
18
+ return {
19
+ placement: parseDevToolbarPlacement(placement),
20
+ stealth: stealth === null ? DEFAULT_PREFERENCES.stealth : stealth !== 'false',
21
+ };
22
+ }
23
+ export function writeDevToolbarPreferences(partial) {
24
+ const current = readDevToolbarPreferences();
25
+ const next = {
26
+ placement: partial.placement ?? current.placement,
27
+ stealth: partial.stealth ?? current.stealth,
28
+ };
29
+ localStorage.setItem(DEV_TOOLBAR_PLACEMENT_STORAGE_KEY, next.placement);
30
+ localStorage.setItem(DEV_TOOLBAR_STEALTH_STORAGE_KEY, String(next.stealth));
31
+ return next;
32
+ }
@@ -0,0 +1,2 @@
1
+ import type { DevToolbarBadge } from '../api/types.js';
2
+ export declare function badgesEqual(left: DevToolbarBadge | undefined, right: DevToolbarBadge | undefined): boolean;
@@ -0,0 +1,9 @@
1
+ export function badgesEqual(left, right) {
2
+ if (left === right) {
3
+ return true;
4
+ }
5
+ if (!left || !right) {
6
+ return false;
7
+ }
8
+ return left.count === right.count && left.severity === right.severity;
9
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Ecopages mark for dark backgrounds (`assets/brand/logo-on-dark.svg`).
3
+ */
4
+ export declare const BRAND_LOGO_ON_DARK_SVG = "<svg width=\"34\" height=\"41\" viewBox=\"0 0 34 41\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\"><path d=\"M8.95038 19.0355C8.73635 19.7972 10.4934 24.8245 18.2298 23.3884C25.3299 22.0704 24.7298 10.8884 18.2298 13.8884C14.2596 15.7208 12.2883 33.409 22.2298 31.8884C29.9216 30.7119 28.75 6.88571 31.434 1.38842C28.4393 4.49822 5.89504 5.06008 2.22981 17.8884C1.27183 21.2414 3.2298 26.8884 8.95037 28.3884L2.22981 38.3884\" stroke=\"currentColor\" stroke-width=\"4\" stroke-linecap=\"round\"/></svg>";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Ecopages mark for dark backgrounds (`assets/brand/logo-on-dark.svg`).
3
+ */
4
+ export const BRAND_LOGO_ON_DARK_SVG = `<svg width="34" height="41" viewBox="0 0 34 41" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M8.95038 19.0355C8.73635 19.7972 10.4934 24.8245 18.2298 23.3884C25.3299 22.0704 24.7298 10.8884 18.2298 13.8884C14.2596 15.7208 12.2883 33.409 22.2298 31.8884C29.9216 30.7119 28.75 6.88571 31.434 1.38842C28.4393 4.49822 5.89504 5.06008 2.22981 17.8884C1.27183 21.2414 3.2298 26.8884 8.95037 28.3884L2.22981 38.3884" stroke="currentColor" stroke-width="4" stroke-linecap="round"/></svg>`;
@@ -0,0 +1,67 @@
1
+ /** @jsxImportSource @ecopages/jsx */
2
+ import '@ecopages/radiant/client/install-hydrator';
3
+ import { RadiantElement } from '@ecopages/radiant';
4
+ import '../apps/a11y-panel.js';
5
+ import '../apps/deps-panel.js';
6
+ import '../apps/islands-panel.js';
7
+ import '../apps/navigation-panel.js';
8
+ import '../apps/settings-panel.js';
9
+ import { type EcoDevManifest } from '../api/dev-manifest.js';
10
+ import type { DevToolbarBadge } from '../api/types.js';
11
+ import { DEV_TOOLBAR_ELEMENT_NAME } from '../runtime/constants.js';
12
+ import { type DevToolbarPlacement } from '../runtime/preferences.js';
13
+ import { type StealthPhase } from './stealth-controller.js';
14
+ export declare class EcoDevToolbar extends RadiantElement {
15
+ placement: DevToolbarPlacement;
16
+ stealthEnabled: boolean;
17
+ stealthPhase: StealthPhase;
18
+ hovered: boolean;
19
+ panelOpen: boolean;
20
+ activeAppId: string | null;
21
+ badges: Record<string, DevToolbarBadge | undefined>;
22
+ loadingApps: Record<string, boolean>;
23
+ mountedAppIds: string[];
24
+ /** Optional dock apps from the reference-toolbar internal registry (`window.__ECO_DEV_TOOLBAR_APPS__`). */
25
+ extensionApps: Array<{
26
+ id: string;
27
+ label: string;
28
+ }>;
29
+ legacyPanel?: HTMLElement;
30
+ private cleanupActiveApp;
31
+ private documentListenersWired;
32
+ private readonly routeListeners;
33
+ private readonly legacyAppHost;
34
+ private readonly stealthController;
35
+ private readonly navigationLoading;
36
+ constructor();
37
+ static mount(): EcoDevToolbar;
38
+ connectedCallback(): void;
39
+ disconnectedCallback(): void;
40
+ setAppBadge(appId: string, badge: DevToolbarBadge | undefined): void;
41
+ notifyRouteChange(manifest?: EcoDevManifest): void;
42
+ applyPreferences(partial: {
43
+ placement?: DevToolbarPlacement;
44
+ stealth?: boolean;
45
+ }): void;
46
+ private handleShellEnter;
47
+ private handleShellLeave;
48
+ private handleShellClick;
49
+ private handlePointerLeave;
50
+ private mountLegacyPanelWhenNeeded;
51
+ private wireDocumentListeners;
52
+ private unwireDocumentListeners;
53
+ private readonly handleOutsideClick;
54
+ private readonly handleNavigationStart;
55
+ private readonly handleNavigationEnd;
56
+ private readonly handleRouteChange;
57
+ private toggleApp;
58
+ private openApp;
59
+ private closePanel;
60
+ private renderAppIcon;
61
+ private renderDockButton;
62
+ private renderRadiantPanelSlot;
63
+ private renderLegacyPanel;
64
+ private renderActivePanel;
65
+ render(): import("@ecopages/jsx").JsxRenderable;
66
+ }
67
+ export { DEV_TOOLBAR_ELEMENT_NAME };