{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "time-split",
  "type": "registry:item",
  "title": "Time Split",
  "description": "A total time on a raised panel, its split shown as coloured segments along the panel's curved bottom edge.",
  "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/time-split.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/time-split.tsx",
      "content": "import { Canvas, Path, Skia, type SkPath } from '@shopify/react-native-skia';\nimport { useEffect, useMemo, useState } from 'react';\nimport { StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native';\nimport { useDerivedValue, 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 TimeSplitItem = {\n  label: string;\n  minutes: number;\n  /** Colour of the segment and its square. Defaults to a rotation. */\n  color?: string;\n};\n\nexport type TimeSplitProps = {\n  title: string;\n  /** Up to about six items. The total is their sum. */\n  items: TimeSplitItem[];\n  /** Label under the hours. Defaults to \"Hours\". */\n  hoursLabel?: string;\n  /** Label under the minutes. Defaults to \"Minutes\". */\n  minutesLabel?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst ROTATION = [\n  'hsl(2, 80%, 66%)',\n  'hsl(216, 76%, 58%)',\n  'hsl(192, 70%, 62%)',\n  'hsl(248, 66%, 68%)',\n  'hsl(150, 70%, 42%)',\n  'hsl(220, 8%, 46%)',\n];\n\nconst CURVE = 30;\nconst RIM = 5;\nconst RIM_BOX = CURVE + RIM + 2;\n/** Space between segments, in points along the rim. */\nconst GAP = 7;\n\n/** Fractions of the rim for each item: where it starts and ends, gaps taken out. */\nexport function rimSegments(minutes: number[], length: number): [number, number][] {\n  const total = minutes.reduce((sum, m) => sum + Math.max(0, m), 0) || 1;\n  const gap = length > 0 ? GAP / length : 0;\n  let at = 0;\n  return minutes.map((m) => {\n    const start = at + gap / 2;\n    at += Math.max(0, m) / total;\n    return [start, Math.max(start, at - gap / 2)];\n  });\n}\n\nfunction spokenTime(minutes: number) {\n  const h = Math.floor(minutes / 60);\n  const m = minutes % 60;\n  const parts = [];\n  if (h) parts.push(`${h} ${h === 1 ? 'hour' : 'hours'}`);\n  if (m || !h) parts.push(`${m} ${m === 1 ? 'minute' : 'minutes'}`);\n  return parts.join(' ');\n}\n\n/**\n * A raised panel showing a total time, with the share of each activity as\n * coloured segments running along the panel's curved bottom edge. Segments glide\n * to their new lengths when the numbers change, and the time counts.\n */\nexport function TimeSplit({\n  title,\n  items,\n  hoursLabel = 'Hours',\n  minutesLabel = 'Minutes',\n  style,\n}: TimeSplitProps) {\n  const { colors, font, radius, space } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const [width, setWidth] = useState(0);\n  const total = items.reduce((sum, i) => sum + Math.max(0, i.minutes), 0);\n  const shown = Math.round(useCountUp(total, { instant: reduced }));\n  const hours = String(Math.floor(shown / 60)).padStart(2, '0');\n  const mins = String(shown % 60).padStart(2, '0');\n\n  const colorOf = (i: number) => items[i]?.color ?? ROTATION[i % ROTATION.length]!;\n  const rim = useMemo(() => {\n    if (!width) return null;\n    const edge = RIM / 2;\n    const bottom = CURVE + edge;\n    return Skia.Path.MakeFromSVGString(\n      `M${edge} 0C${edge} ${CURVE * 0.6} ${CURVE * 0.45} ${bottom} ${CURVE + edge} ${bottom}` +\n        `H${width - CURVE - edge}` +\n        `C${width - CURVE * 0.45} ${bottom} ${width - edge} ${CURVE * 0.6} ${width - edge} 0`,\n    );\n  }, [width]);\n  // The straight part plus two corners, close enough to size the gaps evenly.\n  const length = width - 2 * CURVE + 3 * CURVE;\n  const segments = rimSegments(\n    items.map((i) => i.minutes),\n    length,\n  );\n  const half = Math.ceil(items.length / 2);\n  const spoken = items.map((i) => `${i.label} ${spokenTime(i.minutes)}`).join(', ');\n\n  return (\n    <View\n      accessible\n      accessibilityLabel={`${title}: ${spokenTime(total)}. ${spoken}.`}\n      style={[styles.card, { borderColor: withAlpha(colors.highlight, 0.08) }, style]}\n      onLayout={(e) => setWidth(e.nativeEvent.layout.width)}\n    >\n      <View\n        pointerEvents=\"none\"\n        style={[\n          StyleSheet.absoluteFill,\n          styles.glow,\n          gradient(`linear-gradient(100deg, ${colorOf(0)} 0%, transparent 46%)`),\n        ]}\n      />\n      <View\n        pointerEvents=\"none\"\n        style={[\n          StyleSheet.absoluteFill,\n          styles.glow,\n          gradient(`linear-gradient(260deg, ${colorOf(2)} 0%, transparent 46%)`),\n        ]}\n      />\n      <View style={styles.raised}>\n        <View style={[styles.panel, gradient(PANEL), { paddingTop: space[5] }]}>\n          <Text\n            numberOfLines={1}\n            style={{\n              color: colors.highlight,\n              fontSize: font.size.lg - 1,\n              fontWeight: font.weight.medium,\n            }}\n          >\n            {title}\n          </Text>\n          <View style={[styles.time, { marginTop: space[1] }]}>\n            <Unit value={hours} label={hoursLabel} />\n            <Text\n              style={[\n                styles.colon,\n                {\n                  color: DIGIT,\n                  fontSize: font.size['3xl'] - 4,\n                  fontWeight: font.weight.semibold,\n                },\n              ]}\n            >\n              :\n            </Text>\n            <Unit value={mins} label={minutesLabel} />\n          </View>\n        </View>\n        {rim ? (\n          <Canvas style={{ ...styles.rim, width }} pointerEvents=\"none\">\n            {items.map((item, i) => (\n              <RimSegment\n                key={item.label}\n                path={rim}\n                color={colorOf(i)}\n                from={segments[i]![0]}\n                to={segments[i]![1]}\n              />\n            ))}\n          </Canvas>\n        ) : null}\n      </View>\n\n      <View style={[styles.legend, { padding: space[5], paddingTop: space[3], gap: space[3] }]}>\n        {[items.slice(0, half), items.slice(half)].map((column, c) => (\n          <View key={c} style={[styles.column, { gap: space[1.5] }]}>\n            {column.map((item, i) => (\n              <View key={item.label} style={[styles.entry, { gap: space[2] }]}>\n                <View\n                  style={[\n                    styles.square,\n                    {\n                      backgroundColor: colorOf(c === 0 ? i : half + i),\n                      borderRadius: radius.xs / 2,\n                    },\n                  ]}\n                />\n                <Text\n                  numberOfLines={1}\n                  style={[styles.grow, { color: LEGEND, fontSize: font.size.sm }]}\n                >\n                  {item.label}\n                </Text>\n              </View>\n            ))}\n          </View>\n        ))}\n      </View>\n    </View>\n  );\n}\n\nfunction Unit({ value, label }: { value: string; label: string }) {\n  const { font } = useKinetikTheme();\n  return (\n    <View style={styles.unit}>\n      <Text\n        style={{\n          color: DIGIT,\n          fontSize: font.size['3xl'] + 2,\n          fontWeight: font.weight.semibold,\n          fontVariant: ['tabular-nums'],\n          lineHeight: 42,\n        }}\n      >\n        {value}\n      </Text>\n      <Text style={{ color: DIGIT, fontSize: font.size.sm }}>{label}</Text>\n    </View>\n  );\n}\n\n/** One coloured stretch of the rim. It grows out from the left on arrival. */\nfunction RimSegment({\n  path,\n  color,\n  from,\n  to,\n}: {\n  path: SkPath;\n  color: string;\n  from: number;\n  to: number;\n}) {\n  const reduced = useReduceMotion();\n  const start = useSharedValue(reduced ? from : 0);\n  const end = useSharedValue(reduced ? to : 0);\n\n  useEffect(() => {\n    start.set(reduced ? from : withSpring(from, spring('smooth')));\n    end.set(reduced ? to : withSpring(to, spring('smooth')));\n  }, [from, to, reduced, start, end]);\n\n  // A stretch of no length would still draw its round caps.\n  const opacity = useDerivedValue(() => (end.get() - start.get() > 0.002 ? 1 : 0));\n\n  return (\n    <Path\n      path={path}\n      color={color}\n      style=\"stroke\"\n      strokeWidth={RIM}\n      strokeCap=\"round\"\n      start={start}\n      end={end}\n      opacity={opacity}\n    />\n  );\n}\n\nconst DIGIT = 'hsl(216, 34%, 86%)';\nconst LEGEND = 'hsl(216, 20%, 80%)';\nconst PANEL =\n  'linear-gradient(180deg, hsla(215, 12%, 34%, 0.72) 0%, hsla(218, 10%, 22%, 0.96) 100%)';\n\nconst styles = StyleSheet.create({\n  card: {\n    width: '100%',\n    maxWidth: 320,\n    alignSelf: 'center',\n    borderRadius: 38,\n    borderWidth: 1,\n    overflow: 'hidden',\n    backgroundColor: 'hsl(222, 12%, 13%)',\n    boxShadow: '0px 22px 48px hsla(222, 40%, 4%, 0.42)',\n  },\n  glow: { opacity: 0.22 },\n  raised: { paddingBottom: RIM + 2 },\n  panel: {\n    alignItems: 'center',\n    paddingBottom: 16,\n    borderBottomLeftRadius: CURVE,\n    borderBottomRightRadius: CURVE,\n  },\n  rim: { position: 'absolute', left: 0, bottom: 0, height: RIM_BOX },\n  time: { flexDirection: 'row', alignItems: 'flex-start', justifyContent: 'center', gap: 22 },\n  unit: { alignItems: 'center', minWidth: 62 },\n  colon: { lineHeight: 38 },\n  legend: { flexDirection: 'row' },\n  column: { flex: 1 },\n  entry: { flexDirection: 'row', alignItems: 'center' },\n  square: { width: 10, height: 10 },\n  grow: { flex: 1 },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "data",
    "web": "live",
    "perf": {
      "budget": "Segments trim one path on UI-thread springs on arrival and on change; the time 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": 36,
          "p90Ms": 42,
          "jankyPercent": 100,
          "atRest": "idle",
          "memoryMb": 143
        }
      ]
    },
    "a11y": {
      "reducedMotion": "Segments take their lengths and the time changes without gliding or counting.",
      "screenReader": "One label with the total and every item (\"Studio Hours: 4 hours 36 minutes. Coding 2 hours 30 minutes, Reading 1 hour 1 minute.\").",
      "touchTarget": "Not interactive."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { TimeSplit } from '@/components/kinetik/time-split';\n\n<TimeSplit\n  title=\"Studio Hours\"\n  items={[\n    { label: 'Sketching', minutes: 38 },\n    { label: 'Coding', minutes: 112 },\n    { label: 'Reviews', minutes: 44 },\n    { label: 'Reading', minutes: 26 },\n  ]}\n/>;\n```\n\n## When to use\n\n- A daily total and what it was spent on: screen time, focus time, a timesheet.\n- Widgets, where the split matters as a shape more than as exact numbers.\n\n## When not to use\n\n- When people must compare exact amounts per item. The legend has no values, so use a bar chart.\n- More than about six items: the segments get too short to tell apart.\n\n## Notes\n\n- The total is the sum of `minutes`; 90 reads as 01 : 30.\n- Items are matched by `label`, so keep labels stable and each segment glides to its new length.\n- The first and third colours tint the card's soft glow.\n"
  },
  "docs": "Prefer `npx kinetik-ui add time-split`: it installs dependencies with expo install, so versions match your Expo SDK."
}
