@stylexjs/shared 0.17.5 → 0.18.0

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 (145) hide show
  1. package/lib/common-types.d.ts +61 -0
  2. package/lib/common-types.js +1 -0
  3. package/lib/common-types.js.flow +85 -0
  4. package/lib/hash.d.ts +15 -0
  5. package/lib/hash.js +49 -0
  6. package/lib/hash.js.flow +12 -0
  7. package/lib/messages.d.ts +70 -0
  8. package/lib/messages.js +38 -0
  9. package/lib/messages.js.flow +44 -0
  10. package/lib/physical-rtl/generate-ltr.d.ts +15 -0
  11. package/lib/physical-rtl/generate-ltr.js +75 -0
  12. package/lib/physical-rtl/generate-ltr.js.flow +14 -0
  13. package/lib/physical-rtl/generate-rtl.d.ts +15 -0
  14. package/lib/physical-rtl/generate-rtl.js +157 -0
  15. package/lib/physical-rtl/generate-rtl.js.flow +14 -0
  16. package/lib/preprocess-rules/PreRule.d.ts +51 -0
  17. package/lib/preprocess-rules/PreRule.js +79 -0
  18. package/lib/preprocess-rules/PreRule.js.flow +63 -0
  19. package/lib/preprocess-rules/__tests__/PreRule-test.js +33 -0
  20. package/lib/preprocess-rules/__tests__/flatten-raw-style-obj-test.js +196 -0
  21. package/lib/preprocess-rules/application-order.d.ts +186 -0
  22. package/lib/preprocess-rules/application-order.js +195 -0
  23. package/lib/preprocess-rules/application-order.js.flow +141 -0
  24. package/lib/preprocess-rules/basic-validation.d.ts +13 -0
  25. package/lib/preprocess-rules/basic-validation.js +70 -0
  26. package/lib/preprocess-rules/basic-validation.js.flow +13 -0
  27. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +20 -0
  28. package/lib/preprocess-rules/flatten-raw-style-obj.js +100 -0
  29. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +23 -0
  30. package/lib/preprocess-rules/index.d.ts +21 -0
  31. package/lib/preprocess-rules/index.js +45 -0
  32. package/lib/preprocess-rules/index.js.flow +23 -0
  33. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +170 -0
  34. package/lib/preprocess-rules/legacy-expand-shorthands.js +222 -0
  35. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +142 -0
  36. package/lib/preprocess-rules/property-specificity.d.ts +79 -0
  37. package/lib/preprocess-rules/property-specificity.js +107 -0
  38. package/lib/preprocess-rules/property-specificity.js.flow +93 -0
  39. package/lib/stylex-consts-utils.d.ts +11 -0
  40. package/lib/stylex-consts-utils.js +1 -0
  41. package/lib/stylex-consts-utils.js.flow +14 -0
  42. package/lib/stylex-create-theme.d.ts +26 -0
  43. package/lib/stylex-create-theme.js +53 -0
  44. package/lib/stylex-create-theme.js.flow +19 -0
  45. package/lib/stylex-create.d.ts +27 -0
  46. package/lib/stylex-create.js +60 -0
  47. package/lib/stylex-create.js.flow +37 -0
  48. package/lib/stylex-defaultMarker.d.ts +14 -0
  49. package/lib/stylex-defaultMarker.js +14 -0
  50. package/lib/stylex-defaultMarker.js.flow +13 -0
  51. package/lib/stylex-define-consts.d.ts +23 -0
  52. package/lib/stylex-define-consts.js +40 -0
  53. package/lib/stylex-define-consts.js.flow +19 -0
  54. package/lib/stylex-define-vars.d.ts +28 -0
  55. package/lib/stylex-define-vars.js +90 -0
  56. package/lib/stylex-define-vars.js.flow +26 -0
  57. package/lib/stylex-first-that-works.d.ts +13 -0
  58. package/lib/stylex-first-that-works.js +23 -0
  59. package/lib/stylex-first-that-works.js.flow +12 -0
  60. package/lib/stylex-keyframes.d.ts +17 -0
  61. package/lib/stylex-keyframes.js +46 -0
  62. package/lib/stylex-keyframes.js.flow +20 -0
  63. package/lib/stylex-position-try.d.ts +15 -0
  64. package/lib/stylex-position-try.js +47 -0
  65. package/lib/stylex-position-try.js.flow +18 -0
  66. package/lib/stylex-vars-utils.d.ts +27 -0
  67. package/lib/stylex-vars-utils.js +66 -0
  68. package/lib/stylex-vars-utils.js.flow +31 -0
  69. package/lib/stylex-view-transition-class.d.ts +22 -0
  70. package/lib/stylex-view-transition-class.js +42 -0
  71. package/lib/stylex-view-transition-class.js.flow +23 -0
  72. package/lib/types/__tests__/stylex-types-test.js +178 -0
  73. package/lib/types/index.d.ts +254 -0
  74. package/lib/types/index.js +147 -0
  75. package/lib/types/index.js.flow +280 -0
  76. package/lib/utils/Rule.d.ts +58 -0
  77. package/lib/utils/Rule.js +50 -0
  78. package/lib/utils/Rule.js.flow +64 -0
  79. package/lib/utils/__tests__/convert-to-className-test.js +85 -0
  80. package/lib/utils/__tests__/property-priorities-test.js +33 -0
  81. package/lib/utils/__tests__/split-css-value-test.js +26 -0
  82. package/lib/utils/__tests__/transform-value-test.js +36 -0
  83. package/lib/utils/convert-to-className.d.ts +21 -0
  84. package/lib/utils/convert-to-className.js +61 -0
  85. package/lib/utils/convert-to-className.js.flow +29 -0
  86. package/lib/utils/css-properties.js.flow +155 -0
  87. package/lib/utils/dashify.d.ts +11 -0
  88. package/lib/utils/dashify.js +9 -0
  89. package/lib/utils/dashify.js.flow +10 -0
  90. package/lib/utils/default-options.d.ts +12 -0
  91. package/lib/utils/default-options.js +26 -0
  92. package/lib/utils/default-options.js.flow +12 -0
  93. package/lib/utils/file-based-identifier.d.ts +15 -0
  94. package/lib/utils/file-based-identifier.js +13 -0
  95. package/lib/utils/file-based-identifier.js.flow +14 -0
  96. package/lib/utils/generate-css-rule.d.ts +19 -0
  97. package/lib/utils/generate-css-rule.js +37 -0
  98. package/lib/utils/generate-css-rule.js.flow +19 -0
  99. package/lib/utils/normalize-value.d.ts +16 -0
  100. package/lib/utils/normalize-value.js +27 -0
  101. package/lib/utils/normalize-value.js.flow +16 -0
  102. package/lib/utils/normalizers/convert-camel-case-values.d.ts +14 -0
  103. package/lib/utils/normalizers/convert-camel-case-values.js +23 -0
  104. package/lib/utils/normalizers/convert-camel-case-values.js.flow +13 -0
  105. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
  106. package/lib/utils/normalizers/detect-unclosed-fns.js +16 -0
  107. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
  108. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
  109. package/lib/utils/normalizers/font-size-px-to-rem.js +24 -0
  110. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
  111. package/lib/utils/normalizers/leading-zero.d.ts +17 -0
  112. package/lib/utils/normalizers/leading-zero.js +24 -0
  113. package/lib/utils/normalizers/leading-zero.js.flow +16 -0
  114. package/lib/utils/normalizers/quotes.d.ts +18 -0
  115. package/lib/utils/normalizers/quotes.js +17 -0
  116. package/lib/utils/normalizers/quotes.js.flow +17 -0
  117. package/lib/utils/normalizers/timings.d.ts +18 -0
  118. package/lib/utils/normalizers/timings.js +25 -0
  119. package/lib/utils/normalizers/timings.js.flow +17 -0
  120. package/lib/utils/normalizers/whitespace.d.ts +19 -0
  121. package/lib/utils/normalizers/whitespace.js +54 -0
  122. package/lib/utils/normalizers/whitespace.js.flow +18 -0
  123. package/lib/utils/normalizers/zero-dimensions.d.ts +19 -0
  124. package/lib/utils/normalizers/zero-dimensions.js +45 -0
  125. package/lib/utils/normalizers/zero-dimensions.js.flow +18 -0
  126. package/lib/utils/object-utils.d.ts +68 -0
  127. package/lib/utils/object-utils.js +89 -0
  128. package/lib/utils/object-utils.js.flow +78 -0
  129. package/lib/utils/property-priorities.js +13 -1
  130. package/lib/utils/rule-utils.d.ts +17 -0
  131. package/lib/utils/rule-utils.js +41 -0
  132. package/lib/utils/rule-utils.js.flow +16 -0
  133. package/lib/utils/split-css-value.d.ts +14 -0
  134. package/lib/utils/split-css-value.js +41 -0
  135. package/lib/utils/split-css-value.js.flow +15 -0
  136. package/lib/utils/transform-value.d.ts +24 -0
  137. package/lib/utils/transform-value.js +50 -0
  138. package/lib/utils/transform-value.js.flow +25 -0
  139. package/lib/validate.d.ts +12 -0
  140. package/lib/validate.js +19 -0
  141. package/lib/validate.js.flow +14 -0
  142. package/lib/when/when.d.ts +67 -0
  143. package/lib/when/when.js +71 -0
  144. package/lib/when/when.js.flow +73 -0
  145. package/package.json +1 -1
@@ -0,0 +1,61 @@
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 type TRawValue = number | string | ReadonlyArray<number | string>;
11
+ export type TStyleValue = null | TRawValue;
12
+ export type TNestableStyleValue = TStyleValue | PrimitiveRawStyles;
13
+ export type RawStyles = Readonly<{ [$$Key$$: string]: TNestableStyleValue }>;
14
+ export type PrimitiveRawStyles = Readonly<{
15
+ [$$Key$$: string]: TNestableStyleValue;
16
+ }>;
17
+ export type InjectableStyle = {
18
+ readonly priority: number;
19
+ readonly ltr: string;
20
+ readonly rtl: null | string;
21
+ };
22
+ export type InjectableConstStyle = {
23
+ readonly priority: number;
24
+ readonly ltr: string;
25
+ readonly rtl: null | string;
26
+ readonly constKey: string;
27
+ readonly constVal: string | number;
28
+ };
29
+ export type StyleRule = [string, string, InjectableStyle];
30
+ export type CompiledStyles = Readonly<{
31
+ [$$Key$$: string]:
32
+ | null
33
+ | string
34
+ | Readonly<{ [$$Key$$: string]: null | string }>;
35
+ }>;
36
+ export type FlatCompiledStyles = Readonly<
37
+ { [$$Key$$: string]: string | null } & { $$css: true | string }
38
+ >;
39
+ export type StyleXOptions = Readonly<{
40
+ classNamePrefix: string;
41
+ debug: null | undefined | boolean;
42
+ definedStylexCSSVariables?: { [key: string]: unknown };
43
+ dev: boolean;
44
+ propertyValidationMode?: 'throw' | 'warn' | 'silent';
45
+ enableDebugClassNames?: null | undefined | boolean;
46
+ enableDebugDataProp?: null | undefined | boolean;
47
+ enableDevClassNames?: null | undefined | boolean;
48
+ enableFontSizePxToRem?: null | undefined | boolean;
49
+ enableMediaQueryOrder?: null | undefined | boolean;
50
+ enableLegacyValueFlipping?: null | undefined | boolean;
51
+ enableLogicalStylesPolyfill?: null | undefined | boolean;
52
+ enableLTRRTLComments?: null | undefined | boolean;
53
+ enableMinifiedKeys?: null | undefined | boolean;
54
+ styleResolution:
55
+ | 'application-order'
56
+ | 'property-specificity'
57
+ | 'legacy-expand-shorthands';
58
+ test: boolean;
59
+ }>;
60
+ export type MutableCompiledNamespaces = { [key: string]: FlatCompiledStyles };
61
+ export type CompiledNamespaces = Readonly<MutableCompiledNamespaces>;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,85 @@
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
+ export type TRawValue = number | string | $ReadOnlyArray<number | string>;
11
+ export type TStyleValue = null | TRawValue;
12
+ export type TNestableStyleValue = TStyleValue | PrimitiveRawStyles;
13
+
14
+ export type RawStyles = $ReadOnly<{
15
+ [string]: TNestableStyleValue,
16
+ }>;
17
+ export type PrimitiveRawStyles = $ReadOnly<{
18
+ [string]: TNestableStyleValue,
19
+ }>;
20
+
21
+ export type InjectableStyle = {
22
+ +priority: number,
23
+ +ltr: string,
24
+ +rtl: null | string,
25
+ };
26
+
27
+ export type InjectableConstStyle = {
28
+ +priority: number,
29
+ +ltr: string,
30
+ +rtl: null | string,
31
+ +constKey: string,
32
+ +constVal: string | number,
33
+ };
34
+
35
+ export type StyleRule = [string, string, InjectableStyle];
36
+
37
+ export type CompiledStyles = $ReadOnly<{
38
+ [string]: null | string | $ReadOnly<{ [string]: null | string }>,
39
+ }>;
40
+
41
+ export type FlatCompiledStyles = $ReadOnly<{
42
+ [string]: string | null,
43
+ $$css: true | string,
44
+ }>;
45
+
46
+ export type StyleXOptions = $ReadOnly<{
47
+ classNamePrefix: string,
48
+ debug: ?boolean,
49
+ definedStylexCSSVariables?: { [key: string]: mixed },
50
+ dev: boolean,
51
+ propertyValidationMode?: 'throw' | 'warn' | 'silent',
52
+ enableDebugClassNames?: ?boolean,
53
+ enableDebugDataProp?: ?boolean,
54
+ enableDevClassNames?: ?boolean,
55
+ enableFontSizePxToRem?: ?boolean,
56
+ enableInlinedConditionalMerge?: ?boolean,
57
+ enableMediaQueryOrder?: ?boolean,
58
+ enableLegacyValueFlipping?: ?boolean,
59
+ enableLogicalStylesPolyfill?: ?boolean,
60
+ enableLTRRTLComments?: ?boolean,
61
+ enableMinifiedKeys?: ?boolean,
62
+ // runtimeInjection?:
63
+ // | boolean
64
+ // | ?string
65
+ // | $ReadOnly<{ from: string, as: string }>,
66
+ importSources?: $ReadOnlyArray<
67
+ string | $ReadOnly<{ from: string, as: string }>,
68
+ >,
69
+ treeshakeCompensation?: boolean,
70
+ styleResolution:
71
+ | 'application-order' // The last style applied wins.
72
+ // More specific styles will win over less specific styles. (margin-top wins over margin)
73
+ | 'property-specificity'
74
+ // Legacy behavior, that expands shorthand properties into their longhand counterparts at compile-time.
75
+ // This is not recommended, and will be removed in a future version.
76
+ | 'legacy-expand-shorthands',
77
+ test: boolean,
78
+ ...
79
+ }>;
80
+
81
+ export type MutableCompiledNamespaces = {
82
+ [key: string]: FlatCompiledStyles,
83
+ };
84
+
85
+ export type CompiledNamespaces = $ReadOnly<MutableCompiledNamespaces>;
package/lib/hash.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
10
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: (str: string) => string;
11
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
12
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
13
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
14
+ export declare const createShortHash: (str: string) => string;
15
+ export declare type createShortHash = typeof createShortHash;
package/lib/hash.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.createShortHash = void 0;
7
+ function murmurhash2_32_gc(str, seed = 0) {
8
+ let l = str.length,
9
+ h = seed ^ l,
10
+ i = 0,
11
+ k;
12
+ while (l >= 4) {
13
+ k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24;
14
+ k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16);
15
+ k ^= k >>> 24;
16
+ k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16);
17
+ h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16) ^ k;
18
+ l -= 4;
19
+ ++i;
20
+ }
21
+ switch (l) {
22
+ case 3:
23
+ h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
24
+ case 2:
25
+ h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
26
+ case 1:
27
+ h ^= str.charCodeAt(i) & 0xff;
28
+ h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16);
29
+ }
30
+ h ^= h >>> 13;
31
+ h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16);
32
+ h ^= h >>> 15;
33
+ return h >>> 0;
34
+ }
35
+ const hash = str => murmurhash2_32_gc(str, 1).toString(36);
36
+ var _default = exports.default = hash;
37
+ const base62Chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
38
+ function toBase62(num) {
39
+ let result = '';
40
+ let _num = num;
41
+ while (_num > 0) {
42
+ const remainder = _num % 62;
43
+ result = base62Chars[remainder] + result;
44
+ _num = Math.floor(_num / 62);
45
+ }
46
+ return result;
47
+ }
48
+ const createShortHash = str => toBase62(murmurhash2_32_gc(str, 1) % 62 ** 5);
49
+ exports.createShortHash = createShortHash;
@@ -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 (str: string) => string;
11
+
12
+ declare export const createShortHash: (str: string) => string;
@@ -0,0 +1,70 @@
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 illegalArgumentLength: (
11
+ fn: string,
12
+ argLength: number,
13
+ ) => string;
14
+ export declare type illegalArgumentLength = typeof illegalArgumentLength;
15
+ export declare const nonStaticValue: (fn: string) => string;
16
+ export declare type nonStaticValue = typeof nonStaticValue;
17
+ export declare const nonStyleObject: (fn: string) => string;
18
+ export declare type nonStyleObject = typeof nonStyleObject;
19
+ export declare const nonExportNamedDeclaration: (fn: string) => string;
20
+ export declare type nonExportNamedDeclaration =
21
+ typeof nonExportNamedDeclaration;
22
+ export declare const unboundCallValue: (fn: string) => string;
23
+ export declare type unboundCallValue = typeof unboundCallValue;
24
+ export declare const cannotGenerateHash: (fn: string) => string;
25
+ export declare type cannotGenerateHash = typeof cannotGenerateHash;
26
+ export declare const DUPLICATE_CONDITIONAL: 'The same pseudo selector or at-rule cannot be used more than once.';
27
+ export declare type DUPLICATE_CONDITIONAL = typeof DUPLICATE_CONDITIONAL;
28
+ export declare const ESCAPED_STYLEX_VALUE: 'Escaping a create() value is not allowed.';
29
+ export declare type ESCAPED_STYLEX_VALUE = typeof ESCAPED_STYLEX_VALUE;
30
+ export declare const ILLEGAL_NESTED_PSEUDO: "Pseudo objects can't be nested more than one level deep.";
31
+ export declare type ILLEGAL_NESTED_PSEUDO = typeof ILLEGAL_NESTED_PSEUDO;
32
+ export declare const ILLEGAL_PROP_VALUE: 'A style value can only contain an array, string or number.';
33
+ export declare type ILLEGAL_PROP_VALUE = typeof ILLEGAL_PROP_VALUE;
34
+ export declare const ILLEGAL_PROP_ARRAY_VALUE: 'A style array value can only contain strings or numbers.';
35
+ export declare type ILLEGAL_PROP_ARRAY_VALUE = typeof ILLEGAL_PROP_ARRAY_VALUE;
36
+ export declare const ILLEGAL_NAMESPACE_VALUE: 'A StyleX namespace must be an object.';
37
+ export declare type ILLEGAL_NAMESPACE_VALUE = typeof ILLEGAL_NAMESPACE_VALUE;
38
+ export declare const INVALID_CONST_KEY: 'Keys in defineConsts() cannot start with "--".';
39
+ export declare type INVALID_CONST_KEY = typeof INVALID_CONST_KEY;
40
+ export declare const INVALID_PSEUDO: 'Invalid pseudo selector, not on the whitelist.';
41
+ export declare type INVALID_PSEUDO = typeof INVALID_PSEUDO;
42
+ export declare const INVALID_PSEUDO_OR_AT_RULE: 'Invalid pseudo or at-rule.';
43
+ export declare type INVALID_PSEUDO_OR_AT_RULE =
44
+ typeof INVALID_PSEUDO_OR_AT_RULE;
45
+ export declare const INVALID_MEDIA_QUERY_SYNTAX: 'Invalid media query syntax.';
46
+ export declare type INVALID_MEDIA_QUERY_SYNTAX =
47
+ typeof INVALID_MEDIA_QUERY_SYNTAX;
48
+ export declare const LINT_UNCLOSED_FUNCTION: 'Rule contains an unclosed function';
49
+ export declare type LINT_UNCLOSED_FUNCTION = typeof LINT_UNCLOSED_FUNCTION;
50
+ export declare const LOCAL_ONLY: 'The return value of create() should not be exported.';
51
+ export declare type LOCAL_ONLY = typeof LOCAL_ONLY;
52
+ export declare const NON_OBJECT_KEYFRAME: 'Every frame within a keyframes() call must be an object.';
53
+ export declare type NON_OBJECT_KEYFRAME = typeof NON_OBJECT_KEYFRAME;
54
+ export declare const NON_CONTIGUOUS_VARS: 'All variables passed to firstThatWorks() must be contiguous.';
55
+ export declare type NON_CONTIGUOUS_VARS = typeof NON_CONTIGUOUS_VARS;
56
+ export declare const NO_OBJECT_SPREADS: 'Object spreads are not allowed in create() calls.';
57
+ export declare type NO_OBJECT_SPREADS = typeof NO_OBJECT_SPREADS;
58
+ export declare const ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS: 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
59
+ export declare type ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS =
60
+ typeof ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS;
61
+ export declare const ONLY_TOP_LEVEL: 'create() is only allowed at the root of a program.';
62
+ export declare type ONLY_TOP_LEVEL = typeof ONLY_TOP_LEVEL;
63
+ export declare const UNKNOWN_PROP_KEY: 'Unknown property key';
64
+ export declare type UNKNOWN_PROP_KEY = typeof UNKNOWN_PROP_KEY;
65
+ export declare const POSITION_TRY_INVALID_PROPERTY: 'Invalid property in `positionTry()` call. It may only contain, positionAnchor, positionArea, inset properties (top, left, insetInline etc.), margin properties, size properties (height, inlineSize, etc.), and self-alignment properties (alignSelf, justifySelf, placeSelf)';
66
+ export declare type POSITION_TRY_INVALID_PROPERTY =
67
+ typeof POSITION_TRY_INVALID_PROPERTY;
68
+ export declare const VIEW_TRANSITION_CLASS_INVALID_PROPERTY: 'Invalid property in `viewTransitionClass()` call. It may only contain group, imagePair, old, and new properties';
69
+ export declare type VIEW_TRANSITION_CLASS_INVALID_PROPERTY =
70
+ typeof VIEW_TRANSITION_CLASS_INVALID_PROPERTY;
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.unboundCallValue = exports.nonStyleObject = exports.nonStaticValue = exports.nonExportNamedDeclaration = exports.illegalArgumentLength = exports.cannotGenerateHash = exports.VIEW_TRANSITION_CLASS_INVALID_PROPERTY = exports.UNKNOWN_PROP_KEY = exports.POSITION_TRY_INVALID_PROPERTY = exports.ONLY_TOP_LEVEL = exports.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = exports.NO_OBJECT_SPREADS = exports.NON_OBJECT_KEYFRAME = exports.NON_CONTIGUOUS_VARS = exports.LOCAL_ONLY = exports.LINT_UNCLOSED_FUNCTION = exports.INVALID_PSEUDO_OR_AT_RULE = exports.INVALID_PSEUDO = exports.INVALID_MEDIA_QUERY_SYNTAX = exports.INVALID_CONST_KEY = exports.ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NAMESPACE_VALUE = exports.ESCAPED_STYLEX_VALUE = exports.DUPLICATE_CONDITIONAL = void 0;
7
+ const illegalArgumentLength = (fn, argLength) => `${fn}() should have ${argLength} argument${argLength === 1 ? '' : 's'}.`;
8
+ exports.illegalArgumentLength = illegalArgumentLength;
9
+ const nonStaticValue = fn => `Only static values are allowed inside of a ${fn}() call.`;
10
+ exports.nonStaticValue = nonStaticValue;
11
+ const nonStyleObject = fn => `${fn}() can only accept an object.`;
12
+ exports.nonStyleObject = nonStyleObject;
13
+ const nonExportNamedDeclaration = fn => `The return value of ${fn}() must be bound to a named export.`;
14
+ exports.nonExportNamedDeclaration = nonExportNamedDeclaration;
15
+ const unboundCallValue = fn => `${fn}() calls must be bound to a bare variable.`;
16
+ exports.unboundCallValue = unboundCallValue;
17
+ const cannotGenerateHash = fn => `Unable to generate hash for ${fn}(). Check that the file has a valid extension and that unstable_moduleResolution is configured.`;
18
+ exports.cannotGenerateHash = cannotGenerateHash;
19
+ const DUPLICATE_CONDITIONAL = exports.DUPLICATE_CONDITIONAL = 'The same pseudo selector or at-rule cannot be used more than once.';
20
+ const ESCAPED_STYLEX_VALUE = exports.ESCAPED_STYLEX_VALUE = 'Escaping a create() value is not allowed.';
21
+ const ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NESTED_PSEUDO = "Pseudo objects can't be nested more than one level deep.";
22
+ const ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_VALUE = 'A style value can only contain an array, string or number.';
23
+ const ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = 'A style array value can only contain strings or numbers.';
24
+ const ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_VALUE = 'A StyleX namespace must be an object.';
25
+ const INVALID_CONST_KEY = exports.INVALID_CONST_KEY = 'Keys in defineConsts() cannot start with "--".';
26
+ const INVALID_PSEUDO = exports.INVALID_PSEUDO = 'Invalid pseudo selector, not on the whitelist.';
27
+ const INVALID_PSEUDO_OR_AT_RULE = exports.INVALID_PSEUDO_OR_AT_RULE = 'Invalid pseudo or at-rule.';
28
+ const INVALID_MEDIA_QUERY_SYNTAX = exports.INVALID_MEDIA_QUERY_SYNTAX = 'Invalid media query syntax.';
29
+ const LINT_UNCLOSED_FUNCTION = exports.LINT_UNCLOSED_FUNCTION = 'Rule contains an unclosed function';
30
+ const LOCAL_ONLY = exports.LOCAL_ONLY = 'The return value of create() should not be exported.';
31
+ const NON_OBJECT_KEYFRAME = exports.NON_OBJECT_KEYFRAME = 'Every frame within a keyframes() call must be an object.';
32
+ const NON_CONTIGUOUS_VARS = exports.NON_CONTIGUOUS_VARS = 'All variables passed to firstThatWorks() must be contiguous.';
33
+ const NO_OBJECT_SPREADS = exports.NO_OBJECT_SPREADS = 'Object spreads are not allowed in create() calls.';
34
+ const ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = exports.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
35
+ const ONLY_TOP_LEVEL = exports.ONLY_TOP_LEVEL = 'create() is only allowed at the root of a program.';
36
+ const UNKNOWN_PROP_KEY = exports.UNKNOWN_PROP_KEY = 'Unknown property key';
37
+ const POSITION_TRY_INVALID_PROPERTY = exports.POSITION_TRY_INVALID_PROPERTY = 'Invalid property in `positionTry()` call. It may only contain, positionAnchor, positionArea, inset properties (top, left, insetInline etc.), margin properties, size properties (height, inlineSize, etc.), and self-alignment properties (alignSelf, justifySelf, placeSelf)';
38
+ const VIEW_TRANSITION_CLASS_INVALID_PROPERTY = exports.VIEW_TRANSITION_CLASS_INVALID_PROPERTY = 'Invalid property in `viewTransitionClass()` call. It may only contain group, imagePair, old, and new properties';
@@ -0,0 +1,44 @@
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
+ // This file contains constants to be used within Error messages.
11
+ // The URLs within will eventually be replaced by links to the documentation website for Stylex.
12
+
13
+ declare export const illegalArgumentLength: (
14
+ fn: string,
15
+ argLength: number,
16
+ ) => string;
17
+ declare export const nonStaticValue: (fn: string) => string;
18
+ declare export const nonStyleObject: (fn: string) => string;
19
+ declare export const nonExportNamedDeclaration: (fn: string) => string;
20
+ declare export const unboundCallValue: (fn: string) => string;
21
+ declare export const cannotGenerateHash: (fn: string) => string;
22
+
23
+ declare export const DUPLICATE_CONDITIONAL: 'The same pseudo selector or at-rule cannot be used more than once.';
24
+ declare export const ESCAPED_STYLEX_VALUE: 'Escaping a create() value is not allowed.';
25
+ declare export const ILLEGAL_NESTED_PSEUDO: "Pseudo objects can't be nested more than one level deep.";
26
+ declare export const ILLEGAL_PROP_VALUE: 'A style value can only contain an array, string or number.';
27
+ declare export const ILLEGAL_PROP_ARRAY_VALUE: 'A style array value can only contain strings or numbers.';
28
+ declare export const ILLEGAL_NAMESPACE_VALUE: 'A StyleX namespace must be an object.';
29
+ declare export const INVALID_CONST_KEY: 'Keys in defineConsts() cannot start with "--".';
30
+ declare export const INVALID_PSEUDO: 'Invalid pseudo selector, not on the whitelist.';
31
+ declare export const INVALID_PSEUDO_OR_AT_RULE: 'Invalid pseudo or at-rule.';
32
+ declare export const INVALID_MEDIA_QUERY_SYNTAX: 'Invalid media query syntax.';
33
+ declare export const LINT_UNCLOSED_FUNCTION: 'Rule contains an unclosed function';
34
+ declare export const LOCAL_ONLY: 'The return value of create() should not be exported.';
35
+ declare export const NON_OBJECT_KEYFRAME: 'Every frame within a keyframes() call must be an object.';
36
+ declare export const NON_CONTIGUOUS_VARS: 'All variables passed to firstThatWorks() must be contiguous.';
37
+ declare export const NO_OBJECT_SPREADS: 'Object spreads are not allowed in create() calls.';
38
+ declare export const ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS: 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
39
+ declare export const ONLY_TOP_LEVEL: 'create() is only allowed at the root of a program.';
40
+ declare export const UNKNOWN_PROP_KEY: 'Unknown property key';
41
+
42
+ declare export const POSITION_TRY_INVALID_PROPERTY: 'Invalid property in `positionTry()` call. It may only contain, positionAnchor, positionArea, inset properties (top, left, insetInline etc.), margin properties, size properties (height, inlineSize, etc.), and self-alignment properties (alignSelf, justifySelf, placeSelf)';
43
+
44
+ declare export const VIEW_TRANSITION_CLASS_INVALID_PROPERTY: 'Invalid property in `viewTransitionClass()` call. It may only contain group, imagePair, old, and new properties';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
10
+ import type { StyleXOptions } from '../common-types';
11
+ declare function generateLTR(
12
+ pair: Readonly<[string, string]>,
13
+ options?: StyleXOptions,
14
+ ): Readonly<[string, string]>;
15
+ export default generateLTR;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = generateLTR;
7
+ var _defaultOptions = require("../utils/default-options");
8
+ const logicalToPhysical = {
9
+ start: 'left',
10
+ end: 'right',
11
+ 'inline-start': 'left',
12
+ 'inline-end': 'right'
13
+ };
14
+ const inlinePropertyToLTR = {
15
+ 'margin-inline-start': ([_k, val]) => ['margin-left', val],
16
+ 'margin-inline-end': ([_k, val]) => ['margin-right', val],
17
+ 'padding-inline-start': ([_k, val]) => ['padding-left', val],
18
+ 'padding-inline-end': ([_k, val]) => ['padding-right', val],
19
+ 'border-inline-start': ([_k, val]) => ['border-left', val],
20
+ 'border-inline-end': ([_k, val]) => ['border-right', val],
21
+ 'border-inline-start-width': ([_k, val]) => ['border-left-width', val],
22
+ 'border-inline-end-width': ([_k, val]) => ['border-right-width', val],
23
+ 'border-inline-start-color': ([_key, val]) => ['border-left-color', val],
24
+ 'border-inline-end-color': ([_key, val]) => ['border-right-color', val],
25
+ 'border-inline-start-style': ([_key, val]) => ['border-left-style', val],
26
+ 'border-inline-end-style': ([_key, val]) => ['border-right-style', val],
27
+ 'border-start-start-radius': ([_key, val]) => ['border-top-left-radius', val],
28
+ 'border-end-start-radius': ([_k, val]) => ['border-bottom-left-radius', val],
29
+ 'border-start-end-radius': ([_key, val]) => ['border-top-right-radius', val],
30
+ 'border-end-end-radius': ([_key, val]) => ['border-bottom-right-radius', val],
31
+ 'inset-inline-start': ([_key, val]) => ['left', val],
32
+ 'inset-inline-end': ([_key, val]) => ['right', val]
33
+ };
34
+ const propertyToLTR = {
35
+ 'margin-start': ([_key, val]) => ['margin-left', val],
36
+ 'margin-end': ([_key, val]) => ['margin-right', val],
37
+ 'padding-start': ([_key, val]) => ['padding-left', val],
38
+ 'padding-end': ([_key, val]) => ['padding-right', val],
39
+ 'border-start': ([_key, val]) => ['border-left', val],
40
+ 'border-end': ([_key, val]) => ['border-right', val],
41
+ 'border-start-width': ([_key, val]) => ['border-left-width', val],
42
+ 'border-end-width': ([_key, val]) => ['border-right-width', val],
43
+ 'border-start-color': ([_key, val]) => ['border-left-color', val],
44
+ 'border-end-color': ([_key, val]) => ['border-right-color', val],
45
+ 'border-start-style': ([_key, val]) => ['border-left-style', val],
46
+ 'border-end-style': ([_key, val]) => ['border-right-style', val],
47
+ 'border-top-start-radius': ([_key, val]) => ['border-top-left-radius', val],
48
+ 'border-bottom-start-radius': ([_k, v]) => ['border-bottom-left-radius', v],
49
+ 'border-top-end-radius': ([_key, v]) => ['border-top-right-radius', v],
50
+ 'border-bottom-end-radius': ([_k, v]) => ['border-bottom-right-radius', v],
51
+ float: ([key, val]) => [key, logicalToPhysical[val] ?? val],
52
+ clear: ([key, val]) => [key, logicalToPhysical[val] ?? val],
53
+ start: ([_k, val]) => ['left', val],
54
+ end: ([_k, val]) => ['right', val],
55
+ 'background-position': ([key, val]) => [key, val.split(' ').map(word => word === 'start' || word === 'insetInlineStart' ? 'left' : word === 'end' || word === 'insetInlineEnd' ? 'right' : word).join(' ')]
56
+ };
57
+ function generateLTR(pair, options = _defaultOptions.defaultOptions) {
58
+ const {
59
+ enableLogicalStylesPolyfill,
60
+ styleResolution
61
+ } = options;
62
+ const [key] = pair;
63
+ if (styleResolution === 'legacy-expand-shorthands') {
64
+ if (!enableLogicalStylesPolyfill) {
65
+ return pair;
66
+ }
67
+ if (inlinePropertyToLTR[key]) {
68
+ return inlinePropertyToLTR[key](pair);
69
+ }
70
+ }
71
+ if (!propertyToLTR[key]) {
72
+ return pair;
73
+ }
74
+ return propertyToLTR[key](pair);
75
+ }
@@ -0,0 +1,14 @@
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 { StyleXOptions } from '../common-types';
11
+ declare export default function generateLTR(
12
+ pair: $ReadOnly<[string, string]>,
13
+ options?: StyleXOptions,
14
+ ): $ReadOnly<[string, string]>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
10
+ import type { StyleXOptions } from '../common-types';
11
+ declare function generateRTL(
12
+ pair: Readonly<[string, string]>,
13
+ options?: StyleXOptions,
14
+ ): null | undefined | Readonly<[string, string]>;
15
+ export default generateRTL;