@stylexjs/stylex 0.2.0-beta.8 → 0.3.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 +284 -0
- package/lib/StyleXCSSTypes.d.ts +1414 -0
- package/lib/StyleXCSSTypes.js +0 -9
- package/lib/StyleXCSSTypes.js.flow +1503 -0
- package/lib/StyleXSheet.d.ts +49 -0
- package/lib/StyleXSheet.js +7 -120
- package/lib/StyleXSheet.js.flow +49 -0
- package/lib/StyleXTypes.d.ts +212 -0
- package/lib/StyleXTypes.js +0 -9
- package/lib/StyleXTypes.js.flow +184 -0
- package/lib/native/CSSCustomPropertyValue.d.ts +26 -0
- package/lib/native/CSSCustomPropertyValue.js +27 -0
- package/lib/native/CSSCustomPropertyValue.js.flow +27 -0
- package/lib/native/CSSLengthUnitValue.d.ts +18 -0
- package/lib/native/CSSLengthUnitValue.js +73 -0
- package/lib/native/CSSLengthUnitValue.js.flow +21 -0
- package/lib/native/CSSMediaQuery.d.ts +25 -0
- package/lib/native/CSSMediaQuery.js +55 -0
- package/lib/native/CSSMediaQuery.js.flow +26 -0
- package/lib/native/SpreadOptions.d.ts +19 -0
- package/lib/native/SpreadOptions.js +1 -0
- package/lib/native/SpreadOptions.js.flow +19 -0
- package/lib/native/__tests__/__snapshots__/stylex-css-var-test.js.snap +48 -0
- package/lib/native/__tests__/__snapshots__/stylex-test.js.snap +1046 -0
- package/lib/native/__tests__/parseTimeValue-test.js +11 -0
- package/lib/native/__tests__/stylex-css-var-test.js +148 -0
- package/lib/native/__tests__/stylex-test.js +924 -0
- package/lib/native/errorMsg.d.ts +11 -0
- package/lib/native/errorMsg.js +13 -0
- package/lib/native/errorMsg.js.flow +12 -0
- package/lib/native/fixContentBox.d.ts +11 -0
- package/lib/native/fixContentBox.js +59 -0
- package/lib/native/fixContentBox.js.flow +11 -0
- package/lib/native/flattenStyle.d.ts +15 -0
- package/lib/native/flattenStyle.js +20 -0
- package/lib/native/flattenStyle.js.flow +20 -0
- package/lib/native/parseShadow.d.ts +18 -0
- package/lib/native/parseShadow.js +36 -0
- package/lib/native/parseShadow.js.flow +19 -0
- package/lib/native/parseTimeValue.d.ts +11 -0
- package/lib/native/parseTimeValue.js +18 -0
- package/lib/native/parseTimeValue.js.flow +12 -0
- package/lib/native/stylex.d.ts +50 -0
- package/lib/native/stylex.js +393 -0
- package/lib/native/stylex.js.flow +60 -0
- package/lib/stylex-inject.d.ts +15 -0
- package/lib/stylex-inject.js +0 -9
- package/lib/stylex-inject.js.flow +14 -0
- package/lib/stylex.d.ts +134 -59
- package/lib/stylex.js +123 -91
- package/lib/stylex.js.flow +151 -0
- package/package.json +8 -6
package/lib/stylex.d.ts
CHANGED
|
@@ -3,77 +3,152 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
type Stylex$Create = <S extends NamespaceSet>(
|
|
42
|
-
styles: S
|
|
43
|
-
) => $ReadOnly<{
|
|
44
|
-
readonly [K in keyof S]: {
|
|
45
|
-
readonly [P in keyof S[K]]: S[K][P] extends string | number
|
|
46
|
-
? ClassNameFor<P, S[K][P]>
|
|
47
|
-
: {
|
|
48
|
-
readonly [F in keyof S[K][P]]: ClassNameFor<`${P}+${F}`, S[K][P][F]>;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
10
|
+
import type {
|
|
11
|
+
Keyframes,
|
|
12
|
+
Stylex$Create,
|
|
13
|
+
StyleX$DefineVars,
|
|
14
|
+
StyleX$CreateTheme,
|
|
15
|
+
StyleXArray,
|
|
16
|
+
CompiledStyles,
|
|
17
|
+
InlineStyles,
|
|
18
|
+
StyleXClassNameFor,
|
|
19
|
+
} from './StyleXTypes';
|
|
20
|
+
export type {
|
|
21
|
+
VarGroup,
|
|
22
|
+
Theme,
|
|
23
|
+
StyleXStyles,
|
|
24
|
+
StyleXStylesWithout,
|
|
25
|
+
StaticStyles,
|
|
26
|
+
StaticStylesWithout,
|
|
27
|
+
} from './StyleXTypes';
|
|
28
|
+
import injectStyle from './stylex-inject';
|
|
29
|
+
export declare function props(
|
|
30
|
+
this: null | undefined | unknown,
|
|
31
|
+
...styles: ReadonlyArray<
|
|
32
|
+
StyleXArray<
|
|
33
|
+
| (null | undefined | CompiledStyles)
|
|
34
|
+
| boolean
|
|
35
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
36
|
+
>
|
|
37
|
+
>
|
|
38
|
+
): Readonly<{
|
|
39
|
+
className?: string;
|
|
40
|
+
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
51
41
|
}>;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
type Stylex$Include = <
|
|
43
|
+
TStyles extends {
|
|
44
|
+
readonly [$$Key$$: string]: StyleXClassNameFor<string, unknown>;
|
|
45
|
+
},
|
|
46
|
+
>(
|
|
47
|
+
styles: TStyles,
|
|
55
48
|
) => {
|
|
56
|
-
readonly [
|
|
49
|
+
readonly [Key in keyof TStyles]: TStyles[Key] extends StyleXClassNameFor<
|
|
50
|
+
unknown,
|
|
51
|
+
infer V
|
|
52
|
+
>
|
|
53
|
+
? V
|
|
54
|
+
: string;
|
|
57
55
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
export declare const create: Stylex$Create;
|
|
57
|
+
export declare const defineVars: StyleX$DefineVars;
|
|
58
|
+
export declare const createTheme: StyleX$CreateTheme;
|
|
59
|
+
export declare const include: Stylex$Include;
|
|
60
|
+
type ValueWithDefault<T> =
|
|
61
|
+
| T
|
|
62
|
+
| Readonly<{
|
|
63
|
+
readonly default: T;
|
|
64
|
+
readonly [$$Key$$: string]: ValueWithDefault<T>;
|
|
65
|
+
}>;
|
|
66
|
+
type CSSSyntax =
|
|
67
|
+
| '*'
|
|
68
|
+
| '<length>'
|
|
69
|
+
| '<number>'
|
|
70
|
+
| '<percentage>'
|
|
71
|
+
| '<length-percentage>'
|
|
72
|
+
| '<color>'
|
|
73
|
+
| '<image>'
|
|
74
|
+
| '<url>'
|
|
75
|
+
| '<integer>'
|
|
76
|
+
| '<angle>'
|
|
77
|
+
| '<time>'
|
|
78
|
+
| '<resolution>'
|
|
79
|
+
| '<transform-function>'
|
|
80
|
+
| '<custom-ident>'
|
|
81
|
+
| '<transform-list>';
|
|
82
|
+
type CSSSyntaxType = CSSSyntax | ReadonlyArray<CSSSyntax>;
|
|
83
|
+
interface ICSSType<T extends string | number> {
|
|
84
|
+
readonly value: ValueWithDefault<T>;
|
|
85
|
+
readonly syntax: CSSSyntaxType;
|
|
86
|
+
}
|
|
87
|
+
export declare const types: {
|
|
88
|
+
angle: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
89
|
+
color: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
90
|
+
url: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
91
|
+
image: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
92
|
+
integer: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
93
|
+
lengthPercentage: <T extends number | string>(
|
|
94
|
+
_v: ValueWithDefault<T>,
|
|
95
|
+
) => ICSSType<T>;
|
|
96
|
+
length: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
97
|
+
percentage: <T extends number | string>(
|
|
98
|
+
_v: ValueWithDefault<T>,
|
|
99
|
+
) => ICSSType<T>;
|
|
100
|
+
number: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
101
|
+
resolution: <T extends number | string>(
|
|
102
|
+
_v: ValueWithDefault<T>,
|
|
103
|
+
) => ICSSType<T>;
|
|
104
|
+
time: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
105
|
+
transformFunction: <T extends number | string>(
|
|
106
|
+
_v: ValueWithDefault<T>,
|
|
107
|
+
) => ICSSType<T>;
|
|
108
|
+
transformList: <T extends number | string>(
|
|
109
|
+
_v: ValueWithDefault<T>,
|
|
110
|
+
) => ICSSType<T>;
|
|
111
|
+
};
|
|
112
|
+
export declare const keyframes: (keyframes: Keyframes) => string;
|
|
113
|
+
export declare const firstThatWorks: <T extends string | number>(
|
|
114
|
+
...styles: ReadonlyArray<T>
|
|
115
|
+
) => ReadonlyArray<T>;
|
|
116
|
+
export declare const inject: typeof injectStyle;
|
|
117
|
+
type IStyleX = {
|
|
64
118
|
(
|
|
65
119
|
...styles: ReadonlyArray<
|
|
66
|
-
|
|
120
|
+
StyleXArray<(null | undefined | CompiledStyles) | boolean>
|
|
67
121
|
>
|
|
68
122
|
): string;
|
|
123
|
+
props: (
|
|
124
|
+
this: null | undefined | unknown,
|
|
125
|
+
...styles: ReadonlyArray<
|
|
126
|
+
StyleXArray<
|
|
127
|
+
| (null | undefined | CompiledStyles)
|
|
128
|
+
| boolean
|
|
129
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
130
|
+
>
|
|
131
|
+
>
|
|
132
|
+
) => Readonly<{
|
|
133
|
+
className?: string;
|
|
134
|
+
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
135
|
+
}>;
|
|
69
136
|
create: Stylex$Create;
|
|
70
|
-
|
|
137
|
+
defineVars: StyleX$DefineVars;
|
|
138
|
+
createTheme: StyleX$CreateTheme;
|
|
139
|
+
include: Stylex$Include;
|
|
140
|
+
types: typeof types;
|
|
141
|
+
firstThatWorks: <T extends string | number>(
|
|
142
|
+
...v: ReadonlyArray<T>
|
|
143
|
+
) => ReadonlyArray<T>;
|
|
71
144
|
inject: (
|
|
72
145
|
ltrRule: string,
|
|
73
146
|
priority: number,
|
|
74
|
-
rtlRule:
|
|
147
|
+
rtlRule: null | undefined | string,
|
|
75
148
|
) => void;
|
|
76
|
-
keyframes:
|
|
149
|
+
keyframes: (keyframes: Keyframes) => string;
|
|
150
|
+
__customProperties?: { [$$Key$$: string]: unknown };
|
|
77
151
|
};
|
|
78
|
-
|
|
79
|
-
|
|
152
|
+
export declare const stylex: IStyleX;
|
|
153
|
+
declare const $$EXPORT_DEFAULT_DECLARATION$$: IStyleX;
|
|
154
|
+
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
package/lib/stylex.js
CHANGED
|
@@ -1,110 +1,142 @@
|
|
|
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
1
|
'use strict';
|
|
11
2
|
|
|
12
3
|
Object.defineProperty(exports, "__esModule", {
|
|
13
4
|
value: true
|
|
14
5
|
});
|
|
15
|
-
exports.
|
|
6
|
+
exports.__monkey_patch__ = __monkey_patch__;
|
|
7
|
+
exports.keyframes = exports.inject = exports.include = exports.firstThatWorks = exports.defineVars = exports.default = exports.createTheme = exports.create = void 0;
|
|
8
|
+
exports.props = props;
|
|
9
|
+
exports.types = exports.stylex = void 0;
|
|
16
10
|
var _stylexInject = _interopRequireDefault(require("./stylex-inject"));
|
|
11
|
+
var _styleq = require("styleq");
|
|
17
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
function stylex() {
|
|
21
|
-
// Keep a set of property commits to the className
|
|
22
|
-
const definedProperties = [];
|
|
23
|
-
let className = '';
|
|
24
|
-
let nextCache = cache;
|
|
13
|
+
function props() {
|
|
14
|
+
const options = this;
|
|
25
15
|
for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
26
16
|
styles[_key] = arguments[_key];
|
|
27
17
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const possibleStyle = styles.pop();
|
|
31
|
-
if (Array.isArray(possibleStyle)) {
|
|
32
|
-
for (let i = 0; i < possibleStyle.length; i++) {
|
|
33
|
-
styles.push(possibleStyle[i]);
|
|
34
|
-
}
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Process an individual style object
|
|
39
|
-
const styleObj = possibleStyle;
|
|
40
|
-
if (styleObj != null && typeof styleObj === 'object') {
|
|
41
|
-
// Build up the class names defined by this object
|
|
42
|
-
let classNameChunk = '';
|
|
43
|
-
if (nextCache != null && nextCache.has(styleObj)) {
|
|
44
|
-
// Cache: read
|
|
45
|
-
const cacheEntry = nextCache.get(styleObj);
|
|
46
|
-
if (cacheEntry != null) {
|
|
47
|
-
classNameChunk = cacheEntry.classNameChunk;
|
|
48
|
-
definedProperties.push(...cacheEntry.definedPropertiesChunk);
|
|
49
|
-
nextCache = cacheEntry.next;
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
// Record the properties this object defines (and that haven't already
|
|
53
|
-
// been defined by later objects.)
|
|
54
|
-
const definedPropertiesChunk = [];
|
|
55
|
-
for (const prop in styleObj) {
|
|
56
|
-
const value = styleObj[prop];
|
|
57
|
-
// Style declarations, e.g., opacity: 's3fkgpd'
|
|
58
|
-
if (typeof value === 'string' || value === null) {
|
|
59
|
-
// Skip adding to the chunks if property has already been seen
|
|
60
|
-
if (!definedProperties.includes(prop)) {
|
|
61
|
-
definedProperties.push(prop);
|
|
62
|
-
definedPropertiesChunk.push(prop);
|
|
63
|
-
if (typeof value === 'string') {
|
|
64
|
-
classNameChunk += classNameChunk ? ' ' + value : value;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// Cache: write
|
|
70
|
-
if (nextCache != null) {
|
|
71
|
-
const emptyCache = new WeakMap();
|
|
72
|
-
nextCache.set(styleObj, {
|
|
73
|
-
classNameChunk,
|
|
74
|
-
definedPropertiesChunk,
|
|
75
|
-
next: emptyCache
|
|
76
|
-
});
|
|
77
|
-
nextCache = emptyCache;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Order of classes in chunks matches property-iteration order of style
|
|
82
|
-
// object. Order of chunks matches passed order of styles from first to
|
|
83
|
-
// last (which we iterate over in reverse).
|
|
84
|
-
if (classNameChunk) {
|
|
85
|
-
className = className ? classNameChunk + ' ' + className : classNameChunk;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
18
|
+
if (__implementations.props) {
|
|
19
|
+
return __implementations.props.call(options, styles);
|
|
88
20
|
}
|
|
89
|
-
|
|
21
|
+
const [className, style] = (0, _styleq.styleq)(styles);
|
|
22
|
+
const result = {};
|
|
23
|
+
if (className != null && className !== '') {
|
|
24
|
+
result.className = className;
|
|
25
|
+
}
|
|
26
|
+
if (style != null && Object.keys(style).length > 0) {
|
|
27
|
+
result.style = style;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
90
30
|
}
|
|
91
|
-
function stylexCreate(
|
|
31
|
+
function stylexCreate(styles) {
|
|
32
|
+
if (__implementations.create != null) {
|
|
33
|
+
const create = __implementations.create;
|
|
34
|
+
return create(styles);
|
|
35
|
+
}
|
|
92
36
|
throw new Error('stylex.create should never be called. It should be compiled away.');
|
|
93
37
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
38
|
+
function stylexDefineVars(styles) {
|
|
39
|
+
if (__implementations.defineVars) {
|
|
40
|
+
return __implementations.defineVars(styles);
|
|
41
|
+
}
|
|
42
|
+
throw new Error('stylex.defineVars should never be called. It should be compiled away.');
|
|
96
43
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
44
|
+
const stylexCreateTheme = (baseTokens, overrides) => {
|
|
45
|
+
if (__implementations.createTheme) {
|
|
46
|
+
return __implementations.createTheme(baseTokens, overrides);
|
|
47
|
+
}
|
|
48
|
+
throw new Error('stylex.createTheme should never be called. It should be compiled away.');
|
|
49
|
+
};
|
|
50
|
+
const stylexInclude = styles => {
|
|
51
|
+
if (__implementations.include) {
|
|
52
|
+
return __implementations.include(styles);
|
|
53
|
+
}
|
|
54
|
+
throw new Error('stylex.extends should never be called. It should be compiled away.');
|
|
55
|
+
};
|
|
56
|
+
const create = exports.create = stylexCreate;
|
|
57
|
+
const defineVars = exports.defineVars = stylexDefineVars;
|
|
58
|
+
const createTheme = exports.createTheme = stylexCreateTheme;
|
|
59
|
+
const include = exports.include = stylexInclude;
|
|
60
|
+
const types = exports.types = {
|
|
61
|
+
angle: _v => {
|
|
62
|
+
throw new Error(errorForType('angle'));
|
|
63
|
+
},
|
|
64
|
+
color: _v => {
|
|
65
|
+
throw new Error(errorForType('color'));
|
|
66
|
+
},
|
|
67
|
+
url: _v => {
|
|
68
|
+
throw new Error(errorForType('url'));
|
|
69
|
+
},
|
|
70
|
+
image: _v => {
|
|
71
|
+
throw new Error(errorForType('image'));
|
|
72
|
+
},
|
|
73
|
+
integer: _v => {
|
|
74
|
+
throw new Error(errorForType('integer'));
|
|
75
|
+
},
|
|
76
|
+
lengthPercentage: _v => {
|
|
77
|
+
throw new Error(errorForType('lengthPercentage'));
|
|
78
|
+
},
|
|
79
|
+
length: _v => {
|
|
80
|
+
throw new Error(errorForType('length'));
|
|
81
|
+
},
|
|
82
|
+
percentage: _v => {
|
|
83
|
+
throw new Error(errorForType('percentage'));
|
|
84
|
+
},
|
|
85
|
+
number: _v => {
|
|
86
|
+
throw new Error(errorForType('number'));
|
|
87
|
+
},
|
|
88
|
+
resolution: _v => {
|
|
89
|
+
throw new Error(errorForType('resolution'));
|
|
90
|
+
},
|
|
91
|
+
time: _v => {
|
|
92
|
+
throw new Error(errorForType('time'));
|
|
93
|
+
},
|
|
94
|
+
transformFunction: _v => {
|
|
95
|
+
throw new Error(errorForType('transformFunction'));
|
|
96
|
+
},
|
|
97
|
+
transformList: _v => {
|
|
98
|
+
throw new Error(errorForType('transformList'));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const errorForType = type => `stylex.types.${type} should be compiled away by @stylexjs/babel-plugin`;
|
|
102
|
+
const keyframes = keyframes => {
|
|
103
|
+
if (__implementations.keyframes) {
|
|
104
|
+
return __implementations.keyframes(keyframes);
|
|
105
|
+
}
|
|
100
106
|
throw new Error('stylex.keyframes should never be called');
|
|
101
107
|
};
|
|
102
|
-
|
|
108
|
+
exports.keyframes = keyframes;
|
|
109
|
+
const firstThatWorks = function () {
|
|
110
|
+
if (__implementations.firstThatWorks) {
|
|
111
|
+
return __implementations.firstThatWorks(...arguments);
|
|
112
|
+
}
|
|
103
113
|
throw new Error('stylex.firstThatWorks should never be called.');
|
|
104
114
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
exports.firstThatWorks = firstThatWorks;
|
|
116
|
+
const inject = exports.inject = _stylexInject.default;
|
|
117
|
+
function _stylex() {
|
|
118
|
+
for (var _len2 = arguments.length, styles = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
119
|
+
styles[_key2] = arguments[_key2];
|
|
120
|
+
}
|
|
121
|
+
const [className] = (0, _styleq.styleq)(styles);
|
|
122
|
+
return className;
|
|
123
|
+
}
|
|
124
|
+
_stylex.props = props;
|
|
125
|
+
_stylex.create = create;
|
|
126
|
+
_stylex.defineVars = defineVars;
|
|
127
|
+
_stylex.createTheme = createTheme;
|
|
128
|
+
_stylex.include = include;
|
|
129
|
+
_stylex.keyframes = keyframes;
|
|
130
|
+
_stylex.firstThatWorks = firstThatWorks;
|
|
131
|
+
_stylex.inject = inject;
|
|
132
|
+
_stylex.types = types;
|
|
133
|
+
const __implementations = {};
|
|
134
|
+
function __monkey_patch__(key, implementation) {
|
|
135
|
+
if (key === 'types') {
|
|
136
|
+
Object.assign(types, implementation);
|
|
137
|
+
} else {
|
|
138
|
+
__implementations[key] = implementation;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const stylex = exports.stylex = _stylex;
|
|
142
|
+
var _default = exports.default = _stylex;
|
|
@@ -0,0 +1,151 @@
|
|
|
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
|
+
Keyframes,
|
|
12
|
+
Stylex$Create,
|
|
13
|
+
StyleX$DefineVars,
|
|
14
|
+
StyleX$CreateTheme,
|
|
15
|
+
StyleXArray,
|
|
16
|
+
CompiledStyles,
|
|
17
|
+
InlineStyles,
|
|
18
|
+
StyleXClassNameFor,
|
|
19
|
+
} from './StyleXTypes';
|
|
20
|
+
|
|
21
|
+
export type {
|
|
22
|
+
VarGroup,
|
|
23
|
+
Theme,
|
|
24
|
+
StyleXStyles,
|
|
25
|
+
StyleXStylesWithout,
|
|
26
|
+
StaticStyles,
|
|
27
|
+
StaticStylesWithout,
|
|
28
|
+
} from './StyleXTypes';
|
|
29
|
+
|
|
30
|
+
import injectStyle from './stylex-inject';
|
|
31
|
+
declare export function props(
|
|
32
|
+
this: ?mixed,
|
|
33
|
+
...styles: $ReadOnlyArray<
|
|
34
|
+
StyleXArray<
|
|
35
|
+
?CompiledStyles | boolean | $ReadOnly<[CompiledStyles, InlineStyles]>,
|
|
36
|
+
>,
|
|
37
|
+
>
|
|
38
|
+
): $ReadOnly<{
|
|
39
|
+
className?: string,
|
|
40
|
+
style?: $ReadOnly<{ [string]: string | number }>,
|
|
41
|
+
}>;
|
|
42
|
+
|
|
43
|
+
type Stylex$Include = <
|
|
44
|
+
TStyles: { +[string]: StyleXClassNameFor<string, mixed> },
|
|
45
|
+
>(
|
|
46
|
+
styles: TStyles,
|
|
47
|
+
) => {
|
|
48
|
+
+[Key in keyof TStyles]: TStyles[Key] extends StyleXClassNameFor<
|
|
49
|
+
mixed,
|
|
50
|
+
infer V,
|
|
51
|
+
>
|
|
52
|
+
? V
|
|
53
|
+
: string,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
declare export const create: Stylex$Create;
|
|
57
|
+
|
|
58
|
+
declare export const defineVars: StyleX$DefineVars;
|
|
59
|
+
|
|
60
|
+
declare export const createTheme: StyleX$CreateTheme;
|
|
61
|
+
|
|
62
|
+
declare export const include: Stylex$Include;
|
|
63
|
+
|
|
64
|
+
type ValueWithDefault<+T> =
|
|
65
|
+
| T
|
|
66
|
+
| $ReadOnly<{
|
|
67
|
+
+default: T,
|
|
68
|
+
+[string]: ValueWithDefault<T>,
|
|
69
|
+
}>;
|
|
70
|
+
|
|
71
|
+
type CSSSyntax =
|
|
72
|
+
| '*'
|
|
73
|
+
| '<length>'
|
|
74
|
+
| '<number>'
|
|
75
|
+
| '<percentage>'
|
|
76
|
+
| '<length-percentage>'
|
|
77
|
+
| '<color>'
|
|
78
|
+
| '<image>'
|
|
79
|
+
| '<url>'
|
|
80
|
+
| '<integer>'
|
|
81
|
+
| '<angle>'
|
|
82
|
+
| '<time>'
|
|
83
|
+
| '<resolution>'
|
|
84
|
+
| '<transform-function>'
|
|
85
|
+
| '<custom-ident>'
|
|
86
|
+
| '<transform-list>';
|
|
87
|
+
|
|
88
|
+
type CSSSyntaxType = CSSSyntax | $ReadOnlyArray<CSSSyntax>;
|
|
89
|
+
|
|
90
|
+
interface ICSSType<+T: string | number> {
|
|
91
|
+
+value: ValueWithDefault<T>;
|
|
92
|
+
+syntax: CSSSyntaxType;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
declare export const types: {
|
|
96
|
+
angle: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
97
|
+
color: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
98
|
+
url: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
99
|
+
image: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
100
|
+
integer: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
101
|
+
lengthPercentage: <T: number | string>(
|
|
102
|
+
_v: ValueWithDefault<T>,
|
|
103
|
+
) => ICSSType<T>,
|
|
104
|
+
length: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
105
|
+
percentage: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
106
|
+
number: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
107
|
+
resolution: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
108
|
+
time: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
109
|
+
transformFunction: <T: number | string>(
|
|
110
|
+
_v: ValueWithDefault<T>,
|
|
111
|
+
) => ICSSType<T>,
|
|
112
|
+
transformList: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
113
|
+
};
|
|
114
|
+
declare export const keyframes: (keyframes: Keyframes) => string;
|
|
115
|
+
|
|
116
|
+
declare export const firstThatWorks: <T: string | number>(
|
|
117
|
+
...styles: $ReadOnlyArray<T>
|
|
118
|
+
) => $ReadOnlyArray<T>;
|
|
119
|
+
|
|
120
|
+
declare export const inject: typeof injectStyle;
|
|
121
|
+
|
|
122
|
+
type IStyleX = {
|
|
123
|
+
(...styles: $ReadOnlyArray<StyleXArray<?CompiledStyles | boolean>>): string,
|
|
124
|
+
props: (
|
|
125
|
+
this: ?mixed,
|
|
126
|
+
...styles: $ReadOnlyArray<
|
|
127
|
+
StyleXArray<
|
|
128
|
+
?CompiledStyles | boolean | $ReadOnly<[CompiledStyles, InlineStyles]>,
|
|
129
|
+
>,
|
|
130
|
+
>
|
|
131
|
+
) => $ReadOnly<{
|
|
132
|
+
className?: string,
|
|
133
|
+
style?: $ReadOnly<{ [string]: string | number }>,
|
|
134
|
+
}>,
|
|
135
|
+
create: Stylex$Create,
|
|
136
|
+
defineVars: StyleX$DefineVars,
|
|
137
|
+
createTheme: StyleX$CreateTheme,
|
|
138
|
+
include: Stylex$Include,
|
|
139
|
+
types: typeof types,
|
|
140
|
+
firstThatWorks: <T: string | number>(
|
|
141
|
+
...v: $ReadOnlyArray<T>
|
|
142
|
+
) => $ReadOnlyArray<T>,
|
|
143
|
+
inject: (ltrRule: string, priority: number, rtlRule: ?string) => void,
|
|
144
|
+
keyframes: (keyframes: Keyframes) => string,
|
|
145
|
+
__customProperties?: { [string]: mixed },
|
|
146
|
+
...
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
declare export const stylex: IStyleX;
|
|
151
|
+
declare export default IStyleX;
|
package/package.json
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/stylex",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "A library for defining styles for optimized user interfaces.",
|
|
5
5
|
"main": "lib/stylex.js",
|
|
6
6
|
"types": "lib/stylex.d.ts",
|
|
7
|
-
"repository": "https://www.github.com/
|
|
8
|
-
"author": "Naman Goel <nmn@fb.com>",
|
|
7
|
+
"repository": "https://www.github.com/facebook/stylex",
|
|
9
8
|
"license": "MIT",
|
|
10
9
|
"scripts": {
|
|
10
|
+
"prebuild": "gen-types -i src/ -o lib/",
|
|
11
11
|
"build": "babel src/ --out-dir lib/ --copy-files",
|
|
12
|
-
"build-haste": "
|
|
12
|
+
"build-haste": "rewrite-imports -i src/ -o lib/",
|
|
13
13
|
"test": "jest"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"css-mediaquery": "^0.1.2",
|
|
16
17
|
"invariant": "^2.2.4",
|
|
18
|
+
"styleq": "0.1.3",
|
|
17
19
|
"utility-types": "^3.10.0"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
20
|
-
"
|
|
22
|
+
"@stylexjs/scripts": "0.3.0"
|
|
21
23
|
},
|
|
22
24
|
"jest": {},
|
|
23
25
|
"files": [
|