@stylexjs/shared 0.17.5 → 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 +13 -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,157 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = generateRTL;
7
+ var _defaultOptions = require("../utils/default-options");
8
+ var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ const cursorFlip = {
11
+ 'e-resize': 'w-resize',
12
+ 'w-resize': 'e-resize',
13
+ 'ne-resize': 'nw-resize',
14
+ 'nesw-resize': 'nwse-resize',
15
+ 'nw-resize': 'ne-resize',
16
+ 'nwse-resize': 'nesw-resize',
17
+ 'se-resize': 'sw-resize',
18
+ 'sw-resize': 'se-resize'
19
+ };
20
+ function splitByDivisor(value) {
21
+ const ast = (0, _postcssValueParser.default)(value);
22
+ const groups = [];
23
+ let currGroup = [];
24
+ function push() {
25
+ if (currGroup.length === 0) {
26
+ return;
27
+ }
28
+ groups.push(_postcssValueParser.default.stringify(currGroup));
29
+ currGroup = [];
30
+ }
31
+ for (const node of ast.nodes) {
32
+ if (node.type === 'div') {
33
+ push();
34
+ } else {
35
+ currGroup.push(node);
36
+ }
37
+ }
38
+ push();
39
+ return groups;
40
+ }
41
+ function flipSign(value) {
42
+ if (value === '0') {
43
+ return value;
44
+ } else {
45
+ return value[0] === '-' ? value.slice(1) : '-' + value;
46
+ }
47
+ }
48
+ function flipShadow(value) {
49
+ const defs = splitByDivisor(value);
50
+ const builtDefs = [];
51
+ for (const def of defs) {
52
+ const parts = def.split(' ');
53
+ const index = _postcssValueParser.default.unit(parts[0]) === false ? 1 : 0;
54
+ if (index < parts.length) {
55
+ parts[index] = flipSign(parts[index]);
56
+ }
57
+ builtDefs.push(parts.join(' '));
58
+ }
59
+ const rtl = builtDefs.join(',');
60
+ if (rtl !== value) {
61
+ return rtl;
62
+ }
63
+ }
64
+ const logicalToPhysical = {
65
+ start: 'right',
66
+ end: 'left',
67
+ 'inline-start': 'right',
68
+ 'inline-end': 'left'
69
+ };
70
+ const inlinePropertyToRTL = {
71
+ 'margin-inline-start': ([_key, val]) => ['margin-right', val],
72
+ 'margin-inline-end': ([_key, val]) => ['margin-left', val],
73
+ 'padding-inline-start': ([_key, val]) => ['padding-right', val],
74
+ 'padding-inline-end': ([_key, val]) => ['padding-left', val],
75
+ 'border-inline-start': ([_key, val]) => ['border-right', val],
76
+ 'border-inline-end': ([_key, val]) => ['border-left', val],
77
+ 'border-inline-start-width': ([_key, val]) => ['border-right-width', val],
78
+ 'border-inline-end-width': ([_key, val]) => ['border-left-width', val],
79
+ 'border-inline-start-color': ([_key, val]) => ['border-right-color', val],
80
+ 'border-inline-end-color': ([_key, val]) => ['border-left-color', val],
81
+ 'border-inline-start-style': ([_key, val]) => ['border-right-style', val],
82
+ 'border-inline-end-style': ([_key, val]) => ['border-left-style', val],
83
+ 'border-start-start-radius': ([_k, val]) => ['border-top-right-radius', val],
84
+ 'border-end-start-radius': ([_k, val]) => ['border-bottom-right-radius', val],
85
+ 'border-start-end-radius': ([_key, val]) => ['border-top-left-radius', val],
86
+ 'border-end-end-radius': ([_key, val]) => ['border-bottom-left-radius', val],
87
+ 'inset-inline-start': ([_key, val]) => ['right', val],
88
+ 'inset-inline-end': ([_key, val]) => ['left', val]
89
+ };
90
+ const propertyToRTL = {
91
+ 'margin-start': ([_key, val]) => ['margin-right', val],
92
+ 'margin-end': ([_key, val]) => ['margin-left', val],
93
+ 'padding-start': ([_key, val]) => ['padding-right', val],
94
+ 'padding-end': ([_key, val]) => ['padding-left', val],
95
+ 'border-start': ([_key, val]) => ['border-right', val],
96
+ 'border-end': ([_key, val]) => ['border-left', val],
97
+ 'border-start-width': ([_key, val]) => ['border-right-width', val],
98
+ 'border-end-width': ([_key, val]) => ['border-left-width', val],
99
+ 'border-start-color': ([_key, val]) => ['border-right-color', val],
100
+ 'border-end-color': ([_key, val]) => ['border-left-color', val],
101
+ 'border-start-style': ([_key, val]) => ['border-right-style', val],
102
+ 'border-end-style': ([_key, val]) => ['border-left-style', val],
103
+ 'border-top-start-radius': ([_key, val]) => ['border-top-right-radius', val],
104
+ 'border-bottom-start-radius': ([_k, v]) => ['border-bottom-right-radius', v],
105
+ 'border-top-end-radius': ([_key, val]) => ['border-top-left-radius', val],
106
+ 'border-bottom-end-radius': ([_k, val]) => ['border-bottom-left-radius', val],
107
+ float: ([key, val]) => logicalToPhysical[val] != null ? [key, logicalToPhysical[val]] : null,
108
+ clear: ([key, val]) => logicalToPhysical[val] != null ? [key, logicalToPhysical[val]] : null,
109
+ start: ([_key, val]) => ['right', val],
110
+ end: ([_key, val]) => ['left', val],
111
+ 'background-position': ([key, val]) => {
112
+ const words = val.split(' ');
113
+ if (!words.includes('start') && !words.includes('end')) {
114
+ return null;
115
+ }
116
+ return [key, words.map(word => word === 'start' || word === 'insetInlineStart' ? 'right' : word === 'end' || word === 'insetInlineEnd' ? 'left' : word).join(' ')];
117
+ },
118
+ cursor: ([key, val], options = _defaultOptions.defaultOptions) => {
119
+ if (!options.enableLegacyValueFlipping) {
120
+ return null;
121
+ }
122
+ return cursorFlip[val] != null ? [key, cursorFlip[val]] : null;
123
+ },
124
+ 'box-shadow': ([key, val], options = _defaultOptions.defaultOptions) => {
125
+ if (!options.enableLegacyValueFlipping) {
126
+ return null;
127
+ }
128
+ const rtlVal = flipShadow(val);
129
+ return rtlVal ? [key, rtlVal] : null;
130
+ },
131
+ 'text-shadow': ([key, val], options = _defaultOptions.defaultOptions) => {
132
+ if (!options.enableLegacyValueFlipping) {
133
+ return null;
134
+ }
135
+ const rtlVal = flipShadow(val);
136
+ return rtlVal ? [key, rtlVal] : null;
137
+ }
138
+ };
139
+ function generateRTL(pair, options = _defaultOptions.defaultOptions) {
140
+ const {
141
+ enableLogicalStylesPolyfill,
142
+ styleResolution
143
+ } = options;
144
+ const [key] = pair;
145
+ if (styleResolution === 'legacy-expand-shorthands') {
146
+ if (!enableLogicalStylesPolyfill) {
147
+ return null;
148
+ }
149
+ if (inlinePropertyToRTL[key]) {
150
+ return inlinePropertyToRTL[key](pair);
151
+ }
152
+ }
153
+ if (!propertyToRTL[key]) {
154
+ return null;
155
+ }
156
+ return propertyToRTL[key](pair, options);
157
+ }
@@ -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
+ * @flow strict
8
+ */
9
+
10
+ import type { StyleXOptions } from '../common-types';
11
+ declare export default function generateRTL(
12
+ pair: $ReadOnly<[string, string]>,
13
+ options?: StyleXOptions,
14
+ ): ?$ReadOnly<[string, string]>;
@@ -0,0 +1,51 @@
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
+ export type ClassesToOriginalPaths = {
12
+ readonly [className: string]: ReadonlyArray<string>;
13
+ };
14
+ export type ComputedStyle = null | Readonly<
15
+ [string, InjectableStyle, ClassesToOriginalPaths]
16
+ >;
17
+ export interface IPreRule {
18
+ compiled(options: StyleXOptions): ReadonlyArray<ComputedStyle>;
19
+ equals(other: IPreRule): boolean;
20
+ }
21
+ export type AnyPreRule = NullPreRule | PreRule | PreRuleSet;
22
+ export declare class NullPreRule implements IPreRule {
23
+ compiled(_options: StyleXOptions): [null];
24
+ equals(other: IPreRule): boolean;
25
+ }
26
+ export declare class PreRule implements IPreRule {
27
+ readonly property: string;
28
+ readonly value: string | number | ReadonlyArray<string | number>;
29
+ readonly keyPath: ReadonlyArray<string>;
30
+ constructor(
31
+ property: string,
32
+ value: string | number | ReadonlyArray<string | number>,
33
+ keyPath?: ReadonlyArray<string>,
34
+ );
35
+ get pseudos(): ReadonlyArray<string>;
36
+ get atRules(): ReadonlyArray<string>;
37
+ get constRules(): ReadonlyArray<string>;
38
+ compiled(
39
+ options: StyleXOptions,
40
+ ): ReadonlyArray<[string, InjectableStyle, ClassesToOriginalPaths]>;
41
+ equals(other: IPreRule): boolean;
42
+ }
43
+ export declare class PreRuleSet implements IPreRule {
44
+ readonly rules: ReadonlyArray<PreRule | NullPreRule>;
45
+ constructor(rules: ReadonlyArray<PreRule | NullPreRule>);
46
+ static create(
47
+ rules: ReadonlyArray<PreRule | NullPreRule | PreRuleSet>,
48
+ ): AnyPreRule;
49
+ compiled(options: StyleXOptions): ReadonlyArray<ComputedStyle>;
50
+ equals(other: IPreRule): boolean;
51
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PreRuleSet = exports.PreRule = exports.NullPreRule = void 0;
7
+ var _convertToClassName = require("../utils/convert-to-className");
8
+ var _objectUtils = require("../utils/object-utils");
9
+ var _ruleUtils = require("../utils/rule-utils");
10
+ class NullPreRule {
11
+ compiled(_options) {
12
+ return [null];
13
+ }
14
+ equals(other) {
15
+ return other instanceof NullPreRule;
16
+ }
17
+ }
18
+ exports.NullPreRule = NullPreRule;
19
+ class PreRule {
20
+ constructor(property, value, keyPath) {
21
+ this.property = property;
22
+ this.keyPath = keyPath ?? [];
23
+ this.value = value;
24
+ }
25
+ get pseudos() {
26
+ const unsortedPseudos = this.keyPath.filter(key => key.startsWith(':') || key.startsWith('['));
27
+ return (0, _ruleUtils.sortPseudos)(unsortedPseudos);
28
+ }
29
+ get atRules() {
30
+ const unsortedAtRules = this.keyPath.filter(key => key.startsWith('@'));
31
+ return (0, _ruleUtils.sortAtRules)(unsortedAtRules);
32
+ }
33
+ get constRules() {
34
+ return this.keyPath.filter(key => key.startsWith('var(--'));
35
+ }
36
+ compiled(options) {
37
+ const [_key, className, rule] = (0, _convertToClassName.convertStyleToClassName)([this.property, this.value], this.pseudos ?? [], this.atRules ?? [], this.constRules ?? [], options);
38
+ return [[className, rule, {
39
+ [className]: this.keyPath
40
+ }]];
41
+ }
42
+ equals(other) {
43
+ if (!(other instanceof PreRule)) {
44
+ return false;
45
+ }
46
+ const valuesEqual = Array.isArray(this.value) && Array.isArray(other.value) ? (0, _objectUtils.arrayEquals)(this.value, other.value) : this.value === other.value;
47
+ return this.property === other.property && valuesEqual && (0, _objectUtils.arrayEquals)(this.pseudos, other.pseudos) && (0, _objectUtils.arrayEquals)(this.atRules, other.atRules);
48
+ }
49
+ }
50
+ exports.PreRule = PreRule;
51
+ class PreRuleSet {
52
+ constructor(rules) {
53
+ this.rules = rules;
54
+ }
55
+ static create(rules) {
56
+ const flatRules = rules.flatMap(rule => rule instanceof PreRuleSet ? rule.rules : [rule]);
57
+ if (flatRules.length === 0) {
58
+ return new NullPreRule();
59
+ }
60
+ if (flatRules.length === 1) {
61
+ return flatRules[0];
62
+ }
63
+ return new PreRuleSet(flatRules);
64
+ }
65
+ compiled(options) {
66
+ const styleTuple = this.rules.flatMap(rule => rule.compiled(options)).filter(Boolean);
67
+ return styleTuple.length > 0 ? styleTuple : [null];
68
+ }
69
+ equals(other) {
70
+ if (!(other instanceof PreRuleSet)) {
71
+ return false;
72
+ }
73
+ if (this.rules.length !== other.rules.length) {
74
+ return false;
75
+ }
76
+ return (0, _objectUtils.arrayEquals)(this.rules, other.rules, (a, b) => a.equals(b));
77
+ }
78
+ }
79
+ exports.PreRuleSet = PreRuleSet;
@@ -0,0 +1,63 @@
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
+ export type ClassesToOriginalPaths = {
13
+ +[className: string]: $ReadOnlyArray<string>,
14
+ };
15
+
16
+ export type ComputedStyle = null | $ReadOnly<
17
+ [string, InjectableStyle, ClassesToOriginalPaths],
18
+ >;
19
+
20
+ // The classes in this file are used to represent objects that
21
+ // can be compiled into one or CSS rules.
22
+ //
23
+ // These are thin wrappers around the "values" in Raw Style Objects
24
+ // with all the metadata needed to compile them into CSS.
25
+ export interface IPreRule {
26
+ compiled(options: StyleXOptions): $ReadOnlyArray<ComputedStyle>;
27
+ equals(other: IPreRule): boolean;
28
+ }
29
+
30
+ export type AnyPreRule = NullPreRule | PreRule | PreRuleSet;
31
+
32
+ declare export class NullPreRule implements IPreRule {
33
+ compiled(_options: StyleXOptions): [null];
34
+ equals(other: IPreRule): boolean;
35
+ }
36
+
37
+ declare export class PreRule implements IPreRule {
38
+ +property: string;
39
+ +value: string | number | $ReadOnlyArray<string | number>;
40
+ +keyPath: $ReadOnlyArray<string>;
41
+ constructor(
42
+ property: string,
43
+ value: string | number | $ReadOnlyArray<string | number>,
44
+ keyPath?: $ReadOnlyArray<string>,
45
+ ): void;
46
+ get pseudos(): $ReadOnlyArray<string>;
47
+ get atRules(): $ReadOnlyArray<string>;
48
+ get constRules(): $ReadOnlyArray<string>;
49
+ compiled(
50
+ options: StyleXOptions,
51
+ ): $ReadOnlyArray<[string, InjectableStyle, ClassesToOriginalPaths]>;
52
+ equals(other: IPreRule): boolean;
53
+ }
54
+
55
+ declare export class PreRuleSet implements IPreRule {
56
+ +rules: $ReadOnlyArray<PreRule | NullPreRule>;
57
+ constructor(rules: $ReadOnlyArray<PreRule | NullPreRule>): void;
58
+ static create(
59
+ rules: $ReadOnlyArray<PreRule | NullPreRule | PreRuleSet>,
60
+ ): AnyPreRule;
61
+ compiled(options: StyleXOptions): $ReadOnlyArray<ComputedStyle>;
62
+ equals(other: IPreRule): boolean;
63
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var _PreRule = require("../PreRule");
4
+ const options = {
5
+ classNamePrefix: 'x',
6
+ styleResolution: 'legacy-expand-shorthands',
7
+ dev: false,
8
+ debug: false,
9
+ enableFontSizePxToRem: true,
10
+ runtimeInjection: false,
11
+ test: false
12
+ };
13
+ describe('Converting PreRule to CSS', () => {
14
+ test('should convert a PreRule to CSS', () => {
15
+ expect(new _PreRule.PreRule('color', 'red', ['color']).compiled(options)).toMatchInlineSnapshot(`
16
+ [
17
+ [
18
+ "x1e2nbdu",
19
+ {
20
+ "ltr": ".x1e2nbdu{color:red}",
21
+ "priority": 3000,
22
+ "rtl": null,
23
+ },
24
+ {
25
+ "x1e2nbdu": [
26
+ "color",
27
+ ],
28
+ },
29
+ ],
30
+ ]
31
+ `);
32
+ });
33
+ });
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+
3
+ var _PreRule = require("../PreRule");
4
+ var _flattenRawStyleObj = require("../flatten-raw-style-obj");
5
+ const options = {
6
+ classNamePrefix: 'x',
7
+ debug: false,
8
+ styleResolution: 'legacy-expand-shorthands',
9
+ runtimeInjection: false,
10
+ dev: false,
11
+ test: false
12
+ };
13
+ describe('Flatten Style Object with legacy shorthand expansion', () => {
14
+ describe('Simple Objects', () => {
15
+ test('should create PreRule objects for simple style values', () => {
16
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
17
+ color: 'red',
18
+ marginStart: 10
19
+ }, options)).toEqual([['color', new _PreRule.PreRule('color', 'red', ['color'])], ['marginInlineStart', new _PreRule.PreRule('marginInlineStart', 10, ['marginInlineStart'])], ['marginLeft', new _PreRule.NullPreRule()], ['marginRight', new _PreRule.NullPreRule()]]);
20
+ });
21
+ test('should expand simple gap values', () => {
22
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
23
+ gap: 10
24
+ }, options)).toEqual([['rowGap', new _PreRule.PreRule('rowGap', 10, ['rowGap'])], ['columnGap', new _PreRule.PreRule('columnGap', 10, ['columnGap'])]]);
25
+ });
26
+ test('should expand simple containIntrinsicSize values', () => {
27
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
28
+ containIntrinsicSize: 10
29
+ }, options)).toEqual([['containIntrinsicWidth', new _PreRule.PreRule('containIntrinsicWidth', 10, ['containIntrinsicWidth'])], ['containIntrinsicHeight', new _PreRule.PreRule('containIntrinsicHeight', 10, ['containIntrinsicHeight'])]]);
30
+ });
31
+ test('should expand simple shorthands', () => {
32
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
33
+ margin: 10
34
+ }, options)).toEqual([['marginTop', new _PreRule.PreRule('marginTop', 10, ['marginTop'])], ['marginInlineEnd', new _PreRule.PreRule('marginInlineEnd', 10, ['marginInlineEnd'])], ['marginBottom', new _PreRule.PreRule('marginBottom', 10, ['marginBottom'])], ['marginInlineStart', new _PreRule.PreRule('marginInlineStart', 10, ['marginInlineStart'])]]);
35
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
36
+ margin: 10,
37
+ marginBottom: 20
38
+ }, options)).toEqual([['marginTop', new _PreRule.PreRule('marginTop', 10, ['marginTop'])], ['marginInlineEnd', new _PreRule.PreRule('marginInlineEnd', 10, ['marginInlineEnd'])], ['marginBottom', new _PreRule.PreRule('marginBottom', 10, ['marginBottom'])], ['marginInlineStart', new _PreRule.PreRule('marginInlineStart', 10, ['marginInlineStart'])], ['marginBottom', new _PreRule.PreRule('marginBottom', 20, ['marginBottom'])]]);
39
+ });
40
+ test('should expand shorthands with space-separated values', () => {
41
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
42
+ margin: '10px 20px',
43
+ borderColor: 'red'
44
+ }, options)).toEqual([['marginTop', new _PreRule.PreRule('marginTop', '10px', ['marginTop'])], ['marginInlineEnd', new _PreRule.PreRule('marginInlineEnd', '20px', ['marginInlineEnd'])], ['marginBottom', new _PreRule.PreRule('marginBottom', '10px', ['marginBottom'])], ['marginInlineStart', new _PreRule.PreRule('marginInlineStart', '20px', ['marginInlineStart'])], ['borderTopColor', new _PreRule.PreRule('borderTopColor', 'red', ['borderTopColor'])], ['borderInlineEndColor', new _PreRule.PreRule('borderInlineEndColor', 'red', ['borderInlineEndColor'])], ['borderBottomColor', new _PreRule.PreRule('borderBottomColor', 'red', ['borderBottomColor'])], ['borderInlineStartColor', new _PreRule.PreRule('borderInlineStartColor', 'red', ['borderInlineStartColor'])]]);
45
+ });
46
+ test('should expand simple gap with space-separated values', () => {
47
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
48
+ gap: '10px 20px'
49
+ }, options)).toEqual([['rowGap', new _PreRule.PreRule('rowGap', '10px', ['rowGap'])], ['columnGap', new _PreRule.PreRule('columnGap', '20px', ['columnGap'])]]);
50
+ });
51
+ test('should expand simple containIntrinsicSize with space-separated values', () => {
52
+ const w = 'containIntrinsicWidth';
53
+ const h = 'containIntrinsicHeight';
54
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
55
+ containIntrinsicSize: '10px 20px'
56
+ }, options)).toEqual([[w, new _PreRule.PreRule(w, '10px', [w])], [h, new _PreRule.PreRule(h, '20px', [h])]]);
57
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
58
+ containIntrinsicSize: 'auto 10px 20px'
59
+ }, options)).toEqual([[w, new _PreRule.PreRule(w, 'auto 10px', [w])], [h, new _PreRule.PreRule(h, '20px', [h])]]);
60
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
61
+ containIntrinsicSize: '10px auto 20px'
62
+ }, options)).toEqual([[w, new _PreRule.PreRule(w, '10px', [w])], [h, new _PreRule.PreRule(h, 'auto 20px', [h])]]);
63
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
64
+ containIntrinsicSize: 'auto 10px auto 20px'
65
+ }, options)).toEqual([[w, new _PreRule.PreRule(w, 'auto 10px', [w])], [h, new _PreRule.PreRule(h, 'auto 20px', [h])]]);
66
+ });
67
+ test('should expand shorthands with fallbacks', () => {
68
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
69
+ margin: ['10vh 20px', '10dvh 20px']
70
+ }, options)).toEqual([['marginTop', new _PreRule.PreRule('marginTop', ['10vh', '10dvh'], ['marginTop'])], ['marginInlineEnd', new _PreRule.PreRule('marginInlineEnd', '20px', ['marginInlineEnd'])], ['marginBottom', new _PreRule.PreRule('marginBottom', ['10vh', '10dvh'], ['marginBottom'])], ['marginInlineStart', new _PreRule.PreRule('marginInlineStart', '20px', ['marginInlineStart'])]]);
71
+ });
72
+ });
73
+ describe('Nested Objects', () => {
74
+ test('Legacy Pseudo classes', () => {
75
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
76
+ color: 'blue',
77
+ marginStart: 0,
78
+ ':hover': {
79
+ color: 'red',
80
+ marginStart: 10
81
+ }
82
+ }, options)).toEqual([['color', new _PreRule.PreRule('color', 'blue', ['color'])], ['marginInlineStart', new _PreRule.PreRule('marginInlineStart', 0, ['marginInlineStart'])], ['marginLeft', new _PreRule.NullPreRule()], ['marginRight', new _PreRule.NullPreRule()], [':hover_color', new _PreRule.PreRule('color', 'red', [':hover', 'color'])], [':hover_marginInlineStart', new _PreRule.PreRule('marginInlineStart', 10, [':hover', 'marginInlineStart'])], [':hover_marginLeft', new _PreRule.NullPreRule()], [':hover_marginRight', new _PreRule.NullPreRule()]]);
83
+ });
84
+ test('Modern Pseudo classes', () => {
85
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
86
+ color: {
87
+ default: 'blue',
88
+ ':hover': 'red'
89
+ },
90
+ marginStart: {
91
+ default: 0,
92
+ ':hover': 10
93
+ }
94
+ }, options)).toEqual([['color', _PreRule.PreRuleSet.create([new _PreRule.PreRule('color', 'blue', ['color', 'default']), new _PreRule.PreRule('color', 'red', ['color', ':hover'])])], ['marginInlineStart', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginInlineStart', 0, ['marginInlineStart', 'default']), new _PreRule.PreRule('marginInlineStart', 10, ['marginInlineStart', ':hover'])])], ['marginLeft', _PreRule.PreRuleSet.create([new _PreRule.NullPreRule(), new _PreRule.NullPreRule()])], ['marginRight', _PreRule.PreRuleSet.create([new _PreRule.NullPreRule(), new _PreRule.NullPreRule()])]]);
95
+ });
96
+ test('Modern Pseudo classes with shorthands', () => {
97
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
98
+ color: {
99
+ default: 'blue',
100
+ ':hover': 'red'
101
+ },
102
+ margin: {
103
+ default: 0,
104
+ ':hover': 10
105
+ }
106
+ }, options)).toEqual([['color', _PreRule.PreRuleSet.create([new _PreRule.PreRule('color', 'blue', ['color', 'default']), new _PreRule.PreRule('color', 'red', ['color', ':hover'])])], ['marginTop', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginTop', 0, ['marginTop', 'default']), new _PreRule.PreRule('marginTop', 10, ['marginTop', ':hover'])])], ['marginInlineEnd', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginInlineEnd', 0, ['marginInlineEnd', 'default']), new _PreRule.PreRule('marginInlineEnd', 10, ['marginInlineEnd', ':hover'])])], ['marginBottom', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginBottom', 0, ['marginBottom', 'default']), new _PreRule.PreRule('marginBottom', 10, ['marginBottom', ':hover'])])], ['marginInlineStart', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginInlineStart', 0, ['marginInlineStart', 'default']), new _PreRule.PreRule('marginInlineStart', 10, ['marginInlineStart', ':hover'])])]]);
107
+ });
108
+ test('Modern Pseudo classes with complex shorthands', () => {
109
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
110
+ color: {
111
+ default: 'blue',
112
+ ':hover': 'red'
113
+ },
114
+ margin: {
115
+ default: '1px 2px 3px 4px',
116
+ ':hover': '10px 20px'
117
+ }
118
+ }, options)).toEqual([['color', _PreRule.PreRuleSet.create([new _PreRule.PreRule('color', 'blue', ['color', 'default']), new _PreRule.PreRule('color', 'red', ['color', ':hover'])])], ['marginTop', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginTop', '1px', ['marginTop', 'default']), new _PreRule.PreRule('marginTop', '10px', ['marginTop', ':hover'])])], ['marginInlineEnd', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginInlineEnd', '2px', ['marginInlineEnd', 'default']), new _PreRule.PreRule('marginInlineEnd', '20px', ['marginInlineEnd', ':hover'])])], ['marginBottom', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginBottom', '3px', ['marginBottom', 'default']), new _PreRule.PreRule('marginBottom', '10px', ['marginBottom', ':hover'])])], ['marginInlineStart', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginInlineStart', '4px', ['marginInlineStart', 'default']), new _PreRule.PreRule('marginInlineStart', '20px', ['marginInlineStart', ':hover'])])]]);
119
+ });
120
+ test('Modern pseudo and at-rules', () => {
121
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
122
+ color: {
123
+ default: 'blue',
124
+ ':hover': 'red',
125
+ '@media (min-width: 300px)': 'green'
126
+ },
127
+ marginStart: {
128
+ default: 0,
129
+ ':hover': 10
130
+ }
131
+ }, options)).toEqual([['color', _PreRule.PreRuleSet.create([new _PreRule.PreRule('color', 'blue', ['color', 'default']), new _PreRule.PreRule('color', 'red', ['color', ':hover']), new _PreRule.PreRule('color', 'green', ['color', '@media (min-width: 300px)'])])], ['marginInlineStart', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginInlineStart', 0, ['marginInlineStart', 'default']), new _PreRule.PreRule('marginInlineStart', 10, ['marginInlineStart', ':hover'])])], ['marginLeft', _PreRule.PreRuleSet.create([new _PreRule.NullPreRule(), new _PreRule.NullPreRule()])], ['marginRight', _PreRule.PreRuleSet.create([new _PreRule.NullPreRule(), new _PreRule.NullPreRule()])]]);
132
+ });
133
+ test('Attribute selector conditions', () => {
134
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
135
+ color: {
136
+ default: 'blue',
137
+ '[data-panel-state="open"]': 'red'
138
+ }
139
+ }, options)).toEqual([['color', _PreRule.PreRuleSet.create([new _PreRule.PreRule('color', 'blue', ['color', 'default']), new _PreRule.PreRule('color', 'red', ['color', '[data-panel-state="open"]'])])]]);
140
+ });
141
+ });
142
+ describe('Multiple levels of nesting', () => {
143
+ test('Fallback styles within nested objects', () => {
144
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
145
+ margin: {
146
+ default: '1px 2px 3px 4px',
147
+ ':hover': ['10px 20px', '1dvh 2dvw']
148
+ }
149
+ }, options)).toEqual([['marginTop', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginTop', '1px', ['marginTop', 'default']), new _PreRule.PreRule('marginTop', ['10px', '1dvh'], ['marginTop', ':hover'])])], ['marginInlineEnd', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginInlineEnd', '2px', ['marginInlineEnd', 'default']), new _PreRule.PreRule('marginInlineEnd', ['20px', '2dvw'], ['marginInlineEnd', ':hover'])])], ['marginBottom', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginBottom', '3px', ['marginBottom', 'default']), new _PreRule.PreRule('marginBottom', ['10px', '1dvh'], ['marginBottom', ':hover'])])], ['marginInlineStart', _PreRule.PreRuleSet.create([new _PreRule.PreRule('marginInlineStart', '4px', ['marginInlineStart', 'default']), new _PreRule.PreRule('marginInlineStart', ['20px', '2dvw'], ['marginInlineStart', ':hover'])])]]);
150
+ });
151
+ test('pseudo within a media query - legacy syntax', () => {
152
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
153
+ '@media (min-width: 300px)': {
154
+ ':hover': {
155
+ color: 'red'
156
+ }
157
+ }
158
+ }, options)).toEqual([['@media (min-width: 300px)_:hover_color', _PreRule.PreRuleSet.create([new _PreRule.PreRule('color', 'red', ['@media (min-width: 300px)', ':hover', 'color'])])]]);
159
+ });
160
+ test('pseudo with a pseudo within a media query - legacy syntax', () => {
161
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
162
+ '@media (min-width: 300px)': {
163
+ ':hover': {
164
+ color: 'pink',
165
+ ':active': {
166
+ color: 'red'
167
+ }
168
+ }
169
+ }
170
+ }, options)).toEqual([['@media (min-width: 300px)_:hover_color', _PreRule.PreRuleSet.create([new _PreRule.PreRule('color', 'pink', ['@media (min-width: 300px)', ':hover', 'color'])])], ['@media (min-width: 300px)_:hover_:active_color', _PreRule.PreRuleSet.create([new _PreRule.PreRule('color', 'red', ['@media (min-width: 300px)', ':hover', ':active', 'color'])])]]);
171
+ });
172
+ test('pseudo within a media query - modern syntax', () => {
173
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
174
+ color: {
175
+ default: 'blue',
176
+ '@media (min-width: 300px)': {
177
+ ':hover': 'red'
178
+ }
179
+ }
180
+ }, options)).toEqual([['color', _PreRule.PreRuleSet.create([new _PreRule.PreRule('color', 'blue', ['color', 'default']), new _PreRule.PreRule('color', 'red', ['color', '@media (min-width: 300px)', ':hover'])])]]);
181
+ });
182
+ test('extra deep, pseudo within a media query - modern syntax', () => {
183
+ expect((0, _flattenRawStyleObj.flattenRawStyleObject)({
184
+ color: {
185
+ default: 'blue',
186
+ '@media (min-width: 300px)': {
187
+ ':hover': {
188
+ default: 'red',
189
+ ':active': 'maroon'
190
+ }
191
+ }
192
+ }
193
+ }, options)).toEqual([['color', _PreRule.PreRuleSet.create([new _PreRule.PreRule('color', 'blue', ['color', 'default']), new _PreRule.PreRule('color', 'red', ['color', '@media (min-width: 300px)', ':hover', 'default']), new _PreRule.PreRule('color', 'maroon', ['color', '@media (min-width: 300px)', ':hover', ':active'])])]]);
194
+ });
195
+ });
196
+ });