@stylexjs/shared 0.1.0-beta.7 → 0.2.0-beta.11
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +81 -0
- package/lib/convert-to-className.js +13 -6
- package/lib/expand-shorthands.d.ts +5 -0
- package/lib/expand-shorthands.js +241 -101
- package/lib/generate-css-rule.js +10 -38
- package/lib/index.d.ts +10 -0
- package/lib/index.js.flow +5 -0
- package/lib/messages.js +11 -3
- package/lib/namespace-transforms/__tests__/preflatten.test.js +120 -0
- package/lib/namespace-transforms/preflatten.js +89 -0
- package/lib/physical-rtl/generate-ltr.js +32 -32
- package/lib/physical-rtl/generate-rtl.js +30 -30
- package/lib/preprocess-rules/PreRule.js +101 -0
- package/lib/preprocess-rules/application-order.js +259 -0
- package/lib/preprocess-rules/basic-validation.js +92 -0
- package/lib/preprocess-rules/expand-shorthands.js +156 -0
- package/lib/preprocess-rules/flatten-raw-style-obj.js +148 -0
- package/lib/preprocess-rules/index.js +39 -0
- package/lib/preprocess-rules/legacy-expand-shorthands.js +219 -0
- package/lib/preprocess-rules/null-out-longhand.js +310 -0
- package/lib/preprocess-rules/property-specificity.js +135 -0
- package/lib/preprocess-rules/react-native-web.js +142 -0
- package/lib/stylex-create-vars.js +59 -0
- package/lib/stylex-create.js +30 -101
- package/lib/stylex-defaultValue.js +230 -98
- package/lib/stylex-keyframes.js +23 -10
- package/lib/utils/Rule.js +71 -0
- package/lib/utils/default-options.js +34 -0
- package/lib/utils/genCSSRule.js +9 -8
- package/lib/utils/normalize-value.js +3 -0
- package/lib/utils/object-utils.js +23 -2
- package/lib/utils/property-priorities.js +116 -0
- package/lib/utils/split-css-value.js +47 -0
- package/lib/validate.js +1 -1
- package/package.json +2 -4
@@ -0,0 +1,135 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _splitCssValue = _interopRequireDefault(require("../utils/split-css-value"));
|
8
|
+
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
|
+
const shorthands = {
|
19
|
+
all: _ => {
|
20
|
+
throw new Error('all is not supported');
|
21
|
+
},
|
22
|
+
animation: _value => {
|
23
|
+
throw new Error('animation is not supported');
|
24
|
+
},
|
25
|
+
background: _value => {
|
26
|
+
throw new Error('background is not supported. Use background-color, border-image etc. instead.');
|
27
|
+
},
|
28
|
+
border: _rawValue => {
|
29
|
+
throw new Error('border is not supported. Use border-width, border-style and border-color instead.');
|
30
|
+
},
|
31
|
+
borderInline: _rawValue => {
|
32
|
+
throw new Error('borderInline is not supported. Use borderInlineWidth, borderInlineStyle and borderInlineColor instead.');
|
33
|
+
},
|
34
|
+
// @Deprecated
|
35
|
+
borderBlock: _rawValue => {
|
36
|
+
throw new Error('borderBlock is not supported. Use borderBlockWidth, borderBlockStyle and borderBlockColor instead.');
|
37
|
+
},
|
38
|
+
// @Deprecated
|
39
|
+
borderTop: _rawValue => {
|
40
|
+
throw new Error('borderTop is not supported. Use borderTopWidth, borderTopStyle and borderTopColor instead.');
|
41
|
+
},
|
42
|
+
// @Deprecated
|
43
|
+
borderInlineEnd: _rawValue => {
|
44
|
+
throw new Error('borderInlineEnd is not supported. Use borderInlineEndWidth, borderInlineEndStyle and borderInlineEndColor instead.');
|
45
|
+
},
|
46
|
+
// @Deprecated
|
47
|
+
borderRight: _rawValue => {
|
48
|
+
throw new Error('borderRight is not supported. Use borderRightWidth, borderRightStyle and borderRightColor instead.');
|
49
|
+
},
|
50
|
+
// @Deprecated
|
51
|
+
borderBottom: _rawValue => {
|
52
|
+
throw new Error('borderBottom is not supported. Use borderBottomWidth, borderBottomStyle and borderBottomColor instead.');
|
53
|
+
},
|
54
|
+
// @Deprecated
|
55
|
+
borderInlineStart: _rawValue => {
|
56
|
+
throw new Error('borderInlineStart is not supported. Use borderInlineStartWidth, borderInlineStartStyle and borderInlineStartColor instead.');
|
57
|
+
},
|
58
|
+
// @Deprecated
|
59
|
+
borderLeft: _rawValue => {
|
60
|
+
throw new Error(['`borderLeft` is not supported.', 'You could use `borderLeftWidth`, `borderLeftStyle` and `borderLeftColor`,', 'but it is preferable to use `borderInlineStartWidth`, `borderInlineStartStyle` and `borderInlineStartColor`.'].join(' '));
|
61
|
+
},
|
62
|
+
margin: value => {
|
63
|
+
const values = (0, _splitCssValue.default)(value);
|
64
|
+
if (values.length === 1) {
|
65
|
+
return [['margin', values[0]]];
|
66
|
+
} else {
|
67
|
+
throw new Error('margin shorthand with multiple values is not supported. Use marginTop, marginInlineEnd, marginBottom and marginInlineStart instead.');
|
68
|
+
}
|
69
|
+
},
|
70
|
+
padding: rawValue => {
|
71
|
+
const values = (0, _splitCssValue.default)(rawValue);
|
72
|
+
if (values.length === 1) {
|
73
|
+
return [['padding', values[0]]];
|
74
|
+
}
|
75
|
+
throw new Error('padding shorthand with multiple values is not supported. Use paddingTop, paddingInlineEnd, paddingBottom and paddingInlineStart instead.');
|
76
|
+
}
|
77
|
+
};
|
78
|
+
const aliases = {
|
79
|
+
// @UNSUPPORTED
|
80
|
+
borderHorizontal: shorthands.borderInline,
|
81
|
+
// @UNSUPPORTED
|
82
|
+
borderVertical: shorthands.borderBlock,
|
83
|
+
// @UNSUPPORTED
|
84
|
+
borderBlockStart: shorthands.borderTop,
|
85
|
+
// @UNSUPPORTED
|
86
|
+
borderEnd: shorthands.borderInlineEnd,
|
87
|
+
// @UNSUPPORTED
|
88
|
+
borderBlockEnd: shorthands.borderBottom,
|
89
|
+
// @UNSUPPORTED
|
90
|
+
borderStart: shorthands.borderInlineStart,
|
91
|
+
borderHorizontalWidth: value => [['borderInlineWidth', value]],
|
92
|
+
borderHorizontalStyle: value => [['borderInlineStyle', value]],
|
93
|
+
borderHorizontalColor: value => [['borderInlineColor', value]],
|
94
|
+
borderVerticalWidth: value => [['borderBlockWidth', value]],
|
95
|
+
borderVerticalStyle: value => [['borderBlockStyle', value]],
|
96
|
+
borderVerticalColor: value => [['borderBlockColor', value]],
|
97
|
+
borderBlockStartColor: value => [['borderTopColor', value]],
|
98
|
+
borderBlockEndColor: value => [['borderBottomColor', value]],
|
99
|
+
borderBlockStartStyle: value => [['borderTopStyle', value]],
|
100
|
+
borderBlockEndStyle: value => [['borderBottomStyle', value]],
|
101
|
+
borderBlockStartWidth: value => [['borderTopWidth', value]],
|
102
|
+
borderBlockEndWidth: value => [['borderBottomWidth', value]],
|
103
|
+
borderStartColor: value => [['borderInlineStartColor', value]],
|
104
|
+
borderEndColor: value => [['borderInlineEndColor', value]],
|
105
|
+
borderStartStyle: value => [['borderInlineStartStyle', value]],
|
106
|
+
borderEndStyle: value => [['borderInlineEndStyle', value]],
|
107
|
+
borderStartWidth: value => [['borderInlineStartWidth', value]],
|
108
|
+
borderEndWidth: value => [['borderInlineEndWidth', value]],
|
109
|
+
borderTopStartRadius: value => [['borderStartStartRadius', value]],
|
110
|
+
borderTopEndRadius: value => [['borderStartEndRadius', value]],
|
111
|
+
borderBottomStartRadius: value => [['borderEndStartRadius', value]],
|
112
|
+
borderBottomEndRadius: value => [['borderEndEndRadius', value]],
|
113
|
+
marginBlockStart: value => [['marginTop', value]],
|
114
|
+
marginBlockEnd: value => [['marginBottom', value]],
|
115
|
+
marginStart: value => [['marginInlineStart', value]],
|
116
|
+
marginEnd: value => [['marginInlineEnd', value]],
|
117
|
+
marginHorizontal: value => [['marginInline', value]],
|
118
|
+
marginVertical: value => [['marginBlock', value]],
|
119
|
+
paddingBlockStart: rawValue => [['paddingTop', rawValue]],
|
120
|
+
paddingBlockEnd: rawValue => [['paddingBottom', rawValue]],
|
121
|
+
paddingStart: value => [['paddingInlineStart', value]],
|
122
|
+
paddingEnd: value => [['paddingInlineEnd', value]],
|
123
|
+
paddingHorizontal: value => [['paddingInline', value]],
|
124
|
+
paddingVertical: value => [['paddingBlock', value]],
|
125
|
+
insetBlockStart: value => [['top', value]],
|
126
|
+
insetBlockEnd: value => [['bottom', value]],
|
127
|
+
start: value => [['insetInlineStart', value]],
|
128
|
+
end: value => [['insetInlineEnd', value]]
|
129
|
+
};
|
130
|
+
const expansions = {
|
131
|
+
...shorthands,
|
132
|
+
...aliases
|
133
|
+
};
|
134
|
+
var _default = expansions;
|
135
|
+
exports.default = _default;
|
@@ -0,0 +1,142 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _splitCssValue = _interopRequireDefault(require("../utils/split-css-value"));
|
8
|
+
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
|
+
/// # Handle CSS shorthands in a React Native compatible way.
|
19
|
+
///
|
20
|
+
/// This means:
|
21
|
+
/// - disallowing certain properties altogether by throwing errors
|
22
|
+
/// - disallowing multiple values within many shorthands
|
23
|
+
/// - Treating certain non-standard properties as aliases for real CSS properties
|
24
|
+
|
25
|
+
const shorthands = {
|
26
|
+
all: _ => {
|
27
|
+
throw new Error('all is not supported');
|
28
|
+
},
|
29
|
+
animation: value => {
|
30
|
+
throw new Error('animation is not supported');
|
31
|
+
},
|
32
|
+
background: value => {
|
33
|
+
throw new Error('background is not supported. Use background-color, border-image etc. instead.');
|
34
|
+
},
|
35
|
+
border: rawValue => {
|
36
|
+
throw new Error('border is not supported. Use border-width, border-style and border-color instead.');
|
37
|
+
},
|
38
|
+
borderInline: rawValue => {
|
39
|
+
throw new Error('borderInline is not supported. Use borderInlineWidth, borderInlineStyle and borderInlineColor instead.');
|
40
|
+
},
|
41
|
+
// @Deprecated
|
42
|
+
borderBlock: rawValue => {
|
43
|
+
throw new Error('borderBlock is not supported. Use borderBlockWidth, borderBlockStyle and borderBlockColor instead.');
|
44
|
+
},
|
45
|
+
// @Deprecated
|
46
|
+
borderTop: rawValue => {
|
47
|
+
throw new Error('borderTop is not supported. Use borderTopWidth, borderTopStyle and borderTopColor instead.');
|
48
|
+
},
|
49
|
+
// @Deprecated
|
50
|
+
borderInlineEnd: rawValue => {
|
51
|
+
throw new Error('borderInlineEnd is not supported. Use borderInlineEndWidth, borderInlineEndStyle and borderInlineEndColor instead.');
|
52
|
+
},
|
53
|
+
// @Deprecated
|
54
|
+
borderRight: rawValue => {
|
55
|
+
throw new Error('borderRight is not supported. Use borderRightWidth, borderRightStyle and borderRightColor instead.');
|
56
|
+
},
|
57
|
+
// @Deprecated
|
58
|
+
borderBottom: rawValue => {
|
59
|
+
throw new Error('borderBottom is not supported. Use borderBottomWidth, borderBottomStyle and borderBottomColor instead.');
|
60
|
+
},
|
61
|
+
// @Deprecated
|
62
|
+
borderInlineStart: rawValue => {
|
63
|
+
throw new Error('borderInlineStart is not supported. Use borderInlineStartWidth, borderInlineStartStyle and borderInlineStartColor instead.');
|
64
|
+
},
|
65
|
+
// @Deprecated
|
66
|
+
borderLeft: rawValue => {
|
67
|
+
throw new Error(['`borderLeft` is not supported.', 'You could use `borderLeftWidth`, `borderLeftStyle` and `borderLeftColor`,', 'but it is preferable to use `borderInlineStartWidth`, `borderInlineStartStyle` and `borderInlineStartColor`.'].join(' '));
|
68
|
+
},
|
69
|
+
margin: value => {
|
70
|
+
const values = typeof value === 'number' ? [value] : (0, _splitCssValue.default)(value);
|
71
|
+
if (values.length === 1) {
|
72
|
+
return [['margin', values[0]]];
|
73
|
+
} else {
|
74
|
+
throw new Error('margin shorthand with multiple values is not supported. Use marginTop, marginInlineEnd, marginBottom and marginInlineStart instead.');
|
75
|
+
}
|
76
|
+
},
|
77
|
+
padding: rawValue => {
|
78
|
+
const values = typeof rawValue === 'number' ? [rawValue] : (0, _splitCssValue.default)(rawValue);
|
79
|
+
if (values.length === 1) {
|
80
|
+
return [['padding', values[0]]];
|
81
|
+
}
|
82
|
+
throw new Error('padding shorthand with multiple values is not supported. Use paddingTop, paddingInlineEnd, paddingBottom and paddingInlineStart instead.');
|
83
|
+
}
|
84
|
+
};
|
85
|
+
const aliases = {
|
86
|
+
// @UNSUPPORTED
|
87
|
+
borderHorizontal: shorthands.borderInline,
|
88
|
+
// @UNSUPPORTED
|
89
|
+
borderVertical: shorthands.borderBlock,
|
90
|
+
// @UNSUPPORTED
|
91
|
+
borderBlockStart: shorthands.borderTop,
|
92
|
+
// @UNSUPPORTED
|
93
|
+
borderEnd: shorthands.borderInlineEnd,
|
94
|
+
// @UNSUPPORTED
|
95
|
+
borderBlockEnd: shorthands.borderBottom,
|
96
|
+
// @UNSUPPORTED
|
97
|
+
borderStart: shorthands.borderInlineStart,
|
98
|
+
borderHorizontalWidth: value => [['borderInlineWidth', value]],
|
99
|
+
borderHorizontalStyle: value => [['borderInlineStyle', value]],
|
100
|
+
borderHorizontalColor: value => [['borderInlineColor', value]],
|
101
|
+
borderVerticalWidth: value => [['borderBlockWidth', value]],
|
102
|
+
borderVerticalStyle: value => [['borderBlockStyle', value]],
|
103
|
+
borderVerticalColor: value => [['borderBlockColor', value]],
|
104
|
+
borderBlockStartColor: value => [['borderTopColor', value]],
|
105
|
+
borderBlockEndColor: value => [['borderBottomColor', value]],
|
106
|
+
borderBlockStartStyle: value => [['borderTopStyle', value]],
|
107
|
+
borderBlockEndStyle: value => [['borderBottomStyle', value]],
|
108
|
+
borderBlockStartWidth: value => [['borderTopWidth', value]],
|
109
|
+
borderBlockEndWidth: value => [['borderBottomWidth', value]],
|
110
|
+
borderStartColor: value => [['borderInlineStartColor', value]],
|
111
|
+
borderEndColor: value => [['borderInlineEndColor', value]],
|
112
|
+
borderStartStyle: value => [['borderInlineStartStyle', value]],
|
113
|
+
borderEndStyle: value => [['borderInlineEndStyle', value]],
|
114
|
+
borderStartWidth: value => [['borderInlineStartWidth', value]],
|
115
|
+
borderEndWidth: value => [['borderInlineEndWidth', value]],
|
116
|
+
borderTopStartRadius: value => [['borderStartStartRadius', value]],
|
117
|
+
borderTopEndRadius: value => [['borderStartEndRadius', value]],
|
118
|
+
borderBottomStartRadius: value => [['borderEndStartRadius', value]],
|
119
|
+
borderBottomEndRadius: value => [['borderEndEndRadius', value]],
|
120
|
+
marginBlockStart: value => [['marginTop', value]],
|
121
|
+
marginBlockEnd: value => [['marginBottom', value]],
|
122
|
+
marginStart: value => [['marginInlineStart', value]],
|
123
|
+
marginEnd: value => [['marginInlineEnd', value]],
|
124
|
+
marginHorizontal: value => [['marginInline', value]],
|
125
|
+
marginVertical: value => [['marginBlock', value]],
|
126
|
+
paddingBlockStart: rawValue => [['paddingTop', rawValue]],
|
127
|
+
paddingBlockEnd: rawValue => [['paddingBottom', rawValue]],
|
128
|
+
paddingStart: value => [['paddingInlineStart', value]],
|
129
|
+
paddingEnd: value => [['paddingInlineEnd', value]],
|
130
|
+
paddingHorizontal: value => [['paddingInline', value]],
|
131
|
+
paddingVertical: value => [['paddingBlock', value]],
|
132
|
+
insetBlockStart: value => [['top', value]],
|
133
|
+
insetBlockEnd: value => [['bottom', value]],
|
134
|
+
start: value => [['insetInlineStart', value]],
|
135
|
+
end: value => [['insetInlineEnd', value]]
|
136
|
+
};
|
137
|
+
const expansions = {
|
138
|
+
...shorthands,
|
139
|
+
...aliases
|
140
|
+
};
|
141
|
+
var _default = expansions;
|
142
|
+
exports.default = _default;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = styleXCreateVars;
|
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
|
+
/**
|
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
|
+
// Similar to `stylex.create` it takes an object of variables with their values
|
21
|
+
// and returns a string after hashing it.
|
22
|
+
function styleXCreateVars(variables, options) {
|
23
|
+
const {
|
24
|
+
classNamePrefix,
|
25
|
+
themeName
|
26
|
+
} = {
|
27
|
+
..._defaultOptions.defaultOptions,
|
28
|
+
...options
|
29
|
+
};
|
30
|
+
const themeNameHash = classNamePrefix + (0, _hash.default)(themeName);
|
31
|
+
const variablesMap = (0, _objectUtils.objMap)(variables, (value, key) => {
|
32
|
+
// Created hashed variable names with fileName//themeName//key
|
33
|
+
const nameHash = classNamePrefix + (0, _hash.default)(`${themeName}.${key}`);
|
34
|
+
return {
|
35
|
+
nameHash,
|
36
|
+
value
|
37
|
+
};
|
38
|
+
});
|
39
|
+
const themeVariablesObject = (0, _objectUtils.objMap)(variablesMap, _ref => {
|
40
|
+
let {
|
41
|
+
nameHash
|
42
|
+
} = _ref;
|
43
|
+
return `var(--${nameHash})`;
|
44
|
+
});
|
45
|
+
const cssVariablesString = constructCssVariablesString(variablesMap);
|
46
|
+
return [{
|
47
|
+
...themeVariablesObject,
|
48
|
+
__themeName__: themeNameHash
|
49
|
+
}, {
|
50
|
+
css: cssVariablesString
|
51
|
+
}];
|
52
|
+
}
|
53
|
+
function constructCssVariablesString(variables) {
|
54
|
+
const vars = (0, _objectUtils.objEntries)(variables).map(_ref2 => {
|
55
|
+
let [_, value] = _ref2;
|
56
|
+
return `--${value.nameHash}:${value.value};`;
|
57
|
+
}).join('');
|
58
|
+
return `:root{${vars}}`;
|
59
|
+
}
|
package/lib/stylex-create.js
CHANGED
@@ -4,14 +4,11 @@ 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 _expandShorthands = _interopRequireDefault(require("./expand-shorthands"));
|
9
7
|
var _objectUtils = require("./utils/object-utils");
|
10
|
-
var messages = _interopRequireWildcard(require("./messages"));
|
11
8
|
var _stylexInclude = require("./stylex-include");
|
12
|
-
|
13
|
-
|
14
|
-
|
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");
|
15
12
|
/**
|
16
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
17
14
|
*
|
@@ -32,109 +29,41 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
32
29
|
//
|
33
30
|
// Before returning, it ensures that there are no duplicate styles being injected.
|
34
31
|
function styleXCreateSet(namespaces) {
|
35
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] :
|
32
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaultOptions.defaultOptions;
|
36
33
|
const resolvedNamespaces = {};
|
37
34
|
const injectedStyles = {};
|
38
35
|
for (const namespaceName of Object.keys(namespaces)) {
|
39
36
|
const namespace = namespaces[namespaceName];
|
40
|
-
|
41
|
-
|
37
|
+
(0, _basicValidation.validateNamespace)(namespace);
|
38
|
+
const flattenedNamespace = (0, _flattenRawStyleObj.flattenRawStyleObject)(namespace, options);
|
39
|
+
const compiledNamespaceTuples = flattenedNamespace.map(_ref => {
|
40
|
+
let [key, value] = _ref;
|
41
|
+
return [key, value.compiled(options)];
|
42
|
+
});
|
43
|
+
const compiledNamespace = (0, _objectUtils.objFromEntries)(compiledNamespaceTuples);
|
44
|
+
const namespaceObj = {};
|
45
|
+
for (const key of Object.keys(compiledNamespace)) {
|
46
|
+
const value = compiledNamespace[key];
|
47
|
+
if (value instanceof _stylexInclude.IncludedStyles) {
|
48
|
+
namespaceObj[key] = value;
|
49
|
+
} else {
|
50
|
+
const classNameTuples = value.map(v => Array.isArray(v) ? v : null).filter(Boolean);
|
51
|
+
const className = classNameTuples.map(_ref2 => {
|
52
|
+
let [className] = _ref2;
|
53
|
+
return className;
|
54
|
+
}).join(' ') || null;
|
55
|
+
namespaceObj[key] = className;
|
56
|
+
for (const [className, injectable] of classNameTuples) {
|
57
|
+
if (injectedStyles[className] == null) {
|
58
|
+
injectedStyles[className] = injectable;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
42
62
|
}
|
43
|
-
const [resolvedNamespace, injected] = styleXCreateNamespace(namespace, options);
|
44
|
-
const compiledNamespace = (0, _objectUtils.flattenObject)(resolvedNamespace);
|
45
63
|
resolvedNamespaces[namespaceName] = {
|
46
|
-
...
|
64
|
+
...namespaceObj,
|
47
65
|
$$css: true
|
48
66
|
};
|
49
|
-
for (const cn of Object.keys(injected)) {
|
50
|
-
if (injectedStyles[cn] == null) {
|
51
|
-
injectedStyles[cn] = injected[cn];
|
52
|
-
}
|
53
|
-
}
|
54
67
|
}
|
55
68
|
return [resolvedNamespaces, injectedStyles];
|
56
|
-
}
|
57
|
-
|
58
|
-
// Transforms a single style namespace.
|
59
|
-
// e.g. Something along the lines of:
|
60
|
-
// {color: 'red', margin: '10px'} =>
|
61
|
-
// {
|
62
|
-
// color: 'color-red',
|
63
|
-
// marginTop: 'margin-top-10px',
|
64
|
-
// marginBottom: 'margin-bottom-10px',
|
65
|
-
// marginStart: 'margin-start-10px',
|
66
|
-
// marginEnd: 'margin-end-10px'
|
67
|
-
// }
|
68
|
-
//
|
69
|
-
// First, it expands shorthand properties. (margin => marginTop, marginBottom, marginStart, marginEnd)
|
70
|
-
// Then, it converts each style value to a className.
|
71
|
-
// Then, it returns the transformed style Object and an object of injected styles.
|
72
|
-
function styleXCreateNamespace(style, options) {
|
73
|
-
const namespaceEntries = (0, _objectUtils.objEntries)(style);
|
74
|
-
|
75
|
-
// First the shorthand properties are expanded.
|
76
|
-
// e.g. `margin` gets expanded to `marginTop`, `marginBottom`, `marginStart`, `marginEnd`.
|
77
|
-
// `entries` is an array of [key, value] pairs.
|
78
|
-
const entries = namespaceEntries.flatMap(_ref => {
|
79
|
-
let [key, value] = _ref;
|
80
|
-
if (value instanceof _stylexInclude.IncludedStyles) {
|
81
|
-
return [[key, value]];
|
82
|
-
}
|
83
|
-
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
|
84
|
-
if (!key.startsWith(':') && !key.startsWith('@')) {
|
85
|
-
throw new Error(messages.INVALID_PSEUDO);
|
86
|
-
}
|
87
|
-
return [[key, (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(value).flatMap(_ref2 => {
|
88
|
-
let [innerKey, innerValue] = _ref2;
|
89
|
-
if (innerValue != null && typeof innerValue === 'object' && !Array.isArray(innerValue)) {
|
90
|
-
throw new Error(messages.ILLEGAL_NESTED_PSEUDO);
|
91
|
-
}
|
92
|
-
return (0, _expandShorthands.default)([innerKey, innerValue]);
|
93
|
-
}))]];
|
94
|
-
} else {
|
95
|
-
if (value !== null && typeof value !== 'string' && typeof value !== 'number' && !Array.isArray(value)) {
|
96
|
-
throw new Error(messages.ILLEGAL_PROP_VALUE);
|
97
|
-
}
|
98
|
-
if (Array.isArray(value) && value.some(val => typeof val === 'object')) {
|
99
|
-
throw new Error(messages.ILLEGAL_PROP_ARRAY_VALUE);
|
100
|
-
}
|
101
|
-
return (0, _expandShorthands.default)([key, value]);
|
102
|
-
}
|
103
|
-
});
|
104
|
-
|
105
|
-
// Now each [key, value] pair is considered a single atomic style.
|
106
|
-
// This atomic style is converted to a className by hashing
|
107
|
-
//
|
108
|
-
// The [key, className] pair is then added to the output Object: `resolvedNamespace`.
|
109
|
-
// While hashing, the CSS rule that the className is generated from is also added to the output Object: `injectedStyles`.
|
110
|
-
const resolvedNamespace = {};
|
111
|
-
const injectedStyles = {};
|
112
|
-
for (const [key, val] of entries) {
|
113
|
-
if (val instanceof _stylexInclude.IncludedStyles) {
|
114
|
-
resolvedNamespace[key] = val;
|
115
|
-
} else if (val != null && typeof val === 'object' && !Array.isArray(val)) {
|
116
|
-
const pseudo = key;
|
117
|
-
const innerObj = {};
|
118
|
-
for (const [innerKey, innerVal] of (0, _objectUtils.objEntries)(val)) {
|
119
|
-
if (innerVal === null) {
|
120
|
-
innerObj[innerKey] = null;
|
121
|
-
} else {
|
122
|
-
const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([innerKey, innerVal], pseudo, options);
|
123
|
-
innerObj[updatedKey] = className;
|
124
|
-
injectedStyles[updatedKey + pseudo] = [className, cssRule];
|
125
|
-
}
|
126
|
-
}
|
127
|
-
resolvedNamespace[key] = innerObj;
|
128
|
-
} else {
|
129
|
-
if (val === null) {
|
130
|
-
resolvedNamespace[key] = null;
|
131
|
-
} else {
|
132
|
-
const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([key, val], undefined, options);
|
133
|
-
resolvedNamespace[updatedKey] = className;
|
134
|
-
injectedStyles[updatedKey] = [className, cssRule];
|
135
|
-
}
|
136
|
-
}
|
137
|
-
}
|
138
|
-
const finalInjectedStyles = (0, _objectUtils.objFromEntries)((0, _objectUtils.objValues)(injectedStyles));
|
139
|
-
return [resolvedNamespace, finalInjectedStyles];
|
140
69
|
}
|