@stylexjs/shared 0.5.0-alpha.4 → 0.5.1
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/lib/index.d.ts +8 -0
- package/lib/index.js +6 -2
- package/lib/index.js.flow +8 -0
- package/lib/preprocess-rules/index.js +4 -1
- package/lib/utils/normalizers/whitespace.js +10 -0
- package/lib/utils/normalizers/zero-dimensions.js +8 -1
- package/lib/utils/property-priorities.d.ts +59 -0
- package/lib/utils/property-priorities.js +13 -6
- package/lib/utils/property-priorities.js.flow +68 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
@@ -26,6 +26,11 @@ import hash from './hash';
|
|
26
26
|
import genFileBasedIdentifier from './utils/file-based-identifier';
|
27
27
|
import * as m from './messages';
|
28
28
|
export * as types from './types';
|
29
|
+
import {
|
30
|
+
PSEUDO_CLASS_PRIORITIES as _PSEUDO_CLASS_PRIORITIES,
|
31
|
+
AT_RULE_PRIORITIES as _AT_RULE_PRIORITIES,
|
32
|
+
PSEUDO_ELEMENT_PRIORITY as _PSEUDO_ELEMENT_PRIORITY,
|
33
|
+
} from './utils/property-priorities';
|
29
34
|
import type {
|
30
35
|
InjectableStyle as _InjectableStyle,
|
31
36
|
CompiledNamespaces as _CompiledNamespaces,
|
@@ -44,6 +49,9 @@ export declare const utils: {
|
|
44
49
|
export declare const messages: typeof m;
|
45
50
|
export declare const IncludedStyles: typeof _IncludedStyles;
|
46
51
|
export declare const firstThatWorks: typeof stylexFirstThatWorks;
|
52
|
+
export declare const PSEUDO_CLASS_PRIORITIES: typeof _PSEUDO_CLASS_PRIORITIES;
|
53
|
+
export declare const AT_RULE_PRIORITIES: typeof _AT_RULE_PRIORITIES;
|
54
|
+
export declare const PSEUDO_ELEMENT_PRIORITY: typeof _PSEUDO_ELEMENT_PRIORITY;
|
47
55
|
export type InjectableStyle = _InjectableStyle;
|
48
56
|
export type CompiledNamespaces = _CompiledNamespaces;
|
49
57
|
export type MutableCompiledNamespaces = _MutableCompiledNamespaces;
|
package/lib/index.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.utils = exports.types = exports.messages = exports.keyframes = exports.include = exports.firstThatWorks = exports.defineVars = exports.createTheme = 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.PSEUDO_ELEMENT_PRIORITY = exports.PSEUDO_CLASS_PRIORITIES = exports.IncludedStyles = exports.AT_RULE_PRIORITIES = void 0;
|
7
7
|
var _stylexCreate = _interopRequireDefault(require("./stylex-create"));
|
8
8
|
var _stylexDefineVars = _interopRequireDefault(require("./stylex-define-vars"));
|
9
9
|
var _stylexCreateTheme = _interopRequireDefault(require("./stylex-create-theme"));
|
@@ -15,6 +15,7 @@ var _fileBasedIdentifier = _interopRequireDefault(require("./utils/file-based-id
|
|
15
15
|
var m = _interopRequireWildcard(require("./messages"));
|
16
16
|
var _types = _interopRequireWildcard(require("./types"));
|
17
17
|
exports.types = _types;
|
18
|
+
var _propertyPriorities = require("./utils/property-priorities");
|
18
19
|
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
20
|
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; }
|
20
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -29,4 +30,7 @@ const utils = exports.utils = {
|
|
29
30
|
};
|
30
31
|
const messages = exports.messages = m;
|
31
32
|
const IncludedStyles = exports.IncludedStyles = _stylexInclude.IncludedStyles;
|
32
|
-
const firstThatWorks = exports.firstThatWorks = _stylexFirstThatWorks.default;
|
33
|
+
const firstThatWorks = exports.firstThatWorks = _stylexFirstThatWorks.default;
|
34
|
+
const PSEUDO_CLASS_PRIORITIES = exports.PSEUDO_CLASS_PRIORITIES = _propertyPriorities.PSEUDO_CLASS_PRIORITIES;
|
35
|
+
const AT_RULE_PRIORITIES = exports.AT_RULE_PRIORITIES = _propertyPriorities.AT_RULE_PRIORITIES;
|
36
|
+
const PSEUDO_ELEMENT_PRIORITY = exports.PSEUDO_ELEMENT_PRIORITY = _propertyPriorities.PSEUDO_ELEMENT_PRIORITY;
|
package/lib/index.js.flow
CHANGED
@@ -32,6 +32,11 @@ import hash from './hash';
|
|
32
32
|
import genFileBasedIdentifier from './utils/file-based-identifier';
|
33
33
|
import * as m from './messages';
|
34
34
|
export * as types from './types';
|
35
|
+
import {
|
36
|
+
PSEUDO_CLASS_PRIORITIES as _PSEUDO_CLASS_PRIORITIES,
|
37
|
+
AT_RULE_PRIORITIES as _AT_RULE_PRIORITIES,
|
38
|
+
PSEUDO_ELEMENT_PRIORITY as _PSEUDO_ELEMENT_PRIORITY,
|
39
|
+
} from './utils/property-priorities';
|
35
40
|
|
36
41
|
import type {
|
37
42
|
InjectableStyle as _InjectableStyle,
|
@@ -52,6 +57,9 @@ declare export const utils: {
|
|
52
57
|
declare export const messages: typeof m;
|
53
58
|
declare export const IncludedStyles: typeof _IncludedStyles;
|
54
59
|
declare export const firstThatWorks: typeof stylexFirstThatWorks;
|
60
|
+
declare export const PSEUDO_CLASS_PRIORITIES: typeof _PSEUDO_CLASS_PRIORITIES;
|
61
|
+
declare export const AT_RULE_PRIORITIES: typeof _AT_RULE_PRIORITIES;
|
62
|
+
declare export const PSEUDO_ELEMENT_PRIORITY: typeof _PSEUDO_ELEMENT_PRIORITY;
|
55
63
|
|
56
64
|
export type InjectableStyle = _InjectableStyle;
|
57
65
|
export type CompiledNamespaces = _CompiledNamespaces;
|
@@ -18,7 +18,10 @@ function getExpandedKeys(options) {
|
|
18
18
|
return Object.keys(expansions[options.styleResolution ?? 'application-order']);
|
19
19
|
}
|
20
20
|
function flatMapExpandedShorthands(objEntry, options) {
|
21
|
-
|
21
|
+
let [key, value] = objEntry;
|
22
|
+
if (key.startsWith('var(') && key.endsWith(')')) {
|
23
|
+
key = key.slice(4, -1);
|
24
|
+
}
|
22
25
|
const expansion = expansions[options.styleResolution ?? 'application-order'][key];
|
23
26
|
if (expansion) {
|
24
27
|
if (Array.isArray(value)) {
|
@@ -19,6 +19,16 @@ function normalizeWhitespace(ast, _) {
|
|
19
19
|
break;
|
20
20
|
}
|
21
21
|
case 'div':
|
22
|
+
{
|
23
|
+
if (node.value === ',') {
|
24
|
+
node.before = '';
|
25
|
+
node.after = '';
|
26
|
+
} else {
|
27
|
+
node.before = ' ';
|
28
|
+
node.after = ' ';
|
29
|
+
}
|
30
|
+
break;
|
31
|
+
}
|
22
32
|
case 'function':
|
23
33
|
{
|
24
34
|
node.before = '';
|
@@ -9,7 +9,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
9
9
|
const angles = ['deg', 'grad', 'turn', 'rad'];
|
10
10
|
const timings = ['ms', 's'];
|
11
11
|
function normalizeZeroDimensions(ast, _) {
|
12
|
+
let endFunction = 0;
|
12
13
|
ast.walk(node => {
|
14
|
+
if (node.type === 'function' && !endFunction) {
|
15
|
+
endFunction = node.sourceEndIndex ?? 0;
|
16
|
+
}
|
17
|
+
if (endFunction > 0 && node.sourceIndex > endFunction) {
|
18
|
+
endFunction = 0;
|
19
|
+
}
|
13
20
|
if (node.type !== 'word') {
|
14
21
|
return;
|
15
22
|
}
|
@@ -21,7 +28,7 @@ function normalizeZeroDimensions(ast, _) {
|
|
21
28
|
node.value = '0deg';
|
22
29
|
} else if (timings.indexOf(dimension.unit) !== -1) {
|
23
30
|
node.value = '0s';
|
24
|
-
} else {
|
31
|
+
} else if (!endFunction) {
|
25
32
|
node.value = '0';
|
26
33
|
}
|
27
34
|
});
|
@@ -7,5 +7,64 @@
|
|
7
7
|
*
|
8
8
|
*/
|
9
9
|
|
10
|
+
type PseudoClassPriorities = {
|
11
|
+
':is': 40;
|
12
|
+
':where': 40;
|
13
|
+
':not': 40;
|
14
|
+
':has': 45;
|
15
|
+
':dir': 50;
|
16
|
+
':lang': 51;
|
17
|
+
':first-child': 52;
|
18
|
+
':first-of-type': 53;
|
19
|
+
':last-child': 54;
|
20
|
+
':last-of-type': 55;
|
21
|
+
':only-child': 56;
|
22
|
+
':only-of-type': 57;
|
23
|
+
':nth-child': 60;
|
24
|
+
':nth-last-child': 61;
|
25
|
+
':nth-of-type': 62;
|
26
|
+
':nth-last-of-type': 63;
|
27
|
+
':empty': 70;
|
28
|
+
':link': 80;
|
29
|
+
':any-link': 81;
|
30
|
+
':local-link': 82;
|
31
|
+
':target-within': 83;
|
32
|
+
':target': 84;
|
33
|
+
':visited': 85;
|
34
|
+
':enabled': 91;
|
35
|
+
':disabled': 92;
|
36
|
+
':required': 93;
|
37
|
+
':optional': 94;
|
38
|
+
':read-only': 95;
|
39
|
+
':read-write': 96;
|
40
|
+
':placeholder-shown': 97;
|
41
|
+
':in-range': 98;
|
42
|
+
':out-of-range': 99;
|
43
|
+
':default': 100;
|
44
|
+
':checked': 101;
|
45
|
+
':indeterminate': 101;
|
46
|
+
':blank': 102;
|
47
|
+
':valid': 103;
|
48
|
+
':invalid': 104;
|
49
|
+
':user-invalid': 105;
|
50
|
+
':autofill': 110;
|
51
|
+
':picture-in-picture': 120;
|
52
|
+
':modal': 121;
|
53
|
+
':fullscreen': 122;
|
54
|
+
':paused': 123;
|
55
|
+
':playing': 124;
|
56
|
+
':current': 125;
|
57
|
+
':past': 126;
|
58
|
+
':future': 127;
|
59
|
+
':hover': 130;
|
60
|
+
':focusWithin': 140;
|
61
|
+
':focus': 150;
|
62
|
+
':focusVisible': 160;
|
63
|
+
':active': 170;
|
64
|
+
};
|
65
|
+
export declare const PSEUDO_CLASS_PRIORITIES: Readonly<PseudoClassPriorities>;
|
66
|
+
type AtRulePriorities = { '@supports': 30; '@media': 200; '@container': 300 };
|
67
|
+
export declare const AT_RULE_PRIORITIES: Readonly<AtRulePriorities>;
|
68
|
+
export declare const PSEUDO_ELEMENT_PRIORITY: number;
|
10
69
|
declare function getPriority(key: string): number;
|
11
70
|
export default getPriority;
|
@@ -3,6 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.PSEUDO_ELEMENT_PRIORITY = exports.PSEUDO_CLASS_PRIORITIES = exports.AT_RULE_PRIORITIES = void 0;
|
6
7
|
exports.default = getPriority;
|
7
8
|
const longHandPhysical = new Set();
|
8
9
|
const longHandLogical = new Set();
|
@@ -440,7 +441,7 @@ longHandLogical.add('math-depth');
|
|
440
441
|
longHandLogical.add('math-shift');
|
441
442
|
longHandLogical.add('math-style');
|
442
443
|
longHandLogical.add('touch-action');
|
443
|
-
const
|
444
|
+
const PSEUDO_CLASS_PRIORITIES = exports.PSEUDO_CLASS_PRIORITIES = {
|
444
445
|
':is': 40,
|
445
446
|
':where': 40,
|
446
447
|
':not': 40,
|
@@ -495,25 +496,31 @@ const PRIORITIES = {
|
|
495
496
|
':focusVisible': 160,
|
496
497
|
':active': 170
|
497
498
|
};
|
499
|
+
const AT_RULE_PRIORITIES = exports.AT_RULE_PRIORITIES = {
|
500
|
+
'@supports': 30,
|
501
|
+
'@media': 200,
|
502
|
+
'@container': 300
|
503
|
+
};
|
504
|
+
const PSEUDO_ELEMENT_PRIORITY = exports.PSEUDO_ELEMENT_PRIORITY = 5000;
|
498
505
|
function getPriority(key) {
|
499
506
|
if (key.startsWith('--')) {
|
500
507
|
return 1;
|
501
508
|
}
|
502
509
|
if (key.startsWith('@supports')) {
|
503
|
-
return
|
510
|
+
return AT_RULE_PRIORITIES['@supports'];
|
504
511
|
}
|
505
512
|
if (key.startsWith('@media')) {
|
506
|
-
return
|
513
|
+
return AT_RULE_PRIORITIES['@media'];
|
507
514
|
}
|
508
515
|
if (key.startsWith('@container')) {
|
509
|
-
return
|
516
|
+
return AT_RULE_PRIORITIES['@container'];
|
510
517
|
}
|
511
518
|
if (key.startsWith('::')) {
|
512
|
-
return
|
519
|
+
return PSEUDO_ELEMENT_PRIORITY;
|
513
520
|
}
|
514
521
|
if (key.startsWith(':')) {
|
515
522
|
const prop = key.startsWith(':') && key.includes('(') ? key.slice(0, key.indexOf('(')) : key;
|
516
|
-
return
|
523
|
+
return PSEUDO_CLASS_PRIORITIES[prop] ?? 40;
|
517
524
|
}
|
518
525
|
if (longHandPhysical.has(key)) {
|
519
526
|
return 4000;
|
@@ -7,4 +7,72 @@
|
|
7
7
|
* @flow strict
|
8
8
|
*/
|
9
9
|
|
10
|
+
type PseudoClassPriorities = {
|
11
|
+
':is': 40,
|
12
|
+
':where': 40,
|
13
|
+
':not': 40,
|
14
|
+
':has': 45,
|
15
|
+
':dir': 50,
|
16
|
+
':lang': 51,
|
17
|
+
':first-child': 52,
|
18
|
+
':first-of-type': 53,
|
19
|
+
':last-child': 54,
|
20
|
+
':last-of-type': 55,
|
21
|
+
':only-child': 56,
|
22
|
+
':only-of-type': 57,
|
23
|
+
':nth-child': 60,
|
24
|
+
':nth-last-child': 61,
|
25
|
+
':nth-of-type': 62,
|
26
|
+
':nth-last-of-type': 63, // 'nth-last-of-type' is the same priority as 'nth-of-type
|
27
|
+
':empty': 70,
|
28
|
+
':link': 80,
|
29
|
+
':any-link': 81,
|
30
|
+
':local-link': 82,
|
31
|
+
':target-within': 83,
|
32
|
+
':target': 84,
|
33
|
+
':visited': 85,
|
34
|
+
':enabled': 91,
|
35
|
+
':disabled': 92,
|
36
|
+
':required': 93,
|
37
|
+
':optional': 94,
|
38
|
+
':read-only': 95,
|
39
|
+
':read-write': 96,
|
40
|
+
':placeholder-shown': 97,
|
41
|
+
':in-range': 98,
|
42
|
+
':out-of-range': 99,
|
43
|
+
':default': 100,
|
44
|
+
':checked': 101,
|
45
|
+
':indeterminate': 101,
|
46
|
+
':blank': 102,
|
47
|
+
':valid': 103,
|
48
|
+
':invalid': 104,
|
49
|
+
':user-invalid': 105,
|
50
|
+
':autofill': 110,
|
51
|
+
':picture-in-picture': 120,
|
52
|
+
':modal': 121,
|
53
|
+
':fullscreen': 122,
|
54
|
+
':paused': 123,
|
55
|
+
':playing': 124,
|
56
|
+
':current': 125,
|
57
|
+
':past': 126,
|
58
|
+
':future': 127,
|
59
|
+
':hover': 130,
|
60
|
+
':focusWithin': 140,
|
61
|
+
':focus': 150,
|
62
|
+
':focusVisible': 160,
|
63
|
+
':active': 170,
|
64
|
+
};
|
65
|
+
|
66
|
+
declare export const PSEUDO_CLASS_PRIORITIES: $ReadOnly<PseudoClassPriorities>;
|
67
|
+
|
68
|
+
type AtRulePriorities = {
|
69
|
+
'@supports': 30,
|
70
|
+
'@media': 200,
|
71
|
+
'@container': 300,
|
72
|
+
};
|
73
|
+
|
74
|
+
declare export const AT_RULE_PRIORITIES: $ReadOnly<AtRulePriorities>;
|
75
|
+
|
76
|
+
declare export const PSEUDO_ELEMENT_PRIORITY: number;
|
77
|
+
|
10
78
|
declare export default function getPriority(key: string): number;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@stylexjs/shared",
|
3
|
-
"version": "0.5.
|
3
|
+
"version": "0.5.1",
|
4
4
|
"main": "lib/index.js",
|
5
5
|
"repository": "https://www.github.com/facebook/stylex",
|
6
6
|
"license": "MIT",
|
@@ -13,7 +13,7 @@
|
|
13
13
|
"postcss-value-parser": "^4.1.0"
|
14
14
|
},
|
15
15
|
"devDependencies": {
|
16
|
-
"@stylexjs/scripts": "0.5.
|
16
|
+
"@stylexjs/scripts": "0.5.1"
|
17
17
|
},
|
18
18
|
"jest": {
|
19
19
|
"snapshotFormat": {
|