@stylexjs/shared 0.1.0-beta.5 → 0.1.0-beta.7
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/index.d.ts +4 -2
- package/lib/stylex-create.js +20 -8
- package/lib/stylex-defaultValue.js +265 -0
- package/lib/utils/object-utils.js +1 -1
- package/package.json +1 -1
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 };
|
package/lib/stylex-create.js
CHANGED
@@ -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];
|
@@ -88,7 +92,7 @@ function styleXCreateNamespace(style, options) {
|
|
88
92
|
return (0, _expandShorthands.default)([innerKey, innerValue]);
|
89
93
|
}))]];
|
90
94
|
} else {
|
91
|
-
if (typeof value !== 'string' && typeof value !== 'number' && !Array.isArray(value)) {
|
95
|
+
if (value !== null && typeof value !== 'string' && typeof value !== 'number' && !Array.isArray(value)) {
|
92
96
|
throw new Error(messages.ILLEGAL_PROP_VALUE);
|
93
97
|
}
|
94
98
|
if (Array.isArray(value) && value.some(val => typeof val === 'object')) {
|
@@ -112,15 +116,23 @@ function styleXCreateNamespace(style, options) {
|
|
112
116
|
const pseudo = key;
|
113
117
|
const innerObj = {};
|
114
118
|
for (const [innerKey, innerVal] of (0, _objectUtils.objEntries)(val)) {
|
115
|
-
|
116
|
-
|
117
|
-
|
119
|
+
if (innerVal === null) {
|
120
|
+
innerObj[innerKey] = null;
|
121
|
+
} else {
|
122
|
+
const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([innerKey, innerVal], pseudo, options);
|
123
|
+
innerObj[updatedKey] = className;
|
124
|
+
injectedStyles[updatedKey + pseudo] = [className, cssRule];
|
125
|
+
}
|
118
126
|
}
|
119
127
|
resolvedNamespace[key] = innerObj;
|
120
128
|
} else {
|
121
|
-
|
122
|
-
|
123
|
-
|
129
|
+
if (val === null) {
|
130
|
+
resolvedNamespace[key] = null;
|
131
|
+
} else {
|
132
|
+
const [updatedKey, className, cssRule] = (0, _convertToClassName.default)([key, val], undefined, options);
|
133
|
+
resolvedNamespace[updatedKey] = className;
|
134
|
+
injectedStyles[updatedKey] = [className, cssRule];
|
135
|
+
}
|
124
136
|
}
|
125
137
|
}
|
126
138
|
const finalInjectedStyles = (0, _objectUtils.objFromEntries)((0, _objectUtils.objValues)(injectedStyles));
|
@@ -0,0 +1,265 @@
|
|
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 _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
14
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
15
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
16
|
+
var _set = /*#__PURE__*/new WeakSet();
|
17
|
+
class StylexValueBuilder {
|
18
|
+
constructor(defaultValue) {
|
19
|
+
_classPrivateMethodInitSpec(this, _set);
|
20
|
+
this.default = defaultValue;
|
21
|
+
}
|
22
|
+
// @media Queries
|
23
|
+
|
24
|
+
mediaPrint(value) {
|
25
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media print', value);
|
26
|
+
}
|
27
|
+
mediaWidth(_ref, value) {
|
28
|
+
let [min, max] = _ref;
|
29
|
+
if (min > 0 && max < Infinity) {
|
30
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-width: ${min}px and max-width: ${max}px)`, value);
|
31
|
+
} else if (min === 0) {
|
32
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (max-width: ${max}px)`, value);
|
33
|
+
} else if (max === Infinity) {
|
34
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-width: ${min}px)`, value);
|
35
|
+
}
|
36
|
+
throw new Error(messages.INVALID_MEDIA_QUERY);
|
37
|
+
}
|
38
|
+
mediaHeight(_ref2, value) {
|
39
|
+
let [min, max] = _ref2;
|
40
|
+
if (min > 0 && max < Infinity) {
|
41
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-height: ${min}px and max-height: ${max}px)`, value);
|
42
|
+
} else if (min === 0) {
|
43
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (max-height: ${max}px)`, value);
|
44
|
+
} else if (max === Infinity) {
|
45
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-height: ${min}px)`, value);
|
46
|
+
}
|
47
|
+
throw new Error(messages.INVALID_MEDIA_QUERY);
|
48
|
+
}
|
49
|
+
mediaAspectRatio(_ref3, value) {
|
50
|
+
let [min, max] = _ref3;
|
51
|
+
if (min > 0 && max < Infinity) {
|
52
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-aspect-ratio: ${min} and max-aspect-ratio: $, })`, value);
|
53
|
+
} else if (min === 0) {
|
54
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (max-aspect-ratio: ${max})`, value);
|
55
|
+
} else if (max === Infinity) {
|
56
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media (min-aspect-ratio: ${min})`, value);
|
57
|
+
}
|
58
|
+
throw new Error(messages.INVALID_MEDIA_QUERY);
|
59
|
+
}
|
60
|
+
mediaPortrait(value) {
|
61
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (orientation: portrait)', value);
|
62
|
+
}
|
63
|
+
mediaLandscape(value) {
|
64
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (orientation: landscape)', value);
|
65
|
+
}
|
66
|
+
mediaSRGBDisplay(value) {
|
67
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (color-gamut: srgb)', value);
|
68
|
+
}
|
69
|
+
mediaP3Display(value) {
|
70
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (color-gamut: p3)', value);
|
71
|
+
}
|
72
|
+
mediaRec2020Display(value) {
|
73
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (color-gamut: rec2020)', value);
|
74
|
+
}
|
75
|
+
mediaIsFullscreen(value) {
|
76
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (display-mode: fullscreen)', value);
|
77
|
+
}
|
78
|
+
|
79
|
+
// These are confusing, so skipping them for now
|
80
|
+
// mediaIsStandalone
|
81
|
+
// mediaIsMinimalUI
|
82
|
+
|
83
|
+
mediaSDRDisplay(value) {
|
84
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (dynamic-range: standard)', value);
|
85
|
+
}
|
86
|
+
mediaHDRDisplay(value) {
|
87
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (dynamic-range: high)', value);
|
88
|
+
}
|
89
|
+
mediaSupportsHDRVideo(value) {
|
90
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (video-dynamic-range: high)', value);
|
91
|
+
}
|
92
|
+
|
93
|
+
//<TAddedValue> mediaHasColor(value: TAddedValue): StylexValueBuilder<TValue | TAddedValue> {
|
94
|
+
// return this.#set('@media (color)', value);
|
95
|
+
// }
|
96
|
+
|
97
|
+
primaryInputCanHover(value) {
|
98
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (hover: hover)', value);
|
99
|
+
}
|
100
|
+
primaryInputCanNotHover(value) {
|
101
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (hover: none)', value);
|
102
|
+
}
|
103
|
+
someInputCanHover(value) {
|
104
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (any-hover: hover)', value);
|
105
|
+
}
|
106
|
+
noInputCanHover(value) {
|
107
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (any-hover: none)', value);
|
108
|
+
}
|
109
|
+
somePointerIsFine(value) {
|
110
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (any-pointer: fine)', value);
|
111
|
+
}
|
112
|
+
somePointerIsCoarse(value) {
|
113
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (any-pointer: coarse)', value);
|
114
|
+
}
|
115
|
+
primaryPointerIsFine(value) {
|
116
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (pointer: fine)', value);
|
117
|
+
}
|
118
|
+
primaryPointerIsCoarse(value) {
|
119
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (pointer: coarse)', value);
|
120
|
+
}
|
121
|
+
lightMode(value) {
|
122
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (prefers-color-scheme: light)', value);
|
123
|
+
}
|
124
|
+
darkMode(value) {
|
125
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (prefers-color-scheme: dark)', value);
|
126
|
+
}
|
127
|
+
userPrefersMoreContrast(value) {
|
128
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (prefers-contrast: more)', value);
|
129
|
+
}
|
130
|
+
userPrefersLessContrast(value) {
|
131
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (prefers-contrast: less)', value);
|
132
|
+
}
|
133
|
+
userPrefersReducedMotion(value) {
|
134
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (prefers-reduced-motion)', value);
|
135
|
+
}
|
136
|
+
noScript(value) {
|
137
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, '@media (scripting: none)', value);
|
138
|
+
}
|
139
|
+
matchMediaUNSAFE(query, value) {
|
140
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@media ${query}`, value);
|
141
|
+
}
|
142
|
+
supports(selector, value) {
|
143
|
+
const toSelector = _ref4 => {
|
144
|
+
let [k, v] = _ref4;
|
145
|
+
return `(${(0, _dashify.default)(k)}: ${String(v)})`;
|
146
|
+
};
|
147
|
+
const query = Object.entries(selector).map(toSelector).join(' and ');
|
148
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@supports ${query}`, value);
|
149
|
+
}
|
150
|
+
supportsNot(selector, value) {
|
151
|
+
const toSelector = _ref5 => {
|
152
|
+
let [k, v] = _ref5;
|
153
|
+
return `(not (${(0, _dashify.default)(k)}: ${String(v)}))`;
|
154
|
+
};
|
155
|
+
const query = Object.entries(selector).map(toSelector).join(' and ');
|
156
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `@supports ${query}`, value);
|
157
|
+
}
|
158
|
+
|
159
|
+
// Pseudo Classes
|
160
|
+
|
161
|
+
hover(value) {
|
162
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':hover', value);
|
163
|
+
}
|
164
|
+
focus(value) {
|
165
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':focus', value);
|
166
|
+
}
|
167
|
+
focusVisible(value) {
|
168
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':focus-visible', value);
|
169
|
+
}
|
170
|
+
focusWithin(value) {
|
171
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':focus-within', value);
|
172
|
+
}
|
173
|
+
active(value) {
|
174
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':active', value);
|
175
|
+
}
|
176
|
+
anyLink(value) {
|
177
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':any-link', value);
|
178
|
+
}
|
179
|
+
autofill(value) {
|
180
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':autofill', value);
|
181
|
+
}
|
182
|
+
checked(value) {
|
183
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':checked', value);
|
184
|
+
}
|
185
|
+
defaultSelection(value) {
|
186
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':default', value);
|
187
|
+
}
|
188
|
+
disabled(value) {
|
189
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':disabled', value);
|
190
|
+
}
|
191
|
+
empty(value) {
|
192
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':empty', value);
|
193
|
+
}
|
194
|
+
enabled(value) {
|
195
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':enabled', value);
|
196
|
+
}
|
197
|
+
fullscreen(value) {
|
198
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':fullscreen', value);
|
199
|
+
}
|
200
|
+
indeterminate(value) {
|
201
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':indeterminate', value);
|
202
|
+
}
|
203
|
+
invalid(value) {
|
204
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':invalid', value);
|
205
|
+
}
|
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
|
+
lang(value) {
|
213
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':lang', value);
|
214
|
+
}
|
215
|
+
dirRTLUNSFAE(value) {
|
216
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':dir(rtl)', value);
|
217
|
+
}
|
218
|
+
link(value) {
|
219
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':link', value);
|
220
|
+
}
|
221
|
+
optional(value) {
|
222
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':optional', value);
|
223
|
+
}
|
224
|
+
pictureInPicture(value) {
|
225
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':picture-in-picture', value);
|
226
|
+
}
|
227
|
+
placeholderShown(value) {
|
228
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':placeholder-shown', value);
|
229
|
+
}
|
230
|
+
paused(value) {
|
231
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':paused', value);
|
232
|
+
}
|
233
|
+
playing(value) {
|
234
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':playing', value);
|
235
|
+
}
|
236
|
+
readOnly(value) {
|
237
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':read-only', value);
|
238
|
+
}
|
239
|
+
readWrite(value) {
|
240
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':read-write', value);
|
241
|
+
}
|
242
|
+
required(value) {
|
243
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':required', value);
|
244
|
+
}
|
245
|
+
target(value) {
|
246
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':target', value);
|
247
|
+
}
|
248
|
+
valid(value) {
|
249
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':valid', value);
|
250
|
+
}
|
251
|
+
visited(value) {
|
252
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, ':visited', value);
|
253
|
+
}
|
254
|
+
pseudoUNSAFE(selector, value) {
|
255
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, `:${selector}`, value);
|
256
|
+
}
|
257
|
+
}
|
258
|
+
exports.StylexValueBuilder = StylexValueBuilder;
|
259
|
+
function _set2(key, value) {
|
260
|
+
this[key] = value;
|
261
|
+
return this;
|
262
|
+
}
|
263
|
+
function stylexDefaultValue(value) {
|
264
|
+
return new StylexValueBuilder(value);
|
265
|
+
}
|
@@ -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