From a7776b93b8cfff29b396be8c8d865f3269e40f7f Mon Sep 17 00:00:00 2001 From: Mahemoff Date: Fri, 21 Jun 2013 23:55:31 +0100 Subject: [PATCH] Add in-browser Stylus lib --- ajax/libs/stylus/0.32.1/stylus.js | 9582 +++++++++++++++++++++++++ ajax/libs/stylus/0.32.1/stylus.min.js | 3 + ajax/libs/stylus/package.json | 26 + 3 files changed, 9611 insertions(+) create mode 100644 ajax/libs/stylus/0.32.1/stylus.js create mode 100644 ajax/libs/stylus/0.32.1/stylus.min.js create mode 100644 ajax/libs/stylus/package.json diff --git a/ajax/libs/stylus/0.32.1/stylus.js b/ajax/libs/stylus/0.32.1/stylus.js new file mode 100644 index 000000000..9d7cf40d7 --- /dev/null +++ b/ajax/libs/stylus/0.32.1/stylus.js @@ -0,0 +1,9582 @@ + +var bifs = "\ +vendors = moz webkit o ms official\n\ +\n\ +// stringify the given arg\n\ +\n\ +-string(arg)\n\ + type(arg) + ' ' + arg\n\ +\n\ +// require a color\n\ +\n\ +require-color(color)\n\ + unless color is a 'color' \n\ + error('RGB or HSL value expected, got a ' + -string(color))\n\ +\n\ +// require a unit\n\ +\n\ +require-unit(n)\n\ + unless n is a 'unit'\n\ + error('unit expected, got a ' + -string(n))\n\ +\n\ +// require a string\n\ +\n\ +require-string(str)\n\ + unless str is a 'string' or str is a 'ident'\n\ + error('string expected, got a ' + -string(str))\n\ +\n\ +// apply js Math function\n\ +\n\ +math(n, fn) \n\ + require-unit(n)\n\ + require-string(fn)\n\ + -math(n, fn)\n\ +\n\ +// adjust the given color's property by amount\n\ +\n\ +adjust(color, prop, amount)\n\ + require-color(color)\n\ + require-string(prop)\n\ + require-unit(amount)\n\ + -adjust(color, prop, amount)\n\ +\n\ +// Math functions\n\ +\n\ +abs(n) { math(n, 'abs') }\n\ +ceil(n) { math(n, 'ceil') }\n\ +floor(n) { math(n, 'floor') }\n\ +round(n) { math(n, 'round') }\n\ +sin(n) { math(n, 'sin') }\n\ +cos(n) { math(n, 'cos') }\n\ +min(a, b) { a < b ? a : b }\n\ +max(a, b) { a > b ? a : b }\n\ +PI = -math-prop('PI')\n\ +\n\ +// return the sum of the given numbers\n\ +\n\ +sum(nums)\n\ + sum = 0\n\ + sum += n for n in nums\n\ +\n\ +// return the average of the given numbers\n\ +\n\ +avg(nums)\n\ + sum(nums) / length(nums)\n\ +\n\ +// color components\n\ +\n\ +alpha(color) { component(hsl(color), 'alpha') }\n\ +hue(color) { component(hsl(color), 'hue') }\n\ +saturation(color) { component(hsl(color), 'saturation') }\n\ +lightness(color) { component(hsl(color), 'lightness') }\n\ +\n\ +// check if n is an odd number\n\ +\n\ +odd(n)\n\ + 1 == n % 2\n\ +\n\ +// check if n is an even number\n\ +\n\ +even(n)\n\ + 0 == n % 2\n\ +\n\ +// check if color is light\n\ +\n\ +light(color)\n\ + lightness(color) >= 50%\n\ +\n\ +// check if color is dark\n\ +\n\ +dark(color)\n\ + lightness(color) < 50%\n\ +\n\ +// desaturate color by amount\n\ +\n\ +desaturate(color, amount)\n\ + adjust(color, 'saturation', - amount)\n\ +\n\ +// saturate color by amount\n\ +\n\ +saturate(color, amount)\n\ + adjust(color, 'saturation', amount)\n\ +\n\ +// darken by the given amount\n\ +\n\ +darken(color, amount)\n\ + adjust(color, 'lightness', - amount)\n\ +\n\ +// lighten by the given amount\n\ +\n\ +lighten(color, amount)\n\ + adjust(color, 'lightness', amount)\n\ +\n\ +// decerase opacity by amount\n\ +\n\ +fade-out(color, amount)\n\ + color - rgba(black, amount)\n\ +\n\ +// increase opacity by amount\n\ +\n\ +fade-in(color, amount)\n\ + color + rgba(black, amount)\n\ +\n\ +// return the last value in the given expr\n\ +\n\ +last(expr)\n\ + expr[length(expr) - 1]\n\ +\n\ +// join values with the given delimiter\n\ +\n\ +join(delim, vals...)\n\ + buf = ''\n\ + vals = vals[0] if length(vals) == 1\n\ + for val, i in vals\n\ + buf += i ? delim + val : val\n\ +"; + +var stylus = (function(){ +function require(p){ + var path = require.resolve(p) + , mod = require.modules[path]; + if (!mod) throw new Error('failed to require "' + p + '"'); + if (!mod.exports) { + mod.exports = {}; + mod.call(mod.exports, mod, mod.exports, require.relative(path)); + } + return mod.exports; + } + + +require.modules = {}; + + +require.resolve = function (path){ + var orig = path + , reg = path + '.js' + , index = path + '/index.js'; + return require.modules[reg] && reg + || require.modules[index] && index + || orig; + }; + + +require.register = function (path, fn){ + require.modules[path] = fn; + }; + + +require.relative = function (parent) { + return function(p){ + if ('.' != p[0]) return require(p); + + var path = parent.split('/') + , segs = p.split('/'); + path.pop(); + + for (var i = 0; i < segs.length; i++) { + var seg = segs[i]; + if ('..' == seg) path.pop(); + else if ('.' != seg) path.push(seg); + } + + return require(path.join('/')); + }; + }; + + + +require.register("path.js", function(module, exports, require){ + +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + + +var isWindows = false; + + +// resolves . and .. elements in a path array with directory names there +// must be no slashes, empty elements, or device names (c:\) in the array +// (so also no leading and trailing slashes - it does not distinguish +// relative and absolute paths) +function normalizeArray(parts, allowAboveRoot) { + // if the path tries to go above the root, `up` ends up > 0 + var up = 0; + for (var i = parts.length-1; i >= 0; i--) { + var last = parts[i]; + if (last == '.') { + parts.splice(i, 1); + } else if (last === '..') { + parts.splice(i, 1); + up++; + } else if (up) { + parts.splice(i, 1); + up--; + } + } + + // if the path is allowed to go above the root, restore leading ..s + if (allowAboveRoot) { + for (; up--; up) { + parts.unshift('..'); + } + } + + return parts; +} + + + // Regex to split a filename into [*, dir, basename, ext] +// posix version +var splitPathRe = /^([\s\S]+\/(?!$)|\/)?((?:[\s\S]+?)?(\.[^.]*)?)$/; + +// path.normalize(path) +// posix version +exports.normalize = function(path) { + var isAbsolute = path.charAt(0) === '/', + trailingSlash = path.slice(-1) === '/'; + + // Normalize the path + path = normalizeArray(path.split('/').filter(function(p) { + return !!p; + }), !isAbsolute).join('/'); + + if (!path && !isAbsolute) { + path = '.'; + } + if (path && trailingSlash) { + path += '/'; + } + + return (isAbsolute ? '/' : '') + path; +}; + + +// posix version +exports.join = function() { + var paths = Array.prototype.slice.call(arguments, 0); + return exports.normalize(paths.filter(function(p, index) { + return p && typeof p === 'string'; + }).join('/')); +}; + + +// path.relative(from, to) +// posix version +exports.relative = function(from, to) { + from = exports.resolve(from).substr(1); + to = exports.resolve(to).substr(1); + + function trim(arr) { + var start = 0; + for (; start < arr.length; start++) { + if (arr[start] !== '') break; + } + + var end = arr.length - 1; + for (; end >= 0; end--) { + if (arr[end] !== '') break; + } + + if (start > end) return []; + return arr.slice(start, end - start + 1); + } + + var fromParts = trim(from.split('/')); + var toParts = trim(to.split('/')); + + var length = Math.min(fromParts.length, toParts.length); + var samePartsLength = length; + for (var i = 0; i < length; i++) { + if (fromParts[i] !== toParts[i]) { + samePartsLength = i; + break; + } + } + + var outputParts = []; + for (var i = samePartsLength; i < fromParts.length; i++) { + outputParts.push('..'); + } + + outputParts = outputParts.concat(toParts.slice(samePartsLength)); + + return outputParts.join('/'); +}; + + +exports.dirname = function(path) { + var dir = splitPathRe.exec(path)[1] || ''; + if (!dir) { + // No dirname + return '.'; + } else if (dir.length === 1 || + (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) { + // It is just a slash or a drive letter with a slash + return dir; + } else { + // It is a full dirname, strip trailing slash + return dir.substring(0, dir.length - 1); + } +}; + + +exports.basename = function(path, ext) { + var f = splitPathRe.exec(path)[2] || ''; + // TODO: make this comparison case-insensitive on windows? + if (ext && f.substr(-1 * ext.length) === ext) { + f = f.substr(0, f.length - ext.length); + } + return f; +}; + + +exports.extname = function(path) { + return splitPathRe.exec(path)[3] || ''; +}; + + +});// module: path.js + + +require.register("colors.js", function(module, exports, require){ + + +/*! + * Stylus - colors + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +module.exports = { + aliceblue: [240, 248, 255] + , antiquewhite: [250, 235, 215] + , aqua: [0, 255, 255] + , aquamarine: [127, 255, 212] + , azure: [240, 255, 255] + , beige: [245, 245, 220] + , bisque: [255, 228, 196] + , black: [0, 0, 0] + , blanchedalmond: [255, 235, 205] + , blue: [0, 0, 255] + , blueviolet: [138, 43, 226] + , brown: [165, 42, 42] + , burlywood: [222, 184, 135] + , cadetblue: [95, 158, 160] + , chartreuse: [127, 255, 0] + , chocolate: [210, 105, 30] + , coral: [255, 127, 80] + , cornflowerblue: [100, 149, 237] + , cornsilk: [255, 248, 220] + , crimson: [220, 20, 60] + , cyan: [0, 255, 255] + , darkblue: [0, 0, 139] + , darkcyan: [0, 139, 139] + , darkgoldenrod: [184, 132, 11] + , darkgray: [169, 169, 169] + , darkgreen: [0, 100, 0] + , darkgrey: [169, 169, 169] + , darkkhaki: [189, 183, 107] + , darkmagenta: [139, 0, 139] + , darkolivegreen: [85, 107, 47] + , darkorange: [255, 140, 0] + , darkorchid: [153, 50, 204] + , darkred: [139, 0, 0] + , darksalmon: [233, 150, 122] + , darkseagreen: [143, 188, 143] + , darkslateblue: [72, 61, 139] + , darkslategray: [47, 79, 79] + , darkslategrey: [47, 79, 79] + , darkturquoise: [0, 206, 209] + , darkviolet: [148, 0, 211] + , deeppink: [255, 20, 147] + , deepskyblue: [0, 191, 255] + , dimgray: [105, 105, 105] + , dimgrey: [105, 105, 105] + , dodgerblue: [30, 144, 255] + , firebrick: [178, 34, 34] + , floralwhite: [255, 255, 240] + , forestgreen: [34, 139, 34] + , fuchsia: [255, 0, 255] + , gainsboro: [220, 220, 220] + , ghostwhite: [248, 248, 255] + , gold: [255, 215, 0] + , goldenrod: [218, 165, 32] + , gray: [128, 128, 128] + , green: [0, 128, 0] + , greenyellow: [173, 255, 47] + , grey: [128, 128, 128] + , honeydew: [240, 255, 240] + , hotpink: [255, 105, 180] + , indianred: [205, 92, 92] + , indigo: [75, 0, 130] + , ivory: [255, 255, 240] + , khaki: [240, 230, 140] + , lavender: [230, 230, 250] + , lavenderblush: [255, 240, 245] + , lawngreen: [124, 252, 0] + , lemonchiffon: [255, 250, 205] + , lightblue: [173, 216, 230] + , lightcoral: [240, 128, 128] + , lightcyan: [224, 255, 255] + , lightgoldenrodyellow: [250, 250, 210] + , lightgray: [211, 211, 211] + , lightgreen: [144, 238, 144] + , lightgrey: [211, 211, 211] + , lightpink: [255, 182, 193] + , lightsalmon: [255, 160, 122] + , lightseagreen: [32, 178, 170] + , lightskyblue: [135, 206, 250] + , lightslategray: [119, 136, 153] + , lightslategrey: [119, 136, 153] + , lightsteelblue: [176, 196, 222] + , lightyellow: [255, 255, 224] + , lime: [0, 255, 0] + , limegreen: [50, 205, 50] + , linen: [250, 240, 230] + , magenta: [255, 0, 255] + , maroon: [128, 0, 0] + , mediumaquamarine: [102, 205, 170] + , mediumblue: [0, 0, 205] + , mediumorchid: [186, 85, 211] + , mediumpurple: [147, 112, 219] + , mediumseagreen: [60, 179, 113] + , mediumslateblue: [123, 104, 238] + , mediumspringgreen: [0, 250, 154] + , mediumturquoise: [72, 209, 204] + , mediumvioletred: [199, 21, 133] + , midnightblue: [25, 25, 112] + , mintcream: [245, 255, 250] + , mistyrose: [255, 228, 225] + , moccasin: [255, 228, 181] + , navajowhite: [255, 222, 173] + , navy: [0, 0, 128] + , oldlace: [253, 245, 230] + , olive: [128, 128, 0] + , olivedrab: [107, 142, 35] + , orange: [255, 165, 0] + , orangered: [255, 69, 0] + , orchid: [218, 112, 214] + , palegoldenrod: [238, 232, 170] + , palegreen: [152, 251, 152] + , paleturquoise: [175, 238, 238] + , palevioletred: [219, 112, 147] + , papayawhip: [255, 239, 213] + , peachpuff: [255, 218, 185] + , peru: [205, 133, 63] + , pink: [255, 192, 203] + , plum: [221, 160, 203] + , powderblue: [176, 224, 230] + , purple: [128, 0, 128] + , red: [255, 0, 0] + , rosybrown: [188, 143, 143] + , royalblue: [65, 105, 225] + , saddlebrown: [139, 69, 19] + , salmon: [250, 128, 114] + , sandybrown: [244, 164, 96] + , seagreen: [46, 139, 87] + , seashell: [255, 245, 238] + , sienna: [160, 82, 45] + , silver: [192, 192, 192] + , skyblue: [135, 206, 235] + , slateblue: [106, 90, 205] + , slategray: [119, 128, 144] + , slategrey: [119, 128, 144] + , snow: [255, 255, 250] + , springgreen: [0, 255, 127] + , steelblue: [70, 130, 180] + , tan: [210, 180, 140] + , teal: [0, 128, 128] + , thistle: [216, 191, 216] + , tomato: [255, 99, 71] + , turquoise: [64, 224, 208] + , violet: [238, 130, 238] + , wheat: [245, 222, 179] + , white: [255, 255, 255] + , whitesmoke: [245, 245, 245] + , yellow: [255, 255, 0] + , yellowgreen: [154, 205, 5] +}; + +});// module: colors.js + + +require.register("errors.js", function(module, exports, require){ + + +/*! + * Stylus - errors + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Expose constructors. + */ + +exports.ParseError = ParseError; +exports.SyntaxError = SyntaxError; + +/** + * Inherit from `Error.prototype`. + */ + +SyntaxError.prototype.__proto__ = Error.prototype; + +/** + * Initialize a new `ParseError` with the given `msg`. + * + * @param {String} msg + * @api private + */ + +function ParseError(msg) { + this.name = 'ParseError'; + this.message = msg; + Error.captureStackTrace(this, ParseError); +} + +/** + * Inherit from `Error.prototype`. + */ + +ParseError.prototype.__proto__ = Error.prototype; + +/** + * Initialize a new `SyntaxError` with the given `msg`. + * + * @param {String} msg + * @api private + */ + +function SyntaxError(msg) { + this.name = 'SyntaxError'; + this.message = msg; + Error.captureStackTrace(this, ParseError); +} + +/** + * Inherit from `Error.prototype`. + */ + +SyntaxError.prototype.__proto__ = Error.prototype; + + + +});// module: errors.js + + +require.register("functions/index.js", function(module, exports, require){ + + +/*! + * Stylus - Evaluator - built-in functions + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Compiler = require('../visitor/compiler') + , nodes = require('../nodes') + , utils = require('../utils') + , Image = require('./image'); + +/** + * Color component name map. + */ + +var componentMap = { + red: 'r' + , green: 'g' + , blue: 'b' + , alpha: 'a' + , hue: 'h' + , saturation: 's' + , lightness: 'l' +}; + +/** + * Color component unit type map. + */ + +var unitMap = { + hue: 'deg' + , saturation: '%' + , lightness: '%' +}; + +/** + * Color type map. + */ + +var typeMap = { + red: 'rgba' + , blue: 'rgba' + , green: 'rgba' + , alpha: 'rgba' + , hue: 'hsla' + , saturation: 'hsla' + , lightness: 'hsla' +}; + +/** + * 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 + */ + +exports.hsla = function hsla(hue, saturation, lightness, alpha){ + switch (arguments.length) { + case 1: + utils.assertColor(hue); + return hue.hsla; + default: + utils.assertType(hue, 'unit', 'hue'); + utils.assertType(saturation, 'unit', 'saturation'); + utils.assertType(lightness, 'unit', 'lightness'); + utils.assertType(alpha, 'unit', 'alpha'); + return new nodes.HSLA( + hue.val + , saturation.val + , lightness.val + , alpha.val); + } +}; + +/** + * Convert the given `color` to an `HSLA` node, + * or h,s,l component values. + * + * Examples: + * + * hsl(10, 50, 30) + * // => HSLA + * + * hsl(#ffcc00) + * // => HSLA + * + * @param {Unit|HSLA|RGBA} hue + * @param {Unit} saturation + * @param {Unit} lightness + * @return {HSLA} + * @api public + */ + +exports.hsl = function hsl(hue, saturation, lightness){ + if (1 == arguments.length) { + utils.assertColor(hue, 'color'); + return hue.hsla; + } else { + return exports.hsla( + hue + , saturation + , lightness + , new nodes.Unit(1)); + } +}; + +/** + * Return type of `node`. + * + * Examples: + * + * type(12) + * // => 'unit' + * + * type(#fff) + * // => 'color' + * + * type(type) + * // => 'function' + * + * type(unbound) + * typeof(unbound) + * type-of(unbound) + * // => 'ident' + * + * @param {Node} node + * @return {String} + * @api public + */ + +exports.type = +exports['typeof'] = +exports['type-of'] = function type(node){ + utils.assertPresent(node, 'expression'); + var type = node.nodeName; + return new nodes.String(type); +}; + +/** + * Return component `name` for the given `color`. + * + * @param {RGBA|HSLA} color + * @param {String} na,e + * @return {Unit} + * @api public + */ + +exports.component = function component(color, name) { + utils.assertColor(color, 'color'); + utils.assertString(name, 'name'); + var name = name.string + , unit = unitMap[name] + , type = typeMap[name] + , name = componentMap[name]; + if (!name) throw new Error('invalid color component "' + name + '"'); + return new nodes.Unit(color[type][name], unit); +}; + +/** + * Return the red component of the given `color`. + * + * Examples: + * + * red(#c00) + * // => 204 + * + * @param {RGBA|HSLA} color + * @return {Unit} + * @api public + */ + +exports.red = function red(color){ + return exports.component(color, new nodes.String('red')); +}; + +/** + * Return the green component of the given `color`. + * + * Examples: + * + * green(#0c0) + * // => 204 + * + * @param {RGBA|HSLA} color + * @return {Unit} + * @api public + */ + +exports.green = function green(color){ + return exports.component(color, new nodes.String('green')); +}; + +/** + * Return the blue component of the given `color`. + * + * Examples: + * + * blue(#00c) + * // => 204 + * + * @param {RGBA|HSLA} color + * @return {Unit} + * @api public + */ + +exports.blue = function blue(color){ + return exports.component(color, new nodes.String('blue')); +}; + +/** + * Return a `RGBA` from the r,g,b,a channels. + * + * Examples: + * + * rgba(255,0,0,0.5) + * // => rgba(255,0,0,0.5) + * + * rgba(255,0,0,1) + * // => #ff0000 + * + * rgba(#ffcc00, 0.5) + * // rgba(255,204,0,0.5) + * + * @param {Unit|RGBA|HSLA} red + * @param {Unit} green + * @param {Unit} blue + * @param {Unit} alpha + * @return {RGBA} + * @api public + */ + +exports.rgba = function rgba(red, green, blue, alpha){ + switch (arguments.length) { + case 1: + utils.assertColor(red); + var color = red.rgba; + return new nodes.RGBA( + color.r + , color.g + , color.b + , color.a); + case 2: + utils.assertColor(red); + var color = red.rgba; + utils.assertType(green, 'unit', 'alpha'); + return new nodes.RGBA( + color.r + , color.g + , color.b + , green.val); + default: + utils.assertType(red, 'unit', 'red'); + utils.assertType(green, 'unit', 'green'); + utils.assertType(blue, 'unit', 'blue'); + utils.assertType(alpha, 'unit', 'alpha'); + return new nodes.RGBA( + red.val + , green.val + , blue.val + , alpha.val); + } +}; + +/** + * Return a `RGBA` from the r,g,b channels. + * + * Examples: + * + * rgb(255,204,0) + * // => #ffcc00 + * + * rgb(#fff) + * // => #fff + * + * @param {Unit|RGBA|HSLA} red + * @param {Unit} green + * @param {Unit} blue + * @return {RGBA} + * @api public + */ + +exports.rgb = function rgb(red, green, blue){ + switch (arguments.length) { + case 1: + utils.assertColor(red); + var color = red.rgba; + return new nodes.RGBA( + color.r + , color.g + , color.b + , 1); + default: + return exports.rgba( + red + , green + , blue + , new nodes.Unit(1)); + } +}; + +/** + * Unquote the given `str`. + * + * Examples: + * + * unquote("sans-serif") + * // => sans-serif + * + * unquote(sans-serif) + * // => sans-serif + * + * @param {String|Ident} string + * @return {Literal} + * @api public + */ + +exports.unquote = function unquote(string){ + utils.assertString(string, 'string'); + return new nodes.Literal(string.string); +}; + +/** + * Assign `type` to the given `unit` or return `unit`'s type. + * + * @param {Unit} unit + * @param {String|Ident} type + * @return {Unit} + * @api public + */ + +exports.unit = function unit(unit, type){ + utils.assertType(unit, 'unit', 'unit'); + + // Assign + if (type) { + utils.assertString(type, 'type'); + return new nodes.Unit(unit.val, type.string); + } else { + return new nodes.String(unit.type || ''); + } +}; + +/** + * Lookup variable `name` or return Null. + * + * @param {String} name + * @return {Mixed} + * @api public + */ + +exports.lookup = function lookup(name){ + utils.assertType(name, 'string', 'name'); + var node = this.lookup(name.val); + if (!node) return nodes.nil; + return this.visit(node); +}; + +/** + * Perform `op` on the `left` and `right` operands. + * + * @param {String} op + * @param {Node} left + * @param {Node} right + * @return {Node} + * @api public + */ + +exports.operate = function operate(op, left, right){ + utils.assertType(op, 'string', 'op'); + utils.assertPresent(left, 'left'); + utils.assertPresent(right, 'right'); + return left.operate(op.val, right); +}; + +/** + * Test if `val` matches the given `pattern`. + * + * Examples: + * + * match('^foo(bar)?', foo) + * match('^foo(bar)?', foobar) + * match('^foo(bar)?', 'foo') + * match('^foo(bar)?', 'foobar') + * // => true + * + * match('^foo(bar)?', 'bar') + * // => false + * + * @param {String} pattern + * @param {String|Ident} val + * @return {Boolean} + * @api public + */ + +exports.match = function match(pattern, val){ + utils.assertType(pattern, 'string', 'pattern'); + utils.assertString(val, 'val'); + var re = new RegExp(pattern.val); + return nodes.Boolean(re.test(val.string)); +}; + +/** + * Return length of the given `expr`. + * + * @param {Expression} expr + * @return {Unit} + * @api public + */ + +(exports.length = function length(expr){ + if (expr) { + if (expr.nodes) { + return new nodes.Unit(utils.unwrap(expr).nodes.length); + } else { + return new nodes.Unit(1); + } + } + return new nodes.Unit(0); +}).raw = true; + +/** + * Inspect the given `expr`. + * + * @param {Expression} expr + * @api public + */ + +(exports.p = function p(expr){ + expr = utils.unwrap(expr); + console.log('\033[90minspect:\033[0m undefined' + , expr.toString().replace(/^\(|\)$/g, '')); + return nodes.nil; +}).raw = true; + +/** + * Throw an error with the given `msg`. + * + * @param {String} msg + * @api public + */ + +exports.error = function error(msg){ + utils.assertType(msg, 'string', 'msg'); + throw new Error(msg.val); +}; + +/** + * Warn with the given `msg` prefixed by "Warning: ". + * + * @param {String} msg + * @api public + */ + +exports.warn = function warn(msg){ + utils.assertType(msg, 'string', 'msg'); + console.warn('Warning: undefined', msg.val); + return nodes.nil; +}; + +/** + * Output stack trace. + * + * @api public + */ + +exports.trace = function trace(){ + console.log(this.stack); + return nodes.nil; +}; + +/** + * Push the given args to `expr`. + * + * @param {Expression} expr + * @param {Node} ... + * @return {Unit} + * @api public + */ + +(exports.push = exports.append = function(expr){ + expr = utils.unwrap(expr); + for (var i = 1, len = arguments.length; i < len; ++i) { + expr.nodes.push(utils.unwrap(arguments[i])); + } + return new nodes.Unit(expr.nodes.length); +}).raw = true; + +/** + * Unshift the given args to `expr`. + * + * @param {Expression} expr + * @param {Node} ... + * @return {Unit} + * @api public + */ + +(exports.unshift = exports.prepend = function(expr){ + expr = utils.unwrap(expr); + for (var i = 1, len = arguments.length; i < len; ++i) { + expr.nodes.unshift(utils.unwrap(arguments[i])); + } + return new nodes.Unit(expr.nodes.length); +}).raw = true; + +/** + * Return a `Literal` with the given `fmt`, and + * variable number of arguments. + * + * @param {String} fmt + * @param {Node} ... + * @return {Literal} + * @api public + */ + +(exports.s = function s(fmt){ + fmt = utils.unwrap(fmt).nodes[0]; + utils.assertString(fmt); + var self = this + , str = fmt.string + , args = arguments + , i = 1; + + // format + str = str.replace(/%(s|d)/g, function(_, specifier){ + var arg = args[i++] || nodes.nil; + switch (specifier) { + case 's': + return new Compiler(arg, self.options).compile(); + case 'd': + arg = utils.unwrap(arg).first; + if ('unit' != arg.nodeName) throw new Error('NaN requires a unit'); + return arg.val; + } + }); + + return new nodes.Literal(str); +}).raw = true; + +/** + * Return the opposites of the given `positions`. + * + * Examples: + * + * opposite-position(top left) + * // => bottom right + * + * @param {Expression} positions + * @return {Expression} + * @api public + */ + +(exports['opposite-position'] = function oppositePosition(positions){ + var expr = new nodes.Expression; + utils.unwrap(positions).nodes.forEach(function(pos, i){ + utils.assertString(pos, 'position ' + i); + pos = (function(){ switch (pos.string) { + case 'top': return 'bottom'; + case 'bottom': return 'top'; + case 'left': return 'right'; + case 'right': return 'left'; + default: throw new Error('invalid position ' + pos); + }})(); + expr.push(new nodes.Literal(pos)); + }); + return expr; +}).raw = true; + +/** + * Return the width and height of the given `img` path. + * + * Examples: + * + * image-size('foo.png') + * // => 200px 100px + * + * image-size('foo.png')[0] + * // => 200px + * + * image-size('foo.png')[1] + * // => 100px + * + * @param {String} img + * @return {Expression} + * @api public + */ + +exports['image-size'] = function imageSize(img) { + utils.assertType(img, 'string', 'img'); + var img = new Image(this, img.string); + + // Read size + img.open(); + var size = img.size(); + img.close(); + + // Return (w h) + var expr = new nodes.Expression; + expr.push(new nodes.Unit(size[0], 'px')); + expr.push(new nodes.Unit(size[1], 'px')); + + return expr; +}; + +/** + * Apply Math `fn` to `n`. + * + * @param {Unit} n + * @param {String} fn + * @return {Unit} + * @api private + */ + +exports['-math'] = function math(n, fn){ + return new nodes.Unit(Math[fn.string](n.val), n.type); +}; + +/** + * Get Math `prop`. + * + * @param {String} prop + * @return {Unit} + * @api private + */ + +exports['-math-prop'] = function math(prop){ + return new nodes.Unit(Math[prop.string]); +}; + +/** + * Buffer the given js `str`. + * + * @param {String} str + * @return {JSLiteral} + * @api private + */ + +exports.js = function js(str){ + utils.assertString(str, 'str'); + return new nodes.JSLiteral(str.val); +}; + +/** + * Adjust HSL `color` `prop` by `amount`. + * + * @param {RGBA|HSLA} color + * @param {String} prop + * @param {Unit} amount + * @return {RGBA} + * @api private + */ + +exports['-adjust'] = function adjust(color, prop, amount){ + var hsl = color.hsla.clone(); + prop = { hue: 'h', saturation: 's', lightness: 'l' }[prop.string]; + if (!prop) throw new Error('invalid adjustment property'); + var val = amount.val; + if ('%' == amount.type){ + val = 'l' == prop && val > 0 + ? (100 - hsl[prop]) * val / 100 + : hsl[prop] * (val / 100); + } + hsl[prop] += val; + return hsl.rgba; +}; + +/** + * Return a clone of the given `expr`. + * + * @param {Expression} expr + * @return {Node} + * @api public + */ + +(exports.clone = function clone(expr){ + utils.assertPresent(expr, 'expr'); + return expr.clone(); +}).raw = true; + +/** + * Add property `name` with the given `expr` + * to the mixin-able block. + * + * @param {String|Ident|Literal} name + * @param {Expression} expr + * @return {Property} + * @api public + */ + +(exports['add-property'] = function addProperty(name, expr){ + utils.assertType(name, 'expression', 'name'); + name = utils.unwrap(name).first; + utils.assertString(name, 'name'); + utils.assertType(expr, 'expression', 'expr'); + var prop = new nodes.Property([name], expr); + var block = this.closestBlock; + + var len = block.nodes.length + , head = block.nodes.slice(0, block.index) + , tail = block.nodes.slice(block.index++, len); + head.push(prop); + block.nodes = head.concat(tail); + + return prop; +}).raw = true; + + +});// module: functions/index.js + + +require.register("functions/image.js", function(module, exports, require){ + + + +/*! + * Stylus - plugin - url + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var utils = require('../utils') + , nodes = require('../nodes'); + +/** + * Initialize a new `Image` with the given `ctx` and `path. + * + * @param {Evaluator} ctx + * @param {String} path + * @api private + */ + +var Image = module.exports = function Image(ctx, path) { + this.ctx = ctx; + this.path = utils.lookup(path, ctx.paths); + if (!this.path) throw new Error('failed to locate file ' + path); +}; + +/** + * Open the image for reading. + * + * @api private + */ + +Image.prototype.open = function(){ + this.fd = fs.openSync(this.path, 'r'); +}; + +/** + * Close the file. + * + * @api private + */ + +Image.prototype.close = function(){ + if (this.fd) fs.closeSync(this.fd); +}; + +/** + * Return the type of image, supports: + * + * - gif + * - png + * - jpeg + * + * @return {String} + * @api private + */ + +Image.prototype.type = function(){ + var type + , buf = new Buffer(4); + + fs.readSync(this.fd, buf, 0, 4, 0); + + // GIF + if (0x47 == buf[0] && 0x49 == buf[1] && 0x46 == buf[2]) type = 'gif'; + + // PNG + else if (0x50 == buf[1] && 0x4E == buf[2] && 0x47 == buf[3]) type = 'png'; + + // JPEG + else if (0xff == buf[0] && 0xd8 == buf[1]) type = 'jpeg'; + + return type; +}; + +/** + * Return image dimensions `[width, height]`. + * + * @return {Array} + * @api private + */ + +Image.prototype.size = function(){ + var width + , height + , type = this.type(); + + function uint16(b) { return b[1] << 8 | b[0]; } + function uint32(b) { return b[0] << 24 | b[1] << 16 | b[2] << 8 | b[3]; } + + // Determine dimensions + switch (type) { + case 'jpeg': + throw new Error('image-size() jpeg support not yet implemented'); + break; + case 'png': + var buf = new Buffer(8); + // IHDR chunk width / height uint32_t big-endian + fs.readSync(this.fd, buf, 0, 8, 16); + width = uint32(buf); + height = uint32(buf.slice(4, 8)); + break; + case 'gif': + var buf = new Buffer(4); + // width / height uint16_t little-endian + fs.readSync(this.fd, buf, 0, 4, 6); + width = uint16(buf); + height = uint16(buf.slice(2, 4)); + break; + } + + if ('number' != typeof width) throw new Error('failed to find width of "' + this.path + '"'); + if ('number' != typeof height) throw new Error('failed to find height of "' + this.path + '"'); + + return [width, height]; +}; + +});// module: functions/image.js + + +require.register("functions/url.js", function(module, exports, require){ + + +/*! + * Stylus - plugin - url + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Compiler = require('../visitor/compiler') + , nodes = require('../nodes') + // , parse = require('url').parse + , extname = require('../path').extname + , utils = require('../utils') + // , fs = require('fs'); + +/** + * Mime table. + */ + +var mimes = { + '.gif': 'image/gif' + , '.png': 'image/png' + , '.jpg': 'image/jpeg' + , '.jpeg': 'image/jpeg' + , '.svg': 'image/svg+xml' +}; + +/** + * Return a url() function with the given `options`. + * + * Options: + * + * - `limit` bytesize limit defaulting to 30Kb + * - `paths` image resolution path(s), merged with general lookup paths + * + * Examples: + * + * stylus(str) + * .set('filename', __dirname + '/css/test.styl') + * .define('url', stylus.url({ paths: [__dirname + '/public'] })) + * .render(function(err, css){ ... }) + * + * @param {Object} options + * @return {Function} + * @api public + */ + +module.exports = function(options) { + options = options || {}; + + var sizeLimit = options.limit || 30000 + , _paths = options.paths || []; + + function url(url){ + // Compile the url + var compiler = new Compiler(url); + compiler.isURL = true; + var url = url.nodes.map(function(node){ + return compiler.visit(node); + }).join(''); + + // Parse literal + var url = parse(url) + , ext = extname(url.pathname) + , mime = mimes[ext] + , literal = new nodes.Literal('url("' + url.href + '")') + , paths = _paths.concat(this.paths) + , founds + , buf; + + // Not supported + if (!mime) return literal; + + // Absolute + if (url.protocol) return literal; + + // Lookup + found = utils.lookup(url.pathname, paths); + + // Failed to lookup + if (!found) return literal; + + // Read data + buf = fs.readFileSync(found); + + // To large + if (buf.length > sizeLimit) return literal; + + // Encode + return new nodes.Literal('url("data:' + mime + ';base64,' + buf.toString('base64') + '")'); + }; + + url.raw = true; + return url; +}; + +});// module: functions/url.js + + +require.register("lexer.js", function(module, exports, require){ + + +/*! + * Stylus - Lexer + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Token = require('./token') + , nodes = require('./nodes') + , errors = require('./errors'); + +/** + * Operator aliases. + */ + +var alias = { + 'and': '&&' + , 'or': '||' + , 'is': '==' + , 'isnt': '!=' + , 'is not': '!=' + , ':=': '?=' +}; + +/** + * Units. + */ + +var units = [ + 'em' + , 'ex' + , 'px' + , 'mm' + , 'cm' + , 'in' + , 'pt' + , 'pc' + , 'deg' + , 'rad' + , 'grad' + , 'ms' + , 's' + , 'Hz' + , 'kHz' + , 'rem' + , '%'].join('|'); + +/** + * Unit RegExp. + */ + +var unit = new RegExp('^(-)?(\\d+\\.\\d+|\\d+|\\.\\d+)(' + units + ')? *'); + +/** + * Initialize a new `Lexer` with the given `str` and `options`. + * + * @param {String} str + * @param {Object} options + * @api private + */ + +var Lexer = module.exports = function Lexer(str, options) { + options = options || {}; + this.str = str.replace(/\r\n?/g, '\n'); + this.stash = []; + this.indentStack = []; + this.indentRe = null; + this.lineno = 1; +}; + +/** + * Lexer prototype. + */ + +Lexer.prototype = { + + /** + * Custom inspect. + */ + + inspect: function(){ + var tok + , tmp = this.str + , buf = []; + while ('eos' != (tok = this.next()).type) { + buf.push(tok.inspect()); + } + this.str = tmp; + this.prevIndents = 0; + return buf.concat(tok.inspect()).join('\n'); + }, + + /** + * Lookahead `n` tokens. + * + * @param {Number} n + * @return {Object} + * @api private + */ + + lookahead: function(n){ + var fetch = n - this.stash.length; + while (fetch-- > 0) this.stash.push(this.advance()); + return this.stash[--n]; + }, + + /** + * Consume the given `len`. + * + * @param {Number|Array} len + * @api private + */ + + skip: function(len){ + this.str = this.str.substr(Array.isArray(len) + ? len[0].length + : len); + }, + + /** + * Fetch next token including those stashed by peek. + * + * @return {Token} + * @api private + */ + + next: function() { + var tok = this.stashed() || this.advance(); + switch (tok.type) { + case 'newline': + case 'indent': + ++this.lineno; + break; + case 'outdent': + if ('outdent' != this.prev.type) ++this.lineno; + } + this.prev = tok; + tok.lineno = this.lineno; + return tok; + }, + + /** + * Fetch next token. + * + * @return {Token} + * @api private + */ + + advance: function() { + return this.eos() + || this.nil() + || this.sep() + || this.keyword() + || this.urlchars() + || this.atrule() + || this.scope() + || this.media() + || this.comment() + || this.newline() + || this.escaped() + || this.important() + || this.literal() + || this.fun() + || this.brace() + || this.paren() + || this.color() + || this.string() + || this.unit() + || this.namedop() + || this.boolean() + || this.ident() + || this.op() + || this.space() + || this.selector(); + }, + + /** + * Lookahead a single token. + * + * @return {Token} + * @api private + */ + + peek: function() { + return this.lookahead(1); + }, + + /** + * Return the next possibly stashed token. + * + * @return {Token} + * @api private + */ + + stashed: function() { + return this.stash.shift(); + }, + + /** + * EOS | trailing outdents. + */ + + eos: function() { + if (this.str.length) return; + if (this.indentStack.length) { + this.indentStack.shift(); + return new Token('outdent'); + } else { + return new Token('eos'); + } + }, + + /** + * url char + */ + + urlchars: function() { + var captures; + if (!this.isURL) return; + if (captures = /^[\/:@.;?&=*!,<>#%0-9]+/.exec(this.str)) { + this.skip(captures); + return new Token('literal', new nodes.Literal(captures[0])); + } + }, + + /** + * ';' ' '* + */ + + sep: function() { + var captures; + if (captures = /^; */.exec(this.str)) { + this.skip(captures); + return new Token(';'); + } + }, + + /** + * ' '+ + */ + + space: function() { + var captures; + if (captures = /^( +)/.exec(this.str)) { + this.skip(captures); + return new Token('space'); + } + }, + + /** + * '\\' . ' '* + */ + + escaped: function() { + var captures; + if (captures = /^\\(.) */.exec(this.str)) { + var c = captures[1]; + this.skip(captures); + return new Token('ident', new nodes.Literal(c)); + } + }, + + /** + * '@css' ' '* '{' .* '}' ' '* + */ + + literal: function() { + // HACK attack !!! + var captures; + if (captures = /^@css *\{/.exec(this.str)) { + this.skip(captures); + var c + , braces = 1 + , css = ''; + while (c = this.str[0]) { + this.str = this.str.substr(1); + switch (c) { + case '{': ++braces; break; + case '}': --braces; break; + } + css += c; + if (!braces) break; + } + css = css.replace(/\s*}$/, ''); + return new Token('literal', new nodes.Literal(css)); + } + }, + + /** + * '!important' ' '* + */ + + important: function() { + var captures; + if (captures = /^!important */.exec(this.str)) { + this.skip(captures); + return new Token('ident', new nodes.Literal('!important')); + } + }, + + /** + * '{' | '}' + */ + + brace: function() { + var captures; + if (captures = /^([{}])/.exec(this.str)) { + this.skip(1); + var brace = captures[1]; + return new Token(brace, brace); + } + }, + + /** + * '(' | ')' ' '* + */ + + paren: function() { + var captures; + if (captures = /^([()]) */.exec(this.str)) { + var paren = captures[1]; + this.skip(captures); + if (')' == paren) this.isURL = false; + return new Token(paren, paren); + } + }, + + /** + * 'null' + */ + + nil: function() { + var captures; + if (captures = /^(null)\b */.exec(this.str)) { + this.skip(captures); + return new Token('null', nodes.nil); + } + }, + + /** + * 'if' + * | 'else' + * | 'unless' + * | 'return' + * | 'for' + * | 'in' + */ + + keyword: function() { + var captures; + if (captures = /^(return|if|else|unless|for|in)\b */.exec(this.str)) { + var keyword = captures[1]; + this.skip(captures); + return new Token(keyword, keyword); + } + }, + + /** + * 'not' + * | 'and' + * | 'or' + * | 'is' + * | 'is not' + * | 'isnt' + * | 'is a' + * | 'is defined' + */ + + namedop: function() { + var captures; + if (captures = /^(not|and|or|is a|is defined|isnt|is not|is)\b( *)/.exec(this.str)) { + var op = captures[1]; + this.skip(captures); + op = alias[op] || op; + var tok = new Token(op, op); + tok.space = captures[2]; + return tok; + } + }, + + /** + * ',' + * | '+' + * | '+=' + * | '-' + * | '-=' + * | '*' + * | '*=' + * | '/' + * | '/=' + * | '%' + * | '%=' + * | '**' + * | '!' + * | '&' + * | '&&' + * | '||' + * | '>' + * | '>=' + * | '<' + * | '<=' + * | '=' + * | '==' + * | '!=' + * | '!' + * | '~' + * | '?=' + * | ':=' + * | '?' + * | ':' + * | '[' + * | ']' + * | '..' + * | '...' + */ + + op: function() { + var captures; + if (captures = /^([.]{2,3}|&&|\|\||[!<>=?:]=|\*\*|[-+*\/%]=?|[,=?:!~<>&\[\]])( *)/.exec(this.str)) { + var op = captures[1]; + this.skip(captures); + op = alias[op] || op; + var tok = new Token(op, op); + tok.space = captures[2]; + return tok; + } + }, + + /** + * '@media' ([^{\n]+) + */ + + media: function() { + var captures; + if (captures = /^@media *([^\/{\n]+)/.exec(this.str)) { + this.skip(captures); + return new Token('media', captures[1].trim()); + } + }, + + /** + * '@scope' ([^{\n]+) + */ + + scope: function() { + var captures; + if (captures = /^@scope *([^\/{\n]+)/.exec(this.str)) { + this.skip(captures); + return new Token('scope', captures[1].trim()); + } + }, + + /** + * '@' ('import' | 'keyframes' | 'charset' | 'page' | 'font-face') + */ + + atrule: function() { + var captures; + if (captures = /^@(import|(?:-(\w+)-)?keyframes|charset|font-face|page) */.exec(this.str)) { + this.skip(captures); + var vendor = captures[2] + , type = captures[1]; + if (vendor) type = 'keyframes'; + return new Token(type, vendor); + } + }, + + /** + * '//' * + */ + + comment: function() { + // Single line + if ('/' == this.str[0] && '/' == this.str[1]) { + var end = this.str.indexOf('\n'); + if (-1 == end) end = this.str.length; + this.skip(end); + return this.advance(); + } + + // Multi-line + if ('/' == this.str[0] && '*' == this.str[1]) { + var end = this.str.indexOf('*/'); + if (-1 == end) end = this.str.length; + var str = this.str.substr(0, end + 2) + , lines = str.split('\n').length - 1 + , suppress = true; + this.lineno += lines; + this.skip(end + 2); + // output + if ('!' == str[2]) { + str = str.replace('*!', '*'); + suppress = false; + } + return new Token('comment', new nodes.Comment(str, suppress)); + } + }, + + /** + * 'true' | 'false' + */ + + boolean: function() { + var captures; + if (captures = /^(true|false)\b( *)/.exec(this.str)) { + var val = nodes.Boolean('true' == captures[1]); + this.skip(captures); + var tok = new Token('boolean', val); + tok.space = captures[2]; + return tok; + } + }, + + /** + * -?[a-zA-Z$] [-\w\d$]* '(' + */ + + fun: function() { + var captures; + if (captures = /^(-?[a-zA-Z$][-\w\d$]*)\(( *)/.exec(this.str)) { + var name = captures[1]; + this.skip(captures); + this.isURL = 'url' == name; + var tok = new Token('function', new nodes.Ident(name)); + tok.space = captures[2]; + return tok; + } + }, + + /** + * -?[_a-zA-Z$] [-\w\d$]* + */ + + ident: function() { + var captures; + if (captures = /^(@)?(-?[_a-zA-Z$][-\w\d$]*)/.exec(this.str)) { + var at = captures[1] + , name = captures[2] + , id = new nodes.Ident(name); + this.skip(captures); + id.property = !! at; + return new Token('ident', id); + } + }, + + /** + * '\n' ' '+ + */ + + newline: function() { + var captures, re; + + // we have established the indentation regexp + if (this.indentRe){ + captures = this.indentRe.exec(this.str); + // figure out if we are using tabs or spaces + } else { + // try tabs + re = /^\n([\t]*) */; + captures = re.exec(this.str); + + // nope, try spaces + if (captures && !captures[1].length) { + re = /^\n( *)/; + captures = re.exec(this.str); + } + + // established + if (captures && captures[1].length) this.indentRe = re; + } + + + if (captures) { + var tok + , indents = captures[1].length; + + this.skip(captures); + if (this.str[0] === ' ' || this.str[0] === '\t') { + throw new errors.SyntaxError('Invalid indentation. You can use tabs or spaces to indent, but not both.'); + } + + // Reset state + this.isVariable = false; + + // Blank line + if ('\n' == this.str[0]) { + ++this.lineno; + return this.advance(); + } + + // Outdent + if (this.indentStack.length && indents < this.indentStack[0]) { + while (this.indentStack.length && this.indentStack[0] > indents) { + this.stash.push(new Token('outdent')); + this.indentStack.shift(); + } + tok = this.stash.pop(); + // Indent + } else if (indents && indents != this.indentStack[0]) { + this.indentStack.unshift(indents); + tok = new Token('indent'); + // Newline + } else { + tok = new Token('newline'); + } + + return tok; + } + }, + + /** + * '-'? (digit+ | digit* '.' digit+) unit + */ + + unit: function() { + var captures; + if (captures = unit.exec(this.str)) { + this.skip(captures); + var n = parseFloat(captures[2]); + if ('-' == captures[1]) n = -n; + var node = new nodes.Unit(n, captures[3]); + return new Token('unit', node); + } + }, + + /** + * '"' [^"]+ '"' | "'"" [^']+ "'" + */ + + string: function() { + var captures; + if (captures = /^("[^"]*"|'[^']*') */.exec(this.str)) { + var str = captures[1]; + this.skip(captures); + str = str.slice(1,-1).replace(/\\n/g, '\n'); + return new Token('string', new nodes.String(str)); + } + }, + + /** + * #rrggbbaa | #rrggbb | #rgba | #rgb + */ + + color: function() { + return this.rrggbbaa() + || this.rrggbb() + || this.rgba() + || this.rgb() + }, + + /** + * #rgb + */ + + rgb: function() { + var captures; + if (captures = /^#([a-fA-F0-9]{3}) */.exec(this.str)) { + this.skip(captures); + var rgb = captures[1] + , r = parseInt(rgb[0] + rgb[0], 16) + , g = parseInt(rgb[1] + rgb[1], 16) + , b = parseInt(rgb[2] + rgb[2], 16) + , color = new nodes.RGBA(r, g, b, 1); + color.raw = captures[0]; + return new Token('color', color); + } + }, + + /** + * #rgba + */ + + rgba: function() { + var captures; + if (captures = /^#([a-fA-F0-9]{4}) */.exec(this.str)) { + this.skip(captures); + var rgb = captures[1] + , r = parseInt(rgb[0] + rgb[0], 16) + , g = parseInt(rgb[1] + rgb[1], 16) + , b = parseInt(rgb[2] + rgb[2], 16) + , a = parseInt(rgb[3] + rgb[3], 16) + , color = new nodes.RGBA(r, g, b, a/255); + color.raw = captures[0]; + return new Token('color', color); + } + }, + + /** + * #rrggbb + */ + + rrggbb: function() { + var captures; + if (captures = /^#([a-fA-F0-9]{6}) */.exec(this.str)) { + this.skip(captures); + var rgb = captures[1] + , r = parseInt(rgb.substr(0, 2), 16) + , g = parseInt(rgb.substr(2, 2), 16) + , b = parseInt(rgb.substr(4, 2), 16) + , color = new nodes.RGBA(r, g, b, 1); + color.raw = captures[0]; + return new Token('color', color); + } + }, + + /** + * #rrggbbaa + */ + + rrggbbaa: function() { + var captures; + if (captures = /^#([a-fA-F0-9]{8}) */.exec(this.str)) { + this.skip(captures); + var rgb = captures[1] + , r = parseInt(rgb.substr(0, 2), 16) + , g = parseInt(rgb.substr(2, 2), 16) + , b = parseInt(rgb.substr(4, 2), 16) + , a = parseInt(rgb.substr(6, 2), 16) + , color = new nodes.RGBA(r, g, b, a/255); + color.raw = captures[0]; + return new Token('color', color); + } + }, + + /** + * [^\n,;]+ + */ + + selector: function() { + var captures; + if (captures = /^[^{\n,]+/.exec(this.str)) { + var selector = captures[0]; + this.skip(captures); + return new Token('selector', selector); + } + } +}; + + +});// module: lexer.js + + +require.register("nodes/arguments.js", function(module, exports, require){ + + +/*! + * Stylus - Arguments + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('../nodes') + , utils = require('../utils'); + +/** + * Initialize a new `Arguments`. + * + * @api public + */ + +var Arguments = module.exports = function Arguments(){ + nodes.Expression.call(this); + this.map = {}; +}; + +/** + * Inherit from `nodes.Expression.prototype`. + */ + +Arguments.prototype.__proto__ = nodes.Expression.prototype; + +/** + * Initialize an `Arguments` object with the nodes + * from the given `expr`. + * + * @param {Expression} expr + * @return {Arguments} + * @api public + */ + +Arguments.fromExpression = function(expr){ + var args = new Arguments + , len = expr.nodes.length; + args.lineno = expr.lineno; + args.isList = expr.isList; + for (var i = 0; i < len; ++i) { + args.push(expr.nodes[i]); + } + return args; +}; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Arguments.prototype.clone = function(){ + var clone = nodes.Expression.prototype.clone.call(this); + clone.map = this.map; + return clone; +}; + + + +});// module: nodes/arguments.js + + +require.register("nodes/binop.js", function(module, exports, require){ + + +/*! + * Stylus - BinOp + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `BinOp` with `op`, `left` and `right`. + * + * @param {String} op + * @param {Node} left + * @param {Node} right + * @api public + */ + +var BinOp = module.exports = function BinOp(op, left, right){ + Node.call(this); + this.op = op; + this.left = left; + this.right = right; +}; + +/** + * Inherit from `Node.prototype`. + */ + +BinOp.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +BinOp.prototype.clone = function(){ + var clone = new BinOp( + this.op + , this.left.clone() + , this.right ? + this.right.clone() + : null); + clone.lineno = this.lineno; + clone.filename = this.filename; + if (this.val) clone.val = this.val.clone(); + return clone; +}; + +});// module: nodes/binop.js + + +require.register("nodes/block.js", function(module, exports, require){ + + +/*! + * Stylus - Block + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Block` node with `parent` Block. + * + * @param {Block} parent + * @api public + */ + +var Block = module.exports = function Block(parent, node){ + Node.call(this); + this.nodes = []; + this.parent = parent; + this.node = node; + this.scope = true; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Block.prototype.__proto__ = Node.prototype; + +/** + * Check if this block has properties.. + * + * @return {Boolean} + * @api public + */ + +Block.prototype.__defineGetter__('hasProperties', function(){ + for (var i = 0, len = this.nodes.length; i < len; ++i) { + if ('property' == this.nodes[i].nodeName) { + return true; + } + } +}); + +/** + * Check if this block is empty. + * + * @return {Boolean} + * @api public + */ + +Block.prototype.__defineGetter__('isEmpty', function(){ + return !this.nodes.length; +}); + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Block.prototype.clone = function(){ + var clone = new Block(this.parent, this.node); + clone.lineno = this.lineno; + clone.filename = this.filename; + clone.scope = this.scope; + this.nodes.forEach(function(node){ + node = node.clone(); + switch (node.nodeName) { + case 'each': + case 'group': + node.block.parent = clone; + break; + case 'ident': + if ('function' == node.val.nodeName) { + node.val.block.parent = clone; + } + } + clone.push(node); + }); + return clone; +}; + +/** + * Push a `node` to this block. + * + * @param {Node} node + * @api public + */ + +Block.prototype.push = function(node){ + this.nodes.push(node); +}; + + +});// module: nodes/block.js + + +require.register("nodes/boolean.js", function(module, exports, require){ + + +/*! + * Stylus - Boolean + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `Boolean` node with the given `val`. + * + * @param {Boolean} val + * @api public + */ + +var Boolean = module.exports = function Boolean(val){ + Node.call(this); + if (this.nodeName) { + this.val = !!val; + } else { + return new Boolean(val); + } +}; + +/** + * Inherit from `Node.prototype`. + */ + +Boolean.prototype.__proto__ = Node.prototype; + +/** + * Return `this` node. + * + * @return {Boolean} + * @api public + */ + +Boolean.prototype.toBoolean = function(){ + return this; +}; + +/** + * Return `true` if this node represents `true`. + * + * @return {Boolean} + * @api public + */ + +Boolean.prototype.__defineGetter__('isTrue', function(){ + return this.val; +}); + +/** + * Return `true` if this node represents `false`. + * + * @return {Boolean} + * @api public + */ + +Boolean.prototype.__defineGetter__('isFalse', function(){ + return ! this.val; +}); + +/** + * Negate the value. + * + * @return {Boolean} + * @api public + */ + +Boolean.prototype.negate = function(){ + return Boolean(!this.val); +}; + +/** + * Return 'Boolean'. + * + * @return {String} + * @api public + */ + +Boolean.prototype.inspect = function(){ + return '[Boolean ' + this.val + ']'; +}; + +/** + * Return 'true' or 'false'. + * + * @return {String} + * @api public + */ + +Boolean.prototype.toString = function(){ + return this.val + ? 'true' + : 'false'; +}; + +});// module: nodes/boolean.js + + +require.register("nodes/call.js", function(module, exports, require){ + + +/*! + * Stylus - Call + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Call` with `name` and `args`. + * + * @param {String} name + * @param {Expression} args + * @api public + */ + +var Call = module.exports = function Call(name, args){ + Node.call(this); + this.name = name; + this.args = args; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Call.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Call.prototype.clone = function(){ + var clone = new Call(this.name, this.args.clone()); + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +/** + * Return (). + * + * @return {String} + * @api public + */ + +Call.prototype.toString = function(){ + return this.name + '()'; +}; + +});// module: nodes/call.js + + +require.register("nodes/charset.js", function(module, exports, require){ + + +/*! + * Stylus - Charset + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `Charset` with the given `val` + * + * @param {String} val + * @api public + */ + +var Charset = module.exports = function Charset(val){ + Node.call(this); + this.val = val; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Charset.prototype.__proto__ = Node.prototype; + +/** + * Return @charset "val". + * + * @return {String} + * @api public + */ + +Charset.prototype.toString = function(){ + return '@charset ' + this.val; +}; + + +});// module: nodes/charset.js + + +require.register("nodes/comment.js", function(module, exports, require){ + + +/*! + * Stylus - Comment + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Comment` with the given `str`. + * + * @param {String} str + * @param {Boolean} suppress + * @api public + */ + +var Comment = module.exports = function Comment(str, suppress){ + Node.call(this); + this.str = str; + this.suppress = suppress; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Comment.prototype.__proto__ = Node.prototype; + + +});// module: nodes/comment.js + + +require.register("nodes/each.js", function(module, exports, require){ + + +/*! + * Stylus - Each + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `Each` node with the given `val` name, + * `key` name, `expr`, and `block`. + * + * @param {String} val + * @param {String} key + * @param {Expression} expr + * @param {Block} block + * @api public + */ + +var Each = module.exports = function Each(val, key, expr, block){ + Node.call(this); + this.val = val; + this.key = key; + this.expr = expr; + this.block = block; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Each.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Each.prototype.clone = function(){ + var clone = new Each( + this.val + , this.key + , this.expr.clone() + , this.block.clone()); + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +});// module: nodes/each.js + + +require.register("nodes/expression.js", function(module, exports, require){ + + +/*! + * Stylus - Expression + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('../nodes') + , utils = require('../utils'); + +/** + * Initialize a new `Expression`. + * + * @param {Boolean} isList + * @api public + */ + +var Expression = module.exports = function Expression(isList){ + Node.call(this); + this.nodes = []; + this.isList = isList; +}; + +/** + * Check if the variable has a value. + * + * @return {Boolean} + * @api public + */ + +Expression.prototype.__defineGetter__('isEmpty', function(){ + return !this.nodes.length; +}); + +/** + * Return the first node in this expression. + * + * @return {Node} + * @api public + */ + +Expression.prototype.__defineGetter__('first', function(){ + return this.nodes[0] + ? this.nodes[0].first + : nodes.nil; +}); + +/** + * Hash all the nodes in order. + * + * @return {String} + * @api public + */ + +Expression.prototype.__defineGetter__('hash', function(){ + return this.nodes.map(function(node){ + return node.hash; + }).join('::'); +}); + +/** + * Inherit from `Node.prototype`. + */ + +Expression.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Expression.prototype.clone = function(){ + var clone = new this.constructor(this.isList); + clone.preserve = this.preserve; + clone.lineno = this.lineno; + clone.filename = this.filename; + for (var i = 0; i < this.nodes.length; ++i) { + clone.push(this.nodes[i].clone()); + } + return clone; +}; + +/** + * Push the given `node`. + * + * @param {Node} node + * @api public + */ + +Expression.prototype.push = function(node){ + this.nodes.push(node); +}; + +/** + * Operate on `right` with the given `op`. + * + * @param {String} op + * @param {Node} right + * @return {Node} + * @api public + */ + +Expression.prototype.operate = function(op, right, val){ + switch (op) { + case '[]=': + var self = this + , range = utils.unwrap(right).nodes + , val = utils.unwrap(val) + , len; + range.forEach(function(unit){ + len = self.nodes.length; + if ('unit' == unit.nodeName) { + var i = unit.val; + while (i-- > len) self.nodes[i] = nodes.nil; + self.nodes[unit.val] = val; + } + }); + return val; + case '[]': + var expr = new nodes.Expression + , vals = utils.unwrap(this).nodes + , range = utils.unwrap(right).nodes; + range.forEach(function(unit){ + if ('unit' == unit.nodeName) { + var node = vals[unit.val]; + if (node) expr.push(node); + } + }); + return expr.isEmpty + ? nodes.nil + : utils.unwrap(expr); + case '||': + // we consider lists with length > 1 truth, + // for example (0 1 2) + if (this.nodes.length > 1) return this; + + // check the return value, and return the lhs expr + // as a whole rather than the first item + var ret = this.first.operate(op, right, val); + return ret == this.nodes[0] ? this : right; + case 'in': + return Node.prototype.operate.call(this, op, right); + case '!=': + return this.operate('==', right, val).negate(); + case '==': + var len = this.nodes.length + , right = right.toExpression() + , a + , b; + if (len != right.nodes.length) return nodes.no; + for (var i = 0; i < len; ++i) { + a = this.nodes[i]; + b = right.nodes[i]; + if (a.operate(op, b).isTrue) continue; + return nodes.no; + } + return nodes.yes; + break; + default: + return this.first.operate(op, right, val); + } +}; + +/** + * Iterate nodes to return a `Boolean`. + * + * @return {Boolean} + * @api public + */ + +Expression.prototype.toBoolean = function(){ + for (var i = 0, len = this.nodes.length; i < len; ++i) { + if (this.nodes[i].toBoolean().isTrue) { + return nodes.yes; + } + } + return nodes.no; +}; + +/** + * Return " " or ", , " if + * the expression represents a list. + * + * @return {String} + * @api public + */ + +Expression.prototype.toString = function(){ + return '(' + this.nodes.map(function(node){ + return node.toString(); + }).join(this.isList ? ', ' : ' ') + ')'; +}; + + + +});// module: nodes/expression.js + + +require.register("nodes/fontface.js", function(module, exports, require){ + + +/*! + * Stylus - FontFace + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `FontFace` with the given `block`. + * + * @param {Block} block + * @api public + */ + +var FontFace = module.exports = function FontFace(block){ + Node.call(this); + this.block = block; +}; + +/** + * Inherit from `Node.prototype`. + */ + +FontFace.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +FontFace.prototype.clone = function(){ + var clone = new FontFace(this.block.clone()); + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +/** + * Return `@oage name`. + * + * @return {String} + * @api public + */ + +FontFace.prototype.toString = function(){ + return '@font-face'; +}; + + +});// module: nodes/fontface.js + + +require.register("nodes/function.js", function(module, exports, require){ + + +/*! + * Stylus - Function + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Function` with `name`, `params`, and `body`. + * + * @param {String} name + * @param {Params|Function} params + * @param {Block} body + * @api public + */ + +var Function = module.exports = function Function(name, params, body){ + Node.call(this); + this.name = name; + this.params = params; + this.block = body; + if ('function' == typeof params) this.fn = params; +}; + +/** + * Check function arity. + * + * @return {Boolean} + * @api public + */ + +Function.prototype.__defineGetter__('arity', function(){ + return this.params.length; +}); + +/** + * Inherit from `Node.prototype`. + */ + +Function.prototype.__proto__ = Node.prototype; + +/** + * Return hash. + * + * @return {String} + * @api public + */ + +Function.prototype.__defineGetter__('hash', function(){ + return 'function ' + this.name; +}); + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Function.prototype.clone = function(){ + if (this.fn) { + var clone = new Function( + this.name + , this.fn); + } else { + var clone = new Function( + this.name + , this.params.clone() + , this.block.clone()); + } + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +/** + * Return (param1, param2, ...). + * + * @return {String} + * @api public + */ + +Function.prototype.toString = function(){ + if (this.fn) { + return this.name + + '(' + + this.fn.toString() + .match(/^function *\((.*?)\)/) + .slice(1) + .join(', ') + + ')'; + } else { + return this.name + + '(' + + this.params.nodes.join(', ') + + ')'; + } +}; + + +});// module: nodes/function.js + + +require.register("nodes/group.js", function(module, exports, require){ + + +/*! + * Stylus - Group + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Group`. + * + * @api public + */ + +var Group = module.exports = function Group(){ + Node.call(this); + this.nodes = []; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Group.prototype.__proto__ = Node.prototype; + +/** + * Push the given `selector` node. + * + * @param {Selector} selector + * @api public + */ + +Group.prototype.push = function(selector){ + this.nodes.push(selector); +}; + +/** + * Return this set's `Block`. + */ + +Group.prototype.__defineGetter__('block', function(){ + return this.nodes[0].block; +}); + +/** + * Assign `block` to each selector in this set. + * + * @param {Block} block + * @api public + */ + +Group.prototype.__defineSetter__('block', function(block){ + for (var i = 0, len = this.nodes.length; i < len; ++i) { + this.nodes[i].block = block; + } +}); + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Group.prototype.clone = function(){ + var clone = new Group; + clone.lineno = this.lineno; + this.nodes.forEach(function(node){ + clone.push(node.clone()); + }); + clone.filename = this.filename; + clone.block = this.block.clone(); + return clone; +}; + + +});// module: nodes/group.js + + +require.register("nodes/hsla.js", function(module, exports, require){ + + +/*! + * Stylus - HSLA + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `HSLA` with the given h,s,l,a component values. + * + * @param {Number} h + * @param {Number} s + * @param {Number} l + * @param {Number} a + * @api public + */ + +var HSLA = exports = module.exports = function HSLA(h,s,l,a){ + Node.call(this); + this.h = clampDegrees(h); + this.s = clampPercentage(s); + this.l = clampPercentage(l); + this.a = clampAlpha(a); + this.hsla = this; +}; + +/** + * Inherit from `Node.prototype`. + */ + +HSLA.prototype.__proto__ = Node.prototype; + +/** + * Return hsla(n,n,n,n). + * + * @return {String} + * @api public + */ + +HSLA.prototype.toString = function(){ + return 'hsla(' + + this.h + ',' + + this.s.toFixed(0) + ',' + + this.l.toFixed(0) + ',' + + this.a + ')'; +}; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +HSLA.prototype.clone = function(){ + var clone = new HSLA( + this.h + , this.s + , this.l + , this.a); + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +/** + * Return rgba `RGBA` representation. + * + * @return {RGBA} + * @api public + */ + +HSLA.prototype.__defineGetter__('rgba', function(){ + return nodes.RGBA.fromHSLA(this); +}); + +/** + * Return hash. + * + * @return {String} + * @api public + */ + +HSLA.prototype.__defineGetter__('hash', function(){ + return this.rgba.toString(); +}); + +/** + * Add h,s,l to the current component values. + * + * @param {Number} h + * @param {Number} s + * @param {Number} l + * @return {HSLA} new node + * @api public + */ + +HSLA.prototype.add = function(h,s,l){ + return new HSLA( + this.h + h + , this.s + s + , this.l + l + , this.a); +}; + +/** + * Subtract h,s,l from the current component values. + * + * @param {Number} h + * @param {Number} s + * @param {Number} l + * @return {HSLA} new node + * @api public + */ + +HSLA.prototype.sub = function(h,s,l){ + return this.add(-h, -s, -l); +}; + +/** + * Operate on `right` with the given `op`. + * + * @param {String} op + * @param {Node} right + * @return {Node} + * @api public + */ + +HSLA.prototype.operate = function(op, right){ + switch (op) { + case '==': + case '!=': + case '<=': + case '>=': + case '<': + case '>': + case 'is a': + case '||': + case '&&': + return this.rgba.operate(op, right); + default: + return this.rgba.operate(op, right).hsla; + } +}; + +/** + * Return `HSLA` representation of the given `color`. + * + * @param {RGBA} color + * @return {HSLA} + * @api public + */ + +exports.fromRGBA = function(rgba){ + var r = rgba.r / 255 + , g = rgba.g / 255 + , b = rgba.b / 255 + , a = rgba.a; + + var min = Math.min(r,g,b) + , max = Math.max(r,g,b) + , l = (max + min) / 2 + , d = max - min + , h, s; + + switch (max) { + case min: h = 0; break; + case r: h = 60 * (g-b) / d; break; + case g: h = 60 * (b-r) / d + 120; break; + case b: h = 60 * (r-g) / d + 240; break; + } + + if (max == min) { + s = 0; + } else if (l < .5) { + s = d / (2 * l); + } else { + s = d / (2 - 2 * l); + } + + h %= 360; + s *= 100; + l *= 100; + + return new HSLA(h,s,l,a); +}; + +/** + * Adjust lightness by `percent`. + * + * @param {Number} percent + * @return {HSLA} for chaining + * @api public + */ + +HSLA.prototype.adjustLightness = function(percent){ + this.l = clampPercentage(this.l + this.l * (percent / 100)); + return this; +}; + +/** + * Adjust hue by `deg`. + * + * @param {Number} deg + * @return {HSLA} for chaining + * @api public + */ + +HSLA.prototype.adjustHue = function(deg){ + this.h = clampDegrees(this.h + deg); + return this; +}; + +/** + * Clamp degree `n` >= 0 and <= 360. + * + * @param {Number} n + * @return {Number} + * @api private + */ + +function clampDegrees(n) { + n = n % 360; + return n >= 0 ? n : 360 + n; +} + +/** + * Clamp percentage `n` >= 0 and <= 100. + * + * @param {Number} n + * @return {Number} + * @api private + */ + +function clampPercentage(n) { + return Math.max(0, Math.min(n, 100)); +} + +/** + * Clamp alpha `n` >= 0 and <= 1. + * + * @param {Number} n + * @return {Number} + * @api private + */ + +function clampAlpha(n) { + return Math.max(0, Math.min(n, 1)); +} + + +});// module: nodes/hsla.js + + +require.register("nodes/ident.js", function(module, exports, require){ + + +/*! + * Stylus - Ident + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `Ident` by `name` with the given `val` node. + * + * @param {String} name + * @param {Node} val + * @api public + */ + +var Ident = module.exports = function Ident(name, val){ + Node.call(this); + this.name = name; + this.string = name; + this.val = val || nodes.nil; +}; + +/** + * Check if the variable has a value. + * + * @return {Boolean} + * @api public + */ + +Ident.prototype.__defineGetter__('isEmpty', function(){ + return undefined == this.val; +}); + +/** + * Return hash. + * + * @return {String} + * @api public + */ + +Ident.prototype.__defineGetter__('hash', function(){ + return this.name; +}); + +/** + * Inherit from `Node.prototype`. + */ + +Ident.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Ident.prototype.clone = function(){ + var clone = new Ident(this.name, this.val.clone()); + clone.lineno = this.lineno; + clone.filename = this.filename; + clone.property = this.property; + return clone; +}; + +/** + * Return . + * + * @return {String} + * @api public + */ + +Ident.prototype.toString = function(){ + return this.name; +}; + +/** + * Coerce `other` to an ident. + * + * @param {Node} other + * @return {String} + * @api public + */ + +Ident.prototype.coerce = function(other){ + switch (other.nodeName) { + case 'ident': + case 'string': + case 'literal': + return new Ident(other.string); + default: + return Node.prototype.coerce.call(this, other); + } +}; + +/** + * Operate on `right` with the given `op`. + * + * @param {String} op + * @param {Node} right + * @return {Node} + * @api public + */ + +Ident.prototype.operate = function(op, right){ + var val = right.first; + switch (op) { + case '-': + if ('unit' == val.nodeName) { + var expr = new nodes.Expression; + val.val = -val.val; + expr.push(this); + expr.push(val); + return expr; + } + case '+': + return new nodes.Ident(this.string + this.coerce(val).string); + } + return Node.prototype.operate.call(this, op, right); +}; + + +});// module: nodes/ident.js + + +require.register("nodes/if.js", function(module, exports, require){ + + +/*! + * Stylus - If + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `If` with the given `cond`. + * + * @param {Expression} cond + * @param {Boolean|Block} negate, block + * @api public + */ + +var If = module.exports = function If(cond, negate){ + Node.call(this); + this.cond = cond; + this.elses = []; + if (negate && negate.nodeName) { + this.block = negate; + } else { + this.negate = negate; + } +}; + +/** + * Inherit from `Node.prototype`. + */ + +If.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +If.prototype.clone = function(){ + var cond = this.cond.clone() + , block = this.block.clone(); + var clone = new If(cond, block); + clone.elses = this.elses.map(function(node){ return node.clone(); }); + clone.negate = this.negate; + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + + +});// module: nodes/if.js + + +require.register("nodes/import.js", function(module, exports, require){ + + +/*! + * Stylus - Import + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Import` with the given `expr`. + * + * @param {Expression} expr + * @api public + */ + +var Import = module.exports = function Import(expr){ + Node.call(this); + this.path = expr; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Import.prototype.__proto__ = Node.prototype; + + +});// module: nodes/import.js + + +require.register("nodes/index.js", function(module, exports, require){ + + +/*! + * Stylus - nodes + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Constructors + */ + +exports.Node = require('./node'); +exports.Root = require('./root'); +exports.Null = require('./null'); +exports.Each = require('./each'); +exports.If = require('./if'); +exports.Call = require('./call'); +exports.Page = require('./page'); +exports.FontFace = require('./fontface'); +exports.UnaryOp = require('./unaryop'); +exports.BinOp = require('./binop'); +exports.Ternary = require('./ternary'); +exports.Block = require('./block'); +exports.Unit = require('./unit'); +exports.String = require('./string'); +exports.HSLA = require('./hsla'); +exports.RGBA = require('./rgba'); +exports.Ident = require('./ident'); +exports.Group = require('./group'); +exports.Literal = require('./literal'); +exports.JSLiteral = require('./jsliteral'); +exports.Boolean = require('./boolean'); +exports.Return = require('./return'); +exports.Media = require('./media'); +exports.Params = require('./params'); +exports.Comment = require('./comment'); +exports.Keyframes = require('./keyframes'); +exports.Charset = require('./charset'); +exports.Import = require('./import'); +exports.Function = require('./function'); +exports.Property = require('./property'); +exports.Selector = require('./selector'); +exports.Expression = require('./expression'); +exports.Arguments = require('./arguments'); + +/** + * Singletons. + */ + +exports.yes = new exports.Boolean(true); +exports.no = new exports.Boolean(false); +exports.nil = new exports.Null; + +});// module: nodes/index.js + + +require.register("nodes/jsliteral.js", function(module, exports, require){ + + +/*! + * Stylus - JSLiteral + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `JSLiteral` with the given `str`. + * + * @param {String} str + * @api public + */ + +var JSLiteral = module.exports = function JSLiteral(str){ + Node.call(this); + this.val = str; + this.string = str; +}; + +/** + * Inherit from `Node.prototype`. + */ + +JSLiteral.prototype.__proto__ = Node.prototype; + + +});// module: nodes/jsliteral.js + + +require.register("nodes/keyframes.js", function(module, exports, require){ + + +/*! + * Stylus - Keyframes + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Keyframes` with the given `name`, + * and optional vendor `prefix`. + * + * @param {String} name + * @param {String} prefix + * @api public + */ + +var Keyframes = module.exports = function Keyframes(name, prefix){ + Node.call(this); + this.name = name; + this.frames = []; + this.prefix = prefix || 'official'; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Keyframes.prototype.__proto__ = Node.prototype; + +/** + * Push the given `block` at `pos`. + * + * @param {Unit} pos + * @param {Block} block + * @api public + */ + +Keyframes.prototype.push = function(pos, block){ + this.frames.push({ + pos: pos + , block: block + }); +}; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Keyframes.prototype.clone = function(){ + var clone = new Keyframes(this.name); + clone.lineno = this.lineno; + clone.prefix = this.prefix; + clone.frames = this.frames.map(function(node){ + node.block = node.block.clone(); + return node; + }); + return clone; +}; + +/** + * Return `@keyframes name`. + * + * @return {String} + * @api public + */ + +Keyframes.prototype.toString = function(){ + return '@keyframes ' + this.name; +}; + + +});// module: nodes/keyframes.js + + +require.register("nodes/literal.js", function(module, exports, require){ + + +/*! + * Stylus - Literal + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `Literal` with the given `str`. + * + * @param {String} str + * @api public + */ + +var Literal = module.exports = function Literal(str){ + Node.call(this); + this.val = str; + this.string = str; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Literal.prototype.__proto__ = Node.prototype; + +/** + * Return hash. + * + * @return {String} + * @api public + */ + +Literal.prototype.__defineGetter__('hash', function(){ + return this.val; +}); + +/** + * Return literal value. + * + * @return {String} + * @api public + */ + +Literal.prototype.toString = function(){ + return this.val; +}; + +/** + * Coerce `other` to a literal. + * + * @param {Node} other + * @return {String} + * @api public + */ + +Literal.prototype.coerce = function(other){ + switch (other.nodeName) { + case 'ident': + case 'string': + case 'literal': + return new Literal(other.string); + default: + return Node.prototype.coerce.call(this, other); + } +}; + +/** + * Operate on `right` with the given `op`. + * + * @param {String} op + * @param {Node} right + * @return {Node} + * @api public + */ + +Literal.prototype.operate = function(op, right){ + var val = right.first; + switch (op) { + case '+': + return new nodes.Literal(this.string + this.coerce(val).string); + default: + return Node.prototype.operate.call(this, op, right); + } +}; + + +});// module: nodes/literal.js + + +require.register("nodes/media.js", function(module, exports, require){ + + +/*! + * Stylus - Media + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `Media` with the given `val` + * + * @param {String} val + * @api public + */ + +var Media = module.exports = function Media(val){ + Node.call(this); + this.val = val; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Media.prototype.__proto__ = Node.prototype; + +/** + * Return @media "val". + * + * @return {String} + * @api public + */ + +Media.prototype.toString = function(){ + return '@media ' + this.val; +}; + + +});// module: nodes/media.js + + +require.register("nodes/node.js", function(module, exports, require){ + + +/*! + * Stylus - Node + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Evaluator = require('../visitor/evaluator') + , utils = require('../utils') + , nodes = require('./index'); + +/** + * Node constructor. + * + * @api public + */ + +var Node = module.exports = function Node(){ + this.lineno = nodes.lineno; + Object.defineProperty(this, 'filename', { writable: true, value: nodes.filename }); +}; + +/** + * Return this node. + * + * @return {Node} + * @api public + */ + +Node.prototype.__defineGetter__('first', function(){ + return this; +}); + +/** + * Return hash. + * + * @return {String} + * @api public + */ + +Node.prototype.__defineGetter__('hash', function(){ + return this.val; +}); + +/** + * Return node name. + * + * @return {String} + * @api public + */ + +Node.prototype.__defineGetter__('nodeName', function(){ + return this.constructor.name.toLowerCase(); +}); + +/** + * Return this node. + * + * @return {Node} + * @api public + */ + +Node.prototype.clone = function(){ + return this; +}; + +/** + * Nodes by default evaluate to themselves. + * + * @return {Node} + * @api public + */ + +Node.prototype.eval = function(){ + return new Evaluator(this).evaluate(); +}; + +/** + * Return true. + * + * @return {Boolean} + * @api public + */ + +Node.prototype.toBoolean = function(){ + return nodes.yes; +}; + +/** + * Return the expression, or wrap this node in an expression. + * + * @return {Expression} + * @api public + */ + +Node.prototype.toExpression = function(){ + if ('expression' == this.nodeName) return this; + var expr = new nodes.Expression; + expr.push(this); + return expr; +}; + +/** + * Return false if `op` is generally not coerced. + * + * @param {String} op + * @return {Boolean} + * @api private + */ + +Node.prototype.shouldCoerce = function(op){ + switch (op) { + case 'is a': + case 'in': + case '||': + case '&&': + return false; + default: + return true; + } +}; + +/** + * Operate on `right` with the given `op`. + * + * @param {String} op + * @param {Node} right + * @return {Node} + * @api public + */ + +Node.prototype.operate = function(op, right){ + switch (op) { + case 'is a': + if ('string' == right.nodeName) { + return nodes.Boolean(this.nodeName == right.val); + } else { + throw new Error('"is a" expects a string, got ' + right.toString()); + } + case '==': + return nodes.Boolean(this.hash == right.hash); + case '!=': + return nodes.Boolean(this.hash != right.hash); + case '>=': + return nodes.Boolean(this.hash >= right.hash); + case '<=': + return nodes.Boolean(this.hash <= right.hash); + case '>': + return nodes.Boolean(this.hash > right.hash); + case '<': + return nodes.Boolean(this.hash < right.hash); + case '||': + return this.toBoolean().isTrue + ? this + : right; + case 'in': + var vals = utils.unwrap(right).nodes + , hash = this.hash; + if (!vals) throw new Error('"in" given invalid right-hand operand, expecting an expression'); + for (var i = 0, len = vals.length; i < len; ++i) { + if (hash == vals[i].hash) { + return nodes.yes; + } + } + return nodes.no; + case '&&': + var a = this.toBoolean() + , b = right.toBoolean(); + return a.isTrue && b.isTrue + ? right + : a.isFalse + ? this + : right; + default: + if ('[]' == op) { + var msg = 'cannot perform ' + + this + + '[' + right + ']'; + } else { + var msg = 'cannot perform' + + ' ' + this + + ' ' + op + + ' ' + right; + } + throw new Error(msg); + } +}; + +/** + * Initialize a new `CoercionError` with the given `msg`. + * + * @param {String} msg + * @api private + */ + +function CoercionError(msg) { + this.name = 'CoercionError' + this.message = msg + Error.captureStackTrace(this, CoercionError); +} + +/** + * Inherit from `Error.prototype`. + */ + +CoercionError.prototype.__proto__ = Error.prototype; + +/** + * Default coercion throws. + * + * @param {Node} other + * @return {Node} + * @api public + */ + +Node.prototype.coerce = function(other){ + if (other.nodeName == this.nodeName) return other; + throw new CoercionError('cannot coerce ' + other + ' to ' + this.nodeName); +}; + + +});// module: nodes/node.js + + +require.register("nodes/null.js", function(module, exports, require){ + + +/*! + * Stylus - Null + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `Null` node. + * + * @api public + */ + +var Null = module.exports = function Null(){}; + +/** + * Inherit from `Node.prototype`. + */ + +Null.prototype.__proto__ = Node.prototype; + +/** + * Return 'Null'. + * + * @return {String} + * @api public + */ + +Null.prototype.inspect = +Null.prototype.toString = function(){ + return 'null'; +}; + +/** + * Return false. + * + * @return {Boolean} + * @api public + */ + +Null.prototype.toBoolean = function(){ + return nodes.no; +}; + +/** + * Check if the node is a null node. + * + * @return {Boolean} + * @api public + */ + +Null.prototype.__defineGetter__('isNull', function(){ + return true; +}); + +/** + * Return hash. + * + * @return {String} + * @api public + */ + +Null.prototype.__defineGetter__('hash', function(){ + return null; +}); + +});// module: nodes/null.js + + +require.register("nodes/page.js", function(module, exports, require){ + + +/*! + * Stylus - Page + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Page` with the given `selector` and `block`. + * + * @param {Selector} selector + * @param {Block} block + * @api public + */ + +var Page = module.exports = function Page(selector, block){ + Node.call(this); + this.selector = selector; + this.block = block; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Page.prototype.__proto__ = Node.prototype; + +/** + * Return `@oage name`. + * + * @return {String} + * @api public + */ + +Page.prototype.toString = function(){ + return '@page ' + this.selector; +}; + + +});// module: nodes/page.js + + +require.register("nodes/params.js", function(module, exports, require){ + + +/*! + * Stylus - Params + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Params` with `name`, `params`, and `body`. + * + * @param {String} name + * @param {Params} params + * @param {Expression} body + * @api public + */ + +var Params = module.exports = function Params(){ + Node.call(this); + this.nodes = []; +}; + +/** + * Check function arity. + * + * @return {Boolean} + * @api public + */ + +Params.prototype.__defineGetter__('length', function(){ + return this.nodes.length; +}); + +/** + * Inherit from `Node.prototype`. + */ + +Params.prototype.__proto__ = Node.prototype; + +/** + * Push the given `node`. + * + * @param {Node} node + * @api public + */ + +Params.prototype.push = function(node){ + this.nodes.push(node); +}; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Params.prototype.clone = function(){ + var clone = new Params; + clone.lineno = this.lineno; + clone.filename = this.filename; + this.nodes.forEach(function(node){ + clone.push(node.clone()); + }); + return clone; +}; + + + +});// module: nodes/params.js + + +require.register("nodes/property.js", function(module, exports, require){ + + +/*! + * Stylus - Property + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Property` with the given `segs` and optional `expr`. + * + * @param {Array} segs + * @param {Expression} expr + * @api public + */ + +var Property = module.exports = function Property(segs, expr){ + Node.call(this); + this.segments = segs; + this.expr = expr; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Property.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Property.prototype.clone = function(){ + var clone = new Property(this.segments); + clone.lineno = this.lineno; + clone.filename = this.filename; + clone.segments = this.segments.map(function(node){ return node.clone(); }); + if (this.expr) clone.expr = this.expr.clone(); + return clone; +}; + +/** + * Return string representation of this node. + * + * @return {String} + * @api public + */ + +Property.prototype.toString = function(){ + return 'property(' + this.name + ', ' + this.expr + ')'; +}; + +/** + * Operate on the property expression. + * + * @param {String} op + * @param {Node} right + * @return {Node} + * @api public + */ + +Property.prototype.operate = function(op, right, val){ + return this.expr.operate(op, right, val); +}; + + +});// module: nodes/property.js + + +require.register("nodes/return.js", function(module, exports, require){ + + +/*! + * Stylus - Return + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `Return` node with the given `expr`. + * + * @param {Expression} expr + * @api public + */ + +var Return = module.exports = function Return(expr){ + this.expr = expr || nodes.nil; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Return.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Return.prototype.clone = function(){ + var clone = new Return(this.expr.clone()); + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +});// module: nodes/return.js + + +require.register("nodes/rgba.js", function(module, exports, require){ + + +/*! + * Stylus - RGBA + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , HSLA = require('./hsla') + , functions = require('../functions') + , adjust = functions['-adjust'] + , nodes = require('./index'); + +/** + * Initialize a new `RGBA` with the given r,g,b,a component values. + * + * @param {Number} r + * @param {Number} g + * @param {Number} b + * @param {Number} a + * @api public + */ + +var RGBA = exports = module.exports = function RGBA(r,g,b,a){ + Node.call(this); + this.r = clamp(r); + this.g = clamp(g); + this.b = clamp(b); + this.a = clampAlpha(a); + this.rgba = this; +}; + +/** + * Inherit from `Node.prototype`. + */ + +RGBA.prototype.__proto__ = Node.prototype; + +/** + * Return an `RGBA` without clamping values. + * + * @param {Number} r + * @param {Number} g + * @param {Number} b + * @param {Number} a + * @return {RGBA} + * @api public + */ + +RGBA.withoutClamping = function(r,g,b,a){ + var rgba = new RGBA(0,0,0,0); + rgba.r = r; + rgba.g = g; + rgba.b = b; + rgba.a = a; + return rgba; +}; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +RGBA.prototype.clone = function(){ + var clone = new RGBA( + this.r + , this.g + , this.b + , this.a); + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +/** + * Return true. + * + * @return {Boolean} + * @api public + */ + +RGBA.prototype.toBoolean = function(){ + return nodes.yes; +}; + +/** + * Return `HSLA` representation. + * + * @return {HSLA} + * @api public + */ + +RGBA.prototype.__defineGetter__('hsla', function(){ + return HSLA.fromRGBA(this); +}); + +/** + * Return hash. + * + * @return {String} + * @api public + */ + +RGBA.prototype.__defineGetter__('hash', function(){ + return this.toString(); +}); + +/** + * Add r,g,b,a to the current component values. + * + * @param {Number} r + * @param {Number} g + * @param {Number} b + * @param {Number} a + * @return {RGBA} new node + * @api public + */ + +RGBA.prototype.add = function(r,g,b,a){ + return new RGBA( + this.r + r + , this.g + g + , this.b + b + , this.a + a); +}; + +/** + * Subtract r,g,b,a from the current component values. + * + * @param {Number} r + * @param {Number} g + * @param {Number} b + * @param {Number} a + * @return {RGBA} new node + * @api public + */ + +RGBA.prototype.sub = function(r,g,b,a){ + return new RGBA( + this.r - r + , this.g - g + , this.b - b + , a == 1 ? this.a : this.a - a); +}; + +/** + * Multiply rgb components by `n`. + * + * @param {String} n + * @return {RGBA} new node + * @api public + */ + +RGBA.prototype.multiply = function(n){ + return new RGBA( + this.r * n + , this.g * n + , this.b * n + , this.a); +}; + +/** + * Divide rgb components by `n`. + * + * @param {String} n + * @return {RGBA} new node + * @api public + */ + +RGBA.prototype.divide = function(n){ + return new RGBA( + this.r / n + , this.g / n + , this.b / n + , this.a); +}; + +/** + * Operate on `right` with the given `op`. + * + * @param {String} op + * @param {Node} right + * @return {Node} + * @api public + */ + +RGBA.prototype.operate = function(op, right){ + right = right.first; + + switch (op) { + case 'is a': + if ('string' == right.nodeName && 'color' == right.string) { + return nodes.yes; + } + break; + case '+': + switch (right.nodeName) { + case 'unit': + var n = right.val; + switch (right.type) { + case '%': return adjust(this, new nodes.String('lightness'), right); + case 'deg': return this.hsla.adjustHue(n).rgba; + default: return this.add(n,n,n,0); + } + case 'rgba': + return this.add(right.r, right.g, right.b, right.a); + case 'hsla': + return this.hsla.add(right.h, right.s, right.l); + } + break; + case '-': + switch (right.nodeName) { + case 'unit': + var n = right.val; + switch (right.type) { + case '%': return adjust(this, new nodes.String('lightness'), new nodes.Unit(-n, '%')); + case 'deg': return this.hsla.adjustHue(-n).rgba; + default: return this.sub(n,n,n,0); + } + case 'rgba': + return this.sub(right.r, right.g, right.b, right.a); + case 'hsla': + return this.hsla.sub(right.h, right.s, right.l); + } + break; + case '*': + switch (right.nodeName) { + case 'unit': + return this.multiply(right.val); + } + break; + case '/': + switch (right.nodeName) { + case 'unit': + return this.divide(right.val); + } + break; + } + return Node.prototype.operate.call(this, op, right); +}; + +/** + * Return #nnnnnn, #nnn, or rgba(n,n,n,n) string representation of the color. + * + * @return {String} + * @api public + */ + +RGBA.prototype.toString = function(){ + function pad(n) { + return n < 16 + ? '0' + n.toString(16) + : n.toString(16); + } + + if (1 == this.a) { + var r = pad(this.r) + , g = pad(this.g) + , b = pad(this.b); + + // Compress + if (r[0] == r[1] && g[0] == g[1] && b[0] == b[1]) { + return '#' + r[0] + g[0] + b[0]; + } else { + return '#' + r + g + b; + } + } else { + return 'rgba(' + + this.r + ',' + + this.g + ',' + + this.b + ',' + + this.a.toFixed(2) + ')'; + } +}; + +/** + * Return a `RGBA` from the given `hsla`. + * + * @param {HSLA} hsla + * @return {RGBA} + * @api public + */ + +exports.fromHSLA = function(hsla){ + var h = hsla.h / 360 + , s = hsla.s / 100 + , l = hsla.l / 100 + , a = hsla.a; + + var m2 = l <= .5 ? l * (s + 1) : l + s - l * s + , m1 = l * 2 - m2; + + var r = hue(h + 1/3) * 0xff + , g = hue(h) * 0xff + , b = hue(h - 1/3) * 0xff; + + function hue(h) { + if (h < 0) ++h; + if (h > 1) --h; + if (h * 6 < 1) return m1 + (m2 - m1) * h * 6; + if (h * 2 < 1) return m2; + if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6; + return m1; + } + + return new RGBA(r,g,b,a); +}; + +/** + * Clamp `n` >= 0 and <= 255. + * + * @param {Number} n + * @return {Number} + * @api private + */ + +function clamp(n) { + return Math.max(0, Math.min(n.toFixed(0), 255)); +} + +/** + * Clamp alpha `n` >= 0 and <= 1. + * + * @param {Number} n + * @return {Number} + * @api private + */ + +function clampAlpha(n) { + return Math.max(0, Math.min(n, 1)); +} + + +});// module: nodes/rgba.js + + +require.register("nodes/root.js", function(module, exports, require){ + + +/*! + * Stylus - Root + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Root` node. + * + * @api public + */ + +var Root = module.exports = function Root(){ + this.nodes = []; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Root.prototype.__proto__ = Node.prototype; + +/** + * Push a `node` to this block. + * + * @param {Node} node + * @api public + */ + +Root.prototype.push = function(node){ + this.nodes.push(node); +}; + +/** + * Return "root". + * + * @return {String} + * @api public + */ + +Root.prototype.toString = function(){ + return '[Root]'; +}; + + +});// module: nodes/root.js + + +require.register("nodes/selector.js", function(module, exports, require){ + + +/*! + * Stylus - Selector + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Block = require('./block') + , Node = require('./node'); + +/** + * Initialize a new `Selector` with the given `segs`. + * + * @param {Array} segs + * @api public + */ + +var Selector = module.exports = function Selector(segs){ + Node.call(this); + this.segments = segs; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Selector.prototype.__proto__ = Node.prototype; + +/** + * Return the selector string. + * + * @return {String} + * @api public + */ + +Selector.prototype.toString = function(){ + return this.segments.join(''); +}; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Selector.prototype.clone = function(){ + var clone = new Selector; + clone.lineno = this.lineno; + clone.filename = this.filename; + clone.segments = this.segments.map(function(node){ return node.clone(); }); + return clone; +}; + + +});// module: nodes/selector.js + + +require.register("nodes/string.js", function(module, exports, require){ + + +/*! + * Stylus - String + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , sprintf = require('../functions').s + , utils = require('../utils') + , nodes = require('./index'); + +/** + * Initialize a new `String` with the given `val`. + * + * @param {String} val + * @api public + */ + +var String = module.exports = function String(val){ + Node.call(this); + this.val = val; + this.string = val; +}; + +/** + * Inherit from `Node.prototype`. + */ + +String.prototype.__proto__ = Node.prototype; + +/** + * Return quoted string. + * + * @return {String} + * @api public + */ + +String.prototype.toString = function(){ + return '"' + this.val + '"'; +}; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +String.prototype.clone = function(){ + var clone = new String(this.val); + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +/** + * Return Boolean based on the length of this string. + * + * @return {Boolean} + * @api public + */ + +String.prototype.toBoolean = function(){ + return nodes.Boolean(this.val.length); +}; + +/** + * Coerce `other` to a string. + * + * @param {Node} other + * @return {String} + * @api public + */ + +String.prototype.coerce = function(other){ + switch (other.nodeName) { + case 'string': + return other; + case 'expression': + return new String(other.nodes.map(function(node){ + return this.coerce(node).val; + }, this).join(' ')); + default: + return new String(other.toString()); + } +}; + +/** + * Operate on `right` with the given `op`. + * + * @param {String} op + * @param {Node} right + * @return {Node} + * @api public + */ + +String.prototype.operate = function(op, right){ + switch (op) { + case '%': + var expr = new nodes.Expression; + expr.push(this); + + // constructargs + var args = 'expression' == right.nodeName + ? utils.unwrap(right).nodes + : [right]; + + // apply + return sprintf.apply(null, [expr].concat(args)); + case '+': + return new String(this.val + this.coerce(right).val); + default: + return Node.prototype.operate.call(this, op, right); + } +}; + + +});// module: nodes/string.js + + +require.register("nodes/ternary.js", function(module, exports, require){ + + +/*! + * Stylus - Ternary + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `Ternary` with `cond`, `trueExpr` and `falseExpr`. + * + * @param {Expression} cond + * @param {Expression} trueExpr + * @param {Expression} falseExpr + * @api public + */ + +var Ternary = module.exports = function Ternary(cond, trueExpr, falseExpr){ + Node.call(this); + this.cond = cond; + this.trueExpr = trueExpr; + this.falseExpr = falseExpr; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Ternary.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Ternary.prototype.clone = function(){ + var clone = new Ternary( + this.cond.clone() + , this.trueExpr.clone() + , this.falseExpr.clone()); + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +});// module: nodes/ternary.js + + +require.register("nodes/unaryop.js", function(module, exports, require){ + + +/*! + * Stylus - UnaryOp + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node'); + +/** + * Initialize a new `UnaryOp` with `op`, and `expr`. + * + * @param {String} op + * @param {Node} expr + * @api public + */ + +var UnaryOp = module.exports = function UnaryOp(op, expr){ + Node.call(this); + this.op = op; + this.expr = expr; +}; + +/** + * Inherit from `Node.prototype`. + */ + +UnaryOp.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +UnaryOp.prototype.clone = function(){ + var clone = new UnaryOp(this.op, this.expr.clone()); + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +});// module: nodes/unaryop.js + + +require.register("nodes/unit.js", function(module, exports, require){ + + +/*! + * Stylus - Unit + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./index'); + +/** + * Initialize a new `Unit` with the given `val` and unit `type` + * such as "px", "pt", "in", etc. + * + * @param {String} val + * @param {String} type + * @api public + */ + +var Unit = module.exports = function Unit(val, type){ + Node.call(this); + this.val = val; + this.type = type; +}; + +/** + * Inherit from `Node.prototype`. + */ + +Unit.prototype.__proto__ = Node.prototype; + +/** + * Return Boolean based on the unit value. + * + * @return {Boolean} + * @api public + */ + +Unit.prototype.toBoolean = function(){ + return nodes.Boolean(this.type + ? true + : this.val); +}; + +/** + * Return unit string. + * + * @return {String} + * @api public + */ + +Unit.prototype.toString = function(){ + var n = this.val; + if ('px' == this.type) n = n.toFixed(0); + return n + (this.type || ''); +}; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Unit.prototype.clone = function(){ + var clone = new Unit(this.val, this.type); + clone.lineno = this.lineno; + clone.filename = this.filename; + return clone; +}; + +/** + * Operate on `right` with the given `op`. + * + * @param {String} op + * @param {Node} right + * @return {Node} + * @api public + */ + +Unit.prototype.operate = function(op, right){ + var type = this.type || right.type; + + // swap color + if ('rgba' == right.nodeName || 'hsla' == right.nodeName) { + return right.operate(op, this); + } + + // operate + if (this.shouldCoerce(op)) { + // percentages + if (('-' == op || '+' == op) && '%' == right.type) { + right.val = this.val * (right.val / 100); + } else { + right = this.coerce(right.first); + } + + switch (op) { + case '-': + return new Unit(this.val - right.val, type); + case '+': + return new Unit(this.val + right.val, type); + case '/': + return new Unit(this.val / right.val, type); + case '*': + return new Unit(this.val * right.val, type); + case '%': + return new Unit(this.val % right.val, type); + case '**': + return new Unit(Math.pow(this.val, right.val), type); + case '..': + case '...': + var start = this.val + , end = right.val + , expr = new nodes.Expression + , inclusive = '..' == op; + do { + expr.push(new nodes.Unit(start)); + } while (inclusive ? ++start <= end : ++start < end); + return expr; + } + } + + return Node.prototype.operate.call(this, op, right); +}; + +/** + * Coerce `other` unit to the same type as `this` unit. + * + * Supports: + * + * mm -> cm | in + * cm -> mm | in + * in -> mm | cm + * + * ms -> s + * s -> ms + * + * Hz -> kHz + * kHz -> Hz + * + * @param {Unit} other + * @return {Unit} + * @api public + */ + +Unit.prototype.coerce = function(other){ + if ('unit' == other.nodeName) { + var a = this + , b = other; + switch (a.type) { + case 'mm': + switch (b.type) { + case 'cm': + return new nodes.Unit(b.val * 2.54, 'mm'); + case 'in': + return new nodes.Unit(b.val * 25.4, 'mm'); + } + case 'cm': + switch (b.type) { + case 'mm': + return new nodes.Unit(b.val / 10, 'cm'); + case 'in': + return new nodes.Unit(b.val * 2.54, 'cm'); + } + case 'in': + switch (b.type) { + case 'mm': + return new nodes.Unit(b.val / 25.4, 'in'); + case 'cm': + return new nodes.Unit(b.val / 2.54, 'in'); + } + case 'ms': + switch (b.type) { + case 's': + return new nodes.Unit(b.val * 1000, 'ms'); + } + case 's': + switch (b.type) { + case 'ms': + return new nodes.Unit(b.val / 1000, 's'); + } + case 'Hz': + switch (b.type) { + case 'kHz': + return new nodes.Unit(b.val * 1000, 'Hz'); + } + case 'kHz': + switch (b.type) { + case 'Hz': + return new nodes.Unit(b.val / 1000, 'kHz'); + } + default: + return new nodes.Unit(b.val, a.type); + } + } else if ('string' == other.nodeName) { + var val = parseInt(other.val, 10); + if (isNaN(val)) Node.prototype.coerce.call(this, other); + return new nodes.Unit(val); + } else { + return Node.prototype.coerce.call(this, other); + } +}; + + +});// module: nodes/unit.js + + +require.register("parser.js", function(module, exports, require){ + + +/*! + * Stylus - Parser + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Lexer = require('./lexer') + , nodes = require('./nodes') + , Token = require('./token') + , errors = require('./errors'); + +/** + * Selector composite tokens. + */ + +var selectorTokens = [ + 'ident' + , 'string' + , 'selector' + , 'function' + , 'comment' + , 'boolean' + , 'space' + , 'color' + , 'unit' + , 'for' + , '[' + , ']' + , '(' + , ')' + , '+' + , '-' + , '*' + , '*=' + , '<' + , '>' + , '=' + , ':' + , '&' + , '~' + , '{' + , '}' +]; + +/** + * CSS3 pseudo-selectors. + */ + +var pseudoSelectors = [ + 'root' + , 'nth-child' + , 'nth-last-child' + , 'nth-of-type' + , 'nth-last-of-type' + , 'first-child' + , 'last-child' + , 'first-of-type' + , 'last-of-type' + , 'only-child' + , 'only-of-type' + , 'empty' + , 'link' + , 'visited' + , 'active' + , 'hover' + , 'focus' + , 'target' + , 'lang' + , 'enabled' + , 'disabled' + , 'checked' + , 'not' +]; + +/** + * Initialize a new `Parser` with the given `str` and `options`. + * + * @param {String} str + * @param {Object} options + * @api private + */ + +var Parser = module.exports = function Parser(str, options) { + var self = this; + options = options || {}; + this.lexer = new Lexer(str, options); + this.root = options.root || new nodes.Root; + this.state = ['root']; + this.stash = []; + this.parens = 0; + this.state.pop = function(){ + self.prevState = [].pop.call(this); + }; +}; + +/** + * Parser prototype. + */ + +Parser.prototype = { + + /** + * Constructor. + */ + + constructor: Parser, + + /** + * Return current state. + * + * @return {String} + * @api private + */ + + currentState: function() { + return this.state[this.state.length - 1]; + }, + + /** + * Parse the input, then return the root node. + * + * @return {Node} + * @api private + */ + + parse: function(){ + var block = this.parent = this.root; + while ('eos' != this.peek().type) { + if (this.accept('newline')) continue; + var stmt = this.statement(); + this.accept(';'); + if (!stmt) this.error('unexpected token {peek}, not allowed at the root level'); + block.push(stmt); + } + return block; + }, + + /** + * Throw an `Error` with the given `msg`. + * + * @param {String} msg + * @api private + */ + + error: function(msg){ + var type = this.peek().type + , val = undefined == this.peek().val + ? '' + : ' ' + this.peek().toString(); + if (val.trim() == type.trim()) val = ''; + throw new errors.ParseError(msg.replace('{peek}', '"' + type + val + '"')); + }, + + /** + * Accept the given token `type`, and return it, + * otherwise return `undefined`. + * + * @param {String} type + * @return {Token} + * @api private + */ + + accept: function(type){ + if (type == this.peek().type) { + return this.next(); + } + }, + + /** + * Expect token `type` and return it, throw otherwise. + * + * @param {String} type + * @return {Token} + * @api private + */ + + expect: function(type){ + if (type != this.peek().type) { + this.error('expected "' + type + '", got {peek}'); + } + return this.next(); + }, + + /** + * Get the next token. + * + * @return {Token} + * @api private + */ + + next: function() { + var tok = this.stash.length + ? this.stash.pop() + : this.lexer.next(); + nodes.lineno = tok.lineno; + return tok; + }, + + /** + * Peek with lookahead(1). + * + * @return {Token} + * @api private + */ + + peek: function() { + return this.lexer.peek(); + }, + + /** + * Lookahead `n` tokens. + * + * @param {Number} n + * @return {Token} + * @api private + */ + + lookahead: function(n){ + return this.lexer.lookahead(n); + }, + + /** + * Check if the token at `n` is a valid selector token. + * + * @param {Number} n + * @return {Boolean} + * @api private + */ + + isSelectorToken: function(n) { + var la = this.lookahead(n).type; + switch (la) { + case 'for': + return this.bracketed; + case '[': + this.bracketed = true; + return true; + case ']': + this.bracketed = false; + return true; + default: + return ~selectorTokens.indexOf(la); + } + }, + + /** + * Check if the token at `n` is a pseudo selector. + * + * @param {Number} n + * @return {Boolean} + * @api private + */ + + isPseudoSelector: function(n){ + return ~pseudoSelectors.indexOf(this.lookahead(n).val.name); + }, + + /** + * Check if the current line contains `type`. + * + * @param {String} type + * @return {Boolean} + * @api private + */ + + lineContains: function(type){ + var i = 1 + , la; + + while (la = this.lookahead(i++)) { + if (~['indent', 'outdent', 'newline'].indexOf(la.type)) return; + if (type == la.type) return true; + } + }, + + /** + * Valid selector tokens. + */ + + selectorToken: function() { + if (this.isSelectorToken(1)) { + if ('{' == this.peek().type) { + // unclosed, must be a block + if (!this.lineContains('}')) return; + // check if ':' is within the braces. + // though not required by stylus, chances + // are if someone is using {} they will + // use css-style props, helping us with + // the ambiguity in this case + var i = 0 + , la; + while (la = this.lookahead(++i)) { + if ('}' == la.type) break; + if (':' == la.type) return; + } + } + return this.next(); + } + }, + + /** + * Consume whitespace. + */ + + skipWhitespace: function() { + while (~['space', 'indent', 'outdent', 'newline'].indexOf(this.peek().type)) + this.next(); + }, + + /** + * Consume spaces. + */ + + skipSpaces: function() { + while ('space' == this.peek().type) + this.next(); + }, + + /** + * Check if the following sequence of tokens + * forms a function definition, ie trailing + * `{` or indentation. + */ + + looksLikeFunctionDefinition: function(i) { + return 'indent' == this.lookahead(i).type + || '{' == this.lookahead(i).type; + }, + + /** + * Check if the following sequence of tokens + * forms a selector. + */ + + looksLikeSelector: function() { + var i = 1 + , brace; + + // Assume selector when an ident is + // followed by a selector + while ('ident' == this.lookahead(i).type + && 'newline' == this.lookahead(i + 1).type) i += 2; + + while (this.isSelectorToken(i) + || ',' == this.lookahead(i).type) { + + if ('selector' == this.lookahead(i).type) + return true; + + // the ':' token within braces signifies + // a selector. ex: "foo{bar:'baz'}" + if ('{' == this.lookahead(i).type) brace = true; + else if ('}' == this.lookahead(i).type) brace = false; + if (brace && ':' == this.lookahead(i).type) return true; + + // '}' preceded by a space is considered a selector. + // for example "foo{bar}{baz}" may be a property, + // however "foo{bar} {baz}" is a selector + if ('space' == this.lookahead(i).type + && '{' == this.lookahead(i + 1).type) + return true; + + // Assume pseudo selectors are NOT properties + // as 'td:th-child(1)' may look like a property + // and function call to the parser otherwise + if (':' == this.lookahead(i++).type + && this.isPseudoSelector(i)) + return true; + + if (',' == this.lookahead(i).type + && 'newline' == this.lookahead(i + 1).type) + return true; + } + + // Trailing comma + if (',' == this.lookahead(i).type + && 'newline' == this.lookahead(i + 1).type) + return true; + + // Trailing brace + if ('{' == this.lookahead(i).type + && 'newline' == this.lookahead(i + 1).type) + return true; + + // css-style mode, false on ; } + if (this.css) { + if (';' == this.lookahead(i) || + '}' == this.lookahead(i)) + return false; + } + + // Trailing separators + while (!~[ + 'indent' + , 'outdent' + , 'newline' + , 'for' + , 'if' + , ';' + , '}'].indexOf(this.lookahead(i).type)) + ++i; + + if ('indent' == this.lookahead(i).type) + return true; + }, + + /** + * Check if the current state supports selectors. + */ + + stateAllowsSelector: function() { + switch (this.currentState()) { + case 'root': + case 'selector': + case 'conditional': + case 'keyframe': + case 'function': + case 'font-face': + case 'media': + case 'for': + return true; + } + }, + + /** + * statement + * | statement 'if' expression + * | statement 'unless' expression + */ + + statement: function() { + var stmt = this.stmt() + , state = this.prevState + , block + , op; + + // special-case statements since it + // is not an expression. We could + // implement postfix conditionals at + // the expression level, however they + // would then fail to enclose properties + if (this.allowPostfix) { + delete this.allowPostfix; + state = 'expression'; + } + + switch (state) { + case 'assignment': + case 'expression': + case 'function arguments': + while (op = + this.accept('if') + || this.accept('unless') + || this.accept('for')) { + switch (op.type) { + case 'if': + case 'unless': + stmt = new nodes.If(this.expression(), stmt); + stmt.postfix = true; + stmt.negate = 'unless' == op.type; + this.accept(';'); + break; + case 'for': + var key + , val = this.id().name; + if (this.accept(',')) key = this.id().name; + this.expect('in'); + var each = new nodes.Each(val, key, this.expression()); + block = new nodes.Block; + block.push(stmt); + each.block = block; + stmt = each; + } + } + } + + return stmt; + }, + + /** + * ident + * | selector + * | literal + * | charset + * | import + * | media + * | scope + * | keyframes + * | page + * | for + * | if + * | unless + * | comment + * | expression + * | 'return' expression + */ + + stmt: function() { + var type = this.peek().type; + switch (type) { + case '-webkit-keyframes': + case 'keyframes': + return this.keyframes(); + case 'font-face': + return this.fontface(); + case 'comment': + case 'selector': + case 'literal': + case 'charset': + case 'media': + case 'page': + case 'ident': + case 'scope': + case 'unless': + return this[type](); + case 'function': + return this.fun(); + case 'import': + return this.atimport(); + case 'if': + return this.ifstmt(); + case 'for': + return this.forin(); + case 'return': + return this.ret(); + case '{': + return this.property(); + default: + // Contextual selectors + if (this.stateAllowsSelector()) { + switch (type) { + case 'color': + case '~': + case '+': + case '>': + case '<': + case ':': + case '&': + case '[': + return this.selector(); + case '*': + return this.property(); + case '-': + if ('{' == this.lookahead(2).type) + return this.property(); + } + } + + // Expression fallback + var expr = this.expression(); + if (expr.isEmpty) this.error('unexpected {peek}'); + return expr; + } + }, + + /** + * indent (!outdent)+ outdent + */ + + block: function(node, scope) { + var delim + , stmt + , _ = this.css + , block = this.parent = new nodes.Block(this.parent, node); + + if (false === scope) block.scope = false; + + // css-style + if (this.css = this.accept('{')) { + delim = '}'; + this.skipWhitespace(); + } else { + delim = 'outdent'; + this.expect('indent'); + } + + while (delim != this.peek().type) { + // css-style + if (this.css) { + if (this.accept('newline')) continue; + stmt = this.statement(); + this.accept(';'); + this.skipWhitespace(); + } else { + if (this.accept('newline')) continue; + stmt = this.statement(); + this.accept(';'); + } + if (!stmt) this.error('unexpected token {peek} in block'); + block.push(stmt); + } + + // css-style + if (this.css) { + this.skipWhitespace(); + this.expect('}'); + this.skipSpaces(); + this.css = _; + } else { + this.expect('outdent'); + } + + this.parent = block.parent; + return block; + }, + + /** + * comment space* + */ + + comment: function(){ + var node = this.next().val; + this.skipSpaces(); + return node; + }, + + /** + * for val (',' key) in expr + */ + + forin: function() { + this.expect('for'); + var key + , val = this.id().name; + if (this.accept(',')) key = this.id().name; + this.expect('in'); + var each = new nodes.Each(val, key, this.expression()); + this.state.push('for'); + each.block = this.block(each, false); + this.state.pop(); + return each; + }, + + /** + * return expression + */ + + ret: function() { + this.expect('return'); + var expr = this.expression(); + return expr.isEmpty + ? new nodes.Return + : new nodes.Return(expr); + }, + + /** + * unless expression block + */ + + unless: function() { + this.expect('unless'); + var node = new nodes.If(this.expression(), true); + this.state.push('conditional'); + node.block = this.block(node, false); + this.state.pop(); + return node; + }, + + /** + * if expression block (else block)? + */ + + ifstmt: function() { + this.expect('if'); + var node = new nodes.If(this.expression()); + this.state.push('conditional'); + node.block = this.block(node, false); + while (this.accept('else')) { + if (this.accept('if')) { + var cond = this.expression() + , block = this.block(node, false); + node.elses.push(new nodes.If(cond, block)); + } else { + node.elses.push(this.block(node, false)); + break; + } + } + this.state.pop(); + return node; + }, + + /** + * scope + */ + + scope: function(){ + var val = this.expect('scope').val; + this.selectorScope = val; + return nodes.nil; + }, + + /** + * media + */ + + media: function() { + var val = this.expect('media').val + , media = new nodes.Media(val); + this.state.push('media'); + media.block = this.block(media); + this.state.pop(); + return media; + }, + + /** + * fontface + */ + + fontface: function() { + this.expect('font-face'); + var node = new nodes.FontFace; + this.state.push('font-face'); + node.block = this.block(node); + this.state.pop(); + return node; + }, + + /** + * import expression + */ + + atimport: function() { + this.expect('import'); + this.allowPostfix = true; + return new nodes.Import(this.expression()); + }, + + /** + * charset string + */ + + charset: function() { + this.expect('charset'); + var str = this.expect('string').val; + this.allowPostfix = true; + return new nodes.Charset(str); + }, + + /** + * page selector? block + */ + + page: function() { + var selector; + this.expect('page'); + if (this.accept(':')) { + var str = this.expect('ident').val.name; + selector = new nodes.Literal(':' + str); + } + var page = new nodes.Page(selector); + this.state.push('page'); + page.block = this.block(page); + this.state.pop(); + return page; + }, + + /** + * keyframes name ((unit | from | to) block)+ + */ + + keyframes: function() { + var pos + , _ = this.css + , tok = this.expect('keyframes') + , keyframes = new nodes.Keyframes(this.id(), tok.val); + + // css-style + if (this.css = this.accept('{')) { + this.skipWhitespace(); + } else { + this.expect('indent'); + } + + while (pos = this.accept('unit') || this.accept('ident')) { + // from | to + if ('ident' == pos.type) { + this.accept('space'); + switch (pos.val.name) { + case 'from': + pos = new nodes.Unit(0, '%'); + break; + case 'to': + pos = new nodes.Unit(100, '%'); + break; + default: + this.error('"' + pos.val.name + '" is invalid, use "from" or "to"'); + } + } else { + pos = pos.val; + } + + // block + this.state.push('keyframe'); + var block = this.block(keyframes); + keyframes.push(pos, block); + this.state.pop(); + if (this.css) this.skipWhitespace(); + } + + // css-style + if (this.css) { + this.skipWhitespace(); + this.expect('}'); + this.css = _; + } else { + this.expect('outdent'); + } + + return keyframes; + }, + + /** + * literal + */ + + literal: function() { + return this.expect('literal').val; + }, + + /** + * ident space? + */ + + id: function() { + var tok = this.expect('ident'); + this.accept('space'); + return tok.val; + }, + + /** + * ident + * | assignment + * | property + * | selector + */ + + ident: function() { + var i = 2 + , la = this.lookahead(i).type; + + while ('space' == la) la = this.lookahead(++i).type; + + switch (la) { + // Assignment + case '=': + case '?=': + case '-=': + case '+=': + case '*=': + case '/=': + case '%=': + return this.assignment(); + // Assignment []= + case '[': + if (this._ident == this.peek()) return this.id(); + while (']' != this.lookahead(i++).type + && 'selector' != this.lookahead(i).type) ; + if ('=' == this.lookahead(i).type) { + this._ident = this.peek(); + return this.expression(); + } else if (this.looksLikeSelector() && this.stateAllowsSelector()) { + return this.selector(); + } + // Operation + case '-': + case '+': + case '/': + case '*': + case '%': + case '**': + case 'and': + case 'or': + case '&&': + case '||': + case '>': + case '<': + case '>=': + case '<=': + case '!=': + case '==': + case '?': + case 'in': + case 'is a': + case 'is defined': + // Prevent cyclic .ident, return literal + if (this._ident == this.peek()) { + return this.id(); + } else { + this._ident = this.peek(); + switch (this.currentState()) { + // unary op or selector in property / for + case 'for': + case 'selector': + return this.property(); + // Part of a selector + case 'root': + case 'media': + case 'font-face': + return this.selector(); + // Do not disrupt the ident when an operand + default: + return this.operand + ? this.id() + : this.expression(); + } + } + // Selector or property + default: + switch (this.currentState()) { + case 'root': + return this.selector(); + case 'for': + case 'page': + case 'media': + case 'font-face': + case 'selector': + case 'function': + case 'keyframe': + case 'conditional': + return this.property(); + default: + return this.id(); + } + } + }, + + /** + * '*'? (ident | '{' expression '}')+ + */ + + interpolate: function() { + var node + , segs = [] + , star; + + star = this.accept('*'); + if (star) segs.push(new nodes.Literal('*')); + + while (true) { + if (this.accept('{')) { + this.state.push('interpolation'); + segs.push(this.expression()); + this.expect('}'); + this.state.pop(); + } else if (node = this.accept('-')){ + segs.push(new nodes.Literal('-')); + } else if (node = this.accept('ident')){ + segs.push(node.val); + } else { + break; + } + } + if (!segs.length) this.expect('ident'); + return segs; + }, + + /** + * property ':'? expression + * | ident + */ + + property: function() { + if (this.looksLikeSelector()) return this.selector(); + + // property + var ident = this.interpolate() + , ret = prop = new nodes.Property(ident); + + // optional ':' + this.accept('space'); + if (this.accept(':')) this.accept('space'); + + this.state.push('property'); + this.inProperty = true; + prop.expr = this.list(); + if (prop.expr.isEmpty) ret = ident[0]; + this.inProperty = false; + this.allowPostfix = true; + this.state.pop(); + + // optional ';' + this.accept(';'); + + return ret; + }, + + /** + * selector ',' selector + * | selector newline selector + * | selector block + */ + + selector: function() { + var tok + , arr + , group = new nodes.Group + , scope = this.selectorScope + , isRoot = 'root' == this.currentState(); + + do { + arr = []; + + // Clobber newline after , + this.accept('newline'); + + // Selector candidates, + // stitched together to + // form a selector. + while (tok = this.selectorToken()) { + // Selector component + switch (tok.type) { + case '{': + this.skipSpaces(); + var expr = this.expression(); + this.skipSpaces(); + this.expect('}'); + arr.push(expr); + break; + case 'comment': + arr.push(new nodes.Literal(tok.val.str)); + break; + case 'color': + arr.push(new nodes.Literal(tok.val.raw)); + break; + case 'space': + arr.push(new nodes.Literal(' ')); + break; + case 'function': + arr.push(new nodes.Literal(tok.val.name + '(')); + break; + case 'ident': + arr.push(new nodes.Literal(tok.val.name)); + break; + default: + arr.push(new nodes.Literal(tok.val)); + if (tok.space) arr.push(new nodes.Literal(' ')); + } + } + + // Push the selector + if (isRoot && scope) arr.unshift(new nodes.Literal(scope + ' ')); + group.push(new nodes.Selector(arr)); + } while (this.accept(',') || this.accept('newline')); + + this.lexer.allowComments = false; + this.state.push('selector'); + group.block = this.block(group); + this.state.pop(); + + + return group; + }, + + /** + * ident ('=' | '?=') expression + */ + + assignment: function() { + var op + , node + , name = this.id().name; + + if (op = + this.accept('=') + || this.accept('?=') + || this.accept('+=') + || this.accept('-=') + || this.accept('*=') + || this.accept('/=') + || this.accept('%=')) { + this.state.push('assignment'); + var expr = this.list(); + if (expr.isEmpty) this.error('invalid right-hand side operand in assignment, got {peek}') + node = new nodes.Ident(name, expr); + this.state.pop(); + + switch (op.type) { + case '?=': + var defined = new nodes.BinOp('is defined', node) + , lookup = new nodes.Ident(name); + node = new nodes.Ternary(defined, lookup, node); + break; + case '+=': + case '-=': + case '*=': + case '/=': + case '%=': + node.val = new nodes.BinOp(op.type[0], new nodes.Ident(name), expr); + break; + } + } + + return node; + }, + + /** + * definition + * | call + */ + + fun: function() { + var parens = 1 + , i = 2 + , tok; + + // Lookahead and determine if we are dealing + // with a function call or definition. Here + // we pair parens to prevent false negatives + out: + while (tok = this.lookahead(i++)) { + switch (tok.type) { + case 'function': + case '(': + ++parens; + break; + case ')': + if (!--parens) break out; + break; + case 'eos': + this.error('failed to find closing paren ")"'); + } + } + + // Definition or call + switch (this.currentState()) { + case 'expression': + return this.functionCall(); + default: + return this.looksLikeFunctionDefinition(i) + ? this.functionDefinition() + : this.expression(); + } + }, + + /** + * url '(' (expression | urlchars)+ ')' + */ + + url: function() { + this.expect('function'); + this.state.push('function arguments'); + var args = this.args(); + this.expect(')'); + this.state.pop(); + return new nodes.Call('url', args); + }, + + /** + * ident '(' expression ')' + */ + + functionCall: function() { + if ('url' == this.peek().val.name) return this.url(); + var name = this.expect('function').val.name; + this.state.push('function arguments'); + var args = this.args(); + this.expect(')'); + this.state.pop(); + return new nodes.Call(name, args); + }, + + /** + * ident '(' params ')' block + */ + + functionDefinition: function() { + var name = this.expect('function').val.name; + + // params + this.state.push('function params'); + this.skipWhitespace(); + var params = this.params(); + this.skipWhitespace(); + this.expect(')'); + this.state.pop(); + + // Body + this.state.push('function'); + var fn = new nodes.Function(name, params); + fn.block = this.block(fn); + this.state.pop(); + return new nodes.Ident(name, fn); + }, + + /** + * ident + * | ident '...' + * | ident '=' expression + * | ident ',' ident + */ + + params: function() { + var tok + , node + , params = new nodes.Params; + while (tok = this.accept('ident')) { + this.accept('space'); + params.push(node = tok.val); + if (this.accept('...')) { + node.rest = true; + } else if (this.accept('=')) { + node.val = this.expression(); + } + this.skipWhitespace(); + this.accept(','); + this.skipWhitespace(); + } + return params; + }, + + /** + * (ident ':')? expression (',' (ident ':')? expression)* + */ + + args: function() { + var args = new nodes.Arguments + , keyword; + + do { + // keyword + if ('ident' == this.peek().type && ':' == this.lookahead(2).type) { + keyword = this.next().val.string; + this.expect(':'); + args.map[keyword] = this.expression(); + // arg + } else { + args.push(this.expression()); + } + } while (this.accept(',')); + + return args; + }, + + /** + * expression (',' expression)* + */ + + list: function() { + var node = this.expression(); + while (this.accept(',')) { + if (node.isList) { + list.push(this.expression()); + } else { + var list = new nodes.Expression(true); + list.push(node); + list.push(this.expression()); + node = list; + } + } + return node; + }, + + /** + * negation+ + */ + + expression: function() { + var node + , expr = new nodes.Expression; + this.state.push('expression'); + while (node = this.negation()) { + if (!node) this.error('unexpected token {peek} in expression'); + expr.push(node); + } + this.state.pop(); + return expr; + }, + + /** + * 'not' ternary + * | ternary + */ + + negation: function() { + if (this.accept('not')) { + return new nodes.UnaryOp('!', this.negation()); + } + return this.ternary(); + }, + + /** + * logical ('?' expression ':' expression)? + */ + + ternary: function() { + var node = this.logical(); + if (this.accept('?')) { + var trueExpr = this.expression(); + this.expect(':'); + var falseExpr = this.expression(); + node = new nodes.Ternary(node, trueExpr, falseExpr); + } + return node; + }, + + /** + * typecheck (('&&' | '||') typecheck)* + */ + + logical: function() { + var op + , node = this.typecheck(); + while (op = this.accept('&&') || this.accept('||')) { + node = new nodes.BinOp(op.type, node, this.typecheck()); + } + return node; + }, + + /** + * equality ('is a' equality)* + */ + + typecheck: function() { + var op + , node = this.equality(); + while (op = this.accept('is a')) { + this.operand = true; + if (!node) this.error('illegal unary "' + op + '", missing left-hand operand'); + node = new nodes.BinOp(op.type, node, this.equality()); + this.operand = false; + } + return node; + }, + + /** + * in (('==' | '!=') in)* + */ + + equality: function() { + var op + , node = this.inop(); + while (op = this.accept('==') || this.accept('!=')) { + this.operand = true; + if (!node) this.error('illegal unary "' + op + '", missing left-hand operand'); + node = new nodes.BinOp(op.type, node, this.inop()); + this.operand = false; + } + return node; + }, + + /** + * relational ('in' relational)* + */ + + inop: function() { + var node = this.relational(); + while (this.accept('in')) { + this.operand = true; + if (!node) this.error('illegal unary "in", missing left-hand operand'); + node = new nodes.BinOp('in', node, this.relational()); + this.operand = false; + } + return node; + }, + + /** + * range (('>=' | '<=' | '>' | '<') range)* + */ + + relational: function() { + var op + , node = this.range(); + while (op = + this.accept('>=') + || this.accept('<=') + || this.accept('<') + || this.accept('>') + ) { + this.operand = true; + if (!node) this.error('illegal unary "' + op + '", missing left-hand operand'); + node = new nodes.BinOp(op.type, node, this.range()); + this.operand = false; + } + return node; + }, + + /** + * additive (('..' | '...') additive)* + */ + + range: function() { + var op + , node = this.additive(); + if (op = this.accept('...') || this.accept('..')) { + this.operand = true; + if (!node) this.error('illegal unary "' + op + '", missing left-hand operand'); + node = new nodes.BinOp(op.val, node, this.additive()); + this.operand = false; + } + return node; + }, + + /** + * multiplicative (('+' | '-') multiplicative)* + */ + + additive: function() { + var op + , node = this.multiplicative(); + while (op = this.accept('+') || this.accept('-')) { + this.operand = true; + node = new nodes.BinOp(op.type, node, this.multiplicative()); + this.operand = false; + } + return node; + }, + + /** + * defined (('**' | '*' | '/' | '%') defined)* + */ + + multiplicative: function() { + var op + , node = this.defined(); + while (op = + this.accept('**') + || this.accept('*') + || this.accept('/') + || this.accept('%')) { + this.operand = true; + if ('/' == op && this.inProperty && !this.parens) { + this.stash.push(new Token('literal', new nodes.Literal('/'))); + this.operand = false; + return node; + } else { + if (!node) this.error('illegal unary "' + op + '", missing left-hand operand'); + node = new nodes.BinOp(op.type, node, this.defined()); + this.operand = false; + } + } + return node; + }, + + /** + * unary 'is defined' + * | unary + */ + + defined: function() { + var node = this.unary(); + if (this.accept('is defined')) { + if (!node) this.error('illegal unary "is defined", missing left-hand operand'); + node = new nodes.BinOp('is defined', node); + } + return node; + }, + + /** + * ('!' | '~' | '+' | '-') unary + * | subscript + */ + + unary: function() { + var op + , node; + if (op = + this.accept('!') + || this.accept('~') + || this.accept('+') + || this.accept('-')) { + this.operand = true; + node = new nodes.UnaryOp(op.type, this.unary()); + this.operand = false; + return node; + } + return this.subscript(); + }, + + /** + * primary ('[' expression ']' '='?)+ + * | primary + */ + + subscript: function() { + var node = this.primary(); + while (this.accept('[')) { + node = new nodes.BinOp('[]', node, this.expression()); + this.expect(']'); + // TODO: TernaryOp :) + if (this.accept('=')) { + node.op += '='; + node.val = this.expression(); + } + } + return node; + }, + + /** + * unit + * | null + * | color + * | string + * | ident + * | boolean + * | literal + * | '(' expression ')' + */ + + primary: function() { + var op + , node; + + // Parenthesis + if (this.accept('(')) { + ++this.parens; + var expr = this.expression(); + this.expect(')'); + --this.parens; + return expr; + } + + // Primitive + switch (this.peek().type) { + case 'null': + case 'unit': + case 'color': + case 'string': + case 'literal': + case 'boolean': + return this.next().val; + case 'ident': + return this.ident(); + case 'function': + return this.functionCall(); + } + } +}; + + +});// module: parser.js + + +require.register("renderer.js", function(module, exports, require){ + + +/*! + * Stylus - Renderer + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Parser = require('./parser') + , Compiler = require('./visitor/compiler') + , Evaluator = require('./visitor/evaluator') + , utils = require('./utils') + , nodes = require('./nodes') + , path = require('./path') + , join = path.join; + +/** + * Initialize a new `Renderer` with the given `str` and `options`. + * + * @param {String} str + * @param {Object} options + * @api public + */ + +var Renderer = module.exports = function Renderer(str, options) { + options = options || {}; + options.globals = {}; + options.functions = {}; + options.imports = []; + // options.imports = [join(__dirname, 'functions')]; + options.paths = options.paths || []; + options.filename = options.filename || 'stylus'; + this.options = options; + this.str = str; +}; + +/** + * Parse and evaluate AST, then callback `fn(err, css, js)`. + * + * @param {Function} fn + * @api public + */ + +Renderer.prototype.render = function(fn){ + var parser = this.parser = new Parser(this.str, this.options); + try { + nodes.filename = this.options.filename; + var ast = parser.parse(); + this.evaluator = new Evaluator(ast, this.options); + ast = this.evaluator.evaluate(); + var compiler = new Compiler(ast, this.options) + , css = compiler.compile() + , js = compiler.js; + fn(null, css, js); + } catch (err) { + // var options = {}; + // options.input = err.input || this.str; + // options.filename = err.filename || this.options.filename; + // options.lineno = err.lineno || parser.lexer.lineno; + // fn(utils.formatException(err, options)); + fn(err); + } +}; + +/** + * Set option `key` to `val`. + * + * @param {String} key + * @param {Mixed} val + * @return {Renderer} for chaining + * @api public + */ + +Renderer.prototype.set = function(key, val){ + this.options[key] = val; + return this; +}; + +/** + * Get option `key`. + * + * @param {String} key + * @return {Mixed} val + * @api public + */ + +Renderer.prototype.get = function(key){ + return this.options[key]; +}; + +/** + * Include the given `path` to the lookup paths array. + * + * @param {String} path + * @return {Renderer} for chaining + * @api public + */ + +Renderer.prototype.include = function(path){ + this.options.paths.push(path); + return this; +}; + +/** + * Use the given `fn`. + * + * This allows for plugins to alter the renderer in + * any way they wish, exposing paths etc. + * + * @param {Function} + * @return {Renderer} for chaining + * @api public + */ + +Renderer.prototype.use = function(fn){ + fn.call(this, this); + return this; +}; + +/** + * Define function or global var with the given `name`. Optionally + * the function may accept full expressions, by setting `raw` + * to `true`. + * + * @param {String} name + * @param {Function|Node} fn + * @return {Renderer} for chaining + * @api public + */ + +Renderer.prototype.define = function(name, fn, raw){ + if (fn.nodeName) { + this.options.globals[name] = fn; + return this; + } + + // function + this.options.functions[name] = fn; + if (undefined != raw) fn.raw = raw; + return this; +}; + +// /** +// * Import the given `file`. +// * +// * @param {String} file +// * @return {Renderer} for chaining +// * @api public +// */ +// +// Renderer.prototype.import = function(file){ +// this.options.imports.push(file); +// return this; +// }; + + + + +});// module: renderer.js + + +require.register("stack/index.js", function(module, exports, require){ + + +/*! + * Stylus - Stack + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Frame = require('./frame'); + +/** + * Initialize a new `Stack`. + * + * @api private + */ + +var Stack = module.exports = function Stack() { + Array.apply(this, arguments); +}; + +/** + * Inherit from `Array.prototype`. + */ + +Stack.prototype.__proto__ = Array.prototype; + +/** + * Push the given `frame`. + * + * @param {Frame} frame + * @api public + */ + +Stack.prototype.push = function(frame){ + frame.stack = this; + frame.parent = this.currentFrame; + return [].push.apply(this, arguments); +}; + +/** + * Return the current stack `Frame`. + * + * @return {Frame} + * @api private + */ + +Stack.prototype.__defineGetter__('currentFrame', function(){ + return this[this.length - 1]; +}); + +/** + * Lookup stack frame for the given `block`. + * + * @param {Block} block + * @return {Frame} + * @api private + */ + +Stack.prototype.getBlockFrame = function(block){ + for (var i = 0; i < this.length; ++i) { + if (block == this[i].block) { + return this[i]; + } + } +}; + +/** + * Lookup the given local variable `name`, relative + * to the lexical scope of the current frame's `Block`. + * + * When the result of a lookup is an identifier + * a recursive lookup is performed, defaulting to + * returning the identifier itself. + * + * @param {String} name + * @return {Node} + * @api private + */ + +Stack.prototype.lookup = function(name){ + var block = this.currentFrame.block + , val + , ret; + + do { + var frame = this.getBlockFrame(block); + if (frame && (val = frame.lookup(name))) { + switch (val.first.nodeName) { + case 'ident': + return this.lookup(val.first.name) || val; + default: + return val; + } + } + } while (block = block.parent); +}; + +/** + * Custom inspect. + * + * @return {String} + * @api private + */ + +Stack.prototype.inspect = function(){ + return this.reverse().map(function(frame){ + return frame.inspect(); + }).join('\n'); +}; + +/** + * Return stack string formatted as: + * + * at (:) + * + * @return {String} + * @api private + */ + +Stack.prototype.toString = function(){ + var block + , node + , buf = [] + , location + , len = this.length; + + while (len--) { + block = this[len].block; + if (node = block.node) { + location = '(' + node.filename + ':' + (node.lineno + 1) + ')'; + switch (node.nodeName) { + case 'function': + buf.push(' at ' + node.name + '() ' + location); + break; + case 'group': + buf.push(' at "' + node.nodes[0].val + '" ' + location); + break; + } + } + } + + return buf.join('\n'); +}; + +});// module: stack/index.js + + +require.register("stack/frame.js", function(module, exports, require){ + + +/*! + * Stylus - stack - Frame + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Scope = require('./scope') + , blocks = require('../nodes'); + +/** + * Initialize a new `Frame` with the given `block`. + * + * @param {Block} block + * @api private + */ + +var Frame = module.exports = function Frame(block) { + this._scope = false === block.scope + ? null + : new Scope; + this.block = block; +}; + +/** + * Return this frame's scope or the parent scope + * for scope-less blocks. + * + * @return {Scope} + * @api public + */ + +Frame.prototype.__defineGetter__('scope', function(){ + return this._scope || this.parent.scope; +}); + +/** + * Lookup the given local variable `name`. + * + * @param {String} name + * @return {Node} + * @api private + */ + +Frame.prototype.lookup = function(name){ + return this.scope.lookup(name) +}; + +/** + * Custom inspect. + * + * @return {String} + * @api public + */ + +Frame.prototype.inspect = function(){ + return '[Frame ' + + (false === this.block.scope + ? 'scope-less' + : this.scope.inspect()) + + ']'; +}; + + +});// module: stack/frame.js + + +require.register("stack/scope.js", function(module, exports, require){ + + +/*! + * Stylus - stack - Scope + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Initialize a new `Scope`. + * + * @api private + */ + +var Scope = module.exports = function Scope() { + this.locals = {}; +}; + +/** + * Add `ident` node to the current scope. + * + * @param {Ident} ident + * @api private + */ + +Scope.prototype.add = function(ident){ + this.locals[ident.name] = ident.val; +}; + +/** + * Lookup the given local variable `name`. + * + * @param {String} name + * @return {Node} + * @api private + */ + +Scope.prototype.lookup = function(name){ + return this.locals[name]; +}; + +/** + * Custom inspect. + * + * @return {String} + * @api public + */ + +Scope.prototype.inspect = function(){ + var keys = Object.keys(this.locals).map(function(key){ return '@' + key; }); + return '[Scope' + + (keys.length ? ' ' + keys.join(', ') : '') + + ']'; +}; + + +});// module: stack/scope.js + + +require.register("stylus.js", function(module, exports, require){ + + +/*! + * Stylus + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Renderer = require('./renderer') + , Parser = require('./parser') + , nodes = require('./nodes') + , utils = require('./utils'); + +/** + * Export render as the module. + */ + +exports = module.exports = render; + +/** + * Library version. + */ + +exports.version = '0.16.0'; + +/** + * Expose nodes. + */ + +exports.nodes = nodes; + +/** + * Expose BIFs. + */ + +exports.functions = require('./functions'); + +/** + * Expose utils. + */ + +exports.utils = require('./utils'); + +/** + * Expose constructors. + */ + +exports.Visitor = require('./visitor'); +exports.Parser = require('./parser'); +exports.Evaluator = require('./visitor/evaluator'); + +/** + * Render the given `str` with `options` and callback `fn(err, css)`. + * + * @param {String} str + * @param {Object|Function} options + * @param {Function} fn + * @api public + */ + +exports.render = function(str, options, fn){ + if ('function' == typeof options) fn = options, options = {}; + new Renderer(str, options).render(fn); +}; + +/** + * Return a new `Renderer` for the given `str` and `options`. + * + * @param {String} str + * @param {Object} options + * @return {Renderer} + * @api public + */ + +function render(str, options) { + str = bifs + str; + return new Renderer(str, options); +} + +/** + * Expose optional functions. + */ + +exports.url = require('./functions/url'); + + +});// module: stylus.js + + +require.register("token.js", function(module, exports, require){ + + +/*! + * Stylus - Token + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Initialize a new `Token` with the given `type` and `val`. + * + * @param {String} type + * @param {Mixed} val + * @api private + */ + +var Token = exports = module.exports = function Token(type, val) { + this.type = type; + this.val = val; +}; + +/** + * Custom inspect. + * + * @return {String} + * @api public + */ + +Token.prototype.inspect = function(){ + var val = ' ' + this.val; + return '[Token:' + this.lineno + ' ' + + '\x1b[32m' + this.type + '\x1b[0m' + + '\x1b[33m' + (this.val ? val : '') + '\x1b[0m' + + ']'; +}; + +/** + * Return type or val. + * + * @return {String} + * @api public + */ + +Token.prototype.toString = function(){ + return (undefined === this.val + ? this.type + : this.val).toString(); +}; + + +});// module: token.js + + +require.register("utils.js", function(module, exports, require){ + + +/*! + * Stylus - utils + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var nodes = require('./nodes') + , join = require('./path').join; + +/** + * Check if `path` looks absolute. + * + * @param {String} path + * @return {Boolean} + * @api private + */ + +exports.absolute = function(path){ + return /^([a-z]:\\)|\//i.test(path); +}; + +/** + * Attempt to lookup `path` within `paths` from tail to head. + * Optionally a path to `ignore` may be passed. + * + * @param {String} path + * @param {String} paths + * @param {String} ignore + * @return {String} + * @api private + */ + +exports.lookup = function(path, paths, ignore){ + var lookup + , i = paths.length; + + // Absolute + if (exports.absolute(path)) { + try { + // fs.statSync(path); + return path; + } catch (err) { + // Ignore, continue on + // to trying relative lookup. + // Needed for url(/images/foo.png) + // for example + } + } + + // Relative + while (i--) { + try { + lookup = join(paths[i], path); + if (ignore == lookup) continue; + // fs.statSync(lookup); + return lookup; + } catch (err) { + // Ignore + } + } +}; + +/** + * Format the given `err` with the given `options`. + * + * Options: + * + * - `filename` context filename + * - `context` context line count [8] + * - `lineno` context line number + * - `input` input string + * + * @param {Error} err + * @param {Object} options + * @return {Error} + * @api private + */ + +exports.formatException = function(err, options){ + var lineno = options.lineno + , filename = options.filename + , str = options.input + , context = options.context || 8 + , context = context / 2 + , lines = ('\n' + str).split('\n') + , start = Math.max(lineno - context, 1) + , end = Math.min(lines.length, lineno + context) + , pad = end.toString().length; + + var context = lines.slice(start, end).map(function(line, i){ + var curr = i + start; + return (curr == lineno ? ' > ' : ' ') + + Array(pad - curr.toString().length + 1).join(' ') + + curr + + '| ' + + line; + }).join('\n'); + + err.message = filename + + ':' + lineno + + '\n' + context + + '\n\n' + err.message + '\n' + + (err.stylusStack ? err.stylusStack + '\n' : ''); + + return err; +}; + +/** + * Assert that `node` is of the given `type`, or throw. + * + * @param {Node} node + * @param {Function} type + * @param {String} param + * @api public + */ + +exports.assertType = function(node, type, param){ + exports.assertPresent(node, param); + if (node.nodeName == type) return; + var actual = node.nodeName + , msg = 'expected "' + + param + '" to be a ' + + type + ', but got ' + + actual + ':' + node; + throw new Error('TypeError: ' + msg); +}; + +/** + * Assert that `node` is a `String` or `Ident`. + * + * @param {Node} node + * @param {String} param + * @api public + */ + +exports.assertString = function(node, param){ + exports.assertPresent(node, param); + switch (node.nodeName) { + case 'string': + case 'ident': + case 'literal': + return; + default: + var actual = node.nodeName + , msg = 'expected string, ident or literal, but got ' + actual + ':' + node; + throw new Error('TypeError: ' + msg); + } +}; + +/** + * Assert that `node` is a `RGBA` or `HSLA`. + * + * @param {Node} node + * @param {String} param + * @api public + */ + +exports.assertColor = function(node, param){ + exports.assertPresent(node, param); + switch (node.nodeName) { + case 'rgba': + case 'hsla': + return; + default: + var actual = node.nodeName + , msg = 'expected rgba or hsla, but got ' + actual + ':' + node; + throw new Error('TypeError: ' + msg); + } +}; + +/** + * Assert that param `name` is given, aka the `node` is passed. + * + * @param {Node} node + * @param {String} name + * @api public + */ + +exports.assertPresent = function(node, name){ + if (node) return; + if (name) throw new Error('"' + name + '" argument required'); + throw new Error('argument missing'); +}; + +/** + * Unwrap `expr`. + * + * Takes an expressions with length of 1 + * such as `((1 2 3))` and unwraps it to `(1 2 3)`. + * + * @param {Expression} expr + * @return {Node} + * @api public + */ + +exports.unwrap = function(expr){ + // explicitly preserve the expression + if (expr.preserve) return expr; + if ('arguments' != expr.nodeName && 'expression' != expr.nodeName) return expr; + if (1 != expr.nodes.length) return expr; + if ('arguments' != expr.nodes[0].nodeName && 'expression' != expr.nodes[0].nodeName) return expr; + return exports.unwrap(expr.nodes[0]); +}; + +/** + * Return param names for `fn`. + * + * @param {Function} fn + * @return {Array} + * @api private + */ + +exports.params = function(fn){ + return fn + .toString() + .match(/\(([^)]*)\)/)[1].split(/ *, */); +}; + +/** + * Merge object `b` with `a`. + * + * @param {Object} a + * @param {Object} b + * @return {Object} a + * @api private + */ + +exports.merge = function(a, b){ + for (var k in b) a[k] = b[k]; + return a; +} + + +});// module: utils.js + + +require.register("visitor/index.js", function(module, exports, require){ + + +/*! + * Stylus - Visitor + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Initialize a new `Visitor` with the given `root` Node. + * + * @param {Node} root + * @api private + */ + +var Visitor = module.exports = function Visitor(root) { + this.root = root; +}; + +/** + * Visit the given `node`. + * + * @param {Node|Array} node + * @api public + */ + +Visitor.prototype.visit = function(node, fn){ + var method = 'visit' + node.constructor.name; + if (this[method]) return this[method](node); + return node; +}; + + + +});// module: visitor/index.js + + +require.register("visitor/compiler.js", function(module, exports, require){ + + +/*! + * Stylus - Compiler + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Visitor = require('./index') + , nodes = require('../nodes'); + +/** + * Initialize a new `Compiler` with the given `root` Node + * and the following `options`. + * + * Options: + * + * - `compress` Compress the css output, defaults to false + * + * @param {Node} root + * @api public + */ + +var Compiler = module.exports = function Compiler(root, options) { + options = options || {}; + this.compress = options.compress; + this.firebug = options.firebug; + this.linenos = options.linenos; + this.indents = 1; + Visitor.call(this, root); + this.tree = []; + this.js = ''; +}; + +/** + * Inherit from `Visitor.prototype`. + */ + +Compiler.prototype.__proto__ = Visitor.prototype; + +/** + * Compile to css, and return a string of CSS. + * + * @return {String} + * @api private + */ + +Compiler.prototype.compile = function(){ + return this.visit(this.root); +}; + +/** + * Return indentation string. + * + * @return {String} + * @api private + */ + +Compiler.prototype.__defineGetter__('indent', function(){ + return this.compress + ? '' + : new Array(this.indents).join(' '); +}); + +/** + * Visit Root. + */ + +Compiler.prototype.visitRoot = function(block){ + this.buf = ''; + for (var i = 0, len = block.nodes.length; i < len; ++i) { + var node = block.nodes[i]; + switch (node.nodeName) { + case 'null': + case 'expression': + case 'function': + case 'jsliteral': + case 'unit': + continue; + default: + var ret = this.visit(node); + if (ret) this.buf += ret + '\n'; + } + } + return this.buf; +}; + +/** + * Visit Block. + */ + +Compiler.prototype.visitBlock = function(block){ + var node; + + if (block.hasProperties) { + var arr = [this.compress ? '{' : ' {']; + ++this.indents; + for (var i = 0, len = block.nodes.length; i < len; ++i) { + this.last = len - 1 == i; + node = block.nodes[i]; + switch (node.nodeName) { + case 'null': + case 'expression': + case 'function': + case 'jsliteral': + case 'group': + case 'unit': + continue; + default: + arr.push(this.visit(node)); + } + } + --this.indents; + arr.push(this.indent + '}'); + this.buf += arr.join(this.compress ? '' : '\n'); + this.buf += '\n'; + } + + // Nesting + for (var i = 0, len = block.nodes.length; i < len; ++i) { + node = block.nodes[i]; + switch (node.nodeName) { + case 'group': + case 'print': + case 'page': + case 'block': + case 'keyframes': + if (this.linenos || this.firebug) this.debugInfo(node); + this.visit(node); + break; + case 'media': + case 'import': + case 'fontface': + this.visit(node); + break; + } + } +}; + +/** + * Visit Keyframes. + */ + +Compiler.prototype.visitKeyframes = function(node){ + var prefix = 'official' == node.prefix + ? '' + : '-' + node.prefix + '-'; + + this.buf += '@' + prefix + 'keyframes ' + + this.visit(node.name) + + (this.compress ? '{' : ' {'); + ++this.indents; + node.frames.forEach(function(frame){ + if (!this.compress) this.buf += '\n '; + this.buf += this.visit(frame.pos); + this.visit(frame.block); + }, this); + --this.indents; + this.buf += '}' + (this.compress ? '' : '\n'); +}; + +/** + * Visit Media. + */ + +Compiler.prototype.visitMedia = function(media){ + this.buf += '@media ' + media.val; + this.buf += this.compress ? '{' : ' {\n'; + ++this.indents; + this.visit(media.block); + --this.indents; + this.buf += '}' + (this.compress ? '' : '\n'); +}; + +/** + * Visit Page. + */ + +Compiler.prototype.visitPage = function(page){ + this.buf += this.indent + '@page'; + this.buf += page.selector ? ' ' + page.selector : ''; + this.visit(page.block); +}; + +/** + * Visit Import. + */ + +Compiler.prototype.visitImport = function(imported){ + this.buf += '@import ' + this.visit(imported.path) + ';\n'; +}; + +/** + * Visit FontFace. + */ + +Compiler.prototype.visitFontFace = function(face){ + this.buf += this.indent + '@font-face'; + this.visit(face.block); +}; + +/** + * Visit JSLiteral. + */ + +Compiler.prototype.visitJSLiteral = function(js){ + this.js += '\n' + js.val.replace(/@selector/g, '"' + this.selector + '"'); + return ''; +}; + +/** + * Visit Comment. + */ + +Compiler.prototype.visitComment = function(comment){ + return this.compress + ? comment.suppress + ? '' + : comment.str + : comment.str; +}; + +/** + * Visit Function. + */ + +Compiler.prototype.visitFunction = function(fn){ + return fn.name; +}; + +/** + * Visit Variable. + */ + +Compiler.prototype.visitVariable = function(variable){ + return ''; +}; + +/** + * Visit Charset. + */ + +Compiler.prototype.visitCharset = function(charset){ + return '@charset ' + this.visit(charset.val) + ';'; +}; + +/** + * Visit Literal. + */ + +Compiler.prototype.visitLiteral = function(lit){ + return lit.val.trim().replace(/^ /gm, ''); +}; + +/** + * Visit Boolean. + */ + +Compiler.prototype.visitBoolean = function(bool){ + return bool.toString(); +}; + +/** + * Visit RGBA. + */ + +Compiler.prototype.visitRGBA = function(rgba){ + return rgba.toString(); +}; + +/** + * Visit HSLA. + */ + +Compiler.prototype.visitHSLA = function(hsla){ + return hsla.rgba.toString(); +}; + +/** + * Visit Unit. + */ + +Compiler.prototype.visitUnit = function(unit){ + var type = unit.type || '' + , n = unit.val + , float = n != (n | 0); + + // Compress + if (this.compress) { + // Zero is always '0', unless when + // a percentage, this is required by keyframes + if ('%' != type && 0 == n) return '0'; + // Omit leading '0' on floats + if (float && n < 1 && n > -1) { + return n.toString().replace('0.', '.') + type; + } + } + + return n.toString() + type; +}; + +/** + * Visit Group. + */ + +Compiler.prototype.visitGroup = function(group){ + var self = this + , tree = this.tree + , prev = tree[tree.length - 1] + , curr = []; + + // Construct an array of arrays + // representing the selector hierarchy + group.nodes.forEach(function(node){ + curr.push(node.parent + ? node + : node.val); + }); + + tree.push(curr); + + // Reverse recurse the + // hierarchy array to build + // up the selector combinations. + // When we reach root, we have our + // selector string built + var selectors = [] + , buf = []; + function join(arr, i) { + if (i) { + arr[i].forEach(function(str){ + buf.unshift(str); + join(arr, i - 1); + buf.shift(); + }); + } else { + arr[0].forEach(function(selector){ + var str = selector.trim(); + if (buf.length) { + for (var i = 0, len = buf.length; i < len; ++i) { + if (~buf[i].indexOf('&')) { + str = buf[i].replace(/&/g, str).trim(); + } else { + str += ' ' + buf[i].trim(); + } + } + } + selectors.push(self.indent + str.trimRight()); + }); + } + } + + // Join selectors + if (group.block.hasProperties) { + join(tree, tree.length - 1); + this.buf += (this.selector = selectors.join(this.compress ? ',' : ',\n')); + } + + // Output blocks + this.visit(group.block); + tree.pop(); +}; + +/** + * Visit Ident. + */ + +Compiler.prototype.visitIdent = function(ident){ + return ident.name; +}; + +/** + * Visit String. + */ + +Compiler.prototype.visitString = function(string){ + return this.isURL + ? string.val + : string.toString(); +}; + +/** + * Visit Null. + */ + +Compiler.prototype.visitNull = function(node){ + return ''; +}; + +/** + * Visit Call. + */ + +Compiler.prototype.visitCall = function(call){ + this.isURL = 'url' == call.name; + var args = call.args.nodes.map(function(arg){ + return this.visit(arg); + }, this).join(this.compress ? ',' : ', '); + if (this.isURL) args = '"' + args + '"'; + delete this.isURL; + return call.name + '(' + args + ')'; +}; + +/** + * Visit Expression. + */ + +Compiler.prototype.visitExpression = function(expr){ + var buf = [] + , self = this + , len = expr.nodes.length + , nodes = expr.nodes.map(function(node){ return self.visit(node); }); + + nodes.forEach(function(node, i){ + var last = i == len - 1; + buf.push(node); + if ('/' == nodes[i + 1] || '/' == node) return; + if (last) return; + buf.push(expr.isList + ? (self.compress ? ',' : ', ') + : (self.isURL ? '' : ' ')); + }); + + return buf.join(''); +}; + +/** + * Visit Arguments. + */ + +Compiler.prototype.visitArguments = Compiler.prototype.visitExpression; + +/** + * Visit Property. + */ + +Compiler.prototype.visitProperty = function(prop){ + var self = this + , val = this.visit(prop.expr); + return this.indent + (prop.name || prop.segments.join('')) + + (this.compress ? ':' + val : ': ' + val) + + (this.compress + ? (this.last ? '' : ';') + : ';'); +}; + + +});// module: visitor/compiler.js + + +require.register("visitor/evaluator.js", function(module, exports, require){ + + +/*! + * Stylus - Evaluator + * Copyright(c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Visitor = require('./index') + , nodes = require('../nodes') + , Stack = require('../stack') + , Frame = require('../stack/frame') + , Scope = require('../stack/scope') + , utils = require('../utils') + , bifs = require('../functions') + , dirname = require('../path').dirname + , join = require('../path').join + , colors = require('../colors'); + +/** + * Initialize a new `Evaluator` with the given `root` Node + * and the following `options`. + * + * Options: + * + * - `compress` Compress the css output, defaults to false + * - `warn` Warn the user of duplicate function definitions etc + * + * @param {Node} root + * @api private + */ + +var Evaluator = module.exports = function Evaluator(root, options) { + options = options || {}; + Visitor.call(this, root); + this.stack = new Stack; + this.imports = options.imports || []; + this.functions = options.functions || {}; + this.globals = options.globals || {}; + this.paths = options.paths || []; + this.filename = options.filename; + this.paths.push(dirname(options.filename || '.')); + this.stack.push(this.global = new Frame(root)); + this.warnings = options.warn; + this.options = options; + this.calling = []; // TODO: remove, use stack + this.importStack = []; +}; + +/** + * Inherit from `Visitor.prototype`. + */ + +Evaluator.prototype.__proto__ = Visitor.prototype; + +/** + * Proxy visit to expose node line numbers. + * + * @param {Node} node + * @return {Node} + * @api private + */ + +var visit = Visitor.prototype.visit; +Evaluator.prototype.visit = function(node){ + try { + return visit.call(this, node); + } catch (err) { + if (err.filename) throw err; + err.lineno = node.lineno; + err.filename = node.filename; + err.stylusStack = this.stack.toString(); + try { + // err.input = fs.readFileSync(err.filename, 'utf8'); + } catch (err) { + // ignore + } + throw err; + } +}; + +/** + * Perform evaluation setup: + * + * - populate global scope + * - iterate imports + * + * @api private + */ + +Evaluator.prototype.setup = function(){ + this.populateGlobalScope(); + this.imports.forEach(function(file){ + var expr = new nodes.Expression; + expr.push(new nodes.String(file)); + this.visit(new nodes.Import(expr)); + }, this); +}; + +/** + * Populate the global scope with: + * + * - css colors + * - user-defined globals + * + * @api private + */ + +Evaluator.prototype.populateGlobalScope = function(){ + var scope = this.global.scope; + + // colors + Object.keys(colors).forEach(function(name){ + var rgb = colors[name] + , rgba = new nodes.RGBA(rgb[0], rgb[1], rgb[2], 1) + , node = new nodes.Ident(name, rgba); + scope.add(node); + }); + + // user-defined globals + var globals = this.globals; + Object.keys(globals).forEach(function(name){ + scope.add(new nodes.Ident(name, globals[name])); + }); +}; + +/** + * Evaluate the tree. + * + * @return {Node} + * @api private + */ + +Evaluator.prototype.evaluate = function(){ + this.setup(); + return this.visit(this.root); +}; + +/** + * Visit Group. + */ + +Evaluator.prototype.visitGroup = function(group){ + var vendors = this.vendors; + + group.nodes = group.nodes.map(function(selector){ + selector.val = this.interpolate(selector); + return selector; + }, this); + + group.block = this.visit(group.block); + return group; +}; + +/** + * Visit Charset. + */ + +Evaluator.prototype.visitCharset = function(charset){ + return charset; +}; + +/** + * Visit Return. + */ + +Evaluator.prototype.visitReturn = function(ret){ + ret.expr = this.visit(ret.expr); + throw ret; +}; + +/** + * Visit Media. + */ + +Evaluator.prototype.visitMedia = function(media){ + media.block = this.visit(media.block); + return media; +}; + +/** + * Visit Keyframes. + */ + +Evaluator.prototype.visitKeyframes = function(keyframes){ + if (keyframes.fabricated) return keyframes; + keyframes.name = this.visit(keyframes.name).first.name; + + keyframes.frames = keyframes.frames.map(function(frame){ + frame.block = this.visit(frame.block); + return frame; + }, this); + + if ('official' != keyframes.prefix) return keyframes; + + this.vendors.forEach(function(prefix){ + var node = keyframes.clone(); + node.prefix = prefix; + node.fabricated = true; + this.currentBlock.push(node); + }, this); + + return nodes.nil; +}; + +/** + * Visit Function. + */ + +Evaluator.prototype.visitFunction = function(fn){ + // check local + var local = this.stack.currentFrame.scope.lookup(fn.name); + if (local) this.warn('local ' + local.nodeName + ' "' + fn.name + '" previously defined in this scope'); + + // user-defined + var user = this.functions[fn.name]; + if (user) this.warn('user-defined function "' + fn.name + '" is already defined'); + + // BIF + var bif = bifs[fn.name]; + if (bif) this.warn('built-in function "' + fn.name + '" is already defined'); + + return fn; +}; + +/** + * Visit Each. + */ + +Evaluator.prototype.visitEach = function(each){ + var expr = utils.unwrap(this.visit(utils.unwrap(each.expr))) + , len = expr.nodes.length + , val = new nodes.Ident(each.val) + , key = new nodes.Ident(each.key || '__index__') + , scope = this.currentScope + , block = this.currentBlock + , vals = [] + , body; + + each.block.scope = false; + for (var i = 0; i < len; ++i) { + val.val = expr.nodes[i]; + key.val = new nodes.Unit(i); + scope.add(val); + scope.add(key); + body = this.visit(each.block.clone()); + vals = vals.concat(body.nodes); + } + + this.mixin(vals, block); + return vals[vals.length - 1] || nodes.nil; +}; + +/** + * Visit Call. + */ + +Evaluator.prototype.visitCall = function(call){ + var fn = this.lookup(call.name) + , ret; + + // url() + this.ignoreColors = 'url' == call.name; + + // Variable function + if (fn && 'expression' == fn.nodeName) { + fn = fn.nodes[0]; + } + + // Not a function? try user-defined or built-ins + if (fn && 'function' != fn.nodeName) { + fn = this.lookupFunction(call.name); + } + + // Undefined function, render literal css + if (!fn || fn.nodeName != 'function') { + var ret = this.literalCall(call); + this.ignoreColors = false; + return ret; + } + + this.calling.push(call.name); + + // Massive stack + if (this.calling.length > 200) { + throw new RangeError('Maximum call stack size exceeded'); + } + + // First node in expression + if ('expression' == fn.nodeName) fn = fn.first; + + // Evaluate arguments + var _ = this.ret; + this.ret = true; + var args = this.visit(call.args); + for (var key in call.args.map) { + call.args.map[key] = this.visit(call.args.map[key]); + } + this.ret = _; + + // Built-in + if (fn.fn) { + ret = this.invokeBuiltin(fn.fn, args); + // User-defined + } else if ('function' == fn.nodeName) { + ret = this.invokeFunction(fn, args); + } + + this.calling.pop(); + this.ignoreColors = false; + return ret; +}; + +/** + * Visit Ident. + */ + +Evaluator.prototype.visitIdent = function(ident){ + var prop; + // Property lookup + if (ident.property) { + if (prop = this.lookupProperty(ident.name)) { + return this.visit(prop.expr.clone()); + } + return nodes.nil; + // Lookup + } else if (ident.val.isNull) { + var val = this.lookup(ident.name); + return val ? this.visit(val) : ident; + // Assign + } else { + var _ = this.ret; + this.ret = true; + ident.val = this.visit(ident.val); + this.ret = _; + this.currentScope.add(ident); + return ident.val; + } +}; + +/** + * Visit BinOp. + */ + +Evaluator.prototype.visitBinOp = function(binop){ + // Special-case "is defined" pseudo binop + if ('is defined' == binop.op) return this.isDefined(binop.left); + + var _ = this.ret; + this.ret = true; + // Visit operands + var op = binop.op + , left = this.visit(binop.left) + , right = this.visit(binop.right); + this.ret = _; + + // HACK: ternary + var val = binop.val + ? this.visit(binop.val) + : null; + + // Operate + try { + return this.visit(left.operate(op, right, val)); + } catch (err) { + // disregard coercion issues in equality + // checks, and simply return false + if ('CoercionError' == err.name) { + switch (op) { + case '==': + return nodes.no; + case '!=': + return nodes.yes; + } + } + throw err; + } +}; + +/** + * Visit UnaryOp. + */ + +Evaluator.prototype.visitUnaryOp = function(unary){ + var op = unary.op + , node = this.visit(unary.expr); + + if ('!' != op) { + node = node.first.clone(); + utils.assertType(node, 'unit'); + } + + switch (op) { + case '-': + node.val = -node.val; + break; + case '+': + node.val = +node.val; + break; + case '~': + node.val = ~node.val; + break; + case '!': + return node.toBoolean().negate(); + } + + return node; +}; + +/** + * Visit TernaryOp. + */ + +Evaluator.prototype.visitTernary = function(ternary){ + var ok = this.visit(ternary.cond).toBoolean(); + return ok.isTrue + ? this.visit(ternary.trueExpr) + : this.visit(ternary.falseExpr); +}; + +/** + * Visit Expression. + */ + +Evaluator.prototype.visitExpression = function(expr){ + for (var i = 0, len = expr.nodes.length; i < len; ++i) { + expr.nodes[i] = this.visit(expr.nodes[i]); + } + return expr; +}; + +/** + * Visit Arguments. + */ + +Evaluator.prototype.visitArguments = Evaluator.prototype.visitExpression; + +/** + * Visit Property. + */ + +Evaluator.prototype.visitProperty = function(prop){ + var name = this.interpolate(prop) + , fn = this.lookup(name) + , call = fn && 'function' == fn.nodeName + , literal = ~this.calling.indexOf(name); + + // Function of the same name + if (call && !literal && !prop.literal) { + this.calling.push(name); + var args = nodes.Arguments.fromExpression(utils.unwrap(prop.expr)); + var ret = this.visit(new nodes.Call(name, args)); + this.calling.pop(); + return ret; + // Regular property + } else { + var _ = this.ret; + this.ret = true; + prop.name = name; + prop.literal = true; + this.property = prop; + prop.expr = this.visit(prop.expr); + delete this.property; + this.ret = _; + return prop; + } +}; + +/** + * Visit Root. + */ + +Evaluator.prototype.visitRoot = function(block){ + for (var i = 0; i < block.nodes.length; ++i) { + block.index = this.rootIndex = i; + block.nodes[i] = this.visit(block.nodes[i]); + } + return block; +}; + +/** + * Visit Block. + */ + +Evaluator.prototype.visitBlock = function(block){ + this.stack.push(new Frame(block)); + for (block.index = 0; block.index < block.nodes.length; ++block.index) { + try { + block.nodes[block.index] = this.visit(block.nodes[block.index]); + } catch (err) { + if ('return' == err.nodeName) { + if (this.ret) { + this.stack.pop(); + throw err; + } else { + block.nodes[block.index] = err; + break; + } + } else { + throw err; + } + } + } + this.stack.pop(); + return block; +}; + +/** + * Visit If. + */ + +Evaluator.prototype.visitIf = function(node){ + var ret + , _ = this.ret + , block = this.currentBlock + , negate = node.negate; + + this.ret = true; + var ok = this.visit(node.cond).first.toBoolean(); + this.ret = _; + + // Evaluate body + if (negate) { + // unless + if (ok.isFalse) { + ret = this.visit(node.block); + } + } else { + // if + if (ok.isTrue) { + ret = this.visit(node.block); + // else + } else if (node.elses.length) { + var elses = node.elses + , len = elses.length; + for (var i = 0; i < len; ++i) { + // else if + if (elses[i].cond) { + if (this.visit(elses[i].cond).first.toBoolean().isTrue) { + ret = this.visit(elses[i].block); + break; + } + // else + } else { + ret = this.visit(elses[i]); + } + } + } + } + + // mixin conditional statements within a selector group + if (ret && !node.postfix && block.node && 'group' == block.node.nodeName) { + this.mixin(ret.nodes, block); + return nodes.nil; + } + + return ret || nodes.nil; +}; + +/** + * Visit Import. + */ + +Evaluator.prototype.visitImport = function(imported){ + var found + , root = this.root + , Parser = require('../parser') + , path = this.visit(imported.path).first; + + // url() passed + if ('url' == path.name) return imported; + + // Enusre string + if (!path.string) throw new Error('@import string expected'); + var name = path = path.string; + + // Literal + if (~path.indexOf('.css')) return imported; + if (!~path.indexOf('.styl')) path += '.styl'; + + // Lookup + found = utils.lookup(path, this.paths, this.filename); + found = found || utils.lookup(join(name, 'index.styl'), this.paths, this.filename); + + // Expose imports + imported.path = found; + imported.dirname = dirname(found); + this.paths.push(imported.dirname); + if (this.options._imports) this.options._imports.push(imported); + + // Throw if import failed + if (!found) throw new Error('failed to locate @import file ' + path); + + // Parse the file + this.importStack.push(found); + nodes.filename = found; + + var str = fs.readFileSync(found, 'utf8') + , block = new nodes.Block + , parser = new Parser(str, utils.merge({ root: block }, this.options)); + + try { + block = parser.parse(); + } catch (err) { + err.filename = found; + err.lineno = parser.lexer.lineno; + err.input = str; + throw err; + } + + // Store the modified time + fs.stat(found, function(err, stat){ + if (err) return; + imported.mtime = stat.mtime; + }); + + // Evaluate imported "root" + block.parent = root; + block.scope = false; + var ret = this.visit(block); + this.paths.pop(); + this.importStack.pop(); + + return ret; +}; + +/** + * Invoke `fn` with `args`. + * + * @param {Function} fn + * @param {Array} args + * @return {Node} + * @api private + */ + +Evaluator.prototype.invokeFunction = function(fn, args){ + var block = new nodes.Block(fn.block.parent); + fn.block.parent = block; + + // Clone the function body + // to prevent mutation of subsequent calls + // inject argument scope + var body = fn.block.clone(); + + // mixin block + var mixinBlock = this.stack.currentFrame.block; + + // new block scope + this.stack.push(new Frame(block)); + var scope = this.currentScope; + + // arguments local + scope.add(new nodes.Ident('arguments', args)); + + // mixin scope introspection + scope.add(new nodes.Ident('mixin', this.ret + ? nodes.no + : new nodes.String(mixinBlock.nodeName))); + + // current property + if (this.property) { + var prop = this.propertyExpression(this.property, fn.name); + scope.add(new nodes.Ident('current-property', prop)); + } else { + scope.add(new nodes.Ident('current-property', nodes.nil)); + } + + // inject arguments as locals + var i = 0 + , len = args.nodes.length; + fn.params.nodes.forEach(function(node){ + // rest param support + if (node.rest) { + node.val = new nodes.Expression; + for (; i < len; ++i) node.val.push(args.nodes[i]); + node.val.preserve = true; + // argument default support + } else { + var arg = args.map[node.name] || args.nodes[i++]; + node = node.clone(); + if (arg) { + if (!arg.isEmpty) node.val = arg; + } else { + args.push(node.val); + } + + // required argument not satisfied + if (node.val.isNull) { + throw new Error('argument "' + node + '" required for ' + fn); + } + } + + scope.add(node); + }); + + // invoke + return this.invoke(body, true); +}; + +/** + * Invoke built-in `fn` with `args`. + * + * @param {Function} fn + * @param {Array} args + * @return {Node} + * @api private + */ + +Evaluator.prototype.invokeBuiltin = function(fn, args){ + // Map arguments to first node + // providing a nicer js api for + // BIFs. Functions may specify that + // they wish to accept full expressions + // via .raw + if (fn.raw) { + args = args.nodes; + } else { + args = utils.params(fn).reduce(function(ret, param){ + var arg = args.map[param] || args.nodes.shift(); + if (arg) ret.push(arg.first); + return ret; + }, []); + } + + // Invoke the BIF + var body = fn.apply(this, args); + + // Always wrapping allows js functions + // to return several values with a single + // Expression node + var expr = new nodes.Expression; + expr.push(body); + body = expr; + + // Invoke + return this.invoke(body); +}; + +/** + * Invoke the given function `body`. + * + * @param {Block} body + * @return {Node} + * @api private + */ + +Evaluator.prototype.invoke = function(body, stack){ + var self = this + , ret; + + // Return + if (this.ret) { + ret = this.eval(body.nodes); + if (stack) this.stack.pop(); + // Mixin + } else { + var targetFrame = this.stack[this.stack.length - 2]; + if (targetFrame) this.targetBlock = targetFrame.block; + body = this.visit(body); + if (stack) this.stack.pop(); + this.mixin(body.nodes, this.currentBlock); + ret = nodes.nil; + } + + return ret; +}; + +/** + * Mixin the given `nodes` to the given `block`. + * + * @param {Array} nodes + * @param {Block} block + * @api private + */ + +Evaluator.prototype.mixin = function(nodes, block){ + var len = block.nodes.length + , head = block.nodes.slice(0, block.index) + , tail = block.nodes.slice(block.index + 1, len); + this._mixin(nodes, head); + block.nodes = head.concat(tail); +}; + +/** + * Mixin the given `nodes` to the `dest` array. + * + * @param {Array} nodes + * @param {Array} dest + * @api private + */ + +Evaluator.prototype._mixin = function(nodes, dest){ + var node + , len = nodes.length; + for (var i = 0; i < len; ++i) { + switch ((node = nodes[i]).nodeName) { + case 'return': + return; + case 'block': + this._mixin(node.nodes, dest); + break; + default: + dest.push(node); + } + } +}; + +/** + * Evaluate the given `vals`. + * + * @param {Array} vals + * @return {Node} + * @api private + */ + +Evaluator.prototype.eval = function(vals){ + if (!vals) return nodes.nil; + var len = vals.length + , node = nodes.nil; + + try { + for (var i = 0; i < len; ++i) { + node = vals[i]; + switch (node.nodeName) { + case 'if': + if ('block' != node.block.nodeName) { + node = this.visit(node); + break; + } + case 'each': + case 'block': + node = this.visit(node); + if (node.nodes) node = this.eval(node.nodes); + break; + default: + node = this.visit(node); + } + } + } catch (err) { + if ('return' == err.nodeName) { + return err.expr; + } else { + throw err; + } + } + + return node; +}; + +/** + * Literal function `call`. + * + * @param {Call} call + * @return {call} + * @api private + */ + +Evaluator.prototype.literalCall = function(call){ + call.args = this.visit(call.args); + return call; +}; + +/** + * Lookup property `name` in the in the current block. + * + * @param {String} name + * @return {Property} + * @api private + */ + +Evaluator.prototype.lookupProperty = function(name){ + var nodes = this.closestBlock.nodes + , target = (this.targetBlock && this.targetBlock.nodes) || [] + , nodes = target.concat(nodes); + + for (var i = 0, len = nodes.length; i < len; ++i) { + if ('property' != nodes[i].nodeName) continue; + if (name == this.interpolate(nodes[i])) { + return nodes[i].clone(); + } + } +}; + +/** + * Lookup `name`, with support for JavaScript + * functions, and BIFs. + * + * @param {String} name + * @return {Node} + * @api private + */ + +Evaluator.prototype.lookup = function(name){ + var val; + if (this.ignoreColors && name in colors) return; + if (val = this.stack.lookup(name)) { + return utils.unwrap(val); + } else { + return this.lookupFunction(name); + } +}; + +/** + * Map segments in `node` returning a string. + * + * @param {Node} node + * @return {String} + * @api private + */ + +Evaluator.prototype.interpolate = function(node){ + var self = this; + return node.segments.map(function(node){ + function toString(node) { + switch (node.nodeName) { + case 'function': + case 'ident': + return node.name; + case 'literal': + case 'string': + case 'unit': + return node.val; + case 'expression': + var _ = self.ret; + self.ret = true; + var ret = toString(self.visit(node).first); + self.ret = _; + return ret; + } + } + return toString(node); + }).join(''); +}; + +/** + * Lookup JavaScript user-defined or built-in function. + * + * @param {String} name + * @return {Function} + * @api private + */ + +Evaluator.prototype.lookupFunction = function(name){ + var fn = this.functions[name] || bifs[name]; + if (fn) return new nodes.Function(name, fn); +}; + +/** + * Check if the given `node` is an ident, and if it is defined. + * + * @param {Node} node + * @return {Boolean} + * @api private + */ + +Evaluator.prototype.isDefined = function(node){ + if ('ident' == node.nodeName) { + return nodes.Boolean(this.lookup(node.name)); + } else { + throw new Error('invalid "is defined" check on non-variable ' + node); + } +}; + +/** + * Return `Expression` based on the given `prop`, + * replacing cyclic calls to the given function `name` + * with "__CALL__". + * + * @param {Property} prop + * @param {String} name + * @return {Expression} + * @api private + */ + +Evaluator.prototype.propertyExpression = function(prop, name){ + var expr = new nodes.Expression + , val = prop.expr.clone(); + + // name + expr.push(new nodes.String(prop.name)); + + // replace cyclic call with __CALL__ + val.nodes = val.nodes.map(function(node){ + if ('call' == node.nodeName && name == node.name) { + return new nodes.Literal('__CALL__'); + } + return node; + }); + + expr.push(val); + return expr; +}; + +/** + * Warn with the given `msg`. + * + * @param {String} msg + * @api private + */ + +Evaluator.prototype.warn = function(msg){ + if (!this.warnings) return; + console.warn('\033[33mWarning:\033[0m ' + msg); +}; + +/** + * Return the current `Block`. + * + * @return {Block} + * @api private + */ + +Evaluator.prototype.__defineGetter__('currentBlock', function(){ + return this.stack.currentFrame.block; +}); + +/** + * Return the closest mixin-able `Block`. + * + * @return {Block} + * @api private + */ + +Evaluator.prototype.__defineGetter__('closestBlock', function(){ + var i = this.stack.length + , block; + while (i--) { + block = this.stack[i].block; + if (block.node) { + switch (block.node.nodeName) { + case 'group': + case 'function': + return block; + } + } + } +}); + +/** + * Return an array of vendor names. + * + * @return {Array} + * @api private + */ + +Evaluator.prototype.__defineGetter__('vendors', function(){ + return []; // TOOD: fix + return this.lookup('vendors').nodes.map(function(node){ + return node.string; + }); +}); + +/** + * Return the current frame `Scope`. + * + * @return {Scope} + * @api private + */ + +Evaluator.prototype.__defineGetter__('currentScope', function(){ + return this.stack.currentFrame.scope; +}); + +/** + * Return the current `Frame`. + * + * @return {Frame} + * @api private + */ + +Evaluator.prototype.__defineGetter__('currentFrame', function(){ + return this.stack.currentFrame; +}); + + +});// module: visitor/evaluator.js + + return require('stylus'); +})(); \ No newline at end of file diff --git a/ajax/libs/stylus/0.32.1/stylus.min.js b/ajax/libs/stylus/0.32.1/stylus.min.js new file mode 100644 index 000000000..522e6064b --- /dev/null +++ b/ajax/libs/stylus/0.32.1/stylus.min.js @@ -0,0 +1,3 @@ +var bifs="vendors = moz webkit o ms official\n\n// stringify the given arg\n\n-string(arg)\n type(arg) + ' ' + arg\n\n// require a color\n\nrequire-color(color)\n unless color is a 'color' \n error('RGB or HSL value expected, got a ' + -string(color))\n\n// require a unit\n\nrequire-unit(n)\n unless n is a 'unit'\n error('unit expected, got a ' + -string(n))\n\n// require a string\n\nrequire-string(str)\n unless str is a 'string' or str is a 'ident'\n error('string expected, got a ' + -string(str))\n\n// apply js Math function\n\nmath(n, fn) \n require-unit(n)\n require-string(fn)\n -math(n, fn)\n\n// adjust the given color's property by amount\n\nadjust(color, prop, amount)\n require-color(color)\n require-string(prop)\n require-unit(amount)\n -adjust(color, prop, amount)\n\n// Math functions\n\nabs(n) { math(n, 'abs') }\nceil(n) { math(n, 'ceil') }\nfloor(n) { math(n, 'floor') }\nround(n) { math(n, 'round') }\nsin(n) { math(n, 'sin') }\ncos(n) { math(n, 'cos') }\nmin(a, b) { a < b ? a : b }\nmax(a, b) { a > b ? a : b }\nPI = -math-prop('PI')\n\n// return the sum of the given numbers\n\nsum(nums)\n sum = 0\n sum += n for n in nums\n\n// return the average of the given numbers\n\navg(nums)\n sum(nums) / length(nums)\n\n// color components\n\nalpha(color) { component(hsl(color), 'alpha') }\nhue(color) { component(hsl(color), 'hue') }\nsaturation(color) { component(hsl(color), 'saturation') }\nlightness(color) { component(hsl(color), 'lightness') }\n\n// check if n is an odd number\n\nodd(n)\n 1 == n % 2\n\n// check if n is an even number\n\neven(n)\n 0 == n % 2\n\n// check if color is light\n\nlight(color)\n lightness(color) >= 50%\n\n// check if color is dark\n\ndark(color)\n lightness(color) < 50%\n\n// desaturate color by amount\n\ndesaturate(color, amount)\n adjust(color, 'saturation', - amount)\n\n// saturate color by amount\n\nsaturate(color, amount)\n adjust(color, 'saturation', amount)\n\n// darken by the given amount\n\ndarken(color, amount)\n adjust(color, 'lightness', - amount)\n\n// lighten by the given amount\n\nlighten(color, amount)\n adjust(color, 'lightness', amount)\n\n// decerase opacity by amount\n\nfade-out(color, amount)\n color - rgba(black, amount)\n\n// increase opacity by amount\n\nfade-in(color, amount)\n color + rgba(black, amount)\n\n// return the last value in the given expr\n\nlast(expr)\n expr[length(expr) - 1]\n\n// join values with the given delimiter\n\njoin(delim, vals...)\n buf = ''\n vals = vals[0] if length(vals) == 1\n for val, i in vals\n buf += i ? delim + val : val\n",stylus=function(){function a(b){var c=a.resolve(b),d=a.modules[c];if(!d)throw new Error('failed to require "'+b+'"');return d.exports||(d.exports={},d.call(d.exports,d,d.exports,a.relative(c))),d.exports}return a.modules={},a.resolve=function(b){var c=b,d=b+".js",e=b+"/index.js";return a.modules[d]&&d||a.modules[e]&&e||c},a.register=function(b,c){a.modules[b]=c},a.relative=function(b){return function(c){if("."!=c[0])return a(c);var d=b.split("/"),e=c.split("/");d.pop();for(var f=0;f=0;d--){var e=a[d];e=="."?a.splice(d,1):e===".."?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}var d=!1,f=/^([\s\S]+\/(?!$)|\/)?((?:[\s\S]+?)?(\.[^.]*)?)$/;b.normalize=function(a){var b=a.charAt(0)==="/",c=a.slice(-1)==="/";return a=e(a.split("/").filter(function(a){return!!a}),!b).join("/"),!a&&!b&&(a="."),a&&c&&(a+="/"),(b?"/":"")+a},b.join=function(){var a=Array.prototype.slice.call(arguments,0);return b.normalize(a.filter(function(a,b){return a&&typeof a=="string"}).join("/"))},b.relative=function(a,c){function d(a){var b=0;for(;b=0;c--)if(a[c]!=="")break;return b>c?[]:a.slice(b,c-b+1)}a=b.resolve(a).substr(1),c=b.resolve(c).substr(1);var e=d(a.split("/")),f=d(c.split("/")),g=Math.min(e.length,f.length),h=g;for(var i=0;i0?(100-e[c])*f/100:e[c]*(f/100)),e[c]+=f,e.rgba},(b.clone=function(b){return f.assertPresent(b,"expr"),b.clone()}).raw=!0,(b["add-property"]=function(b,c){f.assertType(b,"expression","name"),b=f.unwrap(b).first,f.assertString(b,"name"),f.assertType(c,"expression","expr");var d=new e.Property([b],c),g=this.closestBlock,h=g.nodes.length,i=g.nodes.slice(0,g.index),j=g.nodes.slice(g.index++,h);return i.push(d),g.nodes=i.concat(j),d}).raw=!0}),a.register("functions/image.js",function(a,b,c){var d=c("../utils"),e=c("../nodes"),f=a.exports=function(b,c){this.ctx=b,this.path=d.lookup(c,b.paths);if(!this.path)throw new Error("failed to locate file "+c)};f.prototype.open=function(){this.fd=fs.openSync(this.path,"r")},f.prototype.close=function(){this.fd&&fs.closeSync(this.fd)},f.prototype.type=function(){var a,b=new Buffer(4);return fs.readSync(this.fd,b,0,4,0),71==b[0]&&73==b[1]&&70==b[2]?a="gif":80==b[1]&&78==b[2]&&71==b[3]?a="png":255==b[0]&&216==b[1]&&(a="jpeg"),a},f.prototype.size=function(){function d(a){return a[1]<<8|a[0]}function e(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}var a,b,c=this.type();switch(c){case"jpeg":throw new Error("image-size() jpeg support not yet implemented");case"png":var f=new Buffer(8);fs.readSync(this.fd,f,0,8,16),a=e(f),b=e(f.slice(4,8));break;case"gif":var f=new Buffer(4);fs.readSync(this.fd,f,0,4,6),a=d(f),b=d(f.slice(2,4))}if("number"!=typeof a)throw new Error('failed to find width of "'+this.path+'"');if("number"!=typeof b)throw new Error('failed to find height of "'+this.path+'"');return[a,b]}}),a.register("functions/url.js",function(a,b,c){var d=c("../visitor/compiler"),e=c("../nodes"),f=c("../path").extname,g=c("../utils"),h={".gif":"image/gif",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".svg":"image/svg+xml"};a.exports=function(a){function i(a){var i=new d(a);i.isURL=!0;var a=a.nodes.map(function(a){return i.visit(a)}).join(""),a=parse(a),j=f(a.pathname),k=h[j],l=new e.Literal('url("'+a.href+'")'),m=c.concat(this.paths),n,o;return k?a.protocol?l:(found=g.lookup(a.pathname,m),found?(o=fs.readFileSync(found),o.length>b?l:new e.Literal('url("data:'+k+";base64,"+o.toString("base64")+'")')):l):l}a=a||{};var b=a.limit||3e4,c=a.paths||[];return i.raw=!0,i}}),a.register("lexer.js",function(a,b,c){var d=c("./token"),e=c("./nodes"),f=c("./errors"),g={and:"&&",or:"||",is:"==",isnt:"!=","is not":"!=",":=":"?="},h=["em","ex","px","mm","cm","in","pt","pc","deg","rad","grad","ms","s","Hz","kHz","rem","%"].join("|"),i=new RegExp("^(-)?(\\d+\\.\\d+|\\d+|\\.\\d+)("+h+")? *"),j=a.exports=function(b,c){c=c||{},this.str=b.replace(/\r\n?/g,"\n"),this.stash=[],this.indentStack=[],this.indentRe=null,this.lineno=1};j.prototype={inspect:function(){var a,b=this.str,c=[];while("eos"!=(a=this.next()).type)c.push(a.inspect());return this.str=b,this.prevIndents=0,c.concat(a.inspect()).join("\n")},lookahead:function(a){var b=a-this.stash.length;while(b-->0)this.stash.push(this.advance());return this.stash[--a]},skip:function(a){this.str=this.str.substr(Array.isArray(a)?a[0].length:a)},next:function(){var a=this.stashed()||this.advance();switch(a.type){case"newline":case"indent":++this.lineno;break;case"outdent":"outdent"!=this.prev.type&&++this.lineno}return this.prev=a,a.lineno=this.lineno,a},advance:function(){return this.eos()||this.nil()||this.sep()||this.keyword()||this.urlchars()||this.atrule()||this.scope()||this.media()||this.comment()||this.newline()||this.escaped()||this.important()||this.literal()||this.fun()||this.brace()||this.paren()||this.color()||this.string()||this.unit()||this.namedop()||this.boolean()||this.ident()||this.op()||this.space()||this.selector()},peek:function(){return this.lookahead(1)},stashed:function(){return this.stash.shift()},eos:function(){if(this.str.length)return;return this.indentStack.length?(this.indentStack.shift(),new d("outdent")):new d("eos")},urlchars:function(){var a;if(!this.isURL)return;if(a=/^[\/:@.;?&=*!,<>#%0-9]+/.exec(this.str))return this.skip(a),new d("literal",new e.Literal(a[0]))},sep:function(){var a;if(a=/^; */.exec(this.str))return this.skip(a),new d(";")},space:function(){var a;if(a=/^( +)/.exec(this.str))return this.skip(a),new d("space")},escaped:function(){var a;if(a=/^\\(.) */.exec(this.str)){var b=a[1];return this.skip(a),new d("ident",new e.Literal(b))}},literal:function(){var a;if(a=/^@css *\{/.exec(this.str)){this.skip(a);var b,c=1,f="";while(b=this.str[0]){this.str=this.str.substr(1);switch(b){case"{":++c;break;case"}":--c}f+=b;if(!c)break}return f=f.replace(/\s*}$/,""),new d("literal",new e.Literal(f))}},important:function(){var a;if(a=/^!important */.exec(this.str))return this.skip(a),new d("ident",new e.Literal("!important"))},brace:function(){var a;if(a=/^([{}])/.exec(this.str)){this.skip(1);var b=a[1];return new d(b,b)}},paren:function(){var a;if(a=/^([()]) */.exec(this.str)){var b=a[1];return this.skip(a),")"==b&&(this.isURL=!1),new d(b,b)}},nil:function(){var a;if(a=/^(null)\b */.exec(this.str))return this.skip(a),new d("null",e.nil)},keyword:function(){var a;if(a=/^(return|if|else|unless|for|in)\b */.exec(this.str)){var b=a[1];return this.skip(a),new d(b,b)}},namedop:function(){var a;if(a=/^(not|and|or|is a|is defined|isnt|is not|is)\b( *)/.exec(this.str)){var b=a[1];this.skip(a),b=g[b]||b;var c=new d(b,b);return c.space=a[2],c}},op:function(){var a;if(a=/^([.]{2,3}|&&|\|\||[!<>=?:]=|\*\*|[-+*\/%]=?|[,=?:!~<>&\[\]])( *)/.exec(this.str)){var b=a[1];this.skip(a),b=g[b]||b;var c=new d(b,b);return c.space=a[2],c}},media:function(){var a;if(a=/^@media *([^\/{\n]+)/.exec(this.str))return this.skip(a),new d("media",a[1].trim())},scope:function(){var a;if(a=/^@scope *([^\/{\n]+)/.exec(this.str))return this.skip(a),new d("scope",a[1].trim())},atrule:function(){var a;if(a=/^@(import|(?:-(\w+)-)?keyframes|charset|font-face|page) */.exec(this.str)){this.skip(a);var b=a[2],c=a[1];return b&&(c="keyframes"),new d(c,b)}},comment:function(){if("/"==this.str[0]&&"/"==this.str[1]){var a=this.str.indexOf("\n");return-1==a&&(a=this.str.length),this.skip(a),this.advance()}if("/"==this.str[0]&&"*"==this.str[1]){var a=this.str.indexOf("*/");-1==a&&(a=this.str.length);var b=this.str.substr(0,a+2),c=b.split("\n").length-1,f=!0;return this.lineno+=c,this.skip(a+2),"!"==b[2]&&(b=b.replace("*!","*"),f=!1),new d("comment",new e.Comment(b,f))}},"boolean":function(){var a;if(a=/^(true|false)\b( *)/.exec(this.str)){var b=e.Boolean("true"==a[1]);this.skip(a);var c=new d("boolean",b);return c.space=a[2],c}},fun:function(){var a;if(a=/^(-?[a-zA-Z$][-\w\d$]*)\(( *)/.exec(this.str)){var b=a[1];this.skip(a),this.isURL="url"==b;var c=new d("function",new e.Ident(b));return c.space=a[2],c}},ident:function(){var a;if(a=/^(@)?(-?[_a-zA-Z$][-\w\d$]*)/.exec(this.str)){var b=a[1],c=a[2],f=new e.Ident(c);return this.skip(a),f.property=!!b,new d("ident",f)}},newline:function(){var a,b;this.indentRe?a=this.indentRe.exec(this.str):(b=/^\n([\t]*) */,a=b.exec(this.str),a&&!a[1].length&&(b=/^\n( *)/,a=b.exec(this.str)),a&&a[1].length&&(this.indentRe=b));if(a){var c,e=a[1].length;this.skip(a);if(this.str[0]===" "||this.str[0]==="\t")throw new f.SyntaxError("Invalid indentation. You can use tabs or spaces to indent, but not both.");this.isVariable=!1;if("\n"==this.str[0])return++this.lineno,this.advance();if(this.indentStack.length&&ee)this.stash.push(new d("outdent")),this.indentStack.shift();c=this.stash.pop()}else e&&e!=this.indentStack[0]?(this.indentStack.unshift(e),c=new d("indent")):c=new d("newline");return c}},unit:function(){var a;if(a=i.exec(this.str)){this.skip(a);var b=parseFloat(a[2]);"-"==a[1]&&(b=-b);var c=new e.Unit(b,a[3]);return new d("unit",c)}},string:function(){var a;if(a=/^("[^"]*"|'[^']*') */.exec(this.str)){var b=a[1];return this.skip(a),b=b.slice(1,-1).replace(/\\n/g,"\n"),new d("string",new e.String(b))}},color:function(){return this.rrggbbaa()||this.rrggbb()||this.rgba()||this.rgb()},rgb:function(){var a;if(a=/^#([a-fA-F0-9]{3}) */.exec(this.str)){this.skip(a);var b=a[1],c=parseInt(b[0]+b[0],16),f=parseInt(b[1]+b[1],16),g=parseInt(b[2]+b[2],16),h=new e.RGBA(c,f,g,1);return h.raw=a[0],new d("color",h)}},rgba:function(){var a;if(a=/^#([a-fA-F0-9]{4}) */.exec(this.str)){this.skip(a);var b=a[1],c=parseInt(b[0]+b[0],16),f=parseInt(b[1]+b[1],16),g=parseInt(b[2]+b[2],16),h=parseInt(b[3]+b[3],16),i=new e.RGBA(c,f,g,h/255);return i.raw=a[0],new d("color",i)}},rrggbb:function(){var a;if(a=/^#([a-fA-F0-9]{6}) */.exec(this.str)){this.skip(a);var b=a[1],c=parseInt(b.substr(0,2),16),f=parseInt(b.substr(2,2),16),g=parseInt(b.substr(4,2),16),h=new e.RGBA(c,f,g,1);return h.raw=a[0],new d("color",h)}},rrggbbaa:function(){var a;if(a=/^#([a-fA-F0-9]{8}) */.exec(this.str)){this.skip(a);var b=a[1],c=parseInt(b.substr(0,2),16),f=parseInt(b.substr(2,2),16),g=parseInt(b.substr(4,2),16),h=parseInt(b.substr(6,2),16),i=new e.RGBA(c,f,g,h/255);return i.raw=a[0],new d("color",i)}},selector:function(){var a;if(a=/^[^{\n,]+/.exec(this.str)){var b=a[0];return this.skip(a),new d("selector",b)}}}}),a.register("nodes/arguments.js",function(a,b,c){var d=c("./node"),e=c("../nodes"),f=c("../utils"),g=a.exports=function(){e.Expression.call(this),this.map={}};g.prototype.__proto__=e.Expression.prototype,g.fromExpression=function(a){var b=new g,c=a.nodes.length;b.lineno=a.lineno,b.isList=a.isList;for(var d=0;di)g.nodes[b]=e.nil;g.nodes[a.val]=c}}),c;case"[]":var j=new e.Expression,k=f.unwrap(this).nodes,h=f.unwrap(b).nodes;return h.forEach(function(a){if("unit"==a.nodeName){var b=k[a.val];b&&j.push(b)}}),j.isEmpty?e.nil:f.unwrap(j);case"||":if(this.nodes.length>1)return this;var l=this.first.operate(a,b,c);return l==this.nodes[0]?this:b;case"in":return d.prototype.operate.call(this,a,b);case"!=":return this.operate("==",b,c).negate();case"==":var i=this.nodes.length,b=b.toExpression(),m,n;if(i!=b.nodes.length)return e.no;for(var o=0;o=0?a:360+a}function h(a){return Math.max(0,Math.min(a,100))}function i(a){return Math.max(0,Math.min(a,1))}var d=c("./node"),e=c("./index"),f=b=a.exports=function(b,c,e,f){d.call(this),this.h=g(b),this.s=h(c),this.l=h(e),this.a=i(f),this.hsla=this};f.prototype.__proto__=d.prototype,f.prototype.toString=function(){return"hsla("+this.h+","+this.s.toFixed(0)+","+this.l.toFixed(0)+","+this.a+")"},f.prototype.clone=function(){var a=new f(this.h,this.s,this.l,this.a);return a.lineno=this.lineno,a.filename=this.filename,a},f.prototype.__defineGetter__("rgba",function(){return e.RGBA.fromHSLA(this)}),f.prototype.__defineGetter__("hash",function(){return this.rgba.toString()}),f.prototype.add=function(a,b,c){return new f(this.h+a,this.s+b,this.l+c,this.a)},f.prototype.sub=function(a,b,c){return this.add(-a,-b,-c)},f.prototype.operate=function(a,b){switch(a){case"==":case"!=":case"<=":case">=":case"<":case">":case"is a":case"||":case"&&":return this.rgba.operate(a,b);default:return this.rgba.operate(a,b).hsla}},b.fromRGBA=function(a){var b=a.r/255,c=a.g/255,d=a.b/255,e=a.a,g=Math.min(b,c,d),h=Math.max(b,c,d),i=(h+g)/2,j=h-g,k,l;switch(h){case g:k=0;break;case b:k=60*(c-d)/j;break;case c:k=60*(d-b)/j+120;break;case d:k=60*(b-c)/j+240}return h==g?l=0:i<.5?l=j/(2*i):l=j/(2-2*i),k%=360,l*=100,i*=100,new f(k,l,i,e)},f.prototype.adjustLightness=function(a){return this.l=h(this.l+this.l*(a/100)),this},f.prototype.adjustHue=function(a){return this.h=g(this.h+a),this}}),a.register("nodes/ident.js",function(a,b,c){var d=c("./node"),e=c("./index"),f=a.exports=function(b,c){d.call(this),this.name=b,this.string=b,this.val=c||e.nil};f.prototype.__defineGetter__("isEmpty",function(){return undefined==this.val}),f.prototype.__defineGetter__("hash",function(){return this.name}),f.prototype.__proto__=d.prototype,f.prototype.clone=function(){var a=new f(this.name,this.val.clone());return a.lineno=this.lineno,a.filename=this.filename,a.property=this.property,a},f.prototype.toString=function(){return this.name},f.prototype.coerce=function(a){switch(a.nodeName){case"ident":case"string":case"literal":return new f(a.string);default:return d.prototype.coerce.call(this,a)}},f.prototype.operate=function(a,b){var c=b.first;switch(a){case"-":if("unit"==c.nodeName){var f=new e.Expression;return c.val=-c.val,f.push(this),f.push(c),f};case"+":return new e.Ident(this.string+this.coerce(c).string)}return d.prototype.operate.call(this,a,b)}}),a.register("nodes/if.js",function(a,b,c){var d=c("./node"),e=a.exports=function(b,c){d.call(this),this.cond=b,this.elses=[],c&&c.nodeName?this.block=c:this.negate=c};e.prototype.__proto__=d.prototype,e.prototype.clone=function(){var a=this.cond.clone(),b=this.block.clone(),c=new e(a,b);return c.elses=this.elses.map(function(a){return a.clone()}),c.negate=this.negate,c.lineno=this.lineno,c.filename=this.filename,c}}),a.register("nodes/import.js",function(a,b,c){var d=c("./node"),e=a.exports=function(b){d.call(this),this.path=b};e.prototype.__proto__=d.prototype}),a.register("nodes/index.js",function(a,b,c){b.Node=c("./node"),b.Root=c("./root"),b.Null=c("./null"),b.Each=c("./each"),b.If=c("./if"),b.Call=c("./call"),b.Page=c("./page"),b.FontFace=c("./fontface"),b.UnaryOp=c("./unaryop"),b.BinOp=c("./binop"),b.Ternary=c("./ternary"),b.Block=c("./block"),b.Unit=c("./unit"),b.String=c("./string"),b.HSLA=c("./hsla"),b.RGBA=c("./rgba"),b.Ident=c("./ident"),b.Group=c("./group"),b.Literal=c("./literal"),b.JSLiteral=c("./jsliteral"),b.Boolean=c("./boolean"),b.Return=c("./return"),b.Media=c("./media"),b.Params=c("./params"),b.Comment=c("./comment"),b.Keyframes=c("./keyframes"),b.Charset=c("./charset"),b.Import=c("./import"),b.Function=c("./function"),b.Property=c("./property"),b.Selector=c("./selector"),b.Expression=c("./expression"),b.Arguments=c("./arguments"),b.yes=new b.Boolean(!0),b.no=new b.Boolean(!1),b.nil=new b.Null}),a.register("nodes/jsliteral.js",function(a,b,c){var d=c("./node"),e=c("./index"),f=a.exports=function(b){d.call(this),this.val=b,this.string=b};f.prototype +.__proto__=d.prototype}),a.register("nodes/keyframes.js",function(a,b,c){var d=c("./node"),e=a.exports=function(b,c){d.call(this),this.name=b,this.frames=[],this.prefix=c||"official"};e.prototype.__proto__=d.prototype,e.prototype.push=function(a,b){this.frames.push({pos:a,block:b})},e.prototype.clone=function(){var a=new e(this.name);return a.lineno=this.lineno,a.prefix=this.prefix,a.frames=this.frames.map(function(a){return a.block=a.block.clone(),a}),a},e.prototype.toString=function(){return"@keyframes "+this.name}}),a.register("nodes/literal.js",function(a,b,c){var d=c("./node"),e=c("./index"),f=a.exports=function(b){d.call(this),this.val=b,this.string=b};f.prototype.__proto__=d.prototype,f.prototype.__defineGetter__("hash",function(){return this.val}),f.prototype.toString=function(){return this.val},f.prototype.coerce=function(a){switch(a.nodeName){case"ident":case"string":case"literal":return new f(a.string);default:return d.prototype.coerce.call(this,a)}},f.prototype.operate=function(a,b){var c=b.first;switch(a){case"+":return new e.Literal(this.string+this.coerce(c).string);default:return d.prototype.operate.call(this,a,b)}}}),a.register("nodes/media.js",function(a,b,c){var d=c("./node"),e=c("./index"),f=a.exports=function(b){d.call(this),this.val=b};f.prototype.__proto__=d.prototype,f.prototype.toString=function(){return"@media "+this.val}}),a.register("nodes/node.js",function(a,b,c){function h(a){this.name="CoercionError",this.message=a,Error.captureStackTrace(this,h)}var d=c("../visitor/evaluator"),e=c("../utils"),f=c("./index"),g=a.exports=function(){this.lineno=f.lineno,Object.defineProperty(this,"filename",{writable:!0,value:f.filename})};g.prototype.__defineGetter__("first",function(){return this}),g.prototype.__defineGetter__("hash",function(){return this.val}),g.prototype.__defineGetter__("nodeName",function(){return this.constructor.name.toLowerCase()}),g.prototype.clone=function(){return this},g.prototype.eval=function(){return(new d(this)).evaluate()},g.prototype.toBoolean=function(){return f.yes},g.prototype.toExpression=function(){if("expression"==this.nodeName)return this;var a=new f.Expression;return a.push(this),a},g.prototype.shouldCoerce=function(a){switch(a){case"is a":case"in":case"||":case"&&":return!1;default:return!0}},g.prototype.operate=function(a,b){switch(a){case"is a":if("string"==b.nodeName)return f.Boolean(this.nodeName==b.val);throw new Error('"is a" expects a string, got '+b.toString());case"==":return f.Boolean(this.hash==b.hash);case"!=":return f.Boolean(this.hash!=b.hash);case">=":return f.Boolean(this.hash>=b.hash);case"<=":return f.Boolean(this.hash<=b.hash);case">":return f.Boolean(this.hash>b.hash);case"<":return f.Boolean(this.hash1&&--a,a*6<1?g+(f-g)*a*6:a*2<1?f:a*3<2?g+(f-g)*(2/3-a)*6:g}var b=a.h/360,c=a.s/100,d=a.l/100,e=a.a,f=d<=.5?d*(c+1):d+c-d*c,g=d*2-f,h=l(b+1/3)*255,j=l(b)*255,k=l(b-1/3)*255;return new i(h,j,k,e)}}),a.register("nodes/root.js",function(a,b,c){var d=c("./node"),e=a.exports=function(){this.nodes=[]};e.prototype.__proto__=d.prototype,e.prototype.push=function(a){this.nodes.push(a)},e.prototype.toString=function(){return"[Root]"}}),a.register("nodes/selector.js",function(a,b,c){var d=c("./block"),e=c("./node"),f=a.exports=function(b){e.call(this),this.segments=b};f.prototype.__proto__=e.prototype,f.prototype.toString=function(){return this.segments.join("")},f.prototype.clone=function(){var a=new f;return a.lineno=this.lineno,a.filename=this.filename,a.segments=this.segments.map(function(a){return a.clone()}),a}}),a.register("nodes/string.js",function(a,b,c){var d=c("./node"),e=c("../functions").s,f=c("../utils"),g=c("./index"),h=a.exports=function(b){d.call(this),this.val=b,this.string=b};h.prototype.__proto__=d.prototype,h.prototype.toString=function(){return'"'+this.val+'"'},h.prototype.clone=function(){var a=new h(this.val);return a.lineno=this.lineno,a.filename=this.filename,a},h.prototype.toBoolean=function(){return g.Boolean(this.val.length)},h.prototype.coerce=function(a){switch(a.nodeName){case"string":return a;case"expression":return new h(a.nodes.map(function(a){return this.coerce(a).val},this).join(" "));default:return new h(a.toString())}},h.prototype.operate=function(a,b){switch(a){case"%":var c=new g.Expression;c.push(this);var i="expression"==b.nodeName?f.unwrap(b).nodes:[b];return e.apply(null,[c].concat(i));case"+":return new h(this.val+this.coerce(b).val);default:return d.prototype.operate.call(this,a,b)}}}),a.register("nodes/ternary.js",function(a,b,c){var d=c("./node"),e=a.exports=function(b,c,e){d.call(this),this.cond=b,this.trueExpr=c,this.falseExpr=e};e.prototype.__proto__=d.prototype,e.prototype.clone=function(){var a=new e(this.cond.clone(),this.trueExpr.clone(),this.falseExpr.clone());return a.lineno=this.lineno,a.filename=this.filename,a}}),a.register("nodes/unaryop.js",function(a,b,c){var d=c("./node"),e=a.exports=function(b,c){d.call(this),this.op=b,this.expr=c};e.prototype.__proto__=d.prototype,e.prototype.clone=function(){var a=new e(this.op,this.expr.clone());return a.lineno=this.lineno,a.filename=this.filename,a}}),a.register("nodes/unit.js",function(a,b,c){var d=c("./node"),e=c("./index"),f=a.exports=function(b,c){d.call(this),this.val=b,this.type=c};f.prototype.__proto__=d.prototype,f.prototype.toBoolean=function(){return e.Boolean(this.type?!0:this.val)},f.prototype.toString=function(){var a=this.val;return"px"==this.type&&(a=a.toFixed(0)),a+(this.type||"")},f.prototype.clone=function(){var a=new f(this.val,this.type);return a.lineno=this.lineno,a.filename=this.filename,a},f.prototype.operate=function(a,b){var c=this.type||b.type;if("rgba"==b.nodeName||"hsla"==b.nodeName)return b.operate(a,this);if(this.shouldCoerce(a)){"-"!=a&&"+"!=a||"%"!=b.type?b=this.coerce(b.first):b.val=this.val*(b.val/100);switch(a){case"-":return new f(this.val-b.val,c);case"+":return new f(this.val+b.val,c);case"/":return new f(this.val/b.val,c);case"*":return new f(this.val*b.val,c);case"%":return new f(this.val%b.val,c);case"**":return new f(Math.pow(this.val,b.val),c);case"..":case"...":var g=this.val,h=b.val,i=new e.Expression,j=".."==a;do i.push(new e.Unit(g));while(j?++g<=h:++g","=",":","&","~","{","}"],i=["root","nth-child","nth-last-child","nth-of-type","nth-last-of-type","first-child","last-child","first-of-type","last-of-type","only-child","only-of-type","empty","link","visited","active","hover","focus","target","lang","enabled","disabled","checked","not"],j=a.exports=function(b,c){var f=this;c=c||{},this.lexer=new d(b,c),this.root=c.root||new e.Root,this.state=["root"],this.stash=[],this.parens=0,this.state.pop=function(){f.prevState=[].pop.call(this)}};j.prototype={constructor:j,currentState:function(){return this.state[this.state.length-1]},parse:function(){var a=this.parent=this.root;while("eos"!=this.peek().type){if(this.accept("newline"))continue;var b=this.statement();this.accept(";"),b||this.error("unexpected token {peek}, not allowed at the root level"),a.push(b)}return a},error:function(a){var b=this.peek().type,c=undefined==this.peek().val?"":" "+this.peek().toString();throw c.trim()==b.trim()&&(c=""),new g.ParseError(a.replace("{peek}",'"'+b+c+'"'))},accept:function(a){if(a==this.peek().type)return this.next()},expect:function(a){return a!=this.peek().type&&this.error('expected "'+a+'", got {peek}'),this.next()},next:function(){var a=this.stash.length?this.stash.pop():this.lexer.next();return e.lineno=a.lineno,a},peek:function(){return this.lexer.peek()},lookahead:function(a){return this.lexer.lookahead(a)},isSelectorToken:function(a){var b=this.lookahead(a).type;switch(b){case"for":return this.bracketed;case"[":return this.bracketed=!0,!0;case"]":return this.bracketed=!1,!0;default:return~h.indexOf(b)}},isPseudoSelector:function(a){return~i.indexOf(this.lookahead(a).val.name)},lineContains:function(a){var b=1,c;while(c=this.lookahead(b++)){if(~["indent","outdent","newline"].indexOf(c.type))return;if(a==c.type)return!0}},selectorToken:function(){if(this.isSelectorToken(1)){if("{"==this.peek().type){if(!this.lineContains("}"))return;var a=0,b;while(b=this.lookahead(++a)){if("}"==b.type)break;if(":"==b.type)return}}return this.next()}},skipWhitespace:function(){while(~["space","indent","outdent","newline"].indexOf(this.peek().type))this.next()},skipSpaces:function(){while("space"==this.peek().type)this.next()},looksLikeFunctionDefinition:function(a){return"indent"==this.lookahead(a).type||"{"==this.lookahead(a).type},looksLikeSelector:function(){var a=1,b;while("ident"==this.lookahead(a).type&&"newline"==this.lookahead(a+1).type)a+=2;while(this.isSelectorToken(a)||","==this.lookahead(a).type){if("selector"==this.lookahead(a).type)return!0;"{"==this.lookahead(a).type?b=!0:"}"==this.lookahead(a).type&&(b=!1);if(b&&":"==this.lookahead(a).type)return!0;if("space"==this.lookahead(a).type&&"{"==this.lookahead(a+1).type)return!0;if(":"==this.lookahead(a++).type&&this.isPseudoSelector(a))return!0;if(","==this.lookahead(a).type&&"newline"==this.lookahead(a+1).type)return!0}if(","==this.lookahead(a).type&&"newline"==this.lookahead(a+1).type)return!0;if("{"==this.lookahead(a).type&&"newline"==this.lookahead(a+1).type)return!0;if(this.css)if(";"==this.lookahead(a)||"}"==this.lookahead(a))return!1;while(!~["indent","outdent","newline","for","if",";","}"].indexOf(this.lookahead(a).type))++a;if("indent"==this.lookahead(a).type)return!0},stateAllowsSelector:function(){switch(this.currentState()){case"root":case"selector":case"conditional":case"keyframe":case"function":case"font-face":case"media":case"for":return!0}},statement:function(){var a=this.stmt(),b=this.prevState,c,d;this.allowPostfix&&(delete this.allowPostfix,b="expression");switch(b){case"assignment":case"expression":case"function arguments":while(d=this.accept("if")||this.accept("unless")||this.accept("for"))switch(d.type){case"if":case"unless":a=new e.If(this.expression(),a),a.postfix=!0,a.negate="unless"==d.type,this.accept(";");break;case"for":var f,g=this.id().name;this.accept(",")&&(f=this.id().name),this.expect("in");var h=new e.Each(g,f,this.expression());c=new e.Block,c.push(a),h.block=c,a=h}}return a},stmt:function(){var a=this.peek().type;switch(a){case"-webkit-keyframes":case"keyframes":return this.keyframes();case"font-face":return this.fontface();case"comment":case"selector":case"literal":case"charset":case"media":case"page":case"ident":case"scope":case"unless":return this[a]();case"function":return this.fun();case"import":return this.atimport();case"if":return this.ifstmt();case"for":return this.forin();case"return":return this.ret();case"{":return this.property();default:if(this.stateAllowsSelector())switch(a){case"color":case"~":case"+":case">":case"<":case":":case"&":case"[":return this.selector();case"*":return this.property();case"-":if("{"==this.lookahead(2).type)return this.property()}var b=this.expression();return b.isEmpty&&this.error("unexpected {peek}"),b}},block:function(a,b){var c,d,f=this.css,g=this.parent=new e.Block(this.parent,a);!1===b&&(g.scope=!1),(this.css=this.accept("{"))?(c="}",this.skipWhitespace()):(c="outdent",this.expect("indent"));while(c!=this.peek().type){if(this.css){if(this.accept("newline"))continue;d=this.statement(),this.accept(";"),this.skipWhitespace()}else{if(this.accept("newline"))continue;d=this.statement(),this.accept(";")}d||this.error("unexpected token {peek} in block"),g.push(d)}return this.css?(this.skipWhitespace(),this.expect("}"),this.skipSpaces(),this.css=f):this.expect("outdent"),this.parent=g.parent,g},comment:function(){var a=this.next().val;return this.skipSpaces(),a},forin:function(){this.expect("for");var a,b=this.id().name;this.accept(",")&&(a=this.id().name),this.expect("in");var c=new e.Each(b,a,this.expression());return this.state.push("for"),c.block=this.block(c,!1),this.state.pop(),c},ret:function(){this.expect("return");var a=this.expression();return a.isEmpty?new e.Return:new e.Return(a)},unless:function(){this.expect("unless");var a=new e.If(this.expression(),!0);return this.state.push("conditional"),a.block=this.block(a,!1),this.state.pop(),a},ifstmt:function(){this.expect("if");var a=new e.If(this.expression());this.state.push("conditional"),a.block=this.block(a,!1);while(this.accept("else")){if(!this.accept("if")){a.elses.push(this.block(a,!1));break}var b=this.expression(),c=this.block(a,!1);a.elses.push(new e.If(b,c))}return this.state.pop(),a},scope:function(){var a=this.expect("scope").val;return this.selectorScope=a,e.nil},media:function(){var a=this.expect("media").val,b=new e.Media(a);return this.state.push("media"),b.block=this.block(b),this.state.pop(),b},fontface:function(){this.expect("font-face");var a=new e.FontFace;return this.state.push("font-face"),a.block=this.block(a),this.state.pop(),a},atimport:function(){return this.expect("import"),this.allowPostfix=!0,new e.Import(this.expression())},charset:function(){this.expect("charset");var a=this.expect("string").val;return this.allowPostfix=!0,new e.Charset(a)},page:function(){var a;this.expect("page");if(this.accept(":")){var b=this.expect("ident").val.name;a=new e.Literal(":"+b)}var c=new e.Page(a);return this.state.push("page"),c.block=this.block(c),this.state.pop(),c},keyframes:function(){var a,b=this.css,c=this.expect("keyframes"),d=new e.Keyframes(this.id(),c.val);(this.css=this.accept("{"))?this.skipWhitespace():this.expect("indent");while(a=this.accept("unit")||this.accept("ident")){if("ident"==a.type){this.accept("space");switch(a.val.name){case"from":a=new e.Unit(0,"%");break;case"to":a=new e.Unit(100,"%");break;default:this.error('"'+a.val.name+'" is invalid, use "from" or "to"')}}else a=a.val;this.state.push("keyframe");var f=this.block(d);d.push(a,f),this.state.pop(),this.css&&this.skipWhitespace()}return this.css?(this.skipWhitespace(),this.expect("}"),this.css=b):this.expect("outdent"),d},literal:function(){return this.expect("literal").val},id:function(){var a=this.expect("ident");return this.accept("space"),a.val},ident:function(){var a=2,b=this.lookahead(a).type;while("space"==b)b=this.lookahead(++a).type;switch(b){case"=":case"?=":case"-=":case"+=":case"*=":case"/=":case"%=":return this.assignment();case"[":if(this._ident==this.peek())return this.id();while("]"!=this.lookahead(a++).type&&"selector"!=this.lookahead(a).type);if("="==this.lookahead(a).type)return this._ident=this.peek(),this.expression();if(this.looksLikeSelector()&&this.stateAllowsSelector())return this.selector();case"-":case"+":case"/":case"*":case"%":case"**":case"and":case"or":case"&&":case"||":case">":case"<":case">=":case"<=":case"!=":case"==":case"?":case"in":case"is a":case"is defined":if(this._ident==this.peek())return this.id();this._ident=this.peek();switch(this.currentState()){case"for":case"selector":return this.property();case"root":case"media":case"font-face":return this.selector();default:return this.operand?this.id():this.expression()};default:switch(this.currentState()){case"root":return this.selector();case"for":case"page":case"media":case"font-face":case"selector":case"function":case"keyframe":case"conditional":return this.property();default:return this.id()}}},interpolate:function(){var a,b=[],c;c=this.accept("*"),c&&b.push(new e.Literal("*"));for(;;)if(this.accept("{"))this.state.push("interpolation"),b.push(this.expression()),this.expect("}"),this.state.pop();else if(a=this.accept("-"))b.push(new e.Literal("-"));else{if(!(a=this.accept("ident")))break;b.push(a.val)}return b.length||this.expect("ident"),b},property:function(){if(this.looksLikeSelector())return this.selector();var a=this.interpolate(),b=prop=new e.Property(a);return this.accept("space"),this.accept(":")&&this.accept("space"),this.state.push("property"),this.inProperty=!0,prop.expr=this.list(),prop.expr.isEmpty&&(b=a[0]),this.inProperty=!1,this.allowPostfix=!0,this.state.pop(),this.accept(";"),b},selector:function(){var a,b,c=new e.Group,d=this.selectorScope,f="root"==this.currentState();do{b=[],this.accept("newline");while(a=this.selectorToken())switch(a.type){case"{":this.skipSpaces();var g=this.expression();this.skipSpaces(),this.expect("}"),b.push(g);break;case"comment":b.push(new e.Literal(a.val.str));break;case"color":b.push(new e.Literal(a.val.raw));break;case"space":b.push(new e.Literal(" "));break;case"function":b.push(new e.Literal(a.val.name+"("));break;case"ident":b.push(new e.Literal(a.val.name));break;default:b.push(new e.Literal(a.val)),a.space&&b.push(new e.Literal(" "))}f&&d&&b.unshift(new e.Literal(d+" ")),c.push(new e.Selector(b))}while(this.accept(",")||this.accept("newline"));return this.lexer.allowComments=!1,this.state.push("selector"),c.block=this.block(c),this.state.pop(),c},assignment:function(){var a,b,c=this.id().name;if(a=this.accept("=")||this.accept("?=")||this.accept("+=")||this.accept("-=")||this.accept("*=")||this.accept("/=")||this.accept("%=")){this.state.push("assignment");var d=this.list();d.isEmpty&&this.error("invalid right-hand side operand in assignment, got {peek}"),b=new e.Ident(c,d),this.state.pop();switch(a.type){case"?=":var f=new e.BinOp("is defined",b),g=new e.Ident(c);b=new e.Ternary(f,g,b);break;case"+=":case"-=":case"*=":case"/=":case"%=":b.val=new e.BinOp(a.type[0],new e.Ident(c),d)}}return b},fun:function(){var a=1,b=2,c;a:while(c=this.lookahead(b++))switch(c.type){case"function":case"(":++a;break;case")":if(!--a)break a;break;case"eos":this.error('failed to find closing paren ")"')}switch(this.currentState()){case"expression":return this.functionCall();default:return this.looksLikeFunctionDefinition(b)?this.functionDefinition():this.expression()}},url:function(){this.expect("function"),this.state.push("function arguments");var a=this.args();return this.expect(")"),this.state.pop(),new e.Call("url",a)},functionCall:function(){if("url"==this.peek().val.name)return this.url();var a=this.expect("function").val.name;this.state.push("function arguments");var b=this.args();return this.expect(")"),this.state.pop(),new e.Call(a,b)},functionDefinition:function(){var a=this.expect("function").val.name;this.state.push("function params"),this.skipWhitespace();var b=this.params();this.skipWhitespace(),this.expect(")"),this.state.pop(),this.state.push("function");var c=new e.Function(a,b);return c.block=this.block(c),this.state.pop(),new e.Ident(a,c)},params:function(){var a,b,c=new e.Params;while(a=this.accept("ident"))this.accept("space"),c.push(b=a.val),this.accept("...")?b.rest=!0:this.accept("=")&&(b.val=this.expression()),this.skipWhitespace(),this.accept(","),this.skipWhitespace();return c},args:function(){var a=new e.Arguments,b;do"ident"==this.peek().type&&":"==this.lookahead(2).type?(b=this.next().val.string,this.expect(":"),a.map[b]=this.expression()):a.push(this.expression());while(this.accept(","));return a},list:function(){var a=this.expression();while(this.accept(","))if(a.isList)b.push(this.expression());else{var b=new e.Expression(!0);b.push(a),b.push(this.expression()),a=b}return a},expression:function(){var a,b=new e.Expression;this.state.push("expression");while(a=this.negation())a||this.error("unexpected token {peek} in expression"),b.push(a);return this.state.pop(),b},negation:function(){return this.accept("not")?new e.UnaryOp("!",this.negation()):this.ternary()},ternary:function(){var a=this.logical();if(this.accept("?")){var b=this.expression();this.expect(":");var c=this.expression();a=new e.Ternary(a,b,c)}return a},logical:function(){var a,b=this.typecheck();while(a=this.accept("&&")||this.accept("||"))b=new e.BinOp(a.type,b,this.typecheck());return b},typecheck:function(){var a,b=this.equality();while(a=this.accept("is a"))this.operand=!0,b||this.error('illegal unary "'+a+'", missing left-hand operand'),b=new e.BinOp(a.type,b,this.equality()),this.operand=!1;return b},equality:function(){var a,b=this.inop();while(a=this.accept("==")||this.accept("!="))this.operand=!0,b||this.error('illegal unary "'+a+'", missing left-hand operand'),b=new e.BinOp(a.type,b,this.inop()),this.operand=!1;return b},inop:function(){var a=this.relational();while(this.accept("in"))this.operand=!0,a||this.error('illegal unary "in", missing left-hand operand'),a=new e.BinOp("in",a,this.relational()),this.operand=!1;return a},relational:function(){var a,b=this.range();while(a=this.accept(">=")||this.accept("<=")||this.accept("<")||this.accept(">"))this.operand=!0,b||this.error('illegal unary "'+a+'", missing left-hand operand'),b=new e.BinOp(a.type,b,this.range()),this.operand=!1;return b},range:function(){var a,b=this.additive();if(a=this.accept("...")||this.accept(".."))this.operand=!0,b||this.error('illegal unary "'+a+'", missing left-hand operand'),b=new e.BinOp(a.val,b,this.additive()),this.operand=!1;return b},additive:function(){var a,b=this.multiplicative();while(a=this.accept("+")||this.accept("-"))this.operand=!0,b=new e.BinOp(a.type,b,this.multiplicative()),this.operand=!1;return b},multiplicative:function(){var a,b=this.defined();while(a=this.accept("**")||this.accept("*")||this.accept("/")||this.accept("%")){this.operand=!0;if("/"==a&&this.inProperty&&!this.parens)return this.stash.push(new f("literal",new e.Literal("/"))),this.operand=!1,b;b||this.error('illegal unary "'+a+'", missing left-hand operand'),b=new e.BinOp(a.type,b,this.defined()),this.operand=!1}return b},defined:function(){var a=this.unary();return this.accept("is defined")&&(a||this.error('illegal unary "is defined", missing left-hand operand'),a=new e.BinOp("is defined",a)),a},unary:function(){var a,b;return(a=this.accept("!")||this.accept("~")||this.accept("+")||this.accept("-"))?(this.operand=!0,b=new e.UnaryOp(a.type,this.unary()),this.operand=!1,b):this.subscript()},subscript:function(){var a=this.primary();while(this.accept("["))a=new e.BinOp("[]",a,this.expression()),this.expect("]"),this.accept("=")&&(a.op+="=",a.val=this.expression());return a},primary:function(){var a,b;if(this.accept("(")){++this.parens;var c=this.expression();return this.expect(")"),--this.parens,c}switch(this.peek().type){case"null":case"unit":case"color":case"string":case"literal":case"boolean":return this.next().val;case"ident":return this.ident();case"function":return this.functionCall()}}}}),a.register("renderer.js",function(a,b,c){var d=c("./parser"),e=c("./visitor/compiler"),f=c("./visitor/evaluator"),g=c("./utils"),h=c("./nodes"),i=c("./path"),j=i.join,k=a.exports=function(b,c){c=c||{},c.globals={},c.functions={},c.imports=[],c.paths=c.paths||[],c.filename=c.filename||"stylus",this.options=c,this.str=b};k.prototype.render=function(a){var b=this.parser=new d(this.str,this.options);try{h.filename=this.options.filename;var c=b.parse();this.evaluator=new f(c,this.options),c=this.evaluator.evaluate();var g=new e(c,this.options),i=g.compile(),j=g.js;a(null,i,j)}catch(k){a(k)}},k.prototype.set=function(a,b){return this.options[a]=b,this},k.prototype.get=function(a){return this.options[a]},k.prototype.include=function(a){return this.options.paths.push(a),this},k.prototype.use=function(a){return a.call(this,this),this},k.prototype.define=function(a,b,c){return b.nodeName?(this.options.globals[a]=b,this):(this.options.functions[a]=b,undefined!=c&&(b.raw=c),this)}}),a.register("stack/index.js",function(a,b,c){var d=c("./frame"),e=a.exports=function(){Array.apply(this,arguments)};e.prototype.__proto__=Array.prototype,e.prototype.push=function(a){return a.stack=this,a.parent=this.currentFrame,[].push.apply(this,arguments)},e.prototype.__defineGetter__("currentFrame",function(){return this[this.length-1]}),e.prototype.getBlockFrame=function(a){for(var b=0;b ":" ")+Array(j-d.toString().length+1).join(" ")+d+"| "+a}).join("\n");return a.message=d+":"+c+"\n"+f+"\n\n"+a.message+"\n"+(a.stylusStack?a.stylusStack+"\n":""),a},b.assertType=function(a,c,d){b.assertPresent(a,d);if(a.nodeName==c)return;var e=a.nodeName,f='expected "'+d+'" to be a '+c+", but got "+e+":"+a;throw new Error("TypeError: "+f)},b.assertString=function(a,c){b.assertPresent(a,c);switch(a.nodeName){case"string":case"ident":case"literal":return;default:var d=a.nodeName +,e="expected string, ident or literal, but got "+d+":"+a;throw new Error("TypeError: "+e)}},b.assertColor=function(a,c){b.assertPresent(a,c);switch(a.nodeName){case"rgba":case"hsla":return;default:var d=a.nodeName,e="expected rgba or hsla, but got "+d+":"+a;throw new Error("TypeError: "+e)}},b.assertPresent=function(a,b){if(a)return;throw b?new Error('"'+b+'" argument required'):new Error("argument missing")},b.unwrap=function(a){return a.preserve?a:"arguments"!=a.nodeName&&"expression"!=a.nodeName?a:1!=a.nodes.length?a:"arguments"!=a.nodes[0].nodeName&&"expression"!=a.nodes[0].nodeName?a:b.unwrap(a.nodes[0])},b.params=function(a){return a.toString().match(/\(([^)]*)\)/)[1].split(/ *, */)},b.merge=function(a,b){for(var c in b)a[c]=b[c];return a}}),a.register("visitor/index.js",function(a,b,c){var d=a.exports=function(b){this.root=b};d.prototype.visit=function(a,b){var c="visit"+a.constructor.name;return this[c]?this[c](a):a}}),a.register("visitor/compiler.js",function(a,b,c){var d=c("./index"),e=c("../nodes"),f=a.exports=function(b,c){c=c||{},this.compress=c.compress,this.firebug=c.firebug,this.linenos=c.linenos,this.indents=1,d.call(this,b),this.tree=[],this.js=""};f.prototype.__proto__=d.prototype,f.prototype.compile=function(){return this.visit(this.root)},f.prototype.__defineGetter__("indent",function(){return this.compress?"":(new Array(this.indents)).join(" ")}),f.prototype.visitRoot=function(a){this.buf="";for(var b=0,c=a.nodes.length;b-1)return c.toString().replace("0.",".")+b}return c.toString()+b},f.prototype.visitGroup=function(a){function h(a,c){c?a[c].forEach(function(b){g.unshift(b),h(a,c-1),g.shift()}):a[0].forEach(function(a){var c=a.trim();if(g.length)for(var d=0,e=g.length;d200)throw new RangeError("Maximum call stack size exceeded");"expression"==b.nodeName&&(b=b.first);var d=this.ret;this.ret=!0;var e=this.visit(a.args);for(var f in a.args.map)a.args.map[f]=this.visit(a.args.map[f]);return this.ret=d,b.fn?c=this.invokeBuiltin(b.fn,e):"function"==b.nodeName&&(c=this.invokeFunction(b,e)),this.calling.pop(),this.ignoreColors=!1,c},n.prototype.visitIdent=function(a){var b;if(a.property)return(b=this.lookupProperty(a.name))?this.visit(b.expr.clone()):e.nil;if(a.val.isNull){var c=this.lookup(a.name);return c?this.visit(c):a}var d=this.ret;return this.ret=!0,a.val=this.visit(a.val),this.ret=d,this.currentScope.add(a),a.val},n.prototype.visitBinOp=function(a){if("is defined"==a.op)return this.isDefined(a.left);var b=this.ret;this.ret=!0;var c=a.op,d=this.visit(a.left),f=this.visit(a.right);this.ret=b;var g=a.val?this.visit(a.val):null;try{return this.visit(d.operate(c,f,g))}catch(h){if("CoercionError"==h.name)switch(c){case"==":return e.no;case"!=":return e.yes}throw h}},n.prototype.visitUnaryOp=function(a){var b=a.op,c=this.visit(a.expr);"!"!=b&&(c=c.first.clone(),i.assertType(c,"unit"));switch(b){case"-":c.val=-c.val;break;case"+":c.val=+c.val;break;case"~":c.val=~c.val;break;case"!":return c.toBoolean().negate()}return c},n.prototype.visitTernary=function(a){var b=this.visit(a.cond).toBoolean();return b.isTrue?this.visit(a.trueExpr):this.visit(a.falseExpr)},n.prototype.visitExpression=function(a){for(var b=0,c=a.nodes.length;b