🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style(agents): taller badge cover tinted from the avatar, owner in the corner, hide the core chip (#21845)
Arvin Xub3b5bdec1ff5
diff --git a/locales/en-US/common.json b/locales/en-US/common.jsonindex 6c81fd9c6ee..21ccceb82fa 100644--- a/locales/en-US/common.json+++ b/locales/en-US/common.json@@ -20,7 +20,6 @@"agentViewAll.orderBy.author": "Author","agentViewAll.orderBy.title": "Title","agentViewAll.orderBy.updatedAt": "Updated at",- "agentViewAll.pendant.core": "Core","agentViewAll.pendant.official": "Official","agentViewAll.removeFromSidebar": "Hide from my sidebar","agentViewAll.sidebarSection.collapse": "Fold",diff --git a/locales/zh-CN/common.json b/locales/zh-CN/common.jsonindex fca5b81ae47..294e6b7ed36 100644--- a/locales/zh-CN/common.json+++ b/locales/zh-CN/common.json@@ -20,7 +20,6 @@"agentViewAll.orderBy.author": "作者","agentViewAll.orderBy.title": "标题","agentViewAll.orderBy.updatedAt": "更新时间",- "agentViewAll.pendant.core": "核心","agentViewAll.pendant.official": "官方","agentViewAll.removeFromSidebar": "在我的侧边栏隐藏","agentViewAll.sidebarSection.collapse": "收起",diff --git a/packages/locales/src/default/common.ts b/packages/locales/src/default/common.tsindex 7c57badd64b..656c64bc6e3 100644--- a/packages/locales/src/default/common.ts+++ b/packages/locales/src/default/common.ts@@ -26,7 +26,6 @@ export default {'agentViewAll.orderBy.author': 'Author','agentViewAll.orderBy.title': 'Title','agentViewAll.orderBy.updatedAt': 'Updated at',- 'agentViewAll.pendant.core': 'Core','agentViewAll.pendant.official': 'Official','agentViewAll.removeFromSidebar': 'Hide from my sidebar','agentViewAll.sidebarSection.collapse': 'Fold',diff --git a/src/features/AgentViewAll/AgentCard.tsx b/src/features/AgentViewAll/AgentCard.tsxindex adc28783c8a..53c2af97c47 100644--- a/src/features/AgentViewAll/AgentCard.tsx+++ b/src/features/AgentViewAll/AgentCard.tsx@@ -1,9 +1,10 @@'use client';-import { AGENT_CHAT_URL, GROUP_CHAT_URL } from '@lobechat/const';+import { AGENT_CHAT_URL, DEFAULT_USER_AVATAR_URL, GROUP_CHAT_URL } from '@lobechat/const';import type { SidebarAgentItem } from '@lobechat/types';import { agentDisplayName, agentSecondaryDisplayName } from '@lobechat/types';import {+ Avatar,Block,ContextMenuTrigger,createStaticStyles,@@ -17,16 +18,17 @@ import { useTranslation } from 'react-i18next';import WorkspaceLink from '@/features/Workspace/WorkspaceLink';import AgentPendant from './AgentPendant';+import type { AgentRowAuthor } from './AgentRow';import ItemActions from './ItemActions';import { resolveAgentBadge } from './resolveAgentBadge';import SidebarItemAvatar from './SidebarItemAvatar';+import { useAgentCoverColor } from './useAgentCoverColor';-// Badge-wall layout: avatar → name → role chip → two-line description,-// centered. Every row has a fixed height, so plain and cover badges mixed in-// one row keep the avatar, the name baseline and the description's first line-// aligned. The avatar sits at the same y either way: with a cover it straddles-// the cover's bottom edge, without one the band is just top padding.-const COVER_HEIGHT = 48;+// Badge-wall layout: cover → avatar → name → role chip → two-line description,+// centered, with the owner in the bottom-left corner. Every row has a fixed+// height, so the avatar, the name baseline and the description's first line+// line up across a row. The avatar straddles the cover's bottom edge.+const COVER_HEIGHT = 80;const AVATAR_SIZE = 56;export const AGENT_GRID_MIN_COLUMN = 260;@@ -54,9 +56,9 @@ export const cardStyles = createStaticStyles(({ css, cssVar }) => ({box-shadow: ${cssVar.boxShadowTertiary};}`,- // Identity texture, not artwork: a short straight-edged band tinted from the- // agent's avatar background, mixed toward the container color so it stays- // calm in both themes, with a faint dot grid on top.+ // Identity texture, not artwork: a straight-edged band tinted from the+ // agent's avatar (see useAgentCoverColor), mixed toward the container color+ // so it stays calm in both themes, with a faint dot grid on top.cover: css`position: absolute;inset-block-start: 0;@@ -64,12 +66,20 @@ export const cardStyles = createStaticStyles(({ css, cssVar }) => ({height: ${COVER_HEIGHT}px;- background-color: color-mix(in srgb, var(--agent-cover) 72%, ${cssVar.colorBgContainer});+ /* Neutral until an avatar image has been sampled. */+ background-color: color-mix(+ in srgb,+ var(--agent-cover, ${cssVar.colorFill}) 72%,+ ${cssVar.colorBgContainer}+ );background-image: radial-gradient(color-mix(in srgb, ${cssVar.colorBgContainer} 30%, transparent) 1px,transparent 1.5px);background-size: 10px 10px;++ /* The sampled color fades in over the neutral band. */+ transition: background-color 0.3s;`,avatarRing: css`position: relative;@@ -142,6 +152,28 @@ export const cardStyles = createStaticStyles(({ css, cssVar }) => ({color: ${cssVar.colorTextSecondary};overflow-wrap: anywhere;`,+ // Pinned to the bottom-left corner: auto top margin takes up whatever height+ // the grid row adds, so the owner sits on the same line across a row.+ owner: css`+ display: flex;+ gap: 6px;+ align-items: center;+ align-self: stretch;++ min-width: 0;+ margin-block-start: auto;+ padding-block-start: 12px;++ font-size: 12px;+ line-height: 16px;+ color: ${cssVar.colorTextTertiary};+ `,+ ownerName: css`+ overflow: hidden;+ min-width: 0;+ text-overflow: ellipsis;+ white-space: nowrap;+ `,// Columns come from the content width: as many 260px+ badges as fit, so a// ~1300px page shows four and an ultra-wide one six, instead of a fixed four// stretching each badge. Shares the min width with SidebarAgentsSection so@@ -203,17 +235,20 @@ interface AgentCardProps {item: SidebarAgentItem;/** Toggle whether this item appears in the caller's sidebar. */onToggleSidebar?: (item: SidebarAgentItem) => void;+ /** Who owns the agent; shown in the bottom-left corner when given. */+ owner?: AgentRowAuthor | null;/** Whether the caller removed this item from their sidebar (default listed). */sidebarHidden?: boolean;}-const AgentCard = memo<AgentCardProps>(({ item, onToggleSidebar, sidebarHidden }) => {+const AgentCard = memo<AgentCardProps>(({ item, onToggleSidebar, owner, sidebarHidden }) => {const { t } = useTranslation('common');const { description, id, type } = item;// Groups have no personal name, so this resolves to their title.const displayTitle = agentDisplayName(item, t('agentViewAll.untitled'));const roleTag = agentSecondaryDisplayName(item);const badge = resolveAgentBadge(item);+ const coverColor = useAgentCoverColor(item, badge.cover);const [anchor, setAnchor] = useState<HTMLElement | null>(null);// Right-click support — same bridge as AgentRow: the hook-bearing menu@@ -237,12 +272,10 @@ const AgentCard = memo<AgentCardProps>(({ item, onToggleSidebar, sidebarHidden }onPointerEnter={activateMenu}><Block clickable className={cardStyles.card} height={'100%'} variant={'outlined'}>- {badge.cover ? (- <div- className={cardStyles.cover}- style={{ '--agent-cover': badge.cover } as CSSProperties}- />- ) : null}+ <div+ className={cardStyles.cover}+ style={{ '--agent-cover': coverColor } as CSSProperties}+ /><AgentPendant bottom={badge.bottom} top={badge.top}><spanclassName={cx(@@ -265,6 +298,18 @@ const AgentCard = memo<AgentCardProps>(({ item, onToggleSidebar, sidebarHidden }) : null}</div><div className={cardStyles.description}>{description}</div>+ {owner?.name ? (+ <div className={cardStyles.owner}>+ <Avatar+ avatar={owner.avatar || DEFAULT_USER_AVATAR_URL}+ shape={'circle'}+ size={16}+ />+ <span className={cardStyles.ownerName} title={owner.name}>+ {owner.name}+ </span>+ </div>+ ) : null}</Block></WorkspaceLink><span data-card-actions className={cardStyles.actions}>diff --git a/src/features/AgentViewAll/AgentPendant.tsx b/src/features/AgentViewAll/AgentPendant.tsxindex da92ad02d30..ed5726dc6c9 100644--- a/src/features/AgentViewAll/AgentPendant.tsx+++ b/src/features/AgentViewAll/AgentPendant.tsx@@ -47,11 +47,8 @@ const styles = stylex.create({borderStartStartRadius: 9,insetBlockStart: -10,},- // White 10px text needs a dark enough plate: use the deeper warning shade- // and darken free-form label colors (gray / yellow presets) before use.- core: {- backgroundColor: cssVar.colorWarningActive,- },+ // White 10px text needs a dark enough plate: darken free-form label colors+ // (gray / yellow presets) before use.official: {backgroundColor: cssVar.colorPrimary,},diff --git a/src/features/AgentViewAll/AgentViewAllPage.tsx b/src/features/AgentViewAll/AgentViewAllPage.tsxindex 5ed19efe467..1e2b6e7af79 100644--- a/src/features/AgentViewAll/AgentViewAllPage.tsx+++ b/src/features/AgentViewAll/AgentViewAllPage.tsx@@ -456,11 +456,12 @@ const AgentViewAllPage = memo(() => {<AgentCarditem={item}key={item.id}+ owner={showAuthor && item.userId ? authorByUserId.get(item.userId) : undefined}sidebarHidden={!isSidebarItemVisible(item)}onToggleSidebar={handleToggleSidebar}/>),- [handleToggleSidebar, isSidebarItemVisible],+ [showAuthor, authorByUserId, handleToggleSidebar, isSidebarItemVisible],);const renderRow = useCallback(diff --git a/src/features/AgentViewAll/coverColor.test.ts b/src/features/AgentViewAll/coverColor.test.tsnew file mode 100644index 00000000000..6f0fc1cf1a1--- /dev/null+++ b/src/features/AgentViewAll/coverColor.test.ts@@ -0,0 +1,71 @@+import { DEFAULT_AVATAR } from '@lobechat/const';+import type { SidebarAgentItem } from '@lobechat/types';+import { describe, expect, it } from 'vitest';++import { coverImageSrc, pickDominantColor, seedCoverColor } from './coverColor';++const agent = (overrides: Partial<SidebarAgentItem> = {}): SidebarAgentItem => ({+ id: 'agt_1',+ pinned: false,+ title: 'Agent',+ type: 'agent',+ updatedAt: new Date(0),+ ...overrides,+});++const pixels = (...colors: [number, number, number, number, number][]) =>+ colors.flatMap(([r, g, b, a, count]) => Array.from({ length: count }, () => [r, g, b, a]).flat());++describe('pickDominantColor', () => {+ it('returns nothing for a fully transparent image', () => {+ expect(pickDominantColor(pixels([255, 0, 0, 0, 10]))).toBeUndefined();+ });++ it('lets a colored logo win over a larger white background', () => {+ expect(pickDominantColor(pixels([255, 255, 255, 255, 30], [30, 90, 220, 255, 10]))).toBe(+ 'rgb(30, 90, 220)',+ );+ });++ it('lets a small anti-aliased logo win over a mostly white image', () => {+ // A blue mark split across two hue buckets, its edges blended toward white.+ const color = pickDominantColor(+ pixels(+ [255, 255, 255, 255, 400],+ [8, 102, 255, 255, 8],+ [40, 70, 230, 255, 6],+ [170, 200, 250, 255, 10],+ ),+ );+ expect(color).toBe('rgb(31, 101, 248)');+ });++ it('falls back to the neutral average for a grayscale image', () => {+ expect(pickDominantColor(pixels([200, 200, 200, 255, 4], [100, 100, 100, 255, 4]))).toBe(+ 'rgb(150, 150, 150)',+ );+ });++ it('picks the heaviest hue when several compete', () => {+ expect(pickDominantColor(pixels([230, 40, 40, 255, 3], [40, 200, 60, 255, 8]))).toBe(+ 'rgb(40, 200, 60)',+ );+ });+});++describe('coverImageSrc', () => {+ it('only samples uploaded images', () => {+ expect(coverImageSrc(agent({ avatar: 'https://cdn.example.com/a.png' }))).toBe(+ 'https://cdn.example.com/a.png',+ );+ expect(coverImageSrc(agent({ avatar: '🤖' }))).toBeUndefined();+ expect(coverImageSrc(agent({ avatar: DEFAULT_AVATAR }))).toBeUndefined();+ expect(coverImageSrc(agent({ avatar: null }))).toBeUndefined();+ });+});++describe('seedCoverColor', () => {+ it('is stable per agent id', () => {+ expect(seedCoverColor(agent())).toBe(seedCoverColor(agent({ title: 'Renamed' })));+ });+});diff --git a/src/features/AgentViewAll/coverColor.ts b/src/features/AgentViewAll/coverColor.tsnew file mode 100644index 00000000000..3793f575b1b--- /dev/null+++ b/src/features/AgentViewAll/coverColor.ts@@ -0,0 +1,174 @@+import type { SidebarAgentItem } from '@lobechat/types';+import { type AgentAvatarColor, cssVar, getAgentAvatarTraits } from '@lobehub/ui';++import { isDefaultAgentAvatar } from '@/components/AgentAvatar';+import { remoteAvatarSrc } from '@/components/Avatar/fallback';++/**+ * The generated character's palette as theme colors. `ink` / `gray` share the+ * gray scale: the cover is mixed toward the container color, which keeps both+ * readable in either theme.+ */+const SEED_COLORS: Record<AgentAvatarColor, string> = {+ geekblue: cssVar.geekblue,+ gray: cssVar.gray,+ ink: cssVar.gray,+ magenta: cssVar.magenta,+ orange: cssVar.orange,+ purple: cssVar.purple,+ volcano: cssVar.volcano,+};++/**+ * Cover color derived from the agent id: the same color its generated+ * character wears, so an agent without an avatar of its own gets a band that+ * matches its face, and any other agent still gets a stable one.+ */+export const seedCoverColor = (item: SidebarAgentItem): string =>+ SEED_COLORS[getAgentAvatarTraits(item.id).color];++/** The uploaded image worth sampling, if the avatar is one. */+export const coverImageSrc = (item: SidebarAgentItem): string | undefined => {+ const { avatar } = item;+ if (typeof avatar !== 'string' || isDefaultAgentAvatar(avatar)) return undefined;++ return remoteAvatarSrc(avatar);+};++const HUE_BINS = 12;+/**+ * Share of opaque pixels that must carry color before the color wins. A logo+ * on white is mostly white, and its edges are anti-aliased toward it, so color+ * has to win on presence, not on pixel count — only a (nearly) colorless image+ * falls back to its neutral average.+ */+const MIN_COLOR_SHARE = 0.03;++interface Bin {+ b: number;+ g: number;+ n: number;+ r: number;+ w: number;+}++const emptyBin = (): Bin => ({ b: 0, g: 0, n: 0, r: 0, w: 0 });++/** Weighted average color of the bins (channels are stored pre-multiplied by weight). */+const average = (bins: Bin[]): string => {+ const total = bins.reduce((sum, bin) => sum + bin.w, 0);+ const channel = (key: 'b' | 'g' | 'r') =>+ Math.round(bins.reduce((sum, bin) => sum + bin[key], 0) / total);++ return `rgb(${channel('r')}, ${channel('g')}, ${channel('b')})`;+};++/**+ * Dominant color of RGBA pixel data. Vivid pixels are bucketed by hue and+ * weighted by the square of how vivid they are, so a logo's pale anti-aliased+ * edges barely tint the result; the heaviest hue (together with its two+ * neighbors, so a gradient split across a bucket edge still counts as one+ * color) gives the average. Washed-out and near-black pixels are ignored+ * unless the image has (almost) no color at all.+ */+export const pickDominantColor = (data: ArrayLike<number>): string | undefined => {+ const hues = Array.from({ length: HUE_BINS }, emptyBin);+ const neutral = emptyBin();+ let colored = 0;++ for (let i = 0; i + 3 < data.length; i += 4) {+ if (data[i + 3] < 128) continue;++ const r = data[i];+ const g = data[i + 1];+ const b = data[i + 2];+ const max = Math.max(r, g, b);+ const min = Math.min(r, g, b);+ const value = max / 255;+ const saturation = max === 0 ? 0 : (max - min) / max;++ let bin = neutral;+ let weight = 1;+ if (saturation >= 0.25 && value >= 0.2) {+ const delta = max - min;+ let hue =+ max === r ? ((g - b) / delta) % 6 : max === g ? (b - r) / delta + 2 : (r - g) / delta + 4;+ hue = (hue * 60 + 360) % 360;+ bin = hues[Math.min(HUE_BINS - 1, Math.floor((hue / 360) * HUE_BINS))];+ weight = (saturation * value) ** 2;+ colored += 1;+ }++ bin.r += r * weight;+ bin.g += g * weight;+ bin.b += b * weight;+ bin.n += 1;+ bin.w += weight;+ }++ const opaque = colored + neutral.n;+ if (opaque === 0) return undefined;+ if (colored < Math.max(1, opaque * MIN_COLOR_SHARE)) return average([neutral]);++ const around = (i: number) => [+ hues[(i + HUE_BINS - 1) % HUE_BINS],+ hues[i],+ hues[(i + 1) % HUE_BINS],+ ];+ const weight = (i: number) => around(i).reduce((sum, bin) => sum + bin.w, 0);++ let best = 0;+ for (let i = 1; i < HUE_BINS; i++) if (weight(i) > weight(best)) best = i;++ return average(around(best).filter((bin) => bin.n > 0));+};++const SAMPLE_SIZE = 24;++const sampleImage = (src: string): Promise<string | undefined> =>+ new Promise((resolve) => {+ const image = new Image();+ // Canvas reads need CORS; a host that refuses it taints the canvas and the+ // card keeps its seed color.+ image.crossOrigin = 'anonymous';+ image.decoding = 'async';+ image.addEventListener('error', () => resolve(undefined));+ image.addEventListener('load', () => {+ try {+ const canvas = document.createElement('canvas');+ canvas.width = SAMPLE_SIZE;+ canvas.height = SAMPLE_SIZE;+ const context = canvas.getContext('2d', { willReadFrequently: true });+ if (!context) return resolve(undefined);++ context.drawImage(image, 0, 0, SAMPLE_SIZE, SAMPLE_SIZE);+ resolve(pickDominantColor(context.getImageData(0, 0, SAMPLE_SIZE, SAMPLE_SIZE).data));+ } catch {+ resolve(undefined);+ }+ });+ image.src = src;+ });++// The wall renders a hundred cards and re-renders on every filter change, so+// each image is sampled once per page load, and a finished sample is readable+// synchronously so a remounted card paints its color on the first frame.+const pending = new Map<string, Promise<string | undefined>>();+const settled = new Map<string, string | undefined>();++/** The sampled color of `src`: `undefined` = no color, absent key = not sampled yet. */+export const sampledImageColor = (src: string): { color?: string } | undefined =>+ settled.has(src) ? { color: settled.get(src) } : undefined;++export const sampleImageColor = (src: string): Promise<string | undefined> => {+ let promise = pending.get(src);+ if (!promise) {+ promise = sampleImage(src).then((color) => {+ settled.set(src, color);+ return color;+ });+ pending.set(src, promise);+ }++ return promise;+};diff --git a/src/features/AgentViewAll/resolveAgentBadge.test.ts b/src/features/AgentViewAll/resolveAgentBadge.test.tsindex c6240c217bf..e4bc81174d7 100644--- a/src/features/AgentViewAll/resolveAgentBadge.test.ts+++ b/src/features/AgentViewAll/resolveAgentBadge.test.ts@@ -17,7 +17,7 @@ describe('resolveAgentBadge', () => {expect(resolveAgentBadge(agent())).toEqual({});});- it('adds a cover only when the agent picked an avatar background color', () => {+ it('takes the cover from the avatar background color only when one was picked', () => {expect(resolveAgentBadge(agent({ backgroundColor: '#3b82f6' })).cover).toBe('#3b82f6');expect(resolveAgentBadge(agent({ backgroundColor: ' ' })).cover).toBeUndefined();expect(resolveAgentBadge(agent({ backgroundColor: null })).cover).toBeUndefined();@@ -25,10 +25,10 @@ describe('resolveAgentBadge', () => {expect(resolveAgentBadge(agent({ backgroundColor: 'rgba(0, 0, 0, 0)' })).cover).toBeUndefined();});- it('marks builtin agents official before pinned ones core', () => {+ it('marks only builtin agents with a chip', () => {expect(resolveAgentBadge(agent({ slug: 'inbox' })).bottom).toBe('official');expect(resolveAgentBadge(agent({ pinned: true, slug: 'inbox' })).bottom).toBe('official');- expect(resolveAgentBadge(agent({ pinned: true })).bottom).toBe('core');+ expect(resolveAgentBadge(agent({ pinned: true })).bottom).toBeUndefined();expect(resolveAgentBadge(agent({ slug: 'my-custom-agent' })).bottom).toBeUndefined();});diff --git a/src/features/AgentViewAll/resolveAgentBadge.ts b/src/features/AgentViewAll/resolveAgentBadge.tsindex 80995b660b2..c934a645da7 100644--- a/src/features/AgentViewAll/resolveAgentBadge.ts+++ b/src/features/AgentViewAll/resolveAgentBadge.ts@@ -11,7 +11,7 @@ const BUILTIN_SLUGS = new Set<string>(Object.values(BUILTIN_AGENT_SLUGS));*/const EVENT_LABEL_PATTERN = /\b(?:hackathons?|events?|limited)\b|限定|活动/i;-export type AgentBottomPendant = 'core' | 'official';+export type AgentBottomPendant = 'official';export interface AgentTopPendant {color?: string | null;@@ -21,7 +21,7 @@ export interface AgentTopPendant {export interface AgentBadge {/** Short identity chip pinned to the avatar's bottom edge. */bottom?: AgentBottomPendant;- /** Cover band color; absent renders the plain (avatar-only) badge. */+ /** Cover color the agent picked; absent lets the card derive one from the avatar. */cover?: string;/** Arch badge above the avatar, reserved for event / limited agents. */top?: AgentTopPendant;@@ -30,8 +30,8 @@ export interface AgentBadge {/*** Data-driven badge decorations for the agent list's badge wall. Most agents* resolve to nothing, so the wall doesn't turn into a sticker board:- * - cover: only agents that picked a real (non-transparent) avatar background color;- * - bottom chip: builtin agents read "official", pinned agents read "core";+ * - cover: the avatar background color the agent picked, if it is a real one;+ * - bottom chip: only builtin agents, reading "official";* - top arch: only agents carrying an event / limited label.*/export const resolveAgentBadge = (item: SidebarAgentItem): AgentBadge => {@@ -43,7 +43,6 @@ export const resolveAgentBadge = (item: SidebarAgentItem): AgentBadge => {if (cover) badge.cover = cover;if (item.slug && BUILTIN_SLUGS.has(item.slug)) badge.bottom = 'official';- else if (item.pinned) badge.bottom = 'core';const eventLabel = item.labels?.find((label) => EVENT_LABEL_PATTERN.test(label.name));if (eventLabel) badge.top = { color: eventLabel.color, label: eventLabel.name };diff --git a/src/features/AgentViewAll/useAgentCoverColor.ts b/src/features/AgentViewAll/useAgentCoverColor.tsnew file mode 100644index 00000000000..7f2729c5c65--- /dev/null+++ b/src/features/AgentViewAll/useAgentCoverColor.ts@@ -0,0 +1,40 @@+'use client';++import type { SidebarAgentItem } from '@lobechat/types';+import { useEffect, useState } from 'react';++import { coverImageSrc, sampledImageColor, sampleImageColor, seedCoverColor } from './coverColor';++/**+ * Cover color of a badge-wall card, in order of preference: the avatar+ * background color the agent picked, the dominant color of its uploaded+ * avatar image, then the color of its generated character (from the id).+ *+ * Returns `undefined` while an image is still being sampled, so the card shows+ * a neutral band rather than flashing an unrelated seed color first.+ */+export const useAgentCoverColor = (item: SidebarAgentItem, picked?: string): string | undefined => {+ const src = picked ? undefined : coverImageSrc(item);+ const [, rerender] = useState(0);++ useEffect(() => {+ if (!src || sampledImageColor(src)) return;++ let active = true;+ sampleImageColor(src).then(() => {+ if (active) rerender((count) => count + 1);+ });++ return () => {+ active = false;+ };+ }, [src]);++ if (picked) return picked;+ if (!src) return seedCoverColor(item);++ const sampled = sampledImageColor(src);+ if (!sampled) return undefined;++ return sampled.color || seedCoverColor(item);+};