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.
- package/LICENSE +9 -0
- package/README.md +160 -2
- package/dist/console.d.ts +5 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +47 -0
- package/dist/console.js.map +1 -0
- package/dist/define.d.ts +8 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +4 -0
- package/dist/define.js.map +1 -0
- package/dist/edges.d.ts +25 -0
- package/dist/edges.d.ts.map +1 -0
- package/dist/edges.js +28 -0
- package/dist/edges.js.map +1 -0
- package/dist/element/chips.d.ts +17 -0
- package/dist/element/chips.d.ts.map +1 -0
- package/dist/element/chips.js +134 -0
- package/dist/element/chips.js.map +1 -0
- package/dist/element/glyphs.d.ts +34 -0
- package/dist/element/glyphs.d.ts.map +1 -0
- package/dist/element/glyphs.js +107 -0
- package/dist/element/glyphs.js.map +1 -0
- package/dist/element/inspector.d.ts +7 -0
- package/dist/element/inspector.d.ts.map +1 -0
- package/dist/element/inspector.js +183 -0
- package/dist/element/inspector.js.map +1 -0
- package/dist/element/links.d.ts +4 -0
- package/dist/element/links.d.ts.map +1 -0
- package/dist/element/links.js +87 -0
- package/dist/element/links.js.map +1 -0
- package/dist/element/log.d.ts +12 -0
- package/dist/element/log.d.ts.map +1 -0
- package/dist/element/log.js +272 -0
- package/dist/element/log.js.map +1 -0
- package/dist/element/map.d.ts +5 -0
- package/dist/element/map.d.ts.map +1 -0
- package/dist/element/map.js +5 -0
- package/dist/element/map.js.map +1 -0
- package/dist/element/mapview.d.ts +17 -0
- package/dist/element/mapview.d.ts.map +1 -0
- package/dist/element/mapview.js +158 -0
- package/dist/element/mapview.js.map +1 -0
- package/dist/element/measure.d.ts +3 -0
- package/dist/element/measure.d.ts.map +1 -0
- package/dist/element/measure.js +9 -0
- package/dist/element/measure.js.map +1 -0
- package/dist/element/nested.d.ts +45 -0
- package/dist/element/nested.d.ts.map +1 -0
- package/dist/element/nested.js +686 -0
- package/dist/element/nested.js.map +1 -0
- package/dist/element/pack.d.ts +75 -0
- package/dist/element/pack.d.ts.map +1 -0
- package/dist/element/pack.js +281 -0
- package/dist/element/pack.js.map +1 -0
- package/dist/element/panel.d.ts +159 -0
- package/dist/element/panel.d.ts.map +1 -0
- package/dist/element/panel.js +1542 -0
- package/dist/element/panel.js.map +1 -0
- package/dist/element/popover.d.ts +12 -0
- package/dist/element/popover.d.ts.map +1 -0
- package/dist/element/popover.js +38 -0
- package/dist/element/popover.js.map +1 -0
- package/dist/element/route.d.ts +75 -0
- package/dist/element/route.d.ts.map +1 -0
- package/dist/element/route.js +883 -0
- package/dist/element/route.js.map +1 -0
- package/dist/element/scrubber.d.ts +4 -0
- package/dist/element/scrubber.d.ts.map +1 -0
- package/dist/element/scrubber.js +67 -0
- package/dist/element/scrubber.js.map +1 -0
- package/dist/element/styles.d.ts +3 -0
- package/dist/element/styles.d.ts.map +1 -0
- package/dist/element/styles.js +2084 -0
- package/dist/element/styles.js.map +1 -0
- package/dist/element/timeline-styles.d.ts +3 -0
- package/dist/element/timeline-styles.d.ts.map +1 -0
- package/dist/element/timeline-styles.js +286 -0
- package/dist/element/timeline-styles.js.map +1 -0
- package/dist/element/timeline.d.ts +9 -0
- package/dist/element/timeline.d.ts.map +1 -0
- package/dist/element/timeline.js +225 -0
- package/dist/element/timeline.js.map +1 -0
- package/dist/element/tree.d.ts +24 -0
- package/dist/element/tree.d.ts.map +1 -0
- package/dist/element/tree.js +149 -0
- package/dist/element/tree.js.map +1 -0
- package/dist/element/viewmap-styles.d.ts +3 -0
- package/dist/element/viewmap-styles.d.ts.map +1 -0
- package/dist/element/viewmap-styles.js +282 -0
- package/dist/element/viewmap-styles.js.map +1 -0
- package/dist/element/viewmap.d.ts +39 -0
- package/dist/element/viewmap.d.ts.map +1 -0
- package/dist/element/viewmap.js +406 -0
- package/dist/element/viewmap.js.map +1 -0
- package/dist/element/viewport.d.ts +31 -0
- package/dist/element/viewport.d.ts.map +1 -0
- package/dist/element/viewport.js +37 -0
- package/dist/element/viewport.js.map +1 -0
- package/dist/element/waterfall.d.ts +85 -0
- package/dist/element/waterfall.d.ts.map +1 -0
- package/dist/element/waterfall.js +284 -0
- package/dist/element/waterfall.js.map +1 -0
- package/dist/fold.d.ts +27 -0
- package/dist/fold.d.ts.map +1 -0
- package/dist/fold.js +104 -0
- package/dist/fold.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/lit-ui-router.d.ts +24 -0
- package/dist/lit-ui-router.d.ts.map +1 -0
- package/dist/lit-ui-router.js +102 -0
- package/dist/lit-ui-router.js.map +1 -0
- package/dist/notation.d.ts +28 -0
- package/dist/notation.d.ts.map +1 -0
- package/dist/notation.js +105 -0
- package/dist/notation.js.map +1 -0
- package/dist/performance.d.ts +5 -0
- package/dist/performance.d.ts.map +1 -0
- package/dist/performance.js +66 -0
- package/dist/performance.js.map +1 -0
- package/dist/plugin.d.ts +32 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +21 -0
- package/dist/plugin.js.map +1 -0
- package/dist/recorder.d.ts +30 -0
- package/dist/recorder.d.ts.map +1 -0
- package/dist/recorder.js +117 -0
- package/dist/recorder.js.map +1 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +2 -0
- package/dist/schema.js.map +1 -0
- package/dist/session-schema.d.ts +31 -0
- package/dist/session-schema.d.ts.map +1 -0
- package/dist/session-schema.js +314 -0
- package/dist/session-schema.js.map +1 -0
- package/dist/session.schema.json +1172 -0
- package/dist/shared/event-schema.d.ts +225 -0
- package/dist/shared/event-schema.d.ts.map +1 -0
- package/dist/shared/event-schema.js +2 -0
- package/dist/shared/event-schema.js.map +1 -0
- package/dist/shared/redaction.d.ts +19 -0
- package/dist/shared/redaction.d.ts.map +1 -0
- package/dist/shared/redaction.js +56 -0
- package/dist/shared/redaction.js.map +1 -0
- package/dist/shared/resolve-timing.d.ts +6 -0
- package/dist/shared/resolve-timing.d.ts.map +1 -0
- package/dist/shared/resolve-timing.js +61 -0
- package/dist/shared/resolve-timing.js.map +1 -0
- package/dist/shared/router-events.d.ts +10 -0
- package/dist/shared/router-events.d.ts.map +1 -0
- package/dist/shared/router-events.js +296 -0
- package/dist/shared/router-events.js.map +1 -0
- package/dist/shared/thrown.d.ts +5 -0
- package/dist/shared/thrown.d.ts.map +1 -0
- package/dist/shared/thrown.js +12 -0
- package/dist/shared/thrown.js.map +1 -0
- package/dist/shared/transition-source.d.ts +4 -0
- package/dist/shared/transition-source.d.ts.map +1 -0
- package/dist/shared/transition-source.js +2 -0
- package/dist/shared/transition-source.js.map +1 -0
- package/dist/shared/views.d.ts +10 -0
- package/dist/shared/views.d.ts.map +1 -0
- package/dist/shared/views.js +67 -0
- package/dist/shared/views.js.map +1 -0
- package/dist/spans.d.ts +15 -0
- package/dist/spans.d.ts.map +1 -0
- package/dist/spans.js +24 -0
- package/dist/spans.js.map +1 -0
- package/dist/testing.d.ts +32 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +28 -0
- package/dist/testing.js.map +1 -0
- package/dist/ui-router-devtools.d.ts +36 -0
- package/dist/ui-router-devtools.d.ts.map +1 -0
- package/dist/ui-router-devtools.js +3 -0
- package/dist/ui-router-devtools.js.map +1 -0
- package/dist/views.d.ts +44 -0
- package/dist/views.d.ts.map +1 -0
- package/dist/views.js +43 -0
- package/dist/views.js.map +1 -0
- package/package.json +118 -3
- package/src/console.ts +104 -0
- package/src/define.ts +12 -0
- package/src/edges.ts +64 -0
- package/src/element/chips.ts +187 -0
- package/src/element/glyphs.ts +218 -0
- package/src/element/inspector.ts +315 -0
- package/src/element/links.ts +136 -0
- package/src/element/log.ts +410 -0
- package/src/element/map.ts +22 -0
- package/src/element/mapview.ts +224 -0
- package/src/element/measure.ts +13 -0
- package/src/element/nested.ts +1124 -0
- package/src/element/pack.ts +526 -0
- package/src/element/panel.ts +2378 -0
- package/src/element/popover.ts +64 -0
- package/src/element/route.ts +1481 -0
- package/src/element/scrubber.ts +103 -0
- package/src/element/styles.ts +2084 -0
- package/src/element/timeline-styles.ts +287 -0
- package/src/element/timeline.ts +392 -0
- package/src/element/tree.ts +271 -0
- package/src/element/viewmap-styles.ts +283 -0
- package/src/element/viewmap.ts +733 -0
- package/src/element/viewport.ts +112 -0
- package/src/element/waterfall.ts +585 -0
- package/src/fold.ts +151 -0
- package/src/index.ts +40 -0
- package/src/lit-ui-router.ts +194 -0
- package/src/notation.ts +181 -0
- package/src/performance.ts +142 -0
- package/src/plugin.ts +57 -0
- package/src/recorder.ts +228 -0
- package/src/schema.ts +32 -0
- package/src/session-schema.ts +362 -0
- package/src/spans.ts +53 -0
- package/src/testing.ts +74 -0
- package/src/types/import-meta-env.d.ts +9 -0
- package/src/ui-router-devtools.ts +39 -0
- package/src/views.ts +116 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { html, nothing, type TemplateResult } from 'lit';
|
|
2
|
+
import type { DevtoolsPanel } from './panel.ts';
|
|
3
|
+
import type { Tx } from '../fold.ts';
|
|
4
|
+
import type { ParamValue } from '../schema.ts';
|
|
5
|
+
import {
|
|
6
|
+
paramText,
|
|
7
|
+
pathParts,
|
|
8
|
+
resultText,
|
|
9
|
+
sameParam,
|
|
10
|
+
segment,
|
|
11
|
+
seq,
|
|
12
|
+
sourceTags,
|
|
13
|
+
type Status,
|
|
14
|
+
} from '../notation.ts';
|
|
15
|
+
import { roleGlyph, statusGlyph, statusLabel, took } from './glyphs.ts';
|
|
16
|
+
|
|
17
|
+
const SLOW_MS = 150;
|
|
18
|
+
|
|
19
|
+
const PHASES: readonly string[] = [
|
|
20
|
+
'before',
|
|
21
|
+
'start',
|
|
22
|
+
'exit',
|
|
23
|
+
'retain',
|
|
24
|
+
'enter',
|
|
25
|
+
'finish',
|
|
26
|
+
'success',
|
|
27
|
+
'error',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
// Known phases in core's order, then any a later v1 adds, in the order they started.
|
|
31
|
+
const phaseRank = (phase: string): number => {
|
|
32
|
+
const rank = PHASES.indexOf(phase);
|
|
33
|
+
|
|
34
|
+
return rank < 0 ? PHASES.length : rank;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const FAULTS: ReadonlySet<Status> = new Set(['error', 'invalid']);
|
|
38
|
+
|
|
39
|
+
type LogItem =
|
|
40
|
+
| { kind: 'tx'; tx: Tx; origin?: Tx }
|
|
41
|
+
| { kind: 'ignored'; txs: Tx[] };
|
|
42
|
+
|
|
43
|
+
const logItems = (host: DevtoolsPanel): LogItem[] => {
|
|
44
|
+
const items: LogItem[] = [];
|
|
45
|
+
|
|
46
|
+
for (const tx of [...host._model.txs].reverse()) {
|
|
47
|
+
if (tx.result?.outcome === 'redirected' && tx.successor) continue;
|
|
48
|
+
const previous = items.at(-1);
|
|
49
|
+
|
|
50
|
+
if (tx.result?.outcome === 'ignored') {
|
|
51
|
+
if (previous?.kind === 'ignored') previous.txs.push(tx);
|
|
52
|
+
else items.push({ kind: 'ignored', txs: [tx] });
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
items.push({ kind: 'tx', tx, origin: host._origin(tx) });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return items;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// How the transition ended, in words derived from its result; a fault's detail follows its head.
|
|
63
|
+
export const reasonLine = (
|
|
64
|
+
tx: Tx | undefined,
|
|
65
|
+
status: Status,
|
|
66
|
+
): TemplateResult | typeof nothing => {
|
|
67
|
+
const text = tx && resultText(tx);
|
|
68
|
+
|
|
69
|
+
if (!text) return nothing;
|
|
70
|
+
|
|
71
|
+
const { head, detail } = text;
|
|
72
|
+
|
|
73
|
+
return html`<p
|
|
74
|
+
class="reason ${FAULTS.has(status) ? 'fault' : ''}"
|
|
75
|
+
title=${detail ? `${head}: ${detail}` : head}
|
|
76
|
+
>
|
|
77
|
+
<span class="msg">${head}</span
|
|
78
|
+
>${detail ? html`<span class="more">${detail}</span>` : nothing}
|
|
79
|
+
</p>`;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const renderIgnored = (txs: Tx[]) => {
|
|
83
|
+
const ids = txs.map((tx) => seq(tx.id)).join(', ');
|
|
84
|
+
|
|
85
|
+
return html`<li
|
|
86
|
+
class="tx ignored"
|
|
87
|
+
title="${ids} ignored: already at ${txs[0]?.to}"
|
|
88
|
+
>
|
|
89
|
+
<div class="line">
|
|
90
|
+
<span class="seq"></span>${statusGlyph('ignored')}<span class="path muted"
|
|
91
|
+
>${txs.length > 1 ? `${txs.length} ignored` : `ignored`}</span
|
|
92
|
+
>
|
|
93
|
+
</div>
|
|
94
|
+
${reasonLine(txs[0], 'ignored')}
|
|
95
|
+
</li>`;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const renderPath = (tx: Tx): TemplateResult => {
|
|
99
|
+
if (tx.id < 0)
|
|
100
|
+
return html`<span class="path"
|
|
101
|
+
><span class="entered">${tx.to}</span></span
|
|
102
|
+
>`;
|
|
103
|
+
const { pivot, exited, entered } = pathParts(tx);
|
|
104
|
+
|
|
105
|
+
return html`<span class="path"
|
|
106
|
+
>${pivot ? html`<span class="retained">${pivot}</span>` : nothing}${
|
|
107
|
+
exited
|
|
108
|
+
? html`<span class="op">−</span><span class="exited">${exited}</span>`
|
|
109
|
+
: nothing
|
|
110
|
+
}${entered ? html`<span class="op">+</span><span class="entered">${entered}</span>` : nothing}</span
|
|
111
|
+
>`;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const hidden = (s: Status) =>
|
|
115
|
+
html`<span class="visually-hidden">${statusLabel[s]}</span>`;
|
|
116
|
+
|
|
117
|
+
export const valueCell = (
|
|
118
|
+
host: DevtoolsPanel,
|
|
119
|
+
tx: Tx,
|
|
120
|
+
status: Status,
|
|
121
|
+
): TemplateResult => {
|
|
122
|
+
const tags = sourceTags(tx);
|
|
123
|
+
const muted = status === 'superseded' || status === 'aborted';
|
|
124
|
+
|
|
125
|
+
return html`<span class="value"
|
|
126
|
+
>${tags.map((tag) => html`<span class="tag source">${tag}</span>`)}${
|
|
127
|
+
muted
|
|
128
|
+
? html`<span class="tag">${status}</span>`
|
|
129
|
+
: tx.id < 0
|
|
130
|
+
? nothing
|
|
131
|
+
: html`<span class="num">${took(host._duration(tx))}</span>`
|
|
132
|
+
}</span
|
|
133
|
+
>`;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const renderTx = (host: DevtoolsPanel, tx: Tx, origin: Tx | undefined) => {
|
|
137
|
+
const status: Status = tx.result?.outcome ?? 'running';
|
|
138
|
+
const selected = host._selectedTx === tx.id;
|
|
139
|
+
const preview = (id: number | null) => () => (host._previewTx = id);
|
|
140
|
+
const muted = status === 'superseded' || status === 'aborted';
|
|
141
|
+
|
|
142
|
+
const head = origin
|
|
143
|
+
? html`<span class="seq">${seq(origin.id)}</span
|
|
144
|
+
>${statusGlyph('redirected')}${hidden('redirected')}${renderPath(
|
|
145
|
+
origin,
|
|
146
|
+
)}${valueCell(host, origin, 'redirected')}`
|
|
147
|
+
: html`<span class="seq">${seq(tx.id)}</span
|
|
148
|
+
>${statusGlyph(status)}${hidden(status)}${renderPath(tx)}${valueCell(
|
|
149
|
+
host,
|
|
150
|
+
tx,
|
|
151
|
+
status,
|
|
152
|
+
)}`;
|
|
153
|
+
|
|
154
|
+
return html`<li
|
|
155
|
+
class="tx status-${status} ${selected ? 'selected' : ''} ${muted ? 'muted' : ''}"
|
|
156
|
+
@mouseenter=${preview(tx.id)}
|
|
157
|
+
@mouseleave=${preview(null)}
|
|
158
|
+
@focusin=${preview(tx.id)}
|
|
159
|
+
@focusout=${preview(null)}
|
|
160
|
+
>
|
|
161
|
+
<button
|
|
162
|
+
class="line"
|
|
163
|
+
aria-expanded=${selected}
|
|
164
|
+
@click=${() => host._selectTx(selected ? null : tx.id)}
|
|
165
|
+
@mouseenter=${origin ? preview(origin.id) : nothing}
|
|
166
|
+
@mouseleave=${origin ? preview(tx.id) : nothing}
|
|
167
|
+
>
|
|
168
|
+
${head}
|
|
169
|
+
</button>
|
|
170
|
+
${
|
|
171
|
+
origin
|
|
172
|
+
? html`<div class="line chain">
|
|
173
|
+
<span class="seq">${seq(tx.id)}</span
|
|
174
|
+
>${statusGlyph(status)}${hidden(
|
|
175
|
+
status,
|
|
176
|
+
)}${renderPath(tx)}${valueCell(host, tx, status)}
|
|
177
|
+
</div>`
|
|
178
|
+
: nothing
|
|
179
|
+
}
|
|
180
|
+
${reasonLine(tx, status)}
|
|
181
|
+
${
|
|
182
|
+
selected
|
|
183
|
+
? html`<div class="detail">
|
|
184
|
+
${renderParams(host, tx, '2.1')}${renderOptions(tx, '2.2', false)}${renderTiming(host, tx, '2.3')}
|
|
185
|
+
</div>`
|
|
186
|
+
: nothing
|
|
187
|
+
}
|
|
188
|
+
</li>`;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// The oldest end of the log says when the recorder discarded events before it.
|
|
192
|
+
const renderDropped = (host: DevtoolsPanel) => {
|
|
193
|
+
const { dropped } = host._sessionFacts();
|
|
194
|
+
|
|
195
|
+
return dropped
|
|
196
|
+
? html`<p class="dropped">
|
|
197
|
+
<span class="num">${dropped}</span> earlier
|
|
198
|
+
${dropped === 1 ? 'event' : 'events'} dropped
|
|
199
|
+
</p>`
|
|
200
|
+
: nothing;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export const renderLog = (host: DevtoolsPanel): TemplateResult => {
|
|
204
|
+
const items = logItems(host);
|
|
205
|
+
|
|
206
|
+
if (!items.length)
|
|
207
|
+
return html`<p class="empty">No transitions yet.</p>
|
|
208
|
+
${renderDropped(host)}`;
|
|
209
|
+
|
|
210
|
+
return html`<ol class="log">
|
|
211
|
+
${items.map((item) => (item.kind === 'ignored' ? renderIgnored(item.txs) : renderTx(host, item.tx, item.origin)))}
|
|
212
|
+
</ol>
|
|
213
|
+
${renderDropped(host)}`;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const sub = (n: string, title: string) =>
|
|
217
|
+
html`<h3 class="section sub">
|
|
218
|
+
<span class="num">${n}</span><span class="title">${title}</span>
|
|
219
|
+
</h3>`;
|
|
220
|
+
|
|
221
|
+
const renderResolveRow = (
|
|
222
|
+
r: Tx['resolves'][number],
|
|
223
|
+
pct: (t: number) => string,
|
|
224
|
+
) => {
|
|
225
|
+
const slow = !r.cached && r.end - r.start > SLOW_MS;
|
|
226
|
+
|
|
227
|
+
return html`<span class="wf-key">${r.token}</span>
|
|
228
|
+
<div class="track">
|
|
229
|
+
${
|
|
230
|
+
r.cached
|
|
231
|
+
? nothing
|
|
232
|
+
: html`<span
|
|
233
|
+
class="bar ${r.ok ? '' : 'failed'}"
|
|
234
|
+
style="inset-inline-start:${pct(r.start)};inline-size:max(2px, calc(${pct(r.end)} - ${pct(r.start)}))"
|
|
235
|
+
></span>`
|
|
236
|
+
}
|
|
237
|
+
</div>
|
|
238
|
+
${
|
|
239
|
+
r.cached
|
|
240
|
+
? html`<span class="tag">Cached</span>`
|
|
241
|
+
: html`<span class="value"
|
|
242
|
+
>${slow ? html`<span class="tag">Slow</span>` : nothing}<span
|
|
243
|
+
class="num"
|
|
244
|
+
>${took(r.end - r.start)}</span
|
|
245
|
+
></span
|
|
246
|
+
>`
|
|
247
|
+
}`;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// Phases sit on an ordinal ruler with their real offsets; only resolve bars are proportional.
|
|
251
|
+
export const renderTiming = (
|
|
252
|
+
host: DevtoolsPanel,
|
|
253
|
+
tx: Tx,
|
|
254
|
+
n: string,
|
|
255
|
+
): TemplateResult | typeof nothing => {
|
|
256
|
+
if (tx.id < 0) return nothing;
|
|
257
|
+
const t0 = (host._origin(tx) ?? tx).t;
|
|
258
|
+
const end = tx.result?.t ?? host._clock;
|
|
259
|
+
const total = Math.max(end - t0, ...tx.resolves.map((r) => r.end - t0), 0.1);
|
|
260
|
+
|
|
261
|
+
const pct = (t: number) =>
|
|
262
|
+
`${(Math.min(Math.max(0, t - t0), total) / total) * 100}%`;
|
|
263
|
+
|
|
264
|
+
const firstStarts = new Map<string, number>();
|
|
265
|
+
|
|
266
|
+
for (const m of tx.marks)
|
|
267
|
+
if (m.edge === 'start' && !firstStarts.has(m.phase))
|
|
268
|
+
firstStarts.set(m.phase, m.t);
|
|
269
|
+
|
|
270
|
+
const phases = [...firstStarts]
|
|
271
|
+
.map(([phase, t]) => ({ phase, t }))
|
|
272
|
+
.sort((a, b) => phaseRank(a.phase) - phaseRank(b.phase));
|
|
273
|
+
|
|
274
|
+
const byState = [...tx.retained, ...tx.entering].flatMap((state) => {
|
|
275
|
+
const resolves = tx.resolves.filter((r) => r.state === state);
|
|
276
|
+
|
|
277
|
+
return resolves.length ? [{ state, resolves }] : [];
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
return html`${sub(n, 'Resolves')}
|
|
281
|
+
<ol class="ruler" aria-label="Phases, time from start">
|
|
282
|
+
${phases.map(
|
|
283
|
+
(p) =>
|
|
284
|
+
html`<li class=${p.phase === 'error' ? 'fault' : ''}>
|
|
285
|
+
<span class="tag">${p.phase}</span
|
|
286
|
+
><span class="num">${took(Math.max(0, p.t - t0))}</span>
|
|
287
|
+
</li>`,
|
|
288
|
+
)}
|
|
289
|
+
</ol>
|
|
290
|
+
${
|
|
291
|
+
byState.length
|
|
292
|
+
? html`<div class="wf">
|
|
293
|
+
${byState.map(
|
|
294
|
+
(group) =>
|
|
295
|
+
html`${roleGlyph(tx.entering.includes(group.state) ? 'entering' : 'retained')}<span
|
|
296
|
+
class="wf-state"
|
|
297
|
+
>${segment(group.state)}</span
|
|
298
|
+
>
|
|
299
|
+
${group.resolves.map((r) => renderResolveRow(r, pct))}`,
|
|
300
|
+
)}
|
|
301
|
+
<div class="axis" aria-hidden="true">
|
|
302
|
+
<span class="num">0</span><span class="num">${took(total)}</span>
|
|
303
|
+
</div>
|
|
304
|
+
</div>`
|
|
305
|
+
: nothing
|
|
306
|
+
}`;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const opOf = (
|
|
310
|
+
was: ParamValue | undefined,
|
|
311
|
+
now: ParamValue | undefined,
|
|
312
|
+
): string => {
|
|
313
|
+
if (sameParam(was, now)) return '';
|
|
314
|
+
|
|
315
|
+
if (was == null) return '+';
|
|
316
|
+
|
|
317
|
+
return now == null ? '−' : '~';
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export const renderParams = (
|
|
321
|
+
host: DevtoolsPanel,
|
|
322
|
+
tx: Tx,
|
|
323
|
+
n: string,
|
|
324
|
+
all = false,
|
|
325
|
+
): TemplateResult => {
|
|
326
|
+
const before = tx.id < 0 ? {} : host._paramBase(tx);
|
|
327
|
+
const after = tx.toParams;
|
|
328
|
+
|
|
329
|
+
const keys = [
|
|
330
|
+
...new Set([...Object.keys(before), ...Object.keys(after)]),
|
|
331
|
+
].filter((k) => before[k] != null || after[k] != null);
|
|
332
|
+
|
|
333
|
+
const shown = all
|
|
334
|
+
? keys
|
|
335
|
+
: keys.filter((k) => !sameParam(before[k], after[k]));
|
|
336
|
+
|
|
337
|
+
return html`${sub(n, 'Params')}
|
|
338
|
+
${
|
|
339
|
+
shown.length
|
|
340
|
+
? html`<dl class="params">
|
|
341
|
+
${shown.map((k) => {
|
|
342
|
+
const was = before[k];
|
|
343
|
+
const now = after[k];
|
|
344
|
+
const op = opOf(was, now);
|
|
345
|
+
|
|
346
|
+
return html`<dt><span class="op">${op}</span>${k}</dt>
|
|
347
|
+
<dd>
|
|
348
|
+
${op === '~' ? html`<span class="muted">${paramText(was)}</span> → ` : nothing}${now == null ? html`<span class="muted">${paramText(was)}</span>` : paramText(now)}
|
|
349
|
+
</dd>`;
|
|
350
|
+
})}
|
|
351
|
+
</dl>`
|
|
352
|
+
: html`<p class="empty">No param changes</p>`
|
|
353
|
+
}`;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const SOURCE_LABEL: Record<Tx['options']['source'], string> = {
|
|
357
|
+
sref: 'link',
|
|
358
|
+
url: 'URL',
|
|
359
|
+
redirect: 'redirect',
|
|
360
|
+
otherwise: 'otherwise rule',
|
|
361
|
+
unknown: 'go()',
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const yes = (value: boolean) => (value ? 'yes' : 'no');
|
|
365
|
+
|
|
366
|
+
const DEFAULTS = ['go()', 'push', 'no', 'yes', 'yes', 'no'];
|
|
367
|
+
|
|
368
|
+
// The inline detail lists only options that differ from a plain go(); the inspector lists all.
|
|
369
|
+
export const renderOptions = (
|
|
370
|
+
tx: Tx,
|
|
371
|
+
n: string,
|
|
372
|
+
all = true,
|
|
373
|
+
): TemplateResult | typeof nothing => {
|
|
374
|
+
if (tx.id < 0) return nothing;
|
|
375
|
+
const { source, location, reload, inherit, supercede } = tx.options;
|
|
376
|
+
|
|
377
|
+
const every: [string, string, boolean][] = [
|
|
378
|
+
['Source', SOURCE_LABEL[source], false],
|
|
379
|
+
[
|
|
380
|
+
'Location',
|
|
381
|
+
location === 'replace' ? 'replace' : location ? 'push' : 'unchanged',
|
|
382
|
+
false,
|
|
383
|
+
],
|
|
384
|
+
[
|
|
385
|
+
'Reload',
|
|
386
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- the option's own union: a flag or the reloaded state's name
|
|
387
|
+
typeof reload === 'string' ? reload : yes(reload),
|
|
388
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- as above
|
|
389
|
+
typeof reload === 'string',
|
|
390
|
+
],
|
|
391
|
+
['Inherit', yes(inherit), false],
|
|
392
|
+
['Supersede', yes(supercede), false],
|
|
393
|
+
['Dynamic', yes(tx.dynamic), false],
|
|
394
|
+
];
|
|
395
|
+
|
|
396
|
+
const rows = all
|
|
397
|
+
? every
|
|
398
|
+
: every.filter(([, value], i) => value !== DEFAULTS[i]);
|
|
399
|
+
|
|
400
|
+
if (!rows.length) return nothing;
|
|
401
|
+
|
|
402
|
+
return html`${sub(n, 'Options')}
|
|
403
|
+
<dl class="facts">
|
|
404
|
+
${rows.map(
|
|
405
|
+
([key, value, literal]) =>
|
|
406
|
+
html`<dt>${key}</dt>
|
|
407
|
+
<dd class=${literal ? 'literal' : ''}>${value}</dd>`,
|
|
408
|
+
)}
|
|
409
|
+
</dl>`;
|
|
410
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The Map's code, loaded on first use of the Map tab so an Outline-only panel does not pay for it.
|
|
2
|
+
export {
|
|
3
|
+
anchorRect,
|
|
4
|
+
keepClear,
|
|
5
|
+
layoutNested,
|
|
6
|
+
renderNested,
|
|
7
|
+
ZOOMS,
|
|
8
|
+
type NestedLayout,
|
|
9
|
+
} from './nested.ts';
|
|
10
|
+
|
|
11
|
+
export { MINI_FOOT, startPan, wheelPan } from './mapview.ts';
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
centreView,
|
|
15
|
+
clampView,
|
|
16
|
+
fitView,
|
|
17
|
+
overflows,
|
|
18
|
+
revealView,
|
|
19
|
+
zoomView,
|
|
20
|
+
} from './viewport.ts';
|
|
21
|
+
|
|
22
|
+
export { renderMap } from './links.ts';
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// The Map's viewport in the panel: the keys, drags and wheel that move it, and the minimap.
|
|
2
|
+
import { html, nothing, svg, type TemplateResult } from 'lit';
|
|
3
|
+
import type { DevtoolsPanel } from './panel.ts';
|
|
4
|
+
import type { NestedLayout } from './nested.ts';
|
|
5
|
+
import type { Size } from './pack.ts';
|
|
6
|
+
import { overflows, type View } from './viewport.ts';
|
|
7
|
+
|
|
8
|
+
/** How far one press of Shift and an arrow key pans. */
|
|
9
|
+
const PAN_STEP = 48;
|
|
10
|
+
|
|
11
|
+
const PAN_KEYS: ReadonlyMap<string, View> = new Map([
|
|
12
|
+
['ArrowLeft', { x: PAN_STEP, y: 0 }],
|
|
13
|
+
['ArrowRight', { x: -PAN_STEP, y: 0 }],
|
|
14
|
+
['ArrowUp', { x: 0, y: PAN_STEP }],
|
|
15
|
+
['ArrowDown', { x: 0, y: -PAN_STEP }],
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const ZOOM_KEYS: ReadonlyMap<string, number> = new Map([
|
|
19
|
+
['+', 1],
|
|
20
|
+
['=', 1],
|
|
21
|
+
['-', -1],
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
// Shift with an arrow key pans, plus and minus change the type step, and 0 fits; the plain arrow keys stay the tree's.
|
|
25
|
+
export const viewKey = (
|
|
26
|
+
host: DevtoolsPanel,
|
|
27
|
+
layout: NestedLayout,
|
|
28
|
+
event: KeyboardEvent,
|
|
29
|
+
): boolean => {
|
|
30
|
+
if (event.ctrlKey || event.metaKey || event.altKey) return false;
|
|
31
|
+
|
|
32
|
+
const pan = event.shiftKey ? PAN_KEYS.get(event.key) : undefined;
|
|
33
|
+
const zoom = ZOOM_KEYS.get(event.key);
|
|
34
|
+
|
|
35
|
+
if (pan) {
|
|
36
|
+
const view = host._viewOf(layout);
|
|
37
|
+
host._panTo(layout, { x: view.x + pan.x, y: view.y + pan.y }, true);
|
|
38
|
+
} else if (zoom) host._zoomBy(layout, zoom);
|
|
39
|
+
else if (event.key === '0') host._fit();
|
|
40
|
+
else return false;
|
|
41
|
+
|
|
42
|
+
return true;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Capture keeps a drag going past the element's edge; a pointer that is already gone cannot be captured, and the drag then ends at the edge.
|
|
46
|
+
const capture = (element: Element, event: PointerEvent): void => {
|
|
47
|
+
try {
|
|
48
|
+
element.setPointerCapture(event.pointerId);
|
|
49
|
+
} catch {
|
|
50
|
+
// the moves still arrive while the pointer is over the element
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** A drag has to move this far before it pans, so a click still selects. */
|
|
55
|
+
const DRAG = 4;
|
|
56
|
+
|
|
57
|
+
/** Pans by a drag on the Map, from empty space or from a box. */
|
|
58
|
+
export const startPan = (host: DevtoolsPanel, event: PointerEvent): void => {
|
|
59
|
+
const layout = host._nested();
|
|
60
|
+
// SAFETY: the listener is on the Map viewport's own element
|
|
61
|
+
const scroller = event.currentTarget as HTMLElement;
|
|
62
|
+
|
|
63
|
+
if (!layout || event.button !== 0 || !host._pans(layout)) return;
|
|
64
|
+
|
|
65
|
+
const from = host._viewOf(layout);
|
|
66
|
+
let dragging = false;
|
|
67
|
+
|
|
68
|
+
const move = (to: PointerEvent) => {
|
|
69
|
+
const x = to.clientX - event.clientX;
|
|
70
|
+
const y = to.clientY - event.clientY;
|
|
71
|
+
|
|
72
|
+
if (!dragging && Math.hypot(x, y) < DRAG) return;
|
|
73
|
+
|
|
74
|
+
if (!dragging) {
|
|
75
|
+
dragging = true;
|
|
76
|
+
scroller.toggleAttribute('data-panning', true);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
host._panTo(layout, { x: from.x + x, y: from.y + y }, false);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const swallow = (click: Event) => click.stopPropagation();
|
|
83
|
+
|
|
84
|
+
// The drag is followed on the window, so it goes on when the pointer leaves the Map.
|
|
85
|
+
const end = () => {
|
|
86
|
+
removeEventListener('pointermove', move);
|
|
87
|
+
removeEventListener('pointerup', end);
|
|
88
|
+
removeEventListener('pointercancel', end);
|
|
89
|
+
scroller.removeAttribute('data-panning');
|
|
90
|
+
|
|
91
|
+
if (!dragging) return;
|
|
92
|
+
|
|
93
|
+
// The click that ends a drag selects nothing.
|
|
94
|
+
scroller.addEventListener('click', swallow, { capture: true, once: true });
|
|
95
|
+
setTimeout(() => scroller.removeEventListener('click', swallow, true));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
addEventListener('pointermove', move);
|
|
99
|
+
addEventListener('pointerup', end);
|
|
100
|
+
addEventListener('pointercancel', end);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const wheeled = new WeakMap<DevtoolsPanel, number>();
|
|
104
|
+
|
|
105
|
+
/** How much wheel travel with Control or Command held changes the type step once. */
|
|
106
|
+
const NOTCH = 48;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The wheel pans the Map while there is more of it that way, and past its edge scrolls the page as any scroller would.
|
|
110
|
+
* With Control or Command held, which is also what a pinch sends, it changes the type step.
|
|
111
|
+
*/
|
|
112
|
+
export const wheelPan = (host: DevtoolsPanel, event: WheelEvent): void => {
|
|
113
|
+
const layout = host._nested();
|
|
114
|
+
|
|
115
|
+
if (!layout) return;
|
|
116
|
+
|
|
117
|
+
const lines = event.deltaMode === WheelEvent.DOM_DELTA_LINE ? 16 : 1;
|
|
118
|
+
|
|
119
|
+
if (event.ctrlKey || event.metaKey) {
|
|
120
|
+
const total = (wheeled.get(host) ?? 0) + event.deltaY * lines;
|
|
121
|
+
const steps = Math.trunc(total / NOTCH);
|
|
122
|
+
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
wheeled.set(host, total - steps * NOTCH);
|
|
125
|
+
|
|
126
|
+
if (steps) host._zoomBy(layout, -Math.sign(steps));
|
|
127
|
+
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const view = host._viewOf(layout);
|
|
132
|
+
|
|
133
|
+
const moved = host._panTo(
|
|
134
|
+
layout,
|
|
135
|
+
{ x: view.x - event.deltaX * lines, y: view.y - event.deltaY * lines },
|
|
136
|
+
false,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
if (moved) event.preventDefault();
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** The largest the minimap is drawn. */
|
|
143
|
+
const MINI = { width: 144, height: 60 };
|
|
144
|
+
|
|
145
|
+
/** The room the minimap takes at the block end, its frame and margin included; the diagram can be pulled clear of it. */
|
|
146
|
+
export const MINI_FOOT = 84;
|
|
147
|
+
|
|
148
|
+
// A thumbnail of the whole layout with the part in view outlined, drawn only while the layout overflows the room.
|
|
149
|
+
// A press or a drag on it puts that point in the middle of the room. It is a pointer's shortcut, so it is hidden from assistive technology.
|
|
150
|
+
export const renderMinimap = (
|
|
151
|
+
host: DevtoolsPanel,
|
|
152
|
+
layout: NestedLayout,
|
|
153
|
+
view: View,
|
|
154
|
+
room: Size,
|
|
155
|
+
): TemplateResult | typeof nothing => {
|
|
156
|
+
const { placed, rects, open } = layout;
|
|
157
|
+
|
|
158
|
+
if (!overflows(placed, room)) return nothing;
|
|
159
|
+
|
|
160
|
+
const scale = Math.min(
|
|
161
|
+
MINI.width / placed.width,
|
|
162
|
+
MINI.height / placed.height,
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const width = Math.ceil(placed.width * scale);
|
|
166
|
+
const height = Math.ceil(placed.height * scale);
|
|
167
|
+
|
|
168
|
+
// The part of the diagram in the room, held to the thumbnail's own outline.
|
|
169
|
+
const left = Math.min(width - 2, Math.max(0, -view.x * scale));
|
|
170
|
+
const top = Math.min(height - 2, Math.max(0, -view.y * scale));
|
|
171
|
+
|
|
172
|
+
const centre = (event: PointerEvent) => {
|
|
173
|
+
// SAFETY: the listener is on the minimap's own element
|
|
174
|
+
const box = (event.currentTarget as Element).getBoundingClientRect();
|
|
175
|
+
|
|
176
|
+
host._panTo(
|
|
177
|
+
layout,
|
|
178
|
+
{
|
|
179
|
+
x: room.width / 2 - (event.clientX - box.x) / scale,
|
|
180
|
+
y: room.height / 2 - (event.clientY - box.y) / scale,
|
|
181
|
+
},
|
|
182
|
+
false,
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const press = (event: PointerEvent) => {
|
|
187
|
+
// SAFETY: the listener is on the minimap's own element
|
|
188
|
+
capture(event.currentTarget as Element, event);
|
|
189
|
+
event.stopPropagation();
|
|
190
|
+
centre(event);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const drag = (event: PointerEvent) => {
|
|
194
|
+
if (event.buttons & 1) centre(event);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
return html`<svg
|
|
198
|
+
class="minimap"
|
|
199
|
+
aria-hidden="true"
|
|
200
|
+
width=${width}
|
|
201
|
+
height=${height}
|
|
202
|
+
viewBox="0 0 ${width} ${height}"
|
|
203
|
+
@pointerdown=${press}
|
|
204
|
+
@pointermove=${drag}
|
|
205
|
+
>
|
|
206
|
+
${[...rects].map(
|
|
207
|
+
([name, rect]) =>
|
|
208
|
+
svg`<rect
|
|
209
|
+
class="${host._depthClass(name)} ${open.has(name) ? 'open' : ''} ${name === host._model.current.name ? 'current' : ''}"
|
|
210
|
+
x=${rect.x * scale}
|
|
211
|
+
y=${rect.y * scale}
|
|
212
|
+
width=${rect.width * scale}
|
|
213
|
+
height=${rect.height * scale}
|
|
214
|
+
/>`,
|
|
215
|
+
)}
|
|
216
|
+
<rect
|
|
217
|
+
class="window"
|
|
218
|
+
x=${left + 0.5}
|
|
219
|
+
y=${top + 0.5}
|
|
220
|
+
width=${Math.max(1, Math.min(width, left + room.width * scale) - left - 1)}
|
|
221
|
+
height=${Math.max(1, Math.min(height, top + room.height * scale) - top - 1)}
|
|
222
|
+
/>
|
|
223
|
+
</svg>`;
|
|
224
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const CHAR = 7.2;
|
|
2
|
+
|
|
3
|
+
let context: CanvasRenderingContext2D | null | undefined;
|
|
4
|
+
|
|
5
|
+
/** A label's width from a canvas, so packing needs no render; without one, from a per-character estimate. */
|
|
6
|
+
export const textWidth = (text: string, font: string): number => {
|
|
7
|
+
context ??= globalThis.document?.createElement('canvas').getContext('2d');
|
|
8
|
+
|
|
9
|
+
if (!context) return text.length * CHAR;
|
|
10
|
+
context.font = font;
|
|
11
|
+
|
|
12
|
+
return context.measureText(text).width;
|
|
13
|
+
};
|