@stylexjs/shared 0.1.0-beta.7 → 0.2.0-beta.10
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 -0
- package/lib/convert-to-className.js +13 -6
- package/lib/expand-shorthands.d.ts +5 -0
- package/lib/expand-shorthands.js +241 -101
- package/lib/generate-css-rule.js +10 -38
- package/lib/index.d.ts +10 -0
- package/lib/index.js.flow +5 -0
- package/lib/messages.js +11 -3
- package/lib/namespace-transforms/__tests__/preflatten.test.js +120 -0
- package/lib/namespace-transforms/preflatten.js +89 -0
- package/lib/physical-rtl/generate-ltr.js +32 -32
- package/lib/physical-rtl/generate-rtl.js +30 -30
- package/lib/preprocess-rules/PreRule.js +101 -0
- package/lib/preprocess-rules/application-order.js +259 -0
- package/lib/preprocess-rules/basic-validation.js +92 -0
- package/lib/preprocess-rules/expand-shorthands.js +156 -0
- package/lib/preprocess-rules/flatten-raw-style-obj.js +148 -0
- package/lib/preprocess-rules/index.js +39 -0
- package/lib/preprocess-rules/legacy-expand-shorthands.js +219 -0
- package/lib/preprocess-rules/null-out-longhand.js +310 -0
- package/lib/preprocess-rules/property-specificity.js +135 -0
- package/lib/preprocess-rules/react-native-web.js +142 -0
- package/lib/stylex-create.js +30 -101
- package/lib/stylex-defaultValue.js +230 -98
- package/lib/stylex-keyframes.js +23 -10
- package/lib/utils/Rule.js +71 -0
- package/lib/utils/default-options.js +34 -0
- package/lib/utils/genCSSRule.js +9 -8
- package/lib/utils/normalize-value.js +3 -0
- package/lib/utils/object-utils.js +23 -2
- package/lib/utils/property-priorities.js +116 -0
- package/lib/utils/split-css-value.js +47 -0
- package/lib/validate.js +1 -1
- package/package.json +1 -1
@@ -10,22 +10,38 @@ var _dashify = _interopRequireDefault(require("./utils/dashify"));
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
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
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); }
|
13
14
|
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
14
15
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
15
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; }
|
16
20
|
var _set = /*#__PURE__*/new WeakSet();
|
21
|
+
var _mediaWidths = /*#__PURE__*/new WeakMap();
|
22
|
+
var _mediaHeights = /*#__PURE__*/new WeakMap();
|
17
23
|
class StylexValueBuilder {
|
18
24
|
constructor(defaultValue) {
|
19
25
|
_classPrivateMethodInitSpec(this, _set);
|
26
|
+
_classPrivateFieldInitSpec(this, _mediaWidths, {
|
27
|
+
writable: true,
|
28
|
+
value: []
|
29
|
+
});
|
30
|
+
_classPrivateFieldInitSpec(this, _mediaHeights, {
|
31
|
+
writable: true,
|
32
|
+
value: []
|
33
|
+
});
|
20
34
|
this.default = defaultValue;
|
21
35
|
}
|
22
|
-
// @media Queries
|
23
|
-
|
24
|
-
mediaPrint(value) {
|
25
|
-
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media print', value);
|
26
|
-
}
|
27
36
|
mediaWidth(_ref, value) {
|
28
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]);
|
29
45
|
if (min > 0 && max < Infinity) {
|
30
46
|
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-width: ${min}px and max-width: ${max}px)`, value);
|
31
47
|
} else if (min === 0) {
|
@@ -35,8 +51,15 @@ class StylexValueBuilder {
|
|
35
51
|
}
|
36
52
|
throw new Error(messages.INVALID_MEDIA_QUERY);
|
37
53
|
}
|
38
|
-
mediaHeight(
|
39
|
-
let [min, max] =
|
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]);
|
40
63
|
if (min > 0 && max < Infinity) {
|
41
64
|
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-height: ${min}px and max-height: ${max}px)`, value);
|
42
65
|
} else if (min === 0) {
|
@@ -46,110 +69,184 @@ class StylexValueBuilder {
|
|
46
69
|
}
|
47
70
|
throw new Error(messages.INVALID_MEDIA_QUERY);
|
48
71
|
}
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
|
62
|
-
}
|
63
|
-
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
}
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
}
|
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
|
+
// }
|
78
125
|
|
79
126
|
// These are confusing, so skipping them for now
|
80
127
|
// mediaIsStandalone
|
81
128
|
// mediaIsMinimalUI
|
82
129
|
|
83
|
-
mediaSDRDisplay(
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
+
// }
|
92
147
|
|
93
148
|
//<TAddedValue> mediaHasColor(value: TAddedValue): StylexValueBuilder<TValue | TAddedValue> {
|
94
149
|
// return this.#set('@media (color)', value);
|
95
150
|
// }
|
96
151
|
|
97
|
-
primaryInputCanHover(
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
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) {
|
140
237
|
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media ${query}`, value);
|
141
238
|
}
|
142
239
|
supports(selector, value) {
|
143
|
-
const toSelector =
|
144
|
-
let [k, v] =
|
240
|
+
const toSelector = _ref5 => {
|
241
|
+
let [k, v] = _ref5;
|
145
242
|
return `(${(0, _dashify.default)(k)}: ${String(v)})`;
|
146
243
|
};
|
147
244
|
const query = Object.entries(selector).map(toSelector).join(' and ');
|
148
245
|
return _classPrivateMethodGet(this, _set, _set2).call(this, `@supports ${query}`, value);
|
149
246
|
}
|
150
247
|
supportsNot(selector, value) {
|
151
|
-
const toSelector =
|
152
|
-
let [k, v] =
|
248
|
+
const toSelector = _ref6 => {
|
249
|
+
let [k, v] = _ref6;
|
153
250
|
return `(not (${(0, _dashify.default)(k)}: ${String(v)}))`;
|
154
251
|
};
|
155
252
|
const query = Object.entries(selector).map(toSelector).join(' and ');
|
@@ -203,12 +300,6 @@ class StylexValueBuilder {
|
|
203
300
|
invalid(value) {
|
204
301
|
return _classPrivateMethodGet(this, _set, _set2).call(this, ':invalid', value);
|
205
302
|
}
|
206
|
-
isUNSAFE(selector, value) {
|
207
|
-
return _classPrivateMethodGet(this, _set, _set2).call(this, `:is(${selector})`, value);
|
208
|
-
}
|
209
|
-
notUNSAFE(selector, value) {
|
210
|
-
return _classPrivateMethodGet(this, _set, _set2).call(this, `:not(${selector})`, value);
|
211
|
-
}
|
212
303
|
lang(value) {
|
213
304
|
return _classPrivateMethodGet(this, _set, _set2).call(this, ':lang', value);
|
214
305
|
}
|
@@ -251,9 +342,50 @@ class StylexValueBuilder {
|
|
251
342
|
visited(value) {
|
252
343
|
return _classPrivateMethodGet(this, _set, _set2).call(this, ':visited', value);
|
253
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
|
+
}
|
254
378
|
pseudoUNSAFE(selector, value) {
|
255
379
|
return _classPrivateMethodGet(this, _set, _set2).call(this, `:${selector}`, value);
|
256
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
|
+
}
|
257
389
|
}
|
258
390
|
exports.StylexValueBuilder = StylexValueBuilder;
|
259
391
|
function _set2(key, value) {
|
package/lib/stylex-keyframes.js
CHANGED
@@ -5,12 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = styleXKeyframes;
|
7
7
|
var _hash = _interopRequireDefault(require("./hash"));
|
8
|
-
var
|
8
|
+
var _index = _interopRequireDefault(require("./preprocess-rules/index"));
|
9
9
|
var _generateLtr = _interopRequireDefault(require("./physical-rtl/generate-ltr"));
|
10
10
|
var _generateRtl = _interopRequireDefault(require("./physical-rtl/generate-rtl"));
|
11
11
|
var _transformValue = _interopRequireDefault(require("./transform-value"));
|
12
12
|
var _dashify = _interopRequireDefault(require("./utils/dashify"));
|
13
13
|
var _objectUtils = require("./utils/object-utils");
|
14
|
+
var _defaultOptions = require("./utils/default-options");
|
14
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
16
|
/**
|
16
17
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
@@ -27,11 +28,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
27
28
|
// It also expands shorthand properties to maintain parity with
|
28
29
|
// `stylex.create`.
|
29
30
|
function styleXKeyframes(frames) {
|
30
|
-
let
|
31
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaultOptions.defaultOptions;
|
32
|
+
const {
|
31
33
|
stylexSheetName = '<>',
|
32
34
|
classNamePrefix = 'x'
|
33
|
-
} =
|
34
|
-
const expandedObject = (0, _objectUtils.objMap)(frames, frame => _objectUtils.Pipe.create(frame).pipe(expandFrameShorthands).pipe(x => (0, _objectUtils.objMapKeys)(x, _dashify.default)).pipe(x => (0, _objectUtils.objMap)(x, (value, key) => (0, _transformValue.default)(key, value))).done());
|
35
|
+
} = options;
|
36
|
+
const expandedObject = (0, _objectUtils.objMap)(frames, frame => _objectUtils.Pipe.create(frame).pipe(frame => expandFrameShorthands(frame, options)).pipe(x => (0, _objectUtils.objMapKeys)(x, _dashify.default)).pipe(x => (0, _objectUtils.objMap)(x, (value, key) => (0, _transformValue.default)(key, value))).done());
|
35
37
|
const ltrStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, _generateLtr.default));
|
36
38
|
const rtlStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, entry => (0, _generateRtl.default)(entry) ?? entry));
|
37
39
|
const ltrString = constructKeyframesObj(ltrStyles);
|
@@ -47,16 +49,27 @@ function styleXKeyframes(frames) {
|
|
47
49
|
priority: 1
|
48
50
|
}];
|
49
51
|
}
|
50
|
-
function expandFrameShorthands(frame) {
|
51
|
-
return (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(frame).flatMap(pair => (0,
|
52
|
+
function expandFrameShorthands(frame, options) {
|
53
|
+
return (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(frame).flatMap(pair => (0, _index.default)(pair, options).map(_ref => {
|
54
|
+
let [key, value] = _ref;
|
55
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
56
|
+
return [key, value];
|
57
|
+
}
|
58
|
+
return null;
|
59
|
+
}).filter(Boolean))
|
60
|
+
// Keyframes are not combined. The nulls can be skipped
|
61
|
+
.filter(_ref2 => {
|
62
|
+
let [_key, value] = _ref2;
|
63
|
+
return value != null;
|
64
|
+
}));
|
52
65
|
}
|
53
66
|
|
54
67
|
// Create t
|
55
68
|
function constructKeyframesObj(frames) {
|
56
|
-
return (0, _objectUtils.objEntries)(frames).map(
|
57
|
-
let [key, value] =
|
58
|
-
return `${key}{${(0, _objectUtils.objEntries)(value).map(
|
59
|
-
let [k, v] =
|
69
|
+
return (0, _objectUtils.objEntries)(frames).map(_ref3 => {
|
70
|
+
let [key, value] = _ref3;
|
71
|
+
return `${key}{${(0, _objectUtils.objEntries)(value).map(_ref4 => {
|
72
|
+
let [k, v] = _ref4;
|
60
73
|
return `${k}:${v};`;
|
61
74
|
}).join('')}}`;
|
62
75
|
}).join('');
|
@@ -0,0 +1,71 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Rule = exports.RawRuleRTLTuple = exports.RawRuleList = exports.RawRule = exports.CompiledRuleTuple2 = exports.CompiledRule = void 0;
|
7
|
+
/**
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
9
|
+
*
|
10
|
+
* This source code is licensed under the MIT license found in the
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
12
|
+
*
|
13
|
+
*
|
14
|
+
*/
|
15
|
+
|
16
|
+
/**
|
17
|
+
* This could be an interface, but we use a class so that we can
|
18
|
+
* use instanceof to check for it.
|
19
|
+
*/
|
20
|
+
// eslint-disable-next-line no-unused-vars
|
21
|
+
class Rule {}
|
22
|
+
|
23
|
+
/**
|
24
|
+
* This is a class that represents a raw style rule.
|
25
|
+
*
|
26
|
+
* It exists to track the actual CSS rule that should be compiled
|
27
|
+
* even as we transform the structure of the RawStyles object.
|
28
|
+
*/
|
29
|
+
exports.Rule = Rule;
|
30
|
+
class RawRule extends Rule {
|
31
|
+
constructor(key, value, psuedos, atRules) {
|
32
|
+
super();
|
33
|
+
this.key = key;
|
34
|
+
this.value = value;
|
35
|
+
this.psuedos = psuedos;
|
36
|
+
this.atRules = atRules;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
exports.RawRule = RawRule;
|
40
|
+
class RawRuleList extends Rule {
|
41
|
+
constructor(rules) {
|
42
|
+
super();
|
43
|
+
this.rules = rules;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
exports.RawRuleList = RawRuleList;
|
47
|
+
class RawRuleRTLTuple extends Rule {
|
48
|
+
constructor(rule1, rule2) {
|
49
|
+
super();
|
50
|
+
this.rules = [rule1, rule2];
|
51
|
+
}
|
52
|
+
}
|
53
|
+
exports.RawRuleRTLTuple = RawRuleRTLTuple;
|
54
|
+
class CompiledRule extends Rule {
|
55
|
+
constructor(key, value, psuedos, atRules, className) {
|
56
|
+
super();
|
57
|
+
this.key = key;
|
58
|
+
this.value = value;
|
59
|
+
this.psuedos = psuedos;
|
60
|
+
this.atRules = atRules;
|
61
|
+
this.className = className;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
exports.CompiledRule = CompiledRule;
|
65
|
+
class CompiledRuleTuple2 extends Rule {
|
66
|
+
constructor(rule1, rule2) {
|
67
|
+
super();
|
68
|
+
this.rules = [rule1, rule2];
|
69
|
+
}
|
70
|
+
}
|
71
|
+
exports.CompiledRuleTuple2 = CompiledRuleTuple2;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.defaultOptions = void 0;
|
7
|
+
/**
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
9
|
+
*
|
10
|
+
* This source code is licensed under the MIT license found in the
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
12
|
+
*
|
13
|
+
*/
|
14
|
+
|
15
|
+
// {
|
16
|
+
// ...options,
|
17
|
+
// dev: !!(options as any).dev,
|
18
|
+
// test: !!(options as any).test,
|
19
|
+
// stylexSheetName: (options as any).stylexSheetName ?? undefined,
|
20
|
+
// classNamePrefix: (options as any).classNamePrefix ?? 'x',
|
21
|
+
// importSources: (options as any).importSources ?? [name, 'stylex'],
|
22
|
+
// definedStylexCSSVariables:
|
23
|
+
// (options as any).definedStylexCSSVariables ?? {},
|
24
|
+
// genConditionalClasses: !!(options as any).genConditionalClasses,
|
25
|
+
// skipShorthandExpansion: !!(options as any).skipShorthandExpansion,
|
26
|
+
// } as StyleXOptions;
|
27
|
+
|
28
|
+
const defaultOptions = {
|
29
|
+
dev: false,
|
30
|
+
test: false,
|
31
|
+
classNamePrefix: 'x',
|
32
|
+
styleResolution: 'application-order'
|
33
|
+
};
|
34
|
+
exports.defaultOptions = defaultOptions;
|
package/lib/utils/genCSSRule.js
CHANGED
@@ -13,12 +13,13 @@
|
|
13
13
|
Object.defineProperty(exports, "__esModule", {
|
14
14
|
value: true
|
15
15
|
});
|
16
|
-
exports.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
exports.genCSSRule = genCSSRule;
|
17
|
+
const THUMB_VARIANTS = ['::-webkit-slider-thumb', '::-moz-range-thumb', '::-ms-thumb'];
|
18
|
+
function genCSSRule(className, decls, pseudos, atRules) {
|
19
|
+
const pseudo = pseudos.filter(p => p !== '::thumb').join('');
|
20
|
+
let selectorForAtRules = `.${className}` + atRules.map(() => `.${className}`).join('') + pseudo;
|
21
|
+
if (pseudos.includes('::thumb')) {
|
22
|
+
selectorForAtRules = THUMB_VARIANTS.map(suffix => selectorForAtRules + suffix).join(', ');
|
21
23
|
}
|
22
|
-
return
|
23
|
-
}
|
24
|
-
const THUMB_VARIANTS = ['::-webkit-slider-thumb', '::-moz-range-thumb', '::-ms-thumb'];
|
24
|
+
return atRules.reduce((acc, atRule) => `${atRule}{${acc}}`, `${selectorForAtRules}{${decls}}`);
|
25
|
+
}
|
@@ -27,6 +27,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
27
27
|
// changes 500ms to 0.5s, then `LeadingZero` makes it .5s
|
28
28
|
const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _zeroDimensions.default, _leadingZero.default, _quotes.default, _fontSizePxToRem.default];
|
29
29
|
function normalizeValue(value, key) {
|
30
|
+
if (value == null) {
|
31
|
+
return value;
|
32
|
+
}
|
30
33
|
const parsedAST = (0, _postcssValueParser.default)(value);
|
31
34
|
return normalizers.reduce((ast, fn) => fn(ast, key), parsedAST).toString();
|
32
35
|
}
|
@@ -3,8 +3,9 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.Pipe = void 0;
|
6
|
+
exports.arraySort = exports.arrayEquals = exports.Pipe = void 0;
|
7
7
|
exports.flattenObject = flattenObject;
|
8
|
+
exports.isPlainObject = isPlainObject;
|
8
9
|
exports.objEntries = objEntries;
|
9
10
|
exports.objFromEntries = objFromEntries;
|
10
11
|
exports.objMap = objMap;
|
@@ -23,6 +24,9 @@ var _stylexInclude = require("../stylex-include");
|
|
23
24
|
|
24
25
|
// A bunch of object utils with better Flow types
|
25
26
|
|
27
|
+
function isPlainObject(obj) {
|
28
|
+
return typeof obj === 'object' && obj != null && !Array.isArray(obj) && (obj === null || obj === void 0 ? void 0 : obj.constructor) === Object;
|
29
|
+
}
|
26
30
|
function flattenObject(obj) {
|
27
31
|
const result = {};
|
28
32
|
for (const [key, value] of objEntries(obj)) {
|
@@ -91,4 +95,21 @@ class Pipe {
|
|
91
95
|
return new Pipe(val);
|
92
96
|
}
|
93
97
|
}
|
94
|
-
|
98
|
+
|
99
|
+
// Function that sorts an array without mutating it and returns a new array
|
100
|
+
exports.Pipe = Pipe;
|
101
|
+
const arraySort = (arr, fn) => [...arr].sort(fn);
|
102
|
+
exports.arraySort = arraySort;
|
103
|
+
const arrayEquals = function (arr1, arr2) {
|
104
|
+
let equals = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (a, b) => a === b;
|
105
|
+
if (arr1.length !== arr2.length) {
|
106
|
+
return false;
|
107
|
+
}
|
108
|
+
for (let i = 0; i < arr1.length; i++) {
|
109
|
+
if (!equals(arr1[i], arr2[i])) {
|
110
|
+
return false;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
return true;
|
114
|
+
};
|
115
|
+
exports.arrayEquals = arrayEquals;
|