colors 0.0.2

A color library that implement CSS colors.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Colors

colors DUB package is a CSS color parsing libraries. It defines basic types for colors, and a monomorphic Color type to use as interchange.

The problem is that screens and CSS now support the P3 colorspace, the end-goal is to be ready for more conversions than just staying sRGB forever. Color will be able to "do it all", in the future.

This is a work in progress. Only sRGB supported for now.

Current features

  • 🎨 color() function to parse a CSS color string.
  • 🎨 rgb() and rgba() functions, return a Color
  • 🎨 hsl() and hsla() functions, return a Color
  • 🎨 Color.toRGBA8() to get a 8-bit sRGB quadruplet
  • 🎨 Color.toRGBAf() to get a 32-bit float sRGB quadruplet
  • 🎨 nothrow @nogc @safe
  • 🎨 See test-suite/ for exact syntax supported, the goal is to follow CSS recommendations.

Tip: Parsing a color string

import colors;

// Quick way:
Color c = color("red");
Color c = Color("blue"); // also works

// More correct way:
string err;
if (!parseCSSColor(str, c, err)) 
    throw new Exception(err);

Making it useful

import std.stdio;
import colors;

void main()
{
    RGBA8 c = color("coral").toRGBA8;
    writefln("c is %s,%s,%s,%s", c.r, c.g, c.b, c.a);
}
Dependencies:
none
Versions:
0.0.3 2024-Oct-11
0.0.2 2024-Oct-11
0.0.1 2024-Oct-11
~master 2024-Oct-14
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 2 downloads this week

  • 17 downloads this month

  • 20 downloads total

Score:
1.0
Short URL:
colors.dub.pm