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,235 +0,0 @@
1
- /** Lowers target-neutral callback declarations to ordered native binding data. @module */
2
- import * as Binding from '../../internal/Binding.js'
3
- import type * as Native from '../Native.js'
4
- import type * as Recipe from '../../internal/Recipe.js'
5
- import type * as Runtime from '../../runtime/NativeDynamic.js'
6
- import * as Scalar from '../../react-native/internal/Scalar.js'
7
- import type * as Source from '../Source.js'
8
- import type * as Static from '../../runtime/NativeStatic.js'
9
- import type * as Style from '../../Style.js'
10
- import * as StyleSheet from '../../react-native/StyleSheet.js'
11
- import * as Token from '../../internal/Token.js'
12
- import * as Tokens from '../../react-native/internal/Tokens.js'
13
-
14
- type Step = Runtime.Program['rules'][number]['steps'][number]
15
- type PreparedStep =
16
- | Extract<Step, { readonly style: string }>
17
- | {
18
- readonly property: keyof typeof Scalar.properties
19
- readonly parts: readonly (
20
- | string
21
- | number
22
- | Token.Reference
23
- | { readonly slot: string; readonly number?: true }
24
- )[]
25
- }
26
- type PreparedRule = {
27
- readonly matches: Runtime.Program['rules'][number]['matches']
28
- readonly steps: readonly PreparedStep[]
29
- }
30
-
31
- /** Compiles static fragments and retains scalar assignments in authored order. */
32
- export function compile(
33
- recipe: Recipe.Definition,
34
- call: Pick<Source.Call, 'slots' | 'recipe'>,
35
- options: Native.compile.Options,
36
- prepared = prepare(recipe, call, options),
37
- ): Runtime.create.Options {
38
- const selected = options.vars?.[options.set ?? 'default']
39
- const metadata =
40
- selected &&
41
- (Object.getOwnPropertyDescriptor(selected, Token.definition)?.value as
42
- | Token.Metadata
43
- | undefined)
44
- return {
45
- ...prepared,
46
- program: {
47
- slots: prepared.program.slots,
48
- rules: prepared.program.rules.map((rule) => ({
49
- ...rule,
50
- steps: rule.steps.map((step) =>
51
- 'style' in step
52
- ? step
53
- : {
54
- ...step,
55
- parts: step.parts.map((part) =>
56
- Token.is(part)
57
- ? Tokens.resolve(part, {
58
- ...options,
59
- metadata,
60
- resolution: { schemeIndependent: true },
61
- })
62
- : part,
63
- ),
64
- },
65
- ),
66
- })),
67
- },
68
- styles: StyleSheet.select(prepared.styles, {
69
- set: options.set ?? 'default',
70
- colorScheme: options.colorScheme,
71
- }),
72
- }
73
- }
74
-
75
- /** Removes dynamic instructions and resolves absolute line heights before publication. */
76
- export function finite(options: Runtime.create.Options): Static.create.Options {
77
- const styles = { ...options.styles }
78
- return {
79
- axes: options.axes,
80
- defaults: options.defaults,
81
- rules: options.program.rules.map((rule) => ({
82
- matches: rule.matches,
83
- steps: rule.steps.map((step) => {
84
- if ('style' in step) return step.style
85
- if (
86
- step.property !== 'lineHeight' ||
87
- !step.parts.length ||
88
- step.parts.some((part) => typeof part === 'object')
89
- )
90
- throw new Error(
91
- 'Static native recipes cannot contain runtime bindings.',
92
- )
93
- const value = (
94
- step.parts.length === 1 ? step.parts[0]! : step.parts.join('')
95
- ) as string | number
96
- if (typeof value === 'number') return value
97
- const name = String(Object.keys(styles).length)
98
- styles[name] = {
99
- lineHeight: Scalar.length(value, options, false, ['lineHeight']),
100
- }
101
- return name
102
- }),
103
- })),
104
- styles,
105
- }
106
- }
107
-
108
- /** Prepares immutable programs and all set/scheme tables before selection. */
109
- export function prepare(
110
- recipe: Recipe.Definition,
111
- call: Pick<Source.Call, 'slots' | 'recipe'>,
112
- options: Native.compile.Options,
113
- ) {
114
- const slots = Object.fromEntries(
115
- Object.entries(call.slots ?? {}).map(([name, slot]) => [name, slot.name]),
116
- )
117
- const available = new Set([
118
- ...Object.values(slots),
119
- ...(call.recipe?.payloads ?? []).flatMap((payload) =>
120
- Object.values(payload.slots[0]!),
121
- ),
122
- ])
123
- const fragments: Style.NamedStyle[] = []
124
- const rules: PreparedRule[] = []
125
-
126
- for (const rule of recipe.rules) {
127
- const steps: PreparedStep[] = []
128
- function fragment(style: Style.NamedStyle) {
129
- const name = String(fragments.length)
130
- fragments.push({ ...style, name })
131
- steps.push({ style: name })
132
- }
133
- function visit(style: Style.NamedStyle) {
134
- const declared = new Set<string>()
135
- let declarations: Style.Declaration[] = []
136
- function flush() {
137
- if (!declarations.length) return
138
- fragment({ name: style.name, declarations })
139
- declarations = []
140
- }
141
- for (const declaration of style.declarations) {
142
- if (declaration.important || declared.has(declaration.property))
143
- throw new Error(
144
- 'Importance and fallback declarations are not supported on native.',
145
- )
146
- declared.add(declaration.property)
147
- const parts = Token.isExpression(declaration.value)
148
- ? declaration.value.parts
149
- : [declaration.value]
150
- const dynamic = parts.some((part) => Binding.is(part))
151
- if (!dynamic && declaration.property !== 'lineHeight') {
152
- declarations.push(declaration)
153
- continue
154
- }
155
- flush()
156
- const property = declaration.property as keyof typeof Scalar.properties
157
- if (
158
- !Object.hasOwn(Scalar.properties, property) ||
159
- [
160
- 'flex',
161
- 'transform',
162
- 'origin',
163
- 'shadow',
164
- 'textShadow',
165
- 'fontVariant',
166
- ].includes(String(Scalar.properties[property]))
167
- )
168
- throw new Error(
169
- `Dynamic native property is unsupported: ${property}.`,
170
- )
171
- const values = parts.map((part) => {
172
- if (typeof part === 'string' || typeof part === 'number') return part
173
- if (Token.is(part)) return part
174
- if (!Binding.is(part) || !available.has(part.name))
175
- throw new Error(
176
- 'Native bindings require declared runtime scalar fields.',
177
- )
178
- return {
179
- slot: part.name,
180
- ...(part.type === 'number' ? { number: true as const } : {}),
181
- }
182
- })
183
- const calculation = values.some(
184
- (value) => typeof value === 'string' && /(?:^|\s)calc\(/i.test(value),
185
- )
186
- if (
187
- values.length > 1 &&
188
- !calculation &&
189
- !(
190
- values.length === 2 &&
191
- typeof values[0] === 'object' &&
192
- ['px', 'rem', '%'].includes(String(values[1]))
193
- )
194
- )
195
- throw new Error(
196
- 'Native dynamic expressions support a scalar with a px, rem, or percent suffix.',
197
- )
198
- steps.push({ property, parts: values })
199
- }
200
- flush()
201
- if (style.targets)
202
- fragment({ name: style.name, declarations: [], targets: style.targets })
203
- for (const rule of style.rules ?? []) {
204
- if (rule.condition !== undefined)
205
- throw new Error(
206
- 'Selectors, queries, and nested rules are not supported on native.',
207
- )
208
- visit(rule.style)
209
- }
210
- }
211
- for (const style of rule.value.styles) visit(style)
212
- rules.push({ matches: rule.matches, steps })
213
- }
214
- const compiled = StyleSheet.compile({
215
- styles: { styles: fragments },
216
- fonts: options.fonts,
217
- platform: options.platform,
218
- vars: options.vars,
219
- units: options.units,
220
- })
221
- return {
222
- axes: recipe.axes,
223
- defaults: recipe.defaults,
224
- ...(call.recipe?.payloads
225
- ? {
226
- payloads: call.recipe.payloads,
227
- defaultPayloads: call.recipe.defaultPayloads,
228
- }
229
- : {}),
230
- fonts: options.fonts,
231
- units: options.units,
232
- program: { slots, rules },
233
- styles: compiled.styles,
234
- }
235
- }
@@ -1,342 +0,0 @@
1
- /** Lowers native media rules and conditional tokens to bounded static alternatives. @module */
2
- import * as CssTree from 'css-tree'
3
- import type * as Media from '../../runtime/internal/NativeMedia.js'
4
- import * as Scalar from '../../react-native/internal/Scalar.js'
5
- import type * as Style from '../../Style.js'
6
- import type * as StyleSheet from '../../react-native/StyleSheet.js'
7
- import * as Token from '../../internal/Token.js'
8
-
9
- /** Retains authored precedence while selecting each possible media outcome. */
10
- export function prepare<variables extends StyleSheet.compile.Options['vars']>(
11
- styles: readonly Style.NamedStyle[] | undefined,
12
- vars: variables,
13
- options: Scalar.Options,
14
- ) {
15
- const catalog: StyleSheet.compile.Options['vars'] = vars
16
- const expressions = new Map<string, number>()
17
- const names = new Map<string, number>()
18
- const queries: Media.Query[] = []
19
- const visited = new Set<object>()
20
-
21
- function add(name: string) {
22
- if (names.has(name)) return
23
-
24
- const query = parse(name, options)
25
- const expression = JSON.stringify(query)
26
- let index = expressions.get(expression)
27
- if (index === undefined) {
28
- index = queries.length
29
- if (index === 8)
30
- throw new Error(
31
- 'Native media supports at most eight distinct conditions per definition.',
32
- )
33
-
34
- queries.push(query)
35
- expressions.set(expression, index)
36
- }
37
-
38
- names.set(name, index)
39
- }
40
-
41
- function values(value: unknown) {
42
- if (!value || typeof value !== 'object' || visited.has(value)) return
43
-
44
- visited.add(value)
45
- if (Token.is(value)) {
46
- values(value.value)
47
- for (const theme of Object.values(catalog ?? {})) {
48
- const metadata = theme[Token.definition]
49
- if (
50
- metadata.contract === value.contract ||
51
- (metadata.contract[Token.identity] !== undefined &&
52
- metadata.contract[Token.identity] ===
53
- value.contract[Token.identity])
54
- )
55
- values(metadata.values[value.path])
56
- }
57
- } else if (Token.isExpression(value)) value.parts.forEach(values)
58
- else if ('default' in value) {
59
- for (const [name, entry] of Object.entries(value)) {
60
- if (name !== 'default') {
61
- // Unsupported variable leaves keep their deferred read diagnostic.
62
- try {
63
- add(name)
64
- } catch (error) {
65
- if (!(error instanceof UnsupportedError)) throw error
66
- }
67
- }
68
- values(entry)
69
- }
70
- } else if ('light' in value && 'dark' in value) {
71
- values(value.light)
72
- values(value.dark)
73
- }
74
- }
75
-
76
- function visit(style: Style.NamedStyle) {
77
- for (const declaration of style.declarations) values(declaration.value)
78
- for (const rule of style.rules ?? []) {
79
- if (rule.condition?.startsWith('@media')) add(rule.condition)
80
- visit(rule.style)
81
- }
82
- }
83
-
84
- styles?.forEach(visit)
85
- if (!styles)
86
- for (const theme of Object.values(catalog ?? {})) {
87
- const metadata = theme[Token.definition]
88
- Object.values(metadata.values).forEach(values)
89
- }
90
- if (!queries.length) return
91
-
92
- return {
93
- queries,
94
- select(selection: string) {
95
- const active = new Set<object>()
96
- function value<entry>(entry: entry): entry {
97
- if (!entry || typeof entry !== 'object') return entry
98
- if (active.has(entry))
99
- throw new Error('Native token aliases must not form a cycle.')
100
-
101
- active.add(entry)
102
- try {
103
- if (Token.is(entry))
104
- return Token.create({
105
- ...entry,
106
- value: value(entry.value),
107
- }) as entry
108
- if (Token.isExpression(entry))
109
- return { ...entry, parts: entry.parts.map(value) } as entry
110
- if ('default' in entry) {
111
- const branches = Object.entries(entry)
112
- if (
113
- branches.some(([name]) => name !== 'default' && !names.has(name))
114
- )
115
- return Object.fromEntries(
116
- branches
117
- .filter(([name]) => name === 'default' || !names.has(name))
118
- .map(([name, branch]) => [name, value(branch)]),
119
- ) as entry
120
-
121
- let selected = entry.default
122
- for (const [name, branch] of branches)
123
- if (name !== 'default' && selection[names.get(name)!] === '1')
124
- selected = branch
125
-
126
- return value(selected) as entry
127
- }
128
- if ('light' in entry && 'dark' in entry)
129
- return {
130
- ...entry,
131
- dark: value(entry.dark),
132
- light: value(entry.light),
133
- }
134
- return entry
135
- } finally {
136
- active.delete(entry)
137
- }
138
- }
139
-
140
- function style(entry: Style.NamedStyle): Style.NamedStyle {
141
- return {
142
- ...entry,
143
- declarations: entry.declarations.map((declaration) => ({
144
- ...declaration,
145
- value: value(declaration.value),
146
- })),
147
- ...(entry.rules
148
- ? {
149
- rules: entry.rules.flatMap((rule) => {
150
- const index =
151
- rule.condition === undefined
152
- ? undefined
153
- : names.get(rule.condition)
154
- if (index !== undefined && selection[index] !== '1') return []
155
-
156
- return [
157
- {
158
- ...(index === undefined ? rule : {}),
159
- style: style(rule.style),
160
- },
161
- ]
162
- }),
163
- }
164
- : {}),
165
- }
166
- }
167
-
168
- return {
169
- style,
170
- vars:
171
- catalog &&
172
- (Object.fromEntries(
173
- Object.entries(catalog).map(([name, theme]) => {
174
- const metadata = theme[Token.definition]
175
- return [
176
- name,
177
- Object.defineProperty({}, Token.definition, {
178
- value: {
179
- ...metadata,
180
- values: Object.fromEntries(
181
- Object.entries(metadata.values).map(([path, entry]) => [
182
- path,
183
- value(entry),
184
- ]),
185
- ),
186
- },
187
- }) as typeof theme,
188
- ]
189
- }),
190
- ) as variables),
191
- }
192
- },
193
- selections: Array.from({ length: 2 ** queries.length }, (_entry, index) =>
194
- index.toString(2).padStart(queries.length, '0'),
195
- ),
196
- }
197
- }
198
-
199
- class UnsupportedError extends Error {
200
- override name = 'NativeMedia.UnsupportedError'
201
- }
202
-
203
- function parse(input: string, options: Scalar.Options): Media.Query {
204
- if (!input.startsWith('@media'))
205
- throw new UnsupportedError(
206
- 'Native conditional variables require media queries.',
207
- )
208
- const parsed = CssTree.parse(input.slice(6), { context: 'mediaQueryList' })
209
- let count = 0
210
- function read(node: CssTree.CssNode): Media.Query {
211
- if (++count > 128)
212
- throw new Error('Native media queries exceed 128 syntax nodes.')
213
- if (node.type === 'MediaQueryList') {
214
- const queries = node.children.toArray().map(read)
215
- return queries.length === 1 ? queries[0]! : { kind: 'or', queries }
216
- }
217
- if (node.type === 'MediaQuery') {
218
- if (
219
- (node.mediaType &&
220
- !['all', 'screen'].includes(node.mediaType.toLowerCase())) ||
221
- node.modifier?.toLowerCase() === 'not'
222
- )
223
- throw new UnsupportedError(
224
- 'Native media types support all or screen without negation.',
225
- )
226
- return node.condition
227
- ? read(node.condition)
228
- : { kind: 'compare', left: 0, operator: '=', right: 0 }
229
- }
230
- if (node.type === 'Condition') {
231
- const parts = node.children.toArray()
232
- if (parts.length === 1) return read(parts[0]!)
233
- if (
234
- parts.length === 2 &&
235
- parts[0]?.type === 'Identifier' &&
236
- parts[0].name.toLowerCase() === 'not'
237
- )
238
- return { kind: 'not', query: read(parts[1]!) }
239
- const operator =
240
- parts[1]?.type === 'Identifier'
241
- ? parts[1].name.toLowerCase()
242
- : undefined
243
- if (
244
- (operator !== 'and' && operator !== 'or') ||
245
- parts.length % 2 !== 1 ||
246
- parts.some(
247
- (part, index) =>
248
- index % 2 === 1 &&
249
- (part.type !== 'Identifier' ||
250
- part.name.toLowerCase() !== operator),
251
- )
252
- )
253
- throw new UnsupportedError('Unsupported native media condition.')
254
- return {
255
- kind: operator,
256
- queries: parts.filter((_part, index) => index % 2 === 0).map(read),
257
- }
258
- }
259
- function operand(entry: CssTree.CssNode): number | 'height' | 'width' {
260
- if (
261
- entry.type === 'Identifier' &&
262
- (entry.name.toLowerCase() === 'height' ||
263
- entry.name.toLowerCase() === 'width')
264
- )
265
- return entry.name.toLowerCase() as 'height' | 'width'
266
- if (entry.type === 'Dimension') {
267
- try {
268
- return Scalar.length(
269
- `${entry.value}${entry.unit.toLowerCase()}`,
270
- options,
271
- false,
272
- [],
273
- )
274
- } catch (error) {
275
- throw new UnsupportedError((error as Error).message)
276
- }
277
- }
278
- if (entry.type === 'Number' && Number(entry.value) === 0) return 0
279
- throw new UnsupportedError(
280
- 'Native media ranges require width/height and px/rem thresholds.',
281
- )
282
- }
283
- function comparison(
284
- left: CssTree.CssNode,
285
- operator: string | null,
286
- right: CssTree.CssNode,
287
- ): Media.Query {
288
- if (!operator || !['<', '<=', '=', '>', '>='].includes(operator))
289
- throw new UnsupportedError('Unsupported native media comparison.')
290
- return {
291
- kind: 'compare',
292
- left: operand(left),
293
- operator: operator as '<' | '<=' | '=' | '>' | '>=',
294
- right: operand(right),
295
- }
296
- }
297
- if (node.type === 'FeatureRange') {
298
- const first = comparison(node.left, node.leftComparison, node.middle)
299
- return node.right
300
- ? {
301
- kind: 'and',
302
- queries: [
303
- first,
304
- comparison(node.middle, node.rightComparison, node.right),
305
- ],
306
- }
307
- : first
308
- }
309
- if (node.type === 'Feature') {
310
- const name = node.name.toLowerCase()
311
- if (
312
- name === 'orientation' &&
313
- node.value?.type === 'Identifier' &&
314
- ['landscape', 'portrait'].includes(node.value.name.toLowerCase())
315
- )
316
- return {
317
- kind: 'compare',
318
- left: 'width',
319
- operator: node.value.name.toLowerCase() === 'landscape' ? '>' : '<=',
320
- right: 'height',
321
- }
322
- const match = /^(?:(min|max)-)?(height|width)$/.exec(name)
323
- if (match)
324
- return {
325
- kind: 'compare',
326
- left: match[2] as 'height' | 'width',
327
- operator:
328
- match[1] === 'min'
329
- ? '>='
330
- : match[1] === 'max'
331
- ? '<='
332
- : node.value
333
- ? '='
334
- : '>',
335
- right: node.value ? operand(node.value) : 0,
336
- }
337
- }
338
- throw new UnsupportedError('Unsupported native media feature.')
339
- }
340
-
341
- return read(parsed)
342
- }