{"$schema":"https:\/\/ui.particle.academy\/schema\/registry-item.json","name":"live-badge","type":"registry:ui","title":"LiveBadge","description":"Live, starting, offline or ended as a Badge, from a status the host supplies.","package":"react-fancy","dependencies":["tailwind-merge"],"registryDependencies":["badge"],"files":[{"path":"components\/fancy\/live-badge\/LiveBadge.tsx","content":"import { forwardRef } from \"react\";\nimport { Badge } from \"..\/badge\/Badge\";\nimport type { Color } from \"..\/lib\/utils\/types\";\nimport type { LiveStatus } from \"..\/lib\/utils\/media-channel\";\nimport type { LiveBadgeLabels, LiveBadgeProps } from \".\/LiveBadge.types\";\n\nconst DEFAULT_LABELS: LiveBadgeLabels = {\n  live: \"LIVE\",\n  starting: \"Starting\",\n  offline: \"Offline\",\n  ended: \"Ended\",\n};\n\nconst COLORS: Record<LiveStatus, Color> = {\n  live: \"red\",\n  starting: \"amber\",\n  offline: \"zinc\",\n  ended: \"zinc\",\n};\n\n\/** A live channel's status: LIVE, Starting, Offline or Ended. The status itself is the host's to supply. *\/\nexport const LiveBadge = forwardRef<HTMLSpanElement, LiveBadgeProps>(function LiveBadge(\n  { status = \"live\", dot, size = \"sm\", labels: labelsProp, ...rest },\n  ref,\n) {\n  const labels = { ...DEFAULT_LABELS, ...labelsProp };\n  return (\n    <Badge\n      ref={ref}\n      data-react-fancy-live-badge=\"\"\n      data-live-status={status}\n      color={COLORS[status]}\n      size={size}\n      dot={dot ?? status === \"live\"}\n      {...rest}\n    >\n      {labels[status]}\n    <\/Badge>\n  );\n});\n\nLiveBadge.displayName = \"LiveBadge\";\n","type":"registry:ui","target":"components\/fancy\/live-badge\/LiveBadge.tsx"},{"path":"components\/fancy\/live-badge\/LiveBadge.types.ts","content":"import type { HTMLAttributes } from \"react\";\nimport type { LiveStatus } from \"..\/lib\/utils\/media-channel\";\n\nexport interface LiveBadgeLabels {\n  live: string;\n  starting: string;\n  offline: string;\n  ended: string;\n}\n\nexport interface LiveBadgeProps extends Omit<HTMLAttributes<HTMLSpanElement>, \"color\"> {\n  \/** Default `\"live\"`. *\/\n  status?: LiveStatus;\n  \/** Show the dot (on air). Default: on while `status` is `\"live\"`. *\/\n  dot?: boolean;\n  size?: \"sm\" | \"md\" | \"lg\";\n  \/** Every visible string. English defaults. *\/\n  labels?: Partial<LiveBadgeLabels>;\n}\n","type":"registry:ui","target":"components\/fancy\/live-badge\/LiveBadge.types.ts"},{"path":"components\/fancy\/live-badge\/index.ts","content":"export { LiveBadge } from \".\/LiveBadge\";\nexport type { LiveBadgeProps, LiveBadgeLabels } from \".\/LiveBadge.types\";\n","type":"registry:ui","target":"components\/fancy\/live-badge\/index.ts"},{"path":"components\/fancy\/lib\/utils\/types.ts","content":"import type { ElementType } from \"react\";\n\nexport type Size = \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\";\n\n\/**\n * What a navigation primitive owes a router.\n *\n * Every nav surface here \u2014 `Navbar.Item`, `Sidebar.Item`, `Menu.Item`,\n * `MobileMenu.Item`, `Breadcrumbs.Item` \u2014 used to hardcode a plain `<a href>`.\n * That is a FULL PAGE LOAD in every client-routed app, and the only way around\n * it was to nest a router `<Link>` inside the item: an anchor inside an anchor,\n * which is invalid HTML and the same nested-anchor shape that already cost this\n * suite an SSR hydration bug.\n *\n * `as` is the seam {@link ButtonProps.as} already had. It is router-agnostic on\n * purpose \u2014 one prop serves Inertia, TanStack Router, React Router and Next\n * rather than a package per router:\n *\n * ```tsx\n * \/\/ href-based routers (Inertia, Next)\n * <Navbar.Item as={Link} href=\"\/dashboard\">Dashboard<\/Navbar.Item>\n *\n * \/\/ to-based routers (TanStack Router, React Router) \u2014 `to` reaches the Link\n * \/\/ through the forwarded rest props\n * <Navbar.Item as={Link} to=\"\/dashboard\">Dashboard<\/Navbar.Item>\n * ```\n *\n * Link mode engages on `href` OR `as`, because a `to`-based router never passes\n * an `href` and would otherwise silently render the non-interactive fallback.\n *\/\nexport interface NavigableProps {\n  \/** Target URL. Renders link mode with a plain `<a>` unless `as` is given. *\/\n  href?: string;\n  \/**\n   * Link-mode element override \u2014 the component to render INSTEAD of the plain\n   * `<a>`, e.g. a router's `<Link>` so navigation happens client-side. Receives\n   * `className`, the item's `data-*` handles, and every unrecognized prop, so\n   * router-specific props (`to`, `params`, `preload`, `search`) pass straight\n   * through. Ignored in button mode.\n   *\/\n  as?: ElementType;\n}\n\n\/**\n * The full Tailwind v4 named color palette \u2014 every default hue, including all\n * five gray families \u2014 plus `brand`, the host's own colour. Components that\n * accept a `color` should type it as this so the whole palette is available.\n *\n * `brand` is not a hue. It resolves through three CSS variables the host sets\n * once, rather than through a Tailwind scale:\n *\n *   `--color-brand`, `--color-brand-contrast`, `--color-brand-hover`\n *\n * Three rather than one because a generated hover assumes \"same hue, darker\",\n * and a brand palette need not work that way \u2014 navy whose hover is gold cannot\n * be derived from navy by any amount of arithmetic. The host states it.\n *\/\nexport type Color =\n  \/\/ the host's own colour, resolved from CSS variables (see styles.css)\n  | \"brand\"\n  \/\/ grays\n  | \"slate\"\n  | \"gray\"\n  | \"zinc\"\n  | \"neutral\"\n  | \"stone\"\n  \/\/ hues\n  | \"red\"\n  | \"orange\"\n  | \"amber\"\n  | \"yellow\"\n  | \"lime\"\n  | \"green\"\n  | \"emerald\"\n  | \"teal\"\n  | \"cyan\"\n  | \"sky\"\n  | \"blue\"\n  | \"indigo\"\n  | \"violet\"\n  | \"purple\"\n  | \"fuchsia\"\n  | \"pink\"\n  | \"rose\";\n\n\/** Every value of {@link Color}, for building exhaustive class maps. *\/\nexport const COLORS = [\n  \"brand\",\n  \"slate\", \"gray\", \"zinc\", \"neutral\", \"stone\",\n  \"red\", \"orange\", \"amber\", \"yellow\", \"lime\", \"green\", \"emerald\", \"teal\",\n  \"cyan\", \"sky\", \"blue\", \"indigo\", \"violet\", \"purple\", \"fuchsia\", \"pink\", \"rose\",\n] as const satisfies readonly Color[];\n\nexport type Variant = \"solid\" | \"outline\" | \"ghost\" | \"soft\";\n\n\/** Button accepts the full Tailwind v4 palette (alias of {@link Color}). *\/\nexport type ButtonColor = Color;\n\n\/**\n * @deprecated Renamed to {@link ButtonColor}. `ActionColor` remains as an alias\n * for backward compatibility and will be removed in a future major version.\n *\/\nexport type ActionColor = ButtonColor;\n\nexport type Placement =\n  | \"top\"\n  | \"bottom\"\n  | \"left\"\n  | \"right\"\n  | \"top-start\"\n  | \"top-end\"\n  | \"bottom-start\"\n  | \"bottom-end\";\n","type":"registry:lib","target":"components\/fancy\/lib\/utils\/types.ts"},{"path":"components\/fancy\/lib\/utils\/media-channel.ts","content":"\/**\n * The channel model: a channel is a single track, a playlist of tracks, or a\n * live stream from any service. Every shape is plain JSON, so a host, a server\n * or an agent can emit it.\n *\n * Every channel component (ChannelPlayer, ChannelGuide, Playlist, MediaQueue)\n * is controlled through ONE {@link ChannelPlayerValue}, and every move they\n * make goes through the pure functions below. An agent bridge calls the same\n * functions, so \"next\", \"shuffle\" or \"remove\" cannot mean one thing in the UI\n * and another to an agent.\n *\/\n\n\/** Where a track or a live channel plays from. *\/\nexport type ChannelSource =\n  \/** A finite file: MP3, M4A, MP4, WebM... Seekable. *\/\n  | { type: \"file\"; url: string; mime?: string; media?: \"audio\" | \"video\" }\n  \/**\n   * An endless stream. `protocol` defaults by guess: `.m3u8` is HLS, `.mpd` is\n   * DASH, anything else is an Icecast \/ Shoutcast mount.\n   *\/\n  | { type: \"stream\"; url: string; protocol?: \"icecast\" | \"hls\" | \"dash\"; media?: \"audio\" | \"video\" }\n  \/** A provider's own player in an iframe: `youtube`, `vimeo`, `twitch`, or one a host registers. *\/\n  | { type: \"embed\"; provider: string; id: string; params?: Record<string, string> };\n\nexport type EmbedSource = Extract<ChannelSource, { type: \"embed\" }>;\n\nexport interface MediaTrack {\n  \/** Stable identity: `value.trackId`, `data-track-id`. Unique within a channel. *\/\n  id: string;\n  title: string;\n  artist?: string;\n  album?: string;\n  \/** Seconds, when known up front (shown before the file loads). *\/\n  duration?: number;\n  \/** Image URL. *\/\n  artwork?: string;\n  source: ChannelSource;\n}\n\nexport type LiveStatus = \"live\" | \"offline\" | \"starting\" | \"ended\";\n\nexport interface ChannelBase {\n  \/** Stable identity: `value.channelId`, `data-channel-id`. *\/\n  id: string;\n  name: string;\n  description?: string;\n  artwork?: string;\n  tags?: string[];\n}\n\nexport type TrackChannel = ChannelBase & { kind: \"track\"; track: MediaTrack };\nexport type PlaylistChannel = ChannelBase & { kind: \"playlist\"; tracks: MediaTrack[] };\nexport type LiveChannel = ChannelBase & {\n  kind: \"live\";\n  source: ChannelSource;\n  \/** Supplied by the host (a provider API, an Icecast status poll). Default `\"live\"`. *\/\n  status?: LiveStatus;\n  \/** What is on air, supplied by the host. *\/\n  nowPlaying?: string;\n};\n\nexport type Channel = TrackChannel | PlaylistChannel | LiveChannel;\nexport type ChannelKind = Channel[\"kind\"];\n\nexport type RepeatMode = \"off\" | \"all\" | \"one\";\n\n\/** The whole state of a channel UI, in one JSON object. *\/\nexport interface ChannelPlayerValue {\n  channelId: string | null;\n  \/** The current track: within a playlist, the track channel's own track, or `null` on live. *\/\n  trackId: string | null;\n  \/** Whether the host wants media playing. Components set it back to `false` when the browser refuses. *\/\n  playing: boolean;\n  \/** Seconds into the current track. Ignored on live. Moving it seeks. *\/\n  position: number;\n  \/** 0..1 *\/\n  volume: number;\n  muted: boolean;\n  shuffle: boolean;\n  repeat: RepeatMode;\n  \/** The shuffled play order (track ids), or `null` for playlist order. *\/\n  order: string[] | null;\n}\n\n\/** A playlist edit held for a person to confirm (an agent proposes, a human accepts). *\/\nexport type PendingQueueEdit =\n  | { id: string; op: \"remove\"; trackId: string }\n  | { id: string; op: \"clear\" }\n  | { id: string; op: \"replace\"; tracks: MediaTrack[] };\n\ntype Random = () => number;\n\n\/** Seconds into a track before \"previous\" restarts it instead of going back. *\/\nconst RESTART_THRESHOLD = 3;\n\nexport function createChannelValue(patch: Partial<ChannelPlayerValue> = {}): ChannelPlayerValue {\n  return {\n    channelId: null,\n    trackId: null,\n    playing: false,\n    position: 0,\n    volume: 1,\n    muted: false,\n    shuffle: false,\n    repeat: \"off\",\n    order: null,\n    ...patch,\n  };\n}\n\nexport function findChannel(channels: readonly Channel[], id: string | null | undefined): Channel | undefined {\n  return id == null ? undefined : channels.find((c) => c.id === id);\n}\n\n\/** The tracks a channel plays: one, the list, or none for live. *\/\nexport function channelTracks(channel: Channel | undefined): MediaTrack[] {\n  if (!channel) return [];\n  if (channel.kind === \"track\") return [channel.track];\n  if (channel.kind === \"playlist\") return channel.tracks;\n  return [];\n}\n\n\/** Fisher-Yates over a copy; `first`, when given and present, leads. *\/\nexport function shuffleIds(ids: readonly string[], random: Random = Math.random, first?: string | null): string[] {\n  const out = ids.filter((id) => id !== first);\n  for (let i = out.length - 1; i > 0; i--) {\n    const j = Math.min(i, Math.floor(random() * (i + 1)));\n    [out[i], out[j]] = [out[j]!, out[i]!];\n  }\n  return first != null && ids.includes(first) ? [first, ...out] : out;\n}\n\n\/**\n * The order tracks play in. A held shuffle order is used only while it names\n * exactly the channel's tracks; a stale one (tracks added or removed since)\n * is repaired: unknown ids dropped, missing ones appended.\n *\/\nexport function playOrder(channel: Channel | undefined, value: ChannelPlayerValue): string[] {\n  const ids = channelTracks(channel).map((t) => t.id);\n  if (!value.shuffle || !value.order) return ids;\n  const kept = value.order.filter((id) => ids.includes(id));\n  return [...kept, ...ids.filter((id) => !kept.includes(id))];\n}\n\nexport function currentTrack(channel: Channel | undefined, value: ChannelPlayerValue): MediaTrack | undefined {\n  if (value.trackId == null) return undefined;\n  return channelTracks(channel).find((t) => t.id === value.trackId);\n}\n\n\/** Tune to a channel: its first track (in shuffle order when shuffling), from the start. *\/\nexport function selectChannel(\n  value: ChannelPlayerValue,\n  channel: Channel | undefined,\n  random: Random = Math.random,\n): ChannelPlayerValue {\n  if (!channel) return { ...value, channelId: null, trackId: null, position: 0, order: null };\n  const ids = channelTracks(channel).map((t) => t.id);\n  const order = value.shuffle && channel.kind === \"playlist\" ? shuffleIds(ids, random) : null;\n  return {\n    ...value,\n    channelId: channel.id,\n    trackId: (order ?? ids)[0] ?? null,\n    position: 0,\n    order,\n  };\n}\n\nexport function selectTrack(value: ChannelPlayerValue, trackId: string): ChannelPlayerValue {\n  return { ...value, trackId, position: 0 };\n}\n\nexport function toggleShuffle(\n  value: ChannelPlayerValue,\n  channel: Channel | undefined,\n  random: Random = Math.random,\n): ChannelPlayerValue {\n  if (value.shuffle) return { ...value, shuffle: false, order: null };\n  const ids = channelTracks(channel).map((t) => t.id);\n  return { ...value, shuffle: true, order: shuffleIds(ids, random, value.trackId) };\n}\n\nexport function cycleRepeat(value: ChannelPlayerValue): ChannelPlayerValue {\n  const next: Record<RepeatMode, RepeatMode> = { off: \"all\", all: \"one\", one: \"off\" };\n  return { ...value, repeat: next[value.repeat] };\n}\n\n\/** The next track by hand. At the end: wraps with repeat all, otherwise nothing changes. *\/\nexport function nextTrack(value: ChannelPlayerValue, channel: Channel | undefined): ChannelPlayerValue {\n  const order = playOrder(channel, value);\n  if (order.length === 0) return value;\n  const at = value.trackId == null ? -1 : order.indexOf(value.trackId);\n  if (at < order.length - 1) return selectTrack(value, order[at + 1]!);\n  return value.repeat === \"all\" ? selectTrack(value, order[0]!) : value;\n}\n\n\/** Restart a track more than 3s in; otherwise the one before (wrapping with repeat all). *\/\nexport function previousTrack(value: ChannelPlayerValue, channel: Channel | undefined): ChannelPlayerValue {\n  const order = playOrder(channel, value);\n  if (order.length === 0) return value;\n  if (value.position > RESTART_THRESHOLD) return { ...value, position: 0 };\n  const at = value.trackId == null ? 0 : order.indexOf(value.trackId);\n  if (at > 0) return selectTrack(value, order[at - 1]!);\n  if (value.repeat === \"all\") return selectTrack(value, order[order.length - 1]!);\n  return { ...value, position: 0 };\n}\n\n\/** What a track finishing does: replay, advance, wrap, or stop. *\/\nexport function trackEnded(value: ChannelPlayerValue, channel: Channel | undefined): ChannelPlayerValue {\n  const order = playOrder(channel, value);\n  if (order.length === 0) return { ...value, playing: false, position: 0 };\n  if (value.repeat === \"one\" || (order.length === 1 && value.repeat === \"all\")) return { ...value, position: 0 };\n  const at = value.trackId == null ? -1 : order.indexOf(value.trackId);\n  if (at < order.length - 1) return selectTrack(value, order[at + 1]!);\n  if (value.repeat === \"all\") return selectTrack(value, order[0]!);\n  return { ...value, playing: false, position: 0 };\n}\n\n\/** What plays after the current track, in play order (wrapping with repeat all). *\/\nexport function upNext(channel: Channel | undefined, value: ChannelPlayerValue): MediaTrack[] {\n  const tracks = channelTracks(channel);\n  const order = playOrder(channel, value);\n  const at = value.trackId == null ? -1 : order.indexOf(value.trackId);\n  const after = order.slice(at + 1);\n  const ids = value.repeat === \"all\" && at >= 0 ? [...after, ...order.slice(0, at)] : after;\n  return ids.map((id) => tracks.find((t) => t.id === id)!).filter(Boolean);\n}\n\nexport function moveTrack(tracks: readonly MediaTrack[], trackId: string, toIndex: number): MediaTrack[] {\n  const from = tracks.findIndex((t) => t.id === trackId);\n  if (from < 0) return [...tracks];\n  const out = tracks.filter((t) => t.id !== trackId);\n  const to = Math.max(0, Math.min(out.length, Math.floor(toIndex)));\n  out.splice(to, 0, tracks[from]!);\n  return out;\n}\n\n\/** Add a track (at the end, or at `index`). A duplicate id is refused: the same array comes back. *\/\nexport function addTrack<T extends readonly MediaTrack[]>(tracks: T, track: MediaTrack, index?: number): T | MediaTrack[] {\n  if (tracks.some((t) => t.id === track.id)) return tracks;\n  const out = [...tracks];\n  out.splice(index == null ? out.length : Math.max(0, Math.min(out.length, index)), 0, track);\n  return out;\n}\n\nexport function removeTrack(tracks: readonly MediaTrack[], trackId: string): MediaTrack[] {\n  return tracks.filter((t) => t.id !== trackId);\n}\n\nexport function applyQueueEdit(tracks: readonly MediaTrack[], edit: PendingQueueEdit): MediaTrack[] {\n  if (edit.op === \"remove\") return removeTrack(tracks, edit.trackId);\n  if (edit.op === \"clear\") return [];\n  return [...edit.tracks];\n}\n\n\/**\n * Bring a value back in step after a channel's tracks changed. A current track\n * that was removed gives way to the one that took its place (or the first);\n * an emptied channel stops. A shuffle order keeps its sequence, drops removed\n * ids and appends added ones. Another channel's value comes back untouched.\n *\/\nexport function reconcileValue(\n  value: ChannelPlayerValue,\n  channel: Channel,\n  previous?: Channel,\n): ChannelPlayerValue {\n  if (value.channelId !== channel.id) return value;\n  const ids = channelTracks(channel).map((t) => t.id);\n  const order = value.shuffle && value.order ? playOrder(channel, value) : null;\n  const sameOrder =\n    order === value.order ||\n    (order !== null && value.order !== null && order.length === value.order.length && order.every((id, i) => id === value.order![i]));\n  if (value.trackId != null && ids.includes(value.trackId)) {\n    return sameOrder ? value : { ...value, order };\n  }\n  if (ids.length === 0) return { ...value, trackId: null, playing: false, position: 0, order: value.shuffle ? [] : null };\n  \/\/ The first survivor after the removed track, in the order that was playing\n  \/\/ (known from `previous`, or from a held shuffle order); else the first.\n  const before = previous ? playOrder(previous, value) : (value.order ?? []);\n  const oldIndex = value.trackId == null ? -1 : before.indexOf(value.trackId);\n  const survivor = oldIndex >= 0 ? before.slice(oldIndex + 1).find((id) => ids.includes(id)) : undefined;\n  return { ...value, trackId: survivor ?? (order ?? ids)[0]!, position: 0, order };\n}\n","type":"registry:lib","target":"components\/fancy\/lib\/utils\/media-channel.ts"},{"path":"components\/fancy\/lib\/utils\/cn.ts","content":"import { twMerge } from \"tailwind-merge\";\n\n\/**\n * A class value: a string, a number, a conditional map, an array of any of\n * those, or nothing. Mirrors what `clsx` accepted, because every component in\n * this package already passes these shapes.\n *\/\nexport type ClassValue =\n  | string\n  | number\n  | bigint\n  | null\n  | undefined\n  | false\n  | ClassDictionary\n  | ClassValue[];\n\ntype ClassDictionary = Record<string, unknown>;\n\n\/**\n * Flatten class values into a space-separated string.\n *\n * This was `clsx` until 2026-08-19. It is roughly twenty lines of logic, it\n * shipped as a RUNTIME dependency to every consumer of this package, and its\n * last commit was 801 days old \u2014 so it fell to the rule that third-party code\n * must be both approved and actively maintained. Owning it costs less than\n * carrying it.\n *\n * `tailwind-merge` deliberately stays: deciding which of two conflicting\n * Tailwind utilities wins requires modelling the entire utility space, which is\n * emphatically not twenty lines, and it is actively maintained.\n *\n * Falsy values are dropped \u2014 including `0` and `\"\"`, which is what `clsx` did\n * and what `tests\/cn.test.ts` pins. A truthy number is kept, because digits are\n * legal class names. `bigint` is admitted because clsx's signature did and\n * the compiler proved it reachable from two call sites here.\n *\/\nfunction flatten(value: ClassValue): string {\n  if (!value) return \"\";\n\n  if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"bigint\") {\n    return String(value);\n  }\n\n  if (Array.isArray(value)) {\n    let out = \"\";\n    for (const item of value) {\n      const part = flatten(item);\n      if (part) out = out ? `${out} ${part}` : part;\n    }\n    return out;\n  }\n\n  let out = \"\";\n  for (const key in value) {\n    if (value[key]) out = out ? `${out} ${key}` : key;\n  }\n  return out;\n}\n\nexport function cn(...inputs: ClassValue[]): string {\n  return twMerge(flatten(inputs));\n}\n","type":"registry:lib","target":"components\/fancy\/lib\/utils\/cn.ts"}]}