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.

102 lines
3.3 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. parseGridAreas = _require.parseGridAreas,
  8. warnMissedAreas = _require.warnMissedAreas,
  9. prefixTrackProp = _require.prefixTrackProp,
  10. prefixTrackValue = _require.prefixTrackValue,
  11. getGridGap = _require.getGridGap,
  12. warnGridGap = _require.warnGridGap,
  13. inheritGridGap = _require.inheritGridGap;
  14. function getGridRows(tpl) {
  15. return tpl.trim().slice(1, -1).split(/["']\s*["']?/g);
  16. }
  17. var GridTemplateAreas =
  18. /*#__PURE__*/
  19. function (_Declaration) {
  20. _inheritsLoose(GridTemplateAreas, _Declaration);
  21. function GridTemplateAreas() {
  22. return _Declaration.apply(this, arguments) || this;
  23. }
  24. var _proto = GridTemplateAreas.prototype;
  25. /**
  26. * Translate grid-template-areas to separate -ms- prefixed properties
  27. */
  28. _proto.insert = function insert(decl, prefix, prefixes, result) {
  29. if (prefix !== '-ms-') return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  30. var hasColumns = false;
  31. var hasRows = false;
  32. var parent = decl.parent;
  33. var gap = getGridGap(decl);
  34. gap = inheritGridGap(decl, gap) || gap; // remove already prefixed rows
  35. // to prevent doubling prefixes
  36. parent.walkDecls(/-ms-grid-rows/, function (i) {
  37. return i.remove();
  38. }); // add empty tracks to rows
  39. parent.walkDecls(/grid-template-(rows|columns)/, function (trackDecl) {
  40. if (trackDecl.prop === 'grid-template-rows') {
  41. hasRows = true;
  42. var prop = trackDecl.prop,
  43. value = trackDecl.value;
  44. trackDecl.cloneBefore({
  45. prop: prefixTrackProp({
  46. prop: prop,
  47. prefix: prefix
  48. }),
  49. value: prefixTrackValue({
  50. value: value,
  51. gap: gap.row
  52. })
  53. });
  54. } else {
  55. hasColumns = true;
  56. }
  57. });
  58. var gridRows = getGridRows(decl.value);
  59. if (hasColumns && !hasRows && gap.row && gridRows.length > 1) {
  60. decl.cloneBefore({
  61. prop: '-ms-grid-rows',
  62. value: prefixTrackValue({
  63. value: "repeat(" + gridRows.length + ", auto)",
  64. gap: gap.row
  65. }),
  66. raws: {}
  67. });
  68. } // warnings
  69. warnGridGap({
  70. gap: gap,
  71. hasColumns: hasColumns,
  72. decl: decl,
  73. result: result
  74. });
  75. var areas = parseGridAreas({
  76. rows: gridRows,
  77. gap: gap
  78. });
  79. warnMissedAreas(areas, decl, result);
  80. return decl;
  81. };
  82. return GridTemplateAreas;
  83. }(Declaration);
  84. _defineProperty(GridTemplateAreas, "names", ['grid-template-areas']);
  85. module.exports = GridTemplateAreas;