order.js 907 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. let flexSpec = require('./flex-spec')
  2. let Declaration = require('../declaration')
  3. class Order 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-ordinal-group'
  12. }
  13. if (spec === 2012) {
  14. return prefix + 'flex-order'
  15. }
  16. return super.prefixed(prop, prefix)
  17. }
  18. /**
  19. * Return property name by final spec
  20. */
  21. normalize() {
  22. return 'order'
  23. }
  24. /**
  25. * Fix value for 2009 spec
  26. */
  27. set(decl, prefix) {
  28. let spec = flexSpec(prefix)[0]
  29. if (spec === 2009 && /\d/.test(decl.value)) {
  30. decl.value = (parseInt(decl.value) + 1).toString()
  31. return super.set(decl, prefix)
  32. }
  33. return super.set(decl, prefix)
  34. }
  35. }
  36. Order.names = ['order', 'flex-order', 'box-ordinal-group']
  37. module.exports = Order