grid-template.js 2.7 KB

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