break-props.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. var Declaration = require('../declaration');
  6. var BreakProps = function (_Declaration) {
  7. _inherits(BreakProps, _Declaration);
  8. function BreakProps() {
  9. _classCallCheck(this, BreakProps);
  10. return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
  11. }
  12. /**
  13. * Change name for -webkit- and -moz- prefix
  14. */
  15. BreakProps.prototype.prefixed = function prefixed(prop, prefix) {
  16. if (prefix === '-moz-') {
  17. return 'page-' + prop;
  18. } else {
  19. return prefix + 'column-' + prop;
  20. }
  21. };
  22. /**
  23. * Return property name by final spec
  24. */
  25. BreakProps.prototype.normalize = function normalize(prop) {
  26. if (prop.indexOf('inside') !== -1) {
  27. return 'break-inside';
  28. } else if (prop.indexOf('before') !== -1) {
  29. return 'break-before';
  30. } else {
  31. return 'break-after';
  32. }
  33. };
  34. /**
  35. * Change prefixed value for avoid-column and avoid-page
  36. */
  37. BreakProps.prototype.set = function set(decl, prefix) {
  38. if (decl.prop === 'break-inside' && decl.value === 'avoid-column' || decl.value === 'avoid-page') {
  39. decl.value = 'avoid';
  40. }
  41. return _Declaration.prototype.set.call(this, decl, prefix);
  42. };
  43. /**
  44. * Don’t prefix some values
  45. */
  46. BreakProps.prototype.insert = function insert(decl, prefix, prefixes) {
  47. if (decl.prop !== 'break-inside') {
  48. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  49. } else if (decl.value === 'avoid-region') {
  50. return undefined;
  51. } else if (decl.value === 'avoid-page' && prefix === '-webkit-') {
  52. return undefined;
  53. } else {
  54. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  55. }
  56. };
  57. return BreakProps;
  58. }(Declaration);
  59. Object.defineProperty(BreakProps, 'names', {
  60. enumerable: true,
  61. writable: true,
  62. value: ['break-inside', 'page-break-inside', 'column-break-inside', 'break-before', 'page-break-before', 'column-break-before', 'break-after', 'page-break-after', 'column-break-after']
  63. });
  64. module.exports = BreakProps;