@stylexjs/babel-plugin 0.16.1 → 0.16.2

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.d.ts CHANGED
@@ -42,8 +42,7 @@ declare function processStylexRules(
42
42
  useLayers?: boolean,
43
43
  enableLTRRTLComments?: boolean,
44
44
  legacyDisableLayers?: boolean,
45
- ...
46
- },
45
+ }
47
46
  ): string;
48
47
  export type StyleXTransformObj = Readonly<{
49
48
  (): PluginObj;
package/lib/index.js CHANGED
@@ -5403,6 +5403,13 @@ const AT_RULE_PRIORITIES = {
5403
5403
  '@container': 300
5404
5404
  };
5405
5405
  const PSEUDO_ELEMENT_PRIORITY = 5000;
5406
+ const RELATIONAL_SELECTORS = {
5407
+ ANCESTOR: /^:where\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\s+\*\)$/,
5408
+ DESCENDANT: /^:where\(:has\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/,
5409
+ SIBLING_BEFORE: /^:where\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\s+~\s+\*\)$/,
5410
+ SIBLING_AFTER: /^:where\(:has\(~\s\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/,
5411
+ ANY_SIBLING: /^:where\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\s+~\s+\*,\s+:has\(~\s\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/
5412
+ };
5406
5413
  function getPriority(key) {
5407
5414
  if (key.startsWith('--')) {
5408
5415
  return 1;
@@ -5419,6 +5426,25 @@ function getPriority(key) {
5419
5426
  if (key.startsWith('::')) {
5420
5427
  return PSEUDO_ELEMENT_PRIORITY;
5421
5428
  }
5429
+ const pseudoBase = p => (PSEUDO_CLASS_PRIORITIES[p] ?? 40) / 100;
5430
+ const ancestorMatch = RELATIONAL_SELECTORS.ANCESTOR.exec(key);
5431
+ if (ancestorMatch) {
5432
+ return 10 + pseudoBase(ancestorMatch[1]);
5433
+ }
5434
+ const descendantMatch = RELATIONAL_SELECTORS.DESCENDANT.exec(key);
5435
+ if (descendantMatch) {
5436
+ return 15 + pseudoBase(descendantMatch[1]);
5437
+ }
5438
+ const anySiblingMatch = RELATIONAL_SELECTORS.ANY_SIBLING.exec(key);
5439
+ if (anySiblingMatch) return 20 + Math.max(pseudoBase(anySiblingMatch[1]), pseudoBase(anySiblingMatch[2]));
5440
+ const siblingBeforeMatch = RELATIONAL_SELECTORS.SIBLING_BEFORE.exec(key);
5441
+ if (siblingBeforeMatch) {
5442
+ return 30 + pseudoBase(siblingBeforeMatch[1]);
5443
+ }
5444
+ const siblingAfterMatch = RELATIONAL_SELECTORS.SIBLING_AFTER.exec(key);
5445
+ if (siblingAfterMatch) {
5446
+ return 40 + pseudoBase(siblingAfterMatch[1]);
5447
+ }
5422
5448
  if (key.startsWith(':')) {
5423
5449
  const prop = key.startsWith(':') && key.includes('(') ? key.slice(0, key.indexOf('(')) : key;
5424
5450
  return PSEUDO_CLASS_PRIORITIES[prop] ?? 40;
@@ -6060,7 +6086,7 @@ function priorityForAtRule(atRule) {
6060
6086
  if (atRule === 'default') {
6061
6087
  return 1;
6062
6088
  }
6063
- return atRule.split(SPLIT_TOKEN).length;
6089
+ return 1 + atRule.split(SPLIT_TOKEN).length;
6064
6090
  }
6065
6091
  function getDefaultValue(value) {
6066
6092
  if (typeof value === 'string' || typeof value === 'number') {
@@ -6154,7 +6180,7 @@ function constructCssVariablesString(variables, varGroupHash) {
6154
6180
  result[varGroupHash + suffix] = {
6155
6181
  ltr,
6156
6182
  rtl: null,
6157
- priority: priorityForAtRule(atRule) * 0.1
6183
+ priority: priorityForAtRule(atRule) / 10
6158
6184
  };
6159
6185
  }
6160
6186
  return result;
@@ -6217,19 +6243,14 @@ function styleXCreateTheme(themeVars, variables, options) {
6217
6243
  for (const atRule of sortedAtRules) {
6218
6244
  const decls = rulesByAtRule[atRule].join('');
6219
6245
  const rule = `.${overrideClassName}, .${overrideClassName}:root{${decls}}`;
6220
- if (atRule === 'default') {
6221
- stylesToInject[overrideClassName] = {
6222
- ltr: rule,
6223
- priority: 0.5,
6224
- rtl: null
6225
- };
6226
- } else {
6227
- stylesToInject[overrideClassName + '-' + hash(atRule)] = {
6228
- ltr: wrapWithAtRules(rule, atRule),
6229
- priority: 0.5 + 0.1 * priorityForAtRule(atRule),
6230
- rtl: null
6231
- };
6232
- }
6246
+ const priority = 0.4 + priorityForAtRule(atRule) / 10;
6247
+ const suffix = atRule === 'default' ? '' : `-${hash(atRule)}`;
6248
+ const ltr = atRule === 'default' ? rule : wrapWithAtRules(rule, atRule);
6249
+ stylesToInject[overrideClassName + suffix] = {
6250
+ ltr: ltr,
6251
+ priority: priority,
6252
+ rtl: null
6253
+ };
6233
6254
  }
6234
6255
  const themeClass = `${overrideClassName} ${themeVars.__varGroupHash__}`;
6235
6256
  return [{
@@ -6349,7 +6370,7 @@ function ancestor(pseudo, options = defaultOptions) {
6349
6370
  function descendant(pseudo, options = defaultOptions) {
6350
6371
  validatePseudoSelector(pseudo);
6351
6372
  const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
6352
- return `:has(.${defaultMarker}${pseudo})`;
6373
+ return `:where(:has(.${defaultMarker}${pseudo}))`;
6353
6374
  }
6354
6375
  function siblingBefore(pseudo, options = defaultOptions) {
6355
6376
  validatePseudoSelector(pseudo);
@@ -6359,7 +6380,7 @@ function siblingBefore(pseudo, options = defaultOptions) {
6359
6380
  function siblingAfter(pseudo, options = defaultOptions) {
6360
6381
  validatePseudoSelector(pseudo);
6361
6382
  const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
6362
- return `:has(~ .${defaultMarker}${pseudo})`;
6383
+ return `:where(:has(~ .${defaultMarker}${pseudo}))`;
6363
6384
  }
6364
6385
  function anySibling(pseudo, options = defaultOptions) {
6365
6386
  validatePseudoSelector(pseudo);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/babel-plugin",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
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.16.1",
24
+ "@stylexjs/stylex": "0.16.2",
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.16.1"
36
+ "scripts": "0.16.2"
37
37
  },
38
38
  "files": [
39
39
  "flow_modules/*",