source: imaps-frontend/node_modules/inline-style-prefixer/lib/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
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _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"); } }; }();
8
9exports.default = grid;
10function isSimplePositionValue(value) {
11 return typeof value === 'number' && !isNaN(value);
12}
13
14function isComplexSpanValue(value) {
15 return typeof value === 'string' && value.includes('/');
16}
17
18var alignmentValues = ['center', 'end', 'start', 'stretch'];
19
20var displayValues = {
21 'inline-grid': ['-ms-inline-grid', 'inline-grid'],
22 grid: ['-ms-grid', 'grid']
23};
24
25var propertyConverters = {
26 alignSelf: function alignSelf(value, style) {
27 if (alignmentValues.indexOf(value) > -1) {
28 style.msGridRowAlign = value;
29 }
30 },
31
32 gridColumn: function gridColumn(value, style) {
33 if (isSimplePositionValue(value)) {
34 style.msGridColumn = value;
35 } else if (isComplexSpanValue(value)) {
36 var _value$split = value.split('/'),
37 _value$split2 = _slicedToArray(_value$split, 2),
38 start = _value$split2[0],
39 end = _value$split2[1];
40
41 propertyConverters.gridColumnStart(+start, style);
42
43 var _end$split = end.split(/ ?span /),
44 _end$split2 = _slicedToArray(_end$split, 2),
45 maybeSpan = _end$split2[0],
46 maybeNumber = _end$split2[1];
47
48 if (maybeSpan === '') {
49 propertyConverters.gridColumnEnd(+start + +maybeNumber, style);
50 } else {
51 propertyConverters.gridColumnEnd(+end, style);
52 }
53 } else {
54 propertyConverters.gridColumnStart(value, style);
55 }
56 },
57
58 gridColumnEnd: function gridColumnEnd(value, style) {
59 var msGridColumn = style.msGridColumn;
60
61 if (isSimplePositionValue(value) && isSimplePositionValue(msGridColumn)) {
62 style.msGridColumnSpan = value - msGridColumn;
63 }
64 },
65
66 gridColumnStart: function gridColumnStart(value, style) {
67 if (isSimplePositionValue(value)) {
68 style.msGridColumn = value;
69 }
70 },
71
72 gridRow: function gridRow(value, style) {
73 if (isSimplePositionValue(value)) {
74 style.msGridRow = value;
75 } else if (isComplexSpanValue(value)) {
76 var _value$split3 = value.split('/'),
77 _value$split4 = _slicedToArray(_value$split3, 2),
78 start = _value$split4[0],
79 end = _value$split4[1];
80
81 propertyConverters.gridRowStart(+start, style);
82
83 var _end$split3 = end.split(/ ?span /),
84 _end$split4 = _slicedToArray(_end$split3, 2),
85 maybeSpan = _end$split4[0],
86 maybeNumber = _end$split4[1];
87
88 if (maybeSpan === '') {
89 propertyConverters.gridRowEnd(+start + +maybeNumber, style);
90 } else {
91 propertyConverters.gridRowEnd(+end, style);
92 }
93 } else {
94 propertyConverters.gridRowStart(value, style);
95 }
96 },
97
98 gridRowEnd: function gridRowEnd(value, style) {
99 var msGridRow = style.msGridRow;
100
101 if (isSimplePositionValue(value) && isSimplePositionValue(msGridRow)) {
102 style.msGridRowSpan = value - msGridRow;
103 }
104 },
105
106 gridRowStart: function gridRowStart(value, style) {
107 if (isSimplePositionValue(value)) {
108 style.msGridRow = value;
109 }
110 },
111
112 gridTemplateColumns: function gridTemplateColumns(value, style) {
113 style.msGridColumns = value;
114 },
115
116 gridTemplateRows: function gridTemplateRows(value, style) {
117 style.msGridRows = value;
118 },
119
120 justifySelf: function justifySelf(value, style) {
121 if (alignmentValues.indexOf(value) > -1) {
122 style.msGridColumnAlign = value;
123 }
124 }
125};
126
127function grid(property, value, style) {
128 if (property === 'display' && value in displayValues) {
129 return displayValues[value];
130 }
131
132 if (property in propertyConverters) {
133 var propertyConverter = propertyConverters[property];
134 propertyConverter(value, style);
135 }
136}
Note: See TracBrowser for help on using the repository browser.