ui-router-devtools 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +160 -2
  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 +159 -0
  56. package/dist/element/panel.d.ts.map +1 -0
  57. package/dist/element/panel.js +1542 -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/lit-ui-router.d.ts +24 -0
  112. package/dist/lit-ui-router.d.ts.map +1 -0
  113. package/dist/lit-ui-router.js +102 -0
  114. package/dist/lit-ui-router.js.map +1 -0
  115. package/dist/notation.d.ts +28 -0
  116. package/dist/notation.d.ts.map +1 -0
  117. package/dist/notation.js +105 -0
  118. package/dist/notation.js.map +1 -0
  119. package/dist/performance.d.ts +5 -0
  120. package/dist/performance.d.ts.map +1 -0
  121. package/dist/performance.js +66 -0
  122. package/dist/performance.js.map +1 -0
  123. package/dist/plugin.d.ts +32 -0
  124. package/dist/plugin.d.ts.map +1 -0
  125. package/dist/plugin.js +21 -0
  126. package/dist/plugin.js.map +1 -0
  127. package/dist/recorder.d.ts +30 -0
  128. package/dist/recorder.d.ts.map +1 -0
  129. package/dist/recorder.js +117 -0
  130. package/dist/recorder.js.map +1 -0
  131. package/dist/schema.d.ts +2 -0
  132. package/dist/schema.d.ts.map +1 -0
  133. package/dist/schema.js +2 -0
  134. package/dist/schema.js.map +1 -0
  135. package/dist/session-schema.d.ts +31 -0
  136. package/dist/session-schema.d.ts.map +1 -0
  137. package/dist/session-schema.js +314 -0
  138. package/dist/session-schema.js.map +1 -0
  139. package/dist/session.schema.json +1172 -0
  140. package/dist/shared/event-schema.d.ts +225 -0
  141. package/dist/shared/event-schema.d.ts.map +1 -0
  142. package/dist/shared/event-schema.js +2 -0
  143. package/dist/shared/event-schema.js.map +1 -0
  144. package/dist/shared/redaction.d.ts +19 -0
  145. package/dist/shared/redaction.d.ts.map +1 -0
  146. package/dist/shared/redaction.js +56 -0
  147. package/dist/shared/redaction.js.map +1 -0
  148. package/dist/shared/resolve-timing.d.ts +6 -0
  149. package/dist/shared/resolve-timing.d.ts.map +1 -0
  150. package/dist/shared/resolve-timing.js +61 -0
  151. package/dist/shared/resolve-timing.js.map +1 -0
  152. package/dist/shared/router-events.d.ts +10 -0
  153. package/dist/shared/router-events.d.ts.map +1 -0
  154. package/dist/shared/router-events.js +296 -0
  155. package/dist/shared/router-events.js.map +1 -0
  156. package/dist/shared/thrown.d.ts +5 -0
  157. package/dist/shared/thrown.d.ts.map +1 -0
  158. package/dist/shared/thrown.js +12 -0
  159. package/dist/shared/thrown.js.map +1 -0
  160. package/dist/shared/transition-source.d.ts +4 -0
  161. package/dist/shared/transition-source.d.ts.map +1 -0
  162. package/dist/shared/transition-source.js +2 -0
  163. package/dist/shared/transition-source.js.map +1 -0
  164. package/dist/shared/views.d.ts +10 -0
  165. package/dist/shared/views.d.ts.map +1 -0
  166. package/dist/shared/views.js +67 -0
  167. package/dist/shared/views.js.map +1 -0
  168. package/dist/spans.d.ts +15 -0
  169. package/dist/spans.d.ts.map +1 -0
  170. package/dist/spans.js +24 -0
  171. package/dist/spans.js.map +1 -0
  172. package/dist/testing.d.ts +32 -0
  173. package/dist/testing.d.ts.map +1 -0
  174. package/dist/testing.js +28 -0
  175. package/dist/testing.js.map +1 -0
  176. package/dist/ui-router-devtools.d.ts +36 -0
  177. package/dist/ui-router-devtools.d.ts.map +1 -0
  178. package/dist/ui-router-devtools.js +3 -0
  179. package/dist/ui-router-devtools.js.map +1 -0
  180. package/dist/views.d.ts +44 -0
  181. package/dist/views.d.ts.map +1 -0
  182. package/dist/views.js +43 -0
  183. package/dist/views.js.map +1 -0
  184. package/package.json +118 -3
  185. package/src/console.ts +104 -0
  186. package/src/define.ts +12 -0
  187. package/src/edges.ts +64 -0
  188. package/src/element/chips.ts +187 -0
  189. package/src/element/glyphs.ts +218 -0
  190. package/src/element/inspector.ts +315 -0
  191. package/src/element/links.ts +136 -0
  192. package/src/element/log.ts +410 -0
  193. package/src/element/map.ts +22 -0
  194. package/src/element/mapview.ts +224 -0
  195. package/src/element/measure.ts +13 -0
  196. package/src/element/nested.ts +1124 -0
  197. package/src/element/pack.ts +526 -0
  198. package/src/element/panel.ts +2378 -0
  199. package/src/element/popover.ts +64 -0
  200. package/src/element/route.ts +1481 -0
  201. package/src/element/scrubber.ts +103 -0
  202. package/src/element/styles.ts +2084 -0
  203. package/src/element/timeline-styles.ts +287 -0
  204. package/src/element/timeline.ts +392 -0
  205. package/src/element/tree.ts +271 -0
  206. package/src/element/viewmap-styles.ts +283 -0
  207. package/src/element/viewmap.ts +733 -0
  208. package/src/element/viewport.ts +112 -0
  209. package/src/element/waterfall.ts +585 -0
  210. package/src/fold.ts +151 -0
  211. package/src/index.ts +40 -0
  212. package/src/lit-ui-router.ts +194 -0
  213. package/src/notation.ts +181 -0
  214. package/src/performance.ts +142 -0
  215. package/src/plugin.ts +57 -0
  216. package/src/recorder.ts +228 -0
  217. package/src/schema.ts +32 -0
  218. package/src/session-schema.ts +362 -0
  219. package/src/spans.ts +53 -0
  220. package/src/testing.ts +74 -0
  221. package/src/types/import-meta-env.d.ts +9 -0
  222. package/src/ui-router-devtools.ts +39 -0
  223. package/src/views.ts +116 -0
@@ -0,0 +1,218 @@
1
+ import { html, svg, type SVGTemplateResult, type TemplateResult } from 'lit';
2
+ import { ms, type Status } from '../notation.ts';
3
+ import type { StateInfo } from '../schema.ts';
4
+ import { bareName } from '../fold.ts';
5
+
6
+ export type { Status };
7
+
8
+ export type Role =
9
+ | 'current'
10
+ | 'ancestor'
11
+ | 'inactive'
12
+ | 'future'
13
+ | 'entering'
14
+ | 'exiting'
15
+ | 'retained'
16
+ | 'errored';
17
+
18
+ const frame = (body: SVGTemplateResult, cls: string): SVGTemplateResult =>
19
+ svg`<svg class="glyph ${cls}" viewBox="0 0 12 12" aria-hidden="true">${body}</svg>`;
20
+
21
+ const ring = svg`<circle class="ring" cx="6" cy="6" r="4.75" />`;
22
+
23
+ const fault = svg`<rect class="fault" x="1" y="1" width="10" height="10" /><path class="knock" d="M3.75 3.75l4.5 4.5M8.25 3.75l-4.5 4.5" />`;
24
+
25
+ // An abstract state is never a target itself, so its outline is the statechart's compound-state box.
26
+ const plainBox = svg`<rect class="ring" x="1.25" y="1.25" width="9.5" height="9.5" rx="1" />`;
27
+
28
+ const box = svg`<title>abstract</title>${plainBox}`;
29
+
30
+ const roleBodies = (
31
+ outline: SVGTemplateResult,
32
+ ): Record<Role, SVGTemplateResult> => ({
33
+ current: svg`<circle class="solid" cx="6" cy="6" r="5.5" />`,
34
+ ancestor: svg`${outline}<circle class="solid" cx="6" cy="6" r="2" />`,
35
+ inactive: outline,
36
+ future: svg`<circle class="ring" cx="6" cy="6" r="4.75" stroke-dasharray="2.487" />`,
37
+ entering: svg`${outline}<path class="sign" d="M6 3v6M3 6h6" />`,
38
+ exiting: svg`${outline}<path class="sign" d="M3 6h6" />`,
39
+ retained: svg`${outline}<path d="M3.5 4.5h5M3.5 7.5h5" />`,
40
+ errored: fault,
41
+ });
42
+
43
+ const concreteBodies = roleBodies(ring);
44
+
45
+ const abstractBodies = roleBodies(box);
46
+
47
+ const plainAbstractBodies = roleBodies(plainBox);
48
+
49
+ export type Mark = 'initial' | 'history' | 'sticky';
50
+
51
+ const markBodies: Record<Mark, SVGTemplateResult> = {
52
+ initial: svg`<circle class="solid" cx="2.5" cy="6" r="2" /><path d="M4.5 6h5.5" /><polyline points="7.5,3.5 10,6 7.5,8.5" />`,
53
+ history: svg`${ring}<path d="M4.25 3.5v5M7.75 3.5v5M4.25 6h3.5" />`,
54
+ sticky: svg`<rect x="0.75" y="2.25" width="10.5" height="7.5" rx="1" /><path d="M6 3.75v4.5" stroke-dasharray="1.5" />`,
55
+ };
56
+
57
+ const statusBodies: Record<Status, SVGTemplateResult> = {
58
+ running: svg`<path class="arc" d="M6 1.5a4.5 4.5 0 1 1 -4.5 4.5" />`,
59
+ success: svg`<polyline points="2.5,6.5 5,9 9.5,3.5" />`,
60
+ error: fault,
61
+ invalid: svg`<polygon class="fault" points="6,0.75 11.5,11 0.5,11" /><path class="knock" d="M6 4.5v4" />`,
62
+ redirected: svg`<polyline points="2.5,2.5 2.5,7 9,7" /><polyline points="7,5 9,7 7,9" />`,
63
+ superseded: svg`<polyline points="2.5,3 5.5,6 2.5,9" /><polyline points="6.5,3 9.5,6 6.5,9" />`,
64
+ aborted: svg`${ring}<path d="M2.8 9.2L9.2 2.8" />`,
65
+ ignored: svg`<path d="M3.5 6h5" />`,
66
+ };
67
+
68
+ // `titled` is off where the glyph sits in a labelled item: a title's text would count as visible text the label lacks.
69
+ export const roleGlyph = (
70
+ role: Role,
71
+ abstract = false,
72
+ titled = true,
73
+ ): SVGTemplateResult => {
74
+ const bodies = titled ? abstractBodies : plainAbstractBodies;
75
+
76
+ return frame((abstract ? bodies : concreteBodies)[role], `role-${role}`);
77
+ };
78
+
79
+ export const markGlyph = (mark: Mark): SVGTemplateResult =>
80
+ frame(markBodies[mark], `mark-${mark}`);
81
+
82
+ export const statusGlyph = (status: Status): SVGTemplateResult =>
83
+ frame(statusBodies[status], `status-${status}`);
84
+
85
+ // The deepest retained state; it takes the role glyph's place, so nothing in the row moves when it appears.
86
+ const diamond = svg`<polygon class="solid" points="6,0.5 11.5,6 6,11.5 0.5,6" />`;
87
+
88
+ export const pivotGlyph: SVGTemplateResult = frame(
89
+ svg`<title>pivot: deepest retained state</title>${diamond}`,
90
+ 'pivot',
91
+ );
92
+
93
+ export const plainPivotGlyph: SVGTemplateResult = frame(diamond, 'pivot');
94
+
95
+ export const pivotLabel = 'retained, pivot';
96
+
97
+ export const closeGlyph: SVGTemplateResult = frame(
98
+ svg`<path d="M3 3l6 6M9 3l-6 6" />`,
99
+ 'close',
100
+ );
101
+
102
+ export const maxGlyph: SVGTemplateResult = frame(
103
+ svg`<path d="M2.5 5V2.5H5M7 2.5h2.5V5M9.5 7v2.5H7M5 9.5H2.5V7" />`,
104
+ 'max',
105
+ );
106
+
107
+ export const minGlyph: SVGTemplateResult = frame(
108
+ svg`<path d="M5 2.5V5H2.5M9.5 5H7V2.5M7 9.5V7h2.5M2.5 7H5v2.5" />`,
109
+ 'min',
110
+ );
111
+
112
+ export const copyGlyph: SVGTemplateResult = frame(
113
+ svg`<path d="M1.25 8.25v-7h7" /><rect x="3.75" y="3.75" width="7" height="7" />`,
114
+ 'copy',
115
+ );
116
+
117
+ export const copiedGlyph: SVGTemplateResult = frame(
118
+ statusBodies.success,
119
+ 'copied',
120
+ );
121
+
122
+ // Closes or opens a compound on the Map.
123
+ export const foldGlyph = (open: boolean): SVGTemplateResult =>
124
+ frame(
125
+ svg`<polyline points=${open ? '2.5,4.5 6,8 9.5,4.5' : '4.5,2.5 8,6 4.5,9.5'} />`,
126
+ open ? 'fold-open' : 'fold-closed',
127
+ );
128
+
129
+ /** How many identity colours there are; deeper states cycle through them again. */
130
+ export const DEPTHS = 4;
131
+
132
+ // A state's identity colour follows its depth in the declared tree, so it is the same on every surface and in every layout.
133
+ export const depthClass = (depth: number): string =>
134
+ `d${((Math.max(1, depth) - 1) % DEPTHS) + 1}`;
135
+
136
+ export const roleLabel: Record<Role, string> = {
137
+ current: 'active, current',
138
+ ancestor: 'active',
139
+ inactive: 'inactive',
140
+ future: 'lazy, not loaded',
141
+ entering: 'entering',
142
+ exiting: 'exiting',
143
+ retained: 'retained',
144
+ errored: 'errored',
145
+ };
146
+
147
+ export interface StateMark {
148
+ mark: Mark;
149
+ term: string;
150
+ text: string;
151
+ }
152
+
153
+ // What a state's declaration says beyond its place in the tree; a redirect to a direct child is its default child.
154
+ export const stateMarks = (
155
+ state: StateInfo,
156
+ states: readonly StateInfo[],
157
+ ): StateMark[] => {
158
+ const marks: StateMark[] = [];
159
+
160
+ if (state.redirects) {
161
+ const target = states.find((s) => bareName(s.name) === state.redirectTo);
162
+
163
+ marks.push({
164
+ mark: 'initial',
165
+ term: target?.parent === state.name ? 'Default child' : 'Redirects to',
166
+ text: state.redirectTo ?? 'a target computed when it runs',
167
+ });
168
+ }
169
+
170
+ if (state.dsr)
171
+ marks.push({
172
+ mark: 'history',
173
+ term: 'History',
174
+ text: state.dsr.default
175
+ ? `deep state redirect, default ${state.dsr.default}`
176
+ : 'deep state redirect',
177
+ });
178
+
179
+ if (state.sticky)
180
+ marks.push({
181
+ mark: 'sticky',
182
+ term: 'Sticky',
183
+ text: 'kept alive while a sibling is active',
184
+ });
185
+
186
+ return marks;
187
+ };
188
+
189
+ export const markLabel = ({ term, text }: StateMark): string =>
190
+ `${term.toLowerCase()}: ${text}`;
191
+
192
+ // The words a treeitem or map node carries after its name.
193
+ export const describeState = (
194
+ role: string,
195
+ state: StateInfo,
196
+ marks: readonly StateMark[],
197
+ ): string =>
198
+ [role, state.abstract && 'abstract', ...marks.map(markLabel)]
199
+ .filter(Boolean)
200
+ .join(', ');
201
+
202
+ export const statusLabel: Record<Status, string> = {
203
+ running: 'running',
204
+ success: 'succeeded',
205
+ error: 'failed',
206
+ invalid: 'invalid target',
207
+ redirected: 'redirected',
208
+ superseded: 'superseded',
209
+ aborted: 'aborted',
210
+ ignored: 'ignored',
211
+ };
212
+
213
+ /** A duration as it is shown: the number, then its unit set close and muted. A screen reader hears "0.6 ms". */
214
+ export const took = (value: number): TemplateResult => {
215
+ const [amount, unit] = ms(value).split(' ');
216
+
217
+ return html`${amount}<span class="unit">${unit}</span>`;
218
+ };
@@ -0,0 +1,315 @@
1
+ import { html, nothing, type TemplateResult } from 'lit';
2
+ import type { DevtoolsPanel } from './panel.ts';
3
+ import { bareName, type Tx } from '../fold.ts';
4
+ import { SCHEMA_VERSION, type LocationInfo } from '../schema.ts';
5
+ import { edgesOf } from '../edges.ts';
6
+ import { paramText, segment, seq } from '../notation.ts';
7
+ import {
8
+ reasonLine,
9
+ renderOptions,
10
+ renderParams,
11
+ renderTiming,
12
+ } from './log.ts';
13
+ import {
14
+ copiedGlyph,
15
+ copyGlyph,
16
+ markGlyph,
17
+ roleGlyph,
18
+ roleLabel,
19
+ stateMarks,
20
+ statusGlyph,
21
+ statusLabel,
22
+ } from './glyphs.ts';
23
+
24
+ const sub = (n: string, title: string) =>
25
+ html`<h3 class="section sub">
26
+ <span class="num">${n}</span><span class="title">${title}</span>
27
+ </h3>`;
28
+
29
+ // A state named in words; it selects that state and moves focus to its row or box.
30
+ const stateLink = (host: DevtoolsPanel, name: string) =>
31
+ html`<button
32
+ class="link ${host._depthClass(name)}"
33
+ title=${name}
34
+ @click=${() => host._revealState(name)}
35
+ >
36
+ ${segment(name)}
37
+ </button>`;
38
+
39
+ const COPIED_MS = 1500;
40
+
41
+ // Without the Clipboard API, the copied text is selected in place for the viewer to copy by hand.
42
+ const copy = async (
43
+ host: DevtoolsPanel,
44
+ key: string,
45
+ what: string,
46
+ text: string,
47
+ source: Element,
48
+ ) => {
49
+ try {
50
+ await navigator.clipboard.writeText(text);
51
+ } catch {
52
+ const node = document.createTreeWalker(source, NodeFilter.SHOW_TEXT);
53
+ const shown = node.nextNode()!;
54
+ getSelection()!.setBaseAndExtent(shown, 0, shown, text.length);
55
+ host._announcement = `Could not copy; the ${what} is selected`;
56
+
57
+ return;
58
+ }
59
+
60
+ host._announcement = `Copied ${text}`;
61
+ host._copied = key;
62
+ clearTimeout(host._copiedTimer);
63
+ host._copiedTimer = setTimeout(() => (host._copied = null), COPIED_MS);
64
+ };
65
+
66
+ // Copies `text`, which the element before the button shows.
67
+ const copyButton = (
68
+ host: DevtoolsPanel,
69
+ key: string,
70
+ what: string,
71
+ text: string,
72
+ ) => {
73
+ const label = `Copy ${what}`;
74
+ const copied = host._copied === key;
75
+
76
+ return html`<button
77
+ class="icon copy"
78
+ aria-label=${label}
79
+ title=${label}
80
+ ?data-copied=${copied}
81
+ @click=${(e: Event) => {
82
+ // SAFETY: the listener is on this <button>, which always follows the text it copies
83
+ const source = (e.currentTarget as Element).previousElementSibling!;
84
+ void copy(host, key, what, text, source);
85
+ }}
86
+ >
87
+ ${copied ? copiedGlyph : copyGlyph}
88
+ </button>`;
89
+ };
90
+
91
+ const commas = (items: readonly unknown[]) =>
92
+ items.map((item, index) => html`${index ? ', ' : nothing}${item}`);
93
+
94
+ const stateLinks = (host: DevtoolsPanel, names: readonly string[]) =>
95
+ commas(names.map((name) => stateLink(host, name)));
96
+
97
+ // What the Map draws as edges for a selected transition, in words.
98
+ const renderTxPath = (host: DevtoolsPanel, tx: Tx) => {
99
+ if (tx.id < 0) return nothing;
100
+
101
+ const origin = host._origin(tx);
102
+
103
+ return html`<dl class="facts">
104
+ ${
105
+ tx.from
106
+ ? html`<dt>From</dt>
107
+ <dd>${stateLink(host, tx.from)}</dd>`
108
+ : nothing
109
+ }${
110
+ origin
111
+ ? html`<dt>Redirected</dt>
112
+ <dd>from ${seq(origin.id)}, bound for ${origin.to}</dd>`
113
+ : nothing
114
+ }${
115
+ tx.exiting.length
116
+ ? html`<dt>Exits</dt>
117
+ <dd>${stateLinks(host, tx.exiting)}</dd>`
118
+ : nothing
119
+ }${
120
+ tx.entering.length
121
+ ? html`<dt>Enters</dt>
122
+ <dd>${stateLinks(host, tx.entering)}</dd>`
123
+ : nothing
124
+ }
125
+ </dl>`;
126
+ };
127
+
128
+ // What the Map draws as edges for a selected state, in words: successful arrivals and departures per other state.
129
+ const renderTraffic = (host: DevtoolsPanel, name: string) => {
130
+ const seen = edgesOf(host._model).flatMap((edge) =>
131
+ edge.outcomes.success ? [{ ...edge, count: edge.outcomes.success }] : [],
132
+ );
133
+
134
+ const arrived = seen.filter((edge) => edge.to === name);
135
+ const left = seen.filter((edge) => edge.from === name && edge.to !== name);
136
+
137
+ // One state and how often, per hop: `stars ×2`.
138
+ const hop = (other: string, count: number) =>
139
+ html`<span class="hop"
140
+ >${
141
+ other === name || !other
142
+ ? html`<span class="muted">${other ? 'itself' : 'start'}</span>`
143
+ : stateLink(host, other)
144
+ }<span class="times"> ×${count}</span></span
145
+ >`;
146
+
147
+ return html`${
148
+ arrived.length
149
+ ? html`<dt>Arrived</dt>
150
+ <dd class="traffic">
151
+ ${arrived.map((edge) => hop(edge.from, edge.count))}
152
+ </dd>`
153
+ : nothing
154
+ }${
155
+ left.length
156
+ ? html`<dt>Left</dt>
157
+ <dd class="traffic">
158
+ ${left.map((edge) => hop(edge.to, edge.count))}
159
+ </dd>`
160
+ : nothing
161
+ }`;
162
+ };
163
+
164
+ export const renderTxInspector = (
165
+ host: DevtoolsPanel,
166
+ tx: Tx,
167
+ ): TemplateResult => {
168
+ const status = tx.result?.outcome ?? 'running';
169
+
170
+ return html`<div class="inspector">
171
+ <p class="insp-title">
172
+ ${statusGlyph(status)}<span class="name">${tx.to}</span
173
+ ><span class="visually-hidden">${statusLabel[status]}</span>
174
+ </p>
175
+ ${reasonLine(tx, status)} ${renderTxPath(host, tx)}
176
+ ${renderParams(host, tx, '3.1', true)}${renderOptions(tx, '3.2')}${renderTiming(host, tx, '3.3')}
177
+ </div>`;
178
+ };
179
+
180
+ export const renderStateInspector = (host: DevtoolsPanel): TemplateResult => {
181
+ const { states, current } = host._model;
182
+ const name = host._selectedState ?? current.name;
183
+ const state = states.find((s) => s.name === name);
184
+
185
+ if (!state) return html`<p class="empty">Select a state or transition.</p>`;
186
+ const role = host._role(state);
187
+
188
+ const values = state.name === current.name ? current.params : {};
189
+
190
+ return html`<div class="inspector">
191
+ <p class="insp-title ${host._depthClass(state.name)}">
192
+ ${roleGlyph(role, state.abstract)}<span class="name">${state.name}</span
193
+ >${copyButton(host, `name ${state.name}`, 'state name', bareName(state.name))}
194
+ ${
195
+ host._canGo(state)
196
+ ? html`<button class="go" @click=${() => host._go(state)}>Go</button>`
197
+ : nothing
198
+ }
199
+ </p>
200
+ <dl class="facts">
201
+ <dt>Status</dt>
202
+ <dd>${roleLabel[role]}</dd>
203
+ <dt>URL</dt>
204
+ ${
205
+ state.url
206
+ ? html`<dd class="literal copyable">
207
+ <span>${state.url}</span
208
+ >${copyButton(host, `url ${state.name}`, 'URL', state.url)}
209
+ </dd>`
210
+ : html`<dd class="literal">—</dd>`
211
+ }
212
+ ${
213
+ state.abstract
214
+ ? html`<dt>Abstract</dt>
215
+ <dd>never a target itself</dd>`
216
+ : nothing
217
+ }
218
+ ${stateMarks(state, states).map(
219
+ ({ mark, term, text }) =>
220
+ html`<dt>${term}</dt>
221
+ <dd class="marked">${markGlyph(mark)}<span>${text}</span></dd>`,
222
+ )}
223
+ ${renderTraffic(host, state.name)}
224
+ </dl>
225
+ ${sub('3.1', 'Params')}
226
+ ${
227
+ state.params.length
228
+ ? html`<dl class="params">
229
+ ${state.params.map(
230
+ (p) =>
231
+ html`<dt>
232
+ <span class="op"></span
233
+ >${p.id}${p.optional ? '' : html` <span class="muted">required</span>`}
234
+ </dt>
235
+ <dd>
236
+ ${values[p.id] == null ? html`<span class="muted">—</span>` : paramText(values[p.id])}<span
237
+ class="muted"
238
+ >
239
+ ${p.type}${p.dynamic ? ', dynamic' : ''}${p.array ? ', array' : ''}</span
240
+ >
241
+ </dd>`,
242
+ )}
243
+ </dl>`
244
+ : html`<p class="empty">None</p>`
245
+ }
246
+ ${sub('3.2', 'Resolves')}
247
+ ${
248
+ state.resolves.length
249
+ ? html`<ul class="plain">
250
+ ${state.resolves.map((r) => html`<li>${r}</li>`)}
251
+ </ul>`
252
+ : html`<p class="empty">None</p>`
253
+ }
254
+ </div>`;
255
+ };
256
+
257
+ const LOCATION: Record<LocationInfo['kind'], string> = {
258
+ hash: 'Hash',
259
+ pushState: 'pushState',
260
+ memory: 'Memory',
261
+ other: 'Other',
262
+ };
263
+
264
+ const literal = (value: string) =>
265
+ value
266
+ ? html`<dd class="literal">${value}</dd>`
267
+ : html`<dd class="muted">none</dd>`;
268
+
269
+ // The router facts; the dock shows it as the inspector's default, the sheets as their own pane.
270
+ export const renderRouterCard = (
271
+ host: DevtoolsPanel,
272
+ actions = false,
273
+ ): TemplateResult => {
274
+ const { config, states } = host._model;
275
+ const facts = host._sessionFacts();
276
+
277
+ if (!config) return html`<p class="empty">No router attached.</p>`;
278
+
279
+ return html`<div class="inspector router-card">
280
+ <dl class="facts">
281
+ <dt>Location</dt>
282
+ <dd>${LOCATION[config.location.kind]}</dd>
283
+ <dt>Base href</dt>
284
+ ${literal(config.location.baseHref)}
285
+ <dt>HTML5</dt>
286
+ <dd>${config.location.html5Mode ? 'yes' : 'no'}</dd>
287
+ <dt>Hash prefix</dt>
288
+ ${literal(config.location.hashPrefix)}
289
+ <dt>Strict</dt>
290
+ <dd>${config.strictMode ? 'yes' : 'no'}</dd>
291
+ <dt>Case</dt>
292
+ <dd>${config.caseInsensitive ? 'insensitive' : 'sensitive'}</dd>
293
+ <dt>States</dt>
294
+ <dd class="num-start">${states.length}</dd>
295
+ <dt>Events</dt>
296
+ <dd class="num-start">${facts.events}</dd>
297
+ ${
298
+ facts.dropped
299
+ ? html`<dt>Dropped</dt>
300
+ <dd class="num-start">${facts.dropped}</dd>`
301
+ : nothing
302
+ }
303
+ <dt>Session</dt>
304
+ <dd class="literal">${facts.routerId || '—'}</dd>
305
+ <dt>Schema</dt>
306
+ <dd>v${SCHEMA_VERSION}, ${host._imported ? 'imported' : 'live'}</dd>
307
+ </dl>
308
+ ${sub('3.1', 'Plugins')}
309
+ <ul class="plain literal">
310
+ ${config.plugins.map((name) => html`<li>${name}</li>`)}
311
+ </ul>
312
+ ${sub('3.2', 'Export')} ${host._exportToggles()}
313
+ ${actions ? html`<p class="session card-actions">${host._sessionButtons()}</p>` : nothing}
314
+ </div>`;
315
+ };
@@ -0,0 +1,136 @@
1
+ import { html, nothing, type TemplateResult } from 'lit';
2
+ import { hierarchy, tree } from 'd3-hierarchy';
3
+ import type { DevtoolsPanel } from './panel.ts';
4
+ import type { StateInfo } from '../schema.ts';
5
+ import { segment } from '../notation.ts';
6
+ import { depthClass, stateMarks, type Role } from './glyphs.ts';
7
+ import { facts, GLYPH_R, label, rails, RANK, words } from './tree.ts';
8
+
9
+ const MAP_ROW = 36;
10
+
11
+ const MAP_LEAD = 12;
12
+
13
+ const MAP_RUN = 36;
14
+
15
+ const CHAR = 7.2;
16
+
17
+ type MapNode = { state: StateInfo | null; children: MapNode[] };
18
+
19
+ export const renderMap = (host: DevtoolsPanel): TemplateResult => {
20
+ const children = host._children();
21
+
22
+ const build = (parent: string | null): MapNode[] =>
23
+ (children.get(parent) ?? []).map((state) => ({
24
+ state,
25
+ children: build(state.name),
26
+ }));
27
+
28
+ const layout = tree<MapNode>()
29
+ .nodeSize([MAP_ROW, 1])
30
+ .separation(() => 1)(
31
+ hierarchy<MapNode>({ state: null, children: build(null) }),
32
+ );
33
+
34
+ const nodes = layout.descendants();
35
+ // Every state is drawn, so a state tied to the view selected from the path is marked on its own node.
36
+ const linked = host._linkedStates();
37
+ const pivot = host._focusTx?.retained.at(-1);
38
+ const current = host._model.current.name;
39
+
40
+ const nodeWidth = (state: StateInfo) =>
41
+ host._mapWidths.get(state.name) ??
42
+ 12 + 12 + segment(state.name).length * CHAR;
43
+
44
+ // Column n starts one edge run past the widest label in column n - 1.
45
+ const columns = [6];
46
+ const depths = Math.max(...nodes.map((n) => n.depth));
47
+
48
+ for (let depth = 1; depth <= depths; depth++) {
49
+ const widest = Math.max(
50
+ 0,
51
+ ...nodes
52
+ .filter((n) => n.depth === depth - 1 && n.data.state)
53
+ .map((n) => nodeWidth(n.data.state!) - 6 + MAP_LEAD),
54
+ );
55
+
56
+ columns.push(columns[depth - 1] + widest + MAP_RUN);
57
+ }
58
+
59
+ const top = Math.min(...nodes.map((n) => n.x));
60
+
61
+ const pos = (n: (typeof nodes)[number]) => ({
62
+ x: columns[n.depth],
63
+ y: n.x - top + 12,
64
+ });
65
+
66
+ const width = Math.max(
67
+ ...nodes.map(
68
+ (n) => pos(n).x + (n.data.state ? nodeWidth(n.data.state) : 0),
69
+ ),
70
+ );
71
+
72
+ const height = Math.max(...nodes.map((n) => pos(n).y)) + 12;
73
+
74
+ const links = layout
75
+ .links()
76
+ .map(({ source, target }) => {
77
+ const s = pos(source);
78
+ const t = pos(target);
79
+
80
+ const sx = source.data.state
81
+ ? s.x - 6 + nodeWidth(source.data.state) + MAP_LEAD
82
+ : s.x + 4;
83
+
84
+ const role: Role = target.data.state
85
+ ? host._role(target.data.state)
86
+ : 'inactive';
87
+
88
+ return {
89
+ role,
90
+ depth: target.depth,
91
+ d: `M${sx} ${s.y}H${t.x - 24}V${t.y}H${t.x - GLYPH_R}`,
92
+ };
93
+ })
94
+ .sort((a, b) => RANK[a.role] - RANK[b.role]);
95
+
96
+ return html`<div
97
+ class="map"
98
+ role="group"
99
+ aria-label="State map"
100
+ style="inline-size:${width}px;block-size:${height}px"
101
+ >
102
+ <svg class="edges" aria-hidden="true" width=${width} height=${height}>
103
+ ${rails(links)}
104
+ </svg>
105
+ ${nodes.map((node) => {
106
+ const { x, y } = pos(node);
107
+ const state = node.data.state;
108
+
109
+ if (!state)
110
+ return html`<span
111
+ class="map-root"
112
+ style="inset-inline-start:${x - 4}px;inset-block-start:${y - 4}px"
113
+ aria-hidden="true"
114
+ ></span>`;
115
+ const role = host._role(state);
116
+ const isPivot = role === 'retained' && state.name === pivot;
117
+ const marks = stateMarks(state, host._model.states);
118
+ const selected = host._selectedState === state.name;
119
+ const tie = linked.get(state.name);
120
+
121
+ return html`<button
122
+ class="map-node role-${role} ${depthClass(node.depth)} ${facts(state, current)} ${selected ? 'selected' : ''} ${state.name === host._anchorState ? 'anchor' : ''} ${tie ? 'linked' : ''}"
123
+ data-name=${state.name}
124
+ style="inset-inline-start:${x - 6}px;inset-block-start:${y - 12}px"
125
+ aria-pressed=${selected}
126
+ aria-label="${state.name}, ${words(state, role, isPivot, marks)}"
127
+ aria-description=${tie ?? nothing}
128
+ @click=${(e: MouseEvent) => host._selectState(state.name, e.detail > 1)}
129
+ @mousedown=${host._keepText}
130
+ @dblclick=${() => host._goState(state.name)}
131
+ >
132
+ ${label(state, role, isPivot, marks, segment(state.name), false)}
133
+ </button>`;
134
+ })}
135
+ </div>`;
136
+ };