@stylexjs/shared 0.2.0-beta.8 → 0.2.0-beta.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _splitCssValue = _interopRequireDefault(require("../utils/split-css-value"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ /**
10
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
11
+ *
12
+ * This source code is licensed under the MIT license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ *
15
+ *
16
+ */
17
+
18
+ // TODO: to be added later.
19
+ // const aliases = {
20
+ // marginInlineStart: (rawValue) => [['marginStart', rawValue]],
21
+ // marginInlineEnd: (rawValue) => [['marginEnd', rawValue]],
22
+ // marginInline: (rawValue) => [
23
+ // ['marginStart', rawValue],
24
+ // ['marginEnd', rawValue],
25
+ // ],
26
+ // paddingInlineStart: (rawValue) => [['paddingStart', rawValue]],
27
+ // paddingInlineEnd: (rawValue) => [['paddingEnd', rawValue]],
28
+ // paddingInline: (rawValue) => [
29
+ // ['paddingStart', rawValue],
30
+ // ['paddingEnd', rawValue],
31
+ // ],
32
+ // // 'borderInlineStart': (rawValue) => [['borderStart', rawValue]],
33
+ // // 'borderInlineEnd': (rawValue) => [['borderEnd', rawValue]],
34
+ // // // This will need to change.
35
+ // // 'borderInline': (rawValue) => [
36
+ // // ['borderStart', rawValue],
37
+ // // ['borderEnd', rawValue],
38
+ // // ],
39
+ // };
40
+
41
+ /**
42
+ * Shorthand properties:
43
+ * - [x] all - Should be banned
44
+ * - [ ] animation
45
+ * - [ ] background
46
+ * - [-] border
47
+ * - [x] border-block-end
48
+ * - [x] border-block-start
49
+ * - [ ] border-bottom
50
+ * - [x] border-color
51
+ * - [x] border-image
52
+ * - [x] border-inline-end
53
+ * - [x] border-inline-start
54
+ * - [ ] border-left
55
+ * - [x] border-radius
56
+ * - [ ] border-right
57
+ * - [x] border-style
58
+ * - [ ] border-top
59
+ * - [x] border-width
60
+ * - [ ] column-rule
61
+ * - [ ] columns
62
+ * - [ ] flex
63
+ * - [ ] flex-flow
64
+ * - [ ] font
65
+ * - [ ] gap
66
+ * - [ ] grid
67
+ * - [ ] grid-area
68
+ * - [ ] grid-column
69
+ * - [ ] grid-row
70
+ * - [ ] grid-template
71
+ * - [ ] list-style
72
+ * - [x] margin
73
+ * - [ ] mask
74
+ * - [ ] offset
75
+ * - [ ] outline
76
+ * - [x] overflow
77
+ * - [x] padding
78
+ * - [ ] place-content
79
+ * - [ ] place-items
80
+ * - [ ] place-self
81
+ * - [ ] scroll-margin
82
+ * - [ ] scroll-padding
83
+ * - [ ] text-decoration
84
+ * - [ ] text-emphasis
85
+ * - [ ] transition
86
+ */
87
+
88
+ const expansions = {
89
+ // ...aliases,
90
+ border: rawValue => {
91
+ return [['borderTop', rawValue], ['borderEnd', rawValue], ['borderBottom', rawValue], ['borderStart', rawValue]];
92
+ },
93
+ /*
94
+ // Add this later, as this will be a breaking change
95
+ border: (rawValue: string): Array<[string, string]> => {
96
+ if (typeof rawValue === 'number') {
97
+ return expansions.borderWidth(rawValue);
98
+ }
99
+ const [width, style, color] = splitValue(rawValue);
100
+ return [
101
+ ...expansions.borderWidth(width),
102
+ ...expansions.borderStyle(style),
103
+ ...expansions.borderColor(color),
104
+ ];
105
+ }
106
+ */
107
+ borderColor: rawValue => {
108
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
109
+ return [['borderTopColor', top], ['borderEndColor', right], ['borderBottomColor', bottom], ['borderStartColor', left]];
110
+ },
111
+ borderHorizontal: rawValue => {
112
+ return [['borderStart', rawValue], ['borderEnd', rawValue]];
113
+ },
114
+ borderStyle: rawValue => {
115
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
116
+ return [['borderTopStyle', top], ['borderEndStyle', right], ['borderBottomStyle', bottom], ['borderStartStyle', left]];
117
+ },
118
+ borderVertical: rawValue => {
119
+ return [['borderTop', rawValue], ['borderBottom', rawValue]];
120
+ },
121
+ borderWidth: rawValue => {
122
+ const [top, right = top, bottom = top, left = right] = typeof rawValue === 'number' ? [rawValue] : (0, _splitCssValue.default)(rawValue);
123
+ return [['borderTopWidth', top], ['borderEndWidth', right], ['borderBottomWidth', bottom], ['borderStartWidth', left]];
124
+ },
125
+ borderRadius: rawValue => {
126
+ const [top, right = top, bottom = top, left = right] = typeof rawValue === 'string' ? (0, _splitCssValue.default)(rawValue) : typeof rawValue === 'number' ? [rawValue] : rawValue; // remove
127
+
128
+ return [['borderTopStartRadius', top], ['borderTopEndRadius', right], ['borderBottomEndRadius', bottom], ['borderBottomStartRadius', left]];
129
+ },
130
+ margin: rawValue => {
131
+ const [top, right = top, bottom = top, left = right] = typeof rawValue === 'number' ? [rawValue] : (0, _splitCssValue.default)(rawValue);
132
+ return [['marginTop', top], ['marginEnd', right], ['marginBottom', bottom], ['marginStart', left]];
133
+ },
134
+ marginHorizontal: rawValue => {
135
+ return [['marginStart', rawValue], ['marginEnd', rawValue]];
136
+ },
137
+ marginVertical: rawValue => {
138
+ return [['marginTop', rawValue], ['marginBottom', rawValue]];
139
+ },
140
+ overflow: rawValue => {
141
+ const [x, y = x] = (0, _splitCssValue.default)(rawValue);
142
+ return [['overflowX', x], ['overflowY', y]];
143
+ },
144
+ padding: rawValue => {
145
+ const [top, right = top, bottom = top, left = right] = typeof rawValue === 'number' ? [rawValue] : (0, _splitCssValue.default)(rawValue);
146
+ return [['paddingTop', top], ['paddingEnd', right], ['paddingBottom', bottom], ['paddingStart', left]];
147
+ },
148
+ paddingHorizontal: rawValue => {
149
+ return [['paddingStart', rawValue], ['paddingEnd', rawValue]];
150
+ },
151
+ paddingVertical: rawValue => {
152
+ return [['paddingTop', rawValue], ['paddingBottom', rawValue]];
153
+ }
154
+ };
155
+ var _default = expansions;
156
+ exports.default = _default;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = flatMapExpandedShorthands;
7
+ exports.getExpandedKeys = getExpandedKeys;
8
+ var _applicationOrder = _interopRequireDefault(require("./application-order"));
9
+ var _legacyExpandShorthands = _interopRequireDefault(require("./legacy-expand-shorthands"));
10
+ var _propertySpecificity = _interopRequireDefault(require("./property-specificity"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ *
19
+ */
20
+
21
+ const expansions = {
22
+ 'application-order': _applicationOrder.default,
23
+ 'property-specificity': _propertySpecificity.default,
24
+ 'legacy-expand-shorthands': _legacyExpandShorthands.default
25
+ };
26
+ function getExpandedKeys(options) {
27
+ return Object.keys(expansions[options.styleResolution ?? 'application-order']);
28
+ }
29
+ function flatMapExpandedShorthands(objEntry, options) {
30
+ const [key, value] = objEntry;
31
+ const expansion = expansions[options.styleResolution ?? 'application-order'][key];
32
+ if (expansion) {
33
+ if (Array.isArray(value)) {
34
+ throw new Error('Cannot use fallbacks for shorthands. Use the expansion instead.');
35
+ }
36
+ return expansion(value);
37
+ }
38
+ return [[key, value]];
39
+ }
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _splitCssValue = _interopRequireDefault(require("../utils/split-css-value"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ /**
10
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
11
+ *
12
+ * This source code is licensed under the MIT license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ *
15
+ *
16
+ */
17
+
18
+ const borderWidthKeywords = new Set(['thin', 'medium', 'thick']);
19
+ const borderStyleKeywords = new Set(['none', 'hidden', 'solid', 'dashed', 'dotted', 'double', 'groove', 'ridge', 'inside',
20
+ // Non-standard
21
+ 'inset', 'outset']);
22
+ const globalKeywords = new Set(['initial', 'inherit', 'unset']);
23
+ function borderDetector(borderParts) {
24
+ const parts = borderParts.filter(Boolean).slice();
25
+ let suffix = '';
26
+ for (let i = 0; i < parts.length; i++) {
27
+ const part = parts[i];
28
+ if (typeof part === 'string' && part.endsWith('!important')) {
29
+ parts[i] = part.replace('!important', '').trim();
30
+ suffix = ' !important';
31
+ }
32
+ }
33
+ if (parts.length === 1 && globalKeywords.has(parts[0])) {
34
+ return [parts[0], parts[0], parts[0]];
35
+ }
36
+
37
+ // Find the part that starts with a number
38
+ // This is most likely to be the borderWidth
39
+ let width = parts.find(part => typeof part === 'number' || part.match(/^\.?\d+/) || borderWidthKeywords.has(part));
40
+ if (typeof width === 'number') {
41
+ width = String(width) + 'px';
42
+ }
43
+ // console.log('width', width);
44
+ if (width != null) {
45
+ parts.splice(parts.indexOf(width), 1);
46
+ }
47
+ if (parts.length === 0) {
48
+ return [String(width) + suffix, null, null];
49
+ }
50
+ const style = parts.find(part => typeof part === 'string' && borderStyleKeywords.has(part));
51
+ if (style != null) {
52
+ parts.splice(parts.indexOf(style), 1);
53
+ }
54
+ if (parts.length === 2 && width == null) {
55
+ width = parts[0];
56
+ parts.splice(0, 1);
57
+ }
58
+ if (width != null && parts.length > 1) {
59
+ throw new Error('Invalid border shorthand value');
60
+ }
61
+ const color = parts[0];
62
+ return [width, style, color].map(part => part != null ? part + suffix : null);
63
+ }
64
+ const expansions = {
65
+ border: rawValue => {
66
+ if (typeof rawValue === 'number') {
67
+ return expansions.borderWidth(rawValue);
68
+ }
69
+ const parts = (0, _splitCssValue.default)(rawValue);
70
+ const [width, style, color] = borderDetector(parts);
71
+ return [...(width != null ? expansions.borderWidth(width) : []), ...(style != null ? expansions.borderStyle(style) : []), ...(color != null ? expansions.borderColor(color) : [])];
72
+ },
73
+ borderTop: rawValue => {
74
+ if (typeof rawValue === 'number') {
75
+ return [['borderTopWidth', rawValue]];
76
+ }
77
+ const parts = (0, _splitCssValue.default)(rawValue);
78
+ const [width, style, color] = borderDetector(parts);
79
+ return [width != null ? ['borderTopWidth', width] : null, style != null ? ['borderTopStyle', style] : null, color != null ? ['borderTopColor', color] : null].filter(Boolean);
80
+ },
81
+ borderEnd: rawValue => {
82
+ if (typeof rawValue === 'number') {
83
+ return [['borderEndWidth', rawValue]];
84
+ }
85
+ const parts = (0, _splitCssValue.default)(rawValue);
86
+ const [width, style, color] = borderDetector(parts);
87
+ return [width != null ? ['borderEndWidth', width] : null, style != null ? ['borderEndStyle', style] : null, color != null ? ['borderEndColor', color] : null].filter(Boolean);
88
+ },
89
+ borderRight: rawValue => {
90
+ if (typeof rawValue === 'number') {
91
+ return [['borderRightWidth', rawValue]];
92
+ }
93
+ const parts = (0, _splitCssValue.default)(rawValue);
94
+ const [width, style, color] = borderDetector(parts);
95
+ return [width != null ? ['borderRightWidth', width] : null, style != null ? ['borderRightStyle', style] : null, color != null ? ['borderRightColor', color] : null].filter(Boolean);
96
+ },
97
+ borderBottom: rawValue => {
98
+ if (typeof rawValue === 'number') {
99
+ return [['borderBottomWidth', rawValue]];
100
+ }
101
+ const parts = (0, _splitCssValue.default)(rawValue);
102
+ const [width, style, color] = borderDetector(parts);
103
+ return [width != null ? ['borderBottomWidth', width] : null, style != null ? ['borderBottomStyle', style] : null, color != null ? ['borderBottomColor', color] : null].filter(Boolean);
104
+ },
105
+ borderStart: rawValue => {
106
+ if (typeof rawValue === 'number') {
107
+ return [['borderStartWidth', rawValue]];
108
+ }
109
+ const parts = (0, _splitCssValue.default)(rawValue);
110
+ const [width, style, color] = borderDetector(parts);
111
+ return [width != null ? ['borderStartWidth', width] : null, style != null ? ['borderStartStyle', style] : null, color != null ? ['borderStartColor', color] : null].filter(Boolean);
112
+ },
113
+ borderLeft: rawValue => {
114
+ if (typeof rawValue === 'number') {
115
+ return [['borderLeftWidth', rawValue]];
116
+ }
117
+ const parts = (0, _splitCssValue.default)(rawValue);
118
+ const [width, style, color] = borderDetector(parts);
119
+ return [width != null ? ['borderLeftWidth', width] : null, style != null ? ['borderLeftStyle', style] : null, color != null ? ['borderLeftColor', color] : null].filter(Boolean);
120
+ },
121
+ borderColor: rawValue => {
122
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
123
+ return [['borderTopColor', top], ['borderEndColor', right], ['borderBottomColor', bottom], ['borderStartColor', left]];
124
+ },
125
+ borderHorizontal: rawValue => {
126
+ return [...expansions.borderStart(rawValue), ...expansions.borderEnd(rawValue)];
127
+ },
128
+ borderStyle: rawValue => {
129
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
130
+ return [['borderTopStyle', top], ['borderEndStyle', right], ['borderBottomStyle', bottom], ['borderStartStyle', left]];
131
+ },
132
+ borderVertical: rawValue => {
133
+ return [...expansions.borderTop(rawValue), ...expansions.borderBottom(rawValue)];
134
+ },
135
+ borderWidth: rawValue => {
136
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
137
+ return [['borderTopWidth', top], ['borderEndWidth', right], ['borderBottomWidth', bottom], ['borderStartWidth', left]];
138
+ },
139
+ borderRadius: rawValue => {
140
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
141
+ return [['borderTopStartRadius', top], ['borderTopEndRadius', right], ['borderBottomEndRadius', bottom], ['borderBottomStartRadius', left]];
142
+ },
143
+ margin: rawValue => {
144
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
145
+ return [['marginTop', top], ['marginEnd', right], ['marginBottom', bottom], ['marginStart', left]];
146
+ },
147
+ marginHorizontal: rawValue => {
148
+ return [['marginStart', rawValue], ['marginEnd', rawValue]];
149
+ },
150
+ marginVertical: rawValue => {
151
+ return [['marginTop', rawValue], ['marginBottom', rawValue]];
152
+ },
153
+ overflow: rawValue => {
154
+ const [x, y = x] = (0, _splitCssValue.default)(rawValue);
155
+ return [['overflowX', x], ['overflowY', y]];
156
+ },
157
+ padding: rawValue => {
158
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
159
+ return [['paddingTop', top], ['paddingEnd', right], ['paddingBottom', bottom], ['paddingStart', left]];
160
+ },
161
+ paddingHorizontal: rawValue => {
162
+ return [['paddingStart', rawValue], ['paddingEnd', rawValue]];
163
+ },
164
+ paddingVertical: rawValue => {
165
+ return [['paddingTop', rawValue], ['paddingBottom', rawValue]];
166
+ }
167
+ };
168
+ var _default = expansions;
169
+ exports.default = _default;