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.

150 lines
4.4 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. prefixTrackProp = _require.prefixTrackProp,
  8. prefixTrackValue = _require.prefixTrackValue,
  9. autoplaceGridItems = _require.autoplaceGridItems,
  10. getGridGap = _require.getGridGap,
  11. inheritGridGap = _require.inheritGridGap;
  12. var Processor = require('../processor');
  13. var GridRowsColumns =
  14. /*#__PURE__*/
  15. function (_Declaration) {
  16. _inheritsLoose(GridRowsColumns, _Declaration);
  17. function GridRowsColumns() {
  18. return _Declaration.apply(this, arguments) || this;
  19. }
  20. var _proto = GridRowsColumns.prototype;
  21. /**
  22. * Change property name for IE
  23. */
  24. _proto.prefixed = function prefixed(prop, prefix) {
  25. if (prefix === '-ms-') {
  26. return prefixTrackProp({
  27. prop: prop,
  28. prefix: prefix
  29. });
  30. }
  31. return _Declaration.prototype.prefixed.call(this, prop, prefix);
  32. }
  33. /**
  34. * Change IE property back
  35. */
  36. ;
  37. _proto.normalize = function normalize(prop) {
  38. return prop.replace(/^grid-(rows|columns)/, 'grid-template-$1');
  39. };
  40. _proto.insert = function insert(decl, prefix, prefixes, result) {
  41. if (prefix !== '-ms-') return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  42. var parent = decl.parent,
  43. prop = decl.prop,
  44. value = decl.value;
  45. var isRowProp = prop.includes('rows');
  46. var isColumnProp = prop.includes('columns');
  47. var hasGridTemplate = parent.some(function (i) {
  48. return i.prop === 'grid-template' || i.prop === 'grid-template-areas';
  49. });
  50. /**
  51. * Not to prefix rows declaration if grid-template(-areas) is present
  52. */
  53. if (hasGridTemplate && isRowProp) {
  54. return false;
  55. }
  56. var processor = new Processor({
  57. options: {}
  58. });
  59. var status = processor.gridStatus(parent, result);
  60. var gap = getGridGap(decl);
  61. gap = inheritGridGap(decl, gap) || gap;
  62. var gapValue = isRowProp ? gap.row : gap.column;
  63. if ((status === 'no-autoplace' || status === true) && !hasGridTemplate) {
  64. gapValue = null;
  65. }
  66. var prefixValue = prefixTrackValue({
  67. value: value,
  68. gap: gapValue
  69. });
  70. /**
  71. * Insert prefixes
  72. */
  73. decl.cloneBefore({
  74. prop: prefixTrackProp({
  75. prop: prop,
  76. prefix: prefix
  77. }),
  78. value: prefixValue
  79. });
  80. var autoflow = parent.nodes.find(function (i) {
  81. return i.prop === 'grid-auto-flow';
  82. });
  83. var autoflowValue = 'row';
  84. if (autoflow && !processor.disabled(autoflow, result)) {
  85. autoflowValue = autoflow.value.trim();
  86. }
  87. if (status === 'autoplace') {
  88. /**
  89. * Show warning if grid-template-rows decl is not found
  90. */
  91. var rowDecl = parent.nodes.find(function (i) {
  92. return i.prop === 'grid-template-rows';
  93. });
  94. if (!rowDecl && hasGridTemplate) {
  95. return undefined;
  96. } else if (!rowDecl && !hasGridTemplate) {
  97. decl.warn(result, 'Autoplacement does not work without grid-template-rows property');
  98. return undefined;
  99. }
  100. /**
  101. * Show warning if grid-template-columns decl is not found
  102. */
  103. var columnDecl = parent.nodes.find(function (i) {
  104. return i.prop === 'grid-template-columns';
  105. });
  106. if (!columnDecl && !hasGridTemplate) {
  107. decl.warn(result, 'Autoplacement does not work without grid-template-columns property');
  108. }
  109. /**
  110. * Autoplace grid items
  111. */
  112. if (isColumnProp && !hasGridTemplate) {
  113. autoplaceGridItems(decl, result, gap, autoflowValue);
  114. }
  115. }
  116. return undefined;
  117. };
  118. return GridRowsColumns;
  119. }(Declaration);
  120. _defineProperty(GridRowsColumns, "names", ['grid-template-rows', 'grid-template-columns', 'grid-rows', 'grid-columns']);
  121. module.exports = GridRowsColumns;