Sha256: aaae16f8834e9faf5b0c2e92f2304127c18567d4490d81386779ea3e50082fc5
Contents?: true
Size: 1.45 KB
Versions: 14
Compression:
Stored size: 1.45 KB
Contents
/** * Module dependencies. */ var stylus = require('stylus') , Canvas = require('canvas') , nodes = stylus.nodes , utils = stylus.utils /** * Expose `ColorImage`. */ exports = module.exports = ColorImage; /** * Create a new `ColorImage` node with the given `color`. * * @param {Color} color node * @return {ColorImage} * @api public */ exports.create = function(color){ utils.assertColor(color); return new ColorImage(color); }; /** * Return the data URI for `colorImage`. * * @param {ColorImage} colorImage * @return {String} * @api public */ exports.dataURL = function(colorImage){ utils.assertType(colorImage, 'colorimage'); return new nodes.String(colorImage.toDataURL()); }; /** * Initialize a new `ColorImage` node with the given arguments. * * @param {Color} color node * @api private */ function ColorImage(color) { this.color = color; this.canvas = new Canvas(1, 1); this.ctx = this.canvas.getContext('2d'); this.ctx.fillStyle = color.toString(); this.ctx.fillRect(0, 0, 1, 1); }; /** * Inherit from `nodes.Node.prototype`. */ ColorImage.prototype.__proto__ = nodes.Node.prototype; /** * Inspect the color. * * @return {String} * @api private */ ColorImage.prototype.toString = function(){ return 'ColorImage(' + this.color.toString() + ')'; }; /** * Return data URI string. * * @return {String} * @api private */ ColorImage.prototype.toDataURL = function(){ return this.canvas.toDataURL(); };
Version data entries
14 entries across 14 versions & 1 rubygems