import { useState } from 'react'; import MascotClip from './trek3d/MascotClip'; import { findClip, mascot3dEnabled } from './trek3d/mascotClips'; /** * The TREK mascot — an empty-state character that IS the TREK mark: the logo is * the whole body, no arms, no legs. Two eyes give it life; a soft idle keeps it * breathing and blinking, and a ground shadow anchors it. Monochrome * (currentColor, theme-driven) and it holds a single pose under reduced motion. * * Two orthogonal props drive personality: * - `scene` picks the prop + body motion for a page (skateboard, suitcase, …). * - `mood` picks the facial expression (default / happy / sleepy / confused / * error) so loading and error states can reuse the same face. Scenes carry a * sensible default mood (notifications → sleepy, search → confused) that an * explicit `mood` overrides. * * Body motion (`.trek-bounce--`) and each prop animate independently, so * the mascot can react to a prop without the prop moving with it. Choreography * lives in mobile.css (.trek-*). Poking (tap) remounts the svg to replay the * entrance pop-in as a bounce. */ export type TrekScene = | 'idle' | 'chat' | 'transport' | 'bookings' | 'guide' | 'packing' | 'files' | 'notes' | 'links' | 'polls' | 'journey' | 'collections' | 'dashboard' | 'atlas' | 'notifications' | 'costs' | 'search' | 'tasks' | 'tours'; export type TrekMood = 'default' | 'happy' | 'sad' | 'sleepy' | 'confused' | 'error'; const MARK = 'M 855.636719 699.203125 L 222.246094 699.203125 C 197.679688 699.203125 179.90625 675.75 186.539062 652.101562 L 360.429688 32.390625 C 364.921875 16.386719 379.511719 5.328125 396.132812 5.328125 L 1029.527344 5.328125 C 1054.089844 5.328125 1071.867188 28.777344 1065.230469 52.429688 L 891.339844 672.136719 C 886.851562 688.140625 872.257812 699.203125 855.636719 699.203125 Z M 444.238281 1166.980469 L 533.773438 847.898438 C 540.410156 824.246094 522.632812 800.796875 498.070312 800.796875 L 172.472656 800.796875 C 155.851562 800.796875 141.261719 811.855469 136.769531 827.859375 L 47.234375 1146.941406 C 40.597656 1170.59375 58.375 1194.042969 82.9375 1194.042969 L 408.535156 1194.042969 C 425.15625 1194.042969 439.75 1182.984375 444.238281 1166.980469 Z M 609.003906 827.859375 L 435.113281 1447.570312 C 428.476562 1471.21875 446.253906 1494.671875 470.816406 1494.671875 L 1104.210938 1494.671875 C 1120.832031 1494.671875 1135.421875 1483.609375 1139.914062 1467.605469 L 1313.804688 847.898438 C 1320.441406 824.246094 1302.664062 800.796875 1278.101562 800.796875 L 644.707031 800.796875 C 628.085938 800.796875 613.492188 811.855469 609.003906 827.859375 Z M 1056.105469 333.019531 L 966.570312 652.101562 C 959.933594 675.75 977.710938 699.203125 1002.273438 699.203125 L 1327.871094 699.203125 C 1344.492188 699.203125 1359.085938 688.140625 1363.574219 672.136719 L 1453.109375 353.054688 C 1459.746094 329.40625 1441.96875 305.953125 1417.40625 305.953125 L 1091.808594 305.953125 C 1075.1875 305.953125 1060.597656 317.015625 1056.105469 333.019531 Z'; const SCENE_MOOD: Partial> = { notifications: 'sleepy', search: 'confused', }; type MascotProps = { size?: number; scene?: TrekScene; mood?: TrekMood; className?: string; }; /** * Picks the look: the pre-rendered 3D clip when one exists for this scene and * face (see `trek3d/MascotClip`), the SVG otherwise, under reduced motion, in * tests, or when `localStorage['trek-mascot-3d']` is `'0'`. */ export default function MDancingTrek(props: MascotProps) { const { size = 96, scene = 'idle', mood, className = '' } = props; const sceneMood = SCENE_MOOD[scene] ?? 'default'; const clip = import.meta.env.MODE !== 'test' && mascot3dEnabled() ? findClip(scene, mood ?? sceneMood, sceneMood) : null; if (clip) return ( } /> ); return ; } function MDancingTrekSvg({ size = 96, scene = 'idle', mood, className = '' }: MascotProps) { const face = mood ?? SCENE_MOOD[scene] ?? 'default'; // Ground shadow sits under whatever the mascot stands on this scene. const shadowCy = scene === 'transport' ? 86 : 73; // Poke to react: remounting the svg replays the entrance pop-in as a tap bounce. const [poke, setPoke] = useState(0); return ( setPoke((p) => p + 1)} width={size} height={(size * 96) / 88} viewBox="0 0 88 96" fill="none" aria-hidden="true" className={`trek trek--${scene} cursor-pointer text-m-ink ${className}`} > {/* scene prop behind / under the body — animates on its own */} {/* body = the TREK mark, with its own per-scene bounce (hop, nod, …) */} {/* scene prop in front of the body — animates on its own */} ); } /* ── Eyes ──────────────────────────────────────────────────────────────────── Default eyes are surface-colour cutouts with ink pupils that blink and glance. Expression eyes are cut into the body as m-bg strokes so they read on the monochrome mark. */ function Eyes({ mood }: { mood: TrekMood }) { if (mood === 'happy') { return ( ); } if (mood === 'sad') { // The mirror of `happy`: the same arcs bent the other way. `sleepy` is a // shallower dip and reads as eyes falling shut, which is a different thing // from disappointed. return ( ); } if (mood === 'sleepy') { return ( ); } if (mood === 'error') { return ( ); } if (mood === 'confused') { // one eye open, one a raised squint — reads puzzled return ( ); } // default — open eyes that blink and glance around return ( ); } /* ── Scene props ───────────────────────────────────────────────────────────── Monochrome props built from a few shapes. Animated elements never carry a `transform` attribute (a CSS-animation transform would override it) — any static rotation lives on a wrapping instead. */ /** * Gear the mascot carries, drawn inside the body group so it walks, breathes and * hops with it. Each piece carries a surface-coloured outline: on a monochrome * mark that gap is the only thing telling the pack from the body behind it. */ function SceneOnBody({ scene }: { scene: TrekScene }) { if (scene !== 'tours') return null; const cut = { stroke: 'var(--m-bg)', strokeWidth: 1.6, paintOrder: 'stroke' as const, strokeLinejoin: 'round' as const, }; return ( {/* a small smile under the eyes, glad to be out walking */} {/* the pack, slung over the left side */} {/* sleeping mat rolled on top, two straps around it */} {/* body of the pack */} {/* lid seam and buckle */} {/* front pocket */} ); } function SceneBack({ scene }: { scene: TrekScene }) { switch (scene) { case 'tours': // the hills it is heading for, faint behind it, and the trail running under its feet return ( ); case 'transport': // skateboard under the body — deck + two wheels spinning in place return ( ); case 'guide': // tall staff with a big pennant fluttering near the top return ( ); case 'packing': // rolling suitcase parked beside the body — rocks on its wheels, // handle telescoping up and down return ( ); case 'links': // two chain links clicking into each other beside the body. The lower one // carries a surface-coloured under-stroke so it reads as passing through // the upper one rather than lying flat on top of it. return ( ); case 'polls': // vote bars gently rising and settling like live tallies return ( ); case 'collections': // a map pin dropping in and bouncing beside the body return ( ); case 'atlas': // a globe beside the body, meridians drifting return ( ); case 'costs': // a stack of coins beside the body, top one bouncing on return ( ); case 'chat': // a speech bubble beside the body with three typing dots pulsing in turn return ( ); default: return null; } } function SceneFront({ scene }: { scene: TrekScene }) { switch (scene) { case 'tours': // a trekking pole swinging forward and planting in step with the walk return ( ); // Files reuse the booking ticket per design — a card getting written on. case 'bookings': case 'files': return ( ); case 'notes': // a paper note (surface colour) with ink lines being written and a // scribbling pencil — pencil is ink (light in dark theme, dark in light) return ( {/* body + tip modelled vertically as one piece, then leaned together so the point always stays attached to the shaft */} ); case 'journey': // an open book with a fluttering page and a ribbon bookmark return ( ); case 'dashboard': // a little paper plane looping around, ready for a first trip return ( ); case 'notifications': // all caught up — a stack of Zzz drifting up while the mascot dozes return ( ); case 'search': // a magnifying glass scanning back and forth return ( ); case 'tasks': // a clipboard checklist with a checkmark ticking on return ( ); default: return null; } }