"""Exploration & planning templates.
- exploration.comparison_grid : N options side-by-side with pros/cons/tags.
- exploration.design_directions: Visual direction cards with sample swatches.
- exploration.implementation_plan: Milestones, risks, and a flow sketch.
"""
from __future__ import annotations
import composer as c
from . import register
# --------------------------------------------------------------------------- #
# comparison_grid #
# --------------------------------------------------------------------------- #
@register(
"exploration.comparison_grid",
summary="N options side-by-side: verdict, summary, pros, cons, tags.",
spec_keys={
"title": "Page title.",
"subtitle": "Optional sub-headline.",
"options": "List[{name, verdict, summary, pros[], cons[], tags[]}].",
"recommendation": "Optional name of the recommended option (highlighted).",
},
)
def comparison_grid(spec: dict) -> dict:
options = spec.get("options", [])
rec = spec.get("recommendation")
cards = []
for opt in options:
is_rec = rec and opt.get("name") == rec
head_badge = c.badge("recommended", "clay") if is_rec else ""
body = (
(f'
'
f'
{c.esc(opt.get("name"))}
{head_badge}')
+ (f'{c.esc(opt.get("verdict"))}
' if opt.get("verdict") else "")
+ (f'{c.esc(opt.get("summary"))}
' if opt.get("summary") else "")
+ (f'PROS
{c.bullets(opt.get("pros") or [])}' if opt.get("pros") else "")
+ (f'CONS
{c.bullets(opt.get("cons") or [])}' if opt.get("cons") else "")
+ (f'{"".join(c.badge(t) for t in (opt.get("tags") or []))}
' if opt.get("tags") else "")
)
cards.append(c.card(body, elev=is_rec, extra_class="opt-card" + (" opt-rec" if is_rec else "")))
body_html = c.section(body=c.grid(cards, cols=min(3, max(1, len(cards)))))
extra_css = """
.opt-card { display: flex; flex-direction: column; }
.opt-rec { border-color: var(--clay); border-width: 2px; }
"""
return {
"title": spec.get("title", "Comparison"),
"subtitle": spec.get("subtitle"),
"eyebrow_text": spec.get("eyebrow", "EXPLORATION"),
"body": body_html,
"extra_css": extra_css,
}
# --------------------------------------------------------------------------- #
# design_directions #
# --------------------------------------------------------------------------- #
@register(
"exploration.design_directions",
summary="Visual design directions: name, vibe, palette swatches, sample type.",
spec_keys={
"title": "Page title.",
"subtitle": "Optional sub-headline.",
"directions": "List[{name, vibe, palette: [hex...], typography: {display, body}, notes}].",
},
)
def design_directions(spec: dict) -> dict:
cards = []
for d in spec.get("directions", []):
palette = d.get("palette") or []
swatches = "".join(
f''
for hx in palette
)
typo = d.get("typography") or {}
sample = ""
if typo:
disp = c.esc(typo.get("display", "Aa"))
body = c.esc(typo.get("body", "The quick brown fox jumps over the lazy dog."))
sample = (f'')
body = (
f'{c.esc(d.get("name"))}
'
+ (f'{c.esc(d.get("vibe"))}
' if d.get("vibe") else "")
+ (f'{swatches}
' if palette else "")
+ sample
+ (f'{c.esc(d.get("notes"))}
' if d.get("notes") else "")
)
cards.append(c.card(body))
body_html = c.section(body=c.grid(cards, cols=min(3, max(1, len(cards)))))
return {
"title": spec.get("title", "Design directions"),
"subtitle": spec.get("subtitle"),
"eyebrow_text": spec.get("eyebrow", "EXPLORATION"),
"body": body_html,
}
# --------------------------------------------------------------------------- #
# implementation_plan #
# --------------------------------------------------------------------------- #
@register(
"exploration.implementation_plan",
summary="Implementation plan: milestones, owners, risks, and an optional flow sketch.",
spec_keys={
"title": "Page title.",
"subtitle": "Optional sub-headline.",
"summary_html": "Optional rich HTML intro (one or two paragraphs).",
"milestones": "List[{name, when, owner?, deliverables: [str], status?: 'done|active|next|later'}].",
"risks": "List[{risk, likelihood: 'low|med|high', impact: 'low|med|high', mitigation}].",
"data_flow": "Optional list of strings; rendered as arrow-connected boxes (left-to-right).",
},
)
def implementation_plan(spec: dict) -> dict:
# Milestones as a vertical timeline
status_color = {"done": "var(--ok)", "active": "var(--clay)", "next": "var(--info)", "later": "var(--g500)"}
owner_style = "font-family:var(--mono);font-size:12px;color:var(--g500);margin-bottom:6px;"
ms_rows = []
for m in spec.get("milestones", []):
sc = status_color.get(m.get("status", "next"), "var(--g500)")
deliverables = c.bullets(m.get("deliverables") or [])
owner_html = f'{c.esc(m.get("owner"))}
' if m.get("owner") else ""
ms_rows.append(
f''
f'
{c.esc(m.get("when"))}
'
f'{(c.badge(m.get("status","next").upper(), kind="info") if m.get("status") else "")}
'
f'
'
f'
{c.esc(m.get("name"))}
'
f'{owner_html}'
f'{deliverables}'
f'
'
)
milestones_html = c.section("Milestones", body="".join(ms_rows)) if ms_rows else ""
# Risks table
risks = spec.get("risks") or []
risks_html = ""
if risks:
rows = [[r.get("risk"),
c.raw(c.badge((r.get("likelihood") or "med").upper(), "warn")),
c.raw(c.badge((r.get("impact") or "med").upper(), "err")),
r.get("mitigation")] for r in risks]
risks_html = c.section("Risks", body=c.table(["Risk", "Likelihood", "Impact", "Mitigation"], rows))
# Data flow boxes
flow = spec.get("data_flow") or []
flow_html = ""
if flow:
boxes = []
for i, step in enumerate(flow):
boxes.append(f'{c.esc(step)}
')
if i < len(flow) - 1:
boxes.append('→
')
flow_html = c.section("Data flow",
body=f'{"".join(boxes)}
')
summary_html = spec.get("summary_html") or ""
body = ((f'' if summary_html else "")
+ flow_html + milestones_html + risks_html)
extra_css = """
.flow-row { display:flex; align-items:center; gap:14px; flex-wrap:wrap; }
.flow-box { background:var(--paper); border:var(--border); border-radius:var(--radius);
padding:14px 18px; font-family:var(--mono); font-size:13px; min-width:120px;
text-align:center; }
.flow-arrow { color:var(--clay); font-size:24px; font-weight:700; }
"""
return {
"title": spec.get("title", "Implementation plan"),
"subtitle": spec.get("subtitle"),
"eyebrow_text": spec.get("eyebrow", "PLAN"),
"body": body,
"extra_css": extra_css,
}