break-props.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. let Declaration = require('../declaration')
  2. class BreakProps extends Declaration {
  3. /**
  4. * Change name for -webkit- and -moz- prefix
  5. */
  6. prefixed(prop, prefix) {
  7. return `${prefix}column-${prop}`
  8. }
  9. /**
  10. * Return property name by final spec
  11. */
  12. normalize(prop) {
  13. if (prop.includes('inside')) {
  14. return 'break-inside'
  15. }
  16. if (prop.includes('before')) {
  17. return 'break-before'
  18. }
  19. return 'break-after'
  20. }
  21. /**
  22. * Change prefixed value for avoid-column and avoid-page
  23. */
  24. set(decl, prefix) {
  25. if (
  26. (decl.prop === 'break-inside' && decl.value === 'avoid-column') ||
  27. decl.value === 'avoid-page'
  28. ) {
  29. decl.value = 'avoid'
  30. }
  31. return super.set(decl, prefix)
  32. }
  33. /**
  34. * Don’t prefix some values
  35. */
  36. insert(decl, prefix, prefixes) {
  37. if (decl.prop !== 'break-inside') {
  38. return super.insert(decl, prefix, prefixes)
  39. }
  40. if (/region/i.test(decl.value) || /page/i.test(decl.value)) {
  41. return undefined
  42. }
  43. return super.insert(decl, prefix, prefixes)
  44. }
  45. }
  46. BreakProps.names = [
  47. 'break-inside',
  48. 'page-break-inside',
  49. 'column-break-inside',
  50. 'break-before',
  51. 'page-break-before',
  52. 'column-break-before',
  53. 'break-after',
  54. 'page-break-after',
  55. 'column-break-after'
  56. ]
  57. module.exports = BreakProps