align-self.js 2.3 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 _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }
  4. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  5. var flexSpec = require('./flex-spec');
  6. var Declaration = require('../declaration');
  7. var AlignSelf = /*#__PURE__*/function (_Declaration) {
  8. _inheritsLoose(AlignSelf, _Declaration);
  9. function AlignSelf() {
  10. return _Declaration.apply(this, arguments) || this;
  11. }
  12. var _proto = AlignSelf.prototype;
  13. _proto.check = function check(decl) {
  14. return decl.parent && !decl.parent.some(function (i) {
  15. return i.prop && i.prop.startsWith('grid-');
  16. });
  17. }
  18. /**
  19. * Change property name for 2012 specs
  20. */
  21. ;
  22. _proto.prefixed = function prefixed(prop, prefix) {
  23. var spec;
  24. var _flexSpec = flexSpec(prefix);
  25. spec = _flexSpec[0];
  26. prefix = _flexSpec[1];
  27. if (spec === 2012) {
  28. return prefix + 'flex-item-align';
  29. }
  30. return _Declaration.prototype.prefixed.call(this, prop, prefix);
  31. }
  32. /**
  33. * Return property name by final spec
  34. */
  35. ;
  36. _proto.normalize = function normalize() {
  37. return 'align-self';
  38. }
  39. /**
  40. * Change value for 2012 spec and ignore prefix for 2009
  41. */
  42. ;
  43. _proto.set = function set(decl, prefix) {
  44. var spec = flexSpec(prefix)[0];
  45. if (spec === 2012) {
  46. decl.value = AlignSelf.oldValues[decl.value] || decl.value;
  47. return _Declaration.prototype.set.call(this, decl, prefix);
  48. }
  49. if (spec === 'final') {
  50. return _Declaration.prototype.set.call(this, decl, prefix);
  51. }
  52. return undefined;
  53. };
  54. return AlignSelf;
  55. }(Declaration);
  56. _defineProperty(AlignSelf, "names", ['align-self', 'flex-item-align']);
  57. _defineProperty(AlignSelf, "oldValues", {
  58. 'flex-end': 'end',
  59. 'flex-start': 'start'
  60. });
  61. module.exports = AlignSelf;