colorjs.io
Advanced tools
Comparing version 0.4.1 to 0.4.2
{ | ||
"name": "colorjs.io", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Let’s get serious about color", | ||
@@ -48,2 +48,3 @@ "files": [ | ||
"dtslint": "dtslint types", | ||
"lint": "eslint . --fix --ext .js --ext .ts --ext .js --ext .cjs", | ||
"build:css": "npx postcss \"**/*.postcss\" --base . --dir . --ext .css --config postcss.config.cjs", | ||
@@ -57,3 +58,4 @@ "build:html": "npx @11ty/eleventy --config=.eleventy.cjs", | ||
"watch:js": "rollup -c --watch", | ||
"watch": "npm run watch:css & npm run watch:html & npm run watch:js" | ||
"watch": "npm run watch:css & npm run watch:html & npm run watch:js", | ||
"prepack": "npm run build" | ||
}, | ||
@@ -60,0 +62,0 @@ "repository": { |
import hooks from "./hooks.js"; | ||
import {multiplyMatrices} from "./util.js" | ||
import {multiplyMatrices} from "./util.js"; | ||
@@ -8,5 +8,5 @@ export const WHITES = { | ||
D65: [0.3127 / 0.3290, 1.00000, (1.0 - 0.3127 - 0.3290) / 0.3290], | ||
} | ||
}; | ||
export function getWhite(name) { | ||
export function getWhite (name) { | ||
if (Array.isArray(name)) { | ||
@@ -13,0 +13,0 @@ return name; |
@@ -17,3 +17,3 @@ import xyz_d65 from "./spaces/xyz-d65.js"; | ||
export function register(Color) { | ||
export function register (Color) { | ||
// no setters, as lightness information is lost | ||
@@ -20,0 +20,0 @@ // when converting color to chromaticity |
@@ -1,2 +0,2 @@ | ||
export default function clone(color) { | ||
export default function clone (color) { | ||
return { | ||
@@ -7,2 +7,2 @@ space: color.space, | ||
}; | ||
} | ||
} |
@@ -78,9 +78,9 @@ import * as util from "./util.js"; | ||
#space | ||
#space; | ||
get space() { | ||
get space () { | ||
return this.#space; | ||
} | ||
get spaceId() { | ||
get spaceId () { | ||
return this.#space.id; | ||
@@ -123,6 +123,2 @@ } | ||
static defineFunction (name, code, o = code) { | ||
if (arguments.length === 1) { | ||
[name, code, o] = [arguments[0].name, arguments[0], arguments[0]]; | ||
} | ||
let {instance = true, returns} = o; | ||
@@ -138,6 +134,6 @@ | ||
let f = ret; | ||
ret = function(...args) { | ||
ret = function (...args) { | ||
let ret = f(...args); | ||
return Color.get(ret); | ||
} | ||
}; | ||
// Copy any function metadata | ||
@@ -151,3 +147,3 @@ Object.assign(ret, f); | ||
return ret; | ||
} | ||
}; | ||
@@ -161,7 +157,7 @@ if (!(name in Color)) { | ||
return func(this, ...args); | ||
} | ||
}; | ||
} | ||
} | ||
static defineFunctions(o) { | ||
static defineFunctions (o) { | ||
for (let name in o) { | ||
@@ -176,8 +172,2 @@ Color.defineFunction(name, o[name], o[name]); | ||
} | ||
else if (exports.default) { | ||
Color.defineFunction(exports.default.name, exports.default); | ||
} | ||
else if (typeof exports === "function") { | ||
Color.defineFunction(exports); | ||
} | ||
else { | ||
@@ -216,3 +206,1 @@ // No register method, just add the module's functions | ||
}); | ||
@@ -28,2 +28,2 @@ import getColor from "./getColor.js"; | ||
throw new TypeError(`Unknown contrast algorithm: ${algorithm}`); | ||
}; | ||
}; |
@@ -28,3 +28,5 @@ // APCA 0.0.98G | ||
function fclamp (Y) { | ||
if (Y >= blkThrs) return Y; | ||
if (Y >= blkThrs) { | ||
return Y; | ||
} | ||
return Y + (blkThrs - Y) ** blkClmp; | ||
@@ -51,3 +53,3 @@ } | ||
foreground = to(foreground, 'srgb'); | ||
foreground = to(foreground, "srgb"); | ||
// Should these be clamped to in-gamut values? | ||
@@ -60,3 +62,3 @@ | ||
background = to(background, 'srgb'); | ||
background = to(background, "srgb"); | ||
[R, G, B] = background.coords; | ||
@@ -83,3 +85,4 @@ let lumBg = linearize(R) * 0.2126729 + linearize(G) * 0.7151522 + linearize(B) * 0.0721750; | ||
C = S * scaleBoW; | ||
} else { | ||
} | ||
else { | ||
// light text on dark background | ||
@@ -103,2 +106,2 @@ S = Ybg ** revBG - Ytxt ** revTXT; | ||
return Sapc * 100; | ||
} | ||
} |
@@ -20,3 +20,3 @@ // Delta Phi Star perceptual lightness contrast | ||
let deltaPhiStar = Math.abs(Math.pow(Lstr1,phi) - Math.pow(Lstr2,phi)); | ||
let deltaPhiStar = Math.abs(Math.pow(Lstr1, phi) - Math.pow(Lstr2, phi)); | ||
@@ -23,0 +23,0 @@ let contrast = Math.pow(deltaPhiStar, (1 / phi)) * Math.SQRT2 - 40; |
@@ -22,2 +22,2 @@ // Michelson luminance contrast | ||
return denom === 0 ? 0 : (Y1 - Y2) / denom; | ||
}; | ||
}; |
@@ -20,2 +20,2 @@ // WCAG 2.0 contrast https://www.w3.org/TR/WCAG20-TECHS/G18.html | ||
return (Y1 + .05) / (Y2 + .05); | ||
}; | ||
}; |
@@ -8,2 +8,2 @@ // Global defaults one may want to configure | ||
deltaE: "76", // Default deltaE method | ||
} | ||
}; |
@@ -23,2 +23,2 @@ import getColor from "./getColor.js"; | ||
throw new TypeError(`Unknown deltaE method: ${method}`); | ||
}; | ||
}; |
@@ -166,2 +166,2 @@ import lab from "../spaces/lab.js"; | ||
// Yay!!! | ||
}; | ||
}; |
@@ -5,2 +5,2 @@ import distance from "../distance.js"; | ||
return distance(color, sample, "lab"); | ||
}; | ||
}; |
@@ -111,2 +111,2 @@ import lab from "../spaces/lab.js"; | ||
// Yay!!! | ||
}; | ||
}; |
@@ -21,2 +21,2 @@ import ictcp from "../spaces/ictcp.js"; | ||
return 720 * Math.sqrt((I1 - I2) ** 2 + (0.25 * (T1 -T2) ** 2) + (P1 - P2) ** 2); | ||
}; | ||
}; |
@@ -27,8 +27,8 @@ import jzczhz from "../spaces/jzczhz.js"; | ||
Hz2 = 0; | ||
} else | ||
if (Number.isNaN(Hz1)) { | ||
} | ||
else if (Number.isNaN(Hz1)) { | ||
// one undefined, set to the defined hue | ||
Hz1 = Hz2; | ||
} else | ||
if (Number.isNaN(Hz2)) { | ||
} | ||
else if (Number.isNaN(Hz2)) { | ||
Hz2 = Hz1; | ||
@@ -41,2 +41,2 @@ } | ||
return Math.sqrt(ΔJ ** 2 + ΔC ** 2 + ΔH ** 2); | ||
}; | ||
}; |
@@ -6,2 +6,2 @@ export {default as deltaE76} from "./deltaE76.js"; | ||
export {default as deltaEITP} from "./deltaEITP.js"; | ||
export {default as deltaEOK} from "./deltaEOK.js"; | ||
export {default as deltaEOK} from "./deltaEOK.js"; |
@@ -60,2 +60,2 @@ import * as util from "./util.js"; | ||
return ret; | ||
} | ||
} |
@@ -6,3 +6,3 @@ import ColorSpace from "./space.js"; | ||
*/ | ||
export default function distance(color1, color2, space = "lab") { | ||
export default function distance (color1, color2, space = "lab") { | ||
space = ColorSpace.get(space); | ||
@@ -21,2 +21,2 @@ | ||
}, 0)); | ||
} | ||
} |
@@ -10,2 +10,2 @@ import getColor from "./getColor.js"; | ||
&& color1.coords.every((c, i) => c === color2.coords[i]); | ||
} | ||
} |
@@ -8,2 +8,2 @@ import ColorSpace from "./space.js"; | ||
return coords[index]; | ||
} | ||
} |
@@ -12,2 +12,2 @@ import ColorSpace from "./space.js"; | ||
return space.from(color); | ||
} | ||
} |
@@ -32,2 +32,2 @@ import ColorSpace from "./space.js"; | ||
return color; | ||
} | ||
} |
@@ -15,3 +15,3 @@ /** | ||
(Array.isArray(name)? name : [name]).forEach(function(name) { | ||
(Array.isArray(name)? name : [name]).forEach(function (name) { | ||
this[name] = this[name] || []; | ||
@@ -27,3 +27,3 @@ | ||
this[name] = this[name] || []; | ||
this[name].forEach(function(callback) { | ||
this[name].forEach(function (callback) { | ||
callback.call(env && env.context? env.context : env, env); | ||
@@ -39,2 +39,2 @@ }); | ||
export default hooks; | ||
export default hooks; |
@@ -24,2 +24,3 @@ export {default as ColorSpace} from "./space.js"; | ||
export {uv, xy} from "./chromaticity.js"; | ||
export * from "./contrast/index.js"; | ||
export {default as deltaE} from "./deltaE.js"; | ||
@@ -26,0 +27,0 @@ export * from "./deltaE/index.js"; |
@@ -8,7 +8,7 @@ // Import all modules of Color.js | ||
// Import all DeltaE methods | ||
import * as deltaE from "./deltaE.js"; | ||
import deltaE from "./deltaE.js"; | ||
import * as deltaEMethods from "./deltaE/index.js"; | ||
Color.extend(deltaEMethods); | ||
Color.extend(deltaE); | ||
Color.extend({deltaE}); | ||
@@ -20,3 +20,3 @@ // Import optional modules | ||
import contrast from "./contrast.js"; | ||
Color.extend(contrast); | ||
Color.extend({contrast}); | ||
@@ -23,0 +23,0 @@ import * as chromaticity from "./chromaticity.js"; |
@@ -20,2 +20,2 @@ import ColorSpace from "./space.js"; | ||
return space.inGamut(coords, {epsilon}); | ||
} | ||
} |
@@ -212,3 +212,3 @@ /** | ||
export function register(Color) { | ||
export function register (Color) { | ||
Color.defineFunction("mix", mix, {returns: "color"}); | ||
@@ -218,2 +218,1 @@ Color.defineFunction("range", range, {returns: "function<color>"}); | ||
} | ||
@@ -7,11 +7,11 @@ /** | ||
export function getLuminance(color) { | ||
export function getLuminance (color) { | ||
return get(color, [xyz_d65, "y"]); | ||
} | ||
export function setLuminance(color) { | ||
export function setLuminance (color) { | ||
set(color, [xyz_d65, "y"], value); | ||
} | ||
export function register(Color) { | ||
export function register (Color) { | ||
Object.defineProperty(Color.prototype, "luminance", { | ||
@@ -25,2 +25,2 @@ get () { | ||
}); | ||
} | ||
} |
// A is m x n. B is n x p. product is m x p. | ||
export default function multiplyMatrices(A, B) { | ||
export default function multiplyMatrices (A, B) { | ||
let m = A.length; | ||
@@ -4,0 +4,0 @@ |
@@ -134,2 +134,2 @@ import * as util from "./util.js"; | ||
throw new TypeError(`Could not parse ${str} as a color. Missing a plugin?`); | ||
} | ||
} |
@@ -80,3 +80,3 @@ import * as util from "./util.js"; | ||
let strAlpha = color.alpha < 1? ` ${format.commas? "," : "/"} ${alpha}` : ""; | ||
let strAlpha = color.alpha < 1 && !format.noAlpha? `${format.commas? "," : " /"} ${alpha}` : ""; | ||
ret = `${name}(${args.join(format.commas? ", " : " ")}${strAlpha})`; | ||
@@ -86,2 +86,2 @@ } | ||
return ret; | ||
} | ||
} |
@@ -31,2 +31,2 @@ import ColorSpace from "./space.js"; | ||
return color; | ||
} | ||
} |
@@ -7,2 +7,2 @@ import ColorSpace from "./space.js"; | ||
return color; | ||
} | ||
} |
@@ -44,3 +44,3 @@ /** | ||
} | ||
catch(e) {} | ||
catch (e) {} | ||
@@ -87,2 +87,2 @@ return Reflect.has(obj, property); | ||
}); | ||
} | ||
} |
@@ -91,3 +91,3 @@ import {type, parseCoordGrammar, toPrecision, mapRange} from "./util.js"; | ||
get isPolar() { | ||
get isPolar () { | ||
for (let id in this.coords) { | ||
@@ -102,3 +102,3 @@ if (this.coords[id].type === "angle") { | ||
#processFormat(format) { | ||
#processFormat (format) { | ||
if (format.coords && !format.coordGrammar) { | ||
@@ -145,3 +145,3 @@ format.type ||= "function"; | ||
return c; | ||
}) | ||
}); | ||
}; | ||
@@ -176,3 +176,3 @@ } | ||
#path | ||
#path; | ||
@@ -264,3 +264,3 @@ #getPath () { | ||
static registry = {} | ||
static registry = {}; | ||
@@ -372,3 +372,3 @@ // Returns array of unique color spaces | ||
if (meta) { | ||
return {space, id: meta[0], index: coord, ...meta[1]} | ||
return {space, id: meta[0], index: coord, ...meta[1]}; | ||
} | ||
@@ -398,3 +398,3 @@ } | ||
name: "color", | ||
} | ||
}; | ||
} |
@@ -19,3 +19,3 @@ import RGBColorSpace from "../rgbspace.js"; | ||
[ 0.013444280632031142, -0.11836239223101838, 1.0151749943912054 ] | ||
] | ||
]; | ||
@@ -22,0 +22,0 @@ export default new RGBColorSpace({ |
@@ -60,3 +60,3 @@ import ColorSpace from "../space.js"; | ||
function f(n) { | ||
function f (n) { | ||
let k = (n + h/30) % 12; | ||
@@ -63,0 +63,0 @@ let a = s * Math.min(l, 1 - l); |
@@ -23,2 +23,2 @@ export {default as XYZ_D65} from "./xyz-d65.js"; | ||
export * from './index-fn-hdr.js'; | ||
export * from "./index-fn-hdr.js"; |
@@ -95,3 +95,3 @@ import ColorSpace from "../space.js"; | ||
// convert from PQ-coded to linear-light | ||
let LMS = PQLMS.map(function (val){ | ||
let LMS = PQLMS.map(function (val) { | ||
let num = (c1 - (val ** pinv)); | ||
@@ -118,2 +118,1 @@ let denom = (c3 * (val ** pinv)) - c2; | ||
}); | ||
@@ -17,3 +17,3 @@ import ColorSpace from "../space.js"; | ||
[ -0.07637294974672142, -0.4214933239627914, 1.5869240244272418 ] | ||
] | ||
]; | ||
const LMStoLab_M = [ | ||
@@ -20,0 +20,0 @@ [ 0.2104542553, 0.7936177850, -0.0040720468 ], |
@@ -69,2 +69,1 @@ import ColorSpace from "../space.js"; | ||
}); | ||
@@ -13,3 +13,3 @@ import RGBColorSpace from "../rgbspace.js"; | ||
[ 0.03584583024378447, -0.07617238926804182, 0.9568845240076872] | ||
] | ||
]; | ||
@@ -16,0 +16,0 @@ export default new RGBColorSpace({ |
@@ -17,3 +17,3 @@ import RGBColorSpace from "../rgbspace.js"; | ||
[ 0.0, 0.0, 1.2119675456389454 ] | ||
] | ||
]; | ||
@@ -20,0 +20,0 @@ export default new RGBColorSpace({ |
@@ -11,7 +11,7 @@ import RGBColorSpace from "../rgbspace.js"; | ||
base: ProPhotoLinear, | ||
toBase(RGB) { | ||
toBase (RGB) { | ||
// Transfer curve is gamma 1.8 with a small linear portion | ||
return RGB.map(v => v < Et2? v / 16 : v ** 1.8); | ||
}, | ||
fromBase(RGB) { | ||
fromBase (RGB) { | ||
return RGB.map(v => v >= Et? v ** (1/1.8) : 16 * v); | ||
@@ -18,0 +18,0 @@ }, |
@@ -18,3 +18,3 @@ import RGBColorSpace from "../rgbspace.js"; | ||
[ 0.017639857445311, -0.042770613257809, 0.942103121235474 ] | ||
] | ||
]; | ||
@@ -21,0 +21,0 @@ export default new RGBColorSpace({ |
@@ -6,2 +6,3 @@ import RGBColorSpace from "../rgbspace.js"; | ||
let coordGrammar = Array(3).fill("<percentage> | <number>[0, 255]"); | ||
let coordGrammarNumber = Array(3).fill("<number>[0, 255]"); | ||
@@ -46,2 +47,8 @@ export default new RGBColorSpace({ | ||
}, | ||
"rgb_number": { | ||
name: "rgb", | ||
commas: true, | ||
coords: coordGrammarNumber, | ||
noAlpha: true, | ||
}, | ||
"color": { /* use defaults */ }, | ||
@@ -53,2 +60,7 @@ "rgba": { | ||
}, | ||
"rgba_number": { | ||
name: "rgba", | ||
commas: true, | ||
coords: coordGrammarNumber | ||
}, | ||
"hex": { | ||
@@ -55,0 +67,0 @@ type: "custom", |
@@ -14,6 +14,6 @@ import ColorSpace from "../space.js"; | ||
color: { | ||
ids: ['xyz-d65', 'xyz'], | ||
ids: ["xyz-d65", "xyz"], | ||
} | ||
}, | ||
aliases: ['xyz'], | ||
aliases: ["xyz"], | ||
}); |
@@ -26,2 +26,2 @@ import getColor from "./getColor.js"; | ||
to.returns = "color"; | ||
to.returns = "color"; |
@@ -105,2 +105,2 @@ import * as util from "./util.js"; | ||
toGamut.returns = "color"; | ||
toGamut.returns = "color"; |
@@ -32,3 +32,3 @@ /** | ||
*/ | ||
export function toPrecision(n, precision) { | ||
export function toPrecision (n, precision) { | ||
n = +n; | ||
@@ -105,3 +105,3 @@ precision = +precision; | ||
export function last(arr) { | ||
export function last (arr) { | ||
return arr[arr.length - 1]; | ||
@@ -126,3 +126,3 @@ } | ||
export function mapRange(from, to, value) { | ||
export function mapRange (from, to, value) { | ||
return interpolate(to[0], to[1], interpolateInv(from[0], from[1], value)); | ||
@@ -146,2 +146,2 @@ } | ||
}); | ||
} | ||
} |
@@ -14,2 +14,2 @@ import ColorSpace from "./space.js"; | ||
return set(color, lightness, l => l * (1 - amount)); | ||
} | ||
} |
@@ -93,3 +93,2 @@ import { WHITES } from "./adapt"; | ||
static defineFunction(code: DefineFunctionHybrid): void; | ||
static defineFunction(name: string, code: DefineFunctionHybrid): void; | ||
@@ -106,5 +105,3 @@ static defineFunction( | ||
exports: | ||
| DefineFunctionHybrid | ||
| { register: (color: typeof Color) => void } | ||
| { default: DefineFunctionHybrid } | ||
| Record<string, DefineFunctionHybrid> | ||
@@ -154,2 +151,3 @@ ): void; | ||
lab: SpaceAccessor; | ||
lab_d65: SpaceAccessor; | ||
lch: SpaceAccessor; | ||
@@ -156,0 +154,0 @@ oklab: SpaceAccessor; |
@@ -10,1 +10,2 @@ export type Algorithms = keyof typeof import(".") extends `contrast${infer Alg}` | ||
export { default as contrastLstar } from "./Lstar"; | ||
export { default as contrastDeltaPhi } from "./deltaPhi"; |
@@ -25,4 +25,5 @@ export { default as ColorSpace } from "./space"; | ||
export * from "./contrast/index"; | ||
export * from "./deltaE/index"; | ||
export * from "./variations"; | ||
export * from "./spaces/index-fn"; |
@@ -10,2 +10,3 @@ import { uv, xy } from "../src/chromaticity"; | ||
contrastLstar, | ||
contrastDeltaPhi, | ||
} from "../src/contrast/index"; | ||
@@ -35,2 +36,3 @@ import deltaE from "../src/deltaE"; | ||
contrastLstar, | ||
contrastDeltaPhi, | ||
}; | ||
@@ -67,2 +69,3 @@ // deltaE | ||
contrastLstar: ToColorPrototype<typeof contrastLstar>; | ||
contrastDeltaPhi: ToColorPrototype<typeof contrastDeltaPhi>; | ||
@@ -69,0 +72,0 @@ // deltaE |
@@ -27,2 +27,3 @@ import Color, { ColorTypes } from "./color"; | ||
outputSpace?: string | ColorSpace | undefined; | ||
premultiplied?: boolean | undefined; | ||
} | ||
@@ -29,0 +30,0 @@ |
import { ColorTypes } from "./color"; | ||
import { Format } from "./space"; | ||
export interface Options { | ||
precision?: number | undefined; | ||
format?: string | undefined; | ||
format?: string | Format | undefined; | ||
inGamut?: boolean | undefined; | ||
@@ -7,0 +8,0 @@ } |
@@ -16,2 +16,3 @@ import { White } from "./adapt"; | ||
lastAlpha?: boolean | undefined; | ||
noAlpha?: boolean | undefined; | ||
test?: ((str: string) => boolean) | undefined; | ||
@@ -18,0 +19,0 @@ parse?: ((str: string) => ColorConstructor) | undefined; |
@@ -7,2 +7,3 @@ export type Spaces = keyof typeof import("./index-fn"); | ||
export { default as Lab } from "./lab"; | ||
export { default as Lab_D65 } from "./lab-d65"; | ||
export { default as LCH } from "./lch"; | ||
@@ -9,0 +10,0 @@ export { default as sRGB_Linear } from "./srgb-linear"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
1895689
172
20830