@stylexjs/shared 0.2.0-beta.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +81 -0
- package/lib/common-types.d.ts +50 -0
- package/lib/common-types.js.flow +65 -0
- package/lib/convert-to-className.d.ts +16 -0
- package/lib/convert-to-className.js +17 -26
- package/lib/convert-to-className.js.flow +23 -0
- package/lib/generate-css-rule.d.ts +17 -0
- package/lib/generate-css-rule.js +8 -47
- package/lib/generate-css-rule.js.flow +17 -0
- package/lib/hash.d.ts +11 -0
- package/lib/hash.js +3 -27
- package/lib/hash.js.flow +10 -0
- package/lib/index.d.ts +42 -85
- package/lib/index.js +19 -27
- package/lib/index.js.flow +59 -0
- package/lib/messages.d.ts +36 -0
- package/lib/messages.js +28 -55
- package/lib/messages.js.flow +39 -0
- package/lib/physical-rtl/generate-ltr.d.ts +11 -0
- package/lib/physical-rtl/generate-ltr.js +18 -46
- package/lib/physical-rtl/generate-ltr.js.flow +12 -0
- package/lib/physical-rtl/generate-rtl.d.ts +13 -0
- package/lib/physical-rtl/generate-rtl.js +18 -50
- package/lib/physical-rtl/generate-rtl.js.flow +12 -0
- package/lib/preprocess-rules/PreRule.d.ts +52 -0
- package/lib/preprocess-rules/PreRule.js +87 -0
- package/lib/preprocess-rules/PreRule.js.flow +64 -0
- package/lib/preprocess-rules/application-order.d.ts +290 -0
- package/lib/preprocess-rules/application-order.js +193 -0
- package/lib/preprocess-rules/application-order.js.flow +241 -0
- package/lib/preprocess-rules/basic-validation.d.ts +13 -0
- package/lib/preprocess-rules/basic-validation.js +83 -0
- package/lib/preprocess-rules/basic-validation.js.flow +13 -0
- package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +25 -0
- package/lib/preprocess-rules/flatten-raw-style-obj.js +120 -0
- package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +27 -0
- package/lib/preprocess-rules/index.d.ts +18 -0
- package/lib/preprocess-rules/index.js +30 -0
- package/lib/preprocess-rules/index.js.flow +19 -0
- package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +200 -0
- package/lib/preprocess-rules/legacy-expand-shorthands.js +136 -0
- package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +179 -0
- package/lib/preprocess-rules/property-specificity.d.ts +89 -0
- package/lib/preprocess-rules/property-specificity.js +107 -0
- package/lib/preprocess-rules/property-specificity.js.flow +98 -0
- package/lib/properties/CSS Animations.json +445 -0
- package/lib/properties/CSS Backgrounds and Borders.json +1085 -0
- package/lib/properties/CSS Basic User Interface.json +365 -0
- package/lib/properties/CSS Box Alignment.json +245 -0
- package/lib/properties/CSS Box Model.json +501 -0
- package/lib/properties/CSS Color.json +100 -0
- package/lib/properties/CSS Columns.json +185 -0
- package/lib/properties/CSS Containment.json +203 -0
- package/lib/properties/CSS Counter Styles.json +56 -0
- package/lib/properties/CSS Display.json +20 -0
- package/lib/properties/CSS Flexible Box Layout.json +167 -0
- package/lib/properties/CSS Fonts.json +684 -0
- package/lib/properties/CSS Fragmentation.json +110 -0
- package/lib/properties/CSS Generated Content.json +38 -0
- package/lib/properties/CSS Grid Layout.json +500 -0
- package/lib/properties/CSS Images.json +91 -0
- package/lib/properties/CSS Inline.json +38 -0
- package/lib/properties/CSS Lists and Counters.json +86 -0
- package/lib/properties/CSS Logical Properties.json +1086 -0
- package/lib/properties/CSS Masking.json +399 -0
- package/lib/properties/CSS Miscellaneous.json +38 -0
- package/lib/properties/CSS Motion Path.json +132 -0
- package/lib/properties/CSS Overflow.json +216 -0
- package/lib/properties/CSS Pages.json +83 -0
- package/lib/properties/CSS Positioning.json +166 -0
- package/lib/properties/CSS Ruby.json +55 -0
- package/lib/properties/CSS Scroll Anchoring.json +19 -0
- package/lib/properties/CSS Scroll Snap.json +604 -0
- package/lib/properties/CSS Scrollbars.json +38 -0
- package/lib/properties/CSS Shapes.json +56 -0
- package/lib/properties/CSS Speech.json +20 -0
- package/lib/properties/CSS Table.json +115 -0
- package/lib/properties/CSS Text Decoration.json +312 -0
- package/lib/properties/CSS Text.json +415 -0
- package/lib/properties/CSS Transforms.json +188 -0
- package/lib/properties/CSS Transitions.json +122 -0
- package/lib/properties/CSS Variables.json +20 -0
- package/lib/properties/CSS View Transitions.json +20 -0
- package/lib/properties/CSS Will Change.json +20 -0
- package/lib/properties/CSS Writing Modes.json +92 -0
- package/lib/properties/Compositing and Blending.json +62 -0
- package/lib/properties/Filter Effects.json +38 -0
- package/lib/properties/MathML.json +56 -0
- package/lib/properties/Microsoft Extensions.json +885 -0
- package/lib/properties/Mozilla Extensions.json +607 -0
- package/lib/properties/Pointer Events.json +20 -0
- package/lib/properties/WebKit Extensions.json +707 -0
- package/lib/properties.json +10122 -0
- package/lib/stylex-create-theme.d.ts +26 -0
- package/lib/stylex-create-theme.js +62 -0
- package/lib/stylex-create-theme.js.flow +19 -0
- package/lib/stylex-create.d.ts +23 -0
- package/lib/stylex-create.js +30 -142
- package/lib/stylex-create.js.flow +30 -0
- package/lib/stylex-define-vars.d.ts +36 -0
- package/lib/stylex-define-vars.js +72 -0
- package/lib/stylex-define-vars.js.flow +28 -0
- package/lib/stylex-first-that-works.d.ts +13 -0
- package/lib/stylex-first-that-works.js +0 -10
- package/lib/stylex-first-that-works.js.flow +12 -0
- package/lib/stylex-include.d.ts +18 -0
- package/lib/stylex-include.js +0 -10
- package/lib/stylex-include.js.flow +20 -0
- package/lib/stylex-keyframes.d.ts +17 -0
- package/lib/stylex-keyframes.js +22 -30
- package/lib/stylex-keyframes.js.flow +20 -0
- package/lib/transform-value.d.ts +22 -0
- package/lib/transform-value.js +9 -23
- package/lib/transform-value.js.flow +25 -0
- package/lib/types/index.d.ts +205 -0
- package/lib/types/index.js +191 -0
- package/lib/types/index.js.flow +241 -0
- package/lib/utils/Rule.d.ts +58 -0
- package/lib/utils/Rule.js +50 -0
- package/lib/utils/Rule.js.flow +64 -0
- package/lib/utils/dashify.d.ts +11 -0
- package/lib/utils/dashify.js +0 -8
- package/lib/utils/dashify.js.flow +10 -0
- package/lib/utils/default-options.d.ts +11 -0
- package/lib/utils/default-options.js +14 -0
- package/lib/utils/default-options.js.flow +25 -0
- package/lib/utils/file-based-identifier.d.ts +15 -0
- package/lib/utils/file-based-identifier.js +14 -0
- package/lib/utils/file-based-identifier.js.flow +14 -0
- package/lib/utils/genCSSRule.d.ts +15 -0
- package/lib/utils/genCSSRule.js +9 -18
- package/lib/utils/genCSSRule.js.flow +15 -0
- package/lib/utils/normalize-value.d.ts +16 -0
- package/lib/utils/normalize-value.js +11 -15
- package/lib/utils/normalize-value.js.flow +16 -0
- package/lib/utils/normalizers/convert-camel-case-transition-props.d.ts +14 -0
- package/lib/utils/normalizers/convert-camel-case-transition-props.js +23 -0
- package/lib/utils/normalizers/convert-camel-case-transition-props.js.flow +13 -0
- package/lib/utils/normalizers/convert-camel-case-values.d.ts +14 -0
- package/lib/utils/normalizers/convert-camel-case-values.js +23 -0
- package/lib/utils/normalizers/convert-camel-case-values.js.flow +13 -0
- package/lib/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
- package/lib/utils/normalizers/detect-unclosed-fns.js +0 -12
- package/lib/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
- package/lib/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
- package/lib/utils/normalizers/font-size-px-to-rem.js +9 -19
- package/lib/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
- package/lib/utils/normalizers/leading-zero.d.ts +17 -0
- package/lib/utils/normalizers/leading-zero.js +0 -12
- package/lib/utils/normalizers/leading-zero.js.flow +16 -0
- package/lib/utils/normalizers/quotes.d.ts +18 -0
- package/lib/utils/normalizers/quotes.js +0 -13
- package/lib/utils/normalizers/quotes.js.flow +17 -0
- package/lib/utils/normalizers/timings.d.ts +18 -0
- package/lib/utils/normalizers/timings.js +0 -14
- package/lib/utils/normalizers/timings.js.flow +17 -0
- package/lib/utils/normalizers/whitespace.d.ts +19 -0
- package/lib/utils/normalizers/whitespace.js +0 -15
- package/lib/utils/normalizers/whitespace.js.flow +18 -0
- package/lib/utils/normalizers/zero-dimensions.d.ts +19 -0
- package/lib/utils/normalizers/zero-dimensions.js +0 -15
- package/lib/utils/normalizers/zero-dimensions.js.flow +18 -0
- package/lib/utils/object-utils.d.ts +66 -0
- package/lib/utils/object-utils.js +21 -13
- package/lib/utils/object-utils.js.flow +77 -0
- package/lib/utils/property-priorities.d.ts +11 -0
- package/lib/utils/property-priorities.js +531 -0
- package/lib/utils/property-priorities.js.flow +10 -0
- package/lib/utils/split-css-value.d.ts +14 -0
- package/lib/utils/split-css-value.js +33 -0
- package/lib/utils/split-css-value.js.flow +15 -0
- package/lib/validate.d.ts +12 -0
- package/lib/validate.js +1 -10
- package/lib/validate.js.flow +12 -0
- package/package.json +4 -5
- package/lib/expand-shorthands.d.ts +0 -5
- package/lib/expand-shorthands.js +0 -387
- package/lib/stylex-defaultValue.js +0 -397
package/lib/stylex-keyframes.js
CHANGED
@@ -5,40 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = styleXKeyframes;
|
7
7
|
var _hash = _interopRequireDefault(require("./hash"));
|
8
|
-
var
|
8
|
+
var _index = _interopRequireDefault(require("./preprocess-rules/index"));
|
9
9
|
var _generateLtr = _interopRequireDefault(require("./physical-rtl/generate-ltr"));
|
10
10
|
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
|
31
|
-
|
17
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaultOptions.defaultOptions;
|
18
|
+
const {
|
32
19
|
classNamePrefix = 'x'
|
33
|
-
} =
|
34
|
-
const expandedObject = (0, _objectUtils.objMap)(frames, frame => _objectUtils.Pipe.create(frame).pipe(expandFrameShorthands).pipe(x => (0, _objectUtils.objMapKeys)(x, _dashify.default)).pipe(x => (0, _objectUtils.objMap)(x, (value, key) => (0, _transformValue.default)(key, value))).done());
|
20
|
+
} = options;
|
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());
|
35
22
|
const ltrStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, _generateLtr.default));
|
36
23
|
const rtlStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, entry => (0, _generateRtl.default)(entry) ?? entry));
|
37
24
|
const ltrString = constructKeyframesObj(ltrStyles);
|
38
25
|
const rtlString = constructKeyframesObj(rtlStyles);
|
39
|
-
|
40
|
-
// This extra `-B` is kept for some idiosyncratic legacy compatibility for now.
|
41
|
-
const animationName = classNamePrefix + (0, _hash.default)(stylexSheetName + ltrString) + '-B';
|
26
|
+
const animationName = classNamePrefix + (0, _hash.default)('<>' + ltrString) + '-B';
|
42
27
|
const ltr = `@keyframes ${animationName}{${ltrString}}`;
|
43
28
|
const rtl = ltrString === rtlString ? null : `@keyframes ${animationName}{${rtlString}}`;
|
44
29
|
return [animationName, {
|
@@ -47,16 +32,23 @@ function styleXKeyframes(frames) {
|
|
47
32
|
priority: 1
|
48
33
|
}];
|
49
34
|
}
|
50
|
-
function expandFrameShorthands(frame) {
|
51
|
-
return (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(frame).flatMap(pair => (0,
|
35
|
+
function expandFrameShorthands(frame, options) {
|
36
|
+
return (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(frame).flatMap(pair => (0, _index.default)(pair, options).map(_ref => {
|
37
|
+
let [key, value] = _ref;
|
38
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
39
|
+
return [key, value];
|
40
|
+
}
|
41
|
+
return null;
|
42
|
+
}).filter(Boolean)).filter(_ref2 => {
|
43
|
+
let [_key, value] = _ref2;
|
44
|
+
return value != null;
|
45
|
+
}));
|
52
46
|
}
|
53
|
-
|
54
|
-
// Create t
|
55
47
|
function constructKeyframesObj(frames) {
|
56
|
-
return (0, _objectUtils.objEntries)(frames).map(
|
57
|
-
let [key, value] =
|
58
|
-
return `${key}{${(0, _objectUtils.objEntries)(value).map(
|
59
|
-
let [k, v] =
|
48
|
+
return (0, _objectUtils.objEntries)(frames).map(_ref3 => {
|
49
|
+
let [key, value] = _ref3;
|
50
|
+
return `${key}{${(0, _objectUtils.objEntries)(value).map(_ref4 => {
|
51
|
+
let [k, v] = _ref4;
|
60
52
|
return `${k}:${v};`;
|
61
53
|
}).join('')}}`;
|
62
54
|
}).join('');
|
@@ -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>;
|
package/lib/transform-value.js
CHANGED
@@ -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');
|