@venizia/vulcan 0.4.4 → 0.4.6
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.md +1 -1
- package/README.md +13 -0
- package/base/agents.json +22 -1
- package/base/checks/wiki-anchors.ts +8 -0
- package/base/checks/wiki-source-links.ts +8 -0
- package/base/claude/remote-hosts.json +1 -1
- package/base/claude/settings.json +12 -12
- package/base/extensions/vulcan-guards.ts +301 -0
- package/base/hooks/antigravity-guards.ts +68 -0
- package/base/hooks/codex-guards.ts +66 -0
- package/base/hooks/guard-git.ts +38 -9
- package/base/hooks/guard-outside.ts +29 -9
- package/base/hooks/guard-writes.ts +29 -1
- package/base/hooks/session-start.ts +14 -4
- package/base/make/vulcan.mk +12 -1
- package/base/references/delegation-brief.md +5 -4
- package/base/rules.md +2 -2
- package/base/skills/docs-writing/SKILL.md +1 -1
- package/base/skills/docs-writing/references/agent-documents.md +1 -1
- package/base/skills/knowledge-sync/SKILL.md +1 -1
- package/base/skills/plan-a-change/SKILL.md +1 -1
- package/base/skills/report-back/SKILL.md +1 -1
- package/base/skills/retro/SKILL.md +1 -1
- package/base/skills/review-a-change/SKILL.md +1 -1
- package/base/skills/ship/SKILL.md +1 -1
- package/base/skills/visualize-work/SKILL.md +33 -11
- package/base/skills/visualize-work/references/spec.md +77 -12
- package/package.json +4 -4
- package/src/agents/codex-hooks.ts +133 -0
- package/src/agents/common/constants.ts +54 -0
- package/src/agents/common/schema.ts +10 -1
- package/src/agents/common/types.ts +3 -1
- package/src/agents/exclude.ts +4 -0
- package/src/agents/hooks-json.ts +111 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/render.ts +5 -4
- package/src/agents/resolve.ts +24 -9
- package/src/config/common/constants.ts +12 -0
- package/src/config/common/types.ts +2 -1
- package/src/config/packages.ts +2 -1
- package/src/config/schema.ts +84 -5
- package/src/create/add-app.ts +2 -2
- package/src/create/add-lib.ts +21 -8
- package/src/create/common/constants.ts +12 -0
- package/src/create/common/types.ts +2 -1
- package/src/create/preset-diff.ts +4 -2
- package/src/create/workspace.ts +13 -9
- package/src/doctor/checks.ts +71 -1
- package/src/doctor/common/constants.ts +2 -0
- package/src/doctor/runner.ts +6 -0
- package/src/hooks/codex-patch.ts +47 -0
- package/src/hooks/command-view.ts +97 -0
- package/src/hooks/common/constants.ts +46 -0
- package/src/hooks/common/types.ts +9 -1
- package/src/hooks/decision.ts +50 -8
- package/src/hooks/guard-git.ts +64 -5
- package/src/hooks/guard-manifest.ts +22 -8
- package/src/hooks/guard-outside.ts +38 -6
- package/src/hooks/guard-package.ts +15 -12
- package/src/hooks/guard-writes.ts +72 -21
- package/src/hooks/index.ts +5 -0
- package/src/hooks/project-guards.ts +123 -0
- package/src/hooks/project-tmp.ts +36 -0
- package/src/hooks/remote-hosts.ts +38 -14
- package/src/hooks/session-digest.ts +5 -0
- package/src/hooks/shell.ts +665 -35
- package/src/hooks/trusted-scripts.ts +134 -0
- package/src/manifest/render.ts +38 -0
- package/src/sync/agent-files.ts +122 -4
- package/src/sync/agent-removal.ts +118 -4
- package/src/sync/claude-launch.ts +48 -0
- package/src/sync/index.ts +1 -0
- package/src/sync/local-choice.ts +2 -0
- package/src/visualize/assets.ts +195 -54
- package/src/visualize/charts.ts +235 -0
- package/src/visualize/constants.ts +122 -1
- package/src/visualize/diagrams.ts +224 -0
- package/src/visualize/icons.ts +28 -0
- package/src/visualize/layout.ts +58 -8
- package/src/visualize/page.ts +151 -145
- package/src/visualize/schema.ts +252 -2
- package/src/visualize/sections.ts +370 -0
- package/src/visualize/validate.ts +100 -7
- package/src/wiki/anchors.ts +118 -0
- package/src/wiki/command.ts +110 -0
- package/src/wiki/constants.ts +30 -0
- package/src/wiki/index.ts +4 -0
- package/src/wiki/source-links.ts +186 -0
package/src/visualize/assets.ts
CHANGED
|
@@ -1,64 +1,205 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/** Light and dark palettes: neutral ink, one bronze accent, semantic states with tints, five series colours for charts. */
|
|
2
|
+
const LIGHT =
|
|
3
|
+
'--bg:#f4f4f4;--surface:#fff;--surface2:#ececec;--fg:#15161a;--mut:#585d66;--line:#dedede;--acc:#98681a;--acc-bg:#f6ecd9;--ok:#157a3a;--ok-bg:#e4f3e8;--warn:#9c5a06;--warn-bg:#fcefd8;--bad:#bd2820;--bad-bg:#fbe8e6;--info:#1c5ccc;--info-bg:#e6edfb;--s1:#2a78d6;--s2:#eb6834;--s3:#1baf7a;--s4:#eda100;--s5:#e87ba4;--shadow:0 1px 2px rgba(20,22,30,.06);color-scheme:light';
|
|
4
|
+
const DARK =
|
|
5
|
+
'--bg:#0e0f12;--surface:#17191e;--surface2:#1d2026;--fg:#eeeef0;--mut:#a2a6af;--line:#2a2d35;--acc:#e0b366;--acc-bg:#2b2314;--ok:#5fd18a;--ok-bg:#13261b;--warn:#f0b955;--warn-bg:#2b2212;--bad:#ff8a80;--bad-bg:#2d1816;--info:#7ab0ff;--info-bg:#14213a;--s1:#3987e5;--s2:#d95926;--s3:#199e70;--s4:#c98500;--s5:#d55181;--shadow:0 1px 2px rgba(0,0,0,.4);color-scheme:dark';
|
|
6
|
+
|
|
7
|
+
/** The page's stylesheet: light and dark by variables, system fonts, no image, final state in print and under reduced motion. */
|
|
8
|
+
export const PAGE_CSS = `:root{${LIGHT};--sans:ui-sans-serif,system-ui,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;--serif:ui-serif,"Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;--mono:ui-monospace,"SF Mono","JetBrains Mono",Menlo,Consolas,monospace}
|
|
9
|
+
@media (prefers-color-scheme:dark){:root:not([data-theme=light]){${DARK}}}
|
|
10
|
+
:root[data-theme=dark]{${DARK}}
|
|
5
11
|
*{box-sizing:border-box}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.
|
|
12
|
-
.
|
|
13
|
-
.chip
|
|
14
|
-
.
|
|
15
|
-
.
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
button{font:
|
|
19
|
-
button:
|
|
20
|
-
.
|
|
21
|
-
.
|
|
22
|
-
.
|
|
23
|
-
.
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
.
|
|
12
|
+
html{-webkit-text-size-adjust:100%}
|
|
13
|
+
body{margin:0;background:var(--bg);color:var(--fg);font:16px/1.55 var(--sans);font-variant-numeric:tabular-nums;-webkit-font-smoothing:antialiased}
|
|
14
|
+
h1,h2,h3,p,ol,ul,figure,blockquote{margin:0}
|
|
15
|
+
ol,ul{padding:0;list-style:none}
|
|
16
|
+
a{color:inherit;text-underline-offset:3px}
|
|
17
|
+
.ic{flex:none;display:inline-block;vertical-align:middle}
|
|
18
|
+
.c-ok{--c:var(--ok);--cb:var(--ok-bg)}.c-warn{--c:var(--warn);--cb:var(--warn-bg)}.c-bad{--c:var(--bad);--cb:var(--bad-bg)}.c-info{--c:var(--info);--cb:var(--info-bg)}.c-mut{--c:var(--mut);--cb:var(--surface2)}
|
|
19
|
+
.chip{display:inline-flex;align-items:center;gap:6px;color:var(--c);font:600 .8125rem/1.2 var(--mono);text-transform:uppercase;letter-spacing:.05em}
|
|
20
|
+
.lab{font:600 .8125rem/1.3 var(--mono);text-transform:uppercase;letter-spacing:.08em;color:var(--mut)}
|
|
21
|
+
.mut{color:var(--mut)}.inl{display:inline-flex;margin-right:6px;color:var(--c)}
|
|
22
|
+
.vh{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
23
|
+
:focus-visible{outline:2px solid var(--acc);outline-offset:2px}
|
|
24
|
+
button{font:500 .8125rem/1.3 var(--mono);letter-spacing:.04em;color:var(--fg);background:transparent;border:1px solid var(--line);border-radius:4px;padding:5px 10px;cursor:pointer}
|
|
25
|
+
button:hover{border-color:var(--fg)}
|
|
26
|
+
.wrap{max-width:1240px;margin:0 auto;padding:16px 20px 72px}
|
|
27
|
+
.tools{display:flex;justify-content:flex-end;gap:8px;margin-bottom:14px}
|
|
28
|
+
.mini{position:sticky;top:0;z-index:20;display:flex;align-items:center;gap:12px;padding:0 20px;background:var(--bg);border-bottom:1px solid transparent;opacity:0;pointer-events:none;height:0;overflow:hidden;transition:opacity .2s}
|
|
29
|
+
.mini.on{opacity:1;pointer-events:auto;height:auto;padding:8px 20px;border-bottom-color:var(--line)}
|
|
30
|
+
.mini b{font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0;font-size:.9375rem}
|
|
31
|
+
.banner{display:grid;grid-template-columns:auto 1fr;gap:28px;align-items:center;padding:30px 32px;border-radius:4px;background:var(--cb);border:1px solid color-mix(in srgb,var(--c) 40%,var(--surface));box-shadow:var(--shadow)}
|
|
32
|
+
.b-ic{color:var(--c);display:grid;place-items:center;width:84px;height:84px;border-radius:4px;background:var(--surface)}
|
|
33
|
+
.b-ic .ic{width:52px;height:52px}
|
|
34
|
+
.meta{display:flex;flex-wrap:wrap;gap:2px 16px;font:500 .8125rem/1.4 var(--mono);color:var(--mut);letter-spacing:.03em}
|
|
35
|
+
.word{font:800 clamp(1.8rem,1.2rem + 2.6vw,3rem)/1 var(--sans);letter-spacing:-.02em;text-transform:uppercase;color:var(--c);margin:10px 0 8px}
|
|
36
|
+
h1{font-size:clamp(1.3rem,1.1rem + .8vw,1.6rem);line-height:1.25;font-weight:650;max-width:62ch}
|
|
37
|
+
.verdict{margin-top:8px;font-size:1.05rem;max-width:62ch}
|
|
38
|
+
.cap{margin-top:6px;color:var(--mut);max-width:62ch}
|
|
39
|
+
.sec{margin-top:40px}
|
|
40
|
+
.sec>h2.lab{margin-bottom:14px}
|
|
41
|
+
.tiles{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px;margin-top:20px}
|
|
42
|
+
.tile{padding:18px;border-radius:4px;background:var(--surface);box-shadow:var(--shadow);position:relative;display:grid;gap:8px}
|
|
43
|
+
.tile .n{font:750 2.4rem/1 var(--sans);letter-spacing:-.03em;font-variant-numeric:tabular-nums}
|
|
44
|
+
.tile .l{color:var(--mut);font-size:.9375rem}
|
|
45
|
+
.tile .ic{position:absolute;top:16px;right:16px;color:var(--c)}
|
|
46
|
+
.strip{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(0,1fr);gap:6px}
|
|
47
|
+
.seg{display:grid;gap:8px;align-content:start}
|
|
48
|
+
.seg .bar{height:10px;border-radius:4px;background:var(--c)}
|
|
49
|
+
.seg.c-mut .bar{background:repeating-linear-gradient(135deg,var(--line) 0 5px,transparent 5px 10px);border:1px solid var(--line)}
|
|
50
|
+
.seg .nm{display:grid;gap:3px;font-size:.9375rem;line-height:1.3}.seg .tn{font-weight:600}
|
|
51
|
+
.seg .nt{color:var(--mut);font-size:.875rem;line-height:1.35}
|
|
52
|
+
.two{display:grid;grid-template-columns:minmax(0,3fr) minmax(0,2fr);gap:12px;margin-top:28px;align-items:start}
|
|
53
|
+
.card{padding:22px;border-radius:4px;background:var(--surface);box-shadow:var(--shadow)}
|
|
54
|
+
.action{background:var(--fg);color:var(--surface);box-shadow:none}
|
|
55
|
+
.action .lab{color:var(--surface);opacity:.7}
|
|
56
|
+
.action h2{font-size:clamp(1.15rem,1.05rem + .5vw,1.4rem);line-height:1.3;margin:6px 0 14px}
|
|
57
|
+
.check{display:grid;gap:10px;counter-reset:s}
|
|
58
|
+
.check li{counter-increment:s;display:grid;grid-template-columns:34px 1fr;gap:12px;align-items:center;padding:12px 14px;border-radius:4px;background:color-mix(in srgb,var(--surface) 14%,transparent);font-weight:550}
|
|
59
|
+
.check li::before{content:counter(s);display:grid;place-items:center;width:34px;height:34px;border-radius:4px;background:var(--surface);color:var(--fg);font:750 1rem var(--mono)}
|
|
60
|
+
.jump{display:inline-block;margin-top:14px;color:inherit;font:600 .8125rem/1.3 var(--mono);letter-spacing:.04em}
|
|
61
|
+
.blocked .bb{display:flex;gap:10px;margin:8px 0 14px;font-weight:550}
|
|
62
|
+
.blocked .bb .ic{color:var(--warn);margin-top:3px}
|
|
63
|
+
.ok-line{display:flex;gap:10px;padding-top:12px;margin-top:12px;border-top:1px solid var(--line);color:var(--mut);font-size:.9375rem}
|
|
64
|
+
.ok-line .ic{margin-top:3px}.ok-line b{color:var(--fg);font-weight:600}
|
|
65
|
+
.fig{background:var(--surface);border:1px solid var(--line);border-radius:4px;padding:12px;overflow-x:auto;box-shadow:var(--shadow)}
|
|
66
|
+
.fig svg{display:block;max-width:100%;height:auto;color:var(--mut)}
|
|
67
|
+
.node rect{fill:var(--surface);stroke:var(--c,var(--fg));stroke-width:1.5}
|
|
68
|
+
.node .t{font:600 15px var(--sans);fill:var(--fg)}.node .s{font:13px var(--mono);fill:var(--mut)}.node .st{color:var(--c)}
|
|
69
|
+
.node.service rect{stroke-width:3}.node.store rect{stroke-dasharray:2 3;stroke-width:2.25}.node.actor rect{rx:30}.node.external rect{stroke-dasharray:8 4}
|
|
70
|
+
.edge path{fill:none;stroke:currentColor;stroke-width:1.6}.edge text{font:13px var(--mono);fill:var(--fg);paint-order:stroke;stroke:var(--surface);stroke-width:5px}
|
|
71
|
+
.edge.branch path,.edge.return path{stroke-dasharray:7 5}.edge.fanout path{stroke-width:2.6}.edge.error{color:var(--bad)}.edge.error path{stroke:var(--bad);stroke-dasharray:2 4}marker .bad{fill:var(--bad)}
|
|
33
72
|
.flow .edge path{stroke-dasharray:6 6;animation:dash 1s linear infinite}
|
|
34
73
|
@keyframes dash{to{stroke-dashoffset:-12}}
|
|
35
74
|
.focus .node:not(.on),.focus .edge:not(.on){opacity:.22}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.
|
|
39
|
-
.
|
|
40
|
-
.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
.
|
|
75
|
+
.node:focus-visible{outline:2px solid var(--acc);outline-offset:2px}
|
|
76
|
+
.dbox rect{fill:var(--surface);stroke:var(--c,var(--fg));stroke-width:1.5}.dbox .t{font:600 14px var(--sans);fill:var(--fg)}.dbox .s{font:12.5px var(--mono);fill:var(--mut)}.dbox .st{color:var(--c)}
|
|
77
|
+
.dline{stroke:var(--mut);stroke-width:1.6;fill:none}.dl{font:12.5px var(--mono);fill:var(--fg);paint-order:stroke;stroke:var(--surface);stroke-width:4px}
|
|
78
|
+
.dband{fill:var(--surface2)}.dlab{font:600 13px var(--mono);fill:var(--mut);text-transform:uppercase}
|
|
79
|
+
.bar{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin:12px 0 0}
|
|
80
|
+
#detail,#stepnote{min-height:1.5em;margin:10px 0 0;color:var(--mut)}
|
|
81
|
+
#stepnote{color:var(--fg);font-weight:600}
|
|
82
|
+
.legend{display:flex;flex-wrap:wrap;gap:6px 18px;margin-top:12px;color:var(--mut);font:.8125rem/1.4 var(--mono)}
|
|
83
|
+
.steps-note{margin:14px 0 0;padding-left:24px;max-width:70ch;list-style:decimal}
|
|
84
|
+
.path{display:none;margin:0;padding:0}
|
|
85
|
+
.path li{display:flex;flex-wrap:wrap;align-items:center;gap:8px;border-top:1px solid var(--line);padding:10px 0}.path li:first-child{border-top:0}
|
|
86
|
+
.path b{font-weight:600}
|
|
87
|
+
.verb{display:inline-block;border:1px solid var(--line);border-radius:4px;padding:0 8px;font:.8125rem/1.6 var(--mono);color:var(--mut)}.verb.error{color:var(--bad);border-color:var(--bad)}.verb.branch,.verb.return{border-style:dashed}
|
|
88
|
+
.path-detail{display:none;margin-top:12px}.path-detail li{border-top:1px solid var(--line);padding:10px 0}.path-detail b{display:block}
|
|
89
|
+
.opts{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px;margin-top:14px;align-items:start}
|
|
90
|
+
.opts.n2{grid-template-columns:repeat(2,minmax(0,1fr))}.opts.n4,.opts.n6{grid-template-columns:repeat(4,minmax(0,1fr))}.opts.n5{grid-template-columns:repeat(3,minmax(0,1fr))}
|
|
91
|
+
.opt{padding:22px 20px;border-radius:4px;background:var(--surface);box-shadow:var(--shadow);display:grid;gap:12px;align-content:start;position:relative}
|
|
92
|
+
.opt.rec{background:var(--acc-bg);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--acc) 45%,var(--surface))}
|
|
93
|
+
.opt .tag{position:absolute;top:-12px;left:16px;background:var(--acc);color:var(--surface);padding:3px 10px;border-radius:4px;font:700 .8125rem var(--mono);letter-spacing:.06em;text-transform:uppercase}
|
|
94
|
+
.opt h3{font-size:1.15rem;line-height:1.3}.opt .ln{color:var(--mut)}
|
|
95
|
+
.opt .tot{font:750 1.9rem/1 var(--sans);font-variant-numeric:tabular-nums}.opt .tot small{font:500 .875rem var(--sans);color:var(--mut)}
|
|
96
|
+
.crit{display:grid;gap:7px}.crit div{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px;align-items:center;font-size:.9rem}
|
|
97
|
+
.dots{display:inline-flex;gap:3px}.dots i{width:14px;height:8px;border-radius:2px;background:var(--surface2);border:1px solid var(--line)}.dots i.on{background:var(--mut);border-color:var(--mut)}
|
|
98
|
+
.opt.rec .dots i.on{background:var(--acc);border-color:var(--acc)}
|
|
99
|
+
.pc{display:grid;gap:6px}.pc li{display:flex;gap:8px;font-size:.9375rem}.pc .ic{margin-top:3px}.pc .p .ic{color:var(--ok)}.pc .c .ic{color:var(--bad)}
|
|
100
|
+
.note{margin-top:14px;display:flex;gap:8px;color:var(--mut);font-size:.9rem}.note .ic{margin-top:3px}
|
|
101
|
+
.chart.card{padding:18px 20px;max-width:520px}
|
|
102
|
+
svg .ct{font:13px var(--sans);fill:var(--fg)}svg .ct.strong{font-weight:700}svg .cv{font:600 13px var(--mono);fill:var(--fg)}
|
|
103
|
+
svg .ctrack{fill:var(--surface2)}svg .cgrid{stroke:var(--line);stroke-width:1}svg .cring{stroke:var(--surface);stroke-width:2}
|
|
104
|
+
svg .cbig{font:750 22px var(--sans);fill:var(--fg)}
|
|
105
|
+
.charts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;margin-top:14px}
|
|
106
|
+
figure.chart{background:var(--surface);border-radius:4px;box-shadow:var(--shadow);padding:18px 20px;display:grid;gap:12px;align-content:start}
|
|
107
|
+
figure.chart{align-self:start}
|
|
108
|
+
figure.chart svg{display:block;width:100%;max-width:380px;height:auto}
|
|
109
|
+
figure.chart.donut .cbody{display:flex;flex-wrap:wrap;gap:16px;align-items:center}figure.chart.donut svg{max-width:150px;flex:none}
|
|
110
|
+
.clegend{display:grid;gap:6px;min-width:0;flex:1 1 150px}.clegend li{display:grid;grid-template-columns:14px minmax(0,1fr) auto auto;gap:8px;align-items:center;font-size:.9rem}.clegend.row{display:flex;flex-wrap:wrap;gap:6px 16px}.clegend.row li{display:flex}
|
|
111
|
+
.clegend em{color:var(--mut);font-style:normal;font:.8125rem var(--mono)}.clegend b{font:600 .875rem var(--mono)}
|
|
112
|
+
.sw{width:12px;height:12px;border-radius:3px;background:var(--mut);display:inline-block}
|
|
113
|
+
.sw[data-s="1"]{background:var(--s1)}.sw[data-s="2"]{background:var(--s2)}.sw[data-s="3"]{background:var(--s3)}.sw[data-s="4"]{background:var(--s4)}.sw[data-s="5"]{background:var(--s5)}
|
|
114
|
+
.sw[data-t=ok]{background:var(--ok)}.sw[data-t=warn]{background:var(--warn)}.sw[data-t=bad]{background:var(--bad)}.sw[data-t=info]{background:var(--info)}.sw[data-t=mut]{background:var(--mut)}
|
|
115
|
+
.tv summary{cursor:pointer;font:600 .8125rem var(--mono);letter-spacing:.06em;text-transform:uppercase;color:var(--mut)}.tv .tw{margin-top:8px}
|
|
116
|
+
.callouts{display:grid;gap:10px;margin-top:14px}.callout{display:flex;gap:12px;padding:14px 18px;border-radius:4px;background:var(--cb)}.callout .ic{color:var(--c);margin-top:2px}
|
|
117
|
+
.steps{display:grid;gap:0;position:relative}
|
|
118
|
+
.estep{display:grid;grid-template-columns:44px minmax(0,1fr) minmax(0,1.1fr);gap:4px 22px;padding:0 0 30px;position:relative}
|
|
119
|
+
.estep::before{content:"";position:absolute;left:16px;top:36px;bottom:0;width:2px;background:var(--line)}.estep:last-child::before{display:none}
|
|
120
|
+
.estep .no{display:grid;place-items:center;width:34px;height:34px;border-radius:4px;background:var(--fg);color:var(--surface);font:750 1rem var(--mono)}
|
|
121
|
+
.estep h3{font-size:1.2rem;line-height:1.3}.estep .sb p{color:var(--mut);margin-top:6px;max-width:48ch}
|
|
122
|
+
.estep .dg .fig{box-shadow:none}
|
|
123
|
+
.idea{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,.7fr) minmax(0,1fr);gap:20px;align-items:center}
|
|
124
|
+
.idea .side{display:grid;gap:14px}.centre{display:grid;gap:8px;justify-items:center;text-align:center;padding:26px 18px;border-radius:4px;border:1px solid color-mix(in srgb,var(--acc) 45%,var(--surface));background:var(--acc-bg);color:var(--acc)}.centre b{color:var(--fg);font-size:1.25rem;line-height:1.25}
|
|
125
|
+
.branch{padding:16px 18px;border-radius:4px;background:var(--surface);box-shadow:var(--shadow);display:grid;gap:10px;position:relative}
|
|
126
|
+
.branch h3{display:flex;gap:8px;align-items:center;font-size:1rem}
|
|
127
|
+
.chips{display:flex;flex-wrap:wrap;gap:6px}.chips li{padding:3px 10px;border-radius:4px;background:var(--surface2);font-size:.9rem}
|
|
128
|
+
.tl{position:relative;display:grid;gap:22px;padding-left:36px}
|
|
129
|
+
.tl::before{content:"";position:absolute;left:11px;top:6px;bottom:6px;width:2px;background:var(--line)}
|
|
130
|
+
.tl li{position:relative;display:grid;gap:2px}
|
|
131
|
+
.tl .dot{position:absolute;left:-36px;top:0;display:grid;place-items:center;width:24px;height:24px;border-radius:50%;background:var(--bg);color:var(--c);border:2px solid var(--c)}
|
|
132
|
+
.tl .dot .ic{width:14px;height:14px}.tl li.c-mut .dot{border-style:dashed}
|
|
133
|
+
.tl time{font:600 .8125rem var(--mono);letter-spacing:.06em;color:var(--mut)}.tl h3{font-size:1.05rem}.tl p{color:var(--mut);max-width:60ch}
|
|
134
|
+
.diff{display:grid;grid-template-columns:1fr 1fr;gap:12px}
|
|
135
|
+
.diff section{border:1px solid var(--line);border-radius:4px;background:var(--surface);overflow:hidden}
|
|
136
|
+
.diff h3{padding:10px 14px;font:600 .8125rem/1.3 var(--mono);text-transform:uppercase;letter-spacing:.08em;color:var(--mut);border-bottom:1px solid var(--line)}
|
|
137
|
+
.diff li{display:flex;gap:10px;padding:9px 14px;border-top:1px solid var(--line)}.diff li:first-child{border-top:0}
|
|
138
|
+
.diff li.add{background:var(--ok-bg)}.diff li.del{background:var(--bad-bg)}
|
|
139
|
+
.diff li .ic{margin-top:3px}.diff li.add .ic{color:var(--ok)}.diff li.del .ic{color:var(--bad)}.diff li.same .ic{opacity:0}
|
|
140
|
+
.dr{display:grid;gap:12px}.dr .ctx{max-width:70ch;font-size:1.05rem}
|
|
141
|
+
.pull{margin:14px 0;padding:26px 0;border-top:1px solid var(--line);border-bottom:1px solid var(--line)}
|
|
142
|
+
.pull .ic{color:var(--acc);width:36px;height:36px}.pull .lab{color:var(--acc);margin:8px 0}
|
|
143
|
+
.pull .big{font:italic 500 clamp(1.4rem,1.15rem + 1.2vw,2rem)/1.3 var(--serif);max-width:34em}
|
|
144
|
+
.cons{display:grid;gap:8px}.cons li{display:flex;gap:10px}.cons .ic{color:var(--ok);margin-top:3px}
|
|
145
|
+
.dec{display:grid;gap:12px}
|
|
146
|
+
.dec li{display:grid;grid-template-columns:minmax(0,1.25fr) minmax(0,1fr);gap:6px 28px;align-items:start;padding:18px;border-radius:4px;background:var(--surface);box-shadow:var(--shadow)}
|
|
147
|
+
.dec .q{grid-column:1;font-size:1.1rem;line-height:1.4;font-weight:600}
|
|
148
|
+
.dec .rec{grid-column:2;grid-row:1 / span 2;padding:10px 14px;background:var(--acc-bg);border-radius:4px}.dec .rec .lab{color:var(--acc)}.dec .rec p{margin-top:4px;font-weight:500}
|
|
149
|
+
.dec .chg{grid-column:1;color:var(--mut);font-size:.9375rem}.dec .chg .lab{margin-right:8px}
|
|
150
|
+
.evs{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px}
|
|
151
|
+
.ev{padding:16px 18px;border-radius:4px;background:var(--surface);box-shadow:var(--shadow);display:grid;gap:10px;align-content:start}
|
|
152
|
+
.ev b{font-weight:600;line-height:1.35}.ev .pr{color:var(--mut);font-size:.875rem}.ev .rs{font:600 .9375rem var(--mono)}
|
|
153
|
+
.badge{display:inline-flex;align-items:center;gap:6px;justify-self:start;border-radius:4px;padding:3px 9px;background:var(--cb);color:var(--c);font:600 .8125rem/1.3 var(--mono);letter-spacing:.03em}
|
|
154
|
+
.ev-verified{--c:var(--ok);--cb:var(--ok-bg)}.ev-inferred{--c:var(--warn);--cb:var(--warn-bg)}.ev-guess{--c:var(--mut);--cb:var(--surface2)}
|
|
44
155
|
.tw{overflow-x:auto}
|
|
45
|
-
table{border-collapse:collapse;width:100
|
|
46
|
-
th
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.
|
|
52
|
-
|
|
53
|
-
|
|
156
|
+
table{border-collapse:collapse;width:100%}
|
|
157
|
+
th{font:600 .8125rem/1.3 var(--mono);text-transform:uppercase;letter-spacing:.08em;color:var(--mut);text-align:left;padding:0 14px 8px 0;border-bottom:1px solid var(--fg)}
|
|
158
|
+
td{text-align:left;vertical-align:top;border-top:1px solid var(--line);padding:11px 14px 11px 0}
|
|
159
|
+
tbody tr:first-child td{border-top:0}
|
|
160
|
+
.log{background:var(--surface);border-radius:4px;box-shadow:var(--shadow)}
|
|
161
|
+
.log li{display:grid;grid-template-columns:110px 1fr;gap:14px;padding:12px 18px;border-top:1px solid var(--line)}.log li:first-child{border-top:0}.log time{font:600 .8125rem var(--mono);color:var(--mut);padding-top:2px}
|
|
162
|
+
.links{display:grid;gap:6px}
|
|
163
|
+
footer{margin-top:48px;padding-top:16px;border-top:1px solid var(--line);font:.8125rem/1.5 var(--mono);color:var(--mut)}
|
|
164
|
+
.deck{display:none}
|
|
165
|
+
html.present{font-size:1.15em}
|
|
166
|
+
html.present [data-slide]{display:none}
|
|
167
|
+
html.present [data-slide].cur{display:block;min-height:calc(100vh - 140px)}
|
|
168
|
+
html.present .banner.cur{display:grid;align-content:center}
|
|
169
|
+
html.present .mini,html.present footer,html.present .two:not(.cur){display:none}
|
|
170
|
+
html.present .deck{display:flex;position:fixed;left:0;right:0;bottom:0;z-index:30;gap:12px;align-items:center;justify-content:center;padding:10px;background:var(--bg);border-top:1px solid var(--line)}
|
|
171
|
+
html.present .deck span{font:600 .875rem var(--mono);color:var(--mut)}
|
|
172
|
+
@media (max-width:860px){.tiles{grid-template-columns:repeat(2,minmax(0,1fr))}.two,.charts,.evs,.opts,.opts.n2,.opts.n4,.opts.n5,.opts.n6{grid-template-columns:1fr}.banner{grid-template-columns:1fr;padding:22px;gap:14px}.b-ic{width:60px;height:60px}.b-ic .ic{width:38px;height:38px}
|
|
173
|
+
.strip{grid-auto-flow:row;gap:0}.seg{grid-template-columns:8px minmax(0,1fr);column-gap:14px;padding:10px 0;border-top:1px solid var(--line)}.seg:first-child{border-top:0}.seg .bar{grid-row:1 / span 2;height:100%;min-height:36px;width:6px;justify-self:center}
|
|
174
|
+
.log li{grid-template-columns:1fr;gap:2px}.dec li{display:block}.dec .rec{margin-top:12px}.diff{grid-template-columns:1fr}.estep{grid-template-columns:44px minmax(0,1fr)}.estep .dg{grid-column:2}
|
|
175
|
+
.idea{grid-template-columns:1fr}.idea .centre{order:-1}
|
|
176
|
+
.stack thead{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}.stack,.stack tbody,.stack tr,.stack td{display:block;width:100%}.stack tr{padding:12px 0;border-top:1px solid var(--line)}.stack tbody tr:first-child{border-top:0;padding-top:0}.stack td{border:0;padding:3px 0}
|
|
177
|
+
.stack td[data-label]::before{content:attr(data-label);display:block;font:600 .8125rem/1.3 var(--mono);text-transform:uppercase;letter-spacing:.08em;color:var(--mut);margin-bottom:2px}
|
|
178
|
+
.wrap{padding:12px 16px 56px}.sec{margin-top:32px}}
|
|
179
|
+
@media (prefers-reduced-motion:reduce){.flow .edge path{animation:none}.mini{transition:none}}
|
|
180
|
+
@media print{body{background:#fff;color:#000}.mini,.tools,.deck,.bar{display:none}.fig{overflow:visible;display:block!important}.path,.path-detail{display:none!important}[data-slide]{display:block!important;break-inside:avoid}.banner{break-after:page}.flow .edge path{animation:none}.focus .node:not(.on),.focus .edge:not(.on){opacity:1}}`;
|
|
54
181
|
|
|
55
|
-
/** The page's script: theme, detail on hover or focus, play and
|
|
182
|
+
/** The page's script: theme, the mini header, detail on hover or focus, play and numbered steps, and the presentation mode. Text is set with textContent only. */
|
|
56
183
|
export const PAGE_JS = `(()=>{
|
|
57
184
|
const d=document,q=(s,r=d)=>r.querySelector(s),qa=(s,r=d)=>[...r.querySelectorAll(s)],root=d.documentElement;
|
|
58
185
|
try{const t=localStorage.getItem('vz-theme');if(t==='dark'||t==='light')root.dataset.theme=t}catch(e){}
|
|
59
186
|
const tb=q('#theme');
|
|
60
187
|
if(tb)tb.onclick=()=>{const dark=root.dataset.theme?root.dataset.theme==='dark':matchMedia('(prefers-color-scheme: dark)').matches,n=dark?'light':'dark';root.dataset.theme=n;try{localStorage.setItem('vz-theme',n)}catch(e){}};
|
|
61
|
-
|
|
188
|
+
const hero=q('[data-hero]'),mini=q('.mini');
|
|
189
|
+
if(hero&&mini&&'IntersectionObserver'in window)new IntersectionObserver(([e])=>mini.classList.toggle('on',!e.isIntersecting),{threshold:0}).observe(hero);
|
|
190
|
+
const slides=qa('[data-slide]'),pb=q('#present'),count=q('#slide-count');
|
|
191
|
+
let cur=0;
|
|
192
|
+
const show=i=>{cur=Math.max(0,Math.min(slides.length-1,i));slides.forEach((s,k)=>s.classList.toggle('cur',k===cur));if(count)count.textContent=(cur+1)+' / '+slides.length;scrollTo(0,0)};
|
|
193
|
+
const present=on=>{root.classList.toggle('present',on);if(pb)pb.textContent=on?pb.dataset.off:pb.dataset.on;if(on)show(cur);else slides.forEach(s=>s.classList.remove('cur'))};
|
|
194
|
+
if(pb)pb.onclick=()=>present(!root.classList.contains('present'));
|
|
195
|
+
const sp=q('#slide-prev'),sn=q('#slide-next');
|
|
196
|
+
if(sp)sp.onclick=()=>show(cur-1);
|
|
197
|
+
if(sn)sn.onclick=()=>show(cur+1);
|
|
198
|
+
addEventListener('keydown',e=>{if(!root.classList.contains('present'))return;const k=e.key;
|
|
199
|
+
if(k==='ArrowRight'||k==='ArrowDown'||k==='PageDown'||k===' '){e.preventDefault();show(cur+1)}
|
|
200
|
+
else if(k==='ArrowLeft'||k==='ArrowUp'||k==='PageUp'){e.preventDefault();show(cur-1)}
|
|
201
|
+
else if(k==='Home'){show(0)}else if(k==='End'){show(slides.length-1)}else if(k==='Escape'){present(false)}});
|
|
202
|
+
if(new URLSearchParams(location.search).get('present')==='1')present(true);
|
|
62
203
|
const fig=q('.fig'),panel=q('#detail');
|
|
63
204
|
qa('[data-node]').forEach(n=>{const show=()=>{if(panel)panel.textContent=n.dataset.detail};n.addEventListener('mouseenter',show);n.addEventListener('focus',show)});
|
|
64
205
|
const pp=q('#play');
|
|
@@ -67,14 +208,14 @@ const raw=q('#steps');
|
|
|
67
208
|
if(raw&&fig){
|
|
68
209
|
const steps=JSON.parse(raw.textContent),note=q('#stepnote'),prev=q('#prev'),next=q('#next'),all=q('#all');
|
|
69
210
|
let at=-1;
|
|
70
|
-
const
|
|
211
|
+
const go=i=>{at=i;qa('.on',fig).forEach(x=>x.classList.remove('on'));
|
|
71
212
|
if(i<0){fig.classList.remove('focus');note.textContent='';return}
|
|
72
213
|
const s=steps[i];fig.classList.add('focus');
|
|
73
214
|
s.nodes.forEach(id=>q('[data-node="'+id+'"]',fig)?.classList.add('on'));
|
|
74
215
|
s.edges.forEach(id=>q('[data-edge="'+id+'"]',fig)?.classList.add('on'));
|
|
75
216
|
note.textContent=(i+1)+'/'+steps.length+' '+s.title+' - '+s.note};
|
|
76
|
-
if(prev)prev.onclick=()=>
|
|
77
|
-
if(next)next.onclick=()=>
|
|
78
|
-
if(all)all.onclick=()=>
|
|
217
|
+
if(prev)prev.onclick=()=>go(Math.max(0,at-1));
|
|
218
|
+
if(next)next.onclick=()=>go(Math.min(steps.length-1,at+1));
|
|
219
|
+
if(all)all.onclick=()=>go(-1);
|
|
79
220
|
}
|
|
80
221
|
})();`;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { iconSvg } from './icons.ts';
|
|
2
|
+
import { NodeStates } from './constants.ts';
|
|
3
|
+
import type { TChrome } from './constants.ts';
|
|
4
|
+
import { escapeText } from './layout.ts';
|
|
5
|
+
import type { TVisualizeSpec } from './schema.ts';
|
|
6
|
+
|
|
7
|
+
type TChart = NonNullable<NonNullable<TVisualizeSpec['findings']>['charts']>[number];
|
|
8
|
+
|
|
9
|
+
const escaped = (value: string): string => escapeText({ value });
|
|
10
|
+
|
|
11
|
+
/** 1234567 as 1,234,567 and 0.5 as 0.5: no locale, so the page reads the same everywhere. */
|
|
12
|
+
export const formatNumber = (opts: { value: number }): string => {
|
|
13
|
+
const rounded = Math.round(opts.value * 100) / 100;
|
|
14
|
+
const [whole = '0', fraction] = String(Math.abs(rounded)).split('.');
|
|
15
|
+
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
16
|
+
|
|
17
|
+
return `${rounded < 0 ? '-' : ''}${grouped}${fraction === undefined ? '' : `.${fraction}`}`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const shorten = (opts: { value: string; max: number }): string =>
|
|
21
|
+
opts.value.length <= opts.max ? opts.value : `${opts.value.slice(0, opts.max - 1)}…`;
|
|
22
|
+
|
|
23
|
+
/** A bar anchored to its baseline: square at the base, 4 px round at the data end. */
|
|
24
|
+
const barPath = (opts: { x: number; y: number; width: number; height: number }): string => {
|
|
25
|
+
const { x, y, width, height } = opts;
|
|
26
|
+
const r = Math.min(4, width / 2, height / 2);
|
|
27
|
+
|
|
28
|
+
return `M${x} ${y}h${width - r}a${r} ${r} 0 0 1 ${r} ${r}v${height - 2 * r}a${r} ${r} 0 0 1 ${-r} ${r}h${-(width - r)}z`;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** A readable axis: a step of 1, 2 or 5 times a power of ten, and the bounds that hold the data. */
|
|
32
|
+
const niceScale = (opts: {
|
|
33
|
+
min: number;
|
|
34
|
+
max: number;
|
|
35
|
+
ticks: number;
|
|
36
|
+
}): { low: number; high: number; step: number } => {
|
|
37
|
+
const span = opts.max - opts.min || Math.abs(opts.max) || 1;
|
|
38
|
+
const raw = span / opts.ticks;
|
|
39
|
+
const power = 10 ** Math.floor(Math.log10(raw));
|
|
40
|
+
const unit = raw / power;
|
|
41
|
+
const step = (unit <= 1 ? 1 : unit <= 2 ? 2 : unit <= 5 ? 5 : 10) * power;
|
|
42
|
+
|
|
43
|
+
return { low: Math.floor(opts.min / step) * step, high: Math.ceil(opts.max / step) * step, step };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const VIEW_WIDTH = 340;
|
|
47
|
+
|
|
48
|
+
const barChart = (opts: { chart: Extract<TChart, { type: 'bar' }> }): string => {
|
|
49
|
+
const { labels, values } = opts.chart;
|
|
50
|
+
const max = Math.max(...values, 1);
|
|
51
|
+
const rowHeight = 30;
|
|
52
|
+
const left = 120;
|
|
53
|
+
const plot = 150;
|
|
54
|
+
|
|
55
|
+
return `<svg viewBox="0 0 ${VIEW_WIDTH} ${labels.length * rowHeight + 8}" role="img" aria-label="${escaped(opts.chart.title)}">${labels
|
|
56
|
+
.map((label, index) => {
|
|
57
|
+
const y = index * rowHeight + 6;
|
|
58
|
+
const width = Math.max(2, Math.round(((values[index] ?? 0) / max) * plot));
|
|
59
|
+
|
|
60
|
+
return `<g><title>${escaped(label)}: ${formatNumber({ value: values[index] ?? 0 })}${escaped(opts.chart.unit ?? '')}</title><text x="0" y="${y + 16}" class="ct">${escaped(shorten({ value: label, max: 18 }))}</text><rect x="${left}" y="${y + 2}" width="${plot}" height="18" rx="4" class="ctrack"/><path d="${barPath({ x: left, y: y + 2, width, height: 18 })}" fill="var(--s1)"/><text x="${left + width + 6}" y="${y + 16}" class="cv">${formatNumber({ value: values[index] ?? 0 })}${escaped(opts.chart.unit ?? '')}</text></g>`;
|
|
61
|
+
})
|
|
62
|
+
.join('')}</svg>`;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const lineChart = (opts: { chart: Extract<TChart, { type: 'line' }> }): string => {
|
|
66
|
+
const { labels, series } = opts.chart;
|
|
67
|
+
const all = series.flatMap((s) => s.values.slice(0, labels.length));
|
|
68
|
+
const scale = niceScale({ min: Math.min(...all), max: Math.max(...all), ticks: 4 });
|
|
69
|
+
const left = 44;
|
|
70
|
+
const right = 64;
|
|
71
|
+
const top = 12;
|
|
72
|
+
const height = 150;
|
|
73
|
+
const plot = VIEW_WIDTH - left - right;
|
|
74
|
+
const x = (index: number): number => left + (index / (labels.length - 1)) * plot;
|
|
75
|
+
const y = (value: number): number =>
|
|
76
|
+
top + height - ((value - scale.low) / (scale.high - scale.low || 1)) * height;
|
|
77
|
+
const ticks: number[] = [];
|
|
78
|
+
|
|
79
|
+
for (let value = scale.low; value <= scale.high + scale.step / 2; value += scale.step) {
|
|
80
|
+
ticks.push(Math.round(value * 1000) / 1000);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const every = labels.length > 6 ? Math.ceil(labels.length / 6) : 1;
|
|
84
|
+
// The direct labels sit at the last point of each line; where two would touch, they are pushed apart by 15 px.
|
|
85
|
+
const ends = series
|
|
86
|
+
.map((s, index) => ({ index, y: y(s.values.slice(0, labels.length).at(-1) ?? 0) }))
|
|
87
|
+
.sort((a, b) => a.y - b.y);
|
|
88
|
+
|
|
89
|
+
for (let at = 1; at < ends.length; at += 1) {
|
|
90
|
+
const previous = ends[at - 1];
|
|
91
|
+
const current = ends[at];
|
|
92
|
+
|
|
93
|
+
if (previous !== undefined && current !== undefined && current.y - previous.y < 15) {
|
|
94
|
+
current.y = previous.y + 15;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const labelY = new Map(ends.map((end) => [end.index, end.y]));
|
|
99
|
+
|
|
100
|
+
return `<svg viewBox="0 0 ${VIEW_WIDTH} ${top + height + 34}" role="img" aria-label="${escaped(opts.chart.title)}">${ticks
|
|
101
|
+
.map(
|
|
102
|
+
(tick) =>
|
|
103
|
+
`<line x1="${left}" x2="${VIEW_WIDTH - right}" y1="${y(tick)}" y2="${y(tick)}" class="cgrid"/><text x="${left - 6}" y="${y(tick) + 4}" text-anchor="end" class="ct">${formatNumber({ value: tick })}</text>`,
|
|
104
|
+
)
|
|
105
|
+
.join('')}${labels
|
|
106
|
+
.map((label, index) =>
|
|
107
|
+
index % every === 0
|
|
108
|
+
? `<text x="${x(index)}" y="${top + height + 20}" text-anchor="middle" class="ct">${escaped(shorten({ value: label, max: 8 }))}</text>`
|
|
109
|
+
: '',
|
|
110
|
+
)
|
|
111
|
+
.join('')}${series
|
|
112
|
+
.map((s, index) => {
|
|
113
|
+
const points = s.values.slice(0, labels.length);
|
|
114
|
+
const path = points.map((value, i) => `${i === 0 ? 'M' : 'L'}${x(i)} ${y(value)}`).join('');
|
|
115
|
+
const last = points.at(-1) ?? 0;
|
|
116
|
+
|
|
117
|
+
return `<g><path d="${path}" fill="none" stroke="var(--s${index + 1})" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round"/>${points
|
|
118
|
+
.map(
|
|
119
|
+
(value, i) =>
|
|
120
|
+
`<circle cx="${x(i)}" cy="${y(value)}" r="4.5" fill="var(--s${index + 1})" class="cring"><title>${escaped(s.name)}, ${escaped(labels[i] ?? '')}: ${formatNumber({ value })}${escaped(opts.chart.unit ?? '')}</title></circle>`,
|
|
121
|
+
)
|
|
122
|
+
.join(
|
|
123
|
+
'',
|
|
124
|
+
)}<text x="${VIEW_WIDTH - right + 8}" y="${(labelY.get(index) ?? y(last)) + 4}" class="cv">${escaped(shorten({ value: s.name, max: 8 }))}</text></g>`;
|
|
125
|
+
})
|
|
126
|
+
.join('')}</svg>`;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const SLOTS = ['var(--s1)', 'var(--s2)', 'var(--s3)', 'var(--s4)', 'var(--s5)'];
|
|
130
|
+
|
|
131
|
+
const donutColour = (opts: { index: number; state?: string }): string =>
|
|
132
|
+
opts.state === undefined
|
|
133
|
+
? (SLOTS[opts.index] ?? 'var(--s5)')
|
|
134
|
+
: `var(--${NodeStates.toneOf(opts.state)})`;
|
|
135
|
+
|
|
136
|
+
const donutChart = (opts: { chart: Extract<TChart, { type: 'donut' }> }): string => {
|
|
137
|
+
const { parts } = opts.chart;
|
|
138
|
+
const total = parts.reduce((sum, part) => sum + part.value, 0) || 1;
|
|
139
|
+
const radius = 54;
|
|
140
|
+
const circumference = 2 * Math.PI * radius;
|
|
141
|
+
let offset = 0;
|
|
142
|
+
const segments = parts
|
|
143
|
+
.map((part, index) => {
|
|
144
|
+
const share = part.value / total;
|
|
145
|
+
const length = Math.max(0, share * circumference - 3);
|
|
146
|
+
const out = `<circle cx="80" cy="80" r="${radius}" fill="none" stroke="${donutColour({ index, state: part.state })}" stroke-width="22" stroke-dasharray="${length.toFixed(2)} ${(circumference - length).toFixed(2)}" stroke-dashoffset="${(-offset).toFixed(2)}" transform="rotate(-90 80 80)"><title>${escaped(part.label)}: ${formatNumber({ value: part.value })}${escaped(opts.chart.unit ?? '')}</title></circle>`;
|
|
147
|
+
|
|
148
|
+
offset += share * circumference;
|
|
149
|
+
|
|
150
|
+
return out;
|
|
151
|
+
})
|
|
152
|
+
.join('');
|
|
153
|
+
|
|
154
|
+
return `<svg viewBox="0 0 160 160" class="donut-svg" role="img" aria-label="${escaped(opts.chart.title)}">${segments}<text x="80" y="82" text-anchor="middle" class="cbig">${formatNumber({ value: total })}</text><text x="80" y="100" text-anchor="middle" class="ct">${escaped(opts.chart.unit ?? 'total')}</text></svg>`;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const legend = (opts: { chart: TChart }): string => {
|
|
158
|
+
const { chart } = opts;
|
|
159
|
+
|
|
160
|
+
if (chart.type === 'donut') {
|
|
161
|
+
const total = chart.parts.reduce((sum, part) => sum + part.value, 0) || 1;
|
|
162
|
+
|
|
163
|
+
return `<ul class="clegend">${chart.parts
|
|
164
|
+
.map(
|
|
165
|
+
(part, index) =>
|
|
166
|
+
`<li><i class="sw" ${part.state === undefined ? `data-s="${index + 1}"` : `data-t="${NodeStates.toneOf(part.state)}"`}></i><span>${escaped(part.label)}</span><b>${formatNumber({ value: part.value })}${escaped(chart.unit ?? '')}</b><em>${Math.round((part.value / total) * 100)}%</em></li>`,
|
|
167
|
+
)
|
|
168
|
+
.join('')}</ul>`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (chart.type === 'line' && chart.series.length > 1) {
|
|
172
|
+
return `<ul class="clegend row">${chart.series.map((s, index) => `<li><i class="sw" data-s="${index + 1}"></i><span>${escaped(s.name)}</span></li>`).join('')}</ul>`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return '';
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const tableView = (opts: { chart: TChart; chrome: TChrome }): string => {
|
|
179
|
+
const { chart, chrome } = opts;
|
|
180
|
+
const head =
|
|
181
|
+
chart.type === 'line' ? ['', ...chart.series.map((s) => s.name)] : ['', chrome.value];
|
|
182
|
+
const rows =
|
|
183
|
+
chart.type === 'bar'
|
|
184
|
+
? chart.labels.map((label, index) => [
|
|
185
|
+
label,
|
|
186
|
+
formatNumber({ value: chart.values[index] ?? 0 }),
|
|
187
|
+
])
|
|
188
|
+
: chart.type === 'line'
|
|
189
|
+
? chart.labels.map((label, index) => [
|
|
190
|
+
label,
|
|
191
|
+
...chart.series.map((s) => formatNumber({ value: s.values[index] ?? 0 })),
|
|
192
|
+
])
|
|
193
|
+
: chart.parts.map((part) => [part.label, formatNumber({ value: part.value })]);
|
|
194
|
+
|
|
195
|
+
return `<details class="tv"><summary>${escaped(chrome.tableView)}</summary><div class="tw"><table><thead><tr>${head.map((cell) => `<th>${escaped(cell)}</th>`).join('')}</tr></thead><tbody>${rows.map((row) => `<tr>${row.map((cell) => `<td>${escaped(cell)}</td>`).join('')}</tr>`).join('')}</tbody></table></div></details>`;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/** One chart as a figure: a title, the drawing, a legend when there is more than one thing to tell apart, and its data as a table. */
|
|
199
|
+
export const renderChart = (opts: { chart: TChart; chrome: TChrome }): string => {
|
|
200
|
+
const { chart } = opts;
|
|
201
|
+
const drawing =
|
|
202
|
+
chart.type === 'bar'
|
|
203
|
+
? barChart({ chart })
|
|
204
|
+
: chart.type === 'line'
|
|
205
|
+
? lineChart({ chart })
|
|
206
|
+
: donutChart({ chart });
|
|
207
|
+
|
|
208
|
+
return `<figure class="chart ${chart.type}"><figcaption class="lab">${escaped(chart.title)}</figcaption><div class="cbody">${drawing}${legend({ chart })}</div>${tableView({ chart, chrome: opts.chrome })}</figure>`;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/** Total scores of a comparison as horizontal bars out of the maximum, the recommendation in the accent. */
|
|
212
|
+
export const renderTotals = (opts: {
|
|
213
|
+
names: string[];
|
|
214
|
+
totals: number[];
|
|
215
|
+
best: number;
|
|
216
|
+
max: number;
|
|
217
|
+
chrome: TChrome;
|
|
218
|
+
}): string => {
|
|
219
|
+
const rowHeight = 34;
|
|
220
|
+
const plot = 150;
|
|
221
|
+
|
|
222
|
+
return `<svg viewBox="0 0 ${VIEW_WIDTH} ${opts.names.length * rowHeight + 6}" role="img" aria-label="${escaped(opts.chrome.total)}: ${opts.names.map((n, i) => `${escaped(n)} ${opts.totals[i]}`).join(', ')}">${opts.names
|
|
223
|
+
.map((name, index) => {
|
|
224
|
+
const y = index * rowHeight + 4;
|
|
225
|
+
const total = opts.totals[index] ?? 0;
|
|
226
|
+
const width = Math.max(2, Math.round((total / opts.max) * plot));
|
|
227
|
+
const isBest = index === opts.best;
|
|
228
|
+
|
|
229
|
+
return `<g><title>${escaped(name)}: ${total} ${escaped(opts.chrome.outOf)} ${opts.max}</title><text x="0" y="${y + 19}" class="ct${isBest ? ' strong' : ''}">${escaped(shorten({ value: name, max: 18 }))}</text><rect x="120" y="${y + 5}" width="${plot}" height="20" rx="4" class="ctrack"/><path d="${barPath({ x: 120, y: y + 5, width, height: 20 })}" fill="${isBest ? 'var(--acc)' : 'var(--mut)'}" opacity="${isBest ? 1 : 0.6}"/><text x="${120 + width + 6}" y="${y + 20}" class="cv">${total}</text></g>`;
|
|
230
|
+
})
|
|
231
|
+
.join('')}</svg>`;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export const stateIcon = (opts: { state: string; size?: number }): string =>
|
|
235
|
+
iconSvg({ name: NodeStates.iconOf(opts.state), size: opts.size });
|