@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
@@ -11,35 +11,19 @@ var _generateRtl = _interopRequireDefault(require("./physical-rtl/generate-rtl")
11
11
  var _transformValue = _interopRequireDefault(require("./transform-value"));
12
12
  var _dashify = _interopRequireDefault(require("./utils/dashify"));
13
13
  var _objectUtils = require("./utils/object-utils");
14
+ var _defaultOptions = require("./utils/default-options");
14
15
  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
- // Similar to `stylex.create` it takes an object of keyframes
25
- // and returns a string after hashing it.
26
- //
27
- // It also expands shorthand properties to maintain parity with
28
- // `stylex.create`.
29
16
  function styleXKeyframes(frames) {
30
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaultOptions.defaultOptions;
31
18
  const {
32
- stylexSheetName = '<>',
33
19
  classNamePrefix = 'x'
34
20
  } = options;
35
- const expandedObject = (0, _objectUtils.objMap)(frames, frame => _objectUtils.Pipe.create(frame).pipe(frame => expandFrameShorthands(frame, options)).pipe(x => (0, _objectUtils.objMapKeys)(x, _dashify.default)).pipe(x => (0, _objectUtils.objMap)(x, (value, key) => (0, _transformValue.default)(key, value))).done());
21
+ const expandedObject = (0, _objectUtils.objMap)(frames, frame => _objectUtils.Pipe.create(frame).pipe(frame => expandFrameShorthands(frame, options)).pipe(x => (0, _objectUtils.objMapKeys)(x, _dashify.default)).pipe(x => (0, _objectUtils.objMap)(x, (value, key) => (0, _transformValue.default)(key, value, options))).done());
36
22
  const ltrStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, _generateLtr.default));
37
23
  const rtlStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, entry => (0, _generateRtl.default)(entry) ?? entry));
38
24
  const ltrString = constructKeyframesObj(ltrStyles);
39
25
  const rtlString = constructKeyframesObj(rtlStyles);
40
-
41
- // This extra `-B` is kept for some idiosyncratic legacy compatibility for now.
42
- const animationName = classNamePrefix + (0, _hash.default)(stylexSheetName + ltrString) + '-B';
26
+ const animationName = classNamePrefix + (0, _hash.default)('<>' + ltrString) + '-B';
43
27
  const ltr = `@keyframes ${animationName}{${ltrString}}`;
44
28
  const rtl = ltrString === rtlString ? null : `@keyframes ${animationName}{${rtlString}}`;
45
29
  return [animationName, {
@@ -55,15 +39,11 @@ function expandFrameShorthands(frame, options) {
55
39
  return [key, value];
56
40
  }
57
41
  return null;
58
- }).filter(Boolean))
59
- // Keyframes are not combined. The nulls can be skipped
60
- .filter(_ref2 => {
61
- let [key, value] = _ref2;
42
+ }).filter(Boolean)).filter(_ref2 => {
43
+ let [_key, value] = _ref2;
62
44
  return value != null;
63
45
  }));
64
46
  }
65
-
66
- // Create t
67
47
  function constructKeyframesObj(frames) {
68
48
  return (0, _objectUtils.objEntries)(frames).map(_ref3 => {
69
49
  let [key, value] = _ref3;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
+
12
+ // Similar to `stylex.create` it takes an object of keyframes
13
+ // and returns a string after hashing it.
14
+ //
15
+ // It also expands shorthand properties to maintain parity with
16
+ // `stylex.create`.
17
+ declare export default function styleXKeyframes(
18
+ frames: { +[string]: { +[string]: string | number } },
19
+ options: StyleXOptions,
20
+ ): [string, InjectableStyle];
@@ -0,0 +1,22 @@
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
+ /**
12
+ * Convert a CSS value in JS to the final CSS string value
13
+ */
14
+ declare function transformValue(
15
+ key: string,
16
+ rawValue: string | number,
17
+ options: StyleXOptions,
18
+ ): string;
19
+ export default transformValue;
20
+ export declare function getNumberSuffix(key: string): string;
21
+ export declare const timeUnits: Set<string>;
22
+ export declare const lengthUnits: Set<string>;
@@ -4,25 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = transformValue;
7
+ exports.getNumberSuffix = getNumberSuffix;
8
+ exports.timeUnits = exports.lengthUnits = void 0;
7
9
  var _normalizeValue = _interopRequireDefault(require("./utils/normalize-value"));
8
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- /**
10
- * Copyright (c) Meta Platforms, Inc. and affiliates.
11
- *
12
- * This source code is licensed under the MIT license found in the
13
- * LICENSE file in the root directory of this source tree.
14
- *
15
- */
16
-
17
- /**
18
- * Convert a CSS value in JS to the final CSS string value
19
- */
20
- function transformValue(key, rawValue) {
11
+ function transformValue(key, rawValue, options) {
21
12
  const value = typeof rawValue === 'number' ? String(Math.round(rawValue * 10000) / 10000) + getNumberSuffix(key) : rawValue;
22
-
23
- // content is one of the values that needs to wrapped in quotes.
24
- // Users may write `''` without thinking about it, so we fix that.
25
- if (key === 'content' && typeof value === 'string') {
13
+ if ((key === 'content' || key === 'hyphenateCharacter' || key === 'hyphenate-character') && typeof value === 'string') {
26
14
  const val = value.trim();
27
15
  if (val.match(/^attr\([a-zA-Z0-9-]+\)$/)) {
28
16
  return val;
@@ -31,7 +19,7 @@ function transformValue(key, rawValue) {
31
19
  return `"${val}"`;
32
20
  }
33
21
  }
34
- return (0, _normalizeValue.default)(value, key);
22
+ return (0, _normalizeValue.default)(value, key, options);
35
23
  }
36
24
  function getNumberSuffix(key) {
37
25
  if (unitlessNumberProperties.has(key)) {
@@ -44,15 +32,13 @@ function getNumberSuffix(key) {
44
32
  return suffix;
45
33
  }
46
34
  }
47
- const unitlessNumberProperties = new Set(['animationIterationCount', 'borderImageOutset', 'borderImageSlice', 'borderImageWidth', 'columnCount', 'flex',
48
- // Unsupported
49
- 'flexGrow', 'flexPositive', 'flexShrink', 'flexOrder', 'gridRow', 'gridColumn', 'fontWeight', 'lineClamp', 'lineHeight', 'opacity', 'order', 'orphans', 'tabSize', 'widows', 'zIndex', 'fillOpacity', 'floodOpacity', 'stopOpacity', 'strokeDasharray', 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth']);
50
-
51
- // List of properties that have custom suffixes for numbers
35
+ const unitlessNumberProperties = new Set(['WebkitLineClamp', 'animationIterationCount', 'aspectRatio', 'borderImageOutset', 'borderImageSlice', 'borderImageWidth', 'counterSet', 'columnCount', 'flex', 'flexGrow', 'flexPositive', 'flexShrink', 'flexOrder', 'gridRow', 'gridColumn', 'fontWeight', 'hyphenateLimitChars', 'lineClamp', 'lineHeight', 'maskBorderOutset', 'maskBorderSlice', 'maskBorderWidth', 'opacity', 'order', 'orphans', 'tabSize', 'widows', 'zIndex', 'fillOpacity', 'floodOpacity', 'rotate', 'scale', 'stopOpacity', 'strokeDasharray', 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'scale', 'mathDepth']);
52
36
  const numberPropertySuffixes = {
53
37
  animationDelay: 'ms',
54
38
  animationDuration: 'ms',
55
39
  transitionDelay: 'ms',
56
40
  transitionDuration: 'ms',
57
41
  voiceDuration: 'ms'
58
- };
42
+ };
43
+ const timeUnits = exports.timeUnits = new Set(Object.keys(numberPropertySuffixes));
44
+ const lengthUnits = exports.lengthUnits = new Set(['backgroundPositionX', 'backgroundPositionY', 'blockSize', 'borderBlockEndWidth', 'borderBlockStartWidth', 'borderBlockWidth', 'borderVerticalWidth', 'borderVerticalWidth', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomWidth', 'borderEndEndRadius', 'borderEndStartRadius', 'borderImageWidth', 'borderInlineEndWidth', 'borderEndWidth', 'borderInlineStartWidth', 'borderStartWidth', 'borderInlineWidth', 'borderHorizontalWidth', 'borderLeftWidth', 'borderRightWidth', 'borderSpacing', 'borderStartEndRadius', 'borderStartStartRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopWidth', 'bottom', 'columnGap', 'columnRuleWidth', 'columnWidth', 'containIntrinsicBlockSize', 'containIntrinsicHeight', 'containIntrinsicInlineSize', 'containIntrinsicWidth', 'flexBasis', 'fontSize', 'fontSmooth', 'height', 'inlineSize', 'insetBlockEnd', 'insetBlockStart', 'insetInlineEnd', 'insetInlineStart', 'left', 'letterSpacing', 'marginBlockEnd', 'marginBlockStart', 'marginBottom', 'marginInlineEnd', 'marginEnd', 'marginInlineStart', 'marginStart', 'marginLeft', 'marginRight', 'marginTop', 'maskBorderOutset', 'maskBorderWidth', 'maxBlockSize', 'maxHeight', 'maxInlineSize', 'maxWidth', 'minBlockSize', 'minHeight', 'minInlineSize', 'minWidth', 'offsetDistance', 'outlineOffset', 'outlineWidth', 'overflowClipMargin', 'paddingBlockEnd', 'paddingBlockStart', 'paddingBottom', 'paddingInlineEnd', 'paddingEnd', 'paddingInlineStart', 'paddingStart', 'paddingLeft', 'paddingRight', 'paddingTop', 'perspective', 'right', 'rowGap', 'scrollMarginBlockEnd', 'scrollMarginBlockStart', 'scrollMarginBottom', 'scrollMarginInlineEnd', 'scrollMarginInlineStart', 'scrollMarginLeft', 'scrollMarginRight', 'scrollMarginTop', 'scrollPaddingBlockEnd', 'scrollPaddingBlockStart', 'scrollPaddingBottom', 'scrollPaddingInlineEnd', 'scrollPaddingInlineStart', 'scrollPaddingLeft', 'scrollPaddingRight', 'scrollPaddingTop', 'scrollSnapMarginBottom', 'scrollSnapMarginLeft', 'scrollSnapMarginRight', 'scrollSnapMarginTop', 'shapeMargin', 'tabSize', 'textDecorationThickness', 'textIndent', 'textUnderlineOffset', 'top', 'transformOrigin', 'translate', 'verticalAlign', 'width', 'wordSpacing', 'border', 'borderBlock', 'borderBlockEnd', 'borderBlockStart', 'borderBottom', 'borderLeft', 'borderRadius', 'borderRight', 'borderTop', 'borderWidth', 'columnRule', 'containIntrinsicSize', 'gap', 'inset', 'insetBlock', 'insetInline', 'margin', 'marginBlock', 'marginVertical', 'marginInline', 'marginHorizontal', 'offset', 'outline', 'padding', 'paddingBlock', 'paddingVertical', 'paddingInline', 'paddingHorizontal', 'scrollMargin', 'scrollMarginBlock', 'scrollMarginInline', 'scrollPadding', 'scrollPaddingBlock', 'scrollPaddingInline', 'scrollSnapMargin']);
@@ -0,0 +1,25 @@
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
+
12
+ /**
13
+ * Convert a CSS value in JS to the final CSS string value
14
+ */
15
+ declare export default function transformValue(
16
+ key: string,
17
+ rawValue: string | number,
18
+ options: StyleXOptions,
19
+ ): string;
20
+
21
+ declare export function getNumberSuffix(key: string): string;
22
+
23
+ declare export const timeUnits: Set<string>;
24
+
25
+ declare export const lengthUnits: Set<string>;
@@ -0,0 +1,205 @@
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
+ type ValueWithDefault<T> =
11
+ | T
12
+ | Readonly<{ default: T; [$$Key$$: string]: ValueWithDefault<T> }>;
13
+ type CSSSyntax =
14
+ | '*'
15
+ | '<length>'
16
+ | '<number>'
17
+ | '<percentage>'
18
+ | '<length-percentage>'
19
+ | '<color>'
20
+ | '<image>'
21
+ | '<url>'
22
+ | '<integer>'
23
+ | '<angle>'
24
+ | '<time>'
25
+ | '<resolution>'
26
+ | '<transform-function>'
27
+ | '<custom-ident>'
28
+ | '<transform-list>';
29
+ type CSSSyntaxType = CSSSyntax | ReadonlyArray<CSSSyntax>;
30
+ export declare class CSSType {}
31
+ export interface ICSSType<T extends string | number> {
32
+ readonly value: ValueWithDefault<T>;
33
+ readonly syntax: CSSSyntaxType;
34
+ }
35
+ type AnguleValue = string;
36
+ export declare class Angle<T extends AnguleValue>
37
+ extends CSSType
38
+ implements ICSSType<T>
39
+ {
40
+ readonly value: ValueWithDefault<T>;
41
+ readonly syntax: CSSSyntaxType;
42
+ static readonly syntax: CSSSyntaxType;
43
+ constructor(value: ValueWithDefault<T>);
44
+ static create<T extends AnguleValue = AnguleValue>(
45
+ value: ValueWithDefault<T>,
46
+ ): Angle<T>;
47
+ }
48
+ export declare const angle: any;
49
+ type ColorValue = string;
50
+ export declare class Color<T extends ColorValue>
51
+ extends CSSType
52
+ implements ICSSType<T>
53
+ {
54
+ readonly value: ValueWithDefault<T>;
55
+ readonly syntax: CSSSyntaxType;
56
+ constructor(value: ValueWithDefault<T>);
57
+ static create<T extends ColorValue = ColorValue>(
58
+ value: ValueWithDefault<T>,
59
+ ): Color<T>;
60
+ }
61
+ export declare const color: any;
62
+ type URLValue = string;
63
+ export declare class Url<T extends URLValue>
64
+ extends CSSType
65
+ implements ICSSType<T>
66
+ {
67
+ readonly value: ValueWithDefault<T>;
68
+ readonly syntax: CSSSyntaxType;
69
+ constructor(value: ValueWithDefault<T>);
70
+ static create<T extends URLValue = URLValue>(
71
+ value: ValueWithDefault<T>,
72
+ ): Url<T>;
73
+ }
74
+ export declare const url: any;
75
+ type ImageValue = string;
76
+ export declare class Image<T extends ImageValue>
77
+ extends Url<T>
78
+ implements ICSSType<T>
79
+ {
80
+ readonly value: ValueWithDefault<T>;
81
+ readonly syntax: CSSSyntaxType;
82
+ constructor(value: ValueWithDefault<T>);
83
+ static create<T extends ImageValue = ImageValue>(
84
+ value: ValueWithDefault<T>,
85
+ ): Image<T>;
86
+ }
87
+ export declare const image: any;
88
+ type IntegerValue = number;
89
+ export declare class Integer<T extends IntegerValue>
90
+ extends CSSType
91
+ implements ICSSType<T>
92
+ {
93
+ readonly value: ValueWithDefault<T>;
94
+ readonly syntax: CSSSyntaxType;
95
+ constructor(value: ValueWithDefault<T>);
96
+ static create<T extends IntegerValue = IntegerValue>(value: T): Integer<T>;
97
+ }
98
+ export declare const integer: any;
99
+ type LengthPercentageValue = string;
100
+ export declare class LengthPercentage<T extends LengthPercentageValue>
101
+ extends CSSType
102
+ implements ICSSType<string>
103
+ {
104
+ readonly value: ValueWithDefault<T>;
105
+ readonly syntax: CSSSyntaxType;
106
+ constructor(value: ValueWithDefault<T>);
107
+ static createLength<T extends LengthPercentageValue | number>(
108
+ value: ValueWithDefault<T>,
109
+ ): LengthPercentage<string>;
110
+ static createPercentage<T extends LengthPercentageValue | number>(
111
+ value: ValueWithDefault<T>,
112
+ ): LengthPercentage<string>;
113
+ }
114
+ export declare const lengthPercentage: any;
115
+ type LengthValue = number | string;
116
+ export declare class Length<T extends LengthValue>
117
+ extends LengthPercentage<string>
118
+ implements ICSSType<string>
119
+ {
120
+ readonly value: ValueWithDefault<string>;
121
+ readonly syntax: CSSSyntaxType;
122
+ constructor(value: ValueWithDefault<T>);
123
+ static create<T extends LengthValue = LengthValue>(
124
+ value: ValueWithDefault<T>,
125
+ ): Length<T>;
126
+ }
127
+ export declare const length: any;
128
+ type PercentageValue = string | number;
129
+ export declare class Percentage<T extends PercentageValue>
130
+ extends LengthPercentage<string>
131
+ implements ICSSType<string>
132
+ {
133
+ readonly value: ValueWithDefault<string>;
134
+ readonly syntax: CSSSyntaxType;
135
+ constructor(value: ValueWithDefault<T>);
136
+ static create<T extends PercentageValue = PercentageValue>(
137
+ value: ValueWithDefault<T>,
138
+ ): Percentage<T>;
139
+ }
140
+ export declare const percentage: any;
141
+ type NumberValue = number;
142
+ export declare class Num<T extends NumberValue>
143
+ extends CSSType
144
+ implements ICSSType<T>
145
+ {
146
+ readonly value: ValueWithDefault<T>;
147
+ readonly syntax: CSSSyntaxType;
148
+ constructor(value: ValueWithDefault<T>);
149
+ static create<T extends NumberValue = NumberValue>(
150
+ value: ValueWithDefault<T>,
151
+ ): Num<T>;
152
+ }
153
+ export declare const number: any;
154
+ type ResolutionValue = string | 0;
155
+ export declare class Resolution<T extends ResolutionValue>
156
+ extends CSSType
157
+ implements ICSSType<T>
158
+ {
159
+ readonly value: ValueWithDefault<T>;
160
+ readonly syntax: CSSSyntaxType;
161
+ constructor(value: ValueWithDefault<T>);
162
+ static create<T extends ResolutionValue = ResolutionValue>(
163
+ value: ValueWithDefault<T>,
164
+ ): Resolution<T>;
165
+ }
166
+ export declare const resolution: any;
167
+ type TimeValue = string | 0;
168
+ export declare class Time<T extends TimeValue>
169
+ extends CSSType
170
+ implements ICSSType<T>
171
+ {
172
+ readonly value: ValueWithDefault<T>;
173
+ readonly syntax: CSSSyntaxType;
174
+ constructor(value: ValueWithDefault<T>);
175
+ static create<T extends TimeValue = TimeValue>(
176
+ value: ValueWithDefault<T>,
177
+ ): Time<T>;
178
+ }
179
+ export declare const time: any;
180
+ type TransformFunctionValue = string;
181
+ export declare class TransformFunction<T extends TransformFunctionValue>
182
+ extends CSSType
183
+ implements ICSSType<T>
184
+ {
185
+ readonly value: ValueWithDefault<T>;
186
+ readonly syntax: CSSSyntaxType;
187
+ constructor(value: ValueWithDefault<T>);
188
+ static create<T extends TransformFunctionValue = TransformFunctionValue>(
189
+ value: ValueWithDefault<T>,
190
+ ): TransformFunction<T>;
191
+ }
192
+ export declare const transformFunction: any;
193
+ type TransformListValue = string;
194
+ export declare class TransformList<T extends TransformListValue>
195
+ extends CSSType
196
+ implements ICSSType<T>
197
+ {
198
+ readonly value: ValueWithDefault<T>;
199
+ readonly syntax: CSSSyntaxType;
200
+ constructor(value: ValueWithDefault<T>);
201
+ static create<T extends TransformListValue = TransformListValue>(
202
+ value: ValueWithDefault<T>,
203
+ ): TransformList<T>;
204
+ }
205
+ export declare const transformList: any;
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.url = exports.transformList = exports.transformFunction = exports.time = exports.resolution = exports.percentage = exports.number = exports.lengthPercentage = exports.length = exports.integer = exports.image = exports.color = exports.angle = exports.Url = exports.TransformList = exports.TransformFunction = exports.Time = exports.Resolution = exports.Percentage = exports.Num = exports.LengthPercentage = exports.Length = exports.Integer = exports.Image = exports.Color = exports.CSSType = exports.Angle = void 0;
7
+ class CSSType {}
8
+ exports.CSSType = CSSType;
9
+ class Angle extends CSSType {
10
+ syntax = '<angle>';
11
+ static syntax = '<angle>';
12
+ constructor(value) {
13
+ super();
14
+ this.value = value;
15
+ }
16
+ static create(value) {
17
+ return new Angle(value);
18
+ }
19
+ }
20
+ exports.Angle = Angle;
21
+ const angle = exports.angle = Angle.create;
22
+ class Color extends CSSType {
23
+ syntax = '<color>';
24
+ constructor(value) {
25
+ super();
26
+ this.value = value;
27
+ }
28
+ static create(value) {
29
+ return new Color(value);
30
+ }
31
+ }
32
+ exports.Color = Color;
33
+ const color = exports.color = Color.create;
34
+ class Url extends CSSType {
35
+ syntax = '<url>';
36
+ constructor(value) {
37
+ super();
38
+ this.value = value;
39
+ }
40
+ static create(value) {
41
+ return new Url(value);
42
+ }
43
+ }
44
+ exports.Url = Url;
45
+ const url = exports.url = Url.create;
46
+ class Image extends Url {
47
+ syntax = '<image>';
48
+ constructor(value) {
49
+ super(value);
50
+ this.value = value;
51
+ }
52
+ static create(value) {
53
+ return new Image(value);
54
+ }
55
+ }
56
+ exports.Image = Image;
57
+ const image = exports.image = Image.create;
58
+ class Integer extends CSSType {
59
+ syntax = '<integer>';
60
+ constructor(value) {
61
+ super();
62
+ this.value = value;
63
+ }
64
+ static create(value) {
65
+ return new Integer(value);
66
+ }
67
+ }
68
+ exports.Integer = Integer;
69
+ const integer = exports.integer = Integer.create;
70
+ class LengthPercentage extends CSSType {
71
+ syntax = '<length-percentage>';
72
+ constructor(value) {
73
+ super();
74
+ this.value = value;
75
+ }
76
+ static createLength(value) {
77
+ return new LengthPercentage(convertNumberToLength(value));
78
+ }
79
+ static createPercentage(value) {
80
+ return new LengthPercentage(convertNumberToPercentage(value));
81
+ }
82
+ }
83
+ exports.LengthPercentage = LengthPercentage;
84
+ const lengthPercentage = exports.lengthPercentage = LengthPercentage.createLength;
85
+ class Length extends LengthPercentage {
86
+ syntax = '<length>';
87
+ constructor(value) {
88
+ super(convertNumberToLength(value));
89
+ }
90
+ static create(value) {
91
+ return new Length(value);
92
+ }
93
+ }
94
+ exports.Length = Length;
95
+ const length = exports.length = Length.create;
96
+ class Percentage extends LengthPercentage {
97
+ syntax = '<percentage>';
98
+ constructor(value) {
99
+ super(convertNumberToPercentage(value));
100
+ }
101
+ static create(value) {
102
+ return new Percentage(value);
103
+ }
104
+ }
105
+ exports.Percentage = Percentage;
106
+ const percentage = exports.percentage = Percentage.create;
107
+ class Num extends CSSType {
108
+ syntax = '<number>';
109
+ constructor(value) {
110
+ super();
111
+ this.value = value;
112
+ }
113
+ static create(value) {
114
+ return new Num(value);
115
+ }
116
+ }
117
+ exports.Num = Num;
118
+ const number = exports.number = Num.create;
119
+ class Resolution extends CSSType {
120
+ syntax = '<resolution>';
121
+ constructor(value) {
122
+ super();
123
+ this.value = value;
124
+ }
125
+ static create(value) {
126
+ return new Resolution(value);
127
+ }
128
+ }
129
+ exports.Resolution = Resolution;
130
+ const resolution = exports.resolution = Resolution.create;
131
+ class Time extends CSSType {
132
+ syntax = '<time>';
133
+ constructor(value) {
134
+ super();
135
+ this.value = value;
136
+ }
137
+ static create(value) {
138
+ return new Time(value);
139
+ }
140
+ }
141
+ exports.Time = Time;
142
+ const time = exports.time = Time.create;
143
+ class TransformFunction extends CSSType {
144
+ syntax = '<transform-function>';
145
+ constructor(value) {
146
+ super();
147
+ this.value = value;
148
+ }
149
+ static create(value) {
150
+ return new TransformFunction(value);
151
+ }
152
+ }
153
+ exports.TransformFunction = TransformFunction;
154
+ const transformFunction = exports.transformFunction = TransformFunction.create;
155
+ class TransformList extends CSSType {
156
+ syntax = '<transform-list>';
157
+ constructor(value) {
158
+ super();
159
+ this.value = value;
160
+ }
161
+ static create(value) {
162
+ return new TransformList(value);
163
+ }
164
+ }
165
+ exports.TransformList = TransformList;
166
+ const transformList = exports.transformList = TransformList.create;
167
+ const convertNumberToStringUsing = (transformNumber, defaultStr) => value => {
168
+ if (typeof value === 'number') {
169
+ return transformNumber(value);
170
+ }
171
+ if (typeof value === 'string') {
172
+ return value;
173
+ }
174
+ if (typeof value === 'object') {
175
+ const {
176
+ default: defaultValue,
177
+ ...rest
178
+ } = value;
179
+ const defaultResult = convertNumberToLength(defaultValue);
180
+ const result = {
181
+ default: typeof defaultResult === 'string' ? defaultResult : defaultStr
182
+ };
183
+ for (const [key, value] of Object.entries(rest)) {
184
+ result[key] = convertNumberToLength(value);
185
+ }
186
+ return result;
187
+ }
188
+ return value;
189
+ };
190
+ const convertNumberToLength = convertNumberToStringUsing(value => value === 0 ? '0' : `${value}px`, '0px');
191
+ const convertNumberToPercentage = convertNumberToStringUsing(value => value === 0 ? '0' : `${value * 100}%`, '0');