ch prefix
This commit is contained in:
6
frontend/node_modules/culori/src/lab/convertLabToRgb.js
generated
vendored
Normal file
6
frontend/node_modules/culori/src/lab/convertLabToRgb.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import convertLabToXyz50 from './convertLabToXyz50.js';
|
||||
import convertXyz50ToRgb from '../xyz50/convertXyz50ToRgb.js';
|
||||
|
||||
const convertLabToRgb = lab => convertXyz50ToRgb(convertLabToXyz50(lab));
|
||||
|
||||
export default convertLabToRgb;
|
||||
25
frontend/node_modules/culori/src/lab/convertLabToXyz50.js
generated
vendored
Normal file
25
frontend/node_modules/culori/src/lab/convertLabToXyz50.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { k, e } from '../xyz50/constants.js';
|
||||
import { D50 } from '../constants.js';
|
||||
|
||||
let fn = v => (Math.pow(v, 3) > e ? Math.pow(v, 3) : (116 * v - 16) / k);
|
||||
|
||||
const convertLabToXyz50 = ({ l, a, b, alpha }) => {
|
||||
let fy = (l + 16) / 116;
|
||||
let fx = a / 500 + fy;
|
||||
let fz = fy - b / 200;
|
||||
|
||||
let res = {
|
||||
mode: 'xyz50',
|
||||
x: fn(fx) * D50.X,
|
||||
y: fn(fy) * D50.Y,
|
||||
z: fn(fz) * D50.Z
|
||||
};
|
||||
|
||||
if (alpha !== undefined) {
|
||||
res.alpha = alpha;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export default convertLabToXyz50;
|
||||
16
frontend/node_modules/culori/src/lab/convertRgbToLab.js
generated
vendored
Normal file
16
frontend/node_modules/culori/src/lab/convertRgbToLab.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import convertRgbToXyz50 from '../xyz50/convertRgbToXyz50.js';
|
||||
import convertXyz50ToLab from './convertXyz50ToLab.js';
|
||||
|
||||
const convertRgbToLab = rgb => {
|
||||
let res = convertXyz50ToLab(convertRgbToXyz50(rgb));
|
||||
|
||||
// Fixes achromatic RGB colors having a _slight_ chroma due to floating-point errors
|
||||
// and approximated computations in sRGB <-> CIELab.
|
||||
// See: https://github.com/d3/d3-color/pull/46
|
||||
if (rgb.r === rgb.b && rgb.b === rgb.g) {
|
||||
res.a = res.b = 0;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
export default convertRgbToLab;
|
||||
25
frontend/node_modules/culori/src/lab/convertXyz50ToLab.js
generated
vendored
Normal file
25
frontend/node_modules/culori/src/lab/convertXyz50ToLab.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { k, e } from '../xyz50/constants.js';
|
||||
import { D50 } from '../constants.js';
|
||||
|
||||
const f = value => (value > e ? Math.cbrt(value) : (k * value + 16) / 116);
|
||||
|
||||
const convertXyz50ToLab = ({ x, y, z, alpha }) => {
|
||||
let f0 = f(x / D50.X);
|
||||
let f1 = f(y / D50.Y);
|
||||
let f2 = f(z / D50.Z);
|
||||
|
||||
let res = {
|
||||
mode: 'lab',
|
||||
l: 116 * f1 - 16,
|
||||
a: 500 * (f0 - f1),
|
||||
b: 200 * (f1 - f2)
|
||||
};
|
||||
|
||||
if (alpha !== undefined) {
|
||||
res.alpha = alpha;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export default convertXyz50ToLab;
|
||||
46
frontend/node_modules/culori/src/lab/definition.js
generated
vendored
Normal file
46
frontend/node_modules/culori/src/lab/definition.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import convertLabToRgb from './convertLabToRgb.js';
|
||||
import convertLabToXyz50 from './convertLabToXyz50.js';
|
||||
import convertRgbToLab from './convertRgbToLab.js';
|
||||
import convertXyz50ToLab from './convertXyz50ToLab.js';
|
||||
import parseLab from './parseLab.js';
|
||||
import { interpolatorLinear } from '../interpolate/linear.js';
|
||||
import { fixupAlpha } from '../fixup/alpha.js';
|
||||
|
||||
const definition = {
|
||||
mode: 'lab',
|
||||
|
||||
toMode: {
|
||||
xyz50: convertLabToXyz50,
|
||||
rgb: convertLabToRgb
|
||||
},
|
||||
|
||||
fromMode: {
|
||||
xyz50: convertXyz50ToLab,
|
||||
rgb: convertRgbToLab
|
||||
},
|
||||
|
||||
channels: ['l', 'a', 'b', 'alpha'],
|
||||
|
||||
ranges: {
|
||||
l: [0, 100],
|
||||
a: [-100, 100],
|
||||
b: [-100, 100]
|
||||
},
|
||||
|
||||
parse: [parseLab],
|
||||
serialize: c =>
|
||||
`lab(${c.l !== undefined ? c.l : 'none'} ${
|
||||
c.a !== undefined ? c.a : 'none'
|
||||
} ${c.b !== undefined ? c.b : 'none'}${
|
||||
c.alpha < 1 ? ` / ${c.alpha}` : ''
|
||||
})`,
|
||||
|
||||
interpolate: {
|
||||
l: interpolatorLinear,
|
||||
a: interpolatorLinear,
|
||||
b: interpolatorLinear,
|
||||
alpha: { use: interpolatorLinear, fixup: fixupAlpha }
|
||||
}
|
||||
};
|
||||
|
||||
export default definition;
|
||||
28
frontend/node_modules/culori/src/lab/parseLab.js
generated
vendored
Normal file
28
frontend/node_modules/culori/src/lab/parseLab.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Tok } from '../parse.js';
|
||||
|
||||
function parseLab(color, parsed) {
|
||||
if (!parsed || parsed[0] !== 'lab') {
|
||||
return undefined;
|
||||
}
|
||||
const res = { mode: 'lab' };
|
||||
const [, l, a, b, alpha] = parsed;
|
||||
if (l.type === Tok.Hue || a.type === Tok.Hue || b.type === Tok.Hue) {
|
||||
return undefined;
|
||||
}
|
||||
if (l.type !== Tok.None) {
|
||||
res.l = l.value;
|
||||
}
|
||||
if (a.type !== Tok.None) {
|
||||
res.a = a.type === Tok.Number ? a.value : (a.value * 125) / 100;
|
||||
}
|
||||
if (b.type !== Tok.None) {
|
||||
res.b = b.type === Tok.Number ? b.value : (b.value * 125) / 100;
|
||||
}
|
||||
if (alpha.type !== Tok.None) {
|
||||
res.alpha = alpha.type === Tok.Number ? alpha.value : alpha.value / 100;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export default parseLab;
|
||||
Reference in New Issue
Block a user