import { getGradientFirstParam } from '.'; import { Form, Switch } from 'antd'; import hljs from 'highlight.js/lib/core'; import React, { useState } from 'react'; import shallow from 'zustand/shallow'; import { symbols, rgbToString } from './Output'; import { SectionTitle, SliderInput } from './subcomponents'; import { useInputStore } from '~/components/store'; export const FilterControls: React.FC = () => { const [svgProps, cssProps, filterProps, setFilterProps] = useInputStore( (state) => [state.svgProps, state.cssProps, state.filterProps, state.setFilterProps], shallow ); const { contrast, brightness, invert } = filterProps; const [inlineSvg, setInlineSvg] = useState(false); const { size, baseFrequency, numOctaves } = svgProps; const { gradients } = cssProps; const gradientsString = gradients.map((grad) => { return `${grad.type}-gradient(${getGradientFirstParam(grad)}, ${rgbToString( grad.stops[0].color )}, ${rgbToString(grad.stops[1].color)})`; }); const cleanSvgString = ``; const inlineSvgString = `url("data:image/svg+xml,${cleanSvgString.replace( symbols, encodeURIComponent )}")`; const resultCssDisplay = `/* resulting css */ { width: 250px; height: 250px; background: ${gradientsString.join(', ')}, ${ inlineSvg ? inlineSvgString : 'url(/👆/that/noise.svg)' }; filter: contrast(${contrast}%) brightness(${brightness}%)${invert ? ' invert(100%)' : ''}; } `; return (
        
      
`${v}%`} onChange={(val: number) => setFilterProps({ ...filterProps, contrast: val, }) } value={typeof contrast === 'number' ? contrast : 10} /> `${v}%`} onChange={(val: number) => setFilterProps({ ...filterProps, brightness: val, }) } value={typeof brightness === 'number' ? brightness : 0} /> setFilterProps({ ...filterProps, invert: v, }) } /> setInlineSvg(e)} />
); };