diff --git a/src/clamp.js b/src/clamp.js index 10a85b83..f634ce09 100644 --- a/src/clamp.js +++ b/src/clamp.js @@ -13,7 +13,7 @@ const fixup_rgb = color => { return c; }; -const clampRgb = color => { +export const clampRgb = color => { color = prepare(color); // if the color is undefined or displayable, return it directly @@ -25,7 +25,7 @@ const clampRgb = color => { return conv(fixup_rgb(color)); }; -const clampChroma = (color, mode = 'lch') => { +export const clampChroma = (color, mode = 'lch') => { color = prepare(color); // if the color is undefined or displayable, return it directly @@ -68,15 +68,3 @@ const clampChroma = (color, mode = 'lch') => { displayable(clamped) ? clamped : { ...clamped, c: _last_good_c } ); }; - -// Deprecated / no longer documented -const clamp = (method = 'rgb') => { - switch (method) { - case 'rgb': - return clampRgb; - case 'lch': - return clampChroma; - } -}; - -export { clampRgb, clampChroma, clamp }; diff --git a/src/deficiency.js b/src/deficiency.js index abb34531..b7f99e9f 100644 --- a/src/deficiency.js +++ b/src/deficiency.js @@ -25,342 +25,132 @@ let rgb = converter('rgb'); const PROT = [ [1.0, 0.0, -0.0, 0.0, 1.0, 0.0, -0.0, -0.0, 1.0], [ - 0.856167, - 0.182038, - -0.038205, - 0.029342, - 0.955115, - 0.015544, - -0.00288, - -0.001563, - 1.004443 + 0.856167, 0.182038, -0.038205, 0.029342, 0.955115, 0.015544, -0.00288, + -0.001563, 1.004443 ], [ - 0.734766, - 0.334872, - -0.069637, - 0.05184, - 0.919198, - 0.028963, - -0.004928, - -0.004209, - 1.009137 + 0.734766, 0.334872, -0.069637, 0.05184, 0.919198, 0.028963, -0.004928, + -0.004209, 1.009137 ], [ - 0.630323, - 0.465641, - -0.095964, - 0.069181, - 0.890046, - 0.040773, - -0.006308, - -0.007724, - 1.014032 + 0.630323, 0.465641, -0.095964, 0.069181, 0.890046, 0.040773, -0.006308, + -0.007724, 1.014032 ], [ - 0.539009, - 0.579343, - -0.118352, - 0.082546, - 0.866121, - 0.051332, - -0.007136, - -0.011959, - 1.019095 + 0.539009, 0.579343, -0.118352, 0.082546, 0.866121, 0.051332, -0.007136, + -0.011959, 1.019095 ], [ - 0.458064, - 0.679578, - -0.137642, - 0.092785, - 0.846313, - 0.060902, - -0.007494, - -0.016807, - 1.024301 + 0.458064, 0.679578, -0.137642, 0.092785, 0.846313, 0.060902, -0.007494, + -0.016807, 1.024301 ], [ - 0.38545, - 0.769005, - -0.154455, - 0.100526, - 0.829802, - 0.069673, - -0.007442, - -0.02219, - 1.029632 + 0.38545, 0.769005, -0.154455, 0.100526, 0.829802, 0.069673, -0.007442, + -0.02219, 1.029632 ], [ - 0.319627, - 0.849633, - -0.169261, - 0.106241, - 0.815969, - 0.07779, - -0.007025, - -0.028051, - 1.035076 + 0.319627, 0.849633, -0.169261, 0.106241, 0.815969, 0.07779, -0.007025, + -0.028051, 1.035076 ], [ - 0.259411, - 0.923008, - -0.18242, - 0.110296, - 0.80434, - 0.085364, - -0.006276, - -0.034346, - 1.040622 + 0.259411, 0.923008, -0.18242, 0.110296, 0.80434, 0.085364, -0.006276, + -0.034346, 1.040622 ], [ - 0.203876, - 0.990338, - -0.194214, - 0.112975, - 0.794542, - 0.092483, - -0.005222, - -0.041043, - 1.046265 + 0.203876, 0.990338, -0.194214, 0.112975, 0.794542, 0.092483, -0.005222, + -0.041043, 1.046265 ], [ - 0.152286, - 1.052583, - -0.204868, - 0.114503, - 0.786281, - 0.099216, - -0.003882, - -0.048116, - 1.051998 + 0.152286, 1.052583, -0.204868, 0.114503, 0.786281, 0.099216, -0.003882, + -0.048116, 1.051998 ] ]; const DEUTER = [ [1.0, 0.0, -0.0, 0.0, 1.0, 0.0, -0.0, -0.0, 1.0], [ - 0.866435, - 0.177704, - -0.044139, - 0.049567, - 0.939063, - 0.01137, - -0.003453, - 0.007233, - 0.99622 + 0.866435, 0.177704, -0.044139, 0.049567, 0.939063, 0.01137, -0.003453, + 0.007233, 0.99622 ], [ - 0.760729, - 0.319078, - -0.079807, - 0.090568, - 0.889315, - 0.020117, - -0.006027, - 0.013325, - 0.992702 + 0.760729, 0.319078, -0.079807, 0.090568, 0.889315, 0.020117, -0.006027, + 0.013325, 0.992702 ], [ - 0.675425, - 0.43385, - -0.109275, - 0.125303, - 0.847755, - 0.026942, - -0.00795, - 0.018572, - 0.989378 + 0.675425, 0.43385, -0.109275, 0.125303, 0.847755, 0.026942, -0.00795, + 0.018572, 0.989378 ], [ - 0.605511, - 0.52856, - -0.134071, - 0.155318, - 0.812366, - 0.032316, - -0.009376, - 0.023176, - 0.9862 + 0.605511, 0.52856, -0.134071, 0.155318, 0.812366, 0.032316, -0.009376, + 0.023176, 0.9862 ], [ - 0.547494, - 0.607765, - -0.155259, - 0.181692, - 0.781742, - 0.036566, - -0.01041, - 0.027275, - 0.983136 + 0.547494, 0.607765, -0.155259, 0.181692, 0.781742, 0.036566, -0.01041, + 0.027275, 0.983136 ], [ - 0.498864, - 0.674741, - -0.173604, - 0.205199, - 0.754872, - 0.039929, - -0.011131, - 0.030969, - 0.980162 + 0.498864, 0.674741, -0.173604, 0.205199, 0.754872, 0.039929, -0.011131, + 0.030969, 0.980162 ], [ - 0.457771, - 0.731899, - -0.18967, - 0.226409, - 0.731012, - 0.042579, - -0.011595, - 0.034333, - 0.977261 + 0.457771, 0.731899, -0.18967, 0.226409, 0.731012, 0.042579, -0.011595, + 0.034333, 0.977261 ], [ - 0.422823, - 0.781057, - -0.203881, - 0.245752, - 0.709602, - 0.044646, - -0.011843, - 0.037423, - 0.974421 + 0.422823, 0.781057, -0.203881, 0.245752, 0.709602, 0.044646, -0.011843, + 0.037423, 0.974421 ], [ - 0.392952, - 0.82361, - -0.216562, - 0.263559, - 0.69021, - 0.046232, - -0.01191, - 0.040281, - 0.97163 + 0.392952, 0.82361, -0.216562, 0.263559, 0.69021, 0.046232, -0.01191, + 0.040281, 0.97163 ], [ - 0.367322, - 0.860646, - -0.227968, - 0.280085, - 0.672501, - 0.047413, - -0.01182, - 0.04294, - 0.968881 + 0.367322, 0.860646, -0.227968, 0.280085, 0.672501, 0.047413, -0.01182, + 0.04294, 0.968881 ] ]; const TRIT = [ [1.0, 0.0, -0.0, 0.0, 1.0, 0.0, -0.0, -0.0, 1.0], [ - 0.92667, - 0.092514, - -0.019184, - 0.021191, - 0.964503, - 0.014306, - 0.008437, - 0.054813, - 0.93675 + 0.92667, 0.092514, -0.019184, 0.021191, 0.964503, 0.014306, 0.008437, + 0.054813, 0.93675 ], [ - 0.89572, - 0.13333, - -0.02905, - 0.029997, - 0.9454, - 0.024603, - 0.013027, - 0.104707, - 0.882266 + 0.89572, 0.13333, -0.02905, 0.029997, 0.9454, 0.024603, 0.013027, + 0.104707, 0.882266 ], [ - 0.905871, - 0.127791, - -0.033662, - 0.026856, - 0.941251, - 0.031893, - 0.01341, - 0.148296, - 0.838294 + 0.905871, 0.127791, -0.033662, 0.026856, 0.941251, 0.031893, 0.01341, + 0.148296, 0.838294 ], [ - 0.948035, - 0.08949, - -0.037526, - 0.014364, - 0.946792, - 0.038844, - 0.010853, - 0.193991, - 0.795156 + 0.948035, 0.08949, -0.037526, 0.014364, 0.946792, 0.038844, 0.010853, + 0.193991, 0.795156 ], [ - 1.017277, - 0.027029, - -0.044306, - -0.006113, - 0.958479, - 0.047634, - 0.006379, - 0.248708, - 0.744913 + 1.017277, 0.027029, -0.044306, -0.006113, 0.958479, 0.047634, 0.006379, + 0.248708, 0.744913 ], [ - 1.104996, - -0.046633, - -0.058363, - -0.032137, - 0.971635, - 0.060503, - 0.001336, - 0.317922, - 0.680742 + 1.104996, -0.046633, -0.058363, -0.032137, 0.971635, 0.060503, 0.001336, + 0.317922, 0.680742 ], [ - 1.193214, - -0.109812, - -0.083402, - -0.058496, - 0.97941, - 0.079086, - -0.002346, - 0.403492, - 0.598854 + 1.193214, -0.109812, -0.083402, -0.058496, 0.97941, 0.079086, -0.002346, + 0.403492, 0.598854 ], [ - 1.257728, - -0.139648, - -0.118081, - -0.078003, - 0.975409, - 0.102594, - -0.003316, - 0.501214, - 0.502102 + 1.257728, -0.139648, -0.118081, -0.078003, 0.975409, 0.102594, + -0.003316, 0.501214, 0.502102 ], [ - 1.278864, - -0.125333, - -0.153531, - -0.084748, - 0.957674, - 0.127074, - -0.000989, - 0.601151, - 0.399838 + 1.278864, -0.125333, -0.153531, -0.084748, 0.957674, 0.127074, + -0.000989, 0.601151, 0.399838 ], [ - 1.255528, - -0.076749, - -0.178779, - -0.078411, - 0.930809, - 0.147602, - 0.004733, - 0.691367, - 0.3039 + 1.255528, -0.076749, -0.178779, -0.078411, 0.930809, 0.147602, 0.004733, + 0.691367, 0.3039 ] ]; @@ -392,8 +182,9 @@ const deficiency = (lut, t) => { }; }; -const deficiencyProt = (severity = 1) => deficiency(PROT, severity); -const deficiencyDeuter = (severity = 1) => deficiency(DEUTER, severity); -const deficiencyTrit = (severity = 1) => deficiency(TRIT, severity); - -export { deficiencyProt, deficiencyDeuter, deficiencyTrit }; +export const filterDeficiencyProt = (severity = 1) => + deficiency(PROT, severity); +export const filterDeficiencyDeuter = (severity = 1) => + deficiency(DEUTER, severity); +export const filterDeficiencyTrit = (severity = 1) => + deficiency(TRIT, severity); diff --git a/src/formatter.js b/src/formatter.js index 78695d3a..8d40d1df 100644 --- a/src/formatter.js +++ b/src/formatter.js @@ -10,7 +10,7 @@ let twoDecimals = round(2); const clamp = value => Math.max(0, Math.min(1, value)); const fixup = value => Math.round(clamp(value) * 255); -const formatHex = c => { +export const formatHex = c => { let color = rgb(c); if (color === undefined) { @@ -24,7 +24,7 @@ const formatHex = c => { return '#' + ((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1); }; -const formatHex8 = c => { +export const formatHex8 = c => { let color = rgb(c); if (color === undefined) { @@ -36,7 +36,7 @@ const formatHex8 = c => { return formatHex(color) + ((1 << 8) | a).toString(16).slice(1); }; -const formatRgb = c => { +export const formatRgb = c => { let color = rgb(c); if (color === undefined) { @@ -56,7 +56,7 @@ const formatRgb = c => { } }; -const formatHsl = c => { +export const formatHsl = c => { let color = hsl(c); if (color === undefined) { @@ -76,7 +76,7 @@ const formatHsl = c => { } }; -const formatCss = c => { +export const formatCss = c => { const color = prepare(c); if (!color) { return undefined; @@ -99,16 +99,3 @@ const formatCss = c => { } return undefined; }; - -// Deprecated / no longer documented -const formatter = (format = 'rgb') => { - switch (format) { - case 'rgb': - return formatRgb; - case 'hex': - return formatHex; - } - return undefined; -}; - -export { formatHex, formatHex8, formatRgb, formatHsl, formatCss, formatter }; diff --git a/src/index.js b/src/index.js index e7217ac6..cd3969bb 100644 --- a/src/index.js +++ b/src/index.js @@ -114,7 +114,6 @@ export { }; export { - formatter, formatHex, formatHex8, formatRgb, @@ -128,30 +127,21 @@ export { interpolateWithPremultipliedAlpha } from './interpolate/interpolate'; -export { - interpolateLinear, // @deprecated - interpolatorLinear -} from './interpolate/linear'; +export { interpolatorLinear } from './interpolate/linear'; export { interpolatorPiecewise } from './interpolate/piecewise'; -// @deprecated -export { default as interpolateCosine } from './interpolate/cosine'; - export { - interpolateSplineBasis, // @deprecated interpolatorSplineBasis, interpolatorSplineBasisClosed } from './interpolate/splineBasis'; export { - interpolateSplineNatural, // @deprecated interpolatorSplineNatural, interpolatorSplineNaturalClosed } from './interpolate/splineNatural'; export { - interpolateSplineMonotone, // @deprecated interpolatorSplineMonotone, interpolatorSplineMonotone2, interpolatorSplineMonotoneClosed @@ -160,7 +150,7 @@ export { export { default as lerp } from './interpolate/lerp'; export { default as samples } from './samples'; export { default as displayable } from './displayable'; -export { clamp, clampRgb, clampChroma } from './clamp'; +export { clampRgb, clampChroma } from './clamp'; export { default as nearest } from './nearest'; export { getModeDefinition } from './modes'; export { default as parse } from './parse'; @@ -191,27 +181,19 @@ export { default as easingGamma } from './easing/gamma'; export { luminance as wcagLuminance, contrast as wcagContrast } from './wcag'; export { - deficiencyProt as filterDeficiencyProt, - deficiencyDeuter as filterDeficiencyDeuter, - deficiencyTrit as filterDeficiencyTrit, - // @deprecated - deficiencyProt, - deficiencyDeuter, - deficiencyTrit + filterDeficiencyProt, + filterDeficiencyDeuter, + filterDeficiencyTrit } from './deficiency'; export { - fixupHueShorter as interpolateHue, // @deprecated fixupHueShorter, fixupHueLonger, fixupHueIncreasing, fixupHueDecreasing } from './fixup/hue'; -export { - fixupAlpha, - fixupAlpha as interpolateAlpha // @deprecated -} from './fixup/alpha'; +export { fixupAlpha } from './fixup/alpha'; export { mapper, diff --git a/src/interpolate/cosine.js b/src/interpolate/cosine.js deleted file mode 100644 index e952b405..00000000 --- a/src/interpolate/cosine.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - Cosine interpolation - -------------------- - - Reference: - - http://paulbourke.net/miscellaneous/interpolation/ - */ - -import lerp from './lerp'; -import easeInOutSine from '../easing/inOutSine'; -import gamma from '../easing/gamma'; -import { interpolatorPiecewise } from './piecewise'; - -// @deprecated -const cosine = (fixup, γ = 1) => arr => { - let ease = gamma(γ); - let interpolator = interpolatorPiecewise((a, b, t) => - lerp(a, b, easeInOutSine(t)) - )((fixup || (v => v))(arr)); - return t => interpolator(ease(t)); -}; - -export default cosine; diff --git a/src/interpolate/linear.js b/src/interpolate/linear.js index 1863b631..d9d93b47 100644 --- a/src/interpolate/linear.js +++ b/src/interpolate/linear.js @@ -1,16 +1,4 @@ import lerp from './lerp'; -import gamma from '../easing/gamma'; import { interpolatorPiecewise } from './piecewise'; -const interpolatorLinear = interpolatorPiecewise(lerp); - -const interpolateLinear = (fixup, γ = 1) => arr => { - let ease = gamma(γ); - return t => interpolatorLinear((fixup || (v => v))(arr))(ease(t)); -}; - -export { - interpolatorLinear, - // legacy - interpolateLinear -}; +export const interpolatorLinear = interpolatorPiecewise(lerp); diff --git a/src/interpolate/splineBasis.js b/src/interpolate/splineBasis.js index dfdb6f63..fc887c8b 100644 --- a/src/interpolate/splineBasis.js +++ b/src/interpolate/splineBasis.js @@ -1,5 +1,3 @@ -import gamma from '../easing/gamma'; - /* Basis spline ------------ @@ -35,7 +33,7 @@ const bspline = (Vim2, Vim1, Vi, Vip1, t) => { ); }; -const interpolatorSplineBasis = arr => t => { +export const interpolatorSplineBasis = arr => t => { let classes = arr.length - 1; let i = t >= 1 ? classes - 1 : Math.max(0, Math.floor(t * classes)); return bspline( @@ -47,7 +45,7 @@ const interpolatorSplineBasis = arr => t => { ); }; -const interpolatorSplineBasisClosed = arr => t => { +export const interpolatorSplineBasisClosed = arr => t => { const classes = arr.length - 1; const i = Math.floor(t * classes); return bspline( @@ -58,24 +56,3 @@ const interpolatorSplineBasisClosed = arr => t => { (t - i / classes) * classes ); }; - -const interpolateSplineBasis = - (fixup, type = 'default', γ = 1) => - arr => { - let ease = gamma(γ); - if (type === 'default') { - return t => - interpolatorSplineBasis((fixup || (v => v))(arr))(ease(t)); - } else if (type === 'closed') { - return t => - interpolatorSplineBasisClosed((fixup || (v => v))(arr))( - ease(t) - ); - } - }; - -export { - interpolateSplineBasis, - interpolatorSplineBasis, - interpolatorSplineBasisClosed -}; diff --git a/src/interpolate/splineMonotone.js b/src/interpolate/splineMonotone.js index dac3da47..17657123 100644 --- a/src/interpolate/splineMonotone.js +++ b/src/interpolate/splineMonotone.js @@ -1,4 +1,3 @@ -import gamma from '../easing/gamma'; import { interpolatorLinear } from './linear'; /* @@ -65,7 +64,7 @@ const interpolator = (arr, yp, s) => { A monotone spline which uses one-sided finite differences at the boundaries. */ -const interpolatorSplineMonotone = arr => { +export const interpolatorSplineMonotone = arr => { if (arr.length < 3) { return interpolatorLinear(arr); } @@ -85,7 +84,7 @@ const interpolatorSplineMonotone = arr => { linear interpolation. */ -const interpolatorSplineMonotone2 = arr => { +export const interpolatorSplineMonotone2 = arr => { if (arr.length < 3) { return interpolatorLinear(arr); } @@ -112,7 +111,7 @@ const interpolatorSplineMonotone2 = arr => { ...and so on. */ -const interpolatorSplineMonotoneClosed = arr => { +export const interpolatorSplineMonotoneClosed = arr => { let n = arr.length - 1; let [s, p, yp] = mono(arr); // boundary conditions @@ -127,25 +126,3 @@ const interpolatorSplineMonotoneClosed = arr => { min(abs(s[n - 1]), abs(s_n), 0.5 * abs(p[n])); return interpolator(arr, yp, s); }; - -const interpolateSplineMonotone = - (fixup, type = 'default', γ = 1) => - arr => { - let ease = gamma(γ); - if (type === 'closed') { - return t => - interpolatorSplineMonotoneClosed((fixup || (v => v))(arr))( - ease(t) - ); - } else if (type === 'default') { - return t => - interpolatorSplineMonotone((fixup || (v => v))(arr))(ease(t)); - } - }; - -export { - interpolateSplineMonotone, - interpolatorSplineMonotone, - interpolatorSplineMonotone2, - interpolatorSplineMonotoneClosed -}; diff --git a/src/interpolate/splineNatural.js b/src/interpolate/splineNatural.js index 09d1ad76..1f33bc8e 100644 --- a/src/interpolate/splineNatural.js +++ b/src/interpolate/splineNatural.js @@ -2,7 +2,6 @@ import { interpolatorSplineBasisClosed, interpolatorSplineBasis } from './splineBasis'; -import gamma from '../easing/gamma'; const solve = v => { let i; @@ -32,23 +31,7 @@ const solve = v => { return sol; }; -const interpolatorSplineNatural = arr => interpolatorSplineBasis(solve(arr)); -const interpolatorSplineNaturalClosed = arr => +export const interpolatorSplineNatural = arr => + interpolatorSplineBasis(solve(arr)); +export const interpolatorSplineNaturalClosed = arr => interpolatorSplineBasisClosed(solve(arr)); - -const interpolateSplineNatural = (fixup, type = 'default', γ = 1) => arr => { - let ease = gamma(γ); - if (type === 'default') { - return t => - interpolatorSplineNatural((fixup || (v => v))(arr))(ease(t)); - } else if (type === 'closed') { - return t => - interpolatorSplineNaturalClosed((fixup || (v => v))(arr))(ease(t)); - } -}; - -export { - interpolateSplineNatural, - interpolatorSplineNatural, - interpolatorSplineNaturalClosed -}; diff --git a/test/interpolate-legacy.test.js b/test/interpolate-legacy.test.js deleted file mode 100644 index 1a83bf05..00000000 --- a/test/interpolate-legacy.test.js +++ /dev/null @@ -1,20 +0,0 @@ -/* - Interpolation: legacy API - */ - -import tape from 'tape'; -import { - interpolate, - interpolateLinear, - interpolateHue, - formatHex -} from '../src/index'; - -tape('custom interpolators', t => { - let interpolator = interpolate(['red', 'green'], 'hsv', { - h: interpolateLinear(interpolateHue) - }); - - t.deepEqual(formatHex(interpolator(0.5)), '#c0c000'); - t.end(); -});