Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

colorjs.io

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colorjs.io - npm Package Compare versions

Comparing version
0.4.0
to
0.4.1-patch.1
dist/color.legacy.cjs

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

+25
// Delta Phi Star perceptual lightness contrast
// See https://github.com/Myndex/deltaphistar
// The (difference between two Lstars each raised to phi) raised to (1/phi)
// Symmetric, does not matter which is foreground and which is background
import getColor from "../getColor.js";
import get from "../get.js";
import lab_d65 from "../spaces/lab-d65.js";
const phi = Math.pow(5, 0.5) * 0.5 + 0.5; // Math.phi can be used if Math.js
export default function contrastDeltaPhi (color1, color2) {
color1 = getColor(color1);
color2 = getColor(color2);
let Lstr1 = get(color1, [lab_d65, "l"]);
let Lstr2 = get(color2, [lab_d65, "l"]);
let deltaPhiStar = Math.abs(Math.pow(Lstr1,phi) - Math.pow(Lstr2,phi));
let contrast = Math.pow(deltaPhiStar, (1 / phi)) * Math.SQRT2 - 40;
return (contrast < 7.5) ? 0.0 : contrast ;
};
import ColorSpace from "../space.js";
import {WHITES} from "../adapt.js";
import xyz_d65 from "./xyz-d65.js";
// κ * ε = 2^3 = 8
const ε = 216/24389; // 6^3/29^3 == (24/116)^3
const ε3 = 24/116;
const κ = 24389/27; // 29^3/3^3
let white = WHITES.D65;
export default new ColorSpace({
id: "lab-d65",
name: "Lab D65",
coords: {
l: {
refRange: [0, 100],
name: "L"
},
a: {
refRange: [-125, 125]
},
b: {
refRange: [-125, 125]
}
},
// Assuming XYZ is relative to D65, convert to CIE Lab
// from CIE standard, which now defines these as a rational fraction
white,
base: xyz_d65,
// Convert D65-adapted XYZ to Lab
// CIE 15.3:2004 section 8.2.1.1
fromBase (XYZ) {
// compute xyz, which is XYZ scaled relative to reference white
let xyz = XYZ.map((value, i) => value / white[i]);
// now compute f
let f = xyz.map(value => value > ε ? Math.cbrt(value) : (κ * value + 16)/116);
return [
(116 * f[1]) - 16, // L
500 * (f[0] - f[1]), // a
200 * (f[1] - f[2]) // b
];
},
// Convert Lab to D65-adapted XYZ
// Same result as CIE 15.3:2004 Appendix D although the derivation is different
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
toBase (Lab) {
// compute f, starting with the luminance-related term
let f = [];
f[1] = (Lab[0] + 16)/116;
f[0] = Lab[1]/500 + f[1];
f[2] = f[1] - Lab[2]/200;
// compute xyz
let xyz = [
f[0] > ε3 ? Math.pow(f[0], 3) : (116*f[0]-16)/κ,
Lab[0] > 8 ? Math.pow((Lab[0]+16)/116, 3) : Lab[0]/κ,
f[2] > ε3 ? Math.pow(f[2], 3) : (116*f[2]-16)/κ
];
// Compute XYZ by scaling xyz by reference white
return xyz.map((value, i) => value * white[i]);
},
formats: {
"lab-d65": {
coords: ["<number> | <percentage>", "<number>", "<number>"],
}
}
});
export { default } from "../src";
// Definitions by: Adam Thompson-Sharpe <https://github.com/MysteryBlokHed>
// Minimum TypeScript Version: 4.1
export { default } from "./dist/color";
export type White = [number, number, number];
export const WHITES: Record<string, White>;
export function getWhite(name: string | White): White;
export default function adapt(
w1: White,
w2: White,
xyz: [number, number, number],
options?: { method?: string | undefined }
): void;
/** Constrain an angle to 360 degrees */
export function constrain(angle: number): number;
export function adjust(
arc: "raw" | "increasing" | "decreasing" | "longer" | "shorter",
angles: [number, number]
): [number, number];
import { White } from "./adapt";
export interface CAT {
id: string;
toCone_M: number[][];
fromCone_M: number[][];
}
export const CATs: Record<string, CAT>;
export function defineCAT(cat: CAT): void;
export function adapt(W1: White, W2: White, id?: string): number[];
import Color, { ColorObject } from "./color";
export function uv(color: Color | ColorObject): [number, number];
export function xy(color: Color | ColorObject): [number, number];
export function register(color: typeof Color): void;
import Color from "./color";
export default function clone(color: Color): Color;
import { WHITES } from "./adapt";
import defaults from "./defaults";
import hooks from "./hooks";
import * as util from "./util";
import ColorSpace from "./space";
import {
to,
parse,
serialize,
inGamut,
toGamut,
distance,
equals,
get,
getAll,
set,
setAll,
display,
} from "./index-fn";
export type Coords = [number, number, number];
export interface ColorObject {
space: ColorSpace;
coords: Coords;
alpha?: number;
}
export interface ColorConstructor {
spaceId: string;
coords: Coords;
alpha: number | undefined;
}
export type ColorTypes = Color | ColorObject | ColorConstructor | string;
export type DefineFunctionCode = (
...args: any[]
) => ColorTypes | ColorTypes[] | ((...args: any[]) => ColorTypes);
export interface DefineFunctionOptions {
instance?: boolean | undefined;
returns?: "color" | "function<color>" | "array<color>" | undefined;
}
export type DefineFunctionHybrid = DefineFunctionCode & DefineFunctionOptions;
/** Remove the first element of an array type */
type RemoveFirstElement<T extends any[]> = T extends [any, ...infer R]
? R
: Array<T[number]>;
/** Convert a function to a prototype for Color */
export type ToColorPrototype<T extends (...args: any[]) => any> = T extends (
color: Color,
...args: infer A
) => infer R
? (...args: A) => R
: never;
/** Proxy used for space accessors */
export type SpaceAccessor = Record<string, number> & number[];
declare namespace Color {
export {
getAll,
set,
setAll,
to,
equals,
inGamut,
toGamut,
distance,
serialize as toString,
};
export { util, hooks, WHITES, ColorSpace as Space, parse, defaults };
export const spaces: typeof ColorSpace["registry"];
}
declare class Color {
constructor(color: ColorTypes);
constructor(space: string | ColorSpace, coords: Coords, alpha: number);
// These signatures should always be the same as the constructor
static get(color: ColorTypes): Color;
static get(
space: string | ColorSpace,
coords: Coords,
alpha: number
): Color;
static defineFunction(code: DefineFunctionHybrid): void;
static defineFunction(name: string, code: DefineFunctionHybrid): void;
static defineFunction(
name: string,
code: DefineFunctionCode,
options: DefineFunctionOptions
): void;
static defineFunctions(objects: Record<string, DefineFunctionHybrid>): void;
static extend(
exports:
| DefineFunctionHybrid
| { register: (color: typeof Color) => void }
| { default: DefineFunctionHybrid }
| Record<string, DefineFunctionHybrid>
): void;
get space(): ColorSpace;
get spaceId(): string;
alpha: number;
coords: Coords;
clone(): this;
// Copy parameter types from display function, except for the first one
display(
...args: RemoveFirstElement<Parameters<typeof display>>
): string & { color: Color };
toJSON(): ColorConstructor;
// Functions defined using Color.defineFunctions
get: ToColorPrototype<typeof get>;
getAll: ToColorPrototype<typeof getAll>;
set: ToColorPrototype<typeof set>;
setAll: ToColorPrototype<typeof setAll>;
to: ToColorPrototype<typeof to>;
equals: ToColorPrototype<typeof equals>;
inGamut: ToColorPrototype<typeof inGamut>;
toGamut: ToColorPrototype<typeof toGamut>;
distance: ToColorPrototype<typeof distance>;
toString: ToColorPrototype<typeof serialize>;
// Space accessors
// A property should technically be added every time a new ColorSpace is initialized,
// but I don't know that there's any good way to do that with TypeScript
a98rgb: SpaceAccessor;
a98rgb_linear: SpaceAccessor;
acescc: SpaceAccessor;
acescg: SpaceAccessor;
hsl: SpaceAccessor;
hsv: SpaceAccessor;
hwb: SpaceAccessor;
ictcp: SpaceAccessor;
jzazbz: SpaceAccessor;
jzczhz: SpaceAccessor;
lab: SpaceAccessor;
lch: SpaceAccessor;
oklab: SpaceAccessor;
oklch: SpaceAccessor;
p3: SpaceAccessor;
p3_linear: SpaceAccessor;
prophoto: SpaceAccessor;
prophoto_linear: SpaceAccessor;
rec2020: SpaceAccessor;
rec2020_linear: SpaceAccessor;
rec2100hlg: SpaceAccessor;
rec2100pq: SpaceAccessor;
srgb: SpaceAccessor;
srgb_linear: SpaceAccessor;
xyz: SpaceAccessor;
xyz_abs_d65: SpaceAccessor;
xyz_d50: SpaceAccessor;
xyz_d65: SpaceAccessor;
}
export default Color;
import { ColorTypes } from "./color";
import { Algorithms } from "./contrast/index";
/**
* @param options Algorithm to use as well as any other options to pass to the contrast function
* @throws {TypeError} Unknown or unspecified algorithm
*/
export default function contrast(
background: ColorTypes,
foreground: ColorTypes,
options: Algorithms | ({ algorithm: Algorithms } & Record<string, any>)
): number;
import { ColorTypes } from "../color";
export default function (
background: ColorTypes,
forgeround: ColorTypes
): number;
export type Algorithms = keyof typeof import(".") extends `contrast${infer Alg}`
? Alg
: string;
export { default as contrastWCAG21 } from "./WCAG21";
export { default as contrastAPCA } from "./APCA";
export { default as contrastMichelson } from "./Michelson";
export { default as contrastWeber } from "./Weber";
export { default as contrastLstar } from "./Lstar";
import { ColorTypes } from "../color";
export default function (
background: ColorTypes,
forgeround: ColorTypes
): number;
import { ColorTypes } from "../color";
export default function (
background: ColorTypes,
forgeround: ColorTypes
): number;
import { ColorTypes } from "../color";
export default function (
background: ColorTypes,
forgeround: ColorTypes
): number;
import { ColorTypes } from "../color";
export default function (
background: ColorTypes,
forgeround: ColorTypes
): number;
declare const _default: Record<string, any>;
export default _default;
import { ColorTypes } from "./color";
import { Methods } from "./deltaE/index";
/**
* @param options deltaE method to use as well as any other options to pass to the deltaE function
* @throws {TypeError} Unknown or unspecified method
*/
export default function deltaE(
color1: ColorTypes,
color2: ColorTypes,
options: Methods | ({ method: Methods } & Record<string, any>)
): number;
import Color, { ColorObject } from "../color";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject,
options?: {
kL?: number | undefined;
kC?: number | undefined;
kH?: number | undefined;
}
): number;
import Color, { ColorObject } from "../color";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject
): number;
import Color, { ColorObject } from "../color";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject,
options?: {
l?: number | undefined;
c?: number | undefined;
}
): number;
import Color, { ColorObject } from "../color";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject
): number;
import Color, { ColorObject } from "../color";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject
): number;
import Color, { ColorObject } from "../color";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject
): number;
export type Methods = keyof typeof import(".") extends `deltaE${infer Method}`
? Method
: string;
export { default as deltaE76 } from "./deltaE76";
export { default as deltaECMC } from "./deltaECMC";
export { default as deltaE2000 } from "./deltaE2000";
export { default as deltaEJz } from "./deltaEJz";
export { default as deltaEITP } from "./deltaEITP";
export { default as deltaEOK } from "./deltaEOK";
import Color, { ColorObject, ColorTypes } from "./color";
import ColorSpace from "./space";
export type Display = string & { color: ColorObject };
export default function display(
color: ColorTypes,
options?: {
space?: string | ColorSpace | undefined;
} & Record<string, any>
): Display;
import Color, { ColorObject } from "./color";
import ColorSpace from "./space";
export default function distance(
color1: Color | ColorObject,
color2: Color | ColorObject,
space?: string | ColorSpace
): number;
import { ColorTypes } from "./color";
export default function equals(color1: ColorTypes, color2: ColorTypes): boolean;
import Color, { ColorObject } from "./color";
import { Ref } from "./space";
export default function get(color: Color | ColorObject, prop: Ref): number;
import Color, { ColorObject } from "./color";
import ColorSpace from "./space";
export default function getAll(
color: Color | ColorObject,
space: string | ColorSpace
): [number, number, number];
import { ColorObject, ColorTypes } from "./color";
export default function getColor(color: ColorTypes): ColorObject;
export class Hooks {
// Can't find a way to type this more specifically
// without conflicting with the types of add and run
[name: string]: any;
add(
name: string | string[],
callback: (env: Record<string, any>) => void,
first?: boolean
): void;
run(name: string, env?: { context?: Record<string, any> }): void;
}
declare const hooks: Hooks;
export default hooks;
export { default as ColorSpace } from "./space";
export { default as RGBColorSpace } from "./rgbspace";
export { default as hooks, Hooks } from "./hooks";
export { default as defaults } from "./defaults";
export { default as getColor } from "./getColor";
export { default as get } from "./get";
export { default as getAll } from "./getAll";
export { default as set } from "./set";
export { default as setAll } from "./setAll";
export { default as parse } from "./parse";
export { default as to } from "./to";
export { default as serialize } from "./serialize";
export { default as display } from "./display";
export { default as inGamut } from "./inGamut";
export { default as toGamut } from "./toGamut";
export { default as distance } from "./distance";
export { default as equals } from "./equals";
export { default as contrast } from "./contrast";
export { default as clone } from "./clone";
export { getLuminance, setLuminance } from "./luminance";
export { uv, xy } from "./chromaticity";
export { default as deltaE } from "./deltaE";
export { mix, steps, range, isRange } from "./interpolation";
export * from "./deltaE/index";
export * from "./variations";
export * from "./spaces/index-fn";
import { uv, xy } from "../src/chromaticity";
import ColorImport, { ToColorPrototype } from "../src/color";
import contrast from "../src/contrast";
import {
contrastWCAG21,
contrastAPCA,
contrastMichelson,
contrastWeber,
contrastLstar,
} from "../src/contrast/index";
import deltaE from "../src/deltaE";
import {
deltaE76,
deltaECMC,
deltaE2000,
deltaEJz,
deltaEITP,
deltaEOK,
} from "../src/deltaE/index";
import { mix, range, steps } from "../src/interpolation";
import { getLuminance } from "../src/luminance";
import { lighten, darken } from "../src/variations";
declare namespace Color {
// contrast
export { contrast };
// contrastMethods
export {
contrastWCAG21,
contrastAPCA,
contrastMichelson,
contrastWeber,
contrastLstar,
};
// deltaE
export {
deltaE,
deltaE76,
deltaECMC,
deltaE2000,
deltaEJz,
deltaEITP,
deltaEOK,
};
// interpolation
export { mix, range, steps };
// variations
export { lighten, darken };
}
declare class Color extends ColorImport {
// chromaticity
uv: ToColorPrototype<typeof uv>;
xy: ToColorPrototype<typeof xy>;
// contrast
contrast: ToColorPrototype<typeof contrast>;
// contrastMethods
contrastWCAG21: ToColorPrototype<typeof contrastWCAG21>;
contrastAPCA: ToColorPrototype<typeof contrastAPCA>;
contrastMichelson: ToColorPrototype<typeof contrastMichelson>;
contrastWeber: ToColorPrototype<typeof contrastWeber>;
contrastLstar: ToColorPrototype<typeof contrastLstar>;
// deltaE
deltaE: ToColorPrototype<typeof deltaE>;
deltaE76: ToColorPrototype<typeof deltaE76>;
deltaECMC: ToColorPrototype<typeof deltaECMC>;
deltaE2000: ToColorPrototype<typeof deltaE2000>;
deltaEJz: ToColorPrototype<typeof deltaEJz>;
deltaEITP: ToColorPrototype<typeof deltaEITP>;
deltaEOK: ToColorPrototype<typeof deltaEOK>;
// interpolation
mix: ToColorPrototype<typeof mix>;
range: ToColorPrototype<typeof range>;
steps: ToColorPrototype<typeof steps>;
// luminance
get luminance(): ReturnType<typeof getLuminance>;
// the definition for this set in the orignial code like it doesn't actually use the parameter?
set luminance(_: number);
// variations
lighten: ToColorPrototype<typeof lighten>;
darken: ToColorPrototype<typeof darken>;
}
export default Color;
import { ColorTypes } from "./color";
import ColorSpace from "./space";
export default function inGamut(
color: ColorTypes,
space?: string | ColorSpace,
options?: { epsilon?: number | undefined }
): boolean;
import Color, { ColorTypes } from "./color";
import ColorSpace from "./space";
export type Range = ((percentage: number) => number) & {
rangeArgs: { colors: [Color, Color]; options: Record<string, any> };
};
export function isRange(val: any): val is Range;
export interface RangeOptions {
space?: string | ColorSpace | undefined;
outputSpace?: string | ColorSpace | undefined;
progression?: ((percentage: number) => number) | undefined;
premultiplied?: boolean | undefined;
}
export function range(range: Range, options?: RangeOptions): Range;
export function range(
color1: ColorTypes,
color2: ColorTypes,
options?: RangeOptions & Record<string, any>
): Range;
export interface MixOptions {
space?: string | ColorSpace | undefined;
outputSpace?: string | ColorSpace | undefined;
}
export function mix(
color1: ColorTypes,
color2: ColorTypes,
options?: MixOptions
): number;
export function mix(
color1: ColorTypes,
color2: ColorTypes,
p: number,
options?: MixOptions
): number;
export function steps(color1: ColorTypes | Range, color2: ColorTypes): Color[];
export function register(color: typeof Color): void;
declare const _default: Record<string, [number, number, number]>;
export default _default;
import Color, { ColorObject } from "./color";
export function getLuminance(color: Color | ColorObject): number;
export function setLuminance(color: Color | ColorObject): void;
export function register(color: typeof Color): void;
/**
* @param a m x n
* @param b n x p
* @returns m x p
*/
export default function multiplyMatrices(
a: number[] | number[][],
b: number[] | number[][]
): number[];
import { ColorConstructor } from "./color";
export default function parse(str: string): ColorConstructor;
import ColorSpace, { Options } from "./space";
export interface RGBOptions extends Options {
toXYZ_M?: number[][] | undefined;
fromXYZ_M?: number[][] | undefined;
}
export default class RGBColorSpace extends ColorSpace {
constructor(options: RGBOptions);
}
import { ColorTypes } from "./color";
export interface Options {
precision?: number | undefined;
format?: string | undefined;
inGamut?: boolean | undefined;
}
export default function serialize(
color: ColorTypes,
options?: Options & Record<string, any>
): string;
import Color, { ColorTypes } from "./color";
import { Ref } from "./space";
export default function set(
color: ColorTypes,
prop: Ref,
value: number | ((coord: number) => number)
): Color;
import Color, { ColorObject } from "./color";
import ColorSpace from "./space";
export default function setAll<T extends Color | ColorObject>(
color: T,
space: string | ColorSpace,
coords: [number, number, number]
): T;
import { White } from "./adapt";
import Color, { ColorConstructor, ColorObject, Coords } from "./color";
export interface Format {
type?: string | undefined;
name?: string | undefined;
id?: string | undefined;
coords?: string[] | undefined;
coordGrammar?: Array<string & { range?: [number, number] }> | undefined;
serializeCoords?:
| ((coords: Coords, precision: number) => [string, string, string])
| undefined;
toGamut?: boolean | undefined;
commas?: boolean | undefined;
lastAlpha?: boolean | undefined;
test?: ((str: string) => boolean) | undefined;
parse?: ((str: string) => ColorConstructor) | undefined;
serialize?: ((coords: Coords, alpha: number, opts?: Record<string, any>) => string) | undefined;
}
export interface CoordMeta {
name?: string | undefined;
type?: string | undefined;
range?: [number, number] | undefined;
refRange?: [number, number] | undefined;
}
export interface Options {
id: string;
name: string;
base?: string | ColorSpace | null | undefined;
fromBase?: ((coords: Coords) => number[]) | undefined;
toBase?: ((coords: Coords) => number[]) | undefined;
coords?: Record<string, CoordMeta> | undefined;
white?: string | White | undefined;
cssId?: string | undefined;
referred?: string | undefined;
formats?: Record<string, Format> | undefined;
}
export type Ref =
| string
| [string | ColorSpace, string]
| { space: string | ColorSpace; coordId: string };
export default class ColorSpace {
constructor(options: Options);
static DEFAULT_FORMAT: { type: "functions"; name: "color" };
/**
* @throws {TypeError} If no matching color space is found
*/
static get(
space: ColorSpace | string,
...alternatives: Array<ColorSpace | string>
): ColorSpace;
/**
* @throws {TypeError} If no space or an unknown space is provided
*/
static resolveCoord(
ref: Ref,
workingSpace?: string | ColorSpace
): CoordMeta & {
id: string;
index: string | number;
space: ColorSpace;
};
/**
* @throws {TypeError} If a space with the provided id already exists
*/
static register(space: ColorSpace): ColorSpace;
static register(id: string, space: ColorSpace): ColorSpace;
static registry: Record<string, ColorSpace>;
get all(): Set<ColorSpace>;
get cssId(): string;
get isPolar(): boolean;
name: string;
id: string;
aliases?: string[] | undefined;
base: ColorSpace | null;
coords: Record<string, CoordMeta>;
fromBase?: ((coords: Coords) => number[]) | undefined;
toBase?: ((coords: Coords) => number[]) | undefined;
formats: Record<string, Format>;
referred?: string | undefined;
white: White;
from(color: Color | ColorObject): Coords;
from(space: string | ColorSpace, coords: Coords): Coords;
getFormat(format?: string | Format): Format | null;
getMinCoords(): Coords;
inGamut(coords: Coords, options?: { epsilon?: number }): boolean;
to(color: Color | ColorObject): Coords;
to(space: string | ColorSpace, coords: Coords): Coords;
toString(): string;
}
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
export type HDRSpaces = keyof typeof import("./index-fn-hdr");
export { default as Jzazbz } from "./jzazbz";
export { default as JzCzHz } from "./jzczhz";
export { default as ICTCP } from "./ictcp";
export { default as REC_2100_PQ } from "./rec2100-pq";
export { default as REC_2100_HLG } from "./rec2100-hlg";
export { default as ACEScg } from "./acescg";
export { default as ACEScc } from "./acescc";
export type Spaces = keyof typeof import("./index-fn");
export { default as XYZ_D65 } from "./xyz-d65";
export { default as XYZ_D50 } from "./xyz-d50";
export { default as XYZ_ABS_D65 } from "./xyz-abs-d65";
export { default as Lab } from "./lab";
export { default as LCH } from "./lch";
export { default as sRGB_Linear } from "./srgb-linear";
export { default as sRGB } from "./srgb";
export { default as HSL } from "./hsl";
export { default as HWB } from "./hwb";
export { default as HSV } from "./hsv";
export { default as P3_Linear } from "./p3-linear";
export { default as P3 } from "./p3";
export { default as A98RGB_Linear } from "./a98rgb-linear";
export { default as A98RGB } from "./a98rgb";
export { default as ProPhoto_Linear } from "./prophoto-linear";
export { default as ProPhoto } from "./prophoto";
export { default as REC_2020_Linear } from "./rec2020-linear";
export { default as REC_2020 } from "./rec2020";
export { default as OKLab } from "./oklab";
export { default as OKLCH } from "./oklch";
export * from "./index-fn-hdr";
import * as spaces from "./index-fn";
export { Spaces } from "./index-fn";
export { spaces };
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import RGBColorSpace from "../rgbspace";
declare const _default: RGBColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import ColorSpace from "../space";
declare const _default: ColorSpace;
export default _default;
import { ColorObject, ColorTypes } from "./color";
import ColorSpace from "./space";
declare namespace to {
let returns: "color";
}
declare function to(
color: ColorTypes,
space: string | ColorSpace,
options?: { inGamut?: boolean | undefined }
): ColorObject;
export default to;
import Color, { ColorObject } from "./color";
import ColorSpace from "./space";
export default function toGamut<T extends Color | ColorObject>(
color: T,
options?: {
method?: string | undefined;
space?: string | ColorSpace | undefined;
}
): T;
export { default as multiplyMatrices } from "./multiply-matrices";
/**
* Check if a value is a string
* @param str Value to check
*/
export function isString(str: any): str is string;
/**
* Find the internal JavaScript `[[Class]]` of an object
* @param o Value to check
*/
export function type(o: any): string;
/**
* Round a number to an amount of significant digits
* @param n The number to round
* @param precision The amount of significant digits
*/
export function toPrecision(n: number, precision: number): number;
/**
* Parse a CSS function regardless of its name and arguments
* @param str String to parse
*/
export function parseFunction(str: string): {
name: string;
rawName: string;
rawArgs: string;
args: Array<
| string
| (number & {
type?: "<angle>" | "<number>" | "<percentage>" | undefined;
unit?: "deg" | undefined;
alpha?: true | undefined;
})
>;
};
/**
* Get the last element of an array
* @param arr The array
*/
export function last<T extends readonly any[]>(arr: T): T[number];
export function interpolate(start: number, end: number, p: number): number;
export function interpolateInv(
start: number,
end: number,
value: number
): number;
export function mapRange(
from: [number, number],
to: [number, number],
value: number
): number;
export function parseCoordGrammar(coordGrammars: string[]): string[];
import Color, { ColorTypes } from "./color";
export function lighten(color: ColorTypes, amount?: number): Color;
export function darken(color: ColorTypes, amount?: number): Color;
+42
-7
{
"name": "colorjs.io",
"version": "0.4.0",
"version": "0.4.1-patch.1",
"description": "Let’s get serious about color",

@@ -10,14 +10,34 @@ "files": [

"dist/color.js.map",
"src/"
"dist/color.legacy.cjs",
"dist/color.legacy.cjs.map",
"dist/color.legacy.js",
"dist/color.legacy.js.map",
"src/",
"types/dist/",
"types/src/",
"types/index.d.ts"
],
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./dist/color.js",
"require": "./dist/color.cjs"
},
"./fn": "./src/index-fn.js"
"./fn": {
"types": "./types/src/index-fn.d.ts",
"import": "./src/index-fn.js"
},
"./dist/*": "./dist/*"
},
"typesVersions": {
"*": {
"fn": [
"./types/src/index-fn.d.ts"
]
}
},
"type": "module",
"main": "./dist/color.cjs",
"module": "./dist/color.js",
"types": "./types",
"directories": {

@@ -28,10 +48,13 @@ "test": "tests"

"test": "open tests/",
"dtslint": "dtslint types",
"build:css": "npx postcss \"**/*.postcss\" --base . --dir . --ext .css --config postcss.config.cjs",
"build:html": "npx @11ty/eleventy --config=.eleventy.cjs",
"build:js": "rollup -c",
"build": "npm run build:html && npm run build:css && npm run build:js",
"build:js:legacy": "rollup -c rollup.legacy.config.js",
"build": "npm run build:html && npm run build:css && npm run build:js && npm run build:js:legacy",
"watch:css": "npx postcss \"**/*.postcss\" --base . --dir . --ext .css --config postcss.config.cjs --watch",
"watch:html": "npx @11ty/eleventy --config=.eleventy.cjs --watch",
"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"
},

@@ -45,3 +68,6 @@ "repository": {

],
"contributors": ["Lea Verou", "Chris Lilley"],
"contributors": [
"Lea Verou",
"Chris Lilley"
],
"license": "MIT",

@@ -54,3 +80,11 @@ "bugs": {

"@11ty/eleventy": "^1.0",
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.3",
"@definitelytyped/dtslint": "latest",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-node-resolve": "^14.1.0",
"@typescript-eslint/parser": "^5.40.0",
"acorn": "latest",
"core-js": "^3.25.3",
"eslint": "latest",

@@ -62,3 +96,4 @@ "markdown-it": "latest",

"rollup": "^2.10",
"rollup-plugin-terser": "^7"
"rollup-plugin-terser": "^7",
"typescript": "^4.8.4"
},

@@ -65,0 +100,0 @@ "sideEffects": [

@@ -70,2 +70,4 @@ // APCA 0.0.98G

// why is this a delta, when Y is not perceptually uniform?
// Answer: it is a noise gate, see
// https://github.com/LeaVerou/color.js/issues/208
if (Math.abs(Ybg - Ytxt) < deltaYmin) {

@@ -72,0 +74,0 @@ C = 0;

+2
-1

@@ -5,2 +5,3 @@ export {default as contrastWCAG21} from "./WCAG21.js";

export {default as contrastWeber} from "./Weber.js";
export {default as contrastLstar} from "./Lstar.js";
export {default as contrastLstar} from "./Lstar.js";
export {default as contrastDeltaPhi} from "./deltaPhi.js";

@@ -9,2 +9,8 @@ // Weber luminance contrast

// the darkest sRGB color above black is #000001 and this produces
// a plain Weber contrast of ~45647.
// So, setting the divide-by-zero result at 50000 is a reasonable
// max clamp for the plain Weber
const max = 50000;
export default function contrastWeber (color1, color2) {

@@ -21,3 +27,3 @@ color1 = getColor(color1);

return Y2 === 0 ? 0 : (Y1 - Y2) / Y2;
};
return Y2 === 0 ? max : (Y1 - Y2) / Y2;
};

@@ -35,5 +35,5 @@ /**

let {space, outputSpace} = o;
let {space, outputSpace, premultiplied} = o;
let r = range(c1, c2, {space, outputSpace});
let r = range(c1, c2, {space, outputSpace, premultiplied});
return r(p);

@@ -40,0 +40,0 @@ }

export {default as XYZ_D65} from "./xyz-d65.js";
export {default as XYZ_D50} from "./xyz-d50.js";
export {default as XYZ_ABS_D65} from "./xyz-abs-d65.js";
export {default as Lab_D65} from "./lab-d65.js";
export {default as Lab} from "./lab.js";

@@ -5,0 +6,0 @@ export {default as LCH} from "./lch.js";

@@ -71,5 +71,5 @@ import ColorSpace from "../space.js";

"lab": {
coords: ["<percentage> | <number>", "<number>", "<number>"],
coords: ["<number> | <percentage>", "<number>", "<number>"],
}
}
});

@@ -64,5 +64,5 @@ import ColorSpace from "../space.js";

"lch": {
coords: ["<percentage> | <number>", "<number>", "<number> | <angle>"],
coords: ["<number> | <percentage>", "<number>", "<number> | <angle>"],
}
}
});

@@ -71,5 +71,5 @@ import ColorSpace from "../space.js";

"oklab": {
coords: ["<percentage>", "<number>", "<number>"],
coords: ["<number> | <percentage>", "<number>", "<number>"],
}
}
});

@@ -65,3 +65,3 @@ import ColorSpace from "../space.js";

"oklch": {
coords: ["<percentage>", "<number>", "<number> | <angle>"],
coords: ["<number> | <percentage>", "<number>", "<number> | <angle>"],
}

@@ -68,0 +68,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display