Skip to content

palette - Shade Palette Generation ​

Generate design system shade palettes from any color. Supports Ant Design HSV curves, linear interpolation, and custom generator functions.

An invalid base color throws, including empty shade requests and custom generators. Parser fallback black is never promoted into a valid palette.

Built-in algorithms retain the base alpha and instance useDecimal option. Shade 500 is an independent copy of the base. Later global configuration does not override the source instance's options. Custom generators control their output opacity and precision.

Install ​

ts
import xcolor from '@xpyjs/color'
import palettePlugin from '@xpyjs/color/plugins/palette'

xcolor.use(palettePlugin)

Instance Methods ​

palette(options?) ​

Generate a design system shade palette from the current color. The base color maps to shade 500, with lighter shades below and darker shades above.

Dark shades can reach pure black. A black base remains black in subsequent dark shades instead of being artificially brightened.

linear uses fixed anchors: white at 50, the base at 500, and black at 950. Intermediate colors interpolate by shade value. Subsets, ordering and duplicates do not change a shade's color. This corrects the previous request-relative interpolation, so intermediate colors may differ from older versions.

ParameterTypeDefaultDescription
options.typePaletteType'antd'Palette generation type
options.shadesShade[][50,...,950]Shade levels

Return value: XColor[]

ts
xcolor('#1890ff').palette()
// → XColor[], 11 shades (50–950)

xcolor('#1890ff').palette({ type: 'linear' })
// → linear interpolation palette

xcolor('#ff0000').palette({ shades: [100, 500, 900] })
// → 3 shades

Palette Type (PaletteType) ​

antd— HSV curve, perceptually uniform50100200300400500600700800900950linear— linear RGB interpolationantd— richer hue rotation50100200300400500600700800900950linear— even but may feel flatantd uses non-linear hue rotation & saturation shifts for richer palettes
ValueDescription
'antd'Ant Design HSV curve algorithm. Non-linear hue rotation + saturation/value adjustment for perceptually uniform palettes
'linear'Linear RGB interpolation. Even transition from white through base color to black
(baseColor, shades) => XColor[]Custom function. Receives the base color and shade levels, returns corresponding XColor[]
ts
// Custom function example
const result = xcolor('#1890ff').palette({
  type: (baseColor, shades) => {
    return shades.map((s) => {
      const factor = (s - 500) / 500
      return factor < 0
        ? xcolor(baseColor.toHex()).lighten(Math.abs(factor) * 50)
        : xcolor(baseColor.toHex()).darken(factor * 50)
    })
  }
})

Shade Levels (Shade) ​

By default, 11 shade levels are generated: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950.

The base color maps to 500. Shades below 500 are lighter; shades above 500 are darker.

Released under the MIT License.