keyframes.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*!
  2. * Stylus - Keyframes
  3. * Copyright (c) Automattic <developer.wordpress.com>
  4. * MIT Licensed
  5. */
  6. /**
  7. * Module dependencies.
  8. */
  9. var Atrule = require('./atrule');
  10. /**
  11. * Initialize a new `Keyframes` with the given `segs`,
  12. * and optional vendor `prefix`.
  13. *
  14. * @param {Array} segs
  15. * @param {String} prefix
  16. * @api public
  17. */
  18. var Keyframes = module.exports = function Keyframes(segs, prefix){
  19. Atrule.call(this, 'keyframes');
  20. this.segments = segs;
  21. this.prefix = prefix || 'official';
  22. };
  23. /**
  24. * Inherit from `Atrule.prototype`.
  25. */
  26. Keyframes.prototype.__proto__ = Atrule.prototype;
  27. /**
  28. * Return a clone of this node.
  29. *
  30. * @return {Node}
  31. * @api public
  32. */
  33. Keyframes.prototype.clone = function(parent){
  34. var clone = new Keyframes;
  35. clone.lineno = this.lineno;
  36. clone.column = this.column;
  37. clone.filename = this.filename;
  38. clone.segments = this.segments.map(function(node) { return node.clone(parent, clone); });
  39. clone.prefix = this.prefix;
  40. clone.block = this.block.clone(parent, clone);
  41. return clone;
  42. };
  43. /**
  44. * Return a JSON representation of this node.
  45. *
  46. * @return {Object}
  47. * @api public
  48. */
  49. Keyframes.prototype.toJSON = function(){
  50. return {
  51. __type: 'Keyframes',
  52. segments: this.segments,
  53. prefix: this.prefix,
  54. block: this.block,
  55. lineno: this.lineno,
  56. column: this.column,
  57. filename: this.filename
  58. };
  59. };
  60. /**
  61. * Return `@keyframes name`.
  62. *
  63. * @return {String}
  64. * @api public
  65. */
  66. Keyframes.prototype.toString = function(){
  67. return '@keyframes ' + this.segments.join('');
  68. };