@stylexjs/babel-plugin 0.1.0-beta.6 → 0.2.0-beta.8

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.
Files changed (2) hide show
  1. package/lib/index.js +896 -305
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var t = require('@babel/types');
6
6
  var require$$0 = require('postcss-value-parser');
7
7
  var path = require('path');
8
+ var require$$0$1 = require('invariant');
8
9
 
9
10
  function _interopNamespaceDefault(e) {
10
11
  var n = Object.create(null);
@@ -25,7 +26,7 @@ function _interopNamespaceDefault(e) {
25
26
 
26
27
  var t__namespace = /*#__PURE__*/_interopNamespaceDefault(t);
27
28
 
28
- function _defineProperty(obj, key, value) {
29
+ function _defineProperty$1(obj, key, value) {
29
30
  if (key in obj) {
30
31
  Object.defineProperty(obj, key, {
31
32
  value: value,
@@ -49,15 +50,15 @@ class StateManager {
49
50
  // resuls of `stylex.create` calls that should be kept
50
51
 
51
52
  constructor(state) {
52
- _defineProperty(this, "_state", void 0);
53
- _defineProperty(this, "stylexImport", new Set());
54
- _defineProperty(this, "stylexCreateImport", new Set());
55
- _defineProperty(this, "stylexIncludeImport", new Set());
56
- _defineProperty(this, "stylexFirstThatWorksImport", new Set());
57
- _defineProperty(this, "stylexKeyframesImport", new Set());
58
- _defineProperty(this, "styleMap", new Map());
59
- _defineProperty(this, "styleVars", new Map());
60
- _defineProperty(this, "styleVarsToKeep", new Set());
53
+ _defineProperty$1(this, "_state", void 0);
54
+ _defineProperty$1(this, "stylexImport", new Set());
55
+ _defineProperty$1(this, "stylexCreateImport", new Set());
56
+ _defineProperty$1(this, "stylexIncludeImport", new Set());
57
+ _defineProperty$1(this, "stylexFirstThatWorksImport", new Set());
58
+ _defineProperty$1(this, "stylexKeyframesImport", new Set());
59
+ _defineProperty$1(this, "styleMap", new Map());
60
+ _defineProperty$1(this, "styleVars", new Map());
61
+ _defineProperty$1(this, "styleVarsToKeep", new Set());
61
62
  this._state = state;
62
63
  state.file.metadata.stylex = [];
63
64
  }
@@ -70,7 +71,9 @@ class StateManager {
70
71
  stylexSheetName: options.stylexSheetName ?? undefined,
71
72
  classNamePrefix: options.classNamePrefix ?? 'x',
72
73
  importSources: options.importSources ?? [name, 'stylex'],
73
- definedStylexCSSVariables: options.definedStylexCSSVariables ?? {}
74
+ definedStylexCSSVariables: options.definedStylexCSSVariables ?? {},
75
+ genConditionalClasses: !!options.genConditionalClasses,
76
+ allowUnsafeProperties: !!options.allowUnsafeProperties
74
77
  };
75
78
  return this._state.opts;
76
79
  }
@@ -191,7 +194,7 @@ function readRequires(path, state) {
191
194
 
192
195
  var lib = {};
193
196
 
194
- var stylexCreate = {};
197
+ var stylexCreate$1 = {};
195
198
 
196
199
  var convertToClassName$1 = {};
197
200
 
@@ -254,8 +257,8 @@ function murmurhash2_32_gc(str, seed) {
254
257
  return h >>> 0;
255
258
  }
256
259
  const hash = str => murmurhash2_32_gc(str, 1).toString(36);
257
- var _default = hash;
258
- hash$1.default = _default;
260
+ var _default$1 = hash;
261
+ hash$1.default = _default$1;
259
262
 
260
263
  var dashify$1 = {};
261
264
 
@@ -327,8 +330,8 @@ Object.defineProperty(leadingZero, "__esModule", {
327
330
  value: true
328
331
  });
329
332
  leadingZero.default = normalizeLeadingZero;
330
- var _postcssValueParser$5 = _interopRequireDefault$b(require$$0);
331
- function _interopRequireDefault$b(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
333
+ var _postcssValueParser$5 = _interopRequireDefault$d(require$$0);
334
+ function _interopRequireDefault$d(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
332
335
  /**
333
336
  * Remove leading zeros from numbers
334
337
  */
@@ -396,8 +399,8 @@ Object.defineProperty(timings$1, "__esModule", {
396
399
  value: true
397
400
  });
398
401
  timings$1.default = normalizeTimings;
399
- var _postcssValueParser$4 = _interopRequireDefault$a(require$$0);
400
- function _interopRequireDefault$a(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
402
+ var _postcssValueParser$4 = _interopRequireDefault$c(require$$0);
403
+ function _interopRequireDefault$c(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
401
404
  /**
402
405
  * Turn millisecond values to seconds (shorter), except when < 10ms
403
406
  */
@@ -491,8 +494,8 @@ Object.defineProperty(zeroDimensions, "__esModule", {
491
494
  value: true
492
495
  });
493
496
  zeroDimensions.default = normalizeZeroDimensions;
494
- var _postcssValueParser$3 = _interopRequireDefault$9(require$$0);
495
- function _interopRequireDefault$9(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
497
+ var _postcssValueParser$3 = _interopRequireDefault$b(require$$0);
498
+ function _interopRequireDefault$b(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
496
499
  const angles = ['deg', 'grad', 'turn', 'rad'];
497
500
  const timings = ['ms', 's'];
498
501
 
@@ -538,7 +541,7 @@ var messages$4 = {};
538
541
  Object.defineProperty(messages$4, "__esModule", {
539
542
  value: true
540
543
  });
541
- messages$4.UNKNOWN_PROP_KEY = messages$4.UNKNOWN_NAMESPACE = messages$4.UNEXPECTED_ARGUMENT = messages$4.UNBOUND_STYLEX_CALL_VALUE = messages$4.ONLY_TOP_LEVEL = messages$4.NO_PARENT_PATH = messages$4.NON_STATIC_VALUE = messages$4.NON_OBJECT_FOR_STYLEX_CALL = messages$4.LOCAL_ONLY = messages$4.LINT_UNCLOSED_FUNCTION = messages$4.INVALID_SPREAD = messages$4.INVALID_PSEUDO = messages$4.ILLEGAL_PROP_VALUE = messages$4.ILLEGAL_PROP_ARRAY_VALUE = messages$4.ILLEGAL_NESTED_PSEUDO = messages$4.ILLEGAL_NAMESPACE_VALUE = messages$4.ILLEGAL_NAMESPACE_TYPE = messages$4.ILLEGAL_ARGUMENT_LENGTH = messages$4.EXPECTED_FUNCTION_CALL = messages$4.ESCAPED_STYLEX_VALUE = void 0;
544
+ messages$4.UNKNOWN_PROP_KEY = messages$4.UNKNOWN_NAMESPACE = messages$4.UNEXPECTED_ARGUMENT = messages$4.UNBOUND_STYLEX_CALL_VALUE = messages$4.ONLY_TOP_LEVEL = messages$4.NO_PARENT_PATH = messages$4.NO_CONDITIONAL_SHORTHAND = messages$4.NON_STATIC_VALUE = messages$4.NON_OBJECT_FOR_STYLEX_CALL = messages$4.MULTIPLE_DIRECTIONS_IN_SHORTHAND = messages$4.LOCAL_ONLY = messages$4.LINT_UNCLOSED_FUNCTION = messages$4.INVALID_SPREAD = messages$4.INVALID_PSEUDO = messages$4.ILLEGAL_PROP_VALUE = messages$4.ILLEGAL_PROP_ARRAY_VALUE = messages$4.ILLEGAL_NESTED_PSEUDO = messages$4.ILLEGAL_NAMESPACE_VALUE = messages$4.ILLEGAL_NAMESPACE_TYPE = messages$4.ILLEGAL_ARGUMENT_LENGTH = messages$4.EXPECTED_FUNCTION_CALL = messages$4.ESCAPED_STYLEX_VALUE = void 0;
542
545
  const ILLEGAL_ARGUMENT_LENGTH = 'stylex() should have 1 argument.';
543
546
  messages$4.ILLEGAL_ARGUMENT_LENGTH = ILLEGAL_ARGUMENT_LENGTH;
544
547
  const NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
@@ -555,6 +558,8 @@ const UNKNOWN_PROP_KEY = 'Unknown property key';
555
558
  messages$4.UNKNOWN_PROP_KEY = UNKNOWN_PROP_KEY;
556
559
  const INVALID_PSEUDO = 'Invalid pseudo selector, not on the whitelist.';
557
560
  messages$4.INVALID_PSEUDO = INVALID_PSEUDO;
561
+ const NO_CONDITIONAL_SHORTHAND = 'You cannot use conditional style values for a shorthand property.';
562
+ messages$4.NO_CONDITIONAL_SHORTHAND = NO_CONDITIONAL_SHORTHAND;
558
563
  const ILLEGAL_NAMESPACE_TYPE = 'Only a string literal namespace is allowed here.';
559
564
  messages$4.ILLEGAL_NAMESPACE_TYPE = ILLEGAL_NAMESPACE_TYPE;
560
565
  const UNKNOWN_NAMESPACE = 'Unknown namespace';
@@ -579,6 +584,8 @@ const EXPECTED_FUNCTION_CALL = 'Expected a simple function call but found someth
579
584
  messages$4.EXPECTED_FUNCTION_CALL = EXPECTED_FUNCTION_CALL;
580
585
  const NO_PARENT_PATH = 'Unexpected AST node without a parent path.';
581
586
  messages$4.NO_PARENT_PATH = NO_PARENT_PATH;
587
+ const MULTIPLE_DIRECTIONS_IN_SHORTHAND = 'Shorthand properties cannot contain different values for different directions.';
588
+ messages$4.MULTIPLE_DIRECTIONS_IN_SHORTHAND = MULTIPLE_DIRECTIONS_IN_SHORTHAND;
582
589
 
583
590
  /**
584
591
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -593,9 +600,9 @@ Object.defineProperty(detectUnclosedFns$1, "__esModule", {
593
600
  value: true
594
601
  });
595
602
  detectUnclosedFns$1.default = detectUnclosedFns;
596
- var messages$3 = _interopRequireWildcard$3(messages$4);
597
- function _getRequireWildcardCache$3(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache$3 = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
598
- function _interopRequireWildcard$3(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache$3(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
603
+ var messages$3 = _interopRequireWildcard$4(messages$4);
604
+ function _getRequireWildcardCache$4(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache$4 = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
605
+ function _interopRequireWildcard$4(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache$4(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
599
606
  /**
600
607
  * Remove leading zeros from numbers
601
608
  */
@@ -622,15 +629,15 @@ Object.defineProperty(normalizeValue$1, "__esModule", {
622
629
  value: true
623
630
  });
624
631
  normalizeValue$1.default = normalizeValue;
625
- var _fontSizePxToRem = _interopRequireDefault$8(fontSizePxToRem);
626
- var _leadingZero = _interopRequireDefault$8(leadingZero);
627
- var _quotes = _interopRequireDefault$8(quotes);
628
- var _timings = _interopRequireDefault$8(timings$1);
629
- var _whitespace = _interopRequireDefault$8(whitespace);
630
- var _zeroDimensions = _interopRequireDefault$8(zeroDimensions);
631
- var _detectUnclosedFns = _interopRequireDefault$8(detectUnclosedFns$1);
632
- var _postcssValueParser$2 = _interopRequireDefault$8(require$$0);
633
- function _interopRequireDefault$8(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
632
+ var _fontSizePxToRem = _interopRequireDefault$a(fontSizePxToRem);
633
+ var _leadingZero = _interopRequireDefault$a(leadingZero);
634
+ var _quotes = _interopRequireDefault$a(quotes);
635
+ var _timings = _interopRequireDefault$a(timings$1);
636
+ var _whitespace = _interopRequireDefault$a(whitespace);
637
+ var _zeroDimensions = _interopRequireDefault$a(zeroDimensions);
638
+ var _detectUnclosedFns = _interopRequireDefault$a(detectUnclosedFns$1);
639
+ var _postcssValueParser$2 = _interopRequireDefault$a(require$$0);
640
+ function _interopRequireDefault$a(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
634
641
  // `Timings` should be before `LeadingZero`, because it
635
642
  // changes 500ms to 0.5s, then `LeadingZero` makes it .5s
636
643
  const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _zeroDimensions.default, _leadingZero.default, _quotes.default, _fontSizePxToRem.default];
@@ -643,8 +650,8 @@ Object.defineProperty(transformValue$1, "__esModule", {
643
650
  value: true
644
651
  });
645
652
  transformValue$1.default = transformValue;
646
- var _normalizeValue = _interopRequireDefault$7(normalizeValue$1);
647
- function _interopRequireDefault$7(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
653
+ var _normalizeValue = _interopRequireDefault$9(normalizeValue$1);
654
+ function _interopRequireDefault$9(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
648
655
  /**
649
656
  * Copyright (c) Meta Platforms, Inc. and affiliates.
650
657
  *
@@ -840,8 +847,8 @@ Object.defineProperty(generateRtl, "__esModule", {
840
847
  value: true
841
848
  });
842
849
  generateRtl.default = generateRTL;
843
- var _postcssValueParser$1 = _interopRequireDefault$6(require$$0);
844
- function _interopRequireDefault$6(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
850
+ var _postcssValueParser$1 = _interopRequireDefault$8(require$$0);
851
+ function _interopRequireDefault$8(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
845
852
  /**
846
853
  * Copyright (c) Meta Platforms, Inc. and affiliates.
847
854
  *
@@ -1080,10 +1087,10 @@ Object.defineProperty(generateCssRule, "__esModule", {
1080
1087
  value: true
1081
1088
  });
1082
1089
  generateCssRule.default = generateCSSRule;
1083
- var _generateLtr$1 = _interopRequireDefault$5(generateLtr);
1084
- var _generateRtl$1 = _interopRequireDefault$5(generateRtl);
1085
- var _genCSSRule = _interopRequireDefault$5(genCSSRule);
1086
- function _interopRequireDefault$5(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1090
+ var _generateLtr$1 = _interopRequireDefault$7(generateLtr);
1091
+ var _generateRtl$1 = _interopRequireDefault$7(generateRtl);
1092
+ var _genCSSRule = _interopRequireDefault$7(genCSSRule);
1093
+ function _interopRequireDefault$7(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1087
1094
  /**
1088
1095
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1089
1096
  *
@@ -1143,11 +1150,11 @@ Object.defineProperty(convertToClassName$1, "__esModule", {
1143
1150
  value: true
1144
1151
  });
1145
1152
  convertToClassName$1.default = convertToClassName;
1146
- var _hash$1 = _interopRequireDefault$4(hash$1);
1147
- var _dashify$1 = _interopRequireDefault$4(dashify$1);
1148
- var _transformValue$1 = _interopRequireDefault$4(transformValue$1);
1149
- var _generateCssRule = _interopRequireDefault$4(generateCssRule);
1150
- function _interopRequireDefault$4(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1153
+ var _hash$1 = _interopRequireDefault$6(hash$1);
1154
+ var _dashify$1 = _interopRequireDefault$6(dashify$1);
1155
+ var _transformValue$1 = _interopRequireDefault$6(transformValue$1);
1156
+ var _generateCssRule = _interopRequireDefault$6(generateCssRule);
1157
+ function _interopRequireDefault$6(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1151
1158
  /**
1152
1159
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1153
1160
  *
@@ -1183,9 +1190,14 @@ var expandShorthands = {};
1183
1190
  Object.defineProperty(expandShorthands, "__esModule", {
1184
1191
  value: true
1185
1192
  });
1193
+ expandShorthands.BANNED_PROPERTIES = void 0;
1186
1194
  expandShorthands.default = flatMapExpandedShorthands;
1187
- var _postcssValueParser = _interopRequireDefault$3(require$$0);
1188
- function _interopRequireDefault$3(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1195
+ expandShorthands.expandedKeys = void 0;
1196
+ _interopRequireWildcard$3(messages$4);
1197
+ var _postcssValueParser = _interopRequireDefault$5(require$$0);
1198
+ function _interopRequireDefault$5(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1199
+ function _getRequireWildcardCache$3(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache$3 = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
1200
+ function _interopRequireWildcard$3(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache$3(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
1189
1201
  /**
1190
1202
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1191
1203
  *
@@ -1245,70 +1257,233 @@ function splitValue(str) {
1245
1257
 
1246
1258
  /**
1247
1259
  * Shorthand properties:
1248
- * - [x] all - Should be banned
1249
- * - [ ] animation
1250
- * - [ ] background
1251
- * - [-] border
1252
- * - [x] border-block-end
1253
- * - [x] border-block-start
1254
- * - [ ] border-bottom
1260
+ * - [!] all - BANNED
1261
+ * - [!] animation - BANNED
1262
+ * - [!] background - BANNED
1263
+ * - [x] border - adequate for now
1264
+ * - [ ] border-block-end
1265
+ * - [ ] border-block-start
1266
+ * - [x] border-bottom
1255
1267
  * - [x] border-color
1256
- * - [x] border-image
1257
- * - [x] border-inline-end
1258
- * - [x] border-inline-start
1259
- * - [ ] border-left
1268
+ * - [o] border-image - Only the shorthand is allowed.
1269
+ * - [ ] border-inline-end
1270
+ * - [ ] border-inline-start
1271
+ * - [!] border-left - BANNED
1260
1272
  * - [x] border-radius
1261
- * - [ ] border-right
1273
+ * - [!] border-right
1262
1274
  * - [x] border-style
1263
1275
  * - [ ] border-top
1264
1276
  * - [x] border-width
1265
- * - [ ] column-rule
1266
- * - [ ] columns
1267
- * - [ ] flex
1268
- * - [ ] flex-flow
1269
- * - [ ] font
1270
- * - [ ] gap
1271
- * - [ ] grid
1272
- * - [ ] grid-area
1273
- * - [ ] grid-column
1274
- * - [ ] grid-row
1275
- * - [ ] grid-template
1276
- * - [ ] list-style
1277
+ * - [o] column-rule - Only the shorthand is allowed.
1278
+ * - [!] columns - BANNED
1279
+ * - [!] flex - BANNED
1280
+ * - [!] flex-flow - BANNED
1281
+ * - [!] font - BANNED
1282
+ * - [x] gap
1283
+ * - [!] grid - BANNED
1284
+ * - [!] grid-area - BANNED
1285
+ * - [!] grid-column - BANNED
1286
+ * - [!] grid-row - BANNED
1287
+ * - [!] grid-template - BANNED
1288
+ * - [!] grid-template-areas - BANNED
1289
+ *
1290
+ * - [o] list-style - Only the shorthand is allowed.
1277
1291
  * - [x] margin
1278
- * - [ ] mask
1279
- * - [ ] offset
1280
- * - [ ] outline
1292
+ * - [o] mask - Only the shorthand is allowed.
1293
+ * - [o] offset - Only the shorthand is allowed.
1294
+ * - [o] outline - Only the shorthand is allowed.
1281
1295
  * - [x] overflow
1282
1296
  * - [x] padding
1283
- * - [ ] place-content
1284
- * - [ ] place-items
1285
- * - [ ] place-self
1286
- * - [ ] scroll-margin
1287
- * - [ ] scroll-padding
1288
- * - [ ] text-decoration
1289
- * - [ ] text-emphasis
1290
- * - [ ] transition
1297
+ * - [x] place-content
1298
+ * - [x] place-items
1299
+ * - [x] place-self
1300
+ * - [X] scroll-margin
1301
+ * - [x] scroll-padding
1302
+ * - [o] text-decoration - Only the shorthand is allowed.
1303
+ * - [o] text-emphasis - Only the shorthand is allowed.
1304
+ * - [!] transition - BANNED
1291
1305
  */
1292
1306
 
1307
+ const BANNED_PROPERTIES = {
1308
+ all: '`all` is not supported. Use individual properties instead.',
1309
+ animation: '`animation` is not supported. Use individual properties like `animationName`, `animationDuration`, etc. instead.',
1310
+ background: '`background` is not supported. Use individual properties like `backgroundImage`, `backgroundPosition`, etc. instead.',
1311
+ borderColor: '`borderColor` is not supported. Use `border`, `borderTop`, `borderEnd`, `borderBottom` or `borderStart` instead.',
1312
+ borderStyle: '`borderStyle` is not supported. Use `border`, `borderTop`, `borderEnd`, `borderBottom` or `borderStart` instead.',
1313
+ borderWidth: '`borderWidth` is not supported. Use `border`, `borderTop`, `borderEnd`, `borderBottom` or `borderStart` instead.',
1314
+ borderTopColor: '`borderTopColor` is not supported. Use `borderTop` instead.',
1315
+ borderTopStyle: '`borderTopStyle` is not supported. Use `borderTop` instead.',
1316
+ borderTopWidth: '`borderTopWidth` is not supported. Use `borderTop` instead.',
1317
+ borderEndColor: '`borderEndColor` is not supported. Use `borderEnd` instead.',
1318
+ borderEndStyle: '`borderEndStyle` is not supported. Use `borderEnd` instead.',
1319
+ borderEndWidth: '`borderEndWidth` is not supported. Use `borderEnd` instead.',
1320
+ borderBottomColor: '`borderBottomColor` is not supported. Use `borderBottom` instead.',
1321
+ borderBottomStyle: '`borderBottomStyle` is not supported. Use `borderBottom` instead.',
1322
+ borderBottomWidth: '`borderBottomWidth` is not supported. Use `borderBottom` instead.',
1323
+ borderStartColor: '`borderStartColor` is not supported. Use `borderStart` instead.',
1324
+ borderStartStyle: '`borderStartStyle` is not supported. Use `borderStart` instead.',
1325
+ borderStartWidth: '`borderStartWidth` is not supported. Use `borderStart` instead.',
1326
+ borderBlockStartColor: '`borderBlockStartColor` is not supported. Use `borderTop` instead.',
1327
+ borderBlockStartStyle: '`borderBlockStartStyle` is not supported. Use `borderTop` instead.',
1328
+ borderBlockStartWidth: '`borderBlockStartWidth` is not supported. Use `borderTop` instead.',
1329
+ borderBlockEndColor: '`borderBlockEndColor` is not supported. Use `borderBottom` instead.',
1330
+ borderBlockEndStyle: '`borderBlockEndStyle` is not supported. Use `borderBottom` instead.',
1331
+ borderBlockEndWidth: '`borderBlockEndWidth` is not supported. Use `borderBottom` instead.',
1332
+ borderInlineStartColor: '`borderInlineStartColor` is not supported. Use `borderStart` instead.',
1333
+ borderInlineStartStyle: '`borderInlineStartStyle` is not supported. Use `borderStart` instead.',
1334
+ borderInlineStartWidth: '`borderInlineStartWidth` is not supported. Use `borderStart` instead.',
1335
+ borderInlineEndColor: '`borderInlineEndColor` is not supported. Use `borderEnd` instead.',
1336
+ borderInlineEndStyle: '`borderInlineEndStyle` is not supported. Use `borderEnd` instead.',
1337
+ borderInlineEndWidth: '`borderInlineEndWidth` is not supported. Use `borderEnd` instead.',
1338
+ borderLeft: '`borderLeft` is not supported. Use `borderStart` instead.',
1339
+ borderLeftColor: '`borderLeftColor` is not supported. Use `borderStart` instead.',
1340
+ borderLeftStyle: '`borderLeftStyle` is not supported. Use `borderStart` instead.',
1341
+ borderLeftWidth: '`borderLeftWidth` is not supported. Use `borderStart` instead.',
1342
+ borderRight: '`borderRight` is not supported. Use `borderEnd` instead.',
1343
+ borderRightColor: '`borderRightColor` is not supported. Use `borderEnd` instead.',
1344
+ borderRightStyle: '`borderRightStyle` is not supported. Use `borderEnd` instead.',
1345
+ borderRightWidth: '`borderRightWidth` is not supported. Use `borderEnd` instead.',
1346
+ borderTopLeftRadius: '`borderTopLeftRadius` is not supported. Use `borderTopStartRadius` instead.',
1347
+ borderTopRightRadius: '`borderTopRightRadius` is not supported. Use `borderTopEndRadius` instead.',
1348
+ borderBottomLeftRadius: '`borderBottomLeftRadius` is not supported. Use `borderBottomStartRadius` instead.',
1349
+ borderBottomRightRadius: '`borderBottomRightRadius` is not supported. Use `borderBottomEndRadius` instead.',
1350
+ borderImageSource: '`borderImageSource` is not supported. Use `borderImage` instead.',
1351
+ borderImageSlice: '`borderImageSlice` is not supported. Use `borderImage` instead.',
1352
+ borderImageWidth: '`borderImageWidth` is not supported. Use `borderImage` instead.',
1353
+ borderImageOutset: '`borderImageOutset` is not supported. Use `borderImage` instead.',
1354
+ borderImageRepeat: '`borderImageRepeat` is not supported. Use `borderImage` instead.',
1355
+ marginLeft: '`marginLeft` is not supported. Use `marginStart` instead.',
1356
+ marginRight: '`marginRight` is not supported. Use `marginEnd` instead.',
1357
+ paddingLeft: '`paddingLeft` is not supported. Use `paddingStart` instead.',
1358
+ paddingRight: '`paddingRight` is not supported. Use `paddingEnd` instead.',
1359
+ columnRuleWidth: '`columnRuleWidth` is not supported. Use `columnRule` instead.',
1360
+ columnRuleStyle: '`columnRuleStyle` is not supported. Use `columnRule` instead.',
1361
+ columnRuleColor: '`columnRuleColor` is not supported. Use `columnRule` instead.',
1362
+ columns: '`columns` is not supported. Use `columnCount` and `columnWidth` instead.',
1363
+ flex: '`flex` is not supported. Use `flexGrow`, `flexShrink`, and `flexBasis` instead.',
1364
+ flexFlow: '`flexFlow` is not supported. Use `flexDirection` and `flexWrap` instead.',
1365
+ font: '`font` is not supported. Use individual properties like `fontFamily`, `fontSize`, etc. instead.',
1366
+ grid: '`grid` is not supported. Use individual properties like `gridTemplateColumns`, `gridTemplateRows`, etc. instead.',
1367
+ gridColumn: '`gridColumn` is not supported. Use `gridColumnStart` and `gridColumnEnd` instead.',
1368
+ gridRow: '`gridRow` is not supported. Use `gridRowStart` and `gridRowEnd` instead.',
1369
+ gridArea: '`gridArea` is not supported. Use `gridRowStart`, `gridColumnStart`, `gridRowEnd`, and `gridColumnEnd` instead.',
1370
+ gridTemplate: '`gridTemplate` is not supported. Use individual properties like `gridTemplateColumns`, `gridTemplateRows`, etc. instead.',
1371
+ gridTemplateAreas: '`gridTemplateAreas` is not supported. Use `gridTemplateRows` and `gridTemplateColumns` instead.',
1372
+ listStyleImage: '`listStyleImage` is not supported. Use `listStyle` instead.',
1373
+ listStylePosition: '`listStylePosition` is not supported. Use `listStyle` instead.',
1374
+ listStyleType: '`listStyleType` is not supported. Use `listStyle` instead.',
1375
+ maskClip: '`maskClip` is not supported. Use `mask` instead.',
1376
+ maskComposite: '`maskComposite` is not supported. Use `mask` instead.',
1377
+ maskImage: '`maskImage` is not supported. Use `mask` instead.',
1378
+ maskMode: '`maskMode` is not supported. Use `mask` instead.',
1379
+ maskOrigin: '`maskOrigin` is not supported. Use `mask` instead.',
1380
+ maskPosition: '`maskPosition` is not supported. Use `mask` instead.',
1381
+ maskRepeat: '`maskRepeat` is not supported. Use `mask` instead.',
1382
+ maskSize: '`maskSize` is not supported. Use `mask` instead.',
1383
+ offsetAnchor: '`offsetAnchor` is not supported. Use `offset` instead.',
1384
+ offsetDistance: '`offsetDistance` is not supported. Use `offset` instead.',
1385
+ offsetPath: '`offsetPath` is not supported. Use `offset` instead.',
1386
+ offsetPosition: '`offsetPosition` is not supported. Use `offset` instead.',
1387
+ offsetRotate: '`offsetRotate` is not supported. Use `offset` instead.',
1388
+ outlineColor: '`outlineColor` is not supported. Use `outline` instead.',
1389
+ outlineStyle: '`outlineStyle` is not supported. Use `outline` instead.',
1390
+ outlineWidth: '`outlineWidth` is not supported. Use `outline` instead.',
1391
+ textDecorationColor: '`textDecorationColor` is not supported. Use `textDecoration` instead.',
1392
+ textDecorationLine: '`textDecorationLine` is not supported. Use `textDecoration` instead.',
1393
+ textDecorationStyle: '`textDecorationStyle` is not supported. Use `textDecoration` instead.',
1394
+ textDecorationThickness: '`textDecorationThickness` is not supported. Use `textDecoration` instead.',
1395
+ textEmphasisColor: '`textEmphasisColor` is not supported. Use `textEmphasis` instead.',
1396
+ textEmphasisStyle: '`textEmphasisStyle` is not supported. Use `textEmphasis` instead.',
1397
+ transition: '`transition` is not supported. Use individual properties like `transitionProperty`, `transitionDuration`, etc. instead.'
1398
+ };
1399
+ expandShorthands.BANNED_PROPERTIES = BANNED_PROPERTIES;
1293
1400
  const expansions = {
1294
- // ...aliases,
1295
1401
  border: rawValue => {
1296
1402
  return [['borderTop', rawValue], ['borderEnd', rawValue], ['borderBottom', rawValue], ['borderStart', rawValue]];
1297
1403
  },
1298
- /*
1299
- // Add this later, as this will be a breaking change
1300
- border: (rawValue: string) => {
1301
- if (typeof rawValue === 'number') {
1302
- return expansions.borderWidth(rawValue);
1303
- }
1304
- const [width, style, color] = splitValue(rawValue);
1305
- return [
1306
- ...expansions.borderWidth(width),
1307
- ...expansions.borderStyle(style),
1308
- ...expansions.borderColor(color),
1309
- ];
1310
- }
1311
- */
1404
+ // border: (rawValue: string) => {
1405
+ // if (typeof rawValue === 'number') {
1406
+ // return expansions.borderWidth(rawValue);
1407
+ // }
1408
+ // const [width, style, color, more] = splitValue(rawValue);
1409
+ // if (more != null) {
1410
+ // throw new Error(messages.MULTIPLE_DIRECTIONS_IN_SHORTHAND);
1411
+ // }
1412
+ // if (style == null || color == null) {
1413
+ // throw new Error(
1414
+ // 'Border shorthand requires at least 2 values - width, style and color.'
1415
+ // );
1416
+ // }
1417
+ // return [
1418
+ // ...expansions.borderWidth(width),
1419
+ // ...expansions.borderStyle(style),
1420
+ // ...expansions.borderColor(color),
1421
+ // ];
1422
+ // },
1423
+ // borderTop: (rawValue: string) => {
1424
+ // if (typeof rawValue === 'number') {
1425
+ // return [['borderTopWidth', rawValue + 'px']];
1426
+ // }
1427
+ // const [width, style, color] = splitValue(rawValue);
1428
+ // if (style == null || color == null) {
1429
+ // throw new Error(
1430
+ // 'BorderTop shorthand requires at least 2 values - width, style and color.'
1431
+ // );
1432
+ // }
1433
+ // return [
1434
+ // ['borderTopWidth', width],
1435
+ // ['borderTopStyle', style],
1436
+ // ['borderTopColor', color],
1437
+ // ];
1438
+ // },
1439
+ // borderEnd: (rawValue: string) => {
1440
+ // if (typeof rawValue === 'number') {
1441
+ // return [['borderEndWidth', rawValue + 'px']];
1442
+ // }
1443
+ // const [width, style, color] = splitValue(rawValue);
1444
+ // if (style == null || color == null) {
1445
+ // throw new Error(
1446
+ // 'BorderEnd shorthand requires at least 2 values - width, style and color.'
1447
+ // );
1448
+ // }
1449
+ // return [
1450
+ // ['borderEndWidth', width],
1451
+ // ['borderEndStyle', style],
1452
+ // ['borderEndColor', color],
1453
+ // ];
1454
+ // },
1455
+ // borderBottom: (rawValue: string) => {
1456
+ // if (typeof rawValue === 'number') {
1457
+ // return [['borderBottomWidth', rawValue + 'px']];
1458
+ // }
1459
+ // const [width, style, color] = splitValue(rawValue);
1460
+ // if (style == null || color == null) {
1461
+ // throw new Error(
1462
+ // 'BorderBottom shorthand requires at least 2 values - width, style and color.'
1463
+ // );
1464
+ // }
1465
+ // return [
1466
+ // ['borderBottomWidth', width],
1467
+ // ['borderBottomStyle', style],
1468
+ // ['borderBottomColor', color],
1469
+ // ];
1470
+ // },
1471
+ // borderStart: (rawValue: string) => {
1472
+ // if (typeof rawValue === 'number') {
1473
+ // return [['borderStartWidth', rawValue + 'px']];
1474
+ // }
1475
+ // const [width, style, color] = splitValue(rawValue);
1476
+ // if (style == null || color == null) {
1477
+ // throw new Error(
1478
+ // 'BorderStart shorthand requires at least 2 values - width, style and color.'
1479
+ // );
1480
+ // }
1481
+ // return [
1482
+ // ['borderStartWidth', width],
1483
+ // ['borderStartStyle', style],
1484
+ // ['borderStartColor', color],
1485
+ // ];
1486
+ // },
1312
1487
  borderColor: rawValue => {
1313
1488
  const [top, right = top, bottom = top, left = right] = splitValue(rawValue);
1314
1489
  return [['borderTopColor', top], ['borderEndColor', right], ['borderBottomColor', bottom], ['borderStartColor', left]];
@@ -1355,8 +1530,37 @@ const expansions = {
1355
1530
  },
1356
1531
  paddingVertical: rawValue => {
1357
1532
  return [['paddingTop', rawValue], ['paddingBottom', rawValue]];
1533
+ },
1534
+ gap: rawValue => {
1535
+ if (typeof rawValue === 'number') {
1536
+ return [['rowGap', rawValue], ['columnGap', rawValue]];
1537
+ }
1538
+ const [row, column = row] = splitValue(rawValue);
1539
+ return [['rowGap', row], ['columnGap', column]];
1540
+ },
1541
+ placeContent: rawValue => {
1542
+ const [align, justify = align] = splitValue(rawValue);
1543
+ return [['alignContent', align], ['justifyContent', justify]];
1544
+ },
1545
+ placeItems: rawValue => {
1546
+ const [align, justify = align] = splitValue(rawValue);
1547
+ return [['alignItems', align], ['justifyItems', justify]];
1548
+ },
1549
+ placeSelf: rawValue => {
1550
+ const [align, justify = align] = splitValue(rawValue);
1551
+ return [['alignSelf', align], ['justifySelf', justify]];
1552
+ },
1553
+ scrollMargin: rawValue => {
1554
+ const [top, right = top, bottom = top, left = right] = typeof rawValue === 'number' ? [rawValue] : splitValue(rawValue);
1555
+ return [['scrollMarginTop', top], ['scrollMarginEnd', right], ['scrollMarginBottom', bottom], ['scrollMarginStart', left]];
1556
+ },
1557
+ scrollPadding: rawValue => {
1558
+ const [top, right = top, bottom = top, left = right] = typeof rawValue === 'number' ? [rawValue] : splitValue(rawValue);
1559
+ return [['scrollPaddingTop', top], ['scrollPaddingEnd', right], ['scrollPaddingBottom', bottom], ['scrollPaddingStart', left]];
1358
1560
  }
1359
1561
  };
1562
+ const expandedKeys = [...Object.keys(expansions), ...Object.keys(BANNED_PROPERTIES)];
1563
+ expandShorthands.expandedKeys = expandedKeys;
1360
1564
  function flatMapExpandedShorthands(objEntry) {
1361
1565
  const [key, value] = objEntry;
1362
1566
  const expansion = expansions[key];
@@ -1414,7 +1618,7 @@ Object.defineProperty(objectUtils, "__esModule", {
1414
1618
  value: true
1415
1619
  });
1416
1620
  objectUtils.Pipe = void 0;
1417
- objectUtils.flattenObject = flattenObject$1;
1621
+ objectUtils.flattenObject = flattenObject;
1418
1622
  objectUtils.objEntries = objEntries;
1419
1623
  objectUtils.objFromEntries = objFromEntries;
1420
1624
  objectUtils.objMap = objMap;
@@ -1433,10 +1637,10 @@ var _stylexInclude$2 = stylexInclude$1;
1433
1637
 
1434
1638
  // A bunch of object utils with better Flow types
1435
1639
 
1436
- function flattenObject$1(obj) {
1640
+ function flattenObject(obj) {
1437
1641
  const result = {};
1438
1642
  for (const [key, value] of objEntries(obj)) {
1439
- if (typeof value === 'string') {
1643
+ if (typeof value === 'string' || value == null) {
1440
1644
  result[key] = value;
1441
1645
  } else if (value instanceof _stylexInclude$2.IncludedStyles) {
1442
1646
  result[key] = value;
@@ -1503,18 +1707,18 @@ class Pipe {
1503
1707
  }
1504
1708
  objectUtils.Pipe = Pipe;
1505
1709
 
1506
- Object.defineProperty(stylexCreate, "__esModule", {
1710
+ Object.defineProperty(stylexCreate$1, "__esModule", {
1507
1711
  value: true
1508
1712
  });
1509
- stylexCreate.default = styleXCreateSet;
1510
- var _convertToClassName = _interopRequireDefault$2(convertToClassName$1);
1511
- var _expandShorthands$1 = _interopRequireDefault$2(expandShorthands);
1713
+ stylexCreate$1.default = styleXCreateSet;
1714
+ var _convertToClassName = _interopRequireDefault$4(convertToClassName$1);
1715
+ var _expandShorthands$1 = _interopRequireWildcard$1(expandShorthands);
1512
1716
  var _objectUtils$1 = objectUtils;
1513
1717
  var messages$1 = _interopRequireWildcard$1(messages$4);
1514
1718
  var _stylexInclude$1 = stylexInclude$1;
1515
1719
  function _getRequireWildcardCache$1(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache$1 = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
1516
1720
  function _interopRequireWildcard$1(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache$1(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
1517
- function _interopRequireDefault$2(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1721
+ function _interopRequireDefault$4(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1518
1722
  /**
1519
1723
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1520
1724
  *
@@ -1544,7 +1748,11 @@ function styleXCreateSet(namespaces) {
1544
1748
  throw new Error(messages$1.ILLEGAL_NAMESPACE_VALUE);
1545
1749
  }
1546
1750
  const [resolvedNamespace, injected] = styleXCreateNamespace(namespace, options);
1547
- resolvedNamespaces[namespaceName] = (0, _objectUtils$1.flattenObject)(resolvedNamespace);
1751
+ const compiledNamespace = (0, _objectUtils$1.flattenObject)(resolvedNamespace);
1752
+ resolvedNamespaces[namespaceName] = {
1753
+ ...compiledNamespace,
1754
+ $$css: true
1755
+ };
1548
1756
  for (const cn of Object.keys(injected)) {
1549
1757
  if (injectedStyles[cn] == null) {
1550
1758
  injectedStyles[cn] = injected[cn];
@@ -1580,7 +1788,7 @@ function styleXCreateNamespace(style, options) {
1580
1788
  return [[key, value]];
1581
1789
  }
1582
1790
  if (value != null && typeof value === 'object' && !Array.isArray(value)) {
1583
- if (!key.startsWith(':') && !key.startsWith('@')) {
1791
+ if (!key.startsWith(':') && !key.startsWith('@') && _expandShorthands$1.expandedKeys.includes(key)) {
1584
1792
  throw new Error(messages$1.INVALID_PSEUDO);
1585
1793
  }
1586
1794
  return [[key, (0, _objectUtils$1.objFromEntries)((0, _objectUtils$1.objEntries)(value).flatMap(_ref2 => {
@@ -1588,15 +1796,21 @@ function styleXCreateNamespace(style, options) {
1588
1796
  if (innerValue != null && typeof innerValue === 'object' && !Array.isArray(innerValue)) {
1589
1797
  throw new Error(messages$1.ILLEGAL_NESTED_PSEUDO);
1590
1798
  }
1799
+ if (!options.allowUnsafeProperties && _expandShorthands$1.BANNED_PROPERTIES[key]) {
1800
+ throw new Error(_expandShorthands$1.BANNED_PROPERTIES[key]);
1801
+ }
1591
1802
  return (0, _expandShorthands$1.default)([innerKey, innerValue]);
1592
1803
  }))]];
1593
1804
  } else {
1594
- if (typeof value !== 'string' && typeof value !== 'number' && !Array.isArray(value)) {
1805
+ if (value !== null && typeof value !== 'string' && typeof value !== 'number' && !Array.isArray(value)) {
1595
1806
  throw new Error(messages$1.ILLEGAL_PROP_VALUE);
1596
1807
  }
1597
1808
  if (Array.isArray(value) && value.some(val => typeof val === 'object')) {
1598
1809
  throw new Error(messages$1.ILLEGAL_PROP_ARRAY_VALUE);
1599
1810
  }
1811
+ if (!options.allowUnsafeProperties && _expandShorthands$1.BANNED_PROPERTIES[key]) {
1812
+ throw new Error(_expandShorthands$1.BANNED_PROPERTIES[key]);
1813
+ }
1600
1814
  return (0, _expandShorthands$1.default)([key, value]);
1601
1815
  }
1602
1816
  });
@@ -1612,18 +1826,42 @@ function styleXCreateNamespace(style, options) {
1612
1826
  if (val instanceof _stylexInclude$1.IncludedStyles) {
1613
1827
  resolvedNamespace[key] = val;
1614
1828
  } else if (val != null && typeof val === 'object' && !Array.isArray(val)) {
1615
- const pseudo = key;
1616
- const innerObj = {};
1617
- for (const [innerKey, innerVal] of (0, _objectUtils$1.objEntries)(val)) {
1618
- const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([innerKey, innerVal], pseudo, options);
1619
- innerObj[updatedKey] = className;
1620
- injectedStyles[updatedKey + pseudo] = [className, cssRule];
1829
+ if (key.startsWith(':') || key.startsWith('@')) {
1830
+ const pseudo = key;
1831
+ const innerObj = {};
1832
+ for (const [innerKey, innerVal] of (0, _objectUtils$1.objEntries)(val)) {
1833
+ if (innerVal === null) {
1834
+ innerObj[innerKey] = null;
1835
+ } else {
1836
+ const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([innerKey, innerVal], pseudo, options);
1837
+ innerObj[updatedKey] = className;
1838
+ injectedStyles[updatedKey + pseudo] = [className, cssRule];
1839
+ }
1840
+ }
1841
+ resolvedNamespace[key] = innerObj;
1842
+ } else {
1843
+ const propKey = key;
1844
+ const classNames = [];
1845
+ for (const [pseudo, innerVal] of (0, _objectUtils$1.objEntries)(val)) {
1846
+ if (pseudo !== 'default' && !pseudo.startsWith(':') && !pseudo.startsWith('@')) {
1847
+ throw new Error(messages$1.INVALID_PSEUDO);
1848
+ }
1849
+ if (innerVal !== null) {
1850
+ const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([propKey, innerVal], pseudo === 'default' ? undefined : pseudo, options);
1851
+ injectedStyles[updatedKey + pseudo] = [className, cssRule];
1852
+ classNames.push(className);
1853
+ }
1854
+ }
1855
+ resolvedNamespace[key] = classNames.join(' ');
1621
1856
  }
1622
- resolvedNamespace[key] = innerObj;
1623
1857
  } else {
1624
- const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([key, val], undefined, options);
1625
- resolvedNamespace[updatedKey] = className;
1626
- injectedStyles[updatedKey] = [className, cssRule];
1858
+ if (val === null) {
1859
+ resolvedNamespace[key] = null;
1860
+ } else {
1861
+ const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([key, val], undefined, options);
1862
+ resolvedNamespace[updatedKey] = className;
1863
+ injectedStyles[updatedKey] = [className, cssRule];
1864
+ }
1627
1865
  }
1628
1866
  }
1629
1867
  const finalInjectedStyles = (0, _objectUtils$1.objFromEntries)((0, _objectUtils$1.objValues)(injectedStyles));
@@ -1636,14 +1874,14 @@ Object.defineProperty(stylexKeyframes, "__esModule", {
1636
1874
  value: true
1637
1875
  });
1638
1876
  stylexKeyframes.default = styleXKeyframes;
1639
- var _hash = _interopRequireDefault$1(hash$1);
1640
- var _expandShorthands = _interopRequireDefault$1(expandShorthands);
1641
- var _generateLtr = _interopRequireDefault$1(generateLtr);
1642
- var _generateRtl = _interopRequireDefault$1(generateRtl);
1643
- var _transformValue = _interopRequireDefault$1(transformValue$1);
1644
- var _dashify = _interopRequireDefault$1(dashify$1);
1877
+ var _hash = _interopRequireDefault$3(hash$1);
1878
+ var _expandShorthands = _interopRequireDefault$3(expandShorthands);
1879
+ var _generateLtr = _interopRequireDefault$3(generateLtr);
1880
+ var _generateRtl = _interopRequireDefault$3(generateRtl);
1881
+ var _transformValue = _interopRequireDefault$3(transformValue$1);
1882
+ var _dashify = _interopRequireDefault$3(dashify$1);
1645
1883
  var _objectUtils = objectUtils;
1646
- function _interopRequireDefault$1(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1884
+ function _interopRequireDefault$3(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1647
1885
  /**
1648
1886
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1649
1887
  *
@@ -1721,14 +1959,14 @@ Object.defineProperty(lib, "__esModule", {
1721
1959
  value: true
1722
1960
  });
1723
1961
  var messages_1 = lib.messages = keyframes_1 = lib.keyframes = include_1 = lib.include = firstThatWorks_1 = lib.firstThatWorks = create_1 = lib.create = IncludedStyles_1 = lib.IncludedStyles = void 0;
1724
- var _stylexCreate = _interopRequireDefault(stylexCreate);
1725
- var _stylexKeyframes = _interopRequireDefault(stylexKeyframes);
1962
+ var _stylexCreate = _interopRequireDefault$2(stylexCreate$1);
1963
+ var _stylexKeyframes = _interopRequireDefault$2(stylexKeyframes);
1726
1964
  var _stylexInclude = _interopRequireWildcard(stylexInclude$1);
1727
- var _stylexFirstThatWorks = _interopRequireDefault(stylexFirstThatWorks$1);
1965
+ var _stylexFirstThatWorks = _interopRequireDefault$2(stylexFirstThatWorks$1);
1728
1966
  var m = _interopRequireWildcard(messages$4);
1729
1967
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
1730
1968
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
1731
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1969
+ function _interopRequireDefault$2(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1732
1970
  /**
1733
1971
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1734
1972
  *
@@ -1788,7 +2026,8 @@ function convertToTestStyles(obj, varName, state) {
1788
2026
  for (const [key, value] of Object.entries(obj)) {
1789
2027
  const devClassName = namespaceToDevClassName(key, varName, state.filename ?? 'UnkownFile');
1790
2028
  result[key] = {
1791
- [devClassName]: devClassName
2029
+ [devClassName]: devClassName,
2030
+ $$css: true
1792
2031
  };
1793
2032
  }
1794
2033
  return result;
@@ -1803,7 +2042,7 @@ function convertToTestStyles(obj, varName, state) {
1803
2042
  function convertObjectToAST(obj) {
1804
2043
  return t__namespace.objectExpression(Object.entries(obj).map(_ref => {
1805
2044
  let [key, value] = _ref;
1806
- return value instanceof IncludedStyles_1 ? t__namespace.spreadElement(value.astNode) : t__namespace.objectProperty(canBeIdentifier(key) ? t__namespace.identifier(key) : t__namespace.stringLiteral(key), typeof value === 'string' ? t__namespace.stringLiteral(value) : convertObjectToAST(value));
2045
+ return value instanceof IncludedStyles_1 ? t__namespace.spreadElement(value.astNode) : t__namespace.objectProperty(canBeIdentifier(key) ? t__namespace.identifier(key) : t__namespace.stringLiteral(key), typeof value === 'string' ? t__namespace.stringLiteral(value) : typeof value === 'boolean' ? t__namespace.booleanLiteral(value) : value === null ? t__namespace.nullLiteral() : convertObjectToAST(value));
1807
2046
  }));
1808
2047
  }
1809
2048
  function canBeIdentifier(str) {
@@ -1836,14 +2075,10 @@ function canBeIdentifier(str) {
1836
2075
  const VALID_CALLEES = ['String', 'Number', 'Math'];
1837
2076
  const INVALID_METHODS = ['random'];
1838
2077
  function isValidCallee(val) {
1839
- return VALID_CALLEES.includes(
1840
- // @ts-expect-error
1841
- val);
2078
+ return VALID_CALLEES.includes(val);
1842
2079
  }
1843
2080
  function isInvalidMethod(val) {
1844
- return INVALID_METHODS.includes(
1845
- // @ts-expect-error
1846
- val);
2081
+ return INVALID_METHODS.includes(val);
1847
2082
  }
1848
2083
  /**
1849
2084
  * Deopts the evaluation
@@ -2190,6 +2425,13 @@ function evaluateQuasis(path, quasis, state) {
2190
2425
  let str = '';
2191
2426
  let i = 0;
2192
2427
  const exprs = path.get('expressions');
2428
+
2429
+ // const exprs: Array<NodePath<t.Node>> = path.isTemplateLiteral()
2430
+ // ? path.get('expressions')
2431
+ // : (path as NodePath<t.TaggedTemplateExpression>)
2432
+ // .get('quasi')
2433
+ // .get('expressions');
2434
+
2193
2435
  for (const elem of quasis) {
2194
2436
  // not confident, evaluated an expression we don't like
2195
2437
  if (!state.confident) break;
@@ -2270,7 +2512,7 @@ function transformStyleXCreate(path, state) {
2270
2512
  if (firstArg == null || !firstArg.isObjectExpression()) {
2271
2513
  throw new Error(messages_1.ILLEGAL_ARGUMENT_LENGTH);
2272
2514
  }
2273
- const processingState = preProcessStyleArg(firstArg);
2515
+ preProcessStyleArg(firstArg, state);
2274
2516
  const injectedKeyframes = {};
2275
2517
  function keyframes(animation) {
2276
2518
  const [animationName, injectedStyle] = keyframes_1(animation, state.options);
@@ -2343,20 +2585,12 @@ function transformStyleXCreate(path, state) {
2343
2585
  state.styleVars.set(varName, path.parentPath);
2344
2586
  }
2345
2587
  path.replaceWith(convertObjectToAST(compiledStyles));
2346
- postProcessStyles(path, processingState);
2347
2588
  if (Object.keys(injectedStyles).length === 0) {
2348
2589
  return;
2349
2590
  }
2350
2591
  if (state.isDev || state.stylexSheetName == null) {
2351
2592
  const statementPath = findNearestStatementAncestor(path);
2352
- let stylexName;
2353
- state.stylexImport.forEach(importName => {
2354
- stylexName = importName;
2355
- });
2356
- if (stylexName == null) {
2357
- stylexName = '__stylex__';
2358
- statementPath.insertBefore(t__namespace.importDeclaration([t__namespace.importDefaultSpecifier(t__namespace.identifier(stylexName))], t__namespace.stringLiteral('stylex')));
2359
- }
2593
+ let stylexName = getStylexDefaultImport(path, state);
2360
2594
  for (const [key, {
2361
2595
  ltr,
2362
2596
  priority,
@@ -2402,13 +2636,8 @@ function findNearestStatementAncestor(path) {
2402
2636
  return findNearestStatementAncestor(path.parentPath);
2403
2637
  }
2404
2638
 
2405
- // These functions are for special handling of dynamic parts of the style object
2406
- // Currently they handle spreading pre-defined style objects with stylex.create calls.
2407
- //
2408
- // It converts the spreads into a special string and remembers the original value in an object...
2409
-
2410
- function preProcessStyleArg(objPath) {
2411
- const state = {};
2639
+ // Converts typed spreads to `stylex.include` calls.
2640
+ function preProcessStyleArg(objPath, state) {
2412
2641
  objPath.traverse({
2413
2642
  SpreadElement(path) {
2414
2643
  const argument = path.get('argument');
@@ -2431,36 +2660,23 @@ function preProcessStyleArg(objPath) {
2431
2660
  // Disallow spreads within pseudo or media query objects
2432
2661
  throw new Error(messages_1.ILLEGAL_NESTED_PSEUDO);
2433
2662
  }
2434
- const key = `include(${toString(expression)})`;
2435
- path.replaceWith(t__namespace.objectProperty(t__namespace.stringLiteral(key), t__namespace.stringLiteral(key)));
2436
- state[key] = expression.node;
2663
+ let stylexName = getStylexDefaultImport(path, state);
2664
+ argument.replaceWith(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.identifier(stylexName), t__namespace.identifier('include')), [expression.node]));
2437
2665
  }
2438
2666
  });
2439
- return state;
2440
2667
  }
2441
-
2442
- // Later, it finds those strings and replaces them back with their original values.
2443
- function postProcessStyles(objPath, state) {
2444
- objPath.traverse({
2445
- ObjectProperty(path) {
2446
- const node = path.node.key;
2447
- if (node.type === 'StringLiteral' && state[node.value] != null) {
2448
- path.replaceWith(t__namespace.spreadElement(state[node.value]));
2449
- }
2450
- }
2668
+ function getStylexDefaultImport(path, state) {
2669
+ const statementPath = findNearestStatementAncestor(path);
2670
+ let stylexName;
2671
+ state.stylexImport.forEach(importName => {
2672
+ stylexName = importName;
2451
2673
  });
2452
- }
2453
-
2454
- // A function to deterministicly convert a spreadded expression to a string.
2455
- function toString(path) {
2456
- if (path.isIdentifier()) {
2457
- return path.node.name;
2458
- } else if (path.isStringLiteral() || path.isNumericLiteral()) {
2459
- return String(path.node.value);
2460
- } else if (path.isMemberExpression()) {
2461
- return `${toString(path.get('object'))}.${toString(path.get('property'))}`;
2674
+ if (stylexName == null) {
2675
+ stylexName = '__stylex__';
2676
+ statementPath.insertBefore(t__namespace.importDeclaration([t__namespace.importDefaultSpecifier(t__namespace.identifier(stylexName))], t__namespace.stringLiteral('stylex')));
2677
+ state.stylexImport.add(stylexName);
2462
2678
  }
2463
- throw new Error(path.node.type);
2679
+ return stylexName;
2464
2680
  }
2465
2681
 
2466
2682
  /**
@@ -2551,6 +2767,422 @@ function assertValidKeyframes(obj) {
2551
2767
  }
2552
2768
  }
2553
2769
 
2770
+ var stylex$1 = {};
2771
+
2772
+ var stylexInject = {};
2773
+
2774
+ var StyleXSheet$1 = {};
2775
+
2776
+ /**
2777
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2778
+ *
2779
+ * This source code is licensed under the MIT license found in the
2780
+ * LICENSE file in the root directory of this source tree.
2781
+ *
2782
+ *
2783
+ */
2784
+
2785
+ Object.defineProperty(StyleXSheet$1, "__esModule", {
2786
+ value: true
2787
+ });
2788
+ StyleXSheet$1.styleSheet = StyleXSheet$1.StyleXSheet = void 0;
2789
+ var _invariant = _interopRequireDefault$1(require$$0$1);
2790
+ function _interopRequireDefault$1(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2791
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2792
+ const LIGHT_MODE_CLASS_NAME = '__fb-light-mode';
2793
+ const DARK_MODE_CLASS_NAME = '__fb-dark-mode';
2794
+ /**
2795
+ * Take a theme and generate it's accompanying CSS variables
2796
+ */
2797
+ function buildTheme(selector, theme) {
2798
+ const lines = [];
2799
+ lines.push(`${selector} {`);
2800
+ for (const key in theme) {
2801
+ const value = theme[key];
2802
+ lines.push(` --${key}: ${value};`);
2803
+ }
2804
+ lines.push('}');
2805
+ return lines.join('\n');
2806
+ }
2807
+
2808
+ /**
2809
+ * Create a <style> tag and add it to the head.
2810
+ */
2811
+ function makeStyleTag() {
2812
+ const tag = document.createElement('style');
2813
+ tag.setAttribute('type', 'text/css');
2814
+ tag.setAttribute('data-stylex', 'true');
2815
+ const head = document.head || document.getElementsByTagName('head')[0];
2816
+ (0, _invariant.default)(head, 'expected head');
2817
+ head.appendChild(tag);
2818
+ return tag;
2819
+ }
2820
+
2821
+ /**
2822
+ * Check if the browser supports CSS variables
2823
+ */
2824
+ function doesSupportCSSVariables() {
2825
+ return globalThis.CSS != null && globalThis.CSS.supports != null && globalThis.CSS.supports('--fake-var:0');
2826
+ }
2827
+
2828
+ // Regex to replace var(--foo) with an inlined version
2829
+ const VARIABLE_MATCH = /var\(--(.*?)\)/g;
2830
+
2831
+ // Stylesheet options
2832
+
2833
+ /**
2834
+ * This class manages the CSS stylesheet for the page and the injection of new
2835
+ * CSS rules.
2836
+ */
2837
+ class StyleXSheet {
2838
+ constructor(opts) {
2839
+ this.tag = null;
2840
+ this.injected = false;
2841
+ this.ruleForPriority = new Map();
2842
+ this.rules = [];
2843
+ this.rootTheme = opts.rootTheme;
2844
+ this.rootDarkTheme = opts.rootDarkTheme;
2845
+ this.supportsVariables = opts.supportsVariables ?? doesSupportCSSVariables();
2846
+ }
2847
+ getVariableMatch() {
2848
+ return VARIABLE_MATCH;
2849
+ }
2850
+
2851
+ /**
2852
+ * Check if we have don't have access to the dom
2853
+ */
2854
+ isHeadless() {
2855
+ var _globalThis$document;
2856
+ return this.tag == null || (globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.body) == null;
2857
+ }
2858
+
2859
+ /**
2860
+ * Get the stylesheet tag. Throw if none exists.
2861
+ */
2862
+ getTag() {
2863
+ const {
2864
+ tag
2865
+ } = this;
2866
+ (0, _invariant.default)(tag != null, 'expected tag');
2867
+ return tag;
2868
+ }
2869
+
2870
+ /**
2871
+ * Get the current stylesheet CSS.
2872
+ */
2873
+ getCSS() {
2874
+ return this.rules.join('\n');
2875
+ }
2876
+
2877
+ /**
2878
+ * Get the position of the rule in the stylesheet.
2879
+ */
2880
+ getRulePosition(rule) {
2881
+ return this.rules.indexOf(rule);
2882
+ }
2883
+
2884
+ /**
2885
+ * Count of the current rules in the stylesheet. Used in tests.
2886
+ */
2887
+ getRuleCount() {
2888
+ return this.rules.length;
2889
+ }
2890
+
2891
+ /**
2892
+ * Inject a style tag into the document head
2893
+ */
2894
+ inject() {
2895
+ var _globalThis$document2;
2896
+ if (this.injected) {
2897
+ return;
2898
+ }
2899
+ this.injected = true;
2900
+
2901
+ // Running in a server environment
2902
+ if (((_globalThis$document2 = globalThis.document) === null || _globalThis$document2 === void 0 ? void 0 : _globalThis$document2.body) == null) {
2903
+ this.injectTheme();
2904
+ return;
2905
+ }
2906
+
2907
+ // Create style tag if in browser
2908
+ this.tag = makeStyleTag();
2909
+ this.injectTheme();
2910
+ }
2911
+
2912
+ /**
2913
+ * Inject the theme styles
2914
+ */
2915
+ injectTheme() {
2916
+ if (this.rootTheme != null) {
2917
+ this.insert(buildTheme(`:root, .${LIGHT_MODE_CLASS_NAME}`, this.rootTheme), 0);
2918
+ }
2919
+ if (this.rootDarkTheme != null) {
2920
+ this.insert(buildTheme(`.${DARK_MODE_CLASS_NAME}:root, .${DARK_MODE_CLASS_NAME}`, this.rootDarkTheme), 0);
2921
+ }
2922
+ }
2923
+
2924
+ /**
2925
+ * Inject custom theme styles (only for internal testing)
2926
+ */
2927
+ __injectCustomThemeForTesting(selector, theme) {
2928
+ if (theme != null) {
2929
+ this.insert(buildTheme(selector, theme), 0);
2930
+ }
2931
+ }
2932
+
2933
+ /**
2934
+ * Delete the requested rule from the stylesheet
2935
+ */
2936
+ delete(rule) {
2937
+ // Get the index of this rule
2938
+ const index = this.rules.indexOf(rule);
2939
+ (0, _invariant.default)(index >= 0, "Couldn't find the index for rule %s", rule);
2940
+
2941
+ // Remove the rule from our index
2942
+ this.rules.splice(index, 1);
2943
+ if (this.isHeadless()) {
2944
+ return;
2945
+ }
2946
+ const tag = this.getTag();
2947
+ const sheet = tag.sheet;
2948
+ (0, _invariant.default)(sheet, 'expected sheet');
2949
+ sheet.deleteRule(index);
2950
+ }
2951
+
2952
+ /**
2953
+ *
2954
+ */
2955
+ normalizeRule(rule) {
2956
+ const {
2957
+ rootTheme
2958
+ } = this;
2959
+ if (this.supportsVariables || rootTheme == null) {
2960
+ return rule;
2961
+ }
2962
+ return rule.replace(VARIABLE_MATCH, (_match, name) => {
2963
+ return rootTheme[name];
2964
+ });
2965
+ }
2966
+
2967
+ /**
2968
+ * Get the rule position a rule should be inserted at according to the
2969
+ * specified priority.
2970
+ */
2971
+ getInsertPositionForPriority(priority) {
2972
+ // If there's an end rule associated with this priority, then get the next
2973
+ // rule which will belong to the next priority
2974
+ // The rule will be inserted before it and assigned to the current priority
2975
+ const priorityRule = this.ruleForPriority.get(priority);
2976
+ if (priorityRule != null) {
2977
+ return this.rules.indexOf(priorityRule) + 1;
2978
+ }
2979
+
2980
+ // If we've never created this priority before, then let's find the highest
2981
+ // priority to target
2982
+ const priorities = Array.from(this.ruleForPriority.keys()).sort((a, b) => b - a).filter(num => num > priority ? 1 : 0);
2983
+
2984
+ // If there's no priorities then place us at the start
2985
+ if (priorities.length === 0) {
2986
+ return this.getRuleCount();
2987
+ }
2988
+
2989
+ // Place us next to the next highest priority
2990
+ const lastPriority = priorities.pop();
2991
+ return this.rules.indexOf(this.ruleForPriority.get(lastPriority));
2992
+ }
2993
+
2994
+ /**
2995
+ * Insert a rule into the stylesheet.
2996
+ */
2997
+ insert(rawLTRRule, priority, rawRTLRule) {
2998
+ // Inject the stylesheet if it hasn't already been
2999
+ if (this.injected === false) {
3000
+ this.inject();
3001
+ }
3002
+ if (rawRTLRule != null) {
3003
+ this.insert(addAncestorSelector$1(rawLTRRule, "html:not([dir='rtl'])"), priority);
3004
+ this.insert(addAncestorSelector$1(rawRTLRule, "html[dir='rtl']"), priority);
3005
+ return;
3006
+ }
3007
+ const rawRule = rawLTRRule;
3008
+
3009
+ // Don't insert this rule if it already exists
3010
+ if (this.rules.includes(rawRule)) {
3011
+ return;
3012
+ }
3013
+ const rule = this.normalizeRule(rawRule);
3014
+
3015
+ // Get the position where we should insert the rule
3016
+ const insertPos = this.getInsertPositionForPriority(priority);
3017
+ this.rules.splice(insertPos, 0, rule);
3018
+
3019
+ // Set this rule as the end of the priority group
3020
+ this.ruleForPriority.set(priority, rule);
3021
+ if (this.isHeadless()) {
3022
+ return;
3023
+ }
3024
+ const tag = this.getTag();
3025
+ const sheet = tag.sheet;
3026
+ if (sheet != null) {
3027
+ try {
3028
+ sheet.insertRule(rule, insertPos);
3029
+ } catch {
3030
+ // Ignore: error likely due to inserting prefixed rules (e.g. `::-moz-range-thumb`).
3031
+ }
3032
+ }
3033
+ // Ignore the case where sheet == null. It's an edge-case Edge 17 bug.
3034
+ }
3035
+ }
3036
+
3037
+ /**
3038
+ * Adds an ancestor selector in a media-query-aware way.
3039
+ */
3040
+ StyleXSheet$1.StyleXSheet = StyleXSheet;
3041
+ _defineProperty(StyleXSheet, "LIGHT_MODE_CLASS_NAME", LIGHT_MODE_CLASS_NAME);
3042
+ _defineProperty(StyleXSheet, "DARK_MODE_CLASS_NAME", DARK_MODE_CLASS_NAME);
3043
+ function addAncestorSelector$1(selector, ancestorSelector) {
3044
+ if (!selector.startsWith('@')) {
3045
+ return `${ancestorSelector} ${selector}`;
3046
+ }
3047
+ const firstBracketIndex = selector.indexOf('{');
3048
+ const mediaQueryPart = selector.slice(0, firstBracketIndex + 1);
3049
+ const rest = selector.slice(firstBracketIndex + 1);
3050
+ return `${mediaQueryPart}${ancestorSelector} ${rest}`;
3051
+ }
3052
+ const styleSheet = new StyleXSheet({
3053
+ supportsVariables: true,
3054
+ rootTheme: {},
3055
+ rootDarkTheme: {}
3056
+ });
3057
+ StyleXSheet$1.styleSheet = styleSheet;
3058
+
3059
+ Object.defineProperty(stylexInject, "__esModule", {
3060
+ value: true
3061
+ });
3062
+ stylexInject.default = inject;
3063
+ var _StyleXSheet = StyleXSheet$1;
3064
+ /**
3065
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3066
+ *
3067
+ * This source code is licensed under the MIT license found in the
3068
+ * LICENSE file in the root directory of this source tree.
3069
+ *
3070
+ *
3071
+ */
3072
+
3073
+ function inject(ltrRule, priority) {
3074
+ let rtlRule = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
3075
+ _StyleXSheet.styleSheet.insert(ltrRule, priority, rtlRule);
3076
+ }
3077
+
3078
+ /**
3079
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3080
+ *
3081
+ * This source code is licensed under the MIT license found in the
3082
+ * LICENSE file in the root directory of this source tree.
3083
+ *
3084
+ *
3085
+ */
3086
+
3087
+ Object.defineProperty(stylex$1, "__esModule", {
3088
+ value: true
3089
+ });
3090
+ var default_1 = stylex$1.default = void 0;
3091
+ var _stylexInject = _interopRequireDefault(stylexInject);
3092
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
3093
+ const cache = new WeakMap() ;
3094
+ function stylex() {
3095
+ // Keep a set of property commits to the className
3096
+ const definedProperties = [];
3097
+ let className = '';
3098
+ let nextCache = cache;
3099
+ for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
3100
+ styles[_key] = arguments[_key];
3101
+ }
3102
+ while (styles.length) {
3103
+ // Push nested styles back onto the stack to be processed
3104
+ const possibleStyle = styles.pop();
3105
+ if (Array.isArray(possibleStyle)) {
3106
+ for (let i = 0; i < possibleStyle.length; i++) {
3107
+ styles.push(possibleStyle[i]);
3108
+ }
3109
+ continue;
3110
+ }
3111
+
3112
+ // Process an individual style object
3113
+ const styleObj = possibleStyle;
3114
+ if (styleObj != null && typeof styleObj === 'object') {
3115
+ // Build up the class names defined by this object
3116
+ let classNameChunk = '';
3117
+ if (nextCache != null && nextCache.has(styleObj)) {
3118
+ // Cache: read
3119
+ const cacheEntry = nextCache.get(styleObj);
3120
+ if (cacheEntry != null) {
3121
+ classNameChunk = cacheEntry.classNameChunk;
3122
+ definedProperties.push(...cacheEntry.definedPropertiesChunk);
3123
+ nextCache = cacheEntry.next;
3124
+ }
3125
+ } else {
3126
+ // Record the properties this object defines (and that haven't already
3127
+ // been defined by later objects.)
3128
+ const definedPropertiesChunk = [];
3129
+ for (const prop in styleObj) {
3130
+ const value = styleObj[prop];
3131
+ // Style declarations, e.g., opacity: 's3fkgpd'
3132
+ if (typeof value === 'string' || value === null) {
3133
+ // Skip adding to the chunks if property has already been seen
3134
+ if (!definedProperties.includes(prop)) {
3135
+ definedProperties.push(prop);
3136
+ definedPropertiesChunk.push(prop);
3137
+ if (typeof value === 'string') {
3138
+ classNameChunk += classNameChunk ? ' ' + value : value;
3139
+ }
3140
+ }
3141
+ }
3142
+ }
3143
+ // Cache: write
3144
+ if (nextCache != null) {
3145
+ const emptyCache = new WeakMap();
3146
+ nextCache.set(styleObj, {
3147
+ classNameChunk,
3148
+ definedPropertiesChunk,
3149
+ next: emptyCache
3150
+ });
3151
+ nextCache = emptyCache;
3152
+ }
3153
+ }
3154
+
3155
+ // Order of classes in chunks matches property-iteration order of style
3156
+ // object. Order of chunks matches passed order of styles from first to
3157
+ // last (which we iterate over in reverse).
3158
+ if (classNameChunk) {
3159
+ className = className ? classNameChunk + ' ' + className : classNameChunk;
3160
+ }
3161
+ }
3162
+ }
3163
+ return className;
3164
+ }
3165
+ function stylexCreate(_styles) {
3166
+ throw new Error('stylex.create should never be called. It should be compiled away.');
3167
+ }
3168
+ function stylexIncludes(_styles) {
3169
+ throw new Error('stylex.extends should never be called. It should be compiled away.');
3170
+ }
3171
+ stylex.create = stylexCreate;
3172
+ stylex.include = stylexIncludes;
3173
+ stylex.keyframes = _keyframes => {
3174
+ throw new Error('stylex.keyframes should never be called');
3175
+ };
3176
+ stylex.firstThatWorks = function () {
3177
+ throw new Error('stylex.firstThatWorks should never be called.');
3178
+ };
3179
+ stylex.inject = _stylexInject.default;
3180
+ stylex.UNSUPPORTED_PROPERTY = props => {
3181
+ throw new Error('stylex.UNSUPPORTED_PROPERTY should never be called. It should be compiled away.');
3182
+ };
3183
+ var _default = stylex;
3184
+ default_1 = stylex$1.default = _default;
3185
+
2554
3186
  /**
2555
3187
  * Copyright (c) Meta Platforms, Inc. and affiliates.
2556
3188
  *
@@ -2578,38 +3210,21 @@ function transformStyleXMerge(path, state) {
2578
3210
  return;
2579
3211
  }
2580
3212
  let bailOut = false;
2581
- const resolvedStyles = {};
2582
- for (const arg of node.arguments) {
3213
+ let conditional = false;
3214
+ const resolvedArgs = [];
3215
+ loop: for (const arg of node.arguments) {
2583
3216
  switch (arg.type) {
2584
3217
  case 'MemberExpression':
2585
- const {
2586
- property,
2587
- object,
2588
- computed
2589
- } = arg;
2590
- let objName = null;
2591
- let propName = null;
2592
- if (object.type === 'Identifier' && state.styleMap.has(object.name) && property.type === 'Identifier' && !computed) {
2593
- objName = object.name;
2594
- propName = property.name;
2595
- }
2596
- if (object.type === 'Identifier' && state.styleMap.has(object.name) && (property.type === 'StringLiteral' || property.type === 'NumericLiteral') && computed) {
2597
- objName = object.name;
2598
- propName = property.value;
2599
- }
2600
- if (objName != null && propName != null) {
2601
- const style = state.styleMap.get(objName);
2602
- if (style == null || style[propName] == null) {
2603
- throw new Error(`Unknown style ${objName}.${propName}. The defined style ${objName}, contains the following keys: ${Object.keys(style ?? {}).join(', ')}`);
2604
- }
2605
- const namespace = flattenObject(style[propName]);
2606
- Object.assign(resolvedStyles, namespace);
2607
- } else {
2608
- // Unknown style found. bail out.
3218
+ const resolved = parseNullableStyle(arg, state);
3219
+ if (resolved === 'other') {
2609
3220
  bailOut = true;
3221
+ break loop;
3222
+ } else {
3223
+ resolvedArgs.push(resolved);
2610
3224
  }
2611
3225
  break;
2612
3226
  case 'ConditionalExpression':
3227
+ conditional = true;
2613
3228
  const {
2614
3229
  test,
2615
3230
  consequent,
@@ -2619,53 +3234,36 @@ function transformStyleXMerge(path, state) {
2619
3234
  const fallback = parseNullableStyle(alternate, state);
2620
3235
  if (primary === 'other' || fallback === 'other') {
2621
3236
  bailOut = true;
2622
- break;
2623
- }
2624
- if (primary === null && fallback === null) {
2625
- // A no-op
2626
- break;
2627
- }
2628
- const allKeys = new Set([...Object.keys(primary ?? {}), ...Object.keys(fallback ?? {})]);
2629
- for (const key of allKeys) {
2630
- if (resolvedStyles[key] == null) {
2631
- const primaryValue = (primary === null || primary === void 0 ? void 0 : primary[key]) ?? resolvedStyles[key] ?? '';
2632
- const fallbackValue = (fallback === null || fallback === void 0 ? void 0 : fallback[key]) ?? resolvedStyles[key] ?? '';
2633
- resolvedStyles[key] = [test, primaryValue, fallbackValue];
2634
- }
3237
+ break loop;
2635
3238
  }
3239
+ resolvedArgs.push([test, primary, fallback]);
2636
3240
  break;
2637
3241
  case 'LogicalExpression':
3242
+ conditional = true;
2638
3243
  if (arg.operator !== '&&') {
2639
3244
  bailOut = true;
2640
- break;
3245
+ break loop;
2641
3246
  }
2642
3247
  const {
2643
3248
  left,
2644
3249
  right
2645
3250
  } = arg;
2646
- if (left.type === 'MemberExpression' && left.object.type === 'Identifier' && state.styleMap.has(left.object.name)) {
2647
- // We don't support `a && b` in stylex calls where `a` is a style namespace.
3251
+ const leftResolved = parseNullableStyle(left, state);
3252
+ const rightResolved = parseNullableStyle(right, state);
3253
+ if (leftResolved !== 'other' || rightResolved === 'other') {
2648
3254
  bailOut = true;
2649
- break;
2650
- }
2651
- const value = parseNullableStyle(right, state);
2652
- if (value === 'other') {
2653
- bailOut = true;
2654
- break;
2655
- }
2656
- if (value === null) {
2657
- // A no-op??
2658
- break;
2659
- }
2660
- for (const [key, val] of Object.entries(value)) {
2661
- resolvedStyles[key] = [left, val, resolvedStyles[key] ?? ''];
3255
+ break loop;
2662
3256
  }
3257
+ resolvedArgs.push([left, rightResolved, null]);
2663
3258
  break;
2664
3259
  default:
2665
3260
  bailOut = true;
2666
3261
  break;
2667
3262
  }
2668
3263
  }
3264
+ if (!state.options.genConditionalClasses && conditional) {
3265
+ bailOut = true;
3266
+ }
2669
3267
  if (bailOut) {
2670
3268
  path.traverse({
2671
3269
  MemberExpression(path) {
@@ -2692,27 +3290,11 @@ function transformStyleXMerge(path, state) {
2692
3290
  path.skip();
2693
3291
  // convert resolvedStyles to a string + ternary expressions
2694
3292
  // We no longer need the keys, so we can just use the values.
2695
- const stringExpression = makeStringExpression(Object.values(resolvedStyles));
3293
+ const stringExpression = makeStringExpression(resolvedArgs);
2696
3294
  path.replaceWith(stringExpression);
2697
3295
  }
2698
3296
  }
2699
3297
 
2700
- // This function takes nested objects with styles collapses them to a single level deep.
2701
- // `':hover': {color: 'red'}` becomes `':hover.color': 'red'`
2702
- function flattenObject(object) {
2703
- const result = {};
2704
- for (const [key, value] of Object.entries(object)) {
2705
- if (typeof value === 'string') {
2706
- result[key] = value;
2707
- } else if (typeof value === 'object') {
2708
- for (const [subKey, subValue] of Object.entries(value)) {
2709
- result[`${key}.${subKey}`] = subValue;
2710
- }
2711
- }
2712
- }
2713
- return result;
2714
- }
2715
-
2716
3298
  // Looks for Null or locally defined style namespaces.
2717
3299
  // Otherwise it returns the string "other"
2718
3300
  // Which is used as an indicator to bail out of this optimization.
@@ -2722,72 +3304,81 @@ function parseNullableStyle(node, state) {
2722
3304
  }
2723
3305
  if (t__namespace.isMemberExpression(node)) {
2724
3306
  const {
2725
- object: obj,
2726
- property: prop,
3307
+ object,
3308
+ property,
2727
3309
  computed: computed
2728
3310
  } = node;
2729
- if (obj.type !== 'Identifier' || !state.styleMap.has(obj.name) || prop.type !== 'Identifier' || computed) {
2730
- return 'other';
2731
- }
2732
- const namespace1 = state.styleMap.get(obj.name);
2733
- if (namespace1 == null) {
2734
- return 'other';
2735
- }
2736
- const style = namespace1[prop.name];
2737
- if (style == null) {
2738
- return 'other';
3311
+ let objName = null;
3312
+ let propName = null;
3313
+ if (object.type === 'Identifier' && state.styleMap.has(object.name) && property.type === 'Identifier' && !computed) {
3314
+ objName = object.name;
3315
+ propName = property.name;
3316
+ }
3317
+ if (object.type === 'Identifier' && state.styleMap.has(object.name) && (property.type === 'StringLiteral' || property.type === 'NumericLiteral') && computed) {
3318
+ objName = object.name;
3319
+ propName = property.value;
3320
+ }
3321
+ if (objName != null && propName != null) {
3322
+ const style = state.styleMap.get(objName);
3323
+ if (style != null && style[propName] != null) {
3324
+ return style[propName];
3325
+ }
2739
3326
  }
2740
- return flattenObject(style);
2741
- } else {
2742
- return 'other';
2743
3327
  }
3328
+ return 'other';
2744
3329
  }
2745
3330
  function makeStringExpression(values) {
2746
- let inTernary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2747
- // To start let's split the plain strings and everything else.
2748
- let strings = values.filter(value => typeof value === 'string').join(' ').trim();
2749
- if (inTernary && strings !== '') {
2750
- strings = ' ' + strings;
2751
- }
2752
- const nonStrings = values.filter(value => typeof value !== 'string');
2753
- const groupedByTest = groupBy(nonStrings, _ref => {
2754
- let [test, _a, _b] = _ref;
2755
- return test;
2756
- });
2757
- const eachTernary = [...groupedByTest.entries()].map(_ref2 => {
2758
- let [test, value] = _ref2;
2759
- const consequents = makeStringExpression(value.map(_ref3 => {
2760
- let [_a, a, _b] = _ref3;
2761
- return a;
2762
- }), true);
2763
- const fallbacks = makeStringExpression(value.map(_ref4 => {
2764
- let [_a, _b, b] = _ref4;
2765
- return b;
2766
- }), true);
2767
- return t__namespace.conditionalExpression(test, consequents, fallbacks);
3331
+ const conditions = values.filter(v => Array.isArray(v)).map(v => v[0]);
3332
+ if (conditions.length === 0) {
3333
+ return t__namespace.stringLiteral(default_1(...values));
3334
+ }
3335
+ const conditionPermutations = genConditionPermutations(conditions.length);
3336
+ const objEntries = conditionPermutations.map(permutation => {
3337
+ let i = 0;
3338
+ const args = values.map(v => {
3339
+ if (Array.isArray(v)) {
3340
+ const [test, primary, fallback] = v;
3341
+ return permutation[i++] ? primary : fallback;
3342
+ } else {
3343
+ return v;
3344
+ }
3345
+ });
3346
+ const key = permutation.reduce((soFar, bool) => soFar << 1 | (bool ? 1 : 0), 0);
3347
+ return t__namespace.objectProperty(t__namespace.numericLiteral(key), t__namespace.stringLiteral(default_1(...args)));
2768
3348
  });
2769
- return addAll([t__namespace.stringLiteral(strings), ...eachTernary]);
2770
- }
2771
- function addAll(_ref5) {
2772
- let [first, ...nodes] = _ref5;
2773
- if (nodes.length === 0) {
2774
- return first;
2775
- }
2776
- return t__namespace.binaryExpression('+', first, addAll(nodes));
3349
+ const objExpressions = t__namespace.objectExpression(objEntries);
3350
+ const conditionsToKey = genBitwiseOrOfConditions(conditions);
3351
+ return t__namespace.memberExpression(objExpressions, conditionsToKey, true);
2777
3352
  }
2778
3353
 
2779
- // Array groupBy function
2780
- function groupBy(array, key) {
2781
- const result = new Map();
2782
- for (const item of array) {
2783
- const k = key(item);
2784
- const array = result.get(k) ?? [];
2785
- array.push(item);
2786
- result.set(k, array);
3354
+ // A function to generate a list of all possible permutations of true and false for a given count of conditional expressions.
3355
+ // For example, if there are 2 conditional expressions, this function will return:
3356
+ // [[true, true], [true, false], [false, true], [false, false]]
3357
+ function genConditionPermutations(count) {
3358
+ const result = [];
3359
+ for (let i = 0; i < 2 ** count; i++) {
3360
+ const combination = [];
3361
+ for (let j = 0; j < count; j++) {
3362
+ combination.push(Boolean(i & 1 << j));
3363
+ }
3364
+ result.push(combination);
2787
3365
  }
2788
3366
  return result;
2789
3367
  }
2790
3368
 
3369
+ // A function to generate a bitwise or of all the conditions.
3370
+ // For example, if there are 2 conditional expressions, this function will return:
3371
+ // `!!test1 << 2 | !!test2 << 1
3372
+ function genBitwiseOrOfConditions(conditions) {
3373
+ const binaryExpressions = conditions.map((condition, i) => {
3374
+ const shift = conditions.length - i - 1;
3375
+ return t__namespace.binaryExpression('<<', t__namespace.unaryExpression('!', t__namespace.unaryExpression('!', condition)), t__namespace.numericLiteral(shift));
3376
+ });
3377
+ return binaryExpressions.reduce((acc, expr) => {
3378
+ return t__namespace.binaryExpression('|', acc, expr);
3379
+ });
3380
+ }
3381
+
2791
3382
  /**
2792
3383
  * Copyright (c) Meta Platforms, Inc. and affiliates.
2793
3384
  *