Files
Gabriel VidalandClaude Opus 5.5 3d7c7192ba docs(mockups): animated conversation-page motion mockups
- docs/mockups/conversation-motion.html: the review sheet — 41 looping
  mockups (35 proposals, 6 of today's behaviour) for every element of the
  conversation page that snaps today: new rows, Claude typing, your sent
  message's hand-off, status tags, dividers, the jump flash, summary folds,
  page swaps, opening any card, calls finishing and grouping, every widget's
  state change, the waiting card, task panel, corner gizmos, strips, menus
  and the header; replay and ½× / ¼× per section
- conversation-motion/build.py + kit.py: one generator for the sheet and
  the form's script-free snippets (each one its own iframe in ask-form)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 19:45:20 +01:00

318 lines
17 KiB
Python

"""Building blocks for the conversation-motion mockups (build.py).
Every mockup is one self-contained, script-free HTML snippet: the app's dark
tokens + the primitives below + its own keyframes, looping on a cycle of
`--T` seconds. The same snippet goes into the ask-form (each block/option is
its own sandboxed iframe — no scripts, inline styles only) and into the
review page (one shadow root each, so the styles never meet). The review page
scales every cycle with `--spd` (½×, ¼×).
"""
from __future__ import annotations
import re
# ── the app (dark) — frontend/src/index.css `.dark` ──────────────────────────
BASE_CSS = """
*{box-sizing:border-box}
.ph{--bg:#0a0a0a;--card:#121212;--border:#2e2e2e;--muted:#212121;--mfg:#999;--fg:#f2f2f2;
--pr:#f97a1f;--amber:#f59e0b;--em:#10b981;--red:#ef4444;--vio:#a78bfa;--sky:#38bdf8;--rose:#f43f5e;
--ui:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;--mono:ui-monospace,SFMono-Regular,Menlo,monospace;
position:relative;width:360px;background:var(--bg);color:var(--fg);border:1px solid #262626;border-radius:18px;
overflow:hidden;font:12.5px/1.45 var(--ui);-webkit-font-smoothing:antialiased}
.ph i{font-style:normal}
.ph svg{display:block;flex:none}
/* the thread: bottom-anchored like a pinned scroller — a row that makes room pushes the rest up */
.th{position:absolute;left:0;right:0;top:0;padding:10px;display:flex;flex-direction:column;justify-content:flex-end;gap:8px;overflow:hidden}
.th>*{flex:none}
.slot{overflow:hidden}
/* a message card (ThreadRow) */
.c{border:1px solid var(--border);border-radius:12px;background:var(--card);padding:8px 11px 9px}
.c.you{border-color:rgba(249,122,31,.32);background:#16100b}
.hd{display:flex;align-items:center;gap:5px;margin-bottom:3px;font-size:10.5px;font-weight:600;color:var(--mfg);white-space:nowrap}
.hd .ts{font:400 9.5px var(--mono);color:#777}
.hd .r{margin-left:auto;font:400 9.5px var(--mono);color:#777}
.bd{font-size:12.5px;line-height:1.5;color:var(--fg)}
.ln{display:block;white-space:nowrap;overflow:hidden}
/* a tool row / group (ToolUse, ToolGroup) */
.tr{display:flex;align-items:center;gap:6px;border:1px solid var(--border);border-radius:9px;background:var(--card);padding:5px 9px;font-size:11.5px;white-space:nowrap;overflow:hidden}
.tr b{font-weight:600}
.tr .tg{font:10.5px var(--mono);color:var(--mfg);overflow:hidden;text-overflow:ellipsis}
.tr .r{margin-left:auto;display:flex;align-items:center;gap:6px;font:10px var(--mono);color:#777}
.add{color:var(--em)}.del{color:var(--red)}
.box{border:1px solid var(--border);border-radius:9px;background:var(--card);overflow:hidden}
.box>.tr{border:0;border-radius:0}
.out{border-top:1px solid var(--border);padding:6px 10px;font:10px/1.55 var(--mono);color:#bbb;background:#0e0e0e}
/* pills */
.pl{display:inline-flex;align-items:center;gap:4px;border-radius:999px;padding:2px 8px;font-size:9.5px;font-weight:600;text-transform:uppercase;letter-spacing:.04em;white-space:nowrap}
.pl.amber{color:var(--amber);background:rgba(245,158,11,.1);border:1px solid rgba(245,158,11,.3)}
.pl.rose{color:var(--rose);background:rgba(244,63,94,.1);border:1px solid rgba(244,63,94,.3)}
.pl.slate{color:#94a3b8;background:rgba(100,116,139,.1);border:1px solid rgba(100,116,139,.3)}
.pl.em{color:var(--em);background:rgba(16,185,129,.12);border:1px solid rgba(16,185,129,.35)}
.pl.sky{color:var(--sky);background:rgba(56,189,248,.12);border:1px solid rgba(56,189,248,.3)}
.pl.pr{color:var(--pr);background:rgba(249,122,31,.1);border:1px solid rgba(249,122,31,.3)}
.pl.n{text-transform:none;letter-spacing:0;font-weight:500}
.tag{display:inline-flex;align-items:center;gap:3px;border:1px solid var(--border);border-radius:999px;padding:1px 7px;font-size:10px;color:var(--mfg);white-space:nowrap}
/* the composer (ResumeBox) */
.cmp{position:absolute;left:10px;right:10px;bottom:10px;height:44px;border:1px solid var(--border);border-radius:12px;background:var(--card);
display:flex;align-items:center;padding:0 6px 0 12px;font:12px var(--mono);color:#6f6f6f;z-index:5}
.cmp .tx{color:var(--fg)}
.cmp .go{margin-left:auto;width:30px;height:30px;border-radius:9px;display:grid;place-items:center;background:var(--muted);color:var(--mfg)}
.cmp .go.on{background:var(--pr);color:#0a0a0a}
.dock{position:absolute;left:0;right:0;bottom:0;height:64px;background:var(--bg);border-top:1px solid #1f1f1f;z-index:4}
/* floating corner gizmos */
.gz{position:absolute;bottom:74px;z-index:6;display:flex;align-items:center;gap:5px;border:1px solid var(--border);border-radius:999px;background:rgba(18,18,18,.92);
padding:4px 9px;font-size:10.5px;font-weight:600;color:var(--mfg);white-space:nowrap}
.gz.l{left:10px}.gz.r{right:10px}
/* labels drawn on the mockups (not app UI) */
.cap{position:absolute;left:50%;top:8px;transform:translateX(-50%);z-index:30;font:600 9.5px/1 var(--mono);letter-spacing:.03em;color:#cfcfcf;
background:rgba(10,10,10,.8);border:1px solid #333;border-radius:999px;padding:4px 8px;white-space:nowrap}
.tap{position:absolute;z-index:40;width:26px;height:26px;margin:-13px 0 0 -13px;border-radius:50%;background:rgba(255,255,255,.35);border:2px solid rgba(255,255,255,.75);opacity:0;pointer-events:none}
.dim{color:var(--mfg)}
.mono{font-family:var(--mono)}
.cd{display:inline-block;overflow:hidden;vertical-align:bottom}.cdi{display:block}
.spin{animation:spin .9s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
"""
def _rules(css: str) -> list[str]:
"""Top-level rules of a stylesheet (one level of nesting, for @keyframes)."""
out, depth, cur = [], 0, ""
for ch in re.sub(r"\s*\n\s*", "", css):
cur += ch
if ch == "{":
depth += 1
elif ch == "}":
depth -= 1
if depth == 0:
out.append(cur)
cur = ""
return out
def _prune(base: str, used: str) -> str:
"""Keep the base rules whose classes the mockup uses (and the class-free ones)."""
names = set(re.findall(r'class="([^"]*)"', used))
classes = {c for n in names for c in n.split()} | set(re.findall(r"\.([a-zA-Z][\w-]*)", used))
keep = []
for r in _rules(base):
if r.startswith("@keyframes spin"):
if "spin" in classes:
keep.append(r)
continue
sel = r.split("{", 1)[0]
cls = set(re.findall(r"\.([a-zA-Z][\w-]*)", sel))
if not cls or cls & classes:
keep.append(r)
return "".join(keep)
# ── icons (lucide paths, 24-unit grid) ───────────────────────────────────────
_ICON = {
"bot": '<path d="M12 8V4H8"/><rect x="4" y="8" width="16" height="12" rx="2"/><path d="M2 14h2M20 14h2M15 13v2M9 13v2"/>',
"user": '<circle cx="12" cy="8" r="4"/><path d="M4 21v-1a6 6 0 0 1 6-6h4a6 6 0 0 1 6 6v1"/>',
"layers": '<path d="m12 2 9 5-9 5-9-5 9-5Z"/><path d="m3 12 9 5 9-5"/><path d="m3 17 9 5 9-5"/>',
"chev": '<path d="m9 18 6-6-6-6"/>',
"chevd": '<path d="m6 9 6 6 6-6"/>',
"term": '<path d="m4 17 6-6-6-6"/><path d="M12 19h8"/>',
"check": '<path d="M20 6 9 17l-5-5"/>',
"x": '<path d="M18 6 6 18M6 6l12 12"/>',
"loader": '<path d="M21 12a9 9 0 1 1-6.2-8.6"/>',
"file": '<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v5h6"/>',
"pen": '<path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"/>',
"search": '<circle cx="11" cy="11" r="7"/><path d="m21 21-4.3-4.3"/>',
"commit": '<circle cx="12" cy="12" r="3"/><path d="M3 12h6M15 12h6"/>',
"merge": '<circle cx="18" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><path d="M6 21V9a9 9 0 0 0 9 9"/>',
"rocket": '<path d="M4.5 16.5c-1.5 1.3-2 5-2 5s3.7-.5 5-2c.7-.8.7-2.1-.1-2.9a2.2 2.2 0 0 0-2.9-.1Z"/><path d="m12 15-3-3a22 22 0 0 1 2-3.9A12.9 12.9 0 0 1 22 2c0 2.7-.8 7.5-6 11a22.4 22.4 0 0 1-4 2Z"/>',
"brain": '<path d="M9.5 2A2.5 2.5 0 0 1 12 4.5v15a2.5 2.5 0 0 1-4.96.44 2.5 2.5 0 0 1-2.96-3.08 3 3 0 0 1-.34-5.58 2.5 2.5 0 0 1 1.32-4.24A2.5 2.5 0 0 1 9.5 2Z"/><path d="M14.5 2A2.5 2.5 0 0 0 12 4.5v15a2.5 2.5 0 0 0 4.96.44 2.5 2.5 0 0 0 2.96-3.08 3 3 0 0 0 .34-5.58 2.5 2.5 0 0 0-1.32-4.24A2.5 2.5 0 0 0 14.5 2Z"/>',
"list": '<path d="m3 17 2 2 4-4"/><path d="m3 7 2 2 4-4"/><path d="M13 6h8M13 12h8M13 18h8"/>',
"ff": '<path d="m13 19 9-7-9-7z"/><path d="m2 19 9-7-9-7z"/>',
"send": '<path d="m5 12 7-7 7 7"/><path d="M12 19V5"/>',
"form": '<rect x="4" y="3" width="16" height="18" rx="2"/><path d="M8 8h8M8 12h8M8 16h5"/>',
"bell": '<path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/>',
"alert": '<path d="m21.7 18-8-14a2 2 0 0 0-3.4 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.7-3Z"/><path d="M12 9v4M12 17h.01"/>',
"ban": '<circle cx="12" cy="12" r="10"/><path d="m4.9 4.9 14.2 14.2"/>',
"pause": '<rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/>',
"hour": '<path d="M5 22h14M5 2h14M17 22v-4.2a2 2 0 0 0-.6-1.4L12 12l-4.4 4.4a2 2 0 0 0-.6 1.4V22M7 2v4.2a2 2 0 0 0 .6 1.4L12 12l4.4-4.4a2 2 0 0 0 .6-1.4V2"/>',
"stop": '<circle cx="12" cy="12" r="10"/><rect x="9" y="9" width="6" height="6" rx="1"/>',
"arrowl": '<path d="m12 19-7-7 7-7M19 12H5"/>',
"up": '<path d="m18 15-6-6-6 6"/>',
"down": '<path d="m6 9 6 6 6-6"/>',
"msgs": '<path d="M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2Z"/><path d="M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1"/>',
"eye": '<path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/>',
"panel": '<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M15 3v18"/>',
"image": '<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.1-3.1a2 2 0 0 0-2.8 0L6 21"/>',
"globe": '<circle cx="12" cy="12" r="10"/><path d="M2 12h20M12 2a15.3 15.3 0 0 1 0 20 15.3 15.3 0 0 1 0-20"/>',
"clock": '<circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/>',
"refresh": '<path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/><path d="M8 16H3v5"/>',
"copy": '<rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>',
"fork": '<circle cx="12" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><circle cx="18" cy="6" r="3"/><path d="M18 9v2a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V9M12 13v2"/>',
"minus": '<path d="M5 12h14"/>',
"folds": '<path d="m7 20 5-5 5 5M7 4l5 5 5-5"/>',
"wave": '<path d="M2 12h3l3-8 4 16 3-8h7"/>',
}
def ic(name: str, size: int = 13, color: str = "currentColor", cls: str = "", sw: float = 2) -> str:
c = f' class="{cls}"' if cls else ""
return (
f'<svg{c} width="{size}" height="{size}" viewBox="0 0 24 24" fill="none" stroke="{color}" '
f'stroke-width="{sw}" stroke-linecap="round" stroke-linejoin="round">{_ICON[name]}</svg>'
)
# ── keyframes ────────────────────────────────────────────────────────────────
EASE_OUT = "cubic-bezier(.16,1,.3,1)"
EASE_IN = "cubic-bezier(.55,0,.75,.2)"
SPRING = "cubic-bezier(.22,1.25,.36,1)"
LIN = "linear"
def _pct(t: float, T: float) -> str:
p = max(0.0, min(100.0, t / T * 100))
s = f"{p:.3f}".rstrip("0").rstrip(".")
return f"{s}%"
REST = {"opacity": "1", "transform": "none", "clip-path": "inset(0 0 0 0)", "filter": "none", "box-shadow": "none"}
UNSET: list[tuple[str, str]] = [] # (keyframes, property) that had to borrow a later value
def _props(css: str) -> dict[str, str]:
out: dict[str, str] = {}
for part in css.split(";"):
if ":" in part:
k, v = part.split(":", 1)
out[k.strip()] = v.strip()
return out
def kf(name: str, T: float, frames: list[tuple]) -> str:
"""@keyframes from (seconds, css[, easing of the segment that starts here]).
Every property holds its value between the frames that name it: a
property missing from a frame takes the last value given (the first one,
before that). Left to CSS, a property named only in a later frame would
interpolate from the element's own value across the whole cycle.
"""
parsed = [_props(fr[1]) for fr in frames]
keys: list[str] = []
for d in parsed:
keys += [k for k in d if k not in keys]
# a property the first frame leaves out starts at its resting value
first = {}
for k in keys:
if k in parsed[0]:
first[k] = parsed[0][k]
elif k in REST:
first[k] = REST[k]
else:
first[k] = next(d[k] for d in parsed if k in d)
UNSET.append((name, k))
cur = dict(first)
out = []
for fr, d in zip(frames, parsed):
cur.update(d)
ease = fr[2] if len(fr) > 2 else None
body = ";".join(f"{k}:{cur[k]}" for k in keys) + (f";animation-timing-function:{ease}" if ease else "")
out.append(f"{_pct(fr[0], T)}{{{body}}}")
return f"@keyframes {name}{{{''.join(out)}}}"
class Mock:
"""One looping mockup: register animations, then render to a snippet."""
def __init__(self, key: str, T: float, h: int, w: int = 360):
self.key, self.T, self.h, self.w = key, T, h, w
self.css: list[str] = []
self.n = 0
def anim(self, sel: str, frames: list[tuple], extra: str = "", fill: str = "both") -> str:
"""Animate `sel` on the mockup's cycle. Returns the keyframes' name."""
self.n += 1
name = f"{re.sub(r'[^a-z0-9]', '', self.key)}{self.n}"
self.css.append(kf(name, self.T, frames))
self.css.append(
f"{sel}{{animation:{name} calc(var(--T)/var(--spd,1)) infinite {fill};{extra}}}"
)
return name
def style(self, css: str) -> None:
self.css.append(css)
def tap(self, x: int, y: int, t: float) -> str:
"""A finger tap drawn at (x, y) at time t."""
cls = f"tp{self.n + 1}"
self.anim(
f".{cls}",
[
(0, "opacity:0;transform:scale(.6)"),
(max(0, t - 0.25), "opacity:0;transform:scale(.6)", EASE_OUT),
(t, "opacity:1;transform:scale(1)"),
(t + 0.15, "opacity:1;transform:scale(.85)", EASE_OUT),
(t + 0.45, "opacity:0;transform:scale(1.2)"),
(self.T, "opacity:0;transform:scale(1.2)"),
],
)
return f'<i class="tap {cls}" style="left:{x}px;top:{y}px"></i>'
def fade_cycle(self, sel: str = ".stage", out_at: float | None = None) -> None:
"""Hide the reset: the stage fades out at the end of the cycle and back in."""
T = self.T
o = out_at if out_at is not None else T - 0.45
self.anim(
sel,
[(0, "opacity:0"), (0.25, "opacity:1"), (o, "opacity:1"), (o + 0.3, "opacity:0"), (T, "opacity:0")],
)
def html(self, body: str) -> str:
own = "".join(self.css)
css = _prune(BASE_CSS, '<div class="ph stage">' + body + own) + own
css = re.sub(r"\s*\n\s*", "", css)
return (
f'<style>{css}</style><div class="ph" style="--T:{self.T}s;width:{self.w}px;height:{self.h}px">'
f'<div class="stage" style="position:absolute;inset:0">{body}</div></div>'
)
# ── reusable markup ──────────────────────────────────────────────────────────
def claude(text_lines: list[str], ts: str = "10:12", cls: str = "", meta: str = "", line_cls: str = "") -> str:
lines = "".join(f'<span class="ln l{i}{f" {line_cls}{i}" if line_cls else ""}">{t}</span>' for i, t in enumerate(text_lines))
r = f'<span class="r">{meta}</span>' if meta else ""
return (
f'<div class="c {cls}"><div class="hd">{ic("bot", 12, "var(--pr)")}Claude'
f'<span class="ts">· Nov 3, {ts}</span>{r}</div><div class="bd">{lines}</div></div>'
)
def you(text_lines: list[str], ts: str = "10:14", cls: str = "", head_extra: str = "") -> str:
lines = "".join(f'<span class="ln">{t}</span>' for t in text_lines)
return (
f'<div class="c you {cls}"><div class="hd">{ic("user", 12)}You{head_extra}'
f'<span class="ts">· Nov 3, {ts}</span></div><div class="bd">{lines}</div></div>'
)
def group(label: str, n: int | str, cls: str = "", right: str = "") -> str:
return (
f'<div class="tr {cls}">{ic("chev", 11, "#777")}{ic("layers", 13, "var(--mfg)")}'
f'<span>{label}</span><span class="r">{right}<span>{n}</span></span></div>'
)
def tool(verb: str, target: str, icon: str = "term", cls: str = "", right: str = "") -> str:
return (
f'<div class="tr {cls}">{ic("chev", 11, "#777")}{ic(icon, 12, "var(--mfg)")}'
f'<b>{verb}</b><span class="tg">{target}</span><span class="r">{right}</span></div>'
)
def composer(text: str = "", placeholder: str = "Continue this session…", armed: bool = False, extra: str = "") -> str:
inner = f'<span class="tx">{text}</span>' if text else placeholder
go = "go on" if armed else "go"
return f'<div class="dock"></div><div class="cmp">{inner}{extra}<span class="{go}">{ic("send", 15)}</span></div>'
def cap(text: str) -> str:
return f'<span class="cap">{text}</span>'