chromaticity-color-utilities
Advanced tools
Comparing version 0.3.0-alpha to 0.4.0-alpha
@@ -67,5 +67,5 @@ import * as Colors from './Colors'; | ||
a?: number; | ||
to(type: string, args?: newColorArgs): colorType | any; | ||
modify(modification: string, args?: modifyArgs): colorType; | ||
scheme(type: string, args?: schemeArgs): colorType[]; | ||
to<T extends colorType>(type: string, args?: newColorArgs): T; | ||
modify<T extends colorType>(modification: string, args?: modifyArgs): T; | ||
scheme<T extends colorType>(type: string, args?: schemeArgs): T[]; | ||
css(): string; | ||
@@ -72,0 +72,0 @@ protected torgb(args: newColorArgs): Colors.rgb; |
@@ -55,8 +55,11 @@ "use strict"; | ||
type = type.toLowerCase().replace(/[^a-z0-9]/, ''); | ||
var to; | ||
switch (type) { | ||
case 'rgb': | ||
case 'rgba': | ||
return this.torgb(args); | ||
to = this.torgb(args); | ||
break; | ||
case 'hex': | ||
return this.tohex(args); | ||
to = this.tohex(args); | ||
break; | ||
case 'rec709': | ||
@@ -66,3 +69,4 @@ case 'rgb709': | ||
case 'rgbrec709': | ||
return this.torec709(args); | ||
to = this.torec709(args); | ||
break; | ||
case 'rec2020': | ||
@@ -72,12 +76,16 @@ case 'rgb2020': | ||
case 'rgbrec2020': | ||
return this.torec2020(args); | ||
to = this.torec2020(args); | ||
break; | ||
case 'hsv': | ||
case 'hsva': | ||
return this.tohsv(args); | ||
to = this.tohsv(args); | ||
break; | ||
case 'hsl': | ||
case 'hsla': | ||
return this.tohsl(args); | ||
to = this.tohsl(args); | ||
break; | ||
case 'hsi': | ||
case 'hsia': | ||
return this.tohsi(args); | ||
to = this.tohsi(args); | ||
break; | ||
case 'hsp': | ||
@@ -87,22 +95,32 @@ case 'hspa': | ||
case 'hspba': | ||
return this.tohsp(args); | ||
to = this.tohsp(args); | ||
break; | ||
case 'cmyk': | ||
return this.tocmyk(args); | ||
to = this.tocmyk(args); | ||
break; | ||
case 'yiq': | ||
return this.toyiq(args); | ||
to = this.toyiq(args); | ||
break; | ||
case 'xyz': | ||
return this.toxyz(args); | ||
to = this.toxyz(args); | ||
break; | ||
case 'xyy': | ||
return this.toxyy(args); | ||
to = this.toxyy(args); | ||
break; | ||
case 'lab': | ||
return this.tolab(args); | ||
to = this.tolab(args); | ||
break; | ||
case 'luv': | ||
return this.toluv(args); | ||
to = this.toluv(args); | ||
break; | ||
case 'ypbpr': | ||
return this.toypbpr(args); | ||
to = this.toypbpr(args); | ||
break; | ||
case 'ycbcr': | ||
return this.toycbcr(args); | ||
to = this.toycbcr(args); | ||
break; | ||
default: | ||
throw new Error('Unable to find conversion path'); | ||
} | ||
return to; | ||
}; | ||
@@ -281,3 +299,4 @@ colorType.prototype.modify = function (modification, args) { | ||
case 'comp': | ||
intScheme = Harmony_1.default.complement(this.to('hsv', { round: false })); | ||
var hsv = this.to('hsv', { round: false }); | ||
intScheme = Harmony_1.default.complement(hsv); | ||
break; | ||
@@ -284,0 +303,0 @@ case 'analogous': |
@@ -1,24 +0,3 @@ | ||
import { colorType } from './ColorType'; | ||
interface newColorArgs { | ||
bitDepth?: number; | ||
bitRate?: number; | ||
normalized?: boolean; | ||
colorSpace?: string; | ||
referenceWhite?: string; | ||
yLower?: number; | ||
yUpper?: number; | ||
cLower?: number; | ||
cUpper?: number; | ||
kb?: number; | ||
kr?: number; | ||
pb?: number; | ||
pr?: number; | ||
} | ||
interface colorDef { | ||
from(type: string, value: number[] | string, args?: newColorArgs): colorType; | ||
} | ||
declare class Color implements colorDef { | ||
from(type: string, value: number[] | number | string, args?: newColorArgs): colorType; | ||
} | ||
declare const _default: Color; | ||
export = _default; | ||
import Color from './Color'; | ||
export default Color; | ||
export * as colorTypes from './Colors'; |
119
dist/main.js
@@ -40,112 +40,9 @@ "use strict"; | ||
}; | ||
var Colors = __importStar(require("./Colors")); | ||
var Color = /** @class */ (function () { | ||
function Color() { | ||
} | ||
Color.prototype.from = function (type, value, args) { | ||
type = type.toLowerCase().replace(/[^a-z0-9]/, ''); | ||
if (typeof args === 'undefined') | ||
args = {}; | ||
if (typeof args.bitDepth === 'undefined' && | ||
typeof args.bitRate !== 'undefined') { | ||
args.bitDepth = args.bitRate; | ||
} | ||
if (typeof value === 'string') { | ||
if (type == 'hex') | ||
return new Colors.hex(value); | ||
else | ||
throw new Error('Unable to parse color'); | ||
} | ||
else if (typeof value === 'number') { | ||
switch (type) { | ||
case 'hex': | ||
return new Colors.hex(value); | ||
case 'nm': | ||
case 'light': | ||
case 'nanometers': | ||
case 'nano': | ||
case 'wavelength': | ||
return new Colors.nm(value); | ||
case 'kelvin': | ||
case 'k': | ||
case 'temperature': | ||
case 'temp': | ||
return new Colors.kelvin(value); | ||
default: | ||
throw new Error('Unable to determine color type'); | ||
} | ||
} | ||
else { | ||
switch (type) { | ||
case 'rgb': | ||
case 'rgba': | ||
if (typeof args.bitDepth === 'undefined') | ||
args.bitDepth = 8; | ||
if (typeof value[3] === 'undefined') | ||
value[3] = Math.pow(2, args.bitDepth) - 1; | ||
return new Colors.rgb(value[0], value[1], value[2], value[3], args.bitDepth); | ||
case 'rec709': | ||
case 'rgb709': | ||
case 'rec709rgb': | ||
case 'rgbrec709': | ||
if (typeof args.bitDepth === 'undefined') | ||
args.bitDepth = 8; | ||
if (typeof value[3] === 'undefined') | ||
value[3] = Math.pow(2, args.bitDepth) - 1; | ||
return new Colors.rec709rgb(value[0], value[1], value[2], value[3], args.bitDepth); | ||
case 'rec2020': | ||
case 'rgb2020': | ||
case 'rec2020rgb': | ||
case 'rgbrec2020': | ||
if (typeof args.bitDepth === 'undefined') | ||
args.bitDepth = 10; | ||
if (typeof value[3] === 'undefined') | ||
value[3] = Math.pow(2, args.bitDepth) - 1; | ||
return new Colors.rec2020rgb(value[0], value[1], value[2], value[3], args.bitDepth); | ||
case 'hsv': | ||
case 'hsva': | ||
if (typeof value[3] === 'undefined') | ||
value[3] = 100; | ||
return new Colors.hsv(value[0], value[1], value[2], value[3]); | ||
case 'hsl': | ||
case 'hsla': | ||
if (typeof value[3] === 'undefined') | ||
value[3] = 100; | ||
return new Colors.hsl(value[0], value[1], value[2], value[3]); | ||
case 'hsi': | ||
case 'hsia': | ||
if (typeof value[3] === 'undefined') | ||
value[3] = 100; | ||
return new Colors.hsi(value[0], value[1], value[2], value[3]); | ||
case 'hsp': | ||
case 'hspa': | ||
if (typeof value[3] === 'undefined') | ||
value[3] = 100; | ||
return new Colors.hsp(value[0], value[1], value[2], value[3], args.pb, args.pr); | ||
case 'cmyk': | ||
return new Colors.cmyk(value[0], value[1], value[2], value[3]); | ||
case 'yiq': | ||
return new Colors.yiq(value[0], value[1], value[2], args.normalized); | ||
case 'xyz': | ||
return new Colors.xyz(value[0], value[1], value[2]); | ||
case 'xyy': | ||
return new Colors.xyy(value[0], value[1], value[2]); | ||
case 'lab': | ||
return new Colors.lab(value[0], value[1], value[2]); | ||
case 'luv': | ||
return new Colors.luv(value[0], value[1], value[2]); | ||
case 'ypbpr': | ||
if (typeof args.kb == 'undefined' || typeof args.kr == 'undefined') { | ||
throw new Error('Must supply Kb and Kr constants'); | ||
} | ||
return new Colors.ypbpr(value[0], value[1], value[2], args.kb, args.kr); | ||
case 'ycbcr': | ||
return new Colors.ycbcr(value[0], value[1], value[2], args.yLower, args.yUpper, args.cLower, args.cUpper); | ||
default: | ||
throw new Error('Unable to determine color type'); | ||
} | ||
} | ||
}; | ||
return Color; | ||
}()); | ||
module.exports = new Color(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.colorTypes = void 0; | ||
var Color_1 = __importDefault(require("./Color")); | ||
exports.default = Color_1.default; | ||
exports.colorTypes = __importStar(require("./Colors")); |
{ | ||
"name": "chromaticity-color-utilities", | ||
"version": "0.3.0-alpha", | ||
"version": "0.4.0-alpha", | ||
"description": "Color utilities for Node.js", | ||
@@ -49,3 +49,5 @@ "main": "dist/main.js", | ||
"devDependencies": { | ||
"@types/chai": "^4.3.0", | ||
"@types/express": "^4.17.11", | ||
"@types/mocha": "^9.1.0", | ||
"@types/node": "^14.14.37", | ||
@@ -52,0 +54,0 @@ "chai": "^4.3.4", |
@@ -13,8 +13,10 @@ # <img src="https://reiniiriarios.github.io/chromaticity-color-utilities/assets/images/chromaticity-icon-01.png" width="26" height="26"> chromaticity-color-utilities | ||
```ts | ||
### Example Usage - JavaScript | ||
```js | ||
const Color = require('chromaticity-color-utilities') | ||
let color1 = Color.from('rgb', [255, 128, 0]).to('hsv') | ||
const color1 = Color.from('rgb', [255, 128, 0]).to('hsv') | ||
let scheme1 = Color.from('hex', 0x9a237f) | ||
const scheme1 = Color.from('hex', 0x9a237f) | ||
.modify('desaturate', { amount: 0.2 }) | ||
@@ -31,2 +33,28 @@ .to('lab', { | ||
### Example Usage - TypeScript | ||
```ts | ||
import Color, { colorTypes } from 'chromaticity-color-utilities' | ||
const color1: colorTypes.hsv = Color.from('rgb', [255, 128, 0]).to('hsv') | ||
const scheme1: colorTypes.lab[] = Color.from('hex', 0x9a237f) | ||
.modify('desaturate', { amount: 0.2 }) | ||
.to('lab', { | ||
colorSpace: 'AdobeRGB', | ||
referenceWhite: 'D50', | ||
}) | ||
.scheme('gradient', { | ||
with: Color.from('hsl', [300, 50, 45]), | ||
colors: 5, | ||
}) | ||
const yourMethod = (rgb: colorTypes.rgb): colorTypes.hsv => { | ||
// do things | ||
let hsv: colorTypes.hsv = rgb.to('hsv') | ||
// do things | ||
return hsv | ||
} | ||
``` | ||
## Install | ||
@@ -46,3 +74,3 @@ | ||
## Example Usage | ||
## More Example Usage | ||
@@ -141,1 +169,3 @@ See [documentation](https://reiniiriarios.github.io/chromaticity-color-utilities) for more details and usage examples. | ||
- Integrate my references better. :) | ||
- Validate YIQ | ||
- For RGBA to CMYK, mix alpha with white |
@@ -70,3 +70,5 @@ { | ||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ | ||
} | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["test/**/*"], | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
267180
6307
168
8
22