@stylexjs/shared 0.12.0 → 0.17.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/lib/index.d.ts +10 -36
- package/lib/index.js +8 -25
- package/lib/index.js.flow +10 -43
- package/lib/utils/property-priorities.d.ts +4 -0
- package/lib/utils/property-priorities.js +54 -8
- package/lib/utils/property-priorities.js.flow +8 -0
- package/package.json +5 -21
- package/README.md +0 -81
- package/lib/common-types.d.ts +0 -50
- package/lib/common-types.js +0 -1
- package/lib/common-types.js.flow +0 -63
- package/lib/convert-to-className.d.ts +0 -20
- package/lib/convert-to-className.js +0 -66
- package/lib/convert-to-className.js.flow +0 -27
- package/lib/generate-css-rule.d.ts +0 -17
- package/lib/generate-css-rule.js +0 -25
- package/lib/generate-css-rule.js.flow +0 -17
- package/lib/hash.d.ts +0 -12
- package/lib/hash.js +0 -50
- package/lib/hash.js.flow +0 -12
- package/lib/messages.d.ts +0 -42
- package/lib/messages.js +0 -39
- package/lib/messages.js.flow +0 -45
- package/lib/physical-rtl/generate-ltr.d.ts +0 -13
- package/lib/physical-rtl/generate-ltr.js +0 -103
- package/lib/physical-rtl/generate-ltr.js.flow +0 -12
- package/lib/physical-rtl/generate-rtl.d.ts +0 -13
- package/lib/physical-rtl/generate-rtl.js +0 -177
- package/lib/physical-rtl/generate-rtl.js.flow +0 -12
- package/lib/preprocess-rules/PreRule.d.ts +0 -50
- package/lib/preprocess-rules/PreRule.js +0 -76
- package/lib/preprocess-rules/PreRule.js.flow +0 -62
- package/lib/preprocess-rules/application-order.d.ts +0 -183
- package/lib/preprocess-rules/application-order.js +0 -186
- package/lib/preprocess-rules/application-order.js.flow +0 -134
- package/lib/preprocess-rules/basic-validation.d.ts +0 -13
- package/lib/preprocess-rules/basic-validation.js +0 -73
- package/lib/preprocess-rules/basic-validation.js.flow +0 -13
- package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +0 -20
- package/lib/preprocess-rules/flatten-raw-style-obj.js +0 -98
- package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +0 -23
- package/lib/preprocess-rules/index.d.ts +0 -18
- package/lib/preprocess-rules/index.js +0 -33
- package/lib/preprocess-rules/index.js.flow +0 -22
- package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +0 -165
- package/lib/preprocess-rules/legacy-expand-shorthands.js +0 -147
- package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +0 -144
- package/lib/preprocess-rules/property-specificity.d.ts +0 -78
- package/lib/preprocess-rules/property-specificity.js +0 -107
- package/lib/preprocess-rules/property-specificity.js.flow +0 -87
- package/lib/stylex-consts-utils.d.ts +0 -11
- package/lib/stylex-consts-utils.js +0 -1
- package/lib/stylex-consts-utils.js.flow +0 -14
- package/lib/stylex-create-theme.d.ts +0 -26
- package/lib/stylex-create-theme.js +0 -58
- package/lib/stylex-create-theme.js.flow +0 -19
- package/lib/stylex-create.d.ts +0 -27
- package/lib/stylex-create.js +0 -64
- package/lib/stylex-create.js.flow +0 -37
- package/lib/stylex-define-consts.d.ts +0 -23
- package/lib/stylex-define-consts.js +0 -42
- package/lib/stylex-define-consts.js.flow +0 -18
- package/lib/stylex-define-vars.d.ts +0 -28
- package/lib/stylex-define-vars.js +0 -96
- package/lib/stylex-define-vars.js.flow +0 -27
- package/lib/stylex-first-that-works.d.ts +0 -13
- package/lib/stylex-first-that-works.js +0 -26
- package/lib/stylex-first-that-works.js.flow +0 -12
- package/lib/stylex-include.d.ts +0 -18
- package/lib/stylex-include.js +0 -28
- package/lib/stylex-include.js.flow +0 -20
- package/lib/stylex-keyframes.d.ts +0 -17
- package/lib/stylex-keyframes.js +0 -55
- package/lib/stylex-keyframes.js.flow +0 -20
- package/lib/stylex-vars-utils.d.ts +0 -27
- package/lib/stylex-vars-utils.js +0 -69
- package/lib/stylex-vars-utils.js.flow +0 -31
- package/lib/transform-value.d.ts +0 -22
- package/lib/transform-value.js +0 -50
- package/lib/transform-value.js.flow +0 -25
- package/lib/types/index.d.ts +0 -240
- package/lib/types/index.js +0 -147
- package/lib/types/index.js.flow +0 -280
- package/lib/utils/Rule.d.ts +0 -58
- package/lib/utils/Rule.js +0 -50
- package/lib/utils/Rule.js.flow +0 -64
- package/lib/utils/dashify.d.ts +0 -11
- package/lib/utils/dashify.js +0 -9
- package/lib/utils/dashify.js.flow +0 -10
- package/lib/utils/default-options.d.ts +0 -11
- package/lib/utils/default-options.js +0 -17
- package/lib/utils/default-options.js.flow +0 -12
- package/lib/utils/file-based-identifier.d.ts +0 -15
- package/lib/utils/file-based-identifier.js +0 -14
- package/lib/utils/file-based-identifier.js.flow +0 -14
- package/lib/utils/genCSSRule.d.ts +0 -15
- package/lib/utils/genCSSRule.js +0 -15
- package/lib/utils/genCSSRule.js.flow +0 -15
- package/lib/utils/media-query-transform.d.ts +0 -16
- package/lib/utils/media-query-transform.js +0 -53
- package/lib/utils/media-query-transform.js.flow +0 -20
- package/lib/utils/normalize-value.d.ts +0 -16
- package/lib/utils/normalize-value.js +0 -28
- package/lib/utils/normalize-value.js.flow +0 -16
- package/lib/utils/normalizers/convert-camel-case-values.d.ts +0 -14
- package/lib/utils/normalizers/convert-camel-case-values.js +0 -23
- package/lib/utils/normalizers/convert-camel-case-values.js.flow +0 -13
- package/lib/utils/normalizers/detect-unclosed-fns.d.ts +0 -17
- package/lib/utils/normalizers/detect-unclosed-fns.js +0 -17
- package/lib/utils/normalizers/detect-unclosed-fns.js.flow +0 -16
- package/lib/utils/normalizers/font-size-px-to-rem.d.ts +0 -19
- package/lib/utils/normalizers/font-size-px-to-rem.js +0 -24
- package/lib/utils/normalizers/font-size-px-to-rem.js.flow +0 -18
- package/lib/utils/normalizers/leading-zero.d.ts +0 -17
- package/lib/utils/normalizers/leading-zero.js +0 -24
- package/lib/utils/normalizers/leading-zero.js.flow +0 -16
- package/lib/utils/normalizers/quotes.d.ts +0 -18
- package/lib/utils/normalizers/quotes.js +0 -17
- package/lib/utils/normalizers/quotes.js.flow +0 -17
- package/lib/utils/normalizers/timings.d.ts +0 -18
- package/lib/utils/normalizers/timings.js +0 -25
- package/lib/utils/normalizers/timings.js.flow +0 -17
- package/lib/utils/normalizers/whitespace.d.ts +0 -19
- package/lib/utils/normalizers/whitespace.js +0 -54
- package/lib/utils/normalizers/whitespace.js.flow +0 -18
- package/lib/utils/normalizers/zero-dimensions.d.ts +0 -19
- package/lib/utils/normalizers/zero-dimensions.js +0 -42
- package/lib/utils/normalizers/zero-dimensions.js.flow +0 -18
- package/lib/utils/object-utils.d.ts +0 -66
- package/lib/utils/object-utils.js +0 -99
- package/lib/utils/object-utils.js.flow +0 -78
- package/lib/utils/rule-utils.d.ts +0 -15
- package/lib/utils/rule-utils.js +0 -41
- package/lib/utils/rule-utils.js.flow +0 -16
- package/lib/utils/split-css-value.d.ts +0 -14
- package/lib/utils/split-css-value.js +0 -33
- package/lib/utils/split-css-value.js.flow +0 -15
- package/lib/validate.d.ts +0 -12
- package/lib/validate.js +0 -21
- package/lib/validate.js.flow +0 -12
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type {
|
|
11
|
-
RawStyles,
|
|
12
|
-
InjectableStyle,
|
|
13
|
-
StyleXOptions,
|
|
14
|
-
FlatCompiledStyles,
|
|
15
|
-
} from './common-types';
|
|
16
|
-
type ClassPathsInNamespace = {
|
|
17
|
-
+[className: string]: $ReadOnlyArray<string>,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// This takes the object of styles passed to `stylex.create` and transforms it.
|
|
21
|
-
// The transformation replaces style values with classNames.
|
|
22
|
-
//
|
|
23
|
-
// It also collects all injected styles along the way.
|
|
24
|
-
// It then returns a tuple of the transformed style Object and an object of injected styles.
|
|
25
|
-
//
|
|
26
|
-
// This function does some basic validation, and then uses `styleXCreateNamespace` to transform
|
|
27
|
-
// each namespace within,
|
|
28
|
-
//
|
|
29
|
-
// Before returning, it ensures that there are no duplicate styles being injected.
|
|
30
|
-
declare export default function styleXCreateSet(
|
|
31
|
-
namespaces: { +[string]: RawStyles },
|
|
32
|
-
options?: StyleXOptions,
|
|
33
|
-
): [
|
|
34
|
-
{ [string]: FlatCompiledStyles },
|
|
35
|
-
{ [string]: InjectableStyle },
|
|
36
|
-
{ +[string]: ClassPathsInNamespace },
|
|
37
|
-
];
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { InjectableConstStyle, StyleXOptions } from './common-types';
|
|
11
|
-
import type { ConstsConfig } from './stylex-consts-utils';
|
|
12
|
-
declare function styleXDefineConsts<Vars extends ConstsConfig>(
|
|
13
|
-
constants: Vars,
|
|
14
|
-
options: Readonly<
|
|
15
|
-
Omit<Partial<StyleXOptions>, keyof ({ themeName: string })> & {
|
|
16
|
-
themeName: string;
|
|
17
|
-
}
|
|
18
|
-
>,
|
|
19
|
-
): [
|
|
20
|
-
{ [$$Key$$: string]: string | number },
|
|
21
|
-
{ [$$Key$$: string]: InjectableConstStyle },
|
|
22
|
-
];
|
|
23
|
-
export default styleXDefineConsts;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = styleXDefineConsts;
|
|
7
|
-
var _defaultOptions = require("./utils/default-options");
|
|
8
|
-
var messages = _interopRequireWildcard(require("./messages"));
|
|
9
|
-
var _hash = _interopRequireDefault(require("./hash"));
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
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); }
|
|
12
|
-
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 && {}.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; }
|
|
13
|
-
function styleXDefineConsts(constants, options) {
|
|
14
|
-
const {
|
|
15
|
-
classNamePrefix,
|
|
16
|
-
themeName,
|
|
17
|
-
debug,
|
|
18
|
-
enableDebugClassNames
|
|
19
|
-
} = {
|
|
20
|
-
..._defaultOptions.defaultOptions,
|
|
21
|
-
...options
|
|
22
|
-
};
|
|
23
|
-
const jsOutput = {};
|
|
24
|
-
const injectableStyles = {};
|
|
25
|
-
for (const [key, value] of Object.entries(constants)) {
|
|
26
|
-
if (key.startsWith('--')) {
|
|
27
|
-
throw new Error(messages.INVALID_CONST_KEY);
|
|
28
|
-
}
|
|
29
|
-
const varSafeKey = (key[0] >= '0' && key[0] <= '9' ? `_${key}` : key).replace(/[^a-zA-Z0-9]/g, '_');
|
|
30
|
-
const nameHash = debug && enableDebugClassNames ? `${varSafeKey}-${classNamePrefix}${(0, _hash.default)(`${themeName}.${key}`)}` : `${classNamePrefix}${(0, _hash.default)(`${themeName}.${key}`)}`;
|
|
31
|
-
jsOutput[key] = value;
|
|
32
|
-
injectableStyles[nameHash] = {
|
|
33
|
-
key: nameHash,
|
|
34
|
-
constKey: varSafeKey,
|
|
35
|
-
constVal: value,
|
|
36
|
-
priority: 0,
|
|
37
|
-
ltr: '',
|
|
38
|
-
rtl: null
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
return [jsOutput, injectableStyles];
|
|
42
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { InjectableConstStyle, StyleXOptions } from './common-types';
|
|
11
|
-
import type { ConstsConfig } from './stylex-consts-utils';
|
|
12
|
-
declare export default function styleXDefineConsts<Vars: ConstsConfig>(
|
|
13
|
-
constants: Vars,
|
|
14
|
-
options: $ReadOnly<{ ...Partial<StyleXOptions>, themeName: string, ... }>,
|
|
15
|
-
): [
|
|
16
|
-
{ [string]: string | number }, // jsOutput JS output
|
|
17
|
-
{ [string]: InjectableConstStyle }, // metadata for registerinjectableStyles
|
|
18
|
-
];
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { InjectableStyle, StyleXOptions } from './common-types';
|
|
11
|
-
import type { VarsConfig } from './stylex-vars-utils';
|
|
12
|
-
type VarsKeysWithStringValues<Vars extends VarsConfig> = Readonly<{
|
|
13
|
-
[$$Key$$: keyof Vars]: string;
|
|
14
|
-
}>;
|
|
15
|
-
type VarsObject<Vars extends VarsConfig> = Readonly<
|
|
16
|
-
Omit<VarsKeysWithStringValues<Vars>, keyof ({ __themeName__: string })> & {
|
|
17
|
-
__themeName__: string;
|
|
18
|
-
}
|
|
19
|
-
>;
|
|
20
|
-
declare function styleXDefineVars<Vars extends VarsConfig>(
|
|
21
|
-
variables: Vars,
|
|
22
|
-
options: Readonly<
|
|
23
|
-
Omit<Partial<StyleXOptions>, keyof ({ themeName: string })> & {
|
|
24
|
-
themeName: string;
|
|
25
|
-
}
|
|
26
|
-
>,
|
|
27
|
-
): [VarsObject<Vars>, { [$$Key$$: string]: InjectableStyle }];
|
|
28
|
-
export default styleXDefineVars;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = styleXDefineVars;
|
|
7
|
-
var _hash = _interopRequireDefault(require("./hash"));
|
|
8
|
-
var _objectUtils = require("./utils/object-utils");
|
|
9
|
-
var _defaultOptions = require("./utils/default-options");
|
|
10
|
-
var _stylexVarsUtils = require("./stylex-vars-utils");
|
|
11
|
-
var _types = require("./types");
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
function styleXDefineVars(variables, options) {
|
|
14
|
-
const {
|
|
15
|
-
classNamePrefix,
|
|
16
|
-
themeName,
|
|
17
|
-
debug,
|
|
18
|
-
enableDebugClassNames
|
|
19
|
-
} = {
|
|
20
|
-
..._defaultOptions.defaultOptions,
|
|
21
|
-
...options
|
|
22
|
-
};
|
|
23
|
-
const themeNameHash = classNamePrefix + (0, _hash.default)(themeName);
|
|
24
|
-
const typedVariables = {};
|
|
25
|
-
const variablesMap = (0, _objectUtils.objMap)(variables, (value, key) => {
|
|
26
|
-
const varSafeKey = (key[0] >= '0' && key[0] <= '9' ? `_${key}` : key).replace(/[^a-zA-Z0-9]/g, '_');
|
|
27
|
-
const nameHash = key.startsWith('--') ? key.slice(2) : debug && enableDebugClassNames ? varSafeKey + '-' + classNamePrefix + (0, _hash.default)(`${themeName}.${key}`) : classNamePrefix + (0, _hash.default)(`${themeName}.${key}`);
|
|
28
|
-
if ((0, _types.isCSSType)(value)) {
|
|
29
|
-
const v = value;
|
|
30
|
-
typedVariables[nameHash] = {
|
|
31
|
-
initialValue: (0, _stylexVarsUtils.getDefaultValue)(v.value),
|
|
32
|
-
syntax: v.syntax
|
|
33
|
-
};
|
|
34
|
-
return {
|
|
35
|
-
nameHash,
|
|
36
|
-
value: v.value
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
nameHash,
|
|
41
|
-
value: value
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
const themeVariablesObject = (0, _objectUtils.objMap)(variablesMap, _ref => {
|
|
45
|
-
let {
|
|
46
|
-
nameHash
|
|
47
|
-
} = _ref;
|
|
48
|
-
return `var(--${nameHash})`;
|
|
49
|
-
});
|
|
50
|
-
const injectableStyles = constructCssVariablesString(variablesMap, themeNameHash);
|
|
51
|
-
const injectableTypes = (0, _objectUtils.objMap)(typedVariables, (_ref2, nameHash) => {
|
|
52
|
-
let {
|
|
53
|
-
initialValue: iv,
|
|
54
|
-
syntax
|
|
55
|
-
} = _ref2;
|
|
56
|
-
return {
|
|
57
|
-
ltr: `@property --${nameHash} { syntax: "${syntax}"; inherits: true;${iv != null ? ` initial-value: ${iv}` : ''} }`,
|
|
58
|
-
rtl: null,
|
|
59
|
-
priority: 0
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
return [{
|
|
63
|
-
...themeVariablesObject,
|
|
64
|
-
__themeName__: themeNameHash
|
|
65
|
-
}, {
|
|
66
|
-
...injectableTypes,
|
|
67
|
-
...injectableStyles
|
|
68
|
-
}];
|
|
69
|
-
}
|
|
70
|
-
function constructCssVariablesString(variables, themeNameHash) {
|
|
71
|
-
const rulesByAtRule = {};
|
|
72
|
-
for (const [key, {
|
|
73
|
-
nameHash,
|
|
74
|
-
value
|
|
75
|
-
}] of Object.entries(variables)) {
|
|
76
|
-
(0, _stylexVarsUtils.collectVarsByAtRule)(key, {
|
|
77
|
-
nameHash,
|
|
78
|
-
value
|
|
79
|
-
}, rulesByAtRule);
|
|
80
|
-
}
|
|
81
|
-
const result = {};
|
|
82
|
-
for (const [atRule, value] of Object.entries(rulesByAtRule)) {
|
|
83
|
-
const suffix = atRule === 'default' ? '' : `-${(0, _hash.default)(atRule)}`;
|
|
84
|
-
const selector = `:root, .${themeNameHash}`;
|
|
85
|
-
let ltr = `${selector}{${value.join('')}}`;
|
|
86
|
-
if (atRule !== 'default') {
|
|
87
|
-
ltr = (0, _stylexVarsUtils.wrapWithAtRules)(ltr, atRule);
|
|
88
|
-
}
|
|
89
|
-
result[themeNameHash + suffix] = {
|
|
90
|
-
ltr,
|
|
91
|
-
rtl: null,
|
|
92
|
-
priority: (0, _stylexVarsUtils.priorityForAtRule)(atRule) * 0.1
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { InjectableStyle, StyleXOptions } from './common-types';
|
|
11
|
-
import type { VarsConfig } from './stylex-vars-utils';
|
|
12
|
-
|
|
13
|
-
type VarsKeysWithStringValues<Vars: VarsConfig> = $ReadOnly<{
|
|
14
|
-
[$Keys<Vars>]: string,
|
|
15
|
-
}>;
|
|
16
|
-
|
|
17
|
-
type VarsObject<Vars: VarsConfig> = $ReadOnly<{
|
|
18
|
-
...VarsKeysWithStringValues<Vars>,
|
|
19
|
-
__themeName__: string,
|
|
20
|
-
}>;
|
|
21
|
-
|
|
22
|
-
// Similar to `stylex.create` it takes an object of variables with their values
|
|
23
|
-
// and returns a string after hashing it.
|
|
24
|
-
declare export default function styleXDefineVars<Vars: VarsConfig>(
|
|
25
|
-
variables: Vars,
|
|
26
|
-
options: $ReadOnly<{ ...Partial<StyleXOptions>, themeName: string, ... }>,
|
|
27
|
-
): [VarsObject<Vars>, { [string]: InjectableStyle }];
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
declare function stylexFirstThatWorks(
|
|
11
|
-
...args: ReadonlyArray<string>
|
|
12
|
-
): ReadonlyArray<string> | string;
|
|
13
|
-
export default stylexFirstThatWorks;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = stylexFirstThatWorks;
|
|
7
|
-
const isVar = arg => typeof arg === 'string' && arg.match(/^var\(--[a-zA-Z0-9-_]+\)$/);
|
|
8
|
-
function stylexFirstThatWorks() {
|
|
9
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
-
args[_key] = arguments[_key];
|
|
11
|
-
}
|
|
12
|
-
const firstVar = args.findIndex(isVar);
|
|
13
|
-
if (firstVar === -1) {
|
|
14
|
-
return [...args].reverse();
|
|
15
|
-
}
|
|
16
|
-
const priorities = args.slice(0, firstVar).reverse();
|
|
17
|
-
const rest = args.slice(firstVar);
|
|
18
|
-
const firstNonVar = rest.findIndex(arg => !isVar(arg));
|
|
19
|
-
const varParts = rest.slice(0, firstNonVar === -1 ? rest.length : firstNonVar + 1).reverse();
|
|
20
|
-
const vars = varParts.map(arg => isVar(arg) ? arg.slice(4, -1) : arg);
|
|
21
|
-
const returnValue = [vars.reduce((soFar, varName) => soFar ? `var(${varName}, ${String(soFar)})` : varName.startsWith('--') ? `var(${varName})` : varName, ''), ...priorities];
|
|
22
|
-
if (returnValue.length === 1) {
|
|
23
|
-
return returnValue[0];
|
|
24
|
-
}
|
|
25
|
-
return returnValue;
|
|
26
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
declare export default function stylexFirstThatWorks(
|
|
11
|
-
...args: $ReadOnlyArray<string>
|
|
12
|
-
): $ReadOnlyArray<string> | string;
|
package/lib/stylex-include.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export declare class IncludedStyles {
|
|
11
|
-
astNode: any;
|
|
12
|
-
constructor(astNode: any);
|
|
13
|
-
}
|
|
14
|
-
declare function stylexInclude(
|
|
15
|
-
firstArg: any,
|
|
16
|
-
...styles: any
|
|
17
|
-
): { [key: string]: IncludedStyles };
|
|
18
|
-
export default stylexInclude;
|
package/lib/stylex-include.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.IncludedStyles = void 0;
|
|
7
|
-
exports.default = stylexInclude;
|
|
8
|
-
var messages = _interopRequireWildcard(require("./messages"));
|
|
9
|
-
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); }
|
|
10
|
-
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 && {}.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; }
|
|
11
|
-
let number = 0;
|
|
12
|
-
function uuid() {
|
|
13
|
-
return `__included_${++number}__`;
|
|
14
|
-
}
|
|
15
|
-
class IncludedStyles {
|
|
16
|
-
constructor(astNode) {
|
|
17
|
-
this.astNode = astNode;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.IncludedStyles = IncludedStyles;
|
|
21
|
-
function stylexInclude(firstArg) {
|
|
22
|
-
if ((arguments.length <= 1 ? 0 : arguments.length - 1) > 0) {
|
|
23
|
-
throw new Error(messages.ILLEGAL_ARGUMENT_LENGTH);
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
[uuid()]: new IncludedStyles(firstArg.node)
|
|
27
|
-
};
|
|
28
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
declare export class IncludedStyles {
|
|
11
|
-
astNode: any;
|
|
12
|
-
constructor(astNode: any): void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare export default function stylexInclude(
|
|
16
|
-
firstArg: any,
|
|
17
|
-
...styles: any
|
|
18
|
-
): {
|
|
19
|
-
[key: string]: IncludedStyles,
|
|
20
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { InjectableStyle, StyleXOptions } from './common-types';
|
|
11
|
-
declare function styleXKeyframes(
|
|
12
|
-
frames: {
|
|
13
|
-
readonly [$$Key$$: string]: { readonly [$$Key$$: string]: string | number };
|
|
14
|
-
},
|
|
15
|
-
options: StyleXOptions,
|
|
16
|
-
): [string, InjectableStyle];
|
|
17
|
-
export default styleXKeyframes;
|
package/lib/stylex-keyframes.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = styleXKeyframes;
|
|
7
|
-
var _hash = _interopRequireDefault(require("./hash"));
|
|
8
|
-
var _index = _interopRequireDefault(require("./preprocess-rules/index"));
|
|
9
|
-
var _generateLtr = _interopRequireDefault(require("./physical-rtl/generate-ltr"));
|
|
10
|
-
var _generateRtl = _interopRequireDefault(require("./physical-rtl/generate-rtl"));
|
|
11
|
-
var _transformValue = _interopRequireDefault(require("./transform-value"));
|
|
12
|
-
var _dashify = _interopRequireDefault(require("./utils/dashify"));
|
|
13
|
-
var _objectUtils = require("./utils/object-utils");
|
|
14
|
-
var _defaultOptions = require("./utils/default-options");
|
|
15
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
function styleXKeyframes(frames) {
|
|
17
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaultOptions.defaultOptions;
|
|
18
|
-
const {
|
|
19
|
-
classNamePrefix = 'x'
|
|
20
|
-
} = options;
|
|
21
|
-
const expandedObject = (0, _objectUtils.objMap)(frames, frame => _objectUtils.Pipe.create(frame).pipe(frame => expandFrameShorthands(frame, options)).pipe(x => (0, _objectUtils.objMapKeys)(x, _dashify.default)).pipe(x => (0, _objectUtils.objMap)(x, (value, key) => (0, _transformValue.default)(key, value, options))).done());
|
|
22
|
-
const ltrStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, _generateLtr.default));
|
|
23
|
-
const rtlStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, entry => (0, _generateRtl.default)(entry) ?? entry));
|
|
24
|
-
const ltrString = constructKeyframesObj(ltrStyles);
|
|
25
|
-
const rtlString = constructKeyframesObj(rtlStyles);
|
|
26
|
-
const animationName = classNamePrefix + (0, _hash.default)('<>' + ltrString) + '-B';
|
|
27
|
-
const ltr = `@keyframes ${animationName}{${ltrString}}`;
|
|
28
|
-
const rtl = ltrString === rtlString ? null : `@keyframes ${animationName}{${rtlString}}`;
|
|
29
|
-
return [animationName, {
|
|
30
|
-
ltr,
|
|
31
|
-
rtl,
|
|
32
|
-
priority: 1
|
|
33
|
-
}];
|
|
34
|
-
}
|
|
35
|
-
function expandFrameShorthands(frame, options) {
|
|
36
|
-
return (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(frame).flatMap(pair => (0, _index.default)(pair, options).map(_ref => {
|
|
37
|
-
let [key, value] = _ref;
|
|
38
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
39
|
-
return [key, value];
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}).filter(Boolean)).filter(_ref2 => {
|
|
43
|
-
let [_key, value] = _ref2;
|
|
44
|
-
return value != null;
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
function constructKeyframesObj(frames) {
|
|
48
|
-
return (0, _objectUtils.objEntries)(frames).map(_ref3 => {
|
|
49
|
-
let [key, value] = _ref3;
|
|
50
|
-
return `${key}{${(0, _objectUtils.objEntries)(value).map(_ref4 => {
|
|
51
|
-
let [k, v] = _ref4;
|
|
52
|
-
return `${k}:${v};`;
|
|
53
|
-
}).join('')}}`;
|
|
54
|
-
}).join('');
|
|
55
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { InjectableStyle, StyleXOptions } from './common-types';
|
|
11
|
-
|
|
12
|
-
// Similar to `stylex.create` it takes an object of keyframes
|
|
13
|
-
// and returns a string after hashing it.
|
|
14
|
-
//
|
|
15
|
-
// It also expands shorthand properties to maintain parity with
|
|
16
|
-
// `stylex.create`.
|
|
17
|
-
declare export default function styleXKeyframes(
|
|
18
|
-
frames: { +[string]: { +[string]: string | number } },
|
|
19
|
-
options: StyleXOptions,
|
|
20
|
-
): [string, InjectableStyle];
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { CSSType } from './types';
|
|
11
|
-
export type VarsConfigValue =
|
|
12
|
-
| string
|
|
13
|
-
| Readonly<{ default: VarsConfigValue; [$$Key$$: string]: VarsConfigValue }>;
|
|
14
|
-
export type VarsConfig = Readonly<{
|
|
15
|
-
[$$Key$$: string]: VarsConfigValue | CSSType;
|
|
16
|
-
}>;
|
|
17
|
-
export declare function collectVarsByAtRule(
|
|
18
|
-
key: string,
|
|
19
|
-
$$PARAM_1$$: { readonly nameHash: string; readonly value: VarsConfigValue },
|
|
20
|
-
collection: { [$$Key$$: string]: Array<string> },
|
|
21
|
-
atRules: Array<string>,
|
|
22
|
-
): void;
|
|
23
|
-
export declare function wrapWithAtRules(ltr: string, atRule: string): string;
|
|
24
|
-
export declare function priorityForAtRule(atRule: string): number;
|
|
25
|
-
export declare function getDefaultValue(
|
|
26
|
-
value: VarsConfigValue,
|
|
27
|
-
): null | undefined | string;
|
package/lib/stylex-vars-utils.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.collectVarsByAtRule = collectVarsByAtRule;
|
|
7
|
-
exports.getDefaultValue = getDefaultValue;
|
|
8
|
-
exports.priorityForAtRule = priorityForAtRule;
|
|
9
|
-
exports.wrapWithAtRules = wrapWithAtRules;
|
|
10
|
-
const SPLIT_TOKEN = '__$$__';
|
|
11
|
-
function collectVarsByAtRule(key, _ref) {
|
|
12
|
-
let {
|
|
13
|
-
nameHash,
|
|
14
|
-
value
|
|
15
|
-
} = _ref;
|
|
16
|
-
let collection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
17
|
-
let atRules = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
18
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
19
|
-
const val = typeof value === 'number' ? value.toString() : value;
|
|
20
|
-
const key = atRules.length === 0 ? 'default' : [...atRules].sort().join(SPLIT_TOKEN);
|
|
21
|
-
collection[key] ??= [];
|
|
22
|
-
collection[key].push(`--${nameHash}:${val};`);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (value === null) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (Array.isArray(value)) {
|
|
29
|
-
throw new Error('Array is not supported in stylex.defineVars');
|
|
30
|
-
}
|
|
31
|
-
if (typeof value === 'object') {
|
|
32
|
-
if (value.default === undefined) {
|
|
33
|
-
throw new Error('Default value is not defined for ' + key + ' variable.');
|
|
34
|
-
}
|
|
35
|
-
for (const atRule of Object.keys(value)) {
|
|
36
|
-
collectVarsByAtRule(key, {
|
|
37
|
-
nameHash,
|
|
38
|
-
value: value[atRule]
|
|
39
|
-
}, collection, atRule === 'default' ? atRules : [...atRules, atRule]);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function wrapWithAtRules(ltr, atRule) {
|
|
44
|
-
return atRule.split(SPLIT_TOKEN).reduce((acc, atRule) => `${atRule}{${acc}}`, ltr);
|
|
45
|
-
}
|
|
46
|
-
function priorityForAtRule(atRule) {
|
|
47
|
-
if (atRule === 'default') {
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
return atRule.split(SPLIT_TOKEN).length;
|
|
51
|
-
}
|
|
52
|
-
function getDefaultValue(value) {
|
|
53
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
54
|
-
return value.toString();
|
|
55
|
-
}
|
|
56
|
-
if (value == null) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
if (Array.isArray(value)) {
|
|
60
|
-
throw new Error('Array is not supported in stylex.defineVars');
|
|
61
|
-
}
|
|
62
|
-
if (typeof value === 'object') {
|
|
63
|
-
if (value.default === undefined) {
|
|
64
|
-
throw new Error('Default value is not defined for variable.');
|
|
65
|
-
}
|
|
66
|
-
return getDefaultValue(value.default);
|
|
67
|
-
}
|
|
68
|
-
throw new Error('Invalid value in stylex.defineVars');
|
|
69
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { CSSType } from './types';
|
|
11
|
-
|
|
12
|
-
export type VarsConfigValue =
|
|
13
|
-
| string
|
|
14
|
-
| $ReadOnly<{ default: VarsConfigValue, [string]: VarsConfigValue }>;
|
|
15
|
-
|
|
16
|
-
export type VarsConfig = $ReadOnly<{
|
|
17
|
-
[string]: VarsConfigValue | CSSType<>,
|
|
18
|
-
}>;
|
|
19
|
-
|
|
20
|
-
declare export function collectVarsByAtRule(
|
|
21
|
-
key: string,
|
|
22
|
-
{ +nameHash: string, +value: VarsConfigValue },
|
|
23
|
-
collection: { [string]: Array<string> },
|
|
24
|
-
atRules: Array<string>,
|
|
25
|
-
): void;
|
|
26
|
-
|
|
27
|
-
declare export function wrapWithAtRules(ltr: string, atRule: string): string;
|
|
28
|
-
|
|
29
|
-
declare export function priorityForAtRule(atRule: string): number;
|
|
30
|
-
|
|
31
|
-
declare export function getDefaultValue(value: VarsConfigValue): ?string;
|
package/lib/transform-value.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { StyleXOptions } from './common-types';
|
|
11
|
-
/**
|
|
12
|
-
* Convert a CSS value in JS to the final CSS string value
|
|
13
|
-
*/
|
|
14
|
-
declare function transformValue(
|
|
15
|
-
key: string,
|
|
16
|
-
rawValue: string | number,
|
|
17
|
-
options: StyleXOptions,
|
|
18
|
-
): string;
|
|
19
|
-
export default transformValue;
|
|
20
|
-
export declare function getNumberSuffix(key: string): string;
|
|
21
|
-
export declare const timeUnits: Set<string>;
|
|
22
|
-
export declare const lengthUnits: Set<string>;
|