break-props.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
  3. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }
  4. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  5. var Declaration = require('../declaration');
  6. var BreakProps = /*#__PURE__*/function (_Declaration) {
  7. _inheritsLoose(BreakProps, _Declaration);
  8. function BreakProps() {
  9. return _Declaration.apply(this, arguments) || this;
  10. }
  11. var _proto = BreakProps.prototype;
  12. /**
  13. * Change name for -webkit- and -moz- prefix
  14. */
  15. _proto.prefixed = function prefixed(prop, prefix) {
  16. return prefix + "column-" + prop;
  17. }
  18. /**
  19. * Return property name by final spec
  20. */
  21. ;
  22. _proto.normalize = function normalize(prop) {
  23. if (prop.includes('inside')) {
  24. return 'break-inside';
  25. }
  26. if (prop.includes('before')) {
  27. return 'break-before';
  28. }
  29. return 'break-after';
  30. }
  31. /**
  32. * Change prefixed value for avoid-column and avoid-page
  33. */
  34. ;
  35. _proto.set = function set(decl, prefix) {
  36. if (decl.prop === 'break-inside' && decl.value === 'avoid-column' || decl.value === 'avoid-page') {
  37. decl.value = 'avoid';
  38. }
  39. return _Declaration.prototype.set.call(this, decl, prefix);
  40. }
  41. /**
  42. * Don’t prefix some values
  43. */
  44. ;
  45. _proto.insert = function insert(decl, prefix, prefixes) {
  46. if (decl.prop !== 'break-inside') {
  47. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  48. }
  49. if (/region/i.test(decl.value) || /page/i.test(decl.value)) {
  50. return undefined;
  51. }
  52. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  53. };
  54. return BreakProps;
  55. }(Declaration);
  56. _defineProperty(BreakProps, "names", ['break-inside', 'page-break-inside', 'column-break-inside', 'break-before', 'page-break-before', 'column-break-before', 'break-after', 'page-break-after', 'column-break-after']);
  57. module.exports = BreakProps;