zyzz 0.0.28 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/binding/wasi/wasi-worker.mjs +186 -0
  2. package/binding/wasi/zyzz.wasi.cjs +2302 -0
  3. package/binding/wasi/zyzz.wasm32-wasi.wasm +0 -0
  4. package/binding/zyzz.linux-x64-gnu.node +0 -0
  5. package/dist/babel/index.d.ts.map +1 -1
  6. package/dist/babel/index.js +2 -4
  7. package/dist/babel/index.js.map +1 -1
  8. package/dist/babel/internal/Compilation.d.ts +0 -1
  9. package/dist/babel/internal/Compilation.d.ts.map +1 -1
  10. package/dist/compiler/Graph.d.ts +14 -11
  11. package/dist/compiler/Graph.d.ts.map +1 -1
  12. package/dist/compiler/Graph.js +57 -1442
  13. package/dist/compiler/Graph.js.map +1 -1
  14. package/dist/compiler/Native.d.ts +7 -9
  15. package/dist/compiler/Native.d.ts.map +1 -1
  16. package/dist/compiler/Native.js +12 -716
  17. package/dist/compiler/Native.js.map +1 -1
  18. package/dist/compiler/Source.d.ts +122 -24
  19. package/dist/compiler/Source.d.ts.map +1 -1
  20. package/dist/compiler/Source.js +10 -1267
  21. package/dist/compiler/Source.js.map +1 -1
  22. package/dist/compiler/Transform.d.ts +4 -3
  23. package/dist/compiler/Transform.d.ts.map +1 -1
  24. package/dist/compiler/Transform.js +13 -961
  25. package/dist/compiler/Transform.js.map +1 -1
  26. package/dist/compiler/internal/AtRules.d.ts +5 -1
  27. package/dist/compiler/internal/AtRules.d.ts.map +1 -1
  28. package/dist/compiler/internal/AtRules.js +12 -106
  29. package/dist/compiler/internal/AtRules.js.map +1 -1
  30. package/dist/compiler/internal/Context.d.ts +11 -0
  31. package/dist/compiler/internal/Context.d.ts.map +1 -0
  32. package/dist/compiler/internal/Context.js +11 -0
  33. package/dist/compiler/internal/Context.js.map +1 -0
  34. package/dist/compiler/internal/Results.d.ts +148 -0
  35. package/dist/compiler/internal/Results.d.ts.map +1 -0
  36. package/dist/compiler/internal/Results.js +259 -0
  37. package/dist/compiler/internal/Results.js.map +1 -0
  38. package/dist/compiler/internal/Syntax.d.ts +0 -2
  39. package/dist/compiler/internal/Syntax.d.ts.map +1 -1
  40. package/dist/compiler/internal/Syntax.js +0 -2
  41. package/dist/compiler/internal/Syntax.js.map +1 -1
  42. package/dist/compiler/internal/Wire.d.ts +17 -0
  43. package/dist/compiler/internal/Wire.d.ts.map +1 -0
  44. package/dist/compiler/internal/Wire.js +795 -0
  45. package/dist/compiler/internal/Wire.js.map +1 -0
  46. package/dist/internal/Addon.d.ts +28 -0
  47. package/dist/internal/Addon.d.ts.map +1 -0
  48. package/dist/internal/Addon.js +87 -0
  49. package/dist/internal/Addon.js.map +1 -0
  50. package/dist/internal/Literal.d.ts +4 -1
  51. package/dist/internal/Literal.d.ts.map +1 -1
  52. package/dist/internal/Literal.js +4 -2
  53. package/dist/internal/Literal.js.map +1 -1
  54. package/dist/internal/Token.d.ts +2 -1
  55. package/dist/internal/Token.d.ts.map +1 -1
  56. package/dist/internal/Token.js +2 -2
  57. package/dist/internal/Token.js.map +1 -1
  58. package/dist/internal/Vlq.d.ts +14 -0
  59. package/dist/internal/Vlq.d.ts.map +1 -0
  60. package/dist/internal/Vlq.js +47 -0
  61. package/dist/internal/Vlq.js.map +1 -0
  62. package/dist/internal/Wasm.d.ts +22 -0
  63. package/dist/internal/Wasm.d.ts.map +1 -0
  64. package/dist/internal/Wasm.js +83 -0
  65. package/dist/internal/Wasm.js.map +1 -0
  66. package/dist/metro/Graph.d.ts +0 -1
  67. package/dist/metro/Graph.d.ts.map +1 -1
  68. package/dist/metro/transformer.d.ts.map +1 -1
  69. package/dist/metro/transformer.js +0 -1
  70. package/dist/metro/transformer.js.map +1 -1
  71. package/dist/next/internal/Project.d.ts.map +1 -1
  72. package/dist/next/internal/Project.js +2 -5
  73. package/dist/next/internal/Project.js.map +1 -1
  74. package/dist/node/Host.d.ts.map +1 -1
  75. package/dist/node/Host.js +0 -2
  76. package/dist/node/Host.js.map +1 -1
  77. package/dist/node/internal/Contracts.d.ts.map +1 -1
  78. package/dist/node/internal/Contracts.js +3 -7
  79. package/dist/node/internal/Contracts.js.map +1 -1
  80. package/dist/node/internal/Snapshot.d.ts +0 -1
  81. package/dist/node/internal/Snapshot.d.ts.map +1 -1
  82. package/dist/node/internal/Snapshot.js +0 -6
  83. package/dist/node/internal/Snapshot.js.map +1 -1
  84. package/dist/runtime/Composition.d.ts +2 -3
  85. package/dist/runtime/Composition.d.ts.map +1 -1
  86. package/dist/runtime/Composition.js +51 -30
  87. package/dist/runtime/Composition.js.map +1 -1
  88. package/dist/runtime/Recipe.d.ts.map +1 -1
  89. package/dist/runtime/Recipe.js +16 -12
  90. package/dist/runtime/Recipe.js.map +1 -1
  91. package/dist/unplugin/index.d.ts.map +1 -1
  92. package/dist/unplugin/index.js +3 -6
  93. package/dist/unplugin/index.js.map +1 -1
  94. package/dist/vite/index.d.ts.map +1 -1
  95. package/dist/vite/index.js +696 -201
  96. package/dist/vite/index.js.map +1 -1
  97. package/dist/web/Css.d.ts +8 -3
  98. package/dist/web/Css.d.ts.map +1 -1
  99. package/dist/web/Css.js +5 -721
  100. package/dist/web/Css.js.map +1 -1
  101. package/dist/web/internal/Block.d.ts +0 -2
  102. package/dist/web/internal/Block.d.ts.map +1 -1
  103. package/dist/web/internal/Block.js +1 -12
  104. package/dist/web/internal/Block.js.map +1 -1
  105. package/dist/web/internal/ClassName.d.ts +23 -18
  106. package/dist/web/internal/ClassName.d.ts.map +1 -1
  107. package/dist/web/internal/ClassName.js +26 -55
  108. package/dist/web/internal/ClassName.js.map +1 -1
  109. package/dist/web/internal/Contributions.d.ts +3 -5
  110. package/dist/web/internal/Contributions.d.ts.map +1 -1
  111. package/dist/web/internal/Contributions.js +0 -45
  112. package/dist/web/internal/Contributions.js.map +1 -1
  113. package/dist/web/internal/Engine.browser.d.ts +8 -0
  114. package/dist/web/internal/Engine.browser.d.ts.map +1 -0
  115. package/dist/web/internal/Engine.browser.js +42 -0
  116. package/dist/web/internal/Engine.browser.js.map +1 -0
  117. package/dist/web/internal/Engine.d.ts +9 -0
  118. package/dist/web/internal/Engine.d.ts.map +1 -0
  119. package/dist/web/internal/Engine.js +14 -0
  120. package/dist/web/internal/Engine.js.map +1 -0
  121. package/dist/web/internal/Themes.d.ts +1 -9
  122. package/dist/web/internal/Themes.d.ts.map +1 -1
  123. package/dist/web/internal/Themes.js +3 -221
  124. package/dist/web/internal/Themes.js.map +1 -1
  125. package/dist/web/internal/Wasm.generated.d.ts +4 -0
  126. package/dist/web/internal/Wasm.generated.d.ts.map +1 -0
  127. package/dist/web/internal/Wasm.generated.js +4 -0
  128. package/dist/web/internal/Wasm.generated.js.map +1 -0
  129. package/dist/web/internal/Wire.d.ts +19 -0
  130. package/dist/web/internal/Wire.d.ts.map +1 -0
  131. package/dist/web/internal/Wire.js +387 -0
  132. package/dist/web/internal/Wire.js.map +1 -0
  133. package/package.json +20 -1
  134. package/src/babel/index.ts +2 -5
  135. package/src/babel/internal/Compilation.ts +0 -1
  136. package/src/compiler/Graph.ts +89 -1930
  137. package/src/compiler/Native.ts +18 -871
  138. package/src/compiler/Source.ts +144 -1803
  139. package/src/compiler/Transform.ts +16 -1315
  140. package/src/compiler/internal/AtRules.ts +27 -115
  141. package/src/compiler/internal/Context.ts +11 -0
  142. package/src/compiler/internal/Results.ts +406 -0
  143. package/src/compiler/internal/Syntax.ts +0 -3
  144. package/src/compiler/internal/Wire.ts +1045 -0
  145. package/src/internal/Addon.ts +118 -0
  146. package/src/internal/Literal.ts +4 -2
  147. package/src/internal/Token.ts +2 -2
  148. package/src/internal/Vlq.ts +59 -0
  149. package/src/internal/Wasm.ts +111 -0
  150. package/src/metro/transformer.ts +0 -1
  151. package/src/next/internal/Project.ts +2 -9
  152. package/src/node/Host.ts +0 -2
  153. package/src/node/internal/Contracts.ts +3 -7
  154. package/src/node/internal/Snapshot.ts +0 -8
  155. package/src/runtime/Composition.ts +48 -25
  156. package/src/runtime/Recipe.ts +21 -14
  157. package/src/unplugin/index.ts +6 -6
  158. package/src/vite/index.ts +922 -221
  159. package/src/web/Css.ts +12 -908
  160. package/src/web/internal/Block.ts +0 -14
  161. package/src/web/internal/ClassName.ts +52 -85
  162. package/src/web/internal/Contributions.ts +3 -59
  163. package/src/web/internal/Engine.browser.ts +51 -0
  164. package/src/web/internal/Engine.ts +17 -0
  165. package/src/web/internal/Themes.ts +3 -279
  166. package/src/web/internal/Wasm.generated.ts +3 -0
  167. package/src/web/internal/Wire.ts +466 -0
  168. package/src/web/internal/wasm.d.ts +9 -0
  169. package/dist/compiler/internal/Applications.d.ts +0 -55
  170. package/dist/compiler/internal/Applications.d.ts.map +0 -1
  171. package/dist/compiler/internal/Applications.js +0 -393
  172. package/dist/compiler/internal/Applications.js.map +0 -1
  173. package/dist/compiler/internal/ColorProfiles.d.ts +0 -3
  174. package/dist/compiler/internal/ColorProfiles.d.ts.map +0 -1
  175. package/dist/compiler/internal/ColorProfiles.js +0 -84
  176. package/dist/compiler/internal/ColorProfiles.js.map +0 -1
  177. package/dist/compiler/internal/CompositionBindings.d.ts +0 -16
  178. package/dist/compiler/internal/CompositionBindings.d.ts.map +0 -1
  179. package/dist/compiler/internal/CompositionBindings.js +0 -89
  180. package/dist/compiler/internal/CompositionBindings.js.map +0 -1
  181. package/dist/compiler/internal/Compositions.d.ts +0 -37
  182. package/dist/compiler/internal/Compositions.d.ts.map +0 -1
  183. package/dist/compiler/internal/Compositions.js +0 -494
  184. package/dist/compiler/internal/Compositions.js.map +0 -1
  185. package/dist/compiler/internal/Configurations.d.ts +0 -26
  186. package/dist/compiler/internal/Configurations.d.ts.map +0 -1
  187. package/dist/compiler/internal/Configurations.js +0 -259
  188. package/dist/compiler/internal/Configurations.js.map +0 -1
  189. package/dist/compiler/internal/Contract.d.ts +0 -30
  190. package/dist/compiler/internal/Contract.d.ts.map +0 -1
  191. package/dist/compiler/internal/Contract.js +0 -753
  192. package/dist/compiler/internal/Contract.js.map +0 -1
  193. package/dist/compiler/internal/Contributions.d.ts +0 -54
  194. package/dist/compiler/internal/Contributions.d.ts.map +0 -1
  195. package/dist/compiler/internal/Contributions.js +0 -1151
  196. package/dist/compiler/internal/Contributions.js.map +0 -1
  197. package/dist/compiler/internal/Descriptors.d.ts +0 -15
  198. package/dist/compiler/internal/Descriptors.d.ts.map +0 -1
  199. package/dist/compiler/internal/Descriptors.js +0 -192
  200. package/dist/compiler/internal/Descriptors.js.map +0 -1
  201. package/dist/compiler/internal/Dynamic.d.ts +0 -14
  202. package/dist/compiler/internal/Dynamic.d.ts.map +0 -1
  203. package/dist/compiler/internal/Dynamic.js +0 -175
  204. package/dist/compiler/internal/Dynamic.js.map +0 -1
  205. package/dist/compiler/internal/Expression.d.ts +0 -19
  206. package/dist/compiler/internal/Expression.d.ts.map +0 -1
  207. package/dist/compiler/internal/Expression.js +0 -164
  208. package/dist/compiler/internal/Expression.js.map +0 -1
  209. package/dist/compiler/internal/Functions.d.ts +0 -5
  210. package/dist/compiler/internal/Functions.d.ts.map +0 -1
  211. package/dist/compiler/internal/Functions.js +0 -191
  212. package/dist/compiler/internal/Functions.js.map +0 -1
  213. package/dist/compiler/internal/Keyframes.d.ts +0 -5
  214. package/dist/compiler/internal/Keyframes.d.ts.map +0 -1
  215. package/dist/compiler/internal/Keyframes.js +0 -51
  216. package/dist/compiler/internal/Keyframes.js.map +0 -1
  217. package/dist/compiler/internal/Names.d.ts +0 -5
  218. package/dist/compiler/internal/Names.d.ts.map +0 -1
  219. package/dist/compiler/internal/Names.js +0 -37
  220. package/dist/compiler/internal/Names.js.map +0 -1
  221. package/dist/compiler/internal/NativeBindings.d.ts +0 -72
  222. package/dist/compiler/internal/NativeBindings.d.ts.map +0 -1
  223. package/dist/compiler/internal/NativeBindings.js +0 -171
  224. package/dist/compiler/internal/NativeBindings.js.map +0 -1
  225. package/dist/compiler/internal/NativeMedia.d.ts +0 -14
  226. package/dist/compiler/internal/NativeMedia.d.ts.map +0 -1
  227. package/dist/compiler/internal/NativeMedia.js +0 -287
  228. package/dist/compiler/internal/NativeMedia.js.map +0 -1
  229. package/dist/compiler/internal/NativeVars.d.ts +0 -28
  230. package/dist/compiler/internal/NativeVars.d.ts.map +0 -1
  231. package/dist/compiler/internal/NativeVars.js +0 -160
  232. package/dist/compiler/internal/NativeVars.js.map +0 -1
  233. package/dist/compiler/internal/PackedStyles.d.ts +0 -37
  234. package/dist/compiler/internal/PackedStyles.d.ts.map +0 -1
  235. package/dist/compiler/internal/PackedStyles.js +0 -344
  236. package/dist/compiler/internal/PackedStyles.js.map +0 -1
  237. package/dist/compiler/internal/Properties.d.ts +0 -5
  238. package/dist/compiler/internal/Properties.d.ts.map +0 -1
  239. package/dist/compiler/internal/Properties.js +0 -82
  240. package/dist/compiler/internal/Properties.js.map +0 -1
  241. package/dist/compiler/internal/RecipeConditions.d.ts +0 -41
  242. package/dist/compiler/internal/RecipeConditions.d.ts.map +0 -1
  243. package/dist/compiler/internal/RecipeConditions.js +0 -82
  244. package/dist/compiler/internal/RecipeConditions.js.map +0 -1
  245. package/dist/compiler/internal/RecipePayloads.d.ts +0 -31
  246. package/dist/compiler/internal/RecipePayloads.d.ts.map +0 -1
  247. package/dist/compiler/internal/RecipePayloads.js +0 -99
  248. package/dist/compiler/internal/RecipePayloads.js.map +0 -1
  249. package/dist/compiler/internal/Recipes.d.ts +0 -32
  250. package/dist/compiler/internal/Recipes.d.ts.map +0 -1
  251. package/dist/compiler/internal/Recipes.js +0 -339
  252. package/dist/compiler/internal/Recipes.js.map +0 -1
  253. package/dist/compiler/internal/Selectors.d.ts +0 -13
  254. package/dist/compiler/internal/Selectors.d.ts.map +0 -1
  255. package/dist/compiler/internal/Selectors.js +0 -280
  256. package/dist/compiler/internal/Selectors.js.map +0 -1
  257. package/dist/compiler/internal/Static.d.ts +0 -39
  258. package/dist/compiler/internal/Static.d.ts.map +0 -1
  259. package/dist/compiler/internal/Static.js +0 -534
  260. package/dist/compiler/internal/Static.js.map +0 -1
  261. package/dist/compiler/internal/Themes.d.ts +0 -190
  262. package/dist/compiler/internal/Themes.d.ts.map +0 -1
  263. package/dist/compiler/internal/Themes.js +0 -1577
  264. package/dist/compiler/internal/Themes.js.map +0 -1
  265. package/dist/compiler/internal/Vars.d.ts +0 -33
  266. package/dist/compiler/internal/Vars.d.ts.map +0 -1
  267. package/dist/compiler/internal/Vars.js +0 -387
  268. package/dist/compiler/internal/Vars.js.map +0 -1
  269. package/dist/compiler/internal/ViewTransitions.d.ts +0 -3
  270. package/dist/compiler/internal/ViewTransitions.d.ts.map +0 -1
  271. package/dist/compiler/internal/ViewTransitions.js +0 -68
  272. package/dist/compiler/internal/ViewTransitions.js.map +0 -1
  273. package/dist/internal/Cascade.d.ts +0 -74
  274. package/dist/internal/Cascade.d.ts.map +0 -1
  275. package/dist/internal/Cascade.js +0 -210
  276. package/dist/internal/Cascade.js.map +0 -1
  277. package/src/compiler/internal/Applications.ts +0 -610
  278. package/src/compiler/internal/ColorProfiles.ts +0 -93
  279. package/src/compiler/internal/CompositionBindings.ts +0 -120
  280. package/src/compiler/internal/Compositions.ts +0 -678
  281. package/src/compiler/internal/Configurations.ts +0 -349
  282. package/src/compiler/internal/Contract.ts +0 -1028
  283. package/src/compiler/internal/Contributions.ts +0 -1561
  284. package/src/compiler/internal/Descriptors.ts +0 -242
  285. package/src/compiler/internal/Dynamic.ts +0 -275
  286. package/src/compiler/internal/Expression.ts +0 -218
  287. package/src/compiler/internal/Functions.ts +0 -206
  288. package/src/compiler/internal/Keyframes.ts +0 -62
  289. package/src/compiler/internal/Names.ts +0 -48
  290. package/src/compiler/internal/NativeBindings.ts +0 -235
  291. package/src/compiler/internal/NativeMedia.ts +0 -342
  292. package/src/compiler/internal/NativeVars.ts +0 -231
  293. package/src/compiler/internal/PackedStyles.ts +0 -473
  294. package/src/compiler/internal/Properties.ts +0 -121
  295. package/src/compiler/internal/RecipeConditions.ts +0 -139
  296. package/src/compiler/internal/RecipePayloads.ts +0 -132
  297. package/src/compiler/internal/Recipes.ts +0 -531
  298. package/src/compiler/internal/Selectors.ts +0 -353
  299. package/src/compiler/internal/Static.ts +0 -784
  300. package/src/compiler/internal/Themes.ts +0 -2398
  301. package/src/compiler/internal/Vars.ts +0 -516
  302. package/src/compiler/internal/ViewTransitions.ts +0 -82
@@ -1,73 +1,38 @@
1
1
  /** Adapts standard descriptor extensions that precede the pinned parser's grammar. @module */
2
- import * as ColorProfiles from './ColorProfiles.js'
3
- import * as Descriptors from './Descriptors.js'
4
- import * as Functions from './Functions.js'
5
- import * as Identifiers from './Identifiers.js'
6
- import * as Keyframes from './Keyframes.js'
7
2
  import * as Lightning from 'lightningcss'
8
- import * as Properties from './Properties.js'
9
- import * as ViewTransitions from './ViewTransitions.js'
3
+ import * as Results from './Results.js'
10
4
 
11
- /** Parses structured contributions while retaining newer font descriptors. */
5
+ /** A stylesheet whose newer at-keywords travel through the parser under markers. */
6
+ type Transport = {
7
+ readonly code: string
8
+ readonly features: string
9
+ readonly import: string
10
+ readonly palette: string
11
+ readonly property: string
12
+ }
13
+
14
+ /**
15
+ * Parses structured contributions while retaining newer font descriptors.
16
+ * The engine validates newer at-rules and renames the at-keywords the parser cannot round-trip.
17
+ */
12
18
  export function transform<C extends Lightning.CustomAtRules>(
13
19
  options: Lightning.TransformOptions<C>,
14
20
  ): Lightning.TransformResult {
15
21
  // Stylesheets without an @ byte cannot require at-keyword transport.
16
22
  if (!options.code.includes(64)) return Lightning.transform(options)
17
23
 
18
- const source = new TextDecoder().decode(options.code)
19
- if (
20
- /@(?:counter-style|custom-media|document|font-face|font-palette-values|page)\b/i.test(
21
- source,
22
- )
23
- )
24
- Descriptors.validate(source)
25
- if (/@function\b/i.test(source)) Functions.validate(source)
26
- const properties = /@property\b/i.test(source) && Properties.validate(source)
27
- let propertyMarker = 'zyzz-property'
28
- while (source.includes(propertyMarker)) propertyMarker += '-x'
29
- validateFeatures(source)
30
- // The pinned visitor cannot round-trip the nested Option used for anonymous import layers.
31
- // Give emitted anonymous layers a temporary name while URL visitors run, then restore them.
32
- let importMarker = 'zyzz-anonymous-import'
33
- while (source.includes(importMarker)) importMarker += '-x'
34
- const imports = options.visitor
35
- ? source.replace(
36
- /^(\s*@import\s+(?:url\()?"(?:\\.|[^"\\])*"\)?\s+)layer(?=[\s;])/gm,
37
- `$1layer(${importMarker})`,
38
- )
39
- : source
40
- const lower = source.toLowerCase()
41
- let marker = '-zyzz-ffv-000000000'
42
- let suffix = 0
43
- while (lower.includes(marker))
44
- marker = `-zyzz-ffv-${(++suffix).toString(36).padStart(9, '0')}`
45
- let paletteMarker = '-zyzz-fpv-000000000'
46
- let paletteSuffix = 0
47
- while (lower.includes(paletteMarker))
48
- paletteMarker = `-zyzz-fpv-${(++paletteSuffix).toString(36).padStart(9, '0')}`
49
- // The pinned parser silently drops font-family lists from palette rules.
50
- const registered = properties
51
- ? rename(imports, 'property', propertyMarker)
52
- : imports
53
- const features = lower.includes('@font-feature-values')
54
- ? rename(registered, 'font-feature-values', marker)
55
- : registered
56
- const renamed = lower.includes('@font-palette-values')
57
- ? rename(features, 'font-palette-values', paletteMarker)
58
- : features
59
- if (lower.includes('@color-profile')) ColorProfiles.validate(renamed)
60
- if (lower.includes('@keyframes')) Keyframes.validate(renamed)
61
- if (source.toLowerCase().includes('@view-transition')) {
62
- let marker = '-zyzz-view-transition'
63
- while (source.includes(marker)) marker += '-x'
64
- ViewTransitions.validate(rename(renamed, 'view-transition', marker), marker)
65
- }
66
- if (source === renamed) return Lightning.transform(options)
24
+ const transport = Results.call<Transport | null>('css.transport', {
25
+ code: new TextDecoder().decode(options.code),
26
+ visitor: Boolean(options.visitor),
27
+ })
28
+
29
+ if (!transport) return Lightning.transform(options)
30
+
67
31
  const result = Lightning.transform({
68
32
  ...options,
69
- code: new TextEncoder().encode(renamed),
33
+ code: new TextEncoder().encode(transport.code),
70
34
  })
35
+
71
36
  return {
72
37
  ...result,
73
38
  code: new TextEncoder().encode(
@@ -76,22 +41,20 @@ export function transform<C extends Lightning.CustomAtRules>(
76
41
  rename(
77
42
  new TextDecoder()
78
43
  .decode(result.code)
79
- .replaceAll(`layer(${importMarker})`, 'layer'),
80
- propertyMarker,
44
+ .replaceAll(`layer(${transport.import})`, 'layer'),
45
+ transport.property,
81
46
  'property',
82
47
  ),
83
- marker,
48
+ transport.features,
84
49
  'font-feature-values',
85
50
  ),
86
- paletteMarker,
51
+ transport.palette,
87
52
  'font-palette-values',
88
53
  ),
89
54
  ),
90
55
  }
91
56
  }
92
57
 
93
- // Contribution extraction validates feature blocks and their descriptors before this adapter.
94
- // At-keyword substitution keeps Lightning's token/URL traversal without discarding newer descriptors.
95
58
  /** Renames actual at-keywords without touching strings, comments, or function arguments. */
96
59
  export function rename(source: string, before: string, after: string): string {
97
60
  let output = ''
@@ -149,54 +112,3 @@ export function relocateImport(
149
112
  },
150
113
  }
151
114
  }
152
-
153
- // Validate the standard rule before shielding the newer font-display descriptor.
154
- function validateFeatures(source: string): void {
155
- if (!source.toLowerCase().includes('@font-feature-values')) return
156
- const masked = source.replace(
157
- /"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\/\*[\s\S]*?\*\//g,
158
- (value) => ' '.repeat(value.length),
159
- )
160
- for (const match of masked.matchAll(/@font-feature-values(?=[\s{])/gi)) {
161
- const start = match.index
162
- const open = masked.indexOf('{', start)
163
- if (open < 0) throw new Error('Invalid font-feature-values block.')
164
- let depth = 1
165
- let end = open + 1
166
- let plain = source.slice(start, open + 1)
167
- let cursor = open + 1
168
- for (; end < masked.length && depth; end++) {
169
- const char = masked[end]
170
- if (char === '{') depth++
171
- else if (char === '}') depth--
172
- else if (depth === 1 && masked.slice(end).match(/^font-display\s*:/i)) {
173
- const finish = masked.indexOf(';', end)
174
- const close = masked.indexOf('}', end)
175
- const boundary = finish >= 0 && finish < close ? finish : close
176
- if (boundary < 0) throw new Error('Invalid font-display descriptor.')
177
- const descriptor = source.slice(end, boundary)
178
- const names = Identifiers.list(
179
- descriptor.slice(descriptor.indexOf(':') + 1),
180
- 'space',
181
- )
182
- if (
183
- names?.length !== 1 ||
184
- !['auto', 'block', 'fallback', 'optional', 'swap'].includes(
185
- names[0]!.replace(/[A-Z]/g, (letter) => letter.toLowerCase()),
186
- )
187
- )
188
- throw new Error('Invalid font-display descriptor.')
189
- plain += source.slice(cursor, end)
190
- cursor = boundary + (boundary === finish ? 1 : 0)
191
- end = cursor - 1
192
- }
193
- }
194
- if (depth) throw new Error('Invalid font-feature-values block.')
195
- plain += source.slice(cursor, end)
196
- Lightning.transform({
197
- filename: 'font-feature-values.css',
198
- code: new TextEncoder().encode(plain),
199
- errorRecovery: false,
200
- })
201
- }
202
- }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Marks native compilation inside a host-owned graph context.
3
+ * @module
4
+ */
5
+
6
+ /**
7
+ * Option key of `Native.compile` for an adapter that compiles a module as a member of its own
8
+ * graph. Extraction then validates contributed CSS without relocating relative assets, and it
9
+ * links no other module.
10
+ */
11
+ export const key = Symbol('zyzz.source.graph')
@@ -0,0 +1,406 @@
1
+ /**
2
+ * Runs compiler operations in the Rust engine and rebuilds their frozen results and errors.
3
+ * @module
4
+ */
5
+ import type * as Mapping from '@jridgewell/gen-mapping'
6
+ import * as StyleSheet from '../../react-native/StyleSheet.js'
7
+ import * as Variants from '../../react-native/Variants.js'
8
+ import * as Css from '../../web/Css.js'
9
+ import * as ClassName from '../../web/internal/ClassName.js'
10
+ import * as Engine from '../../web/internal/Engine.js'
11
+ import * as ThemeRules from '../../web/internal/Themes.js'
12
+ import * as Wire from '../../web/internal/Wire.js'
13
+ import type * as Graph from '../Graph.js'
14
+ import * as Native from '../Native.js'
15
+ import * as Source from '../Source.js'
16
+ import type * as Transform from '../Transform.js'
17
+ import * as Edits from './Edits.js'
18
+ import * as Stylesheets from './Stylesheets.js'
19
+
20
+ /** A failure as the engine encodes it. */
21
+ type Failure = {
22
+ readonly diagnostics?: readonly unknown[] | undefined
23
+ readonly message: string
24
+ readonly name: string
25
+ readonly source?: string | undefined
26
+ }
27
+
28
+ /** One module's transform output as the engine encodes it. */
29
+ export type Module = Records & {
30
+ readonly code: string
31
+ readonly css: string
32
+ readonly cssMap: Mapping.EncodedSourceMap
33
+ readonly map: Transform.compile.ReturnType['map']
34
+ readonly shared?: readonly ThemeRules.Resource[] | undefined
35
+ readonly vars: Readonly<Record<string, string>>
36
+ }
37
+
38
+ /** One native graph module as the engine encodes it. */
39
+ type NativeModule = {
40
+ readonly code: string
41
+ readonly edits: readonly Edits.Edit[]
42
+ readonly map: Mapping.EncodedSourceMap
43
+ }
44
+
45
+ /** A `native.compile` result as the engine encodes it. */
46
+ export type NativeOutput = {
47
+ readonly code: string
48
+ readonly edits: readonly Edits.Edit[]
49
+ readonly map: string
50
+ readonly recipes: Readonly<Record<string, unknown>>
51
+ }
52
+
53
+ /** A module's class, rule, and unit records as the engine encodes them. */
54
+ type Records = {
55
+ readonly classes: Readonly<Record<string, string>>
56
+ readonly rules: Readonly<Record<string, string>>
57
+ readonly units: readonly (readonly [string, boolean, string])[]
58
+ }
59
+
60
+ /** One rendered stylesheet as the engine encodes it. */
61
+ type Rendered = {
62
+ readonly assets: Readonly<Record<string, string>>
63
+ readonly css: string
64
+ readonly id?: string | undefined
65
+ readonly map: Mapping.EncodedSourceMap
66
+ readonly owners: Readonly<Record<string, string>>
67
+ }
68
+
69
+ /**
70
+ * A graph result as the engine encodes it. Modules whose output the host last decoded are `0`,
71
+ * and `prune` drops every other decoded module.
72
+ */
73
+ export type Output = {
74
+ readonly contracts: Readonly<Record<string, string>>
75
+ readonly dependencies: Readonly<Record<string, readonly string[]>>
76
+ readonly modules: Readonly<Record<string, Module | NativeModule | 0>>
77
+ readonly packed?: readonly Rendered[] | undefined
78
+ readonly prune?: true | undefined
79
+ readonly reset?: Rendered | undefined
80
+ readonly same?: true | undefined
81
+ readonly shared?: Rendered | undefined
82
+ }
83
+
84
+ /**
85
+ * Runs an engine operation on JSON input.
86
+ * @param operation - Operation name, such as `graph.compile`.
87
+ * @param input - Input data, serialized as JSON.
88
+ * @returns The parsed result.
89
+ * @throws {Source.ExtractError} For source the compiler does not support.
90
+ * @throws {Css.CompileError} For CSS emission failures.
91
+ * @throws {Native.CompileError} For native features outside the static boundary.
92
+ */
93
+ export function call<result>(operation: string, input: unknown): result {
94
+ return decode(Engine.call(operation, JSON.stringify(input)))
95
+ }
96
+
97
+ /**
98
+ * Runs `transform.compile`. JSON text never holds a raw NUL, so a string source follows one and
99
+ * crosses without escaping. The engine writes the module's records after one, and they decode
100
+ * when first read.
101
+ * @param input - Options, with the source when it is not a string.
102
+ * @param source - Module text.
103
+ * @returns The output `Transform.compile` returns.
104
+ * @throws {Source.ExtractError} For source the compiler does not support.
105
+ * @throws {Css.CompileError} For CSS emission failures.
106
+ */
107
+ export function transform(
108
+ input: unknown,
109
+ source?: string | undefined,
110
+ ): Transform.compile.ReturnType {
111
+ const json = JSON.stringify(input)
112
+ const text = Engine.call(
113
+ 'transform.compile',
114
+ source === undefined ? json : `${json}\0${source}`,
115
+ )
116
+ const split = text.indexOf('\0')
117
+
118
+ // Failures write no records, and decoding throws them.
119
+ if (split === -1) return module(decode<Module>(text), source)
120
+
121
+ return module(
122
+ decode<Omit<Module, keyof Records>>(text.slice(0, split)),
123
+ source,
124
+ text.slice(split + 1),
125
+ )
126
+ }
127
+
128
+ /**
129
+ * Parses an engine result, throwing the failure it encodes.
130
+ * @param json - The engine's JSON result.
131
+ * @returns The parsed result.
132
+ * @throws {Source.ExtractError} For source the compiler does not support.
133
+ * @throws {Css.CompileError} For CSS emission failures.
134
+ * @throws {Native.CompileError} For native features outside the static boundary.
135
+ */
136
+ export function decode<result>(json: string): result {
137
+ const output = JSON.parse(json) as {
138
+ readonly error?: Failure | undefined
139
+ } | null
140
+
141
+ if (output?.error) throw failure(output.error)
142
+
143
+ return output as result
144
+ }
145
+
146
+ /**
147
+ * Lists each packed stylesheet section's import chain of a library contract, which hosts
148
+ * resolve before compiling the graph.
149
+ * @param contract - Serialized library contract.
150
+ * @param moduleId - Host-resolved identity of the contract's module.
151
+ * @returns One specifier chain per stylesheet section, in section order.
152
+ * @throws {SyntaxError} For malformed contract JSON.
153
+ * @throws {Error} For unsupported or invalid contract metadata.
154
+ */
155
+ export function dependencies(
156
+ contract: string,
157
+ moduleId: string,
158
+ ): readonly (readonly string[])[] {
159
+ return call<{ readonly dependencies: readonly (readonly string[])[] }>(
160
+ 'contract.dependencies',
161
+ { contract, moduleId },
162
+ ).dependencies
163
+ }
164
+
165
+ function failure(error: Failure): Error {
166
+ if (error.name === 'Source.ExtractError')
167
+ return new Source.ExtractError(
168
+ error.diagnostics as readonly Source.Diagnostic[],
169
+ )
170
+ if (error.name === 'Css.CompileError')
171
+ return new Css.CompileError(error.diagnostics as readonly Css.Diagnostic[])
172
+ if (error.name === 'Native.CompileError')
173
+ return new Native.CompileError(error.message)
174
+ if (error.name === 'StyleSheet.CompileError')
175
+ return new StyleSheet.CompileError(
176
+ error.diagnostics as readonly StyleSheet.Diagnostic[],
177
+ )
178
+ if (error.name === 'StyleSheet.SelectionError')
179
+ return new StyleSheet.SelectionError(error.message)
180
+ if (error.name === 'Stylesheets.ConflictError')
181
+ return new Stylesheets.ConflictError(error.source ?? '', error.message)
182
+ if (error.name === 'Variants.CompileError')
183
+ return new Variants.CompileError(error.message)
184
+ if (error.name === 'SyntaxError') return new SyntaxError(error.message)
185
+
186
+ return new Error(error.message)
187
+ }
188
+
189
+ /**
190
+ * Deeply freezes decoded JSON data, giving its objects null prototypes as compiled tables have.
191
+ * @param value - Data parsed from engine JSON.
192
+ * @returns The same data, frozen.
193
+ */
194
+ export function frozen(value: unknown): unknown {
195
+ if (Array.isArray(value)) return Object.freeze(value.map(frozen))
196
+ if (value === null || typeof value !== 'object') return value
197
+
198
+ return Object.freeze(
199
+ Object.assign(
200
+ Object.create(null),
201
+ Object.fromEntries(
202
+ Object.entries(value).map(([key, entry]) => [key, frozen(entry)]),
203
+ ),
204
+ ),
205
+ )
206
+ }
207
+
208
+ /**
209
+ * Rebuilds a frozen graph result, keeping the decoded module objects the engine reports
210
+ * unchanged.
211
+ * @param value - The encoded graph result.
212
+ * @param previous - The result of the same compiler's previous call.
213
+ * @param decoded - The same compiler's last decoded module per identity, updated in place.
214
+ * @returns The output `Graph.compile` returns.
215
+ */
216
+ export function graph(
217
+ value: Output,
218
+ previous?: Graph.compile.ReturnType | undefined,
219
+ decoded?: Map<string, Transform.compile.ReturnType> | undefined,
220
+ ): Graph.compile.ReturnType {
221
+ if (value.same && previous) return previous
222
+
223
+ const modules = Object.fromEntries(
224
+ Object.entries(value.modules).map(([id, encoded]) => [
225
+ id,
226
+ (() => {
227
+ if (encoded === 0) return decoded!.get(id)!
228
+ if ('edits' in encoded) return nativeModule(encoded)
229
+
230
+ return module(encoded)
231
+ })(),
232
+ ]),
233
+ )
234
+
235
+ if (decoded) {
236
+ for (const [id, output] of Object.entries(modules)) decoded.set(id, output)
237
+ if (value.prune)
238
+ for (const id of decoded.keys())
239
+ if (!Object.hasOwn(modules, id)) decoded.delete(id)
240
+ }
241
+
242
+ return Object.freeze({
243
+ ...(value.reset
244
+ ? { [Stylesheets.reset]: rendered(value.reset) as Stylesheets.Resource }
245
+ : {}),
246
+ ...(value.packed
247
+ ? {
248
+ [Stylesheets.packed]: Object.freeze(
249
+ value.packed.map((resource) => rendered(resource)),
250
+ ) as readonly Stylesheets.Resource[],
251
+ }
252
+ : {}),
253
+ ...(value.shared
254
+ ? {
255
+ sharedCss: value.shared.css,
256
+ sharedCssMap: value.shared.map,
257
+ sharedAssets: Object.freeze(
258
+ Object.assign(Object.create(null), value.shared.assets),
259
+ ),
260
+ sharedAssetOwners: Object.freeze(
261
+ Object.assign(Object.create(null), value.shared.owners),
262
+ ),
263
+ }
264
+ : {}),
265
+ contracts: Object.freeze({ ...value.contracts }),
266
+ dependencies: Object.freeze(
267
+ Object.assign(
268
+ Object.create(null),
269
+ Object.fromEntries(
270
+ Object.entries(value.dependencies).map(([id, targets]) => [
271
+ id,
272
+ Object.freeze([...targets]),
273
+ ]),
274
+ ),
275
+ ),
276
+ ),
277
+ modules: Object.freeze(modules),
278
+ }) as Graph.compile.ReturnType
279
+ }
280
+
281
+ /** Graph option for hosts that read module code, stylesheets, and configuration catalogs only. */
282
+ export const lean = Symbol('lean graph output')
283
+
284
+ /**
285
+ * Rebuilds one module's frozen transform output. Records decode when first read, so a module
286
+ * whose classes, rules, and units are never read skips their parsing.
287
+ * @param value - The encoded module, with its records unless `records` holds them.
288
+ * @param source - Module text the engine left out of the maps' `sourcesContent`.
289
+ * @param records - The encoded records, which `transform.compile` writes apart.
290
+ * @returns The output `Transform.compile` returns.
291
+ */
292
+ export function module(
293
+ value: Omit<Module, keyof Records> & Partial<Records>,
294
+ source?: string | undefined,
295
+ records?: string | undefined,
296
+ ): Transform.compile.ReturnType {
297
+ // The engine writes `0` for content the caller supplied separately, so it crosses once.
298
+ if (source !== undefined)
299
+ for (const map of [value.cssMap, value.map]) {
300
+ const contents = map.sourcesContent as (string | null | 0)[] | undefined
301
+
302
+ for (let index = 0; index < (contents?.length ?? 0); index++)
303
+ if (contents![index] === 0) contents![index] = source
304
+ }
305
+
306
+ let decoded: Records | undefined =
307
+ records === undefined ? (value as Records) : undefined
308
+ let classes: Transform.compile.ReturnType['classes'] | undefined
309
+ let rules: Transform.compile.ReturnType[typeof ClassName.rules] | undefined
310
+ let units: Transform.compile.ReturnType[typeof ClassName.units] | undefined
311
+ const read = () => (decoded ??= JSON.parse(records!) as Records)
312
+
313
+ const result = {
314
+ ...(value.shared
315
+ ? {
316
+ [ThemeRules.shared]: Object.freeze(
317
+ value.shared.map((resource) => Object.freeze(resource)),
318
+ ),
319
+ }
320
+ : {}),
321
+ // Parsed records are fresh, so they freeze in place rather than as copies.
322
+ get classes() {
323
+ return (classes ??= Object.freeze(read().classes))
324
+ },
325
+ code: value.code,
326
+ css: value.css,
327
+ cssMap: value.cssMap,
328
+ map: value.map,
329
+ vars: Object.freeze(Object.setPrototypeOf(value.vars, null)),
330
+ }
331
+
332
+ Object.defineProperties(result, {
333
+ [ClassName.rules]: {
334
+ enumerable: false,
335
+ get: () => (rules ??= Object.freeze(read().rules)),
336
+ },
337
+ [ClassName.units]: {
338
+ enumerable: false,
339
+ get: () =>
340
+ (units ??= new Map(
341
+ read().units.map(([key, borrowed, name]) => [
342
+ key,
343
+ { borrowed, name },
344
+ ]),
345
+ )),
346
+ },
347
+ })
348
+
349
+ return Object.freeze(result) as Transform.compile.ReturnType
350
+ }
351
+
352
+ /**
353
+ * Encodes native options as the engine reads them. Sets are written in the `Css.compile` wire
354
+ * format, so the engine decodes them as it decodes literal definitions.
355
+ * @param options - Native options of `Native.compile` or a native graph.
356
+ * @returns The engine's native input.
357
+ */
358
+ export function native(
359
+ options: Omit<Native.compile.Options, 'moduleId' | 'source'>,
360
+ ) {
361
+ return {
362
+ colorScheme: options.colorScheme,
363
+ contextual: options.contextual,
364
+ fonts: options.fonts,
365
+ platform: options.platform,
366
+ runtime: options[Edits.runtime],
367
+ set: options.set,
368
+ units: options.units,
369
+ vars:
370
+ options.vars === undefined
371
+ ? undefined
372
+ : Wire.encode({
373
+ styles: { styles: [] },
374
+ vars: options.vars,
375
+ } as unknown as Css.compile.Options),
376
+ }
377
+ }
378
+
379
+ // A graph's native module carries the web output shape with empty CSS.
380
+ function nativeModule(value: NativeModule): Transform.compile.ReturnType {
381
+ return Object.freeze({
382
+ [ClassName.rules]: Object.freeze({}),
383
+ classes: Object.freeze({}),
384
+ [Edits.key]: value.edits,
385
+ code: value.code,
386
+ css: '',
387
+ cssMap: {
388
+ version: 3 as const,
389
+ names: [],
390
+ sources: [],
391
+ mappings: '',
392
+ },
393
+ map: value.map,
394
+ vars: Object.freeze({}),
395
+ }) as Transform.compile.ReturnType
396
+ }
397
+
398
+ function rendered(value: Rendered) {
399
+ return Object.freeze({
400
+ ...(value.id === undefined ? {} : { id: value.id }),
401
+ css: value.css,
402
+ map: value.map,
403
+ assets: Object.freeze(Object.assign(Object.create(null), value.assets)),
404
+ owners: Object.freeze(Object.assign(Object.create(null), value.owners)),
405
+ })
406
+ }
@@ -1,9 +1,6 @@
1
1
  /** Parses authoring modules while retaining TypeScript assertion syntax. @module */
2
2
  import * as Parser from 'oxc-parser'
3
3
 
4
- /** Parsed modules supplied by the host for a single compilation. */
5
- export const cache = Symbol('parsed modules')
6
-
7
4
  /** Preserves JSX authoring and retries TypeScript files with assertion-aware grammar. */
8
5
  export function parse(options: parse.Options) {
9
6
  const settings = {