@yutaura/live-spec 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/.claude-plugin/plugin.json +12 -0
- package/LICENSE +21 -0
- package/README.md +195 -2
- package/dist/cli.d.ts +20 -0
- package/dist/cli.js +180 -0
- package/dist/diff.d.ts +33 -0
- package/dist/diff.js +141 -0
- package/dist/ensure.d.ts +5 -0
- package/dist/ensure.js +10 -0
- package/dist/explore.d.ts +6 -0
- package/dist/explore.js +270 -0
- package/dist/generate.d.ts +15 -0
- package/dist/generate.js +147 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/load.d.ts +52 -0
- package/dist/load.js +74 -0
- package/dist/model.d.ts +402 -0
- package/dist/model.js +175 -0
- package/dist/render/collapse.d.ts +4 -0
- package/dist/render/collapse.js +22 -0
- package/dist/render/escape.d.ts +1 -0
- package/dist/render/escape.js +2 -0
- package/dist/render/html.d.ts +12 -0
- package/dist/render/html.js +685 -0
- package/dist/render/layout.d.ts +37 -0
- package/dist/render/layout.js +74 -0
- package/dist/render/markdown.d.ts +20 -0
- package/dist/render/markdown.js +227 -0
- package/dist/render/summary.d.ts +62 -0
- package/dist/render/summary.js +119 -0
- package/dist/render/wireframe.d.ts +3 -0
- package/dist/render/wireframe.js +62 -0
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +71 -0
- package/dist/skills.d.ts +8 -0
- package/dist/skills.js +20 -0
- package/dist/static.d.ts +10 -0
- package/dist/static.js +117 -0
- package/dist/surface.d.ts +59 -0
- package/dist/surface.js +44 -0
- package/dist/watch.d.ts +10 -0
- package/dist/watch.js +47 -0
- package/package.json +54 -4
- package/skills/live-spec-authoring/SKILL.md +160 -0
- package/skills/live-spec-from-code/SKILL.md +93 -0
- package/skills/live-spec-review/SKILL.md +65 -0
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
import { ANY } from "./collapse.js";
|
|
2
|
+
import { esc } from "./escape.js";
|
|
3
|
+
import { layout } from "./layout.js";
|
|
4
|
+
import { describeFinding, describeStep, formatEffect, inputCell, questionTarget, resultCell, splitEvidence } from "./markdown.js";
|
|
5
|
+
import { formatTransition, presentBlocked, summarizeActions, summarizeStates } from "./summary.js";
|
|
6
|
+
import { surfaceToHtml } from "./wireframe.js";
|
|
7
|
+
const WIREFLOW_NODE = { width: 260, height: 220 };
|
|
8
|
+
const THUMB_SCALE = 0.6;
|
|
9
|
+
export const renderHtml = (spec, graph) => renderProjectHtml([{ spec, graph }], { title: spec.name });
|
|
10
|
+
export const renderProjectHtml = async (objects, options) => {
|
|
11
|
+
const links = objects.flatMap(({ spec, graph }) => graph.links.map((l) => ({ ...l, source: spec.name })));
|
|
12
|
+
const pages = await Promise.all(objects.map((o, i) => renderPage(o, i, objects, links)));
|
|
13
|
+
const multiple = objects.length > 1;
|
|
14
|
+
const data = {
|
|
15
|
+
single: multiple ? null : objects[0].spec.name,
|
|
16
|
+
pages: Object.fromEntries(pages.map((p) => [p.name, p.data])),
|
|
17
|
+
};
|
|
18
|
+
return `<!doctype html>
|
|
19
|
+
<html lang="ja">
|
|
20
|
+
<head>
|
|
21
|
+
<meta charset="utf-8">
|
|
22
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
23
|
+
<title>${esc(options.title)} — 仕様書</title>
|
|
24
|
+
<style>${CSS}</style>
|
|
25
|
+
</head>
|
|
26
|
+
<body>
|
|
27
|
+
${multiple
|
|
28
|
+
? `<header class="site">
|
|
29
|
+
<a class="site-title" href="#/">${esc(options.title)}</a>
|
|
30
|
+
<nav class="tabs" aria-label="ドメインオブジェクト">${objects
|
|
31
|
+
.map((o) => `<a href="#/${encodeURIComponent(o.spec.name)}" data-tab="${esc(o.spec.name)}">${esc(o.spec.name)}</a>`)
|
|
32
|
+
.join("")}</nav>
|
|
33
|
+
</header>
|
|
34
|
+
${await overviewPage(objects, options, links)}`
|
|
35
|
+
: ""}
|
|
36
|
+
${pages.map((p) => p.html).join("\n")}
|
|
37
|
+
<aside class="panel" id="panel" aria-live="polite" hidden></aside>
|
|
38
|
+
${pages.flatMap((p) => p.templates).join("\n")}
|
|
39
|
+
<script type="application/json" id="live-spec-data">${jsonForScript(data)}</script>
|
|
40
|
+
<script>${CLIENT}</script>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
|
43
|
+
`;
|
|
44
|
+
};
|
|
45
|
+
const actionLabel = (objects, object, action) => {
|
|
46
|
+
if (action === null)
|
|
47
|
+
return "";
|
|
48
|
+
const doc = objects.find((o) => o.spec.name === object)?.spec.docs[action];
|
|
49
|
+
return doc === undefined ? action : `${doc.replace(/。$/, "")}(${action})`;
|
|
50
|
+
};
|
|
51
|
+
const objectLink = (name) => `<a href="#/${encodeURIComponent(name)}">${esc(name)}</a>`;
|
|
52
|
+
// つながりの図に状態遷移図と同じ layout を使う理由: 配置の仕組みを 2 つ持たずに済み、見た目もそろうため。
|
|
53
|
+
const relationsSvg = async (objects, links) => {
|
|
54
|
+
const names = objects.map((o) => o.spec.name);
|
|
55
|
+
const known = links.filter((l) => names.includes(l.to) && l.to !== l.source);
|
|
56
|
+
if (known.length === 0)
|
|
57
|
+
return "";
|
|
58
|
+
const idOf = (name) => `o${names.indexOf(name)}`;
|
|
59
|
+
const l = await layout({
|
|
60
|
+
states: names.map((name, i) => ({ id: idOf(name), label: name, values: {}, initial: i === 0, terminal: false })),
|
|
61
|
+
transitions: known.map((k) => ({ from: idOf(k.source), to: idOf(k.to), action: k.label, actors: [] })),
|
|
62
|
+
availability: [],
|
|
63
|
+
findings: [],
|
|
64
|
+
surfaces: [],
|
|
65
|
+
decisions: [],
|
|
66
|
+
links: [],
|
|
67
|
+
questions: [],
|
|
68
|
+
scenarios: [],
|
|
69
|
+
});
|
|
70
|
+
const nodes = l.nodes
|
|
71
|
+
.map((n) => `<a href="#/${encodeURIComponent(n.label)}" class="rel-node"><rect x="${n.x}" y="${n.y}" width="${n.width}" height="${n.height}" rx="10"/><text x="${n.x + n.width / 2}" y="${n.y + n.height / 2}">${esc(n.label)}</text></a>`)
|
|
72
|
+
.join("");
|
|
73
|
+
return `<div class="diagram relations"><svg viewBox="0 0 ${l.width} ${l.height}" width="${l.width}" height="${l.height}" role="img" aria-label="ドメインオブジェクトのつながり">
|
|
74
|
+
<defs><marker id="arrow-rel" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z"/></marker></defs>
|
|
75
|
+
${l.edges.map((e) => edgeSvg(e, "arrow-rel")).join("")}${nodes}
|
|
76
|
+
</svg></div>`;
|
|
77
|
+
};
|
|
78
|
+
const overviewPage = async (objects, options, links) => `<section class="page" data-page="" hidden>
|
|
79
|
+
<header class="top">
|
|
80
|
+
<div>
|
|
81
|
+
<p class="eyebrow">仕様書</p>
|
|
82
|
+
<h1>${esc(options.title)}</h1>
|
|
83
|
+
<p class="lead">ドメインオブジェクト ${objects.length} 個</p>
|
|
84
|
+
</div>
|
|
85
|
+
</header>
|
|
86
|
+
<main>
|
|
87
|
+
<div class="cards">
|
|
88
|
+
${objects
|
|
89
|
+
.map(({ spec, graph }) => `<a class="card object-card" href="#/${encodeURIComponent(spec.name)}">
|
|
90
|
+
<h3>${esc(spec.name)}</h3>
|
|
91
|
+
${spec.stateDoc === null ? "" : `<p class="object-doc">${esc(spec.stateDoc)}</p>`}
|
|
92
|
+
<dl class="object-stats"><div><dt>状態</dt><dd>${graph.states.length}</dd></div><div><dt>操作</dt><dd>${spec.actions.length}</dd></div><div><dt>未決</dt><dd class="${graph.questions.length === 0 ? "" : "warn"}">${graph.questions.length}</dd></div><div><dt>検査</dt><dd class="${graph.findings.length === 0 ? "ok" : "warn"}">${graph.findings.length === 0 ? "OK" : graph.findings.length}</dd></div></dl>
|
|
93
|
+
</a>`)
|
|
94
|
+
.join("\n ")}
|
|
95
|
+
</div>
|
|
96
|
+
${links.length === 0
|
|
97
|
+
? ""
|
|
98
|
+
: `<section class="links-section">
|
|
99
|
+
<h2>つながり</h2>
|
|
100
|
+
${await relationsSvg(objects, links)}
|
|
101
|
+
<ul class="link-list">${links
|
|
102
|
+
.map((l) => `<li>${objectLink(l.source)}${l.from === null ? "" : ` の ${esc(actionLabel(objects, l.source, l.from))}`} → ${objectLink(l.to)}${l.action === null ? "" : ` の ${esc(actionLabel(objects, l.to, l.action))}`}<span class="sub">${esc(l.label)}</span></li>`)
|
|
103
|
+
.join("")}</ul>
|
|
104
|
+
</section>`}
|
|
105
|
+
</main>
|
|
106
|
+
</section>`;
|
|
107
|
+
const renderPage = async ({ spec, graph }, index, objects, links) => {
|
|
108
|
+
const outgoing = links.filter((l) => l.source === spec.name);
|
|
109
|
+
const incoming = links.filter((l) => l.to === spec.name && l.source !== spec.name);
|
|
110
|
+
const connections = outgoing.length + incoming.length === 0
|
|
111
|
+
? ""
|
|
112
|
+
: `<section class="links-section">
|
|
113
|
+
<h2>つながり</h2>
|
|
114
|
+
<ul class="link-list">${outgoing
|
|
115
|
+
.map((l) => `<li>${l.from === null ? "" : `${esc(actionLabel(objects, spec.name, l.from))} `}→ ${objectLink(l.to)}${l.action === null ? "" : ` の ${esc(actionLabel(objects, l.to, l.action))}`}<span class="sub">${esc(l.label)}</span></li>`)
|
|
116
|
+
.join("")}${incoming
|
|
117
|
+
.map((l) => `<li>${l.action === null ? "" : `${esc(actionLabel(objects, spec.name, l.action))} `}← ${objectLink(l.source)}${l.from === null ? "" : ` の ${esc(actionLabel(objects, l.source, l.from))}`}<span class="sub">${esc(l.label)}</span></li>`)
|
|
118
|
+
.join("")}</ul>
|
|
119
|
+
</section>`;
|
|
120
|
+
const linksOf = (action) => outgoing.filter((l) => l.from === action);
|
|
121
|
+
const l = await layout(graph);
|
|
122
|
+
const actions = summarizeActions(spec, graph);
|
|
123
|
+
const labelOf = (id) => graph.states.find((s) => s.id === id)?.label ?? id;
|
|
124
|
+
const initial = graph.states.find((s) => s.initial);
|
|
125
|
+
const terminal = new Set(graph.states.filter((s) => s.terminal).map((s) => s.id));
|
|
126
|
+
const violating = new Set(graph.findings.flatMap((f) => (f.kind === "invariant-violation" ? [f.state] : [])));
|
|
127
|
+
const notAllowed = (state, actors) => graph.findings.flatMap((f) => f.kind === "surface-action-not-allowed" && f.state === state && actors.includes(f.actor) ? [f.action] : []);
|
|
128
|
+
const states = summarizeStates(spec, graph);
|
|
129
|
+
// id にページの番号を入れる理由: 状態の ID(s0, s1…)はドメインオブジェクトごとに振られるので、
|
|
130
|
+
// 1 つの HTML に複数のページを入れると、テンプレートや図の矢印の id が衝突する。
|
|
131
|
+
const templateId = (state, i) => `sf-${index}-${state}-${i}`;
|
|
132
|
+
// パネルの画面はサーバ側で描いた HTML を <template> に置き、クライアントは複製するだけにする。
|
|
133
|
+
const templates = states.flatMap((s) => s.surfaces.map((g, i) => `<template id="${esc(templateId(s.id, i))}">${surfaceToHtml(g.surface, notAllowed(s.id, g.actors))}</template>`));
|
|
134
|
+
const data = {
|
|
135
|
+
states: states.map((s) => ({ ...s, surfaces: s.surfaces.map((g, i) => ({ actors: g.actors, template: templateId(s.id, i) })) })),
|
|
136
|
+
questions: Object.fromEntries(graph.states.map((s) => [s.id, graph.questions.filter((q) => q.states.includes(s.id)).map((q) => q.ask)])),
|
|
137
|
+
terms: Object.fromEntries(graph.states.map((s) => [s.id, termsOf(s.id)])),
|
|
138
|
+
scenarios: Object.fromEntries(graph.scenarios.map((s) => [s.name, s.steps.filter((st) => st.ok).map((st) => ({ from: st.from, to: st.to, action: st.action }))])),
|
|
139
|
+
};
|
|
140
|
+
const scenarioCard = (s) => `<article class="card scenario-card" data-scenario="${esc(s.name)}" tabindex="0">
|
|
141
|
+
<h3>${s.passed ? "✅" : "❌"} ${esc(s.name)}</h3>
|
|
142
|
+
<ol class="storyboard">${s.steps
|
|
143
|
+
.map((st) => {
|
|
144
|
+
const shown = st.to === null ? undefined : graph.surfaces.find((x) => x.state === st.to && x.actor === st.actor);
|
|
145
|
+
return `<li class="${st.ok ? "" : "failed"}"><p class="step">${esc(describeStep(spec, st))}</p>${st.ok
|
|
146
|
+
? `<p class="flow">${esc(labelOf(st.from ?? ""))} → ${esc(labelOf(st.to ?? ""))}</p>`
|
|
147
|
+
: `<p class="reason">❌ ${esc(st.reason ?? "")}</p>`}${shown === undefined ? "" : `<div class="frame"><div class="frame-inner">${surfaceToHtml(shown.surface, notAllowed(st.to, [st.actor]))}</div></div>`}</li>`;
|
|
148
|
+
})
|
|
149
|
+
.join("")}</ol>
|
|
150
|
+
</article>`;
|
|
151
|
+
const actorNames = spec.actors.map(([name]) => name);
|
|
152
|
+
const thumbsOf = (state) => actorNames.map((actor) => {
|
|
153
|
+
const found = graph.surfaces.find((x) => x.state === state && x.actor === actor);
|
|
154
|
+
const html = found === undefined
|
|
155
|
+
? '<p class="wf-text">(画面がありません)</p>'
|
|
156
|
+
: surfaceToHtml(found.surface, notAllowed(state, [actor]));
|
|
157
|
+
return [actor, html];
|
|
158
|
+
});
|
|
159
|
+
const wl = graph.surfaces.length > 0 ? await layout(graph, { nodeSize: WIREFLOW_NODE }) : null;
|
|
160
|
+
const questioned = new Set(graph.questions.flatMap((q) => q.states));
|
|
161
|
+
// ノードにカーソルを合わせたとき、状態の名前に含まれる用語の説明を出す(名前だけでは意味が伝わらないことがあるため)。
|
|
162
|
+
// データ(data)を組み立てる時点でも使うので、巻き上げられる関数宣言にしている。
|
|
163
|
+
function termsOf(id) {
|
|
164
|
+
return labelOf(id)
|
|
165
|
+
.split(" · ")
|
|
166
|
+
.flatMap((part) => (spec.glossary[part] === undefined ? [] : [`${part}: ${spec.glossary[part]}`]));
|
|
167
|
+
}
|
|
168
|
+
const flags = (id) => ({
|
|
169
|
+
terms: termsOf(id),
|
|
170
|
+
initial: id === initial?.id,
|
|
171
|
+
terminal: terminal.has(id),
|
|
172
|
+
violation: violating.has(id),
|
|
173
|
+
question: questioned.has(id),
|
|
174
|
+
});
|
|
175
|
+
const asksOf = (action) => graph.questions.filter((q) => q.action === action).map((q) => q.ask);
|
|
176
|
+
const arrow = `arrow-${index}`;
|
|
177
|
+
const arrowWf = `arrow-wf-${index}`;
|
|
178
|
+
const html = `<section class="page" data-page="${esc(spec.name)}" hidden>
|
|
179
|
+
<header class="top">
|
|
180
|
+
<div>
|
|
181
|
+
<p class="eyebrow">ドメインオブジェクト</p>
|
|
182
|
+
<h1>${esc(spec.name)}</h1>
|
|
183
|
+
${spec.stateDoc === null ? "" : `<p class="lead">${esc(spec.stateDoc)}</p>`}
|
|
184
|
+
</div>
|
|
185
|
+
<dl class="stats">
|
|
186
|
+
<div><dt>状態</dt><dd>${graph.states.length}</dd></div>
|
|
187
|
+
<div><dt>操作</dt><dd>${actions.length}</dd></div>
|
|
188
|
+
<div><dt>未決</dt><dd class="${graph.questions.length === 0 ? "" : "warn"}">${graph.questions.length}</dd></div>
|
|
189
|
+
<div><dt>検査</dt><dd class="${graph.findings.length === 0 ? "ok" : "warn"}">${graph.findings.length === 0 ? "OK" : graph.findings.length}</dd></div>
|
|
190
|
+
</dl>
|
|
191
|
+
</header>
|
|
192
|
+
<main>
|
|
193
|
+
${graph.questions.length === 0
|
|
194
|
+
? ""
|
|
195
|
+
: `<section class="questions" aria-label="未決事項">
|
|
196
|
+
<h2>未決事項</h2>
|
|
197
|
+
<ol>${graph.questions
|
|
198
|
+
.map((q) => `<li><span class="ask">${esc(q.ask)}</span><span class="target">${esc(questionTarget(spec, q, labelOf))}</span>${q.note === null ? "" : `<span class="note">${esc(q.note)}</span>`}</li>`)
|
|
199
|
+
.join("")}</ol>
|
|
200
|
+
</section>`}
|
|
201
|
+
<section class="board" aria-label="状態遷移図" data-mode="states">
|
|
202
|
+
<p class="hint">状態をクリックすると、その状態でできること・できないことを表示します。矢印のラベルや操作カードをクリックすると、その操作の遷移を強調します。Esc で解除。</p>
|
|
203
|
+
${wl === null
|
|
204
|
+
? ""
|
|
205
|
+
: `<div class="toolbar">
|
|
206
|
+
<div class="modes" role="group" aria-label="図の表示"><button type="button" data-mode="states" aria-pressed="true">状態遷移図</button><button type="button" data-mode="wireflow" aria-pressed="false">画面つき</button></div>
|
|
207
|
+
<label class="viewpoint">視点 <select class="viewpoint-select">${actorNames.map((a) => `<option value="${esc(a)}">${esc(a)}</option>`).join("")}</select></label>
|
|
208
|
+
</div>`}
|
|
209
|
+
<div class="diagram diagram-states">
|
|
210
|
+
${diagramSvg(spec.name, l, arrow, (n) => nodeSvg(n, flags(n.id), arrow))}
|
|
211
|
+
</div>
|
|
212
|
+
${wl === null
|
|
213
|
+
? ""
|
|
214
|
+
: `<div class="diagram diagram-wireflow">
|
|
215
|
+
${diagramSvg(spec.name, wl, arrowWf, (n) => wireflowNodeSvg(n, flags(n.id), thumbsOf(n.id), actorNames[0], arrowWf))}
|
|
216
|
+
</div>`}
|
|
217
|
+
</section>
|
|
218
|
+
${glossaryHtml(spec)}
|
|
219
|
+
<section class="actions">
|
|
220
|
+
<h2>操作</h2>
|
|
221
|
+
<div class="cards">
|
|
222
|
+
${actions.map((a) => actionCard(a, asksOf(a.name), linksOf(a.name), spec.evidence[a.name] ?? [])).join("\n ")}
|
|
223
|
+
</div>
|
|
224
|
+
</section>
|
|
225
|
+
${graph.decisions.length === 0
|
|
226
|
+
? ""
|
|
227
|
+
: `<section class="decisions">
|
|
228
|
+
<h2>ルール</h2>
|
|
229
|
+
${graph.decisions
|
|
230
|
+
.map((d) => `<h3>${esc(d.name)}</h3><table class="decision"><thead><tr>${d.columns.map((c) => `<th>${esc(c)}</th>`).join("")}<th>結果</th></tr></thead><tbody>${d.rows
|
|
231
|
+
.map((r) => `<tr class="${r.ok ? "" : "ng"}">${d.columns.map((c) => `<td>${esc(inputCell(r.input, c))}</td>`).join("")}<td class="result">${esc(resultCell(r))}</td></tr>`)
|
|
232
|
+
.join("")}</tbody></table>`)
|
|
233
|
+
.join("\n ")}
|
|
234
|
+
</section>`}
|
|
235
|
+
${connections}
|
|
236
|
+
${graph.scenarios.length === 0
|
|
237
|
+
? ""
|
|
238
|
+
: `<section class="scenarios">
|
|
239
|
+
<h2>シナリオ</h2>
|
|
240
|
+
<p class="hint">シナリオを選ぶと、状態遷移図の上でその経路を強調します。各段階には、操作した人に見える画面を並べます。</p>
|
|
241
|
+
${graph.scenarios.map(scenarioCard).join("\n ")}
|
|
242
|
+
</section>`}
|
|
243
|
+
<section class="findings">
|
|
244
|
+
<h2>検査結果</h2>
|
|
245
|
+
${graph.findings.length === 0
|
|
246
|
+
? '<p class="ok-line">問題は見つかりませんでした。</p>'
|
|
247
|
+
: `<ul>${graph.findings.map((f) => `<li>${esc(describeFinding(f, labelOf))}</li>`).join("")}</ul>`}
|
|
248
|
+
</section>
|
|
249
|
+
</main>
|
|
250
|
+
</section>`;
|
|
251
|
+
return { name: spec.name, html, templates, data };
|
|
252
|
+
};
|
|
253
|
+
export const renderErrorHtml = (name, error) => {
|
|
254
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
255
|
+
return `<!doctype html>
|
|
256
|
+
<html lang="ja">
|
|
257
|
+
<head>
|
|
258
|
+
<meta charset="utf-8">
|
|
259
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
260
|
+
<title>${esc(name)} — 生成エラー</title>
|
|
261
|
+
<style>${CSS}
|
|
262
|
+
.error{margin:40px;max-width:72ch}.error pre{white-space:pre-wrap;background:var(--card);border:1px solid var(--warn);border-radius:12px;padding:16px;color:var(--warn)}</style>
|
|
263
|
+
</head>
|
|
264
|
+
<body>
|
|
265
|
+
<main class="error">
|
|
266
|
+
<p class="eyebrow">仕様書を生成できませんでした</p>
|
|
267
|
+
<h1>${esc(name)}</h1>
|
|
268
|
+
<pre>${esc(message)}</pre>
|
|
269
|
+
<p class="hint">spec ファイルを直して保存すると、自動で生成し直します。生成し直したら、このページを再読み込みしてください。</p>
|
|
270
|
+
</main>
|
|
271
|
+
</body>
|
|
272
|
+
</html>
|
|
273
|
+
`;
|
|
274
|
+
};
|
|
275
|
+
const diagramSvg = (name, l, markerId, node) => `<svg viewBox="0 0 ${l.width + 24} ${l.height}" width="${l.width + 24}" height="${l.height}" role="img" aria-label="${esc(name)} の状態遷移図">
|
|
276
|
+
<defs><marker id="${markerId}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z"/></marker></defs>
|
|
277
|
+
<g transform="translate(24 0)">
|
|
278
|
+
${l.edges.map((e) => edgeSvg(e, markerId)).join("\n ")}
|
|
279
|
+
${l.nodes.map(node).join("\n ")}
|
|
280
|
+
</g>
|
|
281
|
+
</svg>`;
|
|
282
|
+
const glossaryHtml = (spec) => {
|
|
283
|
+
const fields = Object.entries(spec.fieldDocs).map(([field, doc]) => {
|
|
284
|
+
const values = spec.fields[field];
|
|
285
|
+
return `<dt>${esc(field)} <span class="kind">項目</span></dt><dd>${esc(doc)}${values === undefined ? "" : `<span class="sub">値: ${esc(values.map(String).join(" / "))}</span>`}</dd>`;
|
|
286
|
+
});
|
|
287
|
+
const terms = Object.entries(spec.glossary).map(([term, doc]) => `<dt>${esc(term)}</dt><dd>${esc(doc)}</dd>`);
|
|
288
|
+
return fields.length + terms.length === 0
|
|
289
|
+
? ""
|
|
290
|
+
: `<section class="glossary"><h2>用語</h2><dl>${[...fields, ...terms].join("")}</dl></section>`;
|
|
291
|
+
};
|
|
292
|
+
const nodeClass = (f, extra = "") => ["node", f.initial ? "initial" : "", f.terminal ? "terminal" : "", f.violation ? "violation" : "", f.question ? "has-question" : "", extra]
|
|
293
|
+
.filter(Boolean)
|
|
294
|
+
.join(" ");
|
|
295
|
+
const questionMark = (n, f) => f.question ? `<g class="q-mark"><circle cx="${n.x + n.width - 2}" cy="${n.y + 2}" r="8"/><text x="${n.x + n.width - 2}" y="${n.y + 2}">?</text></g>` : "";
|
|
296
|
+
const startMarker = (n, cy, markerId) => `<circle class="start" cx="${n.x - 18}" cy="${cy}" r="5"/><path class="start-line" d="M${n.x - 13},${cy} L${n.x - 2},${cy}" marker-end="url(#${markerId})"/>`;
|
|
297
|
+
const terminalRect = (n) => `<rect class="inner" x="${n.x + 3}" y="${n.y + 3}" width="${n.width - 6}" height="${n.height - 6}" rx="7"/>`;
|
|
298
|
+
// 「どの状態からでも」は実在の状態ではないので、点線で描き、クリックできる状態(data-state)にはしない。
|
|
299
|
+
const anyNodeSvg = (n) => `<g class="any-node"><rect x="${n.x}" y="${n.y}" width="${n.width}" height="${n.height}" rx="${n.height / 2}"/><text x="${n.x + n.width / 2}" y="${n.y + n.height / 2}">${esc(n.label)}</text></g>`;
|
|
300
|
+
const nodeSvg = (n, f, markerId) => {
|
|
301
|
+
if (n.id === ANY)
|
|
302
|
+
return anyNodeSvg(n);
|
|
303
|
+
const cy = n.y + n.height / 2;
|
|
304
|
+
return `${f.initial ? startMarker(n, cy, markerId) : ""}<g class="${nodeClass(f)}" data-state="${esc(n.id)}" tabindex="0" role="button" aria-label="状態 ${esc(n.label)}"><rect x="${n.x}" y="${n.y}" width="${n.width}" height="${n.height}" rx="10"/>${f.terms.length === 0 ? "" : `<title>${esc(f.terms.join("\n"))}</title>`}${f.terminal ? terminalRect(n) : ""}<text x="${n.x + n.width / 2}" y="${cy}">${esc(n.label)}</text>${questionMark(n, f)}</g>`;
|
|
305
|
+
};
|
|
306
|
+
// サムネイルを SVG の foreignObject に入れる理由: パネルと同じ HTML のワイヤーフレームを、
|
|
307
|
+
// 縮小してそのまま図の中に置けるため。見る人ごとに用意し、視点の切り替えで表示を変える。
|
|
308
|
+
const wireflowNodeSvg = (n, f, thumbs, visible, markerId) => {
|
|
309
|
+
if (n.id === ANY)
|
|
310
|
+
return anyNodeSvg(n);
|
|
311
|
+
const inner = n.width - 16;
|
|
312
|
+
const thumbHtml = thumbs
|
|
313
|
+
.map(([actor, html]) => `<div class="thumb" data-actor="${esc(actor)}"${actor === visible ? "" : " hidden"}><div class="thumb-inner" style="width:${inner / THUMB_SCALE}px">${html}</div></div>`)
|
|
314
|
+
.join("");
|
|
315
|
+
return `${f.initial ? startMarker(n, n.y + n.height / 2, markerId) : ""}<g class="${nodeClass(f, "wf-node")}" data-state="${esc(n.id)}" tabindex="0" role="button" aria-label="状態 ${esc(n.label)}"><rect x="${n.x}" y="${n.y}" width="${n.width}" height="${n.height}" rx="10"/>${f.terminal ? terminalRect(n) : ""}<text class="wf-node-label" x="${n.x + 12}" y="${n.y + 16}">${esc(n.label)}</text><foreignObject x="${n.x + 8}" y="${n.y + 30}" width="${inner}" height="${n.height - 38}"><div class="thumb-frame">${thumbHtml}</div></foreignObject></g>`;
|
|
316
|
+
};
|
|
317
|
+
const edgeSvg = (e, markerId) => {
|
|
318
|
+
const d = e.points.map((p, i) => `${i === 0 ? "M" : "L"}${p.x},${p.y}`).join(" ");
|
|
319
|
+
const lb = e.label;
|
|
320
|
+
return `<g class="edge" data-action="${esc(e.action)}" data-from="${esc(e.from)}" data-to="${esc(e.to)}"><path d="${d}" marker-end="url(#${markerId})"/><g class="edge-label"><rect x="${lb.x}" y="${lb.y}" width="${lb.width}" height="${lb.height}" rx="4"/><text x="${lb.x + lb.width / 2}" y="${lb.y + lb.height / 2}">${esc(e.action)}</text></g></g>`;
|
|
321
|
+
};
|
|
322
|
+
const actionCard = (a, asks, links, evidence) => {
|
|
323
|
+
const others = a.othersReasons.length === 0 ? "" : `<span class="muted">ほかの人は「${a.othersReasons.map(esc).join("」「")}」</span>`;
|
|
324
|
+
const who = a.capable.length === 0
|
|
325
|
+
? '<span class="muted">なし(どの状態でも誰も実行できない)</span>'
|
|
326
|
+
: `${a.capable.map((c) => `<span class="chip">${esc(c)}</span>`).join("")}${others}`;
|
|
327
|
+
const when = a.when.length === 0
|
|
328
|
+
? '<span class="muted">なし</span>'
|
|
329
|
+
: a.when.map((w) => `<span class="flow">${esc(formatTransition(w))}</span>`).join("");
|
|
330
|
+
const blocked = presentBlocked(a.blocked).map((b) => `<li><span class="reason">${esc(b.reason)}</span> ${b.states === null ? '<span class="state rest">それ以外のすべての状態</span>' : b.states.map((s) => `<span class="state">${esc(s)}</span>`).join("")}</li>`);
|
|
331
|
+
const whenNot = blocked.length === 0 ? '<span class="muted">なし</span>' : `<ul>${blocked.join("")}</ul>`;
|
|
332
|
+
const effect = formatEffect(a);
|
|
333
|
+
return `<article class="card" data-action="${esc(a.name)}" tabindex="0">
|
|
334
|
+
<h3>${a.summary === null ? "" : `${esc(a.summary)} `}<code>${esc(a.name)}</code>${asks.length === 0 ? "" : ` <span class="q-badge">未決 ${asks.length}</span>`}</h3>
|
|
335
|
+
<dl>
|
|
336
|
+
<dt>できる人</dt><dd>${who}</dd>
|
|
337
|
+
<dt>できるとき</dt><dd>${when}</dd>
|
|
338
|
+
<dt>できないとき</dt><dd>${whenNot}</dd>
|
|
339
|
+
${a.inputOutcomes.length === 0 ? "" : `<dt>入力ごとの結果</dt><dd><ul>${a.inputOutcomes.map((o) => `<li><span class="reason">${esc(o.input)}</span> ${o.transitions.length > 0 ? o.transitions.map((t) => `<span class="flow">${esc(formatTransition(t))}</span>`).join("") : `<span class="state">❌ ${esc(o.reasons.join("、"))}</span>`}</li>`).join("")}</ul></dd>`}
|
|
340
|
+
${effect === "" ? "" : `<dt>結果</dt><dd>${esc(effect)}</dd>`}
|
|
341
|
+
${evidence.length === 0
|
|
342
|
+
? ""
|
|
343
|
+
: `<dt>根拠</dt><dd>${evidence
|
|
344
|
+
.map((e) => {
|
|
345
|
+
const { path, rest } = splitEvidence(e);
|
|
346
|
+
return `<span class="ev"><code class="evidence">${esc(path)}</code>${esc(rest)}</span>`;
|
|
347
|
+
})
|
|
348
|
+
.join("")}</dd>`}
|
|
349
|
+
${links.length === 0 ? "" : `<dt>つながり</dt><dd>${links.map((l) => `<span class="flow">→ ${objectLink(l.to)}${l.action === null ? "" : ` の ${esc(l.action)}`}</span>`).join("")}<span class="muted">${esc(links.map((l) => l.label).join(" / "))}</span></dd>`}
|
|
350
|
+
${asks.length === 0 ? "" : `<dt>未決</dt><dd><ul>${asks.map((q) => `<li class="ask">${esc(q)}</li>`).join("")}</ul></dd>`}
|
|
351
|
+
</dl>
|
|
352
|
+
</article>`;
|
|
353
|
+
};
|
|
354
|
+
// < などをエスケープする理由: spec の文字列に "</script>" が含まれていても、
|
|
355
|
+
// 埋め込んだ JSON が script 要素を途中で閉じないようにするため。
|
|
356
|
+
const jsonForScript = (data) => JSON.stringify(data)
|
|
357
|
+
.replace(/</g, "\\u003c")
|
|
358
|
+
.replace(/\u{2028}/gu, "\\u2028")
|
|
359
|
+
.replace(/\u{2029}/gu, "\\u2029");
|
|
360
|
+
const CSS = `
|
|
361
|
+
:root{--bg:#f6f5f1;--fg:#1c1c1e;--muted:#6e6d72;--line:#d9d6cd;--card:#fff;--node:#fff;--accent:#2b59e0;--accent-weak:#e5ebfc;--ok:#1d7f48;--warn:#b3501a;--chip:#efeee9}
|
|
362
|
+
@media (prefers-color-scheme:dark){:root{--bg:#141416;--fg:#ececee;--muted:#9a99a0;--line:#34343a;--card:#1c1c20;--node:#1f1f24;--accent:#7f9dff;--accent-weak:#232b45;--ok:#5cc98b;--warn:#f0a46b;--chip:#2a2a30}}
|
|
363
|
+
*{box-sizing:border-box}
|
|
364
|
+
body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.65 system-ui,-apple-system,"Hiragino Sans","Noto Sans JP",sans-serif}
|
|
365
|
+
code{font:13px ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--chip);padding:1px 6px;border-radius:5px}
|
|
366
|
+
.top{display:flex;justify-content:space-between;align-items:flex-end;gap:24px;padding:40px 40px 24px;border-bottom:1px solid var(--line)}
|
|
367
|
+
.eyebrow{margin:0 0 4px;font-size:12px;letter-spacing:.08em;color:var(--muted)}
|
|
368
|
+
h1{margin:0;font-size:32px;letter-spacing:-.01em}
|
|
369
|
+
.lead{margin:8px 0 0;color:var(--muted);max-width:60ch}
|
|
370
|
+
.stats{display:flex;gap:28px;margin:0}
|
|
371
|
+
.stats div{text-align:right}.stats dt{font-size:12px;color:var(--muted)}.stats dd{margin:0;font-size:24px;font-weight:600}
|
|
372
|
+
.stats .ok{color:var(--ok)}.stats .warn{color:var(--warn)}
|
|
373
|
+
main{padding:24px 40px 64px}
|
|
374
|
+
h2{font-size:18px;margin:40px 0 16px}
|
|
375
|
+
.board .hint{margin:0 0 10px}
|
|
376
|
+
.diagram{background:var(--card);border:1px solid var(--line);border-radius:14px;overflow:auto;padding:8px}
|
|
377
|
+
.diagram svg{display:block;max-width:100%;height:auto;margin:0 auto}
|
|
378
|
+
.panel{position:fixed;top:16px;right:16px;width:400px;max-height:calc(100vh - 32px);overflow:auto;background:var(--card);border:1px solid var(--line);border-radius:14px;padding:20px;box-shadow:0 12px 40px rgba(0,0,0,.25);z-index:10}
|
|
379
|
+
.panel[hidden]{display:none}
|
|
380
|
+
.panel h2{margin:0 0 12px;font-size:20px}
|
|
381
|
+
.panel h3{font-size:13px;color:var(--muted);margin:18px 0 6px;font-weight:600}
|
|
382
|
+
.panel ul{list-style:none;margin:0;padding:0}
|
|
383
|
+
.panel li{padding:6px 0;border-top:1px solid var(--line)}
|
|
384
|
+
.panel li:first-child{border-top:0}
|
|
385
|
+
.panel .sub{display:block;font-size:12px;color:var(--muted)}
|
|
386
|
+
.panel .tag{display:inline-block;font-size:11px;padding:1px 8px;border-radius:999px;background:var(--chip);margin-right:6px}
|
|
387
|
+
.panel button{margin-top:16px;font:inherit;font-size:13px;background:none;border:1px solid var(--line);color:var(--fg);border-radius:8px;padding:4px 12px;cursor:pointer}
|
|
388
|
+
.hint{font-size:12px;color:var(--muted)}
|
|
389
|
+
.site{position:sticky;top:0;z-index:5;display:flex;gap:24px;align-items:center;padding:10px 40px;background:var(--bg);border-bottom:1px solid var(--line)}
|
|
390
|
+
.site-title{font-weight:700;color:var(--fg);text-decoration:none}
|
|
391
|
+
.tabs{display:flex;gap:4px;flex-wrap:wrap}
|
|
392
|
+
.tabs a{color:var(--muted);text-decoration:none;padding:4px 12px;border-radius:8px;font-size:14px}
|
|
393
|
+
.tabs a:hover{color:var(--fg)}
|
|
394
|
+
.tabs a[aria-current="page"]{background:var(--accent-weak);color:var(--accent);font-weight:600}
|
|
395
|
+
.page[hidden]{display:none}
|
|
396
|
+
.object-card{display:block;color:var(--fg);text-decoration:none}
|
|
397
|
+
.object-card h3{font-size:18px}
|
|
398
|
+
.object-doc{color:var(--muted);margin:0 0 12px}
|
|
399
|
+
.card .object-stats{display:flex;gap:20px;margin:0}
|
|
400
|
+
.object-stats dt{font-size:12px;color:var(--muted)}.object-stats dd{margin:0;font-weight:600;font-size:18px}
|
|
401
|
+
.object-stats .ok{color:var(--ok)}.object-stats .warn{color:var(--warn)}
|
|
402
|
+
.toolbar{display:flex;gap:16px;align-items:center;margin:0 0 10px;font-size:13px}
|
|
403
|
+
.modes{display:inline-flex;border:1px solid var(--line);border-radius:8px;overflow:hidden}
|
|
404
|
+
.modes button{font:inherit;font-size:13px;background:none;border:0;color:var(--muted);padding:4px 12px;cursor:pointer}
|
|
405
|
+
.modes button[aria-pressed="true"]{background:var(--accent-weak);color:var(--accent);font-weight:600}
|
|
406
|
+
.viewpoint{color:var(--muted)}.viewpoint select{font:inherit;font-size:13px;margin-left:4px}
|
|
407
|
+
.board[data-mode="states"] .diagram-wireflow,.board[data-mode="wireflow"] .diagram-states{display:none}
|
|
408
|
+
.board:not([data-mode="wireflow"]) .viewpoint{display:none}
|
|
409
|
+
svg text.wf-node-label{text-anchor:start;font-weight:600;font-size:13px}
|
|
410
|
+
.thumb-frame{width:100%;height:100%;overflow:hidden;pointer-events:none}
|
|
411
|
+
.thumb-inner{transform:scale(${THUMB_SCALE});transform-origin:0 0}
|
|
412
|
+
.wf-group{margin:10px 0 16px}
|
|
413
|
+
.wf-screen{border:1.5px solid var(--fg);border-radius:8px;background:var(--node);font-size:13px;overflow:hidden}
|
|
414
|
+
.wf-title{border-bottom:1.5px solid var(--fg);padding:6px 10px;font-weight:600;display:flex;gap:6px;align-items:center}
|
|
415
|
+
.wf-title::before{content:"";width:28px;height:6px;border-radius:3px;background:repeating-linear-gradient(90deg,var(--muted) 0 6px,transparent 6px 11px)}
|
|
416
|
+
.wf-body{padding:10px;display:flex;flex-direction:column;gap:8px;align-items:flex-start}
|
|
417
|
+
.wf-section{border:1px dashed var(--muted);border-radius:6px;padding:8px;align-self:stretch;display:flex;flex-direction:column;gap:6px;align-items:flex-start}
|
|
418
|
+
.wf-section > .wf-label{font-size:11.5px;color:var(--muted)}
|
|
419
|
+
.wf-heading{font-weight:600;font-size:14px}
|
|
420
|
+
.wf-text{margin:0}
|
|
421
|
+
.wf-field{display:flex;flex-direction:column;gap:2px;align-self:stretch;font-size:11.5px;color:var(--muted)}
|
|
422
|
+
.wf-input{border:1.2px solid var(--muted);border-radius:4px;min-height:24px;padding:2px 6px;color:var(--fg);font-size:12.5px}
|
|
423
|
+
.wf-button{border:1.5px solid var(--fg);border-radius:6px;padding:2px 12px;font-size:12.5px;font-weight:600}
|
|
424
|
+
.wf-button.is-disabled{opacity:.4;border-style:dashed}
|
|
425
|
+
.wf-button.is-invalid{border-color:var(--warn);color:var(--warn)}
|
|
426
|
+
.wf-button.is-invalid::after{content:" ⚠"}
|
|
427
|
+
.wf-badge{border:1px solid var(--muted);border-radius:999px;padding:0 8px;font-size:11px;color:var(--muted)}
|
|
428
|
+
.wf-list{margin:0;padding-left:18px;align-self:stretch}
|
|
429
|
+
.wf-code{margin:0;align-self:stretch;background:var(--chip);border-radius:6px;padding:8px;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap}
|
|
430
|
+
.wf-code[data-language="terminal"]{background:#111;color:#e6e6e6}
|
|
431
|
+
svg text{font-size:13px;fill:var(--fg);text-anchor:middle;dominant-baseline:central}
|
|
432
|
+
marker path{fill:var(--muted)}
|
|
433
|
+
.node{cursor:pointer;outline:none}
|
|
434
|
+
.node rect{fill:var(--node);stroke:var(--fg);stroke-width:1.4}
|
|
435
|
+
.node rect.inner{fill:none;stroke-width:1}
|
|
436
|
+
.node:hover rect,.node:focus-visible rect{stroke:var(--accent)}
|
|
437
|
+
.node.violation rect{stroke:var(--warn);stroke-width:2;stroke-dasharray:5 3}
|
|
438
|
+
.panel .tag.warn{background:var(--warn);color:var(--bg)}
|
|
439
|
+
.panel .violation{color:var(--warn);font-size:13px;margin:10px 0 0}
|
|
440
|
+
.start{fill:var(--fg)}.start-line{stroke:var(--fg);stroke-width:1.4}
|
|
441
|
+
.edge{cursor:pointer}
|
|
442
|
+
.edge path{fill:none;stroke:var(--muted);stroke-width:1.3}
|
|
443
|
+
.edge-label rect{fill:var(--card)}
|
|
444
|
+
.edge-label text{font-size:11.5px;fill:var(--muted)}
|
|
445
|
+
.edge:hover path{stroke:var(--accent)}.edge:hover .edge-label text{fill:var(--accent)}
|
|
446
|
+
.is-dim{opacity:.18;transition:opacity .15s}
|
|
447
|
+
.node.is-selected rect{stroke:var(--accent);stroke-width:2.2;fill:var(--accent-weak)}
|
|
448
|
+
.edge.is-active path{stroke:var(--accent);stroke-width:2.2}
|
|
449
|
+
.edge.is-active .edge-label text{fill:var(--accent);font-weight:600}
|
|
450
|
+
.cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:16px}
|
|
451
|
+
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:18px 20px;cursor:pointer;outline:none}
|
|
452
|
+
.card:hover,.card:focus-visible{border-color:var(--accent)}
|
|
453
|
+
.card.is-selected{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-weak)}
|
|
454
|
+
.card h3{margin:0 0 12px;font-size:16px}
|
|
455
|
+
.card dl{display:grid;grid-template-columns:5.5em 1fr;gap:8px 12px;margin:0;font-size:14px}
|
|
456
|
+
.card dt{color:var(--muted);font-size:12.5px;padding-top:2px}
|
|
457
|
+
.card dd{margin:0}
|
|
458
|
+
.card ul{margin:0;padding:0;list-style:none}
|
|
459
|
+
.card li+li{margin-top:6px}
|
|
460
|
+
.chip,.state,.flow{display:inline-block;font-size:12.5px;border-radius:6px;padding:0 7px;margin:0 4px 4px 0;background:var(--chip)}
|
|
461
|
+
.flow{background:var(--accent-weak)}
|
|
462
|
+
.questions{border:1px solid var(--warn);border-radius:14px;padding:4px 20px 12px;margin:0 0 20px;background:var(--card)}
|
|
463
|
+
.questions h2{margin:14px 0 8px;color:var(--warn);font-size:16px}
|
|
464
|
+
.questions ol{margin:0;padding-left:20px}
|
|
465
|
+
.questions li{margin:6px 0}
|
|
466
|
+
.questions .ask{font-weight:600}
|
|
467
|
+
.questions .target{color:var(--muted);font-size:13px;margin-left:4px}
|
|
468
|
+
.questions .note{display:block;color:var(--muted);font-size:13px}
|
|
469
|
+
.q-badge{display:inline-block;font-size:11px;font-weight:600;padding:1px 8px;border-radius:999px;background:var(--warn);color:var(--bg);vertical-align:middle}
|
|
470
|
+
.card .ask{color:var(--warn);font-size:13px}
|
|
471
|
+
.q-mark circle{fill:var(--warn)}
|
|
472
|
+
.q-mark text{fill:var(--bg);font-size:11px;font-weight:700}
|
|
473
|
+
.stats .warn,.object-stats .warn{color:var(--warn)}
|
|
474
|
+
.links-section{margin:0 0 8px}
|
|
475
|
+
.link-list{list-style:none;padding:0;margin:8px 0 0}
|
|
476
|
+
.link-list li{padding:6px 0;border-top:1px solid var(--line)}
|
|
477
|
+
.link-list li:first-child{border-top:0}
|
|
478
|
+
.link-list .sub{display:block;color:var(--muted);font-size:13px}
|
|
479
|
+
.link-list a,.card .flow a{color:var(--accent)}
|
|
480
|
+
.relations{margin-bottom:12px}
|
|
481
|
+
.rel-node rect{fill:var(--node);stroke:var(--fg);stroke-width:1.4}
|
|
482
|
+
.rel-node:hover rect{stroke:var(--accent)}
|
|
483
|
+
.any-node rect{fill:none;stroke:var(--muted);stroke-width:1.2;stroke-dasharray:4 3}
|
|
484
|
+
.any-node text{fill:var(--muted);font-size:12px}
|
|
485
|
+
.glossary dl{display:grid;grid-template-columns:max-content 1fr;gap:6px 16px;margin:0}
|
|
486
|
+
.glossary dt{font-weight:600}
|
|
487
|
+
.glossary .kind{font-size:11px;color:var(--muted);font-weight:400;margin-left:4px}
|
|
488
|
+
.glossary .sub{display:block;color:var(--muted);font-size:13px}
|
|
489
|
+
.ev{display:block;font-size:13px}
|
|
490
|
+
code.evidence{font-size:12px}
|
|
491
|
+
table.decision{border-collapse:collapse;margin:8px 0 20px;background:var(--card);border:1px solid var(--line);border-radius:10px;overflow:hidden;font-size:14px}
|
|
492
|
+
table.decision th,table.decision td{padding:6px 14px;border-bottom:1px solid var(--line);text-align:left}
|
|
493
|
+
table.decision th{color:var(--muted);font-weight:600;font-size:12.5px}
|
|
494
|
+
table.decision td.result{font-weight:600}
|
|
495
|
+
table.decision tr.ng td.result{color:var(--warn)}
|
|
496
|
+
.decisions h3{font-size:15px;margin:16px 0 4px}
|
|
497
|
+
.scenario-card{margin-bottom:16px}
|
|
498
|
+
.storyboard{display:flex;gap:14px;overflow-x:auto;list-style:none;margin:0;padding:0 0 6px;counter-reset:step}
|
|
499
|
+
.storyboard li{flex:0 0 220px;counter-increment:step}
|
|
500
|
+
.storyboard li::before{content:counter(step);display:inline-block;width:20px;height:20px;border-radius:50%;background:var(--accent-weak);color:var(--accent);font-size:12px;font-weight:700;text-align:center;line-height:20px;margin-bottom:4px}
|
|
501
|
+
.storyboard li.failed::before{background:var(--warn);color:var(--bg)}
|
|
502
|
+
.storyboard .step{margin:0 0 4px;font-size:13px;font-weight:600}
|
|
503
|
+
.storyboard .flow{margin:0 0 8px;font-size:12px;display:inline-block}
|
|
504
|
+
.storyboard .reason{margin:0;color:var(--warn);font-size:12.5px}
|
|
505
|
+
.storyboard .frame{height:200px;overflow:hidden;border-radius:8px}
|
|
506
|
+
.storyboard .frame-inner{width:366px;transform:scale(.6);transform-origin:0 0;pointer-events:none}
|
|
507
|
+
.state.rest{background:none;border:1px dashed var(--line)}
|
|
508
|
+
.reason{font-weight:600;margin-right:4px}
|
|
509
|
+
.muted{color:var(--muted);font-size:13px;display:block}
|
|
510
|
+
.findings ul{padding-left:20px}.findings li{color:var(--warn)}
|
|
511
|
+
.ok-line{color:var(--ok)}
|
|
512
|
+
@media (max-width:960px){.top{flex-direction:column;align-items:flex-start;padding:28px 20px 20px}main{padding:16px 20px 48px}.panel{left:16px;right:16px;width:auto;top:auto;bottom:16px;max-height:60vh}}
|
|
513
|
+
@media print{.panel,.board .hint{display:none}.card{break-inside:avoid}}
|
|
514
|
+
`;
|
|
515
|
+
// クライアントの描画で innerHTML を使わない理由: 状態名や理由は spec 由来の文字列なので、
|
|
516
|
+
// textContent で組み立てて HTML として解釈される余地をなくすため。
|
|
517
|
+
const CLIENT = `
|
|
518
|
+
(function () {
|
|
519
|
+
var data = JSON.parse(document.getElementById("live-spec-data").textContent);
|
|
520
|
+
var panel = document.getElementById("panel");
|
|
521
|
+
var current = null;
|
|
522
|
+
|
|
523
|
+
function el(tag, cls, text) {
|
|
524
|
+
var e = document.createElement(tag);
|
|
525
|
+
if (cls) e.className = cls;
|
|
526
|
+
if (text != null) e.textContent = text;
|
|
527
|
+
return e;
|
|
528
|
+
}
|
|
529
|
+
function all(sel) { return Array.prototype.slice.call(document.querySelectorAll(sel)); }
|
|
530
|
+
// 表示中のページの中だけを探す。状態の ID はドメインオブジェクトごとに s0 から振られるので、
|
|
531
|
+
// ページをまたいで探すと別のオブジェクトの状態まで選んでしまう。
|
|
532
|
+
function within(sel) { return current ? Array.prototype.slice.call(current.el.querySelectorAll(sel)) : []; }
|
|
533
|
+
function attr(name, value) { return "[" + name + '="' + CSS.escape(value) + '"]'; }
|
|
534
|
+
function hashOf(name, state) { return "#/" + encodeURIComponent(name) + (state ? "/" + encodeURIComponent(state) : ""); }
|
|
535
|
+
function clear() {
|
|
536
|
+
all(".is-selected,.is-active,.is-dim").forEach(function (n) { n.classList.remove("is-selected", "is-active", "is-dim"); });
|
|
537
|
+
}
|
|
538
|
+
function dimAll() { within(".node,.edge").forEach(function (n) { n.classList.add("is-dim"); }); }
|
|
539
|
+
function undim(n) { if (n) n.classList.remove("is-dim"); }
|
|
540
|
+
function nodes(id) { return within(".node" + attr("data-state", id)); }
|
|
541
|
+
function closePanel() { clear(); panel.replaceChildren(); panel.hidden = true; }
|
|
542
|
+
function reset() {
|
|
543
|
+
closePanel();
|
|
544
|
+
if (current && current.name) history.replaceState(null, "", hashOf(current.name));
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function list(items, render) {
|
|
548
|
+
var ul = el("ul");
|
|
549
|
+
if (items.length === 0) ul.append(el("li", "sub", "なし"));
|
|
550
|
+
items.forEach(function (item) { ul.append(render(item)); });
|
|
551
|
+
return ul;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function selectState(id) {
|
|
555
|
+
var page = current && data.pages[current.name];
|
|
556
|
+
var s = page && page.states.find(function (x) { return x.id === id; });
|
|
557
|
+
if (!s) return;
|
|
558
|
+
clear(); dimAll();
|
|
559
|
+
// 選択を URL の hash に残す理由: リンクで共有でき、--serve で自動再読み込みしたあとも同じ状態を見続けられるため。
|
|
560
|
+
history.replaceState(null, "", hashOf(current.name, id));
|
|
561
|
+
nodes(id).forEach(function (n) { n.classList.add("is-selected"); undim(n); });
|
|
562
|
+
within(".edge" + attr("data-from", id)).forEach(function (e) {
|
|
563
|
+
e.classList.add("is-active"); undim(e);
|
|
564
|
+
nodes(e.dataset.to).forEach(undim);
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
panel.replaceChildren();
|
|
568
|
+
panel.hidden = false;
|
|
569
|
+
panel.append(el("p", "eyebrow", current.name + " の状態"), el("h2", null, s.label));
|
|
570
|
+
if (s.initial) panel.append(el("span", "tag", "初期状態"));
|
|
571
|
+
if (s.terminal) panel.append(el("span", "tag", "終端"));
|
|
572
|
+
s.violations.forEach(function (v) { panel.append(el("p", "violation", "⚠ 不変条件「" + v + "」を破っています")); });
|
|
573
|
+
(page.questions[id] || []).forEach(function (q) { panel.append(el("p", "violation", "? 未決: " + q)); });
|
|
574
|
+
(page.terms[id] || []).forEach(function (t) { panel.append(el("p", "sub", t)); });
|
|
575
|
+
if (s.surfaces.length > 0) {
|
|
576
|
+
panel.append(el("h3", null, "見える画面"));
|
|
577
|
+
s.surfaces.forEach(function (g) {
|
|
578
|
+
var group = el("div", "wf-group");
|
|
579
|
+
group.append(el("span", "sub", g.actors.join(", ") + " が見る画面"));
|
|
580
|
+
group.append(document.getElementById(g.template).content.cloneNode(true));
|
|
581
|
+
panel.append(group);
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
panel.append(el("h3", null, "できること(" + s.can.length + ")"));
|
|
585
|
+
panel.append(list(s.can, function (c) {
|
|
586
|
+
var li = el("li");
|
|
587
|
+
li.append(el("strong", null, c.action), document.createTextNode(" → " + c.to), el("span", "sub", c.actors.join(", ")));
|
|
588
|
+
return li;
|
|
589
|
+
}));
|
|
590
|
+
panel.append(el("h3", null, "できないこと(" + s.cannot.length + ")"));
|
|
591
|
+
panel.append(list(s.cannot, function (c) {
|
|
592
|
+
var li = el("li");
|
|
593
|
+
li.append(el("strong", null, c.action), el("span", "sub", c.reason));
|
|
594
|
+
return li;
|
|
595
|
+
}));
|
|
596
|
+
var button = el("button", null, "選択を解除");
|
|
597
|
+
button.setAttribute("data-clear", "");
|
|
598
|
+
panel.append(button);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function selectAction(name) {
|
|
602
|
+
reset(); dimAll();
|
|
603
|
+
within(".edge" + attr("data-action", name)).forEach(function (e) {
|
|
604
|
+
e.classList.add("is-active"); undim(e);
|
|
605
|
+
nodes(e.dataset.from).forEach(undim);
|
|
606
|
+
nodes(e.dataset.to).forEach(undim);
|
|
607
|
+
});
|
|
608
|
+
within(".card" + attr("data-action", name)).forEach(function (c) { c.classList.add("is-selected"); });
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function setMode(mode) {
|
|
612
|
+
var board = current && current.el.querySelector(".board");
|
|
613
|
+
if (!board) return;
|
|
614
|
+
board.dataset.mode = mode;
|
|
615
|
+
within(".modes button").forEach(function (b) { b.setAttribute("aria-pressed", String(b.dataset.mode === mode)); });
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function show(name) {
|
|
619
|
+
var page = document.querySelector(".page" + attr("data-page", name));
|
|
620
|
+
if (!page) return false;
|
|
621
|
+
all(".page").forEach(function (p) { p.hidden = p !== page; });
|
|
622
|
+
all(".tabs a").forEach(function (a) {
|
|
623
|
+
if (a.dataset.tab === name) a.setAttribute("aria-current", "page"); else a.removeAttribute("aria-current");
|
|
624
|
+
});
|
|
625
|
+
var changed = !current || current.name !== name;
|
|
626
|
+
current = { name: name, el: page };
|
|
627
|
+
if (changed) window.scrollTo(0, 0);
|
|
628
|
+
return true;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// ページは URL の hash で表す(#/ が一覧、#/<名前> がドメインオブジェクト、#/<名前>/<状態> が状態の選択)。
|
|
632
|
+
// ブラウザの戻る・進むでページを行き来でき、リンクでそのまま共有できる。
|
|
633
|
+
function route() {
|
|
634
|
+
var parts = location.hash.replace(/^#\\/?/, "").split("/").filter(Boolean).map(decodeURIComponent);
|
|
635
|
+
var name = parts[0] || data.single || "";
|
|
636
|
+
closePanel();
|
|
637
|
+
if (!show(name)) show(data.single || "");
|
|
638
|
+
if (parts[1] && current && current.name) selectState(parts[1]);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function selectScenario(name) {
|
|
642
|
+
var page = current && data.pages[current.name];
|
|
643
|
+
var steps = page && page.scenarios[name];
|
|
644
|
+
if (!steps) return;
|
|
645
|
+
reset(); dimAll();
|
|
646
|
+
steps.forEach(function (st) {
|
|
647
|
+
within(".edge" + attr("data-from", st.from) + attr("data-to", st.to) + attr("data-action", st.action)).forEach(function (e) {
|
|
648
|
+
e.classList.add("is-active"); undim(e);
|
|
649
|
+
});
|
|
650
|
+
nodes(st.from).forEach(undim);
|
|
651
|
+
nodes(st.to).forEach(undim);
|
|
652
|
+
});
|
|
653
|
+
within(".scenario-card" + attr("data-scenario", name)).forEach(function (c) { c.classList.add("is-selected"); });
|
|
654
|
+
var board = current.el.querySelector(".board");
|
|
655
|
+
if (board) board.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function activate(target) {
|
|
659
|
+
var scenario = target.closest(".scenario-card");
|
|
660
|
+
if (scenario) return selectScenario(scenario.dataset.scenario);
|
|
661
|
+
var modeButton = target.closest(".modes button");
|
|
662
|
+
if (modeButton) return setMode(modeButton.dataset.mode);
|
|
663
|
+
if (target.closest("[data-clear]")) return reset();
|
|
664
|
+
var node = target.closest(".node");
|
|
665
|
+
if (node) return selectState(node.dataset.state);
|
|
666
|
+
var action = target.closest(".edge,.card[data-action]");
|
|
667
|
+
if (action) return selectAction(action.dataset.action);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
document.addEventListener("click", function (ev) { activate(ev.target); });
|
|
671
|
+
document.addEventListener("change", function (ev) {
|
|
672
|
+
if (!ev.target.classList || !ev.target.classList.contains("viewpoint-select")) return;
|
|
673
|
+
within(".thumb").forEach(function (t) { t.hidden = t.dataset.actor !== ev.target.value; });
|
|
674
|
+
});
|
|
675
|
+
document.addEventListener("keydown", function (ev) {
|
|
676
|
+
if (ev.key === "Escape") return reset();
|
|
677
|
+
if ((ev.key === "Enter" || ev.key === " ") && ev.target.closest && ev.target.closest(".node,.card[data-action]")) {
|
|
678
|
+
ev.preventDefault();
|
|
679
|
+
activate(ev.target);
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
window.addEventListener("hashchange", route);
|
|
683
|
+
route();
|
|
684
|
+
})();
|
|
685
|
+
`;
|