{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "vinyl-player",
  "type": "registry:item",
  "title": "Vinyl Player",
  "description": "A music card whose cover is a record half out of its sleeve, spinning while it plays and coasting to a stop.",
  "categories": [
    "card"
  ],
  "dependencies": [
    "react-native-reanimated",
    "react-native-svg",
    "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-haptics.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/vinyl-player.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/vinyl-player.tsx",
      "content": "import { useEffect, useRef, useState } from 'react';\nimport {\n  Image,\n  Pressable,\n  StyleSheet,\n  Text,\n  View,\n  type GestureResponderEvent,\n  type ImageSourcePropType,\n  type StyleProp,\n  type ViewStyle,\n} from 'react-native';\nimport Animated, {\n  Easing,\n  cancelAnimation,\n  useAnimatedStyle,\n  useSharedValue,\n  withRepeat,\n  withSequence,\n  withSpring,\n  withTiming,\n} from 'react-native-reanimated';\nimport Svg, { Path } from 'react-native-svg';\n\nimport { useHaptic } from '../../lib/kinetik/hooks/use-haptic';\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { spring, timing } from '../../lib/kinetik/motion/motion';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport { withAlpha } from '../../lib/kinetik/tokens/tokens';\n\nexport type VinylTrack = {\n  id: string;\n  title: string;\n  artist: string;\n  cover: ImageSourcePropType;\n  /** Length in seconds. */\n  duration: number;\n};\n\nexport type VinylPlayerProps = {\n  tracks: readonly VinylTrack[];\n  /** Start playing at once. Defaults to false. Ignored when `playing` is set. */\n  autoPlay?: boolean;\n  /** Whether it plays, owned by your app. Leave unset to let the player keep its own state. */\n  playing?: boolean;\n  /**\n   * Seconds into the current track, reported by your audio engine. Setting it turns the\n   * player's own clock off: the bar and the time follow this value.\n   */\n  position?: number;\n  /** The id of the current track, owned by your app (say, after a skip from the lock screen). */\n  trackId?: string;\n  onTrackChange?: (track: VinylTrack) => void;\n  onPlayingChange?: (playing: boolean) => void;\n  /** Called with the seconds to jump to when the bar is tapped, stepped or Previous restarts. */\n  onSeek?: (seconds: number) => void;\n  /** Called when the mute button is toggled. Without it there is no mute button. */\n  onMutedChange?: (muted: boolean) => void;\n  /** Colour of the progress. Defaults to the theme azure. */\n  accent?: string;\n  /** A tick on each control. Defaults to true. */\n  haptics?: boolean;\n  style?: StyleProp<ViewStyle>;\n};\n\n// Player icons from Tabler Icons (MIT, https://tabler.io/icons), via iconstack.io.\nconst ICONS = {\n  play: 'M7 4v16l13 -8z',\n  pause:\n    'M6 6a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z M14 6a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z',\n  next: 'M3 5v14l8 -7z M14 5v14l8 -7z',\n  prev: 'M21 5v14l-8 -7z M10 5v14l-8 -7z',\n  volume:\n    'M15 8a5 5 0 0 1 0 8 M17.7 5a9 9 0 0 1 0 14 M6 15h-2a1 1 0 0 1 -1 -1v-4a1 1 0 0 1 1 -1h2l3.5 -4.5a.8 .8 0 0 1 1.5 .5v14a.8 .8 0 0 1 -1.5 .5l-3.5 -4.5',\n  muted:\n    'M6 15h-2a1 1 0 0 1 -1 -1v-4a1 1 0 0 1 1 -1h2l3.5 -4.5a.8 .8 0 0 1 1.5 .5v14a.8 .8 0 0 1 -1.5 .5l-3.5 -4.5 M16 10l4 4m0 -4l-4 4',\n};\n\nconst DISC = 132;\n/** One full turn of the record, in ms. */\nconst TURN = 6000;\n\n/**\n * Playback state for one track: a 0–1 progress that runs on the UI thread\n * while playing, and whole seconds for the readout. Given a `position`, the\n * own clock is off and the bar follows the reported seconds instead.\n */\nfunction usePlayback(\n  duration: number,\n  playing: boolean,\n  track: string,\n  onEnd: () => void,\n  position?: number,\n) {\n  const controlled = position !== undefined;\n  const progress = useSharedValue(0);\n  const [elapsed, setElapsed] = useState(0);\n  const [seeks, setSeeks] = useState(0);\n  const ended = useRef(onEnd);\n  useEffect(() => {\n    ended.current = onEnd;\n  });\n\n  // A new track starts from the top: the readout resets during render, the bar in an effect.\n  const [current, setCurrent] = useState(track);\n  if (current !== track) {\n    setCurrent(track);\n    setElapsed(0);\n  }\n  useEffect(() => {\n    cancelAnimation(progress);\n    progress.set(0);\n  }, [track, progress]);\n\n  useEffect(() => {\n    if (controlled || !playing || duration <= 0) {\n      cancelAnimation(progress);\n      return;\n    }\n    const from = progress.get();\n    progress.set(\n      withTiming(1, { duration: Math.max(0, (1 - from) * duration * 1000), easing: Easing.linear }),\n    );\n    const id = setInterval(() => {\n      const p = progress.get();\n      setElapsed(Math.floor(p * duration));\n      if (p >= 1) ended.current();\n    }, 250);\n    return () => {\n      clearInterval(id);\n      cancelAnimation(progress);\n    };\n  }, [controlled, playing, duration, track, seeks, progress]);\n\n  // Driven from outside: glide to each reported position, so sparse updates still read smoothly.\n  useEffect(() => {\n    if (position === undefined || duration <= 0) return;\n    const p = Math.max(0, Math.min(1, position / duration));\n    progress.set(withTiming(p, { duration: 250, easing: Easing.linear }));\n  }, [position, duration, track, progress]);\n\n  /** Moves the bar at once and returns the seconds to jump to. */\n  const seek = (share: number) => {\n    const p = Math.max(0, Math.min(1, share));\n    cancelAnimation(progress);\n    progress.set(p);\n    if (!controlled) {\n      setElapsed(Math.floor(p * duration));\n      setSeeks((n) => n + 1);\n    }\n    // Whole milliseconds, so a ten-second step reports 59, not 58.99999.\n    return Math.round(p * duration * 1000) / 1000;\n  };\n\n  const shown =\n    position === undefined ? elapsed : Math.floor(Math.max(0, Math.min(duration, position)));\n  return { progress, elapsed: shown, seek };\n}\n\nfunction mmss(seconds: number) {\n  const s = Math.max(0, Math.floor(seconds));\n  return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;\n}\n\n/**\n * A light music card with the cover as a record half out of its sleeve: it\n * spins while the track plays and coasts to a stop on pause. The pressed\n * control flashes a ring, the mute icon pops between states, and a new track\n * drops its record in with a little turn.\n */\nexport function VinylPlayer({\n  tracks,\n  autoPlay = false,\n  playing: playingProp,\n  position,\n  trackId,\n  onTrackChange,\n  onPlayingChange,\n  onSeek,\n  onMutedChange,\n  accent,\n  haptics = true,\n  style,\n}: VinylPlayerProps) {\n  const { colors, radius, space, font, shadow } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const [ownIndex, setOwnIndex] = useState(0);\n  const [ownPlaying, setOwnPlaying] = useState(autoPlay);\n  const [muted, setMuted] = useState(false);\n  const [barWidth, setBarWidth] = useState(0);\n  // Each of these is the app's when it passes the prop, the player's own otherwise.\n  const picked = trackId === undefined ? -1 : tracks.findIndex((t) => t.id === trackId);\n  const index = picked >= 0 ? picked : ownIndex;\n  const playing = playingProp ?? ownPlaying;\n  const track = tracks[index];\n  const tone = accent ?? colors.azure;\n\n  const go = (to: number) => {\n    const next = (to + tracks.length) % tracks.length;\n    if (trackId === undefined) setOwnIndex(next);\n    const t = tracks[next];\n    if (t) onTrackChange?.(t);\n  };\n  const { progress, elapsed, seek } = usePlayback(\n    track?.duration ?? 0,\n    playing,\n    track?.id ?? '',\n    () => go(index + 1),\n    position,\n  );\n  const seekTo = (share: number) => {\n    const seconds = seek(share);\n    onSeek?.(seconds);\n  };\n\n  // The record keeps its angle between plays, so pausing never snaps it back.\n  const angle = useSharedValue(0);\n  useEffect(() => {\n    if (!playing || reduced) {\n      const at = angle.get();\n      cancelAnimation(angle);\n      // Coast a little further, like a platter slowing down.\n      if (!reduced && at > 0)\n        angle.set(withTiming(at + 24, { duration: 700, easing: Easing.out(Easing.quad) }));\n      return;\n    }\n    // Each loop runs a full turn from the current angle, so the repeat never shows a jump.\n    const from = angle.get() % 360;\n    angle.set(from);\n    angle.set(withRepeat(withTiming(from + 360, { duration: TURN, easing: Easing.linear }), -1));\n    return () => cancelAnimation(angle);\n  }, [playing, reduced, angle]);\n\n  const drop = useSharedValue(1);\n  useEffect(() => {\n    if (reduced) return;\n    drop.set(withSequence(withTiming(0, { duration: 0 }), withSpring(1, spring('smooth'))));\n  }, [index, reduced, drop]);\n\n  const record = useAnimatedStyle(() => ({\n    opacity: 0.4 + drop.get() * 0.6,\n    transform: [\n      { translateX: (1 - drop.get()) * -24 },\n      { rotate: `${angle.get() - (1 - drop.get()) * 60}deg` },\n    ],\n  }));\n  // A transform, not a width, so the bar never asks for layout while it plays.\n  const fill = useAnimatedStyle(() => ({ transform: [{ scaleX: progress.get() }] }));\n\n  if (!track) return null;\n\n  const press = (fn: () => void) => () => {\n    haptic('tick');\n    fn();\n  };\n\n  return (\n    <View style={[styles.host, style]}>\n      <View\n        style={[\n          styles.card,\n          {\n            marginLeft: DISC * 0.5,\n            paddingLeft: DISC * 0.5 + space[4],\n            paddingRight: space[4],\n            paddingVertical: space[4],\n            borderRadius: radius.xl - 4,\n            backgroundColor: colors.surfaceRaised,\n            borderColor: colors.border,\n            boxShadow: shadow.lg,\n          },\n        ]}\n      >\n        <View style={styles.head}>\n          <View\n            accessible\n            accessibilityLabel={`${track.title}, ${track.artist}`}\n            style={styles.grow}\n          >\n            <Text\n              numberOfLines={1}\n              style={{ color: colors.text, fontSize: font.size.lg, fontWeight: font.weight.medium }}\n            >\n              {track.title}\n            </Text>\n            <Text numberOfLines={1} style={{ color: colors.textSubtle, fontSize: font.size.sm }}>\n              {track.artist}\n            </Text>\n          </View>\n          {onMutedChange ? (\n            <MuteButton\n              muted={muted}\n              onPress={() => {\n                haptic('tap');\n                setMuted(!muted);\n                onMutedChange(!muted);\n              }}\n            />\n          ) : null}\n        </View>\n\n        <Pressable\n          accessibilityRole=\"adjustable\"\n          accessibilityLabel=\"Playback position\"\n          accessibilityValue={{\n            min: 0,\n            max: track.duration,\n            now: elapsed,\n            text: `${mmss(elapsed)} of ${mmss(track.duration)}`,\n          }}\n          accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }]}\n          onAccessibilityAction={(e) => {\n            const step = 10 / track.duration;\n            seekTo(\n              elapsed / track.duration + (e.nativeEvent.actionName === 'increment' ? step : -step),\n            );\n          }}\n          onLayout={(e) => setBarWidth(e.nativeEvent.layout.width)}\n          onPress={(e: GestureResponderEvent) =>\n            barWidth > 0 && seekTo(e.nativeEvent.locationX / barWidth)\n          }\n          style={[styles.barHit, { marginTop: space[3] - 14 }]}\n        >\n          <View style={[styles.bar, { backgroundColor: colors.track }]}>\n            <Animated.View style={[styles.barFill, { backgroundColor: tone }, fill]} />\n          </View>\n        </Pressable>\n\n        <View style={[styles.controls, { marginTop: space[2] }]}>\n          <RingButton\n            label=\"Previous\"\n            icon={ICONS.prev}\n            onPress={press(() => (elapsed > 3 ? seekTo(0) : go(index - 1)))}\n          />\n          <RingButton\n            label={playing ? 'Pause' : 'Play'}\n            icon={playing ? ICONS.pause : ICONS.play}\n            onPress={press(() => {\n              if (playingProp === undefined) setOwnPlaying(!playing);\n              onPlayingChange?.(!playing);\n            })}\n          />\n          <RingButton label=\"Next\" icon={ICONS.next} onPress={press(() => go(index + 1))} />\n        </View>\n      </View>\n\n      <View pointerEvents=\"none\" style={[styles.discSlot, { width: DISC, height: DISC }]}>\n        <Animated.View\n          style={[\n            styles.disc,\n            { width: DISC, height: DISC, borderRadius: DISC / 2, boxShadow: shadow.lg },\n            record,\n          ]}\n        >\n          <Image\n            source={track.cover}\n            style={StyleSheet.absoluteFill}\n            resizeMode=\"cover\"\n            accessibilityIgnoresInvertColors\n          />\n          {/* Grooves and the spindle hole, so the turn reads even on a plain cover. */}\n          <View\n            style={[\n              styles.groove,\n              { inset: DISC * 0.16, borderColor: withAlpha(colors.highlight, 0.18) },\n            ]}\n          />\n          <View\n            style={[\n              styles.groove,\n              { inset: DISC * 0.3, borderColor: withAlpha(colors.highlight, 0.14) },\n            ]}\n          />\n          <View\n            style={[\n              styles.hole,\n              { backgroundColor: colors.highlight, borderColor: withAlpha(colors.text, 0.2) },\n            ]}\n          />\n        </Animated.View>\n      </View>\n    </View>\n  );\n}\n\n/** A round control whose ring flashes out when pressed. */\nfunction RingButton({\n  label,\n  icon,\n  onPress,\n}: {\n  label: string;\n  icon: string;\n  onPress: () => void;\n}) {\n  const { colors } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const flash = useSharedValue(0);\n  const ring = useAnimatedStyle(() => ({\n    opacity: flash.get(),\n    transform: [{ scale: 0.7 + flash.get() * 0.3 }],\n  }));\n  return (\n    <Pressable\n      accessibilityRole=\"button\"\n      accessibilityLabel={label}\n      onPress={() => {\n        if (!reduced) {\n          flash.set(withSequence(withTiming(1, timing('quick')), withTiming(0, timing('slow'))));\n        }\n        onPress();\n      }}\n      style={({ pressed }) => [styles.round, { transform: [{ scale: pressed ? 0.9 : 1 }] }]}\n    >\n      <Animated.View\n        style={[\n          styles.ring,\n          { borderColor: colors.borderStrong, backgroundColor: withAlpha(colors.text, 0.05) },\n          ring,\n        ]}\n      />\n      <Svg width={22} height={22} viewBox=\"0 0 24 24\">\n        <Path\n          d={icon}\n          fill={colors.text}\n          stroke={colors.text}\n          strokeWidth={2}\n          strokeLinejoin=\"round\"\n        />\n      </Svg>\n    </Pressable>\n  );\n}\n\nfunction MuteButton({ muted, onPress }: { muted: boolean; onPress: () => void }) {\n  const { colors } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const pop = useSharedValue(1);\n  useEffect(() => {\n    if (!reduced)\n      pop.set(withSequence(withTiming(0.6, { duration: 0 }), withSpring(1, spring('bouncy'))));\n  }, [muted, reduced, pop]);\n  const style = useAnimatedStyle(() => ({ transform: [{ scale: pop.get() }] }));\n  return (\n    <Pressable\n      accessibilityRole=\"switch\"\n      accessibilityLabel=\"Mute\"\n      accessibilityState={{ checked: muted }}\n      onPress={onPress}\n      style={styles.round}\n    >\n      <Animated.View style={style}>\n        <Svg width={20} height={20} viewBox=\"0 0 24 24\" fill=\"none\">\n          <Path\n            d={muted ? ICONS.muted : ICONS.volume}\n            stroke={colors.textSubtle}\n            strokeWidth={2}\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n          />\n        </Svg>\n      </Animated.View>\n    </Pressable>\n  );\n}\n\nconst styles = StyleSheet.create({\n  host: { justifyContent: 'center' },\n  card: { borderWidth: StyleSheet.hairlineWidth },\n  head: { flexDirection: 'row', alignItems: 'flex-start' },\n  grow: { flex: 1, minWidth: 0, paddingTop: 2 },\n  // 44 pt to touch, with the extra height taken back so the bar keeps its place.\n  barHit: { height: 44, marginVertical: -14, justifyContent: 'center' },\n  bar: { height: 4, borderRadius: 2, overflow: 'hidden' },\n  barFill: { height: 4, width: '100%', transformOrigin: 'left center' },\n  controls: { flexDirection: 'row', justifyContent: 'space-between', marginHorizontal: -8 },\n  round: { width: 48, height: 48, alignItems: 'center', justifyContent: 'center' },\n  ring: { position: 'absolute', width: 48, height: 48, borderRadius: 24, borderWidth: 2 },\n  discSlot: { position: 'absolute', left: 0, alignSelf: 'center' },\n  disc: { overflow: 'hidden', alignItems: 'center', justifyContent: 'center' },\n  groove: { position: 'absolute', borderRadius: 999, borderWidth: 1 },\n  hole: { width: 14, height: 14, borderRadius: 7, borderWidth: 1 },\n});\n"
    }
  ],
  "meta": {
    "version": "1.1.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "card",
    "web": "live",
    "perf": {
      "budget": "While playing, the record turns with one repeating UI-thread timing and the progress with another; the time re-renders four times a second. Paused, nothing animates.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-14",
          "build": "release",
          "frameMs": 17,
          "p90Ms": 18,
          "baselineMs": 17,
          "jankyPercent": 1.39,
          "atRest": "idle",
          "memoryMb": 171
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The record does not spin or drop in; controls change state without the ring flash or icon pop.",
      "screenReader": "Title and artist read as one line; the progress is adjustable in ten-second steps; Mute is a switch; Previous, Play/Pause and Next are buttons.",
      "touchTarget": "Controls and the mute switch are 48 pt; the progress bar's touch area is 44 pt tall."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { VinylPlayer } from '@/components/kinetik/vinyl-player';\n\n<VinylPlayer\n  tracks={queue.map((t) => ({\n    id: t.id,\n    title: t.title,\n    artist: t.artist,\n    cover: { uri: t.artwork },\n    duration: t.seconds,\n  }))}\n  onPlayingChange={(on) => (on ? player.play() : player.pause())}\n  onTrackChange={(t) => player.load(t.id)}\n  onMutedChange={player.setMuted}\n/>;\n```\n\n### With a real audio engine\n\nPass `playing`, `position` and `trackId` from your player, and the card follows it instead of keeping its own clock. Buffering, a seek from the lock screen or a skip from headphones then shows up as it happens.\n\n```tsx\nconst { playing, position, trackId } = usePlayerState(); // from your audio library\n\n<VinylPlayer\n  tracks={tracks}\n  playing={playing}\n  position={position}\n  trackId={trackId}\n  onPlayingChange={(on) => (on ? player.play() : player.pause())}\n  onTrackChange={(t) => player.skipTo(t.id)}\n  onSeek={(seconds) => player.seekTo(seconds)}\n/>;\n```\n\n## When to use\n\n- A mini player with some character: a music app's home, a playlist header, a widget.\n\n## When not to use\n\n- When people need to scrub precisely, say through podcasts or audiobooks: the bar seeks on a tap, not a drag.\n\n## Notes\n\n- Without `position` it keeps its own clock, which is fine for a preview or a demo. With real audio, pass `position` so the audio engine stays the source of truth. Updates a few times a second are enough: the bar glides between them.\n- Each of `playing`, `position` and `trackId` is optional and independent. Whatever you leave unset, the card keeps on its own.\n- `onSeek` fires for a tap on the bar, a screen-reader step and Previous restarting the track.\n\n- The record half sits outside the card, so leave room on the left (about 66 pt).\n- It spins while playing (one turn every six seconds) and coasts a little when paused, keeping its angle.\n- Previous restarts the track after three seconds; otherwise it goes back a track. The queue wraps around.\n- The mute button only shows when you pass `onMutedChange`.\n"
  },
  "docs": "Prefer `npx kinetik-ui add vinyl-player`: it installs dependencies with expo install, so versions match your Expo SDK."
}
