colors ~master
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()
andrgba()
functions, return aColor
- 🎨
hsl()
andhsla()
functions, return aColor
- 🎨
Color.toRGBA8()
to get a 8-bit sRGB quadruplet - 🎨
Color.toRGBA16()
to get a 16-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
// CSS support (WIP)
c = color("#ab9");
c = color("#0f1c4A43");
c = color("rgba(14.01, 25.0e+0%, 16, 0.5)");
c = color("hsl(180deg, 100%, 50%)");
c = color("gray(100%, 50%)");
c = color("lightgoldenrodyellow");
// 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);
}
- Registered by ponce
- ~master released a month ago
- AuburnSounds/colors
- BSL-1.0
- 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 - Download Stats:
-
-
0 downloads today
-
2 downloads this week
-
17 downloads this month
-
20 downloads total
-
- Score:
- 1.0
- Short URL:
- colors.dub.pm