@stylexjs/shared 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/convert-to-className.d.ts +5 -1
- package/lib/convert-to-className.js +33 -1
- package/lib/convert-to-className.js.flow +5 -1
- package/lib/messages.d.ts +1 -0
- package/lib/messages.js +3 -2
- package/lib/messages.js.flow +1 -0
- package/lib/stylex-create-theme.js +30 -40
- package/lib/stylex-define-vars.d.ts +2 -6
- package/lib/stylex-define-vars.js +40 -21
- package/lib/stylex-define-vars.js.flow +1 -4
- package/lib/stylex-first-that-works.d.ts +1 -1
- package/lib/stylex-first-that-works.js.flow +1 -1
- package/lib/stylex-vars-utils.d.ts +27 -0
- package/lib/stylex-vars-utils.js +69 -0
- package/lib/stylex-vars-utils.js.flow +31 -0
- package/lib/types/index.d.ts +79 -76
- package/lib/types/index.js +28 -72
- package/lib/types/index.js.flow +82 -82
- package/lib/utils/normalize-value.js +1 -2
- package/lib/utils/normalizers/zero-dimensions.d.ts +2 -2
- package/lib/utils/normalizers/zero-dimensions.js +6 -0
- package/lib/utils/normalizers/zero-dimensions.js.flow +2 -2
- package/package.json +2 -2
package/lib/types/index.js.flow
CHANGED
@@ -15,15 +15,23 @@
|
|
15
15
|
// We want on type that defines CSS Types
|
16
16
|
// Option 2: Do a union type and make
|
17
17
|
|
18
|
-
// interface
|
18
|
+
// interface CSSType {
|
19
19
|
// toString(): string;
|
20
20
|
// }
|
21
21
|
|
22
|
-
type
|
23
|
-
|
|
22
|
+
type NestedWithNumbers =
|
23
|
+
| number
|
24
|
+
| string
|
24
25
|
| $ReadOnly<{
|
25
|
-
default:
|
26
|
-
[string]:
|
26
|
+
default: NestedWithNumbers,
|
27
|
+
[string]: NestedWithNumbers,
|
28
|
+
}>;
|
29
|
+
|
30
|
+
type ValueWithDefault =
|
31
|
+
| string
|
32
|
+
| $ReadOnly<{
|
33
|
+
default: ValueWithDefault,
|
34
|
+
[string]: ValueWithDefault,
|
27
35
|
}>;
|
28
36
|
|
29
37
|
type CSSSyntax =
|
@@ -43,51 +51,56 @@ type CSSSyntax =
|
|
43
51
|
| '<custom-ident>'
|
44
52
|
| '<transform-list>';
|
45
53
|
|
46
|
-
type CSSSyntaxType = CSSSyntax
|
47
|
-
|
48
|
-
declare export class CSSType {}
|
54
|
+
type CSSSyntaxType = CSSSyntax;
|
49
55
|
|
50
|
-
|
51
|
-
+value: ValueWithDefault
|
56
|
+
declare class BaseCSSType {
|
57
|
+
+value: ValueWithDefault;
|
58
|
+
+syntax: CSSSyntaxType;
|
59
|
+
constructor(value: ValueWithDefault): void;
|
60
|
+
}
|
61
|
+
export interface CSSType<+_T: string | number = string | number> {
|
62
|
+
+value: ValueWithDefault;
|
52
63
|
+syntax: CSSSyntaxType;
|
53
64
|
}
|
54
65
|
|
66
|
+
declare export const isCSSType: (
|
67
|
+
value: mixed,
|
68
|
+
) => value is CSSType<string | number>;
|
69
|
+
|
55
70
|
type AnguleValue = string;
|
56
71
|
declare export class Angle<+T: AnguleValue>
|
57
|
-
extends
|
58
|
-
implements
|
72
|
+
extends BaseCSSType
|
73
|
+
implements CSSType<T>
|
59
74
|
{
|
60
|
-
+value: ValueWithDefault
|
75
|
+
+value: ValueWithDefault;
|
61
76
|
+syntax: CSSSyntaxType;
|
62
77
|
static +syntax: CSSSyntaxType;
|
63
|
-
constructor(value: ValueWithDefault<T>): void;
|
64
78
|
static create<T: AnguleValue = AnguleValue>(
|
65
|
-
value: ValueWithDefault
|
79
|
+
value: ValueWithDefault,
|
66
80
|
): Angle<T>;
|
67
81
|
}
|
68
82
|
declare export const angle: $FlowFixMe;
|
69
83
|
|
70
84
|
type ColorValue = string;
|
71
85
|
declare export class Color<+T: ColorValue>
|
72
|
-
extends
|
73
|
-
implements
|
86
|
+
extends BaseCSSType
|
87
|
+
implements CSSType<T>
|
74
88
|
{
|
75
|
-
+value: ValueWithDefault
|
89
|
+
+value: ValueWithDefault;
|
76
90
|
+syntax: CSSSyntaxType;
|
77
|
-
|
78
|
-
static create<T: ColorValue = ColorValue>(
|
79
|
-
value: ValueWithDefault<T>,
|
80
|
-
): Color<T>;
|
91
|
+
static create<T: ColorValue = ColorValue>(value: ValueWithDefault): Color<T>;
|
81
92
|
}
|
82
93
|
declare export const color: $FlowFixMe;
|
83
94
|
|
84
95
|
type URLValue = string;
|
85
96
|
|
86
|
-
declare export class Url<+T: URLValue>
|
87
|
-
|
97
|
+
declare export class Url<+T: URLValue>
|
98
|
+
extends BaseCSSType
|
99
|
+
implements CSSType<T>
|
100
|
+
{
|
101
|
+
+value: ValueWithDefault;
|
88
102
|
+syntax: CSSSyntaxType;
|
89
|
-
|
90
|
-
static create<T: URLValue = URLValue>(value: ValueWithDefault<T>): Url<T>;
|
103
|
+
static create<T: URLValue = URLValue>(value: ValueWithDefault): Url<T>;
|
91
104
|
}
|
92
105
|
declare export const url: $FlowFixMe;
|
93
106
|
|
@@ -95,74 +108,68 @@ type ImageValue = string;
|
|
95
108
|
|
96
109
|
declare export class Image<+T: ImageValue>
|
97
110
|
extends Url<T>
|
98
|
-
implements
|
111
|
+
implements CSSType<T>
|
99
112
|
{
|
100
|
-
+value: ValueWithDefault
|
113
|
+
+value: ValueWithDefault;
|
101
114
|
+syntax: CSSSyntaxType;
|
102
|
-
constructor(value: ValueWithDefault
|
103
|
-
static create<T: ImageValue = ImageValue>(
|
104
|
-
value: ValueWithDefault<T>,
|
105
|
-
): Image<T>;
|
115
|
+
constructor(value: ValueWithDefault): void;
|
116
|
+
static create<T: ImageValue = ImageValue>(value: ValueWithDefault): Image<T>;
|
106
117
|
}
|
107
118
|
declare export const image: $FlowFixMe;
|
108
119
|
|
109
120
|
type IntegerValue = number;
|
110
121
|
|
111
122
|
declare export class Integer<+T: IntegerValue>
|
112
|
-
extends
|
113
|
-
implements
|
123
|
+
extends BaseCSSType
|
124
|
+
implements CSSType<T>
|
114
125
|
{
|
115
|
-
+value: ValueWithDefault
|
126
|
+
+value: ValueWithDefault;
|
116
127
|
+syntax: CSSSyntaxType;
|
117
|
-
constructor(value: ValueWithDefault<T>): void;
|
118
128
|
static create<T: IntegerValue = IntegerValue>(value: T): Integer<T>;
|
119
129
|
}
|
120
130
|
declare export const integer: $FlowFixMe;
|
121
131
|
|
122
132
|
type LengthPercentageValue = string;
|
123
133
|
|
124
|
-
declare export class LengthPercentage<+
|
125
|
-
extends
|
126
|
-
implements
|
134
|
+
declare export class LengthPercentage<+_T: LengthPercentageValue>
|
135
|
+
extends BaseCSSType
|
136
|
+
implements CSSType<string>
|
127
137
|
{
|
128
|
-
+value: ValueWithDefault
|
138
|
+
+value: ValueWithDefault;
|
129
139
|
+syntax: CSSSyntaxType;
|
130
|
-
|
131
|
-
|
132
|
-
value: ValueWithDefault<T>,
|
140
|
+
static createLength<_T: LengthPercentageValue | number>(
|
141
|
+
value: ValueWithDefault,
|
133
142
|
): LengthPercentage<string>;
|
134
|
-
static createPercentage<
|
135
|
-
value: ValueWithDefault
|
143
|
+
static createPercentage<_T: LengthPercentageValue | number>(
|
144
|
+
value: ValueWithDefault,
|
136
145
|
): LengthPercentage<string>;
|
137
146
|
}
|
138
147
|
declare export const lengthPercentage: $FlowFixMe;
|
139
148
|
|
140
149
|
type LengthValue = number | string;
|
141
150
|
|
142
|
-
declare export class Length<+
|
151
|
+
declare export class Length<+_T: LengthValue>
|
143
152
|
extends LengthPercentage<string>
|
144
|
-
implements
|
153
|
+
implements CSSType<string>
|
145
154
|
{
|
146
|
-
+value: ValueWithDefault
|
155
|
+
+value: ValueWithDefault;
|
147
156
|
+syntax: CSSSyntaxType;
|
148
|
-
constructor(value: ValueWithDefault<T>): void;
|
149
157
|
static create<T: LengthValue = LengthValue>(
|
150
|
-
value:
|
158
|
+
value: NestedWithNumbers,
|
151
159
|
): Length<T>;
|
152
160
|
}
|
153
161
|
declare export const length: $FlowFixMe;
|
154
162
|
|
155
163
|
type PercentageValue = string | number;
|
156
164
|
|
157
|
-
declare export class Percentage<+
|
165
|
+
declare export class Percentage<+_T: PercentageValue>
|
158
166
|
extends LengthPercentage<string>
|
159
|
-
implements
|
167
|
+
implements CSSType<string>
|
160
168
|
{
|
161
|
-
+value: ValueWithDefault
|
169
|
+
+value: ValueWithDefault;
|
162
170
|
+syntax: CSSSyntaxType;
|
163
|
-
constructor(value: ValueWithDefault<T>): void;
|
164
171
|
static create<T: PercentageValue = PercentageValue>(
|
165
|
-
value:
|
172
|
+
value: NestedWithNumbers,
|
166
173
|
): Percentage<T>;
|
167
174
|
}
|
168
175
|
declare export const percentage: $FlowFixMe;
|
@@ -170,29 +177,25 @@ declare export const percentage: $FlowFixMe;
|
|
170
177
|
type NumberValue = number;
|
171
178
|
|
172
179
|
declare export class Num<+T: NumberValue>
|
173
|
-
extends
|
174
|
-
implements
|
180
|
+
extends BaseCSSType
|
181
|
+
implements CSSType<T>
|
175
182
|
{
|
176
|
-
+value: ValueWithDefault
|
183
|
+
+value: ValueWithDefault;
|
177
184
|
+syntax: CSSSyntaxType;
|
178
|
-
|
179
|
-
static create<T: NumberValue = NumberValue>(
|
180
|
-
value: ValueWithDefault<T>,
|
181
|
-
): Num<T>;
|
185
|
+
static create<T: NumberValue = NumberValue>(value: NestedWithNumbers): Num<T>;
|
182
186
|
}
|
183
187
|
declare export const number: $FlowFixMe;
|
184
188
|
|
185
189
|
type ResolutionValue = string | 0;
|
186
190
|
|
187
191
|
declare export class Resolution<+T: ResolutionValue>
|
188
|
-
extends
|
189
|
-
implements
|
192
|
+
extends BaseCSSType
|
193
|
+
implements CSSType<T>
|
190
194
|
{
|
191
|
-
+value: ValueWithDefault
|
195
|
+
+value: ValueWithDefault;
|
192
196
|
+syntax: CSSSyntaxType;
|
193
|
-
constructor(value: ValueWithDefault<T>): void;
|
194
197
|
static create<T: ResolutionValue = ResolutionValue>(
|
195
|
-
value: ValueWithDefault
|
198
|
+
value: ValueWithDefault,
|
196
199
|
): Resolution<T>;
|
197
200
|
}
|
198
201
|
declare export const resolution: $FlowFixMe;
|
@@ -200,27 +203,25 @@ declare export const resolution: $FlowFixMe;
|
|
200
203
|
type TimeValue = string | 0;
|
201
204
|
|
202
205
|
declare export class Time<+T: TimeValue>
|
203
|
-
extends
|
204
|
-
implements
|
206
|
+
extends BaseCSSType
|
207
|
+
implements CSSType<T>
|
205
208
|
{
|
206
|
-
+value: ValueWithDefault
|
209
|
+
+value: ValueWithDefault;
|
207
210
|
+syntax: CSSSyntaxType;
|
208
|
-
|
209
|
-
static create<T: TimeValue = TimeValue>(value: ValueWithDefault<T>): Time<T>;
|
211
|
+
static create<T: TimeValue = TimeValue>(value: ValueWithDefault): Time<T>;
|
210
212
|
}
|
211
213
|
declare export const time: $FlowFixMe;
|
212
214
|
|
213
215
|
type TransformFunctionValue = string;
|
214
216
|
|
215
217
|
declare export class TransformFunction<+T: TransformFunctionValue>
|
216
|
-
extends
|
217
|
-
implements
|
218
|
+
extends BaseCSSType
|
219
|
+
implements CSSType<T>
|
218
220
|
{
|
219
|
-
+value: ValueWithDefault
|
221
|
+
+value: ValueWithDefault;
|
220
222
|
+syntax: CSSSyntaxType;
|
221
|
-
constructor(value: ValueWithDefault<T>): void;
|
222
223
|
static create<T: TransformFunctionValue = TransformFunctionValue>(
|
223
|
-
value: ValueWithDefault
|
224
|
+
value: ValueWithDefault,
|
224
225
|
): TransformFunction<T>;
|
225
226
|
}
|
226
227
|
declare export const transformFunction: $FlowFixMe;
|
@@ -228,14 +229,13 @@ declare export const transformFunction: $FlowFixMe;
|
|
228
229
|
type TransformListValue = string;
|
229
230
|
|
230
231
|
declare export class TransformList<T: TransformListValue>
|
231
|
-
extends
|
232
|
-
implements
|
232
|
+
extends BaseCSSType
|
233
|
+
implements CSSType<T>
|
233
234
|
{
|
234
|
-
+value: ValueWithDefault
|
235
|
+
+value: ValueWithDefault;
|
235
236
|
+syntax: CSSSyntaxType;
|
236
|
-
constructor(value: ValueWithDefault<T>): void;
|
237
237
|
static create<T: TransformListValue = TransformListValue>(
|
238
|
-
value: ValueWithDefault
|
238
|
+
value: ValueWithDefault,
|
239
239
|
): TransformList<T>;
|
240
240
|
}
|
241
241
|
declare export const transformList: $FlowFixMe;
|
@@ -9,12 +9,11 @@ var _leadingZero = _interopRequireDefault(require("./normalizers/leading-zero"))
|
|
9
9
|
var _quotes = _interopRequireDefault(require("./normalizers/quotes"));
|
10
10
|
var _timings = _interopRequireDefault(require("./normalizers/timings"));
|
11
11
|
var _whitespace = _interopRequireDefault(require("./normalizers/whitespace"));
|
12
|
-
var _zeroDimensions = _interopRequireDefault(require("./normalizers/zero-dimensions"));
|
13
12
|
var _detectUnclosedFns = _interopRequireDefault(require("./normalizers/detect-unclosed-fns"));
|
14
13
|
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
15
14
|
var _convertCamelCaseValues = _interopRequireDefault(require("./normalizers/convert-camel-case-values"));
|
16
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
-
const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default,
|
16
|
+
const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _leadingZero.default, _quotes.default, _convertCamelCaseValues.default];
|
18
17
|
function normalizeValue(value, key, _ref) {
|
19
18
|
let {
|
20
19
|
useRemForFontSize
|
@@ -8,8 +8,8 @@
|
|
8
8
|
*/
|
9
9
|
|
10
10
|
/**
|
11
|
-
* Remove units in zero values, except when required: in angles and
|
12
|
-
* in which case make them consistent 0deg and
|
11
|
+
* Remove units in zero values, except when required: in angles, timings, fractions, and percentages,
|
12
|
+
* in which case make them consistent 0deg, 0s, 0fr, and 0%.
|
13
13
|
*/
|
14
14
|
|
15
15
|
declare function normalizeZeroDimensions(
|
@@ -8,6 +8,8 @@ var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser")
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
9
|
const angles = ['deg', 'grad', 'turn', 'rad'];
|
10
10
|
const timings = ['ms', 's'];
|
11
|
+
const fraction = 'fr';
|
12
|
+
const percentage = '%';
|
11
13
|
function normalizeZeroDimensions(ast, _) {
|
12
14
|
let endFunction = 0;
|
13
15
|
ast.walk(node => {
|
@@ -28,6 +30,10 @@ function normalizeZeroDimensions(ast, _) {
|
|
28
30
|
node.value = '0deg';
|
29
31
|
} else if (timings.indexOf(dimension.unit) !== -1) {
|
30
32
|
node.value = '0s';
|
33
|
+
} else if (dimension.unit === fraction) {
|
34
|
+
node.value = '0fr';
|
35
|
+
} else if (dimension.unit === percentage) {
|
36
|
+
node.value = '0%';
|
31
37
|
} else if (!endFunction) {
|
32
38
|
node.value = '0';
|
33
39
|
}
|
@@ -8,8 +8,8 @@
|
|
8
8
|
*/
|
9
9
|
|
10
10
|
/**
|
11
|
-
* Remove units in zero values, except when required: in angles and
|
12
|
-
* in which case make them consistent 0deg and
|
11
|
+
* Remove units in zero values, except when required: in angles, timings, fractions, and percentages,
|
12
|
+
* in which case make them consistent 0deg, 0s, 0fr, and 0%.
|
13
13
|
*/
|
14
14
|
|
15
15
|
declare export default function normalizeZeroDimensions(
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@stylexjs/shared",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.6.0",
|
4
4
|
"main": "lib/index.js",
|
5
5
|
"repository": "https://www.github.com/facebook/stylex",
|
6
6
|
"license": "MIT",
|
@@ -13,7 +13,7 @@
|
|
13
13
|
"postcss-value-parser": "^4.1.0"
|
14
14
|
},
|
15
15
|
"devDependencies": {
|
16
|
-
"@stylexjs/scripts": "0.
|
16
|
+
"@stylexjs/scripts": "0.6.0"
|
17
17
|
},
|
18
18
|
"jest": {
|
19
19
|
"snapshotFormat": {
|