grid-end.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 GridEnd = /*#__PURE__*/function (_Declaration) {
  7. _inheritsLoose(GridEnd, _Declaration);
  8. function GridEnd() {
  9. return _Declaration.apply(this, arguments) || this;
  10. }
  11. var _proto = GridEnd.prototype;
  12. /**
  13. * Change repeating syntax for IE
  14. */
  15. _proto.insert = function insert(decl, prefix, prefixes, result) {
  16. if (prefix !== '-ms-') return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  17. var clonedDecl = this.clone(decl);
  18. var startProp = decl.prop.replace(/end$/, 'start');
  19. var spanProp = prefix + decl.prop.replace(/end$/, 'span');
  20. if (decl.parent.some(function (i) {
  21. return i.prop === spanProp;
  22. })) {
  23. return undefined;
  24. }
  25. clonedDecl.prop = spanProp;
  26. if (decl.value.includes('span')) {
  27. clonedDecl.value = decl.value.replace(/span\s/i, '');
  28. } else {
  29. var startDecl;
  30. decl.parent.walkDecls(startProp, function (d) {
  31. startDecl = d;
  32. });
  33. if (startDecl) {
  34. var value = Number(decl.value) - Number(startDecl.value) + '';
  35. clonedDecl.value = value;
  36. } else {
  37. decl.warn(result, "Can not prefix " + decl.prop + " (" + startProp + " is not found)");
  38. }
  39. }
  40. decl.cloneBefore(clonedDecl);
  41. return undefined;
  42. };
  43. return GridEnd;
  44. }(Declaration);
  45. _defineProperty(GridEnd, "names", ['grid-row-end', 'grid-column-end']);
  46. module.exports = GridEnd;