@stylexjs/babel-plugin 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1128,8 +1128,8 @@ Object.defineProperty(splitCssValue, "__esModule", {
1128
1128
  value: true
1129
1129
  });
1130
1130
  splitCssValue.default = splitValue;
1131
- var _postcssValueParser$5 = _interopRequireDefault$g(require$$0);
1132
- function _interopRequireDefault$g(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1131
+ var _postcssValueParser$6 = _interopRequireDefault$h(require$$0);
1132
+ function _interopRequireDefault$h(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1133
1133
  function printNode(node) {
1134
1134
  switch (node.type) {
1135
1135
  case 'word':
@@ -1148,7 +1148,7 @@ function splitValue(str) {
1148
1148
  if (Array.isArray(str)) {
1149
1149
  return str;
1150
1150
  }
1151
- const parsed = (0, _postcssValueParser$5.default)(str.trim());
1151
+ const parsed = (0, _postcssValueParser$6.default)(str.trim());
1152
1152
  const nodes = parsed.nodes.filter(node => node.type !== 'space' && node.type !== 'div').map(printNode);
1153
1153
  if (nodes.length > 1 && nodes[nodes.length - 1].toLowerCase() === '!important') {
1154
1154
  return nodes.slice(0, nodes.length - 1).map(node => node + ' !important');
@@ -1160,8 +1160,8 @@ Object.defineProperty(legacyExpandShorthands, "__esModule", {
1160
1160
  value: true
1161
1161
  });
1162
1162
  legacyExpandShorthands.default = void 0;
1163
- var _splitCssValue = _interopRequireDefault$f(splitCssValue);
1164
- function _interopRequireDefault$f(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1163
+ var _splitCssValue = _interopRequireDefault$g(splitCssValue);
1164
+ function _interopRequireDefault$g(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1165
1165
  const shorthands$1 = {
1166
1166
  border: rawValue => {
1167
1167
  return [['borderTop', rawValue], ['borderEnd', rawValue], ['borderBottom', rawValue], ['borderStart', rawValue]];
@@ -1404,10 +1404,10 @@ Object.defineProperty(preprocessRules, "__esModule", {
1404
1404
  });
1405
1405
  preprocessRules.default = flatMapExpandedShorthands;
1406
1406
  preprocessRules.getExpandedKeys = getExpandedKeys;
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 }; }
1407
+ var _applicationOrder = _interopRequireDefault$f(applicationOrder);
1408
+ var _legacyExpandShorthands = _interopRequireDefault$f(legacyExpandShorthands);
1409
+ var _propertySpecificity = _interopRequireDefault$f(propertySpecificity);
1410
+ function _interopRequireDefault$f(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1411
1411
  const expansions = {
1412
1412
  'application-order': _applicationOrder.default,
1413
1413
  'property-specificity': _propertySpecificity.default,
@@ -1493,8 +1493,8 @@ Object.defineProperty(fontSizePxToRem, "__esModule", {
1493
1493
  value: true
1494
1494
  });
1495
1495
  fontSizePxToRem.default = convertFontSizeToRem;
1496
- var _postcssValueParser$4 = _interopRequireDefault$d(require$$0);
1497
- function _interopRequireDefault$d(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1496
+ var _postcssValueParser$5 = _interopRequireDefault$e(require$$0);
1497
+ function _interopRequireDefault$e(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1498
1498
  const ROOT_FONT_SIZE = 16;
1499
1499
  function convertFontSizeToRem(ast, key) {
1500
1500
  if (key !== 'fontSize') {
@@ -1504,7 +1504,7 @@ function convertFontSizeToRem(ast, key) {
1504
1504
  if (node.type !== 'word') {
1505
1505
  return;
1506
1506
  }
1507
- const dimension = _postcssValueParser$4.default.unit(node.value);
1507
+ const dimension = _postcssValueParser$5.default.unit(node.value);
1508
1508
  if (dimension && dimension.unit === 'px') {
1509
1509
  node.value = `${parseFloat(dimension.number) / ROOT_FONT_SIZE}rem`;
1510
1510
  }
@@ -1518,8 +1518,8 @@ Object.defineProperty(leadingZero, "__esModule", {
1518
1518
  value: true
1519
1519
  });
1520
1520
  leadingZero.default = normalizeLeadingZero;
1521
- var _postcssValueParser$3 = _interopRequireDefault$c(require$$0);
1522
- function _interopRequireDefault$c(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1521
+ var _postcssValueParser$4 = _interopRequireDefault$d(require$$0);
1522
+ function _interopRequireDefault$d(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1523
1523
  function normalizeLeadingZero(ast, _) {
1524
1524
  ast.walk(node => {
1525
1525
  if (node.type !== 'word') {
@@ -1529,7 +1529,7 @@ function normalizeLeadingZero(ast, _) {
1529
1529
  if (Number.isNaN(value)) {
1530
1530
  return;
1531
1531
  }
1532
- const dimension = _postcssValueParser$3.default.unit(node.value);
1532
+ const dimension = _postcssValueParser$4.default.unit(node.value);
1533
1533
  if (value < 1 && value >= 0) {
1534
1534
  node.value = value.toString().replace('0.', '.') + (dimension ? dimension.unit : '');
1535
1535
  }
@@ -1555,14 +1555,14 @@ function normalizeQuotes(ast, _) {
1555
1555
  return ast;
1556
1556
  }
1557
1557
 
1558
- var timings = {};
1558
+ var timings$1 = {};
1559
1559
 
1560
- Object.defineProperty(timings, "__esModule", {
1560
+ Object.defineProperty(timings$1, "__esModule", {
1561
1561
  value: true
1562
1562
  });
1563
- timings.default = normalizeTimings;
1564
- var _postcssValueParser$2 = _interopRequireDefault$b(require$$0);
1565
- function _interopRequireDefault$b(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1563
+ timings$1.default = normalizeTimings;
1564
+ var _postcssValueParser$3 = _interopRequireDefault$c(require$$0);
1565
+ function _interopRequireDefault$c(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1566
1566
  function normalizeTimings(ast, _) {
1567
1567
  ast.walk(node => {
1568
1568
  if (node.type !== 'word') {
@@ -1572,7 +1572,7 @@ function normalizeTimings(ast, _) {
1572
1572
  if (Number.isNaN(value)) {
1573
1573
  return;
1574
1574
  }
1575
- const dimension = _postcssValueParser$2.default.unit(node.value);
1575
+ const dimension = _postcssValueParser$3.default.unit(node.value);
1576
1576
  if (!dimension || dimension.unit !== 'ms' || value < 10) {
1577
1577
  return;
1578
1578
  }
@@ -1632,6 +1632,49 @@ function normalizeWhitespace(ast, _) {
1632
1632
  return ast;
1633
1633
  }
1634
1634
 
1635
+ var zeroDimensions = {};
1636
+
1637
+ Object.defineProperty(zeroDimensions, "__esModule", {
1638
+ value: true
1639
+ });
1640
+ zeroDimensions.default = normalizeZeroDimensions;
1641
+ var _postcssValueParser$2 = _interopRequireDefault$b(require$$0);
1642
+ function _interopRequireDefault$b(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1643
+ const angles = ['deg', 'grad', 'turn', 'rad'];
1644
+ const timings = ['ms', 's'];
1645
+ const fraction = 'fr';
1646
+ const percentage = '%';
1647
+ function normalizeZeroDimensions(ast, _) {
1648
+ let endFunction = 0;
1649
+ ast.walk(node => {
1650
+ if (node.type === 'function' && !endFunction) {
1651
+ endFunction = node.sourceEndIndex ?? 0;
1652
+ }
1653
+ if (endFunction > 0 && node.sourceIndex > endFunction) {
1654
+ endFunction = 0;
1655
+ }
1656
+ if (node.type !== 'word') {
1657
+ return;
1658
+ }
1659
+ const dimension = _postcssValueParser$2.default.unit(node.value);
1660
+ if (!dimension || dimension.number !== '0') {
1661
+ return;
1662
+ }
1663
+ if (angles.indexOf(dimension.unit) !== -1) {
1664
+ node.value = '0deg';
1665
+ } else if (timings.indexOf(dimension.unit) !== -1) {
1666
+ node.value = '0s';
1667
+ } else if (dimension.unit === fraction) {
1668
+ node.value = '0fr';
1669
+ } else if (dimension.unit === percentage) {
1670
+ node.value = '0%';
1671
+ } else if (!endFunction) {
1672
+ node.value = '0';
1673
+ }
1674
+ });
1675
+ return ast;
1676
+ }
1677
+
1635
1678
  var detectUnclosedFns$1 = {};
1636
1679
 
1637
1680
  Object.defineProperty(detectUnclosedFns$1, "__esModule", {
@@ -1681,13 +1724,14 @@ normalizeValue$1.default = normalizeValue;
1681
1724
  var _fontSizePxToRem = _interopRequireDefault$9(fontSizePxToRem);
1682
1725
  var _leadingZero = _interopRequireDefault$9(leadingZero);
1683
1726
  var _quotes = _interopRequireDefault$9(quotes);
1684
- var _timings = _interopRequireDefault$9(timings);
1727
+ var _timings = _interopRequireDefault$9(timings$1);
1685
1728
  var _whitespace = _interopRequireDefault$9(whitespace);
1729
+ var _zeroDimensions = _interopRequireDefault$9(zeroDimensions);
1686
1730
  var _detectUnclosedFns = _interopRequireDefault$9(detectUnclosedFns$1);
1687
1731
  var _postcssValueParser$1 = _interopRequireDefault$9(require$$0);
1688
1732
  var _convertCamelCaseValues = _interopRequireDefault$9(convertCamelCaseValues);
1689
1733
  function _interopRequireDefault$9(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1690
- const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _leadingZero.default, _quotes.default, _convertCamelCaseValues.default];
1734
+ const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _zeroDimensions.default, _leadingZero.default, _quotes.default, _convertCamelCaseValues.default];
1691
1735
  function normalizeValue(value, key, _ref) {
1692
1736
  let {
1693
1737
  useRemForFontSize
@@ -3260,7 +3304,7 @@ function styleXDefineVars(variables, options) {
3260
3304
  const themeNameHash = classNamePrefix + (0, _hash$3.default)(themeName);
3261
3305
  const typedVariables = {};
3262
3306
  const variablesMap = (0, _objectUtils$1.objMap)(variables, (value, key) => {
3263
- const nameHash = classNamePrefix + (0, _hash$3.default)(`${themeName}.${key}`);
3307
+ const nameHash = key.startsWith('--') ? key.slice(2) : classNamePrefix + (0, _hash$3.default)(`${themeName}.${key}`);
3264
3308
  if ((0, _types$2.isCSSType)(value)) {
3265
3309
  const v = value;
3266
3310
  typedVariables[nameHash] = {
@@ -3619,7 +3663,7 @@ function evaluateThemeRef(fileName, exportName, state) {
3619
3663
  const strToHash = key === '__themeName__' ? utils_1.genFileBasedIdentifier({
3620
3664
  fileName,
3621
3665
  exportName
3622
- }) : utils_1.genFileBasedIdentifier({
3666
+ }) : key.startsWith('--') ? `var(${key})` : utils_1.genFileBasedIdentifier({
3623
3667
  fileName,
3624
3668
  exportName,
3625
3669
  key
@@ -11,9 +11,9 @@ import * as t from '../../../flow_modules/@babel/types';
11
11
  import type { NodePath } from '../../../flow_modules/@babel/traverse';
12
12
  import StateManager from '../../utils/state-manager';
13
13
  /// This function looks for `stylex.create` calls and transforms them.
14
- //. 1. It finds the first argument to `stylex.create` and validates it.
14
+ /// 1. It finds the first argument to `stylex.create` and validates it.
15
15
  /// 2. It pre-processes valid-dynamic parts of style object such as custom presets (spreads)
16
- /// 3. It envalues the style object to get a JS object. This also handles local constants automatically.
16
+ /// 3. It evaluates the style object to get a JS object. This also handles local constants automatically.
17
17
  /// 4. It uses the `stylexCreate` from `@stylexjs/shared` to transform the JS
18
18
  /// object and to get a list of injected styles.
19
19
  /// 5. It converts the resulting Object back into an AST and replaces the call with it.
@@ -11,7 +11,7 @@ import * as t from '../../flow_modules/@babel/types';
11
11
  import type { NodePath } from '../../flow_modules/@babel/traverse';
12
12
  import StateManager from '../utils/state-manager';
13
13
  /// This function looks for `stylex.createTheme` calls and transforms them.
14
- //. 1. It finds the first two arguments to `stylex.createTheme` and validates those.
14
+ /// 1. It finds the first two arguments to `stylex.createTheme` and validates those.
15
15
  /// 2. This handles local constants automatically.
16
16
  /// 4. It uses the `stylexCreateTheme` from `@stylexjs/shared` to transform the JS
17
17
  /// object and to get a list of injected styles.
@@ -11,8 +11,8 @@ import * as t from '../../flow_modules/@babel/types';
11
11
  import type { NodePath } from '../../flow_modules/@babel/traverse';
12
12
  import StateManager from '../utils/state-manager';
13
13
  /// This function looks for `stylex.defineVars` calls and transforms them.
14
- //. 1. It finds the first argument to `stylex.defineVars` and validates it.
15
- /// 2. It envalues the style object to get a JS object. This also handles local constants automatically.
14
+ /// 1. It finds the first argument to `stylex.defineVars` and validates it.
15
+ /// 2. It evaluates the style object to get a JS object. This also handles local constants automatically.
16
16
  /// 4. It uses the `stylexDefineVars` from `@stylexjs/shared` to transform the JS
17
17
  /// object and to get a list of injected styles.
18
18
  /// 5. It converts the resulting Object back into an AST and replaces the call with it.
@@ -11,8 +11,8 @@ import * as t from '../../flow_modules/@babel/types';
11
11
  import type { NodePath } from '../../flow_modules/@babel/traverse';
12
12
  import StateManager from '../utils/state-manager';
13
13
  /// This function looks for `stylex.keyframes` calls and transforms them.
14
- //. 1. It finds the first argument to `stylex.keyframes` and validates it.
15
- /// 2. It envalues the style object to get a JS object. This also handles local constants automatically.
14
+ /// 1. It finds the first argument to `stylex.keyframes` and validates it.
15
+ /// 2. It evaluates the style object to get a JS object. This also handles local constants automatically.
16
16
  /// 4. It uses the `stylexKeyframes` from `@stylexjs/shared` to transform the JS
17
17
  /// object and to get a list of injected styles.
18
18
  /// 5. It converts the resulting Object back into an AST and replaces the call with it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/babel-plugin",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "description": "StyleX babel plugin.",
5
5
  "main": "lib/index.js",
6
6
  "repository": "https://github.com/facebook/stylex",
@@ -14,8 +14,8 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@babel/helper-module-imports": "^7.22.15",
17
- "@stylexjs/shared": "0.6.1",
18
- "@stylexjs/stylex": "0.6.1",
17
+ "@stylexjs/shared": "0.7.1",
18
+ "@stylexjs/stylex": "0.7.1",
19
19
  "@babel/core": "^7.23.6",
20
20
  "@babel/traverse": "^7.23.6",
21
21
  "@babel/types": "^7.23.6"