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
@@ -1,17 +1,10 @@
1
1
  /** Rewrites shared authoring to native tables and ordered runtime bindings. @module */
2
- import type * as Ast from '@oxc-project/types'
3
- import MagicString from 'magic-string'
4
- import type * as Recipe from '../internal/Recipe.js'
5
- import * as Source from './Source.js'
2
+ import type * as Source from './Source.js'
3
+ import * as Context from './internal/Context.js'
6
4
  import * as Edits from './internal/Edits.js'
7
- import * as NativeBindings from './internal/NativeBindings.js'
8
- import * as NativeMedia from './internal/NativeMedia.js'
9
- import * as NativeVars from './internal/NativeVars.js'
10
- import * as Themes from './internal/Themes.js'
11
- import * as StyleSheet from '../react-native/StyleSheet.js'
12
- import * as Syntax from './internal/Syntax.js'
13
- import * as Variants from '../react-native/Variants.js'
14
- import * as Walker from 'oxc-walker'
5
+ import * as Results from './internal/Results.js'
6
+ import type * as StyleSheet from '../react-native/StyleSheet.js'
7
+ import type * as Variants from '../react-native/Variants.js'
15
8
 
16
9
  /**
17
10
  * Compiles local styles, variants, and variable reads for an explicit native target.
@@ -22,836 +15,19 @@ import * as Walker from 'oxc-walker'
22
15
  * @throws {StyleSheet.CompileError} For unsupported native declaration values.
23
16
  */
24
17
  export function compile(options: compile.Options): compile.ReturnType {
25
- const typed = !options[Edits.runtime] && /\.[cm]?tsx?$/.test(options.moduleId)
26
- const extracted =
27
- options[Themes.context]?.extracted ??
28
- Source.extract({
29
- moduleId: options.moduleId,
30
- source: options.source,
31
- target: 'native',
32
- [Themes.context]: options[Themes.context],
33
- })
34
- if (
35
- extracted.contributions?.length ||
36
- extracted.variableCalls?.length ||
37
- extracted.themeReferences.length ||
38
- extracted.themeSelections?.length ||
39
- (!options.contextual &&
40
- (extracted.themeAppearances?.length || extracted.themeScripts?.length))
41
- )
42
- throw new CompileError(
43
- 'Native static modules do not support CSS contributions, variables, or web set controls.',
44
- )
45
- const parsed = options[Themes.context]?.parsed ?? Syntax.parse(options)
46
- const names = new Set(options[Themes.context]?.identifiers)
47
- if (!options[Themes.context]?.identifiers)
48
- Walker.walk(parsed.program, {
49
- enter(node) {
50
- if (node.type === 'Identifier') names.add(node.name)
51
- },
52
- })
53
- let helper = '__zyzzNative'
54
- while (
55
- [
56
- helper,
57
- `${helper}Context`,
58
- `${helper}Dynamic`,
59
- `${helper}Static`,
60
- `${helper}Vars`,
61
- ].some((name) => names.has(name))
62
- )
63
- helper += '_'
64
- let dynamicHelper = `${helper}Dynamic`
65
- while (names.has(dynamicHelper)) dynamicHelper += '_'
66
- const module = new MagicString(options.source)
67
- const edits: Edits.Edit[] = []
68
- function overwrite(
69
- start: number,
70
- end: number,
71
- code: string,
72
- expression = false,
73
- ) {
74
- edits.push({ start, end, code, expression })
75
- module.overwrite(start, end, code)
76
- }
77
- const recipes: Record<string, Variants.Definition> = Object.create(null)
78
- let dynamic = false
79
- let finite = false
80
- const contexts = new Map<string, string>()
81
- const compiledCalls = new WeakMap<
82
- Variants.Definition,
83
- {
84
- styles: Readonly<Record<string, StyleSheet.NativeStyle>>
85
- value: string
86
- }
87
- >()
88
- const factories = new Map<string, { name: string; parameters: string[] }>()
89
- const literals = new Map<string, string>()
90
- const initializers = new Map<string, { name: string; values: string[] }>()
91
- const stylesByName = new Map<
92
- string,
93
- (typeof extracted.styles.styles)[number][]
94
- >()
95
- for (const style of extracted.styles.styles) {
96
- const styles = stylesByName.get(style.name)
97
- if (styles) styles.push(style)
98
- else stylesByName.set(style.name, [style])
99
- }
100
-
101
- const staticTables = new Map<Source.Call, Variants.Definition>()
102
- if (extracted.nativeVars?.length)
103
- StyleSheet.compile({
104
- fonts: options.fonts,
105
- platform: options.platform,
106
- styles: { styles: [] },
107
- units: options.units,
108
- })
109
-
110
- const shared = options[NativeVars.shared]
111
- const variables = new Map(shared?.definitions)
112
- const imports = new Set<string>()
113
- for (const read of extracted.nativeVars ?? []) {
114
- const imported = shared?.reads.get(read.start)
115
- if (imported) {
116
- if (imported.source)
117
- imports.add(
118
- `import {${imported.name}} from ${JSON.stringify(imported.source)};`,
119
- )
120
- const type = typed
121
- ? ` as typeof ${options.source.slice(read.start, read.end)}`
122
- : ''
123
- overwrite(read.start, read.end, `(${imported.name}${type})`, true)
124
- continue
125
- }
126
- const definition = (() => {
127
- try {
128
- return NativeVars.compile({
129
- ...read,
130
- fonts: options.fonts,
131
- units: options.units,
132
- })
133
- } catch (error) {
134
- throw new CompileError((error as Error).message)
135
- }
136
- })()
137
- const key = JSON.stringify(definition)
138
- let name = variables.get(key)
139
- if (!name) {
140
- name = `${helper}Vars${variables.size}`
141
- while (names.has(name)) name += '_'
142
- names.add(name)
143
- variables.set(key, name)
144
- }
145
- const type = typed
146
- ? ` as typeof ${options.source.slice(read.start, read.end)}`
147
- : ''
148
- overwrite(read.start, read.end, `(${name}${type})`, true)
149
- }
150
- if (options.contextual) {
151
- const groups = new Map<StyleSheet.compile.Options['vars'], Source.Call[]>()
152
- for (const call of extracted.calls) {
153
- if (
154
- call.recipe ||
155
- call.staticRecipe ||
156
- call.dynamicRecipe ||
157
- call.slots ||
158
- call.output === 'html'
159
- )
160
- continue
161
- const vars = call.nativeContext?.vars ?? options.vars
162
- try {
163
- if (
164
- NativeMedia.prepare(stylesByName.get(call.name) ?? [], vars, options)
165
- )
166
- continue
167
- } catch (error) {
168
- throw new CompileError((error as Error).message)
169
- }
170
-
171
- const group = groups.get(vars)
172
- if (group) group.push(call)
173
- else groups.set(vars, [call])
174
- }
175
- for (const [vars, calls] of groups) {
176
- if (calls.length < 2) continue
177
- try {
178
- const compiled = StyleSheet.compile({
179
- fonts: options.fonts,
180
- platform: options.platform,
181
- styles: {
182
- styles: calls.map((call) => ({
183
- name: call.name,
184
- declarations: [],
185
- rules: (stylesByName.get(call.name) ?? []).map((style) => ({
186
- style,
187
- })),
188
- })),
189
- },
190
- vars,
191
- units: options.units,
192
- })
193
- for (const call of calls) {
194
- const styles = Object.fromEntries(
195
- Object.entries(compiled.styles).map(([set, schemes]) => [
196
- set,
197
- Object.freeze({
198
- light: Object.freeze({ '0': schemes.light[call.name]! }),
199
- dark: Object.freeze({ '0': schemes.dark[call.name]! }),
200
- }),
201
- ]),
202
- )
203
- staticTables.set(
204
- call,
205
- Object.freeze({
206
- axes: Object.freeze({}),
207
- defaults: Object.freeze({}),
208
- styles: Object.freeze(styles),
209
- }),
210
- )
211
- }
212
- } catch (error) {
213
- // Recompile failures individually to retain authored error order and paths.
214
- if (!(error instanceof StyleSheet.CompileError)) throw error
215
- }
216
- }
217
- }
218
-
219
- for (const call of extracted.calls) {
220
- if (
221
- (call.recipe && !call.staticRecipe && !call.dynamicRecipe) ||
222
- call.output === 'html'
223
- )
224
- throw new CompileError(
225
- 'Native source compilation does not support named conditions or HTML output.',
226
- )
227
- const recipe = call.staticRecipe ??
228
- call.dynamicRecipe ?? {
229
- axes: {},
230
- defaults: {},
231
- rules: [
232
- {
233
- matches: [],
234
- value: {
235
- styles: stylesByName.get(call.name) ?? [],
236
- },
237
- },
238
- ],
239
- }
240
- overwrite(
241
- call.start,
242
- call.end,
243
- callable(recipe, call.name, call, options, staticTables.get(call)),
244
- true,
245
- )
246
- }
247
-
248
- function create(name: string, data: unknown): string {
249
- const literal = JSON.stringify(data)
250
- if (!options[Edits.runtime] || extracted.calls.length < 2)
251
- return `${name}.create(${literal})`
252
- const key = `${name}:${literal}`
253
- const cached = literals.get(key)
254
- if (cached) return cached
255
- const values: string[] = []
256
- const structure = literal.replace(
257
- /"(?:[^"\\]|\\.)*"|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null/g,
258
- (value: string, offset: number) => {
259
- // Serialized property names precede colons; only value tokens become parameters.
260
- if (literal[offset + value.length] === ':') return value
261
- const parameter = `v${values.length}`
262
- values.push(value)
263
- return parameter
264
- },
265
- )
266
- const expression = `${name}.create(${structure})`
267
- const value =
268
- values.length > 64
269
- ? `${name}.create(${literal})`
270
- : factory(expression, values)
271
- literals.set(key, value)
272
- return value
273
- }
274
-
275
- function factory(expression: string, values: string[]): string {
276
- let definition = factories.get(expression)
277
- if (!definition) {
278
- let name = `${helper}Factory${factories.size}`
279
- while (names.has(name)) name += '_'
280
- names.add(name)
281
- definition = { name, parameters: values.map((_, index) => `v${index}`) }
282
- factories.set(expression, definition)
283
- }
284
- const value = `${definition.name}(${values.join(',')})`
285
- initializers.set(value, { name: definition.name, values })
286
- return value
287
- }
288
-
289
- function callable(
290
- recipe: Recipe.Definition,
291
- name: string,
292
- call?: Pick<
293
- Source.Call,
294
- 'slots' | 'recipe' | 'valuesType' | 'recipeTypes' | 'nativeContext'
295
- >,
296
- contextOptions = options,
297
- compiled?: Variants.Definition,
298
- bindings?: ReturnType<typeof NativeBindings.prepare>,
299
- ): string {
300
- const program =
301
- Object.keys(recipe.axes).length > 0 ||
302
- call?.slots ||
303
- call?.recipe?.payloads?.length
304
-
305
- if (contextOptions.contextual) {
306
- const vars = call?.nativeContext?.vars ?? contextOptions.vars
307
- const media = (() => {
308
- try {
309
- return NativeMedia.prepare(
310
- recipe.rules.flatMap((rule) => rule.value.styles),
311
- vars,
312
- contextOptions,
313
- )
314
- } catch (error) {
315
- throw new CompileError((error as Error).message)
316
- }
317
- })()
318
- if (media) {
319
- const profiles = media.selections.map((selection) => {
320
- const selected = media.select(selection)
321
- const next = {
322
- ...recipe,
323
- rules: recipe.rules.map((rule) => ({
324
- ...rule,
325
- value: {
326
- ...rule.value,
327
- styles: rule.value.styles.map(selected.style),
328
- },
329
- })),
330
- }
331
- const source = call?.nativeContext
332
- ? {
333
- ...call,
334
- nativeContext: {
335
- ...call.nativeContext,
336
- vars: selected.vars as typeof call.nativeContext.vars,
337
- },
338
- }
339
- : call
340
- const value = callable(next, name, source, {
341
- ...contextOptions,
342
- vars: selected.vars,
343
- })
344
- return `${JSON.stringify(selection)}:${value}`
345
- })
346
- // A single static table cannot represent the responsive callable.
347
- delete recipes[name]
348
-
349
- return `${helper}Context.responsive(${JSON.stringify(media.queries)},{${profiles.join(',')}})`
350
- }
351
- if (!program)
352
- compiled ??= Variants.compile({
353
- recipe,
354
- fonts: contextOptions.fonts,
355
- platform: contextOptions.platform,
356
- vars,
357
- units: contextOptions.units,
358
- })
359
- else {
360
- try {
361
- bindings = NativeBindings.prepare(recipe, call ?? {}, {
362
- ...contextOptions,
363
- vars,
364
- })
365
- } catch (error) {
366
- if (error instanceof StyleSheet.CompileError) throw error
367
- throw new CompileError((error as Error).message)
368
- }
369
- }
370
- const defaultVars =
371
- call?.nativeContext?.defaultVars ?? contextOptions.set ?? 'default'
372
- const tables = new Map<string, string>()
373
- const alternatives = (vars ? Object.keys(vars) : ['default']).map(
374
- (set) => ({
375
- set,
376
- schemes: (['light', 'dark'] as const).map((colorScheme) => {
377
- const value = callable(
378
- recipe,
379
- name,
380
- call,
381
- {
382
- ...contextOptions,
383
- contextual: false,
384
- vars,
385
- set,
386
- colorScheme,
387
- },
388
- compiled,
389
- bindings,
390
- )
391
- if (!tables.has(value))
392
- tables.set(value, `${helper}Table${tables.size}`)
393
- return { colorScheme, value }
394
- }),
395
- }),
396
- )
397
- const entries = alternatives.map(
398
- ({ set, schemes }) =>
399
- `${JSON.stringify(set)}:{${schemes.map(({ colorScheme, value }) => `${JSON.stringify(colorScheme)}:${tables.get(value)}`).join(',')}}`,
400
- )
401
- const parameters = [...tables.values()].map((name, index) =>
402
- typed ? `${name}:T${index}` : name,
403
- )
404
- const types = typed
405
- ? `<${parameters.map((_, index) => `const T${index} extends (input:never)=>import('zyzz/runtime').Native.Props<object>`).join(',')},>`
406
- : ''
407
- const expression = `${types}(${parameters.join(',')})=>${helper}Context.create({${entries.join(',')}},${JSON.stringify(defaultVars)})`
408
- let context = contexts.get(expression)
409
- if (!context) {
410
- context = `${helper}ContextFactory${contexts.size}`
411
- while (names.has(context)) context += '_'
412
- names.add(context)
413
- contexts.set(expression, context)
414
- }
415
- const inputs = [...tables.keys()].map((value) => initializers.get(value))
416
- if (inputs.every((input) => input !== undefined)) {
417
- const values: string[] = []
418
- const arguments_ = inputs.map((input) => {
419
- const parameters = input.values.map((value) => {
420
- const parameter = `v${values.length}`
421
- values.push(value)
422
- return parameter
423
- })
424
- return `${input.name}(${parameters.join(',')})`
425
- })
426
- if (values.length <= 64)
427
- return factory(`${context}(${arguments_.join(',')})`, values)
428
- }
429
- return `${context}(${[...tables.keys()].join(',')})`
430
- }
431
- const axes = Object.entries(recipe.axes)
432
- .map(
433
- ([axis, choices]) =>
434
- `${JSON.stringify(axis)}:readonly ${JSON.stringify(choices)}`,
435
- )
436
- .join(';')
437
-
438
- if (program) {
439
- const scalar = !!(call?.slots || call?.recipe?.payloads?.length)
440
- dynamic ||= scalar
441
- finite ||= !scalar
442
- const compiled = (() => {
443
- try {
444
- const compiled = NativeBindings.compile(
445
- recipe,
446
- call ?? {},
447
- contextOptions,
448
- bindings,
449
- )
450
- return scalar ? compiled : NativeBindings.finite(compiled)
451
- } catch (error) {
452
- if (error instanceof StyleSheet.CompileError) throw error
453
- throw new CompileError((error as Error).message)
454
- }
455
- })()
456
- const value = create(scalar ? dynamicHelper : `${helper}Static`, compiled)
457
- if (!typed) return value
458
- if (!call?.slots && !call?.recipe?.payloads?.length)
459
- return `(${value} as import('zyzz/runtime').Native.Callable<{${axes}}>)`
460
-
461
- let input = call.valuesType ?? '{}'
462
- if (call.recipe) {
463
- input = `{${Object.entries(recipe.axes)
464
- .map(([axis, choices]) => {
465
- const types = choices.map((choice) =>
466
- call.recipeTypes?.[axis]?.[choice]
467
- ? `{${JSON.stringify(choice)}:${call.recipeTypes[axis]![choice]}}`
468
- : choice === 'true' || choice === 'false'
469
- ? choice
470
- : JSON.stringify(choice),
471
- )
472
- return `${JSON.stringify(axis)}?:${types.join('|')}|null|undefined`
473
- })
474
- .join(';')}}`
475
- }
476
- return `(${value} as import('zyzz/runtime').NativeDynamic.${call.recipe ? 'RecipeCallable' : 'Callable'}<${input}>)`
477
- }
478
- compiled ??= Variants.compile({
479
- recipe,
480
- fonts: contextOptions.fonts,
481
- platform: contextOptions.platform,
482
- vars: contextOptions.vars,
483
- units: contextOptions.units,
484
- })
485
- recipes[name] = compiled
486
- const styles = StyleSheet.select(compiled.styles, {
487
- set: contextOptions.set ?? 'default',
488
- colorScheme: contextOptions.colorScheme,
489
- })
490
- const cached = compiledCalls.get(compiled)
491
- const value =
492
- cached &&
493
- Object.keys(cached.styles).length === Object.keys(styles).length &&
494
- Object.entries(styles).every(
495
- ([name, style]) => cached.styles[name] === style,
496
- )
497
- ? cached.value
498
- : create(helper, {
499
- axes: compiled.axes,
500
- defaults: compiled.defaults,
501
- styles,
502
- })
503
- if (options.contextual) compiledCalls.set(compiled, { styles, value })
504
- if (!typed) return value
505
- return `(${value} as import('zyzz/runtime').Native.Callable<{${axes}}>)`
506
- }
507
-
508
- const packed: string[] = []
509
- const explicit = new Set<string>()
510
- function binding(node: Ast.Node) {
511
- if (node.type === 'Identifier') explicit.add(node.name)
512
- else if (node.type === 'ObjectPattern')
513
- for (const property of node.properties)
514
- binding(
515
- property.type === 'RestElement' ? property.argument : property.value,
516
- )
517
- else if (node.type === 'ArrayPattern')
518
- for (const element of node.elements) {
519
- if (element) binding(element)
520
- }
521
- else if (node.type === 'AssignmentPattern') binding(node.left)
522
- else if (node.type === 'RestElement') binding(node.argument)
523
- }
524
- for (const statement of parsed.program.body) {
525
- if (
526
- statement.type !== 'ExportNamedDeclaration' ||
527
- statement.exportKind === 'type'
528
- )
529
- continue
530
- for (const specifier of statement.specifiers)
531
- if (specifier.exportKind !== 'type')
532
- explicit.add(
533
- specifier.exported.type === 'Identifier'
534
- ? specifier.exported.name
535
- : specifier.exported.value,
536
- )
537
- const declaration = statement.declaration
538
- if (declaration?.type === 'VariableDeclaration') {
539
- for (const item of declaration.declarations) binding(item.id)
540
- } else if (
541
- declaration &&
542
- 'id' in declaration &&
543
- declaration.id?.type === 'Identifier'
544
- )
545
- explicit.add(declaration.id.name)
546
- }
547
- for (const statement of parsed.program.body) {
548
- if (
549
- (statement.type !== 'ImportDeclaration' &&
550
- statement.type !== 'ExportNamedDeclaration' &&
551
- statement.type !== 'ExportAllDeclaration') ||
552
- !statement.source
553
- )
554
- continue
555
- if (
556
- (statement.type === 'ImportDeclaration' &&
557
- statement.importKind === 'type') ||
558
- (statement.type !== 'ImportDeclaration' &&
559
- statement.exportKind === 'type')
560
- )
561
- continue
562
- const specifier = statement.source.value
563
- const exports = options[Themes.context]?.libraries?.[specifier]
564
- if (!exports) continue
565
-
566
- let imported: string | undefined
567
- function original(): string {
568
- if (imported) return imported
569
- imported = `${helper}Namespace${packed.length}`
570
- while (names.has(imported)) imported += '_'
571
- names.add(imported)
572
- packed.push(`import * as ${imported} from ${JSON.stringify(specifier)};`)
573
- return imported
574
- }
575
-
576
- function overlay(original: string, expression: string): string {
577
- let overrides = `${helper}Members${packed.length}`
578
- while (names.has(overrides)) overrides += '_'
579
- names.add(overrides)
580
- packed.push(`const ${overrides}=${expression};`)
581
- // Getter descriptors retain live bindings outside the recipe contract.
582
- return `Object.freeze(Object.defineProperties({...${original},...${overrides}},Object.fromEntries(Object.keys(${original}).filter(key=>!Object.hasOwn(${overrides},key)).map(key=>[key,{get:()=>Reflect.get(${original},key)}]))))`
583
- }
584
-
585
- function value(
586
- name: string,
587
- link = exports![name],
588
- input?: string,
589
- path: readonly string[] = [name],
590
- ): string | undefined {
591
- if (!link || link.kind !== 'style-reference') return undefined
592
- if (link.members) {
593
- const source = input ?? `${original()}[${JSON.stringify(name)}]`
594
- const expression = `{${Object.entries(link.members)
595
- .map(
596
- ([member, link]) =>
597
- `[${JSON.stringify(member)}]:${value(`${name}.${member}`, link, `${source}[${JSON.stringify(member)}]`, [...path, member])}`,
598
- )
599
- .join(',')}}`
600
- return overlay(source, expression)
601
- }
602
- const recipe = link.style?.staticRecipe ?? link.style?.dynamic?.recipe
603
- if (
604
- !recipe ||
605
- link.style?.output ||
606
- (link.style?.slots.length && !link.style.dynamic)
607
- )
608
- throw new CompileError(
609
- `Packed native callable ${name} requires a static recipe contract.`,
610
- )
611
- const expression = callable(recipe, `${specifier}:${name}`, {
612
- nativeContext: link.style?.nativeContext,
613
- ...(link.style?.dynamic
614
- ? {
615
- slots: link.style.dynamic.slots,
616
- recipe: {
617
- axes: recipe.axes,
618
- defaults: recipe.defaults,
619
- payloads: link.style.dynamic.payloads,
620
- defaultPayloads: link.style.dynamic.defaultPayloads,
621
- },
622
- }
623
- : {}),
624
- })
625
- if (!link.style?.dynamic || !typed) return expression
626
- const type = `typeof import(${JSON.stringify(specifier)})${path
627
- .map((part) => `[${JSON.stringify(part)}]`)
628
- .join('')}`
629
- return `(${expression} as import('zyzz/runtime').NativeDynamic.From<${type}>)`
630
- }
631
-
632
- function namespace(): string | undefined {
633
- if (
634
- !Object.values(exports!).some((link) => link.kind === 'style-reference')
635
- )
636
- return undefined
637
- const imported = original()
638
- const members = Object.keys(exports!).flatMap((name) => {
639
- const expression = value(
640
- name,
641
- exports![name],
642
- `${imported}[${JSON.stringify(name)}]`,
643
- )
644
- return expression === undefined
645
- ? []
646
- : [`[${JSON.stringify(name)}]:${expression}`]
647
- })
648
- return overlay(imported, `{${members.join(',')}}`)
649
- }
650
-
651
- if (statement.type === 'ExportAllDeclaration') {
652
- if (statement.exported) {
653
- const expression = namespace()
654
- if (expression === undefined) continue
655
- let local = `${helper}Export${packed.length}`
656
- while (names.has(local)) local += '_'
657
- names.add(local)
658
- const name =
659
- statement.exported.type === 'Identifier'
660
- ? statement.exported.name
661
- : statement.exported.value
662
- packed.push(
663
- `const ${local}=${expression};export {${local} as ${JSON.stringify(name)}};`,
664
- )
665
- overwrite(statement.start, statement.end, '')
666
- continue
667
- }
668
- for (const name of Object.keys(exports)) {
669
- if (name === 'default' || explicit.has(name)) continue
670
- const expression = value(name)
671
- if (expression === undefined) continue
672
- explicit.add(name)
673
- let local = `${helper}Export${packed.length}`
674
- while (names.has(local)) local += '_'
675
- names.add(local)
676
- packed.push(
677
- `const ${local}=${expression};export {${local} as ${JSON.stringify(name)}};`,
678
- )
679
- }
680
- continue
681
- }
682
- const kept: string[] = []
683
- for (const specifier of statement.specifiers) {
684
- if (specifier.type === 'ImportNamespaceSpecifier') {
685
- const expression = namespace()
686
- if (expression === undefined) {
687
- packed.push(
688
- `import * as ${specifier.local.name} from ${JSON.stringify(statement.source.value)};`,
689
- )
690
- } else packed.push(`const ${specifier.local.name}=${expression};`)
691
- continue
692
- }
693
- if (
694
- (specifier.type === 'ImportSpecifier' &&
695
- specifier.importKind === 'type') ||
696
- (specifier.type === 'ExportSpecifier' &&
697
- specifier.exportKind === 'type')
698
- ) {
699
- kept.push(options.source.slice(specifier.start, specifier.end))
700
- continue
701
- }
702
- const imported =
703
- specifier.type === 'ImportDefaultSpecifier'
704
- ? 'default'
705
- : specifier.type === 'ImportSpecifier'
706
- ? specifier.imported
707
- : specifier.local
708
- const name =
709
- typeof imported === 'string'
710
- ? imported
711
- : imported.type === 'Identifier'
712
- ? imported.name
713
- : imported.value
714
- const expression = value(name)
715
- if (expression === undefined) {
716
- if (specifier.type === 'ImportDefaultSpecifier')
717
- kept.push(`default as ${specifier.local.name}`)
718
- else kept.push(options.source.slice(specifier.start, specifier.end))
719
- continue
720
- }
721
- if (specifier.type === 'ExportSpecifier') {
722
- let local = `${helper}Export${packed.length}`
723
- while (names.has(local)) local += '_'
724
- names.add(local)
725
- const exported =
726
- specifier.exported.type === 'Identifier'
727
- ? specifier.exported.name
728
- : specifier.exported.value
729
- packed.push(
730
- `const ${local}=${expression};export {${local} as ${JSON.stringify(exported)}};`,
731
- )
732
- } else packed.push(`const ${specifier.local.name}=${expression};`)
733
- }
734
- const keyword = statement.type === 'ImportDeclaration' ? 'import' : 'export'
735
- overwrite(
736
- statement.start,
737
- statement.end,
738
- kept.length
739
- ? `${keyword} {${kept.join(',')}} from ${JSON.stringify(statement.source.value)};`
740
- : `import ${JSON.stringify(statement.source.value)};`,
741
- )
742
- }
743
- const compositions: string[] = []
744
- for (const statement of parsed.program.body) {
745
- if (
746
- statement.type === 'ExportAllDeclaration' &&
747
- statement.source.value === 'zyzz' &&
748
- statement.exportKind !== 'type'
749
- )
750
- throw new CompileError(
751
- 'Native modules require named re-exports from zyzz.',
752
- )
753
- if (
754
- statement.type === 'ExportNamedDeclaration' &&
755
- statement.source?.value === 'zyzz' &&
756
- statement.exportKind !== 'type'
757
- ) {
758
- const cx = statement.specifiers.filter(
759
- (specifier) =>
760
- specifier.exportKind !== 'type' &&
761
- (specifier.local.type === 'Identifier'
762
- ? specifier.local.name
763
- : specifier.local.value) === 'cx',
764
- )
765
- if (!cx.length) continue
766
- let binding = `${helper}Compose`
767
- while (names.has(binding)) binding += '_'
768
- names.add(binding)
769
- compositions.push(`const ${binding}=${helper}.compose;`)
770
- const kept = statement.specifiers
771
- .filter((specifier) => !cx.includes(specifier))
772
- .map((specifier) =>
773
- options.source.slice(specifier.start, specifier.end),
774
- )
775
- const exports = cx.map(
776
- (specifier) =>
777
- `${binding} as ${options.source.slice(specifier.exported.start, specifier.exported.end)}`,
778
- )
779
- overwrite(
780
- statement.start,
781
- statement.end,
782
- `${kept.length ? `export {${kept.join(',')}} from 'zyzz';` : ''}export {${exports.join(',')}};`,
783
- )
784
- continue
785
- }
786
- if (
787
- statement.type !== 'ImportDeclaration' ||
788
- statement.source.value !== 'zyzz' ||
789
- statement.importKind === 'type'
790
- )
791
- continue
792
- const cx = statement.specifiers.filter(
793
- (specifier) =>
794
- specifier.type === 'ImportSpecifier' &&
795
- specifier.importKind !== 'type' &&
796
- (specifier.imported.type === 'Identifier'
797
- ? specifier.imported.name
798
- : specifier.imported.value) === 'cx',
799
- )
800
- if (!cx.length) continue
801
- compositions.push(
802
- ...cx.map(
803
- (specifier) => `const ${specifier.local.name}=${helper}.compose;`,
804
- ),
805
- )
806
- const kept = statement.specifiers.filter(
807
- (specifier) => !cx.includes(specifier),
808
- )
809
- const named = kept
810
- .filter((specifier) => specifier.type === 'ImportSpecifier')
811
- .map((specifier) => options.source.slice(specifier.start, specifier.end))
812
- const other = kept
813
- .filter((specifier) => specifier.type !== 'ImportSpecifier')
814
- .map((specifier) => options.source.slice(specifier.start, specifier.end))
815
- const imports = [
816
- ...other,
817
- ...(named.length ? [`{${named.join(',')}}`] : []),
818
- ]
819
- overwrite(
820
- statement.start,
821
- statement.end,
822
- imports.length ? `import ${imports.join(',')} from 'zyzz';` : '',
823
- )
824
- }
825
- if (
826
- extracted.calls.length ||
827
- compositions.length ||
828
- packed.length ||
829
- variables.size ||
830
- imports.size
831
- ) {
832
- let offset = 0
833
- if (options.source.startsWith('#!')) {
834
- const newline = /\r\n|[\n\r\u2028\u2029]/.exec(options.source)
835
- offset = newline
836
- ? newline.index + newline[0].length
837
- : options.source.length
838
- }
839
-
840
- for (const node of parsed.program.body) {
841
- if (node.type !== 'ExpressionStatement' || !node.directive) break
842
-
843
- offset = node.end
844
- }
845
-
846
- const prelude = `\nimport {Native as ${helper}${dynamic ? `,NativeDynamic as ${dynamicHelper}` : ''}${finite ? `,NativeStatic as ${helper}Static` : ''}${options.contextual ? `,NativeContext as ${helper}Context` : ''}${variables.size ? `,NativeVars as ${helper}Vars` : ''}} from 'zyzz/runtime';\n${[...factories].map(([expression, factory]) => `const ${factory.name}=(${factory.parameters.join(',')})=>${expression};`).join('\n')}\n${[...contexts].map(([expression, name]) => `const ${name}=${expression};`).join('\n')}\n${[...variables].map(([value, name]) => `${shared?.definitions.has(value) ? 'export ' : ''}const ${name}=${helper}Vars.create(JSON.parse(${JSON.stringify(value)}));`).join('\n')}\n${[...imports, ...compositions, ...packed].join('\n')}\n`
847
- module.appendLeft(offset, prelude)
848
- edits.push({ start: offset, end: offset, code: prelude, expression: false })
849
- }
850
- return output(module, {
851
- edits,
18
+ const output = Results.call<Results.NativeOutput>('native.compile', {
19
+ ...Results.native(options),
20
+ context: options[Context.key] === true,
852
21
  moduleId: options.moduleId,
853
- recipes: Object.freeze(recipes),
22
+ source: options.source,
854
23
  })
24
+
25
+ return {
26
+ [Edits.key]: output.edits,
27
+ code: output.code,
28
+ map: output.map,
29
+ recipes: Results.frozen(output.recipes) as compile.ReturnType['recipes'],
30
+ }
855
31
  }
856
32
 
857
33
  /** Native source compilation contracts. */
@@ -868,10 +44,8 @@ export declare namespace compile {
868
44
  type Options = Omit<StyleSheet.compile.Options, 'styles'> & {
869
45
  /** Internal Babel emission mode; authoring types are still validated. */
870
46
  readonly [Edits.runtime]?: boolean | undefined
871
- /** Compiler-owned shared native variable profiles. */
872
- readonly [NativeVars.shared]?: NativeVars.Shared | undefined
873
- /** Compiler-owned graph context. */
874
- readonly [Themes.context]?: Themes.Context | undefined
47
+ /** Compiles the module as a member of an adapter-owned graph. */
48
+ readonly [Context.key]?: true | undefined
875
49
  /** Retain every set and scheme for render-local selection. */
876
50
  readonly contextual?: boolean | undefined
877
51
  /** Scheme compiled into this module's callables. Recompile to select another scheme. */
@@ -901,30 +75,3 @@ export class CompileError extends Error {
901
75
  /** Stable namespaced diagnostic name. */
902
76
  override name = 'Native.CompileError'
903
77
  }
904
-
905
- // Keep lazy maps independent of the compiler's parser trees and extracted styles.
906
- function output(
907
- module: MagicString,
908
- options: {
909
- readonly edits: readonly Edits.Edit[]
910
- readonly moduleId: string
911
- readonly recipes: compile.ReturnType['recipes']
912
- },
913
- ): compile.ReturnType {
914
- let sourceMap: string | undefined
915
-
916
- return {
917
- [Edits.key]: options.edits,
918
- code: module.toString(),
919
- get map() {
920
- return (sourceMap ??= module
921
- .generateMap({
922
- hires: true,
923
- includeContent: true,
924
- source: options.moduleId,
925
- })
926
- .toString())
927
- },
928
- recipes: options.recipes,
929
- }
930
- }