Colore JS

Search documentation

Find a function or jump to a section.
v2.0.1

TypeScript types

Colore exports TypeScript types for inputs, channel objects, options, and result shapes.

Syntax

import type {
  ColorInput,
  ColorValue,
  ColorObject,
  ColorSpace,
  MixColorSpace,
  InterpolationColorSpace,
  InternalColor,
  RgbObject,
  OklchObject,
  TaggedColorObject,
  SrgbColorInput,
  ReadableOptions,
  TargetOptions,
  ContrastAlgorithm,
  ContrastLevel,
  ScaleOptions,
  PaletteOptions,
  ColorBlindnessType,
  DetectedFormat,
  AuditOptions,
  AuditResult,
  ResolveResult,
  SystemConfig,
  ColorSystem,
  StateOptions,
} from 'colore-js';

Pick the input or channel type

  • InternalColor: untagged { r, g, b, alpha } used by low-level internals.
  • ColorValue: public tagged linear-sRGB value { space: 'srgb-linear', r, g, b, alpha }; returned by parse and parseColorMix, and accepted by all public color-input APIs. Channels can be outside 0–1 for out-of-sRGB colors.
  • SrgbColorInput: { space: 'srgb', r, g, b, alpha? } with gamma-encoded 0–1 channels, like CSS color(srgb …). Use it for Figma and three.js floats.
  • TaggedColorObject: what toObject(space) returns; always tagged with space and carrying alpha.
  • ColorInput: union of supported constructor inputs.
  • ColorObject: union of supported color object inputs. Use TaggedColorObject when every object includes a space.
  • ColorSpace: 'srgb' | 'hsl' | 'hwb' | 'hsv' | 'lab' | 'lch' | 'oklab' | 'oklch' | 'xyz' | 'p3'.
  • MixColorSpace: ColorSpace without 'hsv'. Used by mix(); HSV is a conversion target only.
  • InterpolationColorSpace: 'srgb' | 'p3' | 'hsl' | 'lab' | 'lch' | 'oklab' | 'oklch'. Used by scale() and interpolate(); unsupported runtime names throw rather than falling back to OKLab.

Use named channels

Colore exports typed objects for each space, including alpha variants where relevant:

  • RgbObject, RgbaObject
  • HslObject, HslaObject
  • HsvObject, HsvaObject
  • HwbObject, HwbaObject
  • LabObject, LabaObject
  • LchObject, LchaObject
  • OklabObject, OklabaObject
  • OklchObject, OklchaObject
  • XyzObject, XyzaObject
  • P3Object, P3aObject

The channel ranges on these types are nominal ranges for ordinary in-gamut colors, not runtime clamps. Numeric conversion methods preserve extended coordinates, so a wide-gamut source may produce negative components or values above the nominal maximum. Request a bounded sRGB display value with an explicit string serializer such as hex(), rgb(), or hsl().

Ambiguous input shapes use explicit tagged types: LabColorInput, LchColorInput, OklabColorInput, OklchColorInput, XyzColorInput, and P3ColorInput. For example:

import type { ColorInput } from 'colore-js';

const perceptual: ColorInput = {
  space: 'oklch',
  l: 0.65,
  c: 0.18,
  h: 280,
  alpha: 0.8,
};

Type options and results

  • ContrastAlgorithm ('wcag2' | 'apca'), ContrastLevel ('aa' | 'aaa'), TargetOptions ({ intent, algorithm, level, target }): the one contrast vocabulary shared by ensureContrast, isReadable, generateStates, generateSystem, audit, and auditCssVariables. contrastRatio and contrastAPCA return plain numbers.
  • ReadableOptions: 'aa' | 'aaa' | TargetOptions, accepted by isReadable.
  • ScaleOptions: { steps?: number; space?: InterpolationColorSpace }.
  • PaletteOptions: { steps?: number }.
  • ColorBlindnessType: supported simulation type union.
  • DetectedFormat: return type used by detectFormat.

Find types for themes and audits

  • Audit: AuditInput, AuditOptions, AuditResult, AuditIssue, AuditSuggestion, ColorPair; for CSS, CssAuditOptions, CssAuditResult, CssContrastIssue, CssFixResult, CssFixChange.
  • Contrast repair: ResolveResult (returned by ensureContrast), EnsureContrastOptions, ContrastIntent.
  • Systems: ColorSystem, SystemConfig, ResolvedSystemConfig, SemanticRole, ThemeMode, RoleColors, ThemeColors, GeneratedSystem, StateOptions, ColorStates.
  • Export options: SystemCSSExportOptions, SystemTailwindCssOptions, and ShadcnCssOptions for the system's toCSS, toTailwindCss, and toShadcnCss.
  • Color results: NearestResult, NearestNamedResult, MixToCssOptions, CssColorMixSpace.
  • Theme files: ThemeReport, ThemeEditResult, ApplyThemeOptions, AdjustThemeOptions, ThemeGroup and ChannelChange.

/fn Types

colore-js/fn re-exports the core input/result types used in standalone signatures plus audit, system, accessibility, contrast-repair, and CSS-mix option types.

import type { ColorInput, EnsureContrastOptions, ResolveResult } from 'colore-js/fn';

Design token types

  • DTCGDocument, DTCGGroup, DTCGToken, DTCGColorValue, DTCGColorSpace: the DTCG 2025.10 output of ColorSystem.toDTCG(). Exported from the package root.

Error Type

  • ColorError: exported error class used by strict parsing and invalid argument paths.

Example

import { colore, detectFormat, ColorError } from 'colore-js';
import type { ColorInput, ScaleOptions, DetectedFormat } from 'colore-js';

const input: ColorInput = '#7c3aed';
const format: DetectedFormat | null = detectFormat(input);
const scaleOptions: ScaleOptions = { steps: 7, space: 'oklab' };

try {
  const out = colore(input).scale('#22c55e', scaleOptions).map(c => c.hex());
  console.log(format, out.length); // hex 7
} catch (error) {
  if (error instanceof ColorError) {
    console.error(error.message);
  }
}