"""Prototype templates. - prototype.animation_sandbox: Interactive parameter knobs that drive a visual element via CSS variables. - prototype.click_flow: Sequence of mockup screens with arrow links. """ from __future__ import annotations import composer as c from . import register # --------------------------------------------------------------------------- # # animation_sandbox # # --------------------------------------------------------------------------- # @register( "prototype.animation_sandbox", summary="Live-tunable parameters (sliders/selects) driving a CSS-variable preview.", spec_keys={ "title": "Page title.", "subtitle": "Optional sub-headline.", "intro_html": "Optional intro HTML.", "params": "List[{name, label, type: 'range|select', min?, max?, step?, default, unit?, options?: [str], format?: 'number|percent|ms'}]. " "Param values are exposed as CSS vars `--bind-` and live-rendered via base.js.", "preview_html": "HTML for the preview region. Use the CSS vars `--bind-` to react to params.", "preview_height": "Optional CSS height for preview region (default: '320px').", }, ) def animation_sandbox(spec: dict) -> dict: controls = [] for p in spec.get("params", []): name = p["name"] label = c.esc(p.get("label", name)) if p.get("type") == "select": opts = "".join(f'' for o in p.get("options", [])) ctl = (f'') else: ctl = (f'') controls.append( f'
' f'
' f'
' f'{ctl}
' ) preview_h = c.esc(spec.get("preview_height", "320px")) body = ((f'
{spec.get("intro_html")}
' if spec.get("intro_html") else "") + c.section(body=( f'
' f'
{spec.get("preview_html","")}
' f'
{"".join(controls)}
' f'
' ))) extra_css = """ .sandbox { display: grid; grid-template-columns: 1fr 280px; gap: 24px; } @media (max-width: 880px) { .sandbox { grid-template-columns: 1fr; } } .sandbox-preview { background: var(--paper); border: var(--border); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; overflow: hidden; } .sandbox-controls { display: flex; flex-direction: column; gap: 18px; background: var(--g100); border: var(--border-soft); border-radius: var(--radius); padding: 20px; } .ctrl-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; } .ctrl-row label { font-family: var(--mono); font-size: 12px; color: var(--g700); } .ctrl-val { font-family: var(--mono); font-size: 12px; color: var(--clay-d); } .ctrl input[type="range"], .ctrl select { width: 100%; } """ return { "title": spec.get("title", "Prototype"), "subtitle": spec.get("subtitle"), "eyebrow_text": spec.get("eyebrow", "PROTOTYPE"), "body": body, "extra_css": extra_css, } # --------------------------------------------------------------------------- # # click_flow # # --------------------------------------------------------------------------- # @register( "prototype.click_flow", summary="Sequence of mockup screens connected by labelled arrows.", spec_keys={ "title": "Page title.", "subtitle": "Optional sub-headline.", "screens": "List[{id, label, html, transitions?: [{label, to_id}]}].", }, ) def click_flow(spec: dict) -> dict: screens = spec.get("screens") or [] cards = [] for s in screens: trs = "" if s.get("transitions"): chips = " ".join( f'{c.esc(t.get("label","→"))}' for t in s["transitions"] ) trs = f'
{chips}
' cards.append( f'
' f'
{c.esc(s.get("label"))}
' f'
{s.get("html","")}
' f'{trs}
' ) body = c.section(body=f'
{"".join(cards)}
') extra_css = """ .flow-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 24px; } .screen { display: flex; flex-direction: column; background: var(--paper); border: var(--border); border-radius: var(--radius); overflow: hidden; } .screen-head { padding: 10px 14px; background: var(--g100); font-family: var(--mono); font-size: 12px; color: var(--g500); } .screen-body { padding: 16px; flex: 1; min-height: 200px; } .screen-tr { padding: 10px 14px; border-top: 1px solid var(--g150); display: flex; gap: 8px; flex-wrap: wrap; } .tr { background: var(--oat); color: var(--clay-d); font-family: var(--mono); font-size: 11px; padding: 4px 10px; border-radius: 999px; text-decoration: none; } .tr:hover { background: var(--clay); color: white; } """ return { "title": spec.get("title", "Click flow"), "subtitle": spec.get("subtitle"), "eyebrow_text": spec.get("eyebrow", "PROTOTYPE"), "body": body, "extra_css": extra_css, "page_class": "page page--wide", }