@stylexjs/stylex 0.2.0-beta.21 → 0.2.0-beta.23

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.
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # @stylexjs/stylex
2
2
 
3
- StyleX is a JavaScript library for defining styles for optimized user interfaces.
3
+ StyleX is a JavaScript library for defining styles for optimized user
4
+ interfaces.
4
5
 
5
6
  ## Installation
6
7
 
7
- To start playing with StyleX without having to set up any build settings you can install just two packages:
8
+ To start playing with StyleX without having to set up any build settings you can
9
+ install just two packages:
8
10
 
9
11
  ```sh
10
12
  npm install --save @stylexjs/stylex
@@ -12,13 +14,17 @@ npm install --save @stylexjs/stylex
12
14
 
13
15
  ### Compiler
14
16
 
15
- StyleX is designed to extract styles to a static CSS style sheet during an app's build process. StyleX provides a Babel plugin along with plugin integrations for Webpack, Rollup and NextJS.
17
+ StyleX is designed to extract styles to a static CSS style sheet during an app's
18
+ build process. StyleX provides a Babel plugin along with plugin integrations for
19
+ Webpack, Rollup and NextJS.
16
20
 
17
21
  ```sh
18
22
  npm install --save-dev @stylexjs/babel-plugin
19
23
  ```
20
24
 
21
- For more information on working with the compiler, please see the documentation for [`@stylexjs/babel-plugin`](https://www.npmjs.com/package/@stylexjs/babel-plugin).
25
+ For more information on working with the compiler, please see the documentation
26
+ for
27
+ [`@stylexjs/babel-plugin`](https://www.npmjs.com/package/@stylexjs/babel-plugin).
22
28
 
23
29
  ### Runtime compiler
24
30
 
@@ -43,13 +49,17 @@ if (process.env.NODE_ENV !== 'production') {
43
49
  }
44
50
  ```
45
51
 
46
- For more information on working with the compiler, please see the documentation for [`@stylexjs/dev-runtime`](https://www.npmjs.com/package/@stylexjs/dev-runtime).
52
+ For more information on working with the compiler, please see the documentation
53
+ for
54
+ [`@stylexjs/dev-runtime`](https://www.npmjs.com/package/@stylexjs/dev-runtime).
47
55
 
48
56
  ## API
49
57
 
50
58
  ### stylex.create()
51
59
 
52
- Styles are defined as a map of CSS rules using `stylex.create()`. In the example below, there are 2 different CSS rules. The names "root" and "highlighted" are arbitrary names given to the rules.
60
+ Styles are defined as a map of CSS rules using `stylex.create()`. In the example
61
+ below, there are 2 different CSS rules. The names "root" and "highlighted" are
62
+ arbitrary names given to the rules.
53
63
 
54
64
  ```tsx
55
65
  import stylex from '@stylexjs/stylex';
@@ -61,7 +71,7 @@ const styles = stylex.create({
61
71
  },
62
72
  highlighted: {
63
73
  color: 'yellow',
64
- }
74
+ },
65
75
  });
66
76
  ```
67
77
 
@@ -82,63 +92,74 @@ const styles = stylex.create({
82
92
  color: 'yellow',
83
93
  ':hover': {
84
94
  opacity: '0.9',
85
- }
86
- }
95
+ },
96
+ },
87
97
  });
88
98
  ```
89
99
 
90
- The compiler will extract the rules to CSS and replace the rules in the source code with a "compiled style" object.
100
+ The compiler will extract the rules to CSS and replace the rules in the source
101
+ code with a "compiled style" object.
91
102
 
92
- ### stylex.spread()
103
+ ### stylex.props()
93
104
 
94
- Applying style rules to specific elements is done using `stylex.spread`. Each argument to this function must be a reference to a compiled style object, or an array of compiled style objects. The function merges styles from left to right.
105
+ Applying style rules to specific elements is done using `stylex.props`. Each
106
+ argument to this function must be a reference to a compiled style object, or an
107
+ array of compiled style objects. The function merges styles from left to right.
95
108
 
96
109
  ```tsx
97
- <div {...stylex.spread(styles.root, styles.highlighted)} />
110
+ <div {...stylex.props(styles.root, styles.highlighted)} />
98
111
  ```
99
112
 
100
- The `stylex.spread` function returns React props as required to render an element. StyleX styles can still be passed to other components via props, but only the components rendering host platform elements will use `stylex.spread()`. For example:
113
+ The `stylex.props` function returns React props as required to render an
114
+ element. StyleX styles can still be passed to other components via props, but
115
+ only the components rendering host platform elements will use `stylex.props()`.
116
+ For example:
101
117
 
102
118
  ```tsx
103
119
  const styles = stylex.create({
104
120
  internalRoot: {
105
- padding: 10
121
+ padding: 10,
106
122
  },
107
123
  exportedRoot: {
108
- position: 'relative'
109
- }
124
+ position: 'relative',
125
+ },
110
126
  });
111
127
 
112
128
  function InternalComponent(props) {
113
- return <div {...props} {...stylex.spread([ styles.internalRoot, props.style ])} />
129
+ return (
130
+ <div {...props} {...stylex.props([styles.internalRoot, props.style])} />
131
+ );
114
132
  }
115
133
 
116
134
  export function ExportedComponent(props) {
117
- return <InternalComponent style={[ styles.exportedRoot, props.style ]} />
135
+ return <InternalComponent style={[styles.exportedRoot, props.style]} />;
118
136
  }
119
137
  ```
120
138
 
121
139
  Styles can be conditionally included using standard JavaScript.
122
140
 
123
141
  ```tsx
124
- <div {...stylex.spread(styles.root, isHighlighted && styles.highlighted)} />
142
+ <div {...stylex.props(styles.root, isHighlighted && styles.highlighted)} />
125
143
  ```
126
144
 
127
- And the local merging of styles can be used to control the relative priority of rules. For example, to allow a component's local styles to take priority over style property values passed in via props.
145
+ And the local merging of styles can be used to control the relative priority of
146
+ rules. For example, to allow a component's local styles to take priority over
147
+ style property values passed in via props.
128
148
 
129
149
  ```tsx
130
- <div {...stylex.spread(props.style, styles.root)} />
150
+ <div {...stylex.props(props.style, styles.root)} />
131
151
  ```
132
152
 
133
153
  You can even mix compiled styles with inline styles
134
154
 
135
155
  ```tsx
136
- <div {...stylex.spread(styles.root, { opacity })} />
156
+ <div {...stylex.props(styles.root, { opacity })} />
137
157
  ```
138
158
 
139
159
  ### stylex.firstThatWorks()
140
160
 
141
- Defining fallback styles is done with `stylex.firstThatWorks()`. This is useful for engines that may not support a specific style property.
161
+ Defining fallback styles is done with `stylex.firstThatWorks()`. This is useful
162
+ for engines that may not support a specific style property.
142
163
 
143
164
  ```tsx
144
165
  import stylex from '@stylexjs/stylex';
@@ -166,7 +187,8 @@ StyleX comes with full support for Static Types.
166
187
 
167
188
  ### `XStyle<>`
168
189
 
169
- The most common type you might need to use is `XStyle<>`. This lets you accept an object of arbitrary StyleX styles.
190
+ The most common type you might need to use is `XStyle<>`. This lets you accept
191
+ an object of arbitrary StyleX styles.
170
192
 
171
193
  ```tsx
172
194
  type Props = {
@@ -176,7 +198,7 @@ type Props = {
176
198
 
177
199
  function MyComponent({style, ...}: Props) {
178
200
  return (
179
- <div {...stylex.spread(localStyles.foo, localStyles.bar, style)} />
201
+ <div {...stylex.props(localStyles.foo, localStyles.bar, style)} />
180
202
  );
181
203
  }
182
204
  ```
@@ -189,34 +211,39 @@ To disallow specific style properties, use the `XStyleWithout<>` type.
189
211
  type Props = {
190
212
  // ...
191
213
  style?: XStyleWithout<{
192
- postion: unknown,
193
- display: unknown
194
- }>
214
+ postion: unknown;
215
+ display: unknown;
216
+ }>;
195
217
  };
196
218
  ```
197
219
 
198
220
  ### `XStyleValue<>`
199
221
 
200
- To accept specific style properties only, use the `XStyle<{...}>` and `XStyleValue` types. For example, to allow only color-related style props:
222
+ To accept specific style properties only, use the `XStyle<{...}>` and
223
+ `XStyleValue` types. For example, to allow only color-related style props:
201
224
 
202
225
  ```tsx
203
226
  type Props = {
204
227
  // ...
205
228
  style?: XStyle<{
206
- color?: StyleXValue,
207
- backgroundColor?: StyleXValue,
208
- borderColor?: StyleXValue,
209
- borderTopColor?: StyleXValue,
210
- borderEndColor?: StyleXValue,
211
- borderBottomColor?: StyleXValue,
212
- borderStartColor?: StyleXValue,
213
- }>,
229
+ color?: StyleXValue;
230
+ backgroundColor?: StyleXValue;
231
+ borderColor?: StyleXValue;
232
+ borderTopColor?: StyleXValue;
233
+ borderEndColor?: StyleXValue;
234
+ borderBottomColor?: StyleXValue;
235
+ borderStartColor?: StyleXValue;
236
+ }>;
214
237
  };
215
238
  ```
216
239
 
217
240
  ### `XStyleValueFor<>`
218
241
 
219
- To limit the possible values for style properties, use the `XStyleValueFor<>` type. Pass in a type argument with a union of literal types that provide the set of possible values that the style property can have. For example, if a component should accept `marginTop` but only accept one of `0`, `4`, or `8` pixels as values.
242
+ To limit the possible values for style properties, use the `XStyleValueFor<>`
243
+ type. Pass in a type argument with a union of literal types that provide the set
244
+ of possible values that the style property can have. For example, if a component
245
+ should accept `marginTop` but only accept one of `0`, `4`, or `8` pixels as
246
+ values.
220
247
 
221
248
  ```tsx
222
249
  type Props = {
@@ -229,7 +256,8 @@ type Props = {
229
256
 
230
257
  ## How StyleX works
231
258
 
232
- StyleX produces atomic styles, which means that each CSS rule contains only a single declaration and uses a unique class name. For example:
259
+ StyleX produces atomic styles, which means that each CSS rule contains only a
260
+ single declaration and uses a unique class name. For example:
233
261
 
234
262
  ```tsx
235
263
  import stylex from '@stylexjs/stylex';
@@ -242,6 +270,15 @@ const styles = stylex.create({
242
270
  }
243
271
  ```
244
272
 
245
- From this code, StyleX will generate 2 classes. One for the `width: '100%'` declaration, and one for the `color: 'red'` declaration. If you use the declaration `width: '100%'` anywhere else in your application, it will *reuse the same CSS class* rather than creating a new one.
246
-
247
- One of the benefits of this approach is that the generated CSS file grows *logarithmically* as you add new styled components to your app. As more style declarations are added to components, they are more likely to already be in use elsehwere in the app. As a result of this CSS optimization, the generated CSS style sheet for an app is usually small enough to be contained in a single file and used across routes, avoiding style recalculation and layout thrashing as users navigate through your app.
273
+ From this code, StyleX will generate 2 classes. One for the `width: '100%'`
274
+ declaration, and one for the `color: 'red'` declaration. If you use the
275
+ declaration `width: '100%'` anywhere else in your application, it will _reuse
276
+ the same CSS class_ rather than creating a new one.
277
+
278
+ One of the benefits of this approach is that the generated CSS file grows
279
+ _logarithmically_ as you add new styled components to your app. As more style
280
+ declarations are added to components, they are more likely to already be in use
281
+ elsehwere in the app. As a result of this CSS optimization, the generated CSS
282
+ style sheet for an app is usually small enough to be contained in a single file
283
+ and used across routes, avoiding style recalculation and layout thrashing as
284
+ users navigate through your app.
@@ -1 +1 @@
1
- "use strict";
1
+ 'use strict';
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.styleSheet = exports.StyleXSheet = void 0;
7
7
  var _invariant = _interopRequireDefault(require("invariant"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const LIGHT_MODE_CLASS_NAME = "__fb-light-mode";
10
- const DARK_MODE_CLASS_NAME = "__fb-dark-mode";
9
+ const LIGHT_MODE_CLASS_NAME = '__fb-light-mode';
10
+ const DARK_MODE_CLASS_NAME = '__fb-dark-mode';
11
11
  function buildTheme(selector, theme) {
12
12
  const lines = [];
13
13
  lines.push(`${selector} {`);
@@ -15,20 +15,20 @@ function buildTheme(selector, theme) {
15
15
  const value = theme[key];
16
16
  lines.push(` --${key}: ${value};`);
17
17
  }
18
- lines.push("}");
19
- return lines.join("\n");
18
+ lines.push('}');
19
+ return lines.join('\n');
20
20
  }
21
21
  function makeStyleTag() {
22
- const tag = document.createElement("style");
23
- tag.setAttribute("type", "text/css");
24
- tag.setAttribute("data-stylex", "true");
25
- const head = document.head || document.getElementsByTagName("head")[0];
26
- (0, _invariant.default)(head, "expected head");
22
+ const tag = document.createElement('style');
23
+ tag.setAttribute('type', 'text/css');
24
+ tag.setAttribute('data-stylex', 'true');
25
+ const head = document.head || document.getElementsByTagName('head')[0];
26
+ (0, _invariant.default)(head, 'expected head');
27
27
  head.appendChild(tag);
28
28
  return tag;
29
29
  }
30
30
  function doesSupportCSSVariables() {
31
- return globalThis.CSS != null && globalThis.CSS.supports != null && globalThis.CSS.supports("--fake-var:0");
31
+ return globalThis.CSS != null && globalThis.CSS.supports != null && globalThis.CSS.supports('--fake-var:0');
32
32
  }
33
33
  const VARIABLE_MATCH = /var\(--(.*?)\)/g;
34
34
  class StyleXSheet {
@@ -53,11 +53,11 @@ class StyleXSheet {
53
53
  const {
54
54
  tag
55
55
  } = this;
56
- (0, _invariant.default)(tag != null, "expected tag");
56
+ (0, _invariant.default)(tag != null, 'expected tag');
57
57
  return tag;
58
58
  }
59
59
  getCSS() {
60
- return this.rules.join("\n");
60
+ return this.rules.join('\n');
61
61
  }
62
62
  getRulePosition(rule) {
63
63
  return this.rules.indexOf(rule);
@@ -99,7 +99,7 @@ class StyleXSheet {
99
99
  }
100
100
  const tag = this.getTag();
101
101
  const sheet = tag.sheet;
102
- (0, _invariant.default)(sheet, "expected sheet");
102
+ (0, _invariant.default)(sheet, 'expected sheet');
103
103
  sheet.deleteRule(index);
104
104
  }
105
105
  normalizeRule(rule) {
@@ -156,17 +156,16 @@ class StyleXSheet {
156
156
  }
157
157
  exports.StyleXSheet = StyleXSheet;
158
158
  function addAncestorSelector(selector, ancestorSelector) {
159
- if (!selector.startsWith("@")) {
159
+ if (!selector.startsWith('@')) {
160
160
  return `${ancestorSelector} ${selector}`;
161
161
  }
162
- const firstBracketIndex = selector.indexOf("{");
162
+ const firstBracketIndex = selector.indexOf('{');
163
163
  const mediaQueryPart = selector.slice(0, firstBracketIndex + 1);
164
164
  const rest = selector.slice(firstBracketIndex + 1);
165
165
  return `${mediaQueryPart}${ancestorSelector} ${rest}`;
166
166
  }
167
- const styleSheet = new StyleXSheet({
167
+ const styleSheet = exports.styleSheet = new StyleXSheet({
168
168
  supportsVariables: true,
169
169
  rootTheme: {},
170
170
  rootDarkTheme: {}
171
- });
172
- exports.styleSheet = styleSheet;
171
+ });
@@ -15,29 +15,18 @@ export type StyleXClassNameFor<K, V> = string & {
15
15
  _value: V;
16
16
  };
17
17
 
18
- export type StyleXClassNameForValue<V> = StyleXClassNameFor<unknown, V>;
19
- export type StyleXClassNameForKey<K> = StyleXClassNameFor<K, unknown>;
20
- export type StyleXClassName = StyleXClassNameFor<unknown, unknown>;
18
+ export type StyleXClassNameForValue<V> = StyleXClassNameFor<any, V>;
19
+ export type StyleXClassNameForKey<K> = StyleXClassNameFor<K, any>;
20
+ export type StyleXClassName = StyleXClassNameFor<any, any>;
21
21
  // Type for arbitrarily nested Array.
22
22
  export type StyleXArray<T> = T | ReadonlyArray<StyleXArray<T>>;
23
23
 
24
24
  declare const StyleXVarTag: unique symbol;
25
25
  export type StyleXVar<_Val> = string & typeof StyleXVarTag;
26
26
 
27
- // prettier-ignore
28
- type NonDollarChars =
29
- | 'a' | 'A' | 'b' | 'B' | 'c' | 'C' | 'd' | 'D'
30
- | 'e' | 'E' | 'f' | 'F' | 'g' | 'G'
31
- | 'h' | 'H' | 'i' | 'I' | 'j' | 'J' | 'k' | 'K'
32
- | 'l' | 'L' | 'm' | 'M' | 'n' | 'N' | 'o' | 'O' | 'p' | 'P'
33
- | 'q' | 'Q' | 'r' | 'R' | 's' | 'S' | 't' | 'T'
34
- | 'u' | 'U' | 'v' | 'V' | 'w' | 'W'
35
- | 'x' | 'X' | 'y' | 'Y' | 'z' | 'Z'
36
- | '-' | '_' | '@' | ':';
37
-
38
27
  // Strings that don't start with a dollar sign.
39
28
  // So that we can `&` with {$$css: true} without type errors.
40
- type NonDollarStr = `${NonDollarChars}${string}`;
29
+ type string = `${NonDollarChars}${string}`;
41
30
  type PseudoClassStr = `:${string}`;
42
31
  type AtRuleStr = `@${string}`;
43
32
 
@@ -77,16 +66,12 @@ export type NestedCSSPropTypes = Partial<
77
66
  }>
78
67
  >;
79
68
 
80
- type UserAuthoredStyles = { [key: NonDollarStr]: unknown };
69
+ type UserAuthoredStyles = { [key: string]: unknown };
81
70
  export type StyleXSingleStyle = false | (null | undefined | NestedCSSPropTypes);
82
- export type XStyle<T extends UserAuthoredStyles = NestedCSSPropTypes> =
83
- StyleXArray<false | (null | undefined | Readonly<T & { $$css: true }>)>;
84
- export type XStyleWithout<T extends UserAuthoredStyles> = XStyle<
85
- Readonly<Pick<NestedCSSPropTypes, Exclude<keyof NestedCSSPropTypes, keyof T>>>
86
- >;
71
+ // NOTE: `XStyle` has been deprecated in favor of `StaticStyles` and `StyleXStyles`.
87
72
 
88
- export type Keyframes = Readonly<{ [name: NonDollarStr]: CSSProperties }>;
89
- export type LegacyTheme = Readonly<{ [constantName: NonDollarStr]: string }>;
73
+ export type Keyframes = Readonly<{ [name: string]: CSSProperties }>;
74
+ export type LegacyTheme = Readonly<{ [constantName: string]: string }>;
90
75
 
91
76
  type ComplexStyleValueType<T> = T extends string | number | null
92
77
  ? T
@@ -98,14 +83,10 @@ type ComplexStyleValueType<T> = T extends string | number | null
98
83
  ? ComplexStyleValueType<A> | ComplexStyleValueType<B>
99
84
  : T;
100
85
 
101
- type _MapNamespace<CSS> = Readonly<{
86
+ export type MapNamespace<CSS> = Readonly<{
102
87
  [Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>;
103
88
  }>;
104
89
 
105
- export type MapNamespace<CSS> = Readonly<
106
- _MapNamespace<CSS> & Readonly<{ $$css: true }>
107
- >;
108
-
109
90
  export type MapNamespaces<
110
91
  S extends {
111
92
  [key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
@@ -124,34 +105,29 @@ export type Stylex$Create = <
124
105
  styles: S,
125
106
  ) => MapNamespaces<S>;
126
107
 
127
- export type CompiledStyles = Readonly<
128
- {
129
- [key: NonDollarStr]:
130
- | StyleXClassName
131
- | Readonly<{ [key: NonDollarStr]: StyleXClassName }>;
132
- } & { $$css: true }
133
- >;
108
+ export type CompiledStyles = Readonly<{
109
+ [key: string]: StyleXClassName | null | void | never;
110
+ }>;
134
111
 
135
- export type InlineStyles = Readonly<
136
- { [key: NonDollarStr]: string } & { $$css?: void }
137
- >;
112
+ declare const StyleXInlineStylesTag: unique symbol;
113
+
114
+ export type InlineStyles = typeof StyleXInlineStylesTag;
138
115
 
139
116
  type _GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<{
140
117
  [Key in keyof CSS]: StyleXClassNameFor<Key, Readonly<CSS[Key]>>;
141
118
  }>;
142
119
  type GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<
143
- _GenStylePropType<CSS> & { $$css: true } & Partial<{
144
- [Key in Exclude<
145
- keyof CSSPropertiesWithExtras,
146
- keyof CSS | '$$css'
147
- >]: never;
120
+ _GenStylePropType<CSS> &
121
+ Partial<{
122
+ [Key in Exclude<keyof CSSPropertiesWithExtras, keyof CSS>]: never;
148
123
  }>
149
124
  >;
150
125
 
151
126
  // Replace `XStyle` with this.
152
127
  export type StaticStyles<
153
128
  CSS extends UserAuthoredStyles = CSSPropertiesWithExtras,
154
- > = StyleXArray<false | null | void | GenStylePropType<CSS>>;
129
+ > = StyleXArray<false | null | GenStylePropType<CSS>>;
130
+
155
131
  export type StaticStylesWithout<CSS extends UserAuthoredStyles> = StaticStyles<
156
132
  Omit<CSSPropertiesWithExtras, keyof CSS>
157
133
  >;
@@ -160,7 +136,6 @@ export type StyleXStyles<
160
136
  CSS extends UserAuthoredStyles = CSSPropertiesWithExtras,
161
137
  > = StyleXArray<
162
138
  | null
163
- | void
164
139
  | false
165
140
  | GenStylePropType<CSS>
166
141
  | Readonly<[GenStylePropType<CSS>, InlineStyles]>
@@ -171,26 +146,26 @@ export type StyleXStylesWithout<CSS extends UserAuthoredStyles> = StyleXStyles<
171
146
 
172
147
  declare const StyleXThemeTag: unique symbol;
173
148
  export type Theme<
174
- Tokens extends { [key: NonDollarStr]: unknown },
149
+ Tokens extends { [key: string]: unknown },
175
150
  ID extends symbol = symbol,
176
- > = Readonly<{ [_Key in keyof Tokens]: string }> & {
151
+ > = Readonly<{ [Key in keyof Tokens]: Tokens[Key] & typeof StyleXThemeTag }> & {
177
152
  $opaqueId: ID;
178
153
  $tokens: Tokens;
179
- } & typeof StyleXThemeTag;
154
+ };
180
155
 
181
156
  export type TokensFromTheme<T extends Theme<TTokens>> = T['$tokens'];
182
157
 
183
158
  export type IDFromTheme<T extends Theme<TTokens>> = T['$opaqueId'];
184
159
 
185
160
  type TTokens = {
186
- [key: NonDollarStr]: string | { default: string; [key: AtRuleStr]: string };
161
+ [key: string]: string | { default: string; [key: AtRuleStr]: string };
187
162
  };
188
163
 
189
164
  export type FlattenTokens<T extends TTokens> = Readonly<{
190
165
  [Key in keyof T]: T[Key] extends { [key: string]: infer X } ? X : T[Key];
191
166
  }>;
192
167
 
193
- export type StyleX$CreateVars = <
168
+ export type StyleX$DefineVars = <
194
169
  DefaultTokens extends TTokens,
195
170
  ID extends symbol = symbol,
196
171
  >(
@@ -212,7 +187,7 @@ type OverridesForTokenType<Config extends { [key: string]: any }> = {
212
187
  | { default: Config[Key]; [atRule: AtRuleStr]: Config[Key] };
213
188
  };
214
189
 
215
- export type StyleX$OverrideVars = <
190
+ export type StyleX$CreateTheme = <
216
191
  BaseTokens extends Theme<any>,
217
192
  ID extends symbol = symbol,
218
193
  >(
@@ -1 +1 @@
1
- "use strict";
1
+ 'use strict';
@@ -97,15 +97,15 @@ export type Keyframes = $ReadOnly<{ [name: string]: CSSProperties, ... }>;
97
97
 
98
98
  export type LegacyTheme = $ReadOnly<{ [constantName: string]: string, ... }>;
99
99
 
100
- type ComplexStyleValueType<+T> = T extends string | number | null
101
- ? T
102
- : T extends StyleXVar<infer U>
100
+ type ComplexStyleValueType<+T> = T extends StyleXVar<infer U>
103
101
  ? U
102
+ : T extends string | number | null
103
+ ? T
104
104
  : T extends $ReadOnlyArray<infer U>
105
105
  ? U
106
106
  : T extends $ReadOnly<{ default: infer A, +[string]: infer B }>
107
107
  ? ComplexStyleValueType<A> | ComplexStyleValueType<B>
108
- : T;
108
+ : $ReadOnly<T>;
109
109
 
110
110
  type _MapNamespace<+CSS: { +[string]: mixed }> = $ReadOnly<{
111
111
  [Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>,
@@ -125,10 +125,7 @@ export type Stylex$Create = <S: { +[string]: mixed }>(
125
125
 
126
126
  export type CompiledStyles = $ReadOnly<{
127
127
  $$css: true,
128
- [key: string]:
129
- | StyleXClassName
130
- | $ReadOnly<{ [key: string]: StyleXClassName, ... }>,
131
- ...
128
+ [key: string]: StyleXClassName,
132
129
  }>;
133
130
  export type InlineStyles = $ReadOnly<{
134
131
  $$css?: void,
@@ -163,21 +160,21 @@ export type StyleXStyles<+CSS: { +[string]: mixed } = CSSPropertiesWithExtras> =
163
160
  export type StyleXStylesWithout<+CSS: { +[string]: mixed }> = StyleXStyles<
164
161
  $Rest<CSSPropertiesWithExtras, $ReadOnly<CSS>>,
165
162
  >;
163
+
166
164
  // This is the type for the variables object
167
- declare export opaque type StyleXVar<+_Val: mixed>;
165
+ declare export opaque type StyleXVar<+Val: mixed>;
168
166
 
169
167
  declare export opaque type Theme<
170
168
  +Tokens: { +[string]: mixed },
171
- // eslint-disable-next-line no-unused-vars
172
- +ID: string = string,
169
+ +_ID: string = string,
173
170
  >: $ReadOnly<{ [Key in keyof Tokens]: StyleXVar<Tokens[Key]> }>;
174
171
 
175
172
  export type TokensFromTheme<T: Theme<{ +[string]: mixed }>> = T extends Theme<
176
- infer Tokens,
173
+ infer Tokens extends { +[string]: mixed },
177
174
  >
178
175
  ? Tokens
179
176
  : empty;
180
- type IDFromTheme<T: Theme<{ +[string]: mixed }>> = T extends Theme<
177
+ type IDFromTheme<+T: Theme<{ +[string]: mixed }>> = T extends Theme<
181
178
  { +[string]: mixed },
182
179
  infer ID,
183
180
  >
@@ -185,7 +182,10 @@ type IDFromTheme<T: Theme<{ +[string]: mixed }>> = T extends Theme<
185
182
  : empty;
186
183
 
187
184
  type TTokens = $ReadOnly<{
188
- [string]: string | $ReadOnly<{ default: string, [string]: string }>,
185
+ [string]:
186
+ | number
187
+ | string
188
+ | $ReadOnly<{ default: number | string, [string]: number | string }>,
189
189
  }>;
190
190
 
191
191
  export type FlattenTokens<T: TTokens> = {
@@ -194,7 +194,7 @@ export type FlattenTokens<T: TTokens> = {
194
194
  : T[Key],
195
195
  };
196
196
 
197
- export type StyleX$CreateVars = <DefaultTokens: TTokens, ID: string = string>(
197
+ export type StyleX$DefineVars = <DefaultTokens: TTokens, ID: string = string>(
198
198
  tokens: DefaultTokens,
199
199
  ) => Theme<FlattenTokens<DefaultTokens>, ID>;
200
200
 
@@ -212,7 +212,7 @@ export type OverridesForTokenType<Config: { +[string]: mixed }> = {
212
212
  | { +default: Config[Key], +[string]: Config[Key] },
213
213
  };
214
214
 
215
- export type StyleX$OverrideVars = <
215
+ export type StyleX$CreateTheme = <
216
216
  BaseTokens: Theme<{ +[string]: mixed }>,
217
217
  ID: string = string,
218
218
  >(
@@ -10,7 +10,7 @@ function camelize(s) {
10
10
  return s.replace(/-./g, x => x.toUpperCase()[1]);
11
11
  }
12
12
  function createCSSCustomPropertyValue(value) {
13
- if (typeof value === "string") {
13
+ if (typeof value === 'string') {
14
14
  const match = CUSTOM_PROPERTY_REGEX.exec(value);
15
15
  if (match) {
16
16
  return new CSSCustomPropertyValue(match[1], match[2]);
@@ -30,7 +30,7 @@ class CSSLengthUnitValue {
30
30
  const value = this.value;
31
31
  const valuePercent = value / 100;
32
32
  switch (unit) {
33
- case "em":
33
+ case 'em':
34
34
  {
35
35
  if (inheritedFontSize == null) {
36
36
  return fontScale * 16 * value;
@@ -38,27 +38,27 @@ class CSSLengthUnitValue {
38
38
  return inheritedFontSize * value;
39
39
  }
40
40
  }
41
- case "px":
41
+ case 'px':
42
42
  {
43
43
  return value;
44
44
  }
45
- case "rem":
45
+ case 'rem':
46
46
  {
47
47
  return fontScale * 16 * value;
48
48
  }
49
- case "vh":
49
+ case 'vh':
50
50
  {
51
51
  return viewportHeight * valuePercent;
52
52
  }
53
- case "vmin":
53
+ case 'vmin':
54
54
  {
55
55
  return Math.min(viewportWidth, viewportHeight) * valuePercent;
56
56
  }
57
- case "vmax":
57
+ case 'vmax':
58
58
  {
59
59
  return Math.max(viewportWidth, viewportHeight) * valuePercent;
60
60
  }
61
- case "vw":
61
+ case 'vw':
62
62
  {
63
63
  return viewportWidth * valuePercent;
64
64
  }