align-items.js 2.6 KB

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