@stylexjs/babel-plugin 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -4
- package/flow_modules/@babel/core/index.js.flow +6 -6
- package/flow_modules/@babel/helper-module-imports/index.js.flow +182 -0
- package/flow_modules/@babel/traverse/index.js.flow +7 -6
- package/lib/index.d.ts +15 -2
- package/lib/index.js +535 -515
- package/lib/index.js.flow +18 -2
- package/lib/utils/state-manager.d.ts +52 -15
- package/lib/utils/state-manager.js.flow +22 -7
- package/package.json +7 -10
- package/lib/visitors/stylex-override-vars.d.ts +0 -17
- package/lib/visitors/stylex-override-vars.js.flow +0 -23
package/lib/index.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var t = require('@babel/types');
|
|
4
4
|
var path = require('path');
|
|
5
|
+
var helperModuleImports = require('@babel/helper-module-imports');
|
|
5
6
|
var require$$0 = require('postcss-value-parser');
|
|
6
7
|
var core = require('@babel/core');
|
|
7
8
|
var traverse = require('@babel/traverse');
|
|
8
|
-
var require$$0$1 = require('
|
|
9
|
-
var require$$1 = require('styleq');
|
|
9
|
+
var require$$0$1 = require('styleq');
|
|
10
10
|
|
|
11
11
|
function _interopNamespaceDefault(e) {
|
|
12
12
|
var n = Object.create(null);
|
|
@@ -29,6 +29,7 @@ var t__namespace = /*#__PURE__*/_interopNamespaceDefault(t);
|
|
|
29
29
|
|
|
30
30
|
var name = "@stylexjs/stylex";
|
|
31
31
|
|
|
32
|
+
const DEFAULT_INJECT_PATH = '@stylexjs/stylex/lib/stylex-inject';
|
|
32
33
|
class StateManager {
|
|
33
34
|
importPaths = new Set();
|
|
34
35
|
stylexImport = new Set();
|
|
@@ -40,6 +41,7 @@ class StateManager {
|
|
|
40
41
|
stylexDefineVarsImport = new Set();
|
|
41
42
|
stylexCreateThemeImport = new Set();
|
|
42
43
|
stylexTypesImport = new Set();
|
|
44
|
+
injectImportInserted = null;
|
|
43
45
|
styleMap = new Map();
|
|
44
46
|
styleVars = new Map();
|
|
45
47
|
styleVarsToKeep = new Set();
|
|
@@ -54,9 +56,9 @@ class StateManager {
|
|
|
54
56
|
...options,
|
|
55
57
|
dev: !!options.dev,
|
|
56
58
|
test: !!options.test,
|
|
57
|
-
runtimeInjection: options.runtimeInjection
|
|
59
|
+
runtimeInjection: options.runtimeInjection === true ? DEFAULT_INJECT_PATH : options.runtimeInjection ? options.runtimeInjection : options.dev ? DEFAULT_INJECT_PATH : undefined,
|
|
58
60
|
classNamePrefix: options.classNamePrefix ?? 'x',
|
|
59
|
-
importSources: options.importSources ?? [
|
|
61
|
+
importSources: [name, 'stylex', ...(options.importSources ?? [])],
|
|
60
62
|
definedStylexCSSVariables: options.definedStylexCSSVariables ?? {},
|
|
61
63
|
genConditionalClasses: !!options.genConditionalClasses,
|
|
62
64
|
useRemForFontSize: !!options.useRemForFontSize,
|
|
@@ -76,6 +78,17 @@ class StateManager {
|
|
|
76
78
|
}
|
|
77
79
|
return '@stylexjs/stylex';
|
|
78
80
|
}
|
|
81
|
+
get importSources() {
|
|
82
|
+
return this.options.importSources.map(source => typeof source === 'string' ? source : source.from);
|
|
83
|
+
}
|
|
84
|
+
importAs(source) {
|
|
85
|
+
for (const importSource of this.options.importSources) {
|
|
86
|
+
if (typeof importSource !== 'string' && importSource.from === source) {
|
|
87
|
+
return importSource.as;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
79
92
|
get canReferenceTheme() {
|
|
80
93
|
return !!this.inStyleXCreate;
|
|
81
94
|
}
|
|
@@ -83,7 +96,9 @@ class StateManager {
|
|
|
83
96
|
return this._state.file.metadata;
|
|
84
97
|
}
|
|
85
98
|
get runtimeInjection() {
|
|
86
|
-
return
|
|
99
|
+
return typeof this.options.runtimeInjection === 'string' ? {
|
|
100
|
+
from: this.options.runtimeInjection
|
|
101
|
+
} : this.options.runtimeInjection || null;
|
|
87
102
|
}
|
|
88
103
|
get isDev() {
|
|
89
104
|
return !!this.options.dev;
|
|
@@ -197,66 +212,51 @@ function readImportDeclarations(path, state) {
|
|
|
197
212
|
if (node?.importKind === 'type' || node?.importKind === 'typeof') {
|
|
198
213
|
return;
|
|
199
214
|
}
|
|
200
|
-
|
|
201
|
-
|
|
215
|
+
const sourcePath = node.source.value;
|
|
216
|
+
if (state.importSources.includes(sourcePath)) {
|
|
202
217
|
for (const specifier of node.specifiers) {
|
|
203
|
-
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
218
|
+
if (specifier.type === 'ImportDefaultSpecifier' && state.importAs(sourcePath) === null) {
|
|
219
|
+
state.importPaths.add(sourcePath);
|
|
204
220
|
state.stylexImport.add(specifier.local.name);
|
|
205
221
|
}
|
|
206
|
-
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
222
|
+
if (specifier.type === 'ImportNamespaceSpecifier' && state.importAs(sourcePath) === null) {
|
|
223
|
+
state.importPaths.add(sourcePath);
|
|
207
224
|
state.stylexImport.add(specifier.local.name);
|
|
208
225
|
}
|
|
209
226
|
if (specifier.type === 'ImportSpecifier') {
|
|
210
|
-
if (specifier.imported.type === 'Identifier') {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
state.
|
|
216
|
-
}
|
|
217
|
-
if (specifier.imported.name === 'keyframes') {
|
|
218
|
-
state.stylexKeyframesImport.add(specifier.local.name);
|
|
219
|
-
}
|
|
220
|
-
if (specifier.imported.name === 'include') {
|
|
221
|
-
state.stylexIncludeImport.add(specifier.local.name);
|
|
222
|
-
}
|
|
223
|
-
if (specifier.imported.name === 'firstThatWorks') {
|
|
224
|
-
state.stylexFirstThatWorksImport.add(specifier.local.name);
|
|
225
|
-
}
|
|
226
|
-
if (specifier.imported.name === 'defineVars') {
|
|
227
|
-
state.stylexDefineVarsImport.add(specifier.local.name);
|
|
228
|
-
}
|
|
229
|
-
if (specifier.imported.name === 'createTheme') {
|
|
230
|
-
state.stylexCreateThemeImport.add(specifier.local.name);
|
|
227
|
+
if (specifier.imported.type === 'Identifier' || specifier.imported.type === 'StringLiteral') {
|
|
228
|
+
const importedName = specifier.imported.type === 'Identifier' ? specifier.imported.name : specifier.imported.value;
|
|
229
|
+
const localName = specifier.local.name;
|
|
230
|
+
if (state.importAs(sourcePath) === importedName) {
|
|
231
|
+
state.importPaths.add(sourcePath);
|
|
232
|
+
state.stylexImport.add(localName);
|
|
231
233
|
}
|
|
232
|
-
if (
|
|
233
|
-
state.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (specifier.imported.value === 'types ') {
|
|
259
|
-
state.stylexTypesImport.add(specifier.local.name);
|
|
234
|
+
if (state.importAs(sourcePath) === null) {
|
|
235
|
+
state.importPaths.add(sourcePath);
|
|
236
|
+
if (importedName === 'create') {
|
|
237
|
+
state.stylexCreateImport.add(localName);
|
|
238
|
+
}
|
|
239
|
+
if (importedName === 'props') {
|
|
240
|
+
state.stylexPropsImport.add(localName);
|
|
241
|
+
}
|
|
242
|
+
if (importedName === 'keyframes') {
|
|
243
|
+
state.stylexKeyframesImport.add(localName);
|
|
244
|
+
}
|
|
245
|
+
if (importedName === 'include') {
|
|
246
|
+
state.stylexIncludeImport.add(localName);
|
|
247
|
+
}
|
|
248
|
+
if (importedName === 'firstThatWorks') {
|
|
249
|
+
state.stylexFirstThatWorksImport.add(localName);
|
|
250
|
+
}
|
|
251
|
+
if (importedName === 'defineVars') {
|
|
252
|
+
state.stylexDefineVarsImport.add(localName);
|
|
253
|
+
}
|
|
254
|
+
if (importedName === 'createTheme') {
|
|
255
|
+
state.stylexCreateThemeImport.add(localName);
|
|
256
|
+
}
|
|
257
|
+
if (importedName === 'types') {
|
|
258
|
+
state.stylexTypesImport.add(localName);
|
|
259
|
+
}
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
}
|
|
@@ -268,9 +268,12 @@ function readRequires(path, state) {
|
|
|
268
268
|
node
|
|
269
269
|
} = path;
|
|
270
270
|
const init = node.init;
|
|
271
|
-
if (init != null && init.type === 'CallExpression' && init.callee?.type === 'Identifier' && init.callee?.name === 'require' && init.arguments?.length === 1 && init.arguments?.[0].type === 'StringLiteral' && state.
|
|
271
|
+
if (init != null && init.type === 'CallExpression' && init.callee?.type === 'Identifier' && init.callee?.name === 'require' && init.arguments?.length === 1 && init.arguments?.[0].type === 'StringLiteral' && state.importSources.includes(init.arguments[0].value)) {
|
|
272
272
|
const importPath = init.arguments[0].value;
|
|
273
|
-
importPath
|
|
273
|
+
if (importPath == null) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
state.importPaths.add(importPath);
|
|
274
277
|
if (node.id.type === 'Identifier') {
|
|
275
278
|
state.stylexImport.add(node.id.name);
|
|
276
279
|
}
|
|
@@ -321,13 +324,16 @@ var messages$3 = {};
|
|
|
321
324
|
Object.defineProperty(messages$3, "__esModule", {
|
|
322
325
|
value: true
|
|
323
326
|
});
|
|
324
|
-
messages$3.UNKNOWN_PROP_KEY = messages$3.UNKNOWN_NAMESPACE = messages$3.UNEXPECTED_ARGUMENT = messages$3.UNBOUND_STYLEX_CALL_VALUE = messages$3.
|
|
325
|
-
messages$3.ILLEGAL_ARGUMENT_LENGTH = 'stylex() should have 1 argument.';
|
|
327
|
+
messages$3.UNKNOWN_PROP_KEY = messages$3.UNKNOWN_NAMESPACE = messages$3.UNEXPECTED_ARGUMENT = messages$3.UNBOUND_STYLEX_CALL_VALUE = messages$3.ONLY_TOP_LEVEL_INCLUDES = messages$3.ONLY_TOP_LEVEL = messages$3.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = messages$3.NO_PROJECT_ROOT_DIRECTORY = messages$3.NO_PARENT_PATH = messages$3.NO_CONDITIONAL_SHORTHAND = messages$3.NON_STATIC_VALUE = messages$3.NON_STATIC_KEYFRAME_VALUE = messages$3.NON_OBJECT_KEYFRAME = messages$3.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = messages$3.NON_OBJECT_FOR_STYLEX_CALL = messages$3.NON_EXPORT_NAMED_DECLARATION = messages$3.LOCAL_ONLY = messages$3.LINT_UNCLOSED_FUNCTION = messages$3.INVALID_SPREAD = messages$3.INVALID_PSEUDO_OR_AT_RULE = messages$3.INVALID_PSEUDO = messages$3.ILLEGAL_PROP_VALUE = messages$3.ILLEGAL_PROP_ARRAY_VALUE = messages$3.ILLEGAL_NESTED_PSEUDO = messages$3.ILLEGAL_NAMESPACE_VALUE = messages$3.ILLEGAL_NAMESPACE_TYPE = messages$3.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = messages$3.ILLEGAL_ARGUMENT_LENGTH = messages$3.EXPECTED_FUNCTION_CALL = messages$3.ESCAPED_STYLEX_VALUE = messages$3.DUPLICATE_CONDITIONAL = messages$3.ANONYMOUS_THEME = void 0;
|
|
328
|
+
messages$3.ILLEGAL_ARGUMENT_LENGTH = 'stylex.create() should have 1 argument.';
|
|
329
|
+
messages$3.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = 'stylex.keyframes() should have 1 argument.';
|
|
326
330
|
messages$3.NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
|
|
331
|
+
messages$3.NON_STATIC_KEYFRAME_VALUE = 'Only static values are allowed inside of a stylex.keyframes() call.';
|
|
327
332
|
messages$3.ESCAPED_STYLEX_VALUE = 'Escaping a stylex.create() value is not allowed.';
|
|
328
333
|
messages$3.UNBOUND_STYLEX_CALL_VALUE = 'stylex.create calls must be bound to a bare variable.';
|
|
329
334
|
messages$3.ONLY_TOP_LEVEL = 'stylex.create() is only allowed at the root of a program.';
|
|
330
335
|
messages$3.NON_OBJECT_FOR_STYLEX_CALL = 'stylex.create() can only accept a style object.';
|
|
336
|
+
messages$3.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = 'stylex.keyframes() can only accept an object.';
|
|
331
337
|
messages$3.UNKNOWN_PROP_KEY = 'Unknown property key';
|
|
332
338
|
messages$3.INVALID_PSEUDO = 'Invalid pseudo selector, not on the whitelist.';
|
|
333
339
|
messages$3.INVALID_PSEUDO_OR_AT_RULE = 'Invalid pseudo or at-rule.';
|
|
@@ -338,17 +344,19 @@ messages$3.ILLEGAL_NESTED_PSEUDO = "Pseudo objects can't be nested more than one
|
|
|
338
344
|
messages$3.ILLEGAL_PROP_VALUE = 'A style value can only contain an array, string or number.';
|
|
339
345
|
messages$3.ILLEGAL_PROP_ARRAY_VALUE = 'A style array value can only contain strings or numbers.';
|
|
340
346
|
messages$3.ILLEGAL_NAMESPACE_VALUE = 'A stylex namespace must be an object.';
|
|
347
|
+
messages$3.NON_OBJECT_KEYFRAME = 'Every frame within a stylex.keyframes() call must be an object.';
|
|
341
348
|
messages$3.INVALID_SPREAD = 'Imported styles spread with a stylex.create call must be type cast as `XStyle<>` to verify their type.';
|
|
342
349
|
messages$3.LINT_UNCLOSED_FUNCTION = 'Rule contains an unclosed function';
|
|
343
350
|
messages$3.LOCAL_ONLY = 'The return value of stylex.create() should not be exported.';
|
|
344
351
|
messages$3.UNEXPECTED_ARGUMENT = 'Unexpected argument passed to the stylex() function.';
|
|
345
352
|
messages$3.EXPECTED_FUNCTION_CALL = 'Expected a simple function call but found something else.';
|
|
346
353
|
messages$3.NO_PARENT_PATH = 'Unexpected AST node without a parent path.';
|
|
347
|
-
messages$3.
|
|
354
|
+
messages$3.ONLY_TOP_LEVEL_INCLUDES = 'stylex.include() is only at the top level of a style definition object.';
|
|
348
355
|
messages$3.DUPLICATE_CONDITIONAL = 'The same pseudo selector or at-rule cannot be used more than once.';
|
|
349
356
|
messages$3.NO_PROJECT_ROOT_DIRECTORY = 'The project root directory `rootDir` is not configured.';
|
|
350
357
|
messages$3.NON_EXPORT_NAMED_DECLARATION = 'The return value of stylex.defineVars() must be bound to a named export.';
|
|
351
358
|
messages$3.ANONYMOUS_THEME = 'stylex.createTheme() must be bound to a named constant.';
|
|
359
|
+
messages$3.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
|
|
352
360
|
|
|
353
361
|
Object.defineProperty(stylexInclude$2, "__esModule", {
|
|
354
362
|
value: true
|
|
@@ -356,8 +364,8 @@ Object.defineProperty(stylexInclude$2, "__esModule", {
|
|
|
356
364
|
stylexInclude$2.IncludedStyles = void 0;
|
|
357
365
|
stylexInclude$2.default = stylexInclude$1;
|
|
358
366
|
var messages$2 = _interopRequireWildcard$3(messages$3);
|
|
359
|
-
function _getRequireWildcardCache$3(
|
|
360
|
-
function _interopRequireWildcard$3(
|
|
367
|
+
function _getRequireWildcardCache$3(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache$3 = function (e) { return e ? t : r; })(e); }
|
|
368
|
+
function _interopRequireWildcard$3(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache$3(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
361
369
|
let number = 0;
|
|
362
370
|
function uuid() {
|
|
363
371
|
return `__included_${++number}__`;
|
|
@@ -486,7 +494,6 @@ Object.defineProperty(defaultOptions, "__esModule", {
|
|
|
486
494
|
defaultOptions.defaultOptions = void 0;
|
|
487
495
|
defaultOptions.defaultOptions = {
|
|
488
496
|
dev: false,
|
|
489
|
-
runtimeInjection: false,
|
|
490
497
|
useRemForFontSize: true,
|
|
491
498
|
test: false,
|
|
492
499
|
classNamePrefix: 'x',
|
|
@@ -499,46 +506,10 @@ var preprocessRules = {};
|
|
|
499
506
|
|
|
500
507
|
var applicationOrder = {};
|
|
501
508
|
|
|
502
|
-
var splitCssValue = {};
|
|
503
|
-
|
|
504
|
-
Object.defineProperty(splitCssValue, "__esModule", {
|
|
505
|
-
value: true
|
|
506
|
-
});
|
|
507
|
-
splitCssValue.default = splitValue;
|
|
508
|
-
var _postcssValueParser$6 = _interopRequireDefault$k(require$$0);
|
|
509
|
-
function _interopRequireDefault$k(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
510
|
-
function printNode(node) {
|
|
511
|
-
switch (node.type) {
|
|
512
|
-
case 'word':
|
|
513
|
-
case 'string':
|
|
514
|
-
return `${node.value}`;
|
|
515
|
-
case 'function':
|
|
516
|
-
return `${node.value}(${node.nodes.map(printNode).join('')})`;
|
|
517
|
-
default:
|
|
518
|
-
return node.value;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
function splitValue(str) {
|
|
522
|
-
if (str == null || typeof str === 'number') {
|
|
523
|
-
return [str];
|
|
524
|
-
}
|
|
525
|
-
if (Array.isArray(str)) {
|
|
526
|
-
return str;
|
|
527
|
-
}
|
|
528
|
-
const parsed = (0, _postcssValueParser$6.default)(str.trim());
|
|
529
|
-
const nodes = parsed.nodes.filter(node => node.type !== 'space' && node.type !== 'div').map(printNode);
|
|
530
|
-
if (nodes.length > 1 && nodes[nodes.length - 1].toLowerCase() === '!important') {
|
|
531
|
-
return nodes.slice(0, nodes.length - 1).map(node => node + ' !important');
|
|
532
|
-
}
|
|
533
|
-
return nodes;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
509
|
Object.defineProperty(applicationOrder, "__esModule", {
|
|
537
510
|
value: true
|
|
538
511
|
});
|
|
539
512
|
applicationOrder.default = void 0;
|
|
540
|
-
var _splitCssValue$1 = _interopRequireDefault$j(splitCssValue);
|
|
541
|
-
function _interopRequireDefault$j(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
542
513
|
const shorthands$2 = {
|
|
543
514
|
all: _ => {
|
|
544
515
|
throw new Error('all is not supported');
|
|
@@ -554,8 +525,8 @@ const shorthands$2 = {
|
|
|
554
525
|
borderInlineEnd: rawValue => [['borderInlineEnd', rawValue], ...shorthands$2.borderInlineEndWidth(null), ...shorthands$2.borderInlineEndStyle(null), ...shorthands$2.borderInlineEndColor(null)],
|
|
555
526
|
borderRight: rawValue => [['borderRight', rawValue], ...shorthands$2.borderRightWidth(null), ...shorthands$2.borderRightStyle(null), ...shorthands$2.borderRightColor(null)],
|
|
556
527
|
borderBottom: rawValue => [['borderBottom', rawValue], ['borderBottomWidth', null], ['borderBottomStyle', null], ['borderBottomColor', null]],
|
|
557
|
-
borderInlineStart:
|
|
558
|
-
borderLeft:
|
|
528
|
+
borderInlineStart: rawValue => [['borderInlineStart', rawValue], ...shorthands$2.borderInlineStartWidth(null), ...shorthands$2.borderInlineStartStyle(null), ...shorthands$2.borderInlineStartColor(null)],
|
|
529
|
+
borderLeft: rawValue => [['borderLeft', rawValue], ...shorthands$2.borderLeftWidth(null), ...shorthands$2.borderLeftStyle(null), ...shorthands$2.borderLeftColor(null)],
|
|
559
530
|
borderInlineWidth: rawValue => [['borderInlineWidth', rawValue], ['borderInlineStartWidth', null], ['borderLeftWidth', null], ['borderInlineEndWidth', null], ['borderRightWidth', null]],
|
|
560
531
|
borderInlineStyle: rawValue => [['borderInlineStyle', rawValue], ['borderInlineStartStyle', null], ['borderLeftStyle', null], ['borderInlineEndStyle', null], ['borderRightStyle', null]],
|
|
561
532
|
borderInlineColor: rawValue => [['borderInlineColor', rawValue], ['borderInlineStartColor', null], ['borderLeftColor', null], ['borderInlineEndColor', null], ['borderRightColor', null]],
|
|
@@ -622,12 +593,7 @@ const shorthands$2 = {
|
|
|
622
593
|
outline: value => [['outline', value], ['outlineColor', null], ['outlineOffset', null], ['outlineStyle', null], ['outlineWidth', null]],
|
|
623
594
|
overflow: value => [['overflow', value], ['overflowX', null], ['overflowY', null]],
|
|
624
595
|
padding: rawValue => {
|
|
625
|
-
|
|
626
|
-
if (values.length === 1) {
|
|
627
|
-
return [['padding', values[0]], ['paddingStart', null], ['paddingLeft', null], ['paddingEnd', null], ['paddingRight', null], ['paddingTop', null], ['paddingBottom', null]];
|
|
628
|
-
}
|
|
629
|
-
const [top, right = top, bottom = top, left = right] = values;
|
|
630
|
-
return [['paddingTop', top], ['paddingEnd', right], ['paddingBottom', bottom], ['paddingStart', left]];
|
|
596
|
+
return [['padding', rawValue], ...shorthands$2.paddingInline(null), ...shorthands$2.paddingBlock(null)];
|
|
631
597
|
},
|
|
632
598
|
paddingInline: rawValue => [['paddingInline', rawValue], ['paddingStart', null], ['paddingLeft', null], ['paddingEnd', null], ['paddingRight', null]],
|
|
633
599
|
paddingBlock: rawValue => [['paddingBlock', rawValue], ['paddingTop', null], ['paddingBottom', null]],
|
|
@@ -727,12 +693,46 @@ applicationOrder.default = expansions$3;
|
|
|
727
693
|
|
|
728
694
|
var legacyExpandShorthands = {};
|
|
729
695
|
|
|
696
|
+
var splitCssValue = {};
|
|
697
|
+
|
|
698
|
+
Object.defineProperty(splitCssValue, "__esModule", {
|
|
699
|
+
value: true
|
|
700
|
+
});
|
|
701
|
+
splitCssValue.default = splitValue;
|
|
702
|
+
var _postcssValueParser$6 = _interopRequireDefault$h(require$$0);
|
|
703
|
+
function _interopRequireDefault$h(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
704
|
+
function printNode(node) {
|
|
705
|
+
switch (node.type) {
|
|
706
|
+
case 'word':
|
|
707
|
+
case 'string':
|
|
708
|
+
return `${node.value}`;
|
|
709
|
+
case 'function':
|
|
710
|
+
return `${node.value}(${node.nodes.map(printNode).join('')})`;
|
|
711
|
+
default:
|
|
712
|
+
return node.value;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
function splitValue(str) {
|
|
716
|
+
if (str == null || typeof str === 'number') {
|
|
717
|
+
return [str];
|
|
718
|
+
}
|
|
719
|
+
if (Array.isArray(str)) {
|
|
720
|
+
return str;
|
|
721
|
+
}
|
|
722
|
+
const parsed = (0, _postcssValueParser$6.default)(str.trim());
|
|
723
|
+
const nodes = parsed.nodes.filter(node => node.type !== 'space' && node.type !== 'div').map(printNode);
|
|
724
|
+
if (nodes.length > 1 && nodes[nodes.length - 1].toLowerCase() === '!important') {
|
|
725
|
+
return nodes.slice(0, nodes.length - 1).map(node => node + ' !important');
|
|
726
|
+
}
|
|
727
|
+
return nodes;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
730
|
Object.defineProperty(legacyExpandShorthands, "__esModule", {
|
|
731
731
|
value: true
|
|
732
732
|
});
|
|
733
733
|
legacyExpandShorthands.default = void 0;
|
|
734
|
-
var _splitCssValue = _interopRequireDefault$
|
|
735
|
-
function _interopRequireDefault$
|
|
734
|
+
var _splitCssValue = _interopRequireDefault$g(splitCssValue);
|
|
735
|
+
function _interopRequireDefault$g(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
736
736
|
const shorthands$1 = {
|
|
737
737
|
border: rawValue => {
|
|
738
738
|
return [['borderTop', rawValue], ['borderEnd', rawValue], ['borderBottom', rawValue], ['borderStart', rawValue]];
|
|
@@ -975,10 +975,10 @@ Object.defineProperty(preprocessRules, "__esModule", {
|
|
|
975
975
|
});
|
|
976
976
|
preprocessRules.default = flatMapExpandedShorthands;
|
|
977
977
|
preprocessRules.getExpandedKeys = getExpandedKeys;
|
|
978
|
-
var _applicationOrder = _interopRequireDefault$
|
|
979
|
-
var _legacyExpandShorthands = _interopRequireDefault$
|
|
980
|
-
var _propertySpecificity = _interopRequireDefault$
|
|
981
|
-
function _interopRequireDefault$
|
|
978
|
+
var _applicationOrder = _interopRequireDefault$f(applicationOrder);
|
|
979
|
+
var _legacyExpandShorthands = _interopRequireDefault$f(legacyExpandShorthands);
|
|
980
|
+
var _propertySpecificity = _interopRequireDefault$f(propertySpecificity);
|
|
981
|
+
function _interopRequireDefault$f(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
982
982
|
const expansions = {
|
|
983
983
|
'application-order': _applicationOrder.default,
|
|
984
984
|
'property-specificity': _propertySpecificity.default,
|
|
@@ -1061,8 +1061,8 @@ Object.defineProperty(fontSizePxToRem, "__esModule", {
|
|
|
1061
1061
|
value: true
|
|
1062
1062
|
});
|
|
1063
1063
|
fontSizePxToRem.default = convertFontSizeToRem;
|
|
1064
|
-
var _postcssValueParser$5 = _interopRequireDefault$
|
|
1065
|
-
function _interopRequireDefault$
|
|
1064
|
+
var _postcssValueParser$5 = _interopRequireDefault$e(require$$0);
|
|
1065
|
+
function _interopRequireDefault$e(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1066
1066
|
const ROOT_FONT_SIZE = 16;
|
|
1067
1067
|
function convertFontSizeToRem(ast, key) {
|
|
1068
1068
|
if (key !== 'fontSize') {
|
|
@@ -1086,8 +1086,8 @@ Object.defineProperty(leadingZero, "__esModule", {
|
|
|
1086
1086
|
value: true
|
|
1087
1087
|
});
|
|
1088
1088
|
leadingZero.default = normalizeLeadingZero;
|
|
1089
|
-
var _postcssValueParser$4 = _interopRequireDefault$
|
|
1090
|
-
function _interopRequireDefault$
|
|
1089
|
+
var _postcssValueParser$4 = _interopRequireDefault$d(require$$0);
|
|
1090
|
+
function _interopRequireDefault$d(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1091
1091
|
function normalizeLeadingZero(ast, _) {
|
|
1092
1092
|
ast.walk(node => {
|
|
1093
1093
|
if (node.type !== 'word') {
|
|
@@ -1129,8 +1129,8 @@ Object.defineProperty(timings$1, "__esModule", {
|
|
|
1129
1129
|
value: true
|
|
1130
1130
|
});
|
|
1131
1131
|
timings$1.default = normalizeTimings;
|
|
1132
|
-
var _postcssValueParser$3 = _interopRequireDefault$
|
|
1133
|
-
function _interopRequireDefault$
|
|
1132
|
+
var _postcssValueParser$3 = _interopRequireDefault$c(require$$0);
|
|
1133
|
+
function _interopRequireDefault$c(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1134
1134
|
function normalizeTimings(ast, _) {
|
|
1135
1135
|
ast.walk(node => {
|
|
1136
1136
|
if (node.type !== 'word') {
|
|
@@ -1196,8 +1196,8 @@ Object.defineProperty(zeroDimensions, "__esModule", {
|
|
|
1196
1196
|
value: true
|
|
1197
1197
|
});
|
|
1198
1198
|
zeroDimensions.default = normalizeZeroDimensions;
|
|
1199
|
-
var _postcssValueParser$2 = _interopRequireDefault$
|
|
1200
|
-
function _interopRequireDefault$
|
|
1199
|
+
var _postcssValueParser$2 = _interopRequireDefault$b(require$$0);
|
|
1200
|
+
function _interopRequireDefault$b(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1201
1201
|
const angles = ['deg', 'grad', 'turn', 'rad'];
|
|
1202
1202
|
const timings = ['ms', 's'];
|
|
1203
1203
|
function normalizeZeroDimensions(ast, _) {
|
|
@@ -1227,8 +1227,8 @@ Object.defineProperty(detectUnclosedFns$1, "__esModule", {
|
|
|
1227
1227
|
});
|
|
1228
1228
|
detectUnclosedFns$1.default = detectUnclosedFns;
|
|
1229
1229
|
var messages$1 = _interopRequireWildcard$2(messages$3);
|
|
1230
|
-
function _getRequireWildcardCache$2(
|
|
1231
|
-
function _interopRequireWildcard$2(
|
|
1230
|
+
function _getRequireWildcardCache$2(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache$2 = function (e) { return e ? t : r; })(e); }
|
|
1231
|
+
function _interopRequireWildcard$2(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache$2(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
1232
1232
|
function detectUnclosedFns(ast, _) {
|
|
1233
1233
|
ast.walk(node => {
|
|
1234
1234
|
if (node.type === 'function' && node.unclosed) {
|
|
@@ -1244,8 +1244,8 @@ Object.defineProperty(convertCamelCaseValues, "__esModule", {
|
|
|
1244
1244
|
value: true
|
|
1245
1245
|
});
|
|
1246
1246
|
convertCamelCaseValues.default = convertCamelCasedValues;
|
|
1247
|
-
var _dashify$2 = _interopRequireDefault$
|
|
1248
|
-
function _interopRequireDefault$
|
|
1247
|
+
var _dashify$2 = _interopRequireDefault$a(dashify$1);
|
|
1248
|
+
function _interopRequireDefault$a(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1249
1249
|
function convertCamelCasedValues(ast, key) {
|
|
1250
1250
|
if (key !== 'transitionProperty' && key !== 'willChange') {
|
|
1251
1251
|
return ast;
|
|
@@ -1266,16 +1266,16 @@ Object.defineProperty(normalizeValue$1, "__esModule", {
|
|
|
1266
1266
|
value: true
|
|
1267
1267
|
});
|
|
1268
1268
|
normalizeValue$1.default = normalizeValue;
|
|
1269
|
-
var _fontSizePxToRem = _interopRequireDefault$
|
|
1270
|
-
var _leadingZero = _interopRequireDefault$
|
|
1271
|
-
var _quotes = _interopRequireDefault$
|
|
1272
|
-
var _timings = _interopRequireDefault$
|
|
1273
|
-
var _whitespace = _interopRequireDefault$
|
|
1274
|
-
var _zeroDimensions = _interopRequireDefault$
|
|
1275
|
-
var _detectUnclosedFns = _interopRequireDefault$
|
|
1276
|
-
var _postcssValueParser$1 = _interopRequireDefault$
|
|
1277
|
-
var _convertCamelCaseValues = _interopRequireDefault$
|
|
1278
|
-
function _interopRequireDefault$
|
|
1269
|
+
var _fontSizePxToRem = _interopRequireDefault$9(fontSizePxToRem);
|
|
1270
|
+
var _leadingZero = _interopRequireDefault$9(leadingZero);
|
|
1271
|
+
var _quotes = _interopRequireDefault$9(quotes);
|
|
1272
|
+
var _timings = _interopRequireDefault$9(timings$1);
|
|
1273
|
+
var _whitespace = _interopRequireDefault$9(whitespace);
|
|
1274
|
+
var _zeroDimensions = _interopRequireDefault$9(zeroDimensions);
|
|
1275
|
+
var _detectUnclosedFns = _interopRequireDefault$9(detectUnclosedFns$1);
|
|
1276
|
+
var _postcssValueParser$1 = _interopRequireDefault$9(require$$0);
|
|
1277
|
+
var _convertCamelCaseValues = _interopRequireDefault$9(convertCamelCaseValues);
|
|
1278
|
+
function _interopRequireDefault$9(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1279
1279
|
const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _zeroDimensions.default, _leadingZero.default, _quotes.default, _convertCamelCaseValues.default];
|
|
1280
1280
|
function normalizeValue(value, key, _ref) {
|
|
1281
1281
|
let {
|
|
@@ -1297,8 +1297,8 @@ Object.defineProperty(transformValue$1, "__esModule", {
|
|
|
1297
1297
|
transformValue$1.default = transformValue;
|
|
1298
1298
|
var getNumberSuffix_1 = transformValue$1.getNumberSuffix = getNumberSuffix;
|
|
1299
1299
|
var timeUnits_1 = transformValue$1.timeUnits = lengthUnits_1 = transformValue$1.lengthUnits = void 0;
|
|
1300
|
-
var _normalizeValue = _interopRequireDefault$
|
|
1301
|
-
function _interopRequireDefault$
|
|
1300
|
+
var _normalizeValue = _interopRequireDefault$8(normalizeValue$1);
|
|
1301
|
+
function _interopRequireDefault$8(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1302
1302
|
function transformValue(key, rawValue, options) {
|
|
1303
1303
|
const value = typeof rawValue === 'number' ? String(Math.round(rawValue * 10000) / 10000) + getNumberSuffix(key) : rawValue;
|
|
1304
1304
|
if ((key === 'content' || key === 'hyphenateCharacter' || key === 'hyphenate-character') && typeof value === 'string') {
|
|
@@ -1450,8 +1450,8 @@ Object.defineProperty(generateRtl, "__esModule", {
|
|
|
1450
1450
|
value: true
|
|
1451
1451
|
});
|
|
1452
1452
|
generateRtl.default = generateRTL;
|
|
1453
|
-
var _postcssValueParser = _interopRequireDefault$
|
|
1454
|
-
function _interopRequireDefault$
|
|
1453
|
+
var _postcssValueParser = _interopRequireDefault$7(require$$0);
|
|
1454
|
+
function _interopRequireDefault$7(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1455
1455
|
const cursorFlip = {
|
|
1456
1456
|
'e-resize': 'w-resize',
|
|
1457
1457
|
'w-resize': 'e-resize',
|
|
@@ -2181,11 +2181,11 @@ Object.defineProperty(generateCssRule, "__esModule", {
|
|
|
2181
2181
|
value: true
|
|
2182
2182
|
});
|
|
2183
2183
|
generateCssRule.generateRule = generateRule;
|
|
2184
|
-
var _generateLtr$1 = _interopRequireDefault$
|
|
2185
|
-
var _generateRtl$1 = _interopRequireDefault$
|
|
2184
|
+
var _generateLtr$1 = _interopRequireDefault$6(generateLtr);
|
|
2185
|
+
var _generateRtl$1 = _interopRequireDefault$6(generateRtl);
|
|
2186
2186
|
var _genCSSRule = genCSSRule$1;
|
|
2187
|
-
var _propertyPriorities = _interopRequireDefault$
|
|
2188
|
-
function _interopRequireDefault$
|
|
2187
|
+
var _propertyPriorities = _interopRequireDefault$6(propertyPriorities);
|
|
2188
|
+
function _interopRequireDefault$6(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2189
2189
|
function generateRule(className, key, value, pseudos, atRules) {
|
|
2190
2190
|
const pairs = Array.isArray(value) ? value.map(eachValue => [key, eachValue]) : [[key, value]];
|
|
2191
2191
|
const ltrPairs = pairs.map(_generateLtr$1.default);
|
|
@@ -2205,13 +2205,13 @@ Object.defineProperty(convertToClassName, "__esModule", {
|
|
|
2205
2205
|
value: true
|
|
2206
2206
|
});
|
|
2207
2207
|
convertToClassName.convertStyleToClassName = convertStyleToClassName;
|
|
2208
|
-
var _hash$4 = _interopRequireDefault$
|
|
2209
|
-
var _dashify$1 = _interopRequireDefault$
|
|
2210
|
-
var _transformValue$1 = _interopRequireDefault$
|
|
2208
|
+
var _hash$4 = _interopRequireDefault$5(hash$1);
|
|
2209
|
+
var _dashify$1 = _interopRequireDefault$5(dashify$1);
|
|
2210
|
+
var _transformValue$1 = _interopRequireDefault$5(transformValue$1);
|
|
2211
2211
|
var _generateCssRule = generateCssRule;
|
|
2212
2212
|
var _defaultOptions$4 = defaultOptions;
|
|
2213
2213
|
var _objectUtils$5 = objectUtils;
|
|
2214
|
-
function _interopRequireDefault$
|
|
2214
|
+
function _interopRequireDefault$5(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2215
2215
|
function convertStyleToClassName(objEntry, pseudos, atRules) {
|
|
2216
2216
|
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _defaultOptions$4.defaultOptions;
|
|
2217
2217
|
const {
|
|
@@ -2322,10 +2322,10 @@ Object.defineProperty(flattenRawStyleObj, "__esModule", {
|
|
|
2322
2322
|
});
|
|
2323
2323
|
flattenRawStyleObj._flattenRawStyleObject = _flattenRawStyleObject;
|
|
2324
2324
|
flattenRawStyleObj.flattenRawStyleObject = flattenRawStyleObject;
|
|
2325
|
-
var _index$1 = _interopRequireDefault$
|
|
2325
|
+
var _index$1 = _interopRequireDefault$4(preprocessRules);
|
|
2326
2326
|
var _PreRule = PreRule$1;
|
|
2327
2327
|
var _stylexInclude$3 = stylexInclude$2;
|
|
2328
|
-
function _interopRequireDefault$
|
|
2328
|
+
function _interopRequireDefault$4(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2329
2329
|
function flattenRawStyleObject(style, options) {
|
|
2330
2330
|
return _flattenRawStyleObject(style, [], [], options);
|
|
2331
2331
|
}
|
|
@@ -2445,8 +2445,8 @@ basicValidation.validateNamespace = validateNamespace;
|
|
|
2445
2445
|
var _stylexInclude$2 = stylexInclude$2;
|
|
2446
2446
|
var messages = _interopRequireWildcard$1(messages$3);
|
|
2447
2447
|
var _objectUtils$3 = objectUtils;
|
|
2448
|
-
function _getRequireWildcardCache$1(
|
|
2449
|
-
function _interopRequireWildcard$1(
|
|
2448
|
+
function _getRequireWildcardCache$1(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache$1 = function (e) { return e ? t : r; })(e); }
|
|
2449
|
+
function _interopRequireWildcard$1(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache$1(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
2450
2450
|
function validateNamespace(namespace) {
|
|
2451
2451
|
let conditions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
2452
2452
|
if (!(0, _objectUtils$3.isPlainObject)(namespace)) {
|
|
@@ -2471,7 +2471,7 @@ function validateNamespace(namespace) {
|
|
|
2471
2471
|
if (conditions.length === 0) {
|
|
2472
2472
|
continue;
|
|
2473
2473
|
}
|
|
2474
|
-
throw new Error(messages.
|
|
2474
|
+
throw new Error(messages.ONLY_TOP_LEVEL_INCLUDES);
|
|
2475
2475
|
}
|
|
2476
2476
|
if ((0, _objectUtils$3.isPlainObject)(val)) {
|
|
2477
2477
|
if (key.startsWith('@') || key.startsWith(':')) {
|
|
@@ -2510,7 +2510,7 @@ function validateConditionalStyles(val) {
|
|
|
2510
2510
|
continue;
|
|
2511
2511
|
}
|
|
2512
2512
|
if (v instanceof _stylexInclude$2.IncludedStyles) {
|
|
2513
|
-
throw new Error(messages.
|
|
2513
|
+
throw new Error(messages.ONLY_TOP_LEVEL_INCLUDES);
|
|
2514
2514
|
}
|
|
2515
2515
|
if ((0, _objectUtils$3.isPlainObject)(v)) {
|
|
2516
2516
|
validateConditionalStyles(v, [...conditions, key]);
|
|
@@ -2575,10 +2575,10 @@ Object.defineProperty(stylexDefineVars$1, "__esModule", {
|
|
|
2575
2575
|
value: true
|
|
2576
2576
|
});
|
|
2577
2577
|
stylexDefineVars$1.default = styleXDefineVars;
|
|
2578
|
-
var _hash$3 = _interopRequireDefault$
|
|
2578
|
+
var _hash$3 = _interopRequireDefault$3(hash$1);
|
|
2579
2579
|
var _objectUtils$1 = objectUtils;
|
|
2580
2580
|
var _defaultOptions$2 = defaultOptions;
|
|
2581
|
-
function _interopRequireDefault$
|
|
2581
|
+
function _interopRequireDefault$3(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2582
2582
|
function styleXDefineVars(variables, options) {
|
|
2583
2583
|
const {
|
|
2584
2584
|
classNamePrefix,
|
|
@@ -2601,45 +2601,46 @@ function styleXDefineVars(variables, options) {
|
|
|
2601
2601
|
} = _ref;
|
|
2602
2602
|
return `var(--${nameHash})`;
|
|
2603
2603
|
});
|
|
2604
|
-
const
|
|
2604
|
+
const injectableStyles = constructCssVariablesString(variablesMap, themeNameHash);
|
|
2605
2605
|
return [{
|
|
2606
2606
|
...themeVariablesObject,
|
|
2607
2607
|
__themeName__: themeNameHash
|
|
2608
|
-
},
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
}
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
nameHash,
|
|
2617
|
-
value
|
|
2618
|
-
}] = _ref2;
|
|
2608
|
+
}, injectableStyles];
|
|
2609
|
+
}
|
|
2610
|
+
function constructCssVariablesString(variables, themeNameHash) {
|
|
2611
|
+
const ruleByAtRule = {};
|
|
2612
|
+
for (const [key, {
|
|
2613
|
+
nameHash,
|
|
2614
|
+
value
|
|
2615
|
+
}] of (0, _objectUtils$1.objEntries)(variables)) {
|
|
2619
2616
|
if (value !== null && typeof value === 'object') {
|
|
2620
2617
|
if (value.default === undefined) {
|
|
2621
2618
|
throw new Error('Default value is not defined for ' + key + ' variable.');
|
|
2622
2619
|
}
|
|
2623
|
-
const
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
});
|
|
2634
|
-
return definedVarString;
|
|
2620
|
+
const v = value;
|
|
2621
|
+
for (const [key, value] of (0, _objectUtils$1.objEntries)(v)) {
|
|
2622
|
+
ruleByAtRule[key] ??= [];
|
|
2623
|
+
ruleByAtRule[key].push(`--${nameHash}:${value};`);
|
|
2624
|
+
}
|
|
2625
|
+
} else {
|
|
2626
|
+
ruleByAtRule.default ??= [];
|
|
2627
|
+
ruleByAtRule.default.push(`--${nameHash}:${value};`);
|
|
2635
2628
|
}
|
|
2636
|
-
|
|
2637
|
-
}
|
|
2638
|
-
const
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2629
|
+
}
|
|
2630
|
+
const result = {};
|
|
2631
|
+
for (const [key, value] of (0, _objectUtils$1.objEntries)(ruleByAtRule)) {
|
|
2632
|
+
const suffix = key === 'default' ? '' : `-${(0, _hash$3.default)(key)}`;
|
|
2633
|
+
let ltr = `:root{${value.join('')}}`;
|
|
2634
|
+
if (key !== 'default') {
|
|
2635
|
+
ltr = `${key}{${ltr}}`;
|
|
2636
|
+
}
|
|
2637
|
+
result[themeNameHash + suffix] = {
|
|
2638
|
+
ltr,
|
|
2639
|
+
rtl: null,
|
|
2640
|
+
priority: key === 'default' ? 0 : 0.1
|
|
2641
|
+
};
|
|
2642
|
+
}
|
|
2643
|
+
return result;
|
|
2643
2644
|
}
|
|
2644
2645
|
|
|
2645
2646
|
var stylexCreateTheme$1 = {};
|
|
@@ -2648,9 +2649,9 @@ Object.defineProperty(stylexCreateTheme$1, "__esModule", {
|
|
|
2648
2649
|
value: true
|
|
2649
2650
|
});
|
|
2650
2651
|
stylexCreateTheme$1.default = styleXCreateTheme;
|
|
2651
|
-
var _hash$2 = _interopRequireDefault$
|
|
2652
|
+
var _hash$2 = _interopRequireDefault$2(hash$1);
|
|
2652
2653
|
var _defaultOptions$1 = defaultOptions;
|
|
2653
|
-
function _interopRequireDefault$
|
|
2654
|
+
function _interopRequireDefault$2(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2654
2655
|
function styleXCreateTheme(themeVars, variables, options) {
|
|
2655
2656
|
if (typeof themeVars.__themeName__ !== 'string') {
|
|
2656
2657
|
throw new Error('Can only override variables theme created with stylex.defineVars().');
|
|
@@ -2690,19 +2691,24 @@ function styleXCreateTheme(themeVars, variables, options) {
|
|
|
2690
2691
|
return `${atRule}{${atRules[atRule].sort().join('')}}`;
|
|
2691
2692
|
}).join('');
|
|
2692
2693
|
const overrideClassName = classNamePrefix + (0, _hash$2.default)(cssVariablesOverrideString + atRulesStringForHash);
|
|
2693
|
-
const
|
|
2694
|
-
return `${atRule}{.${overrideClassName}{${atRules[atRule].join('')}}}`;
|
|
2695
|
-
}).join('');
|
|
2696
|
-
return [{
|
|
2697
|
-
$$css: true,
|
|
2698
|
-
[themeVars.__themeName__]: overrideClassName
|
|
2699
|
-
}, {
|
|
2694
|
+
const stylesToInject = {
|
|
2700
2695
|
[overrideClassName]: {
|
|
2701
|
-
ltr: `.${overrideClassName}{${cssVariablesOverrideString}}
|
|
2702
|
-
priority: 0.
|
|
2696
|
+
ltr: `.${overrideClassName}{${cssVariablesOverrideString}}`,
|
|
2697
|
+
priority: 0.8,
|
|
2703
2698
|
rtl: undefined
|
|
2704
2699
|
}
|
|
2705
|
-
}
|
|
2700
|
+
};
|
|
2701
|
+
for (const atRule of sortedAtRules) {
|
|
2702
|
+
stylesToInject[overrideClassName + '-' + (0, _hash$2.default)(atRule)] = {
|
|
2703
|
+
ltr: `${atRule}{.${overrideClassName}{${atRules[atRule].join('')}}}`,
|
|
2704
|
+
priority: 0.9,
|
|
2705
|
+
rtl: null
|
|
2706
|
+
};
|
|
2707
|
+
}
|
|
2708
|
+
return [{
|
|
2709
|
+
$$css: true,
|
|
2710
|
+
[themeVars.__themeName__]: overrideClassName
|
|
2711
|
+
}, stylesToInject];
|
|
2706
2712
|
}
|
|
2707
2713
|
|
|
2708
2714
|
var stylexKeyframes = {};
|
|
@@ -2711,15 +2717,15 @@ Object.defineProperty(stylexKeyframes, "__esModule", {
|
|
|
2711
2717
|
value: true
|
|
2712
2718
|
});
|
|
2713
2719
|
stylexKeyframes.default = styleXKeyframes;
|
|
2714
|
-
var _hash$1 = _interopRequireDefault$
|
|
2715
|
-
var _index = _interopRequireDefault$
|
|
2716
|
-
var _generateLtr = _interopRequireDefault$
|
|
2717
|
-
var _generateRtl = _interopRequireDefault$
|
|
2718
|
-
var _transformValue = _interopRequireDefault$
|
|
2719
|
-
var _dashify = _interopRequireDefault$
|
|
2720
|
+
var _hash$1 = _interopRequireDefault$1(hash$1);
|
|
2721
|
+
var _index = _interopRequireDefault$1(preprocessRules);
|
|
2722
|
+
var _generateLtr = _interopRequireDefault$1(generateLtr);
|
|
2723
|
+
var _generateRtl = _interopRequireDefault$1(generateRtl);
|
|
2724
|
+
var _transformValue = _interopRequireDefault$1(transformValue$1);
|
|
2725
|
+
var _dashify = _interopRequireDefault$1(dashify$1);
|
|
2720
2726
|
var _objectUtils = objectUtils;
|
|
2721
2727
|
var _defaultOptions = defaultOptions;
|
|
2722
|
-
function _interopRequireDefault$
|
|
2728
|
+
function _interopRequireDefault$1(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2723
2729
|
function styleXKeyframes(frames) {
|
|
2724
2730
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaultOptions.defaultOptions;
|
|
2725
2731
|
const {
|
|
@@ -2994,20 +3000,20 @@ Object.defineProperty(lib, "__esModule", {
|
|
|
2994
3000
|
value: true
|
|
2995
3001
|
});
|
|
2996
3002
|
var utils_1 = lib.utils = lib.types = messages_1 = lib.messages = keyframes_1 = lib.keyframes = include_1 = lib.include = firstThatWorks_1 = lib.firstThatWorks = defineVars_1 = lib.defineVars = createTheme_1 = lib.createTheme = create_1 = lib.create = IncludedStyles_1 = lib.IncludedStyles = void 0;
|
|
2997
|
-
var _stylexCreate = _interopRequireDefault
|
|
2998
|
-
var _stylexDefineVars = _interopRequireDefault
|
|
2999
|
-
var _stylexCreateTheme = _interopRequireDefault
|
|
3000
|
-
var _stylexKeyframes = _interopRequireDefault
|
|
3003
|
+
var _stylexCreate = _interopRequireDefault(stylexCreate$1);
|
|
3004
|
+
var _stylexDefineVars = _interopRequireDefault(stylexDefineVars$1);
|
|
3005
|
+
var _stylexCreateTheme = _interopRequireDefault(stylexCreateTheme$1);
|
|
3006
|
+
var _stylexKeyframes = _interopRequireDefault(stylexKeyframes);
|
|
3001
3007
|
var _stylexInclude = _interopRequireWildcard(stylexInclude$2);
|
|
3002
|
-
var _stylexFirstThatWorks = _interopRequireDefault
|
|
3003
|
-
var _hash = _interopRequireDefault
|
|
3004
|
-
var _fileBasedIdentifier = _interopRequireDefault
|
|
3008
|
+
var _stylexFirstThatWorks = _interopRequireDefault(stylexFirstThatWorks$1);
|
|
3009
|
+
var _hash = _interopRequireDefault(hash$1);
|
|
3010
|
+
var _fileBasedIdentifier = _interopRequireDefault(fileBasedIdentifier);
|
|
3005
3011
|
var m = _interopRequireWildcard(messages$3);
|
|
3006
3012
|
var _types = _interopRequireWildcard(types$1);
|
|
3007
3013
|
lib.types = _types;
|
|
3008
|
-
function _getRequireWildcardCache(
|
|
3009
|
-
function _interopRequireWildcard(
|
|
3010
|
-
function _interopRequireDefault
|
|
3014
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
3015
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
3016
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
3011
3017
|
create_1 = lib.create = _stylexCreate.default;
|
|
3012
3018
|
defineVars_1 = lib.defineVars = _stylexDefineVars.default;
|
|
3013
3019
|
createTheme_1 = lib.createTheme = _stylexCreateTheme.default;
|
|
@@ -3029,7 +3035,7 @@ function namespaceToDevClassName(namespace, varName, filename) {
|
|
|
3029
3035
|
function injectDevClassNames(obj, varName, state) {
|
|
3030
3036
|
const result = {};
|
|
3031
3037
|
for (const [key, value] of Object.entries(obj)) {
|
|
3032
|
-
const devClassName = namespaceToDevClassName(key, varName, state.filename ?? '
|
|
3038
|
+
const devClassName = namespaceToDevClassName(key, varName, state.filename ?? 'UnknownFile');
|
|
3033
3039
|
result[key] = {
|
|
3034
3040
|
[devClassName]: devClassName,
|
|
3035
3041
|
...value
|
|
@@ -3040,7 +3046,7 @@ function injectDevClassNames(obj, varName, state) {
|
|
|
3040
3046
|
function convertToTestStyles(obj, varName, state) {
|
|
3041
3047
|
const result = {};
|
|
3042
3048
|
for (const [key, _value] of Object.entries(obj)) {
|
|
3043
|
-
const devClassName = namespaceToDevClassName(key, varName, state.filename ?? '
|
|
3049
|
+
const devClassName = namespaceToDevClassName(key, varName, state.filename ?? 'UnknownFile');
|
|
3044
3050
|
result[key] = {
|
|
3045
3051
|
[devClassName]: devClassName,
|
|
3046
3052
|
$$css: true
|
|
@@ -3724,14 +3730,8 @@ function evaluateStyleXCreateArg(path, traversalState) {
|
|
|
3724
3730
|
}
|
|
3725
3731
|
const fnPath = valPath;
|
|
3726
3732
|
const allParams = fnPath.get('params');
|
|
3733
|
+
validateDynamicStyleParams(allParams);
|
|
3727
3734
|
const params = allParams.filter(param => isIdentifier(param)).map(param => param.node);
|
|
3728
|
-
if (params.length !== allParams.length) {
|
|
3729
|
-
return {
|
|
3730
|
-
confident: false,
|
|
3731
|
-
deopt: valPath,
|
|
3732
|
-
value: null
|
|
3733
|
-
};
|
|
3734
|
-
}
|
|
3735
3735
|
const fnBody = fnPath.get('body');
|
|
3736
3736
|
if (!isObjectExpression(fnBody)) {
|
|
3737
3737
|
return evaluate(path, traversalState, functions);
|
|
@@ -3855,6 +3855,11 @@ function evaluateObjKey(prop, traversalState, functions) {
|
|
|
3855
3855
|
value: String(key)
|
|
3856
3856
|
};
|
|
3857
3857
|
}
|
|
3858
|
+
function validateDynamicStyleParams(params) {
|
|
3859
|
+
if (params.some(param => !isIdentifier(param))) {
|
|
3860
|
+
throw new Error(messages_1.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS);
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3858
3863
|
|
|
3859
3864
|
function transformStyleXCreate(path, state) {
|
|
3860
3865
|
const {
|
|
@@ -3867,9 +3872,6 @@ function transformStyleXCreate(path, state) {
|
|
|
3867
3872
|
validateStyleXCreate(path);
|
|
3868
3873
|
const args = path.get('arguments');
|
|
3869
3874
|
const firstArg = args[0];
|
|
3870
|
-
if (!isObjectExpression(firstArg)) {
|
|
3871
|
-
throw new Error(messages_1.ILLEGAL_ARGUMENT_LENGTH);
|
|
3872
|
-
}
|
|
3873
3875
|
state.inStyleXCreate = true;
|
|
3874
3876
|
const injectedKeyframes = {};
|
|
3875
3877
|
function keyframes(animation) {
|
|
@@ -3970,15 +3972,29 @@ function transformStyleXCreate(path, state) {
|
|
|
3970
3972
|
if (Object.keys(injectedStyles).length === 0) {
|
|
3971
3973
|
return;
|
|
3972
3974
|
}
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3975
|
+
const statementPath = path.getStatementParent();
|
|
3976
|
+
if (state.runtimeInjection != null && statementPath != null) {
|
|
3977
|
+
let injectName;
|
|
3978
|
+
if (state.injectImportInserted != null) {
|
|
3979
|
+
injectName = state.injectImportInserted;
|
|
3980
|
+
} else {
|
|
3981
|
+
const {
|
|
3982
|
+
from,
|
|
3983
|
+
as
|
|
3984
|
+
} = state.runtimeInjection;
|
|
3985
|
+
injectName = as != null ? helperModuleImports.addNamed(statementPath, as, from, {
|
|
3986
|
+
nameHint: 'inject'
|
|
3987
|
+
}) : helperModuleImports.addDefault(statementPath, from, {
|
|
3988
|
+
nameHint: 'inject'
|
|
3989
|
+
});
|
|
3990
|
+
state.injectImportInserted = injectName;
|
|
3991
|
+
}
|
|
3976
3992
|
for (const [_key, {
|
|
3977
3993
|
ltr,
|
|
3978
3994
|
priority,
|
|
3979
3995
|
rtl
|
|
3980
3996
|
}] of Object.entries(injectedStyles)) {
|
|
3981
|
-
statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(
|
|
3997
|
+
statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority), ...(rtl != null ? [t__namespace.stringLiteral(rtl)] : [])])));
|
|
3982
3998
|
}
|
|
3983
3999
|
}
|
|
3984
4000
|
for (const [key, {
|
|
@@ -4014,19 +4030,6 @@ function findNearestStatementAncestor(path) {
|
|
|
4014
4030
|
}
|
|
4015
4031
|
return findNearestStatementAncestor(path.parentPath);
|
|
4016
4032
|
}
|
|
4017
|
-
function getStylexDefaultImport(path, state) {
|
|
4018
|
-
const statementPath = findNearestStatementAncestor(path);
|
|
4019
|
-
let stylexName;
|
|
4020
|
-
state.stylexImport.forEach(importName => {
|
|
4021
|
-
stylexName = importName;
|
|
4022
|
-
});
|
|
4023
|
-
if (stylexName == null) {
|
|
4024
|
-
stylexName = '__stylex__';
|
|
4025
|
-
statementPath.insertBefore(t__namespace.importDeclaration([t__namespace.importDefaultSpecifier(t__namespace.identifier(stylexName))], t__namespace.stringLiteral(state.importPathString)));
|
|
4026
|
-
state.stylexImport.add(stylexName);
|
|
4027
|
-
}
|
|
4028
|
-
return stylexName;
|
|
4029
|
-
}
|
|
4030
4033
|
|
|
4031
4034
|
function transformStyleXDefineVars(callExpressionPath, state) {
|
|
4032
4035
|
const callExpressionNode = callExpressionPath.node;
|
|
@@ -4066,9 +4069,7 @@ function transformStyleXDefineVars(callExpressionPath, state) {
|
|
|
4066
4069
|
throw new Error('No filename found for generating theme name.');
|
|
4067
4070
|
}
|
|
4068
4071
|
const exportName = varId.name;
|
|
4069
|
-
const [variablesObj, {
|
|
4070
|
-
css
|
|
4071
|
-
}] = defineVars_1(value, {
|
|
4072
|
+
const [variablesObj, injectedStyles] = defineVars_1(value, {
|
|
4072
4073
|
...state.options,
|
|
4073
4074
|
themeName: utils_1.genFileBasedIdentifier({
|
|
4074
4075
|
fileName,
|
|
@@ -4076,28 +4077,41 @@ function transformStyleXDefineVars(callExpressionPath, state) {
|
|
|
4076
4077
|
})
|
|
4077
4078
|
});
|
|
4078
4079
|
callExpressionPath.replaceWith(convertObjectToAST(variablesObj));
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
if (
|
|
4086
|
-
|
|
4080
|
+
const statementPath = variableDeclaratorPath.parentPath.parentPath;
|
|
4081
|
+
if (Object.keys(injectedStyles).length === 0) {
|
|
4082
|
+
return;
|
|
4083
|
+
}
|
|
4084
|
+
if (state.runtimeInjection != null && statementPath != null) {
|
|
4085
|
+
let injectName;
|
|
4086
|
+
if (state.injectImportInserted != null) {
|
|
4087
|
+
injectName = state.injectImportInserted;
|
|
4088
|
+
} else {
|
|
4089
|
+
const {
|
|
4090
|
+
from,
|
|
4091
|
+
as
|
|
4092
|
+
} = state.runtimeInjection;
|
|
4093
|
+
injectName = as != null ? helperModuleImports.addNamed(statementPath, as, from, {
|
|
4094
|
+
nameHint: 'inject'
|
|
4095
|
+
}) : helperModuleImports.addDefault(statementPath, from, {
|
|
4096
|
+
nameHint: 'inject'
|
|
4097
|
+
});
|
|
4098
|
+
state.injectImportInserted = injectName;
|
|
4087
4099
|
}
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
})
|
|
4092
|
-
|
|
4093
|
-
stylexName = '__stylex__';
|
|
4094
|
-
statementPath.insertBefore(t__namespace.importDeclaration([t__namespace.importDefaultSpecifier(t__namespace.identifier(stylexName))], t__namespace.stringLiteral(state.importPathString)));
|
|
4100
|
+
for (const [_k, {
|
|
4101
|
+
ltr,
|
|
4102
|
+
priority
|
|
4103
|
+
}] of Object.entries(injectedStyles)) {
|
|
4104
|
+
statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority)])));
|
|
4095
4105
|
}
|
|
4096
|
-
statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.identifier(stylexName), t__namespace.identifier('inject')), [t__namespace.stringLiteral(css), t__namespace.numericLiteral(0)])));
|
|
4097
4106
|
}
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4107
|
+
for (const [key, {
|
|
4108
|
+
priority,
|
|
4109
|
+
ltr
|
|
4110
|
+
}] of Object.entries(injectedStyles)) {
|
|
4111
|
+
state.addStyle([key, {
|
|
4112
|
+
ltr
|
|
4113
|
+
}, priority]);
|
|
4114
|
+
}
|
|
4101
4115
|
}
|
|
4102
4116
|
}
|
|
4103
4117
|
function validateStyleXDefineVars(callExpressionPath) {
|
|
@@ -4155,30 +4169,49 @@ function transformStyleXCreateTheme(callExpressionPath, state) {
|
|
|
4155
4169
|
if (typeof variables.__themeName__ !== 'string' || variables.__themeName__ === '') {
|
|
4156
4170
|
throw new Error('Can only override variables theme created with stylex.defineVars().');
|
|
4157
4171
|
}
|
|
4158
|
-
let [overridesObj,
|
|
4172
|
+
let [overridesObj, injectedStyles] = createTheme_1(variables, overrides, state.options);
|
|
4159
4173
|
if (state.isDev) {
|
|
4160
4174
|
overridesObj = {
|
|
4161
4175
|
...overridesObj,
|
|
4162
4176
|
[debugName]: debugName
|
|
4163
4177
|
};
|
|
4164
4178
|
}
|
|
4165
|
-
const styleKey = overridesObj[variables.__themeName__];
|
|
4166
4179
|
callExpressionPath.replaceWith(convertObjectToAST(overridesObj));
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
if (
|
|
4174
|
-
|
|
4175
|
-
|
|
4180
|
+
const statementPath = variableDeclaratorPath.parentPath;
|
|
4181
|
+
if (Object.keys(injectedStyles).length === 0) {
|
|
4182
|
+
return;
|
|
4183
|
+
}
|
|
4184
|
+
if (state.runtimeInjection != null && statementPath != null) {
|
|
4185
|
+
let injectName;
|
|
4186
|
+
if (state.injectImportInserted != null) {
|
|
4187
|
+
injectName = state.injectImportInserted;
|
|
4188
|
+
} else {
|
|
4189
|
+
const {
|
|
4190
|
+
from,
|
|
4191
|
+
as
|
|
4192
|
+
} = state.runtimeInjection;
|
|
4193
|
+
injectName = as != null ? helperModuleImports.addNamed(statementPath, as, from, {
|
|
4194
|
+
nameHint: 'inject'
|
|
4195
|
+
}) : helperModuleImports.addDefault(statementPath, from, {
|
|
4196
|
+
nameHint: 'inject'
|
|
4197
|
+
});
|
|
4198
|
+
state.injectImportInserted = injectName;
|
|
4199
|
+
}
|
|
4200
|
+
for (const [_k, {
|
|
4201
|
+
ltr,
|
|
4202
|
+
priority
|
|
4203
|
+
}] of Object.entries(injectedStyles)) {
|
|
4204
|
+
statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority)])));
|
|
4176
4205
|
}
|
|
4177
|
-
statementPath?.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.identifier(stylexName), t__namespace.identifier('inject')), [t__namespace.stringLiteral(css[styleKey].ltr), t__namespace.numericLiteral(css[styleKey].priority)])));
|
|
4178
4206
|
}
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4207
|
+
for (const [key, {
|
|
4208
|
+
priority,
|
|
4209
|
+
ltr
|
|
4210
|
+
}] of Object.entries(injectedStyles)) {
|
|
4211
|
+
state.addStyle([key, {
|
|
4212
|
+
ltr
|
|
4213
|
+
}, priority]);
|
|
4214
|
+
}
|
|
4182
4215
|
}
|
|
4183
4216
|
}
|
|
4184
4217
|
function validateStyleXCreateTheme(callExpressionPath) {
|
|
@@ -4207,18 +4240,36 @@ function transformStyleXKeyframes(path, state) {
|
|
|
4207
4240
|
throw new Error(messages_1.ILLEGAL_ARGUMENT_LENGTH);
|
|
4208
4241
|
}
|
|
4209
4242
|
if (nodeInit.arguments[0].type !== 'ObjectExpression') {
|
|
4210
|
-
throw new Error(messages_1.
|
|
4243
|
+
throw new Error(messages_1.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL);
|
|
4211
4244
|
}
|
|
4212
4245
|
const init = path.get('init');
|
|
4213
4246
|
if (init == null || !isCallExpression(init)) {
|
|
4214
|
-
throw new Error(messages_1.
|
|
4247
|
+
throw new Error(messages_1.NON_STATIC_KEYFRAME_VALUE);
|
|
4215
4248
|
}
|
|
4216
4249
|
const args = init.get('arguments');
|
|
4217
4250
|
const firstArg = args[0];
|
|
4251
|
+
const identifiers = {};
|
|
4252
|
+
const memberExpressions = {};
|
|
4253
|
+
state.stylexFirstThatWorksImport.forEach(name => {
|
|
4254
|
+
identifiers[name] = {
|
|
4255
|
+
fn: firstThatWorks_1
|
|
4256
|
+
};
|
|
4257
|
+
});
|
|
4258
|
+
state.stylexImport.forEach(name => {
|
|
4259
|
+
if (memberExpressions[name] == null) {
|
|
4260
|
+
memberExpressions[name] = {};
|
|
4261
|
+
}
|
|
4262
|
+
memberExpressions[name].firstThatWorks = {
|
|
4263
|
+
fn: firstThatWorks_1
|
|
4264
|
+
};
|
|
4265
|
+
});
|
|
4218
4266
|
const {
|
|
4219
4267
|
confident,
|
|
4220
4268
|
value
|
|
4221
|
-
} =
|
|
4269
|
+
} = evaluate(firstArg, state, {
|
|
4270
|
+
identifiers,
|
|
4271
|
+
memberExpressions
|
|
4272
|
+
});
|
|
4222
4273
|
if (!confident) {
|
|
4223
4274
|
throw new Error(messages_1.NON_STATIC_VALUE);
|
|
4224
4275
|
}
|
|
@@ -4231,17 +4282,24 @@ function transformStyleXKeyframes(path, state) {
|
|
|
4231
4282
|
priority,
|
|
4232
4283
|
rtl
|
|
4233
4284
|
} = injectedStyle;
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
let
|
|
4237
|
-
state.
|
|
4238
|
-
|
|
4239
|
-
}
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4285
|
+
const statementPath = path.getStatementParent();
|
|
4286
|
+
if (statementPath != null && state.runtimeInjection != null) {
|
|
4287
|
+
let injectName;
|
|
4288
|
+
if (state.injectImportInserted != null) {
|
|
4289
|
+
injectName = state.injectImportInserted;
|
|
4290
|
+
} else {
|
|
4291
|
+
const {
|
|
4292
|
+
from,
|
|
4293
|
+
as
|
|
4294
|
+
} = state.runtimeInjection;
|
|
4295
|
+
injectName = as != null ? helperModuleImports.addNamed(statementPath, as, from, {
|
|
4296
|
+
nameHint: 'inject'
|
|
4297
|
+
}) : helperModuleImports.addDefault(statementPath, from, {
|
|
4298
|
+
nameHint: 'inject'
|
|
4299
|
+
});
|
|
4300
|
+
state.injectImportInserted = injectName;
|
|
4243
4301
|
}
|
|
4244
|
-
statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(
|
|
4302
|
+
statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority), ...(rtl != null ? [t__namespace.stringLiteral(rtl)] : [])])));
|
|
4245
4303
|
}
|
|
4246
4304
|
state.addStyle([animationName, {
|
|
4247
4305
|
ltr,
|
|
@@ -4251,213 +4309,27 @@ function transformStyleXKeyframes(path, state) {
|
|
|
4251
4309
|
}
|
|
4252
4310
|
function assertValidKeyframes(obj) {
|
|
4253
4311
|
if (typeof obj !== 'object' || Array.isArray(obj) || obj == null) {
|
|
4254
|
-
throw new Error(messages_1.
|
|
4312
|
+
throw new Error(messages_1.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL);
|
|
4255
4313
|
}
|
|
4256
4314
|
for (const [_key, value] of Object.entries(obj)) {
|
|
4257
4315
|
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
4258
|
-
throw new Error(messages_1.
|
|
4316
|
+
throw new Error(messages_1.NON_OBJECT_KEYFRAME);
|
|
4259
4317
|
}
|
|
4260
4318
|
}
|
|
4261
4319
|
}
|
|
4262
4320
|
|
|
4263
4321
|
var stylex = {};
|
|
4264
4322
|
|
|
4265
|
-
var stylexInject = {};
|
|
4266
|
-
|
|
4267
|
-
var StyleXSheet$1 = {};
|
|
4268
|
-
|
|
4269
|
-
Object.defineProperty(StyleXSheet$1, "__esModule", {
|
|
4270
|
-
value: true
|
|
4271
|
-
});
|
|
4272
|
-
StyleXSheet$1.styleSheet = StyleXSheet$1.StyleXSheet = void 0;
|
|
4273
|
-
var _invariant = _interopRequireDefault$1(require$$0$1);
|
|
4274
|
-
function _interopRequireDefault$1(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
4275
|
-
const LIGHT_MODE_CLASS_NAME = '__fb-light-mode';
|
|
4276
|
-
const DARK_MODE_CLASS_NAME = '__fb-dark-mode';
|
|
4277
|
-
function buildTheme(selector, theme) {
|
|
4278
|
-
const lines = [];
|
|
4279
|
-
lines.push(`${selector} {`);
|
|
4280
|
-
for (const key in theme) {
|
|
4281
|
-
const value = theme[key];
|
|
4282
|
-
lines.push(` --${key}: ${value};`);
|
|
4283
|
-
}
|
|
4284
|
-
lines.push('}');
|
|
4285
|
-
return lines.join('\n');
|
|
4286
|
-
}
|
|
4287
|
-
function makeStyleTag() {
|
|
4288
|
-
const tag = document.createElement('style');
|
|
4289
|
-
tag.setAttribute('type', 'text/css');
|
|
4290
|
-
tag.setAttribute('data-stylex', 'true');
|
|
4291
|
-
const head = document.head || document.getElementsByTagName('head')[0];
|
|
4292
|
-
(0, _invariant.default)(head, 'expected head');
|
|
4293
|
-
head.appendChild(tag);
|
|
4294
|
-
return tag;
|
|
4295
|
-
}
|
|
4296
|
-
function doesSupportCSSVariables() {
|
|
4297
|
-
return globalThis.CSS != null && globalThis.CSS.supports != null && globalThis.CSS.supports('--fake-var:0');
|
|
4298
|
-
}
|
|
4299
|
-
const VARIABLE_MATCH = /var\(--(.*?)\)/g;
|
|
4300
|
-
class StyleXSheet {
|
|
4301
|
-
static LIGHT_MODE_CLASS_NAME = LIGHT_MODE_CLASS_NAME;
|
|
4302
|
-
static DARK_MODE_CLASS_NAME = DARK_MODE_CLASS_NAME;
|
|
4303
|
-
constructor(opts) {
|
|
4304
|
-
this.tag = null;
|
|
4305
|
-
this.injected = false;
|
|
4306
|
-
this.ruleForPriority = new Map();
|
|
4307
|
-
this.rules = [];
|
|
4308
|
-
this.rootTheme = opts.rootTheme;
|
|
4309
|
-
this.rootDarkTheme = opts.rootDarkTheme;
|
|
4310
|
-
this.supportsVariables = opts.supportsVariables ?? doesSupportCSSVariables();
|
|
4311
|
-
}
|
|
4312
|
-
getVariableMatch() {
|
|
4313
|
-
return VARIABLE_MATCH;
|
|
4314
|
-
}
|
|
4315
|
-
isHeadless() {
|
|
4316
|
-
return this.tag == null || globalThis?.document?.body == null;
|
|
4317
|
-
}
|
|
4318
|
-
getTag() {
|
|
4319
|
-
const {
|
|
4320
|
-
tag
|
|
4321
|
-
} = this;
|
|
4322
|
-
(0, _invariant.default)(tag != null, 'expected tag');
|
|
4323
|
-
return tag;
|
|
4324
|
-
}
|
|
4325
|
-
getCSS() {
|
|
4326
|
-
return this.rules.join('\n');
|
|
4327
|
-
}
|
|
4328
|
-
getRulePosition(rule) {
|
|
4329
|
-
return this.rules.indexOf(rule);
|
|
4330
|
-
}
|
|
4331
|
-
getRuleCount() {
|
|
4332
|
-
return this.rules.length;
|
|
4333
|
-
}
|
|
4334
|
-
inject() {
|
|
4335
|
-
if (this.injected) {
|
|
4336
|
-
return;
|
|
4337
|
-
}
|
|
4338
|
-
this.injected = true;
|
|
4339
|
-
if (globalThis.document?.body == null) {
|
|
4340
|
-
this.injectTheme();
|
|
4341
|
-
return;
|
|
4342
|
-
}
|
|
4343
|
-
this.tag = makeStyleTag();
|
|
4344
|
-
this.injectTheme();
|
|
4345
|
-
}
|
|
4346
|
-
injectTheme() {
|
|
4347
|
-
if (this.rootTheme != null) {
|
|
4348
|
-
this.insert(buildTheme(`:root, .${LIGHT_MODE_CLASS_NAME}`, this.rootTheme), 0);
|
|
4349
|
-
}
|
|
4350
|
-
if (this.rootDarkTheme != null) {
|
|
4351
|
-
this.insert(buildTheme(`.${DARK_MODE_CLASS_NAME}:root, .${DARK_MODE_CLASS_NAME}`, this.rootDarkTheme), 0);
|
|
4352
|
-
}
|
|
4353
|
-
}
|
|
4354
|
-
__injectCustomThemeForTesting(selector, theme) {
|
|
4355
|
-
if (theme != null) {
|
|
4356
|
-
this.insert(buildTheme(selector, theme), 0);
|
|
4357
|
-
}
|
|
4358
|
-
}
|
|
4359
|
-
delete(rule) {
|
|
4360
|
-
const index = this.rules.indexOf(rule);
|
|
4361
|
-
(0, _invariant.default)(index >= 0, "Couldn't find the index for rule %s", rule);
|
|
4362
|
-
this.rules.splice(index, 1);
|
|
4363
|
-
if (this.isHeadless()) {
|
|
4364
|
-
return;
|
|
4365
|
-
}
|
|
4366
|
-
const tag = this.getTag();
|
|
4367
|
-
const sheet = tag.sheet;
|
|
4368
|
-
(0, _invariant.default)(sheet, 'expected sheet');
|
|
4369
|
-
sheet.deleteRule(index);
|
|
4370
|
-
}
|
|
4371
|
-
normalizeRule(rule) {
|
|
4372
|
-
const {
|
|
4373
|
-
rootTheme
|
|
4374
|
-
} = this;
|
|
4375
|
-
if (this.supportsVariables || rootTheme == null) {
|
|
4376
|
-
return rule;
|
|
4377
|
-
}
|
|
4378
|
-
return rule.replace(VARIABLE_MATCH, (_match, name) => {
|
|
4379
|
-
return rootTheme[name];
|
|
4380
|
-
});
|
|
4381
|
-
}
|
|
4382
|
-
getInsertPositionForPriority(priority) {
|
|
4383
|
-
const priorityRule = this.ruleForPriority.get(priority);
|
|
4384
|
-
if (priorityRule != null) {
|
|
4385
|
-
return this.rules.indexOf(priorityRule) + 1;
|
|
4386
|
-
}
|
|
4387
|
-
const priorities = Array.from(this.ruleForPriority.keys()).sort((a, b) => b - a).filter(num => num > priority ? 1 : 0);
|
|
4388
|
-
if (priorities.length === 0) {
|
|
4389
|
-
return this.getRuleCount();
|
|
4390
|
-
}
|
|
4391
|
-
const lastPriority = priorities.pop();
|
|
4392
|
-
return this.rules.indexOf(this.ruleForPriority.get(lastPriority));
|
|
4393
|
-
}
|
|
4394
|
-
insert(rawLTRRule, priority, rawRTLRule) {
|
|
4395
|
-
if (this.injected === false) {
|
|
4396
|
-
this.inject();
|
|
4397
|
-
}
|
|
4398
|
-
if (rawRTLRule != null) {
|
|
4399
|
-
this.insert(addAncestorSelector$1(rawLTRRule, "html:not([dir='rtl'])"), priority);
|
|
4400
|
-
this.insert(addAncestorSelector$1(rawRTLRule, "html[dir='rtl']"), priority);
|
|
4401
|
-
return;
|
|
4402
|
-
}
|
|
4403
|
-
const rawRule = rawLTRRule;
|
|
4404
|
-
if (this.rules.includes(rawRule)) {
|
|
4405
|
-
return;
|
|
4406
|
-
}
|
|
4407
|
-
const rule = this.normalizeRule(rawRule);
|
|
4408
|
-
const insertPos = this.getInsertPositionForPriority(priority);
|
|
4409
|
-
this.rules.splice(insertPos, 0, rule);
|
|
4410
|
-
this.ruleForPriority.set(priority, rule);
|
|
4411
|
-
if (this.isHeadless()) {
|
|
4412
|
-
return;
|
|
4413
|
-
}
|
|
4414
|
-
const tag = this.getTag();
|
|
4415
|
-
const sheet = tag.sheet;
|
|
4416
|
-
if (sheet != null) {
|
|
4417
|
-
try {
|
|
4418
|
-
sheet.insertRule(rule, insertPos);
|
|
4419
|
-
} catch {}
|
|
4420
|
-
}
|
|
4421
|
-
}
|
|
4422
|
-
}
|
|
4423
|
-
StyleXSheet$1.StyleXSheet = StyleXSheet;
|
|
4424
|
-
function addAncestorSelector$1(selector, ancestorSelector) {
|
|
4425
|
-
if (!selector.startsWith('@')) {
|
|
4426
|
-
return `${ancestorSelector} ${selector}`;
|
|
4427
|
-
}
|
|
4428
|
-
const firstBracketIndex = selector.indexOf('{');
|
|
4429
|
-
const mediaQueryPart = selector.slice(0, firstBracketIndex + 1);
|
|
4430
|
-
const rest = selector.slice(firstBracketIndex + 1);
|
|
4431
|
-
return `${mediaQueryPart}${ancestorSelector} ${rest}`;
|
|
4432
|
-
}
|
|
4433
|
-
StyleXSheet$1.styleSheet = new StyleXSheet({
|
|
4434
|
-
supportsVariables: true,
|
|
4435
|
-
rootTheme: {},
|
|
4436
|
-
rootDarkTheme: {}
|
|
4437
|
-
});
|
|
4438
|
-
|
|
4439
|
-
Object.defineProperty(stylexInject, "__esModule", {
|
|
4440
|
-
value: true
|
|
4441
|
-
});
|
|
4442
|
-
stylexInject.default = inject$1;
|
|
4443
|
-
var _StyleXSheet = StyleXSheet$1;
|
|
4444
|
-
function inject$1(ltrRule, priority) {
|
|
4445
|
-
let rtlRule = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
4446
|
-
_StyleXSheet.styleSheet.insert(ltrRule, priority, rtlRule);
|
|
4447
|
-
}
|
|
4448
|
-
|
|
4449
4323
|
var default_1;
|
|
4450
4324
|
|
|
4451
4325
|
Object.defineProperty(stylex, "__esModule", {
|
|
4452
4326
|
value: true
|
|
4453
4327
|
});
|
|
4454
4328
|
stylex.__monkey_patch__ = __monkey_patch__;
|
|
4455
|
-
stylex.keyframes = stylex.
|
|
4329
|
+
stylex.keyframes = stylex.include = stylex.firstThatWorks = stylex.defineVars = default_1 = stylex.default = stylex.createTheme = stylex.create = void 0;
|
|
4456
4330
|
var props_1 = stylex.props = props;
|
|
4457
4331
|
stylex.types = stylex.stylex = void 0;
|
|
4458
|
-
var
|
|
4459
|
-
var _styleq = require$$1;
|
|
4460
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
4332
|
+
var _styleq = require$$0$1;
|
|
4461
4333
|
function props() {
|
|
4462
4334
|
const options = this;
|
|
4463
4335
|
for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -4561,7 +4433,6 @@ const firstThatWorks = function () {
|
|
|
4561
4433
|
throw new Error('stylex.firstThatWorks should never be called.');
|
|
4562
4434
|
};
|
|
4563
4435
|
stylex.firstThatWorks = firstThatWorks;
|
|
4564
|
-
const inject = stylex.inject = _stylexInject.default;
|
|
4565
4436
|
function _stylex() {
|
|
4566
4437
|
for (var _len2 = arguments.length, styles = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
4567
4438
|
styles[_key2] = arguments[_key2];
|
|
@@ -4576,7 +4447,6 @@ _stylex.createTheme = createTheme;
|
|
|
4576
4447
|
_stylex.include = include;
|
|
4577
4448
|
_stylex.keyframes = keyframes;
|
|
4578
4449
|
_stylex.firstThatWorks = firstThatWorks;
|
|
4579
|
-
_stylex.inject = inject;
|
|
4580
4450
|
_stylex.types = types;
|
|
4581
4451
|
const __implementations = {};
|
|
4582
4452
|
function __monkey_patch__(key, implementation) {
|
|
@@ -4607,13 +4477,17 @@ function transformStyleXMerge(path, state) {
|
|
|
4607
4477
|
}
|
|
4608
4478
|
let bailOut = false;
|
|
4609
4479
|
let conditional = 0;
|
|
4480
|
+
let currentIndex = -1;
|
|
4481
|
+
let bailOutIndex = null;
|
|
4610
4482
|
const resolvedArgs = [];
|
|
4611
4483
|
for (const arg of node.arguments) {
|
|
4484
|
+
currentIndex++;
|
|
4612
4485
|
switch (arg.type) {
|
|
4613
4486
|
case 'MemberExpression':
|
|
4614
4487
|
{
|
|
4615
4488
|
const resolved = parseNullableStyle$1(arg, state);
|
|
4616
4489
|
if (resolved === 'other') {
|
|
4490
|
+
bailOutIndex = currentIndex;
|
|
4617
4491
|
bailOut = true;
|
|
4618
4492
|
} else {
|
|
4619
4493
|
resolvedArgs.push(resolved);
|
|
@@ -4630,6 +4504,7 @@ function transformStyleXMerge(path, state) {
|
|
|
4630
4504
|
const primary = parseNullableStyle$1(consequent, state);
|
|
4631
4505
|
const fallback = parseNullableStyle$1(alternate, state);
|
|
4632
4506
|
if (primary === 'other' || fallback === 'other') {
|
|
4507
|
+
bailOutIndex = currentIndex;
|
|
4633
4508
|
bailOut = true;
|
|
4634
4509
|
} else {
|
|
4635
4510
|
resolvedArgs.push([test, primary, fallback]);
|
|
@@ -4640,6 +4515,7 @@ function transformStyleXMerge(path, state) {
|
|
|
4640
4515
|
case 'LogicalExpression':
|
|
4641
4516
|
{
|
|
4642
4517
|
if (arg.operator !== '&&') {
|
|
4518
|
+
bailOutIndex = currentIndex;
|
|
4643
4519
|
bailOut = true;
|
|
4644
4520
|
break;
|
|
4645
4521
|
}
|
|
@@ -4650,6 +4526,7 @@ function transformStyleXMerge(path, state) {
|
|
|
4650
4526
|
const leftResolved = parseNullableStyle$1(left, state);
|
|
4651
4527
|
const rightResolved = parseNullableStyle$1(right, state);
|
|
4652
4528
|
if (leftResolved !== 'other' || rightResolved === 'other') {
|
|
4529
|
+
bailOutIndex = currentIndex;
|
|
4653
4530
|
bailOut = true;
|
|
4654
4531
|
} else {
|
|
4655
4532
|
resolvedArgs.push([left, rightResolved, null]);
|
|
@@ -4658,6 +4535,7 @@ function transformStyleXMerge(path, state) {
|
|
|
4658
4535
|
break;
|
|
4659
4536
|
}
|
|
4660
4537
|
default:
|
|
4538
|
+
bailOutIndex = currentIndex;
|
|
4661
4539
|
bailOut = true;
|
|
4662
4540
|
break;
|
|
4663
4541
|
}
|
|
@@ -4672,8 +4550,12 @@ function transformStyleXMerge(path, state) {
|
|
|
4672
4550
|
bailOut = true;
|
|
4673
4551
|
}
|
|
4674
4552
|
if (bailOut) {
|
|
4675
|
-
path.
|
|
4676
|
-
|
|
4553
|
+
const argumentPaths = path.get('arguments');
|
|
4554
|
+
let nonNullProps = [];
|
|
4555
|
+
let index = -1;
|
|
4556
|
+
for (const argPath of argumentPaths) {
|
|
4557
|
+
index++;
|
|
4558
|
+
function MemberExpression(path) {
|
|
4677
4559
|
const object = path.get('object').node;
|
|
4678
4560
|
const property = path.get('property').node;
|
|
4679
4561
|
const computed = path.node.computed;
|
|
@@ -4688,11 +4570,40 @@ function transformStyleXMerge(path, state) {
|
|
|
4688
4570
|
propName = property.value;
|
|
4689
4571
|
}
|
|
4690
4572
|
}
|
|
4573
|
+
let styleNonNullProps = [];
|
|
4574
|
+
if (bailOutIndex != null && index > bailOutIndex) {
|
|
4575
|
+
nonNullProps = true;
|
|
4576
|
+
styleNonNullProps = true;
|
|
4577
|
+
}
|
|
4578
|
+
if (nonNullProps === true) {
|
|
4579
|
+
styleNonNullProps = true;
|
|
4580
|
+
} else {
|
|
4581
|
+
const {
|
|
4582
|
+
confident,
|
|
4583
|
+
value: styleValue
|
|
4584
|
+
} = evaluate(path, state);
|
|
4585
|
+
if (!confident) {
|
|
4586
|
+
nonNullProps = true;
|
|
4587
|
+
styleNonNullProps = true;
|
|
4588
|
+
} else {
|
|
4589
|
+
styleNonNullProps = nonNullProps === true ? true : [...nonNullProps];
|
|
4590
|
+
if (nonNullProps !== true) {
|
|
4591
|
+
nonNullProps = [...nonNullProps, ...Object.keys(styleValue).filter(key => styleValue[key] !== null)];
|
|
4592
|
+
}
|
|
4593
|
+
}
|
|
4594
|
+
}
|
|
4691
4595
|
if (objName != null) {
|
|
4692
|
-
state.styleVarsToKeep.add([objName, propName != null ? String(propName) :
|
|
4596
|
+
state.styleVarsToKeep.add([objName, propName != null ? String(propName) : true, styleNonNullProps]);
|
|
4693
4597
|
}
|
|
4694
4598
|
}
|
|
4695
|
-
|
|
4599
|
+
if (isMemberExpression(argPath)) {
|
|
4600
|
+
MemberExpression(argPath);
|
|
4601
|
+
} else {
|
|
4602
|
+
argPath.traverse({
|
|
4603
|
+
MemberExpression
|
|
4604
|
+
});
|
|
4605
|
+
}
|
|
4606
|
+
}
|
|
4696
4607
|
} else {
|
|
4697
4608
|
path.skip();
|
|
4698
4609
|
const stringExpression = makeStringExpression$1(resolvedArgs);
|
|
@@ -4788,13 +4699,17 @@ function transformStylexProps(path, state) {
|
|
|
4788
4699
|
let bailOut = false;
|
|
4789
4700
|
let conditional = 0;
|
|
4790
4701
|
const args = node.arguments.flatMap(arg => arg.type === 'ArrayExpression' ? arg.elements : [arg]);
|
|
4702
|
+
let currentIndex = -1;
|
|
4703
|
+
let bailOutIndex = null;
|
|
4791
4704
|
const resolvedArgs = [];
|
|
4792
4705
|
for (const arg of args) {
|
|
4706
|
+
currentIndex++;
|
|
4793
4707
|
switch (arg.type) {
|
|
4794
4708
|
case 'MemberExpression':
|
|
4795
4709
|
{
|
|
4796
4710
|
const resolved = parseNullableStyle(arg, state);
|
|
4797
4711
|
if (resolved === 'other') {
|
|
4712
|
+
bailOutIndex = currentIndex;
|
|
4798
4713
|
bailOut = true;
|
|
4799
4714
|
} else {
|
|
4800
4715
|
resolvedArgs.push(resolved);
|
|
@@ -4811,6 +4726,7 @@ function transformStylexProps(path, state) {
|
|
|
4811
4726
|
const primary = parseNullableStyle(consequent, state);
|
|
4812
4727
|
const fallback = parseNullableStyle(alternate, state);
|
|
4813
4728
|
if (primary === 'other' || fallback === 'other') {
|
|
4729
|
+
bailOutIndex = currentIndex;
|
|
4814
4730
|
bailOut = true;
|
|
4815
4731
|
} else {
|
|
4816
4732
|
resolvedArgs.push([test, primary, fallback]);
|
|
@@ -4821,6 +4737,7 @@ function transformStylexProps(path, state) {
|
|
|
4821
4737
|
case 'LogicalExpression':
|
|
4822
4738
|
{
|
|
4823
4739
|
if (arg.operator !== '&&') {
|
|
4740
|
+
bailOutIndex = currentIndex;
|
|
4824
4741
|
bailOut = true;
|
|
4825
4742
|
break;
|
|
4826
4743
|
}
|
|
@@ -4831,6 +4748,7 @@ function transformStylexProps(path, state) {
|
|
|
4831
4748
|
const leftResolved = parseNullableStyle(left, state);
|
|
4832
4749
|
const rightResolved = parseNullableStyle(right, state);
|
|
4833
4750
|
if (leftResolved !== 'other' || rightResolved === 'other') {
|
|
4751
|
+
bailOutIndex = currentIndex;
|
|
4834
4752
|
bailOut = true;
|
|
4835
4753
|
} else {
|
|
4836
4754
|
resolvedArgs.push([left, rightResolved, null]);
|
|
@@ -4839,6 +4757,7 @@ function transformStylexProps(path, state) {
|
|
|
4839
4757
|
break;
|
|
4840
4758
|
}
|
|
4841
4759
|
default:
|
|
4760
|
+
bailOutIndex = currentIndex;
|
|
4842
4761
|
bailOut = true;
|
|
4843
4762
|
break;
|
|
4844
4763
|
}
|
|
@@ -4853,8 +4772,12 @@ function transformStylexProps(path, state) {
|
|
|
4853
4772
|
bailOut = true;
|
|
4854
4773
|
}
|
|
4855
4774
|
if (bailOut) {
|
|
4856
|
-
path.
|
|
4857
|
-
|
|
4775
|
+
const argumentPaths = path.get('arguments');
|
|
4776
|
+
let nonNullProps = [];
|
|
4777
|
+
let index = -1;
|
|
4778
|
+
for (const argPath of argumentPaths) {
|
|
4779
|
+
index++;
|
|
4780
|
+
function MemberExpression(path) {
|
|
4858
4781
|
const object = path.get('object').node;
|
|
4859
4782
|
const property = path.get('property').node;
|
|
4860
4783
|
const computed = path.node.computed;
|
|
@@ -4869,11 +4792,40 @@ function transformStylexProps(path, state) {
|
|
|
4869
4792
|
propName = property.value;
|
|
4870
4793
|
}
|
|
4871
4794
|
}
|
|
4795
|
+
let styleNonNullProps = [];
|
|
4796
|
+
if (bailOutIndex != null && index > bailOutIndex) {
|
|
4797
|
+
nonNullProps = true;
|
|
4798
|
+
styleNonNullProps = true;
|
|
4799
|
+
}
|
|
4800
|
+
if (nonNullProps === true) {
|
|
4801
|
+
styleNonNullProps = true;
|
|
4802
|
+
} else {
|
|
4803
|
+
const {
|
|
4804
|
+
confident,
|
|
4805
|
+
value: styleValue
|
|
4806
|
+
} = evaluate(path, state);
|
|
4807
|
+
if (!confident) {
|
|
4808
|
+
nonNullProps = true;
|
|
4809
|
+
styleNonNullProps = true;
|
|
4810
|
+
} else {
|
|
4811
|
+
styleNonNullProps = nonNullProps === true ? true : [...nonNullProps];
|
|
4812
|
+
if (nonNullProps !== true) {
|
|
4813
|
+
nonNullProps = [...nonNullProps, ...Object.keys(styleValue).filter(key => styleValue[key] !== null)];
|
|
4814
|
+
}
|
|
4815
|
+
}
|
|
4816
|
+
}
|
|
4872
4817
|
if (objName != null) {
|
|
4873
|
-
state.styleVarsToKeep.add([objName, propName != null ? String(propName) :
|
|
4818
|
+
state.styleVarsToKeep.add([objName, propName != null ? String(propName) : true, styleNonNullProps]);
|
|
4874
4819
|
}
|
|
4875
4820
|
}
|
|
4876
|
-
|
|
4821
|
+
if (isMemberExpression(argPath)) {
|
|
4822
|
+
MemberExpression(argPath);
|
|
4823
|
+
} else {
|
|
4824
|
+
argPath.traverse({
|
|
4825
|
+
MemberExpression
|
|
4826
|
+
});
|
|
4827
|
+
}
|
|
4828
|
+
}
|
|
4877
4829
|
} else {
|
|
4878
4830
|
path.skip();
|
|
4879
4831
|
const stringExpression = makeStringExpression(resolvedArgs);
|
|
@@ -5003,12 +4955,77 @@ function styleXTransform() {
|
|
|
5003
4955
|
transformStylexProps(path, state);
|
|
5004
4956
|
}
|
|
5005
4957
|
});
|
|
5006
|
-
const varsToKeep =
|
|
4958
|
+
const varsToKeep = {};
|
|
4959
|
+
for (const [varName, namespaceName] of state.styleVarsToKeep) {
|
|
4960
|
+
if (varsToKeep[varName] === true) {
|
|
4961
|
+
continue;
|
|
4962
|
+
}
|
|
4963
|
+
if (varsToKeep[varName] == null) {
|
|
4964
|
+
varsToKeep[varName] = namespaceName === true ? true : [namespaceName];
|
|
4965
|
+
} else if (Array.isArray(varsToKeep[varName])) {
|
|
4966
|
+
if (namespaceName === true) {
|
|
4967
|
+
varsToKeep[varName] = true;
|
|
4968
|
+
} else {
|
|
4969
|
+
varsToKeep[varName].push(namespaceName);
|
|
4970
|
+
}
|
|
4971
|
+
}
|
|
4972
|
+
}
|
|
4973
|
+
const varsToKeepOld = new Set([...state.styleVarsToKeep.values()].map(_ref => {
|
|
5007
4974
|
let [varName, _namespaceName] = _ref;
|
|
5008
4975
|
return varName;
|
|
5009
4976
|
}));
|
|
5010
4977
|
state.styleVars.forEach((path, varName) => {
|
|
5011
|
-
if (
|
|
4978
|
+
if (isExported(path)) {
|
|
4979
|
+
return;
|
|
4980
|
+
}
|
|
4981
|
+
if (varsToKeep[varName] === true) {
|
|
4982
|
+
return;
|
|
4983
|
+
}
|
|
4984
|
+
const namespacesToKeep = varsToKeep[varName];
|
|
4985
|
+
if (namespacesToKeep == null) {
|
|
4986
|
+
path.remove();
|
|
4987
|
+
return;
|
|
4988
|
+
}
|
|
4989
|
+
if (isVariableDeclarator(path)) {
|
|
4990
|
+
const init = path.get('init');
|
|
4991
|
+
if (init != null && isObjectExpression(init)) {
|
|
4992
|
+
for (const prop of init.get('properties')) {
|
|
4993
|
+
if (isObjectProperty(prop)) {
|
|
4994
|
+
const key = prop.get('key').node;
|
|
4995
|
+
const keyAsString = key.type === 'Identifier' ? key.name : key.type === 'StringLiteral' ? key.value : key.type === 'NumericLiteral' ? String(key.value) : null;
|
|
4996
|
+
if (keyAsString != null) {
|
|
4997
|
+
if (!namespacesToKeep.includes(keyAsString)) {
|
|
4998
|
+
prop.remove();
|
|
4999
|
+
} else {
|
|
5000
|
+
const allNullsToKeep = [...state.styleVarsToKeep.values()].filter(_ref2 => {
|
|
5001
|
+
let [v, namespaceName] = _ref2;
|
|
5002
|
+
return v === varName && namespaceName === keyAsString;
|
|
5003
|
+
}).map(_ref3 => {
|
|
5004
|
+
let [_v, _namespaceName, nullPropsToKeep] = _ref3;
|
|
5005
|
+
return nullPropsToKeep;
|
|
5006
|
+
});
|
|
5007
|
+
if (!allNullsToKeep.includes(true)) {
|
|
5008
|
+
const nullsToKeep = new Set(allNullsToKeep.filter(x => x !== true).flat());
|
|
5009
|
+
const styleObject = prop.get('value');
|
|
5010
|
+
if (isObjectExpression(styleObject)) {
|
|
5011
|
+
for (const styleProp of styleObject.get('properties')) {
|
|
5012
|
+
if (isObjectProperty(styleProp) && isNullLiteral(styleProp.get('value'))) {
|
|
5013
|
+
const styleKey = styleProp.get('key').node;
|
|
5014
|
+
const styleKeyAsString = styleKey.type === 'Identifier' ? styleKey.name : styleKey.type === 'StringLiteral' ? styleKey.value : styleKey.type === 'NumericLiteral' ? String(styleKey.value) : null;
|
|
5015
|
+
if (styleKeyAsString != null && !nullsToKeep.has(styleKeyAsString)) {
|
|
5016
|
+
styleProp.remove();
|
|
5017
|
+
}
|
|
5018
|
+
}
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
}
|
|
5022
|
+
}
|
|
5023
|
+
}
|
|
5024
|
+
}
|
|
5025
|
+
}
|
|
5026
|
+
}
|
|
5027
|
+
}
|
|
5028
|
+
if (!varsToKeepOld.has(varName) && !isExported(path)) {
|
|
5012
5029
|
path.remove();
|
|
5013
5030
|
}
|
|
5014
5031
|
});
|
|
@@ -5031,14 +5048,16 @@ function styleXTransform() {
|
|
|
5031
5048
|
computed
|
|
5032
5049
|
} = parentPath.node;
|
|
5033
5050
|
if (property.type === 'Identifier' && !computed) {
|
|
5034
|
-
state.markComposedNamespace([name, property.name]);
|
|
5035
|
-
}
|
|
5036
|
-
|
|
5037
|
-
|
|
5051
|
+
state.markComposedNamespace([name, property.name, true]);
|
|
5052
|
+
} else if (property.type === 'StringLiteral' && computed) {
|
|
5053
|
+
state.markComposedNamespace([name, property.value, true]);
|
|
5054
|
+
} else if (property.type === 'NumericLiteral' && computed) {
|
|
5055
|
+
state.markComposedNamespace([name, String(property.value), true]);
|
|
5056
|
+
} else {
|
|
5057
|
+
state.markComposedNamespace([name, true, true]);
|
|
5038
5058
|
}
|
|
5039
|
-
state.markComposedNamespace([name, null]);
|
|
5040
5059
|
} else {
|
|
5041
|
-
state.markComposedNamespace([name,
|
|
5060
|
+
state.markComposedNamespace([name, true, true]);
|
|
5042
5061
|
}
|
|
5043
5062
|
}
|
|
5044
5063
|
}
|
|
@@ -5046,9 +5065,10 @@ function styleXTransform() {
|
|
|
5046
5065
|
}
|
|
5047
5066
|
};
|
|
5048
5067
|
}
|
|
5049
|
-
|
|
5068
|
+
function stylexPluginWithOptions(options) {
|
|
5050
5069
|
return [styleXTransform, options];
|
|
5051
|
-
}
|
|
5070
|
+
}
|
|
5071
|
+
styleXTransform.withOptions = stylexPluginWithOptions;
|
|
5052
5072
|
function isExported(path) {
|
|
5053
5073
|
if (path == null || isProgram(path)) {
|
|
5054
5074
|
return false;
|
|
@@ -5063,13 +5083,13 @@ function processStylexRules(rules) {
|
|
|
5063
5083
|
if (rules.length === 0) {
|
|
5064
5084
|
return '';
|
|
5065
5085
|
}
|
|
5066
|
-
const sortedRules = rules.sort((
|
|
5086
|
+
const sortedRules = rules.sort((_ref4, _ref5) => {
|
|
5067
5087
|
let [_1, {
|
|
5068
5088
|
ltr: rule1
|
|
5069
|
-
}, firstPriority] =
|
|
5089
|
+
}, firstPriority] = _ref4;
|
|
5070
5090
|
let [_2, {
|
|
5071
5091
|
ltr: rule2
|
|
5072
|
-
}, secondPriority] =
|
|
5092
|
+
}, secondPriority] = _ref5;
|
|
5073
5093
|
const priorityComparison = firstPriority - secondPriority;
|
|
5074
5094
|
if (priorityComparison !== 0) return priorityComparison;
|
|
5075
5095
|
if (rule1.startsWith('@') && !rule2.startsWith('@')) {
|
|
@@ -5098,14 +5118,14 @@ function processStylexRules(rules) {
|
|
|
5098
5118
|
}, []);
|
|
5099
5119
|
const header = useLayers ? '\n@layer ' + grouped.map((_, index) => `priority${index + 1}`).join(', ') + ';\n' : '';
|
|
5100
5120
|
const collectedCSS = grouped.map((group, index) => {
|
|
5101
|
-
const collectedCSS = Array.from(new Map(group.map(
|
|
5102
|
-
let [a, b, _c] =
|
|
5121
|
+
const collectedCSS = Array.from(new Map(group.map(_ref6 => {
|
|
5122
|
+
let [a, b, _c] = _ref6;
|
|
5103
5123
|
return [a, b];
|
|
5104
|
-
})).values()).flatMap(
|
|
5124
|
+
})).values()).flatMap(_ref7 => {
|
|
5105
5125
|
let {
|
|
5106
5126
|
ltr,
|
|
5107
5127
|
rtl
|
|
5108
|
-
} =
|
|
5128
|
+
} = _ref7;
|
|
5109
5129
|
let ltrRule = ltr,
|
|
5110
5130
|
rtlRule = rtl;
|
|
5111
5131
|
if (!useLayers) {
|
|
@@ -5137,7 +5157,7 @@ function addSpecificityLevel(selector, index) {
|
|
|
5137
5157
|
return selector;
|
|
5138
5158
|
}
|
|
5139
5159
|
const pseudo = Array.from({
|
|
5140
|
-
length: index
|
|
5160
|
+
length: index
|
|
5141
5161
|
}).map(() => ':not(#\\#)').join('');
|
|
5142
5162
|
const lastOpenCurly = selector.includes('::') ? selector.indexOf('::') : selector.lastIndexOf('{');
|
|
5143
5163
|
const beforeCurly = selector.slice(0, lastOpenCurly);
|