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,49 +2,20 @@
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 type * as Ast from '@oxc-project/types'
8
- import * as AtRules from './internal/AtRules.js'
9
- import * as Binding from '../internal/Binding.js'
10
- import * as Condition from '../internal/Condition.js'
11
- import type * as Composition from '../runtime/Composition.js'
12
- import * as Compositions from './internal/Compositions.js'
13
- import * as Contributions from './internal/Contributions.js'
14
- import * as Css from '../web/Css.js'
15
- import * as Dynamic from './internal/Dynamic.js'
16
- import * as Expression from './internal/Expression.js'
17
- import * as Selectors from './internal/Selectors.js'
18
- import type * as Namespace from '../web/internal/Namespace.js'
19
- import * as Syntax from './internal/Syntax.js'
20
- import * as RuleReference from '../internal/RuleReference.js'
21
- import type * as Recipe from '../runtime/Recipe.js'
5
+ import * as Addon from '../internal/Addon.js'
6
+ import type * as Binding from '../internal/Binding.js'
22
7
  import type * as StaticRecipe from '../internal/Recipe.js'
23
- import type * as RecipePayloads from './internal/RecipePayloads.js'
24
- import * as Recipes from './internal/Recipes.js'
25
- import * as PackedStyles from './internal/PackedStyles.js'
26
- import * as Scope from './internal/Scope.js'
8
+ import type * as RuleReference from '../internal/RuleReference.js'
27
9
  import type * as Shorthands from '../internal/Shorthands.js'
28
- import * as Static from './internal/Static.js'
29
- import * as Style from '../Style.js'
30
10
  import type * as Theme from '../internal/Theme.js'
31
- import * as Themes from './internal/Themes.js'
32
- import * as ThemeValues from '../web/internal/Themes.js'
33
- import * as Token from '../internal/Token.js'
34
- import * as Literal from '../internal/Literal.js'
35
- import * as Names from './internal/Names.js'
36
- import * as ClassName from '../web/internal/ClassName.js'
37
- import * as Typography from '../internal/Typography.js'
38
- import * as Value from '../internal/Value.js'
39
- import * as Vars from './internal/Vars.js'
40
- import * as Walker from 'oxc-walker'
41
-
42
- // JavaScript extraction supplies untyped values. Keep structural checks without
43
- // asserting that those values already satisfy the TypeScript authoring contract.
44
- const define = Style.define as unknown as (
45
- styles: Record<string, unknown>,
46
- options: Style.define.Options,
47
- ) => Style.Definition
11
+ import type * as Composition from '../runtime/Composition.js'
12
+ import type * as Recipe from '../runtime/Recipe.js'
13
+ import type * as Style from '../Style.js'
14
+ import type * as Vars from '../Vars.js'
15
+ import type * as Css from '../web/Css.js'
16
+ import type { cssFunction } from '../web/cssFunction.js'
17
+ import type * as Namespace from '../web/internal/Namespace.js'
18
+ import * as Wire from './internal/Wire.js'
48
19
 
49
20
  /** A direct definition call available for a later source rewriter. */
50
21
  export type Call = {
@@ -102,8 +73,6 @@ export type Call = {
102
73
  | undefined
103
74
  /** Stable selector identity retained independently of declaration deduplication. */
104
75
  readonly identity?: string | undefined
105
- /** Expanded immutable source data retained for declaration mapping. */
106
- readonly body?: Ast.ObjectExpression | undefined
107
76
  /** Alias targets retained for declaration source locations. */
108
77
  readonly shorthands?: Shorthands.Map | undefined
109
78
  /** Emitted typography field counts keyed by authored property offsets. */
@@ -113,7 +82,7 @@ export type Call = {
113
82
  /** Native HTML attribute output selected by the bound configuration. */
114
83
  readonly output?: 'html' | undefined
115
84
  /** Typed runtime slots for callback definitions. */
116
- readonly slots?: Dynamic.Slots | undefined
85
+ readonly slots?: Readonly<Record<string, Binding.Reference>> | undefined
117
86
  /** Authored scalar input type retained in packed declarations. */
118
87
  readonly valuesType?: string | undefined
119
88
  /** Exclusive UTF-16 offset of the complete call. */
@@ -142,1528 +111,135 @@ export type Diagnostic = {
142
111
  readonly start: number
143
112
  }
144
113
 
114
+ /** A static stylesheet effect call replaced by its compiled data. */
115
+ type ContributionCall = {
116
+ /** Exported binding offset of a named factory result. */
117
+ readonly binding?: number | undefined
118
+ /** Exclusive UTF-16 offset of the complete call. */
119
+ readonly end: number
120
+ /** Whether the factory result is exported. */
121
+ readonly exported?: boolean | undefined
122
+ /** CSS function signature of a `cssFunction` call. */
123
+ readonly function?: ThemeCall['function']
124
+ /** Stylesheet factory that created the effect. */
125
+ readonly kind: string
126
+ /** Authored binding of a named factory result. */
127
+ readonly name?: string | undefined
128
+ /** Inclusive UTF-16 offset of the complete call. */
129
+ readonly start: number
130
+ }
131
+
132
+ /** Local bound-authoring initializer replaced while retaining its inferred type. */
133
+ type ThemeAlias = ThemeCall & {
134
+ /** Ordered authoring members replaced in a shared destructuring initializer. */
135
+ readonly bindings?: readonly ('style' | 'variants')[] | undefined
136
+ /** Whether the initializer supplies destructured authoring bindings. */
137
+ readonly destructured: boolean
138
+ /** Retains an immutable theme/configuration alias value with an explicit type. */
139
+ readonly retained?: boolean | undefined
140
+ }
141
+
142
+ /** Theme factory span and generated scope key. */
143
+ type ThemeCall = {
144
+ /** Whether the compiled configuration supplies root controls. */
145
+ readonly appearance?: boolean | undefined
146
+ /** Legacy packed catalog exposes members but lacks callable-selection capability. */
147
+ readonly catalogOnly?: boolean | undefined
148
+ readonly directVariables?: boolean | undefined
149
+ /** Exclusive source offset. */
150
+ readonly end: number
151
+ /** Static CSS function signature shared during extraction and packed serialization. */
152
+ readonly function?:
153
+ | {
154
+ parameters: readonly cssFunction.Parameter[]
155
+ returns: cssFunction.Syntax
156
+ }
157
+ | undefined
158
+ /** Bound root initialization script export. */
159
+ readonly initialization?: boolean | undefined
160
+ /** JSON-encoded member path tuples and their compiled scope keys. */
161
+ readonly members?: Readonly<Record<string, string>> | undefined
162
+ /** Stable module/binding scope key. */
163
+ readonly name: string
164
+ /** Whether native defineConfig retains a typed React Provider. */
165
+ readonly nativeProvider?: boolean | undefined
166
+ /** Validated inline configuration options retained for packed declarations. */
167
+ readonly options?: Readonly<Record<string, unknown>> | undefined
168
+ readonly output?: 'html' | undefined
169
+ /** Whether this bound authoring alias declares recipes. */
170
+ readonly recipe?: boolean | undefined
171
+ /** Named stylesheet identity domain. */
172
+ readonly reference?: RuleReference.Kind | undefined
173
+ /** Bound root controls export. */
174
+ readonly root?: boolean | undefined
175
+ /** Whether the compiled configuration supplies initialization. */
176
+ readonly script?: boolean | undefined
177
+ /** Config helper represented by this linked binding. */
178
+ readonly selection?: boolean | undefined
179
+ /** Inclusive source offset. */
180
+ readonly start: number
181
+ /** Literal token contract retained in rewritten TypeScript type assertions. */
182
+ readonly tokenType: string
183
+ /** Complete authoring type retained for configuration declarations. */
184
+ readonly type?: string | undefined
185
+ readonly variableConfig?: boolean | undefined
186
+ readonly variableMappings?: Vars.Mappings | false | undefined
187
+ /** Canonical defining module for multi-entry variable contracts. */
188
+ readonly variableOwner?: string | undefined
189
+ /** Portable explicit variable references. */
190
+ readonly variables?: Readonly<Record<string, Binding.Reference>> | undefined
191
+ readonly variableSet?: boolean | undefined
192
+ }
193
+
194
+ /** An explicit variable contract replaced by fixed slot data. */
195
+ type VariableCall = {
196
+ /** Exclusive source offset. */
197
+ readonly end: number
198
+ /** Whether the consumer supplied a portable variable identity. */
199
+ readonly explicit?: boolean | undefined
200
+ /** Fixed scalar reference retained in portable metadata. */
201
+ readonly slots: Readonly<Record<string, Binding.Reference>>
202
+ /** Inclusive source offset. */
203
+ readonly start: number
204
+ }
205
+
206
+ /** A readonly variable argument consumed by a native React hook. */
207
+ type VarsRead = {
208
+ /** Owning configuration fallback. */
209
+ readonly defaultVars: string
210
+ /** Exclusive source offset. */
211
+ readonly end: number
212
+ /** Stable configuration identity for graph-owned native profiles. */
213
+ readonly owner: string
214
+ /** Inclusive source offset. */
215
+ readonly start: number
216
+ /** A standalone definition that does not select a named catalog entry. */
217
+ readonly unnamed: boolean
218
+ /** Complete compatible variable alternatives. */
219
+ readonly vars: Readonly<Record<string, Theme.Definition>>
220
+ }
221
+
145
222
  /**
146
223
  * Extracts direct style calls and local Theme definitions imported from zyzz.
147
- * Parses TypeScript and JSX without reading files, loading config, or evaluating source.
224
+ * Parses TypeScript and JSX in the Rust compiler without reading files, loading config, or
225
+ * evaluating source. The returned calls carry no syntax trees.
148
226
  * @param options - Source text and a portable package-relative module identity.
149
227
  * @returns Frozen style/theme definitions and rewrite spans. Source text is unchanged.
150
228
  * @throws {ExtractError} For syntax errors, unsupported imported references, or invalid literals.
151
229
  */
152
230
  export function extract(options: extract.Options): extract.ReturnType {
153
- const calls: Call[] = []
154
- const diagnostics: Diagnostic[] = []
155
- const pending: Ast.CallExpression[] = []
156
- const recipes = new Set<number>()
157
- const styles: Style.NamedStyle[] = []
158
-
159
- function report(
160
- code: Diagnostic['code'],
161
- message: string,
162
- node?: Pick<Ast.Node, 'end' | 'start'>,
163
- ) {
164
- diagnostics.push({
165
- code,
166
- end: node?.end ?? 0,
167
- message,
168
- source: options.moduleId,
169
- start: node?.start ?? 0,
170
- })
171
- }
172
-
173
- if (
174
- !options.moduleId ||
175
- options.moduleId.includes('\\') ||
176
- options.moduleId.includes(':') ||
177
- options.moduleId
178
- .split('/')
179
- .some((part) => !part || part === '.' || part === '..')
180
- ) {
181
- report(
182
- 'invalid_module',
183
- 'Expected a portable package-relative module ID without absolute paths, backslashes, or traversal segments.',
184
- )
185
- throw new ExtractError(diagnostics)
186
- }
187
-
188
- const namespace = identity(options.moduleId)
189
- const parsed = options[Themes.context]?.parsed ?? Syntax.parse(options)
190
- for (const node of parsed.program.body) {
191
- if (node.type !== 'ImportDeclaration' || node.source.value !== 'zyzz')
192
- continue
193
- for (const specifier of node.specifiers) {
194
- if (specifier.type !== 'ImportSpecifier') continue
195
- const name =
196
- specifier.imported.type === 'Identifier'
197
- ? specifier.imported.name
198
- : specifier.imported.value
199
- if (name === 'Theme' || name === 'Variables')
200
- throw new ExtractError([
201
- {
202
- code: 'unsupported_syntax',
203
- message: `Import Vars instead of ${name}.`,
204
- source: options.moduleId,
205
- start: specifier.start,
206
- end: specifier.end,
207
- },
208
- ])
209
- }
210
- }
211
-
212
- if (parsed.errors.length) {
213
- for (const error of parsed.errors) {
214
- const span = error.labels[0]
215
-
216
- report('syntax_error', error.message, span)
217
- }
218
-
219
- throw new ExtractError(diagnostics)
220
- }
221
-
222
- const program = parsed.program
223
- const authoredNames = Names.collect(program)
224
- const scopeTracker = new Scope.Tracker({ preserveExitedScopes: true })
225
-
226
- Walker.walk(program, { scopeTracker })
227
- scopeTracker.freeze()
228
-
229
- const staticData = Static.create(
230
- program,
231
- scopeTracker,
232
- options[Themes.context]?.constants,
233
- )
234
-
235
- const contributions = (() => {
236
- try {
237
- return Contributions.scan(
238
- program,
239
- scopeTracker,
240
- namespace,
241
- options[Themes.context]?.links,
242
- options[Themes.context]?.factories,
243
- )
244
- } catch (error) {
245
- if (!(error instanceof Themes.InvalidError)) throw error
246
-
247
- report('unsupported_syntax', error.message, error)
248
- throw new ExtractError(diagnostics)
249
- }
250
- })()
251
-
252
- const variables = (() => {
253
- try {
254
- return Vars.collect(
255
- program,
256
- namespace,
257
- scopeTracker,
258
- options[Themes.context]?.links,
259
- options.moduleId,
260
- )
261
- } catch (error) {
262
- if (!(error instanceof Themes.InvalidError)) throw error
263
-
264
- report('unsupported_syntax', error.message, error)
265
- throw new ExtractError(diagnostics)
266
- }
267
- })()
268
-
269
- const themes = (() => {
270
- try {
271
- return Themes.collect(program, {
272
- native: options.target === 'native',
273
- staticBindings: staticData.bindings,
274
- namespace: `src-${Identity.label(
275
- options.moduleId
276
- .split('/')
277
- .at(-1)!
278
- .replace(/\.[cm]?[jt]sx?$/, ''),
279
- )}-${Identity.compact(options.moduleId)}`,
280
- contributionCalls: new Set(
281
- contributions.calls.map((call) => call.start),
282
- ),
283
- linked: options[Themes.context] !== undefined,
284
- links: options[Themes.context]?.links,
285
- })
286
- } catch (error) {
287
- if (!(error instanceof Themes.InvalidError)) throw error
288
-
289
- report('unsupported_syntax', error.message, error)
290
- throw new ExtractError(diagnostics)
291
- }
292
- })()
293
-
294
- const ancestors: Ast.Node[] = []
295
- const typeAncestors = new Set<Ast.Node>()
296
- const typeNodes = new Set([
297
- 'TSInterfaceDeclaration',
298
- 'TSTypeAliasDeclaration',
299
- 'TSTypeAnnotation',
300
- 'TSTypeParameterDeclaration',
301
- 'TSTypeParameterInstantiation',
302
- 'TSTypeQuery',
303
- ])
304
-
305
- Walker.walk(program, {
306
- enter(node, parent) {
307
- const declaration = staticData.visitor.enter(node, parent)
308
- ancestors.push(node)
309
- if (
310
- (parent &&
311
- 'typeAnnotation' in parent &&
312
- parent.typeAnnotation === node) ||
313
- typeNodes.has(node.type) ||
314
- (node.type === 'ExportNamedDeclaration' &&
315
- (node.source !== null || node.exportKind === 'type')) ||
316
- (node.type === 'ExportSpecifier' && node.exportKind === 'type')
317
- )
318
- typeAncestors.add(node)
319
-
320
- if (
321
- (node.type !== 'Identifier' && node.type !== 'JSXIdentifier') ||
322
- !parent ||
323
- (node.type === 'Identifier'
324
- ? declaration === undefined
325
- : !Walker.isReferenceIdentifier(node, parent))
326
- )
327
- return
328
-
329
- // Both passes visit identical scopes; skipping type subtrees changes scope IDs.
330
- if (typeAncestors.size) return
331
-
332
- const binding =
333
- node.type === 'Identifier'
334
- ? (declaration ?? null)
335
- : scopeTracker.getDeclaration(node.name)
336
-
337
- contributions.read(node, parent, binding)
338
-
339
- try {
340
- if (variables.reference(node, parent, ancestors, binding)) return
341
- } catch (error) {
342
- if (!(error instanceof Themes.InvalidError)) throw error
343
-
344
- report('unsupported_syntax', error.message, error)
345
-
346
- return
347
- }
348
-
349
- if (themes)
350
- try {
351
- if (
352
- themes.reference(
353
- node,
354
- parent,
355
- ancestors,
356
- binding,
357
- (name) => scopeTracker.getDeclaration(name) ?? null,
358
- )
359
- )
360
- return
361
- } catch (error) {
362
- if (!(error instanceof Themes.InvalidError)) throw error
363
-
364
- report('unsupported_syntax', error.message, error)
365
-
366
- return
367
- }
368
-
369
- if (
370
- binding?.type !== 'Import' ||
371
- binding.importNode.source.value !== 'zyzz' ||
372
- binding.importNode.importKind === 'type'
373
- )
374
- return
375
-
376
- const specifier = binding.node
377
-
378
- if (specifier.type === 'ImportNamespaceSpecifier') {
379
- if (parent.type === 'MemberExpression' && parent.object === node) {
380
- const name = (() => {
381
- if (parent.property.type === 'Identifier' && !parent.computed) {
382
- return parent.property.name
383
- }
384
-
385
- if (parent.property.type === 'Literal') {
386
- return parent.property.value
387
- }
388
-
389
- return undefined
390
- })()
391
-
392
- if (
393
- name === 'Config' ||
394
- name === 'cx' ||
395
- name === 'defineConfig' ||
396
- name === 'defineVars' ||
397
- name === 'extendVars' ||
398
- name === 'style' ||
399
- name === 'Theme' ||
400
- name === 'Vars' ||
401
- name === 'variable' ||
402
- name === 'variants'
403
- )
404
- report(
405
- 'unsupported_syntax',
406
- `Import ${name} by name; namespace authoring calls are not supported yet.`,
407
- parent,
408
- )
409
- }
410
-
411
- return
412
- }
413
-
414
- if (
415
- specifier.type !== 'ImportSpecifier' ||
416
- specifier.importKind === 'type' ||
417
- !['style', 'variants'].includes(
418
- specifier.imported.type === 'Identifier'
419
- ? specifier.imported.name
420
- : specifier.imported.value,
421
- )
422
- )
423
- return
424
-
425
- // Follow only assignment targets; computed keys and default values are reads.
426
- let target: Ast.Node = node
427
- let write: Ast.Node | undefined
428
-
429
- for (let index = ancestors.length - 2; index >= 0; index--) {
430
- const ancestor = ancestors[index]!
431
-
432
- if (
433
- (ancestor.type === 'AssignmentExpression' &&
434
- ancestor.left === target) ||
435
- (ancestor.type === 'UpdateExpression' &&
436
- ancestor.argument === target) ||
437
- ((ancestor.type === 'ForInStatement' ||
438
- ancestor.type === 'ForOfStatement') &&
439
- ancestor.left === target)
440
- ) {
441
- write = ancestor
442
- break
443
- }
444
-
445
- if (
446
- (ancestor.type === 'Property' && ancestor.value === target) ||
447
- ancestor.type === 'ObjectPattern' ||
448
- ancestor.type === 'ArrayPattern' ||
449
- (ancestor.type === 'RestElement' && ancestor.argument === target) ||
450
- (ancestor.type === 'AssignmentPattern' && ancestor.left === target)
451
- )
452
- target = ancestor
453
- else break
454
- }
455
-
456
- if (write)
457
- report(
458
- 'unsupported_syntax',
459
- 'Imported style bindings cannot be reassigned.',
460
- write,
461
- )
462
- else if (
463
- parent.type === 'CallExpression' &&
464
- parent.callee === node &&
465
- !parent.optional
466
- ) {
467
- pending.push(parent)
468
- if (
469
- (specifier.imported.type === 'Identifier'
470
- ? specifier.imported.name
471
- : specifier.imported.value) === 'variants'
472
- )
473
- recipes.add(parent.start)
474
- } else
475
- report(
476
- 'unsupported_syntax',
477
- 'Use a direct style call; aliases, re-exports, and indirect references are not supported yet.',
478
- node,
479
- )
480
- },
481
- leave(node) {
482
- ancestors.pop()
483
- typeAncestors.delete(node)
484
- staticData.visitor.leave()
485
- },
486
- scopeTracker,
487
- })
488
-
489
- Contributions.resolve(contributions)
490
-
491
- // Imports and reference lists can have a different order from authored calls.
492
- if (themes)
493
- for (const entry of themes.styles.values()) {
494
- pending.push(entry.call)
495
- if (entry.recipe) recipes.add(entry.call.start)
496
- }
497
-
498
- pending.sort((a, b) => a.start - b.start)
499
-
500
- const staticCalls = new Set([
501
- ...pending.map((call) => call.start),
502
- ...contributions.calls.map((call) => call.start),
503
- ])
504
- const opaque = new Set(variables.references.keys())
505
- const normalized = new Map<number, Ast.Node | Error>()
506
- const selectorKeys = new Set<number>()
507
- for (const call of pending) {
508
- if (!call.arguments[0]) continue
509
- try {
510
- const value = staticData.normalize(call.arguments[0], staticCalls, opaque)
511
- normalized.set(call.start, value)
512
- const body =
513
- value.type === 'ArrowFunctionExpression'
514
- ? staticData.normalize(value.body, staticCalls, opaque)
515
- : value
516
-
517
- Walker.walk(body, {
518
- enter(node) {
519
- if (
520
- node.type !== 'Property' ||
521
- node.computed ||
522
- node.value.type !== 'ObjectExpression' ||
523
- !(
524
- (node.key.type === 'Identifier' &&
525
- node.key.name === 'selectors') ||
526
- (node.key.type === 'Literal' && node.key.value === 'selectors')
527
- )
528
- )
529
- return
530
-
531
- for (const property of node.value.properties)
532
- if (property.type === 'Property')
533
- selectorKeys.add(property.key.start)
534
- },
535
- })
536
- } catch (error) {
537
- if (!(error instanceof Themes.InvalidError)) throw error
538
- normalized.set(call.start, error)
539
- }
540
- }
541
-
542
- for (const call of pending) {
543
- try {
544
- Identifiers.explicit(call)
545
- } catch (error) {
546
- report('unsupported_syntax', (error as Error).message, call)
547
- }
548
- }
549
- if (diagnostics.length) throw new ExtractError(diagnostics)
550
-
551
- const selectors = (() => {
552
- try {
553
- return Selectors.scan(
554
- program,
555
- scopeTracker,
556
- namespace,
557
- pending,
558
- options[Themes.context]?.links,
559
- selectorKeys,
560
- new Map(
561
- [...(themes?.styles ?? [])].flatMap(([start, context]) => {
562
- const id = context.theme[Token.definition].contract[Token.identity]
563
- return id?.startsWith('id-') ? [[start, id.slice(3)] as const] : []
564
- }),
565
- ),
566
- options.moduleId,
567
- )
568
- } catch (error) {
569
- if (!(error instanceof Themes.InvalidError)) throw error
570
-
571
- report('unsupported_syntax', error.message, error)
572
- throw new ExtractError(diagnostics)
573
- }
574
- })()
575
-
576
- const cssNameCounts = new Map<string, number>()
577
- for (const call of pending) {
578
- const name = authoredNames.get(call.start)!
579
- cssNameCounts.set(name, (cssNameCounts.get(name) ?? 0) + 1)
580
- }
581
- const cssNameIndices = new Map<string, number>()
582
- for (const [callIndex, call] of pending.entries()) {
583
- const explicitId = (() => {
584
- try {
585
- return Identifiers.explicit(call)
586
- } catch (error) {
587
- report('unsupported_syntax', (error as Error).message, call)
588
- return undefined
589
- }
590
- })()
591
- const contractIdentity = themes?.styles.get(call.start)?.theme[
592
- Token.definition
593
- ].contract[Token.identity]
594
- const cssNamespace = contractIdentity?.startsWith('id-')
595
- ? contractIdentity.slice(3)
596
- : undefined
597
- const authoredName = authoredNames.get(call.start)!
598
- const nameIndex = cssNameIndices.get(authoredName) ?? 0
599
- cssNameIndices.set(authoredName, nameIndex + 1)
600
- const cssName =
601
- explicitId !== undefined
602
- ? Identity.name(explicitId)
603
- : `${Identity.compact(options.moduleId).slice(-6)}-${
604
- authoredName === 'style'
605
- ? `style-${callIndex}`
606
- : cssNameCounts.get(authoredName)! > 1
607
- ? `${authoredName}-${nameIndex}`
608
- : authoredName
609
- }`
610
- const definitionId =
611
- explicitId === undefined
612
- ? `${cssNamespace ? `${cssNamespace}-` : ''}${cssName}`
613
- : `id-${cssNamespace ? `${cssNamespace}-` : ''}${Identity.requireId(explicitId, 'style').slice(3)}`
614
- let argument = call.arguments[0]
615
-
616
- if (call.arguments.length === 0)
617
- argument = {
618
- end: call.end - 1,
619
- properties: [],
620
- start: call.end - 1,
621
- type: 'ObjectExpression',
622
- }
623
-
624
- while (
625
- argument?.type === 'TSAsExpression' ||
626
- argument?.type === 'TSSatisfiesExpression'
627
- )
628
- argument = argument.expression
629
-
630
- const original = argument
631
-
632
- try {
633
- const value = normalized.get(call.start)
634
- if (value instanceof Error) throw value
635
- if (value) argument = value as Ast.Expression
636
- } catch (error) {
637
- if (!(error instanceof Themes.InvalidError)) throw error
638
-
639
- report('unsupported_syntax', error.message, error)
640
- continue
641
- }
642
-
643
- const diagnosticCount = diagnostics.length
644
-
645
- const dynamic = (() => {
646
- if (!argument) return undefined
647
-
648
- try {
649
- return Dynamic.read(argument, definitionId, staticData.type)
650
- } catch (error) {
651
- if (!(error instanceof Themes.InvalidError)) throw error
652
-
653
- report('unsupported_syntax', error.message, error)
654
-
655
- return undefined
656
- }
657
- })()
658
- if (diagnostics.length !== diagnosticCount) continue
659
-
660
- let dynamicValues: RecipePayloads.Bindings | undefined = dynamic
661
-
662
- function resolveDynamic(node: Ast.Node) {
663
- try {
664
- return dynamicValues?.resolve(node)
665
- } catch (error) {
666
- if (!(error instanceof Themes.InvalidError)) throw error
667
-
668
- report('unsupported_syntax', error.message, error)
669
-
670
- return undefined
671
- }
672
- }
673
-
674
- if (dynamic) {
675
- try {
676
- argument = staticData.normalize(
677
- dynamic.body,
678
- staticCalls,
679
- opaque,
680
- ) as Ast.Expression
681
- } catch (error) {
682
- if (!(error instanceof Themes.InvalidError)) throw error
683
-
684
- report('unsupported_syntax', error.message, error)
685
- continue
686
- }
687
- }
688
-
689
- if (call.arguments.length > 2 || argument?.type !== 'ObjectExpression') {
690
- report(
691
- 'unsupported_syntax',
692
- 'Expected one literal object or typed callback; spreads and referenced definitions are not supported.',
693
- call,
694
- )
695
- continue
696
- }
697
-
698
- const before = diagnostics.length
699
- let recipe: Recipe.Definition | undefined
700
- let recipeTypes: Call['recipeTypes']
701
- let staticRecipe: StaticRecipe.Definition<Ast.ObjectExpression> | undefined
702
- let dynamicRecipe: StaticRecipe.Definition<Ast.ObjectExpression> | undefined
703
- if (recipes.has(call.start)) {
704
- try {
705
- if (dynamic)
706
- throw new Themes.InvalidError(
707
- 'Recipes require static top-level objects.',
708
- original ?? call,
709
- )
710
- const expanded = Recipes.expand(argument, {
711
- identity: definitionId,
712
- normalize: (node) => staticData.normalize(node, staticCalls, opaque),
713
- queries: themes?.styles.get(call.start)?.theme[Token.definition]
714
- .queries,
715
- resolveType: staticData.type,
716
- source: options.source,
717
- })
718
- argument = expanded.body
719
- recipe = expanded.recipe
720
- staticRecipe = expanded.staticRecipe
721
- dynamicRecipe = expanded.dynamicRecipe
722
- recipeTypes = expanded.types
723
- dynamicValues = expanded.bindings
724
- } catch (error) {
725
- if (!(error instanceof Themes.InvalidError)) throw error
726
- report('unsupported_syntax', error.message, error)
727
- continue
728
- }
729
- }
730
- const name = `style-${namespace}-${call.start}`
731
- const locations: Style.SourceLocation[] = []
732
- const typography = new Map<number, number>()
733
- const typographyQueries = new Map<number, number>()
734
- const conditionKeys = new Map<string, Ast.Node>()
735
-
736
- function object(
737
- argument: Ast.ObjectExpression,
738
- prefix: readonly string[] = [],
739
- ): Record<string, unknown> {
740
- const values: Record<string, unknown> = Object.create(null)
741
- const target = prefix.lastIndexOf('targets')
742
- if (target !== -1 && prefix.length > 64) {
743
- report(
744
- 'unsupported_syntax',
745
- 'Target nesting exceeds 64 levels.',
746
- argument,
747
- )
748
- return values
749
- }
750
- const depth = prefix.length + 2
751
-
752
- function localSlot(node: Ast.Node) {
753
- const slot = resolveDynamic(node)
754
-
755
- if (
756
- slot &&
757
- prefix.some(
758
- (key) =>
759
- !Condition.local(key) && !selectors.localConditions.has(key),
760
- )
761
- ) {
762
- report(
763
- 'unsupported_syntax',
764
- 'Dynamic values require conditions that select the styled element.',
765
- node,
766
- )
767
-
768
- return undefined
769
- }
770
-
771
- return slot
772
- }
773
-
774
- const properties: Ast.ObjectExpression['properties'] = []
775
- for (const entry of argument.properties) {
776
- const key =
777
- entry.type === 'Property' && !entry.computed
778
- ? entry.key.type === 'Identifier'
779
- ? entry.key.name
780
- : entry.key.type === 'Literal'
781
- ? entry.key.value
782
- : undefined
783
- : undefined
784
- if (key !== 'selectors' && key !== 'vars') {
785
- properties.push(entry)
786
- continue
787
- }
788
- if (
789
- entry.type !== 'Property' ||
790
- entry.kind !== 'init' ||
791
- entry.method ||
792
- entry.shorthand ||
793
- entry.value.type !== 'ObjectExpression'
794
- ) {
795
- report(
796
- 'unsupported_syntax',
797
- `${key} requires an explicit literal object.`,
798
- entry,
799
- )
800
- continue
801
- }
802
- for (const property of entry.value.properties) {
803
- if (
804
- property.type !== 'Property' ||
805
- (key === 'selectors'
806
- ? !selectors.conditions.has(property.key.start)
807
- : !property.computed ||
808
- !variables.references.has(property.key.start))
809
- ) {
810
- report(
811
- 'unsupported_syntax',
812
- key === 'selectors'
813
- ? 'Selectors require explicit & targets.'
814
- : 'Variable assignments require declared variable keys.',
815
- property,
816
- )
817
- continue
818
- }
819
- properties.push(property)
820
- }
821
- }
822
-
823
- for (const property of properties) {
824
- if (
825
- property.type !== 'Property' ||
826
- property.kind !== 'init' ||
827
- property.method ||
828
- (property.computed &&
829
- !selectors.conditions.has(property.key.start) &&
830
- !variables.references.has(property.key.start) &&
831
- !contributions.queryKeys.has(property.key.start)) ||
832
- property.shorthand ||
833
- (!selectors.conditions.has(property.key.start) &&
834
- !variables.references.has(property.key.start) &&
835
- property.key.type !== 'Identifier' &&
836
- (property.key.type !== 'Literal' ||
837
- typeof property.key.value !== 'string'))
838
- ) {
839
- report(
840
- 'unsupported_syntax',
841
- 'Only explicit literal properties are supported; spreads, computed keys, shorthand, and methods are not evaluated.',
842
- property,
843
- )
844
- continue
845
- }
846
-
847
- const key =
848
- variables.references.get(property.key.start)?.reference.name ??
849
- selectors.conditions.get(property.key.start) ??
850
- contributions.queryKeys.get(property.key.start) ??
851
- (property.key.type === 'Identifier'
852
- ? property.key.name
853
- : property.key.type === 'Literal'
854
- ? String(property.key.value)
855
- : '')
856
-
857
- if (Object.hasOwn(values, key)) {
858
- report(
859
- 'unsupported_syntax',
860
- 'Duplicate properties are not supported in source definitions yet.',
861
- property,
862
- )
863
- continue
864
- }
865
-
866
- if (
867
- (key === 'targets' || target !== -1) &&
868
- staticData.absent(property.value)
869
- )
870
- continue
871
-
872
- if (key === 'targets' || prefix.at(-1) === 'targets') {
873
- const input = Expression.unwrap(property.value)
874
- if (input.type !== 'ObjectExpression') {
875
- report(
876
- 'unsupported_syntax',
877
- 'Target branches require static declaration objects.',
878
- input,
879
- )
880
- continue
881
- }
882
- values[key] = object(input, [...prefix, key])
883
- continue
884
- }
885
- if (target !== -1 && prefix[target + 1] !== 'web') {
886
- function nativeValue(input: Ast.Node, depth = 0): unknown {
887
- const node = Expression.unwrap(input)
888
- if (depth > 64) {
889
- report(
890
- 'unsupported_syntax',
891
- 'Native value nesting exceeds 64 levels.',
892
- node,
893
- )
894
- return undefined
895
- }
896
- if (node.type === 'ObjectExpression')
897
- return object(node, [...prefix, key])
898
- if (node.type === 'ArrayExpression')
899
- return node.elements.map((entry) => {
900
- if (!entry || entry.type === 'SpreadElement') {
901
- report(
902
- 'unsupported_syntax',
903
- 'Native arrays require dense static entries.',
904
- node,
905
- )
906
- return undefined
907
- }
908
- return nativeValue(entry, depth + 1)
909
- })
910
- if (
911
- node.type === 'Literal' &&
912
- (node.value === null ||
913
- ['boolean', 'number', 'string'].includes(typeof node.value))
914
- )
915
- return node.value
916
- if (
917
- node.type === 'UnaryExpression' &&
918
- ['+', '-'].includes(node.operator) &&
919
- node.argument.type === 'Literal' &&
920
- typeof node.argument.value === 'number'
921
- )
922
- return (node.operator === '-' ? -1 : 1) * node.argument.value
923
- if (node.type === 'TemplateLiteral') {
924
- const value = Expression.template(node)
925
- if (typeof value === 'string') return value
926
- }
927
- report(
928
- 'unsupported_syntax',
929
- 'Native branches require static literal values.',
930
- node,
931
- )
932
- return undefined
933
- }
934
- values[key] = nativeValue(property.value)
935
- continue
936
- }
937
- if (Condition.is(key)) {
938
- conditionKeys.set(
939
- JSON.stringify([name, ...prefix, key]),
940
- property.key,
941
- )
942
-
943
- const input = Expression.unwrap(property.value)
944
-
945
- if (input.type !== 'ObjectExpression') {
946
- report(
947
- 'unsupported_syntax',
948
- 'Conditions require literal declaration objects.',
949
- input,
950
- )
951
- continue
952
- }
953
-
954
- locations.push({
955
- source: options.moduleId,
956
- start: property.start,
957
- end: property.end,
958
- path: [name, ...prefix, key],
959
- })
960
- values[key] = object(input, [...prefix, key])
961
- continue
962
- }
963
-
964
- const targets = themes?.styles.get(call.start)?.theme[Token.definition]
965
- .contract.shorthands?.[key] ?? [key as Style.Declaration['property']]
966
-
967
- function value(node: Ast.Node, path: readonly string[]): unknown {
968
- const unwrapped = Expression.unwrap(node)
969
- const token =
970
- variables.references.get(unwrapped.start) ??
971
- themes?.tokens.get(unwrapped.start)
972
- const reference =
973
- localSlot(node) ??
974
- (token && token.end === unwrapped.end ? token.reference : undefined)
975
-
976
- if (
977
- dynamicValues &&
978
- reference &&
979
- Object.values(dynamicValues.slots).includes(
980
- reference as Binding.Reference,
981
- ) &&
982
- path.length > depth
983
- ) {
984
- report(
985
- 'unsupported_syntax',
986
- 'Dynamic fallback entries are not supported.',
987
- node,
988
- )
989
-
990
- return undefined
991
- }
992
-
993
- node = Expression.unwrap(node)
994
-
995
- const animation = contributions.references.get(node.start)
996
- if (animation) {
997
- const kind = contributions.kinds.get(animation)
998
- if (
999
- kind &&
1000
- targets.some((target) => !RuleReference.accepts(kind, target))
1001
- ) {
1002
- report(
1003
- 'unsupported_syntax',
1004
- 'Named stylesheet reference is incompatible with this property.',
1005
- node,
1006
- )
1007
- return undefined
1008
- }
1009
- return animation
1010
- }
1011
-
1012
- const template =
1013
- node.type === 'TemplateLiteral'
1014
- ? Expression.template(node, 0, (expression, prefix) => {
1015
- const animation = contributions.references.get(
1016
- Expression.unwrap(expression).start,
1017
- )
1018
- if (animation) {
1019
- const kind = contributions.kinds.get(animation)
1020
- if (
1021
- kind &&
1022
- targets.some(
1023
- (target) =>
1024
- !RuleReference.acceptsExpression(
1025
- kind,
1026
- target,
1027
- prefix,
1028
- ),
1029
- )
1030
- ) {
1031
- report(
1032
- 'unsupported_syntax',
1033
- 'Named stylesheet reference is incompatible with this property.',
1034
- expression,
1035
- )
1036
- return undefined
1037
- }
1038
- return animation
1039
- }
1040
-
1041
- const token =
1042
- variables.references.get(expression.start) ??
1043
- themes?.tokens.get(expression.start)
1044
- const slot = localSlot(expression)
1045
-
1046
- if (slot) {
1047
- if (path.length > depth) {
1048
- report(
1049
- 'unsupported_syntax',
1050
- 'Dynamic fallback entries are not supported.',
1051
- expression,
1052
- )
1053
-
1054
- return undefined
1055
- }
1056
-
1057
- return slot
1058
- }
1059
-
1060
- return token?.end === expression.end
1061
- ? token.reference
1062
- : undefined
1063
- })
1064
- : undefined
1065
-
1066
- if (Token.isExpression(template)) {
1067
- for (const part of template.parts) {
1068
- if (
1069
- typeof part !== 'string' &&
1070
- !(Binding.is(part)
1071
- ? (dynamicValues !== undefined &&
1072
- Object.values(dynamicValues.slots).includes(part)) ||
1073
- targets.every(
1074
- (target) =>
1075
- Binding.accepts(part.type, target) ||
1076
- (part.type === 'color' &&
1077
- Expression.acceptsColor(template, target)),
1078
- )
1079
- : targets.every(
1080
- (target) =>
1081
- Token.acceptsReference(part, target) ||
1082
- (part.contract.variableSet &&
1083
- Expression.acceptsVariables(template, target)) ||
1084
- (part.group === 'color' &&
1085
- Expression.acceptsColor(template, target)),
1086
- ))
1087
- ) {
1088
- report(
1089
- 'unsupported_syntax',
1090
- Binding.is(part)
1091
- ? 'Variable domain is incompatible with this property.'
1092
- : 'Theme variable domain is incompatible with this property.',
1093
- node,
1094
- )
1095
-
1096
- return undefined
1097
- }
1098
- }
1099
- }
1100
-
1101
- if (
1102
- reference &&
1103
- Token.is(reference) &&
1104
- !targets.every((target) =>
1105
- Token.acceptsReference(reference, target),
1106
- ) &&
1107
- !targets.every((target) =>
1108
- dynamicValues?.accepts(
1109
- reference as unknown as Binding.Reference,
1110
- target,
1111
- ),
1112
- )
1113
- ) {
1114
- report(
1115
- 'unsupported_syntax',
1116
- 'Theme variable domain is incompatible with this property.',
1117
- node,
1118
- )
1119
-
1120
- return undefined
1121
- }
1122
-
1123
- if (
1124
- reference &&
1125
- Binding.is(reference) &&
1126
- !(
1127
- dynamicValues &&
1128
- Object.values(dynamicValues.slots).includes(reference) &&
1129
- reference.type !== 'number'
1130
- ) &&
1131
- !targets.every(
1132
- (target) =>
1133
- Binding.accepts(reference.type, target) ||
1134
- dynamicValues?.accepts(
1135
- reference as unknown as Binding.Reference,
1136
- target,
1137
- ),
1138
- )
1139
- ) {
1140
- report(
1141
- 'unsupported_syntax',
1142
- 'Variable domain is incompatible with this property.',
1143
- node,
1144
- )
1145
-
1146
- return undefined
1147
- }
1148
-
1149
- let result: unknown
1150
-
1151
- if (reference) result = reference
1152
- else if (template !== undefined) result = template
1153
- else if (
1154
- node.type === 'Literal' &&
1155
- (typeof node.value === 'string' || typeof node.value === 'number')
1156
- )
1157
- result = node.value
1158
- else if (
1159
- node.type === 'UnaryExpression' &&
1160
- (node.operator === '-' || node.operator === '+') &&
1161
- node.argument.type === 'Literal' &&
1162
- typeof node.argument.value === 'number'
1163
- )
1164
- result =
1165
- node.operator === '-' ? -node.argument.value : node.argument.value
1166
- else if (node.type === 'ArrayExpression' && path.length === depth) {
1167
- result = node.elements.map((element, index) => {
1168
- if (!element || element.type === 'SpreadElement') {
1169
- report(
1170
- 'unsupported_syntax',
1171
- 'Fallback arrays require dense literal entries without spreads.',
1172
- element ?? node,
1173
- )
1174
-
1175
- return undefined
1176
- }
1177
-
1178
- return value(element, [...path, String(index)])
1179
- })
1180
- } else {
1181
- report(
1182
- 'unsupported_syntax',
1183
- 'Expected a literal string or number; expressions are not evaluated.',
1184
- node,
1185
- )
1186
-
1187
- return undefined
1188
- }
1189
-
1190
- locations.push({
1191
- end: node.end,
1192
- path,
1193
- source: options.moduleId,
1194
- start: node.start,
1195
- })
1196
-
1197
- return result
1198
- }
1199
-
1200
- values[key] = value(property.value, [name, ...prefix, key])
1201
- }
1202
-
1203
- if (typeof values.typography === 'string') {
1204
- const theme = themes?.styles.get(call.start)?.theme
1205
- const mappings = theme?.[Token.definition].contract.shorthands
1206
- const explicit = new Set(
1207
- Object.keys(values).flatMap((key) => mappings?.[key] ?? [key]),
1208
- )
1209
- const parsed = Value.parse(values.typography, 'fontFamily')
1210
- const keys = Typography.keys(
1211
- theme,
1212
- parsed && !('invalid' in parsed) ? parsed.value : values.typography,
1213
- explicit,
1214
- )
1215
- const queries = keys.filter(Typography.condition).length
1216
- for (const property of properties) {
1217
- if (property.type !== 'Property') continue
1218
- const key =
1219
- property.key.type === 'Identifier'
1220
- ? property.key.name
1221
- : property.key.type === 'Literal'
1222
- ? property.key.value
1223
- : undefined
1224
- if (key === 'typography') {
1225
- typography.set(property.start, keys.length - queries)
1226
- if (queries) typographyQueries.set(property.start, queries)
1227
- }
1228
- }
1229
- }
1230
-
1231
- return values
1232
- }
1233
-
1234
- const values = object(argument)
1235
- if (diagnostics.length !== before) continue
1236
-
1237
- try {
1238
- const definition = define(
1239
- { [name]: values },
1240
- { locations, vars: themes?.styles.get(call.start)?.theme },
1241
- )
1242
-
1243
- function validate(style: Style.NamedStyle, path: readonly string[]) {
1244
- for (const declaration of style.declarations) {
1245
- if (
1246
- Token.is(declaration.value) &&
1247
- declaration.value.contract.variableSet &&
1248
- Literal.rule(declaration.property)?.kind === 'identifier' &&
1249
- !Expression.acceptsIdentifier(
1250
- declaration.value,
1251
- declaration.property,
1252
- )
1253
- )
1254
- report(
1255
- 'invalid_literal',
1256
- 'Variable value is incompatible with this property.',
1257
- call,
1258
- )
1259
- }
1260
- if (style.targets?.web)
1261
- validate(style.targets.web, [...path, 'targets', 'web'])
1262
- for (const rule of style.rules ?? []) {
1263
- if (rule.condition !== undefined) {
1264
- const location =
1265
- conditionKeys.get(JSON.stringify([...path, rule.condition])) ??
1266
- call
1267
-
1268
- try {
1269
- AtRules.transform({
1270
- filename: options.moduleId,
1271
- code: Buffer.from(`.z{${rule.condition}{color:red;}}`),
1272
- errorRecovery: false,
1273
- })
1274
- } catch (error) {
1275
- report(
1276
- 'unsupported_syntax',
1277
- `Invalid selector or condition: ${(error as Error).message}`,
1278
- location,
1279
- )
1280
- }
1281
- }
1282
-
1283
- validate(
1284
- rule.style,
1285
- rule.condition === undefined ? path : [...path, rule.condition],
1286
- )
1287
- }
1288
- }
1289
-
1290
- for (const style of definition.styles) validate(style, [style.name])
1291
-
1292
- if (diagnostics.length !== before) continue
1293
-
1294
- const contract = themes?.styles.get(call.start)?.theme[Token.definition]
1295
- .contract
1296
- const composition = contract?.composition
1297
- const cssOutput = contract?.cssOutput
1298
- styles.push(
1299
- ...definition.styles.map((style) =>
1300
- composition || cssOutput
1301
- ? Object.freeze({
1302
- ...style,
1303
- ...(composition ? { composition } : {}),
1304
- ...(cssOutput ? { cssOutput } : {}),
1305
- })
1306
- : style,
1307
- ),
1308
- )
1309
-
1310
- const shorthands = themes?.styles.get(call.start)?.theme[Token.definition]
1311
- .contract.shorthands
1312
-
1313
- const retained = staticRecipe ?? dynamicRecipe
1314
- const targetRecipe = retained && {
1315
- ...retained,
1316
- rules: retained.rules.map(({ matches, value }, index) => ({
1317
- matches,
1318
- value: define(
1319
- { [`${name}-${index}`]: object(value) },
1320
- { locations, vars: themes?.styles.get(call.start)?.theme },
1321
- ),
1322
- })),
1323
- }
1324
- calls.push({
1325
- ...(recipe ? { recipe, recipeTypes } : {}),
1326
- ...(staticRecipe
1327
- ? { staticRecipe: targetRecipe }
1328
- : dynamicRecipe
1329
- ? { dynamicRecipe: targetRecipe }
1330
- : {}),
1331
- ...(selectors.identities.has(call.start)
1332
- ? { identity: selectors.identities.get(call.start)! }
1333
- : {}),
1334
- ...(argument !== (dynamic?.body ?? original) &&
1335
- argument.type === 'ObjectExpression'
1336
- ? { body: argument }
1337
- : {}),
1338
- ...(shorthands ? { shorthands } : {}),
1339
- ...(typography.size ? { typography } : {}),
1340
- ...(typographyQueries.size ? { typographyQueries } : {}),
1341
- ...(themes?.styles.get(call.start)?.output
1342
- ? { output: 'html' as const }
1343
- : {}),
1344
- ...(dynamic
1345
- ? {
1346
- slots: dynamic.slots,
1347
- valuesType: options.source.slice(
1348
- dynamic.type.start,
1349
- dynamic.type.end,
1350
- ),
1351
- }
1352
- : {}),
1353
- ...(options.compiler === false
1354
- ? {
1355
- portable: (() => {
1356
- if (explicitId !== undefined) return `z-style-${definitionId}`
1357
- if (
1358
- dynamic ||
1359
- recipe ||
1360
- (!definition.styles[0]!.declarations.length &&
1361
- !definition.styles[0]!.rules &&
1362
- !definition.styles[0]!.targets)
1363
- )
1364
- return undefined
1365
- return Identity.style(definition.styles[0]!, cssNamespace)
1366
- })(),
1367
- }
1368
- : {}),
1369
- cssName,
1370
- cssNamespace,
1371
- end: call.end,
1372
- name,
1373
- start: call.start,
1374
- })
1375
- } catch (error) {
1376
- if (!(error instanceof Style.InvalidError)) throw error
1377
-
1378
- for (const diagnostic of error.diagnostics)
1379
- diagnostics.push({
1380
- code: 'invalid_literal',
1381
- end: diagnostic.location?.end ?? call.end,
1382
- message: diagnostic.message,
1383
- source: options.moduleId,
1384
- start: diagnostic.location?.start ?? call.start,
1385
- })
1386
- }
1387
- }
1388
-
1389
- try {
1390
- let compositionIndex = 0
1391
- for (const entry of options.target === 'native'
1392
- ? []
1393
- : Compositions.collect({
1394
- calls,
1395
- identity: namespace,
1396
- links: options[Themes.context]?.links,
1397
- program,
1398
- scopes: themes?.scopeApplications,
1399
- source: options.source,
1400
- styles,
1401
- })) {
1402
- const authored = authoredNames.get(entry.call.start)
1403
- const name = authored && authored !== 'style' ? authored : 'composition'
1404
- const cssName = `${name}-${compositionIndex++}-${entry.call.cssName ?? 'style'}`
1405
- calls.push(
1406
- ...(entry.cases ?? []).map((value, index) => ({
1407
- ...value.call,
1408
- cssName: `${cssName}-${index}`,
1409
- })),
1410
- { ...entry.call, cssName },
1411
- )
1412
- styles.push(
1413
- ...(entry.cases ?? []).map((entry) => entry.style),
1414
- entry.style,
1415
- )
1416
- }
1417
- } catch (error) {
1418
- if (!(error instanceof Themes.InvalidError)) throw error
1419
- report('unsupported_syntax', error.message, error)
1420
- }
1421
-
1422
- if (themes && !diagnostics.length)
1423
- for (const [start, token] of themes.tokens) {
1424
- if (
1425
- !staticData.used.has(start) &&
1426
- !themes.staticTokens.some((node) => node.start === start) &&
1427
- ![...calls, ...contributions.calls].some(
1428
- (call) => start >= call.start && token.end <= call.end,
1429
- )
1430
- )
1431
- report(
1432
- 'unsupported_syntax',
1433
- 'Theme references require a compiled style declaration.',
1434
- { start, end: token.end },
1435
- )
1436
- }
1437
-
1438
- let contributionData: readonly Css.Contribution[] = []
1439
- const contributionStarts = [...variables.registrationStarts]
1440
-
1441
- try {
1442
- for (const [index, registration] of variables.registrations.entries()) {
1443
- try {
1444
- const css = Css.compile({
1445
- styles: { styles: [] },
1446
- contributions: [registration],
1447
- }).css
1448
- AtRules.transform({
1449
- filename: options.moduleId,
1450
- code: new TextEncoder().encode(css),
1451
- errorRecovery: false,
1452
- })
1453
- } catch (error) {
1454
- throw new Themes.InvalidError(
1455
- (error as Error).message,
1456
- variables.registrationLocations[index]!,
1457
- )
1458
- }
1459
- }
1460
-
1461
- contributionData = [
1462
- ...variables.registrations,
1463
- ...Contributions.extract(
1464
- contributions,
1465
- themes?.tokens ?? new Map(),
1466
- contributionStarts,
1467
- (node) => staticData.resolve(node, staticCalls),
1468
- ),
1469
- ...(themes?.calls ?? []).flatMap((call) =>
1470
- call.options?.layers
1471
- ? [
1472
- {
1473
- kind: 'layers' as const,
1474
- names: call.options.layers as readonly string[],
1475
- },
1476
- ]
1477
- : [],
1478
- ),
1479
- ]
1480
-
1481
- if (contributionData.length) {
1482
- const rendered = Css.compile({
1483
- styles: { styles: [] },
1484
- contributions: contributionData,
1485
- vars: themes?.themes,
1486
- }).css
1487
- AtRules.transform({
1488
- filename: options.moduleId,
1489
- code: new TextEncoder().encode(rendered),
1490
- errorRecovery: false,
1491
- ...(!options[Themes.context]
1492
- ? {
1493
- visitor: {
1494
- Rule(rule) {
1495
- if (
1496
- rule.type === 'import' &&
1497
- rule.value.url &&
1498
- !/^(?:\/|[?#]|[a-z][a-z\d+.-]*:)/i.test(rule.value.url)
1499
- )
1500
- throw new Error(
1501
- 'Relative contribution assets require Graph.compile and a relocation host.',
1502
- )
1503
- },
1504
- Url(url) {
1505
- if (
1506
- url.url &&
1507
- !/^(?:\/|[?#]|[a-z][a-z\d+.-]*:)/i.test(url.url)
1508
- )
1509
- throw new Error(
1510
- 'Relative contribution assets require Graph.compile and a relocation host.',
1511
- )
1512
- },
1513
- },
1514
- }
1515
- : {}),
1516
- })
1517
- }
1518
- } catch (error) {
1519
- report(
1520
- 'unsupported_syntax',
1521
- (error as Error).message,
1522
- error instanceof Themes.InvalidError ? error : contributions.calls[0],
1523
- )
1524
- }
1525
-
1526
- for (const token of themes?.staticTokens ?? [])
1527
- if (!staticData.used.has(Expression.unwrap(token).start))
1528
- report(
1529
- 'unsupported_syntax',
1530
- 'Token references must be direct property values in bound theme style calls.',
1531
- token,
1532
- )
1533
-
1534
- if (diagnostics.length) throw new ExtractError(diagnostics)
1535
-
1536
- function exportedStyle(link: Themes.Link): Themes.Link {
1537
- const call = calls.find((call) => call.identity === link.binding)
1538
- const style = call && styles.find((style) => style.name === call.name)
1539
- return {
1540
- ...link,
1541
- ...(call && style
1542
- ? {
1543
- style: PackedStyles.create(
1544
- {
1545
- ...call,
1546
- nativeContext: themes?.nativeContext(call.start, call.end),
1547
- },
1548
- style,
1549
- ),
1550
- }
1551
- : {}),
1552
- ...(link.members
1553
- ? {
1554
- members: Object.fromEntries(
1555
- Object.entries(link.members).map(([name, member]) => [
1556
- name,
1557
- exportedStyle(member),
1558
- ]),
1559
- ),
1560
- }
1561
- : {}),
1562
- }
1563
- }
1564
-
1565
- const callsByName = new Map(calls.map((call) => [call.name, call]))
1566
- const definition = {
1567
- styles: Object.freeze(styles),
1568
- [ClassName.labels]: Object.freeze(
1569
- Object.fromEntries(
1570
- styles.map((style) => {
1571
- let name = style.name
1572
- let call = callsByName.get(name)
1573
- while (!call && name.includes('-')) {
1574
- name = name.slice(0, name.lastIndexOf('-'))
1575
- call = callsByName.get(name)
1576
- }
1577
- return [
1578
- style.name,
1579
- {
1580
- name: call?.cssName
1581
- ? call.cssName + style.name.slice(call.name.length)
1582
- : style.name,
1583
- namespace: call?.cssNamespace,
1584
- },
1585
- ]
1586
- }),
1587
- ),
1588
- ),
1589
- }
1590
- Object.defineProperty(definition, ClassName.labels, { enumerable: false })
1591
- const selections =
1592
- options.target === 'native' ? themes?.selectionUses : themes?.selections
1593
-
1594
- return Object.freeze({
1595
- namespaces: contributionData.filter(
1596
- (value): value is Extract<Css.Contribution, { kind: 'namespace' }> =>
1597
- value.kind === 'namespace',
1598
- ),
1599
- ...(contributionData.length
1600
- ? { contributions: contributionData, contributionStarts }
1601
- : {}),
1602
- ...(contributions.calls.length
1603
- ? { contributionCalls: contributions.calls }
1604
- : {}),
1605
- ...(options[Themes.context]
1606
- ? {
1607
- themeExports: Object.freeze({
1608
- ...themes?.exports,
1609
- ...Object.fromEntries(
1610
- Object.entries(selectors.exports).map(([name, link]) => [
1611
- name,
1612
- exportedStyle(link),
1613
- ]),
1614
- ),
1615
- ...contributions.exports,
1616
- ...variables.exports,
1617
- }),
1618
- }
1619
- : {}),
1620
- calls: Object.freeze(
1621
- calls
1622
- .sort((a, b) => a.start - b.start)
1623
- .map((call) => {
1624
- const nativeContext =
1625
- options.target === 'native'
1626
- ? themes?.nativeContext(call.start, call.end)
1627
- : undefined
1628
- return Object.freeze(
1629
- nativeContext ? { ...call, nativeContext } : call,
1630
- )
1631
- }),
231
+ return Wire.decode(
232
+ Addon.load().call(
233
+ 'source.extract',
234
+ JSON.stringify({
235
+ compiler: options.compiler,
236
+ moduleId: options.moduleId,
237
+ source: options.source,
238
+ target: options.target,
239
+ }),
1632
240
  ),
1633
- styles: Object.freeze(definition),
1634
- ...(variables.calls.length
1635
- ? { variableCalls: Object.freeze(variables.calls) }
1636
- : {}),
1637
- themeAliases: Object.freeze(themes?.aliases ?? []),
1638
- ...(themes?.appearances.size
1639
- ? { themeAppearances: Object.freeze([...themes.appearances]) }
1640
- : {}),
1641
- ...(themes?.scripts.size
1642
- ? { themeScripts: Object.freeze([...themes.scripts]) }
1643
- : {}),
1644
- ...(selections?.size
1645
- ? { themeSelections: Object.freeze([...selections]) }
1646
- : {}),
1647
- themeCalls: Object.freeze(themes?.calls ?? []),
1648
- ...(themes?.staticTokens.length
1649
- ? {
1650
- staticThemeReferences: Object.freeze(
1651
- (themes?.staticTokens ?? []).map((node) => ({
1652
- start: node.start,
1653
- end: node.end,
1654
- value: ThemeValues.create().serialize(
1655
- themes!.tokens.get(node.start)!.reference,
1656
- ),
1657
- })),
1658
- ),
1659
- }
1660
- : {}),
1661
- themeReferences: Object.freeze(themes?.references ?? []),
1662
- vars: themes?.themes ?? Object.freeze({}),
1663
- ...(themes?.varsReads.length
1664
- ? { nativeVars: Object.freeze(themes.varsReads) }
1665
- : {}),
1666
- })
241
+ { compiler: options.compiler },
242
+ )
1667
243
  }
1668
244
 
1669
245
  /** Input and output of source extraction. */
@@ -1679,8 +255,6 @@ export declare namespace extract {
1679
255
  readonly compiler?: boolean | undefined
1680
256
  /** Portable identity including package and module path; no filesystem access occurs. */
1681
257
  readonly moduleId: string
1682
- /** Compiler-owned graph context. */
1683
- readonly [Themes.context]?: Themes.Context | undefined
1684
258
  /** Complete module text, parsed as TypeScript with JSX. */
1685
259
  readonly source: string
1686
260
  }
@@ -1688,21 +262,21 @@ export declare namespace extract {
1688
262
  /** Ordered public compiler input and spans for later rewriting. */
1689
263
  type ReturnType = {
1690
264
  /** Readonly native variable arguments and their complete catalogs. */
1691
- readonly nativeVars?: readonly Themes.VarsRead[] | undefined
265
+ readonly nativeVars?: readonly VarsRead[] | undefined
1692
266
  /** Module-owned namespace bindings retained when contributions are shared. */
1693
267
  readonly namespaces?: readonly Namespace.Definition[] | undefined
1694
268
  /** Static stylesheet effects and their source replacements. */
1695
269
  readonly contributionStarts?: readonly number[] | undefined
1696
270
  readonly contributions?: readonly Css.Contribution[] | undefined
1697
- readonly contributionCalls?: readonly Contributions.Call[] | undefined
271
+ readonly contributionCalls?: readonly ContributionCall[] | undefined
1698
272
  /** Explicit variable contracts replaced by fixed slot data. */
1699
- readonly variableCalls?: readonly Vars.Call[] | undefined
273
+ readonly variableCalls?: readonly VariableCall[] | undefined
1700
274
  /** Direct calls in source order. */
1701
275
  readonly calls: readonly Call[]
1702
276
  /** Validated definitions accepted by Css.compile. */
1703
277
  readonly styles: Style.Definition
1704
278
  /** Local bound-authoring initializers and their retained token types. */
1705
- readonly themeAliases: readonly Themes.Alias[]
279
+ readonly themeAliases: readonly ThemeAlias[]
1706
280
  /** Configuration identities retaining their root controls. */
1707
281
  readonly themeAppearances?: readonly string[] | undefined
1708
282
  /** Configuration identities retaining their initialization helper. */
@@ -1710,7 +284,7 @@ export declare namespace extract {
1710
284
  /** Configuration identities whose theme selector is called, passed, or bound. */
1711
285
  readonly themeSelections?: readonly string[] | undefined
1712
286
  /** Local factory spans replaced by compiled scope data. */
1713
- readonly themeCalls: readonly Themes.Call[]
287
+ readonly themeCalls: readonly ThemeCall[]
1714
288
  /** Scope reads replaced by class constants. */
1715
289
  readonly staticThemeReferences?:
1716
290
  | readonly {
@@ -1719,9 +293,12 @@ export declare namespace extract {
1719
293
  readonly value: string
1720
294
  }[]
1721
295
  | undefined
1722
- readonly themeReferences: readonly Themes.Reference[]
1723
- /** Resolved authoring exports when extracted as part of a source graph. */
1724
- readonly themeExports?: Readonly<Record<string, Themes.Link>> | undefined
296
+ readonly themeReferences: readonly Pick<
297
+ ThemeCall,
298
+ 'end' | 'name' | 'start'
299
+ >[]
300
+ /** Resolved authoring exports when extracted as part of a source graph, absent from a direct call. */
301
+ readonly themeExports?: Readonly<Record<string, object>> | undefined
1725
302
  /** Stable scope keys and validated local theme definitions. */
1726
303
  readonly vars: Readonly<Record<string, Theme.Definition>>
1727
304
  }
@@ -1747,15 +324,3 @@ export class ExtractError extends Error {
1747
324
  /** Stable namespaced error identifier. */
1748
325
  override name = 'Source.ExtractError'
1749
326
  }
1750
-
1751
- function identity(value: string): string {
1752
- let first = 2166136261
1753
- let second = 2246822507
1754
-
1755
- for (let index = 0; index < value.length; index++) {
1756
- first = Math.imul(first ^ value.charCodeAt(index), 16777619)
1757
- second = Math.imul(second ^ value.charCodeAt(index), 3266489909)
1758
- }
1759
-
1760
- return `${(first >>> 0).toString(36)}${(second >>> 0).toString(36)}`
1761
- }