source: trip-planner-front/node_modules/postcss-ordered-values/dist/rules/grid.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.9 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.normalizeGridColumnRow = exports.normalizeGridColumnRowGap = exports.normalizeGridAutoFlow = void 0;
7
8var _joinGridValue = _interopRequireDefault(require("../lib/joinGridValue"));
9
10function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12const normalizeGridAutoFlow = gridAutoFlow => {
13 let newValue = {
14 front: '',
15 back: ''
16 };
17 let shouldNormalize = false;
18 gridAutoFlow.walk(node => {
19 if (node.value === 'dense') {
20 shouldNormalize = true;
21 newValue.back = node.value;
22 } else if (['row', 'column'].includes(node.value.trim().toLowerCase())) {
23 shouldNormalize = true;
24 newValue.front = node.value;
25 } else {
26 shouldNormalize = false;
27 }
28 });
29
30 if (shouldNormalize) {
31 return `${newValue.front.trim()} ${newValue.back.trim()}`;
32 }
33
34 return gridAutoFlow;
35};
36
37exports.normalizeGridAutoFlow = normalizeGridAutoFlow;
38
39const normalizeGridColumnRowGap = gridGap => {
40 let newValue = {
41 front: '',
42 back: ''
43 };
44 let shouldNormalize = false;
45 gridGap.walk(node => {
46 // console.log(node);
47 if (node.value === 'normal') {
48 shouldNormalize = true;
49 newValue.front = node.value;
50 } else {
51 newValue.back = `${newValue.back} ${node.value}`;
52 }
53 });
54
55 if (shouldNormalize) {
56 return `${newValue.front.trim()} ${newValue.back.trim()}`;
57 }
58
59 return gridGap;
60};
61
62exports.normalizeGridColumnRowGap = normalizeGridColumnRowGap;
63
64const normalizeGridColumnRow = grid => {
65 // cant do normalization here using node, so copy it as a string
66 let gridValue = grid.toString().split('/'); // node -> string value, split -> " 2 / 3 span " -> [' 2','3 span ']
67
68 if (gridValue.length > 1) {
69 return (0, _joinGridValue.default)(gridValue.map(gridLine => {
70 let normalizeValue = {
71 front: '',
72 back: ''
73 };
74 gridLine = gridLine.trim(); // '3 span ' -> '3 span'
75
76 gridLine.split(' ').forEach(node => {
77 // ['3','span']
78 if (node === 'span') {
79 normalizeValue.front = node; // span _
80 } else {
81 normalizeValue.back = `${normalizeValue.back} ${node}`; // _ 3
82 }
83 });
84 return `${normalizeValue.front.trim()} ${normalizeValue.back.trim()}`; // span 3
85 }) // returns "2 / span 3"
86 );
87 } // doing this separating if `/` is not present as while joining('/') , it will add `/` at the end
88
89
90 return gridValue.map(gridLine => {
91 let normalizeValue = {
92 front: '',
93 back: ''
94 };
95 gridLine = gridLine.trim();
96 gridLine.split(' ').forEach(node => {
97 if (node === 'span') {
98 normalizeValue.front = node;
99 } else {
100 normalizeValue.back = `${normalizeValue.back} ${node}`;
101 }
102 });
103 return `${normalizeValue.front.trim()} ${normalizeValue.back.trim()}`;
104 });
105};
106
107exports.normalizeGridColumnRow = normalizeGridColumnRow;
Note: See TracBrowser for help on using the repository browser.