react-native-css 3.0.0-nightly.75f8b74 → 3.0.0-nightly.d8cb1bc

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 (214) hide show
  1. package/dist/commonjs/compiler/atRules.js +1 -1
  2. package/dist/commonjs/compiler/attributes.test.js +1 -1
  3. package/dist/commonjs/compiler/attributes.test.js.map +1 -1
  4. package/dist/commonjs/compiler/compiler.js +26 -17
  5. package/dist/commonjs/compiler/compiler.js.map +1 -1
  6. package/dist/commonjs/compiler/declarations.js +164 -72
  7. package/dist/commonjs/compiler/declarations.js.map +1 -1
  8. package/dist/commonjs/compiler/inheritance.test.js +7 -7
  9. package/dist/commonjs/compiler/inheritance.test.js.map +1 -1
  10. package/dist/commonjs/compiler/selector-builder.js +457 -0
  11. package/dist/commonjs/compiler/selector-builder.js.map +1 -0
  12. package/dist/commonjs/compiler/selectors.js +10 -6
  13. package/dist/commonjs/compiler/selectors.js.map +1 -1
  14. package/dist/commonjs/compiler/stylesheet.js +113 -39
  15. package/dist/commonjs/compiler/stylesheet.js.map +1 -1
  16. package/dist/commonjs/jest/index.js +16 -5
  17. package/dist/commonjs/jest/index.js.map +1 -1
  18. package/dist/commonjs/metro/index.js +1 -1
  19. package/dist/commonjs/metro/index.js.map +1 -1
  20. package/dist/commonjs/poison.pill.js +4 -1
  21. package/dist/commonjs/poison.pill.js.map +1 -1
  22. package/dist/commonjs/runtime/native/conditions/attributes.js +42 -0
  23. package/dist/commonjs/runtime/native/conditions/attributes.js.map +1 -0
  24. package/dist/commonjs/runtime/native/conditions/container-query.js +28 -21
  25. package/dist/commonjs/runtime/native/conditions/container-query.js.map +1 -1
  26. package/dist/commonjs/runtime/native/conditions/guards.js.map +1 -1
  27. package/dist/commonjs/runtime/native/conditions/index.js +10 -46
  28. package/dist/commonjs/runtime/native/conditions/index.js.map +1 -1
  29. package/dist/commonjs/runtime/native/conditions/media-query.js +17 -17
  30. package/dist/commonjs/runtime/native/conditions/media-query.js.map +1 -1
  31. package/dist/commonjs/runtime/native/injection.js +3 -2
  32. package/dist/commonjs/runtime/native/injection.js.map +1 -1
  33. package/dist/commonjs/runtime/native/react/interaction.js +10 -10
  34. package/dist/commonjs/runtime/native/react/interaction.js.map +1 -1
  35. package/dist/commonjs/runtime/native/react/rules.js +9 -9
  36. package/dist/commonjs/runtime/native/react/rules.js.map +1 -1
  37. package/dist/commonjs/runtime/native/react/useNativeCss.js +1 -0
  38. package/dist/commonjs/runtime/native/react/useNativeCss.js.map +1 -1
  39. package/dist/commonjs/runtime/native/reactivity.js +1 -12
  40. package/dist/commonjs/runtime/native/reactivity.js.map +1 -1
  41. package/dist/commonjs/runtime/native/root.js +28 -0
  42. package/dist/commonjs/runtime/native/root.js.map +1 -0
  43. package/dist/commonjs/runtime/native/styles/calculate-props.js +53 -48
  44. package/dist/commonjs/runtime/native/styles/calculate-props.js.map +1 -1
  45. package/dist/commonjs/runtime/native/styles/index.js +12 -12
  46. package/dist/commonjs/runtime/native/styles/index.js.map +1 -1
  47. package/dist/commonjs/runtime/native/styles/units.js +6 -3
  48. package/dist/commonjs/runtime/native/styles/units.js.map +1 -1
  49. package/dist/commonjs/runtime/native/styles/variables.js +3 -2
  50. package/dist/commonjs/runtime/native/styles/variables.js.map +1 -1
  51. package/dist/commonjs/runtime/utils/specificity.js +2 -1
  52. package/dist/commonjs/runtime/utils/specificity.js.map +1 -1
  53. package/dist/module/compiler/atRules.js +1 -1
  54. package/dist/module/compiler/attributes.test.js +1 -1
  55. package/dist/module/compiler/attributes.test.js.map +1 -1
  56. package/dist/module/compiler/compiler.js +26 -17
  57. package/dist/module/compiler/compiler.js.map +1 -1
  58. package/dist/module/compiler/compiler.types.js.map +1 -1
  59. package/dist/module/compiler/declarations.js +159 -68
  60. package/dist/module/compiler/declarations.js.map +1 -1
  61. package/dist/module/compiler/inheritance.test.js +7 -7
  62. package/dist/module/compiler/inheritance.test.js.map +1 -1
  63. package/dist/module/compiler/selector-builder.js +452 -0
  64. package/dist/module/compiler/selector-builder.js.map +1 -0
  65. package/dist/module/compiler/selectors.js +10 -6
  66. package/dist/module/compiler/selectors.js.map +1 -1
  67. package/dist/module/compiler/stylesheet.js +112 -38
  68. package/dist/module/compiler/stylesheet.js.map +1 -1
  69. package/dist/module/jest/index.js +16 -4
  70. package/dist/module/jest/index.js.map +1 -1
  71. package/dist/module/metro/index.js +1 -1
  72. package/dist/module/metro/index.js.map +1 -1
  73. package/dist/module/poison.pill.js +4 -1
  74. package/dist/module/poison.pill.js.map +1 -1
  75. package/dist/module/runtime/native/conditions/attributes.js +38 -0
  76. package/dist/module/runtime/native/conditions/attributes.js.map +1 -0
  77. package/dist/module/runtime/native/conditions/container-query.js +28 -21
  78. package/dist/module/runtime/native/conditions/container-query.js.map +1 -1
  79. package/dist/module/runtime/native/conditions/guards.js.map +1 -1
  80. package/dist/module/runtime/native/conditions/index.js +10 -46
  81. package/dist/module/runtime/native/conditions/index.js.map +1 -1
  82. package/dist/module/runtime/native/conditions/media-query.js +17 -17
  83. package/dist/module/runtime/native/conditions/media-query.js.map +1 -1
  84. package/dist/module/runtime/native/injection.js +2 -1
  85. package/dist/module/runtime/native/injection.js.map +1 -1
  86. package/dist/module/runtime/native/react/interaction.js +10 -10
  87. package/dist/module/runtime/native/react/interaction.js.map +1 -1
  88. package/dist/module/runtime/native/react/rules.js +9 -9
  89. package/dist/module/runtime/native/react/rules.js.map +1 -1
  90. package/dist/module/runtime/native/react/useNativeCss.js +1 -0
  91. package/dist/module/runtime/native/react/useNativeCss.js.map +1 -1
  92. package/dist/module/runtime/native/reactivity.js +0 -11
  93. package/dist/module/runtime/native/reactivity.js.map +1 -1
  94. package/dist/module/runtime/native/root.js +24 -0
  95. package/dist/module/runtime/native/root.js.map +1 -0
  96. package/dist/module/runtime/native/styles/calculate-props.js +53 -48
  97. package/dist/module/runtime/native/styles/calculate-props.js.map +1 -1
  98. package/dist/module/runtime/native/styles/index.js +12 -12
  99. package/dist/module/runtime/native/styles/index.js.map +1 -1
  100. package/dist/module/runtime/native/styles/units.js +6 -3
  101. package/dist/module/runtime/native/styles/units.js.map +1 -1
  102. package/dist/module/runtime/native/styles/variables.js +2 -1
  103. package/dist/module/runtime/native/styles/variables.js.map +1 -1
  104. package/dist/module/runtime/utils/specificity.js +2 -1
  105. package/dist/module/runtime/utils/specificity.js.map +1 -1
  106. package/dist/typescript/commonjs/src/compiler/compiler.d.ts +9 -2
  107. package/dist/typescript/commonjs/src/compiler/compiler.d.ts.map +1 -1
  108. package/dist/typescript/commonjs/src/compiler/compiler.types.d.ts +5 -4
  109. package/dist/typescript/commonjs/src/compiler/compiler.types.d.ts.map +1 -1
  110. package/dist/typescript/commonjs/src/compiler/declarations.d.ts +16 -19
  111. package/dist/typescript/commonjs/src/compiler/declarations.d.ts.map +1 -1
  112. package/dist/typescript/commonjs/src/compiler/selector-builder.d.ts +23 -0
  113. package/dist/typescript/commonjs/src/compiler/selector-builder.d.ts.map +1 -0
  114. package/dist/typescript/commonjs/src/compiler/selectors.d.ts +3 -2
  115. package/dist/typescript/commonjs/src/compiler/selectors.d.ts.map +1 -1
  116. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts +21 -7
  117. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
  118. package/dist/typescript/commonjs/src/jest/index.d.ts +8 -1
  119. package/dist/typescript/commonjs/src/jest/index.d.ts.map +1 -1
  120. package/dist/typescript/commonjs/src/metro/index.d.ts.map +1 -1
  121. package/dist/typescript/commonjs/src/poison.pill.d.ts.map +1 -1
  122. package/dist/typescript/commonjs/src/runtime/native/conditions/attributes.d.ts +5 -0
  123. package/dist/typescript/commonjs/src/runtime/native/conditions/attributes.d.ts.map +1 -0
  124. package/dist/typescript/commonjs/src/runtime/native/conditions/container-query.d.ts +3 -3
  125. package/dist/typescript/commonjs/src/runtime/native/conditions/container-query.d.ts.map +1 -1
  126. package/dist/typescript/commonjs/src/runtime/native/conditions/guards.d.ts +2 -2
  127. package/dist/typescript/commonjs/src/runtime/native/conditions/guards.d.ts.map +1 -1
  128. package/dist/typescript/commonjs/src/runtime/native/conditions/index.d.ts +2 -2
  129. package/dist/typescript/commonjs/src/runtime/native/conditions/index.d.ts.map +1 -1
  130. package/dist/typescript/commonjs/src/runtime/native/conditions/media-query.d.ts +2 -2
  131. package/dist/typescript/commonjs/src/runtime/native/conditions/media-query.d.ts.map +1 -1
  132. package/dist/typescript/commonjs/src/runtime/native/injection.d.ts.map +1 -1
  133. package/dist/typescript/commonjs/src/runtime/native/react/interaction.d.ts +2 -2
  134. package/dist/typescript/commonjs/src/runtime/native/react/interaction.d.ts.map +1 -1
  135. package/dist/typescript/commonjs/src/runtime/native/react/useNativeCss.d.ts +2 -1
  136. package/dist/typescript/commonjs/src/runtime/native/react/useNativeCss.d.ts.map +1 -1
  137. package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts +2 -10
  138. package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts.map +1 -1
  139. package/dist/typescript/commonjs/src/runtime/native/root.d.ts +11 -0
  140. package/dist/typescript/commonjs/src/runtime/native/root.d.ts.map +1 -0
  141. package/dist/typescript/commonjs/src/runtime/native/styles/calculate-props.d.ts.map +1 -1
  142. package/dist/typescript/commonjs/src/runtime/native/styles/units.d.ts.map +1 -1
  143. package/dist/typescript/commonjs/src/runtime/native/styles/variables.d.ts.map +1 -1
  144. package/dist/typescript/commonjs/src/runtime/utils/specificity.d.ts +1 -0
  145. package/dist/typescript/commonjs/src/runtime/utils/specificity.d.ts.map +1 -1
  146. package/dist/typescript/module/src/compiler/compiler.d.ts +9 -2
  147. package/dist/typescript/module/src/compiler/compiler.d.ts.map +1 -1
  148. package/dist/typescript/module/src/compiler/compiler.types.d.ts +5 -4
  149. package/dist/typescript/module/src/compiler/compiler.types.d.ts.map +1 -1
  150. package/dist/typescript/module/src/compiler/declarations.d.ts +16 -19
  151. package/dist/typescript/module/src/compiler/declarations.d.ts.map +1 -1
  152. package/dist/typescript/module/src/compiler/selector-builder.d.ts +23 -0
  153. package/dist/typescript/module/src/compiler/selector-builder.d.ts.map +1 -0
  154. package/dist/typescript/module/src/compiler/selectors.d.ts +3 -2
  155. package/dist/typescript/module/src/compiler/selectors.d.ts.map +1 -1
  156. package/dist/typescript/module/src/compiler/stylesheet.d.ts +21 -7
  157. package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
  158. package/dist/typescript/module/src/jest/index.d.ts +8 -1
  159. package/dist/typescript/module/src/jest/index.d.ts.map +1 -1
  160. package/dist/typescript/module/src/metro/index.d.ts.map +1 -1
  161. package/dist/typescript/module/src/poison.pill.d.ts.map +1 -1
  162. package/dist/typescript/module/src/runtime/native/conditions/attributes.d.ts +5 -0
  163. package/dist/typescript/module/src/runtime/native/conditions/attributes.d.ts.map +1 -0
  164. package/dist/typescript/module/src/runtime/native/conditions/container-query.d.ts +3 -3
  165. package/dist/typescript/module/src/runtime/native/conditions/container-query.d.ts.map +1 -1
  166. package/dist/typescript/module/src/runtime/native/conditions/guards.d.ts +2 -2
  167. package/dist/typescript/module/src/runtime/native/conditions/guards.d.ts.map +1 -1
  168. package/dist/typescript/module/src/runtime/native/conditions/index.d.ts +2 -2
  169. package/dist/typescript/module/src/runtime/native/conditions/index.d.ts.map +1 -1
  170. package/dist/typescript/module/src/runtime/native/conditions/media-query.d.ts +2 -2
  171. package/dist/typescript/module/src/runtime/native/conditions/media-query.d.ts.map +1 -1
  172. package/dist/typescript/module/src/runtime/native/injection.d.ts.map +1 -1
  173. package/dist/typescript/module/src/runtime/native/react/interaction.d.ts +2 -2
  174. package/dist/typescript/module/src/runtime/native/react/interaction.d.ts.map +1 -1
  175. package/dist/typescript/module/src/runtime/native/react/useNativeCss.d.ts +2 -1
  176. package/dist/typescript/module/src/runtime/native/react/useNativeCss.d.ts.map +1 -1
  177. package/dist/typescript/module/src/runtime/native/reactivity.d.ts +2 -10
  178. package/dist/typescript/module/src/runtime/native/reactivity.d.ts.map +1 -1
  179. package/dist/typescript/module/src/runtime/native/root.d.ts +11 -0
  180. package/dist/typescript/module/src/runtime/native/root.d.ts.map +1 -0
  181. package/dist/typescript/module/src/runtime/native/styles/calculate-props.d.ts.map +1 -1
  182. package/dist/typescript/module/src/runtime/native/styles/units.d.ts.map +1 -1
  183. package/dist/typescript/module/src/runtime/native/styles/variables.d.ts.map +1 -1
  184. package/dist/typescript/module/src/runtime/utils/specificity.d.ts +1 -0
  185. package/dist/typescript/module/src/runtime/utils/specificity.d.ts.map +1 -1
  186. package/package.json +3 -3
  187. package/src/compiler/atRules.ts +1 -1
  188. package/src/compiler/attributes.test.ts +1 -1
  189. package/src/compiler/compiler.ts +30 -31
  190. package/src/compiler/compiler.types.ts +7 -5
  191. package/src/compiler/declarations.ts +273 -67
  192. package/src/compiler/inheritance.test.ts +6 -6
  193. package/src/compiler/selector-builder.ts +531 -0
  194. package/src/compiler/selectors.ts +20 -6
  195. package/src/compiler/stylesheet.ts +154 -45
  196. package/src/jest/index.ts +19 -4
  197. package/src/metro/index.ts +6 -3
  198. package/src/poison.pill.ts +5 -1
  199. package/src/runtime/native/conditions/attributes.ts +52 -0
  200. package/src/runtime/native/conditions/container-query.ts +27 -22
  201. package/src/runtime/native/conditions/guards.ts +1 -2
  202. package/src/runtime/native/conditions/index.ts +12 -66
  203. package/src/runtime/native/conditions/media-query.ts +18 -20
  204. package/src/runtime/native/injection.ts +1 -1
  205. package/src/runtime/native/react/interaction.ts +12 -12
  206. package/src/runtime/native/react/rules.ts +9 -9
  207. package/src/runtime/native/react/useNativeCss.ts +3 -0
  208. package/src/runtime/native/reactivity.ts +2 -21
  209. package/src/runtime/native/root.ts +31 -0
  210. package/src/runtime/native/styles/calculate-props.ts +59 -49
  211. package/src/runtime/native/styles/index.ts +12 -12
  212. package/src/runtime/native/styles/units.ts +7 -3
  213. package/src/runtime/native/styles/variables.ts +2 -6
  214. package/src/runtime/utils/specificity.ts +1 -0
@@ -6,7 +6,7 @@ test("nested classes", () => {
6
6
  color: red;
7
7
  }`);
8
8
 
9
- expect(compiled).toStrictEqual({
9
+ expect(compiled.stylesheet()).toStrictEqual({
10
10
  s: [
11
11
  [
12
12
  "my-class",
@@ -38,7 +38,7 @@ test("multiple tiers classes", () => {
38
38
  color: red;
39
39
  }`);
40
40
 
41
- expect(compiled).toStrictEqual({
41
+ expect(compiled.stylesheet()).toStrictEqual({
42
42
  s: [
43
43
  [
44
44
  "one",
@@ -79,7 +79,7 @@ test("tiers with multiple classes", () => {
79
79
  color: red;
80
80
  }`);
81
81
 
82
- expect(compiled).toStrictEqual({
82
+ expect(compiled.stylesheet()).toStrictEqual({
83
83
  s: [
84
84
  [
85
85
  "one",
@@ -94,8 +94,9 @@ test("tiers with multiple classes", () => {
94
94
  "three",
95
95
  [
96
96
  {
97
- c: ["three"],
97
+ c: ["three.two"],
98
98
  s: [0],
99
+ aq: [["a", "className", "*=", "two"]],
99
100
  },
100
101
  ],
101
102
  ],
@@ -106,8 +107,7 @@ test("tiers with multiple classes", () => {
106
107
  cq: [
107
108
  { n: "one" },
108
109
  {
109
- a: [["a", "className", "*=", "two"]],
110
- n: "three",
110
+ n: "three.two",
111
111
  },
112
112
  ],
113
113
  d: [{ color: "#f00" }],
@@ -0,0 +1,531 @@
1
+ import type { Selector, SelectorList } from "lightningcss";
2
+
3
+ import { Specificity } from "../runtime/utils";
4
+ import type {
5
+ AttributeQuery,
6
+ AttrSelectorOperator,
7
+ CompilerOptions,
8
+ ContainerQuery,
9
+ MediaCondition,
10
+ PseudoClassesQuery,
11
+ SpecificityArray,
12
+ } from "./compiler.types";
13
+
14
+ interface ReactNativeClassNameSelector {
15
+ type: "className";
16
+ specificity: SpecificityArray;
17
+ className: string;
18
+ mediaQuery?: MediaCondition[];
19
+ containerQuery?: ContainerQuery[];
20
+ pseudoClassesQuery?: PseudoClassesQuery;
21
+ attributeQuery?: AttributeQuery[];
22
+ }
23
+
24
+ interface ReactNativeGlobalSelector {
25
+ type: "rootVariables" | "universalVariables";
26
+ }
27
+
28
+ type PartialSelector = Partial<ReactNativeClassNameSelector> & {
29
+ type: "className";
30
+ specificity: SpecificityArray;
31
+ };
32
+
33
+ const containerQueryMap = new WeakMap<WeakKey, ContainerQuery[]>();
34
+ const attributeQueryMap = new WeakMap<WeakKey, AttributeQuery[]>();
35
+ const pseudoClassesQueryMap = new WeakMap<WeakKey, PseudoClassesQuery>();
36
+
37
+ type ContainerQueryWithSpecificity = ContainerQuery & {
38
+ specificity: SpecificityArray;
39
+ };
40
+
41
+ export function getClassNameSelectors(
42
+ selectors: SelectorList,
43
+ options: CompilerOptions = {},
44
+ specificity: SpecificityArray = [0],
45
+ root: PartialSelector = {
46
+ type: "className",
47
+ specificity: [],
48
+ },
49
+ ) {
50
+ if (!selectors.length) {
51
+ return [];
52
+ }
53
+
54
+ return selectors.flatMap(
55
+ (selector): (ReactNativeGlobalSelector | PartialSelector)[] => {
56
+ if (isRootVariableSelector(selector)) {
57
+ return [{ type: "rootVariables" }];
58
+ } else {
59
+ return (
60
+ parseComponents(
61
+ selector.reverse(),
62
+ options,
63
+ root,
64
+ root,
65
+ specificity,
66
+ ) ?? []
67
+ );
68
+ }
69
+ },
70
+ );
71
+ }
72
+
73
+ function parseComponents(
74
+ [component, ...rest]: Selector,
75
+ options: CompilerOptions,
76
+ root: PartialSelector,
77
+ ref: PartialSelector | ContainerQuery,
78
+ specificity: SpecificityArray,
79
+ ): PartialSelector[] | null {
80
+ if (!component || Array.isArray(component.type)) {
81
+ // Merge the specificity with the root specificity
82
+ for (let i = 0; i < specificity.length; i++) {
83
+ const value = specificity[i];
84
+ if (value !== undefined) {
85
+ root.specificity[i] = (root.specificity[i] ?? 0) + value;
86
+ }
87
+ }
88
+
89
+ // Return the root
90
+ return [root];
91
+ }
92
+
93
+ switch (component.type) {
94
+ case "id": // #id
95
+ case "namespace": // @namespace
96
+ case "universal": // * - universal selector
97
+ return null;
98
+ case "type": {
99
+ // div, span
100
+ if (
101
+ component.name === options.selectorPrefix ||
102
+ component.name === "html"
103
+ ) {
104
+ return parseComponents(rest, options, root, ref, specificity);
105
+ } else {
106
+ return null;
107
+ }
108
+ }
109
+ case "nesting":
110
+ // &
111
+ // The SelectorList should be flattened, so we can skip these
112
+ return parseComponents(rest, options, root, ref, specificity);
113
+ case "combinator": {
114
+ // We only support the descendant combinator
115
+ if (component.value === "descendant") {
116
+ // Switch to now parsing a container query
117
+ ref = {};
118
+ return parseComponents(rest, options, root, ref, specificity);
119
+ }
120
+
121
+ return [];
122
+ }
123
+ case "pseudo-element": {
124
+ // TODO: Support ::selection, ::placeholder, etc
125
+ return [];
126
+ }
127
+ case "pseudo-class": {
128
+ switch (component.kind) {
129
+ case "hover": {
130
+ getPseudoClassesQuery(ref).h = 1;
131
+ specificity[Specificity.PseudoClass] =
132
+ (specificity[Specificity.PseudoClass] ?? 0) + 1;
133
+ return parseComponents(rest, options, root, ref, specificity);
134
+ }
135
+ case "active": {
136
+ getPseudoClassesQuery(ref).a = 1;
137
+ specificity[Specificity.PseudoClass] =
138
+ (specificity[Specificity.PseudoClass] ?? 0) + 1;
139
+ return parseComponents(rest, options, root, ref, specificity);
140
+ }
141
+ case "focus": {
142
+ getPseudoClassesQuery(ref).f = 1;
143
+ specificity[Specificity.PseudoClass] =
144
+ (specificity[Specificity.PseudoClass] ?? 0) + 1;
145
+ return parseComponents(rest, options, root, ref, specificity);
146
+ }
147
+ case "disabled": {
148
+ getAttributeQuery(ref).push(["a", "disabled"]);
149
+ specificity[Specificity.PseudoClass] =
150
+ (specificity[Specificity.PseudoClass] ?? 0) + 1;
151
+ return parseComponents(rest, options, root, ref, specificity);
152
+ }
153
+ case "empty": {
154
+ getAttributeQuery(ref).push(["a", "children", "!"]);
155
+ specificity[Specificity.PseudoClass] =
156
+ (specificity[Specificity.PseudoClass] ?? 0) + 1;
157
+ return parseComponents(rest, options, root, ref, specificity);
158
+ }
159
+ case "where":
160
+ case "is": {
161
+ // Now get the selectors inside the `is` or `where` pseudo-class
162
+ const isWhereContainerQueries = component.selectors.flatMap(
163
+ (selector) => {
164
+ return parseIsWhereComponents(component.kind, selector) ?? [];
165
+ },
166
+ );
167
+
168
+ // Remember we're looping in reverse order,
169
+ // So `rest` contains the selectors BEFORE this one
170
+ const parents = parseComponents(
171
+ rest,
172
+ options,
173
+ root,
174
+ ref,
175
+ specificity,
176
+ );
177
+
178
+ if (!parents) {
179
+ return null;
180
+ }
181
+
182
+ // Each parent selector should be combined with each pseudo-class selector
183
+ return parents.flatMap((parent) => {
184
+ const originalParent = { ...parent };
185
+
186
+ return isWhereContainerQueries.map(({ specificity, ...query }) => {
187
+ parent = { ...originalParent };
188
+ parent.specificity = [...originalParent.specificity];
189
+ parent.containerQuery = [
190
+ ...(originalParent.containerQuery ?? []),
191
+ ];
192
+
193
+ if (component.kind === "is") {
194
+ for (let i = 0; i < specificity.length; i++) {
195
+ const value = specificity[i];
196
+ if (value !== undefined) {
197
+ parent.specificity[i] =
198
+ (parent.specificity[i] ?? 0) + value;
199
+ }
200
+ }
201
+ }
202
+
203
+ parent.containerQuery.push(query);
204
+
205
+ return parent;
206
+ });
207
+ });
208
+ }
209
+ default: {
210
+ return [];
211
+ }
212
+ }
213
+ }
214
+ case "attribute": {
215
+ // specificity[Specificity.ClassName] =
216
+ // (specificity[Specificity.ClassName] ?? 0) + 1;
217
+ const attributeQuery: AttributeQuery = component.name.startsWith("data-")
218
+ ? // [data-*] are turned into `dataSet` queries
219
+ ["d", toRNProperty(component.name.replace("data-", ""))]
220
+ : // Everything else is turned into `attribute` queries
221
+ ["a", toRNProperty(component.name)];
222
+ if (component.operation) {
223
+ let operator: AttrSelectorOperator | undefined;
224
+ switch (component.operation.operator) {
225
+ case "equal":
226
+ operator = "=";
227
+ break;
228
+ case "includes":
229
+ operator = "~=";
230
+ break;
231
+ case "dash-match":
232
+ operator = "|=";
233
+ break;
234
+ case "prefix":
235
+ operator = "^=";
236
+ break;
237
+ case "substring":
238
+ operator = "*=";
239
+ break;
240
+ case "suffix":
241
+ operator = "$=";
242
+ break;
243
+ default:
244
+ component.operation.operator satisfies never;
245
+ break;
246
+ }
247
+ if (operator) {
248
+ // Append the operator onto the attribute query
249
+ attributeQuery.push(operator, component.operation.value);
250
+ }
251
+ }
252
+ getAttributeQuery(ref).push(attributeQuery);
253
+ specificity[Specificity.ClassName] =
254
+ (specificity[Specificity.ClassName] ?? 0) + 1;
255
+ return parseComponents(rest, options, root, ref, specificity);
256
+ }
257
+ case "class": {
258
+ if (component.name === options.selectorPrefix) {
259
+ // Skip this one
260
+ return parseComponents(rest, options, root, ref, specificity);
261
+ } else if (!isContainerQuery(ref) && !ref.className) {
262
+ ref.className = component.name;
263
+ specificity[Specificity.ClassName] =
264
+ (specificity[Specificity.ClassName] ?? 0) + 1;
265
+ return parseComponents(rest, options, root, ref, specificity);
266
+ } else if (!isContainerQuery(ref)) {
267
+ // Only the first className is used, the rest are attribute queries
268
+ getAttributeQuery(ref).unshift([
269
+ "a",
270
+ "className",
271
+ "*=",
272
+ component.name,
273
+ ]);
274
+ } else {
275
+ let containerQueries = containerQueryMap.get(root);
276
+ if (!containerQueries) {
277
+ containerQueries = [];
278
+ root.containerQuery = containerQueries;
279
+ containerQueryMap.set(root, containerQueries);
280
+ }
281
+ if (!ref.n) {
282
+ containerQueries.unshift(ref);
283
+ }
284
+
285
+ ref.n = ref.n ? `${ref.n}.${component.name}` : component.name;
286
+ }
287
+
288
+ specificity[Specificity.ClassName] =
289
+ (specificity[Specificity.ClassName] ?? 0) + 1;
290
+ return parseComponents(rest, options, root, ref, specificity);
291
+ }
292
+ }
293
+ }
294
+
295
+ function parseIsWhereComponents(
296
+ type: "is" | "where",
297
+ selector: Selector,
298
+ index = 0,
299
+ queries?: ContainerQueryWithSpecificity[],
300
+ ): ContainerQueryWithSpecificity[] | null {
301
+ const component = selector[index];
302
+
303
+ if (!component || Array.isArray(component.type)) {
304
+ return queries ?? [];
305
+ }
306
+
307
+ switch (component.type) {
308
+ // These are not allowed in `is()` or `where()`
309
+ case "id": // #id
310
+ case "namespace": // @namespace
311
+ case "type": // div, span
312
+ case "nesting": // &
313
+ case "pseudo-element": // ::selection, ::placeholder, etc
314
+ return null;
315
+ case "combinator": {
316
+ // We only support the descendant combinator
317
+ if (component.value === "descendant") {
318
+ // Each "block" is a new container query
319
+ const children = parseIsWhereComponents(type, selector, index + 1);
320
+ return children && queries ? [...queries, ...children] : children;
321
+ }
322
+ return null;
323
+ }
324
+ case "universal": {
325
+ // * - universal selector
326
+ if (index !== selector.length - 1) {
327
+ // We only accept it in the last position
328
+ return null;
329
+ }
330
+
331
+ // This was the only component, so we return the ref
332
+ if (selector.length === 1) {
333
+ return queries ?? [{ specificity: [] }];
334
+ }
335
+
336
+ const previous = selector[index - 1];
337
+
338
+ // If the previous component is not a descendant combinator,
339
+ if (
340
+ !previous ||
341
+ previous.type !== "combinator" ||
342
+ previous.value !== "descendant"
343
+ ) {
344
+ return null;
345
+ }
346
+
347
+ return parseIsWhereComponents(type, selector, index + 1, queries);
348
+ }
349
+ case "pseudo-class": {
350
+ // const specificity = ref.specificity;
351
+
352
+ // specificity[Specificity.ClassName] =
353
+ // (specificity[Specificity.ClassName] ?? 0) + 1;
354
+ switch (component.kind) {
355
+ case "hover": {
356
+ queries ??= [{ specificity: [] }];
357
+ queries.forEach((query) => {
358
+ getPseudoClassesQuery(query).h = 1;
359
+ });
360
+ return parseIsWhereComponents(type, selector, index + 1, queries);
361
+ }
362
+ case "active": {
363
+ queries ??= [{ specificity: [] }];
364
+ queries.forEach((query) => {
365
+ getPseudoClassesQuery(query).a = 1;
366
+ });
367
+ return parseIsWhereComponents(type, selector, index + 1, queries);
368
+ }
369
+ case "focus": {
370
+ queries ??= [{ specificity: [] }];
371
+ queries.forEach((query) => {
372
+ getPseudoClassesQuery(query).f = 1;
373
+ });
374
+ return parseIsWhereComponents(type, selector, index + 1, queries);
375
+ }
376
+ case "disabled": {
377
+ queries ??= [{ specificity: [] }];
378
+ queries.forEach((query) => {
379
+ getAttributeQuery(query).push(["a", "disabled"]);
380
+ });
381
+ return parseIsWhereComponents(type, selector, index + 1, queries);
382
+ }
383
+ case "empty": {
384
+ queries ??= [{ specificity: [] }];
385
+ queries.forEach((query) => {
386
+ getAttributeQuery(query).push(["a", "children", "!"]);
387
+ });
388
+ return parseIsWhereComponents(type, selector, index + 1, queries);
389
+ }
390
+ case "where":
391
+ case "is": {
392
+ // :is() and :where() need to be at the start of the selector,
393
+ if (index !== 0) {
394
+ return null;
395
+ }
396
+
397
+ // Now get the selectors inside the `is` or `where` pseudo-class
398
+ queries = component.selectors.flatMap((selector) => {
399
+ return parseIsWhereComponents(type, selector, 0, queries) ?? [];
400
+ });
401
+
402
+ return parseIsWhereComponents(type, selector, index + 1, queries);
403
+ }
404
+ default: {
405
+ return null;
406
+ }
407
+ }
408
+ }
409
+ case "attribute": {
410
+ if (type !== "where") {
411
+ // specificity[Specificity.ClassName] =
412
+ // (specificity[Specificity.ClassName] ?? 0) + 1;
413
+ }
414
+ const attributeQuery: AttributeQuery = component.name.startsWith("data-")
415
+ ? // [data-*] are turned into `dataSet` queries
416
+ ["d", toRNProperty(component.name.replace("data-", ""))]
417
+ : // Everything else is turned into `attribute` queries
418
+ ["a", toRNProperty(component.name)];
419
+ if (component.operation) {
420
+ let operator: AttrSelectorOperator | undefined;
421
+ switch (component.operation.operator) {
422
+ case "equal":
423
+ operator = "=";
424
+ break;
425
+ case "includes":
426
+ operator = "~=";
427
+ break;
428
+ case "dash-match":
429
+ operator = "|=";
430
+ break;
431
+ case "prefix":
432
+ operator = "^=";
433
+ break;
434
+ case "substring":
435
+ operator = "*=";
436
+ break;
437
+ case "suffix":
438
+ operator = "$=";
439
+ break;
440
+ default:
441
+ component.operation.operator satisfies never;
442
+ break;
443
+ }
444
+ if (operator) {
445
+ // Append the operator onto the attribute query
446
+ attributeQuery.push(operator, component.operation.value);
447
+ }
448
+ }
449
+ queries ??= [{ specificity: [] }];
450
+ for (const query of queries) {
451
+ if (type === "is") {
452
+ query.specificity[Specificity.ClassName] =
453
+ (query.specificity[Specificity.ClassName] ?? 0) + 1;
454
+ }
455
+ getAttributeQuery(query).push(attributeQuery);
456
+ }
457
+ return parseIsWhereComponents(type, selector, index + 1, queries);
458
+ }
459
+ case "class": {
460
+ // In `is` and `where` selectors, the ref will always be a container query
461
+ queries ??= [{ specificity: [] }];
462
+ for (const query of queries) {
463
+ if (type === "is") {
464
+ query.specificity[Specificity.ClassName] =
465
+ (query.specificity[Specificity.ClassName] ?? 0) + 1;
466
+ }
467
+
468
+ query.n = query.n ? `${query.n}.${component.name}` : component.name;
469
+ }
470
+
471
+ return parseIsWhereComponents(type, selector, index + 1, queries);
472
+ }
473
+ }
474
+ }
475
+
476
+ function isContainerQuery(
477
+ value: PartialSelector | ContainerQuery,
478
+ ): value is ContainerQuery {
479
+ return !("type" in value);
480
+ }
481
+
482
+ function getPseudoClassesQuery(key: PartialSelector | ContainerQuery) {
483
+ let pseudoClassesQuery = pseudoClassesQueryMap.get(key);
484
+ if (!pseudoClassesQuery) {
485
+ if ("type" in key) {
486
+ pseudoClassesQuery = {};
487
+ key.pseudoClassesQuery = pseudoClassesQuery;
488
+ } else {
489
+ key.p ??= {};
490
+ pseudoClassesQuery = key.p;
491
+ }
492
+ pseudoClassesQueryMap.set(key, pseudoClassesQuery);
493
+ }
494
+
495
+ return pseudoClassesQuery;
496
+ }
497
+
498
+ function getAttributeQuery(
499
+ key: PartialSelector | ContainerQuery,
500
+ ): AttributeQuery[] {
501
+ let attributeQuery = attributeQueryMap.get(key);
502
+ if (!attributeQuery) {
503
+ if ("type" in key) {
504
+ attributeQuery = [];
505
+ key.attributeQuery = attributeQuery;
506
+ } else {
507
+ key.a ??= [];
508
+ attributeQuery = key.a;
509
+ }
510
+ attributeQueryMap.set(key, attributeQuery);
511
+ }
512
+
513
+ return attributeQuery;
514
+ }
515
+
516
+ function isRootVariableSelector([first, second]: Selector) {
517
+ return (
518
+ first && !second && first.type === "pseudo-class" && first.kind === "root"
519
+ );
520
+ }
521
+
522
+ export function toRNProperty<T extends string>(str: T) {
523
+ return str
524
+ .replace(/^-rn-/, "")
525
+ .replace(/-./g, (x) => x[1]?.toUpperCase() ?? "") as CamelCase<T>;
526
+ }
527
+
528
+ type CamelCase<S extends string> =
529
+ S extends `${infer P1}-${infer P2}${infer P3}`
530
+ ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
531
+ : Lowercase<S>;
@@ -11,6 +11,7 @@ import type {
11
11
  PseudoClassesQuery,
12
12
  SpecificityArray,
13
13
  } from "./compiler.types";
14
+ import { StylesheetBuilder } from "./stylesheet";
14
15
 
15
16
  export type NormalizeSelector =
16
17
  | ClassNameSelector
@@ -35,13 +36,13 @@ type ClassNameSelector = {
35
36
  export function getSelectors(
36
37
  selectorList: SelectorList,
37
38
  isDarkMode: boolean,
38
- options: CompilerOptions,
39
+ builder: StylesheetBuilder,
39
40
  selectors: NormalizeSelector[] = [],
40
41
  ) {
41
42
  for (let cssSelector of selectorList) {
42
- // Ignore `:is()`, and just process its selectors
43
- if (isIsPseudoClass(cssSelector)) {
44
- getSelectors(cssSelector[0].selectors, isDarkMode, options, selectors);
43
+ // Ignore `:is()` & `:where()`, and just process its selectors
44
+ if (isIsPseudoClass(cssSelector) || isWherePseudoClass(cssSelector)) {
45
+ getSelectors(cssSelector[0].selectors, isDarkMode, builder, selectors);
45
46
  } else if (
46
47
  // Matches: :root {}
47
48
  isRootVariableSelector(cssSelector)
@@ -110,7 +111,7 @@ export function getSelectors(
110
111
  // ["=", "prefers-color-scheme", "dark"],
111
112
  // ]);
112
113
  } else {
113
- const selector = classNameSelector(cssSelector, options);
114
+ const selector = classNameSelector(cssSelector, builder.getOptions());
114
115
 
115
116
  if (selector === null) {
116
117
  continue;
@@ -178,11 +179,12 @@ function classNameSelector(
178
179
  switch (component.type) {
179
180
  case "universal":
180
181
  case "namespace":
181
- case "nesting":
182
182
  case "id":
183
183
  case "pseudo-element":
184
184
  // We don't support these selectors at all
185
185
  return null;
186
+ case "nesting":
187
+ continue;
186
188
  case "class": {
187
189
  if (!primaryClassName) {
188
190
  primaryClassName = component.name;
@@ -371,6 +373,18 @@ function isIsPseudoClass(
371
373
  );
372
374
  }
373
375
 
376
+ function isWherePseudoClass(
377
+ selector: Selector,
378
+ ): selector is [
379
+ { type: "pseudo-class"; kind: "where"; selectors: Selector[] },
380
+ ] {
381
+ return (
382
+ selector.length === 1 &&
383
+ selector[0]?.type === "pseudo-class" &&
384
+ selector[0].kind === "where"
385
+ );
386
+ }
387
+
374
388
  // function isDarkModeMediaQuery(query?: MediaCondition): boolean {
375
389
  // if (!query) return false;
376
390