grid-template.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 GridTemplate = function (_Declaration) {
  8. _inherits(GridTemplate, _Declaration);
  9. function GridTemplate() {
  10. _classCallCheck(this, GridTemplate);
  11. return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
  12. }
  13. /**
  14. * Do not add prefix for unsupported value in IE
  15. */
  16. GridTemplate.prototype.check = function check(decl) {
  17. return decl.value.includes('/') && !decl.value.includes('[') && !decl.value.includes('"') && !decl.value.includes('\'');
  18. };
  19. /**
  20. * Translate grid-template to separate -ms- prefixed properties
  21. */
  22. GridTemplate.prototype.insert = function insert(decl, prefix, prefixes) {
  23. if (prefix !== '-ms-') return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  24. if (decl.parent.some(function (i) {
  25. return i.prop === '-ms-grid-rows';
  26. })) {
  27. return undefined;
  28. }
  29. var _shorthand$parseTempl = shorthand.parseTemplateShortcut(decl),
  30. templateRows = _shorthand$parseTempl[0],
  31. templateColumns = _shorthand$parseTempl[1];
  32. if (templateRows) {
  33. decl.cloneBefore({
  34. prop: '-ms-grid-rows',
  35. value: shorthand.changeRepeat(templateRows.join(''))
  36. });
  37. }
  38. if (templateColumns) {
  39. decl.cloneBefore({
  40. prop: '-ms-grid-columns',
  41. value: shorthand.changeRepeat(templateColumns.join(''))
  42. });
  43. }
  44. return decl;
  45. };
  46. return GridTemplate;
  47. }(Declaration);
  48. Object.defineProperty(GridTemplate, 'names', {
  49. enumerable: true,
  50. writable: true,
  51. value: ['grid-template']
  52. });
  53. module.exports = GridTemplate;