@stylexjs/shared 0.1.0-beta.6 → 0.2.0-beta.8
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/expand-shorthands.d.ts +5 -0
- package/lib/expand-shorthands.js +251 -54
- package/lib/index.d.ts +5 -2
- package/lib/messages.js +6 -2
- package/lib/stylex-create.js +48 -14
- package/lib/stylex-defaultValue.js +397 -0
- package/lib/utils/object-utils.js +1 -1
- package/package.json +1 -1
package/lib/expand-shorthands.js
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.BANNED_PROPERTIES = void 0;
|
6
7
|
exports.default = flatMapExpandedShorthands;
|
8
|
+
exports.expandedKeys = void 0;
|
7
9
|
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
8
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
11
|
/**
|
@@ -65,70 +67,236 @@ function splitValue(str) {
|
|
65
67
|
|
66
68
|
/**
|
67
69
|
* Shorthand properties:
|
68
|
-
* - [
|
69
|
-
* - [
|
70
|
-
* - [
|
71
|
-
* - [
|
72
|
-
*
|
73
|
-
* - [
|
74
|
-
* - [
|
75
|
-
* - [
|
76
|
-
* - [
|
77
|
-
* - [
|
78
|
-
* - [
|
79
|
-
* - [
|
70
|
+
* - [!] all - BANNED
|
71
|
+
* - [!] animation - BANNED
|
72
|
+
* - [!] background - BANNED
|
73
|
+
* - [x] border - Expanded to border-{direction}. Not to border-*-(width|style|color).
|
74
|
+
* This is to limit the number of atoms to 4 instead of 12.
|
75
|
+
* - [o] border-top - Only the shorthand is allowed.
|
76
|
+
* - [o] border-end - Only the shorthand is allowed.
|
77
|
+
* - [o] border-bottom - Only the shorthand is allowed.
|
78
|
+
* - [o] border-start - Only the shorthand is allowed.
|
79
|
+
* - [!] border-left - BANNED
|
80
|
+
* - [!] border-right
|
81
|
+
* - [!] border-*-width - BANNED
|
82
|
+
* - [!] border-*-style - BANNED
|
83
|
+
* - [!] border-*-color - BANNED
|
84
|
+
* - [ ] border-block-end
|
85
|
+
* - [ ] border-block-start
|
86
|
+
* - [ ] border-inline-start
|
87
|
+
* - [ ] border-inline-end
|
88
|
+
* - [!] border-image - BANNED
|
80
89
|
* - [x] border-radius
|
81
|
-
* - [
|
82
|
-
* - [
|
83
|
-
* - [
|
84
|
-
* - [
|
85
|
-
* - [
|
86
|
-
* - [
|
87
|
-
* - [
|
88
|
-
* - [
|
89
|
-
* - [
|
90
|
-
* - [
|
91
|
-
* - [
|
92
|
-
* - [
|
93
|
-
*
|
94
|
-
* - [
|
95
|
-
* - [ ] grid-template
|
96
|
-
* - [ ] list-style
|
90
|
+
* - [o] column-rule - Only the shorthand is allowed.
|
91
|
+
* - [!] columns - BANNED
|
92
|
+
* - [!] flex - BANNED
|
93
|
+
* - [!] flex-flow - BANNED
|
94
|
+
* - [!] font - BANNED
|
95
|
+
* - [x] gap
|
96
|
+
* - [!] grid - BANNED
|
97
|
+
* - [!] grid-area - BANNED
|
98
|
+
* - [!] grid-column - BANNED
|
99
|
+
* - [!] grid-row - BANNED
|
100
|
+
* - [!] grid-template - BANNED
|
101
|
+
* - [!] grid-template-areas - BANNED
|
102
|
+
*
|
103
|
+
* - [o] list-style - Only the shorthand is allowed.
|
97
104
|
* - [x] margin
|
98
|
-
* - [
|
99
|
-
* - [
|
100
|
-
* - [
|
105
|
+
* - [o] mask - Only the shorthand is allowed.
|
106
|
+
* - [o] offset - Only the shorthand is allowed.
|
107
|
+
* - [o] outline - Only the shorthand is allowed.
|
101
108
|
* - [x] overflow
|
102
109
|
* - [x] padding
|
103
|
-
* - [
|
104
|
-
* - [
|
105
|
-
* - [
|
106
|
-
* - [
|
107
|
-
* - [
|
108
|
-
* - [
|
109
|
-
* - [
|
110
|
-
* - [
|
110
|
+
* - [x] place-content
|
111
|
+
* - [x] place-items
|
112
|
+
* - [x] place-self
|
113
|
+
* - [X] scroll-margin
|
114
|
+
* - [x] scroll-padding
|
115
|
+
* - [o] text-decoration - Only the shorthand is allowed.
|
116
|
+
* - [o] text-emphasis - Only the shorthand is allowed.
|
117
|
+
* - [!] transition - BANNED
|
111
118
|
*/
|
112
119
|
|
120
|
+
const BANNED_PROPERTIES = {
|
121
|
+
all: '`all` is not supported. Use individual properties instead.',
|
122
|
+
animation: '`animation` is not supported. Use individual properties like `animationName`, `animationDuration`, etc. instead.',
|
123
|
+
background: '`background` is not supported. Use individual properties like `backgroundImage`, `backgroundPosition`, etc. instead.',
|
124
|
+
borderColor: '`borderColor` is not supported. Use `border`, `borderTop`, `borderEnd`, `borderBottom` or `borderStart` instead.',
|
125
|
+
borderStyle: '`borderStyle` is not supported. Use `border`, `borderTop`, `borderEnd`, `borderBottom` or `borderStart` instead.',
|
126
|
+
borderWidth: '`borderWidth` is not supported. Use `border`, `borderTop`, `borderEnd`, `borderBottom` or `borderStart` instead.',
|
127
|
+
borderTopColor: '`borderTopColor` is not supported. Use `borderTop` instead.',
|
128
|
+
borderTopStyle: '`borderTopStyle` is not supported. Use `borderTop` instead.',
|
129
|
+
borderTopWidth: '`borderTopWidth` is not supported. Use `borderTop` instead.',
|
130
|
+
borderEndColor: '`borderEndColor` is not supported. Use `borderEnd` instead.',
|
131
|
+
borderEndStyle: '`borderEndStyle` is not supported. Use `borderEnd` instead.',
|
132
|
+
borderEndWidth: '`borderEndWidth` is not supported. Use `borderEnd` instead.',
|
133
|
+
borderBottomColor: '`borderBottomColor` is not supported. Use `borderBottom` instead.',
|
134
|
+
borderBottomStyle: '`borderBottomStyle` is not supported. Use `borderBottom` instead.',
|
135
|
+
borderBottomWidth: '`borderBottomWidth` is not supported. Use `borderBottom` instead.',
|
136
|
+
borderStartColor: '`borderStartColor` is not supported. Use `borderStart` instead.',
|
137
|
+
borderStartStyle: '`borderStartStyle` is not supported. Use `borderStart` instead.',
|
138
|
+
borderStartWidth: '`borderStartWidth` is not supported. Use `borderStart` instead.',
|
139
|
+
borderBlockStartColor: '`borderBlockStartColor` is not supported. Use `borderTop` instead.',
|
140
|
+
borderBlockStartStyle: '`borderBlockStartStyle` is not supported. Use `borderTop` instead.',
|
141
|
+
borderBlockStartWidth: '`borderBlockStartWidth` is not supported. Use `borderTop` instead.',
|
142
|
+
borderBlockEndColor: '`borderBlockEndColor` is not supported. Use `borderBottom` instead.',
|
143
|
+
borderBlockEndStyle: '`borderBlockEndStyle` is not supported. Use `borderBottom` instead.',
|
144
|
+
borderBlockEndWidth: '`borderBlockEndWidth` is not supported. Use `borderBottom` instead.',
|
145
|
+
borderInlineStartColor: '`borderInlineStartColor` is not supported. Use `borderStart` instead.',
|
146
|
+
borderInlineStartStyle: '`borderInlineStartStyle` is not supported. Use `borderStart` instead.',
|
147
|
+
borderInlineStartWidth: '`borderInlineStartWidth` is not supported. Use `borderStart` instead.',
|
148
|
+
borderInlineEndColor: '`borderInlineEndColor` is not supported. Use `borderEnd` instead.',
|
149
|
+
borderInlineEndStyle: '`borderInlineEndStyle` is not supported. Use `borderEnd` instead.',
|
150
|
+
borderInlineEndWidth: '`borderInlineEndWidth` is not supported. Use `borderEnd` instead.',
|
151
|
+
borderLeft: '`borderLeft` is not supported. Use `borderStart` instead.',
|
152
|
+
borderLeftColor: '`borderLeftColor` is not supported. Use `borderStart` instead.',
|
153
|
+
borderLeftStyle: '`borderLeftStyle` is not supported. Use `borderStart` instead.',
|
154
|
+
borderLeftWidth: '`borderLeftWidth` is not supported. Use `borderStart` instead.',
|
155
|
+
borderRight: '`borderRight` is not supported. Use `borderEnd` instead.',
|
156
|
+
borderRightColor: '`borderRightColor` is not supported. Use `borderEnd` instead.',
|
157
|
+
borderRightStyle: '`borderRightStyle` is not supported. Use `borderEnd` instead.',
|
158
|
+
borderRightWidth: '`borderRightWidth` is not supported. Use `borderEnd` instead.',
|
159
|
+
borderTopLeftRadius: '`borderTopLeftRadius` is not supported. Use `borderTopStartRadius` instead.',
|
160
|
+
borderTopRightRadius: '`borderTopRightRadius` is not supported. Use `borderTopEndRadius` instead.',
|
161
|
+
borderBottomLeftRadius: '`borderBottomLeftRadius` is not supported. Use `borderBottomStartRadius` instead.',
|
162
|
+
borderBottomRightRadius: '`borderBottomRightRadius` is not supported. Use `borderBottomEndRadius` instead.',
|
163
|
+
borderImageSource: '`borderImageSource` is not supported. Use `borderImage` instead.',
|
164
|
+
borderImageSlice: '`borderImageSlice` is not supported. Use `borderImage` instead.',
|
165
|
+
borderImageWidth: '`borderImageWidth` is not supported. Use `borderImage` instead.',
|
166
|
+
borderImageOutset: '`borderImageOutset` is not supported. Use `borderImage` instead.',
|
167
|
+
borderImageRepeat: '`borderImageRepeat` is not supported. Use `borderImage` instead.',
|
168
|
+
marginLeft: '`marginLeft` is not supported. Use `marginStart` instead.',
|
169
|
+
marginRight: '`marginRight` is not supported. Use `marginEnd` instead.',
|
170
|
+
paddingLeft: '`paddingLeft` is not supported. Use `paddingStart` instead.',
|
171
|
+
paddingRight: '`paddingRight` is not supported. Use `paddingEnd` instead.',
|
172
|
+
columnRuleWidth: '`columnRuleWidth` is not supported. Use `columnRule` instead.',
|
173
|
+
columnRuleStyle: '`columnRuleStyle` is not supported. Use `columnRule` instead.',
|
174
|
+
columnRuleColor: '`columnRuleColor` is not supported. Use `columnRule` instead.',
|
175
|
+
columns: '`columns` is not supported. Use `columnCount` and `columnWidth` instead.',
|
176
|
+
flex: '`flex` is not supported. Use `flexGrow`, `flexShrink`, and `flexBasis` instead.',
|
177
|
+
flexFlow: '`flexFlow` is not supported. Use `flexDirection` and `flexWrap` instead.',
|
178
|
+
font: '`font` is not supported. Use individual properties like `fontFamily`, `fontSize`, etc. instead.',
|
179
|
+
grid: '`grid` is not supported. Use individual properties like `gridTemplateColumns`, `gridTemplateRows`, etc. instead.',
|
180
|
+
gridColumn: '`gridColumn` is not supported. Use `gridColumnStart` and `gridColumnEnd` instead.',
|
181
|
+
gridRow: '`gridRow` is not supported. Use `gridRowStart` and `gridRowEnd` instead.',
|
182
|
+
gridArea: '`gridArea` is not supported. Use `gridRowStart`, `gridColumnStart`, `gridRowEnd`, and `gridColumnEnd` instead.',
|
183
|
+
gridTemplate: '`gridTemplate` is not supported. Use individual properties like `gridTemplateColumns`, `gridTemplateRows`, etc. instead.',
|
184
|
+
gridTemplateAreas: '`gridTemplateAreas` is not supported. Use `gridTemplateRows` and `gridTemplateColumns` instead.',
|
185
|
+
listStyleImage: '`listStyleImage` is not supported. Use `listStyle` instead.',
|
186
|
+
listStylePosition: '`listStylePosition` is not supported. Use `listStyle` instead.',
|
187
|
+
listStyleType: '`listStyleType` is not supported. Use `listStyle` instead.',
|
188
|
+
maskClip: '`maskClip` is not supported. Use `mask` instead.',
|
189
|
+
maskComposite: '`maskComposite` is not supported. Use `mask` instead.',
|
190
|
+
maskImage: '`maskImage` is not supported. Use `mask` instead.',
|
191
|
+
maskMode: '`maskMode` is not supported. Use `mask` instead.',
|
192
|
+
maskOrigin: '`maskOrigin` is not supported. Use `mask` instead.',
|
193
|
+
maskPosition: '`maskPosition` is not supported. Use `mask` instead.',
|
194
|
+
maskRepeat: '`maskRepeat` is not supported. Use `mask` instead.',
|
195
|
+
maskSize: '`maskSize` is not supported. Use `mask` instead.',
|
196
|
+
offsetAnchor: '`offsetAnchor` is not supported. Use `offset` instead.',
|
197
|
+
offsetDistance: '`offsetDistance` is not supported. Use `offset` instead.',
|
198
|
+
offsetPath: '`offsetPath` is not supported. Use `offset` instead.',
|
199
|
+
offsetPosition: '`offsetPosition` is not supported. Use `offset` instead.',
|
200
|
+
offsetRotate: '`offsetRotate` is not supported. Use `offset` instead.',
|
201
|
+
outlineColor: '`outlineColor` is not supported. Use `outline` instead.',
|
202
|
+
outlineStyle: '`outlineStyle` is not supported. Use `outline` instead.',
|
203
|
+
outlineWidth: '`outlineWidth` is not supported. Use `outline` instead.',
|
204
|
+
textDecorationColor: '`textDecorationColor` is not supported. Use `textDecoration` instead.',
|
205
|
+
textDecorationLine: '`textDecorationLine` is not supported. Use `textDecoration` instead.',
|
206
|
+
textDecorationStyle: '`textDecorationStyle` is not supported. Use `textDecoration` instead.',
|
207
|
+
textDecorationThickness: '`textDecorationThickness` is not supported. Use `textDecoration` instead.',
|
208
|
+
textEmphasisColor: '`textEmphasisColor` is not supported. Use `textEmphasis` instead.',
|
209
|
+
textEmphasisStyle: '`textEmphasisStyle` is not supported. Use `textEmphasis` instead.',
|
210
|
+
transition: '`transition` is not supported. Use individual properties like `transitionProperty`, `transitionDuration`, etc. instead.'
|
211
|
+
};
|
212
|
+
exports.BANNED_PROPERTIES = BANNED_PROPERTIES;
|
113
213
|
const expansions = {
|
114
|
-
// ...aliases,
|
115
214
|
border: rawValue => {
|
116
215
|
return [['borderTop', rawValue], ['borderEnd', rawValue], ['borderBottom', rawValue], ['borderStart', rawValue]];
|
117
216
|
},
|
118
|
-
|
119
|
-
//
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
}
|
131
|
-
|
217
|
+
// border: (rawValue: string) => {
|
218
|
+
// if (typeof rawValue === 'number') {
|
219
|
+
// return expansions.borderWidth(rawValue);
|
220
|
+
// }
|
221
|
+
// const [width, style, color, more] = splitValue(rawValue);
|
222
|
+
// if (more != null) {
|
223
|
+
// throw new Error(messages.MULTIPLE_DIRECTIONS_IN_SHORTHAND);
|
224
|
+
// }
|
225
|
+
// if (style == null || color == null) {
|
226
|
+
// throw new Error(
|
227
|
+
// 'Border shorthand requires at least 2 values - width, style and color.'
|
228
|
+
// );
|
229
|
+
// }
|
230
|
+
// return [
|
231
|
+
// ...expansions.borderWidth(width),
|
232
|
+
// ...expansions.borderStyle(style),
|
233
|
+
// ...expansions.borderColor(color),
|
234
|
+
// ];
|
235
|
+
// },
|
236
|
+
// borderTop: (rawValue: string) => {
|
237
|
+
// if (typeof rawValue === 'number') {
|
238
|
+
// return [['borderTopWidth', rawValue + 'px']];
|
239
|
+
// }
|
240
|
+
// const [width, style, color] = splitValue(rawValue);
|
241
|
+
// if (style == null || color == null) {
|
242
|
+
// throw new Error(
|
243
|
+
// 'BorderTop shorthand requires at least 2 values - width, style and color.'
|
244
|
+
// );
|
245
|
+
// }
|
246
|
+
// return [
|
247
|
+
// ['borderTopWidth', width],
|
248
|
+
// ['borderTopStyle', style],
|
249
|
+
// ['borderTopColor', color],
|
250
|
+
// ];
|
251
|
+
// },
|
252
|
+
// borderEnd: (rawValue: string) => {
|
253
|
+
// if (typeof rawValue === 'number') {
|
254
|
+
// return [['borderEndWidth', rawValue + 'px']];
|
255
|
+
// }
|
256
|
+
// const [width, style, color] = splitValue(rawValue);
|
257
|
+
// if (style == null || color == null) {
|
258
|
+
// throw new Error(
|
259
|
+
// 'BorderEnd shorthand requires at least 2 values - width, style and color.'
|
260
|
+
// );
|
261
|
+
// }
|
262
|
+
// return [
|
263
|
+
// ['borderEndWidth', width],
|
264
|
+
// ['borderEndStyle', style],
|
265
|
+
// ['borderEndColor', color],
|
266
|
+
// ];
|
267
|
+
// },
|
268
|
+
// borderBottom: (rawValue: string) => {
|
269
|
+
// if (typeof rawValue === 'number') {
|
270
|
+
// return [['borderBottomWidth', rawValue + 'px']];
|
271
|
+
// }
|
272
|
+
// const [width, style, color] = splitValue(rawValue);
|
273
|
+
// if (style == null || color == null) {
|
274
|
+
// throw new Error(
|
275
|
+
// 'BorderBottom shorthand requires at least 2 values - width, style and color.'
|
276
|
+
// );
|
277
|
+
// }
|
278
|
+
// return [
|
279
|
+
// ['borderBottomWidth', width],
|
280
|
+
// ['borderBottomStyle', style],
|
281
|
+
// ['borderBottomColor', color],
|
282
|
+
// ];
|
283
|
+
// },
|
284
|
+
// borderStart: (rawValue: string) => {
|
285
|
+
// if (typeof rawValue === 'number') {
|
286
|
+
// return [['borderStartWidth', rawValue + 'px']];
|
287
|
+
// }
|
288
|
+
// const [width, style, color] = splitValue(rawValue);
|
289
|
+
// if (style == null || color == null) {
|
290
|
+
// throw new Error(
|
291
|
+
// 'BorderStart shorthand requires at least 2 values - width, style and color.'
|
292
|
+
// );
|
293
|
+
// }
|
294
|
+
// return [
|
295
|
+
// ['borderStartWidth', width],
|
296
|
+
// ['borderStartStyle', style],
|
297
|
+
// ['borderStartColor', color],
|
298
|
+
// ];
|
299
|
+
// },
|
132
300
|
borderColor: rawValue => {
|
133
301
|
const [top, right = top, bottom = top, left = right] = splitValue(rawValue);
|
134
302
|
return [['borderTopColor', top], ['borderEndColor', right], ['borderBottomColor', bottom], ['borderStartColor', left]];
|
@@ -175,8 +343,37 @@ const expansions = {
|
|
175
343
|
},
|
176
344
|
paddingVertical: rawValue => {
|
177
345
|
return [['paddingTop', rawValue], ['paddingBottom', rawValue]];
|
346
|
+
},
|
347
|
+
gap: rawValue => {
|
348
|
+
if (typeof rawValue === 'number') {
|
349
|
+
return [['rowGap', rawValue], ['columnGap', rawValue]];
|
350
|
+
}
|
351
|
+
const [row, column = row] = splitValue(rawValue);
|
352
|
+
return [['rowGap', row], ['columnGap', column]];
|
353
|
+
},
|
354
|
+
placeContent: rawValue => {
|
355
|
+
const [align, justify = align] = splitValue(rawValue);
|
356
|
+
return [['alignContent', align], ['justifyContent', justify]];
|
357
|
+
},
|
358
|
+
placeItems: rawValue => {
|
359
|
+
const [align, justify = align] = splitValue(rawValue);
|
360
|
+
return [['alignItems', align], ['justifyItems', justify]];
|
361
|
+
},
|
362
|
+
placeSelf: rawValue => {
|
363
|
+
const [align, justify = align] = splitValue(rawValue);
|
364
|
+
return [['alignSelf', align], ['justifySelf', justify]];
|
365
|
+
},
|
366
|
+
scrollMargin: rawValue => {
|
367
|
+
const [top, right = top, bottom = top, left = right] = typeof rawValue === 'number' ? [rawValue] : splitValue(rawValue);
|
368
|
+
return [['scrollMarginTop', top], ['scrollMarginEnd', right], ['scrollMarginBottom', bottom], ['scrollMarginStart', left]];
|
369
|
+
},
|
370
|
+
scrollPadding: rawValue => {
|
371
|
+
const [top, right = top, bottom = top, left = right] = typeof rawValue === 'number' ? [rawValue] : splitValue(rawValue);
|
372
|
+
return [['scrollPaddingTop', top], ['scrollPaddingEnd', right], ['scrollPaddingBottom', bottom], ['scrollPaddingStart', left]];
|
178
373
|
}
|
179
374
|
};
|
375
|
+
const expandedKeys = [...Object.keys(expansions), ...Object.keys(BANNED_PROPERTIES)];
|
376
|
+
exports.expandedKeys = expandedKeys;
|
180
377
|
function flatMapExpandedShorthands(objEntry) {
|
181
378
|
const [key, value] = objEntry;
|
182
379
|
const expansion = expansions[key];
|
package/lib/index.d.ts
CHANGED
@@ -25,10 +25,12 @@ export type InjectableStyle = {
|
|
25
25
|
export type StyleRule = readonly [string, string, InjectableStyle];
|
26
26
|
|
27
27
|
export type CompiledStyles = {
|
28
|
-
readonly [key: string]: string |
|
28
|
+
readonly [key: string]: string | null;
|
29
|
+
readonly $$css: true;
|
29
30
|
};
|
30
31
|
export type MutableCompiledStyles = {
|
31
|
-
[key: string]: string |
|
32
|
+
[key: string]: string | null;
|
33
|
+
$$css: true;
|
32
34
|
};
|
33
35
|
|
34
36
|
export type CompiledNamespaces = { readonly [key: string]: CompiledStyles };
|
@@ -62,6 +64,7 @@ export type StyleXOptions = {
|
|
62
64
|
stylexSheetName?: string | undefined;
|
63
65
|
classNamePrefix: string;
|
64
66
|
definedStylexCSSVariables?: { [key: string]: any };
|
67
|
+
allowUnsafeProperties: boolean;
|
65
68
|
[key: string]: any;
|
66
69
|
};
|
67
70
|
|
package/lib/messages.js
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
Object.defineProperty(exports, "__esModule", {
|
14
14
|
value: true
|
15
15
|
});
|
16
|
-
exports.UNKNOWN_PROP_KEY = exports.UNKNOWN_NAMESPACE = exports.UNEXPECTED_ARGUMENT = exports.UNBOUND_STYLEX_CALL_VALUE = exports.ONLY_TOP_LEVEL = exports.NO_PARENT_PATH = exports.NON_STATIC_VALUE = exports.NON_OBJECT_FOR_STYLEX_CALL = exports.LOCAL_ONLY = exports.LINT_UNCLOSED_FUNCTION = exports.INVALID_SPREAD = exports.INVALID_PSEUDO = exports.ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_TYPE = exports.ILLEGAL_ARGUMENT_LENGTH = exports.EXPECTED_FUNCTION_CALL = exports.ESCAPED_STYLEX_VALUE = void 0;
|
16
|
+
exports.UNKNOWN_PROP_KEY = exports.UNKNOWN_NAMESPACE = exports.UNEXPECTED_ARGUMENT = exports.UNBOUND_STYLEX_CALL_VALUE = exports.ONLY_TOP_LEVEL = exports.NO_PARENT_PATH = exports.NO_CONDITIONAL_SHORTHAND = exports.NON_STATIC_VALUE = exports.NON_OBJECT_FOR_STYLEX_CALL = exports.MULTIPLE_DIRECTIONS_IN_SHORTHAND = exports.LOCAL_ONLY = exports.LINT_UNCLOSED_FUNCTION = exports.INVALID_SPREAD = exports.INVALID_PSEUDO = exports.ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_TYPE = exports.ILLEGAL_ARGUMENT_LENGTH = exports.EXPECTED_FUNCTION_CALL = exports.ESCAPED_STYLEX_VALUE = void 0;
|
17
17
|
const ILLEGAL_ARGUMENT_LENGTH = 'stylex() should have 1 argument.';
|
18
18
|
exports.ILLEGAL_ARGUMENT_LENGTH = ILLEGAL_ARGUMENT_LENGTH;
|
19
19
|
const NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
|
@@ -30,6 +30,8 @@ const UNKNOWN_PROP_KEY = 'Unknown property key';
|
|
30
30
|
exports.UNKNOWN_PROP_KEY = UNKNOWN_PROP_KEY;
|
31
31
|
const INVALID_PSEUDO = 'Invalid pseudo selector, not on the whitelist.';
|
32
32
|
exports.INVALID_PSEUDO = INVALID_PSEUDO;
|
33
|
+
const NO_CONDITIONAL_SHORTHAND = 'You cannot use conditional style values for a shorthand property.';
|
34
|
+
exports.NO_CONDITIONAL_SHORTHAND = NO_CONDITIONAL_SHORTHAND;
|
33
35
|
const ILLEGAL_NAMESPACE_TYPE = 'Only a string literal namespace is allowed here.';
|
34
36
|
exports.ILLEGAL_NAMESPACE_TYPE = ILLEGAL_NAMESPACE_TYPE;
|
35
37
|
const UNKNOWN_NAMESPACE = 'Unknown namespace';
|
@@ -53,4 +55,6 @@ exports.UNEXPECTED_ARGUMENT = UNEXPECTED_ARGUMENT;
|
|
53
55
|
const EXPECTED_FUNCTION_CALL = 'Expected a simple function call but found something else.';
|
54
56
|
exports.EXPECTED_FUNCTION_CALL = EXPECTED_FUNCTION_CALL;
|
55
57
|
const NO_PARENT_PATH = 'Unexpected AST node without a parent path.';
|
56
|
-
exports.NO_PARENT_PATH = NO_PARENT_PATH;
|
58
|
+
exports.NO_PARENT_PATH = NO_PARENT_PATH;
|
59
|
+
const MULTIPLE_DIRECTIONS_IN_SHORTHAND = 'Shorthand properties cannot contain different values for different directions.';
|
60
|
+
exports.MULTIPLE_DIRECTIONS_IN_SHORTHAND = MULTIPLE_DIRECTIONS_IN_SHORTHAND;
|
package/lib/stylex-create.js
CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = styleXCreateSet;
|
7
7
|
var _convertToClassName = _interopRequireDefault(require("./convert-to-className"));
|
8
|
-
var _expandShorthands =
|
8
|
+
var _expandShorthands = _interopRequireWildcard(require("./expand-shorthands"));
|
9
9
|
var _objectUtils = require("./utils/object-utils");
|
10
10
|
var messages = _interopRequireWildcard(require("./messages"));
|
11
11
|
var _stylexInclude = require("./stylex-include");
|
@@ -41,7 +41,11 @@ function styleXCreateSet(namespaces) {
|
|
41
41
|
throw new Error(messages.ILLEGAL_NAMESPACE_VALUE);
|
42
42
|
}
|
43
43
|
const [resolvedNamespace, injected] = styleXCreateNamespace(namespace, options);
|
44
|
-
|
44
|
+
const compiledNamespace = (0, _objectUtils.flattenObject)(resolvedNamespace);
|
45
|
+
resolvedNamespaces[namespaceName] = {
|
46
|
+
...compiledNamespace,
|
47
|
+
$$css: true
|
48
|
+
};
|
45
49
|
for (const cn of Object.keys(injected)) {
|
46
50
|
if (injectedStyles[cn] == null) {
|
47
51
|
injectedStyles[cn] = injected[cn];
|
@@ -77,7 +81,7 @@ function styleXCreateNamespace(style, options) {
|
|
77
81
|
return [[key, value]];
|
78
82
|
}
|
79
83
|
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
|
80
|
-
if (!key.startsWith(':') && !key.startsWith('@')) {
|
84
|
+
if (!key.startsWith(':') && !key.startsWith('@') && _expandShorthands.expandedKeys.includes(key)) {
|
81
85
|
throw new Error(messages.INVALID_PSEUDO);
|
82
86
|
}
|
83
87
|
return [[key, (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(value).flatMap(_ref2 => {
|
@@ -85,15 +89,21 @@ function styleXCreateNamespace(style, options) {
|
|
85
89
|
if (innerValue != null && typeof innerValue === 'object' && !Array.isArray(innerValue)) {
|
86
90
|
throw new Error(messages.ILLEGAL_NESTED_PSEUDO);
|
87
91
|
}
|
92
|
+
if (!options.allowUnsafeProperties && _expandShorthands.BANNED_PROPERTIES[key]) {
|
93
|
+
throw new Error(_expandShorthands.BANNED_PROPERTIES[key]);
|
94
|
+
}
|
88
95
|
return (0, _expandShorthands.default)([innerKey, innerValue]);
|
89
96
|
}))]];
|
90
97
|
} else {
|
91
|
-
if (typeof value !== 'string' && typeof value !== 'number' && !Array.isArray(value)) {
|
98
|
+
if (value !== null && typeof value !== 'string' && typeof value !== 'number' && !Array.isArray(value)) {
|
92
99
|
throw new Error(messages.ILLEGAL_PROP_VALUE);
|
93
100
|
}
|
94
101
|
if (Array.isArray(value) && value.some(val => typeof val === 'object')) {
|
95
102
|
throw new Error(messages.ILLEGAL_PROP_ARRAY_VALUE);
|
96
103
|
}
|
104
|
+
if (!options.allowUnsafeProperties && _expandShorthands.BANNED_PROPERTIES[key]) {
|
105
|
+
throw new Error(_expandShorthands.BANNED_PROPERTIES[key]);
|
106
|
+
}
|
97
107
|
return (0, _expandShorthands.default)([key, value]);
|
98
108
|
}
|
99
109
|
});
|
@@ -109,18 +119,42 @@ function styleXCreateNamespace(style, options) {
|
|
109
119
|
if (val instanceof _stylexInclude.IncludedStyles) {
|
110
120
|
resolvedNamespace[key] = val;
|
111
121
|
} else if (val != null && typeof val === 'object' && !Array.isArray(val)) {
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
const [
|
116
|
-
|
117
|
-
|
122
|
+
if (key.startsWith(':') || key.startsWith('@')) {
|
123
|
+
const pseudo = key;
|
124
|
+
const innerObj = {};
|
125
|
+
for (const [innerKey, innerVal] of (0, _objectUtils.objEntries)(val)) {
|
126
|
+
if (innerVal === null) {
|
127
|
+
innerObj[innerKey] = null;
|
128
|
+
} else {
|
129
|
+
const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([innerKey, innerVal], pseudo, options);
|
130
|
+
innerObj[updatedKey] = className;
|
131
|
+
injectedStyles[updatedKey + pseudo] = [className, cssRule];
|
132
|
+
}
|
133
|
+
}
|
134
|
+
resolvedNamespace[key] = innerObj;
|
135
|
+
} else {
|
136
|
+
const propKey = key;
|
137
|
+
const classNames = [];
|
138
|
+
for (const [pseudo, innerVal] of (0, _objectUtils.objEntries)(val)) {
|
139
|
+
if (pseudo !== 'default' && !pseudo.startsWith(':') && !pseudo.startsWith('@')) {
|
140
|
+
throw new Error(messages.INVALID_PSEUDO);
|
141
|
+
}
|
142
|
+
if (innerVal !== null) {
|
143
|
+
const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([propKey, innerVal], pseudo === 'default' ? undefined : pseudo, options);
|
144
|
+
injectedStyles[updatedKey + pseudo] = [className, cssRule];
|
145
|
+
classNames.push(className);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
resolvedNamespace[key] = classNames.join(' ');
|
118
149
|
}
|
119
|
-
resolvedNamespace[key] = innerObj;
|
120
150
|
} else {
|
121
|
-
|
122
|
-
|
123
|
-
|
151
|
+
if (val === null) {
|
152
|
+
resolvedNamespace[key] = null;
|
153
|
+
} else {
|
154
|
+
const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([key, val], undefined, options);
|
155
|
+
resolvedNamespace[updatedKey] = className;
|
156
|
+
injectedStyles[updatedKey] = [className, cssRule];
|
157
|
+
}
|
124
158
|
}
|
125
159
|
}
|
126
160
|
const finalInjectedStyles = (0, _objectUtils.objFromEntries)((0, _objectUtils.objValues)(injectedStyles));
|
@@ -0,0 +1,397 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.StylexValueBuilder = void 0;
|
7
|
+
exports.default = stylexDefaultValue;
|
8
|
+
var messages = _interopRequireWildcard(require("./messages"));
|
9
|
+
var _dashify = _interopRequireDefault(require("./utils/dashify"));
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
13
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
14
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
15
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
16
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
17
|
+
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
18
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
19
|
+
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
20
|
+
var _set = /*#__PURE__*/new WeakSet();
|
21
|
+
var _mediaWidths = /*#__PURE__*/new WeakMap();
|
22
|
+
var _mediaHeights = /*#__PURE__*/new WeakMap();
|
23
|
+
class StylexValueBuilder {
|
24
|
+
constructor(defaultValue) {
|
25
|
+
_classPrivateMethodInitSpec(this, _set);
|
26
|
+
_classPrivateFieldInitSpec(this, _mediaWidths, {
|
27
|
+
writable: true,
|
28
|
+
value: []
|
29
|
+
});
|
30
|
+
_classPrivateFieldInitSpec(this, _mediaHeights, {
|
31
|
+
writable: true,
|
32
|
+
value: []
|
33
|
+
});
|
34
|
+
this.default = defaultValue;
|
35
|
+
}
|
36
|
+
mediaWidth(_ref, value) {
|
37
|
+
let [min, max] = _ref;
|
38
|
+
if (_classPrivateFieldGet(this, _mediaWidths).some(_ref2 => {
|
39
|
+
let [m, M] = _ref2;
|
40
|
+
return m <= min && min < M || m < max && max <= M || min <= m && max >= M;
|
41
|
+
})) {
|
42
|
+
throw new Error(messages.OVERLAPPING_MEDIA_WIDTHS);
|
43
|
+
}
|
44
|
+
_classPrivateFieldGet(this, _mediaWidths).push([min, max]);
|
45
|
+
if (min > 0 && max < Infinity) {
|
46
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-width: ${min}px and max-width: ${max}px)`, value);
|
47
|
+
} else if (min === 0) {
|
48
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (max-width: ${max}px)`, value);
|
49
|
+
} else if (max === Infinity) {
|
50
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-width: ${min}px)`, value);
|
51
|
+
}
|
52
|
+
throw new Error(messages.INVALID_MEDIA_QUERY);
|
53
|
+
}
|
54
|
+
mediaHeight(_ref3, value) {
|
55
|
+
let [min, max] = _ref3;
|
56
|
+
if (_classPrivateFieldGet(this, _mediaHeights).some(_ref4 => {
|
57
|
+
let [m, M] = _ref4;
|
58
|
+
return m <= min && min < M || m < max && max <= M || min <= m && max >= M;
|
59
|
+
})) {
|
60
|
+
throw new Error(messages.OVERLAPPING_MEDIA_HEIGHTS);
|
61
|
+
}
|
62
|
+
_classPrivateFieldGet(this, _mediaHeights).push([min, max]);
|
63
|
+
if (min > 0 && max < Infinity) {
|
64
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-height: ${min}px and max-height: ${max}px)`, value);
|
65
|
+
} else if (min === 0) {
|
66
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (max-height: ${max}px)`, value);
|
67
|
+
} else if (max === Infinity) {
|
68
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-height: ${min}px)`, value);
|
69
|
+
}
|
70
|
+
throw new Error(messages.INVALID_MEDIA_QUERY);
|
71
|
+
}
|
72
|
+
|
73
|
+
// mediaAspectRatio<TAddedValue>(
|
74
|
+
// [min, max]: [number, number],
|
75
|
+
// value: TAddedValue
|
76
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
77
|
+
// if (min > 0 && max < Infinity) {
|
78
|
+
// return this.#set(
|
79
|
+
// `@media (min-aspect-ratio: ${min} and max-aspect-ratio: $, })`,
|
80
|
+
// value
|
81
|
+
// );
|
82
|
+
// } else if (min === 0) {
|
83
|
+
// return this.#set(`@media (max-aspect-ratio: ${max})`, value);
|
84
|
+
// } else if (max === Infinity) {
|
85
|
+
// return this.#set(`@media (min-aspect-ratio: ${min})`, value);
|
86
|
+
// }
|
87
|
+
// throw new Error(messages.INVALID_MEDIA_QUERY);
|
88
|
+
// }
|
89
|
+
|
90
|
+
// mediaPortrait<TAddedValue>(
|
91
|
+
// value: TAddedValue
|
92
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
93
|
+
// return this.#set('@media (orientation: portrait)', value);
|
94
|
+
// }
|
95
|
+
|
96
|
+
// mediaLandscape<TAddedValue>(
|
97
|
+
// value: TAddedValue
|
98
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
99
|
+
// return this.#set('@media (orientation: landscape)', value);
|
100
|
+
// }
|
101
|
+
|
102
|
+
// mediaSRGBDisplay<TAddedValue>(
|
103
|
+
// value: TAddedValue
|
104
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
105
|
+
// return this.#set('@media (color-gamut: srgb)', value);
|
106
|
+
// }
|
107
|
+
|
108
|
+
// mediaP3Display<TAddedValue>(
|
109
|
+
// value: TAddedValue
|
110
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
111
|
+
// return this.#set('@media (color-gamut: p3)', value);
|
112
|
+
// }
|
113
|
+
|
114
|
+
// mediaRec2020Display<TAddedValue>(
|
115
|
+
// value: TAddedValue
|
116
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
117
|
+
// return this.#set('@media (color-gamut: rec2020)', value);
|
118
|
+
// }
|
119
|
+
|
120
|
+
// mediaIsFullscreen<TAddedValue>(
|
121
|
+
// value: TAddedValue
|
122
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
123
|
+
// return this.#set('@media (display-mode: fullscreen)', value);
|
124
|
+
// }
|
125
|
+
|
126
|
+
// These are confusing, so skipping them for now
|
127
|
+
// mediaIsStandalone
|
128
|
+
// mediaIsMinimalUI
|
129
|
+
|
130
|
+
// mediaSDRDisplay<TAddedValue>(
|
131
|
+
// value: TAddedValue
|
132
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
133
|
+
// return this.#set('@media (dynamic-range: standard)', value);
|
134
|
+
// }
|
135
|
+
|
136
|
+
// mediaHDRDisplay<TAddedValue>(
|
137
|
+
// value: TAddedValue
|
138
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
139
|
+
// return this.#set('@media (dynamic-range: high)', value);
|
140
|
+
// }
|
141
|
+
|
142
|
+
// mediaSupportsHDRVideo<TAddedValue>(
|
143
|
+
// value: TAddedValue
|
144
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
145
|
+
// return this.#set('@media (video-dynamic-range: high)', value);
|
146
|
+
// }
|
147
|
+
|
148
|
+
//<TAddedValue> mediaHasColor(value: TAddedValue): StylexValueBuilder<TValue | TAddedValue> {
|
149
|
+
// return this.#set('@media (color)', value);
|
150
|
+
// }
|
151
|
+
|
152
|
+
// primaryInputCanHover<TAddedValue>(
|
153
|
+
// value: TAddedValue
|
154
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
155
|
+
// return this.#set('@media (hover: hover)', value);
|
156
|
+
// }
|
157
|
+
// primaryInputCanNotHover<TAddedValue>(
|
158
|
+
// value: TAddedValue
|
159
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
160
|
+
// return this.#set('@media (hover: none)', value);
|
161
|
+
// }
|
162
|
+
|
163
|
+
// someInputCanHover<TAddedValue>(
|
164
|
+
// value: TAddedValue
|
165
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
166
|
+
// return this.#set('@media (any-hover: hover)', value);
|
167
|
+
// }
|
168
|
+
|
169
|
+
// noInputCanHover<TAddedValue>(
|
170
|
+
// value: TAddedValue
|
171
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
172
|
+
// return this.#set('@media (any-hover: none)', value);
|
173
|
+
// }
|
174
|
+
|
175
|
+
// somePointerIsFine<TAddedValue>(
|
176
|
+
// value: TAddedValue
|
177
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
178
|
+
// return this.#set('@media (any-pointer: fine)', value);
|
179
|
+
// }
|
180
|
+
|
181
|
+
// somePointerIsCoarse<TAddedValue>(
|
182
|
+
// value: TAddedValue
|
183
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
184
|
+
// return this.#set('@media (any-pointer: coarse)', value);
|
185
|
+
// }
|
186
|
+
|
187
|
+
// primaryPointerIsFine<TAddedValue>(
|
188
|
+
// value: TAddedValue
|
189
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
190
|
+
// return this.#set('@media (pointer: fine)', value);
|
191
|
+
// }
|
192
|
+
|
193
|
+
// primaryPointerIsCoarse<TAddedValue>(
|
194
|
+
// value: TAddedValue
|
195
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
196
|
+
// return this.#set('@media (pointer: coarse)', value);
|
197
|
+
// }
|
198
|
+
|
199
|
+
// lightMode<TAddedValue>(
|
200
|
+
// value: TAddedValue
|
201
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
202
|
+
// return this.#set('@media (prefers-color-scheme: light)', value);
|
203
|
+
// }
|
204
|
+
|
205
|
+
// darkMode<TAddedValue>(
|
206
|
+
// value: TAddedValue
|
207
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
208
|
+
// return this.#set('@media (prefers-color-scheme: dark)', value);
|
209
|
+
// }
|
210
|
+
|
211
|
+
// userPrefersMoreContrast<TAddedValue>(
|
212
|
+
// value: TAddedValue
|
213
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
214
|
+
// return this.#set('@media (prefers-contrast: more)', value);
|
215
|
+
// }
|
216
|
+
|
217
|
+
// userPrefersLessContrast<TAddedValue>(
|
218
|
+
// value: TAddedValue
|
219
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
220
|
+
// return this.#set('@media (prefers-contrast: less)', value);
|
221
|
+
// }
|
222
|
+
|
223
|
+
// userPrefersReducedMotion<TAddedValue>(
|
224
|
+
// value: TAddedValue
|
225
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
226
|
+
// return this.#set('@media (prefers-reduced-motion)', value);
|
227
|
+
// }
|
228
|
+
|
229
|
+
// noScript<TAddedValue>(
|
230
|
+
// value: TAddedValue
|
231
|
+
// ): StylexValueBuilder<TValue | TAddedValue> {
|
232
|
+
// return this.#set('@media (scripting: none)', value);
|
233
|
+
// }
|
234
|
+
|
235
|
+
// Choosing a catch-all for now for familiarity
|
236
|
+
matchMedia(query, value) {
|
237
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media ${query}`, value);
|
238
|
+
}
|
239
|
+
supports(selector, value) {
|
240
|
+
const toSelector = _ref5 => {
|
241
|
+
let [k, v] = _ref5;
|
242
|
+
return `(${(0, _dashify.default)(k)}: ${String(v)})`;
|
243
|
+
};
|
244
|
+
const query = Object.entries(selector).map(toSelector).join(' and ');
|
245
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@supports ${query}`, value);
|
246
|
+
}
|
247
|
+
supportsNot(selector, value) {
|
248
|
+
const toSelector = _ref6 => {
|
249
|
+
let [k, v] = _ref6;
|
250
|
+
return `(not (${(0, _dashify.default)(k)}: ${String(v)}))`;
|
251
|
+
};
|
252
|
+
const query = Object.entries(selector).map(toSelector).join(' and ');
|
253
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@supports ${query}`, value);
|
254
|
+
}
|
255
|
+
|
256
|
+
// Pseudo Classes
|
257
|
+
|
258
|
+
hover(value) {
|
259
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':hover', value);
|
260
|
+
}
|
261
|
+
focus(value) {
|
262
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':focus', value);
|
263
|
+
}
|
264
|
+
focusVisible(value) {
|
265
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':focus-visible', value);
|
266
|
+
}
|
267
|
+
focusWithin(value) {
|
268
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':focus-within', value);
|
269
|
+
}
|
270
|
+
active(value) {
|
271
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':active', value);
|
272
|
+
}
|
273
|
+
anyLink(value) {
|
274
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':any-link', value);
|
275
|
+
}
|
276
|
+
autofill(value) {
|
277
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':autofill', value);
|
278
|
+
}
|
279
|
+
checked(value) {
|
280
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':checked', value);
|
281
|
+
}
|
282
|
+
defaultSelection(value) {
|
283
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':default', value);
|
284
|
+
}
|
285
|
+
disabled(value) {
|
286
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':disabled', value);
|
287
|
+
}
|
288
|
+
empty(value) {
|
289
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':empty', value);
|
290
|
+
}
|
291
|
+
enabled(value) {
|
292
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':enabled', value);
|
293
|
+
}
|
294
|
+
fullscreen(value) {
|
295
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':fullscreen', value);
|
296
|
+
}
|
297
|
+
indeterminate(value) {
|
298
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':indeterminate', value);
|
299
|
+
}
|
300
|
+
invalid(value) {
|
301
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':invalid', value);
|
302
|
+
}
|
303
|
+
lang(value) {
|
304
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':lang', value);
|
305
|
+
}
|
306
|
+
dirRTLUNSFAE(value) {
|
307
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':dir(rtl)', value);
|
308
|
+
}
|
309
|
+
link(value) {
|
310
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':link', value);
|
311
|
+
}
|
312
|
+
optional(value) {
|
313
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':optional', value);
|
314
|
+
}
|
315
|
+
pictureInPicture(value) {
|
316
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':picture-in-picture', value);
|
317
|
+
}
|
318
|
+
placeholderShown(value) {
|
319
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':placeholder-shown', value);
|
320
|
+
}
|
321
|
+
paused(value) {
|
322
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':paused', value);
|
323
|
+
}
|
324
|
+
playing(value) {
|
325
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':playing', value);
|
326
|
+
}
|
327
|
+
readOnly(value) {
|
328
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':read-only', value);
|
329
|
+
}
|
330
|
+
readWrite(value) {
|
331
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':read-write', value);
|
332
|
+
}
|
333
|
+
required(value) {
|
334
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':required', value);
|
335
|
+
}
|
336
|
+
target(value) {
|
337
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':target', value);
|
338
|
+
}
|
339
|
+
valid(value) {
|
340
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':valid', value);
|
341
|
+
}
|
342
|
+
visited(value) {
|
343
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':visited', value);
|
344
|
+
}
|
345
|
+
get not() {
|
346
|
+
return {
|
347
|
+
hover: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:hover)', value),
|
348
|
+
focus: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:focus)', value),
|
349
|
+
focusVisible: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:focus-visible)', value),
|
350
|
+
focusWithin: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:focus-within)', value),
|
351
|
+
active: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:active)', value),
|
352
|
+
anyLink: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:any-link)', value),
|
353
|
+
autofill: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:autofill)', value),
|
354
|
+
checked: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:checked)', value),
|
355
|
+
defaultSelection: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:default)', value),
|
356
|
+
disabled: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:disabled)', value),
|
357
|
+
empty: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:empty)', value),
|
358
|
+
enabled: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:enabled)', value),
|
359
|
+
fullscreen: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:fullscreen)', value),
|
360
|
+
indeterminate: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:indeterminate)', value),
|
361
|
+
invalid: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:invalid)', value),
|
362
|
+
lang: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:lang)', value),
|
363
|
+
dirRTLUNSFAE: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:dir-rtlunsfae)', value),
|
364
|
+
link: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:link)', value),
|
365
|
+
optional: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:optional)', value),
|
366
|
+
pictureInPicture: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:picture-in-picture)', value),
|
367
|
+
placeholderShown: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:placeholder-shown)', value),
|
368
|
+
paused: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:paused)', value),
|
369
|
+
playing: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:playing)', value),
|
370
|
+
readOnly: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:read-only)', value),
|
371
|
+
readWrite: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:read-write)', value),
|
372
|
+
required: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:required)', value),
|
373
|
+
target: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:target)', value),
|
374
|
+
valid: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:valid)', value),
|
375
|
+
visited: value => _classPrivateMethodGet(this, _set, _set2).call(this, ':not(:visited)', value)
|
376
|
+
};
|
377
|
+
}
|
378
|
+
pseudoUNSAFE(selector, value) {
|
379
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `:${selector}`, value);
|
380
|
+
}
|
381
|
+
// These can be used to write arbitrary CSS selectors
|
382
|
+
// Which is UNSAFE!
|
383
|
+
_isUNSAFE(selector, value) {
|
384
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `:is(${selector})`, value);
|
385
|
+
}
|
386
|
+
_notUNSAFE(selector, value) {
|
387
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `:not(${selector})`, value);
|
388
|
+
}
|
389
|
+
}
|
390
|
+
exports.StylexValueBuilder = StylexValueBuilder;
|
391
|
+
function _set2(key, value) {
|
392
|
+
this[key] = value;
|
393
|
+
return this;
|
394
|
+
}
|
395
|
+
function stylexDefaultValue(value) {
|
396
|
+
return new StylexValueBuilder(value);
|
397
|
+
}
|
@@ -26,7 +26,7 @@ var _stylexInclude = require("../stylex-include");
|
|
26
26
|
function flattenObject(obj) {
|
27
27
|
const result = {};
|
28
28
|
for (const [key, value] of objEntries(obj)) {
|
29
|
-
if (typeof value === 'string') {
|
29
|
+
if (typeof value === 'string' || value == null) {
|
30
30
|
result[key] = value;
|
31
31
|
} else if (value instanceof _stylexInclude.IncludedStyles) {
|
32
32
|
result[key] = value;
|
package/package.json
CHANGED