@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
@@ -0,0 +1,26 @@
|
|
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, StyleXOptions } from './common-types';
|
11
|
+
declare function styleXCreateTheme(
|
12
|
+
themeVars: {
|
13
|
+
readonly __themeName__: string;
|
14
|
+
readonly [$$Key$$: string]: string;
|
15
|
+
},
|
16
|
+
variables: {
|
17
|
+
readonly [$$Key$$: string]:
|
18
|
+
| string
|
19
|
+
| { default: string; readonly [$$Key$$: string]: string };
|
20
|
+
},
|
21
|
+
options?: StyleXOptions,
|
22
|
+
): [
|
23
|
+
{ $$css: true; readonly [$$Key$$: string]: string },
|
24
|
+
{ [$$Key$$: string]: InjectableStyle },
|
25
|
+
];
|
26
|
+
export default styleXCreateTheme;
|
@@ -0,0 +1,67 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = styleXCreateTheme;
|
7
|
+
var _hash = _interopRequireDefault(require("./hash"));
|
8
|
+
var _defaultOptions = require("./utils/default-options");
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
function styleXCreateTheme(themeVars, variables, options) {
|
11
|
+
if (typeof themeVars.__themeName__ !== 'string') {
|
12
|
+
throw new Error('Can only override variables theme created with stylex.defineVars().');
|
13
|
+
}
|
14
|
+
const {
|
15
|
+
classNamePrefix
|
16
|
+
} = {
|
17
|
+
..._defaultOptions.defaultOptions,
|
18
|
+
...options
|
19
|
+
};
|
20
|
+
const sortedKeys = Object.keys(variables).sort();
|
21
|
+
const atRules = {};
|
22
|
+
const cssVariablesOverrideString = sortedKeys.map(key => {
|
23
|
+
const varNameHash = themeVars[key].slice(4, -1);
|
24
|
+
const value = variables[key];
|
25
|
+
if (varNameHash != null && value !== null && typeof value === 'object') {
|
26
|
+
if (value.default === undefined) {
|
27
|
+
throw new Error('Default value is not defined for ' + key + ' variable.');
|
28
|
+
}
|
29
|
+
const definedVarString = `${varNameHash}:${value.default};`;
|
30
|
+
Object.keys(value).forEach(key => {
|
31
|
+
if (key.startsWith('@')) {
|
32
|
+
const definedVarStringForAtRule = `${varNameHash}:${value[key]};`;
|
33
|
+
if (atRules[key] == null) {
|
34
|
+
atRules[key] = [definedVarStringForAtRule];
|
35
|
+
} else {
|
36
|
+
atRules[key].push(definedVarStringForAtRule);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
});
|
40
|
+
return definedVarString;
|
41
|
+
}
|
42
|
+
return varNameHash != null && typeof value !== 'object' ? `${varNameHash}:${value};` : '';
|
43
|
+
}).join('');
|
44
|
+
const sortedAtRules = Object.keys(atRules).sort();
|
45
|
+
const atRulesStringForHash = sortedAtRules.map(atRule => {
|
46
|
+
return `${atRule}{${atRules[atRule].sort().join('')}}`;
|
47
|
+
}).join('');
|
48
|
+
const overrideClassName = classNamePrefix + (0, _hash.default)(cssVariablesOverrideString + atRulesStringForHash);
|
49
|
+
const stylesToInject = {
|
50
|
+
[overrideClassName]: {
|
51
|
+
ltr: `.${overrideClassName}{${cssVariablesOverrideString}}`,
|
52
|
+
priority: 0.8,
|
53
|
+
rtl: undefined
|
54
|
+
}
|
55
|
+
};
|
56
|
+
for (const atRule of sortedAtRules) {
|
57
|
+
stylesToInject[overrideClassName + '-' + (0, _hash.default)(atRule)] = {
|
58
|
+
ltr: `${atRule}{.${overrideClassName}{${atRules[atRule].join('')}}}`,
|
59
|
+
priority: 0.9,
|
60
|
+
rtl: null
|
61
|
+
};
|
62
|
+
}
|
63
|
+
return [{
|
64
|
+
$$css: true,
|
65
|
+
[themeVars.__themeName__]: overrideClassName
|
66
|
+
}, stylesToInject];
|
67
|
+
}
|
@@ -0,0 +1,19 @@
|
|
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
|
+
// It takes an object of variables with their values and the original set of variables to override
|
13
|
+
// and returns a hashed className with variables overrides.
|
14
|
+
//
|
15
|
+
declare export default function styleXCreateTheme(
|
16
|
+
themeVars: { +__themeName__: string, +[string]: string },
|
17
|
+
variables: { +[string]: string | { default: string, +[string]: string } },
|
18
|
+
options?: StyleXOptions,
|
19
|
+
): [{ $$css: true, +[string]: string }, { [string]: InjectableStyle }];
|
@@ -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
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
import type {
|
11
|
+
RawStyles,
|
12
|
+
InjectableStyle,
|
13
|
+
StyleXOptions,
|
14
|
+
FlatCompiledStyles,
|
15
|
+
} from './common-types';
|
16
|
+
declare function styleXCreateSet(
|
17
|
+
namespaces: { readonly [$$Key$$: string]: RawStyles },
|
18
|
+
options?: StyleXOptions,
|
19
|
+
): [
|
20
|
+
{ [$$Key$$: string]: FlatCompiledStyles },
|
21
|
+
{ [$$Key$$: string]: InjectableStyle },
|
22
|
+
];
|
23
|
+
export default styleXCreateSet;
|
package/lib/stylex-create.js
CHANGED
@@ -4,163 +4,47 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = styleXCreateSet;
|
7
|
-
var _convertToClassName = _interopRequireDefault(require("./convert-to-className"));
|
8
|
-
var _index = _interopRequireWildcard(require("./preprocess-rules/index"));
|
9
7
|
var _objectUtils = require("./utils/object-utils");
|
10
|
-
var messages = _interopRequireWildcard(require("./messages"));
|
11
8
|
var _stylexInclude = require("./stylex-include");
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
// This takes the object of styles passed to `stylex.create` and transforms it.
|
25
|
-
// The transformation replaces style values with classNames.
|
26
|
-
//
|
27
|
-
// It also collects all injected styles along the way.
|
28
|
-
// It then returns a tuple of the transformed style Object and an object of injected styles.
|
29
|
-
//
|
30
|
-
// This function does some basic validation, and then uses `styleXCreateNamespace` to transform
|
31
|
-
// each namespace within,
|
32
|
-
//
|
33
|
-
// Before returning, it ensures that there are no duplicate styles being injected.
|
9
|
+
var _defaultOptions = require("./utils/default-options");
|
10
|
+
var _flattenRawStyleObj = require("./preprocess-rules/flatten-raw-style-obj");
|
11
|
+
var _basicValidation = require("./preprocess-rules/basic-validation");
|
34
12
|
function styleXCreateSet(namespaces) {
|
35
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] :
|
13
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaultOptions.defaultOptions;
|
36
14
|
const resolvedNamespaces = {};
|
37
15
|
const injectedStyles = {};
|
38
16
|
for (const namespaceName of Object.keys(namespaces)) {
|
39
17
|
const namespace = namespaces[namespaceName];
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
const
|
47
|
-
const
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
for (const cn of Object.keys(injected)) {
|
53
|
-
if (injectedStyles[cn] == null) {
|
54
|
-
injectedStyles[cn] = injected[cn];
|
55
|
-
}
|
56
|
-
}
|
57
|
-
}
|
58
|
-
return [resolvedNamespaces, injectedStyles];
|
59
|
-
}
|
60
|
-
|
61
|
-
// Transforms a single style namespace.
|
62
|
-
// e.g. Something along the lines of:
|
63
|
-
// {color: 'red', margin: '10px'} =>
|
64
|
-
// {
|
65
|
-
// color: 'color-red',
|
66
|
-
// marginTop: 'margin-top-10px',
|
67
|
-
// marginBottom: 'margin-bottom-10px',
|
68
|
-
// marginStart: 'margin-start-10px',
|
69
|
-
// marginEnd: 'margin-end-10px'
|
70
|
-
// }
|
71
|
-
//
|
72
|
-
// First, it expands shorthand properties. (margin => marginTop, marginBottom, marginStart, marginEnd)
|
73
|
-
// Then, it converts each style value to a className.
|
74
|
-
// Then, it returns the transformed style Object and an object of injected styles.
|
75
|
-
function styleXCreateNamespace(style, options) {
|
76
|
-
const namespaceEntries = (0, _objectUtils.objEntries)(style);
|
77
|
-
|
78
|
-
// First handle shorthands. The strategy for this is based on the `styleResolution` option.
|
79
|
-
const entries = namespaceEntries.flatMap(_ref => {
|
80
|
-
let [key, value] = _ref;
|
81
|
-
// Detect style ...spreads and leave them unmodified
|
82
|
-
if (value instanceof _stylexInclude.IncludedStyles) {
|
83
|
-
return [[key, value]];
|
84
|
-
}
|
85
|
-
// Detect nested style objects.
|
86
|
-
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
|
87
|
-
// Nested Objects are only allowed for legacy :pseudo, @media or long-hand properties for now.
|
88
|
-
// In the future, we will try to support shorthands as well.
|
89
|
-
if (!key.startsWith(':') && !key.startsWith('@') && (0, _index.getExpandedKeys)(options).includes(key)) {
|
90
|
-
throw new Error(messages.INVALID_PSEUDO);
|
91
|
-
}
|
92
|
-
return [[key, (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(value).flatMap(_ref2 => {
|
93
|
-
let [innerKey, innerValue] = _ref2;
|
94
|
-
if (innerValue != null && typeof innerValue === 'object' && !Array.isArray(innerValue)) {
|
95
|
-
throw new Error(messages.ILLEGAL_NESTED_PSEUDO);
|
96
|
-
}
|
97
|
-
return (0, _index.default)([innerKey, innerValue], options);
|
98
|
-
}))]];
|
99
|
-
} else {
|
100
|
-
if (value !== null && typeof value !== 'string' && typeof value !== 'number' && !Array.isArray(value)) {
|
101
|
-
throw new Error(messages.ILLEGAL_PROP_VALUE);
|
102
|
-
}
|
103
|
-
if (Array.isArray(value) && value.some(val => typeof val === 'object')) {
|
104
|
-
throw new Error(messages.ILLEGAL_PROP_ARRAY_VALUE);
|
105
|
-
}
|
106
|
-
return (0, _index.default)([key, value], options);
|
107
|
-
}
|
108
|
-
});
|
109
|
-
|
110
|
-
// Now each [key, value] pair is considered a single atomic style.
|
111
|
-
// This atomic style is converted to a className by hashing
|
112
|
-
//
|
113
|
-
// The [key, className] pair is then added to the output Object: `resolvedNamespace`.
|
114
|
-
// While hashing, the CSS rule that the className is generated from is also added to the output Object: `injectedStyles`.
|
115
|
-
const resolvedNamespace = {};
|
116
|
-
const injectedStyles = {};
|
117
|
-
for (const [key, val] of entries) {
|
118
|
-
if (val instanceof _stylexInclude.IncludedStyles) {
|
119
|
-
resolvedNamespace[key] = val;
|
120
|
-
} else if (val != null && typeof val === 'object' && !Array.isArray(val)) {
|
121
|
-
if (key.startsWith(':') || key.startsWith('@')) {
|
122
|
-
const pseudo = key;
|
123
|
-
const innerObj = {};
|
124
|
-
for (const [innerKey, innerVal] of (0, _objectUtils.objEntries)(val)) {
|
125
|
-
if (innerVal === null) {
|
126
|
-
innerObj[innerKey] = null;
|
127
|
-
} else if (typeof innerVal === 'object' && !Array.isArray(innerVal)) {
|
128
|
-
throw new Error(messages.ILLEGAL_NESTED_PSEUDO);
|
129
|
-
} else {
|
130
|
-
const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([innerKey, innerVal], pseudo, options);
|
131
|
-
innerObj[updatedKey] = className;
|
132
|
-
injectedStyles[updatedKey + pseudo] = [className, cssRule];
|
133
|
-
}
|
134
|
-
}
|
135
|
-
resolvedNamespace[key] = innerObj;
|
18
|
+
(0, _basicValidation.validateNamespace)(namespace);
|
19
|
+
const flattenedNamespace = (0, _flattenRawStyleObj.flattenRawStyleObject)(namespace, options);
|
20
|
+
const compiledNamespaceTuples = flattenedNamespace.map(_ref => {
|
21
|
+
let [key, value] = _ref;
|
22
|
+
return [key, value.compiled(options)];
|
23
|
+
});
|
24
|
+
const compiledNamespace = (0, _objectUtils.objFromEntries)(compiledNamespaceTuples);
|
25
|
+
const namespaceObj = {};
|
26
|
+
for (const key of Object.keys(compiledNamespace)) {
|
27
|
+
const value = compiledNamespace[key];
|
28
|
+
if (value instanceof _stylexInclude.IncludedStyles) {
|
29
|
+
namespaceObj[key] = value;
|
136
30
|
} else {
|
137
|
-
const
|
138
|
-
const
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
if (innerVal !== null) {
|
147
|
-
const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([propKey, innerVal], pseudo === 'default' ? undefined : pseudo, options);
|
148
|
-
injectedStyles[updatedKey + pseudo] = [className, cssRule];
|
149
|
-
classNames.push(className);
|
31
|
+
const classNameTuples = value.map(v => Array.isArray(v) ? v : null).filter(Boolean);
|
32
|
+
const className = classNameTuples.map(_ref2 => {
|
33
|
+
let [className] = _ref2;
|
34
|
+
return className;
|
35
|
+
}).join(' ') || null;
|
36
|
+
namespaceObj[key] = className;
|
37
|
+
for (const [className, injectable] of classNameTuples) {
|
38
|
+
if (injectedStyles[className] == null) {
|
39
|
+
injectedStyles[className] = injectable;
|
150
40
|
}
|
151
41
|
}
|
152
|
-
resolvedNamespace[key] = classNames.join(' ');
|
153
|
-
}
|
154
|
-
} else {
|
155
|
-
if (val === null) {
|
156
|
-
resolvedNamespace[key] = null;
|
157
|
-
} else {
|
158
|
-
const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([key, val], undefined, options);
|
159
|
-
resolvedNamespace[updatedKey] = className;
|
160
|
-
injectedStyles[updatedKey] = [className, cssRule];
|
161
42
|
}
|
162
43
|
}
|
44
|
+
resolvedNamespaces[namespaceName] = {
|
45
|
+
...namespaceObj,
|
46
|
+
$$css: true
|
47
|
+
};
|
163
48
|
}
|
164
|
-
|
165
|
-
return [resolvedNamespace, finalInjectedStyles];
|
49
|
+
return [resolvedNamespaces, injectedStyles];
|
166
50
|
}
|
@@ -0,0 +1,30 @@
|
|
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 {
|
11
|
+
RawStyles,
|
12
|
+
InjectableStyle,
|
13
|
+
StyleXOptions,
|
14
|
+
FlatCompiledStyles,
|
15
|
+
} from './common-types';
|
16
|
+
|
17
|
+
// This takes the object of styles passed to `stylex.create` and transforms it.
|
18
|
+
// The transformation replaces style values with classNames.
|
19
|
+
//
|
20
|
+
// It also collects all injected styles along the way.
|
21
|
+
// It then returns a tuple of the transformed style Object and an object of injected styles.
|
22
|
+
//
|
23
|
+
// This function does some basic validation, and then uses `styleXCreateNamespace` to transform
|
24
|
+
// each namespace within,
|
25
|
+
//
|
26
|
+
// Before returning, it ensures that there are no duplicate styles being injected.
|
27
|
+
declare export default function styleXCreateSet(
|
28
|
+
namespaces: { +[string]: RawStyles },
|
29
|
+
options?: StyleXOptions,
|
30
|
+
): [{ [string]: FlatCompiledStyles }, { [string]: InjectableStyle }];
|
@@ -0,0 +1,29 @@
|
|
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, StyleXOptions } from './common-types';
|
11
|
+
type VarsConfig = Readonly<{
|
12
|
+
[$$Key$$: string]:
|
13
|
+
| string
|
14
|
+
| Readonly<{ default: string; [$$Key$$: string]: string }>;
|
15
|
+
}>;
|
16
|
+
type VarsObject<Vars extends VarsConfig> = Readonly</**
|
17
|
+
* > 17 | ...$ObjMapConst<Vars, string>,
|
18
|
+
* | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with complex spreads" is currently not supported.
|
19
|
+
**/
|
20
|
+
any>;
|
21
|
+
declare function styleXDefineVars<Vars extends VarsConfig>(
|
22
|
+
variables: Vars,
|
23
|
+
options: Readonly<
|
24
|
+
Omit<Partial<StyleXOptions>, keyof ({ themeName: string })> & {
|
25
|
+
themeName: string;
|
26
|
+
}
|
27
|
+
>,
|
28
|
+
): [VarsObject<Vars>, { [$$Key$$: string]: InjectableStyle }];
|
29
|
+
export default styleXDefineVars;
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = styleXDefineVars;
|
7
|
+
var _hash = _interopRequireDefault(require("./hash"));
|
8
|
+
var _objectUtils = require("./utils/object-utils");
|
9
|
+
var _defaultOptions = require("./utils/default-options");
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
function styleXDefineVars(variables, options) {
|
12
|
+
const {
|
13
|
+
classNamePrefix,
|
14
|
+
themeName
|
15
|
+
} = {
|
16
|
+
..._defaultOptions.defaultOptions,
|
17
|
+
...options
|
18
|
+
};
|
19
|
+
const themeNameHash = classNamePrefix + (0, _hash.default)(themeName);
|
20
|
+
const variablesMap = (0, _objectUtils.objMap)(variables, (value, key) => {
|
21
|
+
const nameHash = classNamePrefix + (0, _hash.default)(`${themeName}.${key}`);
|
22
|
+
return {
|
23
|
+
nameHash,
|
24
|
+
value
|
25
|
+
};
|
26
|
+
});
|
27
|
+
const themeVariablesObject = (0, _objectUtils.objMap)(variablesMap, _ref => {
|
28
|
+
let {
|
29
|
+
nameHash
|
30
|
+
} = _ref;
|
31
|
+
return `var(--${nameHash})`;
|
32
|
+
});
|
33
|
+
const injectableStyles = constructCssVariablesString(variablesMap, themeNameHash);
|
34
|
+
return [{
|
35
|
+
...themeVariablesObject,
|
36
|
+
__themeName__: themeNameHash
|
37
|
+
}, injectableStyles];
|
38
|
+
}
|
39
|
+
function constructCssVariablesString(variables, themeNameHash) {
|
40
|
+
const ruleByAtRule = {};
|
41
|
+
for (const [key, {
|
42
|
+
nameHash,
|
43
|
+
value
|
44
|
+
}] of (0, _objectUtils.objEntries)(variables)) {
|
45
|
+
if (value !== null && typeof value === 'object') {
|
46
|
+
if (value.default === undefined) {
|
47
|
+
throw new Error('Default value is not defined for ' + key + ' variable.');
|
48
|
+
}
|
49
|
+
const v = value;
|
50
|
+
for (const [key, value] of (0, _objectUtils.objEntries)(v)) {
|
51
|
+
ruleByAtRule[key] ??= [];
|
52
|
+
ruleByAtRule[key].push(`--${nameHash}:${value};`);
|
53
|
+
}
|
54
|
+
} else {
|
55
|
+
ruleByAtRule.default ??= [];
|
56
|
+
ruleByAtRule.default.push(`--${nameHash}:${value};`);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
const result = {};
|
60
|
+
for (const [key, value] of (0, _objectUtils.objEntries)(ruleByAtRule)) {
|
61
|
+
const suffix = key === 'default' ? '' : `-${(0, _hash.default)(key)}`;
|
62
|
+
let ltr = `:root{${value.join('')}}`;
|
63
|
+
if (key !== 'default') {
|
64
|
+
ltr = `${key}{${ltr}}`;
|
65
|
+
}
|
66
|
+
result[themeNameHash + suffix] = {
|
67
|
+
ltr,
|
68
|
+
rtl: null,
|
69
|
+
priority: key === 'default' ? 0 : 0.1
|
70
|
+
};
|
71
|
+
}
|
72
|
+
return result;
|
73
|
+
}
|
@@ -0,0 +1,26 @@
|
|
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
|
+
type VarsConfig = $ReadOnly<{
|
13
|
+
[string]: string | $ReadOnly<{ default: string, [string]: string }>,
|
14
|
+
}>;
|
15
|
+
|
16
|
+
type VarsObject<Vars: VarsConfig> = $ReadOnly<{
|
17
|
+
...$ObjMapConst<Vars, string>,
|
18
|
+
__themeName__: string,
|
19
|
+
}>;
|
20
|
+
|
21
|
+
// Similar to `stylex.create` it takes an object of variables with their values
|
22
|
+
// and returns a string after hashing it.
|
23
|
+
declare export default function styleXDefineVars<Vars: VarsConfig>(
|
24
|
+
variables: Vars,
|
25
|
+
options: $ReadOnly<{ ...Partial<StyleXOptions>, themeName: string, ... }>,
|
26
|
+
): [VarsObject<Vars>, { [string]: InjectableStyle }];
|
@@ -0,0 +1,13 @@
|
|
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 function stylexFirstThatWorks<T>(
|
11
|
+
...args: ReadonlyArray<T>
|
12
|
+
): ReadonlyArray<T>;
|
13
|
+
export default stylexFirstThatWorks;
|
@@ -4,16 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = stylexFirstThatWorks;
|
7
|
-
/**
|
8
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
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
|
-
|
17
7
|
function stylexFirstThatWorks() {
|
18
8
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
19
9
|
args[_key] = arguments[_key];
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
*/
|
9
|
+
|
10
|
+
declare export default function stylexFirstThatWorks<T>(
|
11
|
+
...args: $ReadOnlyArray<T>
|
12
|
+
): $ReadOnlyArray<T>;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
export declare class IncludedStyles {
|
11
|
+
astNode: any;
|
12
|
+
constructor(astNode: any);
|
13
|
+
}
|
14
|
+
declare function stylexInclude(
|
15
|
+
firstArg: any,
|
16
|
+
...styles: any
|
17
|
+
): { [key: string]: IncludedStyles };
|
18
|
+
export default stylexInclude;
|
package/lib/stylex-include.js
CHANGED
@@ -6,18 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.IncludedStyles = void 0;
|
7
7
|
exports.default = stylexInclude;
|
8
8
|
var messages = _interopRequireWildcard(require("./messages"));
|
9
|
-
function _getRequireWildcardCache(
|
10
|
-
function _interopRequireWildcard(
|
11
|
-
/**
|
12
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
13
|
-
*
|
14
|
-
* This source code is licensed under the MIT license found in the
|
15
|
-
* LICENSE file in the root directory of this source tree.
|
16
|
-
*
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*/
|
20
|
-
|
9
|
+
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); }
|
10
|
+
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; }
|
21
11
|
let number = 0;
|
22
12
|
function uuid() {
|
23
13
|
return `__included_${++number}__`;
|
@@ -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
|
+
declare export class IncludedStyles {
|
11
|
+
astNode: any;
|
12
|
+
constructor(astNode: any): void;
|
13
|
+
}
|
14
|
+
|
15
|
+
declare export default function stylexInclude(
|
16
|
+
firstArg: any,
|
17
|
+
...styles: any
|
18
|
+
): {
|
19
|
+
[key: string]: IncludedStyles,
|
20
|
+
};
|
@@ -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, StyleXOptions } from './common-types';
|
11
|
+
declare function styleXKeyframes(
|
12
|
+
frames: {
|
13
|
+
readonly [$$Key$$: string]: { readonly [$$Key$$: string]: string | number };
|
14
|
+
},
|
15
|
+
options: StyleXOptions,
|
16
|
+
): [string, InjectableStyle];
|
17
|
+
export default styleXKeyframes;
|