{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cruise-dial",
  "type": "registry:item",
  "title": "Cruise Dial",
  "description": "A numbered dial turns under a fixed needle and settles on the speed, while a small LCD counts to the same number.",
  "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-count.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/cruise-dial.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/cruise-dial.tsx",
      "content": "import { Canvas, Group, LinearGradient, Path, Skia, vec } from '@shopify/react-native-skia';\nimport { useEffect, useMemo, useState } from 'react';\nimport { StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native';\nimport Animated, { useAnimatedStyle, useSharedValue, withSpring } from 'react-native-reanimated';\n\nimport { useCountUp } from '../../lib/kinetik/hooks/use-count-up';\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { spring } from '../../lib/kinetik/motion/motion';\nimport { gradient } from '../../lib/kinetik/tokens/gradient';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport { withAlpha } from '../../lib/kinetik/tokens/tokens';\n\nexport type CruiseDialProps = {\n  /** The speed the dial and the display settle on. */\n  speed: number;\n  /** Unit beside the display, e.g. \"/KMH\". */\n  unit?: string;\n  /** Numbered marks on the dial are this far apart. Defaults to 100. */\n  step?: number;\n  /** Chip in the corner, e.g. the flight number. */\n  tag?: string;\n  /** Label over the reading, e.g. \"CEILING:\". */\n  label?: string;\n  /** Figure in the corner, e.g. \"11,234 M\". */\n  reading?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\n/** Degrees between numbered marks. The last mark stays out of sight of the first. */\nconst STEP_DEG = 28;\nconst MARKS = 10;\nconst MINOR = 5;\nconst DIGITS = 4;\n\n/** Which of the seven segments each digit lights: top, top right, bottom right, bottom, bottom left, top left, middle. */\nconst SEGMENTS: Record<string, string> = {\n  '0': '1111110',\n  '1': '0110000',\n  '2': '1101101',\n  '3': '1111001',\n  '4': '0110011',\n  '5': '1011011',\n  '6': '1011111',\n  '7': '1110000',\n  '8': '1111111',\n  '9': '1111011',\n};\n\n/** SVG path of the lit segments of `digits`, each in a 10 by 18 cell, 3 apart. */\nexport function segmentPath(digits: string) {\n  const bars = [\n    'M1.5 0H8.5L7 2H3Z',\n    'M10 1.5V8L8 7V3Z',\n    'M10 10V16.5L8 15V11Z',\n    'M1.5 18H8.5L7 16H3Z',\n    'M0 10V16.5L2 15V11Z',\n    'M0 1.5V8L2 7V3Z',\n    'M1.5 9L3 8H7L8.5 9L7 10H3Z',\n  ];\n  return [...digits]\n    .map((digit, i) =>\n      bars\n        .filter((_, s) => SEGMENTS[digit]?.[s] === '1')\n        .map((bar) => shift(bar, i * 13))\n        .join(''),\n    )\n    .join('');\n}\n\n/** Moves an absolute path made of M, H, V, L and Z along x. */\nfunction shift(d: string, dx: number) {\n  return d.replace(/([MLHV])([\\d.]+)(?: ([\\d.]+))?/g, (_, op: string, a: string, b?: string) => {\n    if (op === 'V') return `${op}${a}`;\n    return `${op}${Number(a) + dx}${b === undefined ? '' : ` ${b}`}`;\n  });\n}\n\n/**\n * A cockpit-style speed readout: a big numbered dial turns under a fixed needle\n * and settles on the speed, while a small LCD counts to the same number. The\n * dial's lit arc warms towards the needle from the left.\n */\nexport function CruiseDial({\n  speed,\n  unit = '/KMH',\n  step = 100,\n  tag,\n  label,\n  reading,\n  style,\n}: CruiseDialProps) {\n  const { colors, font, radius, space } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const [width, setWidth] = useState(0);\n  const max = step * (MARKS - 1);\n  const v = Math.max(0, Math.min(max, speed));\n  const shown = Math.round(useCountUp(v, { instant: reduced, from: Math.max(0, v - step) }));\n\n  const turn = useSharedValue(reduced ? v : Math.max(0, v - step));\n  useEffect(() => {\n    turn.set(reduced ? v : withSpring(v, spring('smooth')));\n  }, [v, reduced, turn]);\n  const dial = useAnimatedStyle(() => ({\n    transform: [{ rotate: `${(-turn.get() / step) * STEP_DEG}deg` }],\n  }));\n\n  const r = width * 0.54;\n  const top = width * 0.44;\n\n  return (\n    <View\n      accessible\n      accessibilityLabel={[tag, label && reading ? `${label} ${reading}` : reading, `${v} ${unit}`]\n        .filter(Boolean)\n        .join('. ')}\n      onLayout={(e) => setWidth(e.nativeEvent.layout.width)}\n      style={[styles.card, gradient(BACKDROP), { padding: space[4] }, style]}\n    >\n      {width > 0 ? (\n        <>\n          <Grid width={width} />\n          <Animated.View\n            pointerEvents=\"none\"\n            testID=\"cruise-dial-scale\"\n            style={[styles.scale, { width: r * 2, height: r * 2, left: width / 2 - r, top }, dial]}\n          >\n            <Ticks r={r} />\n            {Array.from({ length: MARKS }, (_, i) => (\n              <View\n                key={i}\n                style={[\n                  styles.mark,\n                  {\n                    left: r - 24,\n                    top: r - 8,\n                    transform: [{ rotate: `${i * STEP_DEG}deg` }, { translateY: -(r - 28) }],\n                  },\n                ]}\n              >\n                <Text style={{ color: withAlpha(colors.highlight, 0.72), fontSize: font.size.xs }}>\n                  {i * step}\n                </Text>\n              </View>\n            ))}\n          </Animated.View>\n          <Rim width={width} r={r} top={top} />\n          <View\n            style={[styles.needle, { left: width / 2 - 1.5, top: top - 7, height: width * 0.3 }]}\n          >\n            <View style={styles.needleTip} />\n          </View>\n        </>\n      ) : null}\n\n      <View style={styles.top}>\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        <View style={styles.end}>\n          {label ? (\n            <Text\n              numberOfLines={1}\n              style={{ color: MUTED, fontSize: font.size.xs, fontWeight: font.weight.medium }}\n            >\n              {label}\n            </Text>\n          ) : null}\n          {reading ? (\n            <Text\n              numberOfLines={1}\n              style={{\n                color: colors.highlight,\n                fontSize: font.size.sm + 1,\n                fontWeight: font.weight.semibold,\n              }}\n            >\n              {reading}\n            </Text>\n          ) : null}\n        </View>\n      </View>\n\n      <View style={styles.lcdWrap}>\n        <Lcd value={shown} unit={unit} />\n      </View>\n    </View>\n  );\n}\n\n/** The faint grid behind the dial. */\nfunction Grid({ width }: { width: number }) {\n  const { colors } = useKinetikTheme();\n  const lines = useMemo(() => {\n    const gap = width / 8;\n    let d = '';\n    for (let i = 1; i < 8; i++) d += `M${i * gap} 0V${width}M0 ${i * gap}H${width}`;\n    return Skia.Path.MakeFromSVGString(d);\n  }, [width]);\n  if (!lines) return null;\n  return (\n    <Canvas style={{ ...styles.fill, width, height: width }} pointerEvents=\"none\">\n      <Path\n        path={lines}\n        color={withAlpha(colors.highlight, 0.035)}\n        style=\"stroke\"\n        strokeWidth={1}\n      />\n    </Canvas>\n  );\n}\n\n/** Tick marks around the dial. They turn with it as one still canvas. */\nfunction Ticks({ r }: { r: number }) {\n  const { colors } = useKinetikTheme();\n  const [major, minor] = useMemo(() => {\n    const ticks = (from: number, to: number, keep: (i: number) => boolean) => {\n      let d = '';\n      for (let i = 0; i < (MARKS - 1) * MINOR + 1; i++) {\n        if (!keep(i)) continue;\n        const a = ((i * STEP_DEG) / MINOR - 90) * (Math.PI / 180);\n        d +=\n          `M${(r + Math.cos(a) * from).toFixed(2)} ${(r + Math.sin(a) * from).toFixed(2)}` +\n          `L${(r + Math.cos(a) * to).toFixed(2)} ${(r + Math.sin(a) * to).toFixed(2)}`;\n      }\n      return Skia.Path.MakeFromSVGString(d);\n    };\n    return [\n      ticks(r - 14, r - 2, (i) => i % MINOR === 0),\n      ticks(r - 8, r - 2, (i) => i % MINOR !== 0),\n    ];\n  }, [r]);\n  return (\n    <Canvas style={{ width: r * 2, height: r * 2 }}>\n      {major ? (\n        <Path\n          path={major}\n          color={withAlpha(colors.highlight, 0.8)}\n          style=\"stroke\"\n          strokeWidth={1.5}\n        />\n      ) : null}\n      {minor ? (\n        <Path\n          path={minor}\n          color={withAlpha(colors.highlight, 0.34)}\n          style=\"stroke\"\n          strokeWidth={1}\n        />\n      ) : null}\n    </Canvas>\n  );\n}\n\n/** The fixed rim: warm on the left, up to the needle, and grey on the right. */\nfunction Rim({ width, r, top }: { width: number; r: number; top: number }) {\n  const [warm, cool] = useMemo(() => {\n    const oval = { x: width / 2 - r, y: top, width: r * 2, height: r * 2 };\n    const arc = (start: number, sweep: number) =>\n      Skia.PathBuilder.Make().addArc(oval, start, sweep).detach();\n    return [arc(216, 54), arc(270, 54)];\n  }, [width, r, top]);\n  return (\n    <Canvas style={{ ...styles.fill, width, height: width }} pointerEvents=\"none\">\n      <Group>\n        <Path path={warm} style=\"stroke\" strokeWidth={4} strokeCap=\"round\">\n          <LinearGradient\n            start={vec(width * 0.05, 0)}\n            end={vec(width / 2, 0)}\n            colors={[RIM_FADE, RIM_RED]}\n          />\n        </Path>\n        <Path path={cool} style=\"stroke\" strokeWidth={4} strokeCap=\"round\">\n          <LinearGradient\n            start={vec(width / 2, 0)}\n            end={vec(width * 0.95, 0)}\n            colors={[RIM_GREY, RIM_FADE]}\n          />\n        </Path>\n      </Group>\n    </Canvas>\n  );\n}\n\n/** A small LCD: dark segments on green, unlit eights faintly behind. */\nfunction Lcd({ value, unit }: { value: number; unit: string }) {\n  const { font, radius } = useKinetikTheme();\n  const digits = String(Math.max(0, value)).slice(-DIGITS);\n  const lit = useMemo(() => Skia.Path.MakeFromSVGString(segmentPath(digits)), [digits]);\n  const ghost = useMemo(() => Skia.Path.MakeFromSVGString(segmentPath('8'.repeat(DIGITS))), []);\n  const offset = (DIGITS - digits.length) * 13 * LCD_SCALE;\n  return (\n    <View style={[styles.lcdFrame, { borderRadius: radius.xs + 2 }]}>\n      <View style={[styles.lcd, gradient(LCD), { borderRadius: radius.xs - 1 }]}>\n        <Canvas style={styles.lcdDigits}>\n          <Group transform={[{ scale: LCD_SCALE }]}>\n            {ghost ? <Path path={ghost} color={LCD_GHOST} /> : null}\n          </Group>\n          <Group transform={[{ translateX: offset }, { scale: LCD_SCALE }]}>\n            {lit ? <Path path={lit} color={LCD_INK} /> : null}\n          </Group>\n        </Canvas>\n        <Text\n          style={{\n            color: LCD_INK,\n            fontSize: font.size.xs - 3,\n            fontWeight: font.weight.bold,\n            alignSelf: 'flex-end',\n          }}\n        >\n          {unit}\n        </Text>\n      </View>\n    </View>\n  );\n}\n\nconst LCD_SCALE = 1.15;\nconst MUTED = 'hsl(214, 10%, 62%)';\nconst RIM_RED = 'hsl(356, 78%, 52%)';\nconst RIM_GREY = 'hsl(214, 8%, 58%)';\nconst RIM_FADE = 'hsla(214, 8%, 20%, 0.25)';\nconst LCD_INK = 'hsl(90, 30%, 12%)';\nconst LCD_GHOST = 'hsla(90, 30%, 12%, 0.1)';\nconst LCD = 'linear-gradient(180deg, hsl(78, 26%, 54%) 0%, hsl(72, 34%, 68%) 100%)';\nconst BACKDROP =\n  'linear-gradient(180deg, hsl(220, 12%, 10%) 0%, hsl(214, 24%, 14%) 62%, hsl(220, 12%, 7%) 100%)';\n\nconst styles = StyleSheet.create({\n  card: {\n    width: '100%',\n    maxWidth: 260,\n    aspectRatio: 1,\n    alignSelf: 'center',\n    borderRadius: 30,\n    overflow: 'hidden',\n    justifyContent: 'space-between',\n    boxShadow: '0px 18px 40px hsla(220, 30%, 5%, 0.3)',\n  },\n  fill: { position: 'absolute', top: 0, left: 0 },\n  scale: { position: 'absolute' },\n  mark: { position: 'absolute', width: 48, height: 16, alignItems: 'center' },\n  needle: {\n    position: 'absolute',\n    width: 3,\n    borderRadius: 1.5,\n    backgroundColor: 'hsl(36, 92%, 54%)',\n  },\n  needleTip: { height: 14, borderRadius: 1.5, backgroundColor: 'hsl(356, 78%, 52%)' },\n  top: { flexDirection: 'row', alignItems: 'flex-start', justifyContent: 'space-between' },\n  end: { alignItems: 'flex-end', flexShrink: 1 },\n  chip: {\n    paddingHorizontal: 11,\n    paddingVertical: 7,\n    backgroundColor: 'hsl(214, 16%, 22%)',\n  },\n  lcdWrap: { alignItems: 'center' },\n  lcdFrame: { padding: 4, backgroundColor: 'hsl(214, 6%, 30%)' },\n  lcd: { flexDirection: 'row', gap: 3, paddingHorizontal: 6, paddingVertical: 4 },\n  lcdDigits: { width: (DIGITS * 13 - 3) * LCD_SCALE, height: 18 * LCD_SCALE },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "data",
    "web": "live",
    "perf": {
      "budget": "The dial is a still canvas turned as a view on the UI thread, so it does not redraw. The LCD re-renders only while it counts. Nothing animates at rest.",
      "measurements": [
        {
          "device": "Huawei P20 Lite (ANE-LX1), Android 9",
          "kind": "device",
          "date": "2026-11-02",
          "build": "release",
          "frameMs": 24,
          "p90Ms": 34,
          "jankyPercent": 96.32,
          "atRest": "idle",
          "memoryMb": 132
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The dial and the display jump to the speed.",
      "screenReader": "One label (\"KN204. CEILING: 11,234 M. 842 /KMH\").",
      "touchTarget": "Not interactive."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { CruiseDial } from '@/components/kinetik/cruise-dial';\n\n<CruiseDial speed={842} unit=\"/KMH\" tag=\"KN204\" label=\"CEILING:\" reading=\"11,234 M\" />;\n```\n\n## When to use\n\n- One live speed with character: a flight, a car, a bike ride, a download.\n- Next to Route Card and Arrival Card on a trip screen.\n\n## When not to use\n\n- Readings people must compare or read closely. Use a plain number or a chart.\n- Values that jump around quickly: the dial needs a moment to settle.\n\n## Notes\n\n- The dial shows ten numbered marks from zero, `step` apart. With the default `step` it reads 0 to 900, and `speed` is clamped to that range.\n- Set `step` to fit your range, for example `step={20}` for 0 to 180.\n- The display shows up to four digits, with unlit eights behind them.\n"
  },
  "docs": "Prefer `npx kinetik-ui add cruise-dial`: it installs dependencies with expo install, so versions match your Expo SDK."
}
