Socket
Socket
Sign inDemoInstall

culori

Package Overview
Dependencies
0
Maintainers
3
Versions
256
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.0 to 4.0.0

src/hdr/constants.js

7

package.json
{
"name": "culori",
"version": "3.3.0",
"version": "4.0.0",
"type": "module",

@@ -10,4 +10,7 @@ "main": "./bundled/culori.cjs",

"exports": {
".": {
"require": "./bundled/culori.cjs",
"import": "./src/index.js"
},
"./require": "./bundled/culori.cjs",
".": "./src/index.js",
"./css": "./src/bootstrap/css.js",

@@ -14,0 +17,0 @@ "./all": "./src/bootstrap/all.js",

@@ -10,3 +10,3 @@ /*

const linearize = v => Math.pow(Math.abs(v), 563 / 256) * Math.sign(v);
const linearize = (v = 0) => Math.pow(Math.abs(v), 563 / 256) * Math.sign(v);

@@ -13,0 +13,0 @@ const convertA98ToXyz65 = a98 => {

@@ -12,2 +12,5 @@ /*

const convertXyz65ToA98 = ({ x, y, z, alpha }) => {
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let res = {

@@ -14,0 +17,0 @@ mode: 'a98',

@@ -17,3 +17,4 @@ import converter from './converter.js';

);
return (Math.atan2(sum.sin, sum.cos) * 180) / Math.PI;
let angle = (Math.atan2(sum.sin, sum.cos) * 180) / Math.PI;
return angle < 0 ? 360 + angle : angle;
};

@@ -20,0 +21,0 @@

@@ -10,2 +10,3 @@ // Color space definitions

import modeHwb from '../hwb/definition.js';
import modeItp from '../itp/definition.js';
import modeJab from '../jab/definition.js';

@@ -42,2 +43,3 @@ import modeJch from '../jch/definition.js';

export const hwb = useMode(modeHwb);
export const itp = useMode(modeItp);
export const jab = useMode(modeJab);

@@ -44,0 +46,0 @@ export const jch = useMode(modeJch);

@@ -10,5 +10,5 @@ import converter from './converter.js';

mode: c.mode,
r: Math.max(0, Math.min(c.r, 1)),
g: Math.max(0, Math.min(c.g, 1)),
b: Math.max(0, Math.min(c.b, 1))
r: Math.max(0, Math.min(c.r !== undefined ? c.r : 0, 1)),
g: Math.max(0, Math.min(c.g !== undefined ? c.g : 0, 1)),
b: Math.max(0, Math.min(c.b !== undefined ? c.b : 0, 1))
};

@@ -26,8 +26,5 @@ if (c.alpha !== undefined) {

c !== undefined &&
c.r >= 0 &&
c.r <= 1 &&
c.g >= 0 &&
c.g <= 1 &&
c.b >= 0 &&
c.b <= 1
(c.r === undefined || (c.r >= 0 && c.r <= 1)) &&
(c.g === undefined || (c.g >= 0 && c.g <= 1)) &&
(c.b === undefined || (c.b >= 0 && c.b <= 1))
);

@@ -151,6 +148,6 @@ };

let start = 0;
let end = color.c;
let end = color.c !== undefined ? color.c : 0;
let range = getMode(mode).ranges.c;
let resolution = (range[1] - range[0]) / Math.pow(2, 13);
let _last_good_c;
let _last_good_c = clamped.c;

@@ -203,4 +200,5 @@ while (end - start > resolution) {

const destConv = converter(dest);
const destMode = getMode(dest);
if (!getMode(dest).gamut) {
if (!destMode.gamut) {
return color => destConv(color);

@@ -215,5 +213,2 @@ }

const White = destConv('white');
const Black = destConv('black');
return color => {

@@ -225,4 +220,9 @@ color = prepare(color);

const candidate = { ...ucs(color) };
// account for missing components
if (candidate.l === undefined) candidate.l = 0;
if (candidate.c === undefined) candidate.c = 0;
if (candidate.l >= ranges.l[1]) {
const res = { ...White };
const res = { ...destMode.white, mode: dest };
if (color.alpha !== undefined) {

@@ -234,3 +234,3 @@ res.alpha = color.alpha;

if (candidate.l <= ranges.l[0]) {
const res = { ...Black };
const res = { ...destMode.black, mode: dest };
if (color.alpha !== undefined) {

@@ -237,0 +237,0 @@ res.alpha = color.alpha;

@@ -7,2 +7,3 @@ import { degToRad, M } from './constants.js';

h = (h === undefined ? 0 : h + 120) * degToRad;
if (l === undefined) l = 0;

@@ -9,0 +10,0 @@ let amp = s === undefined ? 0 : s * l * (1 - l);

@@ -21,2 +21,5 @@ /*

const convertRgbToCubehelix = ({ r, g, b, alpha }) => {
if (r === undefined) r = 0;
if (g === undefined) g = 0;
if (b === undefined) b = 0;
let l = (BCAD * b + r * DE - g * BE) / (BCAD + DE - BE);

@@ -23,0 +26,0 @@ let x = b - l;

@@ -295,2 +295,10 @@ import { getMode } from './modes.js';

/*
ΔE_ITP, as defined in Rec. ITU-R BT.2124:
https://www.itu.int/rec/R-REC-BT.2124/en
*/
const differenceItp = () =>
differenceEuclidean('itp', [518400, 129600, 518400]);
export {

@@ -306,3 +314,4 @@ differenceHueChroma,

differenceHyab,
differenceKotsarenkoRamos
differenceKotsarenkoRamos,
differenceItp
};

@@ -9,2 +9,5 @@ import { kCH, kE, sinθ, cosθ, θ, factor } from './constants.js';

const convertDlchToLab65 = ({ l, c, h, alpha }) => {
if (l === undefined) l = 0;
if (c === undefined) c = 0;
if (h === undefined) h = 0;
let res = {

@@ -15,11 +18,7 @@ mode: 'lab65',

if (h === undefined) {
res.a = res.b = 0;
} else {
let G = (Math.exp(0.0435 * c * kCH * kE) - 1) / 0.075;
let e = G * Math.cos((h / 180) * Math.PI - θ);
let f = G * Math.sin((h / 180) * Math.PI - θ);
res.a = e * cosθ - (f / 0.83) * sinθ;
res.b = e * sinθ + (f / 0.83) * cosθ;
}
let G = (Math.exp(0.0435 * c * kCH * kE) - 1) / 0.075;
let e = G * Math.cos((h / 180) * Math.PI - θ);
let f = G * Math.sin((h / 180) * Math.PI - θ);
res.a = e * cosθ - (f / 0.83) * sinθ;
res.b = e * sinθ + (f / 0.83) * cosθ;

@@ -26,0 +25,0 @@ if (alpha !== undefined) res.alpha = alpha;

@@ -10,2 +10,5 @@ import { kCH, kE, sinθ, cosθ, θ, factor } from './constants.js';

const convertLab65ToDlch = ({ l, a, b, alpha }) => {
if (l === undefined) l = 0;
if (a === undefined) a = 0;
if (b === undefined) b = 0;
let e = a * cosθ + b * sinθ;

@@ -12,0 +15,0 @@ let f = 0.83 * (b * cosθ - a * sinθ);

@@ -8,5 +8,8 @@ import converter from './converter.js';

const clamp = value => Math.max(0, Math.min(1, value));
const clamp = value => Math.max(0, Math.min(1, value || 0));
const fixup = value => Math.round(clamp(value) * 255);
const rgb = converter('rgb');
const hsl = converter('hsl');
export const serializeHex = color => {

@@ -38,5 +41,5 @@ if (color === undefined) {

let r = color.r !== undefined ? fixup(color.r) : 'none';
let g = color.g !== undefined ? fixup(color.g) : 'none';
let b = color.b !== undefined ? fixup(color.b) : 'none';
let r = fixup(color.r);
let g = fixup(color.g);
let b = fixup(color.b);

@@ -58,10 +61,4 @@ if (color.alpha === undefined || color.alpha === 1) {

const h = twoDecimals(color.h || 0);
const s =
color.s !== undefined
? twoDecimals(clamp(color.s) * 100) + '%'
: 'none';
const l =
color.l !== undefined
? twoDecimals(clamp(color.l) * 100) + '%'
: 'none';
const s = twoDecimals(clamp(color.s) * 100) + '%';
const l = twoDecimals(clamp(color.l) * 100) + '%';

@@ -103,5 +100,5 @@ if (color.alpha === undefined || color.alpha === 1) {

export const formatHex = c => serializeHex(converter('rgb')(c));
export const formatHex8 = c => serializeHex8(converter('rgb')(c));
export const formatRgb = c => serializeRgb(converter('rgb')(c));
export const formatHsl = c => serializeHsl(converter('hsl')(c));
export const formatHex = c => serializeHex(rgb(c));
export const formatHex8 = c => serializeHex8(rgb(c));
export const formatRgb = c => serializeRgb(rgb(c));
export const formatHsl = c => serializeHsl(hsl(c));

@@ -6,3 +6,5 @@ import normalizeHue from '../util/normalizeHue.js';

export default function convertHsiToRgb({ h, s, i, alpha }) {
h = normalizeHue(h);
h = normalizeHue(h !== undefined ? h : 0);
if (s === undefined) s = 0;
if (i === undefined) i = 0;
let f = Math.abs(((h / 60) % 2) - 1);

@@ -9,0 +11,0 @@ let res;

// Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Formal_derivation
export default function convertRgbToHsi({ r, g, b, alpha }) {
if (r === undefined) r = 0;
if (g === undefined) g = 0;
if (b === undefined) b = 0;
let M = Math.max(r, g, b),

@@ -5,0 +8,0 @@ m = Math.min(r, g, b);

@@ -5,3 +5,5 @@ import normalizeHue from '../util/normalizeHue.js';

export default function convertHslToRgb({ h, s, l, alpha }) {
h = normalizeHue(h);
h = normalizeHue(h !== undefined ? h : 0);
if (s === undefined) s = 0;
if (l === undefined) l = 0;
let m1 = l + s * (l < 0.5 ? l : 1 - l);

@@ -8,0 +10,0 @@ let m2 = m1 - (m1 - l) * 2 * Math.abs(((h / 60) % 2) - 1);

// Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Formal_derivation
export default function convertRgbToHsl({ r, g, b, alpha }) {
if (r === undefined) r = 0;
if (g === undefined) g = 0;
if (b === undefined) b = 0;
let M = Math.max(r, g, b),

@@ -5,0 +8,0 @@ m = Math.min(r, g, b);

@@ -32,5 +32,7 @@ import convertHslToRgb from './convertHslToRgb.js';

serialize: c =>
`hsl(${c.h || 0} ${c.s !== undefined ? c.s * 100 + '%' : 'none'} ${
c.l !== undefined ? c.l * 100 + '%' : 'none'
}${c.alpha < 1 ? ` / ${c.alpha}` : ''})`,
`hsl(${c.h !== undefined ? c.h : 'none'} ${
c.s !== undefined ? c.s * 100 + '%' : 'none'
} ${c.l !== undefined ? c.l * 100 + '%' : 'none'}${
c.alpha < 1 ? ` / ${c.alpha}` : ''
})`,

@@ -37,0 +39,0 @@ interpolate: {

@@ -21,3 +21,3 @@ import { Tok } from '../parse.js';

}
res.s = s.type === Tok.Number ? s.value : s.value / 100;
res.s = s.value / 100;
}

@@ -29,7 +29,13 @@

}
res.l = l.type === Tok.Number ? l.value : l.value / 100;
res.l = l.value / 100;
}
if (alpha.type !== Tok.None) {
res.alpha = alpha.type === Tok.Number ? alpha.value : alpha.value / 100;
res.alpha = Math.min(
1,
Math.max(
0,
alpha.type === Tok.Number ? alpha.value : alpha.value / 100
)
);
}

@@ -36,0 +42,0 @@

@@ -32,5 +32,5 @@ import hueToDeg from '../util/hue.js';

if (match[6] !== undefined) {
res.alpha = match[6] / 100;
res.alpha = Math.max(0, Math.min(1, match[6] / 100));
} else if (match[7] !== undefined) {
res.alpha = +match[7];
res.alpha = Math.max(0, Math.min(1, +match[7]));
}

@@ -37,0 +37,0 @@ return res;

@@ -6,3 +6,5 @@ import normalizeHue from '../util/normalizeHue.js';

export default function convertHsvToRgb({ h, s, v, alpha }) {
h = normalizeHue(h);
h = normalizeHue(h !== undefined ? h : 0);
if (s === undefined) s = 0;
if (v === undefined) v = 0;
let f = Math.abs(((h / 60) % 2) - 1);

@@ -9,0 +11,0 @@ let res;

// Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Formal_derivation
export default function convertRgbToHsv({ r, g, b, alpha }) {
if (r === undefined) r = 0;
if (g === undefined) g = 0;
if (b === undefined) b = 0;
let M = Math.max(r, g, b),

@@ -5,0 +8,0 @@ m = Math.min(r, g, b);

@@ -14,2 +14,4 @@ /*

export default function convertHwbToRgb({ h, w, b, alpha }) {
if (w === undefined) w = 0;
if (b === undefined) b = 0;
// normalize w + b to 1

@@ -16,0 +18,0 @@ if (w + b > 1) {

@@ -16,6 +16,8 @@ /*

if (hsv === undefined) return undefined;
let s = hsv.s !== undefined ? hsv.s : 0;
let v = hsv.v !== undefined ? hsv.v : 0;
let res = {
mode: 'hwb',
w: (1 - hsv.s) * hsv.v,
b: 1 - hsv.v
w: (1 - s) * v,
b: 1 - v
};

@@ -22,0 +24,0 @@ if (hsv.h !== undefined) res.h = hsv.h;

@@ -31,3 +31,5 @@ import convertHwbToRgb from './convertHwbToRgb.js';

serialize: c =>
`hwb(${c.h || 0} ${c.w * 100}% ${c.b * 100}%${
`hwb(${c.h !== undefined ? c.h : 'none'} ${
c.w !== undefined ? c.w * 100 + '%' : 'none'
} ${c.b !== undefined ? c.b * 100 + '%' : 'none'}${
c.alpha < 1 ? ` / ${c.alpha}` : ''

@@ -34,0 +36,0 @@ })`,

@@ -21,3 +21,3 @@ import { Tok } from '../parse.js';

}
res.w = w.type === Tok.Number ? w.value : w.value / 100;
res.w = w.value / 100;
}

@@ -29,7 +29,13 @@

}
res.b = b.type === Tok.Number ? b.value : b.value / 100;
res.b = b.value / 100;
}
if (alpha.type !== Tok.None) {
res.alpha = alpha.type === Tok.Number ? alpha.value : alpha.value / 100;
res.alpha = Math.min(
1,
Math.max(
0,
alpha.type === Tok.Number ? alpha.value : alpha.value / 100
)
);
}

@@ -36,0 +42,0 @@

@@ -10,2 +10,3 @@ // Color space definitions

export { default as modeHwb } from './hwb/definition.js';
export { default as modeItp } from './itp/definition.js';
export { default as modeJab } from './jab/definition.js';

@@ -121,3 +122,4 @@ export { default as modeJch } from './jch/definition.js';

differenceHueNaive,
differenceKotsarenkoRamos
differenceKotsarenkoRamos,
differenceItp
} from './difference.js';

@@ -176,2 +178,3 @@

export { default as convertHwbToRgb } from './hwb/convertHwbToRgb.js';
export { default as convertItpToXyz65 } from './itp/convertItpToXyz65.js';
export { default as convertJabToJch } from './jch/convertJabToJch.js';

@@ -218,2 +221,3 @@ export { default as convertJabToRgb } from './jab/convertJabToRgb.js';

export { default as convertXyz65ToA98 } from './a98/convertXyz65ToA98.js';
export { default as convertXyz65ToItp } from './itp/convertXyz65ToItp.js';
export { default as convertXyz65ToJab } from './jab/convertXyz65ToJab.js';

@@ -220,0 +224,0 @@ export { default as convertXyz65ToLab65 } from './lab65/convertXyz65ToLab65.js';

@@ -10,2 +10,3 @@ // Color space definitions

import modeHwb from './hwb/definition.js';
import modeItp from './itp/definition.js';
import modeJab from './jab/definition.js';

@@ -122,3 +123,4 @@ import modeJch from './jch/definition.js';

differenceHueNaive,
differenceKotsarenkoRamos
differenceKotsarenkoRamos,
differenceItp
} from './difference.js';

@@ -177,2 +179,3 @@

export { default as convertHwbToRgb } from './hwb/convertHwbToRgb.js';
export { default as convertItpToXyz65 } from './itp/convertItpToXyz65.js';
export { default as convertJabToJch } from './jch/convertJabToJch.js';

@@ -224,2 +227,3 @@ export { default as convertJabToRgb } from './jab/convertJabToRgb.js';

export { default as convertXyz65ToA98 } from './a98/convertXyz65ToA98.js';
export { default as convertXyz65ToItp } from './itp/convertXyz65ToItp.js';
export { default as convertXyz65ToJab } from './jab/convertXyz65ToJab.js';

@@ -242,2 +246,3 @@ export { default as convertXyz65ToLab65 } from './lab65/convertXyz65ToLab65.js';

modeHwb,
modeItp,
modeJab,

@@ -274,2 +279,3 @@ modeJch,

export const hwb = useMode(modeHwb);
export const itp = useMode(modeItp);
export const jab = useMode(modeJab);

@@ -276,0 +282,0 @@ export const jch = useMode(modeJch);

@@ -1,12 +0,14 @@

const n = 0.1593017578125; // = 2610 / Math.pow(2, 14);
import { M1 as n, C1, C2, C3 } from '../hdr/transfer.js';
const p = 134.03437499999998; // = 1.7 * 2523 / Math.pow(2, 5);
const c1 = 0.8359375; // = 3424 / Math.pow(2, 12);
const c2 = 18.8515625; // = 2413 / Math.pow(2, 7);
const c3 = 18.6875; // = 2392 / Math.pow(2, 7);
const d0 = 1.6295499532821566e-11;
/* `v` may be negative, in which case return 0 instead of NaN */
const pq_inv = v => {
const npow = (v, exp) => Math.sign(v) * Math.pow(Math.abs(v), exp);
/*
The encoding function is derived from Perceptual Quantizer.
*/
const jabPqDecode = v => {
if (v < 0) return 0;
let vp = Math.pow(v, 1 / p);
return 10000 * Math.pow((c1 - vp) / (c3 * vp - c2), 1 / n) || 0;
return 10000 * Math.pow((C1 - vp) / (C3 * vp - C2), 1 / n);
};

@@ -17,7 +19,10 @@

const convertJabToXyz65 = ({ j, a, b, alpha }) => {
if (j === undefined) j = 0;
if (a === undefined) a = 0;
if (b === undefined) b = 0;
let i = (j + d0) / (0.44 + 0.56 * (j + d0));
let l = pq_inv(i + 0.13860504 * a + 0.058047316 * b);
let m = pq_inv(i - 0.13860504 * a - 0.058047316 * b);
let s = pq_inv(i - 0.096019242 * a - 0.8118919 * b);
let l = jabPqDecode(i + 0.13860504 * a + 0.058047316 * b);
let m = jabPqDecode(i - 0.13860504 * a - 0.058047316 * b);
let s = jabPqDecode(i - 0.096019242 * a - 0.8118919 * b);

@@ -24,0 +29,0 @@ let res = {

@@ -1,16 +0,16 @@

const n = 0.1593017578125; // = 2610 / Math.pow(2, 14);
import { M1 as n, C1, C2, C3 } from '../hdr/transfer.js';
const p = 134.03437499999998; // = 1.7 * 2523 / Math.pow(2, 5);
const c1 = 0.8359375; // = 3424 / Math.pow(2, 12);
const c2 = 18.8515625; // = 2413 / Math.pow(2, 7);
const c3 = 18.6875; // = 2392 / Math.pow(2, 7);
const d0 = 1.6295499532821566e-11;
/* `v` may be negative, in which case return 0 instead of NaN */
const pq = v => {
/*
The encoding function is derived from Perceptual Quantizer.
*/
const jabPqEncode = v => {
if (v < 0) return 0;
let vn = Math.pow(v / 10000, n);
return Math.pow((c1 + c2 * vn) / (1 + c3 * vn), p) || 0;
return Math.pow((C1 + C2 * vn) / (1 + C3 * vn), p);
};
// Convert to Absolute XYZ
const abs = v => Math.max(v * 203, 0);
const abs = (v = 0) => Math.max(v * 203, 0);

@@ -25,5 +25,5 @@ const convertXyz65ToJab = ({ x, y, z, alpha }) => {

let l = pq(0.41478972 * xp + 0.579999 * yp + 0.014648 * z);
let m = pq(-0.20151 * xp + 1.120649 * yp + 0.0531008 * z);
let s = pq(-0.0166008 * xp + 0.2648 * yp + 0.6684799 * z);
let l = jabPqEncode(0.41478972 * xp + 0.579999 * yp + 0.014648 * z);
let m = jabPqEncode(-0.20151 * xp + 1.120649 * yp + 0.0531008 * z);
let s = jabPqEncode(-0.0166008 * xp + 0.2648 * yp + 0.6684799 * z);

@@ -30,0 +30,0 @@ let i = (l + m) / 2;

import normalizeHue from '../util/normalizeHue.js';
const convertJabToJch = ({ j, a, b, alpha }) => {
if (a === undefined) a = 0;
if (b === undefined) b = 0;
let c = Math.sqrt(a * a + b * b);

@@ -5,0 +7,0 @@ let res = {

const convertJchToJab = ({ j, c, h, alpha }) => {
if (h === undefined) h = 0;
let res = {

@@ -3,0 +4,0 @@ mode: 'jab',

@@ -7,2 +7,5 @@ import { k, e } from '../xyz50/constants.js';

const convertLabToXyz50 = ({ l, a, b, alpha }) => {
if (l === undefined) l = 0;
if (a === undefined) a = 0;
if (b === undefined) b = 0;
let fy = (l + 16) / 116;

@@ -9,0 +12,0 @@ let fx = a / 500 + fy;

@@ -7,2 +7,5 @@ import { k, e } from '../xyz50/constants.js';

const convertXyz50ToLab = ({ x, y, z, alpha }) => {
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let f0 = f(x / D50.X);

@@ -9,0 +12,0 @@ let f1 = f(y / D50.Y);

@@ -13,3 +13,3 @@ import { Tok } from '../parse.js';

if (l.type !== Tok.None) {
res.l = l.value;
res.l = Math.min(Math.max(0, l.value), 100);
}

@@ -23,3 +23,9 @@ if (a.type !== Tok.None) {

if (alpha.type !== Tok.None) {
res.alpha = alpha.type === Tok.Number ? alpha.value : alpha.value / 100;
res.alpha = Math.min(
1,
Math.max(
0,
alpha.type === Tok.Number ? alpha.value : alpha.value / 100
)
);
}

@@ -26,0 +32,0 @@

@@ -7,2 +7,6 @@ import { k, e } from '../xyz65/constants.js';

const convertLab65ToXyz65 = ({ l, a, b, alpha }) => {
if (l === undefined) l = 0;
if (a === undefined) a = 0;
if (b === undefined) b = 0;
let fy = (l + 16) / 116;

@@ -9,0 +13,0 @@ let fx = a / 500 + fy;

@@ -7,2 +7,5 @@ import { k, e } from '../xyz65/constants.js';

const convertXyz65ToLab65 = ({ x, y, z, alpha }) => {
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let f0 = f(x / D65.X);

@@ -9,0 +12,0 @@ let f1 = f(y / D65.Y);

@@ -9,2 +9,4 @@ import normalizeHue from '../util/normalizeHue.js';

const convertLabToLch = ({ l, a, b, alpha }, mode = 'lch') => {
if (a === undefined) a = 0;
if (b === undefined) b = 0;
let c = Math.sqrt(a * a + b * b);

@@ -11,0 +13,0 @@ let res = { mode, l, c };

@@ -7,2 +7,3 @@ /*

const convertLchToLab = ({ l, c, h, alpha }, mode = 'lab') => {
if (h === undefined) h = 0;
let res = {

@@ -9,0 +10,0 @@ mode,

@@ -37,3 +37,5 @@ import convertLabToLch from './convertLabToLch.js';

c.c !== undefined ? c.c : 'none'
} ${c.h || 0}${c.alpha < 1 ? ` / ${c.alpha}` : ''})`,
} ${c.h !== undefined ? c.h : 'none'}${
c.alpha < 1 ? ` / ${c.alpha}` : ''
})`,

@@ -40,0 +42,0 @@ interpolate: {

@@ -13,3 +13,3 @@ import { Tok } from '../parse.js';

}
res.l = l.value;
res.l = Math.min(Math.max(0, l.value), 100);
}

@@ -29,3 +29,9 @@ if (c.type !== Tok.None) {

if (alpha.type !== Tok.None) {
res.alpha = alpha.type === Tok.Number ? alpha.value : alpha.value / 100;
res.alpha = Math.min(
1,
Math.max(
0,
alpha.type === Tok.Number ? alpha.value : alpha.value / 100
)
);
}

@@ -32,0 +38,0 @@

const convertLchuvToLuv = ({ l, c, h, alpha }) => {
if (h === undefined) h = 0;
let res = {

@@ -3,0 +4,0 @@ mode: 'luv',

import normalizeHue from '../util/normalizeHue.js';
const convertLuvToLchuv = ({ l, u, v, alpha }) => {
if (u === undefined) u = 0;
if (v === undefined) v = 0;
let c = Math.sqrt(u * u + v * v);

@@ -5,0 +7,0 @@ let res = {

@@ -1,2 +0,2 @@

const fn = c => {
const fn = (c = 0) => {
const abs = Math.abs(c);

@@ -3,0 +3,0 @@ if (abs > 0.0031308) {

@@ -1,2 +0,2 @@

const fn = c => {
const fn = (c = 0) => {
const abs = Math.abs(c);

@@ -3,0 +3,0 @@ if (abs <= 0.04045) {

@@ -11,2 +11,10 @@ import { k } from '../xyz50/constants.js';

const convertLuvToXyz50 = ({ l, u, v, alpha }) => {
if (l === undefined) l = 0;
if (l === 0) {
return { mode: 'xyz50', x: 0, y: 0, z: 0 };
}
if (u === undefined) u = 0;
if (v === undefined) v = 0;
let up = u / (13 * l) + un;

@@ -13,0 +21,0 @@ let vp = v / (13 * l) + vn;

@@ -13,2 +13,5 @@ import { k, e } from '../xyz50/constants.js';

const convertXyz50ToLuv = ({ x, y, z, alpha }) => {
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let l = l_fn(y / D50.Y);

@@ -15,0 +18,0 @@ let u = u_fn(x, y, z);

@@ -29,5 +29,7 @@ /*

export default function convertOkhslToOklab(hsl) {
let l = toe_inv(hsl.l);
let h = hsl.h !== undefined ? hsl.h : 0;
let s = hsl.s !== undefined ? hsl.s : 0;
let l = hsl.l !== undefined ? hsl.l : 0;
const ret = { mode: 'oklab', l };
const ret = { mode: 'oklab', l: toe_inv(l) };

@@ -38,3 +40,3 @@ if (hsl.alpha !== undefined) {

if (!hsl.s || hsl.l === 1) {
if (!s || l === 1) {
ret.a = ret.b = 0;

@@ -44,8 +46,8 @@ return ret;

let a_ = Math.cos((hsl.h / 180) * Math.PI);
let b_ = Math.sin((hsl.h / 180) * Math.PI);
let [C_0, C_mid, C_max] = get_Cs(l, a_, b_);
let a_ = Math.cos((h / 180) * Math.PI);
let b_ = Math.sin((h / 180) * Math.PI);
let [C_0, C_mid, C_max] = get_Cs(ret.l, a_, b_);
let t, k_0, k_1, k_2;
if (hsl.s < 0.8) {
t = 1.25 * hsl.s;
if (s < 0.8) {
t = 1.25 * s;
k_0 = 0;

@@ -55,3 +57,3 @@ k_1 = 0.8 * C_0;

} else {
t = 5 * (hsl.s - 0.8);
t = 5 * (s - 0.8);
k_0 = C_mid;

@@ -58,0 +60,0 @@ k_1 = (0.2 * C_mid * C_mid * 1.25 * 1.25) / C_0;

@@ -30,8 +30,12 @@ /*

export default function convertOklabToOkhsl(lab) {
const ret = { mode: 'okhsl', l: toe(lab.l) };
const l = lab.l !== undefined ? lab.l : 0;
const a = lab.a !== undefined ? lab.a : 0;
const b = lab.b !== undefined ? lab.b : 0;
const ret = { mode: 'okhsl', l: toe(l) };
if (lab.alpha !== undefined) {
ret.alpha = lab.alpha;
}
let c = Math.sqrt(lab.a * lab.a + lab.b * lab.b);
let c = Math.sqrt(a * a + b * b);
if (!c) {

@@ -41,3 +45,3 @@ ret.s = 0;

}
let [C_0, C_mid, C_max] = get_Cs(lab.l, lab.a / c, lab.b / c);
let [C_0, C_mid, C_max] = get_Cs(l, a / c, b / c);
let s;

@@ -59,5 +63,5 @@ if (c < C_mid) {

ret.s = s;
ret.h = normalizeHue((Math.atan2(lab.b, lab.a) * 180) / Math.PI);
ret.h = normalizeHue((Math.atan2(b, a) * 180) / Math.PI);
}
return ret;
}

@@ -32,4 +32,5 @@ /*

// Hue may be missing for achromatic colors
const h = hsv.h || 0;
const h = hsv.h !== undefined ? hsv.h : 0;
const s = hsv.s !== undefined ? hsv.s : 0;
const v = hsv.v !== undefined ? hsv.v : 0;

@@ -42,4 +43,4 @@ const a_ = Math.cos((h / 180) * Math.PI);

const k = 1 - S_0 / S_max;
const L_v = 1 - (hsv.s * S_0) / (S_0 + T - T * k * hsv.s);
const C_v = (hsv.s * T * S_0) / (S_0 + T - T * k * hsv.s);
const L_v = 1 - (s * S_0) / (S_0 + T - T * k * s);
const C_v = (s * T * S_0) / (S_0 + T - T * k * s);

@@ -57,3 +58,3 @@ const L_vt = toe_inv(L_v);

const L_new = toe_inv(hsv.v * L_v);
const L_new = toe_inv(v * L_v);
const C = (C_v * L_new) / L_v;

@@ -60,0 +61,0 @@

@@ -31,8 +31,11 @@ /*

export default function convertOklabToOkhsv(lab) {
let c = Math.sqrt(lab.a * lab.a + lab.b * lab.b);
let l = lab.l !== undefined ? lab.l : 0;
let a = lab.a !== undefined ? lab.a : 0;
let b = lab.b !== undefined ? lab.b : 0;
let l = lab.l;
let c = Math.sqrt(a * a + b * b);
// TODO: c = 0
let a_ = c ? lab.a / c : 1;
let b_ = c ? lab.b / c : 1;
let a_ = c ? a / c : 1;
let b_ = c ? b / c : 1;

@@ -65,3 +68,3 @@ let [S_max, T] = get_ST_max(a_, b_);

if (ret.s) {
ret.h = normalizeHue((Math.atan2(lab.b, lab.a) * 180) / Math.PI);
ret.h = normalizeHue((Math.atan2(b, a) * 180) / Math.PI);
}

@@ -68,0 +71,0 @@ if (lab.alpha !== undefined) {

const convertLrgbToOklab = ({ r, g, b, alpha }) => {
if (r === undefined) r = 0;
if (g === undefined) g = 0;
if (b === undefined) b = 0;
let L = Math.cbrt(

@@ -3,0 +6,0 @@ 0.41222147079999993 * r + 0.5363325363 * g + 0.0514459929 * b

const convertOklabToLrgb = ({ l, a, b, alpha }) => {
if (l === undefined) l = 0;
if (a === undefined) a = 0;
if (b === undefined) b = 0;
let L = Math.pow(

@@ -3,0 +6,0 @@ l * 0.99999999845051981432 +

@@ -13,3 +13,6 @@ import { Tok } from '../parse.js';

if (l.type !== Tok.None) {
res.l = l.type === Tok.Number ? l.value : l.value / 100;
res.l = Math.min(
Math.max(0, l.type === Tok.Number ? l.value : l.value / 100),
1
);
}

@@ -23,3 +26,9 @@ if (a.type !== Tok.None) {

if (alpha.type !== Tok.None) {
res.alpha = alpha.type === Tok.Number ? alpha.value : alpha.value / 100;
res.alpha = Math.min(
1,
Math.max(
0,
alpha.type === Tok.Number ? alpha.value : alpha.value / 100
)
);
}

@@ -26,0 +35,0 @@

@@ -26,3 +26,5 @@ import lch from '../lch/definition.js';

c.c !== undefined ? c.c : 'none'
} ${c.h || 0}${c.alpha < 1 ? ` / ${c.alpha}` : ''})`,
} ${c.h !== undefined ? c.h : 'none'}${
c.alpha < 1 ? ` / ${c.alpha}` : ''
})`,

@@ -29,0 +31,0 @@ ranges: {

@@ -13,3 +13,6 @@ import { Tok } from '../parse.js';

}
res.l = l.type === Tok.Number ? l.value : l.value / 100;
res.l = Math.min(
Math.max(0, l.type === Tok.Number ? l.value : l.value / 100),
1
);
}

@@ -29,3 +32,9 @@ if (c.type !== Tok.None) {

if (alpha.type !== Tok.None) {
res.alpha = alpha.type === Tok.Number ? alpha.value : alpha.value / 100;
res.alpha = Math.min(
1,
Math.max(
0,
alpha.type === Tok.Number ? alpha.value : alpha.value / 100
)
);
}

@@ -32,0 +41,0 @@

@@ -12,2 +12,5 @@ /*

const convertXyz65ToP3 = ({ x, y, z, alpha }) => {
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let res = convertLrgbToRgb(

@@ -14,0 +17,0 @@ {

@@ -277,6 +277,10 @@ import { parsers, colorProfiles, getMode } from './modes.js';

const channels = getMode(mode).channels;
for (let ii = 0, c; ii < channels.length; ii++) {
for (let ii = 0, c, ch; ii < channels.length; ii++) {
c = coords[ii];
ch = channels[ii];
if (c.type !== Tok.None) {
res[channels[ii]] = c.type === Tok.Number ? c.value : c.value / 100;
res[ch] = c.type === Tok.Number ? c.value : c.value / 100;
if (ch === 'alpha') {
res[ch] = Math.max(0, Math.min(1, res[ch]));
}
}

@@ -283,0 +287,0 @@ }

@@ -9,3 +9,3 @@ /*

const linearize = v => {
const linearize = (v = 0) => {
let abs = Math.abs(v);

@@ -12,0 +12,0 @@ if (abs >= 16 / 512) {

@@ -18,2 +18,5 @@ /*

const convertXyz50ToProphoto = ({ x, y, z, alpha }) => {
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let res = {

@@ -20,0 +23,0 @@ mode: 'prophoto',

@@ -13,3 +13,3 @@ /*

const linearize = v => {
const linearize = (v = 0) => {
let abs = Math.abs(v);

@@ -16,0 +16,0 @@ if (abs < β * 4.5) {

@@ -21,2 +21,5 @@ /*

const convertXyz65ToRec2020 = ({ x, y, z, alpha }) => {
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let res = {

@@ -23,0 +26,0 @@ mode: 'rec2020',

@@ -31,5 +31,7 @@ import parseNamed from './parseNamed.js';

},
gamut: true
gamut: true,
white: { r: 1, g: 1, b: 1 },
black: { r: 0, g: 0, b: 0 }
};
export default definition;

@@ -22,3 +22,9 @@ import { Tok } from '../parse.js';

if (alpha.type !== Tok.None) {
res.alpha = alpha.type === Tok.Number ? alpha.value : alpha.value / 100;
res.alpha = Math.min(
1,
Math.max(
0,
alpha.type === Tok.Number ? alpha.value : alpha.value / 100
)
);
}

@@ -25,0 +31,0 @@

@@ -43,5 +43,5 @@ import { num, per, num_per, c } from '../util/regex.js';

if (match[4] !== undefined) {
res.alpha = match[4] / 100;
res.alpha = Math.max(0, Math.min(1, match[4] / 100));
} else if (match[5] !== undefined) {
res.alpha = +match[5];
res.alpha = Math.max(0, Math.min(1, +match[5]));
}

@@ -48,0 +48,0 @@

@@ -7,2 +7,5 @@ import convertLrgbToRgb from '../lrgb/convertLrgbToRgb.js';

const convertXybToRgb = ({ x, y, b, alpha }) => {
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (b === undefined) b = 0;
const l = transfer(x + y) - bias;

@@ -9,0 +12,0 @@ const m = transfer(y - x) - bias;

@@ -12,2 +12,5 @@ /*

const convertXyz50ToRgb = ({ x, y, z, alpha }) => {
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let res = convertLrgbToRgb({

@@ -14,0 +17,0 @@ r:

@@ -12,2 +12,5 @@ /*

let { x, y, z, alpha } = xyz50;
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let res = {

@@ -14,0 +17,0 @@ mode: 'xyz65',

@@ -13,2 +13,5 @@ /*

const convertXyz65ToRgb = ({ x, y, z, alpha }) => {
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let res = convertLrgbToRgb({

@@ -15,0 +18,0 @@ r:

@@ -12,2 +12,5 @@ /*

let { x, y, z, alpha } = xyz65;
if (x === undefined) x = 0;
if (y === undefined) y = 0;
if (z === undefined) z = 0;
let res = {

@@ -14,0 +17,0 @@ mode: 'xyz50',

const convertRgbToYiq = ({ r, g, b, alpha }) => {
if (r === undefined) r = 0;
if (g === undefined) g = 0;
if (b === undefined) b = 0;
const res = {

@@ -3,0 +6,0 @@ mode: 'yiq',

const convertYiqToRgb = ({ y, i, q, alpha }) => {
if (y === undefined) y = 0;
if (i === undefined) i = 0;
if (q === undefined) q = 0;
const res = {

@@ -3,0 +6,0 @@ mode: 'rgb',

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

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

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 too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc