display-flex.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. let flexSpec = require('./flex-spec')
  2. let OldValue = require('../old-value')
  3. let Value = require('../value')
  4. class DisplayFlex extends Value {
  5. constructor(name, prefixes) {
  6. super(name, prefixes)
  7. if (name === 'display-flex') {
  8. this.name = 'flex'
  9. }
  10. }
  11. /**
  12. * Faster check for flex value
  13. */
  14. check(decl) {
  15. return decl.prop === 'display' && decl.value === this.name
  16. }
  17. /**
  18. * Return value by spec
  19. */
  20. prefixed(prefix) {
  21. let spec, value
  22. ;[spec, prefix] = flexSpec(prefix)
  23. if (spec === 2009) {
  24. if (this.name === 'flex') {
  25. value = 'box'
  26. } else {
  27. value = 'inline-box'
  28. }
  29. } else if (spec === 2012) {
  30. if (this.name === 'flex') {
  31. value = 'flexbox'
  32. } else {
  33. value = 'inline-flexbox'
  34. }
  35. } else if (spec === 'final') {
  36. value = this.name
  37. }
  38. return prefix + value
  39. }
  40. /**
  41. * Add prefix to value depend on flebox spec version
  42. */
  43. replace(string, prefix) {
  44. return this.prefixed(prefix)
  45. }
  46. /**
  47. * Change value for old specs
  48. */
  49. old(prefix) {
  50. let prefixed = this.prefixed(prefix)
  51. if (!prefixed) return undefined
  52. return new OldValue(this.name, prefixed)
  53. }
  54. }
  55. DisplayFlex.names = ['display-flex', 'inline-flex']
  56. module.exports = DisplayFlex