import { ColorRGB, ColorReference } from './color.js' import { Length } from './length.js' export const GradientColorStop = (props: any) => ({ color: ColorReference(props.color) as ColorReference | ColorRGB, start: props.start != null ? Length(props.start) : null, end: props.end != null ? Length(props.end) : null }) export const Gradient = (gradient?: any) => { let angle = 0 let stops: GradientColorStop[] = [] if (!gradient) { return { angle, stops } } if (gradient.angle) { angle = gradient.angle } if (Array.isArray(gradient.stops)) { stops = gradient.stops.map(GradientColorStop) } return { angle, stops } } Gradient.isValid = (gradient: Gradient) => gradient.stops.length > 0 && gradient.stops.every((stop) => ColorReference.isValid(stop.color)) export type GradientColorStop = ReturnType export type Gradient = ReturnType