import type { Item } from '@/core-bridge/types'; import type { IconName } from '@/ui/Icon'; const FILE_ICON = { image: 'image', video: 'video', audio: 'file', text: 'text', archive: 'archive', none: 'file', } as const satisfies Record; export function iconOf(item: Item): IconName { return item.kind === 'text' ? 'text' : FILE_ICON[item.preview]; } /** 列表里的一行标题:文件名,或文本的第一行 */ export function titleOf(item: Item): string { if (item.kind === 'file') return item.name; return item.text.split('\n').find((l) => l.trim() !== '')?.trim() ?? '(空)'; } export function shortDevice(name: string | undefined): string { return (name ?? '未知设备').split(' · ')[0] ?? '未知设备'; } /** 当前版本号:旧版本数 + 1 */ export function versionOf(item: Item): number { return item.kind === 'file' ? (item.versions?.length ?? 0) + 1 : 1; }