Skip to content

A JavaScript implementation of the Simple Color Palette format — a minimal JSON-based file format for defining color palettes

License

Notifications You must be signed in to change notification settings

simple-color-palette/javascript-package

Repository files navigation

simple-color-palette

A JavaScript implementation of the Simple Color Palette format — a minimal JSON-based file format for defining color palettes

Feedback wanted on the API.

Install

npm install simple-color-palette

Usage

import ColorPalette from 'simple-color-palette';

const redColor = new ColorPalette.Color({
	name: 'Red',
	red: 1,
	green: 0,
	blue: 0,
});

const greenColor = new ColorPalette.Color({
	name: 'Green',
	red: 0,
	green: 1,
	blue: 0,
});

const palette = new ColorPalette({
	name: 'Traffic Lights',
	colors: [
		redColor,
		greenColor
	],
});

console.log(redColor.components);
// {red: 1, green: 0, blue: 0, opacity: 1}

// Modify color components
redColor.red = 0.9;

// Serialize to string
const serialized = palette.serialize();

// Load from serialized data
const loadedPalette = ColorPalette.deserialize(serialized);

API

See types.

Note

The palette operates in non-linear sRGB, while the serialized version is in linear (gamma-corrected) sRGB for precision.

About

A JavaScript implementation of the Simple Color Palette format — a minimal JSON-based file format for defining color palettes

Topics

Resources

License

Stars

Watchers

Forks