137 lines
6.6 KiB
TypeScript
137 lines
6.6 KiB
TypeScript
// PEP-70: Peppa's mascot — a soft "clay" chibi pug whose face is a terminal screen (`> _`).
|
||
// Pure SVG (no external images), fixed colours that read on both themes; motion only without
|
||
// reduced-motion (see .pug-* in app.css).
|
||
import { useId } from "react";
|
||
import { cn } from "@/lib/utils";
|
||
|
||
type Mood = "sleep" | "alert";
|
||
|
||
export function PugMascot({ mood, size = 96, className }: { mood: Mood; size?: number; className?: string }) {
|
||
const awake = mood === "alert";
|
||
const id = useId().replace(/[^a-zA-Z0-9]/g, "");
|
||
const fur = `pf${id}`, furDark = `pd${id}`, ear = `pe${id}`, screen = `ps${id}`, glow = `pg${id}`, soft = `po${id}`;
|
||
return (
|
||
<svg
|
||
viewBox="0 0 120 140"
|
||
width={(size * 120) / 140}
|
||
height={size}
|
||
role="img"
|
||
aria-label={awake ? "Мопс Пеппы ждёт твоего ответа" : "Мопс Пеппы спит"}
|
||
className={cn("shrink-0 overflow-visible", awake ? "pug-alert" : "pug-sleep", className)}
|
||
>
|
||
<defs>
|
||
<radialGradient id={fur} cx="35%" cy="28%" r="80%">
|
||
<stop offset="0" stopColor="#fbe6c4" />
|
||
<stop offset="0.55" stopColor="#e8bd86" />
|
||
<stop offset="1" stopColor="#b98550" />
|
||
</radialGradient>
|
||
<radialGradient id={furDark} cx="35%" cy="25%" r="85%">
|
||
<stop offset="0" stopColor="#f3d3a4" />
|
||
<stop offset="0.6" stopColor="#dcaa6e" />
|
||
<stop offset="1" stopColor="#a77443" />
|
||
</radialGradient>
|
||
<radialGradient id={ear} cx="35%" cy="30%" r="80%">
|
||
<stop offset="0" stopColor="#6b544b" />
|
||
<stop offset="1" stopColor="#2a201d" />
|
||
</radialGradient>
|
||
<linearGradient id={screen} x1="0" y1="0" x2="0" y2="1">
|
||
<stop offset="0" stopColor="#2b3157" />
|
||
<stop offset="1" stopColor="#11142a" />
|
||
</linearGradient>
|
||
<filter id={glow} x="-50%" y="-50%" width="200%" height="200%">
|
||
<feGaussianBlur stdDeviation="1.6" result="b" />
|
||
<feMerge>
|
||
<feMergeNode in="b" />
|
||
<feMergeNode in="SourceGraphic" />
|
||
</feMerge>
|
||
</filter>
|
||
<filter id={soft} x="-20%" y="-20%" width="140%" height="140%">
|
||
<feDropShadow dx="0" dy="2" stdDeviation="1.5" floodColor="#000" floodOpacity="0.25" />
|
||
</filter>
|
||
</defs>
|
||
|
||
{/* floor shadow */}
|
||
<ellipse cx="60" cy="135" rx="30" ry="4" fill="#000" opacity="0.28" />
|
||
|
||
<g className="pug-body" style={{ transformOrigin: "60px 135px" }} filter={`url(#${soft})`}>
|
||
{/* curly tail */}
|
||
<path d="M82 108 C99 108 103 92 93 89 C86 87 84 96 91 97" fill="none" stroke="#d29c63" strokeWidth="7" strokeLinecap="round" />
|
||
{/* legs */}
|
||
<rect x="42" y="110" width="15" height="22" rx="7.5" fill={`url(#${furDark})`} />
|
||
<rect x="63" y="110" width="15" height="22" rx="7.5" fill={`url(#${furDark})`} />
|
||
{/* body */}
|
||
<ellipse cx="60" cy="102" rx="27" ry="22" fill={`url(#${fur})`} />
|
||
{/* arms */}
|
||
<ellipse cx="34" cy="101" rx="7" ry="11" transform="rotate(22 34 101)" fill={`url(#${furDark})`} />
|
||
<ellipse cx="86" cy="101" rx="7" ry="11" transform="rotate(-22 86 101)" fill={`url(#${furDark})`} />
|
||
{/* belly prompt */}
|
||
<g stroke="#e9f6ff" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" fill="none" opacity="0.9">
|
||
<path d="M52 100 L57 104 L52 108" />
|
||
<path d="M61 108 L69 108" />
|
||
</g>
|
||
|
||
<g className="pug-head" style={{ transformOrigin: "60px 88px" }}>
|
||
{/* head */}
|
||
<ellipse cx="60" cy="54" rx="47" ry="40" fill={`url(#${fur})`} />
|
||
{/* folded button ears */}
|
||
<path d="M34 22 C22 12 5 17 4 34 C3 43 10 47 16 41 C21 36 27 31 37 28 Z" fill={`url(#${ear})`} />
|
||
<path d="M86 22 C98 12 115 17 116 34 C117 43 110 47 104 41 C99 36 93 31 83 28 Z" fill={`url(#${ear})`} />
|
||
{/* forehead wrinkles */}
|
||
<path d="M47 24 Q60 18 73 24" fill="none" stroke="#c08a55" strokeWidth="2.5" strokeLinecap="round" opacity="0.8" />
|
||
<path d="M51 30 Q60 26 69 30" fill="none" stroke="#c08a55" strokeWidth="2.5" strokeLinecap="round" opacity="0.8" />
|
||
{/* cheeks */}
|
||
<ellipse cx="20" cy="66" rx="6" ry="3.5" fill="#f29aa3" opacity="0.6" />
|
||
<ellipse cx="100" cy="66" rx="6" ry="3.5" fill="#f29aa3" opacity="0.6" />
|
||
{/* screen face (the pug's black mask) */}
|
||
<rect x="27" y="36" width="66" height="44" rx="15" fill={`url(#${screen})`} stroke="#0b0d1c" strokeWidth="1.5" />
|
||
<path d="M35 42 Q44 38 60 39" fill="none" stroke="#fff" strokeWidth="2.5" strokeLinecap="round" opacity="0.18" />
|
||
{awake ? (
|
||
<g filter={`url(#${glow})`} stroke="#a6f0ff" strokeWidth="5" strokeLinecap="round" strokeLinejoin="round" fill="none">
|
||
<path d="M42 50 L52 58 L42 66" />
|
||
<path className="pug-cursor" d="M61 66 L77 66" />
|
||
</g>
|
||
) : (
|
||
<g stroke="#a6f0ff" strokeWidth="4" strokeLinecap="round" fill="none" opacity="0.45">
|
||
<path d="M39 58 Q46 63 53 58" />
|
||
<path d="M67 58 Q74 63 81 58" />
|
||
</g>
|
||
)}
|
||
</g>
|
||
</g>
|
||
|
||
{!awake && (
|
||
<g className="pug-zzz" fill="currentColor" fontWeight="700" opacity="0.55">
|
||
<text x="104" y="16" fontSize="13">z</text>
|
||
<text x="113" y="5" fontSize="9">z</text>
|
||
</g>
|
||
)}
|
||
</svg>
|
||
);
|
||
}
|
||
|
||
/** Mascot with a speech bubble: sleeps when nothing waits, perks up when agents ask. */
|
||
export function PugBanner({ count }: { count: number }) {
|
||
const awake = count > 0;
|
||
return (
|
||
<div className="flex items-center gap-3">
|
||
<PugMascot mood={awake ? "alert" : "sleep"} className="text-muted-foreground" />
|
||
<div className="relative rounded-2xl border bg-card px-4 py-2.5 text-sm shadow-xs before:absolute before:top-1/2 before:-left-[7px] before:size-3 before:-translate-y-1/2 before:rotate-45 before:border-b before:border-l before:bg-card">
|
||
{awake ? (
|
||
<>
|
||
<span className="font-medium">Гав! {count === 1 ? "Агент ждёт" : "Агенты ждут"} твоего ответа</span>
|
||
<span className="text-muted-foreground"> — {plural(count)} ниже.</span>
|
||
</>
|
||
) : (
|
||
<span className="text-muted-foreground">Тихо… Агентам от тебя ничего не нужно, мопс спит.</span>
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function plural(n: number) {
|
||
const m10 = n % 10, m100 = n % 100;
|
||
const w = m10 === 1 && m100 !== 11 ? "вопрос" : m10 >= 2 && m10 <= 4 && (m100 < 12 || m100 > 14) ? "вопроса" : "вопросов";
|
||
return `${n} ${w}`;
|
||
}
|