@stylexjs/shared 0.2.0-beta.9 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. package/README.md +3 -3
  2. package/lib/common-types.d.ts +49 -0
  3. package/lib/common-types.js.flow +64 -0
  4. package/lib/convert-to-className.d.ts +16 -0
  5. package/lib/convert-to-className.js +17 -26
  6. package/lib/convert-to-className.js.flow +23 -0
  7. package/lib/generate-css-rule.d.ts +17 -0
  8. package/lib/generate-css-rule.js +6 -17
  9. package/lib/generate-css-rule.js.flow +17 -0
  10. package/lib/hash.d.ts +11 -0
  11. package/lib/hash.js +3 -27
  12. package/lib/hash.js.flow +10 -0
  13. package/lib/index.d.ts +42 -85
  14. package/lib/index.js +21 -29
  15. package/lib/index.js.flow +57 -3
  16. package/lib/messages.d.ts +41 -0
  17. package/lib/messages.js +33 -53
  18. package/lib/messages.js.flow +44 -0
  19. package/lib/physical-rtl/generate-ltr.d.ts +11 -0
  20. package/lib/physical-rtl/generate-ltr.js +18 -46
  21. package/lib/physical-rtl/generate-ltr.js.flow +12 -0
  22. package/lib/physical-rtl/generate-rtl.d.ts +13 -0
  23. package/lib/physical-rtl/generate-rtl.js +18 -50
  24. package/lib/physical-rtl/generate-rtl.js.flow +12 -0
  25. package/lib/preprocess-rules/PreRule.d.ts +52 -0
  26. package/lib/preprocess-rules/PreRule.js +87 -0
  27. package/lib/preprocess-rules/PreRule.js.flow +64 -0
  28. package/lib/preprocess-rules/application-order.d.ts +290 -0
  29. package/lib/preprocess-rules/application-order.js +60 -133
  30. package/lib/preprocess-rules/application-order.js.flow +241 -0
  31. package/lib/preprocess-rules/basic-validation.d.ts +13 -0
  32. package/lib/preprocess-rules/basic-validation.js +83 -0
  33. package/lib/preprocess-rules/basic-validation.js.flow +13 -0
  34. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +25 -0
  35. package/lib/preprocess-rules/flatten-raw-style-obj.js +120 -0
  36. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +27 -0
  37. package/lib/preprocess-rules/index.d.ts +18 -0
  38. package/lib/preprocess-rules/index.js +0 -9
  39. package/lib/preprocess-rules/index.js.flow +19 -0
  40. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +200 -0
  41. package/lib/preprocess-rules/legacy-expand-shorthands.js +90 -123
  42. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +179 -0
  43. package/lib/preprocess-rules/property-specificity.d.ts +89 -0
  44. package/lib/preprocess-rules/property-specificity.js +46 -74
  45. package/lib/preprocess-rules/property-specificity.js.flow +98 -0
  46. package/lib/properties/CSS Animations.json +445 -0
  47. package/lib/properties/CSS Backgrounds and Borders.json +1085 -0
  48. package/lib/properties/CSS Basic User Interface.json +365 -0
  49. package/lib/properties/CSS Box Alignment.json +245 -0
  50. package/lib/properties/CSS Box Model.json +501 -0
  51. package/lib/properties/CSS Color.json +100 -0
  52. package/lib/properties/CSS Columns.json +185 -0
  53. package/lib/properties/CSS Containment.json +203 -0
  54. package/lib/properties/CSS Counter Styles.json +56 -0
  55. package/lib/properties/CSS Display.json +20 -0
  56. package/lib/properties/CSS Flexible Box Layout.json +167 -0
  57. package/lib/properties/CSS Fonts.json +684 -0
  58. package/lib/properties/CSS Fragmentation.json +110 -0
  59. package/lib/properties/CSS Generated Content.json +38 -0
  60. package/lib/properties/CSS Grid Layout.json +500 -0
  61. package/lib/properties/CSS Images.json +91 -0
  62. package/lib/properties/CSS Inline.json +38 -0
  63. package/lib/properties/CSS Lists and Counters.json +86 -0
  64. package/lib/properties/CSS Logical Properties.json +1086 -0
  65. package/lib/properties/CSS Masking.json +399 -0
  66. package/lib/properties/CSS Miscellaneous.json +38 -0
  67. package/lib/properties/CSS Motion Path.json +132 -0
  68. package/lib/properties/CSS Overflow.json +216 -0
  69. package/lib/properties/CSS Pages.json +83 -0
  70. package/lib/properties/CSS Positioning.json +166 -0
  71. package/lib/properties/CSS Ruby.json +55 -0
  72. package/lib/properties/CSS Scroll Anchoring.json +19 -0
  73. package/lib/properties/CSS Scroll Snap.json +604 -0
  74. package/lib/properties/CSS Scrollbars.json +38 -0
  75. package/lib/properties/CSS Shapes.json +56 -0
  76. package/lib/properties/CSS Speech.json +20 -0
  77. package/lib/properties/CSS Table.json +115 -0
  78. package/lib/properties/CSS Text Decoration.json +312 -0
  79. package/lib/properties/CSS Text.json +415 -0
  80. package/lib/properties/CSS Transforms.json +188 -0
  81. package/lib/properties/CSS Transitions.json +122 -0
  82. package/lib/properties/CSS Variables.json +20 -0
  83. package/lib/properties/CSS View Transitions.json +20 -0
  84. package/lib/properties/CSS Will Change.json +20 -0
  85. package/lib/properties/CSS Writing Modes.json +92 -0
  86. package/lib/properties/Compositing and Blending.json +62 -0
  87. package/lib/properties/Filter Effects.json +38 -0
  88. package/lib/properties/MathML.json +56 -0
  89. package/lib/properties/Microsoft Extensions.json +885 -0
  90. package/lib/properties/Mozilla Extensions.json +607 -0
  91. package/lib/properties/Pointer Events.json +20 -0
  92. package/lib/properties/WebKit Extensions.json +707 -0
  93. package/lib/properties.json +10122 -0
  94. package/lib/stylex-create-theme.d.ts +26 -0
  95. package/lib/stylex-create-theme.js +67 -0
  96. package/lib/stylex-create-theme.js.flow +19 -0
  97. package/lib/stylex-create.d.ts +23 -0
  98. package/lib/stylex-create.js +30 -146
  99. package/lib/stylex-create.js.flow +30 -0
  100. package/lib/stylex-define-vars.d.ts +29 -0
  101. package/lib/stylex-define-vars.js +73 -0
  102. package/lib/stylex-define-vars.js.flow +26 -0
  103. package/lib/stylex-first-that-works.d.ts +13 -0
  104. package/lib/stylex-first-that-works.js +0 -10
  105. package/lib/stylex-first-that-works.js.flow +12 -0
  106. package/lib/stylex-include.d.ts +18 -0
  107. package/lib/stylex-include.js +2 -12
  108. package/lib/stylex-include.js.flow +20 -0
  109. package/lib/stylex-keyframes.d.ts +17 -0
  110. package/lib/stylex-keyframes.js +6 -26
  111. package/lib/stylex-keyframes.js.flow +20 -0
  112. package/lib/transform-value.d.ts +22 -0
  113. package/lib/transform-value.js +9 -23
  114. package/lib/transform-value.js.flow +25 -0
  115. package/lib/types/index.d.ts +205 -0
  116. package/lib/types/index.js +191 -0
  117. package/lib/types/index.js.flow +241 -0
  118. package/lib/utils/Rule.d.ts +58 -0
  119. package/lib/utils/Rule.js +0 -21
  120. package/lib/utils/Rule.js.flow +64 -0
  121. package/lib/utils/dashify.d.ts +11 -0
  122. package/lib/utils/dashify.js +0 -8
  123. package/lib/utils/dashify.js.flow +10 -0
  124. package/lib/utils/default-options.d.ts +11 -0
  125. package/lib/utils/default-options.js +13 -0
  126. package/lib/utils/default-options.js.flow +25 -0
  127. package/lib/utils/file-based-identifier.d.ts +15 -0
  128. package/lib/utils/file-based-identifier.js +14 -0
  129. package/lib/utils/file-based-identifier.js.flow +14 -0
  130. package/lib/utils/genCSSRule.d.ts +15 -0
  131. package/lib/utils/genCSSRule.js +9 -18
  132. package/lib/utils/genCSSRule.js.flow +15 -0
  133. package/lib/utils/normalize-value.d.ts +16 -0
  134. package/lib/utils/normalize-value.js +8 -15
  135. package/lib/utils/normalize-value.js.flow +16 -0
  136. package/lib/utils/normalizers/convert-camel-case-transition-props.d.ts +14 -0
  137. package/lib/utils/normalizers/convert-camel-case-transition-props.js +23 -0
  138. package/lib/utils/normalizers/convert-camel-case-transition-props.js.flow +13 -0
  139. package/lib/utils/normalizers/convert-camel-case-values.d.ts +14 -0
  140. package/lib/utils/normalizers/convert-camel-case-values.js +23 -0
  141. package/lib/utils/normalizers/convert-camel-case-values.js.flow +13 -0
  142. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
  143. package/lib/utils/normalizers/detect-unclosed-fns.js +2 -14
  144. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
  145. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
  146. package/lib/utils/normalizers/font-size-px-to-rem.js +9 -19
  147. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
  148. package/lib/utils/normalizers/leading-zero.d.ts +17 -0
  149. package/lib/utils/normalizers/leading-zero.js +0 -12
  150. package/lib/utils/normalizers/leading-zero.js.flow +16 -0
  151. package/lib/utils/normalizers/quotes.d.ts +18 -0
  152. package/lib/utils/normalizers/quotes.js +0 -13
  153. package/lib/utils/normalizers/quotes.js.flow +17 -0
  154. package/lib/utils/normalizers/timings.d.ts +18 -0
  155. package/lib/utils/normalizers/timings.js +0 -14
  156. package/lib/utils/normalizers/timings.js.flow +17 -0
  157. package/lib/utils/normalizers/whitespace.d.ts +19 -0
  158. package/lib/utils/normalizers/whitespace.js +0 -15
  159. package/lib/utils/normalizers/whitespace.js.flow +18 -0
  160. package/lib/utils/normalizers/zero-dimensions.d.ts +19 -0
  161. package/lib/utils/normalizers/zero-dimensions.js +0 -15
  162. package/lib/utils/normalizers/zero-dimensions.js.flow +18 -0
  163. package/lib/utils/object-utils.d.ts +66 -0
  164. package/lib/utils/object-utils.js +21 -13
  165. package/lib/utils/object-utils.js.flow +77 -0
  166. package/lib/utils/property-priorities.d.ts +11 -0
  167. package/lib/utils/property-priorities.js +516 -101
  168. package/lib/utils/property-priorities.js.flow +10 -0
  169. package/lib/utils/split-css-value.d.ts +14 -0
  170. package/lib/utils/split-css-value.js +0 -14
  171. package/lib/utils/split-css-value.js.flow +15 -0
  172. package/lib/validate.d.ts +12 -0
  173. package/lib/validate.js +1 -10
  174. package/lib/validate.js.flow +12 -0
  175. package/package.json +4 -5
  176. package/lib/expand-shorthands.d.ts +0 -5
  177. package/lib/expand-shorthands.js +0 -330
  178. package/lib/namespace-transforms/__tests__/preflatten.test.js +0 -120
  179. package/lib/namespace-transforms/preflatten.js +0 -89
  180. package/lib/preprocess-rules/expand-shorthands.js +0 -156
  181. package/lib/preprocess-rules/null-out-longhand.js +0 -310
  182. package/lib/preprocess-rules/react-native-web.js +0 -142
  183. package/lib/stylex-defaultValue.js +0 -397
@@ -0,0 +1,26 @@
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
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
+ declare function styleXCreateTheme(
12
+ themeVars: {
13
+ readonly __themeName__: string;
14
+ readonly [$$Key$$: string]: string;
15
+ },
16
+ variables: {
17
+ readonly [$$Key$$: string]:
18
+ | string
19
+ | { default: string; readonly [$$Key$$: string]: string };
20
+ },
21
+ options?: StyleXOptions,
22
+ ): [
23
+ { $$css: true; readonly [$$Key$$: string]: string },
24
+ { [$$Key$$: string]: InjectableStyle },
25
+ ];
26
+ export default styleXCreateTheme;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = styleXCreateTheme;
7
+ var _hash = _interopRequireDefault(require("./hash"));
8
+ var _defaultOptions = require("./utils/default-options");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function styleXCreateTheme(themeVars, variables, options) {
11
+ if (typeof themeVars.__themeName__ !== 'string') {
12
+ throw new Error('Can only override variables theme created with stylex.defineVars().');
13
+ }
14
+ const {
15
+ classNamePrefix
16
+ } = {
17
+ ..._defaultOptions.defaultOptions,
18
+ ...options
19
+ };
20
+ const sortedKeys = Object.keys(variables).sort();
21
+ const atRules = {};
22
+ const cssVariablesOverrideString = sortedKeys.map(key => {
23
+ const varNameHash = themeVars[key].slice(4, -1);
24
+ const value = variables[key];
25
+ if (varNameHash != null && value !== null && typeof value === 'object') {
26
+ if (value.default === undefined) {
27
+ throw new Error('Default value is not defined for ' + key + ' variable.');
28
+ }
29
+ const definedVarString = `${varNameHash}:${value.default};`;
30
+ Object.keys(value).forEach(key => {
31
+ if (key.startsWith('@')) {
32
+ const definedVarStringForAtRule = `${varNameHash}:${value[key]};`;
33
+ if (atRules[key] == null) {
34
+ atRules[key] = [definedVarStringForAtRule];
35
+ } else {
36
+ atRules[key].push(definedVarStringForAtRule);
37
+ }
38
+ }
39
+ });
40
+ return definedVarString;
41
+ }
42
+ return varNameHash != null && typeof value !== 'object' ? `${varNameHash}:${value};` : '';
43
+ }).join('');
44
+ const sortedAtRules = Object.keys(atRules).sort();
45
+ const atRulesStringForHash = sortedAtRules.map(atRule => {
46
+ return `${atRule}{${atRules[atRule].sort().join('')}}`;
47
+ }).join('');
48
+ const overrideClassName = classNamePrefix + (0, _hash.default)(cssVariablesOverrideString + atRulesStringForHash);
49
+ const stylesToInject = {
50
+ [overrideClassName]: {
51
+ ltr: `.${overrideClassName}{${cssVariablesOverrideString}}`,
52
+ priority: 0.8,
53
+ rtl: undefined
54
+ }
55
+ };
56
+ for (const atRule of sortedAtRules) {
57
+ stylesToInject[overrideClassName + '-' + (0, _hash.default)(atRule)] = {
58
+ ltr: `${atRule}{.${overrideClassName}{${atRules[atRule].join('')}}}`,
59
+ priority: 0.9,
60
+ rtl: null
61
+ };
62
+ }
63
+ return [{
64
+ $$css: true,
65
+ [themeVars.__themeName__]: overrideClassName
66
+ }, stylesToInject];
67
+ }
@@ -0,0 +1,19 @@
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
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
+
12
+ // It takes an object of variables with their values and the original set of variables to override
13
+ // and returns a hashed className with variables overrides.
14
+ //
15
+ declare export default function styleXCreateTheme(
16
+ themeVars: { +__themeName__: string, +[string]: string },
17
+ variables: { +[string]: string | { default: string, +[string]: string } },
18
+ options?: StyleXOptions,
19
+ ): [{ $$css: true, +[string]: string }, { [string]: InjectableStyle }];
@@ -0,0 +1,23 @@
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
+ import type {
11
+ RawStyles,
12
+ InjectableStyle,
13
+ StyleXOptions,
14
+ FlatCompiledStyles,
15
+ } from './common-types';
16
+ declare function styleXCreateSet(
17
+ namespaces: { readonly [$$Key$$: string]: RawStyles },
18
+ options?: StyleXOptions,
19
+ ): [
20
+ { [$$Key$$: string]: FlatCompiledStyles },
21
+ { [$$Key$$: string]: InjectableStyle },
22
+ ];
23
+ export default styleXCreateSet;
@@ -4,163 +4,47 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = styleXCreateSet;
7
- var _convertToClassName = _interopRequireDefault(require("./convert-to-className"));
8
- var _index = _interopRequireWildcard(require("./preprocess-rules/index"));
9
7
  var _objectUtils = require("./utils/object-utils");
10
- var messages = _interopRequireWildcard(require("./messages"));
11
8
  var _stylexInclude = require("./stylex-include");
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- /**
16
- * Copyright (c) Meta Platforms, Inc. and affiliates.
17
- *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- *
21
- *
22
- */
23
-
24
- // This takes the object of styles passed to `stylex.create` and transforms it.
25
- // The transformation replaces style values with classNames.
26
- //
27
- // It also collects all injected styles along the way.
28
- // It then returns a tuple of the transformed style Object and an object of injected styles.
29
- //
30
- // This function does some basic validation, and then uses `styleXCreateNamespace` to transform
31
- // each namespace within,
32
- //
33
- // Before returning, it ensures that there are no duplicate styles being injected.
9
+ var _defaultOptions = require("./utils/default-options");
10
+ var _flattenRawStyleObj = require("./preprocess-rules/flatten-raw-style-obj");
11
+ var _basicValidation = require("./preprocess-rules/basic-validation");
34
12
  function styleXCreateSet(namespaces) {
35
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
13
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaultOptions.defaultOptions;
36
14
  const resolvedNamespaces = {};
37
15
  const injectedStyles = {};
38
16
  for (const namespaceName of Object.keys(namespaces)) {
39
17
  const namespace = namespaces[namespaceName];
40
- if (typeof namespace !== 'object' || Array.isArray(namespace)) {
41
- throw new Error(messages.ILLEGAL_NAMESPACE_VALUE);
42
- }
43
-
44
- // namespace = preflatten(namespace);
45
-
46
- const [resolvedNamespace, injected] = styleXCreateNamespace(namespace, options);
47
- const compiledNamespace = (0, _objectUtils.flattenObject)(resolvedNamespace);
48
- resolvedNamespaces[namespaceName] = {
49
- ...compiledNamespace,
50
- $$css: true
51
- };
52
- for (const cn of Object.keys(injected)) {
53
- if (injectedStyles[cn] == null) {
54
- injectedStyles[cn] = injected[cn];
55
- }
56
- }
57
- }
58
- return [resolvedNamespaces, injectedStyles];
59
- }
60
-
61
- // Transforms a single style namespace.
62
- // e.g. Something along the lines of:
63
- // {color: 'red', margin: '10px'} =>
64
- // {
65
- // color: 'color-red',
66
- // marginTop: 'margin-top-10px',
67
- // marginBottom: 'margin-bottom-10px',
68
- // marginStart: 'margin-start-10px',
69
- // marginEnd: 'margin-end-10px'
70
- // }
71
- //
72
- // First, it expands shorthand properties. (margin => marginTop, marginBottom, marginStart, marginEnd)
73
- // Then, it converts each style value to a className.
74
- // Then, it returns the transformed style Object and an object of injected styles.
75
- function styleXCreateNamespace(style, options) {
76
- const namespaceEntries = (0, _objectUtils.objEntries)(style);
77
-
78
- // First handle shorthands. The strategy for this is based on the `styleResolution` option.
79
- const entries = namespaceEntries.flatMap(_ref => {
80
- let [key, value] = _ref;
81
- // Detect style ...spreads and leave them unmodified
82
- if (value instanceof _stylexInclude.IncludedStyles) {
83
- return [[key, value]];
84
- }
85
- // Detect nested style objects.
86
- if (value != null && typeof value === 'object' && !Array.isArray(value)) {
87
- // Nested Objects are only allowed for legacy :pseudo, @media or long-hand properties for now.
88
- // In the future, we will try to support shorthands as well.
89
- if (!key.startsWith(':') && !key.startsWith('@') && (0, _index.getExpandedKeys)(options).includes(key)) {
90
- throw new Error(messages.INVALID_PSEUDO);
91
- }
92
- return [[key, (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(value).flatMap(_ref2 => {
93
- let [innerKey, innerValue] = _ref2;
94
- if (innerValue != null && typeof innerValue === 'object' && !Array.isArray(innerValue)) {
95
- throw new Error(messages.ILLEGAL_NESTED_PSEUDO);
96
- }
97
- return (0, _index.default)([innerKey, innerValue], options);
98
- }))]];
99
- } else {
100
- if (value !== null && typeof value !== 'string' && typeof value !== 'number' && !Array.isArray(value)) {
101
- throw new Error(messages.ILLEGAL_PROP_VALUE);
102
- }
103
- if (Array.isArray(value) && value.some(val => typeof val === 'object')) {
104
- throw new Error(messages.ILLEGAL_PROP_ARRAY_VALUE);
105
- }
106
- return (0, _index.default)([key, value], options);
107
- }
108
- });
109
-
110
- // Now each [key, value] pair is considered a single atomic style.
111
- // This atomic style is converted to a className by hashing
112
- //
113
- // The [key, className] pair is then added to the output Object: `resolvedNamespace`.
114
- // While hashing, the CSS rule that the className is generated from is also added to the output Object: `injectedStyles`.
115
- const resolvedNamespace = {};
116
- const injectedStyles = {};
117
- for (const [key, val] of entries) {
118
- if (val instanceof _stylexInclude.IncludedStyles) {
119
- resolvedNamespace[key] = val;
120
- } else if (val != null && typeof val === 'object' && !Array.isArray(val)) {
121
- if (key.startsWith(':') || key.startsWith('@')) {
122
- const pseudo = key;
123
- const innerObj = {};
124
- for (const [innerKey, innerVal] of (0, _objectUtils.objEntries)(val)) {
125
- if (innerVal === null) {
126
- innerObj[innerKey] = null;
127
- } else if (typeof innerVal === 'object' && !Array.isArray(innerVal)) {
128
- throw new Error(messages.ILLEGAL_NESTED_PSEUDO);
129
- } else {
130
- const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([innerKey, innerVal], pseudo, options);
131
- innerObj[updatedKey] = className;
132
- injectedStyles[updatedKey + pseudo] = [className, cssRule];
133
- }
134
- }
135
- resolvedNamespace[key] = innerObj;
18
+ (0, _basicValidation.validateNamespace)(namespace);
19
+ const flattenedNamespace = (0, _flattenRawStyleObj.flattenRawStyleObject)(namespace, options);
20
+ const compiledNamespaceTuples = flattenedNamespace.map(_ref => {
21
+ let [key, value] = _ref;
22
+ return [key, value.compiled(options)];
23
+ });
24
+ const compiledNamespace = (0, _objectUtils.objFromEntries)(compiledNamespaceTuples);
25
+ const namespaceObj = {};
26
+ for (const key of Object.keys(compiledNamespace)) {
27
+ const value = compiledNamespace[key];
28
+ if (value instanceof _stylexInclude.IncludedStyles) {
29
+ namespaceObj[key] = value;
136
30
  } else {
137
- const propKey = key;
138
- const classNames = [];
139
- for (const [pseudo, innerVal] of (0, _objectUtils.objEntries)(val)) {
140
- if (pseudo !== 'default' && !pseudo.startsWith(':') && !pseudo.startsWith('@')) {
141
- throw new Error(messages.INVALID_PSEUDO);
142
- }
143
- if (typeof innerVal === 'object' && !Array.isArray(innerVal)) {
144
- throw new Error(messages.ILLEGAL_NESTED_PSEUDO);
145
- }
146
- if (innerVal !== null) {
147
- const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([propKey, innerVal], pseudo === 'default' ? undefined : pseudo, options);
148
- injectedStyles[updatedKey + pseudo] = [className, cssRule];
149
- classNames.push(className);
31
+ const classNameTuples = value.map(v => Array.isArray(v) ? v : null).filter(Boolean);
32
+ const className = classNameTuples.map(_ref2 => {
33
+ let [className] = _ref2;
34
+ return className;
35
+ }).join(' ') || null;
36
+ namespaceObj[key] = className;
37
+ for (const [className, injectable] of classNameTuples) {
38
+ if (injectedStyles[className] == null) {
39
+ injectedStyles[className] = injectable;
150
40
  }
151
41
  }
152
- resolvedNamespace[key] = classNames.join(' ');
153
- }
154
- } else {
155
- if (val === null) {
156
- resolvedNamespace[key] = null;
157
- } else {
158
- const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([key, val], undefined, options);
159
- resolvedNamespace[updatedKey] = className;
160
- injectedStyles[updatedKey] = [className, cssRule];
161
42
  }
162
43
  }
44
+ resolvedNamespaces[namespaceName] = {
45
+ ...namespaceObj,
46
+ $$css: true
47
+ };
163
48
  }
164
- const finalInjectedStyles = (0, _objectUtils.objFromEntries)((0, _objectUtils.objValues)(injectedStyles));
165
- return [resolvedNamespace, finalInjectedStyles];
49
+ return [resolvedNamespaces, injectedStyles];
166
50
  }
@@ -0,0 +1,30 @@
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
+ import type {
11
+ RawStyles,
12
+ InjectableStyle,
13
+ StyleXOptions,
14
+ FlatCompiledStyles,
15
+ } from './common-types';
16
+
17
+ // This takes the object of styles passed to `stylex.create` and transforms it.
18
+ // The transformation replaces style values with classNames.
19
+ //
20
+ // It also collects all injected styles along the way.
21
+ // It then returns a tuple of the transformed style Object and an object of injected styles.
22
+ //
23
+ // This function does some basic validation, and then uses `styleXCreateNamespace` to transform
24
+ // each namespace within,
25
+ //
26
+ // Before returning, it ensures that there are no duplicate styles being injected.
27
+ declare export default function styleXCreateSet(
28
+ namespaces: { +[string]: RawStyles },
29
+ options?: StyleXOptions,
30
+ ): [{ [string]: FlatCompiledStyles }, { [string]: InjectableStyle }];
@@ -0,0 +1,29 @@
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
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
+ type VarsConfig = Readonly<{
12
+ [$$Key$$: string]:
13
+ | string
14
+ | Readonly<{ default: string; [$$Key$$: string]: string }>;
15
+ }>;
16
+ type VarsObject<Vars extends VarsConfig> = Readonly</**
17
+ * > 17 | ...$ObjMapConst<Vars, string>,
18
+ * | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with complex spreads" is currently not supported.
19
+ **/
20
+ any>;
21
+ declare function styleXDefineVars<Vars extends VarsConfig>(
22
+ variables: Vars,
23
+ options: Readonly<
24
+ Omit<Partial<StyleXOptions>, keyof ({ themeName: string })> & {
25
+ themeName: string;
26
+ }
27
+ >,
28
+ ): [VarsObject<Vars>, { [$$Key$$: string]: InjectableStyle }];
29
+ export default styleXDefineVars;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = styleXDefineVars;
7
+ var _hash = _interopRequireDefault(require("./hash"));
8
+ var _objectUtils = require("./utils/object-utils");
9
+ var _defaultOptions = require("./utils/default-options");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function styleXDefineVars(variables, options) {
12
+ const {
13
+ classNamePrefix,
14
+ themeName
15
+ } = {
16
+ ..._defaultOptions.defaultOptions,
17
+ ...options
18
+ };
19
+ const themeNameHash = classNamePrefix + (0, _hash.default)(themeName);
20
+ const variablesMap = (0, _objectUtils.objMap)(variables, (value, key) => {
21
+ const nameHash = classNamePrefix + (0, _hash.default)(`${themeName}.${key}`);
22
+ return {
23
+ nameHash,
24
+ value
25
+ };
26
+ });
27
+ const themeVariablesObject = (0, _objectUtils.objMap)(variablesMap, _ref => {
28
+ let {
29
+ nameHash
30
+ } = _ref;
31
+ return `var(--${nameHash})`;
32
+ });
33
+ const injectableStyles = constructCssVariablesString(variablesMap, themeNameHash);
34
+ return [{
35
+ ...themeVariablesObject,
36
+ __themeName__: themeNameHash
37
+ }, injectableStyles];
38
+ }
39
+ function constructCssVariablesString(variables, themeNameHash) {
40
+ const ruleByAtRule = {};
41
+ for (const [key, {
42
+ nameHash,
43
+ value
44
+ }] of (0, _objectUtils.objEntries)(variables)) {
45
+ if (value !== null && typeof value === 'object') {
46
+ if (value.default === undefined) {
47
+ throw new Error('Default value is not defined for ' + key + ' variable.');
48
+ }
49
+ const v = value;
50
+ for (const [key, value] of (0, _objectUtils.objEntries)(v)) {
51
+ ruleByAtRule[key] ??= [];
52
+ ruleByAtRule[key].push(`--${nameHash}:${value};`);
53
+ }
54
+ } else {
55
+ ruleByAtRule.default ??= [];
56
+ ruleByAtRule.default.push(`--${nameHash}:${value};`);
57
+ }
58
+ }
59
+ const result = {};
60
+ for (const [key, value] of (0, _objectUtils.objEntries)(ruleByAtRule)) {
61
+ const suffix = key === 'default' ? '' : `-${(0, _hash.default)(key)}`;
62
+ let ltr = `:root{${value.join('')}}`;
63
+ if (key !== 'default') {
64
+ ltr = `${key}{${ltr}}`;
65
+ }
66
+ result[themeNameHash + suffix] = {
67
+ ltr,
68
+ rtl: null,
69
+ priority: key === 'default' ? 0 : 0.1
70
+ };
71
+ }
72
+ return result;
73
+ }
@@ -0,0 +1,26 @@
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
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
+
12
+ type VarsConfig = $ReadOnly<{
13
+ [string]: string | $ReadOnly<{ default: string, [string]: string }>,
14
+ }>;
15
+
16
+ type VarsObject<Vars: VarsConfig> = $ReadOnly<{
17
+ ...$ObjMapConst<Vars, string>,
18
+ __themeName__: string,
19
+ }>;
20
+
21
+ // Similar to `stylex.create` it takes an object of variables with their values
22
+ // and returns a string after hashing it.
23
+ declare export default function styleXDefineVars<Vars: VarsConfig>(
24
+ variables: Vars,
25
+ options: $ReadOnly<{ ...Partial<StyleXOptions>, themeName: string, ... }>,
26
+ ): [VarsObject<Vars>, { [string]: InjectableStyle }];
@@ -0,0 +1,13 @@
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
+ declare function stylexFirstThatWorks<T>(
11
+ ...args: ReadonlyArray<T>
12
+ ): ReadonlyArray<T>;
13
+ export default stylexFirstThatWorks;
@@ -4,16 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = stylexFirstThatWorks;
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
-
17
7
  function stylexFirstThatWorks() {
18
8
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
19
9
  args[_key] = arguments[_key];
@@ -0,0 +1,12 @@
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 default function stylexFirstThatWorks<T>(
11
+ ...args: $ReadOnlyArray<T>
12
+ ): $ReadOnlyArray<T>;
@@ -0,0 +1,18 @@
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 class IncludedStyles {
11
+ astNode: any;
12
+ constructor(astNode: any);
13
+ }
14
+ declare function stylexInclude(
15
+ firstArg: any,
16
+ ...styles: any
17
+ ): { [key: string]: IncludedStyles };
18
+ export default stylexInclude;
@@ -6,18 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.IncludedStyles = void 0;
7
7
  exports.default = stylexInclude;
8
8
  var messages = _interopRequireWildcard(require("./messages"));
9
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
- /**
12
- * Copyright (c) Meta Platforms, Inc. and affiliates.
13
- *
14
- * This source code is licensed under the MIT license found in the
15
- * LICENSE file in the root directory of this source tree.
16
- *
17
- *
18
- *
19
- */
20
-
9
+ 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); }
10
+ 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 && Object.prototype.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; }
21
11
  let number = 0;
22
12
  function uuid() {
23
13
  return `__included_${++number}__`;
@@ -0,0 +1,20 @@
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 class IncludedStyles {
11
+ astNode: any;
12
+ constructor(astNode: any): void;
13
+ }
14
+
15
+ declare export default function stylexInclude(
16
+ firstArg: any,
17
+ ...styles: any
18
+ ): {
19
+ [key: string]: IncludedStyles,
20
+ };
@@ -0,0 +1,17 @@
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
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
+ declare function styleXKeyframes(
12
+ frames: {
13
+ readonly [$$Key$$: string]: { readonly [$$Key$$: string]: string | number };
14
+ },
15
+ options: StyleXOptions,
16
+ ): [string, InjectableStyle];
17
+ export default styleXKeyframes;