justify-content.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 JustifyContent = function (_Declaration) {
  8. _inherits(JustifyContent, _Declaration);
  9. function JustifyContent() {
  10. _classCallCheck(this, JustifyContent);
  11. return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
  12. }
  13. /**
  14. * Change property name for 2009 and 2012 specs
  15. */
  16. JustifyContent.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-pack';
  23. } else if (spec === 2012) {
  24. return prefix + 'flex-pack';
  25. } else {
  26. return _Declaration.prototype.prefixed.call(this, prop, prefix);
  27. }
  28. };
  29. /**
  30. * Return property name by final spec
  31. */
  32. JustifyContent.prototype.normalize = function normalize() {
  33. return 'justify-content';
  34. };
  35. /**
  36. * Change value for 2009 and 2012 specs
  37. */
  38. JustifyContent.prototype.set = function set(decl, prefix) {
  39. var spec = flexSpec(prefix)[0];
  40. if (spec === 2009 || spec === 2012) {
  41. var value = JustifyContent.oldValues[decl.value] || decl.value;
  42. decl.value = value;
  43. if (spec !== 2009 || value !== 'distribute') {
  44. return _Declaration.prototype.set.call(this, decl, prefix);
  45. }
  46. } else if (spec === 'final') {
  47. return _Declaration.prototype.set.call(this, decl, prefix);
  48. }
  49. return undefined;
  50. };
  51. return JustifyContent;
  52. }(Declaration);
  53. Object.defineProperty(JustifyContent, 'names', {
  54. enumerable: true,
  55. writable: true,
  56. value: ['justify-content', 'flex-pack', 'box-pack']
  57. });
  58. Object.defineProperty(JustifyContent, 'oldValues', {
  59. enumerable: true,
  60. writable: true,
  61. value: {
  62. 'flex-end': 'end',
  63. 'flex-start': 'start',
  64. 'space-between': 'justify',
  65. 'space-around': 'distribute'
  66. }
  67. });
  68. module.exports = JustifyContent;