Maps JS behaviour

Route map

The express line from Central Station to the airport on an all-SVG map: the dotted route draws itself end to end, the intermediate stops take their numbers and settle in one by one, the sidebar counts the journey legs with ETA and distance, and the “other route” button re-draws the riverside line.

Documentation

Real scenarios

The component as it is used in a product — not a specimen grid.

Central Station to Airport T3, self-inking

The dotted route draws itself through a wiping SVG mask, the five numbered stops settle in behind the pen tip, and the sidebar counts every leg — ETA and distance per segment. The “other route” button swaps the Harbor Express for the Riverside Line and the whole draw replays.

Important props

Important props
Prop Type Default What it does
draw duration '1.8s' The draw runs through an SVG mask that wipes itself from origin to destination; the dotted route beneath comes alive.
dash pattern '.012 .03' The dots come from a normalised pathLength — no measuring real lengths, every line beads evenly.
stops count '5 · 5' Each route carries five stops; the numbers settle in with a stepped delay, in step with the pen’s tip.
alt-route toggle 'a ⇄ b' The “other route” button swaps the Harbor Express (38 min · 21.4 km) for the Riverside Line (46 min · 24.8 km) and the draw replays.

Snippet

<div class="mrt-root" x-data="{ alt: 'a' }">
<div class="mrt-layer" x-bind:data-alt="alt" dir="ltr">
<svg class="mrt-city" viewBox="0 0 640 400" aria-hidden="true">
<path class="mrt-river" d="M-10 366 C120 350 250 330 360 314 S540 268 650 224"/>
<rect class="mrt-block" x="60" y="60" width="110" height="70" rx="10"/>
<rect class="mrt-block" x="240" y="46" width="96" height="60" rx="10"/>
<rect class="mrt-block" x="330" y="220" width="110" height="60" rx="10"/>
<path class="mrt-ghost" d="M70 330 C130 310 140 280 170 255 C205 227 262 208 300 180 C340 150 400 168 450 150 C500 132 545 105 580 80"/>
<path class="mrt-ghost" d="M70 330 C110 345 150 352 190 345 C240 336 285 315 330 295 C385 271 430 252 470 230 C520 203 555 135 580 80"/>
<defs>
<mask id="mrt-wipe-a" maskUnits="userSpaceOnUse" x="0" y="0" width="640" height="400">
<path class="mrt-wipe mrt-wipe-a" pathLength="1" d="M70 330 C130 310 140 280 170 255 C205 227 262 208 300 180 C340 150 400 168 450 150 C500 132 545 105 580 80"/>
</mask>
<mask id="mrt-wipe-b" maskUnits="userSpaceOnUse" x="0" y="0" width="640" height="400">
<path class="mrt-wipe mrt-wipe-b" pathLength="1" d="M70 330 C110 345 150 352 190 345 C240 336 285 315 330 295 C385 271 430 252 470 230 C520 203 555 135 580 80"/>
</mask>
</defs>
<path class="mrt-line" pathLength="1" mask="url(#mrt-wipe-a)" d="M70 330 C130 310 140 280 170 255 C205 227 262 208 300 180 C340 150 400 168 450 150 C500 132 545 105 580 80"/>
<path class="mrt-line" pathLength="1" mask="url(#mrt-wipe-b)" d="M70 330 C110 345 150 352 190 345 C240 336 285 315 330 295 C385 271 430 252 470 230 C520 203 555 135 580 80"/>
<g class="mrt-stops mrt-stops-a">
<g class="mrt-stop" style="--i: 0"><circle cx="70" cy="330" r="8"/><text x="70" y="333">1</text></g>
<g class="mrt-stop" style="--i: 1"><circle cx="170" cy="255" r="7"/><text x="170" y="258">2</text></g>
<g class="mrt-stop" style="--i: 2"><circle cx="300" cy="180" r="7"/><text x="300" y="183">3</text></g>
<g class="mrt-stop" style="--i: 3"><circle cx="450" cy="150" r="7"/><text x="450" y="153">4</text></g>
<g class="mrt-stop" style="--i: 4"><circle cx="580" cy="80" r="8"/><text x="580" y="83">5</text></g>
</g>
<g class="mrt-stops mrt-stops-b">
<g class="mrt-stop" style="--i: 0"><circle cx="70" cy="330" r="8"/><text x="70" y="333">1</text></g>
<g class="mrt-stop" style="--i: 1"><circle cx="190" cy="345" r="7"/><text x="190" y="348">2</text></g>
<g class="mrt-stop" style="--i: 2"><circle cx="330" cy="295" r="7"/><text x="330" y="298">3</text></g>
<g class="mrt-stop" style="--i: 3"><circle cx="470" cy="230" r="7"/><text x="470" y="233">4</text></g>
<g class="mrt-stop" style="--i: 4"><circle cx="580" cy="80" r="8"/><text x="580" y="83">5</text></g>
</g>
</svg>
</div>
<button type="button" class="mrt-swap" x-on:click="alt = alt === 'a' ? 'b' : 'a'">Other route</button>
</div>

<style>
.mrt-root { --mrt-bg: #f6f7f9; --mrt-block: #e8eaef; --mrt-water: #cfe3f7; --mrt-line: #d4d8e0;
--mrt-accent: #e11d48; --mrt-text: #1c1917;
font-family: 'Inter', 'Vazirmatn', ui-sans-serif, sans-serif; }
.mrt-layer { position: relative; inline-size: min(100%, 40rem); aspect-ratio: 16 / 10; overflow: clip;
border: 1px solid var(--mrt-line); border-radius: 1rem; background: var(--mrt-bg); }
.mrt-city { inline-size: 100%; block-size: 100%; }
.mrt-river { fill: none; stroke: var(--mrt-water); stroke-width: 22; stroke-linecap: round; }
.mrt-block { fill: var(--mrt-block); }
.mrt-ghost { fill: none; stroke: var(--mrt-line); stroke-width: 3; stroke-dasharray: 2 7; stroke-linecap: round; }
.mrt-line { fill: none; stroke: var(--mrt-accent); stroke-width: 4.5; stroke-linecap: round; stroke-dasharray: .012 .03; }
.mrt-wipe { fill: none; stroke: #fff; stroke-width: 18; stroke-dasharray: 1; stroke-dashoffset: 1; }
.mrt-layer[data-alt='a'] .mrt-wipe-a { animation: mrt-draw 1.8s cubic-bezier(.4, .1, .2, 1) .2s forwards; }
.mrt-layer[data-alt='b'] .mrt-wipe-b { animation: mrt-draw 1.8s cubic-bezier(.4, .1, .2, 1) .2s forwards; }
@keyframes mrt-draw { to { stroke-dashoffset: 0; } }
.mrt-stops { display: none; }
.mrt-layer[data-alt='a'] .mrt-stops-a, .mrt-layer[data-alt='b'] .mrt-stops-b { display: block; }
.mrt-stop { opacity: 0; scale: .5; transform-box: fill-box; transform-origin: center; }
.mrt-layer[data-alt='a'] .mrt-stops-a .mrt-stop,
.mrt-layer[data-alt='b'] .mrt-stops-b .mrt-stop { animation: mrt-stop-in .3s ease both; animation-delay: calc(.3s + var(--i) * .38s); }
@keyframes mrt-stop-in { to { opacity: 1; scale: 1; } }
.mrt-stop circle { fill: #fff; stroke: var(--mrt-accent); stroke-width: 3; }
.mrt-stop text { fill: var(--mrt-accent); font: 700 9px sans-serif; text-anchor: middle; }
.mrt-swap { margin-block-start: .8rem; padding: .55rem 1.1rem; border: none; border-radius: 999px;
background: var(--mrt-accent); color: #fff; font: 600 .82rem/1 inherit; cursor: pointer; }
@media (prefers-reduced-motion: reduce) {
.mrt-wipe { stroke-dashoffset: 0; animation: none; }
.mrt-stop { animation: none; opacity: 1; scale: 1; }
}
</style>
// app/Pages/HarborRoute.jsx — Inertia (React) page; renders the React
// snippet below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import RoutePlanner from '@/components/RoutePlanner';

export default function HarborRoute() {
  return (
    <NabuXUIProvider locale="en" linkComponent={Link}>
      <main className="nx-page">
        <RoutePlanner />
      </main>
    </NabuXUIProvider>
  );
}
// RoutePlanner.jsx — the dashed route draws itself; the swap replays it
import { useState } from 'react';
import '@nabuxai/ui-core/css';

const ROUTES = {
  a: {
    name: 'Harbor Express', eta: '38 min', dist: '21.4 km',
    d: 'M70 330 C130 310 140 280 170 255 C205 227 262 208 300 180 C340 150 400 168 450 150 C500 132 545 105 580 80',
    stops: [
      { n: 1, x: 70, y: 330, name: 'Central Station', seg: 'origin' },
      { n: 2, x: 170, y: 255, name: 'Old Harbor', seg: '7 min · 4.1 km' },
      { n: 3, x: 300, y: 180, name: 'Museum Mile', seg: '9 min · 5.2 km' },
      { n: 4, x: 450, y: 150, name: 'Botanic Ring', seg: '11 min · 6.3 km' },
      { n: 5, x: 580, y: 80, name: 'Airport T3', seg: '11 min · 5.8 km' },
    ],
  },
  b: {
    name: 'Riverside Line', eta: '46 min', dist: '24.8 km',
    d: 'M70 330 C110 345 150 352 190 345 C240 336 285 315 330 295 C385 271 430 252 470 230 C520 203 555 135 580 80',
    stops: [
      { n: 1, x: 70, y: 330, name: 'Central Station', seg: 'origin' },
      { n: 2, x: 190, y: 345, name: 'Kessel Bridge', seg: '8 min · 4.4 km' },
      { n: 3, x: 330, y: 295, name: 'Signal Wharf', seg: '10 min · 5.6 km' },
      { n: 4, x: 470, y: 230, name: 'Freight Bypass', seg: '13 min · 6.7 km' },
      { n: 5, x: 580, y: 80, name: 'Airport T3', seg: '15 min · 8.1 km' },
    ],
  },
};

export default function RoutePlanner() {
  const [alt, setAlt] = useState('a');
  const route = ROUTES[alt];
  const other = ROUTES[alt === 'a' ? 'b' : 'a'];

  return (
    <>
      <style>{`
        .mrt-root { --mrt-bg: #f6f7f9; --mrt-block: #e8eaef; --mrt-water: #cfe3f7; --mrt-line: #d4d8e0;
                    --mrt-accent: #e11d48; --mrt-text: #1c1917; font-family: 'Inter', ui-sans-serif, sans-serif;
                    display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.5fr) minmax(14rem, 1fr); }
        .mrt-layer { position: relative; aspect-ratio: 16 / 10; overflow: clip;
                     border: 1px solid var(--mrt-line); border-radius: 1rem; background: var(--mrt-bg); }
        .mrt-city { inline-size: 100%; block-size: 100%; }
        .mrt-river { fill: none; stroke: var(--mrt-water); stroke-width: 22; stroke-linecap: round; }
        .mrt-block { fill: var(--mrt-block); }
        .mrt-ghost { fill: none; stroke: var(--mrt-line); stroke-width: 3; stroke-dasharray: 2 7; stroke-linecap: round; }
        .mrt-line { fill: none; stroke: var(--mrt-accent); stroke-width: 4.5; stroke-linecap: round; stroke-dasharray: .012 .03; }
        .mrt-wipe { fill: none; stroke: #fff; stroke-width: 18; stroke-dasharray: 1; stroke-dashoffset: 1;
                    animation: mrt-draw 1.8s cubic-bezier(.4, .1, .2, 1) .2s forwards; }
        @keyframes mrt-draw { to { stroke-dashoffset: 0; } }
        .mrt-stop { opacity: 0; scale: .5; transform-box: fill-box; transform-origin: center;
                    animation: mrt-stop-in .3s ease both; animation-delay: calc(.3s + var(--i) * .38s); }
        @keyframes mrt-stop-in { to { opacity: 1; scale: 1; } }
        .mrt-stop circle { fill: #fff; stroke: var(--mrt-accent); stroke-width: 3; }
        .mrt-stop text { fill: var(--mrt-accent); font: 700 9px sans-serif; text-anchor: middle; }
        .mrt-stop .mrt-name { font: 600 11px sans-serif; fill: var(--mrt-text); }
        .mrt-panel { display: grid; gap: .75rem; align-content: start; padding: 1rem;
                     border: 1px solid var(--mrt-line); border-radius: 1rem; color: var(--mrt-text); }
        .mrt-badges { margin: 0; color: var(--mrt-accent); font-weight: 700; font-size: .85rem; }
        .mrt-steps { display: grid; gap: .55rem; margin: 0; padding: 0; list-style: none; }
        .mrt-steps li { display: grid; grid-template-columns: 1.5rem 1fr; gap: .25rem .6rem; align-items: baseline; }
        .mrt-steps i { display: grid; place-items: center; aspect-ratio: 1; border-radius: 50%;
                       border: 2px solid var(--mrt-accent); font: 700 .7rem/1 sans-serif; font-style: normal; }
        .mrt-steps small { grid-column: 2; color: var(--mrt-line); }
        .mrt-swap { padding: .6rem 1rem; border: none; border-radius: 999px; background: var(--mrt-accent);
                    color: #fff; font: 600 .82rem/1 inherit; cursor: pointer; }
        @media (prefers-reduced-motion: reduce) {
          .mrt-wipe { stroke-dashoffset: 0; animation: none; }
          .mrt-stop { animation: none; opacity: 1; scale: 1; }
        }
      `}</style>
      <div className="mrt-root">
        <div className="mrt-layer" dir="ltr">
          <svg className="mrt-city" viewBox="0 0 640 400" role="img" aria-label={`Route of the ${route.name}`}>
            <path className="mrt-river" d="M-10 366 C120 350 250 330 360 314 S540 268 650 224" />
            <rect className="mrt-block" x="60" y="60" width="110" height="70" rx="10" />
            <rect className="mrt-block" x="240" y="46" width="96" height="60" rx="10" />
            <rect className="mrt-block" x="330" y="220" width="110" height="60" rx="10" />
            {Object.values(ROUTES).map((r) => <path key={r.name} className="mrt-ghost" d={r.d} />)}
            {/* Keying the group remounts it on swap — the CSS draw replays. */}
            <g key={alt}>
              <defs>
                <mask id="mrt-wipe" maskUnits="userSpaceOnUse" x="0" y="0" width="640" height="400">
                  <path className="mrt-wipe" pathLength="1" d={route.d} />
                </mask>
              </defs>
              <path className="mrt-line" pathLength="1" mask="url(#mrt-wipe)" d={route.d} />
              {route.stops.map((s) => (
                <g key={s.n} className="mrt-stop" style={{ '--i': s.n - 1 }}>
                  <circle cx={s.x} cy={s.y} r={s.n === 1 || s.n === 5 ? 8 : 7} />
                  <text x={s.x} y={s.y + 3.5}>{s.n}</text>
                  <text className="mrt-name" x={s.x} y={s.y - 14}>{s.name}</text>
                </g>
              ))}
            </g>
          </svg>
        </div>
        <aside className="mrt-panel">
          <h4 style={{ margin: 0 }}>{route.name}</h4>
          <p className="mrt-badges">{route.eta} · {route.dist}</p>
          <ol className="mrt-steps">
            {route.stops.map((s) => (
              <li key={s.n}><i>{s.n}</i><b>{s.name}</b><small>{s.seg}</small></li>
            ))}
          </ol>
          <button type="button" className="mrt-swap" onClick={() => setAlt(alt === 'a' ? 'b' : 'a')}>
            Other route: {other.name}
          </button>
        </aside>
      </div>
    </>
  );
}
<!-- RoutePlanner.vue — the dashed route draws itself; the swap replays it -->
<script setup lang="ts">
import { computed, ref } from 'vue';
import '@nabuxai/ui-core/css';

interface Stop { n: number; x: number; y: number; name: string; seg: string }
interface Route { name: string; eta: string; dist: string; d: string; stops: Stop[] }
const routes: Record<'a' | 'b', Route> = {
  a: {
    name: 'Harbor Express', eta: '38 min', dist: '21.4 km',
    d: 'M70 330 C130 310 140 280 170 255 C205 227 262 208 300 180 C340 150 400 168 450 150 C500 132 545 105 580 80',
    stops: [
      { n: 1, x: 70, y: 330, name: 'Central Station', seg: 'origin' },
      { n: 2, x: 170, y: 255, name: 'Old Harbor', seg: '7 min · 4.1 km' },
      { n: 3, x: 300, y: 180, name: 'Museum Mile', seg: '9 min · 5.2 km' },
      { n: 4, x: 450, y: 150, name: 'Botanic Ring', seg: '11 min · 6.3 km' },
      { n: 5, x: 580, y: 80, name: 'Airport T3', seg: '11 min · 5.8 km' },
    ],
  },
  b: {
    name: 'Riverside Line', eta: '46 min', dist: '24.8 km',
    d: 'M70 330 C110 345 150 352 190 345 C240 336 285 315 330 295 C385 271 430 252 470 230 C520 203 555 135 580 80',
    stops: [
      { n: 1, x: 70, y: 330, name: 'Central Station', seg: 'origin' },
      { n: 2, x: 190, y: 345, name: 'Kessel Bridge', seg: '8 min · 4.4 km' },
      { n: 3, x: 330, y: 295, name: 'Signal Wharf', seg: '10 min · 5.6 km' },
      { n: 4, x: 470, y: 230, name: 'Freight Bypass', seg: '13 min · 6.7 km' },
      { n: 5, x: 580, y: 80, name: 'Airport T3', seg: '15 min · 8.1 km' },
    ],
  },
};
const alt = ref<'a' | 'b'>('a');
const route = computed(() => routes[alt.value]);
const other = computed(() => routes[alt.value === 'a' ? 'b' : 'a']);
const swap = () => { alt.value = alt.value === 'a' ? 'b' : 'a'; };
</script>

<template>
  <div class="mrt-root">
    <div class="mrt-layer" dir="ltr">
      <svg class="mrt-city" viewBox="0 0 640 400" role="img" :aria-label="`Route of the ${route.name}`">
        <path class="mrt-river" d="M-10 366 C120 350 250 330 360 314 S540 268 650 224" />
        <rect class="mrt-block" x="60" y="60" width="110" height="70" rx="10" />
        <rect class="mrt-block" x="240" y="46" width="96" height="60" rx="10" />
        <rect class="mrt-block" x="330" y="220" width="110" height="60" rx="10" />
        <path v-for="r in routes" :key="r.name" class="mrt-ghost" :d="r.d" />
        <!-- Keying the group remounts it on swap — the CSS draw replays. -->
        <g :key="alt">
          <defs>
            <mask id="mrt-wipe" maskUnits="userSpaceOnUse" x="0" y="0" width="640" height="400">
              <path class="mrt-wipe" pathLength="1" :d="route.d" />
            </mask>
          </defs>
          <path class="mrt-line" pathLength="1" mask="url(#mrt-wipe)" :d="route.d" />
          <g v-for="s in route.stops" :key="s.n" class="mrt-stop" :style="{ '--i': s.n - 1 }">
            <circle :cx="s.x" :cy="s.y" :r="s.n === 1 || s.n === 5 ? 8 : 7" />
            <text :x="s.x" :y="s.y + 3.5">{{ s.n }}</text>
            <text class="mrt-name" :x="s.x" :y="s.y - 14">{{ s.name }}</text>
          </g>
        </g>
      </svg>
    </div>
    <aside class="mrt-panel">
      <h4 style="margin: 0">{{ route.name }}</h4>
      <p class="mrt-badges">{{ route.eta }} · {{ route.dist }}</p>
      <ol class="mrt-steps">
        <li v-for="s in route.stops" :key="s.n"><i>{{ s.n }}</i><b>{{ s.name }}</b><small>{{ s.seg }}</small></li>
      </ol>
      <button type="button" class="mrt-swap" @click="swap">Other route: {{ other.name }}</button>
    </aside>
  </div>
</template>

<style scoped>
.mrt-root { --mrt-bg: #f6f7f9; --mrt-block: #e8eaef; --mrt-water: #cfe3f7; --mrt-line: #d4d8e0;
            --mrt-accent: #e11d48; --mrt-text: #1c1917; font-family: 'Inter', ui-sans-serif, sans-serif;
            display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.5fr) minmax(14rem, 1fr); }
.mrt-layer { position: relative; aspect-ratio: 16 / 10; overflow: clip;
             border: 1px solid var(--mrt-line); border-radius: 1rem; background: var(--mrt-bg); }
.mrt-city { inline-size: 100%; block-size: 100%; }
.mrt-river { fill: none; stroke: var(--mrt-water); stroke-width: 22; stroke-linecap: round; }
.mrt-block { fill: var(--mrt-block); }
.mrt-ghost { fill: none; stroke: var(--mrt-line); stroke-width: 3; stroke-dasharray: 2 7; stroke-linecap: round; }
.mrt-line { fill: none; stroke: var(--mrt-accent); stroke-width: 4.5; stroke-linecap: round; stroke-dasharray: .012 .03; }
.mrt-wipe { fill: none; stroke: #fff; stroke-width: 18; stroke-dasharray: 1; stroke-dashoffset: 1;
            animation: mrt-draw 1.8s cubic-bezier(.4, .1, .2, 1) .2s forwards; }
@keyframes mrt-draw { to { stroke-dashoffset: 0; } }
.mrt-stop { opacity: 0; scale: .5; transform-box: fill-box; transform-origin: center;
            animation: mrt-stop-in .3s ease both; animation-delay: calc(.3s + var(--i) * .38s); }
@keyframes mrt-stop-in { to { opacity: 1; scale: 1; } }
.mrt-stop circle { fill: #fff; stroke: var(--mrt-accent); stroke-width: 3; }
.mrt-stop text { fill: var(--mrt-accent); font: 700 9px sans-serif; text-anchor: middle; }
.mrt-stop .mrt-name { font: 600 11px sans-serif; fill: var(--mrt-text); }
.mrt-panel { display: grid; gap: .75rem; align-content: start; padding: 1rem;
             border: 1px solid var(--mrt-line); border-radius: 1rem; color: var(--mrt-text); }
.mrt-badges { margin: 0; color: var(--mrt-accent); font-weight: 700; font-size: .85rem; }
.mrt-steps { display: grid; gap: .55rem; margin: 0; padding: 0; list-style: none; }
.mrt-steps li { display: grid; grid-template-columns: 1.5rem 1fr; gap: .25rem .6rem; align-items: baseline; }
.mrt-steps i { display: grid; place-items: center; aspect-ratio: 1; border-radius: 50%;
               border: 2px solid var(--mrt-accent); font: 700 .7rem/1 sans-serif; font-style: normal; }
.mrt-steps small { grid-column: 2; color: var(--mrt-line); }
.mrt-swap { padding: .6rem 1rem; border: none; border-radius: 999px; background: var(--mrt-accent);
            color: #fff; font: 600 .82rem/1 inherit; cursor: pointer; }
@media (prefers-reduced-motion: reduce) {
  .mrt-wipe { stroke-dashoffset: 0; animation: none; }
  .mrt-stop { animation: none; opacity: 1; scale: 1; }
}
</style>
<!-- RoutePlanner.svelte — the dashed route draws itself; the swap replays it -->
<script lang="ts">
  import '@nabuxai/ui-core/css';

  interface Stop { n: number; x: number; y: number; name: string; seg: string }
  interface Route { name: string; eta: string; dist: string; d: string; stops: Stop[] }
  const routes: Record<'a' | 'b', Route> = {
    a: {
      name: 'Harbor Express', eta: '38 min', dist: '21.4 km',
      d: 'M70 330 C130 310 140 280 170 255 C205 227 262 208 300 180 C340 150 400 168 450 150 C500 132 545 105 580 80',
      stops: [
        { n: 1, x: 70, y: 330, name: 'Central Station', seg: 'origin' },
        { n: 2, x: 170, y: 255, name: 'Old Harbor', seg: '7 min · 4.1 km' },
        { n: 3, x: 300, y: 180, name: 'Museum Mile', seg: '9 min · 5.2 km' },
        { n: 4, x: 450, y: 150, name: 'Botanic Ring', seg: '11 min · 6.3 km' },
        { n: 5, x: 580, y: 80, name: 'Airport T3', seg: '11 min · 5.8 km' },
      ],
    },
    b: {
      name: 'Riverside Line', eta: '46 min', dist: '24.8 km',
      d: 'M70 330 C110 345 150 352 190 345 C240 336 285 315 330 295 C385 271 430 252 470 230 C520 203 555 135 580 80',
      stops: [
        { n: 1, x: 70, y: 330, name: 'Central Station', seg: 'origin' },
        { n: 2, x: 190, y: 345, name: 'Kessel Bridge', seg: '8 min · 4.4 km' },
        { n: 3, x: 330, y: 295, name: 'Signal Wharf', seg: '10 min · 5.6 km' },
        { n: 4, x: 470, y: 230, name: 'Freight Bypass', seg: '13 min · 6.7 km' },
        { n: 5, x: 580, y: 80, name: 'Airport T3', seg: '15 min · 8.1 km' },
      ],
    },
  };
  let alt = $state<'a' | 'b'>('a');
  const route = $derived(routes[alt]);
  const other = $derived(routes[alt === 'a' ? 'b' : 'a']);
  const swap = () => { alt = alt === 'a' ? 'b' : 'a'; };
</script>

<div class="mrt-root">
  <div class="mrt-layer" dir="ltr">
    <svg class="mrt-city" viewBox="0 0 640 400" role="img" aria-label={`Route of the ${route.name}`}>
      <path class="mrt-river" d="M-10 366 C120 350 250 330 360 314 S540 268 650 224" />
      <rect class="mrt-block" x="60" y="60" width="110" height="70" rx="10" />
      <rect class="mrt-block" x="240" y="46" width="96" height="60" rx="10" />
      <rect class="mrt-block" x="330" y="220" width="110" height="60" rx="10" />
      {#each Object.values(routes) as r (r.name)}
        <path class="mrt-ghost" d={r.d} />
      {/each}
      <!-- Keying the group remounts it on swap — the CSS draw replays. -->
      {#key alt}
        <g>
          <defs>
            <mask id="mrt-wipe" maskUnits="userSpaceOnUse" x="0" y="0" width="640" height="400">
              <path class="mrt-wipe" pathLength="1" d={route.d} />
            </mask>
          </defs>
          <path class="mrt-line" pathLength="1" mask="url(#mrt-wipe)" d={route.d} />
          {#each route.stops as s (s.n)}
            <g class="mrt-stop" style={`--i: ${s.n - 1}`}>
              <circle cx={s.x} cy={s.y} r={s.n === 1 || s.n === 5 ? 8 : 7} />
              <text x={s.x} y={s.y + 3.5}>{s.n}</text>
              <text class="mrt-name" x={s.x} y={s.y - 14}>{s.name}</text>
            </g>
          {/each}
        </g>
      {/key}
    </svg>
  </div>
  <aside class="mrt-panel">
    <h4 style="margin: 0">{route.name}</h4>
    <p class="mrt-badges">{route.eta} · {route.dist}</p>
    <ol class="mrt-steps">
      {#each route.stops as s (s.n)}
        <li><i>{s.n}</i><b>{s.name}</b><small>{s.seg}</small></li>
      {/each}
    </ol>
    <button type="button" class="mrt-swap" onclick={swap}>Other route: {other.name}</button>
  </aside>
</div>

<style>
.mrt-root { --mrt-bg: #f6f7f9; --mrt-block: #e8eaef; --mrt-water: #cfe3f7; --mrt-line: #d4d8e0;
            --mrt-accent: #e11d48; --mrt-text: #1c1917; font-family: 'Inter', ui-sans-serif, sans-serif;
            display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.5fr) minmax(14rem, 1fr); }
.mrt-layer { position: relative; aspect-ratio: 16 / 10; overflow: clip;
             border: 1px solid var(--mrt-line); border-radius: 1rem; background: var(--mrt-bg); }
.mrt-city { inline-size: 100%; block-size: 100%; }
.mrt-river { fill: none; stroke: var(--mrt-water); stroke-width: 22; stroke-linecap: round; }
.mrt-block { fill: var(--mrt-block); }
.mrt-ghost { fill: none; stroke: var(--mrt-line); stroke-width: 3; stroke-dasharray: 2 7; stroke-linecap: round; }
.mrt-line { fill: none; stroke: var(--mrt-accent); stroke-width: 4.5; stroke-linecap: round; stroke-dasharray: .012 .03; }
.mrt-wipe { fill: none; stroke: #fff; stroke-width: 18; stroke-dasharray: 1; stroke-dashoffset: 1;
            animation: mrt-draw 1.8s cubic-bezier(.4, .1, .2, 1) .2s forwards; }
@keyframes mrt-draw { to { stroke-dashoffset: 0; } }
.mrt-stop { opacity: 0; scale: .5; transform-box: fill-box; transform-origin: center;
            animation: mrt-stop-in .3s ease both; animation-delay: calc(.3s + var(--i) * .38s); }
@keyframes mrt-stop-in { to { opacity: 1; scale: 1; } }
.mrt-stop circle { fill: #fff; stroke: var(--mrt-accent); stroke-width: 3; }
.mrt-stop text { fill: var(--mrt-accent); font: 700 9px sans-serif; text-anchor: middle; }
.mrt-stop .mrt-name { font: 600 11px sans-serif; fill: var(--mrt-text); }
.mrt-panel { display: grid; gap: .75rem; align-content: start; padding: 1rem;
             border: 1px solid var(--mrt-line); border-radius: 1rem; color: var(--mrt-text); }
.mrt-badges { margin: 0; color: var(--mrt-accent); font-weight: 700; font-size: .85rem; }
.mrt-steps { display: grid; gap: .55rem; margin: 0; padding: 0; list-style: none; }
.mrt-steps li { display: grid; grid-template-columns: 1.5rem 1fr; gap: .25rem .6rem; align-items: baseline; }
.mrt-steps i { display: grid; place-items: center; aspect-ratio: 1; border-radius: 50%;
               border: 2px solid var(--mrt-accent); font: 700 .7rem/1 sans-serif; font-style: normal; }
.mrt-steps small { grid-column: 2; color: var(--mrt-line); }
.mrt-swap { padding: .6rem 1rem; border: none; border-radius: 999px; background: var(--mrt-accent);
            color: #fff; font: 600 .82rem/1 inherit; cursor: pointer; }
@media (prefers-reduced-motion: reduce) {
  .mrt-wipe { stroke-dashoffset: 0; animation: none; }
  .mrt-stop { animation: none; opacity: 1; scale: 1; }
}
</style>