/** * The transcript as a person reads it: turns of one speaker, each a soft * bubble under the speaker's name in their colour, with its time and the line * playing now highlighted. A speaker's name opens "Who is this?" (someone from * the people directory, or a new name); a turn's pencil corrects its words and * its ⋯ menu moves it to another speaker. A name recognized by voice is marked * suggested until someone confirms or turns it down. */ import { useOpenGeniText, createOpenGeniText, type OpenGeniText } from "../messages/runtime"; import { useEffect, useId, useMemo, useRef, useState, type ComponentProps, type CSSProperties, } from "react"; import { AudioLinesIcon, CheckIcon, ChevronDownIcon, MoreHorizontalIcon, PencilIcon, UserIcon, UserPlusIcon, UsersIcon, XIcon, } from "lucide-react"; import { toast } from "sonner"; import { userErrorText } from "../ui/api-error"; import type { RecordingPerson, RecordingSpeaker, RecordingTrack, RecordingTranscriptSegment, } from "@opengeni/contracts"; import { Button } from "../ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from "../ui/dropdown-menu"; import { Field, FieldStack, TextArea, TextInput } from "../ui/field"; import { FormDialog } from "../ui/form-dialog"; import { cn } from "../app/lib/utils"; import { formatClock, groupTranscriptTurns, speakerColorSlots, speakerDisplayName, speakerIsNamed, type TranscriptTurn, } from "../recordings"; import { MeetingsOverlayScope } from "./overlay-scope"; const defaultText = createOpenGeniText(); /** The chart palette, one hue per voice. */ const SPEAKER_DOT: Record = { 1: "bg-chart-1", 2: "bg-chart-2", 3: "bg-chart-3", 4: "bg-chart-4", 5: "bg-chart-5", 6: "bg-chart-6", }; /** * A voice's hue, for its name and mentions; the shared rules below mix it. * Set inline, so the six slots cost no stylesheet rules. */ export function speakerHueStyle(slot: number | undefined): CSSProperties | undefined { return slot !== undefined && SPEAKER_DOT[slot] ? ({ "--speaker-hue": `var(--color-chart-${slot})` } as CSSProperties) : undefined; } /** * The hue mixed toward the text colour, so it reads on both themes: darker on * light, lighter on dark. Light takes more of the text colour (about 5:1 or * better on the page and on a mention's tint); dark keeps more hue at the * same contrast. */ const SPEAKER_TEXT = "text-[color-mix(in_oklab,var(--speaker-hue)_50%,var(--color-fg))] dark:text-[color-mix(in_oklab,var(--speaker-hue)_62%,var(--color-fg))]"; /** A faint fill in the voice's hue, for a mention of that speaker. */ const SPEAKER_TINT = "bg-[color-mix(in_oklab,var(--speaker-hue)_14%,transparent)]"; /** The text colour of a speaker's colour slot, with {@link speakerHueStyle}; muted when there is none. */ export function speakerTextClass(slot: number | undefined): string { return speakerHueStyle(slot) ? SPEAKER_TEXT : "text-fg-muted"; } /** The faint fill of a speaker's colour slot, with {@link speakerHueStyle}; the chip surface when there is none. */ export function speakerTintClass(slot: number | undefined): string { return speakerHueStyle(slot) ? SPEAKER_TINT : "bg-surface-2"; } /** A turn's pencil and ⋯: shown on hover or focus of the turn, always on touch. */ const TURN_ACTION = "size-7 rounded-[8px] text-fg-subtle opacity-0 transition-opacity duration-[120ms] group-hover/turn:opacity-100 group-focus-within/turn:opacity-100 focus-visible:opacity-100 data-[state=open]:opacity-100 motion-reduce:transition-none pointer-coarse:size-11 pointer-coarse:opacity-100"; export function SpeakerDot({ slot, className }: { slot: number | undefined; className?: string }) { return (