zyzz 0.0.28 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,121 +0,0 @@
1
- /** Validates native property registration descriptors and independent initial values. @module */
2
- import * as Functions from './Functions.js'
3
- import * as FunctionSyntax from '../../internal/FunctionSyntax.js'
4
- import * as Identifiers from './Identifiers.js'
5
- import * as Tree from 'css-tree'
6
-
7
- /** Rejects declaration delimiters inside an authored initial value. */
8
- export function initial(value: string): void {
9
- Tree.parse(value, { context: 'value' })
10
- }
11
-
12
- /** Validates registrations before output-parser recovery can discard them. */
13
- export function validate(source: string): boolean {
14
- let escaped = false
15
- Tree.walk(Tree.parse(source), {
16
- visit: 'Atrule',
17
- enter(rule) {
18
- if (rule.name.toLowerCase() !== 'property') return
19
- const names = Identifiers.list(
20
- rule.prelude ? Tree.generate(rule.prelude) : '',
21
- 'space',
22
- )
23
- if (
24
- names?.length !== 1 ||
25
- !names[0]!.startsWith('--') ||
26
- names[0]!.length <= 2 ||
27
- !rule.block
28
- )
29
- throw new Error(
30
- 'Property registration requires a custom-property name and descriptors.',
31
- )
32
- const values = new Map<string, Tree.Value>()
33
- rule.block.children.forEach((node) => {
34
- if (node.type !== 'Declaration' || node.important)
35
- throw new Error('Expected non-important property descriptors.')
36
- const key = node.property.toLowerCase()
37
- if (!['syntax', 'inherits', 'initial-value'].includes(key))
38
- throw new Error('Unknown property descriptor.')
39
- values.set(
40
- key,
41
- Tree.parse(Tree.generate(node.value), {
42
- context: 'value',
43
- }) as Tree.Value,
44
- )
45
- })
46
- const syntaxNode = values.get('syntax')
47
- const syntax =
48
- syntaxNode?.children.size === 1 &&
49
- syntaxNode.children.first?.type === 'String'
50
- ? syntaxNode.children.first.value
51
- : undefined
52
- if (syntax?.includes('\\')) escaped = true
53
- const inherits = values.get('inherits')
54
- if (
55
- syntax === undefined ||
56
- !FunctionSyntax.accepts(`type(${syntax})`) ||
57
- syntax.includes('<string>')
58
- )
59
- throw new Error(
60
- 'Property registration requires a supported syntax string.',
61
- )
62
- const inherited =
63
- inherits && Identifiers.list(Tree.generate(inherits), 'space')
64
- if (
65
- inherited?.length !== 1 ||
66
- !['true', 'false'].includes(inherited[0]!.toLowerCase())
67
- )
68
- throw new Error('Property registration requires boolean inherits.')
69
- const initial = values.get('initial-value')
70
- if (!initial && syntax.trim() !== '*')
71
- throw new Error(
72
- 'Non-universal property registrations require an initial value.',
73
- )
74
- if (!initial || syntax.trim() === '*') return
75
- const matched = (() => {
76
- try {
77
- return Functions.value(syntax, Tree.generate(initial))
78
- } catch {
79
- throw new Error(
80
- 'Registered initial values must match the declared syntax.',
81
- )
82
- }
83
- })()
84
- if (
85
- matched &&
86
- (!matched.startsWith('<') || matched.startsWith('<custom-ident>'))
87
- )
88
- return
89
- Tree.walk(initial, (node) => {
90
- if (
91
- node.type === 'Dimension' &&
92
- /^(?:cq(?:w|h|i|b|min|max)|r?(?:em|ex|ch|cap|ic|lh))$/i.test(
93
- node.unit,
94
- )
95
- )
96
- throw new Error(
97
- 'Registered initial values must be computationally independent.',
98
- )
99
- if (
100
- node.type === 'Function' &&
101
- /^(?:var|env|attr|light-dark|contrast-color|anchor|anchor-size|sibling-index|sibling-count)$/i.test(
102
- Tree.ident.decode(node.name),
103
- )
104
- )
105
- throw new Error(
106
- 'Registered initial values must be computationally independent.',
107
- )
108
- if (
109
- node.type === 'Identifier' &&
110
- /^(?:currentcolor|inherit|initial|unset|revert|revert-layer)$/i.test(
111
- Tree.ident.decode(node.name),
112
- )
113
- )
114
- throw new Error(
115
- 'Registered initial values must be computationally independent.',
116
- )
117
- })
118
- },
119
- })
120
- return escaped
121
- }
@@ -1,139 +0,0 @@
1
- /** Partitions named recipe queries into mutually exclusive CSS regions. @module */
2
- import type * as Ast from '@oxc-project/types'
3
- import * as CssTree from 'css-tree'
4
- import * as Query from '../../internal/Query.js'
5
- import * as Themes from './Themes.js'
6
-
7
- /** One named condition and its positive/negative grouping rules. */
8
- export type Condition = {
9
- /** Negated query list, represented as an intersection of grouping rules. */
10
- readonly inactive: readonly string[]
11
- /** Authored name used by the selection callable. */
12
- readonly name: string
13
- /** Authored value span retained for diagnostics and mapping. */
14
- readonly node: Ast.Node
15
- /** Resolved positive grouping rule. */
16
- readonly rule: string
17
- }
18
-
19
- /** Resolves theme thresholds and derives a logical complement without evaluation. */
20
- export function read(options: read.Options): Condition {
21
- const { name, node } = options
22
- if (name === '__proto__')
23
- throw new Themes.InvalidError(
24
- 'Recipe condition names cannot use __proto__.',
25
- node,
26
- )
27
- if (node.type !== 'Literal' || typeof node.value !== 'string')
28
- throw new Themes.InvalidError(
29
- 'Recipe conditions require static media or supports strings.',
30
- node,
31
- )
32
-
33
- try {
34
- const rule = Query.resolve(
35
- node.value,
36
- options.queries ?? {
37
- breakpoint: {},
38
- containerNames: [],
39
- container: {},
40
- },
41
- )
42
- const match = /^@(media|supports)(?=[\s(])\s*([\s\S]+)$/.exec(
43
- rule.replace(/\/\*[\s\S]*?\*\//g, ' '),
44
- )
45
- if (!match)
46
- throw new Error('Recipe conditions support only @media and @supports.')
47
-
48
- const text = match[2]!
49
- if (match[1] === 'supports') {
50
- // Parse the complete rule so malformed braces or trailing rules cannot
51
- // become part of a synthesized condition.
52
- const parsed = CssTree.parse(`@supports ${text}{}`)
53
- if (parsed.type !== 'StyleSheet' || parsed.children.size !== 1)
54
- throw new Error('Malformed supports condition.')
55
- const entry = parsed.children.first
56
- if (
57
- entry?.type !== 'Atrule' ||
58
- !entry.prelude ||
59
- !entry.block ||
60
- !entry.block.children.isEmpty
61
- )
62
- throw new Error('Malformed supports condition.')
63
- CssTree.walk(entry.prelude, (node) => {
64
- if (node.type === 'Raw')
65
- throw new Error('Malformed supports condition.')
66
- })
67
- return { inactive: [`@supports not (${text})`], name, node, rule }
68
- }
69
-
70
- const list = CssTree.parse(text, { context: 'mediaQueryList' })
71
- if (list.type !== 'MediaQueryList' || list.children.isEmpty)
72
- throw new Error('Malformed media condition.')
73
- const inactive = list.children.toArray().map((query) => {
74
- if (query.type !== 'MediaQuery')
75
- throw new Error('Malformed media condition.')
76
- if (query.mediaType)
77
- return `@media ${CssTree.generate({ ...query, modifier: query.modifier?.toLowerCase() === 'not' ? null : 'not' })}`
78
- if (!query.condition) throw new Error('Malformed media condition.')
79
- return `@media not (${CssTree.generate(query.condition)})`
80
- })
81
- return { inactive, name, node, rule }
82
- } catch (error) {
83
- throw new Themes.InvalidError(
84
- error instanceof Error ? error.message : 'Invalid recipe condition.',
85
- node,
86
- )
87
- }
88
- }
89
-
90
- /** Inputs for static condition resolution. */
91
- export declare namespace read {
92
- /** Named condition and optional bound query metadata. */
93
- type Options = {
94
- /** Author-facing condition name. */
95
- readonly name: string
96
- /** Literal query source. */
97
- readonly node: Ast.Node
98
- /** Theme-owned query thresholds. */
99
- readonly queries?: Query.Metadata | undefined
100
- }
101
- }
102
-
103
- /** One satisfiable candidate truth region; CSS discards impossible intersections. */
104
- export type Region = {
105
- /** Active condition indexes in authored priority order. */
106
- readonly active: readonly number[]
107
- /** Nested grouping rules defining this region. */
108
- readonly rules: readonly { readonly node: Ast.Node; readonly rule: string }[]
109
- }
110
-
111
- /** Enumerates only condition states, never combinations of axis choices. */
112
- export function regions(conditions: readonly Condition[]): readonly Region[] {
113
- // A compile-time ceiling bounds generated output before allocating regions.
114
- if (conditions.length > 8)
115
- throw new Themes.InvalidError(
116
- 'Recipes support at most eight named conditions (256 CSS regions).',
117
- conditions[8]!.node,
118
- )
119
-
120
- let result: readonly Region[] = [{ active: [], rules: [] }]
121
- for (const [index, condition] of conditions.entries())
122
- result = result.flatMap((region) => [
123
- {
124
- active: region.active,
125
- rules: [
126
- ...region.rules,
127
- ...condition.inactive.map((rule) => ({ node: condition.node, rule })),
128
- ],
129
- },
130
- {
131
- active: [...region.active, index],
132
- rules: [
133
- ...region.rules,
134
- { node: condition.node, rule: condition.rule },
135
- ],
136
- },
137
- ])
138
- return result
139
- }
@@ -1,132 +0,0 @@
1
- /** Reuses typed callback extraction for isolated recipe payload contexts. @module */
2
- import type * as Ast from '@oxc-project/types'
3
- import * as Walker from 'oxc-walker'
4
- import type * as Binding from '../../internal/Binding.js'
5
- import * as Dynamic from './Dynamic.js'
6
- import * as Expression from './Expression.js'
7
-
8
- /** Shared callback validation and lookup boundary consumed by source extraction. */
9
- export type Bindings = Pick<
10
- NonNullable<ReturnType<typeof Dynamic.read>>,
11
- 'accepts' | 'resolve' | 'slots'
12
- >
13
-
14
- /** Collects isolated bindings without evaluating any author callback. */
15
- export function create(options: create.Options) {
16
- const references = new WeakMap<Ast.Node, Binding.Reference>()
17
- const owners = new Map<
18
- Binding.Reference,
19
- NonNullable<ReturnType<typeof Dynamic.read>>
20
- >()
21
- const slots: Record<string, Binding.Reference> = Object.create(null)
22
-
23
- return {
24
- accepts(reference: Binding.Reference, property: string) {
25
- return owners.get(reference)?.accepts(reference, property) ?? false
26
- },
27
- read(node: Ast.Node, identity: string) {
28
- const model = Dynamic.read(
29
- structuredClone(node),
30
- identity,
31
- options.resolveType,
32
- )
33
- if (!model) return undefined
34
- const body = options.normalize(model.body) as Ast.ObjectExpression
35
- Walker.walk(body, {
36
- enter(node) {
37
- const slot = model.resolve(node)
38
- if (slot) references.set(Expression.unwrap(node), slot)
39
- },
40
- })
41
- for (const slot of Object.values(model.slots)) {
42
- owners.set(slot, model)
43
- slots[slot.name] = slot
44
- }
45
- return {
46
- ...model,
47
- body,
48
- acceptsValue(field: string, value: string | number) {
49
- const type = options.resolveType(model.type)
50
- if (type.type !== 'TSTypeLiteral') return false
51
- const member = type.members.find(
52
- (member) =>
53
- member.type === 'TSPropertySignature' &&
54
- (member.key.type === 'Identifier'
55
- ? member.key.name
56
- : member.key.type === 'Literal'
57
- ? member.key.value
58
- : undefined) === field,
59
- )
60
- return (
61
- member?.type === 'TSPropertySignature' &&
62
- member.typeAnnotation != null &&
63
- accepts(
64
- options.resolveType(member.typeAnnotation.typeAnnotation),
65
- value,
66
- )
67
- )
68
- },
69
- }
70
- },
71
- resolve(node: Ast.Node) {
72
- return references.get(Expression.unwrap(node))
73
- },
74
- slots,
75
- }
76
- }
77
-
78
- /** Source-owned static resolution hooks. */
79
- export declare namespace create {
80
- /** Compiler adapters used for the same resolution as dynamic style callbacks. */
81
- type Options = {
82
- /** Expands immutable body data without executing expressions. */
83
- readonly normalize: (node: Ast.Node) => Ast.Node
84
- /** Resolves finite local or imported callback type aliases. */
85
- readonly resolveType: (node: Ast.Node) => Ast.Node
86
- }
87
- }
88
-
89
- function accepts(node: Ast.Node, value: string | number): boolean {
90
- if (node.type === 'TSUnionType')
91
- return node.types.some((node) => accepts(node, value))
92
- if (node.type === 'TSIntersectionType')
93
- return node.types.every((node) => accepts(node, value))
94
- if (node.type === 'TSStringKeyword') return typeof value === 'string'
95
- if (node.type === 'TSNumberKeyword')
96
- return typeof value === 'number' && Number.isFinite(value)
97
- if (node.type === 'TSLiteralType') {
98
- if (node.literal.type === 'Literal') return node.literal.value === value
99
- if (
100
- node.literal.type === 'UnaryExpression' &&
101
- node.literal.operator === '-' &&
102
- node.literal.argument.type === 'Literal' &&
103
- typeof node.literal.argument.value === 'number'
104
- )
105
- return -node.literal.argument.value === value
106
- }
107
- if (node.type === 'TSTemplateLiteralType' && typeof value === 'string') {
108
- const template = node
109
- const input = value
110
- function match(index: number, offset: number): boolean {
111
- const text =
112
- template.quasis[index]!.value.cooked ??
113
- template.quasis[index]!.value.raw
114
- if (!input.startsWith(text, offset)) return false
115
- offset += text.length
116
- if (index === template.types.length) return offset === input.length
117
- for (let end = offset; end <= input.length; end++) {
118
- const part = input.slice(offset, end)
119
- const type = template.types[index]!
120
- const valid =
121
- accepts(type, part) ||
122
- (part.trim() !== '' &&
123
- Number.isFinite(Number(part)) &&
124
- accepts(type, Number(part)))
125
- if (valid && match(index + 1, end)) return true
126
- }
127
- return false
128
- }
129
- return match(0, 0)
130
- }
131
- return false
132
- }