nib.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*!
  2. * nib
  3. * Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca>
  4. * MIT Licensed
  5. */
  6. /**
  7. * Module dependencies.
  8. */
  9. var stylus = require('stylus'),
  10. path = require('path'),
  11. nodes = stylus.nodes,
  12. utils = stylus.utils,
  13. Canvas;
  14. exports = module.exports = plugin;
  15. // conditionally expose canvas-based APIs.
  16. try {
  17. Canvas = require('canvas');
  18. var gradient = require('./nodes/gradient'),
  19. colorImage = require('./nodes/color-image');
  20. } catch (err) {
  21. // ignore
  22. }
  23. /**
  24. * Library version.
  25. */
  26. exports.version = require(path.join(__dirname, '../package.json')).version;
  27. /**
  28. * Stylus path.
  29. */
  30. exports.path = __dirname;
  31. /**
  32. * Return the plugin callback for stylus.
  33. *
  34. * @return {Function}
  35. * @api public
  36. */
  37. function plugin() {
  38. return function(style){
  39. style.include(__dirname);
  40. if (Canvas) {
  41. style.define('has-canvas', nodes.true);
  42. // gradients
  43. style.define('create-gradient-image', gradient.create);
  44. style.define('gradient-data-uri', gradient.dataURL);
  45. style.define('add-color-stop', gradient.addColorStop);
  46. // color images
  47. style.define('create-color-image', colorImage.create);
  48. style.define('color-data-uri', colorImage.dataURL);
  49. } else {
  50. style.define('has-canvas', nodes.false);
  51. }
  52. };
  53. }