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
@@ -13,17 +13,3 @@ export type Entry =
13
13
  readonly header: string
14
14
  readonly entries: readonly Entry[]
15
15
  }
16
- /** Renders a structured block while delegating ordinary property serialization to the CSS compiler. */
17
- export function render(
18
- entries: readonly Entry[],
19
- style: (value: Style.NamedStyle) => string,
20
- ): string {
21
- return entries
22
- .map((entry) => {
23
- if (entry.kind === 'style') return style(entry.style)
24
- if (entry.kind === 'block')
25
- return `${entry.header}{${render(entry.entries, style)}}`
26
- return `${entry.name}:${entry.value};`
27
- })
28
- .join('')
29
- }
@@ -1,88 +1,4 @@
1
- /** Names atomic declarations with readable values and scoped conflict identities. @module */
2
- import * as Literal from '../../internal/Literal.js'
3
-
4
- /** Creates a CSS identifier without embedding arbitrary CSS syntax. */
5
- export function create(options: create.Options): string {
6
- const property = Object.hasOwn(aliases, options.property)
7
- ? aliases[options.property]!
8
- : Literal.name(options.property)
9
- const condition =
10
- /^&:(hover|focus|focus-visible|active|disabled)\{([^{}]+)\}$/.exec(
11
- options.body,
12
- )
13
- const body = condition?.[2] ?? options.body
14
- const prefix = `${Literal.name(options.property)}:`
15
- const literal =
16
- body.startsWith(prefix) && body.endsWith(';')
17
- ? body.slice(prefix.length, -1)
18
- : ''
19
- const simple = /^[a-zA-Z0-9-]{1,24}$/.test(literal)
20
- const namespace = options.namespace ? `${options.namespace}-` : ''
21
- if (options.context !== undefined)
22
- return `z-${namespace}${options.context}-${encode(property)}${options.slot === undefined ? '' : `-${options.slot}`}`
23
-
24
- const value = simple ? literal : `[${literal || body}]`
25
- const readable =
26
- options.property === 'display' && displays.has(literal)
27
- ? literal
28
- : property.startsWith('--')
29
- ? `[${property}:${literal || body}]`
30
- : `${property}-${value}`
31
- // DOM class tokens cannot contain whitespace; preserve its spelling reversibly.
32
- return `z-${namespace}${condition ? `${condition[1]}-` : ''}${readable.replace(/[\s_"'<>]/gu, (character) => `_${character.codePointAt(0)!.toString(16)}_`)}`
33
- }
34
-
35
- /** Atomic naming inputs; context retains declaration ordering and module ownership. */
36
- export declare namespace create {
37
- /** Serialized declaration and its optional stable slot identity. */
38
- type Options = {
39
- /** Complete declaration, including fallbacks and conditions. */
40
- readonly body: string
41
- /** Identity required when the declaration cannot share a global rule. */
42
- readonly context?: string | undefined
43
- /** Optional consumer-owned configuration namespace. */
44
- readonly namespace?: string | undefined
45
- /** Authoring property spelling. */
46
- readonly property: string
47
- /** Ordered declaration slot inside a contextual style. */
48
- readonly slot?: number | undefined
49
- }
50
- }
51
-
52
- const aliases: Readonly<Record<string, string>> = {
53
- backgroundColor: 'bg',
54
- color: 'text',
55
- height: 'h',
56
- margin: 'm',
57
- marginBottom: 'mb',
58
- marginLeft: 'ml',
59
- marginRight: 'mr',
60
- marginTop: 'mt',
61
- opacity: 'opacity',
62
- padding: 'p',
63
- paddingBottom: 'pb',
64
- paddingLeft: 'pl',
65
- paddingRight: 'pr',
66
- paddingTop: 'pt',
67
- width: 'w',
68
- }
69
-
70
- // Flex and grid also name shorthand properties, so retain their display prefix.
71
- const displays = new Set([
72
- 'block',
73
- 'inline',
74
- 'inline-block',
75
- 'inline-flex',
76
- 'inline-grid',
77
- 'none',
78
- ])
79
-
80
- function encode(value: string): string {
81
- return value.replace(
82
- /[^a-zA-Z0-9-]/g,
83
- (character) => `_${character.charCodeAt(0).toString(16)}_`,
84
- )
85
- }
1
+ /** Escapes class tokens and shares unit names across a graph's compilations. @module */
86
2
 
87
3
  /** Escapes a generated class token for use as a CSS selector. */
88
4
  export function selector(value: string): string {
@@ -108,10 +24,35 @@ export const complete = Symbol('zyzz.css.complete')
108
24
  export type Units = {
109
25
  /** Names a declaration unit, reusing a visible earlier name for an equal body. */
110
26
  readonly name: (body: string, namespace: string | undefined) => string
27
+ /** Shared table access for compilers outside this JavaScript realm. */
28
+ readonly [state]?: State | undefined
111
29
  /** Names chosen so far, keyed by namespace and body, and whether each was reused. */
112
30
  readonly used: ReadonlyMap<string, Decision>
113
31
  }
114
32
 
33
+ /** Exposes a scope's shared name table to compilers outside this JavaScript realm. */
34
+ export const state = Symbol('zyzz.css.units.state')
35
+
36
+ /** Reads and updates one scope's shared name table without naming units. */
37
+ export type State = {
38
+ /** Snapshots every registered name, this scope's identity, and the owners it may borrow from. */
39
+ readonly read: () => Snapshot
40
+ /** Applies decisions made outside this realm, as if this scope had named each unit. */
41
+ readonly record: (used: ReadonlyMap<string, Decision>) => void
42
+ }
43
+
44
+ /** A scope's view of the shared name table. */
45
+ export type Snapshot = {
46
+ /** Registered names as `[key, name, owner]`, in registration order. */
47
+ readonly names: readonly (readonly [string, string, string])[]
48
+ /** Compilation identity recorded on the names it introduces. */
49
+ readonly owner: string
50
+ /** Fixed prefix distinguishing this compilation's new names. */
51
+ readonly qualifier: string
52
+ /** Owners whose names this scope may reuse, or `undefined` for every owner. */
53
+ readonly visible: readonly string[] | undefined
54
+ }
55
+
115
56
  /** A naming decision recorded so cached output can be validated against a later build. */
116
57
  export type Decision = {
117
58
  /** Whether the name was introduced by an earlier compilation. */
@@ -171,6 +112,32 @@ export function registry(): registry.ReturnType {
171
112
 
172
113
  return name
173
114
  },
115
+ [state]: {
116
+ read() {
117
+ const owners = new Set([
118
+ options.owner,
119
+ ...[...names.values()].map((entry) => entry.owner),
120
+ ])
121
+
122
+ return {
123
+ names: [...names].map(
124
+ ([key, entry]) => [key, entry.name, entry.owner] as const,
125
+ ),
126
+ owner: options.owner,
127
+ qualifier: options.qualifier,
128
+ visible: options.visible
129
+ ? [...owners].filter(options.visible)
130
+ : undefined,
131
+ }
132
+ },
133
+ record(decisions) {
134
+ for (const [key, decision] of decisions) {
135
+ if (!names.has(key))
136
+ names.set(key, { name: decision.name, owner: options.owner })
137
+ used.set(key, decision)
138
+ }
139
+ },
140
+ },
174
141
  used,
175
142
  }
176
143
  },
@@ -1,6 +1,6 @@
1
- /** Pure ordered stylesheet contribution data and layer ordering. @module */
2
- import * as Block from './Block.js'
3
- import * as Namespace from './Namespace.js'
1
+ /** Ordered stylesheet contribution data and layer ordering. @module */
2
+ import type * as Block from './Block.js'
3
+ import type * as Namespace from './Namespace.js'
4
4
  import type * as Style from '../../Style.js'
5
5
 
6
6
  /** Explicit stylesheet data supplied by source adapters or in-memory callers. */
@@ -161,59 +161,3 @@ export function order(
161
161
 
162
162
  return result
163
163
  }
164
-
165
- /** Renders static contributions without registration or environment access. */
166
- export function render(
167
- definitions: readonly Definition[],
168
- style: (value: Style.NamedStyle) => string,
169
- ): string {
170
- const layers = order(
171
- definitions.flatMap((value) =>
172
- value.kind === 'layers' ? [value.names] : [],
173
- ),
174
- )
175
-
176
- return [
177
- layers.length ? `@layer ${layers.join(',')};` : '',
178
- ...definitions
179
- .toSorted((a, b) => rank(a) - rank(b))
180
- .map((value) => {
181
- if (value.kind === 'layers') return ''
182
- const css = (() => {
183
- if (value.kind === 'namespace') return Namespace.statement(value)
184
- if (value.kind === 'custom-media')
185
- return `@custom-media ${value.name} ${value.query};`
186
- if (value.kind === 'import')
187
- return `@import url(${JSON.stringify(value.url)})${value.layer === true ? ' layer' : value.layer ? ` layer(${value.layer})` : ''}${value.supports ? ` supports(${value.supports})` : ''}${value.media ? ` ${value.media}` : ''};`
188
- if (value.kind === 'block')
189
- return `${value.header}{${Block.render(value.entries, style)}}`
190
- if (value.kind === 'rule')
191
- return `${value.selector}{${style(value.style)}}`
192
- if (value.kind === 'property')
193
- return `@property ${value.name}{syntax:${JSON.stringify(value.syntax)};inherits:${value.inherits};${value.initialValue === undefined ? '' : `initial-value:${value.initialValue};`}}`
194
- if (value.kind === 'font-face' || value.kind === 'descriptor')
195
- return `@${value.kind === 'font-face' ? 'font-face' : `${value.rule} ${value.name}`}{${Object.entries(
196
- value.declarations,
197
- )
198
- .map(
199
- ([key, value]) =>
200
- `${key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}:${value};`,
201
- )
202
- .join('')}}`
203
- return `@keyframes ${value.name}{${value.frames.map((frame) => `${frame.stop}{${style(frame.style)}}`).join('')}}`
204
- })()
205
- return (value.within ?? []).reduceRight(
206
- (body, header) => `${header}{${body}}`,
207
- css,
208
- )
209
- }),
210
- ]
211
- .filter(Boolean)
212
- .join('\n')
213
- }
214
-
215
- function rank(value: Definition): number {
216
- if (value.kind === 'import') return 0
217
- if (value.kind === 'namespace') return 1
218
- return 2
219
- }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Runs compiler operations in the WebAssembly build inlined into the bundle, for browsers and
3
+ * workers. It needs no Node built-ins, network, or asynchronous start.
4
+ * @module
5
+ */
6
+ import * as Module from '#wasm'
7
+ import * as Wasm from '../../internal/Wasm.js'
8
+
9
+ // Compiling the module is the expensive step, so one instance serves the realm.
10
+ let instance: Wasm.Instance | undefined
11
+
12
+ /**
13
+ * Runs a named compiler operation on JSON input.
14
+ * @param operation - Operation name, such as `css.compile`.
15
+ * @param input - UTF-8 JSON input.
16
+ * @returns UTF-8 JSON output, including encoded failures.
17
+ */
18
+ export function call(operation: string, input: string): string {
19
+ instance ??= Wasm.instantiate(decode(Module.base64))
20
+
21
+ return instance.call(operation, input)
22
+ }
23
+
24
+ const alphabet =
25
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
26
+
27
+ // Decodes without `atob`, which bare realms such as Node `vm` contexts lack.
28
+ function decode(text: string): Uint8Array<ArrayBuffer> {
29
+ const values = new Uint8Array(128)
30
+
31
+ for (let index = 0; index < alphabet.length; index++)
32
+ values[alphabet.charCodeAt(index)] = index
33
+
34
+ const padding = text.length - text.replace(/=+$/u, '').length
35
+ const output = new Uint8Array((text.length / 4) * 3 - padding)
36
+ let position = 0
37
+
38
+ for (let index = 0; index < text.length; index += 4) {
39
+ const bits =
40
+ (values[text.charCodeAt(index)]! << 18) |
41
+ (values[text.charCodeAt(index + 1)]! << 12) |
42
+ (values[text.charCodeAt(index + 2)]! << 6) |
43
+ values[text.charCodeAt(index + 3)]!
44
+
45
+ output[position++] = bits >> 16
46
+ if (position < output.length) output[position++] = (bits >> 8) & 255
47
+ if (position < output.length) output[position++] = bits & 255
48
+ }
49
+
50
+ return output
51
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Runs compiler operations in the native addon. The package.json `browser` field replaces this
3
+ * module with `Engine.browser.ts`, so browser bundles never import Node built-ins.
4
+ * @module
5
+ */
6
+ import * as Addon from '../../internal/Addon.js'
7
+ // The type import keeps both engines' contracts identical and the browser engine in the build.
8
+ import type * as Browser from './Engine.browser.js'
9
+
10
+ /**
11
+ * Runs a named compiler operation on JSON input.
12
+ * @param operation - Operation name, such as `css.compile`.
13
+ * @param input - UTF-8 JSON input.
14
+ * @returns UTF-8 JSON output, including encoded failures.
15
+ */
16
+ export const call: typeof Browser.call = (operation, input) =>
17
+ Addon.load().call(operation, input)
@@ -1,14 +1,11 @@
1
1
  /**
2
- * Collects live theme references and emits graph-local variables and scope rules.
2
+ * Serializes live theme references and combines generated scope rules.
3
3
  * @module
4
4
  */
5
5
  import * as Identity from '../../internal/Identity.js'
6
- import * as Scheme from '../../internal/Scheme.js'
7
6
  import * as Token from '../../internal/Token.js'
8
- import type * as Vars from '../../Vars.js'
9
- import type * as Theme from '../../internal/Theme.js'
10
7
 
11
- /** Collects live token references within one in-memory compilation graph. */
8
+ /** Serializes live token references with graph-local variable names. */
12
9
  export function create() {
13
10
  const contracts = new Map<
14
11
  Token.Contract,
@@ -33,9 +30,6 @@ export function create() {
33
30
  return name
34
31
  }
35
32
 
36
- const defaults = new Map<string, readonly Rule[]>()
37
- const defaultGroups = new Map<Token.Contract, Set<string>>()
38
-
39
33
  function serialize(token: Token.Reference): string {
40
34
  const value = token.value
41
35
  let contract = contracts.get(token.contract)
@@ -59,198 +53,6 @@ export function create() {
59
53
  return `var(${name},${literal(value, label, token.contract)})`
60
54
  }
61
55
 
62
- function emit(
63
- themes: Readonly<Record<string, Theme.Definition | Vars.Definition>>,
64
- schemes = false,
65
- separate?: 'all' | 'defaults',
66
- ) {
67
- const classes: Record<string, string> = Object.create(null)
68
- let nextScope = 0
69
- const scopeBodies = new Map<string, string>()
70
- const completeDefaults = new Set<Token.Contract>()
71
- const empty: string[] = []
72
- const rules: Rule[] = []
73
- const varied = variedPaths(themes)
74
-
75
- for (const [name, theme] of Object.entries(themes)) {
76
- if (!name) throw new Error('Theme names must be nonempty.')
77
-
78
- const data =
79
- theme &&
80
- (Object.getOwnPropertyDescriptor(theme, Token.definition)?.value as
81
- | Token.Metadata
82
- | undefined)
83
- if (!data) throw new Error('Expected a theme definition.')
84
-
85
- // Anonymous contracts are graph-local. Source-owned contracts retain stable
86
- // identities across separately compiled components and theme scopes.
87
- const className =
88
- data.contract[Token.identity] || data.cssName
89
- ? scope(
90
- data.cssName ??
91
- (data.contract[Token.identity] &&
92
- name.startsWith(`${data.contract[Token.identity]}-`)
93
- ? name.slice(data.contract[Token.identity]!.length + 1)
94
- : name),
95
- data.contract[Token.identity],
96
- )
97
- : `z${(nextScope++).toString(36)}`
98
-
99
- classes[name] = className
100
-
101
- let contract = contracts.get(data.contract)
102
-
103
- if (data.contract[Token.complete]) {
104
- contract ??= {
105
- identity: data.contract[Token.identity],
106
- paths: new Map(),
107
- }
108
-
109
- // Separately compiled components may reference tokens absent from this graph.
110
- for (const path of Object.keys(data.values)) {
111
- if (contract.paths.has(path)) continue
112
-
113
- contract.paths.set(path, property(data.contract, path))
114
- }
115
-
116
- contracts.set(data.contract, contract)
117
- }
118
-
119
- if (!contract) continue
120
-
121
- // Independently compiled consumers must import identical fallback contents.
122
- if (separate === 'all' && contract.identity) {
123
- completeDefaults.add(data.contract)
124
- for (const [path, value] of Object.entries(data.values))
125
- literal(value, path, data.contract)
126
- }
127
- if (!contract.paths.size) empty.push(`.${className}{}`)
128
-
129
- const declarations: Rule[] = []
130
- // Resolving a value can add references to this contract.
131
- const paths = [...contract.paths]
132
- for (const [path, name] of paths) {
133
- const value = data.values[path]
134
- // A set sharing its contract with an extension lacks the extension's added paths.
135
- if (value === undefined) continue
136
- // An inherited base reference resolves through its fallback, unless a sibling set overrides it.
137
- if (
138
- inherited(value, path, data.contract) &&
139
- !varied.get(data.contract)?.has(path)
140
- )
141
- continue
142
-
143
- const label = path
144
- declarations.push({
145
- conditions: [],
146
- property: name,
147
- selector: `.${className}`,
148
- value: literal(value, label, data.contract),
149
- })
150
- }
151
-
152
- rules.push(...declarations)
153
- for (const [path, name] of contract.paths)
154
- if (Object.hasOwn(data.values, path))
155
- conditional(
156
- data.values[path]!,
157
- name,
158
- `.${className}`,
159
- rules,
160
- path,
161
- [],
162
- data.contract,
163
- )
164
- }
165
-
166
- for (const rule of rules) {
167
- const key = JSON.stringify([
168
- rule.selector,
169
- rule.conditions,
170
- rule.property,
171
- ])
172
- const previous = scopeBodies.get(key)
173
- if (previous !== undefined && previous !== rule.value)
174
- throw new Error(
175
- `Generated scope ${rule.selector.slice(1)} conflicts. Supply distinct config ids.`,
176
- )
177
- scopeBodies.set(key, rule.value)
178
- }
179
-
180
- const scopes = new Map<string, Rule[]>()
181
- for (const rule of rules) {
182
- const entries = scopes.get(rule.property) ?? []
183
- entries.push(rule)
184
- scopes.set(rule.property, entries)
185
- }
186
-
187
- const grouped = new Set<string>()
188
- const resources: Resource[] = []
189
- if (separate === 'all')
190
- for (const [contract, names] of defaultGroups) {
191
- if (!completeDefaults.has(contract)) continue
192
-
193
- // Sort independent properties only. Each property retains its authored conditional order.
194
- const rules = [...names].sort().flatMap((name) => defaults.get(name)!)
195
- resources.push({
196
- css: render(rules),
197
- id: JSON.stringify([
198
- contract[Token.identity],
199
- 'fallbacks',
200
- Object.entries(themes)
201
- .filter(
202
- ([, theme]) => theme[Token.definition].contract === contract,
203
- )
204
- .map(([name]) => name)
205
- .sort(),
206
- ]),
207
- rules,
208
- })
209
- for (const name of names) grouped.add(name)
210
- }
211
-
212
- return {
213
- classes: Object.freeze(classes),
214
- css:
215
- separate === 'all'
216
- ? ''
217
- : [
218
- ...empty,
219
- render([
220
- ...(separate ? [] : [...defaults.values()].flat()),
221
- ...rules,
222
- ]),
223
- ...(schemes ? [Scheme.css] : []),
224
- ]
225
- .filter(Boolean)
226
- .join('\n'),
227
- rules,
228
- resources: separate
229
- ? [
230
- ...resources,
231
- ...[...defaults]
232
- .filter(([id]) => !grouped.has(id))
233
- .map(([id, rules]) => ({
234
- css: render(rules),
235
- id,
236
- rules,
237
- })),
238
- // Keep every scope of a property together so overlapping themes retain precedence.
239
- ...(separate === 'all'
240
- ? [...scopes].map(([property, rules]) => ({
241
- css: render(rules),
242
- id: JSON.stringify([classes, property]),
243
- rules,
244
- }))
245
- : []),
246
- ...(separate === 'all' && schemes
247
- ? [{ css: Scheme.css, id: 'zyzz-color-scheme' }]
248
- : []),
249
- ]
250
- : [],
251
- }
252
- }
253
-
254
56
  function literal(
255
57
  value: Token.Value,
256
58
  label?: string,
@@ -268,16 +70,6 @@ export function create() {
268
70
  // Rule consolidation must not change existing variable identities, so the name hashes the fallback's CSS.
269
71
  const css = `:where(*){--fallback:${base};}${conditionalCss(value, '--fallback', ':where(*)', label, owner)}`
270
72
  const name = `${owner ? property(owner, label ?? 'value') : variable(undefined, label ?? 'value')}-fallback-${Identity.hash(css)}`
271
- const emitted: Rule[] = [
272
- { conditions: [], property: name, selector: ':where(*)', value: base },
273
- ]
274
- conditional(value, name, ':where(*)', emitted, label, [], owner)
275
- defaults.set(name, emitted)
276
- if (owner) {
277
- const names = defaultGroups.get(owner) ?? new Set<string>()
278
- names.add(name)
279
- defaultGroups.set(owner, names)
280
- }
281
73
  return `var(${name})`
282
74
  }
283
75
  return `light-dark(${literal(value.light, label, owner)},${literal(value.dark, label, owner)})`
@@ -309,37 +101,7 @@ export function create() {
309
101
  )
310
102
  }
311
103
 
312
- function conditional(
313
- value: Token.Value,
314
- name: string,
315
- selector: string,
316
- rules: Rule[],
317
- label?: string,
318
- conditions: readonly string[] = [],
319
- owner?: Token.Contract,
320
- ) {
321
- if (
322
- !value ||
323
- typeof value !== 'object' ||
324
- Token.is(value) ||
325
- !('default' in value)
326
- )
327
- return
328
- conditional(value.default, name, selector, rules, label, conditions, owner)
329
- for (const [query, entry] of Object.entries(value)) {
330
- if (query === 'default') continue
331
- const nested = [...conditions, query]
332
- rules.push({
333
- conditions: nested,
334
- property: name,
335
- selector,
336
- value: literal(entry, label, owner),
337
- })
338
- conditional(entry, name, selector, rules, label, nested, owner)
339
- }
340
- }
341
-
342
- return { emit, serialize }
104
+ return { serialize }
343
105
  }
344
106
 
345
107
  /** Combines generated declarations without crossing competing declarations of the same property. */
@@ -417,44 +179,6 @@ export function scope(value: string, identity?: string): string {
417
179
  return `z-theme-${namespace}${Identity.name(value)}`
418
180
  }
419
181
 
420
- /** Whether a set's value is its base's own reference at the same path, as named extensions inherit. */
421
- function inherited(value: Token.Value, path: string, contract: Token.Contract) {
422
- return Token.is(value) && value.path === path && value.contract !== contract
423
- }
424
-
425
- /** Paths whose values differ between sets that share a contract. */
426
- function variedPaths(
427
- themes: Readonly<Record<string, Theme.Definition | Vars.Definition>>,
428
- ) {
429
- const seen = new Map<Token.Contract, Map<string, string>>()
430
- const varied = new Map<Token.Contract, Set<string>>()
431
-
432
- for (const theme of Object.values(themes)) {
433
- const data = Object.getOwnPropertyDescriptor(theme, Token.definition)
434
- ?.value as Token.Metadata | undefined
435
- if (!data) continue
436
-
437
- const values = seen.get(data.contract) ?? new Map<string, string>()
438
- seen.set(data.contract, values)
439
-
440
- for (const [path, value] of Object.entries(data.values)) {
441
- const key = Token.is(value)
442
- ? JSON.stringify([value.contract[Token.identity], value.path])
443
- : JSON.stringify(value)
444
- const previous = values.get(path)
445
-
446
- if (previous === undefined) values.set(path, key)
447
- else if (previous !== key) {
448
- const paths = varied.get(data.contract) ?? new Set<string>()
449
- paths.add(path)
450
- varied.set(data.contract, paths)
451
- }
452
- }
453
- }
454
-
455
- return varied
456
- }
457
-
458
182
  function variable(identity: string | undefined, path: string): string {
459
183
  const namespace = identity?.startsWith('id-') ? `${identity.slice(3)}-` : ''
460
184
  return `--z-${namespace}${path.split('.').map(Identity.name).join('-')}`