{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "zone-arc",
  "type": "registry:item",
  "title": "Zone Arc",
  "description": "A reading on a half dial of coloured zones: zones sweep in, a marker swings over and its zone lights up.",
  "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/zone-arc.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/zone-arc.tsx",
      "content": "import {\n  Canvas,\n  Group,\n  Path,\n  RoundedRect,\n  Skia,\n  type SkPath,\n  type SkRect,\n} from '@shopify/react-native-skia';\nimport { useEffect, useMemo, useState } from 'react';\nimport { StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native';\nimport {\n  useDerivedValue,\n  useSharedValue,\n  withSpring,\n  withTiming,\n  type SharedValue,\n} from 'react-native-reanimated';\n\nimport { useCountUp } from '../../lib/kinetik/hooks/use-count-up';\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { easings, spring } from '../../lib/kinetik/motion/motion';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\n\nexport type ArcZone = {\n  /** Upper end of the zone. The next zone starts here. */\n  to: number;\n  /** Colour of the zone. */\n  color: string;\n};\n\nexport type ZoneArcProps = {\n  value: number;\n  /** Where the arc starts. */\n  min: number;\n  /** The zones in order. The last one's `to` is the end of the arc. */\n  zones: ArcZone[];\n  /** Unit after the value, e.g. \"AQI\". */\n  unit?: string;\n  /** When it was read, e.g. \"4 min ago\". */\n  ago?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst H = 84;\nconst THICK = 30;\n/** Arc span: from 180° on the left over the top to 360° on the right. */\nconst START = 180;\nconst SWEEP = 180;\nconst GAP_DEG = 1.2;\n\n/** Fraction of the arc (0–1) for a value. */\nexport function arcFraction(value: number, min: number, max: number): number {\n  if (max <= min) return 0;\n  return Math.max(0, Math.min(1, (value - min) / (max - min)));\n}\n\n/** Index of the zone holding a value. */\nexport function zoneIndex(value: number, zones: ArcZone[]): number {\n  const i = zones.findIndex((z) => value < z.to);\n  return i < 0 ? zones.length - 1 : i;\n}\n\n/** One arc path per zone, with the stretch of the dial each one covers. */\nfunction zoneParts(zones: ArcZone[], min: number, max: number, box: SkRect) {\n  const parts = [];\n  let from = 0;\n  for (const zone of zones) {\n    const to = arcFraction(zone.to, min, max);\n    const path = Skia.PathBuilder.Make()\n      .addArc(box, START + from * SWEEP + GAP_DEG / 2, (to - from) * SWEEP - GAP_DEG)\n      .detach();\n    parts.push({ path, from, to, color: zone.color });\n    from = to;\n  }\n  return parts;\n}\n\n/**\n * A reading on a half dial of coloured zones: the zones sweep in around the arc, a\n * white marker swings to the value, and the zone it lands in lights up.\n */\nexport function ZoneArc({ value, min, zones, unit, ago, style }: ZoneArcProps) {\n  const { colors, font } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const [width, setWidth] = useState(0);\n  const shown = Math.round(useCountUp(value, { instant: reduced }));\n  const active = zoneIndex(value, zones);\n\n  return (\n    <View\n      accessible\n      accessibilityLabel={`${value}${unit ? ` ${unit}` : ''}, zone ${active + 1} of ${zones.length}${ago ? `, ${ago}` : ''}`}\n      style={[styles.card, style]}\n    >\n      <View style={styles.head}>\n        <Text\n          style={{\n            color: colors.highlight,\n            fontSize: font.size.lg,\n            fontWeight: font.weight.semibold,\n            fontVariant: ['tabular-nums'],\n          }}\n        >\n          {shown}\n          {unit ? <Text style={{ fontSize: font.size.xs }}> {unit}</Text> : null}\n        </Text>\n        {ago ? <Text style={{ color: MUTED, fontSize: font.size.xs }}>{ago}</Text> : null}\n      </View>\n      <View\n        testID=\"zone-arc-dial\"\n        style={styles.dial}\n        onLayout={(e) => setWidth(e.nativeEvent.layout.width)}\n      >\n        {width > 0 ? (\n          <Dial width={width} value={value} min={min} zones={zones} active={active} />\n        ) : null}\n      </View>\n    </View>\n  );\n}\n\nfunction Dial({\n  width,\n  value,\n  min,\n  zones,\n  active,\n}: {\n  width: number;\n  value: number;\n  min: number;\n  zones: ArcZone[];\n  active: number;\n}) {\n  const { colors } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const max = zones[zones.length - 1]?.to ?? min + 1;\n  const target = arcFraction(value, min, max);\n  const reveal = useSharedValue(reduced ? 1 : 0);\n  const at = useSharedValue(reduced ? target : 0);\n\n  useEffect(() => {\n    if (!reduced) reveal.set(withTiming(1, { duration: 700, easing: easings.standard }));\n  }, [reduced, reveal]);\n\n  useEffect(() => {\n    at.set(reduced ? target : withSpring(target, spring('smooth')));\n  }, [target, reduced, at]);\n\n  const radius = Math.min(width / 2 - THICK / 2, H * 1.5);\n  const cx = width / 2;\n  const cy = radius + THICK / 2;\n  const box = useMemo(\n    () => ({ x: cx - radius, y: cy - radius, width: radius * 2, height: radius * 2 }),\n    [cx, cy, radius],\n  );\n\n  const parts = useMemo(() => zoneParts(zones, min, max, box), [zones, min, max, box]);\n\n  const marker = useDerivedValue(() => [\n    { translateX: cx },\n    { translateY: cy },\n    { rotate: ((START + at.get() * SWEEP) * Math.PI) / 180 },\n  ]);\n\n  return (\n    <>\n      <Canvas style={{ width, height: H }}>\n        {parts.map((part, i) => (\n          <Zone key={i} {...part} lit={i === active} reveal={reveal} />\n        ))}\n        <Group transform={marker}>\n          <RoundedRect\n            x={radius - THICK / 2 - 3}\n            y={-3.5}\n            width={THICK + 6}\n            height={7}\n            r={3.5}\n            color={colors.highlight}\n          />\n        </Group>\n      </Canvas>\n      {parts.slice(0, -1).map((part) => {\n        const a = ((START + part.to * SWEEP) * Math.PI) / 180;\n        const r = radius - THICK / 2 - 10;\n        return (\n          <Text\n            key={part.to}\n            style={[\n              styles.mark,\n              {\n                left: cx + Math.cos(a) * r - 16,\n                top: cy + Math.sin(a) * r - 7,\n                transform: [{ rotate: `${(part.to - 0.5) * SWEEP}deg` }],\n              },\n            ]}\n          >\n            {Math.round(min + part.to * (max - min))}\n          </Text>\n        );\n      })}\n    </>\n  );\n}\n\nfunction Zone({\n  path,\n  from,\n  to,\n  color,\n  lit,\n  reveal,\n}: {\n  path: SkPath;\n  from: number;\n  to: number;\n  color: string;\n  lit: boolean;\n  reveal: SharedValue<number>;\n}) {\n  const end = useDerivedValue(() =>\n    Math.max(0, Math.min(1, (reveal.get() - from) / Math.max(0.001, to - from))),\n  );\n  return (\n    <Path\n      path={path}\n      style=\"stroke\"\n      strokeWidth={THICK}\n      color={color}\n      opacity={lit ? 1 : 0.3}\n      end={end}\n    />\n  );\n}\n\nconst MUTED = 'hsl(0, 0%, 62%)';\n\nconst styles = StyleSheet.create({\n  card: {\n    width: '100%',\n    maxWidth: 320,\n    alignSelf: 'center',\n    overflow: 'hidden',\n    borderRadius: 24,\n    borderWidth: 1,\n    borderColor: 'hsla(0, 0%, 100%, 0.08)',\n    backgroundColor: 'hsl(0, 0%, 5%)',\n    paddingTop: 16,\n    paddingHorizontal: 16,\n    gap: 6,\n  },\n  head: { flexDirection: 'row', alignItems: 'baseline', justifyContent: 'space-between' },\n  dial: { height: H },\n  mark: { position: 'absolute', width: 32, textAlign: 'center', fontSize: 10, color: MUTED },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "data",
    "web": "live",
    "perf": {
      "budget": "One Skia canvas. The sweep and marker run on the UI thread on arrival and on change. Nothing animates at rest.",
      "measurements": [
        {
          "device": "Huawei P20 Lite (ANE-LX1), Android 9",
          "kind": "device",
          "date": "2026-11-02",
          "build": "release",
          "frameMs": 12,
          "p90Ms": 18,
          "jankyPercent": 15.31,
          "atRest": "idle",
          "memoryMb": 126
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The dial appears whole, the marker jumps to its place and the number does not count.",
      "screenReader": "One label (\"86 AQI, zone 2 of 4, 4 min ago\").",
      "touchTarget": "Not interactive."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { ZoneArc } from '@/components/kinetik/zone-arc';\n\n<ZoneArc\n  value={86}\n  min={0}\n  zones={[\n    { to: 50, color: 'hsl(145, 76%, 44%)' },\n    { to: 100, color: 'hsl(50, 90%, 50%)' },\n    { to: 150, color: 'hsl(28, 90%, 50%)' },\n    { to: 200, color: 'hsl(350, 72%, 44%)' },\n  ]}\n  unit=\"AQI\"\n  ago=\"4 min ago\"\n/>;\n```\n\n## When to use\n\n- A reading with named ranges: air quality, noise, battery health.\n- When being in the right zone matters more than the exact figure.\n\n## When not to use\n\n- Colour alone cannot carry the meaning: pair it with a word if the zones have names.\n- Values with no zones. Use Gauge Meter.\n\n## Notes\n\n- Each zone runs from the previous `to` up to its own.\n- The zone holding the value is lit and the rest are dimmed.\n"
  },
  "docs": "Prefer `npx kinetik-ui add zone-arc`: it installs dependencies with expo install, so versions match your Expo SDK."
}
