First Commit
This commit is contained in:
16
node_modules/culori/src/lch/convertLabToLch.js
generated
vendored
Normal file
16
node_modules/culori/src/lch/convertLabToLch.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import normalizeHue from '../util/normalizeHue.js';
|
||||
|
||||
/*
|
||||
References:
|
||||
* https://drafts.csswg.org/css-color/#lab-to-lch
|
||||
* https://drafts.csswg.org/css-color/#color-conversion-code
|
||||
*/
|
||||
const convertLabToLch = ({ l, a, b, alpha }, mode = 'lch') => {
|
||||
let c = Math.sqrt(a * a + b * b);
|
||||
let res = { mode, l, c };
|
||||
if (c) res.h = normalizeHue((Math.atan2(b, a) * 180) / Math.PI);
|
||||
if (alpha !== undefined) res.alpha = alpha;
|
||||
return res;
|
||||
};
|
||||
|
||||
export default convertLabToLch;
|
17
node_modules/culori/src/lch/convertLchToLab.js
generated
vendored
Normal file
17
node_modules/culori/src/lch/convertLchToLab.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
References:
|
||||
* https://drafts.csswg.org/css-color/#lch-to-lab
|
||||
* https://drafts.csswg.org/css-color/#color-conversion-code
|
||||
*/
|
||||
const convertLchToLab = ({ l, c, h, alpha }, mode = 'lab') => {
|
||||
let res = {
|
||||
mode,
|
||||
l,
|
||||
a: c ? c * Math.cos((h / 180) * Math.PI) : 0,
|
||||
b: c ? c * Math.sin((h / 180) * Math.PI) : 0
|
||||
};
|
||||
if (alpha !== undefined) res.alpha = alpha;
|
||||
return res;
|
||||
};
|
||||
|
||||
export default convertLchToLab;
|
55
node_modules/culori/src/lch/definition.js
generated
vendored
Normal file
55
node_modules/culori/src/lch/definition.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import convertLabToLch from './convertLabToLch.js';
|
||||
import convertLchToLab from './convertLchToLab.js';
|
||||
import convertLabToRgb from '../lab/convertLabToRgb.js';
|
||||
import convertRgbToLab from '../lab/convertRgbToLab.js';
|
||||
import parseLch from './parseLch.js';
|
||||
import { fixupHueShorter } from '../fixup/hue.js';
|
||||
import { fixupAlpha } from '../fixup/alpha.js';
|
||||
import { interpolatorLinear } from '../interpolate/linear.js';
|
||||
import { differenceHueChroma } from '../difference.js';
|
||||
import { averageAngle } from '../average.js';
|
||||
|
||||
const definition = {
|
||||
mode: 'lch',
|
||||
|
||||
toMode: {
|
||||
lab: convertLchToLab,
|
||||
rgb: c => convertLabToRgb(convertLchToLab(c))
|
||||
},
|
||||
|
||||
fromMode: {
|
||||
rgb: c => convertLabToLch(convertRgbToLab(c)),
|
||||
lab: convertLabToLch
|
||||
},
|
||||
|
||||
channels: ['l', 'c', 'h', 'alpha'],
|
||||
|
||||
ranges: {
|
||||
l: [0, 100],
|
||||
c: [0, 150],
|
||||
h: [0, 360]
|
||||
},
|
||||
|
||||
parse: [parseLch],
|
||||
serialize: c =>
|
||||
`lch(${c.l !== undefined ? c.l : 'none'} ${
|
||||
c.c !== undefined ? c.c : 'none'
|
||||
} ${c.h || 0}${c.alpha < 1 ? ` / ${c.alpha}` : ''})`,
|
||||
|
||||
interpolate: {
|
||||
h: { use: interpolatorLinear, fixup: fixupHueShorter },
|
||||
c: interpolatorLinear,
|
||||
l: interpolatorLinear,
|
||||
alpha: { use: interpolatorLinear, fixup: fixupAlpha }
|
||||
},
|
||||
|
||||
difference: {
|
||||
h: differenceHueChroma
|
||||
},
|
||||
|
||||
average: {
|
||||
h: averageAngle
|
||||
}
|
||||
};
|
||||
|
||||
export default definition;
|
34
node_modules/culori/src/lch/parseLch.js
generated
vendored
Normal file
34
node_modules/culori/src/lch/parseLch.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Tok } from '../parse.js';
|
||||
|
||||
function parseLch(color, parsed) {
|
||||
if (!parsed || parsed[0] !== 'lch') {
|
||||
return undefined;
|
||||
}
|
||||
const res = { mode: 'lch' };
|
||||
const [, l, c, h, alpha] = parsed;
|
||||
if (l.type !== Tok.None) {
|
||||
if (l.type === Tok.Hue) {
|
||||
return undefined;
|
||||
}
|
||||
res.l = l.value;
|
||||
}
|
||||
if (c.type !== Tok.None) {
|
||||
res.c = Math.max(
|
||||
0,
|
||||
c.type === Tok.Number ? c.value : (c.value * 150) / 100
|
||||
);
|
||||
}
|
||||
if (h.type !== Tok.None) {
|
||||
if (h.type === Tok.Percentage) {
|
||||
return undefined;
|
||||
}
|
||||
res.h = h.value;
|
||||
}
|
||||
if (alpha.type !== Tok.None) {
|
||||
res.alpha = alpha.type === Tok.Number ? alpha.value : alpha.value / 100;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export default parseLch;
|
Reference in New Issue
Block a user