@stylexjs/babel-plugin 0.15.4 → 0.16.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/flow_modules/@babel/traverse/index.js.flow +4 -4
- package/flow_modules/@babel/types/index.js.flow +1 -1
- package/lib/index.d.ts +8 -1
- package/lib/index.js +165 -29
- package/lib/index.js.flow +2 -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 +2 -0
- package/lib/utils/state-manager.js.flow +2 -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,
|
|
@@ -2541,7 +2541,7 @@ declare export function buildChildren(
|
|
|
2541
2541
|
): ReturnedChild[];
|
|
2542
2542
|
|
|
2543
2543
|
/*
|
|
2544
|
-
Skipping all the
|
|
2544
|
+
Skipping all the assertX functions as they're not supported in Flow yet.
|
|
2545
2545
|
*/
|
|
2546
2546
|
// TODO: What is this????
|
|
2547
2547
|
declare export var _default$4: {
|
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();
|
|
@@ -1176,6 +1178,12 @@ function readImportDeclarations(path, state) {
|
|
|
1176
1178
|
if (importedName === 'types') {
|
|
1177
1179
|
state.stylexTypesImport.add(localName);
|
|
1178
1180
|
}
|
|
1181
|
+
if (importedName === 'when') {
|
|
1182
|
+
state.stylexWhenImport.add(localName);
|
|
1183
|
+
}
|
|
1184
|
+
if (importedName === 'defaultMarker') {
|
|
1185
|
+
state.stylexDefaultMarkerImport.add(localName);
|
|
1186
|
+
}
|
|
1179
1187
|
}
|
|
1180
1188
|
}
|
|
1181
1189
|
}
|
|
@@ -1233,6 +1241,12 @@ function readRequires(path, state) {
|
|
|
1233
1241
|
if (prop.key.name === 'types') {
|
|
1234
1242
|
state.stylexTypesImport.add(value.name);
|
|
1235
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
|
+
}
|
|
1236
1250
|
}
|
|
1237
1251
|
}
|
|
1238
1252
|
}
|
|
@@ -6231,9 +6245,11 @@ function styleXKeyframes(frames, options = defaultOptions) {
|
|
|
6231
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());
|
|
6232
6246
|
const ltrStyles = objMap(expandedObject, frame => objMapEntry(frame, entry => generateLTR(entry, options)));
|
|
6233
6247
|
const rtlStyles = objMap(expandedObject, frame => objMapEntry(frame, entry => generateRTL(entry, options) ?? entry));
|
|
6248
|
+
const stableStyles = objMap(expandedObject, frame => objMapEntry(frame, generateLTR));
|
|
6234
6249
|
const ltrString = constructKeyframesObj(ltrStyles);
|
|
6235
6250
|
const rtlString = constructKeyframesObj(rtlStyles);
|
|
6236
|
-
const
|
|
6251
|
+
const stableString = constructKeyframesObj(stableStyles);
|
|
6252
|
+
const animationName = classNamePrefix + hash('<>' + stableString) + '-B';
|
|
6237
6253
|
const ltr = `@keyframes ${animationName}{${ltrString}}`;
|
|
6238
6254
|
const rtl = ltrString === rtlString ? null : `@keyframes ${animationName}{${rtlString}}`;
|
|
6239
6255
|
return [animationName, {
|
|
@@ -6313,6 +6329,53 @@ function genFileBasedIdentifier({
|
|
|
6313
6329
|
return `${fileName}//${exportName}${key != null ? `.${key}` : ''}`;
|
|
6314
6330
|
}
|
|
6315
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
|
+
|
|
6316
6379
|
const create = styleXCreateSet;
|
|
6317
6380
|
const defineVars = styleXDefineVars;
|
|
6318
6381
|
const defineConsts = styleXDefineConsts;
|
|
@@ -6326,6 +6389,14 @@ const utils = {
|
|
|
6326
6389
|
const messages = m;
|
|
6327
6390
|
const firstThatWorks = stylexFirstThatWorks;
|
|
6328
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
|
+
|
|
6329
6400
|
function getPackagePrefix(absolutePath) {
|
|
6330
6401
|
const nodeModulesIndex = absolutePath.indexOf('node_modules');
|
|
6331
6402
|
if (nodeModulesIndex !== -1) {
|
|
@@ -7268,6 +7339,7 @@ function transformStyleXCreate(path, state) {
|
|
|
7268
7339
|
}
|
|
7269
7340
|
const identifiers = {};
|
|
7270
7341
|
const memberExpressions = {};
|
|
7342
|
+
const stylexWhen = Object.fromEntries(Object.entries(_stylexWhen).map(([key, value]) => [key, (pseudo, marker) => value(pseudo, marker ?? state.options)]));
|
|
7271
7343
|
state.stylexFirstThatWorksImport.forEach(name => {
|
|
7272
7344
|
identifiers[name] = {
|
|
7273
7345
|
fn: firstThatWorks
|
|
@@ -7283,6 +7355,12 @@ function transformStyleXCreate(path, state) {
|
|
|
7283
7355
|
fn: positionTry$1
|
|
7284
7356
|
};
|
|
7285
7357
|
});
|
|
7358
|
+
state.stylexDefaultMarkerImport.forEach(name => {
|
|
7359
|
+
identifiers[name] = () => stylexDefaultMarker(state.options);
|
|
7360
|
+
});
|
|
7361
|
+
state.stylexWhenImport.forEach(name => {
|
|
7362
|
+
identifiers[name] = stylexWhen;
|
|
7363
|
+
});
|
|
7286
7364
|
state.stylexImport.forEach(name => {
|
|
7287
7365
|
if (memberExpressions[name] == null) {
|
|
7288
7366
|
memberExpressions[name] = {};
|
|
@@ -7296,6 +7374,13 @@ function transformStyleXCreate(path, state) {
|
|
|
7296
7374
|
memberExpressions[name].positionTry = {
|
|
7297
7375
|
fn: positionTry$1
|
|
7298
7376
|
};
|
|
7377
|
+
memberExpressions[name].defaultMarker = {
|
|
7378
|
+
fn: () => stylexDefaultMarker(state.options)
|
|
7379
|
+
};
|
|
7380
|
+
identifiers[name] = {
|
|
7381
|
+
...(identifiers[name] ?? {}),
|
|
7382
|
+
when: stylexWhen
|
|
7383
|
+
};
|
|
7299
7384
|
});
|
|
7300
7385
|
const {
|
|
7301
7386
|
confident,
|
|
@@ -7357,7 +7442,7 @@ function transformStyleXCreate(path, state) {
|
|
|
7357
7442
|
...convertToTestStyles(compiledStyles, varName, state)
|
|
7358
7443
|
};
|
|
7359
7444
|
}
|
|
7360
|
-
if (varName != null) {
|
|
7445
|
+
if (varName != null && isTopLevel(path)) {
|
|
7361
7446
|
const stylesToRemember = removeObjectsWithSpreads(compiledStyles);
|
|
7362
7447
|
state.styleMap.set(varName, stylesToRemember);
|
|
7363
7448
|
state.styleVars.set(varName, path.parentPath);
|
|
@@ -7493,6 +7578,12 @@ function legacyExpandShorthands(dynamicStyles) {
|
|
|
7493
7578
|
}).filter(Boolean);
|
|
7494
7579
|
return expandedKeysToKeyPaths;
|
|
7495
7580
|
}
|
|
7581
|
+
function isTopLevel(path) {
|
|
7582
|
+
if (path.isStatement()) {
|
|
7583
|
+
return path.parentPath?.isProgram() || path.parentPath?.isExportDeclaration();
|
|
7584
|
+
}
|
|
7585
|
+
return path.parentPath != null && isTopLevel(path.parentPath);
|
|
7586
|
+
}
|
|
7496
7587
|
|
|
7497
7588
|
function transformStyleXCreateTheme(callExpressionPath, state) {
|
|
7498
7589
|
const callExpressionNode = callExpressionPath.node;
|
|
@@ -8175,6 +8266,22 @@ function transformStylexProps(path, state) {
|
|
|
8175
8266
|
const args = node.arguments.flatMap(arg => arg.type === 'ArrayExpression' ? arg.elements : [arg]);
|
|
8176
8267
|
let currentIndex = -1;
|
|
8177
8268
|
let bailOutIndex = null;
|
|
8269
|
+
const identifiers = {};
|
|
8270
|
+
const memberExpressions = {};
|
|
8271
|
+
state.stylexDefaultMarkerImport.forEach(name => {
|
|
8272
|
+
identifiers[name] = () => stylexDefaultMarker(state.options);
|
|
8273
|
+
});
|
|
8274
|
+
state.stylexImport.forEach(name => {
|
|
8275
|
+
memberExpressions[name] = {
|
|
8276
|
+
defaultMarker: {
|
|
8277
|
+
fn: () => stylexDefaultMarker(state.options)
|
|
8278
|
+
}
|
|
8279
|
+
};
|
|
8280
|
+
});
|
|
8281
|
+
const evaluatePathFnConfig = {
|
|
8282
|
+
identifiers,
|
|
8283
|
+
memberExpressions
|
|
8284
|
+
};
|
|
8178
8285
|
const resolvedArgs = [];
|
|
8179
8286
|
for (const arg of args) {
|
|
8180
8287
|
currentIndex++;
|
|
@@ -8277,7 +8384,7 @@ function transformStylexProps(path, state) {
|
|
|
8277
8384
|
const {
|
|
8278
8385
|
confident,
|
|
8279
8386
|
value: styleValue
|
|
8280
|
-
} = evaluate(path, state);
|
|
8387
|
+
} = evaluate(path, state, evaluatePathFnConfig);
|
|
8281
8388
|
if (!confident || styleValue == null) {
|
|
8282
8389
|
nonNullProps = true;
|
|
8283
8390
|
styleNonNullProps = true;
|
|
@@ -8542,6 +8649,22 @@ function assertValidProperties(path, obj) {
|
|
|
8542
8649
|
}
|
|
8543
8650
|
}
|
|
8544
8651
|
|
|
8652
|
+
function transformStyleXDefaultMarker(path, state) {
|
|
8653
|
+
const {
|
|
8654
|
+
node
|
|
8655
|
+
} = path;
|
|
8656
|
+
if (node.type !== 'CallExpression') {
|
|
8657
|
+
return;
|
|
8658
|
+
}
|
|
8659
|
+
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)) {
|
|
8660
|
+
if (node.arguments.length !== 0) {
|
|
8661
|
+
throw path.buildCodeFrameError(illegalArgumentLength('defaultMarker', 0), SyntaxError);
|
|
8662
|
+
}
|
|
8663
|
+
const value = stylexDefaultMarker(state.options);
|
|
8664
|
+
path.replaceWith(convertObjectToAST(value));
|
|
8665
|
+
}
|
|
8666
|
+
}
|
|
8667
|
+
|
|
8545
8668
|
const NAME = 'stylex';
|
|
8546
8669
|
function styleXTransform() {
|
|
8547
8670
|
let state;
|
|
@@ -8692,14 +8815,13 @@ function styleXTransform() {
|
|
|
8692
8815
|
}
|
|
8693
8816
|
},
|
|
8694
8817
|
CallExpression(path) {
|
|
8695
|
-
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
transformStyleXPositionTry(parentPath, state);
|
|
8701
|
-
}
|
|
8818
|
+
const parentPath = path.parentPath;
|
|
8819
|
+
if (parentPath.isVariableDeclarator()) {
|
|
8820
|
+
transformStyleXKeyframes(parentPath, state);
|
|
8821
|
+
transformStyleXViewTransitionClass(parentPath, state);
|
|
8822
|
+
transformStyleXPositionTry(parentPath, state);
|
|
8702
8823
|
}
|
|
8824
|
+
transformStyleXDefaultMarker(path, state);
|
|
8703
8825
|
transformStyleXDefineVars(path, state);
|
|
8704
8826
|
transformStyleXDefineConsts(path, state);
|
|
8705
8827
|
transformStyleXCreateTheme(path, state);
|
|
@@ -8724,7 +8846,9 @@ function isExported(path) {
|
|
|
8724
8846
|
function processStylexRules(rules, config) {
|
|
8725
8847
|
const {
|
|
8726
8848
|
useLayers = false,
|
|
8727
|
-
enableLTRRTLComments = false
|
|
8849
|
+
enableLTRRTLComments = false,
|
|
8850
|
+
legacyDisableLayers = false,
|
|
8851
|
+
useLegacyClassnamesSort = false
|
|
8728
8852
|
} = typeof config === 'boolean' ? {
|
|
8729
8853
|
useLayers: config
|
|
8730
8854
|
} : config ?? {};
|
|
@@ -8764,44 +8888,56 @@ function processStylexRules(rules, config) {
|
|
|
8764
8888
|
for (const [key, value] of constsMap.entries()) {
|
|
8765
8889
|
constsMap.set(key, resolveConstant(value));
|
|
8766
8890
|
}
|
|
8767
|
-
const sortedRules = nonConstantRules.sort(([, {
|
|
8891
|
+
const sortedRules = nonConstantRules.sort(([classname1, {
|
|
8768
8892
|
ltr: rule1
|
|
8769
|
-
}, firstPriority], [, {
|
|
8893
|
+
}, firstPriority], [classname2, {
|
|
8770
8894
|
ltr: rule2
|
|
8771
8895
|
}, secondPriority]) => {
|
|
8772
8896
|
const priorityComparison = firstPriority - secondPriority;
|
|
8773
8897
|
if (priorityComparison !== 0) return priorityComparison;
|
|
8774
|
-
if (
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
if (
|
|
8778
|
-
|
|
8898
|
+
if (useLegacyClassnamesSort) {
|
|
8899
|
+
return classname1.localeCompare(classname2);
|
|
8900
|
+
} else {
|
|
8901
|
+
if (rule1.startsWith('@') && !rule2.startsWith('@')) {
|
|
8902
|
+
const query1 = rule1.slice(0, rule1.indexOf('{'));
|
|
8903
|
+
const query2 = rule2.slice(0, rule2.indexOf('{'));
|
|
8904
|
+
if (query1 !== query2) {
|
|
8905
|
+
return query1.localeCompare(query2);
|
|
8906
|
+
}
|
|
8779
8907
|
}
|
|
8908
|
+
const property1 = rule1.slice(rule1.lastIndexOf('{'));
|
|
8909
|
+
const property2 = rule2.slice(rule2.lastIndexOf('{'));
|
|
8910
|
+
return property1.localeCompare(property2);
|
|
8780
8911
|
}
|
|
8781
|
-
const property1 = rule1.slice(rule1.lastIndexOf('{'));
|
|
8782
|
-
const property2 = rule2.slice(rule2.lastIndexOf('{'));
|
|
8783
|
-
return property1.localeCompare(property2);
|
|
8784
8912
|
});
|
|
8785
8913
|
let lastKPri = -1;
|
|
8786
8914
|
const grouped = sortedRules.reduce((acc, rule) => {
|
|
8787
|
-
const [
|
|
8915
|
+
const [key, {
|
|
8916
|
+
...styleObj
|
|
8917
|
+
}, priority] = rule;
|
|
8788
8918
|
const priorityLevel = Math.floor(priority / 1000);
|
|
8789
8919
|
Object.keys(styleObj).forEach(dir => {
|
|
8790
8920
|
let original = styleObj[dir];
|
|
8791
8921
|
for (const [varRef, constValue] of constsMap.entries()) {
|
|
8792
|
-
if (typeof original
|
|
8793
|
-
|
|
8794
|
-
|
|
8795
|
-
|
|
8922
|
+
if (typeof original !== 'string') continue;
|
|
8923
|
+
const replacement = String(constValue);
|
|
8924
|
+
original = original.replaceAll(varRef, replacement);
|
|
8925
|
+
if (replacement.startsWith('var(') && replacement.endsWith(')')) {
|
|
8926
|
+
const inside = replacement.slice(4, -1).trim();
|
|
8927
|
+
const commaIdx = inside.indexOf(',');
|
|
8928
|
+
const targetName = (commaIdx >= 0 ? inside.slice(0, commaIdx) : inside).trim();
|
|
8929
|
+
const constName = varRef.slice(4, -1);
|
|
8930
|
+
original = original.replaceAll(`${constName}:`, `${targetName}:`);
|
|
8796
8931
|
}
|
|
8932
|
+
styleObj[dir] = original;
|
|
8797
8933
|
}
|
|
8798
8934
|
});
|
|
8799
8935
|
if (priorityLevel === lastKPri) {
|
|
8800
|
-
acc[acc.length - 1].push(
|
|
8936
|
+
acc[acc.length - 1].push([key, styleObj, priority]);
|
|
8801
8937
|
return acc;
|
|
8802
8938
|
}
|
|
8803
8939
|
lastKPri = priorityLevel;
|
|
8804
|
-
acc.push([
|
|
8940
|
+
acc.push([[key, styleObj, priority]]);
|
|
8805
8941
|
return acc;
|
|
8806
8942
|
}, []);
|
|
8807
8943
|
const header = useLayers ? '\n@layer ' + grouped.map((_, index) => `priority${index + 1}`).join(', ') + ';\n' : '';
|
|
@@ -8814,7 +8950,7 @@ function processStylexRules(rules, config) {
|
|
|
8814
8950
|
} = rule;
|
|
8815
8951
|
let ltrRule = ltr,
|
|
8816
8952
|
rtlRule = rtl;
|
|
8817
|
-
if (!useLayers) {
|
|
8953
|
+
if (!useLayers && !legacyDisableLayers) {
|
|
8818
8954
|
ltrRule = addSpecificityLevel(ltrRule, index);
|
|
8819
8955
|
rtlRule = rtlRule && addSpecificityLevel(rtlRule, index);
|
|
8820
8956
|
}
|
package/lib/index.js.flow
CHANGED
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;
|
|
@@ -123,6 +123,8 @@ declare class StateManager {
|
|
|
123
123
|
readonly stylexCreateThemeImport: Set<string>;
|
|
124
124
|
readonly stylexTypesImport: Set<string>;
|
|
125
125
|
readonly stylexViewTransitionClassImport: Set<string>;
|
|
126
|
+
readonly stylexDefaultMarkerImport: Set<string>;
|
|
127
|
+
readonly stylexWhenImport: Set<string>;
|
|
126
128
|
injectImportInserted: null | undefined | t.Identifier;
|
|
127
129
|
readonly styleMap: Map<string, CompiledNamespaces>;
|
|
128
130
|
readonly styleVars: Map<string, NodePath>;
|
|
@@ -80,6 +80,8 @@ declare export default class StateManager {
|
|
|
80
80
|
+stylexCreateThemeImport: Set<string>;
|
|
81
81
|
+stylexTypesImport: Set<string>;
|
|
82
82
|
+stylexViewTransitionClassImport: Set<string>;
|
|
83
|
+
+stylexDefaultMarkerImport: Set<string>;
|
|
84
|
+
+stylexWhenImport: Set<string>;
|
|
83
85
|
injectImportInserted: ?t.Identifier;
|
|
84
86
|
+styleMap: Map<string, CompiledNamespaces>;
|
|
85
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.1",
|
|
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.1",
|
|
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.1"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"flow_modules/*",
|