@stylexjs/stylex 0.8.0 → 0.9.0-beta.1

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.
@@ -111,7 +111,7 @@ type backdropFilter = 'none' | string;
111
111
  type backfaceVisibility = 'visible' | 'hidden';
112
112
  type backgroundAttachment = attachment;
113
113
  type backgroundBlendMode = blendMode;
114
- type backgroundClip = box;
114
+ type backgroundClip = box | 'text';
115
115
  type backgroundColor = color;
116
116
  type backgroundImage = bgImage;
117
117
  type backgroundOrigin = box;
@@ -246,6 +246,7 @@ type display =
246
246
  | 'inherit'
247
247
  | 'inline'
248
248
  | 'block'
249
+ | 'flow-root'
249
250
  | 'list-item'
250
251
  | 'inline-list-item'
251
252
  | 'inline-block'
@@ -536,7 +537,7 @@ type outlineStyle = 'auto' | brStyle;
536
537
  type outlineWidth = borderWidth;
537
538
  type overflow = 'visible' | 'hidden' | 'clip' | 'scroll' | 'auto';
538
539
  type overflowAnchor = 'auto' | 'none';
539
- type overflowWrap = 'normal' | 'break-word';
540
+ type overflowWrap = 'normal' | 'break-word' | 'anywhere';
540
541
  type overflowX = overflow;
541
542
  type overflowY = overflow;
542
543
  type overscrollBehavior = 'none' | 'contain' | 'auto';
@@ -575,7 +576,23 @@ type rubyMerge = 'separate' | 'collapse' | 'auto';
575
576
  type rubyPosition = 'over' | 'under' | 'inter-character';
576
577
  type scrollBehavior = 'auto' | 'smooth';
577
578
  type scrollSnapAlign = 'none' | 'start' | 'end' | 'center';
578
- type scrollSnapType = 'none' | 'x mandatory' | 'y mandatory';
579
+ type scrollSnapType =
580
+ | 'none'
581
+ | 'block mandatory'
582
+ | 'block proximity'
583
+ | 'block'
584
+ | 'both mandatory'
585
+ | 'both proximity'
586
+ | 'both'
587
+ | 'inline mandatory'
588
+ | 'inline proximity'
589
+ | 'inline'
590
+ | 'x'
591
+ | 'x mandatory'
592
+ | 'x proximity'
593
+ | 'y'
594
+ | 'y mandatory'
595
+ | 'y proximity';
579
596
  type shapeImageThreshold = number | string;
580
597
  type shapeMargin = lengthPercentage;
581
598
  type shapeOutside = 'none' | shapeBox | string;
@@ -1078,8 +1095,8 @@ export type CSSProperties = Readonly<{
1078
1095
  containIntrinsicSize?: all | number | string;
1079
1096
  containIntrinsicBlockSize?: all | number | string;
1080
1097
  containIntrinsicInlineSize?: all | number | string;
1081
- containIntrinsicHeightSize?: all | number | string;
1082
- containIntrinsicWidthSize?: all | number | string;
1098
+ containIntrinsicHeight?: all | number | string;
1099
+ containIntrinsicWidth?: all | number | string;
1083
1100
  container?: all | string;
1084
1101
  containerName?: all | string;
1085
1102
  containerType?: all | 'size' | 'inline-size' | 'normal';
@@ -113,7 +113,7 @@ type backfaceVisibility = 'visible' | 'hidden';
113
113
  // type background = string | finalBgLayer;
114
114
  type backgroundAttachment = attachment;
115
115
  type backgroundBlendMode = blendMode;
116
- type backgroundClip = box;
116
+ type backgroundClip = box | 'text';
117
117
  type backgroundColor = color;
118
118
  type backgroundImage = bgImage;
119
119
  type backgroundOrigin = box;
@@ -248,6 +248,7 @@ type display =
248
248
  | 'inherit'
249
249
  | 'inline'
250
250
  | 'block'
251
+ | 'flow-root'
251
252
  | 'list-item'
252
253
  | 'inline-list-item'
253
254
  | 'inline-block'
@@ -542,7 +543,7 @@ type outlineStyle = 'auto' | brStyle;
542
543
  type outlineWidth = borderWidth;
543
544
  type overflow = 'visible' | 'hidden' | 'clip' | 'scroll' | 'auto';
544
545
  type overflowAnchor = 'auto' | 'none';
545
- type overflowWrap = 'normal' | 'break-word';
546
+ type overflowWrap = 'normal' | 'break-word' | 'anywhere';
546
547
  type overflowX = overflow;
547
548
  type overflowY = overflow;
548
549
  type overscrollBehavior = 'none' | 'contain' | 'auto';
@@ -581,7 +582,23 @@ type rubyMerge = 'separate' | 'collapse' | 'auto';
581
582
  type rubyPosition = 'over' | 'under' | 'inter-character';
582
583
  type scrollBehavior = 'auto' | 'smooth';
583
584
  type scrollSnapAlign = 'none' | 'start' | 'end' | 'center';
584
- type scrollSnapType = 'none' | 'x mandatory' | 'y mandatory';
585
+ type scrollSnapType =
586
+ | 'none'
587
+ | 'block mandatory'
588
+ | 'block proximity'
589
+ | 'block'
590
+ | 'both mandatory'
591
+ | 'both proximity'
592
+ | 'both'
593
+ | 'inline mandatory'
594
+ | 'inline proximity'
595
+ | 'inline'
596
+ | 'x'
597
+ | 'x mandatory'
598
+ | 'x proximity'
599
+ | 'y'
600
+ | 'y mandatory'
601
+ | 'y proximity';
585
602
  type shapeImageThreshold = number | string;
586
603
  type shapeMargin = lengthPercentage;
587
604
  type shapeOutside = 'none' | shapeBox | string;
@@ -1117,8 +1134,8 @@ export type CSSProperties = $ReadOnly<{
1117
1134
  containIntrinsicSize?: all | number | string,
1118
1135
  containIntrinsicBlockSize?: all | number | string,
1119
1136
  containIntrinsicInlineSize?: all | number | string,
1120
- containIntrinsicHeightSize?: all | number | string,
1121
- containIntrinsicWidthSize?: all | number | string,
1137
+ containIntrinsicHeight?: all | number | string,
1138
+ containIntrinsicWidth?: all | number | string,
1122
1139
 
1123
1140
  container?: all | string,
1124
1141
  containerName?: all | string,
@@ -0,0 +1,11 @@
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
+ export declare type StyleXVar<_Val extends unknown> = string;
11
+ export declare type StyleXClassNameFor<_K, _V> = string;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,16 @@
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
+ // declare class Var<+T> {
11
+ // value: T;
12
+ // }
13
+ // This is the type for the variables object
14
+ declare export opaque type StyleXVar<+_Val: mixed>: string;
15
+
16
+ declare export opaque type StyleXClassNameFor<+_K, +_V>: string;
@@ -15,13 +15,6 @@ export type StyleXClassNameFor<K, V> = string & {
15
15
  _key: K;
16
16
  _value: V;
17
17
  };
18
-
19
- export type StyleXClassNameForValue<V> = StyleXClassNameFor<any, V>;
20
- export type StyleXClassNameForKey<K> = StyleXClassNameFor<K, any>;
21
- export type StyleXClassName = StyleXClassNameFor<any, any>;
22
- // Type for arbitrarily nested Array.
23
- export type StyleXArray<T> = T | ReadonlyArray<StyleXArray<T>>;
24
-
25
18
  declare const StyleXVarTag: unique symbol;
26
19
  declare class _StyleXVar<out Val> {
27
20
  private _opaque: typeof StyleXVarTag;
@@ -29,6 +22,12 @@ declare class _StyleXVar<out Val> {
29
22
  }
30
23
  export type StyleXVar<Val> = _StyleXVar<Val> & string;
31
24
 
25
+ export type StyleXClassNameForValue<V> = StyleXClassNameFor<any, V>;
26
+ export type StyleXClassNameForKey<K> = StyleXClassNameFor<K, any>;
27
+ export type StyleXClassName = StyleXClassNameFor<any, any>;
28
+ // Type for arbitrarily nested Array.
29
+ export type StyleXArray<T> = T | ReadonlyArray<StyleXArray<T>>;
30
+
32
31
  type PseudoClassStr = `:${string}`;
33
32
  type AtRuleStr = `@${string}`;
34
33
 
@@ -67,6 +66,13 @@ type CSSPropertiesWithExtras = Partial<
67
66
  '::-webkit-search-cancel-button'?: CSSProperties;
68
67
  '::-webkit-search-results-button'?: CSSProperties;
69
68
  '::-webkit-search-results-decoration'?: CSSProperties;
69
+ // For input ranges in Chromium
70
+ '::-webkit-slider-thumb'?: CSSProperties;
71
+ '::-webkit-slider-runnable-track'?: CSSProperties;
72
+ // For input ranges in Firefox
73
+ '::-moz-range-thumb'?: CSSProperties;
74
+ '::-moz-range-track'?: CSSProperties;
75
+ '::-moz-range-progress'?: CSSProperties;
70
76
  }
71
77
  >
72
78
  >;
@@ -93,7 +99,7 @@ type ComplexStyleValueType<T> =
93
99
  : T extends string | number | null
94
100
  ? T
95
101
  : T extends ReadonlyArray<infer U>
96
- ? U
102
+ ? ComplexStyleValueType<U>
97
103
  : T extends Readonly<{ default: infer A; [cond: CondStr]: infer B }>
98
104
  ? ComplexStyleValueType<A> | ComplexStyleValueType<B>
99
105
  : T;
@@ -177,8 +183,7 @@ export type VarGroup<
177
183
  }> &
178
184
  typeof StyleXVarGroupTag;
179
185
 
180
- export type TokensFromVarGroup<T extends VarGroup<unknown, unknown>> =
181
- T['__tokens'];
186
+ export type TokensFromVarGroup<T extends VarGroup<{}>> = T['__tokens'];
182
187
 
183
188
  export type IDFromVarGroup<T extends VarGroup<unknown, unknown>> =
184
189
  T['__opaqueId'];
@@ -194,6 +199,13 @@ export type FlattenTokens<T extends TTokens> = Readonly<{
194
199
  : UnwrapVars<T[Key]>;
195
200
  }>;
196
201
 
202
+ type NestedVarObject<T> =
203
+ | T
204
+ | Readonly<{
205
+ default: NestedVarObject<T>;
206
+ [key: `@${string}`]: NestedVarObject<T>;
207
+ }>;
208
+
197
209
  export type StyleX$DefineVars = <
198
210
  DefaultTokens extends TTokens,
199
211
  ID extends symbol = symbol,
@@ -213,9 +225,7 @@ export type Theme<
213
225
  }>;
214
226
 
215
227
  type OverridesForTokenType<Config extends { [key: string]: unknown }> = {
216
- [Key in keyof Config]?:
217
- | Config[Key]
218
- | { default: Config[Key]; [atRule: AtRuleStr]: Config[Key] };
228
+ [Key in keyof Config]?: NestedVarObject<Config[Key]>;
219
229
  };
220
230
 
221
231
  export type StyleX$CreateTheme = <
@@ -7,11 +7,13 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { CSSType } from './VarTypes';
11
10
  import type { CSSProperties } from './StyleXCSSTypes';
11
+ import type { StyleXClassNameFor, StyleXVar } from './StyleXOpaqueTypes';
12
+ import type { CSSType } from './VarTypes';
13
+
14
+ export type { StyleXClassNameFor, StyleXVar } from './StyleXOpaqueTypes';
12
15
 
13
16
  // Using an opaque type to declare ClassNames generated by stylex.
14
- declare export opaque type StyleXClassNameFor<+_K, +_V>: string;
15
17
  export type StyleXClassNameForValue<+V> = StyleXClassNameFor<mixed, V>;
16
18
  export type StyleXClassNameForKey<+K> = StyleXClassNameFor<K, mixed>;
17
19
  export type StyleXClassName = StyleXClassNameFor<mixed, mixed>;
@@ -68,8 +70,8 @@ type ComplexStyleValueType<+T> =
68
70
  : T extends string | number | null
69
71
  ? T
70
72
  : T extends $ReadOnlyArray<infer U>
71
- ? U
72
- : T extends $ReadOnly<{ default: infer A, +[string]: infer B }>
73
+ ? ComplexStyleValueType<U>
74
+ : T extends { +default: infer A, +[string]: infer B }
73
75
  ? ComplexStyleValueType<A> | ComplexStyleValueType<B>
74
76
  : $ReadOnly<T>;
75
77
 
@@ -127,18 +129,12 @@ export type StyleXStylesWithout<+CSS: { +[string]: mixed }> = StyleXStyles<
127
129
  $Rest<CSSPropertiesWithExtras, $ReadOnly<CSS>>,
128
130
  >;
129
131
 
130
- // This is the type for the variables object
131
- declare export opaque type StyleXVar<+Val: mixed>;
132
-
133
- export type VarGroup<
134
- +Tokens: { +[string]: mixed },
135
- +_ID: string = string,
136
- > = $ReadOnly<{
137
- [Key in keyof Tokens]: StyleXVar<Tokens[Key]>,
138
- }>;
132
+ export type VarGroup<+Tokens: { +[string]: mixed }, +_ID: string = string> = {
133
+ +[Key in keyof Tokens]: StyleXVar<Tokens[Key]>,
134
+ };
139
135
 
140
- export type TokensFromVarGroup<T: VarGroup<{ +[string]: mixed }>> = $ReadOnly<{
141
- [Key in keyof T]: T[Key] extends StyleXVar<infer U> ? U : empty,
136
+ export type TokensFromVarGroup<+T: VarGroup<{ +[string]: mixed }>> = $ReadOnly<{
137
+ [Key in keyof T]: UnwrapVar<T[Key]>,
142
138
  }>;
143
139
 
144
140
  type IDFromVarGroup<+T: VarGroup<{ +[string]: mixed }>> =
@@ -153,18 +149,18 @@ type NestedVarObject<+T> =
153
149
 
154
150
  type TTokens = $ReadOnly<{
155
151
  [string]:
156
- | NestedVarObject<string | number>
157
- | StyleXVar<string | number>
158
- | CSSType<string | number>,
152
+ | NestedVarObject<null | string | number>
153
+ | StyleXVar<null | string | number>
154
+ | CSSType<null | string | number>,
159
155
  }>;
160
156
 
161
- type UnwrapVars<T> = T extends StyleXVar<infer U> ? U : T;
162
- export type FlattenTokens<T: TTokens> = {
157
+ type UnwrapVar<+T> = T extends StyleXVar<infer U> ? U : T;
158
+ export type FlattenTokens<+T: TTokens> = {
163
159
  +[Key in keyof T]: T[Key] extends CSSType<string | number>
164
- ? UnwrapVars<T[Key]>
160
+ ? UnwrapVar<T[Key]>
165
161
  : T[Key] extends { +default: infer X, +[string]: infer Y }
166
- ? UnwrapVars<X | Y>
167
- : UnwrapVars<T[Key]>,
162
+ ? UnwrapVar<X | Y>
163
+ : UnwrapVar<T[Key]>,
168
164
  };
169
165
 
170
166
  export type StyleX$DefineVars = <DefaultTokens: TTokens, ID: string = string>(
@@ -177,13 +173,11 @@ declare export opaque type Theme<
177
173
  +_Tag: string = string,
178
174
  >: $ReadOnly<{
179
175
  $$css: true,
180
- [string]: StyleXClassNameFor<string, IDFromVarGroup<T>>,
176
+ theme: StyleXClassNameFor<'theme', IDFromVarGroup<T>>,
181
177
  }>;
182
178
 
183
- export type OverridesForTokenType<Config: { +[string]: mixed }> = {
184
- [Key in keyof Config]?:
185
- | Config[Key]
186
- | { +default: Config[Key], +[string]: Config[Key] },
179
+ export type OverridesForTokenType<+Config: { +[string]: mixed }> = {
180
+ [Key in keyof Config]?: NestedVarObject<Config[Key]>,
187
181
  };
188
182
 
189
183
  export type StyleX$CreateTheme = <
package/lib/VarTypes.d.ts CHANGED
@@ -92,7 +92,7 @@ export declare class TransformList<T extends string> implements ICSSType<T> {
92
92
  readonly value: ValueWithDefault<string>;
93
93
  readonly syntax: CSSSyntaxType;
94
94
  }
95
- export type CSSType<T extends string | number> =
95
+ export type CSSType<T extends null | string | number> =
96
96
  | Angle<T>
97
97
  | Color<T>
98
98
  | Url<T>
@@ -93,7 +93,7 @@ declare export class TransformList<+T: string> implements ICSSType<T> {
93
93
  +syntax: CSSSyntaxType;
94
94
  }
95
95
 
96
- export type CSSType<+T: string | number> =
96
+ export type CSSType<+T: null | string | number> =
97
97
  | Angle<T>
98
98
  | Color<T>
99
99
  | Url<T>
File without changes
@@ -9,50 +9,60 @@ function getDefaultExportFromCjs (x) {
9
9
  * LICENSE file in the root directory of this source tree.
10
10
  */
11
11
 
12
- /**
13
- * Use invariant() to assert state which your program assumes to be true.
14
- *
15
- * Provide sprintf-style format (only %s is supported) and arguments
16
- * to provide information about what broke and what you were
17
- * expecting.
18
- *
19
- * The invariant message will be stripped in production, but the invariant
20
- * will remain to ensure logic does not differ in production.
21
- */
12
+ var invariant_1;
13
+ var hasRequiredInvariant;
22
14
 
23
- var NODE_ENV = process.env.NODE_ENV;
15
+ function requireInvariant () {
16
+ if (hasRequiredInvariant) return invariant_1;
17
+ hasRequiredInvariant = 1;
24
18
 
25
- var invariant = function(condition, format, a, b, c, d, e, f) {
26
- if (NODE_ENV !== 'production') {
27
- if (format === undefined) {
28
- throw new Error('invariant requires an error message argument');
29
- }
30
- }
19
+ /**
20
+ * Use invariant() to assert state which your program assumes to be true.
21
+ *
22
+ * Provide sprintf-style format (only %s is supported) and arguments
23
+ * to provide information about what broke and what you were
24
+ * expecting.
25
+ *
26
+ * The invariant message will be stripped in production, but the invariant
27
+ * will remain to ensure logic does not differ in production.
28
+ */
31
29
 
32
- if (!condition) {
33
- var error;
34
- if (format === undefined) {
35
- error = new Error(
36
- 'Minified exception occurred; use the non-minified dev environment ' +
37
- 'for the full error message and additional helpful warnings.'
38
- );
39
- } else {
40
- var args = [a, b, c, d, e, f];
41
- var argIndex = 0;
42
- error = new Error(
43
- format.replace(/%s/g, function() { return args[argIndex++]; })
44
- );
45
- error.name = 'Invariant Violation';
46
- }
30
+ var NODE_ENV = process.env.NODE_ENV;
47
31
 
48
- error.framesToPop = 1; // we don't care about invariant's own frame
49
- throw error;
50
- }
51
- };
32
+ var invariant = function(condition, format, a, b, c, d, e, f) {
33
+ if (NODE_ENV !== 'production') {
34
+ if (format === undefined) {
35
+ throw new Error('invariant requires an error message argument');
36
+ }
37
+ }
38
+
39
+ if (!condition) {
40
+ var error;
41
+ if (format === undefined) {
42
+ error = new Error(
43
+ 'Minified exception occurred; use the non-minified dev environment ' +
44
+ 'for the full error message and additional helpful warnings.'
45
+ );
46
+ } else {
47
+ var args = [a, b, c, d, e, f];
48
+ var argIndex = 0;
49
+ error = new Error(
50
+ format.replace(/%s/g, function() { return args[argIndex++]; })
51
+ );
52
+ error.name = 'Invariant Violation';
53
+ }
52
54
 
53
- var invariant_1 = invariant;
55
+ error.framesToPop = 1; // we don't care about invariant's own frame
56
+ throw error;
57
+ }
58
+ };
59
+
60
+ invariant_1 = invariant;
61
+ return invariant_1;
62
+ }
54
63
 
55
- var invariant$1 = /*@__PURE__*/getDefaultExportFromCjs(invariant_1);
64
+ var invariantExports = requireInvariant();
65
+ var invariant = /*@__PURE__*/getDefaultExportFromCjs(invariantExports);
56
66
 
57
67
  const LIGHT_MODE_CLASS_NAME = '__fb-light-mode';
58
68
  const DARK_MODE_CLASS_NAME = '__fb-dark-mode';
@@ -71,7 +81,7 @@ function makeStyleTag() {
71
81
  tag.setAttribute('type', 'text/css');
72
82
  tag.setAttribute('data-stylex', 'true');
73
83
  const head = document.head || document.getElementsByTagName('head')[0];
74
- invariant$1(head, 'expected head');
84
+ invariant(head, 'expected head');
75
85
  head.appendChild(tag);
76
86
  return tag;
77
87
  }
@@ -101,7 +111,7 @@ class StyleXSheet {
101
111
  const {
102
112
  tag
103
113
  } = this;
104
- invariant$1(tag != null, 'expected tag');
114
+ invariant(tag != null, 'expected tag');
105
115
  return tag;
106
116
  }
107
117
  getCSS() {
@@ -140,14 +150,14 @@ class StyleXSheet {
140
150
  }
141
151
  delete(rule) {
142
152
  const index = this.rules.indexOf(rule);
143
- invariant$1(index >= 0, "Couldn't find the index for rule %s", rule);
153
+ invariant(index >= 0, "Couldn't find the index for rule %s", rule);
144
154
  this.rules.splice(index, 1);
145
155
  if (this.isHeadless()) {
146
156
  return;
147
157
  }
148
158
  const tag = this.getTag();
149
159
  const sheet = tag.sheet;
150
- invariant$1(sheet, 'expected sheet');
160
+ invariant(sheet, 'expected sheet');
151
161
  sheet.deleteRule(index);
152
162
  }
153
163
  normalizeRule(rule) {
package/lib/es/stylex.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var styleq$1 = {};
1
+ var styleq = {};
2
2
 
3
3
  /**
4
4
  * Copyright (c) Nicolas Gallagher
@@ -9,179 +9,185 @@ var styleq$1 = {};
9
9
  *
10
10
  */
11
11
 
12
- Object.defineProperty(styleq$1, "__esModule", {
13
- value: true
14
- });
15
- var styleq_2 = styleq$1.styleq = void 0;
16
- var cache = new WeakMap();
17
- var compiledKey = '$$css';
18
-
19
- function createStyleq(options) {
20
- var disableCache;
21
- var disableMix;
22
- var transform;
23
-
24
- if (options != null) {
25
- disableCache = options.disableCache === true;
26
- disableMix = options.disableMix === true;
27
- transform = options.transform;
28
- }
29
-
30
- return function styleq() {
31
- // Keep track of property commits to the className
32
- var definedProperties = []; // The className and inline style to build up
33
-
34
- var className = '';
35
- var inlineStyle = null; // The current position in the cache graph
36
-
37
- var nextCache = disableCache ? null : cache; // This way of creating an array from arguments is fastest
38
-
39
- var styles = new Array(arguments.length);
40
-
41
- for (var i = 0; i < arguments.length; i++) {
42
- styles[i] = arguments[i];
43
- } // Iterate over styles from last to first
44
-
45
-
46
- while (styles.length > 0) {
47
- var possibleStyle = styles.pop(); // Skip empty items
48
-
49
- if (possibleStyle == null || possibleStyle === false) {
50
- continue;
51
- } // Push nested styles back onto the stack to be processed
52
-
53
-
54
- if (Array.isArray(possibleStyle)) {
55
- for (var _i = 0; _i < possibleStyle.length; _i++) {
56
- styles.push(possibleStyle[_i]);
57
- }
58
-
59
- continue;
60
- } // Process an individual style object
61
-
12
+ var hasRequiredStyleq;
62
13
 
63
- var style = transform != null ? transform(possibleStyle) : possibleStyle;
14
+ function requireStyleq () {
15
+ if (hasRequiredStyleq) return styleq;
16
+ hasRequiredStyleq = 1;
64
17
 
65
- if (style.$$css) {
66
- // Build up the class names defined by this object
67
- var classNameChunk = ''; // Check the cache to see if we've already done this work
18
+ Object.defineProperty(styleq, "__esModule", {
19
+ value: true
20
+ });
21
+ styleq.styleq = void 0;
22
+ var cache = new WeakMap();
23
+ var compiledKey = '$$css';
68
24
 
69
- if (nextCache != null && nextCache.has(style)) {
70
- // Cache: read
71
- var cacheEntry = nextCache.get(style);
25
+ function createStyleq(options) {
26
+ var disableCache;
27
+ var disableMix;
28
+ var transform;
72
29
 
73
- if (cacheEntry != null) {
74
- classNameChunk = cacheEntry[0]; // $FlowIgnore
30
+ if (options != null) {
31
+ disableCache = options.disableCache === true;
32
+ disableMix = options.disableMix === true;
33
+ transform = options.transform;
34
+ }
75
35
 
76
- definedProperties.push.apply(definedProperties, cacheEntry[1]);
77
- nextCache = cacheEntry[2];
78
- }
79
- } // Update the chunks with data from this object
80
- else {
81
- // The properties defined by this object
82
- var definedPropertiesChunk = [];
36
+ return function styleq() {
37
+ // Keep track of property commits to the className
38
+ var definedProperties = []; // The className and inline style to build up
83
39
 
84
- for (var prop in style) {
85
- var value = style[prop];
86
- if (prop === compiledKey) continue; // Each property value is used as an HTML class name
87
- // { 'debug.string': 'debug.string', opacity: 's-jskmnoqp' }
40
+ var className = '';
41
+ var inlineStyle = null; // The current position in the cache graph
88
42
 
89
- if (typeof value === 'string' || value === null) {
90
- // Only add to chunks if this property hasn't already been seen
91
- if (!definedProperties.includes(prop)) {
92
- definedProperties.push(prop);
43
+ var nextCache = disableCache ? null : cache; // This way of creating an array from arguments is fastest
93
44
 
94
- if (nextCache != null) {
95
- definedPropertiesChunk.push(prop);
96
- }
45
+ var styles = new Array(arguments.length);
46
+
47
+ for (var i = 0; i < arguments.length; i++) {
48
+ styles[i] = arguments[i];
49
+ } // Iterate over styles from last to first
50
+
51
+
52
+ while (styles.length > 0) {
53
+ var possibleStyle = styles.pop(); // Skip empty items
54
+
55
+ if (possibleStyle == null || possibleStyle === false) {
56
+ continue;
57
+ } // Push nested styles back onto the stack to be processed
97
58
 
98
- if (typeof value === 'string') {
99
- classNameChunk += classNameChunk ? ' ' + value : value;
100
- }
101
- }
102
- } // If we encounter a value that isn't a string or `null`
103
- else {
104
- console.error("styleq: ".concat(prop, " typeof ").concat(String(value), " is not \"string\" or \"null\"."));
105
- }
106
- } // Cache: write
107
59
 
60
+ if (Array.isArray(possibleStyle)) {
61
+ for (var _i = 0; _i < possibleStyle.length; _i++) {
62
+ styles.push(possibleStyle[_i]);
63
+ }
108
64
 
109
- if (nextCache != null) {
110
- // Create the next WeakMap for this sequence of styles
111
- var weakMap = new WeakMap();
112
- nextCache.set(style, [classNameChunk, definedPropertiesChunk, weakMap]);
113
- nextCache = weakMap;
114
- }
115
- } // Order of classes in chunks matches property-iteration order of style
116
- // object. Order of chunks matches passed order of styles from first to
117
- // last (which we iterate over in reverse).
118
-
119
-
120
- if (classNameChunk) {
121
- className = className ? classNameChunk + ' ' + className : classNameChunk;
122
- }
123
- } // ----- DYNAMIC: Process inline style object -----
124
- else {
125
- if (disableMix) {
126
- if (inlineStyle == null) {
127
- inlineStyle = {};
128
- }
129
-
130
- inlineStyle = Object.assign({}, style, inlineStyle);
131
- } else {
132
- var subStyle = null;
133
-
134
- for (var _prop in style) {
135
- var _value = style[_prop];
136
-
137
- if (_value !== undefined) {
138
- if (!definedProperties.includes(_prop)) {
139
- if (_value != null) {
140
- if (inlineStyle == null) {
141
- inlineStyle = {};
142
- }
143
-
144
- if (subStyle == null) {
145
- subStyle = {};
146
- }
147
-
148
- subStyle[_prop] = _value;
149
- }
150
-
151
- definedProperties.push(_prop); // Cache is unnecessary overhead if results can't be reused.
152
-
153
- nextCache = null;
154
- }
155
- }
156
- }
157
-
158
- if (subStyle != null) {
159
- inlineStyle = Object.assign(subStyle, inlineStyle);
160
- }
161
- }
162
- }
163
- }
164
-
165
- var styleProps = [className, inlineStyle];
166
- return styleProps;
167
- };
65
+ continue;
66
+ } // Process an individual style object
67
+
68
+
69
+ var style = transform != null ? transform(possibleStyle) : possibleStyle;
70
+
71
+ if (style.$$css) {
72
+ // Build up the class names defined by this object
73
+ var classNameChunk = ''; // Check the cache to see if we've already done this work
74
+
75
+ if (nextCache != null && nextCache.has(style)) {
76
+ // Cache: read
77
+ var cacheEntry = nextCache.get(style);
78
+
79
+ if (cacheEntry != null) {
80
+ classNameChunk = cacheEntry[0]; // $FlowIgnore
81
+
82
+ definedProperties.push.apply(definedProperties, cacheEntry[1]);
83
+ nextCache = cacheEntry[2];
84
+ }
85
+ } // Update the chunks with data from this object
86
+ else {
87
+ // The properties defined by this object
88
+ var definedPropertiesChunk = [];
89
+
90
+ for (var prop in style) {
91
+ var value = style[prop];
92
+ if (prop === compiledKey) continue; // Each property value is used as an HTML class name
93
+ // { 'debug.string': 'debug.string', opacity: 's-jskmnoqp' }
94
+
95
+ if (typeof value === 'string' || value === null) {
96
+ // Only add to chunks if this property hasn't already been seen
97
+ if (!definedProperties.includes(prop)) {
98
+ definedProperties.push(prop);
99
+
100
+ if (nextCache != null) {
101
+ definedPropertiesChunk.push(prop);
102
+ }
103
+
104
+ if (typeof value === 'string') {
105
+ classNameChunk += classNameChunk ? ' ' + value : value;
106
+ }
107
+ }
108
+ } // If we encounter a value that isn't a string or `null`
109
+ else {
110
+ console.error("styleq: ".concat(prop, " typeof ").concat(String(value), " is not \"string\" or \"null\"."));
111
+ }
112
+ } // Cache: write
113
+
114
+
115
+ if (nextCache != null) {
116
+ // Create the next WeakMap for this sequence of styles
117
+ var weakMap = new WeakMap();
118
+ nextCache.set(style, [classNameChunk, definedPropertiesChunk, weakMap]);
119
+ nextCache = weakMap;
120
+ }
121
+ } // Order of classes in chunks matches property-iteration order of style
122
+ // object. Order of chunks matches passed order of styles from first to
123
+ // last (which we iterate over in reverse).
124
+
125
+
126
+ if (classNameChunk) {
127
+ className = className ? classNameChunk + ' ' + className : classNameChunk;
128
+ }
129
+ } // ----- DYNAMIC: Process inline style object -----
130
+ else {
131
+ if (disableMix) {
132
+ if (inlineStyle == null) {
133
+ inlineStyle = {};
134
+ }
135
+
136
+ inlineStyle = Object.assign({}, style, inlineStyle);
137
+ } else {
138
+ var subStyle = null;
139
+
140
+ for (var _prop in style) {
141
+ var _value = style[_prop];
142
+
143
+ if (_value !== undefined) {
144
+ if (!definedProperties.includes(_prop)) {
145
+ if (_value != null) {
146
+ if (inlineStyle == null) {
147
+ inlineStyle = {};
148
+ }
149
+
150
+ if (subStyle == null) {
151
+ subStyle = {};
152
+ }
153
+
154
+ subStyle[_prop] = _value;
155
+ }
156
+
157
+ definedProperties.push(_prop); // Cache is unnecessary overhead if results can't be reused.
158
+
159
+ nextCache = null;
160
+ }
161
+ }
162
+ }
163
+
164
+ if (subStyle != null) {
165
+ inlineStyle = Object.assign(subStyle, inlineStyle);
166
+ }
167
+ }
168
+ }
169
+ }
170
+
171
+ var styleProps = [className, inlineStyle];
172
+ return styleProps;
173
+ };
174
+ }
175
+
176
+ var styleq$1 = createStyleq();
177
+ styleq.styleq = styleq$1;
178
+ styleq$1.factory = createStyleq;
179
+ return styleq;
168
180
  }
169
181
 
170
- var styleq = createStyleq();
171
- styleq_2 = styleq$1.styleq = styleq;
172
- styleq.factory = createStyleq;
182
+ var styleqExports = /*@__PURE__*/ requireStyleq();
173
183
 
174
184
  const errorForFn = name => new Error(`'stylex.${name}' should never be called at runtime. It should be compiled away by '@stylexjs/babel-plugin'`);
175
185
  const errorForType = key => errorForFn(`types.${key}`);
176
186
  function props() {
177
- const options = this;
178
187
  for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
179
188
  styles[_key] = arguments[_key];
180
189
  }
181
- if (__implementations.props) {
182
- return __implementations.props.call(options, styles);
183
- }
184
- const [className, style] = styleq_2(styles);
190
+ const [className, style] = styleqExports.styleq(styles);
185
191
  const result = {};
186
192
  if (className != null && className !== '') {
187
193
  result.className = className;
@@ -205,29 +211,16 @@ function attrs() {
205
211
  }
206
212
  return result;
207
213
  }
208
- function stylexCreate(styles) {
209
- if (__implementations.create != null) {
210
- const create = __implementations.create;
211
- return create(styles);
212
- }
214
+ function stylexCreate(_styles) {
213
215
  throw errorForFn('create');
214
216
  }
215
- function stylexDefineVars(styles) {
216
- if (__implementations.defineVars) {
217
- return __implementations.defineVars(styles);
218
- }
217
+ function stylexDefineVars(_styles) {
219
218
  throw errorForFn('defineVars');
220
219
  }
221
- const stylexCreateTheme = (baseTokens, overrides) => {
222
- if (__implementations.createTheme) {
223
- return __implementations.createTheme(baseTokens, overrides);
224
- }
220
+ const stylexCreateTheme = (_baseTokens, _overrides) => {
225
221
  throw errorForFn('createTheme');
226
222
  };
227
- const stylexInclude = styles => {
228
- if (__implementations.include) {
229
- return __implementations.include(styles);
230
- }
223
+ const stylexInclude = _styles => {
231
224
  throw errorForFn('include');
232
225
  };
233
226
  const create = stylexCreate;
@@ -275,23 +268,17 @@ const types = {
275
268
  throw errorForType('transformList');
276
269
  }
277
270
  };
278
- const keyframes = keyframes => {
279
- if (__implementations.keyframes) {
280
- return __implementations.keyframes(keyframes);
281
- }
271
+ const keyframes = _keyframes => {
282
272
  throw errorForFn('keyframes');
283
273
  };
284
274
  const firstThatWorks = function () {
285
- if (__implementations.firstThatWorks) {
286
- return __implementations.firstThatWorks(...arguments);
287
- }
288
275
  throw errorForFn('firstThatWorks');
289
276
  };
290
277
  function _stylex() {
291
278
  for (var _len2 = arguments.length, styles = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
292
279
  styles[_key2] = arguments[_key2];
293
280
  }
294
- const [className] = styleq_2(styles);
281
+ const [className] = styleqExports.styleq(styles);
295
282
  return className;
296
283
  }
297
284
  _stylex.props = props;
@@ -303,14 +290,6 @@ _stylex.include = include;
303
290
  _stylex.keyframes = keyframes;
304
291
  _stylex.firstThatWorks = firstThatWorks;
305
292
  _stylex.types = types;
306
- const __implementations = {};
307
- function __monkey_patch__(key, implementation) {
308
- if (key === 'types') {
309
- Object.assign(types, implementation);
310
- } else {
311
- __implementations[key] = implementation;
312
- }
313
- }
314
293
  const legacyMerge = _stylex;
315
294
 
316
- export { __monkey_patch__, attrs, create, createTheme, _stylex as default, defineVars, firstThatWorks, include, keyframes, legacyMerge, props, types };
295
+ export { attrs, create, createTheme, _stylex as default, defineVars, firstThatWorks, include, keyframes, legacyMerge, props, types };
package/lib/stylex.d.ts CHANGED
@@ -114,9 +114,9 @@ export declare const types: {
114
114
  _v: ValueWithDefault<T>,
115
115
  ) => TransformList<T>;
116
116
  };
117
- export declare const keyframes: (keyframes: Keyframes) => string;
117
+ export declare const keyframes: (_keyframes: Keyframes) => string;
118
118
  export declare const firstThatWorks: <T extends string | number>(
119
- ...styles: ReadonlyArray<T>
119
+ ..._styles: ReadonlyArray<T>
120
120
  ) => ReadonlyArray<T>;
121
121
  type IStyleX = {
122
122
  (
package/lib/stylex.js CHANGED
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.__monkey_patch__ = __monkey_patch__;
7
6
  exports.attrs = attrs;
8
7
  exports.legacyMerge = exports.keyframes = exports.include = exports.firstThatWorks = exports.defineVars = exports.default = exports.createTheme = exports.create = void 0;
9
8
  exports.props = props;
@@ -12,13 +11,9 @@ var _styleq = require("styleq");
12
11
  const errorForFn = name => new Error(`'stylex.${name}' should never be called at runtime. It should be compiled away by '@stylexjs/babel-plugin'`);
13
12
  const errorForType = key => errorForFn(`types.${key}`);
14
13
  function props() {
15
- const options = this;
16
14
  for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
17
15
  styles[_key] = arguments[_key];
18
16
  }
19
- if (__implementations.props) {
20
- return __implementations.props.call(options, styles);
21
- }
22
17
  const [className, style] = (0, _styleq.styleq)(styles);
23
18
  const result = {};
24
19
  if (className != null && className !== '') {
@@ -43,29 +38,16 @@ function attrs() {
43
38
  }
44
39
  return result;
45
40
  }
46
- function stylexCreate(styles) {
47
- if (__implementations.create != null) {
48
- const create = __implementations.create;
49
- return create(styles);
50
- }
41
+ function stylexCreate(_styles) {
51
42
  throw errorForFn('create');
52
43
  }
53
- function stylexDefineVars(styles) {
54
- if (__implementations.defineVars) {
55
- return __implementations.defineVars(styles);
56
- }
44
+ function stylexDefineVars(_styles) {
57
45
  throw errorForFn('defineVars');
58
46
  }
59
- const stylexCreateTheme = (baseTokens, overrides) => {
60
- if (__implementations.createTheme) {
61
- return __implementations.createTheme(baseTokens, overrides);
62
- }
47
+ const stylexCreateTheme = (_baseTokens, _overrides) => {
63
48
  throw errorForFn('createTheme');
64
49
  };
65
- const stylexInclude = styles => {
66
- if (__implementations.include) {
67
- return __implementations.include(styles);
68
- }
50
+ const stylexInclude = _styles => {
69
51
  throw errorForFn('include');
70
52
  };
71
53
  const create = exports.create = stylexCreate;
@@ -113,17 +95,11 @@ const types = exports.types = {
113
95
  throw errorForType('transformList');
114
96
  }
115
97
  };
116
- const keyframes = keyframes => {
117
- if (__implementations.keyframes) {
118
- return __implementations.keyframes(keyframes);
119
- }
98
+ const keyframes = _keyframes => {
120
99
  throw errorForFn('keyframes');
121
100
  };
122
101
  exports.keyframes = keyframes;
123
102
  const firstThatWorks = function () {
124
- if (__implementations.firstThatWorks) {
125
- return __implementations.firstThatWorks(...arguments);
126
- }
127
103
  throw errorForFn('firstThatWorks');
128
104
  };
129
105
  exports.firstThatWorks = firstThatWorks;
@@ -143,13 +119,5 @@ _stylex.include = include;
143
119
  _stylex.keyframes = keyframes;
144
120
  _stylex.firstThatWorks = firstThatWorks;
145
121
  _stylex.types = types;
146
- const __implementations = {};
147
- function __monkey_patch__(key, implementation) {
148
- if (key === 'types') {
149
- Object.assign(types, implementation);
150
- } else {
151
- __implementations[key] = implementation;
152
- }
153
- }
154
122
  const legacyMerge = exports.legacyMerge = _stylex;
155
123
  var _default = exports.default = _stylex;
@@ -116,10 +116,10 @@ declare export const types: {
116
116
  ) => TransformList<T>,
117
117
  };
118
118
 
119
- declare export const keyframes: (keyframes: Keyframes) => string;
119
+ declare export const keyframes: (_keyframes: Keyframes) => string;
120
120
 
121
121
  declare export const firstThatWorks: <T: string | number>(
122
- ...styles: $ReadOnlyArray<T>
122
+ ..._styles: $ReadOnlyArray<T>
123
123
  ) => $ReadOnlyArray<T>;
124
124
 
125
125
  type IStyleX = {
@@ -158,6 +158,5 @@ type IStyleX = {
158
158
  ...
159
159
  };
160
160
 
161
-
162
161
  declare export const legacyMerge: IStyleX;
163
162
  declare export default IStyleX;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/stylex",
3
- "version": "0.8.0",
3
+ "version": "0.9.0-beta.1",
4
4
  "description": "A library for defining styles for optimized user interfaces.",
5
5
  "main": "./lib/stylex.js",
6
6
  "module": "./lib/es/stylex.mjs",
@@ -45,7 +45,7 @@
45
45
  "styleq": "0.1.3"
46
46
  },
47
47
  "devDependencies": {
48
- "@stylexjs/scripts": "0.8.0",
48
+ "@stylexjs/scripts": "0.9.0-beta.1",
49
49
  "cross-env": "^7.0.3"
50
50
  },
51
51
  "jest": {},