@stylexjs/shared 0.17.4 → 0.18.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.
Files changed (145) hide show
  1. package/lib/common-types.d.ts +61 -0
  2. package/lib/common-types.js +1 -0
  3. package/lib/common-types.js.flow +85 -0
  4. package/lib/hash.d.ts +15 -0
  5. package/lib/hash.js +49 -0
  6. package/lib/hash.js.flow +12 -0
  7. package/lib/messages.d.ts +70 -0
  8. package/lib/messages.js +38 -0
  9. package/lib/messages.js.flow +44 -0
  10. package/lib/physical-rtl/generate-ltr.d.ts +15 -0
  11. package/lib/physical-rtl/generate-ltr.js +75 -0
  12. package/lib/physical-rtl/generate-ltr.js.flow +14 -0
  13. package/lib/physical-rtl/generate-rtl.d.ts +15 -0
  14. package/lib/physical-rtl/generate-rtl.js +157 -0
  15. package/lib/physical-rtl/generate-rtl.js.flow +14 -0
  16. package/lib/preprocess-rules/PreRule.d.ts +51 -0
  17. package/lib/preprocess-rules/PreRule.js +79 -0
  18. package/lib/preprocess-rules/PreRule.js.flow +63 -0
  19. package/lib/preprocess-rules/__tests__/PreRule-test.js +33 -0
  20. package/lib/preprocess-rules/__tests__/flatten-raw-style-obj-test.js +196 -0
  21. package/lib/preprocess-rules/application-order.d.ts +186 -0
  22. package/lib/preprocess-rules/application-order.js +195 -0
  23. package/lib/preprocess-rules/application-order.js.flow +141 -0
  24. package/lib/preprocess-rules/basic-validation.d.ts +13 -0
  25. package/lib/preprocess-rules/basic-validation.js +70 -0
  26. package/lib/preprocess-rules/basic-validation.js.flow +13 -0
  27. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +20 -0
  28. package/lib/preprocess-rules/flatten-raw-style-obj.js +100 -0
  29. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +23 -0
  30. package/lib/preprocess-rules/index.d.ts +21 -0
  31. package/lib/preprocess-rules/index.js +45 -0
  32. package/lib/preprocess-rules/index.js.flow +23 -0
  33. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +170 -0
  34. package/lib/preprocess-rules/legacy-expand-shorthands.js +222 -0
  35. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +142 -0
  36. package/lib/preprocess-rules/property-specificity.d.ts +79 -0
  37. package/lib/preprocess-rules/property-specificity.js +107 -0
  38. package/lib/preprocess-rules/property-specificity.js.flow +93 -0
  39. package/lib/stylex-consts-utils.d.ts +11 -0
  40. package/lib/stylex-consts-utils.js +1 -0
  41. package/lib/stylex-consts-utils.js.flow +14 -0
  42. package/lib/stylex-create-theme.d.ts +26 -0
  43. package/lib/stylex-create-theme.js +53 -0
  44. package/lib/stylex-create-theme.js.flow +19 -0
  45. package/lib/stylex-create.d.ts +27 -0
  46. package/lib/stylex-create.js +60 -0
  47. package/lib/stylex-create.js.flow +37 -0
  48. package/lib/stylex-defaultMarker.d.ts +14 -0
  49. package/lib/stylex-defaultMarker.js +14 -0
  50. package/lib/stylex-defaultMarker.js.flow +13 -0
  51. package/lib/stylex-define-consts.d.ts +23 -0
  52. package/lib/stylex-define-consts.js +40 -0
  53. package/lib/stylex-define-consts.js.flow +19 -0
  54. package/lib/stylex-define-vars.d.ts +28 -0
  55. package/lib/stylex-define-vars.js +90 -0
  56. package/lib/stylex-define-vars.js.flow +26 -0
  57. package/lib/stylex-first-that-works.d.ts +13 -0
  58. package/lib/stylex-first-that-works.js +23 -0
  59. package/lib/stylex-first-that-works.js.flow +12 -0
  60. package/lib/stylex-keyframes.d.ts +17 -0
  61. package/lib/stylex-keyframes.js +46 -0
  62. package/lib/stylex-keyframes.js.flow +20 -0
  63. package/lib/stylex-position-try.d.ts +15 -0
  64. package/lib/stylex-position-try.js +47 -0
  65. package/lib/stylex-position-try.js.flow +18 -0
  66. package/lib/stylex-vars-utils.d.ts +27 -0
  67. package/lib/stylex-vars-utils.js +66 -0
  68. package/lib/stylex-vars-utils.js.flow +31 -0
  69. package/lib/stylex-view-transition-class.d.ts +22 -0
  70. package/lib/stylex-view-transition-class.js +42 -0
  71. package/lib/stylex-view-transition-class.js.flow +23 -0
  72. package/lib/types/__tests__/stylex-types-test.js +178 -0
  73. package/lib/types/index.d.ts +254 -0
  74. package/lib/types/index.js +147 -0
  75. package/lib/types/index.js.flow +280 -0
  76. package/lib/utils/Rule.d.ts +58 -0
  77. package/lib/utils/Rule.js +50 -0
  78. package/lib/utils/Rule.js.flow +64 -0
  79. package/lib/utils/__tests__/convert-to-className-test.js +85 -0
  80. package/lib/utils/__tests__/property-priorities-test.js +33 -0
  81. package/lib/utils/__tests__/split-css-value-test.js +26 -0
  82. package/lib/utils/__tests__/transform-value-test.js +36 -0
  83. package/lib/utils/convert-to-className.d.ts +21 -0
  84. package/lib/utils/convert-to-className.js +61 -0
  85. package/lib/utils/convert-to-className.js.flow +29 -0
  86. package/lib/utils/css-properties.js.flow +155 -0
  87. package/lib/utils/dashify.d.ts +11 -0
  88. package/lib/utils/dashify.js +9 -0
  89. package/lib/utils/dashify.js.flow +10 -0
  90. package/lib/utils/default-options.d.ts +12 -0
  91. package/lib/utils/default-options.js +26 -0
  92. package/lib/utils/default-options.js.flow +12 -0
  93. package/lib/utils/file-based-identifier.d.ts +15 -0
  94. package/lib/utils/file-based-identifier.js +13 -0
  95. package/lib/utils/file-based-identifier.js.flow +14 -0
  96. package/lib/utils/generate-css-rule.d.ts +19 -0
  97. package/lib/utils/generate-css-rule.js +37 -0
  98. package/lib/utils/generate-css-rule.js.flow +19 -0
  99. package/lib/utils/normalize-value.d.ts +16 -0
  100. package/lib/utils/normalize-value.js +27 -0
  101. package/lib/utils/normalize-value.js.flow +16 -0
  102. package/lib/utils/normalizers/convert-camel-case-values.d.ts +14 -0
  103. package/lib/utils/normalizers/convert-camel-case-values.js +23 -0
  104. package/lib/utils/normalizers/convert-camel-case-values.js.flow +13 -0
  105. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
  106. package/lib/utils/normalizers/detect-unclosed-fns.js +16 -0
  107. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
  108. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
  109. package/lib/utils/normalizers/font-size-px-to-rem.js +24 -0
  110. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
  111. package/lib/utils/normalizers/leading-zero.d.ts +17 -0
  112. package/lib/utils/normalizers/leading-zero.js +24 -0
  113. package/lib/utils/normalizers/leading-zero.js.flow +16 -0
  114. package/lib/utils/normalizers/quotes.d.ts +18 -0
  115. package/lib/utils/normalizers/quotes.js +17 -0
  116. package/lib/utils/normalizers/quotes.js.flow +17 -0
  117. package/lib/utils/normalizers/timings.d.ts +18 -0
  118. package/lib/utils/normalizers/timings.js +25 -0
  119. package/lib/utils/normalizers/timings.js.flow +17 -0
  120. package/lib/utils/normalizers/whitespace.d.ts +19 -0
  121. package/lib/utils/normalizers/whitespace.js +54 -0
  122. package/lib/utils/normalizers/whitespace.js.flow +18 -0
  123. package/lib/utils/normalizers/zero-dimensions.d.ts +19 -0
  124. package/lib/utils/normalizers/zero-dimensions.js +45 -0
  125. package/lib/utils/normalizers/zero-dimensions.js.flow +18 -0
  126. package/lib/utils/object-utils.d.ts +68 -0
  127. package/lib/utils/object-utils.js +89 -0
  128. package/lib/utils/object-utils.js.flow +78 -0
  129. package/lib/utils/property-priorities.js +22 -1
  130. package/lib/utils/rule-utils.d.ts +17 -0
  131. package/lib/utils/rule-utils.js +41 -0
  132. package/lib/utils/rule-utils.js.flow +16 -0
  133. package/lib/utils/split-css-value.d.ts +14 -0
  134. package/lib/utils/split-css-value.js +41 -0
  135. package/lib/utils/split-css-value.js.flow +15 -0
  136. package/lib/utils/transform-value.d.ts +24 -0
  137. package/lib/utils/transform-value.js +50 -0
  138. package/lib/utils/transform-value.js.flow +25 -0
  139. package/lib/validate.d.ts +12 -0
  140. package/lib/validate.js +19 -0
  141. package/lib/validate.js.flow +14 -0
  142. package/lib/when/when.d.ts +67 -0
  143. package/lib/when/when.js +71 -0
  144. package/lib/when/when.js.flow +73 -0
  145. package/package.json +1 -1
@@ -0,0 +1,14 @@
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
+ declare function stylexDefaultMarker(options?: StyleXOptions): {
12
+ [$$Key$$: string]: string | true;
13
+ };
14
+ export default stylexDefaultMarker;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = stylexDefaultMarker;
7
+ var _defaultOptions = require("./utils/default-options");
8
+ function stylexDefaultMarker(options = _defaultOptions.defaultOptions) {
9
+ const prefix = options.classNamePrefix != null ? `${options.classNamePrefix}-` : '';
10
+ return {
11
+ [`${prefix}default-marker`]: `${prefix}default-marker`,
12
+ $$css: true
13
+ };
14
+ }
@@ -0,0 +1,13 @@
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 { StyleXOptions } from './common-types';
11
+ declare export default function stylexDefaultMarker(options?: StyleXOptions): {
12
+ [string]: string | true,
13
+ };
@@ -0,0 +1,23 @@
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 { exportId: string }> & {
16
+ exportId: string;
17
+ }
18
+ >,
19
+ ): [
20
+ { [$$Key$$: string]: string | number },
21
+ { [$$Key$$: string]: InjectableConstStyle },
22
+ ];
23
+ export default styleXDefineConsts;
@@ -0,0 +1,40 @@
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 _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
+ function styleXDefineConsts(constants, options) {
13
+ const {
14
+ classNamePrefix,
15
+ exportId,
16
+ debug,
17
+ enableDebugClassNames
18
+ } = {
19
+ ..._defaultOptions.defaultOptions,
20
+ ...options
21
+ };
22
+ const jsOutput = {};
23
+ const injectableStyles = {};
24
+ for (const [key, value] of Object.entries(constants)) {
25
+ if (key.startsWith('--')) {
26
+ throw new Error(messages.INVALID_CONST_KEY);
27
+ }
28
+ const varSafeKey = (key[0] >= '0' && key[0] <= '9' ? `_${key}` : key).replace(/[^a-zA-Z0-9]/g, '_');
29
+ const constKey = debug && enableDebugClassNames ? `${varSafeKey}-${classNamePrefix}${(0, _hash.default)(`${exportId}.${key}`)}` : `${classNamePrefix}${(0, _hash.default)(`${exportId}.${key}`)}`;
30
+ jsOutput[key] = value;
31
+ injectableStyles[constKey] = {
32
+ constKey,
33
+ constVal: value,
34
+ priority: 0,
35
+ ltr: '',
36
+ rtl: null
37
+ };
38
+ }
39
+ return [jsOutput, injectableStyles];
40
+ }
@@ -0,0 +1,19 @@
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
+
13
+ declare export default function styleXDefineConsts<Vars: ConstsConfig>(
14
+ constants: Vars,
15
+ options: $ReadOnly<{ ...Partial<StyleXOptions>, exportId: string, ... }>,
16
+ ): [
17
+ { [string]: string | number }, // jsOutput JS output
18
+ { [string]: InjectableConstStyle }, // metadata for registerinjectableStyles
19
+ ];
@@ -0,0 +1,28 @@
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$$ in keyof Vars]: string;
14
+ }>;
15
+ type VarsObject<Vars extends VarsConfig> = Readonly<
16
+ Omit<VarsKeysWithStringValues<Vars>, keyof { __varGroupHash__: string }> & {
17
+ __varGroupHash__: string;
18
+ }
19
+ >;
20
+ declare function styleXDefineVars<Vars extends VarsConfig>(
21
+ variables: Vars,
22
+ options: Readonly<
23
+ Omit<Partial<StyleXOptions>, keyof { exportId: string }> & {
24
+ exportId: string;
25
+ }
26
+ >,
27
+ ): [VarsObject<Vars>, { [$$Key$$: string]: InjectableStyle }];
28
+ export default styleXDefineVars;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = styleXDefineVars;
7
+ var _types = require("./types");
8
+ var _hash = _interopRequireDefault(require("./hash"));
9
+ var _objectUtils = require("./utils/object-utils");
10
+ var _defaultOptions = require("./utils/default-options");
11
+ var _stylexVarsUtils = require("./stylex-vars-utils");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ function styleXDefineVars(variables, options) {
14
+ const {
15
+ classNamePrefix,
16
+ exportId,
17
+ debug,
18
+ enableDebugClassNames
19
+ } = {
20
+ ..._defaultOptions.defaultOptions,
21
+ ...options
22
+ };
23
+ const varGroupHash = classNamePrefix + (0, _hash.default)(exportId);
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)(`${exportId}.${key}`) : classNamePrefix + (0, _hash.default)(`${exportId}.${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, ({
45
+ nameHash
46
+ }) => `var(--${nameHash})`);
47
+ const injectableStyles = constructCssVariablesString(variablesMap, varGroupHash);
48
+ const injectableTypes = (0, _objectUtils.objMap)(typedVariables, ({
49
+ initialValue: iv,
50
+ syntax
51
+ }, nameHash) => ({
52
+ ltr: `@property --${nameHash} { syntax: "${syntax}"; inherits: true;${iv != null ? ` initial-value: ${iv}` : ''} }`,
53
+ rtl: null,
54
+ priority: 0
55
+ }));
56
+ return [{
57
+ ...themeVariablesObject,
58
+ __varGroupHash__: varGroupHash
59
+ }, {
60
+ ...injectableTypes,
61
+ ...injectableStyles
62
+ }];
63
+ }
64
+ function constructCssVariablesString(variables, varGroupHash) {
65
+ const rulesByAtRule = {};
66
+ for (const [key, {
67
+ nameHash,
68
+ value
69
+ }] of Object.entries(variables)) {
70
+ (0, _stylexVarsUtils.collectVarsByAtRule)(key, {
71
+ nameHash,
72
+ value
73
+ }, rulesByAtRule);
74
+ }
75
+ const result = {};
76
+ for (const [atRule, value] of Object.entries(rulesByAtRule)) {
77
+ const suffix = atRule === 'default' ? '' : `-${(0, _hash.default)(atRule)}`;
78
+ const selector = `:root, .${varGroupHash}`;
79
+ let ltr = `${selector}{${value.join('')}}`;
80
+ if (atRule !== 'default') {
81
+ ltr = (0, _stylexVarsUtils.wrapWithAtRules)(ltr, atRule);
82
+ }
83
+ result[varGroupHash + suffix] = {
84
+ ltr,
85
+ rtl: null,
86
+ priority: (0, _stylexVarsUtils.priorityForAtRule)(atRule) / 10
87
+ };
88
+ }
89
+ return result;
90
+ }
@@ -0,0 +1,26 @@
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
+ type VarsKeysWithStringValues<Vars: VarsConfig> = $ReadOnly<{
13
+ [$Keys<Vars>]: string,
14
+ }>;
15
+
16
+ type VarsObject<Vars: VarsConfig> = $ReadOnly<{
17
+ ...VarsKeysWithStringValues<Vars>,
18
+ __varGroupHash__: string,
19
+ }>;
20
+
21
+ // Similar to `stylex.create` it takes an object of variables with their values
22
+ // and returns a string after hashing it.
23
+ declare export default function styleXDefineVars<Vars: VarsConfig>(
24
+ variables: Vars,
25
+ options: $ReadOnly<{ ...Partial<StyleXOptions>, exportId: string, ... }>,
26
+ ): [VarsObject<Vars>, { [string]: InjectableStyle }];
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,23 @@
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(...args) {
9
+ const firstVar = args.findIndex(isVar);
10
+ if (firstVar === -1) {
11
+ return [...args].reverse();
12
+ }
13
+ const priorities = args.slice(0, firstVar).reverse();
14
+ const rest = args.slice(firstVar);
15
+ const firstNonVar = rest.findIndex(arg => !isVar(arg));
16
+ const varParts = rest.slice(0, firstNonVar === -1 ? rest.length : firstNonVar + 1).reverse();
17
+ const vars = varParts.map(arg => isVar(arg) ? arg.slice(4, -1) : arg);
18
+ const returnValue = [vars.reduce((soFar, varName) => soFar ? `var(${varName}, ${String(soFar)})` : varName.startsWith('--') ? `var(${varName})` : varName, ''), ...priorities];
19
+ if (returnValue.length === 1) {
20
+ return returnValue[0];
21
+ }
22
+ return returnValue;
23
+ }
@@ -0,0 +1,12 @@
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;
@@ -0,0 +1,17 @@
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;
@@ -0,0 +1,46 @@
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("./utils/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, options = _defaultOptions.defaultOptions) {
17
+ const {
18
+ classNamePrefix = 'x'
19
+ } = options;
20
+ 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());
21
+ const ltrStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, entry => (0, _generateLtr.default)(entry, options)));
22
+ const rtlStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, entry => (0, _generateRtl.default)(entry, options) ?? entry));
23
+ const stableStyles = (0, _objectUtils.objMap)(expandedObject, frame => (0, _objectUtils.objMapEntry)(frame, _generateLtr.default));
24
+ const ltrString = constructKeyframesObj(ltrStyles);
25
+ const rtlString = constructKeyframesObj(rtlStyles);
26
+ const stableString = constructKeyframesObj(stableStyles);
27
+ const animationName = classNamePrefix + (0, _hash.default)('<>' + stableString) + '-B';
28
+ const ltr = `@keyframes ${animationName}{${ltrString}}`;
29
+ const rtl = ltrString === rtlString ? null : `@keyframes ${animationName}{${rtlString}}`;
30
+ return [animationName, {
31
+ ltr,
32
+ rtl,
33
+ priority: 0
34
+ }];
35
+ }
36
+ function expandFrameShorthands(frame, options) {
37
+ return (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(frame).flatMap(pair => (0, _index.default)(pair, options).map(([key, value]) => {
38
+ if (typeof value === 'string' || typeof value === 'number') {
39
+ return [key, value];
40
+ }
41
+ return null;
42
+ }).filter(Boolean)).filter(([_key, value]) => value != null));
43
+ }
44
+ function constructKeyframesObj(frames) {
45
+ return (0, _objectUtils.objEntries)(frames).map(([key, value]) => `${key}{${(0, _objectUtils.objEntries)(value).map(([k, v]) => `${k}:${v};`).join('')}}`).join('');
46
+ }
@@ -0,0 +1,20 @@
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];
@@ -0,0 +1,15 @@
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 styleXPositionTry(
12
+ styles: { readonly [$$Key$$: string]: string | number },
13
+ options?: StyleXOptions,
14
+ ): [string, InjectableStyle];
15
+ export default styleXPositionTry;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = styleXPositionTry;
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("./utils/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 styleXPositionTry(styles, options = _defaultOptions.defaultOptions) {
17
+ const {
18
+ classNamePrefix = 'x'
19
+ } = options;
20
+ const expandedObject = _objectUtils.Pipe.create(styles).pipe(styles => preprocessProperties(styles, options)).pipe(x => (0, _objectUtils.objMapKeys)(x, _dashify.default)).pipe(x => (0, _objectUtils.objMap)(x, (value, key) => (0, _transformValue.default)(key, value, options))).done();
21
+ const ltrStyles = (0, _objectUtils.objMap)(expandedObject, (value, key) => (0, _generateLtr.default)([key, value]));
22
+ const rtlStyles = (0, _objectUtils.objMap)(expandedObject, (value, key) => (0, _generateRtl.default)([key, value]) ?? value);
23
+ const ltrString = constructPositionTryObj(ltrStyles);
24
+ const rtlString = constructPositionTryObj(rtlStyles);
25
+ const positionTryName = '--' + classNamePrefix + (0, _hash.default)(ltrString);
26
+ const ltr = `@position-try ${positionTryName} {${ltrString}}`;
27
+ const rtl = ltrString === rtlString ? null : `@position-try ${positionTryName} {${rtlString}}`;
28
+ return [positionTryName, {
29
+ ltr,
30
+ rtl,
31
+ priority: 0
32
+ }];
33
+ }
34
+ function preprocessProperties(styles, options) {
35
+ return (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(styles).flatMap(pair => (0, _index.default)(pair, options).map(([key, value]) => {
36
+ if (typeof value === 'string' || typeof value === 'number') {
37
+ return [key, value];
38
+ }
39
+ return null;
40
+ }).filter(Boolean)).filter(([_key, value]) => value != null));
41
+ }
42
+ function constructPositionTryObj(styles) {
43
+ return Object.keys(styles).sort().map(k => {
44
+ const v = styles[k];
45
+ return (Array.isArray(v) ? v : [v]).map(val => `${k}:${val};`).join('');
46
+ }).join('');
47
+ }
@@ -0,0 +1,18 @@
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.keyframes` but for position-try-fallbacks
13
+ // Takes an object of positioning properties and returns a string after hashing it
14
+ // The generated string must be prefixed with -- for anchor positioning
15
+ declare export default function styleXPositionTry(
16
+ styles: { +[string]: string | number },
17
+ options?: StyleXOptions,
18
+ ): [string, InjectableStyle];
@@ -0,0 +1,27 @@
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;
@@ -0,0 +1,66 @@
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, {
12
+ nameHash,
13
+ value
14
+ }, collection = {}, atRules = []) {
15
+ if (typeof value === 'string' || typeof value === 'number') {
16
+ const val = typeof value === 'number' ? value.toString() : value;
17
+ const key = atRules.length === 0 ? 'default' : [...atRules].sort().join(SPLIT_TOKEN);
18
+ collection[key] ??= [];
19
+ collection[key].push(`--${nameHash}:${val};`);
20
+ return;
21
+ }
22
+ if (value === null) {
23
+ return;
24
+ }
25
+ if (Array.isArray(value)) {
26
+ throw new Error('Array is not supported in defineVars');
27
+ }
28
+ if (typeof value === 'object') {
29
+ if (value.default === undefined) {
30
+ throw new Error('Default value is not defined for ' + key + ' variable.');
31
+ }
32
+ for (const atRule of Object.keys(value)) {
33
+ collectVarsByAtRule(key, {
34
+ nameHash,
35
+ value: value[atRule]
36
+ }, collection, atRule === 'default' ? atRules : [...atRules, atRule]);
37
+ }
38
+ }
39
+ }
40
+ function wrapWithAtRules(ltr, atRule) {
41
+ return atRule.split(SPLIT_TOKEN).reduce((acc, atRule) => `${atRule}{${acc}}`, ltr);
42
+ }
43
+ function priorityForAtRule(atRule) {
44
+ if (atRule === 'default') {
45
+ return 1;
46
+ }
47
+ return 1 + atRule.split(SPLIT_TOKEN).length;
48
+ }
49
+ function getDefaultValue(value) {
50
+ if (typeof value === 'string' || typeof value === 'number') {
51
+ return value.toString();
52
+ }
53
+ if (value == null) {
54
+ return null;
55
+ }
56
+ if (Array.isArray(value)) {
57
+ throw new Error('Array is not supported in defineVars');
58
+ }
59
+ if (typeof value === 'object') {
60
+ if (value.default === undefined) {
61
+ throw new Error('Default value is not defined for variable.');
62
+ }
63
+ return getDefaultValue(value.default);
64
+ }
65
+ throw new Error('Invalid value in defineVars');
66
+ }
@@ -0,0 +1,31 @@
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
+ $$PARAM_1$$: { +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;
@@ -0,0 +1,22 @@
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
+ type StyleValue = { readonly [$$Key$$: string]: string | number };
12
+ type StyleObj = {
13
+ group?: StyleValue;
14
+ imagePair?: StyleValue;
15
+ old?: StyleValue;
16
+ new?: StyleValue;
17
+ };
18
+ declare function styleXViewTransitionClass(
19
+ styles: StyleObj,
20
+ options?: StyleXOptions,
21
+ ): [string, InjectableStyle];
22
+ export default styleXViewTransitionClass;