zyzz 0.0.28 → 0.0.29

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 (302) hide show
  1. package/binding/wasi/wasi-worker.mjs +186 -0
  2. package/binding/wasi/zyzz.wasi.cjs +2302 -0
  3. package/binding/wasi/zyzz.wasm32-wasi.wasm +0 -0
  4. package/binding/zyzz.linux-x64-gnu.node +0 -0
  5. package/dist/babel/index.d.ts.map +1 -1
  6. package/dist/babel/index.js +2 -4
  7. package/dist/babel/index.js.map +1 -1
  8. package/dist/babel/internal/Compilation.d.ts +0 -1
  9. package/dist/babel/internal/Compilation.d.ts.map +1 -1
  10. package/dist/compiler/Graph.d.ts +14 -11
  11. package/dist/compiler/Graph.d.ts.map +1 -1
  12. package/dist/compiler/Graph.js +57 -1442
  13. package/dist/compiler/Graph.js.map +1 -1
  14. package/dist/compiler/Native.d.ts +7 -9
  15. package/dist/compiler/Native.d.ts.map +1 -1
  16. package/dist/compiler/Native.js +12 -716
  17. package/dist/compiler/Native.js.map +1 -1
  18. package/dist/compiler/Source.d.ts +122 -24
  19. package/dist/compiler/Source.d.ts.map +1 -1
  20. package/dist/compiler/Source.js +10 -1267
  21. package/dist/compiler/Source.js.map +1 -1
  22. package/dist/compiler/Transform.d.ts +4 -3
  23. package/dist/compiler/Transform.d.ts.map +1 -1
  24. package/dist/compiler/Transform.js +13 -961
  25. package/dist/compiler/Transform.js.map +1 -1
  26. package/dist/compiler/internal/AtRules.d.ts +5 -1
  27. package/dist/compiler/internal/AtRules.d.ts.map +1 -1
  28. package/dist/compiler/internal/AtRules.js +12 -106
  29. package/dist/compiler/internal/AtRules.js.map +1 -1
  30. package/dist/compiler/internal/Context.d.ts +11 -0
  31. package/dist/compiler/internal/Context.d.ts.map +1 -0
  32. package/dist/compiler/internal/Context.js +11 -0
  33. package/dist/compiler/internal/Context.js.map +1 -0
  34. package/dist/compiler/internal/Results.d.ts +148 -0
  35. package/dist/compiler/internal/Results.d.ts.map +1 -0
  36. package/dist/compiler/internal/Results.js +259 -0
  37. package/dist/compiler/internal/Results.js.map +1 -0
  38. package/dist/compiler/internal/Syntax.d.ts +0 -2
  39. package/dist/compiler/internal/Syntax.d.ts.map +1 -1
  40. package/dist/compiler/internal/Syntax.js +0 -2
  41. package/dist/compiler/internal/Syntax.js.map +1 -1
  42. package/dist/compiler/internal/Wire.d.ts +17 -0
  43. package/dist/compiler/internal/Wire.d.ts.map +1 -0
  44. package/dist/compiler/internal/Wire.js +795 -0
  45. package/dist/compiler/internal/Wire.js.map +1 -0
  46. package/dist/internal/Addon.d.ts +28 -0
  47. package/dist/internal/Addon.d.ts.map +1 -0
  48. package/dist/internal/Addon.js +87 -0
  49. package/dist/internal/Addon.js.map +1 -0
  50. package/dist/internal/Literal.d.ts +4 -1
  51. package/dist/internal/Literal.d.ts.map +1 -1
  52. package/dist/internal/Literal.js +4 -2
  53. package/dist/internal/Literal.js.map +1 -1
  54. package/dist/internal/Token.d.ts +2 -1
  55. package/dist/internal/Token.d.ts.map +1 -1
  56. package/dist/internal/Token.js +2 -2
  57. package/dist/internal/Token.js.map +1 -1
  58. package/dist/internal/Vlq.d.ts +14 -0
  59. package/dist/internal/Vlq.d.ts.map +1 -0
  60. package/dist/internal/Vlq.js +47 -0
  61. package/dist/internal/Vlq.js.map +1 -0
  62. package/dist/internal/Wasm.d.ts +22 -0
  63. package/dist/internal/Wasm.d.ts.map +1 -0
  64. package/dist/internal/Wasm.js +83 -0
  65. package/dist/internal/Wasm.js.map +1 -0
  66. package/dist/metro/Graph.d.ts +0 -1
  67. package/dist/metro/Graph.d.ts.map +1 -1
  68. package/dist/metro/transformer.d.ts.map +1 -1
  69. package/dist/metro/transformer.js +0 -1
  70. package/dist/metro/transformer.js.map +1 -1
  71. package/dist/next/internal/Project.d.ts.map +1 -1
  72. package/dist/next/internal/Project.js +2 -5
  73. package/dist/next/internal/Project.js.map +1 -1
  74. package/dist/node/Host.d.ts.map +1 -1
  75. package/dist/node/Host.js +0 -2
  76. package/dist/node/Host.js.map +1 -1
  77. package/dist/node/internal/Contracts.d.ts.map +1 -1
  78. package/dist/node/internal/Contracts.js +3 -7
  79. package/dist/node/internal/Contracts.js.map +1 -1
  80. package/dist/node/internal/Snapshot.d.ts +0 -1
  81. package/dist/node/internal/Snapshot.d.ts.map +1 -1
  82. package/dist/node/internal/Snapshot.js +0 -6
  83. package/dist/node/internal/Snapshot.js.map +1 -1
  84. package/dist/runtime/Composition.d.ts +2 -3
  85. package/dist/runtime/Composition.d.ts.map +1 -1
  86. package/dist/runtime/Composition.js +51 -30
  87. package/dist/runtime/Composition.js.map +1 -1
  88. package/dist/runtime/Recipe.d.ts.map +1 -1
  89. package/dist/runtime/Recipe.js +16 -12
  90. package/dist/runtime/Recipe.js.map +1 -1
  91. package/dist/unplugin/index.d.ts.map +1 -1
  92. package/dist/unplugin/index.js +3 -6
  93. package/dist/unplugin/index.js.map +1 -1
  94. package/dist/vite/index.d.ts.map +1 -1
  95. package/dist/vite/index.js +696 -201
  96. package/dist/vite/index.js.map +1 -1
  97. package/dist/web/Css.d.ts +8 -3
  98. package/dist/web/Css.d.ts.map +1 -1
  99. package/dist/web/Css.js +5 -721
  100. package/dist/web/Css.js.map +1 -1
  101. package/dist/web/internal/Block.d.ts +0 -2
  102. package/dist/web/internal/Block.d.ts.map +1 -1
  103. package/dist/web/internal/Block.js +1 -12
  104. package/dist/web/internal/Block.js.map +1 -1
  105. package/dist/web/internal/ClassName.d.ts +23 -18
  106. package/dist/web/internal/ClassName.d.ts.map +1 -1
  107. package/dist/web/internal/ClassName.js +26 -55
  108. package/dist/web/internal/ClassName.js.map +1 -1
  109. package/dist/web/internal/Contributions.d.ts +3 -5
  110. package/dist/web/internal/Contributions.d.ts.map +1 -1
  111. package/dist/web/internal/Contributions.js +0 -45
  112. package/dist/web/internal/Contributions.js.map +1 -1
  113. package/dist/web/internal/Engine.browser.d.ts +8 -0
  114. package/dist/web/internal/Engine.browser.d.ts.map +1 -0
  115. package/dist/web/internal/Engine.browser.js +42 -0
  116. package/dist/web/internal/Engine.browser.js.map +1 -0
  117. package/dist/web/internal/Engine.d.ts +9 -0
  118. package/dist/web/internal/Engine.d.ts.map +1 -0
  119. package/dist/web/internal/Engine.js +14 -0
  120. package/dist/web/internal/Engine.js.map +1 -0
  121. package/dist/web/internal/Themes.d.ts +1 -9
  122. package/dist/web/internal/Themes.d.ts.map +1 -1
  123. package/dist/web/internal/Themes.js +3 -221
  124. package/dist/web/internal/Themes.js.map +1 -1
  125. package/dist/web/internal/Wasm.generated.d.ts +4 -0
  126. package/dist/web/internal/Wasm.generated.d.ts.map +1 -0
  127. package/dist/web/internal/Wasm.generated.js +4 -0
  128. package/dist/web/internal/Wasm.generated.js.map +1 -0
  129. package/dist/web/internal/Wire.d.ts +19 -0
  130. package/dist/web/internal/Wire.d.ts.map +1 -0
  131. package/dist/web/internal/Wire.js +387 -0
  132. package/dist/web/internal/Wire.js.map +1 -0
  133. package/package.json +20 -1
  134. package/src/babel/index.ts +2 -5
  135. package/src/babel/internal/Compilation.ts +0 -1
  136. package/src/compiler/Graph.ts +89 -1930
  137. package/src/compiler/Native.ts +18 -871
  138. package/src/compiler/Source.ts +144 -1803
  139. package/src/compiler/Transform.ts +16 -1315
  140. package/src/compiler/internal/AtRules.ts +27 -115
  141. package/src/compiler/internal/Context.ts +11 -0
  142. package/src/compiler/internal/Results.ts +406 -0
  143. package/src/compiler/internal/Syntax.ts +0 -3
  144. package/src/compiler/internal/Wire.ts +1045 -0
  145. package/src/internal/Addon.ts +118 -0
  146. package/src/internal/Literal.ts +4 -2
  147. package/src/internal/Token.ts +2 -2
  148. package/src/internal/Vlq.ts +59 -0
  149. package/src/internal/Wasm.ts +111 -0
  150. package/src/metro/transformer.ts +0 -1
  151. package/src/next/internal/Project.ts +2 -9
  152. package/src/node/Host.ts +0 -2
  153. package/src/node/internal/Contracts.ts +3 -7
  154. package/src/node/internal/Snapshot.ts +0 -8
  155. package/src/runtime/Composition.ts +48 -25
  156. package/src/runtime/Recipe.ts +21 -14
  157. package/src/unplugin/index.ts +6 -6
  158. package/src/vite/index.ts +922 -221
  159. package/src/web/Css.ts +12 -908
  160. package/src/web/internal/Block.ts +0 -14
  161. package/src/web/internal/ClassName.ts +52 -85
  162. package/src/web/internal/Contributions.ts +3 -59
  163. package/src/web/internal/Engine.browser.ts +51 -0
  164. package/src/web/internal/Engine.ts +17 -0
  165. package/src/web/internal/Themes.ts +3 -279
  166. package/src/web/internal/Wasm.generated.ts +3 -0
  167. package/src/web/internal/Wire.ts +466 -0
  168. package/src/web/internal/wasm.d.ts +9 -0
  169. package/dist/compiler/internal/Applications.d.ts +0 -55
  170. package/dist/compiler/internal/Applications.d.ts.map +0 -1
  171. package/dist/compiler/internal/Applications.js +0 -393
  172. package/dist/compiler/internal/Applications.js.map +0 -1
  173. package/dist/compiler/internal/ColorProfiles.d.ts +0 -3
  174. package/dist/compiler/internal/ColorProfiles.d.ts.map +0 -1
  175. package/dist/compiler/internal/ColorProfiles.js +0 -84
  176. package/dist/compiler/internal/ColorProfiles.js.map +0 -1
  177. package/dist/compiler/internal/CompositionBindings.d.ts +0 -16
  178. package/dist/compiler/internal/CompositionBindings.d.ts.map +0 -1
  179. package/dist/compiler/internal/CompositionBindings.js +0 -89
  180. package/dist/compiler/internal/CompositionBindings.js.map +0 -1
  181. package/dist/compiler/internal/Compositions.d.ts +0 -37
  182. package/dist/compiler/internal/Compositions.d.ts.map +0 -1
  183. package/dist/compiler/internal/Compositions.js +0 -494
  184. package/dist/compiler/internal/Compositions.js.map +0 -1
  185. package/dist/compiler/internal/Configurations.d.ts +0 -26
  186. package/dist/compiler/internal/Configurations.d.ts.map +0 -1
  187. package/dist/compiler/internal/Configurations.js +0 -259
  188. package/dist/compiler/internal/Configurations.js.map +0 -1
  189. package/dist/compiler/internal/Contract.d.ts +0 -30
  190. package/dist/compiler/internal/Contract.d.ts.map +0 -1
  191. package/dist/compiler/internal/Contract.js +0 -753
  192. package/dist/compiler/internal/Contract.js.map +0 -1
  193. package/dist/compiler/internal/Contributions.d.ts +0 -54
  194. package/dist/compiler/internal/Contributions.d.ts.map +0 -1
  195. package/dist/compiler/internal/Contributions.js +0 -1151
  196. package/dist/compiler/internal/Contributions.js.map +0 -1
  197. package/dist/compiler/internal/Descriptors.d.ts +0 -15
  198. package/dist/compiler/internal/Descriptors.d.ts.map +0 -1
  199. package/dist/compiler/internal/Descriptors.js +0 -192
  200. package/dist/compiler/internal/Descriptors.js.map +0 -1
  201. package/dist/compiler/internal/Dynamic.d.ts +0 -14
  202. package/dist/compiler/internal/Dynamic.d.ts.map +0 -1
  203. package/dist/compiler/internal/Dynamic.js +0 -175
  204. package/dist/compiler/internal/Dynamic.js.map +0 -1
  205. package/dist/compiler/internal/Expression.d.ts +0 -19
  206. package/dist/compiler/internal/Expression.d.ts.map +0 -1
  207. package/dist/compiler/internal/Expression.js +0 -164
  208. package/dist/compiler/internal/Expression.js.map +0 -1
  209. package/dist/compiler/internal/Functions.d.ts +0 -5
  210. package/dist/compiler/internal/Functions.d.ts.map +0 -1
  211. package/dist/compiler/internal/Functions.js +0 -191
  212. package/dist/compiler/internal/Functions.js.map +0 -1
  213. package/dist/compiler/internal/Keyframes.d.ts +0 -5
  214. package/dist/compiler/internal/Keyframes.d.ts.map +0 -1
  215. package/dist/compiler/internal/Keyframes.js +0 -51
  216. package/dist/compiler/internal/Keyframes.js.map +0 -1
  217. package/dist/compiler/internal/Names.d.ts +0 -5
  218. package/dist/compiler/internal/Names.d.ts.map +0 -1
  219. package/dist/compiler/internal/Names.js +0 -37
  220. package/dist/compiler/internal/Names.js.map +0 -1
  221. package/dist/compiler/internal/NativeBindings.d.ts +0 -72
  222. package/dist/compiler/internal/NativeBindings.d.ts.map +0 -1
  223. package/dist/compiler/internal/NativeBindings.js +0 -171
  224. package/dist/compiler/internal/NativeBindings.js.map +0 -1
  225. package/dist/compiler/internal/NativeMedia.d.ts +0 -14
  226. package/dist/compiler/internal/NativeMedia.d.ts.map +0 -1
  227. package/dist/compiler/internal/NativeMedia.js +0 -287
  228. package/dist/compiler/internal/NativeMedia.js.map +0 -1
  229. package/dist/compiler/internal/NativeVars.d.ts +0 -28
  230. package/dist/compiler/internal/NativeVars.d.ts.map +0 -1
  231. package/dist/compiler/internal/NativeVars.js +0 -160
  232. package/dist/compiler/internal/NativeVars.js.map +0 -1
  233. package/dist/compiler/internal/PackedStyles.d.ts +0 -37
  234. package/dist/compiler/internal/PackedStyles.d.ts.map +0 -1
  235. package/dist/compiler/internal/PackedStyles.js +0 -344
  236. package/dist/compiler/internal/PackedStyles.js.map +0 -1
  237. package/dist/compiler/internal/Properties.d.ts +0 -5
  238. package/dist/compiler/internal/Properties.d.ts.map +0 -1
  239. package/dist/compiler/internal/Properties.js +0 -82
  240. package/dist/compiler/internal/Properties.js.map +0 -1
  241. package/dist/compiler/internal/RecipeConditions.d.ts +0 -41
  242. package/dist/compiler/internal/RecipeConditions.d.ts.map +0 -1
  243. package/dist/compiler/internal/RecipeConditions.js +0 -82
  244. package/dist/compiler/internal/RecipeConditions.js.map +0 -1
  245. package/dist/compiler/internal/RecipePayloads.d.ts +0 -31
  246. package/dist/compiler/internal/RecipePayloads.d.ts.map +0 -1
  247. package/dist/compiler/internal/RecipePayloads.js +0 -99
  248. package/dist/compiler/internal/RecipePayloads.js.map +0 -1
  249. package/dist/compiler/internal/Recipes.d.ts +0 -32
  250. package/dist/compiler/internal/Recipes.d.ts.map +0 -1
  251. package/dist/compiler/internal/Recipes.js +0 -339
  252. package/dist/compiler/internal/Recipes.js.map +0 -1
  253. package/dist/compiler/internal/Selectors.d.ts +0 -13
  254. package/dist/compiler/internal/Selectors.d.ts.map +0 -1
  255. package/dist/compiler/internal/Selectors.js +0 -280
  256. package/dist/compiler/internal/Selectors.js.map +0 -1
  257. package/dist/compiler/internal/Static.d.ts +0 -39
  258. package/dist/compiler/internal/Static.d.ts.map +0 -1
  259. package/dist/compiler/internal/Static.js +0 -534
  260. package/dist/compiler/internal/Static.js.map +0 -1
  261. package/dist/compiler/internal/Themes.d.ts +0 -190
  262. package/dist/compiler/internal/Themes.d.ts.map +0 -1
  263. package/dist/compiler/internal/Themes.js +0 -1577
  264. package/dist/compiler/internal/Themes.js.map +0 -1
  265. package/dist/compiler/internal/Vars.d.ts +0 -33
  266. package/dist/compiler/internal/Vars.d.ts.map +0 -1
  267. package/dist/compiler/internal/Vars.js +0 -387
  268. package/dist/compiler/internal/Vars.js.map +0 -1
  269. package/dist/compiler/internal/ViewTransitions.d.ts +0 -3
  270. package/dist/compiler/internal/ViewTransitions.d.ts.map +0 -1
  271. package/dist/compiler/internal/ViewTransitions.js +0 -68
  272. package/dist/compiler/internal/ViewTransitions.js.map +0 -1
  273. package/dist/internal/Cascade.d.ts +0 -74
  274. package/dist/internal/Cascade.d.ts.map +0 -1
  275. package/dist/internal/Cascade.js +0 -210
  276. package/dist/internal/Cascade.js.map +0 -1
  277. package/src/compiler/internal/Applications.ts +0 -610
  278. package/src/compiler/internal/ColorProfiles.ts +0 -93
  279. package/src/compiler/internal/CompositionBindings.ts +0 -120
  280. package/src/compiler/internal/Compositions.ts +0 -678
  281. package/src/compiler/internal/Configurations.ts +0 -349
  282. package/src/compiler/internal/Contract.ts +0 -1028
  283. package/src/compiler/internal/Contributions.ts +0 -1561
  284. package/src/compiler/internal/Descriptors.ts +0 -242
  285. package/src/compiler/internal/Dynamic.ts +0 -275
  286. package/src/compiler/internal/Expression.ts +0 -218
  287. package/src/compiler/internal/Functions.ts +0 -206
  288. package/src/compiler/internal/Keyframes.ts +0 -62
  289. package/src/compiler/internal/Names.ts +0 -48
  290. package/src/compiler/internal/NativeBindings.ts +0 -235
  291. package/src/compiler/internal/NativeMedia.ts +0 -342
  292. package/src/compiler/internal/NativeVars.ts +0 -231
  293. package/src/compiler/internal/PackedStyles.ts +0 -473
  294. package/src/compiler/internal/Properties.ts +0 -121
  295. package/src/compiler/internal/RecipeConditions.ts +0 -139
  296. package/src/compiler/internal/RecipePayloads.ts +0 -132
  297. package/src/compiler/internal/Recipes.ts +0 -531
  298. package/src/compiler/internal/Selectors.ts +0 -353
  299. package/src/compiler/internal/Static.ts +0 -784
  300. package/src/compiler/internal/Themes.ts +0 -2398
  301. package/src/compiler/internal/Vars.ts +0 -516
  302. package/src/compiler/internal/ViewTransitions.ts +0 -82
@@ -2,1247 +2,23 @@
2
2
  * Extracts literal styles and local themes through lexical source analysis.
3
3
  * @module
4
4
  */
5
- import * as Identity from '../internal/Identity.js';
6
- import * as Identifiers from './internal/Identifiers.js';
7
- import * as AtRules from './internal/AtRules.js';
8
- import * as Binding from '../internal/Binding.js';
9
- import * as Condition from '../internal/Condition.js';
10
- import * as Compositions from './internal/Compositions.js';
11
- import * as Contributions from './internal/Contributions.js';
12
- import * as Css from '../web/Css.js';
13
- import * as Dynamic from './internal/Dynamic.js';
14
- import * as Expression from './internal/Expression.js';
15
- import * as Selectors from './internal/Selectors.js';
16
- import * as Syntax from './internal/Syntax.js';
17
- import * as RuleReference from '../internal/RuleReference.js';
18
- import * as Recipes from './internal/Recipes.js';
19
- import * as PackedStyles from './internal/PackedStyles.js';
20
- import * as Scope from './internal/Scope.js';
21
- import * as Static from './internal/Static.js';
22
- import * as Style from '../Style.js';
23
- import * as Themes from './internal/Themes.js';
24
- import * as ThemeValues from '../web/internal/Themes.js';
25
- import * as Token from '../internal/Token.js';
26
- import * as Literal from '../internal/Literal.js';
27
- import * as Names from './internal/Names.js';
28
- import * as ClassName from '../web/internal/ClassName.js';
29
- import * as Typography from '../internal/Typography.js';
30
- import * as Value from '../internal/Value.js';
31
- import * as Vars from './internal/Vars.js';
32
- import * as Walker from 'oxc-walker';
33
- // JavaScript extraction supplies untyped values. Keep structural checks without
34
- // asserting that those values already satisfy the TypeScript authoring contract.
35
- const define = Style.define;
5
+ import * as Addon from '../internal/Addon.js';
6
+ import * as Wire from './internal/Wire.js';
36
7
  /**
37
8
  * Extracts direct style calls and local Theme definitions imported from zyzz.
38
- * Parses TypeScript and JSX without reading files, loading config, or evaluating source.
9
+ * Parses TypeScript and JSX in the Rust compiler without reading files, loading config, or
10
+ * evaluating source. The returned calls carry no syntax trees.
39
11
  * @param options - Source text and a portable package-relative module identity.
40
12
  * @returns Frozen style/theme definitions and rewrite spans. Source text is unchanged.
41
13
  * @throws {ExtractError} For syntax errors, unsupported imported references, or invalid literals.
42
14
  */
43
15
  export function extract(options) {
44
- const calls = [];
45
- const diagnostics = [];
46
- const pending = [];
47
- const recipes = new Set();
48
- const styles = [];
49
- function report(code, message, node) {
50
- diagnostics.push({
51
- code,
52
- end: node?.end ?? 0,
53
- message,
54
- source: options.moduleId,
55
- start: node?.start ?? 0,
56
- });
57
- }
58
- if (!options.moduleId ||
59
- options.moduleId.includes('\\') ||
60
- options.moduleId.includes(':') ||
61
- options.moduleId
62
- .split('/')
63
- .some((part) => !part || part === '.' || part === '..')) {
64
- report('invalid_module', 'Expected a portable package-relative module ID without absolute paths, backslashes, or traversal segments.');
65
- throw new ExtractError(diagnostics);
66
- }
67
- const namespace = identity(options.moduleId);
68
- const parsed = options[Themes.context]?.parsed ?? Syntax.parse(options);
69
- for (const node of parsed.program.body) {
70
- if (node.type !== 'ImportDeclaration' || node.source.value !== 'zyzz')
71
- continue;
72
- for (const specifier of node.specifiers) {
73
- if (specifier.type !== 'ImportSpecifier')
74
- continue;
75
- const name = specifier.imported.type === 'Identifier'
76
- ? specifier.imported.name
77
- : specifier.imported.value;
78
- if (name === 'Theme' || name === 'Variables')
79
- throw new ExtractError([
80
- {
81
- code: 'unsupported_syntax',
82
- message: `Import Vars instead of ${name}.`,
83
- source: options.moduleId,
84
- start: specifier.start,
85
- end: specifier.end,
86
- },
87
- ]);
88
- }
89
- }
90
- if (parsed.errors.length) {
91
- for (const error of parsed.errors) {
92
- const span = error.labels[0];
93
- report('syntax_error', error.message, span);
94
- }
95
- throw new ExtractError(diagnostics);
96
- }
97
- const program = parsed.program;
98
- const authoredNames = Names.collect(program);
99
- const scopeTracker = new Scope.Tracker({ preserveExitedScopes: true });
100
- Walker.walk(program, { scopeTracker });
101
- scopeTracker.freeze();
102
- const staticData = Static.create(program, scopeTracker, options[Themes.context]?.constants);
103
- const contributions = (() => {
104
- try {
105
- return Contributions.scan(program, scopeTracker, namespace, options[Themes.context]?.links, options[Themes.context]?.factories);
106
- }
107
- catch (error) {
108
- if (!(error instanceof Themes.InvalidError))
109
- throw error;
110
- report('unsupported_syntax', error.message, error);
111
- throw new ExtractError(diagnostics);
112
- }
113
- })();
114
- const variables = (() => {
115
- try {
116
- return Vars.collect(program, namespace, scopeTracker, options[Themes.context]?.links, options.moduleId);
117
- }
118
- catch (error) {
119
- if (!(error instanceof Themes.InvalidError))
120
- throw error;
121
- report('unsupported_syntax', error.message, error);
122
- throw new ExtractError(diagnostics);
123
- }
124
- })();
125
- const themes = (() => {
126
- try {
127
- return Themes.collect(program, {
128
- native: options.target === 'native',
129
- staticBindings: staticData.bindings,
130
- namespace: `src-${Identity.label(options.moduleId
131
- .split('/')
132
- .at(-1)
133
- .replace(/\.[cm]?[jt]sx?$/, ''))}-${Identity.compact(options.moduleId)}`,
134
- contributionCalls: new Set(contributions.calls.map((call) => call.start)),
135
- linked: options[Themes.context] !== undefined,
136
- links: options[Themes.context]?.links,
137
- });
138
- }
139
- catch (error) {
140
- if (!(error instanceof Themes.InvalidError))
141
- throw error;
142
- report('unsupported_syntax', error.message, error);
143
- throw new ExtractError(diagnostics);
144
- }
145
- })();
146
- const ancestors = [];
147
- const typeAncestors = new Set();
148
- const typeNodes = new Set([
149
- 'TSInterfaceDeclaration',
150
- 'TSTypeAliasDeclaration',
151
- 'TSTypeAnnotation',
152
- 'TSTypeParameterDeclaration',
153
- 'TSTypeParameterInstantiation',
154
- 'TSTypeQuery',
155
- ]);
156
- Walker.walk(program, {
157
- enter(node, parent) {
158
- const declaration = staticData.visitor.enter(node, parent);
159
- ancestors.push(node);
160
- if ((parent &&
161
- 'typeAnnotation' in parent &&
162
- parent.typeAnnotation === node) ||
163
- typeNodes.has(node.type) ||
164
- (node.type === 'ExportNamedDeclaration' &&
165
- (node.source !== null || node.exportKind === 'type')) ||
166
- (node.type === 'ExportSpecifier' && node.exportKind === 'type'))
167
- typeAncestors.add(node);
168
- if ((node.type !== 'Identifier' && node.type !== 'JSXIdentifier') ||
169
- !parent ||
170
- (node.type === 'Identifier'
171
- ? declaration === undefined
172
- : !Walker.isReferenceIdentifier(node, parent)))
173
- return;
174
- // Both passes visit identical scopes; skipping type subtrees changes scope IDs.
175
- if (typeAncestors.size)
176
- return;
177
- const binding = node.type === 'Identifier'
178
- ? (declaration ?? null)
179
- : scopeTracker.getDeclaration(node.name);
180
- contributions.read(node, parent, binding);
181
- try {
182
- if (variables.reference(node, parent, ancestors, binding))
183
- return;
184
- }
185
- catch (error) {
186
- if (!(error instanceof Themes.InvalidError))
187
- throw error;
188
- report('unsupported_syntax', error.message, error);
189
- return;
190
- }
191
- if (themes)
192
- try {
193
- if (themes.reference(node, parent, ancestors, binding, (name) => scopeTracker.getDeclaration(name) ?? null))
194
- return;
195
- }
196
- catch (error) {
197
- if (!(error instanceof Themes.InvalidError))
198
- throw error;
199
- report('unsupported_syntax', error.message, error);
200
- return;
201
- }
202
- if (binding?.type !== 'Import' ||
203
- binding.importNode.source.value !== 'zyzz' ||
204
- binding.importNode.importKind === 'type')
205
- return;
206
- const specifier = binding.node;
207
- if (specifier.type === 'ImportNamespaceSpecifier') {
208
- if (parent.type === 'MemberExpression' && parent.object === node) {
209
- const name = (() => {
210
- if (parent.property.type === 'Identifier' && !parent.computed) {
211
- return parent.property.name;
212
- }
213
- if (parent.property.type === 'Literal') {
214
- return parent.property.value;
215
- }
216
- return undefined;
217
- })();
218
- if (name === 'Config' ||
219
- name === 'cx' ||
220
- name === 'defineConfig' ||
221
- name === 'defineVars' ||
222
- name === 'extendVars' ||
223
- name === 'style' ||
224
- name === 'Theme' ||
225
- name === 'Vars' ||
226
- name === 'variable' ||
227
- name === 'variants')
228
- report('unsupported_syntax', `Import ${name} by name; namespace authoring calls are not supported yet.`, parent);
229
- }
230
- return;
231
- }
232
- if (specifier.type !== 'ImportSpecifier' ||
233
- specifier.importKind === 'type' ||
234
- !['style', 'variants'].includes(specifier.imported.type === 'Identifier'
235
- ? specifier.imported.name
236
- : specifier.imported.value))
237
- return;
238
- // Follow only assignment targets; computed keys and default values are reads.
239
- let target = node;
240
- let write;
241
- for (let index = ancestors.length - 2; index >= 0; index--) {
242
- const ancestor = ancestors[index];
243
- if ((ancestor.type === 'AssignmentExpression' &&
244
- ancestor.left === target) ||
245
- (ancestor.type === 'UpdateExpression' &&
246
- ancestor.argument === target) ||
247
- ((ancestor.type === 'ForInStatement' ||
248
- ancestor.type === 'ForOfStatement') &&
249
- ancestor.left === target)) {
250
- write = ancestor;
251
- break;
252
- }
253
- if ((ancestor.type === 'Property' && ancestor.value === target) ||
254
- ancestor.type === 'ObjectPattern' ||
255
- ancestor.type === 'ArrayPattern' ||
256
- (ancestor.type === 'RestElement' && ancestor.argument === target) ||
257
- (ancestor.type === 'AssignmentPattern' && ancestor.left === target))
258
- target = ancestor;
259
- else
260
- break;
261
- }
262
- if (write)
263
- report('unsupported_syntax', 'Imported style bindings cannot be reassigned.', write);
264
- else if (parent.type === 'CallExpression' &&
265
- parent.callee === node &&
266
- !parent.optional) {
267
- pending.push(parent);
268
- if ((specifier.imported.type === 'Identifier'
269
- ? specifier.imported.name
270
- : specifier.imported.value) === 'variants')
271
- recipes.add(parent.start);
272
- }
273
- else
274
- report('unsupported_syntax', 'Use a direct style call; aliases, re-exports, and indirect references are not supported yet.', node);
275
- },
276
- leave(node) {
277
- ancestors.pop();
278
- typeAncestors.delete(node);
279
- staticData.visitor.leave();
280
- },
281
- scopeTracker,
282
- });
283
- Contributions.resolve(contributions);
284
- // Imports and reference lists can have a different order from authored calls.
285
- if (themes)
286
- for (const entry of themes.styles.values()) {
287
- pending.push(entry.call);
288
- if (entry.recipe)
289
- recipes.add(entry.call.start);
290
- }
291
- pending.sort((a, b) => a.start - b.start);
292
- const staticCalls = new Set([
293
- ...pending.map((call) => call.start),
294
- ...contributions.calls.map((call) => call.start),
295
- ]);
296
- const opaque = new Set(variables.references.keys());
297
- const normalized = new Map();
298
- const selectorKeys = new Set();
299
- const composed = [];
300
- for (const call of pending) {
301
- if (!call.arguments[0])
302
- continue;
303
- try {
304
- const value = staticData.normalize(call.arguments[0], staticCalls, opaque);
305
- normalized.set(call.start, value);
306
- if (value.type === 'ArrayExpression')
307
- for (const element of value.elements) {
308
- const entry = element && Expression.unwrap(element);
309
- if (entry?.type === 'Identifier' ||
310
- entry?.type === 'MemberExpression')
311
- composed.push(entry);
312
- }
313
- const body = value.type === 'ArrowFunctionExpression'
314
- ? staticData.normalize(value.body, staticCalls, opaque)
315
- : value;
316
- Walker.walk(body, {
317
- enter(node) {
318
- if (node.type !== 'Property' ||
319
- node.computed ||
320
- node.value.type !== 'ObjectExpression' ||
321
- !((node.key.type === 'Identifier' &&
322
- node.key.name === 'selectors') ||
323
- (node.key.type === 'Literal' && node.key.value === 'selectors')))
324
- return;
325
- for (const property of node.value.properties)
326
- if (property.type === 'Property')
327
- selectorKeys.add(property.key.start);
328
- },
329
- });
330
- }
331
- catch (error) {
332
- if (!(error instanceof Themes.InvalidError))
333
- throw error;
334
- normalized.set(call.start, error);
335
- }
336
- }
337
- for (const call of pending) {
338
- try {
339
- Identifiers.explicit(call);
340
- }
341
- catch (error) {
342
- report('unsupported_syntax', error.message, call);
343
- }
344
- }
345
- if (diagnostics.length)
346
- throw new ExtractError(diagnostics);
347
- const selectors = (() => {
348
- try {
349
- return Selectors.scan(program, scopeTracker, namespace, pending, options[Themes.context]?.links, selectorKeys, new Map([...(themes?.styles ?? [])].flatMap(([start, context]) => {
350
- const id = context.theme[Token.definition].contract[Token.identity];
351
- return id?.startsWith('id-') ? [[start, id.slice(3)]] : [];
352
- })), options.moduleId, composed);
353
- }
354
- catch (error) {
355
- if (!(error instanceof Themes.InvalidError))
356
- throw error;
357
- report('unsupported_syntax', error.message, error);
358
- throw new ExtractError(diagnostics);
359
- }
360
- })();
361
- const bodies = new Map();
362
- const cssNameCounts = new Map();
363
- for (const call of pending) {
364
- const name = authoredNames.get(call.start);
365
- cssNameCounts.set(name, (cssNameCounts.get(name) ?? 0) + 1);
366
- }
367
- const cssNameIndices = new Map();
368
- for (const [callIndex, call] of pending.entries()) {
369
- const explicitId = (() => {
370
- try {
371
- return Identifiers.explicit(call);
372
- }
373
- catch (error) {
374
- report('unsupported_syntax', error.message, call);
375
- return undefined;
376
- }
377
- })();
378
- const contractIdentity = themes?.styles.get(call.start)?.theme[Token.definition].contract[Token.identity];
379
- const cssNamespace = contractIdentity?.startsWith('id-')
380
- ? contractIdentity.slice(3)
381
- : undefined;
382
- const authoredName = authoredNames.get(call.start);
383
- const nameIndex = cssNameIndices.get(authoredName) ?? 0;
384
- cssNameIndices.set(authoredName, nameIndex + 1);
385
- const cssName = explicitId !== undefined
386
- ? Identity.name(explicitId)
387
- : `${Identity.compact(options.moduleId).slice(-6)}-${authoredName === 'style'
388
- ? `style-${callIndex}`
389
- : cssNameCounts.get(authoredName) > 1
390
- ? `${authoredName}-${nameIndex}`
391
- : authoredName}`;
392
- const definitionId = explicitId === undefined
393
- ? `${cssNamespace ? `${cssNamespace}-` : ''}${cssName}`
394
- : `id-${cssNamespace ? `${cssNamespace}-` : ''}${Identity.requireId(explicitId, 'style').slice(3)}`;
395
- let argument = call.arguments[0];
396
- if (call.arguments.length === 0)
397
- argument = {
398
- end: call.end - 1,
399
- properties: [],
400
- start: call.end - 1,
401
- type: 'ObjectExpression',
402
- };
403
- while (argument?.type === 'TSAsExpression' ||
404
- argument?.type === 'TSSatisfiesExpression')
405
- argument = argument.expression;
406
- const original = argument;
407
- try {
408
- const value = normalized.get(call.start);
409
- if (value instanceof Error)
410
- throw value;
411
- if (value)
412
- argument = value;
413
- }
414
- catch (error) {
415
- if (!(error instanceof Themes.InvalidError))
416
- throw error;
417
- report('unsupported_syntax', error.message, error);
418
- continue;
419
- }
420
- const diagnosticCount = diagnostics.length;
421
- const dynamic = (() => {
422
- if (!argument)
423
- return undefined;
424
- try {
425
- return Dynamic.read(argument, definitionId, staticData.type);
426
- }
427
- catch (error) {
428
- if (!(error instanceof Themes.InvalidError))
429
- throw error;
430
- report('unsupported_syntax', error.message, error);
431
- return undefined;
432
- }
433
- })();
434
- if (diagnostics.length !== diagnosticCount)
435
- continue;
436
- let dynamicValues = dynamic;
437
- function resolveDynamic(node) {
438
- try {
439
- return dynamicValues?.resolve(node);
440
- }
441
- catch (error) {
442
- if (!(error instanceof Themes.InvalidError))
443
- throw error;
444
- report('unsupported_syntax', error.message, error);
445
- return undefined;
446
- }
447
- }
448
- if (dynamic) {
449
- try {
450
- argument = staticData.normalize(dynamic.body, staticCalls, opaque);
451
- }
452
- catch (error) {
453
- if (!(error instanceof Themes.InvalidError))
454
- throw error;
455
- report('unsupported_syntax', error.message, error);
456
- continue;
457
- }
458
- }
459
- const entries = argument?.type === 'ArrayExpression' &&
460
- !dynamic &&
461
- !recipes.has(call.start)
462
- ? argument.elements
463
- : undefined;
464
- if (call.arguments.length > 2 ||
465
- (argument?.type !== 'ObjectExpression' && !entries)) {
466
- report('unsupported_syntax', 'Expected one literal object, typed callback, or array of style definitions and literal objects; spreads are not supported.', call);
467
- continue;
468
- }
469
- const before = diagnostics.length;
470
- let recipe;
471
- let recipeTypes;
472
- let staticRecipe;
473
- let dynamicRecipe;
474
- if (recipes.has(call.start) && argument?.type === 'ObjectExpression') {
475
- try {
476
- if (dynamic)
477
- throw new Themes.InvalidError('Recipes require static top-level objects.', original ?? call);
478
- const expanded = Recipes.expand(argument, {
479
- identity: definitionId,
480
- normalize: (node) => staticData.normalize(node, staticCalls, opaque),
481
- queries: themes?.styles.get(call.start)?.theme[Token.definition]
482
- .queries,
483
- resolveType: staticData.type,
484
- source: options.source,
485
- });
486
- argument = expanded.body;
487
- recipe = expanded.recipe;
488
- staticRecipe = expanded.staticRecipe;
489
- dynamicRecipe = expanded.dynamicRecipe;
490
- recipeTypes = expanded.types;
491
- dynamicValues = expanded.bindings;
492
- }
493
- catch (error) {
494
- if (!(error instanceof Themes.InvalidError))
495
- throw error;
496
- report('unsupported_syntax', error.message, error);
497
- continue;
498
- }
499
- }
500
- const name = `style-${namespace}-${call.start}`;
501
- const locations = [];
502
- const typography = new Map();
503
- const typographyQueries = new Map();
504
- const conditionKeys = new Map();
505
- function object(argument, prefix = []) {
506
- const values = Object.create(null);
507
- const target = prefix.lastIndexOf('targets');
508
- if (target !== -1 && prefix.length > 64) {
509
- report('unsupported_syntax', 'Target nesting exceeds 64 levels.', argument);
510
- return values;
511
- }
512
- const depth = prefix.length + 2;
513
- function localSlot(node) {
514
- const slot = resolveDynamic(node);
515
- if (slot &&
516
- prefix.some((key) => !Condition.local(key) && !selectors.localConditions.has(key))) {
517
- report('unsupported_syntax', 'Dynamic values require conditions that select the styled element.', node);
518
- return undefined;
519
- }
520
- return slot;
521
- }
522
- const properties = [];
523
- for (const entry of argument.properties) {
524
- const key = entry.type === 'Property' && !entry.computed
525
- ? entry.key.type === 'Identifier'
526
- ? entry.key.name
527
- : entry.key.type === 'Literal'
528
- ? entry.key.value
529
- : undefined
530
- : undefined;
531
- if (key !== 'selectors' && key !== 'vars') {
532
- properties.push(entry);
533
- continue;
534
- }
535
- if (entry.type !== 'Property' ||
536
- entry.kind !== 'init' ||
537
- entry.method ||
538
- entry.shorthand ||
539
- entry.value.type !== 'ObjectExpression') {
540
- report('unsupported_syntax', `${key} requires an explicit literal object.`, entry);
541
- continue;
542
- }
543
- for (const property of entry.value.properties) {
544
- if (property.type !== 'Property' ||
545
- (key === 'selectors'
546
- ? !selectors.conditions.has(property.key.start)
547
- : !property.computed ||
548
- !variables.references.has(property.key.start))) {
549
- report('unsupported_syntax', key === 'selectors'
550
- ? 'Selectors require explicit & targets.'
551
- : 'Variable assignments require declared variable keys.', property);
552
- continue;
553
- }
554
- properties.push(property);
555
- }
556
- }
557
- for (const property of properties) {
558
- if (property.type !== 'Property' ||
559
- property.kind !== 'init' ||
560
- property.method ||
561
- (property.computed &&
562
- !selectors.conditions.has(property.key.start) &&
563
- !variables.references.has(property.key.start) &&
564
- !contributions.queryKeys.has(property.key.start)) ||
565
- property.shorthand ||
566
- (!selectors.conditions.has(property.key.start) &&
567
- !variables.references.has(property.key.start) &&
568
- property.key.type !== 'Identifier' &&
569
- (property.key.type !== 'Literal' ||
570
- typeof property.key.value !== 'string'))) {
571
- report('unsupported_syntax', (() => {
572
- const key = property.type === 'Property' && property.computed
573
- ? Expression.unwrap(property.key)
574
- : undefined;
575
- // Template keys with an & target are selectors outside their group.
576
- return key?.type === 'TemplateLiteral' &&
577
- key.quasis.some((quasi) => quasi.value.raw.includes('&'))
578
- ? 'Template selector keys require a selectors object.'
579
- : 'Only explicit literal properties are supported; spreads, computed keys, shorthand, and methods are not evaluated.';
580
- })(), property);
581
- continue;
582
- }
583
- const key = variables.references.get(property.key.start)?.reference.name ??
584
- selectors.conditions.get(property.key.start) ??
585
- contributions.queryKeys.get(property.key.start) ??
586
- (property.key.type === 'Identifier'
587
- ? property.key.name
588
- : property.key.type === 'Literal'
589
- ? String(property.key.value)
590
- : '');
591
- if (Object.hasOwn(values, key)) {
592
- report('unsupported_syntax', 'Duplicate properties are not supported in source definitions yet.', property);
593
- continue;
594
- }
595
- if ((key === 'targets' || target !== -1) &&
596
- staticData.absent(property.value))
597
- continue;
598
- if (key === 'targets' || prefix.at(-1) === 'targets') {
599
- const input = Expression.unwrap(property.value);
600
- if (input.type !== 'ObjectExpression') {
601
- report('unsupported_syntax', 'Target branches require static declaration objects.', input);
602
- continue;
603
- }
604
- values[key] = object(input, [...prefix, key]);
605
- continue;
606
- }
607
- if (target !== -1 && prefix[target + 1] !== 'web') {
608
- function nativeValue(input, depth = 0) {
609
- const node = Expression.unwrap(input);
610
- if (depth > 64) {
611
- report('unsupported_syntax', 'Native value nesting exceeds 64 levels.', node);
612
- return undefined;
613
- }
614
- if (node.type === 'ObjectExpression')
615
- return object(node, [...prefix, key]);
616
- if (node.type === 'ArrayExpression')
617
- return node.elements.map((entry) => {
618
- if (!entry || entry.type === 'SpreadElement') {
619
- report('unsupported_syntax', 'Native arrays require dense static entries.', node);
620
- return undefined;
621
- }
622
- return nativeValue(entry, depth + 1);
623
- });
624
- if (node.type === 'Literal' &&
625
- (node.value === null ||
626
- ['boolean', 'number', 'string'].includes(typeof node.value)))
627
- return node.value;
628
- if (node.type === 'UnaryExpression' &&
629
- ['+', '-'].includes(node.operator) &&
630
- node.argument.type === 'Literal' &&
631
- typeof node.argument.value === 'number')
632
- return (node.operator === '-' ? -1 : 1) * node.argument.value;
633
- if (node.type === 'TemplateLiteral') {
634
- const value = Expression.template(node);
635
- if (typeof value === 'string')
636
- return value;
637
- }
638
- report('unsupported_syntax', 'Native branches require static literal values.', node);
639
- return undefined;
640
- }
641
- values[key] = nativeValue(property.value);
642
- continue;
643
- }
644
- if (Condition.is(key)) {
645
- conditionKeys.set(JSON.stringify([name, ...prefix, key]), property.key);
646
- const input = Expression.unwrap(property.value);
647
- if (input.type !== 'ObjectExpression') {
648
- report('unsupported_syntax', 'Conditions require literal declaration objects.', input);
649
- continue;
650
- }
651
- locations.push({
652
- source: options.moduleId,
653
- start: property.start,
654
- end: property.end,
655
- path: [name, ...prefix, key],
656
- });
657
- values[key] = object(input, [...prefix, key]);
658
- continue;
659
- }
660
- const targets = themes?.styles.get(call.start)?.theme[Token.definition]
661
- .contract.shorthands?.[key] ?? [key];
662
- function value(node, path) {
663
- const unwrapped = Expression.unwrap(node);
664
- const token = variables.references.get(unwrapped.start) ??
665
- themes?.tokens.get(unwrapped.start);
666
- const reference = localSlot(node) ??
667
- (token && token.end === unwrapped.end ? token.reference : undefined);
668
- if (dynamicValues &&
669
- reference &&
670
- Object.values(dynamicValues.slots).includes(reference) &&
671
- path.length > depth) {
672
- report('unsupported_syntax', 'Dynamic fallback entries are not supported.', node);
673
- return undefined;
674
- }
675
- node = Expression.unwrap(node);
676
- const animation = contributions.references.get(node.start);
677
- if (animation) {
678
- const kind = contributions.kinds.get(animation);
679
- if (kind &&
680
- targets.some((target) => !RuleReference.accepts(kind, target))) {
681
- report('unsupported_syntax', 'Named stylesheet reference is incompatible with this property.', node);
682
- return undefined;
683
- }
684
- return animation;
685
- }
686
- const template = node.type === 'TemplateLiteral'
687
- ? Expression.template(node, 0, (expression, prefix) => {
688
- const animation = contributions.references.get(Expression.unwrap(expression).start);
689
- if (animation) {
690
- const kind = contributions.kinds.get(animation);
691
- if (kind &&
692
- targets.some((target) => !RuleReference.acceptsExpression(kind, target, prefix))) {
693
- report('unsupported_syntax', 'Named stylesheet reference is incompatible with this property.', expression);
694
- return undefined;
695
- }
696
- return animation;
697
- }
698
- const token = variables.references.get(expression.start) ??
699
- themes?.tokens.get(expression.start);
700
- const slot = localSlot(expression);
701
- if (slot) {
702
- if (path.length > depth) {
703
- report('unsupported_syntax', 'Dynamic fallback entries are not supported.', expression);
704
- return undefined;
705
- }
706
- return slot;
707
- }
708
- return token?.end === expression.end
709
- ? token.reference
710
- : undefined;
711
- })
712
- : undefined;
713
- if (Token.isExpression(template)) {
714
- for (const part of template.parts) {
715
- if (typeof part !== 'string' &&
716
- !(Binding.is(part)
717
- ? (dynamicValues !== undefined &&
718
- Object.values(dynamicValues.slots).includes(part)) ||
719
- targets.every((target) => Binding.accepts(part.type, target) ||
720
- (part.type === 'color' &&
721
- Expression.acceptsColor(template, target)))
722
- : targets.every((target) => Token.acceptsReference(part, target) ||
723
- (part.contract.variableSet &&
724
- Expression.acceptsVariables(template, target)) ||
725
- (part.group === 'color' &&
726
- Expression.acceptsColor(template, target))))) {
727
- report('unsupported_syntax', Binding.is(part)
728
- ? 'Variable domain is incompatible with this property.'
729
- : 'Theme variable domain is incompatible with this property.', node);
730
- return undefined;
731
- }
732
- }
733
- }
734
- if (reference &&
735
- Token.is(reference) &&
736
- !targets.every((target) => Token.acceptsReference(reference, target)) &&
737
- !targets.every((target) => dynamicValues?.accepts(reference, target))) {
738
- report('unsupported_syntax', 'Theme variable domain is incompatible with this property.', node);
739
- return undefined;
740
- }
741
- if (reference &&
742
- Binding.is(reference) &&
743
- !(dynamicValues &&
744
- Object.values(dynamicValues.slots).includes(reference) &&
745
- reference.type !== 'number') &&
746
- !targets.every((target) => Binding.accepts(reference.type, target) ||
747
- dynamicValues?.accepts(reference, target))) {
748
- report('unsupported_syntax', 'Variable domain is incompatible with this property.', node);
749
- return undefined;
750
- }
751
- let result;
752
- if (reference)
753
- result = reference;
754
- else if (template !== undefined)
755
- result = template;
756
- else if (node.type === 'Literal' &&
757
- (typeof node.value === 'string' || typeof node.value === 'number'))
758
- result = node.value;
759
- else if (node.type === 'UnaryExpression' &&
760
- (node.operator === '-' || node.operator === '+') &&
761
- node.argument.type === 'Literal' &&
762
- typeof node.argument.value === 'number')
763
- result =
764
- node.operator === '-' ? -node.argument.value : node.argument.value;
765
- else if (node.type === 'ArrayExpression' && path.length === depth) {
766
- result = node.elements.map((element, index) => {
767
- if (!element || element.type === 'SpreadElement') {
768
- report('unsupported_syntax', 'Fallback arrays require dense literal entries without spreads.', element ?? node);
769
- return undefined;
770
- }
771
- return value(element, [...path, String(index)]);
772
- });
773
- }
774
- else {
775
- report('unsupported_syntax', 'Expected a literal string or number; expressions are not evaluated.', node);
776
- return undefined;
777
- }
778
- locations.push({
779
- end: node.end,
780
- path,
781
- source: options.moduleId,
782
- start: node.start,
783
- });
784
- return result;
785
- }
786
- values[key] = value(property.value, [name, ...prefix, key]);
787
- }
788
- if (typeof values.typography === 'string') {
789
- const theme = themes?.styles.get(call.start)?.theme;
790
- const mappings = theme?.[Token.definition].contract.shorthands;
791
- const explicit = new Set(Object.keys(values).flatMap((key) => mappings?.[key] ?? [key]));
792
- const parsed = Value.parse(values.typography, 'fontFamily');
793
- const keys = Typography.keys(theme, parsed && !('invalid' in parsed) ? parsed.value : values.typography, explicit);
794
- const queries = keys.filter(Typography.condition).length;
795
- for (const property of properties) {
796
- if (property.type !== 'Property')
797
- continue;
798
- const key = property.key.type === 'Identifier'
799
- ? property.key.name
800
- : property.key.type === 'Literal'
801
- ? property.key.value
802
- : undefined;
803
- if (key === 'typography') {
804
- typography.set(property.start, keys.length - queries);
805
- if (queries)
806
- typographyQueries.set(property.start, queries);
807
- }
808
- }
809
- }
810
- return values;
811
- }
812
- // Each entry becomes an ordered declaration segment, so later entries win as authored declarations do.
813
- function compose(elements) {
814
- const parts = [];
815
- const properties = [];
816
- for (const element of elements) {
817
- const entry = element && element.type !== 'SpreadElement'
818
- ? Expression.unwrap(element)
819
- : undefined;
820
- if (entry?.type === 'ObjectExpression') {
821
- const values = object(entry);
822
- if (diagnostics.length !== before)
823
- continue;
824
- parts.push(define({ [name]: values }, { locations, vars: themes?.styles.get(call.start)?.theme }).styles[0]);
825
- properties.push(...entry.properties);
826
- continue;
827
- }
828
- const target = entry && selectors.compositions.get(entry.start);
829
- const local = target && 'type' in target
830
- ? calls.find((value) => value.start === target.start)
831
- : undefined;
832
- const packed = target && !('type' in target) ? target.style : undefined;
833
- const style = local
834
- ? styles.find((style) => style.name === local.name)
835
- : packed?.style;
836
- if (!style) {
837
- report('unsupported_syntax', 'Composition entries require literal objects or previously declared style definitions.', element ?? call);
838
- continue;
839
- }
840
- if (local?.recipe ||
841
- local?.slots ||
842
- packed?.dynamic ||
843
- (packed?.staticRecipe &&
844
- !(packed.staticRecipe.rules.length === 1 &&
845
- packed.staticRecipe.rules[0].value.styles.length === 1 &&
846
- packed.staticRecipe.rules[0].value.styles[0].name ===
847
- packed.style.name))) {
848
- report('unsupported_syntax', 'Composition entries cannot be variants or dynamic styles; apply them with cx.', entry);
849
- continue;
850
- }
851
- // Native tables select variable alternatives from one context per call.
852
- if (options.target === 'native' &&
853
- !context(local
854
- ? themes?.nativeContext(local.start, local.end)
855
- : packed?.nativeContext, themes?.nativeContext(call.start, call.end))) {
856
- report('unsupported_syntax', 'Native composition entries require the variable catalog of the composing style.', entry);
857
- continue;
858
- }
859
- // The composing configuration decides output for every copied entry.
860
- parts.push(Object.fromEntries(Object.entries(style).filter(([key]) => key !== 'composition' && key !== 'cssOutput')));
861
- if (local) {
862
- properties.push(...(bodies.get(local.start)?.properties ?? []));
863
- for (const [start, count] of local.typography ?? [])
864
- typography.set(start, count);
865
- for (const [start, count] of local.typographyQueries ?? [])
866
- typographyQueries.set(start, count);
867
- continue;
868
- }
869
- // Packed declarations have no authored source here, so they map to the entry.
870
- properties.push(...declarations(style).map((declaration) => ({
871
- type: 'Property',
872
- computed: false,
873
- kind: 'init',
874
- method: false,
875
- shorthand: false,
876
- start: entry.start,
877
- end: entry.end,
878
- key: {
879
- type: 'Literal',
880
- value: declaration.property,
881
- raw: JSON.stringify(declaration.property),
882
- start: entry.start,
883
- end: entry.end,
884
- },
885
- value: {
886
- type: 'Literal',
887
- value: '',
888
- raw: '""',
889
- start: entry.start,
890
- end: entry.end,
891
- },
892
- })));
893
- }
894
- return {
895
- body: {
896
- type: 'ObjectExpression',
897
- start: call.start,
898
- end: call.end,
899
- properties,
900
- },
901
- definition: {
902
- styles: [
903
- Object.freeze({
904
- name,
905
- declarations: Object.freeze([]),
906
- rules: Object.freeze(parts.map((style) => Object.freeze({ style }))),
907
- }),
908
- ],
909
- },
910
- };
911
- }
912
- const values = entries
913
- ? undefined
914
- : object(argument);
915
- if (diagnostics.length !== before)
916
- continue;
917
- try {
918
- const composite = entries && compose(entries);
919
- if (diagnostics.length !== before)
920
- continue;
921
- const definition = composite?.definition ??
922
- define({ [name]: values }, { locations, vars: themes?.styles.get(call.start)?.theme });
923
- const body = composite?.body ?? argument;
924
- bodies.set(call.start, body);
925
- function validate(style, path) {
926
- for (const declaration of style.declarations) {
927
- if (Token.is(declaration.value) &&
928
- declaration.value.contract.variableSet &&
929
- Literal.rule(declaration.property)?.kind === 'identifier' &&
930
- !Expression.acceptsIdentifier(declaration.value, declaration.property))
931
- report('invalid_literal', 'Variable value is incompatible with this property.', call);
932
- }
933
- if (style.targets?.web)
934
- validate(style.targets.web, [...path, 'targets', 'web']);
935
- for (const rule of style.rules ?? []) {
936
- if (rule.condition !== undefined) {
937
- const location = conditionKeys.get(JSON.stringify([...path, rule.condition])) ??
938
- call;
939
- try {
940
- AtRules.transform({
941
- filename: options.moduleId,
942
- code: Buffer.from(`.z{${rule.condition}{color:red;}}`),
943
- errorRecovery: false,
944
- });
945
- }
946
- catch (error) {
947
- report('unsupported_syntax', `Invalid selector or condition: ${error.message}`, location);
948
- }
949
- }
950
- validate(rule.style, rule.condition === undefined ? path : [...path, rule.condition]);
951
- }
952
- }
953
- for (const style of definition.styles)
954
- validate(style, [style.name]);
955
- if (diagnostics.length !== before)
956
- continue;
957
- const contract = themes?.styles.get(call.start)?.theme[Token.definition]
958
- .contract;
959
- const composition = contract?.composition;
960
- const cssOutput = contract?.cssOutput;
961
- styles.push(...definition.styles.map((style) => composition || cssOutput
962
- ? Object.freeze({
963
- ...style,
964
- ...(composition ? { composition } : {}),
965
- ...(cssOutput ? { cssOutput } : {}),
966
- })
967
- : style));
968
- const shorthands = themes?.styles.get(call.start)?.theme[Token.definition]
969
- .contract.shorthands;
970
- const retained = staticRecipe ?? dynamicRecipe;
971
- const targetRecipe = retained && {
972
- ...retained,
973
- rules: retained.rules.map(({ matches, value }, index) => ({
974
- matches,
975
- value: define({ [`${name}-${index}`]: object(value) }, { locations, vars: themes?.styles.get(call.start)?.theme }),
976
- })),
977
- };
978
- calls.push({
979
- ...(recipe ? { recipe, recipeTypes } : {}),
980
- ...(staticRecipe
981
- ? { staticRecipe: targetRecipe }
982
- : dynamicRecipe
983
- ? { dynamicRecipe: targetRecipe }
984
- : {}),
985
- ...(selectors.identities.has(call.start)
986
- ? { identity: selectors.identities.get(call.start) }
987
- : {}),
988
- ...(body !== (dynamic?.body ?? original) ? { body } : {}),
989
- ...(shorthands ? { shorthands } : {}),
990
- ...(typography.size ? { typography } : {}),
991
- ...(typographyQueries.size ? { typographyQueries } : {}),
992
- ...(themes?.styles.get(call.start)?.output
993
- ? { output: 'html' }
994
- : {}),
995
- ...(dynamic
996
- ? {
997
- slots: dynamic.slots,
998
- valuesType: options.source.slice(dynamic.type.start, dynamic.type.end),
999
- }
1000
- : {}),
1001
- ...(options.compiler === false
1002
- ? {
1003
- portable: (() => {
1004
- if (explicitId !== undefined)
1005
- return `z-style-${definitionId}`;
1006
- if (dynamic ||
1007
- recipe ||
1008
- entries?.length === 0 ||
1009
- (!definition.styles[0].declarations.length &&
1010
- !definition.styles[0].rules &&
1011
- !definition.styles[0].targets))
1012
- return undefined;
1013
- return Identity.style(definition.styles[0], cssNamespace);
1014
- })(),
1015
- }
1016
- : {}),
1017
- cssName,
1018
- cssNamespace,
1019
- end: call.end,
1020
- name,
1021
- start: call.start,
1022
- });
1023
- }
1024
- catch (error) {
1025
- if (!(error instanceof Style.InvalidError))
1026
- throw error;
1027
- for (const diagnostic of error.diagnostics)
1028
- diagnostics.push({
1029
- code: 'invalid_literal',
1030
- end: diagnostic.location?.end ?? call.end,
1031
- message: diagnostic.message,
1032
- source: options.moduleId,
1033
- start: diagnostic.location?.start ?? call.start,
1034
- });
1035
- }
1036
- }
1037
- try {
1038
- let compositionIndex = 0;
1039
- for (const entry of options.target === 'native'
1040
- ? []
1041
- : Compositions.collect({
1042
- calls,
1043
- identity: namespace,
1044
- links: options[Themes.context]?.links,
1045
- program,
1046
- scopes: themes?.scopeApplications,
1047
- source: options.source,
1048
- styles,
1049
- })) {
1050
- const authored = authoredNames.get(entry.call.start);
1051
- const name = authored && authored !== 'style' ? authored : 'composition';
1052
- const cssName = `${name}-${compositionIndex++}-${entry.call.cssName ?? 'style'}`;
1053
- calls.push(...(entry.cases ?? []).map((value, index) => ({
1054
- ...value.call,
1055
- cssName: `${cssName}-${index}`,
1056
- })), { ...entry.call, cssName });
1057
- styles.push(...(entry.cases ?? []).map((entry) => entry.style), entry.style);
1058
- }
1059
- }
1060
- catch (error) {
1061
- if (!(error instanceof Themes.InvalidError))
1062
- throw error;
1063
- report('unsupported_syntax', error.message, error);
1064
- }
1065
- if (themes && !diagnostics.length)
1066
- for (const [start, token] of themes.tokens) {
1067
- if (!staticData.used.has(start) &&
1068
- !themes.staticTokens.some((node) => node.start === start) &&
1069
- ![...calls, ...contributions.calls].some((call) => start >= call.start && token.end <= call.end))
1070
- report('unsupported_syntax', 'Theme references require a compiled style declaration.', { start, end: token.end });
1071
- }
1072
- let contributionData = [];
1073
- const contributionStarts = [...variables.registrationStarts];
1074
- try {
1075
- for (const [index, registration] of variables.registrations.entries()) {
1076
- try {
1077
- const css = Css.compile({
1078
- styles: { styles: [] },
1079
- contributions: [registration],
1080
- }).css;
1081
- AtRules.transform({
1082
- filename: options.moduleId,
1083
- code: new TextEncoder().encode(css),
1084
- errorRecovery: false,
1085
- });
1086
- }
1087
- catch (error) {
1088
- throw new Themes.InvalidError(error.message, variables.registrationLocations[index]);
1089
- }
1090
- }
1091
- contributionData = [
1092
- ...variables.registrations,
1093
- ...Contributions.extract(contributions, themes?.tokens ?? new Map(), contributionStarts, (node) => staticData.resolve(node, staticCalls)),
1094
- ...(themes?.calls ?? []).flatMap((call) => call.options?.layers
1095
- ? [
1096
- {
1097
- kind: 'layers',
1098
- names: call.options.layers,
1099
- },
1100
- ]
1101
- : []),
1102
- ];
1103
- if (contributionData.length) {
1104
- const rendered = Css.compile({
1105
- styles: { styles: [] },
1106
- contributions: contributionData,
1107
- vars: themes?.themes,
1108
- }).css;
1109
- AtRules.transform({
1110
- filename: options.moduleId,
1111
- code: new TextEncoder().encode(rendered),
1112
- errorRecovery: false,
1113
- ...(!options[Themes.context]
1114
- ? {
1115
- visitor: {
1116
- Rule(rule) {
1117
- if (rule.type === 'import' &&
1118
- rule.value.url &&
1119
- !/^(?:\/|[?#]|[a-z][a-z\d+.-]*:)/i.test(rule.value.url))
1120
- throw new Error('Relative contribution assets require Graph.compile and a relocation host.');
1121
- },
1122
- Url(url) {
1123
- if (url.url &&
1124
- !/^(?:\/|[?#]|[a-z][a-z\d+.-]*:)/i.test(url.url))
1125
- throw new Error('Relative contribution assets require Graph.compile and a relocation host.');
1126
- },
1127
- },
1128
- }
1129
- : {}),
1130
- });
1131
- }
1132
- }
1133
- catch (error) {
1134
- report('unsupported_syntax', error.message, error instanceof Themes.InvalidError ? error : contributions.calls[0]);
1135
- }
1136
- for (const token of themes?.staticTokens ?? [])
1137
- if (!staticData.used.has(Expression.unwrap(token).start))
1138
- report('unsupported_syntax', 'Token references must be direct property values in bound theme style calls.', token);
1139
- if (diagnostics.length)
1140
- throw new ExtractError(diagnostics);
1141
- function exportedStyle(link) {
1142
- const call = calls.find((call) => call.identity === link.binding);
1143
- const style = call && styles.find((style) => style.name === call.name);
1144
- return {
1145
- ...link,
1146
- ...(call && style
1147
- ? {
1148
- style: PackedStyles.create({
1149
- ...call,
1150
- nativeContext: themes?.nativeContext(call.start, call.end),
1151
- }, style),
1152
- }
1153
- : {}),
1154
- ...(link.members
1155
- ? {
1156
- members: Object.fromEntries(Object.entries(link.members).map(([name, member]) => [
1157
- name,
1158
- exportedStyle(member),
1159
- ])),
1160
- }
1161
- : {}),
1162
- };
1163
- }
1164
- const callsByName = new Map(calls.map((call) => [call.name, call]));
1165
- const definition = {
1166
- styles: Object.freeze(styles),
1167
- [ClassName.labels]: Object.freeze(Object.fromEntries(styles.map((style) => {
1168
- let name = style.name;
1169
- let call = callsByName.get(name);
1170
- while (!call && name.includes('-')) {
1171
- name = name.slice(0, name.lastIndexOf('-'));
1172
- call = callsByName.get(name);
1173
- }
1174
- return [
1175
- style.name,
1176
- {
1177
- name: call?.cssName
1178
- ? call.cssName + style.name.slice(call.name.length)
1179
- : style.name,
1180
- namespace: call?.cssNamespace,
1181
- },
1182
- ];
1183
- }))),
1184
- };
1185
- Object.defineProperty(definition, ClassName.labels, { enumerable: false });
1186
- const selections = options.target === 'native' ? themes?.selectionUses : themes?.selections;
1187
- return Object.freeze({
1188
- namespaces: contributionData.filter((value) => value.kind === 'namespace'),
1189
- ...(contributionData.length
1190
- ? { contributions: contributionData, contributionStarts }
1191
- : {}),
1192
- ...(contributions.calls.length
1193
- ? { contributionCalls: contributions.calls }
1194
- : {}),
1195
- ...(options[Themes.context]
1196
- ? {
1197
- themeExports: Object.freeze({
1198
- ...themes?.exports,
1199
- ...Object.fromEntries(Object.entries(selectors.exports).map(([name, link]) => [
1200
- name,
1201
- exportedStyle(link),
1202
- ])),
1203
- ...contributions.exports,
1204
- ...variables.exports,
1205
- }),
1206
- }
1207
- : {}),
1208
- calls: Object.freeze(calls
1209
- .sort((a, b) => a.start - b.start)
1210
- .map((call) => {
1211
- const nativeContext = options.target === 'native'
1212
- ? themes?.nativeContext(call.start, call.end)
1213
- : undefined;
1214
- return Object.freeze(nativeContext ? { ...call, nativeContext } : call);
1215
- })),
1216
- styles: Object.freeze(definition),
1217
- ...(variables.calls.length
1218
- ? { variableCalls: Object.freeze(variables.calls) }
1219
- : {}),
1220
- themeAliases: Object.freeze(themes?.aliases ?? []),
1221
- ...(themes?.appearances.size
1222
- ? { themeAppearances: Object.freeze([...themes.appearances]) }
1223
- : {}),
1224
- ...(themes?.scripts.size
1225
- ? { themeScripts: Object.freeze([...themes.scripts]) }
1226
- : {}),
1227
- ...(selections?.size
1228
- ? { themeSelections: Object.freeze([...selections]) }
1229
- : {}),
1230
- themeCalls: Object.freeze(themes?.calls ?? []),
1231
- ...(themes?.staticTokens.length
1232
- ? {
1233
- staticThemeReferences: Object.freeze((themes?.staticTokens ?? []).map((node) => ({
1234
- start: node.start,
1235
- end: node.end,
1236
- value: ThemeValues.create().serialize(themes.tokens.get(node.start).reference),
1237
- }))),
1238
- }
1239
- : {}),
1240
- themeReferences: Object.freeze(themes?.references ?? []),
1241
- vars: themes?.themes ?? Object.freeze({}),
1242
- ...(themes?.varsReads.length
1243
- ? { nativeVars: Object.freeze(themes.varsReads) }
1244
- : {}),
1245
- });
16
+ return Wire.decode(Addon.load().call('source.extract', JSON.stringify({
17
+ compiler: options.compiler,
18
+ moduleId: options.moduleId,
19
+ source: options.source,
20
+ target: options.target,
21
+ })), { compiler: options.compiler });
1246
22
  }
1247
23
  /** Aggregated source diagnostics; no partial result is returned. */
1248
24
  export class ExtractError extends Error {
@@ -1259,37 +35,4 @@ export class ExtractError extends Error {
1259
35
  /** Stable namespaced error identifier. */
1260
36
  name = 'Source.ExtractError';
1261
37
  }
1262
- /** Accepts an entry context that the composing call selects identically. */
1263
- function context(entry, composite) {
1264
- if (!entry || entry === composite)
1265
- return true;
1266
- if (!composite || entry.defaultVars !== composite.defaultVars)
1267
- return false;
1268
- const names = Object.keys(entry.vars);
1269
- return (names.length === Object.keys(composite.vars).length &&
1270
- names.every((name) => {
1271
- const left = entry.vars[name]?.[Token.definition].contract;
1272
- const right = composite.vars[name]?.[Token.definition].contract;
1273
- return (!!left &&
1274
- !!right &&
1275
- (left === right ||
1276
- (left[Token.identity] !== undefined &&
1277
- left[Token.identity] === right[Token.identity])));
1278
- }));
1279
- }
1280
- /** Lists declarations in emitted order, through conditions and segments. */
1281
- function declarations(style) {
1282
- return style.rules
1283
- ? style.rules.flatMap((rule) => declarations(rule.style))
1284
- : style.declarations;
1285
- }
1286
- function identity(value) {
1287
- let first = 2166136261;
1288
- let second = 2246822507;
1289
- for (let index = 0; index < value.length; index++) {
1290
- first = Math.imul(first ^ value.charCodeAt(index), 16777619);
1291
- second = Math.imul(second ^ value.charCodeAt(index), 3266489909);
1292
- }
1293
- return `${(first >>> 0).toString(36)}${(second >>> 0).toString(36)}`;
1294
- }
1295
38
  //# sourceMappingURL=Source.js.map