@stylexjs/babel-plugin 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -398,17 +398,20 @@ class StateManager {
398
398
  return identifier;
399
399
  }
400
400
  const bodyPath = programPath.get('body');
401
- let lastImportIndex = -1;
401
+ let targetImportIndex = -1;
402
402
  for (let i = 0; i < bodyPath.length; i++) {
403
403
  const statement = bodyPath[i];
404
404
  if (isImportDeclaration(statement)) {
405
- lastImportIndex = i;
405
+ targetImportIndex = i;
406
+ if (statement.node.specifiers.find(s => s.type === 'ImportSpecifier' && s.local.type === 'Identifier' && s.local.name === identifier.name)) {
407
+ break;
408
+ }
406
409
  }
407
410
  }
408
- if (lastImportIndex === -1) {
411
+ if (targetImportIndex === -1) {
409
412
  return identifier;
410
413
  }
411
- const lastImport = bodyPath[lastImportIndex];
414
+ const lastImport = bodyPath[targetImportIndex];
412
415
  if (lastImport == null) {
413
416
  return identifier;
414
417
  }
@@ -423,17 +426,20 @@ class StateManager {
423
426
  return identifier;
424
427
  }
425
428
  const bodyPath = programPath.get('body');
426
- let lastImportIndex = -1;
429
+ let targetImportIndex = -1;
427
430
  for (let i = 0; i < bodyPath.length; i++) {
428
431
  const statement = bodyPath[i];
429
432
  if (isImportDeclaration(statement)) {
430
- lastImportIndex = i;
433
+ targetImportIndex = i;
434
+ if (statement.node.specifiers.find(s => s.type === 'ImportDefaultSpecifier' && s.local.type === 'Identifier' && s.local.name === identifier.name)) {
435
+ break;
436
+ }
431
437
  }
432
438
  }
433
- if (lastImportIndex === -1) {
439
+ if (targetImportIndex === -1) {
434
440
  return identifier;
435
441
  }
436
- const lastImport = bodyPath[lastImportIndex];
442
+ const lastImport = bodyPath[targetImportIndex];
437
443
  if (lastImport == null) {
438
444
  return identifier;
439
445
  }
@@ -514,6 +520,38 @@ class StateManager {
514
520
  addStyle(style) {
515
521
  this.metadata.stylex.push(style);
516
522
  }
523
+ registerStyles(styles, path) {
524
+ if (styles.length === 0) {
525
+ return;
526
+ }
527
+ styles.forEach(style => this.addStyle(style));
528
+ if (path == null || this.runtimeInjection == null) {
529
+ return;
530
+ }
531
+ const runtimeInjection = this.runtimeInjection;
532
+ const statementPath = path.parentPath != null && isProgram(path.parentPath) ? path : getProgramStatement(path);
533
+ let injectName;
534
+ if (this.injectImportInserted != null) {
535
+ injectName = this.injectImportInserted;
536
+ } else {
537
+ const {
538
+ from,
539
+ as
540
+ } = runtimeInjection;
541
+ injectName = as != null ? this.addNamedImport(statementPath, as, from, {
542
+ nameHint: 'inject'
543
+ }) : this.addDefaultImport(statementPath, from, {
544
+ nameHint: 'inject'
545
+ });
546
+ this.injectImportInserted = injectName;
547
+ }
548
+ for (const [_key, {
549
+ ltr,
550
+ rtl
551
+ }, priority] of styles) {
552
+ statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority), ...(rtl != null ? [t__namespace.stringLiteral(rtl)] : [])])));
553
+ }
554
+ }
517
555
  markComposedNamespace(memberExpression) {
518
556
  this.styleVarsToKeep.add(memberExpression);
519
557
  }
@@ -581,6 +619,13 @@ const getProgramPath = path => {
581
619
  }
582
620
  return programPath;
583
621
  };
622
+ const getProgramStatement = path => {
623
+ let programPath = path;
624
+ while (programPath.parentPath != null && !isProgram(programPath.parentPath) && programPath.parentPath != null) {
625
+ programPath = programPath.parentPath;
626
+ }
627
+ return programPath;
628
+ };
584
629
 
585
630
  function readImportDeclarations(path, state) {
586
631
  const {
@@ -702,53 +747,54 @@ var objectUtils = {};
702
747
 
703
748
  var stylexInclude$2 = {};
704
749
 
705
- var messages$3 = {};
750
+ var messages$4 = {};
706
751
 
707
- Object.defineProperty(messages$3, "__esModule", {
752
+ Object.defineProperty(messages$4, "__esModule", {
708
753
  value: true
709
754
  });
710
- messages$3.UNKNOWN_PROP_KEY = messages$3.UNKNOWN_NAMESPACE = messages$3.UNEXPECTED_ARGUMENT = messages$3.UNBOUND_STYLEX_CALL_VALUE = messages$3.ONLY_TOP_LEVEL_INCLUDES = messages$3.ONLY_TOP_LEVEL = messages$3.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = messages$3.NO_PROJECT_ROOT_DIRECTORY = messages$3.NO_PARENT_PATH = messages$3.NO_CONDITIONAL_SHORTHAND = messages$3.NON_STATIC_VALUE = messages$3.NON_STATIC_KEYFRAME_VALUE = messages$3.NON_OBJECT_KEYFRAME = messages$3.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = messages$3.NON_OBJECT_FOR_STYLEX_CALL = messages$3.NON_EXPORT_NAMED_DECLARATION = messages$3.LOCAL_ONLY = messages$3.LINT_UNCLOSED_FUNCTION = messages$3.INVALID_SPREAD = messages$3.INVALID_PSEUDO_OR_AT_RULE = messages$3.INVALID_PSEUDO = messages$3.ILLEGAL_PROP_VALUE = messages$3.ILLEGAL_PROP_ARRAY_VALUE = messages$3.ILLEGAL_NESTED_PSEUDO = messages$3.ILLEGAL_NAMESPACE_VALUE = messages$3.ILLEGAL_NAMESPACE_TYPE = messages$3.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = messages$3.ILLEGAL_ARGUMENT_LENGTH = messages$3.EXPECTED_FUNCTION_CALL = messages$3.ESCAPED_STYLEX_VALUE = messages$3.DUPLICATE_CONDITIONAL = messages$3.ANONYMOUS_THEME = void 0;
711
- messages$3.ILLEGAL_ARGUMENT_LENGTH = 'stylex.create() should have 1 argument.';
712
- messages$3.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = 'stylex.keyframes() should have 1 argument.';
713
- messages$3.NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
714
- messages$3.NON_STATIC_KEYFRAME_VALUE = 'Only static values are allowed inside of a stylex.keyframes() call.';
715
- messages$3.ESCAPED_STYLEX_VALUE = 'Escaping a stylex.create() value is not allowed.';
716
- messages$3.UNBOUND_STYLEX_CALL_VALUE = 'stylex.create calls must be bound to a bare variable.';
717
- messages$3.ONLY_TOP_LEVEL = 'stylex.create() is only allowed at the root of a program.';
718
- messages$3.NON_OBJECT_FOR_STYLEX_CALL = 'stylex.create() can only accept a style object.';
719
- messages$3.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = 'stylex.keyframes() can only accept an object.';
720
- messages$3.UNKNOWN_PROP_KEY = 'Unknown property key';
721
- messages$3.INVALID_PSEUDO = 'Invalid pseudo selector, not on the whitelist.';
722
- messages$3.INVALID_PSEUDO_OR_AT_RULE = 'Invalid pseudo or at-rule.';
723
- messages$3.NO_CONDITIONAL_SHORTHAND = 'You cannot use conditional style values for a shorthand property.';
724
- messages$3.ILLEGAL_NAMESPACE_TYPE = 'Only a string literal namespace is allowed here.';
725
- messages$3.UNKNOWN_NAMESPACE = 'Unknown namespace';
726
- messages$3.ILLEGAL_NESTED_PSEUDO = "Pseudo objects can't be nested more than one level deep.";
727
- messages$3.ILLEGAL_PROP_VALUE = 'A style value can only contain an array, string or number.';
728
- messages$3.ILLEGAL_PROP_ARRAY_VALUE = 'A style array value can only contain strings or numbers.';
729
- messages$3.ILLEGAL_NAMESPACE_VALUE = 'A stylex namespace must be an object.';
730
- messages$3.NON_OBJECT_KEYFRAME = 'Every frame within a stylex.keyframes() call must be an object.';
731
- messages$3.INVALID_SPREAD = 'Imported styles spread with a stylex.create call must be type cast as `XStyle<>` to verify their type.';
732
- messages$3.LINT_UNCLOSED_FUNCTION = 'Rule contains an unclosed function';
733
- messages$3.LOCAL_ONLY = 'The return value of stylex.create() should not be exported.';
734
- messages$3.UNEXPECTED_ARGUMENT = 'Unexpected argument passed to the stylex() function.';
735
- messages$3.EXPECTED_FUNCTION_CALL = 'Expected a simple function call but found something else.';
736
- messages$3.NO_PARENT_PATH = 'Unexpected AST node without a parent path.';
737
- messages$3.ONLY_TOP_LEVEL_INCLUDES = 'stylex.include() is only at the top level of a style definition object.';
738
- messages$3.DUPLICATE_CONDITIONAL = 'The same pseudo selector or at-rule cannot be used more than once.';
739
- messages$3.NO_PROJECT_ROOT_DIRECTORY = 'The project root directory `rootDir` is not configured.';
740
- messages$3.NON_EXPORT_NAMED_DECLARATION = 'The return value of stylex.defineVars() must be bound to a named export.';
741
- messages$3.ANONYMOUS_THEME = 'stylex.createTheme() must be bound to a named constant.';
742
- messages$3.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
755
+ messages$4.UNKNOWN_PROP_KEY = messages$4.UNKNOWN_NAMESPACE = messages$4.UNEXPECTED_ARGUMENT = messages$4.UNBOUND_STYLEX_CALL_VALUE = messages$4.ONLY_TOP_LEVEL_INCLUDES = messages$4.ONLY_TOP_LEVEL = messages$4.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = messages$4.NO_PROJECT_ROOT_DIRECTORY = messages$4.NO_PARENT_PATH = messages$4.NO_CONDITIONAL_SHORTHAND = messages$4.NON_STATIC_VALUE = messages$4.NON_STATIC_KEYFRAME_VALUE = messages$4.NON_OBJECT_KEYFRAME = messages$4.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = messages$4.NON_OBJECT_FOR_STYLEX_CALL = messages$4.NON_EXPORT_NAMED_DECLARATION = messages$4.NON_CONTIGUOUS_VARS = messages$4.LOCAL_ONLY = messages$4.LINT_UNCLOSED_FUNCTION = messages$4.INVALID_SPREAD = messages$4.INVALID_PSEUDO_OR_AT_RULE = 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_ARG_LENGTH_FOR_KEYFRAMES = messages$4.ILLEGAL_ARGUMENT_LENGTH = messages$4.EXPECTED_FUNCTION_CALL = messages$4.ESCAPED_STYLEX_VALUE = messages$4.DUPLICATE_CONDITIONAL = messages$4.ANONYMOUS_THEME = void 0;
756
+ messages$4.ILLEGAL_ARGUMENT_LENGTH = 'stylex.create() should have 1 argument.';
757
+ messages$4.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = 'stylex.keyframes() should have 1 argument.';
758
+ messages$4.NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
759
+ messages$4.NON_STATIC_KEYFRAME_VALUE = 'Only static values are allowed inside of a stylex.keyframes() call.';
760
+ messages$4.ESCAPED_STYLEX_VALUE = 'Escaping a stylex.create() value is not allowed.';
761
+ messages$4.UNBOUND_STYLEX_CALL_VALUE = 'stylex.create calls must be bound to a bare variable.';
762
+ messages$4.ONLY_TOP_LEVEL = 'stylex.create() is only allowed at the root of a program.';
763
+ messages$4.NON_OBJECT_FOR_STYLEX_CALL = 'stylex.create() can only accept a style object.';
764
+ messages$4.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = 'stylex.keyframes() can only accept an object.';
765
+ messages$4.UNKNOWN_PROP_KEY = 'Unknown property key';
766
+ messages$4.INVALID_PSEUDO = 'Invalid pseudo selector, not on the whitelist.';
767
+ messages$4.INVALID_PSEUDO_OR_AT_RULE = 'Invalid pseudo or at-rule.';
768
+ messages$4.NO_CONDITIONAL_SHORTHAND = 'You cannot use conditional style values for a shorthand property.';
769
+ messages$4.ILLEGAL_NAMESPACE_TYPE = 'Only a string literal namespace is allowed here.';
770
+ messages$4.UNKNOWN_NAMESPACE = 'Unknown namespace';
771
+ messages$4.ILLEGAL_NESTED_PSEUDO = "Pseudo objects can't be nested more than one level deep.";
772
+ messages$4.ILLEGAL_PROP_VALUE = 'A style value can only contain an array, string or number.';
773
+ messages$4.ILLEGAL_PROP_ARRAY_VALUE = 'A style array value can only contain strings or numbers.';
774
+ messages$4.ILLEGAL_NAMESPACE_VALUE = 'A stylex namespace must be an object.';
775
+ messages$4.NON_OBJECT_KEYFRAME = 'Every frame within a stylex.keyframes() call must be an object.';
776
+ messages$4.INVALID_SPREAD = 'Imported styles spread with a stylex.create call must be type cast as `XStyle<>` to verify their type.';
777
+ messages$4.LINT_UNCLOSED_FUNCTION = 'Rule contains an unclosed function';
778
+ messages$4.LOCAL_ONLY = 'The return value of stylex.create() should not be exported.';
779
+ messages$4.UNEXPECTED_ARGUMENT = 'Unexpected argument passed to the stylex() function.';
780
+ messages$4.EXPECTED_FUNCTION_CALL = 'Expected a simple function call but found something else.';
781
+ messages$4.NO_PARENT_PATH = 'Unexpected AST node without a parent path.';
782
+ messages$4.ONLY_TOP_LEVEL_INCLUDES = 'stylex.include() is only at the top level of a style definition object.';
783
+ messages$4.DUPLICATE_CONDITIONAL = 'The same pseudo selector or at-rule cannot be used more than once.';
784
+ messages$4.NO_PROJECT_ROOT_DIRECTORY = 'The project root directory `rootDir` is not configured.';
785
+ messages$4.NON_EXPORT_NAMED_DECLARATION = 'The return value of stylex.defineVars() must be bound to a named export.';
786
+ messages$4.ANONYMOUS_THEME = 'stylex.createTheme() must be bound to a named constant.';
787
+ messages$4.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
788
+ messages$4.NON_CONTIGUOUS_VARS = 'All variables passed to `stylex.firstThatWorks` must be contiguous.';
743
789
 
744
790
  Object.defineProperty(stylexInclude$2, "__esModule", {
745
791
  value: true
746
792
  });
747
793
  stylexInclude$2.IncludedStyles = void 0;
748
794
  stylexInclude$2.default = stylexInclude$1;
749
- var messages$2 = _interopRequireWildcard$3(messages$3);
750
- function _getRequireWildcardCache$3(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache$3 = function (e) { return e ? t : r; })(e); }
751
- function _interopRequireWildcard$3(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache$3(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
795
+ var messages$3 = _interopRequireWildcard$4(messages$4);
796
+ function _getRequireWildcardCache$4(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache$4 = function (e) { return e ? t : r; })(e); }
797
+ function _interopRequireWildcard$4(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache$4(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
752
798
  let number = 0;
753
799
  function uuid() {
754
800
  return `__included_${++number}__`;
@@ -761,7 +807,7 @@ class IncludedStyles {
761
807
  stylexInclude$2.IncludedStyles = IncludedStyles;
762
808
  function stylexInclude$1(firstArg) {
763
809
  if ((arguments.length <= 1 ? 0 : arguments.length - 1) > 0) {
764
- throw new Error(messages$2.ILLEGAL_ARGUMENT_LENGTH);
810
+ throw new Error(messages$3.ILLEGAL_ARGUMENT_LENGTH);
765
811
  }
766
812
  return {
767
813
  [uuid()]: new IncludedStyles(firstArg.node)
@@ -1082,8 +1128,8 @@ Object.defineProperty(splitCssValue, "__esModule", {
1082
1128
  value: true
1083
1129
  });
1084
1130
  splitCssValue.default = splitValue;
1085
- var _postcssValueParser$6 = _interopRequireDefault$h(require$$0);
1086
- function _interopRequireDefault$h(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1131
+ var _postcssValueParser$5 = _interopRequireDefault$g(require$$0);
1132
+ function _interopRequireDefault$g(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1087
1133
  function printNode(node) {
1088
1134
  switch (node.type) {
1089
1135
  case 'word':
@@ -1102,7 +1148,7 @@ function splitValue(str) {
1102
1148
  if (Array.isArray(str)) {
1103
1149
  return str;
1104
1150
  }
1105
- const parsed = (0, _postcssValueParser$6.default)(str.trim());
1151
+ const parsed = (0, _postcssValueParser$5.default)(str.trim());
1106
1152
  const nodes = parsed.nodes.filter(node => node.type !== 'space' && node.type !== 'div').map(printNode);
1107
1153
  if (nodes.length > 1 && nodes[nodes.length - 1].toLowerCase() === '!important') {
1108
1154
  return nodes.slice(0, nodes.length - 1).map(node => node + ' !important');
@@ -1114,8 +1160,8 @@ Object.defineProperty(legacyExpandShorthands, "__esModule", {
1114
1160
  value: true
1115
1161
  });
1116
1162
  legacyExpandShorthands.default = void 0;
1117
- var _splitCssValue = _interopRequireDefault$g(splitCssValue);
1118
- function _interopRequireDefault$g(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1163
+ var _splitCssValue = _interopRequireDefault$f(splitCssValue);
1164
+ function _interopRequireDefault$f(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1119
1165
  const shorthands$1 = {
1120
1166
  border: rawValue => {
1121
1167
  return [['borderTop', rawValue], ['borderEnd', rawValue], ['borderBottom', rawValue], ['borderStart', rawValue]];
@@ -1358,10 +1404,10 @@ Object.defineProperty(preprocessRules, "__esModule", {
1358
1404
  });
1359
1405
  preprocessRules.default = flatMapExpandedShorthands;
1360
1406
  preprocessRules.getExpandedKeys = getExpandedKeys;
1361
- var _applicationOrder = _interopRequireDefault$f(applicationOrder);
1362
- var _legacyExpandShorthands = _interopRequireDefault$f(legacyExpandShorthands);
1363
- var _propertySpecificity = _interopRequireDefault$f(propertySpecificity);
1364
- function _interopRequireDefault$f(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1407
+ var _applicationOrder = _interopRequireDefault$e(applicationOrder);
1408
+ var _legacyExpandShorthands = _interopRequireDefault$e(legacyExpandShorthands);
1409
+ var _propertySpecificity = _interopRequireDefault$e(propertySpecificity);
1410
+ function _interopRequireDefault$e(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1365
1411
  const expansions = {
1366
1412
  'application-order': _applicationOrder.default,
1367
1413
  'property-specificity': _propertySpecificity.default,
@@ -1447,8 +1493,8 @@ Object.defineProperty(fontSizePxToRem, "__esModule", {
1447
1493
  value: true
1448
1494
  });
1449
1495
  fontSizePxToRem.default = convertFontSizeToRem;
1450
- var _postcssValueParser$5 = _interopRequireDefault$e(require$$0);
1451
- function _interopRequireDefault$e(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1496
+ var _postcssValueParser$4 = _interopRequireDefault$d(require$$0);
1497
+ function _interopRequireDefault$d(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1452
1498
  const ROOT_FONT_SIZE = 16;
1453
1499
  function convertFontSizeToRem(ast, key) {
1454
1500
  if (key !== 'fontSize') {
@@ -1458,7 +1504,7 @@ function convertFontSizeToRem(ast, key) {
1458
1504
  if (node.type !== 'word') {
1459
1505
  return;
1460
1506
  }
1461
- const dimension = _postcssValueParser$5.default.unit(node.value);
1507
+ const dimension = _postcssValueParser$4.default.unit(node.value);
1462
1508
  if (dimension && dimension.unit === 'px') {
1463
1509
  node.value = `${parseFloat(dimension.number) / ROOT_FONT_SIZE}rem`;
1464
1510
  }
@@ -1472,8 +1518,8 @@ Object.defineProperty(leadingZero, "__esModule", {
1472
1518
  value: true
1473
1519
  });
1474
1520
  leadingZero.default = normalizeLeadingZero;
1475
- var _postcssValueParser$4 = _interopRequireDefault$d(require$$0);
1476
- function _interopRequireDefault$d(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1521
+ var _postcssValueParser$3 = _interopRequireDefault$c(require$$0);
1522
+ function _interopRequireDefault$c(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1477
1523
  function normalizeLeadingZero(ast, _) {
1478
1524
  ast.walk(node => {
1479
1525
  if (node.type !== 'word') {
@@ -1483,7 +1529,7 @@ function normalizeLeadingZero(ast, _) {
1483
1529
  if (Number.isNaN(value)) {
1484
1530
  return;
1485
1531
  }
1486
- const dimension = _postcssValueParser$4.default.unit(node.value);
1532
+ const dimension = _postcssValueParser$3.default.unit(node.value);
1487
1533
  if (value < 1 && value >= 0) {
1488
1534
  node.value = value.toString().replace('0.', '.') + (dimension ? dimension.unit : '');
1489
1535
  }
@@ -1509,14 +1555,14 @@ function normalizeQuotes(ast, _) {
1509
1555
  return ast;
1510
1556
  }
1511
1557
 
1512
- var timings$1 = {};
1558
+ var timings = {};
1513
1559
 
1514
- Object.defineProperty(timings$1, "__esModule", {
1560
+ Object.defineProperty(timings, "__esModule", {
1515
1561
  value: true
1516
1562
  });
1517
- timings$1.default = normalizeTimings;
1518
- var _postcssValueParser$3 = _interopRequireDefault$c(require$$0);
1519
- function _interopRequireDefault$c(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1563
+ timings.default = normalizeTimings;
1564
+ var _postcssValueParser$2 = _interopRequireDefault$b(require$$0);
1565
+ function _interopRequireDefault$b(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1520
1566
  function normalizeTimings(ast, _) {
1521
1567
  ast.walk(node => {
1522
1568
  if (node.type !== 'word') {
@@ -1526,7 +1572,7 @@ function normalizeTimings(ast, _) {
1526
1572
  if (Number.isNaN(value)) {
1527
1573
  return;
1528
1574
  }
1529
- const dimension = _postcssValueParser$3.default.unit(node.value);
1575
+ const dimension = _postcssValueParser$2.default.unit(node.value);
1530
1576
  if (!dimension || dimension.unit !== 'ms' || value < 10) {
1531
1577
  return;
1532
1578
  }
@@ -1586,56 +1632,19 @@ function normalizeWhitespace(ast, _) {
1586
1632
  return ast;
1587
1633
  }
1588
1634
 
1589
- var zeroDimensions = {};
1590
-
1591
- Object.defineProperty(zeroDimensions, "__esModule", {
1592
- value: true
1593
- });
1594
- zeroDimensions.default = normalizeZeroDimensions;
1595
- var _postcssValueParser$2 = _interopRequireDefault$b(require$$0);
1596
- function _interopRequireDefault$b(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1597
- const angles = ['deg', 'grad', 'turn', 'rad'];
1598
- const timings = ['ms', 's'];
1599
- function normalizeZeroDimensions(ast, _) {
1600
- let endFunction = 0;
1601
- ast.walk(node => {
1602
- if (node.type === 'function' && !endFunction) {
1603
- endFunction = node.sourceEndIndex ?? 0;
1604
- }
1605
- if (endFunction > 0 && node.sourceIndex > endFunction) {
1606
- endFunction = 0;
1607
- }
1608
- if (node.type !== 'word') {
1609
- return;
1610
- }
1611
- const dimension = _postcssValueParser$2.default.unit(node.value);
1612
- if (!dimension || dimension.number !== '0') {
1613
- return;
1614
- }
1615
- if (angles.indexOf(dimension.unit) !== -1) {
1616
- node.value = '0deg';
1617
- } else if (timings.indexOf(dimension.unit) !== -1) {
1618
- node.value = '0s';
1619
- } else if (!endFunction) {
1620
- node.value = '0';
1621
- }
1622
- });
1623
- return ast;
1624
- }
1625
-
1626
1635
  var detectUnclosedFns$1 = {};
1627
1636
 
1628
1637
  Object.defineProperty(detectUnclosedFns$1, "__esModule", {
1629
1638
  value: true
1630
1639
  });
1631
1640
  detectUnclosedFns$1.default = detectUnclosedFns;
1632
- var messages$1 = _interopRequireWildcard$2(messages$3);
1633
- function _getRequireWildcardCache$2(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache$2 = function (e) { return e ? t : r; })(e); }
1634
- function _interopRequireWildcard$2(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache$2(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
1641
+ var messages$2 = _interopRequireWildcard$3(messages$4);
1642
+ function _getRequireWildcardCache$3(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache$3 = function (e) { return e ? t : r; })(e); }
1643
+ function _interopRequireWildcard$3(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache$3(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
1635
1644
  function detectUnclosedFns(ast, _) {
1636
1645
  ast.walk(node => {
1637
1646
  if (node.type === 'function' && node.unclosed) {
1638
- throw new Error(messages$1.LINT_UNCLOSED_FUNCTION);
1647
+ throw new Error(messages$2.LINT_UNCLOSED_FUNCTION);
1639
1648
  }
1640
1649
  });
1641
1650
  return ast;
@@ -1672,14 +1681,13 @@ normalizeValue$1.default = normalizeValue;
1672
1681
  var _fontSizePxToRem = _interopRequireDefault$9(fontSizePxToRem);
1673
1682
  var _leadingZero = _interopRequireDefault$9(leadingZero);
1674
1683
  var _quotes = _interopRequireDefault$9(quotes);
1675
- var _timings = _interopRequireDefault$9(timings$1);
1684
+ var _timings = _interopRequireDefault$9(timings);
1676
1685
  var _whitespace = _interopRequireDefault$9(whitespace);
1677
- var _zeroDimensions = _interopRequireDefault$9(zeroDimensions);
1678
1686
  var _detectUnclosedFns = _interopRequireDefault$9(detectUnclosedFns$1);
1679
1687
  var _postcssValueParser$1 = _interopRequireDefault$9(require$$0);
1680
1688
  var _convertCamelCaseValues = _interopRequireDefault$9(convertCamelCaseValues);
1681
1689
  function _interopRequireDefault$9(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1682
- const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _zeroDimensions.default, _leadingZero.default, _quotes.default, _convertCamelCaseValues.default];
1690
+ const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _leadingZero.default, _quotes.default, _convertCamelCaseValues.default];
1683
1691
  function normalizeValue(value, key, _ref) {
1684
1692
  let {
1685
1693
  useRemForFontSize
@@ -2615,12 +2623,16 @@ Object.defineProperty(convertToClassName, "__esModule", {
2615
2623
  value: true
2616
2624
  });
2617
2625
  convertToClassName.convertStyleToClassName = convertStyleToClassName;
2626
+ convertToClassName.default = variableFallbacks;
2618
2627
  var _hash$4 = _interopRequireDefault$5(hash$1);
2619
2628
  var _dashify$1 = _interopRequireDefault$5(dashify$1);
2620
2629
  var _transformValue$1 = _interopRequireDefault$5(transformValue$1);
2621
2630
  var _generateCssRule = generateCssRule;
2622
2631
  var _defaultOptions$4 = defaultOptions;
2623
2632
  var _objectUtils$5 = objectUtils;
2633
+ var messages$1 = _interopRequireWildcard$2(messages$4);
2634
+ function _getRequireWildcardCache$2(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache$2 = function (e) { return e ? t : r; })(e); }
2635
+ function _interopRequireWildcard$2(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache$2(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
2624
2636
  function _interopRequireDefault$5(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2625
2637
  function convertStyleToClassName(objEntry, pseudos, atRules) {
2626
2638
  let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _defaultOptions$4.defaultOptions;
@@ -2629,7 +2641,10 @@ function convertStyleToClassName(objEntry, pseudos, atRules) {
2629
2641
  } = options;
2630
2642
  const [key, rawValue] = objEntry;
2631
2643
  const dashedKey = (0, _dashify$1.default)(key);
2632
- const value = Array.isArray(rawValue) ? rawValue.map(eachValue => (0, _transformValue$1.default)(key, eachValue, options)) : (0, _transformValue$1.default)(key, rawValue, options);
2644
+ let value = Array.isArray(rawValue) ? rawValue.map(eachValue => (0, _transformValue$1.default)(key, eachValue, options)) : (0, _transformValue$1.default)(key, rawValue, options);
2645
+ if (Array.isArray(value) && value.find(val => val.startsWith('var(') && val.endsWith(')'))) {
2646
+ value = variableFallbacks(value);
2647
+ }
2633
2648
  const sortedPseudos = (0, _objectUtils$5.arraySort)(pseudos ?? []);
2634
2649
  const sortedAtRules = (0, _objectUtils$5.arraySort)(atRules ?? []);
2635
2650
  const atRuleHashString = sortedPseudos.join('');
@@ -2640,6 +2655,31 @@ function convertStyleToClassName(objEntry, pseudos, atRules) {
2640
2655
  const cssRules = (0, _generateCssRule.generateRule)(className, dashedKey, value, pseudos, atRules);
2641
2656
  return [key, className, cssRules];
2642
2657
  }
2658
+ function variableFallbacks(values) {
2659
+ const firstVar = values.findIndex(val => val.startsWith('var(') && val.endsWith(')'));
2660
+ const lastVar = values.findLastIndex(val => val.startsWith('var(') && val.endsWith(')'));
2661
+ const valuesBeforeFirstVar = values.slice(0, firstVar);
2662
+ let varValues = values.slice(firstVar, lastVar + 1).reverse();
2663
+ const valuesAfterLastVar = values.slice(lastVar + 1);
2664
+ if (varValues.find(val => !val.startsWith('var(') || !val.endsWith(')'))) {
2665
+ throw new Error(messages$1.NON_CONTIGUOUS_VARS);
2666
+ }
2667
+ varValues = varValues.map(val => val.slice(4, -1));
2668
+ return [...(valuesBeforeFirstVar.length > 0 ? valuesBeforeFirstVar.map(val => composeVars(...varValues, val)) : composeVars(...varValues)), ...valuesAfterLastVar];
2669
+ }
2670
+ function composeVars() {
2671
+ for (var _len = arguments.length, vars = new Array(_len), _key = 0; _key < _len; _key++) {
2672
+ vars[_key] = arguments[_key];
2673
+ }
2674
+ const [first, ...rest] = vars;
2675
+ if (rest.length > 0) {
2676
+ return `var(${first},${composeVars(...rest)})`;
2677
+ } else if (first.startsWith('--')) {
2678
+ return `var(${first})`;
2679
+ } else {
2680
+ return first;
2681
+ }
2682
+ }
2643
2683
 
2644
2684
  Object.defineProperty(PreRule$1, "__esModule", {
2645
2685
  value: true
@@ -2853,7 +2893,7 @@ Object.defineProperty(basicValidation, "__esModule", {
2853
2893
  });
2854
2894
  basicValidation.validateNamespace = validateNamespace;
2855
2895
  var _stylexInclude$2 = stylexInclude$2;
2856
- var messages = _interopRequireWildcard$1(messages$3);
2896
+ var messages = _interopRequireWildcard$1(messages$4);
2857
2897
  var _objectUtils$3 = objectUtils;
2858
2898
  function _getRequireWildcardCache$1(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache$1 = function (e) { return e ? t : r; })(e); }
2859
2899
  function _interopRequireWildcard$1(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache$1(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -2981,6 +3021,224 @@ function styleXCreateSet(namespaces) {
2981
3021
 
2982
3022
  var stylexDefineVars$1 = {};
2983
3023
 
3024
+ var stylexVarsUtils = {};
3025
+
3026
+ Object.defineProperty(stylexVarsUtils, "__esModule", {
3027
+ value: true
3028
+ });
3029
+ stylexVarsUtils.collectVarsByAtRule = collectVarsByAtRule;
3030
+ stylexVarsUtils.getDefaultValue = getDefaultValue;
3031
+ stylexVarsUtils.priorityForAtRule = priorityForAtRule;
3032
+ stylexVarsUtils.wrapWithAtRules = wrapWithAtRules;
3033
+ const SPLIT_TOKEN = '__$$__';
3034
+ function collectVarsByAtRule(key, _ref) {
3035
+ let {
3036
+ nameHash,
3037
+ value
3038
+ } = _ref;
3039
+ let collection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
3040
+ let atRules = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
3041
+ if (typeof value === 'string' || typeof value === 'number') {
3042
+ const val = typeof value === 'number' ? value.toString() : value;
3043
+ const key = atRules.length === 0 ? 'default' : [...atRules].sort().join(SPLIT_TOKEN);
3044
+ collection[key] ??= [];
3045
+ collection[key].push(`--${nameHash}:${val};`);
3046
+ return;
3047
+ }
3048
+ if (value === null) {
3049
+ return;
3050
+ }
3051
+ if (Array.isArray(value)) {
3052
+ throw new Error('Array is not supported in stylex.defineVars');
3053
+ }
3054
+ if (typeof value === 'object') {
3055
+ if (value.default === undefined) {
3056
+ throw new Error('Default value is not defined for ' + key + ' variable.');
3057
+ }
3058
+ for (const atRule of Object.keys(value)) {
3059
+ collectVarsByAtRule(key, {
3060
+ nameHash,
3061
+ value: value[atRule]
3062
+ }, collection, atRule === 'default' ? atRules : [...atRules, atRule]);
3063
+ }
3064
+ }
3065
+ }
3066
+ function wrapWithAtRules(ltr, atRule) {
3067
+ return atRule.split(SPLIT_TOKEN).reduce((acc, atRule) => `${atRule}{${acc}}`, ltr);
3068
+ }
3069
+ function priorityForAtRule(atRule) {
3070
+ if (atRule === 'default') {
3071
+ return 0;
3072
+ }
3073
+ return atRule.split(SPLIT_TOKEN).length;
3074
+ }
3075
+ function getDefaultValue(value) {
3076
+ if (typeof value === 'string' || typeof value === 'number') {
3077
+ return value.toString();
3078
+ }
3079
+ if (value == null) {
3080
+ return null;
3081
+ }
3082
+ if (Array.isArray(value)) {
3083
+ throw new Error('Array is not supported in stylex.defineVars');
3084
+ }
3085
+ if (typeof value === 'object') {
3086
+ if (value.default === undefined) {
3087
+ throw new Error('Default value is not defined for variable.');
3088
+ }
3089
+ return getDefaultValue(value.default);
3090
+ }
3091
+ throw new Error('Invalid value in stylex.defineVars');
3092
+ }
3093
+
3094
+ var types$1 = {};
3095
+
3096
+ Object.defineProperty(types$1, "__esModule", {
3097
+ value: true
3098
+ });
3099
+ types$1.url = types$1.transformList = types$1.transformFunction = types$1.time = types$1.resolution = types$1.percentage = types$1.number = types$1.lengthPercentage = types$1.length = types$1.isCSSType = types$1.integer = types$1.image = types$1.color = types$1.angle = types$1.Url = types$1.TransformList = types$1.TransformFunction = types$1.Time = types$1.Resolution = types$1.Percentage = types$1.Num = types$1.LengthPercentage = types$1.Length = types$1.Integer = types$1.Image = types$1.Color = types$1.Angle = void 0;
3100
+ class BaseCSSType {
3101
+ constructor(value) {
3102
+ this.value = value;
3103
+ }
3104
+ }
3105
+ const isCSSType = value => {
3106
+ return value instanceof BaseCSSType && value.value != null && typeof value.syntax === 'string';
3107
+ };
3108
+ types$1.isCSSType = isCSSType;
3109
+ class Angle extends BaseCSSType {
3110
+ syntax = '<angle>';
3111
+ static syntax = '<angle>';
3112
+ static create(value) {
3113
+ return new Angle(value);
3114
+ }
3115
+ }
3116
+ types$1.Angle = Angle;
3117
+ types$1.angle = Angle.create;
3118
+ class Color extends BaseCSSType {
3119
+ syntax = '<color>';
3120
+ static create(value) {
3121
+ return new Color(value);
3122
+ }
3123
+ }
3124
+ types$1.Color = Color;
3125
+ types$1.color = Color.create;
3126
+ class Url extends BaseCSSType {
3127
+ syntax = '<url>';
3128
+ static create(value) {
3129
+ return new Url(value);
3130
+ }
3131
+ }
3132
+ types$1.Url = Url;
3133
+ types$1.url = Url.create;
3134
+ class Image extends Url {
3135
+ syntax = '<image>';
3136
+ constructor(value) {
3137
+ super(value);
3138
+ this.value = value;
3139
+ }
3140
+ static create(value) {
3141
+ return new Image(value);
3142
+ }
3143
+ }
3144
+ types$1.Image = Image;
3145
+ types$1.image = Image.create;
3146
+ class Integer extends BaseCSSType {
3147
+ syntax = '<integer>';
3148
+ static create(value) {
3149
+ return new Integer(convertNumberToStringUsing(String)(value));
3150
+ }
3151
+ }
3152
+ types$1.Integer = Integer;
3153
+ types$1.integer = Integer.create;
3154
+ class LengthPercentage extends BaseCSSType {
3155
+ syntax = '<length-percentage>';
3156
+ static createLength(value) {
3157
+ return new LengthPercentage(convertNumberToLength(value));
3158
+ }
3159
+ static createPercentage(value) {
3160
+ return new LengthPercentage(convertNumberToPercentage(value));
3161
+ }
3162
+ }
3163
+ types$1.LengthPercentage = LengthPercentage;
3164
+ types$1.lengthPercentage = LengthPercentage.createLength;
3165
+ class Length extends LengthPercentage {
3166
+ syntax = '<length>';
3167
+ static create(value) {
3168
+ return new Length(convertNumberToLength(value));
3169
+ }
3170
+ }
3171
+ types$1.Length = Length;
3172
+ types$1.length = Length.create;
3173
+ class Percentage extends LengthPercentage {
3174
+ syntax = '<percentage>';
3175
+ static create(value) {
3176
+ return new Percentage(convertNumberToPercentage(value));
3177
+ }
3178
+ }
3179
+ types$1.Percentage = Percentage;
3180
+ types$1.percentage = Percentage.create;
3181
+ class Num extends BaseCSSType {
3182
+ syntax = '<number>';
3183
+ static create(value) {
3184
+ return new Num(convertNumberToBareString(value));
3185
+ }
3186
+ }
3187
+ types$1.Num = Num;
3188
+ types$1.number = Num.create;
3189
+ class Resolution extends BaseCSSType {
3190
+ syntax = '<resolution>';
3191
+ static create(value) {
3192
+ return new Resolution(value);
3193
+ }
3194
+ }
3195
+ types$1.Resolution = Resolution;
3196
+ types$1.resolution = Resolution.create;
3197
+ class Time extends BaseCSSType {
3198
+ syntax = '<time>';
3199
+ static create(value) {
3200
+ return new Time(value);
3201
+ }
3202
+ }
3203
+ types$1.Time = Time;
3204
+ types$1.time = Time.create;
3205
+ class TransformFunction extends BaseCSSType {
3206
+ syntax = '<transform-function>';
3207
+ static create(value) {
3208
+ return new TransformFunction(value);
3209
+ }
3210
+ }
3211
+ types$1.TransformFunction = TransformFunction;
3212
+ types$1.transformFunction = TransformFunction.create;
3213
+ class TransformList extends BaseCSSType {
3214
+ syntax = '<transform-list>';
3215
+ static create(value) {
3216
+ return new TransformList(value);
3217
+ }
3218
+ }
3219
+ types$1.TransformList = TransformList;
3220
+ types$1.transformList = TransformList.create;
3221
+ const convertNumberToStringUsing = (transformNumber, defaultStr) => value => {
3222
+ if (typeof value === 'number') {
3223
+ return transformNumber(value);
3224
+ }
3225
+ if (typeof value === 'string') {
3226
+ return value;
3227
+ }
3228
+ if (typeof value === 'object') {
3229
+ const val = value;
3230
+ const result = {};
3231
+ for (const key of Object.keys(val)) {
3232
+ result[key] = convertNumberToStringUsing(transformNumber)(val[key]);
3233
+ }
3234
+ return result;
3235
+ }
3236
+ return value;
3237
+ };
3238
+ const convertNumberToBareString = convertNumberToStringUsing(value => String(value));
3239
+ const convertNumberToLength = convertNumberToStringUsing(value => value === 0 ? '0' : `${value}px`);
3240
+ const convertNumberToPercentage = convertNumberToStringUsing(value => value === 0 ? '0' : `${value * 100}%`);
3241
+
2984
3242
  Object.defineProperty(stylexDefineVars$1, "__esModule", {
2985
3243
  value: true
2986
3244
  });
@@ -2988,6 +3246,8 @@ stylexDefineVars$1.default = styleXDefineVars;
2988
3246
  var _hash$3 = _interopRequireDefault$3(hash$1);
2989
3247
  var _objectUtils$1 = objectUtils;
2990
3248
  var _defaultOptions$2 = defaultOptions;
3249
+ var _stylexVarsUtils$1 = stylexVarsUtils;
3250
+ var _types$2 = types$1;
2991
3251
  function _interopRequireDefault$3(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2992
3252
  function styleXDefineVars(variables, options) {
2993
3253
  const {
@@ -2998,8 +3258,20 @@ function styleXDefineVars(variables, options) {
2998
3258
  ...options
2999
3259
  };
3000
3260
  const themeNameHash = classNamePrefix + (0, _hash$3.default)(themeName);
3261
+ const typedVariables = {};
3001
3262
  const variablesMap = (0, _objectUtils$1.objMap)(variables, (value, key) => {
3002
3263
  const nameHash = classNamePrefix + (0, _hash$3.default)(`${themeName}.${key}`);
3264
+ if ((0, _types$2.isCSSType)(value)) {
3265
+ const v = value;
3266
+ typedVariables[nameHash] = {
3267
+ initialValue: (0, _stylexVarsUtils$1.getDefaultValue)(v.value),
3268
+ syntax: v.syntax
3269
+ };
3270
+ return {
3271
+ nameHash,
3272
+ value: v.value
3273
+ };
3274
+ }
3003
3275
  return {
3004
3276
  nameHash,
3005
3277
  value
@@ -3012,42 +3284,47 @@ function styleXDefineVars(variables, options) {
3012
3284
  return `var(--${nameHash})`;
3013
3285
  });
3014
3286
  const injectableStyles = constructCssVariablesString(variablesMap, themeNameHash);
3287
+ const injectableTypes = (0, _objectUtils$1.objMap)(typedVariables, (_ref2, nameHash) => {
3288
+ let {
3289
+ initialValue: iv,
3290
+ syntax
3291
+ } = _ref2;
3292
+ return {
3293
+ ltr: `@property --${nameHash} { syntax: "${syntax}"; inherits: true;${iv != null ? ` initial-value: ${iv}` : ''} }`,
3294
+ rtl: null,
3295
+ priority: 0
3296
+ };
3297
+ });
3015
3298
  return [{
3016
3299
  ...themeVariablesObject,
3017
3300
  __themeName__: themeNameHash
3018
- }, injectableStyles];
3301
+ }, {
3302
+ ...injectableTypes,
3303
+ ...injectableStyles
3304
+ }];
3019
3305
  }
3020
3306
  function constructCssVariablesString(variables, themeNameHash) {
3021
- const ruleByAtRule = {};
3307
+ const rulesByAtRule = {};
3022
3308
  for (const [key, {
3023
3309
  nameHash,
3024
3310
  value
3025
- }] of (0, _objectUtils$1.objEntries)(variables)) {
3026
- if (value !== null && typeof value === 'object') {
3027
- if (value.default === undefined) {
3028
- throw new Error('Default value is not defined for ' + key + ' variable.');
3029
- }
3030
- const v = value;
3031
- for (const [key, value] of (0, _objectUtils$1.objEntries)(v)) {
3032
- ruleByAtRule[key] ??= [];
3033
- ruleByAtRule[key].push(`--${nameHash}:${value};`);
3034
- }
3035
- } else {
3036
- ruleByAtRule.default ??= [];
3037
- ruleByAtRule.default.push(`--${nameHash}:${value};`);
3038
- }
3311
+ }] of Object.entries(variables)) {
3312
+ (0, _stylexVarsUtils$1.collectVarsByAtRule)(key, {
3313
+ nameHash,
3314
+ value
3315
+ }, rulesByAtRule);
3039
3316
  }
3040
3317
  const result = {};
3041
- for (const [key, value] of (0, _objectUtils$1.objEntries)(ruleByAtRule)) {
3042
- const suffix = key === 'default' ? '' : `-${(0, _hash$3.default)(key)}`;
3318
+ for (const [atRule, value] of Object.entries(rulesByAtRule)) {
3319
+ const suffix = atRule === 'default' ? '' : `-${(0, _hash$3.default)(atRule)}`;
3043
3320
  let ltr = `:root{${value.join('')}}`;
3044
- if (key !== 'default') {
3045
- ltr = `${key}{${ltr}}`;
3321
+ if (atRule !== 'default') {
3322
+ ltr = (0, _stylexVarsUtils$1.wrapWithAtRules)(ltr, atRule);
3046
3323
  }
3047
3324
  result[themeNameHash + suffix] = {
3048
3325
  ltr,
3049
3326
  rtl: null,
3050
- priority: key === 'default' ? 0 : 0.1
3327
+ priority: (0, _stylexVarsUtils$1.priorityForAtRule)(atRule) * 0.1
3051
3328
  };
3052
3329
  }
3053
3330
  return result;
@@ -3060,6 +3337,8 @@ Object.defineProperty(stylexCreateTheme$1, "__esModule", {
3060
3337
  });
3061
3338
  stylexCreateTheme$1.default = styleXCreateTheme;
3062
3339
  var _hash$2 = _interopRequireDefault$2(hash$1);
3340
+ var _stylexVarsUtils = stylexVarsUtils;
3341
+ var _types$1 = types$1;
3063
3342
  var _defaultOptions$1 = defaultOptions;
3064
3343
  function _interopRequireDefault$2(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
3065
3344
  function styleXCreateTheme(themeVars, variables, options) {
@@ -3072,48 +3351,36 @@ function styleXCreateTheme(themeVars, variables, options) {
3072
3351
  ..._defaultOptions$1.defaultOptions,
3073
3352
  ...options
3074
3353
  };
3354
+ const rulesByAtRule = {};
3075
3355
  const sortedKeys = Object.keys(variables).sort();
3076
- const atRules = {};
3077
- const cssVariablesOverrideString = sortedKeys.map(key => {
3078
- const varNameHash = themeVars[key].slice(4, -1);
3079
- const value = variables[key];
3080
- if (varNameHash != null && value !== null && typeof value === 'object') {
3081
- if (value.default === undefined) {
3082
- throw new Error('Default value is not defined for ' + key + ' variable.');
3083
- }
3084
- const definedVarString = `${varNameHash}:${value.default};`;
3085
- Object.keys(value).forEach(key => {
3086
- if (key.startsWith('@')) {
3087
- const definedVarStringForAtRule = `${varNameHash}:${value[key]};`;
3088
- if (atRules[key] == null) {
3089
- atRules[key] = [definedVarStringForAtRule];
3090
- } else {
3091
- atRules[key].push(definedVarStringForAtRule);
3092
- }
3093
- }
3094
- });
3095
- return definedVarString;
3096
- }
3097
- return varNameHash != null && typeof value !== 'object' ? `${varNameHash}:${value};` : '';
3098
- }).join('');
3099
- const sortedAtRules = Object.keys(atRules).sort();
3100
- const atRulesStringForHash = sortedAtRules.map(atRule => {
3101
- return `${atRule}{${atRules[atRule].sort().join('')}}`;
3102
- }).join('');
3103
- const overrideClassName = classNamePrefix + (0, _hash$2.default)(cssVariablesOverrideString + atRulesStringForHash);
3104
- const stylesToInject = {
3105
- [overrideClassName]: {
3106
- ltr: `.${overrideClassName}{${cssVariablesOverrideString}}`,
3107
- priority: 0.8,
3108
- rtl: undefined
3109
- }
3110
- };
3356
+ for (const key of sortedKeys) {
3357
+ const value = (0, _types$1.isCSSType)(variables[key]) ? variables[key].value : variables[key];
3358
+ const nameHash = themeVars[key].slice(6, -1);
3359
+ (0, _stylexVarsUtils.collectVarsByAtRule)(key, {
3360
+ nameHash,
3361
+ value
3362
+ }, rulesByAtRule);
3363
+ }
3364
+ const sortedAtRules = Object.keys(rulesByAtRule).sort((a, b) => a === 'default' ? -1 : b === 'default' ? 1 : a.localeCompare(b));
3365
+ const atRulesStringForHash = sortedAtRules.map(atRule => (0, _stylexVarsUtils.wrapWithAtRules)(rulesByAtRule[atRule].join(''), atRule)).join('');
3366
+ const overrideClassName = classNamePrefix + (0, _hash$2.default)(atRulesStringForHash);
3367
+ const stylesToInject = {};
3111
3368
  for (const atRule of sortedAtRules) {
3112
- stylesToInject[overrideClassName + '-' + (0, _hash$2.default)(atRule)] = {
3113
- ltr: `${atRule}{.${overrideClassName}{${atRules[atRule].join('')}}}`,
3114
- priority: 0.9,
3115
- rtl: null
3116
- };
3369
+ const decls = rulesByAtRule[atRule].join('');
3370
+ const rule = `.${overrideClassName}{${decls}}`;
3371
+ if (atRule === 'default') {
3372
+ stylesToInject[overrideClassName] = {
3373
+ ltr: rule,
3374
+ priority: 0.5,
3375
+ rtl: null
3376
+ };
3377
+ } else {
3378
+ stylesToInject[overrideClassName + '-' + (0, _hash$2.default)(atRule)] = {
3379
+ ltr: (0, _stylexVarsUtils.wrapWithAtRules)(rule, atRule),
3380
+ priority: 0.5 + 0.1 * (0, _stylexVarsUtils.priorityForAtRule)(atRule),
3381
+ rtl: null
3382
+ };
3383
+ }
3117
3384
  }
3118
3385
  return [{
3119
3386
  $$css: true,
@@ -3205,198 +3472,6 @@ function genFileBasedIdentifier(_ref) {
3205
3472
  return `${fileName}//${exportName}${key != null ? `.${key}` : ''}`;
3206
3473
  }
3207
3474
 
3208
- var types$1 = {};
3209
-
3210
- Object.defineProperty(types$1, "__esModule", {
3211
- value: true
3212
- });
3213
- types$1.url = types$1.transformList = types$1.transformFunction = types$1.time = types$1.resolution = types$1.percentage = types$1.number = types$1.lengthPercentage = types$1.length = types$1.integer = types$1.image = types$1.color = types$1.angle = types$1.Url = types$1.TransformList = types$1.TransformFunction = types$1.Time = types$1.Resolution = types$1.Percentage = types$1.Num = types$1.LengthPercentage = types$1.Length = types$1.Integer = types$1.Image = types$1.Color = types$1.CSSType = types$1.Angle = void 0;
3214
- class CSSType {}
3215
- types$1.CSSType = CSSType;
3216
- class Angle extends CSSType {
3217
- syntax = '<angle>';
3218
- static syntax = '<angle>';
3219
- constructor(value) {
3220
- super();
3221
- this.value = value;
3222
- }
3223
- static create(value) {
3224
- return new Angle(value);
3225
- }
3226
- }
3227
- types$1.Angle = Angle;
3228
- types$1.angle = Angle.create;
3229
- class Color extends CSSType {
3230
- syntax = '<color>';
3231
- constructor(value) {
3232
- super();
3233
- this.value = value;
3234
- }
3235
- static create(value) {
3236
- return new Color(value);
3237
- }
3238
- }
3239
- types$1.Color = Color;
3240
- types$1.color = Color.create;
3241
- class Url extends CSSType {
3242
- syntax = '<url>';
3243
- constructor(value) {
3244
- super();
3245
- this.value = value;
3246
- }
3247
- static create(value) {
3248
- return new Url(value);
3249
- }
3250
- }
3251
- types$1.Url = Url;
3252
- types$1.url = Url.create;
3253
- class Image extends Url {
3254
- syntax = '<image>';
3255
- constructor(value) {
3256
- super(value);
3257
- this.value = value;
3258
- }
3259
- static create(value) {
3260
- return new Image(value);
3261
- }
3262
- }
3263
- types$1.Image = Image;
3264
- types$1.image = Image.create;
3265
- class Integer extends CSSType {
3266
- syntax = '<integer>';
3267
- constructor(value) {
3268
- super();
3269
- this.value = value;
3270
- }
3271
- static create(value) {
3272
- return new Integer(value);
3273
- }
3274
- }
3275
- types$1.Integer = Integer;
3276
- types$1.integer = Integer.create;
3277
- class LengthPercentage extends CSSType {
3278
- syntax = '<length-percentage>';
3279
- constructor(value) {
3280
- super();
3281
- this.value = value;
3282
- }
3283
- static createLength(value) {
3284
- return new LengthPercentage(convertNumberToLength(value));
3285
- }
3286
- static createPercentage(value) {
3287
- return new LengthPercentage(convertNumberToPercentage(value));
3288
- }
3289
- }
3290
- types$1.LengthPercentage = LengthPercentage;
3291
- types$1.lengthPercentage = LengthPercentage.createLength;
3292
- class Length extends LengthPercentage {
3293
- syntax = '<length>';
3294
- constructor(value) {
3295
- super(convertNumberToLength(value));
3296
- }
3297
- static create(value) {
3298
- return new Length(value);
3299
- }
3300
- }
3301
- types$1.Length = Length;
3302
- types$1.length = Length.create;
3303
- class Percentage extends LengthPercentage {
3304
- syntax = '<percentage>';
3305
- constructor(value) {
3306
- super(convertNumberToPercentage(value));
3307
- }
3308
- static create(value) {
3309
- return new Percentage(value);
3310
- }
3311
- }
3312
- types$1.Percentage = Percentage;
3313
- types$1.percentage = Percentage.create;
3314
- class Num extends CSSType {
3315
- syntax = '<number>';
3316
- constructor(value) {
3317
- super();
3318
- this.value = value;
3319
- }
3320
- static create(value) {
3321
- return new Num(value);
3322
- }
3323
- }
3324
- types$1.Num = Num;
3325
- types$1.number = Num.create;
3326
- class Resolution extends CSSType {
3327
- syntax = '<resolution>';
3328
- constructor(value) {
3329
- super();
3330
- this.value = value;
3331
- }
3332
- static create(value) {
3333
- return new Resolution(value);
3334
- }
3335
- }
3336
- types$1.Resolution = Resolution;
3337
- types$1.resolution = Resolution.create;
3338
- class Time extends CSSType {
3339
- syntax = '<time>';
3340
- constructor(value) {
3341
- super();
3342
- this.value = value;
3343
- }
3344
- static create(value) {
3345
- return new Time(value);
3346
- }
3347
- }
3348
- types$1.Time = Time;
3349
- types$1.time = Time.create;
3350
- class TransformFunction extends CSSType {
3351
- syntax = '<transform-function>';
3352
- constructor(value) {
3353
- super();
3354
- this.value = value;
3355
- }
3356
- static create(value) {
3357
- return new TransformFunction(value);
3358
- }
3359
- }
3360
- types$1.TransformFunction = TransformFunction;
3361
- types$1.transformFunction = TransformFunction.create;
3362
- class TransformList extends CSSType {
3363
- syntax = '<transform-list>';
3364
- constructor(value) {
3365
- super();
3366
- this.value = value;
3367
- }
3368
- static create(value) {
3369
- return new TransformList(value);
3370
- }
3371
- }
3372
- types$1.TransformList = TransformList;
3373
- types$1.transformList = TransformList.create;
3374
- const convertNumberToStringUsing = (transformNumber, defaultStr) => value => {
3375
- if (typeof value === 'number') {
3376
- return transformNumber(value);
3377
- }
3378
- if (typeof value === 'string') {
3379
- return value;
3380
- }
3381
- if (typeof value === 'object') {
3382
- const {
3383
- default: defaultValue,
3384
- ...rest
3385
- } = value;
3386
- const defaultResult = convertNumberToLength(defaultValue);
3387
- const result = {
3388
- default: typeof defaultResult === 'string' ? defaultResult : defaultStr
3389
- };
3390
- for (const [key, value] of Object.entries(rest)) {
3391
- result[key] = convertNumberToLength(value);
3392
- }
3393
- return result;
3394
- }
3395
- return value;
3396
- };
3397
- const convertNumberToLength = convertNumberToStringUsing(value => value === 0 ? '0' : `${value}px`, '0px');
3398
- const convertNumberToPercentage = convertNumberToStringUsing(value => value === 0 ? '0' : `${value * 100}%`, '0');
3399
-
3400
3475
  var IncludedStyles_1;
3401
3476
  var create_1;
3402
3477
  var createTheme_1;
@@ -3418,7 +3493,7 @@ var _stylexInclude = _interopRequireWildcard(stylexInclude$2);
3418
3493
  var _stylexFirstThatWorks = _interopRequireDefault(stylexFirstThatWorks$1);
3419
3494
  var _hash = _interopRequireDefault(hash$1);
3420
3495
  var _fileBasedIdentifier = _interopRequireDefault(fileBasedIdentifier);
3421
- var m = _interopRequireWildcard(messages$3);
3496
+ var m = _interopRequireWildcard(messages$4);
3422
3497
  var _types = _interopRequireWildcard(types$1);
3423
3498
  lib.types = _types;
3424
3499
  var _propertyPriorities = propertyPriorities;
@@ -3475,6 +3550,12 @@ function convertObjectToAST(obj) {
3475
3550
  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 === 'number' ? t__namespace.numericLiteral(value) : typeof value === 'boolean' ? t__namespace.booleanLiteral(value) : value === null ? t__namespace.nullLiteral() : convertObjectToAST(value));
3476
3551
  }));
3477
3552
  }
3553
+ function removeObjectsWithSpreads(obj) {
3554
+ return Object.fromEntries(Object.entries(obj).filter(_ref2 => {
3555
+ let [_key, value] = _ref2;
3556
+ return Object.values(value).every(val => !(val instanceof IncludedStyles_1));
3557
+ }).filter(Boolean));
3558
+ }
3478
3559
  function canBeIdentifier(str) {
3479
3560
  return str.match(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/) != null;
3480
3561
  }
@@ -3576,6 +3657,10 @@ function evaluateCached(path, state) {
3576
3657
  resolved: false
3577
3658
  };
3578
3659
  seen.set(node, item);
3660
+ if (node == null) {
3661
+ deopt(path, state);
3662
+ return;
3663
+ }
3579
3664
  const val = _evaluate(path, state);
3580
3665
  if (state.confident) {
3581
3666
  item.resolved = true;
@@ -4251,7 +4336,8 @@ function transformStyleXCreate(path, state) {
4251
4336
  };
4252
4337
  }
4253
4338
  if (varName != null) {
4254
- state.styleMap.set(varName, compiledStyles);
4339
+ const stylesToRemember = removeObjectsWithSpreads(compiledStyles);
4340
+ state.styleMap.set(varName, stylesToRemember);
4255
4341
  state.styleVars.set(varName, path.parentPath);
4256
4342
  }
4257
4343
  const resultAst = convertObjectToAST(compiledStyles);
@@ -4273,41 +4359,18 @@ function transformStyleXCreate(path, state) {
4273
4359
  return prop;
4274
4360
  });
4275
4361
  }
4362
+ const listOfStyles = Object.entries(injectedStyles).map(_ref2 => {
4363
+ let [key, {
4364
+ priority,
4365
+ ...rest
4366
+ }] = _ref2;
4367
+ return [key, rest, priority];
4368
+ });
4369
+ state.registerStyles(listOfStyles, path);
4276
4370
  path.replaceWith(resultAst);
4277
4371
  if (Object.keys(injectedStyles).length === 0) {
4278
4372
  return;
4279
4373
  }
4280
- const statementPath = path.getStatementParent();
4281
- if (state.runtimeInjection != null && statementPath != null) {
4282
- let injectName;
4283
- if (state.injectImportInserted != null) {
4284
- injectName = state.injectImportInserted;
4285
- } else {
4286
- const {
4287
- from,
4288
- as
4289
- } = state.runtimeInjection;
4290
- injectName = as != null ? state.addNamedImport(statementPath, as, from, {
4291
- nameHint: 'inject'
4292
- }) : state.addDefaultImport(statementPath, from, {
4293
- nameHint: 'inject'
4294
- });
4295
- state.injectImportInserted = injectName;
4296
- }
4297
- for (const [_key, {
4298
- ltr,
4299
- priority,
4300
- rtl
4301
- }] of Object.entries(injectedStyles)) {
4302
- statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority), ...(rtl != null ? [t__namespace.stringLiteral(rtl)] : [])])));
4303
- }
4304
- }
4305
- for (const [key, {
4306
- priority,
4307
- ...rest
4308
- }] of Object.entries(injectedStyles)) {
4309
- state.addStyle([key, rest, priority]);
4310
- }
4311
4374
  }
4312
4375
  state.inStyleXCreate = false;
4313
4376
  }
@@ -4405,41 +4468,14 @@ function transformStyleXDefineVars(callExpressionPath, state) {
4405
4468
  ...injectedStylesSansKeyframes
4406
4469
  };
4407
4470
  callExpressionPath.replaceWith(convertObjectToAST(variablesObj));
4408
- const statementPath = variableDeclaratorPath.parentPath.parentPath;
4409
- if (Object.keys(injectedStyles).length === 0) {
4410
- return;
4411
- }
4412
- if (state.runtimeInjection != null && statementPath != null) {
4413
- let injectName;
4414
- if (state.injectImportInserted != null) {
4415
- injectName = state.injectImportInserted;
4416
- } else {
4417
- const {
4418
- from,
4419
- as
4420
- } = state.runtimeInjection;
4421
- injectName = as != null ? state.addNamedImport(statementPath, as, from, {
4422
- nameHint: 'inject'
4423
- }) : state.addDefaultImport(statementPath, from, {
4424
- nameHint: 'inject'
4425
- });
4426
- state.injectImportInserted = injectName;
4427
- }
4428
- for (const [_k, {
4429
- ltr,
4430
- priority
4431
- }] of Object.entries(injectedStyles)) {
4432
- statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority)])));
4433
- }
4434
- }
4435
- for (const [key, {
4436
- priority,
4437
- ltr
4438
- }] of Object.entries(injectedStyles)) {
4439
- state.addStyle([key, {
4440
- ltr
4441
- }, priority]);
4442
- }
4471
+ const listOfStyles = Object.entries(injectedStyles).map(_ref => {
4472
+ let [key, {
4473
+ priority,
4474
+ ...rest
4475
+ }] = _ref;
4476
+ return [key, rest, priority];
4477
+ });
4478
+ state.registerStyles(listOfStyles, variableDeclaratorPath);
4443
4479
  }
4444
4480
  }
4445
4481
  function validateStyleXDefineVars(callExpressionPath) {
@@ -4467,13 +4503,11 @@ function transformStyleXCreateTheme(callExpressionPath, state) {
4467
4503
  if (!isVariableDeclarator(variableDeclaratorPath)) {
4468
4504
  return;
4469
4505
  }
4470
- const varNamePath = variableDeclaratorPath.get('id');
4471
- let varName = 'UnknownVar';
4472
- if (varNamePath.isIdentifier()) {
4473
- varName = varNamePath.node.name;
4506
+ const id = variableDeclaratorPath.get('id');
4507
+ if (!isIdentifier(id)) {
4508
+ return;
4474
4509
  }
4475
- const fileName = state.fileNameForHashing ?? 'UnknownFile';
4476
- const debugName = `${fileName}__${varName}`;
4510
+ const variableName = id.node.name;
4477
4511
  const args = callExpressionPath.get('arguments');
4478
4512
  const firstArg = args[0];
4479
4513
  const secondArg = args[1];
@@ -4498,48 +4532,32 @@ function transformStyleXCreateTheme(callExpressionPath, state) {
4498
4532
  throw new Error('Can only override variables theme created with stylex.defineVars().');
4499
4533
  }
4500
4534
  let [overridesObj, injectedStyles] = createTheme_1(variables, overrides, state.options);
4501
- if (state.isDev) {
4535
+ if (state.isTest) {
4536
+ const fileName = state.filename ?? 'UnknownFile';
4537
+ const basename = path.basename(fileName).split('.')[0];
4538
+ const devClassName = `${basename}__${variableName}`;
4539
+ overridesObj = {
4540
+ [devClassName]: devClassName,
4541
+ $$css: true
4542
+ };
4543
+ } else if (state.isDev) {
4544
+ const fileName = state.filename ?? 'UnknownFile';
4545
+ const basename = path.basename(fileName).split('.')[0];
4546
+ const devClassName = `${basename}__${variableName}`;
4502
4547
  overridesObj = {
4503
- ...overridesObj,
4504
- [debugName]: debugName
4548
+ [devClassName]: devClassName,
4549
+ ...overridesObj
4505
4550
  };
4506
4551
  }
4507
4552
  callExpressionPath.replaceWith(convertObjectToAST(overridesObj));
4508
- const statementPath = variableDeclaratorPath.parentPath;
4509
- if (Object.keys(injectedStyles).length === 0) {
4510
- return;
4511
- }
4512
- if (state.runtimeInjection != null && statementPath != null) {
4513
- let injectName;
4514
- if (state.injectImportInserted != null) {
4515
- injectName = state.injectImportInserted;
4516
- } else {
4517
- const {
4518
- from,
4519
- as
4520
- } = state.runtimeInjection;
4521
- injectName = as != null ? state.addNamedImport(statementPath, as, from, {
4522
- nameHint: 'inject'
4523
- }) : state.addDefaultImport(statementPath, from, {
4524
- nameHint: 'inject'
4525
- });
4526
- state.injectImportInserted = injectName;
4527
- }
4528
- for (const [_k, {
4529
- ltr,
4530
- priority
4531
- }] of Object.entries(injectedStyles)) {
4532
- statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority)])));
4533
- }
4534
- }
4535
- for (const [key, {
4536
- priority,
4537
- ltr
4538
- }] of Object.entries(injectedStyles)) {
4539
- state.addStyle([key, {
4540
- ltr
4541
- }, priority]);
4542
- }
4553
+ const listOfStyles = Object.entries(injectedStyles).map(_ref => {
4554
+ let [key, {
4555
+ priority,
4556
+ ...rest
4557
+ }] = _ref;
4558
+ return [key, rest, priority];
4559
+ });
4560
+ state.registerStyles(listOfStyles, variableDeclaratorPath);
4543
4561
  }
4544
4562
  }
4545
4563
  function validateStyleXCreateTheme(callExpressionPath) {
@@ -4603,36 +4621,16 @@ function transformStyleXKeyframes(path, state) {
4603
4621
  }
4604
4622
  const plainObject = value;
4605
4623
  assertValidKeyframes(plainObject);
4606
- const [animationName, injectedStyle] = keyframes_1(plainObject, state.options);
4607
- init.replaceWith(t__namespace.stringLiteral(animationName));
4608
- const {
4624
+ const [animationName, {
4609
4625
  ltr,
4610
4626
  priority,
4611
4627
  rtl
4612
- } = injectedStyle;
4613
- const statementPath = path.getStatementParent();
4614
- if (statementPath != null && state.runtimeInjection != null) {
4615
- let injectName;
4616
- if (state.injectImportInserted != null) {
4617
- injectName = state.injectImportInserted;
4618
- } else {
4619
- const {
4620
- from,
4621
- as
4622
- } = state.runtimeInjection;
4623
- injectName = as != null ? state.addNamedImport(statementPath, as, from, {
4624
- nameHint: 'inject'
4625
- }) : state.addDefaultImport(statementPath, from, {
4626
- nameHint: 'inject'
4627
- });
4628
- state.injectImportInserted = injectName;
4629
- }
4630
- statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority), ...(rtl != null ? [t__namespace.stringLiteral(rtl)] : [])])));
4631
- }
4632
- state.addStyle([animationName, {
4628
+ }] = keyframes_1(plainObject, state.options);
4629
+ init.replaceWith(t__namespace.stringLiteral(animationName));
4630
+ state.registerStyles([[animationName, {
4633
4631
  ltr,
4634
4632
  rtl
4635
- }, priority]);
4633
+ }, priority]], path);
4636
4634
  }
4637
4635
  }
4638
4636
  function assertValidKeyframes(obj) {
@@ -5076,7 +5074,7 @@ function transformStyleXMerge(path, state) {
5076
5074
  confident,
5077
5075
  value: styleValue
5078
5076
  } = evaluate(path, state);
5079
- if (!confident) {
5077
+ if (!confident || styleValue == null) {
5080
5078
  nonNullProps = true;
5081
5079
  styleNonNullProps = true;
5082
5080
  } else {
@@ -5298,7 +5296,7 @@ function transformStylexProps(path, state) {
5298
5296
  confident,
5299
5297
  value: styleValue
5300
5298
  } = evaluate(path, state);
5301
- if (!confident) {
5299
+ if (!confident || styleValue == null) {
5302
5300
  nonNullProps = true;
5303
5301
  styleNonNullProps = true;
5304
5302
  } else {
@@ -5533,7 +5531,7 @@ function transformStylexAttrs(path, state) {
5533
5531
  confident,
5534
5532
  value: styleValue
5535
5533
  } = evaluate(path, state);
5536
- if (!confident) {
5534
+ if (!confident || styleValue == null) {
5537
5535
  nonNullProps = true;
5538
5536
  styleNonNullProps = true;
5539
5537
  } else {