order.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. var flexSpec = require('./flex-spec');
  6. var Declaration = require('../declaration');
  7. var Order = function (_Declaration) {
  8. _inherits(Order, _Declaration);
  9. function Order() {
  10. _classCallCheck(this, Order);
  11. return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
  12. }
  13. /**
  14. * Change property name for 2009 and 2012 specs
  15. */
  16. Order.prototype.prefixed = function prefixed(prop, prefix) {
  17. var spec = void 0;
  18. var _flexSpec = flexSpec(prefix);
  19. spec = _flexSpec[0];
  20. prefix = _flexSpec[1];
  21. if (spec === 2009) {
  22. return prefix + 'box-ordinal-group';
  23. } else if (spec === 2012) {
  24. return prefix + 'flex-order';
  25. } else {
  26. return _Declaration.prototype.prefixed.call(this, prop, prefix);
  27. }
  28. };
  29. /**
  30. * Return property name by final spec
  31. */
  32. Order.prototype.normalize = function normalize() {
  33. return 'order';
  34. };
  35. /**
  36. * Fix value for 2009 spec
  37. */
  38. Order.prototype.set = function set(decl, prefix) {
  39. var spec = flexSpec(prefix)[0];
  40. if (spec === 2009 && /\d/.test(decl.value)) {
  41. decl.value = (parseInt(decl.value) + 1).toString();
  42. return _Declaration.prototype.set.call(this, decl, prefix);
  43. } else {
  44. return _Declaration.prototype.set.call(this, decl, prefix);
  45. }
  46. };
  47. return Order;
  48. }(Declaration);
  49. Object.defineProperty(Order, 'names', {
  50. enumerable: true,
  51. writable: true,
  52. value: ['order', 'flex-order', 'box-ordinal-group']
  53. });
  54. module.exports = Order;