align-self.js 2.7 KB

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