writing-mode.js 1002 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. let Declaration = require('../declaration')
  2. class WritingMode extends Declaration {
  3. insert(decl, prefix, prefixes) {
  4. if (prefix === '-ms-') {
  5. let cloned = this.set(this.clone(decl), prefix)
  6. if (this.needCascade(decl)) {
  7. cloned.raws.before = this.calcBefore(prefixes, decl, prefix)
  8. }
  9. let direction = 'ltr'
  10. decl.parent.nodes.forEach(i => {
  11. if (i.prop === 'direction') {
  12. if (i.value === 'rtl' || i.value === 'ltr') direction = i.value
  13. }
  14. })
  15. cloned.value = WritingMode.msValues[direction][decl.value] || decl.value
  16. return decl.parent.insertBefore(decl, cloned)
  17. }
  18. return super.insert(decl, prefix, prefixes)
  19. }
  20. }
  21. WritingMode.names = ['writing-mode']
  22. WritingMode.msValues = {
  23. ltr: {
  24. 'horizontal-tb': 'lr-tb',
  25. 'vertical-rl': 'tb-rl',
  26. 'vertical-lr': 'tb-lr'
  27. },
  28. rtl: {
  29. 'horizontal-tb': 'rl-tb',
  30. 'vertical-rl': 'bt-rl',
  31. 'vertical-lr': 'bt-lr'
  32. }
  33. }
  34. module.exports = WritingMode