@stylexjs/stylex 0.2.0-beta.9 → 0.4.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 +81 -67
- package/lib/StyleXCSSTypes.d.ts +1416 -0
- package/lib/StyleXCSSTypes.js +0 -9
- package/lib/StyleXCSSTypes.js.flow +1505 -0
- package/lib/StyleXSheet.d.ts +49 -0
- package/lib/StyleXSheet.js +22 -121
- package/lib/StyleXSheet.js.flow +49 -0
- package/lib/StyleXTypes.d.ts +218 -0
- package/lib/StyleXTypes.js +0 -9
- package/lib/StyleXTypes.js.flow +187 -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 +131 -63
- package/lib/stylex.js +116 -49
- package/lib/stylex.js.flow +147 -0
- package/package.json +11 -7
|
@@ -0,0 +1,187 @@
|
|
|
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 { CSSProperties } from './StyleXCSSTypes';
|
|
11
|
+
|
|
12
|
+
// Using an opaque type to declare ClassNames generated by stylex.
|
|
13
|
+
declare export opaque type StyleXClassNameFor<+_K, +_V>: string;
|
|
14
|
+
export type StyleXClassNameForValue<+V> = StyleXClassNameFor<mixed, V>;
|
|
15
|
+
export type StyleXClassNameForKey<+K> = StyleXClassNameFor<K, mixed>;
|
|
16
|
+
export type StyleXClassName = StyleXClassNameFor<mixed, mixed>;
|
|
17
|
+
|
|
18
|
+
// Type for arbitrarily nested Array.
|
|
19
|
+
export type StyleXArray<+T> = T | $ReadOnlyArray<StyleXArray<T>>;
|
|
20
|
+
|
|
21
|
+
type CSSPropertiesWithExtras = $ReadOnly<{
|
|
22
|
+
...CSSProperties,
|
|
23
|
+
'::before'?: CSSProperties,
|
|
24
|
+
'::after'?: CSSProperties,
|
|
25
|
+
'::backdrop'?: CSSProperties,
|
|
26
|
+
'::cue'?: CSSProperties,
|
|
27
|
+
'::cue-region'?: CSSProperties,
|
|
28
|
+
'::first-letter'?: CSSProperties,
|
|
29
|
+
'::first-line'?: CSSProperties,
|
|
30
|
+
'::file-selector-button'?: CSSProperties,
|
|
31
|
+
'::grammar-error'?: CSSProperties,
|
|
32
|
+
'::marker'?: CSSProperties,
|
|
33
|
+
'::placeholder'?: CSSProperties,
|
|
34
|
+
'::selection'?: CSSProperties,
|
|
35
|
+
'::spelling-error'?: CSSProperties,
|
|
36
|
+
'::target-text'?: CSSProperties,
|
|
37
|
+
'::-webkit-scrollbar'?: CSSProperties,
|
|
38
|
+
// webkit styles used for Search in Safari
|
|
39
|
+
'::-webkit-search-decoration'?: CSSProperties,
|
|
40
|
+
'::-webkit-search-cancel-button'?: CSSProperties,
|
|
41
|
+
'::-webkit-search-results-button'?: CSSProperties,
|
|
42
|
+
'::-webkit-search-results-decoration'?: CSSProperties,
|
|
43
|
+
}>;
|
|
44
|
+
|
|
45
|
+
export type NestedCSSPropTypes = $ReadOnly<{
|
|
46
|
+
[Key in keyof CSSPropertiesWithExtras]?: StyleXClassNameForKey<Key>,
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
export type StyleXSingleStyle = false | ?NestedCSSPropTypes;
|
|
50
|
+
export type XStyle<+T = NestedCSSPropTypes> = StyleXArray<
|
|
51
|
+
false | ?$ReadOnly<{ ...T, $$css: true }>,
|
|
52
|
+
>;
|
|
53
|
+
export type XStyleWithout<+T: { +[string]: mixed }> = XStyle<
|
|
54
|
+
$ReadOnly<$Rest<NestedCSSPropTypes, $Exact<T>>>,
|
|
55
|
+
>;
|
|
56
|
+
|
|
57
|
+
export type Keyframes = $ReadOnly<{ [name: string]: CSSProperties, ... }>;
|
|
58
|
+
|
|
59
|
+
export type LegacyThemeStyles = $ReadOnly<{
|
|
60
|
+
[constantName: string]: string,
|
|
61
|
+
...
|
|
62
|
+
}>;
|
|
63
|
+
|
|
64
|
+
type ComplexStyleValueType<+T> = T extends StyleXVar<infer U>
|
|
65
|
+
? U
|
|
66
|
+
: T extends string | number | null
|
|
67
|
+
? T
|
|
68
|
+
: T extends $ReadOnlyArray<infer U>
|
|
69
|
+
? U
|
|
70
|
+
: T extends $ReadOnly<{ default: infer A, +[string]: infer B }>
|
|
71
|
+
? ComplexStyleValueType<A> | ComplexStyleValueType<B>
|
|
72
|
+
: $ReadOnly<T>;
|
|
73
|
+
|
|
74
|
+
type _MapNamespace<+CSS: { +[string]: mixed }> = $ReadOnly<{
|
|
75
|
+
[Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>,
|
|
76
|
+
}>;
|
|
77
|
+
export type MapNamespace<+CSS: { +[string]: mixed }> = $ReadOnly<{
|
|
78
|
+
..._MapNamespace<CSS>,
|
|
79
|
+
$$css: true,
|
|
80
|
+
}>;
|
|
81
|
+
export type MapNamespaces<+S: { +[string]: mixed }> = $ReadOnly<{
|
|
82
|
+
[Key in keyof S]: S[Key] extends (...args: infer Args) => infer Obj
|
|
83
|
+
? (...args: Args) => $ReadOnly<[MapNamespace<Obj>, InlineStyles]>
|
|
84
|
+
: MapNamespace<S[Key]>,
|
|
85
|
+
}>;
|
|
86
|
+
export type Stylex$Create = <S: { +[string]: mixed }>(
|
|
87
|
+
styles: S,
|
|
88
|
+
) => MapNamespaces<S>;
|
|
89
|
+
|
|
90
|
+
export type CompiledStyles = $ReadOnly<{
|
|
91
|
+
$$css: true,
|
|
92
|
+
[key: string]: StyleXClassName,
|
|
93
|
+
}>;
|
|
94
|
+
export type InlineStyles = $ReadOnly<{
|
|
95
|
+
$$css?: void,
|
|
96
|
+
[key: string]: string,
|
|
97
|
+
}>;
|
|
98
|
+
|
|
99
|
+
type _GenStylePropType<+CSS: { +[string]: mixed }> = $ReadOnly<{
|
|
100
|
+
[Key in keyof CSS]: CSS[Key] extends { +[string]: mixed }
|
|
101
|
+
? StyleXClassNameFor<Key, $ReadOnly<CSS[Key]>>
|
|
102
|
+
: StyleXClassNameFor<Key, CSS[Key]>,
|
|
103
|
+
}>;
|
|
104
|
+
type GenStylePropType<+CSS: { +[string]: mixed }> = $ReadOnly<{
|
|
105
|
+
..._GenStylePropType<CSS>,
|
|
106
|
+
$$css: true,
|
|
107
|
+
}>;
|
|
108
|
+
|
|
109
|
+
// Replace `XStyle` with this.
|
|
110
|
+
export type StaticStyles<+CSS: { +[string]: mixed } = CSSPropertiesWithExtras> =
|
|
111
|
+
StyleXArray<false | ?GenStylePropType<$ReadOnly<CSS>>>;
|
|
112
|
+
|
|
113
|
+
export type StaticStylesWithout<+CSS: { +[string]: mixed }> = StaticStyles<
|
|
114
|
+
$Rest<CSSPropertiesWithExtras, $ReadOnly<CSS>>,
|
|
115
|
+
>;
|
|
116
|
+
|
|
117
|
+
export type StyleXStyles<+CSS: { +[string]: mixed } = CSSPropertiesWithExtras> =
|
|
118
|
+
StyleXArray<
|
|
119
|
+
| ?false
|
|
120
|
+
| GenStylePropType<$ReadOnly<CSS>>
|
|
121
|
+
| $ReadOnly<[GenStylePropType<$ReadOnly<CSS>>, InlineStyles]>,
|
|
122
|
+
>;
|
|
123
|
+
|
|
124
|
+
export type StyleXStylesWithout<+CSS: { +[string]: mixed }> = StyleXStyles<
|
|
125
|
+
$Rest<CSSPropertiesWithExtras, $ReadOnly<CSS>>,
|
|
126
|
+
>;
|
|
127
|
+
|
|
128
|
+
// This is the type for the variables object
|
|
129
|
+
declare export opaque type StyleXVar<+Val: mixed>;
|
|
130
|
+
|
|
131
|
+
declare export opaque type VarGroup<
|
|
132
|
+
+Tokens: { +[string]: mixed },
|
|
133
|
+
+_ID: string = string,
|
|
134
|
+
>: $ReadOnly<{ [Key in keyof Tokens]: StyleXVar<Tokens[Key]> }>;
|
|
135
|
+
|
|
136
|
+
export type TokensFromVarGroup<T: VarGroup<{ +[string]: mixed }>> =
|
|
137
|
+
T extends VarGroup<infer Tokens extends { +[string]: mixed }>
|
|
138
|
+
? Tokens
|
|
139
|
+
: empty;
|
|
140
|
+
type IDFromVarGroup<+T: VarGroup<{ +[string]: mixed }>> = T extends VarGroup<
|
|
141
|
+
{ +[string]: mixed },
|
|
142
|
+
infer ID,
|
|
143
|
+
>
|
|
144
|
+
? ID
|
|
145
|
+
: empty;
|
|
146
|
+
|
|
147
|
+
type TTokens = $ReadOnly<{
|
|
148
|
+
[string]:
|
|
149
|
+
| number
|
|
150
|
+
| string
|
|
151
|
+
| $ReadOnly<{ default: number | string, [string]: number | string }>
|
|
152
|
+
| StyleXVar<string | number>,
|
|
153
|
+
}>;
|
|
154
|
+
|
|
155
|
+
type UnwrapVars<T> = T extends StyleXVar<infer U> ? U : T;
|
|
156
|
+
export type FlattenTokens<T: TTokens> = {
|
|
157
|
+
+[Key in keyof T]: T[Key] extends { +default: infer X, +[string]: infer Y }
|
|
158
|
+
? UnwrapVars<X | Y>
|
|
159
|
+
: UnwrapVars<T[Key]>,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export type StyleX$DefineVars = <DefaultTokens: TTokens, ID: string = string>(
|
|
163
|
+
tokens: DefaultTokens,
|
|
164
|
+
) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
|
|
165
|
+
|
|
166
|
+
// opaque type ThemeKey<+_VG: VarGroup<{ +[string]: mixed }>>: string = string;
|
|
167
|
+
declare export opaque type Theme<
|
|
168
|
+
+T: VarGroup<{ +[string]: mixed }, string>,
|
|
169
|
+
+_Tag: string = string,
|
|
170
|
+
>: $ReadOnly<{
|
|
171
|
+
$$css: true,
|
|
172
|
+
[string]: StyleXClassNameFor<string, IDFromVarGroup<T>>,
|
|
173
|
+
}>;
|
|
174
|
+
|
|
175
|
+
export type OverridesForTokenType<Config: { +[string]: mixed }> = {
|
|
176
|
+
[Key in keyof Config]?:
|
|
177
|
+
| Config[Key]
|
|
178
|
+
| { +default: Config[Key], +[string]: Config[Key] },
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export type StyleX$CreateTheme = <
|
|
182
|
+
BaseTokens: VarGroup<{ +[string]: mixed }>,
|
|
183
|
+
ID: string = string,
|
|
184
|
+
>(
|
|
185
|
+
baseTokens: BaseTokens,
|
|
186
|
+
overrides: OverridesForTokenType<TokensFromVarGroup<BaseTokens>>,
|
|
187
|
+
) => Theme<BaseTokens, ID>;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
declare function inject(
|
|
11
|
+
ltrRule: string,
|
|
12
|
+
priority: number,
|
|
13
|
+
rtlRule: null | undefined | string,
|
|
14
|
+
): void;
|
|
15
|
+
export default inject;
|
package/lib/stylex-inject.js
CHANGED
|
@@ -5,15 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = inject;
|
|
7
7
|
var _StyleXSheet = require("./StyleXSheet");
|
|
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
8
|
function inject(ltrRule, priority) {
|
|
18
9
|
let rtlRule = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
19
10
|
_StyleXSheet.styleSheet.insert(ltrRule, priority, rtlRule);
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
declare export default function inject(
|
|
11
|
+
ltrRule: string,
|
|
12
|
+
priority: number,
|
|
13
|
+
rtlRule: ?string,
|
|
14
|
+
): void;
|
package/lib/stylex.d.ts
CHANGED
|
@@ -3,77 +3,145 @@
|
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
readonly [K in string]: CompiledNamespace;
|
|
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
|
+
export declare function props(
|
|
29
|
+
this: null | undefined | unknown,
|
|
30
|
+
...styles: ReadonlyArray<
|
|
31
|
+
StyleXArray<
|
|
32
|
+
| (null | undefined | CompiledStyles)
|
|
33
|
+
| boolean
|
|
34
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
35
|
+
>
|
|
36
|
+
>
|
|
37
|
+
): Readonly<{
|
|
38
|
+
className?: string;
|
|
39
|
+
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
51
40
|
}>;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
type Stylex$Include = <
|
|
42
|
+
TStyles extends {
|
|
43
|
+
readonly [$$Key$$: string]: StyleXClassNameFor<string, unknown>;
|
|
44
|
+
},
|
|
45
|
+
>(
|
|
46
|
+
styles: TStyles,
|
|
55
47
|
) => {
|
|
56
|
-
readonly [
|
|
48
|
+
readonly [Key in keyof TStyles]: TStyles[Key] extends StyleXClassNameFor<
|
|
49
|
+
unknown,
|
|
50
|
+
infer V
|
|
51
|
+
>
|
|
52
|
+
? V
|
|
53
|
+
: string;
|
|
57
54
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
export declare const create: Stylex$Create;
|
|
56
|
+
export declare const defineVars: StyleX$DefineVars;
|
|
57
|
+
export declare const createTheme: StyleX$CreateTheme;
|
|
58
|
+
export declare const include: Stylex$Include;
|
|
59
|
+
type ValueWithDefault<T> =
|
|
60
|
+
| T
|
|
61
|
+
| Readonly<{
|
|
62
|
+
readonly default: T;
|
|
63
|
+
readonly [$$Key$$: string]: ValueWithDefault<T>;
|
|
64
|
+
}>;
|
|
65
|
+
type CSSSyntax =
|
|
66
|
+
| '*'
|
|
67
|
+
| '<length>'
|
|
68
|
+
| '<number>'
|
|
69
|
+
| '<percentage>'
|
|
70
|
+
| '<length-percentage>'
|
|
71
|
+
| '<color>'
|
|
72
|
+
| '<image>'
|
|
73
|
+
| '<url>'
|
|
74
|
+
| '<integer>'
|
|
75
|
+
| '<angle>'
|
|
76
|
+
| '<time>'
|
|
77
|
+
| '<resolution>'
|
|
78
|
+
| '<transform-function>'
|
|
79
|
+
| '<custom-ident>'
|
|
80
|
+
| '<transform-list>';
|
|
81
|
+
type CSSSyntaxType = CSSSyntax | ReadonlyArray<CSSSyntax>;
|
|
82
|
+
interface ICSSType<T extends string | number> {
|
|
83
|
+
readonly value: ValueWithDefault<T>;
|
|
84
|
+
readonly syntax: CSSSyntaxType;
|
|
85
|
+
}
|
|
86
|
+
export declare const types: {
|
|
87
|
+
angle: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
88
|
+
color: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
89
|
+
url: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
90
|
+
image: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
91
|
+
integer: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
92
|
+
lengthPercentage: <T extends number | string>(
|
|
93
|
+
_v: ValueWithDefault<T>,
|
|
94
|
+
) => ICSSType<T>;
|
|
95
|
+
length: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
96
|
+
percentage: <T extends number | string>(
|
|
97
|
+
_v: ValueWithDefault<T>,
|
|
98
|
+
) => ICSSType<T>;
|
|
99
|
+
number: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
100
|
+
resolution: <T extends number | string>(
|
|
101
|
+
_v: ValueWithDefault<T>,
|
|
102
|
+
) => ICSSType<T>;
|
|
103
|
+
time: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
|
|
104
|
+
transformFunction: <T extends number | string>(
|
|
105
|
+
_v: ValueWithDefault<T>,
|
|
106
|
+
) => ICSSType<T>;
|
|
107
|
+
transformList: <T extends number | string>(
|
|
108
|
+
_v: ValueWithDefault<T>,
|
|
109
|
+
) => ICSSType<T>;
|
|
110
|
+
};
|
|
111
|
+
export declare const keyframes: (keyframes: Keyframes) => string;
|
|
112
|
+
export declare const firstThatWorks: <T extends string | number>(
|
|
113
|
+
...styles: ReadonlyArray<T>
|
|
114
|
+
) => ReadonlyArray<T>;
|
|
115
|
+
type IStyleX = {
|
|
64
116
|
(
|
|
65
117
|
...styles: ReadonlyArray<
|
|
66
|
-
|
|
118
|
+
StyleXArray<(null | undefined | CompiledStyles) | boolean>
|
|
67
119
|
>
|
|
68
120
|
): string;
|
|
121
|
+
props: (
|
|
122
|
+
this: null | undefined | unknown,
|
|
123
|
+
...styles: ReadonlyArray<
|
|
124
|
+
StyleXArray<
|
|
125
|
+
| (null | undefined | CompiledStyles)
|
|
126
|
+
| boolean
|
|
127
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
128
|
+
>
|
|
129
|
+
>
|
|
130
|
+
) => Readonly<{
|
|
131
|
+
className?: string;
|
|
132
|
+
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
133
|
+
}>;
|
|
69
134
|
create: Stylex$Create;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
135
|
+
defineVars: StyleX$DefineVars;
|
|
136
|
+
createTheme: StyleX$CreateTheme;
|
|
137
|
+
include: Stylex$Include;
|
|
138
|
+
types: typeof types;
|
|
139
|
+
firstThatWorks: <T extends string | number>(
|
|
140
|
+
...v: ReadonlyArray<T>
|
|
141
|
+
) => ReadonlyArray<T>;
|
|
142
|
+
keyframes: (keyframes: Keyframes) => string;
|
|
143
|
+
__customProperties?: { [$$Key$$: string]: unknown };
|
|
77
144
|
};
|
|
78
|
-
|
|
79
|
-
|
|
145
|
+
export declare const stylex: IStyleX;
|
|
146
|
+
declare const $$EXPORT_DEFAULT_DECLARATION$$: IStyleX;
|
|
147
|
+
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
package/lib/stylex.js
CHANGED
|
@@ -1,71 +1,138 @@
|
|
|
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.
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
|
|
6
|
+
exports.__monkey_patch__ = __monkey_patch__;
|
|
7
|
+
exports.keyframes = 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;
|
|
19
10
|
var _styleq = require("styleq");
|
|
20
|
-
function
|
|
21
|
-
const
|
|
11
|
+
function props() {
|
|
12
|
+
const options = this;
|
|
22
13
|
for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
23
14
|
styles[_key] = arguments[_key];
|
|
24
15
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
exports.stylex = stylex;
|
|
29
|
-
function apply() {
|
|
30
|
-
for (var _len2 = arguments.length, styles = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
31
|
-
styles[_key2] = arguments[_key2];
|
|
16
|
+
if (__implementations.props) {
|
|
17
|
+
return __implementations.props.call(options, styles);
|
|
32
18
|
}
|
|
33
19
|
const [className, style] = (0, _styleq.styleq)(styles);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
20
|
+
const result = {};
|
|
21
|
+
if (className != null && className !== '') {
|
|
22
|
+
result.className = className;
|
|
23
|
+
}
|
|
24
|
+
if (style != null && Object.keys(style).length > 0) {
|
|
25
|
+
result.style = style;
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
function stylexCreate(styles) {
|
|
30
|
+
if (__implementations.create != null) {
|
|
31
|
+
const create = __implementations.create;
|
|
32
|
+
return create(styles);
|
|
33
|
+
}
|
|
41
34
|
throw new Error('stylex.create should never be called. It should be compiled away.');
|
|
42
35
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
36
|
+
function stylexDefineVars(styles) {
|
|
37
|
+
if (__implementations.defineVars) {
|
|
38
|
+
return __implementations.defineVars(styles);
|
|
39
|
+
}
|
|
40
|
+
throw new Error('stylex.defineVars should never be called. It should be compiled away.');
|
|
45
41
|
}
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
42
|
+
const stylexCreateTheme = (baseTokens, overrides) => {
|
|
43
|
+
if (__implementations.createTheme) {
|
|
44
|
+
return __implementations.createTheme(baseTokens, overrides);
|
|
45
|
+
}
|
|
46
|
+
throw new Error('stylex.createTheme should never be called. It should be compiled away.');
|
|
47
|
+
};
|
|
48
|
+
const stylexInclude = styles => {
|
|
49
|
+
if (__implementations.include) {
|
|
50
|
+
return __implementations.include(styles);
|
|
51
|
+
}
|
|
52
|
+
throw new Error('stylex.extends should never be called. It should be compiled away.');
|
|
53
|
+
};
|
|
54
|
+
const create = exports.create = stylexCreate;
|
|
55
|
+
const defineVars = exports.defineVars = stylexDefineVars;
|
|
56
|
+
const createTheme = exports.createTheme = stylexCreateTheme;
|
|
57
|
+
const include = exports.include = stylexInclude;
|
|
58
|
+
const types = exports.types = {
|
|
59
|
+
angle: _v => {
|
|
60
|
+
throw new Error(errorForType('angle'));
|
|
61
|
+
},
|
|
62
|
+
color: _v => {
|
|
63
|
+
throw new Error(errorForType('color'));
|
|
64
|
+
},
|
|
65
|
+
url: _v => {
|
|
66
|
+
throw new Error(errorForType('url'));
|
|
67
|
+
},
|
|
68
|
+
image: _v => {
|
|
69
|
+
throw new Error(errorForType('image'));
|
|
70
|
+
},
|
|
71
|
+
integer: _v => {
|
|
72
|
+
throw new Error(errorForType('integer'));
|
|
73
|
+
},
|
|
74
|
+
lengthPercentage: _v => {
|
|
75
|
+
throw new Error(errorForType('lengthPercentage'));
|
|
76
|
+
},
|
|
77
|
+
length: _v => {
|
|
78
|
+
throw new Error(errorForType('length'));
|
|
79
|
+
},
|
|
80
|
+
percentage: _v => {
|
|
81
|
+
throw new Error(errorForType('percentage'));
|
|
82
|
+
},
|
|
83
|
+
number: _v => {
|
|
84
|
+
throw new Error(errorForType('number'));
|
|
85
|
+
},
|
|
86
|
+
resolution: _v => {
|
|
87
|
+
throw new Error(errorForType('resolution'));
|
|
88
|
+
},
|
|
89
|
+
time: _v => {
|
|
90
|
+
throw new Error(errorForType('time'));
|
|
91
|
+
},
|
|
92
|
+
transformFunction: _v => {
|
|
93
|
+
throw new Error(errorForType('transformFunction'));
|
|
94
|
+
},
|
|
95
|
+
transformList: _v => {
|
|
96
|
+
throw new Error(errorForType('transformList'));
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const errorForType = type => `stylex.types.${type} should be compiled away by @stylexjs/babel-plugin`;
|
|
100
|
+
const keyframes = keyframes => {
|
|
101
|
+
if (__implementations.keyframes) {
|
|
102
|
+
return __implementations.keyframes(keyframes);
|
|
103
|
+
}
|
|
53
104
|
throw new Error('stylex.keyframes should never be called');
|
|
54
105
|
};
|
|
55
106
|
exports.keyframes = keyframes;
|
|
56
|
-
stylex.keyframes = keyframes;
|
|
57
107
|
const firstThatWorks = function () {
|
|
108
|
+
if (__implementations.firstThatWorks) {
|
|
109
|
+
return __implementations.firstThatWorks(...arguments);
|
|
110
|
+
}
|
|
58
111
|
throw new Error('stylex.firstThatWorks should never be called.');
|
|
59
112
|
};
|
|
60
113
|
exports.firstThatWorks = firstThatWorks;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
114
|
+
function _stylex() {
|
|
115
|
+
for (var _len2 = arguments.length, styles = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
116
|
+
styles[_key2] = arguments[_key2];
|
|
117
|
+
}
|
|
118
|
+
const [className] = (0, _styleq.styleq)(styles);
|
|
119
|
+
return className;
|
|
120
|
+
}
|
|
121
|
+
_stylex.props = props;
|
|
122
|
+
_stylex.create = create;
|
|
123
|
+
_stylex.defineVars = defineVars;
|
|
124
|
+
_stylex.createTheme = createTheme;
|
|
125
|
+
_stylex.include = include;
|
|
126
|
+
_stylex.keyframes = keyframes;
|
|
127
|
+
_stylex.firstThatWorks = firstThatWorks;
|
|
128
|
+
_stylex.types = types;
|
|
129
|
+
const __implementations = {};
|
|
130
|
+
function __monkey_patch__(key, implementation) {
|
|
131
|
+
if (key === 'types') {
|
|
132
|
+
Object.assign(types, implementation);
|
|
133
|
+
} else {
|
|
134
|
+
__implementations[key] = implementation;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const stylex = exports.stylex = _stylex;
|
|
138
|
+
var _default = exports.default = _stylex;
|