grid-row-column.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 shorthand = require('./grid-shorthand');
  7. var GridRowColumn = function (_Declaration) {
  8. _inherits(GridRowColumn, _Declaration);
  9. function GridRowColumn() {
  10. _classCallCheck(this, GridRowColumn);
  11. return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
  12. }
  13. /**
  14. * Translate grid-row / grid-column to separate -ms- prefixed properties
  15. */
  16. GridRowColumn.prototype.insert = function insert(decl, prefix, prefixes) {
  17. if (prefix !== '-ms-') return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  18. var values = shorthand.parse(decl);
  19. var _shorthand$translate = shorthand.translate(values, 0, 1),
  20. start = _shorthand$translate[0],
  21. span = _shorthand$translate[1];
  22. if (start) {
  23. decl.cloneBefore({
  24. prop: '-ms-' + decl.prop,
  25. value: start.toString()
  26. });
  27. }
  28. if (span) {
  29. decl.cloneBefore({
  30. prop: '-ms-' + decl.prop + '-span',
  31. value: span.toString()
  32. });
  33. }
  34. return undefined;
  35. };
  36. return GridRowColumn;
  37. }(Declaration);
  38. Object.defineProperty(GridRowColumn, 'names', {
  39. enumerable: true,
  40. writable: true,
  41. value: ['grid-row', 'grid-column']
  42. });
  43. module.exports = GridRowColumn;