@chikx/compiler 0.0.0-stage → 0.1.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 (323) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/dist/emitter/index.d.ts +96 -0
  4. package/dist/emitter/index.d.ts.map +1 -0
  5. package/dist/emitter/index.js +415 -0
  6. package/dist/emitter/index.js.map +1 -0
  7. package/dist/formatter/index.d.ts +53 -0
  8. package/dist/formatter/index.d.ts.map +1 -0
  9. package/dist/formatter/index.js +464 -0
  10. package/dist/formatter/index.js.map +1 -0
  11. package/dist/host/node.d.ts +34 -0
  12. package/dist/host/node.d.ts.map +1 -0
  13. package/dist/host/node.js +80 -0
  14. package/dist/host/node.js.map +1 -0
  15. package/dist/index.d.ts +93 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +792 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/ir/factories.d.ts +35 -0
  20. package/dist/ir/factories.d.ts.map +1 -0
  21. package/dist/ir/factories.js +47 -0
  22. package/dist/ir/factories.js.map +1 -0
  23. package/dist/ir/index.d.ts +13 -0
  24. package/dist/ir/index.d.ts.map +1 -0
  25. package/dist/ir/index.js +2 -0
  26. package/dist/ir/index.js.map +1 -0
  27. package/dist/ir/types.d.ts +139 -0
  28. package/dist/ir/types.d.ts.map +1 -0
  29. package/dist/ir/types.js +2 -0
  30. package/dist/ir/types.js.map +1 -0
  31. package/dist/lexer/at-keywords.d.ts +27 -0
  32. package/dist/lexer/at-keywords.d.ts.map +1 -0
  33. package/dist/lexer/at-keywords.js +35 -0
  34. package/dist/lexer/at-keywords.js.map +1 -0
  35. package/dist/lexer/characters.d.ts +38 -0
  36. package/dist/lexer/characters.d.ts.map +1 -0
  37. package/dist/lexer/characters.js +74 -0
  38. package/dist/lexer/characters.js.map +1 -0
  39. package/dist/lexer/comments.d.ts +22 -0
  40. package/dist/lexer/comments.d.ts.map +1 -0
  41. package/dist/lexer/comments.js +20 -0
  42. package/dist/lexer/comments.js.map +1 -0
  43. package/dist/lexer/diagnostics.d.ts +24 -0
  44. package/dist/lexer/diagnostics.d.ts.map +1 -0
  45. package/dist/lexer/diagnostics.js +29 -0
  46. package/dist/lexer/diagnostics.js.map +1 -0
  47. package/dist/lexer/dollar-refs.d.ts +13 -0
  48. package/dist/lexer/dollar-refs.d.ts.map +1 -0
  49. package/dist/lexer/dollar-refs.js +22 -0
  50. package/dist/lexer/dollar-refs.js.map +1 -0
  51. package/dist/lexer/index.d.ts +32 -0
  52. package/dist/lexer/index.d.ts.map +1 -0
  53. package/dist/lexer/index.js +26 -0
  54. package/dist/lexer/index.js.map +1 -0
  55. package/dist/lexer/names.d.ts +23 -0
  56. package/dist/lexer/names.d.ts.map +1 -0
  57. package/dist/lexer/names.js +48 -0
  58. package/dist/lexer/names.js.map +1 -0
  59. package/dist/lexer/numbers.d.ts +22 -0
  60. package/dist/lexer/numbers.d.ts.map +1 -0
  61. package/dist/lexer/numbers.js +60 -0
  62. package/dist/lexer/numbers.js.map +1 -0
  63. package/dist/lexer/scanner.d.ts +30 -0
  64. package/dist/lexer/scanner.d.ts.map +1 -0
  65. package/dist/lexer/scanner.js +158 -0
  66. package/dist/lexer/scanner.js.map +1 -0
  67. package/dist/lexer/strings.d.ts +25 -0
  68. package/dist/lexer/strings.d.ts.map +1 -0
  69. package/dist/lexer/strings.js +41 -0
  70. package/dist/lexer/strings.js.map +1 -0
  71. package/dist/lexer/urls.d.ts +28 -0
  72. package/dist/lexer/urls.d.ts.map +1 -0
  73. package/dist/lexer/urls.js +54 -0
  74. package/dist/lexer/urls.js.map +1 -0
  75. package/dist/lowering/expand-groups.d.ts +61 -0
  76. package/dist/lowering/expand-groups.d.ts.map +1 -0
  77. package/dist/lowering/expand-groups.js +117 -0
  78. package/dist/lowering/expand-groups.js.map +1 -0
  79. package/dist/lowering/group.d.ts +30 -0
  80. package/dist/lowering/group.d.ts.map +1 -0
  81. package/dist/lowering/group.js +109 -0
  82. package/dist/lowering/group.js.map +1 -0
  83. package/dist/lowering/index.d.ts +26 -0
  84. package/dist/lowering/index.d.ts.map +1 -0
  85. package/dist/lowering/index.js +23 -0
  86. package/dist/lowering/index.js.map +1 -0
  87. package/dist/lowering/lower.d.ts +21 -0
  88. package/dist/lowering/lower.d.ts.map +1 -0
  89. package/dist/lowering/lower.js +296 -0
  90. package/dist/lowering/lower.js.map +1 -0
  91. package/dist/lowering/media.d.ts +63 -0
  92. package/dist/lowering/media.d.ts.map +1 -0
  93. package/dist/lowering/media.js +237 -0
  94. package/dist/lowering/media.js.map +1 -0
  95. package/dist/lowering/merge.d.ts +35 -0
  96. package/dist/lowering/merge.d.ts.map +1 -0
  97. package/dist/lowering/merge.js +146 -0
  98. package/dist/lowering/merge.js.map +1 -0
  99. package/dist/lowering/property-families.d.ts +50 -0
  100. package/dist/lowering/property-families.d.ts.map +1 -0
  101. package/dist/lowering/property-families.js +175 -0
  102. package/dist/lowering/property-families.js.map +1 -0
  103. package/dist/lowering/spans.d.ts +36 -0
  104. package/dist/lowering/spans.d.ts.map +1 -0
  105. package/dist/lowering/spans.js +100 -0
  106. package/dist/lowering/spans.js.map +1 -0
  107. package/dist/naming/index.d.ts +37 -0
  108. package/dist/naming/index.d.ts.map +1 -0
  109. package/dist/naming/index.js +34 -0
  110. package/dist/naming/index.js.map +1 -0
  111. package/dist/naming/mapgen.d.ts +70 -0
  112. package/dist/naming/mapgen.d.ts.map +1 -0
  113. package/dist/naming/mapgen.js +153 -0
  114. package/dist/naming/mapgen.js.map +1 -0
  115. package/dist/naming/merge.d.ts +62 -0
  116. package/dist/naming/merge.d.ts.map +1 -0
  117. package/dist/naming/merge.js +77 -0
  118. package/dist/naming/merge.js.map +1 -0
  119. package/dist/naming/rewrite.d.ts +14 -0
  120. package/dist/naming/rewrite.d.ts.map +1 -0
  121. package/dist/naming/rewrite.js +191 -0
  122. package/dist/naming/rewrite.js.map +1 -0
  123. package/dist/naming/scan.d.ts +80 -0
  124. package/dist/naming/scan.d.ts.map +1 -0
  125. package/dist/naming/scan.js +193 -0
  126. package/dist/naming/scan.js.map +1 -0
  127. package/dist/naming/table.d.ts +68 -0
  128. package/dist/naming/table.d.ts.map +1 -0
  129. package/dist/naming/table.js +132 -0
  130. package/dist/naming/table.js.map +1 -0
  131. package/dist/naming/types.d.ts +94 -0
  132. package/dist/naming/types.d.ts.map +1 -0
  133. package/dist/naming/types.js +2 -0
  134. package/dist/naming/types.js.map +1 -0
  135. package/dist/output/import-path.d.ts +24 -0
  136. package/dist/output/import-path.d.ts.map +1 -0
  137. package/dist/output/import-path.js +30 -0
  138. package/dist/output/import-path.js.map +1 -0
  139. package/dist/output/importPath.d.ts +27 -0
  140. package/dist/output/importPath.d.ts.map +1 -0
  141. package/dist/output/importPath.js +84 -0
  142. package/dist/output/importPath.js.map +1 -0
  143. package/dist/output/index.d.ts +40 -0
  144. package/dist/output/index.d.ts.map +1 -0
  145. package/dist/output/index.js +138 -0
  146. package/dist/output/index.js.map +1 -0
  147. package/dist/output/manifest.d.ts +17 -0
  148. package/dist/output/manifest.d.ts.map +1 -0
  149. package/dist/output/manifest.js +22 -0
  150. package/dist/output/manifest.js.map +1 -0
  151. package/dist/output/paths.d.ts +54 -0
  152. package/dist/output/paths.d.ts.map +1 -0
  153. package/dist/output/paths.js +183 -0
  154. package/dist/output/paths.js.map +1 -0
  155. package/dist/output/resolve.d.ts +100 -0
  156. package/dist/output/resolve.d.ts.map +1 -0
  157. package/dist/output/resolve.js +313 -0
  158. package/dist/output/resolve.js.map +1 -0
  159. package/dist/output/validate.d.ts +82 -0
  160. package/dist/output/validate.d.ts.map +1 -0
  161. package/dist/output/validate.js +128 -0
  162. package/dist/output/validate.js.map +1 -0
  163. package/dist/parser/cursor.d.ts +55 -0
  164. package/dist/parser/cursor.d.ts.map +1 -0
  165. package/dist/parser/cursor.js +120 -0
  166. package/dist/parser/cursor.js.map +1 -0
  167. package/dist/parser/declaration.d.ts +21 -0
  168. package/dist/parser/declaration.d.ts.map +1 -0
  169. package/dist/parser/declaration.js +201 -0
  170. package/dist/parser/declaration.js.map +1 -0
  171. package/dist/parser/diagnostics.d.ts +52 -0
  172. package/dist/parser/diagnostics.d.ts.map +1 -0
  173. package/dist/parser/diagnostics.js +55 -0
  174. package/dist/parser/diagnostics.js.map +1 -0
  175. package/dist/parser/group.d.ts +26 -0
  176. package/dist/parser/group.d.ts.map +1 -0
  177. package/dist/parser/group.js +219 -0
  178. package/dist/parser/group.js.map +1 -0
  179. package/dist/parser/index.d.ts +30 -0
  180. package/dist/parser/index.d.ts.map +1 -0
  181. package/dist/parser/index.js +48 -0
  182. package/dist/parser/index.js.map +1 -0
  183. package/dist/parser/modifier.d.ts +25 -0
  184. package/dist/parser/modifier.d.ts.map +1 -0
  185. package/dist/parser/modifier.js +41 -0
  186. package/dist/parser/modifier.js.map +1 -0
  187. package/dist/parser/recovery.d.ts +23 -0
  188. package/dist/parser/recovery.d.ts.map +1 -0
  189. package/dist/parser/recovery.js +80 -0
  190. package/dist/parser/recovery.js.map +1 -0
  191. package/dist/parser/rule.d.ts +39 -0
  192. package/dist/parser/rule.d.ts.map +1 -0
  193. package/dist/parser/rule.js +337 -0
  194. package/dist/parser/rule.js.map +1 -0
  195. package/dist/parser/statement.d.ts +21 -0
  196. package/dist/parser/statement.d.ts.map +1 -0
  197. package/dist/parser/statement.js +48 -0
  198. package/dist/parser/statement.js.map +1 -0
  199. package/dist/parser/statements.d.ts +33 -0
  200. package/dist/parser/statements.d.ts.map +1 -0
  201. package/dist/parser/statements.js +605 -0
  202. package/dist/parser/statements.js.map +1 -0
  203. package/dist/parser/value.d.ts +57 -0
  204. package/dist/parser/value.d.ts.map +1 -0
  205. package/dist/parser/value.js +226 -0
  206. package/dist/parser/value.js.map +1 -0
  207. package/dist/resolver/graph.d.ts +20 -0
  208. package/dist/resolver/graph.d.ts.map +1 -0
  209. package/dist/resolver/graph.js +382 -0
  210. package/dist/resolver/graph.js.map +1 -0
  211. package/dist/resolver/groups.d.ts +70 -0
  212. package/dist/resolver/groups.d.ts.map +1 -0
  213. package/dist/resolver/groups.js +143 -0
  214. package/dist/resolver/groups.js.map +1 -0
  215. package/dist/resolver/index.d.ts +46 -0
  216. package/dist/resolver/index.d.ts.map +1 -0
  217. package/dist/resolver/index.js +46 -0
  218. package/dist/resolver/index.js.map +1 -0
  219. package/dist/resolver/keyframes.d.ts +56 -0
  220. package/dist/resolver/keyframes.d.ts.map +1 -0
  221. package/dist/resolver/keyframes.js +102 -0
  222. package/dist/resolver/keyframes.js.map +1 -0
  223. package/dist/resolver/paths.d.ts +37 -0
  224. package/dist/resolver/paths.d.ts.map +1 -0
  225. package/dist/resolver/paths.js +135 -0
  226. package/dist/resolver/paths.js.map +1 -0
  227. package/dist/resolver/rules.d.ts +34 -0
  228. package/dist/resolver/rules.d.ts.map +1 -0
  229. package/dist/resolver/rules.js +52 -0
  230. package/dist/resolver/rules.js.map +1 -0
  231. package/dist/resolver/scopes.d.ts +44 -0
  232. package/dist/resolver/scopes.d.ts.map +1 -0
  233. package/dist/resolver/scopes.js +213 -0
  234. package/dist/resolver/scopes.js.map +1 -0
  235. package/dist/resolver/types.d.ts +238 -0
  236. package/dist/resolver/types.d.ts.map +1 -0
  237. package/dist/resolver/types.js +11 -0
  238. package/dist/resolver/types.js.map +1 -0
  239. package/dist/selectors/flatten.d.ts +95 -0
  240. package/dist/selectors/flatten.d.ts.map +1 -0
  241. package/dist/selectors/flatten.js +384 -0
  242. package/dist/selectors/flatten.js.map +1 -0
  243. package/dist/selectors/index.d.ts +15 -0
  244. package/dist/selectors/index.d.ts.map +1 -0
  245. package/dist/selectors/index.js +14 -0
  246. package/dist/selectors/index.js.map +1 -0
  247. package/dist/selectors/scan.d.ts +54 -0
  248. package/dist/selectors/scan.d.ts.map +1 -0
  249. package/dist/selectors/scan.js +191 -0
  250. package/dist/selectors/scan.js.map +1 -0
  251. package/dist/selectors/specificity.d.ts +28 -0
  252. package/dist/selectors/specificity.d.ts.map +1 -0
  253. package/dist/selectors/specificity.js +297 -0
  254. package/dist/selectors/specificity.js.map +1 -0
  255. package/dist/setup-list.d.ts +41 -0
  256. package/dist/setup-list.d.ts.map +1 -0
  257. package/dist/setup-list.js +122 -0
  258. package/dist/setup-list.js.map +1 -0
  259. package/dist/sourcemaps/index.d.ts +14 -0
  260. package/dist/sourcemaps/index.d.ts.map +1 -0
  261. package/dist/sourcemaps/index.js +13 -0
  262. package/dist/sourcemaps/index.js.map +1 -0
  263. package/dist/sourcemaps/mappings.d.ts +77 -0
  264. package/dist/sourcemaps/mappings.d.ts.map +1 -0
  265. package/dist/sourcemaps/mappings.js +124 -0
  266. package/dist/sourcemaps/mappings.js.map +1 -0
  267. package/dist/sourcemaps/vlq.d.ts +12 -0
  268. package/dist/sourcemaps/vlq.d.ts.map +1 -0
  269. package/dist/sourcemaps/vlq.js +29 -0
  270. package/dist/sourcemaps/vlq.js.map +1 -0
  271. package/dist/types/ast.d.ts +291 -0
  272. package/dist/types/ast.d.ts.map +1 -0
  273. package/dist/types/ast.js +2 -0
  274. package/dist/types/ast.js.map +1 -0
  275. package/dist/types/diagnostics.d.ts +55 -0
  276. package/dist/types/diagnostics.d.ts.map +1 -0
  277. package/dist/types/diagnostics.js +61 -0
  278. package/dist/types/diagnostics.js.map +1 -0
  279. package/dist/types/options.d.ts +274 -0
  280. package/dist/types/options.d.ts.map +1 -0
  281. package/dist/types/options.js +11 -0
  282. package/dist/types/options.js.map +1 -0
  283. package/dist/types/result.d.ts +112 -0
  284. package/dist/types/result.d.ts.map +1 -0
  285. package/dist/types/result.js +2 -0
  286. package/dist/types/result.js.map +1 -0
  287. package/dist/types/span.d.ts +19 -0
  288. package/dist/types/span.d.ts.map +1 -0
  289. package/dist/types/span.js +2 -0
  290. package/dist/types/span.js.map +1 -0
  291. package/dist/types/token.d.ts +68 -0
  292. package/dist/types/token.d.ts.map +1 -0
  293. package/dist/types/token.js +2 -0
  294. package/dist/types/token.js.map +1 -0
  295. package/dist/variables/ast.d.ts +56 -0
  296. package/dist/variables/ast.d.ts.map +1 -0
  297. package/dist/variables/ast.js +167 -0
  298. package/dist/variables/ast.js.map +1 -0
  299. package/dist/variables/expand.d.ts +109 -0
  300. package/dist/variables/expand.d.ts.map +1 -0
  301. package/dist/variables/expand.js +213 -0
  302. package/dist/variables/expand.js.map +1 -0
  303. package/dist/variables/index.d.ts +36 -0
  304. package/dist/variables/index.d.ts.map +1 -0
  305. package/dist/variables/index.js +33 -0
  306. package/dist/variables/index.js.map +1 -0
  307. package/dist/variables/naming.d.ts +39 -0
  308. package/dist/variables/naming.d.ts.map +1 -0
  309. package/dist/variables/naming.js +14 -0
  310. package/dist/variables/naming.js.map +1 -0
  311. package/dist/variables/runtime.d.ts +81 -0
  312. package/dist/variables/runtime.d.ts.map +1 -0
  313. package/dist/variables/runtime.js +228 -0
  314. package/dist/variables/runtime.js.map +1 -0
  315. package/dist/variables/substitute.d.ts +65 -0
  316. package/dist/variables/substitute.d.ts.map +1 -0
  317. package/dist/variables/substitute.js +73 -0
  318. package/dist/variables/substitute.js.map +1 -0
  319. package/dist/variables/walk.d.ts +37 -0
  320. package/dist/variables/walk.d.ts.map +1 -0
  321. package/dist/variables/walk.js +113 -0
  322. package/dist/variables/walk.js.map +1 -0
  323. package/package.json +35 -4
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Token-scope construction for the module resolver.
3
+ *
4
+ * A scope answers the question A08 asks: for a visible `$name` or
5
+ * `$namespace.member`, which module declares it, what AST node carries the
6
+ * value, and how did it become visible? Local definitions are collected first
7
+ * so imports always resolve against the target's *own* definitions and never
8
+ * re-export transitively (SPECIFICATION.md §6.1).
9
+ */
10
+ import { error } from "../types/diagnostics.js";
11
+ import { GROUP_DIRECTIVE } from "./groups.js";
12
+ import { KEYFRAMES_NAMESPACE } from "./keyframes.js";
13
+ /**
14
+ * Collect a module's local compile-time and runtime symbols in authored order.
15
+ *
16
+ * Reports CHIKX2001 at the offending declaration for a duplicate local name
17
+ * within or across blocks, and for a name defined as both a compile-time and a
18
+ * runtime variable (§6.1, §6.2). The first definition wins in the scope so the
19
+ * result stays deterministic even though the input is already erroneous.
20
+ */
21
+ export function collectLocalSymbols(file, ast, report) {
22
+ const compile = new Map();
23
+ const runtime = new Map();
24
+ const add = (target, tokenType, name, declaration) => {
25
+ if (target.has(name)) {
26
+ report(error("CHIKX2001", `Duplicate local ${labelFor(tokenType)} variable "$${name}" in "${file}".`, declaration.span));
27
+ return;
28
+ }
29
+ target.set(name, {
30
+ name,
31
+ tokenType,
32
+ module: file,
33
+ span: declaration.span,
34
+ declaration,
35
+ origin: { kind: "local" },
36
+ unqualified: true,
37
+ });
38
+ };
39
+ for (const item of ast.items) {
40
+ if (item.kind === "variables") {
41
+ for (const token of item.tokens)
42
+ add(compile, "compile", token.name, token);
43
+ }
44
+ else if (item.kind === "runtime") {
45
+ for (const declaration of item.declarations) {
46
+ add(runtime, "runtime", declaration.property, declaration);
47
+ }
48
+ }
49
+ }
50
+ for (const [name, runtimeToken] of runtime) {
51
+ const compileToken = compile.get(name);
52
+ if (compileToken === undefined)
53
+ continue;
54
+ const later = compileToken.span.start <= runtimeToken.span.start ? runtimeToken.span : compileToken.span;
55
+ report(error("CHIKX2001", `"$${name}" cannot be both a compile-time and a runtime variable in "${file}".`, later));
56
+ }
57
+ return { compile, runtime };
58
+ }
59
+ /**
60
+ * Build both token scopes for one module from its resolved imports.
61
+ *
62
+ * Unqualified imports merge into the `$name` namespace shared by both symbol
63
+ * spaces, with a local definition of either kind taking precedence. Namespaced
64
+ * imports are exposed only through `namespaces`, so `$layout` stays
65
+ * unresolvable while `$layout.spacing` works. Ambiguous unqualified names are
66
+ * CHIKX2001 at the second conflicting `@use`; the first provider is kept in the
67
+ * scope for deterministic downstream behaviour when the caller chooses to
68
+ * continue after errors.
69
+ */
70
+ export function buildScopes(file, locals, imports, localsFor, report) {
71
+ const bindings = collectNamespaceBindings(file, imports, report);
72
+ const unqualified = resolveUnqualified(file, locals, imports, localsFor, report);
73
+ return {
74
+ compileScope: buildScope(file, "compile", locals, localsFor, bindings, unqualified),
75
+ runtimeScope: buildScope(file, "runtime", locals, localsFor, bindings, unqualified),
76
+ };
77
+ }
78
+ /**
79
+ * Merge unqualified imports into one shared name table.
80
+ *
81
+ * Compile-time and runtime imports share the `$name` namespace, matching the
82
+ * `$name`/`$name.member` syntax: a single local definition of either kind
83
+ * shadows every unqualified import of that name, and two distinct providers
84
+ * (same or different symbol spaces) are ambiguous. The first provider wins so
85
+ * repeated runs and post-error recovery stay deterministic.
86
+ */
87
+ function resolveUnqualified(file, locals, imports, localsFor, report) {
88
+ const providers = new Map();
89
+ for (const imported of imports) {
90
+ if (imported.target === undefined || imported.item.alias !== undefined)
91
+ continue;
92
+ const exported = localsFor(imported.target);
93
+ if (exported === undefined)
94
+ continue;
95
+ for (const tokenType of ["compile", "runtime"]) {
96
+ for (const [name, definition] of exported[tokenType]) {
97
+ if (locals.compile.has(name) || locals.runtime.has(name))
98
+ continue;
99
+ const existing = providers.get(name);
100
+ if (existing === undefined) {
101
+ providers.set(name, [
102
+ { target: imported.target, tokenType, definition, import: imported },
103
+ ]);
104
+ continue;
105
+ }
106
+ if (existing.some((provider) => provider.target === imported.target && provider.tokenType === tokenType)) {
107
+ continue;
108
+ }
109
+ existing.push({ target: imported.target, tokenType, definition, import: imported });
110
+ }
111
+ }
112
+ }
113
+ const winners = new Map();
114
+ for (const [name, list] of providers) {
115
+ const first = list[0];
116
+ if (first === undefined)
117
+ continue;
118
+ if (list.length > 1) {
119
+ const conflicting = list[1];
120
+ const span = conflicting === undefined ? first.import.item.span : conflicting.import.item.span;
121
+ const sources = list
122
+ .map((provider) => `"${provider.target}" (${labelFor(provider.tokenType)})`)
123
+ .join(", ");
124
+ report(error("CHIKX2001", `Ambiguous unqualified import in "${file}": "$${name}" is exported by ${sources}. Import it with a namespace (@use "..." as <alias>) or define "$${name}" locally to choose one.`, span));
125
+ }
126
+ winners.set(name, importedToken(first.definition, importOrigin(first.import), true));
127
+ }
128
+ return winners;
129
+ }
130
+ function buildScope(file, kind, locals, localsFor, bindings, unqualified) {
131
+ const tokens = new Map(locals[kind]);
132
+ const namespaces = new Map();
133
+ for (const binding of bindings.values()) {
134
+ const exported = localsFor(binding.target);
135
+ if (exported === undefined)
136
+ continue;
137
+ const members = new Map();
138
+ const origin = {
139
+ kind: "import",
140
+ module: binding.target,
141
+ specifier: binding.specifier,
142
+ span: binding.span,
143
+ namespace: binding.namespace,
144
+ };
145
+ for (const [name, definition] of exported[kind]) {
146
+ members.set(name, importedToken(definition, origin, false));
147
+ }
148
+ namespaces.set(binding.namespace, {
149
+ namespace: binding.namespace,
150
+ module: binding.target,
151
+ span: binding.span,
152
+ specifier: binding.specifier,
153
+ members,
154
+ });
155
+ }
156
+ for (const [name, definition] of unqualified) {
157
+ if (definition.tokenType === kind)
158
+ tokens.set(name, definition);
159
+ }
160
+ return { kind, module: file, tokens, namespaces };
161
+ }
162
+ function collectNamespaceBindings(file, imports, report) {
163
+ const bindings = new Map();
164
+ for (const imported of imports) {
165
+ const alias = imported.item.alias;
166
+ if (imported.target === undefined || alias === undefined || alias === "")
167
+ continue;
168
+ // The built-in `keyframes` namespace is reserved (ADR-0015): an alias would
169
+ // shadow names that ADR-0015 defines, so it is a CHIKX2001 instead of a
170
+ // second, competing namespace.
171
+ if (alias === KEYFRAMES_NAMESPACE) {
172
+ report(error("CHIKX2001", `"$${alias}" is a built-in namespace (ADR-0015) and cannot be used as an @use alias in "${file}".`, imported.item.span));
173
+ continue;
174
+ }
175
+ // The built-in `@group.<name>` construct owns the `group` directive name
176
+ // (ADR-0017 item 5, §3.6), so an alias of that name is rejected the same
177
+ // way: CHIKX2001 at the `@use`, no namespace, and the edge itself still
178
+ // resolves.
179
+ if (alias === GROUP_DIRECTIVE) {
180
+ report(error("CHIKX2001", `"${alias}" is a reserved directive name (ADR-0017) and cannot be used as an @use alias in "${file}".`, imported.item.span));
181
+ continue;
182
+ }
183
+ const existing = bindings.get(alias);
184
+ if (existing === undefined) {
185
+ bindings.set(alias, {
186
+ namespace: alias,
187
+ target: imported.target,
188
+ span: imported.item.span,
189
+ specifier: imported.specifier,
190
+ });
191
+ continue;
192
+ }
193
+ if (existing.target !== imported.target) {
194
+ report(error("CHIKX2001", `Duplicate namespace "${alias}" in "${file}" refers to both "${existing.target}" and "${imported.target}".`, imported.item.span));
195
+ }
196
+ }
197
+ return bindings;
198
+ }
199
+ function importedToken(definition, origin, unqualified) {
200
+ return { ...definition, origin, unqualified };
201
+ }
202
+ function importOrigin(imported) {
203
+ return {
204
+ kind: "import",
205
+ module: imported.target ?? imported.specifier,
206
+ specifier: imported.specifier,
207
+ span: imported.item.span,
208
+ };
209
+ }
210
+ function labelFor(tokenType) {
211
+ return tokenType === "compile" ? "compile-time" : "runtime";
212
+ }
213
+ //# sourceMappingURL=scopes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../src/resolver/scopes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAkCrD;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,GAAe,EACf,MAAwC;IAExC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAE/C,MAAM,GAAG,GAAG,CACV,MAAgC,EAChC,SAA0B,EAC1B,IAAY,EACZ,WAA2C,EACrC,EAAE;QACR,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,MAAM,CACJ,KAAK,CACH,WAAW,EACX,mBAAmB,QAAQ,CAAC,SAAS,CAAC,eAAe,IAAI,SAAS,IAAI,IAAI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S;QAC7C,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI;KACzB,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,SAA0B;IAC1C,OAAO,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Public shapes produced by the module resolver.
3
+ *
4
+ * These types are the A08 handoff: a scope tells substitution where every
5
+ * visible symbol is defined, how it was brought into the file, and whether it
6
+ * may be referenced without a namespace. All module identifiers are canonical
7
+ * paths as returned by {@link ModuleHost.canonicalize}, normalized to forward
8
+ * slashes.
9
+ */
10
+ import type { Declaration, GroupDefinition, Stylesheet, TokenDeclaration, UseImport } from "../types/ast.js";
11
+ import type { Diagnostic } from "../types/diagnostics.js";
12
+ import type { Span } from "../types/span.js";
13
+ /**
14
+ * Resolver-internal record of one resolved `@use` statement.
15
+ *
16
+ * Not part of the facade: `target` is present only when the import passed
17
+ * containment and existence checks, so later passes can distinguish a broken
18
+ * edge (already diagnosed) from a real dependency.
19
+ */
20
+ export interface ResolvedImport {
21
+ /** The authored AST node. */
22
+ readonly item: UseImport;
23
+ /** Specifier after CSS string-escape decoding. */
24
+ readonly specifier: string;
25
+ /** Canonical target path when resolution succeeded. */
26
+ readonly target?: string;
27
+ /**
28
+ * `true` when the import carried the `styles` clause, so the edge also merges
29
+ * the target's rules into the importing build (ADR-0014). Token-only imports
30
+ * are `false`.
31
+ */
32
+ readonly styles: boolean;
33
+ }
34
+ /** The two symbol spaces a Chikx module can export. */
35
+ export type ScopedTokenType = "compile" | "runtime";
36
+ /**
37
+ * One `@keyframes` name referenceable as `$keyframes.<name>` in a module.
38
+ *
39
+ * Names are not symbols with a value: substitution splices {@link name} as
40
+ * literal CSS text, and the same authored text resolves identically in every
41
+ * module that can see it (ADR-0015).
42
+ */
43
+ export interface KeyframeName {
44
+ /** Authored keyframe name, a plain identifier (no quotes or escapes). */
45
+ readonly name: string;
46
+ /** Canonical path of the module whose `@keyframes` block declared it. */
47
+ readonly module: string;
48
+ /** Span of the declaring `@keyframes` at-rule in that module. */
49
+ readonly span: Span;
50
+ }
51
+ /**
52
+ * One `@group.<name>` definition visible to a module (ADR-0017).
53
+ *
54
+ * The definition stays in its declaring module: {@link module} and
55
+ * {@link definition} always point at the module that authored it, so expansion
56
+ * can attribute `$refs` to that module (SPECIFICATION.md §6.1).
57
+ */
58
+ export interface VisibleGroup {
59
+ /** Group name without the `@group.` prefix, matched exactly and case-sensitively. */
60
+ readonly name: string;
61
+ /** Canonical path of the module whose `@group` block declares it. */
62
+ readonly module: string;
63
+ /** Span of the declaring `@group` at-rule in that module. */
64
+ readonly span: Span;
65
+ /** The declaring definition node, carrying the defaults and their authored spans. */
66
+ readonly definition: GroupDefinition;
67
+ }
68
+ /**
69
+ * How one group name resolves from a module's point of view (ADR-0017 item 5).
70
+ *
71
+ * Both variants stay inert data for the expansion pass: it splices
72
+ * {@link VisibleGroup.definition} for `resolved` and reports CHIKX2001 at the
73
+ * use site for `ambiguous` (plan G3). Ambiguity is not a resolver diagnostic
74
+ * because only a use site makes it actionable.
75
+ */
76
+ export type GroupResolution = {
77
+ /** Exactly one addressable definition: local first, otherwise a single import. */
78
+ readonly kind: "resolved";
79
+ readonly group: VisibleGroup;
80
+ } | {
81
+ /** Two or more imported definitions and no local one. */
82
+ readonly kind: "ambiguous";
83
+ /** The contested group name. */
84
+ readonly name: string;
85
+ /** Distinct visible definitions in traversal order; the message names their modules. */
86
+ readonly candidates: readonly VisibleGroup[];
87
+ };
88
+ /** Origin of a symbol declared in the scope's own file. */
89
+ export interface LocalSymbolOrigin {
90
+ readonly kind: "local";
91
+ }
92
+ /** Origin of a symbol reached through a `@use` statement. */
93
+ export interface ImportSymbolOrigin {
94
+ readonly kind: "import";
95
+ /** Canonical path of the module that declares the symbol. */
96
+ readonly module: string;
97
+ /** Import specifier after CSS string-escape decoding, as authored otherwise. */
98
+ readonly specifier: string;
99
+ /** Span of the `@use` statement in the importing file. */
100
+ readonly span: Span;
101
+ /** Namespace alias when the import was written `as alias`; absent otherwise. */
102
+ readonly namespace?: string;
103
+ }
104
+ /** How a visible symbol entered a token scope. */
105
+ export type SymbolOrigin = LocalSymbolOrigin | ImportSymbolOrigin;
106
+ /**
107
+ * One visible token definition from the substitution point of view.
108
+ *
109
+ * The definition itself stays in its declaring module: {@link module} and
110
+ * {@link declaration} always point at the module that authored the value, so a
111
+ * local override never mutates an imported module (SPECIFICATION.md §6.1).
112
+ */
113
+ export interface ScopedToken {
114
+ /** Symbol name without the `$` sigil, exactly as authored. */
115
+ readonly name: string;
116
+ /** Which symbol space the definition belongs to. */
117
+ readonly tokenType: ScopedTokenType;
118
+ /** Canonical path of the module that declares this symbol. */
119
+ readonly module: string;
120
+ /** Span of the declaring `TokenDeclaration` or `Declaration`. */
121
+ readonly span: Span;
122
+ /**
123
+ * The declaring AST node, carrying the raw value, optional parsed value
124
+ * tokens and runtime variants. Immutable by contract.
125
+ */
126
+ readonly declaration: TokenDeclaration | Declaration;
127
+ /** Whether the symbol is local or imported, and via which `@use`. */
128
+ readonly origin: SymbolOrigin;
129
+ /**
130
+ * Whether a bare `$name` reference may resolve to this symbol. Always `true`
131
+ * for locals and unqualified imports; `false` for namespaced members, which
132
+ * are reachable only as `$namespace.name`.
133
+ */
134
+ readonly unqualified: boolean;
135
+ }
136
+ /** The members one `@use "... as namespace"` statement exposes. */
137
+ export interface ScopedNamespace {
138
+ /** Authored alias without the `$` sigil. */
139
+ readonly namespace: string;
140
+ /** Canonical path of the imported module. */
141
+ readonly module: string;
142
+ /** Span of the `@use` statement in the importing file. */
143
+ readonly span: Span;
144
+ /** Decoded import specifier as authored otherwise. */
145
+ readonly specifier: string;
146
+ /**
147
+ * Symbols exported by the target module's own `@variables`/`@runtime`
148
+ * blocks. There is no transitive re-export: member definitions are always
149
+ * local to {@link module}.
150
+ */
151
+ readonly members: ReadonlyMap<string, ScopedToken>;
152
+ }
153
+ /**
154
+ * Visible symbols of one module for one symbol space.
155
+ *
156
+ * `tokens` holds the names a bare `$name` reference may use after local
157
+ * definitions shadow unqualified imports; `namespaces` holds every namespaced
158
+ * import, with `members` filtered to this scope's {@link kind}.
159
+ */
160
+ export interface TokenScope {
161
+ /** The symbol space this scope exposes. */
162
+ readonly kind: ScopedTokenType;
163
+ /** Canonical path of the module whose source defines this scope. */
164
+ readonly module: string;
165
+ /** Unqualified, directly referenceable symbols. */
166
+ readonly tokens: ReadonlyMap<string, ScopedToken>;
167
+ /** Namespaced imports, addressable as `$namespace.member`. */
168
+ readonly namespaces: ReadonlyMap<string, ScopedNamespace>;
169
+ }
170
+ /** One parsed and validated module of the graph. */
171
+ export interface ModuleRecord {
172
+ /** Canonical path used as the module cache key and graph key. */
173
+ readonly file: string;
174
+ /** Immutable AST produced by `parseTokens`. */
175
+ readonly ast: Stylesheet;
176
+ /**
177
+ * Canonical paths this module imports, deduplicated in first-authored
178
+ * `@use` order. Includes token-only and rule-merge (`styles`) imports.
179
+ * Failed imports are reported as diagnostics and omitted.
180
+ */
181
+ readonly dependencies: readonly string[];
182
+ /**
183
+ * Canonical paths imported with the `styles` clause, deduplicated in
184
+ * first-authored `@use` order (ADR-0014). These modules contribute their rules
185
+ * to a consuming build; `dependencies` is the superset used for scopes and
186
+ * cycle detection.
187
+ */
188
+ readonly styleDependencies: readonly string[];
189
+ /** Canonical paths of modules importing this one, sorted for determinism. */
190
+ readonly importedBy: readonly string[];
191
+ /** Compile-time (`@variables`) scope, including namespace member maps. */
192
+ readonly compileScope: TokenScope;
193
+ /** Runtime (`@runtime`) scope, including namespace member maps. */
194
+ readonly runtimeScope: TokenScope;
195
+ /**
196
+ * `@keyframes` names visible to this module as `$keyframes.<name>` (ADR-0015):
197
+ * its own top-level blocks plus those of every module reached through a
198
+ * `styles` `@use` edge (ADR-0014), because that is exactly the CSS this module's
199
+ * build emits. Token-only imports contribute nothing.
200
+ */
201
+ readonly keyframes: ReadonlyMap<string, KeyframeName>;
202
+ /**
203
+ * `@group.<name>` definitions visible to this module (ADR-0017): its own
204
+ * top-level definitions plus those of every module reached through a `styles`
205
+ * `@use` edge (ADR-0014), transitively in authored order. Token-only imports
206
+ * contribute no groups.
207
+ *
208
+ * A local definition shadows imported definitions of the same name without a
209
+ * diagnostic; two imported definitions with no local one are
210
+ * {@link GroupResolution} `ambiguous` and stay inert until a use site reports
211
+ * CHIKX2001 (plan G3). The map is resolver-internal data: it carries no
212
+ * expansion state and nothing is emitted for a definition.
213
+ */
214
+ readonly groups: ReadonlyMap<string, GroupResolution>;
215
+ /**
216
+ * Whether the module contains top-level stylesheet rules or native at-rules.
217
+ * Token-only modules report `false` so P4/P5 can skip artifact emission
218
+ * (SPECIFICATION.md §6.1).
219
+ */
220
+ readonly hasRules: boolean;
221
+ }
222
+ /** Result of {@link buildModuleGraph}. */
223
+ export interface ModuleGraph {
224
+ /** Every successfully loaded module keyed by canonical path. */
225
+ readonly modules: ReadonlyMap<string, ModuleRecord>;
226
+ /**
227
+ * Deterministic topological order: dependencies before importers, ties by
228
+ * canonical path. Modules participating in an import cycle are omitted after
229
+ * their CHIKX2001 diagnostic; every other loaded module appears exactly once.
230
+ */
231
+ readonly order: readonly string[];
232
+ /**
233
+ * Parse diagnostics followed by resolver diagnostics, stably sorted by file,
234
+ * offset and code so identical inputs always yield identical output.
235
+ */
236
+ readonly diagnostics: readonly Diagnostic[];
237
+ }
238
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resolver/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO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C1C,MAAM,WAAW,WAAW;IAC1B,gEAAgE;IAChE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACpD;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Public shapes produced by the module resolver.
3
+ *
4
+ * These types are the A08 handoff: a scope tells substitution where every
5
+ * visible symbol is defined, how it was brought into the file, and whether it
6
+ * may be referenced without a namespace. All module identifiers are canonical
7
+ * paths as returned by {@link ModuleHost.canonicalize}, normalized to forward
8
+ * slashes.
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/resolver/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,95 @@
1
+ import type { StylesheetIr } from "../ir/types.js";
2
+ import type { Diagnostic } from "../types/diagnostics.js";
3
+ /**
4
+ * Nested-selector flattening (ADR-0002, ADR-0012, SPECIFICATION.md §7.1).
5
+ *
6
+ * `flattenSelector` is pure: it takes the raw authored selector of one rule
7
+ * and the raw authored selectors of its enclosing rules (outermost-first) and
8
+ * returns a flat selector list. It never reads the AST, mutates its input or
9
+ * throws.
10
+ *
11
+ * Policy summary:
12
+ *
13
+ * - A nested selector without `&` is a descendant: `parent + " " + child`
14
+ * (ADR-0002).
15
+ * - `&` is substituted in any position, including trailing and repeated
16
+ * (ADR-0012). A backslash-escaped `\&` stays literal, and `&` inside strings,
17
+ * comments and attribute selectors is never rewritten.
18
+ * - A parent that resolves to one selector substitutes directly. A complex
19
+ * parent (contains a top-level combinator) is wrapped in `:is(...)` when `&`
20
+ * is attached to a prefix such as `.x&` or `&&`, because plain concatenation
21
+ * would change meaning.
22
+ * - A parent selector list with equal, known specificity expands as the CSS
23
+ * cross-product in authored order. A parent list with mixed or unknown
24
+ * specificity substitutes `:is(list)`, which is exactly native nesting
25
+ * specificity. Mixed-specificity lists containing pseudo-elements are
26
+ * rejected because `:is()` cannot accept them.
27
+ * - A nested rule's own selector list expands as a cross-product: each child
28
+ * item is expanded against every parent alternative in authored order.
29
+ * - Rejected cases return a reason: `&` outside a nested rule, empty selector
30
+ * list items, unbalanced structures, leading combinators (relative nested
31
+ * selectors need an explicit `&` per §7.1) and the pseudo-element case
32
+ * above. The emitter turns a rejection into CHIKX1001.
33
+ * - Expansion is bounded per rule by {@link FLATTEN_LIMITS}. A level that
34
+ * carries repeated `&` duplicates the selector product (and its character
35
+ * count) at every step, so a pathological but syntactically valid document
36
+ * would otherwise grow without bound; the bound rejects that rule with the
37
+ * same CHIKX1001 diagnostic while legal nesting is unaffected.
38
+ */
39
+ /**
40
+ * Per-rule bounds on flattened-selector expansion.
41
+ *
42
+ * A nesting level carrying two `&`s squares the selector product, and a `&`
43
+ * pair against a single parent doubles the selector length, so adversarial
44
+ * input grows exponentially. These limits cap one rule's flattened selector
45
+ * list; exceeding either aborts flattening with a CHIKX1001 diagnostic instead
46
+ * of hanging or exhausting memory.
47
+ *
48
+ * The defaults are deliberately generous: the committed scale case (a
49
+ * 1 000-level `&.m<n>` chain ending in a 500-item selector list) flattens to
50
+ * ~2.45 M characters in 500 alternatives, well inside the budget, while a
51
+ * 1 000-level `& &` chain aborts after roughly two dozen levels.
52
+ */
53
+ export declare const FLATTEN_LIMITS: Readonly<{
54
+ /** Maximum characters in one rule's flattened selector list (joined by `", "`). */
55
+ maxSelectorChars: 8388608;
56
+ /** Maximum number of flat alternatives in one rule's selector list. */
57
+ maxSelectors: 100000;
58
+ }>;
59
+ /** Successful flattening. */
60
+ export interface FlattenedSelector {
61
+ readonly ok: true;
62
+ /** Flat selector list, items joined with `", "`. */
63
+ readonly selector: string;
64
+ }
65
+ /** Rejected flattening with a user-facing reason for the emitter diagnostic. */
66
+ export interface FlattenFailure {
67
+ readonly ok: false;
68
+ readonly reason: string;
69
+ }
70
+ /** Result of {@link flattenSelector}. */
71
+ export type FlattenResult = FlattenedSelector | FlattenFailure;
72
+ /**
73
+ * Flatten one authored selector against its authored ancestor selectors.
74
+ *
75
+ * Pure and deterministic: the returned selector list preserves authored item
76
+ * order, cross-product order and all non-`&` tokens. A rejection carries a
77
+ * reason suitable for a CHIKX1001-family diagnostic. Expansion is bounded by
78
+ * {@link FLATTEN_LIMITS}; a document that exceeds it fails with one rejection
79
+ * instead of hanging or exhausting memory.
80
+ */
81
+ export declare function flattenSelector(selector: string, ancestors: readonly string[]): FlattenResult;
82
+ /**
83
+ * Flatten every rule selector in a stylesheet IR and clear `ancestors`.
84
+ *
85
+ * This is the explicit pipeline step between `groupRuns` and `emitCss`. Rules
86
+ * whose selector cannot be flattened are omitted with a CHIKX1001 diagnostic;
87
+ * callers that emit the original IR instead get the same rejection from
88
+ * `emitCss` directly. Declaration, condition, context and span data are
89
+ * preserved unchanged.
90
+ */
91
+ export declare function flattenIr(ir: StylesheetIr): {
92
+ readonly ir: StylesheetIr;
93
+ readonly diagnostics: readonly Diagnostic[];
94
+ };
95
+ //# sourceMappingURL=flatten.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/selectors/flatten.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAKV,YAAY,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAO1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc;IACzB,mFAAmF;;IAEnF,uEAAuE;;EAEvE,CAAC;AAQH,6BAA6B;AAC7B,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,oDAAoD;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,gFAAgF;AAChF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,yCAAyC;AACzC,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,cAAc,CAAC;AAqQ/D;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,CAY7F;AAgDD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,YAAY,GAAG;IAC3C,QAAQ,CAAC,EAAE,EAAE,YAAY,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C,CAYA"}