@stylexjs/shared 0.8.0 → 0.9.0-beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,6 +36,7 @@ export type FlatCompiledStyles = Readonly<{
36
36
  }>;
37
37
  export type StyleXOptions = Readonly<{
38
38
  dev: boolean;
39
+ debug: null | undefined | boolean;
39
40
  test: boolean;
40
41
  useRemForFontSize: boolean;
41
42
  classNamePrefix: string;
@@ -43,6 +43,7 @@ export type FlatCompiledStyles = $ReadOnly<{
43
43
 
44
44
  export type StyleXOptions = $ReadOnly<{
45
45
  dev: boolean,
46
+ debug: ?boolean,
46
47
  test: boolean,
47
48
  useRemForFontSize: boolean,
48
49
  classNamePrefix: string,
@@ -16,5 +16,5 @@ export declare function convertStyleToClassName(
16
16
  ): StyleRule;
17
17
  declare function variableFallbacks(
18
18
  values: ReadonlyArray<string>,
19
- ): Array<string>;
19
+ ): ReadonlyArray<string>;
20
20
  export default variableFallbacks;
@@ -10,15 +10,16 @@ var _dashify = _interopRequireDefault(require("./utils/dashify"));
10
10
  var _transformValue = _interopRequireDefault(require("./transform-value"));
11
11
  var _generateCssRule = require("./generate-css-rule");
12
12
  var _defaultOptions = require("./utils/default-options");
13
- var _objectUtils = require("./utils/object-utils");
14
13
  var messages = _interopRequireWildcard(require("./messages"));
14
+ var _ruleUtils = require("./utils/rule-utils");
15
15
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
16
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
18
  function convertStyleToClassName(objEntry, pseudos, atRules) {
19
19
  let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _defaultOptions.defaultOptions;
20
20
  const {
21
- classNamePrefix = 'x'
21
+ classNamePrefix = 'x',
22
+ debug = false
22
23
  } = options;
23
24
  const [key, rawValue] = objEntry;
24
25
  const dashedKey = (0, _dashify.default)(key);
@@ -26,13 +27,14 @@ function convertStyleToClassName(objEntry, pseudos, atRules) {
26
27
  if (Array.isArray(value) && value.find(val => val.startsWith('var(') && val.endsWith(')'))) {
27
28
  value = variableFallbacks(value);
28
29
  }
29
- const sortedPseudos = (0, _objectUtils.arraySort)(pseudos ?? []);
30
- const sortedAtRules = (0, _objectUtils.arraySort)(atRules ?? []);
31
- const atRuleHashString = sortedPseudos.join('');
32
- const pseudoHashString = sortedAtRules.join('');
33
- const modifierHashString = atRuleHashString + pseudoHashString || 'null';
34
- const stringToHash = Array.isArray(value) ? dashedKey + value.join(', ') + modifierHashString : dashedKey + value + modifierHashString;
35
- const className = classNamePrefix + (0, _hash.default)('<>' + stringToHash);
30
+ const sortedPseudos = (0, _ruleUtils.sortPseudos)(pseudos ?? []);
31
+ const sortedAtRules = (0, _ruleUtils.sortAtRules)(atRules ?? []);
32
+ const pseudoHashString = sortedPseudos.join('');
33
+ const atRuleHashString = sortedAtRules.join('');
34
+ const modifierHashString = pseudoHashString + atRuleHashString || 'null';
35
+ const valueAsString = Array.isArray(value) ? value.join(', ') : value;
36
+ const stringToHash = dashedKey + valueAsString + modifierHashString;
37
+ const className = debug ? `${key}-${classNamePrefix}${(0, _hash.default)('<>' + stringToHash)}` : classNamePrefix + (0, _hash.default)('<>' + stringToHash);
36
38
  const cssRules = (0, _generateCssRule.generateRule)(className, dashedKey, value, pseudos, atRules);
37
39
  return [key, className, cssRules];
38
40
  }
@@ -24,4 +24,4 @@ declare export function convertStyleToClassName(
24
24
 
25
25
  declare export default function variableFallbacks(
26
26
  values: $ReadOnlyArray<string>,
27
- ): Array<string>;
27
+ ): $ReadOnlyArray<string>;
@@ -9,7 +9,12 @@
9
9
 
10
10
  import type { InjectableStyle, StyleXOptions } from '../common-types';
11
11
  import type { IncludedStyles } from '../stylex-include';
12
- export type ComputedStyle = null | Readonly<[string, InjectableStyle]>;
12
+ export type ClassesToOriginalPaths = {
13
+ readonly [className: string]: ReadonlyArray<string>;
14
+ };
15
+ export type ComputedStyle = null | Readonly<
16
+ [string, InjectableStyle, ClassesToOriginalPaths]
17
+ >;
13
18
  export interface IPreRule {
14
19
  compiled(
15
20
  options: StyleXOptions,
@@ -30,15 +35,17 @@ export declare class PreIncludedStylesRule implements IPreRule {
30
35
  export declare class PreRule implements IPreRule {
31
36
  readonly property: string;
32
37
  readonly value: string | number | ReadonlyArray<string | number>;
33
- readonly pseudos: ReadonlyArray<string>;
34
- readonly atRules: ReadonlyArray<string>;
38
+ readonly keyPath: ReadonlyArray<string>;
35
39
  constructor(
36
40
  property: string,
37
41
  value: string | number | ReadonlyArray<string | number>,
38
- pseudos?: null | undefined | ReadonlyArray<string>,
39
- atRules?: null | undefined | ReadonlyArray<string>,
42
+ keyPath?: ReadonlyArray<string>,
40
43
  );
41
- compiled(options: StyleXOptions): ReadonlyArray<[string, InjectableStyle]>;
44
+ get pseudos(): ReadonlyArray<string>;
45
+ get atRules(): ReadonlyArray<string>;
46
+ compiled(
47
+ options: StyleXOptions,
48
+ ): ReadonlyArray<[string, InjectableStyle, ClassesToOriginalPaths]>;
42
49
  equals(other: IPreRule): boolean;
43
50
  }
44
51
  export declare class PreRuleSet implements IPreRule {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.PreRuleSet = exports.PreRule = exports.PreIncludedStylesRule = exports.NullPreRule = void 0;
7
7
  var _convertToClassName = require("../convert-to-className");
8
8
  var _objectUtils = require("../utils/object-utils");
9
+ var _ruleUtils = require("../utils/rule-utils");
9
10
  class NullPreRule {
10
11
  compiled(_options) {
11
12
  return [null];
@@ -27,25 +28,25 @@ class PreIncludedStylesRule {
27
28
  }
28
29
  }
29
30
  exports.PreIncludedStylesRule = PreIncludedStylesRule;
30
- const stringComparator = (a, b) => {
31
- if (a === 'default') {
32
- return -1;
33
- }
34
- if (b === 'default') {
35
- return 1;
36
- }
37
- return a.localeCompare(b);
38
- };
39
31
  class PreRule {
40
- constructor(property, value, pseudos, atRules) {
32
+ constructor(property, value, keyPath) {
41
33
  this.property = property;
34
+ this.keyPath = keyPath ?? [];
42
35
  this.value = value;
43
- this.pseudos = pseudos ? (0, _objectUtils.arraySort)(pseudos, stringComparator) : [];
44
- this.atRules = atRules ? (0, _objectUtils.arraySort)(atRules) : [];
36
+ }
37
+ get pseudos() {
38
+ const unsortedPseudos = this.keyPath.filter(key => key.startsWith(':'));
39
+ return (0, _ruleUtils.sortPseudos)(unsortedPseudos);
40
+ }
41
+ get atRules() {
42
+ const unsortedAtRules = this.keyPath.filter(key => key.startsWith('@'));
43
+ return (0, _ruleUtils.sortAtRules)(unsortedAtRules);
45
44
  }
46
45
  compiled(options) {
47
46
  const [_key, className, rule] = (0, _convertToClassName.convertStyleToClassName)([this.property, this.value], this.pseudos ?? [], this.atRules ?? [], options);
48
- return [[className, rule]];
47
+ return [[className, rule, {
48
+ [className]: this.keyPath
49
+ }]];
49
50
  }
50
51
  equals(other) {
51
52
  if (!(other instanceof PreRule)) {
@@ -10,7 +10,13 @@
10
10
  import type { InjectableStyle, StyleXOptions } from '../common-types';
11
11
  import type { IncludedStyles } from '../stylex-include';
12
12
 
13
- export type ComputedStyle = null | $ReadOnly<[string, InjectableStyle]>;
13
+ export type ClassesToOriginalPaths = {
14
+ +[className: string]: $ReadOnlyArray<string>,
15
+ };
16
+
17
+ export type ComputedStyle = null | $ReadOnly<
18
+ [string, InjectableStyle, ClassesToOriginalPaths],
19
+ >;
14
20
 
15
21
  // The classes in this file are used to represent objects that
16
22
  // can be compiled into one or CSS rules.
@@ -41,15 +47,17 @@ declare export class PreIncludedStylesRule implements IPreRule {
41
47
  declare export class PreRule implements IPreRule {
42
48
  +property: string;
43
49
  +value: string | number | $ReadOnlyArray<string | number>;
44
- +pseudos: $ReadOnlyArray<string>;
45
- +atRules: $ReadOnlyArray<string>;
50
+ +keyPath: $ReadOnlyArray<string>;
46
51
  constructor(
47
52
  property: string,
48
53
  value: string | number | $ReadOnlyArray<string | number>,
49
- pseudos?: ?$ReadOnlyArray<string>,
50
- atRules?: ?$ReadOnlyArray<string>,
54
+ keyPath?: $ReadOnlyArray<string>,
51
55
  ): void;
52
- compiled(options: StyleXOptions): $ReadOnlyArray<[string, InjectableStyle]>;
56
+ get pseudos(): $ReadOnlyArray<string>;
57
+ get atRules(): $ReadOnlyArray<string>;
58
+ compiled(
59
+ options: StyleXOptions,
60
+ ): $ReadOnlyArray<[string, InjectableStyle, ClassesToOriginalPaths]>;
53
61
  equals(other: IPreRule): boolean;
54
62
  }
55
63
 
@@ -19,7 +19,6 @@ export declare function flattenRawStyleObject(
19
19
  ): ReadonlyArray<Readonly<[string, IPreRule]>>;
20
20
  export declare function _flattenRawStyleObject(
21
21
  style: RawStyles,
22
- pseudos: ReadonlyArray<string>,
23
- atRules: ReadonlyArray<string>,
22
+ keyPath: ReadonlyArray<string>,
24
23
  options: StyleXOptions,
25
24
  ): Array<Readonly<[string, AnyPreRule | PreIncludedStylesRule]>>;
@@ -10,9 +10,9 @@ var _PreRule = require("./PreRule");
10
10
  var _stylexInclude = require("../stylex-include");
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  function flattenRawStyleObject(style, options) {
13
- return _flattenRawStyleObject(style, [], [], options);
13
+ return _flattenRawStyleObject(style, [], options);
14
14
  }
15
- function _flattenRawStyleObject(style, pseudos, atRules, options) {
15
+ function _flattenRawStyleObject(style, keyPath, options) {
16
16
  const flattened = [];
17
17
  for (const _key in style) {
18
18
  const value = style[_key];
@@ -27,7 +27,7 @@ function _flattenRawStyleObject(style, pseudos, atRules, options) {
27
27
  if (value === null) {
28
28
  flattened.push([property, new _PreRule.NullPreRule()]);
29
29
  } else {
30
- flattened.push([property, new _PreRule.PreRule(property, value, pseudos, atRules)]);
30
+ flattened.push([property, new _PreRule.PreRule(property, value, keyPath.includes(key) ? keyPath.map(k => k === key ? property : k) : [...keyPath, property])]);
31
31
  }
32
32
  }
33
33
  continue;
@@ -61,7 +61,7 @@ function _flattenRawStyleObject(style, pseudos, atRules, options) {
61
61
  if (value === null) {
62
62
  flattened.push([property, new _PreRule.NullPreRule()]);
63
63
  } else {
64
- flattened.push([property, new _PreRule.PreRule(property, value, pseudos, atRules)]);
64
+ flattened.push([property, new _PreRule.PreRule(property, value, keyPath.includes(_key) ? keyPath.map(k => k === _key ? property : k) : [...keyPath, property])]);
65
65
  }
66
66
  });
67
67
  continue;
@@ -70,16 +70,9 @@ function _flattenRawStyleObject(style, pseudos, atRules, options) {
70
70
  const equivalentPairs = {};
71
71
  for (const condition in value) {
72
72
  const innerValue = value[condition];
73
- const pseudosToPassDown = [...pseudos];
74
- const atRulesToPassDown = [...atRules];
75
- if (condition.startsWith(':')) {
76
- pseudosToPassDown.push(condition);
77
- } else if (condition.startsWith('@')) {
78
- atRulesToPassDown.push(condition);
79
- }
80
73
  const pairs = _flattenRawStyleObject({
81
74
  [key]: innerValue
82
- }, pseudosToPassDown, atRulesToPassDown, options);
75
+ }, keyPath.length > 0 ? [...keyPath, condition] : [key, condition], options);
83
76
  for (const [property, preRule] of pairs) {
84
77
  if (preRule instanceof _PreRule.PreIncludedStylesRule) {
85
78
  throw new Error('stylex.include can only be used at the top-level');
@@ -103,14 +96,7 @@ function _flattenRawStyleObject(style, pseudos, atRules, options) {
103
96
  }
104
97
  }
105
98
  if (typeof value === 'object' && (key.startsWith(':') || key.startsWith('@'))) {
106
- const pseudosToPassDown = [...pseudos];
107
- const atRulesToPassDown = [...atRules];
108
- if (key.startsWith(':')) {
109
- pseudosToPassDown.push(key);
110
- } else if (key.startsWith('@')) {
111
- atRulesToPassDown.push(key);
112
- }
113
- const pairs = _flattenRawStyleObject(value, pseudosToPassDown, atRulesToPassDown, options);
99
+ const pairs = _flattenRawStyleObject(value, [...keyPath, _key], options);
114
100
  for (const [property, preRule] of pairs) {
115
101
  flattened.push([key + '_' + property, preRule]);
116
102
  }
@@ -21,7 +21,6 @@ declare export function flattenRawStyleObject(
21
21
 
22
22
  declare export function _flattenRawStyleObject(
23
23
  style: RawStyles,
24
- pseudos: $ReadOnlyArray<string>,
25
- atRules: $ReadOnlyArray<string>,
24
+ keyPath: $ReadOnlyArray<string>,
26
25
  options: StyleXOptions,
27
26
  ): Array<$ReadOnly<[string, AnyPreRule | PreIncludedStylesRule]>>;
@@ -13,6 +13,6 @@ export declare function getExpandedKeys(
13
13
  ): ReadonlyArray<string>;
14
14
  declare function flatMapExpandedShorthands(
15
15
  objEntry: Readonly<[string, TStyleValue]>,
16
- options: StyleXOptions,
16
+ options: Readonly<{ styleResolution: StyleXOptions['styleResolution'] }>,
17
17
  ): ReadonlyArray<[string, TStyleValue]>;
18
18
  export default flatMapExpandedShorthands;
@@ -15,5 +15,8 @@ declare export function getExpandedKeys(
15
15
 
16
16
  declare export default function flatMapExpandedShorthands(
17
17
  objEntry: $ReadOnly<[string, TStyleValue]>,
18
- options: StyleXOptions,
18
+ options: $ReadOnly<{
19
+ styleResolution: StyleXOptions['styleResolution'],
20
+ ...
21
+ }>,
19
22
  ): $ReadOnlyArray<[string, TStyleValue]>;
@@ -38,6 +38,17 @@ const shorthands = {
38
38
  const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
39
39
  return [['borderTopStartRadius', top], ['borderTopEndRadius', right], ['borderBottomEndRadius', bottom], ['borderBottomStartRadius', left]];
40
40
  },
41
+ containIntrinsicSize: rawValue => {
42
+ const parts = (0, _splitCssValue.default)(rawValue);
43
+ const [width, height = width] = parts.reduce((coll, part) => {
44
+ const lastElement = coll[coll.length - 1];
45
+ if (lastElement === 'auto' && part != null) {
46
+ return [...coll.slice(0, -1), `auto ${part}`];
47
+ }
48
+ return [...coll, part];
49
+ }, []);
50
+ return [['containIntrinsicWidth', width], ['containIntrinsicHeight', height]];
51
+ },
41
52
  inset: rawValue => [['top', rawValue], ['end', rawValue], ['bottom', rawValue], ['start', rawValue]],
42
53
  insetInline: rawValue => [...shorthands.start(rawValue), ...shorthands.end(rawValue)],
43
54
  insetBlock: rawValue => [['top', rawValue], ['bottom', rawValue]],
@@ -13,11 +13,15 @@ import type {
13
13
  StyleXOptions,
14
14
  FlatCompiledStyles,
15
15
  } from './common-types';
16
+ type ClassPathsInNamespace = {
17
+ readonly [className: string]: ReadonlyArray<string>;
18
+ };
16
19
  declare function styleXCreateSet(
17
20
  namespaces: { readonly [$$Key$$: string]: RawStyles },
18
21
  options?: StyleXOptions,
19
22
  ): [
20
23
  { [$$Key$$: string]: FlatCompiledStyles },
21
24
  { [$$Key$$: string]: InjectableStyle },
25
+ { readonly [$$Key$$: string]: ClassPathsInNamespace },
22
26
  ];
23
27
  export default styleXCreateSet;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = styleXCreateSet;
7
- var _objectUtils = require("./utils/object-utils");
8
7
  var _stylexInclude = require("./stylex-include");
9
8
  var _defaultOptions = require("./utils/default-options");
10
9
  var _flattenRawStyleObj = require("./preprocess-rules/flatten-raw-style-obj");
@@ -13,24 +12,36 @@ function styleXCreateSet(namespaces) {
13
12
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaultOptions.defaultOptions;
14
13
  const resolvedNamespaces = {};
15
14
  const injectedStyles = {};
15
+ const namespaceToClassPaths = {};
16
16
  for (const namespaceName of Object.keys(namespaces)) {
17
17
  const namespace = namespaces[namespaceName];
18
+ const classPathsInNamespace = {};
18
19
  (0, _basicValidation.validateNamespace)(namespace);
19
- const flattenedNamespace = (0, _flattenRawStyleObj.flattenRawStyleObject)(namespace, options);
20
+ const seenProperties = new Set();
21
+ const flattenedNamespace = (0, _flattenRawStyleObj.flattenRawStyleObject)(namespace, options).reduceRight((arr, curr) => {
22
+ if (seenProperties.has(curr[0])) {
23
+ return arr;
24
+ }
25
+ seenProperties.add(curr[0]);
26
+ arr.unshift(curr);
27
+ return arr;
28
+ }, []);
20
29
  const compiledNamespaceTuples = flattenedNamespace.map(_ref => {
21
30
  let [key, value] = _ref;
22
31
  return [key, value.compiled(options)];
23
32
  });
24
- const compiledNamespace = (0, _objectUtils.objFromEntries)(compiledNamespaceTuples);
25
33
  const namespaceObj = {};
26
- for (const key of Object.keys(compiledNamespace)) {
27
- const value = compiledNamespace[key];
34
+ for (const [key, value] of compiledNamespaceTuples) {
28
35
  if (value instanceof _stylexInclude.IncludedStyles) {
29
36
  namespaceObj[key] = value;
30
37
  } else {
31
38
  const classNameTuples = value.map(v => Array.isArray(v) ? v : null).filter(Boolean);
32
- const className = classNameTuples.map(_ref2 => {
33
- let [className] = _ref2;
39
+ classNameTuples.forEach(_ref2 => {
40
+ let [_className, _, classesToOriginalPath] = _ref2;
41
+ Object.assign(classPathsInNamespace, classesToOriginalPath);
42
+ });
43
+ const className = classNameTuples.map(_ref3 => {
44
+ let [className] = _ref3;
34
45
  return className;
35
46
  }).join(' ') || null;
36
47
  namespaceObj[key] = className;
@@ -45,6 +56,7 @@ function styleXCreateSet(namespaces) {
45
56
  ...namespaceObj,
46
57
  $$css: true
47
58
  };
59
+ namespaceToClassPaths[namespaceName] = classPathsInNamespace;
48
60
  }
49
- return [resolvedNamespaces, injectedStyles];
61
+ return [resolvedNamespaces, injectedStyles, namespaceToClassPaths];
50
62
  }
@@ -14,6 +14,10 @@ import type {
14
14
  FlatCompiledStyles,
15
15
  } from './common-types';
16
16
 
17
+ type ClassPathsInNamespace = {
18
+ +[className: string]: $ReadOnlyArray<string>,
19
+ };
20
+
17
21
  // This takes the object of styles passed to `stylex.create` and transforms it.
18
22
  // The transformation replaces style values with classNames.
19
23
  //
@@ -27,4 +31,8 @@ import type {
27
31
  declare export default function styleXCreateSet(
28
32
  namespaces: { +[string]: RawStyles },
29
33
  options?: StyleXOptions,
30
- ): [{ [string]: FlatCompiledStyles }, { [string]: InjectableStyle }];
34
+ ): [
35
+ { [string]: FlatCompiledStyles },
36
+ { [string]: InjectableStyle },
37
+ { +[string]: ClassPathsInNamespace },
38
+ ];
@@ -44,4 +44,4 @@ const numberPropertySuffixes = {
44
44
  voiceDuration: 'ms'
45
45
  };
46
46
  const timeUnits = exports.timeUnits = new Set(Object.keys(numberPropertySuffixes));
47
- const lengthUnits = exports.lengthUnits = new Set(['backgroundPositionX', 'backgroundPositionY', 'blockSize', 'borderBlockEndWidth', 'borderBlockStartWidth', 'borderBlockWidth', 'borderVerticalWidth', 'borderVerticalWidth', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomWidth', 'borderEndEndRadius', 'borderEndStartRadius', 'borderInlineEndWidth', 'borderEndWidth', 'borderInlineStartWidth', 'borderStartWidth', 'borderInlineWidth', 'borderHorizontalWidth', 'borderLeftWidth', 'borderRightWidth', 'borderSpacing', 'borderStartEndRadius', 'borderStartStartRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopWidth', 'bottom', 'columnGap', 'columnRuleWidth', 'columnWidth', 'containIntrinsicBlockSize', 'containIntrinsicHeight', 'containIntrinsicInlineSize', 'containIntrinsicWidth', 'flexBasis', 'fontSize', 'fontSmooth', 'height', 'inlineSize', 'insetBlockEnd', 'insetBlockStart', 'insetInlineEnd', 'insetInlineStart', 'left', 'letterSpacing', 'marginBlockEnd', 'marginBlockStart', 'marginBottom', 'marginInlineEnd', 'marginEnd', 'marginInlineStart', 'marginStart', 'marginLeft', 'marginRight', 'marginTop', 'maskBorderOutset', 'maskBorderWidth', 'maxBlockSize', 'maxHeight', 'maxInlineSize', 'maxWidth', 'minBlockSize', 'minHeight', 'minInlineSize', 'minWidth', 'offsetDistance', 'outlineOffset', 'outlineWidth', 'overflowClipMargin', 'paddingBlockEnd', 'paddingBlockStart', 'paddingBottom', 'paddingInlineEnd', 'paddingEnd', 'paddingInlineStart', 'paddingStart', 'paddingLeft', 'paddingRight', 'paddingTop', 'perspective', 'right', 'rowGap', 'scrollMarginBlockEnd', 'scrollMarginBlockStart', 'scrollMarginBottom', 'scrollMarginInlineEnd', 'scrollMarginInlineStart', 'scrollMarginLeft', 'scrollMarginRight', 'scrollMarginTop', 'scrollPaddingBlockEnd', 'scrollPaddingBlockStart', 'scrollPaddingBottom', 'scrollPaddingInlineEnd', 'scrollPaddingInlineStart', 'scrollPaddingLeft', 'scrollPaddingRight', 'scrollPaddingTop', 'scrollSnapMarginBottom', 'scrollSnapMarginLeft', 'scrollSnapMarginRight', 'scrollSnapMarginTop', 'shapeMargin', 'tabSize', 'textDecorationThickness', 'textIndent', 'textUnderlineOffset', 'top', 'transformOrigin', 'translate', 'verticalAlign', 'width', 'wordSpacing', 'border', 'borderBlock', 'borderBlockEnd', 'borderBlockStart', 'borderBottom', 'borderLeft', 'borderRadius', 'borderRight', 'borderTop', 'borderWidth', 'columnRule', 'containIntrinsicSize', 'gap', 'inset', 'insetBlock', 'insetInline', 'margin', 'marginBlock', 'marginVertical', 'marginInline', 'marginHorizontal', 'offset', 'outline', 'padding', 'paddingBlock', 'paddingVertical', 'paddingInline', 'paddingHorizontal', 'scrollMargin', 'scrollMarginBlock', 'scrollMarginInline', 'scrollPadding', 'scrollPaddingBlock', 'scrollPaddingInline', 'scrollSnapMargin']);
47
+ const lengthUnits = exports.lengthUnits = new Set(['backgroundPositionX', 'backgroundPositionY', 'blockSize', 'borderBlockEndWidth', 'borderBlockStartWidth', 'borderBlockWidth', 'borderVerticalWidth', 'borderVerticalWidth', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomWidth', 'borderEndEndRadius', 'borderEndStartRadius', 'borderInlineEndWidth', 'borderEndWidth', 'borderInlineStartWidth', 'borderStartWidth', 'borderInlineWidth', 'borderHorizontalWidth', 'borderLeftWidth', 'borderRightWidth', 'borderSpacing', 'borderStartEndRadius', 'borderStartStartRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopWidth', 'bottom', 'columnGap', 'columnRuleWidth', 'columnWidth', 'containIntrinsicBlockSize', 'containIntrinsicHeight', 'containIntrinsicInlineSize', 'containIntrinsicWidth', 'flexBasis', 'fontSize', 'fontSmooth', 'height', 'inlineSize', 'insetBlockEnd', 'insetBlockStart', 'insetInlineEnd', 'insetInlineStart', 'left', 'letterSpacing', 'marginBlockEnd', 'marginBlockStart', 'marginBottom', 'marginInlineEnd', 'marginEnd', 'marginInlineStart', 'marginStart', 'marginLeft', 'marginRight', 'marginTop', 'maxBlockSize', 'maxHeight', 'maxInlineSize', 'maxWidth', 'minBlockSize', 'minHeight', 'minInlineSize', 'minWidth', 'offsetDistance', 'outlineOffset', 'outlineWidth', 'overflowClipMargin', 'paddingBlockEnd', 'paddingBlockStart', 'paddingBottom', 'paddingInlineEnd', 'paddingEnd', 'paddingInlineStart', 'paddingStart', 'paddingLeft', 'paddingRight', 'paddingTop', 'perspective', 'right', 'rowGap', 'scrollMarginBlockEnd', 'scrollMarginBlockStart', 'scrollMarginBottom', 'scrollMarginInlineEnd', 'scrollMarginInlineStart', 'scrollMarginLeft', 'scrollMarginRight', 'scrollMarginTop', 'scrollPaddingBlockEnd', 'scrollPaddingBlockStart', 'scrollPaddingBottom', 'scrollPaddingInlineEnd', 'scrollPaddingInlineStart', 'scrollPaddingLeft', 'scrollPaddingRight', 'scrollPaddingTop', 'scrollSnapMarginBottom', 'scrollSnapMarginLeft', 'scrollSnapMarginRight', 'scrollSnapMarginTop', 'shapeMargin', 'tabSize', 'textDecorationThickness', 'textIndent', 'textUnderlineOffset', 'top', 'transformOrigin', 'translate', 'verticalAlign', 'width', 'wordSpacing', 'border', 'borderBlock', 'borderBlockEnd', 'borderBlockStart', 'borderBottom', 'borderLeft', 'borderRadius', 'borderRight', 'borderTop', 'borderWidth', 'columnRule', 'containIntrinsicSize', 'gap', 'inset', 'insetBlock', 'insetInline', 'margin', 'marginBlock', 'marginVertical', 'marginInline', 'marginHorizontal', 'offset', 'outline', 'padding', 'paddingBlock', 'paddingVertical', 'paddingInline', 'paddingHorizontal', 'scrollMargin', 'scrollMarginBlock', 'scrollMarginInline', 'scrollPadding', 'scrollPaddingBlock', 'scrollPaddingInline', 'scrollSnapMargin']);
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.defaultOptions = void 0;
7
7
  const defaultOptions = exports.defaultOptions = {
8
8
  dev: false,
9
+ debug: false,
9
10
  useRemForFontSize: true,
10
11
  test: false,
11
12
  classNamePrefix: 'x',
@@ -0,0 +1,15 @@
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
+ export declare const sortPseudos: (
11
+ pseudos: ReadonlyArray<string>,
12
+ ) => ReadonlyArray<string>;
13
+ export declare const sortAtRules: (
14
+ atRules: ReadonlyArray<string>,
15
+ ) => ReadonlyArray<string>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sortPseudos = exports.sortAtRules = void 0;
7
+ var _objectUtils = require("./object-utils");
8
+ const sortPseudos = pseudos => {
9
+ if (pseudos.length < 2) {
10
+ return pseudos;
11
+ }
12
+ return pseudos.reduce((acc, pseudo) => {
13
+ if (pseudo.startsWith('::')) {
14
+ return [...acc, pseudo];
15
+ }
16
+ const lastElement = acc[acc.length - 1];
17
+ const allButLast = acc.slice(0, acc.length - 1);
18
+ if (Array.isArray(lastElement)) {
19
+ return [...allButLast, [...lastElement, pseudo]];
20
+ } else {
21
+ return [...allButLast, lastElement, [pseudo]].filter(Boolean);
22
+ }
23
+ }, []).flatMap(pseudo => {
24
+ if (Array.isArray(pseudo)) {
25
+ return (0, _objectUtils.arraySort)(pseudo, stringComparator);
26
+ }
27
+ return [pseudo];
28
+ });
29
+ };
30
+ exports.sortPseudos = sortPseudos;
31
+ const sortAtRules = atRules => (0, _objectUtils.arraySort)(atRules);
32
+ exports.sortAtRules = sortAtRules;
33
+ const stringComparator = (a, b) => {
34
+ if (a === 'default') {
35
+ return -1;
36
+ }
37
+ if (b === 'default') {
38
+ return 1;
39
+ }
40
+ return a.localeCompare(b);
41
+ };
@@ -0,0 +1,16 @@
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
+ declare export const sortPseudos: (
11
+ pseudos: $ReadOnlyArray<string>,
12
+ ) => $ReadOnlyArray<string>;
13
+
14
+ declare export const sortAtRules: (
15
+ atRules: $ReadOnlyArray<string>,
16
+ ) => $ReadOnlyArray<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/shared",
3
- "version": "0.8.0",
3
+ "version": "0.9.0-beta.1",
4
4
  "main": "lib/index.js",
5
5
  "repository": "https://www.github.com/facebook/stylex",
6
6
  "license": "MIT",
@@ -13,7 +13,7 @@
13
13
  "postcss-value-parser": "^4.1.0"
14
14
  },
15
15
  "devDependencies": {
16
- "@stylexjs/scripts": "0.8.0"
16
+ "@stylexjs/scripts": "0.9.0-beta.1"
17
17
  },
18
18
  "jest": {
19
19
  "snapshotFormat": {