align-self.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. let flexSpec = require('./flex-spec')
  2. let Declaration = require('../declaration')
  3. class AlignSelf extends Declaration {
  4. check(decl) {
  5. return (
  6. decl.parent &&
  7. !decl.parent.some(i => {
  8. return i.prop && i.prop.startsWith('grid-')
  9. })
  10. )
  11. }
  12. /**
  13. * Change property name for 2012 specs
  14. */
  15. prefixed(prop, prefix) {
  16. let spec
  17. ;[spec, prefix] = flexSpec(prefix)
  18. if (spec === 2012) {
  19. return prefix + 'flex-item-align'
  20. }
  21. return super.prefixed(prop, prefix)
  22. }
  23. /**
  24. * Return property name by final spec
  25. */
  26. normalize() {
  27. return 'align-self'
  28. }
  29. /**
  30. * Change value for 2012 spec and ignore prefix for 2009
  31. */
  32. set(decl, prefix) {
  33. let spec = flexSpec(prefix)[0]
  34. if (spec === 2012) {
  35. decl.value = AlignSelf.oldValues[decl.value] || decl.value
  36. return super.set(decl, prefix)
  37. }
  38. if (spec === 'final') {
  39. return super.set(decl, prefix)
  40. }
  41. return undefined
  42. }
  43. }
  44. AlignSelf.names = ['align-self', 'flex-item-align']
  45. AlignSelf.oldValues = {
  46. 'flex-end': 'end',
  47. 'flex-start': 'start'
  48. }
  49. module.exports = AlignSelf