@stylexjs/shared 0.2.0-beta.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -3
- package/lib/common-types.d.ts +49 -0
- package/lib/common-types.js.flow +64 -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 +6 -17
- 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 +21 -29
- package/lib/index.js.flow +57 -3
- package/lib/messages.d.ts +41 -0
- package/lib/messages.js +33 -53
- package/lib/messages.js.flow +44 -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 +60 -133
- 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 +0 -9
- 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 +90 -123
- 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 +46 -74
- 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 +67 -0
- package/lib/stylex-create-theme.js.flow +19 -0
- package/lib/stylex-create.d.ts +23 -0
- package/lib/stylex-create.js +30 -146
- package/lib/stylex-create.js.flow +30 -0
- package/lib/stylex-define-vars.d.ts +29 -0
- package/lib/stylex-define-vars.js +73 -0
- package/lib/stylex-define-vars.js.flow +26 -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 +2 -12
- package/lib/stylex-include.js.flow +20 -0
- package/lib/stylex-keyframes.d.ts +17 -0
- package/lib/stylex-keyframes.js +6 -26
- 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 +0 -21
- 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 +13 -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 +8 -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 +2 -14
- 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 +516 -101
- 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 +0 -14
- 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 -330
- package/lib/namespace-transforms/__tests__/preflatten.test.js +0 -120
- package/lib/namespace-transforms/preflatten.js +0 -89
- package/lib/preprocess-rules/expand-shorthands.js +0 -156
- package/lib/preprocess-rules/null-out-longhand.js +0 -310
- package/lib/preprocess-rules/react-native-web.js +0 -142
- package/lib/stylex-defaultValue.js +0 -397
package/README.md
CHANGED
@@ -4,8 +4,8 @@ This package contains most of the core JavaScript logic for stylex.
|
|
4
4
|
|
5
5
|
It exports two primary functions `create` and `keyframes`.
|
6
6
|
|
7
|
-
1. `create` - takes a map of style rules. The return value
|
8
|
-
2. `keyframes` - takes a `@keyframes` animation as JS object. Returns a hashed string and the style
|
7
|
+
1. `create` - takes a map of style rules. The return value includes: a) the map with each style value replaced by a unique, reproducible, hashed `className` string, and b) a list of the CSS styles to be inserted into the document.
|
8
|
+
2. `keyframes` - takes a `@keyframes` animation as JS object. Returns a hashed string and the style to be injected.
|
9
9
|
|
10
10
|
#### ⭐️ `create`
|
11
11
|
|
@@ -29,7 +29,7 @@ The first step here is expanding all [shorthands](#shorthands) into their indivi
|
|
29
29
|
|
30
30
|
**Step 2**
|
31
31
|
|
32
|
-
We hash each style `[key, value]` pair and generate a className and an associated CSS rule.
|
32
|
+
We hash each style `[key, value]` pair and generate a className and an associated CSS rule. This is done in the `convertToClassName(...)` function defined within [`convert-to-className.js`](#convert-to-classname-shared-package). (Explained below)
|
33
33
|
|
34
34
|
**Step 3**
|
35
35
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
import type { IncludedStyles } from './stylex-include';
|
11
|
+
export type TRawValue = number | string | ReadonlyArray<number | string>;
|
12
|
+
export type TStyleValue = null | TRawValue;
|
13
|
+
export type TNestableStyleValue = TStyleValue | PrimitiveRawStyles;
|
14
|
+
export type RawStyles = Readonly<{
|
15
|
+
[$$Key$$: string]: TNestableStyleValue | IncludedStyles;
|
16
|
+
}>;
|
17
|
+
export type PrimitiveRawStyles = Readonly<{
|
18
|
+
[$$Key$$: string]: TNestableStyleValue;
|
19
|
+
}>;
|
20
|
+
export type InjectableStyle = {
|
21
|
+
readonly priority: number;
|
22
|
+
readonly ltr: string;
|
23
|
+
readonly rtl: null | string;
|
24
|
+
};
|
25
|
+
export type StyleRule = [string, string, InjectableStyle];
|
26
|
+
export type CompiledStyles = Readonly<{
|
27
|
+
[$$Key$$: string]:
|
28
|
+
| IncludedStyles
|
29
|
+
| null
|
30
|
+
| string
|
31
|
+
| Readonly<{ [$$Key$$: string]: null | string }>;
|
32
|
+
}>;
|
33
|
+
export type FlatCompiledStyles = Readonly<{
|
34
|
+
[$$Key$$: string]: string | IncludedStyles | null;
|
35
|
+
$$css: true;
|
36
|
+
}>;
|
37
|
+
export type StyleXOptions = Readonly<{
|
38
|
+
dev: boolean;
|
39
|
+
test: boolean;
|
40
|
+
useRemForFontSize: boolean;
|
41
|
+
classNamePrefix: string;
|
42
|
+
definedStylexCSSVariables?: { [key: string]: unknown };
|
43
|
+
styleResolution:
|
44
|
+
| 'application-order'
|
45
|
+
| 'property-specificity'
|
46
|
+
| 'legacy-expand-shorthands';
|
47
|
+
}>;
|
48
|
+
export type MutableCompiledNamespaces = { [key: string]: FlatCompiledStyles };
|
49
|
+
export type CompiledNamespaces = Readonly<MutableCompiledNamespaces>;
|
@@ -0,0 +1,64 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
*/
|
9
|
+
|
10
|
+
import type { IncludedStyles } from './stylex-include';
|
11
|
+
|
12
|
+
export type TRawValue = number | string | $ReadOnlyArray<number | string>;
|
13
|
+
export type TStyleValue = null | TRawValue;
|
14
|
+
export type TNestableStyleValue = TStyleValue | PrimitiveRawStyles;
|
15
|
+
|
16
|
+
export type RawStyles = $ReadOnly<{
|
17
|
+
[string]: TNestableStyleValue | IncludedStyles,
|
18
|
+
}>;
|
19
|
+
export type PrimitiveRawStyles = $ReadOnly<{
|
20
|
+
[string]: TNestableStyleValue,
|
21
|
+
}>;
|
22
|
+
|
23
|
+
export type InjectableStyle = {
|
24
|
+
+priority: number,
|
25
|
+
+ltr: string,
|
26
|
+
+rtl: null | string,
|
27
|
+
};
|
28
|
+
|
29
|
+
export type StyleRule = [string, string, InjectableStyle];
|
30
|
+
|
31
|
+
export type CompiledStyles = $ReadOnly<{
|
32
|
+
[string]:
|
33
|
+
| IncludedStyles
|
34
|
+
| null
|
35
|
+
| string
|
36
|
+
| $ReadOnly<{ [string]: null | string }>,
|
37
|
+
}>;
|
38
|
+
|
39
|
+
export type FlatCompiledStyles = $ReadOnly<{
|
40
|
+
[string]: string | IncludedStyles | null,
|
41
|
+
$$css: true,
|
42
|
+
}>;
|
43
|
+
|
44
|
+
export type StyleXOptions = $ReadOnly<{
|
45
|
+
dev: boolean,
|
46
|
+
test: boolean,
|
47
|
+
useRemForFontSize: boolean,
|
48
|
+
classNamePrefix: string,
|
49
|
+
definedStylexCSSVariables?: { [key: string]: mixed },
|
50
|
+
styleResolution:
|
51
|
+
| 'application-order' // The last style applied wins.
|
52
|
+
// More specific styles will win over less specific styles. (margin-top wins over margin)
|
53
|
+
| 'property-specificity'
|
54
|
+
// Legacy behavior, that expands shorthand properties into their longhand counterparts at compile-time.
|
55
|
+
// This is not recommended, and will be removed in a future version.
|
56
|
+
| 'legacy-expand-shorthands',
|
57
|
+
...
|
58
|
+
}>;
|
59
|
+
|
60
|
+
export type MutableCompiledNamespaces = {
|
61
|
+
[key: string]: FlatCompiledStyles,
|
62
|
+
};
|
63
|
+
|
64
|
+
export type CompiledNamespaces = $ReadOnly<MutableCompiledNamespaces>;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
import type { TRawValue, StyleRule, StyleXOptions } from './common-types';
|
11
|
+
export declare function convertStyleToClassName(
|
12
|
+
objEntry: [string, TRawValue],
|
13
|
+
pseudos: ReadonlyArray<string>,
|
14
|
+
atRules: ReadonlyArray<string>,
|
15
|
+
options: StyleXOptions,
|
16
|
+
): StyleRule;
|
@@ -3,38 +3,29 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.convertStyleToClassName = convertStyleToClassName;
|
7
7
|
var _hash = _interopRequireDefault(require("./hash"));
|
8
8
|
var _dashify = _interopRequireDefault(require("./utils/dashify"));
|
9
9
|
var _transformValue = _interopRequireDefault(require("./transform-value"));
|
10
|
-
var _generateCssRule =
|
10
|
+
var _generateCssRule = require("./generate-css-rule");
|
11
|
+
var _defaultOptions = require("./utils/default-options");
|
12
|
+
var _objectUtils = require("./utils/object-utils");
|
11
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
* This source code is licensed under the MIT license found in the
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*/
|
20
|
-
|
21
|
-
// This function takes a single style rule and transforms it into a CSS rule.
|
22
|
-
// [color: 'red'] => ['color', 'classname-for-color-red', CSSRULE{ltr, rtl, priority}]
|
23
|
-
//
|
24
|
-
// It converts the camelCased style key to a dash-separated key.
|
25
|
-
// Handles RTL-flipping
|
26
|
-
// Hashes to get a className
|
27
|
-
// Returns the final key, className a CSS Rule
|
28
|
-
function convertToClassName(objEntry, pseudo) {
|
29
|
-
let {
|
30
|
-
stylexSheetName = '<>',
|
14
|
+
function convertStyleToClassName(objEntry, pseudos, atRules) {
|
15
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _defaultOptions.defaultOptions;
|
16
|
+
const {
|
31
17
|
classNamePrefix = 'x'
|
32
|
-
} =
|
18
|
+
} = options;
|
33
19
|
const [key, rawValue] = objEntry;
|
34
20
|
const dashedKey = (0, _dashify.default)(key);
|
35
|
-
const value = Array.isArray(rawValue) ? rawValue.map(eachValue => (0, _transformValue.default)(key, eachValue)) : (0, _transformValue.default)(key, rawValue);
|
36
|
-
const
|
37
|
-
const
|
38
|
-
const
|
21
|
+
const value = Array.isArray(rawValue) ? rawValue.map(eachValue => (0, _transformValue.default)(key, eachValue, options)) : (0, _transformValue.default)(key, rawValue, options);
|
22
|
+
const sortedPseudos = (0, _objectUtils.arraySort)(pseudos ?? []);
|
23
|
+
const sortedAtRules = (0, _objectUtils.arraySort)(atRules ?? []);
|
24
|
+
const atRuleHashString = sortedPseudos.join('');
|
25
|
+
const pseudoHashString = sortedAtRules.join('');
|
26
|
+
const modifierHashString = atRuleHashString + pseudoHashString || 'null';
|
27
|
+
const stringToHash = Array.isArray(value) ? dashedKey + value.join(', ') + modifierHashString : dashedKey + value + modifierHashString;
|
28
|
+
const className = classNamePrefix + (0, _hash.default)('<>' + stringToHash);
|
29
|
+
const cssRules = (0, _generateCssRule.generateRule)(className, dashedKey, value, pseudos, atRules);
|
39
30
|
return [key, className, cssRules];
|
40
31
|
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
*/
|
9
|
+
|
10
|
+
import type { TRawValue, StyleRule, StyleXOptions } from './common-types';
|
11
|
+
// This function takes a single style rule and transforms it into a CSS rule.
|
12
|
+
// [color: 'red'] => ['color', 'classname-for-color-red', CSSRULE{ltr, rtl, priority}]
|
13
|
+
//
|
14
|
+
// It converts the camelCased style key to a dash-separated key.
|
15
|
+
// Handles RTL-flipping
|
16
|
+
// Hashes to get a className
|
17
|
+
// Returns the final key, className a CSS Rule
|
18
|
+
declare export function convertStyleToClassName(
|
19
|
+
objEntry: [string, TRawValue],
|
20
|
+
pseudos: $ReadOnlyArray<string>,
|
21
|
+
atRules: $ReadOnlyArray<string>,
|
22
|
+
options: StyleXOptions,
|
23
|
+
): StyleRule;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
import type { InjectableStyle } from './common-types';
|
11
|
+
export declare function generateRule(
|
12
|
+
className: string,
|
13
|
+
key: string,
|
14
|
+
value: string | ReadonlyArray<string>,
|
15
|
+
pseudos: ReadonlyArray<string>,
|
16
|
+
atRules: ReadonlyArray<string>,
|
17
|
+
): InjectableStyle;
|
package/lib/generate-css-rule.js
CHANGED
@@ -3,31 +3,20 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.generateRule = generateRule;
|
7
7
|
var _generateLtr = _interopRequireDefault(require("./physical-rtl/generate-ltr"));
|
8
8
|
var _generateRtl = _interopRequireDefault(require("./physical-rtl/generate-rtl"));
|
9
|
-
var _genCSSRule =
|
9
|
+
var _genCSSRule = require("./utils/genCSSRule");
|
10
10
|
var _propertyPriorities = _interopRequireDefault(require("./utils/property-priorities"));
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12
|
-
|
13
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
14
|
-
*
|
15
|
-
* This source code is licensed under the MIT license found in the
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*/
|
20
|
-
|
21
|
-
function generateCSSRule(className, key,
|
22
|
-
// pre-dashed
|
23
|
-
value, pseudo) {
|
12
|
+
function generateRule(className, key, value, pseudos, atRules) {
|
24
13
|
const pairs = Array.isArray(value) ? value.map(eachValue => [key, eachValue]) : [[key, value]];
|
25
14
|
const ltrPairs = pairs.map(_generateLtr.default);
|
26
15
|
const ltrDecls = ltrPairs.map(pair => pair.join(':')).join(';');
|
27
16
|
const rtlDecls = pairs.map(_generateRtl.default).filter(Boolean).map(pair => pair.join(':')).join(';');
|
28
|
-
const ltrRule = (0, _genCSSRule.
|
29
|
-
const rtlRule = !rtlDecls ? null : (0, _genCSSRule.
|
30
|
-
const priority = (0, _propertyPriorities.default)(key) + (
|
17
|
+
const ltrRule = (0, _genCSSRule.genCSSRule)(className, ltrDecls, pseudos, atRules);
|
18
|
+
const rtlRule = !rtlDecls ? null : (0, _genCSSRule.genCSSRule)(className, rtlDecls, pseudos, atRules);
|
19
|
+
const priority = (0, _propertyPriorities.default)(key) + pseudos.map(_propertyPriorities.default).reduce((a, b) => a + b, 0) + atRules.map(_propertyPriorities.default).reduce((a, b) => a + b, 0);
|
31
20
|
return {
|
32
21
|
priority,
|
33
22
|
ltr: ltrRule,
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
*/
|
9
|
+
|
10
|
+
import type { InjectableStyle } from './common-types';
|
11
|
+
declare export function generateRule(
|
12
|
+
className: string,
|
13
|
+
key: string,
|
14
|
+
value: string | $ReadOnlyArray<string>,
|
15
|
+
pseudos: $ReadOnlyArray<string>,
|
16
|
+
atRules: $ReadOnlyArray<string>,
|
17
|
+
): InjectableStyle;
|
package/lib/hash.d.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
declare const $$EXPORT_DEFAULT_DECLARATION$$: (str: string) => string;
|
11
|
+
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
package/lib/hash.js
CHANGED
@@ -4,31 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
|
8
|
-
|
9
|
-
*
|
10
|
-
* This source code is licensed under the MIT license found in the
|
11
|
-
* LICENSE file in the root directory of this source tree.
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*/
|
15
|
-
|
16
|
-
/* eslint-disable default-case */
|
17
|
-
/* eslint-disable no-fallthrough */
|
18
|
-
|
19
|
-
/**
|
20
|
-
* JS Implementation of MurmurHash2
|
21
|
-
*
|
22
|
-
* @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
|
23
|
-
* @see http://github.com/garycourt/murmurhash-js
|
24
|
-
* @author <a href="mailto:aappleby@gmail.com">Austin Appleby</a>
|
25
|
-
* @see http://sites.google.com/site/murmurhash/
|
26
|
-
*
|
27
|
-
* @param {string} str ASCII only
|
28
|
-
* @param {number} seed Positive integer only
|
29
|
-
* @return {number} 32-bit positive integer hash
|
30
|
-
*/
|
31
|
-
function murmurhash2_32_gc(str, seed) {
|
7
|
+
function murmurhash2_32_gc(str) {
|
8
|
+
let seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
32
9
|
let l = str.length,
|
33
10
|
h = seed ^ l,
|
34
11
|
i = 0,
|
@@ -57,5 +34,4 @@ function murmurhash2_32_gc(str, seed) {
|
|
57
34
|
return h >>> 0;
|
58
35
|
}
|
59
36
|
const hash = str => murmurhash2_32_gc(str, 1).toString(36);
|
60
|
-
var _default = hash;
|
61
|
-
exports.default = _default;
|
37
|
+
var _default = exports.default = hash;
|
package/lib/hash.js.flow
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
*/
|
9
|
+
|
10
|
+
declare export default (str: string) => string;
|
package/lib/index.d.ts
CHANGED
@@ -3,91 +3,48 @@
|
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
6
8
|
*/
|
7
9
|
|
8
|
-
export type
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
export
|
37
|
-
|
38
|
-
export
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
export function create<N extends { readonly [key: string]: RawStyles }>(
|
43
|
-
namespaces: N,
|
44
|
-
options?: StyleXOptions
|
45
|
-
): readonly [CompiledNamespaces, { readonly [key: string]: InjectableStyle }];
|
46
|
-
|
47
|
-
export function keyframes<
|
48
|
-
Obj extends {
|
49
|
-
readonly [key: string]: { readonly [k: string]: string | number };
|
50
|
-
}
|
51
|
-
>(animation: Obj, options?: StyleXOptions): readonly [string, InjectableStyle];
|
52
|
-
|
53
|
-
export function include(animation: {
|
54
|
-
readonly [key: string]: string | number;
|
55
|
-
}): readonly { [key: string]: IncludedStyles };
|
56
|
-
|
57
|
-
export class IncludedStyles {
|
58
|
-
astNode: any;
|
59
|
-
}
|
60
|
-
|
61
|
-
export type StyleXOptions = {
|
62
|
-
dev: boolean;
|
63
|
-
test: boolean;
|
64
|
-
stylexSheetName?: string | undefined;
|
65
|
-
classNamePrefix: string;
|
66
|
-
definedStylexCSSVariables?: { [key: string]: any };
|
67
|
-
skipShorthandExpansion?: boolean;
|
68
|
-
[key: string]: any;
|
69
|
-
};
|
70
|
-
|
71
|
-
export function firstThatWorks<T>(...args: T[]): T[];
|
72
|
-
|
73
|
-
export const messages: {
|
74
|
-
ILLEGAL_ARGUMENT_LENGTH: string;
|
75
|
-
NON_STATIC_VALUE: string;
|
76
|
-
ESCAPED_STYLEX_VALUE: string;
|
77
|
-
UNBOUND_STYLEX_CALL_VALUE: string;
|
78
|
-
ONLY_TOP_LEVEL: string;
|
79
|
-
NON_OBJECT_FOR_STYLEX_CALL: string;
|
80
|
-
UNKNOWN_PROP_KEY: string;
|
81
|
-
INVALID_PSEUDO: string;
|
82
|
-
ILLEGAL_NAMESPACE_TYPE: string;
|
83
|
-
UNKNOWN_NAMESPACE: string;
|
84
|
-
ILLEGAL_NESTED_PSEUDO: string;
|
85
|
-
ILLEGAL_PROP_VALUE: string;
|
86
|
-
ILLEGAL_PROP_ARRAY_VALUE: string;
|
87
|
-
ILLEGAL_NAMESPACE_VALUE: string;
|
88
|
-
INVALID_SPREAD: string;
|
89
|
-
LINT_UNCLOSED_FUNCTION: string;
|
90
|
-
LOCAL_ONLY: string;
|
91
|
-
UNEXPECTED_ARGUMENT: string;
|
92
|
-
EXPECTED_FUNCTION_CALL: string;
|
10
|
+
export type {
|
11
|
+
RawStyles,
|
12
|
+
StyleRule,
|
13
|
+
TNestableStyleValue,
|
14
|
+
TRawValue,
|
15
|
+
TStyleValue,
|
16
|
+
} from './common-types';
|
17
|
+
import styleXCreateSet from './stylex-create';
|
18
|
+
import styleXDefineVars from './stylex-define-vars';
|
19
|
+
import styleXCreateTheme from './stylex-create-theme';
|
20
|
+
import stylexKeyframes from './stylex-keyframes';
|
21
|
+
import stylexInclude, {
|
22
|
+
IncludedStyles as _IncludedStyles,
|
23
|
+
} from './stylex-include';
|
24
|
+
import stylexFirstThatWorks from './stylex-first-that-works';
|
25
|
+
import hash from './hash';
|
26
|
+
import genFileBasedIdentifier from './utils/file-based-identifier';
|
27
|
+
import * as m from './messages';
|
28
|
+
export * as types from './types';
|
29
|
+
import type {
|
30
|
+
InjectableStyle as _InjectableStyle,
|
31
|
+
CompiledNamespaces as _CompiledNamespaces,
|
32
|
+
MutableCompiledNamespaces as _MutableCompiledNamespaces,
|
33
|
+
StyleXOptions as _StyleXOptions,
|
34
|
+
} from './common-types';
|
35
|
+
export declare const create: typeof styleXCreateSet;
|
36
|
+
export declare const defineVars: typeof styleXDefineVars;
|
37
|
+
export declare const createTheme: typeof styleXCreateTheme;
|
38
|
+
export declare const keyframes: typeof stylexKeyframes;
|
39
|
+
export declare const include: typeof stylexInclude;
|
40
|
+
export declare const utils: {
|
41
|
+
hash: typeof hash;
|
42
|
+
genFileBasedIdentifier: typeof genFileBasedIdentifier;
|
93
43
|
};
|
44
|
+
export declare const messages: typeof m;
|
45
|
+
export declare const IncludedStyles: typeof _IncludedStyles;
|
46
|
+
export declare const firstThatWorks: typeof stylexFirstThatWorks;
|
47
|
+
export type InjectableStyle = _InjectableStyle;
|
48
|
+
export type CompiledNamespaces = _CompiledNamespaces;
|
49
|
+
export type MutableCompiledNamespaces = _MutableCompiledNamespaces;
|
50
|
+
export type StyleXOptions = _StyleXOptions;
|
package/lib/index.js
CHANGED
@@ -3,38 +3,30 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.messages = exports.keyframes = exports.include = exports.firstThatWorks = exports.create = exports.IncludedStyles = void 0;
|
6
|
+
exports.utils = exports.types = exports.messages = exports.keyframes = exports.include = exports.firstThatWorks = exports.defineVars = exports.createTheme = exports.create = exports.IncludedStyles = void 0;
|
7
7
|
var _stylexCreate = _interopRequireDefault(require("./stylex-create"));
|
8
|
+
var _stylexDefineVars = _interopRequireDefault(require("./stylex-define-vars"));
|
9
|
+
var _stylexCreateTheme = _interopRequireDefault(require("./stylex-create-theme"));
|
8
10
|
var _stylexKeyframes = _interopRequireDefault(require("./stylex-keyframes"));
|
9
11
|
var _stylexInclude = _interopRequireWildcard(require("./stylex-include"));
|
10
12
|
var _stylexFirstThatWorks = _interopRequireDefault(require("./stylex-first-that-works"));
|
13
|
+
var _hash = _interopRequireDefault(require("./hash"));
|
14
|
+
var _fileBasedIdentifier = _interopRequireDefault(require("./utils/file-based-identifier"));
|
11
15
|
var m = _interopRequireWildcard(require("./messages"));
|
12
|
-
|
13
|
-
|
16
|
+
var _types = _interopRequireWildcard(require("./types"));
|
17
|
+
exports.types = _types;
|
18
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
19
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
14
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
// These are the implementations of those functions.
|
28
|
-
|
29
|
-
const create = _stylexCreate.default;
|
30
|
-
exports.create = create;
|
31
|
-
const keyframes = _stylexKeyframes.default;
|
32
|
-
exports.keyframes = keyframes;
|
33
|
-
const include = _stylexInclude.default;
|
34
|
-
exports.include = include;
|
35
|
-
const messages = m;
|
36
|
-
exports.messages = messages;
|
37
|
-
const IncludedStyles = _stylexInclude.IncludedStyles;
|
38
|
-
exports.IncludedStyles = IncludedStyles;
|
39
|
-
const firstThatWorks = _stylexFirstThatWorks.default;
|
40
|
-
exports.firstThatWorks = firstThatWorks;
|
21
|
+
const create = exports.create = _stylexCreate.default;
|
22
|
+
const defineVars = exports.defineVars = _stylexDefineVars.default;
|
23
|
+
const createTheme = exports.createTheme = _stylexCreateTheme.default;
|
24
|
+
const keyframes = exports.keyframes = _stylexKeyframes.default;
|
25
|
+
const include = exports.include = _stylexInclude.default;
|
26
|
+
const utils = exports.utils = {
|
27
|
+
hash: _hash.default,
|
28
|
+
genFileBasedIdentifier: _fileBasedIdentifier.default
|
29
|
+
};
|
30
|
+
const messages = exports.messages = m;
|
31
|
+
const IncludedStyles = exports.IncludedStyles = _stylexInclude.IncludedStyles;
|
32
|
+
const firstThatWorks = exports.firstThatWorks = _stylexFirstThatWorks.default;
|
package/lib/index.js.flow
CHANGED
@@ -1,5 +1,59 @@
|
|
1
1
|
/**
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
5
8
|
*/
|
9
|
+
|
10
|
+
export type {
|
11
|
+
RawStyles,
|
12
|
+
StyleRule,
|
13
|
+
TNestableStyleValue,
|
14
|
+
TRawValue,
|
15
|
+
TStyleValue,
|
16
|
+
} from './common-types';
|
17
|
+
|
18
|
+
// All functions exposed from `stylex` are defined in a way that can be run
|
19
|
+
// entirely in the browser.
|
20
|
+
|
21
|
+
// These are the implementations of those functions.
|
22
|
+
|
23
|
+
import styleXCreateSet from './stylex-create';
|
24
|
+
import styleXDefineVars from './stylex-define-vars';
|
25
|
+
import styleXCreateTheme from './stylex-create-theme';
|
26
|
+
import stylexKeyframes from './stylex-keyframes';
|
27
|
+
import stylexInclude, {
|
28
|
+
IncludedStyles as _IncludedStyles,
|
29
|
+
} from './stylex-include';
|
30
|
+
import stylexFirstThatWorks from './stylex-first-that-works';
|
31
|
+
import hash from './hash';
|
32
|
+
import genFileBasedIdentifier from './utils/file-based-identifier';
|
33
|
+
import * as m from './messages';
|
34
|
+
export * as types from './types';
|
35
|
+
|
36
|
+
import type {
|
37
|
+
InjectableStyle as _InjectableStyle,
|
38
|
+
CompiledNamespaces as _CompiledNamespaces,
|
39
|
+
MutableCompiledNamespaces as _MutableCompiledNamespaces,
|
40
|
+
StyleXOptions as _StyleXOptions,
|
41
|
+
} from './common-types';
|
42
|
+
|
43
|
+
declare export const create: typeof styleXCreateSet;
|
44
|
+
declare export const defineVars: typeof styleXDefineVars;
|
45
|
+
declare export const createTheme: typeof styleXCreateTheme;
|
46
|
+
declare export const keyframes: typeof stylexKeyframes;
|
47
|
+
declare export const include: typeof stylexInclude;
|
48
|
+
declare export const utils: {
|
49
|
+
hash: typeof hash,
|
50
|
+
genFileBasedIdentifier: typeof genFileBasedIdentifier,
|
51
|
+
};
|
52
|
+
declare export const messages: typeof m;
|
53
|
+
declare export const IncludedStyles: typeof _IncludedStyles;
|
54
|
+
declare export const firstThatWorks: typeof stylexFirstThatWorks;
|
55
|
+
|
56
|
+
export type InjectableStyle = _InjectableStyle;
|
57
|
+
export type CompiledNamespaces = _CompiledNamespaces;
|
58
|
+
export type MutableCompiledNamespaces = _MutableCompiledNamespaces;
|
59
|
+
export type StyleXOptions = _StyleXOptions;
|