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.
- package/LICENSE +9 -0
- package/README.md +203 -0
- 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 +160 -0
- package/dist/element/panel.d.ts.map +1 -0
- package/dist/element/panel.js +1562 -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/lazy.d.ts +57 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js +63 -0
- package/dist/lazy.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 +123 -2
- 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 +2410 -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/lazy.ts +134 -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,112 @@
|
|
|
1
|
+
// The Map's viewport: where a packed layout sits in the room it is shown in. It reads no DOM.
|
|
2
|
+
import type { Size } from './pack.ts';
|
|
3
|
+
import type { Rect } from './route.ts';
|
|
4
|
+
|
|
5
|
+
/** The diagram's top-left corner measured from the room's, in whole pixels, so type and hairlines stay on the pixel grid. */
|
|
6
|
+
export interface View {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Room extends Size {
|
|
12
|
+
/** Kept free at the inline end, for the inspector popover's column. */
|
|
13
|
+
reserve: number;
|
|
14
|
+
/** How far past the room's inline end an overflowing diagram may be pulled, to bring it out from under the popover. */
|
|
15
|
+
slack: number;
|
|
16
|
+
/** How far past the room's block end an overflowing diagram may be pulled, to bring it out from under the minimap. */
|
|
17
|
+
foot: number;
|
|
18
|
+
rtl: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The margin kept around a box that is panned into view. */
|
|
22
|
+
const PAD = 12;
|
|
23
|
+
|
|
24
|
+
const within = (value: number, low: number, high: number): number =>
|
|
25
|
+
Math.round(Math.min(high, Math.max(low, value)));
|
|
26
|
+
|
|
27
|
+
export const overflows = (size: Size, room: Size): boolean =>
|
|
28
|
+
size.width > room.width || size.height > room.height;
|
|
29
|
+
|
|
30
|
+
/** The fitted view: the diagram in the middle of the room left beside the reserve, or at the start of an axis it overflows. */
|
|
31
|
+
export const fitView = (size: Size, room: Room): View => {
|
|
32
|
+
const inline = Math.max(
|
|
33
|
+
0,
|
|
34
|
+
Math.round((room.width - room.reserve - size.width) / 2),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
x: room.rtl ? room.width - size.width - inline : inline,
|
|
39
|
+
y: Math.max(0, Math.round((room.height - size.height) / 2)),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Holds a view to what can be panned: an axis the diagram fits on stays fitted, and one it overflows stops at the diagram's edges.
|
|
45
|
+
* A diagram that overflows either axis can also be pulled up by the room's foot.
|
|
46
|
+
*/
|
|
47
|
+
export const clampView = (view: View, size: Size, room: Room): View => {
|
|
48
|
+
const fit = fitView(size, room);
|
|
49
|
+
const spare = room.width - size.width;
|
|
50
|
+
const foot = overflows(size, room) ? room.foot : 0;
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
x:
|
|
54
|
+
spare >= 0
|
|
55
|
+
? fit.x
|
|
56
|
+
: within(
|
|
57
|
+
view.x,
|
|
58
|
+
spare - (room.rtl ? 0 : room.slack),
|
|
59
|
+
room.rtl ? room.slack : 0,
|
|
60
|
+
),
|
|
61
|
+
y: within(view.y, Math.min(fit.y, room.height - size.height - foot), fit.y),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// How far to move one axis so a span lies inside the room; a span longer than the room shows its start.
|
|
66
|
+
const into = (low: number, length: number, room: number): number => {
|
|
67
|
+
if (low < PAD) return PAD - low;
|
|
68
|
+
|
|
69
|
+
const past = low + length - (room - PAD);
|
|
70
|
+
|
|
71
|
+
return past > 0 ? -Math.min(past, low - PAD) : 0;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** The view moved the least that brings a box of the diagram wholly into the room. */
|
|
75
|
+
export const revealView = (
|
|
76
|
+
view: View,
|
|
77
|
+
rect: Rect,
|
|
78
|
+
size: Size,
|
|
79
|
+
room: Room,
|
|
80
|
+
): View =>
|
|
81
|
+
clampView(
|
|
82
|
+
{
|
|
83
|
+
x: view.x + into(view.x + rect.x, rect.width, room.width),
|
|
84
|
+
y: view.y + into(view.y + rect.y, rect.height, room.height),
|
|
85
|
+
},
|
|
86
|
+
size,
|
|
87
|
+
room,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
/** The view that puts a box of the diagram in the middle of the room, as far as the diagram's edges allow. */
|
|
91
|
+
export const centreView = (rect: Rect, size: Size, room: Room): View =>
|
|
92
|
+
clampView(
|
|
93
|
+
{
|
|
94
|
+
x: room.width / 2 - rect.x - rect.width / 2,
|
|
95
|
+
y: room.height / 2 - rect.y - rect.height / 2,
|
|
96
|
+
},
|
|
97
|
+
size,
|
|
98
|
+
room,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
/** The view after the diagram changes size, with the point in the middle of the room held still. */
|
|
102
|
+
export const zoomView = (view: View, from: Size, to: Size, room: Room): View =>
|
|
103
|
+
clampView(
|
|
104
|
+
{
|
|
105
|
+
x: room.width / 2 - ((room.width / 2 - view.x) * to.width) / from.width,
|
|
106
|
+
y:
|
|
107
|
+
room.height / 2 -
|
|
108
|
+
((room.height / 2 - view.y) * to.height) / from.height,
|
|
109
|
+
},
|
|
110
|
+
to,
|
|
111
|
+
room,
|
|
112
|
+
);
|
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
// The Timeline's model: a transition, its redirect chain, its phases, resolves and joined spans, on one time axis. No DOM.
|
|
2
|
+
import { originOf, type Tx } from '../fold.ts';
|
|
3
|
+
import type { PhaseEvent, SpanRecord, StateInfo } from '../schema.ts';
|
|
4
|
+
import { spanWindow, type SpanWindow } from '../spans.ts';
|
|
5
|
+
import { seq, type Status } from '../notation.ts';
|
|
6
|
+
|
|
7
|
+
export type BarKind = 'transition' | 'phase' | 'resolve' | 'span';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* How a span is known to belong to a transition: `child` descends from one of the router's own spans for it, `trace`
|
|
11
|
+
* shares its trace and overlaps it, and `during` only overlaps it in time.
|
|
12
|
+
*/
|
|
13
|
+
export type Relation = 'child' | 'trace' | 'during';
|
|
14
|
+
|
|
15
|
+
export interface Bar {
|
|
16
|
+
/** Unique in one waterfall, and stable while the transition runs. */
|
|
17
|
+
key: string;
|
|
18
|
+
kind: BarKind;
|
|
19
|
+
/** The transition the bar belongs to. */
|
|
20
|
+
tx: number;
|
|
21
|
+
name: string;
|
|
22
|
+
state: string | null;
|
|
23
|
+
/** On the event clock; null for a row nothing timed. */
|
|
24
|
+
time: SpanWindow | null;
|
|
25
|
+
running: boolean;
|
|
26
|
+
fault: boolean;
|
|
27
|
+
/** What the bar alone does not say: `cached`, `untimed`, `cut short`, `redirected to 007`. */
|
|
28
|
+
note: string | null;
|
|
29
|
+
status?: Status;
|
|
30
|
+
relation?: Relation;
|
|
31
|
+
span?: SpanRecord;
|
|
32
|
+
children: Bar[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface Waterfall {
|
|
36
|
+
roots: Bar[];
|
|
37
|
+
/** The axis's zero on the event clock, and its length in milliseconds. */
|
|
38
|
+
zero: number;
|
|
39
|
+
length: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface WaterfallInput {
|
|
43
|
+
txs: readonly Tx[];
|
|
44
|
+
tx: Tx;
|
|
45
|
+
states: readonly StateInfo[];
|
|
46
|
+
/** The event clock now, or at an imported session's export. */
|
|
47
|
+
clock: number;
|
|
48
|
+
/** Whether the session timed resolves; without it a transition's resolves are listed untimed. */
|
|
49
|
+
timeResolves: boolean;
|
|
50
|
+
spans: readonly SpanRecord[];
|
|
51
|
+
/** Epoch milliseconds of the event clock's zero, to place spans on it. */
|
|
52
|
+
timeOrigin: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** How far apart, in milliseconds, the recorder's and the reporter's clocks may read one transition's start. */
|
|
56
|
+
export const START_TOLERANCE = 2;
|
|
57
|
+
|
|
58
|
+
const ROUTER = 'uirouter.';
|
|
59
|
+
|
|
60
|
+
const NOTES: Partial<Record<Status, string>> = {
|
|
61
|
+
aborted: 'aborted',
|
|
62
|
+
ignored: 'ignored',
|
|
63
|
+
invalid: 'invalid',
|
|
64
|
+
error: 'failed',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** The redirect chain `tx` is part of, from the first transition to the last that ran. */
|
|
68
|
+
export const chainOf = (txs: readonly Tx[], tx: Tx): Tx[] => {
|
|
69
|
+
let first = tx;
|
|
70
|
+
const seen = new Set([tx]);
|
|
71
|
+
|
|
72
|
+
for (
|
|
73
|
+
let origin = originOf(txs, first);
|
|
74
|
+
origin && !seen.has(origin);
|
|
75
|
+
origin = originOf(txs, origin)
|
|
76
|
+
) {
|
|
77
|
+
seen.add(origin);
|
|
78
|
+
first = origin;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const chain = [first];
|
|
82
|
+
|
|
83
|
+
for (let id = first.successor; id !== undefined;) {
|
|
84
|
+
const next = txs.find((each) => each.id === id);
|
|
85
|
+
|
|
86
|
+
if (!next || chain.includes(next)) break;
|
|
87
|
+
chain.push(next);
|
|
88
|
+
id = next.successor;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return chain;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const byStart = (a: Bar, b: Bar): number =>
|
|
95
|
+
(a.time?.start ?? Infinity) - (b.time?.start ?? Infinity);
|
|
96
|
+
|
|
97
|
+
const endOf = (tx: Tx, clock: number): number => tx.result?.t ?? clock;
|
|
98
|
+
|
|
99
|
+
const txNote = (tx: Tx): string | null => {
|
|
100
|
+
const result = tx.result;
|
|
101
|
+
|
|
102
|
+
if (!result) return null;
|
|
103
|
+
|
|
104
|
+
if (result.outcome === 'redirected')
|
|
105
|
+
return tx.successor === undefined
|
|
106
|
+
? 'redirected'
|
|
107
|
+
: `redirected to ${seq(tx.successor)}`;
|
|
108
|
+
|
|
109
|
+
if (result.outcome === 'superseded')
|
|
110
|
+
return result.by === undefined
|
|
111
|
+
? 'superseded'
|
|
112
|
+
: `superseded by ${seq(result.by)}`;
|
|
113
|
+
|
|
114
|
+
return NOTES[result.outcome] ?? null;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const phaseBar = (
|
|
118
|
+
tx: Tx,
|
|
119
|
+
start: PhaseEvent,
|
|
120
|
+
end: number,
|
|
121
|
+
cut: 'running' | 'cut' | null,
|
|
122
|
+
): Bar => ({
|
|
123
|
+
key: `${tx.id}:p${start.seq}`,
|
|
124
|
+
kind: 'phase',
|
|
125
|
+
tx: tx.id,
|
|
126
|
+
name: start.state ? `${start.phase} ${start.state}` : start.phase,
|
|
127
|
+
state: start.state,
|
|
128
|
+
time: { start: start.t, end },
|
|
129
|
+
running: cut === 'running',
|
|
130
|
+
fault: start.phase === 'error',
|
|
131
|
+
note: cut === 'cut' ? 'cut short' : null,
|
|
132
|
+
children: [],
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Pairs each phase's two edges; a phase still open when the transition settled ends with it.
|
|
136
|
+
const phaseBars = (tx: Tx, clock: number): Bar[] => {
|
|
137
|
+
const open = new Map<string, PhaseEvent>();
|
|
138
|
+
const bars: Bar[] = [];
|
|
139
|
+
|
|
140
|
+
for (const mark of tx.marks) {
|
|
141
|
+
const key = `${mark.phase} ${mark.state ?? ''}`;
|
|
142
|
+
|
|
143
|
+
if (mark.edge === 'start') {
|
|
144
|
+
open.set(key, mark);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const start = open.get(key);
|
|
149
|
+
|
|
150
|
+
if (!start) continue;
|
|
151
|
+
open.delete(key);
|
|
152
|
+
bars.push(phaseBar(tx, start, mark.t, null));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
for (const start of open.values())
|
|
156
|
+
bars.push(
|
|
157
|
+
phaseBar(tx, start, endOf(tx, clock), tx.result ? 'cut' : 'running'),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return bars;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const resolveBars = (tx: Tx): Bar[] =>
|
|
164
|
+
tx.resolves.map((resolve) => ({
|
|
165
|
+
key: `${tx.id}:r${resolve.seq}`,
|
|
166
|
+
kind: 'resolve',
|
|
167
|
+
tx: tx.id,
|
|
168
|
+
name: `resolve ${resolve.token}`,
|
|
169
|
+
state: resolve.state,
|
|
170
|
+
time: resolve.cached ? null : { start: resolve.start, end: resolve.end },
|
|
171
|
+
running: false,
|
|
172
|
+
fault: !resolve.ok,
|
|
173
|
+
note: resolve.cached ? 'cached' : resolve.ok ? null : 'failed',
|
|
174
|
+
children: [],
|
|
175
|
+
}));
|
|
176
|
+
|
|
177
|
+
const resolveKey = (state: string, token: string): string =>
|
|
178
|
+
`${state} ${token}`;
|
|
179
|
+
|
|
180
|
+
// A declared resolve timed by the router's own resolve span, from ui-router-otel's activateResolveSpans.
|
|
181
|
+
const spannedBar = (
|
|
182
|
+
bar: Bar,
|
|
183
|
+
span: SpanRecord,
|
|
184
|
+
{ timeOrigin, clock }: Placing,
|
|
185
|
+
): Bar => ({
|
|
186
|
+
...bar,
|
|
187
|
+
time: spanWindow(span, timeOrigin, clock),
|
|
188
|
+
running: span.endTime === undefined,
|
|
189
|
+
fault: span.status === 'error',
|
|
190
|
+
note: span.status === 'error' ? 'failed' : null,
|
|
191
|
+
span,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// The entering states' declared resolves still ran when no event timed them: a router resolve span times one, else it is listed untimed.
|
|
195
|
+
const declaredBars = (
|
|
196
|
+
tx: Tx,
|
|
197
|
+
states: readonly StateInfo[],
|
|
198
|
+
spans: ReadonlyMap<string, SpanRecord>,
|
|
199
|
+
placing: Placing,
|
|
200
|
+
): Bar[] =>
|
|
201
|
+
tx.entering.flatMap((name) =>
|
|
202
|
+
(states.find((state) => state.name === name)?.resolves ?? []).map(
|
|
203
|
+
(token): Bar => {
|
|
204
|
+
const bar: Bar = {
|
|
205
|
+
key: `${tx.id}:u${name}:${token}`,
|
|
206
|
+
kind: 'resolve',
|
|
207
|
+
tx: tx.id,
|
|
208
|
+
name: `resolve ${token}`,
|
|
209
|
+
state: name,
|
|
210
|
+
time: null,
|
|
211
|
+
running: false,
|
|
212
|
+
fault: false,
|
|
213
|
+
note: 'untimed',
|
|
214
|
+
children: [],
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const span = spans.get(resolveKey(name, token));
|
|
218
|
+
|
|
219
|
+
return span ? spannedBar(bar, span, placing) : bar;
|
|
220
|
+
},
|
|
221
|
+
),
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const isRouterSpan = (span: SpanRecord): boolean =>
|
|
225
|
+
Object.keys(span.attributes ?? {}).some((key) => key.startsWith(ROUTER));
|
|
226
|
+
|
|
227
|
+
// The router spans that could be `tx`'s: its transition id, its ends, and a start within `START_TOLERANCE`.
|
|
228
|
+
const candidatesOf = (
|
|
229
|
+
tx: Tx,
|
|
230
|
+
spans: readonly SpanRecord[],
|
|
231
|
+
timeOrigin: number,
|
|
232
|
+
): SpanRecord[] =>
|
|
233
|
+
spans.filter(
|
|
234
|
+
({ attributes, startTime }) =>
|
|
235
|
+
attributes?.['uirouter.transition.id'] === tx.id &&
|
|
236
|
+
attributes['uirouter.transition.to'] === tx.to &&
|
|
237
|
+
attributes['uirouter.transition.from'] === tx.from &&
|
|
238
|
+
Math.abs(startTime - timeOrigin - tx.t) <= START_TOLERANCE,
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The router's span for `tx`, from `ui-router-otel`: its transition id, its ends, and a start within
|
|
243
|
+
* `START_TOLERANCE` of the recorded one. A transition id is unique per router only, so the ends and the start tell two
|
|
244
|
+
* routers, or a router created again, apart; when two spans still match, neither is used.
|
|
245
|
+
*/
|
|
246
|
+
export const transitionSpanOf = (
|
|
247
|
+
tx: Tx,
|
|
248
|
+
spans: readonly SpanRecord[],
|
|
249
|
+
timeOrigin: number,
|
|
250
|
+
): SpanRecord | undefined => {
|
|
251
|
+
const found = candidatesOf(tx, spans, timeOrigin);
|
|
252
|
+
|
|
253
|
+
return found.length === 1 ? found[0] : undefined;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
interface SpanIndex {
|
|
257
|
+
spans: readonly SpanRecord[];
|
|
258
|
+
byId: ReadonlyMap<string, SpanRecord>;
|
|
259
|
+
children: ReadonlyMap<string, SpanRecord[]>;
|
|
260
|
+
routerIds: ReadonlySet<string>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const indexSpans = (spans: readonly SpanRecord[]): SpanIndex => {
|
|
264
|
+
const children = new Map<string, SpanRecord[]>();
|
|
265
|
+
|
|
266
|
+
for (const span of spans)
|
|
267
|
+
if (span.parentSpanId)
|
|
268
|
+
children.set(span.parentSpanId, [
|
|
269
|
+
...(children.get(span.parentSpanId) ?? []),
|
|
270
|
+
span,
|
|
271
|
+
]);
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
spans,
|
|
275
|
+
byId: new Map(spans.map((span) => [span.spanId, span])),
|
|
276
|
+
children,
|
|
277
|
+
routerIds: new Set(
|
|
278
|
+
spans.flatMap((span) => (isRouterSpan(span) ? [span.spanId] : [])),
|
|
279
|
+
),
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
interface Placing {
|
|
284
|
+
timeOrigin: number;
|
|
285
|
+
clock: number;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const spanBar = (
|
|
289
|
+
index: SpanIndex,
|
|
290
|
+
span: SpanRecord,
|
|
291
|
+
tx: number,
|
|
292
|
+
placing: Placing,
|
|
293
|
+
seen: Set<string>,
|
|
294
|
+
): Bar => {
|
|
295
|
+
seen.add(span.spanId);
|
|
296
|
+
|
|
297
|
+
const children = (index.children.get(span.spanId) ?? [])
|
|
298
|
+
.filter((child) => !seen.has(child.spanId) && !isRouterSpan(child))
|
|
299
|
+
.map((child) => spanBar(index, child, tx, placing, seen))
|
|
300
|
+
.sort(byStart);
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
key: `${tx}:s${span.spanId}`,
|
|
304
|
+
kind: 'span',
|
|
305
|
+
tx,
|
|
306
|
+
name: span.name,
|
|
307
|
+
state: null,
|
|
308
|
+
time: spanWindow(span, placing.timeOrigin, placing.clock),
|
|
309
|
+
running: span.endTime === undefined,
|
|
310
|
+
fault: span.status === 'error',
|
|
311
|
+
note: null,
|
|
312
|
+
span,
|
|
313
|
+
children,
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// A router span and its phase, resolve and lazy load children.
|
|
318
|
+
const familyOf = (index: SpanIndex, span: SpanRecord): SpanRecord[] => [
|
|
319
|
+
span,
|
|
320
|
+
...(index.children.get(span.spanId) ?? []).filter(isRouterSpan),
|
|
321
|
+
];
|
|
322
|
+
|
|
323
|
+
const resolvesOf = (family: readonly SpanRecord[]) =>
|
|
324
|
+
new Map(
|
|
325
|
+
family.flatMap(({ attributes }, at) => {
|
|
326
|
+
const token = attributes?.['uirouter.resolve'];
|
|
327
|
+
const state = attributes?.['uirouter.state'];
|
|
328
|
+
|
|
329
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- attribute values are a union; the router writes these two as strings
|
|
330
|
+
return typeof token === 'string' && typeof state === 'string'
|
|
331
|
+
? [[resolveKey(state, token), family[at]] as const]
|
|
332
|
+
: [];
|
|
333
|
+
}),
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* For each transition in the chain: its router span, the ids of that span's family, and its resolve spans by state and
|
|
338
|
+
* token. When two router spans match a transition, neither is its; their families' ids are `ambiguous`.
|
|
339
|
+
*/
|
|
340
|
+
const routerSpansOf = (
|
|
341
|
+
chain: readonly Tx[],
|
|
342
|
+
index: SpanIndex,
|
|
343
|
+
timeOrigin: number,
|
|
344
|
+
) =>
|
|
345
|
+
chain.map((tx) => {
|
|
346
|
+
const found = candidatesOf(tx, index.spans, timeOrigin);
|
|
347
|
+
const span = found.length === 1 ? found[0] : undefined;
|
|
348
|
+
const family = span ? familyOf(index, span) : [];
|
|
349
|
+
|
|
350
|
+
const ambiguous =
|
|
351
|
+
found.length > 1
|
|
352
|
+
? found
|
|
353
|
+
.flatMap((each) => familyOf(index, each))
|
|
354
|
+
.map((each) => each.spanId)
|
|
355
|
+
: [];
|
|
356
|
+
|
|
357
|
+
return {
|
|
358
|
+
tx,
|
|
359
|
+
span,
|
|
360
|
+
ids: new Set(family.map((each) => each.spanId)),
|
|
361
|
+
ambiguous: new Set(ambiguous),
|
|
362
|
+
resolves: resolvesOf(family),
|
|
363
|
+
};
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// A span that is not the router's and whose parent is no such span either: the top of what is joined.
|
|
367
|
+
const foreignRoots = (index: SpanIndex): SpanRecord[] =>
|
|
368
|
+
index.spans.filter((span) => {
|
|
369
|
+
if (index.routerIds.has(span.spanId)) return false;
|
|
370
|
+
|
|
371
|
+
const parent = span.parentSpanId && index.byId.get(span.parentSpanId);
|
|
372
|
+
|
|
373
|
+
return !parent || index.routerIds.has(parent.spanId);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
interface Joined {
|
|
377
|
+
tx: Tx;
|
|
378
|
+
relation: Relation;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const overlaps = (
|
|
382
|
+
window: { start: number; end: number },
|
|
383
|
+
from: number,
|
|
384
|
+
to: number,
|
|
385
|
+
): boolean => window.start <= to && window.end >= from;
|
|
386
|
+
|
|
387
|
+
// The transition a span overlapping the chain is drawn under: the last to start before it, else the first.
|
|
388
|
+
const startedBefore = (chain: readonly Tx[], start: number): Tx =>
|
|
389
|
+
chain.findLast((tx) => tx.t <= start) ?? chain[0];
|
|
390
|
+
|
|
391
|
+
const joinOf = (
|
|
392
|
+
root: SpanRecord,
|
|
393
|
+
routers: ReturnType<typeof routerSpansOf>,
|
|
394
|
+
index: SpanIndex,
|
|
395
|
+
placing: Placing,
|
|
396
|
+
): Joined | null => {
|
|
397
|
+
const parent = root.parentSpanId;
|
|
398
|
+
const owner = parent && routers.find(({ ids }) => ids.has(parent));
|
|
399
|
+
|
|
400
|
+
if (owner) return { tx: owner.tx, relation: 'child' };
|
|
401
|
+
|
|
402
|
+
// A child of another transition's router span is that transition's; one whose router span is ambiguous is joined by time.
|
|
403
|
+
if (
|
|
404
|
+
parent &&
|
|
405
|
+
index.routerIds.has(parent) &&
|
|
406
|
+
!routers.some(({ ambiguous }) => ambiguous.has(parent))
|
|
407
|
+
)
|
|
408
|
+
return null;
|
|
409
|
+
|
|
410
|
+
const window = spanWindow(root, placing.timeOrigin, placing.clock);
|
|
411
|
+
const chain = routers.map(({ tx }) => tx);
|
|
412
|
+
|
|
413
|
+
const traced = routers.find(
|
|
414
|
+
({ tx, span }) =>
|
|
415
|
+
span?.traceId === root.traceId &&
|
|
416
|
+
overlaps(window, tx.t, endOf(tx, placing.clock)),
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
if (traced) return { tx: traced.tx, relation: 'trace' };
|
|
420
|
+
|
|
421
|
+
const first = chain[0];
|
|
422
|
+
const last = chain[chain.length - 1];
|
|
423
|
+
|
|
424
|
+
return overlaps(window, first.t, endOf(last, placing.clock))
|
|
425
|
+
? { tx: startedBefore(chain, window.start), relation: 'during' }
|
|
426
|
+
: null;
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
export interface JoinedSpans {
|
|
430
|
+
/** The spans drawn under each transition, keyed by transition id. */
|
|
431
|
+
bars: Map<number, Bar[]>;
|
|
432
|
+
/** Each transition's router resolve spans, keyed by state and token. */
|
|
433
|
+
resolves: Map<number, ReadonlyMap<string, SpanRecord>>;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** Joins spans to the transitions of `chain`: the ones drawn under each, and the router's resolve spans for each. */
|
|
437
|
+
export const joinSpans = (
|
|
438
|
+
chain: readonly Tx[],
|
|
439
|
+
spans: readonly SpanRecord[],
|
|
440
|
+
placing: Placing,
|
|
441
|
+
): JoinedSpans => {
|
|
442
|
+
const index = indexSpans(spans);
|
|
443
|
+
const routers = routerSpansOf(chain, index, placing.timeOrigin);
|
|
444
|
+
const bars = new Map<number, Bar[]>();
|
|
445
|
+
const seen = new Set<string>();
|
|
446
|
+
|
|
447
|
+
for (const root of foreignRoots(index)) {
|
|
448
|
+
const join = joinOf(root, routers, index, placing);
|
|
449
|
+
|
|
450
|
+
if (!join || seen.has(root.spanId)) continue;
|
|
451
|
+
|
|
452
|
+
const bar = {
|
|
453
|
+
...spanBar(index, root, join.tx.id, placing, seen),
|
|
454
|
+
relation: join.relation,
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
bars.set(join.tx.id, [...(bars.get(join.tx.id) ?? []), bar]);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return {
|
|
461
|
+
bars,
|
|
462
|
+
resolves: new Map(routers.map(({ tx, resolves }) => [tx.id, resolves])),
|
|
463
|
+
};
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const NO_SPANS: JoinedSpans = { bars: new Map(), resolves: new Map() };
|
|
467
|
+
|
|
468
|
+
// Recorded resolve events win over resolve spans: they are on the panel's own clock and know a cached resolve.
|
|
469
|
+
const resolveRows = (
|
|
470
|
+
input: WaterfallInput,
|
|
471
|
+
tx: Tx,
|
|
472
|
+
spans: JoinedSpans,
|
|
473
|
+
): Bar[] => {
|
|
474
|
+
if (input.timeResolves || tx.resolves.length) return resolveBars(tx);
|
|
475
|
+
|
|
476
|
+
return declaredBars(
|
|
477
|
+
tx,
|
|
478
|
+
input.states,
|
|
479
|
+
spans.resolves.get(tx.id) ?? new Map(),
|
|
480
|
+
input,
|
|
481
|
+
);
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
const transitionBar = (
|
|
485
|
+
input: WaterfallInput,
|
|
486
|
+
tx: Tx,
|
|
487
|
+
spans: JoinedSpans,
|
|
488
|
+
): Bar => {
|
|
489
|
+
const { clock } = input;
|
|
490
|
+
const status: Status = tx.result?.outcome ?? 'running';
|
|
491
|
+
|
|
492
|
+
return {
|
|
493
|
+
key: `${tx.id}`,
|
|
494
|
+
kind: 'transition',
|
|
495
|
+
tx: tx.id,
|
|
496
|
+
name: tx.to || '(root)',
|
|
497
|
+
state: tx.to,
|
|
498
|
+
time: { start: tx.t, end: endOf(tx, clock) },
|
|
499
|
+
running: !tx.result,
|
|
500
|
+
fault: status === 'error' || status === 'invalid',
|
|
501
|
+
note: txNote(tx),
|
|
502
|
+
status,
|
|
503
|
+
children: [
|
|
504
|
+
...phaseBars(tx, clock),
|
|
505
|
+
...resolveRows(input, tx, spans),
|
|
506
|
+
...(spans.bars.get(tx.id) ?? []),
|
|
507
|
+
].sort(byStart),
|
|
508
|
+
};
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// Every timed bar's window, children included.
|
|
512
|
+
const windows = (bars: readonly Bar[]): SpanWindow[] =>
|
|
513
|
+
bars.flatMap((bar) => [
|
|
514
|
+
...(bar.time ? [bar.time] : []),
|
|
515
|
+
...windows(bar.children),
|
|
516
|
+
]);
|
|
517
|
+
|
|
518
|
+
/** Lays out `tx` and its redirect chain on one axis, which starts at the earliest bar and ends at the latest. */
|
|
519
|
+
export const waterfall = (input: WaterfallInput): Waterfall => {
|
|
520
|
+
const chain = chainOf(input.txs, input.tx);
|
|
521
|
+
|
|
522
|
+
const spans = input.spans.length
|
|
523
|
+
? joinSpans(chain, input.spans, input)
|
|
524
|
+
: NO_SPANS;
|
|
525
|
+
|
|
526
|
+
const roots = chain.map((tx) => transitionBar(input, tx, spans));
|
|
527
|
+
|
|
528
|
+
const timed = windows(roots);
|
|
529
|
+
const zero = Math.min(...timed.map((time) => time.start));
|
|
530
|
+
const end = Math.max(...timed.map((time) => time.end));
|
|
531
|
+
|
|
532
|
+
return { roots, zero, length: Math.max(end - zero, 0.1) };
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const STEPS = [1, 2, 2.5, 5];
|
|
536
|
+
|
|
537
|
+
/** Gridline offsets for an axis `length` long: a 1, 2, 2.5 or 5 step that gives at most `most` lines past zero. */
|
|
538
|
+
export const ticks = (length: number, most = 5): number[] => {
|
|
539
|
+
const raw = length / most;
|
|
540
|
+
const power = 10 ** Math.floor(Math.log10(raw));
|
|
541
|
+
const step = (STEPS.find((each) => each * power >= raw) ?? 10) * power;
|
|
542
|
+
|
|
543
|
+
return Array.from(
|
|
544
|
+
{ length: Math.floor(length / step + 1e-9) + 1 },
|
|
545
|
+
// Rounded, so a tenth of a millisecond times three reads 0.3.
|
|
546
|
+
(_, index) => Number((index * step).toPrecision(12)),
|
|
547
|
+
);
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
export interface WaterfallRow {
|
|
551
|
+
bar: Bar;
|
|
552
|
+
level: number;
|
|
553
|
+
setsize: number;
|
|
554
|
+
posinset: number;
|
|
555
|
+
parent: string | null;
|
|
556
|
+
expanded: boolean | null;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** The rows a tree of bars shows, depth first, with the children of a collapsed bar left out. */
|
|
560
|
+
export const rowsOf = (
|
|
561
|
+
roots: readonly Bar[],
|
|
562
|
+
collapsed: ReadonlySet<string>,
|
|
563
|
+
): WaterfallRow[] => {
|
|
564
|
+
const rows: WaterfallRow[] = [];
|
|
565
|
+
|
|
566
|
+
const walk = (bars: readonly Bar[], level: number, parent: string | null) =>
|
|
567
|
+
bars.forEach((bar, index) => {
|
|
568
|
+
const open = bar.children.length > 0 && !collapsed.has(bar.key);
|
|
569
|
+
|
|
570
|
+
rows.push({
|
|
571
|
+
bar,
|
|
572
|
+
level,
|
|
573
|
+
setsize: bars.length,
|
|
574
|
+
posinset: index + 1,
|
|
575
|
+
parent,
|
|
576
|
+
expanded: bar.children.length ? open : null,
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
if (open) walk(bar.children, level + 1, bar.key);
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
walk(roots, 1, null);
|
|
583
|
+
|
|
584
|
+
return rows;
|
|
585
|
+
};
|