forked from stylus/nib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nib.js
68 lines (53 loc) · 1.27 KB
/
nib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*!
* nib
* Copyright (c) 2010 TJ Holowaychuk <[email protected]>
* MIT Licensed
*/
/**
* Module dependencies.
*/
var stylus = require('stylus'),
path = require('path'),
nodes = stylus.nodes,
utils = stylus.utils,
Canvas;
exports = module.exports = plugin;
// conditionally expose canvas-based APIs.
try {
Canvas = require('canvas');
var gradient = require('./nodes/gradient'),
colorImage = require('./nodes/color-image');
} catch (err) {
// ignore
}
/**
* Library version.
*/
exports.version = require(path.join(__dirname, '../package.json')).version;
/**
* Stylus path.
*/
exports.path = __dirname;
/**
* Return the plugin callback for stylus.
*
* @return {Function}
* @api public
*/
function plugin() {
return function(style){
style.include(__dirname);
if (Canvas) {
style.define('has-canvas', nodes.true);
// gradients
style.define('create-gradient-image', gradient.create);
style.define('gradient-data-uri', gradient.dataURL);
style.define('add-color-stop', gradient.addColorStop);
// color images
style.define('create-color-image', colorImage.create);
style.define('color-data-uri', colorImage.dataURL);
} else {
style.define('has-canvas', nodes.false);
}
};
}