uses heather arthurs excellent color.js library. look in your console for the CSS you can use to override ratchet with these styles
Created
November 8, 2012 19:03
-
-
Save max-mapper/4040799 to your computer and use it in GitHub Desktop.
ratchet color schemer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var require = function (file, cwd) { | |
var resolved = require.resolve(file, cwd || '/'); | |
var mod = require.modules[resolved]; | |
if (!mod) throw new Error( | |
'Failed to resolve module ' + file + ', tried ' + resolved | |
); | |
var cached = require.cache[resolved]; | |
var res = cached? cached.exports : mod(); | |
return res; | |
}; | |
require.paths = []; | |
require.modules = {}; | |
require.cache = {}; | |
require.extensions = [".js",".coffee"]; | |
require._core = { | |
'assert': true, | |
'events': true, | |
'fs': true, | |
'path': true, | |
'vm': true | |
}; | |
require.resolve = (function () { | |
return function (x, cwd) { | |
if (!cwd) cwd = '/'; | |
if (require._core[x]) return x; | |
var path = require.modules.path(); | |
cwd = path.resolve('/', cwd); | |
var y = cwd || '/'; | |
if (x.match(/^(?:\.\.?\/|\/)/)) { | |
var m = loadAsFileSync(path.resolve(y, x)) | |
|| loadAsDirectorySync(path.resolve(y, x)); | |
if (m) return m; | |
} | |
var n = loadNodeModulesSync(x, y); | |
if (n) return n; | |
throw new Error("Cannot find module '" + x + "'"); | |
function loadAsFileSync (x) { | |
x = path.normalize(x); | |
if (require.modules[x]) { | |
return x; | |
} | |
for (var i = 0; i < require.extensions.length; i++) { | |
var ext = require.extensions[i]; | |
if (require.modules[x + ext]) return x + ext; | |
} | |
} | |
function loadAsDirectorySync (x) { | |
x = x.replace(/\/+$/, ''); | |
var pkgfile = path.normalize(x + '/package.json'); | |
if (require.modules[pkgfile]) { | |
var pkg = require.modules[pkgfile](); | |
var b = pkg.browserify; | |
if (typeof b === 'object' && b.main) { | |
var m = loadAsFileSync(path.resolve(x, b.main)); | |
if (m) return m; | |
} | |
else if (typeof b === 'string') { | |
var m = loadAsFileSync(path.resolve(x, b)); | |
if (m) return m; | |
} | |
else if (pkg.main) { | |
var m = loadAsFileSync(path.resolve(x, pkg.main)); | |
if (m) return m; | |
} | |
} | |
return loadAsFileSync(x + '/index'); | |
} | |
function loadNodeModulesSync (x, start) { | |
var dirs = nodeModulesPathsSync(start); | |
for (var i = 0; i < dirs.length; i++) { | |
var dir = dirs[i]; | |
var m = loadAsFileSync(dir + '/' + x); | |
if (m) return m; | |
var n = loadAsDirectorySync(dir + '/' + x); | |
if (n) return n; | |
} | |
var m = loadAsFileSync(x); | |
if (m) return m; | |
} | |
function nodeModulesPathsSync (start) { | |
var parts; | |
if (start === '/') parts = [ '' ]; | |
else parts = path.normalize(start).split('/'); | |
var dirs = []; | |
for (var i = parts.length - 1; i >= 0; i--) { | |
if (parts[i] === 'node_modules') continue; | |
var dir = parts.slice(0, i + 1).join('/') + '/node_modules'; | |
dirs.push(dir); | |
} | |
return dirs; | |
} | |
}; | |
})(); | |
require.alias = function (from, to) { | |
var path = require.modules.path(); | |
var res = null; | |
try { | |
res = require.resolve(from + '/package.json', '/'); | |
} | |
catch (err) { | |
res = require.resolve(from, '/'); | |
} | |
var basedir = path.dirname(res); | |
var keys = (Object.keys || function (obj) { | |
var res = []; | |
for (var key in obj) res.push(key); | |
return res; | |
})(require.modules); | |
for (var i = 0; i < keys.length; i++) { | |
var key = keys[i]; | |
if (key.slice(0, basedir.length + 1) === basedir + '/') { | |
var f = key.slice(basedir.length); | |
require.modules[to + f] = require.modules[basedir + f]; | |
} | |
else if (key === basedir) { | |
require.modules[to] = require.modules[basedir]; | |
} | |
} | |
}; | |
(function () { | |
var process = {}; | |
require.define = function (filename, fn) { | |
if (require.modules.__browserify_process) { | |
process = require.modules.__browserify_process(); | |
} | |
var dirname = require._core[filename] | |
? '' | |
: require.modules.path().dirname(filename) | |
; | |
var require_ = function (file) { | |
var requiredModule = require(file, dirname); | |
var cached = require.cache[require.resolve(file, dirname)]; | |
if (cached.parent === null) { | |
cached.parent = module_; | |
} | |
return requiredModule; | |
}; | |
require_.resolve = function (name) { | |
return require.resolve(name, dirname); | |
}; | |
require_.modules = require.modules; | |
require_.define = require.define; | |
require_.cache = require.cache; | |
var module_ = { | |
id : filename, | |
filename: filename, | |
exports : {}, | |
loaded : false, | |
parent: null | |
}; | |
require.modules[filename] = function () { | |
require.cache[filename] = module_; | |
fn.call( | |
module_.exports, | |
require_, | |
module_, | |
module_.exports, | |
dirname, | |
filename, | |
process | |
); | |
module_.loaded = true; | |
return module_.exports; | |
}; | |
}; | |
})(); | |
require.define("path",function(require,module,exports,__dirname,__filename,process){function filter (xs, fn) { | |
var res = []; | |
for (var i = 0; i < xs.length; i++) { | |
if (fn(xs[i], i, xs)) res.push(xs[i]); | |
} | |
return res; | |
} | |
// 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; 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 = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/; | |
// path.resolve([from ...], to) | |
// posix version | |
exports.resolve = function() { | |
var resolvedPath = '', | |
resolvedAbsolute = false; | |
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) { | |
var path = (i >= 0) | |
? arguments[i] | |
: process.cwd(); | |
// Skip empty and invalid entries | |
if (typeof path !== 'string' || !path) { | |
continue; | |
} | |
resolvedPath = path + '/' + resolvedPath; | |
resolvedAbsolute = path.charAt(0) === '/'; | |
} | |
// At this point the path should be resolved to a full absolute path, but | |
// handle relative paths to be safe (might happen when process.cwd() fails) | |
// Normalize the path | |
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { | |
return !!p; | |
}), !resolvedAbsolute).join('/'); | |
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; | |
}; | |
// path.normalize(path) | |
// posix version | |
exports.normalize = function(path) { | |
var isAbsolute = path.charAt(0) === '/', | |
trailingSlash = path.slice(-1) === '/'; | |
// Normalize the path | |
path = normalizeArray(filter(path.split('/'), 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(filter(paths, function(p, index) { | |
return p && typeof p === 'string'; | |
}).join('/')); | |
}; | |
exports.dirname = function(path) { | |
var dir = splitPathRe.exec(path)[1] || ''; | |
var isWindows = false; | |
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] || ''; | |
}; | |
}); | |
require.define("__browserify_process",function(require,module,exports,__dirname,__filename,process){var process = module.exports = {}; | |
process.nextTick = (function () { | |
var queue = []; | |
var canPost = typeof window !== 'undefined' | |
&& window.postMessage && window.addEventListener | |
; | |
if (canPost) { | |
window.addEventListener('message', function (ev) { | |
if (ev.source === window && ev.data === 'browserify-tick') { | |
ev.stopPropagation(); | |
if (queue.length > 0) { | |
var fn = queue.shift(); | |
fn(); | |
} | |
} | |
}, true); | |
} | |
return function (fn) { | |
if (canPost) { | |
queue.push(fn); | |
window.postMessage('browserify-tick', '*'); | |
} | |
else setTimeout(fn, 0); | |
}; | |
})(); | |
process.title = 'browser'; | |
process.browser = true; | |
process.env = {}; | |
process.argv = []; | |
process.binding = function (name) { | |
if (name === 'evals') return (require)('vm') | |
else throw new Error('No such module. (Possibly not yet loaded)') | |
}; | |
(function () { | |
var cwd = '/'; | |
var path; | |
process.cwd = function () { return cwd }; | |
process.chdir = function (dir) { | |
if (!path) path = require('path'); | |
cwd = path.resolve(dir, cwd); | |
}; | |
})(); | |
}); | |
require.define("/node_modules/ratchet-color/package.json",function(require,module,exports,__dirname,__filename,process){module.exports = {}}); | |
require.define("ratchet-color",function(require,module,exports,__dirname,__filename,process){var Color = require('color') | |
var colorConvert = require('color-convert') | |
module.exports = function calculateColorScheme(baseColor) { | |
if (baseColor[0] !== "#") baseColor = "#" + baseColor | |
var rgb = Color(baseColor).rgb() | |
var baseHSL = colorConvert.rgb2hslRaw([rgb.r, rgb.g, rgb.b]) | |
var hslOffsets = [ | |
[2, 6, -5], // bottom of header gradient | |
[4, 8, -13], // bottom of button gradient | |
[10, 4, -33], // border color | |
[3, 13, -14] // :active button background | |
] | |
var scheme = hslOffsets.map(function(hsl) { | |
var newHSL = {h: baseHSL[0] + hsl[0], s: baseHSL[1] + hsl[1], l: baseHSL[2] + hsl[2]} | |
return Color(newHSL).hexString() | |
}) | |
scheme.unshift(baseColor) | |
return scheme | |
} | |
}); | |
require.define("/node_modules/color/package.json",function(require,module,exports,__dirname,__filename,process){module.exports = {"main":"./color"}}); | |
require.define("/node_modules/color/color.js",function(require,module,exports,__dirname,__filename,process){/* MIT license */ | |
var convert = require("color-convert"), | |
string = require("color-string"); | |
module.exports = function(cssString) { | |
return new Color(cssString); | |
}; | |
var Color = function(cssString) { | |
this.values = { | |
rgb: [0, 0, 0], | |
hsl: [0, 0, 0], | |
hsv: [0, 0, 0], | |
cmyk: [0, 0, 0, 0], | |
alpha: 1 | |
} | |
// parse Color() argument | |
if (typeof cssString == "string") { | |
var vals = string.getRgba(cssString); | |
if (vals) { | |
this.setValues("rgb", vals); | |
} | |
else if(vals = string.getHsla(cssString)) { | |
this.setValues("hsl", vals); | |
} | |
} | |
else if (typeof cssString == "object") { | |
var vals = cssString; | |
if(vals["r"] !== undefined || vals["red"] !== undefined) { | |
this.setValues("rgb", vals) | |
} | |
else if(vals["l"] !== undefined || vals["lightness"] !== undefined) { | |
this.setValues("hsl", vals) | |
} | |
else if(vals["v"] !== undefined || vals["value"] !== undefined) { | |
this.setValues("hsv", vals) | |
} | |
else if(vals["c"] !== undefined || vals["cyan"] !== undefined) { | |
this.setValues("cmyk", vals) | |
} | |
} | |
} | |
Color.prototype = { | |
rgb: function (vals) { | |
return this.setSpace("rgb", arguments); | |
}, | |
hsl: function(vals) { | |
return this.setSpace("hsl", arguments); | |
}, | |
hsv: function(vals) { | |
return this.setSpace("hsv", arguments); | |
}, | |
cmyk: function(vals) { | |
return this.setSpace("cmyk", arguments); | |
}, | |
rgbArray: function() { | |
return this.values.rgb; | |
}, | |
hslArray: function() { | |
return this.values.hsl; | |
}, | |
hsvArray: function() { | |
return this.values.hsv; | |
}, | |
cmykArray: function() { | |
return this.values.cmyk; | |
}, | |
rgbaArray: function() { | |
var rgb = this.values.rgb; | |
rgb.push(this.values.alpha); | |
return rgb; | |
}, | |
hslaArray: function() { | |
var hsl = this.values.hsl; | |
hsl.push(this.values.alpha); | |
return hsl; | |
}, | |
alpha: function(val) { | |
if (val === undefined) { | |
return this.values.alpha; | |
} | |
this.setValues("alpha", val); | |
return this; | |
}, | |
red: function(val) { | |
return this.setChannel("rgb", 0, val); | |
}, | |
green: function(val) { | |
return this.setChannel("rgb", 1, val); | |
}, | |
blue: function(val) { | |
return this.setChannel("rgb", 2, val); | |
}, | |
hue: function(val) { | |
return this.setChannel("hsl", 0, val); | |
}, | |
saturation: function(val) { | |
return this.setChannel("hsl", 1, val); | |
}, | |
lightness: function(val) { | |
return this.setChannel("hsl", 2, val); | |
}, | |
saturationv: function(val) { | |
return this.setChannel("hsv", 1, val); | |
}, | |
value: function(val) { | |
return this.setChannel("hsv", 2, val); | |
}, | |
cyan: function(val) { | |
return this.setChannel("cmyk", 0, val); | |
}, | |
magenta: function(val) { | |
return this.setChannel("cmyk", 1, val); | |
}, | |
yellow: function(val) { | |
return this.setChannel("cmyk", 2, val); | |
}, | |
black: function(val) { | |
return this.setChannel("cmyk", 3, val); | |
}, | |
hexString: function() { | |
return string.hexString(this.values.rgb); | |
}, | |
rgbString: function() { | |
return string.rgbString(this.values.rgb, this.values.alpha); | |
}, | |
rgbaString: function() { | |
return string.rgbaString(this.values.rgb, this.values.alpha); | |
}, | |
percentString: function() { | |
return string.percentString(this.values.rgb, this.values.alpha); | |
}, | |
hslString: function() { | |
return string.hslString(this.values.hsl, this.values.alpha); | |
}, | |
hslaString: function() { | |
return string.hslaString(this.values.hsl, this.values.alpha); | |
}, | |
keyword: function() { | |
return string.keyword(this.values.rgb, this.values.alpha); | |
}, | |
luminosity: function() { | |
// http://www.w3.org/TR/WCAG20/#relativeluminancedef | |
var rgb = this.values.rgb; | |
for (var i = 0; i < rgb.length; i++) { | |
var chan = rgb[i] / 255; | |
rgb[i] = (chan <= 0.03928) ? chan / 12.92 | |
: Math.pow(((chan + 0.055) / 1.055), 2.4) | |
} | |
return 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]; | |
}, | |
contrast: function(color2) { | |
// http://www.w3.org/TR/WCAG20/#contrast-ratiodef | |
var lum1 = this.luminosity(); | |
var lum2 = color2.luminosity(); | |
if (lum1 > lum2) { | |
return (lum1 + 0.05) / (lum2 + 0.05) | |
}; | |
return (lum2 + 0.05) / (lum1 + 0.05); | |
}, | |
dark: function() { | |
// YIQ equation from http://24ways.org/2010/calculating-color-contrast | |
var rgb = this.values.rgb, | |
yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000; | |
return yiq < 128; | |
}, | |
light: function() { | |
return !this.dark(); | |
}, | |
negate: function() { | |
var rgb = [] | |
for (var i = 0; i < 3; i++) { | |
rgb[i] = 255 - this.values.rgb[i]; | |
} | |
this.setValues("rgb", rgb); | |
return this; | |
}, | |
lighten: function(ratio) { | |
this.values.hsl[2] += this.values.hsl[2] * ratio; | |
this.setValues("hsl", this.values.hsl); | |
return this; | |
}, | |
darken: function(ratio) { | |
this.values.hsl[2] -= this.values.hsl[2] * ratio; | |
this.setValues("hsl", this.values.hsl); | |
return this; | |
}, | |
saturate: function(ratio) { | |
this.values.hsl[1] += this.values.hsl[1] * ratio; | |
this.setValues("hsl", this.values.hsl); | |
return this; | |
}, | |
desaturate: function(ratio) { | |
this.values.hsl[1] -= this.values.hsl[1] * ratio; | |
this.setValues("hsl", this.values.hsl); | |
return this; | |
}, | |
greyscale: function() { | |
var rgb = this.values.rgb; | |
// http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale | |
var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11; | |
this.setValues("rgb", [val, val, val]); | |
return this; | |
}, | |
clearer: function(ratio) { | |
this.setValues("alpha", this.values.alpha - (this.values.alpha * ratio)); | |
return this; | |
}, | |
opaquer: function(ratio) { | |
this.setValues("alpha", this.values.alpha + (this.values.alpha * ratio)); | |
return this; | |
}, | |
rotate: function(degrees) { | |
var hue = this.values.hsl[0]; | |
hue = (hue + degrees) % 360; | |
hue = hue < 0 ? 360 + hue : hue; | |
this.values.hsl[0] = hue; | |
this.setValues("hsl", this.values.hsl); | |
return this; | |
}, | |
mix: function(color2, weight) { | |
weight = 1 - (weight || 0.5); | |
// algorithm from Sass's mix(). Ratio of first color in mix is | |
// determined by the alphas of both colors and the weight | |
var t1 = weight * 2 - 1, | |
d = this.alpha() - color2.alpha(); | |
var weight1 = (((t1 * d == -1) ? t1 : (t1 + d) / (1 + t1 * d)) + 1) / 2; | |
var weight2 = 1 - weight1; | |
var rgb = this.rgbArray(); | |
var rgb2 = color2.rgbArray(); | |
for (var i = 0; i < rgb.length; i++) { | |
rgb[i] = rgb[i] * weight1 + rgb2[i] * weight2; | |
} | |
this.setValues("rgb", rgb); | |
var alpha = this.alpha() * weight + color2.alpha() * (1 - weight); | |
this.setValues("alpha", alpha); | |
return this; | |
}, | |
toJSON: function() { | |
return this.rgb(); | |
} | |
} | |
Color.prototype.getValues = function(space) { | |
var vals = {}; | |
for (var i = 0; i < space.length; i++) { | |
vals[space[i]] = this.values[space][i]; | |
} | |
if (this.values.alpha != 1) { | |
vals["a"] = this.values.alpha; | |
} | |
// {r: 255, g: 255, b: 255, a: 0.4} | |
return vals; | |
} | |
Color.prototype.setValues = function(space, vals) { | |
var spaces = { | |
"rgb": ["red", "green", "blue"], | |
"hsl": ["hue", "saturation", "lightness"], | |
"hsv": ["hue", "saturation", "value"], | |
"cmyk": ["cyan", "magenta", "yellow", "black"] | |
}; | |
var maxes = { | |
"rgb": [255, 255, 255], | |
"hsl": [360, 100, 100], | |
"hsv": [360, 100, 100], | |
"cmyk": [100, 100, 100, 100], | |
}; | |
var alpha = 1; | |
if (space == "alpha") { | |
alpha = vals; | |
} | |
else if (vals.length) { | |
// [10, 10, 10] | |
this.values[space] = vals.slice(0, space.length); | |
alpha = vals[space.length]; | |
} | |
else if (vals[space[0]] !== undefined) { | |
// {r: 10, g: 10, b: 10} | |
for (var i = 0; i < space.length; i++) { | |
this.values[space][i] = vals[space[i]]; | |
} | |
alpha = vals.a; | |
} | |
else if (vals[spaces[space][0]] !== undefined) { | |
// {red: 10, green: 10, blue: 10} | |
var chans = spaces[space]; | |
for (var i = 0; i < space.length; i++) { | |
this.values[space][i] = vals[chans[i]]; | |
} | |
alpha = vals.alpha; | |
} | |
this.values.alpha = Math.max(0, Math.min(1, alpha || this.values.alpha)); | |
if (space == "alpha") { | |
return; | |
} | |
// convert to all the other color spaces | |
for (var sname in spaces) { | |
if (sname != space) { | |
this.values[sname] = convert[space][sname](this.values[space]) | |
} | |
// cap values | |
for (var i = 0; i < sname.length; i++) { | |
var capped = Math.max(0, Math.min(maxes[sname][i], this.values[sname][i])); | |
this.values[sname][i] = Math.round(capped); | |
} | |
} | |
return true; | |
} | |
Color.prototype.setSpace = function(space, args) { | |
var vals = args[0]; | |
if (vals === undefined) { | |
// color.rgb() | |
return this.getValues(space); | |
} | |
// color.rgb(10, 10, 10) | |
if (typeof vals == "number") { | |
vals = Array.prototype.slice.call(args); | |
} | |
this.setValues(space, vals); | |
return this; | |
} | |
Color.prototype.setChannel = function(space, index, val) { | |
if (val === undefined) { | |
// color.red() | |
return this.values[space][index]; | |
} | |
// color.red(100) | |
this.values[space][index] = val; | |
this.setValues(space, this.values[space]); | |
return this; | |
} | |
}); | |
require.define("/node_modules/color/node_modules/color-convert/package.json",function(require,module,exports,__dirname,__filename,process){module.exports = {"main":"./index"}}); | |
require.define("/node_modules/color/node_modules/color-convert/index.js",function(require,module,exports,__dirname,__filename,process){var conversions = require("./conversions"); | |
var exports = {}; | |
module.exports = exports; | |
for (var func in conversions) { | |
// export rgb2hslRaw | |
exports[func + "Raw"] = (function(func) { | |
// accept array or plain args | |
return function(arg) { | |
if (typeof arg == "number") | |
arg = Array.prototype.slice.call(arguments); | |
return conversions[func](arg); | |
} | |
})(func); | |
var pair = /(\w+)2(\w+)/.exec(func), | |
from = pair[1], | |
to = pair[2]; | |
// export rgb2hsl and ["rgb"]["hsl"] | |
exports[from] = exports[from] || {}; | |
exports[from][to] = exports[func] = (function(func) { | |
return function(arg) { | |
if (typeof arg == "number") | |
arg = Array.prototype.slice.call(arguments); | |
var val = conversions[func](arg); | |
if (typeof val == "string" || val === undefined) | |
return val; // keyword | |
for (var i = 0; i < val.length; i++) | |
val[i] = Math.round(val[i]); | |
return val; | |
} | |
})(func); | |
}}); | |
require.define("/node_modules/color/node_modules/color-convert/conversions.js",function(require,module,exports,__dirname,__filename,process){/* MIT license */ | |
module.exports = { | |
rgb2hsl: rgb2hsl, | |
rgb2hsv: rgb2hsv, | |
rgb2cmyk: rgb2cmyk, | |
rgb2keyword: rgb2keyword, | |
rgb2xyz: rgb2xyz, | |
rgb2lab: rgb2lab, | |
hsl2rgb: hsl2rgb, | |
hsl2hsv: hsl2hsv, | |
hsl2cmyk: hsl2cmyk, | |
hsl2keyword: hsl2keyword, | |
hsv2rgb: hsv2rgb, | |
hsv2hsl: hsv2hsl, | |
hsv2cmyk: hsv2cmyk, | |
hsv2keyword: hsv2keyword, | |
cmyk2rgb: cmyk2rgb, | |
cmyk2hsl: cmyk2hsl, | |
cmyk2hsv: cmyk2hsv, | |
cmyk2keyword: cmyk2keyword, | |
keyword2rgb: keyword2rgb, | |
keyword2hsl: keyword2hsl, | |
keyword2hsv: keyword2hsv, | |
keyword2cmyk: keyword2cmyk, | |
xyz2rgb: xyz2rgb, | |
} | |
function rgb2hsl(rgb) { | |
var r = rgb[0]/255, | |
g = rgb[1]/255, | |
b = rgb[2]/255, | |
min = Math.min(r, g, b), | |
max = Math.max(r, g, b), | |
delta = max - min, | |
h, s, l; | |
if (max == min) | |
h = 0; | |
else if (r == max) | |
h = (g - b) / delta; | |
else if (g == max) | |
h = 2 + (b - r) / delta; | |
else if (b == max) | |
h = 4 + (r - g)/ delta; | |
h = Math.min(h * 60, 360); | |
if (h < 0) | |
h += 360; | |
l = (min + max) / 2; | |
if (max == min) | |
s = 0; | |
else if (l <= 0.5) | |
s = delta / (max + min); | |
else | |
s = delta / (2 - max - min); | |
return [h, s * 100, l * 100]; | |
} | |
function rgb2hsv(rgb) { | |
var r = rgb[0], | |
g = rgb[1], | |
b = rgb[2], | |
min = Math.min(r, g, b), | |
max = Math.max(r, g, b), | |
delta = max - min, | |
h, s, v; | |
if (max == 0) | |
s = 0; | |
else | |
s = (delta/max * 1000)/10; | |
if (max == min) | |
h = 0; | |
else if (r == max) | |
h = (g - b) / delta; | |
else if (g == max) | |
h = 2 + (b - r) / delta; | |
else if (b == max) | |
h = 4 + (r - g) / delta; | |
h = Math.min(h * 60, 360); | |
if (h < 0) | |
h += 360; | |
v = ((max / 255) * 1000) / 10; | |
return [h, s, v]; | |
} | |
function rgb2cmyk(rgb) { | |
var r = rgb[0] / 255, | |
g = rgb[1] / 255, | |
b = rgb[2] / 255, | |
c, m, y, k; | |
k = Math.min(1 - r, 1 - g, 1 - b); | |
c = (1 - r - k) / (1 - k); | |
m = (1 - g - k) / (1 - k); | |
y = (1 - b - k) / (1 - k); | |
return [c * 100, m * 100, y * 100, k * 100]; | |
} | |
function rgb2keyword(rgb) { | |
return reverseKeywords[JSON.stringify(rgb)]; | |
} | |
function rgb2xyz(rgb) { | |
var r = rgb[0] / 255, | |
g = rgb[1] / 255, | |
b = rgb[2] / 255; | |
// assume sRGB | |
r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92); | |
g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92); | |
b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92); | |
var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805); | |
var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722); | |
var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505); | |
return [x * 100, y *100, z * 100]; | |
} | |
function rgb2lab(rgb) { | |
var xyz = rgb2xyz(rgb), | |
x = xyz[0], | |
y = xyz[1], | |
z = xyz[2], | |
l, a, b; | |
x /= 95.047; | |
y /= 100; | |
z /= 108.883; | |
x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116); | |
y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116); | |
z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116); | |
l = (116 * y) - 16; | |
a = 500 * (x - y); | |
b = 200 * (y - z); | |
return [l, a, b]; | |
} | |
function hsl2rgb(hsl) { | |
var h = hsl[0] / 360, | |
s = hsl[1] / 100, | |
l = hsl[2] / 100, | |
t1, t2, t3, rgb, val; | |
if (s == 0) { | |
val = l * 255; | |
return [val, val, val]; | |
} | |
if (l < 0.5) | |
t2 = l * (1 + s); | |
else | |
t2 = l + s - l * s; | |
t1 = 2 * l - t2; | |
rgb = [0, 0, 0]; | |
for (var i = 0; i < 3; i++) { | |
t3 = h + 1 / 3 * - (i - 1); | |
t3 < 0 && t3++; | |
t3 > 1 && t3--; | |
if (6 * t3 < 1) | |
val = t1 + (t2 - t1) * 6 * t3; | |
else if (2 * t3 < 1) | |
val = t2; | |
else if (3 * t3 < 2) | |
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6; | |
else | |
val = t1; | |
rgb[i] = val * 255; | |
} | |
return rgb; | |
} | |
function hsl2hsv(hsl) { | |
var h = hsl[0], | |
s = hsl[1] / 100, | |
l = hsl[2] / 100, | |
sv, v; | |
l *= 2; | |
s *= (l <= 1) ? l : 2 - l; | |
v = (l + s) / 2; | |
sv = (2 * s) / (l + s); | |
return [h, s * 100, v * 100]; | |
} | |
function hsl2cmyk(args) { | |
return rgb2cmyk(hsl2rgb(args)); | |
} | |
function hsl2keyword(args) { | |
return rgb2keyword(hsl2rgb(args)); | |
} | |
function hsv2rgb(hsv) { | |
var h = hsv[0] / 60, | |
s = hsv[1] / 100, | |
v = hsv[2] / 100, | |
hi = Math.floor(h) % 6; | |
var f = h - Math.floor(h), | |
p = 255 * v * (1 - s), | |
q = 255 * v * (1 - (s * f)), | |
t = 255 * v * (1 - (s * (1 - f))), | |
v = 255 * v; | |
switch(hi) { | |
case 0: | |
return [v, t, p]; | |
case 1: | |
return [q, v, p]; | |
case 2: | |
return [p, v, t]; | |
case 3: | |
return [p, q, v]; | |
case 4: | |
return [t, p, v]; | |
case 5: | |
return [v, p, q]; | |
} | |
} | |
function hsv2hsl(hsv) { | |
var h = hsv[0], | |
s = hsv[1] / 100, | |
v = hsv[2] / 100, | |
sl, l; | |
l = (2 - s) * v; | |
sl = s * v; | |
sl /= (l <= 1) ? l : 2 - l; | |
l /= 2; | |
return [h, sl * 100, l * 100]; | |
} | |
function hsv2cmyk(args) { | |
return rgb2cmyk(hsv2rgb(args)); | |
} | |
function hsv2keyword(args) { | |
return rgb2keyword(hsv2rgb(args)); | |
} | |
function cmyk2rgb(cmyk) { | |
var c = cmyk[0] / 100, | |
m = cmyk[1] / 100, | |
y = cmyk[2] / 100, | |
k = cmyk[3] / 100, | |
r, g, b; | |
r = 1 - Math.min(1, c * (1 - k) + k); | |
g = 1 - Math.min(1, m * (1 - k) + k); | |
b = 1 - Math.min(1, y * (1 - k) + k); | |
return [r * 255, g * 255, b * 255]; | |
} | |
function cmyk2hsl(args) { | |
return rgb2hsl(cmyk2rgb(args)); | |
} | |
function cmyk2hsv(args) { | |
return rgb2hsv(cmyk2rgb(args)); | |
} | |
function cmyk2keyword(args) { | |
return rgb2keyword(cmyk2rgb(args)); | |
} | |
function xyz2rgb(xyz) { | |
var x = xyz[0] / 100, | |
y = xyz[1] / 100, | |
z = xyz[2] / 100, | |
r, g, b; | |
r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986); | |
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415); | |
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570); | |
// assume sRGB | |
r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055) | |
: r = (r * 12.92); | |
g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055) | |
: g = (g * 12.92); | |
b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055) | |
: b = (b * 12.92); | |
r = (r < 0) ? 0 : r; | |
g = (g < 0) ? 0 : g; | |
b = (b < 0) ? 0 : b; | |
return [r * 255, g * 255, b * 255]; | |
} | |
function keyword2rgb(keyword) { | |
return cssKeywords[keyword]; | |
} | |
function keyword2hsl(args) { | |
return rgb2hsl(keyword2rgb(args)); | |
} | |
function keyword2hsv(args) { | |
return rgb2hsv(keyword2rgb(args)); | |
} | |
function keyword2cmyk(args) { | |
return rgb2cmyk(keyword2rgb(args)); | |
} | |
var cssKeywords = { | |
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,134,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,250,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,221], | |
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: [112,128,144], | |
slategrey: [112,128,144], | |
snow: [255,250,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,50] | |
}; | |
var reverseKeywords = {}; | |
for (var key in cssKeywords) { | |
reverseKeywords[JSON.stringify(cssKeywords[key])] = key; | |
} | |
}); | |
require.define("/node_modules/color/node_modules/color-string/package.json",function(require,module,exports,__dirname,__filename,process){module.exports = {"main":"./color-string"}}); | |
require.define("/node_modules/color/node_modules/color-string/color-string.js",function(require,module,exports,__dirname,__filename,process){/* MIT license */ | |
var convert = require("color-convert"); | |
module.exports = { | |
getRgba: getRgba, | |
getHsla: getHsla, | |
getRgb: getRgb, | |
getHsl: getHsl, | |
getAlpha: getAlpha, | |
hexString: hexString, | |
rgbString: rgbString, | |
rgbaString: rgbaString, | |
percentString: percentString, | |
percentaString: percentaString, | |
hslString: hslString, | |
hslaString: hslaString, | |
keyword: keyword | |
} | |
function getRgba(string) { | |
if (!string) { | |
return; | |
} | |
var abbr = /^#([a-fA-F0-9]{3})$/, | |
hex = /^#([a-fA-F0-9]{6})$/, | |
rgba = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d\.]+)\s*)?\)$/, | |
per = /^rgba?\(\s*([\d\.]+)\%\s*,\s*([\d\.]+)\%\s*,\s*([\d\.]+)\%\s*(?:,\s*([\d\.]+)\s*)?\)$/, | |
keyword = /(\D+)/; | |
var rgb = [0, 0, 0], | |
a = 1, | |
match = string.match(abbr); | |
if (match) { | |
match = match[1]; | |
for (var i = 0; i < rgb.length; i++) { | |
rgb[i] = parseInt(match[i] + match[i], 16); | |
} | |
} | |
else if (match = string.match(hex)) { | |
match = match[1]; | |
for (var i = 0; i < rgb.length; i++) { | |
rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16); | |
} | |
} | |
else if (match = string.match(rgba)) { | |
for (var i = 0; i < rgb.length; i++) { | |
rgb[i] = parseInt(match[i + 1]); | |
} | |
a = parseFloat(match[4]); | |
} | |
else if (match = string.match(per)) { | |
for (var i = 0; i < rgb.length; i++) { | |
rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55); | |
} | |
a = parseFloat(match[4]); | |
} | |
else if (match = string.match(keyword)) { | |
if (match[1] == "transparent") { | |
return [0, 0, 0, 0]; | |
} | |
rgb = convert.keyword2rgb(match[1]); | |
if (!rgb) { | |
return; | |
} | |
} | |
for (var i = 0; i < rgb.length; i++) { | |
rgb[i] = scale(rgb[i], 0, 255); | |
} | |
if (!a) { | |
a = 1; | |
} | |
else { | |
a = scale(a, 0, 1); | |
} | |
rgb.push(a); | |
return rgb; | |
} | |
function getHsla(string) { | |
if (!string) { | |
return; | |
} | |
var hsl = /^hsla?\(\s*(\d+)\s*,\s*([\d\.]+)%\s*,\s*([\d\.]+)%\s*(?:,\s*([\d\.]+)\s*)?\)/; | |
var match = string.match(hsl); | |
if (match) { | |
var h = scale(parseInt(match[1]), 0, 360), | |
s = scale(parseFloat(match[2]), 0, 100), | |
l = scale(parseFloat(match[3]), 0, 100), | |
a = scale(parseFloat(match[4]) || 1, 0, 1); | |
return [h, s, l, a]; | |
} | |
} | |
function getRgb(string) { | |
return getRgba(string).slice(0, 3); | |
} | |
function getHsl(string) { | |
return getHsla(string).slice(0, 3); | |
} | |
function getAlpha(string) { | |
var vals = getRgba(string); | |
if (vals) { | |
return vals[3]; | |
} | |
else if (vals = getHsla(string)) { | |
return vals[3]; | |
} | |
} | |
// generators | |
function hexString(rgb) { | |
return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1]) | |
+ hexDouble(rgb[2]); | |
} | |
function rgbString(rgba, alpha) { | |
if (alpha < 1 || (rgba[3] && rgba[3] < 1)) { | |
return rgbaString(rgba, alpha); | |
} | |
return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")"; | |
} | |
function rgbaString(rgba, alpha) { | |
return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] | |
+ ", " + (alpha || rgba[3] || 1) + ")"; | |
} | |
function percentString(rgba, alpha) { | |
if (alpha < 1 || (rgba[3] && rgba[3] < 1)) { | |
return percentaString(rgba, alpha); | |
} | |
var r = Math.round(rgba[0]/255 * 100), | |
g = Math.round(rgba[1]/255 * 100), | |
b = Math.round(rgba[2]/255 * 100); | |
return "rgb(" + r + "%, " + g + "%, " + b + "%)"; | |
} | |
function percentaString(rgba, alpha) { | |
var r = Math.round(rgba[0]/255 * 100), | |
g = Math.round(rgba[1]/255 * 100), | |
b = Math.round(rgba[2]/255 * 100); | |
return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")"; | |
} | |
function hslString(hsla, alpha) { | |
if (alpha < 1 || (hsla[3] && hsla[3] < 1)) { | |
return hslaString(hsla, alpha); | |
} | |
return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)"; | |
} | |
function hslaString(hsla, alpha) { | |
return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, " | |
+ (alpha || hsla[3] || 1) + ")"; | |
} | |
function keyword(rgb) { | |
return convert.rgb2keyword(rgb.slice(0, 3)); | |
} | |
// helpers | |
function scale(num, min, max) { | |
return Math.min(Math.max(min, num), max); | |
} | |
function hexDouble(num) { | |
var str = num.toString(16).toUpperCase(); | |
return (str.length < 2) ? "0" + str : str; | |
} | |
}); | |
require.define("/node_modules/color-convert/package.json",function(require,module,exports,__dirname,__filename,process){module.exports = {"main":"./index"}}); | |
require.define("/node_modules/color-convert/index.js",function(require,module,exports,__dirname,__filename,process){var conversions = require("./conversions"); | |
var exports = {}; | |
module.exports = exports; | |
for (var func in conversions) { | |
// export rgb2hslRaw | |
exports[func + "Raw"] = (function(func) { | |
// accept array or plain args | |
return function(arg) { | |
if (typeof arg == "number") | |
arg = Array.prototype.slice.call(arguments); | |
return conversions[func](arg); | |
} | |
})(func); | |
var pair = /(\w+)2(\w+)/.exec(func), | |
from = pair[1], | |
to = pair[2]; | |
// export rgb2hsl and ["rgb"]["hsl"] | |
exports[from] = exports[from] || {}; | |
exports[from][to] = exports[func] = (function(func) { | |
return function(arg) { | |
if (typeof arg == "number") | |
arg = Array.prototype.slice.call(arguments); | |
var val = conversions[func](arg); | |
if (typeof val == "string" || val === undefined) | |
return val; // keyword | |
for (var i = 0; i < val.length; i++) | |
val[i] = Math.round(val[i]); | |
return val; | |
} | |
})(func); | |
}}); | |
require.define("/node_modules/color-convert/conversions.js",function(require,module,exports,__dirname,__filename,process){/* MIT license */ | |
module.exports = { | |
rgb2hsl: rgb2hsl, | |
rgb2hsv: rgb2hsv, | |
rgb2cmyk: rgb2cmyk, | |
rgb2keyword: rgb2keyword, | |
rgb2xyz: rgb2xyz, | |
rgb2lab: rgb2lab, | |
hsl2rgb: hsl2rgb, | |
hsl2hsv: hsl2hsv, | |
hsl2cmyk: hsl2cmyk, | |
hsl2keyword: hsl2keyword, | |
hsv2rgb: hsv2rgb, | |
hsv2hsl: hsv2hsl, | |
hsv2cmyk: hsv2cmyk, | |
hsv2keyword: hsv2keyword, | |
cmyk2rgb: cmyk2rgb, | |
cmyk2hsl: cmyk2hsl, | |
cmyk2hsv: cmyk2hsv, | |
cmyk2keyword: cmyk2keyword, | |
keyword2rgb: keyword2rgb, | |
keyword2hsl: keyword2hsl, | |
keyword2hsv: keyword2hsv, | |
keyword2cmyk: keyword2cmyk, | |
xyz2rgb: xyz2rgb, | |
} | |
function rgb2hsl(rgb) { | |
var r = rgb[0]/255, | |
g = rgb[1]/255, | |
b = rgb[2]/255, | |
min = Math.min(r, g, b), | |
max = Math.max(r, g, b), | |
delta = max - min, | |
h, s, l; | |
if (max == min) | |
h = 0; | |
else if (r == max) | |
h = (g - b) / delta; | |
else if (g == max) | |
h = 2 + (b - r) / delta; | |
else if (b == max) | |
h = 4 + (r - g)/ delta; | |
h = Math.min(h * 60, 360); | |
if (h < 0) | |
h += 360; | |
l = (min + max) / 2; | |
if (max == min) | |
s = 0; | |
else if (l <= 0.5) | |
s = delta / (max + min); | |
else | |
s = delta / (2 - max - min); | |
return [h, s * 100, l * 100]; | |
} | |
function rgb2hsv(rgb) { | |
var r = rgb[0], | |
g = rgb[1], | |
b = rgb[2], | |
min = Math.min(r, g, b), | |
max = Math.max(r, g, b), | |
delta = max - min, | |
h, s, v; | |
if (max == 0) | |
s = 0; | |
else | |
s = (delta/max * 1000)/10; | |
if (max == min) | |
h = 0; | |
else if (r == max) | |
h = (g - b) / delta; | |
else if (g == max) | |
h = 2 + (b - r) / delta; | |
else if (b == max) | |
h = 4 + (r - g) / delta; | |
h = Math.min(h * 60, 360); | |
if (h < 0) | |
h += 360; | |
v = ((max / 255) * 1000) / 10; | |
return [h, s, v]; | |
} | |
function rgb2cmyk(rgb) { | |
var r = rgb[0] / 255, | |
g = rgb[1] / 255, | |
b = rgb[2] / 255, | |
c, m, y, k; | |
k = Math.min(1 - r, 1 - g, 1 - b); | |
c = (1 - r - k) / (1 - k); | |
m = (1 - g - k) / (1 - k); | |
y = (1 - b - k) / (1 - k); | |
return [c * 100, m * 100, y * 100, k * 100]; | |
} | |
function rgb2keyword(rgb) { | |
return reverseKeywords[JSON.stringify(rgb)]; | |
} | |
function rgb2xyz(rgb) { | |
var r = rgb[0] / 255, | |
g = rgb[1] / 255, | |
b = rgb[2] / 255; | |
// assume sRGB | |
r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92); | |
g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92); | |
b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92); | |
var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805); | |
var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722); | |
var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505); | |
return [x * 100, y *100, z * 100]; | |
} | |
function rgb2lab(rgb) { | |
var xyz = rgb2xyz(rgb), | |
x = xyz[0], | |
y = xyz[1], | |
z = xyz[2], | |
l, a, b; | |
x /= 95.047; | |
y /= 100; | |
z /= 108.883; | |
x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116); | |
y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116); | |
z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116); | |
l = (116 * y) - 16; | |
a = 500 * (x - y); | |
b = 200 * (y - z); | |
return [l, a, b]; | |
} | |
function hsl2rgb(hsl) { | |
var h = hsl[0] / 360, | |
s = hsl[1] / 100, | |
l = hsl[2] / 100, | |
t1, t2, t3, rgb, val; | |
if (s == 0) { | |
val = l * 255; | |
return [val, val, val]; | |
} | |
if (l < 0.5) | |
t2 = l * (1 + s); | |
else | |
t2 = l + s - l * s; | |
t1 = 2 * l - t2; | |
rgb = [0, 0, 0]; | |
for (var i = 0; i < 3; i++) { | |
t3 = h + 1 / 3 * - (i - 1); | |
t3 < 0 && t3++; | |
t3 > 1 && t3--; | |
if (6 * t3 < 1) | |
val = t1 + (t2 - t1) * 6 * t3; | |
else if (2 * t3 < 1) | |
val = t2; | |
else if (3 * t3 < 2) | |
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6; | |
else | |
val = t1; | |
rgb[i] = val * 255; | |
} | |
return rgb; | |
} | |
function hsl2hsv(hsl) { | |
var h = hsl[0], | |
s = hsl[1] / 100, | |
l = hsl[2] / 100, | |
sv, v; | |
l *= 2; | |
s *= (l <= 1) ? l : 2 - l; | |
v = (l + s) / 2; | |
sv = (2 * s) / (l + s); | |
return [h, s * 100, v * 100]; | |
} | |
function hsl2cmyk(args) { | |
return rgb2cmyk(hsl2rgb(args)); | |
} | |
function hsl2keyword(args) { | |
return rgb2keyword(hsl2rgb(args)); | |
} | |
function hsv2rgb(hsv) { | |
var h = hsv[0] / 60, | |
s = hsv[1] / 100, | |
v = hsv[2] / 100, | |
hi = Math.floor(h) % 6; | |
var f = h - Math.floor(h), | |
p = 255 * v * (1 - s), | |
q = 255 * v * (1 - (s * f)), | |
t = 255 * v * (1 - (s * (1 - f))), | |
v = 255 * v; | |
switch(hi) { | |
case 0: | |
return [v, t, p]; | |
case 1: | |
return [q, v, p]; | |
case 2: | |
return [p, v, t]; | |
case 3: | |
return [p, q, v]; | |
case 4: | |
return [t, p, v]; | |
case 5: | |
return [v, p, q]; | |
} | |
} | |
function hsv2hsl(hsv) { | |
var h = hsv[0], | |
s = hsv[1] / 100, | |
v = hsv[2] / 100, | |
sl, l; | |
l = (2 - s) * v; | |
sl = s * v; | |
sl /= (l <= 1) ? l : 2 - l; | |
l /= 2; | |
return [h, sl * 100, l * 100]; | |
} | |
function hsv2cmyk(args) { | |
return rgb2cmyk(hsv2rgb(args)); | |
} | |
function hsv2keyword(args) { | |
return rgb2keyword(hsv2rgb(args)); | |
} | |
function cmyk2rgb(cmyk) { | |
var c = cmyk[0] / 100, | |
m = cmyk[1] / 100, | |
y = cmyk[2] / 100, | |
k = cmyk[3] / 100, | |
r, g, b; | |
r = 1 - Math.min(1, c * (1 - k) + k); | |
g = 1 - Math.min(1, m * (1 - k) + k); | |
b = 1 - Math.min(1, y * (1 - k) + k); | |
return [r * 255, g * 255, b * 255]; | |
} | |
function cmyk2hsl(args) { | |
return rgb2hsl(cmyk2rgb(args)); | |
} | |
function cmyk2hsv(args) { | |
return rgb2hsv(cmyk2rgb(args)); | |
} | |
function cmyk2keyword(args) { | |
return rgb2keyword(cmyk2rgb(args)); | |
} | |
function xyz2rgb(xyz) { | |
var x = xyz[0] / 100, | |
y = xyz[1] / 100, | |
z = xyz[2] / 100, | |
r, g, b; | |
r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986); | |
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415); | |
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570); | |
// assume sRGB | |
r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055) | |
: r = (r * 12.92); | |
g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055) | |
: g = (g * 12.92); | |
b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055) | |
: b = (b * 12.92); | |
r = (r < 0) ? 0 : r; | |
g = (g < 0) ? 0 : g; | |
b = (b < 0) ? 0 : b; | |
return [r * 255, g * 255, b * 255]; | |
} | |
function keyword2rgb(keyword) { | |
return cssKeywords[keyword]; | |
} | |
function keyword2hsl(args) { | |
return rgb2hsl(keyword2rgb(args)); | |
} | |
function keyword2hsv(args) { | |
return rgb2hsv(keyword2rgb(args)); | |
} | |
function keyword2cmyk(args) { | |
return rgb2cmyk(keyword2rgb(args)); | |
} | |
var cssKeywords = { | |
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,134,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,250,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,221], | |
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: [112,128,144], | |
slategrey: [112,128,144], | |
snow: [255,250,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,50] | |
}; | |
var reverseKeywords = {}; | |
for (var key in cssKeywords) { | |
reverseKeywords[JSON.stringify(cssKeywords[key])] = key; | |
} | |
}); | |
require.define("/node_modules/ratchet-color/node_modules/mustache/package.json",function(require,module,exports,__dirname,__filename,process){module.exports = {"main":"./mustache.js"}}); | |
require.define("mustache",function(require,module,exports,__dirname,__filename,process){/*! | |
* mustache.js - Logic-less {{mustache}} templates with JavaScript | |
* http://github.com/janl/mustache.js | |
*/ | |
/*global define: false*/ | |
var Mustache; | |
(function (exports) { | |
if (typeof module !== "undefined" && module.exports) { | |
module.exports = exports; // CommonJS | |
} else if (typeof define === "function") { | |
define(exports); // AMD | |
} else { | |
Mustache = exports; // <script> | |
} | |
}((function () { | |
var exports = {}; | |
exports.name = "mustache.js"; | |
exports.version = "0.7.0"; | |
exports.tags = ["{{", "}}"]; | |
exports.Scanner = Scanner; | |
exports.Context = Context; | |
exports.Writer = Writer; | |
var whiteRe = /\s*/; | |
var spaceRe = /\s+/; | |
var nonSpaceRe = /\S/; | |
var eqRe = /\s*=/; | |
var curlyRe = /\s*\}/; | |
var tagRe = /#|\^|\/|>|\{|&|=|!/; | |
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577 | |
// See https://github.com/janl/mustache.js/issues/189 | |
function testRe(re, string) { | |
return RegExp.prototype.test.call(re, string); | |
} | |
function isWhitespace(string) { | |
return !testRe(nonSpaceRe, string); | |
} | |
var isArray = Array.isArray || function (obj) { | |
return Object.prototype.toString.call(obj) === "[object Array]"; | |
}; | |
function escapeRe(string) { | |
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); | |
} | |
var entityMap = { | |
"&": "&", | |
"<": "<", | |
">": ">", | |
'"': '"', | |
"'": ''', | |
"/": '/' | |
}; | |
function escapeHtml(string) { | |
return String(string).replace(/[&<>"'\/]/g, function (s) { | |
return entityMap[s]; | |
}); | |
} | |
// Export the escaping function so that the user may override it. | |
// See https://github.com/janl/mustache.js/issues/244 | |
exports.escape = escapeHtml; | |
function Scanner(string) { | |
this.string = string; | |
this.tail = string; | |
this.pos = 0; | |
} | |
/** | |
* Returns `true` if the tail is empty (end of string). | |
*/ | |
Scanner.prototype.eos = function () { | |
return this.tail === ""; | |
}; | |
/** | |
* Tries to match the given regular expression at the current position. | |
* Returns the matched text if it can match, the empty string otherwise. | |
*/ | |
Scanner.prototype.scan = function (re) { | |
var match = this.tail.match(re); | |
if (match && match.index === 0) { | |
this.tail = this.tail.substring(match[0].length); | |
this.pos += match[0].length; | |
return match[0]; | |
} | |
return ""; | |
}; | |
/** | |
* Skips all text until the given regular expression can be matched. Returns | |
* the skipped string, which is the entire tail if no match can be made. | |
*/ | |
Scanner.prototype.scanUntil = function (re) { | |
var match, pos = this.tail.search(re); | |
switch (pos) { | |
case -1: | |
match = this.tail; | |
this.pos += this.tail.length; | |
this.tail = ""; | |
break; | |
case 0: | |
match = ""; | |
break; | |
default: | |
match = this.tail.substring(0, pos); | |
this.tail = this.tail.substring(pos); | |
this.pos += pos; | |
} | |
return match; | |
}; | |
function Context(view, parent) { | |
this.view = view; | |
this.parent = parent; | |
this.clearCache(); | |
} | |
Context.make = function (view) { | |
return (view instanceof Context) ? view : new Context(view); | |
}; | |
Context.prototype.clearCache = function () { | |
this._cache = {}; | |
}; | |
Context.prototype.push = function (view) { | |
return new Context(view, this); | |
}; | |
Context.prototype.lookup = function (name) { | |
var value = this._cache[name]; | |
if (!value) { | |
if (name === ".") { | |
value = this.view; | |
} else { | |
var context = this; | |
while (context) { | |
if (name.indexOf(".") > 0) { | |
var names = name.split("."), i = 0; | |
value = context.view; | |
while (value && i < names.length) { | |
value = value[names[i++]]; | |
} | |
} else { | |
value = context.view[name]; | |
} | |
if (value != null) { | |
break; | |
} | |
context = context.parent; | |
} | |
} | |
this._cache[name] = value; | |
} | |
if (typeof value === "function") { | |
value = value.call(this.view); | |
} | |
return value; | |
}; | |
function Writer() { | |
this.clearCache(); | |
} | |
Writer.prototype.clearCache = function () { | |
this._cache = {}; | |
this._partialCache = {}; | |
}; | |
Writer.prototype.compile = function (template, tags) { | |
return this._compile(this._cache, template, template, tags); | |
}; | |
Writer.prototype.compilePartial = function (name, template, tags) { | |
return this._compile(this._partialCache, name, template, tags); | |
}; | |
Writer.prototype.render = function (template, view, partials) { | |
return this.compile(template)(view, partials); | |
}; | |
Writer.prototype._compile = function (cache, key, template, tags) { | |
if (!cache[key]) { | |
var tokens = exports.parse(template, tags); | |
var fn = compileTokens(tokens); | |
var self = this; | |
cache[key] = function (view, partials) { | |
if (partials) { | |
if (typeof partials === "function") { | |
self._loadPartial = partials; | |
} else { | |
for (var name in partials) { | |
self.compilePartial(name, partials[name]); | |
} | |
} | |
} | |
return fn(self, Context.make(view), template); | |
}; | |
} | |
return cache[key]; | |
}; | |
Writer.prototype._section = function (name, context, text, callback) { | |
var value = context.lookup(name); | |
switch (typeof value) { | |
case "object": | |
if (isArray(value)) { | |
var buffer = ""; | |
for (var i = 0, len = value.length; i < len; ++i) { | |
buffer += callback(this, context.push(value[i])); | |
} | |
return buffer; | |
} | |
return value ? callback(this, context.push(value)) : ""; | |
case "function": | |
var self = this; | |
var scopedRender = function (template) { | |
return self.render(template, context); | |
}; | |
return value.call(context.view, text, scopedRender) || ""; | |
default: | |
if (value) { | |
return callback(this, context); | |
} | |
} | |
return ""; | |
}; | |
Writer.prototype._inverted = function (name, context, callback) { | |
var value = context.lookup(name); | |
// Use JavaScript's definition of falsy. Include empty arrays. | |
// See https://github.com/janl/mustache.js/issues/186 | |
if (!value || (isArray(value) && value.length === 0)) { | |
return callback(this, context); | |
} | |
return ""; | |
}; | |
Writer.prototype._partial = function (name, context) { | |
if (!(name in this._partialCache) && this._loadPartial) { | |
this.compilePartial(name, this._loadPartial(name)); | |
} | |
var fn = this._partialCache[name]; | |
return fn ? fn(context) : ""; | |
}; | |
Writer.prototype._name = function (name, context) { | |
var value = context.lookup(name); | |
if (typeof value === "function") { | |
value = value.call(context.view); | |
} | |
return (value == null) ? "" : String(value); | |
}; | |
Writer.prototype._escaped = function (name, context) { | |
return exports.escape(this._name(name, context)); | |
}; | |
/** | |
* Calculates the bounds of the section represented by the given `token` in | |
* the original template by drilling down into nested sections to find the | |
* last token that is part of that section. Returns an array of [start, end]. | |
*/ | |
function sectionBounds(token) { | |
var start = token[3]; | |
var end = start; | |
var tokens; | |
while ((tokens = token[4]) && tokens.length) { | |
token = tokens[tokens.length - 1]; | |
end = token[3]; | |
} | |
return [start, end]; | |
} | |
/** | |
* Low-level function that compiles the given `tokens` into a function | |
* that accepts two arguments: a Context and a Writer. | |
*/ | |
function compileTokens(tokens) { | |
var subRenders = {}; | |
function subRender(i, tokens, template) { | |
if (!subRenders[i]) { | |
var fn = compileTokens(tokens); | |
subRenders[i] = function (writer, context) { | |
return fn(writer, context, template); | |
}; | |
} | |
return subRenders[i]; | |
} | |
function renderFunction(writer, context, template) { | |
var buffer = ""; | |
var token, sectionText; | |
for (var i = 0, len = tokens.length; i < len; ++i) { | |
token = tokens[i]; | |
switch (token[0]) { | |
case "#": | |
sectionText = template.slice.apply(template, sectionBounds(token)); | |
buffer += writer._section(token[1], context, sectionText, subRender(i, token[4], template)); | |
break; | |
case "^": | |
buffer += writer._inverted(token[1], context, subRender(i, token[4], template)); | |
break; | |
case ">": | |
buffer += writer._partial(token[1], context); | |
break; | |
case "&": | |
buffer += writer._name(token[1], context); | |
break; | |
case "name": | |
buffer += writer._escaped(token[1], context); | |
break; | |
case "text": | |
buffer += token[1]; | |
break; | |
} | |
} | |
return buffer; | |
} | |
return renderFunction; | |
} | |
/** | |
* Forms the given array of `tokens` into a nested tree structure where | |
* tokens that represent a section have a fifth item: an array that contains | |
* all tokens in that section. | |
*/ | |
function nestTokens(tokens) { | |
var tree = []; | |
var collector = tree; | |
var sections = []; | |
var token, section; | |
for (var i = 0; i < tokens.length; ++i) { | |
token = tokens[i]; | |
switch (token[0]) { | |
case "#": | |
case "^": | |
token[4] = []; | |
sections.push(token); | |
collector.push(token); | |
collector = token[4]; | |
break; | |
case "/": | |
if (sections.length === 0) { | |
throw new Error("Unopened section: " + token[1]); | |
} | |
section = sections.pop(); | |
if (section[1] !== token[1]) { | |
throw new Error("Unclosed section: " + section[1]); | |
} | |
if (sections.length > 0) { | |
collector = sections[sections.length - 1][4]; | |
} else { | |
collector = tree; | |
} | |
break; | |
default: | |
collector.push(token); | |
} | |
} | |
// Make sure there were no open sections when we're done. | |
section = sections.pop(); | |
if (section) { | |
throw new Error("Unclosed section: " + section[1]); | |
} | |
return tree; | |
} | |
/** | |
* Combines the values of consecutive text tokens in the given `tokens` array | |
* to a single token. | |
*/ | |
function squashTokens(tokens) { | |
var token, lastToken; | |
for (var i = 0; i < tokens.length; ++i) { | |
token = tokens[i]; | |
if (lastToken && lastToken[0] === "text" && token[0] === "text") { | |
lastToken[1] += token[1]; | |
lastToken[3] = token[3]; | |
tokens.splice(i--, 1); // Remove this token from the array. | |
} else { | |
lastToken = token; | |
} | |
} | |
} | |
function escapeTags(tags) { | |
if (tags.length !== 2) { | |
throw new Error("Invalid tags: " + tags.join(" ")); | |
} | |
return [ | |
new RegExp(escapeRe(tags[0]) + "\\s*"), | |
new RegExp("\\s*" + escapeRe(tags[1])) | |
]; | |
} | |
/** | |
* Breaks up the given `template` string into a tree of token objects. If | |
* `tags` is given here it must be an array with two string values: the | |
* opening and closing tags used in the template (e.g. ["<%", "%>"]). Of | |
* course, the default is to use mustaches (i.e. Mustache.tags). | |
*/ | |
exports.parse = function (template, tags) { | |
tags = tags || exports.tags; | |
var tagRes = escapeTags(tags); | |
var scanner = new Scanner(template); | |
var tokens = [], // Buffer to hold the tokens | |
spaces = [], // Indices of whitespace tokens on the current line | |
hasTag = false, // Is there a {{tag}} on the current line? | |
nonSpace = false; // Is there a non-space char on the current line? | |
// Strips all whitespace tokens array for the current line | |
// if there was a {{#tag}} on it and otherwise only space. | |
function stripSpace() { | |
if (hasTag && !nonSpace) { | |
while (spaces.length) { | |
tokens.splice(spaces.pop(), 1); | |
} | |
} else { | |
spaces = []; | |
} | |
hasTag = false; | |
nonSpace = false; | |
} | |
var start, type, value, chr; | |
while (!scanner.eos()) { | |
start = scanner.pos; | |
value = scanner.scanUntil(tagRes[0]); | |
if (value) { | |
for (var i = 0, len = value.length; i < len; ++i) { | |
chr = value.charAt(i); | |
if (isWhitespace(chr)) { | |
spaces.push(tokens.length); | |
} else { | |
nonSpace = true; | |
} | |
tokens.push(["text", chr, start, start + 1]); | |
start += 1; | |
if (chr === "\n") { | |
stripSpace(); // Check for whitespace on the current line. | |
} | |
} | |
} | |
start = scanner.pos; | |
// Match the opening tag. | |
if (!scanner.scan(tagRes[0])) { | |
break; | |
} | |
hasTag = true; | |
type = scanner.scan(tagRe) || "name"; | |
// Skip any whitespace between tag and value. | |
scanner.scan(whiteRe); | |
// Extract the tag value. | |
if (type === "=") { | |
value = scanner.scanUntil(eqRe); | |
scanner.scan(eqRe); | |
scanner.scanUntil(tagRes[1]); | |
} else if (type === "{") { | |
var closeRe = new RegExp("\\s*" + escapeRe("}" + tags[1])); | |
value = scanner.scanUntil(closeRe); | |
scanner.scan(curlyRe); | |
scanner.scanUntil(tagRes[1]); | |
type = "&"; | |
} else { | |
value = scanner.scanUntil(tagRes[1]); | |
} | |
// Match the closing tag. | |
if (!scanner.scan(tagRes[1])) { | |
throw new Error("Unclosed tag at " + scanner.pos); | |
} | |
tokens.push([type, value, start, scanner.pos]); | |
if (type === "name" || type === "{" || type === "&") { | |
nonSpace = true; | |
} | |
// Set the tags for the next time around. | |
if (type === "=") { | |
tags = value.split(spaceRe); | |
tagRes = escapeTags(tags); | |
} | |
} | |
squashTokens(tokens); | |
return nestTokens(tokens); | |
}; | |
// The high-level clearCache, compile, compilePartial, and render functions | |
// use this default writer. | |
var _writer = new Writer(); | |
/** | |
* Clears all cached templates and partials in the default writer. | |
*/ | |
exports.clearCache = function () { | |
return _writer.clearCache(); | |
}; | |
/** | |
* Compiles the given `template` to a reusable function using the default | |
* writer. | |
*/ | |
exports.compile = function (template, tags) { | |
return _writer.compile(template, tags); | |
}; | |
/** | |
* Compiles the partial with the given `name` and `template` to a reusable | |
* function using the default writer. | |
*/ | |
exports.compilePartial = function (name, template, tags) { | |
return _writer.compilePartial(name, template, tags); | |
}; | |
/** | |
* Renders the `template` with the given `view` and `partials` using the | |
* default writer. | |
*/ | |
exports.render = function (template, view, partials) { | |
return _writer.render(template, view, partials); | |
}; | |
// This is here for backwards compatibility with 0.4.x. | |
exports.to_html = function (template, view, partials, send) { | |
var result = exports.render(template, view, partials); | |
if (typeof send === "function") { | |
send(result); | |
} else { | |
return result; | |
} | |
}; | |
return exports; | |
}()))); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>color demo</title> | |
<script type="text/javascript" src="bundle.js"></script> | |
<script type="text/javascript" src="http://maker.github.com/ratchet/dist/ratchet.js"></script> | |
<link rel="stylesheet" href="http://maker.github.com/ratchet/dist/ratchet.css"> | |
<link rel="stylesheet" href="http://maker.github.com/ratchet/css/docs.css"> | |
<style type="text/css"> | |
.instructions { text-align: center; width: 300px;} | |
.picker { position: absolute; width: 300px; margin: 0px 10px; top: 75px; } | |
.picker input { height: 200px; } | |
</style> | |
</head> | |
<body> | |
<div class="iphone iphone-fixed" id=""> | |
<div class="iphone-content"> | |
<div id="iwindow"> | |
<header class="bar-title"> <a class="button" href="#"> | |
Left | |
</a> | |
<ul class="segmented-controller"> | |
<li class="active"> <a href="#">One</a> | |
</li> | |
<li> <a href="#">Two</a> | |
</li> | |
<li> <a href="#">Three</a> | |
</li> | |
</ul> <a class="button" href="#"> | |
Right | |
</a> | |
</header> | |
<div class="picker"> | |
<input type="color" value="#a550e9"></input> | |
<div class="instructions">PICK A COLOR</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script type="text/mustache" class="cssTemplate"> | |
.bar-title { | |
background-color: {{base}}; | |
background-image: -webkit-linear-gradient(top, {{base}} 0, {{buttonGradient}} 100%); | |
background-image: linear-gradient(to bottom, {{base}} 0, {{buttonGradient}} 100%); | |
border-bottom: 1px solid {{border}}; | |
} | |
.bar-title [class*="button"] { | |
background-color: {{base}}; | |
background-image: -webkit-linear-gradient(top, {{base}} 0, {{headerGradient}} 100%); | |
background-image: linear-gradient(to bottom, {{base}} 0, {{headerGradient}} 100%); | |
border: 1px solid {{border}}; | |
} | |
.bar-title .segmented-controller { | |
background-color: {{base}}; | |
background-image: -webkit-linear-gradient(top, {{base}} 0, {{headerGradient}} 100%); | |
background-image: linear-gradient(to bottom, {{base}} 0, {{headerGradient}} 100%); | |
border: 1px solid {{border}}; | |
} | |
.bar-title .segmented-controller li { | |
border-left: 1px solid {{border}}; | |
} | |
.bar-title .segmented-controller li.active { | |
background-color: {{active}}; | |
} | |
</script> | |
<script type="text/javascript"> | |
var calculator = require('ratchet-color') | |
var mustache = require('mustache') | |
var picker = document.querySelector('input') | |
picker.onchange = changeColor | |
changeColor() | |
function changeColor() { | |
var color = picker.value | |
var scheme = calculator(color) | |
insertOverrideCSS(scheme) | |
return false | |
} | |
function insertOverrideCSS(scheme) { | |
var templateString = document.querySelector('.cssTemplate').text | |
var data = {base: scheme[0], headerGradient: scheme[1], buttonGradient: scheme[2], border: scheme[3], active: scheme[4]} | |
var rendered = mustache.to_html(templateString, data) | |
console.log(data, rendered) | |
addOverrideCSS(rendered) | |
} | |
function addOverrideCSS(css) { | |
var existing = document.querySelector('.overrideStyles') | |
if (existing) existing.parentNode.removeChild(existing) | |
var head = document.getElementsByTagName('head')[0] | |
var styleElement = document.createElement('style') | |
styleElement.setAttribute('type', 'text/css') | |
styleElement.appendChild(document.createTextNode(css)) | |
styleElement.className = "overrideStyles" | |
head.appendChild(styleElement) | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment