@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,100 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._flattenRawStyleObject = _flattenRawStyleObject;
7
+ exports.flattenRawStyleObject = flattenRawStyleObject;
8
+ var _index = _interopRequireDefault(require("./index"));
9
+ var _styleValueParser = require("style-value-parser");
10
+ var messages = _interopRequireWildcard(require("../messages"));
11
+ var _PreRule = require("./PreRule");
12
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ function flattenRawStyleObject(style, options) {
15
+ let processedStyle = style;
16
+ try {
17
+ processedStyle = options.enableMediaQueryOrder ? (0, _styleValueParser.lastMediaQueryWinsTransform)(style) : style;
18
+ } catch (error) {
19
+ throw new Error(messages.INVALID_MEDIA_QUERY_SYNTAX);
20
+ }
21
+ return _flattenRawStyleObject(processedStyle, [], options);
22
+ }
23
+ function _flattenRawStyleObject(style, keyPath, options) {
24
+ const flattened = [];
25
+ for (const _key in style) {
26
+ const value = style[_key];
27
+ const key = _key.match(/var\(--[a-z0-9]+\)/) ? _key.slice(4, -1) : _key;
28
+ if (value === null || typeof value === 'string' || typeof value === 'number') {
29
+ const pairs = (0, _index.default)([key, value], options);
30
+ for (const [property, value] of pairs) {
31
+ if (value === null) {
32
+ flattened.push([property, new _PreRule.NullPreRule()]);
33
+ } else {
34
+ flattened.push([property, new _PreRule.PreRule(property, value, keyPath.includes(key) ? keyPath.map(k => k === key ? property : k) : [...keyPath, property])]);
35
+ }
36
+ }
37
+ continue;
38
+ }
39
+ if (Array.isArray(value)) {
40
+ const equivalentPairs = {};
41
+ for (const eachVal of value) {
42
+ const pairs = (0, _index.default)([key, eachVal], options);
43
+ for (const [property, val] of pairs) {
44
+ if (Array.isArray(val)) {
45
+ if (equivalentPairs[property] == null) {
46
+ equivalentPairs[property] = [...val];
47
+ } else {
48
+ equivalentPairs[property].push(...val);
49
+ }
50
+ } else if (equivalentPairs[property] == null) {
51
+ equivalentPairs[property] = [val];
52
+ } else {
53
+ equivalentPairs[property].push(val);
54
+ }
55
+ }
56
+ }
57
+ Object.entries(equivalentPairs).map(([property, values]) => [property, [...new Set(values.filter(Boolean))]]).map(([property, values]) => [property, values.length === 0 ? null : values.length === 1 ? values[0] : values]).forEach(([property, value]) => {
58
+ if (value === null) {
59
+ flattened.push([property, new _PreRule.NullPreRule()]);
60
+ } else {
61
+ flattened.push([property, new _PreRule.PreRule(property, value, keyPath.includes(_key) ? keyPath.map(k => k === _key ? property : k) : [...keyPath, property])]);
62
+ }
63
+ });
64
+ continue;
65
+ }
66
+ if (typeof value === 'object' && !key.startsWith(':') && !key.startsWith('@') && !key.startsWith('[')) {
67
+ const equivalentPairs = {};
68
+ for (const condition in value) {
69
+ const innerValue = value[condition];
70
+ const pairs = _flattenRawStyleObject({
71
+ [key]: innerValue
72
+ }, keyPath.length > 0 ? [...keyPath, condition] : [key, condition], options);
73
+ for (const [property, preRule] of pairs) {
74
+ if (equivalentPairs[property] == null) {
75
+ equivalentPairs[property] = {
76
+ [condition]: preRule
77
+ };
78
+ } else {
79
+ equivalentPairs[property][condition] = preRule;
80
+ }
81
+ }
82
+ }
83
+ for (const [property, obj] of Object.entries(equivalentPairs)) {
84
+ const sortedKeys = Object.keys(obj);
85
+ const rules = [];
86
+ for (const condition of sortedKeys) {
87
+ rules.push(obj[condition]);
88
+ }
89
+ flattened.push([property, _PreRule.PreRuleSet.create(rules)]);
90
+ }
91
+ }
92
+ if (typeof value === 'object' && (key.startsWith(':') || key.startsWith('@') || key.startsWith('['))) {
93
+ const pairs = _flattenRawStyleObject(value, [...keyPath, _key], options);
94
+ for (const [property, preRule] of pairs) {
95
+ flattened.push([key + '_' + property, preRule]);
96
+ }
97
+ }
98
+ }
99
+ return flattened;
100
+ }
@@ -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 { RawStyles, StyleXOptions } from '../common-types';
11
+
12
+ import { type AnyPreRule, type IPreRule } from './PreRule';
13
+
14
+ declare export function flattenRawStyleObject(
15
+ style: RawStyles,
16
+ options: StyleXOptions,
17
+ ): $ReadOnlyArray<$ReadOnly<[string, IPreRule]>>;
18
+
19
+ declare export function _flattenRawStyleObject(
20
+ style: RawStyles,
21
+ keyPath: $ReadOnlyArray<string>,
22
+ options: StyleXOptions,
23
+ ): Array<$ReadOnly<[string, AnyPreRule]>>;
@@ -0,0 +1,21 @@
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, TStyleValue } from '../common-types';
11
+ export declare function getExpandedKeys(
12
+ options: StyleXOptions,
13
+ ): ReadonlyArray<string>;
14
+ declare function flatMapExpandedShorthands(
15
+ objEntry: Readonly<[string, TStyleValue]>,
16
+ options: Readonly<{
17
+ styleResolution: StyleXOptions['styleResolution'];
18
+ propertyValidationMode?: StyleXOptions['propertyValidationMode'];
19
+ }>,
20
+ ): ReadonlyArray<[string, TStyleValue]>;
21
+ export default flatMapExpandedShorthands;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = flatMapExpandedShorthands;
7
+ exports.getExpandedKeys = getExpandedKeys;
8
+ var _applicationOrder = _interopRequireDefault(require("./application-order"));
9
+ var _legacyExpandShorthands = _interopRequireDefault(require("./legacy-expand-shorthands"));
10
+ var _propertySpecificity = _interopRequireDefault(require("./property-specificity"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ const expansions = {
13
+ 'application-order': _applicationOrder.default,
14
+ 'property-specificity': _propertySpecificity.default,
15
+ 'legacy-expand-shorthands': _legacyExpandShorthands.default
16
+ };
17
+ function getExpandedKeys(options) {
18
+ return Object.keys(expansions[options.styleResolution ?? 'property-specificity']);
19
+ }
20
+ function flatMapExpandedShorthands(objEntry, options) {
21
+ let [key, value] = objEntry;
22
+ if (key.startsWith('var(') && key.endsWith(')')) {
23
+ key = key.slice(4, -1);
24
+ }
25
+ const expansion = expansions[options.styleResolution ?? 'property-specificity'][key];
26
+ if (expansion) {
27
+ if (Array.isArray(value)) {
28
+ throw new Error('Cannot use fallbacks for shorthands. Use the expansion instead.');
29
+ }
30
+ try {
31
+ return expansion(value);
32
+ } catch (error) {
33
+ const validationMode = options.propertyValidationMode ?? 'silent';
34
+ if (validationMode === 'throw') {
35
+ throw error;
36
+ } else if (validationMode === 'warn') {
37
+ console.warn(`[stylex] ${error.message}`);
38
+ return [];
39
+ } else {
40
+ return [];
41
+ }
42
+ }
43
+ }
44
+ return [[key, value]];
45
+ }
@@ -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 { StyleXOptions, TStyleValue } from '../common-types';
11
+
12
+ declare export function getExpandedKeys(
13
+ options: StyleXOptions,
14
+ ): $ReadOnlyArray<string>;
15
+
16
+ declare export default function flatMapExpandedShorthands(
17
+ objEntry: $ReadOnly<[string, TStyleValue]>,
18
+ options: $ReadOnly<{
19
+ styleResolution: StyleXOptions['styleResolution'],
20
+ propertyValidationMode?: StyleXOptions['propertyValidationMode'],
21
+ ...
22
+ }>,
23
+ ): $ReadOnlyArray<[string, TStyleValue]>;
@@ -0,0 +1,170 @@
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 { TStyleValue } from '../common-types';
11
+ export declare const LOGICAL_FLOAT_START_VAR: '--stylex-logical-start';
12
+ export declare type LOGICAL_FLOAT_START_VAR = typeof LOGICAL_FLOAT_START_VAR;
13
+ export declare const LOGICAL_FLOAT_END_VAR: '--stylex-logical-end';
14
+ export declare type LOGICAL_FLOAT_END_VAR = typeof LOGICAL_FLOAT_END_VAR;
15
+ /**
16
+ * Shorthand properties:
17
+ * - [x] all - Should be banned
18
+ * - [ ] animation
19
+ * - [ ] background
20
+ * - [-] border
21
+ * - [x] border-block-end
22
+ * - [x] border-block-start
23
+ * - [ ] border-bottom
24
+ * - [x] border-color
25
+ * - [x] border-image
26
+ * - [x] border-inline-end
27
+ * - [x] border-inline-start
28
+ * - [ ] border-left
29
+ * - [x] border-radius
30
+ * - [ ] corner-shape
31
+ * - [ ] border-right
32
+ * - [x] border-style
33
+ * - [ ] border-top
34
+ * - [x] border-width
35
+ * - [ ] column-rule
36
+ * - [ ] columns
37
+ * - [ ] flex
38
+ * - [ ] flex-flow
39
+ * - [ ] font
40
+ * - [ ] gap
41
+ * - [ ] grid
42
+ * - [ ] grid-area
43
+ * - [ ] grid-column
44
+ * - [ ] grid-row
45
+ * - [ ] grid-template
46
+ * - [ ] list-style
47
+ * - [x] margin
48
+ * - [ ] mask
49
+ * - [ ] offset
50
+ * - [ ] outline
51
+ * - [x] overflow
52
+ * - [x] padding
53
+ * - [ ] place-content
54
+ * - [ ] place-items
55
+ * - [ ] place-self
56
+ * - [ ] scroll-margin
57
+ * - [ ] scroll-padding
58
+ * - [ ] text-decoration
59
+ * - [ ] text-emphasis
60
+ * - [ ] transition
61
+ */
62
+
63
+ /**
64
+ * Shorthand properties:
65
+ * - [x] all - Should be banned
66
+ * - [ ] animation
67
+ * - [ ] background
68
+ * - [-] border
69
+ * - [x] border-block-end
70
+ * - [x] border-block-start
71
+ * - [ ] border-bottom
72
+ * - [x] border-color
73
+ * - [x] border-image
74
+ * - [x] border-inline-end
75
+ * - [x] border-inline-start
76
+ * - [ ] border-left
77
+ * - [x] border-radius
78
+ * - [ ] corner-shape
79
+ * - [ ] border-right
80
+ * - [x] border-style
81
+ * - [ ] border-top
82
+ * - [x] border-width
83
+ * - [ ] column-rule
84
+ * - [ ] columns
85
+ * - [ ] flex
86
+ * - [ ] flex-flow
87
+ * - [ ] font
88
+ * - [ ] gap
89
+ * - [ ] grid
90
+ * - [ ] grid-area
91
+ * - [ ] grid-column
92
+ * - [ ] grid-row
93
+ * - [ ] grid-template
94
+ * - [ ] list-style
95
+ * - [x] margin
96
+ * - [ ] mask
97
+ * - [ ] offset
98
+ * - [ ] outline
99
+ * - [x] overflow
100
+ * - [x] padding
101
+ * - [ ] place-content
102
+ * - [ ] place-items
103
+ * - [ ] place-self
104
+ * - [ ] scroll-margin
105
+ * - [ ] scroll-padding
106
+ * - [ ] text-decoration
107
+ * - [ ] text-emphasis
108
+ * - [ ] transition
109
+ */
110
+
111
+ type TReturn = ReadonlyArray<[string, TStyleValue]>;
112
+ declare const shorthands: Readonly<{
113
+ [key: string]: ($$PARAM_0$$: TStyleValue) => TReturn;
114
+ }>;
115
+ declare const aliases: {
116
+ insetBlockStart: (val: TStyleValue) => TReturn;
117
+ insetBlockEnd: (val: TStyleValue) => TReturn;
118
+ insetInlineStart: typeof shorthands.start;
119
+ insetInlineEnd: typeof shorthands.end;
120
+ blockSize: (val: TStyleValue) => TReturn;
121
+ inlineSize: (val: TStyleValue) => TReturn;
122
+ minBlockSize: (val: TStyleValue) => TReturn;
123
+ minInlineSize: (val: TStyleValue) => TReturn;
124
+ maxBlockSize: (val: TStyleValue) => TReturn;
125
+ maxInlineSize: (val: TStyleValue) => TReturn;
126
+ borderStart: (val: TStyleValue) => TReturn;
127
+ borderEnd: (val: TStyleValue) => TReturn;
128
+ borderBlockWidth: typeof shorthands.borderVerticalWidth;
129
+ borderBlockStyle: typeof shorthands.borderVerticalStyle;
130
+ borderBlockColor: typeof shorthands.borderVerticalColor;
131
+ borderBlockStartWidth: (val: TStyleValue) => TReturn;
132
+ borderBlockStartStyle: (val: TStyleValue) => TReturn;
133
+ borderBlockStartColor: (val: TStyleValue) => TReturn;
134
+ borderBlockEndWidth: (val: TStyleValue) => TReturn;
135
+ borderBlockEndStyle: (val: TStyleValue) => TReturn;
136
+ borderBlockEndColor: (val: TStyleValue) => TReturn;
137
+ borderInlineWidth: typeof shorthands.borderHorizontalWidth;
138
+ borderInlineStyle: typeof shorthands.borderHorizontalStyle;
139
+ borderInlineColor: typeof shorthands.borderHorizontalColor;
140
+ borderTopStartRadius: (val: TStyleValue) => TReturn;
141
+ borderTopEndRadius: (val: TStyleValue) => TReturn;
142
+ borderBottomStartRadius: (val: TStyleValue) => TReturn;
143
+ borderBottomEndRadius: (val: TStyleValue) => TReturn;
144
+ gridGap: typeof shorthands.gap;
145
+ gridRowGap: (value: TStyleValue) => TReturn;
146
+ gridColumnGap: (value: TStyleValue) => TReturn;
147
+ marginBlock: typeof shorthands.marginVertical;
148
+ marginBlockStart: (val: TStyleValue) => TReturn;
149
+ marginBlockEnd: (val: TStyleValue) => TReturn;
150
+ marginInline: typeof shorthands.marginHorizontal;
151
+ overflowBlock: (value: TStyleValue) => TReturn;
152
+ overflowInline: (value: TStyleValue) => TReturn;
153
+ paddingBlock: typeof shorthands.paddingVertical;
154
+ paddingBlockStart: (val: TStyleValue) => TReturn;
155
+ paddingBlockEnd: (val: TStyleValue) => TReturn;
156
+ paddingInline: typeof shorthands.paddingHorizontal;
157
+ scrollMarginBlockStart: (value: TStyleValue) => TReturn;
158
+ scrollMarginBlockEnd: (value: TStyleValue) => TReturn;
159
+ float: (value: TStyleValue) => TReturn;
160
+ clear: (value: TStyleValue) => TReturn;
161
+ };
162
+ declare const expansions: Omit<
163
+ typeof shorthands,
164
+ keyof typeof aliases | keyof {}
165
+ > &
166
+ Omit<typeof aliases, keyof {}> & {};
167
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: typeof expansions;
168
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
169
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
170
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.LOGICAL_FLOAT_START_VAR = exports.LOGICAL_FLOAT_END_VAR = void 0;
7
+ var _splitCssValue = _interopRequireDefault(require("../utils/split-css-value"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ const LOGICAL_FLOAT_START_VAR = exports.LOGICAL_FLOAT_START_VAR = '--stylex-logical-start';
10
+ const LOGICAL_FLOAT_END_VAR = exports.LOGICAL_FLOAT_END_VAR = '--stylex-logical-end';
11
+ const listStyleGlobalValues = new Set(['inherit', 'initial', 'revert', 'unset']);
12
+ const listStylePositionValues = new Set(['inside', 'outside']);
13
+ const listStyleTypeRegex = /^([a-z-]+|".*?"|'.*?')$/;
14
+ const shorthands = {
15
+ border: rawValue => {
16
+ return [['borderTop', rawValue], ['borderInlineEnd', rawValue], ['borderBottom', rawValue], ['borderInlineStart', rawValue]];
17
+ },
18
+ borderColor: rawValue => {
19
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
20
+ return [['borderTopColor', top], ['borderInlineEndColor', right], ['borderBottomColor', bottom], ['borderInlineStartColor', left]];
21
+ },
22
+ borderHorizontal: rawValue => {
23
+ return [['borderInlineStart', rawValue], ['borderInlineEnd', rawValue]];
24
+ },
25
+ borderStyle: rawValue => {
26
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
27
+ return [['borderTopStyle', top], ['borderInlineEndStyle', right], ['borderBottomStyle', bottom], ['borderInlineStartStyle', left]];
28
+ },
29
+ borderVertical: rawValue => {
30
+ return [['borderTop', rawValue], ['borderBottom', rawValue]];
31
+ },
32
+ borderWidth: rawValue => {
33
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
34
+ return [['borderTopWidth', top], ['borderInlineEndWidth', right], ['borderBottomWidth', bottom], ['borderInlineStartWidth', left]];
35
+ },
36
+ borderHorizontalColor: rawValue => [['borderInlineStartColor', rawValue], ['borderInlineEndColor', rawValue]],
37
+ borderHorizontalStyle: rawValue => [['borderInlineStartStyle', rawValue], ['borderInlineEndStyle', rawValue]],
38
+ borderHorizontalWidth: rawValue => [['borderInlineStartWidth', rawValue], ['borderInlineEndWidth', rawValue]],
39
+ borderVerticalColor: rawValue => [['borderTopColor', rawValue], ['borderBottomColor', rawValue]],
40
+ borderVerticalStyle: rawValue => [['borderTopStyle', rawValue], ['borderBottomStyle', rawValue]],
41
+ borderVerticalWidth: rawValue => [['borderTopWidth', rawValue], ['borderBottomWidth', rawValue]],
42
+ borderRadius: rawValue => {
43
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
44
+ return [['borderStartStartRadius', top], ['borderStartEndRadius', right], ['borderEndEndRadius', bottom], ['borderEndStartRadius', left]];
45
+ },
46
+ containIntrinsicSize: rawValue => {
47
+ const parts = (0, _splitCssValue.default)(rawValue);
48
+ const [width, height = width] = parts.reduce((coll, part) => {
49
+ const lastElement = coll[coll.length - 1];
50
+ if (lastElement === 'auto' && part != null) {
51
+ return [...coll.slice(0, -1), `auto ${part}`];
52
+ }
53
+ return [...coll, part];
54
+ }, []);
55
+ return [['containIntrinsicWidth', width], ['containIntrinsicHeight', height]];
56
+ },
57
+ inset: rawValue => {
58
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
59
+ return [['top', top], ['insetInlineEnd', right], ['bottom', bottom], ['insetInlineStart', left]];
60
+ },
61
+ insetInline: rawValue => {
62
+ const [start, end = start] = (0, _splitCssValue.default)(rawValue);
63
+ return [...shorthands.start(start), ...shorthands.end(end)];
64
+ },
65
+ insetBlock: rawValue => {
66
+ const [top, bottom = top] = (0, _splitCssValue.default)(rawValue);
67
+ return [['top', top], ['bottom', bottom]];
68
+ },
69
+ start: rawValue => [['insetInlineStart', rawValue], ['left', null], ['right', null]],
70
+ end: rawValue => [['insetInlineEnd', rawValue], ['left', null], ['right', null]],
71
+ left: rawValue => [['left', rawValue], ['insetInlineStart', null], ['insetInlineEnd', null]],
72
+ right: rawValue => [['right', rawValue], ['insetInlineStart', null], ['insetInlineEnd', null]],
73
+ gap: rawValue => {
74
+ const [row, column = row] = (0, _splitCssValue.default)(rawValue);
75
+ return [['rowGap', row], ['columnGap', column]];
76
+ },
77
+ listStyle: rawValue => {
78
+ if (rawValue == null) {
79
+ return [['listStyleType', null], ['listStylePosition', null], ['listStyleImage', null]];
80
+ }
81
+ const parts = (0, _splitCssValue.default)(rawValue);
82
+ let image = null;
83
+ let position = null;
84
+ let type = null;
85
+ if (parts.length === 1 && parts[0] != null && typeof parts[0] === 'string' && listStyleGlobalValues.has(parts[0])) {
86
+ const globalValue = parts[0];
87
+ return [['listStyleType', globalValue], ['listStylePosition', globalValue], ['listStyleImage', globalValue]];
88
+ }
89
+ const remainingParts = [];
90
+ for (const part of parts) {
91
+ if (part == null || typeof part !== 'string') continue;
92
+ if (listStyleGlobalValues.has(part) || part.includes('var(--')) {
93
+ throw new Error(`invalid "listStyle" value of "${JSON.stringify(rawValue)}"`);
94
+ } else if (listStylePositionValues.has(part)) {
95
+ if (position != null) {
96
+ throw new Error(`invalid "listStyle" value of ${JSON.stringify(rawValue)}`);
97
+ }
98
+ position = part;
99
+ } else if (part !== 'none' && listStyleTypeRegex.test(part)) {
100
+ if (type != null) {
101
+ throw new Error(`invalid "listStyle" value of ${JSON.stringify(rawValue)}`);
102
+ }
103
+ type = part;
104
+ } else {
105
+ remainingParts.push(part);
106
+ }
107
+ }
108
+ for (const part of remainingParts) {
109
+ if (part === 'none' && type == null) {
110
+ type = part;
111
+ } else {
112
+ if (image != null) {
113
+ throw new Error(`invalid "listStyle" value of ${JSON.stringify(rawValue)}`);
114
+ }
115
+ image = part;
116
+ }
117
+ }
118
+ return [['listStyleType', type], ['listStylePosition', position], ['listStyleImage', image]];
119
+ },
120
+ margin: rawValue => {
121
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
122
+ return [['marginTop', top], ['marginInlineEnd', right], ['marginBottom', bottom], ['marginInlineStart', left]];
123
+ },
124
+ marginHorizontal: rawValue => {
125
+ const [start, end = start] = (0, _splitCssValue.default)(rawValue);
126
+ return [...shorthands.marginStart(start), ...shorthands.marginEnd(end)];
127
+ },
128
+ marginStart: rawValue => [['marginInlineStart', rawValue], ['marginLeft', null], ['marginRight', null]],
129
+ marginEnd: rawValue => [['marginInlineEnd', rawValue], ['marginLeft', null], ['marginRight', null]],
130
+ marginLeft: rawValue => [['marginLeft', rawValue], ['marginInlineStart', null], ['marginInlineEnd', null]],
131
+ marginRight: rawValue => [['marginRight', rawValue], ['marginInlineStart', null], ['marginInlineEnd', null]],
132
+ marginVertical: rawValue => {
133
+ const [top, bottom = top] = (0, _splitCssValue.default)(rawValue);
134
+ return [['marginTop', top], ['marginBottom', bottom]];
135
+ },
136
+ overflow: rawValue => {
137
+ const [x, y = x] = (0, _splitCssValue.default)(rawValue);
138
+ return [['overflowX', x], ['overflowY', y]];
139
+ },
140
+ padding: rawValue => {
141
+ const [top, right = top, bottom = top, left = right] = (0, _splitCssValue.default)(rawValue);
142
+ return [['paddingTop', top], ['paddingInlineEnd', right], ['paddingBottom', bottom], ['paddingInlineStart', left]];
143
+ },
144
+ paddingHorizontal: val => {
145
+ const [start, end = start] = (0, _splitCssValue.default)(val);
146
+ return [...shorthands.paddingStart(start), ...shorthands.paddingEnd(end)];
147
+ },
148
+ paddingStart: val => [['paddingInlineStart', val], ['paddingLeft', null], ['paddingRight', null]],
149
+ paddingEnd: val => [['paddingInlineEnd', val], ['paddingLeft', null], ['paddingRight', null]],
150
+ paddingLeft: val => [['paddingLeft', val], ['paddingInlineStart', null], ['paddingInlineEnd', null]],
151
+ paddingRight: val => [['paddingRight', val], ['paddingInlineStart', null], ['paddingInlineEnd', null]],
152
+ paddingVertical: val => {
153
+ const [top, bottom = top] = (0, _splitCssValue.default)(val);
154
+ return [['paddingTop', top], ['paddingBottom', bottom]];
155
+ }
156
+ };
157
+ const aliases = {
158
+ insetBlockStart: val => [['top', val]],
159
+ insetBlockEnd: val => [['bottom', val]],
160
+ insetInlineStart: shorthands.start,
161
+ insetInlineEnd: shorthands.end,
162
+ blockSize: val => [['height', val]],
163
+ inlineSize: val => [['width', val]],
164
+ minBlockSize: val => [['minHeight', val]],
165
+ minInlineSize: val => [['minWidth', val]],
166
+ maxBlockSize: val => [['maxHeight', val]],
167
+ maxInlineSize: val => [['maxWidth', val]],
168
+ borderStart: val => [['borderInlineStart', val]],
169
+ borderEnd: val => [['borderInlineEnd', val]],
170
+ borderBlockWidth: shorthands.borderVerticalWidth,
171
+ borderBlockStyle: shorthands.borderVerticalStyle,
172
+ borderBlockColor: shorthands.borderVerticalColor,
173
+ borderBlockStartWidth: val => [['borderTopWidth', val]],
174
+ borderBlockStartStyle: val => [['borderTopStyle', val]],
175
+ borderBlockStartColor: val => [['borderTopColor', val]],
176
+ borderBlockEndWidth: val => [['borderBottomWidth', val]],
177
+ borderBlockEndStyle: val => [['borderBottomStyle', val]],
178
+ borderBlockEndColor: val => [['borderBottomColor', val]],
179
+ borderInlineWidth: shorthands.borderHorizontalWidth,
180
+ borderInlineStyle: shorthands.borderHorizontalStyle,
181
+ borderInlineColor: shorthands.borderHorizontalColor,
182
+ borderTopStartRadius: val => [['borderStartStartRadius', val]],
183
+ borderTopEndRadius: val => [['borderStartEndRadius', val]],
184
+ borderBottomStartRadius: val => [['borderEndStartRadius', val]],
185
+ borderBottomEndRadius: val => [['borderEndEndRadius', val]],
186
+ gridGap: shorthands.gap,
187
+ gridRowGap: value => [['rowGap', value]],
188
+ gridColumnGap: value => [['columnGap', value]],
189
+ marginBlock: shorthands.marginVertical,
190
+ marginBlockStart: val => [['marginTop', val]],
191
+ marginBlockEnd: val => [['marginBottom', val]],
192
+ marginInline: shorthands.marginHorizontal,
193
+ overflowBlock: value => [['overflowY', value]],
194
+ overflowInline: value => [['overflowX', value]],
195
+ paddingBlock: shorthands.paddingVertical,
196
+ paddingBlockStart: val => [['paddingTop', val]],
197
+ paddingBlockEnd: val => [['paddingBottom', val]],
198
+ paddingInline: shorthands.paddingHorizontal,
199
+ scrollMarginBlockStart: value => [['scrollMarginTop', value]],
200
+ scrollMarginBlockEnd: value => [['scrollMarginBottom', value]],
201
+ float: value => {
202
+ if (value === 'inline-start' || value === 'start') {
203
+ return [['float', `var(${LOGICAL_FLOAT_START_VAR})`]];
204
+ } else if (value === 'inline-end' || value === 'end') {
205
+ return [['float', `var(${LOGICAL_FLOAT_END_VAR})`]];
206
+ }
207
+ return [['float', value]];
208
+ },
209
+ clear: value => {
210
+ if (value === 'inline-start' || value === 'start') {
211
+ return [['clear', `var(${LOGICAL_FLOAT_START_VAR})`]];
212
+ } else if (value === 'inline-end' || value === 'end') {
213
+ return [['clear', `var(${LOGICAL_FLOAT_END_VAR})`]];
214
+ }
215
+ return [['clear', value]];
216
+ }
217
+ };
218
+ const expansions = {
219
+ ...shorthands,
220
+ ...aliases
221
+ };
222
+ var _default = exports.default = expansions;