@stylexjs/babel-plugin 0.14.1 → 0.14.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.js CHANGED
@@ -740,6 +740,7 @@ class StateManager {
740
740
  const enableFontSizePxToRem = logAndDefault(boolean(), options.enableFontSizePxToRem ?? false, false, 'options.enableFontSizePxToRem');
741
741
  const enableInlinedConditionalMerge = logAndDefault(boolean(), options.enableInlinedConditionalMerge ?? true, true, 'options.enableInlinedConditionalMerge');
742
742
  const enableMinifiedKeys = logAndDefault(boolean(), options.enableMinifiedKeys ?? true, true, 'options.enableMinifiedKeys');
743
+ const enableLegacyValueFlipping = logAndDefault(boolean(), options.enableLegacyValueFlipping ?? false, false, 'options.enableLegacyValueFlipping');
743
744
  const enableLogicalStylesPolyfill = logAndDefault(boolean(), options.enableLogicalStylesPolyfill ?? false, false, 'options.enableLogicalStylesPolyfill');
744
745
  const test = logAndDefault(boolean(), options.test ?? false, false, 'options.test');
745
746
  const configRuntimeInjection = logAndDefault(checkRuntimeInjection, options.runtimeInjection ?? false, false, 'options.runtimeInjection');
@@ -770,6 +771,7 @@ class StateManager {
770
771
  enableFontSizePxToRem,
771
772
  enableInlinedConditionalMerge,
772
773
  enableMinifiedKeys,
774
+ enableLegacyValueFlipping,
773
775
  enableLogicalStylesPolyfill,
774
776
  importSources,
775
777
  rewriteAliases: typeof options.rewriteAliases === 'boolean' ? options.rewriteAliases : false,
@@ -1278,6 +1280,7 @@ const defaultOptions = {
1278
1280
  enableDevClassNames: false,
1279
1281
  enableDebugDataProp: true,
1280
1282
  enableFontSizePxToRem: false,
1283
+ enableLegacyValueFlipping: false,
1281
1284
  enableLogicalStylesPolyfill: false,
1282
1285
  enableMinifiedKeys: true,
1283
1286
  styleResolution: 'property-specificity',
@@ -2120,9 +2123,18 @@ const shorthands$1 = {
2120
2123
  }, []);
2121
2124
  return [['containIntrinsicWidth', width], ['containIntrinsicHeight', height]];
2122
2125
  },
2123
- inset: rawValue => [['top', rawValue], ['insetInlineEnd', rawValue], ['bottom', rawValue], ['insetInlineStart', rawValue]],
2124
- insetInline: rawValue => [...shorthands$1.start(rawValue), ...shorthands$1.end(rawValue)],
2125
- insetBlock: rawValue => [['top', rawValue], ['bottom', rawValue]],
2126
+ inset: rawValue => {
2127
+ const [top, right = top, bottom = top, left = right] = splitValue(rawValue);
2128
+ return [['top', top], ['insetInlineEnd', right], ['bottom', bottom], ['insetInlineStart', left]];
2129
+ },
2130
+ insetInline: rawValue => {
2131
+ const [start, end = start] = splitValue(rawValue);
2132
+ return [...shorthands$1.start(start), ...shorthands$1.end(end)];
2133
+ },
2134
+ insetBlock: rawValue => {
2135
+ const [top, bottom = top] = splitValue(rawValue);
2136
+ return [['top', top], ['bottom', bottom]];
2137
+ },
2126
2138
  start: rawValue => [['insetInlineStart', rawValue], ['left', null], ['right', null]],
2127
2139
  end: rawValue => [['insetInlineEnd', rawValue], ['left', null], ['right', null]],
2128
2140
  left: rawValue => [['left', rawValue], ['insetInlineStart', null], ['insetInlineEnd', null]],
@@ -3054,17 +3066,29 @@ const propertyToRTL = {
3054
3066
  }
3055
3067
  return [key, words.map(word => word === 'start' || word === 'insetInlineStart' ? 'right' : word === 'end' || word === 'insetInlineEnd' ? 'left' : word).join(' ')];
3056
3068
  },
3057
- cursor: _ref40 => {
3069
+ cursor: function (_ref40) {
3058
3070
  let [key, val] = _ref40;
3071
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
3072
+ if (!options.enableLegacyValueFlipping) {
3073
+ return null;
3074
+ }
3059
3075
  return cursorFlip[val] != null ? [key, cursorFlip[val]] : null;
3060
3076
  },
3061
- 'box-shadow': _ref41 => {
3077
+ 'box-shadow': function (_ref41) {
3062
3078
  let [key, val] = _ref41;
3079
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
3080
+ if (!options.enableLegacyValueFlipping) {
3081
+ return null;
3082
+ }
3063
3083
  const rtlVal = flipShadow(val);
3064
3084
  return rtlVal ? [key, rtlVal] : null;
3065
3085
  },
3066
- 'text-shadow': _ref42 => {
3086
+ 'text-shadow': function (_ref42) {
3067
3087
  let [key, val] = _ref42;
3088
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
3089
+ if (!options.enableLegacyValueFlipping) {
3090
+ return null;
3091
+ }
3068
3092
  const rtlVal = flipShadow(val);
3069
3093
  return rtlVal ? [key, rtlVal] : null;
3070
3094
  }
@@ -3090,7 +3114,7 @@ function generateRTL(_ref43) {
3090
3114
  if (!propertyToRTL[key]) {
3091
3115
  return null;
3092
3116
  }
3093
- return propertyToRTL[key]([key, value]);
3117
+ return propertyToRTL[key]([key, value], options);
3094
3118
  }
3095
3119
 
3096
3120
  const longHandPhysical = new Set();
@@ -4298,18 +4322,18 @@ function getDefaultValue(value) {
4298
4322
  function styleXDefineVars(variables, options) {
4299
4323
  const {
4300
4324
  classNamePrefix,
4301
- themeName,
4325
+ exportId,
4302
4326
  debug,
4303
4327
  enableDebugClassNames
4304
4328
  } = {
4305
4329
  ...defaultOptions,
4306
4330
  ...options
4307
4331
  };
4308
- const themeNameHash = classNamePrefix + hash(themeName);
4332
+ const varGroupHash = classNamePrefix + hash(exportId);
4309
4333
  const typedVariables = {};
4310
4334
  const variablesMap = objMap(variables, (value, key) => {
4311
4335
  const varSafeKey = (key[0] >= '0' && key[0] <= '9' ? `_${key}` : key).replace(/[^a-zA-Z0-9]/g, '_');
4312
- const nameHash = key.startsWith('--') ? key.slice(2) : debug && enableDebugClassNames ? varSafeKey + '-' + classNamePrefix + hash(`${themeName}.${key}`) : classNamePrefix + hash(`${themeName}.${key}`);
4336
+ const nameHash = key.startsWith('--') ? key.slice(2) : debug && enableDebugClassNames ? varSafeKey + '-' + classNamePrefix + hash(`${exportId}.${key}`) : classNamePrefix + hash(`${exportId}.${key}`);
4313
4337
  if (isCSSType(value)) {
4314
4338
  const v = value;
4315
4339
  typedVariables[nameHash] = {
@@ -4332,7 +4356,7 @@ function styleXDefineVars(variables, options) {
4332
4356
  } = _ref;
4333
4357
  return `var(--${nameHash})`;
4334
4358
  });
4335
- const injectableStyles = constructCssVariablesString(variablesMap, themeNameHash);
4359
+ const injectableStyles = constructCssVariablesString(variablesMap, varGroupHash);
4336
4360
  const injectableTypes = objMap(typedVariables, (_ref2, nameHash) => {
4337
4361
  let {
4338
4362
  initialValue: iv,
@@ -4346,13 +4370,13 @@ function styleXDefineVars(variables, options) {
4346
4370
  });
4347
4371
  return [{
4348
4372
  ...themeVariablesObject,
4349
- __themeName__: themeNameHash
4373
+ __varGroupHash__: varGroupHash
4350
4374
  }, {
4351
4375
  ...injectableTypes,
4352
4376
  ...injectableStyles
4353
4377
  }];
4354
4378
  }
4355
- function constructCssVariablesString(variables, themeNameHash) {
4379
+ function constructCssVariablesString(variables, varGroupHash) {
4356
4380
  const rulesByAtRule = {};
4357
4381
  for (const [key, {
4358
4382
  nameHash,
@@ -4366,12 +4390,12 @@ function constructCssVariablesString(variables, themeNameHash) {
4366
4390
  const result = {};
4367
4391
  for (const [atRule, value] of Object.entries(rulesByAtRule)) {
4368
4392
  const suffix = atRule === 'default' ? '' : `-${hash(atRule)}`;
4369
- const selector = `:root, .${themeNameHash}`;
4393
+ const selector = `:root, .${varGroupHash}`;
4370
4394
  let ltr = `${selector}{${value.join('')}}`;
4371
4395
  if (atRule !== 'default') {
4372
4396
  ltr = wrapWithAtRules(ltr, atRule);
4373
4397
  }
4374
- result[themeNameHash + suffix] = {
4398
+ result[varGroupHash + suffix] = {
4375
4399
  ltr,
4376
4400
  rtl: null,
4377
4401
  priority: priorityForAtRule(atRule) * 0.1
@@ -4383,7 +4407,7 @@ function constructCssVariablesString(variables, themeNameHash) {
4383
4407
  function styleXDefineConsts(constants, options) {
4384
4408
  const {
4385
4409
  classNamePrefix,
4386
- themeName,
4410
+ exportId,
4387
4411
  debug,
4388
4412
  enableDebugClassNames
4389
4413
  } = {
@@ -4397,10 +4421,10 @@ function styleXDefineConsts(constants, options) {
4397
4421
  throw new Error(INVALID_CONST_KEY);
4398
4422
  }
4399
4423
  const varSafeKey = (key[0] >= '0' && key[0] <= '9' ? `_${key}` : key).replace(/[^a-zA-Z0-9]/g, '_');
4400
- const nameHash = debug && enableDebugClassNames ? `${varSafeKey}-${classNamePrefix}${hash(`${themeName}.${key}`)}` : `${classNamePrefix}${hash(`${themeName}.${key}`)}`;
4424
+ const constKey = debug && enableDebugClassNames ? `${varSafeKey}-${classNamePrefix}${hash(`${exportId}.${key}`)}` : `${classNamePrefix}${hash(`${exportId}.${key}`)}`;
4401
4425
  jsOutput[key] = value;
4402
- injectableStyles[nameHash] = {
4403
- constKey: nameHash,
4426
+ injectableStyles[constKey] = {
4427
+ constKey,
4404
4428
  constVal: value,
4405
4429
  priority: 0,
4406
4430
  ltr: '',
@@ -4411,7 +4435,7 @@ function styleXDefineConsts(constants, options) {
4411
4435
  }
4412
4436
 
4413
4437
  function styleXCreateTheme(themeVars, variables, options) {
4414
- if (typeof themeVars.__themeName__ !== 'string') {
4438
+ if (typeof themeVars.__varGroupHash__ !== 'string') {
4415
4439
  throw new Error('Can only override variables theme created with defineVars().');
4416
4440
  }
4417
4441
  const {
@@ -4451,9 +4475,9 @@ function styleXCreateTheme(themeVars, variables, options) {
4451
4475
  };
4452
4476
  }
4453
4477
  }
4454
- const themeClass = `${overrideClassName} ${themeVars.__themeName__}`;
4478
+ const themeClass = `${overrideClassName} ${themeVars.__varGroupHash__}`;
4455
4479
  return [{
4456
- [themeVars.__themeName__]: themeClass,
4480
+ [themeVars.__varGroupHash__]: themeClass,
4457
4481
  $$css: true
4458
4482
  }, stylesToInject];
4459
4483
  }
@@ -4767,7 +4791,7 @@ function evaluateThemeRef(fileName, exportName, state) {
4767
4791
  if (key.startsWith('--')) {
4768
4792
  return `var(${key})`;
4769
4793
  }
4770
- const strToHash = key === '__themeName__' ? utils.genFileBasedIdentifier({
4794
+ const strToHash = key === '__varGroupHash__' ? utils.genFileBasedIdentifier({
4771
4795
  fileName,
4772
4796
  exportName
4773
4797
  }) : utils.genFileBasedIdentifier({
@@ -4779,9 +4803,9 @@ function evaluateThemeRef(fileName, exportName, state) {
4779
4803
  debug,
4780
4804
  enableDebugClassNames
4781
4805
  } = state.traversalState.options;
4782
- const varSafeKey = key === '__themeName__' ? '' : (key[0] >= '0' && key[0] <= '9' ? `_${key}` : key).replace(/[^a-zA-Z0-9]/g, '_') + '-';
4806
+ const varSafeKey = key === '__varGroupHash__' ? '' : (key[0] >= '0' && key[0] <= '9' ? `_${key}` : key).replace(/[^a-zA-Z0-9]/g, '_') + '-';
4783
4807
  const varName = debug && enableDebugClassNames ? varSafeKey + state.traversalState.options.classNamePrefix + utils.hash(strToHash) : state.traversalState.options.classNamePrefix + utils.hash(strToHash);
4784
- if (key === '__themeName__') {
4808
+ if (key === '__varGroupHash__') {
4785
4809
  return varName;
4786
4810
  }
4787
4811
  return `var(--${varName})`;
@@ -5846,7 +5870,7 @@ function transformStyleXCreateTheme(callExpressionPath, state) {
5846
5870
  if (typeof overrides !== 'object' || overrides == null) {
5847
5871
  throw callExpressionPath.buildCodeFrameError(messages.nonStyleObject('createTheme'), SyntaxError);
5848
5872
  }
5849
- if (typeof variables.__themeName__ !== 'string' || variables.__themeName__ === '') {
5873
+ if (typeof variables.__varGroupHash__ !== 'string' || variables.__varGroupHash__ === '') {
5850
5874
  throw callExpressionPath.buildCodeFrameError('Can only override variables theme created with defineVars().', SyntaxError);
5851
5875
  }
5852
5876
  let [overridesObj, injectedStyles] = createTheme(variables, overrides, state.options);
@@ -5970,7 +5994,7 @@ function transformStyleXDefineVars(callExpressionPath, state) {
5970
5994
  const exportName = varId.name;
5971
5995
  const [variablesObj, injectedStylesSansKeyframes] = defineVars(value, {
5972
5996
  ...state.options,
5973
- themeName: utils.genFileBasedIdentifier({
5997
+ exportId: utils.genFileBasedIdentifier({
5974
5998
  fileName,
5975
5999
  exportName
5976
6000
  })
@@ -6031,13 +6055,13 @@ function transformStyleXDefineConsts(callExpressionPath, state) {
6031
6055
  throw new Error(messages.cannotGenerateHash('defineConsts'));
6032
6056
  }
6033
6057
  const exportName = varId.name;
6034
- const themeName = utils.genFileBasedIdentifier({
6058
+ const exportId = utils.genFileBasedIdentifier({
6035
6059
  fileName,
6036
6060
  exportName
6037
6061
  });
6038
6062
  const [transformedJsOutput, jsOutput] = defineConsts(value, {
6039
6063
  ...state.options,
6040
- themeName
6064
+ exportId
6041
6065
  });
6042
6066
  callExpressionPath.replaceWith(convertObjectToAST(transformedJsOutput));
6043
6067
  const styles = Object.entries(jsOutput).map(_ref => {
@@ -46,6 +46,7 @@ export type StyleXOptions = Readonly<{
46
46
  enableDebugDataProp?: null | undefined | boolean;
47
47
  enableDevClassNames?: null | undefined | boolean;
48
48
  enableFontSizePxToRem?: null | undefined | boolean;
49
+ enableLegacyValueFlipping?: null | undefined | boolean;
49
50
  enableLogicalStylesPolyfill?: null | undefined | boolean;
50
51
  enableMinifiedKeys?: null | undefined | boolean;
51
52
  styleResolution:
@@ -52,6 +52,7 @@ export type StyleXOptions = $ReadOnly<{
52
52
  enableDebugDataProp?: ?boolean,
53
53
  enableDevClassNames?: ?boolean,
54
54
  enableFontSizePxToRem?: ?boolean,
55
+ enableLegacyValueFlipping?: ?boolean,
55
56
  enableLogicalStylesPolyfill?: ?boolean,
56
57
  enableMinifiedKeys?: ?boolean,
57
58
  styleResolution:
@@ -10,7 +10,7 @@
10
10
  import type { InjectableStyle, StyleXOptions } from './common-types';
11
11
  declare function styleXCreateTheme(
12
12
  themeVars: {
13
- readonly __themeName__: string;
13
+ readonly __varGroupHash__: string;
14
14
  readonly [$$Key$$: string]: string;
15
15
  },
16
16
  variables: {
@@ -13,7 +13,7 @@ import type { InjectableStyle, StyleXOptions } from './common-types';
13
13
  // and returns a hashed className with variables overrides.
14
14
  //
15
15
  declare export default function styleXCreateTheme(
16
- themeVars: { +__themeName__: string, +[string]: string },
16
+ themeVars: { +__varGroupHash__: string, +[string]: string },
17
17
  variables: { +[string]: string | { default: string, +[string]: string } },
18
18
  options?: StyleXOptions,
19
19
  ): [{ $$css: true, +[string]: string }, { [string]: InjectableStyle }];
@@ -12,8 +12,8 @@ import type { ConstsConfig } from './stylex-consts-utils';
12
12
  declare function styleXDefineConsts<Vars extends ConstsConfig>(
13
13
  constants: Vars,
14
14
  options: Readonly<
15
- Omit<Partial<StyleXOptions>, keyof ({ themeName: string })> & {
16
- themeName: string;
15
+ Omit<Partial<StyleXOptions>, keyof ({ exportId: string })> & {
16
+ exportId: string;
17
17
  }
18
18
  >,
19
19
  ): [
@@ -12,7 +12,7 @@ import type { ConstsConfig } from './stylex-consts-utils';
12
12
 
13
13
  declare export default function styleXDefineConsts<Vars: ConstsConfig>(
14
14
  constants: Vars,
15
- options: $ReadOnly<{ ...Partial<StyleXOptions>, themeName: string, ... }>,
15
+ options: $ReadOnly<{ ...Partial<StyleXOptions>, exportId: string, ... }>,
16
16
  ): [
17
17
  { [string]: string | number }, // jsOutput JS output
18
18
  { [string]: InjectableConstStyle }, // metadata for registerinjectableStyles
@@ -13,15 +13,15 @@ type VarsKeysWithStringValues<Vars extends VarsConfig> = Readonly<{
13
13
  [$$Key$$: keyof Vars]: string;
14
14
  }>;
15
15
  type VarsObject<Vars extends VarsConfig> = Readonly<
16
- Omit<VarsKeysWithStringValues<Vars>, keyof ({ __themeName__: string })> & {
17
- __themeName__: string;
16
+ Omit<VarsKeysWithStringValues<Vars>, keyof ({ __varGroupHash__: string })> & {
17
+ __varGroupHash__: string;
18
18
  }
19
19
  >;
20
20
  declare function styleXDefineVars<Vars extends VarsConfig>(
21
21
  variables: Vars,
22
22
  options: Readonly<
23
- Omit<Partial<StyleXOptions>, keyof ({ themeName: string })> & {
24
- themeName: string;
23
+ Omit<Partial<StyleXOptions>, keyof ({ exportId: string })> & {
24
+ exportId: string;
25
25
  }
26
26
  >,
27
27
  ): [VarsObject<Vars>, { [$$Key$$: string]: InjectableStyle }];
@@ -15,12 +15,12 @@ type VarsKeysWithStringValues<Vars: VarsConfig> = $ReadOnly<{
15
15
 
16
16
  type VarsObject<Vars: VarsConfig> = $ReadOnly<{
17
17
  ...VarsKeysWithStringValues<Vars>,
18
- __themeName__: string,
18
+ __varGroupHash__: string,
19
19
  }>;
20
20
 
21
21
  // Similar to `stylex.create` it takes an object of variables with their values
22
22
  // and returns a string after hashing it.
23
23
  declare export default function styleXDefineVars<Vars: VarsConfig>(
24
24
  variables: Vars,
25
- options: $ReadOnly<{ ...Partial<StyleXOptions>, themeName: string, ... }>,
25
+ options: $ReadOnly<{ ...Partial<StyleXOptions>, exportId: string, ... }>,
26
26
  ): [VarsObject<Vars>, { [string]: InjectableStyle }];
@@ -46,6 +46,7 @@ export type StyleXOptions = Readonly<
46
46
  enableDebugDataProp?: boolean;
47
47
  enableDevClassNames?: boolean;
48
48
  enableInlinedConditionalMerge?: boolean;
49
+ enableLegacyValueFlipping?: boolean;
49
50
  enableLogicalStylesPolyfill?: boolean;
50
51
  enableMinifiedKeys?: boolean;
51
52
  importSources: ReadonlyArray<
@@ -68,6 +69,7 @@ export type StyleXOptions = Readonly<
68
69
  enableDebugDataProp?: boolean;
69
70
  enableDevClassNames?: boolean;
70
71
  enableInlinedConditionalMerge?: boolean;
72
+ enableLegacyValueFlipping?: boolean;
71
73
  enableLogicalStylesPolyfill?: boolean;
72
74
  enableMinifiedKeys?: boolean;
73
75
  importSources: ReadonlyArray<
@@ -48,6 +48,7 @@ export type StyleXOptions = $ReadOnly<{
48
48
  enableDebugDataProp?: boolean,
49
49
  enableDevClassNames?: boolean,
50
50
  enableInlinedConditionalMerge?: boolean,
51
+ enableLegacyValueFlipping?: boolean,
51
52
  enableLogicalStylesPolyfill?: boolean,
52
53
  enableMinifiedKeys?: boolean,
53
54
  importSources: $ReadOnlyArray<
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/babel-plugin",
3
- "version": "0.14.1",
3
+ "version": "0.14.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.14.1",
24
+ "@stylexjs/stylex": "0.14.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.14.1"
36
+ "scripts": "0.14.2"
37
37
  },
38
38
  "files": [
39
39
  "flow_modules/*",