stylus-source 0.15.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/.DS_Store +0 -0
  2. data/README.md +3 -0
  3. data/lib/.DS_Store +0 -0
  4. data/lib/node_modules/cssom/.idea/CSSOM.iml +9 -0
  5. data/lib/node_modules/cssom/.idea/dictionaries/nv.xml +3 -0
  6. data/lib/node_modules/cssom/.idea/encodings.xml +5 -0
  7. data/lib/node_modules/cssom/.idea/misc.xml +17 -0
  8. data/lib/node_modules/cssom/.idea/modules.xml +9 -0
  9. data/lib/node_modules/cssom/.idea/projectCodeStyle.xml +82 -0
  10. data/lib/node_modules/cssom/.idea/vcs.xml +8 -0
  11. data/lib/node_modules/cssom/.idea/workspace.xml +467 -0
  12. data/lib/node_modules/cssom/.livereload +19 -0
  13. data/lib/node_modules/cssom/Jakefile +37 -0
  14. data/lib/node_modules/cssom/README.mdown +33 -0
  15. data/lib/node_modules/cssom/Rakefile +23 -0
  16. data/lib/node_modules/cssom/docs/.livereload +19 -0
  17. data/lib/node_modules/cssom/docs/bar.css +3 -0
  18. data/lib/node_modules/cssom/docs/demo.css +0 -0
  19. data/lib/node_modules/cssom/docs/foo.css +4 -0
  20. data/lib/node_modules/cssom/docs/parse.html +170 -0
  21. data/lib/node_modules/cssom/docs/parse2.html +431 -0
  22. data/lib/node_modules/cssom/index.html +100 -0
  23. data/lib/node_modules/cssom/lib/CSSImportRule.js +34 -0
  24. data/lib/node_modules/cssom/lib/CSSMediaRule.js +38 -0
  25. data/lib/node_modules/cssom/lib/CSSOM.js +3 -0
  26. data/lib/node_modules/cssom/lib/CSSRule.js +38 -0
  27. data/lib/node_modules/cssom/lib/CSSStyleDeclaration.js +130 -0
  28. data/lib/node_modules/cssom/lib/CSSStyleRule.js +187 -0
  29. data/lib/node_modules/cssom/lib/CSSStyleSheet.js +85 -0
  30. data/lib/node_modules/cssom/lib/MediaList.js +61 -0
  31. data/lib/node_modules/cssom/lib/StyleSheet.js +15 -0
  32. data/lib/node_modules/cssom/lib/clone.js +69 -0
  33. data/lib/node_modules/cssom/lib/index.js +10 -0
  34. data/lib/node_modules/cssom/lib/parse.js +195 -0
  35. data/lib/node_modules/cssom/media.html +17 -0
  36. data/lib/node_modules/cssom/package.json +30 -0
  37. data/lib/node_modules/cssom/plugins/toHTML.js +32 -0
  38. data/lib/node_modules/cssom/server/index.html +22 -0
  39. data/lib/node_modules/cssom/server/index.js +21 -0
  40. data/lib/node_modules/cssom/shorthands.html +21 -0
  41. data/lib/node_modules/cssom/test/CSSStyleDeclaration.test.js +35 -0
  42. data/lib/node_modules/cssom/test/CSSStyleRule.test.js +12 -0
  43. data/lib/node_modules/cssom/test/CSSStyleSheet.test.js +16 -0
  44. data/lib/node_modules/cssom/test/MediaList.test.js +21 -0
  45. data/lib/node_modules/cssom/test/clone.test.js +38 -0
  46. data/lib/node_modules/cssom/test/fixtures/dummy.css +3 -0
  47. data/lib/node_modules/cssom/test/helper.js +97 -0
  48. data/lib/node_modules/cssom/test/index.html +42 -0
  49. data/lib/node_modules/cssom/test/parse.test.js +346 -0
  50. data/lib/node_modules/cssom/test/vendor/qunit.css +189 -0
  51. data/lib/node_modules/cssom/test/vendor/qunit.js +1341 -0
  52. data/lib/node_modules/growl/History.md +16 -0
  53. data/lib/node_modules/growl/Readme.md +74 -0
  54. data/lib/node_modules/growl/lib/growl.js +82 -0
  55. data/lib/node_modules/growl/package.json +6 -0
  56. data/lib/node_modules/growl/test.js +17 -0
  57. data/lib/stylus/colors.js +156 -0
  58. data/lib/stylus/convert/css.js +130 -0
  59. data/lib/stylus/errors.js +58 -0
  60. data/lib/stylus/functions/image.js +120 -0
  61. data/lib/stylus/functions/index.js +722 -0
  62. data/lib/stylus/functions/index.styl +123 -0
  63. data/lib/stylus/functions/url.js +98 -0
  64. data/lib/stylus/lexer.js +728 -0
  65. data/lib/stylus/middleware.js +223 -0
  66. data/lib/stylus/nodes/arguments.js +65 -0
  67. data/lib/stylus/nodes/binop.js +54 -0
  68. data/lib/stylus/nodes/block.js +99 -0
  69. data/lib/stylus/nodes/boolean.js +103 -0
  70. data/lib/stylus/nodes/call.js +57 -0
  71. data/lib/stylus/nodes/charset.js +42 -0
  72. data/lib/stylus/nodes/comment.js +32 -0
  73. data/lib/stylus/nodes/each.js +56 -0
  74. data/lib/stylus/nodes/expression.js +168 -0
  75. data/lib/stylus/nodes/fontface.js +55 -0
  76. data/lib/stylus/nodes/function.js +104 -0
  77. data/lib/stylus/nodes/group.js +79 -0
  78. data/lib/stylus/nodes/hsla.js +256 -0
  79. data/lib/stylus/nodes/ident.js +127 -0
  80. data/lib/stylus/nodes/if.js +55 -0
  81. data/lib/stylus/nodes/import.js +30 -0
  82. data/lib/stylus/nodes/index.js +52 -0
  83. data/lib/stylus/nodes/jsliteral.js +32 -0
  84. data/lib/stylus/nodes/keyframes.js +78 -0
  85. data/lib/stylus/nodes/literal.js +92 -0
  86. data/lib/stylus/nodes/media.js +42 -0
  87. data/lib/stylus/nodes/node.js +209 -0
  88. data/lib/stylus/nodes/null.js +72 -0
  89. data/lib/stylus/nodes/page.js +43 -0
  90. data/lib/stylus/nodes/params.js +72 -0
  91. data/lib/stylus/nodes/property.js +72 -0
  92. data/lib/stylus/nodes/return.js +44 -0
  93. data/lib/stylus/nodes/rgba.js +335 -0
  94. data/lib/stylus/nodes/root.js +50 -0
  95. data/lib/stylus/nodes/selector.js +57 -0
  96. data/lib/stylus/nodes/string.js +120 -0
  97. data/lib/stylus/nodes/ternary.js +51 -0
  98. data/lib/stylus/nodes/unaryop.js +46 -0
  99. data/lib/stylus/nodes/unit.js +207 -0
  100. data/lib/stylus/parser.js +1514 -0
  101. data/lib/stylus/renderer.js +157 -0
  102. data/lib/stylus/source.rb +7 -0
  103. data/lib/stylus/stack/frame.js +66 -0
  104. data/lib/stylus/stack/index.js +146 -0
  105. data/lib/stylus/stack/scope.js +53 -0
  106. data/lib/stylus/stylus.js +102 -0
  107. data/lib/stylus/token.js +53 -0
  108. data/lib/stylus/utils.js +237 -0
  109. data/lib/stylus/visitor/compiler.js +472 -0
  110. data/lib/stylus/visitor/evaluator.js +1070 -0
  111. data/lib/stylus/visitor/index.js +31 -0
  112. data/stylus-source.gemspec +15 -0
  113. metadata +158 -0
@@ -0,0 +1,72 @@
1
+
2
+ /*!
3
+ * Stylus - Null
4
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
5
+ * MIT Licensed
6
+ */
7
+
8
+ /**
9
+ * Module dependencies.
10
+ */
11
+
12
+ var Node = require('./node')
13
+ , nodes = require('./');
14
+
15
+ /**
16
+ * Initialize a new `Null` node.
17
+ *
18
+ * @api public
19
+ */
20
+
21
+ var Null = module.exports = function Null(){};
22
+
23
+ /**
24
+ * Inherit from `Node.prototype`.
25
+ */
26
+
27
+ Null.prototype.__proto__ = Node.prototype;
28
+
29
+ /**
30
+ * Return 'Null'.
31
+ *
32
+ * @return {String}
33
+ * @api public
34
+ */
35
+
36
+ Null.prototype.inspect =
37
+ Null.prototype.toString = function(){
38
+ return 'null';
39
+ };
40
+
41
+ /**
42
+ * Return false.
43
+ *
44
+ * @return {Boolean}
45
+ * @api public
46
+ */
47
+
48
+ Null.prototype.toBoolean = function(){
49
+ return nodes.false;
50
+ };
51
+
52
+ /**
53
+ * Check if the node is a null node.
54
+ *
55
+ * @return {Boolean}
56
+ * @api public
57
+ */
58
+
59
+ Null.prototype.__defineGetter__('isNull', function(){
60
+ return true;
61
+ });
62
+
63
+ /**
64
+ * Return hash.
65
+ *
66
+ * @return {String}
67
+ * @api public
68
+ */
69
+
70
+ Null.prototype.__defineGetter__('hash', function(){
71
+ return null;
72
+ });
@@ -0,0 +1,43 @@
1
+
2
+ /*!
3
+ * Stylus - Page
4
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
5
+ * MIT Licensed
6
+ */
7
+
8
+ /**
9
+ * Module dependencies.
10
+ */
11
+
12
+ var Node = require('./node');
13
+
14
+ /**
15
+ * Initialize a new `Page` with the given `selector` and `block`.
16
+ *
17
+ * @param {Selector} selector
18
+ * @param {Block} block
19
+ * @api public
20
+ */
21
+
22
+ var Page = module.exports = function Page(selector, block){
23
+ Node.call(this);
24
+ this.selector = selector;
25
+ this.block = block;
26
+ };
27
+
28
+ /**
29
+ * Inherit from `Node.prototype`.
30
+ */
31
+
32
+ Page.prototype.__proto__ = Node.prototype;
33
+
34
+ /**
35
+ * Return `@oage name`.
36
+ *
37
+ * @return {String}
38
+ * @api public
39
+ */
40
+
41
+ Page.prototype.toString = function(){
42
+ return '@page ' + this.selector;
43
+ };
@@ -0,0 +1,72 @@
1
+
2
+ /*!
3
+ * Stylus - Params
4
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
5
+ * MIT Licensed
6
+ */
7
+
8
+ /**
9
+ * Module dependencies.
10
+ */
11
+
12
+ var Node = require('./node');
13
+
14
+ /**
15
+ * Initialize a new `Params` with `name`, `params`, and `body`.
16
+ *
17
+ * @param {String} name
18
+ * @param {Params} params
19
+ * @param {Expression} body
20
+ * @api public
21
+ */
22
+
23
+ var Params = module.exports = function Params(){
24
+ Node.call(this);
25
+ this.nodes = [];
26
+ };
27
+
28
+ /**
29
+ * Check function arity.
30
+ *
31
+ * @return {Boolean}
32
+ * @api public
33
+ */
34
+
35
+ Params.prototype.__defineGetter__('length', function(){
36
+ return this.nodes.length;
37
+ });
38
+
39
+ /**
40
+ * Inherit from `Node.prototype`.
41
+ */
42
+
43
+ Params.prototype.__proto__ = Node.prototype;
44
+
45
+ /**
46
+ * Push the given `node`.
47
+ *
48
+ * @param {Node} node
49
+ * @api public
50
+ */
51
+
52
+ Params.prototype.push = function(node){
53
+ this.nodes.push(node);
54
+ };
55
+
56
+ /**
57
+ * Return a clone of this node.
58
+ *
59
+ * @return {Node}
60
+ * @api public
61
+ */
62
+
63
+ Params.prototype.clone = function(){
64
+ var clone = new Params;
65
+ clone.lineno = this.lineno;
66
+ clone.filename = this.filename;
67
+ this.nodes.forEach(function(node){
68
+ clone.push(node.clone());
69
+ });
70
+ return clone;
71
+ };
72
+
@@ -0,0 +1,72 @@
1
+
2
+ /*!
3
+ * Stylus - Property
4
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
5
+ * MIT Licensed
6
+ */
7
+
8
+ /**
9
+ * Module dependencies.
10
+ */
11
+
12
+ var Node = require('./node');
13
+
14
+ /**
15
+ * Initialize a new `Property` with the given `segs` and optional `expr`.
16
+ *
17
+ * @param {Array} segs
18
+ * @param {Expression} expr
19
+ * @api public
20
+ */
21
+
22
+ var Property = module.exports = function Property(segs, expr){
23
+ Node.call(this);
24
+ this.segments = segs;
25
+ this.expr = expr;
26
+ };
27
+
28
+ /**
29
+ * Inherit from `Node.prototype`.
30
+ */
31
+
32
+ Property.prototype.__proto__ = Node.prototype;
33
+
34
+ /**
35
+ * Return a clone of this node.
36
+ *
37
+ * @return {Node}
38
+ * @api public
39
+ */
40
+
41
+ Property.prototype.clone = function(){
42
+ var clone = new Property(this.segments);
43
+ clone.lineno = this.lineno;
44
+ clone.filename = this.filename;
45
+ clone.segments = this.segments.map(function(node){ return node.clone(); });
46
+ if (this.expr) clone.expr = this.expr.clone();
47
+ return clone;
48
+ };
49
+
50
+ /**
51
+ * Return string representation of this node.
52
+ *
53
+ * @return {String}
54
+ * @api public
55
+ */
56
+
57
+ Property.prototype.toString = function(){
58
+ return 'property(' + this.name + ', ' + this.expr + ')';
59
+ };
60
+
61
+ /**
62
+ * Operate on the property expression.
63
+ *
64
+ * @param {String} op
65
+ * @param {Node} right
66
+ * @return {Node}
67
+ * @api public
68
+ */
69
+
70
+ Property.prototype.operate = function(op, right, val){
71
+ return this.expr.operate(op, right, val);
72
+ };
@@ -0,0 +1,44 @@
1
+
2
+ /*!
3
+ * Stylus - Return
4
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
5
+ * MIT Licensed
6
+ */
7
+
8
+ /**
9
+ * Module dependencies.
10
+ */
11
+
12
+ var Node = require('./node')
13
+ , nodes = require('./');
14
+
15
+ /**
16
+ * Initialize a new `Return` node with the given `expr`.
17
+ *
18
+ * @param {Expression} expr
19
+ * @api public
20
+ */
21
+
22
+ var Return = module.exports = function Return(expr){
23
+ this.expr = expr || nodes.null;
24
+ };
25
+
26
+ /**
27
+ * Inherit from `Node.prototype`.
28
+ */
29
+
30
+ Return.prototype.__proto__ = Node.prototype;
31
+
32
+ /**
33
+ * Return a clone of this node.
34
+ *
35
+ * @return {Node}
36
+ * @api public
37
+ */
38
+
39
+ Return.prototype.clone = function(){
40
+ var clone = new Return(this.expr.clone());
41
+ clone.lineno = this.lineno;
42
+ clone.filename = this.filename;
43
+ return clone;
44
+ };
@@ -0,0 +1,335 @@
1
+
2
+ /*!
3
+ * Stylus - RGBA
4
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
5
+ * MIT Licensed
6
+ */
7
+
8
+ /**
9
+ * Module dependencies.
10
+ */
11
+
12
+ var Node = require('./node')
13
+ , HSLA = require('./hsla')
14
+ , nodes = require('./');
15
+
16
+ /**
17
+ * Initialize a new `RGBA` with the given r,g,b,a component values.
18
+ *
19
+ * @param {Number} r
20
+ * @param {Number} g
21
+ * @param {Number} b
22
+ * @param {Number} a
23
+ * @api public
24
+ */
25
+
26
+ var RGBA = exports = module.exports = function RGBA(r,g,b,a){
27
+ Node.call(this);
28
+ this.r = clamp(r);
29
+ this.g = clamp(g);
30
+ this.b = clamp(b);
31
+ this.a = clampAlpha(a);
32
+ this.rgba = this;
33
+ };
34
+
35
+ /**
36
+ * Inherit from `Node.prototype`.
37
+ */
38
+
39
+ RGBA.prototype.__proto__ = Node.prototype;
40
+
41
+ /**
42
+ * Return an `RGBA` without clamping values.
43
+ *
44
+ * @param {Number} r
45
+ * @param {Number} g
46
+ * @param {Number} b
47
+ * @param {Number} a
48
+ * @return {RGBA}
49
+ * @api public
50
+ */
51
+
52
+ RGBA.withoutClamping = function(r,g,b,a){
53
+ var rgba = new RGBA(0,0,0,0);
54
+ rgba.r = r;
55
+ rgba.g = g;
56
+ rgba.b = b;
57
+ rgba.a = a;
58
+ return rgba;
59
+ };
60
+
61
+ /**
62
+ * Return a clone of this node.
63
+ *
64
+ * @return {Node}
65
+ * @api public
66
+ */
67
+
68
+ RGBA.prototype.clone = function(){
69
+ var clone = new RGBA(
70
+ this.r
71
+ , this.g
72
+ , this.b
73
+ , this.a);
74
+ clone.lineno = this.lineno;
75
+ clone.filename = this.filename;
76
+ return clone;
77
+ };
78
+
79
+ /**
80
+ * Return true.
81
+ *
82
+ * @return {Boolean}
83
+ * @api public
84
+ */
85
+
86
+ RGBA.prototype.toBoolean = function(){
87
+ return nodes.true;
88
+ };
89
+
90
+ /**
91
+ * Return `HSLA` representation.
92
+ *
93
+ * @return {HSLA}
94
+ * @api public
95
+ */
96
+
97
+ RGBA.prototype.__defineGetter__('hsla', function(){
98
+ return HSLA.fromRGBA(this);
99
+ });
100
+
101
+ /**
102
+ * Return hash.
103
+ *
104
+ * @return {String}
105
+ * @api public
106
+ */
107
+
108
+ RGBA.prototype.__defineGetter__('hash', function(){
109
+ return this.toString();
110
+ });
111
+
112
+ /**
113
+ * Add r,g,b,a to the current component values.
114
+ *
115
+ * @param {Number} r
116
+ * @param {Number} g
117
+ * @param {Number} b
118
+ * @param {Number} a
119
+ * @return {RGBA} new node
120
+ * @api public
121
+ */
122
+
123
+ RGBA.prototype.add = function(r,g,b,a){
124
+ return new RGBA(
125
+ this.r + r
126
+ , this.g + g
127
+ , this.b + b
128
+ , this.a + a);
129
+ };
130
+
131
+ /**
132
+ * Subtract r,g,b,a from the current component values.
133
+ *
134
+ * @param {Number} r
135
+ * @param {Number} g
136
+ * @param {Number} b
137
+ * @param {Number} a
138
+ * @return {RGBA} new node
139
+ * @api public
140
+ */
141
+
142
+ RGBA.prototype.sub = function(r,g,b,a){
143
+ return new RGBA(
144
+ this.r - r
145
+ , this.g - g
146
+ , this.b - b
147
+ , a == 1 ? this.a : this.a - a);
148
+ };
149
+
150
+ /**
151
+ * Multiply rgb components by `n`.
152
+ *
153
+ * @param {String} n
154
+ * @return {RGBA} new node
155
+ * @api public
156
+ */
157
+
158
+ RGBA.prototype.multiply = function(n){
159
+ return new RGBA(
160
+ this.r * n
161
+ , this.g * n
162
+ , this.b * n
163
+ , this.a);
164
+ };
165
+
166
+ /**
167
+ * Divide rgb components by `n`.
168
+ *
169
+ * @param {String} n
170
+ * @return {RGBA} new node
171
+ * @api public
172
+ */
173
+
174
+ RGBA.prototype.divide = function(n){
175
+ return new RGBA(
176
+ this.r / n
177
+ , this.g / n
178
+ , this.b / n
179
+ , this.a);
180
+ };
181
+
182
+ /**
183
+ * Operate on `right` with the given `op`.
184
+ *
185
+ * @param {String} op
186
+ * @param {Node} right
187
+ * @return {Node}
188
+ * @api public
189
+ */
190
+
191
+ RGBA.prototype.operate = function(op, right){
192
+ right = right.first;
193
+
194
+ switch (op) {
195
+ case 'is a':
196
+ if ('string' == right.nodeName && 'color' == right.string) {
197
+ return nodes.true;
198
+ }
199
+ break;
200
+ case '+':
201
+ switch (right.nodeName) {
202
+ case 'unit':
203
+ var n = right.val;
204
+ switch (right.type) {
205
+ case '%': return this.hsla.adjustLightness(n).rgba;
206
+ case 'deg': return this.hsla.adjustHue(n).rgba;
207
+ default: return this.add(n,n,n,0);
208
+ }
209
+ case 'rgba':
210
+ return this.add(right.r, right.g, right.b, right.a);
211
+ case 'hsla':
212
+ return this.hsla.add(right.h, right.s, right.l);
213
+ }
214
+ break;
215
+ case '-':
216
+ switch (right.nodeName) {
217
+ case 'unit':
218
+ var n = right.val;
219
+ switch (right.type) {
220
+ case '%': return this.hsla.adjustLightness(-n).rgba;
221
+ case 'deg': return this.hsla.adjustHue(-n).rgba;
222
+ default: return this.sub(n,n,n,0);
223
+ }
224
+ case 'rgba':
225
+ return this.sub(right.r, right.g, right.b, right.a);
226
+ case 'hsla':
227
+ return this.hsla.sub(right.h, right.s, right.l);
228
+ }
229
+ break;
230
+ case '*':
231
+ switch (right.nodeName) {
232
+ case 'unit':
233
+ return this.multiply(right.val);
234
+ }
235
+ break;
236
+ case '/':
237
+ switch (right.nodeName) {
238
+ case 'unit':
239
+ return this.divide(right.val);
240
+ }
241
+ break;
242
+ }
243
+ return Node.prototype.operate.call(this, op, right);
244
+ };
245
+
246
+ /**
247
+ * Return #nnnnnn, #nnn, or rgba(n,n,n,n) string representation of the color.
248
+ *
249
+ * @return {String}
250
+ * @api public
251
+ */
252
+
253
+ RGBA.prototype.toString = function(){
254
+ function pad(n) {
255
+ return n < 16
256
+ ? '0' + n.toString(16)
257
+ : n.toString(16);
258
+ }
259
+
260
+ if (1 == this.a) {
261
+ var r = pad(this.r)
262
+ , g = pad(this.g)
263
+ , b = pad(this.b);
264
+
265
+ // Compress
266
+ if (r[0] == r[1] && g[0] == g[1] && b[0] == b[1]) {
267
+ return '#' + r[0] + g[0] + b[0];
268
+ } else {
269
+ return '#' + r + g + b;
270
+ }
271
+ } else {
272
+ return 'rgba('
273
+ + this.r + ','
274
+ + this.g + ','
275
+ + this.b + ','
276
+ + this.a.toFixed(2) + ')';
277
+ }
278
+ };
279
+
280
+ /**
281
+ * Return a `RGBA` from the given `hsla`.
282
+ *
283
+ * @param {HSLA} hsla
284
+ * @return {RGBA}
285
+ * @api public
286
+ */
287
+
288
+ exports.fromHSLA = function(hsla){
289
+ var h = hsla.h / 360
290
+ , s = hsla.s / 100
291
+ , l = hsla.l / 100
292
+ , a = hsla.a;
293
+
294
+ var m2 = l <= .5 ? l * (s + 1) : l + s - l * s
295
+ , m1 = l * 2 - m2;
296
+
297
+ var r = hue(h + 1/3) * 0xff
298
+ , g = hue(h) * 0xff
299
+ , b = hue(h - 1/3) * 0xff;
300
+
301
+ function hue(h) {
302
+ if (h < 0) ++h;
303
+ if (h > 1) --h;
304
+ if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
305
+ if (h * 2 < 1) return m2;
306
+ if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6;
307
+ return m1;
308
+ }
309
+
310
+ return new RGBA(r,g,b,a);
311
+ };
312
+
313
+ /**
314
+ * Clamp `n` >= 0 and <= 255.
315
+ *
316
+ * @param {Number} n
317
+ * @return {Number}
318
+ * @api private
319
+ */
320
+
321
+ function clamp(n) {
322
+ return Math.max(0, Math.min(n.toFixed(0), 255));
323
+ }
324
+
325
+ /**
326
+ * Clamp alpha `n` >= 0 and <= 1.
327
+ *
328
+ * @param {Number} n
329
+ * @return {Number}
330
+ * @api private
331
+ */
332
+
333
+ function clampAlpha(n) {
334
+ return Math.max(0, Math.min(n, 1));
335
+ }