@stylexjs/stylex 0.4.1 → 0.5.0-alpha.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/es/StyleXCSSTypes.js +1 -0
- package/lib/es/StyleXSheet.js +234 -0
- package/lib/es/StyleXTypes.d.ts +218 -0
- package/lib/es/StyleXTypes.js +1 -0
- package/lib/es/stylex-inject.js +5 -0
- package/lib/es/stylex.js +316 -0
- package/lib/stylex.d.ts +19 -1
- package/lib/stylex.js +40 -23
- package/lib/stylex.js.flow +22 -1
- package/package.json +32 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
function getDefaultExportFromCjs (x) {
|
|
2
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Use invariant() to assert state which your program assumes to be true.
|
|
14
|
+
*
|
|
15
|
+
* Provide sprintf-style format (only %s is supported) and arguments
|
|
16
|
+
* to provide information about what broke and what you were
|
|
17
|
+
* expecting.
|
|
18
|
+
*
|
|
19
|
+
* The invariant message will be stripped in production, but the invariant
|
|
20
|
+
* will remain to ensure logic does not differ in production.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
var NODE_ENV = process.env.NODE_ENV;
|
|
24
|
+
|
|
25
|
+
var invariant = function(condition, format, a, b, c, d, e, f) {
|
|
26
|
+
if (NODE_ENV !== 'production') {
|
|
27
|
+
if (format === undefined) {
|
|
28
|
+
throw new Error('invariant requires an error message argument');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!condition) {
|
|
33
|
+
var error;
|
|
34
|
+
if (format === undefined) {
|
|
35
|
+
error = new Error(
|
|
36
|
+
'Minified exception occurred; use the non-minified dev environment ' +
|
|
37
|
+
'for the full error message and additional helpful warnings.'
|
|
38
|
+
);
|
|
39
|
+
} else {
|
|
40
|
+
var args = [a, b, c, d, e, f];
|
|
41
|
+
var argIndex = 0;
|
|
42
|
+
error = new Error(
|
|
43
|
+
format.replace(/%s/g, function() { return args[argIndex++]; })
|
|
44
|
+
);
|
|
45
|
+
error.name = 'Invariant Violation';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
error.framesToPop = 1; // we don't care about invariant's own frame
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var invariant_1 = invariant;
|
|
54
|
+
|
|
55
|
+
var invariant$1 = /*@__PURE__*/getDefaultExportFromCjs(invariant_1);
|
|
56
|
+
|
|
57
|
+
const LIGHT_MODE_CLASS_NAME = '__fb-light-mode';
|
|
58
|
+
const DARK_MODE_CLASS_NAME = '__fb-dark-mode';
|
|
59
|
+
function buildTheme(selector, theme) {
|
|
60
|
+
const lines = [];
|
|
61
|
+
lines.push(`${selector} {`);
|
|
62
|
+
for (const key in theme) {
|
|
63
|
+
const value = theme[key];
|
|
64
|
+
lines.push(` --${key}: ${value};`);
|
|
65
|
+
}
|
|
66
|
+
lines.push('}');
|
|
67
|
+
return lines.join('\n');
|
|
68
|
+
}
|
|
69
|
+
function makeStyleTag() {
|
|
70
|
+
const tag = document.createElement('style');
|
|
71
|
+
tag.setAttribute('type', 'text/css');
|
|
72
|
+
tag.setAttribute('data-stylex', 'true');
|
|
73
|
+
const head = document.head || document.getElementsByTagName('head')[0];
|
|
74
|
+
invariant$1(head, 'expected head');
|
|
75
|
+
head.appendChild(tag);
|
|
76
|
+
return tag;
|
|
77
|
+
}
|
|
78
|
+
function doesSupportCSSVariables() {
|
|
79
|
+
return globalThis.CSS != null && globalThis.CSS.supports != null && globalThis.CSS.supports('--fake-var:0');
|
|
80
|
+
}
|
|
81
|
+
const VARIABLE_MATCH = /var\(--(.*?)\)/g;
|
|
82
|
+
class StyleXSheet {
|
|
83
|
+
static LIGHT_MODE_CLASS_NAME = LIGHT_MODE_CLASS_NAME;
|
|
84
|
+
static DARK_MODE_CLASS_NAME = DARK_MODE_CLASS_NAME;
|
|
85
|
+
constructor(opts) {
|
|
86
|
+
this.tag = null;
|
|
87
|
+
this.injected = false;
|
|
88
|
+
this.ruleForPriority = new Map();
|
|
89
|
+
this.rules = [];
|
|
90
|
+
this.rootTheme = opts.rootTheme;
|
|
91
|
+
this.rootDarkTheme = opts.rootDarkTheme;
|
|
92
|
+
this.supportsVariables = opts.supportsVariables ?? doesSupportCSSVariables();
|
|
93
|
+
}
|
|
94
|
+
getVariableMatch() {
|
|
95
|
+
return VARIABLE_MATCH;
|
|
96
|
+
}
|
|
97
|
+
isHeadless() {
|
|
98
|
+
return this.tag == null || globalThis?.document?.body == null;
|
|
99
|
+
}
|
|
100
|
+
getTag() {
|
|
101
|
+
const {
|
|
102
|
+
tag
|
|
103
|
+
} = this;
|
|
104
|
+
invariant$1(tag != null, 'expected tag');
|
|
105
|
+
return tag;
|
|
106
|
+
}
|
|
107
|
+
getCSS() {
|
|
108
|
+
return this.rules.join('\n');
|
|
109
|
+
}
|
|
110
|
+
getRulePosition(rule) {
|
|
111
|
+
return this.rules.indexOf(rule);
|
|
112
|
+
}
|
|
113
|
+
getRuleCount() {
|
|
114
|
+
return this.rules.length;
|
|
115
|
+
}
|
|
116
|
+
inject() {
|
|
117
|
+
if (this.injected) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.injected = true;
|
|
121
|
+
if (globalThis.document?.body == null) {
|
|
122
|
+
this.injectTheme();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.tag = makeStyleTag();
|
|
126
|
+
this.injectTheme();
|
|
127
|
+
}
|
|
128
|
+
injectTheme() {
|
|
129
|
+
if (this.rootTheme != null) {
|
|
130
|
+
this.insert(buildTheme(`:root, .${LIGHT_MODE_CLASS_NAME}`, this.rootTheme), 0);
|
|
131
|
+
}
|
|
132
|
+
if (this.rootDarkTheme != null) {
|
|
133
|
+
this.insert(buildTheme(`.${DARK_MODE_CLASS_NAME}:root, .${DARK_MODE_CLASS_NAME}`, this.rootDarkTheme), 0);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
__injectCustomThemeForTesting(selector, theme) {
|
|
137
|
+
if (theme != null) {
|
|
138
|
+
this.insert(buildTheme(selector, theme), 0);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
delete(rule) {
|
|
142
|
+
const index = this.rules.indexOf(rule);
|
|
143
|
+
invariant$1(index >= 0, "Couldn't find the index for rule %s", rule);
|
|
144
|
+
this.rules.splice(index, 1);
|
|
145
|
+
if (this.isHeadless()) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const tag = this.getTag();
|
|
149
|
+
const sheet = tag.sheet;
|
|
150
|
+
invariant$1(sheet, 'expected sheet');
|
|
151
|
+
sheet.deleteRule(index);
|
|
152
|
+
}
|
|
153
|
+
normalizeRule(rule) {
|
|
154
|
+
const {
|
|
155
|
+
rootTheme
|
|
156
|
+
} = this;
|
|
157
|
+
if (this.supportsVariables || rootTheme == null) {
|
|
158
|
+
return rule;
|
|
159
|
+
}
|
|
160
|
+
return rule.replace(VARIABLE_MATCH, (_match, name) => {
|
|
161
|
+
return rootTheme[name];
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
getInsertPositionForPriority(priority) {
|
|
165
|
+
const priorityRule = this.ruleForPriority.get(priority);
|
|
166
|
+
if (priorityRule != null) {
|
|
167
|
+
return this.rules.indexOf(priorityRule) + 1;
|
|
168
|
+
}
|
|
169
|
+
const priorities = Array.from(this.ruleForPriority.keys()).sort((a, b) => b - a).filter(num => num > priority ? 1 : 0);
|
|
170
|
+
if (priorities.length === 0) {
|
|
171
|
+
return this.getRuleCount();
|
|
172
|
+
}
|
|
173
|
+
const lastPriority = priorities.pop();
|
|
174
|
+
return this.rules.indexOf(this.ruleForPriority.get(lastPriority));
|
|
175
|
+
}
|
|
176
|
+
insert(rawLTRRule, priority, rawRTLRule) {
|
|
177
|
+
if (this.injected === false) {
|
|
178
|
+
this.inject();
|
|
179
|
+
}
|
|
180
|
+
if (rawRTLRule != null) {
|
|
181
|
+
this.insert(addAncestorSelector(rawLTRRule, "html:not([dir='rtl'])"), priority);
|
|
182
|
+
this.insert(addAncestorSelector(rawRTLRule, "html[dir='rtl']"), priority);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const rawRule = rawLTRRule;
|
|
186
|
+
if (this.rules.includes(rawRule)) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const rule = this.normalizeRule(addSpecificityLevel(rawRule, Math.floor(priority / 1000)));
|
|
190
|
+
const insertPos = this.getInsertPositionForPriority(priority);
|
|
191
|
+
this.rules.splice(insertPos, 0, rule);
|
|
192
|
+
this.ruleForPriority.set(priority, rule);
|
|
193
|
+
if (this.isHeadless()) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const tag = this.getTag();
|
|
197
|
+
const sheet = tag.sheet;
|
|
198
|
+
if (sheet != null) {
|
|
199
|
+
try {
|
|
200
|
+
sheet.insertRule(rule, Math.min(insertPos, sheet.cssRules.length));
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.error('insertRule error', err, rule, insertPos);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function addAncestorSelector(selector, ancestorSelector) {
|
|
208
|
+
if (!selector.startsWith('@')) {
|
|
209
|
+
return `${ancestorSelector} ${selector}`;
|
|
210
|
+
}
|
|
211
|
+
const firstBracketIndex = selector.indexOf('{');
|
|
212
|
+
const mediaQueryPart = selector.slice(0, firstBracketIndex + 1);
|
|
213
|
+
const rest = selector.slice(firstBracketIndex + 1);
|
|
214
|
+
return `${mediaQueryPart}${ancestorSelector} ${rest}`;
|
|
215
|
+
}
|
|
216
|
+
function addSpecificityLevel(selector, index) {
|
|
217
|
+
if (selector.startsWith('@keyframes')) {
|
|
218
|
+
return selector;
|
|
219
|
+
}
|
|
220
|
+
const pseudo = Array.from({
|
|
221
|
+
length: index
|
|
222
|
+
}).map(() => ':not(#\\#)').join('');
|
|
223
|
+
const lastOpenCurly = selector.includes('::') ? selector.indexOf('::') : selector.lastIndexOf('{');
|
|
224
|
+
const beforeCurly = selector.slice(0, lastOpenCurly);
|
|
225
|
+
const afterCurly = selector.slice(lastOpenCurly);
|
|
226
|
+
return `${beforeCurly}${pseudo}${afterCurly}`;
|
|
227
|
+
}
|
|
228
|
+
const styleSheet = new StyleXSheet({
|
|
229
|
+
supportsVariables: true,
|
|
230
|
+
rootTheme: {},
|
|
231
|
+
rootDarkTheme: {}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
export { StyleXSheet, styleSheet };
|
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
import type { CSSProperties } from './StyleXCSSTypes';
|
|
9
|
+
|
|
10
|
+
// Using an opaque type to declare ClassNames generated by stylex.
|
|
11
|
+
declare const StyleXClassNameTag: unique symbol;
|
|
12
|
+
export type StyleXClassNameFor<K, V> = string & {
|
|
13
|
+
_opaque: typeof StyleXClassNameTag;
|
|
14
|
+
_key: K;
|
|
15
|
+
_value: V;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type StyleXClassNameForValue<V> = StyleXClassNameFor<any, V>;
|
|
19
|
+
export type StyleXClassNameForKey<K> = StyleXClassNameFor<K, any>;
|
|
20
|
+
export type StyleXClassName = StyleXClassNameFor<any, any>;
|
|
21
|
+
// Type for arbitrarily nested Array.
|
|
22
|
+
export type StyleXArray<T> = T | ReadonlyArray<StyleXArray<T>>;
|
|
23
|
+
|
|
24
|
+
declare const StyleXVarTag: unique symbol;
|
|
25
|
+
declare class _StyleXVar<out Val> {
|
|
26
|
+
private _opaque: typeof StyleXVarTag;
|
|
27
|
+
private _value: Val;
|
|
28
|
+
}
|
|
29
|
+
export type StyleXVar<Val> = _StyleXVar<Val> & string;
|
|
30
|
+
|
|
31
|
+
type PseudoClassStr = `:${string}`;
|
|
32
|
+
type AtRuleStr = `@${string}`;
|
|
33
|
+
|
|
34
|
+
type CondStr = PseudoClassStr | AtRuleStr;
|
|
35
|
+
|
|
36
|
+
type CSSPropertiesWithExtras = Partial<
|
|
37
|
+
Readonly<
|
|
38
|
+
CSSProperties & {
|
|
39
|
+
'::after': CSSProperties;
|
|
40
|
+
'::backdrop': CSSProperties;
|
|
41
|
+
'::before': CSSProperties;
|
|
42
|
+
'::cue': CSSProperties;
|
|
43
|
+
'::cue-region': CSSProperties;
|
|
44
|
+
'::first-letter': CSSProperties;
|
|
45
|
+
'::first-line': CSSProperties;
|
|
46
|
+
'::file-selector-button': CSSProperties;
|
|
47
|
+
'::grammar-error': CSSProperties;
|
|
48
|
+
'::marker': CSSProperties;
|
|
49
|
+
// This is a pattern and not a static key so it cannot be typed correctly.
|
|
50
|
+
// [key: `::part(${string})` | `::slotted(${string})`]: CSSProperties;
|
|
51
|
+
'::placeholder': CSSProperties;
|
|
52
|
+
'::selection': CSSProperties;
|
|
53
|
+
// This is a pattern and not a static key so it cannot be typed correctly.
|
|
54
|
+
// '::slotted()': CSSProperties;
|
|
55
|
+
'::spelling-error': CSSProperties;
|
|
56
|
+
'::target-text': CSSProperties;
|
|
57
|
+
'::-webkit-scrollbar'?: CSSProperties;
|
|
58
|
+
// webkit styles used for Search in Safari
|
|
59
|
+
'::-webkit-search-decoration'?: CSSProperties;
|
|
60
|
+
'::-webkit-search-cancel-button'?: CSSProperties;
|
|
61
|
+
'::-webkit-search-results-button'?: CSSProperties;
|
|
62
|
+
'::-webkit-search-results-decoration'?: CSSProperties;
|
|
63
|
+
}
|
|
64
|
+
>
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
export type NestedCSSPropTypes = Partial<
|
|
68
|
+
Readonly<{
|
|
69
|
+
[Key in keyof CSSPropertiesWithExtras]: StyleXClassNameFor<
|
|
70
|
+
Key,
|
|
71
|
+
CSSPropertiesWithExtras[Key]
|
|
72
|
+
>;
|
|
73
|
+
}>
|
|
74
|
+
>;
|
|
75
|
+
|
|
76
|
+
type UserAuthoredStyles = CSSPropertiesWithExtras | { [key: string]: unknown };
|
|
77
|
+
export type StyleXSingleStyle = false | (null | undefined | NestedCSSPropTypes);
|
|
78
|
+
// NOTE: `XStyle` has been deprecated in favor of `StaticStyles` and `StyleXStyles`.
|
|
79
|
+
|
|
80
|
+
export type Keyframes = Readonly<{ [name: string]: CSSProperties }>;
|
|
81
|
+
export type LegacyThemeStyles = Readonly<{ [constantName: string]: string }>;
|
|
82
|
+
|
|
83
|
+
type ComplexStyleValueType<T> = T extends StyleXVar<infer U>
|
|
84
|
+
? U
|
|
85
|
+
: T extends string | number | null
|
|
86
|
+
? T
|
|
87
|
+
: T extends ReadonlyArray<infer U>
|
|
88
|
+
? U
|
|
89
|
+
: T extends Readonly<{ default: infer A; [cond: CondStr]: infer B }>
|
|
90
|
+
? ComplexStyleValueType<A> | ComplexStyleValueType<B>
|
|
91
|
+
: T;
|
|
92
|
+
|
|
93
|
+
export type MapNamespace<CSS> = Readonly<{
|
|
94
|
+
[Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>;
|
|
95
|
+
}>;
|
|
96
|
+
|
|
97
|
+
export type MapNamespaces<
|
|
98
|
+
S extends {
|
|
99
|
+
[key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
|
|
100
|
+
},
|
|
101
|
+
> = Readonly<{
|
|
102
|
+
[Key in keyof S]: S[Key] extends (...args: infer Args) => infer Obj
|
|
103
|
+
? (...args: Args) => Readonly<[MapNamespace<Obj>, InlineStyles]>
|
|
104
|
+
: MapNamespace<S[Key]>;
|
|
105
|
+
}>;
|
|
106
|
+
|
|
107
|
+
export type Stylex$Create = <
|
|
108
|
+
const S extends {
|
|
109
|
+
[key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
|
|
110
|
+
},
|
|
111
|
+
>(
|
|
112
|
+
styles: S,
|
|
113
|
+
) => MapNamespaces<S>;
|
|
114
|
+
|
|
115
|
+
export type CompiledStyles =
|
|
116
|
+
| Readonly<{
|
|
117
|
+
[key: string]: StyleXClassName | null | void | never;
|
|
118
|
+
}>
|
|
119
|
+
| Readonly<{
|
|
120
|
+
theme: StyleXClassName;
|
|
121
|
+
}>;
|
|
122
|
+
|
|
123
|
+
declare const StyleXInlineStylesTag: unique symbol;
|
|
124
|
+
|
|
125
|
+
export type InlineStyles = typeof StyleXInlineStylesTag;
|
|
126
|
+
|
|
127
|
+
type _GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<{
|
|
128
|
+
[Key in keyof CSS]: StyleXClassNameFor<Key, Readonly<CSS[Key]>>;
|
|
129
|
+
}>;
|
|
130
|
+
type GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<
|
|
131
|
+
_GenStylePropType<CSS> &
|
|
132
|
+
Partial<{
|
|
133
|
+
[Key in Exclude<keyof CSSPropertiesWithExtras, keyof CSS>]: never;
|
|
134
|
+
}>
|
|
135
|
+
>;
|
|
136
|
+
|
|
137
|
+
// Replace `XStyle` with this.
|
|
138
|
+
export type StaticStyles<
|
|
139
|
+
CSS extends UserAuthoredStyles = CSSPropertiesWithExtras,
|
|
140
|
+
> = StyleXArray<false | null | GenStylePropType<CSS>>;
|
|
141
|
+
|
|
142
|
+
export type StaticStylesWithout<CSS extends UserAuthoredStyles> = StaticStyles<
|
|
143
|
+
Omit<CSSPropertiesWithExtras, keyof CSS>
|
|
144
|
+
>;
|
|
145
|
+
|
|
146
|
+
export type StyleXStyles<
|
|
147
|
+
CSS extends UserAuthoredStyles = CSSPropertiesWithExtras,
|
|
148
|
+
> = StyleXArray<
|
|
149
|
+
| null
|
|
150
|
+
| false
|
|
151
|
+
| GenStylePropType<CSS>
|
|
152
|
+
| Readonly<[GenStylePropType<CSS>, InlineStyles]>
|
|
153
|
+
>;
|
|
154
|
+
export type StyleXStylesWithout<CSS extends UserAuthoredStyles> = StyleXStyles<
|
|
155
|
+
Omit<CSSPropertiesWithExtras, keyof CSS>
|
|
156
|
+
>;
|
|
157
|
+
|
|
158
|
+
declare const StyleXVarGroupTag: unique symbol;
|
|
159
|
+
export type VarGroup<
|
|
160
|
+
Tokens extends { [key: string]: any },
|
|
161
|
+
ID extends symbol = symbol,
|
|
162
|
+
> = Readonly<{
|
|
163
|
+
[Key in keyof Tokens]: StyleXVar<Tokens[Key]>;
|
|
164
|
+
}> &
|
|
165
|
+
Readonly<{
|
|
166
|
+
__opaqueId: ID;
|
|
167
|
+
__tokens: Tokens;
|
|
168
|
+
}> &
|
|
169
|
+
typeof StyleXVarGroupTag;
|
|
170
|
+
|
|
171
|
+
export type TokensFromVarGroup<T extends VarGroup<unknown, unknown>> =
|
|
172
|
+
T['__tokens'];
|
|
173
|
+
|
|
174
|
+
export type IDFromVarGroup<T extends VarGroup<unknown, unknown>> =
|
|
175
|
+
T['__opaqueId'];
|
|
176
|
+
|
|
177
|
+
type TTokens = Readonly<{
|
|
178
|
+
[key: string]: string | { [key: string]: string };
|
|
179
|
+
}>;
|
|
180
|
+
|
|
181
|
+
type UnwrapVars<T> = T extends StyleXVar<infer U> ? U : T;
|
|
182
|
+
export type FlattenTokens<T extends TTokens> = Readonly<{
|
|
183
|
+
[Key in keyof T]: T[Key] extends { [key: string]: infer X }
|
|
184
|
+
? UnwrapVars<X>
|
|
185
|
+
: UnwrapVars<T[Key]>;
|
|
186
|
+
}>;
|
|
187
|
+
|
|
188
|
+
export type StyleX$DefineVars = <
|
|
189
|
+
DefaultTokens extends TTokens,
|
|
190
|
+
ID extends symbol = symbol,
|
|
191
|
+
>(
|
|
192
|
+
tokens: DefaultTokens,
|
|
193
|
+
) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
|
|
194
|
+
|
|
195
|
+
declare class ThemeKey<out VG extends VarGroup> extends String {
|
|
196
|
+
private varGroup: VG;
|
|
197
|
+
}
|
|
198
|
+
export type Theme<
|
|
199
|
+
T extends VarGroup<unknown, symbol>,
|
|
200
|
+
Tag extends symbol = symbol,
|
|
201
|
+
> = Tag &
|
|
202
|
+
Readonly<{
|
|
203
|
+
theme: StyleXClassNameFor<ThemeKey<T>, IDFromVarGroup<T>>;
|
|
204
|
+
}>;
|
|
205
|
+
|
|
206
|
+
type OverridesForTokenType<Config extends { [key: string]: unknown }> = {
|
|
207
|
+
[Key in keyof Config]?:
|
|
208
|
+
| Config[Key]
|
|
209
|
+
| { default: Config[Key]; [atRule: AtRuleStr]: Config[Key] };
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export type StyleX$CreateTheme = <
|
|
213
|
+
TVars extends VarGroup<unknown, unknown>,
|
|
214
|
+
ThemeID extends symbol = symbol,
|
|
215
|
+
>(
|
|
216
|
+
baseTokens: TVars,
|
|
217
|
+
overrides: OverridesForTokenType<TokensFromVarGroup<TVars>>,
|
|
218
|
+
) => Theme<TVars, ThemeID>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';
|
package/lib/es/stylex.js
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
var styleq$1 = {};
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) Nicolas Gallagher
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(styleq$1, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var styleq_2 = styleq$1.styleq = void 0;
|
|
16
|
+
var cache = new WeakMap();
|
|
17
|
+
var compiledKey = '$$css';
|
|
18
|
+
|
|
19
|
+
function createStyleq(options) {
|
|
20
|
+
var disableCache;
|
|
21
|
+
var disableMix;
|
|
22
|
+
var transform;
|
|
23
|
+
|
|
24
|
+
if (options != null) {
|
|
25
|
+
disableCache = options.disableCache === true;
|
|
26
|
+
disableMix = options.disableMix === true;
|
|
27
|
+
transform = options.transform;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return function styleq() {
|
|
31
|
+
// Keep track of property commits to the className
|
|
32
|
+
var definedProperties = []; // The className and inline style to build up
|
|
33
|
+
|
|
34
|
+
var className = '';
|
|
35
|
+
var inlineStyle = null; // The current position in the cache graph
|
|
36
|
+
|
|
37
|
+
var nextCache = disableCache ? null : cache; // This way of creating an array from arguments is fastest
|
|
38
|
+
|
|
39
|
+
var styles = new Array(arguments.length);
|
|
40
|
+
|
|
41
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
42
|
+
styles[i] = arguments[i];
|
|
43
|
+
} // Iterate over styles from last to first
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
while (styles.length > 0) {
|
|
47
|
+
var possibleStyle = styles.pop(); // Skip empty items
|
|
48
|
+
|
|
49
|
+
if (possibleStyle == null || possibleStyle === false) {
|
|
50
|
+
continue;
|
|
51
|
+
} // Push nested styles back onto the stack to be processed
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if (Array.isArray(possibleStyle)) {
|
|
55
|
+
for (var _i = 0; _i < possibleStyle.length; _i++) {
|
|
56
|
+
styles.push(possibleStyle[_i]);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
continue;
|
|
60
|
+
} // Process an individual style object
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
var style = transform != null ? transform(possibleStyle) : possibleStyle;
|
|
64
|
+
|
|
65
|
+
if (style.$$css) {
|
|
66
|
+
// Build up the class names defined by this object
|
|
67
|
+
var classNameChunk = ''; // Check the cache to see if we've already done this work
|
|
68
|
+
|
|
69
|
+
if (nextCache != null && nextCache.has(style)) {
|
|
70
|
+
// Cache: read
|
|
71
|
+
var cacheEntry = nextCache.get(style);
|
|
72
|
+
|
|
73
|
+
if (cacheEntry != null) {
|
|
74
|
+
classNameChunk = cacheEntry[0]; // $FlowIgnore
|
|
75
|
+
|
|
76
|
+
definedProperties.push.apply(definedProperties, cacheEntry[1]);
|
|
77
|
+
nextCache = cacheEntry[2];
|
|
78
|
+
}
|
|
79
|
+
} // Update the chunks with data from this object
|
|
80
|
+
else {
|
|
81
|
+
// The properties defined by this object
|
|
82
|
+
var definedPropertiesChunk = [];
|
|
83
|
+
|
|
84
|
+
for (var prop in style) {
|
|
85
|
+
var value = style[prop];
|
|
86
|
+
if (prop === compiledKey) continue; // Each property value is used as an HTML class name
|
|
87
|
+
// { 'debug.string': 'debug.string', opacity: 's-jskmnoqp' }
|
|
88
|
+
|
|
89
|
+
if (typeof value === 'string' || value === null) {
|
|
90
|
+
// Only add to chunks if this property hasn't already been seen
|
|
91
|
+
if (!definedProperties.includes(prop)) {
|
|
92
|
+
definedProperties.push(prop);
|
|
93
|
+
|
|
94
|
+
if (nextCache != null) {
|
|
95
|
+
definedPropertiesChunk.push(prop);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (typeof value === 'string') {
|
|
99
|
+
classNameChunk += classNameChunk ? ' ' + value : value;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} // If we encounter a value that isn't a string or `null`
|
|
103
|
+
else {
|
|
104
|
+
console.error("styleq: ".concat(prop, " typeof ").concat(String(value), " is not \"string\" or \"null\"."));
|
|
105
|
+
}
|
|
106
|
+
} // Cache: write
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if (nextCache != null) {
|
|
110
|
+
// Create the next WeakMap for this sequence of styles
|
|
111
|
+
var weakMap = new WeakMap();
|
|
112
|
+
nextCache.set(style, [classNameChunk, definedPropertiesChunk, weakMap]);
|
|
113
|
+
nextCache = weakMap;
|
|
114
|
+
}
|
|
115
|
+
} // Order of classes in chunks matches property-iteration order of style
|
|
116
|
+
// object. Order of chunks matches passed order of styles from first to
|
|
117
|
+
// last (which we iterate over in reverse).
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
if (classNameChunk) {
|
|
121
|
+
className = className ? classNameChunk + ' ' + className : classNameChunk;
|
|
122
|
+
}
|
|
123
|
+
} // ----- DYNAMIC: Process inline style object -----
|
|
124
|
+
else {
|
|
125
|
+
if (disableMix) {
|
|
126
|
+
if (inlineStyle == null) {
|
|
127
|
+
inlineStyle = {};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
inlineStyle = Object.assign({}, style, inlineStyle);
|
|
131
|
+
} else {
|
|
132
|
+
var subStyle = null;
|
|
133
|
+
|
|
134
|
+
for (var _prop in style) {
|
|
135
|
+
var _value = style[_prop];
|
|
136
|
+
|
|
137
|
+
if (_value !== undefined) {
|
|
138
|
+
if (!definedProperties.includes(_prop)) {
|
|
139
|
+
if (_value != null) {
|
|
140
|
+
if (inlineStyle == null) {
|
|
141
|
+
inlineStyle = {};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (subStyle == null) {
|
|
145
|
+
subStyle = {};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
subStyle[_prop] = _value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
definedProperties.push(_prop); // Cache is unnecessary overhead if results can't be reused.
|
|
152
|
+
|
|
153
|
+
nextCache = null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (subStyle != null) {
|
|
159
|
+
inlineStyle = Object.assign(subStyle, inlineStyle);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
var styleProps = [className, inlineStyle];
|
|
166
|
+
return styleProps;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
var styleq = createStyleq();
|
|
171
|
+
styleq_2 = styleq$1.styleq = styleq;
|
|
172
|
+
styleq.factory = createStyleq;
|
|
173
|
+
|
|
174
|
+
const errorForFn = name => new Error(`'stylex.${name}' should never be called at runtime. It should be compiled away by '@stylexjs/babel-plugin'`);
|
|
175
|
+
const errorForType = key => errorForFn(`types.${key}`);
|
|
176
|
+
function props() {
|
|
177
|
+
const options = this;
|
|
178
|
+
for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
179
|
+
styles[_key] = arguments[_key];
|
|
180
|
+
}
|
|
181
|
+
if (__implementations.props) {
|
|
182
|
+
return __implementations.props.call(options, styles);
|
|
183
|
+
}
|
|
184
|
+
const [className, style] = styleq_2(styles);
|
|
185
|
+
const result = {};
|
|
186
|
+
if (className != null && className !== '') {
|
|
187
|
+
result.className = className;
|
|
188
|
+
}
|
|
189
|
+
if (style != null && Object.keys(style).length > 0) {
|
|
190
|
+
result.style = style;
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
function attrs() {
|
|
195
|
+
const {
|
|
196
|
+
className,
|
|
197
|
+
style
|
|
198
|
+
} = props(...arguments);
|
|
199
|
+
const result = {};
|
|
200
|
+
if (className != null && className !== '') {
|
|
201
|
+
result.class = className;
|
|
202
|
+
}
|
|
203
|
+
if (style != null && Object.keys(style).length > 0) {
|
|
204
|
+
result.style = Object.keys(style).map(key => `${key}:${style[key]};`).join('');
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
function stylexCreate(styles) {
|
|
209
|
+
if (__implementations.create != null) {
|
|
210
|
+
const create = __implementations.create;
|
|
211
|
+
return create(styles);
|
|
212
|
+
}
|
|
213
|
+
throw errorForFn('create');
|
|
214
|
+
}
|
|
215
|
+
function stylexDefineVars(styles) {
|
|
216
|
+
if (__implementations.defineVars) {
|
|
217
|
+
return __implementations.defineVars(styles);
|
|
218
|
+
}
|
|
219
|
+
throw errorForFn('defineVars');
|
|
220
|
+
}
|
|
221
|
+
const stylexCreateTheme = (baseTokens, overrides) => {
|
|
222
|
+
if (__implementations.createTheme) {
|
|
223
|
+
return __implementations.createTheme(baseTokens, overrides);
|
|
224
|
+
}
|
|
225
|
+
throw errorForFn('createTheme');
|
|
226
|
+
};
|
|
227
|
+
const stylexInclude = styles => {
|
|
228
|
+
if (__implementations.include) {
|
|
229
|
+
return __implementations.include(styles);
|
|
230
|
+
}
|
|
231
|
+
throw errorForFn('include');
|
|
232
|
+
};
|
|
233
|
+
const create = stylexCreate;
|
|
234
|
+
const defineVars = stylexDefineVars;
|
|
235
|
+
const createTheme = stylexCreateTheme;
|
|
236
|
+
const include = stylexInclude;
|
|
237
|
+
const types = {
|
|
238
|
+
angle: _v => {
|
|
239
|
+
throw errorForType('angle');
|
|
240
|
+
},
|
|
241
|
+
color: _v => {
|
|
242
|
+
throw errorForType('color');
|
|
243
|
+
},
|
|
244
|
+
url: _v => {
|
|
245
|
+
throw errorForType('url');
|
|
246
|
+
},
|
|
247
|
+
image: _v => {
|
|
248
|
+
throw errorForType('image');
|
|
249
|
+
},
|
|
250
|
+
integer: _v => {
|
|
251
|
+
throw errorForType('integer');
|
|
252
|
+
},
|
|
253
|
+
lengthPercentage: _v => {
|
|
254
|
+
throw errorForType('lengthPercentage');
|
|
255
|
+
},
|
|
256
|
+
length: _v => {
|
|
257
|
+
throw errorForType('length');
|
|
258
|
+
},
|
|
259
|
+
percentage: _v => {
|
|
260
|
+
throw errorForType('percentage');
|
|
261
|
+
},
|
|
262
|
+
number: _v => {
|
|
263
|
+
throw errorForType('number');
|
|
264
|
+
},
|
|
265
|
+
resolution: _v => {
|
|
266
|
+
throw errorForType('resolution');
|
|
267
|
+
},
|
|
268
|
+
time: _v => {
|
|
269
|
+
throw errorForType('time');
|
|
270
|
+
},
|
|
271
|
+
transformFunction: _v => {
|
|
272
|
+
throw errorForType('transformFunction');
|
|
273
|
+
},
|
|
274
|
+
transformList: _v => {
|
|
275
|
+
throw errorForType('transformList');
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
const keyframes = keyframes => {
|
|
279
|
+
if (__implementations.keyframes) {
|
|
280
|
+
return __implementations.keyframes(keyframes);
|
|
281
|
+
}
|
|
282
|
+
throw errorForFn('keyframes');
|
|
283
|
+
};
|
|
284
|
+
const firstThatWorks = function () {
|
|
285
|
+
if (__implementations.firstThatWorks) {
|
|
286
|
+
return __implementations.firstThatWorks(...arguments);
|
|
287
|
+
}
|
|
288
|
+
throw errorForFn('firstThatWorks');
|
|
289
|
+
};
|
|
290
|
+
function _stylex() {
|
|
291
|
+
for (var _len2 = arguments.length, styles = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
292
|
+
styles[_key2] = arguments[_key2];
|
|
293
|
+
}
|
|
294
|
+
const [className] = styleq_2(styles);
|
|
295
|
+
return className;
|
|
296
|
+
}
|
|
297
|
+
_stylex.props = props;
|
|
298
|
+
_stylex.attrs = attrs;
|
|
299
|
+
_stylex.create = create;
|
|
300
|
+
_stylex.defineVars = defineVars;
|
|
301
|
+
_stylex.createTheme = createTheme;
|
|
302
|
+
_stylex.include = include;
|
|
303
|
+
_stylex.keyframes = keyframes;
|
|
304
|
+
_stylex.firstThatWorks = firstThatWorks;
|
|
305
|
+
_stylex.types = types;
|
|
306
|
+
const __implementations = {};
|
|
307
|
+
function __monkey_patch__(key, implementation) {
|
|
308
|
+
if (key === 'types') {
|
|
309
|
+
Object.assign(types, implementation);
|
|
310
|
+
} else {
|
|
311
|
+
__implementations[key] = implementation;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const legacyMerge = _stylex;
|
|
315
|
+
|
|
316
|
+
export { __monkey_patch__, attrs, create, createTheme, _stylex as default, defineVars, firstThatWorks, include, keyframes, legacyMerge, props, types };
|
package/lib/stylex.d.ts
CHANGED
|
@@ -38,6 +38,15 @@ export declare function props(
|
|
|
38
38
|
className?: string;
|
|
39
39
|
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
40
40
|
}>;
|
|
41
|
+
export declare function attrs(
|
|
42
|
+
...styles: ReadonlyArray<
|
|
43
|
+
StyleXArray<
|
|
44
|
+
| (null | undefined | CompiledStyles)
|
|
45
|
+
| boolean
|
|
46
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
47
|
+
>
|
|
48
|
+
>
|
|
49
|
+
): Readonly<{ class?: string; style?: string }>;
|
|
41
50
|
type Stylex$Include = <
|
|
42
51
|
TStyles extends {
|
|
43
52
|
readonly [$$Key$$: string]: StyleXClassNameFor<string, unknown>;
|
|
@@ -131,6 +140,15 @@ type IStyleX = {
|
|
|
131
140
|
className?: string;
|
|
132
141
|
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
133
142
|
}>;
|
|
143
|
+
attrs: (
|
|
144
|
+
...styles: ReadonlyArray<
|
|
145
|
+
StyleXArray<
|
|
146
|
+
| (null | undefined | CompiledStyles)
|
|
147
|
+
| boolean
|
|
148
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
149
|
+
>
|
|
150
|
+
>
|
|
151
|
+
) => Readonly<{ class?: string; style?: string }>;
|
|
134
152
|
create: Stylex$Create;
|
|
135
153
|
defineVars: StyleX$DefineVars;
|
|
136
154
|
createTheme: StyleX$CreateTheme;
|
|
@@ -142,6 +160,6 @@ type IStyleX = {
|
|
|
142
160
|
keyframes: (keyframes: Keyframes) => string;
|
|
143
161
|
__customProperties?: { [$$Key$$: string]: unknown };
|
|
144
162
|
};
|
|
145
|
-
export declare const
|
|
163
|
+
export declare const legacyMerge: IStyleX;
|
|
146
164
|
declare const $$EXPORT_DEFAULT_DECLARATION$$: IStyleX;
|
|
147
165
|
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
package/lib/stylex.js
CHANGED
|
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.__monkey_patch__ = __monkey_patch__;
|
|
7
|
-
exports.
|
|
7
|
+
exports.attrs = attrs;
|
|
8
|
+
exports.legacyMerge = exports.keyframes = exports.include = exports.firstThatWorks = exports.defineVars = exports.default = exports.createTheme = exports.create = void 0;
|
|
8
9
|
exports.props = props;
|
|
9
|
-
exports.types =
|
|
10
|
+
exports.types = void 0;
|
|
10
11
|
var _styleq = require("styleq");
|
|
12
|
+
const errorForFn = name => new Error(`'stylex.${name}' should never be called at runtime. It should be compiled away by '@stylexjs/babel-plugin'`);
|
|
13
|
+
const errorForType = key => errorForFn(`types.${key}`);
|
|
11
14
|
function props() {
|
|
12
15
|
const options = this;
|
|
13
16
|
for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -26,30 +29,44 @@ function props() {
|
|
|
26
29
|
}
|
|
27
30
|
return result;
|
|
28
31
|
}
|
|
32
|
+
function attrs() {
|
|
33
|
+
const {
|
|
34
|
+
className,
|
|
35
|
+
style
|
|
36
|
+
} = props(...arguments);
|
|
37
|
+
const result = {};
|
|
38
|
+
if (className != null && className !== '') {
|
|
39
|
+
result.class = className;
|
|
40
|
+
}
|
|
41
|
+
if (style != null && Object.keys(style).length > 0) {
|
|
42
|
+
result.style = Object.keys(style).map(key => `${key}:${style[key]};`).join('');
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
29
46
|
function stylexCreate(styles) {
|
|
30
47
|
if (__implementations.create != null) {
|
|
31
48
|
const create = __implementations.create;
|
|
32
49
|
return create(styles);
|
|
33
50
|
}
|
|
34
|
-
throw
|
|
51
|
+
throw errorForFn('create');
|
|
35
52
|
}
|
|
36
53
|
function stylexDefineVars(styles) {
|
|
37
54
|
if (__implementations.defineVars) {
|
|
38
55
|
return __implementations.defineVars(styles);
|
|
39
56
|
}
|
|
40
|
-
throw
|
|
57
|
+
throw errorForFn('defineVars');
|
|
41
58
|
}
|
|
42
59
|
const stylexCreateTheme = (baseTokens, overrides) => {
|
|
43
60
|
if (__implementations.createTheme) {
|
|
44
61
|
return __implementations.createTheme(baseTokens, overrides);
|
|
45
62
|
}
|
|
46
|
-
throw
|
|
63
|
+
throw errorForFn('createTheme');
|
|
47
64
|
};
|
|
48
65
|
const stylexInclude = styles => {
|
|
49
66
|
if (__implementations.include) {
|
|
50
67
|
return __implementations.include(styles);
|
|
51
68
|
}
|
|
52
|
-
throw
|
|
69
|
+
throw errorForFn('include');
|
|
53
70
|
};
|
|
54
71
|
const create = exports.create = stylexCreate;
|
|
55
72
|
const defineVars = exports.defineVars = stylexDefineVars;
|
|
@@ -57,58 +74,57 @@ const createTheme = exports.createTheme = stylexCreateTheme;
|
|
|
57
74
|
const include = exports.include = stylexInclude;
|
|
58
75
|
const types = exports.types = {
|
|
59
76
|
angle: _v => {
|
|
60
|
-
throw
|
|
77
|
+
throw errorForType('angle');
|
|
61
78
|
},
|
|
62
79
|
color: _v => {
|
|
63
|
-
throw
|
|
80
|
+
throw errorForType('color');
|
|
64
81
|
},
|
|
65
82
|
url: _v => {
|
|
66
|
-
throw
|
|
83
|
+
throw errorForType('url');
|
|
67
84
|
},
|
|
68
85
|
image: _v => {
|
|
69
|
-
throw
|
|
86
|
+
throw errorForType('image');
|
|
70
87
|
},
|
|
71
88
|
integer: _v => {
|
|
72
|
-
throw
|
|
89
|
+
throw errorForType('integer');
|
|
73
90
|
},
|
|
74
91
|
lengthPercentage: _v => {
|
|
75
|
-
throw
|
|
92
|
+
throw errorForType('lengthPercentage');
|
|
76
93
|
},
|
|
77
94
|
length: _v => {
|
|
78
|
-
throw
|
|
95
|
+
throw errorForType('length');
|
|
79
96
|
},
|
|
80
97
|
percentage: _v => {
|
|
81
|
-
throw
|
|
98
|
+
throw errorForType('percentage');
|
|
82
99
|
},
|
|
83
100
|
number: _v => {
|
|
84
|
-
throw
|
|
101
|
+
throw errorForType('number');
|
|
85
102
|
},
|
|
86
103
|
resolution: _v => {
|
|
87
|
-
throw
|
|
104
|
+
throw errorForType('resolution');
|
|
88
105
|
},
|
|
89
106
|
time: _v => {
|
|
90
|
-
throw
|
|
107
|
+
throw errorForType('time');
|
|
91
108
|
},
|
|
92
109
|
transformFunction: _v => {
|
|
93
|
-
throw
|
|
110
|
+
throw errorForType('transformFunction');
|
|
94
111
|
},
|
|
95
112
|
transformList: _v => {
|
|
96
|
-
throw
|
|
113
|
+
throw errorForType('transformList');
|
|
97
114
|
}
|
|
98
115
|
};
|
|
99
|
-
const errorForType = type => `stylex.types.${type} should be compiled away by @stylexjs/babel-plugin`;
|
|
100
116
|
const keyframes = keyframes => {
|
|
101
117
|
if (__implementations.keyframes) {
|
|
102
118
|
return __implementations.keyframes(keyframes);
|
|
103
119
|
}
|
|
104
|
-
throw
|
|
120
|
+
throw errorForFn('keyframes');
|
|
105
121
|
};
|
|
106
122
|
exports.keyframes = keyframes;
|
|
107
123
|
const firstThatWorks = function () {
|
|
108
124
|
if (__implementations.firstThatWorks) {
|
|
109
125
|
return __implementations.firstThatWorks(...arguments);
|
|
110
126
|
}
|
|
111
|
-
throw
|
|
127
|
+
throw errorForFn('firstThatWorks');
|
|
112
128
|
};
|
|
113
129
|
exports.firstThatWorks = firstThatWorks;
|
|
114
130
|
function _stylex() {
|
|
@@ -119,6 +135,7 @@ function _stylex() {
|
|
|
119
135
|
return className;
|
|
120
136
|
}
|
|
121
137
|
_stylex.props = props;
|
|
138
|
+
_stylex.attrs = attrs;
|
|
122
139
|
_stylex.create = create;
|
|
123
140
|
_stylex.defineVars = defineVars;
|
|
124
141
|
_stylex.createTheme = createTheme;
|
|
@@ -134,5 +151,5 @@ function __monkey_patch__(key, implementation) {
|
|
|
134
151
|
__implementations[key] = implementation;
|
|
135
152
|
}
|
|
136
153
|
}
|
|
137
|
-
const
|
|
154
|
+
const legacyMerge = exports.legacyMerge = _stylex;
|
|
138
155
|
var _default = exports.default = _stylex;
|
package/lib/stylex.js.flow
CHANGED
|
@@ -38,6 +38,16 @@ declare export function props(
|
|
|
38
38
|
className?: string,
|
|
39
39
|
style?: $ReadOnly<{ [string]: string | number }>,
|
|
40
40
|
}>;
|
|
41
|
+
declare export function attrs(
|
|
42
|
+
...styles: $ReadOnlyArray<
|
|
43
|
+
StyleXArray<
|
|
44
|
+
?CompiledStyles | boolean | $ReadOnly<[CompiledStyles, InlineStyles]>,
|
|
45
|
+
>,
|
|
46
|
+
>
|
|
47
|
+
): $ReadOnly<{
|
|
48
|
+
class?: string,
|
|
49
|
+
style?: string,
|
|
50
|
+
}>;
|
|
41
51
|
|
|
42
52
|
type Stylex$Include = <
|
|
43
53
|
TStyles: { +[string]: StyleXClassNameFor<string, mixed> },
|
|
@@ -110,6 +120,7 @@ declare export const types: {
|
|
|
110
120
|
) => ICSSType<T>,
|
|
111
121
|
transformList: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
|
|
112
122
|
};
|
|
123
|
+
|
|
113
124
|
declare export const keyframes: (keyframes: Keyframes) => string;
|
|
114
125
|
|
|
115
126
|
declare export const firstThatWorks: <T: string | number>(
|
|
@@ -129,6 +140,16 @@ type IStyleX = {
|
|
|
129
140
|
className?: string,
|
|
130
141
|
style?: $ReadOnly<{ [string]: string | number }>,
|
|
131
142
|
}>,
|
|
143
|
+
attrs: (
|
|
144
|
+
...styles: $ReadOnlyArray<
|
|
145
|
+
StyleXArray<
|
|
146
|
+
?CompiledStyles | boolean | $ReadOnly<[CompiledStyles, InlineStyles]>,
|
|
147
|
+
>,
|
|
148
|
+
>
|
|
149
|
+
) => $ReadOnly<{
|
|
150
|
+
class?: string,
|
|
151
|
+
style?: string,
|
|
152
|
+
}>,
|
|
132
153
|
create: Stylex$Create,
|
|
133
154
|
defineVars: StyleX$DefineVars,
|
|
134
155
|
createTheme: StyleX$CreateTheme,
|
|
@@ -143,5 +164,5 @@ type IStyleX = {
|
|
|
143
164
|
};
|
|
144
165
|
|
|
145
166
|
|
|
146
|
-
declare export const
|
|
167
|
+
declare export const legacyMerge: IStyleX;
|
|
147
168
|
declare export default IStyleX;
|
package/package.json
CHANGED
|
@@ -1,14 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/stylex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-alpha.1",
|
|
4
4
|
"description": "A library for defining styles for optimized user interfaces.",
|
|
5
|
-
"main": "lib/stylex.js",
|
|
6
|
-
"
|
|
5
|
+
"main": "./lib/stylex.js",
|
|
6
|
+
"module": "./lib/es/stylex.js",
|
|
7
|
+
"types": "./lib/stylex.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./lib/es/stylex.js",
|
|
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.js",
|
|
21
|
+
"require": "./lib/StyleXSheet.js",
|
|
22
|
+
"types": "./lib/StyleXSheet.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./lib/stylex-inject": {
|
|
25
|
+
"import": "./lib/es/stylex-inject.js",
|
|
26
|
+
"require": "./lib/stylex-inject.js",
|
|
27
|
+
"types": "./lib/stylex-inject.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
7
31
|
"repository": "https://www.github.com/facebook/stylex",
|
|
8
32
|
"license": "MIT",
|
|
9
33
|
"scripts": {
|
|
10
34
|
"prebuild": "gen-types -i src/ -o lib/",
|
|
11
|
-
"build": "babel src/ --out-dir lib/ --copy-files",
|
|
35
|
+
"build:cjs": "BABEL_ENV=cjs babel src/ --out-dir lib/ --copy-files",
|
|
36
|
+
"build:esm": "BABEL_ENV=esm babel src/ --out-dir lib/es --copy-files",
|
|
37
|
+
"postbuild:esm": "rollup -c ./rollup.config.mjs",
|
|
38
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
12
39
|
"build-haste": "rewrite-imports -i src/ -o lib/",
|
|
13
40
|
"test": "jest"
|
|
14
41
|
},
|
|
@@ -19,7 +46,7 @@
|
|
|
19
46
|
"utility-types": "^3.10.0"
|
|
20
47
|
},
|
|
21
48
|
"devDependencies": {
|
|
22
|
-
"@stylexjs/scripts": "0.
|
|
49
|
+
"@stylexjs/scripts": "0.5.0-alpha.1"
|
|
23
50
|
},
|
|
24
51
|
"jest": {},
|
|
25
52
|
"files": [
|