Skip to main content

stylex_constants/constants/
common.rs

1pub static DEFAULT_INJECT_PATH: &str = "@stylexjs/stylex/lib/stylex-inject";
2use once_cell::sync::Lazy;
3use phf::phf_set;
4
5// Using MDN data as a source of truth to populate the above sets
6// by group in alphabetical order:
7
8pub static VALID_CALLEES: phf::Set<&'static str> = phf_set! {
9
10  "String", "Number", "Math", "Object", "Array"
11};
12
13pub static MUTATING_ARRAY_METHODS: phf::Set<&'static str> = phf_set! {
14  "push",
15  "pop",
16  "shift",
17  "unshift",
18  "splice",
19  "sort",
20  "reverse",
21  "fill",
22  "copyWithin",
23};
24
25pub static MUTATING_OBJECT_METHODS: phf::Set<&'static str> = phf_set! {
26  "assign",
27  "defineProperty",
28  "defineProperties",
29  "setPrototypeOf",
30};
31
32pub static INVALID_METHODS: phf::Set<&'static str> = phf_set! {
33  "random",
34  "assign",
35  "defineProperties",
36  "defineProperty",
37  "freeze",
38  "seal",
39  "splice",
40};
41
42pub static COMPILED_KEY: &str = "$$css";
43
44pub static SPLIT_TOKEN: &str = "__$$__";
45
46pub static ROOT_FONT_SIZE: i8 = 16;
47
48pub static VAR_GROUP_HASH_KEY: &str = "__varGroupHash__";
49
50pub static COLOR_FUNCTION_LISTED_NORMALIZED_PROPERTY_VALUES: Lazy<[&str; 9]> = Lazy::new(|| {
51  [
52    "oklch",
53    "lch",
54    "oklab",
55    "hsla",
56    "radial-gradient",
57    "hwb",
58    "lab",
59    "clamp",
60    "hsl",
61  ]
62});
63
64pub static COLOR_RELATIVE_VALUES_LISTED_NORMALIZED_PROPERTY_VALUES: Lazy<[&str; 7]> =
65  Lazy::new(|| [" a ", " b ", " c ", " l ", " h ", " s ", " w "]);
66
67pub static CSS_CONTENT_FUNCTIONS: Lazy<[&str; 7]> = Lazy::new(|| {
68  [
69    "attr(",
70    "counter(",
71    "counters(",
72    "url(",
73    "linear-gradient(",
74    "image-set(",
75    "var(--",
76  ]
77});
78
79pub static CSS_CONTENT_KEYWORDS: Lazy<[&str; 11]> = Lazy::new(|| {
80  [
81    "normal",
82    "none",
83    "open-quote",
84    "close-quote",
85    "no-open-quote",
86    "no-close-quote",
87    "inherit",
88    "initial",
89    "revert",
90    "revert-layer",
91    "unset",
92  ]
93});
94
95// TODO: Once we have a reliable validator, these property checks should be replaced with
96// validators that can also validate the values.
97pub static VALID_POSITION_TRY_PROPERTIES: Lazy<[&str; 40]> = Lazy::new(|| {
98  [
99    // anchor Properties
100    "anchorName",
101    // position Properties
102    "positionAnchor",
103    "positionArea",
104    // inset Properties
105    "top",
106    "right",
107    "bottom",
108    "left",
109    "inset",
110    "insetBlock",
111    "insetBlockEnd",
112    "insetBlockStart",
113    "insetInline",
114    "insetInlineEnd",
115    "insetInlineStart",
116    // margin Properties
117    "margin",
118    "marginBlock",
119    "marginBlockEnd",
120    "marginBlockStart",
121    "marginInline",
122    "marginInlineEnd",
123    "marginInlineStart",
124    "marginTop",
125    "marginBottom",
126    "marginLeft",
127    "marginRight",
128    // size properties
129    "width",
130    "height",
131    "minWidth",
132    "minHeight",
133    "maxWidth",
134    "maxHeight",
135    "blockSize",
136    "inlineSize",
137    "minBlockSize",
138    "minInlineSize",
139    "maxBlockSize",
140    "maxInlineSize",
141    // self alignment properties
142    "alignSelf",
143    "justifySelf",
144    "placeSelf",
145  ]
146});
147
148// Validation of `stylex.viewTransitionClass` function call
149pub static VALID_VIEW_TRANSITION_CLASS_PROPERTIES: Lazy<[&str; 4]> =
150  Lazy::new(|| ["group", "imagePair", "old", "new"]);
151
152pub static CONSTS_FILE_EXTENSION: &str = ".const";
153
154/// CSS custom property used in the logical float/clear value polyfill system.
155/// Represents the logical "start" direction for float/clear, which maps to the physical
156/// direction "left" in left-to-right (LTR) text direction and "right" in right-to-left (RTL).
157/// This variable should be defined on the root or relevant container elements, typically by
158/// a polyfill or runtime logic that sets its value based on the current text direction.
159///
160/// This ensures that logical float/clear values behave correctly in both LTR and RTL contexts.
161pub static LOGICAL_FLOAT_START_VAR: &str = "--stylex-logical-start";
162
163/// CSS custom property used in the logical float/clear value polyfill system.
164/// Represents the logical "end" direction for float/clear, which maps to the physical
165/// direction "right" in left-to-right (LTR) text direction and "left" in right-to-left (RTL).
166/// This variable should be defined on the root or relevant container elements, typically by
167/// a polyfill or runtime logic that sets its value based on the current text direction.
168///
169/// This ensures that logical float/clear values behave correctly in both LTR and RTL contexts.
170pub static LOGICAL_FLOAT_END_VAR: &str = "--stylex-logical-end";
171
172/// List of valid JSX runtime call names to check against when determining if a call expression is a JSX runtime call.
173/// This includes both the classic React.createElement and the newer jsx/jsxs calls, as well as their DEV variants.
174///
175/// Supported:
176/// - React runtime: `_jsx`, `_jsxs`
177/// - React classic: `createElement`, `React.createElement`
178/// - Vue runtime: `_createElementBlock`, `_createElementVNode`, `_createVNode`
179///
180///   The DEV variants (e.g., `_jsxDEV`) are also included by checking for a "DEV" suffix,
181///   which is commonly used in development builds of React to provide additional debugging information.
182pub static RUNTIME_JSX_CALL_NAMES: &[&str] = &[
183  "jsx",
184  "jsxs",
185  "createElement",
186  "createElementBlock",
187  "createElementVNode",
188  "createVNode",
189];