@instructure/emotion 8.10.3-snapshot.2 → 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 +24 -11
- package/lib/withStyle.js +25 -13
- package/package.json +10 -10
- package/src/withStyle.tsx +30 -18
- package/types/withStyle.d.ts.map +1 -1
- package/es/styleUtils/bidirectionalPolyfill.js +0 -183
- package/lib/styleUtils/bidirectionalPolyfill.js +0 -193
- package/src/styleUtils/bidirectionalPolyfill.ts +0 -213
- package/types/styleUtils/bidirectionalPolyfill.d.ts +0 -6
- package/types/styleUtils/bidirectionalPolyfill.d.ts.map +0 -1
package/es/withStyle.js
CHANGED
|
@@ -26,12 +26,14 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
26
26
|
import React, { forwardRef, useState } from 'react';
|
|
27
27
|
import { isEqual } from 'lodash';
|
|
28
28
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
29
|
+
import { warn } from '@instructure/console';
|
|
29
30
|
import { decorator } from '@instructure/ui-decorator';
|
|
30
|
-
import { useTextDirectionContext } from '@instructure/ui-i18n';
|
|
31
|
-
import { bidirectionalPolyfill } from './styleUtils/bidirectionalPolyfill';
|
|
32
31
|
import { getComponentThemeOverride } from './getComponentThemeOverride';
|
|
33
32
|
import { useTheme } from './useTheme';
|
|
34
|
-
|
|
33
|
+
const defaultValues = {
|
|
34
|
+
styles: {},
|
|
35
|
+
makeStyles: () => {}
|
|
36
|
+
};
|
|
35
37
|
/**
|
|
36
38
|
* ---
|
|
37
39
|
* category: utilities/themes
|
|
@@ -100,26 +102,36 @@ import { useTheme } from './useTheme';
|
|
|
100
102
|
* @param {function} generateComponentTheme - The function that returns the component's theme variables object
|
|
101
103
|
* @returns {ReactElement} The decorated WithStyle Component
|
|
102
104
|
*/
|
|
105
|
+
|
|
103
106
|
const withStyle = decorator((ComposedComponent, generateStyle, generateComponentTheme) => {
|
|
104
107
|
const displayName = ComposedComponent.displayName || ComposedComponent.name;
|
|
105
108
|
const WithStyle = /*#__PURE__*/forwardRef((props, ref) => {
|
|
106
109
|
const theme = useTheme();
|
|
107
|
-
|
|
110
|
+
|
|
111
|
+
if (props.styles) {
|
|
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);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (props.makeStyles) {
|
|
116
|
+
warn(false, `Manually passing the "makeStyles" property is not allowed on the ${displayName} component. Styles are calculated by the @withStyle decorator.`);
|
|
117
|
+
}
|
|
118
|
+
|
|
108
119
|
const componentProps = { ...ComposedComponent.defaultProps,
|
|
109
|
-
...props
|
|
120
|
+
...props,
|
|
121
|
+
...defaultValues
|
|
110
122
|
};
|
|
111
123
|
const themeOverride = getComponentThemeOverride(theme, displayName, ComposedComponent.componentId, componentProps);
|
|
112
124
|
const componentTheme = typeof generateComponentTheme === 'function' ? { ...generateComponentTheme(theme),
|
|
113
125
|
...themeOverride
|
|
114
126
|
} : {};
|
|
115
127
|
|
|
116
|
-
const _useState = useState(generateStyle ?
|
|
128
|
+
const _useState = useState(generateStyle ? generateStyle(componentTheme, componentProps, {}) : {}),
|
|
117
129
|
_useState2 = _slicedToArray(_useState, 2),
|
|
118
130
|
styles = _useState2[0],
|
|
119
131
|
setStyles = _useState2[1];
|
|
120
132
|
|
|
121
133
|
const makeStyleHandler = extraArgs => {
|
|
122
|
-
const calculatedStyles =
|
|
134
|
+
const calculatedStyles = generateStyle(componentTheme, componentProps, extraArgs);
|
|
123
135
|
|
|
124
136
|
if (!isEqual(calculatedStyles, styles)) {
|
|
125
137
|
setStyles(calculatedStyles);
|
|
@@ -127,10 +139,11 @@ const withStyle = decorator((ComposedComponent, generateStyle, generateComponent
|
|
|
127
139
|
};
|
|
128
140
|
|
|
129
141
|
return /*#__PURE__*/React.createElement(ComposedComponent, Object.assign({
|
|
130
|
-
ref: ref
|
|
142
|
+
ref: ref
|
|
143
|
+
}, props, {
|
|
131
144
|
makeStyles: makeStyleHandler,
|
|
132
145
|
styles: styles
|
|
133
|
-
}
|
|
146
|
+
}));
|
|
134
147
|
});
|
|
135
148
|
hoistNonReactStatics(WithStyle, ComposedComponent); // we have to pass these on, because sometimes users
|
|
136
149
|
// access propTypes of the component in other components
|
|
@@ -145,8 +158,8 @@ const withStyle = decorator((ComposedComponent, generateStyle, generateComponent
|
|
|
145
158
|
// eslint-disable-next-line no-param-reassign
|
|
146
159
|
|
|
147
160
|
ComposedComponent.defaultProps = { ...ComposedComponent.defaultProps,
|
|
148
|
-
makeStyles:
|
|
149
|
-
styles:
|
|
161
|
+
makeStyles: defaultValues.makeStyles,
|
|
162
|
+
styles: defaultValues.styles
|
|
150
163
|
};
|
|
151
164
|
|
|
152
165
|
if (process.env.NODE_ENV !== 'production') {
|
package/lib/withStyle.js
CHANGED
|
@@ -17,11 +17,9 @@ var _lodash = require("lodash");
|
|
|
17
17
|
|
|
18
18
|
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
|
19
19
|
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var _uiI18n = require("@instructure/ui-i18n");
|
|
20
|
+
var _console = require("@instructure/console");
|
|
23
21
|
|
|
24
|
-
var
|
|
22
|
+
var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
|
|
25
23
|
|
|
26
24
|
var _getComponentThemeOverride = require("./getComponentThemeOverride");
|
|
27
25
|
|
|
@@ -50,7 +48,10 @@ var _useTheme = require("./useTheme");
|
|
|
50
48
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
51
49
|
* SOFTWARE.
|
|
52
50
|
*/
|
|
53
|
-
|
|
51
|
+
const defaultValues = {
|
|
52
|
+
styles: {},
|
|
53
|
+
makeStyles: () => {}
|
|
54
|
+
};
|
|
54
55
|
/**
|
|
55
56
|
* ---
|
|
56
57
|
* category: utilities/themes
|
|
@@ -119,26 +120,36 @@ var _useTheme = require("./useTheme");
|
|
|
119
120
|
* @param {function} generateComponentTheme - The function that returns the component's theme variables object
|
|
120
121
|
* @returns {ReactElement} The decorated WithStyle Component
|
|
121
122
|
*/
|
|
123
|
+
|
|
122
124
|
const withStyle = (0, _decorator.decorator)((ComposedComponent, generateStyle, generateComponentTheme) => {
|
|
123
125
|
const displayName = ComposedComponent.displayName || ComposedComponent.name;
|
|
124
126
|
const WithStyle = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
125
127
|
const theme = (0, _useTheme.useTheme)();
|
|
126
|
-
|
|
128
|
+
|
|
129
|
+
if (props.styles) {
|
|
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);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (props.makeStyles) {
|
|
134
|
+
(0, _console.warn)(false, `Manually passing the "makeStyles" property is not allowed on the ${displayName} component. Styles are calculated by the @withStyle decorator.`);
|
|
135
|
+
}
|
|
136
|
+
|
|
127
137
|
const componentProps = { ...ComposedComponent.defaultProps,
|
|
128
|
-
...props
|
|
138
|
+
...props,
|
|
139
|
+
...defaultValues
|
|
129
140
|
};
|
|
130
141
|
const themeOverride = (0, _getComponentThemeOverride.getComponentThemeOverride)(theme, displayName, ComposedComponent.componentId, componentProps);
|
|
131
142
|
const componentTheme = typeof generateComponentTheme === 'function' ? { ...generateComponentTheme(theme),
|
|
132
143
|
...themeOverride
|
|
133
144
|
} : {};
|
|
134
145
|
|
|
135
|
-
const _useState = (0, _react.useState)(generateStyle ?
|
|
146
|
+
const _useState = (0, _react.useState)(generateStyle ? generateStyle(componentTheme, componentProps, {}) : {}),
|
|
136
147
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
137
148
|
styles = _useState2[0],
|
|
138
149
|
setStyles = _useState2[1];
|
|
139
150
|
|
|
140
151
|
const makeStyleHandler = extraArgs => {
|
|
141
|
-
const calculatedStyles =
|
|
152
|
+
const calculatedStyles = generateStyle(componentTheme, componentProps, extraArgs);
|
|
142
153
|
|
|
143
154
|
if (!(0, _lodash.isEqual)(calculatedStyles, styles)) {
|
|
144
155
|
setStyles(calculatedStyles);
|
|
@@ -146,10 +157,11 @@ const withStyle = (0, _decorator.decorator)((ComposedComponent, generateStyle, g
|
|
|
146
157
|
};
|
|
147
158
|
|
|
148
159
|
return /*#__PURE__*/_react.default.createElement(ComposedComponent, Object.assign({
|
|
149
|
-
ref: ref
|
|
160
|
+
ref: ref
|
|
161
|
+
}, props, {
|
|
150
162
|
makeStyles: makeStyleHandler,
|
|
151
163
|
styles: styles
|
|
152
|
-
}
|
|
164
|
+
}));
|
|
153
165
|
});
|
|
154
166
|
(0, _hoistNonReactStatics.default)(WithStyle, ComposedComponent); // we have to pass these on, because sometimes users
|
|
155
167
|
// access propTypes of the component in other components
|
|
@@ -164,8 +176,8 @@ const withStyle = (0, _decorator.decorator)((ComposedComponent, generateStyle, g
|
|
|
164
176
|
// eslint-disable-next-line no-param-reassign
|
|
165
177
|
|
|
166
178
|
ComposedComponent.defaultProps = { ...ComposedComponent.defaultProps,
|
|
167
|
-
makeStyles:
|
|
168
|
-
styles:
|
|
179
|
+
makeStyles: defaultValues.makeStyles,
|
|
180
|
+
styles: defaultValues.styles
|
|
169
181
|
};
|
|
170
182
|
|
|
171
183
|
if (process.env.NODE_ENV !== 'production') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/emotion",
|
|
3
|
-
"version": "8.10.3-snapshot.
|
|
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.
|
|
30
|
-
"@instructure/shared-types": "8.10.3-snapshot.
|
|
31
|
-
"@instructure/ui-decorator": "8.10.3-snapshot.
|
|
32
|
-
"@instructure/ui-i18n": "8.10.3-snapshot.
|
|
33
|
-
"@instructure/ui-themes": "8.10.3-snapshot.
|
|
34
|
-
"@instructure/ui-utils": "8.10.3-snapshot.
|
|
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.
|
|
42
|
-
"@instructure/ui-test-utils": "8.10.3-snapshot.
|
|
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": "
|
|
53
|
+
"gitHead": "ed32a6c3b14ddb7fbbb5b543d9871a296f06e4c0"
|
|
54
54
|
}
|
package/src/withStyle.tsx
CHANGED
|
@@ -32,9 +32,8 @@ import type {
|
|
|
32
32
|
import { isEqual } from 'lodash'
|
|
33
33
|
import hoistNonReactStatics from 'hoist-non-react-statics'
|
|
34
34
|
|
|
35
|
+
import { warn } from '@instructure/console'
|
|
35
36
|
import { decorator } from '@instructure/ui-decorator'
|
|
36
|
-
import { useTextDirectionContext } from '@instructure/ui-i18n'
|
|
37
|
-
import { bidirectionalPolyfill } from './styleUtils/bidirectionalPolyfill'
|
|
38
37
|
|
|
39
38
|
import { getComponentThemeOverride } from './getComponentThemeOverride'
|
|
40
39
|
import { useTheme } from './useTheme'
|
|
@@ -76,6 +75,11 @@ type WithStyleProps<
|
|
|
76
75
|
? WithStylePrivateProps<Style>
|
|
77
76
|
: WithStylePrivateProps<Style> & ThemeOverrideProp<Theme>
|
|
78
77
|
|
|
78
|
+
const defaultValues = {
|
|
79
|
+
styles: {},
|
|
80
|
+
makeStyles: () => {}
|
|
81
|
+
}
|
|
82
|
+
|
|
79
83
|
/**
|
|
80
84
|
* ---
|
|
81
85
|
* category: utilities/themes
|
|
@@ -159,11 +163,25 @@ const withStyle = decorator(
|
|
|
159
163
|
allowedProps?: string[]
|
|
160
164
|
} = forwardRef((props, ref) => {
|
|
161
165
|
const theme = useTheme()
|
|
162
|
-
const dir = useTextDirectionContext()
|
|
163
166
|
|
|
167
|
+
if (props.styles) {
|
|
168
|
+
warn(
|
|
169
|
+
false,
|
|
170
|
+
`Manually passing the "styles" property is not allowed on the ${displayName} component. Using the default styles calculated by the @withStyle decorator instead.\n`,
|
|
171
|
+
props.styles
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (props.makeStyles) {
|
|
176
|
+
warn(
|
|
177
|
+
false,
|
|
178
|
+
`Manually passing the "makeStyles" property is not allowed on the ${displayName} component. Styles are calculated by the @withStyle decorator.`
|
|
179
|
+
)
|
|
180
|
+
}
|
|
164
181
|
const componentProps: Props = {
|
|
165
182
|
...ComposedComponent.defaultProps,
|
|
166
|
-
...props
|
|
183
|
+
...props,
|
|
184
|
+
...defaultValues
|
|
167
185
|
}
|
|
168
186
|
|
|
169
187
|
const themeOverride = getComponentThemeOverride(
|
|
@@ -182,20 +200,14 @@ const withStyle = decorator(
|
|
|
182
200
|
: {}
|
|
183
201
|
|
|
184
202
|
const [styles, setStyles] = useState(
|
|
185
|
-
generateStyle
|
|
186
|
-
? bidirectionalPolyfill(
|
|
187
|
-
generateStyle(componentTheme, componentProps, {}),
|
|
188
|
-
// @ts-expect-error TODO: this shouldn't be "auto" (INSTUI-3241)
|
|
189
|
-
dir
|
|
190
|
-
)
|
|
191
|
-
: {}
|
|
203
|
+
generateStyle ? generateStyle(componentTheme, componentProps, {}) : {}
|
|
192
204
|
)
|
|
193
205
|
|
|
194
206
|
const makeStyleHandler: WithStyleProps['makeStyles'] = (extraArgs) => {
|
|
195
|
-
const calculatedStyles =
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
207
|
+
const calculatedStyles = generateStyle(
|
|
208
|
+
componentTheme,
|
|
209
|
+
componentProps,
|
|
210
|
+
extraArgs
|
|
199
211
|
)
|
|
200
212
|
if (!isEqual(calculatedStyles, styles)) {
|
|
201
213
|
setStyles(calculatedStyles)
|
|
@@ -205,9 +217,9 @@ const withStyle = decorator(
|
|
|
205
217
|
return (
|
|
206
218
|
<ComposedComponent
|
|
207
219
|
ref={ref}
|
|
220
|
+
{...props}
|
|
208
221
|
makeStyles={makeStyleHandler}
|
|
209
222
|
styles={styles}
|
|
210
|
-
{...props}
|
|
211
223
|
/>
|
|
212
224
|
)
|
|
213
225
|
})
|
|
@@ -230,8 +242,8 @@ const withStyle = decorator(
|
|
|
230
242
|
// eslint-disable-next-line no-param-reassign
|
|
231
243
|
ComposedComponent.defaultProps = {
|
|
232
244
|
...ComposedComponent.defaultProps,
|
|
233
|
-
makeStyles:
|
|
234
|
-
styles:
|
|
245
|
+
makeStyles: defaultValues.makeStyles,
|
|
246
|
+
styles: defaultValues.styles
|
|
235
247
|
}
|
|
236
248
|
|
|
237
249
|
if (process.env.NODE_ENV !== 'production') {
|
package/types/withStyle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withStyle.d.ts","sourceRoot":"","sources":["../src/withStyle.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAA+C,MAAM,OAAO,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"}
|