Skip to content

Commit

Permalink
Color 1.0.0 HEX,RGBA,HSLA,HSV,HWB,CMYK
Browse files Browse the repository at this point in the history
  • Loading branch information
foo123 committed Dec 5, 2022
1 parent e357b8d commit 4ae3300
Show file tree
Hide file tree
Showing 5 changed files with 1,105 additions and 867 deletions.
64 changes: 41 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,81 @@
css-color
=========

simple class for manipulating color values for css, svg, canvas/image
Class for manipulating color values for css, svg, canvas/image, etc..

version **1.0.0**

**Color Formats: HEX, RGB(A), HSL(A), HWB, HSV, CMYK**

**example:**

```javascript

var rgb = new CSS.Color([128, 255, 245, 1]).toRGB(asString, condenced, noTransparency);
var hsl = new CSS.Color([128, 255, 245, 1]).toHSL(asString, condenced, noTransparency);
var cmyk = new CSS.Color([128, 255, 245, 1]).toCMYK(asString, condenced, withTransparency);
let rgb = new Color([128, 255, 245, 1]).toRGB(asString, condenced, noTransparency);
let hsl = new Color([128, 255, 245, 1]).toHSL(asString, condenced, noTransparency);
let hwb = new Color([128, 255, 245, 1]).toHWB(asString, condenced, noTransparency);
let cmyk = new Color([128, 255, 245, 1]).toCMYK(asString, condenced, withTransparency);

// or using a constructor factory pattern
var rgb = CSS.Color([128, 255, 245, 1]).toRGB(asString, condenced, noTransparency);
var hsl = CSS.Color([128, 255, 245, 1]).toHSL(asString, condenced, noTransparency);
var cmyk = CSS.Color([128, 255, 245, 1]).toCMYK(asString, condenced, withTransparency);
let rgb = Color([128, 255, 245, 1]).toRGB(asString, condenced, noTransparency);
let hsl = Color([128, 255, 245, 1]).toHSL(asString, condenced, noTransparency);
let hwb = Color([128, 255, 245, 1]).toHWB(asString, condenced, noTransparency);
let cmyk = Color([128, 255, 245, 1]).toCMYK(asString, condenced, withTransparency);

let color = new Color().fromRGB([255, 255, 255, 0.3]);
// or via static method
let color = Color.fromRGB([255, 255, 255]);

let color = new Color().fromHSL([120, 50, 100, 0.7]);
// or via static method
let color = Color.fromHSL([120, 50, 100]);

var color = new CSS.Color().fromRGB([255, 255, 255, 0.3]);
let color = new Color().fromHSV([120, 50, 100, 0.7]);
// or via static method
var color = CSS.Color.fromRGB([255, 255, 255]);
let color = CSS.Color.fromHSV([120, 50, 100]);

var color = new CSS.Color().fromHSL([120, 50, 100, 0.7]);
let color = new Color().fromHWB([120, 50, 100, 0.7]);
// or via static method
var color = CSS.Color.fromHSL([120, 50, 100]);
let color = Color.fromHWB([120, 50, 100]);

var color = new CSS.Color().fromHEX([0xff, 0xaa, 0x00, 0xfa]);
let color = new Color().fromHEX([0xff, 0xaa, 0x00, 0xfa]);
// or via static method
var color = CSS.Color.fromHEX([0xff, 0xaa, 0x00]);
let color = Color.fromHEX([0xff, 0xaa, 0x00]);

var color = new CSS.Color().fromPixel(0xff3d1208);
let color = new Color().fromPixel(0xff3d1208);
// or via static method
var color = CSS.Color.fromPixel(0xff3d1208);
let color = Color.fromPixel(0xff3d1208);

var color = new CSS.Color().fromKeyword('orange');
let color = new Color().fromKeyword('orange');
// or via static method
var color = CSS.Color.fromKeyword('orange');
let color = Color.fromKeyword('orange');

var color = new CSS.Color().fromCMYK([1, 0.3, 0.5, 1]);
let color = new Color().fromCMYK([1, 0.3, 0.5, 1]);
// or via static method
var color = CSS.Color.fromCMYK([1, 0.3, 0.5, 1]);
let color = Color.fromCMYK([1, 0.3, 0.5, 1]);

// also
var color = CSS.Color.fromString('rgba(255, 100%, 100%, 0.7)');
var color = CSS.Color.fromString('hsla(120, 50%, 100%, 0.5)');
var color = CSS.Color.fromString('#fff');
var color = CSS.Color.fromString('slategrey');
let color = Color.fromString('rgba(255, 100%, 100%, 0.7)');
let color = Color.fromString('hsla(120, 50%, 100%, 0.5)');
let color = Color.fromString('hwb(120 50% 100% / 0.5)');
let color = Color.fromString('#fff');
let color = Color.fromString('slategrey');

// output
console.log(color.toHSL(asString, condenced, noTransparency)); // hsla(..)
console.log(color.toHWB(asString, condenced, noTransparency)); // hwb(..)
console.log(color.toHEX(asString, condenced, withTransparency)); // #..
console.log(color.toRGB(asString, condenced, noTransparency)); // rgb(255, 255, 255)
console.log(color.toHSL(asString, condenced, noTransparency)); // hsl(..)
console.log(color.toHWB(asString, condenced, noTransparency)); // hwb(..)
console.log(color.toCMYK(asString, condenced, withTransparency)); // CMYK: [..]
console.log(color.toPixel(withTransparency)); // 0x...
console.log(color.toKeyword(asString, condenced, withTransparency)); // only if color was set from keyword

// also
console.log(color.toString('hsla', condenced));
console.log(color.toString('hsl', condenced));
console.log(color.toString('hwb', condenced));
console.log(color.toString('rgb', condenced));
console.log(color.toString('rgba', condenced));
console.log(color.toString('keyword', condenced)); // only if color was set from keyword
Expand Down
Loading

0 comments on commit 4ae3300

Please sign in to comment.