order.js 907 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. let flexSpec = require('./flex-spec')
  2. let Declaration = require('../declaration')
  3. class Order extends Declaration {
  4. /**
  5. * Return property name by final spec
  6. */
  7. normalize() {
  8. return 'order'
  9. }
  10. /**
  11. * Change property name for 2009 and 2012 specs
  12. */
  13. prefixed(prop, prefix) {
  14. let spec
  15. ;[spec, prefix] = flexSpec(prefix)
  16. if (spec === 2009) {
  17. return prefix + 'box-ordinal-group'
  18. }
  19. if (spec === 2012) {
  20. return prefix + 'flex-order'
  21. }
  22. return super.prefixed(prop, prefix)
  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