justify-content.js 1.2 KB

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