@stylexjs/shared 0.11.1 → 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.
Files changed (131) hide show
  1. package/lib/index.d.ts +10 -36
  2. package/lib/index.js +8 -25
  3. package/lib/index.js.flow +10 -43
  4. package/lib/utils/property-priorities.d.ts +4 -0
  5. package/lib/utils/property-priorities.js +54 -8
  6. package/lib/utils/property-priorities.js.flow +8 -0
  7. package/package.json +9 -22
  8. package/README.md +0 -81
  9. package/lib/common-types.d.ts +0 -47
  10. package/lib/common-types.js +0 -1
  11. package/lib/common-types.js.flow +0 -60
  12. package/lib/convert-to-className.d.ts +0 -20
  13. package/lib/convert-to-className.js +0 -66
  14. package/lib/convert-to-className.js.flow +0 -27
  15. package/lib/generate-css-rule.d.ts +0 -17
  16. package/lib/generate-css-rule.js +0 -25
  17. package/lib/generate-css-rule.js.flow +0 -17
  18. package/lib/hash.d.ts +0 -11
  19. package/lib/hash.js +0 -37
  20. package/lib/hash.js.flow +0 -10
  21. package/lib/messages.d.ts +0 -41
  22. package/lib/messages.js +0 -38
  23. package/lib/messages.js.flow +0 -44
  24. package/lib/physical-rtl/generate-ltr.d.ts +0 -13
  25. package/lib/physical-rtl/generate-ltr.js +0 -103
  26. package/lib/physical-rtl/generate-ltr.js.flow +0 -12
  27. package/lib/physical-rtl/generate-rtl.d.ts +0 -13
  28. package/lib/physical-rtl/generate-rtl.js +0 -177
  29. package/lib/physical-rtl/generate-rtl.js.flow +0 -12
  30. package/lib/preprocess-rules/PreRule.d.ts +0 -50
  31. package/lib/preprocess-rules/PreRule.js +0 -76
  32. package/lib/preprocess-rules/PreRule.js.flow +0 -62
  33. package/lib/preprocess-rules/application-order.d.ts +0 -183
  34. package/lib/preprocess-rules/application-order.js +0 -186
  35. package/lib/preprocess-rules/application-order.js.flow +0 -134
  36. package/lib/preprocess-rules/basic-validation.d.ts +0 -13
  37. package/lib/preprocess-rules/basic-validation.js +0 -73
  38. package/lib/preprocess-rules/basic-validation.js.flow +0 -13
  39. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +0 -20
  40. package/lib/preprocess-rules/flatten-raw-style-obj.js +0 -98
  41. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +0 -23
  42. package/lib/preprocess-rules/index.d.ts +0 -18
  43. package/lib/preprocess-rules/index.js +0 -33
  44. package/lib/preprocess-rules/index.js.flow +0 -22
  45. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +0 -165
  46. package/lib/preprocess-rules/legacy-expand-shorthands.js +0 -147
  47. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +0 -144
  48. package/lib/preprocess-rules/property-specificity.d.ts +0 -78
  49. package/lib/preprocess-rules/property-specificity.js +0 -107
  50. package/lib/preprocess-rules/property-specificity.js.flow +0 -87
  51. package/lib/stylex-create-theme.d.ts +0 -26
  52. package/lib/stylex-create-theme.js +0 -58
  53. package/lib/stylex-create-theme.js.flow +0 -19
  54. package/lib/stylex-create.d.ts +0 -27
  55. package/lib/stylex-create.js +0 -57
  56. package/lib/stylex-create.js.flow +0 -38
  57. package/lib/stylex-define-vars.d.ts +0 -28
  58. package/lib/stylex-define-vars.js +0 -94
  59. package/lib/stylex-define-vars.js.flow +0 -27
  60. package/lib/stylex-first-that-works.d.ts +0 -13
  61. package/lib/stylex-first-that-works.js +0 -26
  62. package/lib/stylex-first-that-works.js.flow +0 -12
  63. package/lib/stylex-include.d.ts +0 -18
  64. package/lib/stylex-include.js +0 -28
  65. package/lib/stylex-include.js.flow +0 -20
  66. package/lib/stylex-keyframes.d.ts +0 -17
  67. package/lib/stylex-keyframes.js +0 -55
  68. package/lib/stylex-keyframes.js.flow +0 -20
  69. package/lib/stylex-vars-utils.d.ts +0 -27
  70. package/lib/stylex-vars-utils.js +0 -69
  71. package/lib/stylex-vars-utils.js.flow +0 -31
  72. package/lib/transform-value.d.ts +0 -22
  73. package/lib/transform-value.js +0 -50
  74. package/lib/transform-value.js.flow +0 -25
  75. package/lib/types/index.d.ts +0 -240
  76. package/lib/types/index.js +0 -147
  77. package/lib/types/index.js.flow +0 -280
  78. package/lib/utils/Rule.d.ts +0 -58
  79. package/lib/utils/Rule.js +0 -50
  80. package/lib/utils/Rule.js.flow +0 -64
  81. package/lib/utils/dashify.d.ts +0 -11
  82. package/lib/utils/dashify.js +0 -9
  83. package/lib/utils/dashify.js.flow +0 -10
  84. package/lib/utils/default-options.d.ts +0 -11
  85. package/lib/utils/default-options.js +0 -15
  86. package/lib/utils/default-options.js.flow +0 -12
  87. package/lib/utils/file-based-identifier.d.ts +0 -15
  88. package/lib/utils/file-based-identifier.js +0 -14
  89. package/lib/utils/file-based-identifier.js.flow +0 -14
  90. package/lib/utils/genCSSRule.d.ts +0 -15
  91. package/lib/utils/genCSSRule.js +0 -15
  92. package/lib/utils/genCSSRule.js.flow +0 -15
  93. package/lib/utils/normalize-value.d.ts +0 -16
  94. package/lib/utils/normalize-value.js +0 -28
  95. package/lib/utils/normalize-value.js.flow +0 -16
  96. package/lib/utils/normalizers/convert-camel-case-values.d.ts +0 -14
  97. package/lib/utils/normalizers/convert-camel-case-values.js +0 -23
  98. package/lib/utils/normalizers/convert-camel-case-values.js.flow +0 -13
  99. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +0 -17
  100. package/lib/utils/normalizers/detect-unclosed-fns.js +0 -17
  101. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +0 -16
  102. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +0 -19
  103. package/lib/utils/normalizers/font-size-px-to-rem.js +0 -24
  104. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +0 -18
  105. package/lib/utils/normalizers/leading-zero.d.ts +0 -17
  106. package/lib/utils/normalizers/leading-zero.js +0 -24
  107. package/lib/utils/normalizers/leading-zero.js.flow +0 -16
  108. package/lib/utils/normalizers/quotes.d.ts +0 -18
  109. package/lib/utils/normalizers/quotes.js +0 -17
  110. package/lib/utils/normalizers/quotes.js.flow +0 -17
  111. package/lib/utils/normalizers/timings.d.ts +0 -18
  112. package/lib/utils/normalizers/timings.js +0 -25
  113. package/lib/utils/normalizers/timings.js.flow +0 -17
  114. package/lib/utils/normalizers/whitespace.d.ts +0 -19
  115. package/lib/utils/normalizers/whitespace.js +0 -54
  116. package/lib/utils/normalizers/whitespace.js.flow +0 -18
  117. package/lib/utils/normalizers/zero-dimensions.d.ts +0 -19
  118. package/lib/utils/normalizers/zero-dimensions.js +0 -42
  119. package/lib/utils/normalizers/zero-dimensions.js.flow +0 -18
  120. package/lib/utils/object-utils.d.ts +0 -66
  121. package/lib/utils/object-utils.js +0 -99
  122. package/lib/utils/object-utils.js.flow +0 -78
  123. package/lib/utils/rule-utils.d.ts +0 -15
  124. package/lib/utils/rule-utils.js +0 -41
  125. package/lib/utils/rule-utils.js.flow +0 -16
  126. package/lib/utils/split-css-value.d.ts +0 -14
  127. package/lib/utils/split-css-value.js +0 -33
  128. package/lib/utils/split-css-value.js.flow +0 -15
  129. package/lib/validate.d.ts +0 -12
  130. package/lib/validate.js +0 -21
  131. package/lib/validate.js.flow +0 -12
@@ -1,94 +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
- } = {
19
- ..._defaultOptions.defaultOptions,
20
- ...options
21
- };
22
- const themeNameHash = classNamePrefix + (0, _hash.default)(themeName);
23
- const typedVariables = {};
24
- const variablesMap = (0, _objectUtils.objMap)(variables, (value, key) => {
25
- const nameHash = key.startsWith('--') ? key.slice(2) : debug ? key + '-' + classNamePrefix + (0, _hash.default)(`${themeName}.${key}`) : classNamePrefix + (0, _hash.default)(`${themeName}.${key}`);
26
- if ((0, _types.isCSSType)(value)) {
27
- const v = value;
28
- typedVariables[nameHash] = {
29
- initialValue: (0, _stylexVarsUtils.getDefaultValue)(v.value),
30
- syntax: v.syntax
31
- };
32
- return {
33
- nameHash,
34
- value: v.value
35
- };
36
- }
37
- return {
38
- nameHash,
39
- value: value
40
- };
41
- });
42
- const themeVariablesObject = (0, _objectUtils.objMap)(variablesMap, _ref => {
43
- let {
44
- nameHash
45
- } = _ref;
46
- return `var(--${nameHash})`;
47
- });
48
- const injectableStyles = constructCssVariablesString(variablesMap, themeNameHash);
49
- const injectableTypes = (0, _objectUtils.objMap)(typedVariables, (_ref2, nameHash) => {
50
- let {
51
- initialValue: iv,
52
- syntax
53
- } = _ref2;
54
- return {
55
- ltr: `@property --${nameHash} { syntax: "${syntax}"; inherits: true;${iv != null ? ` initial-value: ${iv}` : ''} }`,
56
- rtl: null,
57
- priority: 0
58
- };
59
- });
60
- return [{
61
- ...themeVariablesObject,
62
- __themeName__: themeNameHash
63
- }, {
64
- ...injectableTypes,
65
- ...injectableStyles
66
- }];
67
- }
68
- function constructCssVariablesString(variables, themeNameHash) {
69
- const rulesByAtRule = {};
70
- for (const [key, {
71
- nameHash,
72
- value
73
- }] of Object.entries(variables)) {
74
- (0, _stylexVarsUtils.collectVarsByAtRule)(key, {
75
- nameHash,
76
- value
77
- }, rulesByAtRule);
78
- }
79
- const result = {};
80
- for (const [atRule, value] of Object.entries(rulesByAtRule)) {
81
- const suffix = atRule === 'default' ? '' : `-${(0, _hash.default)(atRule)}`;
82
- const selector = `:root, .${themeNameHash}`;
83
- let ltr = `${selector}{${value.join('')}}`;
84
- if (atRule !== 'default') {
85
- ltr = (0, _stylexVarsUtils.wrapWithAtRules)(ltr, atRule);
86
- }
87
- result[themeNameHash + suffix] = {
88
- ltr,
89
- rtl: null,
90
- priority: (0, _stylexVarsUtils.priorityForAtRule)(atRule) * 0.1
91
- };
92
- }
93
- return result;
94
- }
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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>;
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = transformValue;
7
- exports.getNumberSuffix = getNumberSuffix;
8
- exports.timeUnits = exports.lengthUnits = void 0;
9
- var _normalizeValue = _interopRequireDefault(require("./utils/normalize-value"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- function transformValue(key, rawValue, options) {
12
- const value = typeof rawValue === 'number' ? String(Math.round(rawValue * 10000) / 10000) + getNumberSuffix(key) : rawValue;
13
- if ((key === 'content' || key === 'hyphenateCharacter' || key === 'hyphenate-character') && typeof value === 'string') {
14
- const val = value.trim();
15
- const cssContentFunctions = ['attr(', 'counter(', 'counters(', 'url(', 'linear-gradient(', 'image-set('];
16
- const cssContentKeywords = new Set(['normal', 'none', 'open-quote', 'close-quote', 'no-open-quote', 'no-close-quote', 'inherit', 'initial', 'revert', 'revert-layer', 'unset']);
17
- const isCssFunction = cssContentFunctions.some(func => val.includes(func));
18
- const isKeyword = cssContentKeywords.has(val);
19
- const hasMatchingQuotes = (val.match(/"/g)?.length ?? 0) >= 2 || (val.match(/'/g)?.length ?? 0) >= 2;
20
- if (isCssFunction || isKeyword || hasMatchingQuotes) {
21
- return val;
22
- }
23
- return `"${val}"`;
24
- }
25
- return (0, _normalizeValue.default)(value, key, options);
26
- }
27
- function getNumberSuffix(key) {
28
- if (unitlessNumberProperties.has(key) || key.startsWith('--')) {
29
- return '';
30
- }
31
- if (!(key in numberPropertySuffixes)) {
32
- return 'px';
33
- }
34
- const suffix = numberPropertySuffixes[key];
35
- if (suffix == null) {
36
- return 'px';
37
- } else {
38
- return suffix;
39
- }
40
- }
41
- const unitlessNumberProperties = new Set(['WebkitLineClamp', 'animationIterationCount', 'aspectRatio', 'borderImageOutset', 'borderImageSlice', 'borderImageWidth', 'counterSet', 'counterReset', 'columnCount', 'flex', 'flexGrow', 'flexShrink', 'flexOrder', 'gridRow', 'gridRowStart', 'gridRowEnd', 'gridColumn', 'gridColumnStart', 'gridColumnEnd', 'gridArea', 'fontWeight', 'hyphenateLimitChars', 'lineClamp', 'lineHeight', 'maskBorderOutset', 'maskBorderSlice', 'maskBorderWidth', 'opacity', 'order', 'orphans', 'tabSize', 'widows', 'zIndex', 'fillOpacity', 'floodOpacity', 'rotate', 'scale', 'shapeImageThreshold', 'stopOpacity', 'strokeDasharray', 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'scale', 'mathDepth']);
42
- const numberPropertySuffixes = {
43
- animationDelay: 'ms',
44
- animationDuration: 'ms',
45
- transitionDelay: 'ms',
46
- transitionDuration: 'ms',
47
- voiceDuration: 'ms'
48
- };
49
- const timeUnits = exports.timeUnits = new Set(Object.keys(numberPropertySuffixes));
50
- const lengthUnits = exports.lengthUnits = new Set(['backgroundPositionX', 'backgroundPositionY', 'blockSize', 'borderBlockEndWidth', 'borderBlockStartWidth', 'borderBlockWidth', 'borderVerticalWidth', 'borderVerticalWidth', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomWidth', 'borderEndEndRadius', 'borderEndStartRadius', 'borderInlineEndWidth', 'borderEndWidth', 'borderInlineStartWidth', 'borderStartWidth', 'borderInlineWidth', 'borderHorizontalWidth', 'borderLeftWidth', 'borderRightWidth', 'borderSpacing', 'borderStartEndRadius', 'borderStartStartRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopWidth', 'bottom', 'columnGap', 'columnRuleWidth', 'columnWidth', 'containIntrinsicBlockSize', 'containIntrinsicHeight', 'containIntrinsicInlineSize', 'containIntrinsicWidth', 'flexBasis', 'fontSize', 'fontSmooth', 'height', 'inlineSize', 'insetBlockEnd', 'insetBlockStart', 'insetInlineEnd', 'insetInlineStart', 'left', 'letterSpacing', 'marginBlockEnd', 'marginBlockStart', 'marginBottom', 'marginInlineEnd', 'marginEnd', 'marginInlineStart', 'marginStart', 'marginLeft', 'marginRight', 'marginTop', 'maxBlockSize', 'maxHeight', 'maxInlineSize', 'maxWidth', 'minBlockSize', 'minHeight', 'minInlineSize', 'minWidth', 'offsetDistance', 'outlineOffset', 'outlineWidth', 'overflowClipMargin', 'paddingBlockEnd', 'paddingBlockStart', 'paddingBottom', 'paddingInlineEnd', 'paddingEnd', 'paddingInlineStart', 'paddingStart', 'paddingLeft', 'paddingRight', 'paddingTop', 'perspective', 'right', 'rowGap', 'scrollMarginBlockEnd', 'scrollMarginBlockStart', 'scrollMarginBottom', 'scrollMarginInlineEnd', 'scrollMarginInlineStart', 'scrollMarginLeft', 'scrollMarginRight', 'scrollMarginTop', 'scrollPaddingBlockEnd', 'scrollPaddingBlockStart', 'scrollPaddingBottom', 'scrollPaddingInlineEnd', 'scrollPaddingInlineStart', 'scrollPaddingLeft', 'scrollPaddingRight', 'scrollPaddingTop', 'scrollSnapMarginBottom', 'scrollSnapMarginLeft', 'scrollSnapMarginRight', 'scrollSnapMarginTop', 'shapeMargin', 'tabSize', 'textDecorationThickness', 'textIndent', 'textUnderlineOffset', 'top', 'transformOrigin', 'translate', 'verticalAlign', 'width', 'wordSpacing', 'border', 'borderBlock', 'borderBlockEnd', 'borderBlockStart', 'borderBottom', 'borderLeft', 'borderRadius', 'borderRight', 'borderTop', 'borderWidth', 'columnRule', 'containIntrinsicSize', 'gap', 'inset', 'insetBlock', 'insetInline', 'margin', 'marginBlock', 'marginVertical', 'marginInline', 'marginHorizontal', 'offset', 'outline', 'padding', 'paddingBlock', 'paddingVertical', 'paddingInline', 'paddingHorizontal', 'scrollMargin', 'scrollMarginBlock', 'scrollMarginInline', 'scrollPadding', 'scrollPaddingBlock', 'scrollPaddingInline', 'scrollSnapMargin']);
@@ -1,25 +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 { StyleXOptions } from './common-types';
11
-
12
- /**
13
- * Convert a CSS value in JS to the final CSS string value
14
- */
15
- declare export default function transformValue(
16
- key: string,
17
- rawValue: string | number,
18
- options: StyleXOptions,
19
- ): string;
20
-
21
- declare export function getNumberSuffix(key: string): string;
22
-
23
- declare export const timeUnits: Set<string>;
24
-
25
- declare export const lengthUnits: Set<string>;