@stylexjs/babel-plugin 0.14.2 → 0.14.3
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 +44 -68
- package/lib/shared/physical-rtl/generate-rtl.d.ts +1 -1
- package/lib/shared/physical-rtl/generate-rtl.js.flow +1 -1
- package/package.json +3 -3
- package/lib/babel-path-utils.d.ts +0 -1100
- package/lib/babel-path-utils.js.flow +0 -1108
- package/lib/shared/utils/genCSSRule.d.ts +0 -15
- package/lib/shared/utils/genCSSRule.js.flow +0 -15
- package/lib/visitors/stylex-attrs.d.ts +0 -21
- package/lib/visitors/stylex-attrs.js.flow +0 -25
- package/lib/visitors/stylex-create/index.d.ts +0 -17
- package/lib/visitors/stylex-create/index.js.flow +0 -24
- package/lib/visitors/stylex-create/parse-stylex-create-arg.d.ts +0 -37
- package/lib/visitors/stylex-create/parse-stylex-create-arg.js.flow +0 -41
package/lib/index.js
CHANGED
|
@@ -2173,7 +2173,7 @@ const shorthands$1 = {
|
|
|
2173
2173
|
},
|
|
2174
2174
|
paddingStart: val => [['paddingInlineStart', val], ['paddingLeft', null], ['paddingRight', null]],
|
|
2175
2175
|
paddingEnd: val => [['paddingInlineEnd', val], ['paddingLeft', null], ['paddingRight', null]],
|
|
2176
|
-
paddingLeft: val => [['paddingLeft', val], ['
|
|
2176
|
+
paddingLeft: val => [['paddingLeft', val], ['paddingInlineStart', null], ['paddingInlineEnd', null]],
|
|
2177
2177
|
paddingRight: val => [['paddingRight', val], ['paddingInlineStart', null], ['paddingInlineEnd', null]],
|
|
2178
2178
|
paddingVertical: val => {
|
|
2179
2179
|
const [top, bottom = top] = splitValue(val);
|
|
@@ -2882,7 +2882,7 @@ function flipShadow(value) {
|
|
|
2882
2882
|
}
|
|
2883
2883
|
builtDefs.push(parts.join(' '));
|
|
2884
2884
|
}
|
|
2885
|
-
const rtl = builtDefs.join(',
|
|
2885
|
+
const rtl = builtDefs.join(',');
|
|
2886
2886
|
if (rtl !== value) {
|
|
2887
2887
|
return rtl;
|
|
2888
2888
|
}
|
|
@@ -3093,28 +3093,28 @@ const propertyToRTL = {
|
|
|
3093
3093
|
return rtlVal ? [key, rtlVal] : null;
|
|
3094
3094
|
}
|
|
3095
3095
|
};
|
|
3096
|
-
function generateRTL(
|
|
3097
|
-
let [key, value] = _ref43;
|
|
3096
|
+
function generateRTL(pair) {
|
|
3098
3097
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
|
|
3099
3098
|
const {
|
|
3100
3099
|
enableLogicalStylesPolyfill,
|
|
3101
3100
|
styleResolution
|
|
3102
3101
|
} = options;
|
|
3102
|
+
const [key] = pair;
|
|
3103
3103
|
if (styleResolution === 'legacy-expand-shorthands') {
|
|
3104
3104
|
if (!enableLogicalStylesPolyfill) {
|
|
3105
3105
|
if (legacyValuesPolyfill[key]) {
|
|
3106
|
-
return legacyValuesPolyfill[key](
|
|
3106
|
+
return legacyValuesPolyfill[key](pair);
|
|
3107
3107
|
}
|
|
3108
3108
|
return null;
|
|
3109
3109
|
}
|
|
3110
3110
|
if (inlinePropertyToRTL[key]) {
|
|
3111
|
-
return inlinePropertyToRTL[key](
|
|
3111
|
+
return inlinePropertyToRTL[key](pair);
|
|
3112
3112
|
}
|
|
3113
3113
|
}
|
|
3114
3114
|
if (!propertyToRTL[key]) {
|
|
3115
3115
|
return null;
|
|
3116
3116
|
}
|
|
3117
|
-
return propertyToRTL[key](
|
|
3117
|
+
return propertyToRTL[key](pair, options);
|
|
3118
3118
|
}
|
|
3119
3119
|
|
|
3120
3120
|
const longHandPhysical = new Set();
|
|
@@ -4488,8 +4488,8 @@ function styleXKeyframes(frames) {
|
|
|
4488
4488
|
classNamePrefix = 'x'
|
|
4489
4489
|
} = options;
|
|
4490
4490
|
const expandedObject = objMap(frames, frame => Pipe.create(frame).pipe(frame => expandFrameShorthands(frame, options)).pipe(x => objMapKeys(x, dashify)).pipe(x => objMap(x, (value, key) => transformValue(key, value, options))).done());
|
|
4491
|
-
const ltrStyles = objMap(expandedObject, frame => objMapEntry(frame, generateLTR));
|
|
4492
|
-
const rtlStyles = objMap(expandedObject, frame => objMapEntry(frame, entry => generateRTL(entry) ?? entry));
|
|
4491
|
+
const ltrStyles = objMap(expandedObject, frame => objMapEntry(frame, entry => generateLTR(entry, options)));
|
|
4492
|
+
const rtlStyles = objMap(expandedObject, frame => objMapEntry(frame, entry => generateRTL(entry, options) ?? entry));
|
|
4493
4493
|
const ltrString = constructKeyframesObj(ltrStyles);
|
|
4494
4494
|
const rtlString = constructKeyframesObj(rtlStyles);
|
|
4495
4495
|
const animationName = classNamePrefix + hash('<>' + ltrString) + '-B';
|
|
@@ -5508,6 +5508,9 @@ function validateDynamicStyleParams(path, params) {
|
|
|
5508
5508
|
}
|
|
5509
5509
|
}
|
|
5510
5510
|
|
|
5511
|
+
function isSafeToSkipNullCheck(expr) {
|
|
5512
|
+
return t__namespace.isBinaryExpression(expr) && ['+', '-', '*', '/', '**'].includes(expr.operator) || t__namespace.isUnaryExpression(expr) && ['-', '+'].includes(expr.operator);
|
|
5513
|
+
}
|
|
5511
5514
|
function transformStyleXCreate(path, state) {
|
|
5512
5515
|
const {
|
|
5513
5516
|
node
|
|
@@ -5655,66 +5658,39 @@ function transformStyleXCreate(path, state) {
|
|
|
5655
5658
|
}
|
|
5656
5659
|
if (t__namespace.isObjectExpression(prop.value)) {
|
|
5657
5660
|
const value = prop.value;
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
+
const conditionalProps = [];
|
|
5662
|
+
value.properties.forEach(prop => {
|
|
5663
|
+
if (!t__namespace.isObjectProperty(prop) || t__namespace.isPrivateName(prop.key)) {
|
|
5664
|
+
return;
|
|
5661
5665
|
}
|
|
5662
5666
|
const objProp = prop;
|
|
5663
5667
|
const propKey = objProp.key.type === 'Identifier' && !objProp.computed ? objProp.key.name : objProp.key.type === 'StringLiteral' ? objProp.key.value : null;
|
|
5664
|
-
if (propKey
|
|
5665
|
-
|
|
5668
|
+
if (propKey == null || propKey === '$$css') {
|
|
5669
|
+
conditionalProps.push(objProp);
|
|
5670
|
+
return;
|
|
5671
|
+
}
|
|
5672
|
+
const classList = t__namespace.isStringLiteral(objProp.value) ? objProp.value.value.split(' ') : [];
|
|
5673
|
+
const exprList = [];
|
|
5674
|
+
classList.forEach(cls => {
|
|
5675
|
+
const expr = dynamicStyles.find(_ref4 => {
|
|
5666
5676
|
let {
|
|
5667
|
-
|
|
5677
|
+
path
|
|
5668
5678
|
} = _ref4;
|
|
5669
|
-
return
|
|
5670
|
-
});
|
|
5671
|
-
if (
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
if (classList.length === 1) {
|
|
5676
|
-
const cls = classList[0];
|
|
5677
|
-
const expr = dynamicMatch.find(_ref5 => {
|
|
5678
|
-
let {
|
|
5679
|
-
path
|
|
5680
|
-
} = _ref5;
|
|
5681
|
-
return origClassPaths[cls] === path;
|
|
5682
|
-
})?.expression;
|
|
5683
|
-
if (expr != null) {
|
|
5684
|
-
objProp.value = t__namespace.conditionalExpression(t__namespace.binaryExpression('==', expr, t__namespace.nullLiteral()), t__namespace.nullLiteral(), value);
|
|
5685
|
-
}
|
|
5686
|
-
} else if (classList.some(cls => dynamicMatch.find(_ref6 => {
|
|
5687
|
-
let {
|
|
5688
|
-
path
|
|
5689
|
-
} = _ref6;
|
|
5690
|
-
return origClassPaths[cls] === path;
|
|
5691
|
-
}))) {
|
|
5692
|
-
const exprArray = classList.map((cls, index) => {
|
|
5693
|
-
const expr = dynamicMatch.find(_ref7 => {
|
|
5694
|
-
let {
|
|
5695
|
-
path
|
|
5696
|
-
} = _ref7;
|
|
5697
|
-
return origClassPaths[cls] === path;
|
|
5698
|
-
})?.expression;
|
|
5699
|
-
const suffix = index === classList.length - 1 ? '' : ' ';
|
|
5700
|
-
if (expr != null) {
|
|
5701
|
-
return t__namespace.conditionalExpression(t__namespace.binaryExpression('==', expr, t__namespace.nullLiteral()), t__namespace.stringLiteral(''), t__namespace.stringLiteral(cls + suffix));
|
|
5702
|
-
}
|
|
5703
|
-
return t__namespace.stringLiteral(cls + suffix);
|
|
5704
|
-
});
|
|
5705
|
-
const [first, ...rest] = exprArray;
|
|
5706
|
-
objProp.value = rest.reduce((acc, curr) => {
|
|
5707
|
-
return t__namespace.binaryExpression('+', acc, curr);
|
|
5708
|
-
}, first);
|
|
5709
|
-
}
|
|
5710
|
-
}
|
|
5679
|
+
return origClassPaths[cls] === path;
|
|
5680
|
+
})?.expression;
|
|
5681
|
+
if (expr && !isSafeToSkipNullCheck(expr)) {
|
|
5682
|
+
exprList.push(t__namespace.conditionalExpression(t__namespace.binaryExpression('!=', expr, t__namespace.nullLiteral()), t__namespace.stringLiteral(cls), expr));
|
|
5683
|
+
} else {
|
|
5684
|
+
exprList.push(t__namespace.stringLiteral(cls));
|
|
5711
5685
|
}
|
|
5712
|
-
}
|
|
5713
|
-
|
|
5686
|
+
});
|
|
5687
|
+
const joined = exprList.length === 0 ? t__namespace.stringLiteral('') : exprList.reduce((acc, curr) => t__namespace.binaryExpression('+', acc, curr));
|
|
5688
|
+
conditionalProps.push(t__namespace.objectProperty(objProp.key, joined));
|
|
5714
5689
|
});
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5690
|
+
const conditionalObj = t__namespace.objectExpression(conditionalProps);
|
|
5691
|
+
prop.value = t__namespace.arrowFunctionExpression(params, t__namespace.arrayExpression([conditionalObj, t__namespace.objectExpression(Object.entries(inlineStyles).map(_ref5 => {
|
|
5692
|
+
let [key, val] = _ref5;
|
|
5693
|
+
return t__namespace.objectProperty(t__namespace.stringLiteral(key), val.expression);
|
|
5718
5694
|
}))]));
|
|
5719
5695
|
}
|
|
5720
5696
|
}
|
|
@@ -5722,11 +5698,11 @@ function transformStyleXCreate(path, state) {
|
|
|
5722
5698
|
return prop;
|
|
5723
5699
|
});
|
|
5724
5700
|
}
|
|
5725
|
-
const listOfStyles = Object.entries(injectedStyles).map(
|
|
5701
|
+
const listOfStyles = Object.entries(injectedStyles).map(_ref6 => {
|
|
5726
5702
|
let [key, {
|
|
5727
5703
|
priority,
|
|
5728
5704
|
...rest
|
|
5729
|
-
}] =
|
|
5705
|
+
}] = _ref6;
|
|
5730
5706
|
return [key, rest, priority];
|
|
5731
5707
|
});
|
|
5732
5708
|
state.registerStyles(listOfStyles, path);
|
|
@@ -5767,15 +5743,15 @@ function findNearestStatementAncestor(path) {
|
|
|
5767
5743
|
return findNearestStatementAncestor(path.parentPath);
|
|
5768
5744
|
}
|
|
5769
5745
|
function legacyExpandShorthands(dynamicStyles) {
|
|
5770
|
-
const expandedKeysToKeyPaths = dynamicStyles.flatMap((
|
|
5746
|
+
const expandedKeysToKeyPaths = dynamicStyles.flatMap((_ref7, i) => {
|
|
5771
5747
|
let {
|
|
5772
5748
|
key
|
|
5773
|
-
} =
|
|
5749
|
+
} = _ref7;
|
|
5774
5750
|
return flatMapExpandedShorthands([key, 'p' + i], {
|
|
5775
5751
|
styleResolution: 'legacy-expand-shorthands'
|
|
5776
5752
|
});
|
|
5777
|
-
}).map(
|
|
5778
|
-
let [key, value] =
|
|
5753
|
+
}).map(_ref8 => {
|
|
5754
|
+
let [key, value] = _ref8;
|
|
5779
5755
|
if (typeof value !== 'string') {
|
|
5780
5756
|
return null;
|
|
5781
5757
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type { StyleXOptions } from '../common-types';
|
|
11
11
|
declare function generateRTL(
|
|
12
|
-
|
|
12
|
+
pair: Readonly<[string, string]>,
|
|
13
13
|
options: StyleXOptions,
|
|
14
14
|
): null | undefined | Readonly<[string, string]>;
|
|
15
15
|
export default generateRTL;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/babel-plugin",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "StyleX babel plugin.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@babel/traverse": "^7.26.8",
|
|
22
22
|
"@babel/types": "^7.26.8",
|
|
23
23
|
"@dual-bundle/import-meta-resolve": "^4.1.0",
|
|
24
|
-
"@stylexjs/stylex": "0.14.
|
|
24
|
+
"@stylexjs/stylex": "0.14.3",
|
|
25
25
|
"postcss-value-parser": "^4.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@rollup/plugin-replace": "^6.0.1",
|
|
34
34
|
"babel-plugin-syntax-hermes-parser": "^0.26.0",
|
|
35
35
|
"rollup": "^4.24.0",
|
|
36
|
-
"scripts": "0.14.
|
|
36
|
+
"scripts": "0.14.3"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"flow_modules/*",
|