Sha256: 9a9bee1f85ba91c0b80fefc310ad431733196f32be62fd2eff642158e2d7c328

Contents?: true

Size: 515 Bytes

Versions: 26

Compression:

Stored size: 515 Bytes

Contents

'use strict';

const MAX_HUE = 360;
const COLOR_NB = 12;
const MAX_RGB_VALUE = 255;

// https://www.w3.org/TR/css-color-4/#hsl-to-rgb
exports.hslToRgb = (hue, sat, light) => {
  hue = hue % MAX_HUE;
  if (hue < 0) {
    hue += MAX_HUE;
  }
  function f(n) {
    const k = (n + hue / (MAX_HUE / COLOR_NB)) % COLOR_NB;
    const a = sat * Math.min(light, 1 - light);
    return light - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
  }
  return [f(0), f(8), f(4)].map((value) => Math.round(value * MAX_RGB_VALUE));
};

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/cssstyle/lib/utils/colorSpace.js