zyzz 0.0.27 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. package/binding/wasi/wasi-worker.mjs +186 -0
  2. package/binding/wasi/zyzz.wasi.cjs +2302 -0
  3. package/binding/wasi/zyzz.wasm32-wasi.wasm +0 -0
  4. package/binding/zyzz.linux-x64-gnu.node +0 -0
  5. package/dist/babel/index.d.ts.map +1 -1
  6. package/dist/babel/index.js +2 -4
  7. package/dist/babel/index.js.map +1 -1
  8. package/dist/babel/internal/Compilation.d.ts +0 -1
  9. package/dist/babel/internal/Compilation.d.ts.map +1 -1
  10. package/dist/compiler/Graph.d.ts +14 -11
  11. package/dist/compiler/Graph.d.ts.map +1 -1
  12. package/dist/compiler/Graph.js +57 -1442
  13. package/dist/compiler/Graph.js.map +1 -1
  14. package/dist/compiler/Native.d.ts +7 -9
  15. package/dist/compiler/Native.d.ts.map +1 -1
  16. package/dist/compiler/Native.js +12 -716
  17. package/dist/compiler/Native.js.map +1 -1
  18. package/dist/compiler/Source.d.ts +122 -24
  19. package/dist/compiler/Source.d.ts.map +1 -1
  20. package/dist/compiler/Source.js +10 -1113
  21. package/dist/compiler/Source.js.map +1 -1
  22. package/dist/compiler/Transform.d.ts +4 -3
  23. package/dist/compiler/Transform.d.ts.map +1 -1
  24. package/dist/compiler/Transform.js +13 -958
  25. package/dist/compiler/Transform.js.map +1 -1
  26. package/dist/compiler/internal/AtRules.d.ts +5 -1
  27. package/dist/compiler/internal/AtRules.d.ts.map +1 -1
  28. package/dist/compiler/internal/AtRules.js +12 -106
  29. package/dist/compiler/internal/AtRules.js.map +1 -1
  30. package/dist/compiler/internal/Context.d.ts +11 -0
  31. package/dist/compiler/internal/Context.d.ts.map +1 -0
  32. package/dist/compiler/internal/Context.js +11 -0
  33. package/dist/compiler/internal/Context.js.map +1 -0
  34. package/dist/compiler/internal/Results.d.ts +148 -0
  35. package/dist/compiler/internal/Results.d.ts.map +1 -0
  36. package/dist/compiler/internal/Results.js +259 -0
  37. package/dist/compiler/internal/Results.js.map +1 -0
  38. package/dist/compiler/internal/Syntax.d.ts +0 -2
  39. package/dist/compiler/internal/Syntax.d.ts.map +1 -1
  40. package/dist/compiler/internal/Syntax.js +0 -2
  41. package/dist/compiler/internal/Syntax.js.map +1 -1
  42. package/dist/compiler/internal/Wire.d.ts +17 -0
  43. package/dist/compiler/internal/Wire.d.ts.map +1 -0
  44. package/dist/compiler/internal/Wire.js +795 -0
  45. package/dist/compiler/internal/Wire.js.map +1 -0
  46. package/dist/internal/Addon.d.ts +28 -0
  47. package/dist/internal/Addon.d.ts.map +1 -0
  48. package/dist/internal/Addon.js +87 -0
  49. package/dist/internal/Addon.js.map +1 -0
  50. package/dist/internal/Authoring.d.ts.map +1 -1
  51. package/dist/internal/Authoring.js +37 -7
  52. package/dist/internal/Authoring.js.map +1 -1
  53. package/dist/internal/Configuration.d.ts +6 -1
  54. package/dist/internal/Configuration.d.ts.map +1 -1
  55. package/dist/internal/Configuration.js.map +1 -1
  56. package/dist/internal/Literal.d.ts +5 -2
  57. package/dist/internal/Literal.d.ts.map +1 -1
  58. package/dist/internal/Literal.js +7 -2
  59. package/dist/internal/Literal.js.map +1 -1
  60. package/dist/internal/Theme.d.ts +4 -0
  61. package/dist/internal/Theme.d.ts.map +1 -1
  62. package/dist/internal/Theme.js.map +1 -1
  63. package/dist/internal/Token.d.ts +2 -1
  64. package/dist/internal/Token.d.ts.map +1 -1
  65. package/dist/internal/Token.js +2 -2
  66. package/dist/internal/Token.js.map +1 -1
  67. package/dist/internal/Vlq.d.ts +14 -0
  68. package/dist/internal/Vlq.d.ts.map +1 -0
  69. package/dist/internal/Vlq.js +47 -0
  70. package/dist/internal/Vlq.js.map +1 -0
  71. package/dist/internal/Wasm.d.ts +22 -0
  72. package/dist/internal/Wasm.d.ts.map +1 -0
  73. package/dist/internal/Wasm.js +83 -0
  74. package/dist/internal/Wasm.js.map +1 -0
  75. package/dist/metro/Graph.d.ts +0 -1
  76. package/dist/metro/Graph.d.ts.map +1 -1
  77. package/dist/metro/transformer.d.ts.map +1 -1
  78. package/dist/metro/transformer.js +0 -1
  79. package/dist/metro/transformer.js.map +1 -1
  80. package/dist/next/internal/Project.d.ts.map +1 -1
  81. package/dist/next/internal/Project.js +2 -5
  82. package/dist/next/internal/Project.js.map +1 -1
  83. package/dist/node/Host.d.ts.map +1 -1
  84. package/dist/node/Host.js +0 -2
  85. package/dist/node/Host.js.map +1 -1
  86. package/dist/node/internal/Contracts.d.ts.map +1 -1
  87. package/dist/node/internal/Contracts.js +3 -7
  88. package/dist/node/internal/Contracts.js.map +1 -1
  89. package/dist/node/internal/Snapshot.d.ts +0 -1
  90. package/dist/node/internal/Snapshot.d.ts.map +1 -1
  91. package/dist/node/internal/Snapshot.js +0 -6
  92. package/dist/node/internal/Snapshot.js.map +1 -1
  93. package/dist/runtime/Composition.d.ts +2 -3
  94. package/dist/runtime/Composition.d.ts.map +1 -1
  95. package/dist/runtime/Composition.js +51 -30
  96. package/dist/runtime/Composition.js.map +1 -1
  97. package/dist/runtime/Recipe.d.ts.map +1 -1
  98. package/dist/runtime/Recipe.js +16 -12
  99. package/dist/runtime/Recipe.js.map +1 -1
  100. package/dist/styleFunction.d.ts +11 -2
  101. package/dist/styleFunction.d.ts.map +1 -1
  102. package/dist/styleFunction.js +3 -1
  103. package/dist/styleFunction.js.map +1 -1
  104. package/dist/unplugin/index.d.ts.map +1 -1
  105. package/dist/unplugin/index.js +3 -6
  106. package/dist/unplugin/index.js.map +1 -1
  107. package/dist/vite/index.d.ts +7 -0
  108. package/dist/vite/index.d.ts.map +1 -1
  109. package/dist/vite/index.js +862 -216
  110. package/dist/vite/index.js.map +1 -1
  111. package/dist/web/Css.d.ts +8 -3
  112. package/dist/web/Css.d.ts.map +1 -1
  113. package/dist/web/Css.js +5 -721
  114. package/dist/web/Css.js.map +1 -1
  115. package/dist/web/internal/Block.d.ts +0 -2
  116. package/dist/web/internal/Block.d.ts.map +1 -1
  117. package/dist/web/internal/Block.js +1 -12
  118. package/dist/web/internal/Block.js.map +1 -1
  119. package/dist/web/internal/ClassName.d.ts +23 -18
  120. package/dist/web/internal/ClassName.d.ts.map +1 -1
  121. package/dist/web/internal/ClassName.js +26 -55
  122. package/dist/web/internal/ClassName.js.map +1 -1
  123. package/dist/web/internal/Contributions.d.ts +3 -5
  124. package/dist/web/internal/Contributions.d.ts.map +1 -1
  125. package/dist/web/internal/Contributions.js +0 -45
  126. package/dist/web/internal/Contributions.js.map +1 -1
  127. package/dist/web/internal/Engine.browser.d.ts +8 -0
  128. package/dist/web/internal/Engine.browser.d.ts.map +1 -0
  129. package/dist/web/internal/Engine.browser.js +42 -0
  130. package/dist/web/internal/Engine.browser.js.map +1 -0
  131. package/dist/web/internal/Engine.d.ts +9 -0
  132. package/dist/web/internal/Engine.d.ts.map +1 -0
  133. package/dist/web/internal/Engine.js +14 -0
  134. package/dist/web/internal/Engine.js.map +1 -0
  135. package/dist/web/internal/Themes.d.ts +1 -9
  136. package/dist/web/internal/Themes.d.ts.map +1 -1
  137. package/dist/web/internal/Themes.js +3 -221
  138. package/dist/web/internal/Themes.js.map +1 -1
  139. package/dist/web/internal/Wasm.generated.d.ts +4 -0
  140. package/dist/web/internal/Wasm.generated.d.ts.map +1 -0
  141. package/dist/web/internal/Wasm.generated.js +4 -0
  142. package/dist/web/internal/Wasm.generated.js.map +1 -0
  143. package/dist/web/internal/Wire.d.ts +19 -0
  144. package/dist/web/internal/Wire.d.ts.map +1 -0
  145. package/dist/web/internal/Wire.js +387 -0
  146. package/dist/web/internal/Wire.js.map +1 -0
  147. package/package.json +20 -1
  148. package/src/babel/index.ts +2 -5
  149. package/src/babel/internal/Compilation.ts +0 -1
  150. package/src/compiler/Graph.ts +89 -1930
  151. package/src/compiler/Native.ts +18 -871
  152. package/src/compiler/Source.ts +144 -1579
  153. package/src/compiler/Transform.ts +16 -1312
  154. package/src/compiler/internal/AtRules.ts +27 -115
  155. package/src/compiler/internal/Context.ts +11 -0
  156. package/src/compiler/internal/Results.ts +406 -0
  157. package/src/compiler/internal/Syntax.ts +0 -3
  158. package/src/compiler/internal/Wire.ts +1045 -0
  159. package/src/internal/Addon.ts +118 -0
  160. package/src/internal/Authoring.ts +53 -18
  161. package/src/internal/Configuration.ts +38 -1
  162. package/src/internal/Literal.ts +7 -2
  163. package/src/internal/Theme.ts +15 -0
  164. package/src/internal/Token.ts +2 -2
  165. package/src/internal/Vlq.ts +59 -0
  166. package/src/internal/Wasm.ts +111 -0
  167. package/src/metro/transformer.ts +0 -1
  168. package/src/next/internal/Project.ts +2 -9
  169. package/src/node/Host.ts +0 -2
  170. package/src/node/internal/Contracts.ts +3 -7
  171. package/src/node/internal/Snapshot.ts +0 -8
  172. package/src/runtime/Composition.ts +48 -25
  173. package/src/runtime/Recipe.ts +21 -14
  174. package/src/styleFunction.ts +31 -2
  175. package/src/unplugin/index.ts +6 -6
  176. package/src/vite/index.ts +1157 -241
  177. package/src/web/Css.ts +12 -908
  178. package/src/web/internal/Block.ts +0 -14
  179. package/src/web/internal/ClassName.ts +52 -85
  180. package/src/web/internal/Contributions.ts +3 -59
  181. package/src/web/internal/Engine.browser.ts +51 -0
  182. package/src/web/internal/Engine.ts +17 -0
  183. package/src/web/internal/Themes.ts +3 -279
  184. package/src/web/internal/Wasm.generated.ts +3 -0
  185. package/src/web/internal/Wire.ts +466 -0
  186. package/src/web/internal/wasm.d.ts +9 -0
  187. package/dist/compiler/internal/Applications.d.ts +0 -55
  188. package/dist/compiler/internal/Applications.d.ts.map +0 -1
  189. package/dist/compiler/internal/Applications.js +0 -352
  190. package/dist/compiler/internal/Applications.js.map +0 -1
  191. package/dist/compiler/internal/ColorProfiles.d.ts +0 -3
  192. package/dist/compiler/internal/ColorProfiles.d.ts.map +0 -1
  193. package/dist/compiler/internal/ColorProfiles.js +0 -84
  194. package/dist/compiler/internal/ColorProfiles.js.map +0 -1
  195. package/dist/compiler/internal/CompositionBindings.d.ts +0 -16
  196. package/dist/compiler/internal/CompositionBindings.d.ts.map +0 -1
  197. package/dist/compiler/internal/CompositionBindings.js +0 -89
  198. package/dist/compiler/internal/CompositionBindings.js.map +0 -1
  199. package/dist/compiler/internal/Compositions.d.ts +0 -37
  200. package/dist/compiler/internal/Compositions.d.ts.map +0 -1
  201. package/dist/compiler/internal/Compositions.js +0 -494
  202. package/dist/compiler/internal/Compositions.js.map +0 -1
  203. package/dist/compiler/internal/Configurations.d.ts +0 -26
  204. package/dist/compiler/internal/Configurations.d.ts.map +0 -1
  205. package/dist/compiler/internal/Configurations.js +0 -259
  206. package/dist/compiler/internal/Configurations.js.map +0 -1
  207. package/dist/compiler/internal/Contract.d.ts +0 -30
  208. package/dist/compiler/internal/Contract.d.ts.map +0 -1
  209. package/dist/compiler/internal/Contract.js +0 -753
  210. package/dist/compiler/internal/Contract.js.map +0 -1
  211. package/dist/compiler/internal/Contributions.d.ts +0 -54
  212. package/dist/compiler/internal/Contributions.d.ts.map +0 -1
  213. package/dist/compiler/internal/Contributions.js +0 -1151
  214. package/dist/compiler/internal/Contributions.js.map +0 -1
  215. package/dist/compiler/internal/Descriptors.d.ts +0 -15
  216. package/dist/compiler/internal/Descriptors.d.ts.map +0 -1
  217. package/dist/compiler/internal/Descriptors.js +0 -192
  218. package/dist/compiler/internal/Descriptors.js.map +0 -1
  219. package/dist/compiler/internal/Dynamic.d.ts +0 -14
  220. package/dist/compiler/internal/Dynamic.d.ts.map +0 -1
  221. package/dist/compiler/internal/Dynamic.js +0 -175
  222. package/dist/compiler/internal/Dynamic.js.map +0 -1
  223. package/dist/compiler/internal/Expression.d.ts +0 -19
  224. package/dist/compiler/internal/Expression.d.ts.map +0 -1
  225. package/dist/compiler/internal/Expression.js +0 -164
  226. package/dist/compiler/internal/Expression.js.map +0 -1
  227. package/dist/compiler/internal/Functions.d.ts +0 -5
  228. package/dist/compiler/internal/Functions.d.ts.map +0 -1
  229. package/dist/compiler/internal/Functions.js +0 -191
  230. package/dist/compiler/internal/Functions.js.map +0 -1
  231. package/dist/compiler/internal/Keyframes.d.ts +0 -5
  232. package/dist/compiler/internal/Keyframes.d.ts.map +0 -1
  233. package/dist/compiler/internal/Keyframes.js +0 -51
  234. package/dist/compiler/internal/Keyframes.js.map +0 -1
  235. package/dist/compiler/internal/Names.d.ts +0 -5
  236. package/dist/compiler/internal/Names.d.ts.map +0 -1
  237. package/dist/compiler/internal/Names.js +0 -37
  238. package/dist/compiler/internal/Names.js.map +0 -1
  239. package/dist/compiler/internal/NativeBindings.d.ts +0 -72
  240. package/dist/compiler/internal/NativeBindings.d.ts.map +0 -1
  241. package/dist/compiler/internal/NativeBindings.js +0 -171
  242. package/dist/compiler/internal/NativeBindings.js.map +0 -1
  243. package/dist/compiler/internal/NativeMedia.d.ts +0 -14
  244. package/dist/compiler/internal/NativeMedia.d.ts.map +0 -1
  245. package/dist/compiler/internal/NativeMedia.js +0 -287
  246. package/dist/compiler/internal/NativeMedia.js.map +0 -1
  247. package/dist/compiler/internal/NativeVars.d.ts +0 -28
  248. package/dist/compiler/internal/NativeVars.d.ts.map +0 -1
  249. package/dist/compiler/internal/NativeVars.js +0 -160
  250. package/dist/compiler/internal/NativeVars.js.map +0 -1
  251. package/dist/compiler/internal/PackedStyles.d.ts +0 -37
  252. package/dist/compiler/internal/PackedStyles.d.ts.map +0 -1
  253. package/dist/compiler/internal/PackedStyles.js +0 -344
  254. package/dist/compiler/internal/PackedStyles.js.map +0 -1
  255. package/dist/compiler/internal/Properties.d.ts +0 -5
  256. package/dist/compiler/internal/Properties.d.ts.map +0 -1
  257. package/dist/compiler/internal/Properties.js +0 -82
  258. package/dist/compiler/internal/Properties.js.map +0 -1
  259. package/dist/compiler/internal/RecipeConditions.d.ts +0 -41
  260. package/dist/compiler/internal/RecipeConditions.d.ts.map +0 -1
  261. package/dist/compiler/internal/RecipeConditions.js +0 -82
  262. package/dist/compiler/internal/RecipeConditions.js.map +0 -1
  263. package/dist/compiler/internal/RecipePayloads.d.ts +0 -31
  264. package/dist/compiler/internal/RecipePayloads.d.ts.map +0 -1
  265. package/dist/compiler/internal/RecipePayloads.js +0 -99
  266. package/dist/compiler/internal/RecipePayloads.js.map +0 -1
  267. package/dist/compiler/internal/Recipes.d.ts +0 -32
  268. package/dist/compiler/internal/Recipes.d.ts.map +0 -1
  269. package/dist/compiler/internal/Recipes.js +0 -339
  270. package/dist/compiler/internal/Recipes.js.map +0 -1
  271. package/dist/compiler/internal/Selectors.d.ts +0 -12
  272. package/dist/compiler/internal/Selectors.d.ts.map +0 -1
  273. package/dist/compiler/internal/Selectors.js +0 -268
  274. package/dist/compiler/internal/Selectors.js.map +0 -1
  275. package/dist/compiler/internal/Static.d.ts +0 -39
  276. package/dist/compiler/internal/Static.d.ts.map +0 -1
  277. package/dist/compiler/internal/Static.js +0 -534
  278. package/dist/compiler/internal/Static.js.map +0 -1
  279. package/dist/compiler/internal/Themes.d.ts +0 -190
  280. package/dist/compiler/internal/Themes.d.ts.map +0 -1
  281. package/dist/compiler/internal/Themes.js +0 -1577
  282. package/dist/compiler/internal/Themes.js.map +0 -1
  283. package/dist/compiler/internal/Vars.d.ts +0 -33
  284. package/dist/compiler/internal/Vars.d.ts.map +0 -1
  285. package/dist/compiler/internal/Vars.js +0 -387
  286. package/dist/compiler/internal/Vars.js.map +0 -1
  287. package/dist/compiler/internal/ViewTransitions.d.ts +0 -3
  288. package/dist/compiler/internal/ViewTransitions.d.ts.map +0 -1
  289. package/dist/compiler/internal/ViewTransitions.js +0 -68
  290. package/dist/compiler/internal/ViewTransitions.js.map +0 -1
  291. package/dist/internal/Cascade.d.ts +0 -74
  292. package/dist/internal/Cascade.d.ts.map +0 -1
  293. package/dist/internal/Cascade.js +0 -210
  294. package/dist/internal/Cascade.js.map +0 -1
  295. package/src/compiler/internal/Applications.ts +0 -554
  296. package/src/compiler/internal/ColorProfiles.ts +0 -93
  297. package/src/compiler/internal/CompositionBindings.ts +0 -120
  298. package/src/compiler/internal/Compositions.ts +0 -678
  299. package/src/compiler/internal/Configurations.ts +0 -349
  300. package/src/compiler/internal/Contract.ts +0 -1028
  301. package/src/compiler/internal/Contributions.ts +0 -1561
  302. package/src/compiler/internal/Descriptors.ts +0 -242
  303. package/src/compiler/internal/Dynamic.ts +0 -275
  304. package/src/compiler/internal/Expression.ts +0 -218
  305. package/src/compiler/internal/Functions.ts +0 -206
  306. package/src/compiler/internal/Keyframes.ts +0 -62
  307. package/src/compiler/internal/Names.ts +0 -48
  308. package/src/compiler/internal/NativeBindings.ts +0 -235
  309. package/src/compiler/internal/NativeMedia.ts +0 -342
  310. package/src/compiler/internal/NativeVars.ts +0 -231
  311. package/src/compiler/internal/PackedStyles.ts +0 -473
  312. package/src/compiler/internal/Properties.ts +0 -121
  313. package/src/compiler/internal/RecipeConditions.ts +0 -139
  314. package/src/compiler/internal/RecipePayloads.ts +0 -132
  315. package/src/compiler/internal/Recipes.ts +0 -531
  316. package/src/compiler/internal/Selectors.ts +0 -339
  317. package/src/compiler/internal/Static.ts +0 -784
  318. package/src/compiler/internal/Themes.ts +0 -2398
  319. package/src/compiler/internal/Vars.ts +0 -516
  320. package/src/compiler/internal/ViewTransitions.ts +0 -82
@@ -0,0 +1,466 @@
1
+ /**
2
+ * Encodes `Css.compile` input as the Rust compiler's JSON wire format and decodes its result.
3
+ * The format is documented in `crates/compiler/src/wire.rs`.
4
+ * @module
5
+ */
6
+ import * as Binding from '../../internal/Binding.js'
7
+ import * as Token from '../../internal/Token.js'
8
+ import type * as Style from '../../Style.js'
9
+ import * as Css from '../Css.js'
10
+ import type * as Block from './Block.js'
11
+ import * as ClassName from './ClassName.js'
12
+ import type * as Contributions from './Contributions.js'
13
+ import * as Themes from './Themes.js'
14
+
15
+ /**
16
+ * Encodes compiler input, listing each identity-compared object once in post order.
17
+ * Reads own properties without invoking accessors on definitions and leaves inputs unchanged.
18
+ * @param options - Input accepted by `Css.compile`.
19
+ * @returns JSON text for the Rust compiler.
20
+ */
21
+ export function encode(options: Css.compile.Options): string {
22
+ const indexes = new Map<object, number>()
23
+ const objects: unknown[] = []
24
+ // Declarations share reference objects, which are classified once per encoding.
25
+ const references = new Map<object, number | undefined>()
26
+ const strings: string[] = []
27
+ const stringIndexes = new Map<string, number>()
28
+
29
+ // Repeated property names and values are written once.
30
+ function string(value: string): number {
31
+ const previous = stringIndexes.get(value)
32
+ if (previous !== undefined) return previous
33
+
34
+ stringIndexes.set(value, strings.length)
35
+ strings.push(value)
36
+
37
+ return strings.length - 1
38
+ }
39
+
40
+ // Dependencies are encoded first, so every entry refers only to earlier entries.
41
+ function add(key: object, entry: () => unknown): number {
42
+ const previous = indexes.get(key)
43
+ if (previous !== undefined) return previous
44
+
45
+ const value = entry()
46
+
47
+ indexes.set(key, objects.length)
48
+ objects.push(value)
49
+
50
+ return objects.length - 1
51
+ }
52
+
53
+ function contract(value: Token.Contract): number {
54
+ return add(value, () => {
55
+ const fields: Record<string, unknown> = { keys: Object.keys(value) }
56
+
57
+ if (value[Token.complete]) fields.complete = true
58
+
59
+ const identity = value[Token.identity]
60
+ if (typeof identity === 'string') fields.identity = identity
61
+
62
+ if (value.variableSet) fields.variableSet = true
63
+ if (value.mappings !== undefined) fields.mappings = value.mappings
64
+ if (typeof value.composition === 'string')
65
+ fields.composition = value.composition
66
+ if (typeof value.cssOutput === 'string')
67
+ fields.cssOutput = value.cssOutput
68
+ if (typeof value.defaultLayer === 'string')
69
+ fields.defaultLayer = value.defaultLayer
70
+ if (value.shorthands !== undefined) fields.shorthands = value.shorthands
71
+
72
+ return ['c', fields]
73
+ })
74
+ }
75
+
76
+ function reference(value: unknown): number {
77
+ if (Binding.is(value))
78
+ return add(value, () => [
79
+ 'b',
80
+ value.name,
81
+ value.type,
82
+ value[Binding.dynamic] === true,
83
+ ])
84
+
85
+ if (Token.is(value))
86
+ return add(value, () => [
87
+ 't',
88
+ contract(value.contract),
89
+ value.group,
90
+ value.path,
91
+ tokenValue(value.value),
92
+ (value as Partial<Record<typeof Token.web, boolean>>)[Token.web] ===
93
+ true,
94
+ ])
95
+
96
+ if (Token.isExpression(value))
97
+ return add(value, () => [
98
+ 'e',
99
+ Object.hasOwn(value, 'group')
100
+ ? (value as unknown as Token.Composition).group
101
+ : null,
102
+ value.parts.map((part) =>
103
+ typeof part === 'string' ? part : [reference(part)],
104
+ ),
105
+ ])
106
+
107
+ throw new Error('Expected a binding, token reference, or expression.')
108
+ }
109
+
110
+ function number(value: number): unknown {
111
+ return Number.isFinite(value) ? value : { n: String(value) }
112
+ }
113
+
114
+ function tokenValue(input: unknown): unknown {
115
+ if (typeof input === 'string') return input
116
+ if (typeof input === 'number') return number(input)
117
+ if (Token.is(input) || Token.isExpression(input)) return [reference(input)]
118
+
119
+ if (typeof input === 'object' && input !== null)
120
+ return {
121
+ r: Object.entries(input).map(([key, entry]) => [
122
+ key,
123
+ tokenValue(entry),
124
+ ]),
125
+ }
126
+
127
+ return String(input)
128
+ }
129
+
130
+ // The encoded index of a binding, token reference, or expression, classified once per object.
131
+ function known(value: object): number | undefined {
132
+ if (references.has(value)) return references.get(value)
133
+
134
+ const index =
135
+ Binding.is(value) || Token.is(value) || Token.isExpression(value)
136
+ ? reference(value)
137
+ : undefined
138
+
139
+ references.set(value, index)
140
+
141
+ return index
142
+ }
143
+
144
+ // Flat triples of property, value, and flags: bit 0 marks importance, and the remaining
145
+ // bits select a string, finite number, object, or non-finite number value.
146
+ function declarations(input: readonly Style.Declaration[]): number[] {
147
+ const output: number[] = []
148
+
149
+ for (const declaration of input) {
150
+ const value: unknown = declaration.value
151
+ const important = declaration.important ? 1 : 0
152
+
153
+ output.push(string(declaration.property))
154
+
155
+ if (typeof value === 'string') output.push(string(value), important)
156
+ else if (typeof value === 'number' && Number.isFinite(value))
157
+ output.push(value, 2 | important)
158
+ else if (typeof value === 'number')
159
+ output.push(Number.isNaN(value) ? 0 : Math.sign(value), 6 | important)
160
+ else {
161
+ const index =
162
+ typeof value === 'object' && value !== null ? known(value) : undefined
163
+
164
+ // Values outside the declaration contract serialize as their template-literal text.
165
+ if (index === undefined) output.push(string(String(value)), important)
166
+ else output.push(index, 4 | important)
167
+ }
168
+ }
169
+
170
+ return output
171
+ }
172
+
173
+ function theme(value: Token.Metadata): number {
174
+ return add(value, () => [
175
+ 'm',
176
+ contract(value.contract),
177
+ value.cssName ?? null,
178
+ Object.entries(value.values).map(([path, entry]) => [
179
+ path,
180
+ tokenValue(entry),
181
+ ]),
182
+ value.paths ?? null,
183
+ value.queries ?? null,
184
+ ])
185
+ }
186
+
187
+ function own(value: object, key: string): unknown {
188
+ return Object.getOwnPropertyDescriptor(value, key)?.value
189
+ }
190
+
191
+ function style(input: Style.NamedStyle): unknown {
192
+ const output: Record<string, unknown> = {
193
+ d: declarations(input.declarations),
194
+ n: input.name,
195
+ }
196
+
197
+ if (input.rules)
198
+ output.r = input.rules.map((rule) => [
199
+ rule.condition === undefined ? null : String(rule.condition),
200
+ style(rule.style),
201
+ ])
202
+
203
+ // Only own modes apply; inherited metadata is ignored.
204
+ const cssOutput = own(input, 'cssOutput')
205
+ if (cssOutput !== undefined)
206
+ output.o = typeof cssOutput === 'string' ? cssOutput : false
207
+
208
+ const composition = own(input, 'composition')
209
+ if (composition !== undefined && composition !== null)
210
+ output.c = typeof composition === 'string' ? composition : false
211
+
212
+ if (input.targets) {
213
+ const targets: Record<string, unknown> = {}
214
+
215
+ for (const key of ['android', 'ios', 'native'] as const)
216
+ if (input.targets[key] !== undefined) targets[key] = input.targets[key]
217
+
218
+ if (input.targets.web) targets.web = style(input.targets.web)
219
+
220
+ output.t = targets
221
+ }
222
+
223
+ return output
224
+ }
225
+
226
+ function scalar(value: string | number): unknown {
227
+ return typeof value === 'number' && !Number.isFinite(value)
228
+ ? String(value)
229
+ : value
230
+ }
231
+
232
+ function entry(value: Block.Entry): unknown {
233
+ if (value.kind === 'style')
234
+ return { kind: 'style', style: style(value.style) }
235
+
236
+ if (value.kind === 'block')
237
+ return {
238
+ entries: value.entries.map(entry),
239
+ header: value.header,
240
+ kind: 'block',
241
+ }
242
+
243
+ return { kind: 'descriptor', name: value.name, value: scalar(value.value) }
244
+ }
245
+
246
+ function contribution(value: Contributions.Definition): unknown {
247
+ const within = value.within?.length ? { within: value.within } : {}
248
+
249
+ switch (value.kind) {
250
+ case 'block':
251
+ return {
252
+ entries: value.entries.map(entry),
253
+ header: value.header,
254
+ kind: value.kind,
255
+ ...within,
256
+ }
257
+ case 'custom-media':
258
+ return {
259
+ kind: value.kind,
260
+ name: value.name,
261
+ query: String(value.query),
262
+ ...within,
263
+ }
264
+ case 'descriptor':
265
+ return {
266
+ declarations: Object.entries(value.declarations).map(
267
+ ([key, entry]) => [key, scalar(entry)],
268
+ ),
269
+ kind: value.kind,
270
+ name: value.name,
271
+ rule: value.rule,
272
+ ...within,
273
+ }
274
+ case 'font-face':
275
+ return {
276
+ declarations: Object.entries(value.declarations).map(
277
+ ([key, entry]) => [key, scalar(entry)],
278
+ ),
279
+ kind: value.kind,
280
+ ...within,
281
+ }
282
+ case 'import':
283
+ return {
284
+ kind: value.kind,
285
+ ...(value.layer === true
286
+ ? { layer: true }
287
+ : value.layer
288
+ ? { layer: value.layer }
289
+ : {}),
290
+ ...(value.media ? { media: value.media } : {}),
291
+ ...(value.supports ? { supports: value.supports } : {}),
292
+ url: value.url,
293
+ ...within,
294
+ }
295
+ case 'keyframes':
296
+ return {
297
+ frames: value.frames.map((frame) => [frame.stop, style(frame.style)]),
298
+ kind: value.kind,
299
+ name: value.name,
300
+ ...within,
301
+ }
302
+ case 'layers':
303
+ return { kind: value.kind, names: value.names, ...within }
304
+ case 'namespace':
305
+ return {
306
+ kind: value.kind,
307
+ name: value.name,
308
+ ...(value.prefix === undefined ? {} : { prefix: value.prefix }),
309
+ uri: value.uri,
310
+ ...within,
311
+ }
312
+ case 'property':
313
+ return {
314
+ inherits: value.inherits,
315
+ ...(value.initialValue === undefined
316
+ ? {}
317
+ : { initialValue: scalar(value.initialValue) }),
318
+ kind: value.kind,
319
+ name: value.name,
320
+ syntax: value.syntax,
321
+ ...within,
322
+ }
323
+ case 'rule':
324
+ return {
325
+ kind: value.kind,
326
+ selector: value.selector,
327
+ style: style(value.style),
328
+ ...within,
329
+ }
330
+ }
331
+ }
332
+
333
+ // `??` treats null as absent for composition, while any present output mode is validated.
334
+ function mode(value: unknown, nullable: boolean): unknown {
335
+ if (value === undefined || (nullable && value === null)) return undefined
336
+ return typeof value === 'string' ? value : false
337
+ }
338
+
339
+ const styles = options.styles.styles.map(style)
340
+ const contributions = (options.contributions ?? []).map(contribution)
341
+ const vars =
342
+ options.vars &&
343
+ Object.entries(options.vars).map(([name, value]) => {
344
+ if (value === null || value === undefined) return [name, null]
345
+
346
+ const metadata = Object.getOwnPropertyDescriptor(value, Token.definition)
347
+ ?.value as Token.Metadata | undefined
348
+
349
+ return [name, value && metadata ? theme(metadata) : false]
350
+ })
351
+ const labels = options[ClassName.labels] ?? options.styles[ClassName.labels]
352
+ const units = options[ClassName.units]?.[ClassName.state]?.read()
353
+ const shared = options[Themes.shared]
354
+ const composition = mode(options.composition, true)
355
+ const cssOutput = mode(options.cssOutput, true)
356
+
357
+ // The decoder resolves the object and string tables before it reads styles.
358
+ return JSON.stringify({
359
+ objects,
360
+ strings,
361
+ ...(composition === undefined ? {} : { composition }),
362
+ ...(contributions.length ? { contributions } : {}),
363
+ ...(cssOutput === undefined ? {} : { cssOutput }),
364
+ ...(options.development ? { development: true } : {}),
365
+ ...(labels
366
+ ? {
367
+ labels: Object.entries(labels).map(([name, label]) => [
368
+ name,
369
+ label?.name ?? null,
370
+ label?.namespace ?? null,
371
+ ]),
372
+ }
373
+ : {}),
374
+ ...(options.names
375
+ ? {
376
+ names: Object.entries(options.names).filter(
377
+ ([, id]) => typeof id === 'string',
378
+ ),
379
+ }
380
+ : {}),
381
+ ...(options.schemes ? { schemes: true } : {}),
382
+ ...(typeof options.scope === 'string' && options.scope
383
+ ? { scope: options.scope }
384
+ : {}),
385
+ ...(shared ? { shared: shared === 'all' ? 'all' : 'defaults' } : {}),
386
+ styles,
387
+ ...(units
388
+ ? {
389
+ units: {
390
+ names: units.names,
391
+ owner: units.owner,
392
+ qualifier: units.qualifier,
393
+ visible: units.visible ?? null,
394
+ },
395
+ }
396
+ : {}),
397
+ ...(vars ? { vars } : {}),
398
+ })
399
+ }
400
+
401
+ /** Decoded output fields, as the Rust compiler emits them. */
402
+ type Output = {
403
+ readonly classes: Readonly<Record<string, string>>
404
+ readonly contributionCss?: string | undefined
405
+ readonly css: string
406
+ readonly error?:
407
+ | {
408
+ readonly diagnostics?: readonly Css.Diagnostic[] | undefined
409
+ readonly message: string
410
+ readonly name: string
411
+ }
412
+ | undefined
413
+ readonly rules: Readonly<Record<string, string>>
414
+ readonly scopedCss?: string | undefined
415
+ readonly shared?: readonly Themes.Resource[] | undefined
416
+ readonly units: readonly (readonly [string, boolean, string])[]
417
+ readonly vars: Readonly<Record<string, string>>
418
+ }
419
+
420
+ /**
421
+ * Decodes a Rust compiler result into the frozen `Css.compile` result.
422
+ * Records unit naming decisions in the supplied scope's shared table.
423
+ * @param json - JSON text from the Rust compiler.
424
+ * @param units - The scope whose table the compilation borrowed, when one was supplied.
425
+ * @returns The same shape `Css.compile` returns.
426
+ * @throws {Css.CompileError} When the compilation reported diagnostics.
427
+ */
428
+ export function decode(
429
+ json: string,
430
+ units?: ClassName.Units | undefined,
431
+ ): Css.compile.ReturnType {
432
+ const output = JSON.parse(json) as Output
433
+
434
+ if (output.error) {
435
+ if (output.error.diagnostics)
436
+ throw new Css.CompileError(output.error.diagnostics)
437
+ throw new Error(output.error.message)
438
+ }
439
+
440
+ const used = new Map(
441
+ output.units.map(([key, borrowed, name]) => [key, { borrowed, name }]),
442
+ )
443
+
444
+ units?.[ClassName.state]?.record(used)
445
+
446
+ const result = {
447
+ ...(output.shared ? { [Themes.shared]: output.shared } : {}),
448
+ ...(output.contributionCss === undefined
449
+ ? {}
450
+ : {
451
+ contributionCss: output.contributionCss,
452
+ scopedCss: output.scopedCss,
453
+ }),
454
+ [ClassName.units]: units?.used ?? used,
455
+ // Parsed records are fresh, so they freeze in place rather than as copies.
456
+ [ClassName.rules]: Object.freeze(output.rules),
457
+ classes: Object.freeze(Object.setPrototypeOf(output.classes, null)),
458
+ css: output.css,
459
+ vars: Object.freeze(Object.setPrototypeOf(output.vars, null)),
460
+ }
461
+
462
+ Object.defineProperty(result, ClassName.rules, { enumerable: false })
463
+ Object.defineProperty(result, ClassName.units, { enumerable: false })
464
+
465
+ return Object.freeze(result) as Css.compile.ReturnType
466
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Declares the generated WebAssembly compiler module for type checks that run before a build.
3
+ * `scripts/build-wasm.ts` writes `Wasm.generated.ts`, which `#wasm` resolves to when present.
4
+ * @module
5
+ */
6
+ declare module '#wasm' {
7
+ /** The `crates/wasm` web build, base64 encoded. */
8
+ export const base64: string
9
+ }
@@ -1,55 +0,0 @@
1
- /** Finds nonescaping local static callables whose applications can become props. @module */
2
- import type * as Ast from '@oxc-project/types';
3
- import type * as Source from '../Source.js';
4
- /** Conservatively proves direct applications without changing binding reads. */
5
- export declare function create(program: Ast.Program, calls: readonly Source.Call[], options?: create.Options): Collector | undefined;
6
- /** Proven call site and its compiled definition. */
7
- type Application = {
8
- /** End of the original binding or property read. */
9
- readonly calleeEnd: number;
10
- /** End of the application. */
11
- readonly end: number;
12
- /** Whether the read runs at top level after its definition initializes. */
13
- readonly initialized: boolean;
14
- /** Extracted class identity. */
15
- readonly name: string;
16
- /** Start of the application. */
17
- readonly start: number;
18
- /** Whether a DOM element receives the props alone, so its classes meet no other style's. */
19
- readonly terminal: boolean;
20
- };
21
- /** A top-level namespace whose members are all static definitions. */
22
- type Namespace = {
23
- /** Member identifier ends keyed by extracted name. */
24
- readonly ends: ReadonlyMap<string, number>;
25
- /** Start of the namespace statement. */
26
- readonly start: number;
27
- };
28
- /** Binding references gathered during the transform's existing walk. */
29
- type Collector = {
30
- /** Definitions with no observable value reads, retaining escaped containers. */
31
- dead: () => ReadonlySet<string>;
32
- /**
33
- * Static definitions whose every read is a found application, keyed by
34
- * extracted name with whether every read is initialized. Namespaces list
35
- * those whose definitions all qualify with initialized reads.
36
- */
37
- definitions: () => {
38
- readonly namespaces: readonly Namespace[];
39
- readonly values: ReadonlyMap<string, boolean>;
40
- };
41
- /** Records relevant reads and their immediate parents. */
42
- enter: (node: Ast.Node, parent: Ast.Node | null | undefined) => void;
43
- /** Resolves applications after traversal completes. */
44
- find: () => readonly Application[];
45
- };
46
- /** Local application collection modes. */
47
- export declare namespace create {
48
- /** Controls whether arguments are retained for fixed runtime compositions. */
49
- type Options = {
50
- /** Includes recipe/value applications while preserving their runtime calls. */
51
- readonly dynamic?: boolean | undefined;
52
- };
53
- }
54
- export {};
55
- //# sourceMappingURL=Applications.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Applications.d.ts","sourceRoot":"","sources":["../../../src/compiler/internal/Applications.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,OAAO,KAAK,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAG9C,OAAO,KAAK,KAAK,MAAM,MAAM,cAAc,CAAA;AAE3C,gFAAgF;AAChF,wBAAgB,MAAM,CACpB,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,KAAK,EAAE,SAAS,MAAM,CAAC,IAAI,EAAE,EAC7B,OAAO,GAAE,MAAM,CAAC,OAAY,GAC3B,SAAS,GAAG,SAAS,CA6avB;AAED,oDAAoD;AACpD,KAAK,WAAW,GAAG;IACjB,oDAAoD;IACpD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,8BAA8B;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,2EAA2E;IAC3E,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;IAC7B,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,gCAAgC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,sEAAsE;AACtE,KAAK,SAAS,GAAG;IACf,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1C,wCAAwC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,wEAAwE;AACxE,KAAK,SAAS,GAAG;IACf,gFAAgF;IAChF,IAAI,EAAE,MAAM,WAAW,CAAC,MAAM,CAAC,CAAA;IAC/B;;;;OAIG;IACH,WAAW,EAAE,MAAM;QACjB,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAA;QACzC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC9C,CAAA;IACD,0DAA0D;IAC1D,KAAK,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAA;IACpE,uDAAuD;IACvD,IAAI,EAAE,MAAM,SAAS,WAAW,EAAE,CAAA;CACnC,CAAA;AAED,0CAA0C;AAC1C,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,8EAA8E;IAC9E,KAAK,OAAO,GAAG;QACb,+EAA+E;QAC/E,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KACvC,CAAA;CACF"}