From 2416daa42c3ce25694e1cb0b268bd43789468108 Mon Sep 17 00:00:00 2001 From: lynn Date: Sat, 14 Oct 2023 16:37:20 +0800 Subject: [PATCH] feat: add ColorStop type --- src/conic.ts | 7 ++----- src/index.ts | 3 ++- src/linear.ts | 7 ++----- src/radial.ts | 7 ++----- src/type.ts | 5 +++++ 5 files changed, 13 insertions(+), 16 deletions(-) create mode 100644 src/type.ts diff --git a/src/conic.ts b/src/conic.ts index 2f0443e..fe2fdde 100644 --- a/src/conic.ts +++ b/src/conic.ts @@ -1,4 +1,5 @@ import { resolveStops, split } from "./utils" +import { ColorStop } from './type' type RectColorSpace = 'srgb' | 'srgb-linear' | 'lab' | 'oklab' | 'xyz' | 'xyz-d50' | 'xyz-d65' type PolarColorSpace = 'hsl' | 'hwb' | 'lch' | 'oklch' @@ -9,11 +10,7 @@ interface ConicGradient { repeating: boolean position: string color?: Color - stops: Array<{ - color: string - offset: string - hint?: string - }> + stops: ColorStop[] } type Color = { diff --git a/src/index.ts b/src/index.ts index c9b67cc..4abcecb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ export * from './linear' export * from './radial' -export * from './conic' \ No newline at end of file +export * from './conic' +export * from './type' \ No newline at end of file diff --git a/src/linear.ts b/src/linear.ts index 36b08a1..6e3a942 100644 --- a/src/linear.ts +++ b/src/linear.ts @@ -1,4 +1,5 @@ import { split, resolveStops } from "./utils" +import { ColorStop } from './type' interface LinearOrientation { type: 'directional' | 'angular' @@ -8,11 +9,7 @@ interface LinearOrientation { export interface LinearResult { orientation: LinearOrientation repeating: boolean - stops: Array<{ - color: string - offset: string - hint?: string - }> + stops: ColorStop[] } export function parseLinearGradient(input: string): LinearResult { diff --git a/src/radial.ts b/src/radial.ts index a7ba997..559fc99 100644 --- a/src/radial.ts +++ b/src/radial.ts @@ -1,4 +1,5 @@ import { resolveStops, split } from './utils' +import { ColorStop } from './type' export type RgExtentKeyword = 'closest-corner' | 'closest-side' | 'farthest-corner' | 'farthest-side' @@ -7,11 +8,7 @@ export interface RadialResult { repeating: boolean size: string position: string - stops: Array<{ - color: string - offset: string - hint?: string - }> + stops: ColorStop[] } export function parseRadialGradient(input: string): RadialResult { diff --git a/src/type.ts b/src/type.ts new file mode 100644 index 0000000..1413f13 --- /dev/null +++ b/src/type.ts @@ -0,0 +1,5 @@ +export interface ColorStop { + color: string + offset: string + hint?: string +} \ No newline at end of file