align-self.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use strict';
  2. function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. 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; }
  5. 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) : _defaults(subClass, superClass); }
  6. var flexSpec = require('./flex-spec');
  7. var Declaration = require('../declaration');
  8. var AlignSelf = function (_Declaration) {
  9. _inherits(AlignSelf, _Declaration);
  10. function AlignSelf() {
  11. _classCallCheck(this, AlignSelf);
  12. return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
  13. }
  14. /**
  15. * Change property name for 2012 specs
  16. */
  17. AlignSelf.prototype.prefixed = function prefixed(prop, prefix) {
  18. var spec = void 0;
  19. var _flexSpec = flexSpec(prefix);
  20. spec = _flexSpec[0];
  21. prefix = _flexSpec[1];
  22. if (spec === 2012) {
  23. return prefix + 'flex-item-align';
  24. } else {
  25. return _Declaration.prototype.prefixed.call(this, prop, prefix);
  26. }
  27. };
  28. /**
  29. * Return property name by final spec
  30. */
  31. AlignSelf.prototype.normalize = function normalize() {
  32. return 'align-self';
  33. };
  34. /**
  35. * Change value for 2012 spec and ignore prefix for 2009
  36. */
  37. AlignSelf.prototype.set = function set(decl, prefix) {
  38. var spec = flexSpec(prefix)[0];
  39. if (spec === 2012) {
  40. decl.value = AlignSelf.oldValues[decl.value] || decl.value;
  41. return _Declaration.prototype.set.call(this, decl, prefix);
  42. } else if (spec === 'final') {
  43. return _Declaration.prototype.set.call(this, decl, prefix);
  44. }
  45. return undefined;
  46. };
  47. return AlignSelf;
  48. }(Declaration);
  49. Object.defineProperty(AlignSelf, 'names', {
  50. enumerable: true,
  51. writable: true,
  52. value: ['align-self', 'flex-item-align']
  53. });
  54. Object.defineProperty(AlignSelf, 'oldValues', {
  55. enumerable: true,
  56. writable: true,
  57. value: {
  58. 'flex-end': 'end',
  59. 'flex-start': 'start'
  60. }
  61. });
  62. module.exports = AlignSelf;