{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "route-card",
  "type": "registry:item",
  "title": "Route Card",
  "description": "A trip card: a line fills behind a plane between two big codes, above a slowly turning globe of dots.",
  "categories": [
    "data"
  ],
  "dependencies": [
    "@shopify/react-native-skia",
    "react-native-reanimated",
    "react-native-worklets"
  ],
  "registryDependencies": [
    "https://kinetik-ui.dev/r/kinetik-tokens.json",
    "https://kinetik-ui.dev/r/kinetik-motion.json",
    "https://kinetik-ui.dev/r/kinetik-clock.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/route-card.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/route-card.tsx",
      "content": "import { BlurMask, Canvas, Circle, Group, Path, Skia } from '@shopify/react-native-skia';\nimport { useEffect, useState, type ReactNode } from 'react';\nimport { StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native';\nimport Animated, {\n  useAnimatedStyle,\n  useDerivedValue,\n  useSharedValue,\n  withSpring,\n} from 'react-native-reanimated';\n\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { useShaderClock } from '../../lib/kinetik/hooks/use-shader-clock';\nimport { spring } from '../../lib/kinetik/motion/motion';\nimport { gradient } from '../../lib/kinetik/tokens/gradient';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport { glow, withAlpha } from '../../lib/kinetik/tokens/tokens';\n\nexport type RouteStop = {\n  /** Short code, e.g. \"IST\". */\n  code: string;\n  /** Place under the code, e.g. \"ISTANBUL\". */\n  city: string;\n  /** Time as shown, e.g. \"09:40AM\". */\n  time: string;\n};\n\nexport type RouteCardProps = {\n  from: RouteStop;\n  to: RouteStop;\n  /** How far along the trip is, 0–1. Changes glide the plane along the line. */\n  progress: number;\n  /** Status between the cities, e.g. \"ON SCHEDULE\". */\n  status?: string;\n  /** Chip in the corner, e.g. the flight number. */\n  tag?: string;\n  /** Label before the departure time. Defaults to \"BOARDS:\". */\n  departLabel?: string;\n  /** Label before the arrival time. Defaults to \"LANDS:\". */\n  arriveLabel?: string;\n  /** Mark in the far corner, usually your logo. Defaults to a small star; null hides it. */\n  mark?: ReactNode;\n  style?: StyleProp<ViewStyle>;\n};\n\n/** Plane from Tabler Icons (MIT, https://tabler.io/icons), nose right on a 24 pt grid. */\nconst PLANE = Skia.Path.MakeFromSVGString(\n  'M16 10h4a2 2 0 0 1 0 4h-4l-4 7h-3l2 -7h-4l-2 2h-3l2 -4l-2 -4h3l2 2h4l-2 -7h3z',\n)!;\nconst STAR = Skia.Path.MakeFromSVGString(\n  'M12 1L14.6 9.4L23 12L14.6 14.6L12 23L9.4 14.6L1 12L9.4 9.4Z',\n)!;\n\nconst ICON = 28;\nconst BAR = 5;\nconst DASHES = 32;\nconst TILT = 0.34;\nconst SPIN = 0.05;\n\n/** Rough land masses as [latitude, longitude, reach north-south, reach east-west], in degrees. */\nconst LAND: readonly (readonly [number, number, number, number])[] = [\n  [50, -100, 22, 30],\n  [30, -95, 12, 16],\n  [14, -88, 8, 8],\n  [-14, -60, 20, 15],\n  [-36, -67, 14, 7],\n  [72, -40, 10, 16],\n  [50, 12, 14, 22],\n  [62, 22, 9, 16],\n  [14, 18, 22, 26],\n  [-14, 25, 16, 13],\n  [28, 48, 12, 12],\n  [55, 90, 16, 54],\n  [33, 100, 16, 24],\n  [20, 79, 12, 8],\n  [38, 138, 8, 5],\n  [0, 112, 8, 14],\n  [-25, 134, 11, 16],\n];\n\nfunction isLand(lat: number, lon: number) {\n  return LAND.some(([la, lo, rLa, rLo]) => {\n    const dLon = ((lon - lo + 540) % 360) - 180;\n    return ((lat - la) / rLa) ** 2 + (dLon / rLo) ** 2 < 1;\n  });\n}\n\n/** Evenly spread points on the land of a unit sphere, north of 25°S: the rest never shows. */\nfunction landDots(count: number): number[] {\n  const out: number[] = [];\n  const golden = Math.PI * (3 - Math.sqrt(5));\n  for (let i = 0; i < count; i++) {\n    const y = 1 - ((i + 0.5) / count) * 2;\n    const lat = (Math.asin(y) * 180) / Math.PI;\n    if (lat < -25) continue;\n    const angle = i * golden;\n    const lon = ((((angle * 180) / Math.PI) % 360) + 360) % 360;\n    if (!isLand(lat, lon - 180)) continue;\n    const r = Math.cos(Math.asin(y));\n    out.push(r * Math.cos(angle), y, r * Math.sin(angle));\n  }\n  return out;\n}\n\nconst DOTS = landDots(2600);\n\n/**\n * A trip card: two big codes joined by a line that fills in green behind a\n * small plane, dashed for the distance still to go, above a slowly turning\n * globe of dots rising from the bottom edge.\n */\nexport function RouteCard({\n  from,\n  to,\n  progress,\n  status,\n  tag,\n  departLabel = 'BOARDS:',\n  arriveLabel = 'LANDS:',\n  mark,\n  style,\n}: RouteCardProps) {\n  const { colors, font, radius, space } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const [width, setWidth] = useState(0);\n  const [track, setTrack] = useState(0);\n  const p = Math.max(0, Math.min(1, progress));\n  const compact = width > 0 && width < 340;\n  const pct = Math.round(p * 100);\n\n  const at = useSharedValue(reduced ? p : 0);\n  useEffect(() => {\n    at.set(reduced ? p : withSpring(p, spring('smooth')));\n  }, [p, reduced, at]);\n\n  const fill = useAnimatedStyle(() => ({ width: at.get() * track }));\n  const plane = useAnimatedStyle(() => ({\n    transform: [{ translateX: at.get() * track - ICON / 2 }],\n  }));\n  const rest = useAnimatedStyle(() => ({ left: at.get() * track + ICON / 2 }));\n\n  const code = {\n    color: colors.highlight,\n    fontSize: compact ? font.size['2xl'] : font.size['3xl'],\n    fontWeight: font.weight.bold,\n    letterSpacing: font.tracking.tight,\n  } as const;\n  const small = { color: MUTED, fontSize: font.size.xs, fontWeight: font.weight.medium } as const;\n\n  return (\n    <View\n      accessible\n      accessibilityRole=\"progressbar\"\n      accessibilityLabel={\n        `${from.code}, ${from.city}, to ${to.code}, ${to.city}. ` +\n        `${departLabel} ${from.time}, ${arriveLabel} ${to.time}.` +\n        `${status ? ` ${status}.` : ''}${tag ? ` ${tag}.` : ''}`\n      }\n      accessibilityValue={{ min: 0, max: 100, now: pct, text: `${pct}% of the way` }}\n      onLayout={(e) => setWidth(e.nativeEvent.layout.width)}\n      style={[styles.card, gradient(BACKDROP), style]}\n    >\n      {width > 0 ? <Globe width={width} reduced={reduced} /> : null}\n\n      <View style={{ padding: space[5], gap: space[2] }}>\n        <View style={styles.between}>\n          <Text numberOfLines={1} style={small}>\n            {departLabel} {from.time}\n          </Text>\n          <Text numberOfLines={1} style={small}>\n            {arriveLabel} {to.time}\n          </Text>\n        </View>\n\n        <View style={[styles.line, { gap: space[3] }]}>\n          <Text style={code}>{from.code}</Text>\n          <View\n            style={styles.route}\n            onLayout={(e) => setTrack(e.nativeEvent.layout.width)}\n            pointerEvents=\"none\"\n          >\n            <Animated.View style={[styles.rest, rest]}>\n              {Array.from({ length: DASHES }, (_, i) => (\n                <View\n                  key={i}\n                  style={[styles.dash, { backgroundColor: withAlpha(colors.highlight, 0.6) }]}\n                />\n              ))}\n            </Animated.View>\n            <Animated.View\n              style={[styles.fill, gradient(LINE), { boxShadow: glow(GREEN) }, fill]}\n            />\n            <Animated.View style={[styles.plane, plane]}>\n              <Canvas style={styles.planeBox}>\n                <Group transform={[{ scale: ICON / 24 }]}>\n                  <Path path={PLANE} color={colors.highlight} />\n                </Group>\n              </Canvas>\n            </Animated.View>\n          </View>\n          <Text style={code}>{to.code}</Text>\n        </View>\n\n        <View style={styles.between}>\n          <Text numberOfLines={1} style={[small, styles.side]}>\n            {from.city}\n          </Text>\n          {status ? (\n            <Text\n              numberOfLines={1}\n              style={{ color: GREEN, fontSize: font.size.xs + 1, fontWeight: font.weight.bold }}\n            >\n              {status}\n            </Text>\n          ) : null}\n          <Text numberOfLines={1} style={[small, styles.side, styles.right]}>\n            {to.city}\n          </Text>\n        </View>\n\n        <View style={[styles.between, styles.foot, { marginTop: space[6] }]}>\n          {tag ? (\n            <View style={[styles.chip, { borderRadius: radius.sm }]}>\n              <Text\n                style={{\n                  color: colors.highlight,\n                  fontSize: font.size.xs + 1,\n                  fontWeight: font.weight.semibold,\n                }}\n              >\n                {tag}\n              </Text>\n            </View>\n          ) : (\n            <View />\n          )}\n          {mark === undefined ? (\n            <Canvas style={styles.mark}>\n              <Group transform={[{ scale: MARK / 24 }]}>\n                <Path path={STAR} color={colors.danger} />\n              </Group>\n            </Canvas>\n          ) : (\n            mark\n          )}\n        </View>\n      </View>\n    </View>\n  );\n}\n\n/** A dark sphere rising from the bottom edge, its land drawn in dots, turning slowly. */\nfunction Globe({ width, reduced }: { width: number; reduced: boolean }) {\n  const { colors } = useKinetikTheme();\n  const clock = useShaderClock({ running: !reduced, frameRate: 30, start: 40 });\n  const height = Math.round(width * 0.2);\n  const r = width * 0.4;\n  const cx = width / 2;\n  const cy = r + 6;\n\n  const dots = useDerivedValue(() => {\n    const path = Skia.PathBuilder.Make();\n    const angle = clock.get() * SPIN;\n    const cosA = Math.cos(angle);\n    const sinA = Math.sin(angle);\n    const cosT = Math.cos(TILT);\n    const sinT = Math.sin(TILT);\n    for (let i = 0; i < DOTS.length; i += 3) {\n      const x0 = DOTS[i]!;\n      const y0 = DOTS[i + 1]!;\n      const z0 = DOTS[i + 2]!;\n      const x = x0 * cosA + z0 * sinA;\n      const z1 = z0 * cosA - x0 * sinA;\n      const y = y0 * cosT - z1 * sinT;\n      const z = z1 * cosT + y0 * sinT;\n      if (z < 0.05) continue;\n      const sy = cy - y * r;\n      if (sy > height) continue;\n      path.addCircle(cx + x * r, sy, 0.45 + z * 0.75);\n    }\n    return path.detach();\n  });\n\n  return (\n    <Canvas style={{ ...styles.globe, height }} pointerEvents=\"none\">\n      <Circle cx={cx} cy={cy} r={r + 4} color={HAZE}>\n        <BlurMask blur={22} style=\"normal\" />\n      </Circle>\n      <Circle cx={cx} cy={cy} r={r} color={SPHERE} />\n      <Circle\n        cx={cx}\n        cy={cy}\n        r={r}\n        color={withAlpha(colors.highlight, 0.14)}\n        style=\"stroke\"\n        strokeWidth={1}\n      />\n      <Path path={dots} color={withAlpha(colors.highlight, 0.82)} />\n    </Canvas>\n  );\n}\n\nconst MARK = 26;\nconst MUTED = 'hsl(220, 6%, 60%)';\nconst GREEN = 'hsl(145, 76%, 46%)';\nconst HAZE = 'hsl(212, 26%, 26%)';\nconst SPHERE = 'hsl(220, 12%, 5%)';\nconst BACKDROP = 'linear-gradient(180deg, hsl(220, 8%, 10%) 0%, hsl(218, 10%, 6%) 100%)';\nconst LINE = 'linear-gradient(90deg, hsl(145, 70%, 24%) 0%, hsl(145, 76%, 46%) 100%)';\n\nconst styles = StyleSheet.create({\n  card: {\n    width: '100%',\n    maxWidth: 440,\n    alignSelf: 'center',\n    borderRadius: 30,\n    overflow: 'hidden',\n    boxShadow: '0px 18px 40px hsla(220, 30%, 5%, 0.3)',\n  },\n  globe: { position: 'absolute', left: 0, right: 0, bottom: 0 },\n  between: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 8 },\n  line: { flexDirection: 'row', alignItems: 'center' },\n  route: { flex: 1, height: ICON, justifyContent: 'center' },\n  fill: { position: 'absolute', left: 0, height: BAR, borderRadius: BAR / 2 },\n  rest: {\n    position: 'absolute',\n    right: 0,\n    height: 2,\n    flexDirection: 'row',\n    gap: 4,\n    overflow: 'hidden',\n    justifyContent: 'flex-end',\n  },\n  dash: { width: 5, height: 2, borderRadius: 1 },\n  plane: { position: 'absolute', left: 0, width: ICON, height: ICON },\n  planeBox: { width: ICON, height: ICON },\n  side: { flex: 1 },\n  right: { textAlign: 'right' },\n  foot: { alignItems: 'flex-end' },\n  chip: {\n    paddingHorizontal: 12,\n    paddingVertical: 8,\n    backgroundColor: 'hsl(214, 16%, 22%)',\n  },\n  mark: { width: MARK, height: MARK },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "data",
    "web": "live",
    "perf": {
      "budget": "The globe redraws a few hundred dots on the UI thread at 30 fps while on screen, so it animates at rest. The plane only moves when progress changes.",
      "measurements": [
        {
          "device": "Huawei P20 Lite (ANE-LX1), Android 9",
          "kind": "device",
          "date": "2026-11-02",
          "build": "release",
          "frameMs": 19,
          "p90Ms": 27,
          "jankyPercent": 72.58,
          "atRest": "animating",
          "memoryMb": 142,
          "notes": "Animating at rest: the globe turns at 30 fps. An old mid-range phone; the numbers include scrolling the demo page."
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The globe holds still and the plane jumps to its place.",
      "screenReader": "One progress bar reading the route and times (\"IST, ISTANBUL, to NRT, TOKYO. BOARDS: 09:40AM, LANDS: 03:25PM. ON SCHEDULE. KN204.\") with \"58% of the way\".",
      "touchTarget": "Not interactive."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { RouteCard } from '@/components/kinetik/route-card';\n\n<RouteCard\n  from={{ code: 'IST', city: 'ISTANBUL', time: '09:40AM' }}\n  to={{ code: 'NRT', city: 'TOKYO', time: '03:25PM' }}\n  status=\"ON SCHEDULE\"\n  tag=\"KN204\"\n  progress={elapsed / duration}\n/>;\n```\n\n## When to use\n\n- The main card for a trip under way: a flight, a long train, a sea crossing.\n- A hero widget where the globe has room to breathe, next to smaller cards such as Arrival Card and Cruise Dial.\n\n## When not to use\n\n- Lists of trips: every card runs its own turning globe. Use Flight Track instead.\n- Trips with stops: one line cannot show them.\n\n## Notes\n\n- `progress` is yours to compute. Each change glides the plane along the line.\n- Pass your logo as `mark`, or `null` for none.\n- The globe's land is a rough, stylised shape, not a map. Do not use it to show real positions.\n- The plane is the Tabler Icons plane (MIT licence, via iconstack.io).\n"
  },
  "docs": "Prefer `npx kinetik-ui add route-card`: it installs dependencies with expo install, so versions match your Expo SDK."
}
