Blame view

node_modules/stylus/lib/functions/hsla.js 1.29 KB
ce4c83ff   wxy   初始提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  var utils = require('../utils')
    , nodes = require('../nodes');
  
  /**
   * Convert the given `color` to an `HSLA` node,
   * or h,s,l,a component values.
   *
   * Examples:
   *
   *    hsla(10deg, 50%, 30%, 0.5)
   *    // => HSLA
   *
   *    hsla(#ffcc00)
   *    // => HSLA
   *
   * @param {RGBA|HSLA|Unit} hue
   * @param {Unit} saturation
   * @param {Unit} lightness
   * @param {Unit} alpha
   * @return {HSLA}
   * @api public
   */
  
  module.exports = function hsla(hue, saturation, lightness, alpha){
    switch (arguments.length) {
      case 1:
        utils.assertColor(hue);
        return hue.hsla;
      case 2:
        utils.assertColor(hue);
        var color = hue.hsla;
        utils.assertType(saturation, 'unit', 'alpha');
        var alpha = saturation.clone();
        if ('%' == alpha.type) alpha.val /= 100;
        return new nodes.HSLA(
            color.h
          , color.s
          , color.l
          , alpha.val);
      default:
        utils.assertType(hue, 'unit', 'hue');
        utils.assertType(saturation, 'unit', 'saturation');
        utils.assertType(lightness, 'unit', 'lightness');
        utils.assertType(alpha, 'unit', 'alpha');
        var alpha = alpha.clone();
        if (alpha && '%' == alpha.type) alpha.val /= 100;
        return new nodes.HSLA(
            hue.val
          , saturation.val
          , lightness.val
          , alpha.val);
    }
  };