grid-area.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 GridArea = function (_Declaration) {
  8. _inherits(GridArea, _Declaration);
  9. function GridArea() {
  10. _classCallCheck(this, GridArea);
  11. return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
  12. }
  13. /**
  14. * Translate grid-area to separate -ms- prefixed properties
  15. */
  16. GridArea.prototype.insert = function insert(decl, prefix, prefixes) {
  17. if (prefix !== '-ms-') return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  18. if (decl.parent.some(function (i) {
  19. return i.prop === '-ms-grid-row';
  20. })) {
  21. return undefined;
  22. }
  23. var values = shorthand.parse(decl);
  24. var _shorthand$translate = shorthand.translate(values, 0, 2),
  25. rowStart = _shorthand$translate[0],
  26. rowSpan = _shorthand$translate[1];
  27. var _shorthand$translate2 = shorthand.translate(values, 1, 3),
  28. columnStart = _shorthand$translate2[0],
  29. columnSpan = _shorthand$translate2[1];
  30. if (rowStart) {
  31. decl.cloneBefore({
  32. prop: '-ms-grid-row',
  33. value: rowStart.toString()
  34. });
  35. }
  36. if (rowSpan) {
  37. decl.cloneBefore({
  38. prop: '-ms-grid-row-span',
  39. value: rowSpan.toString()
  40. });
  41. }
  42. if (columnStart) {
  43. decl.cloneBefore({
  44. prop: '-ms-grid-column',
  45. value: columnStart.toString()
  46. });
  47. }
  48. if (columnSpan) {
  49. decl.cloneBefore({
  50. prop: '-ms-grid-column-span',
  51. value: columnSpan.toString()
  52. });
  53. }
  54. return undefined;
  55. };
  56. return GridArea;
  57. }(Declaration);
  58. Object.defineProperty(GridArea, 'names', {
  59. enumerable: true,
  60. writable: true,
  61. value: ['grid-area']
  62. });
  63. module.exports = GridArea;