UNPKG

3.32 kBJavaScriptView Raw
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2015 - present Instructure, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25/**
26 * ---
27 * category: utilities/themes
28 * ---
29 * @module mirrorShorthand
30 */
31
32/**
33 * Mirror shorthand CSS properties for bidirectional text
34 *
35 * Given a string representing a CSS shorthand for edges,
36 * swaps the values such that 4 value syntax is RTL instead
37 * of LTR.
38 *
39 * See the following for further reference:
40 * https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties
41 *
42 * @param {String} values - space delimited string values representing a CSS shorthand
43 * @returns {String} a space delimited CSS shorthand string converted to RTL
44 */
45function mirrorShorthandEdges(values) {
46 if (typeof values !== 'string') {
47 return;
48 }
49
50 var valuesArr = values.split(' ');
51
52 if (valuesArr.length === 4) {
53 // swap the 2nd and 4th values
54 ;
55 var _ref = [valuesArr[3], valuesArr[1]];
56 valuesArr[1] = _ref[0];
57 valuesArr[3] = _ref[1];
58 }
59
60 return valuesArr.join(' ');
61}
62/**
63 * Convert shorthand CSS properties for corners to rtl
64 *
65 * Given a string representing a CSS shorthand for corners,
66 * swaps the values such that 2,3 and 4 value syntax is rtl
67 * instead of ltr.
68 *
69 * See the following for further reference:
70 * https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties
71 *
72 * @param {String} values - space delimited string values representing a CSS shorthand
73 * @returns {String} a space delimited CSS shorthand string converted to RTL
74 */
75
76
77function mirrorShorthandCorners(values) {
78 if (typeof values !== 'string') {
79 return;
80 }
81
82 var valuesArr = values.split(' ');
83
84 if (valuesArr.length === 2) {
85 // swap the 1st and 2nd values
86 ;
87 var _ref2 = [valuesArr[1], valuesArr[0]];
88 valuesArr[0] = _ref2[0];
89 valuesArr[1] = _ref2[1];
90 }
91
92 if (valuesArr.length === 3) {
93 // convert 3 value syntax to 4 value syntax
94 valuesArr.push(valuesArr[1]);
95 }
96
97 if (valuesArr.length === 4) {
98 ;
99 var _ref3 = [valuesArr[1], valuesArr[0], valuesArr[3], valuesArr[2]];
100 valuesArr[0] = _ref3[0];
101 valuesArr[1] = _ref3[1];
102 valuesArr[2] = _ref3[2];
103 valuesArr[3] = _ref3[3];
104 }
105
106 return valuesArr.join(' ');
107}
108
109export { mirrorShorthandEdges, mirrorShorthandCorners };
\No newline at end of file