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