import { RotateCcw } from 'lucide-react' import * as React from 'react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { Slider } from '@/components/ui/slider' import { hexToHSL } from '@/lib/theme/palette' import { type BackgroundEffects, defaultBackgroundEffects, } from '@/lib/theme/tokens' function hslToHex(hsl: string): string { if (!hsl) return '#000000' const parts = hsl.split(' ').filter(Boolean) if (parts.length < 3) return '#000000' const h = parseFloat(parts[0]) const s = parseFloat(parts[1].replace('%', '')) const l = parseFloat(parts[2].replace('%', '')) const sDecimal = s / 100 const lDecimal = l / 100 const c = (1 - Math.abs(2 * lDecimal - 1)) * sDecimal const x = c * (1 - Math.abs(((h / 60) % 2) - 1)) const m = lDecimal - c / 2 let r = 0 let g = 0 let b = 0 if (h >= 0 && h < 60) { r = c g = x } else if (h >= 60 && h < 120) { r = x g = c } else if (h >= 120 && h < 180) { g = c b = x } else if (h >= 180 && h < 240) { g = x b = c } else if (h >= 240 && h < 300) { r = x b = c } else if (h >= 300 && h < 360) { r = c b = x } const toHex = (value: number) => { const hex = Math.round((value + m) * 255).toString(16) return hex.length === 1 ? `0${hex}` : hex } return `#${toHex(r)}${toHex(g)}${toHex(b)}` } type BackgroundEffectsControlsProps = { effects: BackgroundEffects onChange: (effects: BackgroundEffects) => void disabled?: boolean } export function BackgroundEffectsControls({ effects, onChange, disabled = false, }: BackgroundEffectsControlsProps) { const handleValueChange = (key: keyof BackgroundEffects, value: number) => { if (disabled) return onChange({ ...effects, [key]: value, }) } const handleColorChange = (e: React.ChangeEvent) => { if (disabled) return const hex = e.target.value const hsl = hexToHSL(hex) onChange({ ...effects, overlayColor: hsl, }) } const handlePositionChange = (value: string) => { if (disabled) return onChange({ ...effects, position: value as BackgroundEffects['position'], }) } const handleGradientChange = (e: React.ChangeEvent) => { if (disabled) return onChange({ ...effects, gradientOverlay: e.target.value, }) } const handleReset = () => { if (disabled) return onChange(defaultBackgroundEffects) } return (

背景效果调节

{effects.blur}px
handleValueChange('blur', vals[0])} />
{Math.round(effects.overlayOpacity * 100)}%
handleValueChange('overlayOpacity', vals[0] / 100)} />
{effects.brightness}%
handleValueChange('brightness', vals[0])} />
{effects.contrast}%
handleValueChange('contrast', vals[0])} />
{effects.saturate}%
handleValueChange('saturate', vals[0])} />

可选:输入有效的 CSS gradient 字符串

) }