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 byparseandparseColorMix, and accepted by all public color-input APIs. Channels can be outside0–1for out-of-sRGB colors.SrgbColorInput:{ space: 'srgb', r, g, b, alpha? }with gamma-encoded0–1channels, like CSScolor(srgb …). Use it for Figma and three.js floats.TaggedColorObject: whattoObject(space)returns; always tagged withspaceand carryingalpha.ColorInput: union of supported constructor inputs.ColorObject: union of supported color object inputs. UseTaggedColorObjectwhen every object includes a space.ColorSpace:'srgb' | 'hsl' | 'hwb' | 'hsv' | 'lab' | 'lch' | 'oklab' | 'oklch' | 'xyz' | 'p3'.MixColorSpace:ColorSpacewithout'hsv'. Used bymix(); HSV is a conversion target only.InterpolationColorSpace:'srgb' | 'p3' | 'hsl' | 'lab' | 'lch' | 'oklab' | 'oklch'. Used byscale()andinterpolate(); 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,RgbaObjectHslObject,HslaObjectHsvObject,HsvaObjectHwbObject,HwbaObjectLabObject,LabaObjectLchObject,LchaObjectOklabObject,OklabaObjectOklchObject,OklchaObjectXyzObject,XyzaObjectP3Object,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 byensureContrast,isReadable,generateStates,generateSystem,audit, andauditCssVariables.contrastRatioandcontrastAPCAreturn plain numbers.ReadableOptions:'aa' | 'aaa' | TargetOptions, accepted byisReadable.ScaleOptions:{ steps?: number; space?: InterpolationColorSpace }.PaletteOptions:{ steps?: number }.ColorBlindnessType: supported simulation type union.DetectedFormat: return type used bydetectFormat.
Find types for themes and audits
- Audit:
AuditInput,AuditOptions,AuditResult,AuditIssue,AuditSuggestion,ColorPair; for CSS,CssAuditOptions,CssAuditResult,CssContrastIssue,CssFixResult,CssFixChange. - Contrast repair:
ResolveResult(returned byensureContrast),EnsureContrastOptions,ContrastIntent. - Systems:
ColorSystem,SystemConfig,ResolvedSystemConfig,SemanticRole,ThemeMode,RoleColors,ThemeColors,GeneratedSystem,StateOptions,ColorStates. - Export options:
SystemCSSExportOptions,SystemTailwindCssOptions, andShadcnCssOptionsfor the system'stoCSS,toTailwindCss, andtoShadcnCss. - Color results:
NearestResult,NearestNamedResult,MixToCssOptions,CssColorMixSpace. - Theme files:
ThemeReport,ThemeEditResult,ApplyThemeOptions,AdjustThemeOptions,ThemeGroupandChannelChange.
/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 ofColorSystem.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);
}
}