@stylexjs/shared 0.2.0-beta.16 → 0.2.0-beta.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/lib/convert-to-className.d.ts +1 -1
  2. package/lib/convert-to-className.js +6 -22
  3. package/lib/convert-to-className.js.flow +1 -1
  4. package/lib/generate-css-rule.d.ts +1 -1
  5. package/lib/generate-css-rule.js +3 -14
  6. package/lib/generate-css-rule.js.flow +1 -1
  7. package/lib/hash.d.ts +2 -2
  8. package/lib/hash.js +9 -33
  9. package/lib/hash.js.flow +1 -3
  10. package/lib/index.d.ts +9 -9
  11. package/lib/index.js +0 -14
  12. package/lib/index.js.flow +9 -9
  13. package/lib/messages.d.ts +26 -26
  14. package/lib/messages.js +26 -36
  15. package/lib/messages.js.flow +26 -26
  16. package/lib/physical-rtl/generate-ltr.js +39 -67
  17. package/lib/physical-rtl/generate-ltr.js.flow +1 -1
  18. package/lib/physical-rtl/generate-rtl.d.ts +1 -2
  19. package/lib/physical-rtl/generate-rtl.js +57 -89
  20. package/lib/physical-rtl/generate-rtl.js.flow +1 -2
  21. package/lib/preprocess-rules/PreRule.d.ts +3 -3
  22. package/lib/preprocess-rules/PreRule.js +3 -17
  23. package/lib/preprocess-rules/PreRule.js.flow +3 -3
  24. package/lib/preprocess-rules/application-order.d.ts +8 -5
  25. package/lib/preprocess-rules/application-order.js +121 -160
  26. package/lib/preprocess-rules/application-order.js.flow +6 -5
  27. package/lib/preprocess-rules/basic-validation.d.ts +1 -1
  28. package/lib/preprocess-rules/basic-validation.js +6 -15
  29. package/lib/preprocess-rules/basic-validation.js.flow +1 -1
  30. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +2 -2
  31. package/lib/preprocess-rules/flatten-raw-style-obj.js +14 -43
  32. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +2 -2
  33. package/lib/preprocess-rules/index.d.ts +2 -2
  34. package/lib/preprocess-rules/index.js +6 -15
  35. package/lib/preprocess-rules/index.js.flow +2 -2
  36. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +3 -2
  37. package/lib/preprocess-rules/legacy-expand-shorthands.js +14 -33
  38. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +2 -2
  39. package/lib/preprocess-rules/property-specificity.d.ts +8 -5
  40. package/lib/preprocess-rules/property-specificity.js +54 -76
  41. package/lib/preprocess-rules/property-specificity.js.flow +6 -5
  42. package/lib/stylex-create-vars.d.ts +17 -8
  43. package/lib/stylex-create-vars.js +30 -17
  44. package/lib/stylex-create-vars.js.flow +10 -4
  45. package/lib/stylex-create.d.ts +2 -2
  46. package/lib/stylex-create.js +1 -20
  47. package/lib/stylex-create.js.flow +1 -1
  48. package/lib/stylex-first-that-works.js +0 -10
  49. package/lib/stylex-include.js +0 -10
  50. package/lib/stylex-keyframes.d.ts +1 -1
  51. package/lib/stylex-keyframes.js +7 -27
  52. package/lib/stylex-keyframes.js.flow +1 -1
  53. package/lib/stylex-override-vars.d.ts +11 -4
  54. package/lib/stylex-override-vars.js +32 -18
  55. package/lib/stylex-override-vars.js.flow +3 -3
  56. package/lib/transform-value.js +11 -29
  57. package/lib/transform-value.js.flow +1 -1
  58. package/lib/utils/Rule.d.ts +2 -2
  59. package/lib/utils/Rule.js +0 -21
  60. package/lib/utils/Rule.js.flow +2 -2
  61. package/lib/utils/dashify.js +1 -9
  62. package/lib/utils/default-options.d.ts +1 -1
  63. package/lib/utils/default-options.js +2 -23
  64. package/lib/utils/default-options.js.flow +1 -1
  65. package/lib/utils/file-based-identifier.js +1 -9
  66. package/lib/utils/genCSSRule.d.ts +1 -1
  67. package/lib/utils/genCSSRule.js +6 -16
  68. package/lib/utils/genCSSRule.js.flow +1 -1
  69. package/lib/utils/normalize-value.js +1 -13
  70. package/lib/utils/normalize-value.js.flow +1 -1
  71. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +1 -1
  72. package/lib/utils/normalizers/detect-unclosed-fns.js +2 -14
  73. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +1 -1
  74. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +1 -1
  75. package/lib/utils/normalizers/font-size-px-to-rem.js +4 -19
  76. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +1 -1
  77. package/lib/utils/normalizers/leading-zero.d.ts +1 -1
  78. package/lib/utils/normalizers/leading-zero.js +3 -15
  79. package/lib/utils/normalizers/leading-zero.js.flow +1 -1
  80. package/lib/utils/normalizers/quotes.d.ts +1 -1
  81. package/lib/utils/normalizers/quotes.js +4 -17
  82. package/lib/utils/normalizers/quotes.js.flow +1 -1
  83. package/lib/utils/normalizers/timings.d.ts +1 -1
  84. package/lib/utils/normalizers/timings.js +4 -18
  85. package/lib/utils/normalizers/timings.js.flow +1 -1
  86. package/lib/utils/normalizers/whitespace.d.ts +1 -1
  87. package/lib/utils/normalizers/whitespace.js +12 -27
  88. package/lib/utils/normalizers/whitespace.js.flow +1 -1
  89. package/lib/utils/normalizers/zero-dimensions.d.ts +1 -1
  90. package/lib/utils/normalizers/zero-dimensions.js +8 -23
  91. package/lib/utils/normalizers/zero-dimensions.js.flow +1 -1
  92. package/lib/utils/object-utils.d.ts +28 -20
  93. package/lib/utils/object-utils.js +2 -15
  94. package/lib/utils/object-utils.js.flow +23 -27
  95. package/lib/utils/property-priorities.js +68 -83
  96. package/lib/utils/split-css-value.d.ts +1 -1
  97. package/lib/utils/split-css-value.js +8 -22
  98. package/lib/utils/split-css-value.js.flow +1 -1
  99. package/lib/validate.js +2 -11
  100. package/package.json +2 -3
@@ -13,51 +13,47 @@ import type { CompiledStyles } from '../common-types';
13
13
 
14
14
  import { IncludedStyles } from '../stylex-include';
15
15
 
16
- declare export function isPlainObject(
17
- obj: mixed
18
- ): boolean %checks(typeof obj === 'object' &&
19
- obj != null &&
20
- !Array.isArray(obj) &&
21
- obj?.constructor === Object);
16
+ declare export function isPlainObject(obj: mixed): void;
22
17
 
23
18
  declare export function flattenObject(obj: CompiledStyles): {
24
19
  +[string]: null | string | IncludedStyles,
25
20
  };
26
21
 
27
- declare export function objEntries<Obj: { ... }>(
28
- obj: Obj
29
- ): $ReadOnlyArray<[$Keys<Obj>, Obj[$Keys<Obj>]]>;
22
+ type _ObjectEntries<Obj: { +[string]: mixed }> = {
23
+ [Key in keyof Obj]: [Key, Obj[Key]],
24
+ };
25
+ type ObjectEntries<Obj: { +[string]: mixed }> = $Values<_ObjectEntries<Obj>>;
26
+
27
+ declare export function objEntries<Obj: { +[string]: mixed }>(
28
+ obj: Obj,
29
+ ): $ReadOnlyArray<ObjectEntries<Obj>>;
30
30
 
31
- declare export function objValues<Obj: { ... }>(
32
- obj: Obj
31
+ declare export function objValues<Obj: { +[string]: mixed }>(
32
+ obj: Obj,
33
33
  ): $ReadOnlyArray<Obj[$Keys<Obj>]>;
34
34
 
35
35
  declare export function objFromEntries<K: string | number, V>(
36
- entries: $ReadOnlyArray<$ReadOnly<[K, V]>>
36
+ entries: $ReadOnlyArray<$ReadOnly<[K, V]>>,
37
37
  ): { [K]: V };
38
38
 
39
- declare export function objMapKeys<
40
- V,
41
- K1: string | number = string,
42
- K2: string | number = string
43
- >(
39
+ declare export function objMapKeys<V, K1: string = string, K2: string = string>(
44
40
  obj: { +[K1]: V },
45
- mapper: (K1) => K2
41
+ mapper: (K1) => K2,
46
42
  ): { +[K2]: V };
47
43
 
48
44
  declare export function objMapEntry<
49
45
  V,
50
46
  V2,
51
- K1: string | number = string,
52
- K2: string | number = string
47
+ K1: string = string,
48
+ K2: string = string,
53
49
  >(
54
50
  obj: { +[K1]: V },
55
- mapper: ([K1, V]) => [K2, V2]
51
+ mapper: ([K1, V]) => [K2, V2],
56
52
  ): { +[K2]: V2 };
57
53
 
58
- declare export function objMap<V, V2, K: string | number = string>(
54
+ declare export function objMap<V, V2, K: string = string>(
59
55
  obj: { +[K]: V },
60
- mapper: (V, K) => V2
56
+ mapper: (V, K) => V2,
61
57
  ): { +[K]: V2 };
62
58
 
63
59
  declare export class Pipe<T> {
@@ -69,13 +65,13 @@ declare export class Pipe<T> {
69
65
  }
70
66
 
71
67
  // Function that sorts an array without mutating it and returns a new array
72
- declare export var arraySort: <T>(
68
+ declare export const arraySort: <T>(
73
69
  arr: $ReadOnlyArray<T>,
74
- fn?: (T, T) => number
70
+ fn?: (T, T) => number,
75
71
  ) => $ReadOnlyArray<T>;
76
72
 
77
- declare export var arrayEquals: <T>(
73
+ declare export const arrayEquals: <T>(
78
74
  arr1: $ReadOnlyArray<T>,
79
75
  arr2: $ReadOnlyArray<T>,
80
- equals: (T, T) => boolean
76
+ equals: (T, T) => boolean,
81
77
  ) => boolean;
@@ -4,112 +4,97 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = getPriority;
7
- /**
8
- * Copyright (c) Meta Platforms, Inc. and affiliates.
9
- *
10
- * This source code is licensed under the MIT license found in the
11
- * LICENSE file in the root directory of this source tree.
12
- *
13
- *
14
- */
15
-
16
7
  const PRIORITIES = {
17
- // These should never exist at runtime:
18
8
  border: 1,
19
- 'border-block-end': 2,
20
- 'border-block-start': 2,
21
- 'border-top': 2.1,
22
- 'border-bottom': 2.1,
23
- 'border-inline-end': 2,
24
- 'border-inline-start': 2,
25
- 'border-left': 2,
26
- 'border-right': 2,
27
- // End of never-exist-at-runtime properties.
28
-
29
- // These are shorthands of shorthands:
9
+ "border-block-end": 2,
10
+ "border-block-start": 2,
11
+ "border-top": 2.1,
12
+ "border-bottom": 2.1,
13
+ "border-inline-end": 2,
14
+ "border-inline-start": 2,
15
+ "border-left": 2,
16
+ "border-right": 2,
30
17
  grid: 2,
31
- 'grid-area': 2,
32
- // These are shorthands of final properties:
33
- 'border-color': 3,
34
- 'border-style': 3,
35
- 'border-width': 3,
36
- 'border-image': 3,
37
- 'border-radius': 3,
18
+ "grid-area": 2,
19
+ "border-color": 3,
20
+ "border-style": 3,
21
+ "border-width": 3,
22
+ "border-image": 3,
23
+ "border-radius": 3,
38
24
  animation: 3,
39
25
  background: 3,
40
- 'column-rule': 3,
26
+ "column-rule": 3,
41
27
  columns: 3,
42
28
  flex: 3,
43
- 'flex-flow': 3,
29
+ "flex-flow": 3,
44
30
  font: 3,
45
31
  gap: 3,
46
- 'grid-column': 3,
47
- 'grid-row': 3,
48
- 'grid-template': 3,
49
- 'list-style': 3,
32
+ "grid-column": 3,
33
+ "grid-row": 3,
34
+ "grid-template": 3,
35
+ "list-style": 3,
50
36
  margin: 3,
51
37
  mask: 3,
52
38
  offset: 3,
53
39
  outline: 3,
54
40
  overflow: 3,
55
41
  padding: 3,
56
- 'place-content': 3,
57
- 'place-items': 3,
58
- 'place-self': 3,
59
- 'scroll-margin': 3,
60
- 'scroll-padding': 3,
61
- 'text-decoration': 3,
62
- 'text-emphasis': 3,
42
+ "place-content": 3,
43
+ "place-items": 3,
44
+ "place-self": 3,
45
+ "scroll-margin": 3,
46
+ "scroll-padding": 3,
47
+ "text-decoration": 3,
48
+ "text-emphasis": 3,
63
49
  transition: 3,
64
- ':has': 4.5,
65
- ':dir': 5,
66
- ':lang': 5.1,
67
- ':first-child': 5.2,
68
- ':last-child': 5.3,
69
- ':only-child': 5.4,
70
- ':nth-child': 6,
71
- ':nth-of-type': 6.1,
72
- ':only-of-type': 6.2,
73
- ':empty': 7,
74
- ':link': 8,
75
- ':any-link': 8.1,
76
- ':target': 8.2,
77
- ':visited': 8.3,
78
- ':enabled': 9.1,
79
- ':disabled': 9.2,
80
- ':required': 9.3,
81
- ':optional': 9.4,
82
- ':read-only': 9.5,
83
- ':read-write': 9.6,
84
- ':placeholder-shown': 9.7,
85
- ':default': 10,
86
- ':checked': 10.1,
87
- ':indeterminate': 10.1,
88
- ':blank': 10.2,
89
- ':valid': 10.3,
90
- ':invalid': 10.4,
91
- ':autofill': 11,
92
- ':picture-in-picture': 12,
93
- ':fullscreen': 12.1,
94
- ':paused': 12.2,
95
- ':playing': 12.3,
96
- ':hover': 13,
97
- ':focusWithin': 14,
98
- ':focusVisible': 15,
99
- ':focus': 16,
100
- ':active': 17
50
+ ":has": 4.5,
51
+ ":dir": 5,
52
+ ":lang": 5.1,
53
+ ":first-child": 5.2,
54
+ ":last-child": 5.3,
55
+ ":only-child": 5.4,
56
+ ":nth-child": 6,
57
+ ":nth-of-type": 6.1,
58
+ ":only-of-type": 6.2,
59
+ ":empty": 7,
60
+ ":link": 8,
61
+ ":any-link": 8.1,
62
+ ":target": 8.2,
63
+ ":visited": 8.3,
64
+ ":enabled": 9.1,
65
+ ":disabled": 9.2,
66
+ ":required": 9.3,
67
+ ":optional": 9.4,
68
+ ":read-only": 9.5,
69
+ ":read-write": 9.6,
70
+ ":placeholder-shown": 9.7,
71
+ ":default": 10,
72
+ ":checked": 10.1,
73
+ ":indeterminate": 10.1,
74
+ ":blank": 10.2,
75
+ ":valid": 10.3,
76
+ ":invalid": 10.4,
77
+ ":autofill": 11,
78
+ ":picture-in-picture": 12,
79
+ ":fullscreen": 12.1,
80
+ ":paused": 12.2,
81
+ ":playing": 12.3,
82
+ ":hover": 13,
83
+ ":focusWithin": 14,
84
+ ":focusVisible": 15,
85
+ ":focus": 16,
86
+ ":active": 17
101
87
  };
102
88
  function getPriority(key) {
103
- if (key.startsWith('@supports')) {
89
+ if (key.startsWith("@supports")) {
104
90
  return 20;
105
91
  }
106
- if (key.startsWith('@media')) {
92
+ if (key.startsWith("@media")) {
107
93
  return 21;
108
94
  }
109
- const prop = key.startsWith(':') && key.includes('(') ? key.slice(0, key.indexOf('(')) : key;
95
+ const prop = key.startsWith(":") && key.includes("(") ? key.slice(0, key.indexOf("(")) : key;
110
96
  let priority = PRIORITIES[prop] ?? 4;
111
- if (key.toLowerCase().includes('left') || key.toLowerCase().includes('right')) {
112
- // Bump priority for physical left/right values.
97
+ if (key.toLowerCase().includes("left") || key.toLowerCase().includes("right")) {
113
98
  priority += 0.1;
114
99
  }
115
100
  return priority;
@@ -10,6 +10,6 @@
10
10
 
11
11
  import type { TStyleValue } from '../common-types';
12
12
  declare function splitValue(
13
- str: TStyleValue
13
+ str: TStyleValue,
14
14
  ): ReadonlyArray<number | string | null>;
15
15
  export default splitValue;
@@ -6,42 +6,28 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = splitValue;
7
7
  var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- /**
10
- * Copyright (c) Meta Platforms, Inc. and affiliates.
11
- *
12
- * This source code is licensed under the MIT license found in the
13
- * LICENSE file in the root directory of this source tree.
14
- *
15
- *
16
- *
17
- */
18
-
19
9
  function printNode(node) {
20
10
  switch (node.type) {
21
- case 'word':
22
- case 'string':
11
+ case "word":
12
+ case "string":
23
13
  return `${node.value}`;
24
- case 'function':
25
- return `${node.value}(${node.nodes.map(printNode).join('')})`;
14
+ case "function":
15
+ return `${node.value}(${node.nodes.map(printNode).join("")})`;
26
16
  default:
27
17
  return node.value;
28
18
  }
29
19
  }
30
-
31
- // Using split(' ') Isn't enough bcause of values like calc.
32
20
  function splitValue(str) {
33
- if (str == null || typeof str === 'number') {
21
+ if (str == null || typeof str === "number") {
34
22
  return [str];
35
23
  }
36
-
37
- // This will never happen, but keeping here for Flow.
38
24
  if (Array.isArray(str)) {
39
25
  return str;
40
26
  }
41
27
  const parsed = (0, _postcssValueParser.default)(str.trim());
42
- const nodes = parsed.nodes.filter(node => node.type !== 'space' && node.type !== 'div').map(printNode);
43
- if (nodes.length > 1 && nodes[nodes.length - 1].toLowerCase() === '!important') {
44
- return nodes.slice(0, nodes.length - 1).map(node => node + ' !important');
28
+ const nodes = parsed.nodes.filter(node => node.type !== "space" && node.type !== "div").map(printNode);
29
+ if (nodes.length > 1 && nodes[nodes.length - 1].toLowerCase() === "!important") {
30
+ return nodes.slice(0, nodes.length - 1).map(node => node + " !important");
45
31
  }
46
32
  return nodes;
47
33
  }
@@ -12,5 +12,5 @@ import type { TStyleValue } from '../common-types';
12
12
 
13
13
  // Using split(' ') Isn't enough bcause of values like calc.
14
14
  declare export default function splitValue(
15
- str: TStyleValue
15
+ str: TStyleValue,
16
16
  ): $ReadOnlyArray<number | string | null>;
package/lib/validate.js CHANGED
@@ -4,15 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = validateEntry;
7
- /**
8
- * Copyright (c) Meta Platforms, Inc. and affiliates.
9
- *
10
- * This source code is licensed under the MIT license found in the
11
- * LICENSE file in the root directory of this source tree.
12
- *
13
- *
14
- */
15
-
16
7
  function validateEntry(_ref) {
17
8
  let [key, value] = _ref;
18
9
  if (Array.isArray(value)) {
@@ -24,7 +15,7 @@ function validateEntry(_ref) {
24
15
  function validateSimplyEntry(_ref2) {
25
16
  let [key, _value] = _ref2;
26
17
  if (BANNED_KEYS.has(key)) {
27
- throw new Error('Banned key: ' + key);
18
+ throw new Error("Banned key: " + key);
28
19
  }
29
20
  }
30
- const BANNED_KEYS = new Set(['background', 'transition', 'grid']);
21
+ const BANNED_KEYS = new Set(["background", "transition", "grid"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/shared",
3
- "version": "0.2.0-beta.16",
3
+ "version": "0.2.0-beta.18",
4
4
  "main": "lib/index.js",
5
5
  "repository": "https://www.github.com/facebook/stylex",
6
6
  "license": "MIT",
@@ -13,8 +13,7 @@
13
13
  "postcss-value-parser": "^4.1.0"
14
14
  },
15
15
  "devDependencies": {
16
- "@stylexjs/scripts": "0.2.0-beta.16",
17
- "typescript": "^4.7.4"
16
+ "@stylexjs/scripts": "0.2.0-beta.18"
18
17
  },
19
18
  "jest": {
20
19
  "snapshotFormat": {