@stylexjs/stylex 0.11.1 → 0.13.0
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 +0 -27
- package/lib/{stylex-inject.d.ts → cjs/inject.d.ts} +1 -5
- package/lib/cjs/inject.js +210 -0
- package/lib/{stylex-inject.js.flow → cjs/inject.js.flow} +2 -3
- package/lib/cjs/stylesheet/createCSSStyleSheet.d.ts +13 -0
- package/lib/cjs/stylesheet/createCSSStyleSheet.js.flow +13 -0
- package/lib/cjs/stylesheet/createOrderedCSSStyleSheet.d.ts +31 -0
- package/lib/cjs/stylesheet/createOrderedCSSStyleSheet.js.flow +32 -0
- package/lib/cjs/stylesheet/createSheet.d.ts +12 -0
- package/lib/cjs/stylesheet/createSheet.js.flow +16 -0
- package/lib/cjs/stylesheet/utils.d.ts +18 -0
- package/lib/cjs/stylesheet/utils.js.flow +19 -0
- package/lib/{stylex.d.ts → cjs/stylex.d.ts} +8 -21
- package/lib/cjs/stylex.js +242 -0
- package/lib/{stylex.js.flow → cjs/stylex.js.flow} +10 -26
- package/lib/{StyleXCSSTypes.d.ts → cjs/types/StyleXCSSTypes.d.ts} +22 -0
- package/lib/{StyleXCSSTypes.js.flow → cjs/types/StyleXCSSTypes.js.flow} +25 -0
- package/lib/{StyleXTypes.d.ts → cjs/types/StyleXTypes.d.ts} +60 -5
- package/lib/{StyleXTypes.js.flow → cjs/types/StyleXTypes.js.flow} +56 -5
- package/lib/{VarTypes.d.ts → cjs/types/VarTypes.d.ts} +19 -18
- package/lib/{VarTypes.js.flow → cjs/types/VarTypes.js.flow} +17 -19
- package/lib/es/inject.d.ts +11 -0
- package/lib/es/inject.js.flow +13 -0
- package/lib/es/inject.mjs +208 -0
- package/lib/es/stylesheet/createCSSStyleSheet.d.ts +13 -0
- package/lib/es/stylesheet/createCSSStyleSheet.js.flow +13 -0
- package/lib/es/stylesheet/createOrderedCSSStyleSheet.d.ts +31 -0
- package/lib/es/stylesheet/createOrderedCSSStyleSheet.js.flow +32 -0
- package/lib/es/stylesheet/createSheet.d.ts +12 -0
- package/lib/es/stylesheet/createSheet.js.flow +16 -0
- package/lib/es/stylesheet/utils.d.ts +18 -0
- package/lib/es/stylesheet/utils.js.flow +19 -0
- package/lib/es/stylex.d.ts +135 -0
- package/lib/es/stylex.js.flow +134 -0
- package/lib/es/stylex.mjs +8 -20
- package/lib/es/types/StyleXCSSTypes.d.ts +1487 -0
- package/lib/es/types/StyleXCSSTypes.js.flow +1580 -0
- package/lib/es/types/StyleXOpaqueTypes.d.ts +11 -0
- package/lib/es/types/StyleXOpaqueTypes.js.flow +16 -0
- package/lib/es/types/StyleXTypes.d.ts +292 -0
- package/lib/es/types/StyleXTypes.js.flow +240 -0
- package/lib/es/types/StyleXUtils.d.ts +15 -0
- package/lib/es/types/StyleXUtils.js.flow +15 -0
- package/lib/es/types/VarTypes.d.ts +104 -0
- package/lib/es/types/VarTypes.js.flow +102 -0
- package/package.json +20 -28
- package/lib/StyleXCSSTypes.js +0 -1
- package/lib/StyleXOpaqueTypes.js +0 -1
- package/lib/StyleXSheet.d.ts +0 -49
- package/lib/StyleXSheet.js +0 -188
- package/lib/StyleXSheet.js.flow +0 -49
- package/lib/StyleXTypes.js +0 -1
- package/lib/VarTypes.js +0 -1
- package/lib/es/StyleXCSSTypes.mjs +0 -1
- package/lib/es/StyleXOpaqueTypes.mjs +0 -0
- package/lib/es/StyleXSheet.mjs +0 -247
- package/lib/es/StyleXTypes.mjs +0 -1
- package/lib/es/VarTypes.mjs +0 -0
- package/lib/es/stylex-inject.mjs +0 -5
- package/lib/es/util-types.mjs +0 -0
- package/lib/stylex-inject.js +0 -11
- package/lib/stylex.js +0 -125
- package/lib/util-types.js +0 -1
- /package/lib/{StyleXOpaqueTypes.d.ts → cjs/types/StyleXOpaqueTypes.d.ts} +0 -0
- /package/lib/{StyleXOpaqueTypes.js.flow → cjs/types/StyleXOpaqueTypes.js.flow} +0 -0
- /package/lib/{util-types.d.ts → cjs/types/StyleXUtils.d.ts} +0 -0
- /package/lib/{util-types.js.flow → cjs/types/StyleXUtils.js.flow} +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
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 { ValueWithDefault } from './StyleXUtils';
|
|
11
|
+
|
|
12
|
+
export type CSSSyntax =
|
|
13
|
+
| '*'
|
|
14
|
+
| '<length>'
|
|
15
|
+
| '<number>'
|
|
16
|
+
| '<percentage>'
|
|
17
|
+
| '<length-percentage>'
|
|
18
|
+
| '<color>'
|
|
19
|
+
| '<image>'
|
|
20
|
+
| '<url>'
|
|
21
|
+
| '<integer>'
|
|
22
|
+
| '<angle>'
|
|
23
|
+
| '<time>'
|
|
24
|
+
| '<resolution>'
|
|
25
|
+
| '<transform-function>'
|
|
26
|
+
| '<custom-ident>'
|
|
27
|
+
| '<transform-list>';
|
|
28
|
+
|
|
29
|
+
type CSSSyntaxType = CSSSyntax;
|
|
30
|
+
type InnerValue = null | string | number;
|
|
31
|
+
|
|
32
|
+
interface ICSSType<+_T: InnerValue> {
|
|
33
|
+
+value: ValueWithDefault<string>;
|
|
34
|
+
+syntax: CSSSyntaxType;
|
|
35
|
+
}
|
|
36
|
+
declare export class Angle<+T: InnerValue> implements ICSSType<T> {
|
|
37
|
+
+value: ValueWithDefault<string>;
|
|
38
|
+
+syntax: CSSSyntaxType;
|
|
39
|
+
}
|
|
40
|
+
declare export class Color<+T: InnerValue> implements ICSSType<T> {
|
|
41
|
+
+value: ValueWithDefault<string>;
|
|
42
|
+
+syntax: CSSSyntaxType;
|
|
43
|
+
}
|
|
44
|
+
declare export class Url<+T: InnerValue> implements ICSSType<T> {
|
|
45
|
+
+value: ValueWithDefault<string>;
|
|
46
|
+
+syntax: CSSSyntaxType;
|
|
47
|
+
}
|
|
48
|
+
declare export class Image<+T: InnerValue> implements ICSSType<T> {
|
|
49
|
+
+value: ValueWithDefault<string>;
|
|
50
|
+
+syntax: CSSSyntaxType;
|
|
51
|
+
}
|
|
52
|
+
declare export class Integer<+T: InnerValue> implements ICSSType<T> {
|
|
53
|
+
+value: ValueWithDefault<string>;
|
|
54
|
+
+syntax: CSSSyntaxType;
|
|
55
|
+
}
|
|
56
|
+
declare export class LengthPercentage<+T: InnerValue> implements ICSSType<T> {
|
|
57
|
+
+value: ValueWithDefault<string>;
|
|
58
|
+
+syntax: CSSSyntaxType;
|
|
59
|
+
}
|
|
60
|
+
declare export class Length<+T: InnerValue> implements ICSSType<T> {
|
|
61
|
+
+value: ValueWithDefault<string>;
|
|
62
|
+
+syntax: CSSSyntaxType;
|
|
63
|
+
}
|
|
64
|
+
declare export class Percentage<+T: InnerValue> implements ICSSType<T> {
|
|
65
|
+
+value: ValueWithDefault<string>;
|
|
66
|
+
+syntax: CSSSyntaxType;
|
|
67
|
+
}
|
|
68
|
+
declare export class Num<+T: InnerValue> implements ICSSType<T> {
|
|
69
|
+
+value: ValueWithDefault<string>;
|
|
70
|
+
+syntax: CSSSyntaxType;
|
|
71
|
+
}
|
|
72
|
+
declare export class Resolution<+T: InnerValue> implements ICSSType<T> {
|
|
73
|
+
+value: ValueWithDefault<string>;
|
|
74
|
+
+syntax: CSSSyntaxType;
|
|
75
|
+
}
|
|
76
|
+
declare export class Time<+T: InnerValue> implements ICSSType<T> {
|
|
77
|
+
+value: ValueWithDefault<string>;
|
|
78
|
+
+syntax: CSSSyntaxType;
|
|
79
|
+
}
|
|
80
|
+
declare export class TransformFunction<+T: InnerValue> implements ICSSType<T> {
|
|
81
|
+
+value: ValueWithDefault<string>;
|
|
82
|
+
+syntax: CSSSyntaxType;
|
|
83
|
+
}
|
|
84
|
+
declare export class TransformList<+T: InnerValue> implements ICSSType<T> {
|
|
85
|
+
+value: ValueWithDefault<string>;
|
|
86
|
+
+syntax: CSSSyntaxType;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type CSSType<+T: InnerValue> =
|
|
90
|
+
| Angle<T>
|
|
91
|
+
| Color<T>
|
|
92
|
+
| Url<T>
|
|
93
|
+
| Image<T>
|
|
94
|
+
| Integer<T>
|
|
95
|
+
| LengthPercentage<T>
|
|
96
|
+
| Length<T>
|
|
97
|
+
| Percentage<T>
|
|
98
|
+
| Num<T>
|
|
99
|
+
| Resolution<T>
|
|
100
|
+
| Time<T>
|
|
101
|
+
| TransformFunction<T>
|
|
102
|
+
| TransformList<T>;
|
package/package.json
CHANGED
|
@@ -1,43 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/stylex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "A library for defining styles for optimized user interfaces.",
|
|
5
|
-
"main": "./lib/stylex.js",
|
|
5
|
+
"main": "./lib/cjs/stylex.js",
|
|
6
6
|
"module": "./lib/es/stylex.mjs",
|
|
7
|
-
"types": "./lib/stylex.d.ts",
|
|
7
|
+
"types": "./lib/cjs/stylex.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./lib/es/stylex.mjs",
|
|
11
|
-
"require": "./lib/stylex.js",
|
|
12
|
-
"types": "./lib/stylex.d.ts"
|
|
13
|
-
},
|
|
14
|
-
"./lib/StyleXTypes": {
|
|
15
|
-
"import": "./lib/StyleXTypes.js",
|
|
16
|
-
"require": "./lib/StyleXTypes.js",
|
|
17
|
-
"types": "./lib/StyleXTypes.d.ts"
|
|
18
|
-
},
|
|
19
|
-
"./lib/StyleXSheet": {
|
|
20
|
-
"import": "./lib/es/StyleXSheet.mjs",
|
|
21
|
-
"require": "./lib/StyleXSheet.js",
|
|
22
|
-
"types": "./lib/StyleXSheet.d.ts"
|
|
11
|
+
"require": "./lib/cjs/stylex.js",
|
|
12
|
+
"types": "./lib/cjs/stylex.d.ts"
|
|
23
13
|
},
|
|
24
14
|
"./lib/stylex-inject": {
|
|
25
|
-
"import": "./lib/es/
|
|
26
|
-
"require": "./lib/
|
|
27
|
-
"types": "./lib/
|
|
15
|
+
"import": "./lib/es/inject.mjs",
|
|
16
|
+
"require": "./lib/cjs/inject.js",
|
|
17
|
+
"types": "./lib/cjs/inject.d.ts"
|
|
28
18
|
},
|
|
29
19
|
"./package.json": "./package.json"
|
|
30
20
|
},
|
|
31
|
-
"repository":
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/facebook/stylex.git"
|
|
24
|
+
},
|
|
32
25
|
"license": "MIT",
|
|
33
26
|
"scripts": {
|
|
34
|
-
"prebuild": "gen-types -i src/ -o lib/",
|
|
35
|
-
"build:cjs": "cross-env BABEL_ENV=cjs
|
|
36
|
-
"build:esm": "cross-env BABEL_ENV=esm
|
|
37
|
-
"postbuild:esm": "rollup -c ./rollup.config.mjs",
|
|
27
|
+
"prebuild": "rimraf lib && gen-types -i src/ -o lib/cjs && cp -r lib/cjs lib/es",
|
|
28
|
+
"build:cjs": "cross-env BABEL_ENV=cjs rollup -c ./rollup.config.mjs",
|
|
29
|
+
"build:esm": "cross-env BABEL_ENV=esm rollup -c ./rollup.config.mjs",
|
|
38
30
|
"build": "npm run build:cjs && npm run build:esm",
|
|
39
|
-
"build-haste": "rewrite-imports -i src/ -o lib/",
|
|
40
|
-
"test": "jest"
|
|
31
|
+
"build-haste": "rimraf lib && rewrite-imports -i src/ -o lib/",
|
|
32
|
+
"test": "cross-env BABEL_ENV=test jest --coverage"
|
|
41
33
|
},
|
|
42
34
|
"dependencies": {
|
|
43
35
|
"css-mediaquery": "^0.1.2",
|
|
@@ -60,12 +52,12 @@
|
|
|
60
52
|
"@rollup/plugin-json": "^6.1.0",
|
|
61
53
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
62
54
|
"@rollup/plugin-replace": "^6.0.1",
|
|
63
|
-
"@stylexjs/scripts": "0.11.1",
|
|
64
55
|
"babel-plugin-syntax-hermes-parser": "^0.26.0",
|
|
65
56
|
"cross-env": "^7.0.3",
|
|
66
|
-
"
|
|
57
|
+
"rimraf": "^5.0.10",
|
|
58
|
+
"rollup": "^4.24.0",
|
|
59
|
+
"scripts": "0.13.0"
|
|
67
60
|
},
|
|
68
|
-
"jest": {},
|
|
69
61
|
"files": [
|
|
70
62
|
"lib/*"
|
|
71
63
|
]
|
package/lib/StyleXCSSTypes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';
|
package/lib/StyleXOpaqueTypes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/lib/StyleXSheet.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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 { LegacyThemeStyles as Theme } from './StyleXTypes';
|
|
11
|
-
type SheetOptions = Readonly<{
|
|
12
|
-
rootDarkTheme?: Theme;
|
|
13
|
-
rootTheme?: Theme;
|
|
14
|
-
supportsVariables?: boolean;
|
|
15
|
-
}>;
|
|
16
|
-
/**
|
|
17
|
-
* This class manages the CSS stylesheet for the page and the injection of new
|
|
18
|
-
* CSS rules.
|
|
19
|
-
*/
|
|
20
|
-
export declare class StyleXSheet {
|
|
21
|
-
static LIGHT_MODE_CLASS_NAME: string;
|
|
22
|
-
static DARK_MODE_CLASS_NAME: string;
|
|
23
|
-
constructor(opts: SheetOptions);
|
|
24
|
-
rootTheme: null | undefined | Theme;
|
|
25
|
-
rootDarkTheme: null | undefined | Theme;
|
|
26
|
-
supportsVariables: boolean;
|
|
27
|
-
rules: Array<string>;
|
|
28
|
-
injected: boolean;
|
|
29
|
-
tag: null | undefined | HTMLStyleElement;
|
|
30
|
-
ruleForPriority: Map<number, string>;
|
|
31
|
-
getVariableMatch(): RegExp;
|
|
32
|
-
isHeadless(): boolean;
|
|
33
|
-
getTag(): HTMLStyleElement;
|
|
34
|
-
getCSS(): string;
|
|
35
|
-
getRulePosition(rule: string): number;
|
|
36
|
-
getRuleCount(): number;
|
|
37
|
-
inject(): void;
|
|
38
|
-
injectTheme(): void;
|
|
39
|
-
__injectCustomThemeForTesting(selector: string, theme: Theme): void;
|
|
40
|
-
delete(rule: string): void;
|
|
41
|
-
normalizeRule(rule: string): string;
|
|
42
|
-
getInsertPositionForPriority(priority: number): number;
|
|
43
|
-
insert(
|
|
44
|
-
rawLTRRule: string,
|
|
45
|
-
priority: number,
|
|
46
|
-
rawRTLRule: null | undefined | string,
|
|
47
|
-
): void;
|
|
48
|
-
}
|
|
49
|
-
export declare const styleSheet: StyleXSheet;
|
package/lib/StyleXSheet.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.styleSheet = exports.StyleXSheet = void 0;
|
|
7
|
-
var _invariant = _interopRequireDefault(require("invariant"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
const LIGHT_MODE_CLASS_NAME = '__fb-light-mode';
|
|
10
|
-
const DARK_MODE_CLASS_NAME = '__fb-dark-mode';
|
|
11
|
-
function buildTheme(selector, theme) {
|
|
12
|
-
const lines = [];
|
|
13
|
-
lines.push(`${selector} {`);
|
|
14
|
-
for (const key in theme) {
|
|
15
|
-
const value = theme[key];
|
|
16
|
-
lines.push(` --${key}: ${value};`);
|
|
17
|
-
}
|
|
18
|
-
lines.push('}');
|
|
19
|
-
return lines.join('\n');
|
|
20
|
-
}
|
|
21
|
-
function makeStyleTag() {
|
|
22
|
-
const tag = document.createElement('style');
|
|
23
|
-
tag.setAttribute('type', 'text/css');
|
|
24
|
-
tag.setAttribute('data-stylex', 'true');
|
|
25
|
-
const head = document.head || document.getElementsByTagName('head')[0];
|
|
26
|
-
(0, _invariant.default)(head, 'expected head');
|
|
27
|
-
head.appendChild(tag);
|
|
28
|
-
return tag;
|
|
29
|
-
}
|
|
30
|
-
function doesSupportCSSVariables() {
|
|
31
|
-
return globalThis.CSS != null && globalThis.CSS.supports != null && globalThis.CSS.supports('--fake-var:0');
|
|
32
|
-
}
|
|
33
|
-
const VARIABLE_MATCH = /var\(--(.*?)\)/g;
|
|
34
|
-
class StyleXSheet {
|
|
35
|
-
static LIGHT_MODE_CLASS_NAME = (() => LIGHT_MODE_CLASS_NAME)();
|
|
36
|
-
static DARK_MODE_CLASS_NAME = (() => DARK_MODE_CLASS_NAME)();
|
|
37
|
-
constructor(opts) {
|
|
38
|
-
this.tag = null;
|
|
39
|
-
this.injected = false;
|
|
40
|
-
this.ruleForPriority = new Map();
|
|
41
|
-
this.rules = [];
|
|
42
|
-
this.rootTheme = opts.rootTheme;
|
|
43
|
-
this.rootDarkTheme = opts.rootDarkTheme;
|
|
44
|
-
this.supportsVariables = opts.supportsVariables ?? doesSupportCSSVariables();
|
|
45
|
-
}
|
|
46
|
-
getVariableMatch() {
|
|
47
|
-
return VARIABLE_MATCH;
|
|
48
|
-
}
|
|
49
|
-
isHeadless() {
|
|
50
|
-
return this.tag == null || globalThis?.document?.body == null;
|
|
51
|
-
}
|
|
52
|
-
getTag() {
|
|
53
|
-
const {
|
|
54
|
-
tag
|
|
55
|
-
} = this;
|
|
56
|
-
(0, _invariant.default)(tag != null, 'expected tag');
|
|
57
|
-
return tag;
|
|
58
|
-
}
|
|
59
|
-
getCSS() {
|
|
60
|
-
return this.rules.join('\n');
|
|
61
|
-
}
|
|
62
|
-
getRulePosition(rule) {
|
|
63
|
-
return this.rules.indexOf(rule);
|
|
64
|
-
}
|
|
65
|
-
getRuleCount() {
|
|
66
|
-
return this.rules.length;
|
|
67
|
-
}
|
|
68
|
-
inject() {
|
|
69
|
-
if (this.injected) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
this.injected = true;
|
|
73
|
-
if (globalThis.document?.body == null) {
|
|
74
|
-
this.injectTheme();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
this.tag = makeStyleTag();
|
|
78
|
-
this.injectTheme();
|
|
79
|
-
}
|
|
80
|
-
injectTheme() {
|
|
81
|
-
if (this.rootTheme != null) {
|
|
82
|
-
this.insert(buildTheme(`:root, .${LIGHT_MODE_CLASS_NAME}`, this.rootTheme), 0);
|
|
83
|
-
}
|
|
84
|
-
if (this.rootDarkTheme != null) {
|
|
85
|
-
this.insert(buildTheme(`.${DARK_MODE_CLASS_NAME}:root, .${DARK_MODE_CLASS_NAME}`, this.rootDarkTheme), 0);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
__injectCustomThemeForTesting(selector, theme) {
|
|
89
|
-
if (theme != null) {
|
|
90
|
-
this.insert(buildTheme(selector, theme), 0);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
delete(rule) {
|
|
94
|
-
const index = this.rules.indexOf(rule);
|
|
95
|
-
(0, _invariant.default)(index >= 0, "Couldn't find the index for rule %s", rule);
|
|
96
|
-
this.rules.splice(index, 1);
|
|
97
|
-
if (this.isHeadless()) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const tag = this.getTag();
|
|
101
|
-
const sheet = tag.sheet;
|
|
102
|
-
(0, _invariant.default)(sheet, 'expected sheet');
|
|
103
|
-
sheet.deleteRule(index);
|
|
104
|
-
}
|
|
105
|
-
normalizeRule(rule) {
|
|
106
|
-
const {
|
|
107
|
-
rootTheme
|
|
108
|
-
} = this;
|
|
109
|
-
if (this.supportsVariables || rootTheme == null) {
|
|
110
|
-
return rule;
|
|
111
|
-
}
|
|
112
|
-
return rule.replace(VARIABLE_MATCH, (_match, name) => {
|
|
113
|
-
return rootTheme[name];
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
getInsertPositionForPriority(priority) {
|
|
117
|
-
const priorityRule = this.ruleForPriority.get(priority);
|
|
118
|
-
if (priorityRule != null) {
|
|
119
|
-
return this.rules.indexOf(priorityRule) + 1;
|
|
120
|
-
}
|
|
121
|
-
const priorities = Array.from(this.ruleForPriority.keys()).sort((a, b) => b - a).filter(num => num > priority ? 1 : 0);
|
|
122
|
-
if (priorities.length === 0) {
|
|
123
|
-
return this.getRuleCount();
|
|
124
|
-
}
|
|
125
|
-
const lastPriority = priorities.pop();
|
|
126
|
-
if (lastPriority == null) {
|
|
127
|
-
return this.getRuleCount();
|
|
128
|
-
}
|
|
129
|
-
return this.rules.indexOf(this.ruleForPriority.get(lastPriority));
|
|
130
|
-
}
|
|
131
|
-
insert(rawLTRRule, priority, rawRTLRule) {
|
|
132
|
-
if (this.injected === false) {
|
|
133
|
-
this.inject();
|
|
134
|
-
}
|
|
135
|
-
if (rawRTLRule != null) {
|
|
136
|
-
this.insert(addAncestorSelector(rawLTRRule, "html:not([dir='rtl'])"), priority);
|
|
137
|
-
this.insert(addAncestorSelector(rawRTLRule, "html[dir='rtl']"), priority);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const rawRule = rawLTRRule;
|
|
141
|
-
if (this.rules.includes(rawRule)) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const rule = this.normalizeRule(addSpecificityLevel(rawRule, Math.floor(priority / 1000)));
|
|
145
|
-
const insertPos = this.getInsertPositionForPriority(priority);
|
|
146
|
-
this.rules.splice(insertPos, 0, rule);
|
|
147
|
-
this.ruleForPriority.set(priority, rule);
|
|
148
|
-
if (this.isHeadless()) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const tag = this.getTag();
|
|
152
|
-
const sheet = tag.sheet;
|
|
153
|
-
if (sheet != null) {
|
|
154
|
-
try {
|
|
155
|
-
sheet.insertRule(rule, Math.min(insertPos, sheet.cssRules.length));
|
|
156
|
-
} catch (err) {
|
|
157
|
-
console.error('insertRule error', err, rule, insertPos);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
exports.StyleXSheet = StyleXSheet;
|
|
163
|
-
function addAncestorSelector(selector, ancestorSelector) {
|
|
164
|
-
if (!selector.startsWith('@')) {
|
|
165
|
-
return `${ancestorSelector} ${selector}`;
|
|
166
|
-
}
|
|
167
|
-
const firstBracketIndex = selector.indexOf('{');
|
|
168
|
-
const mediaQueryPart = selector.slice(0, firstBracketIndex + 1);
|
|
169
|
-
const rest = selector.slice(firstBracketIndex + 1);
|
|
170
|
-
return `${mediaQueryPart}${ancestorSelector} ${rest}`;
|
|
171
|
-
}
|
|
172
|
-
function addSpecificityLevel(selector, index) {
|
|
173
|
-
if (selector.startsWith('@keyframes')) {
|
|
174
|
-
return selector;
|
|
175
|
-
}
|
|
176
|
-
const pseudo = Array.from({
|
|
177
|
-
length: index
|
|
178
|
-
}).map(() => ':not(#\\#)').join('');
|
|
179
|
-
const lastOpenCurly = selector.includes('::') ? selector.indexOf('::') : selector.lastIndexOf('{');
|
|
180
|
-
const beforeCurly = selector.slice(0, lastOpenCurly);
|
|
181
|
-
const afterCurly = selector.slice(lastOpenCurly);
|
|
182
|
-
return `${beforeCurly}${pseudo}${afterCurly}`;
|
|
183
|
-
}
|
|
184
|
-
const styleSheet = exports.styleSheet = new StyleXSheet({
|
|
185
|
-
supportsVariables: true,
|
|
186
|
-
rootTheme: {},
|
|
187
|
-
rootDarkTheme: {}
|
|
188
|
-
});
|
package/lib/StyleXSheet.js.flow
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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 { LegacyThemeStyles as Theme } from './StyleXTypes';
|
|
11
|
-
|
|
12
|
-
// Stylesheet options
|
|
13
|
-
type SheetOptions = $ReadOnly<{
|
|
14
|
-
rootDarkTheme?: Theme,
|
|
15
|
-
rootTheme?: Theme,
|
|
16
|
-
supportsVariables?: boolean,
|
|
17
|
-
}>;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* This class manages the CSS stylesheet for the page and the injection of new
|
|
21
|
-
* CSS rules.
|
|
22
|
-
*/
|
|
23
|
-
declare export class StyleXSheet {
|
|
24
|
-
static LIGHT_MODE_CLASS_NAME: string;
|
|
25
|
-
static DARK_MODE_CLASS_NAME: string;
|
|
26
|
-
constructor(opts: SheetOptions): void;
|
|
27
|
-
rootTheme: ?Theme;
|
|
28
|
-
rootDarkTheme: ?Theme;
|
|
29
|
-
supportsVariables: boolean;
|
|
30
|
-
rules: Array<string>;
|
|
31
|
-
injected: boolean;
|
|
32
|
-
tag: ?HTMLStyleElement;
|
|
33
|
-
ruleForPriority: Map<number, string>;
|
|
34
|
-
getVariableMatch(): RegExp;
|
|
35
|
-
isHeadless(): boolean;
|
|
36
|
-
getTag(): HTMLStyleElement;
|
|
37
|
-
getCSS(): string;
|
|
38
|
-
getRulePosition(rule: string): number;
|
|
39
|
-
getRuleCount(): number;
|
|
40
|
-
inject(): void;
|
|
41
|
-
injectTheme(): void;
|
|
42
|
-
__injectCustomThemeForTesting(selector: string, theme: Theme): void;
|
|
43
|
-
delete(rule: string): void;
|
|
44
|
-
normalizeRule(rule: string): string;
|
|
45
|
-
getInsertPositionForPriority(priority: number): number;
|
|
46
|
-
insert(rawLTRRule: string, priority: number, rawRTLRule: ?string): void;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
declare export const styleSheet: StyleXSheet;
|
package/lib/StyleXTypes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';
|
package/lib/VarTypes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
File without changes
|