@stylexjs/shared 0.1.0-beta.6 → 0.2.0-beta.10

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.
Files changed (34) hide show
  1. package/README.md +81 -0
  2. package/lib/convert-to-className.js +13 -6
  3. package/lib/expand-shorthands.d.ts +5 -0
  4. package/lib/expand-shorthands.js +241 -101
  5. package/lib/generate-css-rule.js +10 -38
  6. package/lib/index.d.ts +14 -2
  7. package/lib/index.js.flow +5 -0
  8. package/lib/messages.js +11 -3
  9. package/lib/namespace-transforms/__tests__/preflatten.test.js +120 -0
  10. package/lib/namespace-transforms/preflatten.js +89 -0
  11. package/lib/physical-rtl/generate-ltr.js +32 -32
  12. package/lib/physical-rtl/generate-rtl.js +30 -30
  13. package/lib/preprocess-rules/PreRule.js +101 -0
  14. package/lib/preprocess-rules/application-order.js +259 -0
  15. package/lib/preprocess-rules/basic-validation.js +92 -0
  16. package/lib/preprocess-rules/expand-shorthands.js +156 -0
  17. package/lib/preprocess-rules/flatten-raw-style-obj.js +148 -0
  18. package/lib/preprocess-rules/index.js +39 -0
  19. package/lib/preprocess-rules/legacy-expand-shorthands.js +219 -0
  20. package/lib/preprocess-rules/null-out-longhand.js +310 -0
  21. package/lib/preprocess-rules/property-specificity.js +135 -0
  22. package/lib/preprocess-rules/react-native-web.js +142 -0
  23. package/lib/stylex-create.js +32 -91
  24. package/lib/stylex-defaultValue.js +397 -0
  25. package/lib/stylex-keyframes.js +23 -10
  26. package/lib/utils/Rule.js +71 -0
  27. package/lib/utils/default-options.js +34 -0
  28. package/lib/utils/genCSSRule.js +9 -8
  29. package/lib/utils/normalize-value.js +3 -0
  30. package/lib/utils/object-utils.js +24 -3
  31. package/lib/utils/property-priorities.js +116 -0
  32. package/lib/utils/split-css-value.js +47 -0
  33. package/lib/validate.js +1 -1
  34. package/package.json +1 -1
@@ -0,0 +1,259 @@
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 shorthands = {
19
+ all: _ => {
20
+ throw new Error('all is not supported');
21
+ },
22
+ animation: value => [['animation', value], ['animationName', null], ['animationDuration', null], ['animationTimingFunction', null], ['animationDelay', null], ['animationIterationCount', null], ['animationDirection', null], ['animationFillMode', null], ['animationPlayState', null]],
23
+ background: value => [['background', value], ['backgroundAttachment', null], ['backgroundClip', null], ['backgroundColor', null], ['backgroundImage', null], ['backgroundOrigin', null], ['backgroundPosition', null], ['backgroundRepeat', null], ['backgroundSize', null]],
24
+ // These will be removed later, matching the properties with React Native.
25
+ // For now, we're compiling them to the React Native properties.
26
+ // @Deprecated
27
+ border: rawValue => {
28
+ if (typeof rawValue === 'number') {
29
+ return shorthands.borderWidth(rawValue);
30
+ }
31
+ const [width, style, color] = (0, _splitCssValue.default)(rawValue);
32
+ return [...shorthands.borderWidth(width), ...shorthands.borderStyle(style), ...shorthands.borderColor(color)];
33
+ },
34
+ // @Deprecated
35
+ borderInline: rawValue => {
36
+ if (typeof rawValue === 'number') {
37
+ return [['borderInlineWidth', rawValue], ['borderInlineStartWidth', null], ['borderInlineEndWidth', null]];
38
+ }
39
+ const [width, style, color] = (0, _splitCssValue.default)(rawValue);
40
+ return [...shorthands.borderInlineWidth(width), ...shorthands.borderInlineStyle(style), ...shorthands.borderInlineColor(color)];
41
+ },
42
+ // @Deprecated
43
+ borderBlock: rawValue => {
44
+ if (typeof rawValue === 'number') {
45
+ return [['borderBlockWidth', rawValue], ['borderTopWidth', null], ['borderBottomWidth', null]];
46
+ }
47
+ const [width, style, color] = (0, _splitCssValue.default)(rawValue);
48
+ return [...shorthands.borderBlockWidth(width), ...shorthands.borderBlockStyle(style), ...shorthands.borderBlockColor(color)];
49
+ },
50
+ // @Deprecated
51
+ borderTop: rawValue => {
52
+ if (typeof rawValue === 'number') {
53
+ return [['borderTopWidth', rawValue]];
54
+ }
55
+ const [width, style, color] = (0, _splitCssValue.default)(rawValue);
56
+ return [['borderTopWidth', width], ['borderTopStyle', style], ['borderTopColor', color]];
57
+ },
58
+ // @Deprecated
59
+ borderInlineEnd: rawValue => {
60
+ if (typeof rawValue === 'number') {
61
+ return [['borderInlineEndWidth', rawValue]];
62
+ }
63
+ const [width, style, color] = (0, _splitCssValue.default)(rawValue);
64
+ return [['borderInlineEndWidth', width], ['borderInlineEndStyle', style], ['borderInlineEndColor', color]];
65
+ },
66
+ // @Deprecated
67
+ borderRight: _rawValue => {
68
+ throw new Error(['`borderRight` is not supported.', 'You could use `borderRightWidth`, `borderRightStyle` and `borderRightColor`,', 'but it is preferable to use `borderInlineEndWidth`, `borderInlineEndStyle` and `borderInlineEndColor`.'].join(' '));
69
+ },
70
+ // @Deprecated
71
+ borderBottom: rawValue => {
72
+ if (typeof rawValue === 'number') {
73
+ return [['borderBottomWidth', rawValue]];
74
+ }
75
+ const [width, style, color] = (0, _splitCssValue.default)(rawValue);
76
+ return [['borderBottomWidth', width], ['borderBottomStyle', style], ['borderBottomColor', color]];
77
+ },
78
+ // @Deprecated
79
+ borderInlineStart: rawValue => {
80
+ if (typeof rawValue === 'number') {
81
+ return [['borderInlineStartWidth', rawValue]];
82
+ }
83
+ const [width, style, color] = (0, _splitCssValue.default)(rawValue);
84
+ return [['borderInlineStartWidth', width], ['borderInlineStartStyle', style], ['borderInlineStartColor', color]];
85
+ },
86
+ // @Deprecated
87
+ borderLeft: _rawValue => {
88
+ throw new Error(['`borderLeft` is not supported.', 'You could use `borderLeftWidth`, `borderLeftStyle` and `borderLeftColor`,', 'but it is preferable to use `borderInlineStartWidth`, `borderInlineStartStyle` and `borderInlineStartColor`.'].join(' '));
89
+ },
90
+ borderInlineWidth: rawValue => [['borderInlineWidth', rawValue], ['borderInlineStartWidth', null], ['borderLeftWidth', null], ['borderInlineEndWidth', null], ['borderRightWidth', null]],
91
+ borderInlineStyle: rawValue => [['borderInlineStyle', rawValue], ['borderInlineStartStyle', null], ['borderLeftStyle', null], ['borderInlineEndStyle', null], ['borderRightStyle', null]],
92
+ borderInlineColor: rawValue => [['borderInlineColor', rawValue], ['borderInlineStartColor', null], ['borderLeftColor', null], ['borderInlineEndColor', null], ['borderRightColor', null]],
93
+ borderBlockWidth: rawValue => [['borderBlockWidth', rawValue], ['borderTopWidth', null], ['borderBottomWidth', null]],
94
+ borderBlockStyle: rawValue => [['borderBlockStyle', rawValue], ['borderTopStyle', null], ['borderBottomStyle', null]],
95
+ borderBlockColor: rawValue => [['borderBlockColor', rawValue], ['borderTopColor', null], ['borderBottomColor', null]],
96
+ borderColor: value => [['borderColor', value], ['borderTopColor', null], ['borderInlineEndColor', null], ['borderRightColor', null], ['borderBottomColor', null], ['borderInlineStartColor', null], ['borderLeftColor', null]],
97
+ borderStyle: value => [['borderStyle', value], ['borderTopStyle', null], ['borderInlineEndStyle', null], ['borderRightStyle', null], ['borderBottomStyle', null], ['borderInlineStartStyle', null], ['borderLeftStyle', null]],
98
+ borderWidth: value => [['borderWidth', value], ['borderTopWidth', null], ['borderInlineEndWidth', null], ['borderRightWidth', null], ['borderBottomWidth', null], ['borderInlineStartWidth', null], ['borderLeftWidth', null]],
99
+ borderInlineStartColor: value => [['borderInlineStartColor', value], ['borderLeftColor', null], ['borderRightColor', null]],
100
+ borderInlineEndColor: value => [['borderInlineEndColor', value], ['borderLeftColor', null], ['borderRightColor', null]],
101
+ borderInlineStartStyle: value => [['borderInlineStartStyle', value], ['borderLeftStyle', null], ['borderRightStyle', null]],
102
+ borderInlineEndStyle: value => [['borderInlineEndStyle', value], ['borderLeftStyle', null], ['borderRightStyle', null]],
103
+ borderInlineStartWidth: value => [['borderInlineStartWidth', value], ['borderLeftWidth', null], ['borderRightWidth', null]],
104
+ borderInlineEndWidth: value => [['borderInlineEndWidth', value], ['borderLeftWidth', null], ['borderRightWidth', null]],
105
+ borderLeftColor: value => [['borderLeftColor', value], ['borderInlineStartColor', null], ['borderInlineEndColor', null]],
106
+ borderRightColor: value => [['borderRightColor', value], ['borderInlineStartColor', null], ['borderInlineEndColor', null]],
107
+ borderLeftStyle: value => [['borderLeftStyle', value], ['borderInlineStartStyle', null], ['borderInlineEndStyle', null]],
108
+ borderRightStyle: value => [['borderRightStyle', value], ['borderInlineStartStyle', null], ['borderInlineEndStyle', null]],
109
+ borderLeftWidth: value => [['borderLeftWidth', value], ['borderInlineStartWidth', null], ['borderInlineEndWidth', null]],
110
+ borderRightWidth: value => [['borderRightWidth', value], ['borderInlineStartWidth', null], ['borderInlineEndWidth', null]],
111
+ borderRadius: value => {
112
+ const values = typeof value === 'number' ? [value] : (0, _splitCssValue.default)(value);
113
+ if (values.length === 1) {
114
+ return [['borderRadius', value],
115
+ // // logical constituents
116
+ ['borderStartStartRadius', null], ['borderStartEndRadius', null], ['borderEndStartRadius', null], ['borderEndEndRadius', null],
117
+ // physical constituents
118
+ ['borderTopLeftRadius', null], ['borderTopRightRadius', null], ['borderBottomLeftRadius', null], ['borderBottomRightRadius', null]];
119
+ }
120
+
121
+ // @Deprecated
122
+ const [startStart, startEnd = startStart, endEnd = startStart, endStart = startEnd] = values;
123
+ return [
124
+ // split into logical consituents
125
+ ['borderStartStartRadius', startStart], ['borderStartEndRadius', startEnd], ['borderEndEndRadius', endEnd], ['borderEndStartRadius', endStart],
126
+ // unset physical consituents
127
+ ['borderTopLeftRadius', null], ['borderTopRightRadius', null], ['borderBottomLeftRadius', null], ['borderBottomRightRadius', null]];
128
+ },
129
+ borderStartStartRadius: value => [['borderStartStartRadius', value], ['borderTopLeftRadius', null], ['borderTopRightRadius', null]],
130
+ borderStartEndRadius: value => [['borderStartEndRadius', value], ['borderTopLeftRadius', null], ['borderTopRightRadius', null]],
131
+ borderEndStartRadius: value => [['borderEndStartRadius', value], ['borderBottomLeftRadius', null], ['borderBottomRightRadius', null]],
132
+ borderEndEndRadius: value => [['borderEndEndRadius', value], ['borderBottomLeftRadius', null], ['borderBottomRightRadius', null]],
133
+ borderTopLeftRadius: value => [['borderTopLeftRadius', value], ['borderStartStartRadius', null], ['borderStartEndRadius', null]],
134
+ borderTopRightRadius: value => [['borderTopRightRadius', value], ['borderStartStartRadius', null], ['borderStartEndRadius', null]],
135
+ borderBottomLeftRadius: value => [['borderBottomLeftRadius', value], ['borderEndStartRadius', null], ['borderEndEndRadius', null]],
136
+ borderBottomRightRadius: value => [['borderBottomRightRadius', value], ['borderEndStartRadius', null], ['borderEndEndRadius', null]],
137
+ columnRule: value => [['columnRule', value], ['columnRuleWidth', null], ['columnRuleStyle', null], ['columnRuleColor', null]],
138
+ columns: value => [['columns', value], ['columnCount', null], ['columnWidth', null]],
139
+ container: value => [['container', value], ['containerName', null], ['containerType', null]],
140
+ flex: value => [['flex', value], ['flexGrow', null], ['flexShrink', null], ['flexBasis', null]],
141
+ flexFlow: value => [['flexFlow', value], ['flexDirection', null], ['flexWrap', null]],
142
+ // @Deprecated ?
143
+ font: value => [['font', value], ['fontFamily', null], ['fontSize', null], ['fontStretch', null], ['fontStyle', null], ['fontVariant', null], ['fontWeight', null], ['lineHeight', null]],
144
+ gap: value => [['gap', value], ['rowGap', null], ['columnGap', null]],
145
+ grid: value => [['grid', value], ['gridTemplate', null], ['gridTemplateAreas', null], ['gridTemplateColumns', null], ['gridTemplateRows', null], ['gridAutoRows', null], ['gridAutoColumns', null], ['gridAutoFlow', null]],
146
+ gridArea: value => [['gridArea', value], ['gridRow', null], ['gridRowStart', null], ['gridRowEnd', null], ['gridColumn', null], ['gridColumnStart', null], ['gridColumnEnd', null]],
147
+ gridRow: value => [['gridRow', value], ['gridRowStart', null], ['gridRowEnd', null]],
148
+ gridColumn: value => [['gridColumn', value], ['gridColumnStart', null], ['gridColumnEnd', null]],
149
+ gridTemplate: value => [['gridTemplate', value], ['gridTemplateAreas', null], ['gridTemplateColumns', null], ['gridTemplateRows', null]],
150
+ inset: value => [['inset', value], ['insetInline', null], ['insetBlock', null], ['insetInlineStart', null], ['insetInlineEnd', null], ['top', null], ['right', null], ['bottom', null], ['left', null]],
151
+ insetInline: value => [['insetInline', value], ['insetInlineStart', null], ['insetInlineEnd', null], ['left', null], ['right', null]],
152
+ insetBlock: value => [['insetBlock', value], ['top', null], ['bottom', null]],
153
+ insetInlineStart: value => [['insetInlineStart', value], ['left', null], ['right', null]],
154
+ insetInlineEnd: value => [['insetInlineEnd', value], ['left', null], ['right', null]],
155
+ left: value => [['left', value], ['insetInlineStart', null], ['insetInlineEnd', null]],
156
+ right: value => [['right', value], ['insetInlineStart', null], ['insetInlineEnd', null]],
157
+ listStyle: value => [['listStyle', value], ['listStyleImage', null], ['listStylePosition', null], ['listStyleType', null]],
158
+ margin: value => {
159
+ const values = typeof value === 'number' ? [value] : (0, _splitCssValue.default)(value);
160
+ if (values.length === 1) {
161
+ return [['margin', values[0]], ['marginInlineStart', null], ['marginLeft', null], ['marginInlineEnd', null], ['marginRight', null], ['marginTop', null], ['marginBottom', null]];
162
+ }
163
+ // @Deprecated
164
+ const [top, right = top, bottom = top, left = right] = values;
165
+ return [['marginTop', top], ['marginInlineEnd', right], ['marginBottom', bottom], ['marginInlineStart', left], ['marginLeft', null], ['marginRight', null]];
166
+ },
167
+ marginInline: value => [['marginInline', value], ['marginInlineStart', null], ['marginLeft', null], ['marginInlineEnd', null], ['marginRight', null]],
168
+ marginBlock: value => [['marginBlock', value], ['marginTop', null], ['marginBottom', null]],
169
+ marginInlineStart: value => [['marginInlineStart', value], ['marginLeft', null], ['marginRight', null]],
170
+ marginInlineEnd: value => [['marginInlineEnd', value], ['marginLeft', null], ['marginRight', null]],
171
+ marginLeft: value => [['marginLeft', value], ['marginInlineStart', null], ['marginInlineEnd', null]],
172
+ marginRight: value => [['marginRight', value], ['marginInlineStart', null], ['marginInlineEnd', null]],
173
+ mask: value => [['mask', value], ['maskClip', null], ['maskComposite', null], ['maskImage', null], ['maskMode', null], ['maskOrigin', null], ['maskPosition', null], ['maskRepeat', null], ['maskSize', null]],
174
+ offset: value => [['offset', value], ['offsetAnchor', null], ['offsetDistance', null], ['offsetPath', null], ['offsetPosition', null], ['offsetRotate', null]],
175
+ outline: value => [['outline', value], ['outlineColor', null], ['outlineStyle', null], ['outlineWidth', null]],
176
+ overflow: value => [['overflow', value], ['overflowX', null], ['overflowY', null]],
177
+ padding: rawValue => {
178
+ const values = typeof rawValue === 'number' ? [rawValue] : (0, _splitCssValue.default)(rawValue);
179
+ if (values.length === 1) {
180
+ return [['padding', values[0]], ['paddingStart', null], ['paddingLeft', null], ['paddingEnd', null], ['paddingRight', null], ['paddingTop', null], ['paddingBottom', null]];
181
+ }
182
+ // @Deprecated
183
+ const [top, right = top, bottom = top, left = right] = values;
184
+ return [['paddingTop', top], ['paddingEnd', right], ['paddingBottom', bottom], ['paddingStart', left]];
185
+ },
186
+ paddingInline: rawValue => [['paddingInline', rawValue], ['paddingStart', null], ['paddingLeft', null], ['paddingEnd', null], ['paddingRight', null]],
187
+ paddingBlock: rawValue => [['paddingBlock', rawValue], ['paddingTop', null], ['paddingBottom', null]],
188
+ paddingInlineStart: value => [['paddingInlineStart', value], ['paddingLeft', null], ['paddingRight', null]],
189
+ paddingInlineEnd: value => [['paddingInlineEnd', value], ['paddingLeft', null], ['paddingRight', null]],
190
+ paddingLeft: value => [['paddingLeft', value], ['paddingInlineStart', null], ['paddingInlineEnd', null]],
191
+ paddingRight: value => [['paddingRight', value], ['paddingInlineStart', null], ['paddingInlineEnd', null]],
192
+ placeContent: value => [['placeContent', value], ['alignContent', null], ['justifyContent', null]],
193
+ placeItems: value => [['placeItems', value], ['alignItems', null], ['justifyItems', null]],
194
+ placeSelf: value => [['placeSelf', value], ['alignSelf', null], ['justifySelf', null]],
195
+ scrollMargin: value => [['scrollMargin', value], ['scrollMarginBottom', null], ['scrollMarginLeft', null], ['scrollMarginStart', null], ['scrollMarginRight', null], ['scrollMarginEnd', null], ['scrollMarginTop', null]],
196
+ scrollPadding: value => [['scrollPadding', value], ['scrollPaddingBottom', null], ['scrollPaddingLeft', null], ['scrollPaddingStart', null], ['scrollPaddingRight', null], ['scrollPaddingEnd', null], ['scrollPaddingTop', null]],
197
+ scrollTimeline: value => [['scrollTimeline', value], ['scrollTimelineName', null], ['scrollTimelineAxis', null]],
198
+ textDecoration: value => [['textDecoration', value], ['textDecorationColor', null], ['textDecorationLine', null], ['textDecorationStyle', null], ['textDecorationThickness', null]],
199
+ textEmphasis: value => [['textEmphasis', value], ['textEmphasisColor', null], ['textEmphasisStyle', null]],
200
+ transition: value => [['transition', value], ['transitionDelay', null], ['transitionDuration', null], ['transitionProperty', null], ['transitionTimingFunction', null]]
201
+ };
202
+ const aliases = {
203
+ // @Deprecated
204
+ borderHorizontal: shorthands.borderInline,
205
+ // @Deprecated
206
+ borderVertical: shorthands.borderBlock,
207
+ // @Deprecated
208
+ borderBlockStart: shorthands.borderTop,
209
+ // @Deprecated
210
+ borderEnd: shorthands.borderInlineEnd,
211
+ // @Deprecated
212
+ borderBlockEnd: shorthands.borderBottom,
213
+ // @Deprecated
214
+ borderStart: shorthands.borderInlineStart,
215
+ borderHorizontalWidth: shorthands.borderInlineWidth,
216
+ borderHorizontalStyle: shorthands.borderInlineStyle,
217
+ borderHorizontalColor: shorthands.borderInlineColor,
218
+ borderVerticalWidth: shorthands.borderBlockWidth,
219
+ borderVerticalStyle: shorthands.borderBlockStyle,
220
+ borderVerticalColor: shorthands.borderBlockColor,
221
+ borderBlockStartColor: value => [['borderTopColor', value]],
222
+ borderBlockEndColor: value => [['borderBottomColor', value]],
223
+ borderBlockStartStyle: value => [['borderTopStyle', value]],
224
+ borderBlockEndStyle: value => [['borderBottomStyle', value]],
225
+ borderBlockStartWidth: value => [['borderTopWidth', value]],
226
+ borderBlockEndWidth: value => [['borderBottomWidth', value]],
227
+ borderStartColor: shorthands.borderInlineStartColor,
228
+ borderEndColor: shorthands.borderInlineEndColor,
229
+ borderStartStyle: shorthands.borderInlineStartStyle,
230
+ borderEndStyle: shorthands.borderInlineEndStyle,
231
+ borderStartWidth: shorthands.borderInlineStartWidth,
232
+ borderEndWidth: shorthands.borderInlineEndWidth,
233
+ borderTopStartRadius: value => [['borderStartStartRadius', value]],
234
+ borderTopEndRadius: value => [['borderStartEndRadius', value]],
235
+ borderBottomStartRadius: value => [['borderEndStartRadius', value]],
236
+ borderBottomEndRadius: value => [['borderEndEndRadius', value]],
237
+ marginBlockStart: value => [['marginTop', value]],
238
+ marginBlockEnd: value => [['marginBottom', value]],
239
+ marginStart: shorthands.marginInlineStart,
240
+ marginEnd: shorthands.marginInlineEnd,
241
+ marginHorizontal: shorthands.marginInline,
242
+ marginVertical: shorthands.marginBlock,
243
+ paddingBlockStart: rawValue => [['paddingTop', rawValue]],
244
+ paddingBlockEnd: rawValue => [['paddingBottom', rawValue]],
245
+ paddingStart: shorthands.paddingInlineStart,
246
+ paddingEnd: shorthands.paddingInlineEnd,
247
+ paddingHorizontal: shorthands.paddingInline,
248
+ paddingVertical: shorthands.paddingBlock,
249
+ insetBlockStart: value => [['top', value]],
250
+ insetBlockEnd: value => [['bottom', value]],
251
+ start: shorthands.insetInlineStart,
252
+ end: shorthands.insetInlineEnd
253
+ };
254
+ const expansions = {
255
+ ...shorthands,
256
+ ...aliases
257
+ };
258
+ var _default = expansions;
259
+ exports.default = _default;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validateNamespace = validateNamespace;
7
+ var _ = require("..");
8
+ var messages = _interopRequireWildcard(require("../messages"));
9
+ var _objectUtils = require("../utils/object-utils");
10
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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
+ function validateNamespace(namespace) {
22
+ let conditions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
23
+ if (!(0, _objectUtils.isPlainObject)(namespace)) {
24
+ throw new Error(messages.ILLEGAL_NAMESPACE_VALUE);
25
+ }
26
+ const ns = namespace;
27
+ for (const key in ns) {
28
+ const val = ns[key];
29
+ if (val === null || typeof val === 'string' || typeof val === 'number') {
30
+ continue;
31
+ }
32
+ if (Array.isArray(val)) {
33
+ for (const v of val) {
34
+ if (v === null || typeof v === 'string' || typeof v === 'number') {
35
+ continue;
36
+ }
37
+ throw new Error(messages.ILLEGAL_PROP_ARRAY_VALUE);
38
+ }
39
+ continue;
40
+ }
41
+ if (val instanceof _.IncludedStyles) {
42
+ if (conditions.length === 0) {
43
+ continue;
44
+ }
45
+ throw new Error(messages.ONLY_TOP_LEVEL_INLCUDES);
46
+ }
47
+ if ((0, _objectUtils.isPlainObject)(val)) {
48
+ if (key.startsWith('@') || key.startsWith(':')) {
49
+ if (conditions.includes(key)) {
50
+ throw new Error(messages.DUPLICATE_CONDITIONAL);
51
+ }
52
+ validateNamespace(val, [...conditions, key]);
53
+ } else {
54
+ validateConditionalStyles(val);
55
+ }
56
+ continue;
57
+ }
58
+ throw new Error(messages.ILLEGAL_PROP_VALUE);
59
+ }
60
+ }
61
+ function validateConditionalStyles(val) {
62
+ let conditions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
63
+ for (const key in val) {
64
+ const v = val[key];
65
+ if (!(key.startsWith('@') || key.startsWith(':') || key === 'default')) {
66
+ throw new Error(messages.INVALID_PSEUDO_OR_AT_RULE);
67
+ }
68
+ if (conditions.includes(key)) {
69
+ throw new Error(messages.DUPLICATE_CONDITIONAL);
70
+ }
71
+ if (v === null || typeof v === 'string' || typeof v === 'number') {
72
+ continue;
73
+ }
74
+ if (Array.isArray(v)) {
75
+ for (const vv of v) {
76
+ if (vv === null || typeof vv === 'string' || typeof vv === 'number') {
77
+ continue;
78
+ }
79
+ throw new Error(messages.ILLEGAL_PROP_VALUE);
80
+ }
81
+ continue;
82
+ }
83
+ if (v instanceof _.IncludedStyles) {
84
+ throw new Error(messages.ONLY_TOP_LEVEL_INLCUDES);
85
+ }
86
+ if ((0, _objectUtils.isPlainObject)(v)) {
87
+ validateConditionalStyles(v, [...conditions, key]);
88
+ continue;
89
+ }
90
+ throw new Error(messages.ILLEGAL_PROP_VALUE);
91
+ }
92
+ }
@@ -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,148 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._flattenRawStyleObject = _flattenRawStyleObject;
7
+ exports.flattenRawStyleObject = flattenRawStyleObject;
8
+ var _ = _interopRequireDefault(require("."));
9
+ var _PreRule = require("./PreRule");
10
+ var _2 = require("..");
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
+ function flattenRawStyleObject(style, options) {
22
+ return _flattenRawStyleObject(style, [], [], options);
23
+ }
24
+ function _flattenRawStyleObject(style, pseudos, atRules, options) {
25
+ const flattened = [];
26
+ for (const key in style) {
27
+ const value = style[key];
28
+
29
+ // Included Styles
30
+ if (typeof value === 'object' && value instanceof _2.IncludedStyles) {
31
+ flattened.push([key, new _PreRule.PreIncludedStylesRule(value)]);
32
+ continue;
33
+ }
34
+
35
+ // Default styles
36
+ if (value === null || typeof value === 'string' || typeof value === 'number') {
37
+ const pairs = (0, _.default)([key, value], options);
38
+ for (const [property, value] of pairs) {
39
+ if (value === null) {
40
+ flattened.push([property, new _PreRule.NullPreRule()]);
41
+ } else {
42
+ flattened.push([property, new _PreRule.PreRule(property, value, pseudos, atRules)]);
43
+ }
44
+ }
45
+ continue;
46
+ }
47
+
48
+ // Fallback Styles
49
+ if (Array.isArray(value)) {
50
+ const equivalentPairs = {};
51
+ for (const eachVal of value) {
52
+ const pairs = (0, _.default)([key, eachVal], options);
53
+ for (const [property, val] of pairs) {
54
+ if (Array.isArray(val)) {
55
+ if (equivalentPairs[property] == null) {
56
+ equivalentPairs[property] = [...val];
57
+ } else {
58
+ equivalentPairs[property].push(...val);
59
+ }
60
+ } else if (equivalentPairs[property] == null) {
61
+ equivalentPairs[property] = [val];
62
+ } else {
63
+ equivalentPairs[property].push(val);
64
+ }
65
+ }
66
+ }
67
+ // Deduplicate
68
+ Object.entries(equivalentPairs)
69
+ // Remove Nulls
70
+ .map(_ref => {
71
+ let [property, values] = _ref;
72
+ return [property, [...new Set(values.filter(Boolean))]];
73
+ })
74
+ // Deduplicate and default to null when no values are found
75
+ .map(_ref2 => {
76
+ let [property, values] = _ref2;
77
+ return [property, values.length === 0 ? null : values.length === 1 ? values[0] : values];
78
+ })
79
+ // Push to flattened
80
+ .forEach(_ref3 => {
81
+ let [property, value] = _ref3;
82
+ if (value === null) {
83
+ flattened.push([property, new _PreRule.NullPreRule()]);
84
+ } else {
85
+ flattened.push([property, new _PreRule.PreRule(property, value, pseudos, atRules)]);
86
+ }
87
+ });
88
+ continue;
89
+ }
90
+
91
+ // Object Values for propetiies. e.g. { color: { hover: 'red', default: 'blue' } }
92
+ if (typeof value === 'object' && !key.startsWith(':') && !key.startsWith('@')) {
93
+ const equivalentPairs = {};
94
+ for (const condition in value) {
95
+ const innerValue = value[condition];
96
+ const pseudosToPassDown = [...pseudos];
97
+ const atRulesToPassDown = [...atRules];
98
+ if (condition.startsWith(':')) {
99
+ pseudosToPassDown.push(condition);
100
+ } else if (condition.startsWith('@')) {
101
+ atRulesToPassDown.push(condition);
102
+ }
103
+ const pairs = _flattenRawStyleObject({
104
+ [key]: innerValue
105
+ }, pseudosToPassDown, atRulesToPassDown, options);
106
+ for (const [property, preRule] of pairs) {
107
+ if (preRule instanceof _PreRule.PreIncludedStylesRule) {
108
+ // NOT POSSIBLE, but needed for Flow
109
+ throw new Error('stylex.include can only be used at the top-level');
110
+ }
111
+ if (equivalentPairs[property] == null) {
112
+ equivalentPairs[property] = {
113
+ [condition]: preRule
114
+ };
115
+ } else {
116
+ equivalentPairs[property][condition] = preRule;
117
+ }
118
+ }
119
+ }
120
+ for (const [property, obj] of Object.entries(equivalentPairs)) {
121
+ const sortedKeys = Object.keys(obj); //.sort();
122
+ const rules = [];
123
+ for (const condition of sortedKeys) {
124
+ rules.push(obj[condition]);
125
+ }
126
+ // If there are many conditions with `null` values, we will collapse them into a single `null` value.
127
+ // `PreRuleSet.create` takes care of that for us.
128
+ flattened.push([property, _PreRule.PreRuleSet.create(rules)]);
129
+ }
130
+ }
131
+
132
+ // Object Values for pseudos and at-rules. e.g. { ':hover': { color: 'red' } }
133
+ if (typeof value === 'object' && (key.startsWith(':') || key.startsWith('@'))) {
134
+ const pseudosToPassDown = [...pseudos];
135
+ const atRulesToPassDown = [...atRules];
136
+ if (key.startsWith(':')) {
137
+ pseudosToPassDown.push(key);
138
+ } else if (key.startsWith('@')) {
139
+ atRulesToPassDown.push(key);
140
+ }
141
+ const pairs = _flattenRawStyleObject(value, pseudosToPassDown, atRulesToPassDown, options);
142
+ for (const [property, preRule] of pairs) {
143
+ flattened.push([key + '_' + property, preRule]);
144
+ }
145
+ }
146
+ }
147
+ return flattened;
148
+ }