@stylexjs/shared 0.2.0-beta.10 → 0.2.0-beta.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. package/lib/common-types.d.ts +49 -0
  2. package/lib/common-types.js.flow +64 -0
  3. package/lib/convert-to-className.d.ts +16 -0
  4. package/lib/convert-to-className.js.flow +23 -0
  5. package/lib/generate-css-rule.d.ts +17 -0
  6. package/lib/generate-css-rule.js.flow +17 -0
  7. package/lib/hash.d.ts +11 -0
  8. package/lib/hash.js.flow +12 -0
  9. package/lib/index.d.ts +32 -95
  10. package/lib/index.js.flow +46 -3
  11. package/lib/messages.d.ts +32 -0
  12. package/lib/messages.js.flow +35 -0
  13. package/lib/physical-rtl/generate-ltr.d.ts +12 -0
  14. package/lib/physical-rtl/generate-ltr.js.flow +13 -0
  15. package/lib/physical-rtl/generate-rtl.d.ts +14 -0
  16. package/lib/physical-rtl/generate-rtl.js.flow +13 -0
  17. package/lib/preprocess-rules/PreRule.d.ts +52 -0
  18. package/lib/preprocess-rules/PreRule.js.flow +64 -0
  19. package/lib/preprocess-rules/application-order.d.ts +253 -0
  20. package/lib/preprocess-rules/application-order.js.flow +206 -0
  21. package/lib/preprocess-rules/basic-validation.d.ts +13 -0
  22. package/lib/preprocess-rules/basic-validation.js +3 -3
  23. package/lib/preprocess-rules/basic-validation.js.flow +13 -0
  24. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +25 -0
  25. package/lib/preprocess-rules/flatten-raw-style-obj.js +5 -5
  26. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +27 -0
  27. package/lib/preprocess-rules/index.d.ts +18 -0
  28. package/lib/preprocess-rules/index.js.flow +19 -0
  29. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +122 -0
  30. package/lib/preprocess-rules/legacy-expand-shorthands.js +0 -139
  31. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +101 -0
  32. package/lib/preprocess-rules/property-specificity.d.ts +76 -0
  33. package/lib/preprocess-rules/property-specificity.js.flow +87 -0
  34. package/lib/stylex-create-vars.d.ts +27 -0
  35. package/lib/stylex-create-vars.js +59 -0
  36. package/lib/stylex-create-vars.js.flow +22 -0
  37. package/lib/stylex-create.d.ts +23 -0
  38. package/lib/stylex-create.js.flow +30 -0
  39. package/lib/stylex-first-that-works.d.ts +14 -0
  40. package/lib/stylex-first-that-works.js.flow +13 -0
  41. package/lib/stylex-include.d.ts +19 -0
  42. package/lib/stylex-include.js.flow +21 -0
  43. package/lib/stylex-keyframes.d.ts +17 -0
  44. package/lib/stylex-keyframes.js.flow +20 -0
  45. package/lib/transform-value.d.ts +13 -0
  46. package/lib/transform-value.js.flow +15 -0
  47. package/lib/utils/Rule.d.ts +58 -0
  48. package/lib/utils/Rule.js.flow +64 -0
  49. package/lib/utils/dashify.d.ts +10 -0
  50. package/lib/utils/dashify.js.flow +9 -0
  51. package/lib/utils/default-options.d.ts +10 -0
  52. package/lib/utils/default-options.js.flow +24 -0
  53. package/lib/utils/file-based-identifier.d.ts +14 -0
  54. package/lib/utils/file-based-identifier.js +22 -0
  55. package/lib/utils/file-based-identifier.js.flow +13 -0
  56. package/lib/utils/genCSSRule.d.ts +16 -0
  57. package/lib/utils/genCSSRule.js.flow +16 -0
  58. package/lib/utils/normalize-value.d.ts +12 -0
  59. package/lib/utils/normalize-value.js.flow +14 -0
  60. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
  61. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
  62. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
  63. package/lib/utils/normalizers/font-size-px-to-rem.js +9 -4
  64. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
  65. package/lib/utils/normalizers/leading-zero.d.ts +17 -0
  66. package/lib/utils/normalizers/leading-zero.js.flow +16 -0
  67. package/lib/utils/normalizers/quotes.d.ts +19 -0
  68. package/lib/utils/normalizers/quotes.js.flow +18 -0
  69. package/lib/utils/normalizers/timings.d.ts +19 -0
  70. package/lib/utils/normalizers/timings.js.flow +18 -0
  71. package/lib/utils/normalizers/whitespace.d.ts +20 -0
  72. package/lib/utils/normalizers/whitespace.js.flow +19 -0
  73. package/lib/utils/normalizers/zero-dimensions.d.ts +19 -0
  74. package/lib/utils/normalizers/zero-dimensions.js.flow +18 -0
  75. package/lib/utils/object-utils.d.ts +61 -0
  76. package/lib/utils/object-utils.js.flow +81 -0
  77. package/lib/utils/property-priorities.d.ts +11 -0
  78. package/lib/utils/property-priorities.js.flow +10 -0
  79. package/lib/utils/split-css-value.d.ts +15 -0
  80. package/lib/utils/split-css-value.js.flow +16 -0
  81. package/lib/validate.d.ts +12 -0
  82. package/lib/validate.js.flow +12 -0
  83. package/package.json +4 -4
  84. package/lib/expand-shorthands.d.ts +0 -5
  85. package/lib/expand-shorthands.js +0 -330
  86. package/lib/namespace-transforms/__tests__/preflatten.test.js +0 -120
  87. package/lib/namespace-transforms/preflatten.js +0 -89
  88. package/lib/preprocess-rules/expand-shorthands.js +0 -156
  89. package/lib/preprocess-rules/null-out-longhand.js +0 -310
  90. package/lib/preprocess-rules/react-native-web.js +0 -142
  91. package/lib/stylex-defaultValue.js +0 -397
@@ -0,0 +1,122 @@
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 { TStyleValue } from '../common-types';
11
+ /**
12
+ * Shorthand properties:
13
+ * - [x] all - Should be banned
14
+ * - [ ] animation
15
+ * - [ ] background
16
+ * - [-] border
17
+ * - [x] border-block-end
18
+ * - [x] border-block-start
19
+ * - [ ] border-bottom
20
+ * - [x] border-color
21
+ * - [x] border-image
22
+ * - [x] border-inline-end
23
+ * - [x] border-inline-start
24
+ * - [ ] border-left
25
+ * - [x] border-radius
26
+ * - [ ] border-right
27
+ * - [x] border-style
28
+ * - [ ] border-top
29
+ * - [x] border-width
30
+ * - [ ] column-rule
31
+ * - [ ] columns
32
+ * - [ ] flex
33
+ * - [ ] flex-flow
34
+ * - [ ] font
35
+ * - [ ] gap
36
+ * - [ ] grid
37
+ * - [ ] grid-area
38
+ * - [ ] grid-column
39
+ * - [ ] grid-row
40
+ * - [ ] grid-template
41
+ * - [ ] list-style
42
+ * - [x] margin
43
+ * - [ ] mask
44
+ * - [ ] offset
45
+ * - [ ] outline
46
+ * - [x] overflow
47
+ * - [x] padding
48
+ * - [ ] place-content
49
+ * - [ ] place-items
50
+ * - [ ] place-self
51
+ * - [ ] scroll-margin
52
+ * - [ ] scroll-padding
53
+ * - [ ] text-decoration
54
+ * - [ ] text-emphasis
55
+ * - [ ] transition
56
+ */
57
+
58
+ /**
59
+ * Shorthand properties:
60
+ * - [x] all - Should be banned
61
+ * - [ ] animation
62
+ * - [ ] background
63
+ * - [-] border
64
+ * - [x] border-block-end
65
+ * - [x] border-block-start
66
+ * - [ ] border-bottom
67
+ * - [x] border-color
68
+ * - [x] border-image
69
+ * - [x] border-inline-end
70
+ * - [x] border-inline-start
71
+ * - [ ] border-left
72
+ * - [x] border-radius
73
+ * - [ ] border-right
74
+ * - [x] border-style
75
+ * - [ ] border-top
76
+ * - [x] border-width
77
+ * - [ ] column-rule
78
+ * - [ ] columns
79
+ * - [ ] flex
80
+ * - [ ] flex-flow
81
+ * - [ ] font
82
+ * - [ ] gap
83
+ * - [ ] grid
84
+ * - [ ] grid-area
85
+ * - [ ] grid-column
86
+ * - [ ] grid-row
87
+ * - [ ] grid-template
88
+ * - [ ] list-style
89
+ * - [x] margin
90
+ * - [ ] mask
91
+ * - [ ] offset
92
+ * - [ ] outline
93
+ * - [x] overflow
94
+ * - [x] padding
95
+ * - [ ] place-content
96
+ * - [ ] place-items
97
+ * - [ ] place-self
98
+ * - [ ] scroll-margin
99
+ * - [ ] scroll-padding
100
+ * - [ ] text-decoration
101
+ * - [ ] text-emphasis
102
+ * - [ ] transition
103
+ */
104
+
105
+ type TReturn = ReadonlyArray<[string, TStyleValue]>;
106
+ declare var expansions: {
107
+ border: (rawValue: TStyleValue) => TReturn;
108
+ borderColor: (rawValue: TStyleValue) => TReturn;
109
+ borderHorizontal: (rawValue: TStyleValue) => TReturn;
110
+ borderStyle: (rawValue: TStyleValue) => TReturn;
111
+ borderVertical: (rawValue: TStyleValue) => TReturn;
112
+ borderWidth: (rawValue: TStyleValue) => TReturn;
113
+ borderRadius: (rawValue: TStyleValue) => TReturn;
114
+ margin: (rawValue: TStyleValue) => TReturn;
115
+ marginHorizontal: (rawValue: TStyleValue) => TReturn;
116
+ marginVertical: (rawValue: TStyleValue) => TReturn;
117
+ overflow: (rawValue: TStyleValue) => TReturn;
118
+ padding: (rawValue: TStyleValue) => TReturn;
119
+ paddingHorizontal: (rawValue: TStyleValue) => TReturn;
120
+ paddingVertical: (rawValue: TStyleValue) => TReturn;
121
+ };
122
+ export default expansions;
@@ -15,146 +15,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
15
15
  *
16
16
  */
17
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
- // eslint-disable-next-line no-unused-vars
24
- function borderDetector(borderParts) {
25
- const parts = borderParts.filter(Boolean).slice();
26
- let suffix = '';
27
- for (let i = 0; i < parts.length; i++) {
28
- const part = parts[i];
29
- if (typeof part === 'string' && part.endsWith('!important')) {
30
- parts[i] = part.replace('!important', '').trim();
31
- suffix = ' !important';
32
- }
33
- }
34
- if (parts.length === 1 && typeof parts[0] === 'string' && globalKeywords.has(parts[0])) {
35
- return [parts[0], parts[0], parts[0]];
36
- }
37
-
38
- // Find the part that starts with a number
39
- // This is most likely to be the borderWidth
40
- let width = parts.find(part => typeof part === 'number' || part.match(/^\.?\d+/) || borderWidthKeywords.has(part));
41
- if (typeof width === 'number') {
42
- width = String(width) + 'px';
43
- }
44
- // console.log('width', width);
45
- if (width != null) {
46
- parts.splice(parts.indexOf(width), 1);
47
- }
48
- if (parts.length === 0) {
49
- return [String(width) + suffix, null, null];
50
- }
51
- const style = parts.find(part => typeof part === 'string' && borderStyleKeywords.has(part));
52
- if (style != null) {
53
- parts.splice(parts.indexOf(style), 1);
54
- }
55
- if (parts.length === 2 && width == null) {
56
- width = parts[0];
57
- parts.splice(0, 1);
58
- }
59
- if (width != null && parts.length > 1) {
60
- throw new Error('Invalid border shorthand value');
61
- }
62
- const color = parts[0];
63
- return [width, style, color].map(part => part != null ? part + suffix : null);
64
- }
65
18
  const expansions = {
66
- // TODO: Due to UI regressions internally, we need to maintain the buggy behaviour of
67
- // border shorthand for now. This will be fixed in a future release.
68
- // border: (rawValue: TStyleValue): TReturn => {
69
- // if (typeof rawValue === 'number') {
70
- // return expansions.borderWidth(rawValue);
71
- // }
72
-
73
- // const parts = splitValue(rawValue);
74
- // const [width, style, color] = borderDetector(parts);
75
-
76
- // return [
77
- // ...(width != null ? expansions.borderWidth(width) : []),
78
- // ...(style != null ? expansions.borderStyle(style) : []),
79
- // ...(color != null ? expansions.borderColor(color) : []),
80
- // ];
81
- // },
82
- // borderTop: (rawValue: TStyleValue): TReturn => {
83
- // if (typeof rawValue === 'number') {
84
- // return [['borderTopWidth', rawValue]];
85
- // }
86
- // const parts = splitValue(rawValue);
87
- // const [width, style, color] = borderDetector(parts);
88
-
89
- // return [
90
- // width != null ? ['borderTopWidth', width] : null,
91
- // style != null ? ['borderTopStyle', style] : null,
92
- // color != null ? ['borderTopColor', color] : null,
93
- // ].filter(Boolean);
94
- // },
95
- // borderEnd: (rawValue: TStyleValue): TReturn => {
96
- // if (typeof rawValue === 'number') {
97
- // return [['borderEndWidth', rawValue]];
98
- // }
99
-
100
- // const parts = splitValue(rawValue);
101
- // const [width, style, color] = borderDetector(parts);
102
-
103
- // return [
104
- // width != null ? ['borderEndWidth', width] : null,
105
- // style != null ? ['borderEndStyle', style] : null,
106
- // color != null ? ['borderEndColor', color] : null,
107
- // ].filter(Boolean);
108
- // },
109
- // borderRight: (rawValue: TStyleValue): TReturn => {
110
- // if (typeof rawValue === 'number') {
111
- // return [['borderRightWidth', rawValue]];
112
- // }
113
- // const parts = splitValue(rawValue);
114
- // const [width, style, color] = borderDetector(parts);
115
- // return [
116
- // width != null ? ['borderRightWidth', width] : null,
117
- // style != null ? ['borderRightStyle', style] : null,
118
- // color != null ? ['borderRightColor', color] : null,
119
- // ].filter(Boolean);
120
- // },
121
- // borderBottom: (rawValue: TStyleValue): TReturn => {
122
- // if (typeof rawValue === 'number') {
123
- // return [['borderBottomWidth', rawValue]];
124
- // }
125
- // const parts = splitValue(rawValue);
126
- // const [width, style, color] = borderDetector(parts);
127
- // return [
128
- // width != null ? ['borderBottomWidth', width] : null,
129
- // style != null ? ['borderBottomStyle', style] : null,
130
- // color != null ? ['borderBottomColor', color] : null,
131
- // ].filter(Boolean);
132
- // },
133
- // borderStart: (rawValue: TStyleValue): TReturn => {
134
- // if (typeof rawValue === 'number') {
135
- // return [['borderStartWidth', rawValue]];
136
- // }
137
- // const parts = splitValue(rawValue);
138
- // const [width, style, color] = borderDetector(parts);
139
- // return [
140
- // width != null ? ['borderStartWidth', width] : null,
141
- // style != null ? ['borderStartStyle', style] : null,
142
- // color != null ? ['borderStartColor', color] : null,
143
- // ].filter(Boolean);
144
- // },
145
- // borderLeft: (rawValue: TStyleValue): TReturn => {
146
- // if (typeof rawValue === 'number') {
147
- // return [['borderLeftWidth', rawValue]];
148
- // }
149
- // const parts = splitValue(rawValue);
150
- // const [width, style, color] = borderDetector(parts);
151
- // return [
152
- // width != null ? ['borderLeftWidth', width] : null,
153
- // style != null ? ['borderLeftStyle', style] : null,
154
- // color != null ? ['borderLeftColor', color] : null,
155
- // ].filter(Boolean);
156
- // },
157
-
158
19
  border: rawValue => {
159
20
  return [['borderTop', rawValue], ['borderEnd', rawValue], ['borderBottom', rawValue], ['borderStart', rawValue]];
160
21
  },
@@ -0,0 +1,101 @@
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
+ // TODO: to be added later.
13
+ // const aliases = {
14
+ // marginInlineStart: (rawValue) => [['marginStart', rawValue]],
15
+ // marginInlineEnd: (rawValue) => [['marginEnd', rawValue]],
16
+ // marginInline: (rawValue) => [
17
+ // ['marginStart', rawValue],
18
+ // ['marginEnd', rawValue],
19
+ // ],
20
+ // paddingInlineStart: (rawValue) => [['paddingStart', rawValue]],
21
+ // paddingInlineEnd: (rawValue) => [['paddingEnd', rawValue]],
22
+ // paddingInline: (rawValue) => [
23
+ // ['paddingStart', rawValue],
24
+ // ['paddingEnd', rawValue],
25
+ // ],
26
+ // // 'borderInlineStart': (rawValue) => [['borderStart', rawValue]],
27
+ // // 'borderInlineEnd': (rawValue) => [['borderEnd', rawValue]],
28
+ // // // This will need to change.
29
+ // // 'borderInline': (rawValue) => [
30
+ // // ['borderStart', rawValue],
31
+ // // ['borderEnd', rawValue],
32
+ // // ],
33
+ // };
34
+
35
+ /**
36
+ * Shorthand properties:
37
+ * - [x] all - Should be banned
38
+ * - [ ] animation
39
+ * - [ ] background
40
+ * - [-] border
41
+ * - [x] border-block-end
42
+ * - [x] border-block-start
43
+ * - [ ] border-bottom
44
+ * - [x] border-color
45
+ * - [x] border-image
46
+ * - [x] border-inline-end
47
+ * - [x] border-inline-start
48
+ * - [ ] border-left
49
+ * - [x] border-radius
50
+ * - [ ] border-right
51
+ * - [x] border-style
52
+ * - [ ] border-top
53
+ * - [x] border-width
54
+ * - [ ] column-rule
55
+ * - [ ] columns
56
+ * - [ ] flex
57
+ * - [ ] flex-flow
58
+ * - [ ] font
59
+ * - [ ] gap
60
+ * - [ ] grid
61
+ * - [ ] grid-area
62
+ * - [ ] grid-column
63
+ * - [ ] grid-row
64
+ * - [ ] grid-template
65
+ * - [ ] list-style
66
+ * - [x] margin
67
+ * - [ ] mask
68
+ * - [ ] offset
69
+ * - [ ] outline
70
+ * - [x] overflow
71
+ * - [x] padding
72
+ * - [ ] place-content
73
+ * - [ ] place-items
74
+ * - [ ] place-self
75
+ * - [ ] scroll-margin
76
+ * - [ ] scroll-padding
77
+ * - [ ] text-decoration
78
+ * - [ ] text-emphasis
79
+ * - [ ] transition
80
+ */
81
+
82
+ type TReturn = $ReadOnlyArray<[string, TStyleValue]>;
83
+
84
+ declare var expansions: {
85
+ border: (rawValue: TStyleValue) => TReturn,
86
+ borderColor: (rawValue: TStyleValue) => TReturn,
87
+ borderHorizontal: (rawValue: TStyleValue) => TReturn,
88
+ borderStyle: (rawValue: TStyleValue) => TReturn,
89
+ borderVertical: (rawValue: TStyleValue) => TReturn,
90
+ borderWidth: (rawValue: TStyleValue) => TReturn,
91
+ borderRadius: (rawValue: TStyleValue) => TReturn,
92
+ margin: (rawValue: TStyleValue) => TReturn,
93
+ marginHorizontal: (rawValue: TStyleValue) => TReturn,
94
+ marginVertical: (rawValue: TStyleValue) => TReturn,
95
+ overflow: (rawValue: TStyleValue) => TReturn,
96
+ padding: (rawValue: TStyleValue) => TReturn,
97
+ paddingHorizontal: (rawValue: TStyleValue) => TReturn,
98
+ paddingVertical: (rawValue: TStyleValue) => TReturn,
99
+ };
100
+
101
+ declare export default expansions;
@@ -0,0 +1,76 @@
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 { TStyleValue } from '../common-types';
11
+ type TReturn = ReadonlyArray<[string, TStyleValue]>;
12
+ declare var shorthands: {
13
+ all: (_: TStyleValue) => TReturn;
14
+ animation: (_value: TStyleValue) => TReturn;
15
+ background: (_value: TStyleValue) => TReturn;
16
+ border: (_rawValue: TStyleValue) => TReturn;
17
+ borderInline: (_rawValue: TStyleValue) => TReturn;
18
+ borderBlock: (_rawValue: TStyleValue) => TReturn;
19
+ borderTop: (_rawValue: TStyleValue) => TReturn;
20
+ borderInlineEnd: (_rawValue: TStyleValue) => TReturn;
21
+ borderRight: (_rawValue: TStyleValue) => TReturn;
22
+ borderBottom: (_rawValue: TStyleValue) => TReturn;
23
+ borderInlineStart: (_rawValue: TStyleValue) => TReturn;
24
+ borderLeft: (_rawValue: TStyleValue) => TReturn;
25
+ margin: (value: TStyleValue) => TReturn;
26
+ padding: (rawValue: TStyleValue) => TReturn;
27
+ };
28
+ declare var aliases: {
29
+ borderHorizontal: any;
30
+ borderVertical: any;
31
+ borderBlockStart: any;
32
+ borderEnd: any;
33
+ borderBlockEnd: any;
34
+ borderStart: any;
35
+ borderHorizontalWidth: (value: TStyleValue) => TReturn;
36
+ borderHorizontalStyle: (value: TStyleValue) => TReturn;
37
+ borderHorizontalColor: (value: TStyleValue) => TReturn;
38
+ borderVerticalWidth: (value: TStyleValue) => TReturn;
39
+ borderVerticalStyle: (value: TStyleValue) => TReturn;
40
+ borderVerticalColor: (value: TStyleValue) => TReturn;
41
+ borderBlockStartColor: (value: TStyleValue) => TReturn;
42
+ borderBlockEndColor: (value: TStyleValue) => TReturn;
43
+ borderBlockStartStyle: (value: TStyleValue) => TReturn;
44
+ borderBlockEndStyle: (value: TStyleValue) => TReturn;
45
+ borderBlockStartWidth: (value: TStyleValue) => TReturn;
46
+ borderBlockEndWidth: (value: TStyleValue) => TReturn;
47
+ borderStartColor: (value: TStyleValue) => TReturn;
48
+ borderEndColor: (value: TStyleValue) => TReturn;
49
+ borderStartStyle: (value: TStyleValue) => TReturn;
50
+ borderEndStyle: (value: TStyleValue) => TReturn;
51
+ borderStartWidth: (value: TStyleValue) => TReturn;
52
+ borderEndWidth: (value: TStyleValue) => TReturn;
53
+ borderTopStartRadius: (value: TStyleValue) => TReturn;
54
+ borderTopEndRadius: (value: TStyleValue) => TReturn;
55
+ borderBottomStartRadius: (value: TStyleValue) => TReturn;
56
+ borderBottomEndRadius: (value: TStyleValue) => TReturn;
57
+ marginBlockStart: (value: TStyleValue) => TReturn;
58
+ marginBlockEnd: (value: TStyleValue) => TReturn;
59
+ marginStart: (value: TStyleValue) => TReturn;
60
+ marginEnd: (value: TStyleValue) => TReturn;
61
+ marginHorizontal: (value: TStyleValue) => TReturn;
62
+ marginVertical: (value: TStyleValue) => TReturn;
63
+ paddingBlockStart: (rawValue: TStyleValue) => TReturn;
64
+ paddingBlockEnd: (rawValue: TStyleValue) => TReturn;
65
+ paddingStart: (value: TStyleValue) => TReturn;
66
+ paddingEnd: (value: TStyleValue) => TReturn;
67
+ paddingHorizontal: (value: TStyleValue) => TReturn;
68
+ paddingVertical: (value: TStyleValue) => TReturn;
69
+ insetBlockStart: (value: TStyleValue) => TReturn;
70
+ insetBlockEnd: (value: TStyleValue) => TReturn;
71
+ start: (value: TStyleValue) => TReturn;
72
+ end: (value: TStyleValue) => TReturn;
73
+ };
74
+ declare var expansions: Omit<shorthands, keyof (aliases | {})> &
75
+ Omit<aliases, keyof ({})> & {};
76
+ export default expansions;
@@ -0,0 +1,87 @@
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
+ /// # Handle CSS shorthands in a React Native compatible way.
13
+ ///
14
+ /// This means:
15
+ /// - disallowing certain properties altogether by throwing errors
16
+ /// - disallowing multiple values within many shorthands
17
+ /// - Treating certain non-standard properties as aliases for real CSS properties
18
+
19
+ type TReturn = $ReadOnlyArray<[string, TStyleValue]>;
20
+
21
+ declare var shorthands: {
22
+ all: (_: TStyleValue) => TReturn,
23
+ animation: (_value: TStyleValue) => TReturn,
24
+ background: (_value: TStyleValue) => TReturn,
25
+ border: (_rawValue: TStyleValue) => TReturn,
26
+ borderInline: (_rawValue: TStyleValue) => TReturn,
27
+ borderBlock: (_rawValue: TStyleValue) => TReturn,
28
+ borderTop: (_rawValue: TStyleValue) => TReturn,
29
+ borderInlineEnd: (_rawValue: TStyleValue) => TReturn,
30
+ borderRight: (_rawValue: TStyleValue) => TReturn,
31
+ borderBottom: (_rawValue: TStyleValue) => TReturn,
32
+ borderInlineStart: (_rawValue: TStyleValue) => TReturn,
33
+ borderLeft: (_rawValue: TStyleValue) => TReturn,
34
+ margin: (value: TStyleValue) => TReturn,
35
+ padding: (rawValue: TStyleValue) => TReturn,
36
+ };
37
+
38
+ declare var aliases: {
39
+ borderHorizontal: $FlowFixMe,
40
+ borderVertical: $FlowFixMe,
41
+ borderBlockStart: $FlowFixMe,
42
+ borderEnd: $FlowFixMe,
43
+ borderBlockEnd: $FlowFixMe,
44
+ borderStart: $FlowFixMe,
45
+ borderHorizontalWidth: (value: TStyleValue) => TReturn,
46
+ borderHorizontalStyle: (value: TStyleValue) => TReturn,
47
+ borderHorizontalColor: (value: TStyleValue) => TReturn,
48
+ borderVerticalWidth: (value: TStyleValue) => TReturn,
49
+ borderVerticalStyle: (value: TStyleValue) => TReturn,
50
+ borderVerticalColor: (value: TStyleValue) => TReturn,
51
+ borderBlockStartColor: (value: TStyleValue) => TReturn,
52
+ borderBlockEndColor: (value: TStyleValue) => TReturn,
53
+ borderBlockStartStyle: (value: TStyleValue) => TReturn,
54
+ borderBlockEndStyle: (value: TStyleValue) => TReturn,
55
+ borderBlockStartWidth: (value: TStyleValue) => TReturn,
56
+ borderBlockEndWidth: (value: TStyleValue) => TReturn,
57
+ borderStartColor: (value: TStyleValue) => TReturn,
58
+ borderEndColor: (value: TStyleValue) => TReturn,
59
+ borderStartStyle: (value: TStyleValue) => TReturn,
60
+ borderEndStyle: (value: TStyleValue) => TReturn,
61
+ borderStartWidth: (value: TStyleValue) => TReturn,
62
+ borderEndWidth: (value: TStyleValue) => TReturn,
63
+ borderTopStartRadius: (value: TStyleValue) => TReturn,
64
+ borderTopEndRadius: (value: TStyleValue) => TReturn,
65
+ borderBottomStartRadius: (value: TStyleValue) => TReturn,
66
+ borderBottomEndRadius: (value: TStyleValue) => TReturn,
67
+ marginBlockStart: (value: TStyleValue) => TReturn,
68
+ marginBlockEnd: (value: TStyleValue) => TReturn,
69
+ marginStart: (value: TStyleValue) => TReturn,
70
+ marginEnd: (value: TStyleValue) => TReturn,
71
+ marginHorizontal: (value: TStyleValue) => TReturn,
72
+ marginVertical: (value: TStyleValue) => TReturn,
73
+ paddingBlockStart: (rawValue: TStyleValue) => TReturn,
74
+ paddingBlockEnd: (rawValue: TStyleValue) => TReturn,
75
+ paddingStart: (value: TStyleValue) => TReturn,
76
+ paddingEnd: (value: TStyleValue) => TReturn,
77
+ paddingHorizontal: (value: TStyleValue) => TReturn,
78
+ paddingVertical: (value: TStyleValue) => TReturn,
79
+ insetBlockStart: (value: TStyleValue) => TReturn,
80
+ insetBlockEnd: (value: TStyleValue) => TReturn,
81
+ start: (value: TStyleValue) => TReturn,
82
+ end: (value: TStyleValue) => TReturn,
83
+ };
84
+
85
+ declare var expansions: { ...shorthands, ...aliases };
86
+
87
+ declare export default expansions;
@@ -0,0 +1,27 @@
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 { StyleXOptions } from './common-types';
11
+ type VarsObject<Vars extends { readonly [$$Key$$: string]: string | number }> =
12
+ /**
13
+ * > 13 | ...$ObjMapConst<Vars, string>,
14
+ * | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with complex spreads" is currently not supported.
15
+ **/
16
+ any;
17
+ declare function styleXCreateVars<
18
+ Vars extends { readonly [$$Key$$: string]: string }
19
+ >(
20
+ variables: Vars,
21
+ options: Readonly<
22
+ Omit<Partial<StyleXOptions>, keyof ({ themeName: string })> & {
23
+ themeName: string;
24
+ }
25
+ >
26
+ ): [VarsObject<Vars>, { css: string }];
27
+ export default styleXCreateVars;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = styleXCreateVars;
7
+ var _hash = _interopRequireDefault(require("./hash"));
8
+ var _objectUtils = require("./utils/object-utils");
9
+ var _defaultOptions = require("./utils/default-options");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ *
18
+ */
19
+
20
+ // Similar to `stylex.create` it takes an object of variables with their values
21
+ // and returns a string after hashing it.
22
+ function styleXCreateVars(variables, options) {
23
+ const {
24
+ classNamePrefix,
25
+ themeName
26
+ } = {
27
+ ..._defaultOptions.defaultOptions,
28
+ ...options
29
+ };
30
+ const themeNameHash = classNamePrefix + (0, _hash.default)(themeName);
31
+ const variablesMap = (0, _objectUtils.objMap)(variables, (value, key) => {
32
+ // Created hashed variable names with fileName//themeName//key
33
+ const nameHash = classNamePrefix + (0, _hash.default)(`${themeName}.${key}`);
34
+ return {
35
+ nameHash,
36
+ value
37
+ };
38
+ });
39
+ const themeVariablesObject = (0, _objectUtils.objMap)(variablesMap, _ref => {
40
+ let {
41
+ nameHash
42
+ } = _ref;
43
+ return `var(--${nameHash})`;
44
+ });
45
+ const cssVariablesString = constructCssVariablesString(variablesMap);
46
+ return [{
47
+ ...themeVariablesObject,
48
+ __themeName__: themeNameHash
49
+ }, {
50
+ css: cssVariablesString
51
+ }];
52
+ }
53
+ function constructCssVariablesString(variables) {
54
+ const vars = (0, _objectUtils.objEntries)(variables).map(_ref2 => {
55
+ let [_, value] = _ref2;
56
+ return `--${value.nameHash}:${value.value};`;
57
+ }).join('');
58
+ return `:root{${vars}}`;
59
+ }
@@ -0,0 +1,22 @@
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 { StyleXOptions } from './common-types';
11
+
12
+ type VarsObject<Vars: { +[string]: string | number }> = {
13
+ ...$ObjMapConst<Vars, string>,
14
+ __themeName__: string,
15
+ };
16
+
17
+ // Similar to `stylex.create` it takes an object of variables with their values
18
+ // and returns a string after hashing it.
19
+ declare export default function styleXCreateVars<+Vars: { +[string]: string }>(
20
+ variables: Vars,
21
+ options: $ReadOnly<{ ...Partial<StyleXOptions>, themeName: string, ... }>
22
+ ): [VarsObject<Vars>, { css: string }];
@@ -0,0 +1,23 @@
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 {
11
+ RawStyles,
12
+ InjectableStyle,
13
+ StyleXOptions,
14
+ FlatCompiledStyles,
15
+ } from './common-types';
16
+ declare function styleXCreateSet(
17
+ namespaces: { readonly [$$Key$$: string]: RawStyles },
18
+ options?: StyleXOptions
19
+ ): [
20
+ { [$$Key$$: string]: FlatCompiledStyles },
21
+ { [$$Key$$: string]: InjectableStyle }
22
+ ];
23
+ export default styleXCreateSet;