chromaticity-color-utilities
Advanced tools
Comparing version 0.12.0-alpha to 0.12.1-alpha
@@ -238,5 +238,2 @@ "use strict"; | ||
var max = Math.pow(2, bitDepth) - 1; | ||
// this.valueRangeCheck(r, 0, max) | ||
// this.valueRangeCheck(g, 0, max) | ||
// this.valueRangeCheck(b, 0, max) | ||
if (typeof r == 'undefined') | ||
@@ -316,5 +313,2 @@ throw new Error('r undefined'); | ||
var max = Math.pow(2, bitDepth) - 1; | ||
// this.valueRangeCheck(r, 0, max) | ||
// this.valueRangeCheck(g, 0, max) | ||
// this.valueRangeCheck(b, 0, max) | ||
if (typeof r == 'undefined') | ||
@@ -321,0 +315,0 @@ throw new Error('r undefined'); |
@@ -51,2 +51,5 @@ import * as Colors from './Colors'; | ||
} | ||
export interface cssArgs { | ||
method?: string; | ||
} | ||
export declare abstract class colorType { | ||
@@ -89,3 +92,3 @@ constructor(); | ||
scheme<T extends colorType>(type: string, args?: schemeArgs): T[]; | ||
css(): string; | ||
css(args?: cssArgs): string; | ||
protected torgb(args: newColorArgs): Colors.rgb; | ||
@@ -92,0 +95,0 @@ protected torec709(args: newColorArgs): Colors.rec709rgb; |
@@ -614,4 +614,43 @@ "use strict"; | ||
}; | ||
colorType.prototype.css = function () { | ||
return 'not yet implemented'; | ||
colorType.prototype.css = function (args) { | ||
if (typeof args === 'undefined') { | ||
args = { | ||
method: 'hex' | ||
}; | ||
} | ||
else if (typeof args.method === 'undefined') { | ||
args.method = 'hex'; | ||
} | ||
var colorString; | ||
switch (args.method) { | ||
case 'hex': | ||
var hex = this.to('hex'); | ||
colorString = "#".concat(hex.getHex()); | ||
break; | ||
// case 'hexa': | ||
// break | ||
case 'rgb': | ||
var rgb = this.to('rgb'); | ||
colorString = "rgb(".concat(rgb.getR(), ", ").concat(rgb.getG(), ", ").concat(rgb.getB(), ")"); | ||
break; | ||
case 'rgba': | ||
var rgba = this.to('rgb'); | ||
// precision of alpha is ~1/256, or ~0.004 at best | ||
var rgbaAlpha = (rgba.getA() / rgba.getMax()).toPrecision(4).replace(/\.?0+$/, ''); | ||
colorString = "rgba(".concat(rgba.getR(), ", ").concat(rgba.getG(), ", ").concat(rgba.getB(), ", ").concat(rgbaAlpha, ")"); | ||
break; | ||
case 'hsl': | ||
var hsl = this.to('hsl'); | ||
colorString = "hsl(".concat(hsl.getH(), ", ").concat(hsl.getS(), "%, ").concat(hsl.getL(), "%)"); | ||
break; | ||
case 'hsla': | ||
var hsla = this.to('hsl'); | ||
// precision of alpha is ~1/256, or ~0.004 at best | ||
var hslaAlpha = (hsla.getA() / 100).toPrecision(4).replace(/\.?0+$/, ''); | ||
colorString = "hsla(".concat(hsla.getH(), ", ").concat(hsla.getS(), "%, ").concat(hsla.getL(), "%, ").concat(hslaAlpha, ")"); | ||
break; | ||
default: | ||
throw new Error("Unrecognized css method '".concat(args.method, "'.")); | ||
} | ||
return colorString; | ||
}; | ||
@@ -618,0 +657,0 @@ colorType.prototype.torgb = function (args) { |
@@ -336,4 +336,5 @@ import * as Colors from './Colors'; | ||
* Convert YPbPr to YCbCr | ||
* Y must be in range 0 to 1; Pb and Pr must be in range -0.5 to 0.5 | ||
* 16 for black and the value of 235 for white when using an 8-bit representation. The standard has 8-bit digitized versions of CB and CR scaled to a different range of 16 to 240 | ||
* Y must be in range 0 to 1; Pb and Pr must be in range -0.5 to 0.5. | ||
* Y' defaults to 16 for black and 235 for white when using an 8-bit representation. | ||
* The standard has 8-bit digitized versions of CB and CR scaled to a different range of 16 to 240. | ||
* | ||
@@ -340,0 +341,0 @@ * @param {Colors.ypbpr} ypbpr |
{ | ||
"name": "chromaticity-color-utilities", | ||
"version": "0.12.0-alpha", | ||
"version": "0.12.1-alpha", | ||
"description": "Color utilities for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -15,4 +15,6 @@ # <img src="https://reiniiriarios.github.io/chromaticity-color-utilities/img/chromaticity-icon-01.png" width="26" height="26"> chromaticity-color-utilities | ||
### Example Usage - JavaScript | ||
## Example Usage | ||
### JavaScript | ||
```js | ||
@@ -35,3 +37,3 @@ const Color = require('chromaticity-color-utilities') | ||
### Example Usage - TypeScript | ||
### TypeScript | ||
@@ -38,0 +40,0 @@ ```ts |
Sorry, the diff of this file is too big to display
326984
7763
101