zyzz 0.0.0 → 0.0.2

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 (678) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +380 -0
  3. package/dist/Config.d.ts +170 -0
  4. package/dist/Config.d.ts.map +1 -0
  5. package/dist/Config.js +249 -0
  6. package/dist/Config.js.map +1 -0
  7. package/dist/Props.d.ts +7 -0
  8. package/dist/Props.d.ts.map +1 -0
  9. package/dist/Props.js +3 -0
  10. package/dist/Props.js.map +1 -0
  11. package/dist/Style.d.ts +167 -0
  12. package/dist/Style.d.ts.map +1 -0
  13. package/dist/Style.js +284 -0
  14. package/dist/Style.js.map +1 -0
  15. package/dist/Theme.d.ts +154 -0
  16. package/dist/Theme.d.ts.map +1 -0
  17. package/dist/Theme.js +257 -0
  18. package/dist/Theme.js.map +1 -0
  19. package/dist/babel/NativeEdits.d.ts +8 -0
  20. package/dist/babel/NativeEdits.d.ts.map +1 -0
  21. package/dist/babel/NativeEdits.js +233 -0
  22. package/dist/babel/NativeEdits.js.map +1 -0
  23. package/dist/babel/NativeJsx.d.ts +10 -0
  24. package/dist/babel/NativeJsx.d.ts.map +1 -0
  25. package/dist/babel/NativeJsx.js +204 -0
  26. package/dist/babel/NativeJsx.js.map +1 -0
  27. package/dist/babel/index.d.ts +51 -0
  28. package/dist/babel/index.d.ts.map +1 -0
  29. package/dist/babel/index.js +220 -0
  30. package/dist/babel/index.js.map +1 -0
  31. package/dist/cli/index.d.ts +3 -0
  32. package/dist/cli/index.d.ts.map +1 -0
  33. package/dist/cli/index.js +178 -0
  34. package/dist/cli/index.js.map +1 -0
  35. package/dist/compiler/Graph.d.ts +64 -0
  36. package/dist/compiler/Graph.d.ts.map +1 -0
  37. package/dist/compiler/Graph.js +1111 -0
  38. package/dist/compiler/Graph.js.map +1 -0
  39. package/dist/compiler/Native.d.ts +53 -0
  40. package/dist/compiler/Native.d.ts.map +1 -0
  41. package/dist/compiler/Native.js +617 -0
  42. package/dist/compiler/Native.js.map +1 -0
  43. package/dist/compiler/Source.d.ts +165 -0
  44. package/dist/compiler/Source.d.ts.map +1 -0
  45. package/dist/compiler/Source.js +990 -0
  46. package/dist/compiler/Source.js.map +1 -0
  47. package/dist/compiler/Transform.d.ts +57 -0
  48. package/dist/compiler/Transform.d.ts.map +1 -0
  49. package/dist/compiler/Transform.js +884 -0
  50. package/dist/compiler/Transform.js.map +1 -0
  51. package/dist/compiler/index.d.ts +13 -0
  52. package/dist/compiler/index.d.ts.map +1 -0
  53. package/dist/compiler/index.js +13 -0
  54. package/dist/compiler/index.js.map +1 -0
  55. package/dist/compiler/internal/Applications.d.ts +35 -0
  56. package/dist/compiler/internal/Applications.d.ts.map +1 -0
  57. package/dist/compiler/internal/Applications.js +248 -0
  58. package/dist/compiler/internal/Applications.js.map +1 -0
  59. package/dist/compiler/internal/AtRules.d.ts +8 -0
  60. package/dist/compiler/internal/AtRules.d.ts.map +1 -0
  61. package/dist/compiler/internal/AtRules.js +180 -0
  62. package/dist/compiler/internal/AtRules.js.map +1 -0
  63. package/dist/compiler/internal/Catalogs.d.ts +19 -0
  64. package/dist/compiler/internal/Catalogs.d.ts.map +1 -0
  65. package/dist/compiler/internal/Catalogs.js +68 -0
  66. package/dist/compiler/internal/Catalogs.js.map +1 -0
  67. package/dist/compiler/internal/ColorProfiles.d.ts +3 -0
  68. package/dist/compiler/internal/ColorProfiles.d.ts.map +1 -0
  69. package/dist/compiler/internal/ColorProfiles.js +84 -0
  70. package/dist/compiler/internal/ColorProfiles.js.map +1 -0
  71. package/dist/compiler/internal/CompositionBindings.d.ts +16 -0
  72. package/dist/compiler/internal/CompositionBindings.d.ts.map +1 -0
  73. package/dist/compiler/internal/CompositionBindings.js +89 -0
  74. package/dist/compiler/internal/CompositionBindings.js.map +1 -0
  75. package/dist/compiler/internal/Compositions.d.ts +32 -0
  76. package/dist/compiler/internal/Compositions.d.ts.map +1 -0
  77. package/dist/compiler/internal/Compositions.js +464 -0
  78. package/dist/compiler/internal/Compositions.js.map +1 -0
  79. package/dist/compiler/internal/Configurations.d.ts +21 -0
  80. package/dist/compiler/internal/Configurations.d.ts.map +1 -0
  81. package/dist/compiler/internal/Configurations.js +171 -0
  82. package/dist/compiler/internal/Configurations.js.map +1 -0
  83. package/dist/compiler/internal/Contract.d.ts +27 -0
  84. package/dist/compiler/internal/Contract.d.ts.map +1 -0
  85. package/dist/compiler/internal/Contract.js +600 -0
  86. package/dist/compiler/internal/Contract.js.map +1 -0
  87. package/dist/compiler/internal/Contributions.d.ts +54 -0
  88. package/dist/compiler/internal/Contributions.d.ts.map +1 -0
  89. package/dist/compiler/internal/Contributions.js +1109 -0
  90. package/dist/compiler/internal/Contributions.js.map +1 -0
  91. package/dist/compiler/internal/Descriptors.d.ts +15 -0
  92. package/dist/compiler/internal/Descriptors.d.ts.map +1 -0
  93. package/dist/compiler/internal/Descriptors.js +183 -0
  94. package/dist/compiler/internal/Descriptors.js.map +1 -0
  95. package/dist/compiler/internal/Dynamic.d.ts +14 -0
  96. package/dist/compiler/internal/Dynamic.d.ts.map +1 -0
  97. package/dist/compiler/internal/Dynamic.js +172 -0
  98. package/dist/compiler/internal/Dynamic.js.map +1 -0
  99. package/dist/compiler/internal/Edits.d.ts +12 -0
  100. package/dist/compiler/internal/Edits.d.ts.map +1 -0
  101. package/dist/compiler/internal/Edits.js +5 -0
  102. package/dist/compiler/internal/Edits.js.map +1 -0
  103. package/dist/compiler/internal/Expression.d.ts +12 -0
  104. package/dist/compiler/internal/Expression.d.ts.map +1 -0
  105. package/dist/compiler/internal/Expression.js +98 -0
  106. package/dist/compiler/internal/Expression.js.map +1 -0
  107. package/dist/compiler/internal/Functions.d.ts +5 -0
  108. package/dist/compiler/internal/Functions.d.ts.map +1 -0
  109. package/dist/compiler/internal/Functions.js +191 -0
  110. package/dist/compiler/internal/Functions.js.map +1 -0
  111. package/dist/compiler/internal/Identifiers.d.ts +9 -0
  112. package/dist/compiler/internal/Identifiers.d.ts.map +1 -0
  113. package/dist/compiler/internal/Identifiers.js +106 -0
  114. package/dist/compiler/internal/Identifiers.js.map +1 -0
  115. package/dist/compiler/internal/Keyframes.d.ts +5 -0
  116. package/dist/compiler/internal/Keyframes.d.ts.map +1 -0
  117. package/dist/compiler/internal/Keyframes.js +51 -0
  118. package/dist/compiler/internal/Keyframes.js.map +1 -0
  119. package/dist/compiler/internal/Namespaces.d.ts +17 -0
  120. package/dist/compiler/internal/Namespaces.d.ts.map +1 -0
  121. package/dist/compiler/internal/Namespaces.js +265 -0
  122. package/dist/compiler/internal/Namespaces.js.map +1 -0
  123. package/dist/compiler/internal/NativeBindings.d.ts +74 -0
  124. package/dist/compiler/internal/NativeBindings.d.ts.map +1 -0
  125. package/dist/compiler/internal/NativeBindings.js +117 -0
  126. package/dist/compiler/internal/NativeBindings.js.map +1 -0
  127. package/dist/compiler/internal/PackedStyles.d.ts +35 -0
  128. package/dist/compiler/internal/PackedStyles.d.ts.map +1 -0
  129. package/dist/compiler/internal/PackedStyles.js +345 -0
  130. package/dist/compiler/internal/PackedStyles.js.map +1 -0
  131. package/dist/compiler/internal/Properties.d.ts +5 -0
  132. package/dist/compiler/internal/Properties.d.ts.map +1 -0
  133. package/dist/compiler/internal/Properties.js +82 -0
  134. package/dist/compiler/internal/Properties.js.map +1 -0
  135. package/dist/compiler/internal/RecipeConditions.d.ts +41 -0
  136. package/dist/compiler/internal/RecipeConditions.d.ts.map +1 -0
  137. package/dist/compiler/internal/RecipeConditions.js +82 -0
  138. package/dist/compiler/internal/RecipeConditions.js.map +1 -0
  139. package/dist/compiler/internal/RecipePayloads.d.ts +31 -0
  140. package/dist/compiler/internal/RecipePayloads.d.ts.map +1 -0
  141. package/dist/compiler/internal/RecipePayloads.js +99 -0
  142. package/dist/compiler/internal/RecipePayloads.js.map +1 -0
  143. package/dist/compiler/internal/Recipes.d.ts +32 -0
  144. package/dist/compiler/internal/Recipes.d.ts.map +1 -0
  145. package/dist/compiler/internal/Recipes.js +339 -0
  146. package/dist/compiler/internal/Recipes.js.map +1 -0
  147. package/dist/compiler/internal/Relative.d.ts +19 -0
  148. package/dist/compiler/internal/Relative.d.ts.map +1 -0
  149. package/dist/compiler/internal/Relative.js +62 -0
  150. package/dist/compiler/internal/Relative.js.map +1 -0
  151. package/dist/compiler/internal/Scope.d.ts +10 -0
  152. package/dist/compiler/internal/Scope.d.ts.map +1 -0
  153. package/dist/compiler/internal/Scope.js +28 -0
  154. package/dist/compiler/internal/Scope.js.map +1 -0
  155. package/dist/compiler/internal/Selectors.d.ts +12 -0
  156. package/dist/compiler/internal/Selectors.d.ts.map +1 -0
  157. package/dist/compiler/internal/Selectors.js +265 -0
  158. package/dist/compiler/internal/Selectors.js.map +1 -0
  159. package/dist/compiler/internal/Static.d.ts +39 -0
  160. package/dist/compiler/internal/Static.d.ts.map +1 -0
  161. package/dist/compiler/internal/Static.js +532 -0
  162. package/dist/compiler/internal/Static.js.map +1 -0
  163. package/dist/compiler/internal/Stylesheets.d.ts +47 -0
  164. package/dist/compiler/internal/Stylesheets.d.ts.map +1 -0
  165. package/dist/compiler/internal/Stylesheets.js +272 -0
  166. package/dist/compiler/internal/Stylesheets.js.map +1 -0
  167. package/dist/compiler/internal/Syntax.d.ts +17 -0
  168. package/dist/compiler/internal/Syntax.d.ts.map +1 -0
  169. package/dist/compiler/internal/Syntax.js +19 -0
  170. package/dist/compiler/internal/Syntax.js.map +1 -0
  171. package/dist/compiler/internal/Themes.d.ts +158 -0
  172. package/dist/compiler/internal/Themes.d.ts.map +1 -0
  173. package/dist/compiler/internal/Themes.js +1169 -0
  174. package/dist/compiler/internal/Themes.js.map +1 -0
  175. package/dist/compiler/internal/Variables.d.ts +31 -0
  176. package/dist/compiler/internal/Variables.d.ts.map +1 -0
  177. package/dist/compiler/internal/Variables.js +376 -0
  178. package/dist/compiler/internal/Variables.js.map +1 -0
  179. package/dist/compiler/internal/ViewTransitions.d.ts +3 -0
  180. package/dist/compiler/internal/ViewTransitions.d.ts.map +1 -0
  181. package/dist/compiler/internal/ViewTransitions.js +68 -0
  182. package/dist/compiler/internal/ViewTransitions.js.map +1 -0
  183. package/dist/cx.d.ts +18 -0
  184. package/dist/cx.d.ts.map +1 -0
  185. package/dist/cx.js +60 -0
  186. package/dist/cx.js.map +1 -0
  187. package/dist/default.d.ts +2008 -0
  188. package/dist/default.d.ts.map +1 -0
  189. package/dist/default.js +243 -0
  190. package/dist/default.js.map +7 -0
  191. package/dist/default.js.zyzz.json +1 -0
  192. package/dist/index.d.ts +21 -0
  193. package/dist/index.d.ts.map +1 -0
  194. package/dist/index.js +19 -0
  195. package/dist/index.js.map +1 -0
  196. package/dist/internal/Authoring.d.ts +26 -0
  197. package/dist/internal/Authoring.d.ts.map +1 -0
  198. package/dist/internal/Authoring.js +134 -0
  199. package/dist/internal/Authoring.js.map +1 -0
  200. package/dist/internal/Binding.d.ts +64 -0
  201. package/dist/internal/Binding.d.ts.map +1 -0
  202. package/dist/internal/Binding.js +27 -0
  203. package/dist/internal/Binding.js.map +1 -0
  204. package/dist/internal/BindingDomains.d.ts +11 -0
  205. package/dist/internal/BindingDomains.d.ts.map +1 -0
  206. package/dist/internal/BindingDomains.js +459 -0
  207. package/dist/internal/BindingDomains.js.map +1 -0
  208. package/dist/internal/Cascade.d.ts +45 -0
  209. package/dist/internal/Cascade.d.ts.map +1 -0
  210. package/dist/internal/Cascade.js +165 -0
  211. package/dist/internal/Cascade.js.map +1 -0
  212. package/dist/internal/Compound.d.ts +132 -0
  213. package/dist/internal/Compound.d.ts.map +1 -0
  214. package/dist/internal/Compound.js +2 -0
  215. package/dist/internal/Compound.js.map +1 -0
  216. package/dist/internal/Condition.d.ts +33 -0
  217. package/dist/internal/Condition.d.ts.map +1 -0
  218. package/dist/internal/Condition.js +180 -0
  219. package/dist/internal/Condition.js.map +1 -0
  220. package/dist/internal/Corner.d.ts +9 -0
  221. package/dist/internal/Corner.d.ts.map +1 -0
  222. package/dist/internal/Corner.js +14 -0
  223. package/dist/internal/Corner.js.map +1 -0
  224. package/dist/internal/FunctionSyntax.d.ts +27 -0
  225. package/dist/internal/FunctionSyntax.d.ts.map +1 -0
  226. package/dist/internal/FunctionSyntax.js +91 -0
  227. package/dist/internal/FunctionSyntax.js.map +1 -0
  228. package/dist/internal/FunctionValue.d.ts +19 -0
  229. package/dist/internal/FunctionValue.d.ts.map +1 -0
  230. package/dist/internal/FunctionValue.js +2 -0
  231. package/dist/internal/FunctionValue.js.map +1 -0
  232. package/dist/internal/Geometry.d.ts +8 -0
  233. package/dist/internal/Geometry.d.ts.map +1 -0
  234. package/dist/internal/Geometry.js +2 -0
  235. package/dist/internal/Geometry.js.map +1 -0
  236. package/dist/internal/Grid.d.ts +15 -0
  237. package/dist/internal/Grid.d.ts.map +1 -0
  238. package/dist/internal/Grid.js +2 -0
  239. package/dist/internal/Grid.js.map +1 -0
  240. package/dist/internal/Identifier.d.ts +15 -0
  241. package/dist/internal/Identifier.d.ts.map +1 -0
  242. package/dist/internal/Identifier.js +2 -0
  243. package/dist/internal/Identifier.js.map +1 -0
  244. package/dist/internal/Identity.d.ts +16 -0
  245. package/dist/internal/Identity.d.ts.map +1 -0
  246. package/dist/internal/Identity.js +78 -0
  247. package/dist/internal/Identity.js.map +1 -0
  248. package/dist/internal/Lexical.d.ts +89 -0
  249. package/dist/internal/Lexical.d.ts.map +1 -0
  250. package/dist/internal/Lexical.js +15 -0
  251. package/dist/internal/Lexical.js.map +1 -0
  252. package/dist/internal/Literal.d.ts +3459 -0
  253. package/dist/internal/Literal.d.ts.map +1 -0
  254. package/dist/internal/Literal.js +3371 -0
  255. package/dist/internal/Literal.js.map +1 -0
  256. package/dist/internal/NativeProperties.d.ts +596 -0
  257. package/dist/internal/NativeProperties.d.ts.map +1 -0
  258. package/dist/internal/NativeProperties.js +2 -0
  259. package/dist/internal/NativeProperties.js.map +1 -0
  260. package/dist/internal/Numeric.d.ts +23 -0
  261. package/dist/internal/Numeric.d.ts.map +1 -0
  262. package/dist/internal/Numeric.js +2 -0
  263. package/dist/internal/Numeric.js.map +1 -0
  264. package/dist/internal/Query.d.ts +15 -0
  265. package/dist/internal/Query.d.ts.map +1 -0
  266. package/dist/internal/Query.js +58 -0
  267. package/dist/internal/Query.js.map +1 -0
  268. package/dist/internal/Recipe.d.ts +17 -0
  269. package/dist/internal/Recipe.d.ts.map +1 -0
  270. package/dist/internal/Recipe.js +2 -0
  271. package/dist/internal/Recipe.js.map +1 -0
  272. package/dist/internal/RuleReference.d.ts +23 -0
  273. package/dist/internal/RuleReference.d.ts.map +1 -0
  274. package/dist/internal/RuleReference.js +65 -0
  275. package/dist/internal/RuleReference.js.map +1 -0
  276. package/dist/internal/Scheme.d.ts +12 -0
  277. package/dist/internal/Scheme.d.ts.map +1 -0
  278. package/dist/internal/Scheme.js +16 -0
  279. package/dist/internal/Scheme.js.map +1 -0
  280. package/dist/internal/Shorthands.d.ts +20 -0
  281. package/dist/internal/Shorthands.d.ts.map +1 -0
  282. package/dist/internal/Shorthands.js +49 -0
  283. package/dist/internal/Shorthands.js.map +1 -0
  284. package/dist/internal/Targets.d.ts +43 -0
  285. package/dist/internal/Targets.d.ts.map +1 -0
  286. package/dist/internal/Targets.js +60 -0
  287. package/dist/internal/Targets.js.map +1 -0
  288. package/dist/internal/Token.d.ts +104 -0
  289. package/dist/internal/Token.d.ts.map +1 -0
  290. package/dist/internal/Token.js +162 -0
  291. package/dist/internal/Token.js.map +1 -0
  292. package/dist/internal/Tuple.d.ts +23 -0
  293. package/dist/internal/Tuple.d.ts.map +1 -0
  294. package/dist/internal/Tuple.js +2 -0
  295. package/dist/internal/Tuple.js.map +1 -0
  296. package/dist/internal/Value.d.ts +74 -0
  297. package/dist/internal/Value.d.ts.map +1 -0
  298. package/dist/internal/Value.js +60 -0
  299. package/dist/internal/Value.js.map +1 -0
  300. package/dist/metro/Graph.d.ts +8 -0
  301. package/dist/metro/Graph.d.ts.map +1 -0
  302. package/dist/metro/Graph.js +63 -0
  303. package/dist/metro/Graph.js.map +1 -0
  304. package/dist/metro/Watch.d.ts +21 -0
  305. package/dist/metro/Watch.d.ts.map +1 -0
  306. package/dist/metro/Watch.js +51 -0
  307. package/dist/metro/Watch.js.map +1 -0
  308. package/dist/metro/index.d.ts +30 -0
  309. package/dist/metro/index.d.ts.map +1 -0
  310. package/dist/metro/index.js +52 -0
  311. package/dist/metro/index.js.map +1 -0
  312. package/dist/metro/transformer.d.ts +21 -0
  313. package/dist/metro/transformer.d.ts.map +1 -0
  314. package/dist/metro/transformer.js +71 -0
  315. package/dist/metro/transformer.js.map +1 -0
  316. package/dist/next/index.d.ts +18 -0
  317. package/dist/next/index.d.ts.map +1 -0
  318. package/dist/next/index.js +92 -0
  319. package/dist/next/index.js.map +1 -0
  320. package/dist/next/loader.d.ts +16 -0
  321. package/dist/next/loader.d.ts.map +1 -0
  322. package/dist/next/loader.js +282 -0
  323. package/dist/next/loader.js.map +1 -0
  324. package/dist/node/Host.d.ts +80 -0
  325. package/dist/node/Host.d.ts.map +1 -0
  326. package/dist/node/Host.js +882 -0
  327. package/dist/node/Host.js.map +1 -0
  328. package/dist/node/index.d.ts +7 -0
  329. package/dist/node/index.d.ts.map +1 -0
  330. package/dist/node/index.js +7 -0
  331. package/dist/node/index.js.map +1 -0
  332. package/dist/react-native/Host.d.ts +76 -0
  333. package/dist/react-native/Host.d.ts.map +1 -0
  334. package/dist/react-native/Host.js +209 -0
  335. package/dist/react-native/Host.js.map +1 -0
  336. package/dist/react-native/StyleSheet.d.ts +226 -0
  337. package/dist/react-native/StyleSheet.d.ts.map +1 -0
  338. package/dist/react-native/StyleSheet.js +606 -0
  339. package/dist/react-native/StyleSheet.js.map +1 -0
  340. package/dist/react-native/Variants.d.ts +38 -0
  341. package/dist/react-native/Variants.d.ts.map +1 -0
  342. package/dist/react-native/Variants.js +66 -0
  343. package/dist/react-native/Variants.js.map +1 -0
  344. package/dist/react-native/index.d.ts +8 -0
  345. package/dist/react-native/index.d.ts.map +1 -0
  346. package/dist/react-native/index.js +8 -0
  347. package/dist/react-native/index.js.map +1 -0
  348. package/dist/react-native/internal/Color.d.ts +7 -0
  349. package/dist/react-native/internal/Color.d.ts.map +1 -0
  350. package/dist/react-native/internal/Color.js +93 -0
  351. package/dist/react-native/internal/Color.js.map +1 -0
  352. package/dist/react-native/internal/NativeSchema.d.ts +5138 -0
  353. package/dist/react-native/internal/NativeSchema.d.ts.map +1 -0
  354. package/dist/react-native/internal/NativeSchema.js +3097 -0
  355. package/dist/react-native/internal/NativeSchema.js.map +1 -0
  356. package/dist/react-native/internal/Scalar.d.ts +95 -0
  357. package/dist/react-native/internal/Scalar.d.ts.map +1 -0
  358. package/dist/react-native/internal/Scalar.js +199 -0
  359. package/dist/react-native/internal/Scalar.js.map +1 -0
  360. package/dist/react-native/internal/Values.d.ts +5 -0
  361. package/dist/react-native/internal/Values.d.ts.map +1 -0
  362. package/dist/react-native/internal/Values.js +65 -0
  363. package/dist/react-native/internal/Values.js.map +1 -0
  364. package/dist/react-native/react.d.ts +22 -0
  365. package/dist/react-native/react.d.ts.map +1 -0
  366. package/dist/react-native/react.js +26 -0
  367. package/dist/react-native/react.js.map +1 -0
  368. package/dist/reset.css +244 -0
  369. package/dist/runtime/Appearance.d.ts +55 -0
  370. package/dist/runtime/Appearance.d.ts.map +1 -0
  371. package/dist/runtime/Appearance.js +84 -0
  372. package/dist/runtime/Appearance.js.map +1 -0
  373. package/dist/runtime/Composition.d.ts +46 -0
  374. package/dist/runtime/Composition.d.ts.map +1 -0
  375. package/dist/runtime/Composition.js +52 -0
  376. package/dist/runtime/Composition.js.map +1 -0
  377. package/dist/runtime/CompositionHtml.d.ts +15 -0
  378. package/dist/runtime/CompositionHtml.d.ts.map +1 -0
  379. package/dist/runtime/CompositionHtml.js +20 -0
  380. package/dist/runtime/CompositionHtml.js.map +1 -0
  381. package/dist/runtime/ConditionalRecipe.d.ts +30 -0
  382. package/dist/runtime/ConditionalRecipe.d.ts.map +1 -0
  383. package/dist/runtime/ConditionalRecipe.js +39 -0
  384. package/dist/runtime/ConditionalRecipe.js.map +1 -0
  385. package/dist/runtime/Dynamic.d.ts +19 -0
  386. package/dist/runtime/Dynamic.d.ts.map +1 -0
  387. package/dist/runtime/Dynamic.js +22 -0
  388. package/dist/runtime/Dynamic.js.map +1 -0
  389. package/dist/runtime/Html.d.ts +32 -0
  390. package/dist/runtime/Html.d.ts.map +1 -0
  391. package/dist/runtime/Html.js +63 -0
  392. package/dist/runtime/Html.js.map +1 -0
  393. package/dist/runtime/Native.d.ts +48 -0
  394. package/dist/runtime/Native.d.ts.map +1 -0
  395. package/dist/runtime/Native.js +78 -0
  396. package/dist/runtime/Native.js.map +1 -0
  397. package/dist/runtime/NativeContext.d.ts +17 -0
  398. package/dist/runtime/NativeContext.d.ts.map +1 -0
  399. package/dist/runtime/NativeContext.js +47 -0
  400. package/dist/runtime/NativeContext.js.map +1 -0
  401. package/dist/runtime/NativeDynamic.d.ts +47 -0
  402. package/dist/runtime/NativeDynamic.d.ts.map +1 -0
  403. package/dist/runtime/NativeDynamic.js +141 -0
  404. package/dist/runtime/NativeDynamic.js.map +1 -0
  405. package/dist/runtime/PayloadRecipe.d.ts +22 -0
  406. package/dist/runtime/PayloadRecipe.d.ts.map +1 -0
  407. package/dist/runtime/PayloadRecipe.js +59 -0
  408. package/dist/runtime/PayloadRecipe.js.map +1 -0
  409. package/dist/runtime/Props.d.ts +21 -0
  410. package/dist/runtime/Props.d.ts.map +1 -0
  411. package/dist/runtime/Props.js +17 -0
  412. package/dist/runtime/Props.js.map +1 -0
  413. package/dist/runtime/Recipe.d.ts +52 -0
  414. package/dist/runtime/Recipe.d.ts.map +1 -0
  415. package/dist/runtime/Recipe.js +30 -0
  416. package/dist/runtime/Recipe.js.map +1 -0
  417. package/dist/runtime/Selection.d.ts +31 -0
  418. package/dist/runtime/Selection.d.ts.map +1 -0
  419. package/dist/runtime/Selection.js +30 -0
  420. package/dist/runtime/Selection.js.map +1 -0
  421. package/dist/runtime/Variable.d.ts +6 -0
  422. package/dist/runtime/Variable.d.ts.map +1 -0
  423. package/dist/runtime/Variable.js +10 -0
  424. package/dist/runtime/Variable.js.map +1 -0
  425. package/dist/runtime/index.d.ts +33 -0
  426. package/dist/runtime/index.d.ts.map +1 -0
  427. package/dist/runtime/index.js +33 -0
  428. package/dist/runtime/index.js.map +1 -0
  429. package/dist/styleFunction.d.ts +72 -0
  430. package/dist/styleFunction.d.ts.map +1 -0
  431. package/dist/styleFunction.js +18 -0
  432. package/dist/styleFunction.js.map +1 -0
  433. package/dist/themes/LICENSE.tailwind +21 -0
  434. package/dist/variable.d.ts +50 -0
  435. package/dist/variable.d.ts.map +1 -0
  436. package/dist/variable.js +20 -0
  437. package/dist/variable.js.map +1 -0
  438. package/dist/variants.d.ts +84 -0
  439. package/dist/variants.d.ts.map +1 -0
  440. package/dist/variants.js +21 -0
  441. package/dist/variants.js.map +1 -0
  442. package/dist/vite/index.d.ts +24 -0
  443. package/dist/vite/index.d.ts.map +1 -0
  444. package/dist/vite/index.js +1089 -0
  445. package/dist/vite/index.js.map +1 -0
  446. package/dist/web/Css.d.ts +81 -0
  447. package/dist/web/Css.d.ts.map +1 -0
  448. package/dist/web/Css.js +593 -0
  449. package/dist/web/Css.js.map +1 -0
  450. package/dist/web/colorProfile.d.ts +28 -0
  451. package/dist/web/colorProfile.d.ts.map +1 -0
  452. package/dist/web/colorProfile.js +8 -0
  453. package/dist/web/colorProfile.js.map +1 -0
  454. package/dist/web/counterStyle.d.ts +48 -0
  455. package/dist/web/counterStyle.d.ts.map +1 -0
  456. package/dist/web/counterStyle.js +8 -0
  457. package/dist/web/counterStyle.js.map +1 -0
  458. package/dist/web/cssFunction.d.ts +80 -0
  459. package/dist/web/cssFunction.d.ts.map +1 -0
  460. package/dist/web/cssFunction.js +18 -0
  461. package/dist/web/cssFunction.js.map +1 -0
  462. package/dist/web/customMedia.d.ts +12 -0
  463. package/dist/web/customMedia.d.ts.map +1 -0
  464. package/dist/web/customMedia.js +7 -0
  465. package/dist/web/customMedia.js.map +1 -0
  466. package/dist/web/fontFace.d.ts +26 -0
  467. package/dist/web/fontFace.d.ts.map +1 -0
  468. package/dist/web/fontFace.js +7 -0
  469. package/dist/web/fontFace.js.map +1 -0
  470. package/dist/web/fontFeatureValues.d.ts +40 -0
  471. package/dist/web/fontFeatureValues.d.ts.map +1 -0
  472. package/dist/web/fontFeatureValues.js +7 -0
  473. package/dist/web/fontFeatureValues.js.map +1 -0
  474. package/dist/web/fontPaletteValues.d.ts +21 -0
  475. package/dist/web/fontPaletteValues.d.ts.map +1 -0
  476. package/dist/web/fontPaletteValues.js +9 -0
  477. package/dist/web/fontPaletteValues.js.map +1 -0
  478. package/dist/web/global.d.ts +19 -0
  479. package/dist/web/global.d.ts.map +1 -0
  480. package/dist/web/global.js +6 -0
  481. package/dist/web/global.js.map +1 -0
  482. package/dist/web/importCss.d.ts +18 -0
  483. package/dist/web/importCss.d.ts.map +1 -0
  484. package/dist/web/importCss.js +7 -0
  485. package/dist/web/importCss.js.map +1 -0
  486. package/dist/web/index.d.ts +22 -0
  487. package/dist/web/index.d.ts.map +1 -0
  488. package/dist/web/index.js +22 -0
  489. package/dist/web/index.js.map +1 -0
  490. package/dist/web/internal/Block.d.ts +18 -0
  491. package/dist/web/internal/Block.d.ts.map +1 -0
  492. package/dist/web/internal/Block.js +13 -0
  493. package/dist/web/internal/Block.js.map +1 -0
  494. package/dist/web/internal/ClassName.d.ts +19 -0
  495. package/dist/web/internal/ClassName.d.ts.map +1 -0
  496. package/dist/web/internal/ClassName.js +77 -0
  497. package/dist/web/internal/ClassName.js.map +1 -0
  498. package/dist/web/internal/Context.d.ts +11 -0
  499. package/dist/web/internal/Context.d.ts.map +1 -0
  500. package/dist/web/internal/Context.js +2 -0
  501. package/dist/web/internal/Context.js.map +1 -0
  502. package/dist/web/internal/Contributions.d.ts +70 -0
  503. package/dist/web/internal/Contributions.d.ts.map +1 -0
  504. package/dist/web/internal/Contributions.js +109 -0
  505. package/dist/web/internal/Contributions.js.map +1 -0
  506. package/dist/web/internal/Namespace.d.ts +13 -0
  507. package/dist/web/internal/Namespace.d.ts.map +1 -0
  508. package/dist/web/internal/Namespace.js +13 -0
  509. package/dist/web/internal/Namespace.js.map +1 -0
  510. package/dist/web/internal/Themes.d.ts +13 -0
  511. package/dist/web/internal/Themes.d.ts.map +1 -0
  512. package/dist/web/internal/Themes.js +96 -0
  513. package/dist/web/internal/Themes.js.map +1 -0
  514. package/dist/web/keyframes.d.ts +14 -0
  515. package/dist/web/keyframes.d.ts.map +1 -0
  516. package/dist/web/keyframes.js +8 -0
  517. package/dist/web/keyframes.js.map +1 -0
  518. package/dist/web/layers.d.ts +4 -0
  519. package/dist/web/layers.d.ts.map +1 -0
  520. package/dist/web/layers.js +7 -0
  521. package/dist/web/layers.js.map +1 -0
  522. package/dist/web/namespace.d.ts +14 -0
  523. package/dist/web/namespace.d.ts.map +1 -0
  524. package/dist/web/namespace.js +7 -0
  525. package/dist/web/namespace.js.map +1 -0
  526. package/dist/web/page.d.ts +38 -0
  527. package/dist/web/page.d.ts.map +1 -0
  528. package/dist/web/page.js +7 -0
  529. package/dist/web/page.js.map +1 -0
  530. package/dist/web/positionTry.d.ts +14 -0
  531. package/dist/web/positionTry.d.ts.map +1 -0
  532. package/dist/web/positionTry.js +9 -0
  533. package/dist/web/positionTry.js.map +1 -0
  534. package/dist/web/property.d.ts +24 -0
  535. package/dist/web/property.d.ts.map +1 -0
  536. package/dist/web/property.js +7 -0
  537. package/dist/web/property.js.map +1 -0
  538. package/dist/web/viewTransition.d.ts +29 -0
  539. package/dist/web/viewTransition.d.ts.map +1 -0
  540. package/dist/web/viewTransition.js +7 -0
  541. package/dist/web/viewTransition.js.map +1 -0
  542. package/package.json +136 -10
  543. package/src/Config.ts +690 -0
  544. package/src/Props.ts +8 -0
  545. package/src/Style.ts +748 -0
  546. package/src/Theme.ts +713 -0
  547. package/src/babel/NativeEdits.ts +273 -0
  548. package/src/babel/NativeJsx.ts +260 -0
  549. package/src/babel/index.ts +332 -0
  550. package/src/cli/index.ts +196 -0
  551. package/src/compiler/Graph.ts +1586 -0
  552. package/src/compiler/Native.ts +801 -0
  553. package/src/compiler/Source.ts +1550 -0
  554. package/src/compiler/Transform.ts +1235 -0
  555. package/src/compiler/index.ts +12 -0
  556. package/src/compiler/internal/Applications.ts +378 -0
  557. package/src/compiler/internal/AtRules.ts +202 -0
  558. package/src/compiler/internal/Catalogs.ts +114 -0
  559. package/src/compiler/internal/ColorProfiles.ts +93 -0
  560. package/src/compiler/internal/CompositionBindings.ts +120 -0
  561. package/src/compiler/internal/Compositions.ts +629 -0
  562. package/src/compiler/internal/Configurations.ts +244 -0
  563. package/src/compiler/internal/Contract.ts +846 -0
  564. package/src/compiler/internal/Contributions.ts +1507 -0
  565. package/src/compiler/internal/Descriptors.ts +238 -0
  566. package/src/compiler/internal/Dynamic.ts +266 -0
  567. package/src/compiler/internal/Edits.ts +13 -0
  568. package/src/compiler/internal/Expression.ts +135 -0
  569. package/src/compiler/internal/Functions.ts +206 -0
  570. package/src/compiler/internal/Identifiers.ts +124 -0
  571. package/src/compiler/internal/Keyframes.ts +62 -0
  572. package/src/compiler/internal/Namespaces.ts +296 -0
  573. package/src/compiler/internal/NativeBindings.ts +151 -0
  574. package/src/compiler/internal/PackedStyles.ts +464 -0
  575. package/src/compiler/internal/Properties.ts +121 -0
  576. package/src/compiler/internal/RecipeConditions.ts +139 -0
  577. package/src/compiler/internal/RecipePayloads.ts +132 -0
  578. package/src/compiler/internal/Recipes.ts +531 -0
  579. package/src/compiler/internal/Relative.ts +87 -0
  580. package/src/compiler/internal/Scope.ts +36 -0
  581. package/src/compiler/internal/Selectors.ts +334 -0
  582. package/src/compiler/internal/Static.ts +783 -0
  583. package/src/compiler/internal/Stylesheets.ts +361 -0
  584. package/src/compiler/internal/Syntax.ts +31 -0
  585. package/src/compiler/internal/Themes.ts +1794 -0
  586. package/src/compiler/internal/Variables.ts +497 -0
  587. package/src/compiler/internal/ViewTransitions.ts +82 -0
  588. package/src/cx.ts +98 -0
  589. package/src/default.ts +484 -0
  590. package/src/index.ts +20 -0
  591. package/src/internal/Authoring.ts +199 -0
  592. package/src/internal/Binding.ts +187 -0
  593. package/src/internal/BindingDomains.ts +458 -0
  594. package/src/internal/Cascade.ts +165 -0
  595. package/src/internal/Compound.ts +522 -0
  596. package/src/internal/Condition.ts +283 -0
  597. package/src/internal/Corner.ts +17 -0
  598. package/src/internal/FunctionSyntax.ts +271 -0
  599. package/src/internal/FunctionValue.ts +96 -0
  600. package/src/internal/Geometry.ts +30 -0
  601. package/src/internal/Grid.ts +67 -0
  602. package/src/internal/Identifier.ts +14 -0
  603. package/src/internal/Identity.ts +89 -0
  604. package/src/internal/Lexical.ts +202 -0
  605. package/src/internal/Literal.ts +3820 -0
  606. package/src/internal/NativeProperties.ts +936 -0
  607. package/src/internal/Numeric.ts +77 -0
  608. package/src/internal/Query.ts +87 -0
  609. package/src/internal/Recipe.ts +17 -0
  610. package/src/internal/RuleReference.ts +102 -0
  611. package/src/internal/Scheme.ts +20 -0
  612. package/src/internal/Shorthands.ts +120 -0
  613. package/src/internal/Targets.ts +162 -0
  614. package/src/internal/Token.ts +380 -0
  615. package/src/internal/Tuple.ts +29 -0
  616. package/src/internal/Value.ts +320 -0
  617. package/src/metro/Graph.ts +78 -0
  618. package/src/metro/Watch.ts +88 -0
  619. package/src/metro/index.ts +99 -0
  620. package/src/metro/transformer.ts +97 -0
  621. package/src/next/index.ts +114 -0
  622. package/src/next/loader.ts +369 -0
  623. package/src/node/Host.ts +1204 -0
  624. package/src/node/index.ts +6 -0
  625. package/src/react-native/Host.ts +289 -0
  626. package/src/react-native/StyleSheet.ts +1084 -0
  627. package/src/react-native/Variants.ts +122 -0
  628. package/src/react-native/index.ts +7 -0
  629. package/src/react-native/internal/Color.ts +110 -0
  630. package/src/react-native/internal/NativeSchema.ts +3096 -0
  631. package/src/react-native/internal/Scalar.ts +253 -0
  632. package/src/react-native/internal/Values.ts +87 -0
  633. package/src/react-native/react.ts +47 -0
  634. package/src/reset.css +244 -0
  635. package/src/runtime/Appearance.ts +155 -0
  636. package/src/runtime/Composition.ts +87 -0
  637. package/src/runtime/CompositionHtml.ts +38 -0
  638. package/src/runtime/ConditionalRecipe.ts +70 -0
  639. package/src/runtime/Dynamic.ts +51 -0
  640. package/src/runtime/Html.ts +91 -0
  641. package/src/runtime/Native.ts +144 -0
  642. package/src/runtime/NativeContext.ts +74 -0
  643. package/src/runtime/NativeDynamic.ts +246 -0
  644. package/src/runtime/PayloadRecipe.ts +96 -0
  645. package/src/runtime/Props.ts +33 -0
  646. package/src/runtime/Recipe.ts +74 -0
  647. package/src/runtime/Selection.ts +82 -0
  648. package/src/runtime/Variable.ts +15 -0
  649. package/src/runtime/index.ts +45 -0
  650. package/src/styleFunction.ts +138 -0
  651. package/src/themes/LICENSE.tailwind +21 -0
  652. package/src/variable.ts +105 -0
  653. package/src/variants.ts +218 -0
  654. package/src/vite/index.ts +1473 -0
  655. package/src/web/Css.ts +801 -0
  656. package/src/web/colorProfile.ts +60 -0
  657. package/src/web/counterStyle.ts +82 -0
  658. package/src/web/cssFunction.ts +181 -0
  659. package/src/web/customMedia.ts +16 -0
  660. package/src/web/fontFace.ts +41 -0
  661. package/src/web/fontFeatureValues.ts +79 -0
  662. package/src/web/fontPaletteValues.ts +42 -0
  663. package/src/web/global.ts +39 -0
  664. package/src/web/importCss.ts +23 -0
  665. package/src/web/index.ts +22 -0
  666. package/src/web/internal/Block.ts +29 -0
  667. package/src/web/internal/ClassName.ts +112 -0
  668. package/src/web/internal/Context.ts +16 -0
  669. package/src/web/internal/Contributions.ts +219 -0
  670. package/src/web/internal/Namespace.ts +21 -0
  671. package/src/web/internal/Themes.ts +133 -0
  672. package/src/web/keyframes.ts +43 -0
  673. package/src/web/layers.ts +6 -0
  674. package/src/web/namespace.ts +19 -0
  675. package/src/web/page.ts +140 -0
  676. package/src/web/positionTry.ts +71 -0
  677. package/src/web/property.ts +35 -0
  678. package/src/web/viewTransition.ts +89 -0
@@ -0,0 +1,1473 @@
1
+ /**
2
+ * Connects static Zyzz source compilation to Vite resolution and CSS delivery.
3
+ * @module
4
+ */
5
+ import * as Namespaces from '../compiler/internal/Namespaces.js'
6
+ import * as AtRules from '../compiler/internal/AtRules.js'
7
+ import * as Catalogs from '../compiler/internal/Catalogs.js'
8
+ import * as Mapping from '@jridgewell/gen-mapping'
9
+ import * as Lightning from 'lightningcss'
10
+ import * as Crypto from 'node:crypto'
11
+ import * as Fs from 'node:fs/promises'
12
+ import * as Path from 'node:path'
13
+ import * as Parser from 'oxc-parser'
14
+ import * as Walker from 'oxc-walker'
15
+ import * as Scope from '../compiler/internal/Scope.js'
16
+ import type { Environment, Plugin, Rollup, ViteDevServer } from 'vite'
17
+ import * as Graph from '../compiler/Graph.js'
18
+ import * as Source from '../compiler/Source.js'
19
+
20
+ /**
21
+ * Compiles physical project source without executing authoring code.
22
+ * Vite owns resolution, transpilation, CSS processing, watching, and HMR.
23
+ * @returns A Vite 8 plugin with isolated state for each environment.
24
+ */
25
+ export function zyzz(options: zyzz.Options = {}): Plugin {
26
+ const native = options.native
27
+ ? Object.freeze({
28
+ ...options.native,
29
+ fonts:
30
+ options.native.fonts && Object.freeze({ ...options.native.fonts }),
31
+ themes:
32
+ options.native.themes && Object.freeze({ ...options.native.themes }),
33
+ units:
34
+ options.native.units && Object.freeze({ ...options.native.units }),
35
+ })
36
+ : undefined
37
+ if (native && options.compiler === false)
38
+ throw new Error('Native builds require source compilation.')
39
+
40
+ const states = new WeakMap<Environment, Map<string, Entry>>()
41
+ const discoveries = new WeakMap<Environment, Promise<Map<string, string>>>()
42
+ const contributionFiles = new WeakMap<Environment, Set<string>>()
43
+ const assets = new Map<string, string>()
44
+ const catalogs = new Map<string, Catalogs.Catalog>()
45
+ const edges = new Map<string, ReadonlySet<string>>()
46
+ const graphs = new Map<string, ReadonlySet<string>>()
47
+ const initializers = new WeakMap<Environment, Entry>()
48
+ const sourceEntrypoints = new Set<string>()
49
+ let root: string
50
+
51
+ function entries(environment: Environment) {
52
+ let state = states.get(environment)
53
+
54
+ if (!state) {
55
+ state = new Map()
56
+ states.set(environment, state)
57
+ }
58
+
59
+ return state
60
+ }
61
+
62
+ function sourceId(file: string) {
63
+ return `app/${Path.relative(root, file).split(Path.sep).join('/')}`
64
+ }
65
+
66
+ function resource(id: string) {
67
+ const query = id.split('?')[1]?.split('#')[0]
68
+
69
+ return (
70
+ query !== undefined &&
71
+ [...new URLSearchParams(query).keys()].some(
72
+ (key) => !['v', 't', 'import'].includes(key),
73
+ )
74
+ )
75
+ }
76
+
77
+ function normalize(id: string) {
78
+ return resource(id) ? id : id.split('?')[0]!
79
+ }
80
+
81
+ function eligible(id: string) {
82
+ if (sourceEntrypoints.has(normalize(id))) return true
83
+ // Ids carrying foreign queries are Vite resources such as inline-module proxies, not source.
84
+ if (resource(id)) return false
85
+ const relative = Path.relative(root, id)
86
+
87
+ return (
88
+ Path.isAbsolute(id) &&
89
+ !relative.startsWith('..') &&
90
+ !relative.split(Path.sep).includes('node_modules') &&
91
+ /\.[cm]?[jt]sx?$/.test(id) &&
92
+ !/\.(?:d|test|test-d|bench)\.[cm]?[jt]sx?$/.test(id)
93
+ )
94
+ }
95
+
96
+ function discover(environment: Environment, host: Host) {
97
+ let pending = discoveries.get(environment)
98
+
99
+ if (!pending) {
100
+ pending = (async () => {
101
+ const sources = new Map<string, string>()
102
+ const eagerFiles = new Set<string>()
103
+
104
+ contributionFiles.set(environment, eagerFiles)
105
+
106
+ async function collect(directory: string): Promise<void> {
107
+ for (const item of await Fs.readdir(directory, {
108
+ withFileTypes: true,
109
+ })) {
110
+ if (
111
+ item.name.startsWith('.') ||
112
+ [
113
+ 'node_modules',
114
+ 'dist',
115
+ 'build',
116
+ 'coverage',
117
+ 'test',
118
+ 'tests',
119
+ '__tests__',
120
+ 'fixtures',
121
+ '__fixtures__',
122
+ ].includes(item.name)
123
+ )
124
+ continue
125
+
126
+ const file = Path.join(directory, item.name)
127
+
128
+ if (item.isDirectory()) await collect(file)
129
+ else if (item.isFile() && eager(file)) {
130
+ host.watch(file)
131
+
132
+ const source = await Fs.readFile(file, 'utf8')
133
+
134
+ sources.set(file, source)
135
+
136
+ if (contributes(source)) eagerFiles.add(file)
137
+ }
138
+ }
139
+ }
140
+
141
+ await collect(root)
142
+
143
+ return sources
144
+ })()
145
+ discoveries.set(environment, pending)
146
+ }
147
+
148
+ return pending
149
+ }
150
+
151
+ function eager(file: string) {
152
+ return (
153
+ eligible(file) &&
154
+ !Path.relative(root, file)
155
+ .split(Path.sep)
156
+ .some((part) =>
157
+ ['test', 'tests', '__tests__', 'fixtures', '__fixtures__'].includes(
158
+ part,
159
+ ),
160
+ )
161
+ )
162
+ }
163
+
164
+ function contributes(source: string) {
165
+ const { program } = Parser.parseSync('source.tsx', source, {
166
+ sourceType: 'module',
167
+ })
168
+ const imports = new Map<number, string>()
169
+
170
+ for (const node of program.body) {
171
+ if (node.type !== 'ImportDeclaration' || node.importKind === 'type')
172
+ continue
173
+
174
+ for (const specifier of node.specifiers) {
175
+ if (
176
+ specifier.type !== 'ImportSpecifier' ||
177
+ specifier.importKind === 'type'
178
+ )
179
+ continue
180
+
181
+ const name =
182
+ specifier.imported.type === 'Identifier'
183
+ ? specifier.imported.name
184
+ : specifier.imported.value
185
+
186
+ if (
187
+ node.source.value === 'zyzz/web'
188
+ ? [
189
+ 'colorProfile',
190
+ 'counterStyle',
191
+ 'cssFunction',
192
+ 'customMedia',
193
+ 'fontFace',
194
+ 'fontFeatureValues',
195
+ 'fontPaletteValues',
196
+ 'global',
197
+ 'importCss',
198
+ 'keyframes',
199
+ 'layers',
200
+ 'namespace',
201
+ 'page',
202
+ 'positionTry',
203
+ 'viewTransition',
204
+ ].includes(name)
205
+ : name === 'Config' || node.source.value !== 'zyzz'
206
+ )
207
+ imports.set(specifier.start, name)
208
+ }
209
+ }
210
+ // Local call imports are candidates; Graph follows their re-exports before emission.
211
+
212
+ if (!imports.size) return false
213
+
214
+ const scopeTracker = new Scope.Tracker({ preserveExitedScopes: true })
215
+
216
+ Walker.walk(program, { scopeTracker })
217
+ scopeTracker.freeze()
218
+
219
+ let found = false
220
+
221
+ Walker.walk(program, {
222
+ scopeTracker,
223
+ enter(node) {
224
+ if (node.type !== 'CallExpression') return
225
+
226
+ const callee = node.callee
227
+
228
+ if (callee.type === 'Identifier') {
229
+ const binding = scopeTracker.getDeclaration(callee.name)
230
+
231
+ if (
232
+ binding?.type === 'Import' &&
233
+ imports.has(binding.node.start) &&
234
+ imports.get(binding.node.start) !== 'Config'
235
+ )
236
+ found = true
237
+ } else if (
238
+ callee.type === 'MemberExpression' &&
239
+ callee.object.type === 'Identifier' &&
240
+ !callee.computed &&
241
+ callee.property.type === 'Identifier' &&
242
+ callee.property.name === 'create'
243
+ ) {
244
+ const binding = scopeTracker.getDeclaration(callee.object.name)
245
+ const argument = node.arguments[0]
246
+
247
+ if (
248
+ binding?.type === 'Import' &&
249
+ imports.get(binding.node.start) === 'Config' &&
250
+ argument?.type === 'ObjectExpression' &&
251
+ argument.properties.some(
252
+ (property) =>
253
+ property.type === 'Property' &&
254
+ (property.key.type === 'Identifier'
255
+ ? property.key.name === 'layers'
256
+ : property.key.type === 'Literal' &&
257
+ property.key.value === 'layers'),
258
+ )
259
+ )
260
+ found = true
261
+ }
262
+ },
263
+ })
264
+
265
+ return found
266
+ }
267
+
268
+ async function updateDiscovery(
269
+ environment: Environment,
270
+ file: string,
271
+ event: string,
272
+ ) {
273
+ if (event === 'delete') entries(environment).delete(file)
274
+
275
+ const pending = discoveries.get(environment)
276
+ if (!pending || !eager(file)) return
277
+
278
+ const sources = await pending
279
+
280
+ if (event === 'delete') sources.delete(file)
281
+ else {
282
+ const source = await Fs.readFile(file, 'utf8')
283
+
284
+ sources.set(file, source)
285
+
286
+ if (contributes(source)) contributionFiles.get(environment)?.add(file)
287
+ else contributionFiles.get(environment)?.delete(file)
288
+ }
289
+ }
290
+
291
+ async function compile(
292
+ entry: Entry,
293
+ host: Host,
294
+ code?: string,
295
+ allSources = false,
296
+ everything = false,
297
+ ) {
298
+ async function resolve(source: string, importer: string) {
299
+ const resolved = await host.resolve(source, importer)
300
+ if (!resolved) return resolved
301
+
302
+ if (entry.environment.mode === 'dev') {
303
+ const optimized = Object.values({
304
+ ...entry.environment.depsOptimizer?.metadata.optimized,
305
+ ...entry.environment.depsOptimizer?.metadata.discovered,
306
+ }).find((item) => item.file === resolved.id.split('?')[0])
307
+ if (optimized?.src) return { ...resolved, id: optimized.src }
308
+ }
309
+
310
+ return { ...resolved, id: normalize(resolved.id) }
311
+ }
312
+
313
+ const imports: Record<
314
+ string,
315
+ Record<string, string | null>
316
+ > = Object.create(null)
317
+ const contracts: Record<string, string> = Object.create(null)
318
+ const lazy: Record<string, ReadonlySet<string>> = Object.create(null)
319
+ const modules: Record<string, string> = Object.create(null)
320
+ const files = new Set<string>()
321
+
322
+ async function visit(file: string, source?: string) {
323
+ if (files.has(file)) return
324
+
325
+ files.add(file)
326
+ host.watch(file)
327
+
328
+ const id = sourceId(file)
329
+ const text = source ?? (await Fs.readFile(file, 'utf8'))
330
+
331
+ modules[id] = text
332
+
333
+ const resolutions: Record<string, string | null> = Object.create(null)
334
+
335
+ imports[id] = resolutions
336
+
337
+ const parsed = Parser.parseSync('source.tsx', text, {
338
+ sourceType: 'module',
339
+ })
340
+
341
+ for (const node of parsed.program.body) {
342
+ if (
343
+ (node.type !== 'ImportDeclaration' &&
344
+ node.type !== 'ExportNamedDeclaration' &&
345
+ node.type !== 'ExportAllDeclaration') ||
346
+ !node.source
347
+ )
348
+ continue
349
+
350
+ if (
351
+ node.type === 'ImportDeclaration'
352
+ ? node.importKind === 'type'
353
+ : node.exportKind === 'type'
354
+ )
355
+ continue
356
+
357
+ if (
358
+ 'specifiers' in node &&
359
+ node.specifiers.length &&
360
+ node.specifiers.every((specifier) =>
361
+ specifier.type === 'ImportSpecifier'
362
+ ? specifier.importKind === 'type'
363
+ : specifier.type === 'ExportSpecifier' &&
364
+ specifier.exportKind === 'type',
365
+ )
366
+ )
367
+ continue
368
+
369
+ const specifier = node.source.value
370
+
371
+ // Zyzz authoring and runtime entrypoints are handled by the static transform.
372
+ if (
373
+ specifier === 'zyzz' ||
374
+ (specifier.startsWith('zyzz/') && specifier !== 'zyzz/default')
375
+ ) {
376
+ resolutions[specifier] = null
377
+ continue
378
+ }
379
+
380
+ const resolved = await resolve(specifier, file)
381
+ if (!resolved)
382
+ throw new Source.ExtractError([
383
+ {
384
+ code: 'unsupported_syntax',
385
+ end: node.end,
386
+ message: `Unable to resolve ${JSON.stringify(specifier)}`,
387
+ source: file,
388
+ start: node.start,
389
+ },
390
+ ])
391
+
392
+ if (resource(specifier) || resource(resolved.id)) {
393
+ resolutions[specifier] = null
394
+ continue
395
+ }
396
+
397
+ if (
398
+ specifier === 'zyzz/default' &&
399
+ /[/\\]src[/\\]default\.[cm]?ts$/.test(resolved.id)
400
+ ) {
401
+ sourceEntrypoints.add(normalize(resolved.id))
402
+ resolutions[specifier] = sourceId(resolved.id)
403
+ await visit(resolved.id)
404
+ continue
405
+ }
406
+ if (resolved.external || !eligible(resolved.id)) {
407
+ const physical = resolved.id.split('?')[0]!.split('#')[0]!
408
+ const sidecar = `${physical}.zyzz.json`
409
+
410
+ if (Path.isAbsolute(physical) && /\.[cm]?[jt]sx?$/.test(physical)) {
411
+ try {
412
+ contracts[resolved.id] = await Fs.readFile(sidecar, 'utf8')
413
+ host.watch(sidecar)
414
+ files.add(sidecar)
415
+ resolutions[specifier] = resolved.id
416
+ continue
417
+ } catch (error) {
418
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT')
419
+ throw error
420
+ }
421
+ }
422
+
423
+ resolutions[specifier] = null
424
+ continue
425
+ }
426
+
427
+ resolutions[specifier] = sourceId(resolved.id)
428
+ await visit(resolved.id)
429
+ }
430
+
431
+ // Lazy imports stay outside this compile but scope the documents that load them.
432
+ const specifiers: string[] = []
433
+
434
+ Walker.walk(parsed.program, {
435
+ enter(node) {
436
+ if (
437
+ node.type === 'ImportExpression' &&
438
+ node.source.type === 'Literal' &&
439
+ typeof node.source.value === 'string'
440
+ )
441
+ specifiers.push(node.source.value)
442
+ },
443
+ })
444
+
445
+ const targets = new Set<string>()
446
+
447
+ for (const specifier of specifiers) {
448
+ if (specifier === 'zyzz' || specifier.startsWith('zyzz/')) continue
449
+
450
+ const resolved = await resolve(specifier, file)
451
+ if (!resolved || resource(specifier) || resource(resolved.id)) continue
452
+
453
+ targets.add(eligible(resolved.id) ? sourceId(resolved.id) : resolved.id)
454
+ }
455
+
456
+ lazy[id] = targets
457
+ }
458
+
459
+ await visit(entry.file, code)
460
+
461
+ const connected = new Set(files)
462
+ const entryContracts = new Set(Object.keys(contracts))
463
+
464
+ for (const [file, source] of await discover(entry.environment, host)) {
465
+ if (files.has(file) && !allSources) continue
466
+
467
+ const selected = contributionFiles.get(entry.environment)?.has(file)
468
+
469
+ if (allSources) {
470
+ const { program } = Parser.parseSync('source.tsx', source, {
471
+ sourceType: 'module',
472
+ })
473
+ const dynamic: import('@oxc-project/types').ImportExpression[] = []
474
+
475
+ Walker.walk(program, {
476
+ enter(node) {
477
+ if (
478
+ node.type === 'ImportExpression' &&
479
+ node.source.type === 'Literal' &&
480
+ typeof node.source.value === 'string'
481
+ )
482
+ dynamic.push(node)
483
+ },
484
+ })
485
+
486
+ for (const node of [...program.body, ...dynamic]) {
487
+ if (
488
+ (node.type !== 'ImportExpression' &&
489
+ node.type !== 'ImportDeclaration' &&
490
+ node.type !== 'ExportNamedDeclaration' &&
491
+ node.type !== 'ExportAllDeclaration') ||
492
+ !node.source
493
+ )
494
+ continue
495
+
496
+ if (
497
+ node.type === 'ImportExpression'
498
+ ? false
499
+ : node.type === 'ImportDeclaration'
500
+ ? node.importKind === 'type'
501
+ : node.exportKind === 'type'
502
+ )
503
+ continue
504
+
505
+ if (
506
+ 'specifiers' in node &&
507
+ node.specifiers.length &&
508
+ node.specifiers.every((specifier) =>
509
+ specifier.type === 'ImportSpecifier'
510
+ ? specifier.importKind === 'type'
511
+ : specifier.type === 'ExportSpecifier' &&
512
+ specifier.exportKind === 'type',
513
+ )
514
+ )
515
+ continue
516
+
517
+ if (
518
+ node.source.type !== 'Literal' ||
519
+ typeof node.source.value !== 'string'
520
+ )
521
+ continue
522
+
523
+ const specifier = node.source.value
524
+ if (
525
+ specifier === 'zyzz' ||
526
+ (specifier.startsWith('zyzz/') &&
527
+ specifier !== 'zyzz/default')
528
+ )
529
+ continue
530
+
531
+ const resolved = await resolve(specifier, file)
532
+ if (!resolved || (!resolved.external && eligible(resolved.id)))
533
+ continue
534
+
535
+ if (resource(specifier) || resource(resolved.id)) continue
536
+
537
+ const physical = resolved.id.split(/[?#]/)[0]!
538
+ if (!Path.isAbsolute(physical) || !/\.[cm]?[jt]sx?$/.test(physical))
539
+ continue
540
+
541
+ try {
542
+ const sidecar = `${physical}.zyzz.json`
543
+
544
+ contracts[resolved.id] = await Fs.readFile(sidecar, 'utf8')
545
+ host.watch(sidecar)
546
+ files.add(sidecar)
547
+
548
+ // Discover the package contribution without compiling unrelated authoring
549
+ // expressions in an otherwise unreachable source file.
550
+ const discovery = `${sourceId(file)}.zyzz-discovery`
551
+
552
+ modules[discovery] =
553
+ (modules[discovery] ?? '') +
554
+ `import ${JSON.stringify(specifier)};\n`
555
+ ;(imports[discovery] ??= Object.create(null))[specifier] =
556
+ resolved.id
557
+ } catch (error) {
558
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
559
+ }
560
+ }
561
+ }
562
+
563
+ // A whole-project compile reads disk so the document never trails the watcher.
564
+ if (everything) await visit(file)
565
+ else if (selected) await visit(file, source)
566
+ }
567
+
568
+ const loaded = new Set<string>()
569
+
570
+ async function dependencies(id: string): Promise<void> {
571
+ if (loaded.has(id)) return
572
+
573
+ loaded.add(id)
574
+
575
+ const metadata = (() => {
576
+ try {
577
+ return JSON.parse(contracts[id]!)
578
+ } catch (error) {
579
+ Graph.compile({ modules: {}, contracts: { [id]: contracts[id]! } })
580
+ throw error
581
+ }
582
+ })()
583
+ if (!Array.isArray(metadata?.stylesheets)) return
584
+
585
+ for (const section of metadata.stylesheets) {
586
+ if (!Array.isArray(section?.dependency)) continue
587
+
588
+ let owner = id
589
+
590
+ for (const specifier of section.dependency) {
591
+ if (
592
+ typeof specifier !== 'string' ||
593
+ !specifier ||
594
+ specifier.includes('\0')
595
+ )
596
+ throw new Error('Invalid packed stylesheet dependency.')
597
+
598
+ const target = await resolve(specifier, owner)
599
+ if (!target || !Path.isAbsolute(target.id))
600
+ throw new Error('Unable to resolve packed stylesheet dependency.')
601
+
602
+ imports[owner] ??= Object.create(null)
603
+ imports[owner]![specifier] = target.id
604
+
605
+ if (!Object.hasOwn(contracts, target.id)) {
606
+ const sidecar = `${target.id.split(/[?#]/)[0]}.zyzz.json`
607
+
608
+ contracts[target.id] = await Fs.readFile(sidecar, 'utf8')
609
+ host.watch(sidecar)
610
+ files.add(sidecar)
611
+ }
612
+
613
+ await dependencies(target.id)
614
+ owner = target.id
615
+ }
616
+ }
617
+ }
618
+
619
+ for (const id of Object.keys(contracts)) await dependencies(id)
620
+
621
+ // The entry's authored import closure scopes document initialization in
622
+ // builds, including packed contracts reached through other contracts.
623
+ for (const id of entryContracts)
624
+ for (const target of Object.values(imports[id] ?? {}))
625
+ if (target !== null) entryContracts.add(target)
626
+
627
+ // Static and lazy edges let a served document keep only the catalogs its scripts reach.
628
+ const staged = new Map<string, ReadonlySet<string>>()
629
+
630
+ for (const [id, resolutions] of Object.entries(imports))
631
+ staged.set(
632
+ id,
633
+ new Set([
634
+ ...Object.values(resolutions).filter(
635
+ (target): target is string => target !== null,
636
+ ),
637
+ ...(lazy[id] ?? []),
638
+ ]),
639
+ )
640
+
641
+ const result = entry.compiler.compile({
642
+ compiler: options.compiler,
643
+ native,
644
+ contracts,
645
+ development: entry.environment.mode !== 'build',
646
+ imports,
647
+ modules,
648
+ })
649
+
650
+ if (native) {
651
+ const output = result.modules[sourceId(entry.file)]!
652
+ entry.files = files
653
+ const map = Mapping.toEncodedMap(new Mapping.GenMapping())
654
+ return {
655
+ code: output.code,
656
+ contractIds: Object.keys(result.contracts),
657
+ css: '',
658
+ sharedCss: '',
659
+ cssMap: map,
660
+ sharedCssMap: map,
661
+ map: {
662
+ ...output.map,
663
+ sources: output.map.sources.map((source) =>
664
+ source === null ? null : Path.join(root, source.slice(4)),
665
+ ),
666
+ },
667
+ }
668
+ }
669
+
670
+ // The graph publishes after the compile succeeds, so a broken edit keeps
671
+ // scoping documents through the last good graph beside the kept catalogs.
672
+ graphs.set(
673
+ entry.file,
674
+ new Set([...[...connected].map(sourceId), ...entryContracts]),
675
+ )
676
+
677
+ for (const [id, targets] of staged) edges.set(id, targets)
678
+
679
+ // Packed dependencies contribute catalogs beside the modules compiled here.
680
+ const compiled = { ...contracts, ...result.contracts }
681
+
682
+ // A module owns its catalog keys; recompiling it replaces every
683
+ // configuration it had, including a module that no longer emits a contract.
684
+ for (const id of new Set([
685
+ ...Object.keys(modules),
686
+ ...Object.keys(compiled),
687
+ ]))
688
+ for (const key of catalogs.keys())
689
+ if (key.startsWith(`${id}\0`)) catalogs.delete(key)
690
+
691
+ for (const [id, contract] of Object.entries(compiled))
692
+ for (const configuration of Catalogs.read(contract))
693
+ catalogs.set(`${id}\0${configuration.identity}`, configuration)
694
+
695
+ const map = new Mapping.GenMapping()
696
+ const styles: string[] = []
697
+ let line = 0
698
+
699
+ for (const [id, output] of Object.entries(result.modules)) {
700
+ if (!connected.has(Path.join(root, id.slice(4)))) continue
701
+ if (!output.css) continue
702
+
703
+ for (const mapping of Mapping.allMappings(
704
+ Mapping.fromMap(JSON.stringify(output.cssMap)),
705
+ )) {
706
+ const generated = {
707
+ column: mapping.generated.column,
708
+ line: mapping.generated.line + line,
709
+ }
710
+
711
+ if (mapping.source !== undefined && mapping.original !== undefined) {
712
+ const location = {
713
+ generated,
714
+ original: mapping.original,
715
+ source: Path.join(root, mapping.source.slice(4)),
716
+ }
717
+
718
+ if (mapping.name === undefined) Mapping.addMapping(map, location)
719
+ else Mapping.addMapping(map, { ...location, name: mapping.name })
720
+ } else Mapping.addMapping(map, { generated })
721
+ }
722
+
723
+ for (const [index, source] of output.cssMap.sources.entries())
724
+ if (source !== null)
725
+ Mapping.setSourceContent(
726
+ map,
727
+ Path.join(root, source.slice(4)),
728
+ output.cssMap.sourcesContent?.[index] ?? null,
729
+ )
730
+
731
+ styles.push(output.css)
732
+ line += output.css.split('\n').length
733
+ }
734
+
735
+ const appRoot = await Fs.realpath(root)
736
+ const owners = new Map<string, string>()
737
+
738
+ for (const id of new Set(Object.values(result.sharedAssetOwners ?? {}))) {
739
+ if (!Path.isAbsolute(id)) continue
740
+
741
+ let directory = Path.dirname(id.split(/[?#]/)[0]!)
742
+
743
+ for (;;) {
744
+ try {
745
+ await Fs.access(Path.join(directory, 'package.json'))
746
+ owners.set(id, await Fs.realpath(directory))
747
+ break
748
+ } catch (error) {
749
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
750
+ }
751
+
752
+ const parent = Path.dirname(directory)
753
+ if (parent === directory)
754
+ throw new Error('Packed assets require an owning package.json.')
755
+
756
+ directory = parent
757
+ }
758
+ }
759
+
760
+ const assetUrls = new Map<string, string>()
761
+
762
+ for (const [key, target] of Object.entries(result.sharedAssets ?? {})) {
763
+ const raw = target.split(/[?#]/)[0]!
764
+
765
+ const file = await Fs.realpath(
766
+ target.startsWith('app/')
767
+ ? Path.join(root, decodeURIComponent(raw.slice(4)))
768
+ : Path.isAbsolute(raw)
769
+ ? decodeURIComponent(raw)
770
+ : (() => {
771
+ throw new Error('Asset path escapes the Vite graph.')
772
+ })(),
773
+ )
774
+
775
+ const identity = result.sharedAssetOwners?.[key]
776
+
777
+ const owner = identity?.startsWith('app/')
778
+ ? appRoot
779
+ : identity
780
+ ? owners.get(identity)
781
+ : undefined
782
+
783
+ const relative = owner ? Path.relative(owner, file) : '..'
784
+ if (
785
+ relative === '..' ||
786
+ relative.startsWith(`..${Path.sep}`) ||
787
+ Path.isAbsolute(relative)
788
+ )
789
+ throw new Error('Asset path escapes its owning package.')
790
+
791
+ host.watch(file)
792
+ files.add(file)
793
+
794
+ let url: string
795
+
796
+ if (/[?#%]/.test(file)) {
797
+ if (entry.environment.mode === 'build') {
798
+ url = await host.asset(file)
799
+
800
+ if (target.slice(raw.length)) url += `$_${target.slice(raw.length)}__`
801
+ } else {
802
+ url = `/@zyzz/asset/${Crypto.hash('sha256', file)}/${encodeURIComponent(Path.basename(file))}`
803
+ assets.set(url, file)
804
+ url += target.slice(raw.length)
805
+ }
806
+ } else {
807
+ const pathname = file
808
+ .replaceAll('\\', '/')
809
+ .split('/')
810
+ .map((part, index) =>
811
+ index === 0 && /^[a-z]:$/i.test(part)
812
+ ? part
813
+ : encodeURIComponent(part),
814
+ )
815
+ .join('/')
816
+
817
+ url = `/@fs/${pathname}${target.slice(raw.length)}`
818
+ }
819
+
820
+ assetUrls.set(target, url)
821
+ }
822
+
823
+ const shared = !Object.keys(result.sharedAssets ?? {}).length
824
+ ? {
825
+ code: new TextEncoder().encode(result.sharedCss ?? ''),
826
+ map: new TextEncoder().encode(
827
+ JSON.stringify(
828
+ result.sharedCssMap ??
829
+ Mapping.toEncodedMap(new Mapping.GenMapping()),
830
+ ),
831
+ ),
832
+ }
833
+ : AtRules.transform({
834
+ filename: 'zyzz.shared.css',
835
+ code: new TextEncoder().encode(result.sharedCss ?? ''),
836
+ sourceMap: true,
837
+ inputSourceMap: JSON.stringify(
838
+ result.sharedCssMap ??
839
+ Mapping.toEncodedMap(new Mapping.GenMapping()),
840
+ ),
841
+ visitor: {
842
+ Rule(rule) {
843
+ if (rule.type !== 'import') return
844
+ const target = result.sharedAssets?.[rule.value.url]
845
+ if (target)
846
+ return AtRules.relocateImport(
847
+ rule.value,
848
+ assetUrls.get(target)!,
849
+ )
850
+ },
851
+ Url(url) {
852
+ const target = result.sharedAssets?.[url.url]
853
+ if (!target) return
854
+
855
+ return { ...url, url: assetUrls.get(target)! }
856
+ },
857
+ },
858
+ })
859
+
860
+ const sharedMap = JSON.parse(
861
+ new TextDecoder().decode(shared.map!),
862
+ ) as Mapping.EncodedSourceMap
863
+
864
+ sharedMap.sources = sharedMap.sources.map((source) =>
865
+ source?.startsWith('app/') ? Path.join(root, source.slice(4)) : source,
866
+ )
867
+
868
+ const output = result.modules[sourceId(entry.file)]!
869
+
870
+ entry.files = files
871
+
872
+ return {
873
+ code: output.code,
874
+ contractIds: Object.keys(compiled),
875
+ css: styles.join('\n'),
876
+ sharedCss: new TextDecoder().decode(shared.code),
877
+ sharedCssMap: sharedMap,
878
+ cssMap: Mapping.toEncodedMap(map),
879
+ map: {
880
+ ...output.map,
881
+ sources: output.map.sources.map((source) =>
882
+ source === null ? null : Path.join(root, source.slice(4)),
883
+ ),
884
+ },
885
+ }
886
+ }
887
+
888
+ /** Compiles every discovered source once so index.html can inline each configuration's script before modules load. */
889
+ async function initializations(server: ViteDevServer) {
890
+ const environment = server.environments.client
891
+ const host: Host = {
892
+ asset: async (file) => file,
893
+ resolve: (source, importer) =>
894
+ environment.pluginContainer.resolveId(source, importer),
895
+ watch: (file) => server.watcher.add(file),
896
+ }
897
+ const sources = await discover(environment, host)
898
+ let entry = initializers.get(environment)
899
+
900
+ // The seed only anchors the compile, which visits every discovered source.
901
+ if (!entry || !sources.has(entry.file)) {
902
+ const file = sources.keys().next().value
903
+ if (file === undefined) return []
904
+
905
+ entry = {
906
+ compiler: Graph.create(),
907
+ environment,
908
+ file,
909
+ files: new Set([file]),
910
+ }
911
+ initializers.set(environment, entry)
912
+ }
913
+
914
+ // A source error surfaces through that module's own transform and overlay.
915
+ // The document keeps loading with the catalogs collected before the edit.
916
+ const output = await compile(entry, host, undefined, true, true).catch(
917
+ () => undefined,
918
+ )
919
+
920
+ // This compile saw the whole project, so contracts it no longer produces are gone.
921
+ if (output)
922
+ for (const key of catalogs.keys())
923
+ if (!output.contractIds.some((id) => key.startsWith(`${id}\0`)))
924
+ catalogs.delete(key)
925
+
926
+ return [...catalogs.values()]
927
+ }
928
+
929
+ /** Catalogs reachable from a served document's module scripts; every catalog when none resolve. */
930
+ async function documentCatalogs(
931
+ html: string,
932
+ filename: string,
933
+ resolve: Host['resolve'],
934
+ ) {
935
+ const reachable = new Set<string>()
936
+
937
+ const add = (specifier: string) => {
938
+ if (/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(specifier)) return
939
+
940
+ const path = specifier.split(/[?#]/)[0]!
941
+
942
+ // Vite's inline-module proxies point back at the document itself.
943
+ if (/\.html?$/i.test(path)) return
944
+
945
+ reachable.add(
946
+ sourceId(
947
+ path.startsWith('/')
948
+ ? Path.join(root, path)
949
+ : Path.resolve(Path.dirname(filename), path),
950
+ ),
951
+ )
952
+ }
953
+
954
+ // Vite rewrites inline modules into proxy URLs before this hook runs, so
955
+ // the document on disk supplies their imports beside the served markup.
956
+ const original = await Fs.readFile(filename, 'utf8').catch(() => html)
957
+
958
+ for (const document of new Set([html, original]))
959
+ for (const [, attributes, content] of document.matchAll(
960
+ /<script\b([^>]*)>([\s\S]*?)<\/script>/gi,
961
+ )) {
962
+ if (!/\btype\s*=\s*["']?module["']?/i.test(attributes!)) continue
963
+
964
+ const source = /\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/i.exec(
965
+ attributes!,
966
+ )
967
+ const src = source?.[1] ?? source?.[2] ?? source?.[3]
968
+
969
+ if (src) {
970
+ add(src)
971
+ continue
972
+ }
973
+
974
+ // Inline modules import relative to the document, as Vite's HTML
975
+ // proxy resolves them; aliases and packages resolve through Vite.
976
+ for (const specifier of inlineImports(content!)) {
977
+ if (/^\.{0,2}\//.test(specifier)) {
978
+ add(specifier)
979
+ continue
980
+ }
981
+ if (specifier === 'zyzz' || specifier.startsWith('zyzz/')) continue
982
+
983
+ const resolved = await resolve(specifier, filename).catch(() => null)
984
+ if (!resolved || resource(resolved.id)) continue
985
+
986
+ reachable.add(
987
+ eligible(resolved.id) ? sourceId(resolved.id) : resolved.id,
988
+ )
989
+ }
990
+ }
991
+
992
+ if (![...reachable].some((id) => edges.has(id)))
993
+ return [...catalogs.values()]
994
+
995
+ for (const id of reachable)
996
+ for (const target of edges.get(id) ?? []) reachable.add(target)
997
+
998
+ return [...catalogs]
999
+ .filter(([key]) => reachable.has(key.split('\0')[0]!))
1000
+ .map(([, configuration]) => configuration)
1001
+ }
1002
+
1003
+ /** Static and literal dynamic import specifiers of an inline module script; none when it fails to parse. */
1004
+ function inlineImports(content: string): readonly string[] {
1005
+ const specifiers: string[] = []
1006
+
1007
+ try {
1008
+ const { program } = Parser.parseSync('inline.ts', content, {
1009
+ sourceType: 'module',
1010
+ })
1011
+
1012
+ Walker.walk(program, {
1013
+ enter(node) {
1014
+ if (
1015
+ (node.type === 'ImportDeclaration' ||
1016
+ node.type === 'ExportNamedDeclaration' ||
1017
+ node.type === 'ExportAllDeclaration') &&
1018
+ node.source
1019
+ )
1020
+ specifiers.push(node.source.value)
1021
+
1022
+ if (
1023
+ node.type === 'ImportExpression' &&
1024
+ node.source.type === 'Literal' &&
1025
+ typeof node.source.value === 'string'
1026
+ )
1027
+ specifiers.push(node.source.value)
1028
+ },
1029
+ })
1030
+ } catch {
1031
+ return []
1032
+ }
1033
+
1034
+ return specifiers
1035
+ }
1036
+
1037
+ /** Catalogs contributed by the modules an HTML entry bundles; every catalog without an entry chunk. */
1038
+ function entryCatalogs(
1039
+ bundle?: Rollup.OutputBundle,
1040
+ chunk?: Rollup.OutputChunk,
1041
+ ) {
1042
+ if (!bundle || !chunk) return [...catalogs.values()]
1043
+
1044
+ const contracts = new Set<string>()
1045
+ const visited = new Set<string>()
1046
+
1047
+ function collect(name: string) {
1048
+ if (visited.has(name)) return
1049
+
1050
+ visited.add(name)
1051
+
1052
+ const output = bundle![name]
1053
+ if (output?.type !== 'chunk') return
1054
+
1055
+ // Source graphs follow authored imports, so a configuration compiled away
1056
+ // from the bundle still initializes the pages that authored it.
1057
+ for (const id of Object.keys(output.modules))
1058
+ for (const contract of graphs.get(normalize(id)) ?? [])
1059
+ contracts.add(contract)
1060
+
1061
+ for (const imported of [...output.imports, ...output.dynamicImports])
1062
+ collect(imported)
1063
+ }
1064
+
1065
+ collect(chunk.fileName)
1066
+
1067
+ return [...catalogs]
1068
+ .filter(([key]) => contracts.has(key.split('\0')[0]!))
1069
+ .map(([, configuration]) => configuration)
1070
+ }
1071
+
1072
+ return {
1073
+ config: {
1074
+ order: 'post',
1075
+ handler(config) {
1076
+ if (native) return
1077
+ // Inline color-scheme changes cannot initialize Lightning's lowered helpers.
1078
+ return {
1079
+ build: {
1080
+ cssTarget: config.build?.cssTarget ??
1081
+ config.build?.target ?? [
1082
+ 'chrome123',
1083
+ 'edge123',
1084
+ 'firefox120',
1085
+ 'safari17.5',
1086
+ ],
1087
+ },
1088
+ css: {
1089
+ lightningcss: {
1090
+ targets: config.css?.lightningcss?.targets ?? {
1091
+ chrome: 123 << 16,
1092
+ edge: 123 << 16,
1093
+ firefox: 120 << 16,
1094
+ safari: (17 << 16) | (5 << 8),
1095
+ },
1096
+ exclude:
1097
+ (config.css?.lightningcss?.exclude ?? 0) |
1098
+ Lightning.Features.LightDark,
1099
+ },
1100
+ },
1101
+ }
1102
+ },
1103
+ },
1104
+ configureServer(server) {
1105
+ server.middlewares.use((request, response, next) => {
1106
+ const path = new URL(request.url ?? '/', 'http://localhost').pathname
1107
+ const file = assets.get(path)
1108
+ if (!file) return next()
1109
+
1110
+ Fs.readFile(file).then((content) => {
1111
+ response.setHeader(
1112
+ 'Content-Type',
1113
+ file.endsWith('.svg')
1114
+ ? 'image/svg+xml'
1115
+ : 'application/octet-stream',
1116
+ )
1117
+ response.setHeader('Cache-Control', 'no-cache')
1118
+ response.end(content)
1119
+ }, next)
1120
+ })
1121
+ },
1122
+ configResolved(config) {
1123
+ root = config.root
1124
+ if (native) return
1125
+ const lightning = (config.css.lightningcss ??= {})
1126
+ lightning.include =
1127
+ (lightning.include ?? 0) & ~Lightning.Features.LightDark
1128
+ lightning.exclude =
1129
+ (lightning.exclude ?? 0) | Lightning.Features.LightDark
1130
+
1131
+ // The exclusion also affects imported application CSS.
1132
+ const target = config.build.cssTarget
1133
+ const browsers = (Array.isArray(target) ? target : [target]).flatMap(
1134
+ (value) => {
1135
+ if (!value)
1136
+ throw new Error('Zyzz requires an explicit browser CSS target.')
1137
+ const match =
1138
+ /^(chrome|edge|firefox|safari|ios|opera|ie)([0-9.]+)$/.exec(value)
1139
+ if (!match)
1140
+ throw new Error(
1141
+ `Zyzz cannot verify light-dark() support for CSS target: ${value}`,
1142
+ )
1143
+
1144
+ return [`${match[1] === 'ios' ? 'ios_saf' : match[1]} ${match[2]}`]
1145
+ },
1146
+ )
1147
+
1148
+ for (const targets of [
1149
+ Lightning.browserslistToTargets(browsers),
1150
+ lightning.targets ?? {},
1151
+ ]) {
1152
+ const result = Lightning.transform({
1153
+ code: new TextEncoder().encode(
1154
+ '.theme{color:light-dark(white,black)}',
1155
+ ),
1156
+ filename: 'zyzz-theme-target.css',
1157
+ targets,
1158
+ })
1159
+ if (!new TextDecoder().decode(result.code).includes('light-dark('))
1160
+ throw new Error(
1161
+ 'Zyzz theme colours require native light-dark() support. Set CSS targets to Chrome/Edge 123+, Firefox 120+, or Safari/iOS 17.5+.',
1162
+ )
1163
+ }
1164
+ },
1165
+ enforce: 'pre',
1166
+ generateBundle: {
1167
+ order: 'post',
1168
+ handler(_, bundle) {
1169
+ if (native) return
1170
+ for (const output of Object.values(bundle)) {
1171
+ if (output.type !== 'asset' || !output.fileName.endsWith('.css'))
1172
+ continue
1173
+ const css =
1174
+ typeof output.source === 'string'
1175
+ ? output.source
1176
+ : new TextDecoder().decode(output.source)
1177
+ const external = bundle[`${output.fileName}.map`]
1178
+ const inline = css.match(
1179
+ /\/\*# sourceMappingURL=data:application\/json(?:;charset=[^;,]+)?;base64,([A-Za-z0-9+/=]+)\s*\*\//,
1180
+ )
1181
+ const previous =
1182
+ external?.type === 'asset'
1183
+ ? (JSON.parse(
1184
+ typeof external.source === 'string'
1185
+ ? external.source
1186
+ : new TextDecoder().decode(external.source),
1187
+ ) as Mapping.EncodedSourceMap)
1188
+ : inline
1189
+ ? (JSON.parse(
1190
+ Buffer.from(inline[1]!, 'base64').toString(),
1191
+ ) as Mapping.EncodedSourceMap)
1192
+ : undefined
1193
+ const result = Namespaces.bundle(css, previous)
1194
+ let restored = AtRules.rename(
1195
+ AtRules.rename(
1196
+ result.css,
1197
+ '-zyzz-ffv-000000000',
1198
+ 'font-feature-values',
1199
+ ),
1200
+ '-zyzz-fpv-000000000',
1201
+ 'font-palette-values',
1202
+ )
1203
+ if (result.map && external?.type === 'asset')
1204
+ external.source = JSON.stringify(result.map)
1205
+ if (result.map && inline)
1206
+ restored = restored.replace(
1207
+ inline[0],
1208
+ `/*# sourceMappingURL=data:application/json;base64,${Buffer.from(JSON.stringify(result.map)).toString('base64')} */`,
1209
+ )
1210
+ output.source = restored
1211
+ }
1212
+ },
1213
+ },
1214
+ async watchChange(file, change) {
1215
+ await updateDiscovery(this.environment, file, change.event)
1216
+ },
1217
+ async hotUpdate({ file, modules, timestamp, type }) {
1218
+ await updateDiscovery(this.environment, file, type)
1219
+
1220
+ const affected = new Set(modules)
1221
+
1222
+ for (const entry of entries(this.environment).values()) {
1223
+ if (!entry.files.has(file) && !eager(file)) continue
1224
+
1225
+ // Theme scopes affect CSS even when Vite's JavaScript import was erased.
1226
+ for (const id of [entry.file, cssId(entry.file), sharedId]) {
1227
+ const module = this.environment.moduleGraph.getModuleById(id)
1228
+ if (!module) continue
1229
+
1230
+ this.environment.moduleGraph.invalidateModule(
1231
+ module,
1232
+ new Set(),
1233
+ timestamp,
1234
+ true,
1235
+ )
1236
+ affected.add(module)
1237
+ }
1238
+ }
1239
+
1240
+ return [...affected]
1241
+ },
1242
+ async load(id) {
1243
+ if (!id.startsWith(prefix)) return
1244
+
1245
+ const file =
1246
+ id === sharedId
1247
+ ? undefined
1248
+ : decodeURIComponent(id.slice(prefix.length, -4))
1249
+ const entry =
1250
+ file === undefined
1251
+ ? entries(this.environment).values().next().value
1252
+ : entries(this.environment).get(file)
1253
+ if (!entry) throw new Error(`Unknown Zyzz stylesheet: ${file}`)
1254
+
1255
+ const output = await compile(
1256
+ entry,
1257
+ {
1258
+ resolve: (source, importer) => this.resolve(source, importer),
1259
+ watch: (file) => this.addWatchFile(file),
1260
+ asset: async (file) => {
1261
+ const reference = this.emitFile({
1262
+ type: 'asset',
1263
+ name: Path.basename(file).replace(/[?#%]/g, '_'),
1264
+ source: await Fs.readFile(file),
1265
+ })
1266
+
1267
+ // Vite's CSS asset placeholder preserves its configured base and output naming.
1268
+ return `__VITE_ASSET__${reference}__`
1269
+ },
1270
+ },
1271
+ undefined,
1272
+ id === sharedId,
1273
+ )
1274
+
1275
+ const transport = (css: string) =>
1276
+ this.environment.config.command === 'build'
1277
+ ? AtRules.rename(
1278
+ AtRules.rename(
1279
+ Namespaces.protect(css),
1280
+ 'font-feature-values',
1281
+ '-zyzz-ffv-000000000',
1282
+ ),
1283
+ 'font-palette-values',
1284
+ '-zyzz-fpv-000000000',
1285
+ )
1286
+ : css
1287
+ if (id === sharedId)
1288
+ return {
1289
+ code: transport(output.sharedCss),
1290
+ map: JSON.stringify(output.sharedCssMap),
1291
+ }
1292
+ return { code: transport(output.css), map: JSON.stringify(output.cssMap) }
1293
+ },
1294
+ name: 'zyzz',
1295
+ resolveId(id) {
1296
+ if (id.startsWith(prefix)) return id
1297
+ },
1298
+ async transform(code, id) {
1299
+ id = normalize(id)
1300
+
1301
+ if (!eligible(id)) return
1302
+
1303
+ const state = entries(this.environment)
1304
+ let entry = state.get(id)
1305
+
1306
+ if (!entry) {
1307
+ entry = {
1308
+ compiler: Graph.create(),
1309
+ environment: this.environment,
1310
+ file: id,
1311
+ files: new Set([id]),
1312
+ }
1313
+ state.set(id, entry)
1314
+ }
1315
+
1316
+ const output = await compile(
1317
+ entry,
1318
+ {
1319
+ resolve: (source, importer) => this.resolve(source, importer),
1320
+ watch: (file) => this.addWatchFile(file),
1321
+ asset: async (file) => {
1322
+ const reference = this.emitFile({
1323
+ type: 'asset',
1324
+ name: Path.basename(file).replace(/[?#%]/g, '_'),
1325
+ source: await Fs.readFile(file),
1326
+ })
1327
+
1328
+ // Vite's CSS asset placeholder preserves its configured base and output naming.
1329
+ return `__VITE_ASSET__${reference}__`
1330
+ },
1331
+ },
1332
+ code,
1333
+ )
1334
+
1335
+ if (native) return { code: output.code, map: JSON.stringify(output.map) }
1336
+
1337
+ // Keep the CSS dependency even when the current graph has no live rules.
1338
+ // Later edits can introduce styles without changing this import boundary.
1339
+ const parsed = Parser.parseSync('source.tsx', output.code, {
1340
+ sourceType: 'module',
1341
+ })
1342
+ let offset = output.code.startsWith('#!')
1343
+ ? output.code.indexOf('\n') + 1
1344
+ : 0
1345
+
1346
+ for (const node of parsed.program.body) {
1347
+ if (node.type !== 'ExpressionStatement' || !node.directive) break
1348
+
1349
+ offset = node.end
1350
+ }
1351
+
1352
+ const sharedImport = `\nimport ${JSON.stringify(sharedId)};\n`
1353
+ const map = Mapping.fromMap(JSON.stringify(output.map))
1354
+ // The inserted dependency shifts only generated positions after the prologue.
1355
+ const before = output.code.slice(0, offset)
1356
+ const insertionLine = before.split('\n').length
1357
+ const insertionColumn = before.length - (before.lastIndexOf('\n') + 1)
1358
+ const shifted = new Mapping.GenMapping()
1359
+
1360
+ for (const mapping of Mapping.allMappings(map)) {
1361
+ const generated = { ...mapping.generated }
1362
+
1363
+ if (
1364
+ generated.line > insertionLine ||
1365
+ (generated.line === insertionLine &&
1366
+ generated.column >= insertionColumn)
1367
+ ) {
1368
+ if (generated.line === insertionLine)
1369
+ generated.column -= insertionColumn
1370
+
1371
+ generated.line += 2
1372
+ }
1373
+
1374
+ if (mapping.source !== undefined && mapping.original !== undefined) {
1375
+ const location = {
1376
+ generated,
1377
+ original: mapping.original,
1378
+ source: mapping.source,
1379
+ }
1380
+
1381
+ if (mapping.name === undefined) Mapping.addMapping(shifted, location)
1382
+ else Mapping.addMapping(shifted, { ...location, name: mapping.name })
1383
+ } else Mapping.addMapping(shifted, { generated })
1384
+ }
1385
+
1386
+ for (const [index, source] of output.map.sources.entries())
1387
+ if (source !== null)
1388
+ Mapping.setSourceContent(
1389
+ shifted,
1390
+ source,
1391
+ output.map.sourcesContent?.[index] ?? null,
1392
+ )
1393
+
1394
+ return {
1395
+ code: `${before}${sharedImport}${output.code.slice(offset)}\nimport ${JSON.stringify(cssId(id))};`,
1396
+ map: JSON.stringify(Mapping.toEncodedMap(shifted)),
1397
+ }
1398
+ },
1399
+ transformIndexHtml: {
1400
+ order: 'post',
1401
+ async handler(html, context) {
1402
+ if (native || options.script === false) return
1403
+
1404
+ // Development compiles the whole project on request and keeps the
1405
+ // catalogs the document's scripts reach; a build scopes them to the
1406
+ // source graphs its entry chunk bundles.
1407
+ const configurations = await (async () => {
1408
+ if (!context.server)
1409
+ return entryCatalogs(context.bundle, context.chunk)
1410
+
1411
+ await initializations(context.server)
1412
+
1413
+ const environment = context.server.environments.client
1414
+
1415
+ return await documentCatalogs(
1416
+ html,
1417
+ context.filename,
1418
+ (source, importer) =>
1419
+ environment.pluginContainer.resolveId(source, importer),
1420
+ )
1421
+ })()
1422
+ // Saved preferences apply before any other script or visible content.
1423
+ return Catalogs.scripts(configurations).map((children) => ({
1424
+ children,
1425
+ injectTo: 'head-prepend' as const,
1426
+ tag: 'script',
1427
+ }))
1428
+ },
1429
+ },
1430
+ }
1431
+ }
1432
+
1433
+ type Entry = {
1434
+ environment: Environment
1435
+ compiler: Graph.create.ReturnType
1436
+ file: string
1437
+ files: Set<string>
1438
+ }
1439
+
1440
+ type Host = {
1441
+ asset: (file: string) => Promise<string>
1442
+ resolve: (
1443
+ source: string,
1444
+ importer: string,
1445
+ ) => Promise<{
1446
+ external?: boolean | 'absolute' | 'relative'
1447
+ id: string
1448
+ } | null>
1449
+ watch: (file: string) => void
1450
+ }
1451
+
1452
+ const prefix = '\0zyzz:'
1453
+ const sharedId = `${prefix}shared.css`
1454
+
1455
+ function cssId(file: string) {
1456
+ return `${prefix}${encodeURIComponent(file)}.css`
1457
+ }
1458
+
1459
+ /** Vite integration configuration. */
1460
+ export declare namespace zyzz {
1461
+ /** Source optimization and initialization injection remain enabled by default. */
1462
+ type Options = {
1463
+ /** False retains authored calls and requires explicit identities where needed. */
1464
+ readonly compiler?: boolean | undefined
1465
+ /** Native context captured at creation. Disables CSS delivery and initialization scripts. */
1466
+ readonly native?: Graph.compile.Options['native']
1467
+ /**
1468
+ * Inline each configuration's `script()` at the start of index.html's head.
1469
+ * False skips injection for documents that inline the script themselves.
1470
+ */
1471
+ readonly script?: boolean | undefined
1472
+ }
1473
+ }