@stylexjs/shared 0.2.0-beta.9 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. package/README.md +3 -3
  2. package/lib/common-types.d.ts +49 -0
  3. package/lib/common-types.js.flow +64 -0
  4. package/lib/convert-to-className.d.ts +16 -0
  5. package/lib/convert-to-className.js +17 -26
  6. package/lib/convert-to-className.js.flow +23 -0
  7. package/lib/generate-css-rule.d.ts +17 -0
  8. package/lib/generate-css-rule.js +6 -17
  9. package/lib/generate-css-rule.js.flow +17 -0
  10. package/lib/hash.d.ts +11 -0
  11. package/lib/hash.js +3 -27
  12. package/lib/hash.js.flow +10 -0
  13. package/lib/index.d.ts +42 -85
  14. package/lib/index.js +21 -29
  15. package/lib/index.js.flow +57 -3
  16. package/lib/messages.d.ts +41 -0
  17. package/lib/messages.js +33 -53
  18. package/lib/messages.js.flow +44 -0
  19. package/lib/physical-rtl/generate-ltr.d.ts +11 -0
  20. package/lib/physical-rtl/generate-ltr.js +18 -46
  21. package/lib/physical-rtl/generate-ltr.js.flow +12 -0
  22. package/lib/physical-rtl/generate-rtl.d.ts +13 -0
  23. package/lib/physical-rtl/generate-rtl.js +18 -50
  24. package/lib/physical-rtl/generate-rtl.js.flow +12 -0
  25. package/lib/preprocess-rules/PreRule.d.ts +52 -0
  26. package/lib/preprocess-rules/PreRule.js +87 -0
  27. package/lib/preprocess-rules/PreRule.js.flow +64 -0
  28. package/lib/preprocess-rules/application-order.d.ts +290 -0
  29. package/lib/preprocess-rules/application-order.js +60 -133
  30. package/lib/preprocess-rules/application-order.js.flow +241 -0
  31. package/lib/preprocess-rules/basic-validation.d.ts +13 -0
  32. package/lib/preprocess-rules/basic-validation.js +83 -0
  33. package/lib/preprocess-rules/basic-validation.js.flow +13 -0
  34. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +25 -0
  35. package/lib/preprocess-rules/flatten-raw-style-obj.js +120 -0
  36. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +27 -0
  37. package/lib/preprocess-rules/index.d.ts +18 -0
  38. package/lib/preprocess-rules/index.js +0 -9
  39. package/lib/preprocess-rules/index.js.flow +19 -0
  40. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +200 -0
  41. package/lib/preprocess-rules/legacy-expand-shorthands.js +90 -123
  42. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +179 -0
  43. package/lib/preprocess-rules/property-specificity.d.ts +89 -0
  44. package/lib/preprocess-rules/property-specificity.js +46 -74
  45. package/lib/preprocess-rules/property-specificity.js.flow +98 -0
  46. package/lib/properties/CSS Animations.json +445 -0
  47. package/lib/properties/CSS Backgrounds and Borders.json +1085 -0
  48. package/lib/properties/CSS Basic User Interface.json +365 -0
  49. package/lib/properties/CSS Box Alignment.json +245 -0
  50. package/lib/properties/CSS Box Model.json +501 -0
  51. package/lib/properties/CSS Color.json +100 -0
  52. package/lib/properties/CSS Columns.json +185 -0
  53. package/lib/properties/CSS Containment.json +203 -0
  54. package/lib/properties/CSS Counter Styles.json +56 -0
  55. package/lib/properties/CSS Display.json +20 -0
  56. package/lib/properties/CSS Flexible Box Layout.json +167 -0
  57. package/lib/properties/CSS Fonts.json +684 -0
  58. package/lib/properties/CSS Fragmentation.json +110 -0
  59. package/lib/properties/CSS Generated Content.json +38 -0
  60. package/lib/properties/CSS Grid Layout.json +500 -0
  61. package/lib/properties/CSS Images.json +91 -0
  62. package/lib/properties/CSS Inline.json +38 -0
  63. package/lib/properties/CSS Lists and Counters.json +86 -0
  64. package/lib/properties/CSS Logical Properties.json +1086 -0
  65. package/lib/properties/CSS Masking.json +399 -0
  66. package/lib/properties/CSS Miscellaneous.json +38 -0
  67. package/lib/properties/CSS Motion Path.json +132 -0
  68. package/lib/properties/CSS Overflow.json +216 -0
  69. package/lib/properties/CSS Pages.json +83 -0
  70. package/lib/properties/CSS Positioning.json +166 -0
  71. package/lib/properties/CSS Ruby.json +55 -0
  72. package/lib/properties/CSS Scroll Anchoring.json +19 -0
  73. package/lib/properties/CSS Scroll Snap.json +604 -0
  74. package/lib/properties/CSS Scrollbars.json +38 -0
  75. package/lib/properties/CSS Shapes.json +56 -0
  76. package/lib/properties/CSS Speech.json +20 -0
  77. package/lib/properties/CSS Table.json +115 -0
  78. package/lib/properties/CSS Text Decoration.json +312 -0
  79. package/lib/properties/CSS Text.json +415 -0
  80. package/lib/properties/CSS Transforms.json +188 -0
  81. package/lib/properties/CSS Transitions.json +122 -0
  82. package/lib/properties/CSS Variables.json +20 -0
  83. package/lib/properties/CSS View Transitions.json +20 -0
  84. package/lib/properties/CSS Will Change.json +20 -0
  85. package/lib/properties/CSS Writing Modes.json +92 -0
  86. package/lib/properties/Compositing and Blending.json +62 -0
  87. package/lib/properties/Filter Effects.json +38 -0
  88. package/lib/properties/MathML.json +56 -0
  89. package/lib/properties/Microsoft Extensions.json +885 -0
  90. package/lib/properties/Mozilla Extensions.json +607 -0
  91. package/lib/properties/Pointer Events.json +20 -0
  92. package/lib/properties/WebKit Extensions.json +707 -0
  93. package/lib/properties.json +10122 -0
  94. package/lib/stylex-create-theme.d.ts +26 -0
  95. package/lib/stylex-create-theme.js +67 -0
  96. package/lib/stylex-create-theme.js.flow +19 -0
  97. package/lib/stylex-create.d.ts +23 -0
  98. package/lib/stylex-create.js +30 -146
  99. package/lib/stylex-create.js.flow +30 -0
  100. package/lib/stylex-define-vars.d.ts +29 -0
  101. package/lib/stylex-define-vars.js +73 -0
  102. package/lib/stylex-define-vars.js.flow +26 -0
  103. package/lib/stylex-first-that-works.d.ts +13 -0
  104. package/lib/stylex-first-that-works.js +0 -10
  105. package/lib/stylex-first-that-works.js.flow +12 -0
  106. package/lib/stylex-include.d.ts +18 -0
  107. package/lib/stylex-include.js +2 -12
  108. package/lib/stylex-include.js.flow +20 -0
  109. package/lib/stylex-keyframes.d.ts +17 -0
  110. package/lib/stylex-keyframes.js +6 -26
  111. package/lib/stylex-keyframes.js.flow +20 -0
  112. package/lib/transform-value.d.ts +22 -0
  113. package/lib/transform-value.js +9 -23
  114. package/lib/transform-value.js.flow +25 -0
  115. package/lib/types/index.d.ts +205 -0
  116. package/lib/types/index.js +191 -0
  117. package/lib/types/index.js.flow +241 -0
  118. package/lib/utils/Rule.d.ts +58 -0
  119. package/lib/utils/Rule.js +0 -21
  120. package/lib/utils/Rule.js.flow +64 -0
  121. package/lib/utils/dashify.d.ts +11 -0
  122. package/lib/utils/dashify.js +0 -8
  123. package/lib/utils/dashify.js.flow +10 -0
  124. package/lib/utils/default-options.d.ts +11 -0
  125. package/lib/utils/default-options.js +13 -0
  126. package/lib/utils/default-options.js.flow +25 -0
  127. package/lib/utils/file-based-identifier.d.ts +15 -0
  128. package/lib/utils/file-based-identifier.js +14 -0
  129. package/lib/utils/file-based-identifier.js.flow +14 -0
  130. package/lib/utils/genCSSRule.d.ts +15 -0
  131. package/lib/utils/genCSSRule.js +9 -18
  132. package/lib/utils/genCSSRule.js.flow +15 -0
  133. package/lib/utils/normalize-value.d.ts +16 -0
  134. package/lib/utils/normalize-value.js +8 -15
  135. package/lib/utils/normalize-value.js.flow +16 -0
  136. package/lib/utils/normalizers/convert-camel-case-transition-props.d.ts +14 -0
  137. package/lib/utils/normalizers/convert-camel-case-transition-props.js +23 -0
  138. package/lib/utils/normalizers/convert-camel-case-transition-props.js.flow +13 -0
  139. package/lib/utils/normalizers/convert-camel-case-values.d.ts +14 -0
  140. package/lib/utils/normalizers/convert-camel-case-values.js +23 -0
  141. package/lib/utils/normalizers/convert-camel-case-values.js.flow +13 -0
  142. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
  143. package/lib/utils/normalizers/detect-unclosed-fns.js +2 -14
  144. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
  145. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
  146. package/lib/utils/normalizers/font-size-px-to-rem.js +9 -19
  147. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
  148. package/lib/utils/normalizers/leading-zero.d.ts +17 -0
  149. package/lib/utils/normalizers/leading-zero.js +0 -12
  150. package/lib/utils/normalizers/leading-zero.js.flow +16 -0
  151. package/lib/utils/normalizers/quotes.d.ts +18 -0
  152. package/lib/utils/normalizers/quotes.js +0 -13
  153. package/lib/utils/normalizers/quotes.js.flow +17 -0
  154. package/lib/utils/normalizers/timings.d.ts +18 -0
  155. package/lib/utils/normalizers/timings.js +0 -14
  156. package/lib/utils/normalizers/timings.js.flow +17 -0
  157. package/lib/utils/normalizers/whitespace.d.ts +19 -0
  158. package/lib/utils/normalizers/whitespace.js +0 -15
  159. package/lib/utils/normalizers/whitespace.js.flow +18 -0
  160. package/lib/utils/normalizers/zero-dimensions.d.ts +19 -0
  161. package/lib/utils/normalizers/zero-dimensions.js +0 -15
  162. package/lib/utils/normalizers/zero-dimensions.js.flow +18 -0
  163. package/lib/utils/object-utils.d.ts +66 -0
  164. package/lib/utils/object-utils.js +21 -13
  165. package/lib/utils/object-utils.js.flow +77 -0
  166. package/lib/utils/property-priorities.d.ts +11 -0
  167. package/lib/utils/property-priorities.js +516 -101
  168. package/lib/utils/property-priorities.js.flow +10 -0
  169. package/lib/utils/split-css-value.d.ts +14 -0
  170. package/lib/utils/split-css-value.js +0 -14
  171. package/lib/utils/split-css-value.js.flow +15 -0
  172. package/lib/validate.d.ts +12 -0
  173. package/lib/validate.js +1 -10
  174. package/lib/validate.js.flow +12 -0
  175. package/package.json +4 -5
  176. package/lib/expand-shorthands.d.ts +0 -5
  177. package/lib/expand-shorthands.js +0 -330
  178. package/lib/namespace-transforms/__tests__/preflatten.test.js +0 -120
  179. package/lib/namespace-transforms/preflatten.js +0 -89
  180. package/lib/preprocess-rules/expand-shorthands.js +0 -156
  181. package/lib/preprocess-rules/null-out-longhand.js +0 -310
  182. package/lib/preprocess-rules/react-native-web.js +0 -142
  183. package/lib/stylex-defaultValue.js +0 -397
@@ -6,16 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = splitValue;
7
7
  var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
8
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
-
19
9
  function printNode(node) {
20
10
  switch (node.type) {
21
11
  case 'word':
@@ -27,14 +17,10 @@ function printNode(node) {
27
17
  return node.value;
28
18
  }
29
19
  }
30
-
31
- // Using split(' ') Isn't enough bcause of values like calc.
32
20
  function splitValue(str) {
33
21
  if (str == null || typeof str === 'number') {
34
22
  return [str];
35
23
  }
36
-
37
- // This will never happen, but keeping here for Flow.
38
24
  if (Array.isArray(str)) {
39
25
  return str;
40
26
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type { TStyleValue } from '../common-types';
11
+
12
+ // Using split(' ') Isn't enough because of values like calc.
13
+ declare export default function splitValue(
14
+ str: TStyleValue,
15
+ ): $ReadOnlyArray<number | string | null>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
10
+ import type { TRawValue } from './common-types';
11
+ declare function validateEntry($$PARAM_0$$: [string, TRawValue]): void;
12
+ export default validateEntry;
package/lib/validate.js CHANGED
@@ -4,15 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = validateEntry;
7
- /**
8
- * Copyright (c) Meta Platforms, Inc. and affiliates.
9
- *
10
- * This source code is licensed under the MIT license found in the
11
- * LICENSE file in the root directory of this source tree.
12
- *
13
- *
14
- */
15
-
16
7
  function validateEntry(_ref) {
17
8
  let [key, value] = _ref;
18
9
  if (Array.isArray(value)) {
@@ -22,7 +13,7 @@ function validateEntry(_ref) {
22
13
  }
23
14
  }
24
15
  function validateSimplyEntry(_ref2) {
25
- let [key, value] = _ref2;
16
+ let [key, _value] = _ref2;
26
17
  if (BANNED_KEYS.has(key)) {
27
18
  throw new Error('Banned key: ' + key);
28
19
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type { TRawValue } from './common-types';
11
+
12
+ declare export default function validateEntry([string, TRawValue]): void;
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@stylexjs/shared",
3
- "version": "0.2.0-beta.9",
4
- "description": "Shared Code for Stylex compile and runtime.",
3
+ "version": "0.4.0",
5
4
  "main": "lib/index.js",
6
- "repository": "https://www.github.com/facebookexternal/stylex",
7
- "author": "Naman Goel <nmn@fb.com>",
5
+ "repository": "https://www.github.com/facebook/stylex",
8
6
  "license": "MIT",
9
7
  "scripts": {
8
+ "prebuild": "gen-types -i src/ -o lib/",
10
9
  "build": "babel src/ --out-dir lib/ --copy-files",
11
10
  "test": "jest"
12
11
  },
@@ -14,7 +13,7 @@
14
13
  "postcss-value-parser": "^4.1.0"
15
14
  },
16
15
  "devDependencies": {
17
- "typescript": "^4.7.4"
16
+ "@stylexjs/scripts": "0.4.0"
18
17
  },
19
18
  "jest": {
20
19
  "snapshotFormat": {
@@ -1,5 +0,0 @@
1
- export const BANNED_PROPERTIES: { [key: string]: string };
2
- export const expandedKeys: $ReadOnlyArray<string>;
3
- export default function flatMapExpandedShorthands<T>(
4
- objEntry: [string, T]
5
- ): Array<[string, T]>;
@@ -1,330 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = flatMapExpandedShorthands;
7
- exports.expandedKeys = void 0;
8
- var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- /**
11
- * Copyright (c) Meta Platforms, Inc. and affiliates.
12
- *
13
- * This source code is licensed under the MIT license found in the
14
- * LICENSE file in the root directory of this source tree.
15
- *
16
- *
17
- */
18
-
19
- function printNode(node) {
20
- switch (node.type) {
21
- case 'word':
22
- case 'string':
23
- return `${node.value}`;
24
- case 'function':
25
- return `${node.value}(${node.nodes.map(printNode).join('')})`;
26
- default:
27
- return node.value;
28
- }
29
- }
30
-
31
- // Using split(' ') Isn't enough bcause of values like calc.
32
- function splitValue(str) {
33
- if (Array.isArray(str)) {
34
- return str;
35
- }
36
- const parsed = (0, _postcssValueParser.default)(str.trim());
37
- const nodes = parsed.nodes.filter(node => node.type !== 'space' && node.type !== 'div').map(printNode);
38
- if (nodes.length > 1 && nodes[nodes.length - 1].toLowerCase() === '!important') {
39
- return nodes.slice(0, nodes.length - 1).map(node => node + ' !important');
40
- }
41
- return nodes;
42
- }
43
-
44
- /**
45
- * Shorthand properties:
46
- * - [x] all - Should be banned
47
- * - [x] animation
48
- * - [x] background
49
- * - [x] border
50
- * - [x] border-block-end
51
- * - [x] border-block-start
52
- * - [x] border-bottom
53
- * - [x] border-color
54
- * - [x] border-image
55
- * - [x] border-inline-end
56
- * - [x] border-inline-start
57
- * - [x] border-left
58
- * - [x] border-radius
59
- * - [x] border-right
60
- * - [x] border-style
61
- * - [x] border-top
62
- * - [x] border-width
63
- * - [x] column-rule
64
- * - [x] columns
65
- * - [x] container
66
- * - [x] flex
67
- * - [x] flex-flow
68
- * - [x] font
69
- * - [x] gap
70
- * - [x] grid
71
- * - [x] grid-area
72
- * - [x] grid-column
73
- * - [x] grid-row
74
- * - [x] grid-template
75
- * - [x] inset
76
- * - [x] inset-block
77
- * - [x] inset-inline
78
- * - [x] list-style
79
- * - [x] margin
80
- * - [x] mask
81
- * - [x] offset
82
- * - [x] outline
83
- * - [x] overflow
84
- * - [x] padding
85
- * - [x] place-content
86
- * - [x] place-items
87
- * - [x] place-self
88
- * - [x] scroll-margin
89
- * - [x] scroll-padding
90
- * - [x] text-decoration
91
- * - [x] text-emphasis
92
- * - [x] transition
93
- */
94
-
95
- const shorthands = {
96
- all: _ => {
97
- throw new Error('all is not supported');
98
- },
99
- animation: value => [['animation', value], ['animationName', null], ['animationDuration', null], ['animationTimingFunction', null], ['animationDelay', null], ['animationIterationCount', null], ['animationDirection', null], ['animationFillMode', null], ['animationPlayState', null]],
100
- background: value => [['background', value], ['backgroundAttachment', null], ['backgroundClip', null], ['backgroundColor', null], ['backgroundImage', null], ['backgroundOrigin', null], ['backgroundPosition', null], ['backgroundRepeat', null], ['backgroundSize', null]],
101
- // These will be removed later, matching the properties with React Native.
102
- // For now, we're compiling them to the React Native properties.
103
- // @Deprecated
104
- border: rawValue => {
105
- if (typeof rawValue === 'number') {
106
- return shorthands.borderWidth(rawValue);
107
- }
108
- const [width, style, color] = splitValue(rawValue);
109
- return [...shorthands.borderWidth(width), ...shorthands.borderStyle(style), ...shorthands.borderColor(color)];
110
- },
111
- // @Deprecated
112
- borderInline: rawValue => {
113
- if (typeof rawValue === 'number') {
114
- return [['borderInlineWidth', rawValue], ['borderInlineStartWidth', null], ['borderInlineEndWidth', null]];
115
- }
116
- const [width, style, color] = splitValue(rawValue);
117
- return [...shorthands.borderInlineWidth(width), ...shorthands.borderInlineStyle(style), ...shorthands.borderInlineColor(color)];
118
- },
119
- // @Deprecated
120
- borderBlock: rawValue => {
121
- if (typeof rawValue === 'number') {
122
- return [['borderBlockWidth', rawValue], ['borderTopWidth', null], ['borderBottomWidth', null]];
123
- }
124
- const [width, style, color] = splitValue(rawValue);
125
- return [...shorthands.borderBlockWidth(width), ...shorthands.borderBlockStyle(style), ...shorthands.borderBlockColor(color)];
126
- },
127
- // @Deprecated
128
- borderTop: rawValue => {
129
- if (typeof rawValue === 'number') {
130
- return [['borderTopWidth', rawValue]];
131
- }
132
- const [width, style, color] = splitValue(rawValue);
133
- return [['borderTopWidth', width], ['borderTopStyle', style], ['borderTopColor', color]];
134
- },
135
- // @Deprecated
136
- borderInlineEnd: rawValue => {
137
- if (typeof rawValue === 'number') {
138
- return [['borderInlineEndWidth', rawValue]];
139
- }
140
- const [width, style, color] = splitValue(rawValue);
141
- return [['borderInlineEndWidth', width], ['borderInlineEndStyle', style], ['borderInlineEndColor', color]];
142
- },
143
- // @Deprecated
144
- borderRight: rawValue => {
145
- 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(' '));
146
- },
147
- // @Deprecated
148
- borderBottom: rawValue => {
149
- if (typeof rawValue === 'number') {
150
- return [['borderBottomWidth', rawValue]];
151
- }
152
- const [width, style, color] = splitValue(rawValue);
153
- return [['borderBottomWidth', width], ['borderBottomStyle', style], ['borderBottomColor', color]];
154
- },
155
- // @Deprecated
156
- borderInlineStart: rawValue => {
157
- if (typeof rawValue === 'number') {
158
- return [['borderInlineStartWidth', rawValue]];
159
- }
160
- const [width, style, color] = splitValue(rawValue);
161
- return [['borderInlineStartWidth', width], ['borderInlineStartStyle', style], ['borderInlineStartColor', color]];
162
- },
163
- // @Deprecated
164
- borderLeft: rawValue => {
165
- 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(' '));
166
- },
167
- borderInlineWidth: rawValue => [['borderInlineWidth', rawValue], ['borderInlineStartWidth', null], ['borderLeftWidth', null], ['borderInlineEndWidth', null], ['borderRightWidth', null]],
168
- borderInlineStyle: rawValue => [['borderInlineStyle', rawValue], ['borderInlineStartStyle', null], ['borderLeftStyle', null], ['borderInlineEndStyle', null], ['borderRightStyle', null]],
169
- borderInlineColor: rawValue => [['borderInlineColor', rawValue], ['borderInlineStartColor', null], ['borderLeftColor', null], ['borderInlineEndColor', null], ['borderRightColor', null]],
170
- borderBlockWidth: rawValue => [['borderBlockWidth', rawValue], ['borderTopWidth', null], ['borderBottomWidth', null]],
171
- borderBlockStyle: rawValue => [['borderBlockStyle', rawValue], ['borderTopStyle', null], ['borderBottomStyle', null]],
172
- borderBlockColor: rawValue => [['borderBlockColor', rawValue], ['borderTopColor', null], ['borderBottomColor', null]],
173
- borderColor: value => [['borderColor', value], ['borderTopColor', null], ['borderInlineEndColor', null], ['borderRightColor', null], ['borderBottomColor', null], ['borderInlineStartColor', null], ['borderLeftColor', null]],
174
- borderStyle: value => [['borderStyle', value], ['borderTopStyle', null], ['borderInlineEndStyle', null], ['borderRightStyle', null], ['borderBottomStyle', null], ['borderInlineStartStyle', null], ['borderLeftStyle', null]],
175
- borderWidth: value => [['borderWidth', value], ['borderTopWidth', null], ['borderInlineEndWidth', null], ['borderRightWidth', null], ['borderBottomWidth', null], ['borderInlineStartWidth', null], ['borderLeftWidth', null]],
176
- borderRadius: value => {
177
- const values = typeof value === 'number' ? [value] : splitValue(value);
178
- if (values.length === 1) {
179
- return [['borderRadius', value],
180
- // // logical constituents
181
- ['borderStartStartRadius', null], ['borderStartEndRadius', null], ['borderEndStartRadius', null], ['borderEndEndRadius', null],
182
- // physical constituents
183
- ['borderTopLeftRadius', null], ['borderTopRightRadius', null], ['borderBottomLeftRadius', null], ['borderBottomRightRadius', null]];
184
- }
185
-
186
- // @Deprecated
187
- const [startStart, startEnd = startStart, endEnd = startStart, endStart = startEnd] = values;
188
- return [
189
- // split into logical consituents
190
- ['borderStartStartRadius', startStart], ['borderStartEndRadius', startEnd], ['borderEndEndRadius', endEnd], ['borderEndStartRadius', endStart],
191
- // unset physical consituents
192
- ['borderTopLeftRadius', null], ['borderTopRightRadius', null], ['borderBottomLeftRadius', null], ['borderBottomRightRadius', null]];
193
- },
194
- columnRule: value => [['columnRule', value], ['columnRuleWidth', null], ['columnRuleStyle', null], ['columnRuleColor', null]],
195
- columns: value => [['columns', value], ['columnCount', null], ['columnWidth', null]],
196
- container: value => [['container', value], ['containerName', null], ['containerType', null]],
197
- flex: value => [['flex', value], ['flexGrow', null], ['flexShrink', null], ['flexBasis', null]],
198
- flexFlow: value => [['flexFlow', value], ['flexDirection', null], ['flexWrap', null]],
199
- // @Deprecated ?
200
- font: value => [['font', value], ['fontFamily', null], ['fontSize', null], ['fontStretch', null], ['fontStyle', null], ['fontVariant', null], ['fontWeight', null], ['lineHeight', null]],
201
- gap: value => [['gap', value], ['rowGap', null], ['columnGap', null]],
202
- grid: value => [['grid', value], ['gridTemplate', null], ['gridTemplateAreas', null], ['gridTemplateColumns', null], ['gridTemplateRows', null], ['gridAutoRows', null], ['gridAutoColumns', null], ['gridAutoFlow', null]
203
-
204
- // This is for grid items only
205
- // Not a constituent of `grid`
206
- // ['gridRow', null],
207
- // ['gridRowStart', null],
208
- // ['gridRowEnd', null],
209
- // ['gridColumn', null],
210
- // ['gridColumnStart', null],
211
- // ['gridColumnEnd', null],
212
- // ['gridArea', null],
213
- ],
214
-
215
- gridArea: value => [['gridArea', value], ['gridRow', null], ['gridRowStart', null], ['gridRowEnd', null], ['gridColumn', null], ['gridColumnStart', null], ['gridColumnEnd', null]],
216
- gridRow: value => [['gridRow', value], ['gridRowStart', null], ['gridRowEnd', null]],
217
- gridColumn: value => [['gridColumn', value], ['gridColumnStart', null], ['gridColumnEnd', null]],
218
- gridTemplate: value => [['gridTemplate', value], ['gridTemplateAreas', null], ['gridTemplateColumns', null], ['gridTemplateRows', null]],
219
- inset: value => [['inset', value], ['insetInline', null], ['insetBlock', null], ['insetInlineStart', null], ['insetInlineEnd', null], ['top', null], ['right', null], ['bottom', null], ['left', null]],
220
- insetInline: value => [['insetInline', value], ['insetInlineStart', null], ['insetInlineEnd', null], ['left', null], ['right', null]],
221
- insetBlock: value => [['insetBlock', value], ['top', null], ['bottom', null]],
222
- listStyle: value => [['listStyle', value], ['listStyleImage', null], ['listStylePosition', null], ['listStyleType', null]],
223
- margin: value => {
224
- const values = typeof value === 'number' ? [value] : splitValue(value);
225
- if (values.length === 1) {
226
- return [['margin', values[0]], ['marginInlineStart', null], ['marginLeft', null], ['marginInlineEnd', null], ['marginRight', null], ['marginTop', null], ['marginBottom', null]];
227
- }
228
- // @Deprecated
229
- const [top, right = top, bottom = top, left = right] = values;
230
- return [['marginTop', top], ['marginInlineEnd', right], ['marginBottom', bottom], ['marginInlineStart', left], ['marginLeft', null], ['marginRight', null]];
231
- },
232
- marginInline: value => [['marginInline', value], ['marginInlineStart', null], ['marginLeft', null], ['marginInlineEnd', null], ['marginRight', null]],
233
- marginBlock: value => [['marginBlock', value], ['marginTop', null], ['marginBottom', null]],
234
- mask: value => [['mask', value], ['maskClip', null], ['maskComposite', null], ['maskImage', null], ['maskMode', null], ['maskOrigin', null], ['maskPosition', null], ['maskRepeat', null], ['maskSize', null]],
235
- offset: value => [['offset', value], ['offsetAnchor', null], ['offsetDistance', null], ['offsetPath', null], ['offsetPosition', null], ['offsetRotate', null]],
236
- outline: value => [['outline', value], ['outlineColor', null], ['outlineStyle', null], ['outlineWidth', null]],
237
- overflow: value => [['overflow', value], ['overflowX', null], ['overflowY', null]],
238
- padding: rawValue => {
239
- const values = typeof rawValue === 'number' ? [rawValue] : splitValue(rawValue);
240
- if (values.length === 1) {
241
- return [['padding', values[0]], ['paddingStart', null], ['paddingLeft', null], ['paddingEnd', null], ['paddingRight', null], ['paddingTop', null], ['paddingBottom', null]];
242
- }
243
- // @Deprecated
244
- const [top, right = top, bottom = top, left = right] = values;
245
- return [['paddingTop', top], ['paddingEnd', right], ['paddingBottom', bottom], ['paddingStart', left]];
246
- },
247
- paddingInline: rawValue => [['paddingInline', rawValue], ['paddingStart', null], ['paddingLeft', null], ['paddingEnd', null], ['paddingRight', null]],
248
- paddingBlock: rawValue => [['paddingBlock', rawValue], ['paddingTop', null], ['paddingBottom', null]],
249
- placeContent: value => [['placeContent', value], ['alignContent', null], ['justifyContent', null]],
250
- placeItems: value => [['placeItems', value], ['alignItems', null], ['justifyItems', null]],
251
- placeSelf: value => [['placeSelf', value], ['alignSelf', null], ['justifySelf', null]],
252
- scrollMargin: value => [['scrollMargin', value], ['scrollMarginBottom', null], ['scrollMarginLeft', null], ['scrollMarginStart', null], ['scrollMarginRight', null], ['scrollMarginEnd', null], ['scrollMarginTop', null]],
253
- scrollPadding: value => [['scrollPadding', value], ['scrollPaddingBottom', null], ['scrollPaddingLeft', null], ['scrollPaddingStart', null], ['scrollPaddingRight', null], ['scrollPaddingEnd', null], ['scrollPaddingTop', null]],
254
- scrollTimeline: value => [['scrollTimeline', value], ['scrollTimelineName', null], ['scrollTimelineAxis', null]],
255
- textDecoration: value => [['textDecoration', value], ['textDecorationColor', null], ['textDecorationLine', null], ['textDecorationStyle', null], ['textDecorationThickness', null]],
256
- textEmphasis: value => [['textEmphasis', value], ['textEmphasisColor', null], ['textEmphasisStyle', null]],
257
- transition: value => [['transition', value], ['transitionDelay', null], ['transitionDuration', null], ['transitionProperty', null], ['transitionTimingFunction', null]]
258
- };
259
- const aliases = {
260
- // @Deprecated
261
- borderHorizontal: shorthands.borderInline,
262
- // @Deprecated
263
- borderVertical: shorthands.borderBlock,
264
- // @Deprecated
265
- borderBlockStart: shorthands.borderTop,
266
- // @Deprecated
267
- borderEnd: shorthands.borderInlineEnd,
268
- // @Deprecated
269
- borderBlockEnd: shorthands.borderBottom,
270
- // @Deprecated
271
- borderStart: shorthands.borderInlineStart,
272
- borderHorizontalWidth: shorthands.borderInlineWidth,
273
- borderHorizontalStyle: shorthands.borderInlineStyle,
274
- borderHorizontalColor: shorthands.borderInlineColor,
275
- borderVerticalWidth: shorthands.borderBlockWidth,
276
- borderVerticalStyle: shorthands.borderBlockStyle,
277
- borderVerticalColor: shorthands.borderBlockColor,
278
- borderBlockStartColor: value => [['borderTopColor', value]],
279
- borderBlockEndColor: value => [['borderBottomColor', value]],
280
- borderStartColor: value => [['borderInlineStartColor', value]],
281
- borderEndColor: value => [['borderInlineEndColor', value]],
282
- borderBlockStartStyle: value => [['borderTopStyle', value]],
283
- borderBlockEndStyle: value => [['borderBottomStyle', value]],
284
- borderStartStyle: value => [['borderInlineStartStyle', value]],
285
- borderEndStyle: value => [['borderInlineEndStyle', value]],
286
- borderBlockStartWidth: value => [['borderTopWidth', value]],
287
- borderBlockEndWidth: value => [['borderBottomWidth', value]],
288
- borderStartWidth: value => [['borderInlineStartWidth', value]],
289
- borderEndWidth: value => [['borderInlineEndWidth', value]],
290
- borderTopStartRadius: value => [['borderStartStartRadius', value]],
291
- borderTopEndRadius: value => [['borderStartEndRadius', value]],
292
- borderBottomStartRadius: value => [['borderEndStartRadius', value]],
293
- borderBottomEndRadius: value => [['borderEndEndRadius', value]],
294
- marginBlockStart: value => [['marginTop', value]],
295
- marginBlockEnd: value => [['marginBottom', value]],
296
- marginStart: value => [['marginInlineStart', value]],
297
- marginEnd: value => [['marginInlineEnd', value]],
298
- marginHorizontal: shorthands.marginInline,
299
- marginVertical: shorthands.marginBlock,
300
- paddingBlockStart: rawValue => [['paddingTop', rawValue]],
301
- paddingBlockEnd: rawValue => [['paddingBottom', rawValue]],
302
- paddingStart: rawValue => [['paddingInlinStart', rawValue]],
303
- paddingEnd: rawValue => [['paddingInlineEnd', rawValue]],
304
- paddingHorizontal: shorthands.paddingInline,
305
- paddingVertical: shorthands.paddingBlock,
306
- insetBlockStart: value => [['top', value]],
307
- insetBlockEnd: value => [['bottom', value]],
308
- start: value => [['insetInlineStart', value]],
309
- end: value => [['insetInlineEnd', value]]
310
- };
311
- const expansions = {
312
- ...shorthands,
313
- ...aliases
314
- };
315
-
316
- // TODO: It should be possible to remove this as we should no longer have
317
- // to disallow shorthand properties with object values.
318
- const expandedKeys = Object.keys(expansions);
319
- exports.expandedKeys = expandedKeys;
320
- function flatMapExpandedShorthands(objEntry) {
321
- const [key, value] = objEntry;
322
- const expansion = expansions[key];
323
- if (expansion) {
324
- if (Array.isArray(value)) {
325
- throw new Error('Cannot use fallbacks for shorthands. Use the expansion instead.');
326
- }
327
- return expansion(value);
328
- }
329
- return [objEntry];
330
- }
@@ -1,120 +0,0 @@
1
- "use strict";
2
-
3
- var _preflatten = _interopRequireDefault(require("../preflatten"));
4
- var _Rule = require("../../utils/Rule");
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
- /**
7
- * Copyright (c) Meta Platforms, Inc. and affiliates.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE file in the root directory of this source tree.
11
- *
12
- *
13
- *
14
- */
15
-
16
- describe('preflatten', () => {
17
- test('flattens a simple style object', () => {
18
- const input = {
19
- color: 'red',
20
- backgroundColor: 'blue'
21
- };
22
- const output = {
23
- color: new _Rule.RawRule('color', 'red', [], []),
24
- backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], [])
25
- };
26
- expect((0, _preflatten.default)(input)).toEqual(output);
27
- });
28
- test('flattens styles with fallback styles', () => {
29
- const input = {
30
- color: ['red', 'blue'],
31
- backgroundColor: 'blue'
32
- };
33
- const output = {
34
- color: new _Rule.RawRuleList([new _Rule.RawRule('color', 'red', [], []), new _Rule.RawRule('color', 'blue', [], [])]),
35
- backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], [])
36
- };
37
- expect((0, _preflatten.default)(input)).toEqual(output);
38
- });
39
- test('flattens a simple style object with a nested pseudo styles', () => {
40
- const input = {
41
- color: 'red',
42
- backgroundColor: 'blue',
43
- ':hover': {
44
- color: 'green'
45
- }
46
- };
47
- const output = {
48
- color: new _Rule.RawRule('color', 'red', [], []),
49
- backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], []),
50
- ':hover_color': new _Rule.RawRule('color', 'green', [':hover'], [])
51
- };
52
- expect((0, _preflatten.default)(input)).toEqual(output);
53
- });
54
- test('flattens a simple style object with a nested at-rule styles', () => {
55
- const input = {
56
- color: 'red',
57
- backgroundColor: 'blue',
58
- '@media (min-width: 600px)': {
59
- color: 'green'
60
- }
61
- };
62
- const output = {
63
- color: new _Rule.RawRule('color', 'red', [], []),
64
- backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], []),
65
- '@media (min-width: 600px)_color': new _Rule.RawRule('color', 'green', [], ['@media (min-width: 600px)'])
66
- };
67
- expect((0, _preflatten.default)(input)).toEqual(output);
68
- });
69
- test('flattens style object with nested pseudo in property', () => {
70
- const input = {
71
- color: {
72
- default: 'red',
73
- ':hover': 'green',
74
- ':active': 'blue'
75
- },
76
- backgroundColor: 'blue'
77
- };
78
- const output = {
79
- color: new _Rule.RawRuleList([new _Rule.RawRule('color', 'red', [], []), new _Rule.RawRule('color', 'green', [':hover'], []), new _Rule.RawRule('color', 'blue', [':active'], [])]),
80
- backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], [])
81
- };
82
- expect((0, _preflatten.default)(input)).toEqual(output);
83
- });
84
- test('flattens style object with nested media queries', () => {
85
- const input = {
86
- color: {
87
- default: 'red',
88
- '@media (max-width: 600px)': 'green',
89
- '@media (min-width: 600px and max-width: 900px)': 'blue'
90
- },
91
- backgroundColor: 'blue'
92
- };
93
- const output = {
94
- color: new _Rule.RawRuleList([new _Rule.RawRule('color', 'red', [], []), new _Rule.RawRule('color', 'green', [], ['@media (max-width: 600px)']), new _Rule.RawRule('color', 'blue', [], ['@media (min-width: 600px and max-width: 900px)'])]),
95
- backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], [])
96
- };
97
- expect((0, _preflatten.default)(input)).toEqual(output);
98
- });
99
- test('flattens style object with nested media queries and pseudo', () => {
100
- const input = {
101
- color: {
102
- default: 'red',
103
- '@media (max-width: 600px)': {
104
- default: 'green',
105
- ':hover': 'blue'
106
- },
107
- '@media (min-width: 600px and max-width: 900px)': {
108
- default: 'blue',
109
- ':hover': 'green'
110
- }
111
- },
112
- backgroundColor: 'blue'
113
- };
114
- const output = {
115
- color: new _Rule.RawRuleList([new _Rule.RawRule('color', 'red', [], []), new _Rule.RawRule('color', 'green', [], ['@media (max-width: 600px)']), new _Rule.RawRule('color', 'blue', [':hover'], ['@media (max-width: 600px)']), new _Rule.RawRule('color', 'blue', [], ['@media (min-width: 600px and max-width: 900px)']), new _Rule.RawRule('color', 'green', [':hover'], ['@media (min-width: 600px and max-width: 900px)'])]),
116
- backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], [])
117
- };
118
- expect((0, _preflatten.default)(input)).toEqual(output);
119
- });
120
- });