@instructure/emotion 8.10.3-snapshot.23 → 8.10.3-snapshot.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/withStyle.js CHANGED
@@ -28,8 +28,6 @@ import { isEqual } from 'lodash';
28
28
  import hoistNonReactStatics from 'hoist-non-react-statics';
29
29
  import { warn } from '@instructure/console';
30
30
  import { decorator } from '@instructure/ui-decorator';
31
- import { useTextDirectionContext } from '@instructure/ui-i18n';
32
- import { bidirectionalPolyfill } from './styleUtils/bidirectionalPolyfill';
33
31
  import { getComponentThemeOverride } from './getComponentThemeOverride';
34
32
  import { useTheme } from './useTheme';
35
33
  const defaultValues = {
@@ -109,7 +107,6 @@ const withStyle = decorator((ComposedComponent, generateStyle, generateComponent
109
107
  const displayName = ComposedComponent.displayName || ComposedComponent.name;
110
108
  const WithStyle = /*#__PURE__*/forwardRef((props, ref) => {
111
109
  const theme = useTheme();
112
- const dir = useTextDirectionContext();
113
110
 
114
111
  if (props.styles) {
115
112
  warn(false, `Manually passing the "styles" property is not allowed on the ${displayName} component. Using the default styles calculated by the @withStyle decorator instead.\n`, props.styles);
@@ -128,13 +125,13 @@ const withStyle = decorator((ComposedComponent, generateStyle, generateComponent
128
125
  ...themeOverride
129
126
  } : {};
130
127
 
131
- const _useState = useState(generateStyle ? bidirectionalPolyfill(generateStyle(componentTheme, componentProps, {}), dir) : {}),
128
+ const _useState = useState(generateStyle ? generateStyle(componentTheme, componentProps, {}) : {}),
132
129
  _useState2 = _slicedToArray(_useState, 2),
133
130
  styles = _useState2[0],
134
131
  setStyles = _useState2[1];
135
132
 
136
133
  const makeStyleHandler = extraArgs => {
137
- const calculatedStyles = bidirectionalPolyfill(generateStyle(componentTheme, componentProps, extraArgs), dir);
134
+ const calculatedStyles = generateStyle(componentTheme, componentProps, extraArgs);
138
135
 
139
136
  if (!isEqual(calculatedStyles, styles)) {
140
137
  setStyles(calculatedStyles);
package/lib/withStyle.js CHANGED
@@ -21,10 +21,6 @@ var _console = require("@instructure/console");
21
21
 
22
22
  var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
23
23
 
24
- var _uiI18n = require("@instructure/ui-i18n");
25
-
26
- var _bidirectionalPolyfill = require("./styleUtils/bidirectionalPolyfill");
27
-
28
24
  var _getComponentThemeOverride = require("./getComponentThemeOverride");
29
25
 
30
26
  var _useTheme = require("./useTheme");
@@ -129,7 +125,6 @@ const withStyle = (0, _decorator.decorator)((ComposedComponent, generateStyle, g
129
125
  const displayName = ComposedComponent.displayName || ComposedComponent.name;
130
126
  const WithStyle = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
131
127
  const theme = (0, _useTheme.useTheme)();
132
- const dir = (0, _uiI18n.useTextDirectionContext)();
133
128
 
134
129
  if (props.styles) {
135
130
  (0, _console.warn)(false, `Manually passing the "styles" property is not allowed on the ${displayName} component. Using the default styles calculated by the @withStyle decorator instead.\n`, props.styles);
@@ -148,13 +143,13 @@ const withStyle = (0, _decorator.decorator)((ComposedComponent, generateStyle, g
148
143
  ...themeOverride
149
144
  } : {};
150
145
 
151
- const _useState = (0, _react.useState)(generateStyle ? (0, _bidirectionalPolyfill.bidirectionalPolyfill)(generateStyle(componentTheme, componentProps, {}), dir) : {}),
146
+ const _useState = (0, _react.useState)(generateStyle ? generateStyle(componentTheme, componentProps, {}) : {}),
152
147
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
153
148
  styles = _useState2[0],
154
149
  setStyles = _useState2[1];
155
150
 
156
151
  const makeStyleHandler = extraArgs => {
157
- const calculatedStyles = (0, _bidirectionalPolyfill.bidirectionalPolyfill)(generateStyle(componentTheme, componentProps, extraArgs), dir);
152
+ const calculatedStyles = generateStyle(componentTheme, componentProps, extraArgs);
158
153
 
159
154
  if (!(0, _lodash.isEqual)(calculatedStyles, styles)) {
160
155
  setStyles(calculatedStyles);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/emotion",
3
- "version": "8.10.3-snapshot.23+5aaa29662",
3
+ "version": "8.10.3-snapshot.25+ed32a6c3b",
4
4
  "description": "A UI component library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "type": "commonjs",
@@ -26,20 +26,20 @@
26
26
  "dependencies": {
27
27
  "@babel/runtime": "^7.13.10",
28
28
  "@emotion/react": "^11.4.1",
29
- "@instructure/console": "8.10.3-snapshot.23+5aaa29662",
30
- "@instructure/shared-types": "8.10.3-snapshot.23+5aaa29662",
31
- "@instructure/ui-decorator": "8.10.3-snapshot.23+5aaa29662",
32
- "@instructure/ui-i18n": "8.10.3-snapshot.23+5aaa29662",
33
- "@instructure/ui-themes": "8.10.3-snapshot.23+5aaa29662",
34
- "@instructure/ui-utils": "8.10.3-snapshot.23+5aaa29662",
29
+ "@instructure/console": "8.10.3-snapshot.25+ed32a6c3b",
30
+ "@instructure/shared-types": "8.10.3-snapshot.25+ed32a6c3b",
31
+ "@instructure/ui-decorator": "8.10.3-snapshot.25+ed32a6c3b",
32
+ "@instructure/ui-i18n": "8.10.3-snapshot.25+ed32a6c3b",
33
+ "@instructure/ui-themes": "8.10.3-snapshot.25+ed32a6c3b",
34
+ "@instructure/ui-utils": "8.10.3-snapshot.25+ed32a6c3b",
35
35
  "emotion-theming": "^10.0.27",
36
36
  "hoist-non-react-statics": "^3.3.2",
37
37
  "lodash": "^4",
38
38
  "prop-types": "^15"
39
39
  },
40
40
  "devDependencies": {
41
- "@instructure/ui-babel-preset": "8.10.3-snapshot.23+5aaa29662",
42
- "@instructure/ui-test-utils": "8.10.3-snapshot.23+5aaa29662",
41
+ "@instructure/ui-babel-preset": "8.10.3-snapshot.25+ed32a6c3b",
42
+ "@instructure/ui-test-utils": "8.10.3-snapshot.25+ed32a6c3b",
43
43
  "@types/lodash": "^4.14.171",
44
44
  "cpy-cli": "^3.1.1"
45
45
  },
@@ -50,5 +50,5 @@
50
50
  "access": "public"
51
51
  },
52
52
  "sideEffects": false,
53
- "gitHead": "5aaa296621d72faebe1a809a8895a8185587008d"
53
+ "gitHead": "ed32a6c3b14ddb7fbbb5b543d9871a296f06e4c0"
54
54
  }
package/src/withStyle.tsx CHANGED
@@ -34,8 +34,6 @@ import hoistNonReactStatics from 'hoist-non-react-statics'
34
34
 
35
35
  import { warn } from '@instructure/console'
36
36
  import { decorator } from '@instructure/ui-decorator'
37
- import { useTextDirectionContext } from '@instructure/ui-i18n'
38
- import { bidirectionalPolyfill } from './styleUtils/bidirectionalPolyfill'
39
37
 
40
38
  import { getComponentThemeOverride } from './getComponentThemeOverride'
41
39
  import { useTheme } from './useTheme'
@@ -165,7 +163,6 @@ const withStyle = decorator(
165
163
  allowedProps?: string[]
166
164
  } = forwardRef((props, ref) => {
167
165
  const theme = useTheme()
168
- const dir = useTextDirectionContext()
169
166
 
170
167
  if (props.styles) {
171
168
  warn(
@@ -181,7 +178,6 @@ const withStyle = decorator(
181
178
  `Manually passing the "makeStyles" property is not allowed on the ${displayName} component. Styles are calculated by the @withStyle decorator.`
182
179
  )
183
180
  }
184
-
185
181
  const componentProps: Props = {
186
182
  ...ComposedComponent.defaultProps,
187
183
  ...props,
@@ -204,20 +200,14 @@ const withStyle = decorator(
204
200
  : {}
205
201
 
206
202
  const [styles, setStyles] = useState(
207
- generateStyle
208
- ? bidirectionalPolyfill(
209
- generateStyle(componentTheme, componentProps, {}),
210
- // @ts-expect-error TODO: this shouldn't be "auto" (INSTUI-3241)
211
- dir
212
- )
213
- : {}
203
+ generateStyle ? generateStyle(componentTheme, componentProps, {}) : {}
214
204
  )
215
205
 
216
206
  const makeStyleHandler: WithStyleProps['makeStyles'] = (extraArgs) => {
217
- const calculatedStyles = bidirectionalPolyfill(
218
- generateStyle(componentTheme, componentProps, extraArgs),
219
- // @ts-expect-error TODO: this shouldn't be "auto" (INSTUI-3241)
220
- dir
207
+ const calculatedStyles = generateStyle(
208
+ componentTheme,
209
+ componentProps,
210
+ extraArgs
221
211
  )
222
212
  if (!isEqual(calculatedStyles, styles)) {
223
213
  setStyles(calculatedStyles)
@@ -1 +1 @@
1
- {"version":3,"file":"withStyle.d.ts","sourceRoot":"","sources":["../src/withStyle.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAA+C,MAAM,OAAO,CAAA;AAkBnE,OAAO,KAAK,EAAa,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,KAAK,EACV,cAAc,EAKf,MAAM,gBAAgB,CAAA;AASvB,aAAK,qBAAqB,CACxB,KAAK,SAAS,cAAc,GAAG,IAAI,GAAG,cAAc,IAClD,KAAK,SAAS,IAAI,GAElB,EAAE,GACF;IACE,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,UAAU,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;CAC3D,CAAA;AAEL,aAAK,iBAAiB,CAAC,KAAK,SAAS,cAAc,GAAG,IAAI,GAAG,cAAc,IAAI;IAC7E,aAAa,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;CAC/B,CAAA;AAED,aAAK,cAAc,CACjB,KAAK,SAAS,cAAc,GAAG,IAAI,GAAG,cAAc,EACpD,KAAK,SAAS,cAAc,GAAG,IAAI,GAAG,cAAc,IAClD,KAAK,SAAS,IAAI,GAClB,qBAAqB,CAAC,KAAK,CAAC,GAC5B,qBAAqB,CAAC,KAAK,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA;AAO3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,QAAA,MAAM,SAAS,oFAgHd,CAAA;AAED,eAAe,SAAS,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,CAAA;AACpB,YAAY,EAAE,cAAc,EAAE,CAAA"}
1
+ {"version":3,"file":"withStyle.d.ts","sourceRoot":"","sources":["../src/withStyle.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAA+C,MAAM,OAAO,CAAA;AAgBnE,OAAO,KAAK,EAAa,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,KAAK,EACV,cAAc,EAKf,MAAM,gBAAgB,CAAA;AASvB,aAAK,qBAAqB,CACxB,KAAK,SAAS,cAAc,GAAG,IAAI,GAAG,cAAc,IAClD,KAAK,SAAS,IAAI,GAElB,EAAE,GACF;IACE,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,UAAU,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;CAC3D,CAAA;AAEL,aAAK,iBAAiB,CAAC,KAAK,SAAS,cAAc,GAAG,IAAI,GAAG,cAAc,IAAI;IAC7E,aAAa,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;CAC/B,CAAA;AAED,aAAK,cAAc,CACjB,KAAK,SAAS,cAAc,GAAG,IAAI,GAAG,cAAc,EACpD,KAAK,SAAS,cAAc,GAAG,IAAI,GAAG,cAAc,IAClD,KAAK,SAAS,IAAI,GAClB,qBAAqB,CAAC,KAAK,CAAC,GAC5B,qBAAqB,CAAC,KAAK,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA;AAO3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,QAAA,MAAM,SAAS,oFAwGd,CAAA;AAED,eAAe,SAAS,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,CAAA;AACpB,YAAY,EAAE,cAAc,EAAE,CAAA"}
@@ -1,183 +0,0 @@
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
- import { isObject } from 'lodash';
25
- import { consoleLog as log } from '@instructure/console';
26
-
27
- /**
28
- * ---
29
- * category: utilities/themes
30
- * ---
31
- * Polyfills Bi-directional [CSS proposal from W3C](https://drafts.csswg.org/css-logical-props/) to support direction-sensitive rules, a.k.a Left-To-Right (LTR) and Right-To-Left (RTL) in all browsers.
32
- *
33
- * Based on formerly used [postcss-bidirection](https://github.com/gasolin/postcss-bidirection) plugin.
34
- * @module bidirectionalPolyfill
35
- * @param {object} styles - styles object of a component
36
- * @param {string} dir - "ltr" of "rtl" direction
37
- * @returns {{}} styles object with Bi-directional properties polyfilled
38
- */
39
- const DEBUG = false;
40
- const SUPPORT_PROPS = ['float', 'clear', 'textAlign', 'paddingInlineStart', 'paddingInlineEnd', 'borderInlineStart', 'borderInlineEnd', 'borderInlineStartColor', 'borderInlineEndColor', 'borderInlineStartStyle', 'borderInlineEndStyle', 'borderInlineStartWidth', 'borderInlineEndWidth', 'borderInlineStartTop', 'borderInlineEndTop', 'borderTopInlineStartRadius', 'borderTopInlineEndRadius', 'borderBottomInlineStartRadius', 'borderBottomInlineEndRadius', 'marginInlineStart', 'marginInlineEnd', 'offsetInlineStart', 'offsetInlineEnd', 'insetInlineStart', 'insetInlineEnd'];
41
-
42
- function processProps({
43
- originalProp,
44
- originalValue
45
- }, textDirection) {
46
- const isLtr = textDirection === 'ltr';
47
- let prop = originalProp;
48
- let value = originalValue;
49
- const start = isLtr ? 'Left' : 'Right';
50
- const end = isLtr ? 'Right' : 'Left';
51
-
52
- switch (prop) {
53
- case 'float':
54
- case 'clear':
55
- case 'textAlign':
56
- if (['start', 'end'].indexOf(value) !== -1) {
57
- if (value === 'start') {
58
- value = start.toLowerCase();
59
- } else {
60
- value = end.toLowerCase();
61
- }
62
- }
63
-
64
- break;
65
-
66
- case 'paddingInlineStart':
67
- prop = 'padding' + start;
68
- break;
69
-
70
- case 'paddingInlineEnd':
71
- prop = 'padding' + end;
72
- break;
73
-
74
- case 'borderInlineStart':
75
- prop = 'border' + start;
76
- break;
77
-
78
- case 'borderInlineEnd':
79
- prop = 'border' + end;
80
- break;
81
-
82
- case 'borderInlineStartColor':
83
- prop = 'border' + start + 'Color';
84
- break;
85
-
86
- case 'borderInlineEndColor':
87
- prop = 'border' + end + 'Color';
88
- break;
89
-
90
- case 'borderInlineStartWidth':
91
- prop = 'border' + start + 'Width';
92
- break;
93
-
94
- case 'borderInlineEndWidth':
95
- prop = 'border' + end + 'Width';
96
- break;
97
-
98
- case 'borderInlineStartStyle':
99
- prop = 'border' + start + 'Style';
100
- break;
101
-
102
- case 'borderInlineEndStyle':
103
- prop = 'border' + end + 'Style';
104
- break;
105
-
106
- case 'borderTopInlineStartRadius':
107
- prop = 'borderTop' + start + 'Radius';
108
- break;
109
-
110
- case 'borderTopInlineEndRadius':
111
- prop = 'borderTop' + end + 'Radius';
112
- break;
113
-
114
- case 'borderBottomInlineStartRadius':
115
- prop = 'borderBottom' + start + 'Radius';
116
- break;
117
-
118
- case 'borderBottomInlineEndRadius':
119
- prop = 'borderBottom' + end + 'Radius';
120
- break;
121
-
122
- case 'marginInlineStart':
123
- prop = 'margin' + start;
124
- break;
125
-
126
- case 'marginInlineEnd':
127
- prop = 'margin' + end;
128
- break;
129
-
130
- case 'insetInlineStart':
131
- case 'offsetInlineStart':
132
- prop = start.toLowerCase();
133
- break;
134
-
135
- case 'insetInlineEnd':
136
- case 'offsetInlineEnd':
137
- prop = end.toLowerCase();
138
- break;
139
-
140
- default:
141
- break;
142
- }
143
-
144
- if (DEBUG) log(`${originalProp}: ${originalValue} => ${prop}: ${value}`);
145
- return {
146
- prop,
147
- value
148
- };
149
- }
150
-
151
- const isSupportedProps = prop => SUPPORT_PROPS.indexOf(prop) > -1;
152
-
153
- const processStyleProps = (propsObj, dir) => isObject(propsObj) ? Object.entries(propsObj).reduce((accumulator, [originalProp, originalValue]) => {
154
- if (isObject(originalValue)) {
155
- return { ...accumulator,
156
- [originalProp]: processStyleProps(originalValue, dir)
157
- };
158
- }
159
-
160
- if (isSupportedProps(originalProp) && typeof originalValue !== 'undefined') {
161
- const _processProps = processProps({
162
- originalProp,
163
- originalValue
164
- }, dir),
165
- prop = _processProps.prop,
166
- value = _processProps.value;
167
-
168
- return { ...accumulator,
169
- [prop]: value
170
- };
171
- }
172
-
173
- return { ...accumulator,
174
- [originalProp]: originalValue
175
- };
176
- }, {}) : propsObj;
177
-
178
- const bidirectionalPolyfill = (styles, dir) => Object.entries(styles).reduce((accumulator, [style, props]) => ({ ...accumulator,
179
- [style]: processStyleProps(props, dir)
180
- }), {});
181
-
182
- export default bidirectionalPolyfill;
183
- export { bidirectionalPolyfill };
@@ -1,193 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.bidirectionalPolyfill = exports.default = void 0;
7
-
8
- var _lodash = require("lodash");
9
-
10
- var _console = require("@instructure/console");
11
-
12
- /*
13
- * The MIT License (MIT)
14
- *
15
- * Copyright (c) 2015 - present Instructure, Inc.
16
- *
17
- * Permission is hereby granted, free of charge, to any person obtaining a copy
18
- * of this software and associated documentation files (the "Software"), to deal
19
- * in the Software without restriction, including without limitation the rights
20
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
- * copies of the Software, and to permit persons to whom the Software is
22
- * furnished to do so, subject to the following conditions:
23
- *
24
- * The above copyright notice and this permission notice shall be included in all
25
- * copies or substantial portions of the Software.
26
- *
27
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
- * SOFTWARE.
34
- */
35
-
36
- /**
37
- * ---
38
- * category: utilities/themes
39
- * ---
40
- * Polyfills Bi-directional [CSS proposal from W3C](https://drafts.csswg.org/css-logical-props/) to support direction-sensitive rules, a.k.a Left-To-Right (LTR) and Right-To-Left (RTL) in all browsers.
41
- *
42
- * Based on formerly used [postcss-bidirection](https://github.com/gasolin/postcss-bidirection) plugin.
43
- * @module bidirectionalPolyfill
44
- * @param {object} styles - styles object of a component
45
- * @param {string} dir - "ltr" of "rtl" direction
46
- * @returns {{}} styles object with Bi-directional properties polyfilled
47
- */
48
- const DEBUG = false;
49
- const SUPPORT_PROPS = ['float', 'clear', 'textAlign', 'paddingInlineStart', 'paddingInlineEnd', 'borderInlineStart', 'borderInlineEnd', 'borderInlineStartColor', 'borderInlineEndColor', 'borderInlineStartStyle', 'borderInlineEndStyle', 'borderInlineStartWidth', 'borderInlineEndWidth', 'borderInlineStartTop', 'borderInlineEndTop', 'borderTopInlineStartRadius', 'borderTopInlineEndRadius', 'borderBottomInlineStartRadius', 'borderBottomInlineEndRadius', 'marginInlineStart', 'marginInlineEnd', 'offsetInlineStart', 'offsetInlineEnd', 'insetInlineStart', 'insetInlineEnd'];
50
-
51
- function processProps({
52
- originalProp,
53
- originalValue
54
- }, textDirection) {
55
- const isLtr = textDirection === 'ltr';
56
- let prop = originalProp;
57
- let value = originalValue;
58
- const start = isLtr ? 'Left' : 'Right';
59
- const end = isLtr ? 'Right' : 'Left';
60
-
61
- switch (prop) {
62
- case 'float':
63
- case 'clear':
64
- case 'textAlign':
65
- if (['start', 'end'].indexOf(value) !== -1) {
66
- if (value === 'start') {
67
- value = start.toLowerCase();
68
- } else {
69
- value = end.toLowerCase();
70
- }
71
- }
72
-
73
- break;
74
-
75
- case 'paddingInlineStart':
76
- prop = 'padding' + start;
77
- break;
78
-
79
- case 'paddingInlineEnd':
80
- prop = 'padding' + end;
81
- break;
82
-
83
- case 'borderInlineStart':
84
- prop = 'border' + start;
85
- break;
86
-
87
- case 'borderInlineEnd':
88
- prop = 'border' + end;
89
- break;
90
-
91
- case 'borderInlineStartColor':
92
- prop = 'border' + start + 'Color';
93
- break;
94
-
95
- case 'borderInlineEndColor':
96
- prop = 'border' + end + 'Color';
97
- break;
98
-
99
- case 'borderInlineStartWidth':
100
- prop = 'border' + start + 'Width';
101
- break;
102
-
103
- case 'borderInlineEndWidth':
104
- prop = 'border' + end + 'Width';
105
- break;
106
-
107
- case 'borderInlineStartStyle':
108
- prop = 'border' + start + 'Style';
109
- break;
110
-
111
- case 'borderInlineEndStyle':
112
- prop = 'border' + end + 'Style';
113
- break;
114
-
115
- case 'borderTopInlineStartRadius':
116
- prop = 'borderTop' + start + 'Radius';
117
- break;
118
-
119
- case 'borderTopInlineEndRadius':
120
- prop = 'borderTop' + end + 'Radius';
121
- break;
122
-
123
- case 'borderBottomInlineStartRadius':
124
- prop = 'borderBottom' + start + 'Radius';
125
- break;
126
-
127
- case 'borderBottomInlineEndRadius':
128
- prop = 'borderBottom' + end + 'Radius';
129
- break;
130
-
131
- case 'marginInlineStart':
132
- prop = 'margin' + start;
133
- break;
134
-
135
- case 'marginInlineEnd':
136
- prop = 'margin' + end;
137
- break;
138
-
139
- case 'insetInlineStart':
140
- case 'offsetInlineStart':
141
- prop = start.toLowerCase();
142
- break;
143
-
144
- case 'insetInlineEnd':
145
- case 'offsetInlineEnd':
146
- prop = end.toLowerCase();
147
- break;
148
-
149
- default:
150
- break;
151
- }
152
-
153
- if (DEBUG) (0, _console.consoleLog)(`${originalProp}: ${originalValue} => ${prop}: ${value}`);
154
- return {
155
- prop,
156
- value
157
- };
158
- }
159
-
160
- const isSupportedProps = prop => SUPPORT_PROPS.indexOf(prop) > -1;
161
-
162
- const processStyleProps = (propsObj, dir) => (0, _lodash.isObject)(propsObj) ? Object.entries(propsObj).reduce((accumulator, [originalProp, originalValue]) => {
163
- if ((0, _lodash.isObject)(originalValue)) {
164
- return { ...accumulator,
165
- [originalProp]: processStyleProps(originalValue, dir)
166
- };
167
- }
168
-
169
- if (isSupportedProps(originalProp) && typeof originalValue !== 'undefined') {
170
- const _processProps = processProps({
171
- originalProp,
172
- originalValue
173
- }, dir),
174
- prop = _processProps.prop,
175
- value = _processProps.value;
176
-
177
- return { ...accumulator,
178
- [prop]: value
179
- };
180
- }
181
-
182
- return { ...accumulator,
183
- [originalProp]: originalValue
184
- };
185
- }, {}) : propsObj;
186
-
187
- const bidirectionalPolyfill = (styles, dir) => Object.entries(styles).reduce((accumulator, [style, props]) => ({ ...accumulator,
188
- [style]: processStyleProps(props, dir)
189
- }), {});
190
-
191
- exports.bidirectionalPolyfill = bidirectionalPolyfill;
192
- var _default = bidirectionalPolyfill;
193
- exports.default = _default;
@@ -1,213 +0,0 @@
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
- import { isObject } from 'lodash'
26
- import { consoleLog as log } from '@instructure/console'
27
-
28
- import type { StyleObject } from '../EmotionTypes'
29
-
30
- type Direction = 'ltr' | 'rtl'
31
-
32
- /**
33
- * ---
34
- * category: utilities/themes
35
- * ---
36
- * Polyfills Bi-directional [CSS proposal from W3C](https://drafts.csswg.org/css-logical-props/) to support direction-sensitive rules, a.k.a Left-To-Right (LTR) and Right-To-Left (RTL) in all browsers.
37
- *
38
- * Based on formerly used [postcss-bidirection](https://github.com/gasolin/postcss-bidirection) plugin.
39
- * @module bidirectionalPolyfill
40
- * @param {object} styles - styles object of a component
41
- * @param {string} dir - "ltr" of "rtl" direction
42
- * @returns {{}} styles object with Bi-directional properties polyfilled
43
- */
44
-
45
- const DEBUG = false
46
- const SUPPORT_PROPS = [
47
- 'float',
48
- 'clear',
49
- 'textAlign',
50
- 'paddingInlineStart',
51
- 'paddingInlineEnd',
52
- 'borderInlineStart',
53
- 'borderInlineEnd',
54
- 'borderInlineStartColor',
55
- 'borderInlineEndColor',
56
- 'borderInlineStartStyle',
57
- 'borderInlineEndStyle',
58
- 'borderInlineStartWidth',
59
- 'borderInlineEndWidth',
60
- 'borderInlineStartTop',
61
- 'borderInlineEndTop',
62
- 'borderTopInlineStartRadius',
63
- 'borderTopInlineEndRadius',
64
- 'borderBottomInlineStartRadius',
65
- 'borderBottomInlineEndRadius',
66
- 'marginInlineStart',
67
- 'marginInlineEnd',
68
- 'offsetInlineStart',
69
- 'offsetInlineEnd',
70
- 'insetInlineStart',
71
- 'insetInlineEnd'
72
- ]
73
-
74
- function processProps(
75
- {
76
- originalProp,
77
- originalValue
78
- }: { originalProp: string; originalValue: string | number },
79
- textDirection: Direction
80
- ) {
81
- const isLtr = textDirection === 'ltr'
82
-
83
- let prop = originalProp
84
- let value = originalValue
85
- const start = isLtr ? 'Left' : 'Right'
86
- const end = isLtr ? 'Right' : 'Left'
87
-
88
- switch (prop) {
89
- case 'float':
90
- case 'clear':
91
- case 'textAlign':
92
- if (['start', 'end'].indexOf(value as string) !== -1) {
93
- if (value === 'start') {
94
- value = start.toLowerCase()
95
- } else {
96
- value = end.toLowerCase()
97
- }
98
- }
99
- break
100
- case 'paddingInlineStart':
101
- prop = 'padding' + start
102
- break
103
- case 'paddingInlineEnd':
104
- prop = 'padding' + end
105
- break
106
- case 'borderInlineStart':
107
- prop = 'border' + start
108
- break
109
- case 'borderInlineEnd':
110
- prop = 'border' + end
111
- break
112
- case 'borderInlineStartColor':
113
- prop = 'border' + start + 'Color'
114
- break
115
- case 'borderInlineEndColor':
116
- prop = 'border' + end + 'Color'
117
- break
118
- case 'borderInlineStartWidth':
119
- prop = 'border' + start + 'Width'
120
- break
121
- case 'borderInlineEndWidth':
122
- prop = 'border' + end + 'Width'
123
- break
124
- case 'borderInlineStartStyle':
125
- prop = 'border' + start + 'Style'
126
- break
127
- case 'borderInlineEndStyle':
128
- prop = 'border' + end + 'Style'
129
- break
130
- case 'borderTopInlineStartRadius':
131
- prop = 'borderTop' + start + 'Radius'
132
- break
133
- case 'borderTopInlineEndRadius':
134
- prop = 'borderTop' + end + 'Radius'
135
- break
136
- case 'borderBottomInlineStartRadius':
137
- prop = 'borderBottom' + start + 'Radius'
138
- break
139
- case 'borderBottomInlineEndRadius':
140
- prop = 'borderBottom' + end + 'Radius'
141
- break
142
- case 'marginInlineStart':
143
- prop = 'margin' + start
144
- break
145
- case 'marginInlineEnd':
146
- prop = 'margin' + end
147
- break
148
- case 'insetInlineStart':
149
- case 'offsetInlineStart':
150
- prop = start.toLowerCase()
151
- break
152
- case 'insetInlineEnd':
153
- case 'offsetInlineEnd':
154
- prop = end.toLowerCase()
155
- break
156
- default:
157
- break
158
- }
159
-
160
- if (DEBUG) log(`${originalProp}: ${originalValue} => ${prop}: ${value}`)
161
-
162
- return { prop, value }
163
- }
164
-
165
- const isSupportedProps = (prop: string) => SUPPORT_PROPS.indexOf(prop) > -1
166
-
167
- const processStyleProps = (
168
- propsObj: StyleObject | string | number | undefined,
169
- dir: Direction
170
- ): StyleObject | string | number | undefined =>
171
- isObject(propsObj)
172
- ? Object.entries(propsObj).reduce(
173
- (accumulator, [originalProp, originalValue]) => {
174
- if (isObject(originalValue)) {
175
- return {
176
- ...accumulator,
177
- [originalProp]: processStyleProps(originalValue, dir)
178
- }
179
- }
180
-
181
- if (
182
- isSupportedProps(originalProp) &&
183
- typeof originalValue !== 'undefined'
184
- ) {
185
- const { prop, value } = processProps(
186
- { originalProp, originalValue },
187
-
188
- dir
189
- )
190
-
191
- return { ...accumulator, [prop]: value }
192
- }
193
-
194
- return { ...accumulator, [originalProp]: originalValue }
195
- },
196
- {}
197
- )
198
- : propsObj
199
-
200
- const bidirectionalPolyfill = <S extends StyleObject>(
201
- styles: S,
202
- dir: Direction
203
- ) =>
204
- Object.entries(styles).reduce(
205
- (accumulator, [style, props]) => ({
206
- ...accumulator,
207
- [style]: processStyleProps(props, dir)
208
- }),
209
- {}
210
- ) as S
211
-
212
- export default bidirectionalPolyfill
213
- export { bidirectionalPolyfill }
@@ -1,6 +0,0 @@
1
- import type { StyleObject } from '../EmotionTypes';
2
- declare type Direction = 'ltr' | 'rtl';
3
- declare const bidirectionalPolyfill: <S extends StyleObject>(styles: S, dir: Direction) => S;
4
- export default bidirectionalPolyfill;
5
- export { bidirectionalPolyfill };
6
- //# sourceMappingURL=bidirectionalPolyfill.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bidirectionalPolyfill.d.ts","sourceRoot":"","sources":["../../src/styleUtils/bidirectionalPolyfill.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD,aAAK,SAAS,GAAG,KAAK,GAAG,KAAK,CAAA;AA0K9B,QAAA,MAAM,qBAAqB,0CAEpB,SAAS,MAQR,CAAA;AAER,eAAe,qBAAqB,CAAA;AACpC,OAAO,EAAE,qBAAqB,EAAE,CAAA"}