@stylexjs/shared 0.2.0-beta.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. package/lib/common-types.d.ts +50 -0
  2. package/lib/common-types.js.flow +65 -0
  3. package/lib/convert-to-className.d.ts +16 -0
  4. package/lib/convert-to-className.js +17 -26
  5. package/lib/convert-to-className.js.flow +23 -0
  6. package/lib/generate-css-rule.d.ts +17 -0
  7. package/lib/generate-css-rule.js +6 -17
  8. package/lib/generate-css-rule.js.flow +17 -0
  9. package/lib/hash.d.ts +11 -0
  10. package/lib/hash.js +3 -27
  11. package/lib/hash.js.flow +10 -0
  12. package/lib/index.d.ts +42 -85
  13. package/lib/index.js +19 -27
  14. package/lib/index.js.flow +57 -3
  15. package/lib/messages.d.ts +36 -0
  16. package/lib/messages.js +28 -53
  17. package/lib/messages.js.flow +39 -0
  18. package/lib/physical-rtl/generate-ltr.d.ts +11 -0
  19. package/lib/physical-rtl/generate-ltr.js +18 -46
  20. package/lib/physical-rtl/generate-ltr.js.flow +12 -0
  21. package/lib/physical-rtl/generate-rtl.d.ts +13 -0
  22. package/lib/physical-rtl/generate-rtl.js +18 -50
  23. package/lib/physical-rtl/generate-rtl.js.flow +12 -0
  24. package/lib/preprocess-rules/PreRule.d.ts +52 -0
  25. package/lib/preprocess-rules/PreRule.js +87 -0
  26. package/lib/preprocess-rules/PreRule.js.flow +64 -0
  27. package/lib/preprocess-rules/application-order.d.ts +290 -0
  28. package/lib/preprocess-rules/application-order.js +59 -125
  29. package/lib/preprocess-rules/application-order.js.flow +241 -0
  30. package/lib/preprocess-rules/basic-validation.d.ts +13 -0
  31. package/lib/preprocess-rules/basic-validation.js +83 -0
  32. package/lib/preprocess-rules/basic-validation.js.flow +13 -0
  33. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +25 -0
  34. package/lib/preprocess-rules/flatten-raw-style-obj.js +120 -0
  35. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +27 -0
  36. package/lib/preprocess-rules/index.d.ts +18 -0
  37. package/lib/preprocess-rules/index.js +0 -9
  38. package/lib/preprocess-rules/index.js.flow +19 -0
  39. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +200 -0
  40. package/lib/preprocess-rules/legacy-expand-shorthands.js +90 -123
  41. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +179 -0
  42. package/lib/preprocess-rules/property-specificity.d.ts +89 -0
  43. package/lib/preprocess-rules/property-specificity.js +46 -74
  44. package/lib/preprocess-rules/property-specificity.js.flow +98 -0
  45. package/lib/properties/CSS Animations.json +445 -0
  46. package/lib/properties/CSS Backgrounds and Borders.json +1085 -0
  47. package/lib/properties/CSS Basic User Interface.json +365 -0
  48. package/lib/properties/CSS Box Alignment.json +245 -0
  49. package/lib/properties/CSS Box Model.json +501 -0
  50. package/lib/properties/CSS Color.json +100 -0
  51. package/lib/properties/CSS Columns.json +185 -0
  52. package/lib/properties/CSS Containment.json +203 -0
  53. package/lib/properties/CSS Counter Styles.json +56 -0
  54. package/lib/properties/CSS Display.json +20 -0
  55. package/lib/properties/CSS Flexible Box Layout.json +167 -0
  56. package/lib/properties/CSS Fonts.json +684 -0
  57. package/lib/properties/CSS Fragmentation.json +110 -0
  58. package/lib/properties/CSS Generated Content.json +38 -0
  59. package/lib/properties/CSS Grid Layout.json +500 -0
  60. package/lib/properties/CSS Images.json +91 -0
  61. package/lib/properties/CSS Inline.json +38 -0
  62. package/lib/properties/CSS Lists and Counters.json +86 -0
  63. package/lib/properties/CSS Logical Properties.json +1086 -0
  64. package/lib/properties/CSS Masking.json +399 -0
  65. package/lib/properties/CSS Miscellaneous.json +38 -0
  66. package/lib/properties/CSS Motion Path.json +132 -0
  67. package/lib/properties/CSS Overflow.json +216 -0
  68. package/lib/properties/CSS Pages.json +83 -0
  69. package/lib/properties/CSS Positioning.json +166 -0
  70. package/lib/properties/CSS Ruby.json +55 -0
  71. package/lib/properties/CSS Scroll Anchoring.json +19 -0
  72. package/lib/properties/CSS Scroll Snap.json +604 -0
  73. package/lib/properties/CSS Scrollbars.json +38 -0
  74. package/lib/properties/CSS Shapes.json +56 -0
  75. package/lib/properties/CSS Speech.json +20 -0
  76. package/lib/properties/CSS Table.json +115 -0
  77. package/lib/properties/CSS Text Decoration.json +312 -0
  78. package/lib/properties/CSS Text.json +415 -0
  79. package/lib/properties/CSS Transforms.json +188 -0
  80. package/lib/properties/CSS Transitions.json +122 -0
  81. package/lib/properties/CSS Variables.json +20 -0
  82. package/lib/properties/CSS View Transitions.json +20 -0
  83. package/lib/properties/CSS Will Change.json +20 -0
  84. package/lib/properties/CSS Writing Modes.json +92 -0
  85. package/lib/properties/Compositing and Blending.json +62 -0
  86. package/lib/properties/Filter Effects.json +38 -0
  87. package/lib/properties/MathML.json +56 -0
  88. package/lib/properties/Microsoft Extensions.json +885 -0
  89. package/lib/properties/Mozilla Extensions.json +607 -0
  90. package/lib/properties/Pointer Events.json +20 -0
  91. package/lib/properties/WebKit Extensions.json +707 -0
  92. package/lib/properties.json +10122 -0
  93. package/lib/stylex-create-theme.d.ts +26 -0
  94. package/lib/stylex-create-theme.js +62 -0
  95. package/lib/stylex-create-theme.js.flow +19 -0
  96. package/lib/stylex-create.d.ts +23 -0
  97. package/lib/stylex-create.js +30 -146
  98. package/lib/stylex-create.js.flow +30 -0
  99. package/lib/stylex-define-vars.d.ts +36 -0
  100. package/lib/stylex-define-vars.js +72 -0
  101. package/lib/stylex-define-vars.js.flow +28 -0
  102. package/lib/stylex-first-that-works.d.ts +13 -0
  103. package/lib/stylex-first-that-works.js +0 -10
  104. package/lib/stylex-first-that-works.js.flow +12 -0
  105. package/lib/stylex-include.d.ts +18 -0
  106. package/lib/stylex-include.js +0 -10
  107. package/lib/stylex-include.js.flow +20 -0
  108. package/lib/stylex-keyframes.d.ts +17 -0
  109. package/lib/stylex-keyframes.js +6 -26
  110. package/lib/stylex-keyframes.js.flow +20 -0
  111. package/lib/transform-value.d.ts +22 -0
  112. package/lib/transform-value.js +9 -23
  113. package/lib/transform-value.js.flow +25 -0
  114. package/lib/types/index.d.ts +205 -0
  115. package/lib/types/index.js +191 -0
  116. package/lib/types/index.js.flow +241 -0
  117. package/lib/utils/Rule.d.ts +58 -0
  118. package/lib/utils/Rule.js +0 -21
  119. package/lib/utils/Rule.js.flow +64 -0
  120. package/lib/utils/dashify.d.ts +11 -0
  121. package/lib/utils/dashify.js +0 -8
  122. package/lib/utils/dashify.js.flow +10 -0
  123. package/lib/utils/default-options.d.ts +11 -0
  124. package/lib/utils/default-options.js +14 -0
  125. package/lib/utils/default-options.js.flow +25 -0
  126. package/lib/utils/file-based-identifier.d.ts +15 -0
  127. package/lib/utils/file-based-identifier.js +14 -0
  128. package/lib/utils/file-based-identifier.js.flow +14 -0
  129. package/lib/utils/genCSSRule.d.ts +15 -0
  130. package/lib/utils/genCSSRule.js +9 -18
  131. package/lib/utils/genCSSRule.js.flow +15 -0
  132. package/lib/utils/normalize-value.d.ts +16 -0
  133. package/lib/utils/normalize-value.js +8 -15
  134. package/lib/utils/normalize-value.js.flow +16 -0
  135. package/lib/utils/normalizers/convert-camel-case-transition-props.d.ts +14 -0
  136. package/lib/utils/normalizers/convert-camel-case-transition-props.js +23 -0
  137. package/lib/utils/normalizers/convert-camel-case-transition-props.js.flow +13 -0
  138. package/lib/utils/normalizers/convert-camel-case-values.d.ts +14 -0
  139. package/lib/utils/normalizers/convert-camel-case-values.js +23 -0
  140. package/lib/utils/normalizers/convert-camel-case-values.js.flow +13 -0
  141. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
  142. package/lib/utils/normalizers/detect-unclosed-fns.js +0 -12
  143. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
  144. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
  145. package/lib/utils/normalizers/font-size-px-to-rem.js +9 -19
  146. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
  147. package/lib/utils/normalizers/leading-zero.d.ts +17 -0
  148. package/lib/utils/normalizers/leading-zero.js +0 -12
  149. package/lib/utils/normalizers/leading-zero.js.flow +16 -0
  150. package/lib/utils/normalizers/quotes.d.ts +18 -0
  151. package/lib/utils/normalizers/quotes.js +0 -13
  152. package/lib/utils/normalizers/quotes.js.flow +17 -0
  153. package/lib/utils/normalizers/timings.d.ts +18 -0
  154. package/lib/utils/normalizers/timings.js +0 -14
  155. package/lib/utils/normalizers/timings.js.flow +17 -0
  156. package/lib/utils/normalizers/whitespace.d.ts +19 -0
  157. package/lib/utils/normalizers/whitespace.js +0 -15
  158. package/lib/utils/normalizers/whitespace.js.flow +18 -0
  159. package/lib/utils/normalizers/zero-dimensions.d.ts +19 -0
  160. package/lib/utils/normalizers/zero-dimensions.js +0 -15
  161. package/lib/utils/normalizers/zero-dimensions.js.flow +18 -0
  162. package/lib/utils/object-utils.d.ts +66 -0
  163. package/lib/utils/object-utils.js +21 -13
  164. package/lib/utils/object-utils.js.flow +77 -0
  165. package/lib/utils/property-priorities.d.ts +11 -0
  166. package/lib/utils/property-priorities.js +516 -101
  167. package/lib/utils/property-priorities.js.flow +10 -0
  168. package/lib/utils/split-css-value.d.ts +14 -0
  169. package/lib/utils/split-css-value.js +0 -14
  170. package/lib/utils/split-css-value.js.flow +15 -0
  171. package/lib/validate.d.ts +12 -0
  172. package/lib/validate.js +1 -10
  173. package/lib/validate.js.flow +12 -0
  174. package/package.json +4 -5
  175. package/lib/expand-shorthands.d.ts +0 -5
  176. package/lib/expand-shorthands.js +0 -330
  177. package/lib/namespace-transforms/__tests__/preflatten.test.js +0 -120
  178. package/lib/namespace-transforms/preflatten.js +0 -89
  179. package/lib/preprocess-rules/expand-shorthands.js +0 -156
  180. package/lib/preprocess-rules/null-out-longhand.js +0 -310
  181. package/lib/preprocess-rules/react-native-web.js +0 -142
  182. package/lib/stylex-defaultValue.js +0 -397
@@ -0,0 +1,50 @@
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 { IncludedStyles } from './stylex-include';
11
+ export type TRawValue = number | string | ReadonlyArray<number | string>;
12
+ export type TStyleValue = null | TRawValue;
13
+ export type TNestableStyleValue = TStyleValue | PrimitiveRawStyles;
14
+ export type RawStyles = Readonly<{
15
+ [$$Key$$: string]: TNestableStyleValue | IncludedStyles;
16
+ }>;
17
+ export type PrimitiveRawStyles = Readonly<{
18
+ [$$Key$$: string]: TNestableStyleValue;
19
+ }>;
20
+ export type InjectableStyle = {
21
+ readonly priority: number;
22
+ readonly ltr: string;
23
+ readonly rtl: null | string;
24
+ };
25
+ export type StyleRule = [string, string, InjectableStyle];
26
+ export type CompiledStyles = Readonly<{
27
+ [$$Key$$: string]:
28
+ | IncludedStyles
29
+ | null
30
+ | string
31
+ | Readonly<{ [$$Key$$: string]: null | string }>;
32
+ }>;
33
+ export type FlatCompiledStyles = Readonly<{
34
+ [$$Key$$: string]: string | IncludedStyles | null;
35
+ $$css: true;
36
+ }>;
37
+ export type StyleXOptions = {
38
+ dev: boolean;
39
+ test: boolean;
40
+ useRemForFontSize: boolean;
41
+ runtimeInjection: boolean;
42
+ classNamePrefix: string;
43
+ definedStylexCSSVariables?: { [key: string]: unknown };
44
+ styleResolution:
45
+ | 'application-order'
46
+ | 'property-specificity'
47
+ | 'legacy-expand-shorthands';
48
+ };
49
+ export type MutableCompiledNamespaces = { [key: string]: FlatCompiledStyles };
50
+ export type CompiledNamespaces = Readonly<MutableCompiledNamespaces>;
@@ -0,0 +1,65 @@
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 { IncludedStyles } from './stylex-include';
11
+
12
+ export type TRawValue = number | string | $ReadOnlyArray<number | string>;
13
+ export type TStyleValue = null | TRawValue;
14
+ export type TNestableStyleValue = TStyleValue | PrimitiveRawStyles;
15
+
16
+ export type RawStyles = $ReadOnly<{
17
+ [string]: TNestableStyleValue | IncludedStyles,
18
+ }>;
19
+ export type PrimitiveRawStyles = $ReadOnly<{
20
+ [string]: TNestableStyleValue,
21
+ }>;
22
+
23
+ export type InjectableStyle = {
24
+ +priority: number,
25
+ +ltr: string,
26
+ +rtl: null | string,
27
+ };
28
+
29
+ export type StyleRule = [string, string, InjectableStyle];
30
+
31
+ export type CompiledStyles = $ReadOnly<{
32
+ [string]:
33
+ | IncludedStyles
34
+ | null
35
+ | string
36
+ | $ReadOnly<{ [string]: null | string }>,
37
+ }>;
38
+
39
+ export type FlatCompiledStyles = $ReadOnly<{
40
+ [string]: string | IncludedStyles | null,
41
+ $$css: true,
42
+ }>;
43
+
44
+ export type StyleXOptions = {
45
+ dev: boolean,
46
+ test: boolean,
47
+ useRemForFontSize: boolean,
48
+ runtimeInjection: boolean,
49
+ classNamePrefix: string,
50
+ definedStylexCSSVariables?: { [key: string]: mixed },
51
+ styleResolution:
52
+ | 'application-order' // The last style applied wins.
53
+ // More specific styles will win over less specific styles. (margin-top wins over margin)
54
+ | 'property-specificity'
55
+ // Legacy behavior, that expands shorthand properties into their longhand counterparts at compile-time.
56
+ // This is not recommended, and will be removed in a future version.
57
+ | 'legacy-expand-shorthands',
58
+ ...
59
+ };
60
+
61
+ export type MutableCompiledNamespaces = {
62
+ [key: string]: FlatCompiledStyles,
63
+ };
64
+
65
+ export type CompiledNamespaces = $ReadOnly<MutableCompiledNamespaces>;
@@ -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
+ *
8
+ */
9
+
10
+ import type { TRawValue, StyleRule, StyleXOptions } from './common-types';
11
+ export declare function convertStyleToClassName(
12
+ objEntry: [string, TRawValue],
13
+ pseudos: ReadonlyArray<string>,
14
+ atRules: ReadonlyArray<string>,
15
+ options: StyleXOptions,
16
+ ): StyleRule;
@@ -3,38 +3,29 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = convertToClassName;
6
+ exports.convertStyleToClassName = convertStyleToClassName;
7
7
  var _hash = _interopRequireDefault(require("./hash"));
8
8
  var _dashify = _interopRequireDefault(require("./utils/dashify"));
9
9
  var _transformValue = _interopRequireDefault(require("./transform-value"));
10
- var _generateCssRule = _interopRequireDefault(require("./generate-css-rule"));
10
+ var _generateCssRule = require("./generate-css-rule");
11
+ var _defaultOptions = require("./utils/default-options");
12
+ var _objectUtils = require("./utils/object-utils");
11
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- /**
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- *
18
- *
19
- */
20
-
21
- // This function takes a single style rule and transforms it into a CSS rule.
22
- // [color: 'red'] => ['color', 'classname-for-color-red', CSSRULE{ltr, rtl, priority}]
23
- //
24
- // It converts the camelCased style key to a dash-separated key.
25
- // Handles RTL-flipping
26
- // Hashes to get a className
27
- // Returns the final key, className a CSS Rule
28
- function convertToClassName(objEntry, pseudo) {
29
- let {
30
- stylexSheetName = '<>',
14
+ function convertStyleToClassName(objEntry, pseudos, atRules) {
15
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _defaultOptions.defaultOptions;
16
+ const {
31
17
  classNamePrefix = 'x'
32
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
18
+ } = options;
33
19
  const [key, rawValue] = objEntry;
34
20
  const dashedKey = (0, _dashify.default)(key);
35
- const value = Array.isArray(rawValue) ? rawValue.map(eachValue => (0, _transformValue.default)(key, eachValue)) : (0, _transformValue.default)(key, rawValue);
36
- const stringToHash = Array.isArray(value) ? dashedKey + value.join(', ') + (pseudo ?? 'null') : dashedKey + value + (pseudo ?? 'null');
37
- const className = classNamePrefix + (0, _hash.default)(stylexSheetName + stringToHash);
38
- const cssRules = (0, _generateCssRule.default)(className, dashedKey, value, pseudo);
21
+ const value = Array.isArray(rawValue) ? rawValue.map(eachValue => (0, _transformValue.default)(key, eachValue, options)) : (0, _transformValue.default)(key, rawValue, options);
22
+ const sortedPseudos = (0, _objectUtils.arraySort)(pseudos ?? []);
23
+ const sortedAtRules = (0, _objectUtils.arraySort)(atRules ?? []);
24
+ const atRuleHashString = sortedPseudos.join('');
25
+ const pseudoHashString = sortedAtRules.join('');
26
+ const modifierHashString = atRuleHashString + pseudoHashString || 'null';
27
+ const stringToHash = Array.isArray(value) ? dashedKey + value.join(', ') + modifierHashString : dashedKey + value + modifierHashString;
28
+ const className = classNamePrefix + (0, _hash.default)('<>' + stringToHash);
29
+ const cssRules = (0, _generateCssRule.generateRule)(className, dashedKey, value, pseudos, atRules);
39
30
  return [key, className, cssRules];
40
31
  }
@@ -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
+ * @flow strict
8
+ */
9
+
10
+ import type { TRawValue, StyleRule, StyleXOptions } from './common-types';
11
+ // This function takes a single style rule and transforms it into a CSS rule.
12
+ // [color: 'red'] => ['color', 'classname-for-color-red', CSSRULE{ltr, rtl, priority}]
13
+ //
14
+ // It converts the camelCased style key to a dash-separated key.
15
+ // Handles RTL-flipping
16
+ // Hashes to get a className
17
+ // Returns the final key, className a CSS Rule
18
+ declare export function convertStyleToClassName(
19
+ objEntry: [string, TRawValue],
20
+ pseudos: $ReadOnlyArray<string>,
21
+ atRules: $ReadOnlyArray<string>,
22
+ options: StyleXOptions,
23
+ ): StyleRule;
@@ -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 } from './common-types';
11
+ export declare function generateRule(
12
+ className: string,
13
+ key: string,
14
+ value: string | ReadonlyArray<string>,
15
+ pseudos: ReadonlyArray<string>,
16
+ atRules: ReadonlyArray<string>,
17
+ ): InjectableStyle;
@@ -3,31 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = generateCSSRule;
6
+ exports.generateRule = generateRule;
7
7
  var _generateLtr = _interopRequireDefault(require("./physical-rtl/generate-ltr"));
8
8
  var _generateRtl = _interopRequireDefault(require("./physical-rtl/generate-rtl"));
9
- var _genCSSRule = _interopRequireDefault(require("./utils/genCSSRule"));
9
+ var _genCSSRule = require("./utils/genCSSRule");
10
10
  var _propertyPriorities = _interopRequireDefault(require("./utils/property-priorities"));
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- /**
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- *
18
- *
19
- */
20
-
21
- function generateCSSRule(className, key,
22
- // pre-dashed
23
- value, pseudo) {
12
+ function generateRule(className, key, value, pseudos, atRules) {
24
13
  const pairs = Array.isArray(value) ? value.map(eachValue => [key, eachValue]) : [[key, value]];
25
14
  const ltrPairs = pairs.map(_generateLtr.default);
26
15
  const ltrDecls = ltrPairs.map(pair => pair.join(':')).join(';');
27
16
  const rtlDecls = pairs.map(_generateRtl.default).filter(Boolean).map(pair => pair.join(':')).join(';');
28
- const ltrRule = (0, _genCSSRule.default)(className, ltrDecls, pseudo);
29
- const rtlRule = !rtlDecls ? null : (0, _genCSSRule.default)(className, rtlDecls, pseudo);
30
- const priority = (0, _propertyPriorities.default)(key) + (pseudo ? (0, _propertyPriorities.default)(pseudo) : 0);
17
+ const ltrRule = (0, _genCSSRule.genCSSRule)(className, ltrDecls, pseudos, atRules);
18
+ const rtlRule = !rtlDecls ? null : (0, _genCSSRule.genCSSRule)(className, rtlDecls, pseudos, atRules);
19
+ const priority = (0, _propertyPriorities.default)(key) + pseudos.map(_propertyPriorities.default).reduce((a, b) => a + b, 0) + atRules.map(_propertyPriorities.default).reduce((a, b) => a + b, 0);
31
20
  return {
32
21
  priority,
33
22
  ltr: ltrRule,
@@ -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
+ * @flow strict
8
+ */
9
+
10
+ import type { InjectableStyle } from './common-types';
11
+ declare export function generateRule(
12
+ className: string,
13
+ key: string,
14
+ value: string | $ReadOnlyArray<string>,
15
+ pseudos: $ReadOnlyArray<string>,
16
+ atRules: $ReadOnlyArray<string>,
17
+ ): InjectableStyle;
package/lib/hash.d.ts ADDED
@@ -0,0 +1,11 @@
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 const $$EXPORT_DEFAULT_DECLARATION$$: (str: string) => string;
11
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
package/lib/hash.js CHANGED
@@ -4,31 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
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
- /* eslint-disable default-case */
17
- /* eslint-disable no-fallthrough */
18
-
19
- /**
20
- * JS Implementation of MurmurHash2
21
- *
22
- * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
23
- * @see http://github.com/garycourt/murmurhash-js
24
- * @author <a href="mailto:aappleby@gmail.com">Austin Appleby</a>
25
- * @see http://sites.google.com/site/murmurhash/
26
- *
27
- * @param {string} str ASCII only
28
- * @param {number} seed Positive integer only
29
- * @return {number} 32-bit positive integer hash
30
- */
31
- function murmurhash2_32_gc(str, seed) {
7
+ function murmurhash2_32_gc(str) {
8
+ let seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
32
9
  let l = str.length,
33
10
  h = seed ^ l,
34
11
  i = 0,
@@ -57,5 +34,4 @@ function murmurhash2_32_gc(str, seed) {
57
34
  return h >>> 0;
58
35
  }
59
36
  const hash = str => murmurhash2_32_gc(str, 1).toString(36);
60
- var _default = hash;
61
- exports.default = _default;
37
+ var _default = exports.default = hash;
@@ -0,0 +1,10 @@
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 (str: string) => string;
package/lib/index.d.ts CHANGED
@@ -3,91 +3,48 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
6
8
  */
7
9
 
8
- export type TRawValue = number | string | Array<number | string>;
9
-
10
- export type TStyleValue = number | string | Array<number | string>;
11
- export type TNestableStyleValue =
12
- | TStyleValue
13
- | { readonly [key: string]: TStyleValue };
14
-
15
- export type RawStyles = $ReadOnly<{
16
- [key: string]: TNestableStyleValue;
17
- }>;
18
-
19
- export type InjectableStyle = {
20
- readonly priority: number;
21
- readonly ltr: string;
22
- readonly rtl?: string;
23
- };
24
-
25
- export type StyleRule = readonly [string, string, InjectableStyle];
26
-
27
- export type CompiledStyles = {
28
- readonly [key: string]: string | null;
29
- readonly $$css: true;
30
- };
31
- export type MutableCompiledStyles = {
32
- [key: string]: string | null;
33
- $$css: true;
34
- };
35
-
36
- export type CompiledNamespaces = { readonly [key: string]: CompiledStyles };
37
-
38
- export type MutableCompiledNamespaces = {
39
- [key: string]: MutableCompiledStyles;
40
- };
41
-
42
- export function create<N extends { readonly [key: string]: RawStyles }>(
43
- namespaces: N,
44
- options?: StyleXOptions
45
- ): readonly [CompiledNamespaces, { readonly [key: string]: InjectableStyle }];
46
-
47
- export function keyframes<
48
- Obj extends {
49
- readonly [key: string]: { readonly [k: string]: string | number };
50
- }
51
- >(animation: Obj, options?: StyleXOptions): readonly [string, InjectableStyle];
52
-
53
- export function include(animation: {
54
- readonly [key: string]: string | number;
55
- }): readonly { [key: string]: IncludedStyles };
56
-
57
- export class IncludedStyles {
58
- astNode: any;
59
- }
60
-
61
- export type StyleXOptions = {
62
- dev: boolean;
63
- test: boolean;
64
- stylexSheetName?: string | undefined;
65
- classNamePrefix: string;
66
- definedStylexCSSVariables?: { [key: string]: any };
67
- skipShorthandExpansion?: boolean;
68
- [key: string]: any;
69
- };
70
-
71
- export function firstThatWorks<T>(...args: T[]): T[];
72
-
73
- export const messages: {
74
- ILLEGAL_ARGUMENT_LENGTH: string;
75
- NON_STATIC_VALUE: string;
76
- ESCAPED_STYLEX_VALUE: string;
77
- UNBOUND_STYLEX_CALL_VALUE: string;
78
- ONLY_TOP_LEVEL: string;
79
- NON_OBJECT_FOR_STYLEX_CALL: string;
80
- UNKNOWN_PROP_KEY: string;
81
- INVALID_PSEUDO: string;
82
- ILLEGAL_NAMESPACE_TYPE: string;
83
- UNKNOWN_NAMESPACE: string;
84
- ILLEGAL_NESTED_PSEUDO: string;
85
- ILLEGAL_PROP_VALUE: string;
86
- ILLEGAL_PROP_ARRAY_VALUE: string;
87
- ILLEGAL_NAMESPACE_VALUE: string;
88
- INVALID_SPREAD: string;
89
- LINT_UNCLOSED_FUNCTION: string;
90
- LOCAL_ONLY: string;
91
- UNEXPECTED_ARGUMENT: string;
92
- EXPECTED_FUNCTION_CALL: string;
10
+ export type {
11
+ RawStyles,
12
+ StyleRule,
13
+ TNestableStyleValue,
14
+ TRawValue,
15
+ TStyleValue,
16
+ } from './common-types';
17
+ import styleXCreateSet from './stylex-create';
18
+ import styleXDefineVars from './stylex-define-vars';
19
+ import styleXCreateTheme from './stylex-create-theme';
20
+ import stylexKeyframes from './stylex-keyframes';
21
+ import stylexInclude, {
22
+ IncludedStyles as _IncludedStyles,
23
+ } from './stylex-include';
24
+ import stylexFirstThatWorks from './stylex-first-that-works';
25
+ import hash from './hash';
26
+ import genFileBasedIdentifier from './utils/file-based-identifier';
27
+ import * as m from './messages';
28
+ export * as types from './types';
29
+ import type {
30
+ InjectableStyle as _InjectableStyle,
31
+ CompiledNamespaces as _CompiledNamespaces,
32
+ MutableCompiledNamespaces as _MutableCompiledNamespaces,
33
+ StyleXOptions as _StyleXOptions,
34
+ } from './common-types';
35
+ export declare const create: typeof styleXCreateSet;
36
+ export declare const defineVars: typeof styleXDefineVars;
37
+ export declare const createTheme: typeof styleXCreateTheme;
38
+ export declare const keyframes: typeof stylexKeyframes;
39
+ export declare const include: typeof stylexInclude;
40
+ export declare const utils: {
41
+ hash: typeof hash;
42
+ genFileBasedIdentifier: typeof genFileBasedIdentifier;
93
43
  };
44
+ export declare const messages: typeof m;
45
+ export declare const IncludedStyles: typeof _IncludedStyles;
46
+ export declare const firstThatWorks: typeof stylexFirstThatWorks;
47
+ export type InjectableStyle = _InjectableStyle;
48
+ export type CompiledNamespaces = _CompiledNamespaces;
49
+ export type MutableCompiledNamespaces = _MutableCompiledNamespaces;
50
+ export type StyleXOptions = _StyleXOptions;
package/lib/index.js CHANGED
@@ -3,38 +3,30 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.messages = exports.keyframes = exports.include = exports.firstThatWorks = exports.create = exports.IncludedStyles = void 0;
6
+ exports.utils = exports.types = exports.messages = exports.keyframes = exports.include = exports.firstThatWorks = exports.defineVars = exports.createTheme = exports.create = exports.IncludedStyles = void 0;
7
7
  var _stylexCreate = _interopRequireDefault(require("./stylex-create"));
8
+ var _stylexDefineVars = _interopRequireDefault(require("./stylex-define-vars"));
9
+ var _stylexCreateTheme = _interopRequireDefault(require("./stylex-create-theme"));
8
10
  var _stylexKeyframes = _interopRequireDefault(require("./stylex-keyframes"));
9
11
  var _stylexInclude = _interopRequireWildcard(require("./stylex-include"));
10
12
  var _stylexFirstThatWorks = _interopRequireDefault(require("./stylex-first-that-works"));
13
+ var _hash = _interopRequireDefault(require("./hash"));
14
+ var _fileBasedIdentifier = _interopRequireDefault(require("./utils/file-based-identifier"));
11
15
  var m = _interopRequireWildcard(require("./messages"));
16
+ var _types = _interopRequireWildcard(require("./types"));
17
+ exports.types = _types;
12
18
  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
19
  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
20
  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
- // All functions exposed from `stylex` are defined in a way that can be run
25
- // entirely in the browser.
26
-
27
- // These are the implementations of those functions.
28
-
29
- const create = _stylexCreate.default;
30
- exports.create = create;
31
- const keyframes = _stylexKeyframes.default;
32
- exports.keyframes = keyframes;
33
- const include = _stylexInclude.default;
34
- exports.include = include;
35
- const messages = m;
36
- exports.messages = messages;
37
- const IncludedStyles = _stylexInclude.IncludedStyles;
38
- exports.IncludedStyles = IncludedStyles;
39
- const firstThatWorks = _stylexFirstThatWorks.default;
40
- exports.firstThatWorks = firstThatWorks;
21
+ const create = exports.create = _stylexCreate.default;
22
+ const defineVars = exports.defineVars = _stylexDefineVars.default;
23
+ const createTheme = exports.createTheme = _stylexCreateTheme.default;
24
+ const keyframes = exports.keyframes = _stylexKeyframes.default;
25
+ const include = exports.include = _stylexInclude.default;
26
+ const utils = exports.utils = {
27
+ hash: _hash.default,
28
+ genFileBasedIdentifier: _fileBasedIdentifier.default
29
+ };
30
+ const messages = exports.messages = m;
31
+ const IncludedStyles = exports.IncludedStyles = _stylexInclude.IncludedStyles;
32
+ const firstThatWorks = exports.firstThatWorks = _stylexFirstThatWorks.default;
package/lib/index.js.flow CHANGED
@@ -1,5 +1,59 @@
1
1
  /**
2
- * Flowtype definitions for index.js
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
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
5
8
  */
9
+
10
+ export type {
11
+ RawStyles,
12
+ StyleRule,
13
+ TNestableStyleValue,
14
+ TRawValue,
15
+ TStyleValue,
16
+ } from './common-types';
17
+
18
+ // All functions exposed from `stylex` are defined in a way that can be run
19
+ // entirely in the browser.
20
+
21
+ // These are the implementations of those functions.
22
+
23
+ import styleXCreateSet from './stylex-create';
24
+ import styleXDefineVars from './stylex-define-vars';
25
+ import styleXCreateTheme from './stylex-create-theme';
26
+ import stylexKeyframes from './stylex-keyframes';
27
+ import stylexInclude, {
28
+ IncludedStyles as _IncludedStyles,
29
+ } from './stylex-include';
30
+ import stylexFirstThatWorks from './stylex-first-that-works';
31
+ import hash from './hash';
32
+ import genFileBasedIdentifier from './utils/file-based-identifier';
33
+ import * as m from './messages';
34
+ export * as types from './types';
35
+
36
+ import type {
37
+ InjectableStyle as _InjectableStyle,
38
+ CompiledNamespaces as _CompiledNamespaces,
39
+ MutableCompiledNamespaces as _MutableCompiledNamespaces,
40
+ StyleXOptions as _StyleXOptions,
41
+ } from './common-types';
42
+
43
+ declare export const create: typeof styleXCreateSet;
44
+ declare export const defineVars: typeof styleXDefineVars;
45
+ declare export const createTheme: typeof styleXCreateTheme;
46
+ declare export const keyframes: typeof stylexKeyframes;
47
+ declare export const include: typeof stylexInclude;
48
+ declare export const utils: {
49
+ hash: typeof hash,
50
+ genFileBasedIdentifier: typeof genFileBasedIdentifier,
51
+ };
52
+ declare export const messages: typeof m;
53
+ declare export const IncludedStyles: typeof _IncludedStyles;
54
+ declare export const firstThatWorks: typeof stylexFirstThatWorks;
55
+
56
+ export type InjectableStyle = _InjectableStyle;
57
+ export type CompiledNamespaces = _CompiledNamespaces;
58
+ export type MutableCompiledNamespaces = _MutableCompiledNamespaces;
59
+ export type StyleXOptions = _StyleXOptions;
@@ -0,0 +1,36 @@
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 ILLEGAL_ARGUMENT_LENGTH: 'stylex() should have 1 argument.';
11
+ export declare const NON_STATIC_VALUE: 'Only static values are allowed inside of a stylex.create() call.';
12
+ export declare const ESCAPED_STYLEX_VALUE: 'Escaping a stylex.create() value is not allowed.';
13
+ export declare const UNBOUND_STYLEX_CALL_VALUE: 'stylex.create calls must be bound to a bare variable.';
14
+ export declare const ONLY_TOP_LEVEL: 'stylex.create() is only allowed at the root of a program.';
15
+ export declare const NON_OBJECT_FOR_STYLEX_CALL: 'stylex.create() can only accept a style object.';
16
+ export declare const UNKNOWN_PROP_KEY: 'Unknown property key';
17
+ export declare const INVALID_PSEUDO: 'Invalid pseudo selector, not on the whitelist.';
18
+ export declare const INVALID_PSEUDO_OR_AT_RULE: 'Invalid pseudo or at-rule.';
19
+ export declare const NO_CONDITIONAL_SHORTHAND: 'You cannot use conditional style values for a shorthand property.';
20
+ export declare const ILLEGAL_NAMESPACE_TYPE: 'Only a string literal namespace is allowed here.';
21
+ export declare const UNKNOWN_NAMESPACE: 'Unknown namespace';
22
+ export declare const ILLEGAL_NESTED_PSEUDO: "Pseudo objects can't be nested more than one level deep.";
23
+ export declare const ILLEGAL_PROP_VALUE: 'A style value can only contain an array, string or number.';
24
+ export declare const ILLEGAL_PROP_ARRAY_VALUE: 'A style array value can only contain strings or numbers.';
25
+ export declare const ILLEGAL_NAMESPACE_VALUE: 'A stylex namespace must be an object.';
26
+ export declare const INVALID_SPREAD: 'Imported styles spread with a stylex.create call must be type cast as `XStyle` to verify their type.';
27
+ export declare const LINT_UNCLOSED_FUNCTION: 'Rule contains an unclosed function';
28
+ export declare const LOCAL_ONLY: 'The return value of stylex.create() should not be exported.';
29
+ export declare const UNEXPECTED_ARGUMENT: 'Unexpected argument passed to the stylex() function.';
30
+ export declare const EXPECTED_FUNCTION_CALL: 'Expected a simple function call but found something else.';
31
+ export declare const NO_PARENT_PATH: 'Unexpected AST node without a parent path.';
32
+ export declare const ONLY_TOP_LEVEL_INLCUDES: 'stylex.include() is only at the top level of a style definition object.';
33
+ export declare const DUPLICATE_CONDITIONAL: 'The same pseudo selector or at-rule cannot be used more than once.';
34
+ export declare const NO_PROJECT_ROOT_DIRECTORY: 'The project root directory `rootDir` is not configured.';
35
+ export declare const NON_EXPORT_NAMED_DECLARATION: 'The return value of stylex.defineVars() must be bound to a named export.';
36
+ export declare const ANONYMOUS_THEME: 'stylex.createTheme() must be bound to a named constant.';