@stylexjs/babel-plugin 0.15.3 → 0.16.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/flow_modules/@babel/traverse/index.js.flow +4 -4
- package/lib/index.d.ts +8 -1
- package/lib/index.js +169 -33
- package/lib/index.js.flow +8 -1
- package/lib/shared/common-types.d.ts +1 -0
- package/lib/shared/common-types.js.flow +1 -0
- package/lib/shared/index.d.ts +2 -1
- package/lib/shared/index.js.flow +3 -1
- package/lib/shared/stylex-defaultMarker.d.ts +14 -0
- package/lib/shared/stylex-defaultMarker.js.flow +13 -0
- package/lib/shared/when/when.d.ts +66 -0
- package/lib/shared/when/when.js.flow +71 -0
- package/lib/utils/state-manager.d.ts +4 -0
- package/lib/utils/state-manager.js.flow +3 -0
- package/lib/visitors/stylex-default-marker.d.ts +21 -0
- package/lib/visitors/stylex-default-marker.js.flow +21 -0
- package/lib/visitors/stylex-props.js.flow +0 -1
- package/package.json +3 -3
|
@@ -632,10 +632,10 @@ declare export class NodePath<+T: Node = Node> {
|
|
|
632
632
|
getCompletionRecords(): Array<NodePath<>>;
|
|
633
633
|
|
|
634
634
|
getSibling(key: string | number): NodePath<>;
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
635
|
+
getSiblingBefore(): NodePath<>;
|
|
636
|
+
getSiblingAfter(): NodePath<>;
|
|
637
|
+
getAllSiblingBefore(): Array<NodePath<>>;
|
|
638
|
+
getAllSiblingAfter(): Array<NodePath<>>;
|
|
639
639
|
|
|
640
640
|
get<K: $Keys<T>>(
|
|
641
641
|
key: K,
|
package/lib/index.d.ts
CHANGED
|
@@ -36,7 +36,14 @@ declare function stylexPluginWithOptions(
|
|
|
36
36
|
export type Rule = [string, { ltr: string; rtl?: null | string }, number];
|
|
37
37
|
declare function processStylexRules(
|
|
38
38
|
rules: Array<Rule>,
|
|
39
|
-
|
|
39
|
+
config?:
|
|
40
|
+
| boolean
|
|
41
|
+
| {
|
|
42
|
+
useLayers?: boolean,
|
|
43
|
+
enableLTRRTLComments?: boolean,
|
|
44
|
+
legacyDisableLayers?: boolean,
|
|
45
|
+
...
|
|
46
|
+
},
|
|
40
47
|
): string;
|
|
41
48
|
export type StyleXTransformObj = Readonly<{
|
|
42
49
|
(): PluginObj;
|
package/lib/index.js
CHANGED
|
@@ -807,6 +807,8 @@ class StateManager {
|
|
|
807
807
|
stylexCreateThemeImport = new Set();
|
|
808
808
|
stylexTypesImport = new Set();
|
|
809
809
|
stylexViewTransitionClassImport = new Set();
|
|
810
|
+
stylexDefaultMarkerImport = new Set();
|
|
811
|
+
stylexWhenImport = new Set();
|
|
810
812
|
injectImportInserted = null;
|
|
811
813
|
styleMap = new Map();
|
|
812
814
|
styleVars = new Map();
|
|
@@ -829,6 +831,7 @@ class StateManager {
|
|
|
829
831
|
const enableMediaQueryOrder = logAndDefault(boolean(), options.enableMediaQueryOrder ?? false, false, 'options.enableMediaQueryOrder');
|
|
830
832
|
const enableLegacyValueFlipping = logAndDefault(boolean(), options.enableLegacyValueFlipping ?? false, false, 'options.enableLegacyValueFlipping');
|
|
831
833
|
const enableLogicalStylesPolyfill = logAndDefault(boolean(), options.enableLogicalStylesPolyfill ?? false, false, 'options.enableLogicalStylesPolyfill');
|
|
834
|
+
const enableLTRRTLComments = logAndDefault(boolean(), options.enableLTRRTLComments ?? false, false, 'options.enableLTRRTLComments');
|
|
832
835
|
const test = logAndDefault(boolean(), options.test ?? false, false, 'options.test');
|
|
833
836
|
const configRuntimeInjection = logAndDefault(checkRuntimeInjection, options.runtimeInjection ?? false, false, 'options.runtimeInjection');
|
|
834
837
|
const runtimeInjection = configRuntimeInjection === true ? DEFAULT_INJECT_PATH : configRuntimeInjection === false ? undefined : configRuntimeInjection;
|
|
@@ -860,6 +863,7 @@ class StateManager {
|
|
|
860
863
|
enableMediaQueryOrder,
|
|
861
864
|
enableLegacyValueFlipping,
|
|
862
865
|
enableLogicalStylesPolyfill,
|
|
866
|
+
enableLTRRTLComments,
|
|
863
867
|
importSources,
|
|
864
868
|
rewriteAliases: typeof options.rewriteAliases === 'boolean' ? options.rewriteAliases : false,
|
|
865
869
|
runtimeInjection,
|
|
@@ -978,32 +982,27 @@ class StateManager {
|
|
|
978
982
|
if (sourceFilePath == null) {
|
|
979
983
|
return false;
|
|
980
984
|
}
|
|
985
|
+
const themeFileExtension = this.options.unstable_moduleResolution?.themeFileExtension ?? '.stylex';
|
|
986
|
+
const transformedVarsFileExtension = '.transformed';
|
|
987
|
+
const isValidStylexFile = matchesFileSuffix(themeFileExtension)(importPath);
|
|
988
|
+
const isValidTransformedVarsFile = matchesFileSuffix(transformedVarsFileExtension)(importPath);
|
|
989
|
+
if (!isValidStylexFile && !isValidTransformedVarsFile) {
|
|
990
|
+
return false;
|
|
991
|
+
}
|
|
981
992
|
switch (this.options.unstable_moduleResolution?.type) {
|
|
982
993
|
case 'commonJS':
|
|
983
994
|
{
|
|
984
995
|
const aliases = this.options.aliases;
|
|
985
|
-
const themeFileExtension = this.options.unstable_moduleResolution?.themeFileExtension ?? '.stylex';
|
|
986
|
-
if (!matchesFileSuffix(themeFileExtension)(importPath)) {
|
|
987
|
-
return false;
|
|
988
|
-
}
|
|
989
996
|
const resolvedFilePath = filePathResolver(importPath, sourceFilePath, aliases);
|
|
990
997
|
return resolvedFilePath ? ['themeNameRef', this.getCanonicalFilePath(resolvedFilePath)] : false;
|
|
991
998
|
}
|
|
992
999
|
case 'haste':
|
|
993
1000
|
{
|
|
994
|
-
const themeFileExtension = this.options.unstable_moduleResolution.themeFileExtension ?? '.stylex';
|
|
995
|
-
if (!matchesFileSuffix(themeFileExtension)(importPath)) {
|
|
996
|
-
return false;
|
|
997
|
-
}
|
|
998
1001
|
return ['themeNameRef', addFileExtension(importPath, sourceFilePath)];
|
|
999
1002
|
}
|
|
1000
1003
|
case 'experimental_crossFileParsing':
|
|
1001
1004
|
{
|
|
1002
1005
|
const aliases = this.options.aliases;
|
|
1003
|
-
const themeFileExtension = this.options.unstable_moduleResolution.themeFileExtension ?? '.stylex';
|
|
1004
|
-
if (!matchesFileSuffix(themeFileExtension)(importPath)) {
|
|
1005
|
-
return false;
|
|
1006
|
-
}
|
|
1007
1006
|
const resolvedFilePath = filePathResolver(importPath, sourceFilePath, aliases);
|
|
1008
1007
|
return resolvedFilePath ? ['filePath', resolvedFilePath] : false;
|
|
1009
1008
|
}
|
|
@@ -1179,6 +1178,12 @@ function readImportDeclarations(path, state) {
|
|
|
1179
1178
|
if (importedName === 'types') {
|
|
1180
1179
|
state.stylexTypesImport.add(localName);
|
|
1181
1180
|
}
|
|
1181
|
+
if (importedName === 'when') {
|
|
1182
|
+
state.stylexWhenImport.add(localName);
|
|
1183
|
+
}
|
|
1184
|
+
if (importedName === 'defaultMarker') {
|
|
1185
|
+
state.stylexDefaultMarkerImport.add(localName);
|
|
1186
|
+
}
|
|
1182
1187
|
}
|
|
1183
1188
|
}
|
|
1184
1189
|
}
|
|
@@ -1236,6 +1241,12 @@ function readRequires(path, state) {
|
|
|
1236
1241
|
if (prop.key.name === 'types') {
|
|
1237
1242
|
state.stylexTypesImport.add(value.name);
|
|
1238
1243
|
}
|
|
1244
|
+
if (prop.key.name === 'when') {
|
|
1245
|
+
state.stylexWhenImport.add(value.name);
|
|
1246
|
+
}
|
|
1247
|
+
if (prop.key.name === 'defaultMarker') {
|
|
1248
|
+
state.stylexDefaultMarkerImport.add(value.name);
|
|
1249
|
+
}
|
|
1239
1250
|
}
|
|
1240
1251
|
}
|
|
1241
1252
|
}
|
|
@@ -1295,6 +1306,7 @@ const defaultOptions = {
|
|
|
1295
1306
|
enableMediaQueryOrder: false,
|
|
1296
1307
|
enableLegacyValueFlipping: false,
|
|
1297
1308
|
enableLogicalStylesPolyfill: false,
|
|
1309
|
+
enableLTRRTLComments: false,
|
|
1298
1310
|
enableMinifiedKeys: true,
|
|
1299
1311
|
styleResolution: 'property-specificity',
|
|
1300
1312
|
test: false
|
|
@@ -6233,9 +6245,11 @@ function styleXKeyframes(frames, options = defaultOptions) {
|
|
|
6233
6245
|
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());
|
|
6234
6246
|
const ltrStyles = objMap(expandedObject, frame => objMapEntry(frame, entry => generateLTR(entry, options)));
|
|
6235
6247
|
const rtlStyles = objMap(expandedObject, frame => objMapEntry(frame, entry => generateRTL(entry, options) ?? entry));
|
|
6248
|
+
const stableStyles = objMap(expandedObject, frame => objMapEntry(frame, generateLTR));
|
|
6236
6249
|
const ltrString = constructKeyframesObj(ltrStyles);
|
|
6237
6250
|
const rtlString = constructKeyframesObj(rtlStyles);
|
|
6238
|
-
const
|
|
6251
|
+
const stableString = constructKeyframesObj(stableStyles);
|
|
6252
|
+
const animationName = classNamePrefix + hash('<>' + stableString) + '-B';
|
|
6239
6253
|
const ltr = `@keyframes ${animationName}{${ltrString}}`;
|
|
6240
6254
|
const rtl = ltrString === rtlString ? null : `@keyframes ${animationName}{${rtlString}}`;
|
|
6241
6255
|
return [animationName, {
|
|
@@ -6315,6 +6329,53 @@ function genFileBasedIdentifier({
|
|
|
6315
6329
|
return `${fileName}//${exportName}${key != null ? `.${key}` : ''}`;
|
|
6316
6330
|
}
|
|
6317
6331
|
|
|
6332
|
+
function getDefaultMarkerClassName(options = defaultOptions) {
|
|
6333
|
+
const prefix = options.classNamePrefix != null ? `${options.classNamePrefix}-` : '';
|
|
6334
|
+
return `${prefix}default-marker`;
|
|
6335
|
+
}
|
|
6336
|
+
function validatePseudoSelector(pseudo) {
|
|
6337
|
+
if (!pseudo.startsWith(':')) {
|
|
6338
|
+
throw new Error('Pseudo selector must start with ":"');
|
|
6339
|
+
}
|
|
6340
|
+
if (pseudo.startsWith('::')) {
|
|
6341
|
+
throw new Error('Pseudo selector cannot start with "::" (pseudo-elements are not supported)');
|
|
6342
|
+
}
|
|
6343
|
+
}
|
|
6344
|
+
function ancestor(pseudo, options = defaultOptions) {
|
|
6345
|
+
validatePseudoSelector(pseudo);
|
|
6346
|
+
const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
|
|
6347
|
+
return `:where(.${defaultMarker}${pseudo} *)`;
|
|
6348
|
+
}
|
|
6349
|
+
function descendant(pseudo, options = defaultOptions) {
|
|
6350
|
+
validatePseudoSelector(pseudo);
|
|
6351
|
+
const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
|
|
6352
|
+
return `:has(.${defaultMarker}${pseudo})`;
|
|
6353
|
+
}
|
|
6354
|
+
function siblingBefore(pseudo, options = defaultOptions) {
|
|
6355
|
+
validatePseudoSelector(pseudo);
|
|
6356
|
+
const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
|
|
6357
|
+
return `:where(.${defaultMarker}${pseudo} ~ *)`;
|
|
6358
|
+
}
|
|
6359
|
+
function siblingAfter(pseudo, options = defaultOptions) {
|
|
6360
|
+
validatePseudoSelector(pseudo);
|
|
6361
|
+
const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
|
|
6362
|
+
return `:has(~ .${defaultMarker}${pseudo})`;
|
|
6363
|
+
}
|
|
6364
|
+
function anySibling(pseudo, options = defaultOptions) {
|
|
6365
|
+
validatePseudoSelector(pseudo);
|
|
6366
|
+
const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
|
|
6367
|
+
return `:where(.${defaultMarker}${pseudo} ~ *, :has(~ .${defaultMarker}${pseudo}))`;
|
|
6368
|
+
}
|
|
6369
|
+
|
|
6370
|
+
var _stylexWhen = /*#__PURE__*/Object.freeze({
|
|
6371
|
+
__proto__: null,
|
|
6372
|
+
ancestor: ancestor,
|
|
6373
|
+
anySibling: anySibling,
|
|
6374
|
+
descendant: descendant,
|
|
6375
|
+
siblingAfter: siblingAfter,
|
|
6376
|
+
siblingBefore: siblingBefore
|
|
6377
|
+
});
|
|
6378
|
+
|
|
6318
6379
|
const create = styleXCreateSet;
|
|
6319
6380
|
const defineVars = styleXDefineVars;
|
|
6320
6381
|
const defineConsts = styleXDefineConsts;
|
|
@@ -6328,6 +6389,14 @@ const utils = {
|
|
|
6328
6389
|
const messages = m;
|
|
6329
6390
|
const firstThatWorks = stylexFirstThatWorks;
|
|
6330
6391
|
|
|
6392
|
+
function stylexDefaultMarker(options = defaultOptions) {
|
|
6393
|
+
const prefix = options.classNamePrefix != null ? `${options.classNamePrefix}-` : '';
|
|
6394
|
+
return {
|
|
6395
|
+
[`${prefix}default-marker`]: `${prefix}default-marker`,
|
|
6396
|
+
$$css: true
|
|
6397
|
+
};
|
|
6398
|
+
}
|
|
6399
|
+
|
|
6331
6400
|
function getPackagePrefix(absolutePath) {
|
|
6332
6401
|
const nodeModulesIndex = absolutePath.indexOf('node_modules');
|
|
6333
6402
|
if (nodeModulesIndex !== -1) {
|
|
@@ -7146,10 +7215,13 @@ function evaluatePartialObjectRecursively(path, traversalState, functions = {
|
|
|
7146
7215
|
};
|
|
7147
7216
|
}
|
|
7148
7217
|
let key = keyResult.value;
|
|
7218
|
+
const valuePath = prop.get('value');
|
|
7149
7219
|
if (key.startsWith('var(') && key.endsWith(')')) {
|
|
7150
|
-
|
|
7220
|
+
const inner = key.slice(4, -1);
|
|
7221
|
+
if (keyPath.length === 0) {
|
|
7222
|
+
key = inner;
|
|
7223
|
+
}
|
|
7151
7224
|
}
|
|
7152
|
-
const valuePath = prop.get('value');
|
|
7153
7225
|
if (valuePath.isObjectExpression()) {
|
|
7154
7226
|
const result = evaluatePartialObjectRecursively(valuePath, traversalState, functions, [...keyPath, key]);
|
|
7155
7227
|
if (!result.confident) {
|
|
@@ -7267,6 +7339,7 @@ function transformStyleXCreate(path, state) {
|
|
|
7267
7339
|
}
|
|
7268
7340
|
const identifiers = {};
|
|
7269
7341
|
const memberExpressions = {};
|
|
7342
|
+
const stylexWhen = Object.fromEntries(Object.entries(_stylexWhen).map(([key, value]) => [key, (pseudo, marker) => value(pseudo, marker ?? state.options)]));
|
|
7270
7343
|
state.stylexFirstThatWorksImport.forEach(name => {
|
|
7271
7344
|
identifiers[name] = {
|
|
7272
7345
|
fn: firstThatWorks
|
|
@@ -7282,6 +7355,12 @@ function transformStyleXCreate(path, state) {
|
|
|
7282
7355
|
fn: positionTry$1
|
|
7283
7356
|
};
|
|
7284
7357
|
});
|
|
7358
|
+
state.stylexDefaultMarkerImport.forEach(name => {
|
|
7359
|
+
identifiers[name] = () => stylexDefaultMarker(state.options);
|
|
7360
|
+
});
|
|
7361
|
+
state.stylexWhenImport.forEach(name => {
|
|
7362
|
+
identifiers[name] = stylexWhen;
|
|
7363
|
+
});
|
|
7285
7364
|
state.stylexImport.forEach(name => {
|
|
7286
7365
|
if (memberExpressions[name] == null) {
|
|
7287
7366
|
memberExpressions[name] = {};
|
|
@@ -7295,6 +7374,13 @@ function transformStyleXCreate(path, state) {
|
|
|
7295
7374
|
memberExpressions[name].positionTry = {
|
|
7296
7375
|
fn: positionTry$1
|
|
7297
7376
|
};
|
|
7377
|
+
memberExpressions[name].defaultMarker = {
|
|
7378
|
+
fn: () => stylexDefaultMarker(state.options)
|
|
7379
|
+
};
|
|
7380
|
+
identifiers[name] = {
|
|
7381
|
+
...(identifiers[name] ?? {}),
|
|
7382
|
+
when: stylexWhen
|
|
7383
|
+
};
|
|
7298
7384
|
});
|
|
7299
7385
|
const {
|
|
7300
7386
|
confident,
|
|
@@ -8174,6 +8260,22 @@ function transformStylexProps(path, state) {
|
|
|
8174
8260
|
const args = node.arguments.flatMap(arg => arg.type === 'ArrayExpression' ? arg.elements : [arg]);
|
|
8175
8261
|
let currentIndex = -1;
|
|
8176
8262
|
let bailOutIndex = null;
|
|
8263
|
+
const identifiers = {};
|
|
8264
|
+
const memberExpressions = {};
|
|
8265
|
+
state.stylexDefaultMarkerImport.forEach(name => {
|
|
8266
|
+
identifiers[name] = () => stylexDefaultMarker(state.options);
|
|
8267
|
+
});
|
|
8268
|
+
state.stylexImport.forEach(name => {
|
|
8269
|
+
memberExpressions[name] = {
|
|
8270
|
+
defaultMarker: {
|
|
8271
|
+
fn: () => stylexDefaultMarker(state.options)
|
|
8272
|
+
}
|
|
8273
|
+
};
|
|
8274
|
+
});
|
|
8275
|
+
const evaluatePathFnConfig = {
|
|
8276
|
+
identifiers,
|
|
8277
|
+
memberExpressions
|
|
8278
|
+
};
|
|
8177
8279
|
const resolvedArgs = [];
|
|
8178
8280
|
for (const arg of args) {
|
|
8179
8281
|
currentIndex++;
|
|
@@ -8276,7 +8378,7 @@ function transformStylexProps(path, state) {
|
|
|
8276
8378
|
const {
|
|
8277
8379
|
confident,
|
|
8278
8380
|
value: styleValue
|
|
8279
|
-
} = evaluate(path, state);
|
|
8381
|
+
} = evaluate(path, state, evaluatePathFnConfig);
|
|
8280
8382
|
if (!confident || styleValue == null) {
|
|
8281
8383
|
nonNullProps = true;
|
|
8282
8384
|
styleNonNullProps = true;
|
|
@@ -8541,6 +8643,22 @@ function assertValidProperties(path, obj) {
|
|
|
8541
8643
|
}
|
|
8542
8644
|
}
|
|
8543
8645
|
|
|
8646
|
+
function transformStyleXDefaultMarker(path, state) {
|
|
8647
|
+
const {
|
|
8648
|
+
node
|
|
8649
|
+
} = path;
|
|
8650
|
+
if (node.type !== 'CallExpression') {
|
|
8651
|
+
return;
|
|
8652
|
+
}
|
|
8653
|
+
if (node.callee.type === 'Identifier' && state.stylexDefaultMarkerImport.has(node.callee.name) || node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'defaultMarker' && state.stylexImport.has(node.callee.object.name)) {
|
|
8654
|
+
if (node.arguments.length !== 0) {
|
|
8655
|
+
throw path.buildCodeFrameError(illegalArgumentLength('defaultMarker', 0), SyntaxError);
|
|
8656
|
+
}
|
|
8657
|
+
const value = stylexDefaultMarker(state.options);
|
|
8658
|
+
path.replaceWith(convertObjectToAST(value));
|
|
8659
|
+
}
|
|
8660
|
+
}
|
|
8661
|
+
|
|
8544
8662
|
const NAME = 'stylex';
|
|
8545
8663
|
function styleXTransform() {
|
|
8546
8664
|
let state;
|
|
@@ -8691,14 +8809,13 @@ function styleXTransform() {
|
|
|
8691
8809
|
}
|
|
8692
8810
|
},
|
|
8693
8811
|
CallExpression(path) {
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
transformStyleXPositionTry(parentPath, state);
|
|
8700
|
-
}
|
|
8812
|
+
const parentPath = path.parentPath;
|
|
8813
|
+
if (parentPath.isVariableDeclarator()) {
|
|
8814
|
+
transformStyleXKeyframes(parentPath, state);
|
|
8815
|
+
transformStyleXViewTransitionClass(parentPath, state);
|
|
8816
|
+
transformStyleXPositionTry(parentPath, state);
|
|
8701
8817
|
}
|
|
8818
|
+
transformStyleXDefaultMarker(path, state);
|
|
8702
8819
|
transformStyleXDefineVars(path, state);
|
|
8703
8820
|
transformStyleXDefineConsts(path, state);
|
|
8704
8821
|
transformStyleXCreateTheme(path, state);
|
|
@@ -8720,7 +8837,14 @@ function isExported(path) {
|
|
|
8720
8837
|
}
|
|
8721
8838
|
return isExported(path.parentPath);
|
|
8722
8839
|
}
|
|
8723
|
-
function processStylexRules(rules,
|
|
8840
|
+
function processStylexRules(rules, config) {
|
|
8841
|
+
const {
|
|
8842
|
+
useLayers = false,
|
|
8843
|
+
enableLTRRTLComments = false,
|
|
8844
|
+
legacyDisableLayers = false
|
|
8845
|
+
} = typeof config === 'boolean' ? {
|
|
8846
|
+
useLayers: config
|
|
8847
|
+
} : config ?? {};
|
|
8724
8848
|
if (rules.length === 0) {
|
|
8725
8849
|
return '';
|
|
8726
8850
|
}
|
|
@@ -8777,24 +8901,32 @@ function processStylexRules(rules, useLayers = false) {
|
|
|
8777
8901
|
});
|
|
8778
8902
|
let lastKPri = -1;
|
|
8779
8903
|
const grouped = sortedRules.reduce((acc, rule) => {
|
|
8780
|
-
const [
|
|
8904
|
+
const [key, {
|
|
8905
|
+
...styleObj
|
|
8906
|
+
}, priority] = rule;
|
|
8781
8907
|
const priorityLevel = Math.floor(priority / 1000);
|
|
8782
8908
|
Object.keys(styleObj).forEach(dir => {
|
|
8783
8909
|
let original = styleObj[dir];
|
|
8784
8910
|
for (const [varRef, constValue] of constsMap.entries()) {
|
|
8785
|
-
if (typeof original
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8911
|
+
if (typeof original !== 'string') continue;
|
|
8912
|
+
const replacement = String(constValue);
|
|
8913
|
+
original = original.replaceAll(varRef, replacement);
|
|
8914
|
+
if (replacement.startsWith('var(') && replacement.endsWith(')')) {
|
|
8915
|
+
const inside = replacement.slice(4, -1).trim();
|
|
8916
|
+
const commaIdx = inside.indexOf(',');
|
|
8917
|
+
const targetName = (commaIdx >= 0 ? inside.slice(0, commaIdx) : inside).trim();
|
|
8918
|
+
const constName = varRef.slice(4, -1);
|
|
8919
|
+
original = original.replaceAll(`${constName}:`, `${targetName}:`);
|
|
8789
8920
|
}
|
|
8921
|
+
styleObj[dir] = original;
|
|
8790
8922
|
}
|
|
8791
8923
|
});
|
|
8792
8924
|
if (priorityLevel === lastKPri) {
|
|
8793
|
-
acc[acc.length - 1].push(
|
|
8925
|
+
acc[acc.length - 1].push([key, styleObj, priority]);
|
|
8794
8926
|
return acc;
|
|
8795
8927
|
}
|
|
8796
8928
|
lastKPri = priorityLevel;
|
|
8797
|
-
acc.push([
|
|
8929
|
+
acc.push([[key, styleObj, priority]]);
|
|
8798
8930
|
return acc;
|
|
8799
8931
|
}, []);
|
|
8800
8932
|
const header = useLayers ? '\n@layer ' + grouped.map((_, index) => `priority${index + 1}`).join(', ') + ';\n' : '';
|
|
@@ -8807,11 +8939,15 @@ function processStylexRules(rules, useLayers = false) {
|
|
|
8807
8939
|
} = rule;
|
|
8808
8940
|
let ltrRule = ltr,
|
|
8809
8941
|
rtlRule = rtl;
|
|
8810
|
-
if (!useLayers) {
|
|
8942
|
+
if (!useLayers && !legacyDisableLayers) {
|
|
8811
8943
|
ltrRule = addSpecificityLevel(ltrRule, index);
|
|
8812
8944
|
rtlRule = rtlRule && addSpecificityLevel(rtlRule, index);
|
|
8813
8945
|
}
|
|
8814
|
-
|
|
8946
|
+
ltrRule = ltrRule.replace(/\.([a-zA-Z0-9]+), \.([a-zA-Z0-9]+):root/g, '.$1.$1, .$1.$1:root');
|
|
8947
|
+
if (rtlRule) {
|
|
8948
|
+
rtlRule = rtlRule.replace(/\.([a-zA-Z0-9]+), \.([a-zA-Z0-9]+):root/g, '.$1.$1, .$1.$1:root');
|
|
8949
|
+
}
|
|
8950
|
+
return rtlRule ? enableLTRRTLComments ? [`/* @ltr begin */${ltrRule}/* @ltr end */`, `/* @rtl begin */${rtlRule}/* @rtl end */`] : [addAncestorSelector(ltrRule, "html:not([dir='rtl'])"), addAncestorSelector(rtlRule, "html[dir='rtl']")] : [ltrRule];
|
|
8815
8951
|
}).join('\n');
|
|
8816
8952
|
return useLayers && pri > 0 ? `@layer priority${index + 1}{\n${collectedCSS}\n}` : collectedCSS;
|
|
8817
8953
|
}).join('\n');
|
package/lib/index.js.flow
CHANGED
|
@@ -47,7 +47,14 @@ export type Rule = [
|
|
|
47
47
|
];
|
|
48
48
|
declare function processStylexRules(
|
|
49
49
|
rules: Array<Rule>,
|
|
50
|
-
|
|
50
|
+
config?:
|
|
51
|
+
| boolean
|
|
52
|
+
| {
|
|
53
|
+
useLayers?: boolean,
|
|
54
|
+
enableLTRRTLComments?: boolean,
|
|
55
|
+
legacyDisableLayers?: boolean,
|
|
56
|
+
...
|
|
57
|
+
},
|
|
51
58
|
): string;
|
|
52
59
|
|
|
53
60
|
export type StyleXTransformObj = $ReadOnly<{
|
|
@@ -49,6 +49,7 @@ export type StyleXOptions = Readonly<{
|
|
|
49
49
|
enableMediaQueryOrder?: null | undefined | boolean;
|
|
50
50
|
enableLegacyValueFlipping?: null | undefined | boolean;
|
|
51
51
|
enableLogicalStylesPolyfill?: null | undefined | boolean;
|
|
52
|
+
enableLTRRTLComments?: null | undefined | boolean;
|
|
52
53
|
enableMinifiedKeys?: null | undefined | boolean;
|
|
53
54
|
styleResolution:
|
|
54
55
|
| 'application-order'
|
|
@@ -55,6 +55,7 @@ export type StyleXOptions = $ReadOnly<{
|
|
|
55
55
|
enableMediaQueryOrder?: ?boolean,
|
|
56
56
|
enableLegacyValueFlipping?: ?boolean,
|
|
57
57
|
enableLogicalStylesPolyfill?: ?boolean,
|
|
58
|
+
enableLTRRTLComments?: ?boolean,
|
|
58
59
|
enableMinifiedKeys?: ?boolean,
|
|
59
60
|
styleResolution:
|
|
60
61
|
| 'application-order' // The last style applied wins.
|
package/lib/shared/index.d.ts
CHANGED
|
@@ -30,12 +30,13 @@ import stylexFirstThatWorks from './stylex-first-that-works';
|
|
|
30
30
|
import hash from './hash';
|
|
31
31
|
import genFileBasedIdentifier from './utils/file-based-identifier';
|
|
32
32
|
import * as m from './messages';
|
|
33
|
-
export * as types from './types';
|
|
34
33
|
import {
|
|
35
34
|
PSEUDO_CLASS_PRIORITIES as _PSEUDO_CLASS_PRIORITIES,
|
|
36
35
|
AT_RULE_PRIORITIES as _AT_RULE_PRIORITIES,
|
|
37
36
|
PSEUDO_ELEMENT_PRIORITY as _PSEUDO_ELEMENT_PRIORITY,
|
|
38
37
|
} from './utils/property-priorities';
|
|
38
|
+
export * as types from './types';
|
|
39
|
+
export * as when from './when/when';
|
|
39
40
|
export declare const create: typeof styleXCreateSet;
|
|
40
41
|
export declare const defineVars: typeof styleXDefineVars;
|
|
41
42
|
export declare const defineConsts: typeof styleXDefineConsts;
|
package/lib/shared/index.js.flow
CHANGED
|
@@ -37,13 +37,15 @@ import stylexFirstThatWorks from './stylex-first-that-works';
|
|
|
37
37
|
import hash from './hash';
|
|
38
38
|
import genFileBasedIdentifier from './utils/file-based-identifier';
|
|
39
39
|
import * as m from './messages';
|
|
40
|
-
export * as types from './types';
|
|
41
40
|
import {
|
|
42
41
|
PSEUDO_CLASS_PRIORITIES as _PSEUDO_CLASS_PRIORITIES,
|
|
43
42
|
AT_RULE_PRIORITIES as _AT_RULE_PRIORITIES,
|
|
44
43
|
PSEUDO_ELEMENT_PRIORITY as _PSEUDO_ELEMENT_PRIORITY,
|
|
45
44
|
} from './utils/property-priorities';
|
|
46
45
|
|
|
46
|
+
export * as types from './types';
|
|
47
|
+
export * as when from './when/when';
|
|
48
|
+
|
|
47
49
|
declare export const create: typeof styleXCreateSet;
|
|
48
50
|
declare export const defineVars: typeof styleXDefineVars;
|
|
49
51
|
declare export const defineConsts: typeof styleXDefineConsts;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { StyleXOptions } from './common-types';
|
|
11
|
+
declare function stylexDefaultMarker(options?: StyleXOptions): {
|
|
12
|
+
[$$Key$$: string]: string | true;
|
|
13
|
+
};
|
|
14
|
+
export default stylexDefaultMarker;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { StyleXOptions } from './common-types';
|
|
11
|
+
declare export default function stylexDefaultMarker(options?: StyleXOptions): {
|
|
12
|
+
[string]: string | true,
|
|
13
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { StyleXOptions } from '../common-types';
|
|
11
|
+
/**
|
|
12
|
+
* Creates selector that observes if the given pseudo-class is
|
|
13
|
+
* active on an ancestor with the "defaultMarker"
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
|
|
17
|
+
* @returns A :where() clause for the ancestor observer
|
|
18
|
+
*/
|
|
19
|
+
export declare function ancestor(
|
|
20
|
+
pseudo: string,
|
|
21
|
+
options: string | StyleXOptions,
|
|
22
|
+
): string;
|
|
23
|
+
/**
|
|
24
|
+
* Creates selector that observes if the given pseudo-class is
|
|
25
|
+
* active on a descendant with the "defaultMarker"
|
|
26
|
+
*
|
|
27
|
+
* @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
|
|
28
|
+
* @returns A :has() clause for the descendant observer
|
|
29
|
+
*/
|
|
30
|
+
export declare function descendant(
|
|
31
|
+
pseudo: string,
|
|
32
|
+
options: string | StyleXOptions,
|
|
33
|
+
): string;
|
|
34
|
+
/**
|
|
35
|
+
* Creates selector that observes if the given pseudo-class is
|
|
36
|
+
* active on a previous sibling with the "defaultMarker"
|
|
37
|
+
*
|
|
38
|
+
* @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
|
|
39
|
+
* @returns A :where() clause for the previous sibling observer
|
|
40
|
+
*/
|
|
41
|
+
export declare function siblingBefore(
|
|
42
|
+
pseudo: string,
|
|
43
|
+
options: string | StyleXOptions,
|
|
44
|
+
): string;
|
|
45
|
+
/**
|
|
46
|
+
* Creates selector that observes if the given pseudo-class is
|
|
47
|
+
* active on a next sibling with the "defaultMarker"
|
|
48
|
+
*
|
|
49
|
+
* @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
|
|
50
|
+
* @returns A :has() clause for the next sibling observer
|
|
51
|
+
*/
|
|
52
|
+
export declare function siblingAfter(
|
|
53
|
+
pseudo: string,
|
|
54
|
+
options: string | StyleXOptions,
|
|
55
|
+
): string;
|
|
56
|
+
/**
|
|
57
|
+
* Creates selector that observes if the given pseudo-class is
|
|
58
|
+
* active on any sibling with the "defaultMarker"
|
|
59
|
+
*
|
|
60
|
+
* @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
|
|
61
|
+
* @returns A :where() clause for the any sibling observer
|
|
62
|
+
*/
|
|
63
|
+
export declare function anySibling(
|
|
64
|
+
pseudo: string,
|
|
65
|
+
options: string | StyleXOptions,
|
|
66
|
+
): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { StyleXOptions } from '../common-types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates selector that observes if the given pseudo-class is
|
|
14
|
+
* active on an ancestor with the "defaultMarker"
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
|
|
18
|
+
* @returns A :where() clause for the ancestor observer
|
|
19
|
+
*/
|
|
20
|
+
declare export function ancestor(
|
|
21
|
+
pseudo: string,
|
|
22
|
+
options: string | StyleXOptions,
|
|
23
|
+
): string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates selector that observes if the given pseudo-class is
|
|
27
|
+
* active on a descendant with the "defaultMarker"
|
|
28
|
+
*
|
|
29
|
+
* @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
|
|
30
|
+
* @returns A :has() clause for the descendant observer
|
|
31
|
+
*/
|
|
32
|
+
declare export function descendant(
|
|
33
|
+
pseudo: string,
|
|
34
|
+
options: string | StyleXOptions,
|
|
35
|
+
): string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates selector that observes if the given pseudo-class is
|
|
39
|
+
* active on a previous sibling with the "defaultMarker"
|
|
40
|
+
*
|
|
41
|
+
* @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
|
|
42
|
+
* @returns A :where() clause for the previous sibling observer
|
|
43
|
+
*/
|
|
44
|
+
declare export function siblingBefore(
|
|
45
|
+
pseudo: string,
|
|
46
|
+
options: string | StyleXOptions,
|
|
47
|
+
): string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates selector that observes if the given pseudo-class is
|
|
51
|
+
* active on a next sibling with the "defaultMarker"
|
|
52
|
+
*
|
|
53
|
+
* @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
|
|
54
|
+
* @returns A :has() clause for the next sibling observer
|
|
55
|
+
*/
|
|
56
|
+
declare export function siblingAfter(
|
|
57
|
+
pseudo: string,
|
|
58
|
+
options: string | StyleXOptions,
|
|
59
|
+
): string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Creates selector that observes if the given pseudo-class is
|
|
63
|
+
* active on any sibling with the "defaultMarker"
|
|
64
|
+
*
|
|
65
|
+
* @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
|
|
66
|
+
* @returns A :where() clause for the any sibling observer
|
|
67
|
+
*/
|
|
68
|
+
declare export function anySibling(
|
|
69
|
+
pseudo: string,
|
|
70
|
+
options: string | StyleXOptions,
|
|
71
|
+
): string;
|
|
@@ -44,6 +44,7 @@ export type StyleXOptions = Readonly<
|
|
|
44
44
|
enableMediaQueryOrder?: boolean;
|
|
45
45
|
enableLegacyValueFlipping?: boolean;
|
|
46
46
|
enableLogicalStylesPolyfill?: boolean;
|
|
47
|
+
enableLTRRTLComments?: boolean;
|
|
47
48
|
enableMinifiedKeys?: boolean;
|
|
48
49
|
importSources: ReadonlyArray<
|
|
49
50
|
string | Readonly<{ from: string; as: string }>
|
|
@@ -68,6 +69,7 @@ export type StyleXOptions = Readonly<
|
|
|
68
69
|
enableMediaQueryOrder?: boolean;
|
|
69
70
|
enableLegacyValueFlipping?: boolean;
|
|
70
71
|
enableLogicalStylesPolyfill?: boolean;
|
|
72
|
+
enableLTRRTLComments?: boolean;
|
|
71
73
|
enableMinifiedKeys?: boolean;
|
|
72
74
|
importSources: ReadonlyArray<
|
|
73
75
|
string | Readonly<{ from: string; as: string }>
|
|
@@ -121,6 +123,8 @@ declare class StateManager {
|
|
|
121
123
|
readonly stylexCreateThemeImport: Set<string>;
|
|
122
124
|
readonly stylexTypesImport: Set<string>;
|
|
123
125
|
readonly stylexViewTransitionClassImport: Set<string>;
|
|
126
|
+
readonly stylexDefaultMarkerImport: Set<string>;
|
|
127
|
+
readonly stylexWhenImport: Set<string>;
|
|
124
128
|
injectImportInserted: null | undefined | t.Identifier;
|
|
125
129
|
readonly styleMap: Map<string, CompiledNamespaces>;
|
|
126
130
|
readonly styleVars: Map<string, NodePath>;
|
|
@@ -44,6 +44,7 @@ export type StyleXOptions = $ReadOnly<{
|
|
|
44
44
|
enableMediaQueryOrder?: boolean,
|
|
45
45
|
enableLegacyValueFlipping?: boolean,
|
|
46
46
|
enableLogicalStylesPolyfill?: boolean,
|
|
47
|
+
enableLTRRTLComments?: boolean,
|
|
47
48
|
enableMinifiedKeys?: boolean,
|
|
48
49
|
importSources: $ReadOnlyArray<
|
|
49
50
|
string | $ReadOnly<{ from: string, as: string }>,
|
|
@@ -79,6 +80,8 @@ declare export default class StateManager {
|
|
|
79
80
|
+stylexCreateThemeImport: Set<string>;
|
|
80
81
|
+stylexTypesImport: Set<string>;
|
|
81
82
|
+stylexViewTransitionClassImport: Set<string>;
|
|
83
|
+
+stylexDefaultMarkerImport: Set<string>;
|
|
84
|
+
+stylexWhenImport: Set<string>;
|
|
82
85
|
injectImportInserted: ?t.Identifier;
|
|
83
86
|
+styleMap: Map<string, CompiledNamespaces>;
|
|
84
87
|
+styleVars: Map<string, NodePath<>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { NodePath } from '@babel/traverse';
|
|
11
|
+
import * as t from '@babel/types';
|
|
12
|
+
import StateManager from '../utils/state-manager';
|
|
13
|
+
/**
|
|
14
|
+
* Transforms calls to `stylex.defaultMarker()` (or imported `defaultMarker()`)
|
|
15
|
+
* into a string literal: "stylex-marker".
|
|
16
|
+
*/
|
|
17
|
+
declare function transformStyleXDefaultMarker(
|
|
18
|
+
path: NodePath<t.CallExpression>,
|
|
19
|
+
state: StateManager,
|
|
20
|
+
): void;
|
|
21
|
+
export default transformStyleXDefaultMarker;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
11
|
+
|
|
12
|
+
import * as t from '../../flow_modules/@babel/types';
|
|
13
|
+
import StateManager from '../utils/state-manager';
|
|
14
|
+
/**
|
|
15
|
+
* Transforms calls to `stylex.defaultMarker()` (or imported `defaultMarker()`)
|
|
16
|
+
* into a string literal: "stylex-marker".
|
|
17
|
+
*/
|
|
18
|
+
declare export default function transformStyleXDefaultMarker(
|
|
19
|
+
path: NodePath<t.CallExpression>,
|
|
20
|
+
state: StateManager,
|
|
21
|
+
): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/babel-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
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.
|
|
24
|
+
"@stylexjs/stylex": "0.16.0",
|
|
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.
|
|
36
|
+
"scripts": "0.16.0"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"flow_modules/*",
|