@stylexjs/shared 0.1.0-beta.6 → 0.2.0-beta.10

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.
Files changed (34) hide show
  1. package/README.md +81 -0
  2. package/lib/convert-to-className.js +13 -6
  3. package/lib/expand-shorthands.d.ts +5 -0
  4. package/lib/expand-shorthands.js +241 -101
  5. package/lib/generate-css-rule.js +10 -38
  6. package/lib/index.d.ts +14 -2
  7. package/lib/index.js.flow +5 -0
  8. package/lib/messages.js +11 -3
  9. package/lib/namespace-transforms/__tests__/preflatten.test.js +120 -0
  10. package/lib/namespace-transforms/preflatten.js +89 -0
  11. package/lib/physical-rtl/generate-ltr.js +32 -32
  12. package/lib/physical-rtl/generate-rtl.js +30 -30
  13. package/lib/preprocess-rules/PreRule.js +101 -0
  14. package/lib/preprocess-rules/application-order.js +259 -0
  15. package/lib/preprocess-rules/basic-validation.js +92 -0
  16. package/lib/preprocess-rules/expand-shorthands.js +156 -0
  17. package/lib/preprocess-rules/flatten-raw-style-obj.js +148 -0
  18. package/lib/preprocess-rules/index.js +39 -0
  19. package/lib/preprocess-rules/legacy-expand-shorthands.js +219 -0
  20. package/lib/preprocess-rules/null-out-longhand.js +310 -0
  21. package/lib/preprocess-rules/property-specificity.js +135 -0
  22. package/lib/preprocess-rules/react-native-web.js +142 -0
  23. package/lib/stylex-create.js +32 -91
  24. package/lib/stylex-defaultValue.js +397 -0
  25. package/lib/stylex-keyframes.js +23 -10
  26. package/lib/utils/Rule.js +71 -0
  27. package/lib/utils/default-options.js +34 -0
  28. package/lib/utils/genCSSRule.js +9 -8
  29. package/lib/utils/normalize-value.js +3 -0
  30. package/lib/utils/object-utils.js +24 -3
  31. package/lib/utils/property-priorities.js +116 -0
  32. package/lib/utils/split-css-value.js +47 -0
  33. package/lib/validate.js +1 -1
  34. package/package.json +1 -1
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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
+ const PRIORITIES = {
17
+ // These should never exist at runtime:
18
+ 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:
30
+ 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,
38
+ animation: 3,
39
+ background: 3,
40
+ 'column-rule': 3,
41
+ columns: 3,
42
+ flex: 3,
43
+ 'flex-flow': 3,
44
+ font: 3,
45
+ gap: 3,
46
+ 'grid-column': 3,
47
+ 'grid-row': 3,
48
+ 'grid-template': 3,
49
+ 'list-style': 3,
50
+ margin: 3,
51
+ mask: 3,
52
+ offset: 3,
53
+ outline: 3,
54
+ overflow: 3,
55
+ 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,
63
+ 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
101
+ };
102
+ function getPriority(key) {
103
+ if (key.startsWith('@supports')) {
104
+ return 20;
105
+ }
106
+ if (key.startsWith('@media')) {
107
+ return 21;
108
+ }
109
+ const prop = key.startsWith(':') && key.includes('(') ? key.slice(0, key.indexOf('(')) : key;
110
+ let priority = PRIORITIES[prop] ?? 4;
111
+ if (key.toLowerCase().includes('left') || key.toLowerCase().includes('right')) {
112
+ // Bump priority for physical left/right values.
113
+ priority += 0.1;
114
+ }
115
+ return priority;
116
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = splitValue;
7
+ var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
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
+ function printNode(node) {
20
+ switch (node.type) {
21
+ case 'word':
22
+ case 'string':
23
+ return `${node.value}`;
24
+ case 'function':
25
+ return `${node.value}(${node.nodes.map(printNode).join('')})`;
26
+ default:
27
+ return node.value;
28
+ }
29
+ }
30
+
31
+ // Using split(' ') Isn't enough bcause of values like calc.
32
+ function splitValue(str) {
33
+ if (str == null || typeof str === 'number') {
34
+ return [str];
35
+ }
36
+
37
+ // This will never happen, but keeping here for Flow.
38
+ if (Array.isArray(str)) {
39
+ return str;
40
+ }
41
+ 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');
45
+ }
46
+ return nodes;
47
+ }
package/lib/validate.js CHANGED
@@ -22,7 +22,7 @@ function validateEntry(_ref) {
22
22
  }
23
23
  }
24
24
  function validateSimplyEntry(_ref2) {
25
- let [key, value] = _ref2;
25
+ let [key, _value] = _ref2;
26
26
  if (BANNED_KEYS.has(key)) {
27
27
  throw new Error('Banned key: ' + key);
28
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/shared",
3
- "version": "0.1.0-beta.6",
3
+ "version": "0.2.0-beta.10",
4
4
  "description": "Shared Code for Stylex compile and runtime.",
5
5
  "main": "lib/index.js",
6
6
  "repository": "https://www.github.com/facebookexternal/stylex",