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,231 +0,0 @@
1
- /** Converts authored variables to static native value profiles. @module */
2
- import * as Calculation from '../../react-native/internal/Calculation.js'
3
- import * as Literal from '../../internal/Literal.js'
4
- import * as Media from './NativeMedia.js'
5
- import type * as Runtime from '../../runtime/NativeVars.js'
6
- import * as Scalar from '../../react-native/internal/Scalar.js'
7
- import type * as Theme from '../../internal/Theme.js'
8
- import * as Token from '../../internal/Token.js'
9
- import * as VariableSets from '../../internal/VariableSets.js'
10
-
11
- /** Resolves native domains using the style compiler's unit and font mappings. */
12
- export function compile(options: compile.Options): Runtime.create.Options {
13
- const media = Media.prepare(undefined, options.vars, options)
14
- return {
15
- defaultVars: options.defaultVars,
16
- ...(media
17
- ? {
18
- media: {
19
- profiles: Object.fromEntries(
20
- media.selections.map((selection) => [
21
- selection,
22
- compile({ ...options, vars: media.select(selection).vars! })
23
- .profiles,
24
- ]),
25
- ),
26
- queries: media.queries,
27
- },
28
- }
29
- : {}),
30
- profiles: Object.fromEntries(
31
- Object.entries(options.vars).map((entry) => {
32
- const [name, theme] = entry
33
- return [
34
- name,
35
- { dark: profile(theme, 'dark'), light: profile(theme, 'light') },
36
- ]
37
- }),
38
- ),
39
- unnamed: options.unnamed,
40
- }
41
-
42
- function profile(theme: Theme.Definition, scheme: 'dark' | 'light') {
43
- const metadata = theme[Token.definition]
44
- const active = new Set<Token.Reference>()
45
- type Tree = {
46
- [key: string]: string | number | Tree | readonly [string]
47
- }
48
- const tree: Tree = Object.create(null)
49
-
50
- function resolve(value: Token.Value): string | number {
51
- if (typeof value === 'string' || typeof value === 'number') return value
52
- if (Token.is(value)) {
53
- if (active.has(value))
54
- throw new Error('Native token aliases must not form a cycle.')
55
- const shared =
56
- metadata.contract === value.contract ||
57
- (metadata.contract[Token.identity] !== undefined &&
58
- metadata.contract[Token.identity] ===
59
- value.contract[Token.identity])
60
- const next = shared ? metadata.values[value.path] : value.value
61
- if (next === undefined)
62
- throw new Error(`Missing native token: ${value.path}.`)
63
- active.add(value)
64
- try {
65
- return resolve(next)
66
- } finally {
67
- active.delete(value)
68
- }
69
- }
70
- if (Token.isExpression(value) && 'group' in value) {
71
- const text = value.parts.map(resolve).join('')
72
- return value.group === 'spacing' && /^\s*calc\(/i.test(text)
73
- ? `${Calculation.length(text, options) / (options.units?.px ?? 1)}px`
74
- : text
75
- }
76
- if ('light' in value && 'dark' in value) return resolve(value[scheme])
77
- throw new Error(
78
- media
79
- ? 'Native media-conditioned variables require the native Provider window dimensions.'
80
- : 'Media-conditioned variables require a web target.',
81
- )
82
- }
83
-
84
- for (const [path, source] of Object.entries(metadata.values)) {
85
- const parts = metadata.paths?.[path] ?? path.split('.')
86
- const property = parts.at(-1)
87
- const domain = VariableSets.domain(source)
88
- const mappings = metadata.contract.mappings
89
- const properties = mappings === false ? undefined : mappings?.[parts[0]!]
90
- const category = parts[0] === 'typography' ? property! : parts[0]!
91
- const target = category === 'radius' ? 'borderRadius' : category
92
- const targets = properties?.length
93
- ? properties
94
- : Object.hasOwn(Scalar.properties, target)
95
- ? [target]
96
- : []
97
-
98
- const converted = (() => {
99
- try {
100
- if (parts.some((part) => /^@(media|container)\s/.test(part)))
101
- throw new Error('Media-conditioned variables require a web target.')
102
- const value = resolve(source)
103
-
104
- function convert(property: string): string | number {
105
- property =
106
- property in Literal.aliases
107
- ? Literal.aliases[property as keyof typeof Literal.aliases]
108
- : property
109
- if (!Object.hasOwn(Scalar.properties, property))
110
- throw new Error(`Unsupported native property: ${property}.`)
111
-
112
- if (property === 'lineHeight') {
113
- if (
114
- typeof value === 'string' &&
115
- (/^\s*calc\(/i.test(value) ||
116
- /^\s*[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(?:px|rem)\s*$/i.test(
117
- value,
118
- ))
119
- )
120
- return Scalar.length(
121
- value.trim().toLowerCase(),
122
- options,
123
- false,
124
- [path],
125
- )
126
-
127
- const multiplier =
128
- typeof value === 'number' ? value : Number(value)
129
- if (
130
- !Number.isFinite(multiplier) ||
131
- (typeof value === 'string' && !value.trim())
132
- )
133
- throw new Error(`Unsupported native line height: ${value}.`)
134
- const size =
135
- parts[0] === 'typography'
136
- ? metadata.values[
137
- [...parts.slice(0, -1), 'fontSize'].join('.')
138
- ]
139
- : undefined
140
- if (size === undefined)
141
- throw new Error(
142
- `Native line height requires fontSize: ${path}.`,
143
- )
144
- return Scalar.convert(
145
- 'number',
146
- multiplier *
147
- Scalar.length(resolve(size), options, false, [path]),
148
- options,
149
- [path],
150
- )
151
- }
152
-
153
- const kind =
154
- Scalar.properties[property as keyof typeof Scalar.properties]
155
- if (
156
- typeof kind === 'string' &&
157
- [
158
- 'flex',
159
- 'fontVariant',
160
- 'origin',
161
- 'shadow',
162
- 'textShadow',
163
- 'transform',
164
- ].includes(kind)
165
- )
166
- throw new Error(
167
- `Native property ${property} does not have a scalar variable value.`,
168
- )
169
- if (kind === 'ratio' && typeof value !== 'number')
170
- throw new Error(
171
- 'Native aspect ratios require numeric variable values.',
172
- )
173
- if (kind === 'box' || kind === 'boxSigned')
174
- return Scalar.length(value, options, kind === 'boxSigned', [path])
175
- if (kind === 'boxOffset')
176
- return Scalar.convert('offset', value, options, [path])
177
- return Scalar.convert(kind, value, options, [path])
178
- }
179
-
180
- if (targets.length) {
181
- const values = targets.map(convert)
182
- if (values.some((value) => value !== values[0]))
183
- throw new Error(
184
- 'Mapped native properties require different converted values.',
185
- )
186
- return values[0]!
187
- }
188
- if (domain === 'spacing')
189
- return Scalar.length(value, options, true, [path])
190
- if (domain === 'color')
191
- return Scalar.convert('color', value, options, [path])
192
- return value
193
- } catch (error) {
194
- return [
195
- `Native variable ${path}: ${error instanceof Error ? error.message : String(error)}`,
196
- ] as const
197
- }
198
- })()
199
- let parent = tree
200
- for (const key of parts.slice(0, -1))
201
- parent = (parent[key] ??= Object.create(null)) as typeof tree
202
- parent[parts.at(-1)!] = converted
203
- }
204
- return tree
205
- }
206
- }
207
-
208
- /** Compiler inputs for resolved native variables. */
209
- export declare namespace compile {
210
- /** Complete variable catalog and explicit target mappings. */
211
- type Options = Scalar.Options & {
212
- /** Configuration fallback. */
213
- readonly defaultVars: string
214
- /** Whether the input is a standalone definition instead of a named catalog. */
215
- readonly unnamed: boolean
216
- /** Compatible authored definitions. */
217
- readonly vars: Readonly<Record<string, Theme.Definition>>
218
- }
219
- }
220
-
221
- /** Graph-owned profile exports and imports, excluded from public adapter options. */
222
- export const shared = Symbol('zyzz.compiler.native.vars')
223
-
224
- /** Static profile artifacts belonging to one source module. */
225
- export type Shared = {
226
- readonly definitions: ReadonlyMap<string, string>
227
- readonly reads: ReadonlyMap<
228
- number,
229
- { readonly name: string; readonly source?: string | undefined }
230
- >
231
- }
@@ -1,473 +0,0 @@
1
- /** Preserves ordered style bodies and runtime ownership across package boundaries. @module */
2
- import type * as Recipe from '../../internal/Recipe.js'
3
- import type * as RuntimeRecipe from '../../runtime/Recipe.js'
4
- import * as Targets from '../../internal/Targets.js'
5
- import * as Binding from '../../internal/Binding.js'
6
- import * as Condition from '../../internal/Condition.js'
7
- import * as ConditionalRecipe from '../../runtime/ConditionalRecipe.js'
8
- import * as Literal from '../../internal/Literal.js'
9
- import type * as Source from '../Source.js'
10
- import type * as Style from '../../Style.js'
11
- import type * as Theme from '../../internal/Theme.js'
12
- import * as Token from '../../internal/Token.js'
13
-
14
- /** Portable composition inputs; selection behavior remains in the compiled callable. */
15
- export type Definition = {
16
- /** Runtime scalar slots retained without executable callback bodies. */
17
- readonly dynamic?:
18
- | {
19
- readonly recipe: Recipe.Definition
20
- readonly slots: NonNullable<Source.Call['slots']>
21
- readonly payloads?: RuntimeRecipe.Definition['payloads']
22
- readonly defaultPayloads?: RuntimeRecipe.Definition['defaultPayloads']
23
- }
24
- | undefined
25
- /** Exact published classes replaced by a composition. Filled by graph emission. */
26
- readonly className?: string | undefined
27
- /** Attributes owned by the callable, including conditional selections. */
28
- readonly attributes: readonly string[]
29
- /** Named Provider selections retained by separately compiled styles. */
30
- readonly nativeContext?: Source.Call['nativeContext']
31
- /** Native HTML output; React props are the default. */
32
- readonly output?: 'html' | undefined
33
- /** Private dynamic custom properties owned by the callable. */
34
- readonly slots: readonly string[]
35
- /** Target-neutral finite recipe retained for native consumers. */
36
- readonly staticRecipe?: Recipe.Definition | undefined
37
- /** Complete finite alternatives in authored cascade order. */
38
- readonly style: Style.NamedStyle
39
- }
40
-
41
- /** Captures ownership without retaining source ASTs or executable expressions. */
42
- export function create(call: Source.Call, style: Style.NamedStyle): Definition {
43
- return {
44
- ...(call.nativeContext ? { nativeContext: call.nativeContext } : {}),
45
- ...(call.slots || call.dynamicRecipe
46
- ? {
47
- dynamic: {
48
- recipe: call.dynamicRecipe ?? {
49
- axes: {},
50
- defaults: {},
51
- rules: [{ matches: [], value: { styles: [style] } }],
52
- },
53
- slots: call.slots ?? {},
54
- payloads: call.recipe?.payloads,
55
- defaultPayloads: call.recipe?.defaultPayloads,
56
- },
57
- }
58
- : {}),
59
- attributes: Object.keys(call.recipe?.axes ?? {}).flatMap((axis) => [
60
- `data-${axis}`,
61
- ...(call.recipe?.conditions ?? []).map((_, condition) =>
62
- ConditionalRecipe.attribute({ axis, condition }),
63
- ),
64
- ]),
65
- ...(call.output ? { output: call.output } : {}),
66
- slots: [
67
- ...Object.values(call.slots ?? {}).map((slot) => slot.name),
68
- ...(call.recipe?.payloads ?? []).flatMap((payload) =>
69
- payload.slots.flatMap((slots) => Object.values(slots)),
70
- ),
71
- ],
72
- staticRecipe:
73
- call.staticRecipe ??
74
- (!call.slots && !call.recipe && call.output !== 'html'
75
- ? {
76
- axes: {},
77
- defaults: {},
78
- rules: [{ matches: [], value: { styles: [style] } }],
79
- }
80
- : undefined),
81
- style,
82
- }
83
- }
84
-
85
- /** Validates compiler data and restores live theme references without executing package code. */
86
- export function read(
87
- value: unknown,
88
- themes: Readonly<Record<string, Theme.Definition>>,
89
- version = 17,
90
- ): Definition {
91
- const tokens = new Map<string, Token.Reference>()
92
- function collect(value: unknown) {
93
- if (Token.is(value)) {
94
- tokens.set(
95
- JSON.stringify([value.contract[Token.identity], value.path]),
96
- value,
97
- )
98
- // Catalog themes share identities and paths but retain distinct fallback values.
99
- tokens.set(
100
- JSON.stringify(
101
- [value.contract[Token.identity], value.path, value.value],
102
- encode,
103
- ),
104
- value,
105
- )
106
- return
107
- }
108
- if (value && typeof value === 'object')
109
- for (const child of Object.values(value)) collect(child)
110
- }
111
- for (const theme of Object.values(themes)) collect(theme.tokens)
112
-
113
- function scalar(value: unknown, depth = 0): Style.Declaration['value'] {
114
- if (depth > 64)
115
- throw new Error('Packed style expression exceeds 64 levels.')
116
-
117
- if (
118
- typeof value === 'string' ||
119
- (typeof value === 'number' && Number.isFinite(value))
120
- )
121
- return value
122
- const item = object(value)
123
- if (item.kind === 'token') {
124
- const token = tokens.get(
125
- JSON.stringify([
126
- item.identity,
127
- item.path,
128
- ...(Object.hasOwn(item, 'value') ? [item.value] : []),
129
- ]),
130
- )
131
- if (!token) throw new Error('Unknown packed style token.')
132
- return token
133
- }
134
- if (item.kind === 'expression') {
135
- const parts = array(item.parts).map((part) => scalar(part, depth + 1))
136
- if (
137
- parts.some(
138
- (part) => typeof part === 'number' || Token.isExpression(part),
139
- )
140
- )
141
- throw new Error('Invalid packed style expression.')
142
- return Token.compose(
143
- parts as readonly (string | Token.Reference | Binding.Reference)[],
144
- )
145
- }
146
- const binding = Object.freeze(item)
147
- if (Binding.is(binding) && /^--z-[a-zA-Z0-9_-]+$/.test(binding.name))
148
- return binding
149
- throw new Error('Invalid packed style value.')
150
- }
151
-
152
- function style(value: unknown, depth = 0): Style.NamedStyle {
153
- if (depth > 64) throw new Error('Packed style nesting exceeds 64 levels.')
154
- const item = object(value)
155
- if (item.targets !== undefined && version < 20)
156
- throw new Error('Target branches require contract version 20 or later.')
157
- if (
158
- item.cssOutput !== undefined &&
159
- item.cssOutput !== 'atomic' &&
160
- item.cssOutput !== 'grouped'
161
- )
162
- throw new Error('Invalid packed style CSS output mode.')
163
- if (
164
- item.composition !== undefined &&
165
- (version < 34 ||
166
- (item.composition !== 'independent' && item.composition !== 'ordered'))
167
- )
168
- throw new Error('Invalid packed style composition mode.')
169
- return {
170
- ...(item.composition
171
- ? { composition: item.composition as 'independent' | 'ordered' }
172
- : {}),
173
- ...(item.cssOutput
174
- ? { cssOutput: item.cssOutput as 'atomic' | 'grouped' }
175
- : {}),
176
- declarations: array(item.declarations).map((value) => {
177
- const declaration = object(value)
178
- const property = string(declaration.property)
179
- if (
180
- !Object.hasOwn(Literal.rules, property) &&
181
- !property.startsWith('--')
182
- )
183
- throw new Error('Invalid packed style property.')
184
- if (
185
- declaration.important !== undefined &&
186
- typeof declaration.important !== 'boolean'
187
- )
188
- throw new Error('Invalid packed style importance.')
189
- return {
190
- important: declaration.important,
191
- property,
192
- value: scalar(declaration.value),
193
- } as Style.Declaration
194
- }),
195
- name: string(item.name),
196
- ...(item.targets === undefined
197
- ? {}
198
- : {
199
- targets: (() => {
200
- const targets = object(item.targets)
201
- if (
202
- Object.keys(targets).some(
203
- (key) => !['android', 'ios', 'native', 'web'].includes(key),
204
- )
205
- )
206
- throw new Error('Unknown packed style target.')
207
- return {
208
- ...(targets.android === undefined
209
- ? {}
210
- : {
211
- android: Targets.copy(
212
- object(targets.android),
213
- ) as NonNullable<Style.NamedStyle['targets']>['android'],
214
- }),
215
- ...(targets.ios === undefined
216
- ? {}
217
- : {
218
- ios: Targets.copy(object(targets.ios)) as NonNullable<
219
- Style.NamedStyle['targets']
220
- >['ios'],
221
- }),
222
- ...(targets.native === undefined
223
- ? {}
224
- : {
225
- native: Targets.copy(
226
- object(targets.native),
227
- ) as NonNullable<Style.NamedStyle['targets']>['native'],
228
- }),
229
- ...(targets.web === undefined
230
- ? {}
231
- : { web: style(targets.web, depth + 1) }),
232
- }
233
- })(),
234
- }),
235
- ...(item.rules === undefined
236
- ? {}
237
- : {
238
- rules: array(item.rules).map((value) => {
239
- const rule = object(value)
240
- const condition =
241
- rule.condition === undefined
242
- ? undefined
243
- : string(rule.condition)
244
- if (
245
- condition !== undefined &&
246
- !condition.startsWith('@') &&
247
- !Condition.nested(condition)
248
- )
249
- throw new Error('Invalid packed style condition.')
250
- return {
251
- ...(condition ? { condition } : {}),
252
- style: style(rule.style, depth + 1),
253
- }
254
- }),
255
- }),
256
- }
257
- }
258
-
259
- const item = object(value)
260
- if (version >= 17 && object(item.style).cssOutput === undefined)
261
- throw new Error('Missing packed style CSS output mode.')
262
- const attributes = array(item.attributes).map(string)
263
- const slots = array(item.slots).map(string)
264
- if (
265
- attributes.some((name) => !/^data-[a-zA-Z0-9_-]+$/.test(name)) ||
266
- slots.some((name) => !/^--z-[a-zA-Z0-9_-]+$/.test(name)) ||
267
- (item.output !== undefined && item.output !== 'html')
268
- )
269
- throw new Error('Invalid packed style ownership.')
270
- function readRecipe(input: unknown) {
271
- if (input === undefined) return undefined
272
- if (version < 21)
273
- throw new Error('Static recipes require contract version 21 or later.')
274
- const recipe = object(input)
275
- const axes = Object.fromEntries(
276
- Object.entries(object(recipe.axes)).map(([name, value]) => {
277
- const choices = array(value).map(string)
278
- if (
279
- !name ||
280
- new Set(choices).size !== choices.length ||
281
- !choices.length
282
- )
283
- throw new Error('Invalid packed recipe axis.')
284
- return [name, choices]
285
- }),
286
- )
287
- const defaults = Object.fromEntries(
288
- Object.entries(object(recipe.defaults)).map(([axis, choice]) => {
289
- if (
290
- !Object.hasOwn(axes, axis) ||
291
- (choice !== null && !axes[axis]!.includes(string(choice)))
292
- )
293
- throw new Error('Invalid packed recipe default.')
294
- return [axis, choice === null ? null : string(choice)]
295
- }),
296
- )
297
- const rules = array(recipe.rules).map((value) => {
298
- const rule = object(value)
299
- return {
300
- matches: array(rule.matches).map((value) => {
301
- const match = array(value)
302
- const axis = string(match[0])
303
- const choices = array(match[1]).map(string)
304
- if (
305
- match.length !== 2 ||
306
- !Object.hasOwn(axes, axis) ||
307
- !choices.length ||
308
- choices.some((choice) => !axes[axis]!.includes(choice))
309
- )
310
- throw new Error('Invalid packed recipe match.')
311
- return [axis, choices] as const
312
- }),
313
- value: {
314
- styles: array(object(rule.value).styles).map((value) => style(value)),
315
- },
316
- }
317
- })
318
- return { axes, defaults, rules }
319
- }
320
- const staticRecipe = readRecipe(item.staticRecipe)
321
- const dynamic = (() => {
322
- if (item.dynamic === undefined) return undefined
323
- if (version < 23)
324
- throw new Error('Dynamic native contracts require version 23 or later.')
325
- const entry = object(item.dynamic)
326
- const recipe = readRecipe(entry.recipe)
327
- if (!recipe) throw new Error('Missing packed dynamic recipe.')
328
- function fields(value: unknown): Record<string, string> {
329
- return Object.fromEntries(
330
- Object.entries(object(value)).map(([field, value]) => {
331
- const name = string(value)
332
- if (
333
- !field ||
334
- ['__proto__', 'style', 'className', 'vars', 'key', 'ref'].includes(
335
- field,
336
- ) ||
337
- !slots.includes(name)
338
- )
339
- throw new Error('Invalid packed dynamic slot.')
340
- return [field, name]
341
- }),
342
- )
343
- }
344
- const inputs = Object.fromEntries(
345
- Object.entries(object(entry.slots)).map(([field, value]) => {
346
- const reference = scalar(value)
347
- if (
348
- !Binding.is(reference) ||
349
- !['number', 'length'].includes(reference.type)
350
- )
351
- throw new Error('Invalid packed dynamic scalar.')
352
- fields({ [field]: reference.name })
353
- return [field, reference]
354
- }),
355
- )
356
- const seen = new Set<string>()
357
- const payloads =
358
- entry.payloads === undefined
359
- ? undefined
360
- : array(entry.payloads).map((value) => {
361
- const payload = object(value)
362
- const axis = string(payload.axis)
363
- const choice = string(payload.choice)
364
- const identity = JSON.stringify([axis, choice])
365
- if (!recipe.axes[axis]?.includes(choice) || seen.has(identity))
366
- throw new Error('Invalid packed dynamic choice.')
367
- seen.add(identity)
368
- return {
369
- axis,
370
- choice,
371
- slots: array(payload.slots).map(
372
- (value) => fields(value) as Record<string, `--${string}`>,
373
- ),
374
- }
375
- })
376
- if (payloads?.some((payload) => payload.slots.length !== 1))
377
- throw new Error('Native payloads require one unconditional slot map.')
378
- const defaultPayloads =
379
- entry.defaultPayloads === undefined
380
- ? undefined
381
- : Object.fromEntries(
382
- Object.entries(object(entry.defaultPayloads)).map(
383
- ([axis, value]) => {
384
- const payload = payloads?.find(
385
- (payload) =>
386
- payload.axis === axis &&
387
- payload.choice === recipe.defaults[axis],
388
- )
389
- if (!payload) throw new Error('Invalid packed dynamic default.')
390
- const defaults = object(value)
391
- const expected = Object.keys(payload.slots[0]!)
392
- if (
393
- Object.keys(defaults).length !== expected.length ||
394
- expected.some((field) => !Object.hasOwn(defaults, field))
395
- )
396
- throw new Error('Incomplete packed dynamic default.')
397
- return [
398
- axis,
399
- Object.fromEntries(
400
- Object.entries(defaults).map(([field, value]) => {
401
- if (
402
- typeof value !== 'string' &&
403
- (typeof value !== 'number' || !Number.isFinite(value))
404
- )
405
- throw new Error(
406
- 'Invalid packed dynamic default scalar.',
407
- )
408
- return [field, value]
409
- }),
410
- ),
411
- ]
412
- },
413
- ),
414
- )
415
- return { recipe, slots: inputs, payloads, defaultPayloads }
416
- })()
417
- return {
418
- ...(dynamic ? { dynamic } : {}),
419
- attributes,
420
- className: string(item.className),
421
- ...(item.output ? { output: 'html' } : {}),
422
- slots,
423
- staticRecipe,
424
- style: style(item.style),
425
- }
426
- }
427
-
428
- /** Encodes references as data while preserving declaration and condition order. */
429
- export function write(definition: Definition): unknown {
430
- return JSON.parse(
431
- JSON.stringify(
432
- {
433
- ...definition,
434
- nativeContext: undefined,
435
- style: {
436
- ...definition.style,
437
- cssOutput: definition.style.cssOutput ?? 'atomic',
438
- },
439
- },
440
- encode,
441
- ),
442
- )
443
- }
444
-
445
- function encode(_: string, value: unknown): unknown {
446
- if (Token.is(value))
447
- return {
448
- identity: value.contract[Token.identity],
449
- kind: 'token',
450
- path: value.path,
451
- value: value.value,
452
- }
453
- if (Token.isExpression(value))
454
- return { kind: 'expression', parts: value.parts }
455
- return value
456
- }
457
-
458
- function array(value: unknown): unknown[] {
459
- if (!Array.isArray(value)) throw new Error('Expected a packed style array.')
460
- return value
461
- }
462
-
463
- function object(value: unknown): Record<string, unknown> {
464
- if (!value || typeof value !== 'object' || Array.isArray(value))
465
- throw new Error('Expected a packed style object.')
466
- return value as Record<string, unknown>
467
- }
468
-
469
- function string(value: unknown): string {
470
- if (typeof value !== 'string')
471
- throw new Error('Expected a packed style string.')
472
- return value
473
- }