@stylexjs/shared 0.1.0-beta.7 → 0.2.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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.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 +1 -1
package/lib/messages.js
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
Object.defineProperty(exports, "__esModule", {
|
14
14
|
value: true
|
15
15
|
});
|
16
|
-
exports.UNKNOWN_PROP_KEY = exports.UNKNOWN_NAMESPACE = exports.UNEXPECTED_ARGUMENT = exports.UNBOUND_STYLEX_CALL_VALUE = exports.ONLY_TOP_LEVEL = exports.NO_PARENT_PATH = exports.NON_STATIC_VALUE = exports.NON_OBJECT_FOR_STYLEX_CALL = exports.LOCAL_ONLY = exports.LINT_UNCLOSED_FUNCTION = exports.INVALID_SPREAD = exports.INVALID_PSEUDO = exports.ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_TYPE = exports.ILLEGAL_ARGUMENT_LENGTH = exports.EXPECTED_FUNCTION_CALL = exports.ESCAPED_STYLEX_VALUE = void 0;
|
16
|
+
exports.UNKNOWN_PROP_KEY = exports.UNKNOWN_NAMESPACE = exports.UNEXPECTED_ARGUMENT = exports.UNBOUND_STYLEX_CALL_VALUE = exports.ONLY_TOP_LEVEL_INLCUDES = exports.ONLY_TOP_LEVEL = exports.NO_PARENT_PATH = exports.NO_CONDITIONAL_SHORTHAND = exports.NON_STATIC_VALUE = exports.NON_OBJECT_FOR_STYLEX_CALL = exports.LOCAL_ONLY = exports.LINT_UNCLOSED_FUNCTION = exports.INVALID_SPREAD = exports.INVALID_PSEUDO_OR_AT_RULE = exports.INVALID_PSEUDO = exports.ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_TYPE = exports.ILLEGAL_ARGUMENT_LENGTH = exports.EXPECTED_FUNCTION_CALL = exports.ESCAPED_STYLEX_VALUE = exports.DUPLICATE_CONDITIONAL = void 0;
|
17
17
|
const ILLEGAL_ARGUMENT_LENGTH = 'stylex() should have 1 argument.';
|
18
18
|
exports.ILLEGAL_ARGUMENT_LENGTH = ILLEGAL_ARGUMENT_LENGTH;
|
19
19
|
const NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
|
@@ -30,11 +30,15 @@ const UNKNOWN_PROP_KEY = 'Unknown property key';
|
|
30
30
|
exports.UNKNOWN_PROP_KEY = UNKNOWN_PROP_KEY;
|
31
31
|
const INVALID_PSEUDO = 'Invalid pseudo selector, not on the whitelist.';
|
32
32
|
exports.INVALID_PSEUDO = INVALID_PSEUDO;
|
33
|
+
const INVALID_PSEUDO_OR_AT_RULE = 'Invalid pseudo or at-rule.';
|
34
|
+
exports.INVALID_PSEUDO_OR_AT_RULE = INVALID_PSEUDO_OR_AT_RULE;
|
35
|
+
const NO_CONDITIONAL_SHORTHAND = 'You cannot use conditional style values for a shorthand property.';
|
36
|
+
exports.NO_CONDITIONAL_SHORTHAND = NO_CONDITIONAL_SHORTHAND;
|
33
37
|
const ILLEGAL_NAMESPACE_TYPE = 'Only a string literal namespace is allowed here.';
|
34
38
|
exports.ILLEGAL_NAMESPACE_TYPE = ILLEGAL_NAMESPACE_TYPE;
|
35
39
|
const UNKNOWN_NAMESPACE = 'Unknown namespace';
|
36
40
|
exports.UNKNOWN_NAMESPACE = UNKNOWN_NAMESPACE;
|
37
|
-
const ILLEGAL_NESTED_PSEUDO = "Pseudo objects can't be nested.";
|
41
|
+
const ILLEGAL_NESTED_PSEUDO = "Pseudo objects can't be nested more than one level deep.";
|
38
42
|
exports.ILLEGAL_NESTED_PSEUDO = ILLEGAL_NESTED_PSEUDO;
|
39
43
|
const ILLEGAL_PROP_VALUE = 'A style value can only contain an array, string or number.';
|
40
44
|
exports.ILLEGAL_PROP_VALUE = ILLEGAL_PROP_VALUE;
|
@@ -53,4 +57,8 @@ exports.UNEXPECTED_ARGUMENT = UNEXPECTED_ARGUMENT;
|
|
53
57
|
const EXPECTED_FUNCTION_CALL = 'Expected a simple function call but found something else.';
|
54
58
|
exports.EXPECTED_FUNCTION_CALL = EXPECTED_FUNCTION_CALL;
|
55
59
|
const NO_PARENT_PATH = 'Unexpected AST node without a parent path.';
|
56
|
-
exports.NO_PARENT_PATH = NO_PARENT_PATH;
|
60
|
+
exports.NO_PARENT_PATH = NO_PARENT_PATH;
|
61
|
+
const ONLY_TOP_LEVEL_INLCUDES = 'stylex.include() is only at the top level of a style definition object.';
|
62
|
+
exports.ONLY_TOP_LEVEL_INLCUDES = ONLY_TOP_LEVEL_INLCUDES;
|
63
|
+
const DUPLICATE_CONDITIONAL = 'The same pseudo selector or at-rule cannot be used more than once.';
|
64
|
+
exports.DUPLICATE_CONDITIONAL = DUPLICATE_CONDITIONAL;
|
@@ -0,0 +1,120 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _preflatten = _interopRequireDefault(require("../preflatten"));
|
4
|
+
var _Rule = require("../../utils/Rule");
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
+
/**
|
7
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
8
|
+
*
|
9
|
+
* This source code is licensed under the MIT license found in the
|
10
|
+
* LICENSE file in the root directory of this source tree.
|
11
|
+
*
|
12
|
+
*
|
13
|
+
*
|
14
|
+
*/
|
15
|
+
|
16
|
+
describe('preflatten', () => {
|
17
|
+
test('flattens a simple style object', () => {
|
18
|
+
const input = {
|
19
|
+
color: 'red',
|
20
|
+
backgroundColor: 'blue'
|
21
|
+
};
|
22
|
+
const output = {
|
23
|
+
color: new _Rule.RawRule('color', 'red', [], []),
|
24
|
+
backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], [])
|
25
|
+
};
|
26
|
+
expect((0, _preflatten.default)(input)).toEqual(output);
|
27
|
+
});
|
28
|
+
test('flattens styles with fallback styles', () => {
|
29
|
+
const input = {
|
30
|
+
color: ['red', 'blue'],
|
31
|
+
backgroundColor: 'blue'
|
32
|
+
};
|
33
|
+
const output = {
|
34
|
+
color: new _Rule.RawRuleList([new _Rule.RawRule('color', 'red', [], []), new _Rule.RawRule('color', 'blue', [], [])]),
|
35
|
+
backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], [])
|
36
|
+
};
|
37
|
+
expect((0, _preflatten.default)(input)).toEqual(output);
|
38
|
+
});
|
39
|
+
test('flattens a simple style object with a nested pseudo styles', () => {
|
40
|
+
const input = {
|
41
|
+
color: 'red',
|
42
|
+
backgroundColor: 'blue',
|
43
|
+
':hover': {
|
44
|
+
color: 'green'
|
45
|
+
}
|
46
|
+
};
|
47
|
+
const output = {
|
48
|
+
color: new _Rule.RawRule('color', 'red', [], []),
|
49
|
+
backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], []),
|
50
|
+
':hover_color': new _Rule.RawRule('color', 'green', [':hover'], [])
|
51
|
+
};
|
52
|
+
expect((0, _preflatten.default)(input)).toEqual(output);
|
53
|
+
});
|
54
|
+
test('flattens a simple style object with a nested at-rule styles', () => {
|
55
|
+
const input = {
|
56
|
+
color: 'red',
|
57
|
+
backgroundColor: 'blue',
|
58
|
+
'@media (min-width: 600px)': {
|
59
|
+
color: 'green'
|
60
|
+
}
|
61
|
+
};
|
62
|
+
const output = {
|
63
|
+
color: new _Rule.RawRule('color', 'red', [], []),
|
64
|
+
backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], []),
|
65
|
+
'@media (min-width: 600px)_color': new _Rule.RawRule('color', 'green', [], ['@media (min-width: 600px)'])
|
66
|
+
};
|
67
|
+
expect((0, _preflatten.default)(input)).toEqual(output);
|
68
|
+
});
|
69
|
+
test('flattens style object with nested pseudo in property', () => {
|
70
|
+
const input = {
|
71
|
+
color: {
|
72
|
+
default: 'red',
|
73
|
+
':hover': 'green',
|
74
|
+
':active': 'blue'
|
75
|
+
},
|
76
|
+
backgroundColor: 'blue'
|
77
|
+
};
|
78
|
+
const output = {
|
79
|
+
color: new _Rule.RawRuleList([new _Rule.RawRule('color', 'red', [], []), new _Rule.RawRule('color', 'green', [':hover'], []), new _Rule.RawRule('color', 'blue', [':active'], [])]),
|
80
|
+
backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], [])
|
81
|
+
};
|
82
|
+
expect((0, _preflatten.default)(input)).toEqual(output);
|
83
|
+
});
|
84
|
+
test('flattens style object with nested media queries', () => {
|
85
|
+
const input = {
|
86
|
+
color: {
|
87
|
+
default: 'red',
|
88
|
+
'@media (max-width: 600px)': 'green',
|
89
|
+
'@media (min-width: 600px and max-width: 900px)': 'blue'
|
90
|
+
},
|
91
|
+
backgroundColor: 'blue'
|
92
|
+
};
|
93
|
+
const output = {
|
94
|
+
color: new _Rule.RawRuleList([new _Rule.RawRule('color', 'red', [], []), new _Rule.RawRule('color', 'green', [], ['@media (max-width: 600px)']), new _Rule.RawRule('color', 'blue', [], ['@media (min-width: 600px and max-width: 900px)'])]),
|
95
|
+
backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], [])
|
96
|
+
};
|
97
|
+
expect((0, _preflatten.default)(input)).toEqual(output);
|
98
|
+
});
|
99
|
+
test('flattens style object with nested media queries and pseudo', () => {
|
100
|
+
const input = {
|
101
|
+
color: {
|
102
|
+
default: 'red',
|
103
|
+
'@media (max-width: 600px)': {
|
104
|
+
default: 'green',
|
105
|
+
':hover': 'blue'
|
106
|
+
},
|
107
|
+
'@media (min-width: 600px and max-width: 900px)': {
|
108
|
+
default: 'blue',
|
109
|
+
':hover': 'green'
|
110
|
+
}
|
111
|
+
},
|
112
|
+
backgroundColor: 'blue'
|
113
|
+
};
|
114
|
+
const output = {
|
115
|
+
color: new _Rule.RawRuleList([new _Rule.RawRule('color', 'red', [], []), new _Rule.RawRule('color', 'green', [], ['@media (max-width: 600px)']), new _Rule.RawRule('color', 'blue', [':hover'], ['@media (max-width: 600px)']), new _Rule.RawRule('color', 'blue', [], ['@media (min-width: 600px and max-width: 900px)']), new _Rule.RawRule('color', 'green', [':hover'], ['@media (min-width: 600px and max-width: 900px)'])]),
|
116
|
+
backgroundColor: new _Rule.RawRule('backgroundColor', 'blue', [], [])
|
117
|
+
};
|
118
|
+
expect((0, _preflatten.default)(input)).toEqual(output);
|
119
|
+
});
|
120
|
+
});
|
@@ -0,0 +1,89 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = preflatten;
|
7
|
+
var _Rule = require("../utils/Rule");
|
8
|
+
/**
|
9
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
10
|
+
*
|
11
|
+
* This source code is licensed under the MIT license found in the
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
13
|
+
*
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
|
17
|
+
/// This function takes a Raw Style Object and converts into a flat object of rules.
|
18
|
+
///
|
19
|
+
/// 1. The object is "flat": There will be no nested objects after this function.
|
20
|
+
/// 2. The values are "rules": Each value is the representation of a CSS Rule.
|
21
|
+
function preflatten(namespace) {
|
22
|
+
const result = {};
|
23
|
+
for (const key of Object.keys(namespace)) {
|
24
|
+
const value = namespace[key];
|
25
|
+
if (value === null) {
|
26
|
+
result[key] = null;
|
27
|
+
} else if (Array.isArray(value)) {
|
28
|
+
const allRules = getNestedRules(key, value);
|
29
|
+
if (allRules.length > 1) {
|
30
|
+
result[key] = new _Rule.RawRuleList(allRules);
|
31
|
+
} else if (allRules.length === 1) {
|
32
|
+
result[key] = allRules[0];
|
33
|
+
} else if (allRules.length === 0) {
|
34
|
+
result[key] = null;
|
35
|
+
}
|
36
|
+
} else if (typeof value === 'object' && !Array.isArray(value)) {
|
37
|
+
if (key.startsWith('@') || key.startsWith(':')) {
|
38
|
+
for (const [nestedKey, nestedValue] of Object.entries(value)) {
|
39
|
+
if (nestedValue != null && typeof nestedValue === 'object') {
|
40
|
+
throw new Error('Pseudo and At-Rules cannot be nested.');
|
41
|
+
}
|
42
|
+
result[`${key}_${nestedKey}`] = new _Rule.RawRule(nestedKey, nestedValue, key.startsWith(':') ? [key] : [], key.startsWith('@') ? [key] : []);
|
43
|
+
}
|
44
|
+
} else {
|
45
|
+
/*:: (value: RawStyles); */
|
46
|
+
const allRules = getNestedRules(key, value);
|
47
|
+
if (allRules.length > 1) {
|
48
|
+
result[key] = new _Rule.RawRuleList(allRules);
|
49
|
+
} else if (allRules.length === 1) {
|
50
|
+
result[key] = allRules[0];
|
51
|
+
} else if (allRules.length === 0) {
|
52
|
+
result[key] = null;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
} else {
|
56
|
+
result[key] = new _Rule.RawRule(key, value, [], []);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
return result;
|
60
|
+
}
|
61
|
+
function getNestedRules(key, value) {
|
62
|
+
let pseudos = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
63
|
+
let atRules = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
64
|
+
const result = [];
|
65
|
+
if (value === null) {
|
66
|
+
return result;
|
67
|
+
} else if (Array.isArray(value)) {
|
68
|
+
result.push(new _Rule.RawRuleList(value.map(val => new _Rule.RawRule(key, val, pseudos, atRules))));
|
69
|
+
} else if (typeof value === 'object') {
|
70
|
+
for (const nestedKey of Object.keys(value)) {
|
71
|
+
const nestedValue = value[nestedKey];
|
72
|
+
if (nestedKey.startsWith('@')) {
|
73
|
+
result.push(...getNestedRules(key, nestedValue, pseudos, [...atRules, nestedKey]));
|
74
|
+
} else if (nestedKey.startsWith(':')) {
|
75
|
+
result.push(...getNestedRules(key, nestedValue, [...pseudos, nestedKey], atRules));
|
76
|
+
} else if (nestedKey === 'default') {
|
77
|
+
result.push(...getNestedRules(key, nestedValue, pseudos, atRules));
|
78
|
+
} else {
|
79
|
+
// This can be updated when we support more complex styles, such
|
80
|
+
// as applying a style conditionally when a parent is hovered.
|
81
|
+
throw new Error('Complex Selectors (combinators) are not supported yet.');
|
82
|
+
}
|
83
|
+
}
|
84
|
+
} else {
|
85
|
+
// primitive value
|
86
|
+
result.push(new _Rule.RawRule(key, value, pseudos, atRules));
|
87
|
+
}
|
88
|
+
return result;
|
89
|
+
}
|
@@ -20,82 +20,82 @@ const logicalToPhysical = {
|
|
20
20
|
};
|
21
21
|
const propertyToLTR = {
|
22
22
|
'margin-start': _ref => {
|
23
|
-
let [
|
23
|
+
let [_key, val] = _ref;
|
24
24
|
return ['margin-left', val];
|
25
25
|
},
|
26
|
-
// 'margin-inline-start': ([
|
26
|
+
// 'margin-inline-start': ([_key, val]) => ['margin-left', val],
|
27
27
|
'margin-end': _ref2 => {
|
28
|
-
let [
|
28
|
+
let [_key, val] = _ref2;
|
29
29
|
return ['margin-right', val];
|
30
30
|
},
|
31
|
-
// 'margin-inline-end': ([
|
31
|
+
// 'margin-inline-end': ([_key, val]: [string, string]) => ['margin-right', val],
|
32
32
|
'padding-start': _ref3 => {
|
33
|
-
let [
|
33
|
+
let [_key, val] = _ref3;
|
34
34
|
return ['padding-left', val];
|
35
35
|
},
|
36
|
-
// 'padding-inline-start': ([
|
36
|
+
// 'padding-inline-start': ([_key, val]: [string, string]) => ['padding-left', val],
|
37
37
|
'padding-end': _ref4 => {
|
38
|
-
let [
|
38
|
+
let [_key, val] = _ref4;
|
39
39
|
return ['padding-right', val];
|
40
40
|
},
|
41
|
-
// 'padding-inline-end': ([
|
41
|
+
// 'padding-inline-end': ([_key, val]: [string, string]) => ['padding-right', val],
|
42
42
|
'border-start': _ref5 => {
|
43
|
-
let [
|
43
|
+
let [_key, val] = _ref5;
|
44
44
|
return ['border-left', val];
|
45
45
|
},
|
46
|
-
// 'border-inline-start': ([
|
46
|
+
// 'border-inline-start': ([_key, val]: [string, string]) => ['border-left', val],
|
47
47
|
'border-end': _ref6 => {
|
48
|
-
let [
|
48
|
+
let [_key, val] = _ref6;
|
49
49
|
return ['border-right', val];
|
50
50
|
},
|
51
|
-
// 'border-inline-end': ([
|
51
|
+
// 'border-inline-end': ([_key, val]: [string, string]) => ['border-right', val],
|
52
52
|
'border-start-width': _ref7 => {
|
53
|
-
let [
|
53
|
+
let [_key, val] = _ref7;
|
54
54
|
return ['border-left-width', val];
|
55
55
|
},
|
56
56
|
// 'border-inline-start-width': ([key, val]: [string, string]) => ['border-left-width', val],
|
57
57
|
'border-end-width': _ref8 => {
|
58
|
-
let [
|
58
|
+
let [_key, val] = _ref8;
|
59
59
|
return ['border-right-width', val];
|
60
60
|
},
|
61
|
-
// 'border-inline-end-width': ([
|
61
|
+
// 'border-inline-end-width': ([_key, val]: [string, string]) => ['border-right-width', val],
|
62
62
|
'border-start-color': _ref9 => {
|
63
|
-
let [
|
63
|
+
let [_key, val] = _ref9;
|
64
64
|
return ['border-left-color', val];
|
65
65
|
},
|
66
|
-
// 'border-inline-start-color': ([
|
66
|
+
// 'border-inline-start-color': ([_key, val]: [string, string]) => ['border-left-color', val],
|
67
67
|
'border-end-color': _ref10 => {
|
68
|
-
let [
|
68
|
+
let [_key, val] = _ref10;
|
69
69
|
return ['border-right-color', val];
|
70
70
|
},
|
71
|
-
// 'border-inline-end-color': ([
|
71
|
+
// 'border-inline-end-color': ([_key, val]: [string, string]) => ['border-right-color', val],
|
72
72
|
'border-start-style': _ref11 => {
|
73
|
-
let [
|
73
|
+
let [_key, val] = _ref11;
|
74
74
|
return ['border-left-style', val];
|
75
75
|
},
|
76
|
-
// 'border-inline-start-style': ([
|
76
|
+
// 'border-inline-start-style': ([_key, val]: [string, string]) => ['border-left-style', val],
|
77
77
|
'border-end-style': _ref12 => {
|
78
|
-
let [
|
78
|
+
let [_key, val] = _ref12;
|
79
79
|
return ['border-right-style', val];
|
80
80
|
},
|
81
|
-
// 'border-inline-end-style': ([
|
81
|
+
// 'border-inline-end-style': ([_key, val]: [string, string]) => ['border-right-style', val],
|
82
82
|
'border-top-start-radius': _ref13 => {
|
83
|
-
let [
|
83
|
+
let [_key, val] = _ref13;
|
84
84
|
return ['border-top-left-radius', val];
|
85
85
|
},
|
86
|
-
// 'border-start-start-radius': ([
|
86
|
+
// 'border-start-start-radius': ([_key, val]: [string, string]) => ['border-top-left-radius', val],
|
87
87
|
'border-bottom-start-radius': _ref14 => {
|
88
|
-
let [
|
88
|
+
let [_key, val] = _ref14;
|
89
89
|
return ['border-bottom-left-radius', val];
|
90
90
|
},
|
91
|
-
// 'border-end-start-radius': ([
|
91
|
+
// 'border-end-start-radius': ([_key, val]: [string, string]) => ['border-bottom-left-radius', val],
|
92
92
|
'border-top-end-radius': _ref15 => {
|
93
|
-
let [
|
93
|
+
let [_key, val] = _ref15;
|
94
94
|
return ['border-top-right-radius', val];
|
95
95
|
},
|
96
|
-
// 'border-start-end-radius': ([
|
96
|
+
// 'border-start-end-radius': ([_key, val]: [string, string]) => ['border-top-right-radius', val],
|
97
97
|
'border-bottom-end-radius': _ref16 => {
|
98
|
-
let [
|
98
|
+
let [_key, val] = _ref16;
|
99
99
|
return ['border-bottom-right-radius', val];
|
100
100
|
},
|
101
101
|
// 'border-end-end-radius': ([key, val]: [string, string]) => ['border-bottom-right-radius', val],
|
@@ -112,12 +112,12 @@ const propertyToLTR = {
|
|
112
112
|
return [key, logicalToPhysical[val] ?? val];
|
113
113
|
},
|
114
114
|
start: _ref20 => {
|
115
|
-
let [
|
115
|
+
let [_key, val] = _ref20;
|
116
116
|
return ['left', val];
|
117
117
|
},
|
118
118
|
// 'inset-inline-start': ([key, val]: [string, string]) => ['left', val],
|
119
119
|
end: _ref21 => {
|
120
|
-
let [
|
120
|
+
let [_key, val] = _ref21;
|
121
121
|
return ['right', val];
|
122
122
|
},
|
123
123
|
// 'inset-inline-end': ([key, val]) => ['right', val],
|
@@ -92,82 +92,82 @@ const logicalToPhysical = {
|
|
92
92
|
};
|
93
93
|
const propertyToRTL = {
|
94
94
|
'margin-start': _ref3 => {
|
95
|
-
let [
|
95
|
+
let [_key, val] = _ref3;
|
96
96
|
return ['margin-right', val];
|
97
97
|
},
|
98
98
|
// 'margin-inline-start': ([key, val]: [string, string]) => ['margin-right', val],
|
99
99
|
'margin-end': _ref4 => {
|
100
|
-
let [
|
100
|
+
let [_key, val] = _ref4;
|
101
101
|
return ['margin-left', val];
|
102
102
|
},
|
103
103
|
// 'margin-inline-end': ([key, val]: [string, string]) => ['margin-left', val],
|
104
104
|
'padding-start': _ref5 => {
|
105
|
-
let [
|
105
|
+
let [_key, val] = _ref5;
|
106
106
|
return ['padding-right', val];
|
107
107
|
},
|
108
108
|
// 'padding-inline-start': ([key, val]: [string, string]) => ['padding-right', val],
|
109
109
|
'padding-end': _ref6 => {
|
110
|
-
let [
|
110
|
+
let [_key, val] = _ref6;
|
111
111
|
return ['padding-left', val];
|
112
112
|
},
|
113
|
-
// 'padding-inline-end': ([
|
113
|
+
// 'padding-inline-end': ([_key, val]: [string, string]) => ['padding-left', val],
|
114
114
|
'border-start': _ref7 => {
|
115
|
-
let [
|
115
|
+
let [_key, val] = _ref7;
|
116
116
|
return ['border-right', val];
|
117
117
|
},
|
118
|
-
// 'border-inline-start': ([
|
118
|
+
// 'border-inline-start': ([_key, val]: [string, string]) => ['border-right', val],
|
119
119
|
'border-end': _ref8 => {
|
120
|
-
let [
|
120
|
+
let [_key, val] = _ref8;
|
121
121
|
return ['border-left', val];
|
122
122
|
},
|
123
|
-
// 'border-inline-end': ([
|
123
|
+
// 'border-inline-end': ([_key, val]: [string, string]) => ['border-left', val],
|
124
124
|
'border-start-width': _ref9 => {
|
125
|
-
let [
|
125
|
+
let [_key, val] = _ref9;
|
126
126
|
return ['border-right-width', val];
|
127
127
|
},
|
128
|
-
// 'border-inline-start-width': ([
|
128
|
+
// 'border-inline-start-width': ([_key, val]: [string, string]) => ['border-right-width', val],
|
129
129
|
'border-end-width': _ref10 => {
|
130
|
-
let [
|
130
|
+
let [_key, val] = _ref10;
|
131
131
|
return ['border-left-width', val];
|
132
132
|
},
|
133
|
-
// 'border-inline-end-width': ([
|
133
|
+
// 'border-inline-end-width': ([_key, val]: [string, string]) => ['border-left-width', val],
|
134
134
|
'border-start-color': _ref11 => {
|
135
|
-
let [
|
135
|
+
let [_key, val] = _ref11;
|
136
136
|
return ['border-right-color', val];
|
137
137
|
},
|
138
|
-
// 'border-inline-start-color': ([
|
138
|
+
// 'border-inline-start-color': ([_key, val]: [string, string]) => ['border-right-color', val],
|
139
139
|
'border-end-color': _ref12 => {
|
140
|
-
let [
|
140
|
+
let [_key, val] = _ref12;
|
141
141
|
return ['border-left-color', val];
|
142
142
|
},
|
143
|
-
// 'border-inline-end-color': ([
|
143
|
+
// 'border-inline-end-color': ([_key, val]: [string, string]) => ['border-left-color', val],
|
144
144
|
'border-start-style': _ref13 => {
|
145
|
-
let [
|
145
|
+
let [_key, val] = _ref13;
|
146
146
|
return ['border-right-style', val];
|
147
147
|
},
|
148
|
-
// 'border-inline-start-style': ([
|
148
|
+
// 'border-inline-start-style': ([_key, val]: [string, string]) => ['border-right-style', val],
|
149
149
|
'border-end-style': _ref14 => {
|
150
|
-
let [
|
150
|
+
let [_key, val] = _ref14;
|
151
151
|
return ['border-left-style', val];
|
152
152
|
},
|
153
|
-
// 'border-inline-end-style': ([
|
153
|
+
// 'border-inline-end-style': ([_key, val]: [string, string]) => ['border-left-style', val],
|
154
154
|
'border-top-start-radius': _ref15 => {
|
155
|
-
let [
|
155
|
+
let [_key, val] = _ref15;
|
156
156
|
return ['border-top-right-radius', val];
|
157
157
|
},
|
158
|
-
// 'border-start-start-radius': ([
|
158
|
+
// 'border-start-start-radius': ([_key, val]: [string, string]) => ['border-top-right-radius', val],
|
159
159
|
'border-bottom-start-radius': _ref16 => {
|
160
|
-
let [
|
160
|
+
let [_key, val] = _ref16;
|
161
161
|
return ['border-bottom-right-radius', val];
|
162
162
|
},
|
163
|
-
// 'border-end-start-radius': ([
|
163
|
+
// 'border-end-start-radius': ([_key, val]: [string, string]) => ['border-bottom-right-radius', val],
|
164
164
|
'border-top-end-radius': _ref17 => {
|
165
|
-
let [
|
165
|
+
let [_key, val] = _ref17;
|
166
166
|
return ['border-top-left-radius', val];
|
167
167
|
},
|
168
|
-
// 'border-start-end-radius': ([
|
168
|
+
// 'border-start-end-radius': ([_key, val]: [string, string]) => ['border-top-left-radius', val],
|
169
169
|
'border-bottom-end-radius': _ref18 => {
|
170
|
-
let [
|
170
|
+
let [_key, val] = _ref18;
|
171
171
|
return ['border-bottom-left-radius', val];
|
172
172
|
},
|
173
173
|
// 'border-end-end-radius': ([key, val]: [string, string]) => ['border-bottom-left-radius', val],
|
@@ -184,12 +184,12 @@ const propertyToRTL = {
|
|
184
184
|
return logicalToPhysical[val] != null ? [key, logicalToPhysical[val]] : null;
|
185
185
|
},
|
186
186
|
start: _ref22 => {
|
187
|
-
let [
|
187
|
+
let [_key, val] = _ref22;
|
188
188
|
return ['right', val];
|
189
189
|
},
|
190
190
|
// 'inset-inline-start': ([key, val]: [string, string]) => ['right', val],
|
191
191
|
end: _ref23 => {
|
192
|
-
let [
|
192
|
+
let [_key, val] = _ref23;
|
193
193
|
return ['left', val];
|
194
194
|
},
|
195
195
|
// 'inset-inline-end': ([key, val]: [string, string]) => ['left', val],
|
@@ -0,0 +1,101 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.PreRuleSet = exports.PreRule = exports.PreIncludedStylesRule = exports.NullPreRule = void 0;
|
7
|
+
var _convertToClassName = require("../convert-to-className");
|
8
|
+
var _objectUtils = require("../utils/object-utils");
|
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
|
+
class NullPreRule {
|
19
|
+
compiled(_options) {
|
20
|
+
return [null];
|
21
|
+
}
|
22
|
+
equals(other) {
|
23
|
+
return other instanceof NullPreRule;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
exports.NullPreRule = NullPreRule;
|
27
|
+
class PreIncludedStylesRule {
|
28
|
+
constructor(IncludedStyles) {
|
29
|
+
this.includedStyles = IncludedStyles;
|
30
|
+
}
|
31
|
+
equals(other) {
|
32
|
+
return other instanceof PreIncludedStylesRule &&
|
33
|
+
// We can use reference equality here.
|
34
|
+
this.includedStyles === other.includedStyles;
|
35
|
+
}
|
36
|
+
compiled(_options) {
|
37
|
+
return this.includedStyles;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
// a comparator function that sorts strings alphabetically
|
42
|
+
// but where `default` always comes first
|
43
|
+
exports.PreIncludedStylesRule = PreIncludedStylesRule;
|
44
|
+
const stringComparator = (a, b) => {
|
45
|
+
if (a === 'default') {
|
46
|
+
return -1;
|
47
|
+
}
|
48
|
+
if (b === 'default') {
|
49
|
+
return 1;
|
50
|
+
}
|
51
|
+
return a.localeCompare(b);
|
52
|
+
};
|
53
|
+
class PreRule {
|
54
|
+
constructor(property, value, pseudos, atRules) {
|
55
|
+
this.property = property;
|
56
|
+
this.value = value;
|
57
|
+
this.pseudos = pseudos ? (0, _objectUtils.arraySort)(pseudos, stringComparator) : [];
|
58
|
+
this.atRules = atRules ? (0, _objectUtils.arraySort)(atRules) : [];
|
59
|
+
}
|
60
|
+
compiled(options) {
|
61
|
+
const [_key, className, rule] = (0, _convertToClassName.convertStyleToClassName)([this.property, this.value], this.pseudos ?? [], this.atRules ?? [], options);
|
62
|
+
return [[className, rule]];
|
63
|
+
}
|
64
|
+
equals(other) {
|
65
|
+
if (!(other instanceof PreRule)) {
|
66
|
+
return false;
|
67
|
+
}
|
68
|
+
const valuesEqual = Array.isArray(this.value) && Array.isArray(other.value) ? (0, _objectUtils.arrayEquals)(this.value, other.value) : this.value === other.value;
|
69
|
+
return this.property === other.property && valuesEqual && (0, _objectUtils.arrayEquals)(this.pseudos, other.pseudos) && (0, _objectUtils.arrayEquals)(this.atRules, other.atRules);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
exports.PreRule = PreRule;
|
73
|
+
class PreRuleSet {
|
74
|
+
constructor(rules) {
|
75
|
+
this.rules = rules;
|
76
|
+
}
|
77
|
+
static create(rules) {
|
78
|
+
const flatRules = rules.flatMap(rule => rule instanceof PreRuleSet ? rule.rules : [rule]);
|
79
|
+
if (flatRules.length === 0) {
|
80
|
+
return new NullPreRule();
|
81
|
+
}
|
82
|
+
if (flatRules.length === 1) {
|
83
|
+
return flatRules[0];
|
84
|
+
}
|
85
|
+
return new PreRuleSet(flatRules);
|
86
|
+
}
|
87
|
+
compiled(options) {
|
88
|
+
const styleTuple = this.rules.flatMap(rule => rule.compiled(options)).filter(Boolean);
|
89
|
+
return styleTuple.length > 0 ? styleTuple : [null];
|
90
|
+
}
|
91
|
+
equals(other) {
|
92
|
+
if (!(other instanceof PreRuleSet)) {
|
93
|
+
return false;
|
94
|
+
}
|
95
|
+
if (this.rules.length !== other.rules.length) {
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
return (0, _objectUtils.arrayEquals)(this.rules, other.rules, (a, b) => a.equals(b));
|
99
|
+
}
|
100
|
+
}
|
101
|
+
exports.PreRuleSet = PreRuleSet;
|