source: imaps-frontend/node_modules/inline-style-prefixer/es/plugins/grid.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[d565449]1var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
2
3function isSimplePositionValue(value) {
4 return typeof value === 'number' && !isNaN(value);
5}
6
7function isComplexSpanValue(value) {
8 return typeof value === 'string' && value.includes('/');
9}
10
11var alignmentValues = ['center', 'end', 'start', 'stretch'];
12
13var displayValues = {
14 'inline-grid': ['-ms-inline-grid', 'inline-grid'],
15 grid: ['-ms-grid', 'grid']
16};
17
18var propertyConverters = {
19 alignSelf: function alignSelf(value, style) {
20 if (alignmentValues.indexOf(value) > -1) {
21 style.msGridRowAlign = value;
22 }
23 },
24
25 gridColumn: function gridColumn(value, style) {
26 if (isSimplePositionValue(value)) {
27 style.msGridColumn = value;
28 } else if (isComplexSpanValue(value)) {
29 var _value$split = value.split('/'),
30 _value$split2 = _slicedToArray(_value$split, 2),
31 start = _value$split2[0],
32 end = _value$split2[1];
33
34 propertyConverters.gridColumnStart(+start, style);
35
36 var _end$split = end.split(/ ?span /),
37 _end$split2 = _slicedToArray(_end$split, 2),
38 maybeSpan = _end$split2[0],
39 maybeNumber = _end$split2[1];
40
41 if (maybeSpan === '') {
42 propertyConverters.gridColumnEnd(+start + +maybeNumber, style);
43 } else {
44 propertyConverters.gridColumnEnd(+end, style);
45 }
46 } else {
47 propertyConverters.gridColumnStart(value, style);
48 }
49 },
50
51 gridColumnEnd: function gridColumnEnd(value, style) {
52 var msGridColumn = style.msGridColumn;
53
54 if (isSimplePositionValue(value) && isSimplePositionValue(msGridColumn)) {
55 style.msGridColumnSpan = value - msGridColumn;
56 }
57 },
58
59 gridColumnStart: function gridColumnStart(value, style) {
60 if (isSimplePositionValue(value)) {
61 style.msGridColumn = value;
62 }
63 },
64
65 gridRow: function gridRow(value, style) {
66 if (isSimplePositionValue(value)) {
67 style.msGridRow = value;
68 } else if (isComplexSpanValue(value)) {
69 var _value$split3 = value.split('/'),
70 _value$split4 = _slicedToArray(_value$split3, 2),
71 start = _value$split4[0],
72 end = _value$split4[1];
73
74 propertyConverters.gridRowStart(+start, style);
75
76 var _end$split3 = end.split(/ ?span /),
77 _end$split4 = _slicedToArray(_end$split3, 2),
78 maybeSpan = _end$split4[0],
79 maybeNumber = _end$split4[1];
80
81 if (maybeSpan === '') {
82 propertyConverters.gridRowEnd(+start + +maybeNumber, style);
83 } else {
84 propertyConverters.gridRowEnd(+end, style);
85 }
86 } else {
87 propertyConverters.gridRowStart(value, style);
88 }
89 },
90
91 gridRowEnd: function gridRowEnd(value, style) {
92 var msGridRow = style.msGridRow;
93
94 if (isSimplePositionValue(value) && isSimplePositionValue(msGridRow)) {
95 style.msGridRowSpan = value - msGridRow;
96 }
97 },
98
99 gridRowStart: function gridRowStart(value, style) {
100 if (isSimplePositionValue(value)) {
101 style.msGridRow = value;
102 }
103 },
104
105 gridTemplateColumns: function gridTemplateColumns(value, style) {
106 style.msGridColumns = value;
107 },
108
109 gridTemplateRows: function gridTemplateRows(value, style) {
110 style.msGridRows = value;
111 },
112
113 justifySelf: function justifySelf(value, style) {
114 if (alignmentValues.indexOf(value) > -1) {
115 style.msGridColumnAlign = value;
116 }
117 }
118};
119
120export default function grid(property, value, style) {
121 if (property === 'display' && value in displayValues) {
122 return displayValues[value];
123 }
124
125 if (property in propertyConverters) {
126 var propertyConverter = propertyConverters[property];
127 propertyConverter(value, style);
128 }
129}
Note: See TracBrowser for help on using the repository browser.