@stylexjs/shared 0.5.1 → 0.6.0

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.
@@ -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 ICSSType {
18
+ // interface CSSType {
19
19
  // toString(): string;
20
20
  // }
21
21
 
22
- type ValueWithDefault<+T> =
23
- | T
22
+ type NestedWithNumbers =
23
+ | number
24
+ | string
24
25
  | $ReadOnly<{
25
- default: T,
26
- [string]: ValueWithDefault<T>,
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 | $ReadOnlyArray<CSSSyntax>;
47
-
48
- declare export class CSSType {}
54
+ type CSSSyntaxType = CSSSyntax;
49
55
 
50
- export interface ICSSType<+T: string | number> {
51
- +value: ValueWithDefault<T>;
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 CSSType
58
- implements ICSSType<T>
72
+ extends BaseCSSType
73
+ implements CSSType<T>
59
74
  {
60
- +value: ValueWithDefault<T>;
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<T>,
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 CSSType
73
- implements ICSSType<T>
86
+ extends BaseCSSType
87
+ implements CSSType<T>
74
88
  {
75
- +value: ValueWithDefault<T>;
89
+ +value: ValueWithDefault;
76
90
  +syntax: CSSSyntaxType;
77
- constructor(value: ValueWithDefault<T>): void;
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> extends CSSType implements ICSSType<T> {
87
- +value: ValueWithDefault<T>;
97
+ declare export class Url<+T: URLValue>
98
+ extends BaseCSSType
99
+ implements CSSType<T>
100
+ {
101
+ +value: ValueWithDefault;
88
102
  +syntax: CSSSyntaxType;
89
- constructor(value: ValueWithDefault<T>): void;
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 ICSSType<T>
111
+ implements CSSType<T>
99
112
  {
100
- +value: ValueWithDefault<T>;
113
+ +value: ValueWithDefault;
101
114
  +syntax: CSSSyntaxType;
102
- constructor(value: ValueWithDefault<T>): void;
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 CSSType
113
- implements ICSSType<T>
123
+ extends BaseCSSType
124
+ implements CSSType<T>
114
125
  {
115
- +value: ValueWithDefault<T>;
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<+T: LengthPercentageValue>
125
- extends CSSType
126
- implements ICSSType<string>
134
+ declare export class LengthPercentage<+_T: LengthPercentageValue>
135
+ extends BaseCSSType
136
+ implements CSSType<string>
127
137
  {
128
- +value: ValueWithDefault<T>;
138
+ +value: ValueWithDefault;
129
139
  +syntax: CSSSyntaxType;
130
- constructor(value: ValueWithDefault<T>): void;
131
- static createLength<T: LengthPercentageValue | number>(
132
- value: ValueWithDefault<T>,
140
+ static createLength<_T: LengthPercentageValue | number>(
141
+ value: ValueWithDefault,
133
142
  ): LengthPercentage<string>;
134
- static createPercentage<T: LengthPercentageValue | number>(
135
- value: ValueWithDefault<T>,
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<+T: LengthValue>
151
+ declare export class Length<+_T: LengthValue>
143
152
  extends LengthPercentage<string>
144
- implements ICSSType<string>
153
+ implements CSSType<string>
145
154
  {
146
- +value: ValueWithDefault<string>;
155
+ +value: ValueWithDefault;
147
156
  +syntax: CSSSyntaxType;
148
- constructor(value: ValueWithDefault<T>): void;
149
157
  static create<T: LengthValue = LengthValue>(
150
- value: ValueWithDefault<T>,
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<+T: PercentageValue>
165
+ declare export class Percentage<+_T: PercentageValue>
158
166
  extends LengthPercentage<string>
159
- implements ICSSType<string>
167
+ implements CSSType<string>
160
168
  {
161
- +value: ValueWithDefault<string>;
169
+ +value: ValueWithDefault;
162
170
  +syntax: CSSSyntaxType;
163
- constructor(value: ValueWithDefault<T>): void;
164
171
  static create<T: PercentageValue = PercentageValue>(
165
- value: ValueWithDefault<T>,
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 CSSType
174
- implements ICSSType<T>
180
+ extends BaseCSSType
181
+ implements CSSType<T>
175
182
  {
176
- +value: ValueWithDefault<T>;
183
+ +value: ValueWithDefault;
177
184
  +syntax: CSSSyntaxType;
178
- constructor(value: ValueWithDefault<T>): void;
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 CSSType
189
- implements ICSSType<T>
192
+ extends BaseCSSType
193
+ implements CSSType<T>
190
194
  {
191
- +value: ValueWithDefault<T>;
195
+ +value: ValueWithDefault;
192
196
  +syntax: CSSSyntaxType;
193
- constructor(value: ValueWithDefault<T>): void;
194
197
  static create<T: ResolutionValue = ResolutionValue>(
195
- value: ValueWithDefault<T>,
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 CSSType
204
- implements ICSSType<T>
206
+ extends BaseCSSType
207
+ implements CSSType<T>
205
208
  {
206
- +value: ValueWithDefault<T>;
209
+ +value: ValueWithDefault;
207
210
  +syntax: CSSSyntaxType;
208
- constructor(value: ValueWithDefault<T>): void;
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 CSSType
217
- implements ICSSType<T>
218
+ extends BaseCSSType
219
+ implements CSSType<T>
218
220
  {
219
- +value: ValueWithDefault<T>;
221
+ +value: ValueWithDefault;
220
222
  +syntax: CSSSyntaxType;
221
- constructor(value: ValueWithDefault<T>): void;
222
223
  static create<T: TransformFunctionValue = TransformFunctionValue>(
223
- value: ValueWithDefault<T>,
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 CSSType
232
- implements ICSSType<T>
232
+ extends BaseCSSType
233
+ implements CSSType<T>
233
234
  {
234
- +value: ValueWithDefault<T>;
235
+ +value: ValueWithDefault;
235
236
  +syntax: CSSSyntaxType;
236
- constructor(value: ValueWithDefault<T>): void;
237
237
  static create<T: TransformListValue = TransformListValue>(
238
- value: ValueWithDefault<T>,
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, _zeroDimensions.default, _leadingZero.default, _quotes.default, _convertCamelCaseValues.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 timings,
12
- * in which case make them consistent 0deg and 0s.
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 timings,
12
- * in which case make them consistent 0deg and 0s.
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.5.1",
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.5.1"
16
+ "@stylexjs/scripts": "0.6.0"
17
17
  },
18
18
  "jest": {
19
19
  "snapshotFormat": {