ui-router-devtools 0.0.1-alpha.0 → 0.2.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.
Files changed (228) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +203 -0
  3. package/dist/console.d.ts +5 -0
  4. package/dist/console.d.ts.map +1 -0
  5. package/dist/console.js +47 -0
  6. package/dist/console.js.map +1 -0
  7. package/dist/define.d.ts +8 -0
  8. package/dist/define.d.ts.map +1 -0
  9. package/dist/define.js +4 -0
  10. package/dist/define.js.map +1 -0
  11. package/dist/edges.d.ts +25 -0
  12. package/dist/edges.d.ts.map +1 -0
  13. package/dist/edges.js +28 -0
  14. package/dist/edges.js.map +1 -0
  15. package/dist/element/chips.d.ts +17 -0
  16. package/dist/element/chips.d.ts.map +1 -0
  17. package/dist/element/chips.js +134 -0
  18. package/dist/element/chips.js.map +1 -0
  19. package/dist/element/glyphs.d.ts +34 -0
  20. package/dist/element/glyphs.d.ts.map +1 -0
  21. package/dist/element/glyphs.js +107 -0
  22. package/dist/element/glyphs.js.map +1 -0
  23. package/dist/element/inspector.d.ts +7 -0
  24. package/dist/element/inspector.d.ts.map +1 -0
  25. package/dist/element/inspector.js +183 -0
  26. package/dist/element/inspector.js.map +1 -0
  27. package/dist/element/links.d.ts +4 -0
  28. package/dist/element/links.d.ts.map +1 -0
  29. package/dist/element/links.js +87 -0
  30. package/dist/element/links.js.map +1 -0
  31. package/dist/element/log.d.ts +12 -0
  32. package/dist/element/log.d.ts.map +1 -0
  33. package/dist/element/log.js +272 -0
  34. package/dist/element/log.js.map +1 -0
  35. package/dist/element/map.d.ts +5 -0
  36. package/dist/element/map.d.ts.map +1 -0
  37. package/dist/element/map.js +5 -0
  38. package/dist/element/map.js.map +1 -0
  39. package/dist/element/mapview.d.ts +17 -0
  40. package/dist/element/mapview.d.ts.map +1 -0
  41. package/dist/element/mapview.js +158 -0
  42. package/dist/element/mapview.js.map +1 -0
  43. package/dist/element/measure.d.ts +3 -0
  44. package/dist/element/measure.d.ts.map +1 -0
  45. package/dist/element/measure.js +9 -0
  46. package/dist/element/measure.js.map +1 -0
  47. package/dist/element/nested.d.ts +45 -0
  48. package/dist/element/nested.d.ts.map +1 -0
  49. package/dist/element/nested.js +686 -0
  50. package/dist/element/nested.js.map +1 -0
  51. package/dist/element/pack.d.ts +75 -0
  52. package/dist/element/pack.d.ts.map +1 -0
  53. package/dist/element/pack.js +281 -0
  54. package/dist/element/pack.js.map +1 -0
  55. package/dist/element/panel.d.ts +160 -0
  56. package/dist/element/panel.d.ts.map +1 -0
  57. package/dist/element/panel.js +1562 -0
  58. package/dist/element/panel.js.map +1 -0
  59. package/dist/element/popover.d.ts +12 -0
  60. package/dist/element/popover.d.ts.map +1 -0
  61. package/dist/element/popover.js +38 -0
  62. package/dist/element/popover.js.map +1 -0
  63. package/dist/element/route.d.ts +75 -0
  64. package/dist/element/route.d.ts.map +1 -0
  65. package/dist/element/route.js +883 -0
  66. package/dist/element/route.js.map +1 -0
  67. package/dist/element/scrubber.d.ts +4 -0
  68. package/dist/element/scrubber.d.ts.map +1 -0
  69. package/dist/element/scrubber.js +67 -0
  70. package/dist/element/scrubber.js.map +1 -0
  71. package/dist/element/styles.d.ts +3 -0
  72. package/dist/element/styles.d.ts.map +1 -0
  73. package/dist/element/styles.js +2084 -0
  74. package/dist/element/styles.js.map +1 -0
  75. package/dist/element/timeline-styles.d.ts +3 -0
  76. package/dist/element/timeline-styles.d.ts.map +1 -0
  77. package/dist/element/timeline-styles.js +286 -0
  78. package/dist/element/timeline-styles.js.map +1 -0
  79. package/dist/element/timeline.d.ts +9 -0
  80. package/dist/element/timeline.d.ts.map +1 -0
  81. package/dist/element/timeline.js +225 -0
  82. package/dist/element/timeline.js.map +1 -0
  83. package/dist/element/tree.d.ts +24 -0
  84. package/dist/element/tree.d.ts.map +1 -0
  85. package/dist/element/tree.js +149 -0
  86. package/dist/element/tree.js.map +1 -0
  87. package/dist/element/viewmap-styles.d.ts +3 -0
  88. package/dist/element/viewmap-styles.d.ts.map +1 -0
  89. package/dist/element/viewmap-styles.js +282 -0
  90. package/dist/element/viewmap-styles.js.map +1 -0
  91. package/dist/element/viewmap.d.ts +39 -0
  92. package/dist/element/viewmap.d.ts.map +1 -0
  93. package/dist/element/viewmap.js +406 -0
  94. package/dist/element/viewmap.js.map +1 -0
  95. package/dist/element/viewport.d.ts +31 -0
  96. package/dist/element/viewport.d.ts.map +1 -0
  97. package/dist/element/viewport.js +37 -0
  98. package/dist/element/viewport.js.map +1 -0
  99. package/dist/element/waterfall.d.ts +85 -0
  100. package/dist/element/waterfall.d.ts.map +1 -0
  101. package/dist/element/waterfall.js +284 -0
  102. package/dist/element/waterfall.js.map +1 -0
  103. package/dist/fold.d.ts +27 -0
  104. package/dist/fold.d.ts.map +1 -0
  105. package/dist/fold.js +104 -0
  106. package/dist/fold.js.map +1 -0
  107. package/dist/index.d.ts +6 -0
  108. package/dist/index.d.ts.map +1 -0
  109. package/dist/index.js +6 -0
  110. package/dist/index.js.map +1 -0
  111. package/dist/lazy.d.ts +57 -0
  112. package/dist/lazy.d.ts.map +1 -0
  113. package/dist/lazy.js +63 -0
  114. package/dist/lazy.js.map +1 -0
  115. package/dist/lit-ui-router.d.ts +24 -0
  116. package/dist/lit-ui-router.d.ts.map +1 -0
  117. package/dist/lit-ui-router.js +102 -0
  118. package/dist/lit-ui-router.js.map +1 -0
  119. package/dist/notation.d.ts +28 -0
  120. package/dist/notation.d.ts.map +1 -0
  121. package/dist/notation.js +105 -0
  122. package/dist/notation.js.map +1 -0
  123. package/dist/performance.d.ts +5 -0
  124. package/dist/performance.d.ts.map +1 -0
  125. package/dist/performance.js +66 -0
  126. package/dist/performance.js.map +1 -0
  127. package/dist/plugin.d.ts +32 -0
  128. package/dist/plugin.d.ts.map +1 -0
  129. package/dist/plugin.js +21 -0
  130. package/dist/plugin.js.map +1 -0
  131. package/dist/recorder.d.ts +30 -0
  132. package/dist/recorder.d.ts.map +1 -0
  133. package/dist/recorder.js +117 -0
  134. package/dist/recorder.js.map +1 -0
  135. package/dist/schema.d.ts +2 -0
  136. package/dist/schema.d.ts.map +1 -0
  137. package/dist/schema.js +2 -0
  138. package/dist/schema.js.map +1 -0
  139. package/dist/session-schema.d.ts +31 -0
  140. package/dist/session-schema.d.ts.map +1 -0
  141. package/dist/session-schema.js +314 -0
  142. package/dist/session-schema.js.map +1 -0
  143. package/dist/session.schema.json +1172 -0
  144. package/dist/shared/event-schema.d.ts +225 -0
  145. package/dist/shared/event-schema.d.ts.map +1 -0
  146. package/dist/shared/event-schema.js +2 -0
  147. package/dist/shared/event-schema.js.map +1 -0
  148. package/dist/shared/redaction.d.ts +19 -0
  149. package/dist/shared/redaction.d.ts.map +1 -0
  150. package/dist/shared/redaction.js +56 -0
  151. package/dist/shared/redaction.js.map +1 -0
  152. package/dist/shared/resolve-timing.d.ts +6 -0
  153. package/dist/shared/resolve-timing.d.ts.map +1 -0
  154. package/dist/shared/resolve-timing.js +61 -0
  155. package/dist/shared/resolve-timing.js.map +1 -0
  156. package/dist/shared/router-events.d.ts +10 -0
  157. package/dist/shared/router-events.d.ts.map +1 -0
  158. package/dist/shared/router-events.js +296 -0
  159. package/dist/shared/router-events.js.map +1 -0
  160. package/dist/shared/thrown.d.ts +5 -0
  161. package/dist/shared/thrown.d.ts.map +1 -0
  162. package/dist/shared/thrown.js +12 -0
  163. package/dist/shared/thrown.js.map +1 -0
  164. package/dist/shared/transition-source.d.ts +4 -0
  165. package/dist/shared/transition-source.d.ts.map +1 -0
  166. package/dist/shared/transition-source.js +2 -0
  167. package/dist/shared/transition-source.js.map +1 -0
  168. package/dist/shared/views.d.ts +10 -0
  169. package/dist/shared/views.d.ts.map +1 -0
  170. package/dist/shared/views.js +67 -0
  171. package/dist/shared/views.js.map +1 -0
  172. package/dist/spans.d.ts +15 -0
  173. package/dist/spans.d.ts.map +1 -0
  174. package/dist/spans.js +24 -0
  175. package/dist/spans.js.map +1 -0
  176. package/dist/testing.d.ts +32 -0
  177. package/dist/testing.d.ts.map +1 -0
  178. package/dist/testing.js +28 -0
  179. package/dist/testing.js.map +1 -0
  180. package/dist/ui-router-devtools.d.ts +36 -0
  181. package/dist/ui-router-devtools.d.ts.map +1 -0
  182. package/dist/ui-router-devtools.js +3 -0
  183. package/dist/ui-router-devtools.js.map +1 -0
  184. package/dist/views.d.ts +44 -0
  185. package/dist/views.d.ts.map +1 -0
  186. package/dist/views.js +43 -0
  187. package/dist/views.js.map +1 -0
  188. package/package.json +123 -2
  189. package/src/console.ts +104 -0
  190. package/src/define.ts +12 -0
  191. package/src/edges.ts +64 -0
  192. package/src/element/chips.ts +187 -0
  193. package/src/element/glyphs.ts +218 -0
  194. package/src/element/inspector.ts +315 -0
  195. package/src/element/links.ts +136 -0
  196. package/src/element/log.ts +410 -0
  197. package/src/element/map.ts +22 -0
  198. package/src/element/mapview.ts +224 -0
  199. package/src/element/measure.ts +13 -0
  200. package/src/element/nested.ts +1124 -0
  201. package/src/element/pack.ts +526 -0
  202. package/src/element/panel.ts +2410 -0
  203. package/src/element/popover.ts +64 -0
  204. package/src/element/route.ts +1481 -0
  205. package/src/element/scrubber.ts +103 -0
  206. package/src/element/styles.ts +2084 -0
  207. package/src/element/timeline-styles.ts +287 -0
  208. package/src/element/timeline.ts +392 -0
  209. package/src/element/tree.ts +271 -0
  210. package/src/element/viewmap-styles.ts +283 -0
  211. package/src/element/viewmap.ts +733 -0
  212. package/src/element/viewport.ts +112 -0
  213. package/src/element/waterfall.ts +585 -0
  214. package/src/fold.ts +151 -0
  215. package/src/index.ts +40 -0
  216. package/src/lazy.ts +134 -0
  217. package/src/lit-ui-router.ts +194 -0
  218. package/src/notation.ts +181 -0
  219. package/src/performance.ts +142 -0
  220. package/src/plugin.ts +57 -0
  221. package/src/recorder.ts +228 -0
  222. package/src/schema.ts +32 -0
  223. package/src/session-schema.ts +362 -0
  224. package/src/spans.ts +53 -0
  225. package/src/testing.ts +74 -0
  226. package/src/types/import-meta-env.d.ts +9 -0
  227. package/src/ui-router-devtools.ts +39 -0
  228. package/src/views.ts +116 -0
@@ -0,0 +1,1562 @@
1
+ import { adoptStyles, html, LitElement, nothing } from "lit";
2
+ import { record } from "../recorder.js";
3
+ import { ancestorsOf, apply, bareName, durationOf, emptyModel, fold, originOf } from "../fold.js";
4
+ import { ms, resultLine, seq } from "../notation.js";
5
+ import { defaultRedaction, redactionOf, redactSession } from "../shared/redaction.js";
6
+ import { SCHEMA_VERSION } from "../schema.js";
7
+ import { spansDuring, upsertSpan } from "../spans.js";
8
+ import { closeGlyph, depthClass, maxGlyph, minGlyph, statusGlyph, statusLabel, took } from "./glyphs.js";
9
+ import { styles } from "./styles.js";
10
+ import { renderOutline } from "./tree.js";
11
+ import { placeBeside } from "./popover.js";
12
+ import { renderScrubber } from "./scrubber.js";
13
+ import { renderLog } from "./log.js";
14
+ import { renderRouterCard, renderStateInspector, renderTxInspector } from "./inspector.js";
15
+ const SNAPSHOTS = new Set([
16
+ "config",
17
+ "states",
18
+ "current",
19
+ "views"
20
+ ]);
21
+ const MAP_FAILED = "The Map did not load. Switch views to retry.";
22
+ const TIMELINE_FAILED = "The Timeline did not load. Switch views to retry.";
23
+ const VIEWS_FAILED = "The Views did not load. Switch views to retry.";
24
+ const HEADINGS = {
25
+ outline: "States",
26
+ map: "States",
27
+ timeline: "Timeline",
28
+ views: "Views"
29
+ };
30
+ const NESTED_MIN_WIDTH = 560;
31
+ const SETTLE = 200;
32
+ const ASIDE = 320;
33
+ const MARGIN = 12;
34
+ const DRAG = 4;
35
+ const EASE_OUT = "cubic-bezier(0.23, 1, 0.32, 1)";
36
+ const FLIP = "uird-flip";
37
+ const RESCALE = "uird-rescale";
38
+ const LAYOUT_KEY = "ui-router-devtools:map-layout";
39
+ const storedLayout = () => {
40
+ try {
41
+ return localStorage.getItem(LAYOUT_KEY) === "tree" ? "tree" : "nested";
42
+ } catch {
43
+ return "nested";
44
+ }
45
+ };
46
+ const storeLayout = (layout) => {
47
+ try {
48
+ localStorage.setItem(LAYOUT_KEY, layout);
49
+ } catch {}
50
+ };
51
+ const VIEWS_KEY = "ui-router-devtools:map-views";
52
+ const storedViews = () => {
53
+ try {
54
+ return localStorage.getItem(VIEWS_KEY) !== "off";
55
+ } catch {
56
+ return true;
57
+ }
58
+ };
59
+ const storeViews = (shown) => {
60
+ try {
61
+ localStorage.setItem(VIEWS_KEY, shown ? "on" : "off");
62
+ } catch {}
63
+ };
64
+ const rectOf = (element, origin) => {
65
+ const rect = element.getBoundingClientRect();
66
+ return {
67
+ x: Math.round(rect.x - origin.x),
68
+ y: Math.round(rect.y - origin.y),
69
+ width: Math.round(rect.width),
70
+ height: Math.round(rect.height)
71
+ };
72
+ };
73
+ const popBounds = (origin) => ({
74
+ x: 8,
75
+ y: 34,
76
+ width: origin.width - 16,
77
+ height: origin.height - 70
78
+ });
79
+ const MOVERS = ":is(.nested, .map), [data-name]";
80
+ const moverKey = (element) => element.dataset.name ?? "";
81
+ const ROOM = " room";
82
+ const rescale = (root, was, shift) => {
83
+ const now = root.getBoundingClientRect();
84
+ const from = `translate(${was.x + shift.x - now.x}px, ${was.y + shift.y - now.y}px) scale(${was.width / now.width}, ${was.height / now.height})`;
85
+ root.animate([{
86
+ transformOrigin: "0 0",
87
+ transform: from
88
+ }, {
89
+ transformOrigin: "0 0",
90
+ transform: "none"
91
+ }], {
92
+ id: RESCALE,
93
+ duration: SETTLE,
94
+ easing: EASE_OUT
95
+ });
96
+ };
97
+ const alike = (a, b) => Math.abs(Math.log(a.width * b.height / (a.height * b.width || 1))) < .1;
98
+ const holdInside = (box, rtl) => {
99
+ const head = box.querySelector(":scope > .head");
100
+ const width = `${head?.offsetWidth ?? 0}px`;
101
+ const timing = {
102
+ id: FLIP,
103
+ duration: SETTLE
104
+ };
105
+ const clipPath = rtl ? "inset(-4px -24px -4px -4px)" : "inset(-4px -4px -4px -24px)";
106
+ return () => {
107
+ head?.animate([{ minWidth: width }, { minWidth: width }], timing);
108
+ box.animate([{ clipPath }, { clipPath }], timing);
109
+ };
110
+ };
111
+ const sizeOf = (rect) => ({
112
+ width: `${rect.width}px`,
113
+ height: `${rect.height}px`
114
+ });
115
+ const ease = (element, was, now, { x, y, rtl }) => {
116
+ const grows = element.matches(".box") && (Math.abs(was.width - now.width) >= 1 || Math.abs(was.height - now.height) >= 1);
117
+ if (!grows && Math.abs(x) < 1 && Math.abs(y) < 1) return;
118
+ const hold = grows ? holdInside(element, rtl) : undefined;
119
+ const from = { transform: `translate(${x}px, ${y}px)` };
120
+ const to = { transform: "none" };
121
+ if (grows) {
122
+ Object.assign(from, sizeOf(was));
123
+ Object.assign(to, sizeOf(now));
124
+ }
125
+ element.animate([from, to], {
126
+ id: FLIP,
127
+ duration: SETTLE,
128
+ easing: EASE_OUT
129
+ });
130
+ hold?.();
131
+ };
132
+ const elide = (name) => {
133
+ if (name.length <= 28) return name;
134
+ return `…${name.split(".").slice(-2).join(".")}`;
135
+ };
136
+ export class DevtoolsPanel extends LitElement {
137
+ static {
138
+ this.styles = styles;
139
+ }
140
+ static {
141
+ this.properties = {
142
+ router: { attribute: false },
143
+ history: { type: Number },
144
+ timeResolves: {
145
+ type: Boolean,
146
+ attribute: "time-resolves"
147
+ },
148
+ redaction: { attribute: false },
149
+ viewLocator: { attribute: false },
150
+ _live: { state: true },
151
+ _imported: { state: true },
152
+ _tab: { state: true },
153
+ _view: { state: true },
154
+ _layoutPref: { state: true },
155
+ _mapViews: { state: true },
156
+ _pathFocus: { state: true },
157
+ _max: { state: true },
158
+ _mapSize: { state: true },
159
+ _mapOpen: { state: true },
160
+ _mapFailed: { state: true },
161
+ _mapPan: { state: true },
162
+ _mapZoom: { state: true },
163
+ _selectedTx: { state: true },
164
+ _previewTx: { state: true },
165
+ _selectedState: { state: true },
166
+ _inspect: { state: true },
167
+ _focusState: { state: true },
168
+ _collapsed: { state: true },
169
+ _announcement: { state: true },
170
+ _copied: { state: true },
171
+ _now: { state: true },
172
+ _keepValues: { state: true },
173
+ _keepMessages: { state: true },
174
+ _notice: { state: true },
175
+ _timelineFailed: { state: true },
176
+ _timelineFocus: { state: true },
177
+ _timelineSelected: { state: true },
178
+ _timelineCollapsed: { state: true },
179
+ _spanCount: { state: true },
180
+ _viewsFailed: { state: true },
181
+ _viewFocus: { state: true },
182
+ _viewSelected: { state: true }
183
+ };
184
+ }
185
+ #timelineLoading;
186
+ #viewsLoading;
187
+ #pathFrom;
188
+ #statesSeen;
189
+ #pathFocused;
190
+ #pointedView;
191
+ #markedView;
192
+ #adopted;
193
+ #spans;
194
+ #mapLoading;
195
+ #geometry;
196
+ #before;
197
+ #layout;
198
+ #direct;
199
+ #onWheel;
200
+ #step;
201
+ #resized;
202
+ #resize;
203
+ #observed;
204
+ #recorder;
205
+ #given;
206
+ #owned;
207
+ #givenChanged;
208
+ #attached;
209
+ #unsubscribe;
210
+ #ticker;
211
+ #newestTick;
212
+ #press;
213
+ constructor() {
214
+ super();
215
+ this._pressed = null;
216
+ this._mapWidths = new Map();
217
+ this._moveFocus = false;
218
+ this._importReader = () => import("../session-schema.js");
219
+ this._importMap = () => import("./map.js");
220
+ this._importTimeline = () => import("./timeline.js");
221
+ this.#timelineLoading = false;
222
+ this._importViews = () => import("./viewmap.js");
223
+ this.#viewsLoading = false;
224
+ this.#pathFrom = null;
225
+ this.#pathFocused = null;
226
+ this.#pointedView = null;
227
+ this.#markedView = null;
228
+ this.#adopted = new Set();
229
+ this.#spans = new Map();
230
+ this.#mapLoading = false;
231
+ this.#geometry = [];
232
+ this.#before = null;
233
+ this.#layout = null;
234
+ this.#direct = false;
235
+ this.#onWheel = {
236
+ handleEvent: (event) => this._map?.wheelPan(this, event),
237
+ passive: false
238
+ };
239
+ this.#resized = false;
240
+ this.#observed = null;
241
+ this.#owned = false;
242
+ this.#givenChanged = false;
243
+ this.history = 500;
244
+ this.timeResolves = false;
245
+ this.redaction = defaultRedaction();
246
+ this._live = emptyModel();
247
+ this._imported = null;
248
+ this._tab = "tree";
249
+ this._view = "outline";
250
+ this._layoutPref = storedLayout();
251
+ this._mapViews = storedViews();
252
+ this._pathFocus = null;
253
+ this._max = false;
254
+ this._mapSize = {
255
+ width: 0,
256
+ height: 0
257
+ };
258
+ this._mapFailed = false;
259
+ this._mapOpen = new Map();
260
+ this._mapPan = null;
261
+ this._mapZoom = null;
262
+ this._inspect = "none";
263
+ this.#resetSelection();
264
+ this._collapsed = new Set();
265
+ this._announcement = "";
266
+ this._copied = null;
267
+ this._now = performance.now();
268
+ this._notice = null;
269
+ this._timelineFailed = false;
270
+ this._timelineCollapsed = new Set();
271
+ this._spanCount = 0;
272
+ this._viewsFailed = false;
273
+ }
274
+ get recorder() {
275
+ return this.#recorder ?? this.#given;
276
+ }
277
+ set recorder(recorder) {
278
+ if (recorder === this.#given) return;
279
+ this.#given = recorder;
280
+ this.#givenChanged = true;
281
+ this.requestUpdate();
282
+ }
283
+ get spans() {
284
+ return [...this.#spans.values()];
285
+ }
286
+ set spans(spans) {
287
+ this.#spans = new Map();
288
+ for (const span of spans) upsertSpan(this.#spans, span);
289
+ this._spanCount += 1;
290
+ }
291
+ addSpan(span) {
292
+ upsertSpan(this.#spans, span);
293
+ this._spanCount += 1;
294
+ }
295
+ _spanList() {
296
+ return this._imported ? this._imported.session.spans ?? [] : this.spans;
297
+ }
298
+ get _timeOrigin() {
299
+ return this._imported?.session.timeOrigin ?? performance.timeOrigin;
300
+ }
301
+ _timelineInput() {
302
+ const model = this._model;
303
+ return {
304
+ txs: model.txs,
305
+ states: model.states,
306
+ clock: this._clock,
307
+ timeResolves: this._imported?.session.timeResolves ?? this.timeResolves,
308
+ spans: this._spanList(),
309
+ timeOrigin: this._timeOrigin
310
+ };
311
+ }
312
+ get _model() {
313
+ return this._imported?.model ?? this._live;
314
+ }
315
+ get _clock() {
316
+ return this._imported?.session.t ?? this._now;
317
+ }
318
+ connectedCallback() {
319
+ super.connectedCallback();
320
+ for (const sheet of this.shadowRoot?.adoptedStyleSheets ?? []) sheet.media.mediaText = String(sheet.media);
321
+ if (this.router && !this.#recorder) this.#attach(this.router);
322
+ if (this.hasUpdated) this.#pill?.showPopover();
323
+ }
324
+ disconnectedCallback() {
325
+ super.disconnectedCallback();
326
+ this.#mark(null);
327
+ this.#detach();
328
+ this.#resize?.disconnect();
329
+ this.#observed = null;
330
+ }
331
+ willUpdate(changed) {
332
+ if (changed.has("redaction")) {
333
+ this._keepValues = this.redaction.params === "all";
334
+ this._keepMessages = this.redaction.messages;
335
+ }
336
+ const given = this.#givenChanged;
337
+ this.#givenChanged = false;
338
+ if ((changed.has("router") || given) && this.#stale()) {
339
+ this.#detach();
340
+ this._live = emptyModel();
341
+ this.#resetSelection();
342
+ if (this.router && this.isConnected) this.#attach(this.router);
343
+ }
344
+ this.#followGoneStates();
345
+ this.#forgetGoneViews();
346
+ this.#dropStrandedView();
347
+ this.#loadViews(changed);
348
+ this.#followMap(changed);
349
+ this.#syncTicker();
350
+ }
351
+ #syncTicker() {
352
+ const running = Boolean(this.#recorder) && !this._imported && (this._live.txs.some((tx) => !tx.result) || this._view === "timeline" && this.spans.some((span) => span.endTime === undefined));
353
+ if (running && !this.#ticker) this.#ticker = setInterval(() => this._now = performance.now(), 100);
354
+ if (!running && this.#ticker) {
355
+ clearInterval(this.#ticker);
356
+ this.#ticker = undefined;
357
+ }
358
+ }
359
+ #loadViews(changed) {
360
+ const retry = changed.has("_view") || changed.has("_mapViews");
361
+ const due = (shown, loaded, loading, failed) => shown && !loaded && !loading && (!failed || retry);
362
+ if (due(this._view === "map", Boolean(this._map), this.#mapLoading, this._mapFailed)) this.#loadMap();
363
+ if (due(this._view === "timeline", Boolean(this._timeline), this.#timelineLoading, this._timelineFailed)) this.#loadTimeline();
364
+ const views = this._view === "views" || this._view === "map" && this._mapViews && this.#holdsViews();
365
+ if (due(views, Boolean(this._viewMap), this.#viewsLoading, this._viewsFailed)) this.#loadViewMap();
366
+ }
367
+ #loadViewMap() {
368
+ this.#viewsLoading = true;
369
+ this._viewsFailed = false;
370
+ if (this._announcement === VIEWS_FAILED) this._announcement = "";
371
+ void this._importViews().then((views) => {
372
+ this._viewMap = views;
373
+ this.#viewsLoading = false;
374
+ this.#adopt(views.viewMapStyles);
375
+ this.requestUpdate();
376
+ }, () => {
377
+ this._viewsFailed = true;
378
+ this.#viewsLoading = false;
379
+ this._announcement = VIEWS_FAILED;
380
+ });
381
+ }
382
+ #loadMap() {
383
+ this.#mapLoading = true;
384
+ this._mapFailed = false;
385
+ if (this._announcement === MAP_FAILED) this._announcement = "";
386
+ void this._importMap().then((map) => {
387
+ this._map = map;
388
+ this.#mapLoading = false;
389
+ this.requestUpdate();
390
+ }, () => {
391
+ this._mapFailed = true;
392
+ this.#mapLoading = false;
393
+ this._announcement = MAP_FAILED;
394
+ });
395
+ }
396
+ #loadTimeline() {
397
+ this.#timelineLoading = true;
398
+ this._timelineFailed = false;
399
+ if (this._announcement === TIMELINE_FAILED) this._announcement = "";
400
+ void this._importTimeline().then((timeline) => {
401
+ this._timeline = timeline;
402
+ this.#timelineLoading = false;
403
+ this.#adopt(timeline.timelineStyles);
404
+ this.requestUpdate();
405
+ }, () => {
406
+ this._timelineFailed = true;
407
+ this.#timelineLoading = false;
408
+ this._announcement = TIMELINE_FAILED;
409
+ });
410
+ }
411
+ #adopt(styles) {
412
+ this.#adopted.add(styles);
413
+ adoptStyles(this.renderRoot, [...DevtoolsPanel.elementStyles, ...this.#adopted]);
414
+ }
415
+ #followMap(changed) {
416
+ const nested = this._view === "map" ? this._nested() : null;
417
+ const last = this.#layout;
418
+ const pan = this._mapPan;
419
+ this.#layout = nested;
420
+ if (!nested || !this._map) return;
421
+ if (pan && last && last !== nested) this._mapPan = changed.has("_mapZoom") ? this._map.zoomView(pan, last.placed, nested.placed, this._room(nested)) : this.#anchored(pan, last, nested);
422
+ if (this._moveFocus && this._focusState) this._reveal(nested, this._focusState);
423
+ }
424
+ #anchored(pan, last, nested) {
425
+ const name = this._focusState ?? this._selectedState ?? "";
426
+ const was = last.rects.get(name);
427
+ const now = nested.rects.get(name);
428
+ return was && now ? {
429
+ x: pan.x + was.x - now.x,
430
+ y: pan.y + was.y - now.y
431
+ } : pan;
432
+ }
433
+ update(changed) {
434
+ const focused = this.shadowRoot?.activeElement;
435
+ if (focused?.matches(".box > .head")) this._moveFocus = true;
436
+ const dropped = !focused && document.activeElement === document.body && this.#pathFocused?.isConnected === false;
437
+ if (!dropped) this.#pathFocused = focused?.closest(".vp") ? focused : null;
438
+ this.#before = this.#mapMoved() ? this.#measureMovers() : null;
439
+ super.update(changed);
440
+ }
441
+ #mapMoved() {
442
+ const nested = this._view === "map" ? this._nested() : null;
443
+ const geometry = this.#drawnGeometry(nested);
444
+ const direct = this.#direct;
445
+ const moved = geometry.length !== this.#geometry.length || geometry.some((part, index) => part !== this.#geometry[index]);
446
+ const drawn = this.#geometry.length > 0;
447
+ this.#direct = false;
448
+ this.#geometry = geometry;
449
+ this.#resized = Boolean(this.#step && nested && this.#step !== nested.metrics);
450
+ this.#step = nested?.metrics;
451
+ return moved && drawn && !direct && geometry.length > 0 && !matchMedia("(prefers-reduced-motion: reduce)").matches;
452
+ }
453
+ #drawnGeometry(nested) {
454
+ if (this._view !== "map") return [];
455
+ const view = nested && this._viewOf(nested);
456
+ return [
457
+ nested?.placed ?? this._layoutPref,
458
+ this._max,
459
+ view?.x,
460
+ view?.y
461
+ ];
462
+ }
463
+ get #movers() {
464
+ return [...this.renderRoot.querySelector(".map-scroll")?.querySelectorAll(MOVERS) ?? []];
465
+ }
466
+ #measureMovers() {
467
+ const room = this.renderRoot.querySelector(".map-scroll");
468
+ return new Map([...this.#movers.map((element) => [moverKey(element), element.getBoundingClientRect()]), ...room ? [[ROOM, room.getBoundingClientRect()]] : []]);
469
+ }
470
+ #roomShift(before) {
471
+ const was = before.get(ROOM);
472
+ const now = this.renderRoot.querySelector(".map-scroll")?.getBoundingClientRect();
473
+ return was && now ? {
474
+ x: now.x + now.width / 2 - was.x - was.width / 2,
475
+ y: now.y + now.height / 2 - was.y - was.height / 2
476
+ } : {
477
+ x: 0,
478
+ y: 0
479
+ };
480
+ }
481
+ #rescaled(root, outline, shift) {
482
+ const rescaling = this.#resized || root?.getAnimations().some((animation) => animation.id === RESCALE);
483
+ for (const element of this.renderRoot.querySelectorAll(".map-scroll *")) for (const animation of element.getAnimations()) if (animation.id === FLIP || animation.id === RESCALE) animation.cancel();
484
+ if (!rescaling || !root?.matches(".nested") || !outline?.width) return false;
485
+ if (!alike(outline, root.getBoundingClientRect())) return false;
486
+ rescale(root, outline, shift);
487
+ return true;
488
+ }
489
+ #flip(before) {
490
+ const movers = this.#movers;
491
+ const room = this.#roomShift(before);
492
+ if (this.#rescaled(movers[0], before.get(""), room)) return;
493
+ const rtl = getComputedStyle(this).direction === "rtl";
494
+ const edge = (rect) => rtl ? rect.right : rect.x;
495
+ const shifts = new Map();
496
+ const plans = movers.map((element) => {
497
+ const read = before.get(moverKey(element));
498
+ const now = element.getBoundingClientRect();
499
+ const was = read && new DOMRect(read.x + room.x, read.y + room.y, read.width, read.height);
500
+ const carried = shifts.get(element.parentElement?.closest(MOVERS) ?? element) ?? {
501
+ x: 0,
502
+ y: 0
503
+ };
504
+ const shift = was ? {
505
+ x: edge(was) - edge(now),
506
+ y: was.y - now.y
507
+ } : carried;
508
+ shifts.set(element, shift);
509
+ return {
510
+ element,
511
+ was: was ?? now,
512
+ now,
513
+ by: {
514
+ x: shift.x - carried.x,
515
+ y: shift.y - carried.y,
516
+ rtl
517
+ }
518
+ };
519
+ });
520
+ for (const { element, was, now, by } of plans) ease(element, was, now, by);
521
+ }
522
+ firstUpdated() {
523
+ if (this.isConnected) this.#pill?.showPopover();
524
+ }
525
+ updated() {
526
+ this.#observeMap();
527
+ this.#markPointed();
528
+ if (this._view === "views") this._viewMap?.measureViewMap(this);
529
+ this.#measureMap();
530
+ this.#placePopover();
531
+ this.#showTick();
532
+ if (this.#before) this.#flip(this.#before);
533
+ this.#before = null;
534
+ this.#keepPathFocus();
535
+ if (!this._moveFocus) return;
536
+ this._moveFocus = false;
537
+ this.renderRoot.querySelector("[role=\"treeitem\"][tabindex=\"0\"]")?.focus();
538
+ }
539
+ #keepPathFocus() {
540
+ if (!this.#pathFocused) return;
541
+ if (!this._pathShown()) {
542
+ this.#pathFocused = null;
543
+ return;
544
+ }
545
+ const stop = this.renderRoot.querySelector(".vp [tabindex=\"0\"]");
546
+ if (!stop) return;
547
+ this.#pathFocused = stop;
548
+ if (this.shadowRoot?.activeElement !== stop) stop.focus();
549
+ }
550
+ #observeMap() {
551
+ const scroller = this.renderRoot.querySelector(".map-scroll, .vm-main");
552
+ if (scroller === this.#observed) return;
553
+ this.#resize ??= new ResizeObserver(([entry]) => {
554
+ const width = Math.floor(entry.contentRect.width);
555
+ const height = Math.floor(entry.contentRect.height);
556
+ if (width !== this._mapSize.width || height !== this._mapSize.height) this._mapSize = {
557
+ width,
558
+ height
559
+ };
560
+ });
561
+ this.#resize.disconnect();
562
+ this.#observed = scroller;
563
+ if (scroller) this.#resize.observe(scroller);
564
+ }
565
+ #placePopover() {
566
+ const panel = this.#panel;
567
+ const popover = this.renderRoot.querySelector(".inspector-pane");
568
+ if (!panel || !popover || this._view !== "map" || this._max) return;
569
+ const origin = panel.getBoundingClientRect();
570
+ const place = this._inspect === "view" ? this.#viewPlace(popover.getBoundingClientRect(), origin) : this.#anchoredPlace(popover, origin);
571
+ if (!place) return;
572
+ panel.style.setProperty("--uird-pop-x", `${place.x}px`);
573
+ panel.style.setProperty("--uird-pop-y", `${place.y}px`);
574
+ }
575
+ #anchoredPlace(popover, origin) {
576
+ const root = this.renderRoot.querySelector(".nested");
577
+ const nested = root && this._nested();
578
+ const marked = [...this.renderRoot.querySelectorAll(".map-node.anchor, .brand.anchor")].at(-1);
579
+ const drawn = root?.getBoundingClientRect();
580
+ const at = drawn ? {
581
+ x: drawn.x - origin.x,
582
+ y: drawn.y - origin.y
583
+ } : {
584
+ x: 0,
585
+ y: 0
586
+ };
587
+ const inPanel = (rect) => ({
588
+ ...rect,
589
+ x: rect.x + at.x,
590
+ y: rect.y + at.y
591
+ });
592
+ const box = nested && this._map?.anchorRect(this, nested);
593
+ const anchor = box ? inPanel(box) : marked && rectOf(marked, origin);
594
+ if (!anchor) return undefined;
595
+ return this.#popoverPlace(anchor, popover.getBoundingClientRect(), origin, nested && box ? {
596
+ nested,
597
+ at
598
+ } : undefined);
599
+ }
600
+ #viewPlace(size, origin) {
601
+ const item = this.renderRoot.querySelector(".vp-chip[aria-pressed=\"true\"]");
602
+ if (!item) return undefined;
603
+ const anchor = rectOf(item, origin);
604
+ return placeBeside(anchor, size, popBounds(origin), [{
605
+ ...anchor,
606
+ weight: 1e3
607
+ }, ...this.#chips(origin)]);
608
+ }
609
+ #chips(origin) {
610
+ return [...this.renderRoot.querySelectorAll(".vp-chip")].map((chip) => ({
611
+ ...rectOf(chip, origin),
612
+ weight: 1
613
+ }));
614
+ }
615
+ #besidePlace(size, origin) {
616
+ const rtl = getComputedStyle(this).direction === "rtl";
617
+ return {
618
+ x: rtl ? MARGIN : origin.width - MARGIN - size.width,
619
+ y: 38
620
+ };
621
+ }
622
+ #popoverPlace(anchor, size, origin, map) {
623
+ const bounds = popBounds(origin);
624
+ if (!map) return placeBeside(anchor, size, bounds);
625
+ if (this._beside(map.nested)) return this.#besidePlace(size, origin);
626
+ const clear = this._map?.keepClear(this, map.nested) ?? [];
627
+ return placeBeside(anchor, size, bounds, [
628
+ {
629
+ ...anchor,
630
+ weight: 1e3
631
+ },
632
+ ...clear.map((rect) => ({
633
+ ...rect,
634
+ x: rect.x + map.at.x,
635
+ y: rect.y + map.at.y
636
+ })),
637
+ ...this.#chips(origin)
638
+ ]);
639
+ }
640
+ #showTick() {
641
+ const ticks = this.renderRoot.querySelector(".ticks");
642
+ const tick = ticks?.querySelector(".tick.on");
643
+ if (!ticks) return;
644
+ if (!tick) {
645
+ const id = this._model.txs.at(-1)?.id;
646
+ const seen = this.#newestTick;
647
+ if (!ticks.clientWidth || seen?.ticks === ticks && seen.id === id) return;
648
+ this.#newestTick = {
649
+ ticks,
650
+ id
651
+ };
652
+ ticks.scrollLeft = ticks.scrollWidth * (ticks.matches(":dir(rtl)") ? -1 : 1);
653
+ return;
654
+ }
655
+ const box = ticks.getBoundingClientRect();
656
+ const rect = tick.getBoundingClientRect();
657
+ if (rect.left < box.left) ticks.scrollLeft -= box.left - rect.left;
658
+ else if (rect.right > box.right) ticks.scrollLeft += rect.right - box.right;
659
+ }
660
+ #measureMap() {
661
+ let changed = false;
662
+ for (const node of this.renderRoot.querySelectorAll(".map-node")) {
663
+ const name = node.dataset.name;
664
+ const width = Math.ceil(node.getBoundingClientRect().width);
665
+ if (width && this._mapWidths.get(name) !== width) {
666
+ this._mapWidths.set(name, width);
667
+ changed = true;
668
+ }
669
+ }
670
+ if (changed) this.requestUpdate();
671
+ }
672
+ get #pill() {
673
+ return this.renderRoot.querySelector(".pill");
674
+ }
675
+ get #panel() {
676
+ return this.renderRoot.querySelector(".panel");
677
+ }
678
+ #followGoneStates() {
679
+ const { states } = this._model;
680
+ if (states === this.#statesSeen) return;
681
+ this.#statesSeen = states;
682
+ const names = new Set(states.map((state) => state.name));
683
+ const follow = (name) => {
684
+ if (name === null || names.has(name)) return name;
685
+ const loaded = bareName(name);
686
+ return names.has(loaded) ? loaded : null;
687
+ };
688
+ this._focusState = follow(this._focusState);
689
+ this.#pathFrom = follow(this.#pathFrom);
690
+ const selected = follow(this._selectedState);
691
+ if (selected === this._selectedState) return;
692
+ this._selectedState = selected;
693
+ if (selected === null && this._inspect === "state") this._inspect = "none";
694
+ }
695
+ #resetSelection() {
696
+ this._selectedTx = null;
697
+ this._previewTx = null;
698
+ this._selectedState = null;
699
+ this._focusState = null;
700
+ this._timelineFocus = null;
701
+ this._timelineSelected = null;
702
+ this._viewFocus = null;
703
+ this._viewSelected = null;
704
+ if (this._inspect !== "router") this._inspect = "none";
705
+ }
706
+ #stale() {
707
+ return this.#attached !== this.router || this.#attached !== undefined && (this.#given ? this.#recorder !== this.#given : !this.#owned);
708
+ }
709
+ #attach(router) {
710
+ this.#attached = router;
711
+ const recorder = this.#given ?? record(router, {
712
+ limit: this.history * 40,
713
+ timeResolves: this.timeResolves
714
+ });
715
+ this.#recorder = recorder;
716
+ this.#owned = recorder !== this.#given;
717
+ this._live = this.#kept(fold(recorder.session({ params: "all" }).events));
718
+ this.#unsubscribe = recorder.subscribe((event) => {
719
+ this._live = this.#kept(apply(this._live, event));
720
+ if (event.type === "result" || event.type === "invalid") this.#announce(event.type === "result" ? event.id : -event.seq);
721
+ });
722
+ }
723
+ #kept(model) {
724
+ return model.txs.length > this.history ? {
725
+ ...model,
726
+ txs: model.txs.slice(-this.history)
727
+ } : model;
728
+ }
729
+ #detach() {
730
+ this.#unsubscribe?.();
731
+ if (this.#owned) this.#recorder?.stop();
732
+ this.#recorder = undefined;
733
+ this.#owned = false;
734
+ this.#attached = undefined;
735
+ this.#unsubscribe = undefined;
736
+ clearInterval(this.#ticker);
737
+ this.#ticker = undefined;
738
+ }
739
+ _tx(id) {
740
+ return id == null ? undefined : this._model.txs.find((tx) => tx.id === id);
741
+ }
742
+ _origin(tx) {
743
+ return originOf(this._model.txs, tx);
744
+ }
745
+ _duration(tx) {
746
+ return durationOf(this._model.txs, tx, this._clock);
747
+ }
748
+ #announce(id) {
749
+ if (this._imported) return;
750
+ const tx = this._live.txs.find((t) => t.id === id);
751
+ const outcome = tx?.result?.outcome;
752
+ if (!tx || !outcome || ![
753
+ "success",
754
+ "error",
755
+ "invalid"
756
+ ].includes(outcome)) return;
757
+ this._announcement = outcome === "success" ? `Transition ${tx.id} succeeded: ${tx.to}, ${ms(this._duration(tx))}` : `${tx.id < 0 ? "Target" : `Transition ${tx.id}`} failed: ${tx.to}. ${resultLine(tx)}`;
758
+ }
759
+ #open() {
760
+ this.#pill?.hidePopover();
761
+ this.#panel?.showPopover();
762
+ this.#markPointed();
763
+ void this.updateComplete.then(() => this.renderRoot.querySelector(".close")?.focus());
764
+ }
765
+ #close() {
766
+ this.#panel?.hidePopover();
767
+ this.#markPointed();
768
+ this.#pill?.showPopover();
769
+ this.#pill?.focus();
770
+ }
771
+ #dropView() {
772
+ if (this._inspect === "view") this._viewSelected = null;
773
+ }
774
+ _selectTx(id) {
775
+ this.#dropView();
776
+ this._selectedTx = id;
777
+ this._inspect = id === null ? "none" : "tx";
778
+ }
779
+ _selectState(name, keep = false) {
780
+ this.#dropView();
781
+ this._selectedState = keep || this._selectedState !== name ? name : null;
782
+ this._focusState = name;
783
+ this._inspect = this._selectedState ? "state" : "none";
784
+ }
785
+ _canGo(state) {
786
+ return !this._imported && !state.abstract && (state.future || state.params.every((p) => p.optional)) && !!this.router;
787
+ }
788
+ _go(state) {
789
+ if (this._canGo(state)) void this.router?.stateService.go(bareName(state.name)).catch(() => {});
790
+ }
791
+ _keepText(event) {
792
+ if (event.detail > 1) event.preventDefault();
793
+ }
794
+ _goState(name) {
795
+ const state = this._model.states.find((s) => s.name === name);
796
+ this._selectState(name, true);
797
+ if (state) this._go(state);
798
+ }
799
+ _revealState(name) {
800
+ const hidden = new Set(ancestorsOf(this._model.states, name));
801
+ this.#dropView();
802
+ this._selectedState = name;
803
+ this._focusState = name;
804
+ this._inspect = "state";
805
+ this._collapsed = new Set([...this._collapsed].filter((state) => !hidden.has(state)));
806
+ this._mapOpen = new Map([...this._mapOpen].filter(([state]) => !hidden.has(state)));
807
+ this._moveFocus = true;
808
+ }
809
+ _selectView(id) {
810
+ const map = this._view === "map";
811
+ const again = id === this._viewSelected && (!map || this._inspect === "view");
812
+ this._viewSelected = again ? null : id;
813
+ if (id !== null) this._viewFocus = id;
814
+ if (!map) return;
815
+ if (this._inspect !== "view") this.#pathFrom = this._pathState();
816
+ this._selectedState = null;
817
+ this._selectedTx = null;
818
+ this._inspect = this._viewSelected === null ? "none" : "view";
819
+ }
820
+ _pointView(id) {
821
+ this.#pointedView = id;
822
+ this.#markPointed();
823
+ }
824
+ _showState(name) {
825
+ if (this._view !== "map") this._view = "outline";
826
+ this._revealState(name);
827
+ }
828
+ #markPointed() {
829
+ const tab = this._view === "views";
830
+ const beside = this._view === "map" && this._pathShown();
831
+ const shown = (tab || beside) && !this._imported && Boolean(this.#panel?.matches(":popover-open"));
832
+ const chosen = tab || this._inspect === "view" ? this._viewSelected : null;
833
+ const id = shown ? this.#pointedView ?? chosen : null;
834
+ const view = this.#viewOf(id);
835
+ if (view !== this.#markedView) this.#mark(view);
836
+ }
837
+ #viewOf(id) {
838
+ return this._model.views?.views.find((view) => view.id === id) ?? null;
839
+ }
840
+ #mark(view) {
841
+ this.#markedView = view;
842
+ this.viewLocator?.highlight(view);
843
+ }
844
+ #forgetGoneViews() {
845
+ if (this.#viewOf(this._viewSelected) === null) {
846
+ this._viewSelected = null;
847
+ if (this._inspect === "view") this._inspect = "none";
848
+ }
849
+ if (this.#viewOf(this.#pointedView) === null) this.#pointedView = null;
850
+ }
851
+ #dropStrandedView() {
852
+ if (this._inspect !== "view") return;
853
+ if (this._view === "map" && this._pathShown()) return;
854
+ if (this._view !== "views") this._viewSelected = null;
855
+ this._inspect = "none";
856
+ }
857
+ _linkedStates() {
858
+ const view = this._inspect === "view" && this.#viewOf(this._viewSelected);
859
+ if (!view) return new Map();
860
+ const ties = [[view.context, "created the selected view"], [view.fill?.state ?? "", "fills the selected view"]];
861
+ return new Map(ties.filter(([name]) => name));
862
+ }
863
+ _clearSelection() {
864
+ this.#dropView();
865
+ this._selectedState = null;
866
+ this._selectedTx = null;
867
+ this._inspect = "none";
868
+ }
869
+ _dismiss() {
870
+ const from = this.#selectionSources();
871
+ const held = this.shadowRoot?.activeElement?.closest(".inspector-pane, .router-pane");
872
+ this._clearSelection();
873
+ if (!held) return;
874
+ void this.updateComplete.then(() => from.find((element) => element?.isConnected && element.checkVisibility())?.focus());
875
+ }
876
+ #selectionSources() {
877
+ const find = (selector) => this.renderRoot.querySelector(selector);
878
+ const tx = this._inspect === "tx";
879
+ return [
880
+ this._inspect === "router" ? find(".brand") : null,
881
+ tx ? find(".ticks") : null,
882
+ tx ? find(".log .tx.selected > .line") : null,
883
+ this._inspect === "state" ? find(".map-node.selected") : null,
884
+ this._inspect === "view" ? find(".vp-chip[aria-pressed=\"true\"]") : null,
885
+ find("[role=\"treeitem\"][tabindex=\"0\"]"),
886
+ find(".map-node"),
887
+ find(".tabs [aria-selected=\"true\"]")
888
+ ];
889
+ }
890
+ #onKey(event) {
891
+ const target = event.target;
892
+ if (event.key !== "Escape" || event.defaultPrevented || this._inspect === "none" || target.closest("input, textarea, select, [contenteditable]")) return;
893
+ event.preventDefault();
894
+ this._dismiss();
895
+ }
896
+ #onMapClick(event) {
897
+ const press = this.#press;
898
+ const target = event.target;
899
+ this.#press = undefined;
900
+ if (this._inspect === "none" || !target.matches(".map-scroll, .nested, .map") || press && Math.hypot(event.clientX - press.x, event.clientY - press.y) >= DRAG) return;
901
+ this._dismiss();
902
+ }
903
+ get _anchorState() {
904
+ if (this._inspect === "state") return this._selectedState;
905
+ return this._inspect === "tx" ? this._tx(this._selectedTx)?.to ?? null : null;
906
+ }
907
+ _beside(nested) {
908
+ return !this._max && this._mapSize.width - nested.placed.width >= ASIDE;
909
+ }
910
+ _reserve(nested) {
911
+ if (!this._beside(nested)) return 0;
912
+ const spare = this._mapSize.width - nested.placed.width;
913
+ return Math.max(0, Math.min(ASIDE, ASIDE * 2 - spare));
914
+ }
915
+ _room(nested) {
916
+ return {
917
+ ...this._mapSize,
918
+ reserve: this._reserve(nested),
919
+ slack: this._max || this._beside(nested) ? 0 : ASIDE,
920
+ foot: this._map?.MINI_FOOT ?? 0,
921
+ rtl: nested.rtl
922
+ };
923
+ }
924
+ _viewOf(nested) {
925
+ const map = this._map;
926
+ const room = this._room(nested);
927
+ const size = nested.placed;
928
+ if (!map) return {
929
+ x: 0,
930
+ y: 0
931
+ };
932
+ if (this._mapPan) return map.clampView(this._mapPan, size, room);
933
+ const current = nested.rects.get(this._model.current.name);
934
+ return current && map.overflows(size, room) ? map.centreView(current, size, room) : map.fitView(size, room);
935
+ }
936
+ _pans(nested) {
937
+ return Boolean(this._map?.overflows(nested.placed, this._mapSize));
938
+ }
939
+ _panTo(nested, view, eased) {
940
+ const now = this._viewOf(nested);
941
+ const next = this._map?.clampView(view, nested.placed, this._room(nested)) ?? now;
942
+ if (next.x === now.x && next.y === now.y) return false;
943
+ this.#direct = !eased;
944
+ this._mapPan = next;
945
+ return true;
946
+ }
947
+ _reveal(nested, name) {
948
+ const rect = nested.rects.get(name);
949
+ if (!rect || !this._map) return;
950
+ const view = this._map.revealView(this._viewOf(nested), rect, nested.placed, this._room(nested));
951
+ this._panTo(nested, view, true);
952
+ }
953
+ _zoomBy(nested, steps) {
954
+ const last = (this._map?.ZOOMS.length ?? 1) - 1;
955
+ const step = Math.min(last, Math.max(0, nested.step + steps));
956
+ if (step !== nested.step) this._mapZoom = step;
957
+ }
958
+ _fit() {
959
+ this._mapPan = null;
960
+ this._mapZoom = null;
961
+ }
962
+ _depthClass(name) {
963
+ return depthClass(ancestorsOf(this._model.states, name).length + 1);
964
+ }
965
+ get #mode() {
966
+ if (this._focusTx) return "tx";
967
+ return this._inspect === "state" ? "state" : "rest";
968
+ }
969
+ _nested() {
970
+ if (!this._map || this._view !== "map" || this._layoutPref !== "nested" || this._mapSize.width < NESTED_MIN_WIDTH) return null;
971
+ return this._map.layoutNested(this);
972
+ }
973
+ _pathShown() {
974
+ return this._view === "map" && this._mapViews && Boolean(this._viewMap) && this.#holdsViews();
975
+ }
976
+ _pathState() {
977
+ if (this._inspect === "state" && this._selectedState !== null) return this._selectedState;
978
+ if (this._inspect === "view" && this.#pathFrom !== null) return this.#pathFrom;
979
+ return this._model.current.name;
980
+ }
981
+ #chooseLayout(layout) {
982
+ this._layoutPref = layout;
983
+ storeLayout(layout);
984
+ }
985
+ #chooseViews(shown) {
986
+ this._mapViews = shown;
987
+ storeViews(shown);
988
+ }
989
+ session(redaction) {
990
+ const session = this._imported?.session ?? this.#liveSession();
991
+ return session && redactSession(session, redactionOf({
992
+ ...this.redaction,
993
+ ...redaction
994
+ }));
995
+ }
996
+ #liveSession() {
997
+ const session = this.#recorder?.session({ params: "all" });
998
+ if (!session || !this.#spans.size) return session;
999
+ const spans = spansDuring(this.spans, fold(session.events).txs, session.timeOrigin, session.t);
1000
+ return spans.length ? {
1001
+ ...session,
1002
+ spans
1003
+ } : session;
1004
+ }
1005
+ importSession(session) {
1006
+ if (session.v !== SCHEMA_VERSION) throw new Error(`Unsupported session version ${String(session.v)}; expected ${String(SCHEMA_VERSION)}`);
1007
+ this._imported = {
1008
+ session,
1009
+ model: fold(session.events)
1010
+ };
1011
+ this.#resetSelection();
1012
+ this._announcement = `Imported session ${session.routerId}, ${this._imported.model.txs.length} transitions. Live updates paused.`;
1013
+ }
1014
+ _sessionFacts() {
1015
+ const imported = this._imported?.session;
1016
+ if (imported) return {
1017
+ routerId: imported.routerId,
1018
+ events: imported.events.filter((event) => !SNAPSHOTS.has(event.type)).length,
1019
+ dropped: imported.dropped
1020
+ };
1021
+ const recorder = this.#recorder;
1022
+ return {
1023
+ routerId: recorder?.routerId ?? "",
1024
+ events: recorder?.events.length ?? 0,
1025
+ dropped: recorder?.dropped ?? 0
1026
+ };
1027
+ }
1028
+ #goLive() {
1029
+ this._imported = null;
1030
+ this._notice = null;
1031
+ this.#resetSelection();
1032
+ this._announcement = "Showing the live router.";
1033
+ }
1034
+ _exportSession() {
1035
+ const configured = this.redaction.params;
1036
+ return this.session({
1037
+ params: this._keepValues ? "all" : configured === "all" ? [] : configured,
1038
+ messages: this._keepMessages
1039
+ });
1040
+ }
1041
+ #export() {
1042
+ const session = this._exportSession();
1043
+ if (!session) return;
1044
+ const blob = new Blob([JSON.stringify(session, null, 1)], { type: "application/json" });
1045
+ const link = document.createElement("a");
1046
+ link.href = URL.createObjectURL(blob);
1047
+ link.download = `ui-router-session-${session.routerId}-${new Date().toISOString().replace(/[:.]/g, "-")}.json`;
1048
+ link.click();
1049
+ setTimeout(() => URL.revokeObjectURL(link.href));
1050
+ }
1051
+ #fail(text) {
1052
+ this._notice = {
1053
+ text,
1054
+ fault: true
1055
+ };
1056
+ this._announcement = text;
1057
+ }
1058
+ async #readFile(file) {
1059
+ if (!file) return;
1060
+ this._notice = null;
1061
+ let json;
1062
+ try {
1063
+ json = JSON.parse(await file.text());
1064
+ } catch {
1065
+ this.#fail(`Import failed: ${file.name} is not JSON.`);
1066
+ return;
1067
+ }
1068
+ let reader;
1069
+ try {
1070
+ reader = await this._importReader();
1071
+ } catch {
1072
+ this.#fail("Import failed: the session reader did not load. Try again.");
1073
+ return;
1074
+ }
1075
+ const read = reader.readSession(json);
1076
+ if (!read.ok) {
1077
+ this.#fail(`Import failed: ${read.error}`);
1078
+ return;
1079
+ }
1080
+ this.importSession(read.session);
1081
+ const skipped = [...read.skipped ? [`${read.skipped} ${read.skipped === 1 ? "event" : "events"} of a kind this version does not read`] : [], ...read.skippedSpans ? [`${read.skippedSpans} ${read.skippedSpans === 1 ? "span" : "spans"} that did not read`] : []];
1082
+ if (skipped.length) this._notice = {
1083
+ text: `${skipped.join(" and ")} skipped`,
1084
+ fault: false
1085
+ };
1086
+ }
1087
+ #onDrop(event) {
1088
+ event.preventDefault();
1089
+ void this.#readFile(event.dataTransfer?.files[0]);
1090
+ }
1091
+ get _runningTx() {
1092
+ return this._model.txs.findLast((tx) => !tx.result);
1093
+ }
1094
+ get _focusTx() {
1095
+ return this._tx(this._previewTx) ?? this._tx(this._selectedTx) ?? this._runningTx;
1096
+ }
1097
+ #erroredState(tx) {
1098
+ if (tx.result?.outcome !== "error") return null;
1099
+ return tx.resolves.find((r) => !r.ok)?.state ?? tx.to;
1100
+ }
1101
+ _role(state) {
1102
+ const tx = this._focusTx;
1103
+ if (tx) {
1104
+ if (this.#erroredState(tx) === state.name) return "errored";
1105
+ if (tx.entering.includes(state.name)) return "entering";
1106
+ if (tx.exiting.includes(state.name)) return "exiting";
1107
+ if (tx.retained.includes(state.name)) return "retained";
1108
+ }
1109
+ const { states, current } = this._model;
1110
+ if (state.name === current.name) return "current";
1111
+ if (ancestorsOf(states, current.name).includes(state.name)) return "ancestor";
1112
+ return state.future ? "future" : "inactive";
1113
+ }
1114
+ _children() {
1115
+ const known = new Set(this._model.states.map((s) => s.name));
1116
+ const children = new Map();
1117
+ for (const state of this._model.states) {
1118
+ const parent = state.parent && known.has(state.parent) ? state.parent : null;
1119
+ children.set(parent, [...children.get(parent) ?? [], state]);
1120
+ }
1121
+ return children;
1122
+ }
1123
+ _rows() {
1124
+ const children = this._children();
1125
+ const rows = [];
1126
+ const walk = (parent, depth) => {
1127
+ const kids = children.get(parent) ?? [];
1128
+ kids.forEach((state, index) => {
1129
+ const hasChildren = (children.get(state.name) ?? []).length > 0;
1130
+ rows.push({
1131
+ state,
1132
+ depth,
1133
+ hasChildren,
1134
+ setsize: kids.length,
1135
+ posinset: index + 1
1136
+ });
1137
+ if (hasChildren && !this._collapsed.has(state.name)) walk(state.name, depth + 1);
1138
+ });
1139
+ };
1140
+ walk(null, 1);
1141
+ return rows;
1142
+ }
1143
+ _paramBase(tx) {
1144
+ const first = (this._origin(tx) ?? tx).id;
1145
+ return this._model.txs.findLast((t) => t.id >= 0 && t.id < first && t.result?.outcome === "success")?.toParams ?? tx.fromParams;
1146
+ }
1147
+ render() {
1148
+ const inspected = this._inspect === "tx" ? this._tx(this._selectedTx) : undefined;
1149
+ const imported = Boolean(this._imported);
1150
+ return html`
1151
+ ${this.#renderPill()}
1152
+ <div
1153
+ class="panel"
1154
+ popover="manual"
1155
+ role="region"
1156
+ aria-label="Router devtools"
1157
+ data-tab=${this._tab}
1158
+ data-view=${this._view}
1159
+ data-inspect=${this._inspect}
1160
+ data-mode=${this.#mode}
1161
+ ?data-max=${this._max}
1162
+ ?data-imported=${imported}
1163
+ @dragover=${(e) => e.preventDefault()}
1164
+ @drop=${this.#onDrop}
1165
+ @keydown=${this.#onKey}
1166
+ >
1167
+ ${this.#renderTitle()}
1168
+ <div class="body">
1169
+ <section
1170
+ class="pane tree-pane"
1171
+ id="pane-tree"
1172
+ role="tabpanel"
1173
+ aria-labelledby="h-states"
1174
+ >
1175
+ ${this.#sectionHead("1", HEADINGS[this._view], "h-states")}
1176
+ <div class="pane-switch">${this.#renderSwitch()}</div>
1177
+ ${this.#renderStates()}
1178
+ </section>
1179
+ ${this._view === "outline" ? nothing : renderScrubber(this)}
1180
+ <section
1181
+ class="pane log-pane"
1182
+ id="pane-log"
1183
+ role="tabpanel"
1184
+ aria-labelledby="h-log"
1185
+ >
1186
+ ${this.#sectionHead("2", "Transitions", "h-log")}
1187
+ <div class="scroll">${renderLog(this)}</div>
1188
+ </section>
1189
+ <section class="pane inspector-pane" aria-labelledby="h-insp">
1190
+ ${this.#sectionHead("3", "Inspector", "h-insp", inspected ? seq(inspected.id) || "Invalid target" : this.#inspectorAside())}${this._inspect === "none" ? nothing : html`<button
1191
+ class="icon dismiss"
1192
+ aria-label="Close inspector"
1193
+ title="Close (Esc)"
1194
+ @click=${() => this._dismiss()}
1195
+ >
1196
+ ${closeGlyph}
1197
+ </button>`}
1198
+ <div
1199
+ class="scroll"
1200
+ tabindex="0"
1201
+ role="group"
1202
+ aria-labelledby="h-insp"
1203
+ >
1204
+ ${this.#renderInspector(inspected)}
1205
+ </div>
1206
+ </section>
1207
+ <section
1208
+ class="pane router-pane"
1209
+ id="pane-router"
1210
+ role="tabpanel"
1211
+ aria-labelledby="h-router"
1212
+ >
1213
+ ${this.#sectionHead("3", "Router", "h-router")}
1214
+ <div
1215
+ class="scroll"
1216
+ tabindex="0"
1217
+ role="group"
1218
+ aria-labelledby="h-router"
1219
+ >
1220
+ ${renderRouterCard(this, true)}
1221
+ </div>
1222
+ </section>
1223
+ </div>
1224
+ </div>
1225
+ <input
1226
+ class="file visually-hidden"
1227
+ type="file"
1228
+ accept=".json,application/json"
1229
+ tabindex="-1"
1230
+ aria-hidden="true"
1231
+ @change=${(e) => {
1232
+ const input = e.currentTarget;
1233
+ void this.#readFile(input.files?.[0]).then(() => input.value = "");
1234
+ }}
1235
+ />
1236
+ <div class="visually-hidden" role="status" aria-live="polite">
1237
+ ${this._announcement}
1238
+ </div>
1239
+ `;
1240
+ }
1241
+ #renderStates() {
1242
+ if (this._view === "outline") return html`<div class="scroll outline-scroll">
1243
+ ${renderOutline(this)}
1244
+ </div>`;
1245
+ if (this._view === "timeline") return html`<div class="scroll timeline-scroll">
1246
+ ${this._timeline ? this._timeline.renderTimeline(this) : this._timelineFailed ? html`<p class="empty">${TIMELINE_FAILED}</p>` : nothing}
1247
+ </div>`;
1248
+ if (this._view === "views") return html`<div class="scroll views-scroll">
1249
+ ${this._viewMap ? this._viewMap.renderViewMap(this) : this._viewsFailed ? html`<p class="empty">${VIEWS_FAILED}</p>` : nothing}
1250
+ </div>`;
1251
+ const nested = this._nested();
1252
+ const map = this._map;
1253
+ return html`<div
1254
+ class="scroll map-scroll"
1255
+ ?data-pan=${nested && this._pans(nested)}
1256
+ @pointerdown=${(event) => {
1257
+ this.#press = {
1258
+ x: event.clientX,
1259
+ y: event.clientY
1260
+ };
1261
+ map?.startPan(this, event);
1262
+ }}
1263
+ @click=${this.#onMapClick}
1264
+ @wheel=${this.#onWheel}
1265
+ >
1266
+ ${map ? nested ? map.renderNested(this, nested) : map.renderMap(this) : this.#mapNotice()}
1267
+ </div>
1268
+ ${this._pathShown() ? this._viewMap.renderPath(this) : nothing}`;
1269
+ }
1270
+ #mapNotice() {
1271
+ return this._mapFailed ? html`<p class="empty">${MAP_FAILED}</p>` : nothing;
1272
+ }
1273
+ #renderSwitch() {
1274
+ const map = this._view === "map";
1275
+ const layout = this._nested();
1276
+ const nested = Boolean(layout);
1277
+ const narrow = this._mapSize.width < NESTED_MIN_WIDTH;
1278
+ const why = `Nested boxes need ${NESTED_MIN_WIDTH}px of width`;
1279
+ return html`<div class="switch" role="group" aria-label="State view">
1280
+ ${[
1281
+ "outline",
1282
+ "map",
1283
+ "timeline",
1284
+ "views"
1285
+ ].map((view) => html`<button
1286
+ aria-pressed=${this._view === view}
1287
+ @click=${() => this._view = view}
1288
+ >
1289
+ ${view}
1290
+ </button>`)}
1291
+ </div>
1292
+ ${map ? html`<div class="switch" role="group" aria-label="Map layout">
1293
+ <button
1294
+ aria-pressed=${nested}
1295
+ ?disabled=${narrow}
1296
+ title=${narrow ? why : "Child states inside their parent"}
1297
+ @click=${() => this.#chooseLayout("nested")}
1298
+ >
1299
+ Nested
1300
+ </button>
1301
+ <button
1302
+ aria-pressed=${!nested}
1303
+ title="Node-link tree"
1304
+ @click=${() => this.#chooseLayout("tree")}
1305
+ >
1306
+ Tree
1307
+ </button>
1308
+ </div>
1309
+ ${layout ? this.#renderViewTools(layout) : nothing}
1310
+ ${this.#holdsViews() ? this.#renderViewsToggle() : nothing}` : nothing}`;
1311
+ }
1312
+ #renderViewsToggle() {
1313
+ const failed = this._mapViews && this._viewsFailed;
1314
+ return html`<div class="switch" role="group" aria-label="Under the Map">
1315
+ <button
1316
+ aria-pressed=${this._mapViews && !failed}
1317
+ ?disabled=${failed}
1318
+ title=${failed ? VIEWS_FAILED : this._mapViews ? "Hide the view path under the Map" : "Show the view path under the Map"}
1319
+ @click=${() => this.#chooseViews(!this._mapViews)}
1320
+ >
1321
+ View path
1322
+ </button>
1323
+ </div>`;
1324
+ }
1325
+ #holdsViews() {
1326
+ return Boolean(this._model.views?.views.length);
1327
+ }
1328
+ #renderViewTools(layout) {
1329
+ const last = (this._map?.ZOOMS.length ?? 1) - 1;
1330
+ const fitted = this._mapPan === null && this._mapZoom === null;
1331
+ return html`<div
1332
+ class="switch view-tools"
1333
+ role="group"
1334
+ aria-label="Map view"
1335
+ >
1336
+ <button
1337
+ class="step"
1338
+ aria-label="Zoom out"
1339
+ title="Smaller type (−)"
1340
+ ?disabled=${layout.step <= 0}
1341
+ @click=${() => this._zoomBy(layout, -1)}
1342
+ >
1343
+ −
1344
+ </button>
1345
+ <button
1346
+ class="step"
1347
+ aria-label="Zoom in"
1348
+ title="Larger type (+)"
1349
+ ?disabled=${layout.step >= last}
1350
+ @click=${() => this._zoomBy(layout, 1)}
1351
+ >
1352
+ +
1353
+ </button>
1354
+ <button
1355
+ title="Fit the map to the panel (0)"
1356
+ ?disabled=${fitted}
1357
+ @click=${() => this._fit()}
1358
+ >
1359
+ Fit
1360
+ </button>
1361
+ </div>`;
1362
+ }
1363
+ #inspectorAside() {
1364
+ if (this._inspect === "state") return undefined;
1365
+ if (this._inspect === "view") return "View";
1366
+ return this._inspect === "none" || this._inspect === "router" ? "Router" : undefined;
1367
+ }
1368
+ #renderInspector(inspected) {
1369
+ if (inspected) return renderTxInspector(this, inspected);
1370
+ if (this._inspect === "state") return renderStateInspector(this);
1371
+ if (this._inspect === "view") return this._viewMap.renderViewInspector(this);
1372
+ return renderRouterCard(this);
1373
+ }
1374
+ #sectionHead(n, title, id, aside) {
1375
+ return html`<h2 class="section" id=${id}>
1376
+ <span class="num">${n}</span
1377
+ ><span class="title">${title}</span
1378
+ >${aside ? html`<span class="aside">${aside}</span>` : nothing}
1379
+ </h2>`;
1380
+ }
1381
+ #summary() {
1382
+ const running = this._runningTx;
1383
+ const last = this._model.txs.findLast((tx) => tx.result?.outcome !== "ignored");
1384
+ const status = running ? "running" : last?.result?.outcome ?? "success";
1385
+ const tx = running ?? last;
1386
+ const name = running?.to ?? (last && last.result?.outcome !== "success" ? last.to : this._model.current.name);
1387
+ return {
1388
+ status,
1389
+ name: name || "(root)",
1390
+ took: tx && tx.id >= 0 ? took(this._duration(tx)) : nothing
1391
+ };
1392
+ }
1393
+ #renderPill() {
1394
+ const { status, name, took } = this.#summary();
1395
+ return html`<button
1396
+ class="pill status-${status}"
1397
+ popover="manual"
1398
+ @click=${this.#open}
1399
+ >
1400
+ ${statusGlyph(status)}<span class="visually-hidden"
1401
+ >Router ${statusLabel[status]}:</span
1402
+ ><span class="pill-name">${elide(name)}</span
1403
+ >${took === nothing ? nothing : html`<span class="num">${took}</span>`}${this._imported ? html`<span class="tag">Imported</span>` : nothing}
1404
+ </button>`;
1405
+ }
1406
+ #toggleRouter() {
1407
+ this.#dropView();
1408
+ this._inspect = this._inspect === "router" ? "none" : "router";
1409
+ this._selectedTx = null;
1410
+ this._selectedState = null;
1411
+ }
1412
+ #showTab(tab) {
1413
+ if (tab === "router") {
1414
+ this._inspect = "router";
1415
+ return;
1416
+ }
1417
+ this._tab = tab;
1418
+ if (this._inspect === "router") this._inspect = "none";
1419
+ }
1420
+ #renderTabs() {
1421
+ const router = this._inspect === "router";
1422
+ const tabs = [
1423
+ [
1424
+ "tree",
1425
+ "1",
1426
+ "States",
1427
+ "pane-tree",
1428
+ !router && this._tab === "tree"
1429
+ ],
1430
+ [
1431
+ "log",
1432
+ "2",
1433
+ "Transitions",
1434
+ "pane-log",
1435
+ !router && this._tab === "log"
1436
+ ],
1437
+ [
1438
+ "router",
1439
+ "3",
1440
+ "Router",
1441
+ "pane-router",
1442
+ router
1443
+ ]
1444
+ ];
1445
+ return html`<div class="tabs" role="tablist" aria-label="Devtools views">
1446
+ ${tabs.map(([tab, n, label, id, selected]) => html`<button
1447
+ role="tab"
1448
+ aria-selected=${selected}
1449
+ aria-controls=${id}
1450
+ @click=${() => this.#showTab(tab)}
1451
+ >
1452
+ <span class="num">${n}</span><span class="label">${label}</span>
1453
+ </button>`)}
1454
+ </div>`;
1455
+ }
1456
+ _exportToggles() {
1457
+ return html`<div class="switch" role="group" aria-label="Export keeps">
1458
+ <button
1459
+ aria-pressed=${this._keepValues}
1460
+ title=${this._keepValues ? "Export keeps param values" : "Export redacts param values; keys stay"}
1461
+ @click=${() => this._keepValues = !this._keepValues}
1462
+ >
1463
+ Param values
1464
+ </button>
1465
+ <button
1466
+ aria-pressed=${this._keepMessages}
1467
+ title=${this._keepMessages ? "Export keeps error messages" : "Export drops error messages"}
1468
+ @click=${() => this._keepMessages = !this._keepMessages}
1469
+ >
1470
+ Messages
1471
+ </button>
1472
+ </div>`;
1473
+ }
1474
+ _sessionButtons() {
1475
+ return html`<button
1476
+ @click=${this.#export}
1477
+ aria-label="Export session as JSON"
1478
+ >
1479
+ Export</button
1480
+ >${this._imported ? html`<button
1481
+ @click=${this.#goLive}
1482
+ aria-label="Live: return to the live router"
1483
+ >
1484
+ Live
1485
+ </button>` : html`<button
1486
+ @click=${() => this.renderRoot.querySelector(".file")?.click()}
1487
+ aria-label="Import session from JSON"
1488
+ >
1489
+ Import
1490
+ </button>`}`;
1491
+ }
1492
+ #renderTitle() {
1493
+ const count = (outcome) => this._model.txs.filter((tx) => tx.result?.outcome === outcome).length;
1494
+ const counts = [
1495
+ [
1496
+ "success",
1497
+ count("success"),
1498
+ "succeeded"
1499
+ ],
1500
+ [
1501
+ "error",
1502
+ count("error") + count("invalid"),
1503
+ "failed"
1504
+ ],
1505
+ [
1506
+ "redirected",
1507
+ count("redirected"),
1508
+ "redirected"
1509
+ ]
1510
+ ];
1511
+ const imported = this._imported;
1512
+ return html`<div class="titlestrip">
1513
+ <button
1514
+ class="brand ${this._inspect === "router" || this._inspect === "tx" ? "anchor" : ""}"
1515
+ aria-pressed=${this._inspect === "router"}
1516
+ title="Router configuration"
1517
+ @click=${this.#toggleRouter}
1518
+ >
1519
+ Router
1520
+ </button>
1521
+ <div class="strip-switch">${this.#renderSwitch()}</div>
1522
+ ${this.#renderTabs()}
1523
+ ${imported ? html`<span class="imported tag" title=${imported.session.routerId}>Imported</span>` : nothing}
1524
+ <span class="spacer"
1525
+ >${this._notice ? html`<span
1526
+ class="notice ${this._notice.fault ? "fault" : ""}"
1527
+ title=${this._notice.text}
1528
+ >${this._notice.text}</span
1529
+ >` : nothing}</span
1530
+ >
1531
+ <span class="counts">
1532
+ ${counts.map(([status, n, label]) => html`<span
1533
+ class="count status-${status} ${n ? "" : "zero"}"
1534
+ title="${n} ${label}"
1535
+ >${statusGlyph(status)}<span class="num">${n}</span
1536
+ ><span class="visually-hidden">${label}</span></span
1537
+ >`)}
1538
+ </span>
1539
+ <span class="session">${this._sessionButtons()}</span>
1540
+ <button
1541
+ class="icon max"
1542
+ aria-pressed=${this._max}
1543
+ aria-label="Maximise devtools"
1544
+ title=${this._max ? "Restore the dock" : "Maximise"}
1545
+ @click=${() => {
1546
+ this._max = !this._max;
1547
+ this._fit();
1548
+ }}
1549
+ >
1550
+ ${this._max ? minGlyph : maxGlyph}
1551
+ </button>
1552
+ <button
1553
+ class="icon close"
1554
+ aria-label="Collapse devtools"
1555
+ @click=${this.#close}
1556
+ >
1557
+ ${closeGlyph}
1558
+ </button>
1559
+ </div>`;
1560
+ }
1561
+ }
1562
+ //# sourceMappingURL=panel.js.map