You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.7 KiB

4 years ago
  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 _require = require('./grid-utils'),
  7. parseTemplate = _require.parseTemplate,
  8. warnMissedAreas = _require.warnMissedAreas,
  9. getGridGap = _require.getGridGap,
  10. warnGridGap = _require.warnGridGap,
  11. inheritGridGap = _require.inheritGridGap;
  12. var GridTemplate =
  13. /*#__PURE__*/
  14. function (_Declaration) {
  15. _inheritsLoose(GridTemplate, _Declaration);
  16. function GridTemplate() {
  17. return _Declaration.apply(this, arguments) || this;
  18. }
  19. var _proto = GridTemplate.prototype;
  20. /**
  21. * Translate grid-template to separate -ms- prefixed properties
  22. */
  23. _proto.insert = function insert(decl, prefix, prefixes, result) {
  24. if (prefix !== '-ms-') return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  25. if (decl.parent.some(function (i) {
  26. return i.prop === '-ms-grid-rows';
  27. })) {
  28. return undefined;
  29. }
  30. var gap = getGridGap(decl);
  31. /**
  32. * we must insert inherited gap values in some cases:
  33. * if we are inside media query && if we have no grid-gap value
  34. */
  35. var inheritedGap = inheritGridGap(decl, gap);
  36. var _parseTemplate = parseTemplate({
  37. decl: decl,
  38. gap: inheritedGap || gap
  39. }),
  40. rows = _parseTemplate.rows,
  41. columns = _parseTemplate.columns,
  42. areas = _parseTemplate.areas;
  43. var hasAreas = Object.keys(areas).length > 0;
  44. var hasRows = Boolean(rows);
  45. var hasColumns = Boolean(columns);
  46. warnGridGap({
  47. gap: gap,
  48. hasColumns: hasColumns,
  49. decl: decl,
  50. result: result
  51. });
  52. warnMissedAreas(areas, decl, result);
  53. if (hasRows && hasColumns || hasAreas) {
  54. decl.cloneBefore({
  55. prop: '-ms-grid-rows',
  56. value: rows,
  57. raws: {}
  58. });
  59. }
  60. if (hasColumns) {
  61. decl.cloneBefore({
  62. prop: '-ms-grid-columns',
  63. value: columns,
  64. raws: {}
  65. });
  66. }
  67. return decl;
  68. };
  69. return GridTemplate;
  70. }(Declaration);
  71. _defineProperty(GridTemplate, "names", ['grid-template']);
  72. module.exports = GridTemplate;