grid-end.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. 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; }
  5. 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) : _defaults(subClass, superClass); }
  6. var Declaration = require('../declaration');
  7. var GridEnd = function (_Declaration) {
  8. _inherits(GridEnd, _Declaration);
  9. function GridEnd() {
  10. _classCallCheck(this, GridEnd);
  11. return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
  12. }
  13. /**
  14. * Change repeating syntax for IE
  15. */
  16. GridEnd.prototype.insert = function insert(decl, prefix, prefixes, result) {
  17. if (prefix !== '-ms-') return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  18. var clonedDecl = this.clone(decl);
  19. var startProp = decl.prop.replace(/end$/, 'start');
  20. var spanProp = prefix + decl.prop.replace(/end$/, 'span');
  21. if (decl.parent.some(function (i) {
  22. return i.prop === spanProp;
  23. })) {
  24. return undefined;
  25. }
  26. clonedDecl.prop = spanProp;
  27. if (decl.value.includes('span')) {
  28. clonedDecl.value = decl.value.replace(/span\s/i, '');
  29. } else {
  30. var startDecl = void 0;
  31. decl.parent.walkDecls(startProp, function (d) {
  32. startDecl = d;
  33. });
  34. if (startDecl) {
  35. var value = Number(decl.value) - Number(startDecl.value) + '';
  36. clonedDecl.value = value;
  37. } else {
  38. decl.warn(result, 'Can not prefix ' + decl.prop + ' (' + startProp + ' is not found)');
  39. }
  40. }
  41. decl.cloneBefore(clonedDecl);
  42. return undefined;
  43. };
  44. return GridEnd;
  45. }(Declaration);
  46. Object.defineProperty(GridEnd, 'names', {
  47. enumerable: true,
  48. writable: true,
  49. value: ['grid-row-end', 'grid-column-end']
  50. });
  51. module.exports = GridEnd;