1 | 'use strict';
|
---|
2 |
|
---|
3 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
---|
4 |
|
---|
5 | var postcss = _interopDefault(require('postcss'));
|
---|
6 |
|
---|
7 | var cloneRule = ((decl, dir) => {
|
---|
8 | const rule = Object(decl.parent).type === 'rule' ? decl.parent.clone({
|
---|
9 | raws: {}
|
---|
10 | }).removeAll() : postcss.rule({
|
---|
11 | selector: '&'
|
---|
12 | });
|
---|
13 | rule.selectors = rule.selectors.map(selector => `${selector}:dir(${dir})`);
|
---|
14 | return rule;
|
---|
15 | });
|
---|
16 |
|
---|
17 | const matchLogical = /^\s*logical\s+/i;
|
---|
18 | const matchLogicalBorder = /^border(-width|-style|-color)?$/i;
|
---|
19 | const matchLogicalBorderSide = /^border-(block|block-start|block-end|inline|inline-start|inline-end|start|end)(-(width|style|color))?$/i;
|
---|
20 | var transformBorder = {
|
---|
21 | // border
|
---|
22 | 'border': (decl, values, dir) => {
|
---|
23 | const isLogical = matchLogical.test(values[0]);
|
---|
24 |
|
---|
25 | if (isLogical) {
|
---|
26 | values[0] = values[0].replace(matchLogical, '');
|
---|
27 | }
|
---|
28 |
|
---|
29 | const ltrDecls = [decl.clone({
|
---|
30 | prop: `border-top${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
31 | value: values[0]
|
---|
32 | }), decl.clone({
|
---|
33 | prop: `border-left${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
34 | value: values[1] || values[0]
|
---|
35 | }), decl.clone({
|
---|
36 | prop: `border-bottom${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
37 | value: values[2] || values[0]
|
---|
38 | }), decl.clone({
|
---|
39 | prop: `border-right${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
40 | value: values[3] || values[1] || values[0]
|
---|
41 | })];
|
---|
42 | const rtlDecls = [decl.clone({
|
---|
43 | prop: `border-top${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
44 | value: values[0]
|
---|
45 | }), decl.clone({
|
---|
46 | prop: `border-right${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
47 | value: values[1] || values[0]
|
---|
48 | }), decl.clone({
|
---|
49 | prop: `border-bottom${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
50 | value: values[2] || values[0]
|
---|
51 | }), decl.clone({
|
---|
52 | prop: `border-left${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
53 | value: values[3] || values[1] || values[0]
|
---|
54 | })];
|
---|
55 | return isLogical ? 1 === values.length ? decl.clone({
|
---|
56 | value: decl.value.replace(matchLogical, '')
|
---|
57 | }) : !values[3] || values[3] === values[1] ? [decl.clone({
|
---|
58 | prop: `border-top${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
59 | value: values[0]
|
---|
60 | }), decl.clone({
|
---|
61 | prop: `border-right${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
62 | value: values[3] || values[1] || values[0]
|
---|
63 | }), decl.clone({
|
---|
64 | prop: `border-bottom${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
65 | value: values[2] || values[0]
|
---|
66 | }), decl.clone({
|
---|
67 | prop: `border-left${decl.prop.replace(matchLogicalBorder, '$1')}`,
|
---|
68 | value: values[1] || values[0]
|
---|
69 | })] : 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)] : null;
|
---|
70 | },
|
---|
71 | // border-block
|
---|
72 | 'border-block': (decl, values) => [decl.clone({
|
---|
73 | prop: `border-top${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
74 | value: values[0]
|
---|
75 | }), decl.clone({
|
---|
76 | prop: `border-bottom${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
77 | value: values[0]
|
---|
78 | })],
|
---|
79 | // border-block-start
|
---|
80 | 'border-block-start': decl => {
|
---|
81 | decl.prop = 'border-top';
|
---|
82 | },
|
---|
83 | // border-block-end
|
---|
84 | 'border-block-end': decl => {
|
---|
85 | decl.prop = 'border-bottom';
|
---|
86 | },
|
---|
87 | // border-inline
|
---|
88 | 'border-inline': (decl, values, dir) => {
|
---|
89 | const ltrDecls = [decl.clone({
|
---|
90 | prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
91 | value: values[0]
|
---|
92 | }), decl.clone({
|
---|
93 | prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
94 | value: values[1] || values[0]
|
---|
95 | })];
|
---|
96 | const rtlDecls = [decl.clone({
|
---|
97 | prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
98 | value: values[0]
|
---|
99 | }), decl.clone({
|
---|
100 | prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
101 | value: values[1] || values[0]
|
---|
102 | })];
|
---|
103 | const isLTR = 1 === values.length || 2 === values.length && values[0] === values[1];
|
---|
104 | return isLTR ? ltrDecls : 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
|
---|
105 | },
|
---|
106 | // border-inline-start
|
---|
107 | 'border-inline-start': (decl, values, dir) => {
|
---|
108 | const ltrDecl = decl.clone({
|
---|
109 | prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`
|
---|
110 | });
|
---|
111 | const rtlDecl = decl.clone({
|
---|
112 | prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`
|
---|
113 | });
|
---|
114 | return 'ltr' === dir ? ltrDecl : 'rtl' === dir ? rtlDecl : [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)];
|
---|
115 | },
|
---|
116 | // border-inline-end
|
---|
117 | 'border-inline-end': (decl, values, dir) => {
|
---|
118 | const ltrDecl = decl.clone({
|
---|
119 | prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`
|
---|
120 | });
|
---|
121 | const rtlDecl = decl.clone({
|
---|
122 | prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`
|
---|
123 | });
|
---|
124 | return 'ltr' === dir ? ltrDecl : 'rtl' === dir ? rtlDecl : [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)];
|
---|
125 | },
|
---|
126 | // border-start
|
---|
127 | 'border-start': (decl, values, dir) => {
|
---|
128 | const ltrDecls = [decl.clone({
|
---|
129 | prop: `border-top${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
130 | value: values[0]
|
---|
131 | }), decl.clone({
|
---|
132 | prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
133 | value: values[1] || values[0]
|
---|
134 | })];
|
---|
135 | const rtlDecls = [decl.clone({
|
---|
136 | prop: `border-top${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
137 | value: values[0]
|
---|
138 | }), decl.clone({
|
---|
139 | prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
140 | value: values[1] || values[0]
|
---|
141 | })];
|
---|
142 | return 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
|
---|
143 | },
|
---|
144 | // border-end
|
---|
145 | 'border-end': (decl, values, dir) => {
|
---|
146 | const ltrDecls = [decl.clone({
|
---|
147 | prop: `border-bottom${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
148 | value: values[0]
|
---|
149 | }), decl.clone({
|
---|
150 | prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
151 | value: values[1] || values[0]
|
---|
152 | })];
|
---|
153 | const rtlDecls = [decl.clone({
|
---|
154 | prop: `border-bottom${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
155 | value: values[0]
|
---|
156 | }), decl.clone({
|
---|
157 | prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
|
---|
158 | value: values[1] || values[0]
|
---|
159 | })];
|
---|
160 | return 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
|
---|
161 | }
|
---|
162 | };
|
---|
163 |
|
---|
164 | var transformFloat = ((decl, values, dir) => {
|
---|
165 | const lDecl = decl.clone({
|
---|
166 | value: 'left'
|
---|
167 | });
|
---|
168 | const rDecl = decl.clone({
|
---|
169 | value: 'right'
|
---|
170 | });
|
---|
171 | return /^inline-start$/i.test(decl.value) ? 'ltr' === dir ? lDecl : 'rtl' === dir ? rDecl : [cloneRule(decl, 'ltr').append(lDecl), cloneRule(decl, 'rtl').append(rDecl)] : /^inline-end$/i.test(decl.value) ? 'ltr' === dir ? rDecl : 'rtl' === dir ? lDecl : [cloneRule(decl, 'ltr').append(rDecl), cloneRule(decl, 'rtl').append(lDecl)] : null;
|
---|
172 | });
|
---|
173 |
|
---|
174 | var transformInset = ((decl, values, dir) => {
|
---|
175 | if ('logical' !== values[0]) {
|
---|
176 | return [decl.clone({
|
---|
177 | prop: 'top',
|
---|
178 | value: values[0]
|
---|
179 | }), decl.clone({
|
---|
180 | prop: 'right',
|
---|
181 | value: values[1] || values[0]
|
---|
182 | }), decl.clone({
|
---|
183 | prop: 'bottom',
|
---|
184 | value: values[2] || values[0]
|
---|
185 | }), decl.clone({
|
---|
186 | prop: 'left',
|
---|
187 | value: values[3] || values[1] || values[0]
|
---|
188 | })];
|
---|
189 | }
|
---|
190 |
|
---|
191 | const isLTR = !values[4] || values[4] === values[2];
|
---|
192 | const ltrDecls = [decl.clone({
|
---|
193 | prop: 'top',
|
---|
194 | value: values[1]
|
---|
195 | }), decl.clone({
|
---|
196 | prop: 'left',
|
---|
197 | value: values[2] || values[1]
|
---|
198 | }), decl.clone({
|
---|
199 | prop: 'bottom',
|
---|
200 | value: values[3] || values[1]
|
---|
201 | }), decl.clone({
|
---|
202 | prop: 'right',
|
---|
203 | value: values[4] || values[2] || values[1]
|
---|
204 | })];
|
---|
205 | const rtlDecls = [decl.clone({
|
---|
206 | prop: 'top',
|
---|
207 | value: values[1]
|
---|
208 | }), decl.clone({
|
---|
209 | prop: 'right',
|
---|
210 | value: values[2] || values[1]
|
---|
211 | }), decl.clone({
|
---|
212 | prop: 'bottom',
|
---|
213 | value: values[3] || values[1]
|
---|
214 | }), decl.clone({
|
---|
215 | prop: 'left',
|
---|
216 | value: values[4] || values[2] || values[1]
|
---|
217 | })];
|
---|
218 | return isLTR || 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
|
---|
219 | });
|
---|
220 |
|
---|
221 | var transformResize = (decl => /^block$/i.test(decl.value) ? decl.clone({
|
---|
222 | value: 'vertical'
|
---|
223 | }) : /^inline$/i.test(decl.value) ? decl.clone({
|
---|
224 | value: 'horizontal'
|
---|
225 | }) : null);
|
---|
226 |
|
---|
227 | var matchSide = /^(inset|margin|padding)(?:-(block|block-start|block-end|inline|inline-start|inline-end|start|end))$/i;
|
---|
228 |
|
---|
229 | var matchInsetPrefix = /^inset-/i;
|
---|
230 |
|
---|
231 | var cloneDecl = ((decl, suffix, value) => decl.clone({
|
---|
232 | prop: `${decl.prop.replace(matchSide, '$1')}${suffix}`.replace(matchInsetPrefix, ''),
|
---|
233 | value
|
---|
234 | }));
|
---|
235 |
|
---|
236 | var transformSide = {
|
---|
237 | // inset-block, margin-block, padding-block
|
---|
238 | 'block': (decl, values) => [cloneDecl(decl, '-top', values[0]), cloneDecl(decl, '-bottom', values[1] || values[0])],
|
---|
239 | // inset-block-start, margin-block-start, padding-block-start
|
---|
240 | 'block-start': decl => {
|
---|
241 | decl.prop = decl.prop.replace(matchSide, '$1-top').replace(matchInsetPrefix, '');
|
---|
242 | },
|
---|
243 | // inset-block-end, margin-block-end, padding-block-end
|
---|
244 | 'block-end': decl => {
|
---|
245 | decl.prop = decl.prop.replace(matchSide, '$1-bottom').replace(matchInsetPrefix, '');
|
---|
246 | },
|
---|
247 | // inset-inline, margin-inline, padding-inline
|
---|
248 | 'inline': (decl, values, dir) => {
|
---|
249 | const ltrDecls = [cloneDecl(decl, '-left', values[0]), cloneDecl(decl, '-right', values[1] || values[0])];
|
---|
250 | const rtlDecls = [cloneDecl(decl, '-right', values[0]), cloneDecl(decl, '-left', values[1] || values[0])];
|
---|
251 | const isLTR = 1 === values.length || 2 === values.length && values[0] === values[1];
|
---|
252 | return isLTR ? ltrDecls : 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
|
---|
253 | },
|
---|
254 | // inset-inline-start, margin-inline-start, padding-inline-start
|
---|
255 | 'inline-start': (decl, values, dir) => {
|
---|
256 | const ltrDecl = cloneDecl(decl, '-left', decl.value);
|
---|
257 | const rtlDecl = cloneDecl(decl, '-right', decl.value);
|
---|
258 | return 'ltr' === dir ? ltrDecl : 'rtl' === dir ? rtlDecl : [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)];
|
---|
259 | },
|
---|
260 | // inset-inline-end, margin-inline-end, padding-inline-end
|
---|
261 | 'inline-end': (decl, values, dir) => {
|
---|
262 | const ltrDecl = cloneDecl(decl, '-right', decl.value);
|
---|
263 | const rtlDecl = cloneDecl(decl, '-left', decl.value);
|
---|
264 | return 'ltr' === dir ? ltrDecl : 'rtl' === dir ? rtlDecl : [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)];
|
---|
265 | },
|
---|
266 | // inset-start, margin-start, padding-start
|
---|
267 | 'start': (decl, values, dir) => {
|
---|
268 | const ltrDecls = [cloneDecl(decl, '-top', values[0]), cloneDecl(decl, '-left', values[1] || values[0])];
|
---|
269 | const rtlDecls = [cloneDecl(decl, '-top', values[0]), cloneDecl(decl, '-right', values[1] || values[0])];
|
---|
270 | return 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
|
---|
271 | },
|
---|
272 | // inset-end, margin-end, padding-end
|
---|
273 | 'end': (decl, values, dir) => {
|
---|
274 | const ltrDecls = [cloneDecl(decl, '-bottom', values[0]), cloneDecl(decl, '-right', values[1] || values[0])];
|
---|
275 | const rtlDecls = [cloneDecl(decl, '-bottom', values[0]), cloneDecl(decl, '-left', values[1] || values[0])];
|
---|
276 | return 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
|
---|
277 | }
|
---|
278 | };
|
---|
279 |
|
---|
280 | var matchSize = /^(min-|max-)?(block|inline)-(size)$/i;
|
---|
281 |
|
---|
282 | var transformSize = (decl => {
|
---|
283 | decl.prop = decl.prop.replace(matchSize, ($0, minmax, flow) => `${minmax || ''}${'block' === flow ? 'height' : 'width'}`);
|
---|
284 | });
|
---|
285 |
|
---|
286 | var transformSpacing = ((decl, values, dir) => {
|
---|
287 | if ('logical' !== values[0]) {
|
---|
288 | return null;
|
---|
289 | }
|
---|
290 |
|
---|
291 | const isLTR = !values[4] || values[4] === values[2];
|
---|
292 | const ltrDecl = decl.clone({
|
---|
293 | value: [values[1], values[4] || values[2] || values[1], values[3] || values[1], values[2] || values[1]].join(' ')
|
---|
294 | });
|
---|
295 | const rtlDecl = decl.clone({
|
---|
296 | value: [values[1], values[2] || values[1], values[3] || values[1], values[4] || values[2] || values[1]].join(' ')
|
---|
297 | });
|
---|
298 | return isLTR ? decl.clone({
|
---|
299 | value: decl.value.replace(/^\s*logical\s+/i, '')
|
---|
300 | }) : 'ltr' === dir ? ltrDecl : 'rtl' === dir ? rtlDecl : [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)];
|
---|
301 | });
|
---|
302 |
|
---|
303 | var transformTextAlign = ((decl, values, dir) => {
|
---|
304 | const lDecl = decl.clone({
|
---|
305 | value: 'left'
|
---|
306 | });
|
---|
307 | const rDecl = decl.clone({
|
---|
308 | value: 'right'
|
---|
309 | });
|
---|
310 | return /^start$/i.test(decl.value) ? 'ltr' === dir ? lDecl : 'rtl' === dir ? rDecl : [cloneRule(decl, 'ltr').append(lDecl), cloneRule(decl, 'rtl').append(rDecl)] : /^end$/i.test(decl.value) ? 'ltr' === dir ? rDecl : 'rtl' === dir ? lDecl : [cloneRule(decl, 'ltr').append(rDecl), cloneRule(decl, 'rtl').append(lDecl)] : null;
|
---|
311 | });
|
---|
312 |
|
---|
313 | function splitByComma(string, isTrimmed) {
|
---|
314 | return splitByRegExp(string, /^,$/, isTrimmed);
|
---|
315 | }
|
---|
316 | function splitBySpace(string, isTrimmed) {
|
---|
317 | return splitByRegExp(string, /^\s$/, isTrimmed);
|
---|
318 | }
|
---|
319 | function splitBySlash(string, isTrimmed) {
|
---|
320 | return splitByRegExp(string, /^\/$/, isTrimmed);
|
---|
321 | }
|
---|
322 |
|
---|
323 | function splitByRegExp(string, re, isTrimmed) {
|
---|
324 | const array = [];
|
---|
325 | let buffer = '';
|
---|
326 | let split = false;
|
---|
327 | let func = 0;
|
---|
328 | let i = -1;
|
---|
329 |
|
---|
330 | while (++i < string.length) {
|
---|
331 | const char = string[i];
|
---|
332 |
|
---|
333 | if (char === '(') {
|
---|
334 | func += 1;
|
---|
335 | } else if (char === ')') {
|
---|
336 | if (func > 0) {
|
---|
337 | func -= 1;
|
---|
338 | }
|
---|
339 | } else if (func === 0) {
|
---|
340 | if (re.test(char)) {
|
---|
341 | split = true;
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | if (split) {
|
---|
346 | if (!isTrimmed || buffer.trim()) {
|
---|
347 | array.push(isTrimmed ? buffer.trim() : buffer);
|
---|
348 | }
|
---|
349 |
|
---|
350 | if (!isTrimmed) {
|
---|
351 | array.push(char);
|
---|
352 | }
|
---|
353 |
|
---|
354 | buffer = '';
|
---|
355 | split = false;
|
---|
356 | } else {
|
---|
357 | buffer += char;
|
---|
358 | }
|
---|
359 | }
|
---|
360 |
|
---|
361 | if (buffer !== '') {
|
---|
362 | array.push(isTrimmed ? buffer.trim() : buffer);
|
---|
363 | }
|
---|
364 |
|
---|
365 | return array;
|
---|
366 | }
|
---|
367 |
|
---|
368 | var transformTransition = ((decl, notValues, dir) => {
|
---|
369 | const ltrValues = [];
|
---|
370 | const rtlValues = [];
|
---|
371 | splitByComma(decl.value).forEach(value => {
|
---|
372 | let hasBeenSplit = false;
|
---|
373 | splitBySpace(value).forEach((word, index, words) => {
|
---|
374 | if (word in valueMap) {
|
---|
375 | hasBeenSplit = true;
|
---|
376 | valueMap[word].ltr.forEach(replacement => {
|
---|
377 | const clone = words.slice();
|
---|
378 | clone.splice(index, 1, replacement);
|
---|
379 |
|
---|
380 | if (ltrValues.length && !/^,$/.test(ltrValues[ltrValues.length - 1])) {
|
---|
381 | ltrValues.push(',');
|
---|
382 | }
|
---|
383 |
|
---|
384 | ltrValues.push(clone.join(''));
|
---|
385 | });
|
---|
386 | valueMap[word].rtl.forEach(replacement => {
|
---|
387 | const clone = words.slice();
|
---|
388 | clone.splice(index, 1, replacement);
|
---|
389 |
|
---|
390 | if (rtlValues.length && !/^,$/.test(rtlValues[rtlValues.length - 1])) {
|
---|
391 | rtlValues.push(',');
|
---|
392 | }
|
---|
393 |
|
---|
394 | rtlValues.push(clone.join(''));
|
---|
395 | });
|
---|
396 | }
|
---|
397 | });
|
---|
398 |
|
---|
399 | if (!hasBeenSplit) {
|
---|
400 | ltrValues.push(value);
|
---|
401 | rtlValues.push(value);
|
---|
402 | }
|
---|
403 | });
|
---|
404 | const ltrDecl = decl.clone({
|
---|
405 | value: ltrValues.join('')
|
---|
406 | });
|
---|
407 | const rtlDecl = decl.clone({
|
---|
408 | value: rtlValues.join('')
|
---|
409 | });
|
---|
410 | return ltrValues.length && 'ltr' === dir ? ltrDecl : rtlValues.length && 'rtl' === dir ? rtlDecl : ltrDecl.value !== rtlDecl.value ? [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)] : null;
|
---|
411 | });
|
---|
412 | const valueMap = {
|
---|
413 | 'border-block': {
|
---|
414 | ltr: ['border-top', 'border-bottom'],
|
---|
415 | rtl: ['border-top', 'border-bottom']
|
---|
416 | },
|
---|
417 | 'border-block-color': {
|
---|
418 | ltr: ['border-top-color', 'border-bottom-color'],
|
---|
419 | rtl: ['border-top-color', 'border-bottom-color']
|
---|
420 | },
|
---|
421 | 'border-block-end': {
|
---|
422 | ltr: ['border-bottom'],
|
---|
423 | rtl: ['border-bottom']
|
---|
424 | },
|
---|
425 | 'border-block-end-color': {
|
---|
426 | ltr: ['border-bottom-color'],
|
---|
427 | rtl: ['border-bottom-color']
|
---|
428 | },
|
---|
429 | 'border-block-end-style': {
|
---|
430 | ltr: ['border-bottom-style'],
|
---|
431 | rtl: ['border-bottom-style']
|
---|
432 | },
|
---|
433 | 'border-block-end-width': {
|
---|
434 | ltr: ['border-bottom-width'],
|
---|
435 | rtl: ['border-bottom-width']
|
---|
436 | },
|
---|
437 | 'border-block-start': {
|
---|
438 | ltr: ['border-top'],
|
---|
439 | rtl: ['border-top']
|
---|
440 | },
|
---|
441 | 'border-block-start-color': {
|
---|
442 | ltr: ['border-top-color'],
|
---|
443 | rtl: ['border-top-color']
|
---|
444 | },
|
---|
445 | 'border-block-start-style': {
|
---|
446 | ltr: ['border-top-style'],
|
---|
447 | rtl: ['border-top-style']
|
---|
448 | },
|
---|
449 | 'border-block-start-width': {
|
---|
450 | ltr: ['border-top-width'],
|
---|
451 | rtl: ['border-top-width']
|
---|
452 | },
|
---|
453 | 'border-block-style': {
|
---|
454 | ltr: ['border-top-style', 'border-bottom-style'],
|
---|
455 | rtl: ['border-top-style', 'border-bottom-style']
|
---|
456 | },
|
---|
457 | 'border-block-width': {
|
---|
458 | ltr: ['border-top-width', 'border-bottom-width'],
|
---|
459 | rtl: ['border-top-width', 'border-bottom-width']
|
---|
460 | },
|
---|
461 | 'border-end': {
|
---|
462 | ltr: ['border-bottom', 'border-right'],
|
---|
463 | rtl: ['border-bottom', 'border-left']
|
---|
464 | },
|
---|
465 | 'border-end-color': {
|
---|
466 | ltr: ['border-bottom-color', 'border-right-color'],
|
---|
467 | rtl: ['border-bottom-color', 'border-left-color']
|
---|
468 | },
|
---|
469 | 'border-end-style': {
|
---|
470 | ltr: ['border-bottom-style', 'border-right-style'],
|
---|
471 | rtl: ['border-bottom-style', 'border-left-style']
|
---|
472 | },
|
---|
473 | 'border-end-width': {
|
---|
474 | ltr: ['border-bottom-width', 'border-right-width'],
|
---|
475 | rtl: ['border-bottom-width', 'border-left-width']
|
---|
476 | },
|
---|
477 | 'border-inline': {
|
---|
478 | ltr: ['border-left', 'border-right'],
|
---|
479 | rtl: ['border-left', 'border-right']
|
---|
480 | },
|
---|
481 | 'border-inline-color': {
|
---|
482 | ltr: ['border-left-color', 'border-right-color'],
|
---|
483 | rtl: ['border-left-color', 'border-right-color']
|
---|
484 | },
|
---|
485 | 'border-inline-end': {
|
---|
486 | ltr: ['border-right'],
|
---|
487 | rtl: ['border-left']
|
---|
488 | },
|
---|
489 | 'border-inline-end-color': {
|
---|
490 | ltr: ['border-right-color'],
|
---|
491 | rtl: ['border-left-color']
|
---|
492 | },
|
---|
493 | 'border-inline-end-style': {
|
---|
494 | ltr: ['border-right-style'],
|
---|
495 | rtl: ['border-left-style']
|
---|
496 | },
|
---|
497 | 'border-inline-end-width': {
|
---|
498 | ltr: ['border-right-width'],
|
---|
499 | rtl: ['border-left-width']
|
---|
500 | },
|
---|
501 | 'border-inline-start': {
|
---|
502 | ltr: ['border-left'],
|
---|
503 | rtl: ['border-right']
|
---|
504 | },
|
---|
505 | 'border-inline-start-color': {
|
---|
506 | ltr: ['border-left-color'],
|
---|
507 | rtl: ['border-right-color']
|
---|
508 | },
|
---|
509 | 'border-inline-start-style': {
|
---|
510 | ltr: ['border-left-style'],
|
---|
511 | rtl: ['border-right-style']
|
---|
512 | },
|
---|
513 | 'border-inline-start-width': {
|
---|
514 | ltr: ['border-left-width'],
|
---|
515 | rtl: ['border-right-width']
|
---|
516 | },
|
---|
517 | 'border-inline-style': {
|
---|
518 | ltr: ['border-left-style', 'border-right-style'],
|
---|
519 | rtl: ['border-left-style', 'border-right-style']
|
---|
520 | },
|
---|
521 | 'border-inline-width': {
|
---|
522 | ltr: ['border-left-width', 'border-right-width'],
|
---|
523 | rtl: ['border-left-width', 'border-right-width']
|
---|
524 | },
|
---|
525 | 'border-start': {
|
---|
526 | ltr: ['border-top', 'border-left'],
|
---|
527 | rtl: ['border-top', 'border-right']
|
---|
528 | },
|
---|
529 | 'border-start-color': {
|
---|
530 | ltr: ['border-top-color', 'border-left-color'],
|
---|
531 | rtl: ['border-top-color', 'border-right-color']
|
---|
532 | },
|
---|
533 | 'border-start-style': {
|
---|
534 | ltr: ['border-top-style', 'border-left-style'],
|
---|
535 | rtl: ['border-top-style', 'border-right-style']
|
---|
536 | },
|
---|
537 | 'border-start-width': {
|
---|
538 | ltr: ['border-top-width', 'border-left-width'],
|
---|
539 | rtl: ['border-top-width', 'border-right-width']
|
---|
540 | },
|
---|
541 | 'block-size': {
|
---|
542 | ltr: ['height'],
|
---|
543 | rtl: ['height']
|
---|
544 | },
|
---|
545 | 'inline-size': {
|
---|
546 | ltr: ['width'],
|
---|
547 | rtl: ['width']
|
---|
548 | },
|
---|
549 | 'inset': {
|
---|
550 | ltr: ['top', 'right', 'bottom', 'left'],
|
---|
551 | rtl: ['top', 'right', 'bottom', 'left']
|
---|
552 | },
|
---|
553 | 'inset-block': {
|
---|
554 | ltr: ['top', 'bottom'],
|
---|
555 | rtl: ['top', 'bottom']
|
---|
556 | },
|
---|
557 | 'inset-block-start': {
|
---|
558 | ltr: ['top'],
|
---|
559 | rtl: ['top']
|
---|
560 | },
|
---|
561 | 'inset-block-end': {
|
---|
562 | ltr: ['bottom'],
|
---|
563 | rtl: ['bottom']
|
---|
564 | },
|
---|
565 | 'inset-end': {
|
---|
566 | ltr: ['bottom', 'right'],
|
---|
567 | rtl: ['bottom', 'left']
|
---|
568 | },
|
---|
569 | 'inset-inline': {
|
---|
570 | ltr: ['left', 'right'],
|
---|
571 | rtl: ['left', 'right']
|
---|
572 | },
|
---|
573 | 'inset-inline-start': {
|
---|
574 | ltr: ['left'],
|
---|
575 | rtl: ['right']
|
---|
576 | },
|
---|
577 | 'inset-inline-end': {
|
---|
578 | ltr: ['right'],
|
---|
579 | rtl: ['left']
|
---|
580 | },
|
---|
581 | 'inset-start': {
|
---|
582 | ltr: ['top', 'left'],
|
---|
583 | rtl: ['top', 'right']
|
---|
584 | },
|
---|
585 | 'margin-block': {
|
---|
586 | ltr: ['margin-top', 'margin-bottom'],
|
---|
587 | rtl: ['margin-top', 'margin-bottom']
|
---|
588 | },
|
---|
589 | 'margin-block-start': {
|
---|
590 | ltr: ['margin-top'],
|
---|
591 | rtl: ['margin-top']
|
---|
592 | },
|
---|
593 | 'margin-block-end': {
|
---|
594 | ltr: ['margin-bottom'],
|
---|
595 | rtl: ['margin-bottom']
|
---|
596 | },
|
---|
597 | 'margin-end': {
|
---|
598 | ltr: ['margin-bottom', 'margin-right'],
|
---|
599 | rtl: ['margin-bottom', 'margin-left']
|
---|
600 | },
|
---|
601 | 'margin-inline': {
|
---|
602 | ltr: ['margin-left', 'margin-right'],
|
---|
603 | rtl: ['margin-left', 'margin-right']
|
---|
604 | },
|
---|
605 | 'margin-inline-start': {
|
---|
606 | ltr: ['margin-left'],
|
---|
607 | rtl: ['margin-right']
|
---|
608 | },
|
---|
609 | 'margin-inline-end': {
|
---|
610 | ltr: ['margin-right'],
|
---|
611 | rtl: ['margin-left']
|
---|
612 | },
|
---|
613 | 'margin-start': {
|
---|
614 | ltr: ['margin-top', 'margin-left'],
|
---|
615 | rtl: ['margin-top', 'margin-right']
|
---|
616 | },
|
---|
617 | 'padding-block': {
|
---|
618 | ltr: ['padding-top', 'padding-bottom'],
|
---|
619 | rtl: ['padding-top', 'padding-bottom']
|
---|
620 | },
|
---|
621 | 'padding-block-start': {
|
---|
622 | ltr: ['padding-top'],
|
---|
623 | rtl: ['padding-top']
|
---|
624 | },
|
---|
625 | 'padding-block-end': {
|
---|
626 | ltr: ['padding-bottom'],
|
---|
627 | rtl: ['padding-bottom']
|
---|
628 | },
|
---|
629 | 'padding-end': {
|
---|
630 | ltr: ['padding-bottom', 'padding-right'],
|
---|
631 | rtl: ['padding-bottom', 'padding-left']
|
---|
632 | },
|
---|
633 | 'padding-inline': {
|
---|
634 | ltr: ['padding-left', 'padding-right'],
|
---|
635 | rtl: ['padding-left', 'padding-right']
|
---|
636 | },
|
---|
637 | 'padding-inline-start': {
|
---|
638 | ltr: ['padding-left'],
|
---|
639 | rtl: ['padding-right']
|
---|
640 | },
|
---|
641 | 'padding-inline-end': {
|
---|
642 | ltr: ['padding-right'],
|
---|
643 | rtl: ['padding-left']
|
---|
644 | },
|
---|
645 | 'padding-start': {
|
---|
646 | ltr: ['padding-top', 'padding-left'],
|
---|
647 | rtl: ['padding-top', 'padding-right']
|
---|
648 | }
|
---|
649 | };
|
---|
650 |
|
---|
651 | var matchSupportedProperties = /^(?:(inset|margin|padding)(?:-(block|block-start|block-end|inline|inline-start|inline-end|start|end))|(min-|max-)?(block|inline)-(size))$/i;
|
---|
652 |
|
---|
653 | // tooling
|
---|
654 |
|
---|
655 | const transforms = {
|
---|
656 | 'border': transformBorder['border'],
|
---|
657 | 'border-width': transformBorder['border'],
|
---|
658 | 'border-style': transformBorder['border'],
|
---|
659 | 'border-color': transformBorder['border'],
|
---|
660 | 'border-block': transformBorder['border-block'],
|
---|
661 | 'border-block-width': transformBorder['border-block'],
|
---|
662 | 'border-block-style': transformBorder['border-block'],
|
---|
663 | 'border-block-color': transformBorder['border-block'],
|
---|
664 | 'border-block-start': transformBorder['border-block-start'],
|
---|
665 | 'border-block-start-width': transformBorder['border-block-start'],
|
---|
666 | 'border-block-start-style': transformBorder['border-block-start'],
|
---|
667 | 'border-block-start-color': transformBorder['border-block-start'],
|
---|
668 | 'border-block-end': transformBorder['border-block-end'],
|
---|
669 | 'border-block-end-width': transformBorder['border-block-end'],
|
---|
670 | 'border-block-end-style': transformBorder['border-block-end'],
|
---|
671 | 'border-block-end-color': transformBorder['border-block-end'],
|
---|
672 | 'border-inline': transformBorder['border-inline'],
|
---|
673 | 'border-inline-width': transformBorder['border-inline'],
|
---|
674 | 'border-inline-style': transformBorder['border-inline'],
|
---|
675 | 'border-inline-color': transformBorder['border-inline'],
|
---|
676 | 'border-inline-start': transformBorder['border-inline-start'],
|
---|
677 | 'border-inline-start-width': transformBorder['border-inline-start'],
|
---|
678 | 'border-inline-start-style': transformBorder['border-inline-start'],
|
---|
679 | 'border-inline-start-color': transformBorder['border-inline-start'],
|
---|
680 | 'border-inline-end': transformBorder['border-inline-end'],
|
---|
681 | 'border-inline-end-width': transformBorder['border-inline-end'],
|
---|
682 | 'border-inline-end-style': transformBorder['border-inline-end'],
|
---|
683 | 'border-inline-end-color': transformBorder['border-inline-end'],
|
---|
684 | 'border-start': transformBorder['border-start'],
|
---|
685 | 'border-start-width': transformBorder['border-start'],
|
---|
686 | 'border-start-style': transformBorder['border-start'],
|
---|
687 | 'border-start-color': transformBorder['border-start'],
|
---|
688 | 'border-end': transformBorder['border-end'],
|
---|
689 | 'border-end-width': transformBorder['border-end'],
|
---|
690 | 'border-end-style': transformBorder['border-end'],
|
---|
691 | 'border-end-color': transformBorder['border-end'],
|
---|
692 | 'clear': transformFloat,
|
---|
693 | 'inset': transformInset,
|
---|
694 | 'margin': transformSpacing,
|
---|
695 | 'padding': transformSpacing,
|
---|
696 | 'block': transformSide['block'],
|
---|
697 | 'block-start': transformSide['block-start'],
|
---|
698 | 'block-end': transformSide['block-end'],
|
---|
699 | 'inline': transformSide['inline'],
|
---|
700 | 'inline-start': transformSide['inline-start'],
|
---|
701 | 'inline-end': transformSide['inline-end'],
|
---|
702 | 'start': transformSide['start'],
|
---|
703 | 'end': transformSide['end'],
|
---|
704 | 'float': transformFloat,
|
---|
705 | 'resize': transformResize,
|
---|
706 | 'size': transformSize,
|
---|
707 | 'text-align': transformTextAlign,
|
---|
708 | 'transition': transformTransition,
|
---|
709 | 'transition-property': transformTransition
|
---|
710 | }; // properties that will be split by slash
|
---|
711 |
|
---|
712 | const splitBySlashPropRegExp = /^border(-block|-inline|-start|-end)?(-width|-style|-color)?$/i; // plugin
|
---|
713 |
|
---|
714 | var index = postcss.plugin('postcss-logical-properties', opts => {
|
---|
715 | const preserve = Boolean(Object(opts).preserve);
|
---|
716 | const dir = !preserve && typeof Object(opts).dir === 'string' ? /^rtl$/i.test(opts.dir) ? 'rtl' : 'ltr' : false;
|
---|
717 | return root => {
|
---|
718 | root.walkDecls(decl => {
|
---|
719 | const parent = decl.parent;
|
---|
720 | const values = splitBySlashPropRegExp.test(decl.prop) ? splitBySlash(decl.value, true) : splitBySpace(decl.value, true);
|
---|
721 | const prop = decl.prop.replace(matchSupportedProperties, '$2$5').toLowerCase();
|
---|
722 |
|
---|
723 | if (prop in transforms) {
|
---|
724 | const replacer = transforms[prop](decl, values, dir);
|
---|
725 |
|
---|
726 | if (replacer) {
|
---|
727 | [].concat(replacer).forEach(replacement => {
|
---|
728 | if (replacement.type === 'rule') {
|
---|
729 | parent.before(replacement);
|
---|
730 | } else {
|
---|
731 | decl.before(replacement);
|
---|
732 | }
|
---|
733 | });
|
---|
734 |
|
---|
735 | if (!preserve) {
|
---|
736 | decl.remove();
|
---|
737 |
|
---|
738 | if (!parent.nodes.length) {
|
---|
739 | parent.remove();
|
---|
740 | }
|
---|
741 | }
|
---|
742 | }
|
---|
743 | }
|
---|
744 | });
|
---|
745 | };
|
---|
746 | });
|
---|
747 |
|
---|
748 | module.exports = index;
|
---|
749 | //# sourceMappingURL=index.cjs.js.map
|
---|