feat: 增加单元测试

This commit is contained in:
qier222 2022-04-13 16:17:21 +08:00
parent e6b1b91c01
commit 0c89b4aa53
No known key found for this signature in database
GPG key ID: 9C85007ED905F14D
9 changed files with 777 additions and 90 deletions

View file

@ -1,7 +1,6 @@
import Player from './Player'
import { player, state } from '@/renderer/store'
import { resizeImage } from '@/renderer/utils/common'
import { average } from 'color.js'
import { getCoverColor } from '@/renderer/utils/common'
import { colord } from 'colord'
import IconButton from '../IconButton'
import SvgIcon from '../SvgIcon'
@ -16,21 +15,11 @@ const LyricPanel = () => {
const [bgColor, setBgColor] = useState({ from: '#222', to: '#222' })
useEffect(() => {
const cover = resizeImage(track?.al?.picUrl ?? '', 'xs')
if (cover) {
average(cover, { amount: 1, format: 'hex', sample: 1 }).then(color => {
let c = colord(color as string)
const hsl = c.toHsl()
if (hsl.s > 50) c = colord({ ...hsl, s: 50 })
if (hsl.l > 50) c = colord({ ...c.toHsl(), l: 50 })
if (hsl.l < 30) c = colord({ ...c.toHsl(), l: 30 })
const to = c.darken(0.15).rotate(-5).toHex()
setBgColor({
from: c.toHex(),
to,
})
})
}
getCoverColor(track?.al?.picUrl || '').then(color => {
if (!color) return
const to = colord(color).darken(0.15).rotate(-5).toHex()
setBgColor({ from: color, to })
})
}, [track?.al?.picUrl])
return (